[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH for-4.22 v6] x86/svm: Support vNMI on capable hardware
- To: Teddy Astie <teddy.astie@xxxxxxxxxx>, Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>
- From: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
- Date: Fri, 15 May 2026 11:32:49 +0100
- 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=EiQOaaIiVKnCo8ByStn4RAq7eucU797GJ07Fezt0PCU=; b=Ae3wmpgjnGfLAJ0hg1y9SiJQefGGw219+gFSIwvSILMqmY39oPn+W6sc0L2FLekYjQCr2FiEUkwxnSvD3aAlDrD0zhg3St/MuEx34d5v7E1akLRe24W5NR7oQkPJXC0D09rpoaovQyL8K4SR97AhhOEQktOnkPNKi9I26mde8QCiRWF9IRFQVO8tk0AFzyZ9jqintEoPIgrMqN5YOi7t2hOLWeHE4B44R7md6SWSiJSei8G6vrhs452G2rw9ezqCR4KgLKHXQsJ7/l5N55m/wFeXpE4Ln7R2B0cyXA0Q6aCcCycyoVjYboHBvn6jDUqEpecsR8SetMK6KxE9mEXlqw==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=MrAT/WTUpEBLyeOkjbZIbqDAkx1isPYJwQ+DsraeGwYA599Ov5tHQ75S+w5BJZWagd5A99uaGoYPgGTg+S1R1Iw94+R8a/mbU4u5fYL3HsfSYShgiOj/n8CBp3+01TOYZZ3tXqLKOj+Rm9gV5gCwKMAmSzPodbBFVNFsmqWDkjOBPK/mPiR+W+ISQnoMFZJa+KuKxVVBmfNDZf2vD2SNmvqgJE1rS3+bL0u0c53WLdrN9mYAZgV39hwYkJpKDiXABzweFZcNMpK8fb3uqDSoDGplBMunXFc7PvcCEATyvZcaKYA8MDA+0RLsc9dGdD14d6f6aH1zqfCBjE8KpAF2pA==
- 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: 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/FOdEx4B8cMJt+cWwARA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Cklmkn9Sl9IAKFu29RSo d5bD8kMSCYsTqtTfT6W4A3qHGvIDta3ptLYpIAOD2sY3GYq2nf3Bbzx81wZK14JdDDHUX2Rs 6+ahAA==
- Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Abdelkareem Abdelsaamad <abdelkareem.abdelsaamad@xxxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Jason Andryuk <jason.andryuk@xxxxxxx>, Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx>
- Delivery-date: Fri, 15 May 2026 10:34:18 +0000
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
On 15/05/2026 10:20 am, Teddy Astie wrote:
> Le 14/05/2026 à 19:59, Andrew Cooper a écrit :
>> From: Abdelkareem Abdelsaamad <abdelkareem.abdelsaamad@xxxxxxxxxx>
>>
>> Starting with Zen4, AMD CPUs can virtualise NMIs for a guest. On older
>> hardware, determining when an NMI is safe to deliver is a challenge
>> and Xen
>> does not handle all corner cases correctly.
>>
>> With vNMI, there is an enablement bit and two new bits of state in
>> the VMCB; a
>> pending bit, and a blocked bit. These directly map to the CPU state for
>> handling NMIs, and are maintained by hardware during the running of
>> the vCPU.
>>
>> When vNMI is enabled, have svm_{get,set}set_interrupt_shadow() work
>> in terms
>> of the vnmi_blocking bit rather than the IRET intercept. This allows an
>> emulated IRET instruction to re-enable NMIs.
>>
>> When injecting a new NMI, simply set the vnmi_pending bit; hardware will
>> deliver the NMI to the guest at the next suitable juncture.
>>
>> One complication is that, when delivering a second NMI before the
>> first has
>> completed, the mix between common HVM logic and SVM specific logic
>> will try to
>> open an NMI window, malfunctioning as it does so. When vNMI is
>> enabled, short
>> circuit this to not consider NMIs blocked.
>>
>> Signed-off-by: Abdelkareem Abdelsaamad
>> <abdelkareem.abdelsaamad@xxxxxxxxxx>
>> Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
>> ---
>> CC: Jan Beulich <jbeulich@xxxxxxxx>
>> CC: Roger Pau Monné <roger.pau@xxxxxxxxxx>
>> CC: Teddy Astie <teddy.astie@xxxxxxxxxx>
>> CC: Jason Andryuk <jason.andryuk@xxxxxxx>
>> CC: Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx>
>>
>> For 4.22. This is somewhat overdue and makes a concrete improvement
>> to NMI
>> handling on recent AMD hardware.
>>
>> v6:
>> * Plumb through svm_{get,set}set_interrupt_shadow() so that
>> emulated IRET
>> works, as requested several times during review of earlier
>> revisions.
>> * Expand the commit message
>>
>> The !vNMI case is even more broken than I'd realised. Besides the
>> "what if
>> the IRET faults?" problem, svm_enable_intr_window() basically ignores
>> the NMI
>> case and simply re-enters the VM. This causes the pending NMI to
>> only be
>> injected next time there is a VMExit.
>
> Does that happens often in practice ?
Which?
VMs don't tend to make as much use of NMIs as native does.
IRET faulting is mostly relegated to misbehaving userspace. E.g. one
thread uses SYSCALL_modify_ldt to invalidate the %ss/%cs that another
thread was running on, at which point the next reload of that segment
(generally the next IRET) will fault. But to attack this, userspace
needs to hit the IRET of the NMI handler with this race, and avoid the
IRET of all other interrupts and exceptions. Perf counters is the
typically the only way userspace has to influence this, and we don't
have PMU available to guests by default.
Then we get into differences between Intel and AMD. Intel unblocks NMIs
even if the IRET faults. AMD unblocks NMIs only in the IRET completes.
With Xen's current SVM code and without vNMI, IRETs get Intel-like
behaviour WRT faulting, and already pending NMIs get delayed. Software
needs to cope with the former, and the latter (while far from ideal) is
generally indistinguishable from the NMI being slightly later than it
was in practice.
> Reviewed-by: Teddy Astie <teddy.astie@xxxxxxxxxx>
Thanks.
~Andrew
|