All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86: kill handle_signal()->set_fs()
@ 2011-07-10 16:44 Oleg Nesterov
  2011-07-10 18:26 ` H. Peter Anvin
  2011-07-15  5:47 ` [tip:x86/signal] x86: Kill handle_signal()->set_fs() tip-bot for Oleg Nesterov
  0 siblings, 2 replies; 5+ messages in thread
From: Oleg Nesterov @ 2011-07-10 16:44 UTC (permalink / raw)
  To: Andrew Morton; +Cc: H. Peter Anvin, Ingo Molnar, linux-kernel

handle_signal()->set_fs() has a nice comment which explains what
set_fs() is, but it doesn't explain why it is needed and why it
depends on CONFIG_X86_64.

Afaics, the history of this confusion is:

	1. I guess today nobody can explain why it was needed
	   in arch/i386/kernel/signal.c, perhaps it was always
	   wrong. This predates 2.4.0 kernel.

	2. then it was copy-and-past'ed to the new x86_64 arch.

	3. then it was removed from i386 (but not from x86_64)
	   by b93b6ca3 "i386: remove unnecessary code".

	4. then it was reintroduced under CONFIG_X86_64 when x86
	   unified i386 and x86_64, because the patch above didn't
	   touch x86_64.

Remove it. ->addr_limit should be correct. Even if it was possible
that it is wrong, it is too late to fix it after setup_rt_frame().

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---

 arch/x86/kernel/signal.c |    9 ---------
 1 file changed, 9 deletions(-)

--- ptrace/arch/x86/kernel/signal.c~1_kill_set_fs	2011-05-22 16:27:28.000000000 +0200
+++ ptrace/arch/x86/kernel/signal.c	2011-07-10 18:06:30.000000000 +0200
@@ -717,15 +717,6 @@ handle_signal(unsigned long sig, siginfo
 	if (ret)
 		return ret;
 
-#ifdef CONFIG_X86_64
-	/*
-	 * This has nothing to do with segment registers,
-	 * despite the name.  This magic affects uaccess.h
-	 * macros' behavior.  Reset it to the normal setting.
-	 */
-	set_fs(USER_DS);
-#endif
-
 	/*
 	 * Clear the direction flag as per the ABI for function entry.
 	 */


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

* Re: [PATCH] x86: kill handle_signal()->set_fs()
  2011-07-10 16:44 [PATCH] x86: kill handle_signal()->set_fs() Oleg Nesterov
@ 2011-07-10 18:26 ` H. Peter Anvin
  2011-07-10 18:40   ` Oleg Nesterov
  2011-07-15  5:47 ` [tip:x86/signal] x86: Kill handle_signal()->set_fs() tip-bot for Oleg Nesterov
  1 sibling, 1 reply; 5+ messages in thread
From: H. Peter Anvin @ 2011-07-10 18:26 UTC (permalink / raw)
  To: Oleg Nesterov; +Cc: Andrew Morton, Ingo Molnar, linux-kernel

On 07/10/2011 09:44 AM, Oleg Nesterov wrote:
> handle_signal()->set_fs() has a nice comment which explains what
> set_fs() is, but it doesn't explain why it is needed and why it
> depends on CONFIG_X86_64.
> 
> Afaics, the history of this confusion is:
> 
> 	1. I guess today nobody can explain why it was needed
> 	   in arch/i386/kernel/signal.c, perhaps it was always
> 	   wrong. This predates 2.4.0 kernel.
> 
> 	2. then it was copy-and-past'ed to the new x86_64 arch.
> 
> 	3. then it was removed from i386 (but not from x86_64)
> 	   by b93b6ca3 "i386: remove unnecessary code".
> 
> 	4. then it was reintroduced under CONFIG_X86_64 when x86
> 	   unified i386 and x86_64, because the patch above didn't
> 	   touch x86_64.
> 
> Remove it. ->addr_limit should be correct. Even if it was possible
> that it is wrong, it is too late to fix it after setup_rt_frame().
> 

The main reason I could think of why this would be necessary is if we
take an event while we have fs == KERNEL_DS inside the kernel which is
then promoted to a signal.  Are you absolutely sure that can't happen?

In particular, there should be a setting upstream of this, as you're
correctly pointing out that it's too late.  If not, we might actually
have a problem.

	-hpa

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

* Re: [PATCH] x86: kill handle_signal()->set_fs()
  2011-07-10 18:26 ` H. Peter Anvin
@ 2011-07-10 18:40   ` Oleg Nesterov
  2011-07-14 19:02     ` Oleg Nesterov
  0 siblings, 1 reply; 5+ messages in thread
From: Oleg Nesterov @ 2011-07-10 18:40 UTC (permalink / raw)
  To: H. Peter Anvin; +Cc: Andrew Morton, Ingo Molnar, linux-kernel

On 07/10, H. Peter Anvin wrote:
>
> On 07/10/2011 09:44 AM, Oleg Nesterov wrote:
> > handle_signal()->set_fs() has a nice comment which explains what
> > set_fs() is, but it doesn't explain why it is needed and why it
> > depends on CONFIG_X86_64.
> >
> > Afaics, the history of this confusion is:
> >
> > 	1. I guess today nobody can explain why it was needed
> > 	   in arch/i386/kernel/signal.c, perhaps it was always
> > 	   wrong. This predates 2.4.0 kernel.
> >
> > 	2. then it was copy-and-past'ed to the new x86_64 arch.
> >
> > 	3. then it was removed from i386 (but not from x86_64)
> > 	   by b93b6ca3 "i386: remove unnecessary code".
> >
> > 	4. then it was reintroduced under CONFIG_X86_64 when x86
> > 	   unified i386 and x86_64, because the patch above didn't
> > 	   touch x86_64.
> >
> > Remove it. ->addr_limit should be correct. Even if it was possible
> > that it is wrong, it is too late to fix it after setup_rt_frame().
> >
>
> The main reason I could think of why this would be necessary is if we
> take an event while we have fs == KERNEL_DS inside the kernel

this is possible if we are the kernel thread, or set_fs(KERNEL_DS) was
called.

> which is
> then promoted to a signal.

How? We are going to return to the user-space. Obviously this is not
possible with the kernel thread. So I think this can only happen if
we already have a bug with unbalanced set_fs().

Are you absolutely sure that can't happen?

> In particular, there should be a setting upstream of this, as you're
> correctly pointing out that it's too late.  If not, we might actually
> have a problem.

Hmm... Now I recall, this was already discussed 5 years ago. Thanks to
google, see http://lkml.org/lkml/2007/7/17/321

In particular, Linus sayd:

	Heh. I think it's entirely historical.

	Please realize that the whole reason that function is called "set_fs()" is
	that it literally used to set the %fs segment register, not
	"->addr_limit".

	So I think the "set_fs(USER_DS)" is there _only_ to match the other

		regs->xds = __USER_DS;
		regs->xes = __USER_DS;
		regs->xss = __USER_DS;
		regs->xcs = __USER_CS;

	things, and never mattered. And now it matters even less, and has been
	copied to all other architectures where it is just totally insane.

Oleg.


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

* Re: [PATCH] x86: kill handle_signal()->set_fs()
  2011-07-10 18:40   ` Oleg Nesterov
@ 2011-07-14 19:02     ` Oleg Nesterov
  0 siblings, 0 replies; 5+ messages in thread
From: Oleg Nesterov @ 2011-07-14 19:02 UTC (permalink / raw)
  To: H. Peter Anvin; +Cc: Andrew Morton, Ingo Molnar, linux-kernel

So, Peter, do you agree we can remove this set_fs() ?

Of course, this doesn't matter from the perfomance pov.
But it is very confusing, especially with CONFIG_X86_64.


On 07/10, Oleg Nesterov wrote:
>
> On 07/10, H. Peter Anvin wrote:
> >
> > On 07/10/2011 09:44 AM, Oleg Nesterov wrote:
> > > handle_signal()->set_fs() has a nice comment which explains what
> > > set_fs() is, but it doesn't explain why it is needed and why it
> > > depends on CONFIG_X86_64.
> > >
> > > Afaics, the history of this confusion is:
> > >
> > > 	1. I guess today nobody can explain why it was needed
> > > 	   in arch/i386/kernel/signal.c, perhaps it was always
> > > 	   wrong. This predates 2.4.0 kernel.
> > >
> > > 	2. then it was copy-and-past'ed to the new x86_64 arch.
> > >
> > > 	3. then it was removed from i386 (but not from x86_64)
> > > 	   by b93b6ca3 "i386: remove unnecessary code".
> > >
> > > 	4. then it was reintroduced under CONFIG_X86_64 when x86
> > > 	   unified i386 and x86_64, because the patch above didn't
> > > 	   touch x86_64.
> > >
> > > Remove it. ->addr_limit should be correct. Even if it was possible
> > > that it is wrong, it is too late to fix it after setup_rt_frame().
> > >
> >
> > The main reason I could think of why this would be necessary is if we
> > take an event while we have fs == KERNEL_DS inside the kernel
>
> this is possible if we are the kernel thread, or set_fs(KERNEL_DS) was
> called.
>
> > which is
> > then promoted to a signal.
>
> How? We are going to return to the user-space. Obviously this is not
> possible with the kernel thread. So I think this can only happen if
> we already have a bug with unbalanced set_fs().
>
> Are you absolutely sure that can't happen?
>
> > In particular, there should be a setting upstream of this, as you're
> > correctly pointing out that it's too late.  If not, we might actually
> > have a problem.
>
> Hmm... Now I recall, this was already discussed 5 years ago. Thanks to
> google, see http://lkml.org/lkml/2007/7/17/321
>
> In particular, Linus sayd:
>
> 	Heh. I think it's entirely historical.
>
> 	Please realize that the whole reason that function is called "set_fs()" is
> 	that it literally used to set the %fs segment register, not
> 	"->addr_limit".
>
> 	So I think the "set_fs(USER_DS)" is there _only_ to match the other
>
> 		regs->xds = __USER_DS;
> 		regs->xes = __USER_DS;
> 		regs->xss = __USER_DS;
> 		regs->xcs = __USER_CS;
>
> 	things, and never mattered. And now it matters even less, and has been
> 	copied to all other architectures where it is just totally insane.
>
> Oleg.


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

* [tip:x86/signal] x86: Kill handle_signal()->set_fs()
  2011-07-10 16:44 [PATCH] x86: kill handle_signal()->set_fs() Oleg Nesterov
  2011-07-10 18:26 ` H. Peter Anvin
@ 2011-07-15  5:47 ` tip-bot for Oleg Nesterov
  1 sibling, 0 replies; 5+ messages in thread
From: tip-bot for Oleg Nesterov @ 2011-07-15  5:47 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: linux-kernel, hpa, mingo, oleg, tglx, hpa

Commit-ID:  73d382deccac186d103496bf10388bc2432a8384
Gitweb:     http://git.kernel.org/tip/73d382deccac186d103496bf10388bc2432a8384
Author:     Oleg Nesterov <oleg@redhat.com>
AuthorDate: Sun, 10 Jul 2011 18:44:24 +0200
Committer:  H. Peter Anvin <hpa@linux.intel.com>
CommitDate: Thu, 14 Jul 2011 21:46:20 -0700

x86: Kill handle_signal()->set_fs()

handle_signal()->set_fs() has a nice comment which explains what
set_fs() is, but it doesn't explain why it is needed and why it
depends on CONFIG_X86_64.

Afaics, the history of this confusion is:

	1. I guess today nobody can explain why it was needed
	   in arch/i386/kernel/signal.c, perhaps it was always
	   wrong. This predates 2.4.0 kernel.

	2. then it was copy-and-past'ed to the new x86_64 arch.

	3. then it was removed from i386 (but not from x86_64)
	   by b93b6ca3 "i386: remove unnecessary code".

	4. then it was reintroduced under CONFIG_X86_64 when x86
	   unified i386 and x86_64, because the patch above didn't
	   touch x86_64.

Remove it. ->addr_limit should be correct. Even if it was possible
that it is wrong, it is too late to fix it after setup_rt_frame().

Linus commented in:
http://lkml.kernel.org/r/alpine.LFD.0.999.0707170902570.19166@woody.linux-foundation.org

... about the equivalent bit from i386:

Heh. I think it's entirely historical.

Please realize that the whole reason that function is called "set_fs()" is 
that it literally used to set the %fs segment register, not 
"->addr_limit".

So I think the "set_fs(USER_DS)" is there _only_ to match the other

        regs->xds = __USER_DS;
        regs->xes = __USER_DS;
        regs->xss = __USER_DS;
        regs->xcs = __USER_CS;

things, and never mattered. And now it matters even less, and has been 
copied to all other architectures where it is just totally insane.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Link: http://lkml.kernel.org/r/20110710164424.GA20261@redhat.com
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
---
 arch/x86/kernel/signal.c |    9 ---------
 1 files changed, 0 insertions(+), 9 deletions(-)

diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
index 8c55f97..54ddaeb2 100644
--- a/arch/x86/kernel/signal.c
+++ b/arch/x86/kernel/signal.c
@@ -720,15 +720,6 @@ handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
 	if (ret)
 		return ret;
 
-#ifdef CONFIG_X86_64
-	/*
-	 * This has nothing to do with segment registers,
-	 * despite the name.  This magic affects uaccess.h
-	 * macros' behavior.  Reset it to the normal setting.
-	 */
-	set_fs(USER_DS);
-#endif
-
 	/*
 	 * Clear the direction flag as per the ABI for function entry.
 	 */

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

end of thread, other threads:[~2011-07-15  5:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-10 16:44 [PATCH] x86: kill handle_signal()->set_fs() Oleg Nesterov
2011-07-10 18:26 ` H. Peter Anvin
2011-07-10 18:40   ` Oleg Nesterov
2011-07-14 19:02     ` Oleg Nesterov
2011-07-15  5:47 ` [tip:x86/signal] x86: Kill handle_signal()->set_fs() tip-bot for Oleg Nesterov

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.