From nobody Mon Nov 25 07:23:45 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 header.i=@amazon.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=pass(p=quarantine dis=none) header.from=amazon.com ARC-Seal: i=1; a=rsa-sha256; t=1715598744; cv=none; d=zohomail.com; s=zohoarc; b=HCjk5oruRQuSU+aEXe097IPJ5GMdrEHqu0ZleAQLfZ11sdzhrlUNKqer5vumQYRR28eM22JlZsRevQlv0Q7Q6IQCqRCN0v6KaAkTu9m56xhsxarqLkwjpGs68rfFjrwQ3J4xEg2M5zl+SsnWRy2JAmqZlnB80cUGbIn5gw7SVhI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715598744; 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=mKCZV9DzUavScUGAYIjbkqz34voMdE7B7ItlMBncNvQ=; b=KqrzDgAXWRsI+NjDdE+VUkWnKhGIOg9SVShg7SmK+h79InmQ3AGV9efipv/E/ZyyaLvNHpLP1uHhrskiBjGrrKVHxzr/KJJVgsgSwOnPzeihVGNociVgVv2x+pzap95FNCH4bLzqBH8gCsL3XSqsptiNd6EjtVSwZiiT/5JZ79o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@amazon.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=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 171559874423645.136083413946494; Mon, 13 May 2024 04:12:24 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.720821.1123855 (Exim 4.92) (envelope-from ) id 1s6TbD-0007Jn-3I; Mon, 13 May 2024 11:12:07 +0000 Received: by outflank-mailman (output) from mailman id 720821.1123855; Mon, 13 May 2024 11:12:06 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s6TbC-0007I6-MT; Mon, 13 May 2024 11:12:06 +0000 Received: by outflank-mailman (input) for mailman id 720821; Mon, 13 May 2024 11:12:05 +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 1s6TbA-0003MC-B2 for xen-devel@lists.xenproject.org; Mon, 13 May 2024 11:12:04 +0000 Received: from smtp-fw-9102.amazon.com (smtp-fw-9102.amazon.com [207.171.184.29]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 9f3767fb-1119-11ef-909d-e314d9c70b13; Mon, 13 May 2024 13:12:02 +0200 (CEST) Received: from pdx4-co-svc-p1-lb2-vlan3.amazon.com (HELO smtpout.prod.us-east-1.prod.farcaster.email.amazon.dev) ([10.25.36.214]) by smtp-border-fw-9102.sea19.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2024 11:11:55 +0000 Received: from EX19MTAUEA002.ant.amazon.com [10.0.29.78:56418] by smtpin.naws.us-east-1.prod.farcaster.email.amazon.dev [10.0.83.223:2525] with esmtp (Farcaster) id 2b21e6f7-2a58-484f-8d2a-a0460334d2b3; Mon, 13 May 2024 11:11:53 +0000 (UTC) Received: from EX19D008UEA001.ant.amazon.com (10.252.134.62) by EX19MTAUEA002.ant.amazon.com (10.252.134.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.28; Mon, 13 May 2024 11:11:53 +0000 Received: from EX19MTAUWB001.ant.amazon.com (10.250.64.248) by EX19D008UEA001.ant.amazon.com (10.252.134.62) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.28; Mon, 13 May 2024 11:11:53 +0000 Received: from dev-dsk-eliasely-1a-fd74790f.eu-west-1.amazon.com (10.253.91.118) by mail-relay.amazon.com (10.250.64.254) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.28 via Frontend Transport; Mon, 13 May 2024 11:11:52 +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: 9f3767fb-1119-11ef-909d-e314d9c70b13 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1715598723; x=1747134723; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mKCZV9DzUavScUGAYIjbkqz34voMdE7B7ItlMBncNvQ=; b=FfUMR3FUAQYz29EJ9SvP5Rw00w8z4QDxALGWzwo9OmjSS89RiGydwsIk X66HYB3wa4pD4AsIUWKi1/+1q763DiuGMA/irfseHAkumpZXkYSV43WTY ZHxiagunKNRZUMWvN/Dh1Dq7kF2sOwMlh7tmtCg4SwHnfbOPagi9kpOA2 k=; X-IronPort-AV: E=Sophos;i="6.08,158,1712620800"; d="scan'208";a="418645273" X-Farcaster-Flow-ID: 2b21e6f7-2a58-484f-8d2a-a0460334d2b3 From: Elias El Yandouzi To: CC: , , , "Elias El Yandouzi" Subject: [PATCH V3 14/19] Rename mfn_to_virt() calls Date: Mon, 13 May 2024 11:11:12 +0000 Message-ID: <20240513111117.68828-15-eliasely@amazon.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240513111117.68828-1-eliasely@amazon.com> References: <20240513111117.68828-1-eliasely@amazon.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @amazon.com) X-ZM-MESSAGEID: 1715598746042100003 Content-Type: text/plain; charset="utf-8" Until directmap gets completely removed, we'd still need to keep some calls to mfn_to_virt() for xenheap pages or when the directmap is enabled. Rename the macro to mfn_to_directmap_virt() to flag them and prevent further use of mfn_to_virt(). Signed-off-by: Elias El Yandouzi diff --git a/xen/arch/arm/include/asm/mm.h b/xen/arch/arm/include/asm/mm.h index 48538b5337..2bca3f9e87 100644 --- a/xen/arch/arm/include/asm/mm.h +++ b/xen/arch/arm/include/asm/mm.h @@ -336,6 +336,7 @@ static inline uint64_t gvirt_to_maddr(vaddr_t va, paddr= _t *pa, */ #define virt_to_mfn(va) __virt_to_mfn(va) #define mfn_to_virt(mfn) __mfn_to_virt(mfn) +#define mfn_to_directmap_virt(mfn) mfn_to_virt(mfn) =20 /* Convert between Xen-heap virtual addresses and page-info structures. */ static inline struct page_info *virt_to_page(const void *v) diff --git a/xen/arch/x86/domain_page.c b/xen/arch/x86/domain_page.c index 89caefc8a2..62d6fee0f4 100644 --- a/xen/arch/x86/domain_page.c +++ b/xen/arch/x86/domain_page.c @@ -81,14 +81,14 @@ void *map_domain_page(mfn_t mfn) =20 #ifdef NDEBUG if ( arch_mfns_in_directmap(mfn_x(mfn), 1) ) - return mfn_to_virt(mfn_x(mfn)); + return mfn_to_directmap_virt(mfn_x(mfn)); #endif =20 v =3D mapcache_current_vcpu(); if ( !v || !v->domain->arch.mapcache.inuse ) { if ( arch_mfns_in_directmap(mfn_x(mfn), 1) ) - return mfn_to_virt(mfn_x(mfn)); + return mfn_to_directmap_virt(mfn_x(mfn)); else { BUG_ON(system_state >=3D SYS_STATE_smp_boot); @@ -324,7 +324,7 @@ void *map_domain_page_global(mfn_t mfn) =20 #ifdef NDEBUG if ( arch_mfn_in_directmap(mfn_x(mfn, 1)) ) - return mfn_to_virt(mfn_x(mfn)); + return mfn_to_directmap_virt(mfn_x(mfn)); #endif =20 return vmap(&mfn, 1); diff --git a/xen/arch/x86/hvm/dom0_build.c b/xen/arch/x86/hvm/dom0_build.c index b0cb96c3bc..d1482ae2f7 100644 --- a/xen/arch/x86/hvm/dom0_build.c +++ b/xen/arch/x86/hvm/dom0_build.c @@ -439,7 +439,7 @@ static int __init pvh_populate_p2m(struct domain *d) d->arch.e820[i].addr + d->arch.e820[i].si= ze); enum hvm_translation_result res =3D hvm_copy_to_guest_phys(mfn_to_maddr(_mfn(addr)), - mfn_to_virt(addr), + mfn_to_directmap_virt(addr), end - d->arch.e820[i].addr, v); =20 @@ -725,7 +725,7 @@ static int __init pvh_load_kernel(struct domain *d, con= st module_t *image, =20 if ( initrd !=3D NULL ) { - rc =3D hvm_copy_to_guest_phys(last_addr, mfn_to_virt(initrd->mod_s= tart), + rc =3D hvm_copy_to_guest_phys(last_addr, mfn_to_directmap_virt(ini= trd->mod_start), initrd_len, v); if ( rc ) { diff --git a/xen/arch/x86/include/asm/page.h b/xen/arch/x86/include/asm/pag= e.h index 350d1fb110..c6891b52d4 100644 --- a/xen/arch/x86/include/asm/page.h +++ b/xen/arch/x86/include/asm/page.h @@ -268,7 +268,7 @@ void copy_page_sse2(void *to, const void *from); */ #define mfn_valid(mfn) __mfn_valid(mfn_x(mfn)) #define virt_to_mfn(va) __virt_to_mfn(va) -#define mfn_to_virt(mfn) __mfn_to_virt(mfn) +#define mfn_to_directmap_virt(mfn) __mfn_to_virt(mfn) #define virt_to_maddr(va) __virt_to_maddr((unsigned long)(va)) #define maddr_to_virt(ma) __maddr_to_virt((unsigned long)(ma)) #define maddr_to_page(ma) __maddr_to_page(ma) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index efdf20f775..337363cf17 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -318,8 +318,8 @@ void __init arch_init_memory(void) iostart_pfn =3D max_t(unsigned long, pfn, 1UL << (20 - PAGE_SHIFT)= ); ioend_pfn =3D min(rstart_pfn, 16UL << (20 - PAGE_SHIFT)); if ( iostart_pfn < ioend_pfn ) - destroy_xen_mappings((unsigned long)mfn_to_virt(iostart_pfn), - (unsigned long)mfn_to_virt(ioend_pfn)); + destroy_xen_mappings((unsigned long)mfn_to_directmap_virt(iost= art_pfn), + (unsigned long)mfn_to_directmap_virt(ioen= d_pfn)); =20 /* Mark as I/O up to next RAM region. */ for ( ; pfn < rstart_pfn; pfn++ ) diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 919347d8c2..e0671ab3c3 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -399,7 +399,7 @@ void *__init bootstrap_map(const module_t *mod) void *ret; =20 if ( system_state !=3D SYS_STATE_early_boot ) - return mod ? mfn_to_virt(mod->mod_start) : NULL; + return mod ? mfn_to_directmap_virt(mod->mod_start) : NULL; =20 if ( !mod ) { @@ -1708,7 +1708,7 @@ void asmlinkage __init noreturn __start_xen(unsigned = long mbi_p) { set_pdx_range(mod[i].mod_start, mod[i].mod_start + PFN_UP(mod[i].mod_end)); - map_pages_to_xen((unsigned long)mfn_to_virt(mod[i].mod_start), + map_pages_to_xen((unsigned long)mfn_to_directmap_virt(mod[i].mod_s= tart), _mfn(mod[i].mod_start), PFN_UP(mod[i].mod_end), PAGE_HYPERVISOR); } diff --git a/xen/arch/x86/tboot.c b/xen/arch/x86/tboot.c index ba0700d2d5..58df01dfb9 100644 --- a/xen/arch/x86/tboot.c +++ b/xen/arch/x86/tboot.c @@ -253,7 +253,7 @@ static void tboot_gen_xenheap_integrity(const uint8_t k= ey[TB_KEY_SIZE], continue; /* skip tboot and its page tables */ =20 if ( is_page_in_use(page) && is_special_page(page) ) - vmac_update(mfn_to_virt(mfn), PAGE_SIZE, &ctx); + vmac_update(mfn_to_directmap_virt(mfn), PAGE_SIZE, &ctx); } *mac =3D vmac(NULL, 0, nonce, NULL, &ctx); =20 diff --git a/xen/arch/x86/x86_64/mm.c b/xen/arch/x86/x86_64/mm.c index b2a280fba3..1697760d82 100644 --- a/xen/arch/x86/x86_64/mm.c +++ b/xen/arch/x86/x86_64/mm.c @@ -1247,19 +1247,25 @@ int memory_add(unsigned long spfn, unsigned long ep= fn, unsigned int pxm) i =3D virt_to_mfn(HYPERVISOR_VIRT_END - 1) + 1; if ( spfn < i ) { - ret =3D map_pages_to_xen((unsigned long)mfn_to_virt(spfn), _mfn(sp= fn), - min(epfn, i) - spfn, PAGE_HYPERVISOR); - if ( ret ) - goto destroy_directmap; + if ( arch_mfns_in_directmap(spfn, min(epfn, i) - spfn ) ) + { + ret =3D map_pages_to_xen((unsigned long)mfn_to_directmap_virt(= spfn), _mfn(spfn), + min(epfn, i) - spfn, PAGE_HYPERVISOR); + if ( ret ) + goto destroy_directmap; + } } if ( i < epfn ) { if ( i < spfn ) i =3D spfn; - ret =3D map_pages_to_xen((unsigned long)mfn_to_virt(i), _mfn(i), - epfn - i, __PAGE_HYPERVISOR_RW); - if ( ret ) - goto destroy_directmap; + if ( arch_mfns_in_directmap(spfn, epfn - i) ) + { + ret =3D map_pages_to_xen((unsigned long)mfn_to_directmap_virt(= i), _mfn(i), + epfn - i, __PAGE_HYPERVISOR_RW); + if ( ret ) + goto destroy_directmap; + } } =20 old_node_start =3D node_start_pfn(node); @@ -1348,8 +1354,8 @@ destroy_frametable: NODE_DATA(node)->node_start_pfn =3D old_node_start; NODE_DATA(node)->node_spanned_pages =3D old_node_span; destroy_directmap: - destroy_xen_mappings((unsigned long)mfn_to_virt(spfn), - (unsigned long)mfn_to_virt(epfn)); + destroy_xen_mappings((unsigned long)mfn_to_directmap_virt(spfn), + (unsigned long)mfn_to_directmap_virt(epfn)); =20 return ret; } diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c index efbec00af9..39aed5845d 100644 --- a/xen/common/efi/boot.c +++ b/xen/common/efi/boot.c @@ -1599,7 +1599,7 @@ static __init void copy_mapping(unsigned long mfn, un= signed long end, for ( ; mfn < end; mfn =3D next ) { l4_pgentry_t l4e =3D efi_l4t[l4_table_offset(mfn << PAGE_SHIFT)]; - unsigned long va =3D (unsigned long)mfn_to_virt(mfn); + unsigned long va =3D (unsigned long)mfn_to_directmap_virt(mfn); =20 if ( !(mfn & ((1UL << (L4_PAGETABLE_SHIFT - PAGE_SHIFT)) - 1)) ) UNMAP_DOMAIN_PAGE(l3dst); @@ -1757,15 +1757,18 @@ void __init efi_init_memory(void) if ( pfn_to_pdx(emfn - 1) < (DIRECTMAP_SIZE >> PAGE_SHIFT) && pdx_is_region_compressible(mem_base, mem_npages) ) { - if ( (unsigned long)mfn_to_virt(emfn - 1) >=3D HYPERVISOR_VIRT= _END ) - prot &=3D ~_PAGE_GLOBAL; - if ( map_pages_to_xen((unsigned long)mfn_to_virt(smfn), - _mfn(smfn), emfn - smfn, prot) =3D=3D 0 ) - desc->VirtualStart =3D - (unsigned long)maddr_to_virt(desc->PhysicalStart); - else - printk(XENLOG_ERR "Could not map MFNs %#lx-%#lx\n", - smfn, emfn - 1); + if ( arch_mfns_in_directmap(smfn, emfn - smfn) ) + { + if ( (unsigned long)mfn_to_directmap_virt(emfn - 1) >=3D H= YPERVISOR_VIRT_END ) + prot &=3D ~_PAGE_GLOBAL; + if ( map_pages_to_xen((unsigned long)mfn_to_directmap_virt= (smfn), + _mfn(smfn), emfn - smfn, prot) =3D=3D = 0 ) + desc->VirtualStart =3D + (unsigned long)maddr_to_virt(desc->PhysicalStart); + else + printk(XENLOG_ERR "Could not map MFNs %#lx-%#lx\n", + smfn, emfn - 1); + } } else if ( !((desc->PhysicalStart + len - 1) >> (VADDR_BITS - 1)) && (extra =3D xmalloc(struct rt_extra)) !=3D NULL ) diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 3c0909f333..e1e98d4d59 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -611,8 +611,8 @@ static unsigned long init_node_heap(int node, unsigned = long mfn, { if ( arch_mfns_in_directmap(mfn + nr - needed, needed) ) { - _heap[node] =3D mfn_to_virt(mfn + nr - needed); - avail[node] =3D mfn_to_virt(mfn + nr - 1) + + _heap[node] =3D mfn_to_directmap_virt(mfn + nr - needed); + avail[node] =3D mfn_to_directmap_virt(mfn + nr - 1) + PAGE_SIZE - sizeof(**avail) * NR_ZONES; } else @@ -631,8 +631,8 @@ static unsigned long init_node_heap(int node, unsigned = long mfn, { if ( arch_mfns_in_directmap(mfn, needed) ) { - _heap[node] =3D mfn_to_virt(mfn); - avail[node] =3D mfn_to_virt(mfn + needed - 1) + + _heap[node] =3D mfn_to_directmap_virt(mfn); + avail[node] =3D mfn_to_directmap_virt(mfn + needed - 1) + PAGE_SIZE - sizeof(**avail) * NR_ZONES; } else diff --git a/xen/common/trace.c b/xen/common/trace.c index 4e7b080e61..955509a0d8 100644 --- a/xen/common/trace.c +++ b/xen/common/trace.c @@ -229,7 +229,7 @@ static int alloc_trace_bufs(unsigned int pages) offset =3D t_info->mfn_offset[cpu]; =20 /* Initialize the buffer metadata */ - per_cpu(t_bufs, cpu) =3D buf =3D mfn_to_virt(t_info_mfn_list[offse= t]); + per_cpu(t_bufs, cpu) =3D buf =3D mfn_to_directmap_virt(t_info_mfn_= list[offset]); buf->cons =3D buf->prod =3D 0; =20 printk(XENLOG_INFO "xentrace: p%d mfn %x offset %u\n", @@ -268,7 +268,7 @@ out_dealloc: if ( !mfn ) break; ASSERT(!(mfn_to_page(_mfn(mfn))->count_info & PGC_allocated)); - free_xenheap_pages(mfn_to_virt(mfn), 0); + free_xenheap_pages(mfn_to_directmap_virt(mfn), 0); } } free_xenheap_pages(t_info, get_order_from_pages(t_info_pages)); @@ -529,7 +529,7 @@ static unsigned char *next_record(const struct t_buf *b= uf, uint32_t *next, per_cpu_mfn_offset =3D t_info->mfn_offset[smp_processor_id()]; mfn_list =3D (uint32_t *)t_info; mfn =3D mfn_list[per_cpu_mfn_offset + per_cpu_mfn_nr]; - this_page =3D mfn_to_virt(mfn); + this_page =3D (unsigned char *)mfn_to_directmap_virt(mfn); if (per_cpu_mfn_nr + 1 >=3D opt_tbuf_size) { /* reached end of buffer? */ @@ -538,7 +538,7 @@ static unsigned char *next_record(const struct t_buf *b= uf, uint32_t *next, else { mfn =3D mfn_list[per_cpu_mfn_offset + per_cpu_mfn_nr + 1]; - *next_page =3D mfn_to_virt(mfn); + *next_page =3D mfn_to_directmap_virt(mfn); } return this_page; } --=20 2.40.1