Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1580798
| From | Thomas Garnier <thgarnie@google.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH v3 4/4] KVM: VMX: Simplify segment_base |
| Date | 2017-02-14 20:50 +0100 |
| Message-ID | <taRgS-5Z8-33@gated-at.bofh.it> (permalink) |
| References | <taRgR-5Z8-9@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
The KVM segment_base function is confusing. This patch replaces integers
with appropriate flags, simplify constructs and add comments.
Signed-off-by: Thomas Garnier <thgarnie@google.com>
---
Based on next-20170213
---
arch/x86/kvm/vmx.c | 26 ++++++++++++++++++--------
1 file changed, 18 insertions(+), 8 deletions(-)
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 99167f20bc34..edb8326108dd 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -2062,25 +2062,35 @@ static unsigned long segment_base(u16 selector)
struct desc_struct *d;
unsigned long table_base;
unsigned long v;
+ u32 high32;
- if (!(selector & ~3))
+ if (!(selector & ~SEGMENT_RPL_MASK))
return 0;
- table_base = get_current_gdt_rw_vaddr();
-
- if (selector & 4) { /* from ldt */
+ /* LDT selector */
+ if ((selector & SEGMENT_TI_MASK) == SEGMENT_LDT) {
u16 ldt_selector = kvm_read_ldt();
- if (!(ldt_selector & ~3))
+ if (!(ldt_selector & ~SEGMENT_RPL_MASK))
return 0;
table_base = segment_base(ldt_selector);
+ } else {
+ table_base = get_current_gdt_rw_vaddr();
}
- d = (struct desc_struct *)(table_base + (selector & ~7));
+
+ d = (struct desc_struct *)table_base + (selector >> 3);
v = get_desc_base(d);
#ifdef CONFIG_X86_64
- if (d->s == 0 && (d->type == 2 || d->type == 9 || d->type == 11))
- v |= ((unsigned long)((struct ldttss_desc64 *)d)->base3) << 32;
+ /*
+ * Extend the virtual address if we have a system descriptor entry for
+ * LDT or TSS (available or busy).
+ */
+ if (d->s == 0 && (d->type == DESC_LDT || d->type == DESC_TSS ||
+ d->type == 11/*Busy TSS */)) {
+ high32 = ((struct ldttss_desc64 *)d)->base3;
+ v |= (u64)high32 << 32;
+ }
#endif
return v;
}
--
2.11.0.483.g087da7b7c-goog
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH v3 1/4] x86/mm: Adapt MODULES_END based on Fixmap section size Thomas Garnier <thgarnie@google.com> - 2017-02-14 20:50 +0100
[PATCH v3 3/4] x86: Make the GDT remapping read-only on 64-bit Thomas Garnier <thgarnie@google.com> - 2017-02-14 20:50 +0100
[PATCH v3 2/4] x86: Remap GDT tables in the Fixmap section Thomas Garnier <thgarnie@google.com> - 2017-02-14 20:50 +0100
Re: [PATCH v3 2/4] x86: Remap GDT tables in the Fixmap section Boris Ostrovsky <boris.ostrovsky@oracle.com> - 2017-02-15 16:40 +0100
[PATCH v3 4/4] KVM: VMX: Simplify segment_base Thomas Garnier <thgarnie@google.com> - 2017-02-14 20:50 +0100
Re: [PATCH v3 1/4] x86/mm: Adapt MODULES_END based on Fixmap section size Borislav Petkov <bp@suse.de> - 2017-02-15 15:00 +0100
csiph-web