xref: /linux/include/linux/tsm-mr.h (revision ae5ec8adb8ec9c2aa916f853737c101faa87e5ba)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 
3 #ifndef __TSM_MR_H
4 #define __TSM_MR_H
5 
6 #include <crypto/hash_info.h>
7 
8 /**
9  * struct tsm_measurement_register - describes an architectural measurement
10  * register (MR)
11  * @mr_name: name of the MR
12  * @mr_value: buffer containing the current value of the MR
13  * @mr_size: size of the MR - typically the digest size of @mr_hash
14  * @mr_flags: bitwise OR of one or more flags, detailed below
15  * @mr_hash: optional hash identifier defined in include/uapi/linux/hash_info.h.
16  *
17  * A CC guest driver encloses an array of this structure in struct
18  * tsm_measurements to detail the measurement facility supported by the
19  * underlying CC hardware.
20  *
21  * @mr_name and @mr_value must stay valid until this structure is no longer in
22  * use.
23  *
24  * @mr_flags is the bitwise-OR of zero or more of the flags below.
25  *
26  * * %TSM_MR_F_READABLE - the sysfs attribute corresponding to this MR is readable.
27  * * %TSM_MR_F_WRITABLE - the sysfs attribute corresponding to this MR is writable.
28  *   The semantics is typically to extend the MR but could vary depending on the
29  *   architecture and the MR.
30  * * %TSM_MR_F_LIVE - this MR's value may differ from the last value written, so
31  *   must be read back from the underlying CC hardware/firmware.
32  * * %TSM_MR_F_RTMR - bitwise-OR of %TSM_MR_F_LIVE and %TSM_MR_F_WRITABLE.
33  * * %TSM_MR_F_NOHASH - this MR does NOT have an associated hash algorithm.
34  *   @mr_hash will be ignored when this flag is set.
35  */
36 struct tsm_measurement_register {
37 	const char *mr_name;
38 	void *mr_value;
39 	u32 mr_size;
40 	u32 mr_flags;
41 	enum hash_algo mr_hash;
42 };
43 
44 #define TSM_MR_F_NOHASH 1
45 #define TSM_MR_F_WRITABLE 2
46 #define TSM_MR_F_READABLE 4
47 #define TSM_MR_F_LIVE 8
48 #define TSM_MR_F_RTMR (TSM_MR_F_LIVE | TSM_MR_F_WRITABLE)
49 
50 #define TSM_MR_(mr, hash)                              \
51 	.mr_name = #mr, .mr_size = hash##_DIGEST_SIZE, \
52 	.mr_hash = HASH_ALGO_##hash, .mr_flags = TSM_MR_F_READABLE
53 
54 /**
55  * struct tsm_measurements - defines the CC architecture specific measurement
56  * facility and methods for updating measurement registers (MRs)
57  * @mrs: Array of MR definitions.
58  * @nr_mrs: Number of elements in @mrs.
59  * @refresh: Callback function to load/sync all MRs from TVM hardware/firmware
60  *           into the kernel cache.
61  * @write: Callback function to write to the MR specified by the parameter @mr.
62  *         Typically, writing to an MR extends the input buffer to that MR.
63  *
64  * The @refresh callback is invoked when an MR with %TSM_MR_F_LIVE set is being
65  * read and the cache is stale. It must reload all MRs with %TSM_MR_F_LIVE set.
66  * The function parameter @tm is a pointer pointing back to this structure.
67  *
68  * The @write callback is invoked whenever an MR is being written. It takes two
69  * additional parameters besides @tm:
70  *
71  * * @mr - points to the MR (an element of @tm->mrs) being written.
72  * * @data - contains the bytes to write and whose size is @mr->mr_size.
73  *
74  * Both @refresh and @write should return 0 on success and an appropriate error
75  * code on failure.
76  */
77 struct tsm_measurements {
78 	const struct tsm_measurement_register *mrs;
79 	size_t nr_mrs;
80 	int (*refresh)(const struct tsm_measurements *tm);
81 	int (*write)(const struct tsm_measurements *tm,
82 		     const struct tsm_measurement_register *mr, const u8 *data);
83 };
84 
85 const struct attribute_group *
86 tsm_mr_create_attribute_group(const struct tsm_measurements *tm);
87 void tsm_mr_free_attribute_group(const struct attribute_group *attr_grp);
88 
89 #endif
90