From nobody Mon Nov 23 22:39:59 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=vates.tech ARC-Seal: i=1; a=rsa-sha256; t=1793027708; cv=none; d=zohomail.com; s=zohoarc; b=LcNlJZehaHUr8Oey8+SKWE4im9SwJ8WslCl49xvA8luftFxVUKVr8b9KZdwywvxEEBX+u/RBkSSxjMUGdxo8as4aHTxS+diDU2OsPch4abXmUI+cSf4BEpE4uGm1ySDtcdXmXZAhvEfOG5B4046CPWBEpWSfaNXenmm2wifXamY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793027708; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=wjEhviDbcT9pueHXVGdYgzTkA0vnOrtJ8lu8wj6hDgI=; b=g1o3VlQSf/vX141ilFQnUZPkUUwCYc8O79NRnpdkTUGN8q/12Mj5ZmgXLdbxB5NkvTvYy0j5Et2xS+Iu88OLF8ACQb6i+INRKFdFLC8yCSwp6lv0khYygUx4h+W3PsSr1Fcf57sa/WsWsjIQ2XXq2bS25fGzEH9Y7XoLtD8VoXM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1793027708558615.7420607989435; Mon, 26 Oct 2026 08:15:08 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1461473.1672485 (Exim 4.92) (envelope-from ) id 1xLMPS-0004iY-Qm; Mon, 26 Oct 2026 15:14:50 +0000 Received: by outflank-mailman (output) from mailman id 1461473.1672485; Mon, 26 Oct 2026 15:14:50 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xLMPS-0004iR-Nx; Mon, 26 Oct 2026 15:14:50 +0000 Received: by outflank-mailman (input) for mailman id 1461473; Mon, 26 Oct 2026 15:14:49 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) id 1xLMPR-0004iJ-NE for xen-devel@lists.xenproject.org; Mon, 26 Oct 2026 15:14:49 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1xLMPQ-003d5Y-PF for xen-devel@lists.xenproject.org; Mon, 26 Oct 2026 16:14:48 +0100 Received: from [10.42.69.8] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6adf6e59-8faa-0a2a0a5109dd-0a2a4508df58-40 for ; Mon, 26 Oct 2026 16:14:48 +0100 Received: from [185.255.28.35] (helo=prod-mta-13-02.swg-srv.net) by tlsNG-c1860d.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6adf6e68-f659-0a2a45080019-b9ff1c238a77-3 for ; Mon, 26 Oct 2026 16:14:48 +0100 Received: from mail2.vates.fr ([37.26.189.201] mail2.vates.fr) (Authenticated sender: 8631fc262581453bbf619ec5b2062170/smtp/7773de5a-2839-4720-82ee-e06722ae1d3e) by prod-mta-13-02.swg-srv.net (ZoneMTA - prod-mta-13) with ESMTPSA id 1a178c7355f000f79f.007 for (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Mon, 26 Oct 2026 15:14:43 +0000 Received: from leducb.home (areims-651-1-80-194.w90-18.abo.wanadoo.fr [90.18.187.194]) (Authenticated sender: baptiste.le-duc) by mail2.vates.fr (Postfix) with ESMTPSA id B3CBE815DF; Mon, 26 Oct 2026 16:14:42 +0100 (CET) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=vates.tech header.i="@vates.tech" header.h="From:Subject:Date:Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding:In-Reply-To:References:Feedback-ID" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vates.tech; q=dns/txt; s=selector1; bh=wjEhviDbcT9pueHXVGdYgzTkA0vnOrtJ8lu8wj6hDgI=; h=from:subject:date:message-id:to:cc:mime-version:content-type:content-transfer-encoding:in-reply-to:references:feedback-id; b=cl/AkVMm6tuP7u2ff56WU60KpqsWkRBbcnUoEit04kHMoLtTV58dam7H8nYv2ApCxlYo8c9AD 48gmf94xX+JxzLM7ewUNrLKZAqMtn0r2/b2B6Y8iIBlP0OHIjwrCGp6D9JiuIbwspghD2bXtS0G n30shmqAUf42cL+uqJj1te5vRwC0ifgV9SQFAFTEFpFGinkfsbmpkngYzbP8qMlt7sz4uYlm+7y CfRXqzDiFl9VnAn287HwTHSGtxDg9En4QcBr/GGp2qqT3HQTJhDUhA6+Ch6ZvJes1tYJdtqH33A zAqD0FCK5XMYbY8MV2Vj7IoYSJxDpHAvoXQbWBzhD30Q== X-Zone-Loop: 2de933f4cb81fa1905198a0746675615d4f21e7a3708 x-campaign-type: default x-transaction-id: ae68d5d8-619e-46d3-81b7-56caea521fbd x-swg-uid: 01-6e1abd89-f7e5-4f1d-beea-d5ea9e4d58be X-Mailer: Sweego Message-ID: <1793027683.8631fc262581453bbf619ec5b2062170.1a178c7355f000f79f@vates.tech> x-swg-bid: 1793027683.8631fc262581453bbf619ec5b2062170.1a178c7355f000f79f Feedback-ID: default:8631fc262581453bbf619ec5b2062170:Sweego x-campaign-id: default x-client-id: 8631fc262581453bbf619ec5b2062170 X-Originating-IP: [37.26.189.201] From: Baptiste Le Duc To: xen-devel@lists.xenproject.org Cc: Baptiste Le Duc , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Stefano Stabellini , Alistair Francis , Connor Davis , Oleksii Kurochko , Zheng Zhang Subject: [PATCH v8 1/5] xen/riscv: use pte_is_valid() in pte_is_mapping() Date: Mon, 26 Oct 2026 16:14:33 +0100 In-Reply-To: <1793027589.8631fc262581453bbf619ec5b2062170.1a178c5c430000f79f@vates.tech> References: <1793027589.8631fc262581453bbf619ec5b2062170.1a178c5c430000f79f@vates.tech> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" X-Developer-Signature: v=1; a=ed25519-sha256; t=1793027331; l=1365; i=baptiste.le-duc@vates.tech; s=20260810; h=from:subject:message-id; bh=TR/botraZWIEW3mqExx0XFYiNlY/hru2IatTX7DUjvI=; b=MoZU/esrYk8YjmKuafvbQM8nrTwtLuNkSuV1hWfopxzFcgMX0fALYWkhmyHKvDcOPooNm69dj nP9pZfb44pQBaCEiuZ2AVdT7/IWkyJ0Mm/OMD6j6Ea4U/C/jYQulQhr X-Developer-Key: i=baptiste.le-duc@vates.tech; a=ed25519; pk=N+BbdvMXRzrCuX/ieh4RWodiAKcLNvI+KjflcZ0oXCo= Content-Transfer-Encoding: quoted-printable X-Bm-Milter-Handled: 4ffbd6c1-ee69-4e1b-aabd-f977039bd3e2 X-Bm-Transport-Timestamp: 1793027682927 X-purgate-ID: tlsNG-c1860d/1793027688-CEF5F87B-57C29B8B/10/78276251493 X-purgate-type: spam X-purgate-size: 1367 X-ZohoMail-DKIM: pass (identity @vates.tech) X-ZM-MESSAGEID: 1793027709349158500 Use pte_is_valid() instead of open-coding the PTE_VALID check. No functional change. Assisted-by: Claude:claude-opus-5 Signed-off-by: Baptiste Le Duc Reviewed-by: Oleksii Kurochko Acked-by: Jan Beulich --- Changes since v7: - collect A-by. --- Changes since v6: - rebase, as moving the patch ahead in the series changed its context in pte_is_mapping(). --- Changes since v5: - no changes, already reviewed and waiting to be merged. --- Changes since v4: - rebase on top of staging. --- Changes since v3: - no changes. - add trailers. --- Changes since v2: - new patch. --- xen/arch/riscv/include/asm/page.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xen/arch/riscv/include/asm/page.h b/xen/arch/riscv/include/asm= /page.h index b465a90325..c8bb334b85 100644 --- a/xen/arch/riscv/include/asm/page.h +++ b/xen/arch/riscv/include/asm/page.h @@ -187,7 +187,7 @@ static inline bool pte_is_mapping(pte_t p) /* See pte_is_table() */ ASSERT(((p.pte & PAGE_HYPERVISOR_RW) !=3D (PTE_VALID | PTE_WRITABLE))); =20 - return (p.pte & PTE_VALID) && (p.pte & PTE_ACCESS_MASK); + return pte_is_valid(p) && (p.pte & PTE_ACCESS_MASK); } =20 static inline bool pte_is_superpage(pte_t p, unsigned int level) --=20 2.56.0 From nobody Mon Nov 23 22:39:59 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=vates.tech ARC-Seal: i=1; a=rsa-sha256; t=1793027708; cv=none; d=zohomail.com; s=zohoarc; b=GLehkAXaz5qhMvxvD3WrgG2sFixDBTitlbsv7HAYPfJfQ/AJc6NSzIj+14XAd6BXiORd6Pk8cAuvm850UgSwCb15CMIsprM9tN6+ciVe/WsQC+YYIfMbfBlBqdmlWgimept0a+H/1vzkoQIT7tL9iIQ+GLz7pFGqt/CauOv3TA8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793027708; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=BEakajGWIf4LAv0+KdHp6x8rDSwbOS2sEWIM5GTzxlI=; b=mrvCw9YsbvZsaWqwfzAow6J7BM/NSNQc67XUYYF8bRIpwlzywU/Ec2jPaGmFpO0ExMCO+45C3r1KlGCk1kMGjQLM2aLUyGixaMAS9Hjin2sYh/bxYt1meYzKlAA3HSMjBVgGj5fvZR7w2YRdkWmi4khQB9fTT+sSxhZokqmIZ+8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1793027707898111.70359533438034; Mon, 26 Oct 2026 08:15:07 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1461474.1672494 (Exim 4.92) (envelope-from ) id 1xLMPX-0004wW-11; Mon, 26 Oct 2026 15:14:55 +0000 Received: by outflank-mailman (output) from mailman id 1461474.1672494; Mon, 26 Oct 2026 15:14:55 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xLMPW-0004wO-UC; Mon, 26 Oct 2026 15:14:54 +0000 Received: by outflank-mailman (input) for mailman id 1461474; Mon, 26 Oct 2026 15:14:53 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) id 1xLMPV-0004vo-Q1 for xen-devel@lists.xenproject.org; Mon, 26 Oct 2026 15:14:53 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1xLMPV-00DhdS-6h for xen-devel@lists.xenproject.org; Mon, 26 Oct 2026 16:14:53 +0100 Received: from [10.42.69.8] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6adf6e6b-e002-0a2a0a5209dd-0a2a4508c308-2 for ; Mon, 26 Oct 2026 16:14:53 +0100 Received: from [185.255.28.35] (helo=prod-mta-13-02.swg-srv.net) by tlsNG-c1860d.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6adf6e68-f659-0a2a45080019-b9ff1c238a77-4 for ; Mon, 26 Oct 2026 16:14:53 +0100 Received: from mail2.vates.fr ([37.26.189.201] mail2.vates.fr) (Authenticated sender: 8631fc262581453bbf619ec5b2062170/smtp/7773de5a-2839-4720-82ee-e06722ae1d3e) by prod-mta-13-02.swg-srv.net (ZoneMTA - prod-mta-13) with ESMTPSA id 1a178c7373e000f79f.007 for (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Mon, 26 Oct 2026 15:14:44 +0000 Received: from leducb.home (areims-651-1-80-194.w90-18.abo.wanadoo.fr [90.18.187.194]) (Authenticated sender: baptiste.le-duc) by mail2.vates.fr (Postfix) with ESMTPSA id 55E4D81DAB; Mon, 26 Oct 2026 16:14:43 +0100 (CET) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=vates.tech header.i="@vates.tech" header.h="From:Subject:Date:Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding:In-Reply-To:References:Feedback-ID" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vates.tech; q=dns/txt; s=selector1; bh=BEakajGWIf4LAv0+KdHp6x8rDSwbOS2sEWIM5GTzxlI=; h=from:subject:date:message-id:to:cc:mime-version:content-type:content-transfer-encoding:in-reply-to:references:feedback-id; b=cBWH6k1M+xwapho8bUp5WAL+HJH0rH1z230l696ANNB9KQcvmY7zLKRbt0v7IexfAdgGJEoQm sY1rtBm7EaQkBKfo6jp5THQYIno1ZwA73+rFdoKunj8YdlyHYW3+9V81muGQ3jbfkPbolx4MKgp Q/pGc/p3OStjajel8SFd+764TuWk5lpeIZB6mCuhXGK4NL7R97Ig7oc3NhsFTkruJBKk3uWFpSi vuZPDuU0bxz0WBumf017DRMsugZi2CFCNQ51lhOXD+1BYasusz9cQwIlAgMmJBQVq0/+7IkKo93 zktGS69Zbb8RjHx5hEwHWjZbn4uwfY++RjpvIW0I01Ww== X-Zone-Loop: e35bf4dbb0f12bb4a17d10a26a0ab471ea6b595f8f5e x-campaign-type: default x-transaction-id: ff6cdbcc-aebf-46ef-9970-30530ccb3459 x-swg-uid: 01-0613efb9-1d56-44ea-80bb-626674cd8285 X-Mailer: Sweego Message-ID: <1793027684.8631fc262581453bbf619ec5b2062170.1a178c7373e000f79f@vates.tech> x-swg-bid: 1793027684.8631fc262581453bbf619ec5b2062170.1a178c7373e000f79f Feedback-ID: default:8631fc262581453bbf619ec5b2062170:Sweego x-campaign-id: default x-client-id: 8631fc262581453bbf619ec5b2062170 X-Originating-IP: [37.26.189.201] From: Baptiste Le Duc To: xen-devel@lists.xenproject.org Cc: Baptiste Le Duc , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Stefano Stabellini , Alistair Francis , Connor Davis , Oleksii Kurochko , Zheng Zhang Subject: [PATCH v8 2/5] xen/riscv: fix A/D bits in Xen's page-table mappings Date: Mon, 26 Oct 2026 16:14:34 +0100 In-Reply-To: <1793027589.8631fc262581453bbf619ec5b2062170.1a178c5c430000f79f@vates.tech> References: <1793027589.8631fc262581453bbf619ec5b2062170.1a178c5c430000f79f@vates.tech> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" X-Developer-Signature: v=1; a=ed25519-sha256; t=1793027331; l=8050; i=baptiste.le-duc@vates.tech; s=20260810; h=from:subject:message-id; bh=z2JA5ykm5jV3OWJlXaV6V4FclNBYupnFTEqpKHl8hJU=; b=jvzkOplkM3u99GMDbajurUUlsQuoad9RAE6VgqclDRnPsvuZKo5KVhD4+J014TW/OlRkv/ntS IGglk5XGfVWAD61rznvUH8LoezqwMbROZb7ytCKvEU2VHWbuAiqFw5P X-Developer-Key: i=baptiste.le-duc@vates.tech; a=ed25519; pk=N+BbdvMXRzrCuX/ieh4RWodiAKcLNvI+KjflcZ0oXCo= Content-Transfer-Encoding: quoted-printable X-Bm-Milter-Handled: 4ffbd6c1-ee69-4e1b-aabd-f977039bd3e2 X-Bm-Transport-Timestamp: 1793027683537 X-purgate-ID: tlsNG-c1860d/1793027693-DFAD487B-C812CC5C/10/78276251493 X-purgate-type: spam X-purgate-size: 8052 X-ZohoMail-DKIM: pass (identity @vates.tech) X-ZM-MESSAGEID: 1793027711425158500 Xen does not handle page faults caused by clear A/D bits, so it presets them when creating PTEs. pt_update_entry() does so, but three places build leaf PTEs directly without going through it: setup_initial_mapping() (the boot page tables), check_pgtbl_mode_support() (the temporary root entry used to probe SATP mode support) and arch_pmap_map() (the fixmap). On implementations that fault on clear A/D bits (Svade), all three fault on first access. For check_pgtbl_mode_support(), the fault is raised by the instruction fetch right after the SATP write, before any trap handler is set. Add PTE_ACCESSED and PTE_DIRTY to PAGE_HYPERVISOR_RO, and build PAGE_HYPERVISOR_RW and PAGE_HYPERVISOR_RX on top of it. PTE_DIRTY is set in all cases for consistency with pt_update_entry() which sets it at runtime. This fixes arch_pmap_map() for free, since it already builds its PTE from PAGE_HYPERVISOR_RW. Switch setup_initial_mapping() to use these macros for its default, text and rodata permissions, and check_pgtbl_mode_support() to use PAGE_HYPERVISOR_RX for its temporary root entry. The latter drops PTE_WRITABLE, going from RWX to RX, but this is harmless, as that entry only has to make the current instruction stream fetchable between the two CSR_SATP writes, and nothing writes through it. Drop the now-redundant PTE_LEAF_DEFAULT, since converting the last open-coded site above leaves it with no user outside page.h itself. pte_is_table() and pte_is_mapping() both assert that a PTE doesn't use one of the two reserved encodings, (V=3D1, W=3D1, R=3D0) and (V=3D1, X=3D1, W= =3D1, R=3D0), by masking it with PAGE_HYPERVISOR_RW. Now that PAGE_HYPERVISOR_RW also carries A and D, a reserved PTE with A or D set would no longer be caught. Mask with the V, R and W bits explicitly instead, and factor the check out into pte_has_reserved_rwx(). Fixes: e66003e7be19 ("xen/riscv: introduce setup_initial_pages") Fixes: f89e1a170299 ("xen/riscv: introduce asm/pmap.h header") Assisted-by: Claude:claude-opus-5 Signed-off-by: Baptiste Le Duc Reviewed-by: Oleksii Kurochko Tested-by: Zhang Zheng Acked-by: Jan Beulich --- Changes since v7: - collect A-by and T-by. --- Changes since v6: - add a 2nd Fixes tag, as arch_pmap_map() was introduced by a later commit. --- Changes since v5: - no changes, already reviewed and waiting to be merged. --- Changes since v4: - rebase on top of staging. - add a missing changes line in "Changes since v3". --- Changes since v3: - rebase patch 2/6 which modified wrong indentation. - change commit message to address review comments. - rename pte_is_reserved() to pte_has_reserved_rwx() --- Changes since v2: - add fixes commit ref. - add A/D bits to PAGE_HYPERVISOR_RO and derive PAGE_HYPERVISOR_RW/RX from it for consistency with runtime. - introduce pte_is_reserved() to factor out the reserved-encoding assert shared by pte_is_table() and pte_is_mapping(). - reword commit title --- Changes since v1: - change commit title - mention in patch message that arch_pmap_map() is fixed too, via the PAGE_HYPERVISOR_RW change, not just setup_initial_mapping(). - convert check_pgtbl_mode_support()'s temporary root entry to PAGE_HYPERVISOR_RX, as it's harmless. - drop PTE_LEAF_DEFAULT entirely instead of keeping it, now that no site open-codes it anymore. - drop the pte_is_table() comment line that referenced PAGE_HYPERVISOR_RW, now stale. --- xen/arch/riscv/include/asm/page.h | 33 +++++++++++++++++---------------- xen/arch/riscv/mm.c | 11 +++++------ 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/xen/arch/riscv/include/asm/page.h b/xen/arch/riscv/include/asm= /page.h index c8bb334b85..f9e59e61de 100644 --- a/xen/arch/riscv/include/asm/page.h +++ b/xen/arch/riscv/include/asm/page.h @@ -46,12 +46,12 @@ #define PTE_PBMT_NOCACHE BIT(61, UL) #define PTE_PBMT_IO BIT(62, UL) =20 -#define PTE_LEAF_DEFAULT (PTE_VALID | PTE_READABLE | PTE_WRITAB= LE) #define PTE_TABLE (PTE_VALID) =20 -#define PAGE_HYPERVISOR_RO (PTE_VALID | PTE_READABLE) -#define PAGE_HYPERVISOR_RW (PTE_VALID | PTE_READABLE | PTE_WRITAB= LE) -#define PAGE_HYPERVISOR_RX (PTE_VALID | PTE_READABLE | PTE_EXECUT= ABLE) +#define PAGE_HYPERVISOR_RO (PTE_VALID | PTE_READABLE | \ + PTE_ACCESSED | PTE_DIRTY) +#define PAGE_HYPERVISOR_RW (PAGE_HYPERVISOR_RO | PTE_WRITABLE) +#define PAGE_HYPERVISOR_RX (PAGE_HYPERVISOR_RO | PTE_EXECUTABLE) =20 #define PAGE_HYPERVISOR PAGE_HYPERVISOR_RW /* @@ -161,31 +161,32 @@ static inline bool pte_is_valid(pte_t p) * X W R Meaning * 0 0 0 Pointer to next level of page table. * 0 0 1 Read-only page. - * 0 1 0 Reserved for future use. + * 0 1 0 Reserved for future use. [1] * 0 1 1 Read-write page. * 1 0 0 Execute-only page. * 1 0 1 Read-execute page. - * 1 1 0 Reserved for future use. + * 1 1 0 Reserved for future use. [2] * 1 1 1 Read-write-execute page. + * + * So if V=3D1 and W=3D1 then R also needs to be 1 as R =3D 0 is reserve= d for + * future use ([1], [2]). */ +static inline bool pte_has_reserved_rwx(pte_t p) +{ + return (p.pte & (PTE_VALID | PTE_READABLE | PTE_WRITABLE)) =3D=3D + (PTE_VALID | PTE_WRITABLE); +} + static inline bool pte_is_table(pte_t p) { - /* - * According to the spec if V=3D1 and W=3D1 then R also needs to be 1 = as - * R =3D 0 is reserved for future use ( look at the Table 4.5 ) so che= ck - * in ASSERT that if (V=3D=3D1 && W=3D=3D1) then R isn't 0. - * - * PAGE_HYPERVISOR_RW contains PTE_VALID too. - */ - ASSERT(((p.pte & PAGE_HYPERVISOR_RW) !=3D (PTE_VALID | PTE_WRITABLE))); + ASSERT(!pte_has_reserved_rwx(p)); =20 return ((p.pte & (PTE_VALID | PTE_ACCESS_MASK)) =3D=3D PTE_VALID); } =20 static inline bool pte_is_mapping(pte_t p) { - /* See pte_is_table() */ - ASSERT(((p.pte & PAGE_HYPERVISOR_RW) !=3D (PTE_VALID | PTE_WRITABLE))); + ASSERT(!pte_has_reserved_rwx(p)); =20 return pte_is_valid(p) && (p.pte & PTE_ACCESS_MASK); } diff --git a/xen/arch/riscv/mm.c b/xen/arch/riscv/mm.c index 06f0406781..6f7dcd10b2 100644 --- a/xen/arch/riscv/mm.c +++ b/xen/arch/riscv/mm.c @@ -140,19 +140,18 @@ static void __init setup_initial_mapping(struct mmu_d= esc *mmu_desc, case 1: /* Level 0 */ { unsigned long paddr =3D (page_addr - map_start) + pa_start; - unsigned int pte_flags =3D PTE_LEAF_DEFAULT; + unsigned int pte_flags =3D PAGE_HYPERVISOR_RW; unsigned long addr =3D is_identity_mapping ? page_addr : virt_to_maddr(page_addr= ); pte_t pte_to_be_written; =20 index =3D pt_index(0, page_addr); =20 - if ( is_kernel_text(addr) || - is_kernel_inittext(addr) ) - pte_flags =3D PTE_EXECUTABLE | PTE_READABLE | PTE_VALI= D; + if ( is_kernel_text(addr) || is_kernel_inittext(addr) ) + pte_flags =3D PAGE_HYPERVISOR_RX; =20 if ( is_kernel_rodata(addr) ) - pte_flags =3D PTE_READABLE | PTE_VALID; + pte_flags =3D PAGE_HYPERVISOR_RO; =20 pte_to_be_written =3D paddr_to_pte(paddr, pte_flags); =20 @@ -197,7 +196,7 @@ static bool __init check_pgtbl_mode_support(struct mmu_= desc *mmu_desc, =20 index =3D pt_index(page_table_level, aligned_load_start); stage1_pgtbl_root[index] =3D paddr_to_pte(aligned_load_start, - PTE_LEAF_DEFAULT | PTE_EXECUTA= BLE); + PAGE_HYPERVISOR_RX); =20 sfence_vma(); csr_write(CSR_SATP, --=20 2.56.0 From nobody Mon Nov 23 22:39:59 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=vates.tech ARC-Seal: i=1; a=rsa-sha256; t=1793027713; cv=none; d=zohomail.com; s=zohoarc; b=Gup8UjtWZS7YtVxCBRbmBXR8PGuEWOorepgsttgi8Cnz6WJFhgDEyUpV1hPyxTFyi9wSa4HnHyNvOtgvrAqUdgvcIThjbGpW0u0DRCFRmiJ05ezg6F0oV+jUqw/Hfhck4DISXR+SyWSv741eLo0NQbR85dE3x4OPt73lqSuM2Vg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793027713; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=t+sYHvCIm+RgMaIUIOoBUgA8H4OGZB50SGJyJUcLCR8=; b=aBhd4f6vQfv8pIaLy496KCHYoQnStdE8l6LCQJyoGWM0Aex9a2cw1Xqyqo+d1sTVplzk32dMlNvCkDPLDTqomZrFG302n/ClNziqywKvoqX5BJu/YJubGWFyWCePg2yQ1OAdp0jbKXRWdBgQI2A8A5mDZucSAaagl6lmDeY1Hmw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1793027713010863.6396248154015; Mon, 26 Oct 2026 08:15:13 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1461475.1672504 (Exim 4.92) (envelope-from ) id 1xLMPZ-0005Bp-7q; Mon, 26 Oct 2026 15:14:57 +0000 Received: by outflank-mailman (output) from mailman id 1461475.1672504; Mon, 26 Oct 2026 15:14:57 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xLMPZ-0005Bf-4f; Mon, 26 Oct 2026 15:14:57 +0000 Received: by outflank-mailman (input) for mailman id 1461475; Mon, 26 Oct 2026 15:14:56 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) id 1xLMPX-000587-V7 for xen-devel@lists.xenproject.org; Mon, 26 Oct 2026 15:14:56 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1xLMPX-003d6B-Bw for xen-devel@lists.xenproject.org; Mon, 26 Oct 2026 16:14:55 +0100 Received: from [10.42.69.1] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6adf6e68-2eae-0a2a0a5409dd-0a2a450197f4-18 for ; Mon, 26 Oct 2026 16:14:55 +0100 Received: from [185.255.28.34] (helo=prod-mta-13-01.swg-srv.net) by tlsNG-d62444.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6adf6e6e-5984-0a2a45010019-b9ff1c229eb1-3 for ; Mon, 26 Oct 2026 16:14:55 +0100 Received: from mail2.vates.fr ([37.26.189.201] mail2.vates.fr) (Authenticated sender: 8631fc262581453bbf619ec5b2062170/smtp/7773de5a-2839-4720-82ee-e06722ae1d3e) by prod-mta-13-01.swg-srv.net (ZoneMTA - prod-mta-13) with ESMTPSA id 1a178c73927000f79f.007 for (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Mon, 26 Oct 2026 15:14:44 +0000 Received: from leducb.home (areims-651-1-80-194.w90-18.abo.wanadoo.fr [90.18.187.194]) (Authenticated sender: baptiste.le-duc) by mail2.vates.fr (Postfix) with ESMTPSA id CFC8C815DF; Mon, 26 Oct 2026 16:14:43 +0100 (CET) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=vates.tech header.i="@vates.tech" header.h="From:Subject:Date:Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding:In-Reply-To:References:Feedback-ID" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vates.tech; q=dns/txt; s=selector1; bh=t+sYHvCIm+RgMaIUIOoBUgA8H4OGZB50SGJyJUcLCR8=; h=from:subject:date:message-id:to:cc:mime-version:content-type:content-transfer-encoding:in-reply-to:references:feedback-id; b=VER+rCJKjd9Ir8L9fZ5tx9jZnHY0DBzo/pI64r+XoTfbSvzJlLkkp9++tUqpaLVU0nlIahbW4 chbupQTmI0GAfbBuvq8FhKPrMVHL7Jk/MMUrZkEvAXRCjrXE9GwZgrGtV00+18QHzR9ggwPP73H d825PoGpCgS4mzAQTOOYnYyyE9Ak8KaV5WU7tm6IkW2jiWbQP1w4oXEYcJmJnWTdG3zdZo6iv8+ hyr0LEq7+HKGlAYF0Uk1q6Yi6Tpy0vZyBZfzBLrmGhRnpFpDDsp7LR2rD6z/4Xb6eRqb+Rub4Mc RkyDoDDB+GhTeRjQTZHvFYtNIbBXh2hai0dsR4qf91tA== X-Zone-Loop: 3b1306b5a00d61bd7c75e80f7dcee9acd7d8c45c7d27 x-campaign-type: default x-transaction-id: 1f1c4991-2807-499a-8576-ea5da85cc1c6 x-swg-uid: 01-4109e937-9acb-45d0-a3fc-b8b5bd1af557 X-Mailer: Sweego Message-ID: <1793027684.8631fc262581453bbf619ec5b2062170.1a178c73927000f79f@vates.tech> x-swg-bid: 1793027684.8631fc262581453bbf619ec5b2062170.1a178c73927000f79f Feedback-ID: default:8631fc262581453bbf619ec5b2062170:Sweego x-campaign-id: default x-client-id: 8631fc262581453bbf619ec5b2062170 X-Originating-IP: [37.26.189.201] From: Baptiste Le Duc To: xen-devel@lists.xenproject.org Cc: Baptiste Le Duc , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Stefano Stabellini , Alistair Francis , Connor Davis , Oleksii Kurochko , Zheng Zhang Subject: [PATCH v8 3/5] xen/riscv: look up the exception table for any trap taken in Xen context Date: Mon, 26 Oct 2026 16:14:35 +0100 In-Reply-To: <1793027589.8631fc262581453bbf619ec5b2062170.1a178c5c430000f79f@vates.tech> References: <1793027589.8631fc262581453bbf619ec5b2062170.1a178c5c430000f79f@vates.tech> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" X-Developer-Signature: v=1; a=ed25519-sha256; t=1793027331; l=4280; i=baptiste.le-duc@vates.tech; s=20260810; h=from:subject:message-id; bh=ynAPBxEe/se6dosPBRPOshvwbc043xikGQQ7S5foXVM=; b=0GnQZgaD4G+8xSfn7Y6gVoCK3zvhzwmVV/jC+HWZnZDEbDdEwyk76m6I9NylOX0Cuyu/KZVdj A35uan9etfmB0/AiXtudVFpriZu5zclSL2nPSsGol2e3dvDQSSU4Onj X-Developer-Key: i=baptiste.le-duc@vates.tech; a=ed25519; pk=N+BbdvMXRzrCuX/ieh4RWodiAKcLNvI+KjflcZ0oXCo= Content-Transfer-Encoding: quoted-printable X-Bm-Milter-Handled: 4ffbd6c1-ee69-4e1b-aabd-f977039bd3e2 X-Bm-Transport-Timestamp: 1793027684041 X-purgate-ID: tlsNG-d62444/1793027695-BCF47757-7AB22778/10/73395122804 X-purgate-type: spam X-purgate-size: 4337 X-ZohoMail-DKIM: pass (identity @vates.tech) X-ZM-MESSAGEID: 1793027715453158500 From: Oleksii Kurochko do_trap() consulted the exception table only for CAUSE_ILLEGAL_INSTRUCTION, which covers csr_read_safe() but not a probing access faulting with a page fault cause: it would reach do_unexpected_trap() instead of its fixup. There is no such access yet, the A/D update scheme probe will be the first. Move the lookup ahead of the cause switch, and only do it for exceptions taken in Xen context. Both other cases must skip it: - Traps taken from the guest: sepc is then a guest address, which the guest can point at an address listed in the exception table, making Xen act on an entry fully under guest control. Entries are matched by exact address, so this needs no more than a numerical collision. - Interrupts: an interrupt taken at an address listed in the table would otherwise be "fixed up" as if the access itself had faulted, silently skipping it. Returning early skips check_for_pcpu_work(), which is correct: that only runs for traps taken from the guest. Cache the "trap came from the guest" test in a local as it is now used three times. Signed-off-by: Oleksii Kurochko [Baptiste: drop the parts depending on the vAPLIC/vIMSIC series, adapt the commit message] Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Baptiste Le Duc Acked-by: Jan Beulich Reviewed-by: Oleksii Kurochko --- Changes since v7: - new patch, needed by the A/D update scheme probe of the next patch, whose store page fault would otherwise not be fixed up. Taken from: https://patch.msgid.link/4e2b4e7a99f4d2133ff92559303d19382749de7a.1790779= 209.git.oleksii.kurochko@gmail.com - commit message adapted to this subset: drop the hlv/hlvx and EX_TYPE_TRAP_INFO parts and the paragraph on the guest page fault BUG_ON(), whose code isn't taken; mention the from_guest local, which this subset introduces. - apply my v3 review suggestion to the commit message: state up front that the lookup is only done for exceptions taken in Xen context and list traps taken from the guest and interrupts as the skipped cases. --- xen/arch/riscv/traps.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/xen/arch/riscv/traps.c b/xen/arch/riscv/traps.c index 10d6855d91..dd53454f23 100644 --- a/xen/arch/riscv/traps.c +++ b/xen/arch/riscv/traps.c @@ -195,12 +195,33 @@ void do_trap(struct cpu_user_regs *cpu_regs) { register_t pc =3D cpu_regs->sepc; unsigned long cause =3D csr_read(CSR_SCAUSE); + bool from_guest =3D cpu_regs->hstatus & HSTATUS_SPV; + + /* + * A synchronous trap taken in Xen context may come from a probing acc= ess + * like csr_read_safe(), covered by an exception table entry which res= umes + * execution past the faulting instruction. + * + * Traps taken from the guest must never be fixed up: sepc is then a g= uest + * address, which the guest could point at an address listed in the + * exception table, making Xen act on an entry fully under guest contr= ol. + * + * Interrupts must be excluded too: one taken at an address which happ= ens + * to be listed in the exception table would otherwise be "fixed up" a= s if + * the access itself had faulted, silently skipping it. + * + * Returning early skips check_for_pcpu_work() below, which is correct: + * that only runs for traps taken from the guest. + */ + if ( !from_guest && !(cause & CAUSE_IRQ_FLAG) && + fixup_exception(cpu_regs) ) + return; =20 switch ( cause ) { case CAUSE_VIRTUAL_SUPERVISOR_ECALL: /* CAUSE_VIRTUAL_SUPERVISOR_ECALL should come from VS-mode */ - BUG_ON(!(cpu_regs->hstatus & HSTATUS_SPV)); + BUG_ON(!from_guest); =20 vsbi_handle_ecall(cpu_regs); break; @@ -219,9 +240,6 @@ void do_trap(struct cpu_user_regs *cpu_regs) break; } =20 - if ( fixup_exception(cpu_regs) ) - break; - fallthrough; default: if ( cause & CAUSE_IRQ_FLAG ) @@ -253,7 +271,7 @@ void do_trap(struct cpu_user_regs *cpu_regs) break; } =20 - if ( cpu_regs->hstatus & HSTATUS_SPV ) + if ( from_guest ) check_for_pcpu_work(); } =20 --=20 2.56.0 From nobody Mon Nov 23 22:39:59 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=vates.tech ARC-Seal: i=1; a=rsa-sha256; t=1793027715; cv=none; d=zohomail.com; s=zohoarc; b=QKEOmX15HFOP8yg7cDdvXHYcX34AlPTvCVFWMW5kp2dKju06uz7mCrzHq5/8aZ/wk7/4VN0fGZw56biyOCoXtrr0k1QllDwiNkD92sY99vhC/aIECbfQVhKenwekvXvhrL+R3gbgeo8zKxnYej+/c430cvFMSQ0XYWFVG7dQIWE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793027715; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=05V3BzR+6x5zjvavbuAwm43Wko/6HMSUKNP4NRC4DXs=; b=AiUXPHqT0pcMqKgybe2dy5JQodvfh2MqDEuf+Wvp/+tB5nLTPTfEL1AdSFNUBHpIZOZaVy3pxkxrRls0rLBa65BnqeouL6PDrVKmw4AgUhmOgVjMjlm9q8fMS7wMLD7f2ZocYeJbdrEDFcNY+XfI1ewheZeXfd7XgVn1DW10LUQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 179302771580033.6295528994184; Mon, 26 Oct 2026 08:15:15 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1461476.1672513 (Exim 4.92) (envelope-from ) id 1xLMPb-0005QA-Gc; Mon, 26 Oct 2026 15:14:59 +0000 Received: by outflank-mailman (output) from mailman id 1461476.1672513; Mon, 26 Oct 2026 15:14:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xLMPb-0005Q3-CS; Mon, 26 Oct 2026 15:14:59 +0000 Received: by outflank-mailman (input) for mailman id 1461476; Mon, 26 Oct 2026 15:14:57 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xLMPZ-0005De-Hu for xen-devel@lists.xenproject.org; Mon, 26 Oct 2026 15:14:57 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1xLMPY-003d6B-Uo for xen-devel@lists.xenproject.org; Mon, 26 Oct 2026 16:14:56 +0100 Received: from [10.42.69.1] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6adf6e68-2eae-0a2a0a5409dd-0a2a450197f4-26 for ; Mon, 26 Oct 2026 16:14:56 +0100 Received: from [185.255.28.34] (helo=prod-mta-13-01.swg-srv.net) by tlsNG-d62444.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6adf6e6e-5984-0a2a45010019-b9ff1c229eb1-4 for ; Mon, 26 Oct 2026 16:14:56 +0100 Received: from mail2.vates.fr ([37.26.189.201] mail2.vates.fr) (Authenticated sender: 8631fc262581453bbf619ec5b2062170/smtp/7773de5a-2839-4720-82ee-e06722ae1d3e) by prod-mta-13-01.swg-srv.net (ZoneMTA - prod-mta-13) with ESMTPSA id 1a178c73a5d000f79f.007 for (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Mon, 26 Oct 2026 15:14:44 +0000 Received: from leducb.home (areims-651-1-80-194.w90-18.abo.wanadoo.fr [90.18.187.194]) (Authenticated sender: baptiste.le-duc) by mail2.vates.fr (Postfix) with ESMTPSA id 5548F81DAB; Mon, 26 Oct 2026 16:14:44 +0100 (CET) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=vates.tech header.i="@vates.tech" header.h="From:Subject:Date:Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding:In-Reply-To:References:Feedback-ID" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vates.tech; q=dns/txt; s=selector1; bh=05V3BzR+6x5zjvavbuAwm43Wko/6HMSUKNP4NRC4DXs=; h=from:subject:date:message-id:to:cc:mime-version:content-type:content-transfer-encoding:in-reply-to:references:feedback-id; b=Q8uN5jupVx6Fe/yI8zifA3Nz5E0nBlEy+O2H0Ho4JR1gO9s1ZdaJoDgotvmLOolJTDR238n2E fSLv6ZiHzOKkhEQ8z72OgLc4NWpg9RwNZ3LiH+xpKadyRf1ADtt22plS9DggBzqrT/3dbTJ2eVq Ykih6TDtdsJ+AuqoGdTKbHqWuLH+3OkVlz2TbRxlqvtoDok4wB4eYXT27ijdIu/Op5gLReVW6zA ydFtXvormMFihCSNeY0giCxOl++IHRXHHCW21gmiOkcAC5XcQal//PGzobLByCx4SQm5/0/jJ1z OBjVxs4V4xpIXT3ArtGPRGRnd5zVH/rgfK/n2P/NYkcA== X-Zone-Loop: 2e04acb81c36d885181dc10a34c70001e62d75c9ce61 x-campaign-type: default x-transaction-id: 5ce385fc-d648-46d9-97b9-dfa73fc5e218 x-swg-uid: 01-daeb0d01-50e0-4a8a-809d-41e5a8712c4c X-Mailer: Sweego Message-ID: <1793027685.8631fc262581453bbf619ec5b2062170.1a178c73a5d000f79f@vates.tech> x-swg-bid: 1793027685.8631fc262581453bbf619ec5b2062170.1a178c73a5d000f79f Feedback-ID: default:8631fc262581453bbf619ec5b2062170:Sweego x-campaign-id: default x-client-id: 8631fc262581453bbf619ec5b2062170 X-Originating-IP: [37.26.189.201] From: Baptiste Le Duc To: xen-devel@lists.xenproject.org Cc: Baptiste Le Duc , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Stefano Stabellini , Alistair Francis , Connor Davis , Oleksii Kurochko , Zheng Zhang Subject: [PATCH v8 4/5] xen/riscv: probe the A/D update scheme if the DT advertises neither Date: Mon, 26 Oct 2026 16:14:36 +0100 In-Reply-To: <1793027589.8631fc262581453bbf619ec5b2062170.1a178c5c430000f79f@vates.tech> References: <1793027589.8631fc262581453bbf619ec5b2062170.1a178c5c430000f79f@vates.tech> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" X-Developer-Signature: v=1; a=ed25519-sha256; t=1793027331; l=7572; i=baptiste.le-duc@vates.tech; s=20260810; h=from:subject:message-id; bh=q6jMm0V5keRQlKbvNoUn72l63KmhPB1IAcGOzTgqX84=; b=LXkIdw0zxbbgRP9v+l2VtKF0Ii24w/+/6kP//6J7vOnDQ4B0P7JKUZKvm2mIGSkysPFqpvVmh JRqA4EYimWrBDy5iiKqoPVzG9fOyuVNM2RKEzuECEuqRFlDdGfZVB1C X-Developer-Key: i=baptiste.le-duc@vates.tech; a=ed25519; pk=N+BbdvMXRzrCuX/ieh4RWodiAKcLNvI+KjflcZ0oXCo= Content-Transfer-Encoding: quoted-printable X-Bm-Milter-Handled: 4ffbd6c1-ee69-4e1b-aabd-f977039bd3e2 X-Bm-Transport-Timestamp: 1793027684540 X-purgate-ID: tlsNG-d62444/1793027696-C4F47757-39436220/0/0 X-purgate-type: clean X-purgate-size: 7574 X-ZohoMail-DKIM: pass (identity @vates.tech) X-ZM-MESSAGEID: 1793027717402158500 p2m_set_pte_flags() presets the A/D bits of G-stage PTEs only when RISCV_ISA_EXT_svade is set, which is correct only if the device tree is. The privileged spec allows exactly two schemes for updating the PTE A and D bits: hardware sets them on access and on write, or accessing a page whose A and/or D bit is clear raises a page fault so that software can set them (ratified as Svade). Every implementation uses one of them, but platforms designed before Svade and Svadu were ratified, such as the HiFive Premier P550, may advertise neither. Trust the device tree when it advertises Svade and/or Svadu, as for any other extension. When it advertises neither, probe the scheme in effect and record the matching extension in riscv_isa, so that such device trees can be used as-is, and warn naming the extension to add to "riscv,isa". Introduce probe_hw_ad_update(): alias a local variable through the FIX_MISC fixmap slot with its A and D bits clear, then store to it under an exception table fixup. Hardware updating is in effect if the store completes and the D bit is then set. The probe fails otherwise, whether the store faults or completes leaving the D bit clear. The D bit is checked rather than the A bit, as the A bit may be set speculatively. The PTE is written directly rather than through set_fixmap(), which presets the A/D bits. Add Svadu to the known ISA extensions so it can be told apart from Svade. The comment above the enum asks for new extensions to go at the bottom to avoid shuffling, a leftover from Linux where the IDs were macros with explicit values. Nothing depends on the enum values, so have the comment say that multi-letter extensions follow the order of riscv_isa_ext[]. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Baptiste Le Duc Acked-by: Jan Beulich Reviewed-by: Oleksii Kurochko --- Changes since v7: - probe the A/D update scheme when the device tree advertises neither Svade nor Svadu and record the probed extension, instead of panicking. - drop Suggested-by. - update the patch's title/body accordingly. --- Changes since v6: - drop the probe and trust the device tree, only panic when it advertises neither Svade nor Svadu. - update the patch's title/body accordingly. - put svadu between svade and svpbmt in riscv_isa_ext_id. - rewrite the enum riscv_isa_ext_id comment. --- Changes since v5: - new patch, probe the A/D bits update scheme instead of trusting the device tree alone. --- xen/arch/riscv/cpufeature.c | 69 +++++++++++++++++++++++++++++= ++++ xen/arch/riscv/include/asm/cpufeature.h | 13 ++++--- 2 files changed, 76 insertions(+), 6 deletions(-) diff --git a/xen/arch/riscv/cpufeature.c b/xen/arch/riscv/cpufeature.c index 3d5bbd2228..49cbd0a6fe 100644 --- a/xen/arch/riscv/cpufeature.c +++ b/xen/arch/riscv/cpufeature.c @@ -20,6 +20,7 @@ =20 #include #include +#include =20 #ifdef CONFIG_ACPI # error "cpufeature.c functions should be updated to support ACPI" @@ -200,6 +201,7 @@ static const struct riscv_isa_ext_entry __initconstrel = riscv_isa_ext[] =3D { RISCV_ISA_EXT_ENTRY(ssaia, ANY), RISCV_ISA_EXT_ENTRY(sstc, NONE), RISCV_ISA_EXT_ENTRY(svade, NONE), + RISCV_ISA_EXT_ENTRY(svadu, NONE), RISCV_ISA_EXT_ENTRY(svpbmt, NONE), }; =20 @@ -630,6 +632,51 @@ const char *get_guest_isa_str(void) return guest_isa_str; } =20 +/* + * Probe whether hardware updates the PTE A/D bits by writing to a local + * variable through an alias mapping whose A and D bits are clear. + * + * Check the D bit rather than the A bit, as the A bit may be set + * speculatively while the D bit can't. + * + * Under Svade, the store raises a page fault instead, so use the extable = to + * handle it. + */ +static bool __init probe_hw_ad_update(void) +{ + unsigned int probe_target; + vaddr_t va =3D FIXMAP_ADDR(FIX_MISC) + PAGE_OFFSET(&probe_target); + pte_t *entry =3D &xen_fixmap[FIX_MISC]; + bool d_set =3D false; + + ASSERT(!pte_is_valid(*entry)); + + /* + * Any page in use will do, so alias the stack page this code runs on, + * with A and D clear. Store to a variable of its own, so that nothing + * the compiler relies on gets overwritten. + */ + write_pte(entry, pte_from_mfn(maddr_to_mfn(virt_to_maddr(&probe_target= )), + PTE_VALID | PTE_READABLE | PTE_WRITABLE)= ); + flush_tlb_one_local(va); + + asm_inline goto ( + "1: sw zero, 0(%[va])\n" + ASM_EXTABLE(1b, %l[out]) + : + : [va] "r" (va) + : "memory" + : out ); + + d_set =3D read_pte(entry).pte & PTE_DIRTY; + + out: + write_pte(entry, (pte_t){}); + flush_tlb_one_local(va); + + return d_set; +} + void __init riscv_fill_hwcap(void) { unsigned int i; @@ -674,6 +721,28 @@ void __init riscv_fill_hwcap(void) "Zihintpause unavailable: cpu_relax() gives the CPU no hint= ; " "wire up this platform's pause equivalent in cpu_relax()\n"= ); =20 + /* + * The privileged spec allows exactly two schemes for updating the PTE= A + * and D bits: + * 1) hardware sets them on access and on write; + * 2) accessing a page whose A and/or D bit is clear raises a page fa= ult, + * so that software can set them (ratified as Svade). + * + * Every implementation uses one of them, but may predate the extensio= ns + * and advertise neither. In that case, trust the hardware probe. + */ + if ( !riscv_isa_extension_available(NULL, RISCV_ISA_EXT_svade) && + !riscv_isa_extension_available(NULL, RISCV_ISA_EXT_svadu) ) + { + bool hw_update =3D probe_hw_ad_update(); + + __set_bit(hw_update ? RISCV_ISA_EXT_svadu : RISCV_ISA_EXT_svade, + riscv_isa); + printk(XENLOG_WARNING + "Device tree advertises neither Svade nor Svadu, probed %s:= add it to \"riscv,isa\"\n", + hw_update ? "svadu" : "svade"); + } + for ( i =3D 0; i < req_extns_amount; i++ ) { const struct riscv_isa_ext_data ext =3D required_extensions[i]; diff --git a/xen/arch/riscv/include/asm/cpufeature.h b/xen/arch/riscv/inclu= de/asm/cpufeature.h index 2973eb13a5..b0a23be18e 100644 --- a/xen/arch/riscv/include/asm/cpufeature.h +++ b/xen/arch/riscv/include/asm/cpufeature.h @@ -8,13 +8,13 @@ #include =20 /* - * These macros represent the logical IDs of each multi-letter RISC-V ISA - * extension and are used in the ISA bitmap. The logical IDs start from - * RISCV_ISA_EXT_BASE, which allows the 0-25 range to be reserved for sing= le - * letter extensions and are used in enum riscv_isa_ext_id. + * Logical IDs of RISC-V ISA extensions, used as bit positions in the ISA + * bitmap. * - * New extensions should just be added to the bottom, rather than added - * alphabetically, in order to avoid unnecessary shuffling. + * Single-letter extensions use IDs below RISCV_ISA_EXT_BASE and are sorted + * alphabetically. Multi-letter extensions start from RISCV_ISA_EXT_BASE a= nd + * follow the same order as riscv_isa_ext[] (see the ordering rules descri= bed + * above it). */ #define RISCV_ISA_EXT_BASE 26 =20 @@ -41,6 +41,7 @@ enum riscv_isa_ext_id { RISCV_ISA_EXT_ssaia, RISCV_ISA_EXT_sstc, RISCV_ISA_EXT_svade, + RISCV_ISA_EXT_svadu, RISCV_ISA_EXT_svpbmt, RISCV_ISA_EXT_MAX }; --=20 2.56.0 From nobody Mon Nov 23 22:39:59 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=vates.tech ARC-Seal: i=1; a=rsa-sha256; t=1793027723; cv=none; d=zohomail.com; s=zohoarc; b=e4WQeNAF5D79mbJJkiF+6dqhaO+ivwdpf1It4g1HgcSOQlujo4XwP9rONAhMFBuDjUwvMV8swlcxCgpVAAd5PI2aNW9zr7TdRp5xiFdH3CB7ANCo5EMxGUbDQJjwPg1uvAn4O94vNmX39n9PGXV03ryFIldEAr/pyfdZB2NCjLk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793027723; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=kbx7FuSDc06ZBA43oBu6G+26e9mYroFRMBqi6Ps0vuU=; b=PxxthK1EEQrHlvqJoPAambyrk0Cu1YZArOWL0jMXqLEYo5aqugYvwvaXz+igFcI806mt2WGXpJFVizG9uupOKYp0K84q1OqnQQBgJZGkoRTDXso+h1K+2KoEnq4yBDcdSxzJ6xle/+CDcJfHmLq3l+JyYJaYEMYrK730K50V4IA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1793027723078775.1153457387119; Mon, 26 Oct 2026 08:15:23 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1461478.1672522 (Exim 4.92) (envelope-from ) id 1xLMPe-0005hI-Ql; Mon, 26 Oct 2026 15:15:02 +0000 Received: by outflank-mailman (output) from mailman id 1461478.1672522; Mon, 26 Oct 2026 15:15:02 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xLMPe-0005h9-Nd; Mon, 26 Oct 2026 15:15:02 +0000 Received: by outflank-mailman (input) for mailman id 1461478; Mon, 26 Oct 2026 15:15:01 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) id 1xLMPd-0005fI-Bg for xen-devel@lists.xenproject.org; Mon, 26 Oct 2026 15:15:01 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1xLMPc-00ESEG-Oj for xen-devel@lists.xenproject.org; Mon, 26 Oct 2026 16:15:00 +0100 Received: from [10.42.69.8] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6adf6e6b-e002-0a2a0a5209dd-0a2a4508c308-16 for ; Mon, 26 Oct 2026 16:15:00 +0100 Received: from [185.255.28.18] (helo=prod-mta-13.swg-srv.net) by tlsNG-c1860d.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6adf6e74-f659-0a2a45080019-b9ff1c1288f5-3 for ; Mon, 26 Oct 2026 16:15:00 +0100 Received: from mail2.vates.fr ([37.26.189.201] mail2.vates.fr) (Authenticated sender: 8631fc262581453bbf619ec5b2062170/smtp/7773de5a-2839-4720-82ee-e06722ae1d3e) by prod-mta-13.swg-srv.net (ZoneMTA - prod-mta-13) with ESMTPSA id 1a178c73b94000f79f.007 for (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Mon, 26 Oct 2026 15:14:45 +0000 Received: from leducb.home (areims-651-1-80-194.w90-18.abo.wanadoo.fr [90.18.187.194]) (Authenticated sender: baptiste.le-duc) by mail2.vates.fr (Postfix) with ESMTPSA id A082F81E53; Mon, 26 Oct 2026 16:14:44 +0100 (CET) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=vates.tech header.i="@vates.tech" header.h="From:Subject:Date:Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding:In-Reply-To:References:Feedback-ID" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vates.tech; q=dns/txt; s=selector1; bh=kbx7FuSDc06ZBA43oBu6G+26e9mYroFRMBqi6Ps0vuU=; h=from:subject:date:message-id:to:cc:mime-version:content-type:content-transfer-encoding:in-reply-to:references:feedback-id; b=lsvoqg+3RjD+DEYUJ9yXQVHB4uPBYC3I+WaPrBUBrL90X4xpUixuTI29ZXzz5aFOvTgECrjTv +pQrgSSFfF4SxjbKyM9+UCOOGRerkAxpgP93nLtFjQRmzgHh+yAJDFcG0xonvbNHuiWtj8lVUXl dbYJubvg4Rzfrzf3ySCOnxBtpsrnyEl4NDZhJD6dSAQoYOwSLuEAmFDdT7twv5t5yT6FkpxO+NP i0HHiKwvlAXDCiUnFtxZFPWXr37rvGqqlPO+7N+Dn01FRCrKuuqD3enToKtwNif+f9DhEWjV3HM rA4WEk78f293yp0mQk6qnf2O450cOe+amOwCnw4DGH3w== X-Zone-Loop: d7d220821e69ed06eedb9f2381061f70adb9e84aaf55 x-campaign-type: default x-transaction-id: 80be7ad3-14bf-4d8b-8bbe-13ce78bfed0d x-swg-uid: 01-03d6eaac-5398-4723-a137-2008d35b89b5 X-Mailer: Sweego Message-ID: <1793027685.8631fc262581453bbf619ec5b2062170.1a178c73b94000f79f@vates.tech> x-swg-bid: 1793027685.8631fc262581453bbf619ec5b2062170.1a178c73b94000f79f Feedback-ID: default:8631fc262581453bbf619ec5b2062170:Sweego x-campaign-id: default x-client-id: 8631fc262581453bbf619ec5b2062170 X-Originating-IP: [37.26.189.201] From: Baptiste Le Duc To: xen-devel@lists.xenproject.org Cc: Baptiste Le Duc , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Stefano Stabellini , Alistair Francis , Connor Davis , Oleksii Kurochko , Zheng Zhang Subject: [PATCH v8 5/5] xen/riscv: rework the A/D bits comment in p2m_set_pte_flags() Date: Mon, 26 Oct 2026 16:14:37 +0100 In-Reply-To: <1793027589.8631fc262581453bbf619ec5b2062170.1a178c5c430000f79f@vates.tech> References: <1793027589.8631fc262581453bbf619ec5b2062170.1a178c5c430000f79f@vates.tech> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" X-Developer-Signature: v=1; a=ed25519-sha256; t=1793027331; l=5135; i=baptiste.le-duc@vates.tech; s=20260810; h=from:subject:message-id; bh=vuOMNvviSt4a7TWW5Qv+CGfm+79pNznRqgcCowdji6Q=; b=yptX/IkJuN/jXRyCCBnJuJO2rpZkHeGdjuNS6SNCGwnUtuiqr1yOW2HBsR/7uAgG3XzMSBCZy pdL3EVBzv8YBS5OGd78Zddmel6FVT9/GMXpOEPPmXhKwBYbQOus32xr X-Developer-Key: i=baptiste.le-duc@vates.tech; a=ed25519; pk=N+BbdvMXRzrCuX/ieh4RWodiAKcLNvI+KjflcZ0oXCo= Content-Transfer-Encoding: quoted-printable X-Bm-Milter-Handled: 4ffbd6c1-ee69-4e1b-aabd-f977039bd3e2 X-Bm-Transport-Timestamp: 1793027684846 X-purgate-ID: tlsNG-c1860d/1793027700-D795A87B-6FCBA36E/10/73395122804 X-purgate-type: spam X-purgate-size: 5137 X-ZohoMail-DKIM: pass (identity @vates.tech) X-ZM-MESSAGEID: 1793027725575158500 The comment in p2m_set_pte_flags() quotes the spec at length to describe the two A/D bits schemes, and its TODO mixes two things: why A/D are preset today (OpenSBI delegates the resulting page faults to a lower privilege mode, so Xen would take them with no handler) and what remains to be done. Summarize the two schemes as a short list. The reason for presetting A/D is not future work, so move it out of the TODO, next to the schemes. The TODO now keeps only the later work, handling these page faults instead of presetting A/D, which only concerns Svade as A/D page faults cannot happen otherwise. Also note that presetting the A/D bits is harmless when the device tree advertises both Svade and Svadu and the platform uses hardware A/D updating. No functional change. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Baptiste Le Duc Reviewed-by: Oleksii Kurochko Acked-by: Jan Beulich --- Changes since v7: - collect R-by. - move the patch last, as the previous patch now records Svade whenever the CPU faults on clear A/D bits, instead of riscv_fill_hwcap() panicking when the device tree advertises neither Svade nor Svadu. --- Changes since v6: - drop the change to preset A/D unless only Svadu is advertised, as riscv_fill_hwcap() now panics if the device tree advertises neither Svade nor Svadu. The patch only reworks the comment. - update the patch's title accordingly. --- Changes since v5: - new patch, split out of "xen/riscv: always preset A/D bits in G-stage PTEs". --- xen/arch/riscv/p2m.c | 45 +++++++++++++++++++-------------------------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/xen/arch/riscv/p2m.c b/xen/arch/riscv/p2m.c index 3d195294d5..a2d81a9c8a 100644 --- a/xen/arch/riscv/p2m.c +++ b/xen/arch/riscv/p2m.c @@ -591,35 +591,28 @@ static void p2m_set_pte_flags(pte_t *e, p2m_type_t t) e->pte |=3D PTE_USER; =20 /* - * Two schemes to manage the A and D bits are defined: - * =E2=80=A2 The Svade extension: when a virtual page is accessed an= d the A bit - * is clear, or is written and the D bit is clear, a page-fault - * exception is raised. - * =E2=80=A2 When the Svade extension is not implemented, the follow= ing scheme - * applies. - * When a virtual page is accessed and the A bit is clear, the PTE= is - * updated to set the A bit. When the virtual page is written and = the - * D bit is clear, the PTE is updated to set the D bit. When G-sta= ge - * address translation is in use and is not Bare, the G-stage virt= ual - * pages may be accessed or written by implicit accesses to VS-lev= el - * memory management data structures, such as page tables. - * Thereby to avoid a page-fault in case of Svade is available, it is - * necessary to set A and D bits. + * A RISC-V implementation can either: + * 1) Update the 'A' and 'D' PTE bits in hardware. + * 2) Generate a page fault when 'A' and/or 'D' is clear, so that + * software can set them. * - * TODO: For now, it=E2=80=99s fine to simply set the A/D bits, since = OpenSBI - * delegates page faults to a lower privilege mode and so OpenSBI - * isn't expect to handle page-faults occured in lower modes. - * By setting the A/D bits here, page faults that would otherwise - * be generated due to unset A/D bits will not occur in Xen. + * (1) needs nothing more as it is handled by hardware. For (2), set '= A' + * and 'D' up front: OpenSBI delegates such page faults to a lower + * privilege mode, so they would be raised in Xen, which has no handler + * for them. * - * Currently, Xen on RISC-V does not make use of the information - * that could be obtained from handling such page faults, which - * could otherwise be useful for several use cases such as demand - * paging, cache-flushing optimizations, memory access tracking,= etc. + * If both Svade and Svadu are advertised and the CPU updates A/D in + * hardware, presetting them is harmless. * - * To support the more general case and the optimizations mentio= ned - * above, it would be better to stop setting the A/D bits here a= nd - * instead handle page faults that occur due to unset A/D bits. + * TODO: Xen on RISC-V currently makes no use of the information that + * handling such page faults could provide, which would be useful + * for several use cases such as demand paging, cache-flushing + * optimizations, memory access tracking, etc. + * + * To support the more general case and the optimizations + * mentioned above, it would be better to stop setting the A/D + * bits here and instead handle the page faults that occur due to + * unset A/D bits. */ if ( riscv_isa_extension_available(NULL, RISCV_ISA_EXT_svade) ) e->pte |=3D PTE_ACCESSED | PTE_DIRTY; --=20 2.56.0