From nobody Thu Apr 2 20:22:16 2026 Received: from out-180.mta1.migadu.com (out-180.mta1.migadu.com [95.215.58.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D05442D6E6F for ; Thu, 12 Feb 2026 08:23:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770884641; cv=none; b=NVs/FKbrJaG9S2uFQp21Yq8/G/7SxYbOt0w8QsCCZ/CzEiDGhl0gMJcjQLTK4qMtJvYHr3uSYBRIcb20eoZgZWYgxXEJAlg6Wx927GqxmrDnOROkurlh617F3+QntY9LANlPLYNhTlaHQKyw3NIe8mxz+dnrOa2QYHojOx4OUQA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770884641; c=relaxed/simple; bh=r6OgvQEi15eLD8Z0lMy3VJnZSrA8sKhWevT7njpVbU4=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=e+5MhQm1jxMOXIcGyjM/7+yZ35Zefntnin9dTpjTmw5E3y7QA09iC4yGvwROj4ecTvF54nDMbAbwRi94uWJubu6W4vsv/0ggacTcbgZzyWEKYVHgbJ67iciyjBOvb23U2WUyTPn/QbX6JMAbM8FvmvULHIvZSdp9WkNEIoBVrk4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=HJ0OIcoA; arc=none smtp.client-ip=95.215.58.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="HJ0OIcoA" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1770884637; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6JEGc5je/wM02pWehmFOl3sKJ7z0YxNGSRtnUE/RPCI=; b=HJ0OIcoA3oOP4U35yiAgKDYaQEY7TuX0qZLIDHgEFaDpBmCxjWW09jCTIjMQzH8JMX5S9F xrjh3BlaT9jvCMCDi44I3clcJ/Li+Q3ml5I/JJo7Viwh8gqwadztOu8XjVc6gL933c7r54 OCbBi0K4vo3sxio7V14h6YbB0bfqkCg= From: Hui Zhu To: Johannes Weiner , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Andrew Morton , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shuah Khan , Hui Zhu , JP Kobryn , cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH bpf-next 2/3] mm/memcontrol: Return error when accessing kmem with nokmem Date: Thu, 12 Feb 2026 16:23:15 +0800 Message-ID: <733422f72ccbac94126ae67b9e49f4a3d460b76a.1770883926.git.zhuhui@kylinos.cn> In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: Hui Zhu When running tests on hosts with cgroup.memory=3Dnokmem enabled for performance reasons, test_kmem always gets a value of 0 for kmem statistics. Since BPF programs cannot easily determine whether kmem is enabled, add a check in memcg_stat_item_valid() to return an error when attempting to access MEMCG_KMEM statistics while kmem accounting is disabled via cgroup_memory_nokmem. This prevents BPF programs from silently receiving zero values and allows them to properly handle the case where kmem accounting is unavailable. Signed-off-by: Hui Zhu --- mm/memcontrol.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 129eed3ff5bb..4d8419623d1c 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -667,7 +667,8 @@ unsigned long memcg_page_state(struct mem_cgroup *memcg= , int idx) =20 bool memcg_stat_item_valid(int idx) { - if ((u32)idx >=3D MEMCG_NR_STAT) + if ((u32)idx >=3D MEMCG_NR_STAT || + (cgroup_memory_nokmem && (u32)idx =3D=3D MEMCG_KMEM)) return false; =20 return !BAD_STAT_IDX(memcg_stats_index(idx)); --=20 2.43.0