From patchwork Fri Mar 8 01:54:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Henry Wang X-Patchwork-Id: 13586423 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DE190C54798 for ; Fri, 8 Mar 2024 01:55:10 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.690076.1075744 (Exim 4.92) (envelope-from ) id 1riPRn-0002L5-V7; Fri, 08 Mar 2024 01:54:55 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 690076.1075744; Fri, 08 Mar 2024 01:54:55 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1riPRn-0002Ky-SW; Fri, 08 Mar 2024 01:54:55 +0000 Received: by outflank-mailman (input) for mailman id 690076; Fri, 08 Mar 2024 01:54:54 +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 1riPRm-000262-AL for xen-devel@lists.xenproject.org; Fri, 08 Mar 2024 01:54:54 +0000 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on20600.outbound.protection.outlook.com [2a01:111:f403:2412::600]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id dabc7394-dcee-11ee-a1ee-f123f15fe8a2; Fri, 08 Mar 2024 02:54:52 +0100 (CET) Received: from DM6PR10CA0002.namprd10.prod.outlook.com (2603:10b6:5:60::15) by SA0PR12MB7001.namprd12.prod.outlook.com (2603:10b6:806:2c0::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.24; Fri, 8 Mar 2024 01:54:47 +0000 Received: from CH3PEPF0000000D.namprd04.prod.outlook.com (2603:10b6:5:60:cafe::27) by DM6PR10CA0002.outlook.office365.com (2603:10b6:5:60::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.27 via Frontend Transport; Fri, 8 Mar 2024 01:54:47 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CH3PEPF0000000D.mail.protection.outlook.com (10.167.244.43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7362.11 via Frontend Transport; Fri, 8 Mar 2024 01:54:47 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 7 Mar 2024 19:54:46 -0600 Received: from henry-MS-7D54.amd.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Thu, 7 Mar 2024 19:54:44 -0600 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: dabc7394-dcee-11ee-a1ee-f123f15fe8a2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LrbOO0R3HbwVD8i17/u6NyTVrytsLJlqwJqo9h12AcfNq210pVfNaP9fTiTF2sGm/MJJVaSMw7uQpdG/al5Zt84NjgKwsHD0DeIRoPx7KBuhhzXVZ0fysQFwRmqHHd7R9Dhv0FYeVgrOxNwiKyBntTHx1iPZhU1JYvotco/WWwje0Iv46jk9xiYVXLHR7Ga7qjO42cbnUCiQpegOVkw6B2PKHz9MLTbSBJvXXVrSW8NWWjm5xg25S2QegpXK0b4Q42M37regoxg2jJ6GbGierOdqJ9eZfPrCC9DdDEo8xQ7ZqELEK87X5xhNzsfrr1fW027gCzxP6f36HOX0EBg51A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=t+i1Nrwfs3RtzHQxrkA9Q/UxYobRSCipIPuuOohcu4M=; b=OqD7j2+pBbQKSJemR7k5d7fNhk4BHfbtJzX39H/LLWeERTWwYpeuN7LASrzZN+IdjSj1/nvIA0ySHSdHYXP0+WGHixnemoakFkbkKRSaktPC3yM3lYrZTMGc+uIS9flWHv+ZLzHxlBQxHsO+Vt9XjvMZN4dHanld0g1gyxYYGopmT2xAB1bFaoXMQXBUOH7UR3smiDB2aV7moQfTAwWlMhdD0reDlD3z6m7NJpgTtv845DXKxvSBwXJwaBJre035ElDMxu/AXr3vzUIZ2zJ7kSFxB2g5gKvFLXfD2zEf0Z8Awe3XU9STeL80NFaBbVUenD1q4Zie8FVjO3Xte5AO+Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=t+i1Nrwfs3RtzHQxrkA9Q/UxYobRSCipIPuuOohcu4M=; b=4Ubdres3RNzCsVrJnpv5T9kC8Wp7I13Ear5jk3r4dht3aEp4yMgDZoC79ycuBu6q0Elu994q+Wd6c0Q9ybseKY2iZznlhrzEkU1Mo+3/QO2gkX6wbXRWMTitZacYV4Ro9aVdyn2mMXSL68uh+hZWlWozuG1Gmh2gzVKlnTka5Jk= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Henry Wang To: CC: Henry Wang , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , "Volodymyr Babchuk" Subject: [PATCH v2 1/5] xen/arm: Rename assign_static_memory_11() for consistency Date: Fri, 8 Mar 2024 09:54:31 +0800 Message-ID: <20240308015435.4044339-2-xin.wang2@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240308015435.4044339-1-xin.wang2@amd.com> References: <20240308015435.4044339-1-xin.wang2@amd.com> MIME-Version: 1.0 Received-SPF: None (SATLEXMB04.amd.com: xin.wang2@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PEPF0000000D:EE_|SA0PR12MB7001:EE_ X-MS-Office365-Filtering-Correlation-Id: d1e475ed-1378-433f-83c8-08dc3f12bbfa X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /9Q/4lcYBxbykpoXUM/fT/CW1Nrc89QJIVrrF1vK1MD9RWhgqn8Czd1FQRckfhiTjT5oMjJWfwzcVpAsn74AQrVXtoVlvpe0FNGxbQS4c8rcAFI48GiNVVR3HvF3X9VoxLYyKgihEYb9d7ngp5Gn8/lPYKLd+Cc/nMEPcYtftDgxZMRqxjbpod8GQnnUvnzeSmvxBqZlTx+K5mEDLCXAoJmM/wGPHk1kmcAevX92uj7xM3GAb2z5bYJ9/UMmW01I1Jcn88DPKHPjbhGLS1hm4MfEKur8mgO/LETPUhyITGG2laF8WYOgLw0QaYNQQHbXTVsRl5KsUcRtS8j9magy2WpFE1hAcQap/1gVp+i0wM+xxWNvfmXAxBv+9kOaWXG5nh+p0JYYzXPwKLWYd/WOIxqduijE1HpyisxVUk8+SI8ee6wMQzwVUti7PwICRf9KYwDp1OK7Dl4DI8CpQc+nzLJkssABVIxiY4LgO9WmQvreKJJYdJccagS2y4DXrPdtCXO2lo3tp9jZY+/8ckqz2wZpWmHKd0ghwfAo5/Xq/M4WDHknfbQmg3WJqogvt6IhF82TS2FHiWjUPSzEhTARKsxazmottxusBJE4HEmQGaT+vyZncyJn1s8NA8Ilg6ciztDQ+Yi7W++xN0WoXS0NOxzfTS1Y7xsTwpMfYtoht8Q16f+DZOIDP+Vvu3IvcP0l1dH0XJGALP/1j9565/3eDp3Ymhoid/wJRuHJSjGh2JuVkByYKuiaDwG5vAYwWZuh X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(1800799015)(82310400014)(376005)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Mar 2024 01:54:47.4861 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d1e475ed-1378-433f-83c8-08dc3f12bbfa X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CH3PEPF0000000D.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB7001 Currently on Arm there are 4 functions to allocate memory as domain RAM at boot time for different types of domains: (1) allocate_memory(): To allocate memory for Dom0less DomUs that do not use static memory. (2) allocate_static_memory(): To allocate memory for Dom0less DomUs that use static memory. (3) allocate_memory_11(): To allocate memory for Dom0. (4) assign_static_memory_11(): To allocate memory for Dom0less DomUs that use static memory and directmapped. To keep consistency between the names and the in-code comment on top of the functions, rename assign_static_memory_11() to allocate_static_memory_11(). No functional change intended. Signed-off-by: Henry Wang --- v2: - New patch --- xen/arch/arm/dom0less-build.c | 2 +- xen/arch/arm/include/asm/static-memory.h | 8 ++++---- xen/arch/arm/static-memory.c | 5 +++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/xen/arch/arm/dom0less-build.c b/xen/arch/arm/dom0less-build.c index fb63ec6fd1..1e1c8d83ae 100644 --- a/xen/arch/arm/dom0less-build.c +++ b/xen/arch/arm/dom0less-build.c @@ -806,7 +806,7 @@ static int __init construct_domU(struct domain *d, else if ( !is_domain_direct_mapped(d) ) allocate_static_memory(d, &kinfo, node); else - assign_static_memory_11(d, &kinfo, node); + allocate_static_memory_11(d, &kinfo, node); rc = process_shm(d, &kinfo, node); if ( rc < 0 ) diff --git a/xen/arch/arm/include/asm/static-memory.h b/xen/arch/arm/include/asm/static-memory.h index 3e3efd70c3..667e6d3804 100644 --- a/xen/arch/arm/include/asm/static-memory.h +++ b/xen/arch/arm/include/asm/static-memory.h @@ -9,7 +9,7 @@ void allocate_static_memory(struct domain *d, struct kernel_info *kinfo, const struct dt_device_node *node); -void assign_static_memory_11(struct domain *d, struct kernel_info *kinfo, +void allocate_static_memory_11(struct domain *d, struct kernel_info *kinfo, const struct dt_device_node *node); void init_staticmem_pages(void); @@ -22,9 +22,9 @@ static inline void allocate_static_memory(struct domain *d, ASSERT_UNREACHABLE(); } -static inline void assign_static_memory_11(struct domain *d, - struct kernel_info *kinfo, - const struct dt_device_node *node) +static inline void allocate_static_memory_11(struct domain *d, + struct kernel_info *kinfo, + const struct dt_device_node *node) { ASSERT_UNREACHABLE(); } diff --git a/xen/arch/arm/static-memory.c b/xen/arch/arm/static-memory.c index cffbab7241..20333a7f94 100644 --- a/xen/arch/arm/static-memory.c +++ b/xen/arch/arm/static-memory.c @@ -187,8 +187,9 @@ void __init allocate_static_memory(struct domain *d, struct kernel_info *kinfo, * The static memory will be directly mapped in the guest(Guest Physical * Address == Physical Address). */ -void __init assign_static_memory_11(struct domain *d, struct kernel_info *kinfo, - const struct dt_device_node *node) +void __init allocate_static_memory_11(struct domain *d, + struct kernel_info *kinfo, + const struct dt_device_node *node) { u32 addr_cells, size_cells, reg_cells; unsigned int nr_banks, bank = 0; From patchwork Fri Mar 8 01:54:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Henry Wang X-Patchwork-Id: 13586425 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0ED57C54E4A for ; Fri, 8 Mar 2024 01:55:12 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.690077.1075755 (Exim 4.92) (envelope-from ) id 1riPRs-0002bu-72; Fri, 08 Mar 2024 01:55:00 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 690077.1075755; Fri, 08 Mar 2024 01:55:00 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1riPRs-0002bl-3x; Fri, 08 Mar 2024 01:55:00 +0000 Received: by outflank-mailman (input) for mailman id 690077; Fri, 08 Mar 2024 01:54: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 1riPRq-0002aR-DV for xen-devel@lists.xenproject.org; Fri, 08 Mar 2024 01:54:58 +0000 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on20601.outbound.protection.outlook.com [2a01:111:f403:200a::601]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id dd69a49a-dcee-11ee-afda-a90da7624cb6; Fri, 08 Mar 2024 02:54:57 +0100 (CET) Received: from CH0PR03CA0057.namprd03.prod.outlook.com (2603:10b6:610:b3::32) by LV2PR12MB5944.namprd12.prod.outlook.com (2603:10b6:408:14f::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.26; Fri, 8 Mar 2024 01:54:53 +0000 Received: from CH3PEPF00000009.namprd04.prod.outlook.com (2603:10b6:610:b3:cafe::83) by CH0PR03CA0057.outlook.office365.com (2603:10b6:610:b3::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7339.37 via Frontend Transport; Fri, 8 Mar 2024 01:54:53 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CH3PEPF00000009.mail.protection.outlook.com (10.167.244.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7362.11 via Frontend Transport; Fri, 8 Mar 2024 01:54:52 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 7 Mar 2024 19:54:51 -0600 Received: from henry-MS-7D54.amd.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Thu, 7 Mar 2024 19:54:48 -0600 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: dd69a49a-dcee-11ee-afda-a90da7624cb6 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GSs6ZcY4ffWJ1SQDXMRasVmV/zSNHo7EaKF/09azEe7oYUggQnqd1cZUL4iSQcoKRP40SUZsNks1hNOncxJtXZv7pM62himqUOtEALk7mcBVysjpDPasdvFBMbtIDP7Rga64nZEbjFJC9uzTuv43WoOXgatCzDesbVzS1x7g9jxixfeBAZXhvw0QHIimZ0+kst/AD+I+SetOOTTqpbxL/ChfIEfZQZ3ZQ69pLUl6IlhLL2p/bG7dQi0bGCj1/5f4fYOMM/cvwTevCGIsluOL2pBHvFtzneQPpp+ssza+SweQvElqirrGLQ/3x3RWT6yFMpdDhkJimyY8XZnG/Hvq/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=jTrQweeqJ5wfSQ1EelNhRROTV7nnkDh3tQqIf7Bk5jk=; b=ZK+zljpj6ZIthlzADNJbbkaTcBGBTpgEwqgME+dVn2b3SG1vze20wwAZa66cthI9eHiUcBCSVvvLXXvCDuq9AMKaqkvQroJVhuq14KTwAm/HeyVpts8g5BgoFCAea1vQZJt3MyI6IaJhsZ1cmfBoErAs8jF2PCcfY9JiqbLCwpClatLmxj+2OjTM+yzgsWYFcDaydrjtyPiL9nBeRB0SaU9BCC7FS5HZtsEnplLIAkcB3WjGxbBP9UvwaX+bTp00gR/GkRECH9jFlrgSQPaN0uPTEXzYy3/q+hajVjQEKlcq1MDXmh5pAvlqK6dExOKf3+ACBCtWjYQVcWDP7tTolw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=jTrQweeqJ5wfSQ1EelNhRROTV7nnkDh3tQqIf7Bk5jk=; b=VeCQykNFOg29ITZ3pXoS1YURxh6H91pI89/X2qSPnw27RvnqmATj6hYk3YHpD5c1fJSEbL4oeaW7FuA3cSVZKwXtCOLVtMW6rgBjd8VKAO/8o8IL6LOBMMpQouhUCAtNNRJ6p2uyrKCBTyaRLUwRsmHu6bUjVNWg4SHU5b4UsnI= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Henry Wang To: CC: Henry Wang , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , "Volodymyr Babchuk" , Andrew Cooper , George Dunlap , "Jan Beulich" , Wei Liu , Shawn Anastasio , Alistair Francis , Bob Eshleman , "Connor Davis" , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Subject: [PATCH v2 2/5] xen/domain.h: Centrialize is_domain_direct_mapped() Date: Fri, 8 Mar 2024 09:54:32 +0800 Message-ID: <20240308015435.4044339-3-xin.wang2@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240308015435.4044339-1-xin.wang2@amd.com> References: <20240308015435.4044339-1-xin.wang2@amd.com> MIME-Version: 1.0 Received-SPF: None (SATLEXMB04.amd.com: xin.wang2@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PEPF00000009:EE_|LV2PR12MB5944:EE_ X-MS-Office365-Filtering-Correlation-Id: b2327975-6b70-4fb4-6436-08dc3f12bf00 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2uhOvfvapcZUJ6UsU8iuObgLlp7sB0bdDo3yY7b+0LOckNzr87hHHmp7GWKdmjm96bpfj8ygM3gRqOsCv5jhrkc9TPnYYE+MIeWwXtz5GkX3SyK0xyNZcP2aLEJ6DsfQWj3Z+2vZ9dj2Zqpd1tmvMbCeZWXYGZ05q5I5bSaDOKSg3inv7RWDUMA1jGh3nhDhseLq1mGgu+KG5M31pu+MR6NXCbKeNA2jHbQwLNKj3DZYr1E4VvnqAkjzPCYFawfodtYVkMv3hdunUnSy189KCUDamV5QlgpdiVSJ89LWEHc4+xA1vQBsr17LUObIDZoyWtg/AjsaVmq2Y+oMIlH1IfSSx1CiTOAXSs1ZV5jBhni1g+SxKOUH1f0OmEvdqBA+VjTtccLZyGqK4NHjlWAIXSRQsDCCOlwqYIyarqvudTwXyI0cOVE7UWTRRCmYDunjZa3sTMJrgriZBmUdBRPT1bblI1TlB6eD99UfFrtTtZy3XDLSke6Yo0jHtR4m7hYlxtM1xZaVKTJgkW4oRRh0pNkGJfUN1QtjTLONP/0uJaRCbso37tXV6e9gSzWPWVNVVUuLki5IeUMW4ES5jemnN32u0bVUsoF+4Q03SC9wptc32IRxBk64WOg2gr2ZK+ZtyJv1E6mQuUV2zh84Cbd36plvd0J3YfqcB3w5WSlj36RS3OpkvVH/XUQgMvxQWqgnm19/QlOjVayRWv9O1kZBYIN5hXFH39oNWqhITjqSDCV8OS6zX/PPXJ6Uffzdvii5 X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(1800799015)(7416005)(376005)(36860700004)(82310400014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Mar 2024 01:54:52.5577 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b2327975-6b70-4fb4-6436-08dc3f12bf00 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CH3PEPF00000009.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV2PR12MB5944 Currently direct mapped domain is only supported by the Arm architecture at the domain creation time by setting the CDF_directmap flag. There is not a need for every non-Arm architecture, i.e. x86, RISC-V and PPC, to define a stub is_domain_direct_mapped() in arch header. Move is_domain_direct_mapped() to a centralized place at xen/domain.h and evaluate CDF_directmap for non-Arm architecture to 0. Signed-off-by: Henry Wang Reviewed-by: Michal Orzel Reviewed-by: Jan Beulich Acked-by: Shawn Anastasio --- v2: - New patch --- xen/arch/arm/include/asm/domain.h | 2 -- xen/arch/ppc/include/asm/domain.h | 2 -- xen/arch/riscv/include/asm/domain.h | 2 -- xen/arch/x86/include/asm/domain.h | 1 - xen/include/xen/domain.h | 3 +++ 5 files changed, 3 insertions(+), 7 deletions(-) diff --git a/xen/arch/arm/include/asm/domain.h b/xen/arch/arm/include/asm/domain.h index 8218afb862..f1d72c6e48 100644 --- a/xen/arch/arm/include/asm/domain.h +++ b/xen/arch/arm/include/asm/domain.h @@ -29,8 +29,6 @@ enum domain_type { #define is_64bit_domain(d) (0) #endif -#define is_domain_direct_mapped(d) ((d)->cdf & CDF_directmap) - /* * Is the domain using the host memory layout? * diff --git a/xen/arch/ppc/include/asm/domain.h b/xen/arch/ppc/include/asm/domain.h index 573276d0a8..3a447272c6 100644 --- a/xen/arch/ppc/include/asm/domain.h +++ b/xen/arch/ppc/include/asm/domain.h @@ -10,8 +10,6 @@ struct hvm_domain uint64_t params[HVM_NR_PARAMS]; }; -#define is_domain_direct_mapped(d) ((void)(d), 0) - /* TODO: Implement */ #define guest_mode(r) ({ (void)(r); BUG_ON("unimplemented"); 0; }) diff --git a/xen/arch/riscv/include/asm/domain.h b/xen/arch/riscv/include/asm/domain.h index 0f5dc2be40..027bfa8a93 100644 --- a/xen/arch/riscv/include/asm/domain.h +++ b/xen/arch/riscv/include/asm/domain.h @@ -10,8 +10,6 @@ struct hvm_domain uint64_t params[HVM_NR_PARAMS]; }; -#define is_domain_direct_mapped(d) ((void)(d), 0) - struct arch_vcpu_io { }; diff --git a/xen/arch/x86/include/asm/domain.h b/xen/arch/x86/include/asm/domain.h index 622d22bef2..4bd78e3a6d 100644 --- a/xen/arch/x86/include/asm/domain.h +++ b/xen/arch/x86/include/asm/domain.h @@ -22,7 +22,6 @@ #define is_hvm_pv_evtchn_domain(d) (is_hvm_domain(d) && \ ((d)->arch.hvm.irq->callback_via_type == HVMIRQ_callback_vector || \ (d)->vcpu[0]->arch.hvm.evtchn_upcall_vector)) -#define is_domain_direct_mapped(d) ((void)(d), 0) #define VCPU_TRAP_NONE 0 #define VCPU_TRAP_NMI 1 diff --git a/xen/include/xen/domain.h b/xen/include/xen/domain.h index b1a4aa6f38..3de5635291 100644 --- a/xen/include/xen/domain.h +++ b/xen/include/xen/domain.h @@ -41,6 +41,8 @@ void arch_get_domain_info(const struct domain *d, #ifdef CONFIG_ARM /* Should domain memory be directly mapped? */ #define CDF_directmap (1U << 1) +#else +#define CDF_directmap 0 #endif /* Is domain memory on static allocation? */ #ifdef CONFIG_STATIC_MEMORY @@ -49,6 +51,7 @@ void arch_get_domain_info(const struct domain *d, #define CDF_staticmem 0 #endif +#define is_domain_direct_mapped(d) ((d)->cdf & CDF_directmap) #define is_domain_using_staticmem(d) ((d)->cdf & CDF_staticmem) /* From patchwork Fri Mar 8 01:54:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Henry Wang X-Patchwork-Id: 13586426 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F1A23C54798 for ; Fri, 8 Mar 2024 01:55:14 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.690078.1075765 (Exim 4.92) (envelope-from ) id 1riPRy-0002wP-FA; Fri, 08 Mar 2024 01:55:06 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 690078.1075765; Fri, 08 Mar 2024 01:55:06 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1riPRy-0002wF-Bh; Fri, 08 Mar 2024 01:55:06 +0000 Received: by outflank-mailman (input) for mailman id 690078; Fri, 08 Mar 2024 01:55:05 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1riPRw-0002aR-RK for xen-devel@lists.xenproject.org; Fri, 08 Mar 2024 01:55:04 +0000 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on20600.outbound.protection.outlook.com [2a01:111:f403:2416::600]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id e172b442-dcee-11ee-afda-a90da7624cb6; Fri, 08 Mar 2024 02:55:04 +0100 (CET) Received: from CH0PR08CA0003.namprd08.prod.outlook.com (2603:10b6:610:33::8) by DS0PR12MB7701.namprd12.prod.outlook.com (2603:10b6:8:133::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.27; Fri, 8 Mar 2024 01:55:00 +0000 Received: from CH3PEPF0000000C.namprd04.prod.outlook.com (2603:10b6:610:33:cafe::86) by CH0PR08CA0003.outlook.office365.com (2603:10b6:610:33::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.24 via Frontend Transport; Fri, 8 Mar 2024 01:54:59 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CH3PEPF0000000C.mail.protection.outlook.com (10.167.244.39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7362.11 via Frontend Transport; Fri, 8 Mar 2024 01:54:59 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 7 Mar 2024 19:54:56 -0600 Received: from henry-MS-7D54.amd.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Thu, 7 Mar 2024 19:54:53 -0600 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: e172b442-dcee-11ee-afda-a90da7624cb6 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ret327N92ICMcm5oO0QKCrm/ZGhpRc9Ov+6+EkyJys/G6X5ThsABN+bJH+bT4KOSEize8/BbZ/WlId0fUZAYJfG0FDe01pS5cNn49LqlXMbfT3OlgFs8GDbig9taY4QX7Aa05BiJLCHumrN+fO+7aUq29h77OL6Zlcy6KCnwG/NFm/Fbpiq3OTzwWXuPATrXPpTf4d2N8TIbvw9JPn/HwLYrBKnkFP6CJmbTpxLX4Tew0nrRkcZV9VvoLPNNBdpt8EsKiXFXgpllhdJK+FstdkbXEOaw9FAFGCMOwmlRCKMZ+8HTYPuz9zUOiqOfR3tZ/pG4Z103zbvT/K5t0oJOHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=5JLhDJckjBrTEJORORb//VfOB3M3GRvGRS0zsUFs98o=; b=X9Ko+PlWhRCOGTRjKwWC2G3ooiAE7PsLeEkTdqlg3A2SlAOQ6i806P2PehNJ5grMqX2xwlFeRTUKGEWPXbB2OzyAhvJmAEEERyem2Bgh/kFUGNqoaP2e7Tv3QH/b7ecwbtYMYV3tfDht/CKQTELRBY3Orc/uttRMV+xUmNegIXFj6CsRkqKNSQciPbAIkFmlEgQxskyHf1exOuPsAnD0YfcGDblncRTKZIF+SU4Pc5i4eGJUOlr+nFUQrR+DtZMEJEpCn8S+iP/AlSl27d7Q4NlBlBhPqN+wQGPDsPKJMhH33q8LcjBBtdGA1gxQ6vZHUOaN5mDGeSE1+vLqSRfPvw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5JLhDJckjBrTEJORORb//VfOB3M3GRvGRS0zsUFs98o=; b=2jweelHA3iyHSHrP52YxQ1iTT1+9WZ253Y4xc//KG0h8hDjD9JXJrPROKyfyolK9kJ4Jqp2k5kOba1v/LsQFjbb/2uZILLqUmErnBPNy73igtkUBrrZs0GL3kWPcL+ZP4elwKWvx1a1LHnqWWcWg8SNDU/otU2aFhyVXbmOikmo= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Henry Wang To: CC: Henry Wang , Wei Liu , Anthony PERARD , Juergen Gross , Andrew Cooper , George Dunlap , "Jan Beulich" , Julien Grall , "Stefano Stabellini" , Bertrand Marquis , Michal Orzel , "Volodymyr Babchuk" , Alec Kwapis Subject: [PATCH v2 3/5] xen/domctl, tools: Introduce a new domctl to get guest memory map Date: Fri, 8 Mar 2024 09:54:33 +0800 Message-ID: <20240308015435.4044339-4-xin.wang2@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240308015435.4044339-1-xin.wang2@amd.com> References: <20240308015435.4044339-1-xin.wang2@amd.com> MIME-Version: 1.0 Received-SPF: None (SATLEXMB04.amd.com: xin.wang2@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PEPF0000000C:EE_|DS0PR12MB7701:EE_ X-MS-Office365-Filtering-Correlation-Id: 179b062c-8f68-4748-b45c-08dc3f12c319 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7ktN1Z/K0/PgOFfDzVGPYbkEwXDvsudwHWbVk5xAddK+aZqrG5MqmLLmQLfYihXrml7NrFtd1lwBipWl8nruMsVtZMPj9NFTCKHiDHHsNIM5/YaKn0jgajBCdnQ9PfJi+fo9BjzlxFdX92wSRis6pKImaTlPzhesQSoN7pwrVHMsaY2O46vSgzxzOatUse4CvsgdcE/pLMRXAyAIzXzi0/HnNgbZ95/9bsCKX3fG0hT9Ij24nGcRw9KnQTUk6kQ2QMYrTbC7S7s370rSf7BZRRxaFJgJpAowhiAVRXr+svZUQ26JjvbTfZqAZMKDFev9WNaHCAxqVu1xWbCglHP0o7CHGHI8PiQp1OaqGt2L7cweMCdfDKeu7hZgKp1iLJUUW8IuUe/x/nbNgJzyMLGNVWVWMxO2Uvd4KzO2lG6syh8w9RW/Mofc1CvilpvJyy0ddBWZnSiO5V+RWKpXa45+ADujIflTx7Vz2qLYgCo89azwkE5IXRDv0p2O9dNNdFbmo6AvaZd0Sm9KyE9NIhE2ACHrzdbw9vqzLvWTsyYbRzlLZL45QwJPWviF2N9BR3Wrn8r+fpIa2pvZ5nMHV5R3oKz50CzsDBr/PZyFtQkT+px98bBAeCxmqs/AK2zPD5RCahXMl7NgyyIS8M7OAYiQ47lVFo3wXM4VHe3C2Y58eGZuzIjIDvPTOjiqjirRuD3Lw7iMDmgHT1hrG3r9OQjiK7cTFDoSZ4DmDEoLGvCiWm3cYc3zisNWKhvuMLFgUHOA X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(1800799015)(7416005)(376005)(36860700004)(82310400014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Mar 2024 01:54:59.4345 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 179b062c-8f68-4748-b45c-08dc3f12c319 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CH3PEPF0000000C.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB7701 There are some use cases where the toolstack needs to know the guest memory map. For example, the toolstack helper application "init-dom0less" needs to know the guest magic page regions for 1:1 direct-mapped dom0less DomUs to allocate magic pages. To address such needs, add XEN_DOMCTL_get_mem_map hypercall and related data structures to query the hypervisor for the guest memory map. The guest memory map is recorded in the domain structure and currently only guest magic page region is recorded in the guest memory map. The guest magic page region is initialized at the domain creation time as the layout in the public header, and it is updated for 1:1 dom0less DomUs (see the following commit) to avoid conflict with RAM. Take the opportunity to drop an unnecessary empty line to keep the coding style consistent in the file. Reported-by: Alec Kwapis Signed-off-by: Henry Wang --- v2: - New patch RFC: I think the newly introduced "struct xen_domctl_mem_map" is quite duplicated with "struct xen_memory_map", any comment on reuse the "struct xen_memory_map" for simplicity? --- tools/include/xenctrl.h | 4 ++++ tools/libs/ctrl/xc_domain.c | 32 +++++++++++++++++++++++++++++++ xen/arch/arm/domain.c | 6 ++++++ xen/arch/arm/domctl.c | 19 +++++++++++++++++- xen/arch/arm/include/asm/domain.h | 8 ++++++++ xen/include/public/arch-arm.h | 4 ++++ xen/include/public/domctl.h | 21 ++++++++++++++++++++ 7 files changed, 93 insertions(+), 1 deletion(-) diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 2ef8b4e054..b25e9772a2 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -1195,6 +1195,10 @@ int xc_domain_setmaxmem(xc_interface *xch, uint32_t domid, uint64_t max_memkb); +int xc_get_domain_mem_map(xc_interface *xch, uint32_t domid, + struct xen_mem_region mem_regions[], + uint32_t *nr_regions); + int xc_domain_set_memmap_limit(xc_interface *xch, uint32_t domid, unsigned long map_limitkb); diff --git a/tools/libs/ctrl/xc_domain.c b/tools/libs/ctrl/xc_domain.c index f2d9d14b4d..64b46bdfb4 100644 --- a/tools/libs/ctrl/xc_domain.c +++ b/tools/libs/ctrl/xc_domain.c @@ -697,6 +697,38 @@ int xc_domain_setmaxmem(xc_interface *xch, return do_domctl(xch, &domctl); } +int xc_get_domain_mem_map(xc_interface *xch, uint32_t domid, + struct xen_mem_region mem_regions[], + uint32_t *nr_regions) +{ + int rc; + struct xen_domctl domctl = { + .cmd = XEN_DOMCTL_get_mem_map, + .domain = domid, + .u.mem_map = { + .nr_mem_regions = *nr_regions, + }, + }; + + DECLARE_HYPERCALL_BOUNCE(mem_regions, + sizeof(xen_mem_region_t) * (*nr_regions), + XC_HYPERCALL_BUFFER_BOUNCE_OUT); + + if ( !mem_regions || xc_hypercall_bounce_pre(xch, mem_regions) || + (*nr_regions) < 1 ) + return -1; + + set_xen_guest_handle(domctl.u.mem_map.buffer, mem_regions); + + rc = do_domctl(xch, &domctl); + + xc_hypercall_bounce_post(xch, mem_regions); + + *nr_regions = domctl.u.mem_map.nr_mem_regions; + + return rc; +} + #if defined(__i386__) || defined(__x86_64__) int xc_domain_set_memory_map(xc_interface *xch, uint32_t domid, diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c index 5e7a7f3e7e..54f3601ab0 100644 --- a/xen/arch/arm/domain.c +++ b/xen/arch/arm/domain.c @@ -696,6 +696,7 @@ int arch_domain_create(struct domain *d, { unsigned int count = 0; int rc; + struct mem_map_domain *mem_map = &d->arch.mem_map; BUILD_BUG_ON(GUEST_MAX_VCPUS < MAX_VIRT_CPUS); @@ -785,6 +786,11 @@ int arch_domain_create(struct domain *d, d->arch.sve_vl = config->arch.sve_vl; #endif + mem_map->regions[mem_map->nr_mem_regions].start = GUEST_MAGIC_BASE; + mem_map->regions[mem_map->nr_mem_regions].size = GUEST_MAGIC_SIZE; + mem_map->regions[mem_map->nr_mem_regions].type = GUEST_MEM_REGION_MAGIC; + mem_map->nr_mem_regions++; + return 0; fail: diff --git a/xen/arch/arm/domctl.c b/xen/arch/arm/domctl.c index ad56efb0f5..92024bcaa0 100644 --- a/xen/arch/arm/domctl.c +++ b/xen/arch/arm/domctl.c @@ -148,7 +148,6 @@ long arch_do_domctl(struct xen_domctl *domctl, struct domain *d, return 0; } - case XEN_DOMCTL_vuart_op: { int rc; @@ -176,6 +175,24 @@ long arch_do_domctl(struct xen_domctl *domctl, struct domain *d, return rc; } + case XEN_DOMCTL_get_mem_map: + { + int rc; + /* + * Cap the number of regions to the minimum value between toolstack and + * hypervisor to avoid overflowing the buffer. + */ + uint32_t nr_regions = min(d->arch.mem_map.nr_mem_regions, + domctl->u.mem_map.nr_mem_regions); + + if ( copy_to_guest(domctl->u.mem_map.buffer, + d->arch.mem_map.regions, + nr_regions) || + __copy_to_guest(u_domctl, domctl, 1) ) + rc = -EFAULT; + + return rc; + } default: return subarch_do_domctl(domctl, d, u_domctl); } diff --git a/xen/arch/arm/include/asm/domain.h b/xen/arch/arm/include/asm/domain.h index f1d72c6e48..a559a9e499 100644 --- a/xen/arch/arm/include/asm/domain.h +++ b/xen/arch/arm/include/asm/domain.h @@ -10,6 +10,7 @@ #include #include #include +#include #include struct hvm_domain @@ -59,6 +60,11 @@ struct paging_domain { unsigned long p2m_total_pages; }; +struct mem_map_domain { + unsigned int nr_mem_regions; + struct xen_mem_region regions[XEN_MAX_MEM_REGIONS]; +}; + struct arch_domain { #ifdef CONFIG_ARM_64 @@ -77,6 +83,8 @@ struct arch_domain struct paging_domain paging; + struct mem_map_domain mem_map; + struct vmmio vmmio; /* Continuable domain_relinquish_resources(). */ diff --git a/xen/include/public/arch-arm.h b/xen/include/public/arch-arm.h index a25e87dbda..a06eaf2dab 100644 --- a/xen/include/public/arch-arm.h +++ b/xen/include/public/arch-arm.h @@ -420,6 +420,10 @@ typedef uint64_t xen_callback_t; * should instead use the FDT. */ +/* Guest memory region types */ +#define GUEST_MEM_REGION_DEFAULT 0 +#define GUEST_MEM_REGION_MAGIC 1 + /* Physical Address Space */ /* Virtio MMIO mappings */ diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h index a33f9ec32b..77bf999651 100644 --- a/xen/include/public/domctl.h +++ b/xen/include/public/domctl.h @@ -946,6 +946,25 @@ struct xen_domctl_paging_mempool { uint64_aligned_t size; /* Size in bytes. */ }; +#define XEN_MAX_MEM_REGIONS 1 + +struct xen_mem_region { + uint64_t start; + uint64_t size; + unsigned int type; +}; +typedef struct xen_mem_region xen_mem_region_t; +DEFINE_XEN_GUEST_HANDLE(xen_mem_region_t); + +struct xen_domctl_mem_map { + /* IN & OUT */ + uint32_t nr_mem_regions; + /* OUT */ + XEN_GUEST_HANDLE(xen_mem_region_t) buffer; +}; +typedef struct xen_domctl_mem_map xen_domctl_mem_map_t; +DEFINE_XEN_GUEST_HANDLE(xen_domctl_mem_map_t); + #if defined(__i386__) || defined(__x86_64__) struct xen_domctl_vcpu_msr { uint32_t index; @@ -1277,6 +1296,7 @@ struct xen_domctl { #define XEN_DOMCTL_vmtrace_op 84 #define XEN_DOMCTL_get_paging_mempool_size 85 #define XEN_DOMCTL_set_paging_mempool_size 86 +#define XEN_DOMCTL_get_mem_map 87 #define XEN_DOMCTL_gdbsx_guestmemio 1000 #define XEN_DOMCTL_gdbsx_pausevcpu 1001 #define XEN_DOMCTL_gdbsx_unpausevcpu 1002 @@ -1339,6 +1359,7 @@ struct xen_domctl { struct xen_domctl_vuart_op vuart_op; struct xen_domctl_vmtrace_op vmtrace_op; struct xen_domctl_paging_mempool paging_mempool; + struct xen_domctl_mem_map mem_map; uint8_t pad[128]; } u; }; From patchwork Fri Mar 8 01:54:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Henry Wang X-Patchwork-Id: 13586427 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 36F72C54E4A for ; Fri, 8 Mar 2024 01:55:16 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.690079.1075775 (Exim 4.92) (envelope-from ) id 1riPRz-0003E1-TA; Fri, 08 Mar 2024 01:55:07 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 690079.1075775; Fri, 08 Mar 2024 01:55: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 1riPRz-0003Ds-Ot; Fri, 08 Mar 2024 01:55:07 +0000 Received: by outflank-mailman (input) for mailman id 690079; Fri, 08 Mar 2024 01:55: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 1riPRy-000262-Ih for xen-devel@lists.xenproject.org; Fri, 08 Mar 2024 01:55:06 +0000 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04on20600.outbound.protection.outlook.com [2a01:111:f403:2409::600]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id e18692dd-dcee-11ee-a1ee-f123f15fe8a2; Fri, 08 Mar 2024 02:55:05 +0100 (CET) Received: from CH0PR08CA0008.namprd08.prod.outlook.com (2603:10b6:610:33::13) by DM6PR12MB4299.namprd12.prod.outlook.com (2603:10b6:5:223::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.27; Fri, 8 Mar 2024 01:55:00 +0000 Received: from CH3PEPF0000000C.namprd04.prod.outlook.com (2603:10b6:610:33:cafe::bc) by CH0PR08CA0008.outlook.office365.com (2603:10b6:610:33::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.27 via Frontend Transport; Fri, 8 Mar 2024 01:55:00 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CH3PEPF0000000C.mail.protection.outlook.com (10.167.244.39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7362.11 via Frontend Transport; Fri, 8 Mar 2024 01:55:00 +0000 Received: from SATLEXMB08.amd.com (10.181.40.132) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 7 Mar 2024 19:54:59 -0600 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB08.amd.com (10.181.40.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 7 Mar 2024 17:54:59 -0800 Received: from henry-MS-7D54.amd.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Thu, 7 Mar 2024 19:54:57 -0600 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: e18692dd-dcee-11ee-a1ee-f123f15fe8a2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=imiHSEHGSKFUxX351jEEMbsY5UW+40/WFtHMOEaDJdhAIax8YrU1FASa2FuDtJ1e2MLxbRePU1A/w8FtOP88TRSNIANvAkSxA8XORyZFA3jktPPbRBiz63mbqUW6kky0n3uhziP2KzqgdVnOH36oF5au/2QD8Ra5z0ebkAw6Oa4Oh8YLo7G0aidlWx6E2I27dRz8GnKTTyyFuZc0e7sXGrNmVk+FTryuuHAsYAZw+T2qmEKXyvajEvbGnPDsHb45fZn4qyCSYmu6cm+yGOp6o35MeChQb+3k1FFR+EclbUsjO5PHgWX9flE5W/fj4IEv5om0LEriDLxzLl1f+h2Cjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=CE58BMIuONHX86OiEvm3TsjUfQMGClGr8nUX/wXf4kY=; b=ie1kjj8PIHBKlY8lnXGfTlKkvZ4zXX5XR+sTVaebriEBPfclQIAF6bHRPaDIkFWrzoE3XR7N86ML5a5gghC362cEwqbhOytOeI+4G1p3TDQTPb0ZKIGkOwJFcsTP8QKNsyDQFR6VeE7ETw9cnmG+c++a/wQam6OsVjg+Mlp3lQHxyR89nIBCityOpxsuXmWnKi1WNlOTRCfPwioyVol0geMhNqh955hbu1JH2KLOBi80KPvFoOAUTTnKm8E/t466BorQjXaPTi7g2bs+iQFzn8Ahii5ddGyZJO4NupO3g8RwIr7T5HtLG/2c+e+UdciZXTsTpIMVk7vJwf1S8CskBQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=CE58BMIuONHX86OiEvm3TsjUfQMGClGr8nUX/wXf4kY=; b=qEjq0KVfr1B8U9cBm+lK0Y9TigEXsglYA/GhGQ5mPtS5sCk4hGMLvx4C695jrf7AIWqpop+EhcU+3CMVxVKRsYqm8jeUtzKSdAcsM3UBJ4jHqJn1f5L7ZmZvlB7RitTQFfGFslB7E5vWE2U2nTpx/eIr4Qeq/fj5tCZ3AXRypqw= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Henry Wang To: CC: Henry Wang , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , "Volodymyr Babchuk" , Alec Kwapis Subject: [PATCH v2 4/5] xen/arm: Find unallocated spaces for magic pages of direct-mapped domU Date: Fri, 8 Mar 2024 09:54:34 +0800 Message-ID: <20240308015435.4044339-5-xin.wang2@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240308015435.4044339-1-xin.wang2@amd.com> References: <20240308015435.4044339-1-xin.wang2@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PEPF0000000C:EE_|DM6PR12MB4299:EE_ X-MS-Office365-Filtering-Correlation-Id: c5a2fb12-47a0-462e-ae6b-08dc3f12c395 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8xp3Qzu2hTg/oEmD5mEnWMxjdBceJg0feH5EFHbKD6K/FtDLh3/xFKM/j7jiHbZ8OAG4fl6gWUiyx4YDMXMLzQ0lsf0kaV4xCg8Vh3QOOVIQ0A2IXB2LxUTBhP39cCuULDHvQIEZ6aFmNb19fXtCxOtmQZeY/HotUBzBkXsl2ooNuiblhY41pPbtisXizxvNK+lSjWhRPVHgbE7+dCwcPt64tptCJg4EpiaBrjFndnCha0DQukJsBbSH2q0ei9kJLSHiw8EQ780+I0gL7pfz5r8Ak5MfWoL3BNyAztxTtdXhacmw2Y2vOZ9hI+xra5hMnQgBSyJfeF1GaWdY0dFbL4agJHm8E0f4ZquRMrrYx0f5sK4cg1HpqGSkWkQ9FsxeX636oQk56FXnw3csmxCMeG3mLlKxtCCixdzrzBZllC8e0YdDi/MayDbnkBAevE8VzdYMDQ7EomR4Qz8lxfxmey/yDczQYcW0uqCifUHb98nWIY2lbpOAn2MyPVVy45/SfB0N0u+DFHBdmXGOSiYKd26ajrRjf+W3OsrIKtXTenayNSR0zf7h+npkI6kvwdzo9HrwvSGyWoX3B2njB+eEzVcTNkzjpi4sSbMaIAkTDiCo+r0woqeSbnjc1Lf4sTAnHGJy28A/o1Jid9iVsgOSMHhWRQNl632g8A+8mCYdHc+GFdCRAd8vPYnlT8wDfS89LanITOWCVnVUnQSlkOhmNJwEbGZuSvUnq46CCie4WsE0nXfYlxqvDCwnPIko2be7 X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(1800799015)(82310400014)(36860700004)(376005);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Mar 2024 01:55:00.2626 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c5a2fb12-47a0-462e-ae6b-08dc3f12c395 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CH3PEPF0000000C.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4299 For 1:1 direct-mapped dom0less DomUs, the magic pages should not clash with any RAM region. To find a proper region for guest magic pages, we can reuse the logic of finding domain extended regions. Extract the logic of finding domain extended regions to a helper function named find_unused_memory() and use it to find unallocated spaces for magic pages before make_hypervisor_node(). The result magic page region is added to the reserved memory section of the bootinfo so that it is carved out from the extended regions. Reported-by: Alec Kwapis Signed-off-by: Henry Wang --- v2: - New patch --- xen/arch/arm/dom0less-build.c | 43 +++++++++++++++++++++++++ xen/arch/arm/domain_build.c | 30 ++++++++++------- xen/arch/arm/include/asm/domain_build.h | 2 ++ 3 files changed, 64 insertions(+), 11 deletions(-) diff --git a/xen/arch/arm/dom0less-build.c b/xen/arch/arm/dom0less-build.c index 1e1c8d83ae..99447bfb0c 100644 --- a/xen/arch/arm/dom0less-build.c +++ b/xen/arch/arm/dom0less-build.c @@ -682,6 +682,49 @@ static int __init prepare_dtb_domU(struct domain *d, struct kernel_info *kinfo) if ( kinfo->dom0less_feature & DOM0LESS_ENHANCED_NO_XS ) { + if ( is_domain_direct_mapped(d) ) + { + struct meminfo *avail_magic_regions = xzalloc(struct meminfo); + struct meminfo *rsrv_mem = &bootinfo.reserved_mem; + struct mem_map_domain *mem_map = &d->arch.mem_map; + uint64_t magic_region_start = INVALID_PADDR; + uint64_t magic_region_size = GUEST_MAGIC_SIZE; + unsigned int i; + + if ( !avail_magic_regions ) + return -ENOMEM; + + ret = find_unused_memory(d, kinfo, avail_magic_regions); + if ( ret ) + { + printk(XENLOG_WARNING + "%pd: failed to find a region for domain magic pages\n", + d); + goto err; + } + + magic_region_start = avail_magic_regions->bank[0].start; + + /* + * Register the magic region as reserved mem to make sure this + * region will not be counted when allocating extended regions. + */ + rsrv_mem->bank[rsrv_mem->nr_banks].start = magic_region_start; + rsrv_mem->bank[rsrv_mem->nr_banks].size = magic_region_size; + rsrv_mem->bank[rsrv_mem->nr_banks].type = MEMBANK_DEFAULT; + rsrv_mem->nr_banks++; + + /* Update the domain memory map. */ + for ( i = 0; i < mem_map->nr_mem_regions; i++ ) + { + if ( mem_map->regions[i].type == GUEST_MEM_REGION_MAGIC ) + { + mem_map->regions[i].start = magic_region_start; + mem_map->regions[i].size = magic_region_size; + } + } + } + ret = make_hypervisor_node(d, kinfo, addrcells, sizecells); if ( ret ) goto err; diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 085d88671e..b36b98ee7d 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -1110,6 +1110,24 @@ static int __init find_domU_holes(const struct kernel_info *kinfo, return res; } +int __init find_unused_memory(struct domain *d, const struct kernel_info *kinfo, + struct meminfo *mem_region) +{ + int res; + + if ( is_domain_direct_mapped(d) ) + { + if ( !is_iommu_enabled(d) ) + res = find_unallocated_memory(kinfo, mem_region); + else + res = find_memory_holes(kinfo, mem_region); + } + else + res = find_domU_holes(kinfo, mem_region); + + return res; +} + int __init make_hypervisor_node(struct domain *d, const struct kernel_info *kinfo, int addrcells, int sizecells) @@ -1161,17 +1179,7 @@ int __init make_hypervisor_node(struct domain *d, if ( !ext_regions ) return -ENOMEM; - if ( is_domain_direct_mapped(d) ) - { - if ( !is_iommu_enabled(d) ) - res = find_unallocated_memory(kinfo, ext_regions); - else - res = find_memory_holes(kinfo, ext_regions); - } - else - { - res = find_domU_holes(kinfo, ext_regions); - } + res = find_unused_memory(d, kinfo, ext_regions); if ( res ) printk(XENLOG_WARNING "%pd: failed to allocate extended regions\n", diff --git a/xen/arch/arm/include/asm/domain_build.h b/xen/arch/arm/include/asm/domain_build.h index da9e6025f3..4458012644 100644 --- a/xen/arch/arm/include/asm/domain_build.h +++ b/xen/arch/arm/include/asm/domain_build.h @@ -10,6 +10,8 @@ bool allocate_bank_memory(struct domain *d, struct kernel_info *kinfo, gfn_t sgfn, paddr_t tot_size); int construct_domain(struct domain *d, struct kernel_info *kinfo); int domain_fdt_begin_node(void *fdt, const char *name, uint64_t unit); +int find_unused_memory(struct domain *d, const struct kernel_info *kinfo, + struct meminfo *mem_region); int make_chosen_node(const struct kernel_info *kinfo); int make_cpus_node(const struct domain *d, void *fdt); int make_hypervisor_node(struct domain *d, const struct kernel_info *kinfo, From patchwork Fri Mar 8 01:54:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Henry Wang X-Patchwork-Id: 13586428 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BF5FEC54E49 for ; Fri, 8 Mar 2024 01:55:18 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.690080.1075785 (Exim 4.92) (envelope-from ) id 1riPS3-0003cq-4e; Fri, 08 Mar 2024 01:55:11 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 690080.1075785; Fri, 08 Mar 2024 01:55:11 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1riPS3-0003ci-1K; Fri, 08 Mar 2024 01:55:11 +0000 Received: by outflank-mailman (input) for mailman id 690080; Fri, 08 Mar 2024 01:55:09 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1riPS1-0002aR-UA for xen-devel@lists.xenproject.org; Fri, 08 Mar 2024 01:55:09 +0000 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on20611.outbound.protection.outlook.com [2a01:111:f400:7e88::611]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id e402671c-dcee-11ee-afda-a90da7624cb6; Fri, 08 Mar 2024 02:55:09 +0100 (CET) Received: from SJ0P220CA0015.NAMP220.PROD.OUTLOOK.COM (2603:10b6:a03:41b::19) by PH7PR12MB7455.namprd12.prod.outlook.com (2603:10b6:510:20e::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.24; Fri, 8 Mar 2024 01:55:05 +0000 Received: from SJ1PEPF00001CDD.namprd05.prod.outlook.com (2603:10b6:a03:41b:cafe::71) by SJ0P220CA0015.outlook.office365.com (2603:10b6:a03:41b::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.27 via Frontend Transport; Fri, 8 Mar 2024 01:55:04 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by SJ1PEPF00001CDD.mail.protection.outlook.com (10.167.242.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7362.11 via Frontend Transport; Fri, 8 Mar 2024 01:55:04 +0000 Received: from SATLEXMB06.amd.com (10.181.40.147) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 7 Mar 2024 19:55:03 -0600 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB06.amd.com (10.181.40.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 7 Mar 2024 19:55:02 -0600 Received: from henry-MS-7D54.amd.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Thu, 7 Mar 2024 19:55:00 -0600 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: e402671c-dcee-11ee-afda-a90da7624cb6 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=P1Zb0LmRdLxFMkCQtY9gpGwYCD7CklSEZ/wkEAjq8kUT+rI9oluL0YPOb9Vh8QnMRb+h3+dxQ19txY+azfcR9PpQRopoHZhEZWwvXwiWZcgEvUaQDbaWJuDkqXPT1MasnuPvBC0tNtULBAgQ3G4PBLKmyg7hvWcDSXAwlafKxOm9tH6L0qzK2md/91oac2TlQ3yb/2iy8h7KOo2GrGI5iebTZEas6vQzmpYRfSIc79aVEEHgsT7uUCTqNULEwZh4hoK3hePdvHB2JaZn8M2MXne2T69B+HinDMmClA0NW+V0FwrJh4rER/BkQ3ZRetRU7OMrZgxhxrywmrcN6F+fFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=dchuisJ+SMUCW3UvJNt1sybC0OWRLBHo54+nPU/5Sjc=; b=S/9pQ+orprZ9xcyVM2Iz5Y+Kb5qUmgzaYikQHIAV+dh9dV3RJI3Ox0ibtTC2CbfZlX6hnlpTla0E1BpIPcOeLGMGbhZEyv4mo5QMUTrHwsvZ46X3UA9f3K+Cia0AcQn5ItnhMLSWshxlplmcQ57O2rDr5dLMr3itguoFe4P8KhwDBXq7vOGHFdn63jzVtjuO6+WhneFKOcd0d1xXnKSJ/BATdCuTNKZbwXV8qyo96bvGv31UKGEkgJn85mmKP0Nl8jdc1R7sGYfFuBV/2J/wNBO2MBH/HMymyL0puu1fWxj+VyFPAeBgMRTbL1/hX6VmM+Bylp1mKmLrfS6VlJpRSQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dchuisJ+SMUCW3UvJNt1sybC0OWRLBHo54+nPU/5Sjc=; b=b4KTavVIXCXaKuz7dY1cv0LrppCmcWY0LgsNpvKgLG8sJSq7kjeuZgePzgMoaTulYzT6T8cs6pdJSJhcwb2loOhw0yuI6ciN6RpGT62UC/qAPizkB9HF9SS6Qx3KEQjzoX7PcPCG//4MUKELrht3S1OPZTMHnYB2zCNIFS8BZcY= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C From: Henry Wang To: CC: Henry Wang , Wei Liu , Anthony PERARD , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Alec Kwapis Subject: [PATCH v2 5/5] xen/memory, tools: Make init-dom0less consume XEN_DOMCTL_get_mem_map Date: Fri, 8 Mar 2024 09:54:35 +0800 Message-ID: <20240308015435.4044339-6-xin.wang2@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240308015435.4044339-1-xin.wang2@amd.com> References: <20240308015435.4044339-1-xin.wang2@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF00001CDD:EE_|PH7PR12MB7455:EE_ X-MS-Office365-Filtering-Correlation-Id: e0b20390-affa-4904-1240-08dc3f12c609 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hYS5GjdLVbARs8YBYv1+LhEnnAJk++V6YZLO7DGMPk4oBmPEHHKaxdk12rolQRQEqmHlOrwTPCCCr71C8uQvUcKC1vy84lCJaMFYMjbCcoLa+RxxTnCI2b/ianaYagcrgpDvL6zxSn383vFqGQCIjBlwhHLUueUqwFb7FCS5xQzED8ihBNJ3nJeIHAz+crWhpUoDxAoyqFO9Ex0imT1rs5qP+0XZLWd/SC06UJEKOjrcMrtvvYcZuFH6ST7E0CbIjgQlKFNQyO8T1faeJZvCNNKnjXI+Kf5xcLkQfXvMA9Xn6hLSfROahCU0IICoF+F7y35D4w/bcv+XD2AJ7DE0CmLYoFZVtDzOyK9R/qxCWHqGghtVR9Jehmu06FEebVU4YYiNGur2+oL3ZT837REZH6/wOywarJNx4KouzdsubsHNr1BSDtloGhNjbn7g7zl8mqQJvlpqL2AFP2a5Dza2wDpKPxfsaJgmnRfmTCLwAoKxs8inR5VwzpbXpH+kTjV7Ac4DWAHWMGwAEebSpyCA3QdtCj42k2eIVY15ykQX8v2a79TvspSBVqd4DJxg/lFshS1qc1CTXGVExsm4KvlwfMTv1wwIDy0eSj13AyTtU7fDG0tUdWiteMJFBBbXhsqg8+g3uAGZncsWsHpL4JHNM5YO3g8WvfEt4ctuKG/sfMuVpvcdHewanb3v3vOOXu02Fk6ShOOSEi9/y9OTTOe68TCLJFNApRDrshKayCiB7xF3pDl55i1ojIzI1lmyalFm X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(1800799015)(82310400014)(376005)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Mar 2024 01:55:04.2962 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e0b20390-affa-4904-1240-08dc3f12c609 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SJ1PEPF00001CDD.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB7455 Previous commits enable the toolstack to get the domain memory map, therefore instead of hardcoding the guest magic pages region, use the XEN_DOMCTL_get_mem_map domctl to get the start address of the guest magic pages region. Add the (XEN)MEMF_force_heap_alloc memory flags to force populate_physmap() to allocate page from domheap instead of using 1:1 or static allocated pages to map the magic pages. Reported-by: Alec Kwapis Signed-off-by: Henry Wang --- v2: - New patch --- tools/helpers/init-dom0less.c | 22 ++++++++++++++++++---- xen/common/memory.c | 10 ++++++++-- xen/include/public/memory.h | 5 +++++ xen/include/xen/mm.h | 2 ++ 4 files changed, 33 insertions(+), 6 deletions(-) diff --git a/tools/helpers/init-dom0less.c b/tools/helpers/init-dom0less.c index fee93459c4..92c612f6da 100644 --- a/tools/helpers/init-dom0less.c +++ b/tools/helpers/init-dom0less.c @@ -23,16 +23,30 @@ static int alloc_xs_page(struct xc_interface_core *xch, libxl_dominfo *info, uint64_t *xenstore_pfn) { - int rc; - const xen_pfn_t base = GUEST_MAGIC_BASE >> XC_PAGE_SHIFT; - xen_pfn_t p2m = (GUEST_MAGIC_BASE >> XC_PAGE_SHIFT) + XENSTORE_PFN_OFFSET; + int rc, i; + xen_pfn_t base = ((xen_pfn_t)-1); + xen_pfn_t p2m = ((xen_pfn_t)-1); + uint32_t nr_regions = XEN_MAX_MEM_REGIONS; + struct xen_mem_region mem_regions[XEN_MAX_MEM_REGIONS] = {0}; + + rc = xc_get_domain_mem_map(xch, info->domid, mem_regions, &nr_regions); + + for ( i = 0; i < nr_regions; i++ ) + { + if ( mem_regions[i].type == GUEST_MEM_REGION_MAGIC ) + { + base = mem_regions[i].start >> XC_PAGE_SHIFT; + p2m = (mem_regions[i].start >> XC_PAGE_SHIFT) + XENSTORE_PFN_OFFSET; + } + } rc = xc_domain_setmaxmem(xch, info->domid, info->max_memkb + (XC_PAGE_SIZE/1024)); if (rc < 0) return rc; - rc = xc_domain_populate_physmap_exact(xch, info->domid, 1, 0, 0, &p2m); + rc = xc_domain_populate_physmap_exact(xch, info->domid, 1, 0, + XENMEMF_force_heap_alloc, &p2m); if (rc < 0) return rc; diff --git a/xen/common/memory.c b/xen/common/memory.c index b3b05c2ec0..18b6c16aed 100644 --- a/xen/common/memory.c +++ b/xen/common/memory.c @@ -219,7 +219,8 @@ static void populate_physmap(struct memop_args *a) } else { - if ( is_domain_direct_mapped(d) ) + if ( is_domain_direct_mapped(d) && + !(a->memflags & MEMF_force_heap_alloc) ) { mfn = _mfn(gpfn); @@ -246,7 +247,8 @@ static void populate_physmap(struct memop_args *a) mfn = _mfn(gpfn); } - else if ( is_domain_using_staticmem(d) ) + else if ( is_domain_using_staticmem(d) && + !(a->memflags & MEMF_force_heap_alloc) ) { /* * No easy way to guarantee the retrieved pages are contiguous, @@ -1433,6 +1435,10 @@ long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg) && (reservation.mem_flags & XENMEMF_populate_on_demand) ) args.memflags |= MEMF_populate_on_demand; + if ( op == XENMEM_populate_physmap + && (reservation.mem_flags & XENMEMF_force_heap_alloc) ) + args.memflags |= MEMF_force_heap_alloc; + if ( xsm_memory_adjust_reservation(XSM_TARGET, curr_d, d) ) { rcu_unlock_domain(d); diff --git a/xen/include/public/memory.h b/xen/include/public/memory.h index 5e545ae9a4..2a1bfa5bfa 100644 --- a/xen/include/public/memory.h +++ b/xen/include/public/memory.h @@ -41,6 +41,11 @@ #define XENMEMF_exact_node(n) (XENMEMF_node(n) | XENMEMF_exact_node_request) /* Flag to indicate the node specified is virtual node */ #define XENMEMF_vnode (1<<18) +/* + * Flag to force populate physmap to use pages from domheap instead of 1:1 + * or static allocation. + */ +#define XENMEMF_force_heap_alloc (1<<19) #endif struct xen_memory_reservation { diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h index bb29b352ec..a4554f730d 100644 --- a/xen/include/xen/mm.h +++ b/xen/include/xen/mm.h @@ -205,6 +205,8 @@ struct npfec { #define MEMF_no_icache_flush (1U<<_MEMF_no_icache_flush) #define _MEMF_no_scrub 8 #define MEMF_no_scrub (1U<<_MEMF_no_scrub) +#define _MEMF_force_heap_alloc 9 +#define MEMF_force_heap_alloc (1U<<_MEMF_force_heap_alloc) #define _MEMF_node 16 #define MEMF_node_mask ((1U << (8 * sizeof(nodeid_t))) - 1) #define MEMF_node(n) ((((n) + 1) & MEMF_node_mask) << _MEMF_node)