From nobody Mon May 20 18:31:35 2024 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=1657141555; cv=pass; d=zohomail.com; s=zohoarc; b=I62cuJPpezveJFRHiQxM+oIt3ueOdU170Ib6z2b8JqpMMbd+ZkZkjjcQUGZbADLG4Rfeaph6b0BGwBc29WyoONhH5cUS+ClDQwgLb9K/d1Bhp2eB0x8fFKutaAjAhmtOq5t5kfox5VemQxlWD5P9DPySE3HeuAA/nbfClLdoCuE= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657141555; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=L/WuBmkg15fArIYdTBpQjhnYAJp4Q8ksywWw6j7y7O8=; b=VHIf8XNTzwU9Yr5IY/hV9zxrrlFs3TRbnESoq7/ZvJDMi6lcLilZGbCOOmPNS7u91wNZGxoXXmbNcsCl/40c1SKLilke26hyUPtE4JVYEDMn5gv/cDCPiYjZdMC2X2pEVcBq2Uf0KQZRUCtXqUzu41Qdz/hYeRP/w4ErJJCpCNo= 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 1657141555238132.6532580548634; Wed, 6 Jul 2022 14:05:55 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.362517.592563 (Exim 4.92) (envelope-from ) id 1o9CCz-0003Xw-It; Wed, 06 Jul 2022 21:05:17 +0000 Received: by outflank-mailman (output) from mailman id 362517.592563; Wed, 06 Jul 2022 21:05:17 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1o9CCz-0003Xp-GG; Wed, 06 Jul 2022 21:05:17 +0000 Received: by outflank-mailman (input) for mailman id 362517; Wed, 06 Jul 2022 21:05: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 1o9CCy-0003HV-Cm for xen-devel@lists.xenproject.org; Wed, 06 Jul 2022 21:05:16 +0000 Received: from sender4-of-o51.zoho.com (sender4-of-o51.zoho.com [136.143.188.51]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 54544701-fd6f-11ec-924f-1f966e50362f; Wed, 06 Jul 2022 23:05:15 +0200 (CEST) Received: from sisyou.hme. (static-72-81-132-2.bltmmd.fios.verizon.net [72.81.132.2]) by mx.zohomail.com with SMTPS id 1657141504075850.5089371575083; Wed, 6 Jul 2022 14:05:04 -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: 54544701-fd6f-11ec-924f-1f966e50362f ARC-Seal: i=1; a=rsa-sha256; t=1657141506; cv=none; d=zohomail.com; s=zohoarc; b=BjNz+vhtn7JZ5oNQY7AaCvfLF5xunP4mzu+LiWjrFMTtB3Ri1YD/I59SoR6a+VYGP40lFvuDZIoIeAFqkOM8qGMrtmEYAKutRzGblzu8U6e5jIZPRS0fSlWK3Zk7JffUEB4bz7WtnbF0QfeAbn7OV797ZCoc0+yoIz6MTRpFtjc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657141506; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=L/WuBmkg15fArIYdTBpQjhnYAJp4Q8ksywWw6j7y7O8=; b=BMboqLQtUVXQKRboHj9iTOqC8mgYY3YdmkeTrUDYeRvSO4qZq7EZM5yDTY8+Dj5T47Qi+H2OHuek5SQHssJmEkiUrN5uln8SiSJo41diIH0BQrbn6kJIWAyrOqq3rl51Z2LI5FfP+jTPl7LaX2jngGVvhfn1577XTP3LSjlMRM8= 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=1657141506; 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=L/WuBmkg15fArIYdTBpQjhnYAJp4Q8ksywWw6j7y7O8=; b=KLftkx3bZqqDYrLUBhhP6M3pnGw4ilhiAar0WywhdGCFvn+xvKFDlx/Ye9/i623n e8THaiTSFzoZ53ZxWoTei+e8B/Fg9ehMnHIOnjb58IHArhBmvOKsCFGq2m10n+THzqJ WibxvAosMfuzhxBgJBu5hw+LKsmkYiLa+9sxuxpA= From: "Daniel P. Smith" To: xen-devel@lists.xenproject.org, Volodymyr Babchuk , Wei Liu Cc: "Daniel P. Smith" , scott.davis@starlab.io, christopher.clark@starlab.io, Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Bertrand Marquis , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH v1 01/18] kconfig: allow configuration of maximum modules Date: Wed, 6 Jul 2022 17:04:36 -0400 Message-Id: <20220706210454.30096-2-dpsmith@apertussolutions.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220706210454.30096-1-dpsmith@apertussolutions.com> References: <20220706210454.30096-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: 1657141557428100003 Content-Type: text/plain; charset="utf-8" For x86 the number of allowable multiboot modules varies between the differ= ent entry points, non-efi boot, pvh boot, and efi boot. In the case of both Arm= and x86 this value is fixed to values based on generalized assumptions. With hyperlaunch for x86 and dom0less on Arm, use of static sizes results in lar= ge allocations compiled into the hypervisor that will go unused by many use ca= ses. This commit introduces a Kconfig variable that is set with sane defaults ba= sed on configuration selection. This variable is in turned used as the array si= ze for the cases where a static allocated array of boot modules is declared. Signed-off-by: Daniel P. Smith Reviewed-by: Christopher Clark Reviewed-by: Henry Wang reviewed-by still apply. An example would be if you send a v2, I would=20 --- xen/arch/Kconfig | 12 ++++++++++++ xen/arch/arm/include/asm/setup.h | 5 +++-- xen/arch/x86/efi/efi-boot.h | 2 +- xen/arch/x86/guest/xen/pvh-boot.c | 2 +- xen/arch/x86/setup.c | 4 ++-- 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/xen/arch/Kconfig b/xen/arch/Kconfig index f16eb0df43..24139057be 100644 --- a/xen/arch/Kconfig +++ b/xen/arch/Kconfig @@ -17,3 +17,15 @@ config NR_CPUS For CPU cores which support Simultaneous Multi-Threading or similar technologies, this the number of logical threads which Xen will support. + +config NR_BOOTMODS + int "Maximum number of boot modules that a loader can pass" + range 1 32768 + default "8" if X86 + default "32" if ARM + help + Controls the build-time size of various arrays allocated for + parsing the boot modules passed by a loader when starting Xen. + + This is of particular interest when using Xen's hypervisor domain + capabilities such as dom0less. diff --git a/xen/arch/arm/include/asm/setup.h b/xen/arch/arm/include/asm/se= tup.h index 2bb01ecfa8..312a3e4209 100644 --- a/xen/arch/arm/include/asm/setup.h +++ b/xen/arch/arm/include/asm/setup.h @@ -10,7 +10,8 @@ =20 #define NR_MEM_BANKS 256 =20 -#define MAX_MODULES 32 /* Current maximum useful modules */ +/* Current maximum useful modules */ +#define MAX_MODULES CONFIG_NR_BOOTMODS =20 typedef enum { BOOTMOD_XEN, @@ -38,7 +39,7 @@ struct meminfo { * The domU flag is set for kernels and ramdisks of "xen,domain" nodes. * The purpose of the domU flag is to avoid getting confused in * kernel_probe, where we try to guess which is the dom0 kernel and - * initrd to be compatible with all versions of the multiboot spec.=20 + * initrd to be compatible with all versions of the multiboot spec. */ #define BOOTMOD_MAX_CMDLINE 1024 struct bootmodule { diff --git a/xen/arch/x86/efi/efi-boot.h b/xen/arch/x86/efi/efi-boot.h index 6e65b569b0..4e1a799749 100644 --- a/xen/arch/x86/efi/efi-boot.h +++ b/xen/arch/x86/efi/efi-boot.h @@ -18,7 +18,7 @@ static multiboot_info_t __initdata mbi =3D { * The array size needs to be one larger than the number of modules we * support - see __start_xen(). */ -static module_t __initdata mb_modules[5]; +static module_t __initdata mb_modules[CONFIG_NR_BOOTMODS + 1]; =20 static void __init edd_put_string(u8 *dst, size_t n, const char *src) { diff --git a/xen/arch/x86/guest/xen/pvh-boot.c b/xen/arch/x86/guest/xen/pvh= -boot.c index 498625eae0..834b1ad16b 100644 --- a/xen/arch/x86/guest/xen/pvh-boot.c +++ b/xen/arch/x86/guest/xen/pvh-boot.c @@ -32,7 +32,7 @@ bool __initdata pvh_boot; uint32_t __initdata pvh_start_info_pa; =20 static multiboot_info_t __initdata pvh_mbi; -static module_t __initdata pvh_mbi_mods[8]; +static module_t __initdata pvh_mbi_mods[CONFIG_NR_BOOTMOD + 1]; static const char *__initdata pvh_loader =3D "PVH Directboot"; =20 static void __init convert_pvh_info(multiboot_info_t **mbi, diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index f08b07b8de..2aa1e28c8f 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -1020,9 +1020,9 @@ void __init noreturn __start_xen(unsigned long mbi_p) panic("dom0 kernel not specified. Check bootloader configuration\n= "); =20 /* Check that we don't have a silly number of modules. */ - if ( mbi->mods_count > sizeof(module_map) * 8 ) + if ( mbi->mods_count > CONFIG_NR_BOOTMODS ) { - mbi->mods_count =3D sizeof(module_map) * 8; + mbi->mods_count =3D CONFIG_NR_BOOTMODS; printk("Excessive multiboot modules - using the first %u only\n", mbi->mods_count); } --=20 2.20.1 From nobody Mon May 20 18:31:35 2024 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=1657141562; cv=pass; d=zohomail.com; s=zohoarc; b=AGbH7FdHg2tjNEtK8oFExs6qYU2yJuzR+YpXUXREUtEJPMPQF+SaLDYYcLKfY9XEkLtn3NG+RzuNgy7EDZe5u+4JuXgamPESmxEh6cAs1iRStMlBYSDfx9Pt7z0+2+rFGZsQpKhqof9xXAQoNtAysJqlHGdJxF0J0rCYl6E8Zuo= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657141562; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=l2m2wX7dK/BSzsuu2D0GCQSog1dryKjASVBBBj6qczc=; b=MRpA7KCgka5xxH6n3rHslIaU6uYdbOEhmAX1AUA8eAmEPQqPk0wUd+5QAO7lJyjeGmEAd+tJ2MEHLycfDrA4h77RvsRv1FDlW7wNoTD0FFgKsOwDTx5Z+jPDXwTJ201KShkxi4dGWVbg9hqAF6JXwqBpOwF0LyEOxGEC/emV+b0= 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 1657141562538104.0892419042782; Wed, 6 Jul 2022 14:06:02 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.362522.592575 (Exim 4.92) (envelope-from ) id 1o9CDR-0004EL-TG; Wed, 06 Jul 2022 21:05:45 +0000 Received: by outflank-mailman (output) from mailman id 362522.592575; Wed, 06 Jul 2022 21:05:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1o9CDR-0004EE-PN; Wed, 06 Jul 2022 21:05:45 +0000 Received: by outflank-mailman (input) for mailman id 362522; Wed, 06 Jul 2022 21:05:45 +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 1o9CDQ-0003HV-Ux for xen-devel@lists.xenproject.org; Wed, 06 Jul 2022 21:05:45 +0000 Received: from sender4-of-o51.zoho.com (sender4-of-o51.zoho.com [136.143.188.51]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 6569030e-fd6f-11ec-924f-1f966e50362f; Wed, 06 Jul 2022 23:05:44 +0200 (CEST) Received: from sisyou.hme. (static-72-81-132-2.bltmmd.fios.verizon.net [72.81.132.2]) by mx.zohomail.com with SMTPS id 1657141505647707.2048656643256; Wed, 6 Jul 2022 14:05:05 -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: 6569030e-fd6f-11ec-924f-1f966e50362f ARC-Seal: i=1; a=rsa-sha256; t=1657141507; cv=none; d=zohomail.com; s=zohoarc; b=F53S/fI0beguCKqm60AlEo0l4La9lTDv2Z7hwppp/9JlW0psYjuMVI0JmH4kZ7D9k6SngKWBHKNlTysjOK4KKdVAzHrLdvM10X44uJnj+gmSTx0+6DpA/Tgov94a+pEBYWiRahgXLUWzQXZIAVRxda/LAnACOEl/CXKLg+4BgRU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657141507; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=l2m2wX7dK/BSzsuu2D0GCQSog1dryKjASVBBBj6qczc=; b=d+iNWiPGJvePrA882j0GnmZRKYwp7SDM2Da0ONiwyrk6IqSjb2Dtw1JKuV1dz3d7KCiEXj7c6BDCl8TRG75msUAbyX3TEN2WPvPUEyoGoAcVCazhQFrPjDRq6KXH2JFbtbJvMAFfUaFCHsslpVTe1rlZ2/o8vm60SrWzgwkYRXE= 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=1657141507; 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-Type:Content-Transfer-Encoding:Reply-To; bh=l2m2wX7dK/BSzsuu2D0GCQSog1dryKjASVBBBj6qczc=; b=jZ3HDRBPmvgVEqQvaScvN6a7x+QzCI/HJxuq+G73s//FuigK1Kbkxg8aZApKRXPj BNUgBu1PTyrJT02m9fLWYAKzGQaGDLPpB9+5WLIxOIKskirDq4l+geAIgG8ibjTKIky 3h331NjICkt+HVEOcDtZe6s7uq/+nBKzXJQXDkdM= From: "Daniel P. Smith" To: xen-devel@lists.xenproject.org, Wei Liu Cc: "Daniel P. Smith" , scott.davis@starlab.io, christopher.clark@starlab.io, Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , George Dunlap , Julien Grall , Stefano Stabellini Subject: [PATCH v1 02/18] introduction of generalized boot info Date: Wed, 6 Jul 2022 17:04:37 -0400 Message-Id: <20220706210454.30096-3-dpsmith@apertussolutions.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220706210454.30096-1-dpsmith@apertussolutions.com> References: <20220706210454.30096-1-dpsmith@apertussolutions.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External X-ZohoMail-DKIM: pass (identity dpsmith@apertussolutions.com) X-ZM-MESSAGEID: 1657141563472100001 The x86 and Arm architectures represent in memory the general boot informat= ion and boot modules differently despite having commonality. The x86 representations are bound to the multiboot v1 structures while the Arm representations are a slightly generalized meta-data container for the boot material. The multiboot structure does not lend itself well to being expand= ed to accommodate additional metadata, both general and boot module specific. = The Arm structures are not bound to an external specification and thus are able= to be expanded for solutions such as dom0less. This commit introduces a set of structures patterned off the Arm structures= to represent the boot information in a manner that captures common data. The structures provide an arch field to allow arch specific expansions to the structures. The intended goal of these new common structures is to enable commonality between the different architectures. =C2=A0Specifically to enab= le dom0less and hyperlaunch to have a common representation of boot-time constructed domains. Signed-off-by: Daniel P. Smith Reviewed-by: Christopher Clark --- xen/arch/x86/include/asm/bootinfo.h | 48 +++++++++++++++++++++++++ xen/include/xen/bootinfo.h | 54 +++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 xen/arch/x86/include/asm/bootinfo.h create mode 100644 xen/include/xen/bootinfo.h diff --git a/xen/arch/x86/include/asm/bootinfo.h b/xen/arch/x86/include/asm= /bootinfo.h new file mode 100644 index 0000000000..b0754a3ed0 --- /dev/null +++ b/xen/arch/x86/include/asm/bootinfo.h @@ -0,0 +1,48 @@ +#ifndef __ARCH_X86_BOOTINFO_H__ +#define __ARCH_X86_BOOTINFO_H__ + +/* unused for x86 */ +struct arch_bootstring { }; + +struct __packed arch_bootmodule { +#define BOOTMOD_FLAG_X86_RELOCATED 1U << 0 + uint32_t flags; + uint32_t headroom; +}; + +struct __packed arch_boot_info { + uint32_t flags; +#define BOOTINFO_FLAG_X86_MEMLIMITS 1U << 0 +#define BOOTINFO_FLAG_X86_BOOTDEV 1U << 1 +#define BOOTINFO_FLAG_X86_CMDLINE 1U << 2 +#define BOOTINFO_FLAG_X86_MODULES 1U << 3 +#define BOOTINFO_FLAG_X86_AOUT_SYMS 1U << 4 +#define BOOTINFO_FLAG_X86_ELF_SYMS 1U << 5 +#define BOOTINFO_FLAG_X86_MEMMAP 1U << 6 +#define BOOTINFO_FLAG_X86_DRIVES 1U << 7 +#define BOOTINFO_FLAG_X86_BIOSCONFIG 1U << 8 +#define BOOTINFO_FLAG_X86_LOADERNAME 1U << 9 +#define BOOTINFO_FLAG_X86_APM 1U << 10 + + bool xen_guest; + + char *boot_loader_name; + char *kextra; + + uint32_t mem_lower; + uint32_t mem_upper; + + uint32_t mmap_length; + paddr_t mmap_addr; +}; + +struct __packed mb_memmap { + uint32_t size; + uint32_t base_addr_low; + uint32_t base_addr_high; + uint32_t length_low; + uint32_t length_high; + uint32_t type; +}; + +#endif diff --git a/xen/include/xen/bootinfo.h b/xen/include/xen/bootinfo.h new file mode 100644 index 0000000000..42b53a3ca6 --- /dev/null +++ b/xen/include/xen/bootinfo.h @@ -0,0 +1,54 @@ +#ifndef __XEN_BOOTINFO_H__ +#define __XEN_BOOTINFO_H__ + +#include +#include + +#include + +typedef enum { + BOOTMOD_UNKNOWN, + BOOTMOD_XEN, + BOOTMOD_FDT, + BOOTMOD_KERNEL, + BOOTMOD_RAMDISK, + BOOTMOD_XSM, + BOOTMOD_UCODE, + BOOTMOD_GUEST_DTB, +} bootmodule_kind; + +typedef enum { + BOOTSTR_EMPTY, + BOOTSTR_STRING, + BOOTSTR_CMDLINE, +} bootstring_kind; + +#define BOOTMOD_MAX_STRING 1024 +struct __packed boot_string { + bootstring_kind kind; + struct arch_bootstring *arch; + + char bytes[BOOTMOD_MAX_STRING]; + size_t len; +}; + +struct __packed boot_module { + bootmodule_kind kind; + paddr_t start; + mfn_t mfn; + size_t size; + + struct arch_bootmodule *arch; + struct boot_string string; +}; + +struct __packed boot_info { + char *cmdline; + + uint32_t nr_mods; + struct boot_module *mods; + + struct arch_boot_info *arch; +}; + +#endif --=20 2.20.1 From nobody Mon May 20 18:31:35 2024 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=1657141589; cv=pass; d=zohomail.com; s=zohoarc; b=QevkThM82aMax1VIBkMaAcSyTy2DpP4srJC8od2MepuDbWa4JMgXjXV7ZMK1XFeq02kGqq+2P+A/2rDFZgQx/Ukxdla33qryQdmrpRab/UQEn0VUYFmzzDifv2PK0HPnITM+x4PGKJ3/qIC37smh8yRPGi1j20qQfcVSF3PDx60= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657141589; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=8PbN8YfYMbKnd/HJJdmnKs6uVeRv2IP7bTXausYq7vM=; b=PjTQWGouOQKM0ER/LKVuKcuBWr+b6gjLXKb7UKmOK9iis6bi7/MRhXNaL+VHt1v6dmBWNNE1M9HpK7/KiMn2omRmqetVv1zAurpbe9zD+WESK1yLcK94OH2MUH3JhbWZnO6Vp12hyrlXhGcNIWSQOj2r7GTcLwfMmKOgvrj1vqU= 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 1657141589089393.7642778827337; Wed, 6 Jul 2022 14:06:29 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.362528.592586 (Exim 4.92) (envelope-from ) id 1o9CDl-0004mz-CZ; Wed, 06 Jul 2022 21:06:05 +0000 Received: by outflank-mailman (output) from mailman id 362528.592586; Wed, 06 Jul 2022 21:06:05 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1o9CDl-0004mq-8L; Wed, 06 Jul 2022 21:06:05 +0000 Received: by outflank-mailman (input) for mailman id 362528; Wed, 06 Jul 2022 21:06:03 +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 1o9CDj-0003HV-7V for xen-devel@lists.xenproject.org; Wed, 06 Jul 2022 21:06:03 +0000 Received: from sender4-of-o51.zoho.com (sender4-of-o51.zoho.com [136.143.188.51]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 6f1c94b7-fd6f-11ec-924f-1f966e50362f; Wed, 06 Jul 2022 23:06:00 +0200 (CEST) Received: from sisyou.hme. (static-72-81-132-2.bltmmd.fios.verizon.net [72.81.132.2]) by mx.zohomail.com with SMTPS id 165714150753612.876907581220394; Wed, 6 Jul 2022 14:05: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: 6f1c94b7-fd6f-11ec-924f-1f966e50362f ARC-Seal: i=1; a=rsa-sha256; t=1657141508; cv=none; d=zohomail.com; s=zohoarc; b=UPoKzG2vjDE7b44mUrCaQIzMJ9+48/SRss8uMwYa78V+crmn4F+Aw8cFIZGRtmKNvWAw4k9Of3qFHGuR0NBc82WiwPUzEf1NFkr+Oh+W1A5WTYohvy687EmlLkTwwSY/k6VCbL2rRPLbIJ6uk+G4cijzVcr2k4u1tPxq+BnF26Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657141508; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=8PbN8YfYMbKnd/HJJdmnKs6uVeRv2IP7bTXausYq7vM=; b=M/1dQpIsiqa3n4p5sECtc0xdD3SrovU7EJWpH6XQHHChN8Wx5wBMYAYo55Uh9QulREG8lpVntcTLyZkuyXNOGKyteSPhJadaPlKeoERkLY0tSYXPpDoJy5wbdiK2LaDR0orVGwgPdKdGdqUruVBa786X7hvyverAstF4dx699BE= 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=1657141508; 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=8PbN8YfYMbKnd/HJJdmnKs6uVeRv2IP7bTXausYq7vM=; b=dUfDcCAApjSdHeGYzC+Mh6hNUbKqtabL17PTsyQw3jnh6XfVYVAYZ2MgXOvojmja 8mGFYe0SW3rnf9ghwkkPHUkYl1kLuBr/nlXq5ROLgDvEOv2vMGHiuybHcoVmLgAUiFk uUtxrstCaLUniqznhuLH7EB2MJElF7PcC2qgj93w= From: "Daniel P. Smith" To: xen-devel@lists.xenproject.org, Wei Liu , "Daniel P. Smith" Cc: scott.davis@starlab.io, christopher.clark@starlab.io, Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , George Dunlap , Julien Grall , Stefano Stabellini , Daniel De Graaf Subject: [PATCH v1 03/18] x86: adopt new boot info structures Date: Wed, 6 Jul 2022 17:04:38 -0400 Message-Id: <20220706210454.30096-4-dpsmith@apertussolutions.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220706210454.30096-1-dpsmith@apertussolutions.com> References: <20220706210454.30096-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: 1657141589602100001 Content-Type: text/plain; charset="utf-8" This commit replaces the use of the multiboot v1 structures starting at __start_xen(). The majority of this commit is converting the fields being accessed for the startup calculations. While adapting the ucode boot module location logic, this code was refactored to reduce some of the unnecessary complexity. Signed-off-by: Daniel P. Smith Reviewed-by: Christopher Clark --- xen/arch/x86/bzimage.c | 18 +- xen/arch/x86/cpu/microcode/core.c | 133 ++++++++------ xen/arch/x86/dom0_build.c | 11 +- xen/arch/x86/hvm/dom0_build.c | 42 ++--- xen/arch/x86/include/asm/bootinfo.h | 2 +- xen/arch/x86/include/asm/bzimage.h | 5 +- xen/arch/x86/include/asm/dom0_build.h | 15 +- xen/arch/x86/include/asm/setup.h | 14 +- xen/arch/x86/pv/dom0_build.c | 34 ++-- xen/arch/x86/setup.c | 245 +++++++++++++++----------- xen/include/xen/bootinfo.h | 47 +++++ xen/include/xsm/xsm.h | 26 ++- xen/xsm/xsm_core.c | 43 +++-- xen/xsm/xsm_policy.c | 56 +++--- 14 files changed, 413 insertions(+), 278 deletions(-) diff --git a/xen/arch/x86/bzimage.c b/xen/arch/x86/bzimage.c index ac4fd428be..03cb372957 100644 --- a/xen/arch/x86/bzimage.c +++ b/xen/arch/x86/bzimage.c @@ -69,10 +69,8 @@ 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) +unsigned long __init bzimage_headroom( + void *image_start, unsigned long image_length) { struct setup_header *hdr =3D (struct setup_header *)image_start; int err; @@ -91,7 +89,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)) { @@ -104,12 +101,15 @@ 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 int 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 output_len, orig_image_len; + + orig_image_len =3D *image_len - headroom; =20 if ( err < 0 ) return err; @@ -125,7 +125,7 @@ int __init bzimage_parse(void *image_base, void **image= _start, =20 BUG_ON(!(image_base < *image_start)); =20 - output_len =3D output_length(*image_start, orig_image_len); + output_len =3D output_length(*image_start, *image_len); =20 if ( (err =3D perform_gunzip(image_base, *image_start, orig_image_len)= ) > 0 ) err =3D decompress(*image_start, orig_image_len, image_base); diff --git a/xen/arch/x86/cpu/microcode/core.c b/xen/arch/x86/cpu/microcode= /core.c index 452a7ca773..bfdba85796 100644 --- a/xen/arch/x86/cpu/microcode/core.c +++ b/xen/arch/x86/cpu/microcode/core.c @@ -22,6 +22,7 @@ */ =20 #include +#include #include #include #include @@ -54,7 +55,6 @@ */ #define MICROCODE_UPDATE_TIMEOUT_US 1000000 =20 -static module_t __initdata ucode_mod; static signed int __initdata ucode_mod_idx; static bool_t __initdata ucode_mod_forced; static unsigned int nr_cores; @@ -147,74 +147,113 @@ static int __init cf_check parse_ucode(const char *s) } custom_param("ucode", parse_ucode); =20 -void __init microcode_scan_module( - unsigned long *module_map, - const multiboot_info_t *mbi) +#define MICROCODE_MODULE_MATCH 1 +#define MICROCODE_MODULE_NONMATCH 0 + +static int __init microcode_check_module(struct boot_module *mod) { - module_t *mod =3D (module_t *)__va(mbi->mods_addr); uint64_t *_blob_start; unsigned long _blob_size; - struct cpio_data cd; + struct cpio_data cd =3D { NULL, 0 }; long offset; const char *p =3D NULL; - int i; - - ucode_blob.size =3D 0; - if ( !ucode_scan ) - return; =20 if ( boot_cpu_data.x86_vendor =3D=3D X86_VENDOR_AMD ) p =3D "kernel/x86/microcode/AuthenticAMD.bin"; else if ( boot_cpu_data.x86_vendor =3D=3D X86_VENDOR_INTEL ) p =3D "kernel/x86/microcode/GenuineIntel.bin"; else + return -EFAULT; + + _blob_start =3D bootstrap_map(mod); + _blob_size =3D mod->size; + if ( !_blob_start ) + { + printk("Could not map multiboot module (0x%lx) (size: %ld)\n", + mod->start, _blob_size); + /* Non-fatal error, so just say no match */ + return MICROCODE_MODULE_NONMATCH; + } + + cd =3D find_cpio_data(p, _blob_start, _blob_size, &offset /* ignore */= ); + + if ( cd.data ) + { + ucode_blob.size =3D cd.size; + ucode_blob.data =3D cd.data; + + mod->kind =3D BOOTMOD_UCODE; + return MICROCODE_MODULE_MATCH; + } + + bootstrap_map(NULL); + + return 0; +} + +void __init microcode_scan_module(struct boot_info *bi) +{ + int idx =3D 0; + + if ( !ucode_scan ) return; =20 /* - * Try all modules and see whichever could be the microcode blob. + * Try unidentified modules and see which could be the microcode blob. */ - for ( i =3D 1 /* Ignore dom0 kernel */; i < mbi->mods_count; i++ ) + idx =3D bootmodule_next_idx_by_kind(bi, BOOTMOD_UNKNOWN, idx); + while ( idx < bi->nr_mods ) { - if ( !test_bit(i, module_map) ) - continue; + int ret; =20 - _blob_start =3D bootstrap_map(&mod[i]); - _blob_size =3D mod[i].mod_end; - if ( !_blob_start ) + ret =3D microcode_check_module(&bi->mods[idx]); + switch ( ret ) { - printk("Could not map multiboot module #%d (size: %ld)\n", - i, _blob_size); + case MICROCODE_MODULE_MATCH: + return; + case MICROCODE_MODULE_NONMATCH: + idx =3D bootmodule_next_idx_by_kind(bi, BOOTMOD_UNKNOWN, ++idx= ); continue; + default: + printk("%s: (err: %d) unable to check microcode\n", + __func__, ret); + return; } - cd.data =3D NULL; - cd.size =3D 0; - cd =3D find_cpio_data(p, _blob_start, _blob_size, &offset /* ignor= e */); - if ( cd.data ) - { - ucode_blob.size =3D cd.size; - ucode_blob.data =3D cd.data; - break; - } - bootstrap_map(NULL); } } -void __init microcode_grab_module( - unsigned long *module_map, - const multiboot_info_t *mbi) + +void __init microcode_grab_module(struct boot_info *bi) { - module_t *mod =3D (module_t *)__va(mbi->mods_addr); + ucode_blob.size =3D 0; =20 if ( ucode_mod_idx < 0 ) - ucode_mod_idx +=3D mbi->mods_count; - if ( ucode_mod_idx <=3D 0 || ucode_mod_idx >=3D mbi->mods_count || - !__test_and_clear_bit(ucode_mod_idx, module_map) ) - goto scan; - ucode_mod =3D mod[ucode_mod_idx]; -scan: + ucode_mod_idx +=3D bi->nr_mods; + if ( ucode_mod_idx >=3D 0 && ucode_mod_idx <=3D bi->nr_mods && + bi->mods[ucode_mod_idx].kind =3D=3D BOOTMOD_UNKNOWN ) + { + int ret =3D microcode_check_module(&bi->mods[ucode_mod_idx]); + + switch ( ret ) + { + case MICROCODE_MODULE_MATCH: + return; + case MICROCODE_MODULE_NONMATCH: + break; + default: + printk("%s: (err: %d) unable to check microcode\n", + __func__, ret); + return; + } + } + if ( ucode_scan ) - microcode_scan_module(module_map, mbi); + microcode_scan_module(bi); } =20 +/* Undefining as they are not needed anymore */ +#undef MICROCODE_MODULE_MATCH +#undef MICROCODE_MODULE_NONMATCH + static struct microcode_ops __ro_after_init ucode_ops; =20 static DEFINE_SPINLOCK(microcode_mutex); @@ -711,11 +750,6 @@ static int __init cf_check microcode_init(void) ucode_blob.size =3D 0; ucode_blob.data =3D NULL; } - else if ( ucode_mod.mod_end ) - { - bootstrap_map(NULL); - ucode_mod.mod_end =3D 0; - } =20 return 0; } @@ -745,11 +779,6 @@ static int __init early_microcode_update_cpu(void) len =3D ucode_blob.size; data =3D ucode_blob.data; } - else if ( ucode_mod.mod_end ) - { - len =3D ucode_mod.mod_end; - data =3D bootstrap_map(&ucode_mod); - } =20 if ( !data ) return -ENOMEM; @@ -799,7 +828,7 @@ int __init early_microcode_init(void) =20 alternative_vcall(ucode_ops.collect_cpu_info); =20 - if ( ucode_mod.mod_end || ucode_blob.size ) + if ( ucode_blob.size ) rc =3D early_microcode_update_cpu(); =20 return rc; diff --git a/xen/arch/x86/dom0_build.c b/xen/arch/x86/dom0_build.c index 79234f18ff..9ca5a99510 100644 --- a/xen/arch/x86/dom0_build.c +++ b/xen/arch/x86/dom0_build.c @@ -4,6 +4,7 @@ * Copyright (c) 2002-2005, K A Fraser */ =20 +#include #include #include #include @@ -574,9 +575,9 @@ int __init dom0_setup_permissions(struct domain *d) return rc; } =20 -int __init construct_dom0(struct domain *d, const module_t *image, - unsigned long image_headroom, module_t *initrd, - char *cmdline) +int __init construct_dom0( + struct domain *d, const struct boot_module *image, + struct boot_module *initrd, char *cmdline) { int rc; =20 @@ -588,9 +589,9 @@ int __init construct_dom0(struct domain *d, const modul= e_t *image, process_pending_softirqs(); =20 if ( is_hvm_domain(d) ) - rc =3D dom0_construct_pvh(d, image, image_headroom, initrd, cmdlin= e); + rc =3D dom0_construct_pvh(d, image, initrd, cmdline); else if ( is_pv_domain(d) ) - rc =3D dom0_construct_pv(d, image, image_headroom, initrd, cmdline= ); + rc =3D dom0_construct_pv(d, image, initrd, cmdline); else panic("Cannot construct Dom0. No guest interface available\n"); =20 diff --git a/xen/arch/x86/hvm/dom0_build.c b/xen/arch/x86/hvm/dom0_build.c index 1864d048a1..4e903a848d 100644 --- a/xen/arch/x86/hvm/dom0_build.c +++ b/xen/arch/x86/hvm/dom0_build.c @@ -19,9 +19,9 @@ */ =20 #include +#include #include #include -#include #include #include =20 @@ -543,14 +543,13 @@ static paddr_t __init find_memory( return INVALID_PADDR; } =20 -static int __init pvh_load_kernel(struct domain *d, const module_t *image, - unsigned long image_headroom, - module_t *initrd, void *image_base, - char *cmdline, paddr_t *entry, - paddr_t *start_info_addr) +static int __init pvh_load_kernel( + struct domain *d, const struct boot_module *image, + struct boot_module *initrd, void *image_base, char *cmdline, + paddr_t *entry, paddr_t *start_info_addr) { - void *image_start =3D image_base + image_headroom; - unsigned long image_len =3D image->mod_end; + void *image_start =3D image_base + image->arch->headroom; + unsigned long image_len =3D image->size; struct elf_binary elf; struct elf_dom_parms parms; paddr_t last_addr; @@ -559,7 +558,9 @@ static int __init pvh_load_kernel(struct domain *d, con= st module_t *image, 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->arch->headroom, + &image_len)) !=3D 0 ) { printk("Error trying to detect bz compressed kernel\n"); return rc; @@ -606,7 +607,7 @@ static int __init pvh_load_kernel(struct domain *d, con= st module_t *image, * simplify it. */ last_addr =3D find_memory(d, &elf, sizeof(start_info) + - (initrd ? ROUNDUP(initrd->mod_end, PAGE_SIZE) + + (initrd ? ROUNDUP(initrd->size, PAGE_SIZE) + sizeof(mod) : 0) + (cmdline ? ROUNDUP(strlen(cmdline) + 1, @@ -620,8 +621,8 @@ static int __init pvh_load_kernel(struct domain *d, con= st module_t *image, =20 if ( initrd !=3D NULL ) { - rc =3D hvm_copy_to_guest_phys(last_addr, mfn_to_virt(initrd->mod_s= tart), - initrd->mod_end, v); + rc =3D hvm_copy_to_guest_phys(last_addr, maddr_to_virt(initrd->sta= rt), + initrd->size, v); if ( rc ) { printk("Unable to copy initrd to guest\n"); @@ -629,11 +630,11 @@ static int __init pvh_load_kernel(struct domain *d, c= onst module_t *image, } =20 mod.paddr =3D last_addr; - mod.size =3D initrd->mod_end; - last_addr +=3D ROUNDUP(initrd->mod_end, elf_64bit(&elf) ? 8 : 4); - if ( initrd->string ) + mod.size =3D initrd->size; + last_addr +=3D ROUNDUP(initrd->size, elf_64bit(&elf) ? 8 : 4); + if ( initrd->string.kind =3D=3D BOOTSTR_CMDLINE ) { - char *str =3D __va(initrd->string); + char *str =3D initrd->string.bytes; size_t len =3D strlen(str) + 1; =20 rc =3D hvm_copy_to_guest_phys(last_addr, str, len, v); @@ -1216,10 +1217,9 @@ static void __hwdom_init pvh_setup_mmcfg(struct doma= in *d) } } =20 -int __init dom0_construct_pvh(struct domain *d, const module_t *image, - unsigned long image_headroom, - module_t *initrd, - char *cmdline) +int __init dom0_construct_pvh( + struct domain *d, const struct boot_module *image, + struct boot_module *initrd, char *cmdline) { paddr_t entry, start_info; int rc; @@ -1249,7 +1249,7 @@ int __init dom0_construct_pvh(struct domain *d, const= module_t *image, return rc; } =20 - rc =3D pvh_load_kernel(d, image, image_headroom, initrd, bootstrap_map= (image), + rc =3D pvh_load_kernel(d, image, initrd, bootstrap_map(image), cmdline, &entry, &start_info); if ( rc ) { diff --git a/xen/arch/x86/include/asm/bootinfo.h b/xen/arch/x86/include/asm= /bootinfo.h index b0754a3ed0..e5135e402b 100644 --- a/xen/arch/x86/include/asm/bootinfo.h +++ b/xen/arch/x86/include/asm/bootinfo.h @@ -24,7 +24,7 @@ struct __packed arch_boot_info { #define BOOTINFO_FLAG_X86_LOADERNAME 1U << 9 #define BOOTINFO_FLAG_X86_APM 1U << 10 =20 - bool xen_guest; + bool xenguest; =20 char *boot_loader_name; char *kextra; diff --git a/xen/arch/x86/include/asm/bzimage.h b/xen/arch/x86/include/asm/= bzimage.h index 7ed69d3910..5a5a25b4d7 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 int headroom, + unsigned long *image_len); =20 #endif /* __X86_BZIMAGE_H__ */ diff --git a/xen/arch/x86/include/asm/dom0_build.h b/xen/arch/x86/include/a= sm/dom0_build.h index a5f8c9e67f..ad33413710 100644 --- a/xen/arch/x86/include/asm/dom0_build.h +++ b/xen/arch/x86/include/asm/dom0_build.h @@ -1,6 +1,7 @@ #ifndef _DOM0_BUILD_H_ #define _DOM0_BUILD_H_ =20 +#include #include #include =20 @@ -13,15 +14,13 @@ unsigned long dom0_compute_nr_pages(struct domain *d, unsigned long initrd_len); int dom0_setup_permissions(struct domain *d); =20 -int dom0_construct_pv(struct domain *d, const module_t *image, - unsigned long image_headroom, - module_t *initrd, - char *cmdline); +int __init dom0_construct_pv( + struct domain *d, const struct boot_module *image, + struct boot_module *initrd, char *cmdline); =20 -int dom0_construct_pvh(struct domain *d, const module_t *image, - unsigned long image_headroom, - module_t *initrd, - char *cmdline); +int __init dom0_construct_pvh( + struct domain *d, const struct boot_module *image, + struct boot_module *initrd, char *cmdline); =20 unsigned long dom0_paging_pages(const struct domain *d, unsigned long nr_pages); diff --git a/xen/arch/x86/include/asm/setup.h b/xen/arch/x86/include/asm/se= tup.h index 21037b7f31..27c0d61819 100644 --- a/xen/arch/x86/include/asm/setup.h +++ b/xen/arch/x86/include/asm/setup.h @@ -1,7 +1,8 @@ #ifndef __X86_SETUP_H_ #define __X86_SETUP_H_ =20 -#include +#include + #include =20 extern const char __2M_text_start[], __2M_text_end[]; @@ -33,20 +34,17 @@ static inline void vesa_init(void) {}; #endif =20 int construct_dom0( - struct domain *d, - const module_t *kernel, unsigned long kernel_headroom, - module_t *initrd, - char *cmdline); + struct domain *d, const struct boot_module *image, + struct boot_module *initrd, char *cmdline); void setup_io_bitmap(struct domain *d); =20 unsigned long initial_images_nrpages(nodeid_t node); void discard_initial_images(void); -void *bootstrap_map(const module_t *mod); +void *bootstrap_map(const struct boot_module *mod); =20 int xen_in_range(unsigned long mfn); =20 -void microcode_grab_module( - unsigned long *, const multiboot_info_t *); +void microcode_grab_module(struct boot_info *bi); =20 extern uint8_t kbd_shift_flags; =20 diff --git a/xen/arch/x86/pv/dom0_build.c b/xen/arch/x86/pv/dom0_build.c index e501979a86..f6131147ef 100644 --- a/xen/arch/x86/pv/dom0_build.c +++ b/xen/arch/x86/pv/dom0_build.c @@ -4,6 +4,7 @@ * Copyright (c) 2002-2005, K A Fraser */ =20 +#include #include #include #include @@ -294,11 +295,9 @@ static struct page_info * __init alloc_chunk(struct do= main *d, return page; } =20 -int __init dom0_construct_pv(struct domain *d, - const module_t *image, - unsigned long image_headroom, - module_t *initrd, - char *cmdline) +int __init dom0_construct_pv( + struct domain *d, const struct boot_module *image, + struct boot_module *initrd, char *cmdline) { int i, rc, order, machine; bool compatible, compat; @@ -314,9 +313,9 @@ int __init dom0_construct_pv(struct domain *d, start_info_t *si; struct vcpu *v =3D d->vcpu[0]; void *image_base =3D bootstrap_map(image); - unsigned long image_len =3D image->mod_end; - void *image_start =3D image_base + image_headroom; - unsigned long initrd_len =3D initrd ? initrd->mod_end : 0; + unsigned long image_len =3D image->size; + void *image_start =3D image_base + image->arch->headroom; + unsigned long initrd_len =3D initrd ? initrd->size : 0; l4_pgentry_t *l4tab =3D NULL, *l4start =3D NULL; l3_pgentry_t *l3tab =3D NULL, *l3start =3D NULL; l2_pgentry_t *l2tab =3D NULL, *l2start =3D NULL; @@ -355,7 +354,9 @@ int __init dom0_construct_pv(struct domain *d, =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, image->arch->headroom, + &image_len)) !=3D 0 ) return rc; =20 if ( (rc =3D elf_init(&elf, image_start, image_len)) !=3D 0 ) @@ -544,7 +545,7 @@ int __init dom0_construct_pv(struct domain *d, initrd_pfn =3D vinitrd_start ? (vinitrd_start - v_start) >> PAGE_SHIFT : domain_tot_pages(d); - initrd_mfn =3D mfn =3D initrd->mod_start; + initrd_mfn =3D mfn =3D mfn_x(initrd->mfn); count =3D PFN_UP(initrd_len); if ( d->arch.physaddr_bitsize && ((mfn + count - 1) >> (d->arch.physaddr_bitsize - PAGE_SHIFT)= ) ) @@ -559,12 +560,13 @@ int __init dom0_construct_pv(struct domain *d, free_domheap_pages(page, order); page +=3D 1UL << order; } - memcpy(page_to_virt(page), mfn_to_virt(initrd->mod_start), + memcpy(page_to_virt(page), maddr_to_virt(initrd->start), initrd_len); - mpt_alloc =3D (paddr_t)initrd->mod_start << PAGE_SHIFT; + mpt_alloc =3D initrd->start; init_domheap_pages(mpt_alloc, mpt_alloc + PAGE_ALIGN(initrd_len)); - initrd->mod_start =3D initrd_mfn =3D mfn_x(page_to_mfn(page)); + bootmodule_update_mfn(initrd, page_to_mfn(page)); + initrd_mfn =3D mfn_x(initrd->mfn); } else { @@ -572,7 +574,7 @@ int __init dom0_construct_pv(struct domain *d, if ( assign_pages(mfn_to_page(_mfn(mfn++)), 1, d, 0) ) BUG(); } - initrd->mod_end =3D 0; + initrd->size =3D 0; } =20 printk("PHYSICAL MEMORY ARRANGEMENT:\n" @@ -583,7 +585,7 @@ int __init dom0_construct_pv(struct domain *d, nr_pages - domain_tot_pages(d)); if ( initrd ) { - mpt_alloc =3D (paddr_t)initrd->mod_start << PAGE_SHIFT; + mpt_alloc =3D initrd->start; printk("\n Init. ramdisk: %"PRIpaddr"->%"PRIpaddr, mpt_alloc, mpt_alloc + initrd_len); } @@ -804,7 +806,7 @@ int __init dom0_construct_pv(struct domain *d, if ( pfn >=3D initrd_pfn ) { if ( pfn < initrd_pfn + PFN_UP(initrd_len) ) - mfn =3D initrd->mod_start + (pfn - initrd_pfn); + mfn =3D mfn_x(initrd->mfn) + (pfn - initrd_pfn); else mfn -=3D PFN_UP(initrd_len); } diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 2aa1e28c8f..2700f4eb3e 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -270,8 +271,48 @@ static int __init cf_check parse_acpi_param(const char= *s) } custom_param("acpi", parse_acpi_param); =20 -static const module_t *__initdata initial_images; -static unsigned int __initdata nr_initial_images; +struct boot_info __initdata *boot_info; + +static void __init mb_to_bootinfo(multiboot_info_t *mbi, module_t *mods) +{ + static struct boot_info __initdata x86_binfo; + static struct arch_boot_info __initdata arch_x86_binfo; + static struct boot_module __initdata x86_mods[CONFIG_NR_BOOTMODS += 1]; + static struct arch_bootmodule __initdata + arch_x86_mods[CONFIG_NR_BOOTMODS += 1]; + int i; + + x86_binfo.arch =3D &arch_x86_binfo; + x86_binfo.mods =3D x86_mods; + + x86_binfo.cmdline =3D __va(mbi->cmdline); + + /* The BOOTINFO_FLAG_X86_* flags are a 1-1 map to MBI_* */ + arch_x86_binfo.flags =3D mbi->flags; + arch_x86_binfo.mem_upper =3D mbi->mem_upper; + arch_x86_binfo.mem_lower =3D mbi->mem_lower; + arch_x86_binfo.mmap_length =3D mbi->mmap_length; + arch_x86_binfo.mmap_addr =3D mbi->mmap_addr; + arch_x86_binfo.boot_loader_name =3D __va(mbi->boot_loader_name); + + x86_binfo.nr_mods =3D mbi->mods_count; + for ( i =3D 0; i <=3D CONFIG_NR_BOOTMODS; i++) + { + x86_mods[i].arch =3D &arch_x86_mods[i]; + + if ( i < x86_binfo.nr_mods ) + { + bootmodule_update_start(&x86_mods[i], mods[i].mod_start); + x86_mods[i].size =3D mods[i].mod_end - mods[i].mod_start; + + x86_mods[i].string.len =3D strlcpy(x86_mods[i].string.bytes, + __va(mods[i].string), + BOOTMOD_MAX_STRING); + } + } + + boot_info =3D &x86_binfo; +} =20 unsigned long __init initial_images_nrpages(nodeid_t node) { @@ -280,10 +321,10 @@ unsigned long __init initial_images_nrpages(nodeid_t = node) unsigned long nr; unsigned int i; =20 - for ( nr =3D i =3D 0; i < nr_initial_images; ++i ) + for ( nr =3D i =3D 0; i < boot_info->nr_mods; ++i ) { - unsigned long start =3D initial_images[i].mod_start; - unsigned long end =3D start + PFN_UP(initial_images[i].mod_end); + unsigned long start =3D mfn_x(boot_info->mods[i].mfn); + unsigned long end =3D start + PFN_UP(boot_info->mods[i].size); =20 if ( end > node_start && node_end > start ) nr +=3D min(node_end, end) - max(node_start, start); @@ -296,16 +337,15 @@ void __init discard_initial_images(void) { unsigned int i; =20 - for ( i =3D 0; i < nr_initial_images; ++i ) + for ( i =3D 0; i < boot_info->nr_mods; ++i ) { - uint64_t start =3D (uint64_t)initial_images[i].mod_start << PAGE_S= HIFT; + uint64_t start =3D (uint64_t)boot_info->mods[i].start; =20 init_domheap_pages(start, - start + PAGE_ALIGN(initial_images[i].mod_end)); + start + PAGE_ALIGN(boot_info->mods[i].size)); } =20 - nr_initial_images =3D 0; - initial_images =3D NULL; + boot_info->nr_mods =3D 0; } =20 extern char __init_begin[], __init_end[], __bss_start[], __bss_end[]; @@ -392,14 +432,14 @@ static void __init normalise_cpu_order(void) * Ensure a given physical memory range is present in the bootstrap mappin= gs. * Use superpage mappings to ensure that pagetable memory needn't be alloc= ated. */ -void *__init bootstrap_map(const module_t *mod) +void *__init bootstrap_map(const struct boot_module *mod) { static unsigned long __initdata map_cur =3D BOOTSTRAP_MAP_BASE; uint64_t start, end, mask =3D (1L << L2_PAGETABLE_SHIFT) - 1; void *ret; =20 if ( system_state !=3D SYS_STATE_early_boot ) - return mod ? mfn_to_virt(mod->mod_start) : NULL; + return mod ? maddr_to_virt(mod->start) : NULL; =20 if ( !mod ) { @@ -408,8 +448,8 @@ void *__init bootstrap_map(const module_t *mod) return NULL; } =20 - start =3D (uint64_t)mod->mod_start << PAGE_SHIFT; - end =3D start + mod->mod_end; + start =3D (uint64_t)mod->start; + end =3D start + mod->size; if ( start >=3D end ) return NULL; =20 @@ -436,25 +476,25 @@ static void *__init move_memory( =20 while ( size ) { - module_t mod; + struct boot_module mod; unsigned int soffs =3D src & mask; unsigned int doffs =3D dst & mask; unsigned int sz; void *d, *s; =20 - mod.mod_start =3D (src - soffs) >> PAGE_SHIFT; - mod.mod_end =3D soffs + size; - if ( mod.mod_end > blksz ) - mod.mod_end =3D blksz; - sz =3D mod.mod_end - soffs; + mod.start =3D src - soffs; + mod.size =3D soffs + size; + if ( mod.size > blksz ) + mod.size =3D blksz; + sz =3D mod.size - soffs; s =3D bootstrap_map(&mod); =20 - mod.mod_start =3D (dst - doffs) >> PAGE_SHIFT; - mod.mod_end =3D doffs + size; - if ( mod.mod_end > blksz ) - mod.mod_end =3D blksz; - if ( sz > mod.mod_end - doffs ) - sz =3D mod.mod_end - doffs; + mod.start =3D dst - doffs; + mod.size =3D doffs + size; + if ( mod.size > blksz ) + mod.size =3D blksz; + if ( sz > mod.size - doffs ) + sz =3D mod.size - doffs; d =3D bootstrap_map(&mod); =20 memmove(d + doffs, s + soffs, sz); @@ -475,7 +515,7 @@ static void *__init move_memory( #undef BOOTSTRAP_MAP_LIMIT =20 static uint64_t __init consider_modules( - uint64_t s, uint64_t e, uint32_t size, const module_t *mod, + uint64_t s, uint64_t e, uint32_t size, const struct boot_module *mod, unsigned int nr_mods, unsigned int this_mod) { unsigned int i; @@ -485,8 +525,8 @@ static uint64_t __init consider_modules( =20 for ( i =3D 0; i < nr_mods ; ++i ) { - uint64_t start =3D (uint64_t)mod[i].mod_start << PAGE_SHIFT; - uint64_t end =3D start + PAGE_ALIGN(mod[i].mod_end); + uint64_t start =3D (uint64_t)mod[i].start; + uint64_t end =3D start + PAGE_ALIGN(mod[i].size); =20 if ( i =3D=3D this_mod ) continue; @@ -756,10 +796,8 @@ static unsigned int __init copy_bios_e820(struct e820e= ntry *map, unsigned int li return n; } =20 -static struct domain *__init create_dom0(const module_t *image, - unsigned long headroom, - module_t *initrd, const char *kex= tra, - const char *loader) +static struct domain *__init create_dom0( + const struct boot_info *bi, const char *kextra, const char *loader) { struct xen_domctl_createdomain dom0_cfg =3D { .flags =3D IS_ENABLED(CONFIG_TBOOT) ? XEN_DOMCTL_CDF_s3_integrity = : 0, @@ -772,9 +810,14 @@ static struct domain *__init create_dom0(const module_= t *image, .misc_flags =3D opt_dom0_msr_relaxed ? XEN_X86_MSR_RELAXED : 0, }, }; + struct boot_module *image =3D bootmodule_next_by_kind(bi, BOOTMOD_KERN= EL, 0); + struct boot_module *initrd =3D bootmodule_next_by_kind(bi, BOOTMOD_RAM= DISK, 0); struct domain *d; char *cmdline; - domid_t domid; + domid_t domid =3D 0; + + if ( image =3D=3D NULL ) + panic("Error creating d%uv0\n", domid); =20 if ( opt_dom0_pvh ) { @@ -801,7 +844,8 @@ static struct domain *__init create_dom0(const module_t= *image, panic("Error creating d%uv0\n", domid); =20 /* Grab the DOM0 command line. */ - cmdline =3D image->string ? __va(image->string) : NULL; + cmdline =3D (image->string.kind =3D=3D BOOTSTR_CMDLINE) ? + image->string.bytes : NULL; if ( cmdline || kextra ) { static char __initdata dom0_cmdline[MAX_GUEST_CMDLINE]; @@ -841,7 +885,7 @@ static struct domain *__init create_dom0(const module_t= *image, write_cr4(read_cr4() & ~X86_CR4_SMAP); } =20 - if ( construct_dom0(d, image, headroom, initrd, cmdline) !=3D 0 ) + if ( construct_dom0(d, image, initrd, cmdline) !=3D 0 ) panic("Could not construct domain 0\n"); =20 if ( cpu_has_smap ) @@ -865,7 +909,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) unsigned int initrdidx, num_parked =3D 0; multiboot_info_t *mbi; module_t *mod; - unsigned long nr_pages, raw_max_page, modules_headroom, module_map[1]; + unsigned long nr_pages, raw_max_page; int i, j, e820_warn =3D 0, bytes =3D 0; unsigned long eb_start, eb_end; bool acpi_boot_table_init_done =3D false, relocated =3D false; @@ -910,12 +954,14 @@ void __init noreturn __start_xen(unsigned long mbi_p) mod =3D __va(mbi->mods_addr); } =20 - loader =3D (mbi->flags & MBI_LOADERNAME) - ? (char *)__va(mbi->boot_loader_name) : "unknown"; + mb_to_bootinfo(mbi, mod); + + loader =3D (boot_info->arch->flags & BOOTINFO_FLAG_X86_LOADERNAME) + ? boot_info->arch->boot_loader_name : "unknown"; =20 /* Parse the command-line options. */ - cmdline =3D cmdline_cook((mbi->flags & MBI_CMDLINE) ? - __va(mbi->cmdline) : NULL, + cmdline =3D cmdline_cook((boot_info->arch->flags & BOOTINFO_FLAG_X86_C= MDLINE) ? + boot_info->cmdline : NULL, loader); if ( (kextra =3D strstr(cmdline, " -- ")) !=3D NULL ) { @@ -1016,19 +1062,22 @@ void __init noreturn __start_xen(unsigned long mbi_= p) bootsym(boot_edd_info_nr)); =20 /* Check that we have at least one Multiboot module. */ - if ( !(mbi->flags & MBI_MODULES) || (mbi->mods_count =3D=3D 0) ) + if ( !(boot_info->arch->flags & BOOTINFO_FLAG_X86_MODULES) || + (boot_info->nr_mods =3D=3D 0) ) panic("dom0 kernel not specified. Check bootloader configuration\n= "); =20 /* Check that we don't have a silly number of modules. */ - if ( mbi->mods_count > CONFIG_NR_BOOTMODS ) + if ( boot_info->nr_mods > CONFIG_NR_BOOTMODS ) { - mbi->mods_count =3D CONFIG_NR_BOOTMODS; + boot_info->nr_mods =3D CONFIG_NR_BOOTMODS ; printk("Excessive multiboot modules - using the first %u only\n", - mbi->mods_count); + boot_info->nr_mods); } =20 - bitmap_fill(module_map, mbi->mods_count); - __clear_bit(0, module_map); /* Dom0 kernel is always first */ + /* Dom0 kernel is the first boot module */ + boot_info->mods[0].kind =3D BOOTMOD_KERNEL; + if ( boot_info->mods[0].string.len ) + boot_info->mods[0].string.kind =3D BOOTSTR_CMDLINE; =20 if ( pvh_boot ) { @@ -1052,19 +1101,19 @@ void __init noreturn __start_xen(unsigned long mbi_= p) } else if ( efi_enabled(EFI_BOOT) ) memmap_type =3D "EFI"; - else if ( (e820_raw.nr_map =3D=20 + else if ( (e820_raw.nr_map =3D copy_bios_e820(e820_raw.map, ARRAY_SIZE(e820_raw.map))) !=3D 0 ) { memmap_type =3D "Xen-e820"; } - else if ( mbi->flags & MBI_MEMMAP ) + else if ( boot_info->arch->flags & BOOTINFO_FLAG_X86_MEMMAP ) { memmap_type =3D "Multiboot-e820"; - while ( bytes < mbi->mmap_length && + while ( bytes < boot_info->arch->mmap_length && e820_raw.nr_map < ARRAY_SIZE(e820_raw.map) ) { - memory_map_t *map =3D __va(mbi->mmap_addr + bytes); + struct mb_memmap *map =3D __va(boot_info->arch->mmap_addr + by= tes); =20 /* * This is a gross workaround for a BIOS bug. Some bootloaders= do @@ -1165,17 +1214,9 @@ void __init noreturn __start_xen(unsigned long mbi_p) set_kexec_crash_area_size((u64)nr_pages << PAGE_SHIFT); kexec_reserve_area(&boot_e820); =20 - initial_images =3D mod; - nr_initial_images =3D mbi->mods_count; - - for ( i =3D 0; !efi_enabled(EFI_LOADER) && i < mbi->mods_count; i++ ) - { - if ( mod[i].mod_start & (PAGE_SIZE - 1) ) + for ( i =3D 0; !efi_enabled(EFI_LOADER) && i < boot_info->nr_mods; i++= ) + if ( boot_info->mods[i].start & (PAGE_SIZE - 1) ) panic("Bootloader didn't honor module alignment request\n"); - mod[i].mod_end -=3D mod[i].mod_start; - mod[i].mod_start >>=3D PAGE_SHIFT; - mod[i].reserved =3D 0; - } =20 if ( xen_phys_start ) { @@ -1186,11 +1227,14 @@ void __init noreturn __start_xen(unsigned long mbi_= p) * respective reserve_e820_ram() invocation below. No need to * query efi_boot_mem_unused() here, though. */ - mod[mbi->mods_count].mod_start =3D virt_to_mfn(_stext); - mod[mbi->mods_count].mod_end =3D __2M_rwdata_end - _stext; + bootmodule_update_start(&boot_info->mods[boot_info->nr_mods], + virt_to_maddr(_stext)); + boot_info->mods[boot_info->nr_mods].size =3D __2M_rwdata_end - _st= ext; } =20 - modules_headroom =3D bzimage_headroom(bootstrap_map(mod), mod->mod_end= ); + boot_info->mods[0].arch->headroom =3D bzimage_headroom( + bootstrap_map(&boot_info->mods[0]), + boot_info->mods[0].size); bootstrap_map(NULL); =20 #ifndef highmem_start @@ -1247,7 +1291,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) { /* Don't overlap with modules. */ end =3D consider_modules(s, e, reloc_size + mask, - mod, mbi->mods_count, -1); + boot_info->mods, boot_info->nr_mods, -1= ); end &=3D ~mask; } else @@ -1351,31 +1395,32 @@ void __init noreturn __start_xen(unsigned long mbi_= p) } =20 /* Is the region suitable for relocating the multiboot modules? */ - for ( j =3D mbi->mods_count - 1; j >=3D 0; j-- ) + for ( j =3D boot_info->nr_mods - 1; j >=3D 0; j-- ) { - unsigned long headroom =3D j ? 0 : modules_headroom; - unsigned long size =3D PAGE_ALIGN(headroom + mod[j].mod_end); + struct boot_module *mod =3D boot_info->mods; + unsigned long headroom =3D mod[j].arch->headroom; + unsigned long size =3D PAGE_ALIGN(headroom + mod[j].size); =20 - if ( mod[j].reserved ) + if ( mod[j].arch->flags & BOOTMOD_FLAG_X86_RELOCATED ) continue; =20 /* Don't overlap with other modules (or Xen itself). */ end =3D consider_modules(s, e, size, mod, - mbi->mods_count + relocated, j); + boot_info->nr_mods + relocated, j); =20 if ( highmem_start && end > highmem_start ) continue; =20 if ( s < end && (headroom || - ((end - size) >> PAGE_SHIFT) > mod[j].mod_start) ) + ((end - size) >> PAGE_SHIFT) > mfn_x(mod[j].mfn)) ) { move_memory(end - size + headroom, - (uint64_t)mod[j].mod_start << PAGE_SHIFT, - mod[j].mod_end, 0); - mod[j].mod_start =3D (end - size) >> PAGE_SHIFT; - mod[j].mod_end +=3D headroom; - mod[j].reserved =3D 1; + (uint64_t)mod[j].start, + mod[j].size, 0); + bootmodule_update_start(&mod[j], end - size); + mod[j].size +=3D headroom; + mod[j].arch->flags |=3D BOOTMOD_FLAG_X86_RELOCATED; } } =20 @@ -1387,8 +1432,9 @@ void __init noreturn __start_xen(unsigned long mbi_p) while ( !kexec_crash_area.start ) { /* Don't overlap with modules (or Xen itself). */ - e =3D consider_modules(s, e, PAGE_ALIGN(kexec_crash_area.size)= , mod, - mbi->mods_count + relocated, -1); + e =3D consider_modules(s, e, PAGE_ALIGN(kexec_crash_area.size), + boot_info->mods, + boot_info->nr_mods + relocated, -1); if ( s >=3D e ) break; if ( e > kexec_crash_area_limit ) @@ -1401,13 +1447,14 @@ void __init noreturn __start_xen(unsigned long mbi_= p) #endif } =20 - if ( modules_headroom && !mod->reserved ) + if ( boot_info->mods[0].arch->headroom && + !(boot_info->mods[0].arch->flags & BOOTMOD_FLAG_X86_RELOCATED) ) panic("Not enough memory to relocate the dom0 kernel image\n"); - for ( i =3D 0; i < mbi->mods_count; ++i ) + for ( i =3D 0; i < boot_info->nr_mods; ++i ) { - uint64_t s =3D (uint64_t)mod[i].mod_start << PAGE_SHIFT; + uint64_t s =3D (uint64_t)boot_info->mods[i].start; =20 - reserve_e820_ram(&boot_e820, s, s + PAGE_ALIGN(mod[i].mod_end)); + reserve_e820_ram(&boot_e820, s, s + PAGE_ALIGN(boot_info->mods[i].= size)); } =20 if ( !xen_phys_start ) @@ -1472,10 +1519,10 @@ void __init noreturn __start_xen(unsigned long mbi_= p) ASSERT(j); } map_e =3D boot_e820.map[j].addr + boot_e820.map[j].size; - for ( j =3D 0; j < mbi->mods_count; ++j ) + for ( j =3D 0; j < boot_info->nr_mods; ++j ) { - uint64_t end =3D pfn_to_paddr(mod[j].mod_start) + - mod[j].mod_end; + uint64_t end =3D mfn_to_maddr(boot_info->mods[j].mfn) + + boot_info->mods[j].size; =20 if ( map_e < end ) map_e =3D end; @@ -1548,13 +1595,14 @@ void __init noreturn __start_xen(unsigned long mbi_= p) } } =20 - for ( i =3D 0; i < mbi->mods_count; ++i ) + for ( i =3D 0; i < boot_info->nr_mods; ++i ) { - set_pdx_range(mod[i].mod_start, - mod[i].mod_start + PFN_UP(mod[i].mod_end)); - map_pages_to_xen((unsigned long)mfn_to_virt(mod[i].mod_start), - _mfn(mod[i].mod_start), - PFN_UP(mod[i].mod_end), PAGE_HYPERVISOR); + set_pdx_range(mfn_x(boot_info->mods[i].mfn), + mfn_x(boot_info->mods[i].mfn) + + PFN_UP(boot_info->mods[i].size)); + map_pages_to_xen((unsigned long)maddr_to_virt(boot_info->mods[i].s= tart), + boot_info->mods[i].mfn, + PFN_UP(boot_info->mods[i].size), PAGE_HYPERVISOR); } =20 #ifdef CONFIG_KEXEC @@ -1704,7 +1752,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) mmio_ro_ranges =3D rangeset_new(NULL, "r/o mmio ranges", RANGESETF_prettyprint_hex); =20 - xsm_multiboot_init(module_map, mbi); + xsm_bootmodule_init(boot_info); =20 /* * IOMMU-related ACPI table parsing may require some of the system dom= ains @@ -1773,7 +1821,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) =20 init_IRQ(); =20 - microcode_grab_module(module_map, mbi); + microcode_grab_module(boot_info); =20 timer_init(); =20 @@ -1921,8 +1969,11 @@ void __init noreturn __start_xen(unsigned long mbi_p) cpu_has_nx ? XENLOG_INFO : XENLOG_WARNING "Warning: ", cpu_has_nx ? "" : "not "); =20 - initrdidx =3D find_first_bit(module_map, mbi->mods_count); - if ( bitmap_weight(module_map, mbi->mods_count) > 1 ) + initrdidx =3D bootmodule_next_idx_by_kind(boot_info, BOOTMOD_UNKNOWN, = 0); + if ( initrdidx < boot_info->nr_mods ) + boot_info->mods[initrdidx].kind =3D BOOTMOD_RAMDISK; + + if ( bootmodule_count_by_kind(boot_info, BOOTMOD_UNKNOWN) > 1 ) printk(XENLOG_WARNING "Multiple initrd candidates, picking module #%u\n", initrdidx); @@ -1931,9 +1982,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) * 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(mod, modules_headroom, - initrdidx < mbi->mods_count ? mod + initrdidx : NUL= L, - kextra, loader); + dom0 =3D create_dom0(boot_info, kextra, loader); if ( !dom0 ) panic("Could not set up DOM0 guest OS\n"); =20 diff --git a/xen/include/xen/bootinfo.h b/xen/include/xen/bootinfo.h index 42b53a3ca6..dde8202f62 100644 --- a/xen/include/xen/bootinfo.h +++ b/xen/include/xen/bootinfo.h @@ -51,4 +51,51 @@ struct __packed boot_info { struct arch_boot_info *arch; }; =20 +extern struct boot_info *boot_info; + +static inline unsigned long bootmodule_next_idx_by_kind( + const struct boot_info *bi, bootmodule_kind kind, unsigned long start) +{ + for ( ; start < bi->nr_mods; start++ ) + if ( bi->mods[start].kind =3D=3D kind ) + return start; + + return bi->nr_mods + 1; +} + +static inline unsigned long bootmodule_count_by_kind( + const struct boot_info *bi, bootmodule_kind kind) +{ + unsigned long count =3D 0; + int i; + + for ( i=3D0; i < bi->nr_mods; i++ ) + if ( bi->mods[i].kind =3D=3D kind ) + count++; + + return count; +} + +static inline struct boot_module *bootmodule_next_by_kind( + const struct boot_info *bi, bootmodule_kind kind, unsigned long start) +{ + for ( ; start < bi->nr_mods; start++ ) + if ( bi->mods[start].kind =3D=3D kind ) + return &bi->mods[start]; + + return NULL; +} + +static inline void bootmodule_update_start(struct boot_module *b, paddr_t = new_start) +{ + b->start =3D new_start; + b->mfn =3D maddr_to_mfn(new_start); +} + +static inline void bootmodule_update_mfn(struct boot_module *b, mfn_t new_= mfn) +{ + b->mfn =3D new_mfn; + b->start =3D mfn_to_maddr(new_mfn); +} + #endif diff --git a/xen/include/xsm/xsm.h b/xen/include/xsm/xsm.h index 8dad03fd3d..930939e925 100644 --- a/xen/include/xsm/xsm.h +++ b/xen/include/xsm/xsm.h @@ -16,8 +16,8 @@ #define __XSM_H__ =20 #include +#include #include -#include =20 /* policy magic number (defined by XSM_MAGIC) */ typedef uint32_t xsm_magic_t; @@ -776,15 +776,14 @@ static inline int xsm_argo_send(const struct domain *= d, const struct domain *t) =20 #endif /* XSM_NO_WRAPPERS */ =20 -#ifdef CONFIG_MULTIBOOT -int xsm_multiboot_init( - unsigned long *module_map, const multiboot_info_t *mbi); -int xsm_multiboot_policy_init( - unsigned long *module_map, const multiboot_info_t *mbi, - void **policy_buffer, size_t *policy_size); -#endif +#ifndef CONFIG_HAS_DEVICE_TREE +int xsm_bootmodule_init(const struct boot_info *bi); +int xsm_bootmodule_policy_init( + const struct boot_info *bi, const unsigned char **policy_buffer, + size_t *policy_size); + +#else =20 -#ifdef CONFIG_HAS_DEVICE_TREE /* * Initialize XSM * @@ -826,15 +825,14 @@ static const inline struct xsm_ops *silo_init(void) =20 #include =20 -#ifdef CONFIG_MULTIBOOT -static inline int xsm_multiboot_init ( - unsigned long *module_map, const multiboot_info_t *mbi) +#ifndef CONFIG_HAS_DEVICE_TREE +static inline int xsm_bootmodule_init(const struct boot_info *bi) { return 0; } -#endif =20 -#ifdef CONFIG_HAS_DEVICE_TREE +#else + static inline int xsm_dt_init(void) { return 0; diff --git a/xen/xsm/xsm_core.c b/xen/xsm/xsm_core.c index 2286a502e3..8631f3e7bb 100644 --- a/xen/xsm/xsm_core.c +++ b/xen/xsm/xsm_core.c @@ -10,6 +10,9 @@ * as published by the Free Software Foundation. */ =20 +#include +#include +#include #include #include #include @@ -138,26 +141,34 @@ static int __init xsm_core_init(const void *policy_bu= ffer, size_t policy_size) return 0; } =20 -#ifdef CONFIG_MULTIBOOT -int __init xsm_multiboot_init( - unsigned long *module_map, const multiboot_info_t *mbi) +/* + * ifdef'ing this against multiboot is no longer valid as the boot module + * is agnostic and it will be possible to dropped the ifndef should Arm + * adopt boot info + */ +#ifndef CONFIG_HAS_DEVICE_TREE +int __init xsm_bootmodule_init(const struct boot_info *bi) { int ret =3D 0; - void *policy_buffer =3D NULL; + const unsigned char *policy_buffer =3D NULL; size_t policy_size =3D 0; =20 printk("XSM Framework v" XSM_FRAMEWORK_VERSION " initialized\n"); =20 if ( XSM_MAGIC ) { - ret =3D xsm_multiboot_policy_init(module_map, mbi, &policy_buffer, - &policy_size); - if ( ret ) - { - bootstrap_map(NULL); - printk(XENLOG_ERR "Error %d initializing XSM policy\n", ret); - return -EINVAL; - } + int ret =3D xsm_bootmodule_policy_init(bi, &policy_buffer, &policy= _size); + bootstrap_map(NULL); + + if ( ret =3D=3D -ENOENT ) + /* + * The XSM module needs a policy file but one was not located. + * Report as a warning and continue as the XSM module may late + * load a policy file. + */ + printk(XENLOG_WARNING "xsm: starting without a policy loaded!\= n"); + else if ( ret ) + panic("Error %d initializing XSM policy\n", ret); } =20 ret =3D xsm_core_init(policy_buffer, policy_size); @@ -165,9 +176,9 @@ int __init xsm_multiboot_init( =20 return 0; } -#endif =20 -#ifdef CONFIG_HAS_DEVICE_TREE +#else + int __init xsm_dt_init(void) { int ret =3D 0; @@ -215,9 +226,9 @@ bool __init has_xsm_magic(paddr_t start) =20 return false; } -#endif +#endif /* CONFIG_HAS_DEVICE_TREE */ =20 -#endif +#endif /* CONFIG_XSM */ =20 long cf_check do_xsm_op(XEN_GUEST_HANDLE_PARAM(void) op) { diff --git a/xen/xsm/xsm_policy.c b/xen/xsm/xsm_policy.c index 8dafbc9381..c55ff2a574 100644 --- a/xen/xsm/xsm_policy.c +++ b/xen/xsm/xsm_policy.c @@ -18,61 +18,61 @@ * */ =20 -#include -#ifdef CONFIG_MULTIBOOT -#include -#include -#endif #include +#include +#include + #ifdef CONFIG_HAS_DEVICE_TREE -# include # include #endif =20 -#ifdef CONFIG_MULTIBOOT -int __init xsm_multiboot_policy_init( - unsigned long *module_map, const multiboot_info_t *mbi, - void **policy_buffer, size_t *policy_size) +# include + +#ifndef CONFIG_HAS_DEVICE_TREE +int __init xsm_bootmodule_policy_init( + const struct boot_info *bi, const unsigned char **policy_buffer, + size_t *policy_size) { - int i; - module_t *mod =3D (module_t *)__va(mbi->mods_addr); - int rc =3D 0; + unsigned long idx =3D 0; + int rc =3D -ENOENT; u32 *_policy_start; unsigned long _policy_len; =20 - /* - * Try all modules and see whichever could be the binary policy. - * Adjust module_map for the module that is the binary policy. - */ - for ( i =3D mbi->mods_count-1; i >=3D 1; i-- ) - { - if ( !test_bit(i, module_map) ) - continue; +#ifdef CONFIG_XSM_FLASK_POLICY + /* Initially set to builtin policy, overriden if boot module is found.= */ + *policy_buffer =3D xsm_flask_init_policy; + *policy_size =3D xsm_flask_init_policy_size; + rc =3D 0; +#endif =20 - _policy_start =3D bootstrap_map(mod + i); - _policy_len =3D mod[i].mod_end; + idx =3D bootmodule_next_idx_by_kind(bi, BOOTMOD_UNKNOWN, idx); + while ( idx < bi->nr_mods ) + { + _policy_start =3D bootstrap_map(&bi->mods[idx]); + _policy_len =3D bi->mods[idx].size; =20 if ( (xsm_magic_t)(*_policy_start) =3D=3D XSM_MAGIC ) { - *policy_buffer =3D _policy_start; + *policy_buffer =3D (unsigned char *)_policy_start; *policy_size =3D _policy_len; =20 printk("Policy len %#lx, start at %p.\n", _policy_len,_policy_start); =20 - __clear_bit(i, module_map); + bi->mods[idx].kind =3D BOOTMOD_XSM; + rc =3D 0; break; - } =20 bootstrap_map(NULL); + idx =3D bootmodule_next_idx_by_kind(bi, BOOTMOD_UNKNOWN, ++idx); } =20 return rc; } -#endif =20 -#ifdef CONFIG_HAS_DEVICE_TREE +#else + int __init xsm_dt_policy_init(void **policy_buffer, size_t *policy_size) { struct bootmodule *mod =3D boot_module_find_by_kind(BOOTMOD_XSM); --=20 2.20.1 From nobody Mon May 20 18:31:35 2024 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=1657141608; cv=pass; d=zohomail.com; s=zohoarc; b=RCBY4VW6tNMj5067ip9/GwGY58U/yPN8mZwpeMOVeFTEBpdRR/hTqYErO3R/Uyn4uT4FOOYONECMHT6j3FBwdE/ZNm4mzscpDzpfdr20gfFu49ShPVfH9duXIxAd9+ywS22KUbmPSvFHJ8RN79Gxd8K/bnlOnkgql9tuI4VvV7M= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657141608; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=E/AB0m5ePJCFrkWnhxRrqf9yCakYmeSAVavi9TF9QYs=; b=m5NIwLBx3ljpVw10OJ0i493VwmNHUXUuHA7r7MeqO54O3taceQIZuTSdTR1vxVXdjahD7KcnD2DPot5snND29OqUREiiqZwRfuRO1Z8kYH0l9oTj/0sVjGooV9J9gMe7/JNiiLSFLMmhaS/7aD7qJaQGWOX3155UoN4kHAUE2hE= 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 165714160879399.59184106262819; Wed, 6 Jul 2022 14:06:48 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.362535.592597 (Exim 4.92) (envelope-from ) id 1o9CE7-0005Ta-QC; Wed, 06 Jul 2022 21:06:27 +0000 Received: by outflank-mailman (output) from mailman id 362535.592597; Wed, 06 Jul 2022 21:06:27 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1o9CE7-0005TR-N7; Wed, 06 Jul 2022 21:06:27 +0000 Received: by outflank-mailman (input) for mailman id 362535; Wed, 06 Jul 2022 21:06:26 +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 1o9CE6-0003HV-37 for xen-devel@lists.xenproject.org; Wed, 06 Jul 2022 21:06:26 +0000 Received: from sender4-of-o51.zoho.com (sender4-of-o51.zoho.com [136.143.188.51]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 7d4658e6-fd6f-11ec-924f-1f966e50362f; Wed, 06 Jul 2022 23:06:24 +0200 (CEST) Received: from sisyou.hme. (static-72-81-132-2.bltmmd.fios.verizon.net [72.81.132.2]) by mx.zohomail.com with SMTPS id 1657141508934176.79563610292462; Wed, 6 Jul 2022 14:05: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: 7d4658e6-fd6f-11ec-924f-1f966e50362f ARC-Seal: i=1; a=rsa-sha256; t=1657141510; cv=none; d=zohomail.com; s=zohoarc; b=R27CxvffThjlCN85YFvIcEeKXShctWJstvrmFXX9vLPYr2jkMH2DqDxvPcqRau4QcFdJlHcWDQNrhyKm/sD/MbnSNTfmNfe5IPpCDHUObz6CMcTXBJG7aZFtOiZX+h3kF8IQQXb5Hx7xZvbnP1VLmEODEjiD8IsSWhAp35QYFH8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657141510; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=E/AB0m5ePJCFrkWnhxRrqf9yCakYmeSAVavi9TF9QYs=; b=L4yilOPz5AgLb7ClL5LK+pDGpZ90TeKwTaYW9OMItBJnzfRMVmiLqD3gxS1kO2vpiEyHFd6RxazobxCQe0Vjz69KkDGeIfsIu17lqitrB7N//kyOvFpbjqadSIQQzK1NNqrWwmalXULTZzZsvz+yrcIlc8/ryJRV6X7lbh5e8uc= 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=1657141510; 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-Type:Content-Transfer-Encoding:Reply-To; bh=E/AB0m5ePJCFrkWnhxRrqf9yCakYmeSAVavi9TF9QYs=; b=ecg9RE4yp5kpuFIsVxGnBl9VZ2goLVel8IwuGsyJxtmowPE3FTFUldySQ4y3UXz0 t3UmfzzsH8bNQkEag+uJjDxRy8sq1byW1Op/hYNlRMuGR98vFHT/uIbhQZ9+GR7nm5H 6oQDY6ekC3qJmhRQxQE1P03SR4gmzXyo9KQaRbuE= From: "Daniel P. Smith" To: xen-devel@lists.xenproject.org, Wei Liu Cc: "Daniel P. Smith" , scott.davis@starlab.io, christopher.clark@starlab.io, Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH v1 04/18] x86: refactor entrypoints to new boot info Date: Wed, 6 Jul 2022 17:04:39 -0400 Message-Id: <20220706210454.30096-5-dpsmith@apertussolutions.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220706210454.30096-1-dpsmith@apertussolutions.com> References: <20220706210454.30096-1-dpsmith@apertussolutions.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External X-ZohoMail-DKIM: pass (identity dpsmith@apertussolutions.com) X-ZM-MESSAGEID: 1657141609705100001 This previous commit added a transition point from multiboot v1 structures = to the new boot info structures at the earliest common point for all the x86 entrypoints. The result is that each of the entrypoints would construct a multiboot v1 structure from the structures used by each entrypoint. =C2=A0T= his meant that multiboot2, EFI, and PVH all converted their structures over to mutlib= oot v1 to only be converted again upon entering __start_xen(). This commit drops the translation function and moves the population of the = new boot info structures down into the various entrypoints. Signed-off-by: Daniel P. Smith Reviewed-by: Christopher Clark --- xen/arch/x86/boot/boot_info32.h | 94 +++++++++++ xen/arch/x86/boot/defs.h | 17 +- xen/arch/x86/boot/reloc.c | 187 +++++++++++++++------- xen/arch/x86/efi/efi-boot.h | 96 ++++++----- xen/arch/x86/guest/xen/pvh-boot.c | 64 +++++--- xen/arch/x86/include/asm/guest/pvh-boot.h | 6 +- xen/arch/x86/setup.c | 71 +++----- xen/common/efi/boot.c | 4 +- 8 files changed, 359 insertions(+), 180 deletions(-) create mode 100644 xen/arch/x86/boot/boot_info32.h diff --git a/xen/arch/x86/boot/boot_info32.h b/xen/arch/x86/boot/boot_info3= 2.h new file mode 100644 index 0000000000..01af950efc --- /dev/null +++ b/xen/arch/x86/boot/boot_info32.h @@ -0,0 +1,94 @@ +#ifndef __BOOT_INFO32_H__ +#define __BOOT_INFO32_H__ + +#include "defs.h" + +typedef enum { + BOOTMOD_UNKNOWN, + BOOTMOD_XEN, + BOOTMOD_FDT, + BOOTMOD_KERNEL, + BOOTMOD_RAMDISK, + BOOTMOD_XSM, + BOOTMOD_UCODE, + BOOTMOD_GUEST_DTB, +} bootmodule_kind; + +typedef enum { + BOOTSTR_EMPTY, + BOOTSTR_STRING, + BOOTSTR_CMDLINE, +} bootstring_kind; + +#define BOOTMOD_MAX_STRING 1024 +struct __packed boot_string { + u32 kind; + u64 arch; + + char bytes[BOOTMOD_MAX_STRING]; + u64 len; +}; + +struct __packed arch_bootmodule { + bool relocated; + u32 flags; +#define BOOTMOD_FLAG_X86_RELOCATED 1U << 0 + u32 headroom; +}; + +struct __packed boot_module { + u32 kind; + u64 start; + u64 mfn; + u64 size; + + u64 arch; + struct boot_string string; +}; + +struct __packed arch_boot_info { + /* uint32_t */ + u32 flags; +#define BOOTINFO_FLAG_X86_MEMLIMITS 1U << 0 +#define BOOTINFO_FLAG_X86_BOOTDEV 1U << 1 +#define BOOTINFO_FLAG_X86_CMDLINE 1U << 2 +#define BOOTINFO_FLAG_X86_MODULES 1U << 3 +#define BOOTINFO_FLAG_X86_AOUT_SYMS 1U << 4 +#define BOOTINFO_FLAG_X86_ELF_SYMS 1U << 5 +#define BOOTINFO_FLAG_X86_MEMMAP 1U << 6 +#define BOOTINFO_FLAG_X86_DRIVES 1U << 7 +#define BOOTINFO_FLAG_X86_BIOSCONFIG 1U << 8 +#define BOOTINFO_FLAG_X86_LOADERNAME 1U << 9 +#define BOOTINFO_FLAG_X86_APM 1U << 10 + + /* bool */ + u8 xen_guest; + + /* char* */ + u64 boot_loader_name; + u64 kextra; + + /* uint32_t */ + u32 mem_lower; + u32 mem_upper; + + /* uint32_t */ + u32 mmap_length; + /* paddr_t */ + u64 mmap_addr; +}; + +struct __packed boot_info { + /* char* */ + u64 cmdline; + + /* uint32_t */ + u32 nr_mods; + /* struct boot_module* */ + u64 mods; + + /* struct arch_boot_info* */ + u64 arch; +}; + +#endif diff --git a/xen/arch/x86/boot/defs.h b/xen/arch/x86/boot/defs.h index f9840044ec..d742a2b52a 100644 --- a/xen/arch/x86/boot/defs.h +++ b/xen/arch/x86/boot/defs.h @@ -22,11 +22,11 @@ =20 #include "../../../include/xen/stdbool.h" =20 -#define __maybe_unused __attribute__((__unused__)) -#define __packed __attribute__((__packed__)) -#define __stdcall __attribute__((__stdcall__)) +#define __maybe_unused __attribute__((__unused__)) +#define __packed __attribute__((__packed__)) +#define __stdcall __attribute__((__stdcall__)) =20 -#define NULL ((void *)0) +#define NULL ((void *)0) =20 #define ALIGN_UP(arg, align) \ (((arg) + (align) - 1) & ~((typeof(arg))(align) - 1)) @@ -43,9 +43,10 @@ (void) (&_x =3D=3D &_y); \ _x > _y ? _x : _y; }) =20 -#define _p(val) ((void *)(unsigned long)(val)) +#define _p(val) ((void *)(unsigned long)(val)) +#define _addr(val) ((unsigned long)(void *)(val)) =20 -#define tolower(c) ((c) | 0x20) +#define tolower(c) ((c) | 0x20) =20 typedef unsigned char u8; typedef unsigned short u16; @@ -57,7 +58,7 @@ typedef u16 uint16_t; typedef u32 uint32_t; typedef u64 uint64_t; =20 -#define U16_MAX ((u16)(~0U)) -#define UINT_MAX (~0U) +#define U16_MAX ((u16)(~0U)) +#define UINT_MAX (~0U) =20 #endif /* __BOOT_DEFS_H__ */ diff --git a/xen/arch/x86/boot/reloc.c b/xen/arch/x86/boot/reloc.c index e22bb974bf..4c40cadff6 100644 --- a/xen/arch/x86/boot/reloc.c +++ b/xen/arch/x86/boot/reloc.c @@ -27,6 +27,7 @@ asm ( ); =20 #include "defs.h" +#include "boot_info32.h" #include "../../../include/xen/multiboot.h" #include "../../../include/xen/multiboot2.h" =20 @@ -138,65 +139,116 @@ static struct hvm_start_info *pvh_info_reloc(u32 in) return out; } =20 -static multiboot_info_t *mbi_reloc(u32 mbi_in) +static struct boot_info *mbi_reloc(u32 mbi_in) { + const multiboot_info_t *mbi =3D _p(mbi_in); + struct boot_info *binfo; + struct arch_boot_info *arch_binfo; int i; - multiboot_info_t *mbi_out; + uint32_t ptr; =20 - mbi_out =3D _p(copy_mem(mbi_in, sizeof(*mbi_out))); + ptr =3D alloc_mem(sizeof(*binfo)); + zero_mem(ptr, sizeof(*binfo)); + binfo =3D _p(ptr); =20 - if ( mbi_out->flags & MBI_CMDLINE ) - mbi_out->cmdline =3D copy_string(mbi_out->cmdline); + ptr =3D alloc_mem(sizeof(*arch_binfo)); + zero_mem(ptr, sizeof(*arch_binfo)); + binfo->arch =3D ptr; + arch_binfo =3D _p(ptr); =20 - if ( mbi_out->flags & MBI_MODULES ) + if ( mbi->flags & MBI_CMDLINE ) + { + ptr =3D copy_string(mbi->cmdline); + binfo->cmdline =3D ptr; + arch_binfo->flags |=3D BOOTINFO_FLAG_X86_CMDLINE; + } + + if ( mbi->flags & MBI_MODULES ) { module_t *mods; + struct boot_module *bi_mods; + struct arch_bootmodule *arch_bi_mods; + + /* + * We have to allocate one more module slot here. At some point + * __start_xen() may put Xen image placement into it. + */ + ptr =3D alloc_mem((mbi->mods_count + 1) * sizeof(*bi_mods)); + binfo->nr_mods =3D mbi->mods_count; + binfo->mods =3D ptr; + bi_mods =3D _p(ptr); =20 - mbi_out->mods_addr =3D copy_mem(mbi_out->mods_addr, - mbi_out->mods_count * sizeof(module_= t)); + ptr =3D alloc_mem((mbi->mods_count + 1) * sizeof(*arch_bi_mods)); + arch_bi_mods =3D _p(ptr); =20 - mods =3D _p(mbi_out->mods_addr); + /* map the +1 allocated for Xen image */ + bi_mods[mbi->mods_count].arch =3D _addr(&arch_bi_mods[mbi->mods_co= unt]); =20 - for ( i =3D 0; i < mbi_out->mods_count; i++ ) + arch_binfo->flags |=3D BOOTINFO_FLAG_X86_MODULES; + + mods =3D _p(mbi->mods_addr); + + for ( i =3D 0; i < mbi->mods_count; i++ ) { + bi_mods[i].start =3D mods[i].mod_start; + bi_mods[i].size =3D mods[i].mod_end - mods[i].mod_start; + if ( mods[i].string ) - mods[i].string =3D copy_string(mods[i].string); + { + int j; + char *c =3D _p(mods[i].string); + + for ( j =3D 0; *c !=3D '\0'; j++, c++ ) + bi_mods[i].string.bytes[j] =3D *c; + + bi_mods[i].string.len =3D j + 1; + } + + bi_mods[i].arch =3D _addr(&arch_bi_mods[i]); } } =20 - if ( mbi_out->flags & MBI_MEMMAP ) - mbi_out->mmap_addr =3D copy_mem(mbi_out->mmap_addr, mbi_out->mmap_= length); - - if ( mbi_out->flags & MBI_LOADERNAME ) - mbi_out->boot_loader_name =3D copy_string(mbi_out->boot_loader_nam= e); + if ( mbi->flags & MBI_MEMMAP ) + { + arch_binfo->mmap_addr =3D copy_mem(mbi->mmap_addr, mbi->mmap_lengt= h); + arch_binfo->mmap_length =3D mbi->mmap_length; + arch_binfo->flags |=3D BOOTINFO_FLAG_X86_MEMMAP; + } =20 - /* Mask features we don't understand or don't relocate. */ - mbi_out->flags &=3D (MBI_MEMLIMITS | - MBI_CMDLINE | - MBI_MODULES | - MBI_MEMMAP | - MBI_LOADERNAME); + if ( mbi->flags & MBI_LOADERNAME ) + { + ptr =3D copy_string(mbi->boot_loader_name); + arch_binfo->boot_loader_name =3D ptr; + arch_binfo->flags |=3D BOOTINFO_FLAG_X86_LOADERNAME; + } =20 - return mbi_out; + return binfo; } =20 -static multiboot_info_t *mbi2_reloc(uint32_t mbi_in, uint32_t video_out) +static struct boot_info *mbi2_reloc(uint32_t mbi_in, uint32_t video_out) { const multiboot2_fixed_t *mbi_fix =3D _p(mbi_in); const multiboot2_memory_map_t *mmap_src; const multiboot2_tag_t *tag; - module_t *mbi_out_mods =3D NULL; memory_map_t *mmap_dst; - multiboot_info_t *mbi_out; + struct boot_info *binfo; + struct arch_boot_info *arch_binfo; + struct boot_module *bi_mods; + struct arch_bootmodule *arch_bi_mods; #ifdef CONFIG_VIDEO struct boot_video_info *video =3D NULL; #endif u32 ptr; unsigned int i, mod_idx =3D 0; =20 - ptr =3D alloc_mem(sizeof(*mbi_out)); - mbi_out =3D _p(ptr); - zero_mem(ptr, sizeof(*mbi_out)); + ptr =3D alloc_mem(sizeof(*binfo)); + zero_mem(ptr, sizeof(*binfo)); + binfo =3D _p(ptr); + + ptr =3D alloc_mem(sizeof(*arch_binfo)); + zero_mem(ptr, sizeof(*arch_binfo)); + binfo->arch =3D ptr; + arch_binfo =3D _p(ptr); =20 /* Skip Multiboot2 information fixed part. */ ptr =3D ALIGN_UP(mbi_in + sizeof(*mbi_fix), MULTIBOOT2_TAG_ALIGN); @@ -206,21 +258,28 @@ static multiboot_info_t *mbi2_reloc(uint32_t mbi_in, = uint32_t video_out) tag =3D _p(ALIGN_UP((u32)tag + tag->size, MULTIBOOT2_TAG_ALIGN))= ) { if ( tag->type =3D=3D MULTIBOOT2_TAG_TYPE_MODULE ) - ++mbi_out->mods_count; + ++binfo->nr_mods; else if ( tag->type =3D=3D MULTIBOOT2_TAG_TYPE_END ) break; } =20 - if ( mbi_out->mods_count ) + if ( binfo->nr_mods ) { - mbi_out->flags |=3D MBI_MODULES; /* * We have to allocate one more module slot here. At some point * __start_xen() may put Xen image placement into it. */ - mbi_out->mods_addr =3D alloc_mem((mbi_out->mods_count + 1) * - sizeof(*mbi_out_mods)); - mbi_out_mods =3D _p(mbi_out->mods_addr); + ptr =3D alloc_mem((binfo->nr_mods + 1) * sizeof(*bi_mods)); + binfo->mods =3D ptr; + bi_mods =3D _p(ptr); + + ptr =3D alloc_mem((binfo->nr_mods + 1) * sizeof(*arch_bi_mods)); + arch_bi_mods =3D _p(ptr); + + /* map the +1 allocated for Xen image */ + bi_mods[binfo->nr_mods].arch =3D _addr(&arch_bi_mods[binfo->nr_mod= s]); + + arch_binfo->flags |=3D BOOTINFO_FLAG_X86_MODULES; } =20 /* Skip Multiboot2 information fixed part. */ @@ -232,39 +291,38 @@ static multiboot_info_t *mbi2_reloc(uint32_t mbi_in, = uint32_t video_out) switch ( tag->type ) { case MULTIBOOT2_TAG_TYPE_BOOT_LOADER_NAME: - mbi_out->flags |=3D MBI_LOADERNAME; ptr =3D get_mb2_string(tag, string, string); - mbi_out->boot_loader_name =3D copy_string(ptr); + arch_binfo->boot_loader_name =3D copy_string(ptr); + arch_binfo->flags |=3D BOOTINFO_FLAG_X86_LOADERNAME; break; =20 case MULTIBOOT2_TAG_TYPE_CMDLINE: - mbi_out->flags |=3D MBI_CMDLINE; ptr =3D get_mb2_string(tag, string, string); - mbi_out->cmdline =3D copy_string(ptr); + binfo->cmdline =3D copy_string(ptr); + arch_binfo->flags |=3D BOOTINFO_FLAG_X86_CMDLINE; break; =20 case MULTIBOOT2_TAG_TYPE_BASIC_MEMINFO: - mbi_out->flags |=3D MBI_MEMLIMITS; - mbi_out->mem_lower =3D get_mb2_data(tag, basic_meminfo, mem_lo= wer); - mbi_out->mem_upper =3D get_mb2_data(tag, basic_meminfo, mem_up= per); + arch_binfo->mem_lower =3D get_mb2_data(tag, basic_meminfo, mem= _lower); + arch_binfo->mem_upper =3D get_mb2_data(tag, basic_meminfo, mem= _upper); break; =20 case MULTIBOOT2_TAG_TYPE_MMAP: if ( get_mb2_data(tag, mmap, entry_size) < sizeof(*mmap_src) ) break; =20 - mbi_out->flags |=3D MBI_MEMMAP; - mbi_out->mmap_length =3D get_mb2_data(tag, mmap, size); - mbi_out->mmap_length -=3D sizeof(multiboot2_tag_mmap_t); - mbi_out->mmap_length /=3D get_mb2_data(tag, mmap, entry_size); - mbi_out->mmap_length *=3D sizeof(*mmap_dst); + arch_binfo->mmap_length =3D get_mb2_data(tag, mmap, size); + arch_binfo->mmap_length -=3D sizeof(multiboot2_tag_mmap_t); + arch_binfo->mmap_length /=3D get_mb2_data(tag, mmap, entry_siz= e); + arch_binfo->mmap_length *=3D sizeof(*mmap_dst); =20 - mbi_out->mmap_addr =3D alloc_mem(mbi_out->mmap_length); + arch_binfo->mmap_addr =3D alloc_mem(arch_binfo->mmap_length); + arch_binfo->flags |=3D BOOTINFO_FLAG_X86_MEMMAP; =20 mmap_src =3D get_mb2_data(tag, mmap, entries); - mmap_dst =3D _p(mbi_out->mmap_addr); + mmap_dst =3D _p(arch_binfo->mmap_addr); =20 - for ( i =3D 0; i < mbi_out->mmap_length / sizeof(*mmap_dst); i= ++ ) + for ( i =3D 0; i < arch_binfo->mmap_length / sizeof(*mmap_dst)= ; i++ ) { /* Init size member properly. */ mmap_dst[i].size =3D sizeof(*mmap_dst); @@ -280,14 +338,27 @@ static multiboot_info_t *mbi2_reloc(uint32_t mbi_in, = uint32_t video_out) break; =20 case MULTIBOOT2_TAG_TYPE_MODULE: - if ( mod_idx >=3D mbi_out->mods_count ) + if ( mod_idx >=3D binfo->nr_mods ) break; =20 - mbi_out_mods[mod_idx].mod_start =3D get_mb2_data(tag, module, = mod_start); - mbi_out_mods[mod_idx].mod_end =3D get_mb2_data(tag, module, mo= d_end); + bi_mods[mod_idx].start =3D get_mb2_data(tag, module, mod_start= ); + bi_mods[mod_idx].size =3D get_mb2_data(tag, module, mod_end) + - bi_mods[mod_idx].start; + ptr =3D get_mb2_string(tag, module, cmdline); - mbi_out_mods[mod_idx].string =3D copy_string(ptr); - mbi_out_mods[mod_idx].reserved =3D 0; + if ( ptr ) + { + int i; + char *c =3D _p(ptr); + + for ( i =3D 0; *c !=3D '\0'; i++, c++ ) + bi_mods[mod_idx].string.bytes[i] =3D *c; + + bi_mods[mod_idx].string.len =3D i + 1; + } + + bi_mods[mod_idx].arch =3D _addr(&arch_bi_mods[mod_idx]); + ++mod_idx; break; =20 @@ -344,11 +415,11 @@ static multiboot_info_t *mbi2_reloc(uint32_t mbi_in, = uint32_t video_out) video->orig_video_isVGA =3D 0x23; #endif =20 - return mbi_out; + return binfo; } =20 -void *__stdcall reloc(uint32_t magic, uint32_t in, uint32_t trampoline, - uint32_t video_info) +void *__stdcall reloc( + uint32_t magic, uint32_t in, uint32_t trampoline, uint32_t video_info) { alloc =3D trampoline; =20 diff --git a/xen/arch/x86/efi/efi-boot.h b/xen/arch/x86/efi/efi-boot.h index 4e1a799749..933eb30a28 100644 --- a/xen/arch/x86/efi/efi-boot.h +++ b/xen/arch/x86/efi/efi-boot.h @@ -11,14 +11,17 @@ #include =20 static struct file __initdata ucode; -static multiboot_info_t __initdata mbi =3D { - .flags =3D MBI_MODULES | MBI_LOADERNAME -}; + +static struct boot_info __initdata efi_bi; +static struct arch_boot_info __initdata efi_bi_arch; /* * The array size needs to be one larger than the number of modules we * support - see __start_xen(). */ -static module_t __initdata mb_modules[CONFIG_NR_BOOTMODS + 1]; +static struct boot_module __initdata efi_mods[CONFIG_NR_BOOTMODS + 1]; +static struct arch_bootmodule __initdata efi_arch_mods[CONFIG_NR_BOOTMODS = + 1]; + +static const char *__initdata efi_loader =3D "PVH Directboot"; =20 static void __init edd_put_string(u8 *dst, size_t n, const char *src) { @@ -269,20 +272,37 @@ static void __init noreturn efi_arch_post_exit_boot(v= oid) : [cr3] "r" (idle_pg_table), [cs] "i" (__HYPERVISOR_CS), [ds] "r" (__HYPERVISOR_DS), - "D" (&mbi) + "D" (&efi_bi) : "memory" ); unreachable(); } =20 -static void __init efi_arch_cfg_file_early(const EFI_LOADED_IMAGE *image, - EFI_FILE_HANDLE dir_handle, - const char *section) +static struct boot_info __init *efi_arch_bootinfo_init(void) { + int i; + + efi_bi.arch =3D &efi_bi_arch; + efi_bi.mods =3D efi_mods; + + for ( i=3D0; i <=3D CONFIG_NR_BOOTMODS; i++ ) + efi_bi.mods[i].arch =3D &efi_arch_mods[i]; + + efi_bi_arch.boot_loader_name =3D _p(efi_loader); + + efi_bi_arch.flags =3D BOOTINFO_FLAG_X86_MODULES | + BOOTINFO_FLAG_X86_LOADERNAME; + return &efi_bi; } =20 -static void __init efi_arch_cfg_file_late(const EFI_LOADED_IMAGE *image, - EFI_FILE_HANDLE dir_handle, - const char *section) +static void __init efi_arch_cfg_file_early( + const EFI_LOADED_IMAGE *image, EFI_FILE_HANDLE dir_handle, + const char *section) +{ +} + +static void __init efi_arch_cfg_file_late( + const EFI_LOADED_IMAGE *image, EFI_FILE_HANDLE dir_handle, + const char *section) { union string name; =20 @@ -294,16 +314,15 @@ static void __init efi_arch_cfg_file_late(const EFI_L= OADED_IMAGE *image, name.s =3D get_value(&cfg, "global", "ucode"); if ( name.s ) { - microcode_set_module(mbi.mods_count); + microcode_set_module(efi_bi.nr_mods); split_string(name.s); read_file(dir_handle, s2w(&name), &ucode, NULL); efi_bs->FreePool(name.w); } } =20 -static void __init efi_arch_handle_cmdline(CHAR16 *image_name, - CHAR16 *cmdline_options, - const char *cfgfile_options) +static void __init efi_arch_handle_cmdline( + CHAR16 *image_name, CHAR16 *cmdline_options, const char *cfgfile_optio= ns) { union string name; =20 @@ -311,10 +330,10 @@ static void __init efi_arch_handle_cmdline(CHAR16 *im= age_name, { name.w =3D cmdline_options; w2s(&name); - place_string(&mbi.cmdline, name.s); + place_string((uint32_t *)efi_bi.cmdline, name.s); } if ( cfgfile_options ) - place_string(&mbi.cmdline, cfgfile_options); + place_string((uint32_t *)efi_bi.cmdline, cfgfile_options); /* Insert image name last, as it gets prefixed to the other options. */ if ( image_name ) { @@ -323,16 +342,10 @@ static void __init efi_arch_handle_cmdline(CHAR16 *im= age_name, } else name.s =3D "xen"; - place_string(&mbi.cmdline, name.s); + place_string((uint32_t *)efi_bi.cmdline, name.s); =20 - if ( mbi.cmdline ) - mbi.flags |=3D MBI_CMDLINE; - /* - * These must not be initialized statically, since the value must - * not get relocated when processing base relocations later. - */ - mbi.boot_loader_name =3D (long)"EFI"; - mbi.mods_addr =3D (long)mb_modules; + if ( efi_bi.cmdline ) + efi_bi_arch.flags |=3D BOOTINFO_FLAG_X86_CMDLINE; } =20 static void __init efi_arch_edd(void) @@ -695,9 +708,8 @@ static void __init efi_arch_memory_setup(void) #undef l2_4G_offset } =20 -static void __init efi_arch_handle_module(const struct file *file, - const CHAR16 *name, - const char *options) +static void __init efi_arch_handle_module( + const struct file *file, const CHAR16 *name, const char *options) { union string local_name; void *ptr; @@ -715,17 +727,25 @@ static void __init efi_arch_handle_module(const struc= t file *file, w2s(&local_name); =20 /* - * If options are provided, put them in - * mb_modules[mbi.mods_count].string after the filename, with a space - * separating them. place_string() prepends strings and adds separati= ng - * spaces, so the call order is reversed. + * Set module string to filename and if options are provided, put them= in + * after the filename, with a space separating them. */ + strlcpy(efi_bi.mods[efi_bi.nr_mods].string.bytes, local_name.s, + BOOTMOD_MAX_STRING); if ( options ) - place_string(&mb_modules[mbi.mods_count].string, options); - place_string(&mb_modules[mbi.mods_count].string, local_name.s); - mb_modules[mbi.mods_count].mod_start =3D file->addr >> PAGE_SHIFT; - mb_modules[mbi.mods_count].mod_end =3D file->size; - ++mbi.mods_count; + { + strlcat(efi_bi.mods[efi_bi.nr_mods].string.bytes, " ", + BOOTMOD_MAX_STRING); + strlcat(efi_bi.mods[efi_bi.nr_mods].string.bytes, options, + BOOTMOD_MAX_STRING); + } + efi_bi.mods[efi_bi.nr_mods].string.kind =3D BOOTSTR_CMDLINE; + + efi_bi.mods[efi_bi.nr_mods].start =3D file->addr; + efi_bi.mods[efi_bi.nr_mods].mfn =3D maddr_to_mfn(file->addr); + efi_bi.mods[efi_bi.nr_mods].size =3D file->size; + + ++efi_bi.nr_mods; efi_bs->FreePool(ptr); } =20 diff --git a/xen/arch/x86/guest/xen/pvh-boot.c b/xen/arch/x86/guest/xen/pvh= -boot.c index 834b1ad16b..28cf5df0a3 100644 --- a/xen/arch/x86/guest/xen/pvh-boot.c +++ b/xen/arch/x86/guest/xen/pvh-boot.c @@ -18,6 +18,7 @@ * * Copyright (c) 2017 Citrix Systems Ltd. */ +#include #include #include #include @@ -31,12 +32,28 @@ bool __initdata pvh_boot; uint32_t __initdata pvh_start_info_pa; =20 -static multiboot_info_t __initdata pvh_mbi; -static module_t __initdata pvh_mbi_mods[CONFIG_NR_BOOTMOD + 1]; -static const char *__initdata pvh_loader =3D "PVH Directboot"; +static struct boot_info __initdata pvh_bi; +static struct arch_boot_info __initdata arch_pvh_bi; +static struct boot_module __initdata pvh_mods[CONFIG_NR_BOOTMODS + 1]; +static struct arch_bootmodule __initdata arch_pvh_mods[CONFIG_NR_BOOTMODS = + 1]; +static char __initdata *pvh_loader =3D "PVH Directboot"; =20 -static void __init convert_pvh_info(multiboot_info_t **mbi, - module_t **mod) +static struct boot_info __init *init_pvh_info(void) +{ + int i; + + pvh_bi.arch =3D &arch_pvh_bi; + pvh_bi.mods =3D pvh_mods; + + for ( i=3D0; i <=3D CONFIG_NR_BOOTMODS; i++ ) + pvh_bi.mods[i].arch =3D &arch_pvh_mods[i]; + + pvh_bi.arch->boot_loader_name =3D pvh_loader; + + return &pvh_bi; +} + +static void __init convert_pvh_info(struct boot_info *bi) { const struct hvm_start_info *pvh_info =3D __va(pvh_start_info_pa); const struct hvm_modlist_entry *entry; @@ -50,23 +67,22 @@ static void __init convert_pvh_info(multiboot_info_t **= mbi, * required. The extra element is used to aid relocation. See * arch/x86/setup.c:__start_xen(). */ - if ( ARRAY_SIZE(pvh_mbi_mods) <=3D pvh_info->nr_modules ) + if ( ARRAY_SIZE(pvh_mods) <=3D pvh_info->nr_modules ) panic("The module array is too small, size %zu, requested %u\n", - ARRAY_SIZE(pvh_mbi_mods), pvh_info->nr_modules); + ARRAY_SIZE(pvh_mods), pvh_info->nr_modules); =20 /* * Turn hvm_start_info into mbi. Luckily all modules are placed under = 4GB * boundary on x86. */ - pvh_mbi.flags =3D MBI_CMDLINE | MBI_MODULES | MBI_LOADERNAME; + bi->arch->flags =3D BOOTINFO_FLAG_X86_CMDLINE | BOOTINFO_FLAG_X86_MODU= LES + | BOOTINFO_FLAG_X86_LOADERNAME; =20 BUG_ON(pvh_info->cmdline_paddr >> 32); - pvh_mbi.cmdline =3D pvh_info->cmdline_paddr; - pvh_mbi.boot_loader_name =3D __pa(pvh_loader); + bi->cmdline =3D _p(__va(pvh_info->cmdline_paddr)); =20 - BUG_ON(pvh_info->nr_modules >=3D ARRAY_SIZE(pvh_mbi_mods)); - pvh_mbi.mods_count =3D pvh_info->nr_modules; - pvh_mbi.mods_addr =3D __pa(pvh_mbi_mods); + BUG_ON(pvh_info->nr_modules >=3D ARRAY_SIZE(pvh_mods)); + bi->nr_mods =3D pvh_info->nr_modules; =20 entry =3D __va(pvh_info->modlist_paddr); for ( i =3D 0; i < pvh_info->nr_modules; i++ ) @@ -74,15 +90,18 @@ static void __init convert_pvh_info(multiboot_info_t **= mbi, BUG_ON(entry[i].paddr >> 32); BUG_ON(entry[i].cmdline_paddr >> 32); =20 - pvh_mbi_mods[i].mod_start =3D entry[i].paddr; - pvh_mbi_mods[i].mod_end =3D entry[i].paddr + entry[i].size; - pvh_mbi_mods[i].string =3D entry[i].cmdline_paddr; + bi->mods[i].start =3D entry[i].paddr; + bi->mods[i].size =3D entry[i].size; + if ( entry[i].cmdline_paddr) + { + char *c =3D _p(__va(entry[i].cmdline_paddr)); + + safe_strcpy(bi->mods[i].string.bytes, c); + bi->mods[i].string.kind =3D BOOTSTR_CMDLINE; + } } =20 rsdp_hint =3D pvh_info->rsdp_paddr; - - *mbi =3D &pvh_mbi; - *mod =3D pvh_mbi_mods; } =20 static void __init get_memory_map(void) @@ -99,13 +118,16 @@ static void __init get_memory_map(void) sanitize_e820_map(e820_raw.map, &e820_raw.nr_map); } =20 -void __init pvh_init(multiboot_info_t **mbi, module_t **mod) +void __init pvh_init(struct boot_info **bi) { - convert_pvh_info(mbi, mod); + *bi =3D init_pvh_info(); + convert_pvh_info(*bi); =20 hypervisor_probe(); ASSERT(xen_guest); =20 + (*bi)->arch->xen_guest =3D xen_guest; + get_memory_map(); } =20 diff --git a/xen/arch/x86/include/asm/guest/pvh-boot.h b/xen/arch/x86/inclu= de/asm/guest/pvh-boot.h index 48ffd1a0b1..120baf4ebb 100644 --- a/xen/arch/x86/include/asm/guest/pvh-boot.h +++ b/xen/arch/x86/include/asm/guest/pvh-boot.h @@ -19,13 +19,13 @@ #ifndef __X86_PVH_BOOT_H__ #define __X86_PVH_BOOT_H__ =20 -#include +#include =20 #ifdef CONFIG_PVH_GUEST =20 extern bool pvh_boot; =20 -void pvh_init(multiboot_info_t **mbi, module_t **mod); +void __init pvh_init(struct boot_info **bi); void pvh_print_info(void); =20 #else @@ -34,7 +34,7 @@ void pvh_print_info(void); =20 #define pvh_boot 0 =20 -static inline void pvh_init(multiboot_info_t **mbi, module_t **mod) +static inline void __init pvh_init(struct boot_info **bi) { ASSERT_UNREACHABLE(); } diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 2700f4eb3e..ad37f4a658 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include @@ -273,47 +272,6 @@ custom_param("acpi", parse_acpi_param); =20 struct boot_info __initdata *boot_info; =20 -static void __init mb_to_bootinfo(multiboot_info_t *mbi, module_t *mods) -{ - static struct boot_info __initdata x86_binfo; - static struct arch_boot_info __initdata arch_x86_binfo; - static struct boot_module __initdata x86_mods[CONFIG_NR_BOOTMODS += 1]; - static struct arch_bootmodule __initdata - arch_x86_mods[CONFIG_NR_BOOTMODS += 1]; - int i; - - x86_binfo.arch =3D &arch_x86_binfo; - x86_binfo.mods =3D x86_mods; - - x86_binfo.cmdline =3D __va(mbi->cmdline); - - /* The BOOTINFO_FLAG_X86_* flags are a 1-1 map to MBI_* */ - arch_x86_binfo.flags =3D mbi->flags; - arch_x86_binfo.mem_upper =3D mbi->mem_upper; - arch_x86_binfo.mem_lower =3D mbi->mem_lower; - arch_x86_binfo.mmap_length =3D mbi->mmap_length; - arch_x86_binfo.mmap_addr =3D mbi->mmap_addr; - arch_x86_binfo.boot_loader_name =3D __va(mbi->boot_loader_name); - - x86_binfo.nr_mods =3D mbi->mods_count; - for ( i =3D 0; i <=3D CONFIG_NR_BOOTMODS; i++) - { - x86_mods[i].arch =3D &arch_x86_mods[i]; - - if ( i < x86_binfo.nr_mods ) - { - bootmodule_update_start(&x86_mods[i], mods[i].mod_start); - x86_mods[i].size =3D mods[i].mod_end - mods[i].mod_start; - - x86_mods[i].string.len =3D strlcpy(x86_mods[i].string.bytes, - __va(mods[i].string), - BOOTMOD_MAX_STRING); - } - } - - boot_info =3D &x86_binfo; -} - unsigned long __init initial_images_nrpages(nodeid_t node) { unsigned long node_start =3D node_start_pfn(node); @@ -900,15 +858,13 @@ static struct domain *__init create_dom0( /* How much of the directmap is prebuilt at compile time. */ #define PREBUILT_MAP_LIMIT (1 << L2_PAGETABLE_SHIFT) =20 -void __init noreturn __start_xen(unsigned long mbi_p) +void __init noreturn __start_xen(unsigned long bi_p) { char *memmap_type =3D NULL; char *cmdline, *kextra, *loader; void *bsp_stack; struct cpu_info *info =3D get_cpu_info(), *bsp_info; unsigned int initrdidx, num_parked =3D 0; - multiboot_info_t *mbi; - module_t *mod; unsigned long nr_pages, raw_max_page; int i, j, e820_warn =3D 0, bytes =3D 0; unsigned long eb_start, eb_end; @@ -945,16 +901,29 @@ void __init noreturn __start_xen(unsigned long mbi_p) =20 if ( pvh_boot ) { - ASSERT(mbi_p =3D=3D 0); - pvh_init(&mbi, &mod); + ASSERT(bi_p =3D=3D 0); + pvh_init(&boot_info); } else { - mbi =3D __va(mbi_p); - mod =3D __va(mbi->mods_addr); - } + /* + * Since addresses were setup before virtual addressing was enable= d, + * fixup pointers to virtual addresses for proper dereferencing. + */ + boot_info =3D __va(bi_p); + boot_info->cmdline =3D __va(boot_info->cmdline); + boot_info->mods =3D __va(boot_info->mods); + boot_info->arch =3D __va(boot_info->arch); + + boot_info->arch->boot_loader_name =3D + __va(boot_info->arch->boot_loader_name); =20 - mb_to_bootinfo(mbi, mod); + for ( i =3D 0; i <=3D boot_info->nr_mods; i++ ) + { + boot_info->mods[i].mfn =3D maddr_to_mfn(boot_info->mods[i].sta= rt); + boot_info->mods[i].arch =3D __va(boot_info->mods[i].arch); + } + } =20 loader =3D (boot_info->arch->flags & BOOTINFO_FLAG_X86_LOADERNAME) ? boot_info->arch->boot_loader_name : "unknown"; diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c index a25e1d29f1..287e48b49a 100644 --- a/xen/common/efi/boot.c +++ b/xen/common/efi/boot.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -11,7 +12,6 @@ #include #include #include -#include #include #include #include @@ -1222,6 +1222,8 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *S= ystemTable) =20 efi_arch_relocate_image(0); =20 + efi_arch_bootinfo_init(); + if ( use_cfg_file ) { EFI_FILE_HANDLE dir_handle; --=20 2.20.1 From nobody Mon May 20 18:31:35 2024 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=1657141712; cv=pass; d=zohomail.com; s=zohoarc; b=lVzwOXHde71sIjQVCV8MosOzODhK+O3pxX3G1ODfW6ezibwa6Mvsccuao+aoVCBZYfL5O6fz3a3uCcqxMN9rWqMpNB/38YCyZ/sNIduBfXVQZtzM+fei2aMeO2c99Fj01Yw112Tl9p5xJrMyWmA4gqMuqMuCVo/NLWzqURTVhxM= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657141712; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=AEMYHg/g52JmQvYb/2PyAV5djmhaoa0EO/NLhuQyF24=; b=jQFgwK7gaciunADSvwe4wT6fqtdn0kEn6G/fWXaRz9GaxraLU637rS41adPAHwOAbxPtnf1D6C+/dDZ9UI80ddE8Y4B55ia5Iqh/hH0dclU9gmdcUwZkDI6LZYsabH3Ye2fVXbNxOcbQbXcLyBOEcq7fA/tSJTtNelti7qYysvE= 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 1657141712299628.2093099480155; Wed, 6 Jul 2022 14:08:32 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.362543.592619 (Exim 4.92) (envelope-from ) id 1o9CFq-0006kT-IR; Wed, 06 Jul 2022 21:08:14 +0000 Received: by outflank-mailman (output) from mailman id 362543.592619; Wed, 06 Jul 2022 21:08:14 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1o9CFq-0006kM-EV; Wed, 06 Jul 2022 21:08:14 +0000 Received: by outflank-mailman (input) for mailman id 362543; Wed, 06 Jul 2022 21:08: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 1o9CEG-0003HV-HK for xen-devel@lists.xenproject.org; Wed, 06 Jul 2022 21:06:36 +0000 Received: from sender4-of-o51.zoho.com (sender4-of-o51.zoho.com [136.143.188.51]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 8429ed03-fd6f-11ec-924f-1f966e50362f; Wed, 06 Jul 2022 23:06:35 +0200 (CEST) Received: from sisyou.hme. (static-72-81-132-2.bltmmd.fios.verizon.net [72.81.132.2]) by mx.zohomail.com with SMTPS id 1657141510464427.8856190700619; Wed, 6 Jul 2022 14:05: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: 8429ed03-fd6f-11ec-924f-1f966e50362f ARC-Seal: i=1; a=rsa-sha256; t=1657141512; cv=none; d=zohomail.com; s=zohoarc; b=Sj9GD3wXJe1li2qmx6rCzq1a5bPyg/IU4xYez+aVKX/fxmGBiqp1rKPXeyTsThr6aET3CADBk7qdBmJvg8yeJPITrq6RLI8RPsgUZtKTelNBNsmokrLWHNv2PnB5dCGAoY1t1QI6YeqkXndAtzbp16tMdjeN8KV1sJ+enU6D0P8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657141512; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=AEMYHg/g52JmQvYb/2PyAV5djmhaoa0EO/NLhuQyF24=; b=Cel0AKW74PFnVWaGk0Nr9FEYBuxI7D17IguiYiq+eJM+i+/zjT7YopKyKdE9jtBJ4eQD10vKCzyGYZfA5kSHsgXCbeZrzBRjTzPUz0SD2TK4py9oGvxsakGYUf8QIXwbkeN3+qy34KfaEFrZ10gzm2/41/MfCxlXOPews7YOc4w= 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=1657141512; 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=AEMYHg/g52JmQvYb/2PyAV5djmhaoa0EO/NLhuQyF24=; b=RPSyGPOqI3Ul6wYg6fIT7iqgt/RRDASbnvyhK7y64L0peQF7aP7hEsbWP1WL4xBQ KREuegYf57Bqj038i0OWJ0jMyNwKwKNBcG/EcgaLClt4w7VZPMP5CgwKIU7HPcXveeZ iPTS1mrz1yYkUGrzTXmYYUcav7Qo0vD2K44nIadw= From: "Daniel P. Smith" To: xen-devel@lists.xenproject.org, Wei Liu Cc: "Daniel P. Smith" , scott.davis@starlab.io, christopher.clark@starlab.io, Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , George Dunlap , Julien Grall , Stefano Stabellini Subject: [PATCH v1 05/18] x86: refactor xen cmdline into general framework Date: Wed, 6 Jul 2022 17:04:40 -0400 Message-Id: <20220706210454.30096-6-dpsmith@apertussolutions.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220706210454.30096-1-dpsmith@apertussolutions.com> References: <20220706210454.30096-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: 1657141714095100003 Content-Type: text/plain; charset="utf-8" This refactors xen cmdline processing into a general framework under the new boot info abstraction. Signed-off-by: Daniel P. Smith Reviewed-by: Christopher Clark --- xen/arch/x86/include/asm/bootinfo.h | 49 ++++++++++++++++++++++++ xen/arch/x86/setup.c | 58 ++++------------------------- xen/include/xen/bootinfo.h | 11 ++++++ 3 files changed, 68 insertions(+), 50 deletions(-) diff --git a/xen/arch/x86/include/asm/bootinfo.h b/xen/arch/x86/include/asm= /bootinfo.h index e5135e402b..2fcd576023 100644 --- a/xen/arch/x86/include/asm/bootinfo.h +++ b/xen/arch/x86/include/asm/bootinfo.h @@ -45,4 +45,53 @@ struct __packed mb_memmap { uint32_t type; }; =20 +static inline bool loader_is_grub2(const char *loader_name) +{ + /* GRUB1=3D"GNU GRUB 0.xx"; GRUB2=3D"GRUB 1.xx" */ + const char *p =3D strstr(loader_name, "GRUB "); + return (p !=3D NULL) && (p[5] !=3D '0'); +} + +static inline char *arch_prepare_cmdline(char *p, struct arch_boot_info *a= rch) +{ + p =3D p ? : ""; + + /* Strip leading whitespace. */ + while ( *p =3D=3D ' ' ) + p++; + + /* GRUB2 and PVH don't not include image name as first item on command= line. */ + if ( !(arch->xenguest || loader_is_grub2(arch->boot_loader_name)) ) + { + /* Strip image name plus whitespace. */ + while ( (*p !=3D ' ') && (*p !=3D '\0') ) + p++; + while ( *p =3D=3D ' ' ) + p++; + } + + return p; +} + +static inline char *arch_bootinfo_prepare_cmdline( + char *cmdline, struct arch_boot_info *arch) +{ + if ( !cmdline ) + return ""; + + if ( (arch->kextra =3D strstr(cmdline, " -- ")) !=3D NULL ) + { + /* + * Options after ' -- ' separator belong to dom0. + * 1. Orphan dom0's options from Xen's command line. + * 2. Skip all but final leading space from dom0's options. + */ + *arch->kextra =3D '\0'; + arch->kextra +=3D 3; + while ( arch->kextra[1] =3D=3D ' ' ) arch->kextra++; + } + + + return arch_prepare_cmdline(cmdline, arch); +} #endif diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index ad37f4a658..e4060d6219 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -716,34 +716,6 @@ ignore_param("edid"); */ ignore_param("placeholder"); =20 -static bool __init loader_is_grub2(const char *loader_name) -{ - /* GRUB1=3D"GNU GRUB 0.xx"; GRUB2=3D"GRUB 1.xx" */ - const char *p =3D strstr(loader_name, "GRUB "); - return (p !=3D NULL) && (p[5] !=3D '0'); -} - -static char * __init cmdline_cook(char *p, const char *loader_name) -{ - p =3D p ? : ""; - - /* Strip leading whitespace. */ - while ( *p =3D=3D ' ' ) - p++; - - /* GRUB2 and PVH don't not include image name as first item on command= line. */ - if ( xen_guest || loader_is_grub2(loader_name) ) - return p; - - /* Strip image name plus whitespace. */ - while ( (*p !=3D ' ') && (*p !=3D '\0') ) - p++; - while ( *p =3D=3D ' ' ) - p++; - - return p; -} - static unsigned int __init copy_bios_e820(struct e820entry *map, unsigned = int limit) { unsigned int n =3D min(bootsym(bios_e820nr), limit); @@ -754,8 +726,7 @@ static unsigned int __init copy_bios_e820(struct e820en= try *map, unsigned int li return n; } =20 -static struct domain *__init create_dom0( - const struct boot_info *bi, const char *kextra, const char *loader) +static struct domain *__init create_dom0(const struct boot_info *bi) { struct xen_domctl_createdomain dom0_cfg =3D { .flags =3D IS_ENABLED(CONFIG_TBOOT) ? XEN_DOMCTL_CDF_s3_integrity = : 0, @@ -804,16 +775,16 @@ static struct domain *__init create_dom0( /* Grab the DOM0 command line. */ cmdline =3D (image->string.kind =3D=3D BOOTSTR_CMDLINE) ? image->string.bytes : NULL; - if ( cmdline || kextra ) + if ( cmdline || bi->arch->kextra ) { static char __initdata dom0_cmdline[MAX_GUEST_CMDLINE]; =20 - cmdline =3D cmdline_cook(cmdline, loader); + cmdline =3D arch_prepare_cmdline(cmdline, bi->arch); safe_strcpy(dom0_cmdline, cmdline); =20 - if ( kextra ) + if ( bi->arch->kextra ) /* kextra always includes exactly one leading space. */ - safe_strcat(dom0_cmdline, kextra); + safe_strcat(dom0_cmdline, bi->arch->kextra); =20 /* Append any extra parameters. */ if ( skip_ioapic_setup && !strstr(dom0_cmdline, "noapic") ) @@ -861,7 +832,7 @@ static struct domain *__init create_dom0( void __init noreturn __start_xen(unsigned long bi_p) { char *memmap_type =3D NULL; - char *cmdline, *kextra, *loader; + char *cmdline, *loader; void *bsp_stack; struct cpu_info *info =3D get_cpu_info(), *bsp_info; unsigned int initrdidx, num_parked =3D 0; @@ -929,20 +900,7 @@ void __init noreturn __start_xen(unsigned long bi_p) ? boot_info->arch->boot_loader_name : "unknown"; =20 /* Parse the command-line options. */ - cmdline =3D cmdline_cook((boot_info->arch->flags & BOOTINFO_FLAG_X86_C= MDLINE) ? - boot_info->cmdline : NULL, - loader); - if ( (kextra =3D strstr(cmdline, " -- ")) !=3D NULL ) - { - /* - * Options after ' -- ' separator belong to dom0. - * 1. Orphan dom0's options from Xen's command line. - * 2. Skip all but final leading space from dom0's options. - */ - *kextra =3D '\0'; - kextra +=3D 3; - while ( kextra[1] =3D=3D ' ' ) kextra++; - } + cmdline =3D bootinfo_prepare_cmdline(boot_info); cmdline_parse(cmdline); =20 /* Must be after command line argument parsing and before @@ -1951,7 +1909,7 @@ void __init noreturn __start_xen(unsigned long bi_p) * 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(boot_info, kextra, loader); + dom0 =3D create_dom0(boot_info); if ( !dom0 ) panic("Could not set up DOM0 guest OS\n"); =20 diff --git a/xen/include/xen/bootinfo.h b/xen/include/xen/bootinfo.h index dde8202f62..477294dc10 100644 --- a/xen/include/xen/bootinfo.h +++ b/xen/include/xen/bootinfo.h @@ -53,6 +53,17 @@ struct __packed boot_info { =20 extern struct boot_info *boot_info; =20 +static inline char *bootinfo_prepare_cmdline(struct boot_info *bi) +{ + bi->cmdline =3D arch_bootinfo_prepare_cmdline(bi->cmdline, bi->arch); + + if ( *bi->cmdline =3D=3D ' ' ) + printk(XENLOG_WARNING "%s: leading whitespace left on cmdline\n", + __func__); + + return bi->cmdline; +} + static inline unsigned long bootmodule_next_idx_by_kind( const struct boot_info *bi, bootmodule_kind kind, unsigned long start) { --=20 2.20.1 From nobody Mon May 20 18:31:35 2024 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=1657141726; cv=pass; d=zohomail.com; s=zohoarc; b=Eolwr+ZA4Du3oB3JAZGFDgd+7qEIc4ajDClLek0Jz/eqKz745uESROHJ2+WerJnl9DPWKBExZ5G0IK5VPGgJHdQ9yqr10yq6f7qfZXL4jimGIUENxJol+iek62jhQphzLavKM8fuBdg4dg9sntHIXRtjTwqq3IOgCaJYzkQBskE= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657141726; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Rrvu8k3I40Yg9tyliHrdCDkFpt7JnYcfPTHvIPVr/5k=; b=U/u1vW8UIPeMSULG6best/CCrAEQaRWsLXNjCtm5oQPs+rKqA9DE48VhjtVfOtQDuw3oCfHYcTUs3bYUNi7AA6SGq5PniEfSwXjiXYxksi6zln6f39P7rK9Zxmubj0GQfXUwk2k8e8bAC2p/DHkUoolXJDu2K+dms7HWmdPnSG8= 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 1657141726363610.9784449791429; Wed, 6 Jul 2022 14:08:46 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.362546.592635 (Exim 4.92) (envelope-from ) id 1o9CG1-0007KG-4x; Wed, 06 Jul 2022 21:08:25 +0000 Received: by outflank-mailman (output) from mailman id 362546.592635; Wed, 06 Jul 2022 21:08: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 1o9CG0-0007Iu-Vc; Wed, 06 Jul 2022 21:08:24 +0000 Received: by outflank-mailman (input) for mailman id 362546; Wed, 06 Jul 2022 21:08:23 +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 1o9CES-0003HV-Iv for xen-devel@lists.xenproject.org; Wed, 06 Jul 2022 21:06:48 +0000 Received: from sender4-of-o51.zoho.com (sender4-of-o51.zoho.com [136.143.188.51]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 8b0347d4-fd6f-11ec-924f-1f966e50362f; Wed, 06 Jul 2022 23:06:47 +0200 (CEST) Received: from sisyou.hme. (static-72-81-132-2.bltmmd.fios.verizon.net [72.81.132.2]) by mx.zohomail.com with SMTPS id 1657141512149369.82004181151626; Wed, 6 Jul 2022 14:05: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: 8b0347d4-fd6f-11ec-924f-1f966e50362f ARC-Seal: i=1; a=rsa-sha256; t=1657141514; cv=none; d=zohomail.com; s=zohoarc; b=AODrPQsGitTUc7ZsIrIKbdIQa6xWtcDmC6BK+chBmc+swcdHPajSLVx5jV/R1hPrR4dQqrrMSykfgyZu0oa+ikEIuYMa9ow7IODBaHHTyNYiWMdS/4D/lphTFwtjtOGY4z25kIRmdhC1xkIs9U65WiS+1Q6S82dxgv4bKphD7X0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657141514; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=Rrvu8k3I40Yg9tyliHrdCDkFpt7JnYcfPTHvIPVr/5k=; b=eWvjAAp/PHtnXwC5AvtBUaLEcij1Ks1iaHLsJtJAs+DUFcbS4c3nS/yqosD8whlzwfcPF2uRx+i02QgAuIsJn9SNACDfFzRv7j/5ke4vGGlNsAyX34LZIc6qaxFQtG+Wz+YeIJT7ZY5uXZIc/0usrp5rTGOH/8k97VkOYMfLyXk= 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=1657141514; 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=Rrvu8k3I40Yg9tyliHrdCDkFpt7JnYcfPTHvIPVr/5k=; b=FFl9IBi7r3Mtikob3O2PQ2vXENqfnpaqW4alNDMGkB4v5T+OWnYywPb/6ISTOLTs cKOSjO+Adt7DQVz5SuZR2tpvdckxGm1flVmsWtaH2/KRwwb38HTuRME0PgLSk30999N KGHKhtDy9EA8B6X3CJx2gGeN3KB3piigHb8wQovQ= From: "Daniel P. Smith" To: xen-devel@lists.xenproject.org, Volodymyr Babchuk Cc: "Daniel P. Smith" , scott.davis@starlab.io, christopher.clark@starlab.io, Stefano Stabellini , Julien Grall , Bertrand Marquis , Andrew Cooper , George Dunlap , Jan Beulich , Wei Liu Subject: [PATCH v1 06/18] fdt: make fdt handling reusable across arch Date: Wed, 6 Jul 2022 17:04:41 -0400 Message-Id: <20220706210454.30096-7-dpsmith@apertussolutions.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220706210454.30096-1-dpsmith@apertussolutions.com> References: <20220706210454.30096-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: 1657141728190100001 Content-Type: text/plain; charset="utf-8" This refactors reusable code from Arm's bootfdt.c and device-tree.h that is general fdt handling code. The Kconfig parameter CORE_DEVICE_TREE is introduced for when the ability of parsing DTB files is needed by a capabil= ity such as hyperlaunch. Signed-off-by: Daniel P. Smith Reviewed-by: Christopher Clark Reviewed-by: Henry Wang --- xen/arch/arm/bootfdt.c | 115 +---------------------------- xen/common/Kconfig | 4 ++ xen/common/Makefile | 3 +- xen/common/fdt.c | 131 ++++++++++++++++++++++++++++++++++ xen/include/xen/device_tree.h | 50 +------------ xen/include/xen/fdt.h | 79 ++++++++++++++++++++ 6 files changed, 218 insertions(+), 164 deletions(-) create mode 100644 xen/common/fdt.c create mode 100644 xen/include/xen/fdt.h diff --git a/xen/arch/arm/bootfdt.c b/xen/arch/arm/bootfdt.c index ec81a45de9..ddedb55fe7 100644 --- a/xen/arch/arm/bootfdt.c +++ b/xen/arch/arm/bootfdt.c @@ -14,53 +14,11 @@ #include #include #include +#include #include #include #include =20 -static bool __init device_tree_node_matches(const void *fdt, int node, - const char *match) -{ - const char *name; - size_t match_len; - - name =3D fdt_get_name(fdt, node, NULL); - match_len =3D strlen(match); - - /* Match both "match" and "match@..." patterns but not - "match-foo". */ - return strncmp(name, match, match_len) =3D=3D 0 - && (name[match_len] =3D=3D '@' || name[match_len] =3D=3D '\0'); -} - -static bool __init device_tree_node_compatible(const void *fdt, int node, - const char *match) -{ - int len, l; - const void *prop; - - prop =3D fdt_getprop(fdt, node, "compatible", &len); - if ( prop =3D=3D NULL ) - return false; - - while ( len > 0 ) { - if ( !dt_compat_cmp(prop, match) ) - return true; - l =3D strlen(prop) + 1; - prop +=3D l; - len -=3D l; - } - - return false; -} - -void __init device_tree_get_reg(const __be32 **cell, u32 address_cells, - u32 size_cells, u64 *start, u64 *size) -{ - *start =3D dt_next_cell(address_cells, cell); - *size =3D dt_next_cell(size_cells, cell); -} - static int __init device_tree_get_meminfo(const void *fdt, int node, const char *prop_name, u32 address_cells, u32 size_cell= s, @@ -108,77 +66,6 @@ static int __init device_tree_get_meminfo(const void *f= dt, int node, return 0; } =20 -u32 __init device_tree_get_u32(const void *fdt, int node, - const char *prop_name, u32 dflt) -{ - const struct fdt_property *prop; - - prop =3D fdt_get_property(fdt, node, prop_name, NULL); - if ( !prop || prop->len < sizeof(u32) ) - return dflt; - - return fdt32_to_cpu(*(uint32_t*)prop->data); -} - -/** - * device_tree_for_each_node - iterate over all device tree sub-nodes - * @fdt: flat device tree. - * @node: parent node to start the search from - * @func: function to call for each sub-node. - * @data: data to pass to @func. - * - * Any nodes nested at DEVICE_TREE_MAX_DEPTH or deeper are ignored. - * - * Returns 0 if all nodes were iterated over successfully. If @func - * returns a value different from 0, that value is returned immediately. - */ -int __init device_tree_for_each_node(const void *fdt, int node, - device_tree_node_func func, - void *data) -{ - /* - * We only care about relative depth increments, assume depth of - * node is 0 for simplicity. - */ - int depth =3D 0; - const int first_node =3D node; - u32 address_cells[DEVICE_TREE_MAX_DEPTH]; - u32 size_cells[DEVICE_TREE_MAX_DEPTH]; - int ret; - - do { - const char *name =3D fdt_get_name(fdt, node, NULL); - u32 as, ss; - - if ( depth >=3D DEVICE_TREE_MAX_DEPTH ) - { - printk("Warning: device tree node `%s' is nested too deep\n", - name); - continue; - } - - as =3D depth > 0 ? address_cells[depth-1] : DT_ROOT_NODE_ADDR_CELL= S_DEFAULT; - ss =3D depth > 0 ? size_cells[depth-1] : DT_ROOT_NODE_SIZE_CELLS_D= EFAULT; - - address_cells[depth] =3D device_tree_get_u32(fdt, node, - "#address-cells", as); - size_cells[depth] =3D device_tree_get_u32(fdt, node, - "#size-cells", ss); - - /* skip the first node */ - if ( node !=3D first_node ) - { - ret =3D func(fdt, node, name, depth, as, ss, data); - if ( ret !=3D 0 ) - return ret; - } - - node =3D fdt_next_node(fdt, node, &depth); - } while ( node >=3D 0 && depth > 0 ); - - return 0; -} - static int __init process_memory_node(const void *fdt, int node, const char *name, int depth, u32 address_cells, u32 size_cells, diff --git a/xen/common/Kconfig b/xen/common/Kconfig index 41a67891bc..9fc6683932 100644 --- a/xen/common/Kconfig +++ b/xen/common/Kconfig @@ -31,8 +31,12 @@ config HAS_ALTERNATIVE config HAS_COMPAT bool =20 +config CORE_DEVICE_TREE + bool + config HAS_DEVICE_TREE bool + select CORE_DEVICE_TREE =20 config HAS_EX_TABLE bool diff --git a/xen/common/Makefile b/xen/common/Makefile index 3baf83d527..ebd3e2d659 100644 --- a/xen/common/Makefile +++ b/xen/common/Makefile @@ -10,6 +10,7 @@ obj-y +=3D domain.o obj-y +=3D event_2l.o obj-y +=3D event_channel.o obj-y +=3D event_fifo.o +obj-$(CONFIG_CORE_DEVICE_TREE) +=3D fdt.o obj-$(CONFIG_CRASH_DEBUG) +=3D gdbstub.o obj-$(CONFIG_GRANT_TABLE) +=3D grant_table.o obj-y +=3D guestcopy.o @@ -73,7 +74,7 @@ obj-y +=3D sched/ obj-$(CONFIG_UBSAN) +=3D ubsan/ =20 obj-$(CONFIG_NEEDS_LIBELF) +=3D libelf/ -obj-$(CONFIG_HAS_DEVICE_TREE) +=3D libfdt/ +obj-$(CONFIG_CORE_DEVICE_TREE) +=3D libfdt/ =20 CONF_FILE :=3D $(if $(patsubst /%,,$(KCONFIG_CONFIG)),$(objtree)/)$(KCONFI= G_CONFIG) $(obj)/config.gz: $(CONF_FILE) diff --git a/xen/common/fdt.c b/xen/common/fdt.c new file mode 100644 index 0000000000..ed9347e5f7 --- /dev/null +++ b/xen/common/fdt.c @@ -0,0 +1,131 @@ +/* + * Flattened Device Tree + * + * Copyright (C) 2012-2014 Citrix Systems, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ +#include +#include +#include +#include +#include + +bool __init device_tree_node_matches( + const void *fdt, int node, const char *match) +{ + const char *name; + size_t match_len; + + name =3D fdt_get_name(fdt, node, NULL); + match_len =3D strlen(match); + + /* Match both "match" and "match@..." patterns but not + "match-foo". */ + return strncmp(name, match, match_len) =3D=3D 0 + && (name[match_len] =3D=3D '@' || name[match_len] =3D=3D '\0'); +} + +bool __init device_tree_node_compatible( + const void *fdt, int node, const char *match) +{ + int len, l; + int mlen; + const void *prop; + + mlen =3D strlen(match); + + prop =3D fdt_getprop(fdt, node, "compatible", &len); + if ( prop =3D=3D NULL ) + return false; + + while ( len > 0 ) { + if ( !dt_compat_cmp(prop, match) ) + return true; + l =3D strlen(prop) + 1; + prop +=3D l; + len -=3D l; + } + + return false; +} + +void __init device_tree_get_reg( + const __be32 **cell, u32 address_cells, u32 size_cells, u64 *start, + u64 *size) +{ + *start =3D dt_next_cell(address_cells, cell); + *size =3D dt_next_cell(size_cells, cell); +} + +u32 __init device_tree_get_u32( + const void *fdt, int node, const char *prop_name, u32 dflt) +{ + const struct fdt_property *prop; + + prop =3D fdt_get_property(fdt, node, prop_name, NULL); + if ( !prop || prop->len < sizeof(u32) ) + return dflt; + + return fdt32_to_cpu(*(uint32_t*)prop->data); +} + +/** + * device_tree_for_each_node - iterate over all device tree sub-nodes + * @fdt: flat device tree. + * @node: parent node to start the search from + * @func: function to call for each sub-node. + * @data: data to pass to @func. + * + * Any nodes nested at DEVICE_TREE_MAX_DEPTH or deeper are ignored. + * + * Returns 0 if all nodes were iterated over successfully. If @func + * returns a value different from 0, that value is returned immediately. + */ +int __init device_tree_for_each_node( + const void *fdt, int node, device_tree_node_func func, void *data) +{ + /* + * We only care about relative depth increments, assume depth of + * node is 0 for simplicity. + */ + int depth =3D 0; + const int first_node =3D node; + u32 address_cells[DEVICE_TREE_MAX_DEPTH]; + u32 size_cells[DEVICE_TREE_MAX_DEPTH]; + int ret; + + do { + const char *name =3D fdt_get_name(fdt, node, NULL); + u32 as, ss; + + if ( depth >=3D DEVICE_TREE_MAX_DEPTH ) + { + printk("Warning: device tree node `%s' is nested too deep\n", + name); + continue; + } + + as =3D depth > 0 ? address_cells[depth-1] : DT_ROOT_NODE_ADDR_CELL= S_DEFAULT; + ss =3D depth > 0 ? size_cells[depth-1] : DT_ROOT_NODE_SIZE_CELLS_D= EFAULT; + + address_cells[depth] =3D device_tree_get_u32(fdt, node, + "#address-cells", as); + size_cells[depth] =3D device_tree_get_u32(fdt, node, + "#size-cells", ss); + + /* skip the first node */ + if ( node !=3D first_node ) + { + ret =3D func(fdt, node, name, depth, as, ss, data); + if ( ret !=3D 0 ) + return ret; + } + + node =3D fdt_next_node(fdt, node, &depth); + } while ( node >=3D 0 && depth > 0 ); + + return 0; +} diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h index 430a1ef445..c98c898ffc 100644 --- a/xen/include/xen/device_tree.h +++ b/xen/include/xen/device_tree.h @@ -14,13 +14,12 @@ #include #include #include +#include #include #include #include #include =20 -#define DEVICE_TREE_MAX_DEPTH 16 - /* * Struct used for matching a device */ @@ -158,17 +157,8 @@ struct dt_raw_irq { #define dt_irq(irq) ((irq)->irq) #define dt_irq_flags(irq) ((irq)->flags) =20 -typedef int (*device_tree_node_func)(const void *fdt, - int node, const char *name, int depth, - u32 address_cells, u32 size_cells, - void *data); - extern const void *device_tree_flattened; =20 -int device_tree_for_each_node(const void *fdt, int node, - device_tree_node_func func, - void *data); - /** * dt_unflatten_host_device_tree - Unflatten the host device tree * @@ -213,14 +203,6 @@ extern const struct dt_device_node *dt_interrupt_contr= oller; struct dt_device_node * dt_find_interrupt_controller(const struct dt_device_match *matches); =20 -#define dt_prop_cmp(s1, s2) strcmp((s1), (s2)) -#define dt_node_cmp(s1, s2) strcasecmp((s1), (s2)) -#define dt_compat_cmp(s1, s2) strcasecmp((s1), (s2)) - -/* Default #address and #size cells */ -#define DT_ROOT_NODE_ADDR_CELLS_DEFAULT 2 -#define DT_ROOT_NODE_SIZE_CELLS_DEFAULT 1 - #define dt_for_each_property_node(dn, pp) \ for ( pp =3D dn->properties; pp !=3D NULL; pp =3D pp->next ) =20 @@ -230,36 +212,6 @@ dt_find_interrupt_controller(const struct dt_device_ma= tch *matches); #define dt_for_each_child_node(dt, dn) \ for ( dn =3D dt->child; dn !=3D NULL; dn =3D dn->sibling ) =20 -/* Helper to read a big number; size is in cells (not bytes) */ -static inline u64 dt_read_number(const __be32 *cell, int size) -{ - u64 r =3D 0; - - while ( size-- ) - r =3D (r << 32) | be32_to_cpu(*(cell++)); - return r; -} - -/* Helper to convert a number of cells to bytes */ -static inline int dt_cells_to_size(int size) -{ - return (size * sizeof (u32)); -} - -/* Helper to convert a number of bytes to cells, rounds down */ -static inline int dt_size_to_cells(int bytes) -{ - return (bytes / sizeof(u32)); -} - -static inline u64 dt_next_cell(int s, const __be32 **cellp) -{ - const __be32 *p =3D *cellp; - - *cellp =3D p + s; - return dt_read_number(p, s); -} - static inline const char *dt_node_full_name(const struct dt_device_node *n= p) { return (np && np->full_name) ? np->full_name : ""; diff --git a/xen/include/xen/fdt.h b/xen/include/xen/fdt.h new file mode 100644 index 0000000000..00f9f3792f --- /dev/null +++ b/xen/include/xen/fdt.h @@ -0,0 +1,79 @@ +/* + * Flattened Device Tree + * + * Copyright (C) 2012 Citrix Systems, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ +#ifndef __XEN_FDT_H__ +#define __XEN_FDT_H__ + +#include +#include +#include + +#define DEVICE_TREE_MAX_DEPTH 16 + +/* Default #address and #size cells */ +#define DT_ROOT_NODE_ADDR_CELLS_DEFAULT 2 +#define DT_ROOT_NODE_SIZE_CELLS_DEFAULT 1 + +#define dt_prop_cmp(s1, s2) strcmp((s1), (s2)) +#define dt_node_cmp(s1, s2) strcasecmp((s1), (s2)) +#define dt_compat_cmp(s1, s2) strcasecmp((s1), (s2)) + +/* Helper to read a big number; size is in cells (not bytes) */ +static inline u64 dt_read_number(const __be32 *cell, int size) +{ + u64 r =3D 0; + + while ( size-- ) + r =3D (r << 32) | be32_to_cpu(*(cell++)); + return r; +} + +/* Helper to convert a number of cells to bytes */ +static inline int dt_cells_to_size(int size) +{ + return (size * sizeof (u32)); +} + +/* Helper to convert a number of bytes to cells, rounds down */ +static inline int dt_size_to_cells(int bytes) +{ + return (bytes / sizeof(u32)); +} + +static inline u64 dt_next_cell(int s, const __be32 **cellp) +{ + const __be32 *p =3D *cellp; + + *cellp =3D p + s; + return dt_read_number(p, s); +} + + +bool __init device_tree_node_matches( + const void *fdt, int node, const char *match); + +bool __init device_tree_node_compatible( + const void *fdt, int node, const char *match); + +void __init device_tree_get_reg( + const __be32 **cell, u32 address_cells, u32 size_cells, u64 *start, + u64 *size); + +u32 __init device_tree_get_u32( + const void *fdt, int node, const char *prop_name, u32 dflt); + +typedef int (*device_tree_node_func)( + const void *fdt, int node, const char *name, int depth, u32 address_ce= lls, + u32 size_cells, void *data); + +int device_tree_for_each_node( + const void *fdt, int node, device_tree_node_func func, void *data); + + +#endif /* __XEN_FDT_H__ */ --=20 2.20.1 From nobody Mon May 20 18:31:35 2024 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=1657141734; cv=pass; d=zohomail.com; s=zohoarc; b=fuD4KQ7xyk9Xfpk6TFwNmDqfsRLJGU+4Uvfnq2KNPmzDtet0saIJVgiUSgCmROL0A8ognu6OMlj/6Akpu5qFJ5Tte2L5QJWkFdG3ksC/7jxT1PKazn4jYmBYfHBNN5AvW0HBDxqctSVfhWAS4XRNICZ1YM0Y6wWHftvUrq6WDjk= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657141734; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=J77O8suVeejM9qg7gYOMo0/ft/qDVUpd9vIxutDZU4s=; b=UJkL3165aZh8uoJdUKBy1AJh7gJiQoQnaap1obNSzgQcdmvo/eKbsBMG/IfYdY3smlppQ+B6Vt5OFolJE1wzceNq6wRj6lbLKeEDiH7xNzpmV6iYb4R1HVZHJIb13FUEV7dHlPpduSXewbhsWWj69kyqODh4D58PURQnOCq+b40= 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 1657141734570811.4361928397599; Wed, 6 Jul 2022 14:08:54 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.362548.592653 (Exim 4.92) (envelope-from ) id 1o9CGA-0008Fi-MO; Wed, 06 Jul 2022 21:08:34 +0000 Received: by outflank-mailman (output) from mailman id 362548.592653; Wed, 06 Jul 2022 21:08:34 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1o9CGA-0008F4-Ex; Wed, 06 Jul 2022 21:08:34 +0000 Received: by outflank-mailman (input) for mailman id 362548; Wed, 06 Jul 2022 21:08:33 +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 1o9CEo-0003HV-Mr for xen-devel@lists.xenproject.org; Wed, 06 Jul 2022 21:07:11 +0000 Received: from sender4-of-o51.zoho.com (sender4-of-o51.zoho.com [136.143.188.51]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 980f365c-fd6f-11ec-924f-1f966e50362f; Wed, 06 Jul 2022 23:07:09 +0200 (CEST) Received: from sisyou.hme. (static-72-81-132-2.bltmmd.fios.verizon.net [72.81.132.2]) by mx.zohomail.com with SMTPS id 1657141513567683.6191702459943; Wed, 6 Jul 2022 14:05: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: 980f365c-fd6f-11ec-924f-1f966e50362f ARC-Seal: i=1; a=rsa-sha256; t=1657141515; cv=none; d=zohomail.com; s=zohoarc; b=hH8iSSh7V0tdIXTzS1Ubw9vFs83PaKUcRziQHL+OnMqNVNS+E5snNAWFFY5OgSg7/Gn3kZdza2/V1tL0Gjl7aAPtFzGdnkjby2Uckzh9VRrTTaMC5aZGjQZgi4gcQBUSIMAgp9PQ+PCiyz4TtSOizHarcl43IQz+VbnCbrkgkwM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657141515; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=J77O8suVeejM9qg7gYOMo0/ft/qDVUpd9vIxutDZU4s=; b=PixWEodVN4GaUxiV7hsApDpWo0eO9647EbCs+EHkpFT7xrLOaxCIVbyEZyqhxqp89wC7ITrCcfNZWZNQ0gyliRHsIoJ+BPETPEVBEIuwOmwH0hd9vpiX0RHoz40lmz/ELE6LeFvijQnw1K9hKBctI+tRo/7TAog5aCu502CgyUI= 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=1657141515; 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-Type:Content-Transfer-Encoding:Reply-To; bh=J77O8suVeejM9qg7gYOMo0/ft/qDVUpd9vIxutDZU4s=; b=QTlDaaVUp7U5CqwKiB/RSI74HNKmbgltsH7KOnzePAGUpWbfNmJ/rarveUhifBDu EYaHRDLi8V5n4IjeHtUC/HUFz/wS6mv+XhJ1oEU9BM8/SSW2TdMEkndQRIlFt9VZoSa 9khOUqhvWovwIACE+Kb5mpEKGTUOyPIdIzZ2JUy8= From: "Daniel P. Smith" To: xen-devel@lists.xenproject.org Cc: "Daniel P. Smith" , scott.davis@starlab.io, christopher.clark@starlab.io, Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu Subject: [PATCH v1 07/18] docs: update hyperlaunch device tree documentation Date: Wed, 6 Jul 2022 17:04:42 -0400 Message-Id: <20220706210454.30096-8-dpsmith@apertussolutions.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220706210454.30096-1-dpsmith@apertussolutions.com> References: <20220706210454.30096-1-dpsmith@apertussolutions.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External X-ZohoMail-DKIM: pass (identity dpsmith@apertussolutions.com) X-ZM-MESSAGEID: 1657141736189100002 This commit is to update the hyperlaunch device tree documentation to align with the DTB parsing implementation. Signed-off-by: Daniel P. Smith Reviewed-by: Christopher Clark --- .../designs/launch/hyperlaunch-devicetree.rst | 497 +++++++++++------- 1 file changed, 306 insertions(+), 191 deletions(-) diff --git a/docs/designs/launch/hyperlaunch-devicetree.rst b/docs/designs/= launch/hyperlaunch-devicetree.rst index b49c98cfbd..ae1a786d0b 100644 --- a/docs/designs/launch/hyperlaunch-devicetree.rst +++ b/docs/designs/launch/hyperlaunch-devicetree.rst @@ -13,12 +13,268 @@ difference is the introduction of the ``hypervisor`` n= ode that is under the 2. Allows for the domain construction information to easily be sanitized by simple removing the ``/chosen/hypervisor`` node. =20 + +The Hypervisor node +------------------- + +The ``hypervisor`` node is a top level container for the domains that will= be built +by hypervisor on start up. The node will be named ``hypervisor`` with a `= `compatible`` +property to identify which hypervisors the configuration is intended. The = hypervisor +node will consist of one or more config nodes and one or more domain nodes. + +Properties +"""""""""" + +compatible + Identifies which hypervisors the configuration is compatible. Required. + + Format: "hypervisor,", e.g "hypervisor,xen" + +Child Nodes +""""""""""" + +* config +* domain + +Config Node +----------- + +A ``config`` node is for passing configuration data and identifying any bo= ot +modules that is of interest to the hypervisor. For example this would be = where +Xen would be informed of microcode or XSM policy locations. Each ``config`` +node will require a unique device-tree compliant name as there may be one = or +more ``config`` nodes present in a single dtb file. To identify which +hypervisor the configuration is intended, the required ``compatible`` prop= erty +must be present. + +While the config node is not meant to replace the hypervisor commandline, = there +may be cases where it is better suited for passing configuration details at +boot time. This additional information may be carried in properties assig= ned +to a ``config`` node. If there are any boot modules that are intended for = the +hypervisor, then a ``module`` child node should be provided to identify the +boot module. + +Properties +"""""""""" + +compatible + Identifies the hypervisor the confiugration is intended. Required. + + Format: ",config", e.g "xen,config" + +bootargs + This is used to provide the boot params for Xen. + + Format: String, e.g. "flask=3Dsilo" + +Child Nodes +""""""""""" + +* module + +Domain Node +----------- + +A ``domain`` node is for describing the construction of a domain. Since th= ere +may be one or more domain nodes, each one requires a unique, DTB compliant= name +and a ``compatible`` property to identify as a domain node. + +A ``domain`` node may provide a ``domid`` property which will be used as = the +requested domain id for the domain with a value of =E2=80=9C0=E2=80=9D sig= nifying to use the +next available domain id, which is the default behavior if omitted. It sho= uld +be noted that a domain configuration is not able to request a domid of =E2= =80=9C0=E2=80=9D. +Beyond that a domain node may have any of the following optional propertie= s. + +Properties +"""""""""" + +compatible + Identifies the node as a domain node and for which hypervisor. Required. + + Format: ",domain", e.g "xen,domain" + +domid + Identifies the domid requested to assign to the domain. + + Format: Integer, e.g <0> + +permissions + This sets what Discretionary Access Control permissions + a domain is assigned. Optional, default is none. + + Format: Bitfield, e.g <3> or <0x00000003> + + PERMISSION_NONE (0) + PERMISSION_CONTROL (1 << 0) + PERMISSION_HARDWARE (1 << 1) + +functions + This identifies what system functions a domain will fulfill. + Optional, the default is none. + + Format: Bitfield, e.g <3221225487> or <0xC0000007> + + FUNCTION_NONE (0) + FUNCTION_BOOT (1 << 0) + FUNCTION_CRASH (1 << 1) + FUNCTION_CONSOLE (1 << 2) + FUNCTION_XENSTORE (1 << 30) + FUNCTION_LEGACY_DOM0 (1 << 31) + +.. note:: The `functions` bits that have been selected to indicate + ``FUNCTION_XENSTORE`` and ``FUNCTION_LEGACY_DOM0`` are the last two bits + (30, 31) such that should these features ever be fully replaced or reti= red, + the flags may be dropped without leaving a gap in the flag set. + +mode + The mode the domain will be executed under. Required. + + Format: Bitfield, e.g <5> or <0x00000005> + + MODE_PARAVIRTUALIZED (1 << 0) PV | PVH/HVM + MODE_ENABLE_DEVICE_MODEL (1 << 1) HVM | PVH + MODE_LONG (1 << 2) 64 BIT | 32 BIT + +domain-uuid + A globally unique identifier for the domain. Optional, + the default is NULL. + + Format: Byte Array, e.g [B3 FB 98 FB 8F 9F 67 A3] + +cpus + The number of vCPUs to be assigned to the domain. Optional, + the default is =E2=80=9C1=E2=80=9D. + + Format: Integer, e.g <0> + +memory + The amount of memory to assign to the domain, in KBs. This field uses a = DTB + Reg which contains a start and size. For memory allocation start may or = may + not have significance but size will always be used for the amount of mem= ory + Required. + + Format: String min: | max: | , e.g. "256M" + +security-id + The security identity to be assigned to the domain when XSM + is the access control mechanism being used. Optional, + the default is =E2=80=9Csystem_u:system_r:domU_t=E2=80=9D. + + Format: string, e.g. "system_u:system_r:domU_t" + +Child Nodes +""""""""""" + +* module + +Module node +----------- + +This node describes a boot module loaded by the boot loader. A ``module`` = node +will often appear repeatedly and will require a unique and DTB compliant n= ame +for each instance. The compatible property is required to identify that the +node is a ``module`` node, the type of boot module, and what it represents. + +Depending on the type of boot module, the ``module`` node will require eit= her a +``module-index`` or ``module-addr`` property must be present. They provide= the +boot module specific way of locating the boot module in memory. + +Properties +"""""""""" + +compatible + This identifies what the module is and thus what the hypervisor + should use the module for during domain construction. Required. + + Format: "module,"[, "module,"] + module type: kernel, ramdisk, device-tree, microcode, xsm-policy, + config + + locating type: index, addr + +module-index + This identifies the index for this module when in a module chain. + Required for multiboot environments. + + Format: Integer, e.g. <0> + +module-addr + This identifies where in memory this module is located. Required for + non-multiboot environments. + + Format: DTB Reg , e.g. <0x0 0x20000> + +bootargs + This is used to provide the boot params to kernel modules. + + Format: String, e.g. "ro quiet" + +.. note:: The bootargs property is intended for situations where the same= kernel multiboot module is used for more than one domain. + Example Configuration --------------------- =20 -Below are two example device tree definitions for the hypervisor node. The -first is an example of a multiboot-based configuration for x86 and the sec= ond -is a module-based configuration for Arm. +Below are examples device tree definitions for the hypervisor node. The fi= rst +is an example of booting a dom0 only configuration. Afterh that are a +multiboot-based configuration for x86 and a module-based configuration for= Arm. + +Multiboot x86 Configuration Dom0-only: +"""""""""""""""""""""""""""""""""""""" +The following dts file can be provided to the Device Tree compiler, ``dtc`= `, to +produce a dtb file. +:: + + /dts-v1/; + + / { + chosen { + hypervisor { + compatible =3D "hypervisor,xen"; + + dom0 { + compatible =3D "xen,domain"; + + domid =3D <0>; + + permissions =3D <3>; + functions =3D <0xC000000F>; + mode =3D <5>; + + domain-uuid =3D [B3 FB 98 FB 8F 9F 67 A3 8A 6E 62 5A 09 = 13 F0 8C]; + + cpus =3D <1>; + memory =3D <0x0 0x20000000>; + + kernel { + compatible =3D "module,kernel", "module,index"; + module-index =3D <1>; + }; + }; + + }; + }; + }; + +The resulting dtb file, in this case dom0-only.dtb, can then be used with a +GRUB menuentry as such, +:: + + menuentry 'Devuan GNU/Linux, with Xen hyperlaunch' { + insmod part_gpt + insmod ext2 + set root=3D'hd0,gpt2' + + echo 'Loading Xen hyperlaunch ...' + + multiboot2 /xen.gz placeholder sync_console + echo 'Loading Dom0 hyperlaunch dtb ...' + module2 --nounzip /dom0-only.dtb + echo 'Loading Linux 5.4.36+ ...' + module2 /vmlinuz-5.4.36+ placeholder root=3D/dev/mapper/test01--vg= -root ro quiet + echo 'Loading initial ramdisk ...' + module2 --nounzip /initrd.img-5.4.36+ + } + =20 Multiboot x86 Configuration: """""""""""""""""""""""""""" @@ -31,89 +287,70 @@ Multiboot x86 Configuration: compatible =3D =E2=80=9Chypervisor,xen=E2=80=9D =20 // Configuration container - config { + xen-config { compatible =3D "xen,config"; =20 - module { - compatible =3D "module,microcode", "multiboot,module"; - mb-index =3D <1>; + bootargs =3D "console=3Dcom1,vga com1=3D115200,8n1 loglvl=3Dal= l"; + + microcode { + compatible =3D "module,microcode", "module,index"; + module-index =3D <1>; }; =20 - module { - compatible =3D "module,xsm-policy", "multiboot,module"; - mb-index =3D <2>; + policy { + compatible =3D "module,xsm-policy", "module,index"; + module-index =3D <2>; }; }; =20 // Boot Domain definition - domain { + domB { compatible =3D "xen,domain"; =20 domid =3D <0x7FF5>; =20 - // FUNCTION_NONE (0) - // FUNCTION_BOOT (1 << 0) - // FUNCTION_CRASH (1 << 1) - // FUNCTION_CONSOLE (1 << 2) - // FUNCTION_XENSTORE (1 << 30) - // FUNCTION_LEGACY_DOM0 (1 << 31) functions =3D <0x00000001>; =20 memory =3D <0x0 0x20000>; cpus =3D <1>; - module { - compatible =3D "module,kernel", "multiboot,module"; - mb-index =3D <3>; - }; =20 - module { - compatible =3D "module,ramdisk", "multiboot,module"; - mb-index =3D <4>; + kernel { + compatible =3D "module,kernel", "module,index"; + module-index =3D <3>; }; - module { - compatible =3D "module,config", "multiboot,module"; - mb-index =3D <5>; + initrd { + compatible =3D "module,ramdisk", "module,index"; + module-index =3D <4>; + }; + dom-config { + compatible =3D "module,config", "module,index"; + module-index =3D <5>; }; =20 // Classic Dom0 definition - domain { + dom0 { compatible =3D "xen,domain"; =20 domid =3D <0>; =20 - // PERMISSION_NONE (0) - // PERMISSION_CONTROL (1 << 0) - // PERMISSION_HARDWARE (1 << 1) permissions =3D <3>; - - // FUNCTION_NONE (0) - // FUNCTION_BOOT (1 << 0) - // FUNCTION_CRASH (1 << 1) - // FUNCTION_CONSOLE (1 << 2) - // FUNCTION_XENSTORE (1 << 30) - // FUNCTION_LEGACY_DOM0 (1 << 31) functions =3D <0xC0000006>; - - // MODE_PARAVIRTUALIZED (1 << 0) /* PV | PVH/HVM */ - // MODE_ENABLE_DEVICE_MODEL (1 << 1) /* HVM | PVH */ - // MODE_LONG (1 << 2) /* 64 BIT | 32 BIT */ mode =3D <5>; /* 64 BIT, PV */ =20 - // UUID domain-uuid =3D [B3 FB 98 FB 8F 9F 67 A3]; =20 cpus =3D <1>; memory =3D <0x0 0x20000>; - security-id =3D =E2=80=9Cdom0_t; + security-id =3D =E2=80=9Csystem_u:system_r:dom0_t; =20 - module { - compatible =3D "module,kernel", "multiboot,module"; - mb-index =3D <6>; + kernel { + compatible =3D "module,kernel", "module,index"; + module-index =3D <6>; bootargs =3D "console=3Dhvc0"; }; - module { - compatible =3D "module,ramdisk", "multiboot,module"; - mb-index =3D <7>; + initrd { + compatible =3D "module,ramdisk", "module,index"; + module-index =3D <7>; }; }; =20 @@ -137,89 +374,68 @@ Module Arm Configuration: compatible =3D =E2=80=9Chypervisor,xen=E2=80=9D =20 // Configuration container - config { + xen-config { compatible =3D "xen,config"; =20 - module { - compatible =3D "module,microcode=E2=80=9D; + microcode { + compatible =3D "module,microcode=E2=80=9D,"module,addr"; module-addr =3D <0x0000ff00 0x80>; }; =20 - module { - compatible =3D "module,xsm-policy"; + policy { + compatible =3D "module,xsm-policy","module,addr"; module-addr =3D <0x0000ff00 0x80>; =20 }; }; =20 // Boot Domain definition - domain { + domB { compatible =3D "xen,domain"; =20 domid =3D <0x7FF5>; =20 - // FUNCTION_NONE (0) - // FUNCTION_BOOT (1 << 0) - // FUNCTION_CRASH (1 << 1) - // FUNCTION_CONSOLE (1 << 2) - // FUNCTION_XENSTORE (1 << 30) - // FUNCTION_LEGACY_DOM0 (1 << 31) functions =3D <0x00000001>; =20 memory =3D <0x0 0x20000>; cpus =3D <1>; - module { - compatible =3D "module,kernel"; + + kernel { + compatible =3D "module,kernel","module,addr"; module-addr =3D <0x0000ff00 0x80>; }; - - module { - compatible =3D "module,ramdisk"; + initrd { + compatible =3D "module,ramdisk","module,addr"; module-addr =3D <0x0000ff00 0x80>; }; - module { - compatible =3D "module,config"; + dom-config { + compatible =3D "module,config","module,addr"; module-addr =3D <0x0000ff00 0x80>; }; =20 // Classic Dom0 definition - domain@0 { + dom0 { compatible =3D "xen,domain"; =20 domid =3D <0>; =20 - // PERMISSION_NONE (0) - // PERMISSION_CONTROL (1 << 0) - // PERMISSION_HARDWARE (1 << 1) permissions =3D <3>; - - // FUNCTION_NONE (0) - // FUNCTION_BOOT (1 << 0) - // FUNCTION_CRASH (1 << 1) - // FUNCTION_CONSOLE (1 << 2) - // FUNCTION_XENSTORE (1 << 30) - // FUNCTION_LEGACY_DOM0 (1 << 31) functions =3D <0xC0000006>; - - // MODE_PARAVIRTUALIZED (1 << 0) /* PV | PVH/HVM */ - // MODE_ENABLE_DEVICE_MODEL (1 << 1) /* HVM | PVH */ - // MODE_LONG (1 << 2) /* 64 BIT | 32 BIT */ mode =3D <5>; /* 64 BIT, PV */ =20 - // UUID domain-uuid =3D [B3 FB 98 FB 8F 9F 67 A3]; =20 cpus =3D <1>; memory =3D <0x0 0x20000>; - security-id =3D =E2=80=9Cdom0_t=E2=80=9D; + security-id =3D =E2=80=9Csystem_u:system_r:dom0_t=E2=80=9D; =20 - module { - compatible =3D "module,kernel"; + kernel { + compatible =3D "module,kernel","module,addr"; module-addr =3D <0x0000ff00 0x80>; bootargs =3D "console=3Dhvc0"; }; - module { - compatible =3D "module,ramdisk"; + intird { + compatible =3D "module,ramdisk","module,addr"; module-addr =3D <0x0000ff00 0x80>; }; }; @@ -240,104 +456,3 @@ provided to Xen using the standard method currently i= n use. The remaining modules would need to be loaded in the respective addresses specified in t= he `module-addr` property. =20 - -The Hypervisor node -------------------- - -The hypervisor node is a top level container for the domains that will be = built -by hypervisor on start up. On the ``hypervisor`` node the ``compatible`` -property is used to identify the type of hypervisor node present.. - -compatible - Identifies the type of node. Required. - -The Config node ---------------- - -A config node is for detailing any modules that are of interest to Xen its= elf. -For example this would be where Xen would be informed of microcode or XSM -policy locations. If the modules are multiboot modules and are able to be -located by index within the module chain, the ``mb-index`` property should= be -used to specify the index in the multiboot module chain.. If the module wi= ll be -located by physical memory address, then the ``module-addr`` property shou= ld be -used to identify the location and size of the module. - -compatible - Identifies the type of node. Required. - -The Domain node ---------------- - -A domain node is for describing the construction of a domain. It may provi= de a -domid property which will be used as the requested domain id for the domain -with a value of =E2=80=9C0=E2=80=9D signifying to use the next available d= omain id, which is -the default behavior if omitted. A domain configuration is not able to req= uest -a domid of =E2=80=9C0=E2=80=9D. After that a domain node may have any of t= he following -parameters, - -compatible - Identifies the type of node. Required. - -domid - Identifies the domid requested to assign to the domain. Required. - -permissions - This sets what Discretionary Access Control permissions - a domain is assigned. Optional, default is none. - -functions - This identifies what system functions a domain will fulfill. - Optional, the default is none. - -.. note:: The `functions` bits that have been selected to indicate - ``FUNCTION_XENSTORE`` and ``FUNCTION_LEGACY_DOM0`` are the last two bits - (30, 31) such that should these features ever be fully retired, the fla= gs may - be dropped without leaving a gap in the flag set. - -mode - The mode the domain will be executed under. Required. - -domain-uuid - A globally unique identifier for the domain. Optional, - the default is NULL. - -cpus - The number of vCPUs to be assigned to the domain. Optional, - the default is =E2=80=9C1=E2=80=9D. - -memory - The amount of memory to assign to the domain, in KBs. - Required. - -security-id - The security identity to be assigned to the domain when XSM - is the access control mechanism being used. Optional, - the default is =E2=80=9Cdomu_t=E2=80=9D. - -The Module node ---------------- - -This node describes a boot module loaded by the boot loader. The required -compatible property follows the format: module, where type can be -=E2=80=9Ckernel=E2=80=9D, =E2=80=9Cramdisk=E2=80=9D, =E2=80=9Cdevice-tree= =E2=80=9D, =E2=80=9Cmicrocode=E2=80=9D, =E2=80=9Cxsm-policy=E2=80=9D or =E2= =80=9Cconfig=E2=80=9D. In -the case the module is a multiboot module, the additional property string -=E2=80=9Cmultiboot,module=E2=80=9D may be present. One of two properties i= s required and -identifies how to locate the module. They are the mb-index, used for multi= boot -modules, and the module-addr for memory address based location. - -compatible - This identifies what the module is and thus what the hypervisor - should use the module for during domain construction. Required. - -mb-index - This identifies the index for this module in the multiboot module chain. - Required for multiboot environments. - -module-addr - This identifies where in memory this module is located. Required for - non-multiboot environments. - -bootargs - This is used to provide the boot params to kernel modules. - -.. note:: The bootargs property is intended for situations where the same= kernel multiboot module is used for more than one domain. --=20 2.20.1 From nobody Mon May 20 18:31:35 2024 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=1657141723; cv=pass; d=zohomail.com; s=zohoarc; b=byYrNFWUZnrb260ixdAd6XiorTGLgOh80V+bo1hjHram1kcIR80daWWPyaJ9zce16I/BXJFUIbh2rD8hWITbRsUxfiFTHXT8La+zUMeyq0uAa9URjhbr9KJK92ksIQhQbmhNwJFKPSs9rG/7P0BkgqzsmEgmy9hGNnIxA7U/cy8= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657141723; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=HKjJTQMRAU0h0mGoRHhFPzIn/dQiHWAlt9SCRVrEJ6w=; b=kqzNUpPWLLqvoxmhLHITbEHG9mVRJEP51eL0iekdYa68qMUwxX7EMqgKXDA7oeN3LjLbA0HnQadA4pqn1dzpWe+6tfqOPeVHK99G/vYJ2HOL8zGBF4BUQy+uand4iODL5xeRB4WruvoEnH5wPsPw4Pviq1u3W4EKLjhPVbA/LVs= 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 1657141723451738.6568493772845; Wed, 6 Jul 2022 14:08:43 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.362545.592630 (Exim 4.92) (envelope-from ) id 1o9CG0-0007Gm-SX; Wed, 06 Jul 2022 21:08:24 +0000 Received: by outflank-mailman (output) from mailman id 362545.592630; Wed, 06 Jul 2022 21:08: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 1o9CG0-0007GQ-Nk; Wed, 06 Jul 2022 21:08:24 +0000 Received: by outflank-mailman (input) for mailman id 362545; Wed, 06 Jul 2022 21:08:22 +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 1o9CF4-0003HV-Ba for xen-devel@lists.xenproject.org; Wed, 06 Jul 2022 21:07:26 +0000 Received: from sender4-of-o51.zoho.com (sender4-of-o51.zoho.com [136.143.188.51]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id a1ce176b-fd6f-11ec-924f-1f966e50362f; Wed, 06 Jul 2022 23:07:25 +0200 (CEST) Received: from sisyou.hme. (static-72-81-132-2.bltmmd.fios.verizon.net [72.81.132.2]) by mx.zohomail.com with SMTPS id 1657141515007710.3122852676397; Wed, 6 Jul 2022 14:05:15 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: a1ce176b-fd6f-11ec-924f-1f966e50362f ARC-Seal: i=1; a=rsa-sha256; t=1657141516; cv=none; d=zohomail.com; s=zohoarc; b=kn/VLgVHdrNiMJYv6C8ca0f3cdXI0qCRcFQLsnDcyMGQ1mki8dYJaC3NtgtMnjfgYBfWCjCcWod+iM56MB7VjEdyNP8q1wWzOTBPgidoReSQ46jpnhM77OeMjLtS9WasAHtekYzXvH7tBW3IoEpMn7uttyv5zClFn5gUZTO6KFI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657141516; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=HKjJTQMRAU0h0mGoRHhFPzIn/dQiHWAlt9SCRVrEJ6w=; b=Tpb6tPRG3vu03zYlMxnzKUhhBtf1S5wuRqC8BBy2YpSyaWrcZEQRzU+/Jw+8zg14X2ifEFgBihC0cWFnLBYSX1XlJ3Tjg2XjkCDf3hYgaN5QH4ymcLFJHwHxSAILg0xL/yxB6gkEPIGLaxgxyx/CU0Q6YB3gIHZMlSb1h4MrGyE= 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=1657141516; 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=HKjJTQMRAU0h0mGoRHhFPzIn/dQiHWAlt9SCRVrEJ6w=; b=mARI0734kr2pktMr8wWc2nsNy5B6xK65nm0w1Rh8HNsFD0TZD1DC4JRFO1tG5/nh 53OJP4pGyVDIdK8mbuWT30tkLnig2RETxO93J7Kq9ijq2BdngSh0PYZBX72uFlEMPVr iquDN14+baAoOa9kZEiPo89oz1Fc4x7gHiuF2w8M= From: "Daniel P. Smith" To: xen-devel@lists.xenproject.org Cc: "Daniel P. Smith" , scott.davis@starlab.io, christopher.clark@starlab.io, Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu Subject: [PATCH v1 08/18] kconfig: introduce domain builder config option Date: Wed, 6 Jul 2022 17:04:43 -0400 Message-Id: <20220706210454.30096-9-dpsmith@apertussolutions.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220706210454.30096-1-dpsmith@apertussolutions.com> References: <20220706210454.30096-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: 1657141724107100001 Content-Type: text/plain; charset="utf-8" Hyperlaunch domain builder is the consolidated boot time domain building lo= gic framework. This commit introduces the first config option for the domain builder to control support for loading the domain configurations via the flattened device tree. Signed-off-by: Daniel P. Smith Reviewed-by: Christopher Clark Reviewed-by: Henry Wang --- xen/common/Kconfig | 1 + xen/common/domain-builder/Kconfig | 15 +++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 xen/common/domain-builder/Kconfig diff --git a/xen/common/Kconfig b/xen/common/Kconfig index 9fc6683932..5a1c40e392 100644 --- a/xen/common/Kconfig +++ b/xen/common/Kconfig @@ -355,6 +355,7 @@ config ARGO =20 If unsure, say N. =20 +source "common/domain-builder/Kconfig" source "common/sched/Kconfig" =20 config CRYPTO diff --git a/xen/common/domain-builder/Kconfig b/xen/common/domain-builder/= Kconfig new file mode 100644 index 0000000000..893038cab3 --- /dev/null +++ b/xen/common/domain-builder/Kconfig @@ -0,0 +1,15 @@ + +menu "Domain Builder Features" + +config BUILDER_FDT + bool "Domain builder device tree (UNSUPPORTED)" if UNSUPPORTED + select CORE_DEVICE_TREE + ---help--- + Enables the ability to configure the domain builder using a + flattened device tree. + + This feature is currently experimental. + + If unsure, say N. + +endmenu --=20 2.20.1 From nobody Mon May 20 18:31:35 2024 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=1657141714; cv=pass; d=zohomail.com; s=zohoarc; b=XH5uUqCAMqVgOQkWMLhJ5Xj+RACfQ7f6Csrus/3Y6yMnHtQHWPd8isLPdZCi8wz+BMO3/daR/20HeycgN6HDv8DbgR4cb4fztPcQ5H0NKQoy3daSYhhFRbPBFmcpMjlXCVzmtAnEA4fsM4hXQp/Cl7hcqOf3TTsbKG/jGjyIKlU= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657141714; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=A6AMQVyod82qQaiZjmSPOr+I3hcKRNwtWIcfRwtz3po=; b=NEEh+9sC6AP2zB8gX52YHk+zJVPP/M7EgU1PR5PfdNDA/y9SzsRcxDlWc1d6cQ+SgH546/hfBjXH4J+AIVTBBhlYjdV0YunNQbgpgdQ6thvgRr9fyqvp+3THkFTZw/G2LdFbC8kZsa8STkNVaAk/yUVfkdR79yZ/Aaq/CM9xZOs= 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 1657141714133116.74949417790867; Wed, 6 Jul 2022 14:08:34 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.362540.592608 (Exim 4.92) (envelope-from ) id 1o9CFp-0006Uh-Ad; Wed, 06 Jul 2022 21:08:13 +0000 Received: by outflank-mailman (output) from mailman id 362540.592608; Wed, 06 Jul 2022 21:08: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 1o9CFp-0006Ua-7s; Wed, 06 Jul 2022 21:08:13 +0000 Received: by outflank-mailman (input) for mailman id 362540; Wed, 06 Jul 2022 21:08:11 +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 1o9CFI-0003HV-Oz for xen-devel@lists.xenproject.org; Wed, 06 Jul 2022 21:07:40 +0000 Received: from sender4-of-o51.zoho.com (sender4-of-o51.zoho.com [136.143.188.51]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id aa017a83-fd6f-11ec-924f-1f966e50362f; Wed, 06 Jul 2022 23:07:39 +0200 (CEST) Received: from sisyou.hme. (static-72-81-132-2.bltmmd.fios.verizon.net [72.81.132.2]) by mx.zohomail.com with SMTPS id 1657141516660163.52773294084864; Wed, 6 Jul 2022 14:05:16 -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: aa017a83-fd6f-11ec-924f-1f966e50362f ARC-Seal: i=1; a=rsa-sha256; t=1657141519; cv=none; d=zohomail.com; s=zohoarc; b=dFLnhlcLscM2iZicoi/+xsP7p2cnh9am/AF+aWaW7uI6a2L5Q49qlionMeMtt11RcPdGTppxE4RMf0KMM59eOZ8dxScKLyJlWWSa+kdXB87j5lprdsA0wug5lcgvjamjQvyDjembs059kUiNJX3LUW4eom39ICburkk9JUJusUs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657141519; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=A6AMQVyod82qQaiZjmSPOr+I3hcKRNwtWIcfRwtz3po=; b=Xosg7reBeL0ZV68oKzyFJGUyXhGKQqw0EV1ygRN6bDcUaOCrwCSUE0QOIZEfmx1yh9h21WYjxavYRbqb1daB7C1DCZ9yNAmBKmrUkvAwEK3eqxT4NW7HxF/4/Z4UFFGR6kDGTtdReMK6ju+3x84Gq8mksMSaNlT0vTT8XDgE45I= 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=1657141519; 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=A6AMQVyod82qQaiZjmSPOr+I3hcKRNwtWIcfRwtz3po=; b=pRirURHJn2l6HPxONdBM7XV9yqVH3KutDYO5aDJWm7M4HkD0/n7clNGmoXavbIvf WDqes1mgJjiFQrsCkUOPGiVbNKw5+KZHdk1MqV2fsHtL7oAWD7r4aXKApWDswYhg7y+ aTVvf/N4MBkJUMECOzgVqHLbL7cNjq9ijztnYcIw= From: "Daniel P. Smith" To: xen-devel@lists.xenproject.org, Wei Liu Cc: "Daniel P. Smith" , scott.davis@starlab.io, christopher.clark@starlab.io, Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , George Dunlap , Julien Grall , Stefano Stabellini Subject: [PATCH v1 09/18] x86: introduce abstractions for domain builder Date: Wed, 6 Jul 2022 17:04:44 -0400 Message-Id: <20220706210454.30096-10-dpsmith@apertussolutions.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220706210454.30096-1-dpsmith@apertussolutions.com> References: <20220706210454.30096-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: 1657141716118100005 Content-Type: text/plain; charset="utf-8" This commit expands the new boot info structs to provide the initial abstractions for domain builder. Additionally, it reuses the memory alloca= tion structures previously used for dom0, bring the structures and helper functi= ons under the domain builder. Signed-off-by: Daniel P. Smith Reviewed-by: Christopher Clark --- xen/arch/x86/boot/boot_info32.h | 3 ++ xen/arch/x86/dom0_build.c | 21 +--------- xen/arch/x86/include/asm/bootdomain.h | 30 +++++++++++++++ xen/arch/x86/include/asm/bootinfo.h | 2 + xen/include/xen/bootdomain.h | 52 +++++++++++++++++++++++++ xen/include/xen/bootinfo.h | 4 ++ xen/include/xen/domain_builder.h | 55 +++++++++++++++++++++++++++ 7 files changed, 147 insertions(+), 20 deletions(-) create mode 100644 xen/arch/x86/include/asm/bootdomain.h create mode 100644 xen/include/xen/bootdomain.h create mode 100644 xen/include/xen/domain_builder.h diff --git a/xen/arch/x86/boot/boot_info32.h b/xen/arch/x86/boot/boot_info3= 2.h index 01af950efc..0e7821efb3 100644 --- a/xen/arch/x86/boot/boot_info32.h +++ b/xen/arch/x86/boot/boot_info32.h @@ -87,6 +87,9 @@ struct __packed boot_info { /* struct boot_module* */ u64 mods; =20 + /* struct domain_builder* */ + u64 builder; + /* struct arch_boot_info* */ u64 arch; }; diff --git a/xen/arch/x86/dom0_build.c b/xen/arch/x86/dom0_build.c index 9ca5a99510..e44f7f3c43 100644 --- a/xen/arch/x86/dom0_build.c +++ b/xen/arch/x86/dom0_build.c @@ -4,6 +4,7 @@ * Copyright (c) 2002-2005, K A Fraser */ =20 +#include #include #include #include @@ -22,31 +23,11 @@ #include #include =20 -struct memsize { - long nr_pages; - unsigned int percent; - bool minus; -}; - static struct memsize __initdata dom0_size; static struct memsize __initdata dom0_min_size; static struct memsize __initdata dom0_max_size =3D { .nr_pages =3D LONG_MA= X }; static bool __initdata dom0_mem_set; =20 -static bool __init memsize_gt_zero(const struct memsize *sz) -{ - return !sz->minus && sz->nr_pages; -} - -static unsigned long __init get_memsize(const struct memsize *sz, - unsigned long avail) -{ - unsigned long pages; - - pages =3D sz->nr_pages + sz->percent * avail / 100; - return sz->minus ? avail - pages : pages; -} - /* * dom0_mem=3D[min:,][max:,][] * diff --git a/xen/arch/x86/include/asm/bootdomain.h b/xen/arch/x86/include/a= sm/bootdomain.h new file mode 100644 index 0000000000..6f37ac99dc --- /dev/null +++ b/xen/arch/x86/include/asm/bootdomain.h @@ -0,0 +1,30 @@ +#ifndef __ARCH_X86_BOOTDOMAIN_H__ +#define __ARCH_X86_BOOTDOMAIN_H__ + +struct memsize { + long nr_pages; + unsigned int percent; + bool minus; +}; + +static inline bool memsize_gt_zero(const struct memsize *sz) +{ + return !sz->minus && sz->nr_pages; +} + +static inline unsigned long get_memsize( + const struct memsize *sz, unsigned long avail) +{ + unsigned long pages; + + pages =3D sz->nr_pages + sz->percent * avail / 100; + return sz->minus ? avail - pages : pages; +} + +struct arch_domain_mem { + struct memsize mem_size; + struct memsize mem_min; + struct memsize mem_max; +}; + +#endif diff --git a/xen/arch/x86/include/asm/bootinfo.h b/xen/arch/x86/include/asm= /bootinfo.h index 2fcd576023..f02f4edcd7 100644 --- a/xen/arch/x86/include/asm/bootinfo.h +++ b/xen/arch/x86/include/asm/bootinfo.h @@ -45,6 +45,8 @@ struct __packed mb_memmap { uint32_t type; }; =20 +struct arch_domain_builder { }; + static inline bool loader_is_grub2(const char *loader_name) { /* GRUB1=3D"GNU GRUB 0.xx"; GRUB2=3D"GRUB 1.xx" */ diff --git a/xen/include/xen/bootdomain.h b/xen/include/xen/bootdomain.h new file mode 100644 index 0000000000..b172d16f4e --- /dev/null +++ b/xen/include/xen/bootdomain.h @@ -0,0 +1,52 @@ +#ifndef __XEN_BOOTDOMAIN_H__ +#define __XEN_BOOTDOMAIN_H__ + +#include +#include + +#include + +#include + +struct domain; + +struct boot_domain { +#define BUILD_PERMISSION_NONE (0) +#define BUILD_PERMISSION_CONTROL (1 << 0) +#define BUILD_PERMISSION_HARDWARE (1 << 1) + uint32_t permissions; + +#define BUILD_FUNCTION_NONE (0) +#define BUILD_FUNCTION_BOOT (1 << 0) +#define BUILD_FUNCTION_CRASH (1 << 1) +#define BUILD_FUNCTION_CONSOLE (1 << 2) +#define BUILD_FUNCTION_STUBDOM (1 << 3) +#define BUILD_FUNCTION_XENSTORE (1 << 30) +#define BUILD_FUNCTION_INITIAL_DOM (1 << 31) + uint32_t functions; + /* On | Off */ +#define BUILD_MODE_PARAVIRTUALIZED (1 << 0) /* PV | PVH/HVM */ +#define BUILD_MODE_ENABLE_DEVICE_MODEL (1 << 1) /* HVM | PVH */ +#define BUILD_MODE_LONG (1 << 2) /* 64 BIT | 32 BIT */ + uint32_t mode; + + domid_t domid; + uint8_t uuid[16]; + + uint32_t ncpus; + struct arch_domain_mem meminfo; + +#define BUILD_MAX_SECID_LEN 64 + unsigned char secid[BUILD_MAX_SECID_LEN]; + + struct boot_module *kernel; + struct boot_module *ramdisk; +#define BUILD_MAX_CONF_MODS 2 +#define BUILD_DTB_CONF_IDX 0 +#define BUILD_DOM_CONF_IDX 1 + struct boot_module *configs[BUILD_MAX_CONF_MODS]; + + struct domain *domain; +}; + +#endif diff --git a/xen/include/xen/bootinfo.h b/xen/include/xen/bootinfo.h index 477294dc10..1d76d99a40 100644 --- a/xen/include/xen/bootinfo.h +++ b/xen/include/xen/bootinfo.h @@ -1,6 +1,7 @@ #ifndef __XEN_BOOTINFO_H__ #define __XEN_BOOTINFO_H__ =20 +#include #include #include =20 @@ -15,6 +16,7 @@ typedef enum { BOOTMOD_XSM, BOOTMOD_UCODE, BOOTMOD_GUEST_DTB, + BOOTMOD_GUEST_CONF, } bootmodule_kind; =20 typedef enum { @@ -48,6 +50,8 @@ struct __packed boot_info { uint32_t nr_mods; struct boot_module *mods; =20 + struct domain_builder *builder; + struct arch_boot_info *arch; }; =20 diff --git a/xen/include/xen/domain_builder.h b/xen/include/xen/domain_buil= der.h new file mode 100644 index 0000000000..79785ef251 --- /dev/null +++ b/xen/include/xen/domain_builder.h @@ -0,0 +1,55 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef XEN_DOMAIN_BUILDER_H +#define XEN_DOMAIN_BUILDER_H + +#include +#include + +#include + +struct domain_builder { + bool fdt_enabled; +#define BUILD_MAX_BOOT_DOMAINS 64 + uint16_t nr_doms; + struct boot_domain domains[BUILD_MAX_BOOT_DOMAINS]; + + struct arch_domain_builder *arch; +}; + +static inline bool builder_is_initdom(struct boot_domain *bd) +{ + return bd->functions & BUILD_FUNCTION_INITIAL_DOM; +} + +static inline bool builder_is_ctldom(struct boot_domain *bd) +{ + return (bd->functions & BUILD_FUNCTION_INITIAL_DOM || + bd->permissions & BUILD_PERMISSION_CONTROL ); +} + +static inline bool builder_is_hwdom(struct boot_domain *bd) +{ + return (bd->functions & BUILD_FUNCTION_INITIAL_DOM || + bd->permissions & BUILD_PERMISSION_HARDWARE ); +} + +static inline struct domain *builder_get_hwdom(struct boot_info *info) +{ + int i; + + for ( i =3D 0; i < info->builder->nr_doms; i++ ) + { + struct boot_domain *d =3D &info->builder->domains[i]; + + if ( builder_is_hwdom(d) ) + return d->domain; + } + + return NULL; +} + +void builder_init(struct boot_info *info); +uint32_t builder_create_domains(struct boot_info *info); + +#endif /* XEN_DOMAIN_BUILDER_H */ --=20 2.20.1 From nobody Mon May 20 18:31:35 2024 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=1657141735; cv=pass; d=zohomail.com; s=zohoarc; b=BzCy+8URSbZydrLIMyNASF7iXVqDSpZLDZPn5Z75tDDQbC/SsDBNKXk3XL6Yy+pBJZDBZ24UfEWgRkq0SYJpvlJMkYqOL0RRPSkOGBzp/7Opr0axRc5s4SePRczVIDeMIAnQ1spI1SnIFyPrNctlcYQe7TrGCaykU+GgOqd9jrc= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657141735; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=F4LzAhNPz1Ut05j8lMJsWMf8SmFv3K61ZtdVdpesbfA=; b=AFmWGIp1+oYy1qBhWaabs0yTlXkBIYIVN2UCtitLWEyLz6WW63dGKuDTBhr7jYgm6cOJ3fw33SZRcoURS7+EhILPElEBNyC9f9flvpuMT9mqLn25OQDy5OCQBdjoOI+eujZCgBMGVnLVJuoH17Kq6F+PSkEMV7c12FM/gM/TDQc= 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 1657141734850264.5482324581966; Wed, 6 Jul 2022 14:08:54 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.362549.592663 (Exim 4.92) (envelope-from ) id 1o9CGB-0000AX-Vu; Wed, 06 Jul 2022 21:08:35 +0000 Received: by outflank-mailman (output) from mailman id 362549.592663; Wed, 06 Jul 2022 21:08:35 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1o9CGB-00008t-Rn; Wed, 06 Jul 2022 21:08:35 +0000 Received: by outflank-mailman (input) for mailman id 362549; Wed, 06 Jul 2022 21:08:33 +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 1o9CFW-0003HV-9b for xen-devel@lists.xenproject.org; Wed, 06 Jul 2022 21:07:54 +0000 Received: from sender4-of-o51.zoho.com (sender4-of-o51.zoho.com [136.143.188.51]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id b1eea131-fd6f-11ec-924f-1f966e50362f; Wed, 06 Jul 2022 23:07:52 +0200 (CEST) Received: from sisyou.hme. (static-72-81-132-2.bltmmd.fios.verizon.net [72.81.132.2]) by mx.zohomail.com with SMTPS id 1657141518204185.36893009232347; Wed, 6 Jul 2022 14:05:18 -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: b1eea131-fd6f-11ec-924f-1f966e50362f ARC-Seal: i=1; a=rsa-sha256; t=1657141520; cv=none; d=zohomail.com; s=zohoarc; b=Ue1eFEAVuXgejFvAA+0yve4SHos8OvlwOoZRAvApcYMSGy+9pBEIMLkrMJiSyhD0HscYiMrbOqu8ZYkcnyyr/gJB0jISG4TDkwqKmpJspwli5Cd1urWnGazn6WLsIJN5PZlJspDbC6CiLa7eUI11SN3HUOHIPMEG956hzP0lfbs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657141520; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=F4LzAhNPz1Ut05j8lMJsWMf8SmFv3K61ZtdVdpesbfA=; b=gc6mXWqlp7guNMHg/OlgAe8zR8zr9/2z6/Hi3fR9d7Dn5sij9HLJzf3nVKYrM1vEE1M5AMbj59iBJ6ua5DkWYWGZxeij3czMtL4vYS2BhAe1+Fe0b2L39GADKlrdt5PAml8UOfz+iMKtGc2KYMSIL4dbWnyPu+mLQgxVGQvvvVQ= 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=1657141520; 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=F4LzAhNPz1Ut05j8lMJsWMf8SmFv3K61ZtdVdpesbfA=; b=e6xBEFOFce8A+eAooJUkrcJudnW0akQ8Er0WlYkmWnsHROtQYQ50y3+5ETDM1qiv mK0gjlizY++GnCuUB+7EG5yKBevt3+AaS7hhI8YHSPQ2ov/mamqP2kXJ/pUbCegif9r FR67yWmaULGDF3K0z6yMWppXs+d5NLFunVisrfAQ= From: "Daniel P. Smith" To: xen-devel@lists.xenproject.org, Wei Liu Cc: "Daniel P. Smith" , scott.davis@starlab.io, christopher.clark@starlab.io, Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , George Dunlap , Julien Grall , Stefano Stabellini Subject: [PATCH v1 10/18] x86: introduce the domain builder Date: Wed, 6 Jul 2022 17:04:45 -0400 Message-Id: <20220706210454.30096-11-dpsmith@apertussolutions.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220706210454.30096-1-dpsmith@apertussolutions.com> References: <20220706210454.30096-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: 1657141736182100001 Content-Type: text/plain; charset="utf-8" This commit introduces the domain builder configuration FDT parser along wi= th the domain builder core for domain creation. To enable domain builder to be= a cross architecture internal API, a new arch domain creation call is introdu= ced for use by the domain builder. Signed-off-by: Daniel P. Smith Reviewed-by: Christopher Clark --- xen/arch/x86/setup.c | 9 + xen/common/Makefile | 1 + xen/common/domain-builder/Makefile | 2 + xen/common/domain-builder/core.c | 96 ++++++++++ xen/common/domain-builder/fdt.c | 295 +++++++++++++++++++++++++++++ xen/common/domain-builder/fdt.h | 7 + xen/include/xen/bootinfo.h | 16 ++ xen/include/xen/domain_builder.h | 1 + 8 files changed, 427 insertions(+) create mode 100644 xen/common/domain-builder/Makefile create mode 100644 xen/common/domain-builder/core.c create mode 100644 xen/common/domain-builder/fdt.c create mode 100644 xen/common/domain-builder/fdt.h diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index e4060d6219..28dbfcd209 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -1,4 +1,6 @@ +#include #include +#include #include #include #include @@ -826,6 +828,13 @@ static struct domain *__init create_dom0(const struct = boot_info *bi) return d; } =20 +void __init arch_create_dom( + const struct boot_info *bi, struct boot_domain *bd) +{ + if ( builder_is_initdom(bd) ) + create_dom0(bi); +} + /* How much of the directmap is prebuilt at compile time. */ #define PREBUILT_MAP_LIMIT (1 << L2_PAGETABLE_SHIFT) =20 diff --git a/xen/common/Makefile b/xen/common/Makefile index ebd3e2d659..eb108fa107 100644 --- a/xen/common/Makefile +++ b/xen/common/Makefile @@ -72,6 +72,7 @@ extra-y :=3D symbols-dummy.o obj-$(CONFIG_COVERAGE) +=3D coverage/ obj-y +=3D sched/ obj-$(CONFIG_UBSAN) +=3D ubsan/ +obj-y +=3D domain-builder/ =20 obj-$(CONFIG_NEEDS_LIBELF) +=3D libelf/ obj-$(CONFIG_CORE_DEVICE_TREE) +=3D libfdt/ diff --git a/xen/common/domain-builder/Makefile b/xen/common/domain-builder= /Makefile new file mode 100644 index 0000000000..9561602502 --- /dev/null +++ b/xen/common/domain-builder/Makefile @@ -0,0 +1,2 @@ +obj-$(CONFIG_BUILDER_FDT) +=3D fdt.o +obj-y +=3D core.o diff --git a/xen/common/domain-builder/core.c b/xen/common/domain-builder/c= ore.c new file mode 100644 index 0000000000..b030b07d71 --- /dev/null +++ b/xen/common/domain-builder/core.c @@ -0,0 +1,96 @@ +#include +#include +#include +#include +#include + +#include +#include + +#include "fdt.h" + +static struct domain_builder __initdata builder; + +void __init builder_init(struct boot_info *info) +{ + struct boot_domain *d =3D NULL; + + info->builder =3D &builder; + + if ( IS_ENABLED(CONFIG_BUILDER_FDT) ) + { + /* fdt is required to be module 0 */ + switch ( check_fdt(info, __va(info->mods[0].start)) ) + { + case 0: + printk("Domain Builder: initialized from config\n"); + info->builder->fdt_enabled =3D true; + return; + case -EINVAL: + info->builder->fdt_enabled =3D false; + break; + case -ENODATA: + default: + panic("%s: error occured processing DTB\n", __func__); + } + } + + /* + * No FDT config support or an FDT wasn't present, do an initial + * domain construction + */ + printk("Domain Builder: falling back to initial domain build\n"); + info->builder->nr_doms =3D 1; + d =3D &info->builder->domains[0]; + + d->mode =3D opt_dom0_pvh ? 0 : BUILD_MODE_PARAVIRTUALIZED; + + d->kernel =3D &info->mods[0]; + d->kernel->kind =3D BOOTMOD_KERNEL; + + d->permissions =3D BUILD_PERMISSION_CONTROL | BUILD_PERMISSION_HARDWAR= E; + d->functions =3D BUILD_FUNCTION_CONSOLE | BUILD_FUNCTION_XENSTORE | + BUILD_FUNCTION_INITIAL_DOM; + + d->kernel->arch->headroom =3D bzimage_headroom(bootstrap_map(d->kernel= ), + d->kernel->size); + bootstrap_map(NULL); + + if ( d->kernel->string.len ) + d->kernel->string.kind =3D BOOTSTR_CMDLINE; +} + +uint32_t __init builder_create_domains(struct boot_info *info) +{ + uint32_t build_count =3D 0, functions_built =3D 0; + int i; + + for ( i =3D 0; i < info->builder->nr_doms; i++ ) + { + struct boot_domain *d =3D &info->builder->domains[i]; + + if ( ! IS_ENABLED(CONFIG_MULTIDOM_BUILDER) && + ! builder_is_initdom(d) && + functions_built & BUILD_FUNCTION_INITIAL_DOM ) + continue; + + if ( d->kernel =3D=3D NULL ) + { + if ( builder_is_initdom(d) ) + panic("%s: intial domain missing kernel\n", __func__); + + printk(XENLOG_ERR "%s:Dom%d definiton has no kernel\n", __func= __, + d->domid); + continue; + } + + arch_create_dom(info, d); + if ( d->domain ) + { + functions_built |=3D d->functions; + build_count++; + } + } + + return build_count; +} diff --git a/xen/common/domain-builder/fdt.c b/xen/common/domain-builder/fd= t.c new file mode 100644 index 0000000000..937cc61e7a --- /dev/null +++ b/xen/common/domain-builder/fdt.c @@ -0,0 +1,295 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "fdt.h" + +#define BUILDER_FDT_TARGET_UNK 0 +#define BUILDER_FDT_TARGET_X86 1 +#define BUILDER_FDT_TARGET_ARM 2 +static int __initdata target_arch =3D BUILDER_FDT_TARGET_UNK; + +static struct boot_module *read_module( + const void *fdt, int node, uint32_t address_cells, uint32_t size_cells, + struct boot_info *info) +{ + const struct fdt_property *prop; + const __be32 *cell; + struct boot_module *bm; + bootmodule_kind kind =3D BOOTMOD_UNKNOWN; + int len; + + if ( device_tree_node_compatible(fdt, node, "module,kernel") ) + kind =3D BOOTMOD_KERNEL; + + if ( device_tree_node_compatible(fdt, node, "module,ramdisk") ) + kind =3D BOOTMOD_RAMDISK; + + if ( device_tree_node_compatible(fdt, node, "module,microcode") ) + kind =3D BOOTMOD_UCODE; + + if ( device_tree_node_compatible(fdt, node, "module,xsm-policy") ) + kind =3D BOOTMOD_XSM; + + if ( device_tree_node_compatible(fdt, node, "module,config") ) + kind =3D BOOTMOD_GUEST_CONF; + + if ( device_tree_node_compatible(fdt, node, "module,index") ) + { + uint32_t idx; + + idx =3D (uint32_t)device_tree_get_u32(fdt, node, "module-index", 0= ); + if ( idx =3D=3D 0 ) + return NULL; + + bm =3D &info->mods[idx]; + + bm->kind =3D kind; + + return bm; + } + + if ( device_tree_node_compatible(fdt, node, "module,addr") ) + { + uint64_t addr, size; + + prop =3D fdt_get_property(fdt, node, "module-addr", &len); + if ( !prop ) + return NULL; + + if ( len < dt_cells_to_size(address_cells + size_cells) ) + return NULL; + + cell =3D (const __be32 *)prop->data; + device_tree_get_reg( + &cell, address_cells, size_cells, &addr, &size); + + bm =3D bootmodule_next_by_addr(info, addr, NULL); + + bm->kind =3D kind; + + return bm; + } + + printk(XENLOG_WARNING + "builder fdt: module node %d, no index or addr provided\n", + node); + + return NULL; +} + +static int process_config_node( + const void *fdt, int node, const char *name, int depth, + uint32_t address_cells, uint32_t size_cells, void *data) +{ + struct boot_info *info =3D (struct boot_info *)data; + int node_next; + + if ( !info ) + return -1; + + for ( node_next =3D fdt_first_subnode(fdt, node); + node_next > 0; + node_next =3D fdt_next_subnode(fdt, node_next)) + read_module(fdt, node_next, address_cells, size_cells, info); + + return 0; +} + +static int process_domain_node( + const void *fdt, int node, const char *name, int depth, + uint32_t address_cells, uint32_t size_cells, void *data) +{ + struct boot_info *info =3D (struct boot_info *)data; + const struct fdt_property *prop; + struct boot_domain *domain; + int node_next, i, plen; + + if ( !info ) + return -1; + + if ( info->builder->nr_doms >=3D BUILD_MAX_BOOT_DOMAINS ) + return -1; + + domain =3D &info->builder->domains[info->builder->nr_doms]; + + domain->domid =3D (domid_t)device_tree_get_u32(fdt, node, "domid", 0); + domain->permissions =3D device_tree_get_u32(fdt, node, "permissions", = 0); + domain->functions =3D device_tree_get_u32(fdt, node, "functions", 0); + domain->mode =3D device_tree_get_u32(fdt, node, "mode", 0); + + prop =3D fdt_get_property(fdt, node, "domain-uuid", &plen); + if ( prop ) + for ( i=3D0; i < sizeof(domain->uuid) % sizeof(uint32_t); i++ ) + *(domain->uuid + i) =3D fdt32_to_cpu((uint32_t)prop->data[i]); + + domain->ncpus =3D device_tree_get_u32(fdt, node, "cpus", 1); + + if ( target_arch =3D=3D BUILDER_FDT_TARGET_X86 ) + { + prop =3D fdt_get_property(fdt, node, "memory", &plen); + if ( prop ) + { + int sz =3D fdt32_to_cpu(prop->len); + char s[64]; + unsigned long val; + + if ( sz >=3D 64 ) + panic("node %s invalid `memory' property\n", name); + + memcpy(s, prop->data, sz); + s[sz] =3D '\0'; + val =3D parse_size_and_unit(s, NULL); + + domain->meminfo.mem_size.nr_pages =3D PFN_UP(val); + domain->meminfo.mem_max.nr_pages =3D PFN_UP(val); + } + else + panic("node %s missing `memory' property\n", name); + } + else + panic("%s: only x86 memory parsing supported\n", __func__); + + prop =3D fdt_get_property(fdt, node, "security-id", + &plen); + if ( prop ) + { + int sz =3D fdt32_to_cpu(prop->len); + sz =3D sz > BUILD_MAX_SECID_LEN ? BUILD_MAX_SECID_LEN : sz; + memcpy(domain->secid, prop->data, sz); + } + + for ( node_next =3D fdt_first_subnode(fdt, node); + node_next > 0; + node_next =3D fdt_next_subnode(fdt, node_next)) + { + struct boot_module *bm =3D read_module(fdt, node_next, address_cel= ls, + size_cells, info); + + switch ( bm->kind ) + { + case BOOTMOD_KERNEL: + /* kernel was already found */ + if ( domain->kernel !=3D NULL ) + continue; + + bm->arch->headroom =3D bzimage_headroom(bootstrap_map(bm), bm-= >size); + bootstrap_map(NULL); + + if ( bm->string.len ) + bm->string.kind =3D BOOTSTR_CMDLINE; + else + { + prop =3D fdt_get_property(fdt, node_next, "bootargs", &ple= n); + if ( prop ) + { + int size =3D fdt32_to_cpu(prop->len); + size =3D size > BOOTMOD_MAX_STRING ? + BOOTMOD_MAX_STRING : size; + memcpy(bm->string.bytes, prop->data, size); + bm->string.kind =3D BOOTSTR_CMDLINE; + } + } + + domain->kernel =3D bm; + + break; + case BOOTMOD_RAMDISK: + /* ramdisk was already found */ + if ( domain->ramdisk !=3D NULL ) + continue; + + domain->ramdisk =3D bm; + + break; + case BOOTMOD_GUEST_CONF: + /* guest config was already found */ + if ( domain->configs[BUILD_DOM_CONF_IDX] !=3D NULL ) + continue; + + domain->configs[BUILD_DOM_CONF_IDX] =3D bm; + + break; + default: + continue; + } + } + + info->builder->nr_doms++; + + return 0; +} + +static int __init scan_node( + const void *fdt, int node, const char *name, int depth, u32 address_ce= lls, + u32 size_cells, void *data) +{ + int rc =3D -1; + + /* skip nodes that are not direct children of the hyperlaunch node */ + if ( depth > 1 ) + return 0; + + if ( device_tree_node_compatible(fdt, node, "xen,config") ) + rc =3D process_config_node(fdt, node, name, depth, + address_cells, size_cells, data); + else if ( device_tree_node_compatible(fdt, node, "xen,domain") ) + rc =3D process_domain_node(fdt, node, name, depth, + address_cells, size_cells, data); + + if ( rc < 0 ) + printk("hyperlaunch fdt: node `%s'failed to parse\n", name); + + return rc; +} + +/* check_fdt + * Attempts to initialize hyperlaunch config + * + * Returns: + * -EINVAL: Not a valid DTB + * -ENODATA: Valid DTB but not a valid hyperlaunch device tree + * 0: Valid hyperlaunch device tree + */ +int __init check_fdt(struct boot_info *info, void *fdt) +{ + int hv_node, ret; + + ret =3D fdt_check_header(fdt); + if ( ret < 0 ) + return -EINVAL; + + hv_node =3D fdt_path_offset(fdt, "/chosen/hypervisor"); + if ( hv_node < 0 ) + return -ENODATA; + + if ( !device_tree_node_compatible(fdt, hv_node, "hypervisor,xen") ) + return -EINVAL; + + if ( IS_ENABLED(CONFIG_X86) && + device_tree_node_compatible(fdt, hv_node, "xen,x86") ) + target_arch =3D BUILDER_FDT_TARGET_X86; + else if ( IS_ENABLED(CONFIG_ARM) && + device_tree_node_compatible(fdt, hv_node, "xen,arm") ) + target_arch =3D BUILDER_FDT_TARGET_ARM; + + if ( target_arch !=3D BUILDER_FDT_TARGET_X86 && + target_arch !=3D BUILDER_FDT_TARGET_ARM ) + return -EINVAL; + + ret =3D device_tree_for_each_node(fdt, hv_node, scan_node, boot_info); + if ( ret > 0 ) + return -ENODATA; + + return 0; +} diff --git a/xen/common/domain-builder/fdt.h b/xen/common/domain-builder/fd= t.h new file mode 100644 index 0000000000..b185718412 --- /dev/null +++ b/xen/common/domain-builder/fdt.h @@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef COMMON_BUILDER_FDT_H +#define COMMON_BUILDER_FDT_H + +int __init check_fdt(struct boot_info *info, void *fdt); +#endif diff --git a/xen/include/xen/bootinfo.h b/xen/include/xen/bootinfo.h index 1d76d99a40..07b151e318 100644 --- a/xen/include/xen/bootinfo.h +++ b/xen/include/xen/bootinfo.h @@ -101,6 +101,22 @@ static inline struct boot_module *bootmodule_next_by_k= ind( return NULL; } =20 +static inline struct boot_module *bootmodule_next_by_addr( + const struct boot_info *bi, paddr_t addr, struct boot_module *start) +{ + /* point end at the entry for xen */ + struct boot_module *end =3D &bi->mods[bi->nr_mods]; + + if ( !start ) + start =3D bi->mods; + + for ( ; start < end; start++ ) + if ( start->start =3D=3D addr ) + return start; + + return NULL; +} + static inline void bootmodule_update_start(struct boot_module *b, paddr_t = new_start) { b->start =3D new_start; diff --git a/xen/include/xen/domain_builder.h b/xen/include/xen/domain_buil= der.h index 79785ef251..c0d997f7bd 100644 --- a/xen/include/xen/domain_builder.h +++ b/xen/include/xen/domain_builder.h @@ -51,5 +51,6 @@ static inline struct domain *builder_get_hwdom(struct boo= t_info *info) =20 void builder_init(struct boot_info *info); uint32_t builder_create_domains(struct boot_info *info); +void arch_create_dom(const struct boot_info *bi, struct boot_domain *bd); =20 #endif /* XEN_DOMAIN_BUILDER_H */ --=20 2.20.1 From nobody Mon May 20 18:31:35 2024 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=1657141737; cv=pass; d=zohomail.com; s=zohoarc; b=nnNqmSsLoYiVkO1nf2QJxxfSCy/kiQmno122vz5gd349wUZDkqCfrW0jqm4XFZu1e7yEh6a52fhDz8ShVoTvNNub7rk6Gbzzi0Yt+XklrubY4JiZDVp934M8GGEIJH1lUfHhX5Du5aPlIw9CseFdKdobB/YyCZWu3qHW2hnZpZk= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657141737; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=eTpqwxpSkEMWg//PoKCMIGmKB8+qr3bwNRO2rt7uCKo=; b=c6a2IIA14JwoMh0/AsUz9snJdrHu+NgTjaXozhu970kO03eahvurVGSEPGEbV/bVOD2jeMeLWb4JcO8YxtnAYbetDRsatJ/DP75AVdlD2MWpkq4ui9SFd8yE1zi3wH25wxyyZEybvIxS0vgH+dz+FEhdb0bZr4Xg6+OBj1XidZo= 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 1657141737116211.21340251125582; Wed, 6 Jul 2022 14:08:57 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.362550.592668 (Exim 4.92) (envelope-from ) id 1o9CGC-0000Ey-Db; Wed, 06 Jul 2022 21:08:36 +0000 Received: by outflank-mailman (output) from mailman id 362550.592668; Wed, 06 Jul 2022 21:08: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 1o9CGC-0000EN-6F; Wed, 06 Jul 2022 21:08:36 +0000 Received: by outflank-mailman (input) for mailman id 362550; Wed, 06 Jul 2022 21:08:34 +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 1o9CFl-0003HV-0C for xen-devel@lists.xenproject.org; Wed, 06 Jul 2022 21:08:09 +0000 Received: from sender4-of-o51.zoho.com (sender4-of-o51.zoho.com [136.143.188.51]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id bae41d24-fd6f-11ec-924f-1f966e50362f; Wed, 06 Jul 2022 23:08:07 +0200 (CEST) Received: from sisyou.hme. (static-72-81-132-2.bltmmd.fios.verizon.net [72.81.132.2]) by mx.zohomail.com with SMTPS id 1657141520651940.6489274956703; Wed, 6 Jul 2022 14:05:20 -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: bae41d24-fd6f-11ec-924f-1f966e50362f ARC-Seal: i=1; a=rsa-sha256; t=1657141522; cv=none; d=zohomail.com; s=zohoarc; b=bmYSXXAUB8n4jSmYj9pKCDn2/3VNyaxHV4BJgn8SwBVOKjN4q5kJ6wB7JaTqWt+inxiWwVfWvTTdeP5mfEITFjzQoqbHXvMxBx/9V1hgI1JIZc8HO2zLpB4YfWrdECHcz5sOTii9yjMbBosZWbaUom5EXUkbEfTS6GHdMTQfp7w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657141522; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=eTpqwxpSkEMWg//PoKCMIGmKB8+qr3bwNRO2rt7uCKo=; b=inPXKKpZqe9qe9iysKSIX2T1UnQj+vvh9u+rMs9FCpDbfzpENQQXg/rkhWdb9J7Lpz/I23ah36RQOCM1O/yQjnOgFw/Wx+LoqNcCEhHI7aYI9tHM3RiNbDwuVY9NLsyiQ0yAtI1V7EPibmXkebWlefXxu+fyEwzXvsNhSfOCWwU= 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=1657141522; 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=eTpqwxpSkEMWg//PoKCMIGmKB8+qr3bwNRO2rt7uCKo=; b=Uo4wzGK9lFd7R8bDuJokrOPOnARrls4G0FKlTP2ZIIA3y0D6zX+sWF1RQvA9SBdF tpvS/wxIfvEmRz6AbtHsSkSuF9f0hU0XvPUfqHJ1SOQ453SpXIlmZbmOF2JJoOfLAFA fPum7fIiqay1QIJx7SWKiUGo6X8e2FIFD/+bb7g4= From: "Daniel P. Smith" To: xen-devel@lists.xenproject.org, Wei Liu Cc: "Daniel P. Smith" , scott.davis@starlab.io, christopher.clark@starlab.io, Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH v1 11/18] x86: initial conversion to domain builder Date: Wed, 6 Jul 2022 17:04:46 -0400 Message-Id: <20220706210454.30096-12-dpsmith@apertussolutions.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220706210454.30096-1-dpsmith@apertussolutions.com> References: <20220706210454.30096-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: 1657141738258100001 Content-Type: text/plain; charset="utf-8" This commit is the first step in adopting domain builder. It goes through t= he dom0 creation and construction functions, converting them over to consume struct boot_domaain and changes the startup sequence to use the domain buil= der to create and construct dom0. Signed-off-by: Daniel P. Smith Reviewed-by: Christopher Clark --- xen/arch/x86/dom0_build.c | 30 +++---- xen/arch/x86/hvm/dom0_build.c | 10 +-- xen/arch/x86/include/asm/dom0_build.h | 8 +- xen/arch/x86/include/asm/setup.h | 5 +- xen/arch/x86/pv/dom0_build.c | 39 ++++----- xen/arch/x86/setup.c | 114 +++++++++++++++----------- 6 files changed, 109 insertions(+), 97 deletions(-) diff --git a/xen/arch/x86/dom0_build.c b/xen/arch/x86/dom0_build.c index e44f7f3c43..216c9e3590 100644 --- a/xen/arch/x86/dom0_build.c +++ b/xen/arch/x86/dom0_build.c @@ -6,6 +6,7 @@ =20 #include #include +#include #include #include #include @@ -556,31 +557,32 @@ int __init dom0_setup_permissions(struct domain *d) return rc; } =20 -int __init construct_dom0( - struct domain *d, const struct boot_module *image, - struct boot_module *initrd, char *cmdline) +int __init construct_domain(struct boot_domain *bd) { - int rc; + int rc =3D 0; =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); + BUG_ON(!pv_shim && bd->domid !=3D 0); + BUG_ON(bd->domain->vcpu[0] =3D=3D NULL); + BUG_ON(bd->domain->vcpu[0]->is_initialised); =20 process_pending_softirqs(); =20 - if ( is_hvm_domain(d) ) - rc =3D dom0_construct_pvh(d, image, initrd, cmdline); - else if ( is_pv_domain(d) ) - rc =3D dom0_construct_pv(d, image, initrd, cmdline); - else - panic("Cannot construct Dom0. No guest interface available\n"); + if ( builder_is_initdom(bd) ) + { + if ( is_hvm_domain(bd->domain) ) + rc =3D dom0_construct_pvh(bd); + else if ( is_pv_domain(bd->domain) ) + rc =3D dom0_construct_pv(bd); + else + panic("Cannot construct Dom0. No guest interface available\n"); + } =20 if ( rc ) return rc; =20 /* Sanity! */ - BUG_ON(!d->vcpu[0]->is_initialised); + BUG_ON(!bd->domain->vcpu[0]->is_initialised); =20 return 0; } diff --git a/xen/arch/x86/hvm/dom0_build.c b/xen/arch/x86/hvm/dom0_build.c index 4e903a848d..2fee2ed926 100644 --- a/xen/arch/x86/hvm/dom0_build.c +++ b/xen/arch/x86/hvm/dom0_build.c @@ -19,6 +19,7 @@ */ =20 #include +#include #include #include #include @@ -1217,10 +1218,9 @@ static void __hwdom_init pvh_setup_mmcfg(struct doma= in *d) } } =20 -int __init dom0_construct_pvh( - struct domain *d, const struct boot_module *image, - struct boot_module *initrd, char *cmdline) +int __init dom0_construct_pvh(struct boot_domain *bd) { + struct domain *d =3D bd->domain; paddr_t entry, start_info; int rc; =20 @@ -1249,8 +1249,8 @@ int __init dom0_construct_pvh( return rc; } =20 - rc =3D pvh_load_kernel(d, image, initrd, bootstrap_map(image), - cmdline, &entry, &start_info); + rc =3D pvh_load_kernel(d, bd->kernel, bd->ramdisk, bootstrap_map(bd->k= ernel), + bd->kernel->string.bytes, &entry, &start_info); if ( rc ) { printk("Failed to load Dom0 kernel\n"); diff --git a/xen/arch/x86/include/asm/dom0_build.h b/xen/arch/x86/include/a= sm/dom0_build.h index ad33413710..571b25ea71 100644 --- a/xen/arch/x86/include/asm/dom0_build.h +++ b/xen/arch/x86/include/asm/dom0_build.h @@ -14,13 +14,9 @@ unsigned long dom0_compute_nr_pages(struct domain *d, unsigned long initrd_len); int dom0_setup_permissions(struct domain *d); =20 -int __init dom0_construct_pv( - struct domain *d, const struct boot_module *image, - struct boot_module *initrd, char *cmdline); +int dom0_construct_pv(struct boot_domain *bd); =20 -int __init dom0_construct_pvh( - struct domain *d, const struct boot_module *image, - struct boot_module *initrd, char *cmdline); +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/include/asm/setup.h b/xen/arch/x86/include/asm/se= tup.h index 27c0d61819..f9c1468fcc 100644 --- a/xen/arch/x86/include/asm/setup.h +++ b/xen/arch/x86/include/asm/setup.h @@ -33,9 +33,8 @@ void vesa_init(void); static inline void vesa_init(void) {}; #endif =20 -int construct_dom0( - struct domain *d, const struct boot_module *image, - struct boot_module *initrd, char *cmdline); +int construct_domain(struct boot_domain *bd); + void setup_io_bitmap(struct domain *d); =20 unsigned long initial_images_nrpages(nodeid_t node); diff --git a/xen/arch/x86/pv/dom0_build.c b/xen/arch/x86/pv/dom0_build.c index f6131147ef..78ebb03b1b 100644 --- a/xen/arch/x86/pv/dom0_build.c +++ b/xen/arch/x86/pv/dom0_build.c @@ -4,6 +4,7 @@ * Copyright (c) 2002-2005, K A Fraser */ =20 +#include #include #include #include @@ -295,9 +296,7 @@ static struct page_info * __init alloc_chunk(struct dom= ain *d, return page; } =20 -int __init dom0_construct_pv( - struct domain *d, const struct boot_module *image, - struct boot_module *initrd, char *cmdline) +int __init dom0_construct_pv(struct boot_domain *bd) { int i, rc, order, machine; bool compatible, compat; @@ -311,11 +310,12 @@ int __init dom0_construct_pv( unsigned long count; struct page_info *page =3D NULL; start_info_t *si; + struct domain *d =3D bd->domain; struct vcpu *v =3D d->vcpu[0]; - void *image_base =3D bootstrap_map(image); - unsigned long image_len =3D image->size; - void *image_start =3D image_base + image->arch->headroom; - unsigned long initrd_len =3D initrd ? initrd->size : 0; + void *image_base =3D bootstrap_map(bd->kernel); + unsigned long image_len =3D bd->kernel->size; + void *image_start =3D image_base + bd->kernel->arch->headroom; + unsigned long initrd_len =3D bd->ramdisk ? bd->ramdisk->size : 0; l4_pgentry_t *l4tab =3D NULL, *l4start =3D NULL; l3_pgentry_t *l3tab =3D NULL, *l3start =3D NULL; l2_pgentry_t *l2tab =3D NULL, *l2start =3D NULL; @@ -355,7 +355,7 @@ int __init dom0_construct_pv( d->max_pages =3D ~0U; =20 if ( (rc =3D - bzimage_parse(image_base, &image_start, image->arch->headroom, + bzimage_parse(image_base, &image_start, bd->kernel->arch->headro= om, &image_len)) !=3D 0 ) return rc; =20 @@ -545,7 +545,7 @@ int __init dom0_construct_pv( initrd_pfn =3D vinitrd_start ? (vinitrd_start - v_start) >> PAGE_SHIFT : domain_tot_pages(d); - initrd_mfn =3D mfn =3D mfn_x(initrd->mfn); + initrd_mfn =3D mfn =3D mfn_x(bd->ramdisk->mfn); count =3D PFN_UP(initrd_len); if ( d->arch.physaddr_bitsize && ((mfn + count - 1) >> (d->arch.physaddr_bitsize - PAGE_SHIFT)= ) ) @@ -560,13 +560,13 @@ int __init dom0_construct_pv( free_domheap_pages(page, order); page +=3D 1UL << order; } - memcpy(page_to_virt(page), maddr_to_virt(initrd->start), + memcpy(page_to_virt(page), maddr_to_virt(bd->ramdisk->start), initrd_len); - mpt_alloc =3D initrd->start; + mpt_alloc =3D bd->ramdisk->start; init_domheap_pages(mpt_alloc, mpt_alloc + PAGE_ALIGN(initrd_len)); - bootmodule_update_mfn(initrd, page_to_mfn(page)); - initrd_mfn =3D mfn_x(initrd->mfn); + bootmodule_update_mfn(bd->ramdisk, page_to_mfn(page)); + initrd_mfn =3D mfn_x(bd->ramdisk->mfn); } else { @@ -574,7 +574,7 @@ int __init dom0_construct_pv( if ( assign_pages(mfn_to_page(_mfn(mfn++)), 1, d, 0) ) BUG(); } - initrd->size =3D 0; + bd->ramdisk->size =3D 0; } =20 printk("PHYSICAL MEMORY ARRANGEMENT:\n" @@ -583,9 +583,9 @@ int __init dom0_construct_pv( if ( domain_tot_pages(d) < nr_pages ) printk(" (%lu pages to be allocated)", nr_pages - domain_tot_pages(d)); - if ( initrd ) + if ( bd->ramdisk ) { - mpt_alloc =3D initrd->start; + mpt_alloc =3D bd->ramdisk->start; printk("\n Init. ramdisk: %"PRIpaddr"->%"PRIpaddr, mpt_alloc, mpt_alloc + initrd_len); } @@ -806,7 +806,7 @@ int __init dom0_construct_pv( if ( pfn >=3D initrd_pfn ) { if ( pfn < initrd_pfn + PFN_UP(initrd_len) ) - mfn =3D mfn_x(initrd->mfn) + (pfn - initrd_pfn); + mfn =3D mfn_x(bd->ramdisk->mfn) + (pfn - initrd_pfn); else mfn -=3D PFN_UP(initrd_len); } @@ -866,8 +866,9 @@ int __init dom0_construct_pv( } =20 memset(si->cmd_line, 0, sizeof(si->cmd_line)); - if ( cmdline !=3D NULL ) - strlcpy((char *)si->cmd_line, cmdline, sizeof(si->cmd_line)); + if ( strlen(bd->kernel->string.bytes) > 0 ) + strlcpy((char *)si->cmd_line, bd->kernel->string.bytes, + sizeof(si->cmd_line)); =20 #ifdef CONFIG_VIDEO if ( !pv_shim && fill_console_start_info((void *)(si + 1)) ) diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 28dbfcd209..860b9e3d64 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -45,7 +45,6 @@ #include #include #include -#include /* for bzimage_headroom */ #include /* for generic_apic_probe */ #include #include @@ -272,6 +271,24 @@ static int __init cf_check parse_acpi_param(const char= *s) } custom_param("acpi", parse_acpi_param); =20 +void __init arch_builder_apply_cmdline( + struct boot_info *info, struct boot_domain *bd) +{ + if ( skip_ioapic_setup && !strstr(bd->kernel->string.bytes, "noapic") ) + strlcat(bd->kernel->string.bytes, " noapic", MAX_GUEST_CMDLINE); + if ( (strlen(acpi_param) =3D=3D 0) && acpi_disabled ) + { + printk("ACPI is disabled, notifying Domain 0 (acpi=3Doff)\n"); + strlcpy(acpi_param, "off", sizeof(acpi_param)); + } + if ( (strlen(acpi_param) !=3D 0) && + !strstr(bd->kernel->string.bytes, "acpi=3D") ) + { + strlcat(bd->kernel->string.bytes, " acpi=3D", MAX_GUEST_CMDLINE); + strlcat(bd->kernel->string.bytes, acpi_param, MAX_GUEST_CMDLINE); + } +} + struct boot_info __initdata *boot_info; =20 unsigned long __init initial_images_nrpages(nodeid_t node) @@ -728,7 +745,8 @@ static unsigned int __init copy_bios_e820(struct e820en= try *map, unsigned int li return n; } =20 -static struct domain *__init create_dom0(const struct boot_info *bi) +static struct domain *__init create_dom0( + const struct boot_info *bi, struct boot_domain *bd) { struct xen_domctl_createdomain dom0_cfg =3D { .flags =3D IS_ENABLED(CONFIG_TBOOT) ? XEN_DOMCTL_CDF_s3_integrity = : 0, @@ -741,14 +759,10 @@ static struct domain *__init create_dom0(const struct= boot_info *bi) .misc_flags =3D opt_dom0_msr_relaxed ? XEN_X86_MSR_RELAXED : 0, }, }; - struct boot_module *image =3D bootmodule_next_by_kind(bi, BOOTMOD_KERN= EL, 0); - struct boot_module *initrd =3D bootmodule_next_by_kind(bi, BOOTMOD_RAM= DISK, 0); - struct domain *d; char *cmdline; - domid_t domid =3D 0; =20 - if ( image =3D=3D NULL ) - panic("Error creating d%uv0\n", domid); + if ( bd->kernel =3D=3D NULL ) + panic("Error creating d%uv0\n", bd->domid); =20 if ( opt_dom0_pvh ) { @@ -764,45 +778,46 @@ static struct domain *__init create_dom0(const struct= boot_info *bi) dom0_cfg.flags |=3D XEN_DOMCTL_CDF_iommu; =20 /* Create initial domain. Not d0 for pvshim. */ - domid =3D get_initial_domain_id(); - d =3D domain_create(domid, &dom0_cfg, pv_shim ? 0 : CDF_privileged); - if ( IS_ERR(d) ) - panic("Error creating d%u: %ld\n", domid, PTR_ERR(d)); + bd->domid =3D get_initial_domain_id(); + bd->domain =3D domain_create(bd->domid, &dom0_cfg, pv_shim ? + 0 : CDF_privileged); + if ( IS_ERR(bd->domain) ) + panic("Error creating d%u: %ld\n", bd->domid, PTR_ERR(bd->domain)); =20 - init_dom0_cpuid_policy(d); + init_dom0_cpuid_policy(bd->domain); =20 - if ( alloc_dom0_vcpu0(d) =3D=3D NULL ) - panic("Error creating d%uv0\n", domid); + if ( alloc_dom0_vcpu0(bd->domain) =3D=3D NULL ) + panic("Error creating d%uv0\n", bd->domid); =20 /* Grab the DOM0 command line. */ - cmdline =3D (image->string.kind =3D=3D BOOTSTR_CMDLINE) ? - image->string.bytes : NULL; + cmdline =3D (bd->kernel->string.kind =3D=3D BOOTSTR_CMDLINE) ? + bd->kernel->string.bytes : NULL; if ( cmdline || bi->arch->kextra ) { - static char __initdata dom0_cmdline[MAX_GUEST_CMDLINE]; + char dom0_cmdline[MAX_GUEST_CMDLINE]; =20 cmdline =3D arch_prepare_cmdline(cmdline, bi->arch); - safe_strcpy(dom0_cmdline, cmdline); + strlcpy(dom0_cmdline, cmdline, MAX_GUEST_CMDLINE); =20 if ( bi->arch->kextra ) /* kextra always includes exactly one leading space. */ - safe_strcat(dom0_cmdline, bi->arch->kextra); + strlcat(dom0_cmdline, bi->arch->kextra, MAX_GUEST_CMDLINE); =20 /* Append any extra parameters. */ if ( skip_ioapic_setup && !strstr(dom0_cmdline, "noapic") ) - safe_strcat(dom0_cmdline, " noapic"); + strlcat(dom0_cmdline, " noapic", MAX_GUEST_CMDLINE); if ( (strlen(acpi_param) =3D=3D 0) && acpi_disabled ) { printk("ACPI is disabled, notifying Domain 0 (acpi=3Doff)\n"); - safe_strcpy(acpi_param, "off"); + strlcpy(acpi_param, "off", sizeof(acpi_param)); } if ( (strlen(acpi_param) !=3D 0) && !strstr(dom0_cmdline, "acpi=3D= ") ) { - safe_strcat(dom0_cmdline, " acpi=3D"); - safe_strcat(dom0_cmdline, acpi_param); + strlcat(dom0_cmdline, " acpi=3D", MAX_GUEST_CMDLINE); + strlcat(dom0_cmdline, acpi_param, MAX_GUEST_CMDLINE); } =20 - cmdline =3D dom0_cmdline; + strlcpy(bd->kernel->string.bytes, dom0_cmdline, MAX_GUEST_CMDLINE); } =20 /* @@ -816,7 +831,7 @@ static struct domain *__init create_dom0(const struct b= oot_info *bi) write_cr4(read_cr4() & ~X86_CR4_SMAP); } =20 - if ( construct_dom0(d, image, initrd, cmdline) !=3D 0 ) + if ( construct_domain(bd) !=3D 0 ) panic("Could not construct domain 0\n"); =20 if ( cpu_has_smap ) @@ -825,14 +840,14 @@ static struct domain *__init create_dom0(const struct= boot_info *bi) cr4_pv32_mask |=3D X86_CR4_SMAP; } =20 - return d; + return bd->domain; } =20 void __init arch_create_dom( const struct boot_info *bi, struct boot_domain *bd) { if ( builder_is_initdom(bd) ) - create_dom0(bi); + create_dom0(bi, bd); } =20 /* How much of the directmap is prebuilt at compile time. */ @@ -1010,10 +1025,7 @@ void __init noreturn __start_xen(unsigned long bi_p) boot_info->nr_mods); } =20 - /* Dom0 kernel is the first boot module */ - boot_info->mods[0].kind =3D BOOTMOD_KERNEL; - if ( boot_info->mods[0].string.len ) - boot_info->mods[0].string.kind =3D BOOTSTR_CMDLINE; + builder_init(boot_info); =20 if ( pvh_boot ) { @@ -1168,11 +1180,6 @@ void __init noreturn __start_xen(unsigned long bi_p) boot_info->mods[boot_info->nr_mods].size =3D __2M_rwdata_end - _st= ext; } =20 - boot_info->mods[0].arch->headroom =3D bzimage_headroom( - bootstrap_map(&boot_info->mods[0]), - boot_info->mods[0].size); - bootstrap_map(NULL); - #ifndef highmem_start /* Don't allow split below 4Gb. */ if ( highmem_start < GB(4) ) @@ -1905,22 +1912,29 @@ void __init noreturn __start_xen(unsigned long bi_p) cpu_has_nx ? XENLOG_INFO : XENLOG_WARNING "Warning: ", cpu_has_nx ? "" : "not "); =20 - initrdidx =3D bootmodule_next_idx_by_kind(boot_info, BOOTMOD_UNKNOWN, = 0); - if ( initrdidx < boot_info->nr_mods ) - boot_info->mods[initrdidx].kind =3D BOOTMOD_RAMDISK; - - if ( bootmodule_count_by_kind(boot_info, BOOTMOD_UNKNOWN) > 1 ) - printk(XENLOG_WARNING - "Multiple initrd candidates, picking module #%u\n", - initrdidx); - /* - * 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. + * Boot description not provided, check to see if there are any remain= ing + * boot modules, the first one found will be provided as the ramdisk. */ - dom0 =3D create_dom0(boot_info); + if ( ! boot_info->builder->fdt_enabled ) + { + initrdidx =3D bootmodule_next_idx_by_kind(boot_info, BOOTMOD_UNKNO= WN, 0); + if ( initrdidx < boot_info->nr_mods ) + { + boot_info->builder->domains[0].ramdisk =3D &boot_info->mods[in= itrdidx]; + boot_info->mods[initrdidx].kind =3D BOOTMOD_RAMDISK; + } + if ( bootmodule_count_by_kind(boot_info, BOOTMOD_UNKNOWN) > 1 ) + printk(XENLOG_WARNING + "Multiple initrd candidates, picking module #%u\n", + initrdidx); + } + + builder_create_domains(boot_info); + + dom0 =3D builder_get_hwdom(boot_info); if ( !dom0 ) - panic("Could not set up DOM0 guest OS\n"); + panic("No hardware domain was built\n"); =20 heap_init_late(); =20 --=20 2.20.1 From nobody Mon May 20 18:31:35 2024 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=1657142352; cv=pass; d=zohomail.com; s=zohoarc; b=K3H5WL9R5a/2DghojxiCnUCWrS9f87Op+tGQtIbVQ7QCcig+w7Q+2POiJ8h60bVwsLgjfeWdv45TT/A8vYqwMW2r4UpBq2mia60k8b9lvmf0wFBgRMtJQGBqVnKB3nWXsFm1egLZKuy4VFF/u1s5C0dIzhUTeiP2HEdp14SQsK8= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657142352; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=5yZIw87G7JzBKuFzenXeWr5cm81sZ/kPE47Ov9/J3Yw=; b=CriTAwf/BavXQQZKNhGV+y/xJt7PXBhIkssaiVkjIKFzyUbcIsm0widERrGrDydoV0oEAlI7ecTBUNQ32SpYyRGUyi5xxJmmwrDQyLogXlrGgXcG/MoKZ2XtI33et3K8So2B1obo9y7ZLtkJ3AakPiuxQjSAwxU1vga9dXwM3+A= 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 1657142352874484.7514614323843; Wed, 6 Jul 2022 14:19:12 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.362613.592740 (Exim 4.92) (envelope-from ) id 1o9CQA-0006SI-L4; Wed, 06 Jul 2022 21:18:54 +0000 Received: by outflank-mailman (output) from mailman id 362613.592740; Wed, 06 Jul 2022 21:18:54 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1o9CQA-0006SB-HX; Wed, 06 Jul 2022 21:18:54 +0000 Received: by outflank-mailman (input) for mailman id 362613; Wed, 06 Jul 2022 21:18:53 +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 1o9CFv-0003HV-PX for xen-devel@lists.xenproject.org; Wed, 06 Jul 2022 21:08:20 +0000 Received: from sender4-of-o51.zoho.com (sender4-of-o51.zoho.com [136.143.188.51]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id c1896274-fd6f-11ec-924f-1f966e50362f; Wed, 06 Jul 2022 23:08:18 +0200 (CEST) Received: from sisyou.hme. (static-72-81-132-2.bltmmd.fios.verizon.net [72.81.132.2]) by mx.zohomail.com with SMTPS id 1657141521883800.3456952982841; Wed, 6 Jul 2022 14:05:21 -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: c1896274-fd6f-11ec-924f-1f966e50362f ARC-Seal: i=1; a=rsa-sha256; t=1657141523; cv=none; d=zohomail.com; s=zohoarc; b=bAdaahGy4J37SFBsKk5H8bc+Y1NpSUjAYPOdZs9WMqgWUmz/Zwvvrfzy5TTzr8DH/vQKwczjCFpIjtRXMcqYkGwHNYpYwt+WN8h5//jorw4xFY3eOXvmHEFZyYVTIyzbpCA3DoXgNMrx4Qui1HqXSp5WQrY3T7PZgkLJCFn17oo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657141523; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=5yZIw87G7JzBKuFzenXeWr5cm81sZ/kPE47Ov9/J3Yw=; b=VrsMbbhs0gZbthX97HQSVVe0xHZ3BGb5gaYIJGs6PRAj8r/ktQ9r4WyNOplBTDVjiChPHg4tMWOiVsSlw2jA2DM/IOMt1Pd1ZftGRgg7MfZsFvaRjepWBVrgDZy3OoY6EHLmk4y1ByEUEq8hTShEyWcDjntlW82YCItpAWVYcVk= 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=1657141523; 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=5yZIw87G7JzBKuFzenXeWr5cm81sZ/kPE47Ov9/J3Yw=; b=HcH8j7DdN//CuLxUG8WR8URHxc2t0ESQHkc/VOm3waVqk4MQwx5E/uRU6qfE/Z7v spXjlI0NNzYSAseOlfEFUr0W4Gu7VaHq/KjJglaRkpzeVTQ5y1MpnSSH5Or5pu8uapp R1Fz8xz23VqlfKM4K9aHk8so8nv4sLtp1f5I172g= From: "Daniel P. Smith" To: xen-devel@lists.xenproject.org, Wei Liu Cc: "Daniel P. Smith" , scott.davis@starlab.io, christopher.clark@starlab.io, Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH v1 12/18] x86: convert dom0 creation to domain builder Date: Wed, 6 Jul 2022 17:04:47 -0400 Message-Id: <20220706210454.30096-13-dpsmith@apertussolutions.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220706210454.30096-1-dpsmith@apertussolutions.com> References: <20220706210454.30096-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: 1657142353456100004 Content-Type: text/plain; charset="utf-8" This commit begins the transtion over to domain builder by coverting the dom0 creation logic into a generalized domain creation logic. Signed-off-by: Daniel P. Smith Reviewed-by: Christopher Clark --- xen/arch/x86/Makefile | 1 + xen/arch/x86/domain_builder.c | 128 +++++++++++++++++++++++++++++++ xen/arch/x86/include/asm/setup.h | 1 + xen/arch/x86/setup.c | 109 +++----------------------- 4 files changed, 141 insertions(+), 98 deletions(-) create mode 100644 xen/arch/x86/domain_builder.c diff --git a/xen/arch/x86/Makefile b/xen/arch/x86/Makefile index 177a2ff742..2d5d398551 100644 --- a/xen/arch/x86/Makefile +++ b/xen/arch/x86/Makefile @@ -27,6 +27,7 @@ obj-y +=3D desc.o obj-bin-y +=3D dmi_scan.init.o obj-y +=3D domain.o obj-bin-y +=3D dom0_build.init.o +obj-bin-y +=3D domain_builder.init.o obj-y +=3D domain_page.o obj-y +=3D e820.o obj-y +=3D emul-i8254.o diff --git a/xen/arch/x86/domain_builder.c b/xen/arch/x86/domain_builder.c new file mode 100644 index 0000000000..308e1a1c67 --- /dev/null +++ b/xen/arch/x86/domain_builder.c @@ -0,0 +1,128 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +extern unsigned long cr4_pv32_mask; + +static unsigned int __init dom_max_vcpus(struct boot_domain *bd) +{ + unsigned int limit; + + if ( builder_is_initdom(bd) ) + return dom0_max_vcpus(); + + limit =3D bd->mode & BUILD_MODE_PARAVIRTUALIZED ? + MAX_VIRT_CPUS : HVM_MAX_VCPUS; + + if ( bd->ncpus > limit ) + return limit; + else + return bd->ncpus; +} + +void __init arch_create_dom( + const struct boot_info *bi, struct boot_domain *bd) +{ + 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, + .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 bd->functions & BUILD_FUNCTION_INITIAL_DOM && + opt_dom0_msr_relaxed ? XEN_X86_MSR_RELAXED : 0, + }, + }; + unsigned int is_privileged =3D 0; + char *cmdline; + + if ( bd->kernel =3D=3D NULL ) + panic("Error creating d%uv0\n", bd->domid); + + /* mask out PV and device model bits, if 0 then the domain is PVH */ + if ( !(bd->mode & + (BUILD_MODE_PARAVIRTUALIZED|BUILD_MODE_ENABLE_DEVICE_MODEL)) ) + { + dom_cfg.flags |=3D (XEN_DOMCTL_CDF_hvm | + (hvm_hap_supported() ? XEN_DOMCTL_CDF_hap : 0)); + + /* + * If shadow paging is enabled for the initial domain, mask out + * HAP if it was just enabled. + */ + if ( builder_is_initdom(bd) ) + if ( opt_dom0_shadow ) + dom_cfg.flags |=3D ~XEN_DOMCTL_CDF_hap; + + /* TODO: review which flags should be present */ + dom_cfg.arch.emulation_flags |=3D + XEN_X86_EMU_LAPIC | XEN_X86_EMU_IOAPIC | XEN_X86_EMU_VPCI; + } + + if ( iommu_enabled && builder_is_hwdom(bd) ) + dom_cfg.flags |=3D XEN_DOMCTL_CDF_iommu; + + if ( !pv_shim && builder_is_ctldom(bd) ) + is_privileged =3D CDF_privileged; + + /* Create initial domain. Not d0 for pvshim. */ + bd->domid =3D get_initial_domain_id(); + bd->domain =3D domain_create(bd->domid, &dom_cfg, is_privileged); + if ( IS_ERR(bd->domain) ) + panic("Error creating d%u: %ld\n", bd->domid, PTR_ERR(bd->domain)); + + init_dom0_cpuid_policy(bd->domain); + + if ( alloc_dom0_vcpu0(bd->domain) =3D=3D NULL ) + panic("Error creating d%uv0\n", bd->domid); + + /* Grab the DOM0 command line. */ + cmdline =3D (bd->kernel->string.kind =3D=3D BOOTSTR_CMDLINE) ? + bd->kernel->string.bytes : NULL; + if ( cmdline || bi->arch->kextra ) + { + char dom_cmdline[MAX_GUEST_CMDLINE]; + + cmdline =3D arch_prepare_cmdline(cmdline, bi->arch); + strlcpy(dom_cmdline, cmdline, MAX_GUEST_CMDLINE); + + if ( bi->arch->kextra ) + /* kextra always includes exactly one leading space. */ + strlcat(dom_cmdline, bi->arch->kextra, MAX_GUEST_CMDLINE); + + apply_xen_cmdline(dom_cmdline); + + strlcpy(bd->kernel->string.bytes, dom_cmdline, MAX_GUEST_CMDLINE); + } + + /* + * Temporarily clear SMAP in CR4 to allow user-accesses in construct_d= om0(). + * This saves a large number of corner cases interactions with + * copy_from_user(). + */ + if ( cpu_has_smap ) + { + cr4_pv32_mask &=3D ~X86_CR4_SMAP; + write_cr4(read_cr4() & ~X86_CR4_SMAP); + } + + if ( construct_domain(bd) !=3D 0 ) + panic("Could not construct domain 0\n"); + + if ( cpu_has_smap ) + { + write_cr4(read_cr4() | X86_CR4_SMAP); + cr4_pv32_mask |=3D X86_CR4_SMAP; + } +} + diff --git a/xen/arch/x86/include/asm/setup.h b/xen/arch/x86/include/asm/se= tup.h index f9c1468fcc..6f53623fb3 100644 --- a/xen/arch/x86/include/asm/setup.h +++ b/xen/arch/x86/include/asm/setup.h @@ -33,6 +33,7 @@ void vesa_init(void); static inline void vesa_init(void) {}; #endif =20 +void apply_xen_cmdline(char *cmdline); int construct_domain(struct boot_domain *bd); =20 void setup_io_bitmap(struct domain *d); diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 860b9e3d64..479b9fa149 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -745,109 +746,21 @@ static unsigned int __init copy_bios_e820(struct e82= 0entry *map, unsigned int li return n; } =20 -static struct domain *__init create_dom0( - const struct boot_info *bi, struct boot_domain *bd) +void __init apply_xen_cmdline(char *cmdline) { - 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(), - .arch =3D { - .misc_flags =3D opt_dom0_msr_relaxed ? XEN_X86_MSR_RELAXED : 0, - }, - }; - char *cmdline; - - if ( bd->kernel =3D=3D NULL ) - panic("Error creating d%uv0\n", bd->domid); - - if ( opt_dom0_pvh ) - { - 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 ( iommu_enabled ) - dom0_cfg.flags |=3D XEN_DOMCTL_CDF_iommu; - - /* Create initial domain. Not d0 for pvshim. */ - bd->domid =3D get_initial_domain_id(); - bd->domain =3D domain_create(bd->domid, &dom0_cfg, pv_shim ? - 0 : CDF_privileged); - if ( IS_ERR(bd->domain) ) - panic("Error creating d%u: %ld\n", bd->domid, PTR_ERR(bd->domain)); - - init_dom0_cpuid_policy(bd->domain); - - if ( alloc_dom0_vcpu0(bd->domain) =3D=3D NULL ) - panic("Error creating d%uv0\n", bd->domid); - - /* Grab the DOM0 command line. */ - cmdline =3D (bd->kernel->string.kind =3D=3D BOOTSTR_CMDLINE) ? - bd->kernel->string.bytes : NULL; - if ( cmdline || bi->arch->kextra ) - { - char dom0_cmdline[MAX_GUEST_CMDLINE]; - - cmdline =3D arch_prepare_cmdline(cmdline, bi->arch); - strlcpy(dom0_cmdline, cmdline, MAX_GUEST_CMDLINE); - - if ( bi->arch->kextra ) - /* kextra always includes exactly one leading space. */ - strlcat(dom0_cmdline, bi->arch->kextra, MAX_GUEST_CMDLINE); - - /* Append any extra parameters. */ - if ( skip_ioapic_setup && !strstr(dom0_cmdline, "noapic") ) - strlcat(dom0_cmdline, " noapic", MAX_GUEST_CMDLINE); - if ( (strlen(acpi_param) =3D=3D 0) && acpi_disabled ) - { - printk("ACPI is disabled, notifying Domain 0 (acpi=3Doff)\n"); - strlcpy(acpi_param, "off", sizeof(acpi_param)); - } - if ( (strlen(acpi_param) !=3D 0) && !strstr(dom0_cmdline, "acpi=3D= ") ) - { - strlcat(dom0_cmdline, " acpi=3D", MAX_GUEST_CMDLINE); - strlcat(dom0_cmdline, acpi_param, MAX_GUEST_CMDLINE); - } - - strlcpy(bd->kernel->string.bytes, dom0_cmdline, MAX_GUEST_CMDLINE); - } - - /* - * Temporarily clear SMAP in CR4 to allow user-accesses in construct_d= om0(). - * This saves a large number of corner cases interactions with - * copy_from_user(). - */ - if ( cpu_has_smap ) + if ( skip_ioapic_setup && !strstr(cmdline, "noapic") ) + strlcat(cmdline, " noapic", MAX_GUEST_CMDLINE); + if ( (strlen(acpi_param) =3D=3D 0) && acpi_disabled ) { - cr4_pv32_mask &=3D ~X86_CR4_SMAP; - write_cr4(read_cr4() & ~X86_CR4_SMAP); + printk("ACPI is disabled, notifying Domain 0 (acpi=3Doff)\n"); + strlcpy(acpi_param, "off", sizeof(acpi_param)); } - - if ( construct_domain(bd) !=3D 0 ) - panic("Could not construct domain 0\n"); - - if ( cpu_has_smap ) + if ( (strlen(acpi_param) !=3D 0) && + !strstr(cmdline, "acpi=3D") ) { - write_cr4(read_cr4() | X86_CR4_SMAP); - cr4_pv32_mask |=3D X86_CR4_SMAP; + strlcat(cmdline, " acpi=3D", MAX_GUEST_CMDLINE); + strlcat(cmdline, acpi_param, MAX_GUEST_CMDLINE); } - - return bd->domain; -} - -void __init arch_create_dom( - const struct boot_info *bi, struct boot_domain *bd) -{ - if ( builder_is_initdom(bd) ) - create_dom0(bi, bd); } =20 /* How much of the directmap is prebuilt at compile time. */ --=20 2.20.1 From nobody Mon May 20 18:31:35 2024 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=1657142352; cv=pass; d=zohomail.com; s=zohoarc; b=XBIFkSbDobEcHiee1pMyiRRxV1lmKtwswNrjFvx9VVPePuIVX8XGrQa0kDdghPmcU4V6IKxam7UCOZtEd8yoZit19ZJTKUp3P4OgfX+k4J8LftmD3d95DoDrqiyfisIAfxUNrXUmkrT3cCf1gxLkTv+i4f0rEMi39+AyDQnRASM= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657142352; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=WXmYD77YrhMc0tVJJp6RofHh/xQBmFJZqWBf4zSdvRM=; b=F1nwYs3ssI/Y5UVAE/oNNux8H5mU1iQiNQb15yAXuDhzufyg5AcLiQQRHxFEmSK7QiNPIZpCmdPfLQBS646hoAay1v0Em4SJQZaCHyllJomQ4Tq5UpQSjni2nCQSa+zEugu4tL2i488MquEyU+BSr8dT61XS2phXtNDk7ig4MEQ= 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 1657142352230480.57663539671523; Wed, 6 Jul 2022 14:19:12 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.362615.592743 (Exim 4.92) (envelope-from ) id 1o9CQA-0006Vx-Ub; Wed, 06 Jul 2022 21:18:54 +0000 Received: by outflank-mailman (output) from mailman id 362615.592743; Wed, 06 Jul 2022 21:18:54 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1o9CQA-0006V2-Qe; Wed, 06 Jul 2022 21:18:54 +0000 Received: by outflank-mailman (input) for mailman id 362615; Wed, 06 Jul 2022 21:18:53 +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 1o9CG5-0003HV-CG for xen-devel@lists.xenproject.org; Wed, 06 Jul 2022 21:08:29 +0000 Received: from sender4-of-o51.zoho.com (sender4-of-o51.zoho.com [136.143.188.51]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id c751cda8-fd6f-11ec-924f-1f966e50362f; Wed, 06 Jul 2022 23:08:28 +0200 (CEST) Received: from sisyou.hme. (static-72-81-132-2.bltmmd.fios.verizon.net [72.81.132.2]) by mx.zohomail.com with SMTPS id 1657141523099239.14805637871416; Wed, 6 Jul 2022 14:05: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: c751cda8-fd6f-11ec-924f-1f966e50362f ARC-Seal: i=1; a=rsa-sha256; t=1657141524; cv=none; d=zohomail.com; s=zohoarc; b=gprjnvHTCj66K/3zl3xhHAr3DXoKXA6PrEBBEZ49G2TOXH1XZxa2Tc6C4UMBoeW1Q66kFf5ub/ut0lmqwSR72NeUBuAUhkeolKv5LIrTrDFI3oESHd5BoMyuE2YvGp7hmGhkzNWOtQd9Rr7bsH6IPNn83jyeMqr9oFaRzLtPkbU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657141524; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=WXmYD77YrhMc0tVJJp6RofHh/xQBmFJZqWBf4zSdvRM=; b=kF1fopmFVLXRCb0oG8SdiEpHINmWL3fgc14URNgau+LHLybQa2KwwHlKEYMswFj1y56cIvoxOWT6RjNQAYj88LnO9r6xCPsE/Pvpb1gPIgMNz6j7cBlyxJhffRGOz+0d3ENmlR/WQxFdcSDdaZWyib4iUO0eeat9cisxCKBPqMc= 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=1657141524; 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=WXmYD77YrhMc0tVJJp6RofHh/xQBmFJZqWBf4zSdvRM=; b=Pg4ZizoMIlxabe1CMIbyfMFO6yj6riZclXmO0O+HIaYdhWnOclu+DFPmxWcQaOuu u/R8ZTkPzgzFInWByC30mkDUEkoNBhXW0XqwohkreQPmMn68OmN0cgZt0tKXlYizng7 tEZ+BwCtVrprC7E5i4D075yzfVnJwnAxA8FqThMo= From: "Daniel P. Smith" To: xen-devel@lists.xenproject.org, Wei Liu Cc: "Daniel P. Smith" , scott.davis@starlab.io, christopher.clark@starlab.io, Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH v1 13/18] x86: generalize physmap logic Date: Wed, 6 Jul 2022 17:04:48 -0400 Message-Id: <20220706210454.30096-14-dpsmith@apertussolutions.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220706210454.30096-1-dpsmith@apertussolutions.com> References: <20220706210454.30096-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: 1657142353433100003 Content-Type: text/plain; charset="utf-8" The existing physmap code is specific to dom0. In this commit, the dom0 phy= smap code is generalized for any domain and functions are renamed to reflect the= ir new general nature. Signed-off-by: Daniel P. Smith Reviewed-by: Christopher Clark --- xen/arch/x86/include/asm/dom0_build.h | 2 +- xen/arch/x86/pv/dom0_build.c | 10 +++++----- xen/arch/x86/pv/shim.c | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/xen/arch/x86/include/asm/dom0_build.h b/xen/arch/x86/include/a= sm/dom0_build.h index 571b25ea71..f30e4b860a 100644 --- a/xen/arch/x86/include/asm/dom0_build.h +++ b/xen/arch/x86/include/asm/dom0_build.h @@ -21,7 +21,7 @@ int dom0_construct_pvh(struct boot_domain *bd); unsigned long dom0_paging_pages(const struct domain *d, unsigned long nr_pages); =20 -void dom0_update_physmap(bool compat, unsigned long pfn, +void dom_update_physmap(bool compat, unsigned long pfn, unsigned long mfn, unsigned long vphysmap_s); =20 #endif /* _DOM0_BUILD_H_ */ diff --git a/xen/arch/x86/pv/dom0_build.c b/xen/arch/x86/pv/dom0_build.c index 78ebb03b1b..f1ea0575f0 100644 --- a/xen/arch/x86/pv/dom0_build.c +++ b/xen/arch/x86/pv/dom0_build.c @@ -34,8 +34,8 @@ #define L3_PROT (BASE_PROT|_PAGE_DIRTY) #define L4_PROT (BASE_PROT|_PAGE_DIRTY) =20 -void __init dom0_update_physmap(bool compat, unsigned long pfn, - unsigned long mfn, unsigned long vphysmap_= s) +void __init dom_update_physmap( + bool compat, unsigned long pfn, unsigned long mfn, unsigned long vphys= map_s) { if ( !compat ) ((unsigned long *)vphysmap_s)[pfn] =3D mfn; @@ -815,7 +815,7 @@ int __init dom0_construct_pv(struct boot_domain *bd) if ( pfn > REVERSE_START && (vinitrd_start || pfn < initrd_pfn) ) mfn =3D alloc_epfn - (pfn - REVERSE_START); #endif - dom0_update_physmap(compat, pfn, mfn, vphysmap_start); + dom_update_physmap(compat, pfn, mfn, vphysmap_start); if ( !(pfn & 0xfffff) ) process_pending_softirqs(); } @@ -831,7 +831,7 @@ int __init dom0_construct_pv(struct boot_domain *bd) !get_page_and_type(page, d, PGT_writable_page) ) BUG(); =20 - dom0_update_physmap(compat, pfn, mfn, vphysmap_start); + dom_update_physmap(compat, pfn, mfn, vphysmap_start); ++pfn; if ( !(pfn & 0xfffff) ) process_pending_softirqs(); @@ -851,7 +851,7 @@ int __init dom0_construct_pv(struct boot_domain *bd) #ifndef NDEBUG #define pfn (nr_pages - 1 - (pfn - (alloc_epfn - alloc_spfn))) #endif - dom0_update_physmap(compat, pfn, mfn, vphysmap_start); + dom_update_physmap(compat, pfn, mfn, vphysmap_start); #undef pfn page++; pfn++; if ( !(pfn & 0xfffff) ) diff --git a/xen/arch/x86/pv/shim.c b/xen/arch/x86/pv/shim.c index 2ee290a392..fb2a7ef393 100644 --- a/xen/arch/x86/pv/shim.c +++ b/xen/arch/x86/pv/shim.c @@ -210,7 +210,7 @@ void __init pv_shim_setup_dom(struct domain *d, l4_pgen= try_t *l4start, { = \ share_xen_page_with_guest(mfn_to_page(_mfn(param)), d, SHARE_rw); = \ replace_va_mapping(d, l4start, va, _mfn(param)); = \ - dom0_update_physmap(compat, = \ + dom_update_physmap(compat, = \ PFN_DOWN((va) - va_start), param, vphysmap); = \ } = \ else = \ @@ -238,7 +238,7 @@ void __init pv_shim_setup_dom(struct domain *d, l4_pgen= try_t *l4start, si->console.domU.mfn =3D mfn_x(console_mfn); share_xen_page_with_guest(mfn_to_page(console_mfn), d, SHARE_rw); replace_va_mapping(d, l4start, console_va, console_mfn); - dom0_update_physmap(compat, (console_va - va_start) >> PAGE_SHIFT, + dom_update_physmap(compat, (console_va - va_start) >> PAGE_SHIFT, mfn_x(console_mfn), vphysmap); consoled_set_ring_addr(page); } --=20 2.20.1 From nobody Mon May 20 18:31:35 2024 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=1657142330; cv=pass; d=zohomail.com; s=zohoarc; b=dDhXA9PAYlStaU0vqN5KtaX3g4K1IMJ+eYzdSf+nUaG25G9SgL4oH53J2Rgwi1s5CkPVY9nQuGNlnmRUPj7+9cz/KPt/NB4D7tq8vq4Qp/ff9yBM4JRpSWaDnZ/5i3gQu30sGO+Ge8033zugjcVak66gvWg/XjUAgbej1VlNqMY= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657142330; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=xIVNnCOl//0NwdRtYGKxNcLBDp2Qsryi1rBCkz4SStc=; b=FCbCNwjKM+JbhNV1E2rltJ2he3f8rMjW8G1Bu8txGYJWbfytB3IiiKUvV16QNWk7rHP+j/HMipmD/3ZrDKoQsAjpm0dvuulEfbMWIBPovd67wVIGyTMtQjXJ1JuayMD2xaSV98q7chKacYoTOGKoOuyAEybWRrYGgLBBYlRAZNo= 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 1657142330224233.09823707108956; Wed, 6 Jul 2022 14:18:50 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.362590.592718 (Exim 4.92) (envelope-from ) id 1o9CPn-0004yj-Tk; Wed, 06 Jul 2022 21:18:31 +0000 Received: by outflank-mailman (output) from mailman id 362590.592718; Wed, 06 Jul 2022 21:18:31 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1o9CPn-0004yW-PM; Wed, 06 Jul 2022 21:18:31 +0000 Received: by outflank-mailman (input) for mailman id 362590; Wed, 06 Jul 2022 21:18:29 +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 1o9CGG-0003HV-Co for xen-devel@lists.xenproject.org; Wed, 06 Jul 2022 21:08:40 +0000 Received: from sender4-of-o51.zoho.com (sender4-of-o51.zoho.com [136.143.188.51]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id cd49b360-fd6f-11ec-924f-1f966e50362f; Wed, 06 Jul 2022 23:08:38 +0200 (CEST) Received: from sisyou.hme. (static-72-81-132-2.bltmmd.fios.verizon.net [72.81.132.2]) by mx.zohomail.com with SMTPS id 1657141524647778.2526648624945; Wed, 6 Jul 2022 14:05: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: cd49b360-fd6f-11ec-924f-1f966e50362f ARC-Seal: i=1; a=rsa-sha256; t=1657141526; cv=none; d=zohomail.com; s=zohoarc; b=ivE0OgVasNv4eQ+byR5QWn20FbxaTUDbvjSFp7QK60cmoGErPzReroOliZ9dJcNo86nEzImdvkYHcLeQ0EE0i1mSC+sV3+welJ69edQhlqkuWydJEsg5xLd3xUZQIgk14bAKHFrXRu+zAnbD8+IGLihswPX/kGwE3g4q0tIt6yI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657141526; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=xIVNnCOl//0NwdRtYGKxNcLBDp2Qsryi1rBCkz4SStc=; b=NA5wwh6pTJaDIIYy6/E83Uv31PZFM7t/rjQcadECB5i4Fq1axnrHw49ObNlvXOPSxIFb3mOhgOR8VQWjEuhO1pPtuNdnTfYlCL0zqceDXJ9lPYIKIzzQNIH4Q1yxwnEZk++DsYLNu1/s0ySsi2lrBRh4kDRgoQS46Phh23O9HRY= 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=1657141526; 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=xIVNnCOl//0NwdRtYGKxNcLBDp2Qsryi1rBCkz4SStc=; b=AY9KKnkB06vn++m9x/9zLYHd04WXgZAGqZVmnQ120S7oQnhomKvMFWSSjhgdbGpM 4/+eyN9pEsyGzggIhX87IaIalNJlNIcUsdiQxA9WX8zTZgxlJnoXL+xBgh1maiQTWsi KvkpJF7h01BHXVVCBlJcogr1xHvhR1pzIRRtXrnA= From: "Daniel P. Smith" To: xen-devel@lists.xenproject.org, Wei Liu Cc: "Daniel P. Smith" , scott.davis@starlab.io, christopher.clark@starlab.io, Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , George Dunlap , Julien Grall , Stefano Stabellini , Dario Faggioli Subject: [PATCH v1 14/18] x86: generalize vcpu for domain building Date: Wed, 6 Jul 2022 17:04:49 -0400 Message-Id: <20220706210454.30096-15-dpsmith@apertussolutions.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220706210454.30096-1-dpsmith@apertussolutions.com> References: <20220706210454.30096-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: 1657142331287100003 Content-Type: text/plain; charset="utf-8" Here, the vcpu initialization code for dom0 creation is generalized for use= for other domains. Signed-off-by: Daniel P. Smith Reviewed-by: Christopher Clark --- xen/arch/x86/domain_builder.c | 14 +++++++++++++- xen/arch/x86/hvm/dom0_build.c | 7 ++++--- xen/arch/x86/pv/dom0_build.c | 2 +- xen/common/sched/core.c | 25 ++++++++++++++++--------- xen/include/xen/sched.h | 3 ++- 5 files changed, 36 insertions(+), 15 deletions(-) diff --git a/xen/arch/x86/domain_builder.c b/xen/arch/x86/domain_builder.c index 308e1a1c67..1a4a6b1ca7 100644 --- a/xen/arch/x86/domain_builder.c +++ b/xen/arch/x86/domain_builder.c @@ -28,6 +28,18 @@ static unsigned int __init dom_max_vcpus(struct boot_dom= ain *bd) return bd->ncpus; } =20 +struct vcpu *__init alloc_dom_vcpu0(struct boot_domain *bd) +{ + if ( bd->functions & BUILD_FUNCTION_INITIAL_DOM ) + return alloc_dom0_vcpu0(bd->domain); + + bd->domain->node_affinity =3D node_online_map; + bd->domain->auto_node_affinity =3D true; + + return vcpu_create(bd->domain, 0); +} + + void __init arch_create_dom( const struct boot_info *bi, struct boot_domain *bd) { @@ -83,7 +95,7 @@ void __init arch_create_dom( =20 init_dom0_cpuid_policy(bd->domain); =20 - if ( alloc_dom0_vcpu0(bd->domain) =3D=3D NULL ) + if ( alloc_dom_vcpu0(bd) =3D=3D NULL ) panic("Error creating d%uv0\n", bd->domid); =20 /* Grab the DOM0 command line. */ diff --git a/xen/arch/x86/hvm/dom0_build.c b/xen/arch/x86/hvm/dom0_build.c index 2fee2ed926..ae3ffc614d 100644 --- a/xen/arch/x86/hvm/dom0_build.c +++ b/xen/arch/x86/hvm/dom0_build.c @@ -696,9 +696,10 @@ static int __init pvh_load_kernel( return 0; } =20 -static int __init pvh_setup_cpus(struct domain *d, paddr_t entry, +static int __init pvh_setup_cpus(struct boot_domain *bd, paddr_t entry, paddr_t start_info) { + struct domain *d =3D bd->domain; struct vcpu *v =3D d->vcpu[0]; int rc; /* @@ -722,7 +723,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); + sched_setup_dom_vcpus(bd); =20 rc =3D arch_set_info_hvm_guest(v, &cpu_ctx); if ( rc ) @@ -1257,7 +1258,7 @@ int __init dom0_construct_pvh(struct boot_domain *bd) return rc; } =20 - rc =3D pvh_setup_cpus(d, entry, start_info); + rc =3D pvh_setup_cpus(bd, entry, start_info); if ( rc ) { printk("Failed to setup Dom0 CPUs: %d\n", rc); diff --git a/xen/arch/x86/pv/dom0_build.c b/xen/arch/x86/pv/dom0_build.c index f1ea0575f0..9d1c9fb8b0 100644 --- a/xen/arch/x86/pv/dom0_build.c +++ b/xen/arch/x86/pv/dom0_build.c @@ -729,7 +729,7 @@ int __init dom0_construct_pv(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); + sched_setup_dom_vcpus(bd); =20 d->arch.paging.mode =3D 0; =20 diff --git a/xen/common/sched/core.c b/xen/common/sched/core.c index 250207038e..029f5ea24e 100644 --- a/xen/common/sched/core.c +++ b/xen/common/sched/core.c @@ -14,6 +14,8 @@ */ =20 #ifndef COMPAT +#include +#include #include #include #include @@ -3399,13 +3401,13 @@ void wait(void) } =20 #ifdef CONFIG_X86 -void __init sched_setup_dom0_vcpus(struct domain *d) +void __init sched_setup_dom_vcpus(struct boot_domain *bd) { unsigned int i; struct sched_unit *unit; =20 - for ( i =3D 1; i < d->max_vcpus; i++ ) - vcpu_create(d, i); + for ( i =3D 1; i < bd->domain->max_vcpus; i++ ) + vcpu_create(bd->domain, i); =20 /* * PV-shim: vcpus are pinned 1:1. @@ -3413,19 +3415,24 @@ void __init sched_setup_dom0_vcpus(struct domain *d) * onlining them. This avoids pinning a vcpu to a not yet online cpu h= ere. */ if ( pv_shim ) - sched_set_affinity(d->vcpu[0]->sched_unit, + sched_set_affinity(bd->domain->vcpu[0]->sched_unit, cpumask_of(0), cpumask_of(0)); else { - for_each_sched_unit ( d, unit ) + for_each_sched_unit ( bd->domain, unit ) { - if ( !opt_dom0_vcpus_pin && !dom0_affinity_relaxed ) - sched_set_affinity(unit, &dom0_cpus, NULL); - sched_set_affinity(unit, NULL, &dom0_cpus); + if ( builder_is_initdom(bd) ) + { + if ( !opt_dom0_vcpus_pin && !dom0_affinity_relaxed ) + sched_set_affinity(unit, &dom0_cpus, NULL); + sched_set_affinity(unit, NULL, &dom0_cpus); + } + else + sched_set_affinity(unit, NULL, cpupool_valid_cpus(cpupool0= )); } } =20 - domain_update_node_affinity(d); + domain_update_node_affinity(bd->domain); } #endif =20 diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index b9515eb497..6ab7d69cbd 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -2,6 +2,7 @@ #ifndef __SCHED_H__ #define __SCHED_H__ =20 +#include #include #include #include @@ -1003,7 +1004,7 @@ 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); +void sched_setup_dom_vcpus(struct boot_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); void restore_vcpu_affinity(struct domain *d); --=20 2.20.1 From nobody Mon May 20 18:31:35 2024 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=1657141752; cv=pass; d=zohomail.com; s=zohoarc; b=eYIz+AI7fTXPFU9vLqQk4UUXmkquKJfYP3NCkcJ/4Ms9joguWxZINxw+DLBH/xgQGDOA8B75h1ZRJvV0Ms3Kk76974WChBm+MqjH81G6LUUF0oVV920Z2P2r5ZL1Idpy/cWPiwsPzrFlgwoQnqjiOu/YoFhN946RtIBhqDUgbp0= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657141752; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=S145Tne13TWHR+Kbw2vROFs6IyEj+oY3nk3bfwwUXUQ=; b=Lg9xBGAJxoqqUNtEnnj1tnd4Fp2eduQQkoFysRs/Of8YVD8HLZXxs1v7hsDDX+d0Wgw9c6hF6LlKDnAeNO/JNqqUSk671Ib8eabwZ3NGVZvjSC3HKswYCu2MRgm3JX3wJ9Yq4tCGPFCv4aa95FaNsKx0o83QBLx3oF+IYsnocPY= 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 1657141752202492.3709151707528; Wed, 6 Jul 2022 14:09:12 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.362561.592685 (Exim 4.92) (envelope-from ) id 1o9CGT-0001kc-1k; Wed, 06 Jul 2022 21:08:53 +0000 Received: by outflank-mailman (output) from mailman id 362561.592685; Wed, 06 Jul 2022 21:08:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1o9CGS-0001kP-TC; Wed, 06 Jul 2022 21:08:52 +0000 Received: by outflank-mailman (input) for mailman id 362561; Wed, 06 Jul 2022 21:08:51 +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 1o9CGR-0007yd-FG for xen-devel@lists.xenproject.org; Wed, 06 Jul 2022 21:08:51 +0000 Received: from sender4-of-o51.zoho.com (sender4-of-o51.zoho.com [136.143.188.51]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id d449487b-fd6f-11ec-bd2d-47488cf2e6aa; Wed, 06 Jul 2022 23:08:50 +0200 (CEST) Received: from sisyou.hme. (static-72-81-132-2.bltmmd.fios.verizon.net [72.81.132.2]) by mx.zohomail.com with SMTPS id 1657141525983954.9774962986977; Wed, 6 Jul 2022 14:05: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: d449487b-fd6f-11ec-bd2d-47488cf2e6aa ARC-Seal: i=1; a=rsa-sha256; t=1657141527; cv=none; d=zohomail.com; s=zohoarc; b=jeWDZKBFeS35Z9RwtifusSZdaz0wVhsCakQYdv1hC4oUrttUSv33m2Y7yH0bD2P6QVUjqMXCmcOgTkxjv5x9t0fKUE97ORr9n01rm6rWasw+RXYc3BaSlKHRE+4fNWyKC7g7NkGv8UEwUdnws6FhBq+7V7W+aXRFvHwIm/+AZu4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657141527; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=S145Tne13TWHR+Kbw2vROFs6IyEj+oY3nk3bfwwUXUQ=; b=RoIBD+Zdh1XKu5+7HD8tGQnZfQopwwZc5FMABbKmX6p+j6GILN4HjaOtPwRGGFDSEesWd1WYT5MTYzalRFM1UVOnz3Cp/Z9LywO30LOU0ZHKzWgts0LwBkT5CKKp6RuRh6uG6BYXkd/01XPijhDq414neIFdFbFmSaEeEicwLTc= 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=1657141527; 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=S145Tne13TWHR+Kbw2vROFs6IyEj+oY3nk3bfwwUXUQ=; b=nWNxOPu9Um2DRf6axihFZiQAw/zxtqclsbSsukXxsvcWKO+i4ULxpEmdDK3sOIBO USrlVMoZSQbi6KtDGQedZxaT8w9mO8edn3A+OL2ULR0MAOoay6/CdSjzLSbOo8KXjEN ltSed0UtH5hymmAU40fuCOoTw7exZvZ5o+97Rj6o= From: "Daniel P. Smith" To: xen-devel@lists.xenproject.org, Wei Liu Cc: "Daniel P. Smith" , scott.davis@starlab.io, christopher.clark@starlab.io, Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH v1 15/18] x86: rework domain page allocation Date: Wed, 6 Jul 2022 17:04:50 -0400 Message-Id: <20220706210454.30096-16-dpsmith@apertussolutions.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220706210454.30096-1-dpsmith@apertussolutions.com> References: <20220706210454.30096-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: 1657141754606100001 Content-Type: text/plain; charset="utf-8" This reworks all the dom0 page allocation functions for general domain construction. Where possible, common logic between the two was split into a separate function for reuse by the two functions. Signed-off-by: Daniel P. Smith Reviewed-by: Christopher Clark --- xen/arch/x86/dom0_build.c | 76 ++++++------------- xen/arch/x86/domain_builder.c | 102 ++++++++++++++++++++++++++ xen/arch/x86/hvm/dom0_build.c | 11 +-- xen/arch/x86/include/asm/dom0_build.h | 14 +++- xen/arch/x86/pv/dom0_build.c | 2 +- 5 files changed, 142 insertions(+), 63 deletions(-) diff --git a/xen/arch/x86/dom0_build.c b/xen/arch/x86/dom0_build.c index 216c9e3590..0600773b8f 100644 --- a/xen/arch/x86/dom0_build.c +++ b/xen/arch/x86/dom0_build.c @@ -320,69 +320,31 @@ static unsigned long __init default_nr_pages(unsigned= long avail) } =20 unsigned long __init dom0_compute_nr_pages( - struct domain *d, struct elf_dom_parms *parms, unsigned long initrd_le= n) + struct boot_domain *bd, struct elf_dom_parms *parms, + unsigned long initrd_len) { - nodeid_t node; - unsigned long avail =3D 0, nr_pages, min_pages, max_pages, iommu_pages= =3D 0; + unsigned long avail, nr_pages, min_pages, max_pages; =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 - for_each_node_mask ( node, dom0_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_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; - } + avail =3D dom_avail_nr_pages(bd, dom0_nodes); =20 - if ( paging_mode_enabled(d) || opt_dom0_shadow || opt_pv_l1tf_hwdom ) + /* command line overrides configuration */ + if ( dom0_mem_set ) { - unsigned long cpu_pages; - - 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); - - cpu_pages =3D dom0_paging_pages(d, nr_pages); - - if ( !iommu_use_hap_pt(d) ) - avail -=3D cpu_pages; - else if ( cpu_pages > iommu_pages ) - avail -=3D cpu_pages - iommu_pages; + bd->meminfo.mem_size =3D dom0_size; + bd->meminfo.mem_min =3D dom0_min_size; + bd->meminfo.mem_max =3D dom0_max_size; } =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); + nr_pages =3D get_memsize(&bd->meminfo.mem_size, avail) ? + : default_nr_pages(avail); + min_pages =3D get_memsize(&bd->meminfo.mem_min, avail); + max_pages =3D get_memsize(&bd->meminfo.mem_max, avail); =20 - if ( is_pv_domain(d) && + if ( is_pv_domain(bd->domain) && (parms->p2m_base =3D=3D UNSET_ADDR) && !memsize_gt_zero(&dom0_siz= e) && (!memsize_gt_zero(&dom0_min_size) || (nr_pages > min_pages)) ) { @@ -395,7 +357,8 @@ unsigned long __init dom0_compute_nr_pages( * 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); + size_t sizeof_long =3D is_pv_32bit_domain(bd->domain) ? + sizeof(int) : sizeof(long); =20 vstart =3D parms->virt_base; vend =3D round_pgup(parms->virt_kend); @@ -416,7 +379,12 @@ unsigned long __init dom0_compute_nr_pages( } } =20 - d->max_pages =3D min_t(unsigned long, max_pages, UINT_MAX); + /* 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); + + bd->domain->max_pages =3D min_t(unsigned long, max_pages, UINT_MAX); =20 return nr_pages; } diff --git a/xen/arch/x86/domain_builder.c b/xen/arch/x86/domain_builder.c index 1a4a6b1ca7..d8babb1090 100644 --- a/xen/arch/x86/domain_builder.c +++ b/xen/arch/x86/domain_builder.c @@ -8,7 +8,9 @@ #include =20 #include +#include #include +#include =20 extern unsigned long cr4_pv32_mask; =20 @@ -40,6 +42,106 @@ struct vcpu *__init alloc_dom_vcpu0(struct boot_domain = *bd) } =20 =20 +unsigned long __init dom_avail_nr_pages( + struct boot_domain *bd, nodemask_t nodes) +{ + unsigned long avail =3D 0, iommu_pages =3D 0; + bool is_ctldom =3D false, is_hwdom =3D false; + unsigned long nr_pages =3D bd->meminfo.mem_size.nr_pages; + nodeid_t node; + + if ( builder_is_ctldom(bd) ) + is_ctldom =3D true; + if ( builder_is_hwdom(bd) ) + is_hwdom =3D true; + + 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 (bd->domain->max_vcpus - 1UL) + << get_order_from_bytes(sizeof(struct vcpu)); + /* ...and compat_l4's, if needed. */ + if ( is_pv_32bit_domain(bd->domain) ) + avail -=3D bd->domain->max_vcpus - 1; + + /* Reserve memory for iommu_dom0_init() (rough estimate). */ + if ( is_hwdom && is_iommu_enabled(bd->domain) && !iommu_hwdom_passthro= ugh ) + { + 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(bd->domain) || + (is_ctldom && opt_dom0_shadow) || + (is_hwdom && opt_pv_l1tf_hwdom) ) + { + unsigned long cpu_pages =3D dom0_paging_pages(bd->domain, nr_pages= ); + + if ( !iommu_use_hap_pt(bd->domain) ) + avail -=3D cpu_pages; + else if ( cpu_pages > iommu_pages ) + avail -=3D cpu_pages - iommu_pages; + } + + return avail; +} + +unsigned long __init dom_compute_nr_pages( + struct boot_domain *bd, struct elf_dom_parms *parms, + unsigned long initrd_len) +{ + unsigned long avail, nr_pages =3D bd->meminfo.mem_size.nr_pages; + + if ( builder_is_initdom(bd) ) + return dom0_compute_nr_pages(bd, parms, initrd_len); + + avail =3D dom_avail_nr_pages(bd, node_online_map); + + if ( is_pv_domain(bd->domain) && (parms->p2m_base =3D=3D UNSET_ADDR) ) + { + /* + * 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(bd->domain) ? + sizeof(int) : sizeof(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 + nr_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); + nr_pages =3D (end - vend) / (2 * sizeof_long); + printk("Dom0 memory clipped to %lu pages\n", nr_pages); + } + } + + /* Clamp according to available memory (final). */ + nr_pages =3D min(nr_pages, avail); + + bd->domain->max_pages =3D min_t(unsigned long, nr_pages, UINT_MAX); + + return nr_pages; +} + void __init arch_create_dom( const struct boot_info *bi, struct boot_domain *bd) { diff --git a/xen/arch/x86/hvm/dom0_build.c b/xen/arch/x86/hvm/dom0_build.c index ae3ffc614d..e94392be07 100644 --- a/xen/arch/x86/hvm/dom0_build.c +++ b/xen/arch/x86/hvm/dom0_build.c @@ -412,15 +412,16 @@ 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 dom_compute_nr_pages(bd, NULL, 0); bool preempted; =20 - pvh_setup_e820(d, nr_pages); + pvh_setup_e820(bd->domain, nr_pages); do { preempted =3D false; - paging_set_allocation(d, dom0_paging_pages(d, nr_pages), + paging_set_allocation(bd->domain, + dom0_paging_pages(bd->domain, nr_pages), &preempted); process_pending_softirqs(); } while ( preempted ); @@ -1239,7 +1240,7 @@ int __init dom0_construct_pvh(struct boot_domain *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 f30e4b860a..6c26ab0878 100644 --- a/xen/arch/x86/include/asm/dom0_build.h +++ b/xen/arch/x86/include/asm/dom0_build.h @@ -9,9 +9,17 @@ =20 extern unsigned int dom0_memflags; =20 -unsigned long dom0_compute_nr_pages(struct domain *d, - struct elf_dom_parms *parms, - unsigned long initrd_len); +unsigned long dom_avail_nr_pages( + struct boot_domain *bd, nodemask_t nodes); + +unsigned long dom0_compute_nr_pages( + struct boot_domain *bd, struct elf_dom_parms *parms, + unsigned long initrd_len); + +unsigned long dom_compute_nr_pages( + struct boot_domain *bd, struct elf_dom_parms *parms, + unsigned long initrd_len); + int dom0_setup_permissions(struct domain *d); =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 9d1c9fb8b0..ff5c93fa14 100644 --- a/xen/arch/x86/pv/dom0_build.c +++ b/xen/arch/x86/pv/dom0_build.c @@ -428,7 +428,7 @@ int __init dom0_construct_pv(struct boot_domain *bd) } } =20 - nr_pages =3D dom0_compute_nr_pages(d, &parms, initrd_len); + nr_pages =3D dom_compute_nr_pages(bd, &parms, initrd_len); =20 if ( parms.pae =3D=3D XEN_PAE_EXTCR3 ) set_bit(VMASST_TYPE_pae_extended_cr3, &d->vm_assist); --=20 2.20.1 From nobody Mon May 20 18:31:35 2024 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=1657142313; cv=pass; d=zohomail.com; s=zohoarc; b=HGFWaOD0Phx6qfqxxrW1k8ZA+UxCXUYRHIbLB+PnKa0J9JzlagXuUVqDTLzgEkjn4X7QGjBB4WWsUfgjDcPJ4hF5SiVYg+6NGOIoaG6LGMvKHKgWiIdjk+iePhI3S4n58isiU9izjnXYA5+ZkZad05Mmy8pzK8Fmd0nrt4hRws8= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657142313; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=wO71seG+2JNeV652NZFdlSDXjvFFYd1IqGaFh2WZtlI=; b=S3EV2+6wNMfioMM5kObrWIzqECzUwT05ynMBIHjnNdqO2zbYyQoOLsl4c31TVG2Sao7ebeOp2yJOFwf8Mf1giNUExzQMnr3Y31cGw9qLFJmhaBTp4aq/zrjuxG8vRb9XYasFwssqUAyt0iZPGXCXLMgpnPSe4euJKmv/etM0rmU= 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 1657142313423205.54148467884602; Wed, 6 Jul 2022 14:18:33 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.362584.592695 (Exim 4.92) (envelope-from ) id 1o9CPV-00047x-4f; Wed, 06 Jul 2022 21:18:13 +0000 Received: by outflank-mailman (output) from mailman id 362584.592695; Wed, 06 Jul 2022 21:18: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 1o9CPV-00047q-1w; Wed, 06 Jul 2022 21:18:13 +0000 Received: by outflank-mailman (input) for mailman id 362584; Wed, 06 Jul 2022 21:18:11 +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 1o9CGd-0007yd-8I for xen-devel@lists.xenproject.org; Wed, 06 Jul 2022 21:09:03 +0000 Received: from sender4-of-o51.zoho.com (sender4-of-o51.zoho.com [136.143.188.51]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id db23b078-fd6f-11ec-bd2d-47488cf2e6aa; Wed, 06 Jul 2022 23:09:01 +0200 (CEST) Received: from sisyou.hme. (static-72-81-132-2.bltmmd.fios.verizon.net [72.81.132.2]) by mx.zohomail.com with SMTPS id 1657141527503522.1572181705782; Wed, 6 Jul 2022 14:05: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: db23b078-fd6f-11ec-bd2d-47488cf2e6aa ARC-Seal: i=1; a=rsa-sha256; t=1657141528; cv=none; d=zohomail.com; s=zohoarc; b=gyMMf/zIGC9Fq0T/pchioGdYxETpEQ8ygFPgLloVVR0kmUPJl4bGNK733wllR1bzvUqrPOByzdvNe0DwmtEpNORy779oUDrojao7j6eMLlhfERlOZ21kmzvVAEJZTQAF2/A9bS7QDkehJ6T8voTCf1WySFOL3X0cCPVJ9+p8MZM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657141528; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=wO71seG+2JNeV652NZFdlSDXjvFFYd1IqGaFh2WZtlI=; b=VI5MXUQS/c+tlvAWLP9HWBYIaRff7f2hWCsV+c1f2rOSeQFywFoy0kLC8FuLSl07f/B0x7kVktXfUPSVrlX9RlLFsQK2YGwWjS6zuPC9npOMsS4AkcuRUtGZhn7B3X00wJF/cG1602PQFCGzGnJdWQO1QI78LjbKCFYrv+K9jn4= 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=1657141528; 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=wO71seG+2JNeV652NZFdlSDXjvFFYd1IqGaFh2WZtlI=; b=I0y8K00pZ6ObMS2+85N1SZsq8Mekv/hZPJ2S606KXO/zt/f9QcXMKFwry/zwVMa1 55PkRhPS+rMlky8qIZaAvkfIkc7/nNh5sXvpCN3Ppi4LJjyqp8GlvTD3Ey6ixXYlidp pf2tKFSL+39oAY2iJsR9vy5dU+3KQWbAkV1DnVOM= From: "Daniel P. Smith" To: xen-devel@lists.xenproject.org, Wei Liu Cc: "Daniel P. Smith" , scott.davis@starlab.io, christopher.clark@starlab.io, Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , George Dunlap , Julien Grall , Stefano Stabellini Subject: [PATCH v1 16/18] x86: add pv multidomain construction Date: Wed, 6 Jul 2022 17:04:51 -0400 Message-Id: <20220706210454.30096-17-dpsmith@apertussolutions.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220706210454.30096-1-dpsmith@apertussolutions.com> References: <20220706210454.30096-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: 1657142315563100001 Content-Type: text/plain; charset="utf-8" This adds the ability to domain builder for the construction of multiple pv domains at boot. Signed-off-by: Daniel P. Smith Reviewed-by: Christopher Clark --- xen/arch/x86/dom0_build.c | 31 ----- xen/arch/x86/domain_builder.c | 58 ++++++-- xen/arch/x86/include/asm/dom0_build.h | 2 - xen/arch/x86/include/asm/setup.h | 2 + xen/arch/x86/pv/Makefile | 2 +- .../x86/pv/{dom0_build.c =3D> domain_builder.c} | 86 +++++++----- xen/common/domain-builder/Kconfig | 10 ++ xen/common/domain-builder/core.c | 130 ++++++++++++++++-- xen/include/xen/bootdomain.h | 6 + xen/include/xen/domain_builder.h | 19 +++ 10 files changed, 259 insertions(+), 87 deletions(-) rename xen/arch/x86/pv/{dom0_build.c =3D> domain_builder.c} (92%) diff --git a/xen/arch/x86/dom0_build.c b/xen/arch/x86/dom0_build.c index 0600773b8f..85a10f63aa 100644 --- a/xen/arch/x86/dom0_build.c +++ b/xen/arch/x86/dom0_build.c @@ -524,37 +524,6 @@ int __init dom0_setup_permissions(struct domain *d) =20 return rc; } - -int __init construct_domain(struct boot_domain *bd) -{ - int rc =3D 0; - - /* Sanity! */ - BUG_ON(!pv_shim && bd->domid !=3D 0); - BUG_ON(bd->domain->vcpu[0] =3D=3D NULL); - BUG_ON(bd->domain->vcpu[0]->is_initialised); - - process_pending_softirqs(); - - if ( builder_is_initdom(bd) ) - { - if ( is_hvm_domain(bd->domain) ) - rc =3D dom0_construct_pvh(bd); - else if ( is_pv_domain(bd->domain) ) - rc =3D dom0_construct_pv(bd); - else - panic("Cannot construct Dom0. No guest interface available\n"); - } - - if ( rc ) - return rc; - - /* Sanity! */ - BUG_ON(!bd->domain->vcpu[0]->is_initialised); - - return 0; -} - /* * Local variables: * mode: C diff --git a/xen/arch/x86/domain_builder.c b/xen/arch/x86/domain_builder.c index d8babb1090..94f3ff4d5a 100644 --- a/xen/arch/x86/domain_builder.c +++ b/xen/arch/x86/domain_builder.c @@ -6,6 +6,7 @@ #include #include #include +#include =20 #include #include @@ -189,18 +190,22 @@ void __init arch_create_dom( if ( !pv_shim && builder_is_ctldom(bd) ) is_privileged =3D CDF_privileged; =20 - /* Create initial domain. Not d0 for pvshim. */ - bd->domid =3D get_initial_domain_id(); + /* Determine proper domain id. */ + if ( builder_is_initdom(bd) ) + bd->domid =3D get_initial_domain_id(); + else + bd->domid =3D bd->domid ? bd->domid : get_next_domid(); bd->domain =3D domain_create(bd->domid, &dom_cfg, is_privileged); if ( IS_ERR(bd->domain) ) panic("Error creating d%u: %ld\n", bd->domid, PTR_ERR(bd->domain)); =20 - init_dom0_cpuid_policy(bd->domain); + if ( builder_is_initdom(bd) ) + init_dom0_cpuid_policy(bd->domain); =20 if ( alloc_dom_vcpu0(bd) =3D=3D NULL ) panic("Error creating d%uv0\n", bd->domid); =20 - /* Grab the DOM0 command line. */ + /* Grab the command line. */ cmdline =3D (bd->kernel->string.kind =3D=3D BOOTSTR_CMDLINE) ? bd->kernel->string.bytes : NULL; if ( cmdline || bi->arch->kextra ) @@ -210,15 +215,23 @@ void __init arch_create_dom( cmdline =3D arch_prepare_cmdline(cmdline, bi->arch); strlcpy(dom_cmdline, cmdline, MAX_GUEST_CMDLINE); =20 - if ( bi->arch->kextra ) - /* kextra always includes exactly one leading space. */ - strlcat(dom_cmdline, bi->arch->kextra, MAX_GUEST_CMDLINE); + if ( builder_is_initdom(bd) ) + { + if ( bi->arch->kextra ) + /* kextra always includes exactly one leading space. */ + strlcat(dom_cmdline, bi->arch->kextra, MAX_GUEST_CMDLINE); =20 - apply_xen_cmdline(dom_cmdline); + apply_xen_cmdline(dom_cmdline); + } =20 strlcpy(bd->kernel->string.bytes, dom_cmdline, MAX_GUEST_CMDLINE); } =20 + if ( alloc_system_evtchn(bi, bd) !=3D 0 ) + printk(XENLOG_WARNING "%s: " + "unable set up system event channels for Dom%d\n", + __func__, bd->domid); + /* * Temporarily clear SMAP in CR4 to allow user-accesses in construct_d= om0(). * This saves a large number of corner cases interactions with @@ -240,3 +253,32 @@ void __init arch_create_dom( } } =20 +int __init construct_domain(struct boot_domain *bd) +{ + int rc =3D 0; + + /* Sanity! */ + BUG_ON(bd->domid !=3D bd->domain->domain_id); + BUG_ON(bd->domain->vcpu[0] =3D=3D NULL); + BUG_ON(bd->domain->vcpu[0]->is_initialised); + + process_pending_softirqs(); + + if ( is_hvm_domain(bd->domain) ) + if ( builder_is_initdom(bd) ) + rc =3D dom0_construct_pvh(bd); + else + panic("Cannot construct HVM DomU. Not supported.\n"); + else if ( is_pv_domain(bd->domain) ) + rc =3D dom_construct_pv(bd); + else + panic("Cannot construct Dom0. No guest interface available\n"); + + if ( rc ) + return rc; + + /* Sanity! */ + BUG_ON(!bd->domain->vcpu[0]->is_initialised); + + return 0; +} diff --git a/xen/arch/x86/include/asm/dom0_build.h b/xen/arch/x86/include/a= sm/dom0_build.h index 6c26ab0878..3624a57641 100644 --- a/xen/arch/x86/include/asm/dom0_build.h +++ b/xen/arch/x86/include/asm/dom0_build.h @@ -22,8 +22,6 @@ unsigned long dom_compute_nr_pages( =20 int dom0_setup_permissions(struct domain *d); =20 -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, diff --git a/xen/arch/x86/include/asm/setup.h b/xen/arch/x86/include/asm/se= tup.h index 6f53623fb3..328f9a8611 100644 --- a/xen/arch/x86/include/asm/setup.h +++ b/xen/arch/x86/include/asm/setup.h @@ -36,6 +36,8 @@ static inline void vesa_init(void) {}; void apply_xen_cmdline(char *cmdline); int construct_domain(struct boot_domain *bd); =20 +int dom_construct_pv(struct boot_domain *bd); + void setup_io_bitmap(struct domain *d); =20 unsigned long initial_images_nrpages(nodeid_t node); diff --git a/xen/arch/x86/pv/Makefile b/xen/arch/x86/pv/Makefile index 6cda354cc4..d06a3c1de1 100644 --- a/xen/arch/x86/pv/Makefile +++ b/xen/arch/x86/pv/Makefile @@ -15,5 +15,5 @@ obj-$(CONFIG_PV_SHIM) +=3D shim.o obj-$(CONFIG_TRACEBUFFER) +=3D trace.o obj-y +=3D traps.o =20 -obj-bin-y +=3D dom0_build.init.o +obj-bin-y +=3D domain_builder.init.o obj-bin-y +=3D gpr_switch.o diff --git a/xen/arch/x86/pv/dom0_build.c b/xen/arch/x86/pv/domain_builder.c similarity index 92% rename from xen/arch/x86/pv/dom0_build.c rename to xen/arch/x86/pv/domain_builder.c index ff5c93fa14..2ecf1b0ae3 100644 --- a/xen/arch/x86/pv/dom0_build.c +++ b/xen/arch/x86/pv/domain_builder.c @@ -1,5 +1,5 @@ /*************************************************************************= ***** - * pv/dom0_build.c + * pv/domain_builder.c * * Copyright (c) 2002-2005, K A Fraser */ @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -296,7 +297,7 @@ static struct page_info * __init alloc_chunk(struct dom= ain *d, return page; } =20 -int __init dom0_construct_pv(struct boot_domain *bd) +int __init dom_construct_pv(struct boot_domain *bd) { int i, rc, order, machine; bool compatible, compat; @@ -350,7 +351,7 @@ int __init dom0_construct_pv(struct boot_domain *bd) /* Machine address of next candidate page-table page. */ paddr_t mpt_alloc; =20 - printk(XENLOG_INFO "*** Building a PV Dom%d ***\n", d->domain_id); + printk(XENLOG_INFO "*** Constructing a PV Dom%d ***\n", d->domain_id); =20 d->max_pages =3D ~0U; =20 @@ -362,7 +363,7 @@ int __init dom0_construct_pv(struct boot_domain *bd) if ( (rc =3D elf_init(&elf, image_start, image_len)) !=3D 0 ) return rc; =20 - if ( opt_dom0_verbose ) + if ( builder_is_ctldom(bd) && opt_dom0_verbose ) elf_set_verbose(&elf); =20 elf_parse_binary(&elf); @@ -384,7 +385,8 @@ int __init dom0_construct_pv(struct boot_domain *bd) { if ( unlikely(rc =3D switch_compat(d)) ) { - printk("Dom0 failed to switch to compat: %d\n", rc); + printk("Dom%d failed to switch to compat: %d\n", + d->domain_id, rc); return rc; } =20 @@ -404,22 +406,23 @@ int __init dom0_construct_pv(struct boot_domain *bd) if ( elf_msb(&elf) ) compatible =3D false; =20 - printk(" Dom0 kernel: %s-bit%s, %s, paddr %#" PRIx64 " -> %#" PRIx64 "= \n", - elf_64bit(&elf) ? "64" : elf_32bit(&elf) ? "32" : "??", + printk(" Dom%d kernel: %s-bit%s, %s, paddr %#" PRIx64 " -> %#" PRIx64 = "\n", + d->domain_id, elf_64bit(&elf) ? "64" : elf_32bit(&elf) ? "32" := "??", parms.pae ? ", PAE" : "", elf_msb(&elf) ? "msb" : "lsb", elf.pstart, elf.pend); if ( elf.bsd_symtab_pstart ) - printk(" Dom0 symbol map %#" PRIx64 " -> %#" PRIx64 "\n", - elf.bsd_symtab_pstart, elf.bsd_symtab_pend); + printk(" Dom%d symbol map %#" PRIx64 " -> %#" PRIx64 "\n", + d->domain_id, elf.bsd_symtab_pstart, elf.bsd_symtab_pend); =20 if ( !compatible ) { - printk("Mismatch between Xen and DOM0 kernel\n"); + printk("Mismatch between Xen and DOM%d kernel\n", d->domain_id); return -EINVAL; } =20 - if ( parms.elf_notes[XEN_ELFNOTE_SUPPORTED_FEATURES].type !=3D XEN_ENT= _NONE ) + if ( builder_is_initdom(bd) && + parms.elf_notes[XEN_ELFNOTE_SUPPORTED_FEATURES].type !=3D XEN_ENT= _NONE ) { if ( !pv_shim && !test_bit(XENFEAT_dom0, parms.f_supported) ) { @@ -443,7 +446,8 @@ int __init dom0_construct_pv(struct boot_domain *bd) =20 if ( value > __HYPERVISOR_COMPAT_VIRT_START ) { - printk("Dom0 expects too high a hypervisor start address\n= "); + printk("Dom%d expects too high a hypervisor start address\= n", + d->domain_id); return -ERANGE; } HYPERVISOR_COMPAT_VIRT_START(d) =3D @@ -487,7 +491,7 @@ int __init dom0_construct_pv(struct boot_domain *bd) vstartinfo_start =3D round_pgup(vphysmap_end); vstartinfo_end =3D vstartinfo_start + sizeof(struct start_info); =20 - if ( pv_shim ) + if ( pv_shim || ! builder_is_initdom(bd) ) { vxenstore_start =3D round_pgup(vstartinfo_end); vxenstore_end =3D vxenstore_start + PAGE_SIZE; @@ -578,8 +582,8 @@ int __init dom0_construct_pv(struct boot_domain *bd) } =20 printk("PHYSICAL MEMORY ARRANGEMENT:\n" - " Dom0 alloc.: %"PRIpaddr"->%"PRIpaddr, - pfn_to_paddr(alloc_spfn), pfn_to_paddr(alloc_epfn)); + " Dom%d alloc.: %"PRIpaddr"->%"PRIpaddr, + d->domain_id, pfn_to_paddr(alloc_spfn), pfn_to_paddr(alloc_epfn= )); if ( domain_tot_pages(d) < nr_pages ) printk(" (%lu pages to be allocated)", nr_pages - domain_tot_pages(d)); @@ -596,7 +600,7 @@ int __init dom0_construct_pv(struct boot_domain *bd) printk(" Init. ramdisk: %p->%p\n", _p(vinitrd_start), _p(vinitrd_e= nd)); printk(" Phys-Mach map: %p->%p\n", _p(vphysmap_start), _p(vphysmap_end= )); printk(" Start info: %p->%p\n", _p(vstartinfo_start), _p(vstartinfo= _end)); - if ( pv_shim ) + if ( pv_shim || ! builder_is_initdom(bd) ) { printk(" Xenstore ring: %p->%p\n", _p(vxenstore_start), _p(vxensto= re_end)); printk(" Console ring: %p->%p\n", _p(vconsole_start), _p(vconsole= _end)); @@ -617,7 +621,7 @@ int __init dom0_construct_pv(struct boot_domain *bd) ? v_end > HYPERVISOR_COMPAT_VIRT_START(d) : (v_start < HYPERVISOR_VIRT_END) && (v_end > HYPERVISOR_VIRT_STA= RT) ) { - printk("DOM0 image overlaps with Xen private area.\n"); + printk("DOM%d image overlaps with Xen private area.\n", d->domain_= id); return -EINVAL; } =20 @@ -768,9 +772,6 @@ int __init dom0_construct_pv(struct boot_domain *bd) init_hypercall_page(d, _p(parms.virt_hypercall)); } =20 - /* Free temporary buffers. */ - discard_initial_images(); - /* Set up start info area. */ si =3D (start_info_t *)vstartinfo_start; clear_page(si); @@ -778,7 +779,7 @@ int __init dom0_construct_pv(struct boot_domain *bd) =20 si->shared_info =3D virt_to_maddr(d->shared_info); =20 - if ( !pv_shim ) + if ( !pv_shim && builder_is_ctldom(bd) ) si->flags =3D SIF_PRIVILEGED | SIF_INITDOMAIN; if ( !vinitrd_start && initrd_len ) si->flags |=3D SIF_MOD_START_PFN; @@ -789,6 +790,19 @@ int __init dom0_construct_pv(struct boot_domain *bd) snprintf(si->magic, sizeof(si->magic), "xen-3.0-x86_%d%s", elf_64bit(&elf) ? 64 : 32, parms.pae ? "p" : ""); =20 + if ( !builder_is_initdom(bd) ) + { + si->store_mfn =3D ((vxenstore_start - v_start) >> PAGE_SHIFT) + + alloc_spfn; + bd->store.mfn =3D si->store_mfn; + si->store_evtchn =3D bd->store.evtchn; + + si->console.domU.mfn =3D ((vconsole_start - v_start) >> PAGE_SHIFT) + + alloc_spfn; + bd->console.mfn =3D si->console.domU.mfn; + si->console.domU.evtchn =3D bd->console.evtchn; + } + count =3D domain_tot_pages(d); =20 /* Set up the phys->machine table if not part of the initial mapping. = */ @@ -871,23 +885,24 @@ int __init dom0_construct_pv(struct boot_domain *bd) sizeof(si->cmd_line)); =20 #ifdef CONFIG_VIDEO - if ( !pv_shim && fill_console_start_info((void *)(si + 1)) ) - { - si->console.dom0.info_off =3D sizeof(struct start_info); - si->console.dom0.info_size =3D sizeof(struct dom0_vga_console_info= ); - } + if ( builder_is_hwdom(bd) ) + if ( !pv_shim && fill_console_start_info((void *)(si + 1)) ) + { + si->console.dom0.info_off =3D sizeof(struct start_info); + si->console.dom0.info_size =3D sizeof(struct dom0_vga_console_= info); + } #endif =20 /* * TODO: provide an empty stub for fill_console_start_info in the * !CONFIG_VIDEO case so the logic here can be simplified. */ - if ( pv_shim ) + if ( builder_is_hwdom(bd) && pv_shim ) pv_shim_setup_dom(d, l4start, v_start, vxenstore_start, vconsole_s= tart, vphysmap_start, si); =20 #ifdef CONFIG_COMPAT - if ( compat ) + if ( builder_is_hwdom(bd) && compat ) xlat_start_info(si, pv_shim ? XLAT_start_info_console_domU : XLAT_start_info_console_dom0); #endif @@ -926,15 +941,18 @@ int __init dom0_construct_pv(struct boot_domain *bd) if ( test_bit(XENFEAT_supervisor_mode_kernel, parms.f_required) ) panic("Dom0 requires supervisor-mode execution\n"); =20 - rc =3D dom0_setup_permissions(d); - BUG_ON(rc !=3D 0); + if ( builder_is_hwdom(bd) ) + { + rc =3D dom0_setup_permissions(d); + BUG_ON(rc !=3D 0); + } =20 if ( d->domain_id =3D=3D hardware_domid ) iommu_hwdom_init(d); =20 #ifdef CONFIG_SHADOW_PAGING /* Fill the shadow pool if necessary. */ - if ( opt_dom0_shadow || opt_pv_l1tf_hwdom ) + if ( builder_is_hwdom(bd) && (opt_dom0_shadow || opt_pv_l1tf_hwdom) ) { bool preempted; =20 @@ -948,7 +966,7 @@ int __init dom0_construct_pv(struct boot_domain *bd) } =20 /* Activate shadow mode, if requested. Reuse the pv_l1tf tasklet. */ - if ( opt_dom0_shadow ) + if ( builder_is_hwdom(bd) && opt_dom0_shadow ) { printk("Switching dom0 to using shadow paging\n"); tasklet_schedule(&d->arch.paging.shadow.pv_l1tf_tasklet); @@ -960,8 +978,8 @@ int __init dom0_construct_pv(struct boot_domain *bd) =20 out: if ( elf_check_broken(&elf) ) - printk(XENLOG_WARNING "Dom0 kernel broken ELF: %s\n", - elf_check_broken(&elf)); + printk(XENLOG_WARNING "Dom%d kernel broken ELF: %s\n", + d->domain_id, elf_check_broken(&elf)); =20 return rc; } diff --git a/xen/common/domain-builder/Kconfig b/xen/common/domain-builder/= Kconfig index 893038cab3..0232e1ed8a 100644 --- a/xen/common/domain-builder/Kconfig +++ b/xen/common/domain-builder/Kconfig @@ -12,4 +12,14 @@ config BUILDER_FDT =20 If unsure, say N. =20 +config MULTIDOM_BUILDER + bool "Multidomain building (UNSUPPORTED)" if UNSUPPORTED + depends on BUILDER_FDT + ---help--- + Enables the domain builder to construct multiple domains. + + This feature is currently experimental. + + If unsure, say N. + endmenu diff --git a/xen/common/domain-builder/core.c b/xen/common/domain-builder/c= ore.c index b030b07d71..c6a268eb96 100644 --- a/xen/common/domain-builder/core.c +++ b/xen/common/domain-builder/core.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include =20 @@ -60,37 +61,144 @@ void __init builder_init(struct boot_info *info) d->kernel->string.kind =3D BOOTSTR_CMDLINE; } =20 +static bool __init build_domain(struct boot_info *info, struct boot_domain= *bd) +{ + if ( bd->constructed =3D=3D true ) + return true; + + if ( bd->kernel =3D=3D NULL ) + return false; + + printk(XENLOG_INFO "*** Building Dom%d ***\n", bd->domid); + + arch_create_dom(info, bd); + if ( bd->domain ) + { + bd->constructed =3D true; + return true; + } + + return false; +} + uint32_t __init builder_create_domains(struct boot_info *info) { uint32_t build_count =3D 0, functions_built =3D 0; + struct boot_domain *bd; int i; =20 + if ( IS_ENABLED(CONFIG_MULTIDOM_BUILDER) ) + { + bd =3D builder_dom_by_function(info, BUILD_FUNCTION_XENSTORE); + if ( build_domain(info, bd) ) + { + functions_built |=3D bd->functions; + build_count++; + } + else + printk(XENLOG_WARNING "Xenstore build failed, system may be un= usable\n"); + + bd =3D builder_dom_by_function(info, BUILD_FUNCTION_CONSOLE); + if ( build_domain(info, bd) ) + { + functions_built |=3D bd->functions; + build_count++; + } + else + printk(XENLOG_WARNING "Console build failed, system may be unu= sable\n"); + } + for ( i =3D 0; i < info->builder->nr_doms; i++ ) { - struct boot_domain *d =3D &info->builder->domains[i]; + bd =3D &info->builder->domains[i]; =20 if ( ! IS_ENABLED(CONFIG_MULTIDOM_BUILDER) && - ! builder_is_initdom(d) && + ! builder_is_initdom(bd) && functions_built & BUILD_FUNCTION_INITIAL_DOM ) continue; =20 - if ( d->kernel =3D=3D NULL ) + if ( !build_domain(info, bd) ) { - if ( builder_is_initdom(d) ) + if ( builder_is_initdom(bd) ) panic("%s: intial domain missing kernel\n", __func__); =20 - printk(XENLOG_ERR "%s:Dom%d definiton has no kernel\n", __func= __, - d->domid); + printk(XENLOG_WARNING "Dom%d build failed, skipping\n", bd->do= mid); continue; } =20 - arch_create_dom(info, d); - if ( d->domain ) + functions_built |=3D bd->functions; + build_count++; + } + + if ( IS_ENABLED(CONFIG_X86) ) + /* Free temporary buffers. */ + discard_initial_images(); + + return build_count; +} + +domid_t __init get_next_domid(void) +{ + static domid_t __initdata last_domid =3D 0; + domid_t next; + + for ( next =3D last_domid + 1; next < DOMID_FIRST_RESERVED; next++ ) + { + struct domain *d; + + if ( (d =3D rcu_lock_domain_by_id(next)) =3D=3D NULL ) { - functions_built |=3D d->functions; - build_count++; + last_domid =3D next; + return next; } + + rcu_unlock_domain(d); } =20 - return build_count; + return 0; +} + +int __init alloc_system_evtchn( + const struct boot_info *info, struct boot_domain *bd) +{ + evtchn_alloc_unbound_t evtchn_req; + struct boot_domain *c =3D builder_dom_by_function(info, + BUILD_FUNCTION_CONSOLE= ); + struct boot_domain *s =3D builder_dom_by_function(info, + BUILD_FUNCTION_XENSTOR= E); + int rc; + + evtchn_req.dom =3D bd->domid; + + if ( c !=3D NULL && c !=3D bd && c->constructed ) + { + evtchn_req.remote_dom =3D c->domid; + + rc =3D evtchn_alloc_unbound(&evtchn_req); + if ( rc ) + { + printk("Failed allocating console event channel for domain %d\= n", + bd->domid); + return rc; + } + + bd->console.evtchn =3D evtchn_req.port; + } + + if ( s !=3D NULL && s !=3D bd && s->constructed ) + { + evtchn_req.remote_dom =3D s->domid; + + rc =3D evtchn_alloc_unbound(&evtchn_req); + if ( rc ) + { + printk("Failed allocating xenstore event channel for domain %d= \n", + bd->domid); + return rc; + } + + bd->store.evtchn =3D evtchn_req.port; + } + + return 0; } diff --git a/xen/include/xen/bootdomain.h b/xen/include/xen/bootdomain.h index b172d16f4e..9c5d4d385e 100644 --- a/xen/include/xen/bootdomain.h +++ b/xen/include/xen/bootdomain.h @@ -47,6 +47,12 @@ struct boot_domain { struct boot_module *configs[BUILD_MAX_CONF_MODS]; =20 struct domain *domain; + struct { + xen_pfn_t mfn; + unsigned int evtchn; + } store, console; + bool constructed; + }; =20 #endif diff --git a/xen/include/xen/domain_builder.h b/xen/include/xen/domain_buil= der.h index c0d997f7bd..f9e43c9689 100644 --- a/xen/include/xen/domain_builder.h +++ b/xen/include/xen/domain_builder.h @@ -34,6 +34,22 @@ static inline bool builder_is_hwdom(struct boot_domain *= bd) bd->permissions & BUILD_PERMISSION_HARDWARE ); } =20 +static inline struct boot_domain *builder_dom_by_function( + const struct boot_info *info, uint32_t func) +{ + int i; + + for ( i =3D 0; i < info->builder->nr_doms; i++ ) + { + struct boot_domain *bd =3D &info->builder->domains[i]; + + if ( bd->functions & func ) + return bd; + } + + return NULL; +} + static inline struct domain *builder_get_hwdom(struct boot_info *info) { int i; @@ -51,6 +67,9 @@ static inline struct domain *builder_get_hwdom(struct boo= t_info *info) =20 void builder_init(struct boot_info *info); uint32_t builder_create_domains(struct boot_info *info); +domid_t get_next_domid(void); +int alloc_system_evtchn( + const struct boot_info *info, struct boot_domain *bd); void arch_create_dom(const struct boot_info *bi, struct boot_domain *bd); =20 #endif /* XEN_DOMAIN_BUILDER_H */ --=20 2.20.1 From nobody Mon May 20 18:31:35 2024 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=1657142332; cv=pass; d=zohomail.com; s=zohoarc; b=eZF2jcwBILB35XiGwRtONXp930cZB2c75SUYSkWN7LyG23ll7wN2pPz6A9ixyDr1hft9zFgJetdMuFApsBjSn0VCcbe9Y5Wio5NdMwcugKVVSBKhhF5zdfMO+gFnKn0a5A4BDLMUNHENsTxXELdyZlYQLqUk0+iTRbICEeiAXH0= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657142332; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=uq/k8IUdG9nFheQBakIgF1OjCIHV4VLDEfRMPtZOoM8=; b=UDvPrAJ0d+oX1pLax/++zQHXUMGKfNplOAmqpHexEoTT/oDn8Sb1vGolImb0hMInxeY87PAZybe/sb2IkSUoYngBNtekWYoKCD9kvNo5fVTHrmIPnirfT/Mse7uQNg2G1PPfJ6AHsTo3Vp1UQp8qp0P8e7yNlw8/NYGdtl6MCNE= 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 1657142332333615.8132225124995; Wed, 6 Jul 2022 14:18:52 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.362592.592723 (Exim 4.92) (envelope-from ) id 1o9CPo-00053l-A2; Wed, 06 Jul 2022 21:18:32 +0000 Received: by outflank-mailman (output) from mailman id 362592.592723; Wed, 06 Jul 2022 21:18:32 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1o9CPo-00052n-3f; Wed, 06 Jul 2022 21:18:32 +0000 Received: by outflank-mailman (input) for mailman id 362592; Wed, 06 Jul 2022 21:18:30 +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 1o9CGq-0003HV-3V for xen-devel@lists.xenproject.org; Wed, 06 Jul 2022 21:09:16 +0000 Received: from sender4-of-o51.zoho.com (sender4-of-o51.zoho.com [136.143.188.51]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id e3214e47-fd6f-11ec-924f-1f966e50362f; Wed, 06 Jul 2022 23:09:14 +0200 (CEST) Received: from sisyou.hme. (static-72-81-132-2.bltmmd.fios.verizon.net [72.81.132.2]) by mx.zohomail.com with SMTPS id 1657141528926584.3775148690877; Wed, 6 Jul 2022 14:05: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: e3214e47-fd6f-11ec-924f-1f966e50362f ARC-Seal: i=1; a=rsa-sha256; t=1657141530; cv=none; d=zohomail.com; s=zohoarc; b=N/FSL553HNCEa+TyNxWgI3ljiv4gg26j+KpjtiAjGUSlauyoUajpteJxNg7Jyy6Af3ugKVX9kpz5eob6Mk9uzLDrLqhu8aXf4wz0/e1JEVpkx6C/Tvvu2jgAp4cpWCfrCzZF+Ho2atm9u11XL7qgUR4dP6DchsYV7VKREwOEN0U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657141530; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=uq/k8IUdG9nFheQBakIgF1OjCIHV4VLDEfRMPtZOoM8=; b=H5/S1fH1YZaeMcEQ3dOAI6jaIhWA12cDBec+iG1nb+ONKanf1xzIXuAwty+mETeOeFyXetRvjar64iVwKaKUXmG1WraATQ5HoFCaC9a9+dnJNLw581uFvlTn5qIy8iyfS4qC1sPY+8k9/vZRMHlZkM4dWwKxQ8UAQtBzBovWAhM= 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=1657141530; 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=uq/k8IUdG9nFheQBakIgF1OjCIHV4VLDEfRMPtZOoM8=; b=bTNmAkvNs5MuJJWJBKqoCkjuO2VQ39BIvTeyEFTZb1nuzjCqnnzvEcoWhLsHH0KO tOrRcuESCFR2uzzOEPiL+jn2kA/hwybXIbPmTfXuy96Y63G1gmbr8c6JKZHou1MtVtk k2sEkZEoLi8N2IKJ617BthcUY51iiE+FGOF9Z+Os= From: "Daniel P. Smith" To: xen-devel@lists.xenproject.org Cc: "Daniel P. Smith" , scott.davis@starlab.io, christopher.clark@starlab.io, Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu Subject: [PATCH v1 17/18] builder: introduce domain builder hypfs tree Date: Wed, 6 Jul 2022 17:04:52 -0400 Message-Id: <20220706210454.30096-18-dpsmith@apertussolutions.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220706210454.30096-1-dpsmith@apertussolutions.com> References: <20220706210454.30096-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: 1657142333330100001 Content-Type: text/plain; charset="utf-8" This enables domain builder to construct a hypfs tree to expose relevant do= main creation information for use by the boot domain and/or the runtime system. Signed-off-by: Daniel P. Smith Reviewed-by: Christopher Clark --- xen/common/domain-builder/Kconfig | 11 ++ xen/common/domain-builder/Makefile | 1 + xen/common/domain-builder/core.c | 3 + xen/common/domain-builder/hypfs.c | 193 +++++++++++++++++++++++++++++ xen/include/xen/domain_builder.h | 13 ++ 5 files changed, 221 insertions(+) create mode 100644 xen/common/domain-builder/hypfs.c diff --git a/xen/common/domain-builder/Kconfig b/xen/common/domain-builder/= Kconfig index 0232e1ed8a..4b98cccfab 100644 --- a/xen/common/domain-builder/Kconfig +++ b/xen/common/domain-builder/Kconfig @@ -22,4 +22,15 @@ config MULTIDOM_BUILDER =20 If unsure, say N. =20 +config BUILDER_HYPFS + bool "Domain builder hypfs support (UNSUPPORTED)" if UNSUPPORTED + depends on HYPFS + ---help--- + Exposes the domain builder construction information + through hypfs. + + This feature is currently experimental. + + If unsure, say N. + endmenu diff --git a/xen/common/domain-builder/Makefile b/xen/common/domain-builder= /Makefile index 9561602502..7aa2ea2a53 100644 --- a/xen/common/domain-builder/Makefile +++ b/xen/common/domain-builder/Makefile @@ -1,2 +1,3 @@ obj-$(CONFIG_BUILDER_FDT) +=3D fdt.o +obj-$(CONFIG_HYPFS) +=3D hypfs.o obj-y +=3D core.o diff --git a/xen/common/domain-builder/core.c b/xen/common/domain-builder/c= ore.c index c6a268eb96..f41ca3ed35 100644 --- a/xen/common/domain-builder/core.c +++ b/xen/common/domain-builder/core.c @@ -134,6 +134,9 @@ uint32_t __init builder_create_domains(struct boot_info= *info) /* Free temporary buffers. */ discard_initial_images(); =20 + if ( IS_ENABLED(CONFIG_BUILDER_HYPFS) ) + builder_hypfs(info); + return build_count; } =20 diff --git a/xen/common/domain-builder/hypfs.c b/xen/common/domain-builder/= hypfs.c new file mode 100644 index 0000000000..28f8b13d85 --- /dev/null +++ b/xen/common/domain-builder/hypfs.c @@ -0,0 +1,193 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#define INIT_HYPFS_DIR(var, nam) \ + var.e.type =3D XEN_HYPFS_TYPE_DIR; \ + var.e.encoding =3D XEN_HYPFS_ENC_PLAIN; \ + var.e.name =3D (nam); \ + var.e.size =3D 0; \ + var.e.max_size =3D 0; \ + INIT_LIST_HEAD(&var.e.list); \ + var.e.funcs =3D (&hypfs_dir_funcs); \ + INIT_LIST_HEAD(&var.dirlist) + +#define INIT_HYPFS_FIXEDSIZE(var, typ, nam, contvar, fn, wr) \ + var.e.type =3D (typ); \ + var.e.encoding =3D XEN_HYPFS_ENC_PLAIN; \ + var.e.name =3D (nam); \ + var.e.size =3D sizeof(contvar); \ + var.e.max_size =3D (wr) ? sizeof(contvar) : 0; \ + var.e.funcs =3D (fn); \ + var.u.content =3D &(contvar) + +#define INIT_HYPFS_UINT(var, nam, contvar) \ + INIT_HYPFS_FIXEDSIZE(var, XEN_HYPFS_TYPE_UINT, nam, contvar, \ + &hypfs_leaf_ro_funcs, 0) + +#define INIT_HYPFS_BOOL(var, nam, contvar) \ + INIT_HYPFS_FIXEDSIZE(var, XEN_HYPFS_TYPE_BOOL, nam, contvar, \ + &hypfs_leaf_ro_funcs, 0) + +#define INIT_HYPFS_VARSIZE(var, typ, nam, msz, fn) \ + var.e.type =3D (typ) ; \ + var.e.encoding =3D XEN_HYPFS_ENC_PLAIN; \ + var.e.name =3D (nam); \ + var.e.max_size =3D (msz); \ + var.e.funcs =3D (fn) + +#define INIT_HYPFS_STRING(var, nam) \ + INIT_HYPFS_VARSIZE(var, XEN_HYPFS_TYPE_STRING, nam, 0, &hypfs_leaf_ro_= funcs) + +struct device_node { + struct hypfs_entry_dir dir; + + uint32_t evtchn; + struct hypfs_entry_leaf evtchn_leaf; + + xen_pfn_t mfn; + struct hypfs_entry_leaf mfn_leaf; +}; + +struct domain_node { + char dir_name[HYPFS_DYNDIR_ID_NAMELEN]; + struct hypfs_entry_dir dir; + + char uuid[40]; + struct hypfs_entry_leaf uuid_leaf; + + uint16_t functions; + struct hypfs_entry_leaf func_leaf; + + uint32_t ncpus; + struct hypfs_entry_leaf ncpus_leaf; + + uint32_t mem_size; + struct hypfs_entry_leaf mem_sz_leaf; + + uint32_t mem_max; + struct hypfs_entry_leaf mem_mx_leaf; + + bool constructed; + struct hypfs_entry_leaf const_leaf; + + struct device_node xs; + + struct hypfs_entry_dir dev_dir; + + struct device_node con_dev; +}; + +static struct hypfs_entry_dir __read_mostly *builder_dir; +static struct domain_node __read_mostly *entries; + +static int __init alloc_hypfs(struct boot_info *info) +{ + if ( !(builder_dir =3D (struct hypfs_entry_dir *)xmalloc_bytes( + sizeof(struct hypfs_entry_dir))) ) + { + printk(XENLOG_WARNING "%s: unable to allocate hypfs dir\n", __func= __); + return -ENOMEM; + } + + builder_dir->e.type =3D XEN_HYPFS_TYPE_DIR; + builder_dir->e.encoding =3D XEN_HYPFS_ENC_PLAIN; + builder_dir->e.name =3D "builder"; + builder_dir->e.size =3D 0; + builder_dir->e.max_size =3D 0; + INIT_LIST_HEAD(&builder_dir->e.list); + builder_dir->e.funcs =3D &hypfs_dir_funcs; + INIT_LIST_HEAD(&builder_dir->dirlist); + + if ( !(entries =3D (struct domain_node *)xmalloc_bytes( + sizeof(struct domain_node) * info->builder->nr_dom= s)) ) + { + printk(XENLOG_WARNING "%s: unable to allocate hypfs nodes\n", __fu= nc__); + return -ENOMEM; + } + + return 0; +} + +void __init builder_hypfs(struct boot_info *info) +{ + int i; + + printk("Domain Builder: creating hypfs nodes\n"); + + if ( alloc_hypfs(info) !=3D 0 ) + return; + + for ( i =3D 0; i < info->builder->nr_doms; i++ ) + { + struct domain_node *e =3D &entries[i]; + struct boot_domain *bd =3D &info->builder->domains[i]; + uint8_t *uuid =3D bd->uuid; + + snprintf(e->dir_name, sizeof(e->dir_name), "%d", bd->domid); + + snprintf(e->uuid, sizeof(e->uuid), "%08x-%04x-%04x-%04x-%04x%08x", + *(uint32_t *)uuid, *(uint16_t *)(uuid+4), + *(uint16_t *)(uuid+6), *(uint16_t *)(uuid+8), + *(uint16_t *)(uuid+10), *(uint32_t *)(uuid+12)); + + e->functions =3D bd->functions; + e->constructed =3D bd->constructed; + + e->ncpus =3D bd->ncpus; + e->mem_size =3D (bd->meminfo.mem_size.nr_pages * PAGE_SIZE)/1024; + e->mem_max =3D (bd->meminfo.mem_max.nr_pages * PAGE_SIZE)/1024; + + e->xs.evtchn =3D bd->store.evtchn; + e->xs.mfn =3D bd->store.mfn; + + e->con_dev.evtchn =3D bd->console.evtchn; + e->con_dev.mfn =3D bd->console.mfn; + + /* Initialize and construct builder hypfs tree */ + INIT_HYPFS_DIR(e->dir, e->dir_name); + INIT_HYPFS_DIR(e->xs.dir, "xenstore"); + INIT_HYPFS_DIR(e->dev_dir, "devices"); + INIT_HYPFS_DIR(e->con_dev.dir, "console"); + + INIT_HYPFS_STRING(e->uuid_leaf, "uuid"); + hypfs_string_set_reference(&e->uuid_leaf, e->uuid); + INIT_HYPFS_UINT(e->func_leaf, "functions", e->functions); + INIT_HYPFS_UINT(e->ncpus_leaf, "ncpus", e->ncpus); + INIT_HYPFS_UINT(e->mem_sz_leaf, "mem_size", e->mem_size); + INIT_HYPFS_UINT(e->mem_mx_leaf, "mem_max", e->mem_max); + INIT_HYPFS_BOOL(e->const_leaf, "constructed", e->constructed); + + INIT_HYPFS_UINT(e->xs.evtchn_leaf, "evtchn", e->xs.evtchn); + INIT_HYPFS_UINT(e->xs.mfn_leaf, "mfn", e->xs.mfn); + + INIT_HYPFS_UINT(e->con_dev.evtchn_leaf, "evtchn", e->con_dev.evtch= n); + INIT_HYPFS_UINT(e->con_dev.mfn_leaf, "mfn", e->con_dev.mfn); + + hypfs_add_leaf(&e->con_dev.dir, &e->con_dev.evtchn_leaf, true); + hypfs_add_leaf(&e->con_dev.dir, &e->con_dev.mfn_leaf, true); + hypfs_add_dir(&e->dev_dir, &e->con_dev.dir, true); + + hypfs_add_dir(&e->dir, &e->dev_dir, true); + + hypfs_add_leaf(&e->xs.dir, &e->xs.evtchn_leaf, true); + hypfs_add_leaf(&e->xs.dir, &e->xs.mfn_leaf, true); + hypfs_add_dir(&e->dir, &e->xs.dir, true); + + hypfs_add_leaf(&e->dir, &e->uuid_leaf, true); + hypfs_add_leaf(&e->dir, &e->func_leaf, true); + hypfs_add_leaf(&e->dir, &e->ncpus_leaf, true); + hypfs_add_leaf(&e->dir, &e->mem_sz_leaf, true); + hypfs_add_leaf(&e->dir, &e->mem_mx_leaf, true); + hypfs_add_leaf(&e->dir, &e->const_leaf, true); + + hypfs_add_dir(builder_dir, &e->dir, true); + } + + hypfs_add_dir(&hypfs_root, builder_dir, true); +} diff --git a/xen/include/xen/domain_builder.h b/xen/include/xen/domain_buil= der.h index f9e43c9689..086968b0fe 100644 --- a/xen/include/xen/domain_builder.h +++ b/xen/include/xen/domain_builder.h @@ -72,4 +72,17 @@ int alloc_system_evtchn( const struct boot_info *info, struct boot_domain *bd); void arch_create_dom(const struct boot_info *bi, struct boot_domain *bd); =20 +#ifdef CONFIG_HYPFS + +void builder_hypfs(struct boot_info *info); + +#else + +static inline void builder_hypfs(struct boot_info *info) +{ + return; +} + +#endif + #endif /* XEN_DOMAIN_BUILDER_H */ --=20 2.20.1 From nobody Mon May 20 18:31:35 2024 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=1657142327; cv=pass; d=zohomail.com; s=zohoarc; b=L1bH5AGnuuJ9GkQsXTJtYwqZPBJZecA5g0S4w+R5NdiGnkXb8jXDTpFYLGz9Ua5wOIWVmpAGtIkl8XfHwnWXjjArUv8n0fwn7Jnc8L1OBB4sYcLjdFFQi2fLO96SY18afV2AnrXAnMcAbUYPjfsHPS/jpZHiQP9CXTSyq/khKF8= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657142327; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=TzFqy4EBOd/GMNv9mujkd/fHHyBVp+g+FM7/J81/w1g=; b=Q3wHFx4og0JcHwMFz0kKjFY9MB959mMTu5iUKNpa7wDqLJSt0F2xFMgNrM9TbmR80mEsvhYTDCIqX/nEv5pUGK8dGZqMcwkxPdy9RIOIv/DxUk4z+P5Dkur+rtHuBn/rkZw/HauTmfaaEOF/cIHZH5KTlcSipHRT1ZIdCxnIrHg= 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 1657142327197362.3292139369556; Wed, 6 Jul 2022 14:18:47 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.362587.592707 (Exim 4.92) (envelope-from ) id 1o9CPh-0004Uf-DP; Wed, 06 Jul 2022 21:18:25 +0000 Received: by outflank-mailman (output) from mailman id 362587.592707; Wed, 06 Jul 2022 21:18: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 1o9CPh-0004UY-9X; Wed, 06 Jul 2022 21:18:25 +0000 Received: by outflank-mailman (input) for mailman id 362587; Wed, 06 Jul 2022 21:18:24 +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 1o9CH2-0003HV-NY for xen-devel@lists.xenproject.org; Wed, 06 Jul 2022 21:09:28 +0000 Received: from sender4-of-o51.zoho.com (sender4-of-o51.zoho.com [136.143.188.51]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id ea5ee30e-fd6f-11ec-924f-1f966e50362f; Wed, 06 Jul 2022 23:09:27 +0200 (CEST) Received: from sisyou.hme. (static-72-81-132-2.bltmmd.fios.verizon.net [72.81.132.2]) by mx.zohomail.com with SMTPS id 1657141530530395.5815075032556; Wed, 6 Jul 2022 14:05: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: ea5ee30e-fd6f-11ec-924f-1f966e50362f ARC-Seal: i=1; a=rsa-sha256; t=1657141532; cv=none; d=zohomail.com; s=zohoarc; b=S4Pd5Ua+YLIwBW93VjYZA95MP8py3To/IxTEvHAqYduNamfMq2orRibCfrPlbw4e0W5SbEcQjzJNHoO8adi04PODNP7v1xVl6Ge3ZxKm+WoV+YjmcdBjKq7Gs02QsPSrOEg4soztxITQkF2b1tdvUdz1G50FPFgtd2bd6aLeYo8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657141532; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=TzFqy4EBOd/GMNv9mujkd/fHHyBVp+g+FM7/J81/w1g=; b=OnuQQ+lSE0NsCnvaZf7N5Oy4t7uo60pBy6j7JWFFJAUU2ZRoTtzvxJHk3hkBUPH9SyfpnoSBA86fsYVAfu45QgGpiUWn7FkmsJCQBbHlGYPOkDHQN1BG8qhwOx4pHLFVlmY1aEWpToFmcpomKZEjPeVf8y5H9P+PTwzgx5aFo0k= 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=1657141532; 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=TzFqy4EBOd/GMNv9mujkd/fHHyBVp+g+FM7/J81/w1g=; b=VAT6AYQwoX3OC7hTtJyOksAXMnty1p42z36rkGo+COOWjf0qxxKa4yhRTWg51dnl DHjvb7Y0BR1DgJjTt9EaYI5B/oD2kEBacJGpeB7jlz6VxSAiAYWkzBkVod9i/Z/ojsJ Lcu4E9lvYH6WH+L1shVEAjQ8RUHBT1v40cCqBzE0= From: "Daniel P. Smith" To: xen-devel@lists.xenproject.org Cc: "Daniel P. Smith" , scott.davis@starlab.io, christopher.clark@starlab.io, Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu , Anthony PERARD Subject: [PATCH v1 18/18] tools: introduce example late pv helper Date: Wed, 6 Jul 2022 17:04:53 -0400 Message-Id: <20220706210454.30096-19-dpsmith@apertussolutions.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220706210454.30096-1-dpsmith@apertussolutions.com> References: <20220706210454.30096-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: 1657142329378100001 Content-Type: text/plain; charset="utf-8" The late pv helper is an example helper tool for late setup of Xenstore for= a domain that was created by the hypervisor using hyperlaunch. Signed-off-by: Daniel P. Smith Reviewed-by: Christopher Clark christopher.clark@starlab.io --- .gitignore | 1 + tools/helpers/Makefile | 11 ++ tools/helpers/builder-hypfs.c | 253 ++++++++++++++++++++++++++++++ tools/helpers/hypfs-helpers.h | 9 ++ tools/helpers/late-init-pv.c | 287 ++++++++++++++++++++++++++++++++++ tools/helpers/late-init-pv.h | 29 ++++ tools/helpers/xs-helpers.c | 117 ++++++++++++++ tools/helpers/xs-helpers.h | 27 ++++ 8 files changed, 734 insertions(+) create mode 100644 tools/helpers/builder-hypfs.c create mode 100644 tools/helpers/hypfs-helpers.h create mode 100644 tools/helpers/late-init-pv.c create mode 100644 tools/helpers/late-init-pv.h create mode 100644 tools/helpers/xs-helpers.c create mode 100644 tools/helpers/xs-helpers.h diff --git a/.gitignore b/.gitignore index 18ef56a780..0e5d5ceaab 100644 --- a/.gitignore +++ b/.gitignore @@ -206,6 +206,7 @@ tools/fuzz/x86_instruction_emulator/x86_emulate tools/fuzz/x86_instruction_emulator/x86-emulate.[ch] tools/helpers/init-xenstore-domain tools/helpers/xen-init-dom0 +tools/helpers/late-init-pv 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 8d78ab1e90..c32481202d 100644 --- a/tools/helpers/Makefile +++ b/tools/helpers/Makefile @@ -14,6 +14,7 @@ ifeq ($(CONFIG_ARM),y) PROGS +=3D init-dom0less endif endif +PROGS +=3D late-init-pv =20 XEN_INIT_DOM0_OBJS =3D xen-init-dom0.o init-dom-json.o $(XEN_INIT_DOM0_OBJS): CFLAGS +=3D $(CFLAGS_libxentoollog) @@ -36,6 +37,13 @@ $(INIT_DOM0LESS_OBJS): CFLAGS +=3D $(CFLAGS_libxenlight) $(INIT_DOM0LESS_OBJS): CFLAGS +=3D $(CFLAGS_libxenctrl) $(INIT_DOM0LESS_OBJS): CFLAGS +=3D $(CFLAGS_libxenevtchn) =20 +LATE_INIT_PV_OBJS =3D late-init-pv.o builder-hypfs.o xs-helpers.o +$(LATE_INIT_PV_OBJS): CFLAGS +=3D $(CFLAGS_libxentoollog) +$(LATE_INIT_PV_OBJS): CFLAGS +=3D $(CFLAGS_libxenguest) +$(LATE_INIT_PV_OBJS): CFLAGS +=3D $(CFLAGS_libxenctrl) +$(LATE_INIT_PV_OBJS): CFLAGS +=3D $(CFLAGS_libxenhypfs) +$(LATE_INIT_PV_OBJS): CFLAGS +=3D $(CFLAGS_libxenstore) + .PHONY: all all: $(PROGS) =20 @@ -48,6 +56,9 @@ init-xenstore-domain: $(INIT_XENSTORE_DOMAIN_OBJS) init-dom0less: $(INIT_DOM0LESS_OBJS) $(CC) $(LDFLAGS) -o $@ $(INIT_DOM0LESS_OBJS) $(LDLIBS_libxenctrl) $(LDLIB= S_libxenevtchn) $(LDLIBS_libxentoollog) $(LDLIBS_libxenstore) $(LDLIBS_libx= enlight) $(LDLIBS_libxenguest) $(LDLIBS_libxenforeignmemory) $(APPEND_LDFLA= GS) =20 +late-init-pv: $(LATE_INIT_PV_OBJS) + $(CC) $(LDFLAGS) -o $@ $(LATE_INIT_PV_OBJS) $(LDLIBS_libxentoollog) $(LDL= IBS_libxenstore) $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxen= hypfs) $(APPEND_LDFLAGS) + .PHONY: install install: all $(INSTALL_DIR) $(DESTDIR)$(LIBEXEC_BIN) diff --git a/tools/helpers/builder-hypfs.c b/tools/helpers/builder-hypfs.c new file mode 100644 index 0000000000..d123426cfa --- /dev/null +++ b/tools/helpers/builder-hypfs.c @@ -0,0 +1,253 @@ + +#include +#include +#include +#include + +#include "late-init-pv.h" + +/* general size for static path array */ +#define HYPFS_MAX_PATH 100 + +bool has_builder_hypfs(xenhypfs_handle *hdl, uint32_t domid) +{ + struct xenhypfs_dirent *ent; + char path[HYPFS_MAX_PATH]; + unsigned int n; + + snprintf(path, HYPFS_MAX_PATH, "/builder/%d", domid); + + ent =3D xenhypfs_readdir(hdl, path, &n); + if ( ent ) + { + free(ent); + return true; + } + + return false; +} + +static int read_hypfs_bool(xenhypfs_handle *fshdl, const char *path, bool = *val) +{ + struct xenhypfs_dirent *dirent; + void *raw_value; + + errno =3D 0; + + raw_value =3D xenhypfs_read_raw(fshdl, path, &dirent); + if ( raw_value =3D=3D NULL ) + { + errno =3D EIO; + return false; + } + + if ( dirent->type !=3D xenhypfs_type_bool ) + { + errno =3D EINVAL; + return false; + } + + *val =3D *(bool *)raw_value; + + free(raw_value); free(dirent); + return true; +} + +static bool read_hypfs_uint( + xenhypfs_handle *fshdl, const char *path, size_t sz, void *val) +{ + struct xenhypfs_dirent *dirent; + void *raw_value; + + errno =3D 0; + + raw_value =3D xenhypfs_read_raw(fshdl, path, &dirent); + if ( raw_value =3D=3D NULL ) + { + errno =3D EIO; + return false; + } + + if ( (dirent->type !=3D xenhypfs_type_uint) || + (dirent->size !=3D sz) ) + { + errno =3D EINVAL; + return false; + } + + switch ( sz ) + { + case sizeof(uint8_t): + *(uint8_t *)val =3D *(uint8_t *)raw_value; + break; + case sizeof(uint16_t): + *(uint16_t *)val =3D *(uint16_t *)raw_value; + break; + case sizeof(uint32_t): + *(uint32_t *)val =3D *(uint32_t *)raw_value; + break; + case sizeof(uint64_t): + *(uint64_t *)val =3D *(uint64_t *)raw_value; + break; + default: + free(raw_value); free(dirent); + errno =3D EINVAL; + return false; + } + + free(raw_value); free(dirent); + return true; +} + +static uint8_t read_hypfs_uint8(xenhypfs_handle *fshdl, const char *path) +{ + uint8_t value; + + if ( !read_hypfs_uint(fshdl, path, sizeof(value), &value) ) + { + fprintf(stderr, "error: unable to read uint8_t from %s \n", path); + return 0; + } + + return value; +} + +static uint16_t read_hypfs_uint16(xenhypfs_handle *fshdl, const char *path) +{ + uint16_t value; + + if ( !read_hypfs_uint(fshdl, path, sizeof(value), &value) ) + { + fprintf(stderr, "error: unable to read uint16_t from %s \n", path); + return 0; + } + + return value; +} + +static uint32_t read_hypfs_uint32(xenhypfs_handle *fshdl, const char *path) +{ + uint32_t value; + + if ( !read_hypfs_uint(fshdl, path, sizeof(value), &value) ) + { + fprintf(stderr, "error: unable to read uint32_t from %s \n", path); + return 0; + } + + return value; +} + +static uint64_t read_hypfs_uint64(xenhypfs_handle *fshdl, const char *path) +{ + uint64_t value; + + if ( !read_hypfs_uint(fshdl, path, sizeof(value), &value) ) + { + fprintf(stderr, "error: unable to read uint64_t from %s \n", path); + return 0; + } + + return value; +} + +static bool is_constructed(xenhypfs_handle *fshdl, uint32_t domid) +{ + char path[HYPFS_MAX_PATH]; + bool constructed; + + snprintf(path, HYPFS_MAX_PATH, "/builder/%d/constructed", domid); + + if ( !read_hypfs_bool(fshdl, path, &constructed) ) + { + fprintf(stderr, "error: unable to read constructed field\n"); + return false; + } + + return constructed; +} + +#define XS_PATH "/builder/%d/xenstore" +#define CONS_PATH "/builder/%d/devices/console" + +int read_hypfs_tree(xenhypfs_handle *hdl, struct domain_info *di) +{ + char path[HYPFS_MAX_PATH]; + + if ( !is_constructed(hdl, di->domid) ) + { + fprintf(stderr, "error: domain %d did not get constructed\n", + di->domid); + return -EEXIST; + } + + if ( !di->override_uuid ) + { + snprintf(path, HYPFS_MAX_PATH, "/builder/%d/uuid", di->domid); + di->uuid =3D xenhypfs_read(hdl, path); + } + + snprintf(path, HYPFS_MAX_PATH, "/builder/%d/ncpus", di->domid); + di->num_cpu =3D read_hypfs_uint32(hdl, path); + if ( errno !=3D 0 ) + { + fprintf(stderr, "error: unable to read number of cpus\n"); + return -errno; + } + + snprintf(path, HYPFS_MAX_PATH, "/builder/%d/mem_size", di->domid); + di->mem_info.target =3D read_hypfs_uint32(hdl, path); + if ( errno !=3D 0 ) + { + fprintf(stderr, "error: unable to read memory size\n"); + return -errno; + } + + snprintf(path, HYPFS_MAX_PATH, "/builder/%d/mem_max", di->domid); + di->mem_info.max =3D read_hypfs_uint32(hdl, path); + if ( errno !=3D 0 ) + { + fprintf(stderr, "error: unable to read max memory\n"); + return -errno; + } + + /* Xenstore */ + snprintf(path, HYPFS_MAX_PATH, XS_PATH "/evtchn", di->domid); + di->xs_info.evtchn_port =3D read_hypfs_uint32(hdl, path); + if ( errno !=3D 0 ) + { + fprintf(stderr, "error: unable to read xenstore event channel port= \n"); + return -errno; + } + + snprintf(path, HYPFS_MAX_PATH, XS_PATH "/mfn", di->domid); + di->xs_info.mfn =3D read_hypfs_uint64(hdl, path); + if ( errno !=3D 0 ) + { + fprintf(stderr, "error: unable to read xenstore page mfn\n"); + return -errno; + } + + /* Console */ + if ( di->cons_info.enable ) + { + snprintf(path, HYPFS_MAX_PATH, CONS_PATH "/evtchn", di->domid); + di->cons_info.evtchn_port =3D read_hypfs_uint32(hdl, path); + if ( errno !=3D 0 ) + { + fprintf(stderr, "error: unable to read xenstore event channel = port\n"); + return -errno; + } + + snprintf(path, HYPFS_MAX_PATH, CONS_PATH "/mfn", di->domid); + di->cons_info.mfn =3D read_hypfs_uint64(hdl, path); + if ( errno !=3D 0 ) + { + fprintf(stderr, "error: unable to read xenstore page mfn\n"); + return -errno; + } + } + + return 0; +} + diff --git a/tools/helpers/hypfs-helpers.h b/tools/helpers/hypfs-helpers.h new file mode 100644 index 0000000000..2b2de5967f --- /dev/null +++ b/tools/helpers/hypfs-helpers.h @@ -0,0 +1,9 @@ +#ifndef __HYPFS_HELPERS_H +#define __HYPFS_HELPERS_H + +#include "late-init-pv.h" + +bool has_builder_hypfs(xenhypfs_handle *hdl, uint32_t domid); +int read_hypfs_tree(xenhypfs_handle *hdl, struct domain_info *di); + +#endif diff --git a/tools/helpers/late-init-pv.c b/tools/helpers/late-init-pv.c new file mode 100644 index 0000000000..e1602be6d5 --- /dev/null +++ b/tools/helpers/late-init-pv.c @@ -0,0 +1,287 @@ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "hypfs-helpers.h" +#include "late-init-pv.h" +#include "xs-helpers.h" + +static struct option options[] =3D { + { "uuid", 1, NULL, 'u' }, + { "console", 0, NULL, 'c' }, + { "force", 0, NULL, 'f' }, + { "domain", 1, NULL, 'd' }, + { "verbose", 0, NULL, 'v' }, + { NULL, 0, NULL, 0 } +}; + +static void usage(void) +{ + fprintf(stderr, +"Usage:\n" +"\n" +"late-init-pv \n" +"\n" +"where options may include:\n" +"\n" +" --uuid override the UUID to use for the domain\n" +" --console configure the console\n" +" --force for @introduceDomain even if xenstore entries = exist\n" +" --domain domain id of the domain to be initialized\n" +" -v[v[v]] verbosity constructing xenstore tree\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 create_xs_entries( + struct xs_handle *xsh, uint16_t curr_domid, struct domain_info *di) +{ + char value[16]; + struct xs_permissions perms[2] =3D { + {.id =3D curr_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, "%d", di->mem_info.target); + XS_DOM_PERM(xsh, di->domid, "memory/target", value); + + if ( di->mem_info.max ) + snprintf(value, 16, "%d", di->mem_info.max); + else + snprintf(value, 16, "%d", di->mem_info.target); + XS_DOM_PERM(xsh, di->domid, "memory/static-max", value); + + XS_DOM_PERM(xsh, di->domid, "store", ""); + snprintf(value, 16, "%d", di->xs_info.evtchn_port); + XS_DOM_PERM(xsh, di->domid, "store/port", value); + + snprintf(value, 16, "%ld", di->xs_info.mfn); + XS_DOM_PERM(xsh, di->domid, "store/ring-ref", value); + + if ( di->cons_info.enable ) + { + 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", + di->cons_info.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", di->cons_info.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, "%d", di->cons_info.evtchn_port); + XS_DIR_PERM(xsh, fe_path, "port", value); + + snprintf(value, 16, "%ld", di->cons_info.mfn); + XS_DIR_PERM(xsh, fe_path, "ring-ref", value); + + } + + 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 xs_handle *xsh, struct domain_info *di) +{ + xc_interface *xch =3D xc_interface_open(0, 0, 0); + xen_pfn_t con_mfn =3D 0L; + /*xc_dom_gnttab_seed will do nothing of front =3D=3D back */ + uint32_t con_domid =3D di->domid; + int ret; + + /* console */ + if ( di->cons_info.enable ) + { + con_domid =3D di->cons_info.be_domid; + con_mfn =3D di->cons_info.mfn; + } + + ret =3D xc_dom_gnttab_seed(xch, di->domid, di->is_hvm, con_mfn, + di->xs_info.mfn, con_domid, di->xs_info.be_domid); + if ( ret !=3D 0 ) + { + fprintf(stderr, "error (%d) setting up grant tables for dom%d\n", + ret, di->domid); + xc_interface_close(xch); + return false; + } + + xc_interface_close(xch); + + return xs_introduce_domain(xsh, di->domid, di->xs_info.mfn, + di->xs_info.evtchn_port); +} + +int main(int argc, char** argv) +{ + int opt, rv; + bool force =3D false; + struct xs_handle *xsh =3D NULL; + xenhypfs_handle *xhfs =3D NULL; + xentoollog_level minmsglevel =3D XTL_PROGRESS; + xentoollog_logger *logger =3D NULL; + struct domain_info di =3D { .domid =3D ~0 }; + + while ( (opt =3D getopt_long(argc, argv, "cfd:v", options, NULL)) !=3D= -1 ) + { + switch ( opt ) + { + case 'u': + di.override_uuid =3D true; + di.uuid =3D optarg; + break; + case 'c': + di.cons_info.enable =3D true; + break; + case 'f': + force =3D true; + break; + case 'd': + di.domid =3D strtol(optarg, NULL, 10); + break; + case 'v': + if ( minmsglevel ) + minmsglevel--; + break; + default: + usage(); + return 2; + } + } + + if ( optind !=3D argc || di.domid =3D=3D ~0 ) + { + usage(); + return 1; + } + + logger =3D (xentoollog_logger *)xtl_createlogger_stdiostream(stderr, + minmsglevel= , 0); + + xhfs =3D xenhypfs_open(logger, 0); + if ( !xhfs ) + { + fprintf(stderr, "error: unable to acces xen hypfs\n"); + rv =3D 2; + goto out; + } + + if ( !has_builder_hypfs(xhfs, di.domid) ) + { + fprintf(stderr, "error: hypfs entry for domain %d not present\n", + di.domid); + rv =3D 3; + goto out; + } + + if ( read_hypfs_tree(xhfs, &di) !=3D 0 ) + { + fprintf(stderr, "error: unable to parse hypfs for domain %d\n", + di.domid); + rv =3D 4; + goto out; + } + + xsh =3D xs_open(0); + if ( xsh =3D=3D NULL ) + { + fprintf(stderr, "error: unable to connect to xenstored\n"); + rv =3D 5; + goto out; + } + + if ( xs_is_domain_introduced(xsh, di.domid) ) + { + if ( !force ) + { + fprintf(stderr, "error: domain %d already introduced\n", di.do= mid); + rv =3D 6; + goto out; + } + else + { + fprintf(stderr, "warning: re-introducting domain %d\n", di.dom= id); + } + } + + /* TODO: hardcdoding local domain to 0 for testing purposes */ + if ( (rv =3D create_xs_entries(xsh, 0, &di)) !=3D 0 ) + { + fprintf(stderr, "error(%d): unable create xenstore entries\n", rv); + rv =3D 7; + goto out; + } + + init_domain(xsh, &di); + rv =3D 0; + +out: + if ( xsh ) + xs_close(xsh); + + if ( xhfs ) + xenhypfs_close(xhfs); + + if ( logger ) + xtl_logger_destroy(logger); + + return rv; +} diff --git a/tools/helpers/late-init-pv.h b/tools/helpers/late-init-pv.h new file mode 100644 index 0000000000..5d66e7870f --- /dev/null +++ b/tools/helpers/late-init-pv.h @@ -0,0 +1,29 @@ +#ifndef __LATE_INIT_PV_H +#define __LATE_INIT_PV_H + +struct domain_info { + uint16_t domid; + bool is_hvm; + bool override_uuid; + const char *uuid; + uint32_t num_cpu; + uint32_t max_cpu; + struct { + uint32_t target; + uint32_t max; + uint32_t video; + } mem_info; + struct { + uint16_t be_domid; + uint32_t evtchn_port; + uint64_t mfn; + } xs_info; + struct { + bool enable; + uint16_t be_domid; + uint32_t evtchn_port; + uint64_t mfn; + } cons_info; +}; + +#endif diff --git a/tools/helpers/xs-helpers.c b/tools/helpers/xs-helpers.c new file mode 100644 index 0000000000..a4d2bebbbd --- /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 0000000000..f57fcab843 --- /dev/null +++ b/tools/helpers/xs-helpers.h @@ -0,0 +1,27 @@ +#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.20.1