Stable Archive on
 help / color / Atom feed
From: <>
Cc: <>
Subject: FAILED: patch "[PATCH] blkcg: make blkcg_print_stat() print stats only for online" failed to apply to 4.19-stable tree
Date: Mon, 11 Nov 2019 07:12:24 +0100
Message-ID: <> (raw)

The patch below does not apply to the 4.19-stable tree.
If someone wants it applied there, or to any other stable or longterm
tree, then please email the backport, including the original git commit
id to <>.


greg k-h

------------------ original commit in Linus's tree ------------------

From b0814361a25cba73a224548843ed92d8ea78715a Mon Sep 17 00:00:00 2001
From: Tejun Heo <>
Date: Tue, 5 Nov 2019 08:09:51 -0800
Subject: [PATCH] blkcg: make blkcg_print_stat() print stats only for online

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: # v4.19+
Signed-off-by: Jens Axboe <>

diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
index 5d21027b1faf..1eb8895be4c6 100644
--- a/block/blk-cgroup.c
+++ b/block/blk-cgroup.c
@@ -934,9 +934,14 @@ static int blkcg_print_stat(struct seq_file *sf, void *v)
 		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
@@ -946,8 +951,6 @@ static int blkcg_print_stat(struct seq_file *sf, void *v)
 		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];
@@ -960,8 +963,6 @@ static int blkcg_print_stat(struct seq_file *sf, void *v)
 		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,
@@ -999,6 +1000,8 @@ static int blkcg_print_stat(struct seq_file *sf, void *v)
 				seq_commit(sf, -1);
+	skip:
+		spin_unlock_irq(&blkg->q->queue_lock);

             reply index

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-11  6:12 gregkh [this message]
2019-11-11 13:44 ` Sasha Levin

Reply instructions:

You may reply publically to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Stable Archive on

Archives are clonable:
	git clone --mirror stable/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 stable stable/ \
	public-inbox-index stable

Example config snippet for mirrors

Newsgroup available over NNTP:

AGPL code for this site: git clone