linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] KVM: X86: Explicitly set the 'fault.async_page_fault' value in kvm_fixup_and_inject_pf_error().
@ 2022-07-18  7:47 Yu Zhang
  2022-07-19 19:01 ` Sean Christopherson
  2022-08-05 10:26 ` Paolo Bonzini
  0 siblings, 2 replies; 6+ messages in thread
From: Yu Zhang @ 2022-07-18  7:47 UTC (permalink / raw)
  To: pbonzini, seanjc, vkuznets, jmattson, joro, wanpengli, kvm; +Cc: linux-kernel

kvm_fixup_and_inject_pf_error() was introduced to fixup the error code(
e.g., to add RSVD flag) and inject the #PF to the guest, when guest
MAXPHYADDR is smaller than the host one.

When it comes to nested, L0 is expected to intercept and fix up the #PF
and then inject to L2 directly if
- L2.MAXPHYADDR < L0.MAXPHYADDR and
- L1 has no intention to intercept L2's #PF (e.g., L2 and L1 have the
  same MAXPHYADDR value && L1 is using EPT for L2),
instead of constructing a #PF VM Exit to L1. Currently, with PFEC_MASK
and PFEC_MATCH both set to 0 in vmcs02, the interception and injection
may happen on all L2 #PFs.

However, failing to initialize 'fault' in kvm_fixup_and_inject_pf_error()
may cause the fault.async_page_fault being NOT zeroed, and later the #PF
being treated as a nested async page fault, and then being injected to L1.
Instead of zeroing 'fault' at the beginning of this function, we mannually
set the value of 'fault.async_page_fault', because false is the value we
really expect.

Fixes: 897861479c064 ("KVM: x86: Add helper functions for illegal GPA checking and page fault injection")
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=216178
Reported-by: Yang Lixiao <lixiao.yang@intel.com>
Signed-off-by: Yu Zhang <yu.c.zhang@linux.intel.com>
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
v2:
- Set 'fault.async_page_fault' mannually to false, instead of initializing
the whole structure based on Sean's suggestion.
- Commit message changes based on the code change.
---
 arch/x86/kvm/x86.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 031678eff28e..ffd8c96cfaa5 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -12999,6 +12999,7 @@ void kvm_fixup_and_inject_pf_error(struct kvm_vcpu *vcpu, gva_t gva, u16 error_c
 		fault.error_code = error_code;
 		fault.nested_page_fault = false;
 		fault.address = gva;
+		fault.async_page_fault = false;
 	}
 	vcpu->arch.walk_mmu->inject_page_fault(vcpu, &fault);
 }
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] KVM: X86: Explicitly set the 'fault.async_page_fault' value in kvm_fixup_and_inject_pf_error().
  2022-07-18  7:47 [PATCH v2] KVM: X86: Explicitly set the 'fault.async_page_fault' value in kvm_fixup_and_inject_pf_error() Yu Zhang
@ 2022-07-19 19:01 ` Sean Christopherson
  2022-07-21  9:22   ` Yu Zhang
  2022-08-05 10:26 ` Paolo Bonzini
  1 sibling, 1 reply; 6+ messages in thread
From: Sean Christopherson @ 2022-07-19 19:01 UTC (permalink / raw)
  To: Yu Zhang; +Cc: pbonzini, vkuznets, jmattson, joro, wanpengli, kvm, linux-kernel

On Mon, Jul 18, 2022, Yu Zhang wrote:
> kvm_fixup_and_inject_pf_error() was introduced to fixup the error code(
> e.g., to add RSVD flag) and inject the #PF to the guest, when guest
> MAXPHYADDR is smaller than the host one.
> 
> When it comes to nested, L0 is expected to intercept and fix up the #PF
> and then inject to L2 directly if
> - L2.MAXPHYADDR < L0.MAXPHYADDR and
> - L1 has no intention to intercept L2's #PF (e.g., L2 and L1 have the
>   same MAXPHYADDR value && L1 is using EPT for L2),
> instead of constructing a #PF VM Exit to L1. Currently, with PFEC_MASK
> and PFEC_MATCH both set to 0 in vmcs02, the interception and injection
> may happen on all L2 #PFs.
> 
> However, failing to initialize 'fault' in kvm_fixup_and_inject_pf_error()
> may cause the fault.async_page_fault being NOT zeroed, and later the #PF
> being treated as a nested async page fault, and then being injected to L1.
> Instead of zeroing 'fault' at the beginning of this function, we mannually
> set the value of 'fault.async_page_fault', because false is the value we
> really expect.
> 
> Fixes: 897861479c064 ("KVM: x86: Add helper functions for illegal GPA checking and page fault injection")
> Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=216178
> Reported-by: Yang Lixiao <lixiao.yang@intel.com>
> Signed-off-by: Yu Zhang <yu.c.zhang@linux.intel.com>
> Signed-off-by: Sean Christopherson <seanjc@google.com>

No need for my SoB, I was just providing feedback.  Other than that, 

Reviewed-by: Sean Christopherson <seanjc@google.com>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] KVM: X86: Explicitly set the 'fault.async_page_fault' value in kvm_fixup_and_inject_pf_error().
  2022-07-19 19:01 ` Sean Christopherson
@ 2022-07-21  9:22   ` Yu Zhang
  2022-08-04  3:14     ` Yu Zhang
  0 siblings, 1 reply; 6+ messages in thread
From: Yu Zhang @ 2022-07-21  9:22 UTC (permalink / raw)
  To: Sean Christopherson
  Cc: pbonzini, vkuznets, jmattson, joro, wanpengli, kvm, linux-kernel

On Tue, Jul 19, 2022 at 07:01:41PM +0000, Sean Christopherson wrote:
> On Mon, Jul 18, 2022, Yu Zhang wrote:
> > kvm_fixup_and_inject_pf_error() was introduced to fixup the error code(
> > e.g., to add RSVD flag) and inject the #PF to the guest, when guest
> > MAXPHYADDR is smaller than the host one.
> > 
> > When it comes to nested, L0 is expected to intercept and fix up the #PF
> > and then inject to L2 directly if
> > - L2.MAXPHYADDR < L0.MAXPHYADDR and
> > - L1 has no intention to intercept L2's #PF (e.g., L2 and L1 have the
> >   same MAXPHYADDR value && L1 is using EPT for L2),
> > instead of constructing a #PF VM Exit to L1. Currently, with PFEC_MASK
> > and PFEC_MATCH both set to 0 in vmcs02, the interception and injection
> > may happen on all L2 #PFs.
> > 
> > However, failing to initialize 'fault' in kvm_fixup_and_inject_pf_error()
> > may cause the fault.async_page_fault being NOT zeroed, and later the #PF
> > being treated as a nested async page fault, and then being injected to L1.
> > Instead of zeroing 'fault' at the beginning of this function, we mannually
> > set the value of 'fault.async_page_fault', because false is the value we
> > really expect.
> > 
> > Fixes: 897861479c064 ("KVM: x86: Add helper functions for illegal GPA checking and page fault injection")
> > Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=216178
> > Reported-by: Yang Lixiao <lixiao.yang@intel.com>
> > Signed-off-by: Yu Zhang <yu.c.zhang@linux.intel.com>
> > Signed-off-by: Sean Christopherson <seanjc@google.com>
> 
> No need for my SoB, I was just providing feedback.  Other than that, 
> 
Thanks! It's a very detailed suggestion. :)

> Reviewed-by: Sean Christopherson <seanjc@google.com>
> 

@Paolo Any comment on this fix, and on the test case change(https://www.spinics.net/lists/kvm/msg283600.html)? Thanks!

B.R.
Yu

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] KVM: X86: Explicitly set the 'fault.async_page_fault' value in kvm_fixup_and_inject_pf_error().
  2022-07-21  9:22   ` Yu Zhang
@ 2022-08-04  3:14     ` Yu Zhang
  2022-08-04 15:02       ` Sean Christopherson
  0 siblings, 1 reply; 6+ messages in thread
From: Yu Zhang @ 2022-08-04  3:14 UTC (permalink / raw)
  To: pbonzini; +Cc: seanjc, vkuznets, jmattson, joro, wanpengli, kvm, linux-kernel

On Thu, Jul 21, 2022 at 05:22:14PM +0800, Yu Zhang wrote:
> On Tue, Jul 19, 2022 at 07:01:41PM +0000, Sean Christopherson wrote:
> > On Mon, Jul 18, 2022, Yu Zhang wrote:
> > > kvm_fixup_and_inject_pf_error() was introduced to fixup the error code(
> > > e.g., to add RSVD flag) and inject the #PF to the guest, when guest
> > > MAXPHYADDR is smaller than the host one.
> > > 
> > > When it comes to nested, L0 is expected to intercept and fix up the #PF
> > > and then inject to L2 directly if
> > > - L2.MAXPHYADDR < L0.MAXPHYADDR and
> > > - L1 has no intention to intercept L2's #PF (e.g., L2 and L1 have the
> > >   same MAXPHYADDR value && L1 is using EPT for L2),
> > > instead of constructing a #PF VM Exit to L1. Currently, with PFEC_MASK
> > > and PFEC_MATCH both set to 0 in vmcs02, the interception and injection
> > > may happen on all L2 #PFs.
> > > 
> > > However, failing to initialize 'fault' in kvm_fixup_and_inject_pf_error()
> > > may cause the fault.async_page_fault being NOT zeroed, and later the #PF
> > > being treated as a nested async page fault, and then being injected to L1.
> > > Instead of zeroing 'fault' at the beginning of this function, we mannually
> > > set the value of 'fault.async_page_fault', because false is the value we
> > > really expect.
> > > 
> > > Fixes: 897861479c064 ("KVM: x86: Add helper functions for illegal GPA checking and page fault injection")
> > > Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=216178
> > > Reported-by: Yang Lixiao <lixiao.yang@intel.com>
> > > Signed-off-by: Yu Zhang <yu.c.zhang@linux.intel.com>
> > > Signed-off-by: Sean Christopherson <seanjc@google.com>
> > 
> > No need for my SoB, I was just providing feedback.  Other than that, 
> > 
> Thanks! It's a very detailed suggestion. :)
> 
> > Reviewed-by: Sean Christopherson <seanjc@google.com>
> > 
> 
> @Paolo Any comment on this fix, and on the test case change(https://www.spinics.net/lists/kvm/msg283600.html)? Thanks!
> 
> B.R.
> Yu

Ping... Or should I send another version? Thanks!

B.R.
Yu

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] KVM: X86: Explicitly set the 'fault.async_page_fault' value in kvm_fixup_and_inject_pf_error().
  2022-08-04  3:14     ` Yu Zhang
@ 2022-08-04 15:02       ` Sean Christopherson
  0 siblings, 0 replies; 6+ messages in thread
From: Sean Christopherson @ 2022-08-04 15:02 UTC (permalink / raw)
  To: Yu Zhang; +Cc: pbonzini, vkuznets, jmattson, joro, wanpengli, kvm, linux-kernel

On Thu, Aug 04, 2022, Yu Zhang wrote:
> On Thu, Jul 21, 2022 at 05:22:14PM +0800, Yu Zhang wrote:
> > On Tue, Jul 19, 2022 at 07:01:41PM +0000, Sean Christopherson wrote:
> > > On Mon, Jul 18, 2022, Yu Zhang wrote:
> > > > kvm_fixup_and_inject_pf_error() was introduced to fixup the error code(
> > > > e.g., to add RSVD flag) and inject the #PF to the guest, when guest
> > > > MAXPHYADDR is smaller than the host one.
> > > > 
> > > > When it comes to nested, L0 is expected to intercept and fix up the #PF
> > > > and then inject to L2 directly if
> > > > - L2.MAXPHYADDR < L0.MAXPHYADDR and
> > > > - L1 has no intention to intercept L2's #PF (e.g., L2 and L1 have the
> > > >   same MAXPHYADDR value && L1 is using EPT for L2),
> > > > instead of constructing a #PF VM Exit to L1. Currently, with PFEC_MASK
> > > > and PFEC_MATCH both set to 0 in vmcs02, the interception and injection
> > > > may happen on all L2 #PFs.
> > > > 
> > > > However, failing to initialize 'fault' in kvm_fixup_and_inject_pf_error()
> > > > may cause the fault.async_page_fault being NOT zeroed, and later the #PF
> > > > being treated as a nested async page fault, and then being injected to L1.
> > > > Instead of zeroing 'fault' at the beginning of this function, we mannually
> > > > set the value of 'fault.async_page_fault', because false is the value we
> > > > really expect.
> > > > 
> > > > Fixes: 897861479c064 ("KVM: x86: Add helper functions for illegal GPA checking and page fault injection")
> > > > Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=216178
> > > > Reported-by: Yang Lixiao <lixiao.yang@intel.com>
> > > > Signed-off-by: Yu Zhang <yu.c.zhang@linux.intel.com>
> > > > Signed-off-by: Sean Christopherson <seanjc@google.com>
> > > 
> > > No need for my SoB, I was just providing feedback.  Other than that, 
> > > 
> > Thanks! It's a very detailed suggestion. :)
> > 
> > > Reviewed-by: Sean Christopherson <seanjc@google.com>
> > > 
> > 
> > @Paolo Any comment on this fix, and on the test case change(https://www.spinics.net/lists/kvm/msg283600.html)? Thanks!
> > 
> > B.R.
> > Yu
> 
> Ping... Or should I send another version? Thanks!

Shouldn't need to send a new version.

Paolo, can you grab this for 6.0-rc1?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] KVM: X86: Explicitly set the 'fault.async_page_fault' value in kvm_fixup_and_inject_pf_error().
  2022-07-18  7:47 [PATCH v2] KVM: X86: Explicitly set the 'fault.async_page_fault' value in kvm_fixup_and_inject_pf_error() Yu Zhang
  2022-07-19 19:01 ` Sean Christopherson
@ 2022-08-05 10:26 ` Paolo Bonzini
  1 sibling, 0 replies; 6+ messages in thread
From: Paolo Bonzini @ 2022-08-05 10:26 UTC (permalink / raw)
  To: Yu Zhang
  Cc: pbonzini, seanjc, vkuznets, jmattson, joro, wanpengli, kvm, linux-kernel

Queued, thanks.

Paolo



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-08-05 10:26 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-18  7:47 [PATCH v2] KVM: X86: Explicitly set the 'fault.async_page_fault' value in kvm_fixup_and_inject_pf_error() Yu Zhang
2022-07-19 19:01 ` Sean Christopherson
2022-07-21  9:22   ` Yu Zhang
2022-08-04  3:14     ` Yu Zhang
2022-08-04 15:02       ` Sean Christopherson
2022-08-05 10:26 ` Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).