Skip to contentSkip to conversation

KVM: SVM: Use 'unsigned long' for the physical address passed to VMSAVE

PATCH In review Sean Christopherson 2 participants 3 messages Feb 2, 2021 – Feb 3, 2021

Subsystems (3)
lore
Share & tools
lore

Sean Christopherson

author maintainer
#0 lore raw

PATCH 1/1 KVM: SVM: Use 'unsigned long' for the physical address passed to VMSAVE

Take an 'unsigned long' instead of 'hpa_t' in the recently added vmsave() helper, as loading a 64-bit GPR isn't possible in 32-bit mode. This is properly reflected in the SVM ISA, which explicitly states that VMSAVE, VMLOAD, VMRUN, etc... consume rAX based on the effective address size.

Don't bother with a WARN to detect breakage on 32-bit KVM, the VMCB PA is stored as an 'unsigned long', i.e. the bad address is long since gone. Not to mention that a 32-bit kernel is completely hosed if alloc_page() hands out pages in high memory.

---
 arch/x86/kvm/svm/svm_ops.h | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
arch/x86/kvm/svm/svm_ops.h +6 -1
index 0c8377aee52c..9f007bc8409a 100644
@@ -51,7 +51,12 @@ static inline void invlpga(unsigned long addr, u32 asid)
 	svm_asm2(invlpga, "c"(asid), "a"(addr));
 }
 
-static inline void vmsave(hpa_t pa)
+/*
+ * Despite being a physical address, the portion of rAX that is consumed by
+ * VMSAVE, VMLOAD, etc... is still controlled by the effective address size,
+ * hence 'unsigned long' instead of 'hpa_t'.
+ */
+static inline void vmsave(unsigned long pa)
 {
 	svm_asm1(vmsave, "a" (pa), "memory");
 }
Signature · 1 line
2.30.0.365.g02bc693789-goog
author maintainer
#1 lore raw
Quoted 10 lines · Sean Christopherson

Take an 'unsigned long' instead of 'hpa_t' in the recently added vmsave() helper, as loading a 64-bit GPR isn't possible in 32-bit mode. This is properly reflected in the SVM ISA, which explicitly states that VMSAVE, VMLOAD, VMRUN, etc... consume rAX based on the effective address size.

Don't bother with a WARN to detect breakage on 32-bit KVM, the VMCB PA is stored as an 'unsigned long', i.e. the bad address is long since gone. Not to mention that a 32-bit kernel is completely hosed if alloc_page() hands out pages in high memory.

Quoted 6 lines

Forgot got the Fixes tag. Or just squash this.

Fixes f84a54c04540 ("KVM: SVM: Use asm goto to handle unexpected #UD on SVM instructions")
Quoted 25 lines
---
 arch/x86/kvm/svm/svm_ops.h | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
arch/x86/kvm/svm/svm_ops.h +6 -1
index 0c8377aee52c..9f007bc8409a 100644
@@ -51,7 +51,12 @@ static inline void invlpga(unsigned long addr, u32 asid)
 	svm_asm2(invlpga, "c"(asid), "a"(addr));
 }
 
-static inline void vmsave(hpa_t pa)
+/*
+ * Despite being a physical address, the portion of rAX that is consumed by
+ * VMSAVE, VMLOAD, etc... is still controlled by the effective address size,
+ * hence 'unsigned long' instead of 'hpa_t'.
+ */
+static inline void vmsave(unsigned long pa)
 {
 	svm_asm1(vmsave, "a" (pa), "memory");
 }
Signature · 1 line
2.30.0.365.g02bc693789-goog
maintainer
#2 lore raw
In reply to Sean Christopherson
Quoted 21 lines · Sean Christopherson
arch/x86/kvm/svm/svm_ops.h +6 -1
index 0c8377aee52c..9f007bc8409a 100644
@@ -51,7 +51,12 @@ static inline void invlpga(unsigned long addr, u32 asid)
 	svm_asm2(invlpga, "c"(asid), "a"(addr));
 }
 
-static inline void vmsave(hpa_t pa)
+/*
+ * Despite being a physical address, the portion of rAX that is consumed by
+ * VMSAVE, VMLOAD, etc... is still controlled by the effective address size,
+ * hence 'unsigned long' instead of 'hpa_t'.
+ */
+static inline void vmsave(unsigned long pa)
 {
 	svm_asm1(vmsave, "a" (pa), "memory");
 }
Signature · 1 line
2.30.0.365.g02bc693789-goog

Squashed, thanks.

Paolo