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.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 5EDFCC2BA83 for ; Wed, 12 Feb 2020 11:09:10 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1E0642073C for ; Wed, 12 Feb 2020 11:09:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1E0642073C 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 A8CDA6B0425; Wed, 12 Feb 2020 06:09:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A17526B0427; Wed, 12 Feb 2020 06:09:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 905446B0428; Wed, 12 Feb 2020 06:09:09 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0147.hostedemail.com [216.40.44.147]) by kanga.kvack.org (Postfix) with ESMTP id 751E76B0425 for ; Wed, 12 Feb 2020 06:09:09 -0500 (EST) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 407D7181AEF00 for ; Wed, 12 Feb 2020 11:09:09 +0000 (UTC) X-FDA: 76481203218.06.money62_6cee3cb1d2f01 X-HE-Tag: money62_6cee3cb1d2f01 X-Filterd-Recvd-Size: 4334 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf13.hostedemail.com (Postfix) with ESMTP for ; Wed, 12 Feb 2020 11:09:08 +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 4489030E; Wed, 12 Feb 2020 03:09:07 -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 9602E3F68F; Wed, 12 Feb 2020 03:09:05 -0800 (PST) Date: Wed, 12 Feb 2020 11:09:03 +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: <20200212110903.GE488264@arrakis.emea.arm.com> References: <20191217180152.GO5624@arrakis.emea.arm.com> <20191220013639.212396-1-pcc@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191220013639.212396-1-pcc@google.com> 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 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)