From nobody Fri May 17 04:59:59 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=1653378133; cv=pass; d=zohomail.com; s=zohoarc; b=k7qRJFw02uXYZyW8MUYFIeJw3Rs2DSZ3o0fce4avPNkk9JlVq6iSUNJyM2k+WdukJY1xppXt88BqoPeXYrRvLStw+ErUdllslfda5EE5YzcDwBdbxuP0hNwmoyG+Lm7ua5MNKqfvquhm9wiU0UOoSvyiKkLBa4lm8aX4joWdzTc= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653378133; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=98v0UwvujcfL6C9tx4e5oAX1065dOOeYtIhzPpau0Tw=; b=GQWNdwEnqQNMRknj21OiWgQ9yoRJkcC7O3aj5VTaQC7nMx7QPoQNQuZ7fxfue3+g8+1eU8Av6PxRa1u3aKRLE5eJ3kvMlIwa3qQB9RWRy/Ql1PoSEGoyQ5slKua3iBZXrsmYfL3c6SJMkx0HSo77vieZtj1tH7mOsUZJGsbIRIQ= 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 1653378133402561.2775319532044; Tue, 24 May 2022 00:42:13 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.336194.560515 (Exim 4.92) (envelope-from ) id 1ntPAk-00045X-GJ; Tue, 24 May 2022 07:41:42 +0000 Received: by outflank-mailman (output) from mailman id 336194.560515; Tue, 24 May 2022 07:41:42 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ntPAk-00045Q-Cf; Tue, 24 May 2022 07:41:42 +0000 Received: by outflank-mailman (input) for mailman id 336194; Tue, 24 May 2022 07:41:40 +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 1ntP6E-0003DA-QQ for xen-devel@lists.xenproject.org; Tue, 24 May 2022 07:37:02 +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 abe7e49f-daae-11ec-837e-e5687231ffcc; Mon, 23 May 2022 17:40:30 +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 1653320431089155.22680033498602; Mon, 23 May 2022 08:40:31 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: abe7e49f-daae-11ec-837e-e5687231ffcc ARC-Seal: i=1; a=rsa-sha256; t=1653320432; cv=none; d=zohomail.com; s=zohoarc; b=QuXS1HEj0dvBJR2U8ihqk8BbN7rGuPNp/rtmwBU+gH2/qXMXK5PT76NWyjeLHhuQZBbZbpBDFfoSODSLdAiIQjTy24l35m5/Fm0cWbMipDhAw4anJj1yB94Ni/n9h5tFse0yTg1l8zLQ+mqwjmn57fgVtt8oP+VUCavy4GI8VoM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653320432; h=Content-Transfer-Encoding:Cc:Date:From:MIME-Version:Message-ID:Subject:To; bh=98v0UwvujcfL6C9tx4e5oAX1065dOOeYtIhzPpau0Tw=; b=kZeAUtQNwaAvJEu13sFORdPqc7Soy50h7EmXs3G5DlLoaqHnIqTzoBRxueR7g71kFGpO/BMdYIvkii1aoJP/gbCWj7xkItT95rz8h3SnWbpnR4bTvikCQJacAqvVWaZxRr1QowMYBpOcTYBnsPAW9q1ffD7QmK3syozF1biZlmw= 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=1653320432; s=zoho; d=apertussolutions.com; i=dpsmith@apertussolutions.com; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-Id:Message-Id:MIME-Version:Content-Transfer-Encoding:Reply-To; bh=98v0UwvujcfL6C9tx4e5oAX1065dOOeYtIhzPpau0Tw=; b=BQKPur29NhqC4YNELGVJO0XHUthYhshfF2F2vX5d8boDvAexBYDFDGJULF95kyca yNBi92rvLbiI4/ssoIs0fIOtq6TSjLT6ZOFw76bQd5a+BrW4uzeWmnrOSCQXNPnPEdA V2iyTrkldPiZbwX/EnZNICAywEd94uXHdo0o8Yas= From: "Daniel P. Smith" To: xen-devel@lists.xenproject.org, "Daniel P. Smith" Cc: scott.davis@starlab.io, jandryuk@gmail.com, christopher.clark@starlab.io, Daniel De Graaf Subject: [PATCH] xsm: refactor and optimize policy loading Date: Mon, 23 May 2022 11:40:24 -0400 Message-Id: <20220523154024.1947-1-dpsmith@apertussolutions.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External X-ZohoMail-DKIM: pass (identity dpsmith@apertussolutions.com) X-ZM-MESSAGEID: 1653378134216100005 Content-Type: text/plain; charset="utf-8" It is possible to select a few different build configurations that results = in the unnecessary walking of the boot module list looking for a policy module. This specifically occurs when the flask policy is enabled but either the du= mmy or the SILO policy is selected as the enforcing policy. This is not ideal f= or configurations like hyperlaunch and dom0less when there could be a number of modules to be walked or unnecessary device tree lookups This patch does two things, it moves all policy initialization logic under = the xsm_XXXX_policy_init() functions and introduces the init_policy flag. The init_policy flag will be set based on which enforcing policy is selected and gates whether the boot modules should be checked for a policy file. Signed-off-by: Daniel P. Smith --- xen/xsm/xsm_core.c | 30 +++++++++++++++++++----------- xen/xsm/xsm_policy.c | 21 +++++++++++++++++++-- 2 files changed, 38 insertions(+), 13 deletions(-) diff --git a/xen/xsm/xsm_core.c b/xen/xsm/xsm_core.c index 2286a502e3..0dfc970283 100644 --- a/xen/xsm/xsm_core.c +++ b/xen/xsm/xsm_core.c @@ -55,19 +55,35 @@ static enum xsm_bootparam __initdata xsm_bootparam =3D XSM_BOOTPARAM_DUMMY; #endif =20 +static bool __initdata init_policy =3D +#ifdef CONFIG_XSM_FLASK_DEFAULT + true; +#else + false; +#endif + static int __init cf_check parse_xsm_param(const char *s) { int rc =3D 0; =20 if ( !strcmp(s, "dummy") ) + { xsm_bootparam =3D XSM_BOOTPARAM_DUMMY; + init_policy =3D false; + } #ifdef CONFIG_XSM_FLASK else if ( !strcmp(s, "flask") ) + { xsm_bootparam =3D XSM_BOOTPARAM_FLASK; + init_policy =3D true; + } #endif #ifdef CONFIG_XSM_SILO else if ( !strcmp(s, "silo") ) + { xsm_bootparam =3D XSM_BOOTPARAM_SILO; + init_policy =3D false; + } #endif else rc =3D -EINVAL; @@ -80,14 +96,6 @@ static int __init xsm_core_init(const void *policy_buffe= r, size_t policy_size) { const struct xsm_ops *ops =3D NULL; =20 -#ifdef CONFIG_XSM_FLASK_POLICY - if ( policy_size =3D=3D 0 ) - { - policy_buffer =3D xsm_flask_init_policy; - policy_size =3D xsm_flask_init_policy_size; - } -#endif - if ( xsm_ops_registered !=3D XSM_OPS_UNREGISTERED ) { printk(XENLOG_ERR @@ -148,11 +156,11 @@ int __init xsm_multiboot_init( =20 printk("XSM Framework v" XSM_FRAMEWORK_VERSION " initialized\n"); =20 - if ( XSM_MAGIC ) + if ( init_policy && XSM_MAGIC ) { ret =3D xsm_multiboot_policy_init(module_map, mbi, &policy_buffer, &policy_size); - if ( ret ) + if ( ret !=3D 0 ) { bootstrap_map(NULL); printk(XENLOG_ERR "Error %d initializing XSM policy\n", ret); @@ -176,7 +184,7 @@ int __init xsm_dt_init(void) =20 printk("XSM Framework v" XSM_FRAMEWORK_VERSION " initialized\n"); =20 - if ( XSM_MAGIC ) + if ( init_policy && XSM_MAGIC ) { ret =3D xsm_dt_policy_init(&policy_buffer, &policy_size); if ( ret ) diff --git a/xen/xsm/xsm_policy.c b/xen/xsm/xsm_policy.c index 8dafbc9381..0e32418999 100644 --- a/xen/xsm/xsm_policy.c +++ b/xen/xsm/xsm_policy.c @@ -8,7 +8,7 @@ * Contributors: * Michael LeMay, * George Coker, - * =20 + * * 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. @@ -36,10 +36,17 @@ int __init xsm_multiboot_policy_init( { int i; module_t *mod =3D (module_t *)__va(mbi->mods_addr); - int rc =3D 0; + int rc =3D -ENOENT; u32 *_policy_start; unsigned long _policy_len; =20 +#ifdef CONFIG_XSM_FLASK_POLICY + /* Initially set to builtin policy, overriden if boot module is found.= */ + *policy_buffer =3D (void *)xsm_flask_init_policy; + *policy_size =3D xsm_flask_init_policy_size; + rc =3D 0; +#endif + /* * Try all modules and see whichever could be the binary policy. * Adjust module_map for the module that is the binary policy. @@ -61,6 +68,7 @@ int __init xsm_multiboot_policy_init( _policy_len,_policy_start); =20 __clear_bit(i, module_map); + rc =3D 0; break; =20 } @@ -79,7 +87,16 @@ int __init xsm_dt_policy_init(void **policy_buffer, size= _t *policy_size) paddr_t paddr, len; =20 if ( !mod || !mod->size ) +#ifdef CONFIG_XSM_FLASK_POLICY + { + *policy_buffer =3D (void *)xsm_flask_init_policy; + *policy_size =3D xsm_flask_init_policy_size; return 0; + } +#else + /* No policy was loaded */ + return -ENOENT; +#endif =20 paddr =3D mod->start; len =3D mod->size; --=20 2.20.1