From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6B94FC43331 for ; Mon, 11 Nov 2019 18:49:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 434B8204FD for ; Mon, 11 Nov 2019 18:49:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573498193; bh=6aIYRFn4mz/rizev/wF2Fgg4Ky0sLc65bJWXzf+yNH4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=JBeKybprta2p/arhkU6MzGcGuCqLW6sKZtB+5mmlqryMNg2CYy/JjJF19hQou+F2t Rw2l3pKsx7/tPtPUVFmjuikfhV4C8kg2fr8tlLzqRUaPj5NXHIzyKwFo8Av/QGQU7F izeSEqu/Yc3buYG+c7LaY/RrflQfqCu19LLyFXlo= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730313AbfKKStw (ORCPT ); Mon, 11 Nov 2019 13:49:52 -0500 Received: from mail.kernel.org ([198.145.29.99]:43268 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728080AbfKKStt (ORCPT ); Mon, 11 Nov 2019 13:49:49 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 27FC32196E; Mon, 11 Nov 2019 18:49:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573498189; bh=6aIYRFn4mz/rizev/wF2Fgg4Ky0sLc65bJWXzf+yNH4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vIgqyEdbLf18/W2XxBTDSepg/AsIfaQbOH1BBblj5mT+haONzwv7CQU/sRJV1iij/ hKuPjb+1aSJFlpsBWCrgOHiBDQ1AslRZfBQfoecuMeFSMcYidIlKTWfVcO+RypfTyq xQ8HpQdBdv7KKi+/D94Mv3Z7yVurl/XXbyJDrgzE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tejun Heo , Roman Gushchin , Josef Bacik , Jens Axboe Subject: [PATCH 5.3 048/193] blkcg: make blkcg_print_stat() print stats only for online blkgs Date: Mon, 11 Nov 2019 19:27:10 +0100 Message-Id: <20191111181504.507282441@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191111181459.850623879@linuxfoundation.org> References: <20191111181459.850623879@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tejun Heo commit b0814361a25cba73a224548843ed92d8ea78715a upstream. blkcg_print_stat() iterates blkgs under RCU and doesn't test whether the blkg is online. This can call into pd_stat_fn() on a pd which is still being initialized leading to an oops. The heaviest operation - recursively summing up rwstat counters - is already done while holding the queue_lock. Expand queue_lock to cover the other operations and skip the blkg if it isn't online yet. The online state is protected by both blkcg and queue locks, so this guarantees that only online blkgs are processed. Signed-off-by: Tejun Heo Reported-by: Roman Gushchin Cc: Josef Bacik Fixes: 903d23f0a354 ("blk-cgroup: allow controllers to output their own stats") Cc: stable@vger.kernel.org # v4.19+ Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- block/blk-cgroup.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) --- a/block/blk-cgroup.c +++ b/block/blk-cgroup.c @@ -908,9 +908,14 @@ static int blkcg_print_stat(struct seq_f int i; bool has_stats = false; + spin_lock_irq(&blkg->q->queue_lock); + + if (!blkg->online) + goto skip; + dname = blkg_dev_name(blkg); if (!dname) - continue; + goto skip; /* * Hooray string manipulation, count is the size written NOT @@ -920,8 +925,6 @@ static int blkcg_print_stat(struct seq_f */ off += scnprintf(buf+off, size-off, "%s ", dname); - spin_lock_irq(&blkg->q->queue_lock); - blkg_rwstat_recursive_sum(blkg, NULL, offsetof(struct blkcg_gq, stat_bytes), &rwstat); rbytes = rwstat.cnt[BLKG_RWSTAT_READ]; @@ -934,8 +937,6 @@ static int blkcg_print_stat(struct seq_f wios = rwstat.cnt[BLKG_RWSTAT_WRITE]; dios = rwstat.cnt[BLKG_RWSTAT_DISCARD]; - spin_unlock_irq(&blkg->q->queue_lock); - if (rbytes || wbytes || rios || wios) { has_stats = true; off += scnprintf(buf+off, size-off, @@ -973,6 +974,8 @@ static int blkcg_print_stat(struct seq_f seq_commit(sf, -1); } } + skip: + spin_unlock_irq(&blkg->q->queue_lock); } rcu_read_unlock();