Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp2270624rdb; Mon, 5 Feb 2024 00:48:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IF6ZnnwzjA0xFSHj63Q+qrsVPhCZ8jrW6zqqgUJy6RzgQqM3EogKmV1eooTAx96yvb9GA00 X-Received: by 2002:a05:620a:3db:b0:783:c7c1:3814 with SMTP id r27-20020a05620a03db00b00783c7c13814mr10297511qkm.26.1707122937936; Mon, 05 Feb 2024 00:48:57 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707122937; cv=pass; d=google.com; s=arc-20160816; b=R5xHXPu9dbYbfd2J7Ri76lQE/25ywnw8Kl/weVpH2+pgmZz5rtFIu0XVmMV4ztMk6s aVtwhfkHxuyBau5hZUNI4lWF8SGQUQ+WhVjEDe/MNKKuxw1ceWfLFRGpV0meSI0qbNH3 23dMnVNwK2syv+Pr7g6gyVkLyN8OQXjDc4UYPg2BQh/GTV8AnckZpMkJ7w8Vym55z9nW acLQ73/Js1k6B0fIFR2wM+QxKe0M2DnPEtmelzLPk2Mwq5EXaER8KPEyWvQQb1mBWkUt Vpr/dPkAnhd+RDhoG4We+MO7OYKIA9slq/jro/s6y5j6OCojEHLCzdjXL2gsc8aS2kNv 91Ng== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=2ydA0TsnU465lLz9wxK97OfQIetnhQ94qrcei325RlU=; fh=DcytTno6xtz0oGe/L5mbzS+U0VlhEWEvt48hP3wBVfk=; b=y9j+R7nQqIvdevAJPUmYpsnezrqNC3YMbN2I58mjOB0k3XC24AxT9ZlVxVKkG17vP/ RxsmRqCOjRPgWZO91VjQcMc8gjomE+xUMeMwD4E7FnwurxOJWXsZx+qt75Xqajs3MKRS Bg+IzQ/zumG9wwyYPQ+hTB4VpkeCOqWp+OtHnQhB3+7U/G4FbTThp5bNc02592uXA+w6 AB6BZuR7EoiNVnmvm7h77NHs9BNOZXoDnjvBj/gY1v03ahUA/jC06iqTnpchj3rdYiBo RQMFvC4Tx8xECkcG/B4UjCCMSSAkisqP5eWvsWIjbqy5Wo0EBJCXRVH3RH4m2qAx+dTR xMJg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ggTFkGeg; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-52224-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-52224-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com X-Forwarded-Encrypted: i=1; AJvYcCVVnWcbd86Nn8GavfjhhSqO3Szukhf08F2P2tz19ERL9m1Slij+J+mds7eJzwBys42SZPF/r7/bfqjTp13JELBHySLODGXoq5x7hkC0aQ== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id h8-20020a05620a244800b00783f634199asi8726188qkn.746.2024.02.05.00.48.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 00:48:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-52224-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ggTFkGeg; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-52224-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-52224-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id A05791C23153 for ; Mon, 5 Feb 2024 08:48:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 94D1B11CB9; Mon, 5 Feb 2024 08:48:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ggTFkGeg" Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E82F011701; Mon, 5 Feb 2024 08:48:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707122927; cv=none; b=pvyvCZImpZH/Lw9JFxpkESyB4nj+7zHnknMKoS0QCwvFtJ7IpnOBtO5SQJ0FJ01d6YqYyfClO3UTmjB317GVqhciNn8mwdbPNgun8K+vR0VkOrXxykqFIVE1tAot6LfuUo4rTP5LAPU8enZvgcMjLptFHNjXJGsPqNDqHApCW5s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707122927; c=relaxed/simple; bh=jN9HsR6pkHBGGNfaNQqz0Qo2mPCuk2AwkMIowfmzCxg=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=RYXF9lSV7nH1gy8H/cuwc/8z6EsldzJsfUIOBmgQTM9cTNJ7LbfHj9gVzb8TgdEwe2zQluoCTs0uKZbNtmttCdaohDDeMOpq+gas8vy5FRmZvOAxe4u+0AG7XSeS+DaUjAUdw41AZF4QFdZdc3pxcXMRmB7SEHiV0rxKGXGf8OM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ggTFkGeg; arc=none smtp.client-ip=209.85.167.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-5113303e664so4167293e87.0; Mon, 05 Feb 2024 00:48:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707122924; x=1707727724; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=2ydA0TsnU465lLz9wxK97OfQIetnhQ94qrcei325RlU=; b=ggTFkGegNisLCfNo9cF5nHEbdqZAqURqxYPxhbeX1FSU31qrmjK1CzFlxuocuHSbQk oYuLOM+tW0b7PChZBwI8ULGxpvESSZ+kP1CVTijbGYKzN+TMIOfUkFweR2lIlD//srQR vJ+NhTCVH5ETLwuSmFsy6bDRyutJ6y41SXz7cc7XhVraXu9pV5aN5pQqhMYqkANq7Cx4 SKuMPa+l4ThEQxFbQANjMsdfg1xvfPb31H5b6rVOov/WK8mswJO9hsdOaYuq8pKJvw/k 7ItVc0M6O8P1Q0dOsea7dgLypEnxe/KAMDKTjFgCYFdIZhx+YfMkH3MrdfO0nuUt4giL nwag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707122924; x=1707727724; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=2ydA0TsnU465lLz9wxK97OfQIetnhQ94qrcei325RlU=; b=K2oFqM2ft2CWKZ5yq1A/emmwTnzvxtpnsJMfgWUsjLn+OtSbGWYZGPCm5xFbRoD7G8 1E0S9OxTdfFhu6WnDpBP3pUtuDfsB+mDMzQ44esqn0X3sckXyGdEqZuGZzqdx42iRh8Y QQeQEKSC+9w9Pkb5aT/Oc2pVMiqAXV+tvtHm5y942YPDYlf057+O69SWr29m0LM1Ee4b 4thi4uBtEhwzqHctnZJ4jDXNyIqqr0ifx82AR4Lv8mlwyofJi2d2b8PuD82e5Ri86XOV HeM+LfN5WTPNYsQXNcZcMPuUz8jA7jkEcyJ1xUVjTHnSLWigDGTarhHxjfwYBLhtxfRp cIfg== X-Gm-Message-State: AOJu0YxaYOLwJcr5JYA+ZZtBoUa9wpNsa6Tgk2535EfGHsIV2J1TXzsq oamRnervyd7cIEOsuyhtaZVYg57eDzliz0pnfw0GGJDIVsQ3MY9F X-Received: by 2002:a05:6512:31cb:b0:511:3a70:b954 with SMTP id j11-20020a05651231cb00b005113a70b954mr6520932lfe.18.1707122923640; Mon, 05 Feb 2024 00:48:43 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCXCoeSRFEtdkJcbTVUZ54U6K3KuWSeDkOfG2db1WYNHjJg/nRAjfbybs8KpLWSO1Pd6zr/YZ1svqmlZm3as6lC4UXHrL8TY5kWDNRXZcSECchOZt7VOzWEOSZwTxyfdBG5C7Olmv98tvr3AJSpdHITAI4o4A4z9GXYiyuWRN7poAITWXzkE3R6XPIZzZuzXD0GbAVB7ZvDKq8QGk3AJWHP4M8M/vTc9EQbuMiZZ/lbWB7idgBKgmJF2e9TbSZ/UYrwAPfhGUqWy0tPvhlBIXTLmZqXKxuoGfHZIJPBDpEp8Dte+UPe0/0cSTYPWBQswSUjTIr2o6duH2IRJ4ZQifAdzdHstuXQXoPuIEoNilHlJ+tACRHpFcMflp4iXhQYmITMGnspvl5B/crOIO1VlE1TDsjqzHjr26JaJJA87UhBR/oRT1OESDFQR3wsT+hrt572U9hyNVRRPJmfTDnyj07yhzV9tmHz26k0DxnAjbED3HFwVFZvc5Jz7oM6ml7r6csJrkara0EX0K+SpkKEDPk72N8lHRAam64iIulwa+3ApOaXISqm2IbqnMcHOnBtjUQSFe0VRfiDE/iC25pS6mWi+Tl436sPlbsRc/uDAqOcI1vXRFXjXLolBujD2yLQ1AETm27yRExX8o88gC9denL3Qi4GZ9K1lMq3PzMenHfEOVCr5QNP08F7af5epMZMFvTTQ3Ozi8p1fSQc++S64TL4KrhUvtnj2Q3uNCAMx6um8ytlvJZRqIh25Z97b Received: from [10.254.108.81] (munvpn.amd.com. [165.204.72.6]) by smtp.gmail.com with ESMTPSA id l30-20020a05600c1d1e00b0040e541ddcb1sm7877780wms.33.2024.02.05.00.48.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 05 Feb 2024 00:48:43 -0800 (PST) Message-ID: Date: Mon, 5 Feb 2024 09:48:39 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/3] driver core: bus: introduce can_remove() Content-Language: en-US To: Hamza Mahfooz , linux-kernel@vger.kernel.org Cc: stable@vger.kernel.org, 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 , amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-pci@vger.kernel.org References: <20240202222603.141240-1-hamza.mahfooz@amd.com> From: =?UTF-8?Q?Christian_K=C3=B6nig?= In-Reply-To: <20240202222603.141240-1-hamza.mahfooz@amd.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Am 02.02.24 um 23:25 schrieb Hamza Mahfooz: > 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. Well that is nonsense. When you physically remove a device (e.g. unplug it) then there is nothing in software you can do to prevent that. Regards, Christian. > > 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); >