mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chenyi Qiang <chenyi.qiang@intel.com>
To: Sean Christopherson <seanjc@google.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	Vitaly Kuznetsov <vkuznets@redhat.com>,
	Wanpeng Li <wanpengli@tencent.com>,
	Jim Mattson <jmattson@google.com>, Joerg Roedel <joro@8bytes.org>,
	Xiaoyao Li <xiaoyao.li@intel.com>,
	kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v5 1/3] KVM: X86: Save&restore the triple fault request
Date: Wed, 6 Apr 2022 14:46:59 +0800	[thread overview]
Message-ID: <9b45d2bc-9bb3-53a1-3eb3-4b1bf6987268@intel.com> (raw)
In-Reply-To: <YkzRSHHDMaVBQrxd@google.com>



On 4/6/2022 7:31 AM, Sean Christopherson wrote:
> On Fri, Mar 18, 2022, Chenyi Qiang wrote:
>> For the triple fault sythesized by KVM, e.g. the RSM path or
>> nested_vmx_abort(), if KVM exits to userspace before the request is
>> serviced, userspace could migrate the VM and lose the triple fault.
>> Fix this issue by adding a new event KVM_VCPUEVENT_TRIPLE_FAULT in
>> get/set_vcpu_events() to track the triple fault request.
>>
>> Signed-off-by: Chenyi Qiang <chenyi.qiang@intel.com>
>> ---
>>   Documentation/virt/kvm/api.rst  | 6 ++++++
>>   arch/x86/include/uapi/asm/kvm.h | 1 +
>>   arch/x86/kvm/x86.c              | 9 ++++++++-
>>   3 files changed, 15 insertions(+), 1 deletion(-)
>>
>> diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst
>> index 691ff84444bd..9682b0a438bd 100644
>> --- a/Documentation/virt/kvm/api.rst
>> +++ b/Documentation/virt/kvm/api.rst
>> @@ -1146,6 +1146,9 @@ The following bits are defined in the flags field:
>>     fields contain a valid state. This bit will be set whenever
>>     KVM_CAP_EXCEPTION_PAYLOAD is enabled.
>>   
>> +- KVM_VCPUEVENT_TRIPLE_FAULT may be set to signal that there's a
>> +  triple fault request waiting to be serviced.
> 
> Please avoid "request" in the docs, as before, that's a KVM implemenation detail.
> For this one, maybe "there's a pending triple fault event"?
> 
>> +
>>   ARM/ARM64:
>>   ^^^^^^^^^^
>>   
>> @@ -1241,6 +1244,9 @@ can be set in the flags field to signal that the
>>   exception_has_payload, exception_payload, and exception.pending fields
>>   contain a valid state and shall be written into the VCPU.
>>   
>> +KVM_VCPUEVENT_TRIPLE_FAULT can be set in flags field to signal that a
>> +triple fault request should be made.
> 
> 
> And here, "to signal that KVM should synthesize a triple fault for the guest"?
> 
>> +
>>   ARM/ARM64:
>>   ^^^^^^^^^^
>>   
>> diff --git a/arch/x86/include/uapi/asm/kvm.h b/arch/x86/include/uapi/asm/kvm.h
>> index bf6e96011dfe..d8ef0d993e86 100644
>> --- a/arch/x86/include/uapi/asm/kvm.h
>> +++ b/arch/x86/include/uapi/asm/kvm.h
>> @@ -325,6 +325,7 @@ struct kvm_reinject_control {
>>   #define KVM_VCPUEVENT_VALID_SHADOW	0x00000004
>>   #define KVM_VCPUEVENT_VALID_SMM		0x00000008
>>   #define KVM_VCPUEVENT_VALID_PAYLOAD	0x00000010
>> +#define KVM_VCPUEVENT_TRIPLE_FAULT	0x00000020
>>   
>>   /* Interrupt shadow states */
>>   #define KVM_X86_SHADOW_INT_MOV_SS	0x01
>> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
>> index 4fa4d8269e5b..fee402a700df 100644
>> --- a/arch/x86/kvm/x86.c
>> +++ b/arch/x86/kvm/x86.c
>> @@ -4891,6 +4891,9 @@ static void kvm_vcpu_ioctl_x86_get_vcpu_events(struct kvm_vcpu *vcpu,
>>   	if (vcpu->kvm->arch.exception_payload_enabled)
>>   		events->flags |= KVM_VCPUEVENT_VALID_PAYLOAD;
>>   
>> +	if (kvm_check_request(KVM_REQ_TRIPLE_FAULT, vcpu))
>> +		events->flags |= KVM_VCPUEVENT_TRIPLE_FAULT;
>> +
>>   	memset(&events->reserved, 0, sizeof(events->reserved));
>>   }
>>   
>> @@ -4903,7 +4906,8 @@ static int kvm_vcpu_ioctl_x86_set_vcpu_events(struct kvm_vcpu *vcpu,
>>   			      | KVM_VCPUEVENT_VALID_SIPI_VECTOR
>>   			      | KVM_VCPUEVENT_VALID_SHADOW
>>   			      | KVM_VCPUEVENT_VALID_SMM
>> -			      | KVM_VCPUEVENT_VALID_PAYLOAD))
>> +			      | KVM_VCPUEVENT_VALID_PAYLOAD
>> +			      | KVM_VCPUEVENT_TRIPLE_FAULT))
>>   		return -EINVAL;
>>   
>>   	if (events->flags & KVM_VCPUEVENT_VALID_PAYLOAD) {
>> @@ -4976,6 +4980,9 @@ static int kvm_vcpu_ioctl_x86_set_vcpu_events(struct kvm_vcpu *vcpu,
>>   		}
>>   	}
>>   
>> +	if (events->flags & KVM_VCPUEVENT_TRIPLE_FAULT)
>> +		kvm_make_request(KVM_REQ_TRIPLE_FAULT, vcpu);
>> +
>>   	kvm_make_request(KVM_REQ_EVENT, vcpu);
> 
> Looks correct, but this really needs a selftest, at least for the SET path since
> the intent is to use that for the NOTIFY handling.  Doesn't need to be super fancy,
> e.g. do port I/O from L2, inject a triple fault, and verify L1 sees the appropriate
> exit.
> 
> Aha!  And for the GET path, abuse KVM_X86_SET_MCE with CR4.MCE=0 to coerce KVM into
> making a KVM_REQ_TRIPLE_FAULT, that way there's no need to try and hit a timing
> window to intercept the request.

OK, will cook a selftest to verify it.


  parent reply	other threads:[~2022-04-06 10:21 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-18  7:49 [PATCH v5 0/3] Introduce Notify VM exit Chenyi Qiang
2022-03-18  7:49 ` [PATCH v5 1/3] KVM: X86: Save&restore the triple fault request Chenyi Qiang
2022-04-05 23:31   ` Sean Christopherson
2022-04-05 23:44     ` Sean Christopherson
2022-04-06 21:15       ` Sean Christopherson
2022-04-07  6:12         ` Chenyi Qiang
2022-04-08  2:48           ` Sean Christopherson
2022-04-06 21:25       ` Sean Christopherson
2022-04-06  6:46     ` Chenyi Qiang [this message]
2022-04-06 21:51     ` Sean Christopherson
2022-03-18  7:49 ` [PATCH v5 2/3] KVM: VMX: Enable Notify VM exit Chenyi Qiang
2022-04-06  0:34   ` Sean Christopherson
2022-04-06 18:54     ` Sean Christopherson
2022-03-18  7:49 ` [PATCH v5 3/3] KVM: Add document for KVM_CAP_X86_NOTIFY_VMEXIT and KVM_EXIT_NOTIFY Chenyi Qiang

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=9b45d2bc-9bb3-53a1-3eb3-4b1bf6987268@intel.com \
    --to=chenyi.qiang@intel.com \
    --cc=jmattson@google.com \
    --cc=joro@8bytes.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=vkuznets@redhat.com \
    --cc=wanpengli@tencent.com \
    --cc=xiaoyao.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®