Re: [PATCH v3 30/40] KVM: x86: Move MSR helper declarations from kvm_host.h => msrs.h

From: Yosry Ahmed

Date: Mon Jun 01 2026 - 19:38:56 EST


On Mon, Jun 01, 2026 at 07:50:34AM -0700, Sean Christopherson wrote:
> On Sat, May 30, 2026, Yosry Ahmed wrote:
> > On Fri, May 29, 2026 at 03:22:13PM -0700, Sean Christopherson wrote:
> > > Relocate declarations of MSR helpers (and kvm_nr_uret_msrs) from x86's
> > > x86's kvm_host.h to msrs, to continue trimming down kvm_host.h.
> > >
> > > Deliberately leave the funky read_msr() where it is, as it will hopefully
> > > be removed entirely as part of a broader kernel-API cleanup.
> > >
> > > No functional change intended.
> > >
> > > Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx>
> > > ---
> > > arch/x86/include/asm/kvm_host.h | 26 -------------------------
> > > arch/x86/kvm/msrs.h | 34 ++++++++++++++++++++++++++++++---
> > > 2 files changed, 31 insertions(+), 29 deletions(-)
> > >
> > > diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
> > > index a861c0d70be0..1143140592df 100644
> > > --- a/arch/x86/include/asm/kvm_host.h
> > > +++ b/arch/x86/include/asm/kvm_host.h
> > > @@ -2094,7 +2094,6 @@ struct kvm_arch_async_pf {
> > > u64 error_code;
> > > };
> > >
> > > -extern u32 __read_mostly kvm_nr_uret_msrs;
> > > extern bool __read_mostly allow_smaller_maxphyaddr;
> > > extern bool __read_mostly enable_apicv;
> > > extern bool __read_mostly enable_ipiv;
> > > @@ -2278,18 +2277,6 @@ void kvm_prepare_emulation_failure_exit(struct kvm_vcpu *vcpu);
> > > void kvm_prepare_event_vectoring_exit(struct kvm_vcpu *vcpu, gpa_t gpa);
> > > void kvm_prepare_unexpected_reason_exit(struct kvm_vcpu *vcpu, u64 exit_reason);
> > >
> > > -void kvm_enable_efer_bits(u64);
> > > -bool kvm_valid_efer(struct kvm_vcpu *vcpu, u64 efer);
> >
> > Patch 15's changelog makes me thing EFER will belong to regs.[hc] not
> > msrs.[hc]. Did you change your mind?
>
> Not really, patch 15's changelog was always "bad", even in the previous version,
> before msrs.{c,h} was added. The bulk of EFER handling was left behind in x86.c,
> only the {G,S}ET_SREGS accessor/mutator logic gets moved.
>
> I updated patch 07's changelog between v2 and v3 to better reflect reality:
>
> Move *very* select EFER functionality as well, but leave behind the bulk of
> EFER handling and all other MSR handling.
>
> But I missed patch 15. For patch 15, how about this?

LGTM.

>
> Introduce regs.c, and move the vast majority of register specific code out
> of x86.c and into regs.c. Deliberately leave behind MSR code, as KVM's MSR
> support is complex enough to warrant its own compilation unit, and doesn't
> have much in common with the other register code.
>
> Note, "struct kvm_sregs" has fields for EFER and MSR_IA32_APICBASE, and so
> the {G,S}ET_REGS flows technically contain a tiny amount of MSR code.
> MSR_IA32_APICBASE is already managed by lapic.c, and so doesn't require a
> "placement decision". As for EFER, leave all other EFER handling in x86.c
> (later to be moved to msrs.c), as the primary interface to EFER,
> set_efer(), is very much MSR specific, even though EFER is arguably more
> of a Control Register than an MSR.
>
> No functional change intended.