All of lore.kernel.org
 help / color / mirror / Atom feed
From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
To: "H. Peter Anvin" <hpa@zytor.com>
Cc: linux-kernel@vger.kernel.org, xen-devel@lists.xensource.com,
	lenb@kernel.org, linux-acpi@vger.kernel.org, x86@kernel.org
Subject: Re: [PATCH 1/4] x86/wakeup/sleep: Check whether the TSS GDT descriptor is empty before using it.
Date: Thu, 17 Jan 2013 09:41:31 -0500	[thread overview]
Message-ID: <20130117144131.GB2552@phenom.dumpdata.com> (raw)
In-Reply-To: <507F473D.1060700@zytor.com>

On Wed, Oct 17, 2012 at 05:03:09PM -0700, H. Peter Anvin wrote:
> On 10/17/2012 06:49 AM, Konrad Rzeszutek Wilk wrote:
> >We check the TSS descriptor before we try to dereference it.
> >Also fix up the value to use the #defines.
> >
> >Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> >---
> >  arch/x86/power/cpu.c |    7 +++++--
> >  1 files changed, 5 insertions(+), 2 deletions(-)
> >
> >diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
> >index 218cdb1..c17370e 100644
> >--- a/arch/x86/power/cpu.c
> >+++ b/arch/x86/power/cpu.c
> >@@ -133,7 +133,9 @@ static void fix_processor_context(void)
> >  {
> >  	int cpu = smp_processor_id();
> >  	struct tss_struct *t = &per_cpu(init_tss, cpu);
> >-
> >+#ifdef CONFIG_X86_64
> >+	struct desc_struct *desc = get_cpu_gdt_table(cpu);
> >+#endif
> >  	set_tss_desc(cpu, t);	/*
> >  				 * This just modifies memory; should not be
> >  				 * necessary. But... This is necessary, because
> >@@ -142,7 +144,8 @@ static void fix_processor_context(void)
> >  				 */
> >
> >  #ifdef CONFIG_X86_64
> >-	get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
> >+	if (!desc_empty(&desc[GDT_ENTRY_TSS]))
> >+		desc[GDT_ENTRY_TSS].type = DESC_TSS;
> >
> >  	syscall_init();				/* This sets MSR_*STAR and related */
> >  #endif
> >
> 
> Why is this patch necessary?  Presumably there is something further
> down the line which depends on the TSS descriptor being empty, but
> if so, what?

Ah, so at least on Xen, that desc is marked as RO b/c it has been given
to the hypervisor. And the hypervisor adds its own entries. Lastly on
64-bit, the TSS for PV guests is not used - as the PV kernel and user-space
both run in the user-space ring. So there is nothing in that entry.

The issue I stumbled upon was just a page-fault b/c of trying to modify
a RO region. The other way of fixing this (without knowing that the
TSS entry is not set), was to use the functions/macros, as such:


        if (alternative_tss) {
                memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
                tss.type = DESC_TSS;
                write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
        } else {
                if (!desc_empty(&desc[GDT_ENTRY_TSS])) {
                        desc[GDT_ENTRY_TSS].type = DESC_TSS;
                }   
        }   

which works as well and does not throw the person from trying to figure
out why the TSS descriptor is empty (or not).

> 
> 	-hpa
> 
> -- 
> H. Peter Anvin, Intel Open Source Technology Center
> I work for Intel.  I don't speak on their behalf.

  parent reply	other threads:[~2013-01-17 14:41 UTC|newest]

Thread overview: 39+ 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 [this message]
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 ` [PATCH 3/4] xen/lowlevel: Implement pvop call for store_gdt (gidt) Konrad Rzeszutek Wilk
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 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=20130117144131.GB2552@phenom.dumpdata.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 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.