From: Andy Lutomirski <luto@kernel.org>
To: Paolo Bonzini <pbonzini@redhat.com>, X86 ML <x86@kernel.org>
Cc: "kvm list" <kvm@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"Borislav Petkov" <bpetkov@suse.de>,
"Thomas Garnier" <thgarnie@google.com>,
"Jim Mattson" <jmattson@google.com>,
"Andy Lutomirski" <luto@kernel.org>,
"Radim Krčmář" <rkrcmar@redhat.com>
Subject: [PATCH 4/6] x86/kvm/vmx: Simplify segment_base()
Date: Mon, 20 Feb 2017 08:56:12 -0800 [thread overview]
Message-ID: <5259c65665760cc0755cbb2ae6875954f437d3ec.1487609329.git.luto@kernel.org> (raw)
In-Reply-To: <cover.1487609329.git.luto@kernel.org>
In-Reply-To: <cover.1487609329.git.luto@kernel.org>
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>
---
arch/x86/kvm/vmx.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index b1810a0edec3..17ef11c64702 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -2069,24 +2069,23 @@ static unsigned long segment_base(u16 selector)
{
struct desc_ptr *gdt = this_cpu_ptr(&host_gdt);
struct desc_struct *d;
- unsigned long table_base;
+ struct desc_struct *table;
unsigned long v;
- if (!(selector & ~3))
+ if (!(selector & ~SEGMENT_RPL_MASK))
return 0;
- table_base = gdt->address;
+ table = (struct desc_struct *)gdt->address;
- if (selector & 4) { /* from ldt */
+ 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);
+ table = (struct desc_struct *)segment_base(ldt_selector);
}
- d = (struct desc_struct *)(table_base + (selector & ~7));
- v = get_desc_base(d);
+ v = get_desc_base(&table[selector >> 3]);
return v;
}
#endif
--
2.9.3
next prev parent reply other threads:[~2017-02-20 16:56 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-20 16:56 [PATCH 0/6] KVM TSS cleanups and speedups Andy Lutomirski
2017-02-20 16:56 ` [PATCH 1/6] x86/asm: Define the kernel TSS limit in a macro Andy Lutomirski
2017-02-20 16:56 ` [PATCH 2/6] x86/kvm/vmx: Don't fetch the TSS base from the GDT Andy Lutomirski
2017-02-20 16:56 ` [PATCH 3/6] x86/kvm/vmx: Get rid of segment_base() on 64-bit kernels Andy Lutomirski
2017-02-20 16:56 ` Andy Lutomirski [this message]
2017-02-20 17:49 ` [PATCH 4/6] x86/kvm/vmx: Simplify segment_base() Thomas Garnier
2017-02-20 16:56 ` [PATCH 5/6] x86/asm/64: Drop __cacheline_aligned from struct x86_hw_tss Andy Lutomirski
2017-02-20 16:56 ` [PATCH 6/6] x86/kvm/vmx: Defer TR reload after VM exit Andy Lutomirski
2017-02-20 17:51 ` Paolo Bonzini
2017-02-20 17:52 ` [PATCH 0/6] KVM TSS cleanups and speedups Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5259c65665760cc0755cbb2ae6875954f437d3ec.1487609329.git.luto@kernel.org \
--to=luto@kernel.org \
--cc=bpetkov@suse.de \
--cc=jmattson@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=rkrcmar@redhat.com \
--cc=thgarnie@google.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome