[PATCH] KVM: arm64: pkvm: Adopt MARKER() to define host hypercall ranges

Marc Zyngier maz at kernel.org
Wed Apr 15 06:18:05 PDT 2026


On Wed, 15 Apr 2026 10:56:17 +0100,
Fuad Tabba <tabba at google.com> wrote:
> 
> Hi Marc,
> 
> On Tue, 14 Apr 2026 at 17:05, Marc Zyngier <maz at kernel.org> wrote:
> >
> > The EL2 code defines ranges of host hypercalls that are either
> > enabled at boot-time only, used by [nh]VHE KVM, or reserved to pKVM.
> >
> > The way these ranges are delineated is error prone, as the enum symbols
> > defining the limits are expressed in terms of actual function symbols.
> > This means that should a new function be added, special care must be
> > taken to also update the limit symbol.
> >
> > Improve this by reusing the mechanism introduced for the vcpu_sysreg
> > enum, which uses a MARKER() macro and some extra trickery to make
> > the limit symbol standalone. Crucially, the limit symbol has the
> > same value as the *following* symbol.
> >
> > The handle_host_hcall() function is then updated to make use of
> > the new limit definitions and get rid of the brittle default
> > upper limit. This allows for some more strict checks at build
> > time, and the removal of an comparison at run time.
> 
> This is pretty neat. There is still the issue of a hole, i.e., adding
> an enum in the middle but forgetting to add a function, but that is
> caught in handle_host_hcall(). I can't think of an easy way to catch
> that though (xarray that initializes both?)

Yeah, there isn't a simple way to do that at compile-time,
unfortunately.

One thing that could be done is to have a blanket initialisation with
an illegal value, override all the entries you want, and then check at
KVM init time for the presence of the canary value. If you find it,
abort the KVM initialisation.

With that, you can drop the NULL test on the handling path.

> >
> > Signed-off-by: Marc Zyngier <maz at kernel.org>
> 
> Tested-by: Fuad Tabba <tabba at google.com>
> Reviewed-by: Fuad Tabba <tabba at google.com>

Thanks,

	M.

-- 
Without deviation from the norm, progress is not possible.



More information about the linux-arm-kernel mailing list