From nobody Sat Nov 23 14:27:09 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=1731330752; cv=none; d=zohomail.com; s=zohoarc; b=XfEMGjlLM6zwqC3bxLt8qymAqLPTy0Zpzg8VZwEFZWLK6s836+/1ADNbemOBtGQZm1KIJ4UcUFeUcbffBDsOKNZ3p7HVmX8t6Ifatwc62p4/MCp/Sh+6BQ3VyRJbU4ZFiqUfo1TiLFtofAKihUZPbtveVn/IvJ4tFnpwZEJRPzQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1731330752; 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=0qBSENfwgqkU95D4y/S6zHGmXrylZ30lTrQ15I4hHT8=; b=XVRt+iFscFm1COTvctxuJNCy81K9SMDTdSd1/iZnkQXw9t4xFYlbBmtwwHfZM56s3OVWo2HbNfGr/XVZnqONRoBfmT7YcpkTT08IXwqXXWbi0n5Sq5O4Hgr7NLWBJmVeanIMNVlS7lfTVR9T/+eTc/sudEbruGB+m9p9iZi3CHU= 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 1731330752691839.5168672929436; Mon, 11 Nov 2024 05:12:32 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.833731.1248948 (Exim 4.92) (envelope-from ) id 1tAUDC-0008If-Fv; Mon, 11 Nov 2024 13:12:10 +0000 Received: by outflank-mailman (output) from mailman id 833731.1248948; Mon, 11 Nov 2024 13:12:10 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tAUDC-0008IY-Cg; Mon, 11 Nov 2024 13:12:10 +0000 Received: by outflank-mailman (input) for mailman id 833731; Mon, 11 Nov 2024 13:12:09 +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 1tAUDB-0008Hn-Cv for xen-devel@lists.xenproject.org; Mon, 11 Nov 2024 13:12:09 +0000 Received: from smtp-fw-52002.amazon.com (smtp-fw-52002.amazon.com [52.119.213.150]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 8c45a329-a02e-11ef-a0c6-8be0dac302b0; Mon, 11 Nov 2024 14:12:06 +0100 (CET) Received: from iad6-co-svc-p1-lb1-vlan3.amazon.com (HELO smtpout.prod.us-east-1.prod.farcaster.email.amazon.dev) ([10.124.125.6]) by smtp-border-fw-52002.iad7.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Nov 2024 13:12:03 +0000 Received: from EX19MTAUEC002.ant.amazon.com [10.0.44.209:54712] by smtpin.naws.us-east-1.prod.farcaster.email.amazon.dev [10.0.85.229:2525] with esmtp (Farcaster) id de6160ee-520b-4d69-b6a4-ec18ab5288c7; Mon, 11 Nov 2024 13:12:02 +0000 (UTC) Received: from EX19D008UEA004.ant.amazon.com (10.252.134.191) by EX19MTAUEC002.ant.amazon.com (10.252.135.253) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34; Mon, 11 Nov 2024 13:12:02 +0000 Received: from EX19MTAUWA002.ant.amazon.com (10.250.64.202) by EX19D008UEA004.ant.amazon.com (10.252.134.191) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34; Mon, 11 Nov 2024 13:12:01 +0000 Received: from email-imr-corp-prod-pdx-all-2b-5ec155c2.us-west-2.amazon.com (10.25.36.210) by mail-relay.amazon.com (10.250.64.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34 via Frontend Transport; Mon, 11 Nov 2024 13:12:01 +0000 Received: from dev-dsk-eliasely-1a-fd74790f.eu-west-1.amazon.com (dev-dsk-eliasely-1a-fd74790f.eu-west-1.amazon.com [10.253.91.118]) by email-imr-corp-prod-pdx-all-2b-5ec155c2.us-west-2.amazon.com (Postfix) with ESMTPS id 293DA42116; Mon, 11 Nov 2024 13:12:00 +0000 (UTC) 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: 8c45a329-a02e-11ef-a0c6-8be0dac302b0 X-Custom-Connection: eyJyZW1vdGVpcCI6IjUyLjExOS4yMTMuMTUwIiwiaGVsbyI6InNtdHAtZnctNTIwMDIuYW1hem9uLmNvbSJ9 X-Custom-Transaction: eyJpZCI6IjhjNDVhMzI5LWEwMmUtMTFlZi1hMGM2LThiZTBkYWMzMDJiMCIsInRzIjoxNzMxMzMwNzI2LjU4OTYyLCJzZW5kZXIiOiJwcnZzPTAzOGQyNmQwYz1lbGlhc2VseUBhbWF6b24uY28udWsiLCJyZWNpcGllbnQiOiJ4ZW4tZGV2ZWxAbGlzdHMueGVucHJvamVjdC5vcmcifQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1731330726; x=1762866726; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0qBSENfwgqkU95D4y/S6zHGmXrylZ30lTrQ15I4hHT8=; b=Ja9giNNfVZ0R9geoVcyvCZtt6oK/GBnykRvhM15+qV1IDdgT7CQYGoln buJKEh5d8DeCNq/kswFRXYPmr6pBGCtMUUS0z36Q4mOQnTAj+aDk0SmYK bWuBBUgSybjeHw7SFklsNSU5U2WyFpZc42jZd7IwuTGL7BPapdIuTFEGA 0=; X-IronPort-AV: E=Sophos;i="6.12,145,1728950400"; d="scan'208";a="673030954" X-Farcaster-Flow-ID: de6160ee-520b-4d69-b6a4-ec18ab5288c7 From: Elias El Yandouzi To: CC: , , , Wei Liu , Wei Wang , Hongyan Xia , Julien Grall , Elias El Yandouzi Subject: [PATCH V4 04/15] x86: Initialize mapcache for PV, HVM, and idle domains Date: Mon, 11 Nov 2024 13:11:37 +0000 Message-ID: <20241111131148.52568-5-eliasely@amazon.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20241111131148.52568-1-eliasely@amazon.com> References: <20241111131148.52568-1-eliasely@amazon.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @amazon.com) X-ZM-MESSAGEID: 1731330755015116600 From: Wei Liu To support the transition away from the direct map, the mapcache will now be used by HVM and idle domains as well. This patch lifts the `mapcache` to the arch level and moves its initialization earlier in `arch_domain_create()` to cover PV, HVM, and idle domains. For the idle domain to utilize the mapcache, this patch also populates the mapcache page tables within the `PERDOMAIN` region and adjusts the initialization sequence. With this change, mapcache initialization is now unified across all domain types=E2=80=94PV, HVM, and idle. Signed-off-by: Wei Liu Signed-off-by: Wei Wang Signed-off-by: Hongyan Xia Signed-off-by: Julien Grall Signed-off-by: Elias El Yandouzi ---- Changes in V4: * Reword the commit message * Rebase it on top of staging * The logic for the creation of the domain has been reworked so introduced #ifdef CONFIG_X86 in the common code to initialise the mapcache Changes in V2: * Free resources if mapcache initialisation fails * Remove `is_idle_domain()` check from `create_perdomain_mappings()` diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index 78a13e6812c9..38338f519dea 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -777,6 +777,10 @@ void __init arch_init_idle_domain(struct domain *d) }; =20 d->arch.ctxt_switch =3D &idle_csw; + + /* Slot 260: Per-domain mappings. */ + idle_pg_table[l4_table_offset(PERDOMAIN_VIRT_START)] =3D + l4e_from_page(d->arch.perdomain_l3_pg, __PAGE_HYPERVISOR_RW); } =20 int arch_domain_create(struct domain *d, @@ -870,9 +874,6 @@ int arch_domain_create(struct domain *d, } else if ( is_pv_domain(d) ) { - if ( (rc =3D mapcache_domain_init(d)) !=3D 0 ) - goto fail; - if ( (rc =3D pv_domain_initialise(d)) !=3D 0 ) goto fail; } @@ -909,7 +910,6 @@ int arch_domain_create(struct domain *d, XFREE(d->arch.cpu_policy); if ( paging_initialised ) paging_final_teardown(d); - free_perdomain_mappings(d); =20 return rc; } diff --git a/xen/arch/x86/domain_page.c b/xen/arch/x86/domain_page.c index eac5e3304fb8..55e337aaf703 100644 --- a/xen/arch/x86/domain_page.c +++ b/xen/arch/x86/domain_page.c @@ -82,11 +82,11 @@ void *map_domain_page(mfn_t mfn) #endif =20 v =3D mapcache_current_vcpu(); - if ( !v || !is_pv_vcpu(v) ) + if ( !v ) return mfn_to_virt(mfn_x(mfn)); =20 - dcache =3D &v->domain->arch.pv.mapcache; - vcache =3D &v->arch.pv.mapcache; + dcache =3D &v->domain->arch.mapcache; + vcache =3D &v->arch.mapcache; if ( !dcache->inuse ) return mfn_to_virt(mfn_x(mfn)); =20 @@ -187,14 +187,14 @@ void unmap_domain_page(const void *ptr) ASSERT(va >=3D MAPCACHE_VIRT_START && va < MAPCACHE_VIRT_END); =20 v =3D mapcache_current_vcpu(); - ASSERT(v && is_pv_vcpu(v)); + ASSERT(v); =20 - dcache =3D &v->domain->arch.pv.mapcache; + dcache =3D &v->domain->arch.mapcache; ASSERT(dcache->inuse); =20 idx =3D PFN_DOWN(va - MAPCACHE_VIRT_START); mfn =3D l1e_get_pfn(MAPCACHE_L1ENT(idx)); - hashent =3D &v->arch.pv.mapcache.hash[MAPHASH_HASHFN(mfn)]; + hashent =3D &v->arch.mapcache.hash[MAPHASH_HASHFN(mfn)]; =20 local_irq_save(flags); =20 @@ -233,11 +233,9 @@ void unmap_domain_page(const void *ptr) =20 int mapcache_domain_init(struct domain *d) { - struct mapcache_domain *dcache =3D &d->arch.pv.mapcache; + struct mapcache_domain *dcache =3D &d->arch.mapcache; unsigned int bitmap_pages; =20 - ASSERT(is_pv_domain(d)); - #ifdef NDEBUG if ( !mem_hotplug && max_page <=3D PFN_DOWN(__pa(HYPERVISOR_VIRT_END -= 1)) ) return 0; @@ -261,12 +259,12 @@ int mapcache_domain_init(struct domain *d) int mapcache_vcpu_init(struct vcpu *v) { struct domain *d =3D v->domain; - struct mapcache_domain *dcache =3D &d->arch.pv.mapcache; + struct mapcache_domain *dcache =3D &d->arch.mapcache; unsigned long i; unsigned int ents =3D d->max_vcpus * MAPCACHE_VCPU_ENTRIES; unsigned int nr =3D PFN_UP(BITS_TO_LONGS(ents) * sizeof(long)); =20 - if ( !is_pv_vcpu(v) || !dcache->inuse ) + if ( !dcache->inuse ) return 0; =20 if ( ents > dcache->entries ) @@ -293,7 +291,7 @@ int mapcache_vcpu_init(struct vcpu *v) BUILD_BUG_ON(MAPHASHENT_NOTINUSE < MAPCACHE_ENTRIES); for ( i =3D 0; i < MAPHASH_ENTRIES; i++ ) { - struct vcpu_maphash_entry *hashent =3D &v->arch.pv.mapcache.hash[i= ]; + struct vcpu_maphash_entry *hashent =3D &v->arch.mapcache.hash[i]; =20 hashent->mfn =3D ~0UL; /* never valid to map */ hashent->idx =3D MAPHASHENT_NOTINUSE; diff --git a/xen/arch/x86/include/asm/domain.h b/xen/arch/x86/include/asm/d= omain.h index 478ce41ad8ca..b0fd477c62e7 100644 --- a/xen/arch/x86/include/asm/domain.h +++ b/xen/arch/x86/include/asm/domain.h @@ -285,9 +285,6 @@ struct pv_domain /* Mitigate L1TF with shadow/crashing? */ bool check_l1tf; =20 - /* map_domain_page() mapping cache. */ - struct mapcache_domain mapcache; - struct cpuidmasks *cpuidmasks; }; =20 @@ -326,6 +323,9 @@ struct arch_domain =20 uint8_t scf; /* See SCF_DOM_MASK */ =20 + /* map_domain_page() mapping cache. */ + struct mapcache_domain mapcache; + union { struct pv_domain pv; struct hvm_domain hvm; @@ -516,9 +516,6 @@ struct arch_domain =20 struct pv_vcpu { - /* map_domain_page() mapping cache. */ - struct mapcache_vcpu mapcache; - unsigned int vgc_flags; =20 struct trap_info *trap_ctxt; @@ -612,6 +609,9 @@ struct arch_vcpu #define async_exception_state(t) async_exception_state[(t)-1] uint8_t async_exception_mask; =20 + /* map_domain_page() mapping cache. */ + struct mapcache_vcpu mapcache; + /* Virtual Machine Extensions */ union { struct pv_vcpu pv; diff --git a/xen/common/domain.c b/xen/common/domain.c index 92263a4fbdc5..a7f4929b5893 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -738,6 +738,11 @@ struct domain *domain_create(domid_t domid, =20 rangeset_domain_initialise(d); =20 +#ifdef CONFIG_X86 + if ( (err =3D mapcache_domain_init(d)) !=3D 0) + goto fail; +#endif + if ( is_idle_domain(d) ) arch_init_idle_domain(d); =20 @@ -820,6 +825,10 @@ struct domain *domain_create(domid_t domid, ASSERT(err < 0); /* Sanity check paths leading here. */ err =3D err ?: -EILSEQ; /* Release build safety. */ =20 +#ifdef CONFIG_X86 + free_perdomain_mappings(d); +#endif + d->is_dying =3D DOMDYING_dead; if ( hardware_domain =3D=3D d ) hardware_domain =3D old_hwdom; --=20 2.40.1