linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC] x86: drop unnecessary kernel_eflags variable from 64 bit
@ 2012-08-24 19:58 Cyrill Gorcunov
  2012-08-24 20:02 ` Cyrill Gorcunov
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Cyrill Gorcunov @ 2012-08-24 19:58 UTC (permalink / raw)
  To: X86-ML, LKML
  Cc: H. Peter Anvin, Ingo Molnar, Thomas Gleixner, Brian Gerst,
	Peter Zijlstra, Pekka Enberg, Andi Kleen

Hi guys,

I've been looking for some particular email in my mailbox when
found the patch below (it's dated as August 2011 ;) and think
it's still valid for kernel. Actually there were two patches,
and the second patch was unifying x86-32 with x86-64 but it
was doable as far as I remember.

Anyway, take a look. For debug purpose I've been runing the
kernel on a machine with 2 cpus and when cpus were starting
we're rewritting the kernel_eflags as many times as much cpus
we have. My debug code printed out

[root@neptune ~]# dmesg | grep "eflags"
[   18.459686] cpu_init: kernel_eflags: 46
[   18.782908] cpu_init: kernel_eflags: 46
[root@neptune ~]#

As you may see it has pf and zf flags set, which I suppose
do not mean much for code where we use this variable, ie in
ret_from_fork. The interrupts are off though as expected.

The patch below does substitude this variable with hard-coded
value in a manner of x86-32 code. The only concern I have
is that -- since this `kernel_eflags' was there, it must
be a reason why it was introduced in first place and I failed
to figure out why. Perhaps I need to digg though linux
early time when x86-64 support was introduced?

	Cyrill
---
From: Ian Campbell <ian.campbell@citrix.com>
Subject: [RFC] x86: drop unnecessary kernel_eflags variable from 64 bit

On 64 bit x86 we save the current eflags in cpu_init for use in ret_from_fork.
Strictly speaking reserved bits in EFLAGS should be read as written but in
practise it is unlikely that EFLAGS could ever be extended in this way and the
kernel alread clears any undefined flags early on.

The equivalent 32 bit code simply hard codes 0x0202 as the new EFLAGS.

This change makes 64 bit use the same mechanism to setup the initial EFLAGS on
fork. Note that 64 bit resets EFLAGS before calling schedule_tail() as opposed
to 32 bit which calls schedule_tail() first. Therefore the correct value for
EFLAGS has opposite IF bit.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
CC: "H. Peter Anvin" <hpa@zytor.com>
CC: Ingo Molnar <mingo@kernel.org>
CC: Thomas Gleixner <tglx@linutronix.de>
CC: Brian Gerst <brgerst@gmail.com>
CC: Peter Zijlstra <a.p.zijlstra@chello.nl>
CC: Pekka Enberg <penberg@kernel.org>
CC: Andi Kleen <ak@linux.intel.com>
CC: x86@kernel.org
---
 arch/x86/include/asm/processor.h |    1 -
 arch/x86/kernel/cpu/common.c     |    4 ----
 arch/x86/kernel/entry_64.S       |    2 +-
 3 files changed, 1 insertion(+), 6 deletions(-)

Index: linux-2.6.git/arch/x86/include/asm/processor.h
===================================================================
--- linux-2.6.git.orig/arch/x86/include/asm/processor.h
+++ linux-2.6.git/arch/x86/include/asm/processor.h
@@ -423,7 +423,6 @@ DECLARE_INIT_PER_CPU(irq_stack_union);
 
 DECLARE_PER_CPU(char *, irq_stack_ptr);
 DECLARE_PER_CPU(unsigned int, irq_count);
-extern unsigned long kernel_eflags;
 extern asmlinkage void ignore_sysret(void);
 #else	/* X86_64 */
 #ifdef CONFIG_CC_STACKPROTECTOR
Index: linux-2.6.git/arch/x86/kernel/cpu/common.c
===================================================================
--- linux-2.6.git.orig/arch/x86/kernel/cpu/common.c
+++ linux-2.6.git/arch/x86/kernel/cpu/common.c
@@ -1114,8 +1114,6 @@ void syscall_init(void)
 	       X86_EFLAGS_TF|X86_EFLAGS_DF|X86_EFLAGS_IF|X86_EFLAGS_IOPL);
 }
 
-unsigned long kernel_eflags;
-
 /*
  * Copies of the original ist values from the tss are only accessed during
  * debugging, no special alignment required.
@@ -1297,8 +1295,6 @@ void __cpuinit cpu_init(void)
 	fpu_init();
 	xsave_init();
 
-	raw_local_save_flags(kernel_eflags);
-
 	if (is_uv_system())
 		uv_cpu_init();
 }
Index: linux-2.6.git/arch/x86/kernel/entry_64.S
===================================================================
--- linux-2.6.git.orig/arch/x86/kernel/entry_64.S
+++ linux-2.6.git/arch/x86/kernel/entry_64.S
@@ -440,7 +440,7 @@ ENTRY(ret_from_fork)
 
 	LOCK ; btr $TIF_FORK,TI_flags(%r8)
 
-	pushq_cfi kernel_eflags(%rip)
+	pushq_cfi $0x0002
 	popfq_cfi				# reset kernel eflags
 
 	call schedule_tail			# rdi: 'prev' task parameter

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

* Re: [RFC] x86: drop unnecessary kernel_eflags variable from 64 bit
  2012-08-24 19:58 [RFC] x86: drop unnecessary kernel_eflags variable from 64 bit Cyrill Gorcunov
@ 2012-08-24 20:02 ` Cyrill Gorcunov
  2012-08-27 17:14 ` Andi Kleen
  2012-09-14  6:19 ` [tip:x86/asm] x86: Drop unnecessary kernel_eflags variable on 64-bit tip-bot for Ian Campbell
  2 siblings, 0 replies; 5+ messages in thread
From: Cyrill Gorcunov @ 2012-08-24 20:02 UTC (permalink / raw)
  To: X86-ML, LKML
  Cc: H. Peter Anvin, Ingo Molnar, Thomas Gleixner, Brian Gerst,
	Peter Zijlstra, Pekka Enberg, Andi Kleen, Ian Campbell

On Fri, Aug 24, 2012 at 11:58:47PM +0400, Cyrill Gorcunov wrote:
...
> 
> Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

Crap, forgot to CC Ian. Sorry.

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

* Re: [RFC] x86: drop unnecessary kernel_eflags variable from 64 bit
  2012-08-24 19:58 [RFC] x86: drop unnecessary kernel_eflags variable from 64 bit Cyrill Gorcunov
  2012-08-24 20:02 ` Cyrill Gorcunov
@ 2012-08-27 17:14 ` Andi Kleen
  2012-08-27 17:17   ` Cyrill Gorcunov
  2012-09-14  6:19 ` [tip:x86/asm] x86: Drop unnecessary kernel_eflags variable on 64-bit tip-bot for Ian Campbell
  2 siblings, 1 reply; 5+ messages in thread
From: Andi Kleen @ 2012-08-27 17:14 UTC (permalink / raw)
  To: Cyrill Gorcunov
  Cc: X86-ML, LKML, H. Peter Anvin, Ingo Molnar, Thomas Gleixner,
	Brian Gerst, Peter Zijlstra, Pekka Enberg

On Fri, Aug 24, 2012 at 11:58:47PM +0400, Cyrill Gorcunov wrote:
> Hi guys,
> 
> I've been looking for some particular email in my mailbox when
> found the patch below (it's dated as August 2011 ;) and think
> it's still valid for kernel. Actually there were two patches,
> and the second patch was unifying x86-32 with x86-64 but it
> was doable as far as I remember.

Patch is fine for me. I did the original code, but you're right
it's unlikely the EFLAGS will ever be extended.

Acked-by: Andi Kleen <ak@linux.intel.com>

-Andi

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

* Re: [RFC] x86: drop unnecessary kernel_eflags variable from 64 bit
  2012-08-27 17:14 ` Andi Kleen
@ 2012-08-27 17:17   ` Cyrill Gorcunov
  0 siblings, 0 replies; 5+ messages in thread
From: Cyrill Gorcunov @ 2012-08-27 17:17 UTC (permalink / raw)
  To: Andi Kleen
  Cc: X86-ML, LKML, H. Peter Anvin, Ingo Molnar, Thomas Gleixner,
	Brian Gerst, Peter Zijlstra, Pekka Enberg, Ian Campbell

On Mon, Aug 27, 2012 at 10:14:38AM -0700, Andi Kleen wrote:
> On Fri, Aug 24, 2012 at 11:58:47PM +0400, Cyrill Gorcunov wrote:
> > Hi guys,
> > 
> > I've been looking for some particular email in my mailbox when
> > found the patch below (it's dated as August 2011 ;) and think
> > it's still valid for kernel. Actually there were two patches,
> > and the second patch was unifying x86-32 with x86-64 but it
> > was doable as far as I remember.
> 
> Patch is fine for me. I did the original code, but you're right
> it's unlikely the EFLAGS will ever be extended.
> 
> Acked-by: Andi Kleen <ak@linux.intel.com>

Thanks for review, Andi!

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

* [tip:x86/asm] x86: Drop unnecessary kernel_eflags variable on 64-bit
  2012-08-24 19:58 [RFC] x86: drop unnecessary kernel_eflags variable from 64 bit Cyrill Gorcunov
  2012-08-24 20:02 ` Cyrill Gorcunov
  2012-08-27 17:14 ` Andi Kleen
@ 2012-09-14  6:19 ` tip-bot for Ian Campbell
  2 siblings, 0 replies; 5+ messages in thread
From: tip-bot for Ian Campbell @ 2012-09-14  6:19 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, gorcunov, a.p.zijlstra, brgerst,
	penberg, ian.campbell, ak, tglx

Commit-ID:  6eebdda35e6b18d0dddb2a44e34211bd94f0cad6
Gitweb:     http://git.kernel.org/tip/6eebdda35e6b18d0dddb2a44e34211bd94f0cad6
Author:     Ian Campbell <ian.campbell@citrix.com>
AuthorDate: Fri, 24 Aug 2012 23:58:47 +0400
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Thu, 13 Sep 2012 17:32:47 +0200

x86: Drop unnecessary kernel_eflags variable on 64-bit

On 64 bit x86 we save the current eflags in cpu_init for use in
ret_from_fork. Strictly speaking reserved bits in EFLAGS should
be read as written but in practise it is unlikely that EFLAGS
could ever be extended in this way and the kernel alread clears
any undefined flags early on.

The equivalent 32 bit code simply hard codes 0x0202 as the new
EFLAGS.

This change makes 64 bit use the same mechanism to setup the
initial EFLAGS on fork. Note that 64 bit resets EFLAGS before
calling schedule_tail() as opposed to 32 bit which calls
schedule_tail() first. Therefore the correct value for EFLAGS
has opposite IF bit.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Andi Kleen <ak@linux.intel.com>
Acked-by: "H. Peter Anvin" <hpa@zytor.com>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: Andi Kleen <ak@linux.intel.com>
Link: http://lkml.kernel.org/r/20120824195847.GA31628@moon
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/include/asm/processor.h |    1 -
 arch/x86/kernel/cpu/common.c     |    4 ----
 arch/x86/kernel/entry_64.S       |    2 +-
 3 files changed, 1 insertions(+), 6 deletions(-)

diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
index d048cad..9738b39 100644
--- a/arch/x86/include/asm/processor.h
+++ b/arch/x86/include/asm/processor.h
@@ -423,7 +423,6 @@ DECLARE_INIT_PER_CPU(irq_stack_union);
 
 DECLARE_PER_CPU(char *, irq_stack_ptr);
 DECLARE_PER_CPU(unsigned int, irq_count);
-extern unsigned long kernel_eflags;
 extern asmlinkage void ignore_sysret(void);
 #else	/* X86_64 */
 #ifdef CONFIG_CC_STACKPROTECTOR
diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index a5fbc3c..9961e2e 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -1116,8 +1116,6 @@ void syscall_init(void)
 	       X86_EFLAGS_TF|X86_EFLAGS_DF|X86_EFLAGS_IF|X86_EFLAGS_IOPL);
 }
 
-unsigned long kernel_eflags;
-
 /*
  * Copies of the original ist values from the tss are only accessed during
  * debugging, no special alignment required.
@@ -1299,8 +1297,6 @@ void __cpuinit cpu_init(void)
 	fpu_init();
 	xsave_init();
 
-	raw_local_save_flags(kernel_eflags);
-
 	if (is_uv_system())
 		uv_cpu_init();
 }
diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
index 69babd8..b1dac12 100644
--- a/arch/x86/kernel/entry_64.S
+++ b/arch/x86/kernel/entry_64.S
@@ -440,7 +440,7 @@ ENTRY(ret_from_fork)
 
 	LOCK ; btr $TIF_FORK,TI_flags(%r8)
 
-	pushq_cfi kernel_eflags(%rip)
+	pushq_cfi $0x0002
 	popfq_cfi				# reset kernel eflags
 
 	call schedule_tail			# rdi: 'prev' task parameter

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

end of thread, other threads:[~2012-09-14  6:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-24 19:58 [RFC] x86: drop unnecessary kernel_eflags variable from 64 bit Cyrill Gorcunov
2012-08-24 20:02 ` Cyrill Gorcunov
2012-08-27 17:14 ` Andi Kleen
2012-08-27 17:17   ` Cyrill Gorcunov
2012-09-14  6:19 ` [tip:x86/asm] x86: Drop unnecessary kernel_eflags variable on 64-bit tip-bot for Ian Campbell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).