From nobody Thu Oct 30 23:25:35 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=1753253659; cv=pass; d=zohomail.com; s=zohoarc; b=RJ1BTdYD9TE3QbNIbOMT0lmdZhM38hDdwf//w/XkhQEmn4pONFtex+ar3a7jSt8EhLjSGq7TmT3bZdw4WNnHJNRmt3wfc+udcfL30sFoG9USiAqfVWEEZd0R/Qx0PcLaTcqU2on4mcgQW8Ivv4hzZaiKPQJcEAbAqyCWu/cTeW8= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1753253659; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=PyMEOiDAC6cTdjm1z7YemfcJPrj4nzyhzLEJWpy3Ks8=; b=O3kHTupINZtUKy+3eztHc8gS2sCOd0dqdkGGy6Zb8Kzd8IlqYDLPD2HcfmmPlMmjRunGLOkvCJqhn+qbNN5mnKYaLy0DfktzTTnHX3h7GoilsuernFuP1UyEmEMDTrx/nyJ9mMuTw5CElANZDa0rjLWFRQaDjg9lZ4u35uSlwCg= 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 1753253659012784.1197457817832; Tue, 22 Jul 2025 23:54:19 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1053319.1422071 (Exim 4.92) (envelope-from ) id 1ueTMa-0000NZ-R6; Wed, 23 Jul 2025 06:54:04 +0000 Received: by outflank-mailman (output) from mailman id 1053319.1422071; Wed, 23 Jul 2025 06:54:04 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ueTMa-0000NS-Nm; Wed, 23 Jul 2025 06:54:04 +0000 Received: by outflank-mailman (input) for mailman id 1053319; Wed, 23 Jul 2025 06:54:04 +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 1ueTMZ-0000NK-Vq for xen-devel@lists.xenproject.org; Wed, 23 Jul 2025 06:54:03 +0000 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on20607.outbound.protection.outlook.com [2a01:111:f403:2415::607]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id d0706c93-6791-11f0-a31d-13f23c93f187; Wed, 23 Jul 2025 08:54:02 +0200 (CEST) Received: from BYAPR05CA0097.namprd05.prod.outlook.com (2603:10b6:a03:e0::38) by DS0PR12MB9728.namprd12.prod.outlook.com (2603:10b6:8:226::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8964.21; Wed, 23 Jul 2025 06:53:58 +0000 Received: from MWH0EPF000971E8.namprd02.prod.outlook.com (2603:10b6:a03:e0:cafe::39) by BYAPR05CA0097.outlook.office365.com (2603:10b6:a03:e0::38) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8964.21 via Frontend Transport; Wed, 23 Jul 2025 06:53:58 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by MWH0EPF000971E8.mail.protection.outlook.com (10.167.243.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8964.20 via Frontend Transport; Wed, 23 Jul 2025 06:53:57 +0000 Received: from penny-System-Product-Name.amd.com (10.180.168.240) 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.39; Wed, 23 Jul 2025 01:53:53 -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: d0706c93-6791-11f0-a31d-13f23c93f187 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=BKZhfkW6szCBbKr/BW2zjuYLqwWYWZoUplaNv4I3mgfDNs/cKCKUrix1IZ5mRGPr3KjsI/Pr2oaPiDnOdv0r/TGNGMeRAWQ7DirSxHbaqTMnLs6SwLVTpdQJQILI5jEobqGegAA6pDTDkxbQpvDHFYXQ//cJkrVCOpCsoiJ3BS+gRbcwq2G6Gio3+Z2w4qg1kVGKyIPVmi0Mh12PXBeY1PK61gCY4lof4PUjUqg4zYJmVnB9oWKLMH1dqW1rvBP1wfdb5hY9S/Boo4gF3Fn0ZtB+Z2Q0Hddxtyj6OSY5ipE5LEbtz77XrNlzeqYQAK73Ah++wG9anwPPp6NH7s7FcQ== 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=PyMEOiDAC6cTdjm1z7YemfcJPrj4nzyhzLEJWpy3Ks8=; b=ff6VLQmBAqaUH7SFrLqrdWMoicZLYdbqby0bEM6xyBK3cNH5juIiHtJW7FQBMBK8ulnbZbTWJZto57la935LMCouul2ORTu4y7rN/y6XHbqeI4W4mupoQeZXjezt0mMNis1oFLXvkmRMdl/0yNSL9sZlrfWXM+v2az13U6HKj5b3aJygGhamhmxhk46X0VvBrER0MNrzLutcZz+1WxMhMmXRsNf07JOwT0Ime32mcg/Q8LD87+9093yHeV32DaHYCCJLUTwKalG7EdzyFezwPhdgb+I6Zo5E5iRksN6AoZZVHTId3vfQKXtLI/7EQoW47G2J8yMTTuNUKV5UVG27Yw== 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=PyMEOiDAC6cTdjm1z7YemfcJPrj4nzyhzLEJWpy3Ks8=; b=hSFJ60k40iUuQEor5T/Ag0aF5hDWyiI41N2uN5knjSM6rdH5YAHiCcQDoRV3AArZHlDGO+mDB5EWLsd4Cnthv8eRfE9JvNb8m2yWM5FcjnQzgiqRn+3qMkgQK8ezXkW2OCejGBTOTw4YtM7oovJThCq1ltL+kBYcaSmAm911rXw= 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=SATLEXMB04.amd.com; pr=C From: Penny Zheng To: CC: , Penny Zheng , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , "Julien Grall" , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini Subject: [PATCH v1] xen/domctl: make domctl_lock generic Date: Wed, 23 Jul 2025 14:53:25 +0800 Message-ID: <20250723065325.1452007-1-Penny.Zheng@amd.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWH0EPF000971E8:EE_|DS0PR12MB9728:EE_ X-MS-Office365-Filtering-Correlation-Id: 05eed4aa-fa7f-499f-c62f-08ddc9b5b22c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|82310400026|36860700013|376014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?vQLYLq5TI3GiFu+JDmjKKUXaPJY6IYXTOlCU72QkN+B1uWzw9F5xJRzEy932?= =?us-ascii?Q?HA2U3g17NWOkjCRCFAFrC9/RFuoO3Ql4zPA6mOP5Td71yxrsLR/vzvUC1XbX?= =?us-ascii?Q?KC0bgr+QJclw+6hzoo1ePhIdtIL+6y/zu+RLrvqo5B7+as6oaSJIaDH7TI1x?= =?us-ascii?Q?rLJDLtFULhbzfWVzM3AM7+M332iImiW4myG+noz+xP5sJwJzaGwjIQQL9+el?= =?us-ascii?Q?oROTG5jhWCx530Cu1DSc/T4M3vj5MqfYaug07VNTeB9VOEiT4u1pk7Vq6q3H?= =?us-ascii?Q?2+7IhN+KUrVszog9jdpGbSpcgcuMQkaCPUnVM4JqP8yfOnzpmkbZxnu+58dB?= =?us-ascii?Q?woTZn3dFzj7p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V9k5suXyKsPPkczM5?= =?us-ascii?Q?MOOcX2HqUgCIdZS1JIaAvgPML95V8EwcppHzISW5nDenY1l306GU86LD6itG?= =?us-ascii?Q?GptwEIL3HUn3qpxrqJfdsLUEYlhda0z6w6tvN3BPHXj466wFwQRPolDihs8z?= =?us-ascii?Q?pMHkmwMdPjBbbRmfR3ge/8As8x5xbSN2rKjkOpJISxC6G3lwst3FWYjiGB4J?= =?us-ascii?Q?5TvCxASBT4gKy6TDp4LQXCexU0FHdELfo3UITyeguCpJvruXWnFDIz+/ip4W?= =?us-ascii?Q?tS2RrenxksjRylvGQ3Pstp55FLYUebp7WEZ+?= 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:(13230040)(1800799024)(82310400026)(36860700013)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Jul 2025 06:53:57.0685 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 05eed4aa-fa7f-499f-c62f-08ddc9b5b22c 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: MWH0EPF000971E8.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB9728 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1753253661304116600 Content-Type: text/plain; charset="utf-8" Not only domctl-op could do foreign updates to guest state, some hypercall, like HVMOP_set_param, could also do, and they all need domctl_lock for syncronization. Later, we will introduce CONFIG_DOMCTL to wrap domctl.c. In order to continue using domctl_lock when CONFIG_DOMCTL not defined, we'd like to move domctl_lock_acquire/release() out of domctl.c, and into more common space, domain.c The movement could also fix CI error of a randconfig picking both PV_SHIM_EXCLUSIVE=3Dy and HVM=3Dy results in hvm.c being built, but domctl.c not being built, which leaves domctl_lock_acquire/release() undefined, causing linking to fail. Fixes: 568f806cba4c ("xen/x86: remove "depends on !PV_SHIM_EXCLUSIVE"") Reported-by: Jan Beulich Signed-off-by: Penny Zheng --- xen/common/domain.c | 29 +++++++++++++++++++++++++++++ xen/common/domctl.c | 29 ----------------------------- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/xen/common/domain.c b/xen/common/domain.c index b74d4c7549..6145071e55 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -66,6 +66,35 @@ DEFINE_RCU_READ_LOCK(domlist_read_lock); static struct domain *domain_hash[DOMAIN_HASH_SIZE]; struct domain *domain_list; =20 +static DEFINE_SPINLOCK(domctl_lock); + +bool domctl_lock_acquire(void) +{ + /* + * Caller may try to pause its own VCPUs. We must prevent deadlock + * against other non-domctl routines which try to do the same. + */ + if ( !spin_trylock(¤t->domain->hypercall_deadlock_mutex) ) + return 0; + + /* + * Trylock here is paranoia if we have multiple privileged domains. Th= en + * we could have one domain trying to pause another which is spinning + * on domctl_lock -- results in deadlock. + */ + if ( spin_trylock(&domctl_lock) ) + return 1; + + spin_unlock(¤t->domain->hypercall_deadlock_mutex); + return 0; +} + +void domctl_lock_release(void) +{ + spin_unlock(&domctl_lock); + spin_unlock(¤t->domain->hypercall_deadlock_mutex); +} + /* * Insert a domain into the domlist/hash. This allows the domain to be lo= oked * up by domid, and therefore to be the subject of hypercalls/etc. diff --git a/xen/common/domctl.c b/xen/common/domctl.c index 99de77380f..455fbc5160 100644 --- a/xen/common/domctl.c +++ b/xen/common/domctl.c @@ -35,8 +35,6 @@ #include #include =20 -static DEFINE_SPINLOCK(domctl_lock); - static int nodemask_to_xenctl_bitmap(struct xenctl_bitmap *xenctl_nodemap, const nodemask_t *nodemask) { @@ -65,33 +63,6 @@ static inline int is_free_domid(domid_t dom) return 0; } =20 -bool domctl_lock_acquire(void) -{ - /* - * Caller may try to pause its own VCPUs. We must prevent deadlock - * against other non-domctl routines which try to do the same. - */ - if ( !spin_trylock(¤t->domain->hypercall_deadlock_mutex) ) - return 0; - - /* - * Trylock here is paranoia if we have multiple privileged domains. Th= en - * we could have one domain trying to pause another which is spinning - * on domctl_lock -- results in deadlock. - */ - if ( spin_trylock(&domctl_lock) ) - return 1; - - spin_unlock(¤t->domain->hypercall_deadlock_mutex); - return 0; -} - -void domctl_lock_release(void) -{ - spin_unlock(&domctl_lock); - spin_unlock(¤t->domain->hypercall_deadlock_mutex); -} - void vnuma_destroy(struct vnuma_info *vnuma) { if ( vnuma ) --=20 2.34.1