Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1217094imu; Tue, 11 Dec 2018 15:04:21 -0800 (PST) X-Google-Smtp-Source: AFSGD/Vg+jXN+EZs3qg5FjwlNuLWyVhYKfr3BAiLMEOpCAnDktX/26xapciT/sPLhhwP62vAlCHt X-Received: by 2002:a62:59c9:: with SMTP id k70mr17981593pfj.243.1544569461613; Tue, 11 Dec 2018 15:04:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544569461; cv=none; d=google.com; s=arc-20160816; b=hXM+2FxwMjcECJmEtDLUUoyMTOLrGYxpFjtK0cy85iGy81i9TBkU6cxK2P+JpVeyAo x+CJitcsw2RFF6tkdTFO56bOh1BL/8BuOBI/fXKxPnOXO5dshDvdk0eWK8S0Dqe+Kaxu jUy9GN8hOqd6CJhyxAU7IbGLRvDosDqIk0r/k4GC5Ce7V+neL21ARBknGriY6ll50bPU 9LFYdo62Rt/gJ0rUKIsr6omBEv0ODkfiJXYBXnbHC1yvU8Y+bDIqGIRfL2pKsNEReNQD x+SYtRA9lAMkSBq7u4O7ZV6P8b9n5669bSk9RGCmjrqR7ZVawH4CN10arecPLqWISRs/ AUsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=puxO2IKeuPOawx9ZdsIf28v5dik70E0wmP0rRCpd2u4=; b=Njg6SUQdeolM7Gl5hvYjVDTQzx4fHNwnbeBFblugSZpzM8U+YuXfbvaG7dxTbE63mk EI2Tp+hbj0SSaydI8dsHvRrtGW66KIFgD9W91izDFi7xiucylk6Mtd+C0RInz4G9R7Dq RV8j0RrakEJb8d7zsr7+HQLuAYRxP561311/LpWni+cRuaSt6MtzYouroq6Kd7d6Nq56 4Z9jvGzJ9LxVsHRhh7y4AjoMM41KkKKF0qceJz6dMoKdQ1JZ85iAVPAX4FJxvki/hI72 33JXTbopvhrA4zfHTE+ICUUbu7K+D8KBMINr7T4wSMU6yv3n5mZx771Vjp8mNHDI4mHw jSWQ== 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 b186si14019327pfb.24.2018.12.11.15.04.06; Tue, 11 Dec 2018 15:04:21 -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 S1726237AbeLKXDR (ORCPT + 99 others); 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-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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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; -- 2.17.1