From mboxrd@z Thu Jan 1 00:00:00 1970 From: Catalin Marinas Subject: Re: [PATCH] arm64: mte: Do not service syscalls after async tag fault Date: Wed, 12 Feb 2020 11:09:03 +0000 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 Return-path: Received: from foss.arm.com ([217.140.110.172]:59306 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725821AbgBLLJI (ORCPT ); Wed, 12 Feb 2020 06:09:08 -0500 Content-Disposition: inline In-Reply-To: <20191220013639.212396-1-pcc@google.com> Sender: linux-arch-owner@vger.kernel.org List-ID: 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 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)