Don't map nested_vmcb on INTERCEPT_MSR_PROT
PATCH 1/1 Don't map nested_vmcb on INTERCEPT_MSR_PROT
Thanks to Joerg's previous series of cleanups, we now have almost all information we need to decide what to do on #VMEXIT because we get the variables from the VMCB on VMRUN.
Unfortunately there's one piece that slipped through the conversion, namely the MSR intercept which still tries to map the nested VMCB to find out if MSRs are intercepted.
So let's use the cached value, removing the need for two atomic maps (which breaks anyways) and fix an oops along the way.
---
v1 -> v2:
- Don't break when MSR is not intercepted
--- arch/x86/kvm/svm.c | 15 ++++++--------- 1 files changed, 6 insertions(+), 9 deletions(-)
arch/x86/kvm/svm.c +6 -9
@@ -1427,19 +1427,17 @@ static bool nested_svm_exit_handled_msr(struct vcpu_svm *svm) {u32 param = svm->vmcb->control.exit_info_1 &1 ;u32 msr = svm->vcpu.arch.regs[VCPU_REGS_RCX ]; -struct vmcb *nested_vmcb;bool ret = false;u32 t0, t1;u8 *msrpm; - nested_vmcb =nested_svm_map (svm, svm->nested.vmcb,KM_USER0 ); - msrpm =nested_svm_map (svm, svm->nested.vmcb_msrpm,KM_USER1 ); +if (!(svm->nested.intercept & (1ULL <<INTERCEPT_MSR_PROT ))) +return false; -if (!nested_vmcb || !msrpm) - goto out; + msrpm =nested_svm_map (svm, svm->nested.vmcb_msrpm,KM_USER0 ); -if (!(nested_vmcb->control.intercept & (1ULL <<INTERCEPT_MSR_PROT ))) -return 0 ; +if (!msrpm) + goto out;switch (msr) { case 0 ... 0x1fff:
@@ -1464,8 +1462,7 @@ static bool nested_svm_exit_handled_msr(struct vcpu_svm *svm) ret = msrpm[t1] & ((1 << param) << t0); out: -nested_svm_unmap (nested_vmcb,KM_USER0 ); -nested_svm_unmap (msrpm,KM_USER1 ); +nested_svm_unmap (msrpm,KM_USER0 );return ret; }
Signature · 1 line
1.6.0.2
Indeed. Good catch. Thanks :-)
Quoted 8 lines · Alexander Graf
Thanks to Joerg's previous series of cleanups, we now have almost all information we need to decide what to do on #VMEXIT because we get the variables from the VMCB on VMRUN.
Unfortunately there's one piece that slipped through the conversion, namely the MSR intercept which still tries to map the nested VMCB to find out if MSRs are intercepted.
Quoted 5 lines
So let's use the cached value, removing the need for two atomic maps (which breaks anyways) and fix an oops along the way.
CC Joerg Roedel <[email protected]>Signed-off-by Alexander Graf <[email protected]>
Quoted 53 lines
---
v1 -> v2:
- Don't break when MSR is not intercepted
--- arch/x86/kvm/svm.c | 15 ++++++--------- 1 files changed, 6 insertions(+), 9 deletions(-)arch/x86/kvm/svm.c +6
-9@@ -1427,19 +1427,17 @@ static bool nested_svm_exit_handled_msr(struct vcpu_svm *svm) {u32 param = svm->vmcb->control.exit_info_1 &1 ;u32 msr = svm->vcpu.arch.regs[VCPU_REGS_RCX ]; -struct vmcb *nested_vmcb;bool ret = false;u32 t0, t1;u8 *msrpm; - nested_vmcb =nested_svm_map (svm, svm->nested.vmcb,KM_USER0 ); - msrpm =nested_svm_map (svm, svm->nested.vmcb_msrpm,KM_USER1 ); +if (!(svm->nested.intercept & (1ULL <<INTERCEPT_MSR_PROT ))) +return false; -if (!nested_vmcb || !msrpm) - goto out; + msrpm =nested_svm_map (svm, svm->nested.vmcb_msrpm,KM_USER0 ); -if (!(nested_vmcb->control.intercept & (1ULL <<INTERCEPT_MSR_PROT ))) -return 0 ; +if (!msrpm) + goto out;switch (msr) { case 0 ... 0x1fff:@@ -1464,8 +1462,7 @@ static bool nested_svm_exit_handled_msr(struct vcpu_svm *svm) ret = msrpm[t1] & ((1 << param) << t0); out: -nested_svm_unmap (nested_vmcb,KM_USER0 ); -nested_svm_unmap (msrpm,KM_USER1 ); +nested_svm_unmap (msrpm,KM_USER0 );return ret; }Signature · 1 line
1.6.0.2
Marcelo Tosatti
AppliedQuoted 8 lines · Alexander Graf
Thanks to Joerg's previous series of cleanups, we now have almost all information we need to decide what to do on #VMEXIT because we get the variables from the VMCB on VMRUN.
Unfortunately there's one piece that slipped through the conversion, namely the MSR intercept which still tries to map the nested VMCB to find out if MSRs are intercepted.
Quoted 5 lines
So let's use the cached value, removing the need for two atomic maps (which breaks anyways) and fix an oops along the way.
CC Joerg Roedel <[email protected]>Signed-off-by Alexander Graf <[email protected]>
Applied, thanks.
BTW, why nested_svm_map takes mmap_sem? Thats looks wrong.
Quoted 56 lines
---
v1 -> v2:
- Don't break when MSR is not intercepted
--- arch/x86/kvm/svm.c | 15 ++++++--------- 1 files changed, 6 insertions(+), 9 deletions(-)arch/x86/kvm/svm.c +6
-9@@ -1427,19 +1427,17 @@ static bool nested_svm_exit_handled_msr(struct vcpu_svm *svm) {u32 param = svm->vmcb->control.exit_info_1 &1 ;u32 msr = svm->vcpu.arch.regs[VCPU_REGS_RCX ]; -struct vmcb *nested_vmcb;bool ret = false;u32 t0, t1;u8 *msrpm; - nested_vmcb =nested_svm_map (svm, svm->nested.vmcb,KM_USER0 ); - msrpm =nested_svm_map (svm, svm->nested.vmcb_msrpm,KM_USER1 ); +if (!(svm->nested.intercept & (1ULL <<INTERCEPT_MSR_PROT ))) +return false; -if (!nested_vmcb || !msrpm) - goto out; + msrpm =nested_svm_map (svm, svm->nested.vmcb_msrpm,KM_USER0 ); -if (!(nested_vmcb->control.intercept & (1ULL <<INTERCEPT_MSR_PROT ))) -return 0 ; +if (!msrpm) + goto out;switch (msr) { case 0 ... 0x1fff:@@ -1464,8 +1462,7 @@ static bool nested_svm_exit_handled_msr(struct vcpu_svm *svm) ret = msrpm[t1] & ((1 << param) << t0); out: -nested_svm_unmap (nested_vmcb,KM_USER0 ); -nested_svm_unmap (msrpm,KM_USER1 ); +nested_svm_unmap (msrpm,KM_USER0 );return ret; }Signature · 6 lines
1.6.0.2 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Am 04.09.2009 um 19:05 schrieb Marcelo Tosatti <[email protected]>:
Quoted 12 lines · Alexander Graf
Quoted 11 lines
Thanks to Joerg's previous series of cleanups, we now have almost all information we need to decide what to do on #VMEXIT because we get the variables from the VMCB on VMRUN.
Unfortunately there's one piece that slipped through the conversion, namely the MSR intercept which still tries to map the nested VMCB to find out if MSRs are intercepted.
So let's use the cached value, removing the need for two atomic maps (which breaks anyways) and fix an oops along the way.
Quoted 6 lines
Quoted 2 lines
CC Joerg Roedel <[email protected]>Signed-off-by Alexander Graf <[email protected]>Applied, thanks.
BTW, why
nested_svm_maptakesmmap_sem? Thats looks wrong.
Hm, good question.
As long as it's an atomic section that only touches vcpu local data there's no need to lock at all, right?
Alex
Quoted 61 lines
Quoted 61 lines
---
v1 -> v2:
- Don't break when MSR is not intercepted
---arch/x86/kvm/svm.c| 15 ++++++---------1 files changed, 6 insertions(+), 9 deletions(-)arch/x86/kvm/svm.c +5
-7@@ -1427,19 +1427,17 @@ static bool nested_svm_exit_handled_msr (struct vcpu_svm *svm) { u32 param = svm->vmcb->control.exit_info_1 & 1;u32 msr = svm->vcpu.arch.regs[VCPU_REGS_RCX ]; -struct vmcb *nested_vmcb;bool ret = false;u32 t0, t1;u8 *msrpm; - nested_vmcb =nested_svm_map (svm, svm->nested.vmcb,KM_USER0 ); - msrpm =nested_svm_map (svm, svm->nested.vmcb_msrpm, KM_USER1); +if (!(svm->nested.intercept & (1ULL <<INTERCEPT_MSR_PROT ))) +return false; -if (!nested_vmcb || !msrpm) - goto out; + msrpm =nested_svm_map (svm, svm->nested.vmcb_msrpm,KM_USER0 ); -if (!(nested_vmcb->control.intercept & (1ULL << INTERCEPT_MSR_PROT))) -return 0 ; +if (!msrpm) + goto out;switch (msr) { case 0 ... 0x1fff:arch/x86/kvm/svm.c +0
-0@@ -1464,8 +1462,7 @@ static bool nested_svm_exit_handled_msr (struct vcpu_svm *svm) ret = msrpm[t1] & ((1 << param) << t0);out:
arch/x86/kvm/svm.c +1
-2-nested_svm_unmap (nested_vmcb,KM_USER0 ); -nested_svm_unmap (msrpm,KM_USER1 ); +nested_svm_unmap (msrpm,KM_USER0 );return ret;}
Signature · 6 lines
1.6.0.2 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 18 lines · Alexander Graf
Am 04.09.2009 um 19:05 schrieb Marcelo Tosatti <[email protected]>:
Quoted 15 lines · Alexander Graf
Quoted 13 lines
Thanks to Joerg's previous series of cleanups, we now have almost all information we need to decide what to do on #VMEXIT because we get the variables from the VMCB on VMRUN.
Unfortunately there's one piece that slipped through the conversion, namely the MSR intercept which still tries to map the nested VMCB to find out if MSRs are intercepted.
So let's use the cached value, removing the need for two atomic maps (which breaks anyways) and fix an oops along the way.
CC Joerg Roedel <[email protected]>Signed-off-by Alexander Graf <[email protected]>
Quoted 8 lines
Quoted 3 lines
Applied, thanks.
BTW, why
nested_svm_maptakesmmap_sem? Thats looks wrong.Hm, good question.
As long as it's an atomic section that only touches vcpu local data there's no need to lock at all, right?
Yes. gfn_to_page / get_user_pages will grab mmap_sem if required. Can you please send a patch to drop it from nested_svm_map?