Re: [PATCH 2/8] KVM: x86/xen: Introduce kvm_xen_has_64bit_shinfo() macro

From: David Laight

Date: Sat Jun 06 2026 - 07:13:42 EST


On Sat, 06 Jun 2026 10:35:45 +0100
David Woodhouse <dwmw2@xxxxxxxxxxxxx> wrote:

> On Sat, 2026-06-06 at 10:30 +0100, David Laight wrote:
> > On Fri,  5 Jun 2026 15:17:27 +0100
> > David Woodhouse <dwmw2@xxxxxxxxxxxxx> wrote:
> >
> > > From: David Woodhouse <dwmw@xxxxxxxxxxxx>
> > >
> > > Add a kvm_xen_has_64bit_shinfo() helper macro to replace the repeated
> > > pattern of 'IS_ENABLED(CONFIG_64BIT) && kvm->arch.xen.long_mode'
> > > throughout the Xen emulation code. The macro uses READ_ONCE() to
> > > ensure a consistent snapshot of the flag, which can be changed by
> > > another vCPU at any time.
> >
> > If another vCPU changes the flag then isn't it all broken?
> > The code seems to need the value to be stable.
>
> Do you believe the explanation in patch 4 to be insufficient?

(I read patch 2 first...)
Changing the same lines twice is s bit excessive.

There is this bit in #4:

Even with this fix, the same corruption can occur if 64-bit mode is
latched and the guest switches to 32-bit mode immediately afterward.

which, I think, means it is all hopeless really.

If the structure layout doesn't depend on 32/64 bit then why check
(or compile-time check).

But if the layout differs and the the mode can change dynamically
then you need some kind of locking (or similar).

-- David