From patchwork Wed Oct 4 08:01:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 729252 Delivered-To: patch@linaro.org Received: by 2002:a5d:4a4e:0:b0:31d:da82:a3b4 with SMTP id v14csp221436wrs; Wed, 4 Oct 2023 01:11:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHzXqT331NA9KKq/dgHc4wm12CT0j1dr+R6AAZ75A/eOwNWQyJ8D4e8Q2bYbZ7Jw6CC+3pu X-Received: by 2002:a05:6214:5585:b0:64d:254a:63dc with SMTP id mi5-20020a056214558500b0064d254a63dcmr1649741qvb.19.1696407119571; Wed, 04 Oct 2023 01:11:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696407119; cv=none; d=google.com; s=arc-20160816; b=H43hvV3gf7La0snmVEDALup381zD4/GXWZOchnY8kYHVbi72wvt/tKumpHUoNFmAwT /FvZj/JUEHjb37hhlYDYQwsTR1TYMfIsxP1yltTsp4j09ai0EAZDJvrFoz2It4DFkVTw tvSX3cy0Ky3AIkc90LAMOdXQXHTRMYbVw2u0QWek5NF4neaLOuAv9MVuTvcPAMLXME5n Anq6aw6V9f1mKc6+EN4+N2RvlIeWS1AD3JJO0aHCclp/d9f73HmdGzhB5KxQG56EJbLx 04JghurerWb1jYJvqaIDaH+IdCBmeOdNWZI+mYg5p+XKCNQcbC+1WVBtjLr8ySjHzRpN 9XwQ== 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=EWxsWOPYzdCN0md1pHqryXn+JJWcftwdi44zVlQ5nUY=; fh=xJ1URYKcMN3TM0/XAv5v+aCN+5tIbzAdcfBx5UNgoLw=; b=BQS8qVbw5LPUyz/2fz9KmHvrjHf+IJNUNjHt1uuc9z126j1br7ip1ZAH7ZOt3H9WPe G4oX/tR1+blFTQ+fjo+GDR24z8/W7oCS6uqfTSVLiamwdyC3PYAdBj+1MSqnYvVhb5EX A4Zd9LXDEFN5eq5rSomAXIP8sOeoueQgO2x8Ax5gGpHtIq/7pYLXmO1OPmUNyZoihP7f xWKpGjIlN6WtWiH1QUMlncuYf9S2Vr8Z/q1Q+fUVisl3HLev8X6c4bbsp/IcjC3kqnS0 5WRGc7NJb83B8ELNqqWP9P27QaQKj1zKAutU69ohgs+1JfOZZWHQvxC99h4mcmVE0MPs +R0Q== 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 n12-20020a0ce48c000000b00655dd255108si1223077qvl.375.2023.10.04.01.11.59 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 04 Oct 2023 01:11:59 -0700 (PDT) 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 1qnwsy-00054e-7Y; Wed, 04 Oct 2023 04:05:36 -0400 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 1qnwrI-00075f-Ov; Wed, 04 Oct 2023 04:03:53 -0400 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 1qnwrG-00005l-4v; Wed, 04 Oct 2023 04:03:51 -0400 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 6707E2759E; Wed, 4 Oct 2023 11:02:26 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id B80F72CBDA; Wed, 4 Oct 2023 11:02:25 +0300 (MSK) Received: (nullmailer pid 2702810 invoked by uid 1000); Wed, 04 Oct 2023 08:02:21 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, Peter Maydell , Richard Henderson , Michael Tokarev Subject: [Stable-8.1.2 20/45] target/arm: Don't skip MTE checks for LDRT/STRT at EL0 Date: Wed, 4 Oct 2023 11:01:41 +0300 Message-Id: <20231004080221.2702636-20-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_HELO_NONE=0.001, SPF_PASS=-0.001 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 diff --git a/target/arm/tcg/hflags.c b/target/arm/tcg/hflags.c index 616c5fa723..ea642384f5 100644 --- a/target/arm/tcg/hflags.c +++ b/target/arm/tcg/hflags.c @@ -306,6 +306,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. */