From patchwork Tue Dec 11 23:03:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dennis Zhou X-Patchwork-Id: 10725215 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8ECFF17FE for ; Tue, 11 Dec 2018 23:03:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7D8002B774 for ; Tue, 11 Dec 2018 23:03:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6EC7F2B771; Tue, 11 Dec 2018 23:03:23 +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=-7.9 required=2.0 tests=BAYES_00,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 DBB2C2B771 for ; Tue, 11 Dec 2018 23:03:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726209AbeLKXDR (ORCPT ); Tue, 11 Dec 2018 18:03:17 -0500 Received: from mail-qt1-f193.google.com ([209.85.160.193]:45721 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726158AbeLKXDQ (ORCPT ); Tue, 11 Dec 2018 18:03:16 -0500 Received: by mail-qt1-f193.google.com with SMTP id e5so18427009qtr.12; Tue, 11 Dec 2018 15:03:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=puxO2IKeuPOawx9ZdsIf28v5dik70E0wmP0rRCpd2u4=; b=sFFLNeKk0lznVawoo2awvgk6aGlfQ0JzSzxy+oNYgAZf36KFTRKWEJoT6d1aFXeNVB 2kEgPiSgMmjuMwow0uSbrnIYKBcq/C6sP2vm8BZHjByeejPfubTZMyJPfk56UNNwul9L v1fEYfPDnrNOerzvMMC/rkpLJ8mHS54d4WMi2zy0Liv0mmulK7Y+Cs0P20Dt+qywMw/0 4DhILTiNAmpnxTiI7W2tlyuo9CPChhzng1EbgAaqFh5JngXujxBm9ZK3vVzi+BAAwYB+ QJRUF0ZzAbqXtFnygnj7KjB1k+yjFSspzJG9vrwsLhqyqf85peAtadF+/bDVLYvW2t0A /VhQ== X-Gm-Message-State: AA+aEWbxx2wWuMzgGcSb+O8y/3NvtZkumnTdtvKQcxsNHBgTiOBq8vVs C6iutY4xGlOMQxfn39fXC8A= X-Google-Smtp-Source: AFSGD/XqGjsu2dl3unSdGhUM1EHWX8qf9Ss3EF8HxouvyXzbj3rUHmB01s0xwk9Tdic+bN2nTT6m/A== X-Received: by 2002:ac8:518d:: with SMTP id c13mr17362217qtn.254.1544569395553; Tue, 11 Dec 2018 15:03:15 -0800 (PST) Received: from dennisz-mbp.thefacebook.com ([199.201.65.135]) by smtp.gmail.com with ESMTPSA id c48sm10640106qtd.9.2018.12.11.15.03.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 11 Dec 2018 15:03:14 -0800 (PST) From: Dennis Zhou To: Jens Axboe , Tejun Heo , Josef Bacik Cc: kernel-team@fb.com, linux-block@vger.kernel.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Ming Lei , Dennis Zhou Subject: [PATCH] blkcg: handle dying request_queue when associating a blkg Date: Tue, 11 Dec 2018 18:03:08 -0500 Message-Id: <20181211230308.66276-1-dennis@kernel.org> X-Mailer: git-send-email 2.13.5 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 Between v3 [1] and v4 [2] of the blkg association series, the association point moved from generic_make_request_checks(), which is called after the request enters the queue, to bio_set_dev(), which is when the bio is formed before submit_bio(). When the request_queue goes away, the blkgs supporting the request_queue are destroyed and then the q->root_blkg is set to %NULL. This patch adds a %NULL check to blkg_tryget_closest() to prevent the NPE caused by the above. It also adds a guard to see if the request_queue is dying when creating a blkg to prevent creating a blkg for a dead request_queue. [1] https://lore.kernel.org/lkml/20180911184137.35897-1-dennisszhou@gmail.com/ [2] https://lore.kernel.org/lkml/20181126211946.77067-1-dennis@kernel.org/ Fixes: 5cdf2e3fea5e ("blkcg: associate blkg when associating a device") Reported-and-tested-by: Ming Lei Signed-off-by: Dennis Zhou Reviewed-by: Bart Van Assche --- block/blk-cgroup.c | 6 ++++++ include/linux/blk-cgroup.h | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) 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; diff --git a/include/linux/blk-cgroup.h b/include/linux/blk-cgroup.h index bf13ecb0fe4f..f025fd1e22e6 100644 --- a/include/linux/blk-cgroup.h +++ b/include/linux/blk-cgroup.h @@ -511,7 +511,7 @@ static inline bool blkg_tryget(struct blkcg_gq *blkg) */ static inline struct blkcg_gq *blkg_tryget_closest(struct blkcg_gq *blkg) { - while (!percpu_ref_tryget(&blkg->refcnt)) + while (blkg && !percpu_ref_tryget(&blkg->refcnt)) blkg = blkg->parent; return blkg;