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=-10.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,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 40217C433B4 for ; Fri, 9 Apr 2021 16:57:49 +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 C6C966102A for ; Fri, 9 Apr 2021 16:57:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C6C966102A 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=4FRQdRbxa9AgYxZ8WcXNLVJRF4CalKFqTazFHkP3+KM=; b=mRjqBHYPXk5Q+w6KuCN/Cksw5 3p/++/9Qy0HVfOg3RyLo7y38jV1xQGaz9bsmFhfCdcYJVhwk0Pkj0bRTa1PaAl27QExuGucvLkXnD vpEeZMjRr337t6/0cXoDY6L2KE7qhvhfhC4299ut+jIKGEFXiwY0UfAV7I1WeK3vrDS32Xsx1CZhN U9u6TjmlX39MU1uJRDjdPFG9v4qbWU7rASZi95vQOqPLtLFfTEYQpf0qN+F0vRFAezkHA7EiWqpkt MNHAqN+2zxuRhjlFLdSwBZ5qGfliu/7XPPx64pcGAXy8fVs8A3zZOWo7za8e0Txleu7clHcf6qlc7 5t/lWPt0w==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lUuQW-0019rE-6n; Fri, 09 Apr 2021 16:56:12 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lUuQS-0019qy-Fm for linux-arm-kernel@desiato.infradead.org; Fri, 09 Apr 2021 16:56:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=NYmt+HOlCvRYg6jL6VbjogYBYrcTiq8Xzb5tJM6LQ/g=; b=uZc/e9ZmXZQXJEPWb9ULHVNGCm EtJ6QSaQlnjpWk763KpvOx1dAYJnzrZVgQZmXuKt/uoq17pVtas8dnb+NA0nYOHmiLIwBGj97NgSB KNu/G+KCoWcR1zhQfo9VfUMv9WAMLncxsF/nLZufube4CHSU1GoU9aiIHl3pHGi9BuWpmofbFwXAD 7HaSK3l2VzK8PXtWQw/uQ0E+ukCiGSTEBsz1VIvBpLDYDaZX6xY2J9WVltKg07u8tZRg02c7ykBOl VFKnNzX210zjP6BA8lVgBCDh2u2ebnSFgEOhixzJHEU943S5HnL7Z1rCHHe67khxzDALFbhty+sqk ini2pCcQ==; Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lUuQP-004fpN-R3 for linux-arm-kernel@lists.infradead.org; Fri, 09 Apr 2021 16:56:07 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1E8A8610CA; Fri, 9 Apr 2021 16:56:03 +0000 (UTC) Date: Fri, 9 Apr 2021 17:56:01 +0100 From: Catalin Marinas To: Mark Rutland Cc: Vincenzo Frascino , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, Will Deacon , stable@vger.kernel.org Subject: Re: [PATCH v3] arm64: mte: Move MTE TCF0 check in entry-common Message-ID: <20210409165601.GE24031@arm.com> References: <20210409132419.29965-1-vincenzo.frascino@arm.com> <20210409143247.GA58461@C02TD0UTHF1T.local> <20210409161030.GA60611@C02TD0UTHF1T.local> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210409161030.GA60611@C02TD0UTHF1T.local> 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-20210409_095605_917436_75D8AE0F X-CRM114-Status: GOOD ( 21.91 ) 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 Fri, Apr 09, 2021 at 05:18:45PM +0100, Mark Rutland wrote: > On Fri, Apr 09, 2021 at 03:32:47PM +0100, Mark Rutland wrote: > > Hi Vincenzo, > > > > On Fri, Apr 09, 2021 at 02:24:19PM +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 all the other flags > > > can be lost in the process. > > > > > > 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. > > I've dug into this a bit more, and as set_thread_flag() calls some > potentially-instrumented helpers I don't think this is safe after all > (as e.g. those might cause an EL1 exception and clobber the ESR/FAR/etc > before the EL0 exception handler reads it). > > Making that watertight is pretty hairy, as we either need to open-code > set_thread_flag() or go rework a load of core code. If we can use STSET > in the entry asm that'd be simpler, otherwise we'll need something more > involved. I hacked this up quickly: diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 9b4d629f7628..25efe83d68a4 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -1646,6 +1646,7 @@ config ARM64_AS_HAS_MTE config ARM64_MTE bool "Memory Tagging Extension support" default y + depends on ARM64_LSE_ATOMICS depends on ARM64_AS_HAS_MTE && ARM64_TAGGED_ADDR_ABI depends on AS_HAS_ARMV8_5 # Required for tag checking in the uaccess routines diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S index a45b4ebbfe7d..ad29892f2974 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -148,16 +148,18 @@ alternative_cb_end .endm /* Check for MTE asynchronous tag check faults */ - .macro check_mte_async_tcf, flgs, tmp + .macro check_mte_async_tcf, tmp, ti_flags #ifdef CONFIG_ARM64_MTE + .arch_extension lse alternative_if_not ARM64_MTE b 1f alternative_else_nop_endif mrs_s \tmp, SYS_TFSRE0_EL1 tbz \tmp, #SYS_TFSR_EL1_TF0_SHIFT, 1f /* Asynchronous TCF occurred for TTBR0 access, set the TI flag */ - orr \flgs, \flgs, #_TIF_MTE_ASYNC_FAULT - str \flgs, [tsk, #TSK_TI_FLAGS] + mov \tmp, #_TIF_MTE_ASYNC_FAULT + add \ti_flags, tsk, #TSK_TI_FLAGS + stset \tmp, [\ti_flags] msr_s SYS_TFSRE0_EL1, xzr 1: #endif @@ -244,7 +246,7 @@ alternative_else_nop_endif disable_step_tsk x19, x20 /* Check for asynchronous tag check faults in user space */ - check_mte_async_tcf x19, x22 + check_mte_async_tcf x22, x23 apply_ssbd 1, x22, x23 ptrauth_keys_install_kernel tsk, x20, x22, x23 -- Catalin _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel