Message ID | 20211129153355.60338-4-roger.pau@citrix.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | libs/guest: new CPUID/MSR interface | expand |
On 29.11.2021 16:33, Roger Pau Monne wrote: > Introduce an interface that returns a specific leaf/subleaf from a cpu > policy in xen_cpuid_leaf_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. > > Note that callers of find_leaf need to be slightly adjusted to use the > new helper parameters. Is this sentence a leftover from an earlier version? I can't associate it with anything. > --- a/tools/libs/guest/xg_cpuid_x86.c > +++ b/tools/libs/guest/xg_cpuid_x86.c > @@ -855,6 +855,29 @@ int xc_cpu_policy_update_msrs(xc_interface *xch, xc_cpu_policy_t *policy, > return rc; > } > > +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) Is it common practice in libxc / libxg to have xch parameters even if they're unused? Jan
On Mon, Dec 06, 2021 at 04:25:36PM +0100, Jan Beulich wrote: > On 29.11.2021 16:33, Roger Pau Monne wrote: > > Introduce an interface that returns a specific leaf/subleaf from a cpu > > policy in xen_cpuid_leaf_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. > > > > Note that callers of find_leaf need to be slightly adjusted to use the > > new helper parameters. > > Is this sentence a leftover from an earlier version? I can't associate > it with anything. Yes, looks like. Will remove it. > > --- a/tools/libs/guest/xg_cpuid_x86.c > > +++ b/tools/libs/guest/xg_cpuid_x86.c > > @@ -855,6 +855,29 @@ int xc_cpu_policy_update_msrs(xc_interface *xch, xc_cpu_policy_t *policy, > > return rc; > > } > > > > +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) > > Is it common practice in libxc / libxg to have xch parameters even if > they're unused? I think it's good practice, as if we ever need to add to use ERROR or similar from those functions we would require xch, and it's better to avoid having to change the interface later. Thanks, Roger.
diff --git a/tools/include/xenguest.h b/tools/include/xenguest.h index e01f494b77..0a6fd99306 100644 --- a/tools/include/xenguest.h +++ b/tools/include/xenguest.h @@ -807,6 +807,9 @@ int xc_cpu_policy_update_cpuid(xc_interface *xch, xc_cpu_policy_t *policy, uint32_t nr); int xc_cpu_policy_update_msrs(xc_interface *xch, xc_cpu_policy_t *policy, const xen_msr_entry_t *msrs, uint32_t nr); +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); /* 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 b9e827ce7e..7779a3e1dd 100644 --- a/tools/libs/guest/xg_cpuid_x86.c +++ b/tools/libs/guest/xg_cpuid_x86.c @@ -855,6 +855,29 @@ int xc_cpu_policy_update_msrs(xc_interface *xch, xc_cpu_policy_t *policy, return rc; } +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) +{ + const struct cpuid_leaf *tmp; + + tmp = x86_cpuid_get_leaf(&policy->cpuid, leaf, subleaf); + if ( !tmp ) + { + /* Unable to find a matching leaf. */ + errno = ENOENT; + return -1; + } + + out->leaf = leaf; + out->subleaf = subleaf; + out->a = tmp->a; + out->b = tmp->b; + out->c = tmp->c; + out->d = tmp->d; + return 0; +} + bool xc_cpu_policy_is_compatible(xc_interface *xch, xc_cpu_policy_t *host, xc_cpu_policy_t *guest) {
Introduce an interface that returns a specific leaf/subleaf from a cpu policy in xen_cpuid_leaf_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. Note that callers of find_leaf need to be slightly adjusted to use the new helper parameters. Signed-off-by: Roger Pau Monné <roger.pau@citrix.com> --- Changes since v3: - Use x86_cpuid_get_leaf. Changes since v1: - Use find leaf. --- tools/include/xenguest.h | 3 +++ tools/libs/guest/xg_cpuid_x86.c | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+)