From patchwork Thu Nov 9 13:58:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 742578 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:110f:b0:32d:baff:b0ca with SMTP id z15csp851860wrw; Thu, 9 Nov 2023 06:02:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IGbDiTaUDHQIFCnJnxuisqEM7r80DFip4KvZNERrm0VtsOEJrS6MwMldBcRwrbmnqezlsbE X-Received: by 2002:a05:6000:1843:b0:32f:7e96:b1a2 with SMTP id c3-20020a056000184300b0032f7e96b1a2mr6135381wri.33.1699538539107; Thu, 09 Nov 2023 06:02:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699538539; cv=none; d=google.com; s=arc-20160816; b=byZG8ngQ8Wuyv3g9zc/1OZyY+6WDjNvYxpaEADeqIWwrKVrcw9bwTRdhtgFo+tqZXT 32BJAOIsdqZPwhuZ9UI5omv1BH0puW0bf0JYcHYbRBOSLkAuEzZiKl797tVisqiMznUf eY06e11T9xpv0N2BhVdvSjzYoZCVWYccZQ0L3TMSe7poGZjOn/O7/tF8Yc0soxqHrVXF RM+ARnvLeZkJJ8ShelHeBqvRJsrejNMYoaoSREhTgYhKvELGdCm+vRoEO/EoIDXTjFT8 bouRXi39sN++jiqUpTjAmD1vv2Bu6XUVoieELnIDsGaDLIXwNJFWf/VU3meZSqit0DG0 QXaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=E8oXINCkBmsOEg0hOaK3vjiuc3+eYxJCP7wgiwLF22o=; fh=xJ1URYKcMN3TM0/XAv5v+aCN+5tIbzAdcfBx5UNgoLw=; b=b2dfzTjKo7W9txHcrLnN6/SJO+zm9xdqNJPdIjUX88wZ//KCx2mcNwBYBrq3xPI7/2 iaQT+mIFHOyktsxYxEtUGqTrEuL1OCxdfWez+MzmBHC4dXgWIbhauOJs6GN6Lna3saRq LuXWKo4U/E+9tg9uJ5uRwBP1hzFjKuj1INJmI2dEyW/W3979W1ghvwVv0XaXm4ddQYFH 0Mgh6xPw8JWUO6ircO8diShtc+TyzscQk7DOsIgHYgKSM2viW1Jy0ocGejSXS0Y066Wn bEhjiIkJPM+nv78at463O4nz24/Vlhs8l2GpPORx4/U77iE/lfm4TF9JZyuGKodocCtc zV2A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id b1-20020a5d4b81000000b0032320f3293esi5582102wrt.933.2023.11.09.06.02.19 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 09 Nov 2023 06:02:19 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r15ba-0000vM-AQ; Thu, 09 Nov 2023 09:01:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r15a3-0005ef-Mz; Thu, 09 Nov 2023 09:00:28 -0500 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r15Zl-0005Wu-Ir; Thu, 09 Nov 2023 09:00:19 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id E78BF31BC1; Thu, 9 Nov 2023 16:59:41 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id F2E77344FA; Thu, 9 Nov 2023 16:59:33 +0300 (MSK) Received: (nullmailer pid 1462788 invoked by uid 1000); Thu, 09 Nov 2023 13:59:33 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, Peter Maydell , Richard Henderson , Michael Tokarev Subject: [Stable-7.2.7 11/62] target/arm: Don't skip MTE checks for LDRT/STRT at EL0 Date: Thu, 9 Nov 2023 16:58:39 +0300 Message-Id: <20231109135933.1462615-11-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_HELO_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Peter Maydell The LDRT/STRT "unprivileged load/store" instructions behave like normal ones if executed at EL0. We handle this correctly for the load/store semantics, but get the MTE checking wrong. We always look at s->mte_active[is_unpriv] to see whether we should be doing MTE checks, but in hflags.c when we set the TB flags that will be used to fill the mte_active[] array we only set the MTE0_ACTIVE bit if UNPRIV is true (i.e. we are not at EL0). This means that a LDRT at EL0 will see s->mte_active[1] as 0, and will not do MTE checks even when MTE is enabled. To avoid the translate-time code having to do an explicit check on s->unpriv to see if it is OK to index into the mte_active[] array, duplicate MTE_ACTIVE into MTE0_ACTIVE when UNPRIV is false. (This isn't a very serious bug because generally nobody executes LDRT/STRT at EL0, because they have no use there.) Cc: qemu-stable@nongnu.org Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Message-id: 20230912140434.1333369-2-peter.maydell@linaro.org (cherry picked from commit 903dbefc2b6918c10d12d9aafa0168cee8d287c7) Signed-off-by: Michael Tokarev (Mjt: before v7.2.0-1636-g671efad16a this code was in target/arm/helper.c) diff --git a/target/arm/helper.c b/target/arm/helper.c index 22bc935242..a52ef3dfe4 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -11301,6 +11301,15 @@ static CPUARMTBFlags rebuild_hflags_a64(CPUARMState *env, int el, int fp_el, && !(env->pstate & PSTATE_TCO) && (sctlr & (el == 0 ? SCTLR_TCF0 : SCTLR_TCF))) { DP_TBFLAG_A64(flags, MTE_ACTIVE, 1); + if (!EX_TBFLAG_A64(flags, UNPRIV)) { + /* + * In non-unpriv contexts (eg EL0), unpriv load/stores + * act like normal ones; duplicate the MTE info to + * avoid translate-a64.c having to check UNPRIV to see + * whether it is OK to index into MTE_ACTIVE[]. + */ + DP_TBFLAG_A64(flags, MTE0_ACTIVE, 1); + } } } /* And again for unprivileged accesses, if required. */