From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.7 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D4B97C34055 for ; Wed, 19 Feb 2020 16:20:21 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 793DE24656 for ; Wed, 19 Feb 2020 16:20:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 793DE24656 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D04366B0003; Wed, 19 Feb 2020 11:20:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CB4DC6B0006; Wed, 19 Feb 2020 11:20:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BF1C36B0007; Wed, 19 Feb 2020 11:20:20 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id A530B6B0003 for ; Wed, 19 Feb 2020 11:20:20 -0500 (EST) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 3C0D68133 for ; Wed, 19 Feb 2020 16:20:20 +0000 (UTC) X-FDA: 76507389000.15.town19_8d41d4c4e7b45 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin15.hostedemail.com (Postfix) with ESMTP id B423818034F47 for ; Wed, 19 Feb 2020 16:16:11 +0000 (UTC) X-HE-Tag: town19_8d41d4c4e7b45 X-Filterd-Recvd-Size: 5438 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf32.hostedemail.com (Postfix) with ESMTP for ; Wed, 19 Feb 2020 16:16:10 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C6F231FB; Wed, 19 Feb 2020 08:16:09 -0800 (PST) Received: from arrakis.emea.arm.com (arrakis.cambridge.arm.com [10.1.196.71]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C4CF63F703; Wed, 19 Feb 2020 08:16:07 -0800 (PST) Date: Wed, 19 Feb 2020 16:16:05 +0000 From: Catalin Marinas To: Peter Collingbourne Cc: Evgenii Stepanov , Kostya Serebryany , Linux ARM , linux-arch@vger.kernel.org, Richard Earnshaw , Szabolcs Nagy , Marc Zyngier , Kevin Brodsky , linux-mm@kvack.org, Andrey Konovalov , Vincenzo Frascino , Will Deacon Subject: Re: [PATCH] arm64: mte: Do not service syscalls after async tag fault Message-ID: <20200219161605.GA84712@arrakis.emea.arm.com> References: <20191217180152.GO5624@arrakis.emea.arm.com> <20191220013639.212396-1-pcc@google.com> <20200212110903.GE488264@arrakis.emea.arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, Feb 18, 2020 at 01:59:34PM -0800, Peter Collingbourne wrote: > On Wed, Feb 12, 2020 at 3:09 AM Catalin Marinas wrote: > > On Thu, Dec 19, 2019 at 05:36:39PM -0800, Peter Collingbourne wrote: > > > When entering the kernel after an async tag fault due to a syscall, rather > > > than for another reason (e.g. preemption), we don't want to service the > > > syscall as it may mask the tag fault. Rewind the PC to the svc instruction > > > in order to give a userspace signal handler an opportunity to handle the > > > fault and resume, and skip all other syscall processing. > > > > > > Signed-off-by: Peter Collingbourne > > > --- > > [...] > > > arch/arm64/kernel/syscall.c | 22 +++++++++++++++++++--- > > > 1 file changed, 19 insertions(+), 3 deletions(-) > > > > > > diff --git a/arch/arm64/kernel/syscall.c b/arch/arm64/kernel/syscall.c > > > index 9a9d98a443fc..49ea9bb47190 100644 > > > --- a/arch/arm64/kernel/syscall.c > > > +++ b/arch/arm64/kernel/syscall.c > > > @@ -95,13 +95,29 @@ static void el0_svc_common(struct pt_regs *regs, int scno, int sc_nr, > > > { > > > unsigned long flags = current_thread_info()->flags; > > > > > > - regs->orig_x0 = regs->regs[0]; > > > - regs->syscallno = scno; > > > - > > > cortex_a76_erratum_1463225_svc_handler(); > > > local_daif_restore(DAIF_PROCCTX); > > > user_exit(); > > > > > > +#ifdef CONFIG_ARM64_MTE > > > + if (flags & _TIF_MTE_ASYNC_FAULT) { > > > + /* > > > + * We entered the kernel after an async tag fault due to a > > > + * syscall, rather than for another reason (e.g. preemption). > > > + * In this case, we don't want to service the syscall as it may > > > + * mask the tag fault. Rewind the PC to the svc instruction in > > > + * order to give a userspace signal handler an opportunity to > > > + * handle the fault and resume, and skip all other syscall > > > + * processing. > > > + */ > > > + regs->pc -= 4; > > > + return; > > > + } > > > +#endif > > > + > > > + regs->orig_x0 = regs->regs[0]; > > > + regs->syscallno = scno; > > > > I'm slightly worried about the interaction with single-step, other > > signals. It might be better if we just use the existing syscall > > restarting mechanism. Untested diff below: > > > > -------------------8<------------------------------- > > diff --git a/arch/arm64/kernel/syscall.c b/arch/arm64/kernel/syscall.c > > index a12c0c88d345..db25f5d6a07c 100644 > > --- a/arch/arm64/kernel/syscall.c > > +++ b/arch/arm64/kernel/syscall.c > > @@ -102,6 +102,16 @@ static void el0_svc_common(struct pt_regs *regs, int scno, int sc_nr, > > local_daif_restore(DAIF_PROCCTX); > > user_exit(); > > > > + if (system_supports_mte() && (flags & _TIF_MTE_ASYNC_FAULT)) { > > + /* > > + * Process the asynchronous tag check fault before the actual > > + * syscall. do_notify_resume() will send a signal to userspace > > + * before the syscall is restarted. > > + */ > > + regs->regs[0] = -ERESTARTNOINTR; > > + return; > > + } > > + > > if (has_syscall_work(flags)) { > > /* set default errno for user-issued syscall(-1) */ > > if (scno == NO_SYSCALL) > > That works for me, and I verified that my small test program as well > as some larger unit tests behave as expected. > > Tested-by: Peter Collingbourne Thanks Peter. -- Catalin