mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2 v2] minor cleanups to EFLAGS initialisation in ret_from_fork
@ 2011-08-10 16:29 Ian Campbell
  2011-08-10 16:29 ` [PATCH 1/2] x86: drop unnecessary kernel_eflags variable from 64 bit Ian Campbell
  2011-08-10 16:29 ` [PATCH 2/2] x86: make 32 bit ret_from_fork a little more similar to " Ian Campbell
  0 siblings, 2 replies; 4+ messages in thread
From: Ian Campbell @ 2011-08-10 16:29 UTC (permalink / raw)
  To: linux-kernel
  Cc: Peter Zijlstra, H. Peter Anvin, Pekka Enberg, Cyrill Gorcunov,
	Andi Kleen, Ingo Molnar, Brian Gerst, Frederic Weisbecker, x86,
	LinusTorvalds

The following series removes the use of a global kernel_eflags variable
from the x86_64 ret_from_fork path and (very slightly) merges the 32 and
64 bit version of that code path.

kernel_eflags could be made a __read_mostly but actually there is no
reason to prefer the value at cpu_init() time to a compile time constant
value for the initial eflags after a fork.

Test booted on 32 and 64 bit.

changes since v1:
      * rebased onto tip/master
      * make 32 bit look like 64 bit instead of vice versa since the
        behaviour of resetting eflags with interrupts disabled before
        calling schedule_tail seems more obviously safe than resetting
        eflags with interrupts enabled afterwards (although I think both
        are actually correct).
      * As a consequence of the above patch 3/3 (use symbolic names for
        bits in eflags) goes away since we only use the MBO bit 1 now,
        which doesn't have a name.


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

* [PATCH 1/2] x86: drop unnecessary kernel_eflags variable from 64 bit.
  2011-08-10 16:29 [PATCH 0/2 v2] minor cleanups to EFLAGS initialisation in ret_from_fork Ian Campbell
@ 2011-08-10 16:29 ` Ian Campbell
  2011-08-10 16:29 ` [PATCH 2/2] x86: make 32 bit ret_from_fork a little more similar to " Ian Campbell
  1 sibling, 0 replies; 4+ messages in thread
From: Ian Campbell @ 2011-08-10 16:29 UTC (permalink / raw)
  To: linux-kernel
  Cc: Cyrill Gorcunov, Peter Zijlstra, H. Peter Anvin, Pekka Enberg,
	Andi Kleen, Ingo Molnar, Brian Gerst, Frederic Weisbecker, x86,
	Linus Torvalds, Ian Campbell

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. This will be fixed in a subsequent patch.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Acked-by: Cyrill Gorcunov <gorcunov@gmail.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 insertions(+), 6 deletions(-)

diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
index 0d1171c..3065557 100644
--- a/arch/x86/include/asm/processor.h
+++ b/arch/x86/include/asm/processor.h
@@ -398,7 +398,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 aa003b1..1a11da2 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -1082,8 +1082,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.
@@ -1236,8 +1234,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 e13329d..b50d142 100644
--- a/arch/x86/kernel/entry_64.S
+++ b/arch/x86/kernel/entry_64.S
@@ -396,7 +396,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
-- 
1.7.2.5


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

* [PATCH 2/2] x86: make 32 bit ret_from_fork a little more similar to 64 bit
  2011-08-10 16:29 [PATCH 0/2 v2] minor cleanups to EFLAGS initialisation in ret_from_fork Ian Campbell
  2011-08-10 16:29 ` [PATCH 1/2] x86: drop unnecessary kernel_eflags variable from 64 bit Ian Campbell
@ 2011-08-10 16:29 ` Ian Campbell
  1 sibling, 0 replies; 4+ messages in thread
From: Ian Campbell @ 2011-08-10 16:29 UTC (permalink / raw)
  To: linux-kernel
  Cc: Cyrill Gorcunov, Peter Zijlstra, H. Peter Anvin, Pekka Enberg,
	Andi Kleen, Ingo Molnar, Brian Gerst, Frederic Weisbecker, x86,
	Linus Torvalds, Ian Campbell

The 64 bit version resets EFLAGS before calling schedule_tail() and
therefore leaves EFLAGS.IF clear. 32 bit resets EFLAGS after calling
schedule_tail() and therefore leaves EFLAGS.IF set.

Since the 64 bit version seems more obviously correct (although I think both
are actually right) make the 32 bit version look like that.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: Cyrill Gorcunov <gorcunov@gmail.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: x86@kernel.org
---
 arch/x86/kernel/entry_32.S |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
index 5c1a9197..c134617 100644
--- a/arch/x86/kernel/entry_32.S
+++ b/arch/x86/kernel/entry_32.S
@@ -299,12 +299,12 @@
 
 ENTRY(ret_from_fork)
 	CFI_STARTPROC
+	pushl_cfi $0x0002		# Reset kernel eflags
+	popfl_cfi
 	pushl_cfi %eax
 	call schedule_tail
 	GET_THREAD_INFO(%ebp)
 	popl_cfi %eax
-	pushl_cfi $0x0202		# Reset kernel eflags
-	popfl_cfi
 	jmp syscall_exit
 	CFI_ENDPROC
 END(ret_from_fork)
-- 
1.7.2.5


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

* [PATCH 2/2] x86: make 32 bit ret_from_fork a little more similar to 64 bit
  2011-08-31  9:22 [PATCH 0/2] minor cleanups to EFLAGS initialisation in ret_from_fork Ian Campbell
@ 2011-08-31  9:22 ` Ian Campbell
  0 siblings, 0 replies; 4+ messages in thread
From: Ian Campbell @ 2011-08-31  9:22 UTC (permalink / raw)
  To: linux-kernel
  Cc: Cyrill Gorcunov, H. Peter Anvin, Peter Zijlstra, Pekka Enberg,
	Andi Kleen, Ian Campbell, x86

The 64 bit version resets EFLAGS before calling schedule_tail() and
therefore leaves EFLAGS.IF clear. 32 bit resets EFLAGS after calling
schedule_tail() and therefore leaves EFLAGS.IF set.

Since the 64 bit version seems more obviously correct (although I think both
are actually right) make the 32 bit version look like that.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: Cyrill Gorcunov <gorcunov@gmail.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: x86@kernel.org
---
 arch/x86/kernel/entry_32.S |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
index f3f6f53..8b8794b 100644
--- a/arch/x86/kernel/entry_32.S
+++ b/arch/x86/kernel/entry_32.S
@@ -300,12 +300,12 @@
 
 ENTRY(ret_from_fork)
 	CFI_STARTPROC
+	pushl_cfi $0x0002		# Reset kernel eflags
+	popfl_cfi
 	pushl_cfi %eax
 	call schedule_tail
 	GET_THREAD_INFO(%ebp)
 	popl_cfi %eax
-	pushl_cfi $0x0202		# Reset kernel eflags
-	popfl_cfi
 	jmp syscall_exit
 	CFI_ENDPROC
 END(ret_from_fork)
-- 
1.7.2.5


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

end of thread, other threads:[~2011-08-31  9:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-10 16:29 [PATCH 0/2 v2] minor cleanups to EFLAGS initialisation in ret_from_fork Ian Campbell
2011-08-10 16:29 ` [PATCH 1/2] x86: drop unnecessary kernel_eflags variable from 64 bit Ian Campbell
2011-08-10 16:29 ` [PATCH 2/2] x86: make 32 bit ret_from_fork a little more similar to " Ian Campbell
2011-08-31  9:22 [PATCH 0/2] minor cleanups to EFLAGS initialisation in ret_from_fork Ian Campbell
2011-08-31  9:22 ` [PATCH 2/2] x86: make 32 bit ret_from_fork a little more similar to 64 bit Ian Campbell

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

all inboxes | Powered by JetHome®