On Sat, Oct 24, 2026, H. Peter Anvin wrote: > On 2026-09-14 23:03, Xin Li wrote: > > > >> On Sep 11, 2026, at 2:36 PM, Sohil Mehta <[email protected]> wrote: > >> > >> I mainly rebased the patches to the latest kvm-x86/next branch and fixed > >> a handful of issues reported during internal testing and basic AI > >> reviews. I've avoided making any major code changes or commit message > >> updates as this is the first iteration that I am posting. > > > > Thanks a lot for taking care of the patch series. > > > >> > >> Going forward, based on the feedback, I'll rework the patches as needed. > >> I've listed a few opens below that need additional discussion or > >> clarification. I'm relatively new to the KVM subsystem, so please feel > >> free to provide suggestions on the series structure, code organization > >> as well as commit log clarity to smoothen the review process. > > > > I’ve been thinking about an optimization: because FRED drops most of the > > old > > syscall MSRs (IA32_LSTAR/IA32_CSTAR/IA32_SFMASK), we should be able to omit > > > > them from KVM's uret MSR tracking entirely as if host enables FRED (no > > matter > > whether a guest uses FRED). > > > Yes, although they will need to be handled properly between VCPU switches, of > course.
And we'd want to keep the optimizations to elide writes when vCPUs are using the same value(s). So, compile tested only... From: Sean Christopherson <[email protected]> Date: Mon, 26 Oct 2026 07:37:03 -0700 Subject: [PATCH] KVM: x86: Don't bother loading host values for SYSCALL MSRs when FRED is in use Elide the WRMSRs for the SYSCALL MSRs when returning to userspace if FRED is in use, in which case said MSRs are never actually used in Linux. Note, KVM never saves/restores MSR_CSTAR via the user-return MSR mechanism, as the MSR is unused by Intel/VMX hardware, and SVM unconditionally context switches the MSR via a dedicated VMCB field (along with all other SYSCALL MSRs). Include MSR_CSTAR to provide a contiguous range of values in the case statements, e.g. so that the compiler can optimize the case statements into a simple bounds checks. Suggested-by: Xin Li (Intel) <[email protected]> Signed-off-by: Sean Christopherson <[email protected]> --- arch/x86/kvm/msrs.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/msrs.c b/arch/x86/kvm/msrs.c index e91650af44c2..ef3596d8c780 100644 --- a/arch/x86/kvm/msrs.c +++ b/arch/x86/kvm/msrs.c @@ -65,6 +65,23 @@ void kvm_destroy_user_return_msrs(void) kvm_nr_uret_msrs = 0; } +static bool kvm_is_msr_used_in_host(u32 msr) +{ + if (!cpu_feature_enabled(X86_FEATURE_FRED)) + return true; + + switch (msr) { + case MSR_STAR: + case MSR_LSTAR: + case MSR_CSTAR: + case MSR_SYSCALL_MASK: + return false; + default: + break; + } + return true; +} + static void kvm_on_user_return(struct user_return_notifier *urn) { unsigned slot; @@ -77,7 +94,8 @@ static void kvm_on_user_return(struct user_return_notifier *urn) for (slot = 0; slot < kvm_nr_uret_msrs; ++slot) { values = &msrs->values[slot]; - if (values->host != values->curr) { + if (kvm_is_msr_used_in_host(kvm_uret_msrs_list[slot]) && + values->host != values->curr) { wrmsrq(kvm_uret_msrs_list[slot], values->host); values->curr = values->host; } base-commit: 7e60162b16f9da0d2fa83da5c1723b6853a0ac1d --
