From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752284AbbCYMWH (ORCPT ); Wed, 25 Mar 2015 08:22:07 -0400 Received: from mail-wi0-f178.google.com ([209.85.212.178]:37161 "EHLO mail-wi0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752021AbbCYMWB (ORCPT ); Wed, 25 Mar 2015 08:22:01 -0400 Date: Wed, 25 Mar 2015 13:21:56 +0100 From: Ingo Molnar To: Andy Lutomirski Cc: Andy Lutomirski , Takashi Iwai , Denys Vlasenko , Stefan Seyfried , X86 ML , Jiri Kosina , LKML , Tejun Heo Subject: Re: [PATCH] x86, entry: Check for syscall exit work with IRQs disabled Message-ID: <20150325122156.GA2748@gmail.com> References: <189320d42b4d671df78c10555976bb10af1ffc75.1427137498.git.luto@kernel.org> <20150324200810.GA3753@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Andy Lutomirski wrote: > On Tue, Mar 24, 2015 at 1:08 PM, Ingo Molnar wrote: > > > > * Andy Lutomirski wrote: > > > >> We currently have a race: if we're preempted during syscall exit, we > >> can fail to process syscall return work that is queued up while > >> we're preempted in ret_from_sys_call after checking ti.flags. > >> > >> Fix it by disabling interrupts before checking ti.flags. > >> > >> Fixes: 96b6352c1271 x86_64, entry: Remove the syscall exit audit and schedule optimizations > >> Reported-by: Stefan Seyfried > >> Reported-by: Takashi Iwai > >> Signed-off-by: Andy Lutomirski > >> --- > >> > >> Ingo, I don't understand the LOCKDEP_SYS_EXIT stuff. Can you take a quick > >> look to confirm that it's okay to call it more than once? > > > > So the essence is that it wants to print this warning if we are > > holding a lock after a syscall: > > > > printk("[ BUG: lock held when returning to user space! ]\n"); > > > > it manipulates no state and is not sensitive to whether it's called > > before or after return-work processing. > > > >> arch/x86/kernel/entry_64.S | 18 ++++++++++++++---- > >> 1 file changed, 14 insertions(+), 4 deletions(-) > >> > >> diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S > >> index 1d74d161687c..2babb393915e 100644 > >> --- a/arch/x86/kernel/entry_64.S > >> +++ b/arch/x86/kernel/entry_64.S > >> @@ -364,12 +364,21 @@ system_call_fastpath: > >> * Has incomplete stack frame and undefined top of stack. > >> */ > >> ret_from_sys_call: > >> - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET) > >> - jnz int_ret_from_sys_call_fixup /* Go the the slow path */ > >> - > >> LOCKDEP_SYS_EXIT > >> DISABLE_INTERRUPTS(CLBR_NONE) > >> TRACE_IRQS_OFF > >> + > >> + /* > >> + * We must check ti flags with interrupts (or at least preemption) > >> + * off because we must *never* return to userspace without > >> + * processing exit work that is enqueued if we're preempted here. > >> + * In particular, returning to userspace with any of the one-shot > >> + * flags (TIF_NOTIFY_RESUME, TIF_USER_RETURN_NOTIFY, etc) set is > >> + * very bad. > >> + */ > >> + testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET) > >> + jnz int_ret_from_sys_call_fixup /* Go the the slow path */ > > > > Should be safe to call it once again after user-work processing has > > been finished. > > > > I've picked up your fix for tip:x86/urgent. > > FWIW, the tentative merge here: > > https://git.kernel.org/cgit/linux/kernel/git/tip/tip.git/commit/?h=tmp.tmp&id=a77dd1607ad88a601259a74ba4d646fa68b7cd9a > > looks funny. Why aren't you jumping to int_ret_from_sys_call_irqs_off? Indeed - the orphaned label should have told me that. The mismerge is functionally harmless (causes extra overhead in the slowpath), that's why it passed testing. Does: 06ab9c1ba6a1 Merge branch 'x86/urgent' into x86/asm, to resolve conflict look better to you? Thanks, Ingo