From patchwork Fri Apr 6 15:06:50 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: 10327027 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 34FD260541 for ; Fri, 6 Apr 2018 15:07:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 267332956F for ; Fri, 6 Apr 2018 15:07:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1AE0729569; Fri, 6 Apr 2018 15:07:15 +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=unavailable 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 BAA8F2955B for ; Fri, 6 Apr 2018 15:07:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755142AbeDFPHA (ORCPT ); Fri, 6 Apr 2018 11:07:00 -0400 Received: from mail-wr0-f195.google.com ([209.85.128.195]:36642 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754793AbeDFPG7 (ORCPT ); Fri, 6 Apr 2018 11:06:59 -0400 Received: by mail-wr0-f195.google.com with SMTP id y55so2090137wry.3; Fri, 06 Apr 2018 08:06:58 -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=j41Ybz+SujReRFFrtA2hus3batPBhCeTThVsguqDTO8=; b=WG2rFGZ1npFiEEiRBJ3lEKojLWvRD3JkQPd12ICh/dShZaChYUxEx1yGFPXokyc4+w 1IfgTsdQHNbiHjvR4ucZh8jOQvqjyPMYuqMg9KgNV2fHemrFtzReYIXpvpNJ7a4at3nC 7vJA485aV+W2bePkuHGyUDoiL7Kd37fdxBJVf73fjdMLR0L91IPcoUC7jy78WcWppvBY 8RGe7UbB6jQj3hMp626XYt/J8vYsvKKnV1lqRrXlYs1QD28DAaokxIkhqGKz8ehtLRvp rOA9P/GDgDXHXoBcUu+wW6V6HdM85pUTey2D+xeiEqb3lnO0Gnn9wKn/Aj4fauFF7m/b 0q7g== 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=j41Ybz+SujReRFFrtA2hus3batPBhCeTThVsguqDTO8=; b=atEyNVjMAZ9Lmj1lyoJf6jPMYYyIIXZUfhkaynAae8Ie6MkXgeY9OCyisk06pc+mGe 3tbjpfmiak4KsbNQFAbrRKVDMJaDO+jM53q03rs8FYfKZxs5HRbhiCcN1Ukqn819Aa4j xfGrzsuiJ+maoWSakCT6ijtLm9FT422QCUeWkxN8UAAiT28JQFvXh6ir/6j/nau5EUOQ Ts5fRRmOnD9e39vEepKJPTftgp39+q9B28g/d6DwYXtev2wOuBTwzsLFZDghF8zH/o64 smxX3V6znV974/3PEQCGcRRkMYPD44QV+y8SvBj4uKSMtfH3skyUwLaYufLrn61p+glq T0aQ== X-Gm-Message-State: AElRT7GhfrJsRUV21YmLgQ1SHSPrQnbVCdO7J4thS5V59ExljCOUeK3Z 0YQtPSUeGPc6tpQwDTGc0tQ= X-Google-Smtp-Source: AIpwx4/49ENuP/tYNGnvHSogUcuoqpzpnuhP5FxrQ/vulThpcy6BPFy2FOMGQSJbHpC8DTLqbHJKeQ== X-Received: by 10.223.129.199 with SMTP id 65mr19184885wra.159.1523027217653; Fri, 06 Apr 2018 08:06:57 -0700 (PDT) Received: from gmail.com (51B6C0F5.dsl.pool.telekom.hu. [81.182.192.245]) by smtp.gmail.com with ESMTPSA id t69sm19347581wrc.87.2018.04.06.08.06.56 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 06 Apr 2018 08:06:56 -0700 (PDT) Date: Fri, 6 Apr 2018 17:06:50 +0200 From: Alexandru Moise <00moses.alexander00@gmail.com> To: axboe@kernel.dk, tj@kernel.org, shli@fb.com, pombredanne@nexb.com, gregkh@linuxfoundation.org, joseph.qi@linux.alibaba.com, nborisov@suse.com, arnd@arndb.de, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] blk-cgroup: remove entries in blkg_tree before queue release Message-ID: <20180406150648.GA6378@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> --- block/blk-cgroup.c | 2 +- block/blk-sysfs.c | 4 ++++ include/linux/blk-cgroup.h | 2 ++ 3 files changed, 7 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..4470fdb6ea8f 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);