Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp3944447ybi; Tue, 18 Jun 2019 09:01:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqyS+xNPAoEDjovQbKDkdCXsquYX7Gl3Lcr9cFw9SdLcH/lthV6WEGiiH0QDrfIJurXHE4D4 X-Received: by 2002:a62:3741:: with SMTP id e62mr122133321pfa.213.1560873685428; Tue, 18 Jun 2019 09:01:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560873685; cv=none; d=google.com; s=arc-20160816; b=NmM8aEaq881LfXuelWV/Pko2jQiFmsUPJeamXs4Md7+N4RmzjPScb5ziQckChu3ePG h+x6/QEafSEbxBI//OXz9lRuFLqypeQB+yIiOhOcA5XPrWkgyZqypL9m2Wl3BNqARDOE MjN3UUingO34AhXoPgVkIN4tZ1Tselyjvf/G1URZqw0ZQVKBZhun+AiVb2fShnQWQ4xg djriMqKENduzS8PvWscFdrY2/RW4gMMoprxNBnSa/EqIw/2/yFtb/jG9YGB5NqfTSpS/ xUVRX8c/h/RJtj/h9sYaJf3bdklwReMVTn2hmsl0eK2+vU460WkQhORH6R26GmE+sCwI XaMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:in-reply-to :subject:cc:to:from:date; bh=568OHpQlCpn/pDBKigP5HcUDDY8+kvjykC4X++kVLfM=; b=06pBonogEN3sQuN5F9aBFPNDiU7oRzgF98ZXoNi7e4IjhaxbC0GodVLo3vH5lgk9QE /jlopyV38iYEMLxR28bENphEtlEd2lLCh2t0Ztz28Bxu7We1cE0ss4+ndxONajcX5rFZ hlEFpCWia5n2VOPkxv+5xJPT4OvVfeNWUlZnLOH3B202swDqqyGRD6dHB+Bmrrc0aFZb /YyNVxI6lEQjWaJfq10HvJ79XiGwFZI7PTMX5yJTuU710fdvpyloQHjJ2y0ZtIz3VlY1 3hIHIartwNSCX4L1hoHn3mHfJL3MSVjlOLJ7AVzX2cCl3VREFfrDjN5B6XU/LTWlyXkY 09Zg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h21si454655pgv.102.2019.06.18.09.01.08; Tue, 18 Jun 2019 09:01:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729738AbfFRP7k (ORCPT + 99 others); Tue, 18 Jun 2019 11:59:40 -0400 Received: from iolanthe.rowland.org ([192.131.102.54]:40246 "HELO iolanthe.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1729472AbfFRP7k (ORCPT ); Tue, 18 Jun 2019 11:59:40 -0400 Received: (qmail 5919 invoked by uid 2102); 18 Jun 2019 11:59:39 -0400 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 18 Jun 2019 11:59:39 -0400 Date: Tue, 18 Jun 2019 11:59:39 -0400 (EDT) From: Alan Stern X-X-Sender: stern@iolanthe.rowland.org To: Oliver Neukum , Tejun Heo cc: USB list , Kernel development list Subject: Re: [RFC] deadlock with flush_work() in UAS In-Reply-To: <1560871774.3184.16.camel@suse.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Tejun and other workqueue maintainers: On Tue, 18 Jun 2019, Oliver Neukum wrote: > Am Dienstag, den 18.06.2019, 11:29 -0400 schrieb Alan Stern: > > On Tue, 18 Jun 2019, Oliver Neukum wrote: > > > > > Hi, > > > > > > looking at those deadlocks it looks to me like UAS can > > > deadlock on itself. What do you think? > > > > > > Regards > > > Oliver > > > > > > From 2d497f662e6c03fe9e0a75e05b64d52514e890b3 Mon Sep 17 00:00:00 2001 > > > From: Oliver Neukum > > > Date: Tue, 18 Jun 2019 15:03:56 +0200 > > > Subject: [PATCH] UAS: fix deadlock in error handling and PM flushing work > > > > > > A SCSI error handler and block runtime PM must not allocate > > > memory with GFP_KERNEL. Furthermore they must not wait for > > > tasks allocating memory with GFP_KERNEL. > > > That means that they cannot share a workqueue with arbitrary tasks. > > > > > > Fix this for UAS using a private workqueue. > > > > I'm not so sure that one long-running task in a workqueue will block > > other tasks. Workqueues have variable numbers of threads, added and > > removed on demand. (On the other hand, when new threads need to be > > added the workqueue manager probably uses GFP_KERNEL.) > > Do we have a guarantee it will reschedule already scheduled works? > The deadlock would be something like > > uas_pre_reset() -> uas_wait_for_pending_cmnds() -> > flush_work(&devinfo->work) -> kmalloc() -> DEADLOCK > > You can also make this chain with uas_suspend() > > > Even if you disagree, perhaps we should have a global workqueue with a > > permanently set noio flag. It could be shared among multiple drivers > > such as uas and the hub driver for purposes like this. (In fact, the > > hub driver already has its own dedicated workqueue.) > > That is a good idea. But does UAS need WQ_MEM_RECLAIM? These are good questions, and I don't have the answers. Perhaps Tejun or someone else on LKML can help. Alan Stern