From patchwork Fri Jun 23 12:31:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 695278 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp1929409wrm; Fri, 23 Jun 2023 05:43:39 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5LJl7040A2sLwSR6AHdKrKnEy1jWUWThK9/vYBM5DSpUReVOFsenCR8F0IV3cYFfQ1tC6q X-Received: by 2002:a05:620a:4103:b0:763:aa49:bd3f with SMTP id j3-20020a05620a410300b00763aa49bd3fmr16271944qko.43.1687524219410; Fri, 23 Jun 2023 05:43:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687524219; cv=none; d=google.com; s=arc-20160816; b=QTEwkl4xf79lwzA9c54d58gVBfh7L8hnOR+vy1nwFeUHwwvXRsOIjSMZGqZI0+oIzY rJx4DwowswyGW028IaN0wIf+3bSTVBA8/TT4fJW8MSyKGxry28Xzf8OBH90RoyDvK3Cr zIXsXZZVF3NGI/SP6xzRBsid0wc3pdvhY55u5UI58kyWYAsW5NeFKtSfZIYmr37WwxQ3 Q575jjS3XM0LXAsT6k7cqbfDVKB1qPenHHqh6L695yIKsHFOXH9xnzmVrBAOBrQwFMk1 Kcjw2toGyighXmn0re23XOFiweWyYgdvCmRtRt7OtA8S2HqLKcQPZa2zQ/9zd8GsKVlB /rWw== 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=RB7qUnc5Xl+TcrxsopeEqm0skyH3Xa0G/bAwVFxeQb0=; b=MSl4dnSk2FgdjYzBNb7ZPkrG65HPLNkXL6uD1cspSqQoqNnK78Z95TPw8/5Zn6jqPv 8kZuzXMZOZj6Kn8vYAn42kwrk0KO3XVlQXDFXroM7avLXV1jv+AaQ1aB476zlbUwpCZb TpYd2RqI7ob1WugCNyo7UFvVLO+plgzhr5f7M/fzfpURRR28HFfPzu/m9gY4Kd9LjC86 8+skn2CHybwsBGJf4gp2SyLAyav/fW4xybhgM5pup54VbEEMLebyXPxCfHj9eHut0W1s dGW4ZuU0a2wcXRIbH73bzbXcnyujpkf/RuhvHHRe/PpKCWuhAMzTfM2xMWGKNnINqwrn z4vA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rqieK5EZ; 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 y26-20020a37e31a000000b0075aee28b1bfsi3518629qki.301.2023.06.23.05.43.39 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 23 Jun 2023 05:43:39 -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=rqieK5EZ; 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 1qCfxI-0002Jb-36; Fri, 23 Jun 2023 08:32:00 -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 1qCfx6-0001cU-DH for qemu-devel@nongnu.org; Fri, 23 Jun 2023 08:31:48 -0400 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qCfx3-0000gp-RN for qemu-devel@nongnu.org; Fri, 23 Jun 2023 08:31:47 -0400 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-3fa74d06d72so6674855e9.3 for ; Fri, 23 Jun 2023 05:31:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687523503; x=1690115503; 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=RB7qUnc5Xl+TcrxsopeEqm0skyH3Xa0G/bAwVFxeQb0=; b=rqieK5EZkzq8+3xlJk/gFlIFlXnYPfj9E6dsJmjT4dbPGjDWmC9Wqln8PetoHa0ZwC d404zFujHG3JaK7IWbiBsUYYXp1Dpw/vrs5NoNUyeIpEyvxmHHP49sjYT71/vdSKgXrJ tPxnV07wvHdMg5LWGbnQYKYuT6cZADhJzC6/cZgJMqlj8JdMf2uviSP1l5ozRfnrBvDe PPwDPAYBFgNJAnfdbeC71MT3qvfPq0eJfwDUCpJPsPe3tgHIG4O2o373c1WMbs2S4kTh U+NVVlBUHI2oic0hG1u8YFxs2jRtfT78LmDBLwg99U8EJb4JFlwy6zjgb4AuqufWWdh/ BQQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687523503; x=1690115503; 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=RB7qUnc5Xl+TcrxsopeEqm0skyH3Xa0G/bAwVFxeQb0=; b=SPyzbTVTCRZ00/x5JWjHGGRCAxaVp77j3Nho0FBu2Evm9/uWN4P/b3SnvRAHrn89KF dp9fw03abO80mugQ2cAs2bflabjP9azizIwi193YXJVq3SPpR7H8KBu9yjS4CPD1UX0m Hf03QKlYjrFlDiRBSze5aIvJIWPj15DvRzVmBUBSqT/Mw4KqtkilDYIcWSDDezg1Ulbr bhaBQYBJsXUFCFtA5T8y7mQuNdAd4xQEtv6T8XwfXblP6rNHv4CbkuLZGqAcGE2ntZlt oBOvyKa4Fw+m0Y9t+C+5SlYSIftf7ihC5hrxOO49RKm4vYsiUf07ILJX6VPCTcAV8ESb Az+Q== X-Gm-Message-State: AC+VfDyWUwYp4gUZNEUSbA4N0lSYZnFas79zMKrD/BQxqCc41+Ic4Q+Z 0G/tNdSivdyyma+XFiPIBAzMmCrwnu9Ki5l1tHE= X-Received: by 2002:a1c:7704:0:b0:3fa:7aa3:e32f with SMTP id t4-20020a1c7704000000b003fa7aa3e32fmr1471024wmi.40.1687523503620; Fri, 23 Jun 2023 05:31:43 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id z7-20020a1c4c07000000b003f819dfa0ddsm2232622wmf.28.2023.06.23.05.31.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jun 2023 05:31:43 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 13/26] target/arm: Handle no-execute for Realm and Root regimes Date: Fri, 23 Jun 2023 13:31:22 +0100 Message-Id: <20230623123135.1788191-14-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230623123135.1788191-1-peter.maydell@linaro.org> References: <20230623123135.1788191-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::331; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x331.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 From: Richard Henderson While Root and Realm may read and write data from other spaces, neither may execute from other pa spaces. This happens for Stage1 EL3, EL2, EL2&0, and Stage2 EL1&0. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson Message-id: 20230620124418.805717-14-richard.henderson@linaro.org Signed-off-by: Peter Maydell --- target/arm/ptw.c | 52 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 6 deletions(-) diff --git a/target/arm/ptw.c b/target/arm/ptw.c index bbae432861f..45271d666b3 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -943,7 +943,7 @@ do_fault: * @xn: XN (execute-never) bits * @s1_is_el0: true if this is S2 of an S1+2 walk for EL0 */ -static int get_S2prot(CPUARMState *env, int s2ap, int xn, bool s1_is_el0) +static int get_S2prot_noexecute(int s2ap) { int prot = 0; @@ -953,6 +953,12 @@ static int get_S2prot(CPUARMState *env, int s2ap, int xn, bool s1_is_el0) if (s2ap & 2) { prot |= PAGE_WRITE; } + return prot; +} + +static int get_S2prot(CPUARMState *env, int s2ap, int xn, bool s1_is_el0) +{ + int prot = get_S2prot_noexecute(s2ap); if (cpu_isar_feature(any_tts2uxn, env_archcpu(env))) { switch (xn) { @@ -1030,9 +1036,39 @@ static int get_S1prot(CPUARMState *env, ARMMMUIdx mmu_idx, bool is_aa64, } } - if (out_pa == ARMSS_NonSecure && in_pa == ARMSS_Secure && - (env->cp15.scr_el3 & SCR_SIF)) { - return prot_rw; + if (in_pa != out_pa) { + switch (in_pa) { + case ARMSS_Root: + /* + * R_ZWRVD: permission fault for insn fetched from non-Root, + * I_WWBFB: SIF has no effect in EL3. + */ + return prot_rw; + case ARMSS_Realm: + /* + * R_PKTDS: permission fault for insn fetched from non-Realm, + * for Realm EL2 or EL2&0. The corresponding fault for EL1&0 + * happens during any stage2 translation. + */ + switch (mmu_idx) { + case ARMMMUIdx_E2: + case ARMMMUIdx_E20_0: + case ARMMMUIdx_E20_2: + case ARMMMUIdx_E20_2_PAN: + return prot_rw; + default: + break; + } + break; + case ARMSS_Secure: + if (env->cp15.scr_el3 & SCR_SIF) { + return prot_rw; + } + break; + default: + /* Input NonSecure must have output NonSecure. */ + g_assert_not_reached(); + } } /* TODO have_wxn should be replaced with @@ -1601,12 +1637,16 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1Translate *ptw, /* * R_GYNXY: For stage2 in Realm security state, bit 55 is NS. * The bit remains ignored for other security states. + * R_YMCSL: Executing an insn fetched from non-Realm causes + * a stage2 permission fault. */ if (out_space == ARMSS_Realm && extract64(attrs, 55, 1)) { out_space = ARMSS_NonSecure; + result->f.prot = get_S2prot_noexecute(ap); + } else { + xn = extract64(attrs, 53, 2); + result->f.prot = get_S2prot(env, ap, xn, s1_is_el0); } - xn = extract64(attrs, 53, 2); - result->f.prot = get_S2prot(env, ap, xn, s1_is_el0); } else { int nse, ns = extract32(attrs, 5, 1); switch (out_space) {