Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2577491pxb; Mon, 19 Apr 2021 08:48:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwVAmznEk9I1GNgDXiztGp9Q69i3eideeEcgy4hP/n8xXzk0j/Af9th56WgRbp7fIM0RRq4 X-Received: by 2002:a17:902:848a:b029:e9:914b:7421 with SMTP id c10-20020a170902848ab02900e9914b7421mr23875627plo.78.1618847316544; Mon, 19 Apr 2021 08:48:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618847316; cv=none; d=google.com; s=arc-20160816; b=od7DiBfZ0F6sL145aCVIAoJpN5WkpVn4aUkmY3GhEut3rD0RG+8otfWteIUqYftScn LT7ym9HY7m8z3J+eVYjLsu/NQ3bPmIS4T97RF/XuQEUEcX+e+iz4OtpZUO7+Jyd07Fk3 w/vnsSouqLoV5+B7MSAyrrG9guroRebEHwWNHftiLoL15UJMXkgK7vcWt1Vofey9fvce hEs9yogGwbqmwDWdVgcbDswcJYzeKBNiETNi+os6e8GnuMHgfFCvZQ5j5L/kCcupZoO+ d2lh175Nn+MznEgso01HusUEvLpUXIRe+7NphBzOrHBZVMYLv/KGevJjLo5AtYIvvu2v AhSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=zNBOEQyKfF+ilX+migieMUe+/ODQRaIv8FFNUc/uCwg=; b=CW5VKCTegUFiikdQFjUDuBsA/WViohESCYx7wCqQSUg6Aks1BSvhgmg9U6MCSbushh b2LMGcQ29ZChfT8dJHVZkYNEdGwellIZC7xKvl4jMxnm2yxczQUESRIv5aBP3KyrWq+E QQkctoGk41sFP9excWIgZlFSt3rJbXEyuHM/ERTuwSnfOQuk+WOx6szGt+rpTVL8Wxce BIv89fXkQmTWRQu+l8PTATmvxSFjOslgn3XkU13o60OkoX64I2ggo/F4dkpWs/+CZLkT sbHO7BwcepbDLFYFBcKi+9xZQBH3apgMjFlsy2rfJRRVUPfQUnActUXwVbHriROMwWW0 c4UA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=J6U8tzHq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a18si13129848pfh.317.2021.04.19.08.48.23; Mon, 19 Apr 2021 08:48:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=J6U8tzHq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242946AbhDSNaV (ORCPT + 99 others); Mon, 19 Apr 2021 09:30:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:54556 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240540AbhDSNVG (ORCPT ); Mon, 19 Apr 2021 09:21:06 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C853F613FF; Mon, 19 Apr 2021 13:17:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1618838261; bh=g8h7ByGjrii3dSq3b5pPuTTj3qo48ZbkJFgEQW/uC9I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J6U8tzHqmc9vYKH4kfPR3MkgkmnExlvmcf++kRzkDd+ncrzEAYDGTeyQWFbmsgszy nI8O0KUHgavWuWNFRrArlycqNotmeb2rIXmD0JBLXNGT3qpDlwXX1xmeQUPv9aDTMJ CKxvBT0Hoy5rle26RkbygRHaUnL5opwWUSI78B5w= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Catalin Marinas , Will Deacon , Vincenzo Frascino , Mark Rutland Subject: [PATCH 5.10 100/103] arm64: mte: Ensure TIF_MTE_ASYNC_FAULT is set atomically Date: Mon, 19 Apr 2021 15:06:51 +0200 Message-Id: <20210419130531.214757195@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210419130527.791982064@linuxfoundation.org> References: <20210419130527.791982064@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Catalin Marinas commit 2decad92f4731fac9755a083fcfefa66edb7d67d upstream. The entry from EL0 code checks the TFSRE0_EL1 register for any asynchronous tag check faults in user space and sets the TIF_MTE_ASYNC_FAULT flag. This is not done atomically, potentially racing with another CPU calling set_tsk_thread_flag(). Replace the non-atomic ORR+STR with an STSET instruction. While STSET requires ARMv8.1 and an assembler that understands LSE atomics, the MTE feature is part of ARMv8.5 and already requires an updated assembler. Signed-off-by: Catalin Marinas Fixes: 637ec831ea4f ("arm64: mte: Handle synchronous and asynchronous tag check faults") Cc: # 5.10.x Reported-by: Will Deacon Cc: Will Deacon Cc: Vincenzo Frascino Cc: Mark Rutland Link: https://lore.kernel.org/r/20210409173710.18582-1-catalin.marinas@arm.com Signed-off-by: Will Deacon Signed-off-by: Greg Kroah-Hartman --- arch/arm64/Kconfig | 6 +++++- arch/arm64/kernel/entry.S | 10 ++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -1390,10 +1390,13 @@ config ARM64_PAN The feature is detected at runtime, and will remain as a 'nop' instruction if the cpu does not implement the feature. +config AS_HAS_LSE_ATOMICS + def_bool $(as-instr,.arch_extension lse) + config ARM64_LSE_ATOMICS bool default ARM64_USE_LSE_ATOMICS - depends on $(as-instr,.arch_extension lse) + depends on AS_HAS_LSE_ATOMICS config ARM64_USE_LSE_ATOMICS bool "Atomic instructions" @@ -1667,6 +1670,7 @@ config ARM64_MTE bool "Memory Tagging Extension support" default y depends on ARM64_AS_HAS_MTE && ARM64_TAGGED_ADDR_ABI + depends on AS_HAS_LSE_ATOMICS select ARCH_USES_HIGH_VMA_FLAGS help Memory Tagging (part of the ARMv8.5 Extensions) provides --- 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 @@ -207,7 +209,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