Lines Matching +full:trace +full:- +full:buffer +full:- +full:extension

1 // SPDX-License-Identifier: GPL-2.0-only
2 /* Copyright(c) 2024-2025 Intel Corporation. All rights reserved. */
11 #include <trace/events/tsm_mr.h>
14 * struct tm_context - contains everything necessary to implement sysfs
19 * @in_sync: %true if MR cache is up-to-date.
25 * Given tm->refresh() is potentially expensive, tm_digest_read() caches MR
26 * values and calls tm->refresh() only when necessary. Only live MRs (i.e., with
27 * %TSM_MR_F_LIVE set) can trigger tm->refresh(), while others are assumed to
28 * retain their values from the last tm->write(). @in_sync tracks if there have
29 * been tm->write() calls since the last tm->refresh(). That is, tm->refresh()
33 * tm_digest_write() sets @in_sync to %false and calls tm->write(), whose
35 * extension semantics (i.e., tm->write() extends the input buffer into the MR).
46 const struct bin_attribute *attr, char *buffer, in tm_digest_read() argument
53 ctx = attr->private; in tm_digest_read()
54 rc = down_read_interruptible(&ctx->rwsem); in tm_digest_read()
58 mr = &ctx->tm->mrs[attr - ctx->mrs]; in tm_digest_read()
61 * @ctx->in_sync indicates if the MR cache is stale. It is a global in tm_digest_read()
62 * instead of a per-MR flag for simplicity, as most (if not all) archs in tm_digest_read()
65 * ctx->refresh() is necessary only for LIVE MRs, while others retain in tm_digest_read()
66 * their values from their respective last ctx->write(). in tm_digest_read()
68 if ((mr->mr_flags & TSM_MR_F_LIVE) && !ctx->in_sync) { in tm_digest_read()
69 up_read(&ctx->rwsem); in tm_digest_read()
71 rc = down_write_killable(&ctx->rwsem); in tm_digest_read()
75 if (!ctx->in_sync) { in tm_digest_read()
76 rc = ctx->tm->refresh(ctx->tm); in tm_digest_read()
77 ctx->in_sync = !rc; in tm_digest_read()
81 downgrade_write(&ctx->rwsem); in tm_digest_read()
84 memcpy(buffer, mr->mr_value + off, count); in tm_digest_read()
87 up_read(&ctx->rwsem); in tm_digest_read()
92 const struct bin_attribute *attr, char *buffer, in tm_digest_write() argument
100 if (off != 0 || count != attr->size) in tm_digest_write()
101 return -EINVAL; in tm_digest_write()
103 ctx = attr->private; in tm_digest_write()
104 mr = &ctx->tm->mrs[attr - ctx->mrs]; in tm_digest_write()
106 rc = down_write_killable(&ctx->rwsem); in tm_digest_write()
110 rc = ctx->tm->write(ctx->tm, mr, buffer); in tm_digest_write()
114 ctx->in_sync = false; in tm_digest_write()
115 trace_tsm_mr_write(mr, buffer); in tm_digest_write()
118 up_write(&ctx->rwsem); in tm_digest_write()
123 * tsm_mr_create_attribute_group() - creates an attribute group for measurement
128 * provided by @tm->mrs.
137 * * %-EINVAL - Invalid MR definitions.
138 * * %-ENOMEM - Out of memory.
145 if (!tm || !tm->mrs) in tsm_mr_create_attribute_group()
146 return ERR_PTR(-EINVAL); in tsm_mr_create_attribute_group()
150 for (size_t i = 0; i < tm->nr_mrs; ++i) { in tsm_mr_create_attribute_group()
151 if ((tm->mrs[i].mr_flags & TSM_MR_F_LIVE) && !tm->refresh) in tsm_mr_create_attribute_group()
152 return ERR_PTR(-EINVAL); in tsm_mr_create_attribute_group()
154 if ((tm->mrs[i].mr_flags & TSM_MR_F_WRITABLE) && !tm->write) in tsm_mr_create_attribute_group()
155 return ERR_PTR(-EINVAL); in tsm_mr_create_attribute_group()
157 if (!tm->mrs[i].mr_name) in tsm_mr_create_attribute_group()
158 return ERR_PTR(-EINVAL); in tsm_mr_create_attribute_group()
160 if (tm->mrs[i].mr_flags & TSM_MR_F_NOHASH) in tsm_mr_create_attribute_group()
163 if (tm->mrs[i].mr_hash >= HASH_ALGO__LAST) in tsm_mr_create_attribute_group()
164 return ERR_PTR(-EINVAL); in tsm_mr_create_attribute_group()
167 nlen += strlen(tm->mrs[i].mr_name) + 1 + in tsm_mr_create_attribute_group()
168 strlen(hash_algo_name[tm->mrs[i].mr_hash]) + 1; in tsm_mr_create_attribute_group()
173 * so that we don't have to free MR names one-by-one in in tsm_mr_create_attribute_group()
177 kzalloc(sizeof(*attrs) * (tm->nr_mrs + 1) + nlen, GFP_KERNEL); in tsm_mr_create_attribute_group()
179 kzalloc(struct_size(ctx, mrs, tm->nr_mrs), GFP_KERNEL); in tsm_mr_create_attribute_group()
183 return ERR_PTR(-ENOMEM); in tsm_mr_create_attribute_group()
186 name = (char *)&attrs[tm->nr_mrs + 1]; in tsm_mr_create_attribute_group()
189 for (size_t i = 0; i < tm->nr_mrs; ++i) { in tsm_mr_create_attribute_group()
190 struct bin_attribute *bap = &ctx->mrs[i]; in tsm_mr_create_attribute_group()
194 if (tm->mrs[i].mr_flags & TSM_MR_F_NOHASH) in tsm_mr_create_attribute_group()
195 bap->attr.name = tm->mrs[i].mr_name; in tsm_mr_create_attribute_group()
197 bap->attr.name = name; in tsm_mr_create_attribute_group()
198 name += snprintf(name, end - name, "%s:%s", in tsm_mr_create_attribute_group()
199 tm->mrs[i].mr_name, in tsm_mr_create_attribute_group()
200 hash_algo_name[tm->mrs[i].mr_hash]); in tsm_mr_create_attribute_group()
203 return ERR_PTR(-EINVAL); in tsm_mr_create_attribute_group()
207 if (!strcmp(bap->attr.name, attrs[j]->attr.name)) in tsm_mr_create_attribute_group()
208 return ERR_PTR(-EINVAL); in tsm_mr_create_attribute_group()
210 if (tm->mrs[i].mr_flags & TSM_MR_F_READABLE) { in tsm_mr_create_attribute_group()
211 bap->attr.mode |= 0444; in tsm_mr_create_attribute_group()
212 bap->read = tm_digest_read; in tsm_mr_create_attribute_group()
215 if (tm->mrs[i].mr_flags & TSM_MR_F_WRITABLE) { in tsm_mr_create_attribute_group()
216 bap->attr.mode |= 0200; in tsm_mr_create_attribute_group()
217 bap->write = tm_digest_write; in tsm_mr_create_attribute_group()
220 bap->size = tm->mrs[i].mr_size; in tsm_mr_create_attribute_group()
221 bap->private = ctx; in tsm_mr_create_attribute_group()
227 return ERR_PTR(-EINVAL); in tsm_mr_create_attribute_group()
229 init_rwsem(&ctx->rwsem); in tsm_mr_create_attribute_group()
230 ctx->agrp.name = "measurements"; in tsm_mr_create_attribute_group()
231 ctx->agrp.bin_attrs = no_free_ptr(attrs); in tsm_mr_create_attribute_group()
232 ctx->tm = tm; in tsm_mr_create_attribute_group()
233 return &no_free_ptr(ctx)->agrp; in tsm_mr_create_attribute_group()
238 * tsm_mr_free_attribute_group() - frees the attribute group returned by
247 kfree(attr_grp->bin_attrs); in tsm_mr_free_attribute_group()