From nobody Fri Oct 31 23:30:16 2025 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 header.i=dpsmith@apertussolutions.com; 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; arc=pass (i=1 dmarc=pass fromdomain=apertussolutions.com) ARC-Seal: i=2; a=rsa-sha256; t=1745100662; cv=pass; d=zohomail.com; s=zohoarc; b=XdIQ/B5JWfI8QzjVBq/cl3dHVJbTPYXiSBN/l0vJDZCGv2soUL2jM4Wj3XxxFATwr/3ivMrFghXsWgIBCYX+EjUclX6leNSyrZtwQE9sozPm9nBHeyG995Og6+ZywwfRm+6twL6qMKo221qE3XvQL6uccL7+yHBLgI5pPdpuPPk= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100662; 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=wgGneFZ+dejsZVpf807k7GVId5OnyolV6BLaI9T7Y8g=; b=fuwAUUJyf33Ru0OJNh4LsuzNgGGhXm3BMoZ53mDnpnUEG6NOQZgSh4t9iUphMiiVcoSQjIdK7lEZLipyLS8xpfmuFQErwGAV2F5CS8OmvQs8bH2aJdYFUkJwfWAkDcl3RELepg5hyRz81V0pfVJD3qk5qjwseDWmHjJ9t1wGPv8= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass header.i=dpsmith@apertussolutions.com; 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; arc=pass (i=1 dmarc=pass fromdomain=apertussolutions.com) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1745100662793792.8095669522703; Sat, 19 Apr 2025 15:11:02 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.960055.1352132 (Exim 4.92) (envelope-from ) id 1u6GOW-00007H-8W; Sat, 19 Apr 2025 22:10:40 +0000 Received: by outflank-mailman (output) from mailman id 960055.1352132; Sat, 19 Apr 2025 22:10:40 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u6GOW-00005i-1J; Sat, 19 Apr 2025 22:10:40 +0000 Received: by outflank-mailman (input) for mailman id 960055; Sat, 19 Apr 2025 22:10:38 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u6GOB-0004yY-9X for xen-devel@lists.xenproject.org; Sat, 19 Apr 2025 22:10:19 +0000 Received: from sender4-of-o50.zoho.com (sender4-of-o50.zoho.com [136.143.188.50]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 12fd5733-1d6b-11f0-9eb0-5ba50f476ded; Sun, 20 Apr 2025 00:10:18 +0200 (CEST) Received: by mx.zohomail.com with SMTPS id 174510051751992.3359385834732; Sat, 19 Apr 2025 15:08:37 -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" X-Inumbo-ID: 12fd5733-1d6b-11f0-9eb0-5ba50f476ded ARC-Seal: i=1; a=rsa-sha256; t=1745100520; cv=none; d=zohomail.com; s=zohoarc; b=SaOsX8l+FjnqfgEJhHEIbD7BMhng1MAM5zb+rUtE8kP2g+/p3jM8zYNHcDHnCTgLyPGKXCr2h3VTe6JyuElYo4C+SQUgWQxzsd31l5CJKuQ5cc200apijNqVe88K9ndpLYn3RQUCh0WTUMFnRC/kjG3JYlgidmOGbwZDTsP939o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100520; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=wgGneFZ+dejsZVpf807k7GVId5OnyolV6BLaI9T7Y8g=; b=DrgUU6SaJycbNbvFUhlf1ytPHMIxbCRmR0zudLNrJFSjn0AZ0jKxpMKLrU0xV6/9WoigVGGXo+j8FYz2108Y0HrylHYZrA01UwgDQxy8OBAUX2V61UVNqGrKhz19KkLoWfFhBA1aYlq83+MkhMpyRz1w6+htAcWZrjI4itCNkIw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=apertussolutions.com; spf=pass smtp.mailfrom=dpsmith@apertussolutions.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1745100520; s=zoho; d=apertussolutions.com; i=dpsmith@apertussolutions.com; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-Id:Message-Id:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Reply-To; bh=wgGneFZ+dejsZVpf807k7GVId5OnyolV6BLaI9T7Y8g=; b=H2aExSxsNIwwonPNBwPvJ4lio0wPoITRCxetRW/aXsOaa6GSmnIlcJpsnwWIJhS0 mAvbMiNHeVAvnM4fD6P2biVk/BA+32cULeMMcknQ3pNTPHsanWbWSU5kdnMMOGt9F7U QOlLOEuHz70dBsxlRMqErWkd/26Z0rMNRdb15j6w= From: "Daniel P. Smith" To: xen-devel@lists.xenproject.org Cc: "Daniel P. Smith" , jason.andryuk@amd.com, stefano.stabellini@amd.com, agarciav@amd.com, Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [RFC 09/38] x86/boot: convert dom0 page calculation to use boot domain Date: Sat, 19 Apr 2025 18:07:51 -0400 Message-Id: <20250419220820.4234-10-dpsmith@apertussolutions.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20250419220820.4234-1-dpsmith@apertussolutions.com> References: <20250419220820.4234-1-dpsmith@apertussolutions.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External X-ZohoMail-DKIM: pass (identity dpsmith@apertussolutions.com) X-ZM-MESSAGEID: 1745100663484019000 Content-Type: text/plain; charset="utf-8" This commit seeks to rework the dom0_compute_nr_pages() function to consume= a boot domain structure that may contain requested memory pages, min pages, m= ax pages, and the reference for the initrd. With the passing of the boot domain struct, the initrd_size parameter is dropped. This takes into account the P= VH case, where the value 0 was passed, which is safe as initrd_size is only us= ed behind the is_pv_domain() check. It introduces the calculate_dom0_pages() function that handles the command = line override of the memory pages, min pages, and max pages values. The function also applies a clamping of memory pages to the min/max pages value. Signed-off-by: Daniel P. Smith --- xen/arch/x86/dom0_build.c | 62 ++++++++++++++++----------- xen/arch/x86/hvm/dom0_build.c | 12 +++--- xen/arch/x86/include/asm/dom0_build.h | 10 ++--- xen/arch/x86/pv/dom0_build.c | 6 +-- 4 files changed, 51 insertions(+), 39 deletions(-) diff --git a/xen/arch/x86/dom0_build.c b/xen/arch/x86/dom0_build.c index 08fde953a1e0..658d81ab598c 100644 --- a/xen/arch/x86/dom0_build.c +++ b/xen/arch/x86/dom0_build.c @@ -330,16 +330,37 @@ static unsigned long __init default_nr_pages(unsigned= long avail) : min(avail / 16, 128UL << (20 - PAGE_SHIFT))); } =20 -unsigned long __init dom0_compute_nr_pages( - struct domain *d, struct elf_dom_parms *parms, unsigned long initrd_le= n) +static void __init calculate_dom0_pages( + struct boot_domain *bd, unsigned long avail) { - nodeid_t node; - unsigned long avail =3D 0, nr_pages, min_pages, max_pages, iommu_pages= =3D 0; + unsigned long nr_pages =3D bd->mem_pages ?: default_nr_pages(avail); =20 /* The ordering of operands is to work around a clang5 issue. */ if ( CONFIG_DOM0_MEM[0] && !dom0_mem_set ) parse_dom0_mem(CONFIG_DOM0_MEM); =20 + if ( dom0_mem_set ) + { + nr_pages =3D get_memsize(&dom0_size, avail) ?: default_nr_pages(av= ail); + bd->min_pages =3D get_memsize(&dom0_min_size, avail); + bd->max_pages =3D get_memsize(&dom0_max_size, avail); + } + + nr_pages =3D max(nr_pages, bd->min_pages); + nr_pages =3D min(nr_pages, bd->max_pages); + nr_pages =3D min(nr_pages, avail); + + bd->mem_pages =3D nr_pages; +} + +unsigned long __init dom0_compute_nr_pages( + struct boot_domain *bd, struct elf_dom_parms *parms) +{ + nodeid_t node; + struct domain *d =3D bd->d; + unsigned long initrd_len =3D bd->ramdisk ? bd->ramdisk->size : 0; + unsigned long avail =3D 0, iommu_pages =3D 0; + for_each_node_mask ( node, dom0_nodes ) avail +=3D avail_domheap_pages_region(node, 0, 0) + initial_images_nrpages(node); @@ -366,17 +387,13 @@ unsigned long __init dom0_compute_nr_pages( { unsigned long cpu_pages; =20 - nr_pages =3D get_memsize(&dom0_size, avail) ?: default_nr_pages(av= ail); - /* * Clamp according to min/max limits and available memory * (preliminary). */ - nr_pages =3D max(nr_pages, get_memsize(&dom0_min_size, avail)); - nr_pages =3D min(nr_pages, get_memsize(&dom0_max_size, avail)); - nr_pages =3D min(nr_pages, avail); + calculate_dom0_pages(bd, avail); =20 - cpu_pages =3D dom0_paging_pages(d, nr_pages); + cpu_pages =3D dom0_paging_pages(d, bd->mem_pages); =20 if ( !iommu_use_hap_pt(d) ) avail -=3D cpu_pages; @@ -384,18 +401,12 @@ unsigned long __init dom0_compute_nr_pages( avail -=3D cpu_pages - iommu_pages; } =20 - nr_pages =3D get_memsize(&dom0_size, avail) ?: default_nr_pages(avail); - min_pages =3D get_memsize(&dom0_min_size, avail); - max_pages =3D get_memsize(&dom0_max_size, avail); - /* Clamp according to min/max limits and available memory (final). */ - nr_pages =3D max(nr_pages, min_pages); - nr_pages =3D min(nr_pages, max_pages); - nr_pages =3D min(nr_pages, avail); + calculate_dom0_pages(bd, avail); =20 if ( is_pv_domain(d) && (parms->p2m_base =3D=3D UNSET_ADDR) && !memsize_gt_zero(&dom0_siz= e) && - (!memsize_gt_zero(&dom0_min_size) || (nr_pages > min_pages)) ) + (!memsize_gt_zero(&dom0_min_size) || (bd->mem_pages > bd->min_pag= es)) ) { /* * Legacy Linux kernels (i.e. such without a XEN_ELFNOTE_INIT_P2M @@ -412,7 +423,7 @@ unsigned long __init dom0_compute_nr_pages( vend =3D round_pgup(parms->virt_kend); if ( !parms->unmapped_initrd ) vend +=3D round_pgup(initrd_len); - end =3D vend + nr_pages * sizeof_long; + end =3D vend + bd->mem_pages * sizeof_long; =20 if ( end > vstart ) end +=3D end - vstart; @@ -420,16 +431,17 @@ unsigned long __init dom0_compute_nr_pages( (sizeof_long < sizeof(end) && end > (1UL << (8 * sizeof_long)= )) ) { end =3D sizeof_long >=3D sizeof(end) ? 0 : 1UL << (8 * sizeof_= long); - nr_pages =3D (end - vend) / (2 * sizeof_long); - if ( memsize_gt_zero(&dom0_min_size) && nr_pages < min_pages ) - nr_pages =3D min_pages; - printk("Dom0 memory clipped to %lu pages\n", nr_pages); + bd->mem_pages =3D (end - vend) / (2 * sizeof_long); + if ( memsize_gt_zero(&dom0_min_size) && + bd->mem_pages < bd->min_pages ) + bd->mem_pages =3D bd->min_pages; + printk("Dom0 memory clipped to %lu pages\n", bd->mem_pages); } } =20 - d->max_pages =3D min_t(unsigned long, max_pages, UINT_MAX); + d->max_pages =3D min_t(unsigned long, bd->max_pages, UINT_MAX); =20 - return nr_pages; + return bd->mem_pages; } =20 static void __init process_dom0_ioports_disable(struct domain *dom0) diff --git a/xen/arch/x86/hvm/dom0_build.c b/xen/arch/x86/hvm/dom0_build.c index b4ffebdde00e..a818a9a772ed 100644 --- a/xen/arch/x86/hvm/dom0_build.c +++ b/xen/arch/x86/hvm/dom0_build.c @@ -398,15 +398,15 @@ static __init void pvh_setup_e820(struct domain *d, u= nsigned long nr_pages) ASSERT(cur_pages =3D=3D nr_pages); } =20 -static void __init pvh_init_p2m(struct domain *d) +static void __init pvh_init_p2m(struct boot_domain *bd) { - unsigned long nr_pages =3D dom0_compute_nr_pages(d, NULL, 0); + unsigned long nr_pages =3D dom0_compute_nr_pages(bd, NULL); bool preempted; =20 - pvh_setup_e820(d, nr_pages); + pvh_setup_e820(bd->d, nr_pages); do { preempted =3D false; - paging_set_allocation(d, dom0_paging_pages(d, nr_pages), + paging_set_allocation(bd->d, dom0_paging_pages(bd->d, nr_pages), &preempted); process_pending_softirqs(); } while ( preempted ); @@ -1312,7 +1312,7 @@ static int __init pvh_setup_acpi(struct domain *d, pa= ddr_t start_info) return 0; } =20 -int __init dom0_construct_pvh(const struct boot_domain *bd) +int __init dom0_construct_pvh(struct boot_domain *bd) { paddr_t entry, start_info; struct domain *d =3D bd->d; @@ -1323,7 +1323,7 @@ int __init dom0_construct_pvh(const struct boot_domai= n *bd) * be done before the iommu initializion, since iommu initialization c= ode * will likely add mappings required by devices to the p2m (ie: RMRRs). */ - pvh_init_p2m(d); + pvh_init_p2m(bd); =20 iommu_hwdom_init(d); =20 diff --git a/xen/arch/x86/include/asm/dom0_build.h b/xen/arch/x86/include/a= sm/dom0_build.h index 426def4115ce..dcf71c032a17 100644 --- a/xen/arch/x86/include/asm/dom0_build.h +++ b/xen/arch/x86/include/asm/dom0_build.h @@ -10,14 +10,14 @@ extern unsigned int dom0_memflags; =20 void dom0_set_affinity(struct domain *dom0); =20 -unsigned long dom0_compute_nr_pages(struct domain *d, - struct elf_dom_parms *parms, - unsigned long initrd_len); int dom0_setup_permissions(struct domain *d); =20 struct boot_domain; -int dom0_construct_pv(const struct boot_domain *bd); -int dom0_construct_pvh(const struct boot_domain *bd); +unsigned long dom0_compute_nr_pages( + struct boot_domain *bd, struct elf_dom_parms *parms); + +int dom0_construct_pv(struct boot_domain *bd); +int dom0_construct_pvh(struct boot_domain *bd); =20 unsigned long dom0_paging_pages(const struct domain *d, unsigned long nr_pages); diff --git a/xen/arch/x86/pv/dom0_build.c b/xen/arch/x86/pv/dom0_build.c index 3b2baf057b75..350a60b1e8fd 100644 --- a/xen/arch/x86/pv/dom0_build.c +++ b/xen/arch/x86/pv/dom0_build.c @@ -355,7 +355,7 @@ static struct page_info * __init alloc_chunk(struct dom= ain *d, return page; } =20 -static int __init dom0_construct(const struct boot_domain *bd) +static int __init dom0_construct(struct boot_domain *bd) { unsigned int i; int rc, order, machine; @@ -503,7 +503,7 @@ static int __init dom0_construct(const struct boot_doma= in *bd) } } =20 - nr_pages =3D dom0_compute_nr_pages(d, &parms, initrd_len); + nr_pages =3D dom0_compute_nr_pages(bd, &parms); =20 #ifdef CONFIG_PV32 if ( elf_32bit(&elf) ) @@ -1070,7 +1070,7 @@ out: return rc; } =20 -int __init dom0_construct_pv(const struct boot_domain *bd) +int __init dom0_construct_pv(struct boot_domain *bd) { unsigned long cr4 =3D read_cr4(); int rc; --=20 2.30.2