Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1694238 > unrolled thread
| Started by | Wanpeng Li <kernellwp@gmail.com> |
|---|---|
| First post | 2017-07-23 03:10 +0200 |
| Last post | 2017-07-24 16:30 +0200 |
| Articles | 4 — 2 participants |
Back to article view | Back to linux.kernel
[PATCH] KVM: nVMX: consult PFER_MASK and PFER_MATCH before nested vmexit if inject #PF Wanpeng Li <kernellwp@gmail.com> - 2017-07-23 03:10 +0200
Re: [PATCH] KVM: nVMX: consult PFER_MASK and PFER_MATCH before nested vmexit if inject #PF Paolo Bonzini <pbonzini@redhat.com> - 2017-07-24 15:40 +0200
Re: [PATCH] KVM: nVMX: consult PFER_MASK and PFER_MATCH before nested vmexit if inject #PF Wanpeng Li <kernellwp@gmail.com> - 2017-07-24 16:00 +0200
Re: [PATCH] KVM: nVMX: consult PFER_MASK and PFER_MATCH before nested vmexit if inject #PF Paolo Bonzini <pbonzini@redhat.com> - 2017-07-24 16:30 +0200
| From | Wanpeng Li <kernellwp@gmail.com> |
|---|---|
| Date | 2017-07-23 03:10 +0200 |
| Subject | [PATCH] KVM: nVMX: consult PFER_MASK and PFER_MATCH before nested vmexit if inject #PF |
| Message-ID | <u6dzb-Ql-3@gated-at.bofh.it> |
From: Wanpeng Li <wanpeng.li@hotmail.com>
When generating #PF VM-exit, check equality:
(PFEC & PFEC_MASK) == PFEC_MATCH
If there is equality, the 14 bit of exception bitmap is used to take decision
about generating #PF VM-exit. If there is inequality, inverted 14 bit is used.
Reported-by: Jim Mattson <jmattson@google.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Radim Krčmář <rkrcmar@redhat.com>
Signed-off-by: Wanpeng Li <wanpeng.li@hotmail.com>
---
arch/x86/kvm/vmx.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 29fd8af..8a213f2 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -2429,6 +2429,8 @@ static void skip_emulated_instruction(struct kvm_vcpu *vcpu)
vmx_set_interrupt_shadow(vcpu, 0);
}
+static bool nested_vmx_is_page_fault_vmexit(struct vmcs12 *vmcs12, u16 error_code);
+
/*
* KVM wants to inject page-faults which it got to the guest. This function
* checks whether in a nested guest, we need to inject them to L1 or L2.
@@ -2442,6 +2444,10 @@ static int nested_vmx_check_exception(struct kvm_vcpu *vcpu)
(nr == PF_VECTOR && vcpu->arch.exception.nested_apf)))
return 0;
+ if (nr == PF_VECTOR && !vcpu->arch.exception.nested_apf &&
+ !nested_vmx_is_page_fault_vmexit(vmcs12, vcpu->arch.exception.error_code))
+ return 0;
+
if (vcpu->arch.exception.nested_apf) {
vmcs_write32(VM_EXIT_INTR_ERROR_CODE, vcpu->arch.exception.error_code);
nested_vmx_vmexit(vcpu, EXIT_REASON_EXCEPTION_NMI,
--
2.7.4
[toc] | [next] | [standalone]
| From | Paolo Bonzini <pbonzini@redhat.com> |
|---|---|
| Date | 2017-07-24 15:40 +0200 |
| Subject | Re: [PATCH] KVM: nVMX: consult PFER_MASK and PFER_MATCH before nested vmexit if inject #PF |
| Message-ID | <u6LKx-5uV-1@gated-at.bofh.it> |
| In reply to | #1694238 |
On 23/07/2017 03:05, Wanpeng Li wrote:
> From: Wanpeng Li <wanpeng.li@hotmail.com>
>
> When generating #PF VM-exit, check equality:
> (PFEC & PFEC_MASK) == PFEC_MATCH
> If there is equality, the 14 bit of exception bitmap is used to take decision
> about generating #PF VM-exit. If there is inequality, inverted 14 bit is used.
>
> Reported-by: Jim Mattson <jmattson@google.com>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Radim Krčmář <rkrcmar@redhat.com>
> Signed-off-by: Wanpeng Li <wanpeng.li@hotmail.com>
> ---
> arch/x86/kvm/vmx.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> index 29fd8af..8a213f2 100644
> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -2429,6 +2429,8 @@ static void skip_emulated_instruction(struct kvm_vcpu *vcpu)
> vmx_set_interrupt_shadow(vcpu, 0);
> }
>
> +static bool nested_vmx_is_page_fault_vmexit(struct vmcs12 *vmcs12, u16 error_code);
> +
> /*
> * KVM wants to inject page-faults which it got to the guest. This function
> * checks whether in a nested guest, we need to inject them to L1 or L2.
> @@ -2442,6 +2444,10 @@ static int nested_vmx_check_exception(struct kvm_vcpu *vcpu)
> (nr == PF_VECTOR && vcpu->arch.exception.nested_apf)))
> return 0;
>
> + if (nr == PF_VECTOR && !vcpu->arch.exception.nested_apf &&
> + !nested_vmx_is_page_fault_vmexit(vmcs12, vcpu->arch.exception.error_code))
> + return 0;
This is wrong, the check must replace "(vmcs12->exception_bitmap & (1u
<< nr)" if nr == PF_VECTOR.
Paolo
> if (vcpu->arch.exception.nested_apf) {
> vmcs_write32(VM_EXIT_INTR_ERROR_CODE, vcpu->arch.exception.error_code);
> nested_vmx_vmexit(vcpu, EXIT_REASON_EXCEPTION_NMI,
>
[toc] | [prev] | [next] | [standalone]
| From | Wanpeng Li <kernellwp@gmail.com> |
|---|---|
| Date | 2017-07-24 16:00 +0200 |
| Subject | Re: [PATCH] KVM: nVMX: consult PFER_MASK and PFER_MATCH before nested vmexit if inject #PF |
| Message-ID | <u6M3T-5Cy-5@gated-at.bofh.it> |
| In reply to | #1694711 |
2017-07-24 21:36 GMT+08:00 Paolo Bonzini <pbonzini@redhat.com>:
> On 23/07/2017 03:05, Wanpeng Li wrote:
>> From: Wanpeng Li <wanpeng.li@hotmail.com>
>>
>> When generating #PF VM-exit, check equality:
>> (PFEC & PFEC_MASK) == PFEC_MATCH
>> If there is equality, the 14 bit of exception bitmap is used to take decision
>> about generating #PF VM-exit. If there is inequality, inverted 14 bit is used.
>>
>> Reported-by: Jim Mattson <jmattson@google.com>
>> Cc: Paolo Bonzini <pbonzini@redhat.com>
>> Cc: Radim Krčmář <rkrcmar@redhat.com>
>> Signed-off-by: Wanpeng Li <wanpeng.li@hotmail.com>
>> ---
>> arch/x86/kvm/vmx.c | 6 ++++++
>> 1 file changed, 6 insertions(+)
>>
>> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
>> index 29fd8af..8a213f2 100644
>> --- a/arch/x86/kvm/vmx.c
>> +++ b/arch/x86/kvm/vmx.c
>> @@ -2429,6 +2429,8 @@ static void skip_emulated_instruction(struct kvm_vcpu *vcpu)
>> vmx_set_interrupt_shadow(vcpu, 0);
>> }
>>
>> +static bool nested_vmx_is_page_fault_vmexit(struct vmcs12 *vmcs12, u16 error_code);
>> +
>> /*
>> * KVM wants to inject page-faults which it got to the guest. This function
>> * checks whether in a nested guest, we need to inject them to L1 or L2.
>> @@ -2442,6 +2444,10 @@ static int nested_vmx_check_exception(struct kvm_vcpu *vcpu)
>> (nr == PF_VECTOR && vcpu->arch.exception.nested_apf)))
>> return 0;
>>
>> + if (nr == PF_VECTOR && !vcpu->arch.exception.nested_apf &&
>> + !nested_vmx_is_page_fault_vmexit(vmcs12, vcpu->arch.exception.error_code))
>> + return 0;
>
> This is wrong, the check must replace "(vmcs12->exception_bitmap & (1u
> << nr)" if nr == PF_VECTOR.
How about something like this:
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 29fd8af..52afd23 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -2439,7 +2439,8 @@ static int nested_vmx_check_exception(struct
kvm_vcpu *vcpu)
unsigned int nr = vcpu->arch.exception.nr;
if (!((vmcs12->exception_bitmap & (1u << nr)) ||
- (nr == PF_VECTOR && vcpu->arch.exception.nested_apf)))
+ (nr == PF_VECTOR && (vcpu->arch.exception.nested_apf ||
+ nested_vmx_is_page_fault_vmexit(vmcs12,
vcpu->arch.exception.error_code)))))
return 0;
if (vcpu->arch.exception.nested_apf) {
Regards,
Wanpeng Li
[toc] | [prev] | [next] | [standalone]
| From | Paolo Bonzini <pbonzini@redhat.com> |
|---|---|
| Date | 2017-07-24 16:30 +0200 |
| Subject | Re: [PATCH] KVM: nVMX: consult PFER_MASK and PFER_MATCH before nested vmexit if inject #PF |
| Message-ID | <u6MwV-655-5@gated-at.bofh.it> |
| In reply to | #1694742 |
On 24/07/2017 15:57, Wanpeng Li wrote:
>
> if (!((vmcs12->exception_bitmap & (1u << nr)) ||
> - (nr == PF_VECTOR && vcpu->arch.exception.nested_apf)))
> + (nr == PF_VECTOR && (vcpu->arch.exception.nested_apf ||
> + nested_vmx_is_page_fault_vmexit(vmcs12,
> vcpu->arch.exception.error_code)))))
> return 0;
No, it would be more like
if (nr == PF_VECTOR
? (vcpu->arch.exception.nested_apf ||
nested_vmx_is_page_fault_vmexit(vmcs12, vcpu->arch.exception.error_code))
: (vmcs12->exception_bitmap & (1u << nr)))
but I've sent an RFC patch that also fixes the exit qualification.
Paolo
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web