From nobody Mon May 6 03:22:13 2024 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=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1638563672; cv=none; d=zohomail.com; s=zohoarc; b=fDH/xz5ADPVIwfJrRkd5c6z8r0/MYBdeZxk9QxhAOemqskaGoqyzZ0i8wrpkgIB6ciQ4eXBb1n88nfLtmNH4hhSDJo4/+bU4dovwso/04IKK9z6j+L4bnAZA7I4vx/7qxrUt9sIWxv9bXnV2iNzub/LjZFPQ1sEs5dsrRatj6yY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1638563672; h=Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:Sender:Subject:To; bh=P3/coR+Ce+KVGKSZhioMDcgTipywu+ws8A9dJr646ig=; b=hb+X3ZAwfcTOHxQ3Tqs6MNLrq2IjBaYzkRonGTuGgaIaE3thsyb0ijf1JKTSxiK1fedIjujcxCXAK6XyMo9y9Q3o3LLTFuLoydEyyAshaaN3AnC2LAFGeqzkq/er9MwwD3F8Dl8o02QQRM528hCwLdrRCskD+3qrXLVUFHQOkzE= 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 1638563672134945.5045314043857; Fri, 3 Dec 2021 12:34:32 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.237961.412656 (Exim 4.92) (envelope-from ) id 1mtFFo-0001F3-UZ; Fri, 03 Dec 2021 20:34:00 +0000 Received: by outflank-mailman (output) from mailman id 237961.412656; Fri, 03 Dec 2021 20:34:00 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mtFFo-0001Ew-Rg; Fri, 03 Dec 2021 20:34:00 +0000 Received: by outflank-mailman (input) for mailman id 237961; Fri, 03 Dec 2021 20:33:59 +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 1mtFFn-0001Eq-6c for xen-devel@lists.xenproject.org; Fri, 03 Dec 2021 20:33:59 +0000 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [2a00:1450:4864:20::42a]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 5601af36-5478-11ec-8a4d-196798b21f7b; Fri, 03 Dec 2021 21:33:57 +0100 (CET) Received: by mail-wr1-x42a.google.com with SMTP id q3so8135471wru.5 for ; Fri, 03 Dec 2021 12:33:56 -0800 (PST) Received: from otyshchenko.router ([212.22.223.21]) by smtp.gmail.com with ESMTPSA id q26sm3512045wrc.39.2021.12.03.12.33.54 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 Dec 2021 12:33:54 -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: 5601af36-5478-11ec-8a4d-196798b21f7b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id; bh=P3/coR+Ce+KVGKSZhioMDcgTipywu+ws8A9dJr646ig=; b=LyzHFQOJydTY0dTQ9IiPnaEzQOlDFtUpNULqLvhCU+K3+vxJBHyZ39531/gGP4l29e s/bSiNsOMg76kEpKtK/cseYGHUAIehIy09cgowPrKeqUBufjB0Ytmzjy3Bm0nL32CX1h r3NN2dUyeJgRBL69Pur7sUk7ykuKOoYBZ3OYzDtixffTlhON5hmU1uJYXw45mFrbqKav c72EI1R9MMnx5//Cd1LnBmbvrqkyUGiv6pvxLmeGDX/k3exScS0Dxt28JyGaSIGCJPlX pFFWgJqogsf0hkSWMCSjt6sq/sK+K6I4nV//Qqzk/50Afs6xgIva5e79qBKTrqwukVl5 6Njg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=P3/coR+Ce+KVGKSZhioMDcgTipywu+ws8A9dJr646ig=; b=Q6J5kLeN4AzIioSS45f6OcaU/6JCXFHclft5rd6bK5Y/BRNI9+jFHyHgf1eRQSEZas G35DPsSyQ4PCVlB8qZt0Kpqs/YHb5ZWkV3qxyNAeTnVDoPM3NXaOQ9fijnY1ajMWimzA +t7iIcmkCueBCZHruexSBGQha1G9njCzkfpqMgeiK91yDd+5gpfcg90K4sXozxDt1i87 gEoXxASZjbwFBCeiiqUcBfiwjsHO4wD9+12u1WAt/XO74WhpWhQgPltpzotTxXwDEK3S JOdSf3YJNLqUMEKrJn6B1uueilzzL70v/VWZ5C1O/n9vrq1dNkPw14BxPHHI1/s3bjOr ZVxQ== X-Gm-Message-State: AOAM531oYe9iiBnURzqqr+q869WL0sPHKGwaGZ63RTI30l3HdbDRoAJp q8M9Hi6URjsmwqDqIDMpPGoCuTQiWnw= X-Google-Smtp-Source: ABdhPJzCPEm5ernGdJkUaeY4aMhqxbyqZEf73lTI/M/t1xgZ1oGcrHhjca1bEcrvEV7ChopMEhPfew== X-Received: by 2002:adf:fa81:: with SMTP id h1mr23769190wrr.27.1638563635137; Fri, 03 Dec 2021 12:33:55 -0800 (PST) From: Oleksandr Tyshchenko To: xen-devel@lists.xenproject.org Cc: Oleksandr Tyshchenko , Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Bertrand Marquis , Andrew Cooper , George Dunlap , Ian Jackson , Jan Beulich , Wei Liu , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Bob Eshleman , Alistair Francis , Connor Davis Subject: [PATCH V4] xen/gnttab: Store frame GFN in struct page_info on Arm Date: Fri, 3 Dec 2021 22:33:30 +0200 Message-Id: <1638563610-4419-1-git-send-email-olekstysh@gmail.com> X-Mailer: git-send-email 2.7.4 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1638563673120100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Oleksandr Tyshchenko Rework Arm implementation to store grant table frame GFN in struct page_info directly instead of keeping it in standalone status/shared arrays. This patch is based on the assumption that grant table page is the xenheap page. To cover 64-bit/40-bit IPA on Arm64/Arm32 we need the space to hold 52-bit/28-bit + extra bit value respectively. In order to not grow the size of struct page_info borrow the required amount of bits from type_info's count portion which current context won't suffer (currently only 1 bit is used on Arm). Please note, to minimize code changes and avoid introducing an extra #ifdef-s to the header, we keep the same amount of bits on both subarches, although the count portion on Arm64 could be wider, so we waste some bits here. Introduce corresponding PGT_* constructs and access macros. Update existing gnttab macros to deal with GFN value according to new location. Also update the use of count portion on Arm in share_xen_page_with_guest(). While at it, extend this simplified M2P-like approach for any xenheap pages which are proccessed in xenmem_add_to_physmap_one() except foreign ones. Update the code to set GFN portion after establishing new mapping for the xenheap page in said function and to clean GFN portion when putting a reference on that page in p2m_put_l3_page(). And for everything to work correctly introduce arch-specific macros arch_alloc_(free)xenheap_page to be called from alloc_(free)xenheap_pages() respectively, the former's purpose on Arm is to clear the GFN portion before use, the latter was left dummy for now. On x86 both are just stubs. This patch is intended to fix the potential issue on Arm which might happen when remapping grant-table frame. A guest (or the toolstack) will unmap the grant-table frame using XENMEM_remove_physmap. This is a generic hypercall, so on x86, we are relying on the fact the M2P entry will be cleared on removal. For architecture without the M2P, the GFN would still be present in the grant frame/status array. So on the next call to map the page, we will end up to request the P2M to remove whatever mapping was the given GFN. This could well be another mapping. Besides that, this patch simplifies arch code on Arm by removing arrays and corresponding management code and as the result gnttab_init_arch/gnttab_destroy_arch helpers and struct grant_table_arch become useless and can be dropped globally. Suggested-by: Julien Grall Signed-off-by: Oleksandr Tyshchenko --- Dear @RISC-V maintainers, please note in current patch I drop arch specific gnttab_init(destroy)_arch helpers as unneeded for both Arm and x86. Please let me know if you are going to reuse them in the nearest future and I will retain them. You can find the related discussions at: https://lore.kernel.org/xen-devel/93d0df14-2c8a-c2e3-8c51-54412190171c@xen.= org/ https://lore.kernel.org/xen-devel/1628890077-12545-1-git-send-email-oleksty= sh@gmail.com/ https://lore.kernel.org/xen-devel/1631652245-30746-1-git-send-email-oleksty= sh@gmail.com/ https://lore.kernel.org/xen-devel/1632425551-18910-1-git-send-email-oleksty= sh@gmail.com/ Changes RFC1 -> RFC2: - update patch description - add/update comments in code - clarify check in p2m_put_l3_page() - introduce arch_alloc_xenheap_page() and arch_free_xenheap_page() and drop page_arch_init() - add ASSERT to gnttab_shared_page() and gnttab_status_page() - rework changes to Arm's struct page_info: do not split type_info, allocate GFN portion by reducing count portion, create corresponding PGT_* construct, etc - update page_get_frame_gfn() and page_set_frame_gfn() - update the use of count portion on Arm - drop the leading underscore in the macro parameter names Changes RFC2 -> RFC3: - update patch description - drop PGT_count_base and MASK_INSR() in share_xen_page_with_guest() - update alloc_xenheap_page() and free_xenheap_page() for SEPARATE_XENHEAP case (Arm32) - provide an extra bit for GFN portion, to get PGT_INVALID_FRAME_GFN one bit more than the maximum number of physical address bits on Arm32 Changes RFC3 -> V4: - rebase on Jan's "gnttab: remove guest_physmap_remove_page() call from gnttab_map_frame()" - finally resolve locking question by recent Julien's suggestion, so drop the RFC tag - update comments in Arm's mm.h/p2m.c to not mention grant table - convert page_set(get)_frame_gfn to static inline func and rename them to page_set(get)_xenheap_gfn() - rename PGT_INVALID_FRAME_GFN to PGT_INVALID_XENHEAP_GFN - add ASSERT(is_xen_heap_page(...)) in page_set(get)_frame_gfn - remove BUG_ON() in arch_free_xenheap_page - remove local type_info in share_xen_page_with_guest() - remove an extra argument p2m in p2m_put_l3_page() - remove #ifdef CONFIG_GRANT_TABLE in p2m_put_l3_page() - also cover real-only pages by using p2m_is_ram instead of a check against p2m_ram_rw in p2m_put_l3_page() and use "else if" construct - call arch_free_xenheap_page() before clearing the PGC_xen_heap in free_xenheap_pages() - remove ASSERT() in gnttab_shared(status)_page and use simpler virt_to_page - remove local pg_ in gnttab_shared(status)_gfn - update patch description to reflect recent changes --- xen/arch/arm/mm.c | 24 ++++++++++++++-- xen/arch/arm/p2m.c | 7 +++-- xen/common/grant_table.c | 9 ------ xen/common/page_alloc.c | 20 +++++++++++++- xen/include/asm-arm/grant_table.h | 58 ++++++++++++-----------------------= ---- xen/include/asm-arm/mm.h | 39 ++++++++++++++++++++++++-- xen/include/asm-x86/grant_table.h | 5 ---- xen/include/asm-x86/mm.h | 4 +++ 8 files changed, 102 insertions(+), 64 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index eea926d..4f4cab3 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1382,8 +1382,10 @@ void share_xen_page_with_guest(struct page_info *pag= e, struct domain *d, spin_lock(&d->page_alloc_lock); =20 /* The incremented type count pins as writable or read-only. */ - page->u.inuse.type_info =3D - (flags =3D=3D SHARE_ro ? PGT_none : PGT_writable_page) | 1; + page->u.inuse.type_info &=3D ~(PGT_type_mask | PGT_count_mask); + page->u.inuse.type_info |=3D (flags =3D=3D SHARE_ro ? PGT_none + : PGT_writable_page) | + MASK_INSR(1, PGT_count_mask); =20 page_set_owner(page, d); smp_wmb(); /* install valid domain ptr before updating refcnt. */ @@ -1487,7 +1489,23 @@ int xenmem_add_to_physmap_one( } =20 /* Map at new location. */ - rc =3D guest_physmap_add_entry(d, gfn, mfn, 0, t); + if ( !p2m_is_ram(t) || !is_xen_heap_mfn(mfn) ) + rc =3D guest_physmap_add_entry(d, gfn, mfn, 0, t); + else + { + struct p2m_domain *p2m =3D p2m_get_hostp2m(d); + + p2m_write_lock(p2m); + if ( gfn_eq(page_get_xenheap_gfn(mfn_to_page(mfn)), INVALID_GFN) ) + { + rc =3D p2m_set_entry(p2m, gfn, 1, mfn, t, p2m->default_access); + if ( !rc ) + page_set_xenheap_gfn(mfn_to_page(mfn), gfn); + } + else + rc =3D -EBUSY; + p2m_write_unlock(p2m); + } =20 /* * For XENMAPSPACE_gmfn_foreign if we failed to add the mapping, we ne= ed diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index 8b20b43..fd8aff9 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -720,6 +720,8 @@ static int p2m_mem_access_radix_set(struct p2m_domain *= p2m, gfn_t gfn, */ static void p2m_put_l3_page(const lpae_t pte) { + mfn_t mfn =3D lpae_get_mfn(pte); + ASSERT(p2m_is_valid(pte)); =20 /* @@ -731,11 +733,12 @@ static void p2m_put_l3_page(const lpae_t pte) */ if ( p2m_is_foreign(pte.p2m.type) ) { - mfn_t mfn =3D lpae_get_mfn(pte); - ASSERT(mfn_valid(mfn)); put_page(mfn_to_page(mfn)); } + /* Detect the xenheap page and mark the stored GFN as invalid. */ + else if ( p2m_is_ram(pte.p2m.type) && is_xen_heap_mfn(mfn) ) + page_set_xenheap_gfn(mfn_to_page(mfn), INVALID_GFN); } =20 /* Free lpae sub-tree behind an entry */ diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c index 0262f2c..01d7a29 100644 --- a/xen/common/grant_table.c +++ b/xen/common/grant_table.c @@ -94,8 +94,6 @@ struct grant_table { =20 /* Domain to which this struct grant_table belongs. */ struct domain *domain; - - struct grant_table_arch arch; }; =20 unsigned int __read_mostly opt_max_grant_frames =3D 64; @@ -1997,14 +1995,9 @@ int grant_table_init(struct domain *d, int max_grant= _frames, =20 grant_write_lock(gt); =20 - ret =3D gnttab_init_arch(gt); - if ( ret ) - goto unlock; - /* gnttab_grow_table() allocates a min number of frames, so 0 is okay.= */ ret =3D gnttab_grow_table(d, 0); =20 - unlock: grant_write_unlock(gt); =20 out: @@ -3911,8 +3904,6 @@ grant_table_destroy( if ( t =3D=3D NULL ) return; =20 - gnttab_destroy_arch(t); - for ( i =3D 0; i < nr_grant_frames(t); i++ ) free_xenheap_page(t->shared_raw[i]); xfree(t->shared_raw); diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index d0baaa2..2306d9a 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -2161,6 +2161,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; + unsigned int i; =20 ASSERT(!in_irq()); =20 @@ -2169,6 +2170,9 @@ void *alloc_xenheap_pages(unsigned int order, unsigne= d int memflags) if ( unlikely(pg =3D=3D NULL) ) return NULL; =20 + for ( i =3D 0; i < (1u << order); i++ ) + arch_alloc_xenheap_page(&pg[i]); + memguard_unguard_range(page_to_virt(pg), 1 << (order + PAGE_SHIFT)); =20 return page_to_virt(pg); @@ -2177,14 +2181,22 @@ void *alloc_xenheap_pages(unsigned int order, unsig= ned int memflags) =20 void free_xenheap_pages(void *v, unsigned int order) { + struct page_info *pg; + unsigned int i; + ASSERT(!in_irq()); =20 if ( v =3D=3D NULL ) return; =20 + pg =3D virt_to_page(v); + memguard_guard_range(v, 1 << (order + PAGE_SHIFT)); =20 - free_heap_pages(virt_to_page(v), order, false); + for ( i =3D 0; i < (1u << order); i++ ) + arch_free_xenheap_page(&pg[i]); + + free_heap_pages(pg, order, false); } =20 #else /* !CONFIG_SEPARATE_XENHEAP */ @@ -2220,7 +2232,10 @@ void *alloc_xenheap_pages(unsigned int order, unsign= ed int memflags) return NULL; =20 for ( i =3D 0; i < (1u << order); i++ ) + { pg[i].count_info |=3D PGC_xen_heap; + arch_alloc_xenheap_page(&pg[i]); + } =20 return page_to_virt(pg); } @@ -2238,7 +2253,10 @@ void free_xenheap_pages(void *v, unsigned int order) pg =3D virt_to_page(v); =20 for ( i =3D 0; i < (1u << order); i++ ) + { + arch_free_xenheap_page(&pg[i]); pg[i].count_info &=3D ~PGC_xen_heap; + } =20 free_heap_pages(pg, order, true); } diff --git a/xen/include/asm-arm/grant_table.h b/xen/include/asm-arm/grant_= table.h index d31a4d6..d6fda31 100644 --- a/xen/include/asm-arm/grant_table.h +++ b/xen/include/asm-arm/grant_table.h @@ -11,11 +11,6 @@ #define INITIAL_NR_GRANT_FRAMES 1U #define GNTTAB_MAX_VERSION 1 =20 -struct grant_table_arch { - gfn_t *shared_gfn; - gfn_t *status_gfn; -}; - static inline void gnttab_clear_flags(struct domain *d, unsigned int mask, uint16_t *addr) { @@ -46,41 +41,12 @@ int replace_grant_host_mapping(unsigned long gpaddr, mf= n_t mfn, #define gnttab_dom0_frames() \ min_t(unsigned int, opt_max_grant_frames, PFN_DOWN(_etext - _stext)) =20 -#define gnttab_init_arch(gt) \ -({ \ - unsigned int ngf_ =3D (gt)->max_grant_frames; = \ - unsigned int nsf_ =3D grant_to_status_frames(ngf_); = \ - \ - (gt)->arch.shared_gfn =3D xmalloc_array(gfn_t, ngf_); = \ - (gt)->arch.status_gfn =3D xmalloc_array(gfn_t, nsf_); = \ - if ( (gt)->arch.shared_gfn && (gt)->arch.status_gfn ) \ - { \ - while ( ngf_-- ) \ - (gt)->arch.shared_gfn[ngf_] =3D INVALID_GFN; = \ - while ( nsf_-- ) \ - (gt)->arch.status_gfn[nsf_] =3D INVALID_GFN; = \ - } \ - else \ - gnttab_destroy_arch(gt); \ - (gt)->arch.shared_gfn ? 0 : -ENOMEM; \ -}) - -#define gnttab_destroy_arch(gt) \ - do { \ - XFREE((gt)->arch.shared_gfn); \ - XFREE((gt)->arch.status_gfn); \ - } while ( 0 ) - #define gnttab_set_frame_gfn(gt, st, idx, gfn, mfn) \ ({ \ - int rc_ =3D 0; = \ gfn_t ogfn =3D gnttab_get_frame_gfn(gt, st, idx); = \ - if ( gfn_eq(ogfn, INVALID_GFN) || gfn_eq(ogfn, gfn) || \ - (rc_ =3D guest_physmap_remove_page((gt)->domain, ogfn, mfn, = \ - 0)) =3D=3D 0 ) = \ - ((st) ? (gt)->arch.status_gfn \ - : (gt)->arch.shared_gfn)[idx] =3D (gfn); = \ - rc_; \ + (!gfn_eq(ogfn, INVALID_GFN) && !gfn_eq(ogfn, gfn)) \ + ? guest_physmap_remove_page((gt)->domain, ogfn, mfn, 0) \ + : 0; \ }) =20 #define gnttab_get_frame_gfn(gt, st, idx) ({ \ @@ -88,11 +54,21 @@ int replace_grant_host_mapping(unsigned long gpaddr, mf= n_t mfn, : gnttab_shared_gfn(NULL, gt, idx); \ }) =20 -#define gnttab_shared_gfn(d, t, i) \ - (((i) >=3D nr_grant_frames(t)) ? INVALID_GFN : (t)->arch.shared_gfn[i]) +#define gnttab_shared_page(t, i) ({ \ + virt_to_page((t)->shared_raw[i]); \ +}) + +#define gnttab_status_page(t, i) ({ \ + virt_to_page((t)->status[i]); \ +}) =20 -#define gnttab_status_gfn(d, t, i) \ - (((i) >=3D nr_status_frames(t)) ? INVALID_GFN : (t)->arch.status_gfn[i= ]) +#define gnttab_shared_gfn(d, t, i) ({ \ + page_get_xenheap_gfn(gnttab_shared_page(t, i)); \ +}) + +#define gnttab_status_gfn(d, t, i) ({ \ + page_get_xenheap_gfn(gnttab_status_page(t, i)); \ +}) =20 #define gnttab_need_iommu_mapping(d) \ (is_domain_direct_mapped(d) && is_iommu_enabled(d)) diff --git a/xen/include/asm-arm/mm.h b/xen/include/asm-arm/mm.h index 7b5e7b7..74b6485 100644 --- a/xen/include/asm-arm/mm.h +++ b/xen/include/asm-arm/mm.h @@ -98,9 +98,16 @@ struct page_info #define PGT_writable_page PG_mask(1, 1) /* has writable mappings? = */ #define PGT_type_mask PG_mask(1, 1) /* Bits 31 or 63. = */ =20 - /* Count of uses of this frame as its current type. */ -#define PGT_count_width PG_shift(2) -#define PGT_count_mask ((1UL<u.inuse.type_info & PGT_gfn_mask); + + ASSERT(is_xen_heap_page(p)); + + return gfn_eq(gfn_, PGT_INVALID_XENHEAP_GFN) ? INVALID_GFN : gfn_; +} + +static inline void page_set_xenheap_gfn(struct page_info *p, gfn_t gfn) +{ + gfn_t gfn_ =3D gfn_eq(gfn, INVALID_GFN) ? PGT_INVALID_XENHEAP_GFN : gf= n; + + ASSERT(is_xen_heap_page(p)); + + p->u.inuse.type_info &=3D ~PGT_gfn_mask; + p->u.inuse.type_info |=3D gfn_x(gfn_); +} + +/* + * As the struct page_info representing the xenheap page on Arm can contain + * the valid GFN we need to clear it beforehand. + */ +#define arch_alloc_xenheap_page(p) page_set_xenheap_gfn(p, INVALID_GFN) +#define arch_free_xenheap_page(p) do {} while ( 0 ) + #define frame_table ((struct page_info *)FRAMETABLE_VIRT_START) /* PDX of the first page in the frame table. */ extern unsigned long frametable_base_pdx; diff --git a/xen/include/asm-x86/grant_table.h b/xen/include/asm-x86/grant_= table.h index a8a2143..5c23cec 100644 --- a/xen/include/asm-x86/grant_table.h +++ b/xen/include/asm-x86/grant_table.h @@ -14,9 +14,6 @@ =20 #define INITIAL_NR_GRANT_FRAMES 1U =20 -struct grant_table_arch { -}; - static inline int create_grant_host_mapping(uint64_t addr, mfn_t frame, unsigned int flags, unsigned int cache_flags) @@ -35,8 +32,6 @@ static inline int replace_grant_host_mapping(uint64_t add= r, mfn_t frame, return replace_grant_pv_mapping(addr, frame, new_addr, flags); } =20 -#define gnttab_init_arch(gt) 0 -#define gnttab_destroy_arch(gt) do {} while ( 0 ) #define gnttab_set_frame_gfn(gt, st, idx, gfn, mfn) \ (gfn_eq(gfn, INVALID_GFN) \ ? guest_physmap_remove_page((gt)->domain, \ diff --git a/xen/include/asm-x86/mm.h b/xen/include/asm-x86/mm.h index cb90527..3c153c6 100644 --- a/xen/include/asm-x86/mm.h +++ b/xen/include/asm-x86/mm.h @@ -327,6 +327,10 @@ struct page_info =20 #define maddr_get_owner(ma) (page_get_owner(maddr_to_page((ma)))) =20 +/* No arch-specific actions are needed for the xenheap page */ +#define arch_alloc_xenheap_page(p) do {} while ( 0 ) +#define arch_free_xenheap_page(p) do {} while ( 0 ) + #define frame_table ((struct page_info *)FRAMETABLE_VIRT_START) extern unsigned long max_page; extern unsigned long total_pages; --=20 2.7.4