From: Andrew Cooper <Andrew.Cooper3@citrix.com>
To: "H. Peter Anvin" <hpa@zytor.com>,
Peter Zijlstra <peterz@infradead.org>,
Paolo Bonzini <pbonzini@redhat.com>
Cc: "Li, Xin3" <xin3.li@intel.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"x86@kernel.org" <x86@kernel.org>,
"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
"tglx@linutronix.de" <tglx@linutronix.de>,
"mingo@redhat.com" <mingo@redhat.com>,
"bp@alien8.de" <bp@alien8.de>,
"dave.hansen@linux.intel.com" <dave.hansen@linux.intel.com>,
"Christopherson,, Sean" <seanjc@google.com>,
Kevin Tian <kevin.tian@intel.com>,
Andrew Cooper <Andrew.Cooper3@citrix.com>
Subject: Re: [RESEND PATCH 5/6] KVM: x86/VMX: add kvm_vmx_reinject_nmi_irq() for NMI/IRQ reinjection
Date: Sat, 12 Nov 2022 00:08:11 +0000 [thread overview]
Message-ID: <3435ccbf-8ca4-19ca-ca34-dbb1a551b103@citrix.com> (raw)
In-Reply-To: <8D824B88-1EBB-4CEC-9D1D-89123D536500@zytor.com>
On 11/11/2022 22:22, H. Peter Anvin wrote:
> On November 11, 2022 8:35:30 AM PST, Andrew Cooper <Andrew.Cooper3@citrix.com> wrote:
>> On 11/11/2022 14:23, Peter Zijlstra wrote:
>>> On Fri, Nov 11, 2022 at 01:48:26PM +0100, Paolo Bonzini wrote:
>>>> On 11/11/22 13:19, Peter Zijlstra wrote:
>>>>> On Fri, Nov 11, 2022 at 01:04:27PM +0100, Paolo Bonzini wrote:
>>>>>> On Intel you can optionally make it hold onto IRQs, but NMIs are always
>>>>>> eaten by the VMEXIT and have to be reinjected manually.
>>>>> That 'optionally' thing worries me -- as in, KVM is currently
>>>>> opting-out?
>>>> Yes, because "If the “process posted interrupts” VM-execution control is 1,
>>>> the “acknowledge interrupt on exit” VM-exit control is 1" (SDM 26.2.1.1,
>>>> checks on VM-Execution Control Fields). Ipse dixit. Posted interrupts are
>>>> available and used on all processors since I think Ivy Bridge.
>> On server SKUs. Client only got "virtual interrupt processing" fairly
>> recently IIRC, which is the CPU-side property which matters.
>>
>>> (imagine the non-coc compliant reaction here)
>>>
>>> So instead of fixing it, they made it worse :-(
>>>
>>> And now FRED is arguably making it worse again, and people wonder why I
>>> hate virt...
>> The only FRED-compatible fix is to send a self-NMI, because because you
>> may need a CSL change too.
>>
>> VT-x *does* hold the NMI latch (for VMEXIT_REASON NMI), so it's self-NMI
>> and then enable_nmi()s.
>>
>> Except the IRET to self won't work - it will need to be ERETS-to-self.
>> Which I think is fine.
>>
>> But what isn't fine is the fact that a self-NMI doesn't deliver
>> synchronously, so you need to wait until it is pending, before enabling
>> NMIs. (Well, actually you need to ensure that it's definitely delivered
>> before re-entering the VM).
>>
>> And I'm totally out of ideas here...
>>
>> ~Andrew
>>
> There is no fundamental reason to do a CSL/IST change if you happen to know a priori that the stack is in a valid state to have the NMI frame on it; that is:
>
> 1. Not deep into a nested I/O layer;
> 2. Valid, and not in flux in any way.
3. The NMI handler doesn't depend on being run on the alternate stack.
> Since this reinject will always be in a well-defined location, that's fine.
>
> So I think *that* concern is not actually an issue.
>
> Again, note that this is not a FRED-specific problem.
Hmm yeah. On further consideration, I don't think FRED is relevant here
(outside of a few minor details).
The VMExit behaviour is simply that of the NMI handler but without an
exception frame on the stack. The early asm is walking on egg-shells
with respect to the NMI latch, just like the regular NMI handler is.
Peter is correct that once you leave the VMExit handler's noinstr
region, a plethora of things can re-enable NMIs behind your back. And
this happening in practice will end up with you logically taking NMIs
out of order.
Whether this matters or not is a different question. Right now, NMI is
"just" an edge triggered interrupt, but a theoretical future with NMI
vectors might have some fun causality bugs to contend with.
If the out-of-order NMIs isn't a major concern, then a self-NMI is the
simple way to invoke the NMI handler in a context it can cope with.
Otherwise, the VMExit handler's instr region has to do the handoff when
it's in the same state that the NMI handler is expecting.
~Andrew
next prev parent reply other threads:[~2022-11-12 0:08 UTC|newest]
Thread overview: 56+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-10 6:15 [RESEND PATCH 0/6] x86/traps,VMX: implement software based NMI/IRQ dispatch for VMX " Xin Li
2022-11-10 6:15 ` [RESEND PATCH 1/6] x86/traps: let common_interrupt() handle IRQ_MOVE_CLEANUP_VECTOR Xin Li
2022-11-10 18:59 ` Ashok Raj
2022-11-10 22:09 ` Li, Xin3
2022-11-10 6:15 ` [RESEND PATCH 2/6] x86/traps: add a system interrupt table for system interrupt dispatch Xin Li
2022-11-10 8:56 ` Peter Zijlstra
2022-11-10 19:55 ` Li, Xin3
2022-11-10 20:36 ` Li, Xin3
2022-11-10 21:12 ` Nathan Chancellor
2022-11-10 23:00 ` Li, Xin3
2022-11-11 0:08 ` Nathan Chancellor
2022-11-11 3:03 ` Li, Xin3
2022-11-11 8:58 ` Peter Zijlstra
2022-11-11 1:12 ` Tian, Kevin
2022-11-11 3:54 ` Li, Xin3
2022-11-11 8:55 ` Peter Zijlstra
2022-11-11 22:07 ` H. Peter Anvin
2022-11-12 9:47 ` Peter Zijlstra
2022-11-10 6:15 ` [RESEND PATCH 3/6] x86/traps: add install_system_interrupt_handler() Xin Li
2022-11-10 6:15 ` [RESEND PATCH 4/6] x86/traps: add external_interrupt() to dispatch external interrupts Xin Li
2022-11-10 16:24 ` Sean Christopherson
2022-11-10 18:02 ` Li, Xin3
2022-11-10 20:10 ` Sean Christopherson
2022-11-10 6:15 ` [RESEND PATCH 5/6] KVM: x86/VMX: add kvm_vmx_reinject_nmi_irq() for NMI/IRQ reinjection Xin Li
2022-11-10 9:03 ` Peter Zijlstra
2022-11-10 20:53 ` Li, Xin3
2022-11-11 9:15 ` Peter Zijlstra
2022-11-11 12:04 ` Paolo Bonzini
2022-11-11 12:19 ` Peter Zijlstra
2022-11-11 12:48 ` Paolo Bonzini
2022-11-11 14:23 ` Peter Zijlstra
2022-11-11 16:35 ` Andrew Cooper
2022-11-11 22:22 ` H. Peter Anvin
2022-11-12 0:08 ` Andrew Cooper [this message]
2022-11-11 18:06 ` Li, Xin3
2022-11-11 19:33 ` Peter Zijlstra
2022-11-12 6:35 ` Li, Xin3
2022-11-14 4:39 ` Li, Xin3
2022-11-14 9:08 ` Peter Zijlstra
2022-11-15 7:50 ` Li, Xin3
2022-11-15 9:17 ` Peter Zijlstra
2022-11-17 3:37 ` Li, Xin3
2022-11-17 15:51 ` Sean Christopherson
2022-11-18 0:05 ` Li, Xin3
2022-11-22 13:00 ` Li, Xin3
2022-11-22 20:52 ` Sean Christopherson
2022-11-23 8:31 ` Li, Xin3
2022-11-23 20:42 ` Sean Christopherson
2022-11-24 3:40 ` Li, Xin3
2022-11-28 16:26 ` Sean Christopherson
2022-11-24 9:46 ` Peter Zijlstra
2022-11-28 19:05 ` Sean Christopherson
2022-11-23 9:16 ` Peter Zijlstra
2022-11-23 19:18 ` Sean Christopherson
2022-11-11 22:15 ` H. Peter Anvin
2022-11-10 6:15 ` [RESEND PATCH 6/6] x86/traps: remove unused NMI entry exc_nmi_noist() Xin Li
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3435ccbf-8ca4-19ca-ca34-dbb1a551b103@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=kevin.tian@intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peterz@infradead.org \
--cc=seanjc@google.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
--cc=xin3.li@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®