public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Tejun Heo <tj@kernel.org>
To: Jeremy Fitzhardinge <jeremy@goop.org>
Cc: hpa@zytor.com, tglx@linutronix.de, mingo@elte.hu,
	linux-kernel@vger.kernel.org, x86@kernel.org,
	rusty@rustcorp.com.au, Jeremy Fitzhardinge <jeremy@xensource.com>
Subject: Re: [PATCH 10/11] x86: make lazy %gs optional on x86_32
Date: Tue, 10 Feb 2009 10:27:51 +0900	[thread overview]
Message-ID: <4990D817.7010906@kernel.org> (raw)
In-Reply-To: <49907203.4010009@goop.org>

Hello,

Jeremy Fitzhardinge wrote:
>> * Save and restore %gs along with other registers in entry_32.S unless
>>   LAZY_GS.  Note that this unfortunately adds "pushl $0" on SAVE_ALL
>>   even when LAZY_GS.  However, it adds no overhead to common exit path
>>   and simplifies entry path with error code.
>>   
> 
> I don't think it will make a measurable difference.  "subl $4, %esp"
> might be worth using too, or "lea -4(%esp), %esp" to avoid touching the
> flags.

You mean for PUSH_GS?  It's only used as a part of SAVE_ALL so I don't
think we need to worry about eflags.  The reason why I chose push $0
was because it was the shortest.

 push $0		: 6a 00
 sub $4, %esp		: 83 ec 04
 lea -4(%esp), %esp	: 8d 64 24 fc

>> +.macro POP_GS pop=0
>> +98:    popl %gs
>> +    CFI_ADJUST_CFA_OFFSET -4
>> +    /*CFI_RESTORE gs*/
>> +  .if \pop <> 0
>> +    add $\pop, %esp
>> +    CFI_ADJUST_CFA_OFFSET -\pop
>> +  .endif
>> +.endm
>> +.macro POP_GS_EX
>> +.pushsection .fixup, "ax"
>> +99:    movl $0, (%esp)
>> +    jmp 98b
>> +.section __ex_table, "a"
>> +    .align 4
>> +    .long 98b, 99b
>> +.popsection
>>   
> 
> Why not just fold the exception block into the POP_GS macro?  I don't
> think they need to be separated (ditto other exception handlers).

I originally did that but in ia32_sysenter_target(), it seems that the
exception stuff should be after CFI_ENDPROC, so I split them.  Don't
know much about debugging info so I tried to stick with what's already
there.  Is it okay to move exception block inside CFI_ENDPROC?

>> --- a/arch/x86/xen/enlighten.c
>> +++ b/arch/x86/xen/enlighten.c
>> @@ -323,13 +323,14 @@ static void load_TLS_descriptor(struct
>> thread_struct *t,
>>  static void xen_load_tls(struct thread_struct *t, unsigned int cpu)
>>  {
>>      /*
>> -     * XXX sleazy hack: If we're being called in a lazy-cpu zone,
>> -     * it means we're in a context switch, and %gs has just been
>> -     * saved.  This means we can zero it out to prevent faults on
>> -     * exit from the hypervisor if the next process has no %gs.
>> -     * Either way, it has been saved, and the new value will get
>> -     * loaded properly.  This will go away as soon as Xen has been
>> -     * modified to not save/restore %gs for normal hypercalls.
>> +     * XXX sleazy hack: If we're being called in a lazy-cpu zone
>> +     * and lazy gs handling is enabled, it means we're in a
>> +     * context switch, and %gs has just been saved.  This means we
>> +     * can zero it out to prevent faults on exit from the
>> +     * hypervisor if the next process has no %gs.  Either way, it
>> +     * has been saved, and the new value will get loaded properly.
>> +     * This will go away as soon as Xen has been modified to not
>> +     * save/restore %gs for normal hypercalls.
>>   
> 
> No, this change isn't quite right; the "and lazy gs handling is enabled"
> qualifier is wrong, because the condition the comment describes is
> independent of whether we're doing lazy gs handling.  This would be better:
> 
>    XXX sleazy hack: If we're being called in a lazy-cpu zone, it means
>    we're in a context switch, and %gs has definitely been saved (just
>    saved if we're doing lazy gs handling, and saved on entry if not).
>    This means we can zero it out to prevent faults on exit from the
>    hypervisor if the next process has no %gs. Either way, it has been
>    saved, and the new value will get loaded properly. This will go away
>    as soon as Xen has been modified to not save/restore %gs for normal
>    hypercalls.

Hmmm... I was (lazily) trying to add that %gs can only be cleared if
it's being managed lazily because otherwise it might be being used by
the kernel for other purposes.  :-)

Is my understanding correct?

Thanks.

-- 
tejun

  reply	other threads:[~2009-02-10  1:28 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-09 13:39 [PATCHSET x86/master] add stack protector support for x86_32 Tejun Heo
2009-02-09 13:39 ` [PATCH 01/11] x86: include correct %gs in a.out core dump Tejun Heo
2009-02-09 17:12   ` Jeremy Fitzhardinge
2009-02-09 13:39 ` [PATCH 02/11] x86: math_emu info cleanup Tejun Heo
2009-02-09 13:42   ` Ingo Molnar
2009-02-09 13:45     ` Ingo Molnar
2009-02-09 13:52       ` Tejun Heo
2009-02-09 13:39 ` [PATCH 03/11] x86: fix math_emu register frame access Tejun Heo
2009-02-09 17:13   ` Brian Gerst
2009-02-09 23:40     ` Ingo Molnar
2009-02-10  1:08     ` Tejun Heo
2009-02-09 13:39 ` [PATCH 04/11] elf: add ELF_CORE_COPY_KERNEL_REGS() Tejun Heo
2009-02-09 13:39 ` [PATCH 05/11] x86: stackprotector.h misc update Tejun Heo
2009-02-09 13:39 ` [PATCH 06/11] stackprotector: update make rules Tejun Heo
2009-02-09 13:39 ` [PATCH 07/11] x86: no stack protector for vdso Tejun Heo
2009-02-09 13:39 ` [PATCH 08/11] x86: use asm .macro instead of cpp #define in entry_32.S Tejun Heo
2009-02-09 18:34   ` Jeremy Fitzhardinge
2009-02-10  1:14     ` Tejun Heo
2009-02-10  1:18       ` Jeremy Fitzhardinge
2009-02-10 11:11         ` Ingo Molnar
2009-02-09 13:39 ` [PATCH 09/11] x86: add %gs accessors for x86_32 Tejun Heo
2009-02-09 13:39 ` [PATCH 10/11] x86: make lazy %gs optional on x86_32 Tejun Heo
2009-02-09 18:12   ` Jeremy Fitzhardinge
2009-02-10  1:27     ` Tejun Heo [this message]
2009-02-10  1:51       ` Jeremy Fitzhardinge
2009-02-09 13:39 ` [PATCH 11/11] x86: implement x86_32 stack protector Tejun Heo
2009-02-10 15:25   ` Brian Gerst
2009-02-10 15:39     ` Tejun Heo
2009-02-11  7:31       ` [PATCH x86#core/percpu] x86: fix x86_32 stack protector bugs Tejun Heo
2009-02-11 10:34         ` Ingo Molnar
2009-02-11 14:18           ` Tejun Heo
2009-02-09 13:55 ` [PATCHSET x86/master] add stack protector support for x86_32 Ingo Molnar
2009-02-09 14:06   ` Ingo Molnar
2009-02-09 20:30     ` Ingo Molnar
2009-02-10 13:56       ` Tejun Heo
2009-02-10 14:16         ` Ingo Molnar
2009-02-09 14:12   ` Ingo Molnar
2009-02-10 13:54     ` Tejun Heo
2009-02-10 14:16       ` Tejun Heo
2009-02-10 14:20         ` Ingo Molnar
2009-02-10 14:26           ` Tejun Heo
2009-02-11 10:57             ` Ingo Molnar
2009-02-11 11:18               ` [PATCH] stackprotector: fix multi-word cross-builds Ingo Molnar
2009-02-11 14:19                 ` Tejun Heo
2009-02-10 14:19       ` [PATCHSET x86/master] add stack protector support for x86_32 Ingo Molnar
2009-02-09 14:09 ` Brian Gerst
2009-02-09 14:15   ` Ingo Molnar
2009-02-10  1:36     ` Tejun Heo

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=4990D817.7010906@kernel.org \
    --to=tj@kernel.org \
    --cc=hpa@zytor.com \
    --cc=jeremy@goop.org \
    --cc=jeremy@xensource.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=rusty@rustcorp.com.au \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox