[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH] libx86: Introduce wrappers for extracting XCR0/XSS from a cpuid policy



>>> On 23.05.19 at 12:27, <andrew.cooper3@xxxxxxxxxx> wrote:
> --- a/xen/arch/x86/xstate.c
> +++ b/xen/arch/x86/xstate.c
> @@ -660,9 +660,7 @@ static bool valid_xcr0(u64 xcr0)
>  int validate_xstate(const struct domain *d, uint64_t xcr0, uint64_t 
> xcr0_accum,
>                      const struct xsave_hdr *hdr)
>  {
> -    const struct cpuid_policy *cp = d->arch.cpuid;
> -    uint64_t xcr0_max =
> -        ((uint64_t)cp->xstate.xcr0_high << 32) | cp->xstate.xcr0_low;
> +    uint64_t xcr0_max = cpuid_policy_xcr0(d->arch.cpuid);
>      unsigned int i;
>  
>      if ( (hdr->xstate_bv & ~xcr0_accum) ||
> @@ -686,9 +684,7 @@ int validate_xstate(const struct domain *d, uint64_t 
> xcr0, uint64_t xcr0_accum,
>  int handle_xsetbv(u32 index, u64 new_bv)
>  {
>      struct vcpu *curr = current;
> -    const struct cpuid_policy *cp = curr->domain->arch.cpuid;
> -    uint64_t xcr0_max =
> -        ((uint64_t)cp->xstate.xcr0_high << 32) | cp->xstate.xcr0_low;
> +    uint64_t xcr0_max = cpuid_policy_xcr0(curr->domain->arch.cpuid);

In both cases the variables are more appropriately named than
the new helper. While I agree it's slightly more typing, did you
consider calling it cpuid_policy_xcr0_max()?

> --- a/xen/include/xen/lib/x86/cpuid.h
> +++ b/xen/include/xen/lib/x86/cpuid.h
> @@ -308,6 +308,18 @@ static inline void cpuid_featureset_to_policy(
>      p->feat._7a1  = fs[FEATURESET_7a1];
>  }
>  
> +static inline uint64_t cpuid_policy_xcr0(const struct cpuid_policy *p)
> +{
> +    return ((uint64_t)p->xstate.xcr0_high << 32) | p->xstate.xcr0_low;
> +}
> +
> +static inline uint64_t cpuid_policy_xstates(const struct cpuid_policy *p)
> +{
> +    uint64_t val = p->xstate.xcr0_high | p->xstate.xss_high;
> +
> +    return (val << 32) | p->xstate.xcr0_low | p->xstate.xss_low;
> +}

How about also having cpuid_policy_xss() (or cpuid_policy_xss_max())
and then simply making cpuid_policy_xstates() combine the two
results?

Anyway, as I can also live with things as they are, with or without
either of the suggested changes
Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>

Jan



_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.