From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-178.mta0.migadu.com (out-178.mta0.migadu.com [91.218.175.178]) (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 9C5372C3745 for ; Tue, 23 Dec 2025 03:09:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766459367; cv=none; b=QGwJkYcrIqvfmf+1r1Dop0GjboLZL2oZId2nSCspFyX77ONpAyba5qJTwX4ffBcldxy4AcDw7URz4D+uwOTvonoGK+Py8edDqgWpJpAMvAWU51vD3IvFezWioiXV5JSwI/emUsN9ioV8LnNMzIVcAoX2BfrROsfdOk2/pbyi95c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766459367; c=relaxed/simple; bh=ytRpw626d2B1QzPR1Ew/pa6p2XN/8EY2MLoVtCzGaS0=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=szcsx/ZOPIIbTHyl69Vi0n8VButAEVvc4ACL3VhqoZqMSYCptq6vyA+ep7Tu0WhXEryrxb5OYSuW63XhrA6gxfj4OV9gZhJPdIdkPwJsqwrWs4m+tUYgOV0sRPCC84C9EmBloBLvhKHqVoRLqkDDRdz6MhUOdgtByVkTrl81Qms= 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=hhoQX0TE; arc=none smtp.client-ip=91.218.175.178 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="hhoQX0TE" 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=1766459361; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/ZcZnllijaalGMrElgL86g18d/eiz3nxCYnvfBLSc0k=; b=hhoQX0TEXgJB7rWiNxT4i3slue/uWm/NO9pe5bG3CNmAc0ky5okhCeylMjNbsQsyrHoOKr RL1mtMMGm+s9eMaPcA5K3dip3fHNMrQBh2A/DzL36Vq+yPsR01qj3It9eLJKUWV16nIGyN cWsokGNXndUoPM7ovLn8DOZv5bGjaZA= From: Roman Gushchin To: Alexei Starovoitov Cc: bpf , linux-mm , LKML , JP Kobryn , Alexei Starovoitov , Daniel Borkmann , Shakeel Butt , Michal Hocko , Johannes Weiner Subject: Re: [PATCH bpf-next v3 4/6] mm: introduce BPF kfuncs to access memcg statistics and events In-Reply-To: (Alexei Starovoitov's message of "Mon, 22 Dec 2025 16:11:19 -1000") References: <20251222221754.186191-1-roman.gushchin@linux.dev> <20251222221754.186191-5-roman.gushchin@linux.dev> Date: Mon, 22 Dec 2025 19:09:14 -0800 Message-ID: <87ms39c2sl.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; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Alexei Starovoitov writes: > On Mon, Dec 22, 2025 at 12:18=E2=80=AFPM Roman Gushchin > wrote: >> >> + if (idx < 0 || idx >=3D MEMCG_NR_STAT || !memcg_stat_item_valid(= idx)) >> + return (unsigned long)-1; > > memcg_stat_item_valid() and memcg_stat_item_valid() > helpers introduced specifically to be used in these kfuncs, > so I feel it's cleaner to do all idx checking within them > instead of splitting the checks like this. > Then it will be easier to see that > memcg_stat_item_valid(idx) access is in bounds when idx < MEMCG_NR_STAT > > Also I'd do one check like (u32)idx >=3D MEMCG_NR_STAT > and drop idx < 0 part. Compiler is probably smart enough to > optimize this way itself, but I'd still do one check. Sure, good point. Thanks for reviews!