Re: [PATCH v2 07/15] KVM: x86: Move inlined CR and DR helpers from x86.h to regs.h
From: Yosry Ahmed
Date: Thu May 14 2026 - 18:30:43 EST
On Thu, May 14, 2026 at 2:54 PM Sean Christopherson <seanjc@xxxxxxxxxx> wrote:
>
> Move inlined Control Register and Debug Register helpers from x86.h to the
> aptly named regs.h, to help trim down x86.h (and x86.c in the future).
>
> Move select EFER functionality, but leave behind all other MSR handling,
> There is more than enough MSR code to carve out msr.{c,h} in the future.
> Give EFER special treatment as it's an "MSR" in name only, e.g. it's has
> far more in common with CR4 than it does with any MSR.
>
> No functional change intended.
>
> Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx>
> ---
> arch/x86/kvm/regs.h | 108 ++++++++++++++++++++++++++++++++++++++++++--
> arch/x86/kvm/x86.h | 102 -----------------------------------------
> 2 files changed, 105 insertions(+), 105 deletions(-)
>
> diff --git a/arch/x86/kvm/regs.h b/arch/x86/kvm/regs.h
> index 4440f3992fce..ecc66b577e82 100644
> --- a/arch/x86/kvm/regs.h
> +++ b/arch/x86/kvm/regs.h
> @@ -16,6 +16,37 @@
>
> static_assert(!(KVM_POSSIBLE_CR0_GUEST_BITS & X86_CR0_PDPTR_BITS));
>
> +static inline bool is_long_mode(struct kvm_vcpu *vcpu)
> +{
> +#ifdef CONFIG_X86_64
> + return !!(vcpu->arch.efer & EFER_LMA);
> +#else
> + return false;
> +#endif
> +}
> +
> +static inline bool is_64_bit_mode(struct kvm_vcpu *vcpu)
> +{
> + int cs_db, cs_l;
> +
> + WARN_ON_ONCE(vcpu->arch.guest_state_protected);
> +
> + if (!is_long_mode(vcpu))
> + return false;
> + kvm_x86_call(get_cs_db_l_bits)(vcpu, &cs_db, &cs_l);
> + return cs_l;
> +}
> +
> +static inline bool is_64_bit_hypercall(struct kvm_vcpu *vcpu)
> +{
> + /*
> + * If running with protected guest state, the CS register is not
> + * accessible. The hypercall register values will have had to been
> + * provided in 64-bit mode, so assume the guest is in 64-bit.
> + */
> + return vcpu->arch.guest_state_protected || is_64_bit_mode(vcpu);
> +}
This is really stretching the meaning of 'regs', but it's not that
much worse than 'x86'..
Reviewed-by: Yosry Ahmed <yosry@xxxxxxxxxx>