minor cleanups to EFLAGS initialisation in ret_from_fork
v2 cover minor cleanups to EFLAGS initialisation in ret_from_fork
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.
PATCH v2 1/2 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. This will be fixed in a subsequent patch.
--- 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(-)
arch/x86/include/asm/processor.h +0 -1
@@ -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
arch/x86/kernel/cpu/common.c +0 -4
@@ -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 (); }
arch/x86/kernel/entry_64.S +1 -1
@@ -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
Signature · 1 line
1.7.2.5
PATCH v2 2/2 x86: make 32 bit ret_from_fork a little more similar to 64 bit
In reply to Ian CampbellThe 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.
--- arch/x86/kernel/entry_32.S | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/entry_32.S +2 -2
@@ -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)
Signature · 1 line
1.7.2.5