From nobody Sat Nov 23 13:11:38 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=1731330783; cv=none; d=zohomail.com; s=zohoarc; b=Tbv77F6mrgtDJEyjrW+fL5hBvr3xQXRjgpMduDimAc3H3hD9fVsxu1NyfUqIWZN00w/KEx3IQ+EeF3vO1g2dLe6ceb6P6o+fIefVNtSUjl+tsmuatJnlg5GvqelFRE9x/BuFmhnt6G894MCjMqifI94TO3FCCUCQirFp2FVbQ7E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1731330783; 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=mafc3TENeclkrMcyk4CrldzkIWqGpdnNkd3t+61vW/E=; b=NG0fcB9M/9HsT1q4KI40X71Dhdo7XNKCtB4ddYlL671owtsVgisM79+mxe7qqEefb8UdVwVyBKvycT5fkwVEX1OGX5PJDzX/RnfFd85WyBmpRUhQ2iWCe6jypriQ4tX5D/ciwH0USItvyCs8rhU8qif1YNASdflZTXbSftOd15Q= 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 1731330783813638.6120079206173; Mon, 11 Nov 2024 05:13:03 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.833746.1249055 (Exim 4.92) (envelope-from ) id 1tAUDQ-0002v7-JD; Mon, 11 Nov 2024 13:12:24 +0000 Received: by outflank-mailman (output) from mailman id 833746.1249055; Mon, 11 Nov 2024 13:12:24 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tAUDQ-0002tk-2s; Mon, 11 Nov 2024 13:12:24 +0000 Received: by outflank-mailman (input) for mailman id 833746; Mon, 11 Nov 2024 13:12:22 +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 1tAUDO-0007pD-NL for xen-devel@lists.xenproject.org; Mon, 11 Nov 2024 13:12:22 +0000 Received: from smtp-fw-80007.amazon.com (smtp-fw-80007.amazon.com [99.78.197.218]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 939511ca-a02e-11ef-99a3-01e77a169b0f; Mon, 11 Nov 2024 14:12:19 +0100 (CET) Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO smtpout.prod.us-east-1.prod.farcaster.email.amazon.dev) ([10.25.36.210]) by smtp-border-fw-80007.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Nov 2024 13:12:16 +0000 Received: from EX19MTAUEA001.ant.amazon.com [10.0.44.209:40485] by smtpin.naws.us-east-1.prod.farcaster.email.amazon.dev [10.0.25.25:2525] with esmtp (Farcaster) id 97ed0e1a-4327-40d7-bc26-7f3f8399d6bf; Mon, 11 Nov 2024 13:12:15 +0000 (UTC) Received: from EX19D008UEC002.ant.amazon.com (10.252.135.242) by EX19MTAUEA001.ant.amazon.com (10.252.134.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34; Mon, 11 Nov 2024 13:12:15 +0000 Received: from EX19MTAUWA002.ant.amazon.com (10.250.64.202) by EX19D008UEC002.ant.amazon.com (10.252.135.242) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34; Mon, 11 Nov 2024 13:12:15 +0000 Received: from email-imr-corp-prod-pdx-all-2b-5ec155c2.us-west-2.amazon.com (10.25.36.210) by mail-relay.amazon.com (10.250.64.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34 via Frontend Transport; Mon, 11 Nov 2024 13:12:15 +0000 Received: from dev-dsk-eliasely-1a-fd74790f.eu-west-1.amazon.com (dev-dsk-eliasely-1a-fd74790f.eu-west-1.amazon.com [10.253.91.118]) by email-imr-corp-prod-pdx-all-2b-5ec155c2.us-west-2.amazon.com (Postfix) with ESMTPS id 447F942116; Mon, 11 Nov 2024 13:12:14 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 939511ca-a02e-11ef-99a3-01e77a169b0f X-Custom-Connection: eyJyZW1vdGVpcCI6Ijk5Ljc4LjE5Ny4yMTgiLCJoZWxvIjoic210cC1mdy04MDAwNy5hbWF6b24uY29tIn0= X-Custom-Transaction: eyJpZCI6IjkzOTUxMWNhLWEwMmUtMTFlZi05OWEzLTAxZTc3YTE2OWIwZiIsInRzIjoxNzMxMzMwNzM5LjYyODcxMSwic2VuZGVyIjoicHJ2cz0wMzhkMjZkMGM9ZWxpYXNlbHlAYW1hem9uLmNvLnVrIiwicmVjaXBpZW50IjoieGVuLWRldmVsQGxpc3RzLnhlbnByb2plY3Qub3JnIn0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1731330739; x=1762866739; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mafc3TENeclkrMcyk4CrldzkIWqGpdnNkd3t+61vW/E=; b=GKnC4EPCipWpeBfG0JvFxOXfQAf0xaeRxkExpE5qzzP9LbV0R1BjU6kI MV9RJbuCPobmMSh2AyEtLRA23hit1G1OpwzOuNGvm0isUfxOB8RpuEsrB kXitmQYSIeiVs1ihl/PX+xUj7749CPcvEp2GY/iR0MqzRIwwi99x95CmC g=; X-IronPort-AV: E=Sophos;i="6.12,145,1728950400"; d="scan'208";a="351236520" X-Farcaster-Flow-ID: 97ed0e1a-4327-40d7-bc26-7f3f8399d6bf From: Elias El Yandouzi To: CC: , , , Julien Grall , Elias El Yandouzi Subject: [PATCH V4 15/15] xen/arm64: Allow the admin to enable/disable the directmap Date: Mon, 11 Nov 2024 13:11:48 +0000 Message-ID: <20241111131148.52568-16-eliasely@amazon.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20241111131148.52568-1-eliasely@amazon.com> References: <20241111131148.52568-1-eliasely@amazon.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @amazon.com) X-ZM-MESSAGEID: 1731330785014116600 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 10b0b2714661..c238b866061f 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 aa9e4c381c55..390fe3dd9ebf 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 d7cb3ad2da80..320e9efde93e 100644 --- a/xen/arch/arm/arm64/mmu/mm.c +++ b/xen/arch/arm/arm64/mmu/mm.c @@ -170,16 +170,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)); @@ -200,6 +211,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 b4f7545d2c87..2b1140a6b994 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 def939172cc5..0f3ffab6bab6 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 b33483b8eacf..2e0870dc8af6 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -328,6 +328,7 @@ void asmlinkage __init start_xen(unsigned long fdt_padd= r) cmdline_parse(cmdline); =20 setup_mm(); + printk("Booting with directmap %s\n", has_directmap() ? "on" : "off"); =20 vm_init(); =20 --=20 2.40.1