From nobody Wed Nov 19 01:57:05 2025 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=teddy.astie@vates.tech; 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=vates.tech ARC-Seal: i=1; a=rsa-sha256; t=1762959136; cv=none; d=zohomail.com; s=zohoarc; b=lDje0ZjIftuHKkhx5BEjbofHD7uZzg5mmfQ0j0t7T6TH5ghRf3HLwtjd30pGii5Yuadguv0GQaxZbAwKHISdr3iR96hJn4XEdsdw6V25WyevqFIS6sBTYP4f8dVYGdzzTzJOnCL9CUT2BS40jBIp++fCUd+Y0LWiBQNiTP15Lqw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762959136; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=IuOrOxBNA8cMhpMdlUPw8GDI0O10TQFvQKvWOyS1SPc=; b=kEdVHTZpiyJnI/ILHkL1h0jPOSGylGhDjw7AsGzKHw+7BZP15dyji0RNLx555NbdZBhxiifliumriB2WxCAYc8twqQ5VjCSMlqH8I2UUOQKB39/UokhYzBf4jCtF9qT8Q/5yH32sZoK4R58miQGHPfhToH/SRumBHnRC6subypE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=teddy.astie@vates.tech; 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 1762959136529245.72181031562093; Wed, 12 Nov 2025 06:52:16 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1159989.1488229 (Exim 4.92) (envelope-from ) id 1vJCCM-00079m-Ja; Wed, 12 Nov 2025 14:51:50 +0000 Received: by outflank-mailman (output) from mailman id 1159989.1488229; Wed, 12 Nov 2025 14:51:50 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vJCCM-00079f-H1; Wed, 12 Nov 2025 14:51:50 +0000 Received: by outflank-mailman (input) for mailman id 1159989; Wed, 12 Nov 2025 14:51:48 +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 1vJCCK-000787-Qo for xen-devel@lists.xenproject.org; Wed, 12 Nov 2025 14:51:48 +0000 Received: from mail179-26.suw41.mandrillapp.com (mail179-26.suw41.mandrillapp.com [198.2.179.26]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 1c4f7140-bfd7-11f0-9d18-b5c5bf9af7f9; Wed, 12 Nov 2025 15:51:47 +0100 (CET) Received: from pmta12.mandrill.prod.suw01.rsglab.com (localhost [127.0.0.1]) by mail179-26.suw41.mandrillapp.com (Mailchimp) with ESMTP id 4d65vj35BWzKsbYwq for ; Wed, 12 Nov 2025 14:51:45 +0000 (GMT) Received: from [37.26.189.201] by mandrillapp.com id 52d6befa532c45509e8e4ebbc4f991d1; Wed, 12 Nov 2025 14:51:45 +0000 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: 1c4f7140-bfd7-11f0-9d18-b5c5bf9af7f9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandrillapp.com; s=mte1; t=1762959105; x=1763229105; bh=IuOrOxBNA8cMhpMdlUPw8GDI0O10TQFvQKvWOyS1SPc=; h=From:Subject:To:Cc:Message-Id:Feedback-ID:Date:MIME-Version: Content-Type:Content-Transfer-Encoding:CC:Date:Subject:From; b=DFOEYkAh9ebmUVJ9eN0DjxpnxfsRRVOlT/FCgmV+NqIm8e5iwGgSGgOgIEeYAyfMg Q29kepInuYfrduAA1CHjexzUTNA2tNHses6Wfp/j193VbDm3LgRXLpF+iTzCcbl7Kk Ae0Zo9gHO1NWWZCtv6x1iUM021qkBi9gnoLMvwpf1HY0BcbwR7bQCXzLrk6RLXDS1K IPPMiqpI82dhI997Hr4BjYt92h4BbYUVuTm2hnVtba6bHH6muzxDIl434KEeDyE/80 EloVSX2X1E6830WrcjPKxM+DKBNLHcYxOkAOGn5BaBmyeoXV1IWMFYJ6Xw8eEYZJYI /URQsOeBse6ww== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vates.tech; s=mte1; t=1762959105; x=1763219605; i=teddy.astie@vates.tech; bh=IuOrOxBNA8cMhpMdlUPw8GDI0O10TQFvQKvWOyS1SPc=; h=From:Subject:To:Cc:Message-Id:Feedback-ID:Date:MIME-Version: Content-Type:Content-Transfer-Encoding:CC:Date:Subject:From; b=OEQ1vAPj5iNee8+/+Br36Vwy6Kg/8lck2j+aHURrG2pkgCA1w3c1kB5W9lsNgRROW ArI7R0t5jyKF8WERYiy7rT6Qipcxfp1ugIwbEkpwmj+zoEzmlR/Dax7ldY5R20bGGp CZUrMrRTdAJM5VjgwzviSV1Iu5zRWHOFe21Rfl1xCT+dMwPKoDxuLq4/bhHTDnG5Ih umLB+eyaxEaaoLQ/CDBEpjCRSJ6cvehJuLmA9xY+GRFx47qgxgZsxl9r61VJwMJe06 Vz/eunXzEfHMW7yx8OeiPP+NoA6AU+KpEykoxgYYquHggtCdXMAP8f6eeJA5KGZOwW 3rgI/KBl3dx/Q== From: "Teddy Astie" Subject: =?utf-8?Q?[RFC=20PATCH=20v2]=20x86/hvm:=20Allow=20pre-enabling=20x2apic=20mode=20on=20BSP?= X-Mailer: git-send-email 2.51.2 X-Bm-Disclaimer: Yes X-Bm-Milter-Handled: 4ffbd6c1-ee69-4e1b-aabd-f977039bd3e2 X-Bm-Transport-Timestamp: 1762959104208 To: xen-devel@lists.xenproject.org Cc: "Teddy Astie" , "Anthony PERARD" , "Juergen Gross" , "Andrew Cooper" , "Jan Beulich" , "Alejandro Vallejo" , "Grygorii Strashko" Message-Id: <0cb4d1f91212a65baf924ed0ef825d8adb4b5423.1762958551.git.teddy.astie@vates.tech> X-Native-Encoded: 1 X-Report-Abuse: =?UTF-8?Q?Please=20forward=20a=20copy=20of=20this=20message,=20including=20all=20headers,=20to=20abuse@mandrill.com.=20You=20can=20also=20report=20abuse=20here:=20https://mandrillapp.com/contact/abuse=3Fid=3D30504962.52d6befa532c45509e8e4ebbc4f991d1?= X-Mandrill-User: md_30504962 Feedback-ID: 30504962:30504962.20251112:md Date: Wed, 12 Nov 2025 14:51:45 +0000 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @mandrillapp.com) (identity teddy.astie@vates.tech) X-ZM-MESSAGEID: 1762959137796158500 Content-Type: text/plain; charset="utf-8" Introduce a new option to start the BSP vCPU in x2APIC mode instead of xAPIC mode. Expose this in xl through a new "x2apic_mode" option. Signed-off-by: Teddy Astie --- Cc: Andrew Cooper Cc: Jan Beulich Cc: Alejandro Vallejo Cc: Grygorii Strashko Later on, we could consider with this option to use x2APIC ACPI tables instead of xAPIC ones. There is also some room into introducing a new Kconfig option to only support x2apic mode, which would change how the "Xen default" would behave. changed in v2: - only pre-enable instead of forcing - use domain builder to pre-enable instead of introducing a new domain cre= ation flag v1: - https://lore.kernel.org/xen-devel/d498a50f6187b362ac5da3c6a7a7c348f35dc4b= 3.1761761288.git.teddy.astie@vates.tech/ --- docs/man/xl.cfg.5.pod.in | 16 ++++++++++++ tools/include/libxl.h | 8 ++++++ tools/include/xenguest.h | 4 +++ tools/libs/guest/xg_dom_x86.c | 42 ++++++++++++++++++++++++++++++++ tools/libs/light/libxl_types.idl | 1 + tools/libs/light/libxl_x86.c | 4 +++ tools/xl/xl_parse.c | 11 +++++++++ 7 files changed, 86 insertions(+) diff --git a/docs/man/xl.cfg.5.pod.in b/docs/man/xl.cfg.5.pod.in index ad1553c5e9..0f7a89fe92 100644 --- a/docs/man/xl.cfg.5.pod.in +++ b/docs/man/xl.cfg.5.pod.in @@ -3198,6 +3198,22 @@ option. =20 If using this option is necessary to fix an issue, please report a bug. =20 +=3Ditem B + +Sets the x2apic mode of the domain. The valid values are as follows: + +=3Dover 4 + +=3Ditem B<"default"> + +Use default Xen LAPIC behavior. + +=3Ditem B<"pre_enable"> + +Initially enable x2apic for the BSP of the domain. + +=3Dback + =3Dback =20 =3Dhead1 SEE ALSO diff --git a/tools/include/libxl.h b/tools/include/libxl.h index bc35e412da..9850e8aa41 100644 --- a/tools/include/libxl.h +++ b/tools/include/libxl.h @@ -1537,6 +1537,14 @@ void libxl_mac_copy(libxl_ctx *ctx, libxl_mac *dst, = const libxl_mac *src); */ #define LIBXL_HAVE_XEN_PLATFORM_PCI_BAR_UC =20 +/* + * LIBXL_HAVE_X2APIC_PREENABLE + * + * libxl_domain_build_info contains a boolean 'arch_x86.x2apic_preenable' = field + * to initially set the BSP LAPIC in x2APIC mode. + */ +#define LIBXL_HAVE_X2APIC_PREENABLE + typedef char **libxl_string_list; void libxl_string_list_dispose(libxl_string_list *sl); int libxl_string_list_length(const libxl_string_list *sl); diff --git a/tools/include/xenguest.h b/tools/include/xenguest.h index c88958faa9..408a0c77e8 100644 --- a/tools/include/xenguest.h +++ b/tools/include/xenguest.h @@ -223,6 +223,10 @@ struct xc_dom_image { /* If unset disables the setup of the IOREQ pages. */ bool device_model; =20 +#if defined(__i386__) || defined(__x86_64__) + bool preenable_x2apic; /* 1 makes x2APIC enabled initially, 0 keeps de= fault Xen behavior */ +#endif + /* BIOS/Firmware passed to HVMLOADER */ struct xc_hvm_firmware_module system_firmware_module; =20 diff --git a/tools/libs/guest/xg_dom_x86.c b/tools/libs/guest/xg_dom_x86.c index a82b481a12..43ada5a6ac 100644 --- a/tools/libs/guest/xg_dom_x86.c +++ b/tools/libs/guest/xg_dom_x86.c @@ -58,6 +58,9 @@ #define MTRR_TYPE_WRBACK 6 #define MTRR_DEF_TYPE_ENABLE (1u << 11) =20 +#define APIC_BASE_EXTD (1UL << 10) +#define APIC_BASE_ENABLE (1UL << 11) + #define SPECIALPAGE_PAGING 0 #define SPECIALPAGE_ACCESS 1 #define SPECIALPAGE_SHARING 2 @@ -1131,6 +1134,45 @@ static int vcpu_hvm(struct xc_dom_image *dom) } } =20 + if ( dom->preenable_x2apic ) + { + struct { + struct hvm_save_descriptor header_d; + HVM_SAVE_TYPE(HEADER) header; + struct hvm_save_descriptor lapic_d; + HVM_SAVE_TYPE(LAPIC) lapic; + struct hvm_save_descriptor end_d; + HVM_SAVE_TYPE(END) end; + } lapic =3D { + .header_d =3D bsp_ctx.header_d, + .header =3D bsp_ctx.header, + .lapic_d.typecode =3D HVM_SAVE_CODE(LAPIC), + .lapic_d.length =3D HVM_SAVE_LENGTH(LAPIC), + .end_d =3D bsp_ctx.end_d, + .end =3D bsp_ctx.end, + }; + const HVM_SAVE_TYPE(LAPIC) *lapic_record =3D + hvm_get_save_record(full_ctx, HVM_SAVE_CODE(LAPIC), 0); + + if ( !lapic_record ) + { + xc_dom_panic(dom->xch, XC_INTERNAL_ERROR, + "%s: unable to get LAPIC save record", __func__); + goto out; + } + + memcpy(&lapic.lapic, lapic_record, sizeof(lapic.lapic)); + + lapic.lapic.apic_base_msr |=3D APIC_BASE_ENABLE | APIC_BASE_EXTD; + + rc =3D xc_domain_hvm_setcontext(dom->xch, dom->guest_domid, + (uint8_t *)&lapic, sizeof(lapic)); + + if ( rc !=3D 0 ) + xc_dom_panic(dom->xch, XC_INTERNAL_ERROR, + "%s: SETHVMCONTEXT failed (rc=3D%d)", __func__, r= c); + } + /* * Loading the BSP context should be done in the last call to setconte= xt, * since each setcontext call will put all vCPUs down. diff --git a/tools/libs/light/libxl_types.idl b/tools/libs/light/libxl_type= s.idl index d64a573ff3..9fdf89d88b 100644 --- a/tools/libs/light/libxl_types.idl +++ b/tools/libs/light/libxl_types.idl @@ -738,6 +738,7 @@ libxl_domain_build_info =3D Struct("domain_build_info",[ ("arm_sci", libxl_arm_sci), ])), ("arch_x86", Struct(None, [("msr_relaxed", libxl_defbool), + ("x2apic_preenable", libxl_defbool) ])), # Alternate p2m is not bound to any architecture or guest type, as it = is # supported by x86 HVM and ARM support is planned. diff --git a/tools/libs/light/libxl_x86.c b/tools/libs/light/libxl_x86.c index 60d4e8661c..f9725f069a 100644 --- a/tools/libs/light/libxl_x86.c +++ b/tools/libs/light/libxl_x86.c @@ -555,6 +555,9 @@ int libxl__arch_domain_init_hw_description(libxl__gc *g= c, libxl__domain_build_state *stat= e, struct xc_dom_image *dom) { + if (libxl_defbool_val(d_config->b_info.arch_x86.x2apic_preenable)) + dom->preenable_x2apic =3D true; + return 0; } =20 @@ -818,6 +821,7 @@ int libxl__arch_domain_build_info_setdefault(libxl__gc = *gc, { libxl_defbool_setdefault(&b_info->acpi, true); libxl_defbool_setdefault(&b_info->arch_x86.msr_relaxed, false); + libxl_defbool_setdefault(&b_info->arch_x86.x2apic_preenable, false); libxl_defbool_setdefault(&b_info->trap_unmapped_accesses, false); =20 if (b_info->type =3D=3D LIBXL_DOMAIN_TYPE_HVM) { diff --git a/tools/xl/xl_parse.c b/tools/xl/xl_parse.c index af86d3186d..92bf9d2ad5 100644 --- a/tools/xl/xl_parse.c +++ b/tools/xl/xl_parse.c @@ -3040,6 +3040,17 @@ skip_usbdev: "WARNING: msr_relaxed will be removed in future versio= ns.\n" "If it fixes an issue you are having please report to " "xen-devel@lists.xenproject.org.\n"); + =20 + if (!xlu_cfg_get_string(config, "x2apic_mode", &buf, 1)) { + if (!strcmp(buf, "pre_enable")) + libxl_defbool_set(&b_info->arch_x86.x2apic_preenable, true); + else if (!strcmp(buf, "default")) + libxl_defbool_set(&b_info->arch_x86.x2apic_preenable, false); + else { + fprintf(stderr, "Unknown x2apic mode \"%s\" specified\n", buf); + exit(EXIT_FAILURE); + } + } =20 xlu_cfg_get_defbool(config, "vpmu", &b_info->vpmu, 0); =20 --=20 2.51.2 -- Teddy Astie | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech