1 /* Common data structures and functions consumed by hypervisor and toolstack */
2 #ifndef XEN_LIB_X86_MSR_H
3 #define XEN_LIB_X86_MSR_H
4 
5 /* Maximum number of MSRs written when serialising msr_policy. */
6 #define MSR_MAX_SERIALISED_ENTRIES 2
7 
8 /* MSR policy object for shared per-domain MSRs */
9 struct msr_policy
10 {
11     /*
12      * 0x000000ce - MSR_INTEL_PLATFORM_INFO
13      *
14      * This MSR is non-architectural, but for simplicy we allow it to be read
15      * unconditionally.  CPUID Faulting support can be fully emulated for HVM
16      * guests so can be offered unconditionally, while support for PV guests
17      * is dependent on real hardware support.
18      */
19     union {
20         uint32_t raw;
21         struct {
22             uint32_t :31;
23             bool cpuid_faulting:1;
24         };
25     } platform_info;
26 
27     /*
28      * 0x0000010a - MSR_ARCH_CAPABILITIES
29      *
30      * This is an Intel-only MSR, which provides miscellaneous enumeration,
31      * including those which indicate that microarchitectrual sidechannels are
32      * fixed in hardware.
33      */
34     union {
35         uint32_t raw;
36         struct {
37             bool rdcl_no:1;
38             bool ibrs_all:1;
39             bool rsba:1;
40             bool skip_l1dfl:1;
41             bool ssb_no:1;
42             bool mds_no:1;
43             bool if_pschange_mc_no:1;
44             bool tsx_ctrl:1;
45             bool taa_no:1;
46         };
47     } arch_caps;
48 };
49 
50 #ifdef __XEN__
51 #include <public/arch-x86/xen.h>
52 typedef XEN_GUEST_HANDLE_64(xen_msr_entry_t) msr_entry_buffer_t;
53 #else
54 #include <xen/arch-x86/xen.h>
55 typedef xen_msr_entry_t msr_entry_buffer_t[];
56 #endif
57 
58 /**
59  * Serialise an msr_policy object into an array.
60  *
61  * @param policy     The msr_policy to serialise.
62  * @param msrs       The array of msrs to serialise into.
63  * @param nr_entries The number of entries in 'msrs'.
64  * @returns -errno
65  *
66  * Writes at most MSR_MAX_SERIALISED_ENTRIES.  May fail with -ENOBUFS if the
67  * buffer array is too short.  On success, nr_entries is updated with the
68  * actual number of msrs written.
69  */
70 int x86_msr_copy_to_buffer(const struct msr_policy *policy,
71                            msr_entry_buffer_t msrs, uint32_t *nr_entries);
72 
73 /**
74  * Unserialise an msr_policy object from an array of msrs.
75  *
76  * @param policy     The msr_policy object to unserialise into.
77  * @param msrs       The array of msrs to unserialise from.
78  * @param nr_entries The number of entries in 'msrs'.
79  * @param err_msr    Optional hint for error diagnostics.
80  * @returns -errno
81  *
82  * Reads at most MSR_MAX_SERIALISED_ENTRIES.  May fail for a number of reasons
83  * based on the content in an individual 'msrs' entry, including the MSR index
84  * not being valid in the policy, the flags field being nonzero, or if the
85  * value provided would truncate when stored in the policy.  In such cases,
86  * the optional err_* pointer will identify the problematic MSR.
87  *
88  * No content validation is performed on the data stored in the policy object.
89  */
90 int x86_msr_copy_from_buffer(struct msr_policy *policy,
91                              const msr_entry_buffer_t msrs, uint32_t nr_entries,
92                              uint32_t *err_msr);
93 
94 #endif /* !XEN_LIB_X86_MSR_H */
95 
96 /*
97  * Local variables:
98  * mode: C
99  * c-file-style: "BSD"
100  * c-basic-offset: 4
101  * tab-width: 4
102  * indent-tabs-mode: nil
103  * End:
104  */
105