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=-13.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,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 87358C43461 for ; Thu, 8 Apr 2021 15:08:21 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 3737C610D1 for ; Thu, 8 Apr 2021 15:08:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3737C610D1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+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=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:Cc: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=Z6wScSfyd9QMA/w/MAOhflizH9vlkjway9JWWVEWx7Q=; b=j3g8WKyc3ZytnNJ4sXnYxLpho eSSZYlC/Z10698A7S4BUXvZpmw0AQBO43wkWOF8zDGPTR1K1FEbjZMKfPLzSGk4UWeEaRT5pjSSf3 B+71ztl+hfyD+ODfyPD4jJq+cjXpI/uk9ez/0UIEdGlMHWsSfmmsTcqIvLYbtt9P7I0t5TO85G45/ Uq9Y6dnGuiQkF1k8XEIxhj8yrsyEckJ7PYSFF3oq1S+E0BTT988v07nKMHLng3oymn012rK1Ixmc8 uPAA3gV1Ew+xFU47qyu9niy62xB0G1YuO0Wl1hhkgx0p4nHTG8NVfvEmbi3zXEwIkjjzZpTj/IrpE 9CsKXxMCA==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lUWEz-008KQK-P2; Thu, 08 Apr 2021 15:06:42 +0000 Received: from foss.arm.com ([217.140.110.172]) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lUWEu-008KPj-Jl for linux-arm-kernel@lists.infradead.org; Thu, 08 Apr 2021 15:06:38 +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 AD7CAD6E; Thu, 8 Apr 2021 08:06:34 -0700 (PDT) Received: from C02TD0UTHF1T.local (unknown [10.57.24.62]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 21EBB3F694; Thu, 8 Apr 2021 08:06:32 -0700 (PDT) Date: Thu, 8 Apr 2021 16:06:23 +0100 From: Mark Rutland To: Will Deacon Cc: Vincenzo Frascino , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, Catalin Marinas Subject: Re: [PATCH] arm64: mte: Move MTE TCF0 check in entry-common Message-ID: <20210408150612.GA37165@C02TD0UTHF1T.local> References: <20210408143723.13024-1-vincenzo.frascino@arm.com> <20210408145604.GB18211@willie-the-truck> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210408145604.GB18211@willie-the-truck> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210408_160637_186335_0426B870 X-CRM114-Status: GOOD ( 28.08 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, Apr 08, 2021 at 03:56:04PM +0100, Will Deacon wrote: > On Thu, Apr 08, 2021 at 03:37:23PM +0100, Vincenzo Frascino wrote: > > The check_mte_async_tcf macro sets the TIF flag non-atomically. This can > > race with another CPU doing a set_tsk_thread_flag() and the flag can be > > lost in the process. > > Actually, it's all the *other* flags that get lost! > > > Move the tcf0 check to enter_from_user_mode() and clear tcf0 in > > exit_to_user_mode() to address the problem. > > > > Note: Moving the check in entry-common allows to use set_thread_flag() > > which is safe. > > > > Fixes: 637ec831ea4f ("arm64: mte: Handle synchronous and asynchronous > > tag check faults") > > Cc: Catalin Marinas > > Cc: Will Deacon > > Reported-by: Will Deacon > > Signed-off-by: Vincenzo Frascino > > --- > > arch/arm64/include/asm/mte.h | 8 ++++++++ > > arch/arm64/kernel/entry-common.c | 6 ++++++ > > arch/arm64/kernel/entry.S | 30 ------------------------------ > > arch/arm64/kernel/mte.c | 25 +++++++++++++++++++++++-- > > 4 files changed, 37 insertions(+), 32 deletions(-) > > > > diff --git a/arch/arm64/include/asm/mte.h b/arch/arm64/include/asm/mte.h > > index 9b557a457f24..188f778c6f7b 100644 > > --- a/arch/arm64/include/asm/mte.h > > +++ b/arch/arm64/include/asm/mte.h > > @@ -31,6 +31,8 @@ void mte_invalidate_tags(int type, pgoff_t offset); > > void mte_invalidate_tags_area(int type); > > void *mte_allocate_tag_storage(void); > > void mte_free_tag_storage(char *storage); > > +void check_mte_async_tcf0(void); > > +void clear_mte_async_tcf0(void); > > > > #ifdef CONFIG_ARM64_MTE > > > > @@ -83,6 +85,12 @@ static inline int mte_ptrace_copy_tags(struct task_struct *child, > > { > > return -EIO; > > } > > +void check_mte_async_tcf0(void) > > +{ > > +} > > +void clear_mte_async_tcf0(void) > > +{ > > +} > > > > static inline void mte_assign_mem_tag_range(void *addr, size_t size) > > { > > diff --git a/arch/arm64/kernel/entry-common.c b/arch/arm64/kernel/entry-common.c > > index 9d3588450473..837d3624a1d5 100644 > > --- a/arch/arm64/kernel/entry-common.c > > +++ b/arch/arm64/kernel/entry-common.c > > @@ -289,10 +289,16 @@ asmlinkage void noinstr enter_from_user_mode(void) > > CT_WARN_ON(ct_state() != CONTEXT_USER); > > user_exit_irqoff(); > > trace_hardirqs_off_finish(); > > + > > + /* Check for asynchronous tag check faults in user space */ > > + check_mte_async_tcf0(); > > } > > Is enter_from_user_mode() always called when we enter the kernel from EL0? > afaict, some paths (e.g. el0_irq()) only end up calling it if > CONTEXT_TRACKING or TRACE_IRQFLAGS are enabled. Currently everything that's in {enter,exit}_from_user_mode() only matters when either CONTEXT_TRACKING or TRACE_IRQFLAGS is selected (and expands to an empty stub otherwise). We could drop the ifdeffery in user_{enter,exit}_irqoff() to have them called regardless, or add CONFIG_MTE to the list. > > asmlinkage void noinstr exit_to_user_mode(void) > > { > > + /* Ignore asynchronous tag check faults in the uaccess routines */ > > + clear_mte_async_tcf0(); > > + > > and this one seems to be called even less often. This is always done in ret_to_user, so (modulo ifdeferry above) all returns to EL0 call this. Thanks, Mark. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel