Re: [PATCH v4 02/30] KVM: x86: Move get_segment_base() to regs.h, as kvm_get_segment_base()

From: Binbin Wu

Date: Mon Jun 15 2026 - 01:04:26 EST




On 6/13/2026 8:03 AM, Sean Christopherson wrote:
> Move get_segment_base() to regs.h, as kvm_get_segment_base(), so that the
> bulk of the register code can be moved from x86.c to a new regs.c, without
> simultaneously needing to rename "public" helpers to explicitly scope them
> to KVM.
>
> No functional change intended.
>
> Cc: Yosry Ahmed <yosry@xxxxxxxxxx>
> Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx>

Reviewed-by: Binbin Wu <binbin.wu@xxxxxxxxxxxxxxx>

> ---
> arch/x86/kvm/regs.h | 5 +++++
> arch/x86/kvm/x86.c | 9 ++-------
> 2 files changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/arch/x86/kvm/regs.h b/arch/x86/kvm/regs.h
> index a57ba26279ed..e5b16a0826d9 100644
> --- a/arch/x86/kvm/regs.h
> +++ b/arch/x86/kvm/regs.h
> @@ -412,4 +412,9 @@ static inline bool is_guest_mode(struct kvm_vcpu *vcpu)
> return vcpu->arch.hflags & HF_GUEST_MASK;
> }
>
> +static inline unsigned long kvm_get_segment_base(struct kvm_vcpu *vcpu, int seg)
> +{
> + return kvm_x86_call(get_segment_base)(vcpu, seg);
> +}
> +
> #endif
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 74b8f98dcb24..0f48cd630c32 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -8492,11 +8492,6 @@ static int emulator_pio_out_emulated(struct x86_emulate_ctxt *ctxt,
> return emulator_pio_out(emul_to_vcpu(ctxt), size, port, val, count);
> }
>
> -static unsigned long get_segment_base(struct kvm_vcpu *vcpu, int seg)
> -{
> - return kvm_x86_call(get_segment_base)(vcpu, seg);
> -}
> -
> static void emulator_invlpg(struct x86_emulate_ctxt *ctxt, ulong address)
> {
> kvm_mmu_invlpg(emul_to_vcpu(ctxt), address);
> @@ -8641,7 +8636,7 @@ static void emulator_set_idt(struct x86_emulate_ctxt *ctxt, struct desc_ptr *dt)
> static unsigned long emulator_get_cached_segment_base(
> struct x86_emulate_ctxt *ctxt, int seg)
> {
> - return get_segment_base(emul_to_vcpu(ctxt), seg);
> + return kvm_get_segment_base(emul_to_vcpu(ctxt), seg);
> }
>
> static bool emulator_get_segment(struct x86_emulate_ctxt *ctxt, u16 *selector,
> @@ -13839,7 +13834,7 @@ unsigned long kvm_get_linear_rip(struct kvm_vcpu *vcpu)
>
> if (is_64_bit_mode(vcpu))
> return kvm_rip_read(vcpu);
> - return (u32)(get_segment_base(vcpu, VCPU_SREG_CS) +
> + return (u32)(kvm_get_segment_base(vcpu, VCPU_SREG_CS) +
> kvm_rip_read(vcpu));
> }
> EXPORT_SYMBOL_FOR_KVM_INTERNAL(kvm_get_linear_rip);