Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1340366imm; Wed, 23 May 2018 14:30:19 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrtIUIWiFgwmaqwIMufJkzSGlo/VpX3ON8QzniXW9QWuv4bl68pOrtlOFUwlt3im3URO9x7 X-Received: by 2002:a17:902:781:: with SMTP id 1-v6mr4558751plj.150.1527111019112; Wed, 23 May 2018 14:30:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527111019; cv=none; d=google.com; s=arc-20160816; b=G8hBwxcGogXzT0QPo4f6pMEpalZxUoT7SwVDdqFNfNBgfACs43m6bPOv8TXKseHU89 qjrDHl0lxgnMIKVlzHVMuKooy77PMedZ/Cy8+dCuuWVh6ja38F3NXwfsgHxsnRHUmGv/ RqM3HWiq1tDXDl/76ATA9w09nqaWTUYgP3tGerQ1pBqEOhgUL+M6KdHNOQwg42Hkjn6G YhiSNcph4GKgiT9Stc9lNOaND1q6mjpgQV4BI4anDrmBeYe+tv0+ZTu2U3eOLE1Ll96f s7xAyDzgPpTBNoxhyWD1lBqmW1CngSWnen1/Ndn9i02f5Uuk5irc1zz48eYFK+74m5xH tNGQ== 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=pVslENkbaoQBTGY1pI0wrA3JmBwrWkghEAgkB+yfLow=; b=mBOiwX2BwYBBuh2Q/V+mFawtpXY5mGyAGA3KCtcz1+Nh/bdxKJlfZcK7sjE1o+lmZI 5GEqVX/UFGz55Zs3UA2zYEajz4/tkXA3iT2Rnj+7L5Cvsahv6YG8Sc8DSPxo7FMrlGPq MmwtCUqZ6P7ldcEJQuM8VIyc1PxjH9MxGFbO70sp9qVJsDgegnc2p2aKFtpIJKr7BQ+x /KXA3GNof9fl3NRSGPOYDnKwrQd0gejC3IIWdK+YcYzaCjiAN0LiqYufvScR/UQik2d3 3FCGgIT44DgY00aQe8rCHBBRBVN1M5nkfiKHQ/crMfkxumXy6vzY1LZohmCI3gHDAlaf tS+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=default header.b=FQ57bY8C; 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 k2-v6si19623549plt.374.2018.05.23.14.30.04; Wed, 23 May 2018 14:30:19 -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=FQ57bY8C; 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 S934899AbeEWV3t (ORCPT + 99 others); Wed, 23 May 2018 17:29:49 -0400 Received: from mail.efficios.com ([167.114.142.138]:45088 "EHLO mail.efficios.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934041AbeEWV3r (ORCPT ); Wed, 23 May 2018 17:29:47 -0400 Received: from localhost (ip6-localhost [IPv6:::1]) by mail.efficios.com (Postfix) with ESMTP id 424EB223C08; Wed, 23 May 2018 17:29:46 -0400 (EDT) Received: from mail.efficios.com ([IPv6:::1]) by localhost (mail02.efficios.com [IPv6:::1]) (amavisd-new, port 10032) with ESMTP id Xatokl1EbFDI; Wed, 23 May 2018 17:29:45 -0400 (EDT) Received: from localhost (ip6-localhost [IPv6:::1]) by mail.efficios.com (Postfix) with ESMTP id 6CD6F223C05; Wed, 23 May 2018 17:29:45 -0400 (EDT) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com 6CD6F223C05 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=default; t=1527110985; bh=pVslENkbaoQBTGY1pI0wrA3JmBwrWkghEAgkB+yfLow=; h=Date:From:To:Message-ID:MIME-Version; b=FQ57bY8Csx+d/OV8P7OW/tPCmcQDqFfinz5panhvxOO3NJ8oRRfRbPYi/jfLf5mms CbjHg1uRNC7IjIIo1lItfbka7tpP5rsWh/qmPBUJ4BlM8TJYHCC95M+LCTBGBVUkao anhj7qw0DJjdwDyEPaVpHyVz+1Juu3A60gLXZiBMptf42lFb9m8pw4nHcKeNLDgruJ Pg4xmrGDTeJauSsV+Ln8ZMkYtMSkIOKMGF/hpFZcNhaW1YrCm7ZkL2TbQ0SJOKl2W+ p2TSD9TBA4zd722VqTkwFnqj4WrBEQZvT50cqnKw2lgD/bB8wrAoHf6LzDk6XVLuXu PR6G4JdPXj82g== 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 7UFzMVUN6eUo; Wed, 23 May 2018 17:29:45 -0400 (EDT) Received: from mail02.efficios.com (mail02.efficios.com [167.114.142.138]) by mail.efficios.com (Postfix) with ESMTP id 4A4B9223BFA; Wed, 23 May 2018 17:29:45 -0400 (EDT) Date: Wed, 23 May 2018 17:29:45 -0400 (EDT) From: Mathieu Desnoyers To: Boqun Feng 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 Message-ID: <37442352.1577.1527110985175.JavaMail.zimbra@efficios.com> In-Reply-To: <1928158599.1541.1527106479862.JavaMail.zimbra@efficios.com> References: <20180430224433.17407-1-mathieu.desnoyers@efficios.com> <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> <20180520140811.GB1121@tardis> <1928158599.1541.1527106479862.JavaMail.zimbra@efficios.com> Subject: Re: [PATCH 07/14] powerpc: Add support for restartable sequences 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_2075 (ZimbraWebClient - FF52 (Linux)/8.8.8_GA_2031) Thread-Topic: powerpc: Add support for restartable sequences Thread-Index: qqWL7CAG0anHYmSjRuZc1e0kK3FL8y/YzDEU Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ----- On May 23, 2018, at 4:14 PM, Mathieu Desnoyers mathieu.desnoyers@efficios.com wrote: > ----- On May 20, 2018, at 10:08 AM, Boqun Feng boqun.feng@gmail.com wrote: > >> 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. > > Hi Boqun, > > I tried your patch in a ppc64 le environment, and it does not survive boot > with CONFIG_DEBUG_RSEQ=y. init gets killed right away. The following fixup gets ppc64 to work: --- a/arch/powerpc/kernel/entry_64.S +++ b/arch/powerpc/kernel/entry_64.S @@ -208,6 +208,7 @@ system_call_exit: /* Check whether the syscall is issued inside a restartable sequence */ addi r3,r1,STACK_FRAME_OVERHEAD bl rseq_syscall + ld r3,RESULT(r1) #endif /* * Disable interrupts so current_thread_info()->flags can't change, > Moreover, I'm not sure that the r3 register don't contain something worth > saving before the call on ppc32. Just after there is a "mr" instruction > which AFAIU takes r3 as input register. I'll start testing on ppc32 now. Thanks, Mathieu > > Can you look into it ? > > Thanks, > > Mathieu > >> >> 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 > > -- > Mathieu Desnoyers > EfficiOS Inc. > http://www.efficios.com -- Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com