From nobody Thu May 2 08:29:41 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; 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; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1626093472; cv=none; d=zohomail.com; s=zohoarc; b=aBZWmb73HOa+uCr3fa+3QhZd5fbeNxV9IrnvEfVarxXLYMw0hn5xPhlMDhmwu2/dikRaEXR/NMCcBzbEptgjLG6Q99sl20fTff+9Ius6cl/VWHZfcA2jIoVhWIHLIIOkzcNRDcdrl8HbfwwQcCWMWlS3i6yKKWvS6oPNDyz2Wl8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1626093472; 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=6M8gV7S/RMEzQ+mA8fh7+n2qgQ2Q2znYqk2Q8bcKqrY=; b=LDFNBjfZGJJaRS6bx+bhO4ZaLIsurr7M+He5WRIwNrYBHJN2ZaRMlQch7Dz0MFvphuP16N+vQMUrUNbSOphH5H51Cq2t13/yzB9oTAW0nwkL5N44GuS+Au6E5ZZia7Q+Yobge6aie1SxOljuHaRZwM019cku2SkUzfX9cVNldl8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1626093472012293.35792881477255; Mon, 12 Jul 2021 05:37:52 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.154543.285548 (Exim 4.92) (envelope-from ) id 1m2vBV-0002Ov-Nm; Mon, 12 Jul 2021 12:37:17 +0000 Received: by outflank-mailman (output) from mailman id 154543.285548; Mon, 12 Jul 2021 12:37: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 1m2vBV-0002Oo-JS; Mon, 12 Jul 2021 12:37:17 +0000 Received: by outflank-mailman (input) for mailman id 154543; Mon, 12 Jul 2021 12:37:16 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1m2vBT-0002Oi-VY for xen-devel@lists.xenproject.org; Mon, 12 Jul 2021 12:37:16 +0000 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id e25a4aae-e30d-11eb-86e8-12813bfff9fa; Mon, 12 Jul 2021 12:37:14 +0000 (UTC) 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: e25a4aae-e30d-11eb-86e8-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1626093434; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=k6yCF3T5XWJfLXzW7043PzCL0bWNDFETlXEvaGiXeQI=; b=Mx5NngajeUQ+tRhOgCFheSD9bDaaS3a41tbwd8/xlJuNZvi2iQqquAob GWHvU/L+DFUNtbSkcorGnEUCKOS0+ndad5V86FE3Nkxg1HWqZzcPgTZVX 5LQjFXcqa1CDw3zx71Q5xtSuVdx1pTwMluqNab/ATzb3S6NY/LBzbkucK w=; Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: S42uZYb4tjTVEfpJY2qXTLYJT73DZlIDRDo4uXjbiWZkMho3BfINUeu30cveTzvcjbAYu3bauw NOKJ9BQQldwWP6ndnvmRmqwd79cUxBC//xbjw5KCzZQSBHJ/BhNuNfCMqjNYqY2pr+bGVJPf2Q PVdaOOHdPHzMgR8IbPhdjnbaJwsaG5d4N5TX56/yBKJQylLPesiwul3nL2zLhzk4xAi3UQcs2S zmVklq3UAKrH7eV38zdqbPRmcUp/6yUewc0JR8XYCizLhnKzrZDQr6IGEs/zBeJuaDUti+y0fi Y34= X-SBRS: 5.1 X-MesageID: 48438713 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:OVPStaBn4mBiKN7lHemW55DYdb4zR+YMi2TC1yhKKCC9Ffbo7/ xG/c5rrCMc5wxhO03I9eruBEDEewK5yXcX2/h2AV7BZniFhILAFugLhuGOrwEIWReOkdK1vZ 0QCJSWY+eRMbEVt6jHCXGDYrMd/OU= X-IronPort-AV: E=Sophos;i="5.84,232,1620705600"; d="scan'208";a="48438713" From: Andrew Cooper To: Xen-devel CC: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Bob Eshleman , Alistair Francis , Connor Davis , "Daniel P . Smith" Subject: [PATCH 0.5/6] xen: Implement xen/alternative-call.h for use in common code Date: Mon, 12 Jul 2021 13:36:31 +0100 Message-ID: <20210712123631.3022-1-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20210617233918.10095-2-dpsmith@apertussolutions.com> References: <20210617233918.10095-2-dpsmith@apertussolutions.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1626093474067100001 The alternative call infrastructure is x86-only for now, but the common iom= mu code has a variant and more common code wants to use the infrastructure. Introduce CONFIG_ALTERNATIVE_CALL and a conditional implemetnation so common code can use the optimisation when available, without requiring all architectures to implement no-op stubs. Write some documentation, which was thus far entirely absent, covering the requirements for an architecture to implement this optimsiation, and how to use the infrastructure in general code. Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Wei Liu CC: Stefano Stabellini CC: Julien Grall CC: Volodymyr Babchuk CC: Bob Eshleman CC: Alistair Francis CC: Connor Davis CC: Daniel P. Smith This is a pre-requisite to "xsm: refactor xsm_ops handling" to avoid breaki= ng the ARM build. Build test for the XSM code: diff --git a/xen/xsm/xsm_core.c b/xen/xsm/xsm_core.c index 5eab21e1b168..592074e8f41c 100644 --- a/xen/xsm/xsm_core.c +++ b/xen/xsm/xsm_core.c @@ -195,6 +195,16 @@ bool __init has_xsm_magic(paddr_t start) } #endif +#include +struct foo { + int (*bar)(void *); +} foo __alt_call_maybe_initdata; + +int test_alternative_call(void) +{ + return alternative_call(foo.bar, NULL); +} + int __init register_xsm(struct xsm_operations *ops) { if ( verify(ops) ) --- xen/arch/x86/Kconfig | 1 + xen/common/Kconfig | 3 ++ xen/include/xen/alternative-call.h | 65 ++++++++++++++++++++++++++++++++++= ++++ 3 files changed, 69 insertions(+) create mode 100644 xen/include/xen/alternative-call.h diff --git a/xen/arch/x86/Kconfig b/xen/arch/x86/Kconfig index 9b164db64187..c91cdd83dc8a 100644 --- a/xen/arch/x86/Kconfig +++ b/xen/arch/x86/Kconfig @@ -9,6 +9,7 @@ config X86 select ARCH_SUPPORTS_INT128 select CORE_PARKING select HAS_ALTERNATIVE + select ALTERNATIVE_CALL select HAS_COMPAT select HAS_CPUFREQ select HAS_EHCI diff --git a/xen/common/Kconfig b/xen/common/Kconfig index 0ddd18e11af3..1594ce4e7313 100644 --- a/xen/common/Kconfig +++ b/xen/common/Kconfig @@ -25,6 +25,9 @@ config GRANT_TABLE config HAS_ALTERNATIVE bool =20 +config ALTERNATIVE_CALL + bool + config HAS_COMPAT bool =20 diff --git a/xen/include/xen/alternative-call.h b/xen/include/xen/alternati= ve-call.h new file mode 100644 index 000000000000..11d1c2606818 --- /dev/null +++ b/xen/include/xen/alternative-call.h @@ -0,0 +1,65 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef XEN_ALTERNATIVE_CALL +#define XEN_ALTERNATIVE_CALL + +/* + * Some subsystems in Xen may have multiple implementions, which can be + * resolved to a single implementation at boot time. By default, this will + * result in the use of function pointers. + * + * Some architectures may have mechanisms for dynamically modifying .text. + * Using this mechnaism, function pointers can be converted to direct calls + * which are typically more efficient at runtime. + * + * For architectures to support: + * + * - Implement alternative_{,v}call() in asm/alternative.h. Code generati= on + * requirements are to emit a function pointer call at build time, and s= tash + * enough metadata to simplify the call at boot once the implementation = has + * been resolved. + * - Select ALTERNATIVE_CALL in Kconfig. + * + * To use: + * + * Consider the following simplified example. + * + * 1) struct foo_ops __alt_call_maybe_initdata ops; + * + * 2) struct foo_ops __alt_call_maybe_initconst foo_a_ops =3D { ... }; + * struct foo_ops __alt_call_maybe_initconst foo_b_ops =3D { ... }; + * + * void foo_init(void) + * { + * ... + * if ( use_impl_a ) + * ops =3D *foo_a_ops; + * else if ( use_impl_b ) + * ops =3D *foo_b_ops; + * ... + * } + * + * 3) alternative_call(ops.bar, ...); + * + * There needs to a single ops object (1) which will eventually contain the + * function pointers. This should be populated in foo's init() function (= 2) + * by one of the available implementations. To call functions, use + * alternative_{,v}call() referencing the main ops object (3). + */ + +#ifdef CONFIG_ALTERNATIVE_CALL + +#include + +#define __alt_call_maybe_initdata __initdata +#define __alt_call_maybe_initconst __initconst + +#else + +#define alternative_call(func, args...) (func)(args) +#define alternative_vcall(func, args...) (func)(args) + +#define __alt_call_maybe_initdata +#define __alt_call_maybe_initconst + +#endif /* !CONFIG_ALTERNATIVE_CALL */ +#endif /* XEN_ALTERNATIVE_CALL */ --=20 2.11.0