mirror of
https://github.com/torvalds/linux.git
synced 2026-09-22 20:54:03 +02:00
KVM: nSVM: Use CLASS(kvm_vcpu_map_local) for SMM VMCB mappings
Convert the kvm_vcpu_map() usage in the enter/leave SMM flows to the new CLASS(kvm_vcpu_map_local) implementations, to eliminate the need to manually do unmap() in error paths, and more importantly to eliminate more of the open-coded on-stack "struct kvm_host_map" declarations. No functional change intended. Link: https://patch.msgid.link/20260724004757.131420-4-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
This commit is contained in:
parent
d196e4d91e
commit
b717245a7b
|
|
@ -4992,7 +4992,6 @@ static int svm_smi_allowed(struct kvm_vcpu *vcpu, bool for_injection)
|
|||
static int svm_enter_smm(struct kvm_vcpu *vcpu, union kvm_smram *smram)
|
||||
{
|
||||
struct vcpu_svm *svm = to_svm(vcpu);
|
||||
struct kvm_host_map map_save;
|
||||
|
||||
if (!is_guest_mode(vcpu))
|
||||
return 0;
|
||||
|
|
@ -5026,24 +5025,20 @@ static int svm_enter_smm(struct kvm_vcpu *vcpu, union kvm_smram *smram)
|
|||
* that, see svm_prepare_switch_to_guest()) which must be
|
||||
* preserved.
|
||||
*/
|
||||
if (kvm_vcpu_map(vcpu, gpa_to_gfn(svm->nested.hsave_msr), &map_save))
|
||||
CLASS(kvm_vcpu_map_local, m_save)(vcpu, gpa_to_gfn(svm->nested.hsave_msr));
|
||||
if (m_save.ret)
|
||||
return 1;
|
||||
|
||||
BUILD_BUG_ON(offsetof(struct vmcb, save) != 0x400);
|
||||
|
||||
svm_copy_vmrun_state(map_save.hva + 0x400,
|
||||
&svm->vmcb01.ptr->save);
|
||||
|
||||
kvm_vcpu_unmap(vcpu, &map_save);
|
||||
svm_copy_vmrun_state(m_save.map.hva + 0x400, &svm->vmcb01.ptr->save);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int svm_leave_smm(struct kvm_vcpu *vcpu, const union kvm_smram *smram)
|
||||
{
|
||||
struct vcpu_svm *svm = to_svm(vcpu);
|
||||
struct kvm_host_map map, map_save;
|
||||
struct vmcb *vmcb12;
|
||||
int ret;
|
||||
|
||||
const struct kvm_smram_state_64 *smram64 = &smram->smram64;
|
||||
|
||||
|
|
@ -5060,22 +5055,23 @@ static int svm_leave_smm(struct kvm_vcpu *vcpu, const union kvm_smram *smram)
|
|||
if (!(smram64->efer & EFER_SVME))
|
||||
return 1;
|
||||
|
||||
if (kvm_vcpu_map(vcpu, gpa_to_gfn(smram64->svm_guest_vmcb_gpa), &map))
|
||||
CLASS(kvm_vcpu_map_local, m)(vcpu, gpa_to_gfn(smram64->svm_guest_vmcb_gpa));
|
||||
if (m.ret)
|
||||
return 1;
|
||||
|
||||
ret = 1;
|
||||
if (kvm_vcpu_map(vcpu, gpa_to_gfn(svm->nested.hsave_msr), &map_save))
|
||||
goto unmap_map;
|
||||
CLASS(kvm_vcpu_map_local, m_save)(vcpu, gpa_to_gfn(svm->nested.hsave_msr));
|
||||
if (m_save.ret)
|
||||
return 1;
|
||||
|
||||
if (svm_allocate_nested(svm))
|
||||
goto unmap_save;
|
||||
return 1;
|
||||
|
||||
/*
|
||||
* Restore L1 host state from L1 HSAVE area as VMCB01 was
|
||||
* used during SMM (see svm_enter_smm())
|
||||
*/
|
||||
|
||||
svm_copy_vmrun_state(&svm->vmcb01.ptr->save, map_save.hva + 0x400);
|
||||
svm_copy_vmrun_state(&svm->vmcb01.ptr->save, m_save.map.hva + 0x400);
|
||||
|
||||
/*
|
||||
* Enter the nested guest now
|
||||
|
|
@ -5083,24 +5079,18 @@ static int svm_leave_smm(struct kvm_vcpu *vcpu, const union kvm_smram *smram)
|
|||
|
||||
vmcb_mark_all_dirty(svm->vmcb01.ptr);
|
||||
|
||||
vmcb12 = map.hva;
|
||||
vmcb12 = m.map.hva;
|
||||
nested_copy_vmcb_control_to_cache(svm, &vmcb12->control);
|
||||
nested_copy_vmcb_save_to_cache(svm, &vmcb12->save);
|
||||
|
||||
if (nested_svm_check_cached_vmcb12(vcpu) < 0)
|
||||
goto unmap_save;
|
||||
return 1;
|
||||
|
||||
if (enter_svm_guest_mode(vcpu, smram64->svm_guest_vmcb_gpa, false) != 0)
|
||||
goto unmap_save;
|
||||
return 1;
|
||||
|
||||
ret = 0;
|
||||
vcpu->arch.nested_run_pending = KVM_NESTED_RUN_PENDING;
|
||||
|
||||
unmap_save:
|
||||
kvm_vcpu_unmap(vcpu, &map_save);
|
||||
unmap_map:
|
||||
kvm_vcpu_unmap(vcpu, &map);
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void svm_enable_smi_window(struct kvm_vcpu *vcpu)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user