linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
To: linux-kernel@vger.kernel.org, xen-devel@lists.xensource.com,
	lenb@kernel.org, linux-acpi@vger.kernel.org, hpa@zytor.com,
	x86@kernel.org
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Subject: [PATCH 3/4] xen/lowlevel: Implement pvop call for store_gdt (gidt)
Date: Wed, 17 Oct 2012 09:49:45 -0400	[thread overview]
Message-ID: <1350481786-4969-4-git-send-email-konrad.wilk@oracle.com> (raw)
In-Reply-To: <1350481786-4969-1-git-send-email-konrad.wilk@oracle.com>

In the past it used to point to 'sgdt' (native_store_gdt)
operation which is a non-privileged operation. This resulted
in the value of 'struct desc_ptr' pointing to an bogus address
0xffff820000000000, instead of the GDT table that Linux thinks
it is using. The end result is that doing:

      store_gdt(&desc);
      load_gdt(&desc);

would blow up b/c xen_load_gdt would try to parse the GDT contents
(desc) and de-reference an bogus virtual address.

With this patch we are providing the last written address and size
of the GDT.

Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
---
 arch/x86/xen/enlighten.c |   16 +++++++++++++++-
 1 files changed, 15 insertions(+), 1 deletions(-)

diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
index f29d6d6..4a65138 100644
--- a/arch/x86/xen/enlighten.c
+++ b/arch/x86/xen/enlighten.c
@@ -471,6 +471,8 @@ static void xen_set_ldt(const void *addr, unsigned entries)
 	xen_mc_issue(PARAVIRT_LAZY_CPU);
 }
 
+static DEFINE_PER_CPU(struct desc_ptr, gdt_desc);
+
 static void xen_load_gdt(const struct desc_ptr *dtr)
 {
 	unsigned long va = dtr->address;
@@ -478,6 +480,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
 	unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
 	unsigned long frames[pages];
 	int f;
+	struct desc_ptr *shadow;
 
 	/*
 	 * A GDT can be up to 64k in size, which corresponds to 8192
@@ -515,8 +518,19 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
 
 	if (HYPERVISOR_set_gdt(frames, size / sizeof(struct desc_struct)))
 		BUG();
+
+	shadow = &__get_cpu_var(gdt_desc);
+	shadow->address = dtr->address;
+	shadow->size = size;
 }
 
+static void xen_store_gdt(struct desc_ptr *dtr)
+{
+	const struct desc_ptr *desc = &__get_cpu_var(gdt_desc);
+
+	dtr->address = desc->address;
+	dtr->size = desc->size;
+}
 /*
  * load_gdt for early boot, when the gdt is only mapped once
  */
@@ -1205,7 +1219,7 @@ static const struct pv_cpu_ops xen_cpu_ops __initconst = {
 	.alloc_ldt = xen_alloc_ldt,
 	.free_ldt = xen_free_ldt,
 
-	.store_gdt = native_store_gdt,
+	.store_gdt = xen_store_gdt,
 	.store_idt = xen_store_idt,
 	.store_tr = xen_store_tr,
 
-- 
1.7.7.6


  parent reply	other threads:[~2012-10-17 14:04 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-17 13:49 [RFC] ACPI S3 and Xen (suprisingly small\!) Konrad Rzeszutek Wilk
2012-10-17 13:49 ` [PATCH 1/4] x86/wakeup/sleep: Check whether the TSS GDT descriptor is empty before using it Konrad Rzeszutek Wilk
2012-10-18  0:03   ` H. Peter Anvin
2012-10-18 14:47     ` Konrad Rzeszutek Wilk
2012-10-18 15:01       ` H. Peter Anvin
2013-01-17 14:41     ` Konrad Rzeszutek Wilk
2012-10-17 13:49 ` [PATCH 2/4] xen/lowlevel: Implement pvop call for load_idt (sidt) Konrad Rzeszutek Wilk
2012-10-17 23:51   ` H. Peter Anvin
2012-10-18 14:45     ` Konrad Rzeszutek Wilk
2012-10-18 15:02       ` H. Peter Anvin
2013-01-17 14:36     ` Konrad Rzeszutek Wilk
2012-10-17 13:49 ` Konrad Rzeszutek Wilk [this message]
2012-10-17 13:49 ` [PATCH 4/4] xen/acpi: Prep saved_context cr3 values Konrad Rzeszutek Wilk
2013-01-17 14:48   ` Konrad Rzeszutek Wilk
2012-10-17 16:03 ` [RFC] ACPI S3 and Xen (suprisingly small\!) H. Peter Anvin
2012-10-17 16:10   ` Is: axe read_tscp pvops call. Was: " Konrad Rzeszutek Wilk
2012-10-17 16:39     ` Konrad Rzeszutek Wilk
2012-10-17 16:54       ` H. Peter Anvin
2012-10-17 16:50     ` H. Peter Anvin
2012-10-17 16:54       ` Konrad Rzeszutek Wilk
2012-10-17 17:35         ` H. Peter Anvin
2012-10-18 15:22           ` [Xen-devel] " Dan Magenheimer
2012-10-18 15:28             ` H. Peter Anvin
2012-10-18 15:56               ` Dan Magenheimer
2012-10-18 16:17                 ` Borislav Petkov
2012-10-18 16:44                   ` Stefano Stabellini
2012-10-18 17:04                     ` H. Peter Anvin
2012-10-18 16:37                 ` H. Peter Anvin
2012-10-19 15:48                   ` Is: Xen architecture document. Was: " Konrad Rzeszutek Wilk
2012-10-19 17:45                     ` H. Peter Anvin
2012-10-18 16:31         ` David Vrabel
2012-10-18 17:42           ` Konrad Rzeszutek Wilk
2012-10-18 18:02             ` David Vrabel
2012-10-17 17:46 ` Ben Guthro
2012-10-17 17:43   ` Konrad Rzeszutek Wilk
2012-10-17 18:00     ` Ben Guthro
2012-10-19 18:49       ` Konrad Rzeszutek Wilk
2012-10-20  1:23         ` Ben Guthro

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=1350481786-4969-4-git-send-email-konrad.wilk@oracle.com \
    --to=konrad.wilk@oracle.com \
    --cc=hpa@zytor.com \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=x86@kernel.org \
    --cc=xen-devel@lists.xensource.com \
    /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;
as well as URLs for NNTP newsgroup(s).