Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1914039imm; Tue, 22 May 2018 11:21:33 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrVHjMhY24WATAQGelVPp34NWGSBpcmOl7kGS9HLy/q+/OxiJ9wqefEAdxG3ZQ7Pdj6sjsj X-Received: by 2002:a63:744a:: with SMTP id e10-v6mr20043690pgn.275.1527013293242; Tue, 22 May 2018 11:21:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527013293; cv=none; d=google.com; s=arc-20160816; b=t/NDIv5BiUIsz8bMLPmPR5ynira58xrsyCK6CBNmjrUXoB2ppulEk/uI4fLUMK2TAJ OsbEPlEZqTP8uAEIh10/PEIHnplbstJhLITW1ADtyGxloIv8tyHDCDq6CgZEwTqrDNv8 5Uj3kVR1HpV/TyXZsbkfxcgCg0lw6QQLGFjZaJJvEQmeb00FEGSZl3kOn29hjxqCp3sv 32eJHwlBRN6VN2co2v9yjg5pCnt4Xp8U9SPgLqa9aBptRem5jIez7Q04yUE6InSpmYKo Jk180oBPZfzhWftMIV3TxQUhIWz+KMKPvXuiwlmUkqrBlLO+qwB0FpGgb64KRBvgX8tH DI7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:thread-index:thread-topic :content-transfer-encoding:mime-version:subject:references :in-reply-to:message-id:cc:to:from:date:dkim-signature:dkim-filter :arc-authentication-results; bh=jSp7z7HJH/s14ffCzLLOJFbmfBBiGeuKphVPnKe35cE=; b=k46gorRKAavoemMh1IyPLHxRsJAl3n7Wuf6XCFODc6esjtYrVy+SvW0D62YTR0cng+ +xEx8tXNwfkNJW6QAVfoE+e8Baft7j8Eaev0otIxmdaTb/2wJVpJ4cIa8txSihbA+6yL omcy1BuR2qg+w+zDB+ob8+FASZSg9NBO4qEiCKfFY5RocN5pkHQuVOW2oiYYRzjVBklB Hlophk1wdCITKX6IVc6sjXMGxYlyqEQB3zAIccLgxKKOK+EeN+rPKJ8vx2luwbYiUSX6 261Mxu8MJ2/dy0q/bHjKYKFde7LEYKzrhQuvwrisQaNSKA7q2uWXnhpv3KRPmotk5nHz Lp9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=default header.b=DWlUZpN+; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c21-v6si16947427plo.51.2018.05.22.11.21.18; Tue, 22 May 2018 11:21:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@efficios.com header.s=default header.b=DWlUZpN+; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751470AbeEVSTg (ORCPT + 99 others); Tue, 22 May 2018 14:19:36 -0400 Received: from mail.efficios.com ([167.114.142.138]:38086 "EHLO mail.efficios.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751319AbeEVSTf (ORCPT ); Tue, 22 May 2018 14:19:35 -0400 Received: from localhost (ip6-localhost [IPv6:::1]) by mail.efficios.com (Postfix) with ESMTP id 1ABD51B076A; Tue, 22 May 2018 14:19:34 -0400 (EDT) Received: from mail.efficios.com ([IPv6:::1]) by localhost (mail02.efficios.com [IPv6:::1]) (amavisd-new, port 10032) with ESMTP id YtvH4XmRjhUA; Tue, 22 May 2018 14:19:33 -0400 (EDT) Received: from localhost (ip6-localhost [IPv6:::1]) by mail.efficios.com (Postfix) with ESMTP id 54D6D1B0766; Tue, 22 May 2018 14:19:33 -0400 (EDT) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com 54D6D1B0766 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=default; t=1527013173; bh=jSp7z7HJH/s14ffCzLLOJFbmfBBiGeuKphVPnKe35cE=; h=Date:From:To:Message-ID:MIME-Version; b=DWlUZpN+nEkQSSc1js/4VUIm8/k80mjt8V/W5uVkXiE4kgXTdEqNXXZ0n2oY4njCS ObTzPW/wy+B2HccCS9ZODsHfn+juLbDrRam6V39EExkldwRU68k9y8GmD4w+FVIJs3 KQfgobmxIFA4i7zI+kHxu+RU1ttFsVjeAX1MDjDYljF6xdc6pIVWAq2o/nvbACylDo OgHXPtFwSQvQhP3XyYFaDUeRbGCW1rW1BXwE4uVQaYQny/DKk6JICsoC/kfqgrOIiA Z1DejvioIj2+447Cffdqder3cFIRnr2nPrR40GtqvZvdUUugvD9uJ6lxp3B2Rgctu1 CTlcjVNvoujFw== X-Virus-Scanned: amavisd-new at efficios.com Received: from mail.efficios.com ([IPv6:::1]) by localhost (mail02.efficios.com [IPv6:::1]) (amavisd-new, port 10026) with ESMTP id SvlYo4W2OYZK; Tue, 22 May 2018 14:19:33 -0400 (EDT) Received: from mail02.efficios.com (mail02.efficios.com [167.114.142.138]) by mail.efficios.com (Postfix) with ESMTP id 38C1C1B075D; Tue, 22 May 2018 14:19:33 -0400 (EDT) Date: Tue, 22 May 2018 14:19:33 -0400 (EDT) From: Mathieu Desnoyers To: Will Deacon , Russell King Cc: Peter Zijlstra , "Paul E. McKenney" , Boqun Feng , Andy Lutomirski , Dave Watson , linux-kernel , linux-api , Paul Turner , Andrew Morton , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , Andrew Hunter , Andi Kleen , Chris Lameter , Ben Maurer , rostedt , Josh Triplett , Linus Torvalds , Catalin Marinas , Michael Kerrisk , Joel Fernandes Message-ID: <1564615700.2786.1527013173112.JavaMail.zimbra@efficios.com> In-Reply-To: <2135166002.2147.1526571001678.JavaMail.zimbra@efficios.com> References: <20180430224433.17407-1-mathieu.desnoyers@efficios.com> <20180430224433.17407-4-mathieu.desnoyers@efficios.com> <20180516161809.GH12198@hirez.programming.kicks-ass.net> <670368504.1912.1526501593893.JavaMail.zimbra@efficios.com> <20180517133230.GA2688@arm.com> <2135166002.2147.1526571001678.JavaMail.zimbra@efficios.com> Subject: Re: [PATCH 03/14] arm: Add restartable sequences support MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [167.114.142.138] X-Mailer: Zimbra 8.8.8_GA_2026 (ZimbraWebClient - FF52 (Linux)/8.8.8_GA_2031) Thread-Topic: Add restartable sequences support Thread-Index: hkDF4Yy2rYjeT3UBbYbe4+QoPict4o8/7+pV Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ----- On May 17, 2018, at 11:30 AM, Mathieu Desnoyers mathieu.desnoyers@efficios.com wrote: [...] > > Or as proposed by Boqun, we can simply call rseq_syscall in a CONFIG_DEBUG_RSEQ > ifdef. Given that this is a debug option, is it worth it to add the > current->rseq > test for NULL in assembly before the call, or do we want to favor simplicity ? > Based on advice from Will Deacon, I alternatively tried to add a new TIF_RSEQ thread flags, but unfortunately bits 1 through 8 are already used, and this is all that fits in an immediate operand on arm32 for the fast-path thread flag syscall work mask check in assembly. So considering that this is a kernel debug option, I took the approach of adding a call at the very beginning of return from syscall fast and slow paths, which is only compiled in if CONFIG_DEBUG_RSEQ=y. Does the following approach make sense ? arm: Add syscall detection for restartable sequences Syscalls are not allowed inside restartable sequences, so add a call to rseq_syscall() at the very beginning of system call exiting path for CONFIG_DEBUG_RSEQ=y kernel. This could help us to detect whether there is a syscall issued inside restartable sequences. Signed-off-by: Mathieu Desnoyers --- diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S index 3c4f887..b427ef8 100644 --- a/arch/arm/kernel/entry-common.S +++ b/arch/arm/kernel/entry-common.S @@ -39,12 +39,13 @@ saved_pc .req lr .section .entry.text,"ax",%progbits .align 5 -#if !(IS_ENABLED(CONFIG_TRACE_IRQFLAGS) || IS_ENABLED(CONFIG_CONTEXT_TRACKING)) +#if !(IS_ENABLED(CONFIG_TRACE_IRQFLAGS) || IS_ENABLED(CONFIG_CONTEXT_TRACKING) || \ + IS_ENABLED(CONFIG_DEBUG_RSEQ)) /* * This is the fast syscall return path. We do as little as possible here, * such as avoiding writing r0 to the stack. We only use this path if we - * have tracing and context tracking disabled - the overheads from those - * features make this path too inefficient. + * have tracing, context tracking and rseq debug disabled - the overheads + * from those features make this path too inefficient. */ ret_fast_syscall: UNWIND(.fnstart ) @@ -71,14 +72,20 @@ fast_work_pending: /* fall through to work_pending */ #else /* - * The "replacement" ret_fast_syscall for when tracing or context tracking - * is enabled. As we will need to call out to some C functions, we save - * r0 first to avoid needing to save registers around each C function call. + * The "replacement" ret_fast_syscall for when tracing, context tracking, + * or rseq debug is enabled. As we will need to call out to some C functions, + * we save r0 first to avoid needing to save registers around each C function + * call. */ ret_fast_syscall: UNWIND(.fnstart ) UNWIND(.cantunwind ) str r0, [sp, #S_R0 + S_OFF]! @ save returned r0 +#if IS_ENABLED(CONFIG_DEBUG_RSEQ) + /* do_rseq_syscall needs interrupts enabled. */ + mov r0, sp @ 'regs' + bl do_rseq_syscall +#endif disable_irq_notrace @ disable interrupts ldr r2, [tsk, #TI_ADDR_LIMIT] cmp r2, #TASK_SIZE @@ -113,6 +120,12 @@ ENDPROC(ret_fast_syscall) */ ENTRY(ret_to_user) ret_slow_syscall: +#if IS_ENABLED(CONFIG_DEBUG_RSEQ) + /* do_rseq_syscall needs interrupts enabled. */ + enable_irq_notrace @ enable interrupts + mov r0, sp @ 'regs' + bl do_rseq_syscall +#endif disable_irq_notrace @ disable interrupts ENTRY(ret_to_user_from_irq) ldr r2, [tsk, #TI_ADDR_LIMIT] diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c index 5879ab3..f09e9d66 100644 --- a/arch/arm/kernel/signal.c +++ b/arch/arm/kernel/signal.c @@ -710,3 +710,10 @@ asmlinkage void addr_limit_check_failed(void) { addr_limit_user_check(); } + +#ifdef CONFIG_DEBUG_RSEQ +asmlinkage void do_rseq_syscall(struct pt_regs *regs) +{ + rseq_syscall(regs); +} +#endif -- Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com