From nobody Tue Aug 25 17:57:16 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=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1778144385; cv=none; d=zohomail.com; s=zohoarc; b=FnEarnoNj9IaRyrs3um8PLuwX0mNprCvcAWQ+9xFYQG1ceOY+Awo00F9jSp+cC4btfCHmn7CMtrVUkAJDdmIZPPHFAaJRhRTUo4q6iIbZU2lcibJtpuZC8P7Fu3rEcLG7v2WLncYqTJzvpZq5wUOIUkyQpnh7k/jmNc/IiLlxzo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778144385; h=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:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=aBwbjhvethRi23b0lhhRx6kHsUNIa/c7SiSbkmEzovg=; b=jzIo4TEmExVdwTsJoyfdm3RFEoSyKtbSjah+MpqLA8s7okkhL02lLJQlrlp4cQN8T5v2+woLIm+XblAeCsgygBeuGfcbduhV3w41f6G8BBuk66HpRYTVWr8eThQQSWDY9pwcYJOIHg6iPbN4npq2WjXptikhXfGosQ/mpu51D+I= 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 1778144385696663.4221539947819; Thu, 7 May 2026 01:59:45 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1302342.1576351 (Exim 4.92) (envelope-from ) id 1wKuZj-0004BW-Jr; Thu, 07 May 2026 08:59:19 +0000 Received: by outflank-mailman (output) from mailman id 1302342.1576351; Thu, 07 May 2026 08:59:19 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wKuZj-00048C-3N; Thu, 07 May 2026 08:59:19 +0000 Received: by outflank-mailman (input) for mailman id 1302342; Thu, 07 May 2026 08:59:18 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) id 1wKuZh-0003zG-Ue for xen-devel@lists.xenproject.org; Thu, 07 May 2026 08:59:18 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wKuZh-002yCX-BG for xen-devel@lists.xenproject.org; Thu, 07 May 2026 10:59:17 +0200 Received: from [10.42.69.3] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 69fc5464-bab6-0a2a0a5309dd-0a2a4503ea28-6 for ; Thu, 07 May 2026 10:59:17 +0200 Received: from [209.85.218.45] (helo=mail-ej1-f45.google.com) by tlsNG-33051d.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 69fc5465-672d-0a2a45030019-d155da2dc483-3 for ; Thu, 07 May 2026 10:59:17 +0200 Received: by mail-ej1-f45.google.com with SMTP id a640c23a62f3a-b8f9568e074so89229266b.0 for ; Thu, 07 May 2026 01:59:17 -0700 (PDT) Received: from fedora (user-109-243-69-121.play-internet.pl. [109.243.69.121]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-bc81d5e9583sm57549966b.17.2026.05.07.01.59.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 May 2026 01:59:15 -0700 (PDT) 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=20251104 header.d=gmail.com header.i="@gmail.com" header.h="Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778144356; x=1778749156; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=aBwbjhvethRi23b0lhhRx6kHsUNIa/c7SiSbkmEzovg=; b=pZuoUrET3WFF/aLSI4tBB4MvpisDkk3HZnrWucWF5IiHP3vOB9ysm6a90p/bduvToO KZ3vkQtTj5O+CC3Y1Hn1w2FPkdGDbL5x0PAT+9cm2BtErUwGOH5wR8tA+b8XXaHqTzLk YgMBwo9gYpHSkTNMyOjKC1qGXpSyQUGpY2dVVuqHjLDwv1Xn34Z7EFYEgPUE4puCSnKt SDKzZgaBM7LNVRzF/JUC6wqLpg4XFQ35t96HA7pOYG6cZc0R2tsPJb+IZKEZnAGuaZVC VRnh/pOQuHZ657pJiDoEqJhlVnwX+cHb2g3jUO5LOu9Xh3eeBJ5U5wT3CNlyR+ykHfzH alMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778144356; x=1778749156; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=aBwbjhvethRi23b0lhhRx6kHsUNIa/c7SiSbkmEzovg=; b=VJyMIsU0VTsvMob3kZlGnvdzQfx/PrHwtb55aL58x8jn9QJHbt8AYF3RVMHWDRiKAL +dCXcTsLEgkkEZ7OH5IG5H01jlvzSFE6uf334ioZKoRg9bWXWYEDViw+M9CGvO+KyYkS vSPklRfwjmC7piV1a1jyWO1X3rKbtHmXLJcEuZ8ALf0ZGCcCvpyNZLXYQ8080H2VvDqP YcMp25ODBuxQjKjyjE8AAjydERKBllgQYrCSxacdqEKTF138+KgPwJKm4/O72m7/cbxf hfBfAW/n1ToJPFq2k0qALxINakJA7L24kRiksxL5GuRpGwAZV/w71m1AOxfi+uZwt0RZ XS5A== X-Gm-Message-State: AOJu0Ywj10ksI9zn58xULwUEOjrQ2TFX5NG6V7TKl4tsHuvfRsMQeq+u fuA1fIz+nDGOtq+lyYy7L80TJzVdaO9jHdNZf5nV7gl/s6Abb0MPR+Em12x5Vg== X-Gm-Gg: AeBDiesipUzNcP6rGpdqX4EnJK3yN9K9JEjY/N2pucSoXm8xgI5QR5UEKyKg3S9VE0M 7rOITf8RhP65KePcjbnKWOYrl+4h1enEOIH7HK60WgDF0GIx+yQHFqkz3QHILNpUXq9Nt0pvSQc yf7tjFLAe5u4iLRAMgnIBvIinqTHDYMw2gJfwzyTIkD4w7z1dL76tvF2n0uklUpjGJIMLbmrkUV 6dpzpoCPiStQgGkS3id6mcWZPjunXWUDgEp/vlaaSexf71r+5fQWAZA8RV+weMsvTUHRLRUocN2 hB90FoonmiJy29o4NRs2moEZmwscr2bWmQvgoHsvK+JbdPLIc4J6s8S6yywSdKHMFJJH76u/FJr KqLJAEXSYPBVyq6s7BzLeO4cbPBT0c9PXhuf0ADjukK6ZP+C54+TBycFds4pcU9dICfROK27AVS N1X7z4ojRoAi688qVaLhkc0YXWb6842kcDizGgkNOfkKvJMnS3vkkU+jOoqU0u+GG/7TK1gdyMo yJL X-Received: by 2002:a17:907:1c01:b0:bc3:a4cf:aecd with SMTP id a640c23a62f3a-bc56c520611mr406236566b.14.1778144356168; Thu, 07 May 2026 01:59:16 -0700 (PDT) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Romain Caritey , Oleksii Kurochko , Alistair Francis , Connor Davis , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini Subject: [PATCH v5 09/11] xen/riscv: introduce p2m_gpa_bits Date: Thu, 7 May 2026 10:58:48 +0200 Message-ID: <7c04588686638f3c0c53df4b8fd8645991009bff.1778140240.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-33051d/1778144357-41595938-FB7A37CB/10/73395122804 X-purgate-type: spam X-purgate-size: 3270 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1778144387275158500 Content-Type: text/plain; charset="utf-8" common/device-tree/domain-build.c uses p2m_gpa_bits to determine the upper bound of the GPA space when searching for unused regions, so it must be defined when CONFIG_DOMAIN_BUILD_HELPERS=3Dy. The variable is initialised to PADDR_BITS and narrowed in p2m_init() to the GPA width of the selected G-stage mode, allowing an external entity (e.g. an IOMMU) to restrict it further if needed. p2m_gpa_bits is a global rather than a per-domain value, which is acceptable for now because all domains are required to use the same G-stage MMU mode, as dom0less common code allocates it per all domains. Signed-off-by: Oleksii Kurochko Acked-by: Jan Beulich --- Changes in v5: - Nothing changed. Only rebase. --- Changes in v4: - Add Acked-by: Jan Beulich . --- Changes in v3: - Update initialization of p2m_gpa_bits and the comment above. - Rework how p2m_gpa_bits is limited. - Update the commit message. --- Changes in v2: - New patch. --- --- xen/arch/riscv/include/asm/p2m.h | 3 +++ xen/arch/riscv/p2m.c | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/xen/arch/riscv/include/asm/p2m.h b/xen/arch/riscv/include/asm/= p2m.h index 638c60ddc2f7..0d1dace1a0d8 100644 --- a/xen/arch/riscv/include/asm/p2m.h +++ b/xen/arch/riscv/include/asm/p2m.h @@ -47,6 +47,9 @@ #define P2M_LEVEL_MASK(p2m, lvl) \ (P2M_TABLE_OFFSET(p2m, lvl) << P2M_GFN_LEVEL_SHIFT(lvl)) =20 +/* Holds the bit size of GPAs in p2m tables */ +extern unsigned int p2m_gpa_bits; + #define paddr_bits PADDR_BITS =20 /* Get host p2m table */ diff --git a/xen/arch/riscv/p2m.c b/xen/arch/riscv/p2m.c index f889978cf754..703b9f4d2540 100644 --- a/xen/arch/riscv/p2m.c +++ b/xen/arch/riscv/p2m.c @@ -11,6 +11,8 @@ #include #include =20 +#include + #include #include #include @@ -67,6 +69,12 @@ static const struct gstage_mode_desc gstage_modes[] =3D { const struct gstage_mode_desc *__ro_after_init max_gstage_mode =3D &gstage_modes[0]; =20 +/* + * Set to the maximum configured support for GPA bits, so the number of GPA + * bits can be restricted by an external entity (e.g. IOMMU). + */ +unsigned int __ro_after_init p2m_gpa_bits =3D PADDR_BITS; + static void p2m_free_page(struct p2m_domain *p2m, struct page_info *pg); =20 static inline void p2m_free_metadata_page(struct p2m_domain *p2m, @@ -355,6 +363,7 @@ int p2m_init(struct domain *d, const struct xen_domctl_= createdomain *config) */ static const struct gstage_mode_desc __ro_after_init *m =3D &gstage_mo= des[0]; struct p2m_domain *p2m =3D p2m_get_hostp2m(d); + unsigned int gpa_bits; =20 /* * "Trivial" initialisation is now complete. Set the backpointer so t= he @@ -410,6 +419,12 @@ int p2m_init(struct domain *d, const struct xen_domctl= _createdomain *config) # error "Add init of p2m->clean_dcache" #endif =20 + gpa_bits =3D P2M_GFN_LEVEL_SHIFT(p2m->mode->paging_levels + 1) + + P2M_ROOT_EXTRA_BITS; + + if ( gpa_bits < p2m_gpa_bits ) + p2m_gpa_bits =3D gpa_bits; + return 0; } =20 --=20 2.54.0