Skip to content

Commit 8c2e41f

Browse files
amlutobonzini
authored andcommitted
x86/kvm/vmx: Simplify segment_base()
Use actual pointer types for pointers (instead of unsigned long) and replace hardcoded constants with the appropriate self-documenting macros. The function is still a bit messy, but this seems a lot better than before to me. This is mostly borrowed from a patch by Thomas Garnier. Cc: Thomas Garnier <thgarnie@google.com> Cc: Jim Mattson <jmattson@google.com> Cc: Radim Krčmář <rkrcmar@redhat.com> Cc: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Andy Lutomirski <luto@kernel.org> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent e28baea commit 8c2e41f

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

arch/x86/kvm/vmx.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2067,24 +2067,23 @@ static unsigned long segment_base(u16 selector)
20672067
{
20682068
struct desc_ptr *gdt = this_cpu_ptr(&host_gdt);
20692069
struct desc_struct *d;
2070-
unsigned long table_base;
2070+
struct desc_struct *table;
20712071
unsigned long v;
20722072

2073-
if (!(selector & ~3))
2073+
if (!(selector & ~SEGMENT_RPL_MASK))
20742074
return 0;
20752075

2076-
table_base = gdt->address;
2076+
table = (struct desc_struct *)gdt->address;
20772077

2078-
if (selector & 4) { /* from ldt */
2078+
if ((selector & SEGMENT_TI_MASK) == SEGMENT_LDT) {
20792079
u16 ldt_selector = kvm_read_ldt();
20802080

2081-
if (!(ldt_selector & ~3))
2081+
if (!(ldt_selector & ~SEGMENT_RPL_MASK))
20822082
return 0;
20832083

2084-
table_base = segment_base(ldt_selector);
2084+
table = (struct desc_struct *)segment_base(ldt_selector);
20852085
}
2086-
d = (struct desc_struct *)(table_base + (selector & ~7));
2087-
v = get_desc_base(d);
2086+
v = get_desc_base(&table[selector >> 3]);
20882087
return v;
20892088
}
20902089
#endif

0 commit comments

Comments
 (0)