From nobody Thu Sep 24 12:06:07 2026 Received: from mail-pz2-f41.google.com (mail-pz2-f41.google.com [74.125.228.41]) (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 EE30F47604A for ; Thu, 24 Sep 2026 10:23:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.228.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790245416; cv=none; b=jyCFcvnYvKZpTXdk513xYNseczBs/05JxB5fV73uyxxMs9mNqKtwggg3/P0maHeOQ5Iqz17o5Mct9HMYoW4b/6obsdO+/iv1OEEs8Z3f8peSMHkbzz2wNWiqHi+HhP4unwd5pRhmcOBFXRN8WbSdSJSC6hVyKJvMrqrGBtN1+S8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790245416; c=relaxed/simple; bh=+nouV9zt7W78M6dmzDdd5dBqebiYPUKmIdR5QPLIlO4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LpgjPvHXmQ/UJl01c6G+9r7wUjoSsyuC1uq2ADnvLPY7YjC/V/wPlWouLYLbmjECBM/HDmay0yTOm+UbvtV79VFaBK5sCo/KIrvXbjoEHKxrFkKradMOR0CrTU4iEU+QTazqtJQ9Es6VmueJs0iM2xKOhAwADg5W4U/kopZcgG4= 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=YLXjTmfi; arc=none smtp.client-ip=74.125.228.41 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="YLXjTmfi" Received: by mail-pz2-f41.google.com with SMTP id 41be03b00d2f7-cc1cea4bfb6so610514a12.3 for ; Thu, 24 Sep 2026 03:23:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1790245413; x=1790850213; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=aYSc8z6uUhpoN5DPnRJYqvNeo+ZWN39hf5KrJMSzHAo=; b=YLXjTmfipOU1YvEV2kGztDWFzvx/DUB0Q6CzG34A+HILvW82XH3JxrpdWLvJYyIqt/ dQW1gs4cXnYIldLc5l5YJqgJjs1M/xVTRAomP55RAtO3iF7cIoEzZlfeXmrNFaakKkeW pLrrv+uTsKnkIF6t4I0FsuCY3B8pOCZGYkRqc0WVOMCI0WPG+jwE3KZwyir0rzTubLY/ Wsb2VZOLCwYHUFuyyV1dDAcxZmTE4GIGtcApWOfASs2grSCljusbi4feMlshPKdXzHYf YjE9ZEADYZhxoP7iEc0Jno94Tj4HICQ38fGDlpSK7g/7IPYv3FIA+iWmFPCdIWWoI4gk SAdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790245413; x=1790850213; h=content-transfer-encoding:mime-version:references:in-reply-to :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=aYSc8z6uUhpoN5DPnRJYqvNeo+ZWN39hf5KrJMSzHAo=; b=d5GL3Rwm2eOEjRN1KCHeqqG0vs/qN6DWz7fn1osMO2jjMHXzRbcUn7FCFomG8eGS+D mBD/hdV1/BblfkCejEal6i+LaodQhJmJsZvMQ44Z6qyQfHqHHwSiq3hGWSpHEr42kXNK ZlRP4QVpwns5+sq+cxG523l7DUltNcV6K4fml/Tz5dHNWxIlKshsbeZBBj9p7WDxd6Tn D5YEcHwzT4xW9JkwvIow3S0+4Z4G78TWPjA8bxsEU8V4+5l73/sK8Z13dRGcfowP1cGx uHMo1c/+BQb7S992axefVRXNJueSF/VwRJlBYWTVqmrrClcWaPi8zyHqb+a+nFQkQ3yg qmNQ== X-Forwarded-Encrypted: i=1; AKwUvBx3yPmExv6VDh+6HT2jRAMUczWVrWw/i4sFFfct9qjrgq12YN+Hs5nco6ccbMP6NMiESYMY219qVoSp38Y=@vger.kernel.org X-Gm-Message-State: AFuF++maNo8hFTIbOQ8OIRMT8OltUqJOiFAU+4uTx+3S053hnyOYTzX2 K6PSbX1y9rbwrBFgYMXgu7XvcSJVjlJTsN+O7DpAfon/PW7wHCA6BT8= X-Gm-Gg: AYBFou0nCgZAfW0f8vauchNb4XsVPrA1t4OVGdhvdy0VeUWqlRylCvngOKBz/qwoKQN p/yZ9KBzJb1SUcAX5tPyMAQrA9VV0ixrLWfgTmWaX5f6O/FXKq8PTlZ3lSw02M3d4zJPBcN2cEH C6Ea5tlQg5wQ6fX1C303/g5V29jO6L3Ew0ypUTgxJlOJsW8pRITcQKxUAefMfVZNPeiSyYbXHOv BDBkD9M+opyU3S+PuNh5OMLcVbYg033KROxkUIw4dBUZLSYAxaXg1vc/67XZ58ondBGjcx0QjOa oSTstkUvaRTP7Dh9LBUtogFapSBVcjOei2L3ZX3yGzn2QkT+hVRKOfoh/FCSIc6CJIrgE29zh0C rHGIhviOOdl/fP12yye5nbRT5EOrSfo7AwPXY6aENWB5oliXRovdvaRCFk4PRqn3ncYqoroXFvU c8DiGHq4CuzOrTvb3hb2TGi+MKP2BJcVu6LLM5e80MKJTM8Cu7R07z8djYFAdsgIC5hB+ZKMH64 aFDpb8juzO4RZ8E0L52SNRa X-Received: by 2002:a05:6a21:a45:b0:3dd:a196:30a0 with SMTP id adf61e73a8af0-3de0e9a08b3mr2035615637.80.1790245413127; Thu, 24 Sep 2026 03:23:33 -0700 (PDT) Received: from ydg-Zenbook-14-UM3406GA ([211.230.25.193]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-87d1afb9416sm2661582b3a.7.2026.09.24.03.23.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Sep 2026 03:23:32 -0700 (PDT) From: Donggeun Yoo To: bpf@vger.kernel.org Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, eddyz87@gmail.com, memxor@gmail.com, martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev, jolsa@kernel.org, emil@etsalapatis.com, ihor.solodrai@linux.dev, leon.hwang@linux.dev, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, donggeunyoo.kernel@gmail.com Subject: [PATCH bpf v3 1/2] bpf: Zero-fill other CPUs when BPF_F_CPU creates a per-cpu hash element Date: Thu, 24 Sep 2026 19:23:20 +0900 Message-ID: <20260924102321.2120434-2-donggeunyoo.kernel@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260924102321.2120434-1-donggeunyoo.kernel@gmail.com> References: <20260924102321.2120434-1-donggeunyoo.kernel@gmail.com> 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 Content-Type: text/plain; charset="utf-8" pcpu_init_value() initializes the per-cpu area of a newly created [lru_]percpu_hash element. The area is recycled, so when the value comes from a BPF program (onallcpus =3D=3D false) it writes the running CPU's slot and zeroes the rest. bpf_percpu_hash_update() passes onallcpus =3D=3D true, which delegates to pcpu_copy_value(). pcpu_copy_value() writes only the CPU named in map_flags when BPF_F_CPU is set, so on the create path the other slots keep the recycled element's values: update(k1, 0xdeadc0de, BPF_F_ALL_CPUS) every CPU holds 0xdeadc0de delete(k1) element back on the freelist update(k2, 0xc0ffee, BPF_F_CPU | 0) creates, writes CPU 0 only lookup(k2) CPU 0 0xc0ffee, rest 0xdeadc0de Zero-fill the other CPUs on that arm too. Fixes: c6936161fd55 ("bpf: Add BPF_F_CPU and BPF_F_ALL_CPUS flags support f= or percpu_hash and lru_percpu_hash maps") Signed-off-by: Donggeun Yoo --- kernel/bpf/hashtab.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/kernel/bpf/hashtab.c b/kernel/bpf/hashtab.c index 4f495dcbf670c..f9464e566f109 100644 --- a/kernel/bpf/hashtab.c +++ b/kernel/bpf/hashtab.c @@ -1054,14 +1054,17 @@ static void pcpu_init_value(struct bpf_htab *htab, = void __percpu *pptr, /* When not setting the initial value on all cpus, zero-fill element * values for other cpus. Otherwise, bpf program has no way to ensure * known initial values for cpus other than current one - * (onallcpus=3Dfalse always when coming from bpf prog). + * (onallcpus=3Dfalse always when coming from bpf prog, + * map_flags & BPF_F_CPU when coming from syscall but setting + * only one cpu). */ - if (!onallcpus) { - int current_cpu =3D raw_smp_processor_id(); + if (!onallcpus || (map_flags & BPF_F_CPU)) { + int init_cpu =3D (map_flags & BPF_F_CPU) ? map_flags >> 32 : + raw_smp_processor_id(); int cpu; =20 for_each_possible_cpu(cpu) { - if (cpu =3D=3D current_cpu) + if (cpu =3D=3D init_cpu) copy_map_value(&htab->map, per_cpu_ptr(pptr, cpu), value); else /* Since elem is preallocated, we cannot touch special fields */ zero_map_value(&htab->map, per_cpu_ptr(pptr, cpu)); --=20 2.53.0 From nobody Thu Sep 24 12:06:07 2026 Received: from mail-pz2-f39.google.com (mail-pz2-f39.google.com [74.125.228.39]) (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 1258F48642F for ; Thu, 24 Sep 2026 10:23:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.228.39 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790245419; cv=none; b=GqQrd5RNKot1ci3dfeRwGAObj0B/or1o0XH/fdrhy3N6R+76lzvu3F4w2f38LUC+jHP7f0NkrDbs53E01HmystzmC036Y0c5GdfigVd924DPQn2i1NoF5QlQPus4tC27VKZJI7+JIGywSIDxBd04i14h9GnY9XrETVRyEjYM5gw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790245419; c=relaxed/simple; bh=6YX6h+lVa19ibUpshe0Fzrnf6t9VpTENK7zNCAt5Y1I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Zm7t/ivbLZV2jo3GNoSKWBD7GU4mBpeXAuDF6SxzEilww05eF1tM33lAA+ZYqViNUFbpw7Npf5z7PpqCO1HQ46CzxTjrX5pT40rq6thQayj6A4/HHP22VaPJwmwZ/5nZUK/Zc3Zp78QfRCTfLX7oEbeG3fjOkouCyWSNoQ5C4tU= 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=PDHCprvY; arc=none smtp.client-ip=74.125.228.39 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="PDHCprvY" Received: by mail-pz2-f39.google.com with SMTP id 41be03b00d2f7-cc515bef69dso896568a12.2 for ; Thu, 24 Sep 2026 03:23:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1790245417; x=1790850217; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=bfDHIscfZIaZ+G0e6fi+cyup/qsdiCf7G7ZWGqivqVU=; b=PDHCprvYMNfTvELc1uQm6aZk2TJdVYVP1Q6fq/5zJ0MPffMZI21DAHw7PHhYeP669u PA7R52RIOIe7p9evRblMmpsDCVHgBgH37/xhGtH+pNJe37mM4Mze4H5Mag2xC1Z1RlEz hn8KTVUWu0iK5Vvgt/6Oqf5Ut6qpQ6+MZxG2YENNXU4iFJJX24Xh+wFGImnVbBd6SgjI 1MrGHTCG2Mj0ARHXuMZ/2ZFHeEpruBFmfe62QlqKcLSzsW7tGvR66mSH8UYWm1ri64JP 25Tw9+z8FHZH/M5Q12Z00A5rYsEOd1PfkASy+ldswo0JxD6YDRjY35ba6olFxQqezZIn Pyig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790245417; x=1790850217; h=content-transfer-encoding:mime-version:references:in-reply-to :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=bfDHIscfZIaZ+G0e6fi+cyup/qsdiCf7G7ZWGqivqVU=; b=ASVF/Pem6X1IJzrrTxAz9tAyvCSbOzKm4+6LfmmSWmcVYfXFCv47wYr3cRUMLz540i MJF9NDD1grGVGeXFRFd1lU4kxu1OfxZa9/8J29U2LrLnTMSAzYzBo/tTN6JEg3rUiQVG h3P8oEQ7d0vwvBb6FdjH3LDUVw0MzU9YJUVnxWGPVHMsb+vmlhfKDxAZpLctMn2qC8GX NnI5yMdZal2O6ScrsrwAqcLAdWnqkwczhRTjLd1fo0E7yPqIG4F5+2EfskwRMWpS2z2v fI5q2k2rKUQWcN0faPreLSqg+3Kbd6+d7nEGO84y7exYrVM76xbNw6LhrP3b6UueGeZy DeXg== X-Forwarded-Encrypted: i=1; AKwUvByycuDd5f4QpfL9hWAUSgBqZB8f5PKPk3lJT4Fkm7Fzc6Uf7qbU5fgauF9sYHaZcQtw4X6cJ+DXKqUqyXI=@vger.kernel.org X-Gm-Message-State: AFuF++nOP7FFRqRKzyY1MS9p4E+mSYVn/ngKzWIT/yX2e+AYbBhHDrV5 CCIflYJbGhwtBAsBMJfu7Ya+gnGKD6AoDTkLEnNyhNIntouA9xEZ8wU= X-Gm-Gg: AYBFou3RF3TeuB3Ru8yEnm+1QNT8rhCWKoLja91p3UJ37zXoDkGooTuGJpFin09Jf3Z J/c6IaK6e9qw35kyYEf7F/LpUMYLfcFiECMJuAfYFNMcKoAj6RMhx/6B9sWO8JvYnZGwPgflxZv 9yTO6eq6N/SvvKmy53EnRWfTCx6VDtl8GdfBzIZDHc9UPpZH1DJq3aZRS1D5NlESzlPndAPWYMI 4p7g6gNK4wKIl5H0SgJUUgrHYkXo1t/HhtwxQcKnqEmSPE6YXRCvesOw7raIHhm5se6VUyoGGUs CIRsk4WcOgYPDD/iCgxjLPU+RaV8SJujewWEQcENpnaXOgBIKdDxmexbhTEeoT6kRHcsP491Pxo TwOVPGZ0E+rSyOcVhgdFZobQoinlFhNd748ppek7NI35hcfvhObg8yteawLTCBqpDfReurxbSwO 0N/GoLMvdd7kU1o1y4trpH4ntMgDp6GUZKUuC35y33BoxLYvlhwZFdGy5Sxk1V7jQ4bIGYyDyNU PgtlPe09+xzwyqhineM4o9D X-Received: by 2002:a05:6a20:4394:b0:3dd:85aa:d26d with SMTP id adf61e73a8af0-3de0e7f4a52mr1881230637.37.1790245417278; Thu, 24 Sep 2026 03:23:37 -0700 (PDT) Received: from ydg-Zenbook-14-UM3406GA ([211.230.25.193]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-87d1afb9416sm2661582b3a.7.2026.09.24.03.23.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Sep 2026 03:23:37 -0700 (PDT) From: Donggeun Yoo To: bpf@vger.kernel.org Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, eddyz87@gmail.com, memxor@gmail.com, martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev, jolsa@kernel.org, emil@etsalapatis.com, ihor.solodrai@linux.dev, leon.hwang@linux.dev, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, donggeunyoo.kernel@gmail.com Subject: [PATCH bpf v3 2/2] selftests/bpf: Test per-cpu initialization of a BPF_F_CPU created element Date: Thu, 24 Sep 2026 19:23:21 +0900 Message-ID: <20260924102321.2120434-3-donggeunyoo.kernel@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260924102321.2120434-1-donggeunyoo.kernel@gmail.com> References: <20260924102321.2120434-1-donggeunyoo.kernel@gmail.com> 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 Content-Type: text/plain; charset="utf-8" The existing cpu_flag subtests always prime a key with BPF_F_ALL_CPUS before any BPF_F_CPU write, so the create path is never covered. Add a subtest that creates the element with BPF_F_CPU on a map with max_entries 1, so the key can only reuse the element the previous key released, and check that the CPUs the update did not name read back zero. Run it for PERCPU_HASH preallocated and BPF_F_NO_PREALLOC, whose per-cpu areas come from different allocators, and for LRU_PERCPU_HASH. Under BPF_F_NO_PREALLOC the reuse is only guaranteed on the cpu that ran the delete, so pin the thread across the pair, and name a cpu other than that one in map_flags. Signed-off-by: Donggeun Yoo --- .../selftests/bpf/prog_tests/percpu_alloc.c | 105 ++++++++++++++++++ 1 file changed, 105 insertions(+) diff --git a/tools/testing/selftests/bpf/prog_tests/percpu_alloc.c b/tools/= testing/selftests/bpf/prog_tests/percpu_alloc.c index a72ae0b29f6e9..7b4a1e24363b5 100644 --- a/tools/testing/selftests/bpf/prog_tests/percpu_alloc.c +++ b/tools/testing/selftests/bpf/prog_tests/percpu_alloc.c @@ -1,4 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 +#define _GNU_SOURCE +#include #include #include "cgroup_helpers.h" #include "percpu_alloc_array.skel.h" @@ -350,6 +352,103 @@ static void test_lru_percpu_hash_cpu_flag(void) test_percpu_map_cpu_flag(BPF_MAP_TYPE_LRU_PERCPU_HASH); } =20 +/* + * A BPF_F_CPU update that creates an element must zero the value on the o= ther + * cpus, rather than leave them holding whatever the recycled element last + * contained. max_entries is 1 so the second key can only reuse the element + * the first one released. + */ +static void test_percpu_map_cpu_flag_create(enum bpf_map_type map_type, __= u32 map_flags) +{ + LIBBPF_OPTS(bpf_map_create_opts, opts, .map_flags =3D map_flags); + const u32 stale =3D 0xDEADC0DE, fresh =3D 0xC0FFEE; + int nr_cpus, cpu, map_fd, err, key; + int pinned_cpu, value_cpu; + cpu_set_t old_mask, new_mask; + bool restore_mask =3D false; + u32 value; + u64 flags; + + nr_cpus =3D libbpf_num_possible_cpus(); + if (!ASSERT_GT(nr_cpus, 0, "libbpf_num_possible_cpus")) + return; + + if (nr_cpus < 2) { + test__skip(); + return; + } + + map_fd =3D bpf_map_create(map_type, "cpu_flag_create", sizeof(key), sizeo= f(value), 1, &opts); + if (!ASSERT_GE(map_fd, 0, "bpf_map_create")) + return; + + /* NO_PREALLOC recycles per cpu, so keep the delete and the create on one= cpu. */ + err =3D sched_getaffinity(0, sizeof(old_mask), &old_mask); + if (!ASSERT_OK(err, "sched_getaffinity")) + goto out; + + pinned_cpu =3D sched_getcpu(); + if (!ASSERT_GE(pinned_cpu, 0, "sched_getcpu")) + goto out; + + CPU_ZERO(&new_mask); + CPU_SET(pinned_cpu, &new_mask); + err =3D sched_setaffinity(0, sizeof(new_mask), &new_mask); + if (!ASSERT_OK(err, "sched_setaffinity")) + goto out; + restore_mask =3D true; + + value_cpu =3D pinned_cpu ? 0 : 1; + + key =3D 1; + value =3D stale; + err =3D bpf_map_update_elem(map_fd, &key, &value, BPF_F_ALL_CPUS); + if (!ASSERT_OK(err, "bpf_map_update_elem all_cpus")) + goto out; + + err =3D bpf_map_delete_elem(map_fd, &key); + if (!ASSERT_OK(err, "bpf_map_delete_elem")) + goto out; + + key =3D 2; + value =3D fresh; + flags =3D (u64)value_cpu << 32 | BPF_F_CPU; + err =3D bpf_map_update_elem(map_fd, &key, &value, flags); + if (!ASSERT_OK(err, "bpf_map_update_elem specified cpu")) + goto out; + + for (cpu =3D 0; cpu < nr_cpus; cpu++) { + value =3D 0; + flags =3D (u64)cpu << 32 | BPF_F_CPU; + err =3D bpf_map_lookup_elem_flags(map_fd, &key, &value, flags); + if (!ASSERT_OK(err, "bpf_map_lookup_elem_flags specified cpu")) + goto out; + if (!ASSERT_EQ(value, cpu =3D=3D value_cpu ? fresh : 0, "value on specif= ied cpu")) + goto out; + } + +out: + if (restore_mask) + sched_setaffinity(0, sizeof(old_mask), &old_mask); + close(map_fd); +} + +static void test_percpu_hash_cpu_flag_create(void) +{ + test_percpu_map_cpu_flag_create(BPF_MAP_TYPE_PERCPU_HASH, 0); +} + +static void test_percpu_hash_cpu_flag_create_malloc(void) +{ + test_percpu_map_cpu_flag_create(BPF_MAP_TYPE_PERCPU_HASH, BPF_F_NO_PREALL= OC); +} + +static void test_lru_percpu_hash_cpu_flag_create(void) +{ + /* lru without prealloc is -ENOTSUPP, so there is no malloc variant */ + test_percpu_map_cpu_flag_create(BPF_MAP_TYPE_LRU_PERCPU_HASH, 0); +} + static void test_percpu_cgroup_storage_cpu_flag(void) { struct percpu_alloc_array *skel =3D NULL; @@ -454,6 +553,12 @@ void test_percpu_alloc(void) test_percpu_hash_cpu_flag(); if (test__start_subtest("cpu_flag_lru_percpu_hash")) test_lru_percpu_hash_cpu_flag(); + if (test__start_subtest("cpu_flag_create_percpu_hash")) + test_percpu_hash_cpu_flag_create(); + if (test__start_subtest("cpu_flag_create_percpu_hash_malloc")) + test_percpu_hash_cpu_flag_create_malloc(); + if (test__start_subtest("cpu_flag_create_lru_percpu_hash")) + test_lru_percpu_hash_cpu_flag_create(); if (test__start_subtest("cpu_flag_percpu_cgroup_storage")) test_percpu_cgroup_storage_cpu_flag(); if (test__start_subtest("cpu_flag_array")) --=20 2.53.0