From patchwork Sat Apr 7 10:21:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Moise <00moses.alexander00@gmail.com> X-Patchwork-Id: 10327789 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D20CB600CB for ; Sat, 7 Apr 2018 10:21:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C0825292BB for ; Sat, 7 Apr 2018 10:21:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B2CA0295FB; Sat, 7 Apr 2018 10:21:58 +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,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, FSL_HELO_FAKE, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 521E8292BB for ; Sat, 7 Apr 2018 10:21:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751351AbeDGKV5 (ORCPT ); Sat, 7 Apr 2018 06:21:57 -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-Google-Smtp-Source: AIpwx4+P0r/Cn1KleXEQV2mH7BVsVBmpi20l5lOuC24U4d7w9B5MWD7p+86yFyw9JPkMYN93KG49BQ== 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-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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,