Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2699081imm; Wed, 16 May 2018 18:17:04 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpVI6DBRmyLS8Zq5lDFCO7FnHHaE97ZVcemET2MBVAvz0fPul8jfrtwC3oBXb1ZfQQRMehU X-Received: by 2002:a62:7682:: with SMTP id r124-v6mr3185051pfc.80.1526519824067; Wed, 16 May 2018 18:17:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526519824; cv=none; d=google.com; s=arc-20160816; b=JO940NZl5xvjmkoDS8To9+ebVlByAaiWIsmS1YSw17HLlXJyHM2Fw4DxUIQvMBeWmp m3p/uNsckOxSKiR4gkePzd9NqekkfztMWttg8zuUEOY5ou1vVP0N7wRZQqp1YfmeGndu xcDCgjRxRSZ8GGQeQBA2e8NAGui1Um2UYYga6WEipuScOKa+f2uGRJBrKINc/gFnktri KZH9p5UQgeierJzrkYYqSIG/HKfRZ0op3pI8F4hMsAIOwFT+qJgkChMV7sMirFa9Tuig pVRL8GAMH/GcA4JptVsCgtYHG7id9D5FJB+ae+YpCwtfewmfJ5YrUd0Ry+y1FX/kXsSt t6FA== 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=fZ/XxYICUN1Wj4yVj3LLYx2QqPR8sS3ExOdHoyxBipc=; b=wUXBN6uYf96oc1mc13kE8MHK0xLiG7JtNnliko1KFW9TntwcVxTzR6fTAcBe7KmhMG Oz7jcuHmcc60l0CDpyulf++whJoepBuKTvyXCDF8pp6TaShzFqSP1u2T4BgQaFZBn4Es /p99tlzNMMBtBq2oSUkOXRqur0LdrOrtznk/dMFPp7NrQl4NGQhs5EDaB7xlaZ0hY8Sg TR3JbSw0GRbhJUmf8v7mvO6yOZf5HsvzG5iTkFxN2yXWqjHtMHC3s4Sqffu2dqzdnR9h kwJv1NHEIjPX3dXpm7a1Ewt8k906TsKBdBU1LX2cC04q4H4vYZljfyPji030ZDs3RP/3 jg/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=unFQnbIo; 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 f1-v6si3934396pld.3.2018.05.16.18.16.49; Wed, 16 May 2018 18:17:04 -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=unFQnbIo; 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 S1751880AbeEQBPP (ORCPT + 99 others); Wed, 16 May 2018 21:15:15 -0400 Received: from mail-qk0-f195.google.com ([209.85.220.195]:43310 "EHLO mail-qk0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751290AbeEQBPM (ORCPT ); Wed, 16 May 2018 21:15:12 -0400 Received: by mail-qk0-f195.google.com with SMTP id h19-v6so2322532qkj.10; Wed, 16 May 2018 18:15:12 -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=fZ/XxYICUN1Wj4yVj3LLYx2QqPR8sS3ExOdHoyxBipc=; b=unFQnbIo5NuSRi0dWv1/e5vi/cBiTmtiTTtxrUrterYpSDIohC7hDNJ8QcjUp8cb4D GBwezBKpiOhcAEnjeWCtCT7L2yZiZaMcYKNhY61hjRvL9C+Ip5bsDy8ZFXUMAJxKdyRJ MzLi1KBRwLbtlsYNpNrmV5M30XPgLfrfKpa3fKuI7DJqRWuZ+yxdbtnoWZ5+DYyAez7n 5h5xjCMJJy5aJPjWbO8/RmtmFX5tpY1Jg76hlTn4sp5fZg8Ntk7TEz5XkJUbPBNGLmLl 0JhDd8AovFvzdnYVMFA4fXmrvWZGbpce0w0S4OVHOejKsVyUGz9tY5NQ/NYNQGCpMZoQ I86A== 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=fZ/XxYICUN1Wj4yVj3LLYx2QqPR8sS3ExOdHoyxBipc=; b=howf7xkmIRL4r+R4/Ko8xhJI2XnoANjt4pI0/bnkEESkXL08/BX1Li8pOdpXCqsM3N Em0CQxXCkYxjKkeIS4bv4gJdmZEmkV/iY6no0PtSDfnt1ZYSMdQgHe6Yc1gEeto4Rn5+ FtjaTcsFoK3ZuOyaDG7VvknMCEymLfSF6UPLVvwnd02SG73NRgfnSiFmpqe8eX4BV3we h59nCZ1cBPfuz8gJSCkbT+Otzb7b6HarLhWfa9zNryFUALuYctw4vwcBq70emzLN5BLR rFHo1e2vgaXRUc6JGeCR7rTHhUibeDumAf0xrwqOadd1mWkjmvyWn7/BgF5HXc+xTMD3 Gc+w== X-Gm-Message-State: ALKqPwcMzHpxQFTP16eROk1Ndshil564IiOcK7HgMnyaOu6Qi4zoM0qd zt90uV6OCypDGY84+pW5qK0= X-Received: by 2002:ae9:edc8:: with SMTP id c191-v6mr619073qkg.127.1526519711763; Wed, 16 May 2018 18:15:11 -0700 (PDT) Received: from auth2-smtp.messagingengine.com (auth2-smtp.messagingengine.com. [66.111.4.228]) by smtp.gmail.com with ESMTPSA id b27-v6sm2996705qtc.66.2018.05.16.18.15.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 16 May 2018 18:15:10 -0700 (PDT) Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailauth.nyi.internal (Postfix) with ESMTP id BE2FB21625; Wed, 16 May 2018 21:15:08 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Wed, 16 May 2018 21:15:08 -0400 X-ME-Sender: Received: from localhost (unknown [45.32.128.109]) by mail.messagingengine.com (Postfix) with ESMTPA id B9FF11025D; Wed, 16 May 2018 21:15:07 -0400 (EDT) Date: Thu, 17 May 2018 09:19:49 +0800 From: Boqun Feng To: Mathieu Desnoyers Cc: 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 , Will Deacon , 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: <20180517011949.GA1121@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> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="qMm9M+Fa2AknHoGS" Content-Disposition: inline In-Reply-To: <112970629.1913.1526501596485.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 --qMm9M+Fa2AknHoGS Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, May 16, 2018 at 04:13:16PM -0400, Mathieu Desnoyers wrote: > ----- On May 16, 2018, at 12:18 PM, Peter Zijlstra peterz@infradead.org w= rote: >=20 > > On Mon, Apr 30, 2018 at 06:44:26PM -0400, Mathieu Desnoyers wrote: > >> diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig > >> index c32a181a7cbb..ed21a777e8c6 100644 > >> --- a/arch/powerpc/Kconfig > >> +++ b/arch/powerpc/Kconfig > >> @@ -223,6 +223,7 @@ config PPC > >> select HAVE_SYSCALL_TRACEPOINTS > >> select HAVE_VIRT_CPU_ACCOUNTING > >> select HAVE_IRQ_TIME_ACCOUNTING > >> + select HAVE_RSEQ > >> select IRQ_DOMAIN > >> select IRQ_FORCED_THREADING > >> select MODULES_USE_ELF_RELA > >> diff --git a/arch/powerpc/kernel/signal.c b/arch/powerpc/kernel/signal= =2Ec > >> index 61db86ecd318..d3bb3aaaf5ac 100644 > >> --- a/arch/powerpc/kernel/signal.c > >> +++ b/arch/powerpc/kernel/signal.c > >> @@ -133,6 +133,8 @@ static void do_signal(struct task_struct *tsk) > >> /* Re-enable the breakpoints for the signal stack */ > >> thread_change_pc(tsk, tsk->thread.regs); > >> =20 > >> + rseq_signal_deliver(tsk->thread.regs); > >> + > >> if (is32) { > >> if (ksig.ka.sa.sa_flags & SA_SIGINFO) > >> ret =3D handle_rt_signal32(&ksig, oldset, tsk); > >> @@ -164,6 +166,7 @@ void do_notify_resume(struct pt_regs *regs, unsign= ed long > >> thread_info_flags) > >> if (thread_info_flags & _TIF_NOTIFY_RESUME) { > >> clear_thread_flag(TIF_NOTIFY_RESUME); > >> tracehook_notify_resume(regs); > >> + rseq_handle_notify_resume(regs); > >> } > >> =20 > >> user_enter(); > >=20 > > Again no rseq_syscall(). >=20 > Same question for PowerPC as for ARM: >=20 > Considering that rseq_syscall is implemented as follows: >=20 > +void rseq_syscall(struct pt_regs *regs) > +{ > + unsigned long ip =3D instruction_pointer(regs); > + struct task_struct *t =3D current; > + struct rseq_cs rseq_cs; > + > + if (!t->rseq) > + return; > + if (!access_ok(VERIFY_READ, t->rseq, sizeof(*t->rseq)) || > + rseq_get_rseq_cs(t, &rseq_cs) || in_rseq_cs(ip, &rseq_cs)) > + force_sig(SIGSEGV, t); > +} >=20 > and that x86 calls it from syscall_return_slowpath() (which AFAIU is > now used in the fast-path since KPTI), I wonder where we should call So we actually detect this after the syscall takes effect, right? I wonder whether this could be problematic, because "disallowing syscall" in rseq areas may means the syscall won't take effect to some people, I guess? > this on PowerPC ? I was under the impression that PowerPC return to > userspace fast-path was not calling C code unless work flags were set, > but I might be wrong. >=20 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 */ =20 + 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|_TI= F_PERSYSCALL_MASK) But I think it's important for us to first decide where (before or after the syscall) we do the detection. Regards, Boqun > Thoughts ? >=20 > Thanks! >=20 > Mathieu >=20 > --=20 > Mathieu Desnoyers > EfficiOS Inc. > http://www.efficios.com --qMm9M+Fa2AknHoGS Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCAAdFiEEj5IosQTPz8XU1wRHSXnow7UH+rgFAlr82LEACgkQSXnow7UH +rigrAf9F+civFS4yvkbV5+5YY7LO3c7DJGBFUVnW4gUwQ14uGxh/pzKh9n2Sz1A RUVz++oMugIjA3y4/4dLCEjaG8D1qZ96dTJ01vHakA+ieg6rJ0a2/hqrH2lDur9/ HDrrniFt823LtzZrZtg6gAimOXsRS/lAMJftmrbwDgzNjenr4iOOklZRx/vX7W7k nE/w1BChYNKSqbv8LIGpFLbOdDl1rstDhdAfyq0STjsw15LiL389Ae07MVbibt89 xC06lV+o7EnibHXg7p2K/EJzEG8PYmNRmanayu8Rtw2fwKULbUFiuNJB5L5l27Q+ SdKzROnL22KVhC+kPzLx7l/yI0386Q== =nkk3 -----END PGP SIGNATURE----- --qMm9M+Fa2AknHoGS--