From patchwork Fri Dec 7 16:01:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 10718469 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 689DC1731 for ; Fri, 7 Dec 2018 16:01:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 581E62E9E0 for ; Fri, 7 Dec 2018 16:01:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 562582EE53; Fri, 7 Dec 2018 16:01:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D09202E9E0 for ; Fri, 7 Dec 2018 16:01:36 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A6FC46E7D8; Fri, 7 Dec 2018 16:01:35 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-ed1-x544.google.com (mail-ed1-x544.google.com [IPv6:2a00:1450:4864:20::544]) by gabe.freedesktop.org (Postfix) with ESMTPS id 32DA06E7D8 for ; Fri, 7 Dec 2018 16:01:34 +0000 (UTC) Received: by mail-ed1-x544.google.com with SMTP id f23so4117840edb.3 for ; Fri, 07 Dec 2018 08:01:34 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=n+QY8iC9lcVjfn9oZrJVG4ukFImWaVNIt/fPyWhkA/Y=; b=J/xZkhbFATRRg4Tg0ekhS9Gs3a3zksc4btlR2LDxnELWDxdWubIQyssFKE7udansFa srSPsAZx8JsN6TaQxh0GNEXx4hzWOwfRM1gwlGfSaKJ0hwrve09AqIQ6QMcjGWMkaFxk 3WgLXl88d8Ovo5zouWbv4xIFK5DxsHtcs6lJLu7c52FEaJ7K15TyNmPSpTbK7DMjDNXo uRUgavwHZqdN9u9B1iNUpCs8CkQusd21FDoAcVmpdsh4ne07Kzu91fzy980hfwAWKXfu zCGTHQSZrGQdFdQflAzNF9lYDotQyAUHba5dd/h2mL3m5V9blVlSfl0Z0T8Wy0PmmsiU 9Z6w== X-Gm-Message-State: AA+aEWYykyF1r1Q0uWdC918i+O+zVrbAGwdhkkQ5L+Wb99065yrySF8q A0ozqR2Eva2tgMBcE04L84KyY7ZeYzk= X-Google-Smtp-Source: AFSGD/UUJVjNiiMXzxS1ggySZaOhuChs82sQUu9BSJhJidGEoUx/dpK9/n5PYZRx02WmPbnplOD63Q== X-Received: by 2002:a50:afa3:: with SMTP id h32mr2671834edd.150.1544198492446; Fri, 07 Dec 2018 08:01:32 -0800 (PST) Received: from phenom.ffwll.local ([2a02:168:569e:0:3106:d637:d723:e855]) by smtp.gmail.com with ESMTPSA id by5-v6sm603869ejb.7.2018.12.07.08.01.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Dec 2018 08:01:31 -0800 (PST) From: Daniel Vetter To: Intel Graphics Development Date: Fri, 7 Dec 2018 17:01:26 +0100 Message-Id: <20181207160126.22898-1-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.20.0.rc1 In-Reply-To: <20181207093133.15648-1-daniel.vetter@ffwll.ch> References: <20181207093133.15648-1-daniel.vetter@ffwll.ch> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH] drivers/base: use a worker for sysfs unbind X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel Vetter , Daniel Vetter Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP Drivers might want to remove some sysfs files, which needs the same locks and ends up angering lockdep. Relevant snippet of the stack trace: kernfs_remove_by_name_ns+0x3b/0x80 bus_remove_driver+0x92/0xa0 acpi_video_unregister+0x24/0x40 i915_driver_unload+0x42/0x130 [i915] i915_pci_remove+0x19/0x30 [i915] pci_device_remove+0x36/0xb0 device_release_driver_internal+0x185/0x250 unbind_store+0xaf/0x180 kernfs_fop_write+0x104/0x190 I've stumbled over this because some new patches by Ram connect the snd-hda-intel unload (where we do use sysfs unbind) with the locking chains in the i915 unload code (but without creating a new loop), which upset our CI. But the bug is already there and can be easily reproduced by unbind i915 directly. No idea whether this is the correct place to fix this, should at least get CI happy again. Note that the bus locking is already done by device_release_driver -> device_release_driver_internal, so I dropped that part. Also note that we don't recheck that the device is still bound by the same driver, but neither does the current code do that without races. And I figured that's a obscure enough corner case to not bother. Cc: Ramalingam C Signed-off-by: Daniel Vetter --- drivers/base/bus.c | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 8bfd27ec73d6..2cc18545918a 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -174,22 +174,45 @@ static const struct kset_uevent_ops bus_uevent_ops = { static struct kset *bus_kset; +struct unbind_work { + struct work_struct work; + struct device *dev; +}; + +void unbind_work_fn(struct work_struct *work) +{ + struct unbind_work *unbind_work = + container_of(work, struct unbind_work, work); + + device_release_driver_internal(unbind_work->dev, NULL, + unbind_work->dev->parent); + put_device(unbind_work->dev); + kfree(unbind_work); +} + /* Manually detach a device from its associated driver. */ static ssize_t unbind_store(struct device_driver *drv, const char *buf, size_t count) { struct bus_type *bus = bus_get(drv->bus); + struct unbind_work *unbind_work; struct device *dev; int err = -ENODEV; dev = bus_find_device_by_name(bus, NULL, buf); if (dev && dev->driver == drv) { - if (dev->parent && dev->bus->need_parent_lock) - device_lock(dev->parent); - device_release_driver(dev); - if (dev->parent && dev->bus->need_parent_lock) - device_unlock(dev->parent); - err = count; + unbind_work = kmalloc(sizeof(*unbind_work), GFP_KERNEL); + if (unbind_work) { + unbind_work->dev = dev; + get_device(dev); + INIT_WORK(&unbind_work->work, unbind_work_fn); + + schedule_work(&unbind_work->work); + + err = count; + } else { + err = -ENOMEM; + } } put_device(dev); bus_put(bus);