From nobody Mon Nov 23 22:39:58 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=none dis=none) header.from=vates.tech ARC-Seal: i=1; a=rsa-sha256; t=1792146217; cv=none; d=zohomail.com; s=zohoarc; b=XYWm7Eg8T5WNVWwEI/0nrm++H0/e/4TyWf7/bt97Dzn5SZUp7p1r7CzxBbFH8Uqv7M3SHJMA1+2/HnVCwGbT4xxltAwHh4Sm88t4rpUMbvIcmg2Gzq5p1Akx3VBwFuqE79mydNrlZX9U2hQd7pBBmwQ45l65/YqNMfJvaIdCnIw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792146217; h=Content-Type: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=EIwNFn27oeeB1Vrvy7FJ5dLaZJdL2NDuWkIdyglqKvU=; b=GUuSTQRD/LCUWpyU8vGCNn3v1YbbBDRRsWyYNHTD451msHxnwK9dGG794VSvoD4WkLD0BjfSenTd6DIa4hbRQcG9V5RakGnOvxxMEpF+Md2W9PyLvJvzs+aEY4O1o880NZ8QLyyVajfB0qhinBsgeGJkv1+KF/4sSIHu0+vjV1I= 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=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1792146217334954.9280106067595; Fri, 16 Oct 2026 03:23:37 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1451532.1666580 (Exim 4.92) (envelope-from ) id 1xHf5t-0007L8-CZ; Fri, 16 Oct 2026 10:23:21 +0000 Received: by outflank-mailman (output) from mailman id 1451532.1666580; Fri, 16 Oct 2026 10:23:21 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xHf5t-0007L1-9k; Fri, 16 Oct 2026 10:23:21 +0000 Received: by outflank-mailman (input) for mailman id 1451532; Fri, 16 Oct 2026 10:23:19 +0000 Received: from mx.expurgate.net ([194.145.224.20]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xHf5r-0007Ks-2G for xen-devel@lists.xenproject.org; Fri, 16 Oct 2026 10:23:19 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1xHf5q-005d1v-F0 for xen-devel@lists.xenproject.org; Fri, 16 Oct 2026 12:23:18 +0200 Received: from [10.42.69.1] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6ad1fb11-2eae-0a2a0a5409dd-0a2a45019418-30 for ; Fri, 16 Oct 2026 12:23:18 +0200 Received: from [185.255.28.35] (helo=prod-mta-13-02.swg-srv.net) by tlsNG-d62444.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6ad1fb15-5984-0a2a45010019-b9ff1c239b41-3 for ; Fri, 16 Oct 2026 12:23:17 +0200 Received: from mail2.vates.fr ([37.26.189.201] mail2.vates.fr) (Authenticated sender: 8631fc262581453bbf619ec5b2062170/smtp/7773de5a-2839-4720-82ee-e06722ae1d3e) by prod-mta-13-02.swg-srv.net (ZoneMTA - prod-mta-13) with ESMTPSA id 1a1443cb7e90008425.005 for (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Fri, 16 Oct 2026 10:23:12 +0000 Received: from bazzite.gpn.vates.fr (88-188-240-210.subs.proxad.net [88.188.240.210]) (Authenticated sender: teddy.astie) by mail2.vates.fr (Postfix) with ESMTPSA id 6691782B33; Fri, 16 Oct 2026 12:23: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" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=vates.tech header.i="@vates.tech" header.h="From:Subject:Date:Message-ID:To:Cc:MIME-Version:Content-Type:Feedback-ID" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vates.tech; q=dns/txt; s=selector1; bh=EIwNFn27oeeB1Vrvy7FJ5dLaZJdL2NDuWkIdyglqKvU=; h=from:subject:date:message-id:to:cc:mime-version:content-type:feedback-id; b=Ig44eVE9pZ+58qo9oYBXPKR18c835lfxgDYEx6+aMFBxPMEqELLnnQNuHoEd7LkkGEryNsimL ssuC/tqVnvCJ8yJPVxexZ3EygTmRN99nE4gTA3ZpYgho72HsnKOp/kRF12axmk2e10naJE/FJDa jNaA+iaFLEn1VPFhH21LTcZWP7qjQ01EEDeri1gql0C6zePtWtd54Dpa0Ldh7ROrJDKsczboy+p CwyDiN/PzSzmP8KcqjjZqiswtF0Ahdob7YWPxo73R8YDSPKefyfphj5GXQ3pHh3Edu1/V5C8AYe L0Ejvw3L1ijMUFHw/gCKQRjQ+MJUHL01ylOLqw25opKA== X-Zone-Loop: 477319da4ae58a73404ceb02744c273941bdba5e373b x-campaign-type: default x-transaction-id: b28f0cdd-68a8-467c-9f25-95f76abd61f8 x-swg-uid: 01-adb76025-8703-475e-908d-c500b6386f73 X-Mailer: Sweego Message-ID: <1792146192.8631fc262581453bbf619ec5b2062170.1a1443cb7e90008425@vates.tech> x-swg-bid: 1792146192.8631fc262581453bbf619ec5b2062170.1a1443cb7e90008425 Feedback-ID: default:8631fc262581453bbf619ec5b2062170:Sweego x-campaign-id: default x-client-id: 8631fc262581453bbf619ec5b2062170 X-Originating-IP: [37.26.189.201] From: Teddy Astie To: xen-devel@lists.xenproject.org Cc: Teddy Astie , Juergen Gross , Boris Ostrovsky , Stefano Stabellini , Oleksandr Tyshchenko , David Woodhouse , George Dunlap , x86@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] xen: Use VCPUOP_register_{runstate,vcpu_time}_phys_area when available Date: Fri, 16 Oct 2026 12:22:00 +0200 MIME-Version: 1.0 X-BM-Disclaimer: Yes Content-Type: multipart/alternative; boundary="-=Part.2b5.eea8caf3adaf82ca.1a1443cb515.d621e0f4827f716e=-" X-Bm-Milter-Handled: 4ffbd6c1-ee69-4e1b-aabd-f977039bd3e2 X-Bm-Transport-Timestamp: 1792146191643 X-purgate-ID: tlsNG-d62444/1792146198-C4B45757-AEE1FEF6/0/0 X-purgate-type: clean X-purgate-size: 8222 X-ZohoMail-DKIM: pass (identity @vates.tech) X-ZM-MESSAGEID: 1792146220838158500 ---=Part.2b5.eea8caf3adaf82ca.1a1443cb515.d621e0f4827f716e=- Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Updating these area can be expensive when done through virtual addresses (especially for runstate one), in particular for HVM/PVH guests. Xen 4.18 introduced physical address alternatives to address those short-commings, but they aren't used currently. Fix it by using these alternatives when available (when reported in XENFEAT_{runstate,vcpu_time}_phys_area, but keep the current logic in the PV case. Assisted-by: LLM [guidance and testing] Signed-off-by: Teddy Astie --- When using phys_area ABI, the struct is not allowed to cross a page boundary anymore, hence we need to be careful with per-cpu struct alignment. I've deliberately put the PV domain (!XENFEAT_auto_translated_physmap) case aside as it profits less from the physical address ABI, and it would make things more complicated as "physical address" doesn't have a obvious meaning there. CC: Juergen Gross CC: Boris Ostrovsky CC: Stefano Stabellini CC: Oleksandr Tyshchenko CC: David Woodhouse CC: George Dunlap CC: x86@kernel.org CC: linux-kernel@vger.kernel.org arch/x86/xen/time.c | 35 ++++++++++++++++++-------------- drivers/xen/time.c | 24 +++++++++++++++++----- include/xen/interface/features.h | 9 ++++++++ include/xen/interface/vcpu.h | 17 ++++++++++++++++ 4 files changed, 65 insertions(+), 20 deletions(-) diff --git a/arch/x86/xen/time.c b/arch/x86/xen/time.c index 5c7822254a01..19ace1b78ae4 100644 --- a/arch/x86/xen/time.c +++ b/arch/x86/xen/time.c @@ -37,6 +37,22 @@ =20 static u64 xen_sched_clock_offset __read_mostly; =20 +static int xen_register_time_area(struct pvclock_vcpu_time_info *pvti) +{ + struct vcpu_register_time_memory_area t; + bool phys =3D xen_feature(XENFEAT_vcpu_time_phys_area) && + xen_feature(XENFEAT_auto_translated_physmap); + int op =3D phys ? VCPUOP_register_vcpu_time_phys_area + : VCPUOP_register_vcpu_time_memory_area; + + if (phys) + t.addr.p =3D pvti ? virt_to_phys(pvti) : ~0LLU; + else + t.addr.v =3D pvti; + + return HYPERVISOR_vcpu_op(op, 0, &t); +} + /* Get the TSC speed from Xen */ static unsigned long xen_tsc_khz(void) { @@ -395,7 +411,6 @@ static u64 xen_clock_value_saved; =20 void xen_save_time_memory_area(void) { - struct vcpu_register_time_memory_area t; int ret; =20 xen_clock_value_saved =3D xen_clocksource_read() - xen_sched_clock_offset; @@ -403,9 +418,7 @@ void xen_save_time_memory_area(void) if (!xen_clock) return; =20 - t.addr.v =3D NULL; - - ret =3D HYPERVISOR_vcpu_op(VCPUOP_register_vcpu_time_memory_area, 0, &t); + ret =3D xen_register_time_area(NULL); if (ret !=3D 0) pr_notice("Cannot save secondary vcpu_time_info (err %d)", ret); @@ -415,15 +428,12 @@ void xen_save_time_memory_area(void) =20 void xen_restore_time_memory_area(void) { - struct vcpu_register_time_memory_area t; int ret; =20 if (!xen_clock) goto out; =20 - t.addr.v =3D &xen_clock->pvti; - - ret =3D HYPERVISOR_vcpu_op(VCPUOP_register_vcpu_time_memory_area, 0, &t); + ret =3D xen_register_time_area(&xen_clock->pvti); =20 /* * We don't disable VDSO_CLOCKMODE_PVCLOCK entirely if it fails to @@ -446,7 +456,6 @@ void xen_restore_time_memory_area(void) =20 static void xen_setup_vsyscall_time_info(void) { - struct vcpu_register_time_memory_area t; struct pvclock_vsyscall_time_info *ti; int ret; =20 @@ -454,9 +463,7 @@ static void xen_setup_vsyscall_time_info(void) if (!ti) return; =20 - t.addr.v =3D &ti->pvti; - - ret =3D HYPERVISOR_vcpu_op(VCPUOP_register_vcpu_time_memory_area, 0, &t); + ret =3D xen_register_time_area(&ti->pvti); if (ret) { pr_notice("xen: VDSO_CLOCKMODE_PVCLOCK not supported (err %d)\n", ret); free_page((unsigned long)ti); @@ -469,9 +476,7 @@ static void xen_setup_vsyscall_time_info(void) * still check it in case hypervisor is buggy. */ if (!(ti->pvti.flags & PVCLOCK_TSC_STABLE_BIT)) { - t.addr.v =3D NULL; - ret =3D HYPERVISOR_vcpu_op(VCPUOP_register_vcpu_time_memory_area, - 0, &t); + ret =3D xen_register_time_area(NULL); if (!ret) free_page((unsigned long)ti); =20 diff --git a/drivers/xen/time.c b/drivers/xen/time.c index a2be0a4d45b0..6b6ddc7a5822 100644 --- a/drivers/xen/time.c +++ b/drivers/xen/time.c @@ -19,8 +19,12 @@ #include #include =20 -/* runstate info updated by Xen */ -static DEFINE_PER_CPU(struct vcpu_runstate_info, xen_runstate); +/* + * Runstate info updated by Xen. The phys-area ABI doesn't allow it to cro= ss + * a page boundary; the struct is 48 bytes, so 64 is the smallest alignment + * that guarantees this. + */ +static DEFINE_PER_CPU(struct vcpu_runstate_info, xen_runstate) __aligned(6= 4); =20 static DEFINE_PER_CPU(u64[4], old_runstate_time); =20 @@ -152,11 +156,21 @@ u64 xen_steal_clock(int cpu) void xen_setup_runstate_info(int cpu) { struct vcpu_register_runstate_memory_area area; + unsigned int op; =20 - area.addr.v =3D &per_cpu(xen_runstate, cpu); + if (xen_feature(XENFEAT_runstate_phys_area) && + xen_feature(XENFEAT_auto_translated_physmap)) + { + op =3D VCPUOP_register_runstate_phys_area; + area.addr.p =3D per_cpu_ptr_to_phys(&per_cpu(xen_runstate, cpu)); + } + else + { + op =3D VCPUOP_register_runstate_memory_area; + area.addr.v =3D &per_cpu(xen_runstate, cpu); + } =20 - if (HYPERVISOR_vcpu_op(VCPUOP_register_runstate_memory_area, - xen_vcpu_nr(cpu), &area)) + if (HYPERVISOR_vcpu_op(op, xen_vcpu_nr(cpu), &area)) BUG(); } =20 diff --git a/include/xen/interface/features.h b/include/xen/interface/featu= res.h index 53f760378e39..f00144a7c790 100644 --- a/include/xen/interface/features.h +++ b/include/xen/interface/features.h @@ -97,6 +97,15 @@ #define XENFEAT_not_direct_mapped 16 #define XENFEAT_direct_mapped 17 =20 +/* + * Signal whether the domain is able to use the following hypercalls: + * + * VCPUOP_register_runstate_phys_area + * VCPUOP_register_vcpu_time_phys_area + */ +#define XENFEAT_runstate_phys_area 18 +#define XENFEAT_vcpu_time_phys_area 19 + #define XENFEAT_NR_SUBMAPS 1 =20 #endif /* __XEN_PUBLIC_FEATURES_H__ */ diff --git a/include/xen/interface/vcpu.h b/include/xen/interface/vcpu.h index c7cc28ad8d63..d3858233c32f 100644 --- a/include/xen/interface/vcpu.h +++ b/include/xen/interface/vcpu.h @@ -203,4 +203,21 @@ struct vcpu_register_time_memory_area { }; DEFINE_GUEST_HANDLE_STRUCT(vcpu_register_time_memory_area); =20 +/* + * Like the respective VCPUOP_register_*_memory_area, just using the "addr= .p" + * field of the supplied struct as a guest physical address (i.e. in GFN s= pace). + * The respective area may not cross a page boundary. Pass ~0 to unregist= er an + * area. Note that as long as an area is registered by physical address, = the + * linear address based area will not be serviced (updated) by the hypervi= sor. + * + * Note that the area registered via VCPUOP_register_runstate_phys_area wi= ll + * be updated in the same manner as the one registered via virtual address= PLUS + * VMASST_TYPE_runstate_update_flag engaged by the domain. + * + * XENFEAT_{runstate,vcpu_time}_phys_area feature bits signal the availabi= lity + * of these ops. + */ +#define VCPUOP_register_runstate_phys_area 14 +#define VCPUOP_register_vcpu_time_phys_area 15 + #endif /* __XEN_PUBLIC_VCPU_H__ */ --=20 2.56.0 --=20 Teddy Astie | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech ---=Part.2b5.eea8caf3adaf82ca.1a1443cb515.d621e0f4827f716e=---