From patchwork Fri May 24 22:55:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 13673778 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 2C95AC25B7D for ; Fri, 24 May 2024 22:55:39 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.729962.1135310 (Exim 4.92) (envelope-from ) id 1sAdox-0003yz-Gg; Fri, 24 May 2024 22:55:31 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 729962.1135310; Fri, 24 May 2024 22:55: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 1sAdox-0003ys-Dh; Fri, 24 May 2024 22:55:31 +0000 Received: by outflank-mailman (input) for mailman id 729962; Fri, 24 May 2024 22:55:30 +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 1sAdow-0003hQ-L7 for xen-devel@lists.xenproject.org; Fri, 24 May 2024 22:55:30 +0000 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on20601.outbound.protection.outlook.com [2a01:111:f403:2412::601]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id b661fd4d-1a20-11ef-b4bb-af5377834399; Sat, 25 May 2024 00:55:28 +0200 (CEST) Received: from BLAPR03CA0088.namprd03.prod.outlook.com (2603:10b6:208:329::33) by SA3PR12MB9177.namprd12.prod.outlook.com (2603:10b6:806:39d::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.22; Fri, 24 May 2024 22:55:24 +0000 Received: from MN1PEPF0000ECD5.namprd02.prod.outlook.com (2603:10b6:208:329:cafe::14) by BLAPR03CA0088.outlook.office365.com (2603:10b6:208:329::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.27 via Frontend Transport; Fri, 24 May 2024 22:55:24 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by MN1PEPF0000ECD5.mail.protection.outlook.com (10.167.242.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7611.14 via Frontend Transport; Fri, 24 May 2024 22:55:24 +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; Fri, 24 May 2024 17:55:23 -0500 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; Fri, 24 May 2024 17:55:23 -0500 Received: from smtp.xilinx.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; Fri, 24 May 2024 17:55:22 -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: b661fd4d-1a20-11ef-b4bb-af5377834399 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KHKRq0WLq+gvjaSBU2cBm+tOtKgFYAloEbDoytH7ShGaisA+nWjqSHfCeR54E9z51o+0otJioyy62fZW4rXxvH/lpNs5lImuQzjkJbETUf0fIr63Nfw5nEqPNXQmEbPgyHjPQksjnVQpFFyEHXukn1PeBXJqzbMPjPcXVgMuxrz1jGWM5pFO1o7X+BI6xLVHu/PjXwdJu/o+9ZtDFEp49cvUNjx8vvVpJcU/1UtP8I4K8AtrpBFkNhl4fva+hg4j2ApAL6KYEwMvYfb1HHNkp/AvjXv6fsB9YkwGuarm1azj2CQKaGmfLoSaG4zFsXGT6+zQLq0ix+qKrC4PISoPXw== 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=lzV5nEyCRZZ9wvgQ5/ihrFl2ogjKMReVCJclNQHfPF0=; b=GhCUGIJsy+h6Eb2FQ9I//g+AqcFCWpvi7j0oR5TtapXwYD85Et/JA2s15vhOtA3+UzpdzqIScMYZMIojxo2PhzhtJXEnWUZlyJGT43KNwmFyVgPNHLxTFc+/rgCwuTJ+ZnWhn/+eaztYCKb0zTgQP+ZRj4blkXK6clOvgzjsL0yjRLnSzOTLy6FVMxeXp8VK9EBJaD71sAXHODeLah9ScqJYNycLz2gtEgJ85tzrCPSDUiA8kq81JH2HzjNFJUPstMIO8uENgU6IN7QmCfZTfGF1cPFkrra3D+a/NpkNi82Y8r8EJlsAgRRlS2THFI5RRWES+K0UvcOz41621+znig== 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=lzV5nEyCRZZ9wvgQ5/ihrFl2ogjKMReVCJclNQHfPF0=; b=Lr3XcTWlRaOLU2k/CYK7CGyJJuzf+av0wIXQUNYkNc0Y47kDqDnMeap1EfWmPqrzyEMff8fR5kgPFXvkwsaOrkPwa9xhsFls14jfA7l49un8LixuCTTXkwqVupkwgiGw9UHbwwpSZra5BwdtwNi92XFBnK/MPN/zKNXG1dSS1+k= 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: Stefano Stabellini To: CC: , , , , , Henry Wang , Stefano Stabellini Subject: [PATCH v4 1/4] xen/arm/static-shmem: Static-shmem should be direct-mapped for direct-mapped domains Date: Fri, 24 May 2024 15:55:19 -0700 Message-ID: <20240524225522.2878481-1-stefano.stabellini@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000ECD5:EE_|SA3PR12MB9177:EE_ X-MS-Office365-Filtering-Correlation-Id: 2be1aaed-b1e3-49ab-7fd0-08dc7c4498bb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|82310400017|1800799015|376005|36860700004; X-Microsoft-Antispam-Message-Info: CKxoSez6zEGXESf2xzEkSlkhtrjlI6zvRjKJYtL8eGwP0v6qqkZKAGzs6Ys52zcXcYWc5qresS26+ofH7GV4O9vn/upHrWsS+/Xd9JF/fVC7ziLH1rxJnfHb4d2IZNNFZkYJWDRWn+l2zUWr1VYS1owaKF9SyQ+DSmXKDil6VVEi8glSxByFsxy03qaif6k0OiYEcFsWw4rbI4X46IdaxPD18oQVou8UNSw6g9kk9UV4vWLLrNFRvR4GUmvn5LCGXMFSLI+un0Y5stMgTrgznUUzZdtMxtPnBgN03GHsRwhNQ1cu/w8zK+xa82hVILrqVLh8xYoR4j5Til655Cr45JqhM2wtqFkcMMPTqn0YtzHxeJAc3RYpkn9Wrh6MEO1F8I1MxX9gG/F43BKTOFVJGDABF9wLm9LTJ3vA+FOEP5n5AmhdsLyWmaHIjbTid/o1URydnIH4lcpjk/OX5T3yPpXg2vGnf0kAPsf1Hy3p6+wmNQaC/KXjy9Ye/mPwNGAsvmybVvVCcuwHulxQqUyrFDwMqHnSZMtVT3iiJsW3U/Y1rEGONxjU5tBl6BCbqCSfhIqlB/DO89wUP+wr8ZuAxqtyTQ/Nd4bp/Q+D6h+hn3b1ipHAPDhZpDlvuemZZTplHl+LQVmLeMkcBJq3hsTZ5vDgmNbldgAijnhx1lfPYaOXmy0tQZxwImskua2FvwLF28sS5BCzIqGAxNlHYZG8te5lf36YMnKBXD1FYx/3IrMHIFvUu06woQD8sxYXLXlzlPrriGu+CG1opY5W6ZmUYKRFmaRVJF460Z0KQ+0HmfaxO2V56uBB7La9kYQFl5BmPReLWMfhNGmQHelKF8NatsFEILBsubdc4Zv8MMYhyL00xGRRKe+jtO8uGYRttolp/fgHtmj/VmwS+gvIEson5Vl5gCpiKZCGuV8sGi2erPVWtqhOBGvciqPoHxbwFwCWW4fegxvZUzcpM43FQ3cpkUl6BZ65eY/+1SgeUC+Ne+XBKTikD2I8sKmhJuiVvKUMNb6f1gg6yzL31qktbT7YBZNQuPkyUEKrBT2YU2W2SwXjzSBPicl+WrOMXxfHORJWceML6j5G/daih+HEVUA73DO6v9Eh31qLFbiAfz++Wv8Zf6dZmaagLBpZE6ef95uG7VoDeXpfZdeaILE1+eJ0OEJ96UhQDP2Iq+QyUWrCoXg71o99VExruOf/gNJPNNyiTWrpkuuYtDnh3xO461SilVw/6TJ85vng/KDba4CFdR4iHM/2KRPlC1JcgtiIIkZN5x85UgRAHAGXOYjweV82J5oJL4Q4N1GJvSf/YhHcrYydJArzOyCXEX1ydqjpXh+MLAUVRatdYnLQaky5nm4KBdJzjqhP+Mt8OQZfbyLolmwvURxK3f9Y4EDI8vSGecqw 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)(376005)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 May 2024 22:55:24.1344 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2be1aaed-b1e3-49ab-7fd0-08dc7c4498bb 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: MN1PEPF0000ECD5.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR12MB9177 From: Henry Wang 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 Signed-off-by: Stefano Stabellini Acked-by: Michal Orzel --- 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..5bf1916e5e 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 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 24 22:55:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 13673781 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 228B7C25B7A for ; Fri, 24 May 2024 22:55:46 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.729966.1135340 (Exim 4.92) (envelope-from ) id 1sAdp4-0004ot-IV; Fri, 24 May 2024 22:55:38 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 729966.1135340; Fri, 24 May 2024 22:55:38 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sAdp4-0004og-Ec; Fri, 24 May 2024 22:55:38 +0000 Received: by outflank-mailman (input) for mailman id 729966; Fri, 24 May 2024 22:55:36 +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 1sAdp2-0003hQ-Po for xen-devel@lists.xenproject.org; Fri, 24 May 2024 22:55:36 +0000 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on20601.outbound.protection.outlook.com [2a01:111:f403:2416::601]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id b9ee1500-1a20-11ef-b4bb-af5377834399; Sat, 25 May 2024 00:55:34 +0200 (CEST) Received: from DS0PR17CA0007.namprd17.prod.outlook.com (2603:10b6:8:191::14) by DS0PR12MB6534.namprd12.prod.outlook.com (2603:10b6:8:c1::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.20; Fri, 24 May 2024 22:55:30 +0000 Received: from DS3PEPF0000C37B.namprd04.prod.outlook.com (2603:10b6:8:191:cafe::fa) by DS0PR17CA0007.outlook.office365.com (2603:10b6:8:191::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.36 via Frontend Transport; Fri, 24 May 2024 22:55:25 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by DS3PEPF0000C37B.mail.protection.outlook.com (10.167.23.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7611.14 via Frontend Transport; Fri, 24 May 2024 22:55:25 +0000 Received: from SATLEXMB06.amd.com (10.181.40.147) 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; Fri, 24 May 2024 17:55:24 -0500 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; Fri, 24 May 2024 17:55:24 -0500 Received: from smtp.xilinx.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; Fri, 24 May 2024 17:55: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: b9ee1500-1a20-11ef-b4bb-af5377834399 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=H0ZwdWwFHgIU2CPMt51i20GT77LOt4RDg0m3ViVoe+VbLR2+nwy2hqJMwpFO2IuUd6Ca/FGhpyHnEbjp1ogHiQPr7vB7SP8LWqc+AEkoMXGuJJorunMj/W7SP+9ekbG0L2wefMc3Rm/7qxWosBX/3fQ/F+sasNMBA6i9vNMc3EBLaKHRc4/uIN+9Gg5D+HNiSrt3TsoL8alcUa+yFJVOMGxBpUbRpK3WguMej4o/RJxNyG7A5fdAHmVYAB9dya0Zy9/OzECyRiqluOb3QtYtkbhPW6tA0CX1ch5rF7UkH3FEfZOE47NMfSu5CTtm8J4yrlL7hOtMDHGYp+L3NMhKfg== 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=kGJKl+YgAt+elTNKQCErwYXKgmqb2xKN/qNfttPWbAw=; b=Gt6IeM3OQ9OlNsZBJvR/YroCFBRM8YlaVUHqhTkdhLh9kI0G3RBF47rZlNUg7prCjaKDS0f27DJzOd8V72B/B2Gi+E79GY2NcGCzhwZ15s5+zrySnGA10L/NzsRLdtUX382X2hMeynof0XJUxhBLuxCbhRDiZE60JjxQA8m3O6+t1/M5u1Mihns8SFSsCN9IRWZnV47XE1xrPvorMUboTSvkfFNeaNmxO8g+vVtJwdmWpR2l4RX3l0+hQ8PmKzoQtTusOgrHks9ZE2HtLFYqoHrJQHiwgtK6IExDffab3tjVtiYbTcOz0f6SE7cfWvgA2Zc9SAGl9MXUXIFe/4UFhQ== 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=kGJKl+YgAt+elTNKQCErwYXKgmqb2xKN/qNfttPWbAw=; b=Kss64V5TJPeoTcxFJKrTeGpbOWUFId2KMI6M+sZsx5WXqRgqyQUu/GkXmFjVtywU99TzzsXOqWuPubE5lJlB0CuwpIhcvF7ImB5j05dr/34yTwK75zUOalGvL3Y4bbk8svTsNHNuhxJSPtsBgV1vWW2bLlEgTYVkLuXTIEOm6XM= 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: Stefano Stabellini To: CC: , , , , , Henry Wang , Alec Kwapis , "Daniel P . Smith" , Stefano Stabellini Subject: [PATCH v4 2/4] xen/arm: Alloc XenStore page for Dom0less DomUs from hypervisor Date: Fri, 24 May 2024 15:55:20 -0700 Message-ID: <20240524225522.2878481-2-stefano.stabellini@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF0000C37B:EE_|DS0PR12MB6534:EE_ X-MS-Office365-Filtering-Correlation-Id: 7b482132-61e9-491c-4234-08dc7c44996c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|82310400017|376005|1800799015|36860700004; X-Microsoft-Antispam-Message-Info: b9wWaVUXtHuKsJimiwJE+gdixTUTt56rWyUww7V5ZOSjdNSw832v/fKtmPVpsaMupljRZ4Ou4H6ufSNAv7VOQEYsRSGM4VSwJC8gY5MWWf4ggYh3q4GTg9sKzDZGWLrZ+wTB5BF5aURYCi38Gizq1drsgHNjzRKqaIDCSXWrSLFCPDaIWOt9z0KfPI6XidMECWoYSyqHSKG1wkkJ5qNPrMiJEdld6eSLWLqfe0muqXHuzf2O7/2Zx9B4SQqWstFaNernwQ4hil2zn69EbU7y3hs/1r4Led1BHaCKAfl4slMN6nKucpsshlZWNS+Jg1zvjTy5aNGkFHu1vpX1fNFwG8ItGJrQxIG43DzfmdbYjNZu2wzzb2BDrrpmC+4P6rZ+RMDKYd9FTDGdwLHpqWOjujlz8QzAQtGHseaNmQOdqgFfMDPOQ9PljvyF8BywXBOS7F0Ep2yiHfXmKvsyuiNq+D+BiGRrVjPal5TpPq3iXgEKZC1E+UNpd/QM+dIH3TDm9uXsgFlpA38ifyWE7kCdDS2jvaG3TUifqczF7gOZdStPQlEyqVAO7610RRsS90EVwVB/jN+bfTi2FEokN6sTo8eDo1WHskQSSuFsBK9EZiYKft2mdDdQvS+Lo5Iz8p2DN8J7062Wz/FKZi0Gko0ZuGyqM2j1ghFCNuMtKwakH9FHBSbYVR1R9E5vlsKB4CZUN0xRmbAQHXIvfPBjhV811+pc/Hnn+3oJXeqNTe0L25sPVuRIx5jV6/pnzZwLzFKc1MlPpyQV4tkC8NGIlqFwkTu1yfoCjlTtAq1vY6gWWAAziNOiDaCuEUmphKajq/SjXLeFBYHm06qZJfmqqKNEUj0KsdgKVq+TbbEmV9pF9mheXMsSvhn2HS4c6fplev6DMKAXk2OsPo/CtvThgIp01OknEy4SicbpoGCZbJfj2QR4HMBPF8vvvzJEPlaSd/+V3NjEOCNi4JOYL9ClVobtb6e4XfyxWHTOCtWpLzUaWdQj85lo5IvEUODc6/mSVCgwyVsLpGz6os6x87M875A89ylPhOquj5CYeGHDnnRvAZMrqPRij4u09hiMuF4It7aNBYNbrxxvha47DLZ/loF4qLNh2X3trWeN6KdvhZDfdE+Za3d/rdmAoXWWyHqHYkx0Yph5tuJBblmtEzWF65PVxBVVn6uYVlZoKKGGedX6uIYknuqORrPkhwb8NJl86a1mgCk1fy5/FsZAb0I0sz7tBxpvSr3sP7oh9th7anzmlhtxpOoppul0kdT/pdHSE75JhHt3+klpFcNtDoSf9JbialTPdnGooU+DDQtKgQgo+AjB0/KOljPRli71sBwuIYOJ3brYMmnZg/ep6B9OeQMcXHT+VEQtJY7/hjw0t5gfU+ko4gb8UD/iabrRIiG173er 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)(82310400017)(376005)(1800799015)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 May 2024 22:55:25.2459 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7b482132-61e9-491c-4234-08dc7c44996c 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: DS3PEPF0000C37B.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB6534 From: Henry Wang 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 Signed-off-by: Stefano Stabellini Reviewed-by: Michal Orzel --- xen/arch/arm/dom0less-build.c | 55 ++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/dom0less-build.c b/xen/arch/arm/dom0less-build.c index 74f053c242..2963ecc0b3 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,53 @@ 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; + + if ( (UINT_MAX - d->max_pages) < 1 ) + { + printk(XENLOG_ERR "%pd: Over-allocation for d->max_pages by 1 page.\n", + d); + return -EINVAL; + } + d->max_pages += 1; + xenstore_pg = alloc_domheap_page(d, MEMF_bits(32)); + if ( xenstore_pg == NULL && is_64bit_domain(d) ) + xenstore_pg = alloc_domheap_page(d, 0); + if ( xenstore_pg == NULL ) + return -ENOMEM; + + mfn = page_to_mfn(xenstore_pg); + if ( !mfn_x(mfn) ) + return -ENOMEM; + + 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 = 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 +889,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 24 22:55:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 13673779 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 4BD8DC25B74 for ; Fri, 24 May 2024 22:55:42 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.729963.1135321 (Exim 4.92) (envelope-from ) id 1sAdoz-0004FQ-RY; Fri, 24 May 2024 22:55:33 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 729963.1135321; Fri, 24 May 2024 22:55:33 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sAdoz-0004FG-MY; Fri, 24 May 2024 22:55:33 +0000 Received: by outflank-mailman (input) for mailman id 729963; Fri, 24 May 2024 22:55:32 +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 1sAdoy-0003hQ-B1 for xen-devel@lists.xenproject.org; Fri, 24 May 2024 22:55:32 +0000 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on20601.outbound.protection.outlook.com [2a01:111:f403:2414::601]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id b7c3f78f-1a20-11ef-b4bb-af5377834399; Sat, 25 May 2024 00:55:30 +0200 (CEST) Received: from BL0PR05CA0026.namprd05.prod.outlook.com (2603:10b6:208:91::36) by MN0PR12MB6031.namprd12.prod.outlook.com (2603:10b6:208:3cd::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.22; Fri, 24 May 2024 22:55:26 +0000 Received: from MN1PEPF0000ECDA.namprd02.prod.outlook.com (2603:10b6:208:91:cafe::5a) by BL0PR05CA0026.outlook.office365.com (2603:10b6:208:91::36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.9 via Frontend Transport; Fri, 24 May 2024 22:55:26 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by MN1PEPF0000ECDA.mail.protection.outlook.com (10.167.242.134) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7611.14 via Frontend Transport; Fri, 24 May 2024 22:55:26 +0000 Received: from SATLEXMB05.amd.com (10.181.40.146) 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; Fri, 24 May 2024 17:55:25 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) 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; Fri, 24 May 2024 17:55:25 -0500 Received: from smtp.xilinx.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; Fri, 24 May 2024 17:55:24 -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: b7c3f78f-1a20-11ef-b4bb-af5377834399 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PRdSxu+XN/ZW2GQ5HrLeUE2ojTfJtJP5H833elqm8+dCzt4nobooZ9enOSnLfx1sBhcK0z7NysVwM4nBWhx3KVhwTZBXSX83xRve4KoBun0wHFzxBcKB35N60jLpD4OfIrkVpomjqF0hvXt8loDlCGavuRXNXGVIKmeDMidkm4KQ8syCaKuFlfyMSnoU0SA/4BhgWLvV6IFUmnQVN9QQdPDv5M3yhnOpresV/ZovNonTqb+H9ns3igJnXUnVq62Qf0Tg9dNv0S2bthGfiU75PpARVeoIr+ojQWtQPXX3wUvefE/8totGVUOAoxywb10wwDoBdQ4vNn+pY+pWX7H5kw== 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=FumphntemJECKnhgVYvneYgiginHtvLBa1WGte3c0qA=; b=afGXK/5nfdz4FNrBl1zmsXjAqV0DNrafnleTKdh0nwANYSGWdpz6PAJ4HTo6D+m3CaGOCsF+rwIURAG8408/b5AbIT/+jGhu5MlMITDs8wOFqRdHcylWD0X7zhMVp0w7XiLYzybUoI9d5l7yChu77iZOmTFCHszaDlZvMLCJBEmIdn9911Lz+jic96WIyQxBC5hwqof7nMv1uj+q/3FW8gc1tPNJyUNzOCaGXiAf4KrhwbC3LzKNqMn5BI9P2zM6M1vNew8B4ZMDh0eDigbIbNDBXUFb1D3ejaad/k8VwhRcoGMDF5tDs1BFGM1L2EXWVr9NSe/CvvHlj6QWiY9aCQ== 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=FumphntemJECKnhgVYvneYgiginHtvLBa1WGte3c0qA=; b=fGBXjkIVv5++lnx8mqLMZJXu5BKMcnsT1Zk7j10NfC1qSTJpPkQOS65aHnIEjBOAzuJGpfRo0dQ1mD81C8BFg7AITkZeQ3BjcIicChOuJEN1px5RbOi/VRuKuTRheRN4oYbSzLfD2U30dWrm76wswsGVGNqvYsy0wcReCokSUIQ= 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: Stefano Stabellini To: CC: , , , , , Henry Wang , Alec Kwapis , Jason Andryuk , Subject: [PATCH v4 3/4] tools/init-dom0less: Avoid hardcoding GUEST_MAGIC_BASE Date: Fri, 24 May 2024 15:55:21 -0700 Message-ID: <20240524225522.2878481-3-stefano.stabellini@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Received-SPF: None (SATLEXMB05.amd.com: stefano.stabellini@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000ECDA:EE_|MN0PR12MB6031:EE_ X-MS-Office365-Filtering-Correlation-Id: 309ceecc-faa3-4e74-3bbf-08dc7c4499e1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|1800799015|376005|36860700004|82310400017; X-Microsoft-Antispam-Message-Info: KIxqkTzY8QQ85inv/yQ3OyXd+w3NONL2ZDLaH64xcnGIDqYEbhLNMVoLWc2YSwXHbgtNyLcicxUs5myfcVddrbXi533X5Mci20STU0Aqu/HcR8rFraGjiXnAaa+dpqQYDuEqDpK4p1+sGe8CxJ8M7/Glt9Oa1jAXMGl+YUzKdGoiIZW/xn7gmo1Xg8fcNj9OUJ5pxLqp0na2TrmtVjCnQpEVyV2VXAfQsBQozup7Qz1t4CPI76QfEXhqUpBS6WLCBC5CQc4Vl7mAiHly55wibBY+ozJdxnO6YtHc/LJBM3R7wosG6eN+RNcWOXGLWlP5IhZhPD1O4pXzkEgVAT7YnUGj+zd0NAZs4ubenZxornqr3RFHr88dR8mmXOx/Zpom1xkTQAA3CH+jBQ1KHjvvH+H9olsLOeTs9Ol/pBkIErNyCb6QOnsuCfcR9K64SogHHYJ3qhakRWseWHBJlCfvbsy+ScF1Ct5Olifg5IisDeZ4QFhwmCrzs7RWjPIp7ZVB7q4Lsd4pf9YuYJ+S9V+pEh6jS7MIo1sLzscU4jCt1jRFvbq904eHSB8Ogdq+KQI7yeSn0NugeoDmE/QuM90EP4deNsoF3gN9Nob0WlqBOg47QOhrRng8ve+LHX/F63aDiWGwW8631/BeRacO2iARXQRScUGQsF58pM+k5q/Bw/FZ0IcvWAZqZTk1WlglXN+izXbGoLKnfpWFG1jqA7oxxB2t4EOuOXaH2wSaDFn3LnKQ2LmXCNakMkTiMVm7bsgNcevsmlW1Y4+rznm3xnXYmWj2VNpzuK3PMelvj8OZLgwk6MkSexLZimPYGJg3geoJ/CE/bR9c6it/uiiPZLBaSXWBeGtg+rqZfFGMuauxkRL/uR/qQFsoizNrV4P00cfI8WSrmAj0mP9Cozdj5w4hEjVwcE842i5GYVtakAcgeRNFRh4uKGvWyoVtywRS/hvtfL3DpSP2b6ItJ8PeGlVl6FjcHZFL96p1zV6KQI+XKwtqWwrchaOipYU1sKEY2xbykewpuOtAviGC1zECBwbCBFRQU9A3m7KfqtmOCoXiUyISxUecV4xjDeTmohxQu0P6RF/Ou5j6K33SZbcl9YtA5qMamCsJ6/fRy7SBMDxGzzPC957LSMVLshh7nv27eJJ6a3Km8TUVozIZzLoAH9xHTN1Zbd7YMiyZrb8ewn4oJlj4Z9PoeNTwVYFi6l7EXfhCwNZFthmlbHoMHh/xSvsNUqY6p6l+UGcdOSYm1uVenBdvyZVayBquQ3O8lKbPRcaC8ZdLsoRNjXMQOoC95k6r1lyl/TaxJXqa7W8jjqfGCEEZQpi/LoJImHsrNVrxRNtBTS5QHnKoN4WVPY0d2/vaayrJVkdu5bTBItIKVLy6Vodm64w+Zy2HvsioqFewCo0R 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)(82310400017);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 May 2024 22:55:26.0594 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 309ceecc-faa3-4e74-3bbf-08dc7c4499e1 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: MN1PEPF0000ECDA.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6031 From: Henry Wang 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 CC: anthony@xenproject.org Acked-by: Anthony PERARD --- 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 24 22:55:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 13673780 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 F2EA6C25B74 for ; Fri, 24 May 2024 22:55:45 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.729965.1135330 (Exim 4.92) (envelope-from ) id 1sAdp3-0004Xj-37; Fri, 24 May 2024 22:55:37 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 729965.1135330; Fri, 24 May 2024 22:55:37 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sAdp2-0004XS-W3; Fri, 24 May 2024 22:55:36 +0000 Received: by outflank-mailman (input) for mailman id 729965; Fri, 24 May 2024 22:55:35 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sAdp1-0003hQ-Pe for xen-devel@lists.xenproject.org; Fri, 24 May 2024 22:55:35 +0000 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on20612.outbound.protection.outlook.com [2a01:111:f400:7e88::612]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id b9b2213b-1a20-11ef-b4bb-af5377834399; Sat, 25 May 2024 00:55:34 +0200 (CEST) Received: from DS0PR17CA0010.namprd17.prod.outlook.com (2603:10b6:8:191::26) by CYYPR12MB8921.namprd12.prod.outlook.com (2603:10b6:930:c7::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.36; Fri, 24 May 2024 22:55:31 +0000 Received: from DS3PEPF0000C37B.namprd04.prod.outlook.com (2603:10b6:8:191:cafe::2a) by DS0PR17CA0010.outlook.office365.com (2603:10b6:8:191::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.36 via Frontend Transport; Fri, 24 May 2024 22:55:31 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by DS3PEPF0000C37B.mail.protection.outlook.com (10.167.23.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7611.14 via Frontend Transport; Fri, 24 May 2024 22:55:31 +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; Fri, 24 May 2024 17:55:26 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) 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; Fri, 24 May 2024 17:55:26 -0500 Received: from smtp.xilinx.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; Fri, 24 May 2024 17:55:25 -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: b9b2213b-1a20-11ef-b4bb-af5377834399 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dnrCBpNrmfHy7+Kd8KYhHEIbY0uedHDgUD5UuN6PTWYJGbhtzdX+pat6YhwZd8YhtS06+qszkr+qsqqKIUDqPNCHYmb3uReTcLly5PkDnH1p8tKGZeQ769VKEDUI7OW3bCuXkDYTE9LpfI6hqdNV6UuuWF1YdBg8Ydoh6tCFpyMZkebFMyNdW3qkJmHFfVzHoPSJcstujIDLcfsdbqJ6COqzth/yZzzeFfhEo5Xe7frSZySoa80F/eA2BL5rMVqemVsBSycna6Yb+882JTfPrpuCAvQCaMmHrP7FGyDcjy2Vjso5lv40CkhYjqnRK3dRqlLGNcsxWCof/mKppkfQUg== 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=bm9n7d0lv39csuk5HxxqaBGOy78rYQuqOosnK5AZnWo=; b=jDfES2qfzbdw9HZD2zYMxLw1k9YsFzQX4MTi0v6q2BGnyF3CXEj7u3lzhZsFCn1byxjzs2M1QF58ur8uEDOOmGhNcMwpQ2qIj2Z/4jNKdKS8amclzW4zoN8IQfsYXTM7Wp7+PGcGHXFSnlOmo3SrZ39/7/2a89r63+kBojiKRNFjYWivCLQOqKG5RMPld6BK9dhEOPNxNPLTbG9YUbXiAlDT1VB448cIgLX7VQW8vnnVWdpq6mlZb/3MqSdAX6yqnRhXW28/6ztOP0O3JUVnbXSEIeqvu8iagFZHXJhUOjoi5uvOzamy1XELIjCWwoI3rlWufWF3JDE6mGsWoMAjgg== 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=bm9n7d0lv39csuk5HxxqaBGOy78rYQuqOosnK5AZnWo=; b=IwQEMAv+Oe/Lx2FiUMjPDh28/vGS7kgI+uRC+EcE93yD+IXaOpvb7JGIRs/x9tf2FZ9c2QNa/FPAFtcpxwLruKZRVAvufSPIAnD3RFRFMh5MJ1FHhG6kqbAqsGgTxEdRqTt4Fx87RrfE33/osYpCg/8QpykRycCDZBGPALbudZY= 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: Stefano Stabellini To: CC: , , , , , Henry Wang Subject: [PATCH v4 4/4] docs/features/dom0less: Update the late XenStore init protocol Date: Fri, 24 May 2024 15:55:22 -0700 Message-ID: <20240524225522.2878481-4-stefano.stabellini@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Received-SPF: None (SATLEXMB05.amd.com: stefano.stabellini@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF0000C37B:EE_|CYYPR12MB8921:EE_ X-MS-Office365-Filtering-Correlation-Id: 536ff34d-cb6c-4bc7-555f-08dc7c449cea 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: 3ZTtasn9ADcl2gwGhIWw2r5zzUZzb2+JF2TMnHN/LUZ702OrTzcXGgC3LbqVLz2s2SG8RzBwXzZnDheg/6dP5ASdKx+yFOawIYRzjNXEMxSO4++6AUhPj9sK9UH6lpSAfbuApknpQ1vpNC3R9pCQNa7wljFHsOKj8SaAP9F7si3CsW7yv5LxxiYekh+92jHeNOANh2iXVM1+E7dECzj2d15F6TAGuaa+VnH6rbpax5qU2Wo0oW92xCC3mEnXLXHW5Sgt1IaEfgnK9PZakScP0fEOZYJn4dyKbICaRRU7kGWTL9KkJl+0JTSmCwyt53mu25iAcdEtx1bxFq0vZwBzus6/gQ4mi2PXANOd1FntqkoVuWDejpMTdHDcZ/8jEnpkhUTdOX1ojzZIaR6Wxqykom+SjnbZW4l0i031JFZLtgE9SHHMQrow9KADZ0rmtyhjT2RCxLy5dUqsANYAHG7LBRAYVXhpst3xbJJxeo3BBNTG86cAZTPYZ7yUwMQkXVY29Ebpd7Lf7ohGG/aKEwC/j7JBL3rDS88uggv1/xdHToUPdQkQ5aoVI4AVMZy49emXOypRYCN+xGLlXKuWJBWVf6+cbJVDFZYj93IycEm2mD2d8giq7Kb1A24Zgk1DWLmoONh/MT/lSvq1E9iW/9qg9LQqzEQzyTXVFXlc5fHk8snClDJXmuEws1YNvoY7KHU0+ZUyvcLx/tFr9C2n7VzwCdh+LXvFttB0opPW1U7mh7ZBiAI3LqWh8pM6cAyM3uFOPubp0pFPus4WDlrk8KSdUDy54s3EizePCRMY10yNLOJlklp1LQxkkYERDBuagctqcgobiI+g2/DwuSRRNc/KWSkGD+gU5cpIf/vsSHBtvMlAxCkVon6XBH/R9XpjHIgfBk/G15Qpds+H/20VFFXnEK9K8vQCEkGPaYI1nJNEmYwRFFznZeQ8z5NK4A5xnioFZ3rNruJKrbWglZe4ij/PJBhIX/qLOVQ3xbt44h7A+sqHP050xqXQphFjB8nzrfvbzHfNdIh0xQ2nns3Ojhe7RXG47J+ZH+tNJCNr0lXhrqAWpkq6S6JbySEgGZuY9YiKGivY95QJ7dP5AR7MgryuMFzQJq0QqI3sU7fyUm5w7qgnm2IG7U4ePESaZubfER1A07ByZIooYD39ww4s0ONrBUMxTokZERxOf5DBcLcb4PbEN5BCNCV9rCNnu4A6hbJQ2Guk9uXlbG7TLhhTk/70X0l2X8WFOiCRHVjQo6dw97wSbdrALJNd1Nb1YLIE5V7ZcUrv43CYWEdtCWMw0CXUAxrJAi1fR0zSsK9kJiTy25R2K6mYbVZd6NV8dw64ux4IKTpn8HQd9E4ipF1M7niILpF9RdE+7ZFUDac5zVYSsxFVx5/eON+mvSZXh9DSGRE9 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: 24 May 2024 22:55:31.1053 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 536ff34d-cb6c-4bc7-555f-08dc7c449cea 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: DS3PEPF0000C37B.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CYYPR12MB8921 From: Henry Wang 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: Michal Orzel --- 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