Re: [PATCH v4 01/30] KVM: x86: Extract REGS and SREGS runtime sync code to helpers

From: Binbin Wu

Date: Mon Jun 15 2026 - 01:03:45 EST




On 6/13/2026 8:03 AM, Sean Christopherson wrote:
> Extract the REGS and SREGS portions of {store,sync}_regs() into separate
> helpers in anticipation of moving the register specific code out of x86.c
> and into regs.c.
>
> 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/x86.c | 17 +++++++++++++++--
> 1 file changed, 15 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index cf122b8c3210..74b8f98dcb24 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -12687,7 +12687,7 @@ int kvm_arch_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu)
> return 0;
> }
>
> -static void store_regs(struct kvm_vcpu *vcpu)
> +static void kvm_run_sync_regs_to_user(struct kvm_vcpu *vcpu)
> {
> BUILD_BUG_ON(sizeof(struct kvm_sync_regs) > SYNC_REGS_SIZE_BYTES);
>
> @@ -12696,13 +12696,18 @@ static void store_regs(struct kvm_vcpu *vcpu)
>
> if (vcpu->run->kvm_valid_regs & KVM_SYNC_X86_SREGS)
> __get_sregs(vcpu, &vcpu->run->s.regs.sregs);
> +}
> +
> +static void store_regs(struct kvm_vcpu *vcpu)
> +{
> + kvm_run_sync_regs_to_user(vcpu);
>
> if (vcpu->run->kvm_valid_regs & KVM_SYNC_X86_EVENTS)
> kvm_vcpu_ioctl_x86_get_vcpu_events(
> vcpu, &vcpu->run->s.regs.events);
> }
>
> -static int sync_regs(struct kvm_vcpu *vcpu)
> +static int kvm_run_sync_regs_from_user(struct kvm_vcpu *vcpu)
> {
> if (vcpu->run->kvm_dirty_regs & KVM_SYNC_X86_REGS) {
> __set_regs(vcpu, &vcpu->run->s.regs.regs);
> @@ -12718,6 +12723,14 @@ static int sync_regs(struct kvm_vcpu *vcpu)
> vcpu->run->kvm_dirty_regs &= ~KVM_SYNC_X86_SREGS;
> }
>
> + return 0;
> +}
> +
> +static int sync_regs(struct kvm_vcpu *vcpu)
> +{
> + if (kvm_run_sync_regs_from_user(vcpu))
> + return -EINVAL;
> +
> if (vcpu->run->kvm_dirty_regs & KVM_SYNC_X86_EVENTS) {
> struct kvm_vcpu_events events = vcpu->run->s.regs.events;
>