From nobody Thu May 9 13:57:19 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=1705433200; cv=none; d=zohomail.com; s=zohoarc; b=SiRekGw0kxp7P2n7k5wiydZEBy8IlVqoDdd6WEdhIwtHznahr1wxGeXrQ772H3axZFAUbcYF9Y2LctRmkIFtBQtlEEOtM8TjLBREKQWCixjYF1VBMnYWHPbeWdrkddN2/gikh3J/7YIdehgqtD/DarXnY7I0ajlzIc+X+tbS9e8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705433200; 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=v62iLnCTpjjwMqV4HyxrM90zKMQWzF/DsYPcQzLLs10=; b=NT7pnyqu/ZmM4k1bXK1tppkK+UaPrRABDKkuhtrOnMDgAPnEk0zCcpkTIk20g4iFGbrbbpdInAr5Ltg4nMYJENI8UPZe6UblkxoD7HkYsPzpFXcLXEKUqGfMQGSUpeq+kdlLHc0m+h0LUVQKI3uD0914P4aKNN+1ksmd0xVSiUQ= 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 1705433200433514.8560739124985; Tue, 16 Jan 2024 11:26:40 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.668078.1039961 (Exim 4.92) (envelope-from ) id 1rPp4s-0002wl-0a; Tue, 16 Jan 2024 19:26:26 +0000 Received: by outflank-mailman (output) from mailman id 668078.1039961; Tue, 16 Jan 2024 19:26: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 1rPp4r-0002we-UB; Tue, 16 Jan 2024 19:26:25 +0000 Received: by outflank-mailman (input) for mailman id 668078; Tue, 16 Jan 2024 19:26: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 1rPp4q-0002iI-JR for xen-devel@lists.xenproject.org; Tue, 16 Jan 2024 19:26:24 +0000 Received: from smtp-fw-52005.amazon.com (smtp-fw-52005.amazon.com [52.119.213.156]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 21666e67-b4a5-11ee-9b0f-b553b5be7939; Tue, 16 Jan 2024 20:26:22 +0100 (CET) Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-iad-1d-m6i4x-d8e96288.us-east-1.amazon.com) ([10.43.8.6]) by smtp-border-fw-52005.iad7.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jan 2024 19:26:20 +0000 Received: from smtpout.prod.us-east-1.prod.farcaster.email.amazon.dev (iad7-ws-svc-p70-lb3-vlan3.iad.amazon.com [10.32.235.38]) by email-inbound-relay-iad-1d-m6i4x-d8e96288.us-east-1.amazon.com (Postfix) with ESMTPS id 08B1E84687; Tue, 16 Jan 2024 19:26:17 +0000 (UTC) Received: from EX19MTAUEB002.ant.amazon.com [10.0.29.78:41703] by smtpin.naws.us-east-1.prod.farcaster.email.amazon.dev [10.0.89.133:2525] with esmtp (Farcaster) id 956fd52c-0e3e-43ce-a756-0aa56b33185c; Tue, 16 Jan 2024 19:26:17 +0000 (UTC) Received: from EX19D008UEA004.ant.amazon.com (10.252.134.191) by EX19MTAUEB002.ant.amazon.com (10.252.135.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 16 Jan 2024 19:26:17 +0000 Received: from EX19MTAUEB001.ant.amazon.com (10.252.135.35) by EX19D008UEA004.ant.amazon.com (10.252.134.191) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 16 Jan 2024 19:26:16 +0000 Received: from dev-dsk-eliasely-1a-fd74790f.eu-west-1.amazon.com (10.253.91.118) by mail-relay.amazon.com (10.252.135.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40 via Frontend Transport; Tue, 16 Jan 2024 19:26:16 +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 Sender: "Xen-devel" X-Inumbo-ID: 21666e67-b4a5-11ee-9b0f-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1705433182; x=1736969182; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=v62iLnCTpjjwMqV4HyxrM90zKMQWzF/DsYPcQzLLs10=; b=jgwGGUet6Z1gmXBzynETUo1sj3rpTgLqPL6WiqGQl5FLYQycKyGmsNUx JYBWXZB7qeEvJdAgKZR1VvNtGroZRWn1ggFipPsx2C4MMctZLsH5Nk6KX hinESYAxo+CarT28x20CgoIDBcVd0PuR+NDogtg8uY9qFkol2CSVl3TmF U=; X-IronPort-AV: E=Sophos;i="6.05,200,1701129600"; d="scan'208";a="627983541" X-Farcaster-Flow-ID: 956fd52c-0e3e-43ce-a756-0aa56b33185c From: Elias El Yandouzi To: CC: , , , Julien Grall , Andrew Cooper , George Dunlap , Jan Beulich , "Stefano Stabellini" , Wei Liu , Elias El Yandouzi Subject: [PATCH v2 (resend) 01/27] xen/vmap: Check the page has been mapped in vm_init_type() Date: Tue, 16 Jan 2024 19:25:45 +0000 Message-ID: <20240116192611.41112-2-eliasely@amazon.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240116192611.41112-1-eliasely@amazon.com> References: <20240116192611.41112-1-eliasely@amazon.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: Bulk X-ZohoMail-DKIM: pass (identity @amazon.com) X-ZM-MESSAGEID: 1705433201873100001 Content-Type: text/plain; charset="utf-8" From: Julien Grall The function map_pages_to_xen() could fail if it can't allocate the underlying page tables or (at least on Arm) if the area was already mapped. The first error is caught by clear_page() because it would fault. However, the second error while very unlikely is not caught at all. As this is boot code, use BUG_ON() to check if map_pages_to_xen() has succeeded. Signed-off-by: Julien Grall Signed-off-by: Elias El Yandouzi Acked-by: Jan Beulich ---- Changes in v2: - New patch diff --git a/xen/common/vmap.c b/xen/common/vmap.c index 330e2ba897..830f64c5ef 100644 --- a/xen/common/vmap.c +++ b/xen/common/vmap.c @@ -35,8 +35,11 @@ void __init vm_init_type(enum vmap_region type, void *st= art, void *end) for ( i =3D 0, va =3D (unsigned long)vm_bitmap(type); i < nr; ++i, va = +=3D PAGE_SIZE ) { struct page_info *pg =3D alloc_domheap_page(NULL, 0); + int rc; + + rc =3D map_pages_to_xen(va, page_to_mfn(pg), 1, PAGE_HYPERVISOR); + BUG_ON(rc); =20 - map_pages_to_xen(va, page_to_mfn(pg), 1, PAGE_HYPERVISOR); clear_page((void *)va); } bitmap_fill(vm_bitmap(type), vm_low[type]); --=20 2.40.1 From nobody Thu May 9 13:57:19 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=1705433204; cv=none; d=zohomail.com; s=zohoarc; b=lxX2t974jmep86q+n8W+v8d8LG2A90ZFwG4TF2hUQ8ZqXsOlJH2UcdihcM3r6Uad0u90GOeOPxELmDuA1tGrAWtHs5r3tQrYPjRNDJwY7Rx6qC5RnAMhw9ynQb8wOyTHr3XpAcwUKkA1lmXmcAL6HyYmAaEp5G2RmahZYIvy33s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705433204; 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=3bfMq1Uef4k7zIlKxhavHHhyVuwSclhXcQaPCDrDa7g=; b=F2dcC6f7sPLJ3xVKjDCoIfUF0QIX9kFQlg5u6y3nCFDsc+ISJogO7cHbTtxS/TzHsBZdvjbpUrMOZNGc5+8QotS7JVxQFRk1ssAqLY5CZW3+ljuY+PHCGLvdFnWVMSJXtlYpH5YjsZukc35lMCGomsJ+mtMX+beyzYEej1QCQ84= 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 1705433204170321.26977205838193; Tue, 16 Jan 2024 11:26:44 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.668079.1039972 (Exim 4.92) (envelope-from ) id 1rPp4u-0003Fa-8f; Tue, 16 Jan 2024 19:26:28 +0000 Received: by outflank-mailman (output) from mailman id 668079.1039972; Tue, 16 Jan 2024 19:26:28 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rPp4u-0003F8-4m; Tue, 16 Jan 2024 19:26:28 +0000 Received: by outflank-mailman (input) for mailman id 668079; Tue, 16 Jan 2024 19:26:26 +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 1rPp4s-0002iI-Kv for xen-devel@lists.xenproject.org; Tue, 16 Jan 2024 19:26:26 +0000 Received: from smtp-fw-52005.amazon.com (smtp-fw-52005.amazon.com [52.119.213.156]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 2306d3fa-b4a5-11ee-9b0f-b553b5be7939; Tue, 16 Jan 2024 20:26:24 +0100 (CET) Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-iad-1e-m6i4x-6e7a78d7.us-east-1.amazon.com) ([10.43.8.6]) by smtp-border-fw-52005.iad7.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jan 2024 19:26:23 +0000 Received: from smtpout.prod.us-east-1.prod.farcaster.email.amazon.dev (iad7-ws-svc-p70-lb3-vlan2.iad.amazon.com [10.32.235.34]) by email-inbound-relay-iad-1e-m6i4x-6e7a78d7.us-east-1.amazon.com (Postfix) with ESMTPS id DA21380750; Tue, 16 Jan 2024 19:26:19 +0000 (UTC) Received: from EX19MTAUEB001.ant.amazon.com [10.0.44.209:34232] by smtpin.naws.us-east-1.prod.farcaster.email.amazon.dev [10.0.41.129:2525] with esmtp (Farcaster) id e3eca962-163c-4e87-9189-8e1da0e3c898; Tue, 16 Jan 2024 19:26:19 +0000 (UTC) Received: from EX19D008UEA004.ant.amazon.com (10.252.134.191) by EX19MTAUEB001.ant.amazon.com (10.252.135.108) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 16 Jan 2024 19:26:18 +0000 Received: from EX19MTAUEB001.ant.amazon.com (10.252.135.35) by EX19D008UEA004.ant.amazon.com (10.252.134.191) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 16 Jan 2024 19:26:18 +0000 Received: from dev-dsk-eliasely-1a-fd74790f.eu-west-1.amazon.com (10.253.91.118) by mail-relay.amazon.com (10.252.135.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40 via Frontend Transport; Tue, 16 Jan 2024 19:26: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 Sender: "Xen-devel" X-Inumbo-ID: 2306d3fa-b4a5-11ee-9b0f-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1705433184; x=1736969184; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3bfMq1Uef4k7zIlKxhavHHhyVuwSclhXcQaPCDrDa7g=; b=U2mekgigfQlp97fKeRfKjC/qPWGbEmz4IGoFfdKDtubzcHxaSflsjfG6 5K9mtCaBhSLR2/z2mDnHYJviq35/vO6zXD/dG+xk5D1gVQ541cin8ZtXq C7JPbYCs2Goos6ShROhNsfC3ru6OGglQ9UGhV25OUGAySGg5sPfE/BDZU Q=; X-IronPort-AV: E=Sophos;i="6.05,200,1701129600"; d="scan'208";a="627983547" X-Farcaster-Flow-ID: e3eca962-163c-4e87-9189-8e1da0e3c898 From: Elias El Yandouzi To: CC: , , , Wei Liu , Stefano Stabellini , "Bertrand Marquis" , Michal Orzel , Volodymyr Babchuk , Andrew Cooper , George Dunlap , "Jan Beulich" , Wei Liu , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , David Woodhouse , Hongyan Xia , Julien Grall , Elias El Yandouzi Subject: [PATCH v2 (resend) 02/27] x86/setup: Move vm_init() before acpi calls Date: Tue, 16 Jan 2024 19:25:46 +0000 Message-ID: <20240116192611.41112-3-eliasely@amazon.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240116192611.41112-1-eliasely@amazon.com> References: <20240116192611.41112-1-eliasely@amazon.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: Bulk X-ZohoMail-DKIM: pass (identity @amazon.com) X-ZM-MESSAGEID: 1705433205780100001 Content-Type: text/plain; charset="utf-8" From: Wei Liu After the direct map removal, pages from the boot allocator are not going to be mapped in the direct map. Although we have map_domain_page, they are ephemeral and are less helpful for mappings that are more than a page, so we want a mechanism to globally map a range of pages, which is what vmap is for. Therefore, we bring vm_init into early boot stage. To allow vmap to be initialised and used in early boot, we need to modify vmap to receive pages from the boot allocator during early boot stage. Signed-off-by: Wei Liu Signed-off-by: David Woodhouse Signed-off-by: Hongyan Xia Signed-off-by: Julien Grall Signed-off-by: Elias El Yandouzi Acked-by: Stefano Stabellini Reviewed-by: Jan Beulich ---- Changes in v2: - The return of map_pages_to_xen() is now checked in a separate patch - Clarify the commit message - Group the new boolean with the others diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index 59dd9bb25a..7e28f62d09 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -748,6 +748,8 @@ void asmlinkage __init start_xen(unsigned long boot_phy= s_offset, =20 setup_mm(); =20 + vm_init(); + /* Parse the ACPI tables for possible boot-time configuration */ acpi_boot_table_init(); =20 @@ -759,8 +761,6 @@ void asmlinkage __init start_xen(unsigned long boot_phy= s_offset, */ system_state =3D SYS_STATE_boot; =20 - vm_init(); - if ( acpi_disabled ) { printk("Booting using Device Tree\n"); diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 897b7e9208..4d0c90b7a0 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -989,6 +989,7 @@ void asmlinkage __init noreturn __start_xen(unsigned lo= ng mbi_p) int i, j, e820_warn =3D 0, bytes =3D 0; unsigned long eb_start, eb_end; bool acpi_boot_table_init_done =3D false, relocated =3D false; + bool vm_init_done =3D false; int ret; struct ns16550_defaults ns16550 =3D { .data_bits =3D 8, @@ -1531,12 +1532,23 @@ void asmlinkage __init noreturn __start_xen(unsigne= d long mbi_p) continue; =20 if ( !acpi_boot_table_init_done && - s >=3D (1ULL << 32) && - !acpi_boot_table_init() ) + s >=3D (1ULL << 32) ) { - acpi_boot_table_init_done =3D true; - srat_parse_regions(s); - setup_max_pdx(raw_max_page); + /* + * We only initialise vmap and acpi after going through the bo= ttom + * 4GiB, so that we have enough pages in the boot allocator. + */ + if ( !vm_init_done ) + { + vm_init(); + vm_init_done =3D true; + } + if ( !acpi_boot_table_init() ) + { + acpi_boot_table_init_done =3D true; + srat_parse_regions(s); + setup_max_pdx(raw_max_page); + } } =20 if ( pfn_to_pdx((e - 1) >> PAGE_SHIFT) >=3D max_pdx ) @@ -1722,6 +1734,9 @@ void asmlinkage __init noreturn __start_xen(unsigned = long mbi_p) =20 init_frametable(); =20 + if ( !vm_init_done ) + vm_init(); + if ( !acpi_boot_table_init_done ) acpi_boot_table_init(); =20 @@ -1761,12 +1776,6 @@ void asmlinkage __init noreturn __start_xen(unsigned= long mbi_p) end_boot_allocator(); =20 system_state =3D SYS_STATE_boot; - /* - * No calls involving ACPI code should go between the setting of - * SYS_STATE_boot and vm_init() (or else acpi_os_{,un}map_memory() - * will break). - */ - vm_init(); =20 bsp_stack =3D cpu_alloc_stack(0); if ( !bsp_stack ) diff --git a/xen/common/vmap.c b/xen/common/vmap.c index 830f64c5ef..fc5c70da4d 100644 --- a/xen/common/vmap.c +++ b/xen/common/vmap.c @@ -34,10 +34,19 @@ void __init vm_init_type(enum vmap_region type, void *s= tart, void *end) =20 for ( i =3D 0, va =3D (unsigned long)vm_bitmap(type); i < nr; ++i, va = +=3D PAGE_SIZE ) { - struct page_info *pg =3D alloc_domheap_page(NULL, 0); + mfn_t mfn; int rc; =20 - rc =3D map_pages_to_xen(va, page_to_mfn(pg), 1, PAGE_HYPERVISOR); + if ( system_state =3D=3D SYS_STATE_early_boot ) + mfn =3D alloc_boot_pages(1, 1); + else + { + struct page_info *pg =3D alloc_domheap_page(NULL, 0); + + BUG_ON(!pg); + mfn =3D page_to_mfn(pg); + } + rc =3D map_pages_to_xen(va, mfn, 1, PAGE_HYPERVISOR); BUG_ON(rc); =20 clear_page((void *)va); @@ -65,7 +74,7 @@ static void *vm_alloc(unsigned int nr, unsigned int align, spin_lock(&vm_lock); for ( ; ; ) { - struct page_info *pg; + mfn_t mfn; =20 ASSERT(vm_low[t] =3D=3D vm_top[t] || !test_bit(vm_low[t], vm_bitma= p(t))); for ( start =3D vm_low[t]; start < vm_top[t]; ) @@ -100,9 +109,16 @@ static void *vm_alloc(unsigned int nr, unsigned int al= ign, if ( vm_top[t] >=3D vm_end[t] ) return NULL; =20 - pg =3D alloc_domheap_page(NULL, 0); - if ( !pg ) - return NULL; + if ( system_state =3D=3D SYS_STATE_early_boot ) + mfn =3D alloc_boot_pages(1, 1); + else + { + struct page_info *pg =3D alloc_domheap_page(NULL, 0); + + if ( !pg ) + return NULL; + mfn =3D page_to_mfn(pg); + } =20 spin_lock(&vm_lock); =20 @@ -110,7 +126,7 @@ static void *vm_alloc(unsigned int nr, unsigned int ali= gn, { unsigned long va =3D (unsigned long)vm_bitmap(t) + vm_top[t] /= 8; =20 - if ( !map_pages_to_xen(va, page_to_mfn(pg), 1, PAGE_HYPERVISOR= ) ) + if ( !map_pages_to_xen(va, mfn, 1, PAGE_HYPERVISOR) ) { clear_page((void *)va); vm_top[t] +=3D PAGE_SIZE * 8; @@ -120,7 +136,10 @@ static void *vm_alloc(unsigned int nr, unsigned int al= ign, } } =20 - free_domheap_page(pg); + if ( system_state =3D=3D SYS_STATE_early_boot ) + init_boot_pages(mfn_to_maddr(mfn), mfn_to_maddr(mfn) + PAGE_SI= ZE); + else + free_domheap_page(mfn_to_page(mfn)); =20 if ( start >=3D vm_top[t] ) { --=20 2.40.1 From nobody Thu May 9 13:57:19 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=1705433215; cv=none; d=zohomail.com; s=zohoarc; b=iUHD2VuMPFZMmx5CnESi158/JiIv2LG3Isjt7d584plZAMLFgdizkzqNdb/a6L/8JZvxRYqLk5M4qUJUT8cALMvaJPS5sdlvrqraoLq8I6m5JwRX5BgRenRPAGSqOz7kXi7Z7Vqdc5lwzeVj6bJ/i7G+j8oq2MAZfbZBtDAEJTM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705433215; 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=8FsCSW5o3cFuUs+oU0aAarf/rBoTpzODox4faRm0p08=; b=PtoZq7sjWggMF3QosPcdmPAIRNq8jTSnQJQMPpgqcBE5LiGCtwDjz8Um2OnTPHFY8MJHI+KxEr3T5Jvvs/bF7ZgTMm8SjBtpdDP6kYc/mNID+mw/SnifYrVDWFkv3fMoGM0K215ZR1TBQRWMfdyNzeXDwSdsRQj7222D4l2dfJk= 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 1705433215582947.5675984895162; Tue, 16 Jan 2024 11:26:55 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.668084.1040017 (Exim 4.92) (envelope-from ) id 1rPp53-0004QK-77; Tue, 16 Jan 2024 19:26:37 +0000 Received: by outflank-mailman (output) from mailman id 668084.1040017; Tue, 16 Jan 2024 19:26:37 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rPp52-0004OT-UE; Tue, 16 Jan 2024 19:26:36 +0000 Received: by outflank-mailman (input) for mailman id 668084; Tue, 16 Jan 2024 19:26:35 +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 1rPp51-0002iI-BF for xen-devel@lists.xenproject.org; Tue, 16 Jan 2024 19:26:35 +0000 Received: from smtp-fw-9106.amazon.com (smtp-fw-9106.amazon.com [207.171.188.206]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 277952f4-b4a5-11ee-9b0f-b553b5be7939; Tue, 16 Jan 2024 20:26:33 +0100 (CET) Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO email-inbound-relay-iad-1a-m6i4x-b5bd57cf.us-east-1.amazon.com) ([10.25.36.210]) by smtp-border-fw-9106.sea19.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jan 2024 19:26:25 +0000 Received: from smtpout.prod.us-east-1.prod.farcaster.email.amazon.dev (iad7-ws-svc-p70-lb3-vlan3.iad.amazon.com [10.32.235.38]) by email-inbound-relay-iad-1a-m6i4x-b5bd57cf.us-east-1.amazon.com (Postfix) with ESMTPS id 2AEEA4A030; Tue, 16 Jan 2024 19:26:22 +0000 (UTC) Received: from EX19MTAUEA002.ant.amazon.com [10.0.29.78:58155] by smtpin.naws.us-east-1.prod.farcaster.email.amazon.dev [10.0.28.244:2525] with esmtp (Farcaster) id fbe8e0d8-d681-4c49-bf24-a619c28870a6; Tue, 16 Jan 2024 19:26:21 +0000 (UTC) Received: from EX19D008UEA004.ant.amazon.com (10.252.134.191) 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.1118.40; Tue, 16 Jan 2024 19:26:20 +0000 Received: from EX19MTAUEB001.ant.amazon.com (10.252.135.35) by EX19D008UEA004.ant.amazon.com (10.252.134.191) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 16 Jan 2024 19:26:19 +0000 Received: from dev-dsk-eliasely-1a-fd74790f.eu-west-1.amazon.com (10.253.91.118) by mail-relay.amazon.com (10.252.135.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40 via Frontend Transport; Tue, 16 Jan 2024 19:26:18 +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 Sender: "Xen-devel" X-Inumbo-ID: 277952f4-b4a5-11ee-9b0f-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1705433193; x=1736969193; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8FsCSW5o3cFuUs+oU0aAarf/rBoTpzODox4faRm0p08=; b=J/V+Yegr1PjiC7Loro6hTCvK6l4wKK4yIqNBCNTT7uq6rBaoYIuOhcta NXmR23Xt5bw+DKtYQQx3B1OXy9ck1aUnSeY0cczTpWUvqbX7gbQv2tGeH eKQO7FrCRCZvOWHgwH0K9/xYnmgl1d7XENvk4T91kpTrvzMRrKfKKg57E s=; X-IronPort-AV: E=Sophos;i="6.05,200,1701129600"; d="scan'208";a="697582403" X-Farcaster-Flow-ID: fbe8e0d8-d681-4c49-bf24-a619c28870a6 From: Elias El Yandouzi To: CC: , , , Julien Grall , Andrew Cooper , George Dunlap , Jan Beulich , "Stefano Stabellini" , Wei Liu , Elias El Yandouzi Subject: [PATCH v2 (resend) 03/27] xen/vmap: Introduce vmap_size() and use it Date: Tue, 16 Jan 2024 19:25:47 +0000 Message-ID: <20240116192611.41112-4-eliasely@amazon.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240116192611.41112-1-eliasely@amazon.com> References: <20240116192611.41112-1-eliasely@amazon.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: Bulk X-ZohoMail-DKIM: pass (identity @amazon.com) X-ZM-MESSAGEID: 1705433215870100007 Content-Type: text/plain; charset="utf-8" From: Julien Grall vunmap() and vfree() currently duplicate the (small) logic to find the size of an vmap area. In a follow-up patch, we will want to introduce another one (this time externally). So introduce a new helper vmap_size() that will return the number of pages in the area starting at the given address. Take the opportunity to replace the open-coded version. Note that vfree() was storing the type of the area in a local variable. But this seems to have never been used (even when it was introduced). Signed-off-by: Julien Grall Signed-off-by: Elias El Yandouzi Acked-by: Jan Beulich ---- Changes in v2: * Patch added diff --git a/xen/common/vmap.c b/xen/common/vmap.c index fc5c70da4d..171271fae3 100644 --- a/xen/common/vmap.c +++ b/xen/common/vmap.c @@ -245,14 +245,21 @@ void *vmap(const mfn_t *mfn, unsigned int nr) return __vmap(mfn, 1, nr, 1, PAGE_HYPERVISOR, VMAP_DEFAULT); } =20 -void vunmap(const void *va) +unsigned int vmap_size(const void *va) { - unsigned long addr =3D (unsigned long)va; unsigned int pages =3D vm_size(va, VMAP_DEFAULT); =20 if ( !pages ) pages =3D vm_size(va, VMAP_XEN); =20 + return pages; +} + +void vunmap(const void *va) +{ + unsigned long addr =3D (unsigned long)va; + unsigned pages =3D vmap_size(va); + #ifndef _PAGE_NONE destroy_xen_mappings(addr, addr + PAGE_SIZE * pages); #else /* Avoid tearing down intermediate page tables. */ @@ -328,17 +335,11 @@ void vfree(void *va) unsigned int i, pages; struct page_info *pg; PAGE_LIST_HEAD(pg_list); - enum vmap_region type =3D VMAP_DEFAULT; =20 if ( !va ) return; =20 - pages =3D vm_size(va, type); - if ( !pages ) - { - type =3D VMAP_XEN; - pages =3D vm_size(va, type); - } + pages =3D vmap_size(va); ASSERT(pages); =20 for ( i =3D 0; i < pages; i++ ) diff --git a/xen/include/xen/vmap.h b/xen/include/xen/vmap.h index 2b7369e062..24c85de490 100644 --- a/xen/include/xen/vmap.h +++ b/xen/include/xen/vmap.h @@ -25,6 +25,9 @@ void vfree(void *va); =20 void __iomem *ioremap(paddr_t pa, size_t len); =20 +/* Return the number of pages in the mapping starting at address 'va' */ +unsigned int vmap_size(const void *va); + static inline void iounmap(void __iomem *va) { unsigned long addr =3D (unsigned long)(void __force *)va; --=20 2.40.1 From nobody Thu May 9 13:57:19 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=1705433215; cv=none; d=zohomail.com; s=zohoarc; b=H0NYidx9BpYe/aSyzwqgY8zi3uYXrc9cZEKXDD63a+lTyMwPMCiQVnpWFCw+N0BV1m8fwSLiDQPdHJJt9zEHGLbKX1pJY6qB/a36tkmyeETyhAk0MncTPfrbH6q21loibQnKBDzP7whZFDP2QH46fLrn4v+v/XQ010GIjT0O/F4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705433215; 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=OfEYXQrUMYXPAWM79GmQhfyI8aqQMCL5v2pGd2UmDoQ=; b=BqF3IpEcMUQ8cckXfr4bWMNCO6bsnl5Z1XBSBbXvOOmnPgLyABRSv6mGQh+7cg72xLF0u24RIU+MM2PeRExWJ7y+BHSUnFbXqwxjnImb8AogvgMsU3Io5vyrhVsog8Kup8Z+RqwWg5HlX9IALbFrC0NoPVwje04AJyU9rV0ShKA= 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 1705433215892473.95747661257565; Tue, 16 Jan 2024 11:26:55 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.668086.1040029 (Exim 4.92) (envelope-from ) id 1rPp54-0004sG-Ka; Tue, 16 Jan 2024 19:26:38 +0000 Received: by outflank-mailman (output) from mailman id 668086.1040029; Tue, 16 Jan 2024 19:26:38 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rPp54-0004qW-CS; Tue, 16 Jan 2024 19:26:38 +0000 Received: by outflank-mailman (input) for mailman id 668086; Tue, 16 Jan 2024 19:26:36 +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 1rPp52-0003Xv-Pk for xen-devel@lists.xenproject.org; Tue, 16 Jan 2024 19:26:36 +0000 Received: from smtp-fw-80007.amazon.com (smtp-fw-80007.amazon.com [99.78.197.218]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 27577966-b4a5-11ee-98f1-6d05b1d4d9a1; Tue, 16 Jan 2024 20:26:34 +0100 (CET) Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO email-inbound-relay-iad-1a-m6i4x-96feee09.us-east-1.amazon.com) ([10.25.36.210]) by smtp-border-fw-80007.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jan 2024 19:26:29 +0000 Received: from smtpout.prod.us-east-1.prod.farcaster.email.amazon.dev (iad7-ws-svc-p70-lb3-vlan2.iad.amazon.com [10.32.235.34]) by email-inbound-relay-iad-1a-m6i4x-96feee09.us-east-1.amazon.com (Postfix) with ESMTPS id 87DC94AC9A; Tue, 16 Jan 2024 19:26:24 +0000 (UTC) Received: from EX19MTAUEB002.ant.amazon.com [10.0.29.78:45401] by smtpin.naws.us-east-1.prod.farcaster.email.amazon.dev [10.0.89.133:2525] with esmtp (Farcaster) id d55e2cef-2007-41b2-bf89-6108138fb5eb; Tue, 16 Jan 2024 19:26:24 +0000 (UTC) Received: from EX19D008UEA003.ant.amazon.com (10.252.134.116) by EX19MTAUEB002.ant.amazon.com (10.252.135.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 16 Jan 2024 19:26:21 +0000 Received: from EX19MTAUEB001.ant.amazon.com (10.252.135.35) by EX19D008UEA003.ant.amazon.com (10.252.134.116) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 16 Jan 2024 19:26:21 +0000 Received: from dev-dsk-eliasely-1a-fd74790f.eu-west-1.amazon.com (10.253.91.118) by mail-relay.amazon.com (10.252.135.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40 via Frontend Transport; Tue, 16 Jan 2024 19:26:20 +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 Sender: "Xen-devel" X-Inumbo-ID: 27577966-b4a5-11ee-98f1-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1705433195; x=1736969195; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OfEYXQrUMYXPAWM79GmQhfyI8aqQMCL5v2pGd2UmDoQ=; b=mvOpX/TXdj8oavfa8ECbnQDh7OTbLI8rQZ6s+NH4M0rXJM9ftnaqBZhf ECzpwxxmbcdwJqGLaLCLO9ZglXT2dBvE09QcpFu6+d+UryDYfZ8E0teEx V1CFfYpaKtV/qDTWpfzqVVY9CN3eOY0enQhBvE5BXF8XyaMskQbrwagl5 g=; X-IronPort-AV: E=Sophos;i="6.05,200,1701129600"; d="scan'208";a="267191231" X-Farcaster-Flow-ID: d55e2cef-2007-41b2-bf89-6108138fb5eb From: Elias El Yandouzi To: CC: , , , Hongyan Xia , Andrew Cooper , "George Dunlap" , Jan Beulich , "Stefano Stabellini" , Wei Liu , Julien Grall , Elias El Yandouzi Subject: [PATCH v2 (resend) 04/27] acpi: vmap pages in acpi_os_alloc_memory Date: Tue, 16 Jan 2024 19:25:48 +0000 Message-ID: <20240116192611.41112-5-eliasely@amazon.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240116192611.41112-1-eliasely@amazon.com> References: <20240116192611.41112-1-eliasely@amazon.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: Bulk X-ZohoMail-DKIM: pass (identity @amazon.com) X-ZM-MESSAGEID: 1705433217821100011 Content-Type: text/plain; charset="utf-8" From: Hongyan Xia Also, introduce a wrapper around vmap that maps a contiguous range for boot allocations. Unfortunately, the new helper cannot be a static inline because the dependencies are a mess. We would need to re-include asm/page.h (was removed in aa4b9d1ee653 "include: don't use asm/page.h from common headers") and it doesn't look to be enough anymore because bits from asm/cpufeature.h is used in the definition of PAGE_NX. Lastly, with the move to vmap(), it is now easier to find the size of the mapping. So pass the whole area to init_boot_pages() rather than just the first page. Signed-off-by: Hongyan Xia Signed-off-by: Julien Grall Signed-off-by: Elias El Yandouzi Acked-by: Jan Beulich ---- Changes in v2: * Rename vmap_contig_pages() to vmap_contig() * Rename nr_pages to nr to be consistent with vmap() parameters * Pass the whole region to init_boot_pages() Changes since Hongyan's version: * Rename vmap_boot_pages() to vmap_contig_pages() * Move the new helper in vmap.c to avoid compilation issue * Don't use __pa() to translate the virtual address diff --git a/xen/common/vmap.c b/xen/common/vmap.c index 171271fae3..966a7e763f 100644 --- a/xen/common/vmap.c +++ b/xen/common/vmap.c @@ -245,6 +245,11 @@ void *vmap(const mfn_t *mfn, unsigned int nr) return __vmap(mfn, 1, nr, 1, PAGE_HYPERVISOR, VMAP_DEFAULT); } =20 +void *vmap_contig(mfn_t mfn, unsigned int nr) +{ + return __vmap(&mfn, nr, 1, 1, PAGE_HYPERVISOR, VMAP_DEFAULT); +} + unsigned int vmap_size(const void *va) { unsigned int pages =3D vm_size(va, VMAP_DEFAULT); diff --git a/xen/drivers/acpi/osl.c b/xen/drivers/acpi/osl.c index 389505f786..ab80d6b2a9 100644 --- a/xen/drivers/acpi/osl.c +++ b/xen/drivers/acpi/osl.c @@ -221,7 +221,11 @@ void *__init acpi_os_alloc_memory(size_t sz) void *ptr; =20 if (system_state =3D=3D SYS_STATE_early_boot) - return mfn_to_virt(mfn_x(alloc_boot_pages(PFN_UP(sz), 1))); + { + mfn_t mfn =3D alloc_boot_pages(PFN_UP(sz), 1); + + return vmap_contig(mfn, PFN_UP(sz)); + } =20 ptr =3D xmalloc_bytes(sz); ASSERT(!ptr || is_xmalloc_memory(ptr)); @@ -246,5 +250,11 @@ void __init acpi_os_free_memory(void *ptr) if (is_xmalloc_memory(ptr)) xfree(ptr); else if (ptr && system_state =3D=3D SYS_STATE_early_boot) - init_boot_pages(__pa(ptr), __pa(ptr) + PAGE_SIZE); + { + paddr_t addr =3D mfn_to_maddr(vmap_to_mfn(ptr)); + unsigned int nr =3D vmap_size(ptr); + + vunmap(ptr); + init_boot_pages(addr, addr + nr * PAGE_SIZE); + } } diff --git a/xen/include/xen/vmap.h b/xen/include/xen/vmap.h index 24c85de490..0c16baa85f 100644 --- a/xen/include/xen/vmap.h +++ b/xen/include/xen/vmap.h @@ -15,6 +15,7 @@ void vm_init_type(enum vmap_region type, void *start, voi= d *end); void *__vmap(const mfn_t *mfn, unsigned int granularity, unsigned int nr, unsigned int align, unsigned int flags, enum vmap_region type= ); void *vmap(const mfn_t *mfn, unsigned int nr); +void *vmap_contig(mfn_t mfn, unsigned int nr); void vunmap(const void *va); =20 void *vmalloc(size_t size); --=20 2.40.1 From nobody Thu May 9 13:57:19 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=1705433215; cv=none; d=zohomail.com; s=zohoarc; b=E8w7hEZ4my8mI2wGlQGVyb/ueP9dibyUI/prjKsJSV2L+2/Pvy3edXzkZoS/kjJIbyfLbzynkCalxWXUigwHYJCEnK2PKFUSeIQL8jP44TRLnWyEe+hWwvbRx2ZDe8YkGQNghyIQ4Z6cfSOVKkFSd1V5e5fEDpckKMcUnh0Sp0s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705433215; 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=FgFciMpLuDVe/Ws8Mo0D+wl9Af+6on00mUDD4ztD+mE=; b=SnE73+Ov78riacNhuDrMjv711GHLEnF1TpF1sePhjuR2EPqvBiFZckA5f0QQ9VDwwBfx8u/Jk1mvtrObcxL7Ye4ziZm0Z+dOGUJvbuWQ6+Pjsk6zpxv/U/rD5r/npawbpIfKdRiqpqIFW195lMNZgWvsjXOZv2eFElTSoSrQwa4= 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 1705433215070111.15787854420785; Tue, 16 Jan 2024 11:26:55 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.668081.1039992 (Exim 4.92) (envelope-from ) id 1rPp50-0003sY-Um; Tue, 16 Jan 2024 19:26:34 +0000 Received: by outflank-mailman (output) from mailman id 668081.1039992; Tue, 16 Jan 2024 19:26:34 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rPp50-0003sR-Ql; Tue, 16 Jan 2024 19:26:34 +0000 Received: by outflank-mailman (input) for mailman id 668081; Tue, 16 Jan 2024 19:26:33 +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 1rPp4z-0003Xv-LJ for xen-devel@lists.xenproject.org; Tue, 16 Jan 2024 19:26:33 +0000 Received: from smtp-fw-80006.amazon.com (smtp-fw-80006.amazon.com [99.78.197.217]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 26e12f07-b4a5-11ee-98f1-6d05b1d4d9a1; Tue, 16 Jan 2024 20:26:32 +0100 (CET) Received: from pdx4-co-svc-p1-lb2-vlan3.amazon.com (HELO email-inbound-relay-pdx-2a-m6i4x-3ef535ca.us-west-2.amazon.com) ([10.25.36.214]) by smtp-border-fw-80006.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jan 2024 19:26:29 +0000 Received: from smtpout.prod.us-east-1.prod.farcaster.email.amazon.dev (pdx2-ws-svc-p26-lb5-vlan2.pdx.amazon.com [10.39.38.66]) by email-inbound-relay-pdx-2a-m6i4x-3ef535ca.us-west-2.amazon.com (Postfix) with ESMTPS id 624BD609EA; Tue, 16 Jan 2024 19:26:26 +0000 (UTC) Received: from EX19MTAUEB001.ant.amazon.com [10.0.44.209:34536] by smtpin.naws.us-east-1.prod.farcaster.email.amazon.dev [10.0.3.20:2525] with esmtp (Farcaster) id 5204e9b5-4ffe-4f9b-a668-3a37bda75b90; Tue, 16 Jan 2024 19:26:25 +0000 (UTC) Received: from EX19D008UEA003.ant.amazon.com (10.252.134.116) by EX19MTAUEB001.ant.amazon.com (10.252.135.108) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 16 Jan 2024 19:26:22 +0000 Received: from EX19MTAUEB001.ant.amazon.com (10.252.135.35) by EX19D008UEA003.ant.amazon.com (10.252.134.116) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 16 Jan 2024 19:26:22 +0000 Received: from dev-dsk-eliasely-1a-fd74790f.eu-west-1.amazon.com (10.253.91.118) by mail-relay.amazon.com (10.252.135.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40 via Frontend Transport; Tue, 16 Jan 2024 19:26:21 +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 Sender: "Xen-devel" X-Inumbo-ID: 26e12f07-b4a5-11ee-98f1-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1705433193; x=1736969193; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=FgFciMpLuDVe/Ws8Mo0D+wl9Af+6on00mUDD4ztD+mE=; b=a0gy08PIcgQAWR60qQaCwATt2HxbGCqrIxwZOio+y+p9WUUoo1K398Pq TB8nsB2y+Fju4iUQNXj9/Nz3cEJtxXSIvYZn8CinyHguiN33sFletCKFB MGWUAaq2cYUXtPjnG+UprRSepf0g/GLoWS8V7uTDnFaHekPL5572KWhup 4=; X-IronPort-AV: E=Sophos;i="6.05,200,1701129600"; d="scan'208";a="266414239" X-Farcaster-Flow-ID: 5204e9b5-4ffe-4f9b-a668-3a37bda75b90 From: Elias El Yandouzi To: CC: , , , Hongyan Xia , Andrew Cooper , "George Dunlap" , Jan Beulich , "Stefano Stabellini" , Wei Liu , Julien Grall , Elias El Yandouzi Subject: [PATCH v2 (resend) 05/27] xen/numa: vmap the pages for memnodemap Date: Tue, 16 Jan 2024 19:25:49 +0000 Message-ID: <20240116192611.41112-6-eliasely@amazon.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240116192611.41112-1-eliasely@amazon.com> References: <20240116192611.41112-1-eliasely@amazon.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: Bulk X-ZohoMail-DKIM: pass (identity @amazon.com) X-ZM-MESSAGEID: 1705433215864100005 Content-Type: text/plain; charset="utf-8" From: Hongyan Xia This avoids the assumption that there is a direct map and boot pages fall inside the direct map. Clean up the variables so that mfn actually stores a type-safe mfn. Signed-off-by: Hongyan Xia Signed-off-by: Julien Grall Signed-off-by: Elias El Yandouzi Reviewed-by: Jan Beulich ---- See the discussion in the next patch about using panic(). Changes in v2: * vmap_contig_pages() was renamed to vmap_contig() * Replace the BUG_ON() with a panic() Changes compare to Hongyan's version: * The function modified was moved to common code. So rebase it * vmap_boot_pages() was renamed to vmap_contig_pages() diff --git a/xen/common/numa.c b/xen/common/numa.c index f454c4d894..ef13ec2255 100644 --- a/xen/common/numa.c +++ b/xen/common/numa.c @@ -424,13 +424,14 @@ static int __init populate_memnodemap(const struct no= de *nodes, static int __init allocate_cachealigned_memnodemap(void) { unsigned long size =3D PFN_UP(memnodemapsize * sizeof(*memnodemap)); - unsigned long mfn =3D mfn_x(alloc_boot_pages(size, 1)); + mfn_t mfn =3D alloc_boot_pages(size, 1); =20 - memnodemap =3D mfn_to_virt(mfn); - mfn <<=3D PAGE_SHIFT; + memnodemap =3D vmap_contig(mfn, size); + if ( !memnodemap ) + panic("Unable to map the ACPI SLIT. Retry with numa=3Doff"); size <<=3D PAGE_SHIFT; printk(KERN_DEBUG "NUMA: Allocated memnodemap from %lx - %lx\n", - mfn, mfn + size); + mfn_to_maddr(mfn), mfn_to_maddr(mfn) + size); memnodemapsize =3D size / sizeof(*memnodemap); =20 return 0; --=20 2.40.1 From nobody Thu May 9 13:57:19 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=1705433215; cv=none; d=zohomail.com; s=zohoarc; b=AWURearMfuUBc59eYEW8NrBRwMNoYpYP2+yqTU26WviCEeQp23a3Fvkr14qgWwP++RcRcYu08RtVU4y1EwOlJXalyNfZfsG7W6qqwWPQL7BypgiitLN+5WUlpFhlc3CUv5iJ6+GmT+r0J1/gRyBXFPS6M5D25f2IUIqBFYSYEtU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705433215; 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=0fmTmB+LBqRWLY5/DwT7016ODIBBvVRLjSKMws6FDOA=; b=XpfCx9wCSCS2NxlMvaKapvFjjqj59yGCnE0LU+mjvlGIq8ytoS83tu66N7MGY44iWSW0WiDLnny4ZuxU48DJaIapY1mxc8TLtOW/oSrswfs3MqiUBYmzNg0jicazu+bS7U/1Rtfxk64SRWmm5lUYUhtLa3BMGDYlrtGoUJOASXY= 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 1705433215064600.1824766769278; Tue, 16 Jan 2024 11:26:55 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.668083.1040011 (Exim 4.92) (envelope-from ) id 1rPp52-0004LT-NU; Tue, 16 Jan 2024 19:26:36 +0000 Received: by outflank-mailman (output) from mailman id 668083.1040011; Tue, 16 Jan 2024 19:26:36 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rPp52-0004Jp-Hm; Tue, 16 Jan 2024 19:26:36 +0000 Received: by outflank-mailman (input) for mailman id 668083; Tue, 16 Jan 2024 19:26:35 +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 1rPp51-0003Xv-5F for xen-devel@lists.xenproject.org; Tue, 16 Jan 2024 19:26:35 +0000 Received: from smtp-fw-33001.amazon.com (smtp-fw-33001.amazon.com [207.171.190.10]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 27fc177c-b4a5-11ee-98f1-6d05b1d4d9a1; Tue, 16 Jan 2024 20:26:34 +0100 (CET) Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-pdx-2b-m6i4x-cadc3fbd.us-west-2.amazon.com) ([10.43.8.6]) by smtp-border-fw-33001.sea14.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jan 2024 19:26:26 +0000 Received: from smtpout.prod.us-east-1.prod.farcaster.email.amazon.dev (pdx2-ws-svc-p26-lb5-vlan2.pdx.amazon.com [10.39.38.66]) by email-inbound-relay-pdx-2b-m6i4x-cadc3fbd.us-west-2.amazon.com (Postfix) with ESMTPS id 653E0A0786; Tue, 16 Jan 2024 19:26:24 +0000 (UTC) Received: from EX19MTAUEA002.ant.amazon.com [10.0.29.78:3848] by smtpin.naws.us-east-1.prod.farcaster.email.amazon.dev [10.0.41.129:2525] with esmtp (Farcaster) id f2469a8a-a9e5-458c-a299-f2be24413d76; Tue, 16 Jan 2024 19:26:24 +0000 (UTC) Received: from EX19D008UEC004.ant.amazon.com (10.252.135.170) 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.1118.40; Tue, 16 Jan 2024 19:26:23 +0000 Received: from EX19MTAUEB001.ant.amazon.com (10.252.135.35) by EX19D008UEC004.ant.amazon.com (10.252.135.170) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 16 Jan 2024 19:26:23 +0000 Received: from dev-dsk-eliasely-1a-fd74790f.eu-west-1.amazon.com (10.253.91.118) by mail-relay.amazon.com (10.252.135.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40 via Frontend Transport; Tue, 16 Jan 2024 19:26:22 +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 Sender: "Xen-devel" X-Inumbo-ID: 27fc177c-b4a5-11ee-98f1-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1705433194; x=1736969194; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0fmTmB+LBqRWLY5/DwT7016ODIBBvVRLjSKMws6FDOA=; b=POp82GfUbDdUSIH5x3gb2EEWALVUXCAbRcRJ21UT8KwWbs66r/fBF79L Er7/o2IFFOtE5fd8AI2ariNHKcMZqXAFuJOLJmkk/8Q8+ukwbX+wpk9Ge qcGqCyEaC1pza9GXQK29j7Xrx/ew6dzeotO6kIIYvbp0Nm5abX4OrVkzU 0=; X-IronPort-AV: E=Sophos;i="6.05,200,1701129600"; d="scan'208";a="321879755" X-Farcaster-Flow-ID: f2469a8a-a9e5-458c-a299-f2be24413d76 From: Elias El Yandouzi To: CC: , , , Hongyan Xia , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , Julien Grall , Elias El Yandouzi Subject: [PATCH v2 (resend) 06/27] x86/srat: vmap the pages for acpi_slit Date: Tue, 16 Jan 2024 19:25:50 +0000 Message-ID: <20240116192611.41112-7-eliasely@amazon.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240116192611.41112-1-eliasely@amazon.com> References: <20240116192611.41112-1-eliasely@amazon.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: Bulk X-ZohoMail-DKIM: pass (identity @amazon.com) X-ZM-MESSAGEID: 1705433215864100006 Content-Type: text/plain; charset="utf-8" From: Hongyan Xia This avoids the assumption that boot pages are in the direct map. Signed-off-by: Hongyan Xia Signed-off-by: Julien Grall Signed-off-by: Elias El Yandouzi Reviewed-by: Jan Beulich ---- There was a discussion with Jan regarding early failure vs disable NUMA. I am strongly in favor of the latter because it is more obvious that something went wrong. From my understanding, Jan seems to be in favor of turning off NUMA and then continue to boot. But then implied that a panic() would be fine. So I went with the panic() version. I am happy to rework it to another approach if there is a consensus. Changes in v2: * vmap_contig_pages() was renamed to vmap_contig() * Use a panic() rather than BUG_ON() Changes since Hongyan's version: * vmap_boot_pages() was renamed to vmap_contig_pages() diff --git a/xen/arch/x86/srat.c b/xen/arch/x86/srat.c index 3f70338e6e..688f410287 100644 --- a/xen/arch/x86/srat.c +++ b/xen/arch/x86/srat.c @@ -135,7 +135,9 @@ void __init acpi_numa_slit_init(struct acpi_table_slit = *slit) return; } mfn =3D alloc_boot_pages(PFN_UP(slit->header.length), 1); - acpi_slit =3D mfn_to_virt(mfn_x(mfn)); + acpi_slit =3D vmap_contig(mfn, PFN_UP(slit->header.length)); + if ( !acpi_slit ) + panic("Unable to map the ACPI SLIT. Retry with numa=3Doff"); memcpy(acpi_slit, slit, slit->header.length); } =20 --=20 2.40.1 From nobody Thu May 9 13:57:19 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=1705433212; cv=none; d=zohomail.com; s=zohoarc; b=ZO/FmcY6oiw5ZtiJDUFOzvreCHZCL/LtypA3FvHeEQwk5ns1x1dMFlkhLiMS0fBuFE31uKz6c2Dwe4zWsf7A9IZZBrJj0a42AW+QIksJ4VRs5/Oug553KjUrv5jt2DFwXIwkInYQR83Gl7N5k3iagxKtOnQM0KduB6q7H65PX+s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705433212; 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=RlZPoKBPtPftpmhS8npiHVFZDFdnG1+rb/ajeW5MDFo=; b=XjDVndi75Zd+c4cX02P+NWhc/w2+smbzmedRISS2oLYIi7ACKCKlsE2vh+KVVI4UykDh529as5h2nrTpVafjYdeTLX4+t/cgoDnQELNU+OnbLtzNrT9IKElzJlqGbqVPK7sheh3BPq1ERFezsIOtIh0AEytM80ynkMw22PqghEM= 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 1705433212892349.0005727255119; Tue, 16 Jan 2024 11:26:52 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.668080.1039982 (Exim 4.92) (envelope-from ) id 1rPp4z-0003bE-Gw; Tue, 16 Jan 2024 19:26:33 +0000 Received: by outflank-mailman (output) from mailman id 668080.1039982; Tue, 16 Jan 2024 19:26:33 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rPp4z-0003at-Ch; Tue, 16 Jan 2024 19:26:33 +0000 Received: by outflank-mailman (input) for mailman id 668080; Tue, 16 Jan 2024 19:26:32 +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 1rPp4y-0003Xv-2o for xen-devel@lists.xenproject.org; Tue, 16 Jan 2024 19:26:32 +0000 Received: from smtp-fw-52004.amazon.com (smtp-fw-52004.amazon.com [52.119.213.154]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 26299e47-b4a5-11ee-98f1-6d05b1d4d9a1; Tue, 16 Jan 2024 20:26:30 +0100 (CET) Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-pdx-2b-m6i4x-7fa2de02.us-west-2.amazon.com) ([10.43.8.2]) by smtp-border-fw-52004.iad7.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jan 2024 19:26:28 +0000 Received: from smtpout.prod.us-east-1.prod.farcaster.email.amazon.dev (pdx2-ws-svc-p26-lb5-vlan2.pdx.amazon.com [10.39.38.66]) by email-inbound-relay-pdx-2b-m6i4x-7fa2de02.us-west-2.amazon.com (Postfix) with ESMTPS id EBE47410A5; Tue, 16 Jan 2024 19:26:26 +0000 (UTC) Received: from EX19MTAUEA001.ant.amazon.com [10.0.29.78:2602] by smtpin.naws.us-east-1.prod.farcaster.email.amazon.dev [10.0.57.22:2525] with esmtp (Farcaster) id e792b96e-ad88-4b4f-ac4b-041a01b78128; Tue, 16 Jan 2024 19:26:26 +0000 (UTC) Received: from EX19D008UEA004.ant.amazon.com (10.252.134.191) by EX19MTAUEA001.ant.amazon.com (10.252.134.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 16 Jan 2024 19:26:24 +0000 Received: from EX19MTAUEB001.ant.amazon.com (10.252.135.35) by EX19D008UEA004.ant.amazon.com (10.252.134.191) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 16 Jan 2024 19:26:24 +0000 Received: from dev-dsk-eliasely-1a-fd74790f.eu-west-1.amazon.com (10.253.91.118) by mail-relay.amazon.com (10.252.135.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40 via Frontend Transport; Tue, 16 Jan 2024 19:26:23 +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 Sender: "Xen-devel" X-Inumbo-ID: 26299e47-b4a5-11ee-98f1-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1705433191; x=1736969191; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RlZPoKBPtPftpmhS8npiHVFZDFdnG1+rb/ajeW5MDFo=; b=D9OVH2+o8lgOUCuFIlqUB2ZmF5cKOn+zgZgdQvM5AWJvm/t+q+4Kthkv o6c+voUgcCF3gX+vLaq25om9RCZLSDATRdqN6v3QgaCxpreAuaK1Xj3un hk9oMxehNH1e3iQwNmX45rlEq4QaDR3L4/mUjMe/6bG5vzsBA4GUl5mO+ Q=; X-IronPort-AV: E=Sophos;i="6.05,200,1701129600"; d="scan'208";a="178399454" X-Farcaster-Flow-ID: e792b96e-ad88-4b4f-ac4b-041a01b78128 From: Elias El Yandouzi To: CC: , , , Hongyan Xia , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , Julien Grall , Elias El Yandouzi Subject: [PATCH v2 (resend) 07/27] x86: Map/unmap pages in restore_all_guests Date: Tue, 16 Jan 2024 19:25:51 +0000 Message-ID: <20240116192611.41112-8-eliasely@amazon.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240116192611.41112-1-eliasely@amazon.com> References: <20240116192611.41112-1-eliasely@amazon.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: Bulk X-ZohoMail-DKIM: pass (identity @amazon.com) X-ZM-MESSAGEID: 1705433213856100002 Content-Type: text/plain; charset="utf-8" From: Hongyan Xia Before, it assumed the pv cr3 could be accessed via a direct map. This is no longer true. Note that we do not map and unmap root_pgt for now since it is still a xenheap page. Signed-off-by: Hongyan Xia Signed-off-by: Julien Grall Signed-off-by: Elias El Yandouzi ---- Changes in V2: * Rework the shadow perdomain mapping solution in the follow-up pat= ches Changes since Hongyan's version: * Remove the final dot in the commit title diff --git a/xen/arch/x86/include/asm/config.h b/xen/arch/x86/include/asm/c= onfig.h index bbced338be..7cf1f33dc0 100644 --- a/xen/arch/x86/include/asm/config.h +++ b/xen/arch/x86/include/asm/config.h @@ -202,7 +202,7 @@ extern unsigned char boot_edid_info[128]; /* Slot 260: per-domain mappings (including map cache). */ #define PERDOMAIN_VIRT_START (PML4_ADDR(260)) #define PERDOMAIN_SLOT_MBYTES (PML4_ENTRY_BYTES >> (20 + PAGETABLE_ORDER= )) -#define PERDOMAIN_SLOTS 3 +#define PERDOMAIN_SLOTS 4 #define PERDOMAIN_VIRT_SLOT(s) (PERDOMAIN_VIRT_START + (s) * \ (PERDOMAIN_SLOT_MBYTES << 20)) /* Slot 4: mirror of per-domain mappings (for compat xlat area accesses). = */ @@ -316,6 +316,16 @@ extern unsigned long xen_phys_start; #define ARG_XLAT_START(v) \ (ARG_XLAT_VIRT_START + ((v)->vcpu_id << ARG_XLAT_VA_SHIFT)) =20 +/* root_pt shadow mapping area. The fourth per-domain-mapping sub-area */ +#define SHADOW_ROOT_PT_VIRT_START PERDOMAIN_VIRT_SLOT(3) +#define SHADOW_ROOT_PT_ENTRIES MAX_VIRT_CPUS +#define SHADOW_ROOT_PT_VIRT_END (SHADOW_ROOT_PT_VIRT_START + \ + (SHADOW_ROOT_PT_ENTRIES * PAGE_SIZE)) + +/* The address of a particular VCPU's ROOT_PT */ +#define SHADOW_ROOT_PT_VCPU_VIRT_START(v) \ + (SHADOW_ROOT_PT_VIRT_START + ((v)->vcpu_id * PAGE_SIZE)) + #define ELFSIZE 64 =20 #define ARCH_CRASH_SAVE_VMCOREINFO diff --git a/xen/arch/x86/include/asm/domain.h b/xen/arch/x86/include/asm/d= omain.h index 622d22bef2..4d97c68028 100644 --- a/xen/arch/x86/include/asm/domain.h +++ b/xen/arch/x86/include/asm/domain.h @@ -273,6 +273,7 @@ struct time_scale { struct pv_domain { l1_pgentry_t **gdt_ldt_l1tab; + l1_pgentry_t **shadow_root_pt_l1tab; =20 atomic_t nr_l4_pages; =20 diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index b56e0d8065..a72c32d87c 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -505,6 +505,13 @@ void share_xen_page_with_guest(struct page_info *page,= struct domain *d, spin_unlock(&d->page_alloc_lock); } =20 +#define shadow_root_pt_idx(v) \ + ((v)->vcpu_id >> PAGETABLE_ORDER) + +#define pv_shadow_root_pt_pte(v) \ + ((v)->domain->arch.pv.shadow_root_pt_l1tab[shadow_root_pt_idx(v)] + \ + ((v)->vcpu_id & (L1_PAGETABLE_ENTRIES - 1))) + void make_cr3(struct vcpu *v, mfn_t mfn) { struct domain *d =3D v->domain; @@ -524,6 +531,13 @@ void write_ptbase(struct vcpu *v) =20 if ( is_pv_vcpu(v) && v->domain->arch.pv.xpti ) { + mfn_t guest_root_pt =3D _mfn(v->arch.cr3 >> PAGE_SHIFT); + l1_pgentry_t *pte =3D pv_shadow_root_pt_pte(v); + + ASSERT(v =3D=3D current); + + l1e_write(pte, l1e_from_mfn(guest_root_pt, __PAGE_HYPERVISOR_RW)); + cpu_info->root_pgt_changed =3D true; cpu_info->pv_cr3 =3D __pa(this_cpu(root_pgt)); if ( new_cr4 & X86_CR4_PCIDE ) diff --git a/xen/arch/x86/pv/domain.c b/xen/arch/x86/pv/domain.c index 2a445bb17b..fef9ae2352 100644 --- a/xen/arch/x86/pv/domain.c +++ b/xen/arch/x86/pv/domain.c @@ -288,6 +288,19 @@ static void pv_destroy_gdt_ldt_l1tab(struct vcpu *v) 1U << GDT_LDT_VCPU_SHIFT); } =20 +static int pv_create_shadow_root_pt_l1tab(struct vcpu *v) +{ + return create_perdomain_mapping(v->domain, SHADOW_ROOT_PT_VCPU_VIRT_ST= ART(v), + 1, v->domain->arch.pv.shadow_root_pt_l= 1tab, + NULL); +} + +static void pv_destroy_shadow_root_pt_l1tab(struct vcpu *v) + +{ + destroy_perdomain_mapping(v->domain, SHADOW_ROOT_PT_VCPU_VIRT_START(v)= , 1); +} + void pv_vcpu_destroy(struct vcpu *v) { if ( is_pv_32bit_vcpu(v) ) @@ -297,6 +310,7 @@ void pv_vcpu_destroy(struct vcpu *v) } =20 pv_destroy_gdt_ldt_l1tab(v); + pv_destroy_shadow_root_pt_l1tab(v); XFREE(v->arch.pv.trap_ctxt); } =20 @@ -311,6 +325,13 @@ int pv_vcpu_initialise(struct vcpu *v) if ( rc ) return rc; =20 + if ( v->domain->arch.pv.xpti ) + { + rc =3D pv_create_shadow_root_pt_l1tab(v); + if ( rc ) + goto done; + } + BUILD_BUG_ON(X86_NR_VECTORS * sizeof(*v->arch.pv.trap_ctxt) > PAGE_SIZE); v->arch.pv.trap_ctxt =3D xzalloc_array(struct trap_info, X86_NR_VECTOR= S); @@ -346,10 +367,12 @@ void pv_domain_destroy(struct domain *d) =20 destroy_perdomain_mapping(d, GDT_LDT_VIRT_START, GDT_LDT_MBYTES << (20 - PAGE_SHIFT)); + destroy_perdomain_mapping(d, SHADOW_ROOT_PT_VIRT_START, SHADOW_ROOT_PT= _ENTRIES); =20 XFREE(d->arch.pv.cpuidmasks); =20 FREE_XENHEAP_PAGE(d->arch.pv.gdt_ldt_l1tab); + FREE_XENHEAP_PAGE(d->arch.pv.shadow_root_pt_l1tab); } =20 void noreturn cf_check continue_pv_domain(void); @@ -371,6 +394,12 @@ int pv_domain_initialise(struct domain *d) goto fail; clear_page(d->arch.pv.gdt_ldt_l1tab); =20 + d->arch.pv.shadow_root_pt_l1tab =3D + alloc_xenheap_pages(0, MEMF_node(domain_to_node(d))); + if ( !d->arch.pv.shadow_root_pt_l1tab ) + goto fail; + clear_page(d->arch.pv.shadow_root_pt_l1tab); + if ( levelling_caps & ~LCAP_faulting && (d->arch.pv.cpuidmasks =3D xmemdup(&cpuidmask_defaults)) =3D=3D N= ULL ) goto fail; @@ -381,6 +410,11 @@ int pv_domain_initialise(struct domain *d) if ( rc ) goto fail; =20 + rc =3D create_perdomain_mapping(d, SHADOW_ROOT_PT_VIRT_START, + SHADOW_ROOT_PT_ENTRIES, NULL, NULL); + if ( rc ) + goto fail; + d->arch.ctxt_switch =3D &pv_csw; =20 d->arch.pv.xpti =3D is_hardware_domain(d) ? opt_xpti_hwdom : opt_xpti_= domu; diff --git a/xen/arch/x86/x86_64/asm-offsets.c b/xen/arch/x86/x86_64/asm-of= fsets.c index 57b73a4e62..23f9cca1a2 100644 --- a/xen/arch/x86/x86_64/asm-offsets.c +++ b/xen/arch/x86/x86_64/asm-offsets.c @@ -51,6 +51,7 @@ void __dummy__(void) OFFSET(UREGS_kernel_sizeof, struct cpu_user_regs, es); BLANK(); =20 + OFFSET(VCPU_id, struct vcpu, vcpu_id); OFFSET(VCPU_processor, struct vcpu, processor); OFFSET(VCPU_domain, struct vcpu, domain); OFFSET(VCPU_vcpu_info, struct vcpu, vcpu_info_area.map); diff --git a/xen/arch/x86/x86_64/entry.S b/xen/arch/x86/x86_64/entry.S index c25b14dde6..a216c5ca7a 100644 --- a/xen/arch/x86/x86_64/entry.S +++ b/xen/arch/x86/x86_64/entry.S @@ -165,7 +165,15 @@ restore_all_guest: and %rsi, %rdi and %r9, %rsi add %rcx, %rdi + + /* + * The address in the vCPU cr3 is always mapped in the shadow + * root_pt virt area. + */ + imul $PAGE_SIZE, VCPU_id(%rbx), %esi + movabs $SHADOW_ROOT_PT_VIRT_START, %rcx add %rcx, %rsi + mov $ROOT_PAGETABLE_FIRST_XEN_SLOT, %ecx mov root_table_offset(SH_LINEAR_PT_VIRT_START)*8(%rsi), %r8 mov %r8, root_table_offset(SH_LINEAR_PT_VIRT_START)*8(%rdi) --=20 2.40.1 From nobody Thu May 9 13:57:19 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=1705433227; cv=none; d=zohomail.com; s=zohoarc; b=mI9AOqwiHxnRjZs3CHrfgI96L24SSSbHeVELLRPpZS72l1F5BCmGIpmlIrT0HPLo9jY+ImKLHFXsM8DZJwfUKQ0avz/UlO5rWMgfE1PE76ggMxc+5XBajSCyOZfIZGmsvEMzVNpHEMopWOIzpinTqUVRGPZ72ETYbRx02QAD2n8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705433227; 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=HW3epajLPcDlyqLezVIUXLccUhl0qCm2Of6jKKbyr0s=; b=gAD+NWoJbz3SjdrLx16UV1jlpEZCqX6lzli1fFiBVdSt5ixFrwcaOcoRHaJ+Rptu845U5YGngV6NMlhldvPrzXhcx7c4TIR7PpChNUsFo4H37fjrh+9mp1ZLdE1MqR4BA56LqBsmUG7Dn9mh3YBqnKOFVS7lDi2wTpuHPojJZm4= 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 1705433227308858.6457005037771; Tue, 16 Jan 2024 11:27:07 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.668089.1040054 (Exim 4.92) (envelope-from ) id 1rPp58-0005WS-2b; Tue, 16 Jan 2024 19:26:42 +0000 Received: by outflank-mailman (output) from mailman id 668089.1040054; Tue, 16 Jan 2024 19:26: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 1rPp57-0005VB-FP; Tue, 16 Jan 2024 19:26:41 +0000 Received: by outflank-mailman (input) for mailman id 668089; Tue, 16 Jan 2024 19:26:38 +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 1rPp54-0003Xv-Q0 for xen-devel@lists.xenproject.org; Tue, 16 Jan 2024 19:26:38 +0000 Received: from smtp-fw-80007.amazon.com (smtp-fw-80007.amazon.com [99.78.197.218]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 29e101c5-b4a5-11ee-98f1-6d05b1d4d9a1; Tue, 16 Jan 2024 20:26:36 +0100 (CET) Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO email-inbound-relay-pdx-1box-2bm6-32cf6363.us-west-2.amazon.com) ([10.25.36.210]) by smtp-border-fw-80007.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jan 2024 19:26:29 +0000 Received: from smtpout.prod.us-east-1.prod.farcaster.email.amazon.dev (pdx2-ws-svc-p26-lb5-vlan2.pdx.amazon.com [10.39.38.66]) by email-inbound-relay-pdx-1box-2bm6-32cf6363.us-west-2.amazon.com (Postfix) with ESMTPS id 7F1A189830; Tue, 16 Jan 2024 19:26:27 +0000 (UTC) Received: from EX19MTAUEA002.ant.amazon.com [10.0.29.78:2178] by smtpin.naws.us-east-1.prod.farcaster.email.amazon.dev [10.0.41.129:2525] with esmtp (Farcaster) id 237a9be2-b0f0-4c18-9e6f-15d1094f032e; Tue, 16 Jan 2024 19:26:27 +0000 (UTC) Received: from EX19D008UEA003.ant.amazon.com (10.252.134.116) 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.1118.40; Tue, 16 Jan 2024 19:26:26 +0000 Received: from EX19MTAUEB001.ant.amazon.com (10.252.135.35) by EX19D008UEA003.ant.amazon.com (10.252.134.116) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 16 Jan 2024 19:26:25 +0000 Received: from dev-dsk-eliasely-1a-fd74790f.eu-west-1.amazon.com (10.253.91.118) by mail-relay.amazon.com (10.252.135.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40 via Frontend Transport; Tue, 16 Jan 2024 19:26:24 +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 Sender: "Xen-devel" X-Inumbo-ID: 29e101c5-b4a5-11ee-98f1-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1705433197; x=1736969197; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=HW3epajLPcDlyqLezVIUXLccUhl0qCm2Of6jKKbyr0s=; b=oT63VgqdP8RB9MV/v+qQj7NhNnEVPfwzkA1YBpQ9atnYMlRRsfEsK8Br Y0yjX4KoB5hsiVZLX37SKWQ5b/gDbfBFlmNuqhwMS1xV1zJq+Q6U3FD8T jNBdgMIoSj/FNi9IDuV1iHOqdcVpgT6L5i97032MbEJibJXlGzcOpmM2n 8=; X-IronPort-AV: E=Sophos;i="6.05,200,1701129600"; d="scan'208";a="267191230" X-Farcaster-Flow-ID: 237a9be2-b0f0-4c18-9e6f-15d1094f032e From: Elias El Yandouzi To: CC: , , , Wei Liu , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , Wei Wang , Julien Grall , Elias El Yandouzi Subject: [PATCH v2 (resend) 08/27] x86/pv: Domheap pages should be mapped while relocating initrd Date: Tue, 16 Jan 2024 19:25:52 +0000 Message-ID: <20240116192611.41112-9-eliasely@amazon.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240116192611.41112-1-eliasely@amazon.com> References: <20240116192611.41112-1-eliasely@amazon.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: Bulk X-ZohoMail-DKIM: pass (identity @amazon.com) X-ZM-MESSAGEID: 1705433227864100001 Content-Type: text/plain; charset="utf-8" From: Wei Liu Xen shouldn't use domheap page as if they were xenheap pages. Map and unmap pages accordingly. Signed-off-by: Wei Liu Signed-off-by: Wei Wang Signed-off-by: Julien Grall Signed-off-by: Elias El Yandouzi ---- Changes in V2: * Get rid of mfn_to_virt * Don't open code copy_domain_page() Changes since Hongyan's version: * Add missing newline after the variable declaration diff --git a/xen/arch/x86/pv/dom0_build.c b/xen/arch/x86/pv/dom0_build.c index 5bbed3a36a..5659814e0c 100644 --- a/xen/arch/x86/pv/dom0_build.c +++ b/xen/arch/x86/pv/dom0_build.c @@ -615,18 +615,25 @@ int __init dom0_construct_pv(struct domain *d, if ( d->arch.physaddr_bitsize && ((mfn + count - 1) >> (d->arch.physaddr_bitsize - PAGE_SHIFT)= ) ) { + unsigned long nr_pages; + order =3D get_order_from_pages(count); page =3D alloc_domheap_pages(d, order, MEMF_no_scrub); if ( !page ) panic("Not enough RAM for domain 0 initrd\n"); + + nr_pages =3D 1UL << order; for ( count =3D -count; order--; ) if ( count & (1UL << order) ) { free_domheap_pages(page, order); page +=3D 1UL << order; + nr_pages -=3D 1UL << order; } - memcpy(page_to_virt(page), mfn_to_virt(initrd->mod_start), - initrd_len); + + for ( i =3D 0; i < nr_pages; i++ ) + copy_domain_page(page_to_mfn(page + i), _mfn(initrd_mfn + = i)); + mpt_alloc =3D (paddr_t)initrd->mod_start << PAGE_SHIFT; init_domheap_pages(mpt_alloc, mpt_alloc + PAGE_ALIGN(initrd_len)); --=20 2.40.1 From nobody Thu May 9 13:57:19 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=1705433219; cv=none; d=zohomail.com; s=zohoarc; b=Lh5kS9LFJ5uDYGg6Xq6wbwP1pK51KdJrvNNCLYP6/YDXbyrQi7m54fA2P7oYi3SPyRbyJY6QlRdRuyvuv4ZA5qOTnb3yXSFrc1irWImTXW7yYzWpaqSMs/jCEYjL2qU5TcHh5fB9qPEAgkfu8r4Q4nkxuGcXNYqnA5sGfWqW500= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705433219; 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=DFq2dA1Yv5iX6XPtrbHhlSvMP8eVQGNEuxktAlGi9eU=; b=K8LA88hb+g+BEeo5nQ4jkgfjWKM39d+t6cIwx0v+yHhlmlbUCO2b2iolvxLewN1yMzbplaDnBlzL1eIPmKjKbRhNEdv0R/CRS0RztghEEorandQCM/jzCz6Emwnq7Khc8jTWBXT7/wBv4QUseuqXWG3p3qmULOdotnijdEFuwB4= 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 1705433219833333.95871684684346; Tue, 16 Jan 2024 11:26:59 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.668087.1040040 (Exim 4.92) (envelope-from ) id 1rPp56-0005Gp-Bj; Tue, 16 Jan 2024 19:26:40 +0000 Received: by outflank-mailman (output) from mailman id 668087.1040040; Tue, 16 Jan 2024 19:26:40 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rPp56-0005Fp-0O; Tue, 16 Jan 2024 19:26:40 +0000 Received: by outflank-mailman (input) for mailman id 668087; Tue, 16 Jan 2024 19:26:37 +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 1rPp53-0003Xv-Py for xen-devel@lists.xenproject.org; Tue, 16 Jan 2024 19:26:37 +0000 Received: from smtp-fw-80006.amazon.com (smtp-fw-80006.amazon.com [99.78.197.217]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 29504aca-b4a5-11ee-98f1-6d05b1d4d9a1; Tue, 16 Jan 2024 20:26:35 +0100 (CET) Received: from pdx4-co-svc-p1-lb2-vlan3.amazon.com (HELO email-inbound-relay-iad-1d-m6i4x-d8e96288.us-east-1.amazon.com) ([10.25.36.214]) by smtp-border-fw-80006.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jan 2024 19:26:34 +0000 Received: from smtpout.prod.us-east-1.prod.farcaster.email.amazon.dev (iad7-ws-svc-p70-lb3-vlan3.iad.amazon.com [10.32.235.38]) by email-inbound-relay-iad-1d-m6i4x-d8e96288.us-east-1.amazon.com (Postfix) with ESMTPS id 0B9FF84687; Tue, 16 Jan 2024 19:26:32 +0000 (UTC) Received: from EX19MTAUEA001.ant.amazon.com [10.0.29.78:62111] by smtpin.naws.us-east-1.prod.farcaster.email.amazon.dev [10.0.3.20:2525] with esmtp (Farcaster) id 846161f4-2e4f-42ab-89d6-60167c58a568; Tue, 16 Jan 2024 19:26:31 +0000 (UTC) Received: from EX19D008UEA003.ant.amazon.com (10.252.134.116) by EX19MTAUEA001.ant.amazon.com (10.252.134.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 16 Jan 2024 19:26:27 +0000 Received: from EX19MTAUEB001.ant.amazon.com (10.252.135.35) by EX19D008UEA003.ant.amazon.com (10.252.134.116) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 16 Jan 2024 19:26:26 +0000 Received: from dev-dsk-eliasely-1a-fd74790f.eu-west-1.amazon.com (10.253.91.118) by mail-relay.amazon.com (10.252.135.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40 via Frontend Transport; Tue, 16 Jan 2024 19:26:26 +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 Sender: "Xen-devel" X-Inumbo-ID: 29504aca-b4a5-11ee-98f1-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1705433196; x=1736969196; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=DFq2dA1Yv5iX6XPtrbHhlSvMP8eVQGNEuxktAlGi9eU=; b=dMwbuIaji5I2hq6UW4g9jr9Y71QHDR4pjajcOe7nHtWjOFy+1+LQuIe/ TkZ1dXIBmxjcWuL9HLHPW5PreWekHUNVbqiJsnd7FYta6U7nrowdYg+zP Rf33//GMW6ojHtHHLOG08zpoZjUkqP/R60fbfQTpWf9ECsbiaaFQiwXnJ E=; X-IronPort-AV: E=Sophos;i="6.05,200,1701129600"; d="scan'208";a="266414258" X-Farcaster-Flow-ID: 846161f4-2e4f-42ab-89d6-60167c58a568 From: Elias El Yandouzi To: CC: , , , Hongyan Xia , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , Julien Grall , Elias El Yandouzi Subject: [PATCH v2 (resend) 09/27] x86/pv: Rewrite how building PV dom0 handles domheap mappings Date: Tue, 16 Jan 2024 19:25:53 +0000 Message-ID: <20240116192611.41112-10-eliasely@amazon.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240116192611.41112-1-eliasely@amazon.com> References: <20240116192611.41112-1-eliasely@amazon.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: Bulk X-ZohoMail-DKIM: pass (identity @amazon.com) X-ZM-MESSAGEID: 1705433221847100002 Content-Type: text/plain; charset="utf-8" From: Hongyan Xia Building a PV dom0 is allocating from the domheap but uses it like the xenheap. Use the pages as they should be. Signed-off-by: Hongyan Xia Signed-off-by: Julien Grall Signed-off-by: Elias El Yandouzi ---- Changes in V2: * Clarify the commit message * Break the patch in two parts Changes since Hongyan's version: * Rebase * Remove spurious newline diff --git a/xen/arch/x86/pv/dom0_build.c b/xen/arch/x86/pv/dom0_build.c index 5659814e0c..dc5e9fe117 100644 --- a/xen/arch/x86/pv/dom0_build.c +++ b/xen/arch/x86/pv/dom0_build.c @@ -382,6 +382,10 @@ int __init dom0_construct_pv(struct domain *d, l3_pgentry_t *l3tab =3D NULL, *l3start =3D NULL; l2_pgentry_t *l2tab =3D NULL, *l2start =3D NULL; l1_pgentry_t *l1tab =3D NULL, *l1start =3D NULL; + mfn_t l4start_mfn =3D INVALID_MFN; + mfn_t l3start_mfn =3D INVALID_MFN; + mfn_t l2start_mfn =3D INVALID_MFN; + mfn_t l1start_mfn =3D INVALID_MFN; =20 /* * This fully describes the memory layout of the initial domain. All @@ -708,22 +712,32 @@ int __init dom0_construct_pv(struct domain *d, v->arch.pv.event_callback_cs =3D FLAT_COMPAT_KERNEL_CS; } =20 +#define UNMAP_MAP_AND_ADVANCE(mfn_var, virt_var, maddr) \ +do { \ + unmap_domain_page(virt_var); \ + mfn_var =3D maddr_to_mfn(maddr); \ + maddr +=3D PAGE_SIZE; \ + virt_var =3D map_domain_page(mfn_var); \ +} while ( false ) + if ( !compat ) { maddr_to_page(mpt_alloc)->u.inuse.type_info =3D PGT_l4_page_table; - l4start =3D l4tab =3D __va(mpt_alloc); mpt_alloc +=3D PAGE_SIZE; + UNMAP_MAP_AND_ADVANCE(l4start_mfn, l4start, mpt_alloc); + l4tab =3D l4start; clear_page(l4tab); - init_xen_l4_slots(l4tab, _mfn(virt_to_mfn(l4start)), - d, INVALID_MFN, true); - v->arch.guest_table =3D pagetable_from_paddr(__pa(l4start)); + init_xen_l4_slots(l4tab, l4start_mfn, d, INVALID_MFN, true); + v->arch.guest_table =3D pagetable_from_mfn(l4start_mfn); } else { /* Monitor table already created by switch_compat(). */ - l4start =3D l4tab =3D __va(pagetable_get_paddr(v->arch.guest_table= )); + l4start_mfn =3D pagetable_get_mfn(v->arch.guest_table); + l4start =3D l4tab =3D map_domain_page(l4start_mfn); /* See public/xen.h on why the following is needed. */ maddr_to_page(mpt_alloc)->u.inuse.type_info =3D PGT_l3_page_table; l3start =3D __va(mpt_alloc); mpt_alloc +=3D PAGE_SIZE; + UNMAP_MAP_AND_ADVANCE(l3start_mfn, l3start, mpt_alloc); } =20 l4tab +=3D l4_table_offset(v_start); @@ -733,14 +747,16 @@ int __init dom0_construct_pv(struct domain *d, if ( !((unsigned long)l1tab & (PAGE_SIZE-1)) ) { maddr_to_page(mpt_alloc)->u.inuse.type_info =3D PGT_l1_page_ta= ble; - l1start =3D l1tab =3D __va(mpt_alloc); mpt_alloc +=3D PAGE_SIZ= E; + UNMAP_MAP_AND_ADVANCE(l1start_mfn, l1start, mpt_alloc); + l1tab =3D l1start; clear_page(l1tab); if ( count =3D=3D 0 ) l1tab +=3D l1_table_offset(v_start); if ( !((unsigned long)l2tab & (PAGE_SIZE-1)) ) { maddr_to_page(mpt_alloc)->u.inuse.type_info =3D PGT_l2_pag= e_table; - l2start =3D l2tab =3D __va(mpt_alloc); mpt_alloc +=3D PAGE= _SIZE; + UNMAP_MAP_AND_ADVANCE(l2start_mfn, l2start, mpt_alloc); + l2tab =3D l2start; clear_page(l2tab); if ( count =3D=3D 0 ) l2tab +=3D l2_table_offset(v_start); @@ -750,19 +766,19 @@ int __init dom0_construct_pv(struct domain *d, { maddr_to_page(mpt_alloc)->u.inuse.type_info =3D PGT_l3_page_table; - l3start =3D __va(mpt_alloc); mpt_alloc +=3D PAGE_S= IZE; + UNMAP_MAP_AND_ADVANCE(l3start_mfn, l3start, mpt_al= loc); } l3tab =3D l3start; clear_page(l3tab); if ( count =3D=3D 0 ) l3tab +=3D l3_table_offset(v_start); - *l4tab =3D l4e_from_paddr(__pa(l3start), L4_PROT); + *l4tab =3D l4e_from_mfn(l3start_mfn, L4_PROT); l4tab++; } - *l3tab =3D l3e_from_paddr(__pa(l2start), L3_PROT); + *l3tab =3D l3e_from_mfn(l2start_mfn, L3_PROT); l3tab++; } - *l2tab =3D l2e_from_paddr(__pa(l1start), L2_PROT); + *l2tab =3D l2e_from_mfn(l1start_mfn, L2_PROT); l2tab++; } if ( count < initrd_pfn || count >=3D initrd_pfn + PFN_UP(initrd_l= en) ) @@ -781,30 +797,34 @@ int __init dom0_construct_pv(struct domain *d, =20 if ( compat ) { - l2_pgentry_t *l2t; - /* Ensure the first four L3 entries are all populated. */ for ( i =3D 0, l3tab =3D l3start; i < 4; ++i, ++l3tab ) { if ( !l3e_get_intpte(*l3tab) ) { maddr_to_page(mpt_alloc)->u.inuse.type_info =3D PGT_l2_pag= e_table; - l2tab =3D __va(mpt_alloc); mpt_alloc +=3D PAGE_SIZE; - clear_page(l2tab); - *l3tab =3D l3e_from_paddr(__pa(l2tab), L3_PROT); + UNMAP_MAP_AND_ADVANCE(l2start_mfn, l2start, mpt_alloc); + clear_page(l2start); + *l3tab =3D l3e_from_mfn(l2start_mfn, L3_PROT); } if ( i =3D=3D 3 ) l3e_get_page(*l3tab)->u.inuse.type_info |=3D PGT_pae_xen_l= 2; } =20 - l2t =3D map_l2t_from_l3e(l3start[3]); - init_xen_pae_l2_slots(l2t, d); - unmap_domain_page(l2t); + init_xen_pae_l2_slots(l2start, d); } =20 +#undef UNMAP_MAP_AND_ADVANCE + + UNMAP_DOMAIN_PAGE(l1start); + UNMAP_DOMAIN_PAGE(l2start); + UNMAP_DOMAIN_PAGE(l3start); + /* Pages that are part of page tables must be read only. */ mark_pv_pt_pages_rdonly(d, l4start, vpt_start, nr_pt_pages, &flush_fla= gs); =20 + UNMAP_DOMAIN_PAGE(l4start); + /* Mask all upcalls... */ for ( i =3D 0; i < XEN_LEGACY_MAX_VCPUS; i++ ) shared_info(d, vcpu_info[i].evtchn_upcall_mask) =3D 1; --=20 2.40.1 From nobody Thu May 9 13:57:19 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=1705433212; cv=none; d=zohomail.com; s=zohoarc; b=eVml7Q4/tYkePZDHWrEozlq1//rbUoTFQVQ4nMY90uDlO8X2XV2xr51HYIDGd/NMu6sthBzryaDPWG+d6o0vKKF35MGuOJJZcuvdBYt+gSi3yQIJwT4k+xxm/Af46HfkUrkcWAMpqWgfodLFQOh/kviULVVnDJojtZ5yB2uZVoE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705433212; 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=fLyAFvpkS62mZ58f/yx9ju+/jVeXxTTvsO8RqlfEYZw=; b=XBRH93Y5hU8lNa5pRYxyGFDZ8fgCalDEZjyN9eFNzBU99O+iAQagVQ1d5IbjsyxNlQ0tjfmkfy7zEq2fK0cXcNrX4eTQqMdzvTgBVlS7LYncZjomw9jT/7ZPUV2jXr5Rc/hZqpOuiVwtnkU7ODMOXffhD2MHIzlh9XW1AtmErzQ= 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 1705433212759530.1147610541245; Tue, 16 Jan 2024 11:26:52 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.668082.1039997 (Exim 4.92) (envelope-from ) id 1rPp51-0003w6-9E; Tue, 16 Jan 2024 19:26:35 +0000 Received: by outflank-mailman (output) from mailman id 668082.1039997; Tue, 16 Jan 2024 19:26:35 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rPp51-0003vB-3K; Tue, 16 Jan 2024 19:26:35 +0000 Received: by outflank-mailman (input) for mailman id 668082; Tue, 16 Jan 2024 19:26:34 +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 1rPp50-0003Xv-B2 for xen-devel@lists.xenproject.org; Tue, 16 Jan 2024 19:26:34 +0000 Received: from smtp-fw-52005.amazon.com (smtp-fw-52005.amazon.com [52.119.213.156]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 27f17ebe-b4a5-11ee-98f1-6d05b1d4d9a1; Tue, 16 Jan 2024 20:26:33 +0100 (CET) Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-iad-1a-m6i4x-edda28d4.us-east-1.amazon.com) ([10.43.8.6]) by smtp-border-fw-52005.iad7.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jan 2024 19:26:32 +0000 Received: from smtpout.prod.us-east-1.prod.farcaster.email.amazon.dev (iad7-ws-svc-p70-lb3-vlan3.iad.amazon.com [10.32.235.38]) by email-inbound-relay-iad-1a-m6i4x-edda28d4.us-east-1.amazon.com (Postfix) with ESMTPS id E945E8054B; Tue, 16 Jan 2024 19:26:30 +0000 (UTC) Received: from EX19MTAUEC002.ant.amazon.com [10.0.0.204:41793] by smtpin.naws.us-east-1.prod.farcaster.email.amazon.dev [10.0.95.118:2525] with esmtp (Farcaster) id 0048df5a-a8a5-4bf0-b47e-14349dd2b900; Tue, 16 Jan 2024 19:26:30 +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_256_GCM_SHA384) id 15.2.1118.40; Tue, 16 Jan 2024 19:26:28 +0000 Received: from EX19MTAUEB001.ant.amazon.com (10.252.135.35) by EX19D008UEA004.ant.amazon.com (10.252.134.191) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 16 Jan 2024 19:26:28 +0000 Received: from dev-dsk-eliasely-1a-fd74790f.eu-west-1.amazon.com (10.253.91.118) by mail-relay.amazon.com (10.252.135.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40 via Frontend Transport; Tue, 16 Jan 2024 19:26:27 +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 Sender: "Xen-devel" X-Inumbo-ID: 27f17ebe-b4a5-11ee-98f1-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1705433193; x=1736969193; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fLyAFvpkS62mZ58f/yx9ju+/jVeXxTTvsO8RqlfEYZw=; b=O3Ir0SQYYqAaDqPjAZqr0BkVPlOZ7kl8wt79mIBfXuxBwmnYALJO7DFt JUz4AkNkoCpYcnDNDXPxh0FtSPIkVn9B2gc3LzfjLYo5Y6Haj1fxQhph6 xadChpELoWUpo1JVJFwGZHmpzu+6hwdv0BOJCGAASWdGhI7dUrKRuY850 E=; X-IronPort-AV: E=Sophos;i="6.05,200,1701129600"; d="scan'208";a="627983561" X-Farcaster-Flow-ID: 0048df5a-a8a5-4bf0-b47e-14349dd2b900 From: Elias El Yandouzi To: CC: , , , Hongyan Xia , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , Elias El Yandouzi Subject: [PATCH v2 (resend) 10/27] x86/pv: Map L4 page table for shim domain Date: Tue, 16 Jan 2024 19:25:54 +0000 Message-ID: <20240116192611.41112-11-eliasely@amazon.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240116192611.41112-1-eliasely@amazon.com> References: <20240116192611.41112-1-eliasely@amazon.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: Bulk X-ZohoMail-DKIM: pass (identity @amazon.com) X-ZM-MESSAGEID: 1705433213826100001 Content-Type: text/plain; charset="utf-8" From: Hongyan Xia The root page table is allocated from the domheap and isn't mapped by default. Map it on demand to build pv shim domain. Signed-off-by: Hongyan Xia Signed-off-by: Elias El Yandouzi Reviewed-by: Jan Beulich ---- Changes in v2: * New patch diff --git a/xen/arch/x86/pv/dom0_build.c b/xen/arch/x86/pv/dom0_build.c index dc5e9fe117..fc51c7d362 100644 --- a/xen/arch/x86/pv/dom0_build.c +++ b/xen/arch/x86/pv/dom0_build.c @@ -991,8 +991,12 @@ do { = \ * !CONFIG_VIDEO case so the logic here can be simplified. */ if ( pv_shim ) + { + l4start =3D map_domain_page(l4start_mfn); pv_shim_setup_dom(d, l4start, v_start, vxenstore_start, vconsole_s= tart, vphysmap_start, si); + UNMAP_DOMAIN_PAGE(l4start); + } =20 #ifdef CONFIG_COMPAT if ( compat ) --=20 2.40.1 From nobody Thu May 9 13:57:19 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=1705433220; cv=none; d=zohomail.com; s=zohoarc; b=ILhSC3qGHf/99sxk/MPKouyleZ6an08LcIjyQYx5mPzR5MNIOvZzq+JwF1s2bCCtjMC4+sxxMXE/jz1ROG2Vgpk0kLxxuQYTaTe4bhHFz9PLVibDhEjXxFY6fTgZoLHNPm8YN6oPKcr6bCLVtfvWE2zUoGWL+j4EIB3d2diNXMQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705433220; 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=Dpcwsrxvbe9T9hoTCd3fMKYWwbTAEp7kfzrhfuwZSAw=; b=TWC+8P3W6EggGeyrmSejEO9ECMYiN8Gf0PpSAWpu4MSl4L1dtbk/x3lM0cW8csprHvClYu4A9fBq4EdKQYGITm6hIkb4RvP37F1DnvX7Lk+2iVc906ZNnj0ZqgDgBlwVXJbxmsal4IDuVUB6U62L4k1T1zr20NnO6jrP0y3aJtk= 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 1705433220727775.4377565048313; Tue, 16 Jan 2024 11:27:00 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.668088.1040046 (Exim 4.92) (envelope-from ) id 1rPp57-0005No-3f; Tue, 16 Jan 2024 19:26:41 +0000 Received: by outflank-mailman (output) from mailman id 668088.1040046; Tue, 16 Jan 2024 19:26: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 1rPp56-0005MW-Nv; Tue, 16 Jan 2024 19:26:40 +0000 Received: by outflank-mailman (input) for mailman id 668088; Tue, 16 Jan 2024 19:26:38 +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 1rPp54-0002iI-7M for xen-devel@lists.xenproject.org; Tue, 16 Jan 2024 19:26:38 +0000 Received: from smtp-fw-80009.amazon.com (smtp-fw-80009.amazon.com [99.78.197.220]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 291ce992-b4a5-11ee-9b0f-b553b5be7939; Tue, 16 Jan 2024 20:26:36 +0100 (CET) Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO email-inbound-relay-pdx-2b-m6i4x-cadc3fbd.us-west-2.amazon.com) ([10.25.36.210]) by smtp-border-fw-80009.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jan 2024 19:26:34 +0000 Received: from smtpout.prod.us-east-1.prod.farcaster.email.amazon.dev (pdx2-ws-svc-p26-lb5-vlan2.pdx.amazon.com [10.39.38.66]) by email-inbound-relay-pdx-2b-m6i4x-cadc3fbd.us-west-2.amazon.com (Postfix) with ESMTPS id DA6CEA0786; Tue, 16 Jan 2024 19:26:33 +0000 (UTC) Received: from EX19MTAUEC001.ant.amazon.com [10.0.0.204:53301] by smtpin.naws.us-east-1.prod.farcaster.email.amazon.dev [10.0.15.248:2525] with esmtp (Farcaster) id c4ea0858-a181-498a-b9e5-5a7364e4b9d8; Tue, 16 Jan 2024 19:26:33 +0000 (UTC) Received: from EX19D008UEA004.ant.amazon.com (10.252.134.191) by EX19MTAUEC001.ant.amazon.com (10.252.135.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 16 Jan 2024 19:26:29 +0000 Received: from EX19MTAUEB001.ant.amazon.com (10.252.135.35) by EX19D008UEA004.ant.amazon.com (10.252.134.191) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 16 Jan 2024 19:26:29 +0000 Received: from dev-dsk-eliasely-1a-fd74790f.eu-west-1.amazon.com (10.253.91.118) by mail-relay.amazon.com (10.252.135.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40 via Frontend Transport; Tue, 16 Jan 2024 19:26:28 +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 Sender: "Xen-devel" X-Inumbo-ID: 291ce992-b4a5-11ee-9b0f-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1705433196; x=1736969196; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Dpcwsrxvbe9T9hoTCd3fMKYWwbTAEp7kfzrhfuwZSAw=; b=HrUtGVMS8rkpFHNHM+OEnP8idThelxNKdXx+SpQg9rpAwjr5YOVFJ/H0 cfyUx36ZyaqUwEO2CqONPOWNiaplyzg+EiopIy8ruHuskOVo9wA3K+ACP zypbvy5+jTrjiScFRupNH+HATWavRsFl3iYAm8GVWxAlH+qcr0FtCps8o 0=; X-IronPort-AV: E=Sophos;i="6.05,200,1701129600"; d="scan'208";a="58701489" X-Farcaster-Flow-ID: c4ea0858-a181-498a-b9e5-5a7364e4b9d8 From: Elias El Yandouzi To: CC: , , , Wei Liu , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , Wei Wang , Hongyan Xia , Julien Grall Subject: [PATCH v2 (resend) 11/27] x86: Lift mapcache variable to the arch level Date: Tue, 16 Jan 2024 19:25:55 +0000 Message-ID: <20240116192611.41112-12-eliasely@amazon.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240116192611.41112-1-eliasely@amazon.com> References: <20240116192611.41112-1-eliasely@amazon.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: Bulk X-ZohoMail-DKIM: pass (identity @amazon.com) X-ZM-MESSAGEID: 1705433221839100001 Content-Type: text/plain; charset="utf-8" From: Wei Liu It is going to be needed by HVM and idle domain as well, because without the direct map, both need a mapcache to map pages. This only lifts the mapcache variable up. Whether we populate the mapcache for a domain is unchanged in this patch. Signed-off-by: Wei Liu Signed-off-by: Wei Wang Signed-off-by: Hongyan Xia Signed-off-by: Julien Grall diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index 8a31d18f69..8ef3f7746f 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -843,6 +843,8 @@ int arch_domain_create(struct domain *d, =20 psr_domain_init(d); =20 + mapcache_domain_init(d); + if ( is_hvm_domain(d) ) { if ( (rc =3D hvm_domain_initialise(d, config)) !=3D 0 ) @@ -850,8 +852,6 @@ int arch_domain_create(struct domain *d, } else if ( is_pv_domain(d) ) { - mapcache_domain_init(d); - if ( (rc =3D pv_domain_initialise(d)) !=3D 0 ) goto fail; } diff --git a/xen/arch/x86/domain_page.c b/xen/arch/x86/domain_page.c index eac5e3304f..55e337aaf7 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 4d97c68028..85b890b2cb 100644 --- a/xen/arch/x86/include/asm/domain.h +++ b/xen/arch/x86/include/asm/domain.h @@ -286,9 +286,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 @@ -327,6 +324,9 @@ struct arch_domain =20 uint8_t spec_ctrl_flags; /* See SCF_DOM_MASK */ =20 + /* map_domain_page() mapping cache. */ + struct mapcache_domain mapcache; + union { struct pv_domain pv; struct hvm_domain hvm; @@ -517,9 +517,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; @@ -619,6 +616,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; --=20 2.40.1 From nobody Thu May 9 13:57:19 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=1705433222; cv=none; d=zohomail.com; s=zohoarc; b=mDa75/fjAK+vTfFWwVmR8IJ1JCFxWLOviskBWeA9AnzYAGWFRvvYHR71RdAz0A/teDihsZfOKv3pbfNERHwNes7DeipL/CRx2v/xMWyFQ0urqexa/gnIDpfIRvTKz1QJ+cEanLoEXVF9R5Good1FDgseNNquovzgo+v7oCIJmpY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705433222; 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=sWVxwHwgKXZxnYvHw7QOCApWITjaKrfn/x6fPGCt35k=; b=n8n34KRT1krL8MhJA+fQsl7fB0xnJnvKf4qirAix3al23BYm7M+aqfRi2r+Au1AVAzmTW0s1pzZt7ZPdvgVV1SYFNwlMQSZl3BqFV7ldlS/j6SWsJdyGwCQBDxRyr9UFrTK3b5vdT2ZZvt5JnpvuUQ5vDwk0DDa7Uw8GplX6A6o= 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 1705433222160478.9806859683714; Tue, 16 Jan 2024 11:27:02 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.668091.1040059 (Exim 4.92) (envelope-from ) id 1rPp58-0005ji-Qj; Tue, 16 Jan 2024 19:26:42 +0000 Received: by outflank-mailman (output) from mailman id 668091.1040059; Tue, 16 Jan 2024 19:26:42 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rPp58-0005fZ-9g; Tue, 16 Jan 2024 19:26:42 +0000 Received: by outflank-mailman (input) for mailman id 668091; Tue, 16 Jan 2024 19:26:40 +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 1rPp56-0002iI-F5 for xen-devel@lists.xenproject.org; Tue, 16 Jan 2024 19:26:40 +0000 Received: from smtp-fw-80009.amazon.com (smtp-fw-80009.amazon.com [99.78.197.220]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 2b30fbf2-b4a5-11ee-9b0f-b553b5be7939; Tue, 16 Jan 2024 20:26:38 +0100 (CET) Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO email-inbound-relay-iad-1d-m6i4x-d8e96288.us-east-1.amazon.com) ([10.25.36.210]) by smtp-border-fw-80009.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jan 2024 19:26:36 +0000 Received: from smtpout.prod.us-east-1.prod.farcaster.email.amazon.dev (iad7-ws-svc-p70-lb3-vlan3.iad.amazon.com [10.32.235.38]) by email-inbound-relay-iad-1d-m6i4x-d8e96288.us-east-1.amazon.com (Postfix) with ESMTPS id A011584E30; Tue, 16 Jan 2024 19:26:34 +0000 (UTC) Received: from EX19MTAUEA001.ant.amazon.com [10.0.29.78:62111] by smtpin.naws.us-east-1.prod.farcaster.email.amazon.dev [10.0.3.20:2525] with esmtp (Farcaster) id 526f3352-96b2-47dc-b68e-3f4b8bfe2e83; Tue, 16 Jan 2024 19:26:34 +0000 (UTC) Received: from EX19D008UEC004.ant.amazon.com (10.252.135.170) by EX19MTAUEA001.ant.amazon.com (10.252.134.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 16 Jan 2024 19:26:30 +0000 Received: from EX19MTAUEB001.ant.amazon.com (10.252.135.35) by EX19D008UEC004.ant.amazon.com (10.252.135.170) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 16 Jan 2024 19:26:30 +0000 Received: from dev-dsk-eliasely-1a-fd74790f.eu-west-1.amazon.com (10.253.91.118) by mail-relay.amazon.com (10.252.135.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40 via Frontend Transport; Tue, 16 Jan 2024 19:26:29 +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 Sender: "Xen-devel" X-Inumbo-ID: 2b30fbf2-b4a5-11ee-9b0f-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1705433198; x=1736969198; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=sWVxwHwgKXZxnYvHw7QOCApWITjaKrfn/x6fPGCt35k=; b=QdA1Y0FEmSd7CJBzyGz7QvuahXbB+fbPso/yE90GReTaTIXe3Ky2cMlI DW/Rrvm9HBo8MmeZMnJHeTej8adbIycZEdK7J+RANC50cRLnwCr+z7gXj 4LDPzreTMdKbWDyhkz3bNbMkdacgWamMuVeXrztcPvpBcR8EQ4x3irTpP g=; X-IronPort-AV: E=Sophos;i="6.05,200,1701129600"; d="scan'208";a="58701500" X-Farcaster-Flow-ID: 526f3352-96b2-47dc-b68e-3f4b8bfe2e83 From: Elias El Yandouzi To: CC: , , , Hongyan Xia , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , Wei Wang , Julien Grall , Elias El Yandouzi Subject: [PATCH v2 (resend) 12/27] x86/mapcache: Initialise the mapcache for the idle domain Date: Tue, 16 Jan 2024 19:25:56 +0000 Message-ID: <20240116192611.41112-13-eliasely@amazon.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240116192611.41112-1-eliasely@amazon.com> References: <20240116192611.41112-1-eliasely@amazon.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: Bulk X-ZohoMail-DKIM: pass (identity @amazon.com) X-ZM-MESSAGEID: 1705433223835100005 Content-Type: text/plain; charset="utf-8" From: Hongyan Xia In order to use the mapcache in the idle domain, we also have to populate its page tables in the PERDOMAIN region, and we need to move mapcache_domain_init() earlier in arch_domain_create(). Note, commit 'x86: lift mapcache variable to the arch level' has initialised the mapcache for HVM domains. With this patch, PV, HVM, idle domains now all initialise the mapcache. Signed-off-by: Wei Wang Signed-off-by: Hongyan Xia Signed-off-by: Julien Grall Signed-off-by: Elias El Yandouzi ---- 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 8ef3f7746f..d4c125bc14 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -750,9 +750,16 @@ int arch_domain_create(struct domain *d, =20 spin_lock_init(&d->arch.e820_lock); =20 + if ( (rc =3D mapcache_domain_init(d)) !=3D 0) + { + free_perdomain_mappings(d); + return rc; + } + /* Minimal initialisation for the idle domain. */ if ( unlikely(is_idle_domain(d)) ) { + struct page_info *pg =3D d->arch.perdomain_l3_pg; static const struct arch_csw idle_csw =3D { .from =3D paravirt_ctxt_switch_from, .to =3D paravirt_ctxt_switch_to, @@ -763,6 +770,9 @@ int arch_domain_create(struct domain *d, =20 d->arch.cpu_policy =3D ZERO_BLOCK_PTR; /* Catch stray misuses. */ =20 + idle_pg_table[l4_table_offset(PERDOMAIN_VIRT_START)] =3D + l4e_from_page(pg, __PAGE_HYPERVISOR_RW); + return 0; } =20 @@ -843,8 +853,6 @@ int arch_domain_create(struct domain *d, =20 psr_domain_init(d); =20 - mapcache_domain_init(d); - if ( is_hvm_domain(d) ) { if ( (rc =3D hvm_domain_initialise(d, config)) !=3D 0 ) --=20 2.40.1 From nobody Thu May 9 13:57:19 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=1705433222; cv=none; d=zohomail.com; s=zohoarc; b=E6HIcSBV5j1ZTyMgv+H4VRFujqCx91VcQd1YIfdz/ALnbuc2jGXQbYxN+fR+nzLaibgWokgqDGf17xCPKDgwqwGPAdyBl7012luTb76cqx/VYSN6vT1lMLHI5TRk9ho4nD8JpnQA4d6b/knYLlTSQhcX84HTQ1APiYYe91XnoDs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705433222; 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=OwpyHZJCgfsvXgrpfF3qQCU4NbQDoI500a3pBhrqpBY=; b=Nw8iFuVKlAfX9VV3WkoCtkINU/DxrBAkKpX2X7eDT5LWjjE3I/P3OegD5tG3CKjXo4sxk/sDOjPUZOqsq/aktvD6EDQiPB/sdX93KzWsNwBS76VdF3bxRuYKszhdUycDczOf2s+bmse5pE+l30YnFC8t7gvxLtYIvNwG3X1a0vw= 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 1705433222308402.97896102109405; Tue, 16 Jan 2024 11:27:02 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.668093.1040081 (Exim 4.92) (envelope-from ) id 1rPp5C-0006YI-2i; Tue, 16 Jan 2024 19:26:46 +0000 Received: by outflank-mailman (output) from mailman id 668093.1040081; Tue, 16 Jan 2024 19:26:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rPp5B-0006Us-Ep; Tue, 16 Jan 2024 19:26:45 +0000 Received: by outflank-mailman (input) for mailman id 668093; Tue, 16 Jan 2024 19:26:43 +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 1rPp59-0002iI-0z for xen-devel@lists.xenproject.org; Tue, 16 Jan 2024 19:26:43 +0000 Received: from smtp-fw-52005.amazon.com (smtp-fw-52005.amazon.com [52.119.213.156]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 2be1faf7-b4a5-11ee-9b0f-b553b5be7939; Tue, 16 Jan 2024 20:26:41 +0100 (CET) Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-pdx-2b-m6i4x-cadc3fbd.us-west-2.amazon.com) ([10.43.8.6]) by smtp-border-fw-52005.iad7.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jan 2024 19:26:38 +0000 Received: from smtpout.prod.us-east-1.prod.farcaster.email.amazon.dev (pdx2-ws-svc-p26-lb5-vlan2.pdx.amazon.com [10.39.38.66]) by email-inbound-relay-pdx-2b-m6i4x-cadc3fbd.us-west-2.amazon.com (Postfix) with ESMTPS id 13360A0786; Tue, 16 Jan 2024 19:26:37 +0000 (UTC) Received: from EX19MTAUEB002.ant.amazon.com [10.0.29.78:48367] by smtpin.naws.us-east-1.prod.farcaster.email.amazon.dev [10.0.57.22:2525] with esmtp (Farcaster) id 08e95fd3-8a75-4499-8d5b-ff27ab3d0876; Tue, 16 Jan 2024 19:26:36 +0000 (UTC) Received: from EX19D008UEA004.ant.amazon.com (10.252.134.191) by EX19MTAUEB002.ant.amazon.com (10.252.135.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 16 Jan 2024 19:26:32 +0000 Received: from EX19MTAUEB001.ant.amazon.com (10.252.135.35) by EX19D008UEA004.ant.amazon.com (10.252.134.191) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 16 Jan 2024 19:26:31 +0000 Received: from dev-dsk-eliasely-1a-fd74790f.eu-west-1.amazon.com (10.253.91.118) by mail-relay.amazon.com (10.252.135.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40 via Frontend Transport; Tue, 16 Jan 2024 19:26:30 +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 Sender: "Xen-devel" X-Inumbo-ID: 2be1faf7-b4a5-11ee-9b0f-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1705433201; x=1736969201; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OwpyHZJCgfsvXgrpfF3qQCU4NbQDoI500a3pBhrqpBY=; b=YW9zAB/xT40c292cFPUL3RVcuzLfs512VSeRxEnAAU+MaI6kVNzcZxCu JdW9zar6+ZBj8qxA4wKXAN97XJbrhLfdtzjQFWvoKWfMYRmMtdZaZtrGE BYCVhUeyDOP2dPCX/hwsFy4D31ws/abYltjAPrjmlX71rNUhSK7QZaANj Y=; X-IronPort-AV: E=Sophos;i="6.05,200,1701129600"; d="scan'208";a="627983576" X-Farcaster-Flow-ID: 08e95fd3-8a75-4499-8d5b-ff27ab3d0876 From: Elias El Yandouzi To: CC: , , , Hongyan Xia , Andrew Cooper , "George Dunlap" , Jan Beulich , "Stefano Stabellini" , Wei Liu , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Julien Grall Subject: [PATCH v2 (resend) 13/27] x86: Add a boot option to enable and disable the direct map Date: Tue, 16 Jan 2024 19:25:57 +0000 Message-ID: <20240116192611.41112-14-eliasely@amazon.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240116192611.41112-1-eliasely@amazon.com> References: <20240116192611.41112-1-eliasely@amazon.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: Bulk X-ZohoMail-DKIM: pass (identity @amazon.com) X-ZM-MESSAGEID: 1705433223866100007 Content-Type: text/plain; charset="utf-8" From: Hongyan Xia Also add a helper function to retrieve it. Change arch_mfns_in_direct_map to check this option before returning. This is added as a Kconfig option as well as a boot command line option. While being generic, the Kconfig option is only usable for x86 at the momen= t. Signed-off-by: Hongyan Xia Signed-off-by: Julien Grall ---- Changes in V2: * Introduce a Kconfig option * Reword the commit message * Make opt_directmap and helper generic Changes since Hongyan's version: * Reword the commit message * opt_directmap is only modified during boot so mark it as __ro_after_init diff --git a/docs/misc/xen-command-line.pandoc b/docs/misc/xen-command-line= .pandoc index 8e65f8bd18..63c946f482 100644 --- a/docs/misc/xen-command-line.pandoc +++ b/docs/misc/xen-command-line.pandoc @@ -799,6 +799,18 @@ that enabling this option cannot guarantee anything be= yond what underlying hardware guarantees (with, where available and known to Xen, respective tweaks applied). =20 +### directmap (x86) +> `=3D ` + +> Default: `true` + +Enable or disable the direct map region in Xen. + +By default, Xen creates the direct map region which maps physical memory +in that region. Setting this to no will remove the direct map, blocking +exploits that leak secrets via speculative memory access in the direct +map. + ### dma_bits > `=3D ` =20 diff --git a/xen/arch/x86/Kconfig b/xen/arch/x86/Kconfig index 1acdffc51c..350f41b832 100644 --- a/xen/arch/x86/Kconfig +++ b/xen/arch/x86/Kconfig @@ -29,6 +29,7 @@ config X86 select HAS_UBSAN select HAS_VPCI if HVM select NEEDS_LIBELF + select HAS_SECRET_HIDING =20 config ARCH_DEFCONFIG string diff --git a/xen/arch/x86/include/asm/mm.h b/xen/arch/x86/include/asm/mm.h index 7d26d9cd2f..4aae270a78 100644 --- a/xen/arch/x86/include/asm/mm.h +++ b/xen/arch/x86/include/asm/mm.h @@ -620,10 +620,18 @@ void write_32bit_pse_identmap(uint32_t *l2); /* * x86 maps part of physical memory via the directmap region. * Return whether the range of MFN falls in the directmap region. + * + * When boot command line sets directmap=3Dno, we will not have a direct m= ap at + * all so this will always return false. */ static inline bool arch_mfns_in_directmap(unsigned long mfn, unsigned long= nr) { - unsigned long eva =3D min(DIRECTMAP_VIRT_END, HYPERVISOR_VIRT_END); + unsigned long eva; + + if ( !has_directmap() ) + return false; + + eva =3D min(DIRECTMAP_VIRT_END, HYPERVISOR_VIRT_END); =20 return (mfn + nr) <=3D (virt_to_mfn(eva - 1) + 1); } diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 4d0c90b7a0..b813ea75b5 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -1512,6 +1512,8 @@ void asmlinkage __init noreturn __start_xen(unsigned = long mbi_p) if ( highmem_start ) xenheap_max_mfn(PFN_DOWN(highmem_start - 1)); =20 + printk("Booting with directmap %s\n", has_directmap() ? "on" : "off"); + /* * Walk every RAM region and map it in its entirety (on x86/64, at lea= st) * and notify it to the boot allocator. diff --git a/xen/common/Kconfig b/xen/common/Kconfig index 310ad4229c..9a24c89ac5 100644 --- a/xen/common/Kconfig +++ b/xen/common/Kconfig @@ -83,6 +83,23 @@ config HAS_UBSAN config MEM_ACCESS_ALWAYS_ON bool =20 +config HAS_SECRET_HIDING + bool + +config SECRET_HIDING + bool "Secret hiding" + depends on HAS_SECRET_HIDING + ---help--- + The directmap contains mapping for most of the RAM which makes domain + memory easily accessible. While making the performance better, it also= makes + the hypervisor more vulnerable to speculation attacks. + + Enabling this feature will allow the user to decide whether the memory + is always mapped at boot or mapped only on demand (see the command line + option "directmap"). + + If unsure, say N. + config MEM_ACCESS def_bool MEM_ACCESS_ALWAYS_ON prompt "Memory Access and VM events" if !MEM_ACCESS_ALWAYS_ON diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 740b6f0ff7..a3746cfbcf 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -173,6 +173,11 @@ paddr_t __ro_after_init mem_hotplug; static char __initdata opt_badpage[100] =3D ""; string_param("badpage", opt_badpage); =20 +bool __ro_after_init opt_directmap =3D true; +#ifdef CONFIG_HAS_SECRET_HIDING +boolean_param("directmap", opt_directmap); +#endif + /* * no-bootscrub -> Free pages are not zeroed during boot. */ diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h index 3d9b2d05a5..f860e98ee4 100644 --- a/xen/include/xen/mm.h +++ b/xen/include/xen/mm.h @@ -165,6 +165,13 @@ extern unsigned long max_page; extern unsigned long total_pages; extern paddr_t mem_hotplug; =20 +extern bool opt_directmap; + +static inline bool has_directmap(void) +{ + return opt_directmap; +} + /* * Extra fault info types which are used to further describe * the source of an access violation. --=20 2.40.1 From nobody Thu May 9 13:57:19 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=1705433233; cv=none; d=zohomail.com; s=zohoarc; b=FOKjcRsP/olIc7ttO/DCM2tl5k9KX813ytELoanXk/Qcsl13o92ZaiQCpgZGI9HkPl+Lm0LxejCu/cNUHYUIJKu5THMzzmEmZ+msCOukzLnbYJ2XAAze3/LobcgrGWzNAOYnCMjPruBANH1LuSTlqF9P3XA0k/or9E/AZxiXanc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705433233; 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=wuXlYkg7+aoOLvwI5g/1GuKiK7EGIYHkmtLupKWUrjI=; b=m5bX5yu+XcecKStkkQoy9bsJORzfX/A8DgK+hfrx2RCHajvdfBVffKxbU3m/6sK1lWu05H0A4ErbGDhAtdhLs42NraeCU/5fyOmvVvZB2LfUY4aNWdo11o8GApdxBQmsf78SWZUYlJ+DzswpR8CU7eDDj4yoSuIc33r8qd7zVxM= 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 1705433233600459.4605803216248; Tue, 16 Jan 2024 11:27:13 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.668094.1040095 (Exim 4.92) (envelope-from ) id 1rPp5F-0007FI-4b; Tue, 16 Jan 2024 19:26:49 +0000 Received: by outflank-mailman (output) from mailman id 668094.1040095; Tue, 16 Jan 2024 19:26:48 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rPp5E-0007CZ-I3; Tue, 16 Jan 2024 19:26:48 +0000 Received: by outflank-mailman (input) for mailman id 668094; Tue, 16 Jan 2024 19:26:46 +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 1rPp5C-0002iI-6d for xen-devel@lists.xenproject.org; Tue, 16 Jan 2024 19:26:46 +0000 Received: from smtp-fw-9102.amazon.com (smtp-fw-9102.amazon.com [207.171.184.29]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 2d8e4dfc-b4a5-11ee-9b0f-b553b5be7939; Tue, 16 Jan 2024 20:26:44 +0100 (CET) Received: from pdx4-co-svc-p1-lb2-vlan3.amazon.com (HELO email-inbound-relay-pdx-2b-m6i4x-f253a3a3.us-west-2.amazon.com) ([10.25.36.214]) by smtp-border-fw-9102.sea19.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jan 2024 19:26:35 +0000 Received: from smtpout.prod.us-east-1.prod.farcaster.email.amazon.dev (pdx2-ws-svc-p26-lb5-vlan2.pdx.amazon.com [10.39.38.66]) by email-inbound-relay-pdx-2b-m6i4x-f253a3a3.us-west-2.amazon.com (Postfix) with ESMTPS id B30BC8A2C3; Tue, 16 Jan 2024 19:26:34 +0000 (UTC) Received: from EX19MTAUEB001.ant.amazon.com [10.0.44.209:55964] by smtpin.naws.us-east-1.prod.farcaster.email.amazon.dev [10.0.15.248:2525] with esmtp (Farcaster) id f65ba36b-25b8-4d05-94e6-4f35e33c5e6c; Tue, 16 Jan 2024 19:26:34 +0000 (UTC) Received: from EX19D008UEA004.ant.amazon.com (10.252.134.191) by EX19MTAUEB001.ant.amazon.com (10.252.135.108) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 16 Jan 2024 19:26:33 +0000 Received: from EX19MTAUEB001.ant.amazon.com (10.252.135.35) by EX19D008UEA004.ant.amazon.com (10.252.134.191) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 16 Jan 2024 19:26:33 +0000 Received: from dev-dsk-eliasely-1a-fd74790f.eu-west-1.amazon.com (10.253.91.118) by mail-relay.amazon.com (10.252.135.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40 via Frontend Transport; Tue, 16 Jan 2024 19:26:32 +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 Sender: "Xen-devel" X-Inumbo-ID: 2d8e4dfc-b4a5-11ee-9b0f-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1705433204; x=1736969204; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wuXlYkg7+aoOLvwI5g/1GuKiK7EGIYHkmtLupKWUrjI=; b=b2J504VdoICtkKKbRBdd/H22G7IwiUjt37SvIJBC/W1XQa0c2k8l++zp fiLEWcsDWqFtLxB8JNzN6qKgey+qMtxcvrUI1mOQqjud8WYdfcuXc/Foc 44HcKRaQIXLTu4fEwK4G6Ne6dGodrXlfMR1N2K6z5xhyEcqTDCQr1vC+Q o=; X-IronPort-AV: E=Sophos;i="6.05,200,1701129600"; d="scan'208";a="390211249" X-Farcaster-Flow-ID: f65ba36b-25b8-4d05-94e6-4f35e33c5e6c From: Elias El Yandouzi To: CC: , , , Julien Grall , Stefano Stabellini , "Bertrand Marquis" , Michal Orzel , Volodymyr Babchuk , Andrew Cooper , George Dunlap , "Jan Beulich" , Wei Liu , Elias El Yandouzi , Henry Wang Subject: [PATCH v2 (resend) 14/27] xen/arm: fixmap: Rename the fixmap slots to follow the x86 convention Date: Tue, 16 Jan 2024 19:25:58 +0000 Message-ID: <20240116192611.41112-15-eliasely@amazon.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240116192611.41112-1-eliasely@amazon.com> References: <20240116192611.41112-1-eliasely@amazon.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: Bulk X-ZohoMail-DKIM: pass (identity @amazon.com) X-ZM-MESSAGEID: 1705433233940100001 Content-Type: text/plain; charset="utf-8" From: Julien Grall At the moment the fixmap slots are prefixed differently between arm and x86. Some of them (e.g. the PMAP slots) are used in common code. So it would be better if they are named the same way to avoid having to create aliases. I have decided to use the x86 naming because they are less change. So all the Arm fixmap slots will now be prefixed with FIX rather than FIXMAP. Signed-off-by: Julien Grall Signed-off-by: Elias El Yandouzi Reviewed-by: Henry Wang Reviewed-by: Jan Beulich Reviewed-by: Stefano Stabellini ---- Note that potentially more renaming that could be done to share more code in future. I have decided to not do that to avoid going down a rabbit hole. diff --git a/xen/arch/arm/acpi/lib.c b/xen/arch/arm/acpi/lib.c index 41d521f720..736cf09eca 100644 --- a/xen/arch/arm/acpi/lib.c +++ b/xen/arch/arm/acpi/lib.c @@ -40,10 +40,10 @@ char *__acpi_map_table(paddr_t phys, unsigned long size) return NULL; =20 offset =3D phys & (PAGE_SIZE - 1); - base =3D FIXMAP_ADDR(FIXMAP_ACPI_BEGIN) + offset; + base =3D FIXMAP_ADDR(FIX_ACPI_BEGIN) + offset; =20 /* Check the fixmap is big enough to map the region */ - if ( (FIXMAP_ADDR(FIXMAP_ACPI_END) + PAGE_SIZE - base) < size ) + if ( (FIXMAP_ADDR(FIX_ACPI_END) + PAGE_SIZE - base) < size ) return NULL; =20 /* With the fixmap, we can only map one region at the time */ @@ -54,7 +54,7 @@ char *__acpi_map_table(paddr_t phys, unsigned long size) =20 size +=3D offset; mfn =3D maddr_to_mfn(phys); - idx =3D FIXMAP_ACPI_BEGIN; + idx =3D FIX_ACPI_BEGIN; =20 do { set_fixmap(idx, mfn, PAGE_HYPERVISOR); @@ -72,8 +72,8 @@ bool __acpi_unmap_table(const void *ptr, unsigned long si= ze) unsigned int idx; =20 /* We are only handling fixmap address in the arch code */ - if ( (vaddr < FIXMAP_ADDR(FIXMAP_ACPI_BEGIN)) || - (vaddr >=3D (FIXMAP_ADDR(FIXMAP_ACPI_END) + PAGE_SIZE)) ) + if ( (vaddr < FIXMAP_ADDR(FIX_ACPI_BEGIN)) || + (vaddr >=3D (FIXMAP_ADDR(FIX_ACPI_END) + PAGE_SIZE)) ) return false; =20 /* @@ -81,16 +81,16 @@ bool __acpi_unmap_table(const void *ptr, unsigned long = size) * for the ACPI fixmap region. The caller is expected to free with * the same address. */ - ASSERT((vaddr & PAGE_MASK) =3D=3D FIXMAP_ADDR(FIXMAP_ACPI_BEGIN)); + ASSERT((vaddr & PAGE_MASK) =3D=3D FIXMAP_ADDR(FIX_ACPI_BEGIN)); =20 /* The region allocated fit in the ACPI fixmap region. */ - ASSERT(size < (FIXMAP_ADDR(FIXMAP_ACPI_END) + PAGE_SIZE - vaddr)); + ASSERT(size < (FIXMAP_ADDR(FIX_ACPI_END) + PAGE_SIZE - vaddr)); ASSERT(fixmap_inuse); =20 fixmap_inuse =3D false; =20 - size +=3D vaddr - FIXMAP_ADDR(FIXMAP_ACPI_BEGIN); - idx =3D FIXMAP_ACPI_BEGIN; + size +=3D vaddr - FIXMAP_ADDR(FIX_ACPI_BEGIN); + idx =3D FIX_ACPI_BEGIN; =20 do { diff --git a/xen/arch/arm/include/asm/early_printk.h b/xen/arch/arm/include= /asm/early_printk.h index c1e84f8b00..f444e89a86 100644 --- a/xen/arch/arm/include/asm/early_printk.h +++ b/xen/arch/arm/include/asm/early_printk.h @@ -17,7 +17,7 @@ =20 /* need to add the uart address offset in page to the fixmap address */ #define EARLY_UART_VIRTUAL_ADDRESS \ - (FIXMAP_ADDR(FIXMAP_CONSOLE) + (CONFIG_EARLY_UART_BASE_ADDRESS & ~PAGE= _MASK)) + (FIXMAP_ADDR(FIX_CONSOLE) + (CONFIG_EARLY_UART_BASE_ADDRESS & ~PAGE_MA= SK)) =20 #define TEMPORARY_EARLY_UART_VIRTUAL_ADDRESS \ (TEMPORARY_FIXMAP_ADDR(FIXMAP_CONSOLE) + (CONFIG_EARLY_UART_BASE_ADDRE= SS & ~PAGE_MASK)) diff --git a/xen/arch/arm/include/asm/fixmap.h b/xen/arch/arm/include/asm/f= ixmap.h index 734eb9b1d4..a823456ecb 100644 --- a/xen/arch/arm/include/asm/fixmap.h +++ b/xen/arch/arm/include/asm/fixmap.h @@ -8,17 +8,17 @@ #include =20 /* Fixmap slots */ -#define FIXMAP_CONSOLE 0 /* The primary UART */ -#define FIXMAP_MISC 1 /* Ephemeral mappings of hardware */ -#define FIXMAP_ACPI_BEGIN 2 /* Start mappings of ACPI tables */ -#define FIXMAP_ACPI_END (FIXMAP_ACPI_BEGIN + NUM_FIXMAP_ACPI_PAGES - 1)= /* End mappings of ACPI tables */ -#define FIXMAP_PMAP_BEGIN (FIXMAP_ACPI_END + 1) /* Start of PMAP */ -#define FIXMAP_PMAP_END (FIXMAP_PMAP_BEGIN + NUM_FIX_PMAP - 1) /* End of P= MAP */ +#define FIX_CONSOLE 0 /* The primary UART */ +#define FIX_MISC 1 /* Ephemeral mappings of hardware */ +#define FIX_ACPI_BEGIN 2 /* Start mappings of ACPI tables */ +#define FIX_ACPI_END (FIX_ACPI_BEGIN + NUM_FIXMAP_ACPI_PAGES - 1) /* E= nd mappings of ACPI tables */ +#define FIX_PMAP_BEGIN (FIX_ACPI_END + 1) /* Start of PMAP */ +#define FIX_PMAP_END (FIX_PMAP_BEGIN + NUM_FIX_PMAP - 1) /* End of PMAP */ =20 -#define FIXMAP_LAST FIXMAP_PMAP_END +#define FIX_LAST FIX_PMAP_END =20 #define FIXADDR_START FIXMAP_ADDR(0) -#define FIXADDR_TOP FIXMAP_ADDR(FIXMAP_LAST) +#define FIXADDR_TOP FIXMAP_ADDR(FIX_LAST) =20 #ifndef __ASSEMBLY__ =20 diff --git a/xen/arch/arm/mmu/setup.c b/xen/arch/arm/mmu/setup.c index 72725840b6..57f1b46499 100644 --- a/xen/arch/arm/mmu/setup.c +++ b/xen/arch/arm/mmu/setup.c @@ -351,7 +351,7 @@ void free_init_memory(void) */ void __init copy_from_paddr(void *dst, paddr_t paddr, unsigned long len) { - void *src =3D (void *)FIXMAP_ADDR(FIXMAP_MISC); + void *src =3D (void *)FIXMAP_ADDR(FIX_MISC); =20 while (len) { unsigned long l, s; @@ -359,10 +359,10 @@ void __init copy_from_paddr(void *dst, paddr_t paddr,= unsigned long len) s =3D paddr & (PAGE_SIZE - 1); l =3D min(PAGE_SIZE - s, len); =20 - set_fixmap(FIXMAP_MISC, maddr_to_mfn(paddr), PAGE_HYPERVISOR_WC); + set_fixmap(FIX_MISC, maddr_to_mfn(paddr), PAGE_HYPERVISOR_WC); memcpy(dst, src + s, l); clean_dcache_va_range(dst, l); - clear_fixmap(FIXMAP_MISC); + clear_fixmap(FIX_MISC); =20 paddr +=3D l; dst +=3D l; diff --git a/xen/common/pmap.c b/xen/common/pmap.c index 14517198aa..6e3ba9298d 100644 --- a/xen/common/pmap.c +++ b/xen/common/pmap.c @@ -32,8 +32,8 @@ void *__init pmap_map(mfn_t mfn) =20 __set_bit(idx, inuse); =20 - slot =3D idx + FIXMAP_PMAP_BEGIN; - ASSERT(slot >=3D FIXMAP_PMAP_BEGIN && slot <=3D FIXMAP_PMAP_END); + slot =3D idx + FIX_PMAP_BEGIN; + ASSERT(slot >=3D FIX_PMAP_BEGIN && slot <=3D FIX_PMAP_END); =20 /* * We cannot use set_fixmap() here. We use PMAP when the domain map @@ -53,10 +53,10 @@ void __init pmap_unmap(const void *p) unsigned int slot =3D virt_to_fix((unsigned long)p); =20 ASSERT(system_state < SYS_STATE_smp_boot); - ASSERT(slot >=3D FIXMAP_PMAP_BEGIN && slot <=3D FIXMAP_PMAP_END); + ASSERT(slot >=3D FIX_PMAP_BEGIN && slot <=3D FIX_PMAP_END); ASSERT(!in_irq()); =20 - idx =3D slot - FIXMAP_PMAP_BEGIN; + idx =3D slot - FIX_PMAP_BEGIN; =20 __clear_bit(idx, inuse); arch_pmap_unmap(slot); --=20 2.40.1 From nobody Thu May 9 13:57:19 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=1705433221; cv=none; d=zohomail.com; s=zohoarc; b=itspR2f9GAVkJFbw4s2RdywODZrz28zTAAMOJt0wkF52uClGoU9xsO6PwPJuG0Ib/afM3l3gv2fTvP/3JP1RBkVIir8bjl1nLIhjYq38tk8+hMN8hCJhygSm2yEAXMmhg97vyEgxbn/pcFDyRxk/DhuHks6JJw9dmfVtWV/7n+w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705433221; 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=L0+DUWALuf12F9Qa/oNJ9iBOAHkUE/QEE53X66ACQhM=; b=TQ1WVhvk6J8COi7m1gnsu08xG26ttOvvqt5q81iadzpxGyAchahfiYQb3rZeQ1v4zbTwZLillaR29SgXtKZbvb1UkdznyrrQn3Y5LwFTO/WcFy2QLWsEbBxxB2x9aqThv/QwkIuxbt5gLL4j15L2H9THGfOBNMDcQrZrjUyKPv4= 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 1705433221971508.65514764204136; Tue, 16 Jan 2024 11:27:01 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.668092.1040067 (Exim 4.92) (envelope-from ) id 1rPp59-00062j-WA; Tue, 16 Jan 2024 19:26:44 +0000 Received: by outflank-mailman (output) from mailman id 668092.1040067; Tue, 16 Jan 2024 19:26:43 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rPp59-0005yS-Fa; Tue, 16 Jan 2024 19:26:43 +0000 Received: by outflank-mailman (input) for mailman id 668092; Tue, 16 Jan 2024 19:26:41 +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 1rPp56-0003Xv-Qe for xen-devel@lists.xenproject.org; Tue, 16 Jan 2024 19:26:40 +0000 Received: from smtp-fw-80007.amazon.com (smtp-fw-80007.amazon.com [99.78.197.218]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 2b05fc8a-b4a5-11ee-98f1-6d05b1d4d9a1; Tue, 16 Jan 2024 20:26:38 +0100 (CET) Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO email-inbound-relay-pdx-2c-m6i4x-fa5fe5fb.us-west-2.amazon.com) ([10.25.36.210]) by smtp-border-fw-80007.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jan 2024 19:26:38 +0000 Received: from smtpout.prod.us-east-1.prod.farcaster.email.amazon.dev (pdx2-ws-svc-p26-lb5-vlan3.pdx.amazon.com [10.39.38.70]) by email-inbound-relay-pdx-2c-m6i4x-fa5fe5fb.us-west-2.amazon.com (Postfix) with ESMTPS id BDF6140DC0; Tue, 16 Jan 2024 19:26:36 +0000 (UTC) Received: from EX19MTAUEC002.ant.amazon.com [10.0.0.204:34893] by smtpin.naws.us-east-1.prod.farcaster.email.amazon.dev [10.0.19.196:2525] with esmtp (Farcaster) id 13706365-8a25-4c84-8180-7fdab47f7c13; Tue, 16 Jan 2024 19:26:35 +0000 (UTC) Received: from EX19D008UEC004.ant.amazon.com (10.252.135.170) by EX19MTAUEC002.ant.amazon.com (10.252.135.253) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 16 Jan 2024 19:26:34 +0000 Received: from EX19MTAUEB001.ant.amazon.com (10.252.135.35) by EX19D008UEC004.ant.amazon.com (10.252.135.170) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 16 Jan 2024 19:26:34 +0000 Received: from dev-dsk-eliasely-1a-fd74790f.eu-west-1.amazon.com (10.253.91.118) by mail-relay.amazon.com (10.252.135.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40 via Frontend Transport; Tue, 16 Jan 2024 19:26:33 +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 Sender: "Xen-devel" X-Inumbo-ID: 2b05fc8a-b4a5-11ee-98f1-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1705433199; x=1736969199; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=L0+DUWALuf12F9Qa/oNJ9iBOAHkUE/QEE53X66ACQhM=; b=B0sMpPqNeXJbPpLR0hh0R0YAsdvihp9gAjVjyIfhQ4s3PoNCFVhd79sY MmCfXoQ8QVkTkK9Va9bUY8MCfKPv5oiO5oZ864YG8/ja9S13Fu5/YNcr5 d5Bb03CTUYX3mxX+D5Mrwi+7XMI/bZcQCFpEUpM/6Ce7bjuPqBKF6WwmJ Y=; X-IronPort-AV: E=Sophos;i="6.05,200,1701129600"; d="scan'208";a="267191265" X-Farcaster-Flow-ID: 13706365-8a25-4c84-8180-7fdab47f7c13 From: Elias El Yandouzi To: CC: , , , Julien Grall , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , Elias El Yandouzi Subject: [PATCH v2 (resend) 15/27] xen/x86: Add support for the PMAP Date: Tue, 16 Jan 2024 19:25:59 +0000 Message-ID: <20240116192611.41112-16-eliasely@amazon.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240116192611.41112-1-eliasely@amazon.com> References: <20240116192611.41112-1-eliasely@amazon.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: Bulk X-ZohoMail-DKIM: pass (identity @amazon.com) X-ZM-MESSAGEID: 1705433223846100006 Content-Type: text/plain; charset="utf-8" From: Julien Grall PMAP will be used in a follow-up patch to bootstrap map domain page infrastructure -- we need some way to map pages to setup the mapcache without a direct map. The functions pmap_{map, unmap} open code {set, clear}_fixmap to break the loop. Signed-off-by: Julien Grall Signed-off-by: Elias El Yandouzi ---- The PMAP infrastructure was upstream separately for Arm since Hongyan sent the secret-free hypervisor series. So this is a new patch to plumb the feature on x86. Changes in v2: * Declare PMAP entries earlier in fixed_addresses * Reword the commit message diff --git a/xen/arch/x86/Kconfig b/xen/arch/x86/Kconfig index 350f41b832..16b2a32469 100644 --- a/xen/arch/x86/Kconfig +++ b/xen/arch/x86/Kconfig @@ -25,6 +25,7 @@ config X86 select HAS_PASSTHROUGH select HAS_PCI select HAS_PCI_MSI + select HAS_PMAP select HAS_SCHED_GRANULARITY select HAS_UBSAN select HAS_VPCI if HVM diff --git a/xen/arch/x86/include/asm/fixmap.h b/xen/arch/x86/include/asm/f= ixmap.h index 516ec3fa6c..a7ac365fc6 100644 --- a/xen/arch/x86/include/asm/fixmap.h +++ b/xen/arch/x86/include/asm/fixmap.h @@ -21,6 +21,8 @@ =20 #include #include +#include + #include #include #include @@ -53,6 +55,8 @@ enum fixed_addresses { FIX_PV_CONSOLE, FIX_XEN_SHARED_INFO, #endif /* CONFIG_XEN_GUEST */ + FIX_PMAP_BEGIN, + FIX_PMAP_END =3D FIX_PMAP_BEGIN + NUM_FIX_PMAP, /* Everything else should go further down. */ FIX_APIC_BASE, FIX_IO_APIC_BASE_0, diff --git a/xen/arch/x86/include/asm/pmap.h b/xen/arch/x86/include/asm/pma= p.h new file mode 100644 index 0000000000..62746e191d --- /dev/null +++ b/xen/arch/x86/include/asm/pmap.h @@ -0,0 +1,25 @@ +#ifndef __ASM_PMAP_H__ +#define __ASM_PMAP_H__ + +#include + +static inline void arch_pmap_map(unsigned int slot, mfn_t mfn) +{ + unsigned long linear =3D (unsigned long)fix_to_virt(slot); + l1_pgentry_t *pl1e =3D &l1_fixmap[l1_table_offset(linear)]; + + ASSERT(!(l1e_get_flags(*pl1e) & _PAGE_PRESENT)); + + l1e_write_atomic(pl1e, l1e_from_mfn(mfn, PAGE_HYPERVISOR)); +} + +static inline void arch_pmap_unmap(unsigned int slot) +{ + unsigned long linear =3D (unsigned long)fix_to_virt(slot); + l1_pgentry_t *pl1e =3D &l1_fixmap[l1_table_offset(linear)]; + + l1e_write_atomic(pl1e, l1e_empty()); + flush_tlb_one_local(linear); +} + +#endif /* __ASM_PMAP_H__ */ --=20 2.40.1 From nobody Thu May 9 13:57:19 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=1705434128; cv=none; d=zohomail.com; s=zohoarc; b=ClZCWQDsx/4QsqooVg9sguJNBo4c8lDGeaMekLpwv+xhfooeMhLaIo+VKzJsuRZxYKEXJW4DpPLTc0HHKQ94cw7TQ19r+uXKxm9taSOnYE6Vf6PWHx/n6/aYPxXvR+i60kGOgDO03aWWzJEk1p58+vuXmp4VrEHlmdcNUzk27nM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705434128; 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=tb2fNfqN0eF/OdROl8BG6kceQk3KA1cAs0YAyUr8QAc=; b=g9k4DV2QWPbHRy6VDTWR7EWUD+iYgkYdtO5PzRjiN3ZWiP0PqFC+0fUL+B/yfJk8jil9ZgP5RdDZiYtdT5Mk4uZGAeUQi6vmyLlms7tU7nzVi2Mo+oZhBG92M4vVdiqQJkghJ+IEzQbh3wSniC10L/PtgG8XXdRDIaXE0PiYRJc= 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 1705434128300369.9152122566853; Tue, 16 Jan 2024 11:42:08 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.668179.1040212 (Exim 4.92) (envelope-from ) id 1rPpJp-0001CK-Ee; Tue, 16 Jan 2024 19:41:53 +0000 Received: by outflank-mailman (output) from mailman id 668179.1040212; Tue, 16 Jan 2024 19:41:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rPpJp-0001CD-Bo; Tue, 16 Jan 2024 19:41:53 +0000 Received: by outflank-mailman (input) for mailman id 668179; Tue, 16 Jan 2024 19:41:52 +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 1rPp57-0003Xv-Qz for xen-devel@lists.xenproject.org; Tue, 16 Jan 2024 19:26:41 +0000 Received: from smtp-fw-52004.amazon.com (smtp-fw-52004.amazon.com [52.119.213.154]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 2bb49f52-b4a5-11ee-98f1-6d05b1d4d9a1; Tue, 16 Jan 2024 20:26:40 +0100 (CET) Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-pdx-2c-m6i4x-8c5b1df3.us-west-2.amazon.com) ([10.43.8.2]) by smtp-border-fw-52004.iad7.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jan 2024 19:26:39 +0000 Received: from smtpout.prod.us-east-1.prod.farcaster.email.amazon.dev (pdx2-ws-svc-p26-lb5-vlan3.pdx.amazon.com [10.39.38.70]) by email-inbound-relay-pdx-2c-m6i4x-8c5b1df3.us-west-2.amazon.com (Postfix) with ESMTPS id 348DA40DAA; Tue, 16 Jan 2024 19:26:37 +0000 (UTC) Received: from EX19MTAUEC001.ant.amazon.com [10.0.0.204:53301] by smtpin.naws.us-east-1.prod.farcaster.email.amazon.dev [10.0.15.248:2525] with esmtp (Farcaster) id 5e670533-2f6c-4336-8d86-c15826d81933; Tue, 16 Jan 2024 19:26:36 +0000 (UTC) Received: from EX19D008UEC004.ant.amazon.com (10.252.135.170) by EX19MTAUEC001.ant.amazon.com (10.252.135.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 16 Jan 2024 19:26:35 +0000 Received: from EX19MTAUEB001.ant.amazon.com (10.252.135.35) by EX19D008UEC004.ant.amazon.com (10.252.135.170) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 16 Jan 2024 19:26:35 +0000 Received: from dev-dsk-eliasely-1a-fd74790f.eu-west-1.amazon.com (10.253.91.118) by mail-relay.amazon.com (10.252.135.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40 via Frontend Transport; Tue, 16 Jan 2024 19:26:34 +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 Sender: "Xen-devel" X-Inumbo-ID: 2bb49f52-b4a5-11ee-98f1-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1705433201; x=1736969201; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tb2fNfqN0eF/OdROl8BG6kceQk3KA1cAs0YAyUr8QAc=; b=N0qDNj7xJPr7zenQX6jYFU+05C3mdhtFfH8uasW1C5Q4MtCBvsJHUIAT ZLdTOwuR4XHI9tazy27fNwfT/nwePOV6pc75r8dZ+1TFzuo5qMoCnBK7h NLYT2GrFUZgLalHTVq5j/PfTikk63Qs2Dx9ee1nQRbGAMLArZycCtsNYs 8=; X-IronPort-AV: E=Sophos;i="6.05,200,1701129600"; d="scan'208";a="178399480" X-Farcaster-Flow-ID: 5e670533-2f6c-4336-8d86-c15826d81933 From: Elias El Yandouzi To: CC: , , , "Elias El Yandouzi" , Jan Beulich , "Andrew Cooper" , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu Subject: [PATCH v2 (resend) 16/27] xen/x86: Add build assertion for fixmap entries Date: Tue, 16 Jan 2024 19:26:00 +0000 Message-ID: <20240116192611.41112-17-eliasely@amazon.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240116192611.41112-1-eliasely@amazon.com> References: <20240116192611.41112-1-eliasely@amazon.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: Bulk X-ZohoMail-DKIM: pass (identity @amazon.com) X-ZM-MESSAGEID: 1705434129590100001 Content-Type: text/plain; charset="utf-8" The early fixed addresses must all fit into the static L1 table. Introduce a build assertion to this end. Signed-off-by: Elias El Yandouzi ---- Changes in v2: * New patch diff --git a/xen/arch/x86/include/asm/fixmap.h b/xen/arch/x86/include/asm/f= ixmap.h index a7ac365fc6..904bee0480 100644 --- a/xen/arch/x86/include/asm/fixmap.h +++ b/xen/arch/x86/include/asm/fixmap.h @@ -77,6 +77,11 @@ enum fixed_addresses { #define FIXADDR_SIZE (__end_of_fixed_addresses << PAGE_SHIFT) #define FIXADDR_START (FIXADDR_TOP - FIXADDR_SIZE) =20 +static inline void fixaddr_build_assertion(void) +{ + BUILD_BUG_ON(FIX_PMAP_END > L1_PAGETABLE_ENTRIES - 1); +} + extern void __set_fixmap( enum fixed_addresses idx, unsigned long mfn, unsigned long flags); =20 --=20 2.40.1 From nobody Thu May 9 13:57:19 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=1705433226; cv=none; d=zohomail.com; s=zohoarc; b=KFKD2hT2drcZq0oDz8EvyaJr4AYCwqooyOnEsoChlBjCNAEvjL7asLPRE3+j7IWgB4f0BiZRddxHpSpAaSxQKuzwCOzFncdG0Yh4iXEuoSMs7n1KK/x5Fmnxeo1HR9XoQd5InSUB1yIf3tBmJ+IwH395+BwVoWJ3bk5w+U0hLJM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705433226; 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=Xc4KQdAGUonE6oCgkT6a8PPvVb9mrXzRPtcULUVgVPo=; b=Zu3X0yqaphclfxxfg33xUbqYM5wEd+gBkHf1qZDnv7C14xHrehmUxJnxd86yeIMrvRpBMD1y780ULqdrX6IyNtrYL7DqIg/Kk6FEaqiZhvJjC6dtWEcT8TDnz9O8gsGLYnKebtgNuhoAp/DUX8F9AgiXa+/UBTc1/bvi45odr8E= 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 1705433226612783.3636604546138; Tue, 16 Jan 2024 11:27:06 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.668095.1040104 (Exim 4.92) (envelope-from ) id 1rPp5G-0007XK-JD; Tue, 16 Jan 2024 19:26:50 +0000 Received: by outflank-mailman (output) from mailman id 668095.1040104; Tue, 16 Jan 2024 19:26:50 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rPp5F-0007Sx-TN; Tue, 16 Jan 2024 19:26:49 +0000 Received: by outflank-mailman (input) for mailman id 668095; Tue, 16 Jan 2024 19:26:47 +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 1rPp5D-0002iI-6a for xen-devel@lists.xenproject.org; Tue, 16 Jan 2024 19:26:47 +0000 Received: from smtp-fw-80009.amazon.com (smtp-fw-80009.amazon.com [99.78.197.220]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 2db9a4c6-b4a5-11ee-9b0f-b553b5be7939; Tue, 16 Jan 2024 20:26:44 +0100 (CET) Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO email-inbound-relay-iad-1d-m6i4x-b404fda3.us-east-1.amazon.com) ([10.25.36.210]) by smtp-border-fw-80009.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jan 2024 19:26:41 +0000 Received: from smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev (iad7-ws-svc-p70-lb3-vlan3.iad.amazon.com [10.32.235.38]) by email-inbound-relay-iad-1d-m6i4x-b404fda3.us-east-1.amazon.com (Postfix) with ESMTPS id 53F8C80D01; Tue, 16 Jan 2024 19:26:39 +0000 (UTC) Received: from EX19MTAUEC002.ant.amazon.com [10.0.0.204:54615] by smtpin.naws.us-east-1.prod.farcaster.email.amazon.dev [10.0.28.244:2525] with esmtp (Farcaster) id 548f5f56-80ce-4b57-950b-08f6014ca5ff; Tue, 16 Jan 2024 19:26:38 +0000 (UTC) Received: from EX19D008UEA003.ant.amazon.com (10.252.134.116) by EX19MTAUEC002.ant.amazon.com (10.252.135.253) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 16 Jan 2024 19:26:36 +0000 Received: from EX19MTAUEB001.ant.amazon.com (10.252.135.35) by EX19D008UEA003.ant.amazon.com (10.252.134.116) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 16 Jan 2024 19:26:36 +0000 Received: from dev-dsk-eliasely-1a-fd74790f.eu-west-1.amazon.com (10.253.91.118) by mail-relay.amazon.com (10.252.135.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40 via Frontend Transport; Tue, 16 Jan 2024 19:26:35 +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 Sender: "Xen-devel" X-Inumbo-ID: 2db9a4c6-b4a5-11ee-9b0f-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1705433204; x=1736969204; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Xc4KQdAGUonE6oCgkT6a8PPvVb9mrXzRPtcULUVgVPo=; b=gdHRPwxe/MFPBtj9mChqF4RtE14bnkvndE7sIwydhemFQ5H1sYbeA5s9 kgy7kbDzKrLydayKb2KgpQlieoVzs8lXRbqfZAi90HQ5H35vJvEFLZRLF Omlrdj47I7gl4LiQwQDjxWuzw/r1wYJeFlFNsMZwlyJZmMlY+oKmlw0OM s=; X-IronPort-AV: E=Sophos;i="6.05,200,1701129600"; d="scan'208";a="58701544" X-Farcaster-Flow-ID: 548f5f56-80ce-4b57-950b-08f6014ca5ff From: Elias El Yandouzi To: CC: , , , Hongyan Xia , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , Julien Grall Subject: [PATCH v2 (resend) 17/27] x86/domain_page: Remove the fast paths when mfn is not in the directmap Date: Tue, 16 Jan 2024 19:26:01 +0000 Message-ID: <20240116192611.41112-18-eliasely@amazon.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240116192611.41112-1-eliasely@amazon.com> References: <20240116192611.41112-1-eliasely@amazon.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: Bulk X-ZohoMail-DKIM: pass (identity @amazon.com) X-ZM-MESSAGEID: 1705433227876100002 Content-Type: text/plain; charset="utf-8" From: Hongyan Xia When mfn is not in direct map, never use mfn_to_virt for any mappings. We replace mfn_x(mfn) <=3D PFN_DOWN(__pa(HYPERVISOR_VIRT_END - 1)) with arch_mfns_in_direct_map(mfn, 1) because these two are equivalent. The extra comparison in arch_mfns_in_direct_map() looks different but because DIRECTMAP_VIRT_END is always higher, it does not make any difference. Lastly, domain_page_map_to_mfn() needs to gain to a special case for the PMAP. Signed-off-by: Hongyan Xia Signed-off-by: Julien Grall ---- Changes since Hongyan's version: * arch_mfn_in_direct_map() was renamed to arch_mfns_in_directmap() * add a special case for the PMAP in domain_page_map_to_mfn() diff --git a/xen/arch/x86/domain_page.c b/xen/arch/x86/domain_page.c index 55e337aaf7..89caefc8a2 100644 --- a/xen/arch/x86/domain_page.c +++ b/xen/arch/x86/domain_page.c @@ -14,8 +14,10 @@ #include #include #include +#include #include #include +#include #include =20 static DEFINE_PER_CPU(struct vcpu *, override); @@ -35,10 +37,11 @@ static inline struct vcpu *mapcache_current_vcpu(void) /* * When using efi runtime page tables, we have the equivalent of the i= dle * domain's page tables but current may point at another domain's VCPU. - * Return NULL as though current is not properly set up yet. + * Return the idle domains's vcpu on that core because the efi per-dom= ain + * region (where the mapcache is) is in-sync with the idle domain. */ if ( efi_rs_using_pgtables() ) - return NULL; + return idle_vcpu[smp_processor_id()]; =20 /* * If guest_table is NULL, and we are running a paravirtualised guest, @@ -77,18 +80,24 @@ void *map_domain_page(mfn_t mfn) struct vcpu_maphash_entry *hashent; =20 #ifdef NDEBUG - if ( mfn_x(mfn) <=3D PFN_DOWN(__pa(HYPERVISOR_VIRT_END - 1)) ) + if ( arch_mfns_in_directmap(mfn_x(mfn), 1) ) return mfn_to_virt(mfn_x(mfn)); #endif =20 v =3D mapcache_current_vcpu(); - if ( !v ) - return mfn_to_virt(mfn_x(mfn)); + if ( !v || !v->domain->arch.mapcache.inuse ) + { + if ( arch_mfns_in_directmap(mfn_x(mfn), 1) ) + return mfn_to_virt(mfn_x(mfn)); + else + { + BUG_ON(system_state >=3D SYS_STATE_smp_boot); + return pmap_map(mfn); + } + } =20 dcache =3D &v->domain->arch.mapcache; vcache =3D &v->arch.mapcache; - if ( !dcache->inuse ) - return mfn_to_virt(mfn_x(mfn)); =20 perfc_incr(map_domain_page_count); =20 @@ -184,6 +193,12 @@ void unmap_domain_page(const void *ptr) if ( !va || va >=3D DIRECTMAP_VIRT_START ) return; =20 + if ( va >=3D FIXADDR_START && va < FIXADDR_TOP ) + { + pmap_unmap((void *)ptr); + return; + } + ASSERT(va >=3D MAPCACHE_VIRT_START && va < MAPCACHE_VIRT_END); =20 v =3D mapcache_current_vcpu(); @@ -237,7 +252,7 @@ int mapcache_domain_init(struct domain *d) unsigned int bitmap_pages; =20 #ifdef NDEBUG - if ( !mem_hotplug && max_page <=3D PFN_DOWN(__pa(HYPERVISOR_VIRT_END -= 1)) ) + if ( !mem_hotplug && arch_mfn_in_directmap(0, max_page) ) return 0; #endif =20 @@ -308,7 +323,7 @@ void *map_domain_page_global(mfn_t mfn) local_irq_is_enabled())); =20 #ifdef NDEBUG - if ( mfn_x(mfn) <=3D PFN_DOWN(__pa(HYPERVISOR_VIRT_END - 1)) ) + if ( arch_mfn_in_directmap(mfn_x(mfn, 1)) ) return mfn_to_virt(mfn_x(mfn)); #endif =20 @@ -335,6 +350,23 @@ mfn_t domain_page_map_to_mfn(const void *ptr) if ( va >=3D DIRECTMAP_VIRT_START ) return _mfn(virt_to_mfn(ptr)); =20 + /* + * The fixmap is stealing the top-end of the VMAP. So the check for + * the PMAP *must* happen first. + * + * Also, the fixmap translate a slot to an address backwards. The + * logic will rely on it to avoid any complexity. So check at + * compile time this will always hold. + */ + BUILD_BUG_ON(fix_to_virt(FIX_PMAP_BEGIN) < fix_to_virt(FIX_PMAP_END)); + + if ( ((unsigned long)fix_to_virt(FIX_PMAP_END) <=3D va) && + ((va & PAGE_MASK) <=3D (unsigned long)fix_to_virt(FIX_PMAP_BEGIN)= ) ) + { + BUG_ON(system_state >=3D SYS_STATE_smp_boot); + return l1e_get_mfn(l1_fixmap[l1_table_offset(va)]); + } + if ( va >=3D VMAP_VIRT_START && va < VMAP_VIRT_END ) return vmap_to_mfn(va); =20 --=20 2.40.1 From nobody Thu May 9 13:57:19 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=1705433536; cv=none; d=zohomail.com; s=zohoarc; b=HJcOFa18l1VR3AQE5qY3Iq58aWddBQeUJ4Op/v5iEQcGUjEgN74tizZMsNJH7Km/FB040oDrJg3rTm1kYtJ90iIx2SbpnrM3RpNoH8/QTVbH9LUltYW8XChsrFv/bgW0zhFT+2MJhO3kC+ME2RoQEHJ+aw92XCUGJxln97B+Bu0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705433536; 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=SgoUYRGfBhQWiY7NendWHvruacHBLERYGlNvfzPucEo=; b=OHnmfPQl+7lIO0Lr7nLfUnLd4dlPlI6bqAho4sYLvE0xwWuWZqCs3417Qd+z23tep+szOLlUZhbyJIg/zbHkV1hcf33C9PFwG6gEJoCqXvvyyIg5fPqgJw4xCun8CYMfdPwk9z/s77kOwZRzfhlNNUYee04iv615/X7eOrUi50c= 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 1705433536036999.2408943955446; Tue, 16 Jan 2024 11:32:16 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.668132.1040152 (Exim 4.92) (envelope-from ) id 1rPpAK-0000iI-CV; Tue, 16 Jan 2024 19:32:04 +0000 Received: by outflank-mailman (output) from mailman id 668132.1040152; Tue, 16 Jan 2024 19:32:04 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rPpAK-0000iB-8m; Tue, 16 Jan 2024 19:32:04 +0000 Received: by outflank-mailman (input) for mailman id 668132; Tue, 16 Jan 2024 19:32:03 +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 1rPp5N-0002iI-L8 for xen-devel@lists.xenproject.org; Tue, 16 Jan 2024 19:26:57 +0000 Received: from smtp-fw-9105.amazon.com (smtp-fw-9105.amazon.com [207.171.188.204]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 34c40057-b4a5-11ee-9b0f-b553b5be7939; Tue, 16 Jan 2024 20:26:55 +0100 (CET) Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO email-inbound-relay-iad-1e-m6i4x-9694bb9e.us-east-1.amazon.com) ([10.25.36.210]) by smtp-border-fw-9105.sea19.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jan 2024 19:26:47 +0000 Received: from smtpout.prod.us-east-1.prod.farcaster.email.amazon.dev (iad7-ws-svc-p70-lb3-vlan2.iad.amazon.com [10.32.235.34]) by email-inbound-relay-iad-1e-m6i4x-9694bb9e.us-east-1.amazon.com (Postfix) with ESMTPS id 3AE97817C4; Tue, 16 Jan 2024 19:26:44 +0000 (UTC) Received: from EX19MTAUEA001.ant.amazon.com [10.0.29.78:55866] by smtpin.naws.us-east-1.prod.farcaster.email.amazon.dev [10.0.95.118:2525] with esmtp (Farcaster) id d4d114b5-d0b8-4230-b48b-4345f756de61; Tue, 16 Jan 2024 19:26:43 +0000 (UTC) Received: from EX19D008UEA004.ant.amazon.com (10.252.134.191) by EX19MTAUEA001.ant.amazon.com (10.252.134.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 16 Jan 2024 19:26:37 +0000 Received: from EX19MTAUEB001.ant.amazon.com (10.252.135.35) by EX19D008UEA004.ant.amazon.com (10.252.134.191) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 16 Jan 2024 19:26:37 +0000 Received: from dev-dsk-eliasely-1a-fd74790f.eu-west-1.amazon.com (10.253.91.118) by mail-relay.amazon.com (10.252.135.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40 via Frontend Transport; Tue, 16 Jan 2024 19:26:36 +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 Sender: "Xen-devel" X-Inumbo-ID: 34c40057-b4a5-11ee-9b0f-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1705433216; x=1736969216; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SgoUYRGfBhQWiY7NendWHvruacHBLERYGlNvfzPucEo=; b=NE0f8j1q31G3NHFXG8YOIGRi34LvMR3zHg1ry7fr6y5E21fT+Z9/vtDB DCTjvJ/237fEN5+lnk46KFpKp/+pYUCGR+3WE+5iIcWZgia7H9VBlm5qV Uc5tAcEWVxIKv3QbFF/12B1rfhi+Ti8yuaNtGu6fFC6bz2kjZvkGl8cTL 8=; X-IronPort-AV: E=Sophos;i="6.05,200,1701129600"; d="scan'208";a="698190453" X-Farcaster-Flow-ID: d4d114b5-d0b8-4230-b48b-4345f756de61 From: Elias El Yandouzi To: CC: , , , Hongyan Xia , Andrew Cooper , "George Dunlap" , Jan Beulich , "Stefano Stabellini" , Wei Liu , Julien Grall , Elias El Yandouzi Subject: [PATCH v2 (resend) 18/27] xen/page_alloc: Add a path for xenheap when there is no direct map Date: Tue, 16 Jan 2024 19:26:02 +0000 Message-ID: <20240116192611.41112-19-eliasely@amazon.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240116192611.41112-1-eliasely@amazon.com> References: <20240116192611.41112-1-eliasely@amazon.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: Bulk X-ZohoMail-DKIM: pass (identity @amazon.com) X-ZM-MESSAGEID: 1705433537208100001 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 Signed-off-by: Elias El Yandouzi ---- 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 in v2: * Fix remaining wrong indentation in alloc_xenheap_pages() Changes since Hongyan's version: * Rebase * Fix indentation in alloc_xenheap_pages() * Fix build for arm32 diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index a3746cfbcf..52934ec5c1 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -2237,6 +2237,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 @@ -2245,17 +2246,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 ( !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 ( !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 @@ -2279,6 +2299,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 @@ -2291,16 +2312,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 ( !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 @@ -2312,6 +2345,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 ( !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.40.1 From nobody Thu May 9 13:57:19 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=1705433506; cv=none; d=zohomail.com; s=zohoarc; b=XdxZu47zgDl/DWn4vp7GEd2L8FbvoDaL5Nx/IR+Ny8GJ9FnR4IZGrGaLXLNWNqvZuoo4EJpBB/vxGl2b75616/TpmGleuE4R25d5HGOeSU4KLd4LWb5R5MxTTwRECY8suzFZJV1+8X6DtpPOyg2Qatya/yb9z8BO3T7dm8gky1c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705433506; 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=fVoEyNUTrAzw7YTY+W9724IaRNR5eJ6bcUYtN3Z0rYg=; b=hGlbMsBKW5lUQwT/Ps3d/PWWRTC5TUjFWtBQ0A1pDJ/Cw/t2O1tDWIXG9Yw0kSUJnEFXyNjfcnKA6XDOZjwu1lbU65Tw88vqNOr1sKB3Cl5l66Sgc2YeO/hVaSm/e/fPrjHKxmF5a/CgCD31nTE7WKb23zN3jeUuNezLp7p02wQ= 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 170543350673789.76489023048646; Tue, 16 Jan 2024 11:31:46 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.668126.1040141 (Exim 4.92) (envelope-from ) id 1rPp9l-00089n-06; Tue, 16 Jan 2024 19:31:29 +0000 Received: by outflank-mailman (output) from mailman id 668126.1040141; Tue, 16 Jan 2024 19:31:28 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rPp9k-00089g-Tn; Tue, 16 Jan 2024 19:31:28 +0000 Received: by outflank-mailman (input) for mailman id 668126; Tue, 16 Jan 2024 19:31:27 +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 1rPp5O-0003Xv-Ea for xen-devel@lists.xenproject.org; Tue, 16 Jan 2024 19:26:58 +0000 Received: from smtp-fw-52003.amazon.com (smtp-fw-52003.amazon.com [52.119.213.152]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 3514ea24-b4a5-11ee-98f1-6d05b1d4d9a1; Tue, 16 Jan 2024 20:26:55 +0100 (CET) Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-iad-1e-m6i4x-a65ebc6e.us-east-1.amazon.com) ([10.43.8.6]) by smtp-border-fw-52003.iad7.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jan 2024 19:26:54 +0000 Received: from smtpout.prod.us-east-1.prod.farcaster.email.amazon.dev (iad7-ws-svc-p70-lb3-vlan3.iad.amazon.com [10.32.235.38]) by email-inbound-relay-iad-1e-m6i4x-a65ebc6e.us-east-1.amazon.com (Postfix) with ESMTPS id 91C3168F61; Tue, 16 Jan 2024 19:26:51 +0000 (UTC) Received: from EX19MTAUEC002.ant.amazon.com [10.0.0.204:14050] by smtpin.naws.us-east-1.prod.farcaster.email.amazon.dev [10.0.22.37:2525] with esmtp (Farcaster) id 4817dcb0-016b-443f-977f-5f3d3e04e4ed; Tue, 16 Jan 2024 19:26:51 +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_256_GCM_SHA384) id 15.2.1118.40; Tue, 16 Jan 2024 19:26:39 +0000 Received: from EX19MTAUEB001.ant.amazon.com (10.252.135.35) by EX19D008UEA004.ant.amazon.com (10.252.134.191) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 16 Jan 2024 19:26:38 +0000 Received: from dev-dsk-eliasely-1a-fd74790f.eu-west-1.amazon.com (10.253.91.118) by mail-relay.amazon.com (10.252.135.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40 via Frontend Transport; Tue, 16 Jan 2024 19:26:37 +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 Sender: "Xen-devel" X-Inumbo-ID: 3514ea24-b4a5-11ee-98f1-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1705433216; x=1736969216; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fVoEyNUTrAzw7YTY+W9724IaRNR5eJ6bcUYtN3Z0rYg=; b=hgrTjuOHKKkuAlrGJx3I6tz25MmYtYc6w7ZhnI2uw3v/62eHOpZgPfSe faY1hUVMIpC9pBd1s83sXBN5CkNYZqgfCEIFItffiqCQJAG6zM/p+joLg 8Avz4uKQQbRN9R/ghvCmQrGvmjUoCLmg8PXZz1XXe6Y4MvOGNl7Oi3Fqb w=; X-IronPort-AV: E=Sophos;i="6.05,200,1701129600"; d="scan'208";a="631577135" X-Farcaster-Flow-ID: 4817dcb0-016b-443f-977f-5f3d3e04e4ed From: Elias El Yandouzi To: CC: , , , Hongyan Xia , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , Julien Grall , Elias El Yandouzi Subject: [PATCH v2 (resend) 19/27] x86/setup: Leave early boot slightly earlier Date: Tue, 16 Jan 2024 19:26:03 +0000 Message-ID: <20240116192611.41112-20-eliasely@amazon.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240116192611.41112-1-eliasely@amazon.com> References: <20240116192611.41112-1-eliasely@amazon.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: Bulk X-ZohoMail-DKIM: pass (identity @amazon.com) X-ZM-MESSAGEID: 1705433506949100001 Content-Type: text/plain; charset="utf-8" From: Hongyan Xia When we do not have a direct map, memory for metadata of heap nodes in init_node_heap() is allocated from xenheap, which needs to be mapped and unmapped on demand. However, we cannot just take memory from the boot allocator to create the PTEs while we are passing memory to the heap allocator. To solve this race, we leave early boot slightly sooner so that Xen PTE pages are allocated from the heap instead of the boot allocator. We can do this because the metadata for the 1st node is statically allocated, and by the time we need memory to create mappings for the 2nd node, we already have enough memory in the heap allocator in the 1st node. Signed-off-by: Hongyan Xia Signed-off-by: Julien Grall Signed-off-by: Elias El Yandouzi diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index b813ea75b5..3b698c8c41 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -1746,6 +1746,22 @@ void asmlinkage __init noreturn __start_xen(unsigned= long mbi_p) =20 numa_initmem_init(0, raw_max_page); =20 + /* + * When we do not have a direct map, memory for metadata of heap nodes= in + * init_node_heap() is allocated from xenheap, which needs to be mappe= d and + * unmapped on demand. However, we cannot just take memory from the bo= ot + * allocator to create the PTEs while we are passing memory to the heap + * allocator during end_boot_allocator(). + * + * To solve this race, we need to leave early boot before + * end_boot_allocator() so that Xen PTE pages are allocated from the h= eap + * instead of the boot allocator. We can do this because the metadata = for + * the 1st node is statically allocated, and by the time we need memor= y to + * create mappings for the 2nd node, we already have enough memory in = the + * heap allocator in the 1st node. + */ + system_state =3D SYS_STATE_boot; + if ( max_page - 1 > virt_to_mfn(HYPERVISOR_VIRT_END - 1) ) { unsigned long lo =3D virt_to_mfn(HYPERVISOR_VIRT_END - 1); @@ -1777,8 +1793,6 @@ void asmlinkage __init noreturn __start_xen(unsigned = long mbi_p) else end_boot_allocator(); =20 - system_state =3D SYS_STATE_boot; - bsp_stack =3D cpu_alloc_stack(0); if ( !bsp_stack ) panic("No memory for BSP stack\n"); --=20 2.40.1 From nobody Thu May 9 13:57:19 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=1705433900; cv=none; d=zohomail.com; s=zohoarc; b=SdgoI2hrEUHpiAEyBrZOwlW6f+DSDyvk4lK/POpWBv2G4FxXqIwTPDrOD6yTMaIjAzoPWUWTzLLmSZQ/D3nnOJDSOgj+yfeIsA1uo6+di+ShdPZE69MeYQDsd7kd7KZD0U109XGtoZGGfEPamq95fHDBSHG3E2uSAFgUjA8s0HQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705433900; 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=BQwz5u8QWnu4kJOr/giiJYPgo6aRgBqNBhniW2zo2FE=; b=KpTm6mnVIDv8ahMnAsTzjNxoiNvX7xm5xeegwKL4nDd4iO492LNI4kJwuq8qAoAJXE7TEkXUlaTUr+HN3a2vXw9J5LE470XQrYOJrzXFAFK48qPl1p4ZNzXs/DM2wJ17uwNLc+VmFXuPn5LvV9RAm4fN7ic2XIlI31+7Mdbp2kQ= 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 1705433900171175.7536772053453; Tue, 16 Jan 2024 11:38:20 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.668159.1040182 (Exim 4.92) (envelope-from ) id 1rPpGC-0004n0-DA; Tue, 16 Jan 2024 19:38:08 +0000 Received: by outflank-mailman (output) from mailman id 668159.1040182; Tue, 16 Jan 2024 19:38:08 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rPpGC-0004mt-AA; Tue, 16 Jan 2024 19:38:08 +0000 Received: by outflank-mailman (input) for mailman id 668159; Tue, 16 Jan 2024 19:38:07 +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 1rPp5L-0002iI-Ef for xen-devel@lists.xenproject.org; Tue, 16 Jan 2024 19:26:55 +0000 Received: from smtp-fw-52002.amazon.com (smtp-fw-52002.amazon.com [52.119.213.150]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 33b40b5e-b4a5-11ee-9b0f-b553b5be7939; Tue, 16 Jan 2024 20:26:53 +0100 (CET) Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-iad-1e-m6i4x-529f0975.us-east-1.amazon.com) ([10.43.8.6]) by smtp-border-fw-52002.iad7.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jan 2024 19:26:50 +0000 Received: from smtpout.prod.us-east-1.prod.farcaster.email.amazon.dev (iad7-ws-svc-p70-lb3-vlan3.iad.amazon.com [10.32.235.38]) by email-inbound-relay-iad-1e-m6i4x-529f0975.us-east-1.amazon.com (Postfix) with ESMTPS id 21B894A22B; Tue, 16 Jan 2024 19:26:48 +0000 (UTC) Received: from EX19MTAUEC001.ant.amazon.com [10.0.0.204:44999] by smtpin.naws.us-east-1.prod.farcaster.email.amazon.dev [10.0.41.129:2525] with esmtp (Farcaster) id f94b5ab5-a209-4e45-9547-2bc37d5f6f7e; Tue, 16 Jan 2024 19:26:47 +0000 (UTC) Received: from EX19D008UEA003.ant.amazon.com (10.252.134.116) by EX19MTAUEC001.ant.amazon.com (10.252.135.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 16 Jan 2024 19:26:40 +0000 Received: from EX19MTAUEB001.ant.amazon.com (10.252.135.35) by EX19D008UEA003.ant.amazon.com (10.252.134.116) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 16 Jan 2024 19:26:40 +0000 Received: from dev-dsk-eliasely-1a-fd74790f.eu-west-1.amazon.com (10.253.91.118) by mail-relay.amazon.com (10.252.135.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40 via Frontend Transport; Tue, 16 Jan 2024 19:26:39 +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 Sender: "Xen-devel" X-Inumbo-ID: 33b40b5e-b4a5-11ee-9b0f-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1705433214; x=1736969214; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=BQwz5u8QWnu4kJOr/giiJYPgo6aRgBqNBhniW2zo2FE=; b=fK+gXXWJaTzHux0OYq9rmRDioM0IKYym2t0Dt/pwnXEbvemyK/tfLBB6 FhVkmJ+MAZNd/AUCQK7X+hqnCtxSeOkHk9633jPbPB36cdU8XWXrVxwzO N5vwbou3ekg324YZRmkZI+WgZunxdz/f4Lnjb74gd5fNd3whnVUFO9FE1 s=; X-IronPort-AV: E=Sophos;i="6.05,200,1701129600"; d="scan'208";a="606818879" X-Farcaster-Flow-ID: f94b5ab5-a209-4e45-9547-2bc37d5f6f7e From: Elias El Yandouzi To: CC: , , , Hongyan Xia , Andrew Cooper , "George Dunlap" , Jan Beulich , "Stefano Stabellini" , Wei Liu , Julien Grall , Elias El Yandouzi Subject: [PATCH v2 (resend) 20/27] x86/setup: vmap heap nodes when they are outside the direct map Date: Tue, 16 Jan 2024 19:26:04 +0000 Message-ID: <20240116192611.41112-21-eliasely@amazon.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240116192611.41112-1-eliasely@amazon.com> References: <20240116192611.41112-1-eliasely@amazon.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: Bulk X-ZohoMail-DKIM: pass (identity @amazon.com) X-ZM-MESSAGEID: 1705433900865100001 Content-Type: text/plain; charset="utf-8" From: Hongyan Xia When we do not have a direct map, archs_mfn_in_direct_map() will always return false, thus init_node_heap() will allocate xenheap pages from an existing node for the metadata of a new node. This means that the metadata of a new node is in a different node, slowing down heap allocation. Since we now have early vmap, vmap the metadata locally in the new node. Signed-off-by: Hongyan Xia Signed-off-by: Julien Grall Signed-off-by: Elias El Yandouzi ---- Changes in v2: * vmap_contig_pages() was renamed to vmap_contig() * Fix indentation and coding style Changes from Hongyan's version: * arch_mfn_in_direct_map() was renamed to arch_mfns_in_direct_map() * Use vmap_contig_pages() rather than __vmap(...). * Add missing include (xen/vmap.h) so it compiles on Arm diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 52934ec5c1..42b9aaae1c 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -136,6 +136,7 @@ #include #include #include +#include =20 #include #include @@ -604,22 +605,44 @@ static unsigned long init_node_heap(int node, unsigne= d long mfn, needed =3D 0; } else if ( *use_tail && nr >=3D needed && - arch_mfns_in_directmap(mfn + nr - needed, needed) && (!xenheap_bits || - !((mfn + nr - 1) >> (xenheap_bits - PAGE_SHIFT))) ) + !((mfn + nr - 1) >> (xenheap_bits - PAGE_SHIFT))) ) { - _heap[node] =3D mfn_to_virt(mfn + nr - needed); - avail[node] =3D mfn_to_virt(mfn + nr - 1) + - PAGE_SIZE - sizeof(**avail) * NR_ZONES; + 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) + + PAGE_SIZE - sizeof(**avail) * NR_ZONES; + } + else + { + mfn_t needed_start =3D _mfn(mfn + nr - needed); + + _heap[node] =3D vmap_contig(needed_start, needed); + BUG_ON(!_heap[node]); + avail[node] =3D (void *)(_heap[node]) + (needed << PAGE_SHIFT)= - + sizeof(**avail) * NR_ZONES; + } } else if ( nr >=3D needed && - arch_mfns_in_directmap(mfn, needed) && (!xenheap_bits || - !((mfn + needed - 1) >> (xenheap_bits - PAGE_SHIFT))) ) + !((mfn + needed - 1) >> (xenheap_bits - PAGE_SHIFT))) ) { - _heap[node] =3D mfn_to_virt(mfn); - avail[node] =3D mfn_to_virt(mfn + needed - 1) + - PAGE_SIZE - sizeof(**avail) * NR_ZONES; + if ( arch_mfns_in_directmap(mfn, needed) ) + { + _heap[node] =3D mfn_to_virt(mfn); + avail[node] =3D mfn_to_virt(mfn + needed - 1) + + PAGE_SIZE - sizeof(**avail) * NR_ZONES; + } + else + { + mfn_t needed_start =3D _mfn(mfn); + + _heap[node] =3D vmap_contig(needed_start, needed); + BUG_ON(!_heap[node]); + avail[node] =3D (void *)(_heap[node]) + (needed << PAGE_SHIFT)= - + sizeof(**avail) * NR_ZONES; + } *use_tail =3D false; } else if ( get_order_from_bytes(sizeof(**_heap)) =3D=3D --=20 2.40.1 From nobody Thu May 9 13:57:19 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=1705434690; cv=none; d=zohomail.com; s=zohoarc; b=aMmlBJMRIkxP9A3uRmYCZ2eXaQX8GNaBXVsLWVjt55/hIDE2SiSbOrrcRkflLtRAzuC0TyDF3CDMAt5e/A4qfVmlzJMNL3j2o4isT1k5LicK71dhlccn1EO28VBfPw22OtGIBi++s2s2eFb9rq9AJuHNymuQHy5MsOytIRXAcKI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705434690; 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=RNtWDehKcdKd51zP4omQpNRTUkQx1O6KgQ+LUko8Hd0=; b=Hhiq1TNxVjQn3GXq0biwzlPgOpJGG9YsxPKMWjxuf1NgKDof+6rIv+7YrNz8wCuAeDqrzXyu2nWBz67boiRbMlyjeniDh9xb/5oL7UGv7aAgaCGqh2e4RtA5ERoKZen9WQaAoYr/fcYoa6lTssIdMOqpumL+BZftGX3fyHq/faY= 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 1705434690394381.06488522475695; Tue, 16 Jan 2024 11:51:30 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.668197.1040222 (Exim 4.92) (envelope-from ) id 1rPpSl-0006hA-E4; Tue, 16 Jan 2024 19:51:07 +0000 Received: by outflank-mailman (output) from mailman id 668197.1040222; Tue, 16 Jan 2024 19:51:07 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rPpSl-0006h3-An; Tue, 16 Jan 2024 19:51:07 +0000 Received: by outflank-mailman (input) for mailman id 668197; Tue, 16 Jan 2024 19:51:06 +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 1rPp5M-0002iI-Ep for xen-devel@lists.xenproject.org; Tue, 16 Jan 2024 19:26:56 +0000 Received: from smtp-fw-6001.amazon.com (smtp-fw-6001.amazon.com [52.95.48.154]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 343407ec-b4a5-11ee-9b0f-b553b5be7939; Tue, 16 Jan 2024 20:26:54 +0100 (CET) Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-iad-1a-m6i4x-86a02d5e.us-east-1.amazon.com) ([10.43.8.2]) by smtp-border-fw-6001.iad6.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jan 2024 19:26:52 +0000 Received: from smtpout.prod.us-east-1.prod.farcaster.email.amazon.dev (iad7-ws-svc-p70-lb3-vlan2.iad.amazon.com [10.32.235.34]) by email-inbound-relay-iad-1a-m6i4x-86a02d5e.us-east-1.amazon.com (Postfix) with ESMTPS id 2514BEBF70; Tue, 16 Jan 2024 19:26:50 +0000 (UTC) Received: from EX19MTAUEA002.ant.amazon.com [10.0.29.78:44977] by smtpin.naws.us-east-1.prod.farcaster.email.amazon.dev [10.0.22.37:2525] with esmtp (Farcaster) id 558b48ad-83b8-4317-8bdc-7c0165ceb8c5; Tue, 16 Jan 2024 19:26:49 +0000 (UTC) Received: from EX19D008UEC004.ant.amazon.com (10.252.135.170) 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.1118.40; Tue, 16 Jan 2024 19:26:41 +0000 Received: from EX19MTAUEB001.ant.amazon.com (10.252.135.35) by EX19D008UEC004.ant.amazon.com (10.252.135.170) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 16 Jan 2024 19:26:41 +0000 Received: from dev-dsk-eliasely-1a-fd74790f.eu-west-1.amazon.com (10.253.91.118) by mail-relay.amazon.com (10.252.135.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40 via Frontend Transport; Tue, 16 Jan 2024 19:26:40 +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 Sender: "Xen-devel" X-Inumbo-ID: 343407ec-b4a5-11ee-9b0f-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1705433214; x=1736969214; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RNtWDehKcdKd51zP4omQpNRTUkQx1O6KgQ+LUko8Hd0=; b=dpWXd4EDj23rdLixSqlvXmOCIybgK7gmZQCki4kyQz58l16ZkWZ0UbDB t1CW3DahZbdU7zpEOrju07TwRsUDxz5P+ZvdpCeygHc4pcJkSiTlG77hx 3tQRBogz8mKntlVh2BnqVadmT95qieqtp7V9X6s+yu3kSH1Uw2NbxxO4B k=; X-IronPort-AV: E=Sophos;i="6.05,200,1701129600"; d="scan'208";a="382577346" X-Farcaster-Flow-ID: 558b48ad-83b8-4317-8bdc-7c0165ceb8c5 From: Elias El Yandouzi To: CC: , , , Hongyan Xia , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , Julien Grall , Elias El Yandouzi Subject: [PATCH v2 (resend) 21/27] x86/setup: Do not create valid mappings when directmap=no Date: Tue, 16 Jan 2024 19:26:05 +0000 Message-ID: <20240116192611.41112-22-eliasely@amazon.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240116192611.41112-1-eliasely@amazon.com> References: <20240116192611.41112-1-eliasely@amazon.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: Bulk X-ZohoMail-DKIM: pass (identity @amazon.com) X-ZM-MESSAGEID: 1705434691951100001 Content-Type: text/plain; charset="utf-8" From: Hongyan Xia Create empty mappings in the second e820 pass. Also, destroy existing direct map mappings created in the first pass. To make xenheap pages visible in guests, it is necessary to create empty L3 tables in the direct map even when directmap=3Dno, since guest cr3s copy idle domain's L4 entries, which means they will share mappings in the direct map if we pre-populate idle domain's L4 entries and L3 tables. A helper is introduced for this. Also, after the direct map is actually gone, we need to stop updating the direct map in update_xen_mappings(). Signed-off-by: Hongyan Xia Signed-off-by: Julien Grall Signed-off-by: Elias El Yandouzi diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 3b698c8c41..84c496ac4a 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -976,6 +976,57 @@ static struct domain *__init create_dom0(const module_= t *image, /* How much of the directmap is prebuilt at compile time. */ #define PREBUILT_MAP_LIMIT (1 << L2_PAGETABLE_SHIFT) =20 +/* + * This either populates a valid direct map, or allocates empty L3 tables = and + * creates the L4 entries for virtual address between [start, end) in the + * direct map depending on has_directmap(); + * + * When directmap=3Dno, we still need to populate empty L3 tables in the + * direct map region. The reason is that on-demand xenheap mappings are + * created in the idle domain's page table but must be seen by + * everyone. Since all domains share the direct map L4 entries, they + * will share xenheap mappings if we pre-populate the L4 entries and L3 + * tables in the direct map region for all RAM. We also rely on the fact + * that L3 tables are never freed. + */ +static void __init populate_directmap(uint64_t pstart, uint64_t pend, + unsigned int flags) +{ + unsigned long vstart =3D (unsigned long)__va(pstart); + unsigned long vend =3D (unsigned long)__va(pend); + + if ( pstart >=3D pend ) + return; + + BUG_ON(vstart < DIRECTMAP_VIRT_START); + BUG_ON(vend > DIRECTMAP_VIRT_END); + + if ( has_directmap() ) + /* Populate valid direct map. */ + BUG_ON(map_pages_to_xen(vstart, maddr_to_mfn(pstart), + PFN_DOWN(pend - pstart), flags)); + else + { + /* Create empty L3 tables. */ + unsigned long vaddr =3D vstart & ~((1UL << L4_PAGETABLE_SHIFT) - 1= ); + + for ( ; vaddr < vend; vaddr +=3D (1UL << L4_PAGETABLE_SHIFT) ) + { + l4_pgentry_t *pl4e =3D &idle_pg_table[l4_table_offset(vaddr)]; + + if ( !(l4e_get_flags(*pl4e) & _PAGE_PRESENT) ) + { + mfn_t mfn =3D alloc_boot_pages(1, 1); + void *v =3D map_domain_page(mfn); + + clear_page(v); + UNMAP_DOMAIN_PAGE(v); + l4e_write(pl4e, l4e_from_mfn(mfn, __PAGE_HYPERVISOR)); + } + } + } +} + void asmlinkage __init noreturn __start_xen(unsigned long mbi_p) { const char *memmap_type =3D NULL, *loader, *cmdline =3D ""; @@ -1596,8 +1647,17 @@ void asmlinkage __init noreturn __start_xen(unsigned= long mbi_p) map_e =3D min_t(uint64_t, e, ARRAY_SIZE(l2_directmap) << L2_PAGETABLE_SHIFT); =20 - /* Pass mapped memory to allocator /before/ creating new mappings.= */ + /* + * Pass mapped memory to allocator /before/ creating new mappings. + * The direct map for the bottom 4GiB has been populated in the fi= rst + * e820 pass. In the second pass, we make sure those existing mapp= ings + * are destroyed when directmap=3Dno. + */ init_boot_pages(s, min(map_s, e)); + if ( !has_directmap() ) + destroy_xen_mappings((unsigned long)__va(s), + (unsigned long)__va(min(map_s, e))); + s =3D map_s; if ( s < map_e ) { @@ -1605,6 +1665,9 @@ void asmlinkage __init noreturn __start_xen(unsigned = long mbi_p) map_s =3D (s + mask) & ~mask; map_e &=3D ~mask; init_boot_pages(map_s, map_e); + if ( !has_directmap() ) + destroy_xen_mappings((unsigned long)__va(map_s), + (unsigned long)__va(map_e)); } =20 if ( map_s > map_e ) @@ -1618,8 +1681,7 @@ void asmlinkage __init noreturn __start_xen(unsigned = long mbi_p) =20 if ( map_e < end ) { - map_pages_to_xen((unsigned long)__va(map_e), maddr_to_mfn(= map_e), - PFN_DOWN(end - map_e), PAGE_HYPERVISOR); + populate_directmap(map_e, end, PAGE_HYPERVISOR); init_boot_pages(map_e, end); map_e =3D end; } @@ -1628,13 +1690,11 @@ void asmlinkage __init noreturn __start_xen(unsigne= d long mbi_p) { /* This range must not be passed to the boot allocator and * must also not be mapped with _PAGE_GLOBAL. */ - map_pages_to_xen((unsigned long)__va(map_e), maddr_to_mfn(map_= e), - PFN_DOWN(e - map_e), __PAGE_HYPERVISOR_RW); + populate_directmap(map_e, e, __PAGE_HYPERVISOR_RW); } if ( s < map_s ) { - map_pages_to_xen((unsigned long)__va(s), maddr_to_mfn(s), - PFN_DOWN(map_s - s), PAGE_HYPERVISOR); + populate_directmap(s, map_s, PAGE_HYPERVISOR); init_boot_pages(s, map_s); } } --=20 2.40.1 From nobody Thu May 9 13:57:19 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=1705434092; cv=none; d=zohomail.com; s=zohoarc; b=G0rX+w1xW2zvEZy4mefIVOW/4lTvp7XVoPoJj0JVWvwxpzMpHYH5mNBnq3MyMHsvVN5MtkMv98Zrryz08BdRRzQeAfCR9RfseOTmXwSiXSxzPltgeX/tVFX66SqLHJYZkJ2Ec0ab7nlKpcF61cmdCIfTweO+RdpYNgluCftsoRQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705434092; 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=A4skyGZm0AGMkXurcV6O3b2jzlTiRDRc3CtNyj3qfuY=; b=NVASwy3rN9S4Q0yvoFBBWm/ZPCV+/MGZ2+J+Be5xc9OW6kDO7QfmCSfAmlebk572kHGkhXnbHcDWGY4CH7OBmETl6m8YuI7k8wK8BZ4IIHakwx3KWHpJEK7XKCD3DdquyUKEUrsPSZYKyyBdH5rECrZ2GEzWpVJ5tuO8ZdS9OFs= 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 1705434092466628.4390467829027; Tue, 16 Jan 2024 11:41:32 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.668176.1040201 (Exim 4.92) (envelope-from ) id 1rPpJH-0000NO-5H; Tue, 16 Jan 2024 19:41:19 +0000 Received: by outflank-mailman (output) from mailman id 668176.1040201; Tue, 16 Jan 2024 19:41:19 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rPpJH-0000NH-2b; Tue, 16 Jan 2024 19:41:19 +0000 Received: by outflank-mailman (input) for mailman id 668176; Tue, 16 Jan 2024 19:41:18 +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 1rPp5T-0002iI-0t for xen-devel@lists.xenproject.org; Tue, 16 Jan 2024 19:27:03 +0000 Received: from smtp-fw-2101.amazon.com (smtp-fw-2101.amazon.com [72.21.196.25]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 382ddb8c-b4a5-11ee-9b0f-b553b5be7939; Tue, 16 Jan 2024 20:27:00 +0100 (CET) Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-pdx-2b-m6i4x-f323d91c.us-west-2.amazon.com) ([10.43.8.6]) by smtp-border-fw-2101.iad2.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jan 2024 19:26:59 +0000 Received: from smtpout.prod.us-east-1.prod.farcaster.email.amazon.dev (pdx2-ws-svc-p26-lb5-vlan2.pdx.amazon.com [10.39.38.66]) by email-inbound-relay-pdx-2b-m6i4x-f323d91c.us-west-2.amazon.com (Postfix) with ESMTPS id 75F8140DEA; Tue, 16 Jan 2024 19:26:57 +0000 (UTC) Received: from EX19MTAUEA001.ant.amazon.com [10.0.29.78:7345] by smtpin.naws.us-east-1.prod.farcaster.email.amazon.dev [10.0.41.129:2525] with esmtp (Farcaster) id 6c715488-8cb1-43cc-a661-2a495c363afb; Tue, 16 Jan 2024 19:26:57 +0000 (UTC) Received: from EX19D008UEC004.ant.amazon.com (10.252.135.170) by EX19MTAUEA001.ant.amazon.com (10.252.134.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 16 Jan 2024 19:26:43 +0000 Received: from EX19MTAUEB001.ant.amazon.com (10.252.135.35) by EX19D008UEC004.ant.amazon.com (10.252.135.170) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 16 Jan 2024 19:26:42 +0000 Received: from dev-dsk-eliasely-1a-fd74790f.eu-west-1.amazon.com (10.253.91.118) by mail-relay.amazon.com (10.252.135.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40 via Frontend Transport; Tue, 16 Jan 2024 19:26:41 +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 Sender: "Xen-devel" X-Inumbo-ID: 382ddb8c-b4a5-11ee-9b0f-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1705433221; x=1736969221; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=A4skyGZm0AGMkXurcV6O3b2jzlTiRDRc3CtNyj3qfuY=; b=b0l7EOKuemGQtPHPhenLM2kOi1hv8RxTLk6nGnGYhh/+ouDaxhz7/+0z ElarMr/yN1ywb3CdFsTq+Ti5NTeOh32wEaC8GdEu1TkB9KKq2oWGu00Jg +DqUlPWp8Lk1TrY/Q3QvXdP6bDA+Tf1OeMSI2Kbpgvwct2Fhc0RsKaN/Y 0=; X-IronPort-AV: E=Sophos;i="6.05,200,1701129600"; d="scan'208";a="374795240" X-Farcaster-Flow-ID: 6c715488-8cb1-43cc-a661-2a495c363afb From: Elias El Yandouzi To: CC: , , , "Elias El Yandouzi" , Stefano Stabellini , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Andrew Cooper , George Dunlap , Jan Beulich , Wei Liu , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Lukasz Hawrylko , "Daniel P. Smith" , =?UTF-8?q?Mateusz=20M=C3=B3wka?= Subject: [PATCH v2 (resend) 22/27] Rename mfn_to_virt() calls Date: Tue, 16 Jan 2024 19:26:06 +0000 Message-ID: <20240116192611.41112-23-eliasely@amazon.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240116192611.41112-1-eliasely@amazon.com> References: <20240116192611.41112-1-eliasely@amazon.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: Bulk X-ZohoMail-DKIM: pass (identity @amazon.com) X-ZM-MESSAGEID: 1705434093511100001 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 cbcf3bf147..9a94d7eaf7 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 e59f6657d9..1b3ebae16f 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 @@ -613,7 +613,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->mod_end, 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 a72c32d87c..9530c93b68 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 84c496ac4a..de69b7935c 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -400,7 +400,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 ) { @@ -1703,7 +1703,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 86c4c22cac..4368a64009 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 42b9aaae1c..0877e275e5 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -610,8 +610,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 @@ -630,8 +630,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 From nobody Thu May 9 13:57:19 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=1705433857; cv=none; d=zohomail.com; s=zohoarc; b=af/cpDbofE4nD0/4Fq3MjH1waRt0268dyMNTFSxkh/p3h48wjdMNbqQxJyV1yx4fkhZ7LR9vFJaFtjTVT8X2BCBkwTc8TGjGiii66KnWPeQ7LmNWrwSVWkZ8UiOIy8GeFumb8nzdQeb+mXdkuVmFsaOPfK3nik8quixxeLTkHHc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705433857; 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=+rU3KYKkwvDL5SMUdui7+O6LLhWUw4C+QdJzoyKqE18=; b=EpqvlnOahDAbLlx0DYeBJZpuMOL/wOHqvyBJLjYsSHu/P21XBXs5pasuDSdnpHSUDyIbkZJaRHeiJOH1obhaEjDn5Pr3JqUpSqKYxx1jrJq6UhC8zy2KulnhXult92rL5DRQ2BgqHkyeSnom/tgqjAy06iF2IpaHDQ3vZmy/YwM= 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 1705433857305711.6259555376389; Tue, 16 Jan 2024 11:37:37 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.668154.1040161 (Exim 4.92) (envelope-from ) id 1rPpFP-0003Rq-Tj; Tue, 16 Jan 2024 19:37:19 +0000 Received: by outflank-mailman (output) from mailman id 668154.1040161; Tue, 16 Jan 2024 19:37:19 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rPpFP-0003Rj-RA; Tue, 16 Jan 2024 19:37:19 +0000 Received: by outflank-mailman (input) for mailman id 668154; Tue, 16 Jan 2024 19:37:19 +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 1rPp5Q-0003Xv-QT for xen-devel@lists.xenproject.org; Tue, 16 Jan 2024 19:27:00 +0000 Received: from smtp-fw-52003.amazon.com (smtp-fw-52003.amazon.com [52.119.213.152]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 380532c4-b4a5-11ee-98f1-6d05b1d4d9a1; Tue, 16 Jan 2024 20:26:59 +0100 (CET) Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-iad-1a-m6i4x-86a02d5e.us-east-1.amazon.com) ([10.43.8.6]) by smtp-border-fw-52003.iad7.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jan 2024 19:27:00 +0000 Received: from smtpout.prod.us-east-1.prod.farcaster.email.amazon.dev (iad7-ws-svc-p70-lb3-vlan2.iad.amazon.com [10.32.235.34]) by email-inbound-relay-iad-1a-m6i4x-86a02d5e.us-east-1.amazon.com (Postfix) with ESMTPS id 0E9E9EBF70; Tue, 16 Jan 2024 19:26:58 +0000 (UTC) Received: from EX19MTAUEC001.ant.amazon.com [10.0.0.204:54926] by smtpin.naws.us-east-1.prod.farcaster.email.amazon.dev [10.0.28.244:2525] with esmtp (Farcaster) id c9b4c47f-4ba4-444e-bc53-5dc288ca9c0b; Tue, 16 Jan 2024 19:26:57 +0000 (UTC) Received: from EX19D008UEA004.ant.amazon.com (10.252.134.191) by EX19MTAUEC001.ant.amazon.com (10.252.135.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 16 Jan 2024 19:26:44 +0000 Received: from EX19MTAUEB001.ant.amazon.com (10.252.135.35) by EX19D008UEA004.ant.amazon.com (10.252.134.191) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 16 Jan 2024 19:26:43 +0000 Received: from dev-dsk-eliasely-1a-fd74790f.eu-west-1.amazon.com (10.253.91.118) by mail-relay.amazon.com (10.252.135.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40 via Frontend Transport; Tue, 16 Jan 2024 19:26:43 +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 Sender: "Xen-devel" X-Inumbo-ID: 380532c4-b4a5-11ee-98f1-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1705433220; x=1736969220; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+rU3KYKkwvDL5SMUdui7+O6LLhWUw4C+QdJzoyKqE18=; b=goK8Kc1iTePL4lNi8uSFVzn1nsvTTiMmWGb+2ZNGoV44KDLZJHgqMr0R TGEY215n8BNysCbVjBEspkDpnHQcPHDUpw5P5A2mk/ZAMfqXGcrBEhoc6 Ilthsl8X7KYvvklSJnZ6z3EB6b62+K9u3gXqLN0EJeAPH/yHwtjR4T2Ih I=; X-IronPort-AV: E=Sophos;i="6.05,200,1701129600"; d="scan'208";a="631577165" X-Farcaster-Flow-ID: c9b4c47f-4ba4-444e-bc53-5dc288ca9c0b From: Elias El Yandouzi To: CC: , , , "Elias El Yandouzi" , Jan Beulich , "Andrew Cooper" , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu Subject: [PATCH v2 (resend) 23/27] Rename maddr_to_virt() calls Date: Tue, 16 Jan 2024 19:26:07 +0000 Message-ID: <20240116192611.41112-24-eliasely@amazon.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240116192611.41112-1-eliasely@amazon.com> References: <20240116192611.41112-1-eliasely@amazon.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: Bulk X-ZohoMail-DKIM: pass (identity @amazon.com) X-ZM-MESSAGEID: 1705433858653100001 Content-Type: text/plain; charset="utf-8" Until directmap gets completely removed, we'd still need to keep some calls to mmaddr_to_virt() for xenheap pages or when the directmap is enabled. Rename the macro to maddr_to_directmap_virt() to flag them and prevent further use of maddr_to_virt(). Signed-off-by: Elias El Yandouzi diff --git a/xen/arch/x86/dmi_scan.c b/xen/arch/x86/dmi_scan.c index 81f80c053a..ac016f3a04 100644 --- a/xen/arch/x86/dmi_scan.c +++ b/xen/arch/x86/dmi_scan.c @@ -277,7 +277,7 @@ const char *__init dmi_get_table(paddr_t *base, u32 *le= n) return "SMBIOS"; } } else { - char __iomem *p =3D maddr_to_virt(0xF0000), *q; + char __iomem *p =3D maddr_to_directmap_virt(0xF0000), *q; union { struct dmi_eps dmi; struct smbios3_eps smbios3; @@ -364,7 +364,7 @@ static int __init dmi_iterate(void (*decode)(const stru= ct dmi_header *)) dmi.size =3D 0; smbios3.length =3D 0; =20 - p =3D maddr_to_virt(0xF0000); + p =3D maddr_to_directmap_virt(0xF0000); for (q =3D p; q < p + 0x10000; q +=3D 16) { if (!dmi.size) { memcpy_fromio(&dmi, q, sizeof(dmi)); diff --git a/xen/arch/x86/include/asm/mach-default/bios_ebda.h b/xen/arch/x= 86/include/asm/mach-default/bios_ebda.h index 42de6b2a5b..8cfe53d1f2 100644 --- a/xen/arch/x86/include/asm/mach-default/bios_ebda.h +++ b/xen/arch/x86/include/asm/mach-default/bios_ebda.h @@ -7,7 +7,7 @@ */ static inline unsigned int get_bios_ebda(void) { - unsigned int address =3D *(unsigned short *)maddr_to_virt(0x40E); + unsigned int address =3D *(unsigned short *)maddr_to_directmap_virt(0x40E= ); address <<=3D 4; return address; /* 0 means none */ } diff --git a/xen/arch/x86/include/asm/page.h b/xen/arch/x86/include/asm/pag= e.h index c6891b52d4..bf7bf08ba4 100644 --- a/xen/arch/x86/include/asm/page.h +++ b/xen/arch/x86/include/asm/page.h @@ -240,11 +240,11 @@ void copy_page_sse2(void *to, const void *from); =20 /* Convert between Xen-heap virtual addresses and machine addresses. */ #define __pa(x) (virt_to_maddr(x)) -#define __va(x) (maddr_to_virt(x)) +#define __va(x) (maddr_to_directmap_virt(x)) =20 /* Convert between Xen-heap virtual addresses and machine frame numbers. */ #define __virt_to_mfn(va) (virt_to_maddr(va) >> PAGE_SHIFT) -#define __mfn_to_virt(mfn) (maddr_to_virt((paddr_t)(mfn) << PAGE_SHIFT)) +#define __mfn_to_virt(mfn) (maddr_to_directmap_virt((paddr_t)(mfn) << PAG= E_SHIFT)) =20 /* Convert between machine frame numbers and page-info structures. */ #define mfn_to_page(mfn) (frame_table + mfn_to_pdx(mfn)) @@ -270,7 +270,7 @@ void copy_page_sse2(void *to, const void *from); #define virt_to_mfn(va) __virt_to_mfn(va) #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_directmap_virt(ma) __maddr_to_directmap_virt((unsigned = long)(ma)) #define maddr_to_page(ma) __maddr_to_page(ma) #define page_to_maddr(pg) __page_to_maddr(pg) #define virt_to_page(va) __virt_to_page(va) diff --git a/xen/arch/x86/include/asm/x86_64/page.h b/xen/arch/x86/include/= asm/x86_64/page.h index f49e10475f..b9e47da46e 100644 --- a/xen/arch/x86/include/asm/x86_64/page.h +++ b/xen/arch/x86/include/asm/x86_64/page.h @@ -46,7 +46,7 @@ static inline unsigned long __virt_to_maddr(unsigned long= va) return xen_phys_start + va - XEN_VIRT_START; } =20 -static inline void *__maddr_to_virt(unsigned long ma) +static inline void *__maddr_to_directmap_virt(unsigned long ma) { /* Offset in the direct map, accounting for pdx compression */ unsigned long va_offset =3D maddr_to_directmapoff(ma); diff --git a/xen/arch/x86/mpparse.c b/xen/arch/x86/mpparse.c index d8ccab2449..69181b0abe 100644 --- a/xen/arch/x86/mpparse.c +++ b/xen/arch/x86/mpparse.c @@ -664,7 +664,7 @@ void __init get_smp_config (void) =20 static int __init smp_scan_config (unsigned long base, unsigned long lengt= h) { - unsigned int *bp =3D maddr_to_virt(base); + unsigned int *bp =3D maddr_to_directmap_virt(base); struct intel_mp_floating *mpf; =20 Dprintk("Scan SMP from %p for %ld bytes.\n", bp,length); diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c index 39aed5845d..1b02e2b6d5 100644 --- a/xen/common/efi/boot.c +++ b/xen/common/efi/boot.c @@ -1764,7 +1764,7 @@ void __init efi_init_memory(void) 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); + (unsigned long)maddr_to_directmap_virt(desc->Physi= calStart); else printk(XENLOG_ERR "Could not map MFNs %#lx-%#lx\n", smfn, emfn - 1); --=20 2.40.1 From nobody Thu May 9 13:57:19 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=1705433887; cv=none; d=zohomail.com; s=zohoarc; b=DMeeWHejqmx98eRDN8PYzJm7IURLuo4lnxHTC3yKCRUqS4xnrkm0cQ0GwywRaihZa0gAcOzXGSOZ61PCvnbuLi0FhP4eRhASQ7M7ty0zdNDDTOJp6GipT3FLN/bfCguDm4pW6hiBq8K7LJT49hYmkUw4h0e2ieDqNs7w44Fcils= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705433887; 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=aYNk7nmnUy0AklxdrRg4GNXCK3HA+7wbY/AdUPNJirw=; b=gn4XEVUDMfuk8MueNeuL9Gd/GNi7UDaKc6Iqc1EQEgoCj4Zpa43eCk7DFW+DPlut9wkeZEZxWarVrpUSWS7Ym7ck5jVQp8ka6Oa+e/A0+2ORxVT1NseKzjQ2mhLeECaTuMlYMHDBb31jFha5QwLBlhgSc5tA9QbFjSU147szzmk= 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 1705433887166893.4259661762272; Tue, 16 Jan 2024 11:38:07 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.668158.1040172 (Exim 4.92) (envelope-from ) id 1rPpFy-0004La-51; Tue, 16 Jan 2024 19:37:54 +0000 Received: by outflank-mailman (output) from mailman id 668158.1040172; Tue, 16 Jan 2024 19:37:54 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rPpFy-0004LR-2D; Tue, 16 Jan 2024 19:37:54 +0000 Received: by outflank-mailman (input) for mailman id 668158; Tue, 16 Jan 2024 19:37:53 +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 1rPp5S-0003Xv-QV for xen-devel@lists.xenproject.org; Tue, 16 Jan 2024 19:27:02 +0000 Received: from smtp-fw-80009.amazon.com (smtp-fw-80009.amazon.com [99.78.197.220]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 384ebc32-b4a5-11ee-98f1-6d05b1d4d9a1; Tue, 16 Jan 2024 20:27:02 +0100 (CET) Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO email-inbound-relay-pdx-2a-m6i4x-8a14c045.us-west-2.amazon.com) ([10.25.36.210]) by smtp-border-fw-80009.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jan 2024 19:26:59 +0000 Received: from smtpout.prod.us-east-1.prod.farcaster.email.amazon.dev (pdx2-ws-svc-p26-lb5-vlan3.pdx.amazon.com [10.39.38.70]) by email-inbound-relay-pdx-2a-m6i4x-8a14c045.us-west-2.amazon.com (Postfix) with ESMTPS id 61AFB8A88F; Tue, 16 Jan 2024 19:26:59 +0000 (UTC) Received: from EX19MTAUEB001.ant.amazon.com [10.0.44.209:25181] by smtpin.naws.us-east-1.prod.farcaster.email.amazon.dev [10.0.28.244:2525] with esmtp (Farcaster) id d5980af4-5f49-4af7-90df-632bef320357; Tue, 16 Jan 2024 19:26:58 +0000 (UTC) Received: from EX19D008UEA003.ant.amazon.com (10.252.134.116) by EX19MTAUEB001.ant.amazon.com (10.252.135.108) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 16 Jan 2024 19:26:45 +0000 Received: from EX19MTAUEB001.ant.amazon.com (10.252.135.35) by EX19D008UEA003.ant.amazon.com (10.252.134.116) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 16 Jan 2024 19:26:45 +0000 Received: from dev-dsk-eliasely-1a-fd74790f.eu-west-1.amazon.com (10.253.91.118) by mail-relay.amazon.com (10.252.135.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40 via Frontend Transport; Tue, 16 Jan 2024 19:26:44 +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 Sender: "Xen-devel" X-Inumbo-ID: 384ebc32-b4a5-11ee-98f1-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1705433222; x=1736969222; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=aYNk7nmnUy0AklxdrRg4GNXCK3HA+7wbY/AdUPNJirw=; b=uO7Ic/EPVcSsiLVodvkwfdiz05YSUI2JztFCr+KXgEKGJIiX+k4cCt/x qVO3JhGOuofIezBUuC4E7L9HPu1jGpgUpVh4sD/Xj0372qIxbra2jzoO/ QwJF40J85wR4pca1stBYJUNlNbUrLiq8eVd6Wz/megYCFhQz2m/pYUIS2 g=; X-IronPort-AV: E=Sophos;i="6.05,200,1701129600"; d="scan'208";a="58701687" X-Farcaster-Flow-ID: d5980af4-5f49-4af7-90df-632bef320357 From: Elias El Yandouzi To: CC: , , , Julien Grall , Stefano Stabellini , "Bertrand Marquis" , Michal Orzel , Volodymyr Babchuk , Elias El Yandouzi Subject: [PATCH v2 (resend) 24/27] xen/arm32: mm: Rename 'first' to 'root' in init_secondary_pagetables() Date: Tue, 16 Jan 2024 19:26:08 +0000 Message-ID: <20240116192611.41112-25-eliasely@amazon.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240116192611.41112-1-eliasely@amazon.com> References: <20240116192611.41112-1-eliasely@amazon.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: Bulk X-ZohoMail-DKIM: pass (identity @amazon.com) X-ZM-MESSAGEID: 1705433888604100001 Content-Type: text/plain; charset="utf-8" From: Julien Grall The arm32 version of init_secondary_pagetables() will soon be re-used for arm64 as well where the root table starts at level 0 rather than level = 1. So rename 'first' to 'root'. Signed-off-by: Julien Grall Signed-off-by: Elias El Yandouzi ---- Changelog in v2: * Rebase * Fix typo diff --git a/xen/arch/arm/mmu/smpboot.c b/xen/arch/arm/mmu/smpboot.c index b6fc0aae07..fb5df667ba 100644 --- a/xen/arch/arm/mmu/smpboot.c +++ b/xen/arch/arm/mmu/smpboot.c @@ -84,32 +84,30 @@ int prepare_secondary_mm(int cpu) #else int prepare_secondary_mm(int cpu) { - lpae_t *first; + lpae_t *root =3D alloc_xenheap_page(); =20 - first =3D alloc_xenheap_page(); /* root =3D=3D first level on 32-bit 3= -level trie */ - - if ( !first ) + if ( !root ) { - printk("CPU%u: Unable to allocate the first page-table\n", cpu); + printk("CPU%u: Unable to allocate the root page-table\n", cpu); return -ENOMEM; } =20 /* Initialise root pagetable from root of boot tables */ - memcpy(first, per_cpu(xen_pgtable, 0), PAGE_SIZE); - per_cpu(xen_pgtable, cpu) =3D first; + memcpy(root, per_cpu(xen_pgtable, 0), PAGE_SIZE); + per_cpu(xen_pgtable, cpu) =3D root; =20 if ( !init_domheap_mappings(cpu) ) { printk("CPU%u: Unable to prepare the domheap page-tables\n", cpu); per_cpu(xen_pgtable, cpu) =3D NULL; - free_xenheap_page(first); + free_xenheap_page(root); return -ENOMEM; } =20 clear_boot_pagetables(); =20 /* Set init_ttbr for this CPU coming up */ - init_ttbr =3D __pa(first); + init_ttbr =3D __pa(root); clean_dcache(init_ttbr); =20 return 0; --=20 2.40.1 From nobody Thu May 9 13:57:19 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=1705433343; cv=none; d=zohomail.com; s=zohoarc; b=Eil8e2SHQ+lue3ttSbaTCSL0MEWtVMLIhi3aPexEQnxcQJRd61X6CI9jc62zKz1qy9Fsrb7Dpk+kitTtYeFadTnb9kv6fGno76Lzu72qO5HCIfa8KoyUqJwUc/4OBmd6CSBTw2PLdiDgR1TsqtbIVA6Nnnq0EzDMA6FmkWun9xk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705433343; 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=HBVAS715RpCNC8CvMLRfobjdzDnsKgjKWFL+xKdoEXs=; b=SahFXYmPhFPbYWsu75P9ali2QX6vJdmetD29HeKWK0Ih0vFiiUKEdkJRmj5OnVM1kDtJasuigiCDK97nESO6gIa9d3psBAGGeplB4bTmGaoJqa42cIOlhweAbsDdiVf4ck4UyvepckF9rNgwSsGxmWB3MEjMxJvf0YmlhOOjytE= 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 1705433343419704.1036719670575; Tue, 16 Jan 2024 11:29:03 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.668118.1040122 (Exim 4.92) (envelope-from ) id 1rPp72-0004bV-C9; Tue, 16 Jan 2024 19:28:40 +0000 Received: by outflank-mailman (output) from mailman id 668118.1040122; Tue, 16 Jan 2024 19:28:40 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rPp72-0004bM-8i; Tue, 16 Jan 2024 19:28:40 +0000 Received: by outflank-mailman (input) for mailman id 668118; Tue, 16 Jan 2024 19:28:39 +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 1rPp5U-0003Xv-35 for xen-devel@lists.xenproject.org; Tue, 16 Jan 2024 19:27:04 +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 395d8250-b4a5-11ee-98f1-6d05b1d4d9a1; Tue, 16 Jan 2024 20:27:02 +0100 (CET) Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-pdx-2c-m6i4x-d2040ec1.us-west-2.amazon.com) ([10.43.8.6]) by smtp-border-fw-52002.iad7.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jan 2024 19:27:01 +0000 Received: from smtpout.prod.us-east-1.prod.farcaster.email.amazon.dev (pdx2-ws-svc-p26-lb5-vlan2.pdx.amazon.com [10.39.38.66]) by email-inbound-relay-pdx-2c-m6i4x-d2040ec1.us-west-2.amazon.com (Postfix) with ESMTPS id 90AE540D7F; Tue, 16 Jan 2024 19:26:59 +0000 (UTC) Received: from EX19MTAUEB002.ant.amazon.com [10.0.29.78:14119] by smtpin.naws.us-east-1.prod.farcaster.email.amazon.dev [10.0.57.22:2525] with esmtp (Farcaster) id 193c356f-d5a1-4ec0-b9d7-e823c4fd556c; Tue, 16 Jan 2024 19:26:58 +0000 (UTC) Received: from EX19D008UEA004.ant.amazon.com (10.252.134.191) by EX19MTAUEB002.ant.amazon.com (10.252.135.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 16 Jan 2024 19:26:46 +0000 Received: from EX19MTAUEB001.ant.amazon.com (10.252.135.35) by EX19D008UEA004.ant.amazon.com (10.252.134.191) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 16 Jan 2024 19:26:46 +0000 Received: from dev-dsk-eliasely-1a-fd74790f.eu-west-1.amazon.com (10.253.91.118) by mail-relay.amazon.com (10.252.135.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40 via Frontend Transport; Tue, 16 Jan 2024 19:26:45 +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 Sender: "Xen-devel" X-Inumbo-ID: 395d8250-b4a5-11ee-98f1-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1705433223; x=1736969223; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=HBVAS715RpCNC8CvMLRfobjdzDnsKgjKWFL+xKdoEXs=; b=i4udLAip7iPs8rJsBIgH6ZhDtid5EH+Du6YLwpmLgFbxxE2o99m3zaVJ tyOl4eewHaTALD5eTHySaeGJhSluultpsqmZ9WqKXwUfjhGQ3TRnktEOr GLdsZHiN0WIE6NU7U+eJE1c8h5T4eMQ+PfTKBXywe3jZx7N6c1Cf6B9pv k=; X-IronPort-AV: E=Sophos;i="6.05,200,1701129600"; d="scan'208";a="606818936" X-Farcaster-Flow-ID: 193c356f-d5a1-4ec0-b9d7-e823c4fd556c From: Elias El Yandouzi To: CC: , , , Julien Grall , Stefano Stabellini , "Bertrand Marquis" , Michal Orzel , Volodymyr Babchuk , Elias El Yandouzi Subject: [PATCH v2 (resend) 25/27] xen/arm64: mm: Use per-pCPU page-tables Date: Tue, 16 Jan 2024 19:26:09 +0000 Message-ID: <20240116192611.41112-26-eliasely@amazon.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240116192611.41112-1-eliasely@amazon.com> References: <20240116192611.41112-1-eliasely@amazon.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: Bulk X-ZohoMail-DKIM: pass (identity @amazon.com) X-ZM-MESSAGEID: 1705433344366100001 Content-Type: text/plain; charset="utf-8" From: Julien Grall At the moment, on Arm64, every pCPU is sharing the same page-tables. In a follow-up patch, we will allow the possibility to remove the direct map and therefore it will be necessary to have a mapcache. While we have plenty of spare virtual address space to reserve part for each pCPU, it means that temporary mappings (e.g. guest memory) could be accessible by every pCPU. In order to increase our security posture, it would be better if those mappings are only accessible by the pCPU doing the temporary mapping. In addition to that, a per-pCPU page-tables opens the way to have per-domain mapping area. Arm32 is already using per-pCPU page-tables so most of the code can be re-used. Arm64 doesn't yet have support for the mapcache, so a stub is provided (moved to its own header asm/domain_page.h). Take the opportunity to fix a typo in a comment that is modified. Signed-off-by: Julien Grall Signed-off-by: Elias El Yandouzi ---- Changelog since v1: * Rebase * Fix typoes diff --git a/xen/arch/arm/arm64/mmu/mm.c b/xen/arch/arm/arm64/mmu/mm.c index d2651c9486..4f339efb7b 100644 --- a/xen/arch/arm/arm64/mmu/mm.c +++ b/xen/arch/arm/arm64/mmu/mm.c @@ -75,6 +75,7 @@ static void __init prepare_runtime_identity_mapping(void) paddr_t id_addr =3D virt_to_maddr(_start); lpae_t pte; DECLARE_OFFSETS(id_offsets, id_addr); + lpae_t *root =3D this_cpu(xen_pgtable); =20 if ( id_offsets[0] >=3D IDENTITY_MAPPING_AREA_NR_L0 ) panic("Cannot handle ID mapping above %uTB\n", @@ -85,7 +86,7 @@ static void __init prepare_runtime_identity_mapping(void) pte.pt.table =3D 1; pte.pt.xn =3D 0; =20 - write_pte(&xen_pgtable[id_offsets[0]], pte); + write_pte(&root[id_offsets[0]], pte); =20 /* Link second ID table */ pte =3D pte_of_xenaddr((vaddr_t)xen_second_id); diff --git a/xen/arch/arm/domain_page.c b/xen/arch/arm/domain_page.c index 3a43601623..ac2a6d0332 100644 --- a/xen/arch/arm/domain_page.c +++ b/xen/arch/arm/domain_page.c @@ -3,6 +3,8 @@ #include #include =20 +#include + /* Override macros from asm/page.h to make them work with mfn_t */ #undef virt_to_mfn #define virt_to_mfn(va) _mfn(__virt_to_mfn(va)) diff --git a/xen/arch/arm/include/asm/arm32/mm.h b/xen/arch/arm/include/asm= /arm32/mm.h index 856f2dbec4..87a315db01 100644 --- a/xen/arch/arm/include/asm/arm32/mm.h +++ b/xen/arch/arm/include/asm/arm32/mm.h @@ -1,12 +1,6 @@ #ifndef __ARM_ARM32_MM_H__ #define __ARM_ARM32_MM_H__ =20 -#include - -#include - -DECLARE_PER_CPU(lpae_t *, xen_pgtable); - /* * Only a limited amount of RAM, called xenheap, is always mapped on ARM32. * For convenience always return false. @@ -16,8 +10,6 @@ static inline bool arch_mfns_in_directmap(unsigned long m= fn, unsigned long nr) return false; } =20 -bool init_domheap_mappings(unsigned int cpu); - static inline void arch_setup_page_tables(void) { } diff --git a/xen/arch/arm/include/asm/domain_page.h b/xen/arch/arm/include/= asm/domain_page.h new file mode 100644 index 0000000000..e9f52685e2 --- /dev/null +++ b/xen/arch/arm/include/asm/domain_page.h @@ -0,0 +1,13 @@ +#ifndef __ASM_ARM_DOMAIN_PAGE_H__ +#define __ASM_ARM_DOMAIN_PAGE_H__ + +#ifdef CONFIG_ARCH_MAP_DOMAIN_PAGE +bool init_domheap_mappings(unsigned int cpu); +#else +static inline bool init_domheap_mappings(unsigned int cpu) +{ + return true; +} +#endif + +#endif /* __ASM_ARM_DOMAIN_PAGE_H__ */ diff --git a/xen/arch/arm/include/asm/mm.h b/xen/arch/arm/include/asm/mm.h index 9a94d7eaf7..a76578a16f 100644 --- a/xen/arch/arm/include/asm/mm.h +++ b/xen/arch/arm/include/asm/mm.h @@ -2,6 +2,9 @@ #define __ARCH_ARM_MM__ =20 #include +#include + +#include #include #include #include diff --git a/xen/arch/arm/include/asm/mmu/mm.h b/xen/arch/arm/include/asm/m= mu/mm.h index c5e03a66bf..c03c3a51e4 100644 --- a/xen/arch/arm/include/asm/mmu/mm.h +++ b/xen/arch/arm/include/asm/mmu/mm.h @@ -2,6 +2,8 @@ #ifndef __ARM_MMU_MM_H__ #define __ARM_MMU_MM_H__ =20 +DECLARE_PER_CPU(lpae_t *, xen_pgtable); + /* Non-boot CPUs use this to find the correct pagetables. */ extern uint64_t init_ttbr; =20 diff --git a/xen/arch/arm/mmu/pt.c b/xen/arch/arm/mmu/pt.c index a7755728ae..e772ab4e66 100644 --- a/xen/arch/arm/mmu/pt.c +++ b/xen/arch/arm/mmu/pt.c @@ -606,9 +606,9 @@ static int xen_pt_update(unsigned long virt, unsigned long left =3D nr_mfns; =20 /* - * For arm32, page-tables are different on each CPUs. Yet, they share - * some common mappings. It is assumed that only common mappings - * will be modified with this function. + * Page-tables are different on each CPU. Yet, they share some common + * mappings. It is assumed that only common mappings will be modified + * with this function. * * XXX: Add a check. */ diff --git a/xen/arch/arm/mmu/setup.c b/xen/arch/arm/mmu/setup.c index 57f1b46499..8c81e26da3 100644 --- a/xen/arch/arm/mmu/setup.c +++ b/xen/arch/arm/mmu/setup.c @@ -26,17 +26,15 @@ * PCPUs. */ =20 -#ifdef CONFIG_ARM_64 -DEFINE_PAGE_TABLE(xen_pgtable); -static DEFINE_PAGE_TABLE(xen_first); -#define THIS_CPU_PGTABLE xen_pgtable -#else /* Per-CPU pagetable pages */ /* xen_pgtable =3D=3D root of the trie (zeroeth level on 64-bit, first on = 32-bit) */ DEFINE_PER_CPU(lpae_t *, xen_pgtable); #define THIS_CPU_PGTABLE this_cpu(xen_pgtable) /* Root of the trie for cpu0, other CPU's PTs are dynamically allocated */ static DEFINE_PAGE_TABLE(cpu0_pgtable); + +#ifdef CONFIG_ARM_64 +static DEFINE_PAGE_TABLE(xen_first); #endif =20 /* Common pagetable leaves */ @@ -228,19 +226,22 @@ void __init setup_pagetables(unsigned long boot_phys_= offset) lpae_t pte, *p; int i; =20 + p =3D cpu0_pgtable; + phys_offset =3D boot_phys_offset; =20 + /* arch_setup_page_tables() may need to access the root page-tables. */ + per_cpu(xen_pgtable, 0) =3D cpu0_pgtable; + arch_setup_page_tables(); =20 #ifdef CONFIG_ARM_64 pte =3D pte_of_xenaddr((uintptr_t)xen_first); pte.pt.table =3D 1; pte.pt.xn =3D 0; - xen_pgtable[zeroeth_table_offset(XEN_VIRT_START)] =3D pte; + p[zeroeth_table_offset(XEN_VIRT_START)] =3D pte; =20 - p =3D (void *) xen_first; -#else - p =3D (void *) cpu0_pgtable; + p =3D xen_first; #endif =20 /* Map xen second level page-table */ @@ -283,19 +284,11 @@ void __init setup_pagetables(unsigned long boot_phys_= offset) pte.pt.table =3D 1; xen_second[second_table_offset(FIXMAP_ADDR(0))] =3D pte; =20 -#ifdef CONFIG_ARM_64 - ttbr =3D (uintptr_t) xen_pgtable + phys_offset; -#else ttbr =3D (uintptr_t) cpu0_pgtable + phys_offset; -#endif =20 switch_ttbr(ttbr); =20 xen_pt_enforce_wnx(); - -#ifdef CONFIG_ARM_32 - per_cpu(xen_pgtable, 0) =3D cpu0_pgtable; -#endif } =20 void *__init arch_vmap_virt_end(void) diff --git a/xen/arch/arm/mmu/smpboot.c b/xen/arch/arm/mmu/smpboot.c index fb5df667ba..fdd9b9c580 100644 --- a/xen/arch/arm/mmu/smpboot.c +++ b/xen/arch/arm/mmu/smpboot.c @@ -7,6 +7,7 @@ =20 #include =20 +#include #include =20 /* @@ -68,20 +69,6 @@ static void clear_boot_pagetables(void) clear_table(boot_third); } =20 -#ifdef CONFIG_ARM_64 -int prepare_secondary_mm(int cpu) -{ - clear_boot_pagetables(); - - /* - * Set init_ttbr for this CPU coming up. All CPUs share a single setof - * pagetables, but rewrite it each time for consistency with 32 bit. - */ - init_ttbr =3D virt_to_maddr(xen_pgtable); - clean_dcache(init_ttbr); - return 0; -} -#else int prepare_secondary_mm(int cpu) { lpae_t *root =3D alloc_xenheap_page(); @@ -112,7 +99,6 @@ int prepare_secondary_mm(int cpu) =20 return 0; } -#endif =20 /* * Local variables: diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index 7e28f62d09..3dec365c57 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include --=20 2.40.1 From nobody Thu May 9 13:57:19 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=1705433383; cv=none; d=zohomail.com; s=zohoarc; b=mBcyBrDmuZseroZ9qfuuhuojojB7unNoiM7tCGOdWfiwqDtxZrFvZ1ZNRASJDaQnIl1Z53FsmkYG3POj/3pJDKBj9uZZq5D3K9af2y/juMaoBHVmb2RNFh9v3K1RUkp3ES15EDgxvVNjh55oDlnatKhvLL+SN35dBZde+qYMmlY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705433383; 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=6yOB72LIvzh25UA84mj42X06HmCmvwf5nDXcH1vuudI=; b=SLSENjxQcVNfyyALpsHrMP3bWDNGqtlsNPs2/2A6CWYhjDLyCO1HQf0dW80wBbUyfjBnq4oGI7eyhtQ4SEBbCv+1QTwq1TfB7i9Oly0S9g6PBiHyd8wVLxCxSBuwawKMd7xqzOiETgKsBFZyfJK+JvlJ+rmqdEaU2yztV2BkkN8= 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 1705433383476792.5597668235822; Tue, 16 Jan 2024 11:29:43 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.668122.1040132 (Exim 4.92) (envelope-from ) id 1rPp7s-0005fU-MK; Tue, 16 Jan 2024 19:29:32 +0000 Received: by outflank-mailman (output) from mailman id 668122.1040132; Tue, 16 Jan 2024 19:29:32 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rPp7s-0005fN-II; Tue, 16 Jan 2024 19:29:32 +0000 Received: by outflank-mailman (input) for mailman id 668122; Tue, 16 Jan 2024 19:29:31 +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 1rPp5a-0003Xv-1H for xen-devel@lists.xenproject.org; Tue, 16 Jan 2024 19:27:10 +0000 Received: from smtp-fw-52005.amazon.com (smtp-fw-52005.amazon.com [52.119.213.156]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 3ca3be4e-b4a5-11ee-98f1-6d05b1d4d9a1; Tue, 16 Jan 2024 20:27:08 +0100 (CET) Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-pdx-2c-m6i4x-5eae960a.us-west-2.amazon.com) ([10.43.8.6]) by smtp-border-fw-52005.iad7.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jan 2024 19:27:06 +0000 Received: from smtpout.prod.us-east-1.prod.farcaster.email.amazon.dev (pdx2-ws-svc-p26-lb5-vlan2.pdx.amazon.com [10.39.38.66]) by email-inbound-relay-pdx-2c-m6i4x-5eae960a.us-west-2.amazon.com (Postfix) with ESMTPS id C58DB40E7C; Tue, 16 Jan 2024 19:27:05 +0000 (UTC) Received: from EX19MTAUEC002.ant.amazon.com [10.0.0.204:13937] by smtpin.naws.us-east-1.prod.farcaster.email.amazon.dev [10.0.28.244:2525] with esmtp (Farcaster) id f4cc082f-6bf2-4561-bb03-afd074cc6998; Tue, 16 Jan 2024 19:27:05 +0000 (UTC) Received: from EX19D008UEC004.ant.amazon.com (10.252.135.170) by EX19MTAUEC002.ant.amazon.com (10.252.135.253) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 16 Jan 2024 19:26:47 +0000 Received: from EX19MTAUEB001.ant.amazon.com (10.252.135.35) by EX19D008UEC004.ant.amazon.com (10.252.135.170) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 16 Jan 2024 19:26:47 +0000 Received: from dev-dsk-eliasely-1a-fd74790f.eu-west-1.amazon.com (10.253.91.118) by mail-relay.amazon.com (10.252.135.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40 via Frontend Transport; Tue, 16 Jan 2024 19:26:46 +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 Sender: "Xen-devel" X-Inumbo-ID: 3ca3be4e-b4a5-11ee-98f1-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1705433229; x=1736969229; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6yOB72LIvzh25UA84mj42X06HmCmvwf5nDXcH1vuudI=; b=ZI+I5rjO70K82kL7PhCaGam8F1N9zmmPhPtfdv6CBAzBpzHdUsB5TWAl O+uDDuKciCpu5c9ZE7H4vr/aYhIighqXW1v26kDbD2cTH0vEPWSG/sN/N qI7br2SsT++C6riMOuIHWVb8iqIHLHkpnlnIUzYRfSxw/fw/H0k8seJCe g=; X-IronPort-AV: E=Sophos;i="6.05,200,1701129600"; d="scan'208";a="627983742" X-Farcaster-Flow-ID: f4cc082f-6bf2-4561-bb03-afd074cc6998 From: Elias El Yandouzi To: CC: , , , Julien Grall , Stefano Stabellini , "Bertrand Marquis" , Michal Orzel , Volodymyr Babchuk , Elias El Yandouzi Subject: [PATCH v2 (resend) 26/27] xen/arm64: Implement a mapcache for arm64 Date: Tue, 16 Jan 2024 19:26:10 +0000 Message-ID: <20240116192611.41112-27-eliasely@amazon.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240116192611.41112-1-eliasely@amazon.com> References: <20240116192611.41112-1-eliasely@amazon.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: Bulk X-ZohoMail-DKIM: pass (identity @amazon.com) X-ZM-MESSAGEID: 1705433384491100001 Content-Type: text/plain; charset="utf-8" From: Julien Grall At the moment, on arm64, map_domain_page() is implemented using virt_to_mfn(). Therefore it is relying on the directmap. In a follow-up patch, we will allow the admin to remove the directmap. Therefore we want to implement a mapcache. Thanksfully there is already one for arm32. So select ARCH_ARM_DOMAIN_PAGE and add the necessary boiler plate to support 64-bit: - The page-table start at level 0, so we need to allocate the level 1 page-table - map_domain_page() should check if the page is in the directmap. If yes, then use virt_to_mfn() to limit the performance impact when the directmap is still enabled (this will be selectable on the command line). Take the opportunity to replace first_table_offset(...) with offsets[...]. Note that, so far, arch_mfns_in_directmap() always return true on arm64. So the mapcache is not yet used. This will change in a follow-up patch. Signed-off-by: Julien Grall Signed-off-by: Elias El Yandouzi ---- There are a few TODOs: - It is becoming more critical to fix the mapcache implementation (this is not compliant with the Arm Arm) - Evaluate the performance diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig index 50e9bfae1a..278243f0d6 100644 --- a/xen/arch/arm/Kconfig +++ b/xen/arch/arm/Kconfig @@ -1,7 +1,6 @@ config ARM_32 def_bool y depends on "$(ARCH)" =3D "arm32" - select ARCH_MAP_DOMAIN_PAGE =20 config ARM_64 def_bool y @@ -12,6 +11,7 @@ config ARM_64 config ARM def_bool y select HAS_ALTERNATIVE + select ARCH_MAP_DOMAIN_PAGE select HAS_DEVICE_TREE select HAS_PASSTHROUGH select HAS_UBSAN diff --git a/xen/arch/arm/arm64/mmu/mm.c b/xen/arch/arm/arm64/mmu/mm.c index 4f339efb7b..f4a81aa705 100644 --- a/xen/arch/arm/arm64/mmu/mm.c +++ b/xen/arch/arm/arm64/mmu/mm.c @@ -4,6 +4,7 @@ #include #include =20 +#include #include #include =20 @@ -236,6 +237,14 @@ void __init setup_mm(void) setup_frametable_mappings(ram_start, ram_end); max_page =3D PFN_DOWN(ram_end); =20 + /* + * The allocators may need to use map_domain_page() (such as for + * scrubbing pages). So we need to prepare the domheap area first. + */ + if ( !init_domheap_mappings(smp_processor_id()) ) + panic("CPU%u: Unable to prepare the domheap page-tables\n", + smp_processor_id()); + init_staticmem_pages(); } =20 diff --git a/xen/arch/arm/domain_page.c b/xen/arch/arm/domain_page.c index ac2a6d0332..0f6ba48892 100644 --- a/xen/arch/arm/domain_page.c +++ b/xen/arch/arm/domain_page.c @@ -1,4 +1,5 @@ /* SPDX-License-Identifier: GPL-2.0-or-later */ +#include #include #include #include @@ -8,6 +9,8 @@ /* Override macros from asm/page.h to make them work with mfn_t */ #undef virt_to_mfn #define virt_to_mfn(va) _mfn(__virt_to_mfn(va)) +#undef mfn_to_virt +#define mfn_to_virt(va) __mfn_to_virt(mfn_x(mfn)) =20 /* cpu0's domheap page tables */ static DEFINE_PAGE_TABLES(cpu0_dommap, DOMHEAP_SECOND_PAGES); @@ -31,13 +34,30 @@ bool init_domheap_mappings(unsigned int cpu) { unsigned int order =3D get_order_from_pages(DOMHEAP_SECOND_PAGES); lpae_t *root =3D per_cpu(xen_pgtable, cpu); + lpae_t *first; unsigned int i, first_idx; lpae_t *domheap; mfn_t mfn; =20 + /* Convenience aliases */ + DECLARE_OFFSETS(offsets, DOMHEAP_VIRT_START); + ASSERT(root); ASSERT(!per_cpu(xen_dommap, cpu)); =20 + /* + * On Arm64, the root is at level 0. Therefore we need an extra step + * to allocate the first level page-table. + */ +#ifdef CONFIG_ARM_64 + if ( create_xen_table(&root[offsets[0]]) ) + return false; + + first =3D xen_map_table(lpae_get_mfn(root[offsets[0]])); +#else + first =3D root; +#endif + /* * The domheap for cpu0 is initialized before the heap is initialized. * So we need to use pre-allocated pages. @@ -58,16 +78,20 @@ bool init_domheap_mappings(unsigned int cpu) * domheap mapping pages. */ mfn =3D virt_to_mfn(domheap); - first_idx =3D first_table_offset(DOMHEAP_VIRT_START); + first_idx =3D offsets[1]; for ( i =3D 0; i < DOMHEAP_SECOND_PAGES; i++ ) { lpae_t pte =3D mfn_to_xen_entry(mfn_add(mfn, i), MT_NORMAL); pte.pt.table =3D 1; - write_pte(&root[first_idx + i], pte); + write_pte(&first[first_idx + i], pte); } =20 per_cpu(xen_dommap, cpu) =3D domheap; =20 +#ifdef CONFIG_ARM_64 + xen_unmap_table(first); +#endif + return true; } =20 @@ -91,6 +115,10 @@ void *map_domain_page(mfn_t mfn) lpae_t pte; int i, slot; =20 + /* Bypass the mapcache if the page is in the directmap */ + if ( arch_mfns_in_directmap(mfn_x(mfn), 1) ) + return mfn_to_virt(mfn); + local_irq_save(flags); =20 /* The map is laid out as an open-addressed hash table where each @@ -153,13 +181,25 @@ void *map_domain_page(mfn_t mfn) /* Release a mapping taken with map_domain_page() */ void unmap_domain_page(const void *ptr) { + unsigned long va =3D (unsigned long)ptr; unsigned long flags; lpae_t *map =3D this_cpu(xen_dommap); - int slot =3D ((unsigned long)ptr - DOMHEAP_VIRT_START) >> SECOND_SHIFT; + unsigned int slot; + + /* Below we assume that the domheap area doesn't start at 0 */ + BUILD_BUG_ON(DOMHEAP_VIRT_START =3D=3D 0); =20 - if ( !ptr ) + /* + * map_domain_page() may not have mapped anything if the address + * is part of the directmap. So ignore anything outside of the + * domheap. + */ + if ( (va < DOMHEAP_VIRT_START) || + ((va - DOMHEAP_VIRT_START) >=3D DOMHEAP_VIRT_SIZE) ) return; =20 + slot =3D (va - DOMHEAP_VIRT_START) >> SECOND_SHIFT; + local_irq_save(flags); =20 ASSERT(slot >=3D 0 && slot < DOMHEAP_ENTRIES); diff --git a/xen/arch/arm/include/asm/mm.h b/xen/arch/arm/include/asm/mm.h index a76578a16f..c48e51d827 100644 --- a/xen/arch/arm/include/asm/mm.h +++ b/xen/arch/arm/include/asm/mm.h @@ -432,6 +432,11 @@ static inline void page_set_xenheap_gfn(struct page_in= fo *p, gfn_t gfn) } while ( (y =3D cmpxchg(&p->u.inuse.type_info, x, nx)) !=3D x ); } =20 +/* Helpers to allocate, map and unmap a Xen page-table */ +int create_xen_table(lpae_t *entry); +lpae_t *xen_map_table(mfn_t mfn); +void xen_unmap_table(const lpae_t *table); + #endif /* __ARCH_ARM_MM__ */ /* * Local variables: diff --git a/xen/arch/arm/include/asm/mmu/layout.h b/xen/arch/arm/include/a= sm/mmu/layout.h index a3b546465b..c549420e8b 100644 --- a/xen/arch/arm/include/asm/mmu/layout.h +++ b/xen/arch/arm/include/asm/mmu/layout.h @@ -35,9 +35,13 @@ * * 32G - 64G Frametable: 56 bytes per page for 2TB of RAM * - * 0x00000a8000000000 - 0x00007fffffffffff (512GB+117TB, L0 slots [21..255= ]) + * 0x00000a8000000000 - 0x00007f7fffffffff (117TB, L0 slots [21..254]) * Unused * + * 0x00007f8000000000 - 0x00007fffffffffff (512GB, L0 slot [255]) + * (Relative offsets) + * 0 - 2G Domheap: on-demand-mapped + * * 0x0000800000000000 - 0x000084ffffffffff (5TB, L0 slots [256..265]) * 1:1 mapping of RAM * @@ -130,6 +134,13 @@ #define FRAMETABLE_SIZE GB(32) #define FRAMETABLE_NR (FRAMETABLE_SIZE / sizeof(*frame_table)) =20 +#define DOMHEAP_VIRT_START SLOT0(255) +#define DOMHEAP_VIRT_SIZE GB(2) + +#define DOMHEAP_ENTRIES 1024 /* 1024 2MB mapping slots */ +/* Number of domheap pagetable pages required at the second level (2MB map= pings) */ +#define DOMHEAP_SECOND_PAGES (DOMHEAP_VIRT_SIZE >> FIRST_SHIFT) + #define DIRECTMAP_VIRT_START SLOT0(256) #define DIRECTMAP_SIZE (SLOT0_ENTRY_SIZE * (266 - 256)) #define DIRECTMAP_VIRT_END (DIRECTMAP_VIRT_START + DIRECTMAP_SIZE - 1) diff --git a/xen/arch/arm/mmu/pt.c b/xen/arch/arm/mmu/pt.c index e772ab4e66..f26b1412be 100644 --- a/xen/arch/arm/mmu/pt.c +++ b/xen/arch/arm/mmu/pt.c @@ -32,7 +32,7 @@ mm_printk(const char *fmt, ...) {} #define HYP_PT_ROOT_LEVEL 1 #endif =20 -static lpae_t *xen_map_table(mfn_t mfn) +lpae_t *xen_map_table(mfn_t mfn) { /* * During early boot, map_domain_page() may be unusable. Use the @@ -44,7 +44,7 @@ static lpae_t *xen_map_table(mfn_t mfn) return map_domain_page(mfn); } =20 -static void xen_unmap_table(const lpae_t *table) +void xen_unmap_table(const lpae_t *table) { /* * During early boot, xen_map_table() will not use map_domain_page() @@ -227,7 +227,7 @@ void *ioremap(paddr_t pa, size_t len) return ioremap_attr(pa, len, PAGE_HYPERVISOR_NOCACHE); } =20 -static int create_xen_table(lpae_t *entry) +int create_xen_table(lpae_t *entry) { mfn_t mfn; void *p; --=20 2.40.1 From nobody Thu May 9 13:57:19 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=1705434019; cv=none; d=zohomail.com; s=zohoarc; b=mo8F6Rli0FxvCHW7OEMI/U9fnMcLqkxGbaAmpstKCiT43ueEUD4kTp50Zwq88q9HGRvMhOeaPYe+9TAKxgBS8RVoR/boqhmd5ZfJDx6PEz2Gk9muS4NUyE6q/rbzqMLptVbzF8R0wwe4Uz/Hujv0GwJrxtamHfSfEKxsawudNR0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705434019; 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=bXzdRNb+zZSWrMCWDYUPYL1ZiOjiL92dtef2XmbIpMo=; b=br06cwZx+149jKYBB2osXfaFfLCSuDnDh2zvevVGCRqcaBw4wSHFiYSpxulEmSBXyPiZVcoKeOSIxGcdZKRVMd2ahjGINdmPYGmxWbzfOXyT/cqDq+IlD/GM+S/AzzOHoQ8mVrtDkP69LSqKflcNAB3mrWDGa2vRk7QbmSva+sk= 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 1705434019216905.8106781788953; Tue, 16 Jan 2024 11:40:19 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.668171.1040191 (Exim 4.92) (envelope-from ) id 1rPpHz-0006hx-SH; Tue, 16 Jan 2024 19:39:59 +0000 Received: by outflank-mailman (output) from mailman id 668171.1040191; Tue, 16 Jan 2024 19:39:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rPpHz-0006ho-PM; Tue, 16 Jan 2024 19:39:59 +0000 Received: by outflank-mailman (input) for mailman id 668171; Tue, 16 Jan 2024 19:39:58 +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 1rPp5X-0003Xv-Jh for xen-devel@lists.xenproject.org; Tue, 16 Jan 2024 19:27:07 +0000 Received: from smtp-fw-52004.amazon.com (smtp-fw-52004.amazon.com [52.119.213.154]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 3b08b66f-b4a5-11ee-98f1-6d05b1d4d9a1; Tue, 16 Jan 2024 20:27:06 +0100 (CET) Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-iad-1d-m6i4x-25ac6bd5.us-east-1.amazon.com) ([10.43.8.2]) by smtp-border-fw-52004.iad7.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jan 2024 19:27:05 +0000 Received: from smtpout.prod.us-east-1.prod.farcaster.email.amazon.dev (iad7-ws-svc-p70-lb3-vlan2.iad.amazon.com [10.32.235.34]) by email-inbound-relay-iad-1d-m6i4x-25ac6bd5.us-east-1.amazon.com (Postfix) with ESMTPS id 2875E49E4D; Tue, 16 Jan 2024 19:27:01 +0000 (UTC) Received: from EX19MTAUEB002.ant.amazon.com [10.0.29.78:45873] by smtpin.naws.us-east-1.prod.farcaster.email.amazon.dev [10.0.95.118:2525] with esmtp (Farcaster) id 98f57ce2-9333-45bc-9ae3-0f84349af0f9; Tue, 16 Jan 2024 19:27:00 +0000 (UTC) Received: from EX19D008UEC004.ant.amazon.com (10.252.135.170) by EX19MTAUEB002.ant.amazon.com (10.252.135.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 16 Jan 2024 19:26:48 +0000 Received: from EX19MTAUEB001.ant.amazon.com (10.252.135.35) by EX19D008UEC004.ant.amazon.com (10.252.135.170) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 16 Jan 2024 19:26:48 +0000 Received: from dev-dsk-eliasely-1a-fd74790f.eu-west-1.amazon.com (10.253.91.118) by mail-relay.amazon.com (10.252.135.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40 via Frontend Transport; Tue, 16 Jan 2024 19:26:47 +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 Sender: "Xen-devel" X-Inumbo-ID: 3b08b66f-b4a5-11ee-98f1-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1705433227; x=1736969227; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=bXzdRNb+zZSWrMCWDYUPYL1ZiOjiL92dtef2XmbIpMo=; b=Q8AvmtJf4ZsrgXTlelbv8j5FR3wVday9zQQ/PGbrpdid0DMyGTRSNuaJ zXd9J3hXeDYPKB7o5zfpZu/Bu6/IFhUSMSbPwutQbHKToqs9qCfgU2mC3 rPwh6fDrxcRjT+hTCnbRodHB2IbSCkppQUgHc23AZd8nuPU6qBjvk68HV s=; X-IronPort-AV: E=Sophos;i="6.05,200,1701129600"; d="scan'208";a="178399576" X-Farcaster-Flow-ID: 98f57ce2-9333-45bc-9ae3-0f84349af0f9 From: Elias El Yandouzi To: CC: , , , Julien Grall , Andrew Cooper , George Dunlap , Jan Beulich , "Stefano Stabellini" , Wei Liu , Bertrand Marquis , Michal Orzel , "Volodymyr Babchuk" , Elias El Yandouzi Subject: [PATCH v2 (resend) 27/27] xen/arm64: Allow the admin to enable/disable the directmap Date: Tue, 16 Jan 2024 19:26:11 +0000 Message-ID: <20240116192611.41112-28-eliasely@amazon.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240116192611.41112-1-eliasely@amazon.com> References: <20240116192611.41112-1-eliasely@amazon.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: Bulk X-ZohoMail-DKIM: pass (identity @amazon.com) X-ZM-MESSAGEID: 1705434021177100001 Content-Type: text/plain; charset="utf-8" From: Julien Grall Implement the same command line option as x86 to enable/disable the directmap. By default this is kept enabled. Also modify setup_directmap_mappings() to populate the L0 entries related to the directmap area. Signed-off-by: Julien Grall Signed-off-by: Elias El Yandouzi ---- Changes in v2: * Rely on the Kconfig option to enable Secret Hiding on Arm64 * Use generic helper instead of arch_has_directmap() diff --git a/docs/misc/xen-command-line.pandoc b/docs/misc/xen-command-line= .pandoc index 63c946f482..df90b1c4c9 100644 --- a/docs/misc/xen-command-line.pandoc +++ b/docs/misc/xen-command-line.pandoc @@ -799,7 +799,7 @@ that enabling this option cannot guarantee anything bey= ond what underlying hardware guarantees (with, where available and known to Xen, respective tweaks applied). =20 -### directmap (x86) +### directmap (arm64, x86) > `=3D ` =20 > Default: `true` diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig index 278243f0d6..7a19826233 100644 --- a/xen/arch/arm/Kconfig +++ b/xen/arch/arm/Kconfig @@ -7,6 +7,7 @@ config ARM_64 depends on !ARM_32 select 64BIT select HAS_FAST_MULTIPLY + select HAS_SECRET_HIDING =20 config ARM def_bool y diff --git a/xen/arch/arm/arm64/mmu/mm.c b/xen/arch/arm/arm64/mmu/mm.c index f4a81aa705..22e1e5b9f4 100644 --- a/xen/arch/arm/arm64/mmu/mm.c +++ b/xen/arch/arm/arm64/mmu/mm.c @@ -157,16 +157,27 @@ void __init switch_ttbr(uint64_t ttbr) update_identity_mapping(false); } =20 -/* Map the region in the directmap area. */ +/* + * This either populate a valid fdirect map, or allocates empty L1 tables + * and creates the L0 entries for the given region in the direct map + * depending on has_directmap(). + * + * When directmap=3Dno, we still need to populate empty L1 tables in the + * directmap region. The reason is that the root page-table (i.e. L0) + * is per-CPU and secondary CPUs will initialize their root page-table + * based on the pCPU0 one. So L0 entries will be shared if they are + * pre-populated. We also rely on the fact that L1 tables are never + * freed. + */ static void __init setup_directmap_mappings(unsigned long base_mfn, unsigned long nr_mfns) { + unsigned long mfn_gb =3D base_mfn & ~((FIRST_SIZE >> PAGE_SHIFT) - 1); int rc; =20 /* First call sets the directmap physical and virtual offset. */ if ( mfn_eq(directmap_mfn_start, INVALID_MFN) ) { - unsigned long mfn_gb =3D base_mfn & ~((FIRST_SIZE >> PAGE_SHIFT) -= 1); =20 directmap_mfn_start =3D _mfn(base_mfn); directmap_base_pdx =3D mfn_to_pdx(_mfn(base_mfn)); @@ -187,6 +198,24 @@ static void __init setup_directmap_mappings(unsigned l= ong base_mfn, panic("cannot add directmap mapping at %lx below heap start %lx\n", base_mfn, mfn_x(directmap_mfn_start)); =20 + if ( !has_directmap() ) + { + vaddr_t vaddr =3D (vaddr_t)__mfn_to_virt(base_mfn); + lpae_t *root =3D this_cpu(xen_pgtable); + unsigned int i, slot; + + slot =3D first_table_offset(vaddr); + nr_mfns +=3D base_mfn - mfn_gb; + for ( i =3D 0; i < nr_mfns; i +=3D BIT(XEN_PT_LEVEL_ORDER(0), UL),= slot++ ) + { + lpae_t *entry =3D &root[slot]; + + if ( !lpae_is_valid(*entry) && !create_xen_table(entry) ) + panic("Unable to populate zeroeth slot %u\n", slot); + } + return; + } + rc =3D map_pages_to_xen((vaddr_t)__mfn_to_virt(base_mfn), _mfn(base_mfn), nr_mfns, PAGE_HYPERVISOR_RW | _PAGE_BLOCK); diff --git a/xen/arch/arm/include/asm/arm64/mm.h b/xen/arch/arm/include/asm= /arm64/mm.h index e0bd23a6ed..5888f29159 100644 --- a/xen/arch/arm/include/asm/arm64/mm.h +++ b/xen/arch/arm/include/asm/arm64/mm.h @@ -3,13 +3,10 @@ =20 extern DEFINE_PAGE_TABLE(xen_pgtable); =20 -/* - * On ARM64, all the RAM is currently direct mapped in Xen. - * Hence return always true. - */ +/* On Arm64, the user can chose whether all the RAM is directmap. */ static inline bool arch_mfns_in_directmap(unsigned long mfn, unsigned long= nr) { - return true; + return has_directmap(); } =20 void arch_setup_page_tables(void); diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index b15a18a494..7fb75c5c3e 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -12,6 +12,7 @@ #include #include #include +#include =20 #include =20 diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index 3dec365c57..2bd060d321 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -748,6 +748,7 @@ void asmlinkage __init start_xen(unsigned long boot_phy= s_offset, cmdline_parse(cmdline); =20 setup_mm(); + printk("Booting with directmap %s\n", has_directmap() ? "on" : "off"); =20 vm_init(); =20 --=20 2.40.1