From nobody Wed Dec 4 19:24:39 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=1729471715; cv=pass; d=zohomail.com; s=zohoarc; b=YLyLQikRb89MtwtbtvEE4KcS/nOZhb53HaJXSKYBPPwJKq8wnLtd9mtAWkK0S1c208U3H2mve19AxUzbGg1Q375hirc21QhKZrM6YypH4zBM95FKfoM+dQj/JFnoLtY9c1TSuomK6a5DjeMd+//vF1k5QXKmqMwPXEoN+tgSJco= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1729471715; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=rCqjXfRhQzYVNQ0/zCmbI25PcWcrpjQT5dqAU64Gu4k=; b=lixrpWzg6ESiQ7LAvAung2tGsKsD7g9K9isLstCFBtOimsvwhh+eLcWfTTwXbJ8YYHa977Jkr4CqmQm9tAL4gtUwiU/10gdkag6tp7Ud6wh4/jnSHEIjAwn8b18G8+d00wnLd2Nmm49NLdhzLxWVfRZ1rZz41EwCJG+8exQdCtk= 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 1729471715095779.62115068965; Sun, 20 Oct 2024 17:48:35 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.822902.1236822 (Exim 4.92) (envelope-from ) id 1t2gam-0001iG-7X; Mon, 21 Oct 2024 00:48:16 +0000 Received: by outflank-mailman (output) from mailman id 822902.1236822; Mon, 21 Oct 2024 00:48:16 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t2gam-0001i9-46; Mon, 21 Oct 2024 00:48:16 +0000 Received: by outflank-mailman (input) for mailman id 822902; Mon, 21 Oct 2024 00:48:15 +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 1t2gal-0001i1-5z for xen-devel@lists.xenproject.org; Mon, 21 Oct 2024 00:48:15 +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 265c702e-8f46-11ef-a0be-8be0dac302b0; Mon, 21 Oct 2024 02:48:14 +0200 (CEST) Received: by mx.zohomail.com with SMTPS id 1729471600038731.5465299032828; Sun, 20 Oct 2024 17:46:40 -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: 265c702e-8f46-11ef-a0be-8be0dac302b0 ARC-Seal: i=1; a=rsa-sha256; t=1729471602; cv=none; d=zohomail.com; s=zohoarc; b=R5C/6c72qx+Pv8oreNCXC4DXvp/5JJnmlv/xclSb5BsT0ZdTpN3y4h2M4kFMirySA5JTOFHKNFUEiqU4feYkIjr6+Jv3yU731SSWY6rZRItFchQFW7nv1XxJzyx04RhbxJM6LM70y8a2KbRz6lJWsTBXm1/T6aQXEK0jNGFOGB0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1729471602; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=rCqjXfRhQzYVNQ0/zCmbI25PcWcrpjQT5dqAU64Gu4k=; b=lPzVPPQ3chk7ME56/x00Apav5fW5vjhbd9aysGtiPFmTQQQgCmw4zRHqbh3/aK3TFRSt8oDJaAI2WleAUMcdEpsLrAPljTUkARA9g8vQJ2jIK4384oOfiZarTWy9X2O+D1sGY0CJ3BO+FD98oUj7QobgJ6LPfFhp0/+t87tVwCU= 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=1729471602; 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=rCqjXfRhQzYVNQ0/zCmbI25PcWcrpjQT5dqAU64Gu4k=; b=bf4RE0epFdDbi2YeS7igOMlUsKCKEolaFHUl/BiUULa0RFPS60biKwgRqtVSnA5H YYniQlmasSFzxiSb40XP/+DNeUn1nK/feS03dbKzNI+6lMbefbF+oWG/37nvQBrukCw td96MHar5aOqNCcxHU5R3FRLQd9A4tdidC5JQiP8= From: "Daniel P. Smith" To: xen-devel@lists.xenproject.org Cc: "Daniel P. Smith" , jason.andryuk@amd.com, christopher.w.clark@gmail.com, stefano.stabellini@amd.com, Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH v7 14/38] x86/boot: convert xsm policy loading to struct boot_module Date: Sun, 20 Oct 2024 20:45:49 -0400 Message-Id: <20241021004613.18793-15-dpsmith@apertussolutions.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20241021004613.18793-1-dpsmith@apertussolutions.com> References: <20241021004613.18793-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: 1729471715605116600 Content-Type: text/plain; charset="utf-8" Iterate through the unclaimed boot modules to see if any are an XSM FLASK policy. If one is located, mark it as an xsm policy. To assist with looking up the index of the xsm policy in the boot module ar= ray, an iterator is provided. Signed-off-by: Daniel P. Smith --- Changes since v6: - converted boot module walk over to for each helper - slight reword of commit message - merged the interator patch with its first usage by XSM - corrected the short-circuit return value for Xen in the interator - dropped R-b due to merging with patch not approved. Changes since v5: - replaced bootstrap_map with bootstrap_map_bm - make init function definitions consistent in dropping const on *bi --- xen/arch/x86/include/asm/bootinfo.h | 30 ++++++++++++++++++++++++++++- xen/arch/x86/setup.c | 2 +- xen/include/xsm/xsm.h | 11 +++++++---- xen/xsm/xsm_core.c | 17 ++++++++++++---- xen/xsm/xsm_policy.c | 20 +++++++++---------- 5 files changed, 59 insertions(+), 21 deletions(-) diff --git a/xen/arch/x86/include/asm/bootinfo.h b/xen/arch/x86/include/asm= /bootinfo.h index e470df48700d..3ca56454c4d7 100644 --- a/xen/arch/x86/include/asm/bootinfo.h +++ b/xen/arch/x86/include/asm/bootinfo.h @@ -21,6 +21,7 @@ enum bootmod_type { BOOTMOD_KERNEL, BOOTMOD_RAMDISK, BOOTMOD_MICROCODE, + BOOTMOD_XSM_POLICY, }; =20 struct boot_module { @@ -94,8 +95,35 @@ static inline struct boot_module *__init next_boot_modul= e_by_type( #define boot_module_index(bi, bm) \ (unsigned int)(bm - &bi->mods[0]) =20 -#endif /* X86_BOOTINFO_H */ +/* + * next_boot_module_index: + * Finds the next boot module of type t, starting at array index start. + * + * Returns: + * Success - index in boot_module array + * Failure - a value greater than MAX_NR_BOOTMODS + */ +static inline unsigned int __init next_boot_module_index( + const struct boot_info *bi, enum bootmod_type t, unsigned int start) +{ + unsigned int i; + + if ( t =3D=3D BOOTMOD_XEN ) + return bi->nr_modules; + + for ( i =3D start; i < bi->nr_modules; i++ ) + { + if ( bi->mods[i].type =3D=3D t ) + return i; + } + + return MAX_NR_BOOTMODS + 1; +} + +#define first_boot_module_index(bi, t) \ + next_boot_module_index(bi, t, 0) =20 +#endif /* X86_BOOTINFO_H */ /* * Local variables: * mode: C diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 272d5a725c54..ed1d89ad4bb4 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -1882,7 +1882,7 @@ void asmlinkage __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_multiboot_init(module_map, bi); =20 /* * IOMMU-related ACPI table parsing may require some of the system dom= ains diff --git a/xen/include/xsm/xsm.h b/xen/include/xsm/xsm.h index 627c0d2731af..f155d10e718c 100644 --- a/xen/include/xsm/xsm.h +++ b/xen/include/xsm/xsm.h @@ -17,7 +17,10 @@ =20 #include #include -#include + +#ifdef CONFIG_MULTIBOOT +#include +#endif =20 /* policy magic number (defined by XSM_MAGIC) */ typedef uint32_t xsm_magic_t; @@ -779,9 +782,9 @@ static inline int xsm_argo_send(const struct domain *d,= const struct domain *t) =20 #ifdef CONFIG_MULTIBOOT int xsm_multiboot_init( - unsigned long *module_map, const multiboot_info_t *mbi); + unsigned long *module_map, struct boot_info *bi); int xsm_multiboot_policy_init( - unsigned long *module_map, const multiboot_info_t *mbi, + unsigned long *module_map, struct boot_info *bi, void **policy_buffer, size_t *policy_size); #endif =20 @@ -829,7 +832,7 @@ static const inline struct xsm_ops *silo_init(void) =20 #ifdef CONFIG_MULTIBOOT static inline int xsm_multiboot_init ( - unsigned long *module_map, const multiboot_info_t *mbi) + unsigned long *module_map, struct boot_info *bi) { return 0; } diff --git a/xen/xsm/xsm_core.c b/xen/xsm/xsm_core.c index eaa028109bde..234b39de7a1d 100644 --- a/xen/xsm/xsm_core.c +++ b/xen/xsm/xsm_core.c @@ -21,6 +21,7 @@ #ifdef CONFIG_XSM =20 #ifdef CONFIG_MULTIBOOT +#include #include #endif =20 @@ -140,7 +141,7 @@ static int __init xsm_core_init(const void *policy_buff= er, size_t policy_size) =20 #ifdef CONFIG_MULTIBOOT int __init xsm_multiboot_init( - unsigned long *module_map, const multiboot_info_t *mbi) + unsigned long *module_map, struct boot_info *bi) { int ret =3D 0; void *policy_buffer =3D NULL; @@ -150,18 +151,26 @@ int __init xsm_multiboot_init( =20 if ( XSM_MAGIC ) { - ret =3D xsm_multiboot_policy_init(module_map, mbi, &policy_buffer, + ret =3D xsm_multiboot_policy_init(module_map, bi, &policy_buffer, &policy_size); if ( ret ) { - bootstrap_map(NULL); + bootstrap_map_bm(NULL); printk(XENLOG_ERR "Error %d initializing XSM policy\n", ret); return -EINVAL; } } =20 ret =3D xsm_core_init(policy_buffer, policy_size); - bootstrap_map(NULL); + if ( ret =3D=3D 0 ) + { + int idx =3D first_boot_module_index(bi, BOOTMOD_XSM_POLICY); + + /* If the policy was loaded from a boot module, mark it consumed */ + if ( idx >=3D 0 ) + bi->mods[idx].consumed =3D true; + } + bootstrap_map_bm(NULL); =20 return 0; } diff --git a/xen/xsm/xsm_policy.c b/xen/xsm/xsm_policy.c index 8dafbc93810f..9fb8563eb571 100644 --- a/xen/xsm/xsm_policy.c +++ b/xen/xsm/xsm_policy.c @@ -21,6 +21,7 @@ #include #ifdef CONFIG_MULTIBOOT #include +#include #include #endif #include @@ -31,26 +32,22 @@ =20 #ifdef CONFIG_MULTIBOOT int __init xsm_multiboot_policy_init( - unsigned long *module_map, const multiboot_info_t *mbi, + unsigned long *module_map, struct boot_info *bi, void **policy_buffer, size_t *policy_size) { - int i; - module_t *mod =3D (module_t *)__va(mbi->mods_addr); int rc =3D 0; u32 *_policy_start; unsigned long _policy_len; + struct boot_module *bm; =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-- ) + for_each_boot_module(bi, bm, BOOTMOD_UNKNOWN) { - if ( !test_bit(i, module_map) ) - continue; - - _policy_start =3D bootstrap_map(mod + i); - _policy_len =3D mod[i].mod_end; + _policy_start =3D bootstrap_map_bm(bm); + _policy_len =3D bm->size; =20 if ( (xsm_magic_t)(*_policy_start) =3D=3D XSM_MAGIC ) { @@ -60,12 +57,13 @@ int __init xsm_multiboot_policy_init( printk("Policy len %#lx, start at %p.\n", _policy_len,_policy_start); =20 - __clear_bit(i, module_map); + __clear_bit(boot_module_index(bi, bm), module_map); + bm->type =3D BOOTMOD_XSM_POLICY; break; =20 } =20 - bootstrap_map(NULL); + bootstrap_map_bm(NULL); } =20 return rc; --=20 2.30.2