From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (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 3F12D3B19D9 for ; Mon, 10 Aug 2026 22:47:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786402023; cv=none; b=nLS0xRK9fVpr0thVKaQP87L8vnMR28ywH/AxCp/qgQuCbvvoz49rQIuVzuJ9sgpYKpWplsTf+1RptyGaqaASHWaUVV3tDJkTxJs5hwaFT/y9DRDQ0jWPVpGVPbPLyfimeQ6lZG1EQ46JBMtuGWCE6zO04QdIXim8qMz5kqC7NSE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786402023; c=relaxed/simple; bh=j0OQmT53umZb7i6H00ow16BYQr6XaIiq74a3wXvSmQc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=bpWi+yHqMAZPRTTDSftt4IHXLQstBIcj0avjZkw5ObVwKVtN+pbIIa1SJeepPtjVvrHG8EoKJgBeTHUAmB1tf2uH/haAJD8IfehjCpX3tgRRCwRIUTM1ILEuW4wEucgoSBIVm/0JVkJOFognlj5EesSt/kC6jv6jA6UM3FBkzok= 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=P4xuI4HE; arc=none smtp.client-ip=209.85.214.182 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="P4xuI4HE" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-2d049069377so21246065ad.0 for ; Mon, 10 Aug 2026 15:47:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786402021; x=1787006821; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=GSgLjB/IGBoUiOT3dGu6Xr2ioiybikIeSufKLnKV+5A=; b=P4xuI4HElZe7p0IfsOkFrq6eCDodfYTXhFcQNQWxoRUuTeBDMCKOZsPq46j3udl9gD CCfBbGrzAs/UmB3BootdJTmI5qcwMC1cQq214S0kDof/0IrinaO8MFYcMv0QG8TNjKY2 8jjOwMLeSwOd4o9MviyO/Lu49ePL46ifdbBcbCfRdnq0x9PlmUzyLSjk0hUmTsipmBdy UD698jqBj1XhCKFGnJdDN1EwhwFQU+3BkNjozdSxDhyRF7Jv4UZlnDtpEP6Of/DJzBXe SGhYkBnkAlA01IRiwATSvei8pEZ5NEbwiYjr19E3z4KZG+DysjOsuzv1RXjleJQc8Vhx FI7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786402021; x=1787006821; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=GSgLjB/IGBoUiOT3dGu6Xr2ioiybikIeSufKLnKV+5A=; b=AqGjlMd64qOMZE+biFv0czRWKLj3RabDxddfCeLd9kwOfNI1EX6gGfWzOOtadPYWsR 5PBAPYbTRMfhE4dNYdgL5XWigOaxioriNiV2B4veMGfCbpn1nxRpXQHLb3BE6EBkoz2j XSAK/lc+7bYJ/LEA9Da1ULIzagMmlEQqgjzkyb2bUiysyYAGJAgOyq4ITfdUvyTaYzcB HIMmuMXpFhoZvlbsaqytobSqgmgABlt9kC5zjWbYj1Ku4EflhPSRKFL2cANKvJ09CVDJ +FreyAzw4M6+3a781tgrVka6f9W/uOKBg9CinLSnKrIaG2dzPKXXySWe5ZDZSX64bsHU cbfQ== X-Forwarded-Encrypted: i=1; AHgh+Rqo0zakoFixVtUNg+D5Nz5H15zkhl4dRi3wPHFKDSmfN1K9tIYJi6vi7mXVOIY+761+xNgILdSNagUGuhM=@vger.kernel.org X-Gm-Message-State: AOJu0YyKmzsT+013pHPVEQGeMEGO/9aUL5xOk7FA2Kew91ezIq522CHh sU8uMx9ZoiMZ0HFsm1QZd2+JO1cOSP0jbDVBr2Dflzt+SHrhXqOkyREb X-Gm-Gg: AR+sD11rNsRdDbXtF0hsznz/ZzKNjQ1CXlKm+Zix50QwdPJWeAeJd7r5vEGVstg1dde c96/Dx49hEDR2cBm/yGkIF6oPS0kU3VvZzTlwDHTdh/bq7Mwx/4015jERSLkMtcUMGW2Ogi+9me jGxj/UMhHdDhYMP/uLQsySU5DUZGb37HUPT49rQaQZUnXfbcAq15mNDxGS1I8/1YmriU9ZztwnH aT8bCLQQVEMxag2ZcXz4S4f91wTu9fnX3bxBVKq6d33WnUjhc9y+VtjdtpJzyu4Yk/ZZ4Z1sAEm zFgfZQYB/UdBd0qiu0A2MjVNU/xwxNRubPw86Ajj2PZ8bdnnMS1Jig3oKI91vI9hwRTj/+F5B0N 4Kf/QdfqPnQhFTskgTzbKqnRTuqRFfXFQlrCdb+iyDDxKWWoaHCuJk4kKAp/jX9VE5sfGcB3KG4 +unPf0GK1RvN8bH+jzfxK5FN39BOcdYcuiNVYUSE8Cl4dlGdHHIFAPfddfm7Fln0Kp0T7HUGEKW HRI24g2 X-Received: by 2002:a17:90b:590e:b0:38e:6a44:671b with SMTP id 98e67ed59e1d1-3909d301d9cmr33764302a91.0.1786402021510; Mon, 10 Aug 2026 15:47:01 -0700 (PDT) Received: from devvm16600.scu0.facebook.com ([2a03:2880:9ff:68::]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-315bec26a46sm47194173eec.27.2026.08.10.15.46.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Aug 2026 15:47:00 -0700 (PDT) Date: Mon, 10 Aug 2026 15:46:58 -0700 From: Ziyang Men To: Tejun Heo Cc: Jens Axboe , Josef Bacik , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Eduard Zingerman , Kumar Kartikeya Dwivedi , Martin KaFai Lau , Song Liu , Yonghong Song , Jiri Olsa , Emil Tsalapatis , Shuah Khan , Johannes Weiner , Michal =?iso-8859-1?Q?Koutn=FD?= , 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 Subject: Re: [PATCH 1/2] block: add BPF kfuncs to read blkcg io.stat Message-ID: References: <20260807193732.4073299-1-ziyang.meme@gmail.com> <20260807193732.4073299-2-ziyang.meme@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: Hi Tejun, Thanks for your review and suggestions! On Mon, Aug 10, 2026 at 10:00:55AM -1000, Tejun Heo wrote: >Hello, > >On Fri, Aug 07, 2026 at 12:37:31PM -0700, Ziyang Men wrote: >> +__bpf_kfunc struct blkcg *bpf_get_root_blkcg(void) >> +__bpf_kfunc struct blkcg *bpf_get_blkcg(struct cgroup_subsys_state *css) >> +__bpf_kfunc void bpf_put_blkcg(struct blkcg *blkcg) >> +__bpf_kfunc void bpf_blkcg_flush_stats(struct blkcg *blkcg) > >I wonder whether making the above deal with css's would make more sense so >that we don't end up with per-subsystem iterators. If casting to per-subsys >type is necessary, we can provide RCU protected cast kfucns. > Good idea! These do nothing block specific and we already have some common helpers for it such as the bpf_get_root_blkcg(). What is missing is a way to get one controller's css from a cgroup with a reference held, and the cast. So I would add in kernel/cgroup/ struct cgroup_subsys_state *bpf_cgroup_css(struct cgroup *cgrp, int ssid); void bpf_css_release(struct cgroup_subsys_state *css); where the @ssid is an enum cgroup_subsys_id value. Afterwards, the only piece for blkcg left is: struct blkcg *bpf_css_to_blkcg(struct cgroup_subsys_state *css); Note the bpf_blkcg_flush_stats may keep its current shape as it mirrors the blkcg_print_stat() which skips the root. With these helpers we can also replace the existing ones in mm/bpf_memcontrol.c as well: bpf_get_mem_cgroup() bpf_put_mem_cgroup() bpf_mem_cgroup_flush_stats() they map onto bpf_cgroup_css() plus a bpf_css_to_memcg() cast the same way. Hi Roman, JP, Shakeel: Do you think it is worth applying above changes for the memory controller as well? If you are happy with the direction I am glad to send the conversion as a follow-up once the generic kfuncs are in. Would you take it? >> +__bpf_kfunc u64 bpf_blkg_iostat_bytes(struct blkcg_gq *blkg, >> + enum blkg_iostat_type rw) >> +__bpf_kfunc u64 bpf_blkg_iostat_ios(struct blkcg_gq *blkg, >> + enum blkg_iostat_type rw) >> +__bpf_kfunc u64 bpf_blkg_dev(struct blkcg_gq *blkg) > >Ignoring 32bit split reads (do we really care for BPF accesses?), the above >can easily be done with BPF_CORE_READ(), right? Agree, these parts will be removed in the next version. > >Thanks. > >-- >tejun Please let me know whether the above ideas works. Thanks very much! Best, Ziyang