From patchwork Fri May 17 03:21: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: 13666614 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 DC7E7C25B77 for ; Fri, 17 May 2024 03:23:38 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.723785.1128865 (Exim 4.92) (envelope-from ) id 1s7oBv-0006ql-MP; Fri, 17 May 2024 03:23:31 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 723785.1128865; Fri, 17 May 2024 03:23:31 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s7oBv-0006qe-Jf; Fri, 17 May 2024 03:23:31 +0000 Received: by outflank-mailman (input) for mailman id 723785; Fri, 17 May 2024 03:23:29 +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 1s7oBt-0006l6-I6 for xen-devel@lists.xenproject.org; Fri, 17 May 2024 03:23:29 +0000 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on20601.outbound.protection.outlook.com [2a01:111:f403:2417::601]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id d34aecf3-13fc-11ef-b4bb-af5377834399; Fri, 17 May 2024 05:23:28 +0200 (CEST) Received: from PH7PR03CA0003.namprd03.prod.outlook.com (2603:10b6:510:339::8) by CH3PR12MB9283.namprd12.prod.outlook.com (2603:10b6:610:1cd::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.30; Fri, 17 May 2024 03:23:23 +0000 Received: from SN1PEPF000252A1.namprd05.prod.outlook.com (2603:10b6:510:339:cafe::4f) by PH7PR03CA0003.outlook.office365.com (2603:10b6:510:339::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.29 via Frontend Transport; Fri, 17 May 2024 03:23:23 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by SN1PEPF000252A1.mail.protection.outlook.com (10.167.242.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7587.21 via Frontend Transport; Fri, 17 May 2024 03:23:22 +0000 Received: from SATLEXMB05.amd.com (10.181.40.146) 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, 16 May 2024 22:22:45 -0500 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB05.amd.com (10.181.40.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 16 May 2024 22:22:06 -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, 16 May 2024 22:22:04 -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: d34aecf3-13fc-11ef-b4bb-af5377834399 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=n9e5/ovVTWjkuuRvPCpt/+SZKX1pA6iH5NwxqjN7Eqt9Nt9yOk7jUI6wYZgSB/loO8hslJCdDKWh7LTpBeG2aKtKYJaHJ0ItlkdbD76iKza/dlmY28J0bRomijpsvkrmK2TiIZw0VgIpZCnCFqjeNp2n3W7bT/dv+jd0X+xfRG1ohhLkOMPXiv/NVbQK3oUPsGZQZIhv4n7CE3w5YeYrB9DRNn8UT1I9MQwl7xRG0lS+UwBurs/szKjHH06zvuc2p19uiEWb6RMLJ35ZCRlW45GfQCAsuxOTNeh6p6qdNiGf1ZXGPxf61UPjeX1oXCNV/Xc/Bi9pk61YpVM7fDHCkA== 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=d07nHhnz+E2r01WFGPEt/6CKVIk3TuRy1RIwAxzVZg8=; b=NZvFQIvZKZIPVK7wUXoqVgCJf3IxmM2cLNB8VZDkPZQByKcyfuKcNW6XJMIRSc5L/MJlS3Iu6q0Q9I/DG0Qn+vR+S4ErIZlMCfoGUsmuK8T5yNTGpiUtKxj3/oWzaeno9hfTrDGxacR93qGMs2mkZf4Q5Na6RQCFQblh9aJb/h1U6YKmArS+U+gmhuOwi8lpXgqvbfgFTbIrxFxlsr//Z2MQfspV24ZDFIa3FbWKlgs9gO/tFkLA1YUUCJCJ9op8HWTsI+RNuiEUIvXF12bQ/tK3SGiufPRYeGFHkRcQLHhQkga2QP9ixKjvGoBJ5YAitsA+UU58G1paTqvplPNjSg== 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=d07nHhnz+E2r01WFGPEt/6CKVIk3TuRy1RIwAxzVZg8=; b=0agY+9cxmafoZu2T+FJeoPF8TsVf7XQ0Ruu8n39kIikZjOkbIWcfELta3NPO4Ok3nqSfXw9bnmcEGyG1xKWPIhL8PMaEVoAj0z/lnfISGvE6g9ZEMLwf7M1TUKTI6cWYX7FvO/a0iAqA5uCIytmYksR4WVgwWXYeYfa7WHTRcOo= 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 v3 1/4] xen/arm/static-shmem: Static-shmem should be direct-mapped for direct-mapped domains Date: Fri, 17 May 2024 11:21:53 +0800 Message-ID: <20240517032156.1490515-2-xin.wang2@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240517032156.1490515-1-xin.wang2@amd.com> References: <20240517032156.1490515-1-xin.wang2@amd.com> MIME-Version: 1.0 Received-SPF: None (SATLEXMB05.amd.com: xin.wang2@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF000252A1:EE_|CH3PR12MB9283:EE_ X-MS-Office365-Filtering-Correlation-Id: 1cc80ec2-fb9c-48ee-4b07-08dc7620b527 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|36860700004|1800799015|82310400017|376005; X-Microsoft-Antispam-Message-Info: 0DvR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OwuiU0BS6YuwTWtmBCq+nln6fWr4F+OJeHHNhuGuUGHm+58G0/n+MbEsE8egRTNvdYN/ZgEA/FJ2XN24Zzzc0z7f0y7MGhKdH2Vn5OsS/8pcb3UwOUtZzZLkCh0dIKZEMLQv00RjjcT8DImvCUDfMQXbx8EENxbdNJKaKblsi7hMOANtSdQ9KGGMXayQmDfnBzf9CvRRsndu0myXPt/Gnxc2kYEaKOjAZDlPOS7bSNzw46etBxlKAe9G6od+U+/7/MbyOO9NRbQ5b3oUlnsZP9A1l6l77LVSJNtVp0YoSot8Cyo5p9fR1gtOGfewaMOoiJy4PiW3wC8 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)(1800799015)(82310400017)(376005);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 May 2024 03:23:22.9425 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1cc80ec2-fb9c-48ee-4b07-08dc7620b527 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: SN1PEPF000252A1.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB9283 Currently, users are allowed to map static shared memory in a non-direct-mapped way for direct-mapped domains. This can lead to clashing of guest memory spaces. Also, the current extended region finding logic only removes the host physical addresses of the static shared memory areas for direct-mapped domains, which may be inconsistent with the guest memory map if users map the static shared memory in a non-direct-mapped way. This will lead to incorrect extended region calculation results. To make things easier, add restriction that static shared memory should also be direct-mapped for direct-mapped domains. Check the host physical address to be matched with guest physical address when parsing the device tree. Document this restriction in the doc. Signed-off-by: Henry Wang Acked-by: Michal Orzel --- v3: - New patch. --- docs/misc/arm/device-tree/booting.txt | 3 +++ xen/arch/arm/static-shmem.c | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/docs/misc/arm/device-tree/booting.txt b/docs/misc/arm/device-tree/booting.txt index bbd955e9c2..c994e48391 100644 --- a/docs/misc/arm/device-tree/booting.txt +++ b/docs/misc/arm/device-tree/booting.txt @@ -591,6 +591,9 @@ communication. shared memory region in host physical address space, a size, and a guest physical address, as the target address of the mapping. e.g. xen,shared-mem = < [host physical address] [guest address] [size] > + Note that if a domain is direct-mapped, i.e. the Dom0 and the Dom0less + DomUs with `direct-map` device tree property, the static shared memory + should also be direct-mapped (host physical address == guest address). It shall also meet the following criteria: 1) If the SHM ID matches with an existing region, the address range of the diff --git a/xen/arch/arm/static-shmem.c b/xen/arch/arm/static-shmem.c index 78881dd1d3..b26fb69874 100644 --- a/xen/arch/arm/static-shmem.c +++ b/xen/arch/arm/static-shmem.c @@ -235,6 +235,12 @@ int __init process_shm(struct domain *d, struct kernel_info *kinfo, d, psize); return -EINVAL; } + if ( is_domain_direct_mapped(d) && (pbase != gbase) ) + { + printk("%pd: physical address 0x%"PRIpaddr" and guest address 0x%"PRIpaddr" are not 1:1 direct-mapped.\n", + d, pbase, gbase); + return -EINVAL; + } for ( i = 0; i < PFN_DOWN(psize); i++ ) if ( !mfn_valid(mfn_add(maddr_to_mfn(pbase), i)) ) From patchwork Fri May 17 03:21: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: 13666615 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 4B59DC04FFE for ; Fri, 17 May 2024 03:24:07 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.723789.1128874 (Exim 4.92) (envelope-from ) id 1s7oCP-0007M4-1i; Fri, 17 May 2024 03:24:01 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 723789.1128874; Fri, 17 May 2024 03:24:01 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s7oCO-0007Lx-VK; Fri, 17 May 2024 03:24:00 +0000 Received: by outflank-mailman (input) for mailman id 723789; Fri, 17 May 2024 03:23:59 +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 1s7oCN-0007En-Mo for xen-devel@lists.xenproject.org; Fri, 17 May 2024 03:23:59 +0000 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on20601.outbound.protection.outlook.com [2a01:111:f403:2416::601]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id e5f63868-13fc-11ef-909e-e314d9c70b13; Fri, 17 May 2024 05:23:58 +0200 (CEST) Received: from CH0PR03CA0067.namprd03.prod.outlook.com (2603:10b6:610:cc::12) by CH3PR12MB7643.namprd12.prod.outlook.com (2603:10b6:610:152::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.28; Fri, 17 May 2024 03:23:55 +0000 Received: from CH2PEPF00000146.namprd02.prod.outlook.com (2603:10b6:610:cc:cafe::43) by CH0PR03CA0067.outlook.office365.com (2603:10b6:610:cc::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.28 via Frontend Transport; Fri, 17 May 2024 03:23:55 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CH2PEPF00000146.mail.protection.outlook.com (10.167.244.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7587.21 via Frontend Transport; Fri, 17 May 2024 03:23:54 +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, 16 May 2024 22:23:02 -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, 16 May 2024 22:22:45 -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: e5f63868-13fc-11ef-909e-e314d9c70b13 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cM3+el3unuMU10rud3w2f70OlJrNpEKvpi+Q+OTAguVkxqQy1EGeh/zPDVabehbt5UAYwVtDGzdoEVVs9f0pcAP3D1hiqLCsNp99Y95aQZCGNAoPLJngnq968MDZ8WtqUMGF8Dy36NhGvVgtDVLc2Fohu7KNgXgNDuvjxScGAQHP6e+3eYI66E/naS05C1kuGR0E9NcQ3+KQlU7v3F/3dA35TaQo3utrE+e9ck7aqNnU5Ro1UdTdFKAL9ZXwIe72WZ/mO/w+MKIL9IkfVX7gI67rZspCVlOPXLpUvBO1TflUNjSoODhOhDSd6Glj2pvhLP1NPYjipcglmkK9XXkxxw== 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=fG1F9XegT/sJSYG6Fu85jzQtPZmim9YqynPLlOCoLeE=; b=lgWrhr1X7NFphekaFNfrMFCNl6qK1tkr++mr4XDCxGz/A9km37nU5ngwIcy4HRirjmSGcR/82t8BwQO5yAm5Gi34Ixd8m70wBxb0eqgYZgFWME37+kjNhYnP6jA3qZ+PS5OvrI4LFBOCTJ748mBJIkbK8KyjVIpLP+th/bmGgaUZvlF//bFMQtGiGxXNI/vWQu0C2VJGdKfp2xNNr5ttIIylc6dQl6+xTRFMd3BGgvAuKY0TFN8xxl/SyR87G1UihkM/U0LqXQbFvaHEiL4K7QCT0fx1b01Ms5ypPxoROBPGODzpfhyAU/K3FQ9JHw/zMbeg//wymwnl/AWHf3a0VQ== 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=fG1F9XegT/sJSYG6Fu85jzQtPZmim9YqynPLlOCoLeE=; b=Ob/HghIMy4+7AuuOjEmwGtFEOFbtR+arb8ugrofvaFUDYX4Q7zHsZgp0ZD26xjdzy/d8tl6ZvG8kmokmblJrIErFGSl1toJi1mZr0/PUnVjqPal3KpA+D72UDpsrCuswIVWwlYo+lAY1FTU/0O3kK26juMiAVP3aHWScHWOcTnM= 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 , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , "Volodymyr Babchuk" , Alec Kwapis , "Daniel P . Smith" Subject: [PATCH v3 2/4] xen/arm: Alloc XenStore page for Dom0less DomUs from hypervisor Date: Fri, 17 May 2024 11:21:54 +0800 Message-ID: <20240517032156.1490515-3-xin.wang2@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240517032156.1490515-1-xin.wang2@amd.com> References: <20240517032156.1490515-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: CH2PEPF00000146:EE_|CH3PR12MB7643:EE_ X-MS-Office365-Filtering-Correlation-Id: 36fbe1af-e58e-4651-de76-08dc7620c831 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|82310400017|376005|36860700004|1800799015; X-Microsoft-Antispam-Message-Info: 6BiiqWCLmIwOmluOM5NDMDVRIN7urfuugWAcSQyiQ0feyxQjQz0D547Nrx+cfDDrUjkgsaPtZLWsLfmRrJro4kedSrPWWvzZ7gmrPVvNRtDwf8SHJgGhufCAbzhSF3snc4lHudZsCgAXIDKA9XlIVqQOOCdb4IZsmRUtKiXmFRG6mHXosxOnRVGfnAM31COHLC374WOQI3aHQZP1hFHW0mIWDKbyKsxKsHpw6gDtqKxRzliK3NgAonQs0coTkpQK2bCKlAHZgW7ppepzNkge7uqOcCkRqMmGdk45WYyj3HDefa3az5RZPG038L7hfXGubIYlbZB1F4gcDcrkIE07fAjUkoi/mPEIoPY1hEbbMi1b0c8ccUaVCFk8Kyi6w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:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(82310400017)(376005)(36860700004)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 May 2024 03:23:54.7635 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 36fbe1af-e58e-4651-de76-08dc7620c831 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: CH2PEPF00000146.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB7643 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 ``` The "magic page" is a terminology used in the toolstack as reserved pages for the VM to have access to virtual platform capabilities. 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. Since for init-dom0less, the magic page region is only for XenStore. To solve above issue, this commit allocates the XenStore page for Dom0less DomUs at the domain construction time. The PFN will be noted and communicated to the init-dom0less application executed from Dom0. To keep the XenStore late init protocol, set the connection status to XENSTORE_RECONNECT. Reported-by: Alec Kwapis Suggested-by: Daniel P. Smith Signed-off-by: Henry Wang --- v3: - Only allocate XenStore page. (Julien) - Set HVM_PARAM_STORE_PFN and the XenStore connection status directly from hypervisor. (Stefano) v2: - Reword the commit msg to explain what is "magic page" and use generic terminology "hypervisor reserved pages" in commit msg. (Daniel) - Also move the offset definition of magic pages. (Michal) - Extract the magic page allocation logic to a function. (Michal) --- xen/arch/arm/dom0less-build.c | 44 ++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/dom0less-build.c b/xen/arch/arm/dom0less-build.c index 74f053c242..95c4fd1a2d 100644 --- a/xen/arch/arm/dom0less-build.c +++ b/xen/arch/arm/dom0less-build.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-only */ #include +#include #include #include #include @@ -10,6 +11,8 @@ #include #include +#include + #include #include #include @@ -739,6 +742,42 @@ static int __init alloc_xenstore_evtchn(struct domain *d) return 0; } +#define XENSTORE_PFN_OFFSET 1 +static int __init alloc_xenstore_page(struct domain *d) +{ + struct page_info *xenstore_pg; + struct xenstore_domain_interface *interface; + mfn_t mfn; + gfn_t gfn; + int rc; + + d->max_pages += 1; + xenstore_pg = alloc_domheap_page(d, 0); + if ( xenstore_pg == NULL ) + return -ENOMEM; + + mfn = page_to_mfn(xenstore_pg); + if ( !is_domain_direct_mapped(d) ) + gfn = gaddr_to_gfn(GUEST_MAGIC_BASE + + (XENSTORE_PFN_OFFSET << PAGE_SHIFT)); + else + gfn = gaddr_to_gfn(mfn_to_maddr(mfn)); + + rc = guest_physmap_add_page(d, gfn, mfn, 0); + if ( rc ) + { + free_domheap_page(xenstore_pg); + return rc; + } + + d->arch.hvm.params[HVM_PARAM_STORE_PFN] = gfn_x(gfn); + interface = (struct xenstore_domain_interface *)map_domain_page(mfn); + interface->connection = XENSTORE_RECONNECT; + unmap_domain_page(interface); + + return 0; +} + static int __init construct_domU(struct domain *d, const struct dt_device_node *node) { @@ -839,7 +878,10 @@ static int __init construct_domU(struct domain *d, rc = alloc_xenstore_evtchn(d); if ( rc < 0 ) return rc; - d->arch.hvm.params[HVM_PARAM_STORE_PFN] = ~0ULL; + + rc = alloc_xenstore_page(d); + if ( rc < 0 ) + return rc; } return rc; From patchwork Fri May 17 03:21: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: 13666616 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 D6820C25B77 for ; Fri, 17 May 2024 03:24:22 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.723791.1128885 (Exim 4.92) (envelope-from ) id 1s7oCa-0007it-Ag; Fri, 17 May 2024 03:24:12 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 723791.1128885; Fri, 17 May 2024 03:24:12 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s7oCa-0007ij-6B; Fri, 17 May 2024 03:24:12 +0000 Received: by outflank-mailman (input) for mailman id 723791; Fri, 17 May 2024 03:24:11 +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 1s7oCZ-0006l6-CG for xen-devel@lists.xenproject.org; Fri, 17 May 2024 03:24:11 +0000 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on20600.outbound.protection.outlook.com [2a01:111:f403:2009::600]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id ec385ba3-13fc-11ef-b4bb-af5377834399; Fri, 17 May 2024 05:24:09 +0200 (CEST) Received: from CH2PR12CA0022.namprd12.prod.outlook.com (2603:10b6:610:57::32) by CYYPR12MB8701.namprd12.prod.outlook.com (2603:10b6:930:bf::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.27; Fri, 17 May 2024 03:24:07 +0000 Received: from CH2PEPF00000143.namprd02.prod.outlook.com (2603:10b6:610:57:cafe::c5) by CH2PR12CA0022.outlook.office365.com (2603:10b6:610:57::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.30 via Frontend Transport; Fri, 17 May 2024 03:24:06 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CH2PEPF00000143.mail.protection.outlook.com (10.167.244.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7587.21 via Frontend Transport; Fri, 17 May 2024 03:24:06 +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, 16 May 2024 22:23:54 -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, 16 May 2024 22:23:23 -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: ec385ba3-13fc-11ef-b4bb-af5377834399 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Z1XYILrUxe22f+CO8p9a/Uy7Poo7DKsvyV4yI6p+LfGwfkcvdTz629vvLFTxr1DFF6TiKcTFOTJZtxCf6oyyB46z2sYsALR2xh8KbP1WeuPHzexdedS1dgZmMx9pYKGp96/q5Wq11teXco0VYDJ5m+F2pk7zqqx4nS7S2I6PhKZfQlxjqiFYXTyJDeG8n72xivvPXwvSjYOr0blm6B2fTtisdDOyawr918RW85ortydi/yLheM1Rhnmzz+B3L50shDv93LM0CVU2zatFp7z0RdtQOxA0ROyrinu1cz7XavlGlTOLpAPGF9FXUsfcHrD6NKqDeOp0LipiZY/1snYP9A== 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=GyKN4QF9fVjSu+AyjNRAOue0Obnrq0vCp9OkHGHQS+8=; b=Ug61W5mJiOquEseiazbkFBTgKoFK+ldvDyyduTys/YrB2fyr7lE6071VIb+AC/qvWz7WFQWfhhtJyNQtbZP5iRe/leSUyGTZcr2IPcktTMFl14NOqJyAh1+N78ONe102cVjBOSemqx71tYwE8dRqbKHRozqr9L8OV3w54YCro69/xoXx8Jk8+48h1ZgsOEAHoJTEePvhPVRDt69+UUE5QQSyH/Xb+l4ihFhQil+REdOL/hG8b/rgemRighaHDXbmtefLkoxg3onSu4x4XRoykuQXGO+sssHlJfKldXzlhDLqqCapS74Y7nGcoSbKrtHJ8WneiCWyqP6ijzAsh/NlcA== 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=GyKN4QF9fVjSu+AyjNRAOue0Obnrq0vCp9OkHGHQS+8=; b=sYZi1WHYB2b6gqIn9RpP/IkualfsU+zpIyCDPSH48beLXbRbQD43nsRagh9nOiSmitR1e04kG2n/aywDZ9DmAxGpGnnCeZUjBAyi56F6TB5nflicCUKW/Y1EJeCC5ijsnbv3nbZvZwNBLYz7IiJPqqt4q/biwnW8E8TWt7LLoFk= 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 , Alec Kwapis Subject: [PATCH v3 3/4] tools/init-dom0less: Avoid hardcoding GUEST_MAGIC_BASE Date: Fri, 17 May 2024 11:21:55 +0800 Message-ID: <20240517032156.1490515-4-xin.wang2@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240517032156.1490515-1-xin.wang2@amd.com> References: <20240517032156.1490515-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: CH2PEPF00000143:EE_|CYYPR12MB8701:EE_ X-MS-Office365-Filtering-Correlation-Id: 2116035e-4bcf-482a-0f45-08dc7620cef4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|82310400017|1800799015|36860700004|376005; X-Microsoft-Antispam-Message-Info: NQHS6Ndpm0l2r0sHPBDXsEws8+31YWiTYLcnl8J9Clp6KfWkGctnT62XMdWaIwuhBBtSkSGlwqfyl3aQHOan+O1NoX7XWNlQg+iU99pulfS+9rwMkbn9mqpPz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zeNi3SO+XHsrmCWkbmpoWtQ75AOR84++yl0o7ZnOD7ZExJzhmmthWT5yzFe7agtZZg8lgzHxnvaVkNrLjRl6oaHryNZtAdCIin60pLcdaxW17r+r2Pqt64e9xVze7+DdsB2KZzYDRX4TvefDy+ra62cNAyPg9cZBKU6V3x1NAHEfLvcrtwGq8B4zIJtapZlHnOY2J7XxCyT2Fs/3 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)(82310400017)(1800799015)(36860700004)(376005);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 May 2024 03:24:06.2275 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2116035e-4bcf-482a-0f45-08dc7620cef4 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: CH2PEPF00000143.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CYYPR12MB8701 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 allocation from init-dom0less is for XenStore, and the XenStore page is now allocated from the hypervisor, instead of hardcoding the guest magic pages region, use xc_hvm_param_get() to get the XenStore page PFN. Rename alloc_xs_page() to get_xs_page() to reflect the changes. With this change, some existing code is not needed anymore, including: (1) The definition of the XenStore page offset. (2) Call to xc_domain_setmaxmem() and xc_clear_domain_page() as we don't need to set the max mem and clear the page anymore. (3) Foreign mapping of the XenStore page, setting of XenStore interface status and HVM_PARAM_STORE_PFN from init-dom0less, as they are set by the hypervisor. Take the opportunity to do some coding style improvements when possible. Reported-by: Alec Kwapis Signed-off-by: Henry Wang Reviewed-by: Jason Andryuk Reviewed-by: Stefano Stabellini --- v3: - Only get the XenStore page. - Drop the unneeded code. v2: - Update HVMOP keys name. --- tools/helpers/init-dom0less.c | 58 +++++++++-------------------------- 1 file changed, 14 insertions(+), 44 deletions(-) diff --git a/tools/helpers/init-dom0less.c b/tools/helpers/init-dom0less.c index fee93459c4..2b51965fa7 100644 --- a/tools/helpers/init-dom0less.c +++ b/tools/helpers/init-dom0less.c @@ -16,30 +16,18 @@ #include "init-dom-json.h" -#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; - 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; - - *xenstore_pfn = base + XENSTORE_PFN_OFFSET; - rc = xc_clear_domain_page(xch, info->domid, *xenstore_pfn); - if (rc < 0) - return rc; + rc = xc_hvm_param_get(xch, info->domid, HVM_PARAM_STORE_PFN, xenstore_pfn); + if (rc < 0) { + printf("Failed to get HVM_PARAM_STORE_PFN\n"); + return 1; + } return 0; } @@ -100,6 +88,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, + uint64_t xenstore_pfn, evtchn_port_t xenstore_port) { domid_t domid; @@ -145,8 +134,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, "%"PRIu64, xenstore_pfn); if (rc < 0 || rc >= STR_MAX_LENGTH) return rc; rc = snprintf(xenstore_port_str, STR_MAX_LENGTH, "%u", xenstore_port); @@ -230,7 +218,6 @@ static int init_domain(struct xs_handle *xsh, libxl_uuid uuid; uint64_t xenstore_evtchn, xenstore_pfn; int rc; - struct xenstore_domain_interface *intf; printf("Init dom0less domain: %u\n", info->domid); @@ -245,20 +232,11 @@ 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) { - printf("Error on alloc magic pages\n"); - return 1; - } - - intf = xenforeignmemory_map(xfh, info->domid, PROT_READ | PROT_WRITE, 1, - &xenstore_pfn, NULL); - if (!intf) { - printf("Error mapping xenstore page\n"); + /* Get xenstore page */ + if (get_xs_page(xch, info, &xenstore_pfn) != 0) { + printf("Error on getting xenstore page\n"); return 1; } - intf->connection = XENSTORE_RECONNECT; - xenforeignmemory_unmap(xfh, intf, 1); rc = xc_dom_gnttab_seed(xch, info->domid, true, (xen_pfn_t)-1, xenstore_pfn, 0, 0); @@ -272,19 +250,11 @@ static int init_domain(struct xs_handle *xsh, if (rc) err(1, "gen_stub_json_config"); - /* Now everything is ready: set HVM_PARAM_STORE_PFN */ - rc = xc_hvm_param_set(xch, info->domid, HVM_PARAM_STORE_PFN, - xenstore_pfn); - 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; From patchwork Fri May 17 03:21:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Henry Wang X-Patchwork-Id: 13666617 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 5E3ABC04FFE for ; Fri, 17 May 2024 03:24:24 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.723792.1128895 (Exim 4.92) (envelope-from ) id 1s7oCe-000805-HK; Fri, 17 May 2024 03:24:16 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 723792.1128895; Fri, 17 May 2024 03:24:16 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s7oCe-0007zw-Dv; Fri, 17 May 2024 03:24:16 +0000 Received: by outflank-mailman (input) for mailman id 723792; Fri, 17 May 2024 03:24:14 +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 1s7oCc-0006l6-N9 for xen-devel@lists.xenproject.org; Fri, 17 May 2024 03:24:14 +0000 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on20601.outbound.protection.outlook.com [2a01:111:f403:2408::601]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id ee33ac71-13fc-11ef-b4bb-af5377834399; Fri, 17 May 2024 05:24:13 +0200 (CEST) Received: from CH2PR12CA0005.namprd12.prod.outlook.com (2603:10b6:610:57::15) by PH7PR12MB7209.namprd12.prod.outlook.com (2603:10b6:510:204::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.55; Fri, 17 May 2024 03:24:09 +0000 Received: from CH2PEPF00000143.namprd02.prod.outlook.com (2603:10b6:610:57:cafe::62) by CH2PR12CA0005.outlook.office365.com (2603:10b6:610:57::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.28 via Frontend Transport; Fri, 17 May 2024 03:24:08 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CH2PEPF00000143.mail.protection.outlook.com (10.167.244.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7587.21 via Frontend Transport; Fri, 17 May 2024 03:24:08 +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, 16 May 2024 22:23:56 -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, 16 May 2024 22:23:55 -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: ee33ac71-13fc-11ef-b4bb-af5377834399 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=n26oQiB3rqYQQhQY7AHV0S4Zl1cvg9yF0o0rMNei2YEX4kszHQevDgJy1nNlVNTBcFXhuCUH2OKzu7KVUd86vSRg/nn6BDu6PU8raGFGE//t3JgI5t06xjXABvIgSASX5WuXX8BqMQ0MqkMZdO+/L9Qou23lykiQB0jBwobPmvEbJfx/N/M/DIGsoipqNAthh2K6Q73PEJpjtCU9a54/CLR6NVjlBkUTgMKOWbFos8dSI7BTf481OjWXUpvAF9L6mi03aExjSrf5by/GwomtfFlLILwMa7xCu+qW0SDPNoGSgog24t3ICxD3iXQACzhXcNi9RNdAev/VG+zNQu0sVA== 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=1u+M1MpJUGmCneiJ6tyWezkJk2s1bMCTX2NWTZTsw/0=; b=mjtzhKxESPc/Tdud9EX0lppgwWM6CqqXKDwKDB0o2rdOv5fLb+sGJ75NdpWPRkUEe/TuF62plOkMv5DQ9SdBvPn2IGbLEuOcsauOemei2OjMFU/aGzWVLMn21LwKXGFxqInS6SlM+eiQ5iycuPJInirGImmwHLqv4y/e5amchorSSRG8S2+ul+l+8JtowR2/2OceZFqca4wgKqHu0gu8Vollo8NZVzZiG1PSAwPL7WsMItbn6nyk9FuVGdOfFiq0MgMZW+7GiBKiQUpW6nTPKDJUnfvVY9lt1fr2tUQ/SQ92piJt/2bZn2V/NuWmLJioDqVApK7PNThifD0eirVwhA== 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=1u+M1MpJUGmCneiJ6tyWezkJk2s1bMCTX2NWTZTsw/0=; b=zgCaMAMQCRubaJCTtqToLscyBF7EEpGybk7Jihnxcq4ykznbPD+4sonFC7B86G0gm+t34qgPVeYJajPoTTSfMjCgj2os35BwlU2JJWRFZoKcR9wetvRuWdciz/0qMtsgWrF0GAh8KujWHrUQ9JdNEirZ4G1k9XdAmYvRkR77oE8= 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 , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini Subject: [PATCH v3 4/4] docs/features/dom0less: Update the late XenStore init protocol Date: Fri, 17 May 2024 11:21:56 +0800 Message-ID: <20240517032156.1490515-5-xin.wang2@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240517032156.1490515-1-xin.wang2@amd.com> References: <20240517032156.1490515-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: CH2PEPF00000143:EE_|PH7PR12MB7209:EE_ X-MS-Office365-Filtering-Correlation-Id: dd70f450-ec54-4c0f-c236-08dc7620d06c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|376005|82310400017|36860700004|1800799015; X-Microsoft-Antispam-Message-Info: X2ampRtCEEh65iOCT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ritzPH0uogOiIrntmBWCRizQvg5ePC2Emnzcnlr+74YSulqRHTbJXzE+wIYp5nKpLBagm2/Ltle7gRzvzhRpfWrL97/31stIXhLb+ngkxwj5KJSZAAEwCMu5UhXJxWGohYE36d35WKhYBYS9A8Y5jNBvy0zAInUZySe98tfIYpJNy704yJUyLok75QCOk1PTyD47z/WI71J3JpqFgt59Ds7cG/m8sMGou/uGZhHEx5YvPjyO/3mP1+tqMj3eV3n29S5K5CE9S4TqLM1YgyVVq6Cfiu34Y60s+tGwAraZ9IQ2G4OcQq16q4 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)(376005)(82310400017)(36860700004)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 May 2024 03:24:08.6806 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: dd70f450-ec54-4c0f-c236-08dc7620d06c 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: CH2PEPF00000143.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB7209 With the new allocation strategy of Dom0less DomUs XenStore page, update the doc of the late XenStore init protocol accordingly. Signed-off-by: Henry Wang Reviewed-by: Stefano Stabellini --- v3: - Wording change. v2: - New patch. --- docs/features/dom0less.pandoc | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/docs/features/dom0less.pandoc b/docs/features/dom0less.pandoc index 725afa0558..8b178edee0 100644 --- a/docs/features/dom0less.pandoc +++ b/docs/features/dom0less.pandoc @@ -110,9 +110,10 @@ hotplug PV drivers to dom0less guests. E.g. xl network-attach domU. The implementation works as follows: - Xen allocates the xenstore event channel for each dom0less domU that has the "xen,enhanced" property, and sets HVM_PARAM_STORE_EVTCHN -- Xen does *not* allocate the xenstore page and sets HVM_PARAM_STORE_PFN - to ~0ULL (invalid) -- Dom0less domU kernels check that HVM_PARAM_STORE_PFN is set to invalid +- Xen allocates the xenstore page and sets HVM_PARAM_STORE_PFN as well + as the connection status to XENSTORE_RECONNECT. +- Dom0less domU kernels check that HVM_PARAM_STORE_PFN is set to + ~0ULL (invalid) or the connection status is *not* XENSTORE_CONNECTED. - Old kernels will continue without xenstore support (Note: some old buggy kernels might crash because they don't check the validity of HVM_PARAM_STORE_PFN before using it! Disable "xen,enhanced" in @@ -121,13 +122,14 @@ The implementation works as follows: channel (HVM_PARAM_STORE_EVTCHN) before continuing with the initialization - Once dom0 is booted, init-dom0less is executed: - - it allocates the xenstore shared page and sets HVM_PARAM_STORE_PFN + - it gets the xenstore shared page from HVM_PARAM_STORE_PFN - it calls xs_introduce_domain - Xenstored notices the new domain, initializes interfaces as usual, and sends an event channel notification to the domain using the xenstore event channel (HVM_PARAM_STORE_EVTCHN) - The Linux domU kernel receives the event channel notification, checks - HVM_PARAM_STORE_PFN again and continue with the initialization + HVM_PARAM_STORE_PFN and the connection status again and continue with + the initialization Limitations