From nobody Mon Mar 23 19:54:38 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 header.i=julian.vetter@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=none dis=none) header.from=vates.tech ARC-Seal: i=1; a=rsa-sha256; t=1773659867; cv=none; d=zohomail.com; s=zohoarc; b=T3TjajWYC96IU0xBJY+kYjfB8Wcyojt8EGU+UO/PuJsYBGq+EhWfJX5FcwvHFwQVeguoRU8oR1prr+sNlM3bC4fxelmOh79KJJ8gExSi6bYeBGnNkAImr+NQniZCWOZ/u5oNcy9WD9HLbBGcWb9AgX7mZnKDk2zPTlaR77OL1Vc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1773659867; h=Content-Type: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=1rdsgYGrdZ+Aj6vu34GfiCU8HteOHeBAK+Ods8sd53g=; b=E99mh6gCTN2u7FnWk+NzOWA+R7GbRxz30mGwhWPAlmrb/X5kID75/54ct6f8wyvgGcXVE7rX1jJi5735XFXRDU1tzpwhz8wFNElNCTCDOlkCI/kQu+N2DJNLd0W5YDOT/DaOOKTTONXMB0fTA5SU9yY4SNzu2dVY69L5nBEEHA4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=julian.vetter@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=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1773659867161586.0986319925206; Mon, 16 Mar 2026 04:17:47 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1255502.1550440 (Exim 4.92) (envelope-from ) id 1w25wj-00083a-An; Mon, 16 Mar 2026 11:17:17 +0000 Received: by outflank-mailman (output) from mailman id 1255502.1550440; Mon, 16 Mar 2026 11:17: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 1w25wj-00082j-7T; Mon, 16 Mar 2026 11:17:17 +0000 Received: by outflank-mailman (input) for mailman id 1255502; Mon, 16 Mar 2026 11:17:15 +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 1w25wh-00080D-Fc for xen-devel@lists.xenproject.org; Mon, 16 Mar 2026 11:17:15 +0000 Received: from mail136-12.atl41.mandrillapp.com (mail136-12.atl41.mandrillapp.com [198.2.136.12]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id a7533da5-2129-11f1-9ccf-f158ae23cfc8; Mon, 16 Mar 2026 12:17:01 +0100 (CET) Received: from pmta11.mandrill.prod.atl01.rsglab.com (localhost [127.0.0.1]) by mail136-12.atl41.mandrillapp.com (Mailchimp) with ESMTP id 4fZCGh2Mgfz5QkT4q for ; Mon, 16 Mar 2026 11:17:00 +0000 (GMT) Received: from [37.26.189.201] by mandrillapp.com id 096817dc48ee470daf05cea08c53910a; Mon, 16 Mar 2026 11:17:00 +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: a7533da5-2129-11f1-9ccf-f158ae23cfc8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandrillapp.com; s=mte1; t=1773659820; x=1773929820; bh=1rdsgYGrdZ+Aj6vu34GfiCU8HteOHeBAK+Ods8sd53g=; h=From:Subject:To:Cc:Message-Id:In-Reply-To:References:Feedback-ID: Date:MIME-Version:Content-Type:Content-Transfer-Encoding:CC:Date: Subject:From; b=KsoMc2o9rnN1cBHUFtsRMm0buK7ivoy7p+CFHHXmhGwQrtDGvzuYw2clTd47xw562 z7hsc38a+9+l9K9orfmcOFch5uxY1qZPqZuAX9n0jhPyP87YKL3aycAJZfxJfa9L6R zPJuC/dKhlGZMlZS3KlRADuAmzCAHpOVeAEYcm1MnVDfm7MQROBQOR6XtNN78UctnX Ci+CNVzEneh6prBdX1YN1KQGsk0VPJ5FPZdLR+7zMWFQgzHkFKSrIK8lIM9xvm+W7r RnPxH8b1LK4XXRqwmwIWfqkj6BdAZKealS7vMdGs7f8hk+I8TgUHX8DuUDqHaqlusd oBDMfK19xUoDw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vates.tech; s=mte1; t=1773659820; x=1773920320; i=julian.vetter@vates.tech; bh=1rdsgYGrdZ+Aj6vu34GfiCU8HteOHeBAK+Ods8sd53g=; h=From:Subject:To:Cc:Message-Id:In-Reply-To:References:Feedback-ID: Date:MIME-Version:Content-Type:Content-Transfer-Encoding:CC:Date: Subject:From; b=Bxl3/X9AGtgxVEiWpx+oJf9jqOyGEY6Im/amXa19x+ahVssXvRvIqto+OwgcCrVVy olQ7R7Z3oraWvce6WEOvsEK73wo+5Wn4NHlIIo+5qEz6+NssA2rNhNGsKNlUdXa30d umq6uIgRSrqCN4pZRuW//ir54uHyaY7FKS9yhIz9Z9nqW51k9KQSsCuhiWfNUe3rkW CnFYbHqYzEG7KoJGhp9X4RklHR7aBNa4jIo1FQh49SIaohvoqkGIjgytT47mimnB8g VqJq9JrvX8rnvnb9vd8qKUMbmMSAnJ8aLQBGZdMzsp9Bmf2oVKXcy0YUHVh/ka8ZDQ 6xsX7tKZ/+GVA== From: "Julian Vetter" Subject: =?utf-8?Q?[PATCH=20v5=201/3]=20ioreq:=20Unify=20buf=20and=20non-buf=20ioreq=20page=20management?= X-Mailer: git-send-email 2.51.0 X-Bm-Disclaimer: Yes X-Bm-Milter-Handled: 4ffbd6c1-ee69-4e1b-aabd-f977039bd3e2 X-Bm-Transport-Timestamp: 1773659819095 To: xen-devel@lists.xenproject.org Cc: "Jan Beulich" , "Andrew Cooper" , "=?utf-8?Q?Roger=20Pau=20Monn=C3=A9?=" , "Anthony PERARD" , "Michal Orzel" , "Julien Grall" , "Stefano Stabellini" , "Julian Vetter" Message-Id: <20260316111653.178104-2-julian.vetter@vates.tech> In-Reply-To: <20260316111653.178104-1-julian.vetter@vates.tech> References: <20260316111653.178104-1-julian.vetter@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.096817dc48ee470daf05cea08c53910a?= X-Mandrill-User: md_30504962 Feedback-ID: 30504962:30504962.20260316:md Date: Mon, 16 Mar 2026 11:17:00 +0000 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @mandrillapp.com) (identity julian.vetter@vates.tech) X-ZM-MESSAGEID: 1773659868305154100 Content-Type: text/plain; charset="utf-8" Switch the ioreq page mapping in hvm_map_ioreq_gfn() from prepare_ring_for_helper() / __map_domain_page_global() to explicit vmap(), aligning it with ioreq_server_alloc_mfn() which already allocates domain-heap pages and will now also map them via vmap(). With both paths using vmap(), vmap_to_page() can recover the struct page_info * uniformly during teardown, removing the need to cache the page pointer in struct ioreq_page. So, drop the 'page' field from struct ioreq_page and update all callers accordingly. Signed-off-by: Julian Vetter --- Changes in v5: - New patch that unforms the buf and non-buf code path --- xen/arch/x86/hvm/ioreq.c | 57 ++++++++++++++++++++++++++++++++-------- xen/common/ioreq.c | 36 +++++++++++++------------ xen/include/xen/ioreq.h | 1 - 3 files changed, 65 insertions(+), 29 deletions(-) diff --git a/xen/arch/x86/hvm/ioreq.c b/xen/arch/x86/hvm/ioreq.c index a5fa97e149..145dcba5c1 100644 --- a/xen/arch/x86/hvm/ioreq.c +++ b/xen/arch/x86/hvm/ioreq.c @@ -15,6 +15,7 @@ #include #include #include +#include #include =20 #include @@ -128,8 +129,9 @@ static void hvm_unmap_ioreq_gfn(struct ioreq_server *s,= bool buf) if ( gfn_eq(iorp->gfn, INVALID_GFN) ) return; =20 - destroy_ring_for_helper(&iorp->va, iorp->page); - iorp->page =3D NULL; + put_page_and_type(vmap_to_page(iorp->va)); + vunmap(iorp->va); + iorp->va =3D NULL; =20 hvm_free_ioreq_gfn(s, iorp->gfn); iorp->gfn =3D INVALID_GFN; @@ -139,9 +141,13 @@ static int hvm_map_ioreq_gfn(struct ioreq_server *s, b= ool buf) { struct domain *d =3D s->target; struct ioreq_page *iorp =3D buf ? &s->bufioreq : &s->ioreq; + struct page_info *page; + p2m_type_t p2mt; + gfn_t base_gfn; + mfn_t mfn; int rc; =20 - if ( iorp->page ) + if ( iorp->va ) { /* * If a page has already been allocated (which will happen on @@ -157,17 +163,45 @@ static int hvm_map_ioreq_gfn(struct ioreq_server *s, = bool buf) if ( d->is_dying ) return -EINVAL; =20 - iorp->gfn =3D hvm_alloc_ioreq_gfn(s); + base_gfn =3D hvm_alloc_ioreq_gfn(s); =20 - if ( gfn_eq(iorp->gfn, INVALID_GFN) ) + if ( gfn_eq(base_gfn, INVALID_GFN) ) return -ENOMEM; =20 - rc =3D prepare_ring_for_helper(d, gfn_x(iorp->gfn), &iorp->page, - &iorp->va); - + /* + * vmap() is used for the Xen-side mapping so that vmap_to_page() can + * recover the struct page_info * during teardown, consistent with + * ioreq_server_alloc_mfn(). + */ + rc =3D check_get_page_from_gfn(d, base_gfn, false, &p2mt, &page); if ( rc ) - hvm_unmap_ioreq_gfn(s, buf); + { + if ( rc =3D=3D -EAGAIN ) + rc =3D -ENOENT; + goto fail; + } + + if ( !get_page_type(page, PGT_writable_page) ) + { + put_page(page); + rc =3D -EINVAL; + goto fail; + } + + mfn =3D page_to_mfn(page); + iorp->va =3D vmap(&mfn, 1); + if ( !iorp->va ) + { + put_page_and_type(page); + rc =3D -ENOMEM; + goto fail; + } + + iorp->gfn =3D base_gfn; + return 0; =20 + fail: + hvm_free_ioreq_gfn(s, base_gfn); return rc; } =20 @@ -179,7 +213,7 @@ static void hvm_remove_ioreq_gfn(struct ioreq_server *s= , bool buf) if ( gfn_eq(iorp->gfn, INVALID_GFN) ) return; =20 - if ( p2m_remove_page(d, iorp->gfn, page_to_mfn(iorp->page), 0) ) + if ( p2m_remove_page(d, iorp->gfn, page_to_mfn(vmap_to_page(iorp->va))= , 0) ) domain_crash(d); clear_page(iorp->va); } @@ -195,7 +229,8 @@ static int hvm_add_ioreq_gfn(struct ioreq_server *s, bo= ol buf) =20 clear_page(iorp->va); =20 - rc =3D p2m_add_page(d, iorp->gfn, page_to_mfn(iorp->page), 0, p2m_ram_= rw); + rc =3D p2m_add_page(d, iorp->gfn, page_to_mfn(vmap_to_page(iorp->va)),= 0, + p2m_ram_rw); if ( rc =3D=3D 0 ) paging_mark_pfn_dirty(d, _pfn(gfn_x(iorp->gfn))); =20 diff --git a/xen/common/ioreq.c b/xen/common/ioreq.c index f5fd30ce12..5b026fc1b2 100644 --- a/xen/common/ioreq.c +++ b/xen/common/ioreq.c @@ -17,11 +17,11 @@ */ =20 #include -#include #include #include #include #include +#include #include #include #include @@ -262,8 +262,9 @@ static int ioreq_server_alloc_mfn(struct ioreq_server *= s, bool buf) { struct ioreq_page *iorp =3D buf ? &s->bufioreq : &s->ioreq; struct page_info *page; + mfn_t mfn; =20 - if ( iorp->page ) + if ( iorp->va ) { /* * If a guest frame has already been mapped (which may happen @@ -291,11 +292,11 @@ static int ioreq_server_alloc_mfn(struct ioreq_server= *s, bool buf) return -ENODATA; } =20 - iorp->va =3D __map_domain_page_global(page); + mfn =3D page_to_mfn(page); + iorp->va =3D vmap(&mfn, 1); if ( !iorp->va ) goto fail; =20 - iorp->page =3D page; clear_page(iorp->va); return 0; =20 @@ -309,14 +310,13 @@ static int ioreq_server_alloc_mfn(struct ioreq_server= *s, bool buf) static void ioreq_server_free_mfn(struct ioreq_server *s, bool buf) { struct ioreq_page *iorp =3D buf ? &s->bufioreq : &s->ioreq; - struct page_info *page =3D iorp->page; + struct page_info *page; =20 - if ( !page ) + if ( !iorp->va ) return; =20 - iorp->page =3D NULL; - - unmap_domain_page_global(iorp->va); + page =3D vmap_to_page(iorp->va); + vunmap(iorp->va); iorp->va =3D NULL; =20 put_page_alloc_ref(page); @@ -333,7 +333,8 @@ bool is_ioreq_server_page(struct domain *d, const struc= t page_info *page) =20 FOR_EACH_IOREQ_SERVER(d, id, s) { - if ( (s->ioreq.page =3D=3D page) || (s->bufioreq.page =3D=3D page)= ) + if ( (s->ioreq.va && vmap_to_page(s->ioreq.va) =3D=3D page) || + (s->bufioreq.va && vmap_to_page(s->bufioreq.va) =3D=3D page) ) { found =3D true; break; @@ -626,11 +627,12 @@ static void ioreq_server_deinit(struct ioreq_server *= s) /* * NOTE: It is safe to call both arch_ioreq_server_unmap_pages() and * ioreq_server_free_pages() in that order. - * This is because the former will do nothing if the pages - * are not mapped, leaving the page to be freed by the latter. - * However if the pages are mapped then the former will set - * the page_info pointer to NULL, meaning the latter will do - * nothing. + * arch_ioreq_server_unmap_pages() handles the GFN-mapped path + * (iorp->gfn !=3D INVALID_GFN) and clears iorp->va on completio= n, + * so ioreq_server_free_pages() will find iorp->va =3D=3D NULL a= nd + * do nothing. Conversely, pages allocated via the resource path + * have iorp->gfn =3D=3D INVALID_GFN, so arch_ioreq_server_unmap= _pages() + * is a no-op and ioreq_server_free_pages() handles the teardown. */ arch_ioreq_server_unmap_pages(s); ioreq_server_free_pages(s); @@ -819,12 +821,12 @@ int ioreq_server_get_frame(struct domain *d, ioservid= _t id, if ( !HANDLE_BUFIOREQ(s) ) goto out; =20 - *mfn =3D page_to_mfn(s->bufioreq.page); + *mfn =3D page_to_mfn(vmap_to_page(s->bufioreq.va)); rc =3D 0; break; =20 case XENMEM_resource_ioreq_server_frame_ioreq(0): - *mfn =3D page_to_mfn(s->ioreq.page); + *mfn =3D page_to_mfn(vmap_to_page(s->ioreq.va)); rc =3D 0; break; =20 diff --git a/xen/include/xen/ioreq.h b/xen/include/xen/ioreq.h index e86f0869fa..d63fa4729e 100644 --- a/xen/include/xen/ioreq.h +++ b/xen/include/xen/ioreq.h @@ -25,7 +25,6 @@ =20 struct ioreq_page { gfn_t gfn; - struct page_info *page; void *va; }; =20 --=20 2.51.0 -- Julian Vetter | Vates Hypervisor & Kernel Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech From nobody Mon Mar 23 19:54:38 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 header.i=julian.vetter@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=none dis=none) header.from=vates.tech ARC-Seal: i=1; a=rsa-sha256; t=1773659863; cv=none; d=zohomail.com; s=zohoarc; b=dfB4E/PYqZ1oJ0byrzKmJTFunVol3UNeOYGTA576QRDMK9dMo6RSS4jSlGFHQVbToiPMVHuKXVaBA5t+QPFI2c9EALbqy45wSjxtPVRyfwk+5tZ32aG0JT7ylwfC4FjSB3uXqklpwlbrOuDnlYMhT5D7LXcnGhdPOu4CTpF6ll4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1773659863; h=Content-Type: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=+jyFTwFYuserZEOMpVEgWJSZYL1w2mjTqGK6jzypT0I=; b=cP76Y4vN4E8T4/BXIyEzUu9FmYURki/EE+0daz9S5NV1ibwNfQtDfvqNrGziIIvaU2QQV47trWoM3fTnQed5uaUe7pNYeJtMYeVSoSE1RNVPH95onwEsZ5kNeBs9rRzBACW+vglaixf513iAXRSA9mENAT90DI6RWkx8IaLk9LY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=julian.vetter@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=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1773659863191928.6132385639336; Mon, 16 Mar 2026 04:17:43 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1255501.1550436 (Exim 4.92) (envelope-from ) id 1w25wj-00080b-3d; Mon, 16 Mar 2026 11:17:17 +0000 Received: by outflank-mailman (output) from mailman id 1255501.1550436; Mon, 16 Mar 2026 11:17: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 1w25wj-00080U-0C; Mon, 16 Mar 2026 11:17:17 +0000 Received: by outflank-mailman (input) for mailman id 1255501; Mon, 16 Mar 2026 11:17:15 +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 1w25wg-00080D-TQ for xen-devel@lists.xenproject.org; Mon, 16 Mar 2026 11:17:15 +0000 Received: from mail134-15.atl141.mandrillapp.com (mail134-15.atl141.mandrillapp.com [198.2.134.15]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id a75eee81-2129-11f1-9ccf-f158ae23cfc8; Mon, 16 Mar 2026 12:17:01 +0100 (CET) Received: from pmta10.mandrill.prod.atl01.rsglab.com (localhost [127.0.0.1]) by mail134-15.atl141.mandrillapp.com (Mailchimp) with ESMTP id 4fZCGh4H9jzPm0YZj for ; Mon, 16 Mar 2026 11:17:00 +0000 (GMT) Received: from [37.26.189.201] by mandrillapp.com id f9e7604dea514ce6a47de6ca2a96bfec; Mon, 16 Mar 2026 11:17:00 +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: a75eee81-2129-11f1-9ccf-f158ae23cfc8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandrillapp.com; s=mte1; t=1773659820; x=1773929820; bh=+jyFTwFYuserZEOMpVEgWJSZYL1w2mjTqGK6jzypT0I=; h=From:Subject:To:Cc:Message-Id:In-Reply-To:References:Feedback-ID: Date:MIME-Version:Content-Type:Content-Transfer-Encoding:CC:Date: Subject:From; b=b/rioPjRFM71JvbNPuslFzKgTlmrGWg2V8o4bkdM6WxuijC+eK6DGxOQn47645q/N czv3nhJ69suuZzBLBWAgD8jLQrfbRGEQiDnN7HAj09jRZMooModCGhtsptThXilng+ PCC0WLPbCHm64zQA+MjGa/aYzqP3gb5kMJsWQr0RDf1ux414eO/M3ICXhsl1DhDPRe vsoDz2axejzYZI0yw1InI+SZX7PVlwZ3KzbF2oSKqpucy+qXTMbHB7EXRpEbV/S2si hh1bQhQXAc/63UP+48v17qmAeo+xwQwPaXmsri7MERPf+tSrXRTu3Xujsepmt/KC8l ArFkIhiF3gj7w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vates.tech; s=mte1; t=1773659820; x=1773920320; i=julian.vetter@vates.tech; bh=+jyFTwFYuserZEOMpVEgWJSZYL1w2mjTqGK6jzypT0I=; h=From:Subject:To:Cc:Message-Id:In-Reply-To:References:Feedback-ID: Date:MIME-Version:Content-Type:Content-Transfer-Encoding:CC:Date: Subject:From; b=DOrnxcJNpUJbY4mR1svKfLZ8HBP7FvExNnXxzF7n0rPr65bHWrqaAh4E3URo9aeIj FucUDuZkR/As4TdHB8yf1lC0zqgdzPc6n6w8TG7XkBlU9P4NOxSufBPKodIwZ9w6da tp3GyFkJMh+TSkE1v/f5xnDBnz307aVsH62yVTTNleiw28oTNiHQdEkIXxYpIs8xON Cq9/8+bZhWSy3IhaoYx8QLtUGM1SKcPHDsJ++SSYDa2sGcf3JBuk0CvqVlKec9xR/r n0reaqjZZHL2kJCbjF6g+ip70VH99Nhovmd0HbmJcFwsEnMFXqHh6Z2DO8hTaNUwXi tdD18KwTVITzw== From: "Julian Vetter" Subject: =?utf-8?Q?[PATCH=20v5=202/3]=20ioreq:=20Indent=20ioreq=5Fserver=5F{alloc,free}=5Fmfn()=20body=20one=20level=20deeper?= X-Mailer: git-send-email 2.51.0 X-Bm-Disclaimer: Yes X-Bm-Milter-Handled: 4ffbd6c1-ee69-4e1b-aabd-f977039bd3e2 X-Bm-Transport-Timestamp: 1773659819392 To: xen-devel@lists.xenproject.org Cc: "Jan Beulich" , "Andrew Cooper" , "=?utf-8?Q?Roger=20Pau=20Monn=C3=A9?=" , "Anthony PERARD" , "Michal Orzel" , "Julien Grall" , "Stefano Stabellini" , "Julian Vetter" Message-Id: <20260316111653.178104-3-julian.vetter@vates.tech> In-Reply-To: <20260316111653.178104-1-julian.vetter@vates.tech> References: <20260316111653.178104-1-julian.vetter@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.f9e7604dea514ce6a47de6ca2a96bfec?= X-Mandrill-User: md_30504962 Feedback-ID: 30504962:30504962.20260316:md Date: Mon, 16 Mar 2026 11:17:00 +0000 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity julian.vetter@vates.tech) (identity @mandrillapp.com) X-ZM-MESSAGEID: 1773659865477158500 Content-Type: text/plain; charset="utf-8" No functional change. It adds a wrapping block to prepare for the loop that the subsequent patch introduces to handle multiple ioreq pages. Signed-off-by: Julian Vetter --- Changes in v5 - Added proper commit message and fixed commit title --- xen/common/ioreq.c | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/xen/common/ioreq.c b/xen/common/ioreq.c index 5b026fc1b2..b22f656701 100644 --- a/xen/common/ioreq.c +++ b/xen/common/ioreq.c @@ -277,22 +277,24 @@ static int ioreq_server_alloc_mfn(struct ioreq_server= *s, bool buf) return 0; } =20 - page =3D alloc_domheap_page(s->target, MEMF_no_refcount); + { + page =3D alloc_domheap_page(s->target, MEMF_no_refcount); =20 - if ( !page ) - return -ENOMEM; + if ( !page ) + return -ENOMEM; =20 - if ( !get_page_and_type(page, s->target, PGT_writable_page) ) - { - /* - * The domain can't possibly know about this page yet, so failure - * here is a clear indication of something fishy going on. - */ - domain_crash(s->emulator); - return -ENODATA; - } + if ( !get_page_and_type(page, s->target, PGT_writable_page) ) + { + /* + * The domain can't possibly know about this page yet, so fail= ure + * here is a clear indication of something fishy going on. + */ + domain_crash(s->emulator); + return -ENODATA; + } =20 - mfn =3D page_to_mfn(page); + mfn =3D page_to_mfn(page); + } iorp->va =3D vmap(&mfn, 1); if ( !iorp->va ) goto fail; @@ -315,12 +317,14 @@ static void ioreq_server_free_mfn(struct ioreq_server= *s, bool buf) if ( !iorp->va ) return; =20 - page =3D vmap_to_page(iorp->va); - vunmap(iorp->va); - iorp->va =3D NULL; + { + page =3D vmap_to_page(iorp->va); + vunmap(iorp->va); + iorp->va =3D NULL; =20 - put_page_alloc_ref(page); - put_page_and_type(page); + put_page_alloc_ref(page); + put_page_and_type(page); + } } =20 bool is_ioreq_server_page(struct domain *d, const struct page_info *page) --=20 2.51.0 -- Julian Vetter | Vates Hypervisor & Kernel Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech From nobody Mon Mar 23 19:54:38 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 header.i=julian.vetter@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=none dis=none) header.from=vates.tech ARC-Seal: i=1; a=rsa-sha256; t=1773659863; cv=none; d=zohomail.com; s=zohoarc; b=NPQCDICSItbeyTZAUQwyxKxKiXuSXFs5hTPKOMLgrgbOJx/O0CMdDF4kisJVhqOl6jNmGBdCMdVZ49hQzNn0uB3EnINQo1z2Dg7toIXm7yUUBss5UdxEzeMARYu3zwP1MNVyrLAtXn4mx2dXQb48i43y9Tk9ma8ddyC9K9cgTGA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1773659863; h=Content-Type: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=6RYWc6Fjxgy8OveMTnPi/ksrvu05Heao6RIo3wosYw8=; b=EKMbn8lsaYzRh0T9P9Mv5IEezXGigWzoYSG/MWoEEtsJTlSm/9z4HL0F17pQDHgJbkLg+JS+benSql4vDg1rYyfX6SD0rw/tE+t1DE9CEzCZS/+EWxxeIERjlBCnRIt4NZHc7FZBUCMwJzG3ZWyEDkdAKWPy0nP5KJ6MC4R8sUU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=julian.vetter@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=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1773659863170150.7774111701675; Mon, 16 Mar 2026 04:17:43 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1255503.1550448 (Exim 4.92) (envelope-from ) id 1w25wj-0008Dj-Q4; Mon, 16 Mar 2026 11:17:17 +0000 Received: by outflank-mailman (output) from mailman id 1255503.1550448; Mon, 16 Mar 2026 11:17: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 1w25wj-0008C7-Kp; Mon, 16 Mar 2026 11:17:17 +0000 Received: by outflank-mailman (input) for mailman id 1255503; Mon, 16 Mar 2026 11:17:16 +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 1w25wi-00080O-HU for xen-devel@lists.xenproject.org; Mon, 16 Mar 2026 11:17:16 +0000 Received: from mail136-12.atl41.mandrillapp.com (mail136-12.atl41.mandrillapp.com [198.2.136.12]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id af652f1c-2129-11f1-b164-2bf370ae4941; Mon, 16 Mar 2026 12:17:15 +0100 (CET) Received: from pmta11.mandrill.prod.atl01.rsglab.com (localhost [127.0.0.1]) by mail136-12.atl41.mandrillapp.com (Mailchimp) with ESMTP id 4fZCGh5gmcz5QkW27 for ; Mon, 16 Mar 2026 11:17:00 +0000 (GMT) Received: from [37.26.189.201] by mandrillapp.com id 384f3c454f2b4e7a96bf99f610f55f96; Mon, 16 Mar 2026 11:17:00 +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: af652f1c-2129-11f1-b164-2bf370ae4941 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandrillapp.com; s=mte1; t=1773659820; x=1773929820; bh=6RYWc6Fjxgy8OveMTnPi/ksrvu05Heao6RIo3wosYw8=; h=From:Subject:To:Cc:Message-Id:In-Reply-To:References:Feedback-ID: Date:MIME-Version:Content-Type:Content-Transfer-Encoding:CC:Date: Subject:From; b=pvkx76ahf78bKM6fYZmuZ+wRuUNX+O6vpujMXp8XfA9jurWPMN6l2p1/r17IYvKt/ u5GsiPew3GZWQpMVBUt/HBd6XD9/jZ7o2jY//lpm0YjqMttqY9WjwQ2BOWWhpm+oFv jxpZ/wvRgZighI1wY8TuodkidWbwAtOuQ8ASwuRBCVJwX96XwCBeNEavpBGwLSxBFM ZLfXhJp+r9Yf7FM8DN0xEgOfKqJApD5/g7uyZy3ua9ubptLd9MUzxVjlzFe/RMJ/Kc 5Wcw174sM7Xxb7omove/6hHpY5+EX+4soSmWv7mzHmkqyHSRRrIIFy2H7B92jfmfOl 4LhJs45priH3A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vates.tech; s=mte1; t=1773659820; x=1773920320; i=julian.vetter@vates.tech; bh=6RYWc6Fjxgy8OveMTnPi/ksrvu05Heao6RIo3wosYw8=; h=From:Subject:To:Cc:Message-Id:In-Reply-To:References:Feedback-ID: Date:MIME-Version:Content-Type:Content-Transfer-Encoding:CC:Date: Subject:From; b=XzCqO8EqfeFZCh5tfbSRLQGEIxJ8xbxHAnfIL3u3MjHI3fgViqivWyelLgVFivG2x +ROtvIb+dX3jqMa6kfum4LU1TEW+sIt1r0LnnxCIOBzZst8G2m3s4YGwJSAiCX+W7P 1E8DSsnxNPsj/NNlgTfkZU10GTkGqjIbJckcRV2YA856duhEjR4XVcPsRH2aoTct5d 20ZarZGw/CY8+0T/N1rfr+H6fcHFVlMjmlSfpl7BqUN7SVCY1VUSPFYlWZbSo6fLUV HPPUyEKINZkVbSTa36uzCr2RshR0jIMsXTnFeJMrEu0eikGg6QMNaRgzbSy0+Fajfx IQsSTIyjVZPnw== From: "Julian Vetter" Subject: =?utf-8?Q?[PATCH=20v5=203/3]=20x86/ioreq:=20Extend=20ioreq=20server=20to=20support=20multiple=20ioreq=20pages?= X-Mailer: git-send-email 2.51.0 X-Bm-Disclaimer: Yes X-Bm-Milter-Handled: 4ffbd6c1-ee69-4e1b-aabd-f977039bd3e2 X-Bm-Transport-Timestamp: 1773659819650 To: xen-devel@lists.xenproject.org Cc: "Jan Beulich" , "Andrew Cooper" , "=?utf-8?Q?Roger=20Pau=20Monn=C3=A9?=" , "Anthony PERARD" , "Michal Orzel" , "Julien Grall" , "Stefano Stabellini" , "Julian Vetter" Message-Id: <20260316111653.178104-4-julian.vetter@vates.tech> In-Reply-To: <20260316111653.178104-1-julian.vetter@vates.tech> References: <20260316111653.178104-1-julian.vetter@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.384f3c454f2b4e7a96bf99f610f55f96?= X-Mandrill-User: md_30504962 Feedback-ID: 30504962:30504962.20260316:md Date: Mon, 16 Mar 2026 11:17:00 +0000 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity julian.vetter@vates.tech) (identity @mandrillapp.com) X-ZM-MESSAGEID: 1773659864642154100 Content-Type: text/plain; charset="utf-8" A domain with more than (PAGE_SIZE / sizeof(ioreq_t)) vCPUs needs more than one ioreq page to hold all per-vCPU ioreq slots. In order to support this a number of changes have been made: 1. Add nr_ioreq_pages() to compute the required number of pages, defined as DIV_ROUND_UP(d->max_vcpus, PAGE_SIZE / sizeof(ioreq_t)) 2. ioreq_server_alloc_mfn() now allocates nr_ioreq_pages() pages for the non-buf case, builds an mfn_t array, and calls vmap() to map them contiguously. The buf path remains single-page. 3. ioreq_server_free_mfn() uses vmap_size() to determine how many pages to release. 4. is_ioreq_server_page() loops over all mapped ioreq pages using vmap_size() and vmap_to_page() with per-page offsets 5. ioreq_server_get_frame() now handles idx values in the range [XENMEM_resource_ioreq_server_frame_ioreq(0), XENMEM_resource_ioreq_server_frame_ioreq(nr_pages - 1)], returning the MFN via vmap_to_mfn() with the appropriate page offset. The legacy GFN path (hvm_map_ioreq_gfn) is restricted to single-page. Domains with more vCPUs must use XENMEM_acquire_resource! Signed-off-by: Julian Vetter --- Changes in v5: - Reduced complexity a lot because there is no distinction between buf and !buf case - Directly use va and gfn from struct ioreq_page, dropped additional members in struct ioreq_server --- xen/arch/x86/hvm/ioreq.c | 8 +++ xen/common/ioreq.c | 103 +++++++++++++++++++++++++++++---------- xen/include/xen/ioreq.h | 6 +++ 3 files changed, 90 insertions(+), 27 deletions(-) diff --git a/xen/arch/x86/hvm/ioreq.c b/xen/arch/x86/hvm/ioreq.c index 145dcba5c1..872247e300 100644 --- a/xen/arch/x86/hvm/ioreq.c +++ b/xen/arch/x86/hvm/ioreq.c @@ -163,6 +163,14 @@ static int hvm_map_ioreq_gfn(struct ioreq_server *s, b= ool buf) if ( d->is_dying ) return -EINVAL; =20 + /* + * The legacy GFN path supports only a single ioreq page. Guests requi= ring + * more ioreq slots must use the resource mapping interface + * (XENMEM_acquire_resource). + */ + if ( !buf && nr_ioreq_pages(d) > 1 ) + return -EOPNOTSUPP; + base_gfn =3D hvm_alloc_ioreq_gfn(s); =20 if ( gfn_eq(base_gfn, INVALID_GFN) ) diff --git a/xen/common/ioreq.c b/xen/common/ioreq.c index b22f656701..71fac2bc7b 100644 --- a/xen/common/ioreq.c +++ b/xen/common/ioreq.c @@ -261,8 +261,9 @@ bool vcpu_ioreq_handle_completion(struct vcpu *v) static int ioreq_server_alloc_mfn(struct ioreq_server *s, bool buf) { struct ioreq_page *iorp =3D buf ? &s->bufioreq : &s->ioreq; - struct page_info *page; - mfn_t mfn; + unsigned int i, nr_pages =3D buf ? 1 : nr_ioreq_pages(s->target); + mfn_t *mfns; + int rc; =20 if ( iorp->va ) { @@ -277,11 +278,20 @@ static int ioreq_server_alloc_mfn(struct ioreq_server= *s, bool buf) return 0; } =20 + mfns =3D xmalloc_array(mfn_t, nr_pages); + if ( !mfns ) + return -ENOMEM; + + for ( i =3D 0; i < nr_pages; i++ ) { - page =3D alloc_domheap_page(s->target, MEMF_no_refcount); + struct page_info *page =3D alloc_domheap_page(s->target, + MEMF_no_refcount); =20 if ( !page ) - return -ENOMEM; + { + rc =3D -ENOMEM; + goto fail; + } =20 if ( !get_page_and_type(page, s->target, PGT_writable_page) ) { @@ -290,41 +300,60 @@ static int ioreq_server_alloc_mfn(struct ioreq_server= *s, bool buf) * here is a clear indication of something fishy going on. */ domain_crash(s->emulator); - return -ENODATA; + rc =3D -ENODATA; + goto fail; } =20 - mfn =3D page_to_mfn(page); + mfns[i] =3D page_to_mfn(page); } - iorp->va =3D vmap(&mfn, 1); + + iorp->va =3D vmap(mfns, nr_pages); if ( !iorp->va ) + { + rc =3D -ENOMEM; goto fail; + } + + xfree(mfns); + + for ( i =3D 0; i < nr_pages; i++ ) + clear_page((char *)iorp->va + i * PAGE_SIZE); =20 - clear_page(iorp->va); return 0; =20 fail: - put_page_alloc_ref(page); - put_page_and_type(page); + while ( i-- ) + { + struct page_info *page =3D mfn_to_page(mfns[i]); + + put_page_alloc_ref(page); + put_page_and_type(page); + } + xfree(mfns); =20 - return -ENOMEM; + return rc; } =20 static void ioreq_server_free_mfn(struct ioreq_server *s, bool buf) { struct ioreq_page *iorp =3D buf ? &s->bufioreq : &s->ioreq; - struct page_info *page; + unsigned int i, nr_pages; =20 if ( !iorp->va ) return; =20 + nr_pages =3D vmap_size(iorp->va); + + for ( i =3D 0; i < nr_pages; i++ ) { - page =3D vmap_to_page(iorp->va); - vunmap(iorp->va); - iorp->va =3D NULL; + struct page_info *page =3D vmap_to_page(iorp->va + i * PAGE_SIZE); =20 put_page_alloc_ref(page); put_page_and_type(page); } + + vunmap(iorp->va); + iorp->va =3D NULL; } =20 bool is_ioreq_server_page(struct domain *d, const struct page_info *page) @@ -337,12 +366,28 @@ bool is_ioreq_server_page(struct domain *d, const str= uct page_info *page) =20 FOR_EACH_IOREQ_SERVER(d, id, s) { - if ( (s->ioreq.va && vmap_to_page(s->ioreq.va) =3D=3D page) || - (s->bufioreq.va && vmap_to_page(s->bufioreq.va) =3D=3D page) ) + if ( s->bufioreq.va && vmap_to_page(s->bufioreq.va) =3D=3D page ) { found =3D true; break; } + + if ( s->ioreq.va ) + { + unsigned int i; + + for ( i =3D 0; i < vmap_size(s->ioreq.va); i++ ) + { + if ( vmap_to_page(s->ioreq.va + i * PAGE_SIZE) =3D=3D page= ) + { + found =3D true; + break; + } + } + + if ( found ) + break; + } } =20 rspin_unlock(&d->ioreq_server.lock); @@ -818,26 +863,30 @@ int ioreq_server_get_frame(struct domain *d, ioservid= _t id, if ( rc ) goto out; =20 - switch ( idx ) + if ( idx =3D=3D XENMEM_resource_ioreq_server_frame_bufioreq ) { - case XENMEM_resource_ioreq_server_frame_bufioreq: rc =3D -ENOENT; if ( !HANDLE_BUFIOREQ(s) ) goto out; =20 *mfn =3D page_to_mfn(vmap_to_page(s->bufioreq.va)); rc =3D 0; - break; + } + else if ( idx >=3D XENMEM_resource_ioreq_server_frame_ioreq(0) && + idx < XENMEM_resource_ioreq_server_frame_ioreq(nr_ioreq_page= s(d)) ) + { + unsigned int page_idx =3D idx - XENMEM_resource_ioreq_server_frame= _ioreq(0); + if ( page_idx >=3D vmap_size(s->ioreq.va) ) + { + rc =3D -EINVAL; + goto out; + } =20 - case XENMEM_resource_ioreq_server_frame_ioreq(0): - *mfn =3D page_to_mfn(vmap_to_page(s->ioreq.va)); + *mfn =3D vmap_to_mfn(s->ioreq.va + page_idx * PAGE_SIZE); rc =3D 0; - break; - - default: - rc =3D -EINVAL; - break; } + else + rc =3D -EINVAL; =20 out: rspin_unlock(&d->ioreq_server.lock); diff --git a/xen/include/xen/ioreq.h b/xen/include/xen/ioreq.h index d63fa4729e..c12480472d 100644 --- a/xen/include/xen/ioreq.h +++ b/xen/include/xen/ioreq.h @@ -19,6 +19,7 @@ #ifndef __XEN_IOREQ_H__ #define __XEN_IOREQ_H__ =20 +#include #include =20 #include @@ -82,6 +83,11 @@ static inline bool ioreq_needs_completion(const ioreq_t = *ioreq) #define HANDLE_BUFIOREQ(s) \ ((s)->bufioreq_handling !=3D HVM_IOREQSRV_BUFIOREQ_OFF) =20 +static inline unsigned int nr_ioreq_pages(const struct domain *d) +{ + return DIV_ROUND_UP(d->max_vcpus, PAGE_SIZE / sizeof(ioreq_t)); +} + bool domain_has_ioreq_server(const struct domain *d); =20 bool vcpu_ioreq_pending(struct vcpu *v); --=20 2.51.0 -- Julian Vetter | Vates Hypervisor & Kernel Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech