From patchwork Thu Feb 21 18:57:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 158930 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp832524jaa; Thu, 21 Feb 2019 10:58:42 -0800 (PST) X-Google-Smtp-Source: AHgI3IaPJQVBR8rRCu5aPIIq2ifx76zUr3HyJyLkpm1VyV0wQJAdRkkV4lozQPkwg+e8yOVly4MA X-Received: by 2002:a25:4189:: with SMTP id o131mr19625yba.348.1550775522021; Thu, 21 Feb 2019 10:58:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550775522; cv=none; d=google.com; s=arc-20160816; b=N+iiIUfvmzmoRXemXRDsZsH1Sa/yqMnFajssNWcyJP18vHNAaqPANgpMugohPgTobx 1pk/pK3XjwiyBp1PNn/7qeJFAnLQ8U+Eo43nzC15BBHx21Wm8hy6z1no9S/LF98fL/+e pH0xsFXRU9oJSHAD2kZtTx3Ozs6EX0PI7KJppJEZIuI3v44apYrLN0f2Wd8KbZJxShC6 5N2JGfe46fZ6Y9urgMbJL6wa6bagZqRNYvDqQA7LE0FHjxqgH5NHR0H1YMHzBj76phDb bASD7HQLFb2lv8uTtrUSYXMHGQ6C0H3Z+X+gYEDB4484TYh2/pRE+8p3jPkcefibfeg1 c3rw== 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:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=xUAIzDpNWv8YnIShod0ImX2EP9PZydu99S3FvI92H14=; b=I+Z8P/Dbo5sHo8+O3FGOVRYXKyL0E5Fc9C1FRi4ULHs2IckA34k99jwcCwxjuDR349 W2u67p7LAK8yChvy/ickrX/0o05OlUJaIwhW3NrCZOt+iFQqbk9xUVKFgsqjzl/GEglj 2CYPuF4BcUVl/qTO5Hu9FmrZyNu46r/n1TuQRbLc7CLwIf46XsqL6qUO8aepZkmQ4V7m o/pBmSel9F6Epl/1Yr/LAGpEMF7B1pREBotEj6s8BSEfwM79GkrBYTXwP8/OpLmynxPe pMlqVs1J5KmAVeHN2hkfPPhqkKsSbn2mBDwNvR+8mDb6n/GVNQ5gSMkET2LHFsKHyXXu X4YQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=OZl0YjBv; 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=fail (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 f38si13587432ybi.388.2019.02.21.10.58.41 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 21 Feb 2019 10:58:42 -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; dkim=fail header.i=@linaro.org header.s=google header.b=OZl0YjBv; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:36867 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwtYP-0000Fd-FO for patch@linaro.org; Thu, 21 Feb 2019 13:58:41 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52027) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwtXj-0008NC-44 for qemu-devel@nongnu.org; Thu, 21 Feb 2019 13:58:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gwtXg-0007Mx-Eh for qemu-devel@nongnu.org; Thu, 21 Feb 2019 13:57:58 -0500 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]:35614) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gwtXV-0007Gl-LK for qemu-devel@nongnu.org; Thu, 21 Feb 2019 13:57:49 -0500 Received: by mail-wm1-x334.google.com with SMTP id y15so10336961wma.0 for ; Thu, 21 Feb 2019 10:57:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=xUAIzDpNWv8YnIShod0ImX2EP9PZydu99S3FvI92H14=; b=OZl0YjBvOAQF3KG4MZfX66qbuojlhuOXl/CFTrwNXKI9o704ydaYBoAyr78J7cqQap yqvwflfns70eDuFKxdJGske/+buqezPdtFJt/q+yk1eJyi75ZA++lv5pVMOcz7mOi0vh kOxlDkSdmnpaHCk9n7+3n48hzmmsHuWehMD0lG9sdQvce+s2sjYbkMK34DUPdi/s7wiF aEAgF8mLCHImfLVEz63I6ZHWqMxi2Nx9Y42WBso2g2LOEwyomez1x/qtmTSjIHFnkG4I Y0plNVssbiXQ35qrupItiMmcaRljHohERN+KCH/B2qeZPmQ/odzCctdtyvVtAJQ0gNHm V+2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xUAIzDpNWv8YnIShod0ImX2EP9PZydu99S3FvI92H14=; b=cMP5OJ6ZYdL/iWZVjQiWk17RZerd8rBk3DEQYR7YS2NKwZpb8vFaWk60qvsxpPRTPj ge53CNv1x1ntfo7PMvNI4ouATb/0CN8bhTl3rVZqDsZ6PHDCs3yTmcRGsVFlBdgc4Dvc N+PjtNEflSzhqFYLGeUhDa1WGaYKsqqd1ijuJ3hEfjFVbGu47rrCitCL1B/S3dF7Mi1T 89niI0bEv2a6UDF8GrUdUvaOTftIVZHlC9cb87MJuoUpyvlbPZPvmthhPkmRvbNh85xH 1m3pErJYCw93HkGL1VEwnWYan4lOROIkGEOx+V8YL8+JnMg2OrAYSwXxiLMGLuenQeHp taiA== X-Gm-Message-State: AHQUAua3V+ihSK5ETp8WC5GdZIwY1wStN1vpnl99xe73Uv8kaCm9Iuy5 uwz81hfJHbFgtcBdBHXlWESqPgq7hMw= X-Received: by 2002:a1c:3b06:: with SMTP id i6mr11298854wma.55.1550775464293; Thu, 21 Feb 2019 10:57:44 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id c18sm29065085wre.32.2019.02.21.10.57.43 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Feb 2019 10:57:43 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Date: Thu, 21 Feb 2019 18:57:20 +0000 Message-Id: <20190221185739.25362-3-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190221185739.25362-1-peter.maydell@linaro.org> References: <20190221185739.25362-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::334 Subject: [Qemu-devel] [PULL 02/21] 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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 Message-id: 20190214113408.10214-1-peter.maydell@linaro.org --- target/arm/helper.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) -- 2.20.1 diff --git a/target/arm/helper.c b/target/arm/helper.c index a018eb23fe2..fe054897c78 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -11387,9 +11387,11 @@ static bool pmsav8_mpu_lookup(CPUARMState *env, uint32_t address, hit = true; } else if (m_is_ppb_region(env, address)) { hit = true; - } else if (pmsav7_use_background_region(cpu, mmu_idx, is_user)) { - hit = true; } else { + if (pmsav7_use_background_region(cpu, mmu_idx, is_user)) { + hit = true; + } + for (n = (int)cpu->pmsav7_dregion - 1; n >= 0; n--) { /* region search */ /* Note that the base address is bits [31:5] from the register @@ -11427,7 +11429,7 @@ static bool pmsav8_mpu_lookup(CPUARMState *env, uint32_t address, *is_subpage = true; } - if (hit) { + if (matchregion != -1) { /* Multiple regions match -- always a failure (unlike * PMSAv7 where highest-numbered-region wins) */