Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1423584imu; Tue, 11 Dec 2018 20:08:43 -0800 (PST) X-Google-Smtp-Source: AFSGD/XRCrOjuNpmXztO20Bd5j6ECGfB/1dwYWyKOoXfqmfs4CiHcjhJ7PrJLyR/ggUECMUs+d4a X-Received: by 2002:a63:504d:: with SMTP id q13mr17269165pgl.319.1544587723564; Tue, 11 Dec 2018 20:08:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544587723; cv=none; d=google.com; s=arc-20160816; b=Ofg6fsL3EP17HYn9MqNsqcEdfBIlRq1IPC7NuNpyHNK803/691lBeYbCCMwiIWoWfB CKJmTv20+5MnlKpx2+GREHe5FGPKDip6hYwl50xARE7W3eEfpe2j85gJIqMQ1Mr0yqzv N+oICHDjLnA1jmtk+ZvELXFxaoaPuyTaLOjgvXEJPwM/FRINW8rcijlufbqVjcxifn8g FMN4ebhc9Pnaq025qnCa/7s/80rm/KqVq+ZGc/HC8DPDI+t1XW/OMWQMAvVQ+3WHcxub fqzyEwQFJph2Hs+kIkOnHjHVBGFcDbk+eypesqWPnVqiLSadgnyN0Gup6d4vK2UAbZ9P GXZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=fFhZ3CklTcCwufhpP2IZWbh+thBFUwMG/ZFw2lmBUJE=; b=qkCcHFrTLmoIJ+8BrT9vckNlK0iq/+WTYxUTQUpGe6kQwkHlk6MjHWIppMh9JUSggt Rc5JYFDH/CbL2VeUqSvqpwGcizRFF8UutFVePquxES6IubZrMiS7SI/hyQfn0Sd2/Vay YuNxKeIzYyV3k1HFg4qiJTYcXUf57t6e00N/8SqydK5r4wA6j3DAzyjmoVPhwq+Qr0q3 1blalkhRIL1YQi1ICm5canyoMV+W+j0RuTU36wppIDE2qTRVcrQGsVsdklUKLQfwSvzI 9IrIfkhy3x+rrKmzWAuKcANmvYULIbpsEIkXydE2Ijd3UkugEthdszBs/Gso8RiV9IRN NsHg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ba9si13818951plb.109.2018.12.11.20.08.13; Tue, 11 Dec 2018 20:08:43 -0800 (PST) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726298AbeLLEGu (ORCPT + 99 others); Tue, 11 Dec 2018 23:06:50 -0500 Received: from mail-qk1-f193.google.com ([209.85.222.193]:35482 "EHLO mail-qk1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726218AbeLLEGt (ORCPT ); Tue, 11 Dec 2018 23:06:49 -0500 Received: by mail-qk1-f193.google.com with SMTP id w204so10020862qka.2; Tue, 11 Dec 2018 20:06:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=fFhZ3CklTcCwufhpP2IZWbh+thBFUwMG/ZFw2lmBUJE=; b=ahvfWM6VsgQ9tViyKzEiKcdEZR5wGyzmUODhmbaeUOwz/CczVXfkl5EQ6gM8OQ4/Wa 0ckIaI/+YpJCFPb68bOLDWgm9pYpcz3fhSY2/Vssz9u5mvAPWfh/wkOocU1yT81TVrrh ccNY4Z00OTdxvD8AO8i+V9az2+e9Kl6yuz1XqVOsdIsAeMp0BJJRY852pkyzJ/+09FkI +Gh192zgpBG68ybbYonmnf274Rn9uBtT5XfQrvpZlRvpNKLZeY/U/Remr4xleI1AG10B 2wS5TQHmKgoLUaTLnLU3AogV6eyaq9TexmAofpKR8i04D+HWx8iabuqE4FirI/O7C126 V2IQ== X-Gm-Message-State: AA+aEWb4E1QY1Q1oNG+YCv0N5jNtmELe5dQacVLTASvC5kAQ0tMFAqFy kMa4ORqyp2SQP2Ub5G/sQ6aCz4Oy3rw= X-Received: by 2002:a37:8781:: with SMTP id j123mr16575830qkd.68.1544587608303; Tue, 11 Dec 2018 20:06:48 -0800 (PST) Received: from dennisz-mbp.dhcp.thefacebook.com ([2620:10d:c091:180::1:cdcb]) by smtp.gmail.com with ESMTPSA id b20sm11690712qkb.17.2018.12.11.20.06.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Dec 2018 20:06:47 -0800 (PST) Date: Tue, 11 Dec 2018 23:06:43 -0500 From: Dennis Zhou To: Bart Van Assche Cc: Jens Axboe , Tejun Heo , Josef Bacik , kernel-team@fb.com, linux-block@vger.kernel.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Ming Lei Subject: Re: [PATCH] blkcg: handle dying request_queue when associating a blkg Message-ID: <20181212040643.GA73727@dennisz-mbp.dhcp.thefacebook.com> References: <20181211230308.66276-1-dennis@kernel.org> <1544570173.185366.397.camel@acm.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1544570173.185366.397.camel@acm.org> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Bart, On Tue, Dec 11, 2018 at 03:16:13PM -0800, Bart Van Assche wrote: > On Tue, 2018-12-11 at 18:03 -0500, Dennis Zhou wrote: > > diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c > > index 6bd0619a7d6e..c30661ddc873 100644 > > --- a/block/blk-cgroup.c > > +++ b/block/blk-cgroup.c > > @@ -202,6 +202,12 @@ static struct blkcg_gq *blkg_create(struct blkcg *blkcg, > > WARN_ON_ONCE(!rcu_read_lock_held()); > > lockdep_assert_held(&q->queue_lock); > > > > + /* request_queue is dying, do not create/recreate a blkg */ > > + if (blk_queue_dying(q)) { > > + ret = -ENODEV; > > + goto err_free_blkg; > > + } > > + > > /* blkg holds a reference to blkcg */ > > if (!css_tryget_online(&blkcg->css)) { > > ret = -ENODEV; > > What prevents that the queue state changes after blk_queue_dying() has returned > and before blkg_create() returns? Are you sure you don't need to protect this > code with a blk_queue_enter() / blk_queue_exit() pair? > Hmmm. So I think the idea is that we rely on normal shutdown as I don't think there is anything wrong with creating a blkg on a dying request_queue. When we are doing association, the request_queue should be pinned by the open call. What we are racing against is when the request_queue is shutting down, it goes around and destroys the blkgs. For clarity, QUEUE_FLAG_DYING is set in blk_cleanup_queue() before calling blk_exit_queue() which eventually calls blkcg_exit_queue(). The use of blk_queue_dying() is to determine whether blkg shutdown has already started as if we create one after it has started, we may incorrectly orphan a blkg and leak it. Both blkg creation and destruction require holding the queue_lock, so if the QUEUE_FLAG_DYING flag is set after we've checked it, it means blkg destruction hasn't started because it has to wait on the queue_lock. If QUEUE_FLAG_DYING is set, then we have no guarantee of knowing what phase blkg destruction is in leading to a potential leak. Thanks, Dennis