Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp6555422ybx; Mon, 11 Nov 2019 10:53:08 -0800 (PST) X-Google-Smtp-Source: APXvYqysvokABm65g+h0/+/KsC7zLM2t3rREJEWQk5GHIbF33jYWfhT8It4FmrVL6ZDn6lWAFt1X X-Received: by 2002:a50:baa9:: with SMTP id x38mr27048259ede.106.1573498388561; Mon, 11 Nov 2019 10:53:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573498388; cv=none; d=google.com; s=arc-20160816; b=ksldvFkHEoKVrTpfyWx1D+kGlMovCCFhuLQtAKgZZBTq4NtHK3gg/xQkWxrTcVnLT1 PUBGaeVb7I6srkDO7nzw+UWfTULEv2XHZZJkwanL0rTYI6KnC2DfbHMWICzwqA0wAbWU ArM8nQJ6+/d4RA102EF2cuxqYQ/uQdiHyvs/LGEv18JchRcRvpvxWz58PAbTN0DY6Oyx xpLtj2gt6WIEX3VK9mV/fcLXYd1b9R33xnhxMll8MjqhqOloYfdbt8pWjcJMYaM0yA0R b2SY423zj5v+Iihf7LBKdre1J46m0kbC2wfVVS+9OjbsZWJ9scz3uLL+KZjs2NkS6RHU 2jmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=LI4AkDVNZhwK6xG6vffLEJWmFPPV2ePtRcT7cXMXqvk=; b=uYrli9rD9jWdjyeCft0yRZEhm0d1L8edA1tFwnOojclArMaBv4AMmTZARt1g0m4FBk N6+VzyLbdpwCw18WDCBkEAJxiSttyP86Vv/ZAI+qQsKFhtAOmmbZOp2+WWiiifyh9Y/S UjCuheim+numHE0rwU54S0WwspG3oS/2uEzh/NbfAHgLJpImw5dPltPL1UaUF1k4eMK2 etNvXZEwl89Sw1Qur3oq6iQFwjSEGzXi/stPy11kfhzOqxph1+5KY2kTLL62X9kzGD6Z 3W7Dh6htTQcyVBLhjRmHUTfUVr+DrmnTFV5mlivu0DpiKpA2flDmhZrPDnMYkdU929a5 rbWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vIgqyEdb; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i24si4724060edr.311.2019.11.11.10.52.44; Mon, 11 Nov 2019 10:53:08 -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; dkim=pass header.i=@kernel.org header.s=default header.b=vIgqyEdb; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729404AbfKKStv (ORCPT + 99 others); Mon, 11 Nov 2019 13:49:51 -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();