From patchwork Sat Mar 25 10:54:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 666928 Delivered-To: patch@linaro.org Received: by 2002:a5d:4d08:0:0:0:0:0 with SMTP id z8csp268535wrt; Sat, 25 Mar 2023 05:42:56 -0700 (PDT) X-Google-Smtp-Source: AKy350YJWzxQ7gbTQ7skkbkZi//xYS8T86ZEq2k5gi7/HPejU8Vsc/Mj0/+wCI5x5XR7NaRnUQn6 X-Received: by 2002:a05:622a:178a:b0:3e1:9557:123c with SMTP id s10-20020a05622a178a00b003e19557123cmr6913311qtk.52.1679748175953; Sat, 25 Mar 2023 05:42:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679748175; cv=none; d=google.com; s=arc-20160816; b=NROHqb1aHWDerjKdfihSBXmLcT798uNJTf7sH4lc1RDhbUendQKd1V82hNMOhqkesM /BRyGXqlXwWdA/ZbbOoG5J7fjbHwCHlBIMRRGQDNPWyq95ZnOjgn7jYqH34bCpAunCNR Sbo/KxExt6VLkMsU2WN3YB9x2rxq4/Jn0ybI2N+bfiMsy4mSXYiSeIBUH8laRRWu4cAt 3QIGmzFBAzBr13rb1HE2OnuCkoEcXYzNcvlfRlfi5N0InGBKBl5KUQuJkkHNmwMqvJxX wWkl7G3L6DMsl+COMyBXMSYNzMH4ImW4xjOTUC/ZfGAnSDuaCfKLcNLldVn7fYUWGU1X 8xFA== 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=+p35/oWwAnwR4nkxv4vCszWfRwgaL1NMREdWhFXiQdY=; b=xqT45XhIYgNOyvMNeAMqsKmWzxbV+GQB9vCBiHI8/XvOEy2gL/5WBC/ADPobY0C563 IOKlkSiy1vYPIqsfXxcxqDo/PxBuZJhcCNL/zCCzkKzRUzRX1hF65C7mCvVKWhuwqnKt Zwa7F4i00nhsZgIc821XHoHiRStxCQkzgKCsEgfmyJZbFUMRbKnt+BHpwQsbPKCUao8S RhxCAZfBDKTzxGEzIGjQpGj7HrZZKRrwf5Xk/h1gi4BmumZH6LhaIDw737bBjVNPyMfF Duy6kN38q46e0+O65K0PkkCBoR95KagZFpoAPFNc9exMLRD7B4uwWIPwn8H74FT0Ytnk VxUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vxPydTEm; 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 i5-20020a05620a404500b0072dbba6a4easi8245962qko.547.2023.03.25.05.42.55 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 25 Mar 2023 05:42:55 -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=vxPydTEm; 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 1pg3DK-00062K-JZ; Sat, 25 Mar 2023 08:41:42 -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 1pg3DJ-00062C-7m for qemu-devel@nongnu.org; Sat, 25 Mar 2023 08:41:41 -0400 Received: from mail-oi1-f182.google.com ([209.85.167.182]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pg3DH-0008M3-GT for qemu-devel@nongnu.org; Sat, 25 Mar 2023 08:41:41 -0400 Received: by mail-oi1-f182.google.com with SMTP id f17so3169765oiw.10 for ; Sat, 25 Mar 2023 05:41:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1679748086; 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=+p35/oWwAnwR4nkxv4vCszWfRwgaL1NMREdWhFXiQdY=; b=vxPydTEmcX5Mo/R7Mqi/sYZhF2b+YhqLA42owwKs1nWDJT0OCMZKDCfofDz9VvhpLU YOVVSEUizvW8+ODKDPNZZ3IVkxrNPWvgyc2BY7v2TRxC8iI8G0KDF9itndshrbKWjZKm zTAfS3tC599GOQ8hLtgX33780WKtCcYdreflJDTzkUj6QeBivFMvDqEg3elKzadYGSyh OKZLSXsi3KhDkPXWJJKY4Zwx09ICDe7+ug2EsJaleA5WiCSoi3uxE0vLYEh9zAIA2fL6 0RNCOvkEPPgsWfh03PQegT47/wdHpZH5I7p3WzUMzanBcAcxPQLn+1+DlUFu18c/+UHq UFwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679748086; 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=+p35/oWwAnwR4nkxv4vCszWfRwgaL1NMREdWhFXiQdY=; b=OXPE3AjMnUJqRqcmWnMgEKueDIqLfICLDyxPqrexgU1CJt/+sMmMkvp+XSOFJBGTIr NJM2EcBLqljlq5K64oC/L8bMclveBx1P9fNGrTZzdSuy8Jg9e+lSGJxDDDCI9aof5FvT u04vBH1rKbC2R5z+2TwjMXuSNx5JGlFyUSrQ/CVTHvRO5GQCekkd6xT0JJHumOpdIzBQ Q2ulKtv9yaUBQG4tNs+5Ahig2FiM5WMDSvDaRfl8R0o3011aeTWAyif1+RPF6m7dV05V ibsszK76LDDkIFe0wpiLeBlrAmv7X4yLxRV7vyL75JDAGtYEHbVeG1feOGXQy1Pe2lgc Fm9w== X-Gm-Message-State: AO0yUKUoLZJAxK1Tc769j6XuSEyhWBsV+1EQu3C75Z3P5adsUp56Jhhv 0A/3Qwnhjx0bApsrJbYx+n1kEpa8crdsXD5o5LA= X-Received: by 2002:a17:90b:4a46:b0:22b:b832:d32 with SMTP id lb6-20020a17090b4a4600b0022bb8320d32mr6155611pjb.9.1679741685769; Sat, 25 Mar 2023 03:54:45 -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.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Mar 2023 03:54:45 -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 17/25] target/riscv: Check SUM in the correct register Date: Sat, 25 Mar 2023 03:54:21 -0700 Message-Id: <20230325105429.1142530-18-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=209.85.167.182; envelope-from=richard.henderson@linaro.org; helo=mail-oi1-f182.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, RCVD_IN_MSPIKE_H2=-0.001, 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 Table 9.5 "Effect of MPRV..." specifies that MPV=1 uses VS-level vsstatus.SUM instead of HS-level sstatus.SUM. For HLV/HSV instructions, the HS-level register does not apply, but the VS-level register presumably does, though this is not mentioned explicitly in the manual. However, it matches the behavior for MPV. Signed-off-by: Richard Henderson Reviewed-by: Alistair Francis --- target/riscv/cpu_helper.c | 12 ++++++++---- target/riscv/op_helper.c | 6 +++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 6c42f9c6fd..0017ecbf37 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -42,11 +42,16 @@ int riscv_cpu_mmu_index(CPURISCVState *env, bool ifetch) /* All priv -> mmu_idx mapping are here */ if (!ifetch) { - if (mode == PRV_M && get_field(env->mstatus, MSTATUS_MPRV)) { + uint64_t status = env->mstatus; + + if (mode == PRV_M && get_field(status, MSTATUS_MPRV)) { mode = get_field(env->mstatus, MSTATUS_MPP); virt = get_field(env->mstatus, MSTATUS_MPV); + if (virt) { + status = env->vsstatus; + } } - if (mode == PRV_S && get_field(env->mstatus, MSTATUS_SUM)) { + if (mode == PRV_S && get_field(status, MSTATUS_SUM)) { mode = MMUIdx_S_SUM; } } @@ -838,8 +843,7 @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical, } widened = 2; } - /* status.SUM will be ignored if execute on background */ - sum = mmuidx_sum(mmu_idx) || use_background || is_debug; + sum = mmuidx_sum(mmu_idx) || is_debug; switch (vm) { case VM_1_10_SV32: levels = 2; ptidxbits = 10; ptesize = 4; break; diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c index db7252e09d..93d4ae8b3e 100644 --- a/target/riscv/op_helper.c +++ b/target/riscv/op_helper.c @@ -437,7 +437,11 @@ static int check_access_hlsv(CPURISCVState *env, bool x, uintptr_t ra) riscv_raise_exception(env, RISCV_EXCP_ILLEGAL_INST, ra); } - return get_field(env->hstatus, HSTATUS_SPVP) | MMU_2STAGE_BIT; + int mode = get_field(env->hstatus, HSTATUS_SPVP); + if (!x && mode == PRV_S && get_field(env->vsstatus, MSTATUS_SUM)) { + mode = MMUIdx_S_SUM; + } + return mode | MMU_2STAGE_BIT; } target_ulong helper_hyp_hlv_bu(CPURISCVState *env, target_ulong addr)