diff mbox series

KVM/x86: don't use a literal 1 instead of RET_PF_RETRY

Message ID 20241108161312.28365-1-jgross@suse.com (mailing list archive)
State New
Headers show
Series KVM/x86: don't use a literal 1 instead of RET_PF_RETRY | expand

Commit Message

Jürgen Groß Nov. 8, 2024, 4:13 p.m. UTC
Using a literal 1 instead of RET_PF_RETRY is not nice, fix that.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 arch/x86/kvm/mmu/mmu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Paolo Bonzini Nov. 8, 2024, 5:13 p.m. UTC | #1
Queued, thanks.

Paolo
Sean Christopherson Nov. 8, 2024, 6:44 p.m. UTC | #2
On Fri, Nov 08, 2024, Paolo Bonzini wrote:
> Queued, thanks.

Noooo!  Can you un-queue?

The return from kvm_mmu_page_fault() is NOT RET_PF_xxx, it's KVM outer 0/1/-errno.
I.e. '1' is saying "resume the guest", it has *nothing* to do with RET_PF_RETRY.
E.g. that path also handles RET_PF_FIXED, RET_PF_SPURIOUS, etc.
Jürgen Groß Nov. 8, 2024, 7:18 p.m. UTC | #3
On 08.11.24 19:44, Sean Christopherson wrote:
> On Fri, Nov 08, 2024, Paolo Bonzini wrote:
>> Queued, thanks.
> 
> Noooo!  Can you un-queue?
> 
> The return from kvm_mmu_page_fault() is NOT RET_PF_xxx, it's KVM outer 0/1/-errno.
> I.e. '1' is saying "resume the guest", it has *nothing* to do with RET_PF_RETRY.
> E.g. that path also handles RET_PF_FIXED, RET_PF_SPURIOUS, etc.

And what about the existing "return RET_PF_RETRY" further up?


Juergen
Sean Christopherson Nov. 8, 2024, 10:12 p.m. UTC | #4
On Fri, Nov 08, 2024, Jürgen Groß wrote:
> On 08.11.24 19:44, Sean Christopherson wrote:
> > On Fri, Nov 08, 2024, Paolo Bonzini wrote:
> > > Queued, thanks.
> > 
> > Noooo!  Can you un-queue?
> > 
> > The return from kvm_mmu_page_fault() is NOT RET_PF_xxx, it's KVM outer 0/1/-errno.
> > I.e. '1' is saying "resume the guest", it has *nothing* to do with RET_PF_RETRY.
> > E.g. that path also handles RET_PF_FIXED, RET_PF_SPURIOUS, etc.
> 
> And what about the existing "return RET_PF_RETRY" further up?

Oof.  Works by coincidence.  The intent in that case is to retry the fault, but
the fact that RET_PF_RETRY happens to be '1' is mostly luck.  Returning a postive
value other than '1' should work, but as called out by the comments for the enum,
using '0' for CONTINUE isn't a hard requirement.  E.g. if for some reason we used
'0' for RET_PF_RETRY, this code would break.

 * Note, all values must be greater than or equal to zero so as not to encroach
 * on -errno return values.  Somewhat arbitrarily use '0' for CONTINUE, which
 * will allow for efficient machine code when checking for CONTINUE, e.g.
 * "TEST %rax, %rax, JNZ", as all "stop!" values are non-zero.

FWIW, you are far from the first person to complain about KVM's mostly-undocumented
0/1/-errno return encoding scheme.  The problems is that it's so pervasive
throughout KVM, that in some cases it's not easy to understand if a function is
actually using that scheme, or just happens to return similar values.  I.e.
converting to enums (or #defines) would require a lot of work and churn.
diff mbox series

Patch

diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
index 8e853a5fc867..d4a9f845b373 100644
--- a/arch/x86/kvm/mmu/mmu.c
+++ b/arch/x86/kvm/mmu/mmu.c
@@ -6157,7 +6157,7 @@  int noinline kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, u64 err
 		vcpu->stat.pf_spurious++;
 
 	if (r != RET_PF_EMULATE)
-		return 1;
+		return RET_PF_RETRY;
 
 emulate:
 	return x86_emulate_instruction(vcpu, cr2_or_gpa, emulation_type, insn,