public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Re: [x86] do_arch_prctl - bug?
@ 2008-11-18 17:35 Eric Lacombe
  2008-11-18 23:44 ` Eric Lacombe
  0 siblings, 1 reply; 14+ messages in thread
From: Eric Lacombe @ 2008-11-18 17:35 UTC (permalink / raw)
  To: Arjan van de Ven; +Cc: Ingo Molnar, linux-kernel

Le mardi 18 novembre 2008 15:45:56, vous avez écrit :
> On Tue, 18 Nov 2008 15:33:32 +0100
>
> Eric Lacombe <goretux@gmail.com> wrote:
> > Hello,
> >
> > I would like to know why the ARCH_SET_GS action of sys_arch_prctl,
> > write the MSR MSR_KERNEL_GS_BASE and not the MSR MSR_GS_BASE when the
> > variable "doit" equals 1? Is that a bug?
>
> I don't think it is.
> The trick is that we use "swapgs" on entering/leaving the kernel, and
> that will "swap" gs with the MSR, so when we return to userspace, GS
> gets loaded from the MSR_KERNEL_GS_BASE ...

Yeah when we enter the kernel swapgs is used, so the MSR_GS_BASE is switched 
with the MSR_KERNEL_GS_BASE.

In fact, what I certainly misunderstand is why load_gs_index use swapgs 
inside.
>From that function, I trust that only when gs is loaded, its hidden part is 
loaded with the MSR_GS_BASE.

ENTRY(native_load_gs_index)
        CFI_STARTPROC
        pushf
        CFI_ADJUST_CFA_OFFSET 8
        DISABLE_INTERRUPTS(CLBR_ANY | ~(CLBR_RDI))
        SWAPGS
gs_change:     
        movl %edi,%gs   
2:      mfence          /* workaround */
        SWAPGS
        popf
        CFI_ADJUST_CFA_OFFSET -8
        ret
        CFI_ENDPROC
ENDPROC(native_load_gs_index)

Regards,

	Eric


^ permalink raw reply	[flat|nested] 14+ messages in thread
* Re: [x86] do_arch_prctl
@ 2008-12-07 23:02 Eric Lacombe
  2008-12-08 19:10 ` Jeremy Fitzhardinge
  0 siblings, 1 reply; 14+ messages in thread
From: Eric Lacombe @ 2008-12-07 23:02 UTC (permalink / raw)
  To: Jeremy Fitzhardinge; +Cc: Arjan van de Ven, Ingo Molnar, Alan Cox, linux-kernel

Hi,

I'm sorry to insist, but I really want to understand what occurs in this 
portion of kernel code. And that's why I resend my previous message with the 
hope that someone could enlighten my mind.

Thanks in advance,

	Eric

Le lundi 24 novembre 2008 19:22:18 Jeremy Fitzhardinge, vous avez écrit :
> 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.

The task_struct is also updated in sys_arch_prctl (ARCH_SET_FS and 
ARCH_SET_GS), so not just on a context switch.
How the task structure could be out of date wrt thread.gs and thread.fs?
What could be a typical scenario that could induced gs or fs to be modified and 
not thread.gs and thread.fs?

Why we have a difference between ARCH_GET_GS :

> 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                 }

and ARCH_GET_FS :

> 821                 else if (doit)
> 822                         rdmsrl(MSR_FS_BASE, base);

If I follow what you say, why can't we have the same optimization in 
ARCH_GET_FS?

thanks,

	Eric




^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2008-12-08 20:35 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox