From patchwork Tue Jul 21 12:40:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zong Li X-Patchwork-Id: 11675623 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7F7A6138C for ; Tue, 21 Jul 2020 12:42:36 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 53D6E206E3 for ; Tue, 21 Jul 2020 12:42:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="gHhdKItl" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 53D6E206E3 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:49220 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jxrbP-0003nG-JC for patchwork-qemu-devel@patchwork.kernel.org; Tue, 21 Jul 2020 08:42:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34978) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jxraB-0002C3-GH for qemu-devel@nongnu.org; Tue, 21 Jul 2020 08:41:19 -0400 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]:33491) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jxra5-0004vw-RG for qemu-devel@nongnu.org; Tue, 21 Jul 2020 08:41:19 -0400 Received: by mail-pg1-x542.google.com with SMTP id o13so11904309pgf.0 for ; Tue, 21 Jul 2020 05:41:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=W9alUim2NScoKewf8vVRphcseP9RDIaK8xQN1I3tCFA=; b=gHhdKItlqETPHEa9IlqbXOlkddHLNotQU59wayLuMJvdSoEOuLop4AhwLuSo4RcXVx cDr4IhvynheMWFGRZOVNVofvEw0xy6drY72+lIpKc5N4ank8VZ0rh2iIrE2R0dTWqNcy 7S+i9JQu3uUSpQokrzXg5IQXPMwild/IubTLK+nvyzBc5hQYZorBdBnt40d4VqH33riv DsrnlwwC3wI18y5i+95o7EpGh3IqxoeQcZHZ4bmLvYktpof5tjRnwL/uB4L3D8k+h7ht qW4xny9ydvnoyFn7n1WlsvBtRe/3vLdoCK3JvRbFtueKlXHCH9D6VH6L964Hs8NsxaEA t5Ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=W9alUim2NScoKewf8vVRphcseP9RDIaK8xQN1I3tCFA=; b=l3M/kQrve8fA7qgZdvTXCkh8pCsHsIV1jeyWPnFzYDkh4KQNBFTXxLcxJZ5KqMvaqp NxuCwCZ0QuzslZrWi593HelnKVwuICf9I9YmpFXXK+PMFsGvzFENVJYDistgEcq3Xvnv xV7dYNrQYVunykHEGKKiuBP1bqtQR3wZ/B/UxVC29UB81nHFNmBT7mKHQStuMqQb8Erv U49tDe0kIGhuDhHyGktRmYnU/SHYcueLF7eL20R+6kTbPjDUuuP963a8GJZHo0HghwvP LQrdwsMf7jTqyk/lNGteAz071VAL2RTKEDwxvryx59UmeGgVMbxW4QgcumIsDWA9H4XS zSOg== X-Gm-Message-State: AOAM531aEByn8Rip9AipDXhgbF97TjJ1DfEcVxZH4JakJ6vXg1AA7cHn DXHxrSzz2BSZ4gPHoa7lW39fBQ== X-Google-Smtp-Source: ABdhPJx/Qo/bcEqDMsf0Vlwr6ThIhFcZ4ugvB6RyoJCFwn3nWdHvrPiYBL8FQXPim+6oMFAo8X8rjA== X-Received: by 2002:a63:1059:: with SMTP id 25mr19989645pgq.302.1595335272379; Tue, 21 Jul 2020 05:41:12 -0700 (PDT) Received: from hsinchu02.internal.sifive.com (114-34-229-221.HINET-IP.hinet.net. [114.34.229.221]) by smtp.gmail.com with ESMTPSA id y20sm19819991pfo.170.2020.07.21.05.41.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jul 2020 05:41:12 -0700 (PDT) From: Zong Li To: palmer@dabbelt.com, Alistair.Francis@wdc.com, bmeng.cn@gmail.com, sagark@eecs.berkeley.edu, kbastian@mail.uni-paderborn.de, qemu-riscv@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH v3 1/3] target/riscv: Fix the range of pmpcfg of CSR funcion table Date: Tue, 21 Jul 2020 20:40:50 +0800 Message-Id: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::542; envelope-from=zong.li@sifive.com; helo=mail-pg1-x542.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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, URIBL_BLOCKED=0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Bin Meng , Alistair Francis , Zong Li Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" The range of Physical Memory Protection should be from CSR_PMPCFG0 to CSR_PMPCFG3, not to CSR_PMPADDR9. Signed-off-by: Zong Li Reviewed-by: Alistair Francis Reviewed-by: Bin Meng --- target/riscv/csr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/riscv/csr.c b/target/riscv/csr.c index ac01c835e1..6a96a01b1c 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -1353,7 +1353,7 @@ static riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { [CSR_MTINST] = { hmode, read_mtinst, write_mtinst }, /* Physical Memory Protection */ - [CSR_PMPCFG0 ... CSR_PMPADDR9] = { pmp, read_pmpcfg, write_pmpcfg }, + [CSR_PMPCFG0 ... CSR_PMPCFG3] = { pmp, read_pmpcfg, write_pmpcfg }, [CSR_PMPADDR0 ... CSR_PMPADDR15] = { pmp, read_pmpaddr, write_pmpaddr }, /* Performance Counters */ From patchwork Tue Jul 21 12:40:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zong Li X-Patchwork-Id: 11675637 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2486F1392 for ; Tue, 21 Jul 2020 12:44:09 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EABBE20717 for ; Tue, 21 Jul 2020 12:44:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="cepgz+8y" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EABBE20717 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:54366 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jxrcu-0005r3-6w for patchwork-qemu-devel@patchwork.kernel.org; Tue, 21 Jul 2020 08:44:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34946) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jxra9-000279-Ay for qemu-devel@nongnu.org; Tue, 21 Jul 2020 08:41:17 -0400 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]:39212) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jxra7-0004wg-IH for qemu-devel@nongnu.org; Tue, 21 Jul 2020 08:41:16 -0400 Received: by mail-pf1-x444.google.com with SMTP id x72so10682122pfc.6 for ; Tue, 21 Jul 2020 05:41:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dIdF0vquCIpG/n6QZnNAQHeg090wZ/lgTGaZg/NW1wI=; b=cepgz+8yilbhFmGj40xKqjKM7OXxFQAT2rTNEB/C4L7fvb8wLRjR2igwQe6hrSosa2 9syw88KsK9V0nwuZhHY8Wy/uuljKHXH6sHZEdjn4UChYQCLxluVxtB8mAriKHsP7RTeF n2edkCP7FQaX01o+MWD8z8NwUU+1MRY7KxY/wZfwRqEAoXUdcUHyB6BI74pUUdqYKZp/ 1lhYdmjva3+Zt+f1SqlLSlhuBWESLFc8Hnfwo/KAb4x3pAK50dQreykdQrjaGSPI+nTm jP4LgJ2TAlOh6QRvEnTzODgVdDalKVN9vKAEgK+nLQg9FQB8RRRpntC74cfYKuJC8c/7 ld2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dIdF0vquCIpG/n6QZnNAQHeg090wZ/lgTGaZg/NW1wI=; b=q+6iyejhUo+iUEUdjcGqA7ZlUD2KJvuaCIOvXpH3Q1wSEpImgr1POxFegomtd2sCC5 YRHBnFEXGHhheHq9gKH2ogaQLx4pB601YNTTNwT+PBU93hAIWseQ2x+N6yq4eeViKC1C ZfVn7c3EiV4FLgszeD+IaKb3Xt9/WDoAI0d6pJ7Yf0Bd0ogODCEAii4uQrQYlGmS0I6S 7MhJvgL2qjciDUfcFa27pYpiD8DMKqCpS/IOhxrOsqle1Q4kxgNL+M0znsuBr6OJ9+aH HHvvzaroquWW3M5U0dN2OTH0uto/Y60PlwGjsZJOCY2HW6bcdytFwwXxuG343lVGHeRI Eb3A== X-Gm-Message-State: AOAM530CFppMD1GULUxRjqbP9gYwtLzxyF6M7cf+CXp1A02ngbW3kzq0 o7X+4NMainVNF3zKUvTQ3Lct3Q== X-Google-Smtp-Source: ABdhPJwdm57aCXGpHJ1e2KvyR7NwtS3trU/bzlpXiAOztSYCiNUe77WDclTrpA0MYVnzTjMKAQ0KAA== X-Received: by 2002:a63:6cd:: with SMTP id 196mr22427506pgg.169.1595335274346; Tue, 21 Jul 2020 05:41:14 -0700 (PDT) Received: from hsinchu02.internal.sifive.com (114-34-229-221.HINET-IP.hinet.net. [114.34.229.221]) by smtp.gmail.com with ESMTPSA id y20sm19819991pfo.170.2020.07.21.05.41.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jul 2020 05:41:14 -0700 (PDT) From: Zong Li To: palmer@dabbelt.com, Alistair.Francis@wdc.com, bmeng.cn@gmail.com, sagark@eecs.berkeley.edu, kbastian@mail.uni-paderborn.de, qemu-riscv@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH v3 2/3] target/riscv/pmp.c: Fix the index offset on RV64 Date: Tue, 21 Jul 2020 20:40:51 +0800 Message-Id: <80450819119ba8493f18c825517f1b4f37eeb600.1595335112.git.zong.li@sifive.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::444; envelope-from=zong.li@sifive.com; helo=mail-pf1-x444.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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, URIBL_BLOCKED=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Zong Li Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" On RV64, the reg_index is 2 (pmpcfg2 CSR) after the seventh pmp entry, it is not 1 (pmpcfg1 CSR) like RV32. In the original implementation, the second parameter of pmp_write_cfg is "reg_index * sizeof(target_ulong)", and we get the the result which is started from 16 if reg_index is 2, but we expect that it should be started from 8. Separate the implementation for RV32 and RV64 respectively. Signed-off-by: Zong Li Changed in v3: - Refine the implementation. Suggested by Bin Meng. Changed in v2: - Move out the shifting operation from loop. Suggested by Bin Meng. --- target/riscv/pmp.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c index 2a2b9f5363..f2d50bace5 100644 --- a/target/riscv/pmp.c +++ b/target/riscv/pmp.c @@ -318,6 +318,10 @@ void pmpcfg_csr_write(CPURISCVState *env, uint32_t reg_index, return; } +#if defined(TARGET_RISCV64) + reg_index >>= 1; +#endif + for (i = 0; i < sizeof(target_ulong); i++) { cfg_val = (val >> 8 * i) & 0xff; pmp_write_cfg(env, (reg_index * sizeof(target_ulong)) + i, @@ -335,6 +339,10 @@ target_ulong pmpcfg_csr_read(CPURISCVState *env, uint32_t reg_index) target_ulong cfg_val = 0; target_ulong val = 0; +#if defined(TARGET_RISCV64) + reg_index >>= 1; +#endif + for (i = 0; i < sizeof(target_ulong); i++) { val = pmp_read_cfg(env, (reg_index * sizeof(target_ulong)) + i); cfg_val |= (val << (i * 8)); From patchwork Tue Jul 21 12:40:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zong Li X-Patchwork-Id: 11675639 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3A81C1392 for ; Tue, 21 Jul 2020 12:44:27 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 10FE2206E3 for ; Tue, 21 Jul 2020 12:44:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="SVZtvfX3" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 10FE2206E3 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:55900 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jxrdC-0006Tv-Af for patchwork-qemu-devel@patchwork.kernel.org; Tue, 21 Jul 2020 08:44:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34980) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jxraB-0002CW-NQ for qemu-devel@nongnu.org; Tue, 21 Jul 2020 08:41:19 -0400 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]:32805) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jxra9-0004xq-Iz for qemu-devel@nongnu.org; Tue, 21 Jul 2020 08:41:19 -0400 Received: by mail-pf1-x443.google.com with SMTP id m9so10680796pfh.0 for ; Tue, 21 Jul 2020 05:41:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4QaCAi9itYTAEWQbQQ1orCya0omL343c9jLTjKapu5Y=; b=SVZtvfX3jvaN6eJXoJzUnsQ9nVFQwPUh60I5jNsQebMG00bVdJynr3WIOnrSGLP+hN 1dEPu5dPVeaNhfth5z4UB9FODdz4gKAns6e0WkX28Q2Z9kPccMrF+7OGaR1IdMyQJm72 0SGryNTSMPQIxpRSyaI+PeZnxuGGFzT7C2G8jANEau+ELt7DaoX7SogXRYo04sIHjRX3 sViuYOXgKKB5JfmbyGicheujxpLfz+cC6CwdFEUT8/Cxz3/nGzJFu/hrlU5wKWiNUFnQ DAWeIYq+StrcIi9foygjDFtzEbKkeu6v1xE5P9/iV1yALjHZa9VAzqA4CNwTene8Tu9l 4GrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4QaCAi9itYTAEWQbQQ1orCya0omL343c9jLTjKapu5Y=; b=kaIXJyCl81qxn+GaYHkinznaID5XyQNlBy2EG1xRW0WsZ6lqj3RYt9USa3+ouJ/ADk I1MG0ud6yj7WgrUccTRI5sp7hW06GKQiIBfYxfS3gRHRbJSrRS2XVeuyaV2k1jGdTgtV nvfmOGaun4CGgI/5PkpmEAXQb7LT+LYvLkNdmLOVBUMxhVEx2Hxws/EBL6uSNw0cembm 4k3HRfMkSesLlbbhv6NviThGWcR4GrhY4VF/uvn1B62ic+WvM1pDSpkiDeBzmns9NNme MKM4H7/1W4ZPCfBe20B+BZpMVFtOH+Usz63oUtLVv2GBXEguqH/1SXvXYrDO92mRchr4 mKIw== X-Gm-Message-State: AOAM5314sX3nJVnWn4u/Lk1NeZxvsgLl9JhkQeslqJluwTnjy8zuJoL/ vdL31vv4tYNxFgLPfMoA2QeiNg== X-Google-Smtp-Source: ABdhPJzkkFBl4IavGupQLBDQmfPn/8ZVEAbsH5JjdvQNsemZ7zs0g5DK3aSqeGH+CSiSg0Tyb+maiA== X-Received: by 2002:a63:778c:: with SMTP id s134mr21658197pgc.273.1595335276271; Tue, 21 Jul 2020 05:41:16 -0700 (PDT) Received: from hsinchu02.internal.sifive.com (114-34-229-221.HINET-IP.hinet.net. [114.34.229.221]) by smtp.gmail.com with ESMTPSA id y20sm19819991pfo.170.2020.07.21.05.41.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jul 2020 05:41:15 -0700 (PDT) From: Zong Li To: palmer@dabbelt.com, Alistair.Francis@wdc.com, bmeng.cn@gmail.com, sagark@eecs.berkeley.edu, kbastian@mail.uni-paderborn.de, qemu-riscv@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH v3 3/3] target/riscv: Fix the translation of physical address Date: Tue, 21 Jul 2020 20:40:52 +0800 Message-Id: <26ac4734d2079d5ec782adef3a5a40e82082b51f.1595335112.git.zong.li@sifive.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::443; envelope-from=zong.li@sifive.com; helo=mail-pf1-x443.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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, URIBL_BLOCKED=0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Zong Li Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" The real physical address should add the 12 bits page offset. It also causes the PMP wrong checking due to the minimum granularity of PMP is 4 byte, but we always get the physical address which is 4KB alignment, that means, we always use the start address of the page to check PMP for all addresses which in the same page. Signed-off-by: Zong Li --- target/riscv/cpu_helper.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 75d2ae3434..08b069f0c9 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -543,7 +543,8 @@ restart: /* for superpage mappings, make a fake leaf PTE for the TLB's benefit. */ target_ulong vpn = addr >> PGSHIFT; - *physical = (ppn | (vpn & ((1L << ptshift) - 1))) << PGSHIFT; + *physical = ((ppn | (vpn & ((1L << ptshift) - 1))) << PGSHIFT) | + (addr & ~TARGET_PAGE_MASK); /* set permissions on the TLB entry */ if ((pte & PTE_R) || ((pte & PTE_X) && mxr)) {