From patchwork Fri Apr 14 16:04:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 673132 Delivered-To: patch@linaro.org Received: by 2002:adf:fcce:0:0:0:0:0 with SMTP id f14csp262171wrs; Fri, 14 Apr 2023 09:05:27 -0700 (PDT) X-Google-Smtp-Source: AKy350b8mucTebCKvMsA5UKRP7dcZE9YWv5myEmJR62WzLnwPDl0mnjshtSevY40nspqkr5DgGjW X-Received: by 2002:a05:6214:2607:b0:5c2:a8b0:d71a with SMTP id gu7-20020a056214260700b005c2a8b0d71amr5157888qvb.43.1681488327262; Fri, 14 Apr 2023 09:05:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681488327; cv=none; d=google.com; s=arc-20160816; b=gOjVLyRQWrIr2VA/B9lHyTqdBl+3Wl+BmDlF8wSLdHOsYk3wfOVgm/TCE5pLCm4h19 LfC4tyDjR+IpBh4bZZGPBvEioJud3QkgxADCBr3gIyD6Xw0/O9tU0mHb8WWvpyoPNJf5 yR/rmrZEqJnf9hgt7G60Id1Dr2/7VEDUfRbaOgHTJAC65mrXZ/LPe6HZunY87Sshn2pa GufIKepjFeMSjXQneJphQkRYVqTuzsGg8qLaMPNoohi4TwGECZL9eLh8jnr03V5EfAR9 oWIqtuyu6MwQIUCGO2eD4U78KAqjdN5jL8WbFrFL+kGDoy5OjTFVTyGgmyUmdlUUmowA vfaQ== 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:dkim-signature; bh=jUHq0yTT6mZpyW8ymPG55BvWQqRfjylp1jFh1uUnshs=; b=xOCBHlkkyjQMk7jlZF8Bg7edUPyeBTeTqNITEZcTrgPig3H7fo2Eb019O6UjbR0G0a u41a1ilpFiiT948WHy7lCjjzKagTbSdLesX2tEfR5awYXDTL+kQ6uC0bggX4ut/B4Yyd JpppDNYeIcn3wIQM8zQ0AbN710fe2+c3EIcIfGL3C37Bfbc1n29OHk4G3hXpN+b2pW4q 7oiY3UXhRTjABEkTte6sbY/upjshXKs+xZgKNEf0fRtiOwRJ/HY+GM2wyHcSqUy1o+46 dVESbNiRNaynPz8n/S0j25g7d/ne5J7PNS7mSNhUW7PErvTeIcn1hd3RZ+o1qTgz9CD6 AZkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Z86cmet/"; 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 iy4-20020a0562140f6400b0056ebc773032si2904739qvb.73.2023.04.14.09.05.27 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 14 Apr 2023 09:05:27 -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="Z86cmet/"; 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 1pnLuX-0006IZ-3E; Fri, 14 Apr 2023 12:04:29 -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 1pnLuU-0006Gn-5V for qemu-devel@nongnu.org; Fri, 14 Apr 2023 12:04:26 -0400 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pnLuN-0007uA-Fr for qemu-devel@nongnu.org; Fri, 14 Apr 2023 12:04:25 -0400 Received: by mail-wm1-x333.google.com with SMTP id l10-20020a05600c1d0a00b003f04bd3691eso21024842wms.5 for ; Fri, 14 Apr 2023 09:04:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1681488255; x=1684080255; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jUHq0yTT6mZpyW8ymPG55BvWQqRfjylp1jFh1uUnshs=; b=Z86cmet/oFJLig9vLG0ILm1/FNhYYRfu7A35GrX/shAqhvqcdzEqz52CrVEekTAwIL S7vqSxDS293h99upQmb/0f0z6oJfVc/L2jmw7XvlnkJnVpL9w2xY5SdzsJU7oHtBbQ/f 0ZmHvFaV/D3jn0wRqc1KzHMbywPywnVPFpPM2PauCtRe2tO/TfLoMMEGI8jsOVfXGw16 lFkYf6rCmx2ERV9/xNB33KmSoSoxio1GY1SD+s0S6ceGCEVAcrKdgq0WyRW0+DMWUu6l bkYVsLJrMyVNAJDomEXoHZ0z4matpM6MIIVth4qaVD8kCwVQDDdJGgPIXmYG9QknG3fs ABKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681488255; x=1684080255; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jUHq0yTT6mZpyW8ymPG55BvWQqRfjylp1jFh1uUnshs=; b=LENF2SLkge35pyvyn27lxBrxHk4GXvQc2vKzqVnKsC7YeDhVAE4v1InXPI1FFK/HgY DbPYcu8sGLufLH8UyDFy2zz74FwQnIAaTjdIdJ3pV3kJdX0O1OU9WzuS6XU1hkdywyfV QuYWowjZlFO00DXun6Ts8EVKpXUUTeKxLTLykIy8wzyjv3KKGyNjA3V1iIdEN2wy5Z5A fZSZwYok6fqduEuu4a2kW6d1dsd1/2VIsNILHP+xcn33q6tljYVb7WOdki3Qfq7CeXry 90rSX4wnlJO1EBzw8iManQRUZOkPs3MBobUJdPjB/UItlILzBZ0jhYeDwp9rYETwE6XE lGBA== X-Gm-Message-State: AAQBX9d2fsueOUoWN9iPyl/JvZxxvFcOj0QWAR0kGQf203n8bO7cA5De aYWHaeSeTrf9sHrOgfCJAKPB2w== X-Received: by 2002:a05:600c:2289:b0:3ee:6161:7d98 with SMTP id 9-20020a05600c228900b003ee61617d98mr4732437wmf.16.1681488255598; Fri, 14 Apr 2023 09:04:15 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id 8-20020a05600c22c800b003ef71d541cbsm4673752wmg.1.2023.04.14.09.04.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Apr 2023 09:04:15 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Cc: Richard Henderson Subject: [PATCH 1/3] target/arm: Don't allow stage 2 page table walks to downgrade to NS Date: Fri, 14 Apr 2023 17:04:11 +0100 Message-Id: <20230414160413.549801-2-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230414160413.549801-1-peter.maydell@linaro.org> References: <20230414160413.549801-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::333; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x333.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, T_SCC_BODY_TEXT_LINE=-0.01 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 Bit 63 in a Table descriptor is only the NSTable bit for stage 1 translations; in stage 2 it is RES0. We were incorrectly looking at it all the time. This causes problems if: * the stage 2 table descriptor was incorrectly setting the RES0 bit * we are doing a stage 2 translation in Secure address space for a NonSecure stage 1 regime -- in this case we would incorrectly do an immediate downgrade to NonSecure A bug elsewhere in the code currently prevents us from getting to the second situation, but when we fix that it will be possible. Cc: qemu-stable@nongnu.org Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson --- target/arm/ptw.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/target/arm/ptw.c b/target/arm/ptw.c index 6d72950a795..06865227642 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -1403,17 +1403,18 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1Translate *ptw, descaddrmask &= ~indexmask_grainsize; /* - * Secure accesses start with the page table in secure memory and + * Secure stage 1 accesses start with the page table in secure memory and * can be downgraded to non-secure at any step. Non-secure accesses * remain non-secure. We implement this by just ORing in the NSTable/NS * bits at each step. + * Stage 2 never gets this kind of downgrade. */ tableattrs = is_secure ? 0 : (1 << 4); next_level: descaddr |= (address >> (stride * (4 - level))) & indexmask; descaddr &= ~7ULL; - nstable = extract32(tableattrs, 4, 1); + nstable = !regime_is_stage2(mmu_idx) && extract32(tableattrs, 4, 1); if (nstable) { /* * Stage2_S -> Stage2 or Phys_S -> Phys_NS