From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C2514389DF3 for ; Fri, 7 Aug 2026 19:37:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786131457; cv=none; b=QlrirINzAsx1pl5gojBeWCSkCZCIJZ4xP291G7NUHjt2Fr+6sqDITlksiKna1/q3Pu5J8qrGKQ7Bsl1HWXZwclZsgFRUtECLU5R9OelbOnoWI8kaK2ygXA1ILNgYGXG4RAQ78QECPg9a/lL8ERdrL2eAXA17Ti+cNmO2Bm+O7pc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786131457; c=relaxed/simple; bh=OfZlFzq+2BnMIm4nQBcIZ5X575uhJ2FAVGh4LaBJbkc=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=fOE/ExFJjNlqWp1rZKn6kUuZ8331JDreteikFyDmfld3ilgWyBQdLCe7V6raeAN6iWSFfvz/eniFhF6C+c6HuFEyj5kw1c7Byj4GD9TX2VVtV+1A9bOwZAax+RyHE/6NZPceU9NcNoOVrLagQ9TkHuF4xgyg8rK09rcggWf0UK8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=fyDj2jsA; arc=none smtp.client-ip=209.85.215.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fyDj2jsA" Received: by mail-pg1-f172.google.com with SMTP id 41be03b00d2f7-c96b08cdd1cso2886809a12.0 for ; Fri, 07 Aug 2026 12:37:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786131455; x=1786736255; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=DEQarv7srdTW6cIHXAN9RnUfhHlppoDw4ouFa8YYmro=; b=fyDj2jsA47obp6f8xZJ+6JOpVp4lz9c1395UylUhVe0jh1frOe7KJ5zMMeG9aly9jl B2NO1Vr70JVyYJf6kNkR7pB1o701clz67r5urTJ27Y4/xH/XvwVm2t/n8evI077XbcMw GUeapCx2IocA3sIOdO8BTC/oM+2ma91Hdp2ADVR5mKKTpXOrZvAcAzSbkSk+1rCpu7bS zQIiz8hj+REQ4ADd12zVEOiozjf5dllQBMErUsvhQYuUqqjaCEvt0AlK/SpkeCQDdf9M FqcgM0gYxZzIfBxyx/+5Pf9gmSb2ljcUBKgrAWNsrpoAPp6zwGsqEFW9vm6OOjw92lLR edFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786131455; x=1786736255; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=DEQarv7srdTW6cIHXAN9RnUfhHlppoDw4ouFa8YYmro=; b=EQfFxSnYeJ2257/d/Jsxb7uoAX0M12hB17AOoYJbL1lTmShc2Ui1/cVgjbPauA9/8Q P0IkEybfcA2TPWgXk4KpXDNTR5jHNsSUdl+C9FNsQWVAtKXu96aH+oojPE5DcDerShhh rebTOo4ts6GH6E+/ZkY3Iaa3KjOw64bDLFhAbfkECleyZ8Ghk4DO6eWqSUDNoJawX1AG of9rpBUCqoy3zkQj6vhDxArpreE7tBZOnMVZKnZY17FxWP6J6Bgh0yMvVvkALVnZt4J6 4YnlAahlUBuc90ySaFrxA4FrPQk6hj5v3t+CV9jKu+w4oVVBDhq/TgJYN36g43NwbnpS 9XWA== X-Forwarded-Encrypted: i=1; AHgh+Rrke6fLJpNbKfo/e51SPQ+C46NK1XNDXntvzFEjEaL4LMxlJQ0VCu4IvEGf9/Ysvn+Cg9U=@vger.kernel.org X-Gm-Message-State: AOJu0YzUbqefOTulM0iVjE0pjWId2no2sS7SWfISOLoHFfJbUkylI8P+ t7zkdOT5wuAlT6joxTz5/hEGYJR4Bpg09GbguIuVvx0oOl4e8aHyNEGi X-Gm-Gg: AR+sD13l4i8rPcwO95IsZpWlmJKaAI3LyW7M979Tgp5w/ZNSjeQDYMEk4OQps4ne9av NbOcsGL+Sk1BLl3Bl54emomu2yCSbn3izdamjibwSuwSANR8gkPZDGxZh2GhqmgbXPcTtc8lnQG UUHR3pAUrATYDMqGB6tqG5Ncve/ryJpHkKBuaL9gCI5KBMLBuFk8zMWZWpnGp63KWlk30ntiQaK MtKQNLXvh7oyBgV3++tp9CDV1kd61BhWaSXhT+B6kbH4F7ayoebRUcjVATyq00vLkz1KN15EQvH tsPTf+H6yu6SM1QYEyX6MY04yW9bg52Vcw702CxDEdoEhIIGkQFkxlXriY1gDcr/pyf4xrLVh62 ZWggvGYPSLf7qBRM3qCIIFQd/LK76i3p17irnCLAr6OHZtlvLCgnvhhPLoEbTnmiC+ea6tYFIev LsCK7N7MVFXGscDaTBSctx1Te+7XeRs+j7T83u2nRGHDOeyZU7wXKEKBU= X-Received: by 2002:a05:6a21:7a9c:b0:3bf:983d:e9b4 with SMTP id adf61e73a8af0-3cb8603af0dmr29747576637.33.1786131454911; Fri, 07 Aug 2026 12:37:34 -0700 (PDT) Received: from localhost ([2a03:2880:9ff:44::]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-141019b4eabsm9312963c88.6.2026.08.07.12.37.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Aug 2026 12:37:34 -0700 (PDT) From: Ziyang Men To: Jens Axboe , Tejun Heo , Josef Bacik , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Eduard Zingerman , Kumar Kartikeya Dwivedi Cc: Martin KaFai Lau , Song Liu , Yonghong Song , Jiri Olsa , Emil Tsalapatis , Shuah Khan , Johannes Weiner , =?UTF-8?q?Michal=20Koutn=C3=BD?= , Roman Gushchin , Shakeel Butt , JP Kobryn , Mykola Lysenko , kernel-team@meta.com, linux-block@vger.kernel.org, bpf@vger.kernel.org, cgroups@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Ziyang Men Subject: [PATCH 0/2] block: expose blkcg io.stat to BPF Date: Fri, 7 Aug 2026 12:37:30 -0700 Message-ID: <20260807193732.4073299-1-ziyang.meme@gmail.com> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit This series exposes the block I/O controller's per-device statistics (io.stat) to BPF via read-only kfuncs, mirroring the kfuncs for the memory controller in mm/bpf_memcontrol.c. Motivation: Collecting cgroup statistics is expensive: the existing method is to open and parse a cgroup file for every cgroup of interest. memcg already has an efficient alternative through BPF; this series extends that idea to block. The main difference from the memory controller is that blkcg keeps one blkg (one io.stat line) per block device, so the readers operate on a blkg and the iterator yields them under RCU. Reads take the same u64_stats seqlock as the io.stat file, so the kfuncs add no fast-path cost. The root cgroup needs its own path. It is not accounted through rstat at all, so bpf_blkcg_flush_stats() branches the way blkcg_print_stat() does and refills the root's per-device aggregates from the disks' own statistics. That is the only reason the series touches blk-cgroup.c and blk-cgroup.h: blkcg_fill_root_iostats() is no longer static. Nothing on the I/O path changes. Patch 1 adds the kfuncs (block/bpf_blkcg.c); patch 2 adds a test_progs selftest that drives direct I/O to a loop device and checks 1) that the measured values are non-zero (as cgroup_iter_memcg does), 2) that each kfunc value exactly matches the cgroup's io.stat file for that device, and 3) that the same device read through the root block cgroup is at or above what the test cgroup was charged. Tested on v7.2-rc5 with the series applied: all five cgroup_iter_io subtests pass (write/read/dev/match/root). Ziyang Men (2): block: add BPF kfuncs to read blkcg io.stat selftests/bpf: add test for blkcg io.stat BPF kfuncs MAINTAINERS | 1 + block/Makefile | 3 + block/blk-cgroup.c | 2 +- block/blk-cgroup.h | 1 + block/bpf_blkcg.c | 315 ++++++++++++++++++ tools/testing/selftests/bpf/cgroup_iter_io.h | 17 + tools/testing/selftests/bpf/config | 1 + .../selftests/bpf/prog_tests/cgroup_iter_io.c | 310 +++++++++++++++++ .../selftests/bpf/progs/cgroup_iter_io.c | 107 ++++++ 9 files changed, 756 insertions(+), 1 deletion(-) create mode 100644 block/bpf_blkcg.c create mode 100644 tools/testing/selftests/bpf/cgroup_iter_io.h create mode 100644 tools/testing/selftests/bpf/prog_tests/cgroup_iter_io.c create mode 100644 tools/testing/selftests/bpf/progs/cgroup_iter_io.c -- 2.53.0-Meta