From nobody Fri Oct 31 16:34:17 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=1745100572; cv=pass; d=zohomail.com; s=zohoarc; b=WZW6v92wi1KxlHxxmKh4I/AHz/FMyZ803F8Cq2wXUGGeFlIDpktsokFQagk0tnfFMKoLc9eZhBZaOG1dpTQAhkpv2mJc8BEyd5Sj2jdh6eBPDg963IqdLhBSkoGMKx3PEBw1YH4zrWMfTfWYkAPVKiggqoG5iCjACl67PBhzTDE= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100572; 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=JN77pQspCeOkPfnup+NGDjVXEkmaX55POW75Epj0P+M=; b=k58Gi0q1q5pN3e/pWVXBZHfhznRksxER0ZFAAtUbDiMGrAmATUAAUsSyJuUZL8WMJ6rjCQuGNHszKxD8EK0/mm04feo0c69M3upnLx035I2ZYddv9shtcIa2Ni6YciU1vo1RjlHjvjyVe3oVfw1ObQ+zWDYLc9iRLplF3MMvaTY= 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 1745100571996498.8829005052246; Sat, 19 Apr 2025 15:09:31 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.960019.1352063 (Exim 4.92) (envelope-from ) id 1u6GMk-0004iz-5c; Sat, 19 Apr 2025 22:08:50 +0000 Received: by outflank-mailman (output) from mailman id 960019.1352063; Sat, 19 Apr 2025 22:08: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 1u6GMk-0004iq-0E; Sat, 19 Apr 2025 22:08:50 +0000 Received: by outflank-mailman (input) for mailman id 960019; Sat, 19 Apr 2025 22:08:48 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u6GMi-0004ik-MI for xen-devel@lists.xenproject.org; Sat, 19 Apr 2025 22:08:48 +0000 Received: from sender4-of-o50.zoho.com (sender4-of-o50.zoho.com [136.143.188.50]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id dab1ca76-1d6a-11f0-9ffb-bf95429c2676; Sun, 20 Apr 2025 00:08:43 +0200 (CEST) Received: by mx.zohomail.com with SMTPS id 174510051064835.59787454297157; Sat, 19 Apr 2025 15:08:30 -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: dab1ca76-1d6a-11f0-9ffb-bf95429c2676 ARC-Seal: i=1; a=rsa-sha256; t=1745100512; cv=none; d=zohomail.com; s=zohoarc; b=gpwctGYRt8O3btV9jHXd2KCVn+t1kjs5/Id1HPt2cbGqT026m8dmA2YTwe2AIeEij1nr31qKsZNf3o3orDK7+hLxggdUUhaQzTCEVvAzi3iNMT6n9Ro9doHh7fNjrJXsAd+VvNqWqMAsXQ6zIHFc99ZvB0vNiWLICW1mVbqdN6g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100512; 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=JN77pQspCeOkPfnup+NGDjVXEkmaX55POW75Epj0P+M=; b=Fpnoi1TDSE+n20ORDixmcAODoLeN0Olcvc9qCIs6yLkvpfowxWpLHob6conq5xfsmMXz0v/8hbMrdp3GsQzJi/yPJ9fMlJvanEDzhcpTcAXFMW+AJfAli+bDVoDDF2hmc14LDeoMyaLlxdOnFw80kvRsXLkpevvCzrAKfdC3RZM= 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=1745100512; 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=JN77pQspCeOkPfnup+NGDjVXEkmaX55POW75Epj0P+M=; b=R4S63Kf+ksPn8NQdjAgaIRPp4NbvD0HNL+//O/+YBZMB0lu8eK6T3aE2dK79pllg BcAtQAJEeFaA16i6qgi4YLfFtorYeoNCuhJX23vD9p24NsM+eCaoBbPIulWDVozxgJq 2RQUGeWTgcJAQ/chPyXDlOKvWh3eQiaRYzyNlzbo= 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, Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini Subject: [RFC 01/38] maintainers: add new section for hyperlaunch Date: Sat, 19 Apr 2025 18:07:43 -0400 Message-Id: <20250419220820.4234-2-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: 1745100573212019000 Content-Type: text/plain; charset="utf-8" Add new section to MAINTAINERS for hyperlaunch, including the files specifically added to this point under the hyperlaunch work. Signed-off-by: Daniel P. Smith --- MAINTAINERS | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index c11b82eca98f..7de671efe512 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -343,6 +343,15 @@ F: tools/misc/xenhypfs.c F: xen/common/hypfs.c F: xen/include/xen/hypfs.h =20 +HYPERLAUNCH +M: Daniel P. Smith +M: Christopher Clark +S: Supported +F: xen/x86/domain-builder/ +F: xen/x86/include/asm/bootinfo.h +F: xen/x86/include/asm/boot-domain.h +F: xen/x86/include/asm/domain-builder.h + IMX8QM/QXP SUPPORT R: John Ernberg F: xen/arch/arm/platforms/imx8qm.c --=20 2.30.2 From nobody Fri Oct 31 16:34:17 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=1745100565; cv=pass; d=zohomail.com; s=zohoarc; b=YdiYG/0/dnAlRjbu5i1AMqgPhMbvwn/FDR6tvlMB1lu5BdnP26X3cKjymd7Nrq9BP/t9TsSriAoqMzlukwuAmnYp0nLLwIDV8fx5ODHfziaqNVco1IXK45ss7sA/hxnD/HNAhBiFHdua/h4JTa1Igl7oxZ11ZeF3luxa9JtURbk= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100565; 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=7U1Fqb7JL6jeU93el9q9k/XaCyV8bA/5BXhduZX6xMc=; b=Utdb/7C5cr6uZ92IjvU4Am5tGAJ5mfAFsTqyrQ2ELTkFfAulLzsqqp+lOLjCnUmQTv0uY/lZXeB4JAxXOahAiMp3InltLV8+/+xsT3xh7BNp+xlRPw51N3wVh5pl4r40aYJKYOt8YhLAnvhTaS8BGXU0vd09/klE39BWboX3ETw= 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 1745100565240501.389746409802; Sat, 19 Apr 2025 15:09:25 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.960023.1352082 (Exim 4.92) (envelope-from ) id 1u6GN5-0005IF-Hl; Sat, 19 Apr 2025 22:09:11 +0000 Received: by outflank-mailman (output) from mailman id 960023.1352082; Sat, 19 Apr 2025 22:09:11 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u6GN5-0005I8-F0; Sat, 19 Apr 2025 22:09:11 +0000 Received: by outflank-mailman (input) for mailman id 960023; Sat, 19 Apr 2025 22:09:10 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u6GN4-0004ik-5B for xen-devel@lists.xenproject.org; Sat, 19 Apr 2025 22:09:10 +0000 Received: from sender4-of-o50.zoho.com (sender4-of-o50.zoho.com [136.143.188.50]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id e97500c2-1d6a-11f0-9ffb-bf95429c2676; Sun, 20 Apr 2025 00:09:08 +0200 (CEST) Received: by mx.zohomail.com with SMTPS id 1745100511651881.3603769819105; Sat, 19 Apr 2025 15:08:31 -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: e97500c2-1d6a-11f0-9ffb-bf95429c2676 ARC-Seal: i=1; a=rsa-sha256; t=1745100514; cv=none; d=zohomail.com; s=zohoarc; b=cWeIr/ZaTjTzuFSs20BKmaulJkwDLffqU6l4/4Exd4bwcTicA09gDRrIZ+esjjkGjuBSqeoDFjijGGZNwv9l+t84PKtg+gWkwNEHSQXTomcIOaE6F4dSKlrT/9CGdwSFw+Msd9nq3GMFy7D0M005fBm+6gmckY+B/oOfMfJjcjo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100514; 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=7U1Fqb7JL6jeU93el9q9k/XaCyV8bA/5BXhduZX6xMc=; b=Nr6/oxr21Mrk5E8FX+bIsGu4Va3loqycqmcZvP04UMMq/417XkiNPzfSvKAC5sQyStwhBoqY11s01Md5kqp0KcJEhfA66PPpgen68KHH5x58JpstFiTH1o/RINEAhkeNYsudp5ZdItdQB/KQqmw2ylOhAhK5wtJCZq4vK5a4Ing= 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=1745100514; 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=7U1Fqb7JL6jeU93el9q9k/XaCyV8bA/5BXhduZX6xMc=; b=F/L0fBS+Zo6E2TOzI0mNrNuE6naZsgg2cNz6/6M4jA9X1qJV1h2I/83RS1z+dIvI 7II99riovleZ6lIcwhDDHBn4JHUJOxHkTtLfXeB212ZTZNTgDsPIm3luRATrh8t0Sax a/3N1uxyt1gRZyEJmuKPO2ZTzYcw3+mCXriEJFQI= 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 02/38] x86/hyperlaunch: correct the naming of domain ramdisk field Date: Sat, 19 Apr 2025 18:07:44 -0400 Message-Id: <20250419220820.4234-3-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: 1745100569650019000 Content-Type: text/plain; charset="utf-8" The ramdisk field was incorrectly renamed to module without providing a sou= nd justification. Doing so creates an unnecessary indirection that can cause m= ore confusion than utility. The only way the field is populated is via a match = of a boot module of type BOOTMOD_RAMDISK. All usages of the field are cast into a variables named initrd. The attempt to generalize the field name under the guise that it could be multiplexed for other module types did so without a valid usage. The result is there is no consideration of how that multiplexi= ng would even work or be deconflict with the simultaneous presence of a ramdis= k. Moving the field name back to ramdisk to make the current code flow logical= . At a later time should there be a use case that arises where additional modules need to be passed to a domain, a more appropriate framework will be crafted that will like be more complicated than just renaming the field to something other than ramdisk. Signed-off-by: Daniel P. Smith --- xen/arch/x86/domain-builder/fdt.c | 4 ++-- xen/arch/x86/hvm/dom0_build.c | 2 +- xen/arch/x86/include/asm/boot-domain.h | 2 +- xen/arch/x86/pv/dom0_build.c | 2 +- xen/arch/x86/setup.c | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/xen/arch/x86/domain-builder/fdt.c b/xen/arch/x86/domain-builde= r/fdt.c index dbfbcffb0a9c..d2a7e010ea77 100644 --- a/xen/arch/x86/domain-builder/fdt.c +++ b/xen/arch/x86/domain-builder/fdt.c @@ -310,7 +310,7 @@ static int __init process_domain_node( { int idx; =20 - if ( bd->module ) + if ( bd->ramdisk ) { printk(XENLOG_ERR "Duplicate ramdisk module for domain %s)= \n", name); @@ -328,7 +328,7 @@ static int __init process_domain_node( =20 printk(" ramdisk: boot module %d\n", idx); bi->mods[idx].type =3D BOOTMOD_RAMDISK; - bd->module =3D &bi->mods[idx]; + bd->ramdisk =3D &bi->mods[idx]; =20 continue; } diff --git a/xen/arch/x86/hvm/dom0_build.c b/xen/arch/x86/hvm/dom0_build.c index ebad5a49b8d4..176b253d3c61 100644 --- a/xen/arch/x86/hvm/dom0_build.c +++ b/xen/arch/x86/hvm/dom0_build.c @@ -648,7 +648,7 @@ static int __init pvh_load_kernel( { struct domain *d =3D bd->d; struct boot_module *image =3D bd->kernel; - struct boot_module *initrd =3D bd->module; + struct boot_module *initrd =3D bd->ramdisk; void *image_base =3D bootstrap_map_bm(image); void *image_start =3D image_base + image->headroom; unsigned long image_len =3D image->size; diff --git a/xen/arch/x86/include/asm/boot-domain.h b/xen/arch/x86/include/= asm/boot-domain.h index 29a7d806de1a..b0f956cd734e 100644 --- a/xen/arch/x86/include/asm/boot-domain.h +++ b/xen/arch/x86/include/asm/boot-domain.h @@ -29,7 +29,7 @@ struct boot_domain { unsigned int max_vcpus; =20 struct boot_module *kernel; - struct boot_module *module; + struct boot_module *ramdisk; const char *cmdline; =20 struct domain *d; diff --git a/xen/arch/x86/pv/dom0_build.c b/xen/arch/x86/pv/dom0_build.c index e1b78d47c218..3b2baf057b75 100644 --- a/xen/arch/x86/pv/dom0_build.c +++ b/xen/arch/x86/pv/dom0_build.c @@ -375,7 +375,7 @@ static int __init dom0_construct(const struct boot_doma= in *bd) struct vcpu *v =3D d->vcpu[0]; =20 struct boot_module *image =3D bd->kernel; - struct boot_module *initrd =3D bd->module; + struct boot_module *initrd =3D bd->ramdisk; void *image_base; unsigned long image_len; void *image_start; diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 1e7bbc415e1d..6a939ccede3f 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -2165,7 +2165,7 @@ void asmlinkage __init noreturn __start_xen(void) if ( !bi->hyperlaunch_enabled && initrdidx < MAX_NR_BOOTMODS ) { bi->mods[initrdidx].type =3D BOOTMOD_RAMDISK; - bi->domains[0].module =3D &bi->mods[initrdidx]; + bi->domains[0].ramdisk =3D &bi->mods[initrdidx]; if ( first_boot_module_index(bi, BOOTMOD_UNKNOWN) < MAX_NR_BOOTMOD= S ) printk(XENLOG_WARNING "Multiple initrd candidates, picking module #%u\n", --=20 2.30.2 From nobody Fri Oct 31 16:34:17 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=1745100580; cv=pass; d=zohomail.com; s=zohoarc; b=Y2QZ1GLxoFmpEqQet5N/zu0UXf6N/NkoreWSYSBr1LbrHs+KOcTsob5pZSP+p2c581EgkX9obV0I0kgfBxk27hcgSXKjNdt/9vo+lms75c0lyUQ5+L4peUh+zSWuXBOgpCZVXUuc2BbEylnr8huTrA2nC+BdYu/8anzNbTVhpOc= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100580; 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=YokNzpGdgI0vQMpM08lo4NE+yMaBURARXSs0s10k4IU=; b=kzBvNFmwB6HIOCuOTninyNPhCPONvX4yZtyiodcSnKQ1VztBU10cnPKh26J+FtWgodIiF6cwPMjna8MGZOrncfW58HNH7biLaia/t8qJGLJ57qVodckSLzy9V58I/HlEzS7HaL9sJau9U1rLvxknCP299T0bIt7upT4hFreRI0E= 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 1745100580186732.0566330816124; Sat, 19 Apr 2025 15:09:40 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.960028.1352093 (Exim 4.92) (envelope-from ) id 1u6GNE-0005jx-QI; Sat, 19 Apr 2025 22:09:20 +0000 Received: by outflank-mailman (output) from mailman id 960028.1352093; Sat, 19 Apr 2025 22:09:20 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u6GNE-0005jq-NQ; Sat, 19 Apr 2025 22:09:20 +0000 Received: by outflank-mailman (input) for mailman id 960028; Sat, 19 Apr 2025 22:09:19 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u6GND-0004ik-FL for xen-devel@lists.xenproject.org; Sat, 19 Apr 2025 22:09:19 +0000 Received: from sender4-of-o50.zoho.com (sender4-of-o50.zoho.com [136.143.188.50]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id ef1c04f2-1d6a-11f0-9ffb-bf95429c2676; Sun, 20 Apr 2025 00:09:17 +0200 (CEST) Received: by mx.zohomail.com with SMTPS id 1745100512455384.54233147742355; Sat, 19 Apr 2025 15:08:32 -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: ef1c04f2-1d6a-11f0-9ffb-bf95429c2676 ARC-Seal: i=1; a=rsa-sha256; t=1745100514; cv=none; d=zohomail.com; s=zohoarc; b=kea+OpCMbrU3niOqZ4LOEwuW42skHXjA8N5TrltliYaj/a6mW4QNYiGU3lwmAZbzWUKba8mcY/i6Odpa4LFMHDfqm5NiEPedJLUmR/8JJx1EcZlT04TIZXNL7b7D2YC7jI3pVtN0n6Z23FegLNH6aCmcfH03ylXooy0EOsR8i4M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100514; 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=YokNzpGdgI0vQMpM08lo4NE+yMaBURARXSs0s10k4IU=; b=EHi61hS/Sa1kndbQpbdGURi8SKMwBdvwG2DsXey3X1ecXJRER2y9woP9g/P5UCK85cNydRfYIcuIxJkc9UXojONewLZCHLSZ5VrqIe9rayRwu+eH4oJb9eXvF3uJo/LkD2iFFFSOUCdxSzEDF0F4OWAbeVfnNfyYO0aWTlEfiXw= 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=1745100514; 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=YokNzpGdgI0vQMpM08lo4NE+yMaBURARXSs0s10k4IU=; b=CRabSLX/9Tp3KlF0bltxA3SF8iGKnnVgyojCoTdMzwINEkuTMieLstBIHwYXf8mG bwQUQSmn9xaDs9k6IPaAeJHUE0ut2hkmwztFL6Qi0H6K8uu1KbgNPuL2JHeJQadqDSo njvPS1h/vtAJ8jvF1hpBJZSso/9Yihnr0j8xHueg= 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 03/38] x86/hyperlaunch: convert max vcpu determination to domain builder Date: Sat, 19 Apr 2025 18:07:45 -0400 Message-Id: <20250419220820.4234-4-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: 1745100581163019000 Content-Type: text/plain; charset="utf-8" The domain configuration may request more vcpus than are present in the sys= tem. For dom0, the function dom0_max_vcpus() was used to clamp down to physically available vcpus. Here we are introducing a generalized version, dom_max_vcpus(), that takes a boot domain and sets the max vcpus based on t= he lesser of the requested max and the available vcpus. Signed-off-by: Daniel P. Smith --- xen/arch/x86/domain-builder/Makefile | 1 + xen/arch/x86/domain-builder/domain.c | 38 +++++++++++++++++++++++ xen/arch/x86/include/asm/domain-builder.h | 1 + xen/arch/x86/setup.c | 4 +-- 4 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 xen/arch/x86/domain-builder/domain.c diff --git a/xen/arch/x86/domain-builder/Makefile b/xen/arch/x86/domain-bui= lder/Makefile index b10cd56b286b..67024b5cb213 100644 --- a/xen/arch/x86/domain-builder/Makefile +++ b/xen/arch/x86/domain-builder/Makefile @@ -1,2 +1,3 @@ obj-$(CONFIG_DOMAIN_BUILDER) +=3D fdt.init.o obj-y +=3D core.init.o +obj-y +=3D domain.init.o diff --git a/xen/arch/x86/domain-builder/domain.c b/xen/arch/x86/domain-bui= lder/domain.c new file mode 100644 index 000000000000..f2277b9e3cf3 --- /dev/null +++ b/xen/arch/x86/domain-builder/domain.c @@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (C) 2024, Apertus Solutions, LLC + */ + +#include +#include +#include +#include + +#include + +unsigned int __init dom_max_vcpus(struct boot_domain *bd) +{ + unsigned int limit =3D bd->mode & BUILD_MODE_PARAVIRT ? + MAX_VIRT_CPUS : HVM_MAX_VCPUS; + + if ( bd->capabilities & BUILD_CAPS_CONTROL ) + limit =3D dom0_max_vcpus(); + else + limit =3D min(limit, + (uint32_t)cpumask_weight(cpupool_valid_cpus(cpupool0))= ); + + if ( bd->max_vcpus =3D=3D 0 || bd->max_vcpus > limit ) + bd->max_vcpus =3D limit; + + return bd->max_vcpus; +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/arch/x86/include/asm/domain-builder.h b/xen/arch/x86/inclu= de/asm/domain-builder.h index 7518b6ddf3b9..f37f73e2255b 100644 --- a/xen/arch/x86/include/asm/domain-builder.h +++ b/xen/arch/x86/include/asm/domain-builder.h @@ -8,5 +8,6 @@ int __init builder_get_cmdline( struct boot_info *bi, int offset, char *cmdline, size_t size); =20 void builder_init(struct boot_info *bi); +unsigned int dom_max_vcpus(struct boot_domain *bd); =20 #endif diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 6a939ccede3f..86bbd7c72ccd 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -1010,18 +1010,18 @@ static struct domain *__init create_dom0(struct boo= t_info *bi) char *cmdline =3D NULL; size_t cmdline_size; unsigned int create_flags =3D 0; + struct boot_domain *bd =3D &bi->domains[0]; struct xen_domctl_createdomain dom0_cfg =3D { .flags =3D IS_ENABLED(CONFIG_TBOOT) ? XEN_DOMCTL_CDF_s3_integrity = : 0, .max_evtchn_port =3D -1, .max_grant_frames =3D -1, .max_maptrack_frames =3D -1, .grant_opts =3D XEN_DOMCTL_GRANT_version(opt_gnttab_max_version), - .max_vcpus =3D dom0_max_vcpus(), + .max_vcpus =3D dom_max_vcpus(bd), .arch =3D { .misc_flags =3D opt_dom0_msr_relaxed ? XEN_X86_MSR_RELAXED : 0, }, }; - struct boot_domain *bd =3D &bi->domains[0]; struct domain *d; =20 if ( opt_dom0_pvh || --=20 2.30.2 From nobody Fri Oct 31 16:34:17 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=1745100658; cv=pass; d=zohomail.com; s=zohoarc; b=USvvk+noEX6ycAu+y7OQJyUflCVzd8X8tIULde5Npfir4T/TA8I/mibMnfAJyatUbImaN0Nmi7+sANZNuR7gTtn9U44pHBf0n791F5jZSFERBXZHd83DOfCsKlk82anqbx/27rKecavCO7GiRJbnjXFgh+xID1apFBteG3VA9R4= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100658; 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=RMChXQEbn8VdNk3SfUK0sU6zoeUdrE3WHdblV3zR214=; b=EXII4PsAbKcNkWpi69qhqboS4QQxmdZsZ4OXrqOz7DfgcmopaYS7vbh+YAPMgqUfYrvn7fE+l7mvOjaYxEcVxHNty9eOtheaQZdKRad1PqJPUuwzG3uKHLZ+cKJCXnZYWcg3VA3vrVaAwTCqc9UZuWCH5g719wrZrxWrFhBq+2o= 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 1745100658634808.5717024565928; Sat, 19 Apr 2025 15:10:58 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.960054.1352129 (Exim 4.92) (envelope-from ) id 1u6GOW-0008Tj-1h; Sat, 19 Apr 2025 22:10:40 +0000 Received: by outflank-mailman (output) from mailman id 960054.1352129; 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 1u6GOV-0008Sa-Ov; Sat, 19 Apr 2025 22:10:39 +0000 Received: by outflank-mailman (input) for mailman id 960054; Sat, 19 Apr 2025 22:10:38 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u6GNU-0004ik-Kq for xen-devel@lists.xenproject.org; Sat, 19 Apr 2025 22:09:36 +0000 Received: from sender4-of-o50.zoho.com (sender4-of-o50.zoho.com [136.143.188.50]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id f95b684d-1d6a-11f0-9ffb-bf95429c2676; Sun, 20 Apr 2025 00:09:35 +0200 (CEST) Received: by mx.zohomail.com with SMTPS id 1745100513263991.7777778756324; Sat, 19 Apr 2025 15:08:33 -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: f95b684d-1d6a-11f0-9ffb-bf95429c2676 ARC-Seal: i=1; a=rsa-sha256; t=1745100516; cv=none; d=zohomail.com; s=zohoarc; b=efqKFhmcoG5CWJTP8QZaneW/AuCNBU3qodA6+4pfFr8a9ikNCAHFULjIl+3QnJZ7LvkHwS+I3BORSA7ovrcSdvxNRDQbuWXDdsH/oQl/KQ6QQGWnHaGCqzcbTaz2K/mxzJHC0huMQf6nXAYXa2h8BCjDggCS3jD6wQK+S/pn/gk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100516; 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=RMChXQEbn8VdNk3SfUK0sU6zoeUdrE3WHdblV3zR214=; b=mBoxjwbrXklJQ/ifOeMI7JI3hCA68235zuqJC8Rr+LyMi40qIJxoYHxNG4RRmnFfHuwQDIwjtm+bP+MiZeE+jTFwhFhEGehN4i+ulAqUPKkqPREtQnrQ+TksudguWwUdQiSrm+B/CxZ0rfbY7qOmUIB0OuRzg5+96wH+a3XXkv8= 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=1745100516; 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=RMChXQEbn8VdNk3SfUK0sU6zoeUdrE3WHdblV3zR214=; b=E4nhnPjAKD58SIln8nfWbFzIX6XLbeGfftzUzadtVbUlfsUpB4AJHj01C33A7ll4 rM/uP5iY98xryRfqf7yCtqNt+m+VaawEiSKUmgOgi8JW9Jw00jCJaiGSNGJB52KjL4c LI37EFuU8FUvB9jZuUelnBw3sL39NvnT5pbQJe88= 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 04/38] x86/hyperlaunch: convert vcpu0 creation to domain builder Date: Sat, 19 Apr 2025 18:07:46 -0400 Message-Id: <20250419220820.4234-5-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: 1745100659339019000 Content-Type: text/plain; charset="utf-8" Convert alloc_dom0_vcpu0() to dom0_set_affinity(), making it only set up the node affinity based on command line parameters passed. At the same time, introduce alloc_dom_vcpu0() as the replacement for alloc_dom0_vcpu(). Then = have alloc_dom_vcpu0() call dom0_set_affinity() when the boot domain is the cont= rol domain, otherwise set the affinity to auto. Signed-off-by: Daniel P. Smith --- xen/arch/x86/dom0_build.c | 4 +--- xen/arch/x86/domain-builder/domain.c | 11 +++++++++++ xen/arch/x86/include/asm/dom0_build.h | 2 ++ xen/arch/x86/include/asm/domain-builder.h | 1 + xen/arch/x86/setup.c | 5 +++-- 5 files changed, 18 insertions(+), 5 deletions(-) diff --git a/xen/arch/x86/dom0_build.c b/xen/arch/x86/dom0_build.c index 7b3e31a08f7d..77386cd1e20c 100644 --- a/xen/arch/x86/dom0_build.c +++ b/xen/arch/x86/dom0_build.c @@ -254,12 +254,10 @@ unsigned int __init dom0_max_vcpus(void) return max_vcpus; } =20 -struct vcpu *__init alloc_dom0_vcpu0(struct domain *dom0) +void __init dom0_set_affinity(struct domain *dom0) { dom0->node_affinity =3D dom0_nodes; dom0->auto_node_affinity =3D !dom0_nr_pxms; - - return vcpu_create(dom0, 0); } =20 #ifdef CONFIG_SHADOW_PAGING diff --git a/xen/arch/x86/domain-builder/domain.c b/xen/arch/x86/domain-bui= lder/domain.c index f2277b9e3cf3..619d36ea0b87 100644 --- a/xen/arch/x86/domain-builder/domain.c +++ b/xen/arch/x86/domain-builder/domain.c @@ -9,6 +9,7 @@ #include =20 #include +#include =20 unsigned int __init dom_max_vcpus(struct boot_domain *bd) { @@ -27,6 +28,16 @@ unsigned int __init dom_max_vcpus(struct boot_domain *bd) return bd->max_vcpus; } =20 +struct vcpu *__init alloc_dom_vcpu0(struct boot_domain *bd) +{ + if ( bd->capabilities & BUILD_CAPS_CONTROL ) + dom0_set_affinity(bd->d); + else + bd->d->auto_node_affinity =3D true; + + return vcpu_create(bd->d, 0); +} + /* * Local variables: * mode: C diff --git a/xen/arch/x86/include/asm/dom0_build.h b/xen/arch/x86/include/a= sm/dom0_build.h index ff021c24af9d..426def4115ce 100644 --- a/xen/arch/x86/include/asm/dom0_build.h +++ b/xen/arch/x86/include/asm/dom0_build.h @@ -8,6 +8,8 @@ =20 extern unsigned int dom0_memflags; =20 +void dom0_set_affinity(struct domain *dom0); + unsigned long dom0_compute_nr_pages(struct domain *d, struct elf_dom_parms *parms, unsigned long initrd_len); diff --git a/xen/arch/x86/include/asm/domain-builder.h b/xen/arch/x86/inclu= de/asm/domain-builder.h index f37f73e2255b..dd47e9ac0dc6 100644 --- a/xen/arch/x86/include/asm/domain-builder.h +++ b/xen/arch/x86/include/asm/domain-builder.h @@ -9,5 +9,6 @@ int __init builder_get_cmdline( =20 void builder_init(struct boot_info *bi); unsigned int dom_max_vcpus(struct boot_domain *bd); +struct vcpu *alloc_dom_vcpu0(struct boot_domain *bd); =20 #endif diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 86bbd7c72ccd..8ba9d592ed5a 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -1048,9 +1048,11 @@ static struct domain *__init create_dom0(struct boot= _info *bi) if ( IS_ERR(d) ) panic("Error creating d%u: %ld\n", bd->domid, PTR_ERR(d)); =20 + bd->d =3D d; + init_dom0_cpuid_policy(d); =20 - if ( alloc_dom0_vcpu0(d) =3D=3D NULL ) + if ( alloc_dom_vcpu0(bd) =3D=3D NULL ) panic("Error creating %pd vcpu 0\n", d); =20 cmdline_size =3D domain_cmdline_size(bi, bd); @@ -1090,7 +1092,6 @@ static struct domain *__init create_dom0(struct boot_= info *bi) bd->cmdline =3D cmdline; } =20 - bd->d =3D d; if ( construct_dom0(bd) !=3D 0 ) panic("Could not construct domain 0\n"); =20 --=20 2.30.2 From nobody Fri Oct 31 16:34:17 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=1745100704; cv=pass; d=zohomail.com; s=zohoarc; b=mKHgco74HWlbYXRgrT07WVD/M0XMeQdrxXS17ddJ2TQhz0WPjHD1BI86In8V/CYlLLAO4EKqGnp9W8zdeO/+tEsINh5a9+bg43CzPoatPs2VXlBPxLSG6A+P9O/rXCpZLgc7C7kz4zvyoaSiIGsnXKP5yAV+d+JQkK9cUl8iZsI= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100704; 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=joeZ5CWNCE6Z2Un/cJIOF/EP6nfinf+YaJF/l3mCceo=; b=MjwhGcbaTCMM1u1vV2TSsVY2ZGGBDbK25xNRhH36W166FKk0zERCpnXTJVnbcYdyWCnRFXFLu1rg6MRcM02nhiDwc0PfwROBZPMsVnGxPlF/uCpmcaDT8yw82BevBp2MddwBM8keU+TyH7ATX+0r+WVLDFG9e5P7vjExSqdH48o= 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 1745100704605312.9161982803073; Sat, 19 Apr 2025 15:11:44 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.960066.1352183 (Exim 4.92) (envelope-from ) id 1u6GOg-00020I-Sp; Sat, 19 Apr 2025 22:10:50 +0000 Received: by outflank-mailman (output) from mailman id 960066.1352183; Sat, 19 Apr 2025 22:10: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 1u6GOg-000201-NT; Sat, 19 Apr 2025 22:10:50 +0000 Received: by outflank-mailman (input) for mailman id 960066; Sat, 19 Apr 2025 22:10:48 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u6GNN-0004ik-Oj for xen-devel@lists.xenproject.org; Sat, 19 Apr 2025 22:09:29 +0000 Received: from sender4-of-o50.zoho.com (sender4-of-o50.zoho.com [136.143.188.50]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id f48916eb-1d6a-11f0-9ffb-bf95429c2676; Sun, 20 Apr 2025 00:09:26 +0200 (CEST) Received: by mx.zohomail.com with SMTPS id 1745100514143191.97463134767452; Sat, 19 Apr 2025 15:08:34 -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: f48916eb-1d6a-11f0-9ffb-bf95429c2676 ARC-Seal: i=1; a=rsa-sha256; t=1745100516; cv=none; d=zohomail.com; s=zohoarc; b=EnLesCv4QdHgS2G5laY0Pexlzv+GIkpcoOLjJ/mfBaFaA5Avm/8t04M/xMfrP9N4525LY9UDsy/knSSE7RHpYD12fl53fL3PFwjtoXdHk28J+PO+p0MI8bnWzMGRPhKI66cLqZ/F/UeP9teKYXYRyDRTfME2tYhu1EyuDPKL9ls= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100516; 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=joeZ5CWNCE6Z2Un/cJIOF/EP6nfinf+YaJF/l3mCceo=; b=b6si5+cb73AugZitj+DILLZn4LOtZhVhoJSfqiJ8d3ugzsNecqa65SI9EbEwStYCKfu/jBF7+aIZaDZZwjlw/dByGFdYzwsJEWCo1OtLmObPfUqyDCc5feug/JQacpaF/AcLG2XKD73bPozCZkM+OUtfglAhYBpkcHZ4pdvSLrg= 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=1745100516; 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=joeZ5CWNCE6Z2Un/cJIOF/EP6nfinf+YaJF/l3mCceo=; b=jwe/gSb1XnvZG0Pyu6cJi03zm/soy673yJ4TTvVGXRW7YP/J0nPzWhfFNzrTB5mK Qk/wzD5uq8u6DtPxq9/3HE77iq30UMOEmzRtg5FzVvdQfOh22vs4Hwic5MvInReNVjp SAiJ/0mVdL9gOpgwV6oI2r9nHK2OYWWFk9dkqbGM= 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 05/38] x86/hyperlaunch: move dom0 cpuid policy behind capability check Date: Sat, 19 Apr 2025 18:07:47 -0400 Message-Id: <20250419220820.4234-6-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: 1745100705610019000 Content-Type: text/plain; charset="utf-8" To incrementally convert create_dom0() into being a generalized domain construction function, move the dom0 specific cpuid policy behind the contr= ol domain capability. Signed-off-by: Daniel P. Smith --- xen/arch/x86/setup.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 8ba9d592ed5a..41e46f05a520 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -1050,7 +1050,8 @@ static struct domain *__init create_dom0(struct boot_= info *bi) =20 bd->d =3D d; =20 - init_dom0_cpuid_policy(d); + if ( bd->capabilities & BUILD_CAPS_CONTROL ) + init_dom0_cpuid_policy(bd->d); =20 if ( alloc_dom_vcpu0(bd) =3D=3D NULL ) panic("Error creating %pd vcpu 0\n", d); --=20 2.30.2 From nobody Fri Oct 31 16:34:17 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=1745100655; cv=pass; d=zohomail.com; s=zohoarc; b=LZCMGQNA9ULxHinfPWmhtU7I6D7TIlw88qe1j1KmFOF2mUXqRxjiZ24wbCGxJDiszIdBAaCbFEvCsfs2q6+XxbWqEj2/doFYo3kGSR+Ss6O1gCgpiZpnRaosKvUfxcfP3FhIYw1fzFiOHt3uFu/fRf7BnpszzfGCNe6V7c/ycH0= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100655; 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=KQRQAf1aUXgujyjY1AUdNyPpFSQKcdWAbK0B0zPjexU=; b=b0liMCfNDKcdIWFz/vsEILgs7N154EEE6nXUc7azWfYXFGYfyIxpj3rDQCqWUgVz6Wctu3VonhcqzUFKdk9KQE1+E4V+ah1ncC2bBEOj7pfm3I7ZWL9St6CRAxqXtXm8T62C6Af/nPJIEzCtrma5MB9sOvBZ4cV7Yj6MY3ZS6GQ= 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 1745100655277610.8964261684638; Sat, 19 Apr 2025 15:10:55 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.960053.1352122 (Exim 4.92) (envelope-from ) id 1u6GOV-0008Qn-J1; Sat, 19 Apr 2025 22:10:39 +0000 Received: by outflank-mailman (output) from mailman id 960053.1352122; Sat, 19 Apr 2025 22:10:39 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u6GOV-0008QA-GE; Sat, 19 Apr 2025 22:10:39 +0000 Received: by outflank-mailman (input) for mailman id 960053; Sat, 19 Apr 2025 22:10:37 +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 1u6GNm-0004yY-Qo for xen-devel@lists.xenproject.org; Sat, 19 Apr 2025 22:09:54 +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 04210495-1d6b-11f0-9eb0-5ba50f476ded; Sun, 20 Apr 2025 00:09:53 +0200 (CEST) Received: by mx.zohomail.com with SMTPS id 1745100514979396.05443422958285; Sat, 19 Apr 2025 15:08:34 -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: 04210495-1d6b-11f0-9eb0-5ba50f476ded ARC-Seal: i=1; a=rsa-sha256; t=1745100516; cv=none; d=zohomail.com; s=zohoarc; b=ito7tew2Glt8XnqoYYHzpIISxZA+yEIUckk8P/PFRv2kD2aRs7E2yg6DBVDDx0VsomyS7qkqet16dX/e4jzlMWsII3wcL5H9QMAVkS9GFoxumVZm7kBn8ACgtv07RRBmZFqxcPTg6CyGRcmUqlXsjcJzmDI/bJv/2Bm3tpwbZ7I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100516; 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=KQRQAf1aUXgujyjY1AUdNyPpFSQKcdWAbK0B0zPjexU=; b=RC+sXz9HC3sFhq1jN78fzkER/pYa/n6TTLdMm0aD/tZoP13FwzZiQJDPUDi2qdjz6nBGyUJQ5B5UNIEATo/+4SxzZrCqWjmZA2ubUewn2IDc/DS807JUp7w+qjWNGSL20zDoGv8mFzDtFgWu0C3zCTB9++rfpShdWrvWBB9XILw= 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=1745100516; 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=KQRQAf1aUXgujyjY1AUdNyPpFSQKcdWAbK0B0zPjexU=; b=rB6OwGotvL33oEAvVDXdQcZdLtfmPX7/Yvn+pxbYBkIEmZVLynoyV3GVmtG7S5EJ fZh52+u7ZkLYaOFPXrRl+/pX/VOLdC83yi0XRMxNTs1l2It7UfTe1gBg2yX2qmwmDjf VzIkfoHwjVyoEOI4Z+3mggyl8qpOPE1jv8gR4/v8= 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 06/38] x86/hyperlaunch: add hardware domain capability support Date: Sat, 19 Apr 2025 18:07:48 -0400 Message-Id: <20250419220820.4234-7-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: 1745100657670019000 Content-Type: text/plain; charset="utf-8" Introduce a capability flag to the capabilities property of a domain node in the hyperlaunch device tree. In the domain construction, use the capability flag to determine if CDF_hardware should be set on the domain config. Signed-off-by: Daniel P. Smith --- xen/arch/x86/domain-builder/core.c | 3 ++- xen/arch/x86/domain-builder/fdt.c | 2 ++ xen/arch/x86/include/asm/boot-domain.h | 1 + xen/arch/x86/setup.c | 8 ++++++-- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/xen/arch/x86/domain-builder/core.c b/xen/arch/x86/domain-build= er/core.c index 6ab4e6fe5333..8d137ecaaf84 100644 --- a/xen/arch/x86/domain-builder/core.c +++ b/xen/arch/x86/domain-builder/core.c @@ -96,7 +96,8 @@ void __init builder_init(struct boot_info *bi) i =3D first_boot_module_index(bi, BOOTMOD_UNKNOWN); bi->mods[i].type =3D BOOTMOD_KERNEL; bi->domains[0].kernel =3D &bi->mods[i]; - bi->domains[0].capabilities |=3D BUILD_CAPS_CONTROL; + bi->domains[0].capabilities |=3D + (BUILD_CAPS_CONTROL | BUILD_CAPS_HARDWARE); bi->nr_domains =3D 1; } } diff --git a/xen/arch/x86/domain-builder/fdt.c b/xen/arch/x86/domain-builde= r/fdt.c index d2a7e010ea77..1af58ed4eb86 100644 --- a/xen/arch/x86/domain-builder/fdt.c +++ b/xen/arch/x86/domain-builder/fdt.c @@ -267,6 +267,8 @@ static int __init process_domain_node( printk(" caps: "); if ( bd->capabilities & BUILD_CAPS_CONTROL ) printk("c"); + if ( bd->capabilities & BUILD_CAPS_HARDWARE ) + printk(" h"); printk("\n"); } } diff --git a/xen/arch/x86/include/asm/boot-domain.h b/xen/arch/x86/include/= asm/boot-domain.h index b0f956cd734e..18d144de2fea 100644 --- a/xen/arch/x86/include/asm/boot-domain.h +++ b/xen/arch/x86/include/asm/boot-domain.h @@ -15,6 +15,7 @@ struct boot_domain { =20 #define BUILD_CAPS_NONE (0) #define BUILD_CAPS_CONTROL (1 << 0) +#define BUILD_CAPS_HARDWARE (1 << 1) uint32_t capabilities; =20 /* On | Off */ diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 41e46f05a520..760262ea3d4c 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -1035,8 +1035,12 @@ static struct domain *__init create_dom0(struct boot= _info *bi) XEN_X86_EMU_LAPIC | XEN_X86_EMU_IOAPIC | XEN_X86_EMU_VPCI; } =20 - if ( iommu_enabled ) - dom0_cfg.flags |=3D XEN_DOMCTL_CDF_iommu; + if ( bd->capabilities & BUILD_CAPS_HARDWARE ) + { + create_flags |=3D CDF_hardware; + if ( iommu_enabled ) + dom0_cfg.flags |=3D XEN_DOMCTL_CDF_iommu; + } =20 if ( bd->domid =3D=3D DOMID_INVALID ) /* Create initial domain. Not d0 for pvshim. */ --=20 2.30.2 From nobody Fri Oct 31 16:34:17 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=1745100661; cv=pass; d=zohomail.com; s=zohoarc; b=nFaqGkQ7qLxNWlyx0bimfBxYGAo6nRsaKKhET8xp7mdn5B4qeDd0Hl6Zfsni5dhUHpXvmAmvV24m6YOFJfByk4tcN47OnqDdIlAQu4aScPWoNQCS3tDfwkGnKxzkbjiseaiwn73ZACj9x2f2UPp8ixEhVh+msMf0eo5gMHpvZwQ= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100661; 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=wffNFsu/3o3svqQKlatxNEBU5aErXWps6rcxpmCeDyU=; b=POLXBUQpus2lqyaM4zKMistvDRa3Fv56uYSH9jNaduGLcgkMGH49maUDWnjksnWJzI6fvB5HFnf4Di4o5sVGuYniXYpML9eja26fZcGtM7IjWzooV7ecVN/8+VsuXjarvlT/EXTcsuMW1VfOf6lEft/ve42jvuhiE7ETggly6lY= 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 17451006612699.829103101409373; Sat, 19 Apr 2025 15:11:01 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.960056.1352139 (Exim 4.92) (envelope-from ) id 1u6GOW-0000FK-QX; Sat, 19 Apr 2025 22:10:40 +0000 Received: by outflank-mailman (output) from mailman id 960056.1352139; 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-0000Cu-EN; Sat, 19 Apr 2025 22:10:40 +0000 Received: by outflank-mailman (input) for mailman id 960056; 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 1u6GO3-0004yY-0K for xen-devel@lists.xenproject.org; Sat, 19 Apr 2025 22:10:11 +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 0e441cec-1d6b-11f0-9eb0-5ba50f476ded; Sun, 20 Apr 2025 00:10:10 +0200 (CEST) Received: by mx.zohomail.com with SMTPS id 1745100515847991.1522635224128; Sat, 19 Apr 2025 15:08:35 -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: 0e441cec-1d6b-11f0-9eb0-5ba50f476ded ARC-Seal: i=1; a=rsa-sha256; t=1745100518; cv=none; d=zohomail.com; s=zohoarc; b=FLekLYGKv70f/oLlSKWLJacLb2lbO/uwu0tdWumon7bmSIL3n+eZTg7vH0dm+M9V5vtwEMWC8+vZbnCiEPTlqfaF4CkAREhHft5kHhoQj2j3BoPuAM67D3hmF1LwZvEme0vPd9Ekc2JpaIJ9IScWGYvWN2406jPeraqMWrbgrsE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100518; 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=wffNFsu/3o3svqQKlatxNEBU5aErXWps6rcxpmCeDyU=; b=LbEbEzAAJW7fRDyr2a23Z8KNe0FeiIc+qsFxxP0FLibDIpRE2v7CgMnMNwx/3xIRKQOPwETN68FKj0PmhnyTgcHSfDjRUiuIrAk1RZ0gBNd5ZK25d1isNB0j24bj6hbO1WBrGzz6YEEJnyE9kxVr6PZ7zCniSp1m6IepU4GDsmY= 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=1745100518; 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=wffNFsu/3o3svqQKlatxNEBU5aErXWps6rcxpmCeDyU=; b=hLu8TvTQsrEPpMq50NbmahoIR4sOdtzAwxLMlU3q6wvyMQAAytaUHFVRvOHqLBNC 4JQx3vg0YynZuEGOeEHBCytnWWT6VuypGCIeOYzk6tbpDyc4SCp7PBLm5oznkDEeQwm ggPx5KMhWsklzeSi87DIe8pGZfqBjFAgE1qaKvwQ= 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 07/38] x86/hyperlaunch: introduce pvh domain builder Date: Sat, 19 Apr 2025 18:07:49 -0400 Message-Id: <20250419220820.4234-8-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: 1745100663732019100 Content-Type: text/plain; charset="utf-8" Introduce dom_construct_pvh() as a wrapper around dom0_construct_pvh(). This function will be expanded as dom0 specific construction functions are generalized. Signed-off-by: Daniel P. Smith --- xen/arch/x86/dom0_build.c | 5 ++-- xen/arch/x86/hvm/Makefile | 1 + xen/arch/x86/hvm/dom_build.c | 31 +++++++++++++++++++++++ xen/arch/x86/include/asm/domain-builder.h | 2 ++ xen/arch/x86/include/asm/setup.h | 2 +- 5 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 xen/arch/x86/hvm/dom_build.c diff --git a/xen/arch/x86/dom0_build.c b/xen/arch/x86/dom0_build.c index 77386cd1e20c..08fde953a1e0 100644 --- a/xen/arch/x86/dom0_build.c +++ b/xen/arch/x86/dom0_build.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -613,7 +614,7 @@ int __init dom0_setup_permissions(struct domain *d) return rc; } =20 -int __init construct_dom0(const struct boot_domain *bd) +int __init construct_dom0(struct boot_domain *bd) { int rc; const struct domain *d =3D bd->d; @@ -637,7 +638,7 @@ int __init construct_dom0(const struct boot_domain *bd) opt_dom0_max_vcpus_max =3D bd->max_vcpus; =20 if ( is_hvm_domain(d) ) - rc =3D dom0_construct_pvh(bd); + rc =3D dom_construct_pvh(bd); else if ( is_pv_domain(d) ) rc =3D dom0_construct_pv(bd); else diff --git a/xen/arch/x86/hvm/Makefile b/xen/arch/x86/hvm/Makefile index 4c1fa5c6c2bf..2c1662b66897 100644 --- a/xen/arch/x86/hvm/Makefile +++ b/xen/arch/x86/hvm/Makefile @@ -5,6 +5,7 @@ obj-y +=3D viridian/ obj-y +=3D asid.o obj-y +=3D dm.o obj-bin-y +=3D dom0_build.init.o +obj-bin-y +=3D dom_build.init.o obj-y +=3D domain.o obj-y +=3D emulate.o obj-$(CONFIG_GRANT_TABLE) +=3D grant_table.o diff --git a/xen/arch/x86/hvm/dom_build.c b/xen/arch/x86/hvm/dom_build.c new file mode 100644 index 000000000000..7206815d64a9 --- /dev/null +++ b/xen/arch/x86/hvm/dom_build.c @@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * hvm/dom_build.c + * + * Dom builder for PVH guest. + * + * Copyright (C) 2017 Citrix Systems R&D + * Copyright (C) 2024 Apertus Solutions, LLC + */ + +#include + +#include +#include + +int __init dom_construct_pvh(struct boot_domain *bd) +{ + printk(XENLOG_INFO "*** Building a PVH Dom%d ***\n", bd->domid); + + return dom0_construct_pvh(bd); +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/arch/x86/include/asm/domain-builder.h b/xen/arch/x86/inclu= de/asm/domain-builder.h index dd47e9ac0dc6..ccfa4bd82acd 100644 --- a/xen/arch/x86/include/asm/domain-builder.h +++ b/xen/arch/x86/include/asm/domain-builder.h @@ -11,4 +11,6 @@ void builder_init(struct boot_info *bi); unsigned int dom_max_vcpus(struct boot_domain *bd); struct vcpu *alloc_dom_vcpu0(struct boot_domain *bd); =20 +int dom_construct_pvh(struct boot_domain *bd); + #endif diff --git a/xen/arch/x86/include/asm/setup.h b/xen/arch/x86/include/asm/se= tup.h index ac34c698551e..b517da6144de 100644 --- a/xen/arch/x86/include/asm/setup.h +++ b/xen/arch/x86/include/asm/setup.h @@ -27,7 +27,7 @@ void subarch_init_memory(void); void init_IRQ(void); =20 struct boot_domain; -int construct_dom0(const struct boot_domain *bd); +int construct_dom0(struct boot_domain *bd); =20 void setup_io_bitmap(struct domain *d); =20 --=20 2.30.2 From nobody Fri Oct 31 16:34:17 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=1745100712; cv=pass; d=zohomail.com; s=zohoarc; b=RHYiPa6zVEWsUoREhYrrNCgywbfMaYnhFcFiNfC/1+aHiUXT7o9wWbIkbOa6QjBLFSkirkuX5WwIm0ZONXMfchu+5se1Ku9+iMA6/SQXMSGEZi3DfgKTsNZjd8iPijXLOkPDCkWZKf1VNehla3x6IEwJE0vnks4VNACzAFfE0o4= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100712; 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=hhloariy0ivPaFgv7gJ7fUQsj5qmnZtQNfUz7swuU5o=; b=VDmZX4IzW6E/164gA95DPC6RC3g4utMxhmHzJlQEnlL4ECa0txe6BfukMHxz2s9OagO5BlMxOwLSNQFtl9fxqT25QPPZevWgVU9Xz2TZm55saTlou7k+5MTtojvUBUkEFPdSVwPRFjYTKMjO/lXKjeQlmRR6R6EITcxbj4vPdAM= 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 1745100712824696.2908028279526; Sat, 19 Apr 2025 15:11:52 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.960064.1352172 (Exim 4.92) (envelope-from ) id 1u6GOf-0001k7-FB; Sat, 19 Apr 2025 22:10:49 +0000 Received: by outflank-mailman (output) from mailman id 960064.1352172; Sat, 19 Apr 2025 22:10:49 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u6GOf-0001jz-C6; Sat, 19 Apr 2025 22:10:49 +0000 Received: by outflank-mailman (input) for mailman id 960064; Sat, 19 Apr 2025 22:10:48 +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 1u6GNu-0004yY-Fs for xen-devel@lists.xenproject.org; Sat, 19 Apr 2025 22:10:02 +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 0930067e-1d6b-11f0-9eb0-5ba50f476ded; Sun, 20 Apr 2025 00:10:01 +0200 (CEST) Received: by mx.zohomail.com with SMTPS id 1745100516695805.3400796738428; Sat, 19 Apr 2025 15:08:36 -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: 0930067e-1d6b-11f0-9eb0-5ba50f476ded ARC-Seal: i=1; a=rsa-sha256; t=1745100518; cv=none; d=zohomail.com; s=zohoarc; b=jCHtlTNbPugI4QsIOfMCSshNjkzTlnMLqAQ2vP1auU+C/EtHyN66loQ5UPnOLGrRs2fxULuzzTtaPiTNAkXIPy8FyenMkPZU2XsxZN286tyLGA/tjJnDHw1hL9XZZCgaI1B6knomTSeo60eLPRfS8SZoNuJF+DGR8NlrmN23xYI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100518; 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=hhloariy0ivPaFgv7gJ7fUQsj5qmnZtQNfUz7swuU5o=; b=dVWyCjoB36UUU+HPhr6g+dBMs7jIwim3s9O8c6XL8xOsoSSTARH3fK2aSancJeTn6c7fmvkRBw808Vhx2VoY6BquCbaqA1jh9rC47uWigznmrGbo26468PpzRqlA2hOjtasXa6vAePgcGzWY8qfJLjmfmHCxnVLw1tWqz7lp1J4= 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=1745100518; 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=hhloariy0ivPaFgv7gJ7fUQsj5qmnZtQNfUz7swuU5o=; b=Tdje/yajFWQNPQTzSYZLWr76M0NBIGJoB30uF9T8XUCB6fNMtxoDbWIXhQnPolJV +gBDPbBaXqzd+ONGwKI/A5rYrYyOrOwFP11GrY59pg6ryeOhFFmeFGDbx8MycfgyKic t+wmv7xTJm/eqI9dDJUzklKL9xn6yON+If3tpbow= 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 08/38] x86/hyperlaunch: move initial hwdom setup to dom_construct_pvh Date: Sat, 19 Apr 2025 18:07:50 -0400 Message-Id: <20250419220820.4234-9-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: 1745100713539019000 Content-Type: text/plain; charset="utf-8" Relocate the initial block of hwdom setup code from dom0_construct_pvh() ov= er to dom_construct_pvh(). No functional change. Signed-off-by: Daniel P. Smith --- xen/arch/x86/hvm/dom0_build.c | 44 ------------------------------ xen/arch/x86/hvm/dom_build.c | 50 +++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 44 deletions(-) diff --git a/xen/arch/x86/hvm/dom0_build.c b/xen/arch/x86/hvm/dom0_build.c index 176b253d3c61..b4ffebdde00e 100644 --- a/xen/arch/x86/hvm/dom0_build.c +++ b/xen/arch/x86/hvm/dom0_build.c @@ -1312,56 +1312,12 @@ static int __init pvh_setup_acpi(struct domain *d, = paddr_t start_info) return 0; } =20 -static void __hwdom_init pvh_setup_mmcfg(struct domain *d) -{ - unsigned int i; - int rc; - - for ( i =3D 0; i < pci_mmcfg_config_num; i++ ) - { - rc =3D register_vpci_mmcfg_handler(d, pci_mmcfg_config[i].address, - pci_mmcfg_config[i].start_bus_num= ber, - pci_mmcfg_config[i].end_bus_numbe= r, - pci_mmcfg_config[i].pci_segment); - if ( rc ) - printk("Unable to setup MMCFG handler at %#lx for segment %u\n= ", - pci_mmcfg_config[i].address, - pci_mmcfg_config[i].pci_segment); - } -} - int __init dom0_construct_pvh(const struct boot_domain *bd) { paddr_t entry, start_info; struct domain *d =3D bd->d; int rc; =20 - printk(XENLOG_INFO "*** Building a PVH Dom%d ***\n", d->domain_id); - - if ( bd->kernel =3D=3D NULL ) - panic("Missing kernel boot module for %pd construction\n", d); - - if ( is_hardware_domain(d) ) - { - /* - * MMCFG initialization must be performed before setting domain - * permissions, as the MCFG areas must not be part of the domain I= OMEM - * accessible regions. - */ - pvh_setup_mmcfg(d); - - /* - * Setup permissions early so that calls to add MMIO regions to the - * p2m as part of vPCI setup don't fail due to permission checks. - */ - rc =3D dom0_setup_permissions(d); - if ( rc ) - { - printk("%pd unable to setup permissions: %d\n", d, rc); - return rc; - } - } - /* * Craft dom0 physical memory map and set the paging allocation. This = must * be done before the iommu initializion, since iommu initialization c= ode diff --git a/xen/arch/x86/hvm/dom_build.c b/xen/arch/x86/hvm/dom_build.c index 7206815d64a9..b6e534226434 100644 --- a/xen/arch/x86/hvm/dom_build.c +++ b/xen/arch/x86/hvm/dom_build.c @@ -8,15 +8,65 @@ * Copyright (C) 2024 Apertus Solutions, LLC */ =20 +#include #include +#include + +#include =20 #include #include +#include +#include + +static void __hwdom_init pvh_setup_mmcfg(struct domain *d) +{ + unsigned int i; + int rc; + + for ( i =3D 0; i < pci_mmcfg_config_num; i++ ) + { + rc =3D register_vpci_mmcfg_handler(d, pci_mmcfg_config[i].address, + pci_mmcfg_config[i].start_bus_num= ber, + pci_mmcfg_config[i].end_bus_numbe= r, + pci_mmcfg_config[i].pci_segment); + if ( rc ) + printk("Unable to setup MMCFG handler at %#lx for segment %u\n= ", + pci_mmcfg_config[i].address, + pci_mmcfg_config[i].pci_segment); + } +} =20 int __init dom_construct_pvh(struct boot_domain *bd) { + int rc; + printk(XENLOG_INFO "*** Building a PVH Dom%d ***\n", bd->domid); =20 + if ( bd->kernel =3D=3D NULL ) + panic("Missing kernel boot module for %pd construction\n", bd->d); + + if ( is_hardware_domain(bd->d) ) + { + /* + * MMCFG initialization must be performed before setting domain + * permissions, as the MCFG areas must not be part of the domain I= OMEM + * accessible regions. + */ + pvh_setup_mmcfg(bd->d); + + /* + * Setup permissions early so that calls to add MMIO regions to the + * p2m as part of vPCI setup don't fail due to permission checks. + */ + rc =3D dom0_setup_permissions(bd->d); + if ( rc ) + { + printk("%pd unable to setup permissions: %d\n", bd->d, rc); + return rc; + } + } + return dom0_construct_pvh(bd); } =20 --=20 2.30.2 From nobody Fri Oct 31 16:34:17 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 From nobody Fri Oct 31 16:34:17 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=1745100653; cv=pass; d=zohomail.com; s=zohoarc; b=iMuWf2+q6OGgIl83rFxasDCn5oV70F6lfJ0Oa5buloJ9oBJ3Ciyky2jyR/0sN3viWehqm5c+HDF6FUlhb4XS0Dcpnl5nMNjQkQlGvZPJvwsiq+kfT9YKobiMiXE/L7LD9zz21SfZKy3PJRiWLS5sFzs/qXzxRybK5lq/X1oZlxI= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100653; 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=PuW9czx+Smh71kxlwwA/QW0luHAuyQMJevifyYw5t/k=; b=Qfqw9ewbMGL+WWqhIo0EwdLeIwLvm4tA22GuCPR1tXpvUBuuBIVmv0dmukwNSPDV7Ib5bxjrPf7HbbUoFvYSRDbStP3BWr7FLKTYDXdFyYUL/kZKETErJK1L5+08M1xF2mRdtk+cT+nxDZUzDcABr5rCzuAHNSdXA4WtESC1cI8= 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 1745100653556707.9848228288085; Sat, 19 Apr 2025 15:10:53 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.960052.1352113 (Exim 4.92) (envelope-from ) id 1u6GOT-0007rC-C4; Sat, 19 Apr 2025 22:10:37 +0000 Received: by outflank-mailman (output) from mailman id 960052.1352113; Sat, 19 Apr 2025 22:10:37 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u6GOT-0007r5-95; Sat, 19 Apr 2025 22:10:37 +0000 Received: by outflank-mailman (input) for mailman id 960052; Sat, 19 Apr 2025 22:10:35 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u6GOR-0007X1-CG for xen-devel@lists.xenproject.org; Sat, 19 Apr 2025 22:10:35 +0000 Received: from sender4-of-o50.zoho.com (sender4-of-o50.zoho.com [136.143.188.50]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 1c455903-1d6b-11f0-9ffb-bf95429c2676; Sun, 20 Apr 2025 00:10:33 +0200 (CEST) Received: by mx.zohomail.com with SMTPS id 1745100527528975.9353101015664; Sat, 19 Apr 2025 15:08:47 -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: 1c455903-1d6b-11f0-9ffb-bf95429c2676 ARC-Seal: i=1; a=rsa-sha256; t=1745100530; cv=none; d=zohomail.com; s=zohoarc; b=mQFgns4wlgiFGGcV0I8st8M/lQ28EOzTgXfoj9QLMsh/zr/1N5Y++d0iENcPHzWujNCIyyw4k550kmo5V7GTSWypYxH3pvmZiHmYYhpfWSmQz8dHMv3u6OOOuARIinEPl7ulkkigaEB/UMFrfClNUd4TwL/H38H/jMrrZ8MlUfA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100530; 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=PuW9czx+Smh71kxlwwA/QW0luHAuyQMJevifyYw5t/k=; b=ODQ+J7wMqkVXkGo1ANIcUZ7Rk2YnLRVwnQrJGzIoPUsGONt553R6Fu079lNzWlaoc6z7VlcHZp9JgLIWmahvMwRittuVDs9vqfpsMhd3TDXDPybGv6gKie2bbiXEAIXbg7cm8JSpq1x5DgqcKR+JzFUcAi1tGh46QCYLgqlPrjk= 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=1745100530; 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=PuW9czx+Smh71kxlwwA/QW0luHAuyQMJevifyYw5t/k=; b=Sh2tw14027QbFU8ANCcbVzYiHbUlncxACHeVTZmbh/VThXSU3fEEKbwpBMyHfYyp JXlRG2o6JbcgpjpAQgTHjg3o7gLKa3ReRIZUEJjeViuy22wm7Mj5q0ssBaivT71PNkZ Ya8uJoCJkXmC9aTJ7BDtPmxvlbNaNrAKDtEEVMRg= 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 10/38] x86/boot: refactor dom0 page calculation Date: Sat, 19 Apr 2025 18:07:52 -0400 Message-Id: <20250419220820.4234-11-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: 1745100655725019100 Content-Type: text/plain; charset="utf-8" Caution is needed when dom0 is being constructed as PV using an older kernel that does not have the elf note XEN_ELFNOTE_INIT_P2M. The logic for handling this situation is embedded directly and takes into account whether dom0 mem= ory parameters were specified using the negative allocation syntax. To prepare = for generalizing domain page allocation, isolate this logic to a separate handl= ing function. Signed-off-by: Daniel P. Smith --- xen/arch/x86/dom0_build.c | 76 +++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 35 deletions(-) diff --git a/xen/arch/x86/dom0_build.c b/xen/arch/x86/dom0_build.c index 658d81ab598c..a007e424bbe3 100644 --- a/xen/arch/x86/dom0_build.c +++ b/xen/arch/x86/dom0_build.c @@ -353,12 +353,50 @@ static void __init calculate_dom0_pages( bd->mem_pages =3D nr_pages; } =20 +static void __init dom0_pv_restrict_pages( + struct boot_domain *bd, struct elf_dom_parms *parms) +{ + if ( (parms->p2m_base =3D=3D UNSET_ADDR) && !memsize_gt_zero(&dom0_siz= e) && + (!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 + * note) require that there is enough virtual space beyond the ini= tial + * allocation to set up their initial page tables. This space is + * roughly the same size as the p2m table, so make sure the initial + * allocation doesn't consume more than about half the space that's + * available between params.virt_base and the address space end. + */ + unsigned long vstart, vend, end; + unsigned long initrd_len =3D bd->ramdisk ? bd->ramdisk->size : 0; + size_t sizeof_long =3D is_pv_32bit_domain(bd->d) ? sizeof(int) : s= izeof(long); + + vstart =3D parms->virt_base; + vend =3D round_pgup(parms->virt_kend); + if ( !parms->unmapped_initrd ) + vend +=3D round_pgup(initrd_len); + end =3D vend + bd->mem_pages * sizeof_long; + + if ( end > vstart ) + end +=3D end - vstart; + if ( end <=3D vstart || + (sizeof_long < sizeof(end) && end > (1UL << (8 * sizeof_long)= )) ) + { + end =3D sizeof_long >=3D sizeof(end) ? 0 : 1UL << (8 * sizeof_= long); + 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); + } + } +} + 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; =20 for_each_node_mask ( node, dom0_nodes ) @@ -404,40 +442,8 @@ unsigned long __init dom0_compute_nr_pages( /* Clamp according to min/max limits and available memory (final). */ 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) || (bd->mem_pages > bd->min_pag= es)) ) - { - /* - * Legacy Linux kernels (i.e. such without a XEN_ELFNOTE_INIT_P2M - * note) require that there is enough virtual space beyond the ini= tial - * allocation to set up their initial page tables. This space is - * roughly the same size as the p2m table, so make sure the initial - * allocation doesn't consume more than about half the space that's - * available between params.virt_base and the address space end. - */ - unsigned long vstart, vend, end; - size_t sizeof_long =3D is_pv_32bit_domain(d) ? sizeof(int) : sizeo= f(long); - - vstart =3D parms->virt_base; - vend =3D round_pgup(parms->virt_kend); - if ( !parms->unmapped_initrd ) - vend +=3D round_pgup(initrd_len); - end =3D vend + bd->mem_pages * sizeof_long; - - if ( end > vstart ) - end +=3D end - vstart; - if ( end <=3D vstart || - (sizeof_long < sizeof(end) && end > (1UL << (8 * sizeof_long)= )) ) - { - end =3D sizeof_long >=3D sizeof(end) ? 0 : 1UL << (8 * sizeof_= long); - 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); - } - } + if ( is_pv_domain(d) ) + dom0_pv_restrict_pages(bd, parms); =20 d->max_pages =3D min_t(unsigned long, bd->max_pages, UINT_MAX); =20 --=20 2.30.2 From nobody Fri Oct 31 16:34:17 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=1745100641; cv=pass; d=zohomail.com; s=zohoarc; b=hVz1rVDswuGEpEtafxvEv4UxVyzOtzGdk26es9dW272G3Jq7wBLLkdxGVXSqnmApgcErEk4msRl18wE+/+h0yRW0FkGqdDDqn6fleuPbqGOs5s5M61fDXRQLGGsazEv7LMEloNHQsT9WREo+I6FZMll+OPDwFdriD5VngdXVxQc= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100641; 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=gnnQ4e6BcNj4dPgTJVIEZjw47epf9LWkmO1rTgme/Dc=; b=Sf8pMSMp2f/snH4R0aLELrRDJ+v24N9zDLwlfbpptQguPCjd0KNUlVP+Ho6zbsLNmr/C1IEwQEMCYLmg+nNrxIQ6lN5b/dgPrjaxr/m0iVImrfGgRlSYTvZYLJsTj/rKsy4n/7ZFJm+tcQpecWPLPMV4EtXl0KPfwnb3y4NmqzQ= 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 1745100641827294.97041528593525; Sat, 19 Apr 2025 15:10:41 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.960051.1352103 (Exim 4.92) (envelope-from ) id 1u6GOL-0007XN-2h; Sat, 19 Apr 2025 22:10:29 +0000 Received: by outflank-mailman (output) from mailman id 960051.1352103; Sat, 19 Apr 2025 22:10:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u6GOK-0007XG-W4; Sat, 19 Apr 2025 22:10:28 +0000 Received: by outflank-mailman (input) for mailman id 960051; Sat, 19 Apr 2025 22:10:27 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u6GOJ-0007X1-SK for xen-devel@lists.xenproject.org; Sat, 19 Apr 2025 22:10:27 +0000 Received: from sender4-of-o50.zoho.com (sender4-of-o50.zoho.com [136.143.188.50]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 178494b0-1d6b-11f0-9ffb-bf95429c2676; Sun, 20 Apr 2025 00:10:25 +0200 (CEST) Received: by mx.zohomail.com with SMTPS id 1745100528528400.89376689653477; Sat, 19 Apr 2025 15:08:48 -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: 178494b0-1d6b-11f0-9ffb-bf95429c2676 ARC-Seal: i=1; a=rsa-sha256; t=1745100530; cv=none; d=zohomail.com; s=zohoarc; b=ORXGvRwhMA+cRRSbGW6WP9V7iTovf9ucdJ2qBGNyvnobMVFSHjUc2X5qPyEJqJ5VxY+oXjDhPOnXcEcmVeDIpN776Pu2QR47zkqM1u8cPm+xICk3q8MlYQJNuUiJteYFOGKM3f5ouWvLnzgLB0OAGbZbZkpcLp/KA4ZK8awQ8Vk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100530; 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=gnnQ4e6BcNj4dPgTJVIEZjw47epf9LWkmO1rTgme/Dc=; b=Ot7ULMDnjFSMdI3OUmbgLKOOELPXn+4XSUHAI3XF4xV4sk1h8OwF0drqCo6cYeadsEmXomuFfmFjpP35eyHFU52IrTs/a5FNfUdMsVnDGHIfAJxAfPpUTXih63oEaq+mxb2h5xmd/gYFTjqOSQvDz0W5q8fdI8hs1QUBMWv18d0= 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=1745100530; 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=gnnQ4e6BcNj4dPgTJVIEZjw47epf9LWkmO1rTgme/Dc=; b=TaQdMbOA4rSXg7aANGudfA0WbLaPjaZqWGj+SgzDvaGeX0y/cEfD89SsQmjbg4tN G9+A03qun6d9pkg0WN4g1S/IkBevjeVvLF1OBwoW64irA06zLagg9ulhGhXXh4i8QLK jQjRATdeL+xHS4F4mrrqOuCHTHXCKRcpIUjRX1C4= 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 11/38] x86/boot: generalize paging pages calculation Date: Sat, 19 Apr 2025 18:07:53 -0400 Message-Id: <20250419220820.4234-12-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: 1745100643635019000 Content-Type: text/plain; charset="utf-8" Modeling after libxl__get_required_paging_memory(), refactor dom0_paging_pages() to calculate the number of paging pages required for a domain that is not the control or hardware domain. As the function is being refactored, rename to dom_paging_pages() and move under the domain builder. Signed-off-by: Daniel P. Smith --- xen/arch/x86/dom0_build.c | 17 +---------------- xen/arch/x86/domain-builder/domain.c | 20 ++++++++++++++++++++ xen/arch/x86/hvm/dom0_build.c | 3 ++- xen/arch/x86/include/asm/dom0_build.h | 3 --- xen/arch/x86/include/asm/domain-builder.h | 3 +++ xen/arch/x86/pv/dom0_build.c | 3 ++- 6 files changed, 28 insertions(+), 21 deletions(-) diff --git a/xen/arch/x86/dom0_build.c b/xen/arch/x86/dom0_build.c index a007e424bbe3..1413e8c634a7 100644 --- a/xen/arch/x86/dom0_build.c +++ b/xen/arch/x86/dom0_build.c @@ -305,21 +305,6 @@ boolean_param("ro-hpet", ro_hpet); =20 unsigned int __initdata dom0_memflags =3D MEMF_no_dma|MEMF_exact_node; =20 -unsigned long __init dom0_paging_pages(const struct domain *d, - unsigned long nr_pages) -{ - /* Keep in sync with libxl__get_required_paging_memory(). */ - unsigned long memkb =3D nr_pages * (PAGE_SIZE / 1024); - - memkb =3D 4 * (256 * d->max_vcpus + - (is_pv_domain(d) ? opt_dom0_shadow || opt_pv_l1tf_hwdom - : 1 + opt_dom0_shadow) * - (memkb / 1024)); - - return DIV_ROUND_UP(memkb, 1024) << (20 - PAGE_SHIFT); -} - - /* * If allocation isn't specified, reserve 1/16th of available memory for * things like DMA buffers. This reservation is clamped to a maximum of 12= 8MB. @@ -431,7 +416,7 @@ unsigned long __init dom0_compute_nr_pages( */ calculate_dom0_pages(bd, avail); =20 - cpu_pages =3D dom0_paging_pages(d, bd->mem_pages); + cpu_pages =3D dom_paging_pages(bd, bd->mem_pages); =20 if ( !iommu_use_hap_pt(d) ) avail -=3D cpu_pages; diff --git a/xen/arch/x86/domain-builder/domain.c b/xen/arch/x86/domain-bui= lder/domain.c index 619d36ea0b87..87f538ae26c5 100644 --- a/xen/arch/x86/domain-builder/domain.c +++ b/xen/arch/x86/domain-builder/domain.c @@ -10,6 +10,26 @@ =20 #include #include +#include +#include + +unsigned long __init dom_paging_pages( + const struct boot_domain *bd, unsigned long nr_pages) +{ + /* Keep in sync with libxl__get_required_paging_memory(). */ + unsigned long memkb =3D bd->mem_pages * (PAGE_SIZE / 1024); + unsigned long factor =3D 0; + + if ( bd->capabilities & (BUILD_CAPS_CONTROL | BUILD_CAPS_HARDWARE) ) + factor =3D is_pv_domain(bd->d) ? opt_dom0_shadow || opt_pv_l1tf_hw= dom + : 1 + opt_dom0_shadow; + else + factor =3D !is_pv_domain(bd->d) + !paging_mode_hap(bd->d); + + memkb =3D 4 * (256 * bd->d->max_vcpus + (factor * (memkb / 1024))); + + return DIV_ROUND_UP(memkb, 1024) << (20 - PAGE_SHIFT); +} =20 unsigned int __init dom_max_vcpus(struct boot_domain *bd) { diff --git a/xen/arch/x86/hvm/dom0_build.c b/xen/arch/x86/hvm/dom0_build.c index a818a9a772ed..d3ad90348a1f 100644 --- a/xen/arch/x86/hvm/dom0_build.c +++ b/xen/arch/x86/hvm/dom0_build.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -406,7 +407,7 @@ static void __init pvh_init_p2m(struct boot_domain *bd) pvh_setup_e820(bd->d, nr_pages); do { preempted =3D false; - paging_set_allocation(bd->d, dom0_paging_pages(bd->d, nr_pages), + paging_set_allocation(bd->d, dom_paging_pages(bd, nr_pages), &preempted); process_pending_softirqs(); } while ( preempted ); diff --git a/xen/arch/x86/include/asm/dom0_build.h b/xen/arch/x86/include/a= sm/dom0_build.h index dcf71c032a17..81717b49b4ae 100644 --- a/xen/arch/x86/include/asm/dom0_build.h +++ b/xen/arch/x86/include/asm/dom0_build.h @@ -19,9 +19,6 @@ unsigned long dom0_compute_nr_pages( 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); - void dom0_update_physmap(bool compat, unsigned long pfn, unsigned long mfn, unsigned long vphysmap_s); =20 diff --git a/xen/arch/x86/include/asm/domain-builder.h b/xen/arch/x86/inclu= de/asm/domain-builder.h index ccfa4bd82acd..8b0b224eba41 100644 --- a/xen/arch/x86/include/asm/domain-builder.h +++ b/xen/arch/x86/include/asm/domain-builder.h @@ -8,6 +8,9 @@ int __init builder_get_cmdline( struct boot_info *bi, int offset, char *cmdline, size_t size); =20 void builder_init(struct boot_info *bi); + +unsigned long dom_paging_pages( + const struct boot_domain *d, unsigned long nr_pages); unsigned int dom_max_vcpus(struct boot_domain *bd); struct vcpu *alloc_dom_vcpu0(struct boot_domain *bd); =20 diff --git a/xen/arch/x86/pv/dom0_build.c b/xen/arch/x86/pv/dom0_build.c index 350a60b1e8fd..f8844b858082 100644 --- a/xen/arch/x86/pv/dom0_build.c +++ b/xen/arch/x86/pv/dom0_build.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -1043,7 +1044,7 @@ static int __init dom0_construct(struct boot_domain *= bd) { bool preempted; =20 - nr_pt_pages =3D dom0_paging_pages(d, nr_pages); + nr_pt_pages =3D dom_paging_pages(bd, nr_pages); =20 do { preempted =3D false; --=20 2.30.2 From nobody Fri Oct 31 16:34:17 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=1745100665; cv=pass; d=zohomail.com; s=zohoarc; b=Tpmdfr2HTSoqSyKhKIa97NZkoRCsrwhUPVOjThSviEWmBrjKK4M54WI/8ew7ZmCUNT/8MNT51a7g+FkDx5MRt3RT0Gmysvhgvd1xerlD0Sq4aLp68MMrzZe9n64N9k/reyqP20jWmuDaOAkG+MjQjCplM7cwyw+sPSZXnMs6tPI= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100665; 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=dHzsr1tvYnNwRUTIMNNdv9WOz0SDF5NOBLHUdiE196Q=; b=IuKWjSC8nYyxt37P1l97NAHOF2Njt+ipYiNo93Cdx2WO1CfZMbmZzQasRV3h7fqzQkMeZe18XFLfoqWrQGTFRLXFmqhFFBf1QQ+eiXQCX5HPJscY5XU4VLhcu/X4e3Z7CVEwLeFzojeByt0NQ2BJwgjTtrRwXYdkPmucQILr9Pk= 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 1745100665936187.7786684877193; Sat, 19 Apr 2025 15:11:05 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.960059.1352163 (Exim 4.92) (envelope-from ) id 1u6GOa-00015j-5i; Sat, 19 Apr 2025 22:10:44 +0000 Received: by outflank-mailman (output) from mailman id 960059.1352163; Sat, 19 Apr 2025 22:10:44 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u6GOa-00015C-1L; Sat, 19 Apr 2025 22:10:44 +0000 Received: by outflank-mailman (input) for mailman id 960059; Sat, 19 Apr 2025 22:10:42 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u6GOY-0007X1-RK for xen-devel@lists.xenproject.org; Sat, 19 Apr 2025 22:10:42 +0000 Received: from sender4-of-o50.zoho.com (sender4-of-o50.zoho.com [136.143.188.50]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 20d2f687-1d6b-11f0-9ffb-bf95429c2676; Sun, 20 Apr 2025 00:10:41 +0200 (CEST) Received: by mx.zohomail.com with SMTPS id 1745100529351514.2214468763436; Sat, 19 Apr 2025 15:08:49 -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: 20d2f687-1d6b-11f0-9ffb-bf95429c2676 ARC-Seal: i=1; a=rsa-sha256; t=1745100532; cv=none; d=zohomail.com; s=zohoarc; b=T1aF5NN6TQljao9et5SXqFehz11Af9QnkzBQFOWCzNE44VcUVNMM2RbVQs/C8P7PFEAvv6fiocvlGE/YsKM36kniCkssiwi50nlQfb5Lu9ucCzMbs3AiaNEOOhAcyJtXNeL0eVFiCC9zyHdjSCiMykbXZ9XggHq4Gg3mu68lR50= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100532; 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=dHzsr1tvYnNwRUTIMNNdv9WOz0SDF5NOBLHUdiE196Q=; b=cQOJOTh99Hm7F629nFKX95odWCD0sT/jjGnI9UsgJZUCPcPylhDT8f+rvcXV32+pt1ZXDBijelAlfD+JYZT6K3utduJkham17dkASvjpsOTsq5ttAQK+29UTr2Z2b03m/UFUcWB5EcRC/rrR/ozcvEIr7q287S9Lcv/Y/hgDDqI= 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=1745100532; 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=dHzsr1tvYnNwRUTIMNNdv9WOz0SDF5NOBLHUdiE196Q=; b=O+2YELmPK+BP1TVrgSsaiHBScKLb1fHZVGyy3WgIojkl6V4VISubM9uyFZa7a/ZZ E2V+cmwGPDzkYPlfxx0NAWDn6ZZRWWrWkCuWyFdHvZ5DqU7XKVoLJdCusQZfDbgbEAh /PebNTuCwWgQYslioghtUOboqFrcxo9PQVp1uqkw= 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 12/38] x86/boot: generalize compute number of domain pages Date: Sat, 19 Apr 2025 18:07:54 -0400 Message-Id: <20250419220820.4234-13-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: 1745100667996019100 Content-Type: text/plain; charset="utf-8" The amount of pages for a domain to be allocated is based on the physical n= odes a domain may be scheduled. For dom0, this can be restricted down from avail= able nodes via the dom0_nodes command line parameter. Refactor dom0_compute_nr_pages() such that only apply the dom0_nodes restriction only if the domain has the control domain or hardware domain capability flag set. In doing so, also rename the function to dom_compute_nr_pages(). Signed-off-by: Daniel P. Smith --- xen/arch/x86/dom0_build.c | 16 +++++++++++++--- xen/arch/x86/hvm/dom0_build.c | 2 +- xen/arch/x86/include/asm/dom0_build.h | 2 +- xen/arch/x86/pv/dom0_build.c | 2 +- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/xen/arch/x86/dom0_build.c b/xen/arch/x86/dom0_build.c index 1413e8c634a7..53ab1afbaa1f 100644 --- a/xen/arch/x86/dom0_build.c +++ b/xen/arch/x86/dom0_build.c @@ -377,14 +377,23 @@ static void __init dom0_pv_restrict_pages( } } =20 -unsigned long __init dom0_compute_nr_pages( +unsigned long __init dom_compute_nr_pages( struct boot_domain *bd, struct elf_dom_parms *parms) { nodeid_t node; + nodemask_t nodes =3D { 0 }; struct domain *d =3D bd->d; unsigned long avail =3D 0, iommu_pages =3D 0; =20 - for_each_node_mask ( node, dom0_nodes ) + nodes_or(nodes, nodes, node_online_map); + + /* If building dom0 or hwdom, apply command line restriction. */ + if ( bd->capabilities & (BUILD_CAPS_CONTROL | BUILD_CAPS_HARDWARE) ) + nodes_and(nodes, nodes, dom0_nodes); + + ASSERT(nodes_weight(nodes) !=3D 0); + + for_each_node_mask ( node, nodes ) avail +=3D avail_domheap_pages_region(node, 0, 0) + initial_images_nrpages(node); =20 @@ -396,7 +405,8 @@ unsigned long __init dom0_compute_nr_pages( avail -=3D d->max_vcpus - 1; =20 /* Reserve memory for iommu_dom0_init() (rough estimate). */ - if ( is_iommu_enabled(d) && !iommu_hwdom_passthrough ) + if ( is_hardware_domain(d) && is_iommu_enabled(d) + && !iommu_hwdom_passthrough ) { unsigned int s; =20 diff --git a/xen/arch/x86/hvm/dom0_build.c b/xen/arch/x86/hvm/dom0_build.c index d3ad90348a1f..f59af0e72810 100644 --- a/xen/arch/x86/hvm/dom0_build.c +++ b/xen/arch/x86/hvm/dom0_build.c @@ -401,7 +401,7 @@ static __init void pvh_setup_e820(struct domain *d, uns= igned long nr_pages) =20 static void __init pvh_init_p2m(struct boot_domain *bd) { - unsigned long nr_pages =3D dom0_compute_nr_pages(bd, NULL); + unsigned long nr_pages =3D dom_compute_nr_pages(bd, NULL); bool preempted; =20 pvh_setup_e820(bd->d, nr_pages); diff --git a/xen/arch/x86/include/asm/dom0_build.h b/xen/arch/x86/include/a= sm/dom0_build.h index 81717b49b4ae..7275bcf9ba6b 100644 --- a/xen/arch/x86/include/asm/dom0_build.h +++ b/xen/arch/x86/include/asm/dom0_build.h @@ -13,7 +13,7 @@ void dom0_set_affinity(struct domain *dom0); int dom0_setup_permissions(struct domain *d); =20 struct boot_domain; -unsigned long dom0_compute_nr_pages( +unsigned long dom_compute_nr_pages( struct boot_domain *bd, struct elf_dom_parms *parms); =20 int dom0_construct_pv(struct boot_domain *bd); diff --git a/xen/arch/x86/pv/dom0_build.c b/xen/arch/x86/pv/dom0_build.c index f8844b858082..ad4d1cc3520c 100644 --- a/xen/arch/x86/pv/dom0_build.c +++ b/xen/arch/x86/pv/dom0_build.c @@ -504,7 +504,7 @@ static int __init dom0_construct(struct boot_domain *bd) } } =20 - nr_pages =3D dom0_compute_nr_pages(bd, &parms); + nr_pages =3D dom_compute_nr_pages(bd, &parms); =20 #ifdef CONFIG_PV32 if ( elf_32bit(&elf) ) --=20 2.30.2 From nobody Fri Oct 31 16:34:17 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=1745100713; cv=pass; d=zohomail.com; s=zohoarc; b=F6/4ZKWZfV83AsCvWxZkocc9svV+/GPcLm2qLOwF0ayTinfSISVYF/2GLwCafCq/CNVH2P8haBDCVL884P0TttjQ7cPytH6hZlasOlvjXqFRsPqi/C7/UEbua3NOO0Jq8gAonUb04BPhqyNXlfq4obriEiMko2sGABVys96jKbc= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100713; 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=i4cmCekFDOf6Zqqnx0QnwPpbFO/VkKVHyAi01YfF4U4=; b=FKsWH/Wm5KeSgCJHRCGxfvsO7y7jtmK88n1SdmqQgOLY4RUkL2L28KZEjpBLH55U0X/mfLSq4XSXF6ZVaHD6S41Rk4Z7dB/V9AojZS8qQq0R0r6+yyHwgAxAOiGsVxRAKExiM8KrJoZ7ZjrTra2VSFjIuG8Ps4GpcYxzU5Jn8+M= 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 1745100713663778.3130908162993; Sat, 19 Apr 2025 15:11:53 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.960069.1352192 (Exim 4.92) (envelope-from ) id 1u6GOi-0002JS-9i; Sat, 19 Apr 2025 22:10:52 +0000 Received: by outflank-mailman (output) from mailman id 960069.1352192; Sat, 19 Apr 2025 22:10:52 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u6GOi-0002IR-3a; Sat, 19 Apr 2025 22:10:52 +0000 Received: by outflank-mailman (input) for mailman id 960069; Sat, 19 Apr 2025 22:10:51 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u6GOh-0007X1-2C for xen-devel@lists.xenproject.org; Sat, 19 Apr 2025 22:10:51 +0000 Received: from sender4-of-o50.zoho.com (sender4-of-o50.zoho.com [136.143.188.50]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 25938261-1d6b-11f0-9ffb-bf95429c2676; Sun, 20 Apr 2025 00:10:49 +0200 (CEST) Received: by mx.zohomail.com with SMTPS id 1745100530188877.5400344244114; Sat, 19 Apr 2025 15:08:50 -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: 25938261-1d6b-11f0-9ffb-bf95429c2676 ARC-Seal: i=1; a=rsa-sha256; t=1745100532; cv=none; d=zohomail.com; s=zohoarc; b=g2Pty8YVcaCEnfAg1/dz3RvPZ7/hjg2PgeRXvbCMmoSFR6cqrupwYcaTrShMGVWJe9of+kO4+h2i2bCi7uv+2rz/lGo2iVBYtPBV9OKGFDKOBV6ccWScp5iqw1J/jm77q9GGHKy70ePfp6rEPH2BFRYFo1HwgfDZYCrYoIMgDag= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100532; 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=i4cmCekFDOf6Zqqnx0QnwPpbFO/VkKVHyAi01YfF4U4=; b=K3l7lNjDShe/rNzSGfKEyZTyV9H78ALvN/bnGuY5yFqxDZBwG7TEvL5gLFR+l/97WzIXYWVR3DBu0faBjusakgb/ZxkYa9m+4VCQ3kyVBxvbAQJY5mAS0HZT4BNUGVCKmJBszm3HzJk/XoH6AtRUZbaf3OJfrS1IJXaZxWqsdoM= 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=1745100532; 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=i4cmCekFDOf6Zqqnx0QnwPpbFO/VkKVHyAi01YfF4U4=; b=nD6ofalYGXbAilkE31f+IR6dgUepXRRFNVBg418gQk+LJ8Ezg+Vi22WKzSxgNf1x gQMrGGTG5cFV0Lub/za+lLG22Qe6NxKomzIXHrvbVzbNWqLTwkHh3+jgUNaawRlzSJ9 HNMafPhADieMims7WfdoM3p2zvWYonht7us32saI= 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 13/38] x86/hyperlaunch: move page computation to domain builder Date: Sat, 19 Apr 2025 18:07:55 -0400 Message-Id: <20250419220820.4234-14-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: 1745100715613019000 Content-Type: text/plain; charset="utf-8" The function dom_compute_nr_pages() is being moved to the domain builder. F= or this to happen, the variable dom0_nodes, and the functions calculate_dom0_pages() and dom0_pv_restrict_pages() must be exported. Signed-off-by: Daniel P. Smith --- xen/arch/x86/dom0_build.c | 75 +---------------------- xen/arch/x86/domain-builder/domain.c | 70 +++++++++++++++++++++ xen/arch/x86/include/asm/dom0_build.h | 4 +- xen/arch/x86/include/asm/domain-builder.h | 5 ++ 4 files changed, 81 insertions(+), 73 deletions(-) diff --git a/xen/arch/x86/dom0_build.c b/xen/arch/x86/dom0_build.c index 53ab1afbaa1f..e488a204372b 100644 --- a/xen/arch/x86/dom0_build.c +++ b/xen/arch/x86/dom0_build.c @@ -209,7 +209,7 @@ static int __init cf_check parse_dom0_nodes(const char = *s) custom_param("dom0_nodes", parse_dom0_nodes); =20 cpumask_t __initdata dom0_cpus; -static nodemask_t __initdata dom0_nodes; +nodemask_t __initdata dom0_nodes; =20 unsigned int __init dom0_max_vcpus(void) { @@ -315,8 +315,7 @@ static unsigned long __init default_nr_pages(unsigned l= ong avail) : min(avail / 16, 128UL << (20 - PAGE_SHIFT))); } =20 -static void __init calculate_dom0_pages( - struct boot_domain *bd, unsigned long avail) +void __init calculate_dom0_pages(struct boot_domain *bd, unsigned long ava= il) { unsigned long nr_pages =3D bd->mem_pages ?: default_nr_pages(avail); =20 @@ -338,7 +337,7 @@ static void __init calculate_dom0_pages( bd->mem_pages =3D nr_pages; } =20 -static void __init dom0_pv_restrict_pages( +void __init dom0_pv_restrict_pages( struct boot_domain *bd, struct elf_dom_parms *parms) { if ( (parms->p2m_base =3D=3D UNSET_ADDR) && !memsize_gt_zero(&dom0_siz= e) && @@ -377,74 +376,6 @@ static void __init dom0_pv_restrict_pages( } } =20 -unsigned long __init dom_compute_nr_pages( - struct boot_domain *bd, struct elf_dom_parms *parms) -{ - nodeid_t node; - nodemask_t nodes =3D { 0 }; - struct domain *d =3D bd->d; - unsigned long avail =3D 0, iommu_pages =3D 0; - - nodes_or(nodes, nodes, node_online_map); - - /* If building dom0 or hwdom, apply command line restriction. */ - if ( bd->capabilities & (BUILD_CAPS_CONTROL | BUILD_CAPS_HARDWARE) ) - nodes_and(nodes, nodes, dom0_nodes); - - ASSERT(nodes_weight(nodes) !=3D 0); - - for_each_node_mask ( node, nodes ) - avail +=3D avail_domheap_pages_region(node, 0, 0) + - initial_images_nrpages(node); - - /* Reserve memory for further dom0 vcpu-struct allocations... */ - avail -=3D (d->max_vcpus - 1UL) - << get_order_from_bytes(sizeof(struct vcpu)); - /* ...and compat_l4's, if needed. */ - if ( is_pv_32bit_domain(d) ) - avail -=3D d->max_vcpus - 1; - - /* Reserve memory for iommu_dom0_init() (rough estimate). */ - if ( is_hardware_domain(d) && is_iommu_enabled(d) - && !iommu_hwdom_passthrough ) - { - unsigned int s; - - for ( s =3D 9; s < BITS_PER_LONG; s +=3D 9 ) - iommu_pages +=3D max_pdx >> s; - - avail -=3D iommu_pages; - } - - if ( paging_mode_enabled(d) || opt_dom0_shadow || opt_pv_l1tf_hwdom ) - { - unsigned long cpu_pages; - - /* - * Clamp according to min/max limits and available memory - * (preliminary). - */ - calculate_dom0_pages(bd, avail); - - cpu_pages =3D dom_paging_pages(bd, bd->mem_pages); - - if ( !iommu_use_hap_pt(d) ) - avail -=3D cpu_pages; - else if ( cpu_pages > iommu_pages ) - avail -=3D cpu_pages - iommu_pages; - } - - /* Clamp according to min/max limits and available memory (final). */ - calculate_dom0_pages(bd, avail); - - if ( is_pv_domain(d) ) - dom0_pv_restrict_pages(bd, parms); - - d->max_pages =3D min_t(unsigned long, bd->max_pages, UINT_MAX); - - return bd->mem_pages; -} - static void __init process_dom0_ioports_disable(struct domain *dom0) { unsigned long io_from, io_to; diff --git a/xen/arch/x86/domain-builder/domain.c b/xen/arch/x86/domain-bui= lder/domain.c index 87f538ae26c5..bdb4d9745ff2 100644 --- a/xen/arch/x86/domain-builder/domain.c +++ b/xen/arch/x86/domain-builder/domain.c @@ -6,6 +6,8 @@ #include #include #include +#include +#include #include =20 #include @@ -31,6 +33,74 @@ unsigned long __init dom_paging_pages( return DIV_ROUND_UP(memkb, 1024) << (20 - PAGE_SHIFT); } =20 +unsigned long __init dom_compute_nr_pages( + struct boot_domain *bd, struct elf_dom_parms *parms) +{ + nodeid_t node; + nodemask_t nodes =3D { 0 }; + struct domain *d =3D bd->d; + unsigned long avail =3D 0, iommu_pages =3D 0; + + nodes_or(nodes, nodes, node_online_map); + + /* If building dom0 or hwdom, apply command line restriction. */ + if ( bd->capabilities & (BUILD_CAPS_CONTROL | BUILD_CAPS_HARDWARE) ) + nodes_and(nodes, nodes, dom0_nodes); + + ASSERT(nodes_weight(nodes) !=3D 0); + + for_each_node_mask ( node, nodes ) + avail +=3D avail_domheap_pages_region(node, 0, 0) + + initial_images_nrpages(node); + + /* Reserve memory for further dom0 vcpu-struct allocations... */ + avail -=3D (d->max_vcpus - 1UL) + << get_order_from_bytes(sizeof(struct vcpu)); + /* ...and compat_l4's, if needed. */ + if ( is_pv_32bit_domain(d) ) + avail -=3D d->max_vcpus - 1; + + /* Reserve memory for iommu_dom0_init() (rough estimate). */ + if ( is_hardware_domain(d) && is_iommu_enabled(d) + && !iommu_hwdom_passthrough ) + { + unsigned int s; + + for ( s =3D 9; s < BITS_PER_LONG; s +=3D 9 ) + iommu_pages +=3D max_pdx >> s; + + avail -=3D iommu_pages; + } + + if ( paging_mode_enabled(d) || opt_dom0_shadow || opt_pv_l1tf_hwdom ) + { + unsigned long cpu_pages; + + /* + * Clamp according to min/max limits and available memory + * (preliminary). + */ + calculate_dom0_pages(bd, avail); + + cpu_pages =3D dom_paging_pages(bd, bd->mem_pages); + + if ( !iommu_use_hap_pt(d) ) + avail -=3D cpu_pages; + else if ( cpu_pages > iommu_pages ) + avail -=3D cpu_pages - iommu_pages; + } + + /* Clamp according to min/max limits and available memory (final). */ + calculate_dom0_pages(bd, avail); + + if ( is_pv_domain(d) ) + dom0_pv_restrict_pages(bd, parms); + + d->max_pages =3D min_t(unsigned long, bd->max_pages, UINT_MAX); + + return bd->mem_pages; +} + unsigned int __init dom_max_vcpus(struct boot_domain *bd) { unsigned int limit =3D bd->mode & BUILD_MODE_PARAVIRT ? diff --git a/xen/arch/x86/include/asm/dom0_build.h b/xen/arch/x86/include/a= sm/dom0_build.h index 7275bcf9ba6b..43a402af15b7 100644 --- a/xen/arch/x86/include/asm/dom0_build.h +++ b/xen/arch/x86/include/asm/dom0_build.h @@ -7,13 +7,15 @@ #include =20 extern unsigned int dom0_memflags; +extern nodemask_t dom0_nodes; =20 void dom0_set_affinity(struct domain *dom0); =20 int dom0_setup_permissions(struct domain *d); =20 struct boot_domain; -unsigned long dom_compute_nr_pages( +void calculate_dom0_pages(struct boot_domain *bd, unsigned long avail); +void dom0_pv_restrict_pages( struct boot_domain *bd, struct elf_dom_parms *parms); =20 int dom0_construct_pv(struct boot_domain *bd); diff --git a/xen/arch/x86/include/asm/domain-builder.h b/xen/arch/x86/inclu= de/asm/domain-builder.h index 8b0b224eba41..f9b11e06ceb8 100644 --- a/xen/arch/x86/include/asm/domain-builder.h +++ b/xen/arch/x86/include/asm/domain-builder.h @@ -11,6 +11,11 @@ void builder_init(struct boot_info *bi); =20 unsigned long dom_paging_pages( const struct boot_domain *d, unsigned long nr_pages); + +struct elf_dom_parms; +unsigned long dom_compute_nr_pages( + struct boot_domain *bd, struct elf_dom_parms *parms); + unsigned int dom_max_vcpus(struct boot_domain *bd); struct vcpu *alloc_dom_vcpu0(struct boot_domain *bd); =20 --=20 2.30.2 From nobody Fri Oct 31 16:34:17 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=1745101311; cv=pass; d=zohomail.com; s=zohoarc; b=YHdHPUmfM4A6eeFdHT2KAq/AFP3w4JFYamVeWkNI0keKYcbOvHbsweitxCIzpSUGeiD3uvfmWutKG447DSEGygLDk4rHkHDiw7wpClUjvQddmieHj7Ae88B+yayVsp8duhWBsb1vpnYPzFjs0ksqjjFXPzkET47Axo0xYisA46s= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745101311; 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=oYA+q2bu6uUk9qzE25f2Pzdoh1C0vsI/Nr7Od6zvzCs=; b=Si3jvFkgvyfADOTZy3pwEwoUup4x7SbqskI+/3JD/ntBMfPfQuc4NpD/chzdUURfUnn2B5dVjFNRtG09SMPT2KCHCNtJgeaz8L3HYuVzk/ioycLMx0j8E9wJt9Fv5/6vWvF0WMvqZRuE3cgfyJ5PwHVaaTQWoj9GQdg9ruEFFHo= 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 1745101311130553.9395893344871; Sat, 19 Apr 2025 15:21:51 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.960264.1352373 (Exim 4.92) (envelope-from ) id 1u6GZ0-0005tf-KT; Sat, 19 Apr 2025 22:21:30 +0000 Received: by outflank-mailman (output) from mailman id 960264.1352373; Sat, 19 Apr 2025 22:21:30 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u6GZ0-0005tB-FU; Sat, 19 Apr 2025 22:21:30 +0000 Received: by outflank-mailman (input) for mailman id 960264; Sat, 19 Apr 2025 22:21:29 +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 1u6GOp-0004yY-VT for xen-devel@lists.xenproject.org; Sat, 19 Apr 2025 22:10:59 +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 2acc19f6-1d6b-11f0-9eb0-5ba50f476ded; Sun, 20 Apr 2025 00:10:58 +0200 (CEST) Received: by mx.zohomail.com with SMTPS id 1745100530991699.508073613059; Sat, 19 Apr 2025 15:08:50 -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: 2acc19f6-1d6b-11f0-9eb0-5ba50f476ded ARC-Seal: i=1; a=rsa-sha256; t=1745100533; cv=none; d=zohomail.com; s=zohoarc; b=TI47jSbImDojj0GoQCgsne6LcAcZPiY8E6rV68o5qK2N1XTsj8kbYgfM6Ox/0ew1TZEns4tb77pjlEZzYXJU2AsclfkUMh5YSR3DzPcLiPMlQipLLFePTvlAk9hH4QjxnedyQMP6vOzOC5MGYAStjz486RBGz/AjzRzniHCujlk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100533; 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=oYA+q2bu6uUk9qzE25f2Pzdoh1C0vsI/Nr7Od6zvzCs=; b=QjwyOaC4kX8OZDeQWWm7/p/Rkq21KDVq1D4NqliOJI7lQmEj/PrIIWmEkvQWtAj35nZMfuKjc7QLrNJEGjVFOKjPBWJGiMPcSRQCrCZSTVSAwgHoYwJo8ZltpXv32ab+Coo/zNm3PVXsz8NWwPm+7fT77CWz2ObYZCpfxIwBQQk= 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=1745100533; 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=oYA+q2bu6uUk9qzE25f2Pzdoh1C0vsI/Nr7Od6zvzCs=; b=Y3y8tM7Hzyn6awXzgbx8ZPcZshgVrY8EL+1GoPXJS2W9iEy/J9M5beqXh2mH4QVR 3+Oous/KS8lqEOelc35XwbVERRSWwJscnli7KwYPwTmWM0eHup1doyWyNAQmWEdUEc/ HXI0ynDLq1yWnpzfyp/PrM//EaXlFmsdH2W37uA8= 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 14/38] x86/hyperlaunch: move pvh p2m init to domain builder Date: Sat, 19 Apr 2025 18:07:56 -0400 Message-Id: <20250419220820.4234-15-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: 1745101313247019000 Content-Type: text/plain; charset="utf-8" Generalize pvh_init_p2m() for use on domU and relocate under the domain builder. To support moving the function, dom0_pvh_setup_e820() was exported. Signed-off-by: Daniel P. Smith --- xen/arch/x86/hvm/dom0_build.c | 23 +---------------------- xen/arch/x86/hvm/dom_build.c | 25 +++++++++++++++++++++++++ xen/arch/x86/include/asm/dom0_build.h | 2 ++ 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/xen/arch/x86/hvm/dom0_build.c b/xen/arch/x86/hvm/dom0_build.c index f59af0e72810..4a371dfd66d7 100644 --- a/xen/arch/x86/hvm/dom0_build.c +++ b/xen/arch/x86/hvm/dom0_build.c @@ -323,7 +323,7 @@ static int __init pvh_setup_vmx_realmode_helpers(struct= domain *d) return 0; } =20 -static __init void pvh_setup_e820(struct domain *d, unsigned long nr_pages) +void __init dom0_pvh_setup_e820(struct domain *d, unsigned long nr_pages) { struct e820entry *entry, *entry_guest; unsigned int i; @@ -399,20 +399,6 @@ static __init void pvh_setup_e820(struct domain *d, un= signed long nr_pages) ASSERT(cur_pages =3D=3D nr_pages); } =20 -static void __init pvh_init_p2m(struct boot_domain *bd) -{ - unsigned long nr_pages =3D dom_compute_nr_pages(bd, NULL); - bool preempted; - - pvh_setup_e820(bd->d, nr_pages); - do { - preempted =3D false; - paging_set_allocation(bd->d, dom_paging_pages(bd, nr_pages), - &preempted); - process_pending_softirqs(); - } while ( preempted ); -} - static int __init pvh_populate_p2m(struct domain *d) { struct vcpu *v =3D d->vcpu[0]; @@ -1319,13 +1305,6 @@ int __init dom0_construct_pvh(struct boot_domain *bd) struct domain *d =3D bd->d; int rc; =20 - /* - * Craft dom0 physical memory map and set the paging allocation. This = must - * 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(bd); - iommu_hwdom_init(d); =20 rc =3D pvh_populate_p2m(d); diff --git a/xen/arch/x86/hvm/dom_build.c b/xen/arch/x86/hvm/dom_build.c index b6e534226434..05064ae9ba96 100644 --- a/xen/arch/x86/hvm/dom_build.c +++ b/xen/arch/x86/hvm/dom_build.c @@ -10,13 +10,16 @@ =20 #include #include +#include #include =20 #include =20 #include #include +#include #include +#include #include =20 static void __hwdom_init pvh_setup_mmcfg(struct domain *d) @@ -37,6 +40,20 @@ static void __hwdom_init pvh_setup_mmcfg(struct domain *= d) } } =20 +static void __init pvh_init_p2m(struct boot_domain *bd) +{ + unsigned long nr_pages =3D dom_compute_nr_pages(bd, NULL); + bool preempted; + + dom0_pvh_setup_e820(bd->d, nr_pages); + do { + preempted =3D false; + paging_set_allocation(bd->d, dom_paging_pages(bd, nr_pages), + &preempted); + process_pending_softirqs(); + } while ( preempted ); +} + int __init dom_construct_pvh(struct boot_domain *bd) { int rc; @@ -67,6 +84,14 @@ int __init dom_construct_pvh(struct boot_domain *bd) } } =20 + /* + * Craft domain physical memory map and set the paging allocation. This + * must be done before the iommu initializion, since iommu initializat= ion + * code will likely add mappings required by devices to the p2m (ie: + * RMRRs). + */ + pvh_init_p2m(bd); + return dom0_construct_pvh(bd); } =20 diff --git a/xen/arch/x86/include/asm/dom0_build.h b/xen/arch/x86/include/a= sm/dom0_build.h index 43a402af15b7..e5debd5adf9f 100644 --- a/xen/arch/x86/include/asm/dom0_build.h +++ b/xen/arch/x86/include/asm/dom0_build.h @@ -18,6 +18,8 @@ void calculate_dom0_pages(struct boot_domain *bd, unsigne= d long avail); void dom0_pv_restrict_pages( struct boot_domain *bd, struct elf_dom_parms *parms); =20 +void dom0_pvh_setup_e820(struct domain *d, unsigned long nr_pages); + int dom0_construct_pv(struct boot_domain *bd); int dom0_construct_pvh(struct boot_domain *bd); =20 --=20 2.30.2 From nobody Fri Oct 31 16:34:17 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=1745101331; cv=pass; d=zohomail.com; s=zohoarc; b=LeH+/v1Coc3WD05AOL+YFNrQbz3Elumz8s53YvrKkHvMoxwKIGNvdGLuqVJDywQUsb0ljlLl1WkIGcaI/8smFM7luW8YI0IzWMMxB4ejH6qpCRV9OxpqDkAdfz+ZbCs3F9d/W/NsedcqsDqSOWvG4fxyqqECjou09y+DVWhnUb8= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745101331; 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=ygLJ+ZFCfoz7loFx0eKO6lgsPYvnY/xYVSqzyygRmuE=; b=ZrzaHynTt5KsNLgHHCqb0FQwfxQeEyx7OEBzGc4STS5UlNNzKOAIyrd0HQ4jB3EHinrk9ZRyZ8pjZ0UzxZ5v9btMEZFKiJE0GSXHS1ODeXKjY1bJD9aySkasX7gyEbIpOMdYuivR/AhYQY1RwqyAk6khZDaSlkT0oJxP0vaYT5M= 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 174510133150247.76012361404878; Sat, 19 Apr 2025 15:22:11 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.960330.1352441 (Exim 4.92) (envelope-from ) id 1u6GZR-0002Uj-OQ; Sat, 19 Apr 2025 22:21:57 +0000 Received: by outflank-mailman (output) from mailman id 960330.1352441; Sat, 19 Apr 2025 22:21: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 1u6GZR-0002Sk-Kv; Sat, 19 Apr 2025 22:21:57 +0000 Received: by outflank-mailman (input) for mailman id 960330; Sat, 19 Apr 2025 22:21:56 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u6GPQ-0007X1-Fi for xen-devel@lists.xenproject.org; Sat, 19 Apr 2025 22:11:36 +0000 Received: from sender4-of-o50.zoho.com (sender4-of-o50.zoho.com [136.143.188.50]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 40babaa4-1d6b-11f0-9ffb-bf95429c2676; Sun, 20 Apr 2025 00:11:34 +0200 (CEST) Received: by mx.zohomail.com with SMTPS id 174510053179615.787663375016223; Sat, 19 Apr 2025 15:08:51 -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: 40babaa4-1d6b-11f0-9ffb-bf95429c2676 ARC-Seal: i=1; a=rsa-sha256; t=1745100552; cv=none; d=zohomail.com; s=zohoarc; b=GrUmxwIQbCQBJMf/yiaan/zO7WBRye4DEKlFfIdQjMq7a0ptUOFlJqs5pRCkKHPJ3syhE93a19sQZU1iwGHaxBLP1eM3NltNwWwJtsV6vDWGe0bUT0TkGUfNxZdG1x+JeH1Cor5nCkLpHp/8cqxK3XSpDJ4Atq8XjJTk5Ypv5S8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100552; 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=ygLJ+ZFCfoz7loFx0eKO6lgsPYvnY/xYVSqzyygRmuE=; b=bPT5yBqlCkGdnxZKUMwlLfs3fWKCOlQAL7oEkcjn3KdgeBVlQhFBlxoh3j8ho+5SB7eyRIRqlQ8ly4VWhM4vGwTuPEjGTXO0SDJ0ekOstfu/+08ow3TDU/ki/Hcuo1t1P/zPjEVFoTnI8m6N7czETZTazUDj1IdBQurOETh4Ua8= 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=1745100552; 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=ygLJ+ZFCfoz7loFx0eKO6lgsPYvnY/xYVSqzyygRmuE=; b=D/csDoOiJcHTeytXMVvP+aTGC1cBWBVDr5I31ACab/vDV/I0P/2mnmutKMvkA+mE tVRqSDW6QUuLcoK0i9uCJpveMPlEfs7coSUGxK5AKc1PfvtOBVoGPRa6Lq/H1GUCR1h HZzDIB3Nax33VsovnEN3Sr5lBR1KoA7fxNU6nCMQ= 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 15/38] x86/hyperlaunch: move iommu init to domain builder Date: Sat, 19 Apr 2025 18:07:57 -0400 Message-Id: <20250419220820.4234-16-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: 1745101333306019000 Content-Type: text/plain; charset="utf-8" Move invocation of iommu_hwdom_init() to dom_construct_pvh() and guard it with a hardware domain check. Signed-off-by: Daniel P. Smith --- xen/arch/x86/hvm/dom0_build.c | 2 -- xen/arch/x86/hvm/dom_build.c | 4 ++++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/hvm/dom0_build.c b/xen/arch/x86/hvm/dom0_build.c index 4a371dfd66d7..a68474b7856a 100644 --- a/xen/arch/x86/hvm/dom0_build.c +++ b/xen/arch/x86/hvm/dom0_build.c @@ -1305,8 +1305,6 @@ int __init dom0_construct_pvh(struct boot_domain *bd) struct domain *d =3D bd->d; int rc; =20 - iommu_hwdom_init(d); - rc =3D pvh_populate_p2m(d); if ( rc ) { diff --git a/xen/arch/x86/hvm/dom_build.c b/xen/arch/x86/hvm/dom_build.c index 05064ae9ba96..7fa007a6926d 100644 --- a/xen/arch/x86/hvm/dom_build.c +++ b/xen/arch/x86/hvm/dom_build.c @@ -9,6 +9,7 @@ */ =20 #include +#include #include #include #include @@ -92,6 +93,9 @@ int __init dom_construct_pvh(struct boot_domain *bd) */ pvh_init_p2m(bd); =20 + if ( is_hardware_domain(bd->d) ) + iommu_hwdom_init(bd->d); + return dom0_construct_pvh(bd); } =20 --=20 2.30.2 From nobody Fri Oct 31 16:34:17 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=1745101312; cv=pass; d=zohomail.com; s=zohoarc; b=PynNP5qXhXp3lg/WItJF1Ch812PeNtyxoPqD9UDEQ3dm0uruPuUFRv+85VQMtnwc2lk5bqfTiDKO76eC0D4xe2FPBG9ut6W1Hrc6/odee8nOmrhquWcjg2g0f1S/j6G1AJqGL53Iesu8OZ4+fN5nrr6AoM74TVUQRaoDQ+ZJZJk= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745101312; 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=KtCDPxQ2vryCzA+51vqp2dtiv9M0gWY5QbgCmpBJWTE=; b=HEM/C/Gx/pdp5CLVBTCCmwDpAql52mI0lXaI2p1+npnc+R/RvDxlLCvrFLRfBt/42spkL4QETMlCbrxNNJeGcmgDxwepq8b0FN2tlmQL1qwyGm9EksQ8NieHZ2tT7XsTosUaTdNgII2VJXBY+HvTqHV5HCe0/UwNCN6wlw3dvKo= 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 17451013123241011.2738924074293; Sat, 19 Apr 2025 15:21:52 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.960280.1352401 (Exim 4.92) (envelope-from ) id 1u6GZ9-0007JC-7A; Sat, 19 Apr 2025 22:21:39 +0000 Received: by outflank-mailman (output) from mailman id 960280.1352401; Sat, 19 Apr 2025 22:21:39 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u6GZ8-0007Ii-UF; Sat, 19 Apr 2025 22:21:38 +0000 Received: by outflank-mailman (input) for mailman id 960280; Sat, 19 Apr 2025 22:21:36 +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 1u6GQB-0004yY-HA for xen-devel@lists.xenproject.org; Sat, 19 Apr 2025 22:12:23 +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 5d502b86-1d6b-11f0-9eb0-5ba50f476ded; Sun, 20 Apr 2025 00:12:22 +0200 (CEST) Received: by mx.zohomail.com with SMTPS id 1745100532920361.96569688499153; Sat, 19 Apr 2025 15:08:52 -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: 5d502b86-1d6b-11f0-9eb0-5ba50f476ded ARC-Seal: i=1; a=rsa-sha256; t=1745100552; cv=none; d=zohomail.com; s=zohoarc; b=YfUKKtKb4csvQTdwXPO7rLklEK3/gl9qjNZcNRLoloaNc4ZehP2ukKJOUB8E7ccb22bqCjM+u7GbeCAQWEXOMJaqfuy/lOvQx6tDnIXSYA48t8kQ3AUdCxE25FzcK8xp1KfR6wNVlM+5EIRGmgH/7Ld4T61A7/BVg74jvaDH9j4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100552; 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=KtCDPxQ2vryCzA+51vqp2dtiv9M0gWY5QbgCmpBJWTE=; b=X2+jZi5MyUn+Sh2DQdLPGVadrQg3Fu6GQEu/PXb/bRhn+L6h9Leh3WE1ns++qMM4D0xIJM4c0WHVUTReikvv6oTfGScXhSfVcqqJDYBvEDVYj+lzJXgukr3NSxnEefvhuHB+rbEWHchjpfVs4JldmfN3g6LRlR9i+XzuVgirXRY= 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=1745100552; 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=KtCDPxQ2vryCzA+51vqp2dtiv9M0gWY5QbgCmpBJWTE=; b=TXGq9q33tsw1VnE9Z3Sd5ImUaTH0CJZsGF10DxBhuCz7T1Y2IWaYpGb37CtScjkk 1mts+qiXTRuAqC/gPocvksqUx0bajWFfKQnKu7Mqr3z02gcG9tldfgyGXyHXr71ON0N qSw8ojvB5oOI25J5FUNqyISmNMQL6kjQR4b0CQEQ= 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?= , Anthony PERARD , Michal Orzel , Julien Grall , Stefano Stabellini , Dario Faggioli , Juergen Gross , George Dunlap Subject: [RFC 16/38] x86/boot: move and rename sched_setup_dom0_vcpus Date: Sat, 19 Apr 2025 18:07:58 -0400 Message-Id: <20250419220820.4234-17-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: 1745101313224019000 Content-Type: text/plain; charset="utf-8" Relocated the function sched_setup_dom0_vcpus(), which was protected by an ifdef CONFIG_X86, from common/sched to the hyperlaunch domain builder. Rena= me it to alloc_dom_vcpus() to better reflect the purpose of the function. Signed-off-by: Daniel P. Smith --- xen/arch/x86/domain-builder/domain.c | 10 ++++++++++ xen/arch/x86/hvm/dom0_build.c | 2 +- xen/arch/x86/include/asm/domain-builder.h | 1 + xen/arch/x86/pv/dom0_build.c | 2 +- xen/common/sched/core.c | 12 ------------ xen/include/xen/sched.h | 1 - 6 files changed, 13 insertions(+), 15 deletions(-) diff --git a/xen/arch/x86/domain-builder/domain.c b/xen/arch/x86/domain-bui= lder/domain.c index bdb4d9745ff2..764a1af4acd3 100644 --- a/xen/arch/x86/domain-builder/domain.c +++ b/xen/arch/x86/domain-builder/domain.c @@ -128,6 +128,16 @@ struct vcpu *__init alloc_dom_vcpu0(struct boot_domain= *bd) return vcpu_create(bd->d, 0); } =20 +void __init alloc_dom_vcpus(struct domain *d) +{ + unsigned int i; + + for ( i =3D 1; i < d->max_vcpus; i++ ) + vcpu_create(d, i); + + domain_update_node_affinity(d); +} + /* * Local variables: * mode: C diff --git a/xen/arch/x86/hvm/dom0_build.c b/xen/arch/x86/hvm/dom0_build.c index a68474b7856a..2ed2d5fd7326 100644 --- a/xen/arch/x86/hvm/dom0_build.c +++ b/xen/arch/x86/hvm/dom0_build.c @@ -834,7 +834,7 @@ static int __init pvh_setup_cpus(struct domain *d, padd= r_t entry, .cpu_regs.x86_32.tr_ar =3D 0x8b, }; =20 - sched_setup_dom0_vcpus(d); + alloc_dom_vcpus(d); =20 rc =3D arch_set_info_hvm_guest(v, &cpu_ctx); if ( rc ) diff --git a/xen/arch/x86/include/asm/domain-builder.h b/xen/arch/x86/inclu= de/asm/domain-builder.h index f9b11e06ceb8..af0a24b4edf5 100644 --- a/xen/arch/x86/include/asm/domain-builder.h +++ b/xen/arch/x86/include/asm/domain-builder.h @@ -18,6 +18,7 @@ unsigned long dom_compute_nr_pages( =20 unsigned int dom_max_vcpus(struct boot_domain *bd); struct vcpu *alloc_dom_vcpu0(struct boot_domain *bd); +void alloc_dom_vcpus(struct domain *d); =20 int dom_construct_pvh(struct boot_domain *bd); =20 diff --git a/xen/arch/x86/pv/dom0_build.c b/xen/arch/x86/pv/dom0_build.c index ad4d1cc3520c..c3d269438313 100644 --- a/xen/arch/x86/pv/dom0_build.c +++ b/xen/arch/x86/pv/dom0_build.c @@ -827,7 +827,7 @@ static int __init dom0_construct(struct boot_domain *bd) =20 printk("Dom%u has maximum %u VCPUs\n", d->domain_id, d->max_vcpus); =20 - sched_setup_dom0_vcpus(d); + alloc_dom_vcpus(d); =20 d->arch.paging.mode =3D 0; =20 diff --git a/xen/common/sched/core.c b/xen/common/sched/core.c index 9043414290a8..d679d766a4b6 100644 --- a/xen/common/sched/core.c +++ b/xen/common/sched/core.c @@ -3479,18 +3479,6 @@ void wait(void) schedule(); } =20 -#ifdef CONFIG_X86 -void __init sched_setup_dom0_vcpus(struct domain *d) -{ - unsigned int i; - - for ( i =3D 1; i < d->max_vcpus; i++ ) - vcpu_create(d, i); - - domain_update_node_affinity(d); -} -#endif - #ifdef CONFIG_COMPAT #include "compat.c" #endif diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 559d201e0c7e..4f184cd76206 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -1084,7 +1084,6 @@ static inline bool sched_has_urgent_vcpu(void) } =20 void vcpu_set_periodic_timer(struct vcpu *v, s_time_t value); -void sched_setup_dom0_vcpus(struct domain *d); int vcpu_temporary_affinity(struct vcpu *v, unsigned int cpu, uint8_t reas= on); int vcpu_set_hard_affinity(struct vcpu *v, const cpumask_t *affinity); int vcpu_affinity_domctl(struct domain *d, uint32_t cmd, --=20 2.30.2 From nobody Fri Oct 31 16:34:17 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=1745101287; cv=pass; d=zohomail.com; s=zohoarc; b=DjunnUpzhPi/FgDzqIgTYlqOk4n38maZpH6GqRkuZ/FR0esrj0Qek+1sieZlpAfmwHS/xFYl4ouKdYYATofiXZ0LL4rP+QcPlC1tx4f6TVqjKmiyURk4foEWX/J72Xg8/VXcDdQLyY6SYvGL0UXM5Eb3S9rMSSnp4pZD/F54Csw= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745101287; 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=KU/isf+bIbWsd6Vdl793ESAiGNzLwhwJfrt1XINwyFs=; b=Z2w+JxotTZgrse4BslagD6nmwESwIU2408OXjCZMcs1oKPtq+dIstnWuqvOrFPW6g027Z0uOpxBnFUm+5YGR1jVd5jel2S3GEULDm9jv/sr9cK3sI0WN+w1Cem8qZCZpErlp460g1tup86CtEqp8IHMdEP9xazHc6CizAWn8pws= 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 174510128731167.21440120545083; Sat, 19 Apr 2025 15:21:27 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.960230.1352303 (Exim 4.92) (envelope-from ) id 1u6GYo-0003EF-77; Sat, 19 Apr 2025 22:21:18 +0000 Received: by outflank-mailman (output) from mailman id 960230.1352303; Sat, 19 Apr 2025 22:21:18 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u6GYo-0003E0-0j; Sat, 19 Apr 2025 22:21:18 +0000 Received: by outflank-mailman (input) for mailman id 960230; Sat, 19 Apr 2025 22:21:16 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u6GPh-0007X1-96 for xen-devel@lists.xenproject.org; Sat, 19 Apr 2025 22:11:53 +0000 Received: from sender4-of-o50.zoho.com (sender4-of-o50.zoho.com [136.143.188.50]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 4ab84614-1d6b-11f0-9ffb-bf95429c2676; Sun, 20 Apr 2025 00:11:51 +0200 (CEST) Received: by mx.zohomail.com with SMTPS id 1745100533828780.5983240234141; Sat, 19 Apr 2025 15:08:53 -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: 4ab84614-1d6b-11f0-9ffb-bf95429c2676 ARC-Seal: i=1; a=rsa-sha256; t=1745100552; cv=none; d=zohomail.com; s=zohoarc; b=YyT+hDUYlCb//OFSIs83gn2wDuEFjsUp1Ztasps0AeWRFQogcX+gE3ZKa07J3ENGw734w3rK5ko3tc6OtcPg3N4MTEpjDL/i+PYnsQh5wiOsONFEbKLUOStFni+SsmvRwUIXqOWvjbCFF29iadspoU3w/gG1unpprEG1/2cX5H4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100552; 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=KU/isf+bIbWsd6Vdl793ESAiGNzLwhwJfrt1XINwyFs=; b=UbReVHHFZ+LnnERADyahvt+K79WhHICItNe0YoacwUCX3PUCZj2Q0nE5Idp3xGOnI3GctaTtpGVzwmjLs5JbxuqHqINbjaG8IqHUdaLlAl2SrirYhKbUM7XGEoNcbK+arLvBxhUqvP4P0UDEbp9udk59iKVa2kvThpz16Pi15XQ= 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=1745100552; 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=KU/isf+bIbWsd6Vdl793ESAiGNzLwhwJfrt1XINwyFs=; b=hvTngnkgipf7LENnx6jqb4sQ8ammvGkyS75dOXseclLzVDBOYW7V3Vzhu3EV7iwd L7bbguvERst7FOJKSLnR17O6gs+Jeczpgoorr07P1he2PPJMJnG+y1V6fRvOezVBO4h FdqOa6o+E9hIIBeYQI5WmNlKttGwWniddXPN7lAw= 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 17/38] x86/hyperlaunch: move pvh_setup_cpus to domain builder Date: Sat, 19 Apr 2025 18:07:59 -0400 Message-Id: <20250419220820.4234-18-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: 1745101289132019000 Content-Type: text/plain; charset="utf-8" The function pvh_setup_cpus() is a very general function that is usable by = all HVM domains, not just PVH. As such, renaming to hvm_setup_cpus during move. Signed-off-by: Daniel P. Smith --- xen/arch/x86/hvm/dom0_build.c | 45 +---------------------- xen/arch/x86/hvm/dom_build.c | 45 +++++++++++++++++++++++ xen/arch/x86/include/asm/domain-builder.h | 2 + 3 files changed, 48 insertions(+), 44 deletions(-) diff --git a/xen/arch/x86/hvm/dom0_build.c b/xen/arch/x86/hvm/dom0_build.c index 2ed2d5fd7326..a3b6afc5318a 100644 --- a/xen/arch/x86/hvm/dom0_build.c +++ b/xen/arch/x86/hvm/dom0_build.c @@ -808,49 +808,6 @@ static int __init pvh_load_kernel( return 0; } =20 -static int __init pvh_setup_cpus(struct domain *d, paddr_t entry, - paddr_t start_info) -{ - struct vcpu *v =3D d->vcpu[0]; - int rc; - /* - * This sets the vCPU state according to the state described in - * docs/misc/pvh.pandoc. - */ - vcpu_hvm_context_t cpu_ctx =3D { - .mode =3D VCPU_HVM_MODE_32B, - .cpu_regs.x86_32.ebx =3D start_info, - .cpu_regs.x86_32.eip =3D entry, - .cpu_regs.x86_32.cr0 =3D X86_CR0_PE | X86_CR0_ET, - .cpu_regs.x86_32.cs_limit =3D ~0u, - .cpu_regs.x86_32.ds_limit =3D ~0u, - .cpu_regs.x86_32.es_limit =3D ~0u, - .cpu_regs.x86_32.ss_limit =3D ~0u, - .cpu_regs.x86_32.tr_limit =3D 0x67, - .cpu_regs.x86_32.cs_ar =3D 0xc9b, - .cpu_regs.x86_32.ds_ar =3D 0xc93, - .cpu_regs.x86_32.es_ar =3D 0xc93, - .cpu_regs.x86_32.ss_ar =3D 0xc93, - .cpu_regs.x86_32.tr_ar =3D 0x8b, - }; - - alloc_dom_vcpus(d); - - rc =3D arch_set_info_hvm_guest(v, &cpu_ctx); - if ( rc ) - { - printk("Unable to setup Dom0 BSP context: %d\n", rc); - return rc; - } - - update_domain_wallclock_time(d); - - v->is_initialised =3D 1; - clear_bit(_VPF_down, &v->pause_flags); - - return 0; -} - static int __init cf_check acpi_count_intr_ovr( struct acpi_subtable_header *header, const unsigned long end) { @@ -1319,7 +1276,7 @@ int __init dom0_construct_pvh(struct boot_domain *bd) return rc; } =20 - rc =3D pvh_setup_cpus(d, entry, start_info); + rc =3D hvm_setup_cpus(bd->d, entry, start_info); if ( rc ) { printk("Failed to setup Dom0 CPUs: %d\n", rc); diff --git a/xen/arch/x86/hvm/dom_build.c b/xen/arch/x86/hvm/dom_build.c index 7fa007a6926d..078e42447b0a 100644 --- a/xen/arch/x86/hvm/dom_build.c +++ b/xen/arch/x86/hvm/dom_build.c @@ -16,6 +16,8 @@ =20 #include =20 +#include + #include #include #include @@ -55,6 +57,49 @@ static void __init pvh_init_p2m(struct boot_domain *bd) } while ( preempted ); } =20 +int __init hvm_setup_cpus( + struct domain *d, paddr_t entry, paddr_t start_info) +{ + struct vcpu *v =3D d->vcpu[0]; + int rc; + /* + * This sets the vCPU state according to the state described in + * docs/misc/pvh.pandoc. + */ + vcpu_hvm_context_t cpu_ctx =3D { + .mode =3D VCPU_HVM_MODE_32B, + .cpu_regs.x86_32.ebx =3D start_info, + .cpu_regs.x86_32.eip =3D entry, + .cpu_regs.x86_32.cr0 =3D X86_CR0_PE | X86_CR0_ET, + .cpu_regs.x86_32.cs_limit =3D ~0u, + .cpu_regs.x86_32.ds_limit =3D ~0u, + .cpu_regs.x86_32.es_limit =3D ~0u, + .cpu_regs.x86_32.ss_limit =3D ~0u, + .cpu_regs.x86_32.tr_limit =3D 0x67, + .cpu_regs.x86_32.cs_ar =3D 0xc9b, + .cpu_regs.x86_32.ds_ar =3D 0xc93, + .cpu_regs.x86_32.es_ar =3D 0xc93, + .cpu_regs.x86_32.ss_ar =3D 0xc93, + .cpu_regs.x86_32.tr_ar =3D 0x8b, + }; + + alloc_dom_vcpus(d); + + rc =3D arch_set_info_hvm_guest(v, &cpu_ctx); + if ( rc ) + { + printk("Unable to setup %pd BSP context: %d\n", d, rc); + return rc; + } + + update_domain_wallclock_time(d); + + v->is_initialised =3D 1; + clear_bit(_VPF_down, &v->pause_flags); + + return 0; +} + int __init dom_construct_pvh(struct boot_domain *bd) { int rc; diff --git a/xen/arch/x86/include/asm/domain-builder.h b/xen/arch/x86/inclu= de/asm/domain-builder.h index af0a24b4edf5..7bc2fbe66bc2 100644 --- a/xen/arch/x86/include/asm/domain-builder.h +++ b/xen/arch/x86/include/asm/domain-builder.h @@ -9,6 +9,8 @@ int __init builder_get_cmdline( =20 void builder_init(struct boot_info *bi); =20 +int hvm_setup_cpus(struct domain *d, paddr_t entry, paddr_t start_info); + unsigned long dom_paging_pages( const struct boot_domain *d, unsigned long nr_pages); =20 --=20 2.30.2 From nobody Fri Oct 31 16:34:17 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=1745101315; cv=pass; d=zohomail.com; s=zohoarc; b=EzUNU6gorqtNacfuwiZayPmvk4zfbm3jqRgjWQXDBBY5XJ298oQuJQK1mOkRHney4hrLojvz2Tzwq4IVjIP6OY/lH9/cxktKPma0btqW/wTX6ZQN2qiUARS9ML0h2ixKPMjmtsyIqzoHo5ZjUWkEqY/gCjmrrrfeYUFcOyYvY+0= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745101315; 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=2mkjxzW5Ru2Q92RR48HdEoTcd4H0/JB/kPW2NI5sInE=; b=XuYblOr/Se5lrt3/WFFXQkZQxv0QG1GuFLACHH+7+M6D/dYpG3bruc+sIjPKXZMECGPh/s2CFqogWOvM1qK1chWgHQZXaGHSVkALDgmKH0S7l83PGawtAbhNMotwo6Pbk5voU0kxLAl0CsgtKU2GkXDn6VZkNysDsA8SHriAPQE= 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 1745101315416158.87311282511178; Sat, 19 Apr 2025 15:21:55 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.960275.1352389 (Exim 4.92) (envelope-from ) id 1u6GZ7-0006q6-JR; Sat, 19 Apr 2025 22:21:37 +0000 Received: by outflank-mailman (output) from mailman id 960275.1352389; Sat, 19 Apr 2025 22:21:37 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u6GZ7-0006nr-9o; Sat, 19 Apr 2025 22:21:37 +0000 Received: by outflank-mailman (input) for mailman id 960275; Sat, 19 Apr 2025 22:21:35 +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 1u6GP9-0004yY-WA for xen-devel@lists.xenproject.org; Sat, 19 Apr 2025 22:11:20 +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 377390f8-1d6b-11f0-9eb0-5ba50f476ded; Sun, 20 Apr 2025 00:11:19 +0200 (CEST) Received: by mx.zohomail.com with SMTPS id 1745100534648793.2115318942064; Sat, 19 Apr 2025 15:08:54 -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: 377390f8-1d6b-11f0-9eb0-5ba50f476ded ARC-Seal: i=1; a=rsa-sha256; t=1745100540; cv=none; d=zohomail.com; s=zohoarc; b=EPa67t7mNi7fF2zt10Ul0B2UoAt8xxdRmVRzHl1ZUlfgt4lyO59jE+L/h3OSf/z7YD8SAo3lOkLi45aH6xgVyBUiqhqEGPu5Ko7h+Hi5Xi4pSIIjFohj1bKdi14JEMRrUEPvETir9cExUs+fRRfe5/ZfFUzfIHnvQTyrKnGHAeg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100540; 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=2mkjxzW5Ru2Q92RR48HdEoTcd4H0/JB/kPW2NI5sInE=; b=J4tji14XEmKCceQDiriM56toiiaDpVIvUKZVULx5y7PDUeCabDOKaYOuo/d+VaJkcBKlKFeeL4YdVsM4J0nvWrp96jPHhVip1Pcanqa1A37flOxJzAQDU+NJMvOQcCI2h5TFm+DML2d2mmdcInr/DoVzfAAWTVhe6dQrOSV3r8w= 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=1745100540; 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=2mkjxzW5Ru2Q92RR48HdEoTcd4H0/JB/kPW2NI5sInE=; b=HJYDam8Try/ibd4JiDWljMjg/93cJUlaibk/F0Var7goINrYqEl/8M5SqBdTwhVB bv67aafshWF2D5reTbey8gETBoYDkJrs5WBodfVcxllArgjXgJD0cwka8mp6LuMTW52 6SJEmmG0jHkfWRRADTbbyq9bSfu/xAgQsGrlF0zc= 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 18/38] x86/boot: rename pvh acpi setup function Date: Sat, 19 Apr 2025 18:08:00 -0400 Message-Id: <20250419220820.4234-19-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: 1745101317612019100 Content-Type: text/plain; charset="utf-8" The function pvh_setup_acpi() is dom0 specific, renaming it to dom0_pvh_setup_acpi(). Now export the function so that it may be called by = the domain builder. Signed-off-by: Daniel P. Smith --- xen/arch/x86/hvm/dom0_build.c | 4 ++-- xen/arch/x86/include/asm/dom0_build.h | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/hvm/dom0_build.c b/xen/arch/x86/hvm/dom0_build.c index a3b6afc5318a..8ea4c7bd2792 100644 --- a/xen/arch/x86/hvm/dom0_build.c +++ b/xen/arch/x86/hvm/dom0_build.c @@ -1125,7 +1125,7 @@ static int __init pvh_setup_acpi_xsdt(struct domain *= d, paddr_t madt_addr, return rc; } =20 -static int __init pvh_setup_acpi(struct domain *d, paddr_t start_info) +int __init dom0_pvh_setup_acpi(struct domain *d, paddr_t start_info) { unsigned long pfn, nr_pages; paddr_t madt_paddr, xsdt_paddr, rsdp_paddr; @@ -1283,7 +1283,7 @@ int __init dom0_construct_pvh(struct boot_domain *bd) return rc; } =20 - rc =3D pvh_setup_acpi(d, start_info); + rc =3D dom0_pvh_setup_acpi(bd->d, start_info); if ( rc ) { printk("Failed to setup Dom0 ACPI tables: %d\n", rc); diff --git a/xen/arch/x86/include/asm/dom0_build.h b/xen/arch/x86/include/a= sm/dom0_build.h index e5debd5adf9f..36f563bd9d5b 100644 --- a/xen/arch/x86/include/asm/dom0_build.h +++ b/xen/arch/x86/include/asm/dom0_build.h @@ -20,6 +20,8 @@ void dom0_pv_restrict_pages( =20 void dom0_pvh_setup_e820(struct domain *d, unsigned long nr_pages); =20 +int dom0_pvh_setup_acpi(struct domain *d, paddr_t start_info); + int dom0_construct_pv(struct boot_domain *bd); int dom0_construct_pvh(struct boot_domain *bd); =20 --=20 2.30.2 From nobody Fri Oct 31 16:34:17 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=1745101302; cv=pass; d=zohomail.com; s=zohoarc; b=BgPAngQxpcyI8SSu44gDjLRpiDng6UZjIemgfl8NxcwDIZbc7+OVR6Il+uivWr8nNn4JloM04l3fFypGD7GU0WnDPSnauhZy8cSWRfqCBY81eFB1is18Ppw1a5qb4sN96Z18NtJOzGCNsEZlJVQbgezimcRwZXyZJLYTxAGm6Cc= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745101302; 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=2DObGwETdwh7JUH3NaImfvU+NN7DFUDrg2HJnLwWc6A=; b=HwydyggISvqwY0n3qT3mCoQIKnz2Q8cEAOHeK+QS4nyMwXExoy6VdouxQTHzEjSoJRhy+ScO4pTcCIdMrbETJtnnvSDS8aiwmdOkYlabEeE3fwNpMZTqJptWcKW3TTUEK7ZXahrGiC/JHE5wy5FbFW7Rf1Irwc5sfmg/wvZL3EU= 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 1745101302632737.7105307086844; Sat, 19 Apr 2025 15:21:42 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.960257.1352355 (Exim 4.92) (envelope-from ) id 1u6GYw-0004v1-Tm; Sat, 19 Apr 2025 22:21:26 +0000 Received: by outflank-mailman (output) from mailman id 960257.1352355; Sat, 19 Apr 2025 22:21:26 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u6GYw-0004tw-Ib; Sat, 19 Apr 2025 22:21:26 +0000 Received: by outflank-mailman (input) for mailman id 960257; Sat, 19 Apr 2025 22:21:25 +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 1u6GP5-0004yY-0x for xen-devel@lists.xenproject.org; Sat, 19 Apr 2025 22:11:15 +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 3368e8e3-1d6b-11f0-9eb0-5ba50f476ded; Sun, 20 Apr 2025 00:11:12 +0200 (CEST) Received: by mx.zohomail.com with SMTPS id 1745100535464486.0908090025065; Sat, 19 Apr 2025 15:08:55 -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: 3368e8e3-1d6b-11f0-9eb0-5ba50f476ded ARC-Seal: i=1; a=rsa-sha256; t=1745100540; cv=none; d=zohomail.com; s=zohoarc; b=bCgIUk8XLrSRb2+emrpZXS/xMRZZzP/JIQEx1NDclO9uqk/xo1tzfOwUe5TWhyTHKmAUnTQxyNgwAnCptS/HRCwT6CVUODWnuJa8pIhv+1dRMx1Kd0N7jYeueGQWPMhOQHX/peSUAytuXsMQnIYK9ksVQxWCrW4G6nfgKuj+gwY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100540; 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=2DObGwETdwh7JUH3NaImfvU+NN7DFUDrg2HJnLwWc6A=; b=HAgOY8rb0aTpjt9jpcc8JTsXxQdP/tXtGgTf14h4A35Y1BD6tm0EP1lKs24DCbLIqL332Iazdt7b8V3ylm/MnhPfLg+1QK7kjNspHIISCIIzllaKSIIdY8aPcIxmRrJZc0B1FqBf7DQdyjmrOTmDPDiKWiD5Iby6gtbS0scO/KQ= 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=1745100540; 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=2DObGwETdwh7JUH3NaImfvU+NN7DFUDrg2HJnLwWc6A=; b=j+nMrzDa8bS4dUdaFEuJ1m3fb5Ec2PI3xjnWjgqj98wZLn3l4uteUQanGDU1VSIM yvc6mqxYUxvOnpR+C3bad+Yh+Ut+XDE/AwFJUAY/2e7LPGY8ZsysxbKSsEnYrhPxu8C VCOHJC9PwyhX7FPPzoJNSlk4Reu9Cs88hBOyrqEo= 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 19/38] x86/hyperlaunch: add domu memory map construction Date: Sat, 19 Apr 2025 18:08:01 -0400 Message-Id: <20250419220820.4234-20-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: 1745101305485019100 Content-Type: text/plain; charset="utf-8" Introduce hvm_setup_e820() that will build the e820 memory map for a general domU. To populate the ACPI entry, ACPI table size helpers are introduced. A conditional is added to the domain builder to select between calling hvm_setup_e820() and dom0_pvh_setup_e820() depending on if it is building d= om0 or a domU. Signed-off-by: Daniel P. Smith --- xen/arch/x86/hvm/dom_build.c | 149 ++++++++++++++++++++++++++++++++++- 1 file changed, 148 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/hvm/dom_build.c b/xen/arch/x86/hvm/dom_build.c index 078e42447b0a..658d3d170e64 100644 --- a/xen/arch/x86/hvm/dom_build.c +++ b/xen/arch/x86/hvm/dom_build.c @@ -16,6 +16,7 @@ =20 #include =20 +#include #include =20 #include @@ -43,12 +44,158 @@ static void __hwdom_init pvh_setup_mmcfg(struct domain= *d) } } =20 +static unsigned long __init hvm_size_acpi_madt(struct domain *d) +{ + unsigned long size =3D sizeof(struct acpi_table_madt); + + size +=3D sizeof(struct acpi_madt_local_apic) * d->max_vcpus; + + return size; +} + +static unsigned long __init hvm_size_acpi_xsdt(struct domain *d) +{ + unsigned long size =3D sizeof(struct acpi_table_xsdt); + /* Only adding the MADT table to the XSDT. */ + unsigned int num_tables =3D 1; + + /* + * No need to add or subtract anything because struct acpi_table_xsdt + * includes one array slot already. + */ + size +=3D num_tables * sizeof(uint64_t); + + return size; +} + +static unsigned long __init hvm_size_acpi_region(struct domain *d) +{ + unsigned long size =3D sizeof(struct acpi_table_rsdp); + + size +=3D hvm_size_acpi_xsdt(d); + size +=3D hvm_size_acpi_madt(d); + + return ROUNDUP(size, PAGE_SIZE); +} + +/* From xenguest lib */ +#define END_SPECIAL_REGION 0xff000U +#define NR_SPECIAL_PAGES 8 +#define START_SPECIAL_REGION (END_SPECIAL_REGION - NR_SPECIAL_PAGES) + +#define SPECIALPAGE_PAGING 0 +#define SPECIALPAGE_ACCESS 1 +#define SPECIALPAGE_SHARING 2 +#define SPECIALPAGE_BUFIOREQ 3 +#define SPECIALPAGE_XENSTORE 4 +#define SPECIALPAGE_IOREQ 5 +#define SPECIALPAGE_IDENT_PT 6 +#define SPECIALPAGE_CONSOLE 7 +#define special_pfn(x) (START_SPECIAL_REGION + (x)) + +/* + * Allocation scheme, derived from xenlight/xenguest: + * + * | <4G MMIO Hole | + * [ Low Mem ][ RDM Mem ][ >1M Mem ][ ACPI ][ Special ][ High Mem ] + * + */ +static void __init hvm_setup_e820(struct domain *d, unsigned long nr_pages) +{ + const uint32_t lowmem_reserved_base =3D 0x9e000; + const uint32_t rdm_base =3D 0xa0000, rdm_size =3D 0x60; + unsigned long low_pages, ext_pages, mmio_pages, acpi_pages, high_pages= =3D 0; + unsigned long max_ext_pages =3D (HVM_BELOW_4G_MMIO_START - MB(1)) >> P= AGE_SHIFT, + page_count =3D 0; + unsigned nr =3D 0, e820_entries =3D 5; + + /* low pages: below 1MB */ + low_pages =3D lowmem_reserved_base >> PAGE_SHIFT; + if ( low_pages > nr_pages ) + panic("Insufficient memory for HVM/PVH domain (%pd)\n", d); + + acpi_pages =3D hvm_size_acpi_region(d) >> PAGE_SHIFT; + mmio_pages =3D acpi_pages + NR_SPECIAL_PAGES; + + /* ext pages: from 1MB to mmio hole */ + ext_pages =3D nr_pages - (low_pages + mmio_pages); + if ( ext_pages > max_ext_pages ) + ext_pages =3D max_ext_pages; + + /* high pages: above 4GB */ + if ( nr_pages > (low_pages + mmio_pages + ext_pages) ) + high_pages =3D nr_pages - (low_pages + mmio_pages + ext_pages); + + /* If we should have a highmem range, add one more e820 entry */ + if ( high_pages ) + e820_entries++; + + ASSERT(e820_entries < E820MAX); + + d->arch.e820 =3D xzalloc_array(struct e820entry, e820_entries); + if ( !d->arch.e820 ) + panic("Unable to allocate memory for boot domain e820 map\n"); + + /* usable: Low memory */ + d->arch.e820[nr].addr =3D 0x000000; + d->arch.e820[nr].size =3D low_pages << PAGE_SHIFT; + d->arch.e820[nr].type =3D E820_RAM; + page_count +=3D d->arch.e820[nr].size >> PAGE_SHIFT; + nr++; + + /* reserved: lowmem reserved device memory */ + d->arch.e820[nr].addr =3D rdm_base; + d->arch.e820[nr].size =3D rdm_size; + d->arch.e820[nr].type =3D E820_RESERVED; + nr++; + + /* usable: extended memory from 1MB */ + d->arch.e820[nr].addr =3D 0x100000; + d->arch.e820[nr].size =3D ext_pages << PAGE_SHIFT; + d->arch.e820[nr].type =3D E820_RAM; + page_count +=3D d->arch.e820[nr].size >> PAGE_SHIFT; + nr++; + + /* reserved: ACPI entry, ACPI_INFO_PHYSICAL_ADDRESS */ + d->arch.e820[nr].addr =3D 0xFC000000; + d->arch.e820[nr].size =3D acpi_pages << PAGE_SHIFT; + d->arch.e820[nr].type =3D E820_ACPI; + page_count +=3D d->arch.e820[nr].size >> PAGE_SHIFT; + nr++; + + /* reserved: HVM special pages, X86_HVM_END_SPECIAL_REGION */ + d->arch.e820[nr].addr =3D START_SPECIAL_REGION << PAGE_SHIFT; + d->arch.e820[nr].size =3D NR_SPECIAL_PAGES << PAGE_SHIFT; + d->arch.e820[nr].type =3D E820_RESERVED; + page_count +=3D d->arch.e820[nr].size >> PAGE_SHIFT; + nr++; + + /* usable: highmem */ + if ( high_pages ) + { + d->arch.e820[nr].addr =3D 0x100000000; + d->arch.e820[nr].size =3D high_pages << PAGE_SHIFT; + d->arch.e820[nr].type =3D E820_RAM; + page_count +=3D d->arch.e820[nr].size >> PAGE_SHIFT; + nr++; + } + + d->arch.nr_e820 =3D nr; + + ASSERT(nr =3D=3D e820_entries); + ASSERT(nr_pages =3D=3D page_count); +} + static void __init pvh_init_p2m(struct boot_domain *bd) { unsigned long nr_pages =3D dom_compute_nr_pages(bd, NULL); bool preempted; =20 - dom0_pvh_setup_e820(bd->d, nr_pages); + if ( bd->capabilities & (BUILD_CAPS_CONTROL | BUILD_CAPS_HARDWARE) ) + dom0_pvh_setup_e820(bd->d, nr_pages); + else + hvm_setup_e820(bd->d, nr_pages); + do { preempted =3D false; paging_set_allocation(bd->d, dom_paging_pages(bd, nr_pages), --=20 2.30.2 From nobody Fri Oct 31 16:34:17 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=1745101298; cv=pass; d=zohomail.com; s=zohoarc; b=WFpqYNstMYw6DbZ8zm6RZy1FXqnaBIL85dPh+QQ1gJyZ7LcP4kCHFzoOhLwCvXUFsF4CGEX149SwhnfgwOZd+7iw8i+4poOVOkMdx6EpHGj8GHT90QfFXEflwLsvLSMv3ImlvchWdx6aiwFhmszYtbVxCUlWzwObDMoS2EhrC3Q= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745101298; 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=2KWTr4dpH7kEQOohwPUOqAsWDUBqr7T/oi51YKgyffE=; b=biUKqM7Nrqg/X3cRE+QOO9g54WOBuGqCroYuyucRM+/kiii+pnYLRI6SKUy1ffFOTbAPLPuAUu3V8bpjLpZy1EQYaNCCWyelH30WvZom6j8tU8ZeojFXil2w54Qe4+IQYfsA0exK2z7bqHkxZeSbqVhA4lVgSnnrQkHgdXtYlf4= 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 1745101298218793.6143505969593; Sat, 19 Apr 2025 15:21:38 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.960253.1352337 (Exim 4.92) (envelope-from ) id 1u6GYv-0004Tz-3y; Sat, 19 Apr 2025 22:21:25 +0000 Received: by outflank-mailman (output) from mailman id 960253.1352337; Sat, 19 Apr 2025 22:21:25 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u6GYu-0004TG-RH; Sat, 19 Apr 2025 22:21:24 +0000 Received: by outflank-mailman (input) for mailman id 960253; Sat, 19 Apr 2025 22:21:24 +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 1u6GPo-0004yY-Qt for xen-devel@lists.xenproject.org; Sat, 19 Apr 2025 22:12:00 +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 4fbae569-1d6b-11f0-9eb0-5ba50f476ded; Sun, 20 Apr 2025 00:11:59 +0200 (CEST) Received: by mx.zohomail.com with SMTPS id 1745100546108391.4594608164257; Sat, 19 Apr 2025 15:09:06 -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: 4fbae569-1d6b-11f0-9eb0-5ba50f476ded ARC-Seal: i=1; a=rsa-sha256; t=1745100552; cv=none; d=zohomail.com; s=zohoarc; b=kAFDjP5hC/DHyg5mi6B3pHJBMWipG3yLUNWg01uonydE8pTfNXXDcdtzsjd7XgIvtqBWlumi3KZ4KldEuVank4Zf1x3WEcRQ+ZUFYVBV0DPYpUZgP50P+XKJkRRLktcqHe00QGlc8gdd5Zz5sBrMVmC6cYAjnZzAV6lB/zZRNq0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100552; 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=2KWTr4dpH7kEQOohwPUOqAsWDUBqr7T/oi51YKgyffE=; b=FoRsKBowGPNcX9U26cYDOaPk1heW/XtkCmr5Nn54gMoJkfPALQ2aIu9qCH9hA5tJle8RYGw/2hTuQQJ6YhUi02FeKj8xrENcDS3dgIozCRwrW2O3GStzz7vmsgk4g5Ie9NgPB546PRG5EVOo9plLpO2y0BePs9rrjupmE+Bx6rg= 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=1745100552; 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=2KWTr4dpH7kEQOohwPUOqAsWDUBqr7T/oi51YKgyffE=; b=KBYjqrE3I3JYg6L8aOmLkCsdtPMnvPTK4wDq2Ffu9BKz13Su1VI6XrULRGip/CFi FVxTm8YhlmRD2OONDaBReMycZUdNkYudxCy9RN47JhqcjWAywO1GaNjdr9qAihp42d6 77/uzzeaJuTBxAryeHfDZiDHLR9beggrEY+LxikI= 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 20/38] x86/hyperlaunch: move populating p2m under domain builder Date: Sat, 19 Apr 2025 18:08:02 -0400 Message-Id: <20250419220820.4234-21-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: 1745101299169019000 Content-Type: text/plain; charset="utf-8" Introduce hvm_populate_p2m() for populating domU p2m maps. Rename pvh_populate_p2m() to dom0_pvh_populate_p2m() and export it. With these adjustments, move the calls to populate the p2m maps under domain builder. Signed-off-by: Daniel P. Smith --- xen/arch/x86/hvm/dom0_build.c | 14 ++------ xen/arch/x86/hvm/dom_build.c | 39 +++++++++++++++++++++++ xen/arch/x86/include/asm/dom0_build.h | 1 + xen/arch/x86/include/asm/domain-builder.h | 2 ++ 4 files changed, 45 insertions(+), 11 deletions(-) diff --git a/xen/arch/x86/hvm/dom0_build.c b/xen/arch/x86/hvm/dom0_build.c index 8ea4c7bd2792..73ce33fb17f1 100644 --- a/xen/arch/x86/hvm/dom0_build.c +++ b/xen/arch/x86/hvm/dom0_build.c @@ -88,9 +88,8 @@ static int __init modify_identity_mmio(struct domain *d, = unsigned long pfn, } =20 /* Populate a HVM memory range using the biggest possible order. */ -static int __init pvh_populate_memory_range(struct domain *d, - unsigned long start, - unsigned long nr_pages) +int __init pvh_populate_memory_range( + struct domain *d, unsigned long start, unsigned long nr_pages) { static const struct { unsigned long align; @@ -399,7 +398,7 @@ void __init dom0_pvh_setup_e820(struct domain *d, unsig= ned long nr_pages) ASSERT(cur_pages =3D=3D nr_pages); } =20 -static int __init pvh_populate_p2m(struct domain *d) +int __init dom0_pvh_populate_p2m(struct domain *d) { struct vcpu *v =3D d->vcpu[0]; unsigned int i; @@ -1262,13 +1261,6 @@ int __init dom0_construct_pvh(struct boot_domain *bd) struct domain *d =3D bd->d; int rc; =20 - rc =3D pvh_populate_p2m(d); - if ( rc ) - { - printk("Failed to setup Dom0 physical memory map\n"); - return rc; - } - rc =3D pvh_load_kernel(bd, &entry, &start_info); if ( rc ) { diff --git a/xen/arch/x86/hvm/dom_build.c b/xen/arch/x86/hvm/dom_build.c index 658d3d170e64..9421dc431ba9 100644 --- a/xen/arch/x86/hvm/dom_build.c +++ b/xen/arch/x86/hvm/dom_build.c @@ -23,6 +23,8 @@ #include #include #include +#include +#include #include #include =20 @@ -247,6 +249,33 @@ int __init hvm_setup_cpus( return 0; } =20 +static int __init hvm_populate_p2m(struct domain *d) +{ + unsigned int i; + + /* Populate memory map. */ + for ( i =3D 0; i < d->arch.nr_e820; i++ ) + { + int rc; + unsigned long addr, size; + + if ( d->arch.e820[i].type !=3D E820_RAM && + d->arch.e820[i].type !=3D E820_ACPI && + PFN_DOWN(d->arch.e820[i].addr) !=3D START_SPECIAL_REGION ) + continue; + + addr =3D PFN_DOWN(d->arch.e820[i].addr); + size =3D PFN_DOWN(d->arch.e820[i].size); + + rc =3D pvh_populate_memory_range(d, addr, size); + if ( rc ) + return rc; + + } + + return 0; +} + int __init dom_construct_pvh(struct boot_domain *bd) { int rc; @@ -288,6 +317,16 @@ int __init dom_construct_pvh(struct boot_domain *bd) if ( is_hardware_domain(bd->d) ) iommu_hwdom_init(bd->d); =20 + if ( is_control_domain(bd->d) || is_hardware_domain(bd->d) ) + rc =3D dom0_pvh_populate_p2m(bd->d); + else + rc =3D hvm_populate_p2m(bd->d); + if ( rc ) + { + printk("Failed to setup HVM/PVH %pd physical memory map\n", bd->d); + return rc; + } + return dom0_construct_pvh(bd); } =20 diff --git a/xen/arch/x86/include/asm/dom0_build.h b/xen/arch/x86/include/a= sm/dom0_build.h index 36f563bd9d5b..3819b3f4e7a4 100644 --- a/xen/arch/x86/include/asm/dom0_build.h +++ b/xen/arch/x86/include/asm/dom0_build.h @@ -21,6 +21,7 @@ void dom0_pv_restrict_pages( void dom0_pvh_setup_e820(struct domain *d, unsigned long nr_pages); =20 int dom0_pvh_setup_acpi(struct domain *d, paddr_t start_info); +int dom0_pvh_populate_p2m(struct domain *d); =20 int dom0_construct_pv(struct boot_domain *bd); int dom0_construct_pvh(struct boot_domain *bd); diff --git a/xen/arch/x86/include/asm/domain-builder.h b/xen/arch/x86/inclu= de/asm/domain-builder.h index 7bc2fbe66bc2..fa6fa60841ab 100644 --- a/xen/arch/x86/include/asm/domain-builder.h +++ b/xen/arch/x86/include/asm/domain-builder.h @@ -10,6 +10,8 @@ int __init builder_get_cmdline( void builder_init(struct boot_info *bi); =20 int hvm_setup_cpus(struct domain *d, paddr_t entry, paddr_t start_info); +int pvh_populate_memory_range( + struct domain *d, unsigned long start, unsigned long nr_pages); =20 unsigned long dom_paging_pages( const struct boot_domain *d, unsigned long nr_pages); --=20 2.30.2 From nobody Fri Oct 31 16:34:17 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=1745101293; cv=pass; d=zohomail.com; s=zohoarc; b=Z06hrrcZd4qZKpmqDnaqckuk8iAcerDnzRnRlbaV2lNBv7N0VhCF6d4UuRly6VABz1h8v5A4iivCsbRLyhUdmxOXAFC2TVPrELBQxHNwRXJM9IzEdhzYuKzzRCEr8CgFLC/I68ww1ntKvRHl493TGwozMfJwijGmJHdbYiGJSJ8= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745101293; 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=xoJWXkXpmA/7bILpNXgjvSfpxAXFPtgVddP2jhGbb9Y=; b=Y7WRIkS4I5hPUJYwDAUP3/1+tV5fT5qJVho5mB2Qpjph3AAF5Al7BhvwmNWqfAdvOip8EyKoVVqRbXUPUOoMC9XVyLWUu137cbftWmBmOvPQRJPEc6m4XT4nlhIxawlTzqvrhN579Szr0FSM7LuRxIdZVVOCo6eroVoD1EU0zTc= 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 1745101293087402.84517952236; Sat, 19 Apr 2025 15:21:33 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.960235.1352308 (Exim 4.92) (envelope-from ) id 1u6GYo-0003JX-MG; Sat, 19 Apr 2025 22:21:18 +0000 Received: by outflank-mailman (output) from mailman id 960235.1352308; Sat, 19 Apr 2025 22:21:18 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u6GYo-0003Im-CJ; Sat, 19 Apr 2025 22:21:18 +0000 Received: by outflank-mailman (input) for mailman id 960235; Sat, 19 Apr 2025 22:21:17 +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 1u6GP0-0004yY-0f for xen-devel@lists.xenproject.org; Sat, 19 Apr 2025 22:11:10 +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 2ef04524-1d6b-11f0-9eb0-5ba50f476ded; Sun, 20 Apr 2025 00:11:04 +0200 (CEST) Received: by mx.zohomail.com with SMTPS id 1745100546983292.67406814920184; Sat, 19 Apr 2025 15:09:06 -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: 2ef04524-1d6b-11f0-9eb0-5ba50f476ded ARC-Seal: i=1; a=rsa-sha256; t=1745100550; cv=none; d=zohomail.com; s=zohoarc; b=Vx7LmSizaQI8aTsjW/xcqDxUX7t05aGQcRdNG12cItMoDos1g/aYT/dOSgq9wRpLPDzmQ+D9FDOWyQVJhZQrg9IqxuVyMrMiXpDhsP/ztvwf/27PJqc9kvnEujsff4uM0Aa6wtbDzncEi+jsv7KX3psTUmhy7M2+qKIjoQGrnro= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100550; 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=xoJWXkXpmA/7bILpNXgjvSfpxAXFPtgVddP2jhGbb9Y=; b=FM1a+nuOcoazbxGLbwEZv/wYDNIuVSPWlh0FAYGBpKftZO8mKeHaFrGan65R4Ma49VKjlicWcIpKovrTUqTwj/tVVwqx15xN8Ctuv6gUIij7SJ65JNMSCMhsH/npm/2DONYuH0B+7BBzwoffttGCZtNjM2HkD1yekeV56v18RZw= 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=1745100550; 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=xoJWXkXpmA/7bILpNXgjvSfpxAXFPtgVddP2jhGbb9Y=; b=lOLk6IS7DcWYwCkOVdF1iFNpeszEdsGVHzIftxCSUCBmGBkVu57dQmH9Nt6Z2CcP 8quJhnNdzC8tcJTYYUI80bMdXRjVhVOFsqo8dqmll/LGyA5pTplbNVgt+zCMsihDiUW GXaa0EnrtOLcqe1HpMJDw7L1+ftLJdW8TGHq3cD4= 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 21/38] x86/hyperlaunch: move remaining pvh dom0 construction Date: Sat, 19 Apr 2025 18:08:03 -0400 Message-Id: <20250419220820.4234-22-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: 1745101295218019000 Content-Type: text/plain; charset="utf-8" Move pvh_load_kernel() and its helper functions to the domain builder. With this move, it is now possible to move the remaining logic of dom0_construct_pvh() to the domain builder. With all the logic moved, the function can be dropped. Signed-off-by: Daniel P. Smith --- xen/arch/x86/hvm/dom0_build.c | 365 -------------------------- xen/arch/x86/hvm/dom_build.c | 362 ++++++++++++++++++++++++- xen/arch/x86/include/asm/dom0_build.h | 1 - 3 files changed, 361 insertions(+), 367 deletions(-) diff --git a/xen/arch/x86/hvm/dom0_build.c b/xen/arch/x86/hvm/dom0_build.c index 73ce33fb17f1..23b46ef86c9f 100644 --- a/xen/arch/x86/hvm/dom0_build.c +++ b/xen/arch/x86/hvm/dom0_build.c @@ -478,335 +478,6 @@ int __init dom0_pvh_populate_p2m(struct domain *d) #undef MB1_PAGES } =20 -static paddr_t __init find_memory( - const struct domain *d, const struct elf_binary *elf, size_t size) -{ - paddr_t kernel_start =3D (paddr_t)elf->dest_base & PAGE_MASK; - paddr_t kernel_end =3D ROUNDUP((paddr_t)elf->dest_base + elf->dest_siz= e, - PAGE_SIZE); - unsigned int i; - - /* - * The memory map is sorted and all RAM regions starts and sizes are - * aligned to page boundaries. - */ - for ( i =3D 0; i < d->arch.nr_e820; i++ ) - { - paddr_t start, end =3D d->arch.e820[i].addr + d->arch.e820[i].size; - - /* Don't use memory below 1MB, as it could overwrite BDA/EBDA/IBFT= . */ - if ( end <=3D MB(1) || d->arch.e820[i].type !=3D E820_RAM ) - continue; - - start =3D MAX(ROUNDUP(d->arch.e820[i].addr, PAGE_SIZE), MB(1)); - - ASSERT(IS_ALIGNED(start, PAGE_SIZE) && IS_ALIGNED(end, PAGE_SIZE)); - - /* - * NB: Even better would be to use rangesets to determine a suitab= le - * range, in particular in case a kernel requests multiple heavily - * discontiguous regions (which right now we fold all into one big - * region). - */ - if ( end <=3D kernel_start || start >=3D kernel_end ) - { - /* No overlap, just check whether the region is large enough. = */ - if ( end - start >=3D size ) - return start; - } - /* Deal with the kernel already being loaded in the region. */ - else if ( kernel_start > start && kernel_start - start >=3D size ) - return start; - else if ( kernel_end < end && end - kernel_end >=3D size ) - return kernel_end; - } - - return INVALID_PADDR; -} - -static bool __init check_load_address( - const struct domain *d, const struct elf_binary *elf) -{ - paddr_t kernel_start =3D (uintptr_t)elf->dest_base; - paddr_t kernel_end =3D kernel_start + elf->dest_size; - unsigned int i; - - /* Relies on a sorted memory map with adjacent entries merged. */ - for ( i =3D 0; i < d->arch.nr_e820; i++ ) - { - paddr_t start =3D d->arch.e820[i].addr; - paddr_t end =3D start + d->arch.e820[i].size; - - if ( start >=3D kernel_end ) - return false; - - if ( d->arch.e820[i].type =3D=3D E820_RAM && - start <=3D kernel_start && - end >=3D kernel_end ) - return true; - } - - return false; -} - -/* Find an e820 RAM region that fits the kernel at a suitable alignment. */ -static paddr_t __init find_kernel_memory( - const struct domain *d, struct elf_binary *elf, - const struct elf_dom_parms *parms) -{ - paddr_t kernel_size =3D elf->dest_size; - unsigned int align; - unsigned int i; - - if ( parms->phys_align !=3D UNSET_ADDR32 ) - align =3D parms->phys_align; - else if ( elf->palign >=3D PAGE_SIZE ) - align =3D elf->palign; - else - align =3D MB(2); - - /* Search backwards to find the highest address. */ - for ( i =3D d->arch.nr_e820; i--; ) - { - paddr_t start =3D d->arch.e820[i].addr; - paddr_t end =3D start + d->arch.e820[i].size; - paddr_t kstart, kend; - - if ( d->arch.e820[i].type !=3D E820_RAM || - d->arch.e820[i].size < kernel_size ) - continue; - - if ( start > parms->phys_max ) - continue; - - if ( end - 1 > parms->phys_max ) - end =3D parms->phys_max + 1; - - kstart =3D (end - kernel_size) & ~(align - 1); - kend =3D kstart + kernel_size; - - if ( kstart < parms->phys_min ) - return 0; - - if ( kstart >=3D start && kend <=3D end ) - return kstart; - } - - return 0; -} - -/* Check the kernel load address, and adjust if necessary and possible. */ -static bool __init check_and_adjust_load_address( - const struct domain *d, struct elf_binary *elf, struct elf_dom_parms *= parms) -{ - paddr_t reloc_base; - - if ( check_load_address(d, elf) ) - return true; - - if ( !parms->phys_reloc ) - { - printk("%pd kernel: Address conflict and not relocatable\n", d); - return false; - } - - reloc_base =3D find_kernel_memory(d, elf, parms); - if ( !reloc_base ) - { - printk("%pd kernel: Failed find a load address\n", d); - return false; - } - - if ( opt_dom0_verbose ) - printk("%pd kernel: Moving [%p, %p] -> [%"PRIpaddr", %"PRIpaddr"]\= n", d, - elf->dest_base, elf->dest_base + elf->dest_size - 1, - reloc_base, reloc_base + elf->dest_size - 1); - - parms->phys_entry =3D - reloc_base + (parms->phys_entry - (uintptr_t)elf->dest_base); - elf->dest_base =3D (char *)reloc_base; - - return true; -} - -static int __init pvh_load_kernel( - const struct boot_domain *bd, paddr_t *entry, paddr_t *start_info_addr) -{ - struct domain *d =3D bd->d; - struct boot_module *image =3D bd->kernel; - struct boot_module *initrd =3D bd->ramdisk; - void *image_base =3D bootstrap_map_bm(image); - void *image_start =3D image_base + image->headroom; - unsigned long image_len =3D image->size; - unsigned long initrd_len =3D initrd ? initrd->size : 0; - const char *initrd_cmdline =3D NULL; - struct elf_binary elf; - struct elf_dom_parms parms; - size_t extra_space; - paddr_t last_addr; - struct hvm_start_info start_info =3D { 0 }; - struct hvm_modlist_entry mod =3D { 0 }; - struct vcpu *v =3D d->vcpu[0]; - int rc; - - if ( (rc =3D bzimage_parse(image_base, &image_start, &image_len)) !=3D= 0 ) - { - printk("Error trying to detect bz compressed kernel\n"); - return rc; - } - - if ( (rc =3D elf_init(&elf, image_start, image_len)) !=3D 0 ) - { - printk("Unable to init ELF\n"); - return rc; - } - if ( opt_dom0_verbose ) - elf_set_verbose(&elf); - elf_parse_binary(&elf); - if ( (rc =3D elf_xen_parse(&elf, &parms, true)) !=3D 0 ) - { - printk("Unable to parse kernel for ELFNOTES\n"); - if ( elf_check_broken(&elf) ) - printk("%pd kernel: broken ELF: %s\n", d, elf_check_broken(&el= f)); - return rc; - } - - if ( parms.phys_entry =3D=3D UNSET_ADDR32 ) - { - printk("Unable to find XEN_ELFNOTE_PHYS32_ENTRY address\n"); - return -EINVAL; - } - - /* Copy the OS image and free temporary buffer. */ - elf.dest_base =3D (void *)(parms.virt_kstart - parms.virt_base); - elf.dest_size =3D parms.virt_kend - parms.virt_kstart; - - if ( !check_and_adjust_load_address(d, &elf, &parms) ) - return -ENOSPC; - - elf_set_vcpu(&elf, v); - rc =3D elf_load_binary(&elf); - if ( rc < 0 ) - { - printk("Failed to load kernel: %d\n", rc); - if ( elf_check_broken(&elf) ) - printk("%pd kernel: broken ELF: %s\n", d, elf_check_broken(&el= f)); - return rc; - } - - /* - * Find a RAM region big enough (and that doesn't overlap with the loa= ded - * kernel) in order to load the initrd and the metadata. Note it could= be - * split into smaller allocations, done as a single region in order to - * simplify it. - */ - extra_space =3D sizeof(start_info); - - if ( initrd ) - { - size_t initrd_space =3D elf_round_up(&elf, initrd_len); - - if ( initrd->cmdline_pa ) - { - initrd_cmdline =3D __va(initrd->cmdline_pa); - if ( !*initrd_cmdline ) - initrd_cmdline =3D NULL; - } - if ( initrd_cmdline ) - initrd_space +=3D strlen(initrd_cmdline) + 1; - - if ( initrd_space ) - extra_space +=3D ROUNDUP(initrd_space, PAGE_SIZE) + sizeof(mod= ); - else - initrd =3D NULL; - } - - if ( bd->cmdline ) - extra_space +=3D elf_round_up(&elf, strlen(bd->cmdline) + 1); - - last_addr =3D find_memory(d, &elf, extra_space); - if ( last_addr =3D=3D INVALID_PADDR ) - { - printk("Unable to find a memory region to load initrd and metadata= \n"); - return -ENOMEM; - } - - if ( initrd !=3D NULL ) - { - rc =3D hvm_copy_to_guest_phys(last_addr, __va(initrd->start), - initrd_len, v); - if ( rc ) - { - printk("Unable to copy initrd to guest\n"); - return rc; - } - - mod.paddr =3D last_addr; - mod.size =3D initrd_len; - last_addr +=3D elf_round_up(&elf, initrd_len); - if ( initrd_cmdline ) - { - size_t len =3D strlen(initrd_cmdline) + 1; - - rc =3D hvm_copy_to_guest_phys(last_addr, initrd_cmdline, len, = v); - if ( rc ) - { - printk("Unable to copy module command line\n"); - return rc; - } - mod.cmdline_paddr =3D last_addr; - last_addr +=3D len; - } - last_addr =3D ROUNDUP(last_addr, PAGE_SIZE); - } - - /* Free temporary buffers. */ - free_boot_modules(); - - if ( bd->cmdline ) - { - rc =3D hvm_copy_to_guest_phys(last_addr, bd->cmdline, - strlen(bd->cmdline) + 1, v); - if ( rc ) - { - printk("Unable to copy guest command line\n"); - return rc; - } - start_info.cmdline_paddr =3D last_addr; - /* - * Round up to 32/64 bits (depending on the guest kernel bitness) = so - * the modlist/start_info is aligned. - */ - last_addr +=3D elf_round_up(&elf, strlen(bd->cmdline) + 1); - } - if ( initrd !=3D NULL ) - { - rc =3D hvm_copy_to_guest_phys(last_addr, &mod, sizeof(mod), v); - if ( rc ) - { - printk("Unable to copy guest modules\n"); - return rc; - } - start_info.modlist_paddr =3D last_addr; - start_info.nr_modules =3D 1; - last_addr +=3D sizeof(mod); - } - - start_info.magic =3D XEN_HVM_START_MAGIC_VALUE; - start_info.flags =3D SIF_PRIVILEGED | SIF_INITDOMAIN; - rc =3D hvm_copy_to_guest_phys(last_addr, &start_info, sizeof(start_inf= o), v); - if ( rc ) - { - printk("Unable to copy start info to guest\n"); - return rc; - } - - *entry =3D parms.phys_entry; - *start_info_addr =3D last_addr; - - return 0; -} - static int __init cf_check acpi_count_intr_ovr( struct acpi_subtable_header *header, const unsigned long end) { @@ -1255,42 +926,6 @@ int __init dom0_pvh_setup_acpi(struct domain *d, padd= r_t start_info) return 0; } =20 -int __init dom0_construct_pvh(struct boot_domain *bd) -{ - paddr_t entry, start_info; - struct domain *d =3D bd->d; - int rc; - - rc =3D pvh_load_kernel(bd, &entry, &start_info); - if ( rc ) - { - printk("Failed to load Dom0 kernel\n"); - return rc; - } - - rc =3D hvm_setup_cpus(bd->d, entry, start_info); - if ( rc ) - { - printk("Failed to setup Dom0 CPUs: %d\n", rc); - return rc; - } - - rc =3D dom0_pvh_setup_acpi(bd->d, start_info); - if ( rc ) - { - printk("Failed to setup Dom0 ACPI tables: %d\n", rc); - return rc; - } - - if ( opt_dom0_verbose ) - { - printk("Dom%u memory map:\n", d->domain_id); - print_e820_memory_map(d->arch.e820, d->arch.nr_e820); - } - - return 0; -} - /* * Local variables: * mode: C diff --git a/xen/arch/x86/hvm/dom_build.c b/xen/arch/x86/hvm/dom_build.c index 9421dc431ba9..2e47ca489a71 100644 --- a/xen/arch/x86/hvm/dom_build.c +++ b/xen/arch/x86/hvm/dom_build.c @@ -16,10 +16,12 @@ =20 #include =20 +#include #include #include =20 #include +#include #include #include #include @@ -276,8 +278,338 @@ static int __init hvm_populate_p2m(struct domain *d) return 0; } =20 +static paddr_t __init find_memory( + const struct domain *d, const struct elf_binary *elf, size_t size) +{ + paddr_t kernel_start =3D (paddr_t)elf->dest_base & PAGE_MASK; + paddr_t kernel_end =3D ROUNDUP((paddr_t)elf->dest_base + elf->dest_siz= e, + PAGE_SIZE); + unsigned int i; + + /* + * The memory map is sorted and all RAM regions starts and sizes are + * aligned to page boundaries. + */ + for ( i =3D 0; i < d->arch.nr_e820; i++ ) + { + paddr_t start, end =3D d->arch.e820[i].addr + d->arch.e820[i].size; + + /* Don't use memory below 1MB, as it could overwrite BDA/EBDA/IBFT= . */ + if ( end <=3D MB(1) || d->arch.e820[i].type !=3D E820_RAM ) + continue; + + start =3D MAX(ROUNDUP(d->arch.e820[i].addr, PAGE_SIZE), MB(1)); + + ASSERT(IS_ALIGNED(start, PAGE_SIZE) && IS_ALIGNED(end, PAGE_SIZE)); + + /* + * NB: Even better would be to use rangesets to determine a suitab= le + * range, in particular in case a kernel requests multiple heavily + * discontiguous regions (which right now we fold all into one big + * region). + */ + if ( end <=3D kernel_start || start >=3D kernel_end ) + { + /* No overlap, just check whether the region is large enough. = */ + if ( end - start >=3D size ) + return start; + } + /* Deal with the kernel already being loaded in the region. */ + else if ( kernel_start > start && kernel_start - start >=3D size ) + return start; + else if ( kernel_end < end && end - kernel_end >=3D size ) + return kernel_end; + } + + return INVALID_PADDR; +} + +static bool __init check_load_address( + const struct domain *d, const struct elf_binary *elf) +{ + paddr_t kernel_start =3D (uintptr_t)elf->dest_base; + paddr_t kernel_end =3D kernel_start + elf->dest_size; + unsigned int i; + + /* Relies on a sorted memory map with adjacent entries merged. */ + for ( i =3D 0; i < d->arch.nr_e820; i++ ) + { + paddr_t start =3D d->arch.e820[i].addr; + paddr_t end =3D start + d->arch.e820[i].size; + + if ( start >=3D kernel_end ) + return false; + + if ( d->arch.e820[i].type =3D=3D E820_RAM && + start <=3D kernel_start && + end >=3D kernel_end ) + return true; + } + + return false; +} + +/* Find an e820 RAM region that fits the kernel at a suitable alignment. */ +static paddr_t __init find_kernel_memory( + const struct domain *d, struct elf_binary *elf, + const struct elf_dom_parms *parms) +{ + paddr_t kernel_size =3D elf->dest_size; + unsigned int align; + unsigned int i; + + if ( parms->phys_align !=3D UNSET_ADDR32 ) + align =3D parms->phys_align; + else if ( elf->palign >=3D PAGE_SIZE ) + align =3D elf->palign; + else + align =3D MB(2); + + /* Search backwards to find the highest address. */ + for ( i =3D d->arch.nr_e820; i--; ) + { + paddr_t start =3D d->arch.e820[i].addr; + paddr_t end =3D start + d->arch.e820[i].size; + paddr_t kstart, kend; + + if ( d->arch.e820[i].type !=3D E820_RAM || + d->arch.e820[i].size < kernel_size ) + continue; + + if ( start > parms->phys_max ) + continue; + + if ( end - 1 > parms->phys_max ) + end =3D parms->phys_max + 1; + + kstart =3D (end - kernel_size) & ~(align - 1); + kend =3D kstart + kernel_size; + + if ( kstart < parms->phys_min ) + return 0; + + if ( kstart >=3D start && kend <=3D end ) + return kstart; + } + + return 0; +} + +/* Check the kernel load address, and adjust if necessary and possible. */ +static bool __init check_and_adjust_load_address( + const struct domain *d, struct elf_binary *elf, struct elf_dom_parms *= parms) +{ + paddr_t reloc_base; + + if ( check_load_address(d, elf) ) + return true; + + if ( !parms->phys_reloc ) + { + printk("%pd kernel: Address conflict and not relocatable\n", d); + return false; + } + + reloc_base =3D find_kernel_memory(d, elf, parms); + if ( !reloc_base ) + { + printk("%pd kernel: Failed find a load address\n", d); + return false; + } + + if ( opt_dom0_verbose ) + printk("%pd kernel: Moving [%p, %p] -> [%"PRIpaddr", %"PRIpaddr"]\= n", d, + elf->dest_base, elf->dest_base + elf->dest_size - 1, + reloc_base, reloc_base + elf->dest_size - 1); + + parms->phys_entry =3D + reloc_base + (parms->phys_entry - (uintptr_t)elf->dest_base); + elf->dest_base =3D (char *)reloc_base; + + return true; +} + +static int __init pvh_load_kernel( + const struct boot_domain *bd, paddr_t *entry, paddr_t *start_info_addr) +{ + struct domain *d =3D bd->d; + struct boot_module *image =3D bd->kernel; + struct boot_module *initrd =3D bd->ramdisk; + void *image_base =3D bootstrap_map_bm(image); + void *image_start =3D image_base + image->headroom; + unsigned long image_len =3D image->size; + unsigned long initrd_len =3D initrd ? initrd->size : 0; + const char *initrd_cmdline =3D NULL; + struct elf_binary elf; + struct elf_dom_parms parms; + size_t extra_space; + paddr_t last_addr; + struct hvm_start_info start_info =3D { 0 }; + struct hvm_modlist_entry mod =3D { 0 }; + struct vcpu *v =3D d->vcpu[0]; + int rc; + + if ( (rc =3D bzimage_parse(image_base, &image_start, &image_len)) !=3D= 0 ) + { + printk("Error trying to detect bz compressed kernel\n"); + return rc; + } + + if ( (rc =3D elf_init(&elf, image_start, image_len)) !=3D 0 ) + { + printk("Unable to init ELF\n"); + return rc; + } + if ( opt_dom0_verbose ) + elf_set_verbose(&elf); + elf_parse_binary(&elf); + if ( (rc =3D elf_xen_parse(&elf, &parms, true)) !=3D 0 ) + { + printk("Unable to parse kernel for ELFNOTES\n"); + if ( elf_check_broken(&elf) ) + printk("%pd kernel: broken ELF: %s\n", d, elf_check_broken(&el= f)); + return rc; + } + + if ( parms.phys_entry =3D=3D UNSET_ADDR32 ) + { + printk("Unable to find XEN_ELFNOTE_PHYS32_ENTRY address\n"); + return -EINVAL; + } + + /* Copy the OS image and free temporary buffer. */ + elf.dest_base =3D (void *)(parms.virt_kstart - parms.virt_base); + elf.dest_size =3D parms.virt_kend - parms.virt_kstart; + + if ( !check_and_adjust_load_address(d, &elf, &parms) ) + return -ENOSPC; + + elf_set_vcpu(&elf, v); + rc =3D elf_load_binary(&elf); + if ( rc < 0 ) + { + printk("Failed to load kernel: %d\n", rc); + if ( elf_check_broken(&elf) ) + printk("%pd kernel: broken ELF: %s\n", d, elf_check_broken(&el= f)); + return rc; + } + + /* + * Find a RAM region big enough (and that doesn't overlap with the loa= ded + * kernel) in order to load the initrd and the metadata. Note it could= be + * split into smaller allocations, done as a single region in order to + * simplify it. + */ + extra_space =3D sizeof(start_info); + + if ( initrd ) + { + size_t initrd_space =3D elf_round_up(&elf, initrd_len); + + if ( initrd->cmdline_pa ) + { + initrd_cmdline =3D __va(initrd->cmdline_pa); + if ( !*initrd_cmdline ) + initrd_cmdline =3D NULL; + } + if ( initrd_cmdline ) + initrd_space +=3D strlen(initrd_cmdline) + 1; + + if ( initrd_space ) + extra_space +=3D ROUNDUP(initrd_space, PAGE_SIZE) + sizeof(mod= ); + else + initrd =3D NULL; + } + + if ( bd->cmdline ) + extra_space +=3D elf_round_up(&elf, strlen(bd->cmdline) + 1); + + last_addr =3D find_memory(d, &elf, extra_space); + if ( last_addr =3D=3D INVALID_PADDR ) + { + printk("Unable to find a memory region to load initrd and metadata= \n"); + return -ENOMEM; + } + + if ( initrd !=3D NULL ) + { + rc =3D hvm_copy_to_guest_phys(last_addr, __va(initrd->start), + initrd_len, v); + if ( rc ) + { + printk("Unable to copy initrd to guest\n"); + return rc; + } + + mod.paddr =3D last_addr; + mod.size =3D initrd_len; + last_addr +=3D elf_round_up(&elf, initrd_len); + if ( initrd_cmdline ) + { + size_t len =3D strlen(initrd_cmdline) + 1; + + rc =3D hvm_copy_to_guest_phys(last_addr, initrd_cmdline, len, = v); + if ( rc ) + { + printk("Unable to copy module command line\n"); + return rc; + } + mod.cmdline_paddr =3D last_addr; + last_addr +=3D len; + } + last_addr =3D ROUNDUP(last_addr, PAGE_SIZE); + } + + /* Free temporary buffers. */ + free_boot_modules(); + + if ( bd->cmdline ) + { + rc =3D hvm_copy_to_guest_phys(last_addr, bd->cmdline, + strlen(bd->cmdline) + 1, v); + if ( rc ) + { + printk("Unable to copy guest command line\n"); + return rc; + } + start_info.cmdline_paddr =3D last_addr; + /* + * Round up to 32/64 bits (depending on the guest kernel bitness) = so + * the modlist/start_info is aligned. + */ + last_addr +=3D elf_round_up(&elf, strlen(bd->cmdline) + 1); + } + if ( initrd !=3D NULL ) + { + rc =3D hvm_copy_to_guest_phys(last_addr, &mod, sizeof(mod), v); + if ( rc ) + { + printk("Unable to copy guest modules\n"); + return rc; + } + start_info.modlist_paddr =3D last_addr; + start_info.nr_modules =3D 1; + last_addr +=3D sizeof(mod); + } + + start_info.magic =3D XEN_HVM_START_MAGIC_VALUE; + start_info.flags =3D SIF_PRIVILEGED | SIF_INITDOMAIN; + rc =3D hvm_copy_to_guest_phys(last_addr, &start_info, sizeof(start_inf= o), v); + if ( rc ) + { + printk("Unable to copy start info to guest\n"); + return rc; + } + + *entry =3D parms.phys_entry; + *start_info_addr =3D last_addr; + + return 0; +} + int __init dom_construct_pvh(struct boot_domain *bd) { + paddr_t entry, start_info; int rc; =20 printk(XENLOG_INFO "*** Building a PVH Dom%d ***\n", bd->domid); @@ -327,7 +659,35 @@ int __init dom_construct_pvh(struct boot_domain *bd) return rc; } =20 - return dom0_construct_pvh(bd); + rc =3D pvh_load_kernel(bd, &entry, &start_info); + if ( rc ) + { + printk("Failed to load Dom0 kernel\n"); + return rc; + } + + rc =3D hvm_setup_cpus(bd->d, entry, start_info); + if ( rc ) + { + printk("Failed to setup Dom0 CPUs: %d\n", rc); + return rc; + } + + rc =3D dom0_pvh_setup_acpi(bd->d, start_info); + if ( rc ) + { + printk("Failed to setup Dom0 ACPI tables: %d\n", rc); + return rc; + } + + if ( opt_dom0_verbose ) + { + printk("Dom%u memory map:\n", bd->domid); + print_e820_memory_map(bd->d->arch.e820, bd->d->arch.nr_e820); + } + + printk("WARNING: PVH is an experimental mode with limited functionalit= y\n"); + return 0; } =20 /* diff --git a/xen/arch/x86/include/asm/dom0_build.h b/xen/arch/x86/include/a= sm/dom0_build.h index 3819b3f4e7a4..6947aaa1dce3 100644 --- a/xen/arch/x86/include/asm/dom0_build.h +++ b/xen/arch/x86/include/asm/dom0_build.h @@ -24,7 +24,6 @@ int dom0_pvh_setup_acpi(struct domain *d, paddr_t start_i= nfo); int dom0_pvh_populate_p2m(struct domain *d); =20 int dom0_construct_pv(struct boot_domain *bd); -int dom0_construct_pvh(struct boot_domain *bd); =20 void dom0_update_physmap(bool compat, unsigned long pfn, unsigned long mfn, unsigned long vphysmap_s); --=20 2.30.2 From nobody Fri Oct 31 16:34:17 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=1745101270; cv=pass; d=zohomail.com; s=zohoarc; b=Np0c84aCkxb7BJfm8MjdQdDCv4H1JIfozBiblph/4UzqbtV9NdUqAWqCSiBkLibJYeo9dFQkiMGuCKGxqz/OTNaeFiEuvWm1YCQAff2gudtWbF+VNZSFuZ3xwhFJXXdj4cx0kGKWK8vEZ6izt7VzsC20liCRY1ulIdKGtU8TtAU= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745101270; 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=t9+6TFLoyoFwcTN44ZcSyiJ24R2Iz0GpkYNzuDAFngY=; b=Q21VMkpCb9Z7CEKXanm/O/6VcEC8vKfG9XnCtoT/h7YG/Nc8QbIX6YgMCIsaXaR2pI3BVy/nvI5OuhkIXBBDeegW13oqtARWjMCkCej5Sm6GpeYgA73xtmYsNAZvq+w0JbUcL4aHtCEfYRoxxiaAxbZyS+IPWrgncKo6ERUAq9c= 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 1745101270044378.2787050750926; Sat, 19 Apr 2025 15:21:10 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.960184.1352263 (Exim 4.92) (envelope-from ) id 1u6GYU-0000r0-Tg; Sat, 19 Apr 2025 22:20:58 +0000 Received: by outflank-mailman (output) from mailman id 960184.1352263; Sat, 19 Apr 2025 22:20:58 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u6GYU-0000qo-OM; Sat, 19 Apr 2025 22:20:58 +0000 Received: by outflank-mailman (input) for mailman id 960184; Sat, 19 Apr 2025 22:20:57 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u6GPZ-0007X1-65 for xen-devel@lists.xenproject.org; Sat, 19 Apr 2025 22:11:45 +0000 Received: from sender4-of-o50.zoho.com (sender4-of-o50.zoho.com [136.143.188.50]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 45d07e4d-1d6b-11f0-9ffb-bf95429c2676; Sun, 20 Apr 2025 00:11:43 +0200 (CEST) Received: by mx.zohomail.com with SMTPS id 1745100547815772.7241650743158; Sat, 19 Apr 2025 15:09:07 -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: 45d07e4d-1d6b-11f0-9ffb-bf95429c2676 ARC-Seal: i=1; a=rsa-sha256; t=1745100552; cv=none; d=zohomail.com; s=zohoarc; b=APvg8aaqEPHAMJdH5bBudnqZmc8jkO/dVkRSffABlNQJvYjcF2pQ5/CbKWcmOAAzcDEV7UVE36MXAxNvjRuqBSfc9qWn1e6Zs71gbRoArxu8fKMlAh82B8slh5nrK1qOEMWGboLhAeLi06pWPyD70x7Z5UB6razcRkX6wTcUzoM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100552; 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=t9+6TFLoyoFwcTN44ZcSyiJ24R2Iz0GpkYNzuDAFngY=; b=CqPczbYcAwiXUsrzYtAsyEbNBKeHu4Jbmnv/jx9bOuQGI7r3361+v9yu3WOXjNAMlmQ7OXqDN8cRjB4720k6/gpFjED0BEaEhLQcRjEi+NmjA7yc13oGmPMwyBuWsi6i0pThrP0kZVuMhY8oS64kI6f8knwCe9S3J3uLr63qG9w= 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=1745100552; 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=t9+6TFLoyoFwcTN44ZcSyiJ24R2Iz0GpkYNzuDAFngY=; b=kTlHIIGcdvRSbG1Wkbdk9VosPZ9pZydpKVpvrDIRZ3ts9JLI98NsLSU2KY1sZ7nH YQCIeZB+ApU5VZIWJEXQJyacJJUgcLI62VpB+QpanfC358KX41M5x6CUHDTMOHz2p6q T9Im1hnmUdAqVN0wGUM2aiByfISSpAxxJj3/N0RQ= 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 22/38] x86/hyperlaunch: relocate pvh_steal_ram to domain builder Date: Sat, 19 Apr 2025 18:08:04 -0400 Message-Id: <20250419220820.4234-23-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: 1745101273309019100 Content-Type: text/plain; charset="utf-8" The function pvh_steal_ram() is not pvh specific and can be used on any HVM domain. Move to the domain builder and rename to hvm_steal_ram. Signed-off-by: Daniel P. Smith --- xen/arch/x86/hvm/dom0_build.c | 106 +++------------------- xen/arch/x86/hvm/dom_build.c | 84 +++++++++++++++++ xen/arch/x86/include/asm/domain-builder.h | 7 ++ 3 files changed, 102 insertions(+), 95 deletions(-) diff --git a/xen/arch/x86/hvm/dom0_build.c b/xen/arch/x86/hvm/dom0_build.c index 23b46ef86c9f..11dfc54f5ab2 100644 --- a/xen/arch/x86/hvm/dom0_build.c +++ b/xen/arch/x86/hvm/dom0_build.c @@ -182,90 +182,6 @@ int __init pvh_populate_memory_range( return 0; } =20 -/* Steal RAM from the end of a memory region. */ -static int __init pvh_steal_ram(struct domain *d, unsigned long size, - unsigned long align, paddr_t limit, - paddr_t *addr) -{ - unsigned int i =3D d->arch.nr_e820; - - /* - * Alignment 0 should be set to 1, so it doesn't wrap around in the - * calculations below. - */ - align =3D align ? : 1; - while ( i-- ) - { - struct e820entry *entry =3D &d->arch.e820[i]; - - if ( entry->type !=3D E820_RAM || entry->addr + entry->size > limi= t ) - continue; - - *addr =3D (entry->addr + entry->size - size) & ~(align - 1); - if ( *addr < entry->addr || - /* Don't steal from the low 1MB due to the copying done there= . */ - *addr < MB(1) ) - continue; - - entry->size =3D *addr - entry->addr; - return 0; - } - - return -ENOMEM; -} - -/* NB: memory map must be sorted at all times for this to work correctly. = */ -static int __init pvh_add_mem_range(struct domain *d, uint64_t s, uint64_t= e, - unsigned int type) -{ - struct e820entry *map; - unsigned int i; - - for ( i =3D 0; i < d->arch.nr_e820; i++ ) - { - uint64_t rs =3D d->arch.e820[i].addr; - uint64_t re =3D rs + d->arch.e820[i].size; - - if ( rs =3D=3D e && d->arch.e820[i].type =3D=3D type ) - { - d->arch.e820[i].addr =3D s; - return 0; - } - - if ( re =3D=3D s && d->arch.e820[i].type =3D=3D type && - (i + 1 =3D=3D d->arch.nr_e820 || d->arch.e820[i + 1].addr >= =3D e) ) - { - d->arch.e820[i].size +=3D e - s; - return 0; - } - - if ( rs >=3D e ) - break; - - if ( re > s ) - return -EEXIST; - } - - map =3D xzalloc_array(struct e820entry, d->arch.nr_e820 + 1); - if ( !map ) - { - printk(XENLOG_WARNING "E820: out of memory to add region\n"); - return -ENOMEM; - } - - memcpy(map, d->arch.e820, i * sizeof(*d->arch.e820)); - memcpy(map + i + 1, d->arch.e820 + i, - (d->arch.nr_e820 - i) * sizeof(*d->arch.e820)); - map[i].addr =3D s; - map[i].size =3D e - s; - map[i].type =3D type; - xfree(d->arch.e820); - d->arch.e820 =3D map; - d->arch.nr_e820++; - - return 0; -} - static int __init pvh_setup_vmx_realmode_helpers(struct domain *d) { uint32_t rc, *ident_pt; @@ -279,14 +195,14 @@ static int __init pvh_setup_vmx_realmode_helpers(stru= ct domain *d) * TSS structure (which accounts for the first 104b) doesn't cross * a page boundary. */ - if ( !pvh_steal_ram(d, HVM_VM86_TSS_SIZE, 128, GB(4), &gaddr) ) + if ( !hvm_steal_ram(d, HVM_VM86_TSS_SIZE, 128, GB(4), &gaddr) ) { if ( hvm_copy_to_guest_phys(gaddr, NULL, HVM_VM86_TSS_SIZE, v) != =3D HVMTRANS_okay ) printk("Unable to zero VM86 TSS area\n"); d->arch.hvm.params[HVM_PARAM_VM86_TSS_SIZED] =3D VM86_TSS_UPDATED | ((uint64_t)HVM_VM86_TSS_SIZE << 32) | gaddr; - if ( pvh_add_mem_range(d, gaddr, gaddr + HVM_VM86_TSS_SIZE, + if ( hvm_add_mem_range(d, gaddr, gaddr + HVM_VM86_TSS_SIZE, E820_RESERVED) ) printk("Unable to set VM86 TSS as reserved in the memory map\n= "); } @@ -294,7 +210,7 @@ static int __init pvh_setup_vmx_realmode_helpers(struct= domain *d) printk("Unable to allocate VM86 TSS area\n"); =20 /* Steal some more RAM for the identity page tables. */ - if ( pvh_steal_ram(d, PAGE_SIZE, PAGE_SIZE, GB(4), &gaddr) ) + if ( hvm_steal_ram(d, PAGE_SIZE, PAGE_SIZE, GB(4), &gaddr) ) { printk("Unable to find memory to stash the identity page tables\n"= ); return -ENOMEM; @@ -316,7 +232,7 @@ static int __init pvh_setup_vmx_realmode_helpers(struct= domain *d) unmap_domain_page(ident_pt); put_page(mfn_to_page(mfn)); d->arch.hvm.params[HVM_PARAM_IDENT_PT] =3D gaddr; - if ( pvh_add_mem_range(d, gaddr, gaddr + PAGE_SIZE, E820_RESERVED) ) + if ( hvm_add_mem_range(d, gaddr, gaddr + PAGE_SIZE, E820_RESERVED) ) printk("Unable to set identity page tables as reserved in the = memory map\n"); =20 return 0; @@ -581,7 +497,7 @@ static int __init pvh_setup_acpi_madt(struct domain *d,= paddr_t *addr) madt->header.checksum -=3D acpi_tb_checksum(ACPI_CAST_PTR(u8, madt), s= ize); =20 /* Place the new MADT in guest memory space. */ - if ( pvh_steal_ram(d, size, 0, GB(4), addr) ) + if ( hvm_steal_ram(d, size, 0, GB(4), addr) ) { printk("Unable to steal guest RAM for MADT\n"); rc =3D -ENOMEM; @@ -589,7 +505,7 @@ static int __init pvh_setup_acpi_madt(struct domain *d,= paddr_t *addr) } =20 /* Mark this region as E820_ACPI. */ - if ( pvh_add_mem_range(d, *addr, *addr + size, E820_ACPI) ) + if ( hvm_add_mem_range(d, *addr, *addr + size, E820_ACPI) ) printk("Unable to add MADT region to memory map\n"); =20 rc =3D hvm_copy_to_guest_phys(*addr, madt, size, d->vcpu[0]); @@ -769,7 +685,7 @@ static int __init pvh_setup_acpi_xsdt(struct domain *d,= paddr_t madt_addr, xsdt->header.checksum -=3D acpi_tb_checksum(ACPI_CAST_PTR(u8, xsdt), s= ize); =20 /* Place the new XSDT in guest memory space. */ - if ( pvh_steal_ram(d, size, 0, GB(4), addr) ) + if ( hvm_steal_ram(d, size, 0, GB(4), addr) ) { printk("Unable to find guest RAM for XSDT\n"); rc =3D -ENOMEM; @@ -777,7 +693,7 @@ static int __init pvh_setup_acpi_xsdt(struct domain *d,= paddr_t madt_addr, } =20 /* Mark this region as E820_ACPI. */ - if ( pvh_add_mem_range(d, *addr, *addr + size, E820_ACPI) ) + if ( hvm_add_mem_range(d, *addr, *addr + size, E820_ACPI) ) printk("Unable to add XSDT region to memory map\n"); =20 rc =3D hvm_copy_to_guest_phys(*addr, xsdt, size, d->vcpu[0]); @@ -823,7 +739,7 @@ int __init dom0_pvh_setup_acpi(struct domain *d, paddr_= t start_info) if ( strncmp(sig, ACPI_SIG_MADT, ACPI_NAME_SIZE) ? pvh_acpi_table_allowed(sig, addr, size) : !acpi_memory_banned(addr, size) ) - pvh_add_mem_range(d, addr, addr + size, E820_ACPI); + hvm_add_mem_range(d, addr, addr + size, E820_ACPI); } =20 /* Identity map ACPI e820 regions. */ @@ -892,14 +808,14 @@ int __init dom0_pvh_setup_acpi(struct domain *d, padd= r_t start_info) * the native RSDT, and should not be used for the Dom0 kernel's boot * purposes (we keep it visible for post boot access). */ - if ( pvh_steal_ram(d, sizeof(rsdp), 0, GB(4), &rsdp_paddr) ) + if ( hvm_steal_ram(d, sizeof(rsdp), 0, GB(4), &rsdp_paddr) ) { printk("Unable to allocate guest RAM for RSDP\n"); return -ENOMEM; } =20 /* Mark this region as E820_ACPI. */ - if ( pvh_add_mem_range(d, rsdp_paddr, rsdp_paddr + sizeof(rsdp), + if ( hvm_add_mem_range(d, rsdp_paddr, rsdp_paddr + sizeof(rsdp), E820_ACPI) ) printk("Unable to add RSDP region to memory map\n"); =20 diff --git a/xen/arch/x86/hvm/dom_build.c b/xen/arch/x86/hvm/dom_build.c index 2e47ca489a71..f997f293f329 100644 --- a/xen/arch/x86/hvm/dom_build.c +++ b/xen/arch/x86/hvm/dom_build.c @@ -278,6 +278,38 @@ static int __init hvm_populate_p2m(struct domain *d) return 0; } =20 +/* Steal RAM from the end of a memory region. */ +int __init hvm_steal_ram( + struct domain *d, unsigned long size, unsigned long align, paddr_t lim= it, + paddr_t *addr) +{ + unsigned int i =3D d->arch.nr_e820; + + /* + * Alignment 0 should be set to 1, so it doesn't wrap around in the + * calculations below. + */ + align =3D align ? : 1; + while ( i-- ) + { + struct e820entry *entry =3D &d->arch.e820[i]; + + if ( entry->type !=3D E820_RAM || entry->addr + entry->size > limi= t ) + continue; + + *addr =3D (entry->addr + entry->size - size) & ~(align - 1); + if ( *addr < entry->addr || + /* Don't steal from the low 1MB due to the copying done there= . */ + *addr < MB(1) ) + continue; + + entry->size =3D *addr - entry->addr; + return 0; + } + + return -ENOMEM; +} + static paddr_t __init find_memory( const struct domain *d, const struct elf_binary *elf, size_t size) { @@ -324,6 +356,58 @@ static paddr_t __init find_memory( return INVALID_PADDR; } =20 +/* NB: memory map must be sorted at all times for this to work correctly. = */ +int __init hvm_add_mem_range( + struct domain *d, uint64_t s, uint64_t e, unsigned int type) +{ + struct e820entry *map; + unsigned int i; + + for ( i =3D 0; i < d->arch.nr_e820; i++ ) + { + uint64_t rs =3D d->arch.e820[i].addr; + uint64_t re =3D rs + d->arch.e820[i].size; + + if ( rs =3D=3D e && d->arch.e820[i].type =3D=3D type ) + { + d->arch.e820[i].addr =3D s; + return 0; + } + + if ( re =3D=3D s && d->arch.e820[i].type =3D=3D type && + (i + 1 =3D=3D d->arch.nr_e820 || d->arch.e820[i + 1].addr >= =3D e) ) + { + d->arch.e820[i].size +=3D e - s; + return 0; + } + + if ( rs >=3D e ) + break; + + if ( re > s ) + return -EEXIST; + } + + map =3D xzalloc_array(struct e820entry, d->arch.nr_e820 + 1); + if ( !map ) + { + printk(XENLOG_WARNING "E820: out of memory to add region\n"); + return -ENOMEM; + } + + memcpy(map, d->arch.e820, i * sizeof(*d->arch.e820)); + memcpy(map + i + 1, d->arch.e820 + i, + (d->arch.nr_e820 - i) * sizeof(*d->arch.e820)); + map[i].addr =3D s; + map[i].size =3D e - s; + map[i].type =3D type; + xfree(d->arch.e820); + d->arch.e820 =3D map; + d->arch.nr_e820++; + + return 0; +} + static bool __init check_load_address( const struct domain *d, const struct elf_binary *elf) { diff --git a/xen/arch/x86/include/asm/domain-builder.h b/xen/arch/x86/inclu= de/asm/domain-builder.h index fa6fa60841ab..ee91edc3c4d1 100644 --- a/xen/arch/x86/include/asm/domain-builder.h +++ b/xen/arch/x86/include/asm/domain-builder.h @@ -9,10 +9,17 @@ int __init builder_get_cmdline( =20 void builder_init(struct boot_info *bi); =20 +int hvm_add_mem_range( + struct domain *d, uint64_t s, uint64_t e, unsigned int type); + int hvm_setup_cpus(struct domain *d, paddr_t entry, paddr_t start_info); int pvh_populate_memory_range( struct domain *d, unsigned long start, unsigned long nr_pages); =20 +int hvm_steal_ram( + struct domain *d, unsigned long size, unsigned long align, paddr_t lim= it, + paddr_t *addr); + unsigned long dom_paging_pages( const struct boot_domain *d, unsigned long nr_pages); =20 --=20 2.30.2 From nobody Fri Oct 31 16:34:17 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=1745101303; cv=pass; d=zohomail.com; s=zohoarc; b=fY9RjvCrQg799eyfAgprTaAgEC+qCRfsCgPEcDmeUjyGjDDdp+/O+PNGvuslYuco5izA8U6eL+cNTctqjouiKPDWC7pFRGLpbs8G6KqIBU+2LPFxd6OvxdKvZ/4vY+yzavL5vcQ28WQxMitGcaTIZ443KcYj3jh8dmmzRmh9C1c= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745101303; 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=GejcDqJh4eQpJAs/6oq6gMhMd3jidjZDIYzSmQIkSCQ=; b=Ol3fwkN8uRXH2gB61L4OwoTYThmPfRv76ZvtsXXlFdTrqcTlMFi109kv8zesh1gZaszbGDix7TUWKMHzHIaYw0oHKQYp9crRaVRQ8UAk5t9xw5w6TWSIVJNOptRvFVwUyqVKXHdEl3bF+FB5O91u6yb0qRpAP9KI1MyJxmr7SSE= 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 1745101303724269.4339325746744; Sat, 19 Apr 2025 15:21:43 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.960254.1352351 (Exim 4.92) (envelope-from ) id 1u6GYw-0004sF-IY; Sat, 19 Apr 2025 22:21:26 +0000 Received: by outflank-mailman (output) from mailman id 960254.1352351; Sat, 19 Apr 2025 22:21:26 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u6GYw-0004qZ-7M; Sat, 19 Apr 2025 22:21:26 +0000 Received: by outflank-mailman (input) for mailman id 960254; Sat, 19 Apr 2025 22:21:24 +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 1u6GPw-0004yY-HI for xen-devel@lists.xenproject.org; Sat, 19 Apr 2025 22:12:08 +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 54384874-1d6b-11f0-9eb0-5ba50f476ded; Sun, 20 Apr 2025 00:12:07 +0200 (CEST) Received: by mx.zohomail.com with SMTPS id 1745100548675466.4706189515272; Sat, 19 Apr 2025 15:09:08 -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: 54384874-1d6b-11f0-9eb0-5ba50f476ded ARC-Seal: i=1; a=rsa-sha256; t=1745100552; cv=none; d=zohomail.com; s=zohoarc; b=ElxRJqYtZe7ohyN2i5hH9DKMkius3OTgqmRUQSCXRFxaKRBAJv56z/TU5ZF7LXnQt/ollB0by6LCc5/5l9M0DJqLHRSnJhGdRtnFVAxnXTi4pj49BuGZLsgtBig7s/ONX2vNYR6Pqve3SiPjqx5W1A6vCckRkGWM+lLSK9UGICw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100552; 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=GejcDqJh4eQpJAs/6oq6gMhMd3jidjZDIYzSmQIkSCQ=; b=JpR0xaxhPe6R70jq41xcFaG52X7TLQRb5rwfVubIvvuvl1yczoqyAac9kIyqJ/SKlBHldlnIidJT5QWi+tRBTpRss25uXxZ0CcIIr0dKsZAMmIE2M9712kZtUJoPbqUVR2BaRIy3TiKcnQ573Bd/e1uJoGPN+2b16wSa7dsri14= 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=1745100552; 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=GejcDqJh4eQpJAs/6oq6gMhMd3jidjZDIYzSmQIkSCQ=; b=iKmWKfuSxPlOaKxRc30RWqNNqG1Apa1rBEX2BdlEgkZfQS+pImHabGak0DFLIGP2 Z/TEWxW2yeQ4E0K7vsz49ytpuKPVjRkQ9DOqkbd8v12R5JFZXt01IMq/k3vsJsOrBka KCBB+CCfSmrF9I79FqQ6dPtvDbaFRmv3Oks4zAmY= 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 23/38] x86/hyperlaunch: add domu acpi construction Date: Sat, 19 Apr 2025 18:08:05 -0400 Message-Id: <20250419220820.4234-24-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: 1745101305492019100 Content-Type: text/plain; charset="utf-8" Introduce hvm_setup_acpi() that will construct an APCI table for a general = HVM domU guest. Signed-off-by: Daniel P. Smith --- xen/arch/x86/hvm/dom_build.c | 213 ++++++++++++++++++++++++++++++++++- 1 file changed, 212 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/hvm/dom_build.c b/xen/arch/x86/hvm/dom_build.c index f997f293f329..c482d5c2d974 100644 --- a/xen/arch/x86/hvm/dom_build.c +++ b/xen/arch/x86/hvm/dom_build.c @@ -408,6 +408,214 @@ int __init hvm_add_mem_range( return 0; } =20 +static int __init hvm_setup_acpi_madt( + struct domain *d, struct acpi_table_madt *madt) +{ + struct acpi_table_header *table; + struct acpi_madt_local_apic *lapic; + acpi_status status; + unsigned long size =3D hvm_size_acpi_madt(d); + int i; + + /* Copy the native MADT table header. */ + status =3D acpi_get_table(ACPI_SIG_MADT, 0, &table); + if ( !ACPI_SUCCESS(status) ) + { + printk("Failed to get MADT ACPI table, aborting.\n"); + return -EINVAL; + } + madt->header =3D *table; + madt->address =3D APIC_DEFAULT_PHYS_BASE; + /* + * NB: this is currently set to 4, which is the revision in the ACPI + * spec 6.1. Sadly ACPICA doesn't provide revision numbers for the + * tables described in the headers. + */ + madt->header.revision =3D min_t(unsigned char, table->revision, 4); + + lapic =3D (void *)(madt + 1); + + for ( i =3D 0; i < d->max_vcpus; i++ ) + { + lapic->header.type =3D ACPI_MADT_TYPE_LOCAL_APIC; + lapic->header.length =3D sizeof(*lapic); + lapic->id =3D i * 2; + lapic->processor_id =3D i; + lapic->lapic_flags =3D ACPI_MADT_ENABLED; + + lapic++; + } + + madt->header.length =3D size; + /* + * Calling acpi_tb_checksum here is a layering violation, but + * introducing a wrapper for such simple usage seems overkill. + */ + madt->header.checksum -=3D acpi_tb_checksum(ACPI_CAST_PTR(u8, madt), s= ize); + + return 0; +} + +static int __init hvm_setup_acpi_xsdt( + struct domain *d, struct acpi_table_xsdt *xsdt, paddr_t madt_addr) +{ + struct acpi_table_header *table; + struct acpi_table_rsdp *rsdp; + unsigned long size =3D hvm_size_acpi_xsdt(d); + paddr_t xsdt_paddr; + + /* + * Restore original DMAR table signature, we are going to filter it fr= om + * the new XSDT that is presented to the guest, so it is no longer + * necessary to have it's signature zapped. + */ + acpi_dmar_reinstate(); + + /* Copy the native XSDT table header. */ + rsdp =3D acpi_os_map_memory(acpi_os_get_root_pointer(), sizeof(*rsdp)); + if ( !rsdp ) + { + printk("Unable to map RSDP\n"); + return -EINVAL; + } + xsdt_paddr =3D rsdp->xsdt_physical_address; + acpi_os_unmap_memory(rsdp, sizeof(*rsdp)); + table =3D acpi_os_map_memory(xsdt_paddr, sizeof(*table)); + if ( !table ) + { + printk("Unable to map XSDT\n"); + return -EINVAL; + } + xsdt->header =3D *table; + acpi_os_unmap_memory(table, sizeof(*table)); + + /* Add the custom MADT. */ + xsdt->table_offset_entry[0] =3D madt_addr; + + xsdt->header.revision =3D 1; + xsdt->header.length =3D size; + /* + * Calling acpi_tb_checksum here is a layering violation, but + * introducing a wrapper for such simple usage seems overkill. + */ + xsdt->header.checksum -=3D acpi_tb_checksum(ACPI_CAST_PTR(u8, xsdt), s= ize); + + return 0; +} + +static int __init hvm_alloc_acpi_region( + struct domain *d, void **region, unsigned long size, paddr_t *addr) +{ + int i; + + *addr =3D 0; + + for ( i =3D 0; i < d->arch.nr_e820; i++ ) + { + if ( d->arch.e820[i].type =3D=3D E820_ACPI ) + { + if ( d->arch.e820[i].size < size ) + break; + + *addr =3D d->arch.e820[i].addr; + break; + } + } + + /* The e820 setup did not allocate ACPI region, steal one instead. */ + if ( *addr =3D=3D 0 ) + { + if ( hvm_steal_ram(d, size, 0, GB(4), addr) ) + { + printk("Unable to allocate guest RAM for RSDP\n"); + return -ENOMEM; + } + if ( hvm_add_mem_range(d, *addr, *addr + size, E820_ACPI) ) + { + printk("Unable to add RSDP region to memory map\n"); + return -EFAULT; + } + } + + *region =3D xzalloc_bytes(size); + if ( !region ) + return -ENOMEM; + + return 0; +} + +static int __init hvm_setup_acpi(struct domain *d, paddr_t start_info) +{ + paddr_t rsdp_paddr, xsdt_paddr, madt_paddr; + struct acpi_table_rsdp *rsdp; + unsigned long size =3D hvm_size_acpi_region(d); + void *table; + int rc; + + rc =3D hvm_alloc_acpi_region(d, &table, size, &rsdp_paddr); + if ( rc < 0 ) + return rc; + + /* RSDP */ + rsdp =3D table; + xsdt_paddr =3D rsdp_paddr + sizeof(struct acpi_table_rsdp); + + *rsdp =3D (struct acpi_table_rsdp){ + .signature =3D ACPI_SIG_RSDP, + .revision =3D 2, + .length =3D sizeof(struct acpi_table_rsdp), + .oem_id =3D "XenHL\0", /* Xen Hyperlaunch */ + .xsdt_physical_address =3D xsdt_paddr, + }; + + rsdp->checksum -=3D acpi_tb_checksum(ACPI_CAST_PTR(u8, rsdp), + ACPI_RSDP_REV0_SIZE); + rsdp->extended_checksum -=3D acpi_tb_checksum(ACPI_CAST_PTR(u8, rsdp), + sizeof(*rsdp)); + + /* XSDT */ + table +=3D sizeof(struct acpi_table_rsdp); + madt_paddr =3D xsdt_paddr + hvm_size_acpi_xsdt(d); + + rc =3D hvm_setup_acpi_xsdt(d, table, madt_paddr); + if ( rc ) + { + printk("Unable to construct XSDT\n"); + goto out; + } + + + /* MADT */ + table +=3D hvm_size_acpi_xsdt(d); + rc =3D hvm_setup_acpi_madt(d, table); + if ( rc ) + { + printk("Unable to construct MADT\n"); + goto out; + } + + /* Copy ACPI region into guest memory. */ + rc =3D hvm_copy_to_guest_phys(rsdp_paddr, rsdp, size, d->vcpu[0]); + if ( rc ) + { + printk("Unable to copy RSDP into guest memory\n"); + goto out; + } + + /* Copy RSDP address to start_info. */ + rc =3D hvm_copy_to_guest_phys( + start_info + offsetof(struct hvm_start_info, rsdp_paddr), &rsdp_pa= ddr, + sizeof(((struct hvm_start_info *) 0)->rsdp_paddr), d->vcpu[0]); + if ( rc ) + printk("Unable to copy RSDP address to start info\n"); + + out: + if ( rsdp ) + xfree(rsdp); + + return rc; +} + static bool __init check_load_address( const struct domain *d, const struct elf_binary *elf) { @@ -757,7 +965,10 @@ int __init dom_construct_pvh(struct boot_domain *bd) return rc; } =20 - rc =3D dom0_pvh_setup_acpi(bd->d, start_info); + if ( is_control_domain(bd->d) || is_hardware_domain(bd->d) ) + rc =3D dom0_pvh_setup_acpi(bd->d, start_info); + else + rc =3D hvm_setup_acpi(bd->d, start_info); if ( rc ) { printk("Failed to setup Dom0 ACPI tables: %d\n", rc); --=20 2.30.2 From nobody Fri Oct 31 16:34:17 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=1745101273; cv=pass; d=zohomail.com; s=zohoarc; b=bVP3O4PatICS/eQ1RnfHGRcJoVxtGBJl19Iv4iNMi9USH89rVtghgfrYvHU2EoTcstDgotb8ho+CqmdzVa7olmdAnmfQMshbOcfGzfm9De/RY1tODHKuRdSu6EpqgqMQGD6Qc5/TG5CWZypjxcCTmGpYuqYT9iMNblmhnCbm17A= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745101273; 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=3+vB3y16bSnFHLNAnwMQEpUCCQz/0/mLC5HYpt1w0xg=; b=bg2Kc1T56mqbjVt1ZtfAA3Sc22K4unqxMlZqdeXt2A15bZm7Nu3y0uvMy+xaGPMObP4alDsZYxXvaHNAQIjTR25J5OuEasaNcN+rgzXiuieAUzCXy7MmXFm0kA4DNbFZ5+y5SoNqWNks+mvHUhMoyCwmNpTVOJYj7wi4ipyNfTQ= 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 1745101273965394.6612710646767; Sat, 19 Apr 2025 15:21:13 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.960191.1352273 (Exim 4.92) (envelope-from ) id 1u6GYW-00019G-3o; Sat, 19 Apr 2025 22:21:00 +0000 Received: by outflank-mailman (output) from mailman id 960191.1352273; Sat, 19 Apr 2025 22:21:00 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u6GYW-00018O-0D; Sat, 19 Apr 2025 22:21:00 +0000 Received: by outflank-mailman (input) for mailman id 960191; Sat, 19 Apr 2025 22:20:58 +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 1u6GPH-0004yY-QT for xen-devel@lists.xenproject.org; Sat, 19 Apr 2025 22:11:27 +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 3c1eea24-1d6b-11f0-9eb0-5ba50f476ded; Sun, 20 Apr 2025 00:11:27 +0200 (CEST) Received: by mx.zohomail.com with SMTPS id 1745100549643175.21812378716868; Sat, 19 Apr 2025 15:09:09 -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: 3c1eea24-1d6b-11f0-9eb0-5ba50f476ded ARC-Seal: i=1; a=rsa-sha256; t=1745100552; cv=none; d=zohomail.com; s=zohoarc; b=mHdh+3MqqcnyJBTJL7QjbHtEFSdv5ayjwpAMfjCK+JmOF4YiVEI3WkihtlD3YZHn4WKJtOhgrkmgpHfq8jS3uEPw/GaPwU/SGDrhKdFg1jg9GUVocvb/+kNefM4bt4jw6TS0VUTuI9ub7bJRFmgQQmkIqaKbaG40zFKYPErXk8Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100552; 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=3+vB3y16bSnFHLNAnwMQEpUCCQz/0/mLC5HYpt1w0xg=; b=DD7ET5SPHwed/mglO1PIEBMVFCu8+M/Sh7zx9uiX8Br1O/xAP2pH8R1cWBjZxcoSVObuDn57JGfhelGndXsNpY180qQ9vnjEN4gDwtC+fIH4x8QbWEjtqqGXZzn0QibkEY29L8bjjbzaWy102Ed1PVOBvZVn1gS98z0CVop8zoY= 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=1745100552; 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=3+vB3y16bSnFHLNAnwMQEpUCCQz/0/mLC5HYpt1w0xg=; b=q8cW+vRRPlYjWE78ZG08qDeDuiFpTehb90CG7MDGWPzKIdJ9/7yPHuqNJ1cIt/WA nAAxg0185s9lIKpsOfSG2DFrHLyb8nAXtSy7PACyPxBUSpirQ7HAL1eUP8krJVYtzbh 0yy+3gEEuWKnEA0yYH2+9wNKiaGwQdyZ2Mm2PgEM= 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 24/38] x86/boot: export command line processing Date: Sat, 19 Apr 2025 18:08:06 -0400 Message-Id: <20250419220820.4234-25-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: 1745101275422019100 Content-Type: text/plain; charset="utf-8" Export the function cmdline_cook() so that it can be called outside of setu= p.c. Signed-off-by: Daniel P. Smith --- xen/arch/x86/include/asm/setup.h | 2 ++ xen/arch/x86/setup.c | 4 +--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/xen/arch/x86/include/asm/setup.h b/xen/arch/x86/include/asm/se= tup.h index b517da6144de..4b8fbdc67e05 100644 --- a/xen/arch/x86/include/asm/setup.h +++ b/xen/arch/x86/include/asm/setup.h @@ -29,6 +29,8 @@ void init_IRQ(void); struct boot_domain; int construct_dom0(struct boot_domain *bd); =20 +const char *cmdline_cook(const char *p, const char *loader_name); + void setup_io_bitmap(struct domain *d); =20 extern struct boot_info xen_boot_info; diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 760262ea3d4c..0c9f1cd98faa 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -291,8 +291,6 @@ static int __init cf_check parse_acpi_param(const char = *s) } custom_param("acpi", parse_acpi_param); =20 -static const char *cmdline_cook(const char *p, const char *loader_name); - struct boot_info __initdata xen_boot_info =3D { .loader =3D "unknown", .cmdline =3D "", @@ -950,7 +948,7 @@ static bool __init loader_is_grub2(const char *loader_n= ame) * * Always returns a pointer within @p. */ -static const char *__init cmdline_cook(const char *p, const char *loader_n= ame) +const char *__init cmdline_cook(const char *p, const char *loader_name) { /* Strip leading whitespace. */ while ( *p =3D=3D ' ' ) --=20 2.30.2 From nobody Fri Oct 31 16:34:17 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=1745101285; cv=pass; d=zohomail.com; s=zohoarc; b=BHSAr20T6BuCldKTr7ElyrUmqYOJRsHLBSjBTPucdWcENwaeu5taVrYaKL1PIdXrjVBl5eP9ETpoIIelTO4fXVRJ4himhVO5yySJfZfpaqqzOh8qM24dosTYX24mglYuvG7k/2GmJkOjcnMD8gyno4Xu9q33Gm6qMRvUVFebxHg= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745101285; 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=XCB/veqLy59i1pjLF+gLDnpye6NGCF9wk7+O4Lczmd0=; b=hAaJRr8pR8pwJO8GYhdYlSxJcPN/hc9pbFvvlzlZjYRBSeWK2E63sSwf+D2vKzRHNnJJ/avBDM4uZoCUzULm8HfdxNUz+19zDGeZlQL5jUqakJeD/sJ6UKv+MCUfi165a1fSPdsEhTywPgEA9iOMEFKYHXQidi2558Z8ht07Izg= 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 1745101285771334.26492290138094; Sat, 19 Apr 2025 15:21:25 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.960214.1352293 (Exim 4.92) (envelope-from ) id 1u6GYh-0002RZ-Qv; Sat, 19 Apr 2025 22:21:11 +0000 Received: by outflank-mailman (output) from mailman id 960214.1352293; Sat, 19 Apr 2025 22:21:11 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u6GYh-0002RH-N5; Sat, 19 Apr 2025 22:21:11 +0000 Received: by outflank-mailman (input) for mailman id 960214; Sat, 19 Apr 2025 22:21:10 +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 1u6GQh-0004yY-Rj for xen-devel@lists.xenproject.org; Sat, 19 Apr 2025 22:12:55 +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 70632971-1d6b-11f0-9eb0-5ba50f476ded; Sun, 20 Apr 2025 00:12:54 +0200 (CEST) Received: by mx.zohomail.com with SMTPS id 1745100550463498.5819628185641; Sat, 19 Apr 2025 15:09:10 -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: 70632971-1d6b-11f0-9eb0-5ba50f476ded ARC-Seal: i=1; a=rsa-sha256; t=1745100554; cv=none; d=zohomail.com; s=zohoarc; b=H5fkN4jq2ULvKJ9gyjiOV9wH1NLWdxyX1Q36QQ4vOI46xMR+gneHEtXCdQnGoF0bWfBkezYllrsbYAWYXChk9Y1NVN/rM2FkPFdD9Ri/IZfXg53jLYsiVl8OJ94XSBUK7ifsoWaj50RQy8fP2B4+yqfBexGeWpFayEau08/sSD0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100554; 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=XCB/veqLy59i1pjLF+gLDnpye6NGCF9wk7+O4Lczmd0=; b=ZLaDLcflQpthWdkHn8Rl05tSFexhUHNsV+Pvkdms/icYAZM1ZOtbLql5ZTFHU92+V4gP6rl2oPt8wVVwHHscmMvR7rYfBUHWhAucd3cd2Xcn5paYYBsIv/DYYjmbkXsLufFQ6wIAGJyvfY+xtIBzKycm6dhNDi0z6ZbYQdzz4I8= 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=1745100554; 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=XCB/veqLy59i1pjLF+gLDnpye6NGCF9wk7+O4Lczmd0=; b=dF3rmo7VPvubptUCA4S8zkVCYu+4eUxLi7R8hp9GPzWm1iC4OmvmMq+vV7EOVTvQ uPLQEwPhLnHfT1j72XJDyiYQLp7j8Nnn7ioqSeAsrMUkEBh3CFX/PzcrsGEDzjdWesc wlvnhsyy04dECXKN9abDi/wvafFhLXHoQEitgkpo= 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 25/38] x86/hyperlaunch: convert create_dom0 to arch_create_dom Date: Sat, 19 Apr 2025 18:08:07 -0400 Message-Id: <20250419220820.4234-26-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: 1745101287213019000 Content-Type: text/plain; charset="utf-8" The only consumer of the function domain_cmdline_size() and the acpi_param parameter is create_dom(). It is therefore reasonable to move domain_cmdline_size() and the acpi_param parameter along with its parsing c= ode at the same time as create_dom0() is moved under the domain builder. While moving create_dom0(), rename it to arch_create_dom() as the function is now generalized. Signed-off-by: Daniel P. Smith --- xen/arch/x86/domain-builder/Makefile | 2 +- xen/arch/x86/domain-builder/domain.c | 172 ++++++++++++++++++++++ xen/arch/x86/include/asm/domain-builder.h | 3 + xen/arch/x86/setup.c | 167 +-------------------- 4 files changed, 177 insertions(+), 167 deletions(-) diff --git a/xen/arch/x86/domain-builder/Makefile b/xen/arch/x86/domain-bui= lder/Makefile index 67024b5cb213..cefe20abd2e6 100644 --- a/xen/arch/x86/domain-builder/Makefile +++ b/xen/arch/x86/domain-builder/Makefile @@ -1,3 +1,3 @@ obj-$(CONFIG_DOMAIN_BUILDER) +=3D fdt.init.o obj-y +=3D core.init.o -obj-y +=3D domain.init.o +obj-y +=3D domain.o diff --git a/xen/arch/x86/domain-builder/domain.c b/xen/arch/x86/domain-bui= lder/domain.c index 764a1af4acd3..a82c02250b4c 100644 --- a/xen/arch/x86/domain-builder/domain.c +++ b/xen/arch/x86/domain-builder/domain.c @@ -5,16 +5,65 @@ =20 #include #include +#include +#include #include #include #include +#include #include =20 #include +#include #include +#include +#include #include +#include #include =20 +bool __read_mostly acpi_disabled; +bool __initdata acpi_force; +static char __initdata acpi_param[10] =3D ""; + +static int __init cf_check parse_acpi_param(const char *s) +{ + /* Interpret the parameter for use within Xen. */ + if ( !parse_bool(s, NULL) ) + { + disable_acpi(); + } + else if ( !strcmp(s, "force") ) + { + acpi_force =3D true; + acpi_ht =3D 1; + acpi_disabled =3D false; + } + else if ( !strcmp(s, "ht") ) + { + if ( !acpi_force ) + disable_acpi(); + acpi_ht =3D 1; + } + else if ( !strcmp(s, "noirq") ) + { + acpi_noirq_set(); + } + else if ( !strcmp(s, "verbose") ) + { + opt_acpi_verbose =3D true; + return 0; + } + else + return -EINVAL; + + /* Save the parameter so it can be propagated to domain0. */ + safe_strcpy(acpi_param, s); + + return 0; +} +custom_param("acpi", parse_acpi_param); + unsigned long __init dom_paging_pages( const struct boot_domain *bd, unsigned long nr_pages) { @@ -138,6 +187,129 @@ void __init alloc_dom_vcpus(struct domain *d) domain_update_node_affinity(d); } =20 +static size_t __init domain_cmdline_size( + struct boot_info *bi, struct boot_domain *bd) +{ + size_t s =3D bi->kextra ? strlen(bi->kextra) : 0; + + if ( bd->kernel->fdt_cmdline ) + s +=3D builder_get_cmdline_size(bi, bd->kernel->cmdline_pa); + else + s +=3D strlen(__va(bd->kernel->cmdline_pa)); + + if ( s =3D=3D 0 ) + return s; + + /* + * Certain parameters from the Xen command line may be added to the do= m0 + * command line. Add additional space for the possible cases along wit= h one + * extra char to hold \0. + */ + s +=3D strlen(" noapic") + strlen(" acpi=3D") + sizeof(acpi_param) + 1; + + return s; +} + +struct domain *__init arch_create_dom( + struct boot_info *bi, struct boot_domain *bd) +{ + char *cmdline =3D NULL; + size_t cmdline_size; + unsigned int create_flags =3D 0; + struct xen_domctl_createdomain dom0_cfg =3D { + .flags =3D IS_ENABLED(CONFIG_TBOOT) ? XEN_DOMCTL_CDF_s3_integrity = : 0, + .max_evtchn_port =3D -1, + .max_grant_frames =3D -1, + .max_maptrack_frames =3D -1, + .grant_opts =3D XEN_DOMCTL_GRANT_version(opt_gnttab_max_version), + .max_vcpus =3D dom_max_vcpus(bd), + .arch =3D { + .misc_flags =3D opt_dom0_msr_relaxed ? XEN_X86_MSR_RELAXED : 0, + }, + }; + struct domain *d; + + if ( opt_dom0_pvh || + (bi->hyperlaunch_enabled && !(bd->mode & BUILD_MODE_PARAVIRT)) ) + { + dom0_cfg.flags |=3D (XEN_DOMCTL_CDF_hvm | + ((hvm_hap_supported() && !opt_dom0_shadow) ? + XEN_DOMCTL_CDF_hap : 0)); + + dom0_cfg.arch.emulation_flags |=3D + XEN_X86_EMU_LAPIC | XEN_X86_EMU_IOAPIC | XEN_X86_EMU_VPCI; + } + + if ( bd->capabilities & BUILD_CAPS_HARDWARE ) + { + create_flags |=3D CDF_hardware; + if ( iommu_enabled ) + dom0_cfg.flags |=3D XEN_DOMCTL_CDF_iommu; + } + + if ( bd->domid =3D=3D DOMID_INVALID ) + /* Create initial domain. Not d0 for pvshim. */ + bd->domid =3D get_initial_domain_id(); + if ( bd->capabilities & BUILD_CAPS_CONTROL ) + create_flags |=3D CDF_privileged | CDF_hardware; + d =3D domain_create(bd->domid, &dom0_cfg, + pv_shim ? 0 : create_flags); + if ( IS_ERR(d) ) + panic("Error creating d%u: %ld\n", bd->domid, PTR_ERR(d)); + + bd->d =3D d; + + if ( bd->capabilities & BUILD_CAPS_CONTROL ) + init_dom0_cpuid_policy(bd->d); + + if ( alloc_dom_vcpu0(bd) =3D=3D NULL ) + panic("Error creating %pd vcpu 0\n", d); + + cmdline_size =3D domain_cmdline_size(bi, bd); + if ( cmdline_size ) + { + if ( !(cmdline =3D xzalloc_array(char, cmdline_size)) ) + panic("Error allocating cmdline buffer for %pd\n", d); + + if ( bd->kernel->fdt_cmdline ) + builder_get_cmdline( + bi, bd->kernel->cmdline_pa, cmdline, cmdline_size); + else + strlcpy(cmdline, + cmdline_cook(__va(bd->kernel->cmdline_pa),bi->loader), + cmdline_size); + + if ( bi->kextra ) + /* kextra always includes exactly one leading space. */ + strlcat(cmdline, bi->kextra, cmdline_size); + + /* Append any extra parameters. */ + if ( skip_ioapic_setup && !strstr(cmdline, "noapic") ) + strlcat(cmdline, " noapic", cmdline_size); + + if ( (strlen(acpi_param) =3D=3D 0) && acpi_disabled ) + { + printk("ACPI is disabled, notifying Domain 0 (acpi=3Doff)\n"); + safe_strcpy(acpi_param, "off"); + } + + if ( (strlen(acpi_param) !=3D 0) && !strstr(cmdline, "acpi=3D") ) + { + strlcat(cmdline, " acpi=3D", cmdline_size); + strlcat(cmdline, acpi_param, cmdline_size); + } + bd->kernel->cmdline_pa =3D 0; + bd->cmdline =3D cmdline; + } + + if ( construct_dom0(bd) !=3D 0 ) + panic("Could not construct domain 0\n"); + + XFREE(cmdline); + + return d; +} + /* * Local variables: * mode: C diff --git a/xen/arch/x86/include/asm/domain-builder.h b/xen/arch/x86/inclu= de/asm/domain-builder.h index ee91edc3c4d1..ccab02c3a1fd 100644 --- a/xen/arch/x86/include/asm/domain-builder.h +++ b/xen/arch/x86/include/asm/domain-builder.h @@ -9,6 +9,9 @@ int __init builder_get_cmdline( =20 void builder_init(struct boot_info *bi); =20 +struct domain *arch_create_dom( + struct boot_info *bi, struct boot_domain *bd); + int hvm_add_mem_range( struct domain *d, uint64_t s, uint64_t e, unsigned int type); =20 diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 0c9f1cd98faa..8f956b6eca4f 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -249,48 +249,6 @@ static int __init cf_check parse_smap_param(const char= *s) } custom_param("smap", parse_smap_param); =20 -bool __read_mostly acpi_disabled; -bool __initdata acpi_force; -static char __initdata acpi_param[10] =3D ""; - -static int __init cf_check parse_acpi_param(const char *s) -{ - /* Interpret the parameter for use within Xen. */ - if ( !parse_bool(s, NULL) ) - { - disable_acpi(); - } - else if ( !strcmp(s, "force") ) - { - acpi_force =3D true; - acpi_ht =3D 1; - acpi_disabled =3D false; - } - else if ( !strcmp(s, "ht") ) - { - if ( !acpi_force ) - disable_acpi(); - acpi_ht =3D 1; - } - else if ( !strcmp(s, "noirq") ) - { - acpi_noirq_set(); - } - else if ( !strcmp(s, "verbose") ) - { - opt_acpi_verbose =3D true; - return 0; - } - else - return -EINVAL; - - /* Save the parameter so it can be propagated to domain0. */ - safe_strcpy(acpi_param, s); - - return 0; -} -custom_param("acpi", parse_acpi_param); - struct boot_info __initdata xen_boot_info =3D { .loader =3D "unknown", .cmdline =3D "", @@ -980,129 +938,6 @@ static unsigned int __init copy_bios_e820(struct e820= entry *map, unsigned int li return n; } =20 -static size_t __init domain_cmdline_size( - struct boot_info *bi, struct boot_domain *bd) -{ - size_t s =3D bi->kextra ? strlen(bi->kextra) : 0; - - if ( bd->kernel->fdt_cmdline ) - s +=3D builder_get_cmdline_size(bi, bd->kernel->cmdline_pa); - else - s +=3D strlen(__va(bd->kernel->cmdline_pa)); - - if ( s =3D=3D 0 ) - return s; - - /* - * Certain parameters from the Xen command line may be added to the do= m0 - * command line. Add additional space for the possible cases along wit= h one - * extra char to hold \0. - */ - s +=3D strlen(" noapic") + strlen(" acpi=3D") + sizeof(acpi_param) + 1; - - return s; -} - -static struct domain *__init create_dom0(struct boot_info *bi) -{ - char *cmdline =3D NULL; - size_t cmdline_size; - unsigned int create_flags =3D 0; - struct boot_domain *bd =3D &bi->domains[0]; - struct xen_domctl_createdomain dom0_cfg =3D { - .flags =3D IS_ENABLED(CONFIG_TBOOT) ? XEN_DOMCTL_CDF_s3_integrity = : 0, - .max_evtchn_port =3D -1, - .max_grant_frames =3D -1, - .max_maptrack_frames =3D -1, - .grant_opts =3D XEN_DOMCTL_GRANT_version(opt_gnttab_max_version), - .max_vcpus =3D dom_max_vcpus(bd), - .arch =3D { - .misc_flags =3D opt_dom0_msr_relaxed ? XEN_X86_MSR_RELAXED : 0, - }, - }; - struct domain *d; - - if ( opt_dom0_pvh || - (bi->hyperlaunch_enabled && !(bd->mode & BUILD_MODE_PARAVIRT)) ) - { - dom0_cfg.flags |=3D (XEN_DOMCTL_CDF_hvm | - ((hvm_hap_supported() && !opt_dom0_shadow) ? - XEN_DOMCTL_CDF_hap : 0)); - - dom0_cfg.arch.emulation_flags |=3D - XEN_X86_EMU_LAPIC | XEN_X86_EMU_IOAPIC | XEN_X86_EMU_VPCI; - } - - if ( bd->capabilities & BUILD_CAPS_HARDWARE ) - { - create_flags |=3D CDF_hardware; - if ( iommu_enabled ) - dom0_cfg.flags |=3D XEN_DOMCTL_CDF_iommu; - } - - if ( bd->domid =3D=3D DOMID_INVALID ) - /* Create initial domain. Not d0 for pvshim. */ - bd->domid =3D get_initial_domain_id(); - if ( bd->capabilities & BUILD_CAPS_CONTROL ) - create_flags |=3D CDF_privileged | CDF_hardware; - d =3D domain_create(bd->domid, &dom0_cfg, - pv_shim ? 0 : create_flags); - if ( IS_ERR(d) ) - panic("Error creating d%u: %ld\n", bd->domid, PTR_ERR(d)); - - bd->d =3D d; - - if ( bd->capabilities & BUILD_CAPS_CONTROL ) - init_dom0_cpuid_policy(bd->d); - - if ( alloc_dom_vcpu0(bd) =3D=3D NULL ) - panic("Error creating %pd vcpu 0\n", d); - - cmdline_size =3D domain_cmdline_size(bi, bd); - if ( cmdline_size ) - { - if ( !(cmdline =3D xzalloc_array(char, cmdline_size)) ) - panic("Error allocating cmdline buffer for %pd\n", d); - - if ( bd->kernel->fdt_cmdline ) - builder_get_cmdline( - bi, bd->kernel->cmdline_pa, cmdline, cmdline_size); - else - strlcpy(cmdline, - cmdline_cook(__va(bd->kernel->cmdline_pa),bi->loader), - cmdline_size); - - if ( bi->kextra ) - /* kextra always includes exactly one leading space. */ - strlcat(cmdline, bi->kextra, cmdline_size); - - /* Append any extra parameters. */ - if ( skip_ioapic_setup && !strstr(cmdline, "noapic") ) - strlcat(cmdline, " noapic", cmdline_size); - - if ( (strlen(acpi_param) =3D=3D 0) && acpi_disabled ) - { - printk("ACPI is disabled, notifying Domain 0 (acpi=3Doff)\n"); - safe_strcpy(acpi_param, "off"); - } - - if ( (strlen(acpi_param) !=3D 0) && !strstr(cmdline, "acpi=3D") ) - { - strlcat(cmdline, " acpi=3D", cmdline_size); - strlcat(cmdline, acpi_param, cmdline_size); - } - bd->kernel->cmdline_pa =3D 0; - bd->cmdline =3D cmdline; - } - - if ( construct_dom0(bd) !=3D 0 ) - panic("Could not construct domain 0\n"); - - XFREE(cmdline); - - return d; -} - /* How much of the directmap is prebuilt at compile time. */ #define PREBUILT_MAP_LIMIT (1 << L2_PAGETABLE_SHIFT) =20 @@ -2180,7 +2015,7 @@ void asmlinkage __init noreturn __start_xen(void) * We're going to setup domain0 using the module(s) that we stashed sa= fely * above our heap. The second module, if present, is an initrd ramdisk. */ - dom0 =3D create_dom0(bi); + dom0 =3D arch_create_dom(bi, &bi->domains[0]); if ( !dom0 ) panic("Could not set up DOM0 guest OS\n"); =20 --=20 2.30.2 From nobody Fri Oct 31 16:34:17 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=1745101277; cv=pass; d=zohomail.com; s=zohoarc; b=WYY674Bvr7+DudTtLg3tYFazdNgTHjY+Da6t0epyRzl7dCi5nzyCgNQ4OYoFd4BA6mL3RNAn7GY3TH35BKL8JqIOfJr/1oraa+Fq42EmjgGonx++HTggMv5MLPLmispvyWbMAEcpHwfR2wBzzp0qa2PxidSBEUISG1MPwZo7cFI= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745101277; 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=XAtBPUpKdfuodxySJ/eiFSVT2P5Oe98nw2jobpysUkU=; b=eAVquP2+7vwejSkpY2LWBcHPyhAhWfloyLlnGcaHhPDL96+C5rhtTUgqljvTdJ6wFGS5prnqdrcCck9pRGUbAwiODvkiSnlkrijPs7sRfKnS2JKWN7ZKcRvM+0GuHh3k1xdkZBWbqKwZB22tUNmeRIrf6kCC4iYEUGJyhq9Zmag= 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 17451012778265.603911652043735; Sat, 19 Apr 2025 15:21:17 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.960203.1352283 (Exim 4.92) (envelope-from ) id 1u6GYc-0001os-CT; Sat, 19 Apr 2025 22:21:06 +0000 Received: by outflank-mailman (output) from mailman id 960203.1352283; Sat, 19 Apr 2025 22:21:06 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u6GYc-0001od-97; Sat, 19 Apr 2025 22:21:06 +0000 Received: by outflank-mailman (input) for mailman id 960203; Sat, 19 Apr 2025 22:21:05 +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 1u6GQR-0004yY-J2 for xen-devel@lists.xenproject.org; Sat, 19 Apr 2025 22:12:39 +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 66d1af9f-1d6b-11f0-9eb0-5ba50f476ded; Sun, 20 Apr 2025 00:12:38 +0200 (CEST) Received: by mx.zohomail.com with SMTPS id 1745100551247651.7571400527812; Sat, 19 Apr 2025 15:09:11 -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: 66d1af9f-1d6b-11f0-9eb0-5ba50f476ded ARC-Seal: i=1; a=rsa-sha256; t=1745100554; cv=none; d=zohomail.com; s=zohoarc; b=ISi6kBQih0IAqUVdGkDUx1hAdFnR6dedtv6RC9if7MCuq2fMCsDlSZpbnlS182rwCkBKeU3VebBPu2wofakdab4yM1s2GVHDIVDzDor2BlM7BJ2RbZS5WbSYpvzcuTMXDMrtBR0f2dpCclQW5b099M8MNe2r0nS92L5pP3D45R8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100554; 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=XAtBPUpKdfuodxySJ/eiFSVT2P5Oe98nw2jobpysUkU=; b=aA5oUJGC+b2Wvnqb9OOqfbQ6q5zVdFFS0mTGWBC6z2S9L/EoM3xd10InFhHbAAxqW+S9tF5ekEOE1cqZtURmUm7v85QvavSuOP32fyPHfy4rUF+KPYl6rA7QDtDgkGaN1iymDu8Rrwnw2iqCoS+ANv6rVAt4H8VJoNuE5+ly8Zk= 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=1745100553; 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=XAtBPUpKdfuodxySJ/eiFSVT2P5Oe98nw2jobpysUkU=; b=jdo7Asr62vlVqo+jN4XqB//N3sLexMpHPSfc+IgIGC9oNVxfjR+8IOUpRPJ5A+XS SKrnrrLJ7JavfsvqALqByM458o7E2H1ssbmL7Z0V+JlLLBEJPqx+6EzTB7PwpQUVxOJ UJXkywCrNUt79BZbq65sZrAPTnZBMYyiGAOW0HY0= 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 26/38] x86/hyperlaunch: remove dom0-isms from arch_create_dom Date: Sat, 19 Apr 2025 18:08:08 -0400 Message-Id: <20250419220820.4234-27-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: 1745101279097019000 Content-Type: text/plain; charset="utf-8" Removes the dom0 naming from variables and isolates control/hardware domain specific logic behind capabilities check. Signed-off-by: Daniel P. Smith --- xen/arch/x86/domain-builder/domain.c | 47 +++++++++++++++------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/xen/arch/x86/domain-builder/domain.c b/xen/arch/x86/domain-bui= lder/domain.c index a82c02250b4c..13f99111a3a9 100644 --- a/xen/arch/x86/domain-builder/domain.c +++ b/xen/arch/x86/domain-builder/domain.c @@ -216,7 +216,7 @@ struct domain *__init arch_create_dom( char *cmdline =3D NULL; size_t cmdline_size; unsigned int create_flags =3D 0; - struct xen_domctl_createdomain dom0_cfg =3D { + struct xen_domctl_createdomain dom_cfg =3D { .flags =3D IS_ENABLED(CONFIG_TBOOT) ? XEN_DOMCTL_CDF_s3_integrity = : 0, .max_evtchn_port =3D -1, .max_grant_frames =3D -1, @@ -232,11 +232,11 @@ struct domain *__init arch_create_dom( if ( opt_dom0_pvh || (bi->hyperlaunch_enabled && !(bd->mode & BUILD_MODE_PARAVIRT)) ) { - dom0_cfg.flags |=3D (XEN_DOMCTL_CDF_hvm | + dom_cfg.flags |=3D (XEN_DOMCTL_CDF_hvm | ((hvm_hap_supported() && !opt_dom0_shadow) ? XEN_DOMCTL_CDF_hap : 0)); =20 - dom0_cfg.arch.emulation_flags |=3D + dom_cfg.arch.emulation_flags |=3D XEN_X86_EMU_LAPIC | XEN_X86_EMU_IOAPIC | XEN_X86_EMU_VPCI; } =20 @@ -244,7 +244,7 @@ struct domain *__init arch_create_dom( { create_flags |=3D CDF_hardware; if ( iommu_enabled ) - dom0_cfg.flags |=3D XEN_DOMCTL_CDF_iommu; + dom_cfg.flags |=3D XEN_DOMCTL_CDF_iommu; } =20 if ( bd->domid =3D=3D DOMID_INVALID ) @@ -252,7 +252,7 @@ struct domain *__init arch_create_dom( bd->domid =3D get_initial_domain_id(); if ( bd->capabilities & BUILD_CAPS_CONTROL ) create_flags |=3D CDF_privileged | CDF_hardware; - d =3D domain_create(bd->domid, &dom0_cfg, + d =3D domain_create(bd->domid, &dom_cfg, pv_shim ? 0 : create_flags); if ( IS_ERR(d) ) panic("Error creating d%u: %ld\n", bd->domid, PTR_ERR(d)); @@ -279,25 +279,30 @@ struct domain *__init arch_create_dom( cmdline_cook(__va(bd->kernel->cmdline_pa),bi->loader), cmdline_size); =20 - if ( bi->kextra ) - /* kextra always includes exactly one leading space. */ - strlcat(cmdline, bi->kextra, cmdline_size); - - /* Append any extra parameters. */ - if ( skip_ioapic_setup && !strstr(cmdline, "noapic") ) - strlcat(cmdline, " noapic", cmdline_size); - - if ( (strlen(acpi_param) =3D=3D 0) && acpi_disabled ) + /* Params from Xen cmd line apply only to control/hardware doms */ + if ( bd->capabilities & (BUILD_CAPS_CONTROL | BUILD_CAPS_HARDWARE)= ) { - printk("ACPI is disabled, notifying Domain 0 (acpi=3Doff)\n"); - safe_strcpy(acpi_param, "off"); + if ( bi->kextra ) + /* kextra always includes exactly one leading space. */ + strlcat(cmdline, bi->kextra, cmdline_size); + + /* Append any extra parameters. */ + if ( skip_ioapic_setup && !strstr(cmdline, "noapic") ) + strlcat(cmdline, " noapic", cmdline_size); + + if ( (strlen(acpi_param) =3D=3D 0) && acpi_disabled ) + { + printk("ACPI is disabled, notifying Domain 0 (acpi=3Doff)\= n"); + safe_strcpy(acpi_param, "off"); + } + + if ( (strlen(acpi_param) !=3D 0) && !strstr(cmdline, "acpi=3D"= ) ) + { + strlcat(cmdline, " acpi=3D", cmdline_size); + strlcat(cmdline, acpi_param, cmdline_size); + } } =20 - if ( (strlen(acpi_param) !=3D 0) && !strstr(cmdline, "acpi=3D") ) - { - strlcat(cmdline, " acpi=3D", cmdline_size); - strlcat(cmdline, acpi_param, cmdline_size); - } bd->kernel->cmdline_pa =3D 0; bd->cmdline =3D cmdline; } --=20 2.30.2 From nobody Fri Oct 31 16:34:17 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=1745101293; cv=pass; d=zohomail.com; s=zohoarc; b=BSOHQFakILq6igkPEsvllhwhO0fpuCD7rVGHyogJiEGo873lO2n4e3Ss9pJNdLDC9G1iBdFztxQOfnaESzUDPCANCVCO7asj7B9cGVs4MJ9Ov1nOkWkdrN9WkSFiuHvT7KIwEmzLL0m4TWZQxq0PBk7NMVsfg+4NRoqkPdomc+Y= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745101293; 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=ErU8vuQ7J87fC+REu5nsdOrzqMN/uQj7jaoh0kca6jQ=; b=kH5yPJh+gnvQmDMSq+59Uc/QlNHPo5uiQ8UWiz/gsrQ9K3CQbfzSUQWZdbLsxzGrivbjvpuGqrVgexGmNXBzGWe21ZmJM5LCUeqkvRyd3+bGZM9eeCX4MdX9N4r3ozTzdrIYvpuKEWhLuBHZTghIEspRp2f0TAg7NZbT7XxlnmE= 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 1745101293821427.9156058759181; Sat, 19 Apr 2025 15:21:33 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.960237.1352315 (Exim 4.92) (envelope-from ) id 1u6GYp-0003O5-7Q; Sat, 19 Apr 2025 22:21:19 +0000 Received: by outflank-mailman (output) from mailman id 960237.1352315; Sat, 19 Apr 2025 22:21: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 1u6GYo-0003Lz-QS; Sat, 19 Apr 2025 22:21:18 +0000 Received: by outflank-mailman (input) for mailman id 960237; Sat, 19 Apr 2025 22:21:17 +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 1u6GQa-0004yY-Es for xen-devel@lists.xenproject.org; Sat, 19 Apr 2025 22:12:48 +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 6c1f3d9a-1d6b-11f0-9eb0-5ba50f476ded; Sun, 20 Apr 2025 00:12:47 +0200 (CEST) Received: by mx.zohomail.com with SMTPS id 1745100552055701.4359410353334; Sat, 19 Apr 2025 15:09:12 -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: 6c1f3d9a-1d6b-11f0-9eb0-5ba50f476ded ARC-Seal: i=1; a=rsa-sha256; t=1745100554; cv=none; d=zohomail.com; s=zohoarc; b=Pi5BETfqw22ls3M0dj/Fc9zbpkxZYOYO0Ys+U9C99s/UY5NuARj9msv0te8TZvdQ4YQEJepkp0Lh5caBXjSTgD+8cssYjNn818Ra5fzOvsuQ3L1PFSS2Lrnuk7LQrwkaFvvAT2gkZTptsZcfrKqc3E0tUxZRCy0+900I9/NtJ8E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100554; 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=ErU8vuQ7J87fC+REu5nsdOrzqMN/uQj7jaoh0kca6jQ=; b=TVW4abfNNk+4TTncybXwfIH8nIcwpmgRDmsMVmdLaZcQFpdP7kSlnDjJQbPVjfiMr9gCOL+7XRy7h3j0DNHHaEpd+e8V8OiuRF3+ACQcBc6fiLCVpBJvJH4Z9Bg0kPrJGTKjEz3T0XxFzNU11TIko3GoMeGmqNDBiteMFaPsBCo= 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=1745100554; 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=ErU8vuQ7J87fC+REu5nsdOrzqMN/uQj7jaoh0kca6jQ=; b=vezoF10khKIC1HNu4QNYl20h7IXUDCZJLJPS1LWcA1pre8zEF6vDZoLf2at6n15B h6vSOc6nY/7USaAhlG3e6B06KeGfkosDYtmtwL3unr8TH/Ubp/ZtcQtz3myTkvJNEJk ISZrDmDb0CDDiT8VL0N4kbhWrSmEujQDETsBaHaM= 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 27/38] x86/hyperlaunch: introduce domain builder general dom creation Date: Sat, 19 Apr 2025 18:08:09 -0400 Message-Id: <20250419220820.4234-28-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: 1745101295147019000 Content-Type: text/plain; charset="utf-8" Introduce the builder_create_domains() function that provides the domain construciton abstraction for the hyperlaunch domain builder. Signed-off-by: Daniel P. Smith --- xen/arch/x86/domain-builder/core.c | 17 +++++++++++++++ xen/arch/x86/include/asm/bootinfo.h | 26 +++++++++++++++++++++++ xen/arch/x86/include/asm/domain-builder.h | 1 + xen/arch/x86/setup.c | 23 +++++++++++++++++--- 4 files changed, 64 insertions(+), 3 deletions(-) diff --git a/xen/arch/x86/domain-builder/core.c b/xen/arch/x86/domain-build= er/core.c index 8d137ecaaf84..2f0b8bd82c3a 100644 --- a/xen/arch/x86/domain-builder/core.c +++ b/xen/arch/x86/domain-builder/core.c @@ -9,6 +9,7 @@ =20 #include #include +#include =20 #include "fdt.h" =20 @@ -102,6 +103,22 @@ void __init builder_init(struct boot_info *bi) } } =20 +unsigned int __init builder_create_domains(struct boot_info *bi) +{ + unsigned int build_count =3D 0; + struct boot_domain *bd =3D &bi->domains[0]; + + if ( bd->kernel =3D=3D NULL && bd->capabilities & BUILD_CAPS_CONTROL ) + panic("%s: control domain missing kernel\n", __func__); + + + arch_create_dom(bi, bd); + if ( bd->d ) + build_count++; + + return build_count; +} + /* * Local variables: * mode: C diff --git a/xen/arch/x86/include/asm/bootinfo.h b/xen/arch/x86/include/asm= /bootinfo.h index 5b2c93b1ef9e..430ae08cf5ef 100644 --- a/xen/arch/x86/include/asm/bootinfo.h +++ b/xen/arch/x86/include/asm/bootinfo.h @@ -132,6 +132,32 @@ static inline unsigned int __init next_boot_module_ind= ex( (i) <=3D (b)->nr_modules; \ (i) =3D next_boot_module_index(b, t, i + 1) ) =20 +/* + * next_boot_domain_index: + * Finds the next boot domain with capability cap, starting at array i= ndex + * start. + * + * Returns: + * Success - index in boot_domains array + * Failure - a value greater than MAX_NR_BOOTDOMS + */ +static inline unsigned int __init next_boot_domain_index( + const struct boot_info *bi, uint32_t cap, unsigned int start) +{ + int i; + + for ( i =3D start; i < bi->nr_domains; i++ ) + { + if ( bi->domains[i].capabilities & cap ) + return i; + } + + return MAX_NR_BOOTDOMS + 1; +} + +#define first_boot_domain_index(bi, cap) \ + next_boot_domain_index(bi, cap, 0) + #endif /* X86_BOOTINFO_H */ =20 /* diff --git a/xen/arch/x86/include/asm/domain-builder.h b/xen/arch/x86/inclu= de/asm/domain-builder.h index ccab02c3a1fd..5dc5661bec07 100644 --- a/xen/arch/x86/include/asm/domain-builder.h +++ b/xen/arch/x86/include/asm/domain-builder.h @@ -8,6 +8,7 @@ int __init builder_get_cmdline( struct boot_info *bi, int offset, char *cmdline, size_t size); =20 void builder_init(struct boot_info *bi); +unsigned int builder_create_domains(struct boot_info *bi); =20 struct domain *arch_create_dom( struct boot_info *bi, struct boot_domain *bd); diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 8f956b6eca4f..da5a8e8d8ed3 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -2015,9 +2015,26 @@ void asmlinkage __init noreturn __start_xen(void) * We're going to setup domain0 using the module(s) that we stashed sa= fely * above our heap. The second module, if present, is an initrd ramdisk. */ - dom0 =3D arch_create_dom(bi, &bi->domains[0]); - if ( !dom0 ) - panic("Could not set up DOM0 guest OS\n"); + ret =3D builder_create_domains(bi); + if ( ret <=3D 0 ) + panic("Could not set up boot-time domains\n"); + else + printk(XENLOG_INFO "Constructed %d boot-time domains\n", ret); + + /* Selection order: hardware domain, control domain, first domain */ + i =3D first_boot_domain_index(bi, BUILD_CAPS_HARDWARE); + if ( i >=3D MAX_NR_BOOTDOMS ) + { + i =3D first_boot_domain_index(bi, BUILD_CAPS_CONTROL); + if ( i >=3D MAX_NR_BOOTDOMS ) + { + printk(XENLOG_WARNING + "A hwdom/ctrldom not detected, using 0th domain\n"); + i =3D 0; + } + } + + dom0 =3D bi->domains[i].d; =20 heap_init_late(); =20 --=20 2.30.2 From nobody Fri Oct 31 16:34:17 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=1745100805; cv=pass; d=zohomail.com; s=zohoarc; b=dQzGz+MDB3A3+53U55yGUOYTEJTRSzFcgJCLqF6v2rqN3vjFkIr/nDV/LNKq4gORvor6/28SQWfsxKvYyWfTsxrqyeuTFE1yWxMZm7yihlVzZfpmDLftT+4PnZ9hLBGLkOobbPJmjwwBqZTDXhLogdTdHQ3i919rOLv5gWiOIKQ= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100805; 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=5FUmF1YRY9NDE1umkBI15/zKKYB7vvic5T3QpbucTJ0=; b=DMCDlpien1gaZuLLacPurkTP7FzfslcuZmshVAD+1IdVduP9hMljpy2ahji6SzfkoYZofK9CO8UwotAyGtyg0WWg66Kk5ncZ8qs3ZXJ6A96TMUXNxJEKutV3V3pI2cs8mPcOpVWJ+e+gS6wV1yiyWn0QU2uVXNpl2+ow0Ql8V/U= 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 1745100805474575.4060451639574; Sat, 19 Apr 2025 15:13:25 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.960114.1352202 (Exim 4.92) (envelope-from ) id 1u6GQz-0004p9-TN; Sat, 19 Apr 2025 22:13:13 +0000 Received: by outflank-mailman (output) from mailman id 960114.1352202; Sat, 19 Apr 2025 22:13:13 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u6GQz-0004p0-QE; Sat, 19 Apr 2025 22:13:13 +0000 Received: by outflank-mailman (input) for mailman id 960114; Sat, 19 Apr 2025 22:13:12 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u6GQy-0004oZ-Ku for xen-devel@lists.xenproject.org; Sat, 19 Apr 2025 22:13:12 +0000 Received: from sender4-of-o50.zoho.com (sender4-of-o50.zoho.com [136.143.188.50]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 79c93cdc-1d6b-11f0-9ffb-bf95429c2676; Sun, 20 Apr 2025 00:13:10 +0200 (CEST) Received: by mx.zohomail.com with SMTPS id 1745100552863208.68927810979392; Sat, 19 Apr 2025 15:09:12 -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: 79c93cdc-1d6b-11f0-9ffb-bf95429c2676 ARC-Seal: i=1; a=rsa-sha256; t=1745100556; cv=none; d=zohomail.com; s=zohoarc; b=LHcEECMDjJj3dC1RqieD9Wr7XiwZxrVMvdlaLg9Xxgx0jSazAiWW/miGr06eWR1/1dwfR3RWIwelv+cIxcij2O7HGraU0P5T86QKyMfnxBEXNkLh5vfr+qL2J7kMDmsKHvCze6woX6nCxuwTYZFq0H9MvtOo6VLAQ2JzIwsyqYY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100556; 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=5FUmF1YRY9NDE1umkBI15/zKKYB7vvic5T3QpbucTJ0=; b=fzTYjYL1wH7w0gBmq5H0mV1sJyq3I/1Gxg02/oKnjCFM4mGp/+mBhvQuzkcEQI2+SOQ9eGqP5hYnnDeX7JwwK6Ua+EjlMbvo/37y8aQvBF9Wwv8ew3Ue46ZlxEkWzMW/f3Z8QATAI62VeJeZ3/5grvll3s0oPqJBTp0XxSxv5Bk= 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=1745100556; 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=5FUmF1YRY9NDE1umkBI15/zKKYB7vvic5T3QpbucTJ0=; b=Oj9T8XhxwGoAp7n/4JvkPILnnCIQ6wc4eL+RcluTNx36iQLN4CXQl2pOc1y8rq1N vnWz81HiJA9PPTxzfcYQ3WFpnczBiEDBaNigwJc9sjOEC3tEFQXyrUI+MtwMa0hjqWZ 1aFTz+Od1BWHjUYqhawfx3lQU3KOopzkQU7dbt8U= 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 28/38] x86/hyperlaunch: add xenstore boot capabilities flag Date: Sat, 19 Apr 2025 18:08:10 -0400 Message-Id: <20250419220820.4234-29-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: 1745100805864019000 Content-Type: text/plain; charset="utf-8" Add the ability to designate a domain as the Xenstore domain via the hyperlaunch configuration. Signed-off-by: Daniel P. Smith --- xen/arch/x86/domain-builder/core.c | 2 +- xen/arch/x86/domain-builder/domain.c | 2 ++ xen/arch/x86/domain-builder/fdt.c | 2 ++ xen/arch/x86/include/asm/boot-domain.h | 1 + 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/domain-builder/core.c b/xen/arch/x86/domain-build= er/core.c index 2f0b8bd82c3a..e21f5efbfe62 100644 --- a/xen/arch/x86/domain-builder/core.c +++ b/xen/arch/x86/domain-builder/core.c @@ -98,7 +98,7 @@ void __init builder_init(struct boot_info *bi) bi->mods[i].type =3D BOOTMOD_KERNEL; bi->domains[0].kernel =3D &bi->mods[i]; bi->domains[0].capabilities |=3D - (BUILD_CAPS_CONTROL | BUILD_CAPS_HARDWARE); + (BUILD_CAPS_CONTROL | BUILD_CAPS_HARDWARE | BUILD_CAPS_XENSTOR= E); bi->nr_domains =3D 1; } } diff --git a/xen/arch/x86/domain-builder/domain.c b/xen/arch/x86/domain-bui= lder/domain.c index 13f99111a3a9..c1b2e011aaa0 100644 --- a/xen/arch/x86/domain-builder/domain.c +++ b/xen/arch/x86/domain-builder/domain.c @@ -250,6 +250,8 @@ struct domain *__init arch_create_dom( if ( bd->domid =3D=3D DOMID_INVALID ) /* Create initial domain. Not d0 for pvshim. */ bd->domid =3D get_initial_domain_id(); + if ( bd->capabilities & BUILD_CAPS_XENSTORE ) + dom_cfg.flags |=3D XEN_DOMCTL_CDF_xs_domain; if ( bd->capabilities & BUILD_CAPS_CONTROL ) create_flags |=3D CDF_privileged | CDF_hardware; d =3D domain_create(bd->domid, &dom_cfg, diff --git a/xen/arch/x86/domain-builder/fdt.c b/xen/arch/x86/domain-builde= r/fdt.c index 1af58ed4eb86..9c6c0ae09a24 100644 --- a/xen/arch/x86/domain-builder/fdt.c +++ b/xen/arch/x86/domain-builder/fdt.c @@ -269,6 +269,8 @@ static int __init process_domain_node( printk("c"); if ( bd->capabilities & BUILD_CAPS_HARDWARE ) printk(" h"); + if ( bd->capabilities & BUILD_CAPS_XENSTORE ) + printk(" x"); printk("\n"); } } diff --git a/xen/arch/x86/include/asm/boot-domain.h b/xen/arch/x86/include/= asm/boot-domain.h index 18d144de2fea..32f1f8fbc4e8 100644 --- a/xen/arch/x86/include/asm/boot-domain.h +++ b/xen/arch/x86/include/asm/boot-domain.h @@ -16,6 +16,7 @@ struct boot_domain { #define BUILD_CAPS_NONE (0) #define BUILD_CAPS_CONTROL (1 << 0) #define BUILD_CAPS_HARDWARE (1 << 1) +#define BUILD_CAPS_XENSTORE (1 << 2) uint32_t capabilities; =20 /* On | Off */ --=20 2.30.2 From nobody Fri Oct 31 16:34:17 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=1745101267; cv=pass; d=zohomail.com; s=zohoarc; b=YBCmOiLw8W9OlUhm3TkDJRQe781tIJpWxRknYfoE5SArwr7kRm9JF5awn1MB7xq1TowlGcwRRCSVuHmdQ49W+C0gxCiyp0vSHLSo1owr/GcoqkYoXuY9hST/eW4Zn67fl5W9uTBSeGhLysERqAXomqYJfb5DBIaOs9Ip7u1oQ0I= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745101267; 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=OMaTtguVsoafCK0lkNIJcl8+/3XaPHmXDwj/NHsEKbc=; b=WQvXB3YcF289CIqxVBUxvySwXbKs0muu6SBxjNA6JCLQhnRS0i10ML3o2arg0avMILOOO6l9kz3cfbgJc5Yt6Uf6xPepXNrq0QoyXArnv37+3pPpHP425/2JcNpZeoLJYiGK0SB5uP1pzSnQfXmnMXFqPkhxJ0DspAAoRDjehMg= 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 1745101267010175.8778839800873; Sat, 19 Apr 2025 15:21:07 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.960172.1352252 (Exim 4.92) (envelope-from ) id 1u6GYM-0000KF-JX; Sat, 19 Apr 2025 22:20:50 +0000 Received: by outflank-mailman (output) from mailman id 960172.1352252; Sat, 19 Apr 2025 22:20: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 1u6GYM-0000K6-Gl; Sat, 19 Apr 2025 22:20:50 +0000 Received: by outflank-mailman (input) for mailman id 960172; Sat, 19 Apr 2025 22:20:49 +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 1u6GQp-0004yY-8Y for xen-devel@lists.xenproject.org; Sat, 19 Apr 2025 22:13:03 +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 74ecc5bd-1d6b-11f0-9eb0-5ba50f476ded; Sun, 20 Apr 2025 00:13:02 +0200 (CEST) Received: by mx.zohomail.com with SMTPS id 1745100553667313.49112890011975; Sat, 19 Apr 2025 15:09:13 -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: 74ecc5bd-1d6b-11f0-9eb0-5ba50f476ded ARC-Seal: i=1; a=rsa-sha256; t=1745100556; cv=none; d=zohomail.com; s=zohoarc; b=QzgX0Y8mWmsz+AsIiWp0nfAjtW0zaD5vB/KouKf3Hf/K464Etr0B32nW8ChHLUIXQ+gkP7ESDKwHvCoZ4O4QYeFQFLiKRdsXaS2sZQVrEE1Rc6nS5dsdlYzeP35AuPHLK/+A2tB4ejwEyjck6P6gkwdogo5qxn1crJLU2Tq7Pe8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100556; 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=OMaTtguVsoafCK0lkNIJcl8+/3XaPHmXDwj/NHsEKbc=; b=Hws8dTO1HmPHgoq6VRIpLLm1V3Swu8XS2TR3Zvv8RSHVkoocqdM1HXimczkcegYwG1F5yCkeDgiJyt4P1QbltD2H57Du44+wWBYRHj2ngi7kjeAH9hNB0mdbw5XsSkLYEnBRjTnR8rGouh52lpyh8mw5InyG/QnG0k5Qz6qJjSI= 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=1745100556; 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=OMaTtguVsoafCK0lkNIJcl8+/3XaPHmXDwj/NHsEKbc=; b=N+ctCWMWQA/vKEzT1Kw1DAvVeChBN6YzmEzDbWw7TI8jdlUFpCFBnu77ea2liOOY 5B2n+bDZQ5UJbmUqKXNZxVavzb9OczjkaH5Vd4YSSRTEWMTSLFLWQQDEdRBFQMpYro+ Tu+stkeUTiHvlL+uz984k83XwkvfgLRwltcwpW38= 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 29/38] x86/hyperlaunch: allocate console for domu Date: Sat, 19 Apr 2025 18:08:11 -0400 Message-Id: <20250419220820.4234-30-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: 1745101269098019000 Content-Type: text/plain; charset="utf-8" During domU construction, a page of memory and an event channel must be set= up for the console connection. In this commit, a page from the special page re= gion of domU is setup as the console page along with an event channel. The page address and event channel are published in the HVM parameters, so they may = be published in Xenstore once it is online. Signed-off-by: Daniel P. Smith --- xen/arch/x86/domain-builder/domain.c | 56 ++++++++++++++++++++++++++ xen/arch/x86/hvm/dom_build.c | 34 ++++++++++++++++ xen/arch/x86/include/asm/boot-domain.h | 7 ++++ 3 files changed, 97 insertions(+) diff --git a/xen/arch/x86/domain-builder/domain.c b/xen/arch/x86/domain-bui= lder/domain.c index c1b2e011aaa0..7ce069a57c5d 100644 --- a/xen/arch/x86/domain-builder/domain.c +++ b/xen/arch/x86/domain-builder/domain.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -187,6 +188,58 @@ void __init alloc_dom_vcpus(struct domain *d) domain_update_node_affinity(d); } =20 +static int __init alloc_dom_evtchn( + const struct boot_domain *d, const struct boot_domain *r, + evtchn_alloc_unbound_t *ec) +{ + int rc; + + ec->dom =3D d->domid; + ec->remote_dom =3D r->domid; + + rc =3D evtchn_alloc_unbound(ec, 0); + if ( rc ) + { + printk(XENLOG_WARNING "Failed allocating event channel for %pd\n", + d->d); + return rc; + } + + return 0; +} + +static int __init alloc_console_evtchn( + const struct boot_info *bi, struct boot_domain *bd) +{ + evtchn_alloc_unbound_t evtchn_req; + const struct boot_domain *hwdom; + int idx, rc; + + idx =3D first_boot_domain_index(bi, BUILD_CAPS_HARDWARE); + if ( idx < 0 ) + { + printk(XENLOG_WARNING "No backing hardware domain for %pd console\= n", + bd->d); + return -EINVAL; + } + + if ( bi->domains[idx].d ) + hwdom =3D &bi->domains[idx]; + else + { + printk(XENLOG_WARNING "Hardware domain for %pd console not constru= cted\n", + bd->d); + return -EINVAL; + } + + if ( (rc =3D alloc_dom_evtchn(bd, hwdom, &evtchn_req)) < 0 ) + return rc; + + bd->console.evtchn =3D evtchn_req.port; + + return 0; +} + static size_t __init domain_cmdline_size( struct boot_info *bi, struct boot_domain *bd) { @@ -309,6 +362,9 @@ struct domain *__init arch_create_dom( bd->cmdline =3D cmdline; } =20 + if ( !(bd->capabilities & BUILD_CAPS_HARDWARE) ) + alloc_console_evtchn(bi, bd); + if ( construct_dom0(bd) !=3D 0 ) panic("Could not construct domain 0\n"); =20 diff --git a/xen/arch/x86/hvm/dom_build.c b/xen/arch/x86/hvm/dom_build.c index c482d5c2d974..934ae138e58f 100644 --- a/xen/arch/x86/hvm/dom_build.c +++ b/xen/arch/x86/hvm/dom_build.c @@ -9,6 +9,7 @@ */ =20 #include +#include #include #include #include @@ -19,6 +20,7 @@ #include #include #include +#include =20 #include #include @@ -899,6 +901,35 @@ static int __init pvh_load_kernel( return 0; } =20 +static int __init alloc_console_page(struct boot_domain *bd) +{ + paddr_t con_addr =3D special_pfn(SPECIALPAGE_CONSOLE) << PAGE_SHIFT; + uint32_t fields[4] =3D { 0 }; + + if ( !port_is_valid(bd->d, bd->console.evtchn) ) + { + printk("No event channel available for %pd console\n", bd->d); + return -EINVAL; + } + + /* + * Clear the xencons_interface fields that are located after a 1024 rx= and + * a 2048 tx buffer, 3072 bytes. + */ + if ( hvm_copy_to_guest_phys(con_addr + 3072, fields, sizeof(fields), + bd->d->vcpu[0]) ) + { + printk("Unable to set xenstore connection state\n"); + return -EFAULT; + } + + bd->console.gfn =3D PFN_DOWN(con_addr); + bd->d->arch.hvm.params[HVM_PARAM_CONSOLE_PFN] =3D bd->console.gfn; + bd->d->arch.hvm.params[HVM_PARAM_CONSOLE_EVTCHN] =3D bd->console.evtch= n; + + return 0; +} + int __init dom_construct_pvh(struct boot_domain *bd) { paddr_t entry, start_info; @@ -975,6 +1006,9 @@ int __init dom_construct_pvh(struct boot_domain *bd) return rc; } =20 + if ( !is_hardware_domain(bd->d) ) + alloc_console_page(bd); + if ( opt_dom0_verbose ) { printk("Dom%u memory map:\n", bd->domid); diff --git a/xen/arch/x86/include/asm/boot-domain.h b/xen/arch/x86/include/= asm/boot-domain.h index 32f1f8fbc4e8..cb6e1fab23ba 100644 --- a/xen/arch/x86/include/asm/boot-domain.h +++ b/xen/arch/x86/include/asm/boot-domain.h @@ -5,6 +5,9 @@ * Copyright (c) 2024 Christopher Clark */ =20 +#include +#include + #ifndef __XEN_X86_BOOTDOMAIN_H__ #define __XEN_X86_BOOTDOMAIN_H__ =20 @@ -35,6 +38,10 @@ struct boot_domain { const char *cmdline; =20 struct domain *d; + struct { + xen_pfn_t gfn; + evtchn_port_t evtchn; + } console; }; =20 #endif --=20 2.30.2 From nobody Fri Oct 31 16:34:17 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=1745101301; cv=pass; d=zohomail.com; s=zohoarc; b=jD6VCe9kCDz97gmcy0OzI0/tIgfxU0qbrwkpiwZdTX4BVulL9BtsjS/avXsuvYlx6Gi7cAxfCRqXgAoNa6jUAgoBZ8hIHhLzf0hE4LsCDMU7wZUSEl6mGt9Owy33uIkklqzUpErXiUT00UDRjj8LluQNOWh350XneMrhDrRksUI= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745101301; 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=xTTdPfDolfNjAS0Qvmz0FxzFVp9V69k5pb2zgYetYhg=; b=Q8dskTJcPcsu/57m3Z+Vo3VxBNXko2gurOLToUQ7+mQ1QQsRwntR03FsCD9PwHFB3Y3VIh3SxzwNrWKgisJjDuMUjltc0KB6SPNUwI1uIu9bFApVavU3cPsj474BPW9h8r4lfZxRHNr4zKErF4wuOM+Tpqifc4mvKhic/B9ICrU= 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 1745101301949865.934882155963; Sat, 19 Apr 2025 15:21:41 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.960252.1352334 (Exim 4.92) (envelope-from ) id 1u6GYu-0004Sn-TG; Sat, 19 Apr 2025 22:21:24 +0000 Received: by outflank-mailman (output) from mailman id 960252.1352334; Sat, 19 Apr 2025 22:21:24 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u6GYu-0004SO-Iy; Sat, 19 Apr 2025 22:21:24 +0000 Received: by outflank-mailman (input) for mailman id 960252; Sat, 19 Apr 2025 22:21:23 +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 1u6GRT-0004yY-T6 for xen-devel@lists.xenproject.org; Sat, 19 Apr 2025 22:13:43 +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 8cf644d5-1d6b-11f0-9eb0-5ba50f476ded; Sun, 20 Apr 2025 00:13:42 +0200 (CEST) Received: by mx.zohomail.com with SMTPS id 1745100563151665.1808490006621; Sat, 19 Apr 2025 15:09:23 -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: 8cf644d5-1d6b-11f0-9eb0-5ba50f476ded ARC-Seal: i=1; a=rsa-sha256; t=1745100571; cv=none; d=zohomail.com; s=zohoarc; b=anWjUrDEW6/RaRHcc8BAKESuY1HNFS30V8ANqIDZoiceXVZn27xsv2RbJGuRHjZ0IaHMwVcRu+7zVHlohroibwI22bER1d9BKQ7UmDclWChyY9EIMIqYzJx3bcF8Ub6dIFllkJMVDwY9r8kMt1rizFTKJ9Xgl0TtBN96UMxFTEQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100571; 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=xTTdPfDolfNjAS0Qvmz0FxzFVp9V69k5pb2zgYetYhg=; b=PI1y5fbyqhMuuMmwVBO8UJrEUHmh4QVtiKXtKZhnR+yLI2gVTRsAGHtg/UaQ9XUMqwPw+NE/Oq77sRiKnZl4hcuH0BpDY1Cd57xEZCsZ0WEEzgnLybG0nUozddfdJsiKEVuv6O0uej/qnY/vNbEo3qWTOpxVUwB6SnQNoHiVtes= 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=1745100571; 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=xTTdPfDolfNjAS0Qvmz0FxzFVp9V69k5pb2zgYetYhg=; b=a0ooV0zfRFp3A8MxgK6mqydxzeHTgOL5Q1RQyvzbHmvHexjOjiQzhaq1hgEwkBoq lXkTx2EcQsmi6a2xkWAmCTooNLxvsARFZ1rA+kwhdlmH2BOk76lJMGc8OmUH+3Lz5Nb 194UsoKNenheT+hrBN0Fc6rWTHN0n8zgjf7uNGgo= 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 30/38] x86/hyperlaunch: allocate xenstore for domu Date: Sat, 19 Apr 2025 18:08:12 -0400 Message-Id: <20250419220820.4234-31-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: 1745101303405019000 Content-Type: text/plain; charset="utf-8" During domU construction, a page of memory and an event channel must be set= up for xenstore connection. In this commit, a page from the special page regio= n of domU is setup as the xenstore page along with an event channel. The page address and event channel are published in the HVM parameters, so the domain can be announced to Xenstore. Signed-off-by: Daniel P. Smith --- xen/arch/x86/domain-builder/domain.c | 38 ++++++++++++++++++++++++-- xen/arch/x86/hvm/dom_build.c | 32 ++++++++++++++++++++++ xen/arch/x86/include/asm/boot-domain.h | 2 +- 3 files changed, 69 insertions(+), 3 deletions(-) diff --git a/xen/arch/x86/domain-builder/domain.c b/xen/arch/x86/domain-bui= lder/domain.c index 7ce069a57c5d..b413a87cc9c9 100644 --- a/xen/arch/x86/domain-builder/domain.c +++ b/xen/arch/x86/domain-builder/domain.c @@ -240,6 +240,38 @@ static int __init alloc_console_evtchn( return 0; } =20 +static int __init alloc_store_evtchn( + const struct boot_info *bi, struct boot_domain *bd) +{ + evtchn_alloc_unbound_t evtchn_req; + const struct boot_domain *xsdom; + int idx, rc; + + idx =3D first_boot_domain_index(bi, BUILD_CAPS_XENSTORE); + if ( idx < 0 ) + { + printk(XENLOG_WARNING "No backing xenstore domain for %pdv\n", + bd->d); + return -EINVAL; + } + + if ( bi->domains[idx].d ) + xsdom =3D &bi->domains[idx]; + else + { + printk(XENLOG_WARNING "Xenstore domain for %pd console not constru= cted\n", + bd->d); + return -EINVAL; + } + + if ( (rc =3D alloc_dom_evtchn(bd, xsdom, &evtchn_req)) < 0 ) + return rc; + + bd->store.evtchn =3D evtchn_req.port; + + return 0; +} + static size_t __init domain_cmdline_size( struct boot_info *bi, struct boot_domain *bd) { @@ -362,8 +394,10 @@ struct domain *__init arch_create_dom( bd->cmdline =3D cmdline; } =20 - if ( !(bd->capabilities & BUILD_CAPS_HARDWARE) ) - alloc_console_evtchn(bi, bd); + if ( !(bd->capabilities & BUILD_CAPS_XENSTORE) ) + alloc_store_evtchn(bi, bd); + if ( !(bd->capabilities & BUILD_CAPS_HARDWARE) ) + alloc_console_evtchn(bi, bd); =20 if ( construct_dom0(bd) !=3D 0 ) panic("Could not construct domain 0\n"); diff --git a/xen/arch/x86/hvm/dom_build.c b/xen/arch/x86/hvm/dom_build.c index 934ae138e58f..2798542e5483 100644 --- a/xen/arch/x86/hvm/dom_build.c +++ b/xen/arch/x86/hvm/dom_build.c @@ -930,6 +930,35 @@ static int __init alloc_console_page(struct boot_domai= n *bd) return 0; } =20 +static int __init alloc_xenstore_page(struct boot_domain *bd) +{ + paddr_t xs_addr =3D special_pfn(SPECIALPAGE_XENSTORE) << PAGE_SHIFT; + uint32_t fields[7] =3D { 0, 0, 0, 0, 0, 1, 0}; + + if ( !port_is_valid(bd->d, bd->store.evtchn) ) + { + printk("No event channel available for %pd xenstore\n", bd->d); + return -EINVAL; + } + + /* + * Set connection field to XENSTORE_RECONNECT, where the + * xenstore_domain_interface fields are located after the 2 1024 buffe= rs + */ + if ( hvm_copy_to_guest_phys(xs_addr + 2048, fields, sizeof(fields), + bd->d->vcpu[0]) ) + { + printk("Unable to set xenstore connection state\n"); + return -EFAULT; + } + + bd->store.gfn =3D gfn_x(gaddr_to_gfn(xs_addr)); + bd->d->arch.hvm.params[HVM_PARAM_STORE_PFN] =3D bd->store.gfn; + bd->d->arch.hvm.params[HVM_PARAM_STORE_EVTCHN] =3D bd->store.evtchn; + + return 0; +} + int __init dom_construct_pvh(struct boot_domain *bd) { paddr_t entry, start_info; @@ -1009,6 +1038,9 @@ int __init dom_construct_pvh(struct boot_domain *bd) if ( !is_hardware_domain(bd->d) ) alloc_console_page(bd); =20 + if ( !is_xenstore_domain(bd->d) ) + alloc_xenstore_page(bd); + if ( opt_dom0_verbose ) { printk("Dom%u memory map:\n", bd->domid); diff --git a/xen/arch/x86/include/asm/boot-domain.h b/xen/arch/x86/include/= asm/boot-domain.h index cb6e1fab23ba..df2bfa0c94fa 100644 --- a/xen/arch/x86/include/asm/boot-domain.h +++ b/xen/arch/x86/include/asm/boot-domain.h @@ -41,7 +41,7 @@ struct boot_domain { struct { xen_pfn_t gfn; evtchn_port_t evtchn; - } console; + } console, store; }; =20 #endif --=20 2.30.2 From nobody Fri Oct 31 16:34:17 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=1745100826; cv=pass; d=zohomail.com; s=zohoarc; b=cIQNXFCTQQM7zQFZedArlHWBjDu7WuSbBpUpPXK+U4uiFi3QLY2UqxNq8DQZ10pCUC4P0WxZ697Ts3TItfkRbyTSl6KC1A7d1B/vy/+P6AyvSuPVyvC7OiT2FCbZl1QETjdj0ymeJtkCAjksB+IJBDpCmoROFw+UIGsKtUzrlPw= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100826; 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=DQEG8mIjNUEnBFfKy/NUA5oCT0cynfg6veEbEk7wCvA=; b=ifqKYM/aidys6NpZ7xhN04Hl9l1/2+3RFdUgUYhm8qtTEvGyIMFy3+9mhb2Nw5ckeu0/soIBmPxvyQ2tyzF75FNJDH8e4q+Pgo2TvRQRAd/ZYps1QHlxNGOnifZjxQmR1EQxVuSgVLf11FK7g9Ma15xSRrr+NIXnORxWVP3Bh9g= 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 1745100826814979.079198322569; Sat, 19 Apr 2025 15:13:46 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.960124.1352233 (Exim 4.92) (envelope-from ) id 1u6GRM-0005wP-Jm; Sat, 19 Apr 2025 22:13:36 +0000 Received: by outflank-mailman (output) from mailman id 960124.1352233; Sat, 19 Apr 2025 22:13:36 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u6GRM-0005vl-Gq; Sat, 19 Apr 2025 22:13:36 +0000 Received: by outflank-mailman (input) for mailman id 960124; Sat, 19 Apr 2025 22:13:35 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u6GRL-0004oZ-Sp for xen-devel@lists.xenproject.org; Sat, 19 Apr 2025 22:13:35 +0000 Received: from sender4-of-o50.zoho.com (sender4-of-o50.zoho.com [136.143.188.50]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 87e8e708-1d6b-11f0-9ffb-bf95429c2676; Sun, 20 Apr 2025 00:13:34 +0200 (CEST) Received: by mx.zohomail.com with SMTPS id 1745100564099317.7051324884495; Sat, 19 Apr 2025 15:09:24 -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: 87e8e708-1d6b-11f0-9ffb-bf95429c2676 ARC-Seal: i=1; a=rsa-sha256; t=1745100571; cv=none; d=zohomail.com; s=zohoarc; b=ACFX41L7aYz26PiP6maGudGgR0vSKrM9BZh+cxVP9DokHpRGb11saJoTLwY+riTWZ/3lttDGtj7Wee23bsfMaDKHb0JGfHDONCkjT032rem08ghPN0yryofM8YO5+fyfizxgCNwPSNf0eyDUqqFaj5vt+PuAxN7PD687bNtBlZE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100571; 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=DQEG8mIjNUEnBFfKy/NUA5oCT0cynfg6veEbEk7wCvA=; b=XtRj1fE1S+3oSdcgO5sH9TkC3OSk/HLsOc3XQ/jaunuJMdvyodkphu6hYBTVtz8ZH7f1JuPXctBW99t15Kt0uH8ERrqZZNJ1V8fV9kpgoiKcpUWuStXO8/SEIeOGXMRM/t8tQIfn+ymn3ZERFQxXsfreG97RobxlZsKdJBxRDz8= 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=1745100571; 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=DQEG8mIjNUEnBFfKy/NUA5oCT0cynfg6veEbEk7wCvA=; b=apSo9iKutTJzbuPWj4NB1FYsAQ7yfqohRdp8HQDepjzF4aMhbD29Ybf1h/xFpRw0 YBfP0sXkt7YcQruh9mriCb94Na9C+II3wZ+aeFhmuaJp0svyN79WZ/2vj8ofN2UUzQl 1m4jKFpQbMlvhDHeqFbQc+xez9nludp0Ysaj8UWw= 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 31/38] x86/hyperlaunch: move boot module discard to domain builder Date: Sat, 19 Apr 2025 18:08:13 -0400 Message-Id: <20250419220820.4234-32-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: 1745100828253019100 Content-Type: text/plain; charset="utf-8" Relocate the call to discard boot modules from inside the domain construction logic to the top level domain builder. This will ensure modules are not discarded until after all domains have been constructed. Signed-off-by: Daniel P. Smith --- xen/arch/x86/domain-builder/core.c | 5 ++++- xen/arch/x86/hvm/dom_build.c | 3 --- xen/arch/x86/pv/dom0_build.c | 3 --- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/xen/arch/x86/domain-builder/core.c b/xen/arch/x86/domain-build= er/core.c index e21f5efbfe62..901efce62a61 100644 --- a/xen/arch/x86/domain-builder/core.c +++ b/xen/arch/x86/domain-builder/core.c @@ -8,8 +8,8 @@ #include =20 #include -#include #include +#include =20 #include "fdt.h" =20 @@ -116,6 +116,9 @@ unsigned int __init builder_create_domains(struct boot_= info *bi) if ( bd->d ) build_count++; =20 + /* Free temporary buffers. */ + free_boot_modules(); + return build_count; } =20 diff --git a/xen/arch/x86/hvm/dom_build.c b/xen/arch/x86/hvm/dom_build.c index 2798542e5483..a847c2cb16d9 100644 --- a/xen/arch/x86/hvm/dom_build.c +++ b/xen/arch/x86/hvm/dom_build.c @@ -854,9 +854,6 @@ static int __init pvh_load_kernel( last_addr =3D ROUNDUP(last_addr, PAGE_SIZE); } =20 - /* Free temporary buffers. */ - free_boot_modules(); - if ( bd->cmdline ) { rc =3D hvm_copy_to_guest_phys(last_addr, bd->cmdline, diff --git a/xen/arch/x86/pv/dom0_build.c b/xen/arch/x86/pv/dom0_build.c index c3d269438313..8d941ff4486e 100644 --- a/xen/arch/x86/pv/dom0_build.c +++ b/xen/arch/x86/pv/dom0_build.c @@ -865,9 +865,6 @@ static int __init dom0_construct(struct boot_domain *bd) init_hypercall_page(d, _p(parms.virt_hypercall)); } =20 - /* Free temporary buffers. */ - free_boot_modules(); - /* Set up start info area. */ si =3D (start_info_t *)vstartinfo_start; clear_page(si); --=20 2.30.2 From nobody Fri Oct 31 16:34:17 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=1745100819; cv=pass; d=zohomail.com; s=zohoarc; b=fQ+GHOOYV1ud7Om5kCcTWfM4JaSMEijieLmEKzh2oHoXQtIMpLWUD4x3wljc05LkWnGc3e1j47INpCieX4KDD6xleueNpp1q1Ms0H8OOOH83POFay+q5tBR8xGI7KRliSmX2ncB9M9J3I+9hbG85XygKHYd1B/EJHz0ZOB/zmaw= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100819; 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=9J5GpuQpFoOEieUW2L0AylJvJrVRYTI0FgGOBBazw64=; b=mKrRvJonLd9bneXkIPVEvVS3zCTsqumT6gZaV4tlkCRB7w/U6OOq7UIFZ9W6uDymjmM0WuHFUWxllJ0hD1y0xpWOA2ghTiQBlijvOssav8Wo/fCkKi74NBOQ97Zhp1i5hT3S8tE3VtzHxr0sPrzW0bZsGIA0K7YhyVpuEifYXhw= 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 1745100819278682.6277909231756; Sat, 19 Apr 2025 15:13:39 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.960119.1352222 (Exim 4.92) (envelope-from ) id 1u6GRG-0005XE-Ao; Sat, 19 Apr 2025 22:13:30 +0000 Received: by outflank-mailman (output) from mailman id 960119.1352222; Sat, 19 Apr 2025 22:13:30 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u6GRG-0005X2-7R; Sat, 19 Apr 2025 22:13:30 +0000 Received: by outflank-mailman (input) for mailman id 960119; Sat, 19 Apr 2025 22:13:28 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u6GRE-0004oZ-G7 for xen-devel@lists.xenproject.org; Sat, 19 Apr 2025 22:13:28 +0000 Received: from sender4-of-o50.zoho.com (sender4-of-o50.zoho.com [136.143.188.50]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 83493424-1d6b-11f0-9ffb-bf95429c2676; Sun, 20 Apr 2025 00:13:26 +0200 (CEST) Received: by mx.zohomail.com with SMTPS id 174510056489920.502879948931422; Sat, 19 Apr 2025 15:09:24 -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: 83493424-1d6b-11f0-9ffb-bf95429c2676 ARC-Seal: i=1; a=rsa-sha256; t=1745100568; cv=none; d=zohomail.com; s=zohoarc; b=fQHCS4QPnpOILamjvaebZDeR8BHGW0ULo0rQJo3rxIqb4MkyDCZ+n3iUIxxuiH/e/7E/62Qf9G5SQ1RlEFjnbJdMOphQQyexKUiL0u7boabOHPsT2RAufl/xXKDAuFxCoZJNbqNxkm3jYkDekGQOl2wcP07FiHDWHoF69cf687s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100568; 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=9J5GpuQpFoOEieUW2L0AylJvJrVRYTI0FgGOBBazw64=; b=mZgHBox8c7XDqYwt+pOI+4q6yiZO1cIuQh86w89fhSNAmU3Gqta0CXccH+hzK7dx/4o02HpOMpXKPqt90HDearHeTdHULzAXiF92tnuqhpi54ZU0kCHOxl/ehDA6YXtD+4oNOI0U/BQ59gUXlJQaCvF3oCm7Nx74BtxRSpF8kxI= 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=1745100568; 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=9J5GpuQpFoOEieUW2L0AylJvJrVRYTI0FgGOBBazw64=; b=SyqHYQcvV0xRaOfXBsErvSiGPB+ge32s7BbiKW0b9/hC7YytSM+Js9VNS6BSjLvB Yem6rP0Ym/oX2qUdqLH7KuungAjcHwGR5DTrEOrEJpTVGW4aEiuMUZeSvzoc6lybPZD X8eqZouVTojr+QsglPPWUcg7BZoQkmMWfaiJCpqU= 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 32/38] x86/hyperlaunch: introduce concept of core domains Date: Sat, 19 Apr 2025 18:08:14 -0400 Message-Id: <20250419220820.4234-33-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: 1745100819892019000 Content-Type: text/plain; charset="utf-8" When constructing domU, and specifically the event channels for their conso= le and xenstore event channels, the domid for the backing domain must be known. Therefore, the control, hardware, and xenstore domains are deemed as core domains, and must be constructed before any of the other domains. This commit introduces the build_core_domains() function that will ensure t= he core domains are constructed first. Signed-off-by: Daniel P. Smith --- xen/arch/x86/domain-builder/core.c | 68 ++++++++++++++++++++++++-- xen/arch/x86/include/asm/boot-domain.h | 2 + 2 files changed, 66 insertions(+), 4 deletions(-) diff --git a/xen/arch/x86/domain-builder/core.c b/xen/arch/x86/domain-build= er/core.c index 901efce62a61..f693aa46d278 100644 --- a/xen/arch/x86/domain-builder/core.c +++ b/xen/arch/x86/domain-builder/core.c @@ -103,18 +103,78 @@ void __init builder_init(struct boot_info *bi) } } =20 +static int __init build_core_domains(struct boot_info *bi) +{ + int count =3D 0; + struct boot_domain *bd; + int hw, cd, xs; + + cd =3D first_boot_domain_index(bi, BUILD_CAPS_CONTROL); + if ( cd > MAX_NR_BOOTDOMS ) + printk(XENLOG_WARNING "No control domain was defined\n"); + else + { + bd =3D &bi->domains[cd]; + + arch_create_dom(bi, bd); + if ( bd->d ) + { + bd->constructed =3D true; + count++; + } + } + + hw =3D first_boot_domain_index(bi, BUILD_CAPS_HARDWARE); + if ( hw > MAX_NR_BOOTDOMS ) + printk(XENLOG_WARNING "No hardware domain was defined\n"); + else + { + if ( hw !=3D cd ) + { + bd =3D &bi->domains[hw]; + + arch_create_dom(bi, bd); + if ( bd->d ) + { + bd->constructed =3D true; + count++; + } + } + } + + xs =3D first_boot_domain_index(bi, BUILD_CAPS_XENSTORE); + if ( xs > MAX_NR_BOOTDOMS ) + printk(XENLOG_WARNING "No xenstore domain was defined\n"); + else + { + if ( xs !=3D cd && xs !=3D hw ) + { + bd =3D &bi->domains[xs]; + + arch_create_dom(bi, bd); + if ( bd->d ) + { + bd->constructed =3D true; + count++; + } + } + } + + return count; +} + unsigned int __init builder_create_domains(struct boot_info *bi) { unsigned int build_count =3D 0; struct boot_domain *bd =3D &bi->domains[0]; =20 + if ( bi->nr_domains =3D=3D 0 ) + panic("%s: no domains defined\n", __func__); + if ( bd->kernel =3D=3D NULL && bd->capabilities & BUILD_CAPS_CONTROL ) panic("%s: control domain missing kernel\n", __func__); =20 - - arch_create_dom(bi, bd); - if ( bd->d ) - build_count++; + build_count =3D build_core_domains(bi); =20 /* Free temporary buffers. */ free_boot_modules(); diff --git a/xen/arch/x86/include/asm/boot-domain.h b/xen/arch/x86/include/= asm/boot-domain.h index df2bfa0c94fa..a574f4941ed3 100644 --- a/xen/arch/x86/include/asm/boot-domain.h +++ b/xen/arch/x86/include/asm/boot-domain.h @@ -42,6 +42,8 @@ struct boot_domain { xen_pfn_t gfn; evtchn_port_t evtchn; } console, store; + + bool constructed; }; =20 #endif --=20 2.30.2 From nobody Fri Oct 31 16:34:17 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=1745101333; cv=pass; d=zohomail.com; s=zohoarc; b=I5DQWAlD9CNs18iTmpG5icnXrT4sQ0aWEHEDVoKG7b/UiIO8KFZ7cBAcEMoq6FuiGbjuD9VhqQhr1ddWz7VVbyzUs4JtCfFE2ZGf3fF/mKZUGCuBdOXv+77E2zDaS1nOhQEd878OtUjiBAhNWhSIRv7kR5Uu40GR4Lxr1egbEj4= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745101333; 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=U9FvVn492x+OFP8sG0Y52wx0v+AcRwxTtLU4QhuGxA8=; b=HQfVAa835u8/wCRCZZd0JnawxvwQVVkALdOVpp0ezrLQFA23s1/oDY/LEl2pO2c3kXZELxsPpeOypIAJrbVfBt/FvLbvWNXFcNGKzR4m8TzTOAe/j54VEmrBn0h4Jco17Fo69n2O2pmTjN7HaS1TlG0/lKXVDbb5NCUAF/0nv5g= 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 1745101333267939.2412145174634; Sat, 19 Apr 2025 15:22:13 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.960324.1352433 (Exim 4.92) (envelope-from ) id 1u6GZQ-00029Q-DQ; Sat, 19 Apr 2025 22:21:56 +0000 Received: by outflank-mailman (output) from mailman id 960324.1352433; Sat, 19 Apr 2025 22:21:56 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u6GZQ-000286-9e; Sat, 19 Apr 2025 22:21:56 +0000 Received: by outflank-mailman (input) for mailman id 960324; Sat, 19 Apr 2025 22:21:55 +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 1u6GRi-0004yY-0n for xen-devel@lists.xenproject.org; Sat, 19 Apr 2025 22:13:58 +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 9592cd98-1d6b-11f0-9eb0-5ba50f476ded; Sun, 20 Apr 2025 00:13:57 +0200 (CEST) Received: by mx.zohomail.com with SMTPS id 1745100565715336.52410652135313; Sat, 19 Apr 2025 15:09:25 -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: 9592cd98-1d6b-11f0-9eb0-5ba50f476ded ARC-Seal: i=1; a=rsa-sha256; t=1745100571; cv=none; d=zohomail.com; s=zohoarc; b=btFqBz997oftbi6g/MDEZqH4hS3bnCM9xa+ajGHPcYMNn6oKIkgWwFRcnOgw/9YsbaDxz+8kZpCzbKxTWfDl5JolRGj9ZaOb1E9MovXzS1v+yEFawyRbtbSxvfIPjNi9mhkPGMi0I58mDAuWPZwf9kF2sqHlfwGQ9+cfGs0AWSo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100571; 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=U9FvVn492x+OFP8sG0Y52wx0v+AcRwxTtLU4QhuGxA8=; b=Rt49BZJVAbG5KPOvAQrMKh6xnBTRHIVqyPxzgQ/3a+0ozA8M/jnix5uHA4+inI9STTiznDUH4e+Sss+8Lidaa0SoxspD9bXvLgdQ9aMTvRdakzQW1af1tYB230X1HMBWunhtimXuED66Wb2rhmQ/HfL87ikK6zFpLWor3c+np1U= 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=1745100571; 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=U9FvVn492x+OFP8sG0Y52wx0v+AcRwxTtLU4QhuGxA8=; b=jbYPsAtNflY25+wfKESia+/y49i+O/W+hrm/2+aHYP4i1GPYwxIFYqenBVHm2sv8 zo3AjY3QUdsNKlT2ct71Iq8y17iEjiFRI9omJw+mAPMEqP2sFwUJXxcsrw1p4YD4niY jPIp+ZCttjs9Lx1o/HWVkUNOY71xmHrR04Bj219Y= 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 33/38] x86/boot: refactor bzimage parser to be re-enterant Date: Sat, 19 Apr 2025 18:08:15 -0400 Message-Id: <20250419220820.4234-34-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: 1745101335530019100 Content-Type: text/plain; charset="utf-8" The bzimage logic uses the unit global orig_image_len to hold the original module length for the kernel when the headroom is calculated. It then uses orig_image_len to locate the start of the bzimage when the expansion is don= e. This is an issue when more than one bzimage is processed by the headroom calculation logic, as it will leave orig_image_len set to the length of the last bzimage it processed. The boot module work introduced storing the headroom size on a per module basis. By passing in the headroom from the boot module, orig_image_len is no longer needed to locate the beginning of the bzimage after the allocated headroom. The bzimage functions are reworked as such, allowing the removal = of orig_image_len and enabling them to be reused by multiple kernel boot modul= es. Signed-off-by: Daniel P. Smith --- xen/arch/x86/bzimage.c | 38 ++++++++++++++++++------------ xen/arch/x86/hvm/dom_build.c | 3 ++- xen/arch/x86/include/asm/bzimage.h | 5 ++-- xen/arch/x86/pv/dom0_build.c | 3 ++- 4 files changed, 30 insertions(+), 19 deletions(-) diff --git a/xen/arch/x86/bzimage.c b/xen/arch/x86/bzimage.c index 66f648f311e4..32f0360d25b4 100644 --- a/xen/arch/x86/bzimage.c +++ b/xen/arch/x86/bzimage.c @@ -68,8 +68,6 @@ static __init int bzimage_check(struct setup_header *hdr,= unsigned long len) return 1; } =20 -static unsigned long __initdata orig_image_len; - unsigned long __init bzimage_headroom(void *image_start, unsigned long image_length) { @@ -90,7 +88,6 @@ unsigned long __init bzimage_headroom(void *image_start, if ( elf_is_elfbinary(image_start, image_length) ) return 0; =20 - orig_image_len =3D image_length; headroom =3D output_length(image_start, image_length); if (gzip_check(image_start, image_length)) { @@ -103,13 +100,20 @@ unsigned long __init bzimage_headroom(void *image_sta= rt, return headroom; } =20 -int __init bzimage_parse(void *image_base, void **image_start, - unsigned long *image_len) +int __init bzimage_parse( + void *image_base, void **image_start, unsigned long headroom, + unsigned long *image_len) { struct setup_header *hdr =3D (struct setup_header *)(*image_start); int err =3D bzimage_check(hdr, *image_len); - unsigned long output_len; - + unsigned long module_len =3D *image_len; + + /* + * Variable err will have one of three values: + * - < 0: a error occurred trying to inspect the contents + * - > 0: the image is a bzImage + * - =3D=3D 0: not a bzImage, could be raw elf or elf.gz (vmlinuz.gz) + */ if ( err < 0 ) return err; =20 @@ -118,21 +122,25 @@ int __init bzimage_parse(void *image_base, void **ima= ge_start, *image_start +=3D (hdr->setup_sects + 1) * 512 + hdr->payload_offs= et; *image_len =3D hdr->payload_length; } - - if ( elf_is_elfbinary(*image_start, *image_len) ) - return 0; + else + { + if ( elf_is_elfbinary(*image_start, *image_len) ) + return 0; + else + *image_len =3D *image_len - headroom; + } =20 BUG_ON(!(image_base < *image_start)); =20 - output_len =3D output_length(*image_start, orig_image_len); - - if ( (err =3D perform_gunzip(image_base, *image_start, orig_image_len)= ) > 0 ) - err =3D decompress(*image_start, orig_image_len, image_base); + if ( (err =3D perform_gunzip(image_base, *image_start, *image_len)) > = 0 ) + err =3D decompress(*image_start, *image_len, image_base); =20 if ( !err ) { + printk(XENLOG_ERR "%s(%d): decompression failed, reseting image st= art and len\n", + __func__, err); *image_start =3D image_base; - *image_len =3D output_len; + *image_len =3D module_len; } =20 return err > 0 ? 0 : err; diff --git a/xen/arch/x86/hvm/dom_build.c b/xen/arch/x86/hvm/dom_build.c index a847c2cb16d9..4f614aea34c3 100644 --- a/xen/arch/x86/hvm/dom_build.c +++ b/xen/arch/x86/hvm/dom_build.c @@ -743,7 +743,8 @@ static int __init pvh_load_kernel( struct vcpu *v =3D d->vcpu[0]; int rc; =20 - if ( (rc =3D bzimage_parse(image_base, &image_start, &image_len)) !=3D= 0 ) + if ( (rc =3D bzimage_parse(image_base, &image_start, image->headroom, + &image_len)) !=3D 0 ) { printk("Error trying to detect bz compressed kernel\n"); return rc; diff --git a/xen/arch/x86/include/asm/bzimage.h b/xen/arch/x86/include/asm/= bzimage.h index 7ed69d39103d..24c7d4b8eb68 100644 --- a/xen/arch/x86/include/asm/bzimage.h +++ b/xen/arch/x86/include/asm/bzimage.h @@ -5,7 +5,8 @@ =20 unsigned long bzimage_headroom(void *image_start, unsigned long image_leng= th); =20 -int bzimage_parse(void *image_base, void **image_start, - unsigned long *image_len); +int bzimage_parse( + void *image_base, void **image_start, unsigned long headroom, + unsigned long *image_len); =20 #endif /* __X86_BZIMAGE_H__ */ diff --git a/xen/arch/x86/pv/dom0_build.c b/xen/arch/x86/pv/dom0_build.c index 8d941ff4486e..8b02f62892d4 100644 --- a/xen/arch/x86/pv/dom0_build.c +++ b/xen/arch/x86/pv/dom0_build.c @@ -427,7 +427,8 @@ static int __init dom0_construct(struct boot_domain *bd) =20 d->max_pages =3D ~0U; =20 - if ( (rc =3D bzimage_parse(image_base, &image_start, &image_len)) !=3D= 0 ) + if ( (rc =3D bzimage_parse(image_base, &image_start, bd->kernel->headr= oom, + &image_len)) !=3D 0 ) return rc; =20 if ( (rc =3D elf_init(&elf, image_start, image_len)) !=3D 0 ) --=20 2.30.2 From nobody Fri Oct 31 16:34:17 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=1745100812; cv=pass; d=zohomail.com; s=zohoarc; b=H4kAeXJBzysi64q1WKKNIBQVijfAUM/6SbYvDWw8rwXOyl9kcMEyC65eoAOtUvwvNvh1FRUiDFCZY2O167Gf8ChCAkyPksVzDiuhgbCclncGuYxEHnVXtaZJSS24BKhyARCJi/XbtDrmF0iMskO8dZ76QsOaw9egVYDwWnxSnDk= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100812; 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=2pfoYx7ufXR5MimMumzHjXA6Uyttums4Ez5tgMk1h/4=; b=KTXlDNBvir7Csi574dcU5aOzSPRf95JNZAmaVbMZNglztshBhJ3hwZAEkQeq9rT19BQevW+V9rQnWkmKYb0O48w70DV2BJNL2hs9dhDoETfOZfHJ4ZB1r1suFSyhB+DB6pNuoFofYk7e0gqOdd6RsAGJjF/zAWwm3ful8Yjw4/Q= 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 1745100812746682.8710962126281; Sat, 19 Apr 2025 15:13:32 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.960116.1352213 (Exim 4.92) (envelope-from ) id 1u6GR8-00058O-3E; Sat, 19 Apr 2025 22:13:22 +0000 Received: by outflank-mailman (output) from mailman id 960116.1352213; Sat, 19 Apr 2025 22:13:22 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u6GR8-00058D-0c; Sat, 19 Apr 2025 22:13:22 +0000 Received: by outflank-mailman (input) for mailman id 960116; Sat, 19 Apr 2025 22:13:20 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u6GR6-0004oZ-5l for xen-devel@lists.xenproject.org; Sat, 19 Apr 2025 22:13:20 +0000 Received: from sender4-of-o50.zoho.com (sender4-of-o50.zoho.com [136.143.188.50]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 7e840d94-1d6b-11f0-9ffb-bf95429c2676; Sun, 20 Apr 2025 00:13:18 +0200 (CEST) Received: by mx.zohomail.com with SMTPS id 1745100566539673.7790316696628; Sat, 19 Apr 2025 15:09:26 -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: 7e840d94-1d6b-11f0-9ffb-bf95429c2676 ARC-Seal: i=1; a=rsa-sha256; t=1745100570; cv=none; d=zohomail.com; s=zohoarc; b=QzRaWbeQpwkUFIp4sul5KdDV5Prz7T0mPj68GLFG9CCLF7kc5Ywyv2vbTrH5WXNGgi4sOAk3AjDi+7a0R8dF7ydd0a73KJMzQAB6jyomDPF6vKIIh1TRp5ekJsmuq9/Ypym7fWk7KL36XPeZilk66gqYsDudDrxBLq9lN5idbiQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100570; 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=2pfoYx7ufXR5MimMumzHjXA6Uyttums4Ez5tgMk1h/4=; b=NQuHOYgx7Tuts1j2/y+NFEASXsc8GAvtPL04pGoPTHxili+yVcRc3/E2tge4dEna4Z0bFkSXWDtao0ZKBNFLpZ6H9zgFq40Tc/8wClf5nRnZmasKY1n1NwoGjIJWBO5kfPmDerNyF99eLbkvZFd5R/y+W0sazb3bdMhuqx6EzQw= 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=1745100570; 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=2pfoYx7ufXR5MimMumzHjXA6Uyttums4Ez5tgMk1h/4=; b=rR5jPit++B6TRxeO/HzIn+sRw5HczLcZ+n08bCjMDCOXIe8twcjj9z284AWY68AC LntuqGder4hkv/YTdnuryMeTvIGRy1eIddYSJlqdz+KS5lAqrd+G4RtlwNXxv+T3IvO 9Z21b/ZnE+W0aMhptIKv+fWIEkLHiIsCl5cqK/Xo= 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 34/38] x86/hyperlaunch: introduce multidomain kconfig option Date: Sat, 19 Apr 2025 18:08:16 -0400 Message-Id: <20250419220820.4234-35-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: 1745100813995019000 Content-Type: text/plain; charset="utf-8" This adds the MULTIDOMAIN_BUILDER kconfig option that will be used to enable the domain construction path to be called multiple times. With the idea of being able to construct multiple domains now introduced, rename construct_d= om0() to construct_dom(). Signed-off-by: Daniel P. Smith --- xen/arch/x86/dom0_build.c | 9 +++++---- xen/arch/x86/domain-builder/Kconfig | 12 ++++++++++++ xen/arch/x86/domain-builder/domain.c | 2 +- xen/arch/x86/include/asm/bootinfo.h | 2 +- xen/arch/x86/include/asm/setup.h | 2 +- 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/xen/arch/x86/dom0_build.c b/xen/arch/x86/dom0_build.c index e488a204372b..8c8cb08a6f7e 100644 --- a/xen/arch/x86/dom0_build.c +++ b/xen/arch/x86/dom0_build.c @@ -558,15 +558,16 @@ int __init dom0_setup_permissions(struct domain *d) return rc; } =20 -int __init construct_dom0(struct boot_domain *bd) +int __init construct_dom(struct boot_domain *bd) { int rc; const struct domain *d =3D bd->d; =20 /* Sanity! */ - BUG_ON(!pv_shim && d->domain_id !=3D 0); - BUG_ON(d->vcpu[0] =3D=3D NULL); - BUG_ON(d->vcpu[0]->is_initialised); + if ( ! IS_ENABLED(CONFIG_MULTIDOMAIN_BUILDER) ) + BUG_ON(!pv_shim && bd->d->domain_id !=3D 0); + BUG_ON(bd->d->vcpu[0] =3D=3D NULL); + BUG_ON(bd->d->vcpu[0]->is_initialised); =20 process_pending_softirqs(); =20 diff --git a/xen/arch/x86/domain-builder/Kconfig b/xen/arch/x86/domain-buil= der/Kconfig index 51d549c20df3..05d7859e6b53 100644 --- a/xen/arch/x86/domain-builder/Kconfig +++ b/xen/arch/x86/domain-builder/Kconfig @@ -12,4 +12,16 @@ config DOMAIN_BUILDER =20 If unsure, say N. =20 +config MULTIDOMAIN_BUILDER + bool "Multiple domain building (UNSUPPORTED)" if UNSUPPORTED + depends on DOMAIN_BUILDER + default n + help + Enables the domain builder capability to build multiple domains + using a flattened device tree. + + This feature is currently experimental. + + If unsure, say N. + endmenu diff --git a/xen/arch/x86/domain-builder/domain.c b/xen/arch/x86/domain-bui= lder/domain.c index b413a87cc9c9..919df1ffb1c3 100644 --- a/xen/arch/x86/domain-builder/domain.c +++ b/xen/arch/x86/domain-builder/domain.c @@ -399,7 +399,7 @@ struct domain *__init arch_create_dom( if ( !(bd->capabilities & BUILD_CAPS_HARDWARE) ) alloc_console_evtchn(bi, bd); =20 - if ( construct_dom0(bd) !=3D 0 ) + if ( construct_dom(bd) !=3D 0 ) panic("Could not construct domain 0\n"); =20 XFREE(cmdline); diff --git a/xen/arch/x86/include/asm/bootinfo.h b/xen/arch/x86/include/asm= /bootinfo.h index 430ae08cf5ef..298cff303673 100644 --- a/xen/arch/x86/include/asm/bootinfo.h +++ b/xen/arch/x86/include/asm/bootinfo.h @@ -17,7 +17,7 @@ #define MAX_NR_BOOTMODS 63 =20 /* Max number of boot domains that Xen can construct */ -#define MAX_NR_BOOTDOMS 1 +#define MAX_NR_BOOTDOMS 64 =20 /* Boot module binary type / purpose */ enum bootmod_type { diff --git a/xen/arch/x86/include/asm/setup.h b/xen/arch/x86/include/asm/se= tup.h index 4b8fbdc67e05..3f6850d40d04 100644 --- a/xen/arch/x86/include/asm/setup.h +++ b/xen/arch/x86/include/asm/setup.h @@ -27,7 +27,7 @@ void subarch_init_memory(void); void init_IRQ(void); =20 struct boot_domain; -int construct_dom0(struct boot_domain *bd); +int construct_dom(struct boot_domain *bd); =20 const char *cmdline_cook(const char *p, const char *loader_name); =20 --=20 2.30.2 From nobody Fri Oct 31 16:34:17 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=1745101324; cv=pass; d=zohomail.com; s=zohoarc; b=TDVrFMhQxeoBx5bWQc3TC+L6f8KoxI0oLLBfsJGvN+SQiFHX54FZ14vQP1Pu6O1XLof9E4SdcaxocnsAzK0RS29k8mNNZuUx5BTcfS+kBU2IuRJno5+82t3WLbJbihYj558QdTgYI2jhFsMSwz6lwcdsRhEEmvQyRGE5EhGnJTA= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745101324; 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=E9G74MndY9ZXEk+L1cKEhZ2Ussr5gQpteSfUtOKkupg=; b=m/3j4bqy/2O0lKBEOKo+ppZExa7jmVDHsLaJf6QygNy2RKvh81dvx/dllmIwgrkAKJpU6mvmzo+79B8TVyVOGYu67BQIpOjDJloBE8zZaWUIyAky8nevuy1YihZ+eWqj/s7NNTlvgF2nJcg0VKZvLP7nTgLPSCFzWZvwShqsr44= 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 1745101324511140.45075108613867; Sat, 19 Apr 2025 15:22:04 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.960306.1352423 (Exim 4.92) (envelope-from ) id 1u6GZK-0001Ap-7b; Sat, 19 Apr 2025 22:21:50 +0000 Received: by outflank-mailman (output) from mailman id 960306.1352423; Sat, 19 Apr 2025 22:21: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 1u6GZK-00019u-0U; Sat, 19 Apr 2025 22:21:50 +0000 Received: by outflank-mailman (input) for mailman id 960306; Sat, 19 Apr 2025 22:21:48 +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 1u6GRb-0004yY-4k for xen-devel@lists.xenproject.org; Sat, 19 Apr 2025 22:13:51 +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 91665486-1d6b-11f0-9eb0-5ba50f476ded; Sun, 20 Apr 2025 00:13:50 +0200 (CEST) Received: by mx.zohomail.com with SMTPS id 1745100567355726.0607417322368; Sat, 19 Apr 2025 15:09:27 -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: 91665486-1d6b-11f0-9eb0-5ba50f476ded ARC-Seal: i=1; a=rsa-sha256; t=1745100571; cv=none; d=zohomail.com; s=zohoarc; b=YQ8uzkmpyPlCFPyazWDIbwPOSyCAsWMBRW9+8kLSGG2F6TedD9RJkPmFFpsl6AcSIjuYGivBmQCpJwI2BE6b0w+l4OFKm2IbEKFDIlh8X65yPNkOxZkRkQG92mHFHdIASnU/CgsRIOgDDF11581qNzOs/bhA+omkhgFkM1tBJ1c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100571; 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=E9G74MndY9ZXEk+L1cKEhZ2Ussr5gQpteSfUtOKkupg=; b=CmD9K4OA1Tbbx0GZGexDCYspuFdY3Rd0GuF8H2aPAhbYUWy/XgfhrXBbg1eiuAS7L/lr6T6va4+/dz0/1dybBakCVS+5KiP2gvijoOIPUumN3UKJEXd+BSqGKkGFgetmF8SpRf7K1ahoKCQwAcwUkfexOMKcO1q48pz+dEwtQDs= 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=1745100571; 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=E9G74MndY9ZXEk+L1cKEhZ2Ussr5gQpteSfUtOKkupg=; b=Ak7kH6RAScWmzL2O9SyT749raI8ggkrjE8Z2jZo2KvWds8rpIehLrPNFlLwJrDlg rP7p5JHXv5QODLyQlx3fsTn8Yz/NBMv3Ct5VuoVFLOM6t8UF2RNasCeQR/opsqGaKoI R4ttPJlwATDjxg1wB5+dIjOJB2U2bQCQh7gMIyhI= 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 35/38] x86/hyperlaunch: add multidomain construction logic Date: Sat, 19 Apr 2025 18:08:17 -0400 Message-Id: <20250419220820.4234-36-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: 1745101327485019100 Content-Type: text/plain; charset="utf-8" Introduce the logic to loop over boot_info->domains and construct each valid entry in the array. Signed-off-by: Daniel P. Smith --- xen/arch/x86/domain-builder/core.c | 32 ++++++++++++++++++++++++---- xen/arch/x86/domain-builder/domain.c | 7 ++++-- xen/arch/x86/hvm/dom_build.c | 5 ++++- xen/arch/x86/setup.c | 11 ++++++---- 4 files changed, 44 insertions(+), 11 deletions(-) diff --git a/xen/arch/x86/domain-builder/core.c b/xen/arch/x86/domain-build= er/core.c index f693aa46d278..2712703e17e6 100644 --- a/xen/arch/x86/domain-builder/core.c +++ b/xen/arch/x86/domain-builder/core.c @@ -166,16 +166,40 @@ static int __init build_core_domains(struct boot_inf= o *bi) unsigned int __init builder_create_domains(struct boot_info *bi) { unsigned int build_count =3D 0; - struct boot_domain *bd =3D &bi->domains[0]; + int i; =20 if ( bi->nr_domains =3D=3D 0 ) panic("%s: no domains defined\n", __func__); =20 - if ( bd->kernel =3D=3D NULL && bd->capabilities & BUILD_CAPS_CONTROL ) - panic("%s: control domain missing kernel\n", __func__); - build_count =3D build_core_domains(bi); =20 + if ( ! IS_ENABLED(CONFIG_MULTIDOMAIN_BUILDER) ) + goto out; + + for ( i =3D 0; i < bi->nr_domains; i++ ) + { + struct boot_domain *bd =3D &bi->domains[i]; + + if ( bd->constructed ) + continue; + + if ( bd->mode & BUILD_MODE_PARAVIRT ) + { + printk(XENLOG_WARNING "don't support PV DomU, skipping %d\n", = i); + continue; + } + + arch_create_dom(bi, bd); + if ( bd->d ) + { + bd->constructed =3D true; + build_count++; + } + else + printk(XENLOG_WARNING "failed to construct build domain %d\n",= i); + } + + out: /* Free temporary buffers. */ free_boot_modules(); =20 diff --git a/xen/arch/x86/domain-builder/domain.c b/xen/arch/x86/domain-bui= lder/domain.c index 919df1ffb1c3..7f5bee0dc759 100644 --- a/xen/arch/x86/domain-builder/domain.c +++ b/xen/arch/x86/domain-builder/domain.c @@ -321,8 +321,11 @@ struct domain *__init arch_create_dom( ((hvm_hap_supported() && !opt_dom0_shadow) ? XEN_DOMCTL_CDF_hap : 0)); =20 - dom_cfg.arch.emulation_flags |=3D - XEN_X86_EMU_LAPIC | XEN_X86_EMU_IOAPIC | XEN_X86_EMU_VPCI; + if ( bd->capabilities & BUILD_CAPS_HARDWARE ) + dom_cfg.arch.emulation_flags |=3D + XEN_X86_EMU_LAPIC | XEN_X86_EMU_IOAPIC | XEN_X86_EMU_VPCI; + else + dom_cfg.arch.emulation_flags |=3D X86_EMU_LAPIC; } =20 if ( bd->capabilities & BUILD_CAPS_HARDWARE ) diff --git a/xen/arch/x86/hvm/dom_build.c b/xen/arch/x86/hvm/dom_build.c index 4f614aea34c3..db7bf9a6934a 100644 --- a/xen/arch/x86/hvm/dom_build.c +++ b/xen/arch/x86/hvm/dom_build.c @@ -885,7 +885,10 @@ static int __init pvh_load_kernel( } =20 start_info.magic =3D XEN_HVM_START_MAGIC_VALUE; - start_info.flags =3D SIF_PRIVILEGED | SIF_INITDOMAIN; + if ( is_control_domain(d) ) + start_info.flags =3D SIF_PRIVILEGED; + if ( is_hardware_domain(d) ) + start_info.flags =3D SIF_INITDOMAIN; rc =3D hvm_copy_to_guest_phys(last_addr, &start_info, sizeof(start_inf= o), v); if ( rc ) { diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index da5a8e8d8ed3..09b1fc94426d 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -1319,10 +1319,13 @@ void asmlinkage __init noreturn __start_xen(void) xen->size =3D __2M_rwdata_end - _stext; } =20 - bi->domains[0].kernel->headroom =3D - bzimage_headroom(bootstrap_map_bm(bi->domains[0].kernel), - bi->domains[0].kernel->size); - bootstrap_unmap(); + for ( i =3D 0; i < bi->nr_domains; i++ ) + { + bi->domains[i].kernel->headroom =3D + bzimage_headroom(bootstrap_map_bm(bi->domains[i].kernel), + bi->domains[i].kernel->size); + bootstrap_unmap(); + } =20 #ifndef highmem_start /* Don't allow split below 4Gb. */ --=20 2.30.2 From nobody Fri Oct 31 16:34:17 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=1745101309; cv=pass; d=zohomail.com; s=zohoarc; b=js0mBJknr9HjAlA3xDD4sO7UmsEKp1EHH21z7iFj6qKkEaqewT01M/61vRXpjw2GVf3GUcL94zY5F7G+2GGA5BFs+Oi7in3Juj+oOj6jIkHjHFY9SLrxsOn6V0ToG8qtBXs1a4bUOov1/qXw1hm1eYjBVxy45LZ5CvrjTVsUq+s= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745101309; 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=lqmxREyAE0WjRdlDATtWmFP941B+/fkRIhZO5eZCnWA=; b=XWaw+1uw2Dljy/o/8/aJAb+EYUapI5pCpDz0O1gYcubevWgVotQjnf2BtLU/ohwipolEu8wAQn4UfTwq9tbP5XgXtY1QyVLeE1iac3qZdO92cvhJVB4bQ8SWI/Sw9G/oTLYQgn/tTsCJVTKLNSS8J3bdsiLwO4JsBxxTRQoLrRw= 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 1745101309731135.50129435654333; Sat, 19 Apr 2025 15:21:49 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.960273.1352382 (Exim 4.92) (envelope-from ) id 1u6GZ6-0006jS-TQ; Sat, 19 Apr 2025 22:21:36 +0000 Received: by outflank-mailman (output) from mailman id 960273.1352382; Sat, 19 Apr 2025 22:21:36 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u6GZ6-0006iW-Oi; Sat, 19 Apr 2025 22:21:36 +0000 Received: by outflank-mailman (input) for mailman id 960273; Sat, 19 Apr 2025 22:21:35 +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 1u6GRp-0004yY-7a for xen-devel@lists.xenproject.org; Sat, 19 Apr 2025 22:14:05 +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 99dcf2b1-1d6b-11f0-9eb0-5ba50f476ded; Sun, 20 Apr 2025 00:14:04 +0200 (CEST) Received: by mx.zohomail.com with SMTPS id 17451005681919.729422362614287; Sat, 19 Apr 2025 15:09:28 -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: 99dcf2b1-1d6b-11f0-9eb0-5ba50f476ded ARC-Seal: i=1; a=rsa-sha256; t=1745100571; cv=none; d=zohomail.com; s=zohoarc; b=IeC677nf98P/AOhN210mWuPZjzW3XkZvyeBoTAPX42mwIDr/DA4h+bWDvezCNyORG3dsCnW2kOhzVA/TXgjehU3dJ8PwpeYXjQJOeFWOi2D0uNUf+hcAOpVN2ts93iE90mwyRkC+aEhpn4GvN9cl2XHo/HxSH4QlS0a4FVYYF24= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100571; 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=lqmxREyAE0WjRdlDATtWmFP941B+/fkRIhZO5eZCnWA=; b=FPWgwbab7TgW70DOAImMDgvCzOT30qSfqfAFyE1HzGjTgdajGdUZwnKhq5eGFSBD+IZfVHMkdME77Ofql2gd9KyBU8Z27lP7E+c+g+AnT2FeDDJ39e2Ke5TzoMldaasVWMo1SLAqBkD8aSAJXnhhgmn49nLGRL4Ig7izl44Obic= 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=1745100571; 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=lqmxREyAE0WjRdlDATtWmFP941B+/fkRIhZO5eZCnWA=; b=P3kEEki7Aklx1SZji5YoSDUrUiCWXt2CK/dZ/nV2NgfvkcUDPeRe9MdlJE9T45qc Lc8ywD+kPmMOwmV/b69mRRLCR5K/yR9taaSrCw3NqNcTImZyYIw4KL+j/F4b09u6vYm 5OHY1hv4vcUVR3/8S1tLmH+cmf649GKyHCVlg8Rc= 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 36/38] x86/hyperlaunch: enable unpausing mulitple domains Date: Sat, 19 Apr 2025 18:08:18 -0400 Message-Id: <20250419220820.4234-37-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: 1745101311503019100 Content-Type: text/plain; charset="utf-8" This commit enables the domain builder to unpause all domains that have been flagged to start on boot. Signed-off-by: Daniel P. Smith --- xen/arch/x86/domain-builder/core.c | 20 ++++++++++++++++++++ xen/arch/x86/include/asm/boot-domain.h | 8 +++++--- xen/arch/x86/include/asm/domain-builder.h | 1 + xen/arch/x86/setup.c | 8 +++++++- 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/xen/arch/x86/domain-builder/core.c b/xen/arch/x86/domain-build= er/core.c index 2712703e17e6..fa01b8390a23 100644 --- a/xen/arch/x86/domain-builder/core.c +++ b/xen/arch/x86/domain-builder/core.c @@ -6,6 +6,7 @@ #include #include #include +#include =20 #include #include @@ -206,6 +207,25 @@ unsigned int __init builder_create_domains(struct boot= _info *bi) return build_count; } =20 +int __init builder_unpause_domains(struct boot_info *bi) +{ + int i, count =3D 0; + + for ( i =3D 0; i < bi->nr_domains; i++ ) + { + struct boot_domain *bd =3D &bi->domains[i]; + + if ( bd->capabilities & BUILD_CAPS_HARDWARE || + bd->mode & BUILD_MODE_START_ON_BOOT ) + { + domain_unpause_by_systemcontroller(bd->d); + count++; + } + } + + return count; +} + /* * Local variables: * mode: C diff --git a/xen/arch/x86/include/asm/boot-domain.h b/xen/arch/x86/include/= asm/boot-domain.h index a574f4941ed3..b592aef84b27 100644 --- a/xen/arch/x86/include/asm/boot-domain.h +++ b/xen/arch/x86/include/asm/boot-domain.h @@ -22,9 +22,11 @@ struct boot_domain { #define BUILD_CAPS_XENSTORE (1 << 2) uint32_t capabilities; =20 - /* On | Off */ -#define BUILD_MODE_PARAVIRT (1 << 0) /* PV | PVH/HVM */ -#define BUILD_MODE_ENABLE_DM (1 << 1) /* HVM | PVH */ + /* On | Off */ +#define BUILD_MODE_PARAVIRT (1 << 0) /* PV | PVH/HVM */ +#define BUILD_MODE_ENABLE_DM (1 << 1) /* HVM | PVH */ +#define BUILD_MODE_LONG (1 << 2) /* 64 BIT | 32 BIT */ +#define BUILD_MODE_START_ON_BOOT (1 << 3) /* UNPAUSED | PAUSED */ uint32_t mode; =20 unsigned long mem_pages; diff --git a/xen/arch/x86/include/asm/domain-builder.h b/xen/arch/x86/inclu= de/asm/domain-builder.h index 5dc5661bec07..df55cf52460c 100644 --- a/xen/arch/x86/include/asm/domain-builder.h +++ b/xen/arch/x86/include/asm/domain-builder.h @@ -9,6 +9,7 @@ int __init builder_get_cmdline( =20 void builder_init(struct boot_info *bi); unsigned int builder_create_domains(struct boot_info *bi); +int builder_unpause_domains(struct boot_info *bi); =20 struct domain *arch_create_dom( struct boot_info *bi, struct boot_domain *bd); diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 09b1fc94426d..ba0dd427c81b 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -787,6 +787,7 @@ static inline bool using_2M_mapping(void) =20 static void noreturn init_done(void) { + struct boot_info *bi =3D &xen_boot_info; void *va; unsigned long start, end; int err; @@ -800,7 +801,12 @@ static void noreturn init_done(void) if ( IS_ENABLED(CONFIG_SELF_TESTS) && cpu_has_xen_shstk ) stub_selftest(); =20 - domain_unpause_by_systemcontroller(dom0); + err =3D builder_unpause_domains(bi); + if ( err =3D=3D 0 ) + panic("domain builder: failed to schedule any domain to start\n"); + else + printk("domain builder: unpaused %d of %d domains at boot\n", err, + bi->nr_domains); =20 /* MUST be done prior to removing .init data. */ unregister_init_virtual_region(); --=20 2.30.2 From nobody Fri Oct 31 16:34:17 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=1745101321; cv=pass; d=zohomail.com; s=zohoarc; b=NVTIWYjHAPMoJdPt/tydopmyd9eAHmpyNaHicaQtOWEIVfUjWNyM2ZvlcUltAyexdG/jHfhFJrGMYWatDW0vmVwhNdHcEEeKk2uMki6q0FFcFpnKbipOzk7bUJ8fkhKr3B84Cl4dk16eu9SaUZgLHXuI0MJV0Wdkh4Ub5KfzpXE= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745101321; 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=DZR98Y3OL3o2Z1GWDDRpwBAwXwd/c7ubteAm0GRcRwE=; b=Kz3g9/ca2hbN4KR5z7P07zDwaKsqEHM3E374LPb4tDqvyGHOvqOlz6azs93G75lp+l8LsmHkF/7VLBbvFuJ1yckoHPu4v30nJOgqsnJktnEjnkY+AhQgvE1CgtqicBp4SqTAhyYtbW58WgcwycM2vHcgB1R/CalTp5YCnkpjCtA= 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 1745101321360317.68391310337097; Sat, 19 Apr 2025 15:22:01 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.960290.1352413 (Exim 4.92) (envelope-from ) id 1u6GZC-00087c-OO; Sat, 19 Apr 2025 22:21:42 +0000 Received: by outflank-mailman (output) from mailman id 960290.1352413; Sat, 19 Apr 2025 22:21:42 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u6GZC-00086g-Jk; Sat, 19 Apr 2025 22:21:42 +0000 Received: by outflank-mailman (input) for mailman id 960290; Sat, 19 Apr 2025 22:21:41 +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 1u6GRw-0004yY-4m for xen-devel@lists.xenproject.org; Sat, 19 Apr 2025 22:14:12 +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 9e101f54-1d6b-11f0-9eb0-5ba50f476ded; Sun, 20 Apr 2025 00:14:11 +0200 (CEST) Received: by mx.zohomail.com with SMTPS id 1745100569215364.3088256029555; Sat, 19 Apr 2025 15:09:29 -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: 9e101f54-1d6b-11f0-9eb0-5ba50f476ded ARC-Seal: i=1; a=rsa-sha256; t=1745100572; cv=none; d=zohomail.com; s=zohoarc; b=Zz7GQ4nuwfTGIzQ+RdM5u//Ii6FutWOmtiILYk1CdY41TMjriCzgHEUG8CeJI8pG/qrSOjq/3apYJkBLVAxMVWYSIfl2dIoaI9CqW3JBEr2/yKH+y51LSlrAwpEA7COyQ8rL5k+EjafJtHufEXqIDJ7WrUI56uLAm8YuGOas6qY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100572; 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=DZR98Y3OL3o2Z1GWDDRpwBAwXwd/c7ubteAm0GRcRwE=; b=LbZm6+J64+yKmDeg9lPO4ATWTnNu0MhnmRp0Bv4RfGLuv0W/v5P3g16ZVIx/Fg7ZJPigqLPsZq81k/uBSRzmUo0rj1Q7lLrTwwO2XqTSA7/yi8YQ4pQXLKYlyMj/aMPEBIm+SB/owTuUZhtWN5mzGVQCIwrU+LKbbdHtj3p3QZ8= 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=1745100572; 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=DZR98Y3OL3o2Z1GWDDRpwBAwXwd/c7ubteAm0GRcRwE=; b=m9b0JVzaIF6mNYu1XxmpR0LcOen+l39JxViAXvrAybkEFrjB2D2MMDdDqBbGI9wI 0V7fXPm2XL4lhyyehpBuYQ5NTFWfIrBhOXEA3ZG4wgQLIfyyOWhK/XuXRxKULbur3bU p/goblu0G/VEp0yMDJ3AUjYgctVzCXRVl4DNeslg= 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 37/38] x86/hyperlaunch: generalize domid assignment Date: Sat, 19 Apr 2025 18:08:19 -0400 Message-Id: <20250419220820.4234-38-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: 1745101323387019100 Content-Type: text/plain; charset="utf-8" Signed-off-by: Daniel P. Smith --- xen/arch/x86/domain-builder/fdt.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/domain-builder/fdt.c b/xen/arch/x86/domain-builde= r/fdt.c index 9c6c0ae09a24..543a0c92adb4 100644 --- a/xen/arch/x86/domain-builder/fdt.c +++ b/xen/arch/x86/domain-builder/fdt.c @@ -15,6 +15,21 @@ =20 #include "fdt.h" =20 +#define MAX_DOMID DOMID_FIRST_RESERVED +static __initdata DECLARE_BITMAP(domid_alloc, MAX_DOMID); + +static domid_t find_next_domid(void) +{ + unsigned long n =3D find_next_zero_bit(domid_alloc, MAX_DOMID, 1); + + if ( n =3D=3D MAX_DOMID ) + return DOMID_INVALID; + + set_bit(n, domid_alloc); + + return (domid_t) n; +} + /* * Unpacks a "reg" property into its address and size constituents. * @@ -186,11 +201,21 @@ static int __init process_domain_node( printk(" failed processing domain id for domain %s\n", na= me); return -EINVAL; } + if ( val >=3D DOMID_FIRST_RESERVED ) { - printk(" invalid domain id for domain %s\n", name); - return -EINVAL; + if ( (val =3D find_next_domid()) =3D=3D DOMID_INVALID ) + { + printk(" unable to allocate domid for domain %s\n", n= ame); + return -EFAULT; + } } + else if ( test_and_set_bit(val, domid_alloc) ) + { + printk(XENLOG_ERR "ERR: domid (%d) already assigned\n", va= l); + return -EFAULT; + } + bd->domid =3D (domid_t)val; printk(" domid: %d\n", bd->domid); } --=20 2.30.2 From nobody Fri Oct 31 16:34:17 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=1745101262; cv=pass; d=zohomail.com; s=zohoarc; b=ebwVcl+PlNqYWI0j+ZGDtVWgPn/8Hwk8ofeL8r1dOcs8fnlFV/7fwvPianGidb0PIiZa/pZkwoTY910teBG/EHxvqxtg0OzfQ2U8v7T/4tGnZvWKsalgbpzZw7mVBpuh8VG21YfGncI/fpycFsSesyr91kqZEMepVp8UmZXbu9k= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745101262; 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=Mw5Odp6bgq0ypnGyk6hZln2JaXDA/NCzGFeI/Jyp6zU=; b=jYDwFOGPWqNhDUGgr0keSun0jfURv3R2LeowEELozf/JjtUDaPyF/L7Yu2JMI93XfCa3bZls2p/Qkyc9kvRF4QfxgpUAOjPwbf5Kc54OXUoL355jI/NHCDbbiVQdE2/4qberTjo/ChrrAIVD5tupxHdHHVArgiLyuJUrGUoE2Sc= 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 174510126296487.14939962277185; Sat, 19 Apr 2025 15:21:02 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.960170.1352243 (Exim 4.92) (envelope-from ) id 1u6GYG-0008Sm-Ay; Sat, 19 Apr 2025 22:20:44 +0000 Received: by outflank-mailman (output) from mailman id 960170.1352243; Sat, 19 Apr 2025 22:20:44 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u6GYG-0008Sf-7R; Sat, 19 Apr 2025 22:20:44 +0000 Received: by outflank-mailman (input) for mailman id 960170; Sat, 19 Apr 2025 22:20:43 +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 1u6GS9-0004yY-N3 for xen-devel@lists.xenproject.org; Sat, 19 Apr 2025 22:14:25 +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 a5cfaf31-1d6b-11f0-9eb0-5ba50f476ded; Sun, 20 Apr 2025 00:14:24 +0200 (CEST) Received: by mx.zohomail.com with SMTPS id 1745100570220786.7371535034937; Sat, 19 Apr 2025 15:09:30 -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: a5cfaf31-1d6b-11f0-9eb0-5ba50f476ded ARC-Seal: i=1; a=rsa-sha256; t=1745100572; cv=none; d=zohomail.com; s=zohoarc; b=Pbv10S9WnTZ728F1uAkJV3EI27pZQXQ+wuyS6pOvbgC8d2OUr3xCl+I8fOFRRDHNJDYeuj0hvvuCr2/DvNZAV5VgBiHIAO9kLr2+kSDUgk6RzFa267B+gYRsD2L8dDIdS8Hac7MaRrFCoVuB0lERQcBAheR/8c8DsFaF7iQ0wR0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100572; 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=Mw5Odp6bgq0ypnGyk6hZln2JaXDA/NCzGFeI/Jyp6zU=; b=HAbKuS0Af1UZxqbyrvMGTwwx50w0oTFI0ZMwCJt7CGq8ljmnbPH7xhU9W0m/Ukwd6MCICNFBj9AG6orrF0f28cF8E+1/remIP6TKD5uKqfHM7fsDvXfcy8nq7Muiy/Udtr1vq9nQFxZn63w4h5lLqpCH3+KWoXnPmgxY9mr3FNY= 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=1745100572; 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=Mw5Odp6bgq0ypnGyk6hZln2JaXDA/NCzGFeI/Jyp6zU=; b=dd9n/ghF1ifEzSqBz/wWn3kZjJ+UQyc9qwzkpiuKTLeqX8KvaR2g2ottWuqb3iCy CXmebl4tFVTjWSbmsFuweB4s4m7kk1f4RAXu+yoshMPWUOU+MZiKdTTziWvuOItJdyE vRJ/Ph1qeBti0OIAD6lCiUrZ3lQTM0hdxCtTIAAs= 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, Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini Subject: [RFC 38/38] tools: introduce hyperlaunch domain late init Date: Sat, 19 Apr 2025 18:08:20 -0400 Message-Id: <20250419220820.4234-39-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: 1745101265391019000 Content-Type: text/plain; charset="utf-8" The late domain init helper is a helper tool for late setup of Xenstore for= a domain that was created by the hypervisor using hyperlaunch. Signed-off-by: Daniel P. Smith --- .gitignore | 1 + tools/helpers/Makefile | 12 + tools/helpers/late-init-domains.c | 364 ++++++++++++++++++++++++++++++ tools/helpers/late-init-domains.h | 18 ++ tools/helpers/xs-helpers.c | 117 ++++++++++ tools/helpers/xs-helpers.h | 26 +++ 6 files changed, 538 insertions(+) create mode 100644 tools/helpers/late-init-domains.c create mode 100644 tools/helpers/late-init-domains.h create mode 100644 tools/helpers/xs-helpers.c create mode 100644 tools/helpers/xs-helpers.h diff --git a/.gitignore b/.gitignore index 53f5df000383..7b0c390dbe0d 100644 --- a/.gitignore +++ b/.gitignore @@ -122,6 +122,7 @@ tools/flask/utils/flask-label-pci tools/helpers/init-dom0less tools/helpers/init-xenstore-domain tools/helpers/xen-init-dom0 +tools/helpers/late-init-domains tools/hotplug/common/hotplugpath.sh tools/hotplug/FreeBSD/rc.d/xencommons tools/hotplug/FreeBSD/rc.d/xendriverdomain diff --git a/tools/helpers/Makefile b/tools/helpers/Makefile index 09590eb5b6f0..26fa079e8b1f 100644 --- a/tools/helpers/Makefile +++ b/tools/helpers/Makefile @@ -14,6 +14,7 @@ ifeq ($(CONFIG_ARM),y) TARGETS +=3D init-dom0less endif endif +TARGETS +=3D late-init-domains =20 XEN_INIT_DOM0_OBJS =3D xen-init-dom0.o init-dom-json.o $(XEN_INIT_DOM0_OBJS): CFLAGS +=3D $(CFLAGS_libxentoollog) @@ -39,6 +40,14 @@ $(INIT_DOM0LESS_OBJS): CFLAGS +=3D $(CFLAGS_libxenctrl) $(INIT_DOM0LESS_OBJS): CFLAGS +=3D $(CFLAGS_libxenevtchn) init-dom0less: LDLIBS +=3D $(call xenlibs-ldlibs,ctrl evtchn toollog store= light guest foreignmemory) =20 +LATE_INIT_DOMAINS_OBJS =3D late-init-domains.o xs-helpers.o init-dom-json.o +$(LATE_INIT_DOMAINS_OBJS): CFLAGS +=3D $(CFLAGS_libxentoollog) +$(LATE_INIT_DOMAINS_OBJS): CFLAGS +=3D $(CFLAGS_libxenguest) +$(LATE_INIT_DOMAINS_OBJS): CFLAGS +=3D $(CFLAGS_libxenlight) +$(LATE_INIT_DOMAINS_OBJS): CFLAGS +=3D $(CFLAGS_libxenctrl) +$(LATE_INIT_DOMAINS_OBJS): CFLAGS +=3D $(CFLAGS_libxenstore) +late-init-domains: LDLIBS +=3D $(call xenlibs-ldlibs,ctrl toollog store li= ght guest) + .PHONY: all all: $(TARGETS) =20 @@ -51,6 +60,9 @@ init-xenstore-domain: $(INIT_XENSTORE_DOMAIN_OBJS) init-dom0less: $(INIT_DOM0LESS_OBJS) $(CC) $(LDFLAGS) -o $@ $(INIT_DOM0LESS_OBJS) $(LDLIBS) $(APPEND_LDFLAGS) =20 +late-init-domains: $(LATE_INIT_DOMAINS_OBJS) + $(CC) $(LDFLAGS) -o $@ $(LATE_INIT_DOMAINS_OBJS) $(LDLIBS) $(APPEND_LDFL= AGS) + .PHONY: install install: all $(INSTALL_DIR) $(DESTDIR)$(LIBEXEC_BIN) diff --git a/tools/helpers/late-init-domains.c b/tools/helpers/late-init-do= mains.c new file mode 100644 index 000000000000..06911d2e93d1 --- /dev/null +++ b/tools/helpers/late-init-domains.c @@ -0,0 +1,364 @@ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "init-dom-json.h" +#include "late-init-domains.h" +#include "xs-helpers.h" + +static struct option options[] =3D { + { "console", 0, NULL, 'c' }, + { "xenstore", 1, NULL, 'x' }, + { "force", 0, NULL, 'f' }, + { "verbose", 0, NULL, 'v' }, + { "help", 0, NULL, 'h' }, + { NULL, 0, NULL, 0 } +}; + +static void usage(void) +{ + fprintf(stderr, +"Usage:\n" +"\n" +"late-init-domains \n" +"\n" +"where options may include:\n" +"\n" +" --console configure the console\n" +" --xenstore domain id of the xenstore domain\n" +" --force force domain introduction even if xenstore ent= ries exist\n" +" -v[v[v]] verbosity constructing xenstore tree\n" +" --help help message\n"); +} + +#define XS_DOM_PERM(x, d, k, v) = \ + ret =3D do_xs_write_dom_with_perm(x, d, k, v, perms, num_perms); = \ + if ( ret !=3D 0 ) return ret = \ + +#define XS_DIR_PERM(x, p, k, v) = \ + ret =3D do_xs_write_dir_node_with_perm(x, p, k, v, perms, num_perms); = \ + if ( ret !=3D 0 ) return ret = \ + +static int pages_from_hvm_params( + struct xc_interface_core *xch, libxl_dominfo *info, + struct system_pages *pgs) +{ + int ret; + domid_t domid =3D info->domid; + + ret =3D xc_hvm_param_get(xch, domid, HVM_PARAM_STORE_EVTCHN, + &pgs->store.evtchn); + if (ret !=3D 0) { + fprintf(stderr, "err: failed to get dom%d store evtchn\n", domid); + return ret; + } + + ret =3D xc_hvm_param_get(xch, domid, HVM_PARAM_STORE_PFN, + &pgs->store.pfn); + if (ret < 0) { + fprintf(stderr, "err: failed to get dom%d store pfn\n", domid); + return ret; + } + + if ( pgs->console.enabled ) + { + ret =3D xc_hvm_param_get(xch, domid, HVM_PARAM_CONSOLE_EVTCHN, + &pgs->console.evtchn); + if (ret !=3D 0) { + fprintf(stderr, "warn: console for dom%d not configured\n", do= mid); + pgs->console.evtchn =3D pgs->console.pfn =3D 0; + return 0; + } + + ret =3D xc_hvm_param_get(xch, domid, HVM_PARAM_CONSOLE_PFN, + &pgs->console.pfn); + if (ret < 0) { + fprintf(stderr, "warn: console for dom%d not configured\n", do= mid); + pgs->console.evtchn =3D pgs->console.pfn =3D 0; + return 0; + } + } + + return 0; +} + +static int create_xs_entries( + struct xs_handle *xsh, struct system_pages *pgs, libxl_dominfo *di) +{ + char path[128], value[16]; + struct xs_permissions perms[2] =3D { + {.id =3D pgs->store.be_domid, .perms =3D XS_PERM_NONE}, + {.id =3D di->domid, .perms =3D XS_PERM_READ}, + }; + uint32_t num_perms =3D (sizeof(perms) / sizeof((perms)[0])); + int ret =3D 0; + + while ( do_xs_start_transaction(xsh) =3D=3D 0 ) + { + XS_DOM_PERM(xsh, di->domid, "", ""); + + snprintf(value, 16, "%d", di->domid); + XS_DOM_PERM(xsh, di->domid, "domid", value); + + XS_DOM_PERM(xsh, di->domid, "memory", ""); + snprintf(value, 16, "%" PRIu64, di->current_memkb); + XS_DOM_PERM(xsh, di->domid, "memory/target", value); + + snprintf(value, 16, "%" PRIu64, di->max_memkb); + XS_DOM_PERM(xsh, di->domid, "memory/static-max", value); + + XS_DOM_PERM(xsh, di->domid, "store", ""); + snprintf(value, 16, "%" PRIu64, pgs->store.evtchn); + XS_DOM_PERM(xsh, di->domid, "store/port", value); + + snprintf(value, 16, "%" PRIu64, pgs->store.pfn); + XS_DOM_PERM(xsh, di->domid, "store/ring-ref", value); + + if ( pgs->console.enabled && pgs->console.evtchn ) + { + char be_path[64], fe_path[64]; + + snprintf(fe_path, 64, "/local/domain/%d/console", di->domid); + snprintf(be_path, 64, "/local/domain/%d/backend/console/%d/0", + pgs->console.be_domid, di->domid); + + /* Backend entries */ + XS_DIR_PERM(xsh, be_path, "", ""); + snprintf(value, 16, "%d", di->domid); + XS_DIR_PERM(xsh, be_path, "frontend-id", value); + XS_DIR_PERM(xsh, be_path, "frontend", fe_path); + XS_DIR_PERM(xsh, be_path, "online", "1"); + XS_DIR_PERM(xsh, be_path, "protocol", "vt100"); + + snprintf(value, 16, "%d", XenbusStateInitialising); + XS_DIR_PERM(xsh, be_path, "state", value); + + /* Frontend entries */ + XS_DOM_PERM(xsh, di->domid, "console", ""); + snprintf(value, 16, "%d", pgs->console.be_domid); + XS_DIR_PERM(xsh, fe_path, "backend", be_path); + XS_DIR_PERM(xsh, fe_path, "backend-id", value); + XS_DIR_PERM(xsh, fe_path, "limit", "1048576"); + XS_DIR_PERM(xsh, fe_path, "type", "xenconsoled"); + XS_DIR_PERM(xsh, fe_path, "output", "pty"); + XS_DIR_PERM(xsh, fe_path, "tty", ""); + + snprintf(value, 16, "%" PRIu64, pgs->console.evtchn); + XS_DIR_PERM(xsh, fe_path, "port", value); + + snprintf(value, 16, "%" PRIu64, pgs->console.pfn); + XS_DIR_PERM(xsh, fe_path, "ring-ref", value); + + } + + snprintf(path, 128, "/libxl/%u", di->domid); + switch ( di->domain_type ) + { + case LIBXL_DOMAIN_TYPE_PV: + XS_DIR_PERM(xsh, path, "type", "pv"); + break; + case LIBXL_DOMAIN_TYPE_PVH: + XS_DIR_PERM(xsh, path, "type", "pvh"); + break; + case LIBXL_DOMAIN_TYPE_HVM: + XS_DIR_PERM(xsh, path, "type", "hvm"); + break; + default: + break; + } + + ret =3D do_xs_end_transaction(xsh); + switch ( ret ) + { + case 0: + break; /* proceed to loop break */ + case -EAGAIN: + continue; /* try again */ + default: + return ret; /* failed */ + } + + break; + } + + return ret; +} + +static bool init_domain( + struct xc_interface_core *xch, struct xs_handle *xsh, + struct system_pages *pgs, libxl_dominfo *di) +{ + xen_pfn_t con_pfn =3D 0L; + /*xc_dom_gnttab_seed will do nothing if front =3D=3D back */ + uint32_t con_domid =3D di->domid; + bool is_hvm =3D (di->domain_type =3D=3D LIBXL_DOMAIN_TYPE_HVM || + di->domain_type =3D=3D LIBXL_DOMAIN_TYPE_PVH); + int ret; + + if ( (ret =3D pages_from_hvm_params(xch, di, pgs)) !=3D 0 ) + { + fprintf(stderr, "error(%d): unable to fetch dom%d system pages\n",= ret, + di->domid); + return false; + } + + if ( pgs->console.enabled && pgs->console.evtchn ) + { + con_domid =3D pgs->console.be_domid; + con_pfn =3D pgs->console.pfn; + } + + ret =3D xc_dom_gnttab_seed(xch, di->domid, is_hvm, con_pfn, + pgs->store.pfn, con_domid, pgs->store.be_domid); + if ( ret !=3D 0 ) + { + fprintf(stderr, "error (%d) setting up grant tables for dom%d\n", + ret, di->domid); + return false; + } + + libxl_uuid_generate(&di->uuid); + xc_domain_sethandle(xch, di->domid, + libxl_uuid_bytearray(&di->uuid)); + + if ( (ret =3D gen_stub_json_config(di->domid, &di->uuid)) !=3D 0 ) + fprintf(stderr, "warn(%d): unable generate dom%d json stub\n", ret, + di->domid); + + if ( (ret =3D create_xs_entries(xsh, pgs, di)) !=3D 0 ) + { + fprintf(stderr, "error(%d): unable create dom%d xenstore entries\n= ", + ret, di->domid); + return false; + } + + if ( !xs_introduce_domain(xsh, di->domid, pgs->store.pfn, + pgs->store.evtchn) ) + { + fprintf(stderr, "error introducing dom%d\n", di->domid); + return false; + } + + return true; +} + +int main(int argc, char** argv) +{ + int opt, ret, i, nb_vm =3D 0, count =3D 0; + bool force =3D false; + struct xs_handle *xsh =3D NULL; + struct xc_interface_core *xch =3D NULL; + xentoollog_level minmsglevel =3D XTL_PROGRESS; + xentoollog_logger *logger =3D NULL; + libxl_dominfo *info =3D NULL; + libxl_ctx *ctx; + struct system_pages pages =3D { {0} }; + + while ( (opt =3D getopt_long(argc, argv, "c:x:fv", options, NULL)) != =3D -1 ) + { + switch ( opt ) + { + case 'c': + pages.console.be_domid =3D strtol(optarg, NULL, 10); + pages.console.enabled =3D true; + break; + case 'x': + pages.store.be_domid =3D strtol(optarg, NULL, 10); + break; + case 'f': + force =3D true; + break; + case 'v': + if ( minmsglevel > 1 ) + minmsglevel--; + break; + case 'h': + usage(); + return 0; + default: + usage(); + return 2; + } + } + + if ( optind !=3D argc ) + { + usage(); + return 1; + } + + logger =3D (xentoollog_logger *)xtl_createlogger_stdiostream(stderr, + minmsglevel= , 0); + + xsh =3D xs_open(0); + xch =3D xc_interface_open(0, 0, 0); + if ( xsh =3D=3D NULL || xch =3D=3D NULL ) + { + fprintf(stderr, "error: unable to connect to xs and/or xc interfac= e\n"); + ret =3D 1; + goto out; + } + + ret =3D libxl_ctx_alloc(&ctx, LIBXL_VERSION, 0, NULL); + if (ret) { + fprintf(stderr, "cannot init xl context\n"); + goto out; + } + + info =3D libxl_list_domain(ctx, &nb_vm); + if (!info) { + fprintf(stderr, "libxl_list_vm failed.\n"); + ret =3D 1; + goto out; + } + + for (i =3D 0; i < nb_vm; i++) { + domid_t domid =3D info[i].domid; + + /* Don't need to check for Dom0 */ + if (!domid) + continue; + + if ( xs_is_domain_introduced(xsh, domid) ) + { + if ( !force ) + continue; + + fprintf(stderr, "warning: re-introducting domain %d\n", domid); + } + + if ( init_domain(xch, xsh, &pages, &info[i]) ) + count++; + } + + printf("initialized %d out of %d domains\n", count, nb_vm); + + ret =3D 0; + +out: + if ( info ) + libxl_dominfo_list_free(info, nb_vm); + + if ( xsh ) + xs_close(xsh); + + if ( xch ) + xc_interface_close(xch); + + if ( logger ) + xtl_logger_destroy(logger); + + return ret; +} diff --git a/tools/helpers/late-init-domains.h b/tools/helpers/late-init-do= mains.h new file mode 100644 index 000000000000..8d071ef82ea0 --- /dev/null +++ b/tools/helpers/late-init-domains.h @@ -0,0 +1,18 @@ +#ifndef __LATE_INIT_PV_H +#define __LATE_INIT_PV_H + +struct system_pages { + struct { + uint16_t be_domid; + uint64_t evtchn; + uint64_t pfn; + } store; + struct { + bool enabled; + uint16_t be_domid; + uint64_t evtchn; + uint64_t pfn; + } console; +}; + +#endif diff --git a/tools/helpers/xs-helpers.c b/tools/helpers/xs-helpers.c new file mode 100644 index 000000000000..a4d2bebbbd54 --- /dev/null +++ b/tools/helpers/xs-helpers.c @@ -0,0 +1,117 @@ + +#include +#include +#include +#include + +#define MAX_XS_PAATH 100 + +static xs_transaction_t t_id =3D XBT_NULL; + +int do_xs_start_transaction(struct xs_handle *xsh) +{ + t_id =3D xs_transaction_start(xsh); + if (t_id =3D=3D XBT_NULL) + return -errno; + + return 0; +} + +int do_xs_end_transaction(struct xs_handle *xsh) +{ + if ( t_id =3D=3D XBT_NULL ) + return -EINVAL; + + if (!xs_transaction_end(xsh, t_id, false)) + return -errno; + + return 0; +} + +int do_xs_write(struct xs_handle *xsh, char *path, char *val) +{ + if ( !xs_write(xsh, t_id, path, val, strlen(val)) ) + { + fprintf(stderr, "failed write: %s\n", path); + return -errno; + } + + return 0; +} + +int do_xs_perms( + struct xs_handle *xsh, char *path, struct xs_permissions *perms, + uint32_t num_perms) +{ + if ( !xs_set_permissions(xsh, t_id, path, perms, num_perms) ) + { + fprintf(stderr, "failed set perm: %s\n", path); + return -errno; + } + + return 0; +} + +int do_xs_write_dir_node_with_perm( + struct xs_handle *xsh, char *dir, char *node, char *val, + struct xs_permissions *perms, uint32_t num_perms) +{ + char full_path[MAX_XS_PAATH]; + int ret =3D 0; + + /* + * mainly for creating a value holding node, but + * also support creating directory nodes. + */ + if ( strlen(node) !=3D 0 ) + snprintf(full_path, MAX_XS_PAATH, "%s/%s", dir, node); + else + snprintf(full_path, MAX_XS_PAATH, "%s", dir); + + ret =3D do_xs_write(xsh, full_path, val); + if ( ret < 0 ) + return ret; + + if ( perms !=3D NULL && num_perms > 0 ) + ret =3D do_xs_perms(xsh, full_path, perms, num_perms); + + return ret; +} + +int do_xs_write_dir_node( + struct xs_handle *xsh, char *dir, char *node, char *val) +{ + return do_xs_write_dir_node_with_perm(xsh, dir, node, val, NULL, 0); +} + +int do_xs_write_dom_with_perm( + struct xs_handle *xsh, uint32_t domid, char *path, char *val, + struct xs_permissions *perms, uint32_t num_perms) +{ + char full_path[MAX_XS_PAATH]; + int ret =3D 0; + + /* + * mainly for creating a value holding node, but + * also support creating directory nodes. + */ + if ( strlen(path) !=3D 0 ) + snprintf(full_path, MAX_XS_PAATH, "/local/domain/%d/%s", domid, pa= th); + else + snprintf(full_path, MAX_XS_PAATH, "/local/domain/%d", domid); + + ret =3D do_xs_write(xsh, full_path, val); + if ( ret < 0 ) + return ret; + + if ( perms !=3D NULL && num_perms > 0 ) + ret =3D do_xs_perms(xsh, full_path, perms, num_perms); + + return ret; +} + +int do_xs_write_dom( + struct xs_handle *xsh, uint32_t domid, char *path, char *val) +{ + return do_xs_write_dom_with_perm(xsh, domid, path, val, NULL, 0); +} diff --git a/tools/helpers/xs-helpers.h b/tools/helpers/xs-helpers.h new file mode 100644 index 000000000000..89585637d4bb --- /dev/null +++ b/tools/helpers/xs-helpers.h @@ -0,0 +1,26 @@ +#ifndef __XS_HELPERS_H +#define __XS_HELPERS_H + +#include + +int do_xs_start_transaction(struct xs_handle *xsh); +int do_xs_end_transaction(struct xs_handle *xsh); + +int do_xs_write(struct xs_handle *xsh, char *path, char *val); +int do_xs_perms( + struct xs_handle *xsh, char *path, struct xs_permissions *perms, + uint32_t num_perms); + +int do_xs_write_dir_node_with_perm( + struct xs_handle *xsh, char *dir, char *node, char *val, + struct xs_permissions *perms, uint32_t num_perms); +int do_xs_write_dir_node( + struct xs_handle *xsh, char *dir, char *node, char *val); + +int do_xs_write_dom_with_perm( + struct xs_handle *xsh, uint32_t domid, char *path, char *val, + struct xs_permissions *perms, uint32_t num_perms); +int do_xs_write_dom( + struct xs_handle *xsh, uint32_t domid, char *path, char *val); + +#endif --=20 2.30.2