0296-x86-svm-Set-IBPB-when-running-a-different-VCPU.patch 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Tom Lendacky <[email protected]>
  3. Date: Wed, 20 Dec 2017 10:55:47 +0000
  4. Subject: [PATCH] x86/svm: Set IBPB when running a different VCPU
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. CVE-2017-5753
  9. CVE-2017-5715
  10. Set IBPB (Indirect Branch Prediction Barrier) when the current CPU is
  11. going to run a VCPU different from what was previously run.
  12. Signed-off-by: Paolo Bonzini <[email protected]>
  13. Signed-off-by: Tom Lendacky <[email protected]>
  14. Signed-off-by: Andy Whitcroft <[email protected]>
  15. Signed-off-by: Kleber Sacilotto de Souza <[email protected]>
  16. (cherry picked from commit 0ba3eaabbb6666ebd344ee80534e58c375a00810)
  17. Signed-off-by: Fabian Grünbichler <[email protected]>
  18. ---
  19. arch/x86/kvm/svm.c | 16 ++++++++++++++++
  20. 1 file changed, 16 insertions(+)
  21. diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
  22. index a1b19e810c49..fade4869856a 100644
  23. --- a/arch/x86/kvm/svm.c
  24. +++ b/arch/x86/kvm/svm.c
  25. @@ -518,6 +518,8 @@ struct svm_cpu_data {
  26. struct kvm_ldttss_desc *tss_desc;
  27. struct page *save_area;
  28. +
  29. + struct vmcb *current_vmcb;
  30. };
  31. static DEFINE_PER_CPU(struct svm_cpu_data *, svm_data);
  32. @@ -1685,11 +1687,19 @@ static void svm_free_vcpu(struct kvm_vcpu *vcpu)
  33. __free_pages(virt_to_page(svm->nested.msrpm), MSRPM_ALLOC_ORDER);
  34. kvm_vcpu_uninit(vcpu);
  35. kmem_cache_free(kvm_vcpu_cache, svm);
  36. +
  37. + /*
  38. + * The VMCB could be recycled, causing a false negative in svm_vcpu_load;
  39. + * block speculative execution.
  40. + */
  41. + if (ibpb_inuse)
  42. + wrmsrl(MSR_IA32_PRED_CMD, FEATURE_SET_IBPB);
  43. }
  44. static void svm_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
  45. {
  46. struct vcpu_svm *svm = to_svm(vcpu);
  47. + struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
  48. int i;
  49. if (unlikely(cpu != vcpu->cpu)) {
  50. @@ -1718,6 +1728,12 @@ static void svm_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
  51. if (static_cpu_has(X86_FEATURE_RDTSCP))
  52. wrmsrl(MSR_TSC_AUX, svm->tsc_aux);
  53. + if (sd->current_vmcb != svm->vmcb) {
  54. + sd->current_vmcb = svm->vmcb;
  55. + if (ibpb_inuse)
  56. + wrmsrl(MSR_IA32_PRED_CMD, FEATURE_SET_IBPB);
  57. + }
  58. +
  59. avic_vcpu_load(vcpu, cpu);
  60. }
  61. --
  62. 2.14.2