From patchwork Sat Mar 25 10:54:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 666911 Delivered-To: patch@linaro.org Received: by 2002:a5d:4d08:0:0:0:0:0 with SMTP id z8csp248548wrt; Sat, 25 Mar 2023 04:53:14 -0700 (PDT) X-Google-Smtp-Source: AKy350YzKWcXHiXtQ7yGQuQ59RFFK299RgkX9gSzR+Q5ex/EcP4yMTJkCuK49YGfv5XJuG7KTR8L X-Received: by 2002:a05:6214:626:b0:5a5:7acf:c29f with SMTP id a6-20020a056214062600b005a57acfc29fmr9102642qvx.52.1679745194364; Sat, 25 Mar 2023 04:53:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679745194; cv=none; d=google.com; s=arc-20160816; b=q5PZY/Ytti2SrWnLpbeOaHVLACaW3K1kgULiuuxp6seqjj02CAISWElMFheMppkn54 bIytMxSjvcpIeMKzARMhtcgYFzfZSGouW0Iv95jB4NhWqW6peJY/e6Py8AGN1o7HAcJv MBVXnIwhf145fXuSJZyDAjHECjfDxBmauE3Bw/p+A5YZcT8oP2YQoT/na2xPAHZ4FT4O 6NceNpbp7lcUHgsMgez58gu+jOzPsZh+yQ2h4mXSIpUybIUgzIG+MciRvhsDO7bBSrO6 WE91KYh3RY1hnSslh1sHIB+FNJ8zucjYBa2Lo6w0euSdYTxrjymrRqeDgoYDo25/IRUg FaRw== 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=/7CakJiw3FQaq9CQRWEMSVcA4vdqDdKzHfEhTBS4YSs=; b=bk6eXtNUEv3mjF+xCgCR97vGu8yGFvcQXKi4Vsz6YVrRciCUx9mxE/ILUke4gVkb3E 1N688BwDbIR+Jt1S3AUEjZ5l6TOPSpGdFz+xBpJuasFqs3NhNRKb4moRD3mcAYWMh25X sAXy1CAqsGLzYffRZYV4RIbYvND60auw0LuD2a+UvkiJ9FsNgOa1/E1yKHpcC5pVrq50 OdEswt7dmibKaA9Xf5/E70a+YMyNP84uCe9Ouoas4U5k/iGLUUGpZQyIA1z1kegGcgVu SCudT/XO0SaXck3siCgzvR93PDUyhospBQO2u/9AlZWgOLXLLTBEgu1F3QMOT6lIWHOE QgSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gopGEyha; 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 f5-20020a056214164500b005af46f8fd21si14537024qvw.389.2023.03.25.04.53.14 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 25 Mar 2023 04:53:14 -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=gopGEyha; 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 1pg2Rg-0004My-JH; Sat, 25 Mar 2023 07:52:28 -0400 Received: from [2001:470:142:3::10] (helo=eggs.gnu.org) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pg2Rf-0004D6-G0 for qemu-devel@nongnu.org; Sat, 25 Mar 2023 07:52:27 -0400 Received: from mail-oa1-x2f.google.com ([2001:4860:4864:20::2f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pg2RZ-0007jY-RS for qemu-devel@nongnu.org; Sat, 25 Mar 2023 07:52:24 -0400 Received: by mail-oa1-x2f.google.com with SMTP id 586e51a60fabf-177ca271cb8so4466131fac.2 for ; Sat, 25 Mar 2023 04:52:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1679745140; 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=/7CakJiw3FQaq9CQRWEMSVcA4vdqDdKzHfEhTBS4YSs=; b=gopGEyhaaZwI3LHRzdeS2jLZ/U5biUqM1u8DRng/Bs2DsWQEObLloIPoh4r7djr4iu /EzwWaQw9rQkUu+evpJI52+FhcTXul0qmBjcSFtg6EbbQD4Kzl88Ldd+WFzjRN3N8rfn IJQeBJ/gu40eWBfy7+NHkIoIlbmx1RzbEFCO3lZa3WplcqtsYmVhh4Xf4yv0OyyHyDKl 7QIojW35hPnMoZlJk5pqIr8Kji7fU73JgLCsjKnUtndzcdFRpOyr1V6RE91PMtndsmOg MYFwocp6znuTGviKG3PRrCfd5NKNqXnI6HN4TWq4Sl1+ZBYLxKj39LybY7PF/a+s1aVb MiYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679745140; 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=/7CakJiw3FQaq9CQRWEMSVcA4vdqDdKzHfEhTBS4YSs=; b=vjQKXxfYhNrw2MZVQ2nvrZKwXONTKwVviiiTzomfu+yfBdbiyhi73yHVVKaOjTVlBu xzrVmqStmUr06nSqmGRl88jl3eQ3OsEC2Dzg8DdSXjRNkE8YflIlc0RT19PmrGkrcntf 18w1cXLctfZjrhdG0k2SewlrkNMnCeUagw75GqEfpAHPLKQB2RUweJQYotBE6OYSSv71 8KxMy0Rd0egGTz5y1CZS0lMvhiKzbIf3IpxBl/KXEP920zh4SlsO7wqNTAGY4GmXN+rq fo7S+k6IGbGIm1P7geVLZteBTSKxpHqwQJrSgeZJM8eYIPgZm+uIgsqtpIr0EJ+uvxbj zs1w== X-Gm-Message-State: AAQBX9d5ya/EAPp7ah1lUZiyJEpqgFFOD64rfbulbplORvYGRU5Q6Ltm wwZswc689h+sLllLmOnRGwUlUTViaSehABDcd/U= X-Received: by 2002:a17:90b:38cc:b0:23d:4e0e:cf34 with SMTP id nn12-20020a17090b38cc00b0023d4e0ecf34mr6017114pjb.34.1679741682165; Sat, 25 Mar 2023 03:54:42 -0700 (PDT) Received: from stoup.. ([2602:ae:1544:6601:790a:6e23:4a91:70a]) by smtp.gmail.com with ESMTPSA id p14-20020a17090a2d8e00b0023af4eb597csm1234684pjd.52.2023.03.25.03.54.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Mar 2023 03:54:41 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, palmer@dabbelt.com, zhiwei_liu@linux.alibaba.com, fei2.wu@intel.com Subject: [PATCH v6 13/25] target/riscv: Introduce mmuidx_priv Date: Sat, 25 Mar 2023 03:54:17 -0700 Message-Id: <20230325105429.1142530-14-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230325105429.1142530-1-richard.henderson@linaro.org> References: <20230325105429.1142530-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2001:4860:4864:20::2f; envelope-from=richard.henderson@linaro.org; helo=mail-oa1-x2f.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=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 Use the priv level encoded into the mmu_idx, rather than starting from env->priv. We have already checked MPRV+MPP in riscv_cpu_mmu_index -- no need to repeat that. Signed-off-by: Richard Henderson Reviewed-by: Alistair Francis --- target/riscv/internals.h | 9 +++++++++ target/riscv/cpu_helper.c | 6 +----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/target/riscv/internals.h b/target/riscv/internals.h index 0b61f337dd..4aa1cb409f 100644 --- a/target/riscv/internals.h +++ b/target/riscv/internals.h @@ -37,6 +37,15 @@ #define MMUIdx_M 3 #define MMU_2STAGE_BIT (1 << 2) +static inline int mmuidx_priv(int mmu_idx) +{ + int ret = mmu_idx & 3; + if (ret == MMUIdx_S_SUM) { + ret = PRV_S; + } + return ret; +} + static inline bool mmuidx_sum(int mmu_idx) { return (mmu_idx & 3) == MMUIdx_S_SUM; diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 7e6cd8e0fd..cb260b88ea 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -771,7 +771,7 @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical, * (riscv_cpu_do_interrupt) is correct */ MemTxResult res; MemTxAttrs attrs = MEMTXATTRS_UNSPECIFIED; - int mode = env->priv; + int mode = mmuidx_priv(mmu_idx); bool use_background = false; hwaddr ppn; RISCVCPU *cpu = env_archcpu(env); @@ -793,10 +793,6 @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical, instructions, HLV, HLVX, and HSV. */ if (riscv_cpu_two_stage_lookup(mmu_idx)) { mode = get_field(env->hstatus, HSTATUS_SPVP); - } else if (mode == PRV_M && access_type != MMU_INST_FETCH) { - if (get_field(env->mstatus, MSTATUS_MPRV)) { - mode = get_field(env->mstatus, MSTATUS_MPP); - } } if (first_stage == false) {