Received: by 10.213.65.68 with SMTP id h4csp494849imn; Sat, 7 Apr 2018 03:26:07 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/dBatdEtZ0cnxgbJIT9Og0GWR00qiLtfrdT4kzjAPIguj/rEnWiTmMdIhottWZT1QB/sXG X-Received: by 2002:a17:902:724b:: with SMTP id c11-v6mr30245828pll.192.1523096767903; Sat, 07 Apr 2018 03:26:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523096767; cv=none; d=google.com; s=arc-20160816; b=DuTeWTpR9l6HGVxSiElkZCF4UHb4m+NwYAZmW5wnTJ4lFQ7BGRPK1uS7opNg70udqY ZQM09eaVlR6bxvrY/wC7WkP8e7j4omhkpe3LY3PN4Usij9D7U3OXobwepzq1AIVTXCKS kKOw81VxH0b8tdhWE8P7jH96QVS/AwxdCSoR+LNg784cg7H8GzPrrP92ClZJkMxNrj8o gupiCH0+bWsXsaxgM8I8iWPUcmZEjYBSbYGbVWW8YtO4sBIi65D08QCKzzT0KBXgiIbz RwR8q/MzKDeMktjD47omAPsebW/lrjP4nbWq6ZOmvEX/493UbX8dqkdEGZFC74ycKa4H gZYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:to:from:date:dkim-signature :arc-authentication-results; bh=YXtHPTQV0900LKoudhELokoLrfSgGbsfUiJQxPid3/8=; b=rXA91OThgHm3HqeOvKFrVjpDHLSMjbGpgFWOhcSIzyWQ3fpPhuojDoPUrjsSQ9fwfY lkmk1ZNezXAj8sSgyGNpxq5Gi/TVoMO5umrg4xe4WzKK4QhvGIqh0hDCdWF4MZ/f0FPr 071zWTvyELWxJnLoL/VDG6tI/KMIn5yiooIbjk7ux98iMnYbQvnK/TXRTeoZ8UqbPrhS Yw+dEFKFA9TBvQlCIrfwTFv6S+Es4cMrB5NChmFP95RSxyp2Q84vd8Gf1phbjUNI+aQt DDLCsyyyC/KndVb2t6DGeP26Tqw70orwVqhTUDNX23b3olFok8ayHAHVJMK1MT+Kpq7G yEfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=DR8NDkYh; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 34-v6si12105462plz.76.2018.04.07.03.25.31; Sat, 07 Apr 2018 03:26:07 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=DR8NDkYh; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751598AbeDGKV6 (ORCPT + 99 others); Sat, 7 Apr 2018 06:21:58 -0400 Received: from mail-wr0-f196.google.com ([209.85.128.196]:36283 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751181AbeDGKV4 (ORCPT ); Sat, 7 Apr 2018 06:21:56 -0400 Received: by mail-wr0-f196.google.com with SMTP id y55so3790492wry.3; Sat, 07 Apr 2018 03:21:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:subject:message-id:mime-version:content-disposition :user-agent; bh=YXtHPTQV0900LKoudhELokoLrfSgGbsfUiJQxPid3/8=; b=DR8NDkYh4gI1cEQwq65dVQ72EaDkV0c7nYbMZiVK4GGi/ZGiHsOWEqBLFdwB7jp/Di fWP8snPh+Qr6u/PuHY7i83KOfjbHJIvxW6/kBTZtpHco1kve7eOqsU2cqP6pclwNABHH 6T+26EpI4vRJ0sh65EMnkH7fBXwhrQ0JWXrxgHncYg3CGYmx3mMSP7yKD+JHKTmDaXcR u8jLq9xkmptkczVv1//y89pynu9dvBOgtVayQNgPRbTZmEuMxDag5e5JpBPuzTSOb25Q 1yn/XNtJl8gVpsh6aLfGFsWP8dO7+lMLDzhKfOE6fcTmkhz+S0wZHlMeiTPTb8tYKx5d /8jg== 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:subject:message-id:mime-version :content-disposition:user-agent; bh=YXtHPTQV0900LKoudhELokoLrfSgGbsfUiJQxPid3/8=; b=jJzRNcc3qisWZyj6rNbiHETc7TgBBTG2MyccFfEF458KaEOngCP/OHtfxPvYqXYtjz r/CuairBWNx6K/nriooHzm8sqEoHr9yayrNzdfS9l0aJ8KUe3YG8eQ217ztAwjpD7syR FLCBQNUroHnqMlfXqkNml7iQNwaWpR+x2QXNDtqRM+EJ9cni9sa9DWU4WP/m1Iq+Inoa SqAYvyqA1L5FlLm3ekUZ4M5ALLztec+Tttm5DDePgn2CI+iJSC6ArLZsUoBoxT41yMHg nVOrU5FQkCzrKXjohtjXif0r06aOxE1tg+DUNXK2CpPjlbNDV4oplNtsIa+TgfECorCd U8+g== X-Gm-Message-State: AElRT7EcevN/GGpvOkdDswJWmLxZMPffmq0oLfVsScB2a7jdbIIeyfVt 2lwYU4SKqQBGckJdnPpELLE= X-Received: by 10.223.160.182 with SMTP id m51mr23289335wrm.187.1523096515141; Sat, 07 Apr 2018 03:21:55 -0700 (PDT) Received: from gmail.com (51B6C0F5.dsl.pool.telekom.hu. [81.182.192.245]) by smtp.gmail.com with ESMTPSA id c15sm16567114wrc.64.2018.04.07.03.21.53 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 07 Apr 2018 03:21:54 -0700 (PDT) Date: Sat, 7 Apr 2018 12:21:48 +0200 From: Alexandru Moise <00moses.alexander00@gmail.com> To: axboe@kernel.dk, tj@kernel.org, shli@fb.com, nborisov@suse.com, arnd@arndb.de, gregkh@linuxfoundation.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] blk-cgroup: remove entries in blkg_tree before queue release Message-ID: <20180407102148.GA9729@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The q->id is used as an index within the blkg_tree radix tree. If the entry is not released before reclaiming the blk_queue_ida's id blkcg_init_queue() within a different driver from which this id was originally for can fail due to the entry at that index within the radix tree already existing. Signed-off-by: Alexandru Moise <00moses.alexander00@gmail.com> --- v2: Added no-op for !CONFIG_BLK_CGROUP block/blk-cgroup.c | 2 +- block/blk-sysfs.c | 4 ++++ include/linux/blk-cgroup.h | 3 +++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c index 1c16694ae145..224e937dbb59 100644 --- a/block/blk-cgroup.c +++ b/block/blk-cgroup.c @@ -369,7 +369,7 @@ static void blkg_destroy(struct blkcg_gq *blkg) * * Destroy all blkgs associated with @q. */ -static void blkg_destroy_all(struct request_queue *q) +void blkg_destroy_all(struct request_queue *q) { struct blkcg_gq *blkg, *n; diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c index d00d1b0ec109..a72866458f22 100644 --- a/block/blk-sysfs.c +++ b/block/blk-sysfs.c @@ -816,6 +816,10 @@ static void __blk_release_queue(struct work_struct *work) if (q->bio_split) bioset_free(q->bio_split); + spin_lock_irq(q->queue_lock); + blkg_destroy_all(q); + spin_unlock_irq(q->queue_lock); + ida_simple_remove(&blk_queue_ida, q->id); call_rcu(&q->rcu_head, blk_free_queue_rcu); } diff --git a/include/linux/blk-cgroup.h b/include/linux/blk-cgroup.h index 6c666fd7de3c..3d60b1d1973d 100644 --- a/include/linux/blk-cgroup.h +++ b/include/linux/blk-cgroup.h @@ -179,6 +179,8 @@ struct blkcg_gq *blkg_lookup_create(struct blkcg *blkcg, int blkcg_init_queue(struct request_queue *q); void blkcg_drain_queue(struct request_queue *q); void blkcg_exit_queue(struct request_queue *q); +void blkg_destroy_all(struct request_queue *q); + /* Blkio controller policy registration */ int blkcg_policy_register(struct blkcg_policy *pol); @@ -740,6 +742,7 @@ static inline struct blkcg_gq *blkg_lookup(struct blkcg *blkcg, void *key) { ret static inline int blkcg_init_queue(struct request_queue *q) { return 0; } static inline void blkcg_drain_queue(struct request_queue *q) { } static inline void blkcg_exit_queue(struct request_queue *q) { } +static inline void blkg_destroy_all(struct request_queue *q) { } static inline int blkcg_policy_register(struct blkcg_policy *pol) { return 0; } static inline void blkcg_policy_unregister(struct blkcg_policy *pol) { } static inline int blkcg_activate_policy(struct request_queue *q, -- 2.16.2