From patchwork Fri May 12 15:34:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 681199 Delivered-To: patch@linaro.org Received: by 2002:a5d:4a41:0:0:0:0:0 with SMTP id v1csp4022538wrs; Fri, 12 May 2023 08:37:08 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6FbjioAc7cAm0/UmD8g3eTXaq3fRf6JEXa/8XIptok0ApDEOj6vzK7vGoI7DuvGehmZnVb X-Received: by 2002:a67:ce13:0:b0:42e:5597:b60c with SMTP id s19-20020a67ce13000000b0042e5597b60cmr10085042vsl.2.1683905828784; Fri, 12 May 2023 08:37:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683905828; cv=none; d=google.com; s=arc-20160816; b=Bwt1LZvaEGO+UcgSL4bW/pc1YB9LlAXvDJhPcpxGooxP2zlggVD9/r7fGXO4BIDltf VrlQaQYzQUI5F0Y8nDKdDESA2L97V5YXAo2KnNYqMnFv5LtC/49CegRdaXV5sWXl8SSG TpkK2qUZWZeXbt+G49I7j+kzCozVVjfdwyrnzEPwG3Yd2Ui5d0P0lbOTQqHeduerRRvA 1ggdvO16kk+f0KBuH9tP7hRKtqi2guv1CtATKUn7BH6HAxR2YNSZBPItDeAJqMcpnSqO EqkQIiAaY/ZKrRbgnlqxQKug/yY05T+HY7TRTeK1bpOqV7UDEEb7B4QJAryjBXtUEIbj 6iMg== 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=kyd9YD67afENN/WZ4WK9/2k+BPiSbgkUwINKrCywvQA=; b=xLy6khEqzGl5VfAA4HHswmduPR5YzveIOHOVPX1w03mz2pf86i9CnJtJFtdHKr3s5a bGnrCLnspAwQtgdM0F7zcjW4g6p5ES6JhqvDbMC0jPmGte+Uf6aHjaNEd/p4o0Rm/wdG vZNJQmfv0fhRO2ku+3ZsCcjFctgLewQnXm3T0NGw/WuvsK3O9ne2uSodzg8SAo5GNHnH KPtTWMj2bYrur6UgOm+qCbQWRN5e5Z203S1tUdEQ8nuK5SmJl87YR3/FGTHCG/gwzvSo IgpBcxmfchcx1GlMLsojRMcexGKprxFxVv/PhfqsTZ7Dack0wLD1ZISX3GxamT/iOdpF xh8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=H3qpNy6h; 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 x10-20020ae9e90a000000b0074a6c2570d1si4841573qkf.245.2023.05.12.08.37.08 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 12 May 2023 08:37:08 -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=H3qpNy6h; 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 1pxUmx-0003JD-F0; Fri, 12 May 2023 11:34:35 -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 1pxUms-0003Gt-BG for qemu-devel@nongnu.org; Fri, 12 May 2023 11:34:32 -0400 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pxUmq-00060D-7I for qemu-devel@nongnu.org; Fri, 12 May 2023 11:34:29 -0400 Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-3062db220a3so6639294f8f.0 for ; Fri, 12 May 2023 08:34:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1683905666; x=1686497666; 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=kyd9YD67afENN/WZ4WK9/2k+BPiSbgkUwINKrCywvQA=; b=H3qpNy6hXN04uU2348n0hetl6MGGNPcOTXmMYiTpcg6t5LPAiZCh2RLYootv7VmPEq cmaMF0jazu4dhlVAfXM2DnI7x4r4UWoqn8IOlIXO73qFK45xs95/+R0d2zoYqFr747R8 ma5pM4BHmcUKudTds7uVfwPmgafM4PREr87Oqd3LSdwPc8qImHMcTU6Y652FfBYKXsk7 tnxMmI42JCeilrwc6xg0ttVyT7Wb/NhNUrIgEhOfxZijogzuXFciP/LqjeYY7wCTe8IO Gv4Bp8yIFiPBx2iBGPNu7p3LPwDKT1KREibfUMn8o5RvhMjat8CD5YEIk10PtMvqmdic YAOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683905666; x=1686497666; 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=kyd9YD67afENN/WZ4WK9/2k+BPiSbgkUwINKrCywvQA=; b=Teg33hzb4l9TcLrdAWAFPiaSqDWGYF4t/TCh/sPTpTl1lxXwOYrodCJsPbmqeyS48R sljISkLxL75lRI5G1My4mDABGvAV9rTMs7CusLMEWr5RArVtgO62UtPEaK5eg+boC/tH 8D3NeLzHK7GkmlOwCuyZiRTXnJyT3U8xdOXCgJ+aO38ONlA8u0a1dBqAWwzUfVqdxx3k YTyWMCE3+7/EG8v2daLO5YO/QJFJNxJsCnTOTR+g2+FN48VRunelPx5tKc4hdDFBf5MB naQy2b5uUnCX2FElO2LBs809sZ8J7xEi7pFD4lfMfpDIn/2iI2qXM18h1J9fESx0kOI1 4vEg== X-Gm-Message-State: AC+VfDxwDomrjGbhDv8zzNQT/7P1+sKUStOfHUb1iAo5k0OpLJLsSI9g jVXBHo3y/WOFL55lvEQGQ3LvYmSDYSOpzQdIYHA= X-Received: by 2002:a5d:5503:0:b0:306:2d3d:a108 with SMTP id b3-20020a5d5503000000b003062d3da108mr18030517wrv.11.1683905666762; Fri, 12 May 2023 08:34:26 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id b6-20020adfee86000000b002feea065cc9sm11721297wro.111.2023.05.12.08.34.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 May 2023 08:34:26 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 03/12] target/arm: Don't allow stage 2 page table walks to downgrade to NS Date: Fri, 12 May 2023 16:34:14 +0100 Message-Id: <20230512153423.3704893-4-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230512153423.3704893-1-peter.maydell@linaro.org> References: <20230512153423.3704893-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::434; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x434.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=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 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: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Message-id: 20230504135425.2748672-2-peter.maydell@linaro.org --- 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 bd75da8dbcf..8ac6d9b1d0c 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -1415,17 +1415,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