From patchwork Fri Feb 2 22:25:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hamza Mahfooz X-Patchwork-Id: 13543518 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 158CDC4828E for ; Fri, 2 Feb 2024 22:26:35 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C394710EBC2; Fri, 2 Feb 2024 22:26:33 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=amd.com header.i=@amd.com header.b="MxYdA9Bb"; dkim-atps=neutral Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04on2045.outbound.protection.outlook.com [40.107.102.45]) by gabe.freedesktop.org (Postfix) with ESMTPS id 27E1C10EBC2; Fri, 2 Feb 2024 22:26:32 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=K6ycfbkXDjp3sXqp7nZjrZerCIAWixZ11psn52gZAG2CmG3NurqsGkSuXAMIzN9V0MRuXgYbOzav3uv89uFCE0juZLDxnu9Tc0maQNebbEWJbHRj6aensHz1dIS/mC0w/i+aS+WsH5m/qSMDXRN1WaGkpg6XUIZAbEfVFGiPf5RDFI+mfFlOaUrNtJ5IbqJdGze/QlogBBZhWImEN4o6n1Nol0x9MXyZxVVtkxRpETryztVoQk2gmvAUbMuFrm3PlgI/uW7tSAUoxo30UrObgk+Z9hj433gIWJznDpkCzYT5HU17LnPNnQKjlvnu3TRUlJ3RFZnDWS/2UQeT3CXBKw== 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=P81v5G7zBPiTwN6St3VYTvaErPmQ4ZxmantP7vYOP00=; b=kP+iWeW8EwbPmMNgverndu23ewJ9aPPWxhrilC/kxT89c1WXku3UQSMfwUtE7WhOPVHnHqHbNnT51EopfL27NiGIxoAaFAgptZeT/1m36uPNvfsSdNL7TJbSCDO9s/MVqkkLve8VT/7eXPFaxS0o8Hoa6zE1mTPnOzXMkRg5D1k+XkxDQYmp7rBRNirWL/yqWT+CmsCFgqQt/pI5ZR48nxEhqZTJD6YAMF6fX+GaahkVZO2yYuRT3/zFI0brnwt7vjTIkplMUaunNdJhYiEuOA+WAyfbZJHGsrqis8OR4ZaCrbZ65oamjeJ0GF99ckUcmCJ9T+NL2hTTUpK2OKvksw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.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=P81v5G7zBPiTwN6St3VYTvaErPmQ4ZxmantP7vYOP00=; b=MxYdA9Bb77S0wiKtwUSYoXee9ZNG6GFwr/VVGl1yMdLUtNDlA5HDAFBKvzcGdFQJSxbkqdEnGFTqjh40BuMqb5QTfKSHE5ETo4Z3GT1F6yonlvjFA5ChnM/S4q7qmcfZR67iqNAjSLyasNvZkZopMAZ0HkJsvSLxw3HSuZSgaPk= Received: from CY5PR18CA0049.namprd18.prod.outlook.com (2603:10b6:930:13::17) by CH3PR12MB7714.namprd12.prod.outlook.com (2603:10b6:610:14e::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7270.12; Fri, 2 Feb 2024 22:26:24 +0000 Received: from CY4PEPF0000EE35.namprd05.prod.outlook.com (2603:10b6:930:13:cafe::6d) by CY5PR18CA0049.outlook.office365.com (2603:10b6:930:13::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.26 via Frontend Transport; Fri, 2 Feb 2024 22:26:24 +0000 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 Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EE35.mail.protection.outlook.com (10.167.242.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7249.19 via Frontend Transport; Fri, 2 Feb 2024 22:26:24 +0000 Received: from hamza-pc.localhost (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.34; Fri, 2 Feb 2024 16:26:22 -0600 From: Hamza Mahfooz To: CC: Hamza Mahfooz , , "Greg Kroah-Hartman" , "Rafael J. Wysocki" , Alex Deucher , =?utf-8?q?Christian_K=C3=B6nig?= , "Pan, Xinhui" , David Airlie , Daniel Vetter , Bjorn Helgaas , Mario Limonciello , Lijo Lazar , "Srinivasan Shanmugam" , Le Ma , =?utf-8?q?Andr=C3=A9_Almeida?= , James Zhu , Aurabindo Pillai , "Joerg Roedel" , Iwona Winiarska , "Robin Murphy" , , , Subject: [PATCH 1/3] driver core: bus: introduce can_remove() Date: Fri, 2 Feb 2024 17:25:54 -0500 Message-ID: <20240202222603.141240-1-hamza.mahfooz@amd.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 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: CY4PEPF0000EE35:EE_|CH3PR12MB7714:EE_ X-MS-Office365-Filtering-Correlation-Id: 9ee22a2a-0b2d-4df5-03b1-08dc243dfd9e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Vxya4GWHqRY8KdRp4AaJ9XPsT0VO4DYdHXtLHCINLCUwd/x+E1lREXa+ND5kEectVUNalYWcAHWk8Za4G3kQm7059Gv6B5U/W/otqfEK3r+dro6ezheyNKiRBmwxKEykqsct01sVSEHvpqmAl6qK+gzPbM5jcqChztkypsFg7Iq4yWx2wBq3SIAuKmUYiEvPCWT4Ve/kNHqM2d2m4N3738LIgYDHhYhrHY9ZR9BMRgm4jUfN1Lo6SQbbhv2SGDTD2SgmpsflvCW/5AFIfX1e4gkDkn6uIbWjWL/E5W6ZgvqjdvIdAM4zpXjcDfNh72kkGZi0j+SZdqzK2shi6tOrY2/N0s2cc0ScnB+6FIAH6wGaHOuqRYxwE70vid4i7Rqb4xzj44Bjvv5BchTDwz2qJSj3nLrLfd0+xkTFrhq4NpHnoUM8rnuQvDTSMYj+w+v7Pl+uvjhpLU5DECjUkZsNVmzBk1PaL/+gUBvjNRxzrDSUsCTxUx7ZYVDKPjwa5nwlytgVwGyqSuVLeb9umhuBKnhCQir8W0/Iz8m9LoG585E2vFp7r/+ba4JiGDh5R30f8s0ZgN9FPFAnGXtcoPBSM9mi6MhMDF9D/QeJ654b9+F7LG/JxktK+KmNkhsgcI8/tkA9BJVIx0XW1JrRm+Iu9ePggvpw9mo2Pm9Lye/IU9hyTwgWFyj9dFWuX4zmrRNUX0XOw3LjfvMjWeLqO6LbTMZQsFRbcVmd+oiFEj/9+QTB4dfzijhnRflxLUrAWru87MiVlrEv+q3yqUUjpTQnxCbf//B8eFrBUKixFocdYQu8NrWa9fU1v27s9+CYRJew 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)(4636009)(376002)(136003)(39860400002)(396003)(346002)(230922051799003)(64100799003)(82310400011)(186009)(1800799012)(451199024)(36840700001)(40470700004)(46966006)(478600001)(41300700001)(82740400003)(83380400001)(40480700001)(36860700001)(40460700003)(81166007)(356005)(47076005)(336012)(16526019)(6666004)(6916009)(54906003)(5660300002)(36756003)(316002)(44832011)(8676002)(8936002)(4326008)(426003)(70206006)(7416002)(26005)(70586007)(2906002)(86362001)(2616005)(1076003)(16060500005)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Feb 2024 22:26:24.5426 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9ee22a2a-0b2d-4df5-03b1-08dc243dfd9e 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: CY4PEPF0000EE35.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB7714 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Currently, drivers have no mechanism to block requests to unbind devices. However, this can cause resource leaks and leave the device in an inconsistent state, such that rebinding the device may cause a hang or otherwise prevent the device from being rebound. So, introduce the can_remove() callback to allow drivers to indicate if it isn't appropriate to remove a device at the given time. Cc: stable@vger.kernel.org Signed-off-by: Hamza Mahfooz --- drivers/base/bus.c | 4 ++++ include/linux/device/bus.h | 2 ++ 2 files changed, 6 insertions(+) diff --git a/drivers/base/bus.c b/drivers/base/bus.c index daee55c9b2d9..7c259b01ea99 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -239,6 +239,10 @@ static ssize_t unbind_store(struct device_driver *drv, const char *buf, dev = bus_find_device_by_name(bus, NULL, buf); if (dev && dev->driver == drv) { + if (dev->bus && dev->bus->can_remove && + !dev->bus->can_remove(dev)) + return -EBUSY; + device_driver_detach(dev); err = count; } diff --git a/include/linux/device/bus.h b/include/linux/device/bus.h index 5ef4ec1c36c3..c9d4af0ed3b8 100644 --- a/include/linux/device/bus.h +++ b/include/linux/device/bus.h @@ -46,6 +46,7 @@ struct fwnode_handle; * be called at late_initcall_sync level. If the device has * consumers that are never bound to a driver, this function * will never get called until they do. + * @can_remove: Called before attempting to remove a device from this bus. * @remove: Called when a device removed from this bus. * @shutdown: Called at shut-down time to quiesce the device. * @@ -85,6 +86,7 @@ struct bus_type { int (*uevent)(const struct device *dev, struct kobj_uevent_env *env); int (*probe)(struct device *dev); void (*sync_state)(struct device *dev); + bool (*can_remove)(struct device *dev); void (*remove)(struct device *dev); void (*shutdown)(struct device *dev); From patchwork Fri Feb 2 22:25:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hamza Mahfooz X-Patchwork-Id: 13543519 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 357CCC4828E for ; Fri, 2 Feb 2024 22:26:39 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7F29710EC81; Fri, 2 Feb 2024 22:26:34 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=amd.com header.i=@amd.com header.b="walwakDk"; dkim-atps=neutral Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2044.outbound.protection.outlook.com [40.107.223.44]) by gabe.freedesktop.org (Postfix) with ESMTPS id 16F2910EBC2; Fri, 2 Feb 2024 22:26:33 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JH48bPkFBpkRMAosO3CaBCm5+0ZhqKXzVxNLjwzsIqrClbMfQ+J7uWojdNCstInLdEkLL6kkvQghHfDNRmldIWLZ9BUZFbHYhYiGVS4zJrB0ZDjCop3EW6dG3qwZJXI0RDK1rGUc5+8bcbGOyQWoTUUU7wzdgtI4ROB+RVQrPeNhhvvRhj9a99sFwnG69XELc6P89bH0dg2v1+7YvZnRHU96UEEVWz0IvtBjrBZL78PGuouvH0XRCFScYQ5EVOnRBcdCaMcmnzfG1B9wpZBichxVv+BzAv8LuWbVf8y1fyqXTCmlCFf3cLJJjugHwpUZUZTMYpInJO9B5WizXdScaw== 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=lOad2c9x0ubYcdKEEjzkb2ZBRugUJFx3v8GNWcCJl8A=; b=TD8kdGr6FWnKfzb1cvps6rr4Nsl+4Ys8CHgc4ArjhCGCcbkSfI8guARvgiJQ3g3JX3P5Kyc/yoGCe6wBIsHDQxp/avRy7Dp7f1JrwMGbPwLoMl9hgwmhhhqwcUcy0tfPpnV1dmMmAnTHblK9BSeB8DB2MiXVtRLROZnD0eH+4m88FHfsQGe9Zx/s43nzmAvrqUpHPlbXEfD/iU5mepsYfMKPhOS/Iosoan8pD4q3bn+EZZ/y5OVzIkTUxOwx3gkAQXf44koWIYvugiLfr7r8PufRRi8J0DpjBx38DLvdBVEKiTfl2oPFgSl5Vk7SfjWqkMRqwrN2hunlYx9ioY0JTA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.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=lOad2c9x0ubYcdKEEjzkb2ZBRugUJFx3v8GNWcCJl8A=; b=walwakDkrvt//Gbz8HOzYpA44MlcM1pL66SOe2ePu45a3FT4NqF9YbGNvIRs6xoAthIy9IQNOCFeXHfZ5zNOUcrZivv8IWLiqBdmAW1qE/OCG4fPcR5EpiigkwFp2VTaiHQB/9BbQE2EsZOsQWxx6ByVMGAtlbsJD87Onhej2pM= Received: from CYXPR02CA0022.namprd02.prod.outlook.com (2603:10b6:930:cf::26) by PH7PR12MB7844.namprd12.prod.outlook.com (2603:10b6:510:27b::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7270.12; Fri, 2 Feb 2024 22:26:27 +0000 Received: from CY4PEPF0000EE33.namprd05.prod.outlook.com (2603:10b6:930:cf:cafe::e0) by CYXPR02CA0022.outlook.office365.com (2603:10b6:930:cf::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.31 via Frontend Transport; Fri, 2 Feb 2024 22:26:27 +0000 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 Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EE33.mail.protection.outlook.com (10.167.242.39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7249.19 via Frontend Transport; Fri, 2 Feb 2024 22:26:27 +0000 Received: from hamza-pc.localhost (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.34; Fri, 2 Feb 2024 16:26:25 -0600 From: Hamza Mahfooz To: CC: Hamza Mahfooz , , "Greg Kroah-Hartman" , "Rafael J. Wysocki" , Alex Deucher , =?utf-8?q?Christian_K=C3=B6nig?= , "Pan, Xinhui" , David Airlie , Daniel Vetter , Bjorn Helgaas , Mario Limonciello , Lijo Lazar , "Srinivasan Shanmugam" , Le Ma , =?utf-8?q?Andr=C3=A9_Almeida?= , James Zhu , Aurabindo Pillai , "Jason Gunthorpe" , Wei Liu , Robin Murphy , , , Subject: [PATCH 2/3] PCI: introduce can_remove() Date: Fri, 2 Feb 2024 17:25:55 -0500 Message-ID: <20240202222603.141240-2-hamza.mahfooz@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240202222603.141240-1-hamza.mahfooz@amd.com> References: <20240202222603.141240-1-hamza.mahfooz@amd.com> MIME-Version: 1.0 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: CY4PEPF0000EE33:EE_|PH7PR12MB7844:EE_ X-MS-Office365-Filtering-Correlation-Id: e3b87e87-a491-4be0-d07a-08dc243dff5b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sXJhUV6PfcJj4doUDZppvQuCy8hb9iG9z+uk4Z5AVwIF9OoYzWGMZ9xtrPP44G0b4uj4gE7su4t6D5monmzWimqYQKhSX5v37CaXk70gr9fYKZzqB9HHh/OFGt7DkdbsUjk3ljzJCxpawrOpLzItNCdaaQb2AbPOPHiPTlgWeBLmCsA/J1U9sp19VypnWmSjzxSCz6P8CpsGXQR1bnVrgO4nLZIMYLMmgo9EpvjZB2cLD0dbZaai9vUMWoJGlHGgfRerugm+QjkYXEcKZzswgFWJvdRnsmZOVS3UjzlTVPu+x+TxWMiEhdM02vsTo1/iiYaikKToFaYeof4PntongHa0jALGOSMUVV/ZD0DPKvbFqguA3x/kPh0pGJrVtZgdf20usfLqDcYZdXecjehIH6N8chif0Mi9EwMaZPE+h6rWeZJugiuA+svnh/vMCgeDPo4JyzP8SJbneNRDLWPw4EyUHrtLuh9MO69j1ZZo1iehi0Ls4AU6k/H0FovZoQdFwQIWNshUeV48cLI4vGOi1ydsJitkRrnmOZeRBi8GSASIVSgklNag7zZHxctCQFi2zC5S5uPQFmGhtUxmDHK7/yetBo/9TTcf0by5A3IfE06iAZo1sYplYEs6Hk0rIMjeoM2HuTfFRuwQ999wTGlhi1ni+RP0g6x6ttWLgHmF7b+DORKQGWEpG6wAdpdPpeSgjUgQgvscozwFzZHsCG8pkSczbtn7/CMT3fql96ts/Stxl92hWRAdzu6IyML5AxEf37LELwoi66xBo8VVMF0e/7u6BGoF37TshlQbO2kRbjTVfi7+7UXMvXPQfqar1MM9 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)(4636009)(39860400002)(346002)(396003)(136003)(376002)(230922051799003)(451199024)(1800799012)(186009)(64100799003)(82310400011)(40470700004)(46966006)(36840700001)(6666004)(26005)(16526019)(426003)(1076003)(2616005)(6916009)(4326008)(336012)(36756003)(8936002)(2906002)(316002)(54906003)(5660300002)(8676002)(70586007)(86362001)(44832011)(70206006)(7416002)(41300700001)(478600001)(81166007)(47076005)(356005)(82740400003)(83380400001)(36860700001)(40480700001)(40460700003)(36900700001)(16060500005); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Feb 2024 22:26:27.4486 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e3b87e87-a491-4be0-d07a-08dc243dff5b 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: CY4PEPF0000EE33.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB7844 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Wire up the can_remove() callback, such that pci drivers can implement their own version of it. Cc: stable@vger.kernel.org Signed-off-by: Hamza Mahfooz --- drivers/pci/pci-driver.c | 12 ++++++++++++ include/linux/pci.h | 5 +++++ 2 files changed, 17 insertions(+) diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c index 51ec9e7e784f..8aae484c5494 100644 --- a/drivers/pci/pci-driver.c +++ b/drivers/pci/pci-driver.c @@ -466,6 +466,17 @@ static int pci_device_probe(struct device *dev) return error; } +static bool pci_device_can_remove(struct device *dev) +{ + struct pci_dev *pci_dev = to_pci_dev(dev); + struct pci_driver *drv = pci_dev->driver; + + if (drv->can_remove) + return drv->can_remove(pci_dev); + + return true; +} + static void pci_device_remove(struct device *dev) { struct pci_dev *pci_dev = to_pci_dev(dev); @@ -1680,6 +1691,7 @@ struct bus_type pci_bus_type = { .match = pci_bus_match, .uevent = pci_uevent, .probe = pci_device_probe, + .can_remove = pci_device_can_remove, .remove = pci_device_remove, .shutdown = pci_device_shutdown, .dev_groups = pci_dev_groups, diff --git a/include/linux/pci.h b/include/linux/pci.h index add9368e6314..95276f44b23b 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -902,6 +902,10 @@ struct module; * (negative number) otherwise. * The probe function always gets called from process * context, so it can sleep. + * @can_remove: The can_remove() function gets called during driver + * deregistration to determine if remove() can be called. + * The probe function always gets called from process + * context, so it can sleep. * @remove: The remove() function gets called whenever a device * being handled by this driver is removed (either during * deregistration of the driver or when it's manually @@ -943,6 +947,7 @@ struct pci_driver { const char *name; const struct pci_device_id *id_table; /* Must be non-NULL for probe to be called */ int (*probe)(struct pci_dev *dev, const struct pci_device_id *id); /* New device inserted */ + bool (*can_remove)(struct pci_dev *dev); void (*remove)(struct pci_dev *dev); /* Device removed (NULL if not a hot-plug capable driver) */ int (*suspend)(struct pci_dev *dev, pm_message_t state); /* Device suspended */ int (*resume)(struct pci_dev *dev); /* Device woken up */ From patchwork Fri Feb 2 22:25:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hamza Mahfooz X-Patchwork-Id: 13543520 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 3E381C48291 for ; Fri, 2 Feb 2024 22:26:43 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 58B2A10ED17; Fri, 2 Feb 2024 22:26:36 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=amd.com header.i=@amd.com header.b="5RSiXt1j"; dkim-atps=neutral Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2067.outbound.protection.outlook.com [40.107.237.67]) by gabe.freedesktop.org (Postfix) with ESMTPS id A872E10EC49; Fri, 2 Feb 2024 22:26:34 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QYXEmYKe5LVN9FA4p8K0aR76WCackaQ70W5XGsmJPfdsHDuo0VwRibEWqste+5xLm62tYkoPHWQR2/QiSHhp3cF7d8XBtDa9ca0AzI8Q5sE1AnIQg+ZLS7p7co41b1r84z9LzA7eT3/urTi17hjiU8hXJOXVWEyJOjApfI3YRFj3banbr/fL9pfEW+wX+kIw0r/zmkC+/yuQSlsDdQ0swM4p8S+CctOnn1FwffGNpw+iUNzMTAv3aZnfN5vi6OANwG++DV0EH2GYcOT77dgPpTCdgBukSuOBQiliF78Rpy9SyuHYEAcNNItRG1DaVYH/r4XKB/Ju2XccSARycsc7NA== 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=ij3AysBjE+DDkvHgzRb/qiJ8bpUenktgHD0X9hR9KFA=; b=CmlG7QbXC+4o+tb4nDJHaCFrwiHyrdT0KjpFQEC3MQh5Z2XPiuGd2jSsdKknvA3qNwSmPM6/aiC9fBabiBqeK+IH4DmVBaKfm//x8qLPZnJmDrZf6HIHBTav+2EqzeEyx2JAmDRLExVj5wq4AaDSoAMGeRUNf1XrM187C6pPIydTimKY9gu48h81qM7ySru7tGCwG0jjmGXp6/suqa4sLJUaL+Re/EuWVZGhPhQcgpCNTZ2OSvMLCXWY2VKH0/mrzYRe7typUpYNCJYH1fwSNGB5exV1DeL3yzQGA0KOlVofQysdDPzOFLkbD/0r0jdpZ2hQH3mWli8c6mmJg81jjA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.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=ij3AysBjE+DDkvHgzRb/qiJ8bpUenktgHD0X9hR9KFA=; b=5RSiXt1j0Azvhs7sanaBUcEXtj4S22hBlFhe/eE9O30AGU/qaix9l8tS8/ghdqyMAmA2IkQUrjEXLK1Yn7tZAfFhngtMk4UPezVNEI4J7OGky3RAcYcFc+Z1hhnTX3db0Yhtcz9h2Qeeutaf1IEvR5LJw0B64lYCKrQakC5sRHY= Received: from CY5P221CA0013.NAMP221.PROD.OUTLOOK.COM (2603:10b6:930:b::29) by PH7PR12MB5928.namprd12.prod.outlook.com (2603:10b6:510:1db::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7270.9; Fri, 2 Feb 2024 22:26:30 +0000 Received: from CY4PEPF0000EE30.namprd05.prod.outlook.com (2603:10b6:930:b:cafe::b) by CY5P221CA0013.outlook.office365.com (2603:10b6:930:b::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.29 via Frontend Transport; Fri, 2 Feb 2024 22:26:30 +0000 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 Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EE30.mail.protection.outlook.com (10.167.242.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7249.19 via Frontend Transport; Fri, 2 Feb 2024 22:26:30 +0000 Received: from hamza-pc.localhost (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.34; Fri, 2 Feb 2024 16:26:28 -0600 From: Hamza Mahfooz To: CC: Hamza Mahfooz , , "Greg Kroah-Hartman" , "Rafael J. Wysocki" , Alex Deucher , =?utf-8?q?Christian_K=C3=B6nig?= , "Pan, Xinhui" , David Airlie , Daniel Vetter , Bjorn Helgaas , Mario Limonciello , Lijo Lazar , "Srinivasan Shanmugam" , Le Ma , =?utf-8?q?Andr=C3=A9_Almeida?= , James Zhu , Aurabindo Pillai , Alex Shi , Jerry Snitselaar , Wei Liu , Robin Murphy , , , Subject: [PATCH 3/3] drm/amdgpu: wire up the can_remove() callback Date: Fri, 2 Feb 2024 17:25:56 -0500 Message-ID: <20240202222603.141240-3-hamza.mahfooz@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240202222603.141240-1-hamza.mahfooz@amd.com> References: <20240202222603.141240-1-hamza.mahfooz@amd.com> MIME-Version: 1.0 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: CY4PEPF0000EE30:EE_|PH7PR12MB5928:EE_ X-MS-Office365-Filtering-Correlation-Id: a657c881-da50-4bc1-ec1b-08dc243e0120 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: P8TEXwgsOxpYiAy9jkAO7j9nHkd4LOqYdZoJDMc29Nn2NXwbUE5B9h4P0FXYhfPCxgXvrUbbi9G0AqSpQ6UvcnyMGvCZl2UYa2SsJado53zEGUE9FaIi/4nm21fk3oFOa1odWU39LRqjZglZoM3jm4UIZQ/F88ZJDZnfdUu2n+XdWYi9tSltZ9ue6xKlSsL0xX+gAXtDqF8juOUou8XdyTTEE0YqdljxwPKVrPkp1WKLUg2BDMITWHACZLhDjRxgNNWyaW0svDwDhH7BhVMPHWKvwVHbpnyZ63t0Dj09hJ9kr9nYwl7/Akns3ahhq3JPkE4ub7H6ZSK2PmO58z2vhxALKAYB3+XMLb/x9537+gl5c802ws2jBN46I4ALOjXQB/XR56uj5XCp5lzRzvj0GEzl4uTDmFUogGBZ6WAmNRZSNdkFJf2C2AsbkgnnzkIR8tK0+XLQttI/vOYySEciKeNqWl2skSpVZH90QoIpjOAg7sJ8ZC9uwrZSHlBm1xuJEsvJ9d//Z5X9WzdjJ1Ib+ROhdGNlCw4MfCfBIiCn+b6gHvOue1lugHHSihWd5X3d4UI8CjvO45oniBaca4sJVNRSK4smSoeOoOAxQW8RaX/00fNbJuFRkw3EePdiFpowcd738LlyWbGe1hbjB1kuxf8da+deKvSZMLA7DbGHygEQGYkEDKucQWYNSCmisfbM5o/GXlrQp7W2e8JZg0JGnJXc1Ix0B9VfKtYqSyxo662cjiyURfpVGJq7As2GNOHYAOZGOFzLTYf+gDOz+s4+QL5ogAx1+fEo7DCTk9EBYnMavDZwWrCnF9hX1YRCEqcB 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)(4636009)(136003)(376002)(346002)(39860400002)(396003)(230922051799003)(186009)(82310400011)(451199024)(64100799003)(1800799012)(40470700004)(46966006)(36840700001)(41300700001)(36756003)(44832011)(82740400003)(70586007)(4326008)(8676002)(70206006)(8936002)(7416002)(2906002)(86362001)(5660300002)(316002)(54906003)(6916009)(36860700001)(356005)(81166007)(6666004)(478600001)(83380400001)(47076005)(336012)(426003)(16526019)(2616005)(26005)(40460700003)(1076003)(40480700001)(36900700001)(16060500005); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Feb 2024 22:26:30.4181 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a657c881-da50-4bc1-ec1b-08dc243e0120 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: CY4PEPF0000EE30.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB5928 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Removing an amdgpu device that still has user space references allocated to it causes undefined behaviour. So, implement amdgpu_pci_can_remove() and disallow devices that still have files allocated to them from being unbound. Cc: stable@vger.kernel.org Signed-off-by: Hamza Mahfooz --- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c index cc69005f5b46..cfa64f3c5be5 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c @@ -2323,6 +2323,22 @@ static int amdgpu_pci_probe(struct pci_dev *pdev, return ret; } +static bool amdgpu_pci_can_remove(struct pci_dev *pdev) +{ + struct drm_device *dev = pci_get_drvdata(pdev); + + mutex_lock(&dev->filelist_mutex); + + if (!list_empty(&dev->filelist)) { + mutex_unlock(&dev->filelist_mutex); + return false; + } + + mutex_unlock(&dev->filelist_mutex); + + return true; +} + static void amdgpu_pci_remove(struct pci_dev *pdev) { @@ -2929,6 +2945,7 @@ static struct pci_driver amdgpu_kms_pci_driver = { .name = DRIVER_NAME, .id_table = pciidlist, .probe = amdgpu_pci_probe, + .can_remove = amdgpu_pci_can_remove, .remove = amdgpu_pci_remove, .shutdown = amdgpu_pci_shutdown, .driver.pm = &amdgpu_pm_ops,