From nobody Sat Jan 10 00:26:47 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; 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=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1767803372; cv=none; d=zohomail.com; s=zohoarc; b=Kqgfk0D3MSq/Eo2qdCfxERK8FUJAAM8P/YWW6qAOWv+gjqs6rspCA6Dx6WWNXQrWlNDawwiuQ0jqnbdzEen8Yb2Pd0MmkTC2FvThWOcIv3xizgNFnKQlJTCDNj+HEQSxp03FSDtGd+J/gY3vxv5j4bueWTxUEhpaMSSChjdNEQw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1767803372; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=6yGW8UvBWmtvRdmMTk+NgZys8X+oT8jZSBJlqpDXUFw=; b=HiYKatYmcamv+4oCgsuRvoXSInC1AUmH1+wHzbZiw7E1BD0VbZVK3gm2WcssA/Jrgqc78P5ghANyYEnsoeb/q5k0q/3UUdbu/nAt8wLer1/GrWSpdf/C8D5A994cf1iH8zuKyCFzkmqEKqlpdLV+wztOjUkEN2z3kvwVxcs2Tjw= 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 1767803372152979.3820412773703; Wed, 7 Jan 2026 08:29:32 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1196894.1514606 (Exim 4.92) (envelope-from ) id 1vdWPJ-000097-T7; Wed, 07 Jan 2026 16:29:13 +0000 Received: by outflank-mailman (output) from mailman id 1196894.1514606; Wed, 07 Jan 2026 16:29:13 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vdWPJ-00008y-Q7; Wed, 07 Jan 2026 16:29:13 +0000 Received: by outflank-mailman (input) for mailman id 1196894; Wed, 07 Jan 2026 16:29:12 +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 1vdWPI-0008M3-D0 for xen-devel@lists.xenproject.org; Wed, 07 Jan 2026 16:29:12 +0000 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [2a00:1450:4864:20::62f]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id fea318b0-ebe5-11f0-b15e-2bf370ae4941; Wed, 07 Jan 2026 17:29:10 +0100 (CET) Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-b7cf4a975d2so391631766b.2 for ; Wed, 07 Jan 2026 08:29:10 -0800 (PST) Received: from fedora (user-109-243-67-101.play-internet.pl. [109.243.67.101]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b842a2bcd30sm564782166b.28.2026.01.07.08.29.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jan 2026 08:29:08 -0800 (PST) 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: fea318b0-ebe5-11f0-b15e-2bf370ae4941 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767803349; x=1768408149; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6yGW8UvBWmtvRdmMTk+NgZys8X+oT8jZSBJlqpDXUFw=; b=ARZ5r4E6cU2X/Nw56kGZwi8J6GwKxcfe8Pl/4hNP+w81GBvEiGZi6OiJQCARmOjcV0 tLxDpNogtYY2Rb4DhgeU3dAJcX4GHTPq7ujJhAvx8WAn8o5LlxnGHdS25zFziplzWhcm QW0DuAsXt8hxmUroLxCOOb95HlHhKx++QC3OOYkLfPKvD4SKHOzCHD0NXr2DJFk7eNyt w5y9iG1Zv9W2jfKZM9RwjBO+mfrBvJaHdL1ZlfU1yBU+Hs72eYa5hsuJIuCE1u1Z1NlL gEt/2o7+zMtwaUSnx87WmPJU3o5oVq1CPyfMsM3STedgMWilev2MmA/WSiNQ+sHs4g/l AmnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767803349; x=1768408149; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=6yGW8UvBWmtvRdmMTk+NgZys8X+oT8jZSBJlqpDXUFw=; b=Tgsyder+QkfcaYKT3wJisjHqYTQxeCb+TH9Xf88lSQ43hpgJe8S1GvXfW22mHiOmeM YHymul01kX6RRYHAdS88Zy3df9k0Rp0G5lZKhcH+1+IBPacuzoFSjgU7AmycewFCwT6S QZj6yJPASkCVX/QE91w4QqYFbEWQlesvClhf6Iq0fXjenlAIiEsPWGsoI/Rmg0+IX9gd t/xMZpSKH1D7hL9joiOPKwP8G2cgHKqZZRmmanyE95rPaaGKyNkmaYV/9ArQf03wmwd6 xFkB9txX3UjPwFCeSJZ3gU4LYGYD+VzzGEtMd9p2na6xs0a0HAKWVXzUVTvZV0V9g6/E olFQ== X-Gm-Message-State: AOJu0YwF8fjmBepT27uWCsgQ0ZQNKZsN1do9eqj3v2jwdhpnjKf4a8O+ qdadKFCS57aIN97who9XuV2EsHg7Ng81BOiXWZY9kdO8wjdvXt7/DIAKhLT/Zw== X-Gm-Gg: AY/fxX5IDcSY9hEo3n9a0ogxuM7PzDDrHe9yaPDFE2A7QgQsBI7jvDRLRKW2J0on0R2 YMIkHeFWxmUdR4d2z43JxKmIMyCqIoLeZcNPlX1AIEMCliGwNPmv4xSrPEcQcfRXV40tyXGLYG0 RGzdpJ7WeQ5IY4b15z3aYSu3EeJYCo4Q2v9UIk0qXaYHc/9kU72LEBKWBeTrXmEcKGATGuuw5eE CuIJmXY5oEFOhFrhufYMP4X3IgbbSH4KEqGD9sXlwzrex7AiI2A05a0a0THK3Szusm8IZ1j6hP4 dUwq7PzqB3WST27jr6o+Muz9wH4apK+jqE2J7KQUU+AFopA9Z/YWEzlgORk76QdEjtLuMZOXEtW DkgbrPYjBM1kZUS9fL7i8Q7K5l9dSh7VwwGZxDNl2Z4iqQUxjY7oHX7QsG5e2cza/GNsOm46KeX Kl3OwXVPK5HBo0agq8m8ASi2Equca6VsdIw/Ywf2rgpPX2RLSrZPBwcw== X-Google-Smtp-Source: AGHT+IEq88HKeF95MEbRuBUFDBYiow8dR/PBcpgnTLj2uRlUaT1D0eK33Qc4TlRDaA6RmFlJ4mBmzw== X-Received: by 2002:a17:906:7955:b0:b7a:1bde:1221 with SMTP id a640c23a62f3a-b84451a792cmr313554766b.62.1767803349173; Wed, 07 Jan 2026 08:29:09 -0800 (PST) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Oleksii Kurochko , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Andrew Cooper Subject: [PATCH v5 1/3] xen/arm: optimize the size of struct vcpu Date: Wed, 7 Jan 2026 17:28:58 +0100 Message-ID: <1d7f2183bd01df92445bf37ddc9d41f8bfa0ccdb.1767803084.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1767803373375158500 Content-Type: text/plain; charset="utf-8" When CONFIG_NEW_VGIC=3Dy and CONFIG_ARM_64=3Dy, the size of struct vcpu exceeds one page, which requires allocating two pages and led to the introduction of MAX_PAGES_PER_VCPU. To remove the need for MAX_PAGES_PER_VCPU, the vgic member of NEW_VGIC's struct vgic_cpu member private_irqs is changed to a pointer to struct vgic_irq. As a result, the size of struct vcpu for Arm64 is reduced to 2176 bytes in the case when CONFIG_ARM_64=3Dy and CONFIG_NEW_VGIC=3Dy, compared to 3840 bytes (without these changes and with CONFIG_ARM_64=3Dy) and 4736 bytes (without these changes and with both CONFIG_ARM_64=3Dy and CONFIG_NEW_VGIC= =3Dy). Note that all numbers are based on defconfig with the mentioned options enabled or disabled as specified. Since the private_irqs member is now a pointer, vcpu_vgic_init() and vcpu_vgic_free() are updated to allocate and free private_irqs instance. As struct vcpu now fits into one page, drop MAX_PAGES_PER_VCPU. Suggested-by: Andrew Cooper Signed-off-by: Oleksii Kurochko Reviewed-by: Andrew Cooper --- Michal gave his: Acked-by: Michal Orzel But wrote to MAX_PAGES_PER_VCPU in this patch, so probably he would like to look at how it was done. --- Change in v5: - Correct the commit message: - s/vgic_vcpu/vgic_cpu/ - s/private_irq/private_irqs/ - Drop MAX_PAGES_PER_VCPU. --- Change in v4: - Add Reviewed-by: Andrew Cooper . --- Changes in v3: - Make private_irqs member as pointer to vgic_irq in struct vgic_cpu of new_vgic instead of vgic member of arch_vcpu. --- Changes in v2: - New patch. --- xen/arch/arm/domain.c | 23 ++++------------------- xen/arch/arm/include/asm/new_vgic.h | 2 +- xen/arch/arm/vgic/vgic-init.c | 7 +++++++ 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c index 47973f99d935..64b935b68000 100644 --- a/xen/arch/arm/domain.c +++ b/xen/arch/arm/domain.c @@ -473,36 +473,21 @@ void dump_pageframe_info(struct domain *d) =20 } =20 -/* - * The new VGIC has a bigger per-IRQ structure, so we need more than one - * page on ARM64. Cowardly increase the limit in this case. - */ -#if defined(CONFIG_NEW_VGIC) && defined(CONFIG_ARM_64) -#define MAX_PAGES_PER_VCPU 2 -#else -#define MAX_PAGES_PER_VCPU 1 -#endif - struct vcpu *alloc_vcpu_struct(const struct domain *d) { struct vcpu *v; =20 - BUILD_BUG_ON(sizeof(*v) > MAX_PAGES_PER_VCPU * PAGE_SIZE); - v =3D alloc_xenheap_pages(get_order_from_bytes(sizeof(*v)), 0); + BUILD_BUG_ON(sizeof(*v) > PAGE_SIZE); + v =3D alloc_xenheap_page(); if ( v !=3D NULL ) - { - unsigned int i; - - for ( i =3D 0; i < DIV_ROUND_UP(sizeof(*v), PAGE_SIZE); i++ ) - clear_page((void *)v + i * PAGE_SIZE); - } + clear_page(v); =20 return v; } =20 void free_vcpu_struct(struct vcpu *v) { - free_xenheap_pages(v, get_order_from_bytes(sizeof(*v))); + free_xenheap_page(v); } =20 int arch_vcpu_create(struct vcpu *v) diff --git a/xen/arch/arm/include/asm/new_vgic.h b/xen/arch/arm/include/asm= /new_vgic.h index 1e762138939f..6f7af0e02b2b 100644 --- a/xen/arch/arm/include/asm/new_vgic.h +++ b/xen/arch/arm/include/asm/new_vgic.h @@ -155,7 +155,7 @@ struct vgic_dist { }; =20 struct vgic_cpu { - struct vgic_irq private_irqs[VGIC_NR_PRIVATE_IRQS]; + struct vgic_irq *private_irqs; =20 struct list_head ap_list_head; spinlock_t ap_list_lock; /* Protects the ap_list */ diff --git a/xen/arch/arm/vgic/vgic-init.c b/xen/arch/arm/vgic/vgic-init.c index aef526f2e717..4eb49d922492 100644 --- a/xen/arch/arm/vgic/vgic-init.c +++ b/xen/arch/arm/vgic/vgic-init.c @@ -202,6 +202,11 @@ int vcpu_vgic_init(struct vcpu *v) { int ret =3D 0; =20 + v->arch.vgic.private_irqs =3D + xzalloc_array(struct vgic_irq, VGIC_NR_PRIVATE_IRQS); + if ( !v->arch.vgic.private_irqs ) + return -ENOMEM; + vgic_vcpu_early_init(v); =20 if ( gic_hw_version() =3D=3D GIC_V2 ) @@ -244,6 +249,8 @@ void vcpu_vgic_free(struct vcpu *v) struct vgic_cpu *vgic_cpu =3D &v->arch.vgic; =20 INIT_LIST_HEAD(&vgic_cpu->ap_list_head); + + XFREE(v->arch.vgic.private_irqs); } =20 /* --=20 2.52.0 From nobody Sat Jan 10 00:26:47 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; 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=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1767803378; cv=none; d=zohomail.com; s=zohoarc; b=fm0uhrKwi8CDouU8fUzFtNkcVp5wiFKmCImuH9MsHaFaX0D1wFvILNPVhkPvWHYF91wRuLAgklZi1sW+lj6+ned9WyVuS2xiFfmUPCJxrbPoGu6VpI3V5v+MjRWqvf3/Na0OmB5Aeb4Ommd3lZycSKzsW8wAIKSCPulP2sEs+Jw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1767803378; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=L8UvVrNZgvcTWva9s04sFmSLBrN7YdaYJUEfiGdAX7Q=; b=ANyGPu6HIi/9X9UGs1EvrP7XCjvMSFEkA4Krgxkp3nwX+4dvzs9fUxIddpoigJmhSLKIu3YNY2G6PqD8YG/EIH5RS/TpdN7ES24qnAxfrSpdNUYw4dwPyBRfwj+HmxNqVhgKsoS3hOjhq+G5GUS4QOmtdCDk0f/oDrjNy/7w4xQ= 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 1767803378351876.6552574480397; Wed, 7 Jan 2026 08:29:38 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1196896.1514621 (Exim 4.92) (envelope-from ) id 1vdWPL-0000RK-Gj; Wed, 07 Jan 2026 16:29:15 +0000 Received: by outflank-mailman (output) from mailman id 1196896.1514621; Wed, 07 Jan 2026 16:29: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 1vdWPL-0000Pi-9h; Wed, 07 Jan 2026 16:29:15 +0000 Received: by outflank-mailman (input) for mailman id 1196896; Wed, 07 Jan 2026 16:29:14 +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 1vdWPK-0007tp-KX for xen-devel@lists.xenproject.org; Wed, 07 Jan 2026 16:29:14 +0000 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [2a00:1450:4864:20::62c]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id ff3c6942-ebe5-11f0-9ccf-f158ae23cfc8; Wed, 07 Jan 2026 17:29:11 +0100 (CET) Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-b72b495aa81so431026466b.2 for ; Wed, 07 Jan 2026 08:29:11 -0800 (PST) Received: from fedora (user-109-243-67-101.play-internet.pl. [109.243.67.101]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b842a2bcd30sm564782166b.28.2026.01.07.08.29.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jan 2026 08:29:09 -0800 (PST) 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: ff3c6942-ebe5-11f0-9ccf-f158ae23cfc8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767803350; x=1768408150; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=L8UvVrNZgvcTWva9s04sFmSLBrN7YdaYJUEfiGdAX7Q=; b=Fiq9mrR/lgPz98g/TOzqFOcc4lh94/nmHbVTSA534A6ZCebDpXD2qEsuoWW2Me7sl6 1CQBa/8Lg7vrZJoH+LUUqtJ5zV/UTdCPqAVCjZ1VJIbrV8B0ICC12xZgAn50rX497PxP LvFHl8SxPGU33I8yuT/SEogmuy0iH+gSABrGFgMkDpB23fFFesSh1VSo8HIY8Kkdlise Cn0INJvq4p8FCMXIGtaJuBtKIfKDGh6LeGYt4rXLSWbdxNGi2bj56sbhPCS2DwCV9rox 2QVUcCCzgVX37y2NywAp8nb+Uy8+yOtf/g+K+9AW1L0wgwQyBwIzb8lKM5ZGRfZiY+5s NeTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767803350; x=1768408150; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=L8UvVrNZgvcTWva9s04sFmSLBrN7YdaYJUEfiGdAX7Q=; b=k3dboSc+ah2gydUjNBDMXqiXdndkNMZCvI3Jm97IqkCkpndQHRN2pOiZ8NTVCPsImh pCpQYFHZLtoyndQ6thevVXNLMzTpKwHcKsJuEMv8j2BqA3SQg1xVYLBiiRlzJ5NMEa7x XCR2U3Ta7b2YjKdANRZnw7gPPIbEH0nNB/mI9vHXobsJ+tTwuvIQTNT/MM3heRSdB8M0 /MzcdhRyStRNKGCt4udtqywDoqMmrIwvQUNbDyElKeCBTJHlER+6lAOh/Ivueigh5atp rvU1e/wgPcAfNFgg9LDQypWxV3z8Ucm5kssC93N4fCauBnjWD0Y+e6x+h9cLHn93Ppyk 2whw== X-Gm-Message-State: AOJu0Yy2RC7PpyKaahIlL9DA4EGbCSd2kgLuNS2z3XX8XyeB86q7o+4/ uXwOX7RpKuukeGjLBPp9KQdsDrE+vfngwM6BJJW7stC6e2P7+kyww5v+apq+sw== X-Gm-Gg: AY/fxX76T0+J30IGTy/Qt7pDpTzR6VG0usk025yACnHq41PUXOb0QaG8UsVqFzfiAi5 CVCv5+lR618nMEGu07uBoBEuv8RV8boKT09EE+QdUK6leoS6YEPrb22Q39rcsAA7x4jzuhI4G6e yVHnsVTi0+BC+w2/lC/QAM9h9h3ku10fethA8S1ox3Jagm0iHygLSx4DmI7epw3DS7SUKQNIDrJ iBr3jEVDuV02BXdhaBHoVxPTA1OGFK4fZlkHBj3o2JGtAm1c/GN9nxHkJEiE+AkjajHo1AKMYLM /85Ftt5chz1dTl7diWV3IhtMoyDV/0uQEG9UeMfQI4AY9RGokXDpX4mdo6NErsCjSDn1SgiFE07 iOPdRriQ/b62FB7HllT9QojWiledQItVQAr100bl8mTMS3xo6zk1m0zrpwTYF9NkVFukjtcDRKC XQJVXOWYoOv7R/YjK0BsjQ4KOpQjimXbzpzOUrzpkudV/MOnbcTtQtW2fEhpdgpgH4 X-Google-Smtp-Source: AGHT+IEunqBkiM2UScVpXxO5HUMP2KvMWNBBtele6FJhyy5isAQRlkEX7CZN5hhcYeTwHW/KAZ+nUw== X-Received: by 2002:a17:907:7b8e:b0:b70:b93c:26cf with SMTP id a640c23a62f3a-b84451edb62mr260971566b.6.1767803350258; Wed, 07 Jan 2026 08:29:10 -0800 (PST) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Oleksii Kurochko , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Andrew Cooper , Anthony PERARD , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Timothy Pearson , Alistair Francis , Connor Davis Subject: [PATCH v5 2/3] xen: move alloc/free_vcpu_struct() to common code Date: Wed, 7 Jan 2026 17:28:59 +0100 Message-ID: X-Mailer: git-send-email 2.52.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1767803379481158500 Content-Type: text/plain; charset="utf-8" alloc_vcpu_struct() and free_vcpu_struct() contain little architecture-specific logic and are suitable for sharing across architectures. Move both helpers to common code. To support the remaining architectural differences, introduce arch_vcpu_struct_memflags(), allowing architectures to override the memory flags passed to alloc_xenheap_pages(). This is currently needed by x86, which may require MEMF_bits(32) for HVM guests using shadow paging. The ARM implementation of alloc/free_vcpu_struct() is removed and replaced by the common version. Stub implementations are also dropped from PPC and RISC-V. Now that the size of struct vcpu for Arm64 is smaller than PAGE_SIZE, MAX_PAGES_PER_VCPU is no longer needed and is removed. Finally, make alloc_vcpu_struct() and free_vcpu_struct() static to common/domain.c, as they are no longer used outside common code. No functional changes. Signed-off-by: Oleksii Kurochko Acked-by: Jan Beulich Reviewed-by: Andrew Cooper Acked-by: Michal Orzel --- Changes in v5: - Nothing changed. Only rebase. --- Changes in v4: - Move implementation of alloc_vcpu_struct() and free_vcpu_struct() ahead of vmtrace_free_buffer(). - Add Reviewed-by: Andrew Cooper . - Add Acked-by: Jan Beulich . --- Changes in v3: - Make from function arch_vcpu_struct_memflags() a macros in asm/domain.h. - Drop forward declaration of arch_vcpu_struct_memflags() in asm/domain.h. - Update defintion of arch_vcpu_stuct_memflags() in alloc_vcpu_struct(). --- Changes in v2: - Rework alloc/free_vcpu_struct() to work with only one page. - Return back the comment about the restriction inside x86's arch_vcpu_struct_memflags(). - Drop MAX_PAGES_PER_VCPU. --- xen/arch/arm/domain.c | 17 ----------------- xen/arch/ppc/stubs.c | 10 ---------- xen/arch/riscv/stubs.c | 10 ---------- xen/arch/x86/domain.c | 24 ------------------------ xen/arch/x86/include/asm/domain.h | 12 ++++++++++++ xen/common/domain.c | 20 ++++++++++++++++++++ xen/include/xen/domain.h | 4 ---- 7 files changed, 32 insertions(+), 65 deletions(-) diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c index 64b935b68000..507df807edb8 100644 --- a/xen/arch/arm/domain.c +++ b/xen/arch/arm/domain.c @@ -473,23 +473,6 @@ void dump_pageframe_info(struct domain *d) =20 } =20 -struct vcpu *alloc_vcpu_struct(const struct domain *d) -{ - struct vcpu *v; - - BUILD_BUG_ON(sizeof(*v) > PAGE_SIZE); - v =3D alloc_xenheap_page(); - if ( v !=3D NULL ) - clear_page(v); - - return v; -} - -void free_vcpu_struct(struct vcpu *v) -{ - free_xenheap_page(v); -} - int arch_vcpu_create(struct vcpu *v) { int rc =3D 0; diff --git a/xen/arch/ppc/stubs.c b/xen/arch/ppc/stubs.c index 9953ea1c6c08..f7f6e7ed97af 100644 --- a/xen/arch/ppc/stubs.c +++ b/xen/arch/ppc/stubs.c @@ -152,11 +152,6 @@ void dump_pageframe_info(struct domain *d) BUG_ON("unimplemented"); } =20 -void free_vcpu_struct(struct vcpu *v) -{ - BUG_ON("unimplemented"); -} - int arch_vcpu_create(struct vcpu *v) { BUG_ON("unimplemented"); @@ -264,11 +259,6 @@ void vcpu_kick(struct vcpu *v) BUG_ON("unimplemented"); } =20 -struct vcpu *alloc_vcpu_struct(const struct domain *d) -{ - BUG_ON("unimplemented"); -} - unsigned long hypercall_create_continuation(unsigned int op, const char *format, ...) { diff --git a/xen/arch/riscv/stubs.c b/xen/arch/riscv/stubs.c index 164fc091b28a..29bdb65afbdf 100644 --- a/xen/arch/riscv/stubs.c +++ b/xen/arch/riscv/stubs.c @@ -121,11 +121,6 @@ void dump_pageframe_info(struct domain *d) BUG_ON("unimplemented"); } =20 -void free_vcpu_struct(struct vcpu *v) -{ - BUG_ON("unimplemented"); -} - int arch_vcpu_create(struct vcpu *v) { BUG_ON("unimplemented"); @@ -233,11 +228,6 @@ void vcpu_kick(struct vcpu *v) BUG_ON("unimplemented"); } =20 -struct vcpu *alloc_vcpu_struct(const struct domain *d) -{ - BUG_ON("unimplemented"); -} - unsigned long hypercall_create_continuation(unsigned int op, const char *format, ...) { diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index 7632d5e2d62d..c29a6b0decee 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -493,30 +493,6 @@ unsigned int arch_domain_struct_memflags(void) return MEMF_bits(bits); } =20 -struct vcpu *alloc_vcpu_struct(const struct domain *d) -{ - struct vcpu *v; - /* - * This structure contains embedded PAE PDPTEs, used when an HVM guest - * runs on shadow pagetables outside of 64-bit mode. In this case the = CPU - * may require that the shadow CR3 points below 4GB, and hence the who= le - * structure must satisfy this restriction. Thus we specify MEMF_bits(= 32). - */ - unsigned int memflags =3D - (is_hvm_domain(d) && paging_mode_shadow(d)) ? MEMF_bits(32) : 0; - - BUILD_BUG_ON(sizeof(*v) > PAGE_SIZE); - v =3D alloc_xenheap_pages(0, memflags); - if ( v !=3D NULL ) - clear_page(v); - return v; -} - -void free_vcpu_struct(struct vcpu *v) -{ - free_xenheap_page(v); -} - /* Initialise various registers to their architectural INIT/RESET state. */ void arch_vcpu_regs_init(struct vcpu *v) { diff --git a/xen/arch/x86/include/asm/domain.h b/xen/arch/x86/include/asm/d= omain.h index 16cd45cc32c0..effb23a23416 100644 --- a/xen/arch/x86/include/asm/domain.h +++ b/xen/arch/x86/include/asm/domain.h @@ -15,6 +15,18 @@ unsigned int arch_domain_struct_memflags(void); #define arch_domain_struct_memflags arch_domain_struct_memflags =20 +/* + * This structure contains embedded PAE PDPTEs, used when an HVM guest + * runs on shadow pagetables outside of 64-bit mode. In this case the CPU + * may require that the shadow CR3 points below 4GB, and hence the whole + * structure must satisfy this restriction. Thus we specify MEMF_bits(32). + */ +#define arch_vcpu_struct_memflags(d) ({ \ + const struct domain *d_ =3D (d); \ + \ + (is_hvm_domain(d_) && paging_mode_shadow(d_) ? MEMF_bits(32) : 0); \ +}) + #define has_32bit_shinfo(d) ((d)->arch.has_32bit_shinfo) =20 /* diff --git a/xen/common/domain.c b/xen/common/domain.c index 93c71bc766b0..655d9590f846 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -316,6 +316,26 @@ static void vcpu_info_reset(struct vcpu *v) : &dummy_vcpu_info); } =20 +static struct vcpu *alloc_vcpu_struct(const struct domain *d) +{ +#ifndef arch_vcpu_struct_memflags +# define arch_vcpu_struct_memflags(d) ((void)(d), 0) +#endif + struct vcpu *v; + + BUILD_BUG_ON(sizeof(*v) > PAGE_SIZE); + v =3D alloc_xenheap_pages(0, arch_vcpu_struct_memflags(d)); + if ( v ) + clear_page(v); + + return v; +} + +static void free_vcpu_struct(struct vcpu *v) +{ + free_xenheap_page(v); +} + static void vmtrace_free_buffer(struct vcpu *v) { const struct domain *d =3D v->domain; diff --git a/xen/include/xen/domain.h b/xen/include/xen/domain.h index 8aab05ae93c8..644f5ac3f293 100644 --- a/xen/include/xen/domain.h +++ b/xen/include/xen/domain.h @@ -70,10 +70,6 @@ void domid_free(domid_t domid); struct domain *alloc_domain_struct(void); void free_domain_struct(struct domain *d); =20 -/* Allocate/free a VCPU structure. */ -struct vcpu *alloc_vcpu_struct(const struct domain *d); -void free_vcpu_struct(struct vcpu *v); - /* Allocate/free a PIRQ structure. */ #ifndef alloc_pirq_struct struct pirq *alloc_pirq_struct(struct domain *d); --=20 2.52.0 From nobody Sat Jan 10 00:26:47 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; 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=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1767803369; cv=none; d=zohomail.com; s=zohoarc; b=THaWDyHHEPhVZtpHEOf4KY8rCaVkDClCml0czOTiNmyaZFLNm9N065+WccKqvjegIcis1klLAJfaljpnXZJorJH9ktq0ryxRa1AAK6i4MJajUn9jHDDmamWwaTU8W5pKAm74r7JZd5oUqTSOwvOU+CZycKYmvERorjBAgvwoXyo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1767803369; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=+ez9JtZF2nCaMC9sk3cjdnVhQzElopUuISWmFxgfkIg=; b=jx02dcalFGY605FiccMP3Dio8bKOR6nAyCJn5LojxB05mLJ0Y6+uShdzdK1OcOormFpjXlGuIXI99K5WOqT/fanSvFeSZk/OoJ9tYhOpGytyHeoe3PYl7jhlUmRBYBMUPf7fxP0CfDR2KQe2SWbOUii9MaAlk1hjPsYeiZK3dfw= 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 1767803369159477.55794023605915; Wed, 7 Jan 2026 08:29:29 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1196895.1514616 (Exim 4.92) (envelope-from ) id 1vdWPL-0000Od-5g; Wed, 07 Jan 2026 16:29:15 +0000 Received: by outflank-mailman (output) from mailman id 1196895.1514616; Wed, 07 Jan 2026 16:29: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 1vdWPL-0000OS-2E; Wed, 07 Jan 2026 16:29:15 +0000 Received: by outflank-mailman (input) for mailman id 1196895; Wed, 07 Jan 2026 16:29:14 +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 1vdWPK-0008M3-9N for xen-devel@lists.xenproject.org; Wed, 07 Jan 2026 16:29:14 +0000 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [2a00:1450:4864:20::52c]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id ffb0f3ea-ebe5-11f0-b15e-2bf370ae4941; Wed, 07 Jan 2026 17:29:12 +0100 (CET) Received: by mail-ed1-x52c.google.com with SMTP id 4fb4d7f45d1cf-64d30dc4ed7so4330057a12.0 for ; Wed, 07 Jan 2026 08:29:12 -0800 (PST) Received: from fedora (user-109-243-67-101.play-internet.pl. [109.243.67.101]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b842a2bcd30sm564782166b.28.2026.01.07.08.29.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jan 2026 08:29:10 -0800 (PST) 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: ffb0f3ea-ebe5-11f0-b15e-2bf370ae4941 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767803351; x=1768408151; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+ez9JtZF2nCaMC9sk3cjdnVhQzElopUuISWmFxgfkIg=; b=gMSUDviglT8AuI7JEqJj33JZyB396lQQ7TbKWt0CkqlZtW4XMNPCTy48bczNcjJ9vz gkiI4V/a/G+3ga3f6s9tAvjDN5BkFIsiuqw0xn7dYc47V/vrwy+1wB5LZSB6sP5R7ucd 6dQT4hmZRlN/q+9LyK3lsUSPUTh+WgtF38LojOyTSzZJNCHIVn31B1Wo8nmn9YqN6US3 D+3ba2+gUii4WgGHfzSwKqK0Dcn2XZMzv0LEpVG55ug+YiH3KyBZObeshpxlQDAi2Mw4 x49ZsWzVeA6WfYdLSdc291uWYYOiEsFxbgLfwZnMcMfTYlShVevcjftu7gpiz2U+YskY +aAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767803351; x=1768408151; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=+ez9JtZF2nCaMC9sk3cjdnVhQzElopUuISWmFxgfkIg=; b=T5aqGMnT0lIiS/0GccVwQ320OrX7ENd/TW8ZLn2LSPLn1qYlU/nNmkUA8WloSsGMpo dc9Xb5yxNA0dXHdaOsiAcoa47mQfs4ZyacjEulkifEOwlu8F4gEqJGFnxwCINTw0+mS2 LpYG7Cc9is2troxn8x/jc3oIz395y0dzOca/wAVvFc8nJCk2DDGSVjU3jceKle6OYEIg vUiFwqoaMFupMBlYbSMpsRxD4Y3sueaB/q30j5Ljp0gPtDltt2m2jWrcac6m5y8J3tCY jx5U9QI7LFgE1/aU51Gbz6gg8TkA/5z2hW2S3Pk5kWldwyeTRFaKhaSJMt193vl2y0Ty aYug== X-Gm-Message-State: AOJu0YymjiUdv1tqdBcSYTkerUZ5CEhfoiJMCGqHTW9T8P3cbbbASDJF ihIFc/3Qk5648mJ3l69SEvJFap5jusuj0hGRdkGB+bPtPHmB7eklN3bb9wX3LA== X-Gm-Gg: AY/fxX5ia+3cRWrK/pwmgZbCH/8YLtYwWFWSxDMQix/bnSe6/uiCdURX1s8kBQhf3TR umHRSIWeLn8DQx+GgRaHIEbgZXNI0ckh3NgjkXHUPeOhrHgcSS/vQ1BRuxe/8fTZ9Z2zKH1dj3w /nRy5nKCf3RzIJTBb/f2VSgJRJty1yqAHD0pmyIxy29/p007H2QyzMBq+rFq+jONlwvW6PJbmx9 ogwF9uJK6x5B72UYXF+RT890ATzyUHuK39RN+OsqZfZYXnayb3h6iPyvhhObt9Ho3hKbMGqMAE7 r1ChBhACz7Mcix1HsUirf7qiuQKwnnN6/XMxuenGjzU+hO2PagFSALsWRoHZIbtbzl9+AUozJoI iP7rM/7G+1lrtOPQpgYShRylfFU5oWFoTyf8NVlo8CYVahiUL/JaSLtMC4l/aEKmm+WoLB0q++f P5k8FVfkpSVQSP6ULOzedyhLGqcuWJv3lzMhewC3dUL3YPueX3KYiuKQ== X-Google-Smtp-Source: AGHT+IHV63gItJh83a3Xjq66Fr6D9okyLbTXxBWVEeQ7oPpDm6Zy3VvB5Ttt/7AsQUQhSv/m0Z66yQ== X-Received: by 2002:a17:907:1c8c:b0:b83:a4a7:725e with SMTP id a640c23a62f3a-b8444c9e3c8mr352466566b.24.1767803351213; Wed, 07 Jan 2026 08:29:11 -0800 (PST) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Oleksii Kurochko , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini Subject: [PATCH v5 3/3] xen/common: make {alloc,free}_domain_struct() static Date: Wed, 7 Jan 2026 17:29:00 +0100 Message-ID: X-Mailer: git-send-email 2.52.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1767803369590158500 Content-Type: text/plain; charset="utf-8" As {alloc,free}_domain_struct() are used only within domain.c, they can be declared static and their declarations removed from xen/domain.h. Signed-off-by: Oleksii Kurochko Acked-by: Andrew Cooper --- Changes in v5: - Nothing changed. Only rebase. --- Changes in v4: - Move implementation of alloc_domain_struct() and free_domain_struct() ahead of alloc_vcpu_struct(). --- Changes in v3: - Move alloc_domain_struct() and free_domain_struct() to not have forward declaration. - Add Acked-by: Andrew Cooper . --- Changes in v2: - New patch. --- xen/common/domain.c | 42 ++++++++++++++++++++-------------------- xen/include/xen/domain.h | 4 ---- 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/xen/common/domain.c b/xen/common/domain.c index 655d9590f846..ed4b6175de0b 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -316,6 +316,27 @@ static void vcpu_info_reset(struct vcpu *v) : &dummy_vcpu_info); } =20 +static struct domain *alloc_domain_struct(void) +{ +#ifndef arch_domain_struct_memflags +# define arch_domain_struct_memflags() 0 +#endif + + struct domain *d =3D alloc_xenheap_pages(0, arch_domain_struct_memflag= s()); + + BUILD_BUG_ON(sizeof(*d) > PAGE_SIZE); + + if ( d ) + clear_page(d); + + return d; +} + +static void free_domain_struct(struct domain *d) +{ + free_xenheap_page(d); +} + static struct vcpu *alloc_vcpu_struct(const struct domain *d) { #ifndef arch_vcpu_struct_memflags @@ -819,27 +840,6 @@ static int sanitise_domain_config(struct xen_domctl_cr= eatedomain *config) return arch_sanitise_domain_config(config); } =20 -struct domain *alloc_domain_struct(void) -{ -#ifndef arch_domain_struct_memflags -# define arch_domain_struct_memflags() 0 -#endif - - struct domain *d =3D alloc_xenheap_pages(0, arch_domain_struct_memflag= s()); - - BUILD_BUG_ON(sizeof(*d) > PAGE_SIZE); - - if ( d ) - clear_page(d); - - return d; -} - -void free_domain_struct(struct domain *d) -{ - free_xenheap_page(d); -} - struct domain *domain_create(domid_t domid, struct xen_domctl_createdomain *config, unsigned int flags) diff --git a/xen/include/xen/domain.h b/xen/include/xen/domain.h index 644f5ac3f293..273717c31b3f 100644 --- a/xen/include/xen/domain.h +++ b/xen/include/xen/domain.h @@ -66,10 +66,6 @@ void domid_free(domid_t domid); * Arch-specifics. */ =20 -/* Allocate/free a domain structure. */ -struct domain *alloc_domain_struct(void); -void free_domain_struct(struct domain *d); - /* Allocate/free a PIRQ structure. */ #ifndef alloc_pirq_struct struct pirq *alloc_pirq_struct(struct domain *d); --=20 2.52.0