Re: [PATCH v1 2/4] KVM: x86: Introduce MSR read/write emulation helpers
From: Chao Gao
Date: Thu Jul 31 2025 - 06:35:21 EST
>-fastpath_t handle_fastpath_set_msr_irqoff(struct kvm_vcpu *vcpu)
>+static fastpath_t handle_set_msr_irqoff(struct kvm_vcpu *vcpu, u32 msr, int reg)
How about __handle_fastpath_set_msr_irqoff()? It's better to keep
"fastpath" in the function name to convey that this function is for
fastpath only.
> {
>- u32 msr = kvm_rcx_read(vcpu);
> u64 data;
> fastpath_t ret;
> bool handled;
>@@ -2174,11 +2190,19 @@ fastpath_t handle_fastpath_set_msr_irqoff(struct kvm_vcpu *vcpu)
>
> switch (msr) {
> case APIC_BASE_MSR + (APIC_ICR >> 4):
>- data = kvm_read_edx_eax(vcpu);
>+ if (reg == VCPU_EXREG_EDX_EAX)
>+ data = kvm_read_edx_eax(vcpu);
>+ else
>+ data = kvm_register_read(vcpu, reg);
...
>+
> handled = !handle_fastpath_set_x2apic_icr_irqoff(vcpu, data);
> break;
> case MSR_IA32_TSC_DEADLINE:
>- data = kvm_read_edx_eax(vcpu);
>+ if (reg == VCPU_EXREG_EDX_EAX)
>+ data = kvm_read_edx_eax(vcpu);
>+ else
>+ data = kvm_register_read(vcpu, reg);
>+
Hoist this chunk out of the switch clause to avoid duplication.
> handled = !handle_fastpath_set_tscdeadline(vcpu, data);
> break;
> default:
>@@ -2200,6 +2224,11 @@ fastpath_t handle_fastpath_set_msr_irqoff(struct kvm_vcpu *vcpu)
>
> return ret;
> }
>+
>+fastpath_t handle_fastpath_set_msr_irqoff(struct kvm_vcpu *vcpu)
>+{
>+ return handle_set_msr_irqoff(vcpu, kvm_rcx_read(vcpu), VCPU_EXREG_EDX_EAX);
>+}
> EXPORT_SYMBOL_GPL(handle_fastpath_set_msr_irqoff);
>
> /*
>--
>2.50.1
>