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

Re: [PATCH] x86/svm: Adjust vNMI handling to update the cleanbit


  • To: Ross Lagerwall <ross.lagerwall@xxxxxxxxxx>, Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Date: Mon, 2 Nov 2026 20:34:07 +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=AOh2F4HBlOh17uZPy/+N5rIfIqTcLvr2vaT14vKYoA8=; b=mXEhoAhZYII5SCeAqrqOiLteN91K76gGcVe8MxKaPTfwhtZp/zJ2r+cpM20gwpk/4sxj9WpxdKVzIqWSRRf6kEwuCZlxKUcXq4WZTVvEst4nYe+QgNOQwhI/SBnRhGYDcOuBN7m2V0RKFdf7CEWXbRf4koojH12OvDopfNj3I0KLLfGY4IhpV3LtZdEPMslmutaV9cIX0zM0fXmdp/0bQqRve1twA/ctHoQX6uUMp99TxTuRxnz/An8dDn1GIFlWat757lJLEmnLi0HiDj2iamKkUKiOThHwVWJLh9wsgqhxb9TVTZntlnXS6UUX09hCfXW/AVG1ZA4D7gQVRP+HHw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ozR0zRSF2dMyTnsEii39pECfyiREhaPKOS70CO8+whGsOFwyMxCRMvWrFu0OWsRqH2zBILfgkG4/HIzQw5X/VVcvCsS54UN0o7k/MVHuaEBBMCZXpHcC/c8N9Ru6L/baNE0TywA8f6RukK41bZeIMoe2/DwZwkFqLz3A10wQkOa9FW9oe9qOVy2AQKRdZCbMDvagWAlPzIZVobQ1D8coub00AJuCeig7vdm/lGXd6BdINiJPViHkYLiU6h0ymD0/jIvhNjNId5NSCF+KLZJP9Lq9+byHc7pO0b/LdzSkGqQ5ko+B86ZdORom/vBYq7USUsDV0oBZggnJ3dsVdjuPhg==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=citrix.com header.i="@citrix.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"
  • Authentication-results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Autocrypt: addr=andrew.cooper3@xxxxxxxxxx; keydata= xsFNBFLhNn8BEADVhE+Hb8i0GV6mihnnr/uiQQdPF8kUoFzCOPXkf7jQ5sLYeJa0cQi6Penp VtiFYznTairnVsN5J+ujSTIb+OlMSJUWV4opS7WVNnxHbFTPYZVQ3erv7NKc2iVizCRZ2Kxn srM1oPXWRic8BIAdYOKOloF2300SL/bIpeD+x7h3w9B/qez7nOin5NzkxgFoaUeIal12pXSR Q354FKFoy6Vh96gc4VRqte3jw8mPuJQpfws+Pb+swvSf/i1q1+1I4jsRQQh2m6OTADHIqg2E ofTYAEh7R5HfPx0EXoEDMdRjOeKn8+vvkAwhviWXTHlG3R1QkbE5M/oywnZ83udJmi+lxjJ5 YhQ5IzomvJ16H0Bq+TLyVLO/VRksp1VR9HxCzItLNCS8PdpYYz5TC204ViycobYU65WMpzWe LFAGn8jSS25XIpqv0Y9k87dLbctKKA14Ifw2kq5OIVu2FuX+3i446JOa2vpCI9GcjCzi3oHV e00bzYiHMIl0FICrNJU0Kjho8pdo0m2uxkn6SYEpogAy9pnatUlO+erL4LqFUO7GXSdBRbw5 gNt25XTLdSFuZtMxkY3tq8MFss5QnjhehCVPEpE6y9ZjI4XB8ad1G4oBHVGK5LMsvg22PfMJ ISWFSHoF/B5+lHkCKWkFxZ0gZn33ju5n6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jYnHwn27hmxTC/7tvG3euCklmkn9Sl9IAKFu29RSo d5bD8kMSCYsTqtTfT6W4A3qHGvIDta3ptLYpIAOD2sY3GYq2nf3Bbzx81wZK14JdDDHUX2Rs 6+ahAA==
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Roger Pau Monné <roger@xxxxxxxxxxxxxx>, Teddy Astie <teddy.astie@xxxxxxxxxx>, Jason Andryuk <jason.andryuk@xxxxxxx>
  • Delivery-date: Mon, 02 Nov 2026 20:34:55 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 02/11/2026 6:16 pm, Andrew Cooper wrote:
> On 02/11/2026 4:12 pm, Ross Lagerwall wrote:
>>> From: Xen-devel <xen-devel-bounces@xxxxxxxxxxxxxxxxxxxx> on behalf of 
>>> Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
>>> Sent: Monday, November 02, 2026 13:54
>>> To: Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>
>>> Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>; Jan Beulich 
>>> <jbeulich@xxxxxxxx>; Roger Pau Monné <roger@xxxxxxxxxxxxxx>; Teddy Astie 
>>> <teddy.astie@xxxxxxxxxx>; Jason Andryuk <jason.andryuk@xxxxxxx>
>>> Subject: Re: [PATCH] x86/svm: Adjust vNMI handling to update the cleanbit
>>>
>>>
>>> On 02/11/2026 1:46 pm, Andrew Cooper wrote:
>>>> Despite prior information to the contrary, APM Vol2 revision 3.46 October 
>>>> 2026
>>>> has been adjusted to state that the vNMI fields in vINTR are covered by the
>>>> TPR cleanbit.
>>>>
>>>> Adjust svm_inject_nmi() and svm_set_interrupt_shadow() to use 
>>>> vmcb_set_vintr()
>>>> rather than writing into the VMCB directly.
>>>>
>>>> In svm_inject_nmi(), fix an inefficiency from the introduction of vNMI.  
>>>> Move
>>>> the reading of vmcb_get_general1_intercepts() to the point at which it is
>>>> used; tt does not need reading on the case that vNMIs are enabled.
>>>>
>>>> Fixes: 86a203ab8d38 ("x86/svm: Support vNMI on capable hardware")
>>>> Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
>>>> ---
>>>> CC: Jan Beulich <jbeulich@xxxxxxxx>
>>>> CC: Roger Pau Monné <roger@xxxxxxxxxxxxxx>
>>>> CC: Teddy Astie <teddy.astie@xxxxxxxxxx>
>>>> CC: Jason Andryuk <jason.andryuk@xxxxxxx>
>>> I forgot the extra comment.  This bug is hidden by:
>>>
>>>     /* The exit may have updated the TPR: reflect this in the hardware
>>> vtpr */
>>>     intr = vmcb_get_vintr(vmcb);
>>>     intr.fields.tpr =
>>>         (vlapic_get_reg(vlapic, APIC_TASKPRI) & 0xFF) >> 4;
>>>     vmcb_set_vintr(vmcb, intr);
>>> }
>>>
>>> at the very end of the vmexit handler which unconditionally writes vINTR
>>> and hits the cleanbit.
>>>
>>> This is an absurd codepath.  SVM has virtualised CR8 since the very
>>> beginning, and put in CR8_LEGACY for Windows to use even in 32bit mode,
>>> so the only path modifying TPR is a non-accelerated write to APIC_TPR. 
>>>  That path can be updated to modify vINTR, and this logic dropped.
>>>
>>> ~Andrew
>> The APM says "(Offset 60h–67h)" for this bit in the current and previous
>> versions. Perhaps that means that more or everything in that range may be
>> covered by this bit in future? In which case more extensive changes would be
>> needed to avoid future breakage.
> The vINTR field is complicated, because some bits are unconditional,
> while some are covered by a cleanbit.
>
> Byte 63h (V_INTR_MASKING, vGIF_EN, vNMI_EN, {,x2}AVIC_EN) all control
> virtualisation behaviour.  These are unconditional, and I bet the 3
> reserved bits in there will continue to behave in the same way when they
> are given meaning.
>
> All other bytes are state of the vCPU, and are (now documented to be)
> subject to the cleanbit.
>
>> On a related note, I see the APM says this:
>>> If any VMCB fields (excluding explicitly uncached fields) have been 
>>> modified,
>>> all clean bits that are undefined (within the scope of the hypervisor) must 
>>> be
>>> cleared to zero.
>> AFAICT Xen doesn't do this. Might that cause breakage in future?
> Fun...  That's incompatible with the previous sentence.
>
> Xen follows the previous advice, and sets:
>
>     vmcb->cleanbits.raw = ~0u;
>
> early(ish) in the VMExit handler.

It would appear that AMD reserve the right to retroactively introduce
cleanbits.

I maintain that it's absurd to suggest both "write ~0" and "clear all
cleanbits you don't know if you write anything".

The advice should be "write the cleanbits you know" in order to signify
the VMCB as clean.

~Andrew



 


Rackspace

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