From: Jeremy Fitzhardinge <jeremy@goop.org>
To: Eric Lacombe <goretux@gmail.com>
Cc: Arjan van de Ven <arjan@infradead.org>,
Ingo Molnar <mingo@elte.hu>, Alan Cox <alan@lxorguk.ukuu.org.uk>,
linux-kernel@vger.kernel.org
Subject: Re: [x86] do_arch_prctl
Date: Mon, 24 Nov 2008 10:22:18 -0800 [thread overview]
Message-ID: <492AF0DA.3060702@goop.org> (raw)
In-Reply-To: <200811241324.54606.goretux@gmail.com>
Eric Lacombe wrote:
> Hello,
>
> Does the "doit case" (line 822 in ARCH_GET_FS, function do_arch_prctl) exist
> for performance reasons? Else, why "task->thread.fs" (line 824) does not
> contain the fs base in the "doit case"?
>
"doit" gets set when you're operating on yourself. If you're operating
on another process, then you need to use their task structure values
rather than the current process's values. If you're doing it to
yourself, then the task structure may be out of date because its only
updated on a context switch.
> Can someone explain _precisely_ the lines 835 through 838 (ARCH_GET_GS)?
> (I thought that just the line 836 was sufficient, but I
> obviously miss the case where MSR_KERNEL_GS_BASE does not reflect the value
> requested)
>
gsindex and gs store the same information in two ways. gsindex is the
GDT selector number which contains the (32-bit) base address, and gs is
the raw 64-bit base address. If gsindex != 0 then it prevails,
otherwise gs contains the right value.
When you load %gs with a selector, the MSR is updated with the value
from the GDT. Rather than parsing the GDT entry manually to get the
encoded base address, the code in 836 fetches it out of the MSR. On the
other hand, if you're using a raw gs base (ie gsindex==0), then you can
simply read the base directly from the task structure. rdmsr would work
as well, but be less efficient.
J
> Thanks again for all your previous answers.
>
> Eric
>
> 828 case ARCH_GET_GS: {
> 829 unsigned long base;
> 830 unsigned gsindex;
> 831 if (task->thread.gsindex == GS_TLS_SEL)
> 832 base = read_32bit_tls(task, GS_TLS);
> 833 else if (doit) {
> 834 asm("movl %%gs,%0" : "=r" (gsindex));
> 835 if (gsindex)
> 836 rdmsrl(MSR_KERNEL_GS_BASE, base);
> 837 else
> 838 base = task->thread.gs;
> 839 }
> 840 else
> 841 base = task->thread.gs;
> 842 ret = put_user(base, (unsigned long __user *)addr);
> 843 break;
> 844 }
>
> ---
>
> 817 case ARCH_GET_FS: {
> 818 unsigned long base;
> 819 if (task->thread.fsindex == FS_TLS_SEL)
> 820 base = read_32bit_tls(task, FS_TLS);
> 821 else if (doit)
> 822 rdmsrl(MSR_FS_BASE, base);
> 823 else
> 824 base = task->thread.fs;
> 825 ret = put_user(base, (unsigned long __user *)addr);
> 826 break;
> 827 }
>
>
next prev parent reply other threads:[~2008-11-24 18:22 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-11-18 17:35 [x86] do_arch_prctl - bug? Eric Lacombe
2008-11-18 23:44 ` Eric Lacombe
2008-11-19 1:07 ` Jeremy Fitzhardinge
2008-11-19 9:23 ` Eric Lacombe
2008-11-19 21:06 ` Jeremy Fitzhardinge
2008-11-19 23:35 ` [x86] do_arch_prctl Eric Lacombe
2008-11-20 0:07 ` Jeremy Fitzhardinge
2008-11-20 0:22 ` Eric Lacombe
2008-11-24 12:24 ` Eric Lacombe
2008-11-24 18:22 ` Jeremy Fitzhardinge [this message]
2008-11-24 19:28 ` Eric Lacombe
-- strict thread matches above, loose matches on Subject: below --
2008-12-07 23:02 Eric Lacombe
2008-12-08 19:10 ` Jeremy Fitzhardinge
2008-12-08 20:35 ` Andi Kleen
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=492AF0DA.3060702@goop.org \
--to=jeremy@goop.org \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=arjan@infradead.org \
--cc=goretux@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
/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