From nobody Tue Feb 10 07:22:15 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 ARC-Seal: i=1; a=rsa-sha256; t=1671193100; cv=none; d=zohomail.com; s=zohoarc; b=YwRVrfko8KlojBe7d6xSH4uNH9Q6UXm4fBSCYcTbAkrNPPAPXNxK4usfiSNuSR0HPC548wzugqtn35JXfBIAs9snpgsQjg/+A+senY2+gArB3mubYX3eZ3q8fiHKx+NG/6WlZLWe/QlARvmeY9Vd57IWn3Ab/EP74sWRhJ+4dhA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671193100; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=UCQfX8iMvnpIt+Q9gV/nKjf8GUqEBVsJAQhHBiS7Ykk=; b=I4/1VFzLqlHU7sBxtDue6Xx+WAjSN5BuW8fx82PPPvvTTnPoYo8HtImE2ZN5lo9IGKZDEhyWnFIjwzSuhSt4T5b8Uft/eUhnRW8FlejZw56mr8Q5FFdga3CrepWZvQzASvhMuVBVaIYH4R6T2+y+poVZPkaCNvihXrx7vPutmrI= 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1671193100241181.49687225894422; Fri, 16 Dec 2022 04:18:20 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.464569.723032 (Exim 4.92) (envelope-from ) id 1p69en-00086G-Ve; Fri, 16 Dec 2022 12:17:41 +0000 Received: by outflank-mailman (output) from mailman id 464569.723032; Fri, 16 Dec 2022 12:17:41 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p69en-000816-HE; Fri, 16 Dec 2022 12:17:41 +0000 Received: by outflank-mailman (input) for mailman id 464569; Fri, 16 Dec 2022 12:17:38 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p69ej-0007Lc-Vo for xen-devel@lists.xenproject.org; Fri, 16 Dec 2022 12:17:37 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p69ej-00034Y-Sl; Fri, 16 Dec 2022 12:17:37 +0000 Received: from 54-240-197-232.amazon.com ([54.240.197.232] helo=dev-dsk-jgrall-1b-035652ec.eu-west-1.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1p69DJ-0004sN-Dg; Fri, 16 Dec 2022 11:49:17 +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" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=UCQfX8iMvnpIt+Q9gV/nKjf8GUqEBVsJAQhHBiS7Ykk=; b=jEszd2vIHifnpJMEMVuX8p5kmR qYfa3fiRP+5C70UMHtfog9ySnwE3LVN9RbTWolgSzo4ZPz+gbwXBqNA7frqhrYsXSLHZnHU11Cp75 4cZAuMWYr3CNX/4btJCn1A7sBfNu0PBSJNDACFYRzlX3m3Ph8bF90N91n3El1tYg4L5E=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: julien@xen.org, Hongyan Xia , Andrew Cooper , George Dunlap , Jan Beulich , Stefano Stabellini , Wei Liu , Julien Grall Subject: [PATCH 15/22] xen/page_alloc: add a path for xenheap when there is no direct map Date: Fri, 16 Dec 2022 11:48:46 +0000 Message-Id: <20221216114853.8227-16-julien@xen.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221216114853.8227-1-julien@xen.org> References: <20221216114853.8227-1-julien@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) X-ZM-MESSAGEID: 1671193100911100001 Content-Type: text/plain; charset="utf-8" From: Hongyan Xia When there is not an always-mapped direct map, xenheap allocations need to be mapped and unmapped on-demand. Signed-off-by: Hongyan Xia Signed-off-by: Julien Grall ---- I have left the call to map_pages_to_xen() and destroy_xen_mappings() in the split heap for now. I am not entirely convinced this is necessary because in that setup only the xenheap would be always mapped and this doesn't contain any guest memory (aside the grant-table). So map/unmapping for every allocation seems unnecessary. Changes since Hongyan's version: * Rebase * Fix indentation in alloc_xenheap_pages() * Fix build for arm32 --- xen/common/page_alloc.c | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 0a950288e241..0c4af5a71407 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -2222,6 +2222,7 @@ void init_xenheap_pages(paddr_t ps, paddr_t pe) void *alloc_xenheap_pages(unsigned int order, unsigned int memflags) { struct page_info *pg; + void *ret; =20 ASSERT_ALLOC_CONTEXT(); =20 @@ -2230,17 +2231,36 @@ void *alloc_xenheap_pages(unsigned int order, unsig= ned int memflags) if ( unlikely(pg =3D=3D NULL) ) return NULL; =20 + ret =3D page_to_virt(pg); + + if ( !arch_has_directmap() && + map_pages_to_xen((unsigned long)ret, page_to_mfn(pg), 1UL << orde= r, + PAGE_HYPERVISOR) ) + { + /* Failed to map xenheap pages. */ + free_heap_pages(pg, order, false); + return NULL; + } + return page_to_virt(pg); } =20 =20 void free_xenheap_pages(void *v, unsigned int order) { + unsigned long va =3D (unsigned long)v & PAGE_MASK; + ASSERT_ALLOC_CONTEXT(); =20 if ( v =3D=3D NULL ) return; =20 + if ( !arch_has_directmap() && + destroy_xen_mappings(va, va + (1UL << (order + PAGE_SHIFT))) ) + dprintk(XENLOG_WARNING, + "Error while destroying xenheap mappings at %p, order %u\n= ", + v, order); + free_heap_pages(virt_to_page(v), order, false); } =20 @@ -2264,6 +2284,7 @@ void *alloc_xenheap_pages(unsigned int order, unsigne= d int memflags) { struct page_info *pg; unsigned int i; + void *ret; =20 ASSERT_ALLOC_CONTEXT(); =20 @@ -2276,16 +2297,28 @@ void *alloc_xenheap_pages(unsigned int order, unsig= ned int memflags) if ( unlikely(pg =3D=3D NULL) ) return NULL; =20 + ret =3D page_to_virt(pg); + + if ( !arch_has_directmap() && + map_pages_to_xen((unsigned long)ret, page_to_mfn(pg), 1UL << orde= r, + PAGE_HYPERVISOR) ) + { + /* Failed to map xenheap pages. */ + free_domheap_pages(pg, order); + return NULL; + } + for ( i =3D 0; i < (1u << order); i++ ) pg[i].count_info |=3D PGC_xen_heap; =20 - return page_to_virt(pg); + return ret; } =20 void free_xenheap_pages(void *v, unsigned int order) { struct page_info *pg; unsigned int i; + unsigned long va =3D (unsigned long)v & PAGE_MASK; =20 ASSERT_ALLOC_CONTEXT(); =20 @@ -2297,6 +2330,12 @@ void free_xenheap_pages(void *v, unsigned int order) for ( i =3D 0; i < (1u << order); i++ ) pg[i].count_info &=3D ~PGC_xen_heap; =20 + if ( !arch_has_directmap() && + destroy_xen_mappings(va, va + (1UL << (order + PAGE_SHIFT))) ) + dprintk(XENLOG_WARNING, + "Error while destroying xenheap mappings at %p, order %u\n= ", + v, order); + free_heap_pages(pg, order, true); } =20 --=20 2.38.1