Re: [PATCH v1 2/4] KVM: nSVM: Delay stuffing L2's current RIP into NextRIP until vCPU run

From: Yosry Ahmed

Date: Tue Feb 24 2026 - 20:56:02 EST


> > We discussed a helper before and you didn't like it, but that was in a
> > different context (a helper that combined normal and special cases).
> > WDYT?
>
> A helper would work. svm_fixup_nested_rips() is good, the only flaw is the CS.base
> chunk, but I'm not sure I care enough about 32-bit to reject the name just because
> of that :-)
>
> That would make it easier to reduce indentation, e.g.
>
> static void svm_fixup_nested_rips(struct kvm_vcpu *vcpu)
> {
> struct vcpu_svm *svm = to_svm(vcpu);
>
> /*
> * If nrips is supported in hardware but not exposed to L1, stuff the
> * actual L2 RIP to emulate what a nrips=0 CPU would do (L1 is
> * responsible for advancing RIP prior to injecting the event). Once L2
> * runs after L1 executes VMRUN, NextRIP is updated by the CPU and/or
> * KVM, and this is no longer needed.
> *
> * This is done here (as opposed to when preparing vmcb02) to use the
> * most up-to-date value of RIP regardless of the order of restoring
> * registers and nested state in the vCPU save+restore path.
> *
> * Simiarly, initialize svm->soft_int_* fields here to use the most
> * up-to-date values of RIP and CS base, regardless of restore order.
> */
> if (!is_guest_mode(vcpu) || !svm->nested.nested_run_pending)
> return;
>
> if (boot_cpu_has(X86_FEATURE_NRIPS) &&
> !guest_cpu_cap_has(vcpu, X86_FEATURE_NRIPS))
> svm->vmcb->control.next_rip = kvm_rip_read(vcpu);
>
> if (svm->soft_int_injected) {
> svm->soft_int_csbase = svm->vmcb->save.cs.base;
> svm->soft_int_old_rip = kvm_rip_read(vcpu);
> if (!guest_cpu_cap_has(vcpu, X86_FEATURE_NRIPS))
> svm->soft_int_next_rip = kvm_rip_read(vcpu);
> }
> }

Looks good, thanks Sean!