From patchwork Fri Apr 26 03:14:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Henry Wang X-Patchwork-Id: 13644076 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 505F1C4345F for ; Fri, 26 Apr 2024 03:15:34 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.712372.1113023 (Exim 4.92) (envelope-from ) id 1s0C3S-0006hw-83; Fri, 26 Apr 2024 03:15:18 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 712372.1113023; Fri, 26 Apr 2024 03:15:18 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s0C3S-0006hp-4k; Fri, 26 Apr 2024 03:15:18 +0000 Received: by outflank-mailman (input) for mailman id 712372; Fri, 26 Apr 2024 03:15:16 +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 1s0C3Q-0006S7-KH for xen-devel@lists.xenproject.org; Fri, 26 Apr 2024 03:15:16 +0000 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on20600.outbound.protection.outlook.com [2a01:111:f403:2408::600]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 32b41996-037b-11ef-b4bb-af5377834399; Fri, 26 Apr 2024 05:15:14 +0200 (CEST) Received: from CH0PR03CA0299.namprd03.prod.outlook.com (2603:10b6:610:e6::34) by PH7PR12MB6442.namprd12.prod.outlook.com (2603:10b6:510:1fa::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.44; Fri, 26 Apr 2024 03:15:11 +0000 Received: from CH2PEPF0000009E.namprd02.prod.outlook.com (2603:10b6:610:e6:cafe::d8) by CH0PR03CA0299.outlook.office365.com (2603:10b6:610:e6::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7495.34 via Frontend Transport; Fri, 26 Apr 2024 03:15:11 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CH2PEPF0000009E.mail.protection.outlook.com (10.167.244.27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7519.19 via Frontend Transport; Fri, 26 Apr 2024 03:15:10 +0000 Received: from SATLEXMB04.amd.com (10.181.40.145) 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, 25 Apr 2024 22:15:09 -0500 Received: from henry-MS-7D54.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Thu, 25 Apr 2024 22:15:07 -0500 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: 32b41996-037b-11ef-b4bb-af5377834399 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=i2yE4NXzhxNSx+x05jrom/J+vMDhHaS58obvRvujK69bmHdPTxTzC5YLkWyZ4L3SzIS8v5l/Kqh+nCRPNTMghw6bLFV1jC1H/X9yNoolhf18Z8+VsWeA3XsWROJWNKMr/Jg3AeWxA9heTJm/G0lrO78XJLywC+TtzoWh74jVBzYzmCQOfwV7vsW6iPkh9WJPSg/KRM6meIQ41elmGfrKftn9qtJg4hVveMgj81FKL8KUSuXIi1cGWWSFCiXhC2fdIhUb9JHhArXVcuMVzfNUiHVhZgmsSOTcL/eWU3A3WKYFOcCH2yM295InSykozJdK0ZmK+7J/yRrYdTpqbFd+DA== 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=79RFzyR41EP2xOdusQsL3cCUdGSsRj3jsPfYKcWYOtc=; b=n7ZO5fnDW9g4SGd1F6Kgm7I90hxGGvhgyk7yEwbRdSDWx9QUmn/2sx98xael2OcNz5kPY6neIj0lmWwMZRLgVV09jQ7gyPXxYmPg0w5jZoqgfSHYNrroiQoeBxEy9N80kUuPAD43Bl0Sl+VGvTk6tVeAjMHd+6KIMHMBQBs/zQfLRtcu0sMnkvMfCxCvjID67olUOk7YwV17gh4+yErlKRE11QhTYdWhJMkofXPPM6yGJaPo262LVchnpDjKpSbKCI/qVVX5txJ/YRHnZMWoFJtmfQwxqbc3whc3aluEWucbvLBEYBX9F6mHa8wL1q4nUCM1rGAC2302G93IU5b8Tg== 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=79RFzyR41EP2xOdusQsL3cCUdGSsRj3jsPfYKcWYOtc=; b=NRnOHhO1lZLKsIicRAt3TCojVs0+1pl3v/Af0PdQRFaPOhc6D0RRJetTb9aTPbZDz0UvYmk/IMWj2TYldfxjn3xc2sqeOaaqCeuXQQGTZtAQ/fyWFFqw7zYBo4HOMnpAO6auhiXsBbBIkbTw8/DON0A7CwK5y75gBuqCfr6Ri3w= 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 , Anthony PERARD , Juergen Gross , "Stefano Stabellini" , Julien Grall , "Bertrand Marquis" , Michal Orzel , Volodymyr Babchuk , Alec Kwapis , "Daniel P . Smith" Subject: [PATCH 1/3] xen/arm/dom0less-build: Alloc magic pages for Dom0less DomUs from hypervisor Date: Fri, 26 Apr 2024 11:14:53 +0800 Message-ID: <20240426031455.579637-2-xin.wang2@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240426031455.579637-1-xin.wang2@amd.com> References: <20240426031455.579637-1-xin.wang2@amd.com> MIME-Version: 1.0 Received-SPF: None (SATLEXMB03.amd.com: xin.wang2@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PEPF0000009E:EE_|PH7PR12MB6442:EE_ X-MS-Office365-Filtering-Correlation-Id: f0f1c8d0-ff76-40eb-4c39-08dc659f1516 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: BJoor2yhWlS8Q9TdAnalVRMpEbFUVxO0b5hYAxbvRgGOs6N2eGjDERIxxYvsSADjwxZLpKhxadb+I8iN8QRoynRRs9uJVHQQmleyIGhkF+Q2ocI1aAnb/YkcDvHqWzegwarw9Kc+zm3shTcK1TUuV2isQr6gGOIHTAdA5evZ5I2/eXVtjROnjq9Jd1UoZOnnnwdTbu3TXbGppEt7sF5Kh3u4vuBNrOFAmHNj3nhjR9+lZvT9wMoitP0Zp5b6VKxj9xuFtbyvtoZCVwjrtNwOZdh3V7oIliTQe248KQOMrbwTYcTnKlitV0ytfZnQEyqpzsChNPbvgkbIJSOLUhgqjhXldxLjWsw1r6xh7pXm0KMbxfUJgMmtyXYRvbrbOrEv+6pb0CJBy5cxEU1fMtHJhFdPZAeuRA+tt0LUtilbkfT5y+616RD3JVg5ahXzRIrTjov/PQEvdM4bgJ3AlinqAl6jMyhxIGvtQGGC5WmicMQ8g6J0Nllabziuk0fMy65B/r/naDT4VHnSetVz4G+vy9FLQ5rg1gbOZ842vzjxfJOXJhbS4d0Oaka9wlVsbYQnJAirDm5tA8aGMYt1+YRKkEWNCo4En2pNlqdKry/ijkeRtzbFbHhq/IEHzMPVB2swIvsGeKjWN2oMC9jdTxKqSRgy1NvzjfTNp4KCaNFrCoVNKfAfpwwLnPvwCK5gqJVD6Rhfk69VY2+2TstSmpF8JRpUfnwBpdb9KiNstpuPRMBejkNoknwNU8KhTG0lXExiISo3qzl4hbwgj/A6Ph8c3Apbe1xnq5xpyWrKLXpKVk70c0zw5Cti01Cwv60vgzLOml65qYYoJfTdtgf7Pjx824F0qqtYAUDcDkyaLwCs7kJ7iVqsFwmxeJOf78BbvohXtaX/m77QS5QKaJaCKYcEewnk71M/3iAse7GjkBAYNMmSNWr2NAc/4xMKlBnDhQc2YpmQqwUnS9ZinRJ/fm1tOvWMTINyOzjYi7+dEhK/uyToStl00jgGAEH+x28MbHL8TnwGCe187i7gcZlIyCwyHQfA1semFwAWc5iagUtuNnO7AYiG2fRRznFMmfh9+DQghvONcjmOiHbQGaNzSen5tItee4YknPI1im7I4atCZWebWb0it96JPmut3bfStCf9VtmGKf1JnQjkOWq8re3RCFdB9LdExKYbpiKPiVhPnzeMyzcv373fqLC6k7broKdiAKTLwvq0EZhyHCHDNJuu0IAWu03krBeV5h0YFTQa9eAcz4RF3Hx0HOZQ9w6dTXWptRLKIyCZmwbVDDRGxFmuBSc2Hw/RsfLc8uPcIyOis1rzRTu/w+I7N6keUbisRby/Bzz59hN75YlZ6DzUkDN0UgXw5g15L3E2P9fNJn64pthDO3Dx7aP9cFC1EaiBQD5y 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)(376005)(36860700004)(82310400014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Apr 2024 03:15:10.7131 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f0f1c8d0-ff76-40eb-4c39-08dc659f1516 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: CH2PEPF0000009E.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6442 There are use cases (for example using the PV driver) in Dom0less setup that require Dom0less DomUs start immediately with Dom0, but initialize XenStore later after Dom0's successful boot and call to the init-dom0less application. An error message can seen from the init-dom0less application on 1:1 direct-mapped domains: ``` Allocating magic pages memory.c:238:d0v0 mfn 0x39000 doesn't belong to d1 Error on alloc magic pages ``` This is because currently the magic pages for Dom0less DomUs are populated by the init-dom0less app through populate_physmap(), and populate_physmap() automatically assumes gfn == mfn for 1:1 direct mapped domains. This cannot be true for the magic pages that are allocated later from the init-dom0less application executed in Dom0. For domain using statically allocated memory but not 1:1 direct-mapped, similar error "failed to retrieve a reserved page" can be seen as the reserved memory list is empty at that time. To solve above issue, this commit allocates the magic pages for Dom0less DomUs at the domain construction time. The base address/PFN of the magic page region will be noted and communicated to the init-dom0less application in Dom0. Reported-by: Alec Kwapis Suggested-by: Daniel P. Smith Signed-off-by: Henry Wang --- tools/libs/guest/xg_dom_arm.c | 1 - xen/arch/arm/dom0less-build.c | 22 ++++++++++++++++++++++ xen/include/public/arch-arm.h | 1 + 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/tools/libs/guest/xg_dom_arm.c b/tools/libs/guest/xg_dom_arm.c index 2fd8ee7ad4..8cc7f27dbb 100644 --- a/tools/libs/guest/xg_dom_arm.c +++ b/tools/libs/guest/xg_dom_arm.c @@ -25,7 +25,6 @@ #include "xg_private.h" -#define NR_MAGIC_PAGES 4 #define CONSOLE_PFN_OFFSET 0 #define XENSTORE_PFN_OFFSET 1 #define MEMACCESS_PFN_OFFSET 2 diff --git a/xen/arch/arm/dom0less-build.c b/xen/arch/arm/dom0less-build.c index fb63ec6fd1..40dc85c759 100644 --- a/xen/arch/arm/dom0less-build.c +++ b/xen/arch/arm/dom0less-build.c @@ -834,11 +834,33 @@ static int __init construct_domU(struct domain *d, if ( kinfo.dom0less_feature & DOM0LESS_XENSTORE ) { + struct page_info *magic_pg; + mfn_t mfn; + gfn_t gfn; + ASSERT(hardware_domain); rc = alloc_xenstore_evtchn(d); if ( rc < 0 ) return rc; d->arch.hvm.params[HVM_PARAM_STORE_PFN] = ~0ULL; + + d->max_pages += NR_MAGIC_PAGES; + magic_pg = alloc_domheap_pages(d, get_order_from_pages(NR_MAGIC_PAGES), 0); + if ( magic_pg == NULL ) + return -ENOMEM; + + mfn = page_to_mfn(magic_pg); + if ( !is_domain_direct_mapped(d) ) + gfn = gaddr_to_gfn(GUEST_MAGIC_BASE); + else + gfn = gaddr_to_gfn(mfn_to_maddr(mfn)); + + rc = guest_physmap_add_pages(d, gfn, mfn, NR_MAGIC_PAGES); + if ( rc ) + { + free_domheap_pages(magic_pg, get_order_from_pages(NR_MAGIC_PAGES)); + return rc; + } } return rc; diff --git a/xen/include/public/arch-arm.h b/xen/include/public/arch-arm.h index e167e14f8d..f24e7bbe37 100644 --- a/xen/include/public/arch-arm.h +++ b/xen/include/public/arch-arm.h @@ -475,6 +475,7 @@ typedef uint64_t xen_callback_t; #define GUEST_MAGIC_BASE xen_mk_ullong(0x39000000) #define GUEST_MAGIC_SIZE xen_mk_ullong(0x01000000) +#define NR_MAGIC_PAGES 4 #define GUEST_RAM_BANKS 2 From patchwork Fri Apr 26 03:14:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Henry Wang X-Patchwork-Id: 13644079 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 80049C10F15 for ; Fri, 26 Apr 2024 03:15:36 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.712373.1113034 (Exim 4.92) (envelope-from ) id 1s0C3Z-000703-JV; Fri, 26 Apr 2024 03:15:25 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 712373.1113034; Fri, 26 Apr 2024 03:15: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 1s0C3Z-0006zu-ER; Fri, 26 Apr 2024 03:15:25 +0000 Received: by outflank-mailman (input) for mailman id 712373; Fri, 26 Apr 2024 03:15:23 +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 1s0C3X-0006yc-SN for xen-devel@lists.xenproject.org; Fri, 26 Apr 2024 03:15:23 +0000 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on20600.outbound.protection.outlook.com [2a01:111:f403:200a::600]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 36945780-037b-11ef-909a-e314d9c70b13; Fri, 26 Apr 2024 05:15:21 +0200 (CEST) Received: from CY5PR03CA0010.namprd03.prod.outlook.com (2603:10b6:930:8::18) by BL1PR12MB5778.namprd12.prod.outlook.com (2603:10b6:208:391::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.48; Fri, 26 Apr 2024 03:15:18 +0000 Received: from CY4PEPF0000EE3C.namprd03.prod.outlook.com (2603:10b6:930:8:cafe::b5) by CY5PR03CA0010.outlook.office365.com (2603:10b6:930:8::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.23 via Frontend Transport; Fri, 26 Apr 2024 03:15:17 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EE3C.mail.protection.outlook.com (10.167.242.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7519.19 via Frontend Transport; Fri, 26 Apr 2024 03:15:16 +0000 Received: from SATLEXMB04.amd.com (10.181.40.145) 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, 25 Apr 2024 22:15:16 -0500 Received: from henry-MS-7D54.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Thu, 25 Apr 2024 22:15:12 -0500 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: 36945780-037b-11ef-909a-e314d9c70b13 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FbGmz2BO2gqZWZRz4mAacfOjOhL9G9G3ZqWIKRVIXilya8dCvw6orfFANiyGpvslaoGLtsEWRya9376dMB7DTLtJHE0pWaHYzPwTWvmZioUpLslkMnfj4cVu4CWj4X8rDB6dVVIW+fB4d42sOvS+3saKQ3s23WGS07MH9GZ+Ewk1Pbyd2fgtiNCImqmQSA7c7LevKbVp1fMjUUJGfmuKTOmpzuGE9eLQQIeaywSBXKhlSw5mkFpq2XIsZ4+7ezYqtUFAyQQ+pZpX8j/LwinFLJGgBkQlZ4sPijNx7reeq4Pih6OnnsWeTdzbuci+BkQIPMLsewGj+D+NC23nh3jVUQ== 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=hoINEpwEgGiddQ725fJgeiRoPqfe/wX4qgGl/EaGEJc=; b=G7FKfwHv5G3Z4JgaGKlqwQdAbgJWq5mZYhRZLeegnG4CfIsttFQYF+LQzrmQmh9jkn2TSWBnCks8GW4ZhRR4T+758OFB3SB4vEUxtQhUjxm2wePC1f78XHwqA97Yw56gWr1BtqZXylMSF1MbX5j84hRTFGONqKjdsg38oii7W7fy6Go1wcOtiZlh4GtydRRrkHVEoNjPnZVhV8PgFBBGZ3KKKXSUNNBDmWF9ZLNEuSTz5K9WPYJKyyrcV4ziAGAxbm5560QYBpFlMckaIIG/oHjZw5biPCgpLLMkKqyd2xC/eK66TcbmZNX4U3OtivpQw5J99QPH8fHugPDlr1TupQ== 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=hoINEpwEgGiddQ725fJgeiRoPqfe/wX4qgGl/EaGEJc=; b=dbBBrRI7KSsUoqgw+xpwqSOpPCSq+z3QSFvZdhWte8gPRpjk0feuHF1HuXlZb9VMGhp+dkZ1LM8Kc/Q+d8xUxdq2/+CQXOKYTagNfxmcaXKC/PSNHHrPGgvssmqPOZlO2BGS9AYqoibVS4EFkTqxKX/q2GFit/MUrTvvrd/9QuQ= 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 , Anthony PERARD , Juergen Gross , Andrew Cooper , George Dunlap , "Jan Beulich" , Julien Grall , "Stefano Stabellini" , Bertrand Marquis , Michal Orzel , "Volodymyr Babchuk" , Alec Kwapis Subject: [PATCH 2/3] xen/arm, tools: Add a new HVM_PARAM_MAGIC_BASE_PFN key in HVMOP Date: Fri, 26 Apr 2024 11:14:54 +0800 Message-ID: <20240426031455.579637-3-xin.wang2@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240426031455.579637-1-xin.wang2@amd.com> References: <20240426031455.579637-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: CY4PEPF0000EE3C:EE_|BL1PR12MB5778:EE_ X-MS-Office365-Filtering-Correlation-Id: 640962ea-cd20-4f0b-3f02-08dc659f18b2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Fe5k8i/1h54zu1P00NTC8m4VgasSQicyS/hOPdn9T+DaDo8Cx3QFGFHKu8uGRyy3xKiq2Ufn3VCHzDRYc1Ji1hJH4kOvAJRfXH76PIwoiORwX4sIp5u99brXPMQcrbpSXptWJkaBnRpo4HuNDKrzJM7I5skxD0NmaV9ouErfhkr9/+gGPQL2ucM8htcJc0KtfW+JgiqyjlJotK1rgMX1dITd/6B0DffPNrvv/0j9wheuarCi7hxuVEiJaRqdglB5yj8qMAC4g1wzaG+w34FLinuvw9+0SfiIrO8m302S64fVMx2A/SHTwzOzsBkmPDps38b9AEQuQyWwWphGWJtSaKVH4Fj302pr60oDYYxHh/Oj7tbG86peVnKd+SXbkfeUixiDnJ2fEfTgl7eXM91g5WViwYpXWQzG3S3NQFAMVHuTC8l3bvx8qFpgSAnSI2XRVPH6Lb9mZumtgdgVcy48LlkAow40OoIM7yZXI19dcwuLchIZp0Dhi8VQVTV7qqAdWs2LWL3Yc/nsxRgBBzALvKODCrc8qdOYjtoUJgk7dpCciPn4WXY35DSGAkOfSAdPeAxLKizAWA0aKyGmX7JGZuQEw5cnYzT3PSaF2q0chmBMZNzRsWnpddIlZ/R7WrzfVpQdjy9EbKILSEfN07V/ehoCtwb+bWC7AAVavMyHa5JWa3F6YGXbwCtIGPLzw74sh/fYRim7vllEKp7KOEw/rwAUu25pSD5h/d5p+Ql5udIgdhq43QQNr5Cr3TrsbWzITIQY0MAXjGIboCG9Z26wY+PDauuwh3uGDSPUjJLqEBQKdX1wvYGOEjkRfNY0DzuwUmyfh4GggFqLkgPGv7206Zw1VwInTg96X++RmPKqRJ7mFn8ofmjP+bVhi2+MKtg84uA1EgS89nApNrESw1vMqj/w0+Y57es2NqrwE+650Jt1iUlQ+v2Zm/h6AHWg+BTK0cx13OAcoVlg+q2f8hfQNpQ8qWAvkBe8JeVLc8cYznWeERz/jlrFgFl/CjSUFHqX7zEqkAxjW7MrZmORfxMdPLhITnhCnU3sM6nPY7fEsvJxr7OjBqslRibp3Zi20KoH/jZ5XnffJPbjouV1CeAcUPWipIIT9F+TJHMov1CBKKQyPt/gXWLeFmFcxDHW8R2GyAbObftKf+fZIu0GYexA9Z20PuB1L9QbcDXIuH/lGwOBiFVXTbPwsuYttD3lMTQ04NFGf5e70MvJpyli0S1Y7fRtTkSXHGgcSZ5pBU9K6bUxra5LoUN9M2AfKzPFsp5cYN79WjHcnrZCVRPe4hUKiaN3JD+wtFMJi3qg7CR8orWFTRmky6MqmoDPZyUs0SFMng1K8sH15OAcZUsogVM/hVpmZSJL7RXk5Df58LIPhzRLfZ9YvpabDfcTvMics3MS 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)(376005)(36860700004)(1800799015)(7416005)(82310400014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Apr 2024 03:15:16.7214 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 640962ea-cd20-4f0b-3f02-08dc659f18b2 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: CY4PEPF0000EE3C.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5778 For use cases such as Dom0less PV drivers, a mechanism to communicate Dom0less DomU's static data with the runtime control plane (Dom0) is needed. Since on Arm HVMOP is already the existing approach to address such use cases (for example the allocation of HVM_PARAM_CALLBACK_IRQ), add a new HVMOP key HVM_PARAM_MAGIC_BASE_PFN for storing the magic page region base PFN. The value will be set at Dom0less DomU construction time after Dom0less DomU's magic page region has been allocated. To keep consistent, also set the value for HVM_PARAM_MAGIC_BASE_PFN for libxl guests in alloc_magic_pages(). Reported-by: Alec Kwapis Signed-off-by: Henry Wang --- tools/libs/guest/xg_dom_arm.c | 2 ++ xen/arch/arm/dom0less-build.c | 2 ++ xen/arch/arm/hvm.c | 1 + xen/include/public/hvm/params.h | 1 + 4 files changed, 6 insertions(+) diff --git a/tools/libs/guest/xg_dom_arm.c b/tools/libs/guest/xg_dom_arm.c index 8cc7f27dbb..3c08782d1d 100644 --- a/tools/libs/guest/xg_dom_arm.c +++ b/tools/libs/guest/xg_dom_arm.c @@ -74,6 +74,8 @@ static int alloc_magic_pages(struct xc_dom_image *dom) xc_clear_domain_page(dom->xch, dom->guest_domid, base + MEMACCESS_PFN_OFFSET); xc_clear_domain_page(dom->xch, dom->guest_domid, dom->vuart_gfn); + xc_hvm_param_set(dom->xch, dom->guest_domid, HVM_PARAM_MAGIC_BASE_PFN, + base); xc_hvm_param_set(dom->xch, dom->guest_domid, HVM_PARAM_CONSOLE_PFN, dom->console_pfn); xc_hvm_param_set(dom->xch, dom->guest_domid, HVM_PARAM_STORE_PFN, diff --git a/xen/arch/arm/dom0less-build.c b/xen/arch/arm/dom0less-build.c index 40dc85c759..72187c167d 100644 --- a/xen/arch/arm/dom0less-build.c +++ b/xen/arch/arm/dom0less-build.c @@ -861,6 +861,8 @@ static int __init construct_domU(struct domain *d, free_domheap_pages(magic_pg, get_order_from_pages(NR_MAGIC_PAGES)); return rc; } + + d->arch.hvm.params[HVM_PARAM_MAGIC_BASE_PFN] = gfn_x(gfn); } return rc; diff --git a/xen/arch/arm/hvm.c b/xen/arch/arm/hvm.c index 0989309fea..fa6141e30c 100644 --- a/xen/arch/arm/hvm.c +++ b/xen/arch/arm/hvm.c @@ -55,6 +55,7 @@ static int hvm_allow_get_param(const struct domain *d, unsigned int param) case HVM_PARAM_STORE_EVTCHN: case HVM_PARAM_CONSOLE_PFN: case HVM_PARAM_CONSOLE_EVTCHN: + case HVM_PARAM_MAGIC_BASE_PFN: return 0; /* diff --git a/xen/include/public/hvm/params.h b/xen/include/public/hvm/params.h index a22b4ed45d..c1720b33b9 100644 --- a/xen/include/public/hvm/params.h +++ b/xen/include/public/hvm/params.h @@ -76,6 +76,7 @@ */ #define HVM_PARAM_STORE_PFN 1 #define HVM_PARAM_STORE_EVTCHN 2 +#define HVM_PARAM_MAGIC_BASE_PFN 3 #define HVM_PARAM_IOREQ_PFN 5 From patchwork Fri Apr 26 03:14:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Henry Wang X-Patchwork-Id: 13644078 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 BF3C7C19F4E for ; Fri, 26 Apr 2024 03:15:36 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.712374.1113043 (Exim 4.92) (envelope-from ) id 1s0C3a-0007G6-Ra; Fri, 26 Apr 2024 03:15:26 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 712374.1113043; Fri, 26 Apr 2024 03:15:26 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s0C3a-0007Fz-Ny; Fri, 26 Apr 2024 03:15:26 +0000 Received: by outflank-mailman (input) for mailman id 712374; Fri, 26 Apr 2024 03:15:25 +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 1s0C3Z-0006yc-UR for xen-devel@lists.xenproject.org; Fri, 26 Apr 2024 03:15:25 +0000 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on20601.outbound.protection.outlook.com [2a01:111:f403:2417::601]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 3967c6c0-037b-11ef-909a-e314d9c70b13; Fri, 26 Apr 2024 05:15:25 +0200 (CEST) Received: from DM6PR02CA0045.namprd02.prod.outlook.com (2603:10b6:5:177::22) by CY5PR12MB6525.namprd12.prod.outlook.com (2603:10b6:930:32::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.44; Fri, 26 Apr 2024 03:15:22 +0000 Received: from DS1PEPF00017093.namprd03.prod.outlook.com (2603:10b6:5:177:cafe::2d) by DM6PR02CA0045.outlook.office365.com (2603:10b6:5:177::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.27 via Frontend Transport; Fri, 26 Apr 2024 03:15:22 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by DS1PEPF00017093.mail.protection.outlook.com (10.167.17.136) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7519.19 via Frontend Transport; Fri, 26 Apr 2024 03:15:22 +0000 Received: from SATLEXMB04.amd.com (10.181.40.145) 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, 25 Apr 2024 22:15:21 -0500 Received: from henry-MS-7D54.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Thu, 25 Apr 2024 22:15:20 -0500 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: 3967c6c0-037b-11ef-909a-e314d9c70b13 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=f6JQJ5tb/wzo7lju7iSH21rYKMSURdjryZq7gdDAnlcb5loNEVtHMKlzsEyN3z5M9Z+CtcAxqvrvCUFIDBCMs4/lxmJpZRe7ur9sB4AvhM4CUG0+csPPUSDWVsy82dcgNtvhMJn+4nPtcfr+azyVr9nNWzX6Pcq16hiIytY2Vds4oTyvhwJ7qrnMh6kw/WqBqt7VfU66sQqqyg0MEgLqP7MnTNBHXAjZOIM16/Py+GjNIejZYGTVjC1I7+bq2e1GH/gTU1Agj2IbBVAVHh0FTq8bq0GUErkVEXqrbLZgMEPJi1gUYTekL7OPmoKHKGJugCp8YWR5zzndYLaS1unYvg== 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=U9NhlDanGQKebTLZq79LUOppo21Q/6jmY2OxbeF0g1k=; b=oNVD4r+MyPJKts8Ltr1lPnwlhF2CE43KB0W3i5hSXeRPaM2bSujsTSRj/ZZocoB0ChwoAh5zLCfBlQU9Y20hORLbO8cSelDegrbbUKmkgW9bC5i6F/IrQ05IwDPvxaF64XiFro2etz2SfAud/IJf+XmaDPSCaTN7jSUUNQBdwQVYaGHPmwfYyIYqt0tZCwrllvDtLoZJ36HJukaDbqwqrgVw4utLY5Gwh+QBbLk6Lna/kcKuMRKRf01XaFcEuL08SPKnCEf6wKAoF6/lJtJTqSgc0GflGK+atnZZJniiCqUoRwfHfhro3iMwiyj5UUKBcb9+84R3tccgnVxheV7xOw== 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=U9NhlDanGQKebTLZq79LUOppo21Q/6jmY2OxbeF0g1k=; b=PNfZP+70Pb8zycoYAUUVs7U7zyhxIx/FgFeNfyiB6m4ueziSZGrrh3KOqfcL2D5YVKfbE9Xht73M2SqR+UTxHKDxi47RKhHMrGOkstAwry+zuY8TetUZ0HhEJVryyEWJqUSs0E9NrlOyVidW6UmU7khI+BecmbZwvmpI8Bg8GeA= 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 , Anthony PERARD , Alec Kwapis Subject: [PATCH 3/3] tools/init-dom0less: Avoid hardcoding GUEST_MAGIC_BASE Date: Fri, 26 Apr 2024 11:14:55 +0800 Message-ID: <20240426031455.579637-4-xin.wang2@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240426031455.579637-1-xin.wang2@amd.com> References: <20240426031455.579637-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: DS1PEPF00017093:EE_|CY5PR12MB6525:EE_ X-MS-Office365-Filtering-Correlation-Id: a7f967ab-7afa-42b1-637e-08dc659f1bd6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +JpSYwXogpkByo6s6Bk9UC+I7nOv7+wtbqnsHPoHC9B0BqF50UpV/nK0p7QSxMhYB0o0E4ZOqR7mUmOirRi+Ch5FlzJsmvkAtuiQrN0TRM1H8a1IVjcSuCWLnYrJdowrhlcsMHp9mhXdN9+WtMtq1PwutTp/oo7eCOaVsc7TtZnXvH64FpcLJDw/ClLAuuHLfBuFCEjw/ogPHycEOWruy7R0NorTUVkaEfFhySqzs3wZFOVa/IAlpbXio974KlCXr6RFpuIzynYCfg/Z5DEVqYflJQzazJVrPIkt/KXhA0EjVrH11TkHepKd+ytze0P4KxMejZ05uObPiILvbv5VVmCME2z1jwBkTECjLfF2q8hjgFoY5W1Q1zYFasoCDzkkNIy3ztGEp4yGsRK6kWpV4j7s76sn2VNJpDmSHZkL8i5YCsYom90ROYahmmPVDn/B/SY73ZtylBpgusIJqId5CLJE72AVAL/+f+A75Cx1zJShOoYnXPuwtJjqGU6SF9Sk3LSsFUZ+Bqeg+vKFB5ikbL7rWJf4bEyfVNY+hCnOTV6DFKW+zIX3+DGMS6/SPcAGpjLAIAMRAU3VWiK+HigE9cgqZ4LFaFLtHJSAUFCaiCqUJyyK65xCrXQWk3LW7r51dr3csNzhDkEiQlLaG7U+53RZoKGEBdP9JKSHXGOS+U1E+fqc7UaABSG1vKBGr9ExgN8eLlhsqnHa9ixfE/6t7xlGTiqwle83Nd1jbnlDc41iQqMIwAgQADESNCmkMDIl4FRChQmCnEIDipn/H2cSDNUrGhlq+yr4flssRHwiYlJN8o+zHOTz6GTwQEcM3UKSSDTAjDDIk8u4+o4TA1AmSAbkXHZPMHJbUWm2tEjtxvJdEkdHppzxMo7RRAETav+cSJvMpG+t3RRgNXw9s4pBgMHz4IIw9Kv8KLBsDLvNrdE7zu0vrtqDnkXyBYVRlWx9HVPJ+INdq8uiHK4BsKBlr3kZ74GDNbvbqUfcr3aBf/EbCNb63iC/u4QMJQzw6HtnjTHRGobrERXBEsNGpBBTV0BWpEqhbhWGzZdCVw0PwCWB+8RjhS3Lpo33ry/TMlfQzSNKozhFIkGE6hT38UrSIGGdIpFl+IERzXrNFJhKycZMv8h4ffQGxUTTEY9r0PpsHreIYZiYWvnL3Ie1hdHGMpzCxbps2t7V6IoFj8PScOePcXrxU3TXQHWFBAr8Z0VQuHAnL9vOW4YrVb2kTeEQ4VxCIxqMTD4L0WmC9ZVzZCWfMBNsmwBFQrmOCp68+zk2Jg1WGyY1OUxjY7N/Ew6mDW/MLSKE6GiQ00zq+vhZMWcZ+9Fvu9g9XL1bGSHqleOWlfmrJLi7wibb3fQnIyXmc7RDJixpbMBLjoVNa85vdQWnLSOmMLNnGXslwwAoAxcY 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)(36860700004)(376005)(82310400014)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Apr 2024 03:15:22.0227 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a7f967ab-7afa-42b1-637e-08dc659f1bd6 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: DS1PEPF00017093.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6525 Currently the GUEST_MAGIC_BASE in the init-dom0less application is hardcoded, which will lead to failures for 1:1 direct-mapped Dom0less DomUs. Since the guest magic region is now allocated from the hypervisor, instead of hardcoding the guest magic pages region, use xc_hvm_param_get() to get the guest magic region PFN, and based on that the XenStore PFN can be calculated. Also, we don't need to set the max mem anymore, so drop the call to xc_domain_setmaxmem(). Rename the alloc_xs_page() to get_xs_page() to reflect the changes. Take the opportunity to do some coding style improvements when possible. Reported-by: Alec Kwapis Signed-off-by: Henry Wang --- tools/helpers/init-dom0less.c | 38 +++++++++++++++-------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/tools/helpers/init-dom0less.c b/tools/helpers/init-dom0less.c index fee93459c4..7f6953a818 100644 --- a/tools/helpers/init-dom0less.c +++ b/tools/helpers/init-dom0less.c @@ -19,24 +19,20 @@ #define XENSTORE_PFN_OFFSET 1 #define STR_MAX_LENGTH 128 -static int alloc_xs_page(struct xc_interface_core *xch, - libxl_dominfo *info, - uint64_t *xenstore_pfn) +static int get_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; + xen_pfn_t magic_base_pfn; - 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); - if (rc < 0) - return rc; + rc = xc_hvm_param_get(xch, info->domid, HVM_PARAM_MAGIC_BASE_PFN, + &magic_base_pfn); + if (rc < 0) { + printf("Failed to get HVM_PARAM_MAGIC_BASE_PFN\n"); + return 1; + } - *xenstore_pfn = base + XENSTORE_PFN_OFFSET; + *xenstore_pfn = magic_base_pfn + XENSTORE_PFN_OFFSET; rc = xc_clear_domain_page(xch, info->domid, *xenstore_pfn); if (rc < 0) return rc; @@ -100,6 +96,7 @@ static bool do_xs_write_vm(struct xs_handle *xsh, xs_transaction_t t, */ static int create_xenstore(struct xs_handle *xsh, libxl_dominfo *info, libxl_uuid uuid, + xen_pfn_t xenstore_pfn, evtchn_port_t xenstore_port) { domid_t domid; @@ -145,8 +142,7 @@ static int create_xenstore(struct xs_handle *xsh, rc = snprintf(target_memkb_str, STR_MAX_LENGTH, "%"PRIu64, info->current_memkb); if (rc < 0 || rc >= STR_MAX_LENGTH) return rc; - rc = snprintf(ring_ref_str, STR_MAX_LENGTH, "%lld", - (GUEST_MAGIC_BASE >> XC_PAGE_SHIFT) + XENSTORE_PFN_OFFSET); + rc = snprintf(ring_ref_str, STR_MAX_LENGTH, "%"PRIu_xen_pfn, xenstore_pfn); if (rc < 0 || rc >= STR_MAX_LENGTH) return rc; rc = snprintf(xenstore_port_str, STR_MAX_LENGTH, "%u", xenstore_port); @@ -245,8 +241,8 @@ static int init_domain(struct xs_handle *xsh, if (!xenstore_evtchn) return 0; - /* Alloc xenstore page */ - if (alloc_xs_page(xch, info, &xenstore_pfn) != 0) { + /* Get xenstore page */ + if (get_xs_page(xch, info, &xenstore_pfn) != 0) { printf("Error on alloc magic pages\n"); return 1; } @@ -278,13 +274,11 @@ static int init_domain(struct xs_handle *xsh, if (rc < 0) return rc; - rc = create_xenstore(xsh, info, uuid, xenstore_evtchn); + rc = create_xenstore(xsh, info, uuid, xenstore_pfn, xenstore_evtchn); if (rc) err(1, "writing to xenstore"); - rc = xs_introduce_domain(xsh, info->domid, - (GUEST_MAGIC_BASE >> XC_PAGE_SHIFT) + XENSTORE_PFN_OFFSET, - xenstore_evtchn); + rc = xs_introduce_domain(xsh, info->domid, xenstore_pfn, xenstore_evtchn); if (!rc) err(1, "xs_introduce_domain"); return 0;