From patchwork Mon Feb 20 23:26:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 655148 Delivered-To: patch@linaro.org Received: by 2002:adf:9bcd:0:0:0:0:0 with SMTP id e13csp1661958wrc; Mon, 20 Feb 2023 15:29:21 -0800 (PST) X-Google-Smtp-Source: AK7set/C7YSf6GwfLurLNJcYFQR4rX3oeZg3z17gRaWmpXNci2RsxkrDBYP1Bf6u4jNIAZldKDQp X-Received: by 2002:a05:622a:60f:b0:3a7:e9a2:4f4a with SMTP id z15-20020a05622a060f00b003a7e9a24f4amr19685424qta.8.1676935761133; Mon, 20 Feb 2023 15:29:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676935761; cv=none; d=google.com; s=arc-20160816; b=jFNsW16zR9SZ2lQWSsCdh+8X9ELVuekdMMP+DvnzXa+W2kgllLR5P7r5n0aq0Xo7B5 INU35Pe7dQpvWpir1DU8eSOVcd1SrImeV/J+LdIhtfSe3yMiCn2Gj9utdJyDCPy7vHkG Ae2diiwCveq7Ks73x4b9s+GdX1XOQNobbp3QDJnMKIqLOiU/3kOdNeecPc/uyQYONupi H5vDaaR83P8f3KTWQqAESUWfivXUt7jtgplqOQNh5wzNDjWq2V+g3MNxB7lniWByqksI xFKb5z/SMcd4SdY2VY5iuq9YCKHs/fY0gVe5jgrO3ywUPnZSgSMkERuYIHsY+BdoYqP9 Xacg== 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=Q2wDlc9y+ZmDdlYUvnbEL+qYl6ONKTEgAFqhyLih/rk=; b=WSozsbENa0opebraAlAkvMaIksI2wnbuF9JK2diZQRbQWIlV6ck0Qf7q+ZvfTb1JWD rtLd/G5BIptoKrP8hKsrZIkVtFn6yh8c6VLB01UWZLDIN+VUBgkgd2hjGGP3pFWCwXbG tvDFD1AbBA3LJpkroum1Tf3FT4+Cc8Bakhx+jiaGpsWTadQeo3MS1CIjItoar2IR8BTD +WOHBX8lNvSBELFJkILvC6s9FdVwIOERV2ZFUxfAIOcQDGpsRmsE/reV5d1s7s+IF80Y YyEXzy4B6EpVgG2XDZaqbEwJ/WpeZMxpjvKIycO/i1Tu8nF/BetLhdrP7+A9YUdppT4H L+OQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SI9939Ck; 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 u13-20020a05620a454d00b00738e6f037d4si11404532qkp.757.2023.02.20.15.29.20 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 20 Feb 2023 15:29:21 -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=pass header.i=@linaro.org header.s=google header.b=SI9939Ck; 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 1pUFYe-0004EY-K9; Mon, 20 Feb 2023 18:26:56 -0500 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 1pUFYb-00046u-LU for qemu-devel@nongnu.org; Mon, 20 Feb 2023 18:26:53 -0500 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pUFYZ-0000Os-SV for qemu-devel@nongnu.org; Mon, 20 Feb 2023 18:26:53 -0500 Received: by mail-pj1-x1032.google.com with SMTP id nw10-20020a17090b254a00b00233d7314c1cso3015542pjb.5 for ; Mon, 20 Feb 2023 15:26:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; 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=Q2wDlc9y+ZmDdlYUvnbEL+qYl6ONKTEgAFqhyLih/rk=; b=SI9939CkfMXh2gPFkBNyfUSn311jdAXhlcxpI26CQBa3jmX48aYVUJnNUe298tv0tA /55rvZT1CahipYUH1Ds2W1emizOmKY1KMHEU2McyMcTk5Ao+cM0895YjzE0oVYAZyO9N gaQAUwBjTxhKcIBvHFgpNgWsr1lanhNcQWEz6QMY/nM8ywl9WNlJnL0Z+NoJC+M4rKw5 YlJkGHlgHVgr1LiYKywbBMqXEZpHmEO13E1a3u94o6N0MKb7RhgNEouS4cgr51/G+lhE c4x0uqPh03jiltHhtgLOENZ2EFiy6G/ANfowJLNf13Vo3+O3RfklFKG8YAJZfFVpg+Ao 0Q4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=Q2wDlc9y+ZmDdlYUvnbEL+qYl6ONKTEgAFqhyLih/rk=; b=YoqeTugKycJ9mJGjDnQ0btWiO8AhbOgFdf8Cht+yQ//rMk2CXlDixZP9EsBsibWeZb PcK0ho4sDhqy+8uHltztTST3HWvBFPqKveuKdUP6Y25F8Y0fjO7nPjxHCgKC3hpXUqRJ 2r+xiDHSbpUc1oryGi7gaBBM1kK+LiskJT7xEjjERhkhmsbFMd+MaAPb7op007BaIyzy 6ynyF7EegBJncjjFTeAKCW8ei5CFz4kHiZKWrUfru7b81vOSEIezuoQQ1z1Cp8Ys4NjU n9NK5nR63hFzX9B6SPrOK5UptnLohEC2WlL8DGg1EeiBERa1pABLHbnf/X/CzA9zoXb7 4VVw== X-Gm-Message-State: AO0yUKUi1XaG5dAveS1VT358/CNU3+EAC0domKdLnbKt610lbWfqNELb lt/a3VtkWl/UTp5AutgCe8TKkPahRELH4HZD6D0= X-Received: by 2002:a17:902:e547:b0:19a:a815:2876 with SMTP id n7-20020a170902e54700b0019aa8152876mr4075649plf.62.1676935610970; Mon, 20 Feb 2023 15:26:50 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id j10-20020a170902690a00b001992e74d058sm2665348plk.7.2023.02.20.15.26.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Feb 2023 15:26:50 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH v2 13/21] target/arm: Handle no-execute for Realm and Root regimes Date: Mon, 20 Feb 2023 13:26:18 -1000 Message-Id: <20230220232626.429947-14-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230220232626.429947-1-richard.henderson@linaro.org> References: <20230220232626.429947-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1032; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1032.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 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 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, but stage2 EL1&0. Signed-off-by: Richard Henderson --- 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 a9a9a8a403..54e72baff5 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -909,7 +909,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; @@ -919,6 +919,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) { @@ -984,9 +990,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 @@ -1563,12 +1599,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) {