From nobody Sat Nov 8 06:04:33 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1550144145254479.87472378761254; Thu, 14 Feb 2019 03:35:45 -0800 (PST) Received: from localhost ([127.0.0.1]:46991 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1guFIs-0004dy-Ak for importer@patchew.org; Thu, 14 Feb 2019 06:35:42 -0500 Received: from eggs.gnu.org ([209.51.188.92]:33961) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1guFHQ-0003wY-UT for qemu-devel@nongnu.org; Thu, 14 Feb 2019 06:34:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1guFHQ-0008Mb-4x for qemu-devel@nongnu.org; Thu, 14 Feb 2019 06:34:12 -0500 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:36501) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1guFHP-0008L7-SV for qemu-devel@nongnu.org; Thu, 14 Feb 2019 06:34:12 -0500 Received: by mail-wr1-x443.google.com with SMTP id o17so6107253wrw.3 for ; Thu, 14 Feb 2019 03:34:11 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id b18sm2195399wrr.43.2019.02.14.03.34.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Feb 2019 03:34:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=iX1skGwvvJGFENnn/ez6jeDMPRxcBgS6Sl8tAEAfTag=; b=hKlEfJ2IWHwv6qAiwTeEG/ze9UIi6QeVZWl9oY2tsuGSmTHBK6rEXmuzhFmMOdI10/ 1fvF1NVvKxiTJbud9DZ7p4y3sWyOY6ILQko+GqK8FnHdFUVH48k/pz+BA7QP9ejlXKIK lk9k6/vpdRkODiVCbFXjNHPax4uA8cdk48JdS1XQY64u9b/WmaWEfO6h771m213ZBoRA 7n1imDI0ubiaLeVSoYeBcdNYvFs4eqSjPSEFCmiokvvAKgycxrsgKdEdiEqSpdzh8HVm FN0wnJbh/3cjIgcAlFdSTEjZdRkYTXep401K5YZJZn1k6iuo4Xj62EdoI8bxOexA7OwC GEDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=iX1skGwvvJGFENnn/ez6jeDMPRxcBgS6Sl8tAEAfTag=; b=lIqHwmWGSJgGOtTFUz/reFUslSivLtH8+D/n5uarnA0CzKOs/V0Ryrluj8VnOH8MuL 9DWMfcZo425eHR6lgtIyg/miRyYzWFlTp/qjpoz8ff9nZAHIhXSHur1tQQPxfqI4BZr1 G05rXED4QdtfaGxOS3G4djLxsr1i1Z+ExIxwbFMuH3PzOEIFP6qFwO+XCh3NVmY0OipB SoQtTyyitV/9BX8TMIUwlBtZ9DYXHk9LUCcZ+EzPJ70ybsTuOWsVIDiLxSrDUgfD8eUP UbRixbI1nTzfg08QFUh80QIEHNKdGgAK62ZLbAPo1UYS8wZHj15l93jigwfKrSzKgXjr UDcQ== X-Gm-Message-State: AHQUAubEb8kBeyfgg9LmvFHk2wiITsdVTrlQkoR9QPfM3DRbh2eUolp0 /UCR+yocUaVFJWHhFY6FD6R9QA== X-Google-Smtp-Source: AHgI3IZzjmgUezPuD4gHeNpqKFDOVh3oJd2jAbZblsLLE06L1wg5xjVbktY4fEW3BvOeTcXdmCCtCg== X-Received: by 2002:adf:d08e:: with SMTP id y14mr2474227wrh.306.1550144050205; Thu, 14 Feb 2019 03:34:10 -0800 (PST) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Date: Thu, 14 Feb 2019 11:34:08 +0000 Message-Id: <20190214113408.10214-1-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::443 Subject: [Qemu-devel] [PATCH] target/arm: v8M MPU should use background region as default, not always X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: patches@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The "background region" for a v8M MPU is a default which will be used (if enabled, and if the access is privileged) if the access does not match any specific MPU region. We were incorrectly using it always (by putting the condition at the wrong nesting level). This meant that we would always return the default background permissions rather than the correct permissions for a specific region, and also that we would not return the right information in response to a TT instruction. Move the check for the background region to the same place in the logic as the equivalent v8M MPUCheck() pseudocode puts it. This in turn means we must adjust the condition we use to detect matches in multiple regions to avoid false-positives. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson --- I found this because the incorrect TT response eventually resulted in the Zephyr RTOS writing an invalid region number back to the NVIC and tripping the guest_errors logging. --- target/arm/helper.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/target/arm/helper.c b/target/arm/helper.c index 0f5eb3229b7..d3e15585c25 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -11291,9 +11291,11 @@ static bool pmsav8_mpu_lookup(CPUARMState *env, ui= nt32_t address, hit =3D true; } else if (m_is_ppb_region(env, address)) { hit =3D true; - } else if (pmsav7_use_background_region(cpu, mmu_idx, is_user)) { - hit =3D true; } else { + if (pmsav7_use_background_region(cpu, mmu_idx, is_user)) { + hit =3D true; + } + for (n =3D (int)cpu->pmsav7_dregion - 1; n >=3D 0; n--) { /* region search */ /* Note that the base address is bits [31:5] from the register @@ -11331,7 +11333,7 @@ static bool pmsav8_mpu_lookup(CPUARMState *env, uin= t32_t address, *is_subpage =3D true; } =20 - if (hit) { + if (matchregion !=3D -1) { /* Multiple regions match -- always a failure (unlike * PMSAv7 where highest-numbered-region wins) */ --=20 2.20.1