Skip to contentSkip to conversation

kvm-kmod: x86: make sure kvm_get_desc_base() doesn't sign extend

PATCH Applied Bernhard Kohl 2 participants 2 messages Oct 12, 2010 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kvm-kmod: x86: make sure kvm_get_desc_base() doesn't sign extend

The current implementation of kvm_get_desc_base() sign extends the return value because of integer promotion rules when compiled for x86_64 kernels. For the most part, this doesn't matter, because the top bit of base2 is usually 0. If, however, that bit is 1, then the entire value will be 0xffff... which is probably not what the caller intended.

We have a legacy OS which runs into errors in certain situations (task switches) because of this bug, i.e. error on vm_entry followed by unhandled vm_exit.

dmesg says:
vmx_handle_exit: unexpected, valid vectoring info (0x80000b0d) and exit reason is 0x80000021
or
vmx_handle_exit: unexpected, valid vectoring info (0x80000300) and exit reason is 0x80000021

qemu-kvm says:
kvm: unhandled exit 80000021
kvm_run returned -22

This fix was originally applied as patch 2c75910 in kvm.git:
"x86: Make sure get_user_desc() doesn't sign extend."

---
 x86/external-module-compat.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
x86/external-module-compat.h +1 -1
index 15b0280..a2af776 100644
@@ -435,7 +435,7 @@ struct kvm_desc_ptr {
 static inline unsigned long
 kvm_get_desc_base(const struct kvm_desc_struct *desc)
 {
-	return desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24);
+	return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
 }
 
 static inline void
Signature · 1 line
1.7.2.3
Applied
#1 lore raw
Quoted 35 lines · Bernhard Kohl

The current implementation of kvm_get_desc_base() sign extends the return value because of integer promotion rules when compiled for x86_64 kernels. For the most part, this doesn't matter, because the top bit of base2 is usually 0. If, however, that bit is 1, then the entire value will be 0xffff... which is probably not what the caller intended.

We have a legacy OS which runs into errors in certain situations (task switches) because of this bug, i.e. error on vm_entry followed by unhandled vm_exit.

dmesg says:
vmx_handle_exit: unexpected, valid vectoring info (0x80000b0d) and exit reason is 0x80000021
or
vmx_handle_exit: unexpected, valid vectoring info (0x80000300) and exit reason is 0x80000021

qemu-kvm says:
kvm: unhandled exit 80000021
kvm_run returned -22

This fix was originally applied as patch 2c75910 in kvm.git:
"x86: Make sure get_user_desc() doesn't sign extend."

---
 x86/external-module-compat.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
x86/external-module-compat.h +0 -0
index 15b0280..a2af776 100644

x86/external-module-compat.h struct kvm_desc_ptr { · line 441

Quoted 8 lines
x86/external-module-compat.h +1 -1
@@ -435,7 +435,7 @@ struct kvm_desc_ptr {
 static inline unsigned long
 kvm_get_desc_base(const struct kvm_desc_struct *desc)
 {
-	return desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24);
+	return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
 }
 
 static inline void

Merged, thanks!

Jan