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=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 A9653C34050 for ; Wed, 19 Feb 2020 16:16:20 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 61AD52465D for ; Wed, 19 Feb 2020 16:16:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="pFsWjfJO" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 61AD52465D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=FdoFP+3hhF+o705PX01JCcz9fjkfFHq7FIKzn5S4tsM=; b=pFsWjfJO9suvIE XOfGnfi9ayxvR7LLyQPOSe+EXzk3h+GhYs4YLAhD2yzfJOBMySc5JSXumJHyWkHs4W7Q5CDa25GtM URHhj1So6SrmNVLh9CcA6tKAk6eRWHibvX8+kvk0J4rPSWYn8oduloeKuBdifHQDxK+HZ3pcll6YJ WSzRmGLlP5v/V3u1O8OXzYWWzrxRQa0CJNrHivfptoWTafJsk9NuR9+5U+R4Uer59tNt4FLzH+191 MwukwDnoMaK/6p8oiHw7lQvHYAksWUlVO6ZWZ4KzTyYxGW/e1nVAez7e1q69ftSDLtgTY53lyopjy 0mQZxUSH44vF7v9BDhIw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1j4S1G-0005mE-EN; Wed, 19 Feb 2020 16:16:14 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1j4S1D-0005lV-FH for linux-arm-kernel@lists.infradead.org; Wed, 19 Feb 2020 16:16:13 +0000 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 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-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200219_081611_598623_E96B96A8 X-CRM114-Status: GOOD ( 24.37 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, Richard Earnshaw , linux-mm@kvack.org, Szabolcs Nagy , Marc Zyngier , Kevin Brodsky , Kostya Serebryany , Evgenii Stepanov , Andrey Konovalov , Vincenzo Frascino , Will Deacon , Linux ARM Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel