Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp592916ybz; Wed, 15 Apr 2020 14:44:42 -0700 (PDT) X-Google-Smtp-Source: APiQypKSJXvPLwr8FGl2Y3qzzYMx7bV/g8/WpgzAIRvKc7K9JilkS4TEY+nhWanzZ615T7Fi8+0X X-Received: by 2002:a50:fd0d:: with SMTP id i13mr27632792eds.263.1586987082469; Wed, 15 Apr 2020 14:44:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586987082; cv=none; d=google.com; s=arc-20160816; b=ypKfYjG621HG0xU8SmQGR1eBLFM99ZQygF/6DDhD4gEK+JGiavm+MGDdZhXULH4kDE Ay91mxZBxytyxvkSbpyDSwqIaC3SD2ba94z3y3aQGCCNL5SmcmzeAfJkVxwU/rS0DslY sTSQG3AvYv1rvkUCnkN6O0wS1mRtBGSwLs6Svq+07YEJErrStBkHdQX/Qa3Ancn+9el1 adH04brDrj3MXiLuBHB7IaBdu4RSEHRvF7rp1AovgAjob8ND0Ol+sIRuHhqdy48o6yCm prdmhvyY6RHBob4xBrdK6a/+BsQl0SYAnBS6F2AMxF36YR3tNND3TvMpQdf3ilDTVIgY KyiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=gaNCciS1ZGObUgDnpsOAZP6AUC2c3uZoCdo1HUWts4c=; b=HBvsD+vAmmsFuvzVr93k5z2aLGRCRn0u7XJw+R7me9jyyvappFHB2pxuzLUg0Mziq5 V8y4jTiy/kR4RusUoEjklemMHG8smnBMLPQupFO14Ge7Fzwam6YYF6CzVYnwV6IhD9mk M/6b9/SEkY/pIqPIV/WPATmjkoYToV/2Pmq4hOMJI3+SvYPb4yBC8r2sdeelS0gGEqfw 1p2+3X/Tv97aCLnQMC0mRk3o8XDoutQhPnKVJe1KjAhMMhsCVDOV4hGJ5SEpGxzZ7uhm yyv8IY+5WejvH823YFGZ86Qty/MXV7HIX/wSrZIVV4Mp9gB9/pJ0UOkE2w0BYyGYB+r7 7FDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=fhELgt4F; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c23si7497070edy.407.2020.04.15.14.44.18; Wed, 15 Apr 2020 14:44:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=fhELgt4F; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2440914AbgDNPrt (ORCPT + 99 others); Tue, 14 Apr 2020 11:47:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S2440880AbgDNPrm (ORCPT ); Tue, 14 Apr 2020 11:47:42 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5924FC061A0C; Tue, 14 Apr 2020 08:47:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=gaNCciS1ZGObUgDnpsOAZP6AUC2c3uZoCdo1HUWts4c=; b=fhELgt4Fu4afzRcTGwnL1xPM5P DL/fB9skhUKTXHo7L0rXtnJJ3BHW88ia7IF+Qcl0FZOY81VT9DNxnqrpJkxH5Zn9+fLnU+2OJbZ3H R1GUYoKpMBmph2Iy22aWAPC7cETZpt3NhLARKn5j6QDULr2xUWxaHn2ixo9oXWa4cx7Z3nGtLMWKb iajZ1Iy+5ej/MFbgpKLXS1Bvz6IzCw9dwyw/9QTRsDxL0JUR9USuCXtRHkiwKSFY4iSDnBif88s4c uKVFWfc+ytLkNvqfq1H2oCOv35cFP3OiiDCigYwXgTFSX4HHxz6bEOEHyOHhesC5zhvY2AY6CaKkN Hwlj4epw==; Received: from hch by bombadil.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1jONmX-0004QS-4h; Tue, 14 Apr 2020 15:47:25 +0000 Date: Tue, 14 Apr 2020 08:47:25 -0700 From: Christoph Hellwig To: Luis Chamberlain Cc: axboe@kernel.dk, viro@zeniv.linux.org.uk, bvanassche@acm.org, gregkh@linuxfoundation.org, rostedt@goodmis.org, mingo@redhat.com, jack@suse.cz, ming.lei@redhat.com, nstange@suse.de, akpm@linux-foundation.org, mhocko@suse.com, yukuai3@huawei.com, linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Omar Sandoval , Hannes Reinecke , Michal Hocko Subject: Re: [PATCH 5/5] block: revert back to synchronous request_queue removal Message-ID: <20200414154725.GD25765@infradead.org> References: <20200414041902.16769-1-mcgrof@kernel.org> <20200414041902.16769-6-mcgrof@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200414041902.16769-6-mcgrof@kernel.org> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 14, 2020 at 04:19:02AM +0000, Luis Chamberlain wrote: > Commit dc9edc44de6c ("block: Fix a blk_exit_rl() regression") merged on > v4.12 moved the work behind blk_release_queue() into a workqueue after a > splat floated around which indicated some work on blk_release_queue() > could sleep in blk_exit_rl(). This splat would be possible when a driver > called blk_put_queue() or blk_cleanup_queue() (which calls blk_put_queue() > as its final call) from an atomic context. > > blk_put_queue() decrements the refcount for the request_queue > kobject, and upon reaching 0 blk_release_queue() is called. Although > blk_exit_rl() is now removed through commit db6d9952356 ("block: remove > request_list code"), we reserve the right to be able to sleep within > blk_release_queue() context. If you see no other way and *have* be > in atomic context when you driver calls the last blk_put_queue() > you can always just increase your block device's reference count with > bdgrab() as this can be done in atomic context and the request_queue > removal would be left to upper layers later. We document this bit of > tribal knowledge as well now, and adjust kdoc format a bit. > > We revert back to synchronous request_queue removal because asynchronous > removal creates a regression with expected userspace interaction with > several drivers. An example is when removing the loopback driver and > issues ioctl from userspace to do so, upon return and if successful one > expects the device to be removed. Moving to asynchronous request_queue > removal could have broken many scripts which relied on the removal to > have been completed if there was no error. > > Using asynchronous request_queue removal however has helped us find > other bugs, in the future we can test what could break with this > arrangement by enabling CONFIG_DEBUG_KOBJECT_RELEASE. > > Cc: Bart Van Assche > Cc: Omar Sandoval > Cc: Hannes Reinecke > Cc: Nicolai Stange > Cc: Greg Kroah-Hartman > Cc: Michal Hocko > Cc: yu kuai > Suggested-by: Nicolai Stange > Fixes: dc9edc44de6c ("block: Fix a blk_exit_rl() regression") > Signed-off-by: Luis Chamberlain > --- > block/blk-core.c | 19 ++++++++++++++++++- > block/blk-sysfs.c | 38 +++++++++++++++++--------------------- > include/linux/blkdev.h | 2 -- > 3 files changed, 35 insertions(+), 24 deletions(-) > > diff --git a/block/blk-core.c b/block/blk-core.c > index 5aaae7a1b338..8346c7c59ee6 100644 > --- a/block/blk-core.c > +++ b/block/blk-core.c > @@ -301,6 +301,17 @@ void blk_clear_pm_only(struct request_queue *q) > } > EXPORT_SYMBOL_GPL(blk_clear_pm_only); > > +/** > + * blk_put_queue - decrement the request_queue refcount > + * > + * Decrements the refcount to the request_queue kobject, when this reaches > + * 0 we'll have blk_release_queue() called. You should avoid calling > + * this function in atomic context but if you really have to ensure you > + * first refcount the block device with bdgrab() / bdput() so that the > + * last decrement happens in blk_cleanup_queue(). > + * > + * @q: the request_queue structure to decrement the refcount for > + */ > void blk_put_queue(struct request_queue *q) > { > kobject_put(&q->kobj); > @@ -328,10 +339,16 @@ EXPORT_SYMBOL_GPL(blk_set_queue_dying); > > /** > * blk_cleanup_queue - shutdown a request queue > - * @q: request queue to shutdown > * > * Mark @q DYING, drain all pending requests, mark @q DEAD, destroy and > * put it. All future requests will be failed immediately with -ENODEV. > + * > + * You should not call this function in atomic context. If you need to > + * refcount a request_queue in atomic context, instead refcount the > + * block device with bdgrab() / bdput(). I think this needs a WARN_ON thrown in to enforece the calling context. > + * > + * @q: request queue to shutdown Moving the argument documentation seems against the usual kerneldoc style. Otherwise this look good, I hope it sticks :)