From nobody Tue Feb 10 04:15:37 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; 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=fail(p=none dis=none) header.from=arm.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1652346767147892.0526138497369; Thu, 12 May 2022 02:12:47 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.327495.550347 (Exim 4.92) (envelope-from ) id 1np4rx-0001X8-1e; Thu, 12 May 2022 09:12:25 +0000 Received: by outflank-mailman (output) from mailman id 327495.550347; Thu, 12 May 2022 09:12:25 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1np4rw-0001Wz-Sr; Thu, 12 May 2022 09:12:24 +0000 Received: by outflank-mailman (input) for mailman id 327495; Thu, 12 May 2022 09:12:24 +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 1np4rw-0000Wp-1r for xen-devel@lists.xenproject.org; Thu, 12 May 2022 09:12:24 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id a1f9c86e-d1d3-11ec-8fc4-03012f2f19d4; Thu, 12 May 2022 11:12:23 +0200 (CEST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 67EFE106F; Thu, 12 May 2022 02:12:22 -0700 (PDT) Received: from a011292.shanghai.arm.com (a011292.shanghai.arm.com [10.169.190.94]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 89FF63F73D; Thu, 12 May 2022 02:12:19 -0700 (PDT) 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: a1f9c86e-d1d3-11ec-8fc4-03012f2f19d4 From: Penny Zheng To: xen-devel@lists.xenproject.org Cc: wei.chen@arm.com, Penny Zheng , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , Penny Zheng Subject: [PATCH v3 4/8] xen/arm: introduce put_page_nr and get_page_nr Date: Thu, 12 May 2022 17:11:25 +0800 Message-Id: <20220512091129.2802997-5-Penny.Zheng@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220512091129.2802997-1-Penny.Zheng@arm.com> References: <20220512091129.2802997-1-Penny.Zheng@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1652346767524100001 Content-Type: text/plain; charset="utf-8" Later, we need to add the right amount of references, which should be the number of borrower domains, to the owner domain. Since we only have get_page() to increment the page reference by 1, a loop is needed per page, which is inefficient and time-consuming. To save the loop time, this commit introduces a set of new helpers put_page_nr() and get_page_nr() to increment/drop the page reference by nr. Signed-off-by: Penny Zheng --- v3 changes: - check overflow with "n" - remove spurious change - bring back the check that we enter the loop only when count_info is greater than 0 --- v2 change: - new commit --- xen/arch/arm/include/asm/mm.h | 4 ++++ xen/arch/arm/mm.c | 36 ++++++++++++++++++++++++++--------- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/xen/arch/arm/include/asm/mm.h b/xen/arch/arm/include/asm/mm.h index 424aaf2823..c737d51e4d 100644 --- a/xen/arch/arm/include/asm/mm.h +++ b/xen/arch/arm/include/asm/mm.h @@ -347,6 +347,10 @@ void free_init_memory(void); int guest_physmap_mark_populate_on_demand(struct domain *d, unsigned long = gfn, unsigned int order); =20 +extern bool get_page_nr(struct page_info *page, const struct domain *domai= n, + unsigned long nr); +extern void put_page_nr(struct page_info *page, unsigned long nr); + extern void put_page_type(struct page_info *page); static inline void put_page_and_type(struct page_info *page) { diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 7b1f2f4906..a9461e07aa 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1537,7 +1537,8 @@ long arch_memory_op(int op, XEN_GUEST_HANDLE_PARAM(vo= id) arg) return 0; } =20 -struct domain *page_get_owner_and_reference(struct page_info *page) +static struct domain *page_get_owner_and_nr_reference(struct page_info *pa= ge, + unsigned long nr) { unsigned long x, y =3D page->count_info; struct domain *owner; @@ -1548,10 +1549,10 @@ struct domain *page_get_owner_and_reference(struct = page_info *page) * Count =3D=3D 0: Page is not allocated, so we cannot take a ref= erence. * Count =3D=3D -1: Reference count would wrap, which is invalid. */ - if ( unlikely(((x + 1) & PGC_count_mask) <=3D 1) ) + if ( unlikely(((x + nr) & PGC_count_mask) <=3D 1) ) return NULL; } - while ( (y =3D cmpxchg(&page->count_info, x, x + 1)) !=3D x ); + while ( (y =3D cmpxchg(&page->count_info, x, x + nr)) !=3D x ); =20 owner =3D page_get_owner(page); ASSERT(owner); @@ -1559,14 +1560,20 @@ struct domain *page_get_owner_and_reference(struct = page_info *page) return owner; } =20 -void put_page(struct page_info *page) +struct domain *page_get_owner_and_reference(struct page_info *page) +{ + return page_get_owner_and_nr_reference(page, 1); +} + +void put_page_nr(struct page_info *page, unsigned long nr) { unsigned long nx, x, y =3D page->count_info; =20 do { - ASSERT((y & PGC_count_mask) !=3D 0); + ASSERT(((y & PGC_count_mask) !=3D 0) && + (((y - nr) & PGC_count_mask) >=3D 0)); x =3D y; - nx =3D x - 1; + nx =3D x - nr; } while ( unlikely((y =3D cmpxchg(&page->count_info, x, nx)) !=3D x) ); =20 @@ -1576,19 +1583,30 @@ void put_page(struct page_info *page) } } =20 -bool get_page(struct page_info *page, const struct domain *domain) +void put_page(struct page_info *page) { - const struct domain *owner =3D page_get_owner_and_reference(page); + put_page_nr(page, 1); +} + +bool get_page_nr(struct page_info *page, const struct domain *domain, + unsigned long nr) +{ + const struct domain *owner =3D page_get_owner_and_nr_reference(page, n= r); =20 if ( likely(owner =3D=3D domain) ) return true; =20 if ( owner !=3D NULL ) - put_page(page); + put_page_nr(page, nr); =20 return false; } =20 +bool get_page(struct page_info *page, const struct domain *domain) +{ + return get_page_nr(page, domain, 1); +} + /* Common code requires get_page_type and put_page_type. * We don't care about typecounts so we just do the minimum to make it * happy. */ --=20 2.25.1