From patchwork Sat Jul 25 15:03:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zong Li X-Patchwork-Id: 11685085 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 35532913 for ; Sat, 25 Jul 2020 15:04:57 +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 0B14B20674 for ; Sat, 25 Jul 2020 15:04:56 +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="gy+ktgD9" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0B14B20674 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]:37958 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jzLjM-0004Su-84 for patchwork-qemu-devel@patchwork.kernel.org; Sat, 25 Jul 2020 11:04:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40908) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jzLi7-0002gI-P5 for qemu-devel@nongnu.org; Sat, 25 Jul 2020 11:03:39 -0400 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]:34228) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jzLi5-00086x-8B for qemu-devel@nongnu.org; Sat, 25 Jul 2020 11:03:39 -0400 Received: by mail-pl1-x642.google.com with SMTP id o1so6024141plk.1 for ; Sat, 25 Jul 2020 08:03:36 -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=gy+ktgD9e3vcF029rESntF5bjyoGyGy812jfHvdC0JVIoNe772rxBrPMj7zYkmOEba idct+TvMnTRPSDLPqZvtqTAFco0X29NS8toXxX+vuRCUsMBTN88qg8mzyBLYHRv9cQDS qSzCvd8OaFnJKlgBltej7MJQRlfqGsuEl8yl61dwLn1XUe40rmBEuG36Rw6zm6nSUyYm TbLR0rMCmfzaNTqMcsQeBm1xlskiHa2NomWlnYi+x1TlMixVWAYXDDgF+TN7cNfxy/my q3QtbndFdfAHGWKgqtCsz6ywV4rGEVGXm7Re7ABw2aQLluUw/SyWobtSsV73/Xb4nHCe ziIw== 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=Gwl+/IA2e+XYXeh/wl3eduDadMotFDTZII5ZkxKfn/It6A+YUlryDP3wWnlHuAEcag w7rTLCHEnKl42dr2Zy1NYs+jfQ33Ii3U4jqNmzcn9ymDqkq1x6Hh4ugQrYJQk+uh0BSD M0djS0fhK9nVUwF9ybdZT4YrxysVI3WuhL9wJjPkzdOPABQD7k32bnZNfsFFEI5ZnGfY 1aJ/+hJvgTZgGRx6029kelXc6GegmCyuQ7COJmqRM8urUG/+dxR1V3PzuMs/rcoJdoQz /4uPa+wHYHL5kuKCT95Rb3x/dm0o5u8wYxC0W6OZHIaxeVSLdHwlFlI/Wyx7PELyrltl RQzA== X-Gm-Message-State: AOAM530sIgW3K0zVdVAeeKCMIqt6SF7EaqEGn/6Ru5c7kWzAeqpQqzw3 ixdUa95+75X3LUWk1zMpbgZDtA== X-Google-Smtp-Source: ABdhPJy7Pnueq7RhCVSh8128l2Cy4wrH0owuzAatATnf3D8mb2UlQJ26+A553P+zBBz5c+vNOnlanA== X-Received: by 2002:a17:90a:ba05:: with SMTP id s5mr9593369pjr.132.1595689415837; Sat, 25 Jul 2020 08:03:35 -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 g22sm9059783pgb.82.2020.07.25.08.03.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jul 2020 08:03:35 -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 v5 1/4] target/riscv: Fix the range of pmpcfg of CSR funcion table Date: Sat, 25 Jul 2020 23:03:24 +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::642; envelope-from=zong.li@sifive.com; helo=mail-pl1-x642.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 Sat Jul 25 15:03:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zong Li X-Patchwork-Id: 11685087 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 D655E913 for ; Sat, 25 Jul 2020 15:05:00 +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 ACB2D20674 for ; Sat, 25 Jul 2020 15:05:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="Hvt6a+I7" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org ACB2D20674 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]:38310 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jzLjP-0004bP-UA for patchwork-qemu-devel@patchwork.kernel.org; Sat, 25 Jul 2020 11:04:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40940) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jzLi8-0002iO-VF for qemu-devel@nongnu.org; Sat, 25 Jul 2020 11:03:40 -0400 Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]:38720) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jzLi7-000889-5Y for qemu-devel@nongnu.org; Sat, 25 Jul 2020 11:03:40 -0400 Received: by mail-pl1-x641.google.com with SMTP id m16so6009783pls.5 for ; Sat, 25 Jul 2020 08:03:38 -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=gi/phrEkN1+Q3sxpwjsqg73gbNMUPMMftuyCiLQ2q6I=; b=Hvt6a+I7gFcgihHypX2nlKlOdF8h9S2UV+RpDB5laXZPmsUCtF0Qkd/28Jl3yvojBB IV/tgF6cy3HxNWfH8NGMdbmNOdoRE9yG36+k1O3xanHbRN1nPzYeT2ViE1sYNDL5R5OR JIUvK9f4A0ScefPakhOGEYBLDbfdAlnqVZhB+ohny8vdBr8OTEpITmCh8sFjU4If2RCz 7dyDrP8vr4PYUfQtAOoRRCOcbxjc1tdSLbM0MoDkl8eZFA8yDPnI+N380KqS/FWm7Opf KMK4ZHkNpLz+QtRjbJmtlybf5rxUsNyjfX7POOfhI23mbcCQ6ZoGS4CHSCVxMj3tf8Ac xi+A== 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=gi/phrEkN1+Q3sxpwjsqg73gbNMUPMMftuyCiLQ2q6I=; b=V8CT90W1nER2M5SdxHUEcoSfNNf82WhCMqoCCPknaWa0cbuM+OSSeSevSvSU69WrCe zP0ayMHnZrr1BuPFf3nrDooyF677mP8yhojKLTijMFRsdGsvOViYkucwALKPFf45iJMt NVOM/BgBpjrfuGWKhhfCGzmoiNSFPTZju6cV7nSz1eo7cIHMZnVdLJz7bjAaIq+HnTZP E+63HZsZHILvkKNd7ODq5QbkcPYAHanABwzNaN+agr/myMsiGcCreU+iDwwv3vijVCT1 /wEhfC74Uup2qfEimXktklIa3oVxPSjpCaYPJANxU9/OHJN1eaKT55si5arGu/V7iQAW PYEg== X-Gm-Message-State: AOAM5322yVFbGcBqdjExlox5tzYmjxJxWt/Bh73xlGWoW0UlSiL5aRaA nO6UOIz9pstO+NWFDwKjz1knzw== X-Google-Smtp-Source: ABdhPJzZb0J959VzuW1lTmA4PcW2DAyRg/1ncHDw7sPrKD96IQZ1wSmhvrqDxfTLWZxY1SBRkKHd6A== X-Received: by 2002:a17:90a:30ea:: with SMTP id h97mr10506807pjb.32.1595689417800; Sat, 25 Jul 2020 08:03:37 -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 g22sm9059783pgb.82.2020.07.25.08.03.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jul 2020 08:03:37 -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 v5 2/4] target/riscv/pmp.c: Fix the index offset on RV64 Date: Sat, 25 Jul 2020 23:03:25 +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::641; envelope-from=zong.li@sifive.com; helo=mail-pl1-x641.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" 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 Reviewed-by: Bin Meng Reviewed-by: Alistair Francis --- target/riscv/pmp.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c index 2a2b9f5363..aeba796484 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,11 +339,16 @@ target_ulong pmpcfg_csr_read(CPURISCVState *env, uint32_t reg_index) target_ulong cfg_val = 0; target_ulong val = 0; + trace_pmpcfg_csr_read(env->mhartid, reg_index, cfg_val); + +#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)); } - trace_pmpcfg_csr_read(env->mhartid, reg_index, cfg_val); return cfg_val; } From patchwork Sat Jul 25 15:03:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zong Li X-Patchwork-Id: 11685089 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 4B62D138C for ; Sat, 25 Jul 2020 15:06:14 +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 21B0F206C1 for ; Sat, 25 Jul 2020 15:06:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="Tox6xcq+" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 21B0F206C1 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]:42852 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jzLkb-0006Vb-E7 for patchwork-qemu-devel@patchwork.kernel.org; Sat, 25 Jul 2020 11:06:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40998) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jzLiB-0002pG-3Y for qemu-devel@nongnu.org; Sat, 25 Jul 2020 11:03:43 -0400 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]:43894) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jzLi9-00088o-0F for qemu-devel@nongnu.org; Sat, 25 Jul 2020 11:03:42 -0400 Received: by mail-pg1-x541.google.com with SMTP id w2so6974345pgg.10 for ; Sat, 25 Jul 2020 08:03:40 -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=Tox6xcq+2y9PgheBWJL4mk9bIPp0g3H4V8lbWcjKyx2MIZL/wZrii5uCeeCVFlruyb WkI+YJzHdYMqihv+24SBRv+mhD7vYlWW2LuM1tyaXbmc+dNF8/M4gPamHz58bwNnZncS xF3hlzrx0/wGBFIj3y3T82kUXbxZf81dUSE24c28wtI3ihrIljsuj7etH0YKS2JVVH0x 19dzmvGZSKDqLHV6lkoL9tBRC4eO/FLK9fYR5op5ZMQjGitky2yq0OEiwEISU2jnp0ve 5dGh0c0bXcqZitWn92AGyfGqp2iqEfL8oBMtXweDmH+dEvck81ntfSsdUYOOCTZhtYJq zFHQ== 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=mhXxHeNDQ9S5UOXYYvwZEe6kYwYchpPSzOpbiYgtXKri+8hbV/WPh0Ry6okqOKNkc9 OqYhYvs5JViWeLuWD227InzxkCdsLXF6/rAlggtjdvgbnEbXmWG2H8dJpDgxgtHH1yfb Wdl+NfYv2PxHs5X0y2uzQTDqptM5orMDJo/kJbRdU9Ojqm8o6DVCGqW6W8/8htOzKrM2 p6t+NqXWAPAgimUOpiCWy4+xqp3FweCVSgdNfvIn9c+Blyz3dmo64pLqF5RyibyIY/o+ icVA4QtDtbK6kQ4cycC2gXkooyLgo/62Tmwj1XI8g45OD1ajgMuMWXbBNsKBt2znpfGp zzLg== X-Gm-Message-State: AOAM532DlyfMBWkWluBO5U7OrCLLKnuI0kMEYKgkoqHfSl2sxzhSI1so a1NWzrbfqM47gyG2iV3IHzsTtA== X-Google-Smtp-Source: ABdhPJzWdntjR9EXFrAPIk5gI98/3q6RKbuRJo+C6AHM7ZRK/b3+1o7JR467NxFxikngnhgGRjFADA== X-Received: by 2002:a65:4549:: with SMTP id x9mr12417643pgr.415.1595689419741; Sat, 25 Jul 2020 08:03:39 -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 g22sm9059783pgb.82.2020.07.25.08.03.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jul 2020 08:03:39 -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 v5 3/4] target/riscv: Fix the translation of physical address Date: Sat, 25 Jul 2020 23:03:26 +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::541; envelope-from=zong.li@sifive.com; helo=mail-pg1-x541.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)) { From patchwork Sat Jul 25 15:03:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zong Li X-Patchwork-Id: 11685091 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 B2175913 for ; Sat, 25 Jul 2020 15:07:34 +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 8905A206C1 for ; Sat, 25 Jul 2020 15:07:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="LXT6QVPW" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8905A206C1 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]:46182 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jzLlt-0007rn-PO for patchwork-qemu-devel@patchwork.kernel.org; Sat, 25 Jul 2020 11:07:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41024) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jzLiC-0002tE-U3 for qemu-devel@nongnu.org; Sat, 25 Jul 2020 11:03:44 -0400 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]:36962) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jzLiA-00089O-VR for qemu-devel@nongnu.org; Sat, 25 Jul 2020 11:03:44 -0400 Received: by mail-pg1-x543.google.com with SMTP id d4so6999695pgk.4 for ; Sat, 25 Jul 2020 08:03:42 -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=InaCMlegJaWsB2fv1wyQxNhfO4TjO2lCW/QNWh+yG2U=; b=LXT6QVPWEo9uD29dV7Jfx9rKLwckDM8clpnN8hphx97+ISnrES+UVOzLGCV6CzK3tK gT1Yw31LzH76OlXkUwyLsNnYl8b0k5zGjtb/CoT/i58lgUxSuj5I2M98MhQx1DUbl+dV iNmcusddOC+fm6fU9PrmU0/FpC7mysm6uKFh71h+CBixpiFPSxVGP+kQv+orWL6hmf2y jpVWkprbcp3gEOZxy2RYdnBWjvFtIbG9QfinEajzfxv7gFgVf41wUtFXvndonQEDcuRd NX3QppqD2Qc2kF1DNJVnTmiiIW4ntdo06UqDxZ3wGgtLekOCmggE0ozMJMTGRyHhfXya lK/A== 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=InaCMlegJaWsB2fv1wyQxNhfO4TjO2lCW/QNWh+yG2U=; b=L3AtpHeEFsu7NRTTmbOzf5NF97a2PPM0ja293F5/Hh5Erq9SknUMAgQnbaCP2QkStL jFCreEfTjM0187j7gLxutnwqZCtacEoWrW3IXCc5guyS4//V4Sao5xg84/evBEWhieh4 EZjujXMnFQ5AljwsswCC8P7m9lyit6hk0TT2HSu1AdtmBF3EpEZfso7Zo/Akw2ky0dXX KlUc6U4Bb9hgjZLz1mCOWTb0kUb5acO13KoPDZCnw/EDqsGQmi8bVwqo0xlD4U2TenwS FaI+UHWGae1J6hWc8jIubCnBU+39Xock02HM0WNhGMUEr9KqVwWpbLWQY1CIlE2QCXX7 YUBQ== X-Gm-Message-State: AOAM533SD5+TaYgRppQQifJQTcwsH1vces6PiwfuNm0ekOX10D9bAgsE 6tlOxA54aoaCw1Tef3fQSkheJg== X-Google-Smtp-Source: ABdhPJz6z00QVfRK1pZ9pBxWqxCmu36sjVK0t6Qy1kFJ7mOAEhzQgw/CvYWQ9EH0t4VF/vhUko384w== X-Received: by 2002:aa7:9a03:: with SMTP id w3mr12976992pfj.228.1595689421643; Sat, 25 Jul 2020 08:03:41 -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 g22sm9059783pgb.82.2020.07.25.08.03.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jul 2020 08:03:41 -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 v5 4/4] target/riscv: Change the TLB page size depends on PMP entries. Date: Sat, 25 Jul 2020 23:03:27 +0800 Message-Id: <3b5c4ba2f6ea6fe0a40edd41b02b3d22db2de639.1595689201.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::543; envelope-from=zong.li@sifive.com; helo=mail-pg1-x543.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" The minimum granularity of PMP is 4 bytes, it is small than 4KB page size, therefore, the pmp checking would be ignored if its range doesn't start from the alignment of one page. This patch detects the pmp entries and sets the small page size to TLB if there is a PMP entry which cover the page size. Signed-off-by: Zong Li --- target/riscv/cpu_helper.c | 10 ++++++-- target/riscv/pmp.c | 52 +++++++++++++++++++++++++++++++++++++++ target/riscv/pmp.h | 2 ++ 3 files changed, 62 insertions(+), 2 deletions(-) diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 08b069f0c9..b3013bc91e 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -693,6 +693,7 @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size, bool first_stage_error = true; int ret = TRANSLATE_FAIL; int mode = mmu_idx; + target_ulong tlb_size = 0; env->guest_phys_fault_addr = 0; @@ -784,8 +785,13 @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size, } if (ret == TRANSLATE_SUCCESS) { - tlb_set_page(cs, address & TARGET_PAGE_MASK, pa & TARGET_PAGE_MASK, - prot, mmu_idx, TARGET_PAGE_SIZE); + if (pmp_is_range_in_tlb(env, pa & TARGET_PAGE_MASK, &tlb_size)) { + tlb_set_page(cs, address & ~(tlb_size - 1), pa & ~(tlb_size - 1), + prot, mmu_idx, tlb_size); + } else { + tlb_set_page(cs, address & TARGET_PAGE_MASK, pa & TARGET_PAGE_MASK, + prot, mmu_idx, TARGET_PAGE_SIZE); + } return true; } else if (probe) { return false; diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c index aeba796484..adadf6e9ba 100644 --- a/target/riscv/pmp.c +++ b/target/riscv/pmp.c @@ -393,3 +393,55 @@ target_ulong pmpaddr_csr_read(CPURISCVState *env, uint32_t addr_index) return val; } + +/* + * Calculate the TLB size if the start address or the end address of + * PMP entry is presented in thie TLB page. + */ +static target_ulong pmp_get_tlb_size(CPURISCVState *env, int pmp_index, + target_ulong tlb_sa, target_ulong tlb_ea) +{ + target_ulong pmp_sa = env->pmp_state.addr[pmp_index].sa; + target_ulong pmp_ea = env->pmp_state.addr[pmp_index].ea; + + if (pmp_sa >= tlb_sa && pmp_ea <= tlb_ea) { + return pmp_ea - pmp_sa + 1; + } + + if (pmp_sa >= tlb_sa && pmp_sa <= tlb_ea && pmp_ea >= tlb_ea) { + return tlb_ea - pmp_sa + 1; + } + + if (pmp_ea <= tlb_ea && pmp_ea >= tlb_sa && pmp_sa <= tlb_sa) { + return pmp_ea - tlb_sa + 1; + } + + return 0; +} + +/* + * Check is there a PMP entry whcih range covers this page. If so, + * try to find the minimum granularity for the TLB size. + */ +bool pmp_is_range_in_tlb(CPURISCVState *env, hwaddr tlb_sa, + target_ulong *tlb_size) +{ + int i; + target_ulong val; + target_ulong tlb_ea = (tlb_sa + TARGET_PAGE_SIZE - 1); + + for (i = 0; i < MAX_RISCV_PMPS; i++) { + val = pmp_get_tlb_size(env, i, tlb_sa, tlb_ea); + if (val) { + if (*tlb_size == 0 || *tlb_size > val) { + *tlb_size = val; + } + } + } + + if (*tlb_size != 0) { + return true; + } + + return false; +} diff --git a/target/riscv/pmp.h b/target/riscv/pmp.h index 8e19793132..c70f2ea4c4 100644 --- a/target/riscv/pmp.h +++ b/target/riscv/pmp.h @@ -60,5 +60,7 @@ void pmpaddr_csr_write(CPURISCVState *env, uint32_t addr_index, target_ulong pmpaddr_csr_read(CPURISCVState *env, uint32_t addr_index); bool pmp_hart_has_privs(CPURISCVState *env, target_ulong addr, target_ulong size, pmp_priv_t priv, target_ulong mode); +bool pmp_is_range_in_tlb(CPURISCVState *env, hwaddr tlb_sa, + target_ulong *tlb_size); #endif