Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp6615668imm; Sun, 20 May 2018 07:04:37 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqbSunjrH1XWrw8m/M9p6tV87NnoIf6mLVCvJd5lAEcyKfXN6oQoM0/zl2BOvKfsgsVXyue X-Received: by 2002:a63:7341:: with SMTP id d1-v6mr12824869pgn.404.1526825077397; Sun, 20 May 2018 07:04:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526825077; cv=none; d=google.com; s=arc-20160816; b=L1WBY/d1qzFdLFeu5BBlgfRqwOui+XDKYYHDO416uq0nAlS2ZLKEzhOOYYSth46pzt xe6UyQIOArvDBedBYnSbOdCgH7nfcTLBuo4gRe8z6hdWMUukW3lRvw4y16Lljk2ILax5 rR4V2I6oLDZ34hBZV4zSO7uTOItpFIGPqrB9jiGO0D0DECJ3Zt4I7S8rrdsRmzZMhIc2 8SEAgK/FEdQenkS+YYZ4UTgzSG+218xICzzlKHy80ZosZBEkNfJFl0dyrWvWvL1WFSFk OnRldbC35pXW4d2HtJJjApShh0cgfRkO/R3JjGxVwMFEKZGge+As7kKRXFazmsavufSP Ly4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=OYWrKOePKHY872QquwvO+8HcIsE7wtCqDoXcC2MqTCI=; b=CB7VWRln/pqSrXQjkh96NzqWARNwkyQNJvx7htxig9zV7CuKzq/4yT7HHGOvZGt80B zJYn5/X5qtKp60Ty0n6D8pLpXQxJnW7kTJQqeN7J/+hq+1JyKhcW/ebUeKV8NsHqFogB 09FuQgYoJbzBTl3Bs9gFO36YZg8BWjwi9C2jpwcq3BpvOCl/lBG6rmaeD2ZjqBtSWv4N R++136JJvjGXGE5Qlrysx3Atw6RejTMaGDcfRQ8lzwjb3AMN99XkjGLoV8G1NAL+F6kV mAQsoLU7eHghve9BUfyvEzur5Y60oS8HFbUWvShQE0eoIyaywrMt0bQg+y2Dvhzz/7Gx LTAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=rW4Om3SF; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a98-v6si11912208pla.239.2018.05.20.07.04.08; Sun, 20 May 2018 07:04:37 -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=@gmail.com header.s=20161025 header.b=rW4Om3SF; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751535AbeETODb (ORCPT + 99 others); Sun, 20 May 2018 10:03:31 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:51032 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751331AbeETOD2 (ORCPT ); Sun, 20 May 2018 10:03:28 -0400 Received: by mail-wm0-f68.google.com with SMTP id t11-v6so21216496wmt.0; Sun, 20 May 2018 07:03:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=OYWrKOePKHY872QquwvO+8HcIsE7wtCqDoXcC2MqTCI=; b=rW4Om3SFy8r6kfqICNabes3ximwKbaDAGEsgA39xgyd3bur444vezo/iJgHNkAL7jt XPbsdc8/UWf4w8TiV10h6EOZZlq/MWkL3OPAK+zRm+kqM4zNRKNFF1jC57nsJu4Psvrc ikl8uv6qhFoU8vlk+N6f2k5Z7nf+zH0B4M2GkvT/+JUBWgOQbLR9/3ED+1kJLvsP0i2l gXxdVroBYJomR3FFXKuKv+B1ZSCA98E+HVrSFopCq5kVXI2RAHbMykHqDGMnLW1WPcsc dAmXadfB+luG1SDbL8bsBIv9Ykj2e+g42o7WlxwjOQpylVW9yziynqB3rEl4UuA3+/Z9 vEuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=OYWrKOePKHY872QquwvO+8HcIsE7wtCqDoXcC2MqTCI=; b=Mux/V/EpV1JerLIRCtyUm01i2Rbr/Z/KqFWmBqfASAx7krVXPN1pZ8TN0h/4yvXGRl LfQ6n+d4tsOiTb3ux4DKDAdskbwsDfpxhRvEO+4cRUzGoUWHR77mnSOljf68dqF0gEHM vvb5O9vzBbCMJbuTmCjIZiIzMm0OwDtsC/RhGJtiKSnsTNgZ3eZft88FoMEyXYwBplOp 1ymhIhVCeQjpXwHVoyPGSZdZO3tY9/+eJqetLQ516iaqQR8QbWLepFAUG8YsBnd2BJ6J Mr3aik6qqVzsWx/XX4GqRJUIAW79KUAsmVkiI7IIfi3fIupLX49XgSEdWSf9cvusE/x8 TA2A== X-Gm-Message-State: ALKqPwfrpWCdPgutpAbJGuEW3SACzLlZ5l6/O5m71j6HpY88l8mp+1JX 6I4xaOD/ZZBILYDmD3iQrYU= X-Received: by 2002:aa7:c40b:: with SMTP id j11-v6mr19692135edq.189.1526825007093; Sun, 20 May 2018 07:03:27 -0700 (PDT) Received: from auth2-smtp.messagingengine.com (auth2-smtp.messagingengine.com. [66.111.4.228]) by smtp.gmail.com with ESMTPSA id o47-v6sm6145645edc.95.2018.05.20.07.03.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 20 May 2018 07:03:26 -0700 (PDT) Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailauth.nyi.internal (Postfix) with ESMTP id B7A9521CD3; Sun, 20 May 2018 10:03:21 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Sun, 20 May 2018 10:03:21 -0400 X-ME-Sender: Received: from localhost (unknown [45.32.128.109]) by mail.messagingengine.com (Postfix) with ESMTPA id D0F3CE4A32; Sun, 20 May 2018 10:03:20 -0400 (EDT) Date: Sun, 20 May 2018 22:08:11 +0800 From: Boqun Feng To: Mathieu Desnoyers Cc: Will Deacon , Peter Zijlstra , "Paul E. McKenney" , Andy Lutomirski , Dave Watson , linux-kernel , linux-api , Paul Turner , Andrew Morton , Russell King , 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 , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , linuxppc-dev Subject: Re: [PATCH 07/14] powerpc: Add support for restartable sequences Message-ID: <20180520140811.GB1121@tardis> References: <20180430224433.17407-1-mathieu.desnoyers@efficios.com> <20180430224433.17407-8-mathieu.desnoyers@efficios.com> <20180516161837.GI12198@hirez.programming.kicks-ass.net> <112970629.1913.1526501596485.JavaMail.zimbra@efficios.com> <20180517011949.GA1121@tardis> <277374719.2144.1526570889798.JavaMail.zimbra@efficios.com> <1526601043.1338308.1376191416.0444B8C5@webmail.messagingengine.com> <418003803.516.1526667437396.JavaMail.zimbra@efficios.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <418003803.516.1526667437396.JavaMail.zimbra@efficios.com> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 18, 2018 at 02:17:17PM -0400, Mathieu Desnoyers wrote: > ----- On May 17, 2018, at 7:50 PM, Boqun Feng boqun.feng@gmail.com wrote: > [...] > >> > I think you're right. So we have to introduce callsite to rseq_syscall() > >> > in syscall path, something like: > >> > > >> > diff --git a/arch/powerpc/kernel/entry_64.S b/arch/powerpc/kernel/entry_64.S > >> > index 51695608c68b..a25734a96640 100644 > >> > --- a/arch/powerpc/kernel/entry_64.S > >> > +++ b/arch/powerpc/kernel/entry_64.S > >> > @@ -222,6 +222,9 @@ system_call_exit: > >> > mtmsrd r11,1 > >> > #endif /* CONFIG_PPC_BOOK3E */ > >> > > >> > + addi r3,r1,STACK_FRAME_OVERHEAD > >> > + bl rseq_syscall > >> > + > >> > ld r9,TI_FLAGS(r12) > >> > li r11,-MAX_ERRNO > >> > andi. > >> > r0,r9,(_TIF_SYSCALL_DOTRACE|_TIF_SINGLESTEP|_TIF_USER_WORK_MASK|_TIF_PERSYSCALL_MASK) > >> > > > By the way, I think this is not the right spot to call rseq_syscall, because > interrupts are disabled. I think we should move this hunk right after system_call_exit. > Good point. > Would you like to implement and test an updated patch adding those calls for ppc 32 and 64 ? > I'd like to help, but I don't have a handy ppc environment for test... So I made the below patch which has only been build-tested, hope it could be somewhat helpful. Regards, Boqun --------------------------------->8 Subject: [PATCH] powerpc: 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: Boqun Feng --- arch/powerpc/kernel/entry_32.S | 5 +++++ arch/powerpc/kernel/entry_64.S | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S index eb8d01bae8c6..2f134eebe7ed 100644 --- a/arch/powerpc/kernel/entry_32.S +++ b/arch/powerpc/kernel/entry_32.S @@ -365,6 +365,11 @@ syscall_dotrace_cont: blrl /* Call handler */ .globl ret_from_syscall ret_from_syscall: +#ifdef CONFIG_DEBUG_RSEQ + /* Check whether the syscall is issued inside a restartable sequence */ + addi r3,r1,STACK_FRAME_OVERHEAD + bl rseq_syscall +#endif mr r6,r3 CURRENT_THREAD_INFO(r12, r1) /* disable interrupts so current_thread_info()->flags can't change */ diff --git a/arch/powerpc/kernel/entry_64.S b/arch/powerpc/kernel/entry_64.S index 2cb5109a7ea3..2e2d59bb45d0 100644 --- a/arch/powerpc/kernel/entry_64.S +++ b/arch/powerpc/kernel/entry_64.S @@ -204,6 +204,11 @@ system_call: /* label this so stack traces look sane */ * This is blacklisted from kprobes further below with _ASM_NOKPROBE_SYMBOL(). */ system_call_exit: +#ifdef CONFIG_DEBUG_RSEQ + /* Check whether the syscall is issued inside a restartable sequence */ + addi r3,r1,STACK_FRAME_OVERHEAD + bl rseq_syscall +#endif /* * Disable interrupts so current_thread_info()->flags can't change, * and so that we don't get interrupted after loading SRR0/1. -- 2.16.2