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

Re: [PATCH v1 4/8] x86/traps: Remove lazy FPU support


  • To: Ross Lagerwall <ross.lagerwall@xxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Date: Thu, 19 Mar 2026 18:22:38 +0000
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=sPPIzCjxW1GDjXGHKB+kaFx36wOT27dml5ySYJnRBYs=; b=vqbKoCSmqY56fcCYZ5569J4CGWwP1sgfqGPLaSMlwSE2B9URgDkGSKXAYyuR2KVEegtQEpO7LOm+PS5LICukLeiVE1Wk7wsgrsWWpBdSKMw5OUWARbOW4GP30W9hHesTomicvtuUCas5YBPzQpN88lwVcKBFvXCvCki136M0SIZfa02eLV8QZFY5iMP8sq94iCeCA7YOSybJV8c4f3jscd5WppsulbCy0H7qyVnSIF+pBNhHwCQcCA9oF/K6S2ySsU3V1fKCFwqx3arpSkn14UIG4JBp7YBDEjhiAx1q3WTvoAx+XonPDlzcy/HIJtqPaSv9sWgupuN34rs68vz5NA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=pRqtG/wFvhK74Ju9qC2DB1maaA8ev5xyEnntAyrE6CXPO6IwHX3l5c5U8pcLddNRuu6mGoyG8LxTNvV1rbv7s4hHyVh8u9aFyWJCODNRxPo89ysqoOUxEGUIhFsaL3EPL4Qsx8KnujMU097zPrQMZqvfEGt0hZTY6N1ymh6T2UJilHDlynNYD4AgIIwgtU/kCAHRYiBLR+C/4o1gg4JYIUMZtNg2gBK42cxmCF7V4m6zUY2IUjxthv25rD9QVFmlTTWj8zmZTx3FNrZ1QCKNMRmwkTaPgv9KJhFuctlxa7UqUYGjrn9UvNQmU68U7NU7k2VCOvgIVghMetf7Wog2lg==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Delivery-date: Thu, 19 Mar 2026 18:22:58 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 19/03/2026 1:29 pm, Ross Lagerwall wrote:
> From: Wei Liu <wei.liu2@xxxxxxxxxx>
>
> Remove lazy FPU support from the #DNA exception handler used by PV

It's the #NM exception handler.

The short name is "No Math[sic]", despite the long name being "Device
Not Available".

> guests since fully_eager_fpu is now always true.
>
> Signed-off-by: Ross Lagerwall <ross.lagerwall@xxxxxxxxxx>
> Signed-off-by: Wei Liu <wei.liu2@xxxxxxxxxx>

These two tags need reversing.  Technically this says that Wei
reviewed/accepted the part of the patch that was your changes.

> diff --git a/xen/arch/x86/traps.c b/xen/arch/x86/traps.c
> index b6b119769722..fb1b94245850 100644
> --- a/xen/arch/x86/traps.c
> +++ b/xen/arch/x86/traps.c
> @@ -2045,15 +2045,17 @@ void asmlinkage do_device_not_available(struct 
> cpu_user_regs *regs)
>      }
>  
>  #ifdef CONFIG_PV
> -    vcpu_restore_fpu_lazy(curr);
> +    BUG_ON(!(curr->arch.pv.ctrlreg[0] & X86_CR0_TS));

I'm not sure if this is safe.

Firstly, since Wei wrote the patch originally, a new source of #NM
exceptions has come into existence.  AMX shouldn't be enabled for VMs
yet, but this ought to be 

    if ( !... )
    {
        ASSERT_UNREACHABLE();
        domain_crash(...);
    }

to be less fatal.

Also, at this point in the series, cpu_init() still sets TS, as does
vcpu_save_fpu().  It's far from clear that TS is only set when the guest
wants it, although we have at least excluded the Xen paths by this point
in the handler.

> -    if ( curr->arch.pv.ctrlreg[0] & X86_CR0_TS )
> -    {
> -        pv_inject_hw_exception(X86_EXC_NM, X86_EVENT_NO_EC);
> -        curr->arch.pv.ctrlreg[0] &= ~X86_CR0_TS;
> -    }
> -    else
> -        TRACE_TIME(TRC_PV_MATH_STATE_RESTORE);
> +    /*
> +     * PV ABI QUIRK: Classic Xen kernels (2.6.18 and SLES 11 SP4's
> +     * 3.0) rely on Xen to clear TS. PVOPS kernels (3.0, 3.16 and 4.15
> +     * are checked) always clear TS themselves.
> +     */
> +    clts();

I think this wants wording differently.

"For better or worse, Xen's ABI with PV guests always clears TS on an
#NM exception.  Classic-xen Linux depends on this."

The behaviour of obsolete PVOps kernels isn't relevant to the ABI, and
now that Linux is strictly eager too, I doubt this statement is accurate
any more.

> +
> +    pv_inject_hw_exception(X86_EXC_NM, X86_EVENT_NO_EC);
> +    curr->arch.pv.ctrlreg[0] &= ~X86_CR0_TS;

Swap these two operations.  The optimiser will then be able to tailcall
pv_inject_hw_exception().

Clearing the guest TS ought to be tied to the clts() operation anyway.

~Andrew



 


Rackspace

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