All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Garnier <thgarnie@google.com>
To: Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, "H . Peter Anvin" <hpa@zytor.com>,
	Jonathan Corbet <corbet@lwn.net>,
	Thomas Garnier <thgarnie@google.com>,
	Kees Cook <keescook@chromium.org>,
	Lorenzo Stoakes <lstoakes@gmail.com>,
	Juergen Gross <jgross@suse.com>,
	Andy Lutomirski <luto@amacapital.net>,
	"Rafael J . Wysocki" <rjw@rjwysocki.net>,
	Len Brown <len.brown@intel.com>, Pavel Machek <pavel@ucw.cz>,
	Jiri Kosina <jikos@kernel.org>,
	Matt Fleming <matt@codeblueprint.co.uk>,
	Ard Biesheuvel <ard.biesheuvel@linaro.org>,
	Boris Ostrovsky <boris.ostrovsky@oracle.com>,
	Rusty Russell <rusty@rustcorp.com.au>,
	Borislav Petkov <bp@suse.de>,
	Christian Borntraeger <borntraeger@de.ibm.com>,
	Brian Gerst <brgerst@gmail.com>,
	He Chen <he.chen@linux.intel.com>,
	"Luis R . Rodriguez" <mcgrof@kernel.org>,
	Stanislaw Gruszka <sgruszka@redhat.com>,
	Arnd Bergmann <arnd@arndb>
Cc: linux-efi@vger.kernel.org, kvm@vger.kernel.org,
	linux-pm@vger.kernel.org, x86@kernel.org,
	linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
	lguest@lists.ozlabs.org, kernel-hardening@lists.openwall.com,
	xen-devel@lists.xenproject.org
Subject: [PATCH v4 4/4] KVM: VMX: Simplify segment_base
Date: Thu, 16 Feb 2017 13:54:38 -0800	[thread overview]
Message-ID: <20170216215438.126111-4-thgarnie__47745.5310909592$1487282151$gmane$org@google.com> (raw)
In-Reply-To: <20170216215438.126111-1-thgarnie@google.com>

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 | 30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 99167f20bc34..91e619269128 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -2060,27 +2060,37 @@ static bool update_transition_efer(struct vcpu_vmx *vmx, int efer_offset)
 static unsigned long segment_base(u16 selector)
 {
 	struct desc_struct *d;
-	unsigned long table_base;
+	struct desc_struct *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);
+		table_base = (struct desc_struct *)segment_base(ldt_selector);
+	} else {
+		table_base = get_current_gdt_rw();
 	}
-	d = (struct desc_struct *)(table_base + (selector & ~7));
+
+	d = 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


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

  parent reply	other threads:[~2017-02-16 21:54 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-16 21:54 [PATCH v4 1/4] x86/mm: Adapt MODULES_END based on Fixmap section size Thomas Garnier
2017-02-16 21:54 ` [kernel-hardening] " Thomas Garnier
2017-02-16 21:54 ` Thomas Garnier
2017-02-16 21:54 ` Thomas Garnier
2017-02-16 21:54 ` [PATCH v4 2/4] x86: Remap GDT tables in the Fixmap section Thomas Garnier
2017-02-16 21:54 ` Thomas Garnier
2017-02-16 21:54   ` [kernel-hardening] " Thomas Garnier
2017-02-16 21:54   ` Thomas Garnier
2017-02-16 21:54   ` Thomas Garnier
2017-02-16 21:54 ` [PATCH v4 3/4] x86: Make the GDT remapping read-only on 64-bit Thomas Garnier
2017-02-16 21:54 ` Thomas Garnier
2017-02-16 21:54   ` [kernel-hardening] " Thomas Garnier
2017-02-16 21:54   ` Thomas Garnier
2017-02-16 21:54   ` Thomas Garnier
2017-02-16 21:54 ` Thomas Garnier [this message]
2017-02-16 21:54 ` [PATCH v4 4/4] KVM: VMX: Simplify segment_base Thomas Garnier
2017-02-16 21:54   ` [kernel-hardening] " Thomas Garnier
2017-02-16 21:54   ` Thomas Garnier
2017-02-16 21:54   ` Thomas Garnier
2017-02-17  0:37 ` [PATCH v4 1/4] x86/mm: Adapt MODULES_END based on Fixmap section size kbuild test robot
2017-02-17  0:37 ` kbuild test robot
2017-02-17  0:37   ` [kernel-hardening] " kbuild test robot
2017-02-17  0:37   ` kbuild test robot
2017-02-17  0:37   ` kbuild test robot
2017-02-17  0:45 ` kbuild test robot
2017-02-17  0:45 ` kbuild test robot
2017-02-17  0:45   ` [kernel-hardening] " kbuild test robot
2017-02-17  0:45   ` kbuild test robot
2017-02-17  0:45   ` kbuild test robot
2017-02-17 16:00   ` Thomas Garnier
2017-02-17 16:00   ` Thomas Garnier
2017-02-17 16:00     ` [kernel-hardening] " Thomas Garnier
2017-02-17 16:00     ` Thomas Garnier
2017-02-17 20:52     ` Thomas Garnier
2017-02-17 20:52       ` [kernel-hardening] " Thomas Garnier
2017-02-17 20:52       ` Thomas Garnier
2017-02-17 20:52       ` Thomas Garnier
2017-02-17 20:52     ` Thomas Garnier

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='20170216215438.126111-4-thgarnie__47745.5310909592$1487282151$gmane$org@google.com' \
    --to=thgarnie@google.com \
    --cc=ard.biesheuvel@linaro.org \
    --cc=arnd@arndb \
    --cc=boris.ostrovsky@oracle.com \
    --cc=borntraeger@de.ibm.com \
    --cc=bp@suse.de \
    --cc=brgerst@gmail.com \
    --cc=corbet@lwn.net \
    --cc=he.chen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=jgross@suse.com \
    --cc=jikos@kernel.org \
    --cc=keescook@chromium.org \
    --cc=kernel-hardening@lists.openwall.com \
    --cc=kvm@vger.kernel.org \
    --cc=len.brown@intel.com \
    --cc=lguest@lists.ozlabs.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-efi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=lstoakes@gmail.com \
    --cc=luto@amacapital.net \
    --cc=matt@codeblueprint.co.uk \
    --cc=mcgrof@kernel.org \
    --cc=mingo@redhat.com \
    --cc=pavel@ucw.cz \
    --cc=rjw@rjwysocki.net \
    --cc=rusty@rustcorp.com.au \
    --cc=sgruszka@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    --cc=xen-devel@lists.xenproject.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.