Re: [PATCH v4 22/29] x86/asm: Move 'status' from struct thread_info to struct thread_struct

2016-06-26 Thread Brian Gerst
ine in_ia32_syscall() (IS_ENABLED(CONFIG_IA32_EMULATION) && \ > + current->thread.status & TS_COMPAT) > #endif > - return false; > -} > > /* > * Force syscall return via IRET by making it look as if there was > diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c > index 2bd5c6ff7ee7..a91a6ead24a2 100644 > --- a/arch/x86/kernel/asm-offsets.c > +++ b/arch/x86/kernel/asm-offsets.c > @@ -30,7 +30,6 @@ > void common(void) { > BLANK(); > OFFSET(TI_flags, thread_info, flags); > - OFFSET(TI_status, thread_info, status); TI_status can be deleted. It's last users were removed in commit ee08c6bd. -- Brian Gerst

Re: [PATCH v4 25/29] um: Stop conflating task_struct::stack with thread_info

2016-06-26 Thread Brian Gerst
struct *child, long addr, long > data) > > static int get_fpregs(struct user_i387_struct __user *buf, struct > task_struct *child) > { > - int err, n, cpu = ((struct thread_info *) child->stack)->cpu; > + int err, n, cpu = task_thread_info(child)->cpu; Shouldn't this use task_cpu() like in patch 23? -- Brian Gerst

Re: [PATCH v4 11/16] x86/dumpstack: When OOPSing, rewind the stack before do_exit

2016-06-24 Thread Brian Gerst
>> sysret >> END(ignore_sysret) >> + >> +ENTRY(rewind_stack_do_exit) >> + /* Prevent any naive code from trying to unwind to our caller. */ >> + xorl%ebp, %ebp > > s/ebp/rbp/g/ ? No, this quirk of the x86-64 instruction set will zero-extend to 64-bits without needing a REX prefix. -- Brian Gerst

Re: [PATCH v3 00/13] Virtually mapped stacks with guard pages (x86, core)

2016-06-24 Thread Brian Gerst
t; Linus * A newly forked process directly context switches into this address. * * rdi: prev task we switched from + * rsi: task we're switching to */ ENTRY(ret_from_fork) -LOCK ; btr $TIF_FORK, TI_flags(%r8) + LOCK ; btr $TIF_FORK, TI_flags(%rsi)/* rsi: this newly forked task */ callschedule_tail/* rdi: 'prev' task parameter */ I think you forgot GET_THREAD_INFO() here. RSI is the task, not the thread_info. FYI, this goes away with my switch_to() rewrite, which removes TIF_FORK. -- Brian Gerst

Re: [PATCH v2 5/6] x86: Pass kernel thread parameters in fork_frame

2016-06-22 Thread Brian Gerst
On Mon, Jun 20, 2016 at 11:14 AM, Borislav Petkov wrote: > On Mon, Jun 20, 2016 at 11:01:02AM -0400, Brian Gerst wrote: >> The idea was to put the uncommon case (kernel thread) out of line for >> performance reasons. > > A comment saying so wouldn't hurt... This is a

Re: [PATCH v2 6/6] x86: Fix thread_saved_pc()

2016-06-21 Thread Brian Gerst
On Mon, Jun 20, 2016 at 12:01 PM, Josh Poimboeuf wrote: > On Sat, Jun 18, 2016 at 04:56:18PM -0400, Brian Gerst wrote: >> thread_saved_pc() was using a completely bogus method to get the return >> address. Since switch_to() was previously inlined, there was no sane way >>

Re: [PATCH v2 5/6] x86: Pass kernel thread parameters in fork_frame

2016-06-20 Thread Brian Gerst
On Mon, Jun 20, 2016 at 9:51 AM, Borislav Petkov wrote: > On Sat, Jun 18, 2016 at 04:56:17PM -0400, Brian Gerst wrote: >> Instead of setting up a fake pt_regs context, put the kernel thread >> function pointer and arg into the unused callee-restored registers >> of struct for

Re: [PATCH v2 0/6] x86: Rewrite switch_to()

2016-06-19 Thread Brian Gerst
On Sat, Jun 18, 2016 at 4:56 PM, Brian Gerst wrote: > This patch set simplifies the switch_to() code, by moving the stack switch > code out of line into an asm stub before calling __switch_to(). This ends > up being more readable, and using the C calling convention instead of > cl

Re: [PATCH v2 5/6] x86: Pass kernel thread parameters in fork_frame

2016-06-19 Thread Brian Gerst
On Sun, Jun 19, 2016 at 5:28 PM, Andy Lutomirski wrote: > On Sat, Jun 18, 2016 at 1:56 PM, Brian Gerst wrote: >> Instead of setting up a fake pt_regs context, put the kernel thread >> function pointer and arg into the unused callee-restored registers >> of struct fork_

[PATCH v2 1/6] x86-32, kgdb: Don't use thread.ip in sleeping_thread_to_gdb_regs()

2016-06-18 Thread Brian Gerst
Match 64-bit and set gdb_regs[GDB_PC] to zero. thread.ip is always the same point in the scheduler (except for newly forked processes), and will be removed in a future patch. Signed-off-by: Brian Gerst --- arch/x86/kernel/kgdb.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff

[PATCH v2 4/6] x86: Rewrite switch_to() code

2016-06-18 Thread Brian Gerst
for __schedule() by using the C calling convention instead of clobbering all registers. Signed-off-by: Brian Gerst --- arch/x86/entry/entry_32.S | 37 ++ arch/x86/entry/entry_64.S | 41 ++- arch/x86/include/asm/processor.h | 3 - arch/x86/include/asm

[PATCH v2 0/6] x86: Rewrite switch_to()

2016-06-18 Thread Brian Gerst
thread.sp Brian Gerst (6): x86-32, kgdb: Don't use thread.ip in sleeping_thread_to_gdb_regs() x86-64, kgdb: clear GDB_PS on 64-bit x86: Add struct inactive_task_frame x86: Rewrite switch_to() code x86: Pass kernel thread parameters in fork_frame x86

[PATCH v2 3/6] x86: Add struct inactive_task_frame

2016-06-18 Thread Brian Gerst
Add struct inactive_task_frame, which defines the layout of the stack for a sleeping process. For now, the only defined field is the BP register (frame pointer). Signed-off-by: Brian Gerst --- arch/x86/include/asm/stacktrace.h | 4 ++-- arch/x86/include/asm/switch_to.h | 5 + arch/x86

[PATCH v2 5/6] x86: Pass kernel thread parameters in fork_frame

2016-06-18 Thread Brian Gerst
Instead of setting up a fake pt_regs context, put the kernel thread function pointer and arg into the unused callee-restored registers of struct fork_frame. Signed-off-by: Brian Gerst --- arch/x86/entry/entry_32.S| 31 +++ arch/x86/entry/entry_64.S| 35

[PATCH v2 2/6] x86-64, kgdb: clear GDB_PS on 64-bit

2016-06-18 Thread Brian Gerst
switch_to() no longer saves EFLAGS, so it's bogus to look for it on the stack. Set it to zero like 32-bit. Signed-off-by: Brian Gerst --- arch/x86/kernel/kgdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c index fe

[PATCH v2 6/6] x86: Fix thread_saved_pc()

2016-06-18 Thread Brian Gerst
. Signed-off-by: Brian Gerst --- arch/x86/include/asm/processor.h | 10 ++ arch/x86/kernel/process.c| 10 ++ arch/x86/kernel/process_32.c | 8 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm

Re: [PATCH 3/4] x86: Rewrite switch_to() code

2016-06-15 Thread Brian Gerst
On Wed, Jun 15, 2016 at 4:03 AM, Ingo Molnar wrote: > > * Andy Lutomirski wrote: > >> On Sat, May 21, 2016 at 9:04 AM, Brian Gerst wrote: >> >> > Move the low-level context switch code to an out-of-line asm stub instead >> > of >> > using com

Re: [PATCH][RFC] x86, hotplug: Use zero page for monitor when resuming from hibernation

2016-06-06 Thread Brian Gerst
ver uses the zero page and access it. > > Writing to the zero page would be a major fail. I would think the safest thing to do during resume from hibernation is to use hlt instead of mwait, so there is no dependency on any memory address. It doesn't need the power management features of mwait either because the CPU will be reset soon after the restored kernel resumes. -- Brian Gerst

Re: [PATCH 0/7] x86: uaccess hardening, easy part

2016-05-24 Thread Brian Gerst
rspace accesses so that it only touches kernel memory, you can eliminate the set_fs() and the extra copy from the compat case. I had started work on this a while back but never finished it. I'll look at bringing it up to date. -- Brian Gerst

Re: [PATCH 4/4] x86: Pass kernel thread parameters in fork_frame

2016-05-23 Thread Brian Gerst
On Mon, May 23, 2016 at 11:36 AM, Andy Lutomirski wrote: > On Mon, May 23, 2016 at 8:23 AM, Josh Poimboeuf wrote: >> On Sat, May 21, 2016 at 12:04:51PM -0400, Brian Gerst wrote: >>> --- a/arch/x86/entry/entry_64.S >>> +++ b/arch/x86/entry/entry_64.S >>> @@ -4

Re: [PATCH 3/4] x86: Rewrite switch_to() code

2016-05-23 Thread Brian Gerst
; > >> > But overall I think this patch is a really nice cleanup, and other than >> > the above minor issue it should be fine with my reliable unwinder, since >> > rbp is still at the top of the stack. >> >> Is this a regression or is there some reason that it works right >> without the patch? > > Without the patch, it uses TIF_FORK to determine the stack is empty. Where is this code? I don't see it in the mainline kernel. -- Brian Gerst

Re: [PATCH 3/4] x86: Rewrite switch_to() code

2016-05-23 Thread Brian Gerst
ch is a really nice cleanup, and other than > the above minor issue it should be fine with my reliable unwinder, since > rbp is still at the top of the stack. Ok, how about if it pushed RBP first, then we teach get_wchan() to add the fixed offset from thread.sp to get bp? that way it don't have to push it twice. -- Brian Gerst

Re: [PATCH 3/4] x86: Rewrite switch_to() code

2016-05-22 Thread Brian Gerst
On Sun, May 22, 2016 at 1:59 PM, Andy Lutomirski wrote: > cc: Josh Poimboeuf: do you care about the exact stack layout of the > bottom of the stack of an inactive task? > > On May 21, 2016 9:05 AM, "Brian Gerst" wrote: >> >> Move the low-level context swit

Re: [PATCH 4/4] x86: Pass kernel thread parameters in fork_frame

2016-05-22 Thread Brian Gerst
On Sun, May 22, 2016 at 2:01 PM, Andy Lutomirski wrote: > On Sat, May 21, 2016 at 9:04 AM, Brian Gerst wrote: >> Instead of setting up a fake pt_regs context, put the kernel thread >> function pointer and arg into the unused callee-restored registers >> of struct fork_frame

Re: [PATCH 1/4] x86: Save return value from kernel_thread

2016-05-21 Thread Brian Gerst
On Sat, May 21, 2016 at 9:44 PM, Andy Lutomirski wrote: > On Sat, May 21, 2016 at 9:04 AM, Brian Gerst wrote: >> Kernel threads should always return zero on success after calling >> do_execve(). The >> two existing cases in the kernel (kernel_init() and >> cal

[PATCH 1/4] x86: Save return value from kernel_thread

2016-05-21 Thread Brian Gerst
save the full 64-bits. Signed-off-by: Brian Gerst --- arch/x86/entry/entry_32.S | 2 +- arch/x86/entry/entry_64.S | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/entry/entry_32.S b/arch/x86/entry/entry_32.S index 983e5d3..ee6fea0 100644 --- a/arch/x86/entry/entry_32

[PATCH 3/4] x86: Rewrite switch_to() code

2016-05-21 Thread Brian Gerst
for __schedule() by using the C calling convention instead of clobbering all registers. Signed-off-by: Brian Gerst --- arch/x86/entry/entry_32.S | 38 ++ arch/x86/entry/entry_64.S | 42 +++- arch/x86/include/asm/processor.h | 3 - arch/x86/include/asm

[PATCH 2/4] x86-32, kgdb: Don't use thread.ip in sleeping_thread_to_gdb_regs()

2016-05-21 Thread Brian Gerst
Match 64-bit and set gdb_regs[GDB_PC] to zero. thread.ip is always the same point in the scheduler (except for newly forked processes), and will be removed in a future patch. Signed-off-by: Brian Gerst --- arch/x86/kernel/kgdb.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff

[PATCH 0/4] x86: Rewrite switch_to()

2016-05-21 Thread Brian Gerst
This patch set simplifies the switch_to() code, by moving the stack switch code out of line into an asm stub before calling __switch_to(). This ends up being more readable, and using the C calling convention instead of clobbering all registers improves code generation. It also allows newly forked

[PATCH 4/4] x86: Pass kernel thread parameters in fork_frame

2016-05-21 Thread Brian Gerst
Instead of setting up a fake pt_regs context, put the kernel thread function pointer and arg into the unused callee-restored registers of struct fork_frame. Signed-off-by: Brian Gerst --- arch/x86/entry/entry_32.S| 28 +++- arch/x86/entry/entry_64.S| 30

Re: [PATCH -v2] x86/hweight: Get rid of the special calling convention

2016-05-11 Thread Brian Gerst
will keep those 5 bytes *and* get rid of the calling convention > without the growth. > > Or? I think he meant the out of line version would be asm, so you could control what registers were clobbered. -- Brian Gerst

[tip:x86/asm] x86/entry/32: Remove GET_THREAD_INFO() from entry code

2016-05-05 Thread tip-bot for Brian Gerst
Commit-ID: 1e17880371f85d3d866962e04ba3567c0654a125 Gitweb: http://git.kernel.org/tip/1e17880371f85d3d866962e04ba3567c0654a125 Author: Brian Gerst AuthorDate: Wed, 4 May 2016 22:44:37 -0400 Committer: Ingo Molnar CommitDate: Thu, 5 May 2016 08:37:30 +0200 x86/entry/32: Remove

[tip:x86/asm] x86/entry/32: Remove asmlinkage_protect()

2016-05-05 Thread tip-bot for Brian Gerst
Commit-ID: 0676b4e0a1940a6b7ae3156bd212ca9032a29c30 Gitweb: http://git.kernel.org/tip/0676b4e0a1940a6b7ae3156bd212ca9032a29c30 Author: Brian Gerst AuthorDate: Wed, 4 May 2016 22:44:38 -0400 Committer: Ingo Molnar CommitDate: Thu, 5 May 2016 08:37:31 +0200 x86/entry/32: Remove

[tip:x86/asm] x86/entry, sched/x86: Don't save/restore EFLAGS on task switch

2016-05-05 Thread tip-bot for Brian Gerst
Commit-ID: 092c74e420952c7cb68141731f2b562245b51eeb Gitweb: http://git.kernel.org/tip/092c74e420952c7cb68141731f2b562245b51eeb Author: Brian Gerst AuthorDate: Wed, 4 May 2016 22:44:36 -0400 Committer: Ingo Molnar CommitDate: Thu, 5 May 2016 08:37:30 +0200 x86/entry, sched/x86: Don&#

[PATCH 3/3] x86-32: Remove asmlinkage_protect

2016-05-04 Thread Brian Gerst
Now that syscalls are called from C code, which copies the args to new stack slots instead of overlaying pt_regs, asmlinkage_protect is no longer needed. Signed-off-by: Brian Gerst --- arch/x86/include/asm/linkage.h | 34 -- 1 file changed, 34 deletions(-) diff

[PATCH 1/3] x86: Don't save/restore EFLAGS on task switch

2016-05-04 Thread Brian Gerst
Now that NT is filtered by the SYSENTER entry code, it is safe to skip saving and restoring flags on task switch. Also remove a leftover reset of flags on 64-bit fork. Signed-off-by: Brian Gerst --- arch/x86/entry/entry_32.S| 4 arch/x86/entry/entry_64.S| 3 --- arch/x86

[PATCH 2/3] x86-32: Remove GET_THREAD_INFO from entry code

2016-05-04 Thread Brian Gerst
The entry code used to cache the thread_info pointer in the EBP register, but all the code that used it has been moved to C. Remove the unused code to get the pointer. Signed-off-by: Brian Gerst --- arch/x86/entry/entry_32.S | 3 --- 1 file changed, 3 deletions(-) diff --git a/arch/x86/entry

[PATCH 0/3] Misc x86 cleanups

2016-05-04 Thread Brian Gerst
Here are a few cleanups from the recent x86 entry code rewrite. [PATCH 1/3] x86: Don't save/restore EFLAGS on task switch [PATCH 2/3] x86-32: Remove GET_THREAD_INFO from entry code [PATCH 3/3] x86-32: Remove asmlinkage_protect arch/x86/entry/entry_32.S| 7 --- arch/x86/entry/entry_6

Re: [RFC PATCH] x86/hweight: Get rid of the special calling convention

2016-05-04 Thread Brian Gerst
m (ALTERNATIVE("call __sw_hweight32", POPCNT32, X86_FEATURE_POPCNT) > -: "="REG_OUT (res) > -: REG_IN (w)); > + if (likely(static_cpu_has(X86_FEATURE_POPCNT))) { > + asm volatile("popcnt %[w], %[res]" : [res] "=r" (res) : [w] > "r" (w)); Do all supported versions of the assembler know of the popcnt instruction? That's why is was open coded before. The problem is Intel and AMD are constantly adding new instructions and it's a long cycle for the user's assembler to get updated. -- Brian Gerst

Re: [PATCH RESEND] x86/asm/entry/32: simplify pushes of zeroed pt_regs->REGs

2016-05-03 Thread Brian Gerst
On Tue, May 3, 2016 at 1:55 PM, Andy Lutomirski wrote: > On Tue, May 3, 2016 at 10:45 AM, Brian Gerst wrote: >> On Mon, May 2, 2016 at 10:56 AM, Denys Vlasenko wrote: >>> Use of a temporary R8 register here seems to be unnecessary. >>> >>> "push %r8&qu

Re: [PATCH RESEND] x86/asm/entry/32: simplify pushes of zeroed pt_regs->REGs

2016-05-03 Thread Brian Gerst
/* pt_regs->r13 = 0 */ > + pushq $0 /* pt_regs->r14 = 0 */ > + pushq $0 /* pt_regs->r15 = 0 */ I think it actually should push r12-r15, since they are callee-saved and we don't explicitly zero them out on SYSRET like r8-r10. If it exited via IRET it would reload them as zero, so there is an inconsistency there. -- Brian Gerst

Re: [RFC PATCH v2 03/18] x86/asm/head: standardize the bottom of the stack for idle tasks

2016-04-29 Thread Brian Gerst
# fake return address to stop unwinder > + call1f # put return address on stack for unwinder > +1: xorq%rbp, %rbp # clear frame pointer > + movqinitial_code(%rip), %rax > pushq $__KERNEL_CS# set correct cs > pushq %rax# target address in negative space > lretq This chunk looks like it should be a separate patch. -- Brian Gerst

Re: [PATCH 1/6] x86/fpu/regset: Use boot_cpu_has()

2016-04-05 Thread Brian Gerst
as() for runtime checks, since it reduces down to a single jmp/nop instruction after alternatives run. Even if it's not a hot path, it saves a bit of runtime memory. boot_cpu_has() is fine for run-once init code. -- Brian Gerst

Re: [PATCH v4 4/4] Documentation: SROP Mitigation: Add documentation for SROP cookies

2016-03-29 Thread Brian Gerst
+ REG_EFL, > + REG_CSGSFS,/* Actually short cs, gs, fs, __pad0. */ > + REG_ERR, > + REG_TRAPNO, > + REG_OLDMASK, > + REG_CR2 > +}; > + > +void _exit_(void) > +{ > + exit(1); > +} > + > +void test(void) > +{ > + struct ucontext ctx = { 0 }; > + register unsigned long rsp asm("rsp"); > + register unsigned long rbp asm("rbp"); > + ctx.uc_mcontext.gregs[REG_RIP] = (unsigned long) _exit_ + 4; > + ctx.uc_mcontext.gregs[REG_RSP] = rsp; > + ctx.uc_mcontext.gregs[REG_RBP] = rbp; > + ctx.uc_mcontext.gregs[REG_CSGSFS] = 0x002b0033; > + rsp = (unsigned long) &ctx; > + asm("movq $0xf,%rax\n"); > + asm("syscall\n"); > +} > + > + > +int main(void) > +{ > + test(); > + return 0; > +} > -- > 1.9.1 > These test programs should go in tools/testing/selftests/x86. -- Brian Gerst

Re: [PATCH 2/9] x86: Add support for rd/wr fs/gs base

2016-03-22 Thread Brian Gerst
ode. fs/gs imply the %fs and %gs registers (the selector index), not the base. The rename should be: fs -> fsbase gs -> gsbase fsindex -> fs gsindex -> gs -- Brian Gerst

Re: [PATCH 4/9] x86: Enumerate kernel FSGS capability in AT_HWCAP2

2016-03-21 Thread Brian Gerst
or kernel is FSGSBASE capable. > > The application can then access it manually or using > the getauxval() function in newer glibc. How about adding a VDSO function instead? The VDSO can use alternatives, so it can use the new instructions if supported, or else use the old syscall. -- Brian Gerst

Re: [PATCH 4/9] x86: Enumerate kernel FSGS capability in AT_HWCAP2

2016-03-21 Thread Brian Gerst
On Mon, Mar 21, 2016 at 2:54 PM, Andi Kleen wrote: > On Mon, Mar 21, 2016 at 02:49:44PM -0400, Brian Gerst wrote: >> On Mon, Mar 21, 2016 at 12:16 PM, Andi Kleen wrote: >> > From: Andi Kleen >> > >> > The kernel needs to explicitely enable RD/WRFSBASE to hand

Re: [PATCH v2 07/10] x86/entry: Vastly simplify SYSENTER TF handling

2016-03-07 Thread Brian Gerst
On Mon, Mar 7, 2016 at 1:03 PM, Andy Lutomirski wrote: > On Mon, Mar 7, 2016 at 9:17 AM, Brian Gerst wrote: >> On Sun, Mar 6, 2016 at 12:52 AM, Andy Lutomirski wrote: >>> Due to a blatant design error, SYSENTER doesn't clear TF. As a result, >>> if a user do

Re: [PATCH v2 07/10] x86/entry: Vastly simplify SYSENTER TF handling

2016-03-07 Thread Brian Gerst
to singlestep all the way through the SYSENTER prologue. Unless there is an actual issue with TIF_SINGLESTEP, I don't think this patch is an improvement. -- Brian Gerst

Re: [PATCH v2 07/10] x86/entry: Vastly simplify SYSENTER TF handling

2016-03-06 Thread Brian Gerst
ed kernel on bare metal. This would work though: ALTERNATIVE "movl TSS_sysenter_sp0(%esp), %esp", "addl $5*4, %esp", X86_FEATURE_XENPV I haven't read the Xen hypervisor code, but what are those 5 words that were pushed on the stack by the hypervisor? It suspiciously is the size of an IRET frame. Considering that we don't use SYSEXIT on Xen anymore, can we just redirect SYSENTER to the INT80 handler? Perhaps even just disable SYSENTER support in the VDSO on Xen. I can't imagine SYSENTER is any faster than INT80 on Xen, because it has to trap to the hypervisor first. -- Brian Gerst

Re: [RFC PATCH] x86: Make sure verify_cpu has a good stack

2016-03-02 Thread Brian Gerst
%rsp It would be better to add the offset to the initializer for stack_start instead of adjusting it at runtime. That would require moving the existing load of stack_start from the common path to the secondary startup, which probably isn't a bad thing as it wouldn't depend on the trampoline stack anymore. -- Brian Gerst

Re: [PATCH 02/10] x86/entry/compat: In SYSENTER, sink AC clearing below the existing FLAGS test

2016-02-29 Thread Brian Gerst
set AC, so by adding it to the test for flags to clear we can avoid the CLAC or POPF in the common case that it is already clear. -- Brian Gerst

Re: [patch 01/20] idle: Move x86ism out of generic code

2016-02-27 Thread Brian Gerst
dy on the stack wont ever trigger). > -*/ > - boot_init_stack_canary(); > -#endif > arch_cpu_idle_prepare(); > cpu_idle_loop(); > } Does this actually work with stack protector enabled? boot_init_stack_canary() is inlined while arch_cpu_idle_prepare() is not. -- Brian Gerst

Re: [Xen-devel] [PATCH v3 0/2] Clear .bss for VP guests

2016-02-26 Thread Brian Gerst
th zero when the > program begins to run" which I read as it's up to runtime and not the loader > to do so. > > And since kernel does it explicitly on baremetal path I think it's a good > idea for PV to do the same. It does it on bare metal because bzImage is a raw binary image, not ELF. -- Brian Gerst

Re: [tip:x86/urgent] x86/entry/32: Add an ASM_CLAC to entry_SYSENTER_32

2016-02-25 Thread Brian Gerst
On Thu, Feb 25, 2016 at 2:39 PM, Andy Lutomirski wrote: > On Thu, Feb 25, 2016 at 11:31 AM, Brian Gerst wrote: >> On Thu, Feb 25, 2016 at 1:30 PM, Linus Torvalds >> wrote: >>> On Thu, Feb 25, 2016 at 10:20 AM, Andy Lutomirski >>> wrote: >>>> >&

Re: [tip:x86/urgent] x86/entry/32: Add an ASM_CLAC to entry_SYSENTER_32

2016-02-25 Thread Brian Gerst
y iret > restores iopl, if I recall correctly (but maybe I don't, and I'm too > lazy to take the 30 seconds to look it up). > > Linus According to the SDM, popf will change IOPL only at CPL0, which is why Xen (which runs at CPL1 on 32-bit) has a paravirt hook for it. -- Brian Gerst

Re: [PATCH v3 1/2] xen/x86: Zero out .bss for PV guests

2016-02-25 Thread Brian Gerst
+ > #ifdef CONFIG_X86_32 > mov %esi,xen_start_info > mov $init_thread_union+THREAD_SIZE,%esp Better, but can still be improved. Replace WSIZE_SHIFT with __ASM_SEL(2, 3), and use the macros for the registers (ie. __ASM_DI). -- Brian Gerst

Re: [tip:x86/urgent] x86/entry/32: Add an ASM_CLAC to entry_SYSENTER_32

2016-02-25 Thread Brian Gerst
On Thu, Feb 25, 2016 at 8:47 AM, Brian Gerst wrote: > On Thu, Feb 25, 2016 at 3:03 AM, Andy Lutomirski wrote: >> >> On Feb 24, 2016 10:01 PM, "H. Peter Anvin" wrote: >>> >>> On 02/24/16 21:53, tip-bot for Andy Lutomirski wrote: >>> &g

Re: [tip:x86/urgent] x86/entry/32: Add an ASM_CLAC to entry_SYSENTER_32

2016-02-25 Thread Brian Gerst
confused as > to the status on 32-bit. If we need to fix up NT, I think we can fold AC > into that. 32-bit still saves eflags in switch_to(), so NT can't leak to other tasks. But for consistency it should get the same treatment as 64-bit (clear NT in sysenter entry and drop saving eflags in switch_to). -- Brian Gerst

Re: [PATCH v2] xen/x86: Zero out .bss for PV guests

2016-02-24 Thread Brian Gerst
info > + mov $init_thread_union+THREAD_SIZE,REG(sp) > + > jmp xen_start_kernel > > __FINIT Use the macros in instead of defining your own. Also, xorl %eax,%eax is good for 64-bit too, since the upper bits are cleared. -- Brian Gerst

Re: [PATCH] x86/entry/32: Add an ASM_CLAC to entry_SYSENTER_32

2016-02-24 Thread Brian Gerst
orl $X86_EFLAGS_IF, (%esp) /* Fix IF */ > pushl $__USER_CS /* pt_regs->cs */ > pushl $0 /* pt_regs->ip = 0 (placeholder) */ > -- > 2.5.0 > It looks like entry_INT80_compat is also missing a CLAC. -- Brian Gerst

[tip:x86/asm] x86/alternatives: Discard dynamic check after init

2016-01-30 Thread tip-bot for Brian Gerst
Commit-ID: 2476f2fa20568bd5d9e09cd35bcd73e99a6f4cc6 Gitweb: http://git.kernel.org/tip/2476f2fa20568bd5d9e09cd35bcd73e99a6f4cc6 Author: Brian Gerst AuthorDate: Wed, 27 Jan 2016 09:45:25 +0100 Committer: Ingo Molnar CommitDate: Sat, 30 Jan 2016 11:22:22 +0100 x86/alternatives: Discard

Re: [tip:x86/asm] x86/syscalls: Remove __SYSCALL_COMMON and __SYSCALL_X32

2016-01-29 Thread Brian Gerst
fect other than >>determining which kernels actually support the syscall. Move >>the logic into syscalltbl.sh. >> >>Signed-off-by: Andy Lutomirski >>Cc: Andy Lutomirski >>Cc: Borislav Petkov >>Cc: Brian Gerst >>Cc: Denys Vlasenko >>Cc

Re: [PATCH 06/10] x86/cpufeature: Get rid of the non-asm goto variant

2016-01-26 Thread Brian Gerst
erwise! > */ > > -#if __GNUC__ >= 4 && defined(CONFIG_X86_FAST_FEATURE_TESTS) > +#if CC_HAVE_ASM_GOTO && defined(CONFIG_X86_FAST_FEATURE_TESTS) This should be: #if defined(CC_HAVE_ASM_GOTO) && ... -- Brian Gerst

Re: [RFC PATCH] x86/head_64.S: remove redundant check that kernel address is 2M aligned

2016-01-22 Thread Brian Gerst
directly jumped to startup_64. However, this check can be simplified to: testl $~PMD_PAGE_MASK, %ebp jnz bad_address -- Brian Gerst

Re: [RFC PATCH 0/5] x86/cpufeature: Cleanups and improvements

2016-01-21 Thread Brian Gerst
e direction this is going. > > Thanks! > > Borislav Petkov (4): > x86/cpufeature: Carve out X86_FEATURE_* > x86/cpufeature: Remove static_cpu_has() > x86/cpufeature: Get rid of the non-asm goto variant > x86/alternatives: Add an auxilary section > > Brian Gerst (

Re: [PATCH] kbuild: support make dir/file.i for *.S

2015-12-12 Thread Brian Gerst
o_S = $(CC) $(a_flags) -c -o $@ $< *.s (lower case) is the suffix used for preprocessed assembly files, and there is already a rule for that. *.i is for preprocessed C files. -- Brian Gerst -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the bod

Re: [PATCH] x86/entry/64: Remove duplicate syscall table for fast path

2015-12-09 Thread Brian Gerst
On Wed, Dec 9, 2015 at 6:50 PM, Andy Lutomirski wrote: > On Wed, Dec 9, 2015 at 1:15 PM, Andy Lutomirski wrote: >> On Wed, Dec 9, 2015 at 1:08 PM, Brian Gerst wrote: >>> Simplified version: >>> ENTRY(stub_ptregs_64) >>> cmpl $fast_path_return, (%rsp)

Re: [PATCH] x86/entry/64: Remove duplicate syscall table for fast path

2015-12-09 Thread Brian Gerst
On Wed, Dec 9, 2015 at 1:53 PM, Andy Lutomirski wrote: > On Wed, Dec 9, 2015 at 5:02 AM, Brian Gerst wrote: >> Instead of using a duplicate syscall table for the fast path, create stubs >> for >> the syscalls that need pt_regs that save the extra registers if a flag for &

[PATCH] x86/entry/64: Remove duplicate syscall table for fast path

2015-12-09 Thread Brian Gerst
Instead of using a duplicate syscall table for the fast path, create stubs for the syscalls that need pt_regs that save the extra registers if a flag for the slow path is not set. Signed-off-by: Brian Gerst To: Andy Lutomirski Cc: Andy Lutomirski Cc: the arch/x86 maintainers Cc: Linux Kernel

Re: [PATCH 07/12] x86/entry/64: Always run ptregs-using syscalls on the slow path

2015-12-09 Thread Brian Gerst
On Wed, Dec 9, 2015 at 1:21 AM, Andy Lutomirski wrote: > On Tue, Dec 8, 2015 at 9:45 PM, Andy Lutomirski wrote: >> On Tue, Dec 8, 2015 at 8:43 PM, Brian Gerst wrote: >>> On Mon, Dec 7, 2015 at 4:51 PM, Andy Lutomirski wrote: >>>> 64-bit syscalls currently have an

Re: [PATCH 07/12] x86/entry/64: Always run ptregs-using syscalls on the slow path

2015-12-08 Thread Brian Gerst
48 c7 43 50 00 00 00 00 48 c7 c2 60 b4 c5 81 48 89 de 4c [ 32.675469] RIP [] __audit_syscall_entry+0xcd/0xf0 [ 32.675471] RSP -- Brian Gerst -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More major

Re: [PATCH 07/12] x86/entry/64: Always run ptregs-using syscalls on the slow path

2015-12-08 Thread Brian Gerst
On Mon, Dec 7, 2015 at 8:12 PM, Andy Lutomirski wrote: > On Mon, Dec 7, 2015 at 4:54 PM, Brian Gerst wrote: >> On Mon, Dec 7, 2015 at 7:50 PM, Brian Gerst wrote: >>> On Mon, Dec 7, 2015 at 4:51 PM, Andy Lutomirski wrote: >>>> 64-bit syscalls currently have an

Re: [PATCH 07/12] x86/entry/64: Always run ptregs-using syscalls on the slow path

2015-12-07 Thread Brian Gerst
On Mon, Dec 7, 2015 at 7:50 PM, Brian Gerst wrote: > On Mon, Dec 7, 2015 at 4:51 PM, Andy Lutomirski wrote: >> 64-bit syscalls currently have an optimization in which they are >> called with partial pt_regs. A small handful require full pt_regs. >> >> In the 32-bit

Re: [PATCH 07/12] x86/entry/64: Always run ptregs-using syscalls on the slow path

2015-12-07 Thread Brian Gerst
hout the duplicate syscall table. ptregs_foo: leaq sys_foo(%rip), %rax jmp stub_ptregs_64 stub_ptregs_64: testl $TS_EXTRAREGS, ti_status> jnz 1f SAVE_EXTRA_REGS call *%rax RESTORE_EXTRA_REGS ret 1: call *%rax -- Brian Gerst -- To unsubscribe from this lis

Re: [PATCH 1/3] x86/xen: Avoid fast syscall path for Xen PV guests

2015-11-18 Thread Brian Gerst
.Lsyscasll_32_done", X86_FEATURE_XENPV > > Borislav, what do you think? > > Ditto for the others. Can you just add !xen_pv_domain() to the opportunistic SYSRET check instead? Bury the alternatives in that macro, ie. static_cpu_has(X86_FEATURE_XENPV). That would likely benefit other

Re: [RFC PATCH] x86/cpu: Fix MSR value truncation issue

2015-11-11 Thread Brian Gerst
; 31:0 - Mask: SYSCALL flag mask. Read-write. Reset: _h. This register > holds the EFLAGS > mask used by the SYSCALL instruction. 1=Clear the corresponding EFLAGS bit > when executing the > SYSCALL instruction. > > Intel has that too, except again, no SYSCALL in legacy mode on

Re: [PATCH v2 1/2] x86/entry/32: Fix entry_INT80_32 to expect interrupts to be on

2015-10-16 Thread Brian Gerst
On Fri, Oct 16, 2015 at 6:42 PM, Andy Lutomirski wrote: > When I rewrote entry_INT80_32, I thought that int80 was an interrupt > gate. It's a trap gate. *facepalm* > > Thanks to Brian Gerst for pointing out that it's better to change > the entry code than to change the

Re: [tip:x86/asm] x86/entry/32: Switch INT80 to the new C syscall path

2015-10-16 Thread Brian Gerst
On Fri, Oct 16, 2015 at 2:32 PM, Andy Lutomirski wrote: > On Fri, Oct 16, 2015 at 11:22 AM, Brian Gerst wrote: >> On Fri, Oct 16, 2015 at 1:34 PM, Borislav Petkov wrote: >>> On Fri, Oct 16, 2015 at 08:59:23AM -0700, Andy Lutomirski wrote: >>>> Wow I am incompetent.

Re: [tip:x86/asm] x86/entry/32: Switch INT80 to the new C syscall path

2015-10-16 Thread Brian Gerst
o the tracing should be fixed to expect interrupts on. do_int80_syscall_32() can be eliminated too. -- Brian Gerst -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/

Re: [PATCH v2 07/36] x86/entry/64/compat: After SYSENTER, move STI after the NT fixup

2015-10-12 Thread Brian Gerst
s way, we don't even have an unconditional RMW op. IF should normally be set in userspace, but since SYSENTER doesn't save the old flags and always clears IF when entering the kernel, the flags pushed on the stack will always have IF clear. -- Brian Gerst -- To unsubscribe from this list: send

Re: [tip:x86/asm] x86/vdso: Remove runtime 32-bit vDSO selection

2015-10-07 Thread Brian Gerst
t support SYSENTER and SYSCALL using > alternatives. This doesn't make sense to apply without the rest of the series. -- Brian Gerst -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info

Re: [PATCH v2 05/36] x86/entry/64/compat: Fix SYSENTER's NT flag before user memory access

2015-10-07 Thread Brian Gerst
sysenter_fix_flags >> sysenter_flags_fixed: > > Btw, do I see it correctly that we can save us this jumping to > sysenter_fix_flags and back to sysenter_flags_fixed? Label is jumped to > only once and the couple of insns there can be behind a JZ... This is an optimizat

Re: [PATCH] x86: uapi: Fix __BITS_PER_LONG for x32

2015-10-01 Thread Brian Gerst
R_LONG 64 > > Can we write this as: > > #ifdef __ILP64__ Do all versions of gcc/clang define that, even if x32 isn't supported? -- Brian Gerst -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/

Re: [RFC 24/30] x86/entry/32: Switch INT80 to the new C syscall path

2015-09-03 Thread Brian Gerst
nter_after_call > -- > 2.4.3 > While bisecting a boot failure on the 32-bit native kernel I came across this build error: arch/x86/built-in.o: In function `syscall_trace_entry': /home/bgerst/kernel/linux/arch/x86/entry/entry_32.S:468: undefined reference to `syscall_call' /home/b

Re: [RFC 00/30] x86: Rewrite all syscall entries except native 64-bit

2015-09-02 Thread Brian Gerst
scalls. > > If we want some of the 25 cycles back, we could consider open-coding > a new C fast path. Is the 25 cycles for the compat or native case? I'd expect the native case to be hit harder because of register pressure. -- Brian Gerst -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/

Re: RFC: adding Linux vsyscall-disable and similar backwards-incompatibility flags to ELF headers?

2015-09-02 Thread Brian Gerst
On Tue, Sep 1, 2015 at 10:21 PM, Andy Lutomirski wrote: > On Sep 1, 2015 6:53 PM, "Brian Gerst" wrote: >> >> On Tue, Sep 1, 2015 at 8:51 PM, Andy Lutomirski wrote: >> > Hi all- >> > >> > Linux has a handful of weird features that are only supp

Re: RFC: adding Linux vsyscall-disable and similar backwards-incompatibility flags to ELF headers?

2015-09-01 Thread Brian Gerst
ain features. > > Ideas? We could add a new phdr for this, but then we'd need to play > linker script games, and I'm not sure that could be done in a clean, > extensible way. The vsyscall page is mapped in the fixmap region, which is shared between all processes. You can

Re: Why is irq_stack_union a union?

2015-08-31 Thread Brian Gerst
On Mon, Aug 31, 2015 at 6:01 PM, Andy Lutomirski wrote: > On Mon, Aug 31, 2015 at 2:47 PM, Brian Gerst wrote: >> On Mon, Aug 31, 2015 at 5:00 PM, Andy Lutomirski wrote: >>> Why not just a struct? Also, why is this all tangled up in gsbase >>> initialization? >&

Re: Why is irq_stack_union a union?

2015-08-31 Thread Brian Gerst
nt, we have to make sure that the canary is placed at the start of the percpu section. Overlaying it onto the bottom of the IRQ stack and was the most convenient way to do it, with a side benefit that overflowing the stack will trip the canary. -- Brian Gerst -- To unsubscribe from this list: se

Re: [PATCH 0/7] x86 vdso32 cleanups

2015-08-30 Thread Brian Gerst
On Sat, Aug 29, 2015 at 12:10 PM, Andy Lutomirski wrote: > On Sat, Aug 29, 2015 at 8:20 AM, Brian Gerst wrote: >> This patch set contains several cleanups to the 32-bit VDSO. The >> main change is to only build one VDSO image, and select the syscall >> entry point at runtim

[PATCH 1/7] x86/vdso32: Separate sigreturn code

2015-08-29 Thread Brian Gerst
Compile a separate sigreturn.o instead of including it in the three syscall entry stub files. Use alternatives to patch in a syscall instruction when supported. Signed-off-by: Brian Gerst --- arch/x86/entry/vdso/Makefile | 3 ++- arch/x86/entry/vdso/vdso32/int80.S | 5 + arch

[PATCH 6/7] x86/vdso32/xen: Move VDSO_NOTE_NONEGSEG_BIT define

2015-08-29 Thread Brian Gerst
Xen had its own vdso.h just to define VDSO_NOTE_NONEGSEG_BIT. Move it to the main vdso.h. Signed-off-by: Brian Gerst --- arch/x86/entry/vdso/vdso-note.S | 4 +--- arch/x86/include/asm/vdso.h | 9 + arch/x86/xen/setup.c| 1 - arch/x86/xen/vdso.h | 4 4

[PATCH 4/7] x86/vdso32: Build single vdso32 image

2015-08-29 Thread Brian Gerst
of selecting the image, selects the entry point that is placed in the AT_SYSINFO vector and the ELF entry point. Signed-off-by: Brian Gerst --- arch/x86/entry/vdso/.gitignore| 3 --- arch/x86/entry/vdso/Makefile | 44 --- arch/x86/entry/vdso

[PATCH 5/7] x86/vdso: Merge 32-bit and 64-bit source files

2015-08-29 Thread Brian Gerst
Merge the 32-bit versions of vclock_gettime and note.S into the 64-bit code. Add some make rules to handle the combined code. Signed-off-by: Brian Gerst --- arch/x86/entry/vdso/Makefile| 10 ++- arch/x86/entry/vdso/vclock_gettime.c| 31 arch/x86

[PATCH 3/7] x86/vdso32: Remove unused vdso-fakesections.c

2015-08-29 Thread Brian Gerst
Signed-off-by: Brian Gerst --- arch/x86/entry/vdso/vdso32/vdso-fakesections.c | 1 - 1 file changed, 1 deletion(-) delete mode 100644 arch/x86/entry/vdso/vdso32/vdso-fakesections.c diff --git a/arch/x86/entry/vdso/vdso32/vdso-fakesections.c b/arch/x86/entry/vdso/vdso32/vdso-fakesections.c

[PATCH 7/7] x86/vdso32: Remove vdso32 subdirectory

2015-08-29 Thread Brian Gerst
Since the vdso32 subdirectory doesn't have a proper Makefile, it is more difficult to work with. Move the remaining files up one level. Signed-off-by: Brian Gerst --- arch/x86/entry/vdso/.gitignore | 1 + arch/x86/entry/vdso/Makefile| 14 ++- arch/x86/entry/vdso/in

[PATCH 2/7] x86/vdso32: Remove VDSO32_vsyscall_eh_frame_size

2015-08-29 Thread Brian Gerst
This symbol and the padding are unnecessary since we no longer rely on the symbols being exactly the same in each variant of the vdso32. Signed-off-by: Brian Gerst --- arch/x86/entry/vdso/vdso32/int80.S| 8 arch/x86/entry/vdso/vdso32/syscall.S | 8 arch/x86/entry/vdso

[PATCH 0/7] x86 vdso32 cleanups

2015-08-29 Thread Brian Gerst
This patch set contains several cleanups to the 32-bit VDSO. The main change is to only build one VDSO image, and select the syscall entry point at runtime. arch/x86/entry/vdso/.gitignore | 4 +--- arch/x86/entry/vdso/Makefile | 53 ++--

Re: Proposal for finishing the 64-bit x86 syscall cleanup

2015-08-26 Thread Brian Gerst
On Wed, Aug 26, 2015 at 1:10 PM, Andy Lutomirski wrote: > On Tue, Aug 25, 2015 at 10:20 PM, Brian Gerst wrote: >>>>> Thing 2: vdso compilation with binutils that doesn't support .cfi >>>>> directives >>>>> >>>>> Userspace deb

<    1   2   3   4   5   6   7   >