From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 9A84D41B37D for ; Fri, 14 Aug 2026 07:51:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786693876; cv=none; b=ovTJKdugKexXpvDANg8amDFaNm9arh7GsaQuk1J6TITKqQRdOVNGSBFqxDmkYLH5nGxlnL4BKk8benNazTgB4X9ujVTxd6JdzMwxyXfaMNya38FBNy2UWZZbX1A7dHqREwl5lrwjopBg/VczkRbYQX9LGHnFZ7pdzfo+O/UAqpQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786693876; c=relaxed/simple; bh=vGb2AL0Q+YFnzB3UTu2+t3nWJA5Bw9JDxdRJVkur5KM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=J95n+d/jSfRff143LPCMbWzumN1ae5A1Lp7lg4rZrn36LmOXaC/1OJU9VaO/osQyDyR0FPkKkJqEfhxdctdLN+A/tBFgEM+BnbFKn0rUea30LX0qBT+GwOukTOXVF/I5nstyOJcIieYwvqC1WPLMEWMogCHcz1yAoc2yDmkhqnQ= 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=TUzUmNpO; arc=none smtp.client-ip=209.85.214.181 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="TUzUmNpO" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-2cace91f112so9334165ad.0 for ; Fri, 14 Aug 2026 00:51:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786693871; x=1787298671; darn=lists.linux.dev; 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=P7NJF3oq4Hw+2dLyF07fyfL2A6PD1tYu7/+/ryOQgrk=; b=TUzUmNpOMHcTlIx7i2AG8dCBcx5t8nwsGnBB8GnxWtxKEDtXxmOMpY27L3uIaye0dv kIF0F1oMcsF8snGthxY3hTbOLfohMKbB7jiBe8003gVYHh6MzyCiwUAjaeaLyBF3Q4fc DaWcDZiRccBX4hUDmx4jZWOG+5xfNsaoIR0uKFmtnol4QsnT7rD2dTwtkW6m3w5g/1V3 FmABAANipTIN8JNzuKmA3dQG6/Rf99GMdI4mhavabNP2ffgvUh5ltWXqbSD/dzu9S+Rd CBzNOO21V219/3idB+Y2neBWx8vVsYO8yS0/SIz9SBVWn5YyrSq3f7Zr+O1CiI42BS5/ ohdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786693871; x=1787298671; 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=P7NJF3oq4Hw+2dLyF07fyfL2A6PD1tYu7/+/ryOQgrk=; b=fjBpQD8VOW7JOfQLjGjaKr9uwIgI3BJfjdJo9RePPfN9c9BP3C7QCUuFqbmKjJo8H7 VUq5rE+t/HoXHSaeXKVTyFz4cBldOkD1atKzVTiMTHURArKeK/SEcixiNMz4blnCC9+N Y18fDk1/u2Km+5ZM3CpCWS9rKLGPwrjHM8AUDAYkQZvtf7ZUQVMnR0nMMasv/tUCfKbZ 5wz+XCTrJdzTxIMuGh9PdFlN9OaVS7T96lRpIncKhUF54tvMN4vN80YE9AKHCIYObHUH HgHlegc7DEHP4iUf5cy4k2tUULYRmc0s4GCSRhbbv9/bCycjE9k9i8ND9xy0bbUoEL5y QqRg== X-Forwarded-Encrypted: i=1; AHgh+RobfrbGE9XUm2cCN43rzYZE1AELzJXCmzw9Gw54+ArVfRO24Kq8Brq7nUXJqJnx+FSKQPyf@lists.linux.dev X-Gm-Message-State: AOJu0YzVO1Qu9hVirflOQAUGg5359BnWm9sWwyGhZx1s3nqNnNPg+7d5 uUjDznWr/LmkbAlWJC6ZzPAi+4Zi0YwVTq5PhJx8Ng5+7Lf3bWKj+mUygneSjnVL X-Gm-Gg: AR+sD10oJj5NQytAZKNx0MMhimM1f+2gwCbp2jnIMMnv1WJhtCgyQI3kzRCZBdumjPb SoacLVTd0mK0uZz6ZisvtvulFQPSD/iS7AnYxOD5Lttf0XLeHR7s6PxTvNE0gy1bXNTWPkwP4D4 aPaF08RKjZcH47ekvi01AxZpTB6H74lS8KI4jFemjMVjFgtIVRN+kYxj/bf6tiDE+H7yQN35gnF +4GGL1WD6qLhEqGwoVYipAO1ElQINFSuPMIRSNWip7LvyQk9RN2QjxM4bsJtO0ReQZsL64q/Fwd ZWTdSREdKZOuwZ3UT15gOGXWiklfmlXgimVMj9jK93oX5lRBvYUjJ9VDYekJcVNI1g6yoYwELms RA7JD+WuTDd0U4ocTCbSJFeIsyD+B0vscWDbOXV3HdYirzV5RYhGEGd+xPqPDFyzufUbK+xcp6O yb/rVicIs//GbCq+/u3b3N/z+bxCEX7WJnDXw6Fc7/kU+IH+R7mEplNUaRyHjOmi4uyR30Fc26z sCB9w== X-Received: by 2002:a05:6a20:748a:b0:3c3:a9e1:a819 with SMTP id adf61e73a8af0-3cc71fb5781mr4100219637.24.1786693870755; Fri, 14 Aug 2026 00:51:10 -0700 (PDT) Received: from localhost ([2a03:2880:9ff:68::]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-141387c6f95sm9201342c88.6.2026.08.14.00.51.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Aug 2026 00:51:10 -0700 (PDT) From: Ziyang Men To: Shuah Khan , Tejun Heo , Johannes Weiner , =?UTF-8?q?Michal=20Koutn=C3=BD?= , Jiri Kosina , Benjamin Tissoires , David Vernet , Eduard Zingerman Cc: Viktor Malik , Andrea Righi , Changwoo Min , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Andrew Morton , JP Kobryn , Mykola Lysenko , Nathan Chancellor , Ziyang Men , kernel-team@meta.com, linux-kselftest@vger.kernel.org, cgroups@vger.kernel.org, linux-input@vger.kernel.org, sched-ext@lists.linux.dev, linux-mm@kvack.org, bpf@vger.kernel.org, llvm@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v3 0/4] selftests: shared lib.bpf.mk for building BPF progs and skeletons Date: Fri, 14 Aug 2026 00:50:50 -0700 Message-ID: <20260814075054.507089-1-ziyang.meme@gmail.com> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: llvm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit This series re-factors the bpf-related toolchain for selftests, which currently duplicated across selftests/{bpf,sched_ext,hid}/. Unify them into a single includable fragment, the tools/testing/selftests/lib.bpf.mk, and wires up three consumers. We believe this will simplify the work for configuring selftests with the bpf, for both the existing and future ones. Patch 1 adds lib.bpf.mk mentioned above. Patch 2 adds a new selftest, selftests/cgroup/test_memcg_stat_cross_cpu, which checks the cgroup flush happens correctly by comparing the bpf read value matches the file reading. Existing test bpf/cgroup_iter_memcg only ensures whether the number is non-zero, which is trivial in some cases. Patches 3 and 4 replace the duplicated parts in selftests/{hid, sched_ext} with the lib.bpf.mk === Changes since v2: For shared Makefile: - The lib.bpf.mk now use the USERCFLAGS (and USERLDFLAGS) to extend the CFLAGS and LDFLAGS. - OPT_FLAGS/RELEASE and EXTRA_CFLAGS now reach the libbpf and bpftool sub-makes as well. - One rule per BPF source instead of a vpath, which is global and also applied to the caller's own %.c rules. - HOSTCC/HOSTLD come from lib.mk instead of including Makefile.include, which also rewrote the caller's AR, LD and CFLAGS. - A missing vmlinux is reported by the recipe rather than at parse time, so "make clean" still works without BTF. For cgroup selftest: - Only one cgroup tree is created, one flush is performed, follows by bpf read and file read. - More common cgroup functions e.g., cg_read_key_long() and value_close(), are used in the selftests. - Use cpu_set_t rather than manually allocated cpu lists. - Use test_memcontrol.c's anon allocator and moving it into cgroup_util. - Other suggestion from the review. Others: - Bot reviews are fixed. === Changes since v1: - Generalized lib.bpf.mk (source layout/suffix, extra hdrs/cflags, skeleton suffix, subskeletons, configurable output dirs) so it can serve hid and sched_ext, not just cgroup. - Added patch 3 (hid) and patch 4 (sched_ext), converting those folders to the shared fragment. Ziyang Men (4): selftests: add shared lib.bpf.mk to build BPF progs and skeletons selftests/cgroup: add memcg_stat_cross_cpu correctness test for flush selftests/hid: build the BPF program via the shared lib.bpf.mk selftests/sched_ext: build BPF schedulers via the shared lib.bpf.mk tools/testing/selftests/cgroup/.gitignore | 8 + tools/testing/selftests/cgroup/Makefile | 52 ++ tools/testing/selftests/cgroup/config | 5 + .../selftests/cgroup/lib/cgroup_util.c | 83 +++ .../cgroup/lib/include/cgroup_util.h | 3 + .../cgroup/memcg_stat_cross_cpu.bpf.c | 86 +++ .../selftests/cgroup/memcg_stat_cross_cpu.h | 21 + .../cgroup/test_memcg_stat_cross_cpu.c | 596 ++++++++++++++++++ .../selftests/cgroup/test_memcontrol.c | 29 +- tools/testing/selftests/hid/.gitignore | 1 + tools/testing/selftests/hid/Makefile | 180 +----- tools/testing/selftests/lib.bpf.mk | 296 +++++++++ tools/testing/selftests/sched_ext/Makefile | 146 +---- 13 files changed, 1204 insertions(+), 302 deletions(-) create mode 100644 tools/testing/selftests/cgroup/memcg_stat_cross_cpu.bpf.c create mode 100644 tools/testing/selftests/cgroup/memcg_stat_cross_cpu.h create mode 100644 tools/testing/selftests/cgroup/test_memcg_stat_cross_cpu.c create mode 100644 tools/testing/selftests/lib.bpf.mk -- 2.53.0-Meta