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=-15.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 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 E9D13C433B4 for ; Thu, 8 Apr 2021 14:58:26 +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 9074C61041 for ; Thu, 8 Apr 2021 14:58:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9074C61041 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org 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=FD6bNVdV4ZQB3jlPCxqQ+ZThNOZvR67ZdmTlzN0foi0=; b=q76mxWD2aiCUGg7nJePLLvajI 9raaGx+jFvlFq2JxE/tAAq93i/2CjlKuIw24dvYlKrKdhPuQ8mVbpNsqCXQoj1uRNw5GnyurjqE62 Pq9KKVawI/VJ9jOnxMXEaO4+XslROd+9jLKQ5HOXdH1jjWZn3Hf4pWLjxzd9G05o+HTqWTWt4R8qa tpn5hSxYKLXhwx8xt86dnkgeEi9ERezN37Yoj6Tfp2rfwL95nyF8sNXvq1xxJf1vQXgTHfygDWadK 0jjkiCe12i0Hc/657Je2nLmdSZIXQrQgpXclCgRLMnn2edOabFezHpGA23z41xoaUfp3UvApyaS0t MJI2jT2YQ==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lUW5L-008Ifh-Ix; Thu, 08 Apr 2021 14:56:43 +0000 Received: from mail.kernel.org ([198.145.29.99]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lUW4o-008IXo-16 for linux-arm-kernel@lists.infradead.org; Thu, 08 Apr 2021 14:56:12 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 92784610F9; Thu, 8 Apr 2021 14:56:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1617893768; bh=dRsg/D7XwR/Opxe8txb8yjZZERiYX9xCaPVknGOYM/M=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Tl0OUXv79OcKikGGlNJj2e8yH3bMvRkH0zAVA5oaugYzD0d5iht0PzMb6yUGqwPKO DGb2+LJp9YQ0vSwttlDrL96mvidHI4XikDZfJLQ9yAggFwGsVoYGM/oAq8B48v1Uxp Xeu8SSezDPyc0m6z+m9ILzR1RHpAcXwYVhWynJeQKr+V1Q96qsO/Dp4W8jN7K4ae+z 0qOzWEGKIcCn3FUk17iE4XupAf+PMZFR7vnFBiTfvPguisBBjmCahSWKq1pC3LtTVN KyI1uUcMOMaGNNvjCVQq5wsPRV7cN9XzDIkMNvpEuhyKoW+eFIWIkKWh8ISAXToJJ9 Gixm1cMRz+72g== Date: Thu, 8 Apr 2021 15:56:04 +0100 From: Will Deacon To: Vincenzo Frascino Cc: 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: <20210408145604.GB18211@willie-the-truck> References: <20210408143723.13024-1-vincenzo.frascino@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210408143723.13024-1-vincenzo.frascino@arm.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210408_155610_811580_97B362AF X-CRM114-Status: GOOD ( 23.10 ) 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: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. > > 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. Will _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel