From nobody Mon Feb 9 11:32:19 2026 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=1692133661; cv=none; d=zohomail.com; s=zohoarc; b=BDLdGkoa8zswpeXZqxRyBJn1EyQRY8ubH34ApWf4c4pFv5W2R6NcRVDoTKAG1hR6nE7RCfXxrRP9v2Wr+R7n/gTbQ85LIgU0jPk5pPcRkBbJzCLSbtiINJqTdshoybAAz6WvqWn6QL+cZ80HaOtdr2tg7tWzpMhF3bDH2IzjGfQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692133661; 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=VsmRyBUcRIdJaAQuCAI2EuVqetz64bWOfJkUxeLZJ3k=; b=CPmjrAxeU/ok7HQLz7AQCvQdjA049AU3gguBLwjY94cMYSeihcvgjPI89+8P2G7ycMZr7X94ztvBd+gpWg97A0X4bQTmBfGJHW9oT1giPdN+irRDyCUgZeQvm+W0Omj+adDKu8dfL7HLpGYwGnTFdPKzzyoiwsAhLLEFWZNy8lI= 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 1692133661730979.7618726018364; Tue, 15 Aug 2023 14:07:41 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.584058.914536 (Exim 4.92) (envelope-from ) id 1qW1Fz-0006xI-4a; Tue, 15 Aug 2023 21:07:15 +0000 Received: by outflank-mailman (output) from mailman id 584058.914536; Tue, 15 Aug 2023 21:07:15 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qW1Fy-0006wV-RZ; Tue, 15 Aug 2023 21:07:14 +0000 Received: by outflank-mailman (input) for mailman id 584058; Tue, 15 Aug 2023 21:07:13 +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 1qW1Fx-0004ge-OZ for xen-devel@lists.xenproject.org; Tue, 15 Aug 2023 21:07:13 +0000 Received: from esa5.hc3370-68.iphmx.com (esa5.hc3370-68.iphmx.com [216.71.155.168]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id b3a99d6a-3baf-11ee-9b0c-b553b5be7939; Tue, 15 Aug 2023 23:07:11 +0200 (CEST) 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: b3a99d6a-3baf-11ee-9b0c-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1692133631; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=T+zneU/ODd9BEL6CProAShU+q6Ysw7Qx5ZvQuObYDv8=; b=fL+kq3irB6oK5cXs86k341plqlccLVufi5zKnRxd/N+Q/YlQ8Lc0jaOf 6ro+ZXsW0kXr97ht/RvEHSoxvCalu/Y4pZd1xwHkOLIsyb0WRMce1/8Kf rk2dlPCiA3ncDnbHEsRZw1RYqKL8aQQ8BuSyxtRNH5axK+A+/H96WVf+9 c=; Authentication-Results: esa5.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none X-SBRS: 4.0 X-MesageID: 118253079 X-Ironport-Server: esa5.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.123 X-Policy: $RELAYED IronPort-Data: A9a23:FoW9dqAbQG759xVW/2jkw5YqxClBgxIJ4kV8jS/XYbTApG4l1jVRx mZND2qCPanYYWPxLd92bdyy9E0DvceEzNIxQQY4rX1jcSlH+JHPbTi7wuUcHAvJd5GeExg3h yk6QoOdRCzhZiaE/n9BCpC48T8nk/nOHuGmYAL9EngZbRd+Tys8gg5Ulec8g4p56fC0GArIs t7pyyHlEAbNNwVcbCRMsspvlDs15K6p4GNB4wRkDRx2lAS2e0c9Xcp3yZ6ZdxMUcqEMdsamS uDKyq2O/2+x13/B3fv8z94X2mVTKlLjFVDmZkh+AsBOsTAbzsAG6Y4pNeJ0VKtio27hc+ada jl6ncfYpQ8BZsUgkQmGOvVSO3kW0aZuoNcrLZUj2CA6IoKvn3bEmp1T4E8K0YIw8OFXQmVw/ LsiazUGdg2+ieXtm46eY7w57igjBJGD0II3v3hhyXfSDOo8QICFSKLPjTNa9G5u3IYUR6+YP pdHL2M1N3wsYDUWUrsTILs4kP2lmT/UdDpApUjOjaE2/3LS3Ep6172F3N/9I4XaH5gOxhnJz o7A1zTDU0krHdrP8AS+0imi2sifvXLBWo1HQdVU8dY12QbOlwT/EiY+RVa95PW0lEO6c9ZeM FAPvDojq7Ao806mRcW7WAe3yFamlBMBX9tbE8Uh9RqAjKHT5m6xHXMYRzRMbNgnss4eRjEw0 FKN2dTzClRHr7m9WX+bsLCOoluaOzURLGIETT8JS00C+daLiL80ihXDX9NyCpmfh9f+GSzz6 z2SpS14jLIW5eYM06i45lHGxTGxvJ/CTg0yzgrSV2OhqAh+YeaNfIWu4EPH5O1BK66D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KCoR1jLo59Bup87?= X-Talos-MUID: 9a23:X+/gTgYKHLx0kOBT5wW93ABLMpdR3Z+OU05RtsUm6vOGOnkl X-IronPort-AV: E=Sophos;i="6.01,175,1684814400"; d="scan'208";a="118253079" 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 , Bertrand Marquis , Oleksii Kurochko , Shawn Anastasio , Henry Wang Subject: [PATCH v3 01/10] xen/version: Calculate xen_capabilities_info once at boot Date: Tue, 15 Aug 2023 22:06:41 +0100 Message-ID: <20230815210650.2735671-2-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230815210650.2735671-1-andrew.cooper3@citrix.com> References: <20230815210650.2735671-1-andrew.cooper3@citrix.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: 1692133727827100001 The arch_get_xen_caps() infrastructure is horribly inefficient for something that is constant after features have been resolved on boot. Every instance used snprintf() to format constants into a string (which gets shorter when %d gets resolved!), and which get double buffered on the stack. Switch to using string literals with the "3.0" inserted - these numbers haven't changed in 18 years (The Xen 3.0 release was Dec 5th 2005). Use initcalls to format the data into xen_cap_info, which is deliberately n= ot of type xen_capabilities_info_t because a 1k array is a silly overhead for storing a maximum of 77 chars (the x86 version) and isn't liable to need any more space in the forseeable future. This speeds up the the XENVER_capabilities hypercall, but the purpose of the change is to allow us to introduce a better XENVER_* API that doesn't force the use of a 1k buffer on the stack. Signed-off-by: Andrew Cooper Acked-by: Jan Beulich Reviewed-by: Stefano Stabellini --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Wei Liu CC: Stefano Stabellini CC: Julien Grall CC: Volodymyr Babchuk CC: Bertrand Marquis CC: Oleksii Kurochko CC: Shawn Anastasio CC: Henry Wang v3: * CC new-arch folks so they're aware v2: * New Moving to __initcall() also allows new architectures to not implement this API, and I'm going to recommend strongly that they dont. Its a very dubious way of signalling about 3 bits of info to the toolstack, and inefficient to use (the toolstack has to do string parsing on the result figure out if PV64/PV32/HVM is available). --- xen/arch/arm/setup.c | 20 +++++++------------- xen/arch/x86/setup.c | 31 ++++++++++--------------------- xen/common/kernel.c | 3 ++- xen/include/xen/hypercall.h | 2 -- xen/include/xen/version.h | 2 ++ 5 files changed, 21 insertions(+), 37 deletions(-) diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index 44ccea03ca14..3592c9ebc1cd 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -1286,24 +1287,17 @@ void __init start_xen(unsigned long boot_phys_offse= t, switch_stack_and_jump(idle_vcpu[0]->arch.cpu_info, init_done); } =20 -void arch_get_xen_caps(xen_capabilities_info_t *info) +static int __init init_xen_cap_info(void) { - /* Interface name is always xen-3.0-* for Xen-3.x. */ - int major =3D 3, minor =3D 0; - char s[32]; - - (*info)[0] =3D '\0'; - #ifdef CONFIG_ARM_64 - snprintf(s, sizeof(s), "xen-%d.%d-aarch64 ", major, minor); - safe_strcat(*info, s); + safe_strcat(xen_cap_info, "xen-3.0-aarch64 "); #endif if ( cpu_has_aarch32 ) - { - snprintf(s, sizeof(s), "xen-%d.%d-armv7l ", major, minor); - safe_strcat(*info, s); - } + safe_strcat(xen_cap_info, "xen-3.0-armv7l "); + + return 0; } +__initcall(init_xen_cap_info); =20 /* * Local variables: diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 2bfc1fd00f8c..206f0c50a136 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -2049,35 +2049,24 @@ void __init noreturn __start_xen(unsigned long mbi_= p) unreachable(); } =20 -void arch_get_xen_caps(xen_capabilities_info_t *info) +static int __init cf_check init_xen_cap_info(void) { - /* Interface name is always xen-3.0-* for Xen-3.x. */ - int major =3D 3, minor =3D 0; - char s[32]; - - (*info)[0] =3D '\0'; - if ( IS_ENABLED(CONFIG_PV) ) { - snprintf(s, sizeof(s), "xen-%d.%d-x86_64 ", major, minor); - safe_strcat(*info, s); + safe_strcat(xen_cap_info, "xen-3.0-x86_64 "); =20 if ( opt_pv32 ) - { - snprintf(s, sizeof(s), "xen-%d.%d-x86_32p ", major, minor); - safe_strcat(*info, s); - } + safe_strcat(xen_cap_info, "xen-3.0-x86_32p "); } if ( hvm_enabled ) - { - snprintf(s, sizeof(s), "hvm-%d.%d-x86_32 ", major, minor); - safe_strcat(*info, s); - snprintf(s, sizeof(s), "hvm-%d.%d-x86_32p ", major, minor); - safe_strcat(*info, s); - snprintf(s, sizeof(s), "hvm-%d.%d-x86_64 ", major, minor); - safe_strcat(*info, s); - } + safe_strcat(xen_cap_info, + "hvm-3.0-x86_32 " + "hvm-3.0-x86_32p " + "hvm-3.0-x86_64 "); + + return 0; } +__initcall(init_xen_cap_info); =20 int __hwdom_init xen_in_range(unsigned long mfn) { diff --git a/xen/common/kernel.c b/xen/common/kernel.c index 52aa28762782..f822480a8ef3 100644 --- a/xen/common/kernel.c +++ b/xen/common/kernel.c @@ -30,6 +30,7 @@ enum system_state system_state =3D SYS_STATE_early_boot; =20 static xen_commandline_t saved_cmdline; static const char __initconst opt_builtin_cmdline[] =3D CONFIG_CMDLINE; +char __ro_after_init xen_cap_info[128]; =20 static int assign_integer_param(const struct kernel_param *param, uint64_t= val) { @@ -537,7 +538,7 @@ long do_xen_version(int cmd, XEN_GUEST_HANDLE_PARAM(voi= d) arg) =20 memset(info, 0, sizeof(info)); if ( !deny ) - arch_get_xen_caps(&info); + safe_strcpy(info, xen_cap_info); =20 if ( copy_to_guest(arg, info, ARRAY_SIZE(info)) ) return -EFAULT; diff --git a/xen/include/xen/hypercall.h b/xen/include/xen/hypercall.h index f307dfb59760..15b6be6ec818 100644 --- a/xen/include/xen/hypercall.h +++ b/xen/include/xen/hypercall.h @@ -56,6 +56,4 @@ common_vcpu_op(int cmd, struct vcpu *v, XEN_GUEST_HANDLE_PARAM(void) arg); =20 -void arch_get_xen_caps(xen_capabilities_info_t *info); - #endif /* __XEN_HYPERCALL_H__ */ diff --git a/xen/include/xen/version.h b/xen/include/xen/version.h index 93c58773630c..4856ad1b446d 100644 --- a/xen/include/xen/version.h +++ b/xen/include/xen/version.h @@ -19,6 +19,8 @@ const char *xen_deny(void); const char *xen_build_info(void); int xen_build_id(const void **p, unsigned int *len); =20 +extern char xen_cap_info[128]; + #ifdef BUILD_ID void xen_build_init(void); int xen_build_id_check(const Elf_Note *n, unsigned int n_sz, --=20 2.30.2