[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <a934013f-1f13-40a6-b665-67d62f9df4bc@suse.com>
Date: Sat, 9 Nov 2024 08:06:23 +0100
From: Jürgen Groß <jgross@...e.com>
To: Sean Christopherson <seanjc@...gle.com>
Cc: Paolo Bonzini <pbonzini@...hat.com>, linux-kernel@...r.kernel.org,
x86@...nel.org, kvm@...r.kernel.org, Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
Dave Hansen <dave.hansen@...ux.intel.com>, "H . Peter Anvin" <hpa@...or.com>
Subject: Re: [PATCH] KVM/x86: don't use a literal 1 instead of RET_PF_RETRY
On 08.11.24 23:12, Sean Christopherson wrote:
> 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.
I think this function is an especially awful case, as it seems to be natural
to return a RET_PF_ value from a function named kvm_mmu_page_fault().
>
> * 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.
I think it would be helpful to at least add comments to the functions
returning the 0/1/-errno value.
And it would be even better to have #defines for the 0 and 1. New use cases
should use the #defines, and whether we convert current users is another
question (I'd go for it, as it is only a minor additional work when adding
the comments anyway).
If you are fine with that, I can start the effort.
Juergen
Download attachment "OpenPGP_0xB0DE9DD628BF132F.asc" of type "application/pgp-keys" (3684 bytes)
Download attachment "OpenPGP_signature.asc" of type "application/pgp-signature" (496 bytes)
Powered by blists - more mailing lists