From nobody Thu Oct 30 22:45:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1753488015; cv=pass; d=zohomail.com; s=zohoarc; b=jvZGiyoDkD9VywjAsXbrylNmM8K4Fx9qbtV8ylNlWEEwE/+sN+u/9+lkTNcKpy/cf46thVT12Se19hqp4OP8PyM0rYQAcs+DlnfDBJNCPuoVm9/FLqr83hFiZV2SBLH685C8a3EoisLj1jrSu2howS0gTIMywA6IURPtkHS/I94= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1753488015; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=bu6qy110dZsnS4i5GXYzfa2hnOIRH0xP9Njjyy2eshE=; b=GmiBC622jnhLU4PLIZ2hfc9KbvxnsHOGRCrnpLte8R3T/Q6TuUQshN38c81iBrvO4+VIHIr1wXfp9ZMYm8bDZF0upm1yHqsidlkMX1KcBy0QgM/Kq2mdb2z92s4kY869LCVD6dpA7gNsPuDbNoqNhthBzQ7ZVGqNIsuKhI5Pi1o= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1753488015398140.1324420507019; Fri, 25 Jul 2025 17:00:15 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1058730.1426302 (Exim 4.92) (envelope-from ) id 1ufSKL-0001Sd-5g; Fri, 25 Jul 2025 23:59:49 +0000 Received: by outflank-mailman (output) from mailman id 1058730.1426302; Fri, 25 Jul 2025 23:59:49 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ufSKK-0001Rk-TV; Fri, 25 Jul 2025 23:59:48 +0000 Received: by outflank-mailman (input) for mailman id 1058730; Fri, 25 Jul 2025 23:59:47 +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 1ufSKJ-0007YZ-1L for xen-devel@lists.xenproject.org; Fri, 25 Jul 2025 23:59:47 +0000 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on20613.outbound.protection.outlook.com [2a01:111:f403:200a::613]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 700ed991-69b3-11f0-b895-0df219b8e170; Sat, 26 Jul 2025 01:59:45 +0200 (CEST) Received: from BN0PR04CA0068.namprd04.prod.outlook.com (2603:10b6:408:ea::13) by BL1PR12MB5897.namprd12.prod.outlook.com (2603:10b6:208:395::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8964.22; Fri, 25 Jul 2025 23:59:36 +0000 Received: from BL6PEPF00020E66.namprd04.prod.outlook.com (2603:10b6:408:ea:cafe::85) by BN0PR04CA0068.outlook.office365.com (2603:10b6:408:ea::13) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8964.24 via Frontend Transport; Fri, 25 Jul 2025 23:59:36 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by BL6PEPF00020E66.mail.protection.outlook.com (10.167.249.27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8964.20 via Frontend Transport; Fri, 25 Jul 2025 23:59:35 +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.39; Fri, 25 Jul 2025 18:59:35 -0500 Received: from SATLEXMB04.amd.com (10.181.40.145) 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.39; Fri, 25 Jul 2025 18:59:35 -0500 Received: from fedora.mshome.net (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2507.39 via Frontend Transport; Fri, 25 Jul 2025 18:59:34 -0500 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 700ed991-69b3-11f0-b895-0df219b8e170 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=w+gDYA7JrCwrAXH10ErsbD9ixPIhK/S9hSaJKUWApPHYeFuLYAqujcCvmyjdoTk/k/BscR1kausV6vJb1UPCHUdbg6PEplExJiX2853nFNCg/hsaSMJpEI6c+BmruO5vgDqksAIlho12vRleFFmsteyY55A5rvbCh/U15ctKVZ20tT72j+8ewkqRGhqqikzBUbaIn+K149HCbQw0JgJJ7eJXXOOsfXYFTQfJbASHufHR6W4mdM71Wpne1WkDz+tWiVZygZ8b7pqumiorFfq2m3J3y8Tk3QqaSW6mijp7myDv0W1S5uTkWYaUl1cJv7OLkUigY57ouql6FscIUKNHlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=bu6qy110dZsnS4i5GXYzfa2hnOIRH0xP9Njjyy2eshE=; b=Mv6Pf0g13VUCq0of8tVQlAO94C6eNeQUpDLNwckpVWGNAv2nPmpM1NaD2+drYvXBbVhAAz5T3wY1O0j755d4JaQRdenIvsKT2oKCZbrcTdBAaDFfWHW0xXYCBC8iO9xGHIcpOse0232acHuYeiBEhYnyVsh183YbyxkPiKdNEMwvOkAMu1Kd6ccnEHIy6EdSZ7f+xR0OVhp3eUVjVRSo1FOCvBaB2HNPsuBbjjaQPWMTozy/GtSUwjsX/K2cJktlGXki/GOuS/Ykx/KBJjClEEcJXFXpEEl79Lq2rIoNZxi5v+QJjvo0ovmbqi/Tw4tgOVquTITvM7y2QVkmIZ7R/A== 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=bu6qy110dZsnS4i5GXYzfa2hnOIRH0xP9Njjyy2eshE=; b=4avj68Vwu5ykCyBHFzxAkkde5WQ5ko6Di5vSxZgC/KQgaJFhjbStc/F8W/g/TE7cnBEaancNgabKzg1sFCW7x0RhJ5qNsrYBxYsguOWAtlQrls609uWKe0/sAjpZTXWIEwocw+w7M75obhd7WEZ2p/CfVIDRIAdNFAA3nuQK6vo= 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 (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; 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: Jason Andryuk To: CC: Jason Andryuk , Juergen Gross , Julien Grall , Anthony PERARD Subject: [PATCH v5 07/11] tools/xenstored: Auto-introduce domains Date: Fri, 25 Jul 2025 19:58:54 -0400 Message-ID: <20250725235858.666813-8-jason.andryuk@amd.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250725235858.666813-1-jason.andryuk@amd.com> References: <20250725235858.666813-1-jason.andryuk@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF00020E66:EE_|BL1PR12MB5897:EE_ X-MS-Office365-Filtering-Correlation-Id: 8a119b14-2c6a-4ec5-e52a-08ddcbd74ef4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|82310400026|36860700013|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?SzEQ7orWL2nwIJ9CuFMf51OBv6HvKlSApvdCFufsY0lhrIv5lrfaTpt8zAip?= =?us-ascii?Q?VrpZQiszgBHqxFC/6cG1rOctF/UOZ7VXGakEK26BePB22e+5NYmClL6SWq66?= =?us-ascii?Q?+rtUxI1xM/aKccfNUiCIR7I8Q4NRb61+9Bqs2Cy1tUeqsXfFrvQTbu6Z6naF?= =?us-ascii?Q?vntiTp0Pq0e+zv9dkueCbeQTpkYWnGR7qTT+Ek5mNdTBrIQra0D6gCS7umwB?= =?us-ascii?Q?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vNZq3OXoq7v?= =?us-ascii?Q?4NucC8SjuXGqoxzUkXcXPmz6SPWfsbHo/nwJ9SguCoaqjpW4G6wPWci39hiD?= =?us-ascii?Q?Z9dX49uKtoHlX+TEhK6yi6SKpqQ1j2t00FA2ZGs781lkng9+NWHzCrS1FgRD?= =?us-ascii?Q?J++QhSWO/F24oMbXj0Kd20jZoWrHc9It2mf9Ur/hoHI+APr29QVZ1g5oaO8D?= =?us-ascii?Q?R6xM2uBA8bbKw2JLpODEfsqpc2XBE97tiyzWXXSUZ3TfGeu3Z3SvWWGkAey4?= =?us-ascii?Q?98tpQ6vaAA+wD5/08hKH1gUGotptBS1UxwIUWitY4b3r3/KRmcbdJKa18MvY?= =?us-ascii?Q?iT/lAznK+mDEqLRgQ+p7r1hs2URhzBJJ0FGhJYCChZY6/mb+qM2BSapOAbr6?= =?us-ascii?Q?mXr3xtWWjANQMrqSBDxVrTDhcu2xJDqlfk98?= 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:(13230040)(376014)(82310400026)(36860700013)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jul 2025 23:59:35.9109 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8a119b14-2c6a-4ec5-e52a-08ddcbd74ef4 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: BL6PEPF00020E66.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5897 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1753488016400116600 Content-Type: text/plain; charset="utf-8" Replace dom0_init() with init_domains() which uses libxenmanage to iterate through all existing domains, storing them in a list. The xenstore domain is introduced first, and then all the other domains are introduced. The xenstore domain needs to be introduced first to setup structures needed for firing watches. dom0_domid is updated with the xenstore domain, since it really indicates the local domain. priv_domid is set to the control domain. This makes it limited to a single domain. These features let xenstore automatically connect any existing domains, which means it doesn't need to be done manually from init-dom0less. For a legacy dom0, the result should be unchanged. For a late xenstore stubdom it should also be the same, but priv_domid would be set automatically to control domain (which default to 0 normally). Always signal the event channel for initial domains. This gets dom0 (a local xenstored domain) to connect. Also always write XENSTORE_CONNECTED since we know we are connected at this point. To support ARM dom0less domains with xen,enhanced =3D "no-xenstore" a failed introduce_domain() becomes non-fatal. Normally, HVM_PARAM_STORE_EVTCHN is used to identify . priv_domid from the command line is used, or the first control domain is used. dom0_domid will set to the last xenstore found. This will handle dom0 or dom0less, where only 1 xenstore domain can exist, or stubdom, where dom0 and dom1 exist, and we want to take the stubdom. Signed-off-by: Jason Andryuk Reviewed-by: Juergen Gross --- v5: Add init_domain() helper and call for dom0_domid first outside loop. Fix HVM_PARAM_STORE_EVTCHN typo Only take first priv_domid and respect command line setting Take last dom0_domid Set priv_domid & dom0_domid default values - bail if both unset Use talloc_realloc Remove domain_conn_reset() --- tools/xenstored/core.c | 6 +-- tools/xenstored/domain.c | 100 ++++++++++++++++++++++++++++++--------- tools/xenstored/domain.h | 2 +- 3 files changed, 82 insertions(+), 26 deletions(-) diff --git a/tools/xenstored/core.c b/tools/xenstored/core.c index 37e4dd5a5b..dbf3548a8e 100644 --- a/tools/xenstored/core.c +++ b/tools/xenstored/core.c @@ -2564,9 +2564,9 @@ static struct option options[] =3D { #endif { NULL, 0, NULL, 0 } }; =20 -int dom0_domid =3D 0; +int dom0_domid =3D DOMID_INVALID; int dom0_event =3D 0; -int priv_domid =3D 0; +int priv_domid =3D DOMID_INVALID; domid_t stub_domid =3D DOMID_INVALID; =20 static unsigned int get_optval_uint(const char *arg) @@ -2757,7 +2757,7 @@ int main(int argc, char *argv[]) /* Listen to hypervisor. */ if (!live_update) { domain_init(-1); - dom0_init(); + init_domains(); } =20 /* redirect to /dev/null now we're ready to accept connections */ diff --git a/tools/xenstored/domain.c b/tools/xenstored/domain.c index 71ab7aaad3..5e53fe8736 100644 --- a/tools/xenstored/domain.c +++ b/tools/xenstored/domain.c @@ -1251,41 +1251,97 @@ const char *get_implicit_path(const struct connecti= on *conn) return conn->domain->path; } =20 -void dom0_init(void) +static bool init_domain(unsigned int domid) { evtchn_port_t port; - struct domain *dom0; + struct domain *domain; =20 - port =3D get_domain_evtchn(xenbus_master_domid()); + port =3D get_domain_evtchn(domid); if (port =3D=3D -1) - barf_perror("Failed to initialize dom0 port"); + barf_perror("Failed to initialize dom%u port", domid); =20 - dom0 =3D introduce_domain(NULL, xenbus_master_domid(), port, false); - if (!dom0) - barf_perror("Failed to initialize dom0"); + domain =3D introduce_domain(NULL, domid, port, false); + if (!domain) { + xprintf("Could not initialize dom%u", domid); + return false; + } =20 - xenevtchn_notify(xce_handle, dom0->port); -} + if (domain->interface) + domain->interface->connection =3D XENSTORE_CONNECTED; =20 -void stubdom_init(void) + xenevtchn_notify(xce_handle, domain->port); + + return true; +} +void init_domains(void) { -#ifdef __MINIOS__ - struct domain *stubdom; - evtchn_port_t port; + unsigned int *domids =3D NULL; + unsigned int nr_domids =3D 0; + unsigned int domid; + unsigned int state; + unsigned int caps; + uint64_t unique_id; + int introduce_count =3D 0; =20 - if (stub_domid < 0) - return; + while (!xenmanage_poll_changed_domain(xm_handle, &domid, &state, &caps, + &unique_id)) { + nr_domids++; + domids =3D talloc_realloc(NULL, domids, unsigned int, nr_domids); + if (!domids) + barf_perror("Failed to reallocate domids"); + + domids[nr_domids - 1] =3D domid; + + if (caps & XENMANAGE_GETDOMSTATE_CAP_CONTROL) { + /* + * Only update with first found - otherwise use command + * line. + */ + if (priv_domid =3D=3D DOMID_INVALID) + priv_domid =3D domid; + } =20 - port =3D get_domain_evtchn(stub_domid); - if (port =3D=3D -1) - barf_perror("Failed to initialize stubdom port"); + if (caps & XENMANAGE_GETDOMSTATE_CAP_XENSTORE) { + /* + * Update with last found. dom0 or dom0less will only + * have 1 domain. stubdom there will be dom0 and dom1, + * so this will take the second for stubdom. + */ + dom0_domid =3D domid; + } + } + + if (dom0_domid =3D=3D DOMID_INVALID) + dom0_domid =3D priv_domid; =20 - stubdom =3D introduce_domain(NULL, stub_domid, port, false); - if (!stubdom) - barf_perror("Failed to initialize stubdom"); + if (dom0_domid =3D=3D DOMID_INVALID) + barf("Could not determine xenstore domid\n"); =20 - xenevtchn_notify(xce_handle, stubdom->port); + /* + * Local domid must be first to setup structures for firing the special + * watches. + */ + if (init_domain(dom0_domid)) + introduce_count++; + + for (unsigned int i =3D 0; i < nr_domids; i++) { + domid =3D domids[i]; + if (domid =3D=3D dom0_domid) + continue; =20 + if (init_domain(domid)) + introduce_count++; + } + + talloc_free(domids); + + if (introduce_count =3D=3D 0) + barf("Did not initialize any domains"); +} + +void stubdom_init(void) +{ +#ifdef __MINIOS__ mount_9pfs(); #endif } diff --git a/tools/xenstored/domain.h b/tools/xenstored/domain.h index 844ac11510..6a78f06935 100644 --- a/tools/xenstored/domain.h +++ b/tools/xenstored/domain.h @@ -84,7 +84,7 @@ int do_reset_watches(const void *ctx, struct connection *= conn, =20 void domain_early_init(void); void domain_init(int evtfd); -void dom0_init(void); +void init_domains(void); void stubdom_init(void); void domain_deinit(void); void ignore_connection(struct connection *conn, unsigned int err); --=20 2.50.1