Re: [PATCH v2 03/15] KVM: x86/xen: Don't truncate RAX when handling hypercall from protected guest
From: David Woodhouse
Date: Wed May 20 2026 - 04:27:46 EST
On Wed, 2026-05-20 at 13:02 +0800, Binbin Wu wrote:
> > > > For this one, I think the current KVM code is consistent.
> > > > The format is determined by EFER.LMA, whether the guest is running in 64 bit or
> > > > compatible mode doesn't change the ABI.
>
> I still have a point of confusion.
>
> I noticed a behavioral mismatch between KVM and Xen regarding when they switch
> to the standard/compat shared info.
> - In Xen: The 32-bit shared info structure is latched if the current vCPU is
> not in 64-bit mode:
> hvm_latch_shinfo_size
> d->arch.has_32bit_shinfo = hvm_guest_x86_mode(current) != X86_MODE_64BIT
>
> - In KVM: It evaluates is_long_mode(vcpu) instead. E.g.,
> kvm_xen_write_hypercall_page
> bool lm = is_long_mode(vcpu);
> ...
> kvm->arch.xen.long_mode = lm;
Nice catch. That should probably use is_64_bit_hypercall() too, yes?
> In theory, these two checks could differ when the guest kernel is running in
> a 32-bit compatibility mode. However, I believe this mismatch is fine in
> practice for two reasons:
> - Mainstream 64-bit OSes don't run in compatibility mode for kernel code after
> the early init.
Although... some of the early init does involve 32-bit mode and it
wouldn't be impossible for the guest to build the hypercall page from
32-bit mode during startup.
> - By default, HVM guests cannot issue hypercalls from userspace. The only one
> exception HVMOP_guest_request_vm_event is not related to the share info.
A third reason: This is only one of *two* places where the guest mode
gets latched. The guest's mode is also latched when it sets the
HVM_PARAM_CALLBACK_IRQ parameter. When running under KVM, the VMM
handles this and tells the kernel via the KVM_XEN_ATTR_TYPE_LONG_MODE
attribute.
So even if it doesn't latch correctly when setting the hypercall page,
it will later.
And Linux at least will set KVM_PARAM_CALLBACK_IRQ even if it isn't
using it, in xen_set_upcall_vector() with a comment saying 'Trick
toolstack to think we are enlightened'.
> So the vCPU will never be in compatibility mode when a related hypercall occurs.
> In this specific operational context, evaluating is_long_mode() yields the
> exact same functional outcome as checking for 64-bit execution mode. Am I
> missing anything here?
I think you're right. We have thus far launched about 5 billion Xen
guests with this, and I've never heard any report about guests latching
the wrong mode. And there are a *lot* of random home-grown and network
appliance operating systems out there, and basic things like event
channels would fail to work if the shared_info was in the wrong mode.
That said, I would not be averse to fixing it. We could just use
is_64_bit_hypercall() in kvm_xen_write_hypercall_page(), right?
Or at the very least a comment saying that it *should* be doing so, but
that we're too nervous to change it now?
Attachment:
smime.p7s
Description: S/MIME cryptographic signature