diff mbox series

[v5,05/12] libs/guest: allow fetching a specific MSR entry from a cpu policy

Message ID 20211129153355.60338-6-roger.pau@citrix.com (mailing list archive)
State Superseded
Headers show
Series libs/guest: new CPUID/MSR interface | expand

Commit Message

Roger Pau Monne Nov. 29, 2021, 3:33 p.m. UTC
Introduce an interface that returns a specific MSR entry from a cpu
policy in xen_msr_entry_t format.

This is useful to callers can peek data from the opaque
xc_cpu_policy_t type.

No caller of the interface introduced on this patch.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
---
Changes since v3:
 - Use x86_msr_get_entry.

Changes since v1:
 - Introduce a helper to perform a binary search of the MSR entries
   array.
---
 tools/include/xenguest.h        |  2 ++
 tools/libs/guest/xg_cpuid_x86.c | 20 ++++++++++++++++++++
 2 files changed, 22 insertions(+)

Comments

Jan Beulich Dec. 6, 2021, 3:27 p.m. UTC | #1
On 29.11.2021 16:33, Roger Pau Monne wrote:
> --- a/tools/libs/guest/xg_cpuid_x86.c
> +++ b/tools/libs/guest/xg_cpuid_x86.c
> @@ -878,6 +878,26 @@ int xc_cpu_policy_get_cpuid(xc_interface *xch, const xc_cpu_policy_t *policy,
>      return 0;
>  }
>  
> +int xc_cpu_policy_get_msr(xc_interface *xch, const xc_cpu_policy_t *policy,
> +                          uint32_t msr, xen_msr_entry_t *out)
> +{
> +    const uint64_t *val;
> +
> +    *out = (xen_msr_entry_t){};

Unless there's a specific reason for the divergence, this just-in-
case initialization should imo be consistently there (or absent)
in both the MSR and the CPUID function.

Jan
Roger Pau Monne Jan. 11, 2022, 11:45 a.m. UTC | #2
On Mon, Dec 06, 2021 at 04:27:25PM +0100, Jan Beulich wrote:
> On 29.11.2021 16:33, Roger Pau Monne wrote:
> > --- a/tools/libs/guest/xg_cpuid_x86.c
> > +++ b/tools/libs/guest/xg_cpuid_x86.c
> > @@ -878,6 +878,26 @@ int xc_cpu_policy_get_cpuid(xc_interface *xch, const xc_cpu_policy_t *policy,
> >      return 0;
> >  }
> >  
> > +int xc_cpu_policy_get_msr(xc_interface *xch, const xc_cpu_policy_t *policy,
> > +                          uint32_t msr, xen_msr_entry_t *out)
> > +{
> > +    const uint64_t *val;
> > +
> > +    *out = (xen_msr_entry_t){};
> 
> Unless there's a specific reason for the divergence, this just-in-
> case initialization should imo be consistently there (or absent)
> in both the MSR and the CPUID function.

Right - will add the initialization to the CPUID function.

Thanks, Roger.
diff mbox series

Patch

diff --git a/tools/include/xenguest.h b/tools/include/xenguest.h
index 0a6fd99306..2672fd043c 100644
--- a/tools/include/xenguest.h
+++ b/tools/include/xenguest.h
@@ -810,6 +810,8 @@  int xc_cpu_policy_update_msrs(xc_interface *xch, xc_cpu_policy_t *policy,
 int xc_cpu_policy_get_cpuid(xc_interface *xch, const xc_cpu_policy_t *policy,
                             uint32_t leaf, uint32_t subleaf,
                             xen_cpuid_leaf_t *out);
+int xc_cpu_policy_get_msr(xc_interface *xch, const xc_cpu_policy_t *policy,
+                          uint32_t msr, xen_msr_entry_t *out);
 
 /* Compatibility calculations. */
 bool xc_cpu_policy_is_compatible(xc_interface *xch, xc_cpu_policy_t *host,
diff --git a/tools/libs/guest/xg_cpuid_x86.c b/tools/libs/guest/xg_cpuid_x86.c
index 7779a3e1dd..859c885c15 100644
--- a/tools/libs/guest/xg_cpuid_x86.c
+++ b/tools/libs/guest/xg_cpuid_x86.c
@@ -878,6 +878,26 @@  int xc_cpu_policy_get_cpuid(xc_interface *xch, const xc_cpu_policy_t *policy,
     return 0;
 }
 
+int xc_cpu_policy_get_msr(xc_interface *xch, const xc_cpu_policy_t *policy,
+                          uint32_t msr, xen_msr_entry_t *out)
+{
+    const uint64_t *val;
+
+    *out = (xen_msr_entry_t){};
+
+    val = x86_msr_get_entry(&policy->msr, msr);
+    if ( !val )
+    {
+        errno = ENOENT;
+        return -1;
+    }
+
+    out->idx = msr;
+    out->val = *val;
+
+    return 0;
+}
+
 bool xc_cpu_policy_is_compatible(xc_interface *xch, xc_cpu_policy_t *host,
                                  xc_cpu_policy_t *guest)
 {