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

Re: [Xen-devel] [PATCH RFC] x86/amd: Avoid cpu_has_hypervisor evaluating true on native hardware


  • To: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • From: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Date: Tue, 28 Jan 2020 11:39:33 +0100
  • Authentication-results: esa3.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=roger.pau@xxxxxxxxxx; spf=Pass smtp.mailfrom=roger.pau@xxxxxxxxxx; spf=None smtp.helo=postmaster@xxxxxxxxxxxxxxx
  • Cc: Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Igor Druzhinin <igor.druzhinin@xxxxxxxxxx>
  • Delivery-date: Tue, 28 Jan 2020 10:39:58 +0000
  • Ironport-sdr: U3g/MxR7GOIC0OiP+9gC83u7mDjVlDEIbypm06LxWAiUEm4+HliFRzqST3wrybaXq5MeFm2zFt Cymp4Nf5ca+MxamG/IQTx7WpH1N469EtyHSzQQJ5g9cJSngMXEFBfUHg8IAlbTIct5Ypgdfg1z QVknif8ftpA/SrVJ+GNC8Y13VnX7m77N1oHLn4kqiGxV5Nduq0YATagYASp/D1vwQTT+PwAOgL tSfKudR/nTZ8Sa/b8VnVBUH9tU12jtJbFuT8yioK0d9i74OWda++lAki3UmuXvN8lcFyhIszsG a1w=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On Mon, Jan 27, 2020 at 08:21:21PM +0000, Andrew Cooper wrote:
> Currently when booting native on AMD hardware, cpuidmask_defaults._1cd gets
> configured with the HYPERVISOR bit before native CPUID is scanned for feature
> bits.
> 
> This results in cpu_has_hypervisor becoming set as part of identify_cpu(), and
> ends up appearing in the raw and host CPU policies.  Nothing has really cared
> in the past.
> 
> Alter amd_init_levelling() to exclude the HYPERVISOR bit from
> cpumask_defaults, and update domain_cpu_policy_changed() to allow it to be
> explicitly forwarded.
> 
> This in turn highlighted that dom0 construction was asymetric with domU
> construction, by not having any calls to domain_cpu_policy_changed().  Extend
> arch_domain_create() to always call domain_cpu_policy_changed().
> 
> Reported-by: Igor Druzhinin <igor.druzhinin@xxxxxxxxxx>
> Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
> ---
> CC: Jan Beulich <JBeulich@xxxxxxxx>
> CC: Wei Liu <wl@xxxxxxx>
> CC: Roger Pau Monné <roger.pau@xxxxxxxxxx>
> CC: Igor Druzhinin <igor.druzhinin@xxxxxxxxxx>
> 
> Without this fix, there is apparently a problem with Roger's "[PATCH v3 7/7]
> x86/tlb: use Xen L0 assisted TLB flush when available" on native AMD hardware.
> I haven't investgiated the issue with that patch specifically, because
> cpu_has_hypervisor being wrong is obviously a bug.

I've tested the series on one AMD box and it worked for me. Even if
cpu_has_hypervisor is set on real hardware the added call to
hypervisor_flush_tlb should be fine as ops is NULL in that case and
would just be a dummy (this obviously needs to be fixed so
cpu_has_hypervisor isn't true when not running virtualized).

> 
> This is one of two possible approaches, and both have their downsides.  This
> one takes an extra hit on context switches between PV vcpus and idle/hvm, as
> they will usually differ in HYPERVISOR bit.
> 
> The other approach is to order things more carefully so levelling is
> configured after scanning for cpuid bits, but that has the downside that it is
> very easy to regress.
> 
> Thoughts on which is the least-bad approach to take?  Having written this
> patch, I'm now erring on the side of doing it the other way.
> ---
>  xen/arch/x86/cpu/amd.c       | 3 ---
>  xen/arch/x86/domain.c        | 2 ++
>  xen/arch/x86/domctl.c        | 9 ++++++++-
>  xen/include/asm-x86/domain.h | 2 ++
>  4 files changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/xen/arch/x86/cpu/amd.c b/xen/arch/x86/cpu/amd.c
> index 8b5f0f2e4c..0906b23582 100644
> --- a/xen/arch/x86/cpu/amd.c
> +++ b/xen/arch/x86/cpu/amd.c
> @@ -297,9 +297,6 @@ static void __init noinline amd_init_levelling(void)
>                       ecx |= cpufeat_mask(X86_FEATURE_OSXSAVE);
>               edx |= cpufeat_mask(X86_FEATURE_APIC);
>  
> -             /* Allow the HYPERVISOR bit to be set via guest policy. */
> -             ecx |= cpufeat_mask(X86_FEATURE_HYPERVISOR);

We also seem to force X86_FEATURE_APIC into the policy, which seems
wrong?

I guess all AMD hardware Xen boots on has the APIC feature, so this
isn't a real issue, but still seems quite weird.

>               cpuidmask_defaults._1cd = ((uint64_t)ecx << 32) | edx;
>       }
>  
> diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
> index 28fefa1f81..316b801597 100644
> --- a/xen/arch/x86/domain.c
> +++ b/xen/arch/x86/domain.c
> @@ -665,6 +665,8 @@ int arch_domain_create(struct domain *d,
>       */
>      d->arch.x87_fip_width = cpu_has_fpu_sel ? 0 : 8;
>  
> +    domain_cpu_policy_changed(d);
> +
>      return 0;
>  
>   fail:
> diff --git a/xen/arch/x86/domctl.c b/xen/arch/x86/domctl.c
> index 5ed63ac10a..0627eb4e06 100644
> --- a/xen/arch/x86/domctl.c
> +++ b/xen/arch/x86/domctl.c
> @@ -48,7 +48,7 @@ static int gdbsx_guest_mem_io(domid_t domid, struct 
> xen_domctl_gdbsx_memio *iop)
>  }
>  #endif
>  
> -static void domain_cpu_policy_changed(struct domain *d)
> +void domain_cpu_policy_changed(struct domain *d)
>  {
>      const struct cpuid_policy *p = d->arch.cpuid;
>      struct vcpu *v;
> @@ -106,6 +106,13 @@ static void domain_cpu_policy_changed(struct domain *d)
>                      ecx = 0;
>                  edx = cpufeat_mask(X86_FEATURE_APIC);
>  
> +                /*
> +                 * If the Hypervisor bit is set in the policy, we can also
> +                 * forward it into real CPUID.
> +                 */
> +                if ( p->basic.hypervisor )
> +                    ecx |= cpufeat_mask(X86_FEATURE_HYPERVISOR);

Since the hypervisor bit will be part of both the HVM and PV max
policies, why do you need to explicitly allow it here?

Won't it be naturally added to the guest policy as the rest of
features?

Thanks, Roger.

_______________________________________________
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®.