From patchwork Tue Sep 12 14:04:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 721768 Delivered-To: patch@linaro.org Received: by 2002:adf:f64d:0:b0:31d:da82:a3b4 with SMTP id x13csp1664594wrp; Tue, 12 Sep 2023 07:06:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF1slc+PVUb35eMc1Fpzmyomp570Jlw4SOWBIkgxZvo4qiDqKvc4yh5FKWw/C309KzWlvgT X-Received: by 2002:a05:6102:6d3:b0:450:cf23:b6 with SMTP id m19-20020a05610206d300b00450cf2300b6mr5774669vsg.21.1694527588622; Tue, 12 Sep 2023 07:06:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694527588; cv=none; d=google.com; s=arc-20160816; b=OAxLmPU1DyAIqSJD2LaF2/UKO31DIL0VgbaLtFlxnIaXfQcC4CO1M9RVYSIz/uRCZx 5lufIlQwm905i7uKsCnnAi1LNE+ULrNk/qRAVF8ehWOun56bOnGBHRcGcoYkarhWmHI7 A5tnaUnFifoXUviHEP8xEidzuO+atzw6vyxgEjoK0tKwFza8TqDJrgv1pQAArHo36Ec8 piHvUvVk0w2vq0XlcozVzL9lfIXr+mkB1np98w6zCHbEYZBq9TkBf5uvVgs0CjiTxWG7 qJxiqq2+Z5F4ZTXLgt4U5enIovtYdArtedp0QUO+YQFuDBIHXbq90YFUosj3NUFD6sCs QyYw== 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:to:from :dkim-signature; bh=AZ7z+PF4zRsdie2W5wNUk9pY8AcE3Vlvunka/Km+EXQ=; fh=H2AmuqulvQE+T5zu97MCEUC3z9wF9NssS7895NhR/+c=; b=ROvism4Vy6eFYBV1BlDriAbKFCNJ2JCUXx1R63NYFVzh5wHGx0EBgqKeI8SI3jCNqe i6QwEAob7jCFaIYOHrVGXtW9E5t7LdFKa8TUFueP9gkFF3MlwrFRxE76x4UJp5LEh2cP O/YKTK7dQL25pPgx2Re1YccWi2fALLUcgrXOO5wojeS4e68rqoE8WznF0UotQUkx0LQ7 HchnXzlUza6JPik3N5WZudcB7TQay/74pxS0nYGO8y8lUAa1tbjiRL2nhWWscqaC6aJS ZlrlGriwFCNV3cYRBg0kuGd0fgqh9u4otpTdGQHCTj4LKpYhdqU67jbGbsikMVagJ0uJ R3rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=k50PTPYc; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id w1-20020a67e241000000b0045074173b71si779730vse.239.2023.09.12.07.06.28 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 12 Sep 2023 07:06:28 -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; dkim=pass header.i=@linaro.org header.s=google header.b=k50PTPYc; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qg40s-0008FC-DM; Tue, 12 Sep 2023 10:05:12 -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 1qg40a-000871-8v for qemu-devel@nongnu.org; Tue, 12 Sep 2023 10:04:54 -0400 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qg40N-0003pb-Nm for qemu-devel@nongnu.org; Tue, 12 Sep 2023 10:04:44 -0400 Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-31f915c3c42so3143133f8f.0 for ; Tue, 12 Sep 2023 07:04:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694527476; x=1695132276; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=AZ7z+PF4zRsdie2W5wNUk9pY8AcE3Vlvunka/Km+EXQ=; b=k50PTPYcziYiy1SUZB5An8TkPyoepEGaY393+MoDPpqFBdqJYoUQSA4/N+NPmF9oe/ c8w1hNbVPBmhF1iTKSl4AfwT+a+2RpiTcVHMi6YRTQuXs3WpPnyi+aAsHIqlxXqW3kPq b6e75/GSrgRnMYb4dTmM0/n+N2AxWwEJ0OyLXq3eBc1ChlPDkg+F5ziRvDmLYpsbJCz2 guQ4ZXs94jmFRWtAGXZAH4PILfJSqlAf7FR6ESO/duPWRhxjLb0LWVEmjZdsefRYfT3e 5g0vP+/Qd7UzFR+USe+TF2fWvOEcjy4bvf54J3IcIFWQVPD2dkZc864bKpw00LC1tSBH PA6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694527476; x=1695132276; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AZ7z+PF4zRsdie2W5wNUk9pY8AcE3Vlvunka/Km+EXQ=; b=JIfWWZ6KTCT0ALs7Oz9pbl3FQAwFKVIty9Up462084mXnPpW9ogRdq7l782D46i8z2 sMx+tK0jANi2dhOmomuDwi7PxshDTNffmZ6oGM2k950BeYJS5ZAUm3JO77SIVQqco4mJ 3Elc8NL4m3wbx4P1ze3ivaaYzsXDidarqB7dTBtcK4SmTFrEqrE6DShgAqF6KpOHW6P/ 11ZW4tl/yU9RGr+CszompLyVGF2mpe6rB+tt62sR3r0Y+FYg4w90+SHoSQr4DjSVqeZW efYbCaQqM26ijgOiUz33GpiDovQvnUzv9fVEE+OLjKhL5MwRIgS+l0+s+g+7tFEiyxTa Xbkg== X-Gm-Message-State: AOJu0Yysi/QUWcwYjvl8kltXGytdqLJh5E0AyX2sEymEaVhwS2fDoCcZ 5snKVCvENB/efDMc2BHmqJSl/w== X-Received: by 2002:a5d:5103:0:b0:315:8f4f:81b8 with SMTP id s3-20020a5d5103000000b003158f4f81b8mr10928695wrt.50.1694527476476; Tue, 12 Sep 2023 07:04:36 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id r3-20020a5d4983000000b00317ab75748bsm12892672wrq.49.2023.09.12.07.04.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 07:04:36 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH v2 01/12] target/arm: Don't skip MTE checks for LDRT/STRT at EL0 Date: Tue, 12 Sep 2023 15:04:23 +0100 Message-Id: <20230912140434.1333369-2-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230912140434.1333369-1-peter.maydell@linaro.org> References: <20230912140434.1333369-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::429; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x429.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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 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 --- target/arm/tcg/hflags.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/target/arm/tcg/hflags.c b/target/arm/tcg/hflags.c index 616c5fa7237..ea642384f5a 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. */