Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A4A4FCD5BD5 for ; Thu, 28 May 2026 20:13:49 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wSh6r-00020p-6S; Thu, 28 May 2026 16:13:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wSh6q-00020O-5I for qemu-riscv@nongnu.org; Thu, 28 May 2026 16:13:40 -0400 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wSh6n-000807-3h for qemu-riscv@nongnu.org; Thu, 28 May 2026 16:13:39 -0400 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-49041e84237so57325965e9.1 for ; Thu, 28 May 2026 13:13:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1779999215; x=1780604015; darn=nongnu.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=IajTlBHwPTt/Tp1vL2OQG0W56LP4BolHd4GcTegZ2v0=; b=FBBCx4WpDNxNll9thhaV0DBFiZoKJ4BkTxDcqqXcG4XxMDBmqW3px0SjMABmOLugsW 1w7Si73u/jskITws8HtJ2TbwVF5F1MoSbjJBx3zzE7ozNLsvmrCdvfpCuStdjrFmaNfs 7o3op4fk1JaHVbBkYCv0POuh7RaIIsezZt+3GcptfEDiGZVneeGGb03Rm0obRDMmx7+Q yM+Z+h+jYBTGpOojVRYsun7xFpMvyD5CJBml9I9mz51J78pbMmkuhGapHiB738G+sz8N R401dfTbmvKJzbjNnlTJPBqCmgJcNYAbrjeD+/qwklkLdDJxCok3l47QpM+o7LOp6VPF xzxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779999215; x=1780604015; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=IajTlBHwPTt/Tp1vL2OQG0W56LP4BolHd4GcTegZ2v0=; b=YJyUrLgWrpqv998RvLplTVHS7p/wWqmyU3l/gBy7/MeAdjLmqftpAFHB5DSXygwOYM yxY+YysfHrUeHDliIzlVpj3sFViIOfLnk0On5IzvtedCQb09DpGHM0vDL32OlGLMVpMO FcgwvAMNBm6BIrGsCBeHuy7y8641VLLlrZa7TyZyGaLLkbUD/IIAu8WYuyrn4BvHBY+e 8Bnypd68kaHSW9nXm52X74DxjJv+2F6jRpZVu3gcxWZbZYIe4ov8K9MKEaNCC+HcEkIN DP/PnyKPKMhdztiR1Ecy82X4uoJwHSVztU+UuI9L9vIpeeZu6Hhd+ET8acPZwgCaT6Uq 7nEg== X-Forwarded-Encrypted: i=1; AFNElJ/D61ByJkBtndQwJCOP1wi0K73BUUGsowApL+BMzIPyCc2S+Wsa7pOSS1zUFI8sU4Wj/e0+PDoNBZbZ@nongnu.org X-Gm-Message-State: AOJu0Yz4GbKiewOjN9npNAWgSJUlQW7l8dedv9XAD3r5aOXwOYIDQQH7 8g0LgC0Q9DzyzEAuOK4LTYYTCwFRD4i4ydzorGKmYVZOf8342LO4AY9OI7NnDg65y9o= X-Gm-Gg: Acq92OGI/6jTs+qoPBoyIjJ2vp1ibuDZkHUO4DyUV51WfYlXyl/OzKnBOPIyuDv4rlC j6bEk6i/cOIAfU/HO5vjxKjLg9xuS1voXLRvHOyWYVBjPRz7juq7Sp9vlbbU1usov9s5qSD70kN I5dWkzNzYQQ6BG//P7/DHwj6R9eprO3jt9jeyG4LJQdTU5bzf6SgXuysgx3Md5HuHWUyBvNoumE InnODC5/BE8EkINEkCvzZScPhohvjPZETgRE/2PdSfXx/3bSYSXtwiwdr/XOaEDY7F9nHTNIcVn kaWZF/njGtY8GhaR6mNzXsOPkuN8UTYP9pHUZ22AlU2nc5hvixqyugDdL5ZayVAEtH+0ufTB/r5 n53BG7J6kc/4B/EtCqGmTqmStLlwU+bK8MG5cyvNZA98PrBwDPIBdi+9Jk9luKP6E5GgnQv5Y9s xvS1A36E+TYoa9FSOl30qszOyiszu2jgMC6cS8A9TdiJp7V+YbVJ7ja5JRViYKJQOqPcgT/Ieh7 j03 X-Received: by 2002:a05:600c:6a84:b0:490:3cf0:8d81 with SMTP id 5b1f17b1804b1-4909c087135mr94915e9.13.1779999214757; Thu, 28 May 2026 13:13:34 -0700 (PDT) Received: from [192.168.69.207] (88-187-86-199.subs.proxad.net. [88.187.86.199]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49092654d10sm59928175e9.6.2026.05.28.13.13.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 28 May 2026 13:13:33 -0700 (PDT) Message-ID: Date: Thu, 28 May 2026 22:13:31 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v11 03/12] target/riscv: Assert PTE.N/PBMT bits are not expected on RV32 Content-Language: en-US To: Daniel Henrique Barboza , qemu-devel@nongnu.org Cc: Pierrick Bouvier , qemu-riscv@nongnu.org, Djordje Todorovic , Anton Johansson , Weiwei Li , Liu Zhiwei , Chao Liu , Palmer Dabbelt , Alistair Francis , Christoph Muellner References: <20260527201348.29511-1-philmd@linaro.org> <20260527201348.29511-4-philmd@linaro.org> <200e1664-a690-4fe7-bda3-074da046e311@oss.qualcomm.com> From: =?UTF-8?Q?Philippe_Mathieu-Daud=C3=A9?= In-Reply-To: <200e1664-a690-4fe7-bda3-074da046e311@oss.qualcomm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2a00:1450:4864:20::332; envelope-from=philmd@linaro.org; helo=mail-wm1-x332.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-riscv@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-riscv-bounces+qemu-riscv=archiver.kernel.org@nongnu.org Sender: qemu-riscv-bounces+qemu-riscv=archiver.kernel.org@nongnu.org On 28/5/26 22:01, Daniel Henrique Barboza wrote: > > > On 5/27/2026 5:13 PM, Philippe Mathieu-Daudé wrote: >> PTE_N and PTE_PBMT are undefined on RV64, assert we are not >> under RV32. >> > > I didn't find this info in the RV priv ISA.  Can you please quote the > except it in the commit msg? > > Maybe you meant "undefined on RV32"? Yes :) >> Signed-off-by: Philippe Mathieu-Daudé >> --- >>   target/riscv/cpu_helper.c | 2 ++ >>   1 file changed, 2 insertions(+) >> >> diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c >> index 17305e1bb75..f86bfdb32e7 100644 >> --- a/target/riscv/cpu_helper.c >> +++ b/target/riscv/cpu_helper.c >> @@ -1490,6 +1490,7 @@ static int get_physical_address(CPURISCVState >> *env, hwaddr *physical, >>           return TRANSLATE_FAIL; >>       } >>       if (!pbmte && (pte & PTE_PBMT)) { >> +        assert(riscv_cpu_sxl(env) != MXL_RV32); > > > What I understood from the RV priv ISA w.r.t PTE_PMBT is that it doesn't > have much to do with SXLEN/riscv_cpu_sxl().  PTE_PBMT is a bits 62|61 field > that determine override mem attributes when we have the 'svpbmt' extension > enabled.  'svpbmt' is dependent on satp_mode sv39 or greater, which happens > to be riscv64 only. > > I didn't see any restrictions of SXLEN=32 in the 'svpbmt' chapter in the > RISC-V ISA, e.g. PTE_PMBT set to a non-zero val and SXLEN=32 seems to be > a valid combo - a riscv64 target running sv39+ can use svpbmt to override > PTE properties in a SXLEN=32 context. It was hard to figure that out by myself. > Now, PTE_PBMT is not writable when MXLEN=32 (i.e. riscv_cpu_mxl() == > MXL_RV32), > and maybe this is what you're trying to do. Yes. >  In this case the assert might > be justifiable, although we just landed a recent fix in Alistair's tree > that disables svpbmt for riscv32 entirely, and this also means that > PTE_PBMT won't ever be set.  But if the assert (with MXL, not SXL) would > give > some sort of guarantee aside from the bit being set, by all means go ahead. I'll wait to see that merged before revisiting. This patch is not required for this series, I was trying to make sense of this huge function while reviewing it. >>           /* Reserved without Svpbmt. */ >>           qemu_log_mask(LOG_GUEST_ERROR, "%s: PBMT bits set in PTE, " >>                         "and Svpbmt extension is disabled: " >> @@ -1643,6 +1644,7 @@ static int get_physical_address(CPURISCVState >> *env, hwaddr *physical, >>       target_ulong vpn = addr >> PGSHIFT; >>       if (riscv_cpu_cfg(env)->ext_svnapot && (pte & PTE_N)) { >> +        assert(riscv_cpu_sxl(env) != MXL_RV32); > > > All the stuff I said above happens to be applicable for PTE_N.  This is > a bit > that indicates if the PTE represents a "naturally aligned power-of-2" > range, > or NAPOT range, and this is specified by another extension called > 'svnapot'. > This extension is also sv39+ exclusive, which means riscv64 exclusive, > and it > doesn't seem to have any restrictions with SXLEN=32. OK. Let's discard this patch :) > > > Thanks, > Daniel > >>           napot_bits = ctzl(ppn) + 1; >>           if ((i != (levels - 1)) || (napot_bits != 4)) { >>               return TRANSLATE_FAIL; >