From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-179.mta0.migadu.com (out-179.mta0.migadu.com [91.218.175.179]) (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 60FA53A1E72 for ; Sat, 20 Dec 2025 03:20:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766200821; cv=none; b=hSnVCTGW9o44vQ7YxUtO3pSpTmyqxBxLMCxApfoefAxKq1MW5qIB0SdZtu2mTpyDAJvUv0bNcELl6qe+WATulF8bGp4bWLm6SRyq/aXVoHsMupI7a7QJFsu9U30GLIDmZWE/Qd9AClkXNdIztM7D7S6lSMaezkkZEIf0cyl6jlk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766200821; c=relaxed/simple; bh=IkyeGu9OFPgLYqYZ1qqfIh0vElhnNuk0wiIh82Svu3s=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=OhXq9nDbghZSjdbS11nn3DVYwJ7zkVeepswdJtpW9Vvunl5Zkx3vy4KKIP8bqeyxB6u+L5eI18lip/7qCGWpyl2jLxcGHMcxhPd0UCZJZ7VysvxbbHw54EOjlVLhOFBj3uYbPtwz1bTxjrfZA2ftJK7sT4CGsnfifIy0EjAzzyU= 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=AqfSN9En; arc=none smtp.client-ip=91.218.175.179 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="AqfSN9En" 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=1766200810; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=KSWnxPF7s7XrgaAgGOnY7K1GNIzL+YqDV6JYLvAhZaU=; b=AqfSN9EnBu+pQ+55c6KrxraFWofHwRehkLXlObC2WQPuyODI6sRp51PUDiCH3FSpSQ7hHV WCMjBb/r91usuQ1LiKsr/XDzXH2rvZl2CtPrYl/dV9uHmZAF0fjFp3qytDa7/4JaXToPF3 h06Y8zGnLjlifMc3TK1SqU1GZykFUFQ= From: Roman Gushchin To: Shakeel Butt Cc: bpf@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, JP Kobryn , Alexei Starovoitov , Daniel Borkmann , Michal Hocko , Johannes Weiner Subject: Re: [PATCH bpf-next v1 6/6] bpf: selftests: selftests for memcg stat kfuncs In-Reply-To: <2xhmcrporen72rskghn6hmg6obnojptuerwzqgu7mqzhnxaxs5@33dxlwa6rqlh> (Shakeel Butt's message of "Fri, 19 Dec 2025 15:07:11 -0800") References: <20251219015750.23732-1-roman.gushchin@linux.dev> <20251219015750.23732-7-roman.gushchin@linux.dev> <2xhmcrporen72rskghn6hmg6obnojptuerwzqgu7mqzhnxaxs5@33dxlwa6rqlh> Date: Fri, 19 Dec 2025 19:20:04 -0800 Message-ID: <87cy49g7q3.fsf@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain X-Migadu-Flow: FLOW_OUT Shakeel Butt writes: > On Thu, Dec 18, 2025 at 05:57:50PM -0800, Roman Gushchin wrote: >> From: JP Kobryn >> >> Add test coverage for the kfuncs that fetch memcg stats. Using some common >> stats, test scenarios ensuring that the given stat increases by some >> arbitrary amount. The stats selected cover the three categories represented >> by the enums: node_stat_item, memcg_stat_item, vm_event_item. >> >> Since only a subset of all stats are queried, use a static struct made up >> of fields for each stat. Write to the struct with the fetched values when >> the bpf program is invoked and read the fields in the user mode program for >> verification. >> >> Signed-off-by: JP Kobryn > > Need your signoff Sure, will add, thanks. > > [...] >> + >> +#define NR_PIPES 64 >> +static void test_kmem(struct bpf_link *link, struct memcg_query *memcg_query) >> +{ >> + int fds[NR_PIPES][2], i; >> + >> + /* >> + * Increase kmem value by creating pipes which will allocate some >> + * kernel buffers. >> + */ >> + for (i = 0; i < NR_PIPES; i++) { >> + if (!ASSERT_OK(pipe(fds[i]), "pipe")) >> + goto cleanup; >> + } >> + >> + if (!ASSERT_OK(read_stats(link), "read stats")) >> + goto cleanup; >> + >> + ASSERT_GT(memcg_query->memcg_kmem, 0, "kmem value"); >> + >> +cleanup: >> + for (i = 0; i < NR_PIPES; i++) { > > Instead of from 0 to NR_PIPES, we need to go from i-1 to (and equal to) 0 > otherwise we can potentially close() junk values. Good catch, will fix. > >> + close(fds[i][0]); >> + close(fds[i][1]); >> + } >> +} >> + > > [...] > >> + >> +SEC("iter.s/cgroup") >> +int cgroup_memcg_query(struct bpf_iter__cgroup *ctx) >> +{ >> + struct cgroup *cgrp = ctx->cgroup; >> + struct cgroup_subsys_state *css; >> + struct mem_cgroup *memcg; >> + >> + if (!cgrp) >> + return 1; >> + >> + css = &cgrp->self; >> + if (!css) > > Will css ever be NULL here? Hm, I think previously the verifier wasn't smart enough to understand that it's always a valid pointer, but I just tested it with linux-next and it worked well. I'll drop the check. Thanks!