From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=192.198.163.10 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796331078; b=SYgSW0loJRyoBWyhTnnMbKznrpFrgh3IX5xy9uu+MDFOjQFELRdW7P+f3wm6lnb+4/tg ikZ1h3mhC+q1m1sBox67PQ7dRUXqrpOzPm/2BNpdfyV8xfijbPnecKcLDFFfz1srY/krJ e7oInOtBzqSkptXE4wAS6exWRPtiiJIS7RKNeLs+LoSbTC5vcDq49HXNplNlk73NbWLzn +wf2k4OPU7X24bJvjqbEgqpybs1B0zl9o/aO1y3CL0tiXzw4PgGKlsjDIGHgITACROTUd yB4f6H547XGPXupFEuIXrBbW+kUQzF4xArSFUNbM3bS8YVZvE7DeoM1pd3dLNCjQIgA== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796331078; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:Received:Received: Received:Received:Received:Date:From:To:CC:Subject:Message-ID: References:Content-Type:Content-Disposition:In-Reply-To: X-ClientProxiedBy:MIME-Version:X-MS-PublicTrafficType: X-MS-TrafficTypeDiagnostic:X-MS-Office365-Filtering-Correlation-Id: X-MS-Exchange-SenderADCheck:X-MS-Exchange-AntiSpam-Relay: X-Microsoft-Antispam:X-Microsoft-Antispam-Message-Info: X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-Exchange-RoutingPolicyChecked: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-CrossTenant-Id:X-MS-Exchange-CrossTenant-MailboxType: X-MS-Exchange-CrossTenant-UserPrincipalName: X-MS-Exchange-Transport-CrossTenantHeadersStamped:X-OriginatorOrg; bh=NYcyHhb1Ip/g55yxvXACMNGTSqB9o3FBSgAwf0wFA5E=; b=2iUiVp3fnePSe7THKyNY6rW+H32dUdM+PtQKZ8xGjCmgQsC7r/5c11M3COhTrKK1LXDv xKxPl0nXiy00L3rtEqgDiWfzKoF19bDw8reS7IOXjfMKIU42T7V48ekA2jBoiw8mnAlAn +r+Q74QvBdMfxp3WV9gqQ9nYAcbAUoJGMhFPiJ3euPyyrQqu9thdJgFQYS7zhaZGxGrvH xYnLKuPaJwsYldulgFVlE7mngtgPg10dWDEsbcAiremcuJZz4jbZrLmr9wRHpCHjYOBlq UB4dKTZhVXyFVdmgOH1mmixjOUVcZYmGrkMpH53QlJCKnkEMZpCKXajc/TnCNoUSAfw== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=loTxVIpJ; arc=pass header.oldest-pass=0 smtp.remote-ip=192.198.163.10 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D0DC3606A698; Thu, 3 Dec 2026 20:51:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D0DC3606A698 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=loTxVIpJ DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796331078; x=1827867078; h=date:from:to:cc:subject:message-id:references: in-reply-to:mime-version; bh=NYcyHhb1Ip/g55yxvXACMNGTSqB9o3FBSgAwf0wFA5E=; b=loTxVIpJrMPzgkP+bDntU8xxiSMx1iqGCsge1nQK5x5P9Ol0utvgMzRS JhL4iBaYHRbwq9K5ZWKNiAXAZ/nqR8ud9KZnQstAy6EMThBUyWJakeh+p +rCfRlJ/1/2cscdm0wsqlVyMi7Et1v6WjEAqGpFBzDnm0F/3zsDtTsKa2 p+kvX3aQ4q4bUTLeNoxDSMZkocCjhKGs42HlgKGixMERKwnsnEYFzSf9M r7drnUsvVb25epsJ1kOCr2b4ra2TFQ6Sqq6CvvI6u18SzlUR2Vls3ji+k FMMWQ/tnHD31Klto+FRvfZWYWUkjYZS0ITb6fHq2brQagbbDwaT1CZD6V Q==; X-CSE-ConnectionGUID: G6ZcjaLjRze9GrH+btsYcQ== X-CSE-MsgGUID: n0IKtSguQGeAzt3edsY1vg== X-IronPort-AV: E=McAfee;i="6800,10657,11985"; a="5192518" X-IronPort-AV: E=Sophos;i="6.29,77,1794902400"; d="scan'208";a="5192518" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2026 12:51:17 -0800 X-CSE-ConnectionGUID: E9Q49AwqRd6No1NGadXjoQ== X-CSE-MsgGUID: zou1bUJFTLGTiuloMyx/ng== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.29,77,1794902400"; d="scan'208";a="13909888" Received: from orsmsx903.amr.corp.intel.com ([10.22.229.25]) by orviesa002.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2026 12:51:17 -0800 Received: from ORSMSX901.amr.corp.intel.com (10.22.229.23) by ORSMSX903.amr.corp.intel.com (10.22.229.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Thu, 3 Dec 2026 12:51:16 -0800 Received: from ORSEDG901.ED.cps.intel.com (10.7.248.11) by ORSMSX901.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57 via Frontend Transport; Thu, 3 Dec 2026 12:51:16 -0800 Received: from BN8PR05CU002.outbound.protection.outlook.com (52.101.57.57) by edgegateway.intel.com (134.134.137.111) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Thu, 3 Dec 2026 12:51:16 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=FWoohj2K7Eq4gZspOjZSpJEKo13upbaslND9Gxywhuf5AD9ihwcjwzvmeYBON3PR8nGRYosjcIeAOTEifctM5uxjMVSZZFxSryTcJj09jlWHQYzgnwvCoherY5zOGAwlyJpxcVY2msq28/SOLhTdA6xmrAeRWFCzdJ8duSCTtXHBEqmuY03Cqf25rO0gC61JeJalV6zQeMd/TPp21beUEf+TuaZj6KBIaCQFgrPld7OktDqQJdvDUNzIzb+svZtf8CjvJisufJ5GdO8zU0PTaoCaZTHVaSQ4Cign0yDNRUdGLXn4ywpfz8nVIapL+xDISVgOxN+nm6TcfiJ14YvTEA== 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=NYcyHhb1Ip/g55yxvXACMNGTSqB9o3FBSgAwf0wFA5E=; b=p7fbXijr1JE1tQad3e2PBpKXmy76TpPc4vSSatzIUCZzmWQSieZ+Tp1Vhen0guaZoiRMaPaZ9+beb7s72fJER7/h+pJH6Yl/hXn8HaRD0P/HCHG9+BRLCvKCkh7QQc7AT6lihIBymkiBaJiLc5gI2zE3Fuk1kjEVVnV5Hs8esWZ5U9DLHSXJC7SEfZPnYS7U5oRkkUE+I9PXQr7I5iXTr9UT9DW+TsRvGwoHUSeNcZ2PXaSljZiO4hTNSYMUdYdGHRPKYWT8VK5MokhqxjXGAGzZ0UEHxxU+ClmMSSPsFCkpND9G9gJTQMP1ugTE+Avh03hglXydsAlPiJGZrtOtbQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from DS4PPF0BAC23327.namprd11.prod.outlook.com (2603:10b6:f:fc02::9) by SJ0PR11MB5790.namprd11.prod.outlook.com (2603:10b6:a03:422::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.7; Thu, 3 Dec 2026 20:51:08 +0000 Received: from DS4PPF0BAC23327.namprd11.prod.outlook.com ([fe80::a1fc:97e0:329a:4aa7]) by DS4PPF0BAC23327.namprd11.prod.outlook.com ([fe80::a1fc:97e0:329a:4aa7%6]) with mapi id 15.21.0688.011; Thu, 3 Dec 2026 20:51:08 +0000 Date: Thu, 3 Dec 2026 12:50:57 -0800 From: Alison Schofield To: CC: Dave Jiang , , "Davidlohr Bueso" , Jonathan Cameron , Vishal Verma , Ira Weiny , Li Ming , Ben Cheatham , "Alejandro Lucero" , Richard Cheng , , Sashiko Subject: Re: [PATCH v2] cxl/region: Fix self-deadlock when cxl_memdev_attach_region() fails Message-ID: References: <20261119-junhomax-fix-cxl-attach-region-deadlock-v2-1-32ddef645e52@xcena.com> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261119-junhomax-fix-cxl-attach-region-deadlock-v2-1-32ddef645e52@xcena.com> X-ClientProxiedBy: SJ0PR03CA0125.namprd03.prod.outlook.com (2603:10b6:a03:33c::10) To DS4PPF0BAC23327.namprd11.prod.outlook.com (2603:10b6:f:fc02::9) X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS4PPF0BAC23327:EE_|SJ0PR11MB5790:EE_ X-MS-Office365-Filtering-Correlation-Id: b7f20861-9787-41d8-d9f4-08df517f279b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|23010399003|7416014|366016|261102123227099003|11063799006|56012099006|261026140227099003|261026121527099003|261028144727099003|261021121427099003|261022105027099003|261102130727099003|261022075727099003|10067099003|261021123027099003|261022113327099003|18002099003|22082099003|261009223027099003|6133799003; X-Microsoft-Antispam-Message-Info: C+UC2N2wTvN921dXoJFqKd9IIsDnm5hgfGKRs3z4DlJ+O96DCh8WlmaVuHuDtN9+2at4vOqMv3PSSPw3Cv/ttmbx5sy7E5t6/96zuM+tb5DDILFbl9LPtSPJiPuBb48DYMQx/x0XvgnyAAFTH9hD1WDdNV38P5f8DVfWGsY4/+/Cn1QgwFKJLh+QF4a5iN86aXIoojtRgMBWLkkakMzZxgkPIXdBz7Pkav3Hb8DQI/GC82CC/fQxabA1ukTUcncOvGCUfXrh1bBioc8qZxWecY7IqiE6JjCPAEA2jzlFGJbP7QH4rwUaVES57venirdwnpWC/60oehNvpl+hwVefLrmRkZ4OYTCAJhoSq97ENCXmpt0hm+TlyyVFK7htO20X0wz84couH26ZzC+LKhB9yzRs83NbY8vlj+T3b8CZAfbvhN9CEgm17gUrOLKreC0TPoxO6anuruTXwGGb4qoKbFl8jzmy+OpZQPjfX3W55P+4lQGms/yYLYGCQBYcl7FgT4uzTdmjfZ6i54ab7baTAK1MBki3HZySXn3/dRG9YO/DgwfUZMqCYZWGpzAOjyao5+uvnzSZMV8RS7n00rB2A9PQZDl3IfiB8xeNZpGOwCv+ULdqSY2brkUm2WG4+34f X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS4PPF0BAC23327.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(1800799024)(23010399003)(7416014)(366016)(261102123227099003)(11063799006)(56012099006)(261026140227099003)(261026121527099003)(261028144727099003)(261021121427099003)(261022105027099003)(261102130727099003)(261022075727099003)(10067099003)(261021123027099003)(261022113327099003)(18002099003)(22082099003)(261009223027099003)(6133799003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?TO3PCACwKR4YmoKGeem/4+1+WarQE/k4wM27Odf3gc4BcIu8XHXZ3F51YvS8?= =?us-ascii?Q?1uHH2X4THqdOzs6EIyxXqpkpy3O/LKtWqbM4lMKqBAbURfv36pOwfWXBqSAp?= =?us-ascii?Q?BgcBp5+x6G1uMtDXBMsU1HA5Y+BYiZ+ZrhTs3QIBsoVLZor9IGpzbydVcETW?= =?us-ascii?Q?ejvy5egJvvJbQvn4sUZpm7HoAmnTUcvhlEAEsnoaCNddBt1vKnsliKaGAIqV?= =?us-ascii?Q?bjcQK84IE+U/4lMxCDSY4RjxsXN9C4JK8r3FpDiGSW4QgmOU6snWFoxzTzSp?= =?us-ascii?Q?6yx20/hZfQNF3PMzOY/jFleaP2N0OfYFQ/hRSRiTWzGdKiVVQEiEBDIdBaTr?= =?us-ascii?Q?f2AikUAFBLxjwuREkwyo/Fo8UuLUI6YW4RM3S0qgMlBDlNOBfiDAX9Q0aBlv?= =?us-ascii?Q?N1gVNV2biwA+MkaXymz1MZNO3cBnwDpXwFzq1rkxZneeXSlkB3G6QtlgUpOC?= =?us-ascii?Q?3oPPecnfzzcZ9KHEn9RI8v7yVXT6T12/Dgp24gcZeLfIg6vh+T+Ek6tA0FsL?= =?us-ascii?Q?XLLDOmaCAkLhlWAkLu9ciXOKXxl2WFFy/PfmF/XNBb7bfS+CZsjtT5MTqmyT?= =?us-ascii?Q?IK3DLuocRvaHqB2Zud+sZ1h/MxvnpRHNCIjOjx4DbolK0Dzgjsh0P5rAuahN?= =?us-ascii?Q?AOfmBn2NXyUIq2HapYqYVR+r95u0R6r6sBddzapEEUHnnDHOp8PhC0XFqbBG?= =?us-ascii?Q?BPtlBpJgogB0JDdjzJ/GWA2OlMEaO5bRCrwGCGaLYCfnbgU3pGKbhOGyxu4/?= =?us-ascii?Q?WNUQQNNPC3tPggjsmhMPSfeIWnFs2zCg5Idz+3bguMriOFh/+EXuYKYeGPz3?= =?us-ascii?Q?eeQN6SpafVO6omg0/LaINqx+2ajNmBz1j/Q+3CExIRTH+j2sfrtjlXm7qVDU?= =?us-ascii?Q?4D2yM4OfITPwT1PS69BjnZF9emEDfqOGPz/+1LUGMtbN3t6PMNIgym3l39iC?= =?us-ascii?Q?mfFn+XoLTa1BSUIaM1fKaL2Z4aopipgQ6U52uDiJji/02XdgAvseN3Y+rElq?= =?us-ascii?Q?YpEWzr3jg7PW3fiWO+T+pHMaMyiodKj9zyRvJvH6Y1xX+x++hQWx5rVXH4xJ?= =?us-ascii?Q?yhAPZ54Ia27eLnMlNu2ufUPEqiYP5+Xuy2OSdvZNa5M9vG9ecMTEmOzlPQlZ?= =?us-ascii?Q?ATEHQZXojrsSrI5PfJ9WkXha6jJt+uF2nqmUO8KZk8YdyTTjGxtbregZg18a?= =?us-ascii?Q?T67oEMCJ24u4aZu3ON4/4J8e578eX/SJfEIbvrT3P7QCvOi0nREEZvaQbHs3?= =?us-ascii?Q?6u+Safd+D3mO8gGw7keOtsK4vRUooHG4G/9zx9UJjjtHiNl1g6y55KBRNnRE?= =?us-ascii?Q?EFWD02a5Yh4u0TJE7j6RC58hDuNGBI34MHzeua2PqTfbcymPa33LToHyTudd?= =?us-ascii?Q?+nms6oC8RWxpA/sQCWG90ETDoG1Qs+y1yQ/Ux07rrvELg7bIfpAHc3DNfhYN?= =?us-ascii?Q?8svAZ7gm4sormC0WPNpuhvbPvg4e21wrV5kRD/BDjSSHbe3G8Ma2GQWRurUZ?= =?us-ascii?Q?1uV/ETcj3hmoO+IWNJ/wmZ1enshzGES7szXiDzO7qJJ7LpwU7TUDM2lXdzRf?= =?us-ascii?Q?gx07r4EcWIBSZBXUwp0PHBjhB6Sth0wHNQEBLftl3aq9XZJpIWzbXny7dUZE?= =?us-ascii?Q?IYiLy1P1y70brBI60zq5ggwZF3bO0Op4L6ea7xErcKKmuej7+VkrcRMN0kH2?= =?us-ascii?Q?5iIuYFxbT+zQMMEhbwkmZGhJerARNcPEoa5z2ryETG3Op9LhuBinK1IJFZcM?= =?us-ascii?Q?Tbr6hT4TO7mLBzWOQvkF6r1NL1/DUjY=3D?= X-Exchange-RoutingPolicyChecked: XtKpfeZduuHzmqengAtxaIExOaZxFsyXEetUQFD0GiZN4qpnCSdmOu8XlbH65lRl2QuR9BIlUeK87W5UnIDRidHL/Kun3HixMoU0E77AREZaXLvWSs0jtGdXiDUyf0HaBDaYvIgympJcLgBffEH9cnntr0wZ/tc+VROzxuzr3ZFa+3CztYaSfQlm09FH4Mnswb9zFTd6mvRZspP1mnr6tmVuoxu7C5IhddEyEbqHXTfI1Pbs//sCnPWj1B/Ojtwf9kZ7qWBk6arEJgjQfaFMCQxRBl+C3aWFzH3OoA1IyPCdNXBaXtrrs5N3mIWmv9U9/jhXQNjsoXQIZkYL34lf2w== X-MS-Exchange-CrossTenant-Network-Message-Id: b7f20861-9787-41d8-d9f4-08df517f279b X-MS-Exchange-CrossTenant-AuthSource: DS4PPF0BAC23327.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Dec 2026 20:51:07.9600 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ebd6wlHZNpnkxEDqurfLBj2MhKnmc0AkdtUt8vJuFnGCNCVaf6e6xnVYa18ToaD9wV0yRScTVsemgRHcotZKdwUyxZEp9RmX5rWKAPlYCZw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR11MB5790 X-OriginatorOrg: intel.com On Thu, Nov 19, 2026 at 10:44:36AM +0900, Junho Cha via B4 Relay wrote: > From: Junho Cha > > cxl_memdev_attach_region() holds cxl_rwsem.region for read while it > registers endpoint_unregister_region() with devm_add_action_or_reset(). > If registering the action fails, devm_add_action_or_reset() runs the > action at once, which reaches cxl_decoder_detach() through > unregister_region() and detach_target(): > > cxl_memdev_attach_region() > down_read(&cxl_rwsem.region) > devm_add_action_or_reset() /* fails with -ENOMEM */ > endpoint_unregister_region() > unregister_region() > detach_target() > cxl_decoder_detach() > down_write_killable(&cxl_rwsem.region) > > The task then waits for a write lock while holding the same rwsem for > read, and never makes progress. Before it hangs, lockdep also reports > a circular dependency: endpoint_unregister_region() takes > cxlrd->regions_lock under cxl_rwsem.dpa, while cxl_add_to_region() > takes cxlrd->regions_lock before both rwsems. > Hi Junho, The code changes look functional, but I'll ask for changes to this commit log and the variable naming inline below. Please rewrite the commit log as a concise kernel-style summary. Replace the call trace and the surrounding walkthrough with a short paragraph that leads with the bug, like "a devres allocation failure during cxl_mem probe can deadlock the probing task because cleanup tries to take the region rwsem for write while that task holds it for read." The wait is killable, so "never makes progress" is too absolute. A fatal signal can interrupt the detach and leave the decoder attached to an unregistered region. Keep the lockdep inversion to one sentence. > Register the action with devm_add_action() instead, still under both > rwsems, and if that fails, run it only after the rwsems are dropped. > The endpoint device lock stays held throughout, as before. > Summarize the locking rationale. Something like - Keep both rwsems held through action registration so the region cannot be detached between validation and registration. If registration fails, release both rwsems before unregistering the region to avoid the self-deadlock and the lock-order inversion. Keep the endpoint device lock held throughout. > Reproduced with cxl_test (type2_test=1) by failing the devres > allocation through failslab, with the stack filter limited to > cxl_memdev_attach_region(). Without this patch the probing task hangs > in cxl_decoder_detach(). With it, the cxl_mem probe fails with > -ENOMEM, the region is unregistered, and lockdep stays quiet. Keep the fault-injection setup and close with the result: probe returned -ENOMEM, the region was unregistered, and lockdep reported no inversion. See renaming asks inline below... > > Fixes: d8dcb0b74b04 ("cxl/region: Introduce devm_cxl_probe_mem()") > Reported-by: Sashiko > Link: https://lore.kernel.org/all/20260805080537.7489E1F000E9@smtp.kernel.org/ > Assisted-by: LLM > Signed-off-by: Junho Cha > --- > Dave pointed at this reset path while reviewing the Type2 multipf > series [1]. This is a standalone fix for the existing code that keeps > the region teardown when registering the action fails. > > [1] https://lore.kernel.org/linux-cxl/6bc33514-8bfb-44d6-8fde-28f45dff5eb9@intel.com/ > --- > Changes in v2: > - Register the action under both rwsems as before and only run the > unwind after dropping them. v1 left a window where the region could > be detached before the action was registered (Ben). > - Add Reported-by/Link for Sashiko. > - Drop Alejandro's Reviewed-by, since the fix changed. > - Link to v1: https://patch.msgid.link/20261117-junhomax-fix-cxl-attach-region-deadlock-v1-1-f373a135edd2@xcena.com > --- > drivers/cxl/core/region.c | 32 ++++++++++++++++++++++++-------- > 1 file changed, 24 insertions(+), 8 deletions(-) > > diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c > index 237172b33f55..f9538ac98a1f 100644 > --- a/drivers/cxl/core/region.c > +++ b/drivers/cxl/core/region.c > @@ -4437,7 +4437,8 @@ static int first_mapped_decoder(struct device *dev, const void *data) > * Runs in cxl_mem_probe context after successful endpoint probe, assumes the > * simple case of single mapped decoder per memdev. > */ > -int cxl_memdev_attach_region(struct cxl_memdev *cxlmd) > +static int __cxl_memdev_attach_region(struct cxl_memdev *cxlmd, > + struct cxl_region **unwind) Please call this out-parameter region_out. "Unwind" describes the error-handling operation. This parameter gives the caller the region to unregister. > { > struct cxl_attach_region *attach = > container_of(cxlmd->attach, typeof(*attach), attach); > @@ -4446,10 +4447,6 @@ int cxl_memdev_attach_region(struct cxl_memdev *cxlmd) > struct cxl_region *cxlr; > int rc; > > - /* hold endpoint lock to setup autoremove of the region */ > - guard(device)(&endpoint->dev); > - if (!endpoint->dev.driver) > - return -ENXIO; > guard(rwsem_read)(&cxl_rwsem.region); > guard(rwsem_read)(&cxl_rwsem.dpa); > > @@ -4484,10 +4481,11 @@ int cxl_memdev_attach_region(struct cxl_memdev *cxlmd) > > /* Only teardown regions that pass validation, ignore the rest */ > get_device(&cxlr->dev); > - rc = devm_add_action_or_reset(&endpoint->dev, > - endpoint_unregister_region, cxlr); > - if (rc) > + rc = devm_add_action(&endpoint->dev, endpoint_unregister_region, cxlr); > + if (rc) { > + *unwind = cxlr; > return rc; > + } > > attach->hpa_range = (struct range) { > .start = cxlr->params.res->start, > @@ -4495,6 +4493,24 @@ int cxl_memdev_attach_region(struct cxl_memdev *cxlmd) > }; > return 0; > } > + > +int cxl_memdev_attach_region(struct cxl_memdev *cxlmd) > +{ > + struct cxl_port *endpoint = cxlmd->endpoint; > + struct cxl_region *unwind = NULL; Please call this pointer cxlr. The call to endpoint_unregister_region(cxlr) already shows what the caller does with it. > + int rc; > + > + /* hold endpoint lock to setup autoremove of the region */ > + guard(device)(&endpoint->dev); > + if (!endpoint->dev.driver) > + return -ENXIO; > + > + /* Detaching the region takes cxl_rwsem.region, so unwind without it */ I'll also suggest dropping this comment. The helper's scoped guards show where the rwsems are released, and the call to endpoint_unregister_region() shows what happens afterward. So - the code is self-documenting. "Unwind without it" just restates that ordering and does so less clearly IMO. > + rc = __cxl_memdev_attach_region(cxlmd, &unwind); > + if (unwind) > + endpoint_unregister_region(unwind); > + return rc; > +} > EXPORT_SYMBOL_FOR_MODULES(cxl_memdev_attach_region, "cxl_mem"); > > /* > > --- > base-commit: 32af7819352bae9c690ebe277a44eceb501d5c68 > change-id: 20261113-junhomax-fix-cxl-attach-region-deadlock-fc0a425f7265 > > Best regards, > -- > Junho Cha > >