* [PATCH v2 0/2] minor cleanups on efer emulation
@ 2022-03-11 10:26 Zhenzhong Duan
2022-03-11 10:26 ` [PATCH v2 1/2] KVM: x86: Remove unnecessory assignment to uret->data Zhenzhong Duan
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Zhenzhong Duan @ 2022-03-11 10:26 UTC (permalink / raw)
To: kvm, linux-kernel; +Cc: pbonzini, seanjc, vkuznets, wanpengli, jmattson, joro
These two patches remove some redundant code related to mode switch
and EFER emulation.
Sanity tested with kernel in L0, L1 and L2 all patched.
v2: Split to two patches and use comments from Sean to explain why
it's secure to remove them, suggested by Sean.
Zhenzhong Duan (2):
KVM: x86: Remove unnecessory assignment to uret->data
KVM: x86: Remove redundant vm_entry_controls_clearbit() call
arch/x86/kvm/vmx/vmx.c | 15 +++++----------
1 file changed, 5 insertions(+), 10 deletions(-)
--
2.25.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2 1/2] KVM: x86: Remove unnecessory assignment to uret->data
2022-03-11 10:26 [PATCH v2 0/2] minor cleanups on efer emulation Zhenzhong Duan
@ 2022-03-11 10:26 ` Zhenzhong Duan
2022-03-11 10:26 ` [PATCH v2 2/2] KVM: x86: Remove redundant vm_entry_controls_clearbit() call Zhenzhong Duan
2022-03-25 9:14 ` [PATCH v2 0/2] minor cleanups on efer emulation Paolo Bonzini
2 siblings, 0 replies; 4+ messages in thread
From: Zhenzhong Duan @ 2022-03-11 10:26 UTC (permalink / raw)
To: kvm, linux-kernel; +Cc: pbonzini, seanjc, vkuznets, wanpengli, jmattson, joro
While update_transition_efer() doesn't unconditionally set uret->data,
which on the surface makes this look suspect, but it's safe because
uret->data is consumed if and only if uret->load_into_hardware is
true, and it's (a) set to false if uret->data isn't updated and
(b) uret->data is guaranteed to be updated before it's set to true.
Drop the local "msr" and use "vmx" directly instead of redoing to_vmx().
Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
---
arch/x86/kvm/vmx/vmx.c | 14 +++++---------
1 file changed, 5 insertions(+), 9 deletions(-)
diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index b730d799c26e..cadb3769031c 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -2871,21 +2871,17 @@ static void enter_rmode(struct kvm_vcpu *vcpu)
int vmx_set_efer(struct kvm_vcpu *vcpu, u64 efer)
{
struct vcpu_vmx *vmx = to_vmx(vcpu);
- struct vmx_uret_msr *msr = vmx_find_uret_msr(vmx, MSR_EFER);
/* Nothing to do if hardware doesn't support EFER. */
- if (!msr)
+ if (!vmx_find_uret_msr(vmx, MSR_EFER))
return 0;
vcpu->arch.efer = efer;
- if (efer & EFER_LMA) {
- vm_entry_controls_setbit(to_vmx(vcpu), VM_ENTRY_IA32E_MODE);
- msr->data = efer;
- } else {
- vm_entry_controls_clearbit(to_vmx(vcpu), VM_ENTRY_IA32E_MODE);
+ if (efer & EFER_LMA)
+ vm_entry_controls_setbit(vmx, VM_ENTRY_IA32E_MODE);
+ else
+ vm_entry_controls_clearbit(vmx, VM_ENTRY_IA32E_MODE);
- msr->data = efer & ~EFER_LME;
- }
vmx_setup_uret_msrs(vmx);
return 0;
}
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v2 2/2] KVM: x86: Remove redundant vm_entry_controls_clearbit() call
2022-03-11 10:26 [PATCH v2 0/2] minor cleanups on efer emulation Zhenzhong Duan
2022-03-11 10:26 ` [PATCH v2 1/2] KVM: x86: Remove unnecessory assignment to uret->data Zhenzhong Duan
@ 2022-03-11 10:26 ` Zhenzhong Duan
2022-03-25 9:14 ` [PATCH v2 0/2] minor cleanups on efer emulation Paolo Bonzini
2 siblings, 0 replies; 4+ messages in thread
From: Zhenzhong Duan @ 2022-03-11 10:26 UTC (permalink / raw)
To: kvm, linux-kernel; +Cc: pbonzini, seanjc, vkuznets, wanpengli, jmattson, joro
When emulating exit from long mode, EFER_LMA is cleared which lead to
efer writing emulation, which will unset VM_ENTRY_IA32E_MODE control
bit as requested by SDM. So no need to unset VM_ENTRY_IA32E_MODE again
in exit_lmode() explicitly.
In fact benefited from shadow controls mechanism, this change doesn't
eliminate vmread or vmwrite.
In case EFER isn't supported by hardware, long mode isn't supported,
so this will no break.
Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
---
arch/x86/kvm/vmx/vmx.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index cadb3769031c..70717f56a2a2 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -2907,7 +2907,6 @@ static void enter_lmode(struct kvm_vcpu *vcpu)
static void exit_lmode(struct kvm_vcpu *vcpu)
{
- vm_entry_controls_clearbit(to_vmx(vcpu), VM_ENTRY_IA32E_MODE);
vmx_set_efer(vcpu, vcpu->arch.efer & ~EFER_LMA);
}
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2 0/2] minor cleanups on efer emulation
2022-03-11 10:26 [PATCH v2 0/2] minor cleanups on efer emulation Zhenzhong Duan
2022-03-11 10:26 ` [PATCH v2 1/2] KVM: x86: Remove unnecessory assignment to uret->data Zhenzhong Duan
2022-03-11 10:26 ` [PATCH v2 2/2] KVM: x86: Remove redundant vm_entry_controls_clearbit() call Zhenzhong Duan
@ 2022-03-25 9:14 ` Paolo Bonzini
2 siblings, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2022-03-25 9:14 UTC (permalink / raw)
To: Zhenzhong Duan
Cc: kvm, linux-kernel, pbonzini, seanjc, vkuznets, wanpengli, jmattson, joro
Queued, thanks.
Paolo
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-03-25 9:14 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-11 10:26 [PATCH v2 0/2] minor cleanups on efer emulation Zhenzhong Duan
2022-03-11 10:26 ` [PATCH v2 1/2] KVM: x86: Remove unnecessory assignment to uret->data Zhenzhong Duan
2022-03-11 10:26 ` [PATCH v2 2/2] KVM: x86: Remove redundant vm_entry_controls_clearbit() call Zhenzhong Duan
2022-03-25 9:14 ` [PATCH v2 0/2] minor cleanups on efer emulation Paolo Bonzini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).