From patchwork Wed Mar 5 21:12:33 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Tsalapatis X-Patchwork-Id: 14003379 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-qt1-f172.google.com (mail-qt1-f172.google.com [209.85.160.172]) (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 D041416426 for ; Wed, 5 Mar 2025 21:12:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741209167; cv=none; b=DQgBFlBJob3Xa2BIJhVxvNkw0nXJuiV/gcTY5oGRw9yQHdWaVQjWKeU5xQv2A66+e+3d/DvY9ckiEQR+8uql6q2z/1GIedPRenmu7rPxBvNPq7CpjRdYgcwPSFtnGn5mOnizvfiYeYxip+X6DNf4HwfPTm4M1lSOf8EgraR5aIk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741209167; c=relaxed/simple; bh=C21DKof42ArviOdYqXGiNPXIkzx61D5SRrwmr5MsZRk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nCbC5R8nZRpwTwCYeNknIslZdCX3xdPZ8P4xw9i0evD1KwCZTuyhGOBJL1aE3VkXar5b5PKGQpR26RMhMMMkhVDahDZkqWqCK746IvivVBDDeb19BCZgmJiS6ST6++nEBx/ncmHKWXb3zeTQklJtd2rYjmokL21qcBST/B08KMA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=etsalapatis.com; spf=pass smtp.mailfrom=etsalapatis.com; dkim=pass (2048-bit key) header.d=etsalapatis-com.20230601.gappssmtp.com header.i=@etsalapatis-com.20230601.gappssmtp.com header.b=Qpj8V9Jy; arc=none smtp.client-ip=209.85.160.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=etsalapatis.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=etsalapatis.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=etsalapatis-com.20230601.gappssmtp.com header.i=@etsalapatis-com.20230601.gappssmtp.com header.b="Qpj8V9Jy" Received: by mail-qt1-f172.google.com with SMTP id d75a77b69052e-4721325e3b5so61564641cf.0 for ; Wed, 05 Mar 2025 13:12:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=etsalapatis-com.20230601.gappssmtp.com; s=20230601; t=1741209164; x=1741813964; 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; bh=w2Yn1YOUIiLwYiCIsvkK6BnPw5MMb4a3IXIPOWbODOg=; b=Qpj8V9JyIqQly4XFJ2SPuTIJ22LK91W3AkvWmWquFDAec4qcXZPHgG1iMqhjiFmWxr nmBhTw0QEyY2SsRAzaR/FKsT84GKo5jXKKSEDPiLMQP/NlIgYJy4ttnk2PoYyiqUr8g8 Q6ouPNisPj2iLKbSDdmP/JCs9T1NcYw+i5zEF1LkUllV2dYGxSSQdBDqnxANv5FA8jJd 0Sq3GfsYimVGQh8bFwhBTYTREfWZgdFVW8u0pJNCo3mIJ6dOrALAdiq412lCXmtLcv0L 1OsHhzocqwF122OxhFXBw+oU9soigya2DUS1YJ756XfMZX5xApChb3TFwqRjfGGPVuvM A4Bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741209164; x=1741813964; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=w2Yn1YOUIiLwYiCIsvkK6BnPw5MMb4a3IXIPOWbODOg=; b=JSQynDGL1jE3I4Pej5I2JmtLiSO+CxEzDQVsRpDhz2TeuEhSyE/Dwy1ICD9eqT09/C cGo6JHtYJHgzOynK0OK+s1zxGKKZvsjZUnTkVn9+Brqei4C8k2ALiRDx3es5Th0RyAES Fpc04nL8rN3FTSl+JLZw2Hl03NpkCjHD5tQDUgeMo8SB91cykl2G1pbC1eEX/pM8PnvL ZwxiEl17/HufSzrkdYjTdRsvGHXVkLhUDGK2jS6si6zuUJ89jJ1IddXl44SSbKkfhGy6 LYoGgzDfQSE2pjCraBhpGlhAIWL/Yct2rTdC4jJ3xduzvBHXmskOnK1ZYrBFnpT+Nbwq xk4A== X-Gm-Message-State: AOJu0YxOgznhu8NJ+L3kqHiECSnsb7oR0tDvpUTRi9btc7P/A8DNsWKf 3jSvINMJLyItD7HZpIMezIQ18svy371bzFjlArV+wQhZxlS/YC0sjvTfI/1rdr1fKsE4rPlYZR9 zSqGu7A== X-Gm-Gg: ASbGncsxhaCHrij4YrPkP/DEgeiu7zLQ4m0/R3BOv9l8ZUNIgNAvIes5lvmvxCDkI7r KX22F9D6a6V4YDGTeBS/USj09P0YJIFsgJgA1Mj9Jn6WkDYA/yIT1D+KtZHLTn2SZsahl10vVrb F0DgaLIokID79L0kxFEofD06kIKZMx9PeLyxdffu83wx1mAW9mbTMYWS2N0wSUiSWvNg0u2EGrS UG8ubVmMNhGUB3cctn4xrwG2wiMj5paw8rmCDUoVuMHTSOsBygfYTG28n63HdvS/5eh55rm52z0 n+0jMC8kv82zDagml4NbMHAdxxwl+bXYwqZcOX4viQ== X-Google-Smtp-Source: AGHT+IGKRIOhQCq0Fez4x5h9Jdis92n8d9c32gwmEN2lm7qZy8vVLNqsNWrOad7TjavSdmpzPlKqrQ== X-Received: by 2002:ac8:5f46:0:b0:472:1399:2da7 with SMTP id d75a77b69052e-4750b448137mr65100311cf.17.1741209164515; Wed, 05 Mar 2025 13:12:44 -0800 (PST) Received: from boreas.. ([140.174.215.88]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-474eced9880sm43726851cf.17.2025.03.05.13.12.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Mar 2025 13:12:44 -0800 (PST) From: Emil Tsalapatis To: bpf@vger.kernel.org Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, yonghong.song@linux.dev, tj@kernel.org, memxor@gmail.com, houtao@huaweicloud.com, Emil Tsalapatis Subject: [PATCH v4 1/3] bpf: add kfunc for populating cpumask bits Date: Wed, 5 Mar 2025 16:12:33 -0500 Message-ID: <20250305211235.368399-2-emil@etsalapatis.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250305211235.368399-1-emil@etsalapatis.com> References: <20250305211235.368399-1-emil@etsalapatis.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net Add a helper kfunc that sets the bitmap of a bpf_cpumask from BPF memory. Signed-off-by: Emil Tsalapatis (Meta) Acked-by: Hou Tao --- kernel/bpf/cpumask.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/kernel/bpf/cpumask.c b/kernel/bpf/cpumask.c index cfa1c18e3a48..14080ca694b0 100644 --- a/kernel/bpf/cpumask.c +++ b/kernel/bpf/cpumask.c @@ -420,6 +420,38 @@ __bpf_kfunc u32 bpf_cpumask_weight(const struct cpumask *cpumask) return cpumask_weight(cpumask); } +/** + * bpf_cpumask_populate() - Populate the CPU mask from the contents of + * a BPF memory region. + * + * @cpumask: The cpumask being populated. + * @src: The BPF memory holding the bit pattern. + * @src__sz: Length of the BPF memory region in bytes. + * + * Return: + * * 0 if the struct cpumask * instance was populated successfully. + * * -EACCES if the memory region is too small to populate the cpumask. + * * -EINVAL if the memory region is not aligned to the size of a long + * and the architecture does not support efficient unaligned accesses. + */ +__bpf_kfunc int bpf_cpumask_populate(struct cpumask *cpumask, void *src, size_t src__sz) +{ + unsigned long source = (unsigned long)src; + + /* The memory region must be large enough to populate the entire CPU mask. */ + if (src__sz < bitmap_size(nr_cpu_ids)) + return -EACCES; + + /* If avoiding unaligned accesses, the input region must be aligned to the nearest long. */ + if (!IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && + !IS_ALIGNED(source, sizeof(long))) + return -EINVAL; + + bitmap_copy(cpumask_bits(cpumask), src, nr_cpu_ids); + + return 0; +} + __bpf_kfunc_end_defs(); BTF_KFUNCS_START(cpumask_kfunc_btf_ids) @@ -448,6 +480,7 @@ BTF_ID_FLAGS(func, bpf_cpumask_copy, KF_RCU) BTF_ID_FLAGS(func, bpf_cpumask_any_distribute, KF_RCU) BTF_ID_FLAGS(func, bpf_cpumask_any_and_distribute, KF_RCU) BTF_ID_FLAGS(func, bpf_cpumask_weight, KF_RCU) +BTF_ID_FLAGS(func, bpf_cpumask_populate, KF_RCU) BTF_KFUNCS_END(cpumask_kfunc_btf_ids) static const struct btf_kfunc_id_set cpumask_kfunc_set = { From patchwork Wed Mar 5 21:12:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Tsalapatis X-Patchwork-Id: 14003381 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-qt1-f173.google.com (mail-qt1-f173.google.com [209.85.160.173]) (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 82F9D1FC0F3 for ; Wed, 5 Mar 2025 21:12:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741209168; cv=none; b=kNT+6LFXYJa8ebf/pi678TTbIl5ThAumhoBoLdBL/YJ20MRDObpOPqeYjL1DUPyV0+wx3lfRSzxyaGc+B7NVffzGhkaLCuBQB9S/eWkvvevoZgHqYwzhdSyAsvCC49n9pnFIUGHd+CfpbbcTw0RPGaUfVomhaT2CYsGvQ3HQXWk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741209168; c=relaxed/simple; bh=Q+M7ITeliy4I1QVtUflC9vsSCW+e19xHlw6fwckMuPE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MqXVojq5OfVwc4FruO3ZLnvJdO2r6vQga17bX9QfJ2A3lW4gnxkUHiRM6xxchUw0SPzaa3qGVuC11/uDYn4RdqpVprf4X8ZwRBUkk5QU2FEUtcuGB+PHTmfJuHlMU6IcL+pwmmsXDUSvXqJQhMdxQJhqmfbWZ8AyOgRazbQlPOM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=etsalapatis.com; spf=pass smtp.mailfrom=etsalapatis.com; dkim=pass (2048-bit key) header.d=etsalapatis-com.20230601.gappssmtp.com header.i=@etsalapatis-com.20230601.gappssmtp.com header.b=NUMv7UA+; arc=none smtp.client-ip=209.85.160.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=etsalapatis.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=etsalapatis.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=etsalapatis-com.20230601.gappssmtp.com header.i=@etsalapatis-com.20230601.gappssmtp.com header.b="NUMv7UA+" Received: by mail-qt1-f173.google.com with SMTP id d75a77b69052e-471fe5e0a80so65282021cf.1 for ; Wed, 05 Mar 2025 13:12:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=etsalapatis-com.20230601.gappssmtp.com; s=20230601; t=1741209165; x=1741813965; 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; bh=ptvDvINcrJ+IHiQEaD0ERRof30Fe7KxAOaVsuQI4KFQ=; b=NUMv7UA+xcSyM40O5bb3CsLUrToa6SlAmgdeVwZUKz1iW+2T19WWHC4mk3DsjOjT2V NDYRbBCpE9Qu8qgQKD6Zk1+2iBmPtzBsFDRWKS6vNA19Rylnq93wHF2dmU5QGvH5+19P 2mXrwzWyaZ6CDnExZECzuTZv0+ohqB6iFCK3dw7F5HzoHXpfwO+reIgboAZlyLBVTgQZ gjjI9CCFFsLfHu4RT703B48i+OCoIaKLa3IJgxobEDoqsGKVvasjq8/KXmTJpYoivjYq 220WiT/6MbUPuvc3yPHWUpjuaBcp1WwRhDs/+kmQjqcKtNzynIxJaVBdk0gliC00D/Af iILA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741209165; x=1741813965; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ptvDvINcrJ+IHiQEaD0ERRof30Fe7KxAOaVsuQI4KFQ=; b=bvKL2UNa8Z2KK2QCqkkooB56idzXKbvAikh4nX8vdpiaSBJne/li/pFX5xThBbT/8T Ly7PI/X97rHz0AS95LnG1uEYi7Q0KGvIDFBmNyET2zvTYX9IkrvpDTjSJ8Rnq3QJ7I/O 4le6xblS9My8rHDlJsiZLcQup/Nn/uBDROujQ8Uj5O+DMe4Ebppu6nRibNAq1fzyEcgK vpcUmTFdM5iYGvWzMjqO12PrzslOTuybnivqcy6mkOUSE2QhrliUcbx0f989QXFksZsd lLJuwg+twTBofL1iDvw0G3J3m9FvbPbHIEQEeI6nvy8zOmAdsuGqktcrS0okN/zowG/w FG5w== X-Gm-Message-State: AOJu0YynZ/4f9KMxt7RASFZh7CzlSk3UYO2YQD2m+L3xTtAPipk7teoh 4Z6AXuLJxk/RnlR3tzBld+K9ODq0T0gbGrI4An4RQXvGVQHZkwn5lbXslXyEWcPKD+CYBcCfy5F mjXipXQ== X-Gm-Gg: ASbGncvlYqLvreUuo7C9t73rXogZjXOvl0nwWqj9KjJjI4m5NtaGyGHRPf+/VgMSVuF KKiZcZzPXbtKg8CfoScxl+G3t47ybIty+3v4VsBULEOubezz/bSyKgFOJX8usJA5fZfDY+wIgOh 1owt1Y/Bed6zVWASA4bG6SOPmM/+zTa6JynWaoRivylBebxRVAaAiL9GRZeIn/uQ/FD9RssJ1lO KhYZ2fzQ83BIONODjnNSZLaaqlvaOwPWZA1pR7WyLe8GLd0r0rLr5H3zva1n/w/7F7on4BcDK/X wXspvApctYoCuFMdYoRjgi0CFX5PMZTPz+a9yNlong== X-Google-Smtp-Source: AGHT+IGIJzAfmdUgm6mfcadFHWNecCdZ9FN/zoctgiLHLQU/A7heuBDNkp5cAto614rUR61sndhfdg== X-Received: by 2002:ac8:5750:0:b0:471:f08e:d661 with SMTP id d75a77b69052e-4750b4411fdmr80338271cf.13.1741209165241; Wed, 05 Mar 2025 13:12:45 -0800 (PST) Received: from boreas.. ([140.174.215.88]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-474eced9880sm43726851cf.17.2025.03.05.13.12.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Mar 2025 13:12:44 -0800 (PST) From: Emil Tsalapatis To: bpf@vger.kernel.org Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, yonghong.song@linux.dev, tj@kernel.org, memxor@gmail.com, houtao@huaweicloud.com, Emil Tsalapatis Subject: [PATCH v4 2/3] selftests: bpf: add bpf_cpumask_fill selftests Date: Wed, 5 Mar 2025 16:12:34 -0500 Message-ID: <20250305211235.368399-3-emil@etsalapatis.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250305211235.368399-1-emil@etsalapatis.com> References: <20250305211235.368399-1-emil@etsalapatis.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net Add selftests for the bpf_cpumask_fill helper that sets a bpf_cpumask to a bit pattern provided by a BPF program. Signed-off-by: Emil Tsalapatis (Meta) --- .../selftests/bpf/progs/cpumask_failure.c | 38 ++++++ .../selftests/bpf/progs/cpumask_success.c | 114 ++++++++++++++++++ 2 files changed, 152 insertions(+) diff --git a/tools/testing/selftests/bpf/progs/cpumask_failure.c b/tools/testing/selftests/bpf/progs/cpumask_failure.c index b40b52548ffb..8a2fd596c8a3 100644 --- a/tools/testing/selftests/bpf/progs/cpumask_failure.c +++ b/tools/testing/selftests/bpf/progs/cpumask_failure.c @@ -222,3 +222,41 @@ int BPF_PROG(test_invalid_nested_array, struct task_struct *task, u64 clone_flag return 0; } + +SEC("tp_btf/task_newtask") +__failure __msg("type=scalar expected=fp") +int BPF_PROG(test_populate_invalid_destination, struct task_struct *task, u64 clone_flags) +{ + struct bpf_cpumask *invalid = (struct bpf_cpumask *)0x123456; + u64 bits; + int ret; + + ret = bpf_cpumask_populate((struct cpumask *)invalid, &bits, sizeof(bits)); + if (!ret) + err = 2; + + return 0; +} + +SEC("tp_btf/task_newtask") +__failure __msg("leads to invalid memory access") +int BPF_PROG(test_populate_invalid_source, struct task_struct *task, u64 clone_flags) +{ + void *garbage = (void *)0x123456; + struct bpf_cpumask *local; + int ret; + + local = create_cpumask(); + if (!local) { + err = 1; + return 0; + } + + ret = bpf_cpumask_populate((struct cpumask *)local, garbage, 8); + if (!ret) + err = 2; + + bpf_cpumask_release(local); + + return 0; +} diff --git a/tools/testing/selftests/bpf/progs/cpumask_success.c b/tools/testing/selftests/bpf/progs/cpumask_success.c index 80ee469b0b60..5dc0fe9940dc 100644 --- a/tools/testing/selftests/bpf/progs/cpumask_success.c +++ b/tools/testing/selftests/bpf/progs/cpumask_success.c @@ -757,6 +757,7 @@ int BPF_PROG(test_refcount_null_tracking, struct task_struct *task, u64 clone_fl mask1 = bpf_cpumask_create(); mask2 = bpf_cpumask_create(); + if (!mask1 || !mask2) goto free_masks_return; @@ -770,3 +771,116 @@ int BPF_PROG(test_refcount_null_tracking, struct task_struct *task, u64 clone_fl bpf_cpumask_release(mask2); return 0; } + +SEC("tp_btf/task_newtask") +__success +int BPF_PROG(test_populate_reject_small_mask, struct task_struct *task, u64 clone_flags) +{ + struct bpf_cpumask *local; + u8 toofewbits; + int ret; + + local = create_cpumask(); + if (!local) + return 0; + + /* The kfunc should prevent this operation */ + ret = bpf_cpumask_populate((struct cpumask *)local, &toofewbits, sizeof(toofewbits)); + if (ret != -EACCES) + err = 2; + + bpf_cpumask_release(local); + + return 0; +} + +/* Mask is guaranteed to be large enough for bpf_cpumask_t. */ +#define CPUMASK_TEST_MASKLEN (sizeof(cpumask_t)) + +/* Add an extra word for the test_populate_reject_unaligned test. */ +u64 bits[CPUMASK_TEST_MASKLEN / 8 + 1]; +extern bool CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS __kconfig __weak; + +SEC("tp_btf/task_newtask") +__success +int BPF_PROG(test_populate_reject_unaligned, struct task_struct *task, u64 clone_flags) +{ + struct bpf_cpumask *mask; + char *src; + int ret; + + /* Skip if unaligned accesses are fine for this arch. */ + if (CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) + return 0; + + mask = bpf_cpumask_create(); + if (!mask) { + err = 1; + return 0; + } + + /* Misalign the source array by a byte. */ + src = &((char *)bits)[1]; + + ret = bpf_cpumask_populate((struct cpumask *)mask, src, CPUMASK_TEST_MASKLEN); + if (ret != -EINVAL) + err = 2; + + bpf_cpumask_release(mask); + + return 0; +} + + +SEC("tp_btf/task_newtask") +__success +int BPF_PROG(test_populate, struct task_struct *task, u64 clone_flags) +{ + struct bpf_cpumask *mask; + bool bit; + int ret; + int i; + + /* Set only odd bits. */ + __builtin_memset(bits, 0xaa, CPUMASK_TEST_MASKLEN); + + mask = bpf_cpumask_create(); + if (!mask) { + err = 1; + return 0; + } + + /* Pass the entire bits array, the kfunc will only copy the valid bits. */ + ret = bpf_cpumask_populate((struct cpumask *)mask, bits, CPUMASK_TEST_MASKLEN); + if (ret) { + err = 2; + goto out; + } + + /* + * Test is there to appease the verifier. We cannot directly + * access NR_CPUS, the upper bound for nr_cpus, so we infer + * it from the size of cpumask_t. + */ + if (nr_cpus < 0 || nr_cpus >= CPUMASK_TEST_MASKLEN * 8) { + err = 3; + goto out; + } + + bpf_for(i, 0, nr_cpus) { + /* Odd-numbered bits should be set, even ones unset. */ + bit = bpf_cpumask_test_cpu(i, (const struct cpumask *)mask); + if (bit == (i % 2 != 0)) + continue; + + err = 4; + break; + } + +out: + bpf_cpumask_release(mask); + + return 0; +} + +#undef CPUMASK_TEST_MASKLEN From patchwork Wed Mar 5 21:12:35 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Tsalapatis X-Patchwork-Id: 14003382 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-qt1-f169.google.com (mail-qt1-f169.google.com [209.85.160.169]) (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 040F1253330 for ; Wed, 5 Mar 2025 21:12:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741209168; cv=none; b=l+HSJVOynnuMAUwD3Eypq+XW6xUxz5fKAbEcu+szfrp9gm2bMZSAuwlHtqHlCgrXjFoVtKH3abPO1LyvTZUujGY6OWfZOsZTFwMWSDsvM+BxRNtsdtUVX9ELdsvLm9md7M6xLJfdYT5PftAKl/Ga4RIhu3tzhfHrFhPFzOVJ8EE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741209168; c=relaxed/simple; bh=mv+HCMVBbVmHqdUiugOOXjr5g7BLszR+Jps6EmD+8CI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qnorkHhSaOzYdYR9j0BcAbWUfkn+tYonDbOuPnDQ8sVadgNkbc4SJa+B58zT6vDhIk/rIaDkg2w8ejowA1SU9CUec2Ochk1cC9EykjBbcaNYZUlkMaSBbVbwZfsnnaMoi0qJlhRITE7V7UTviNruvnxfuOAVMabKIktj9OALiG0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=etsalapatis.com; spf=pass smtp.mailfrom=etsalapatis.com; dkim=pass (2048-bit key) header.d=etsalapatis-com.20230601.gappssmtp.com header.i=@etsalapatis-com.20230601.gappssmtp.com header.b=tpRMzpeO; arc=none smtp.client-ip=209.85.160.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=etsalapatis.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=etsalapatis.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=etsalapatis-com.20230601.gappssmtp.com header.i=@etsalapatis-com.20230601.gappssmtp.com header.b="tpRMzpeO" Received: by mail-qt1-f169.google.com with SMTP id d75a77b69052e-474f8d2f21aso13400471cf.1 for ; Wed, 05 Mar 2025 13:12:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=etsalapatis-com.20230601.gappssmtp.com; s=20230601; t=1741209166; x=1741813966; 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; bh=+HdrhctNSRPqibWATjlfkSbi305qwbCuRWPmEde3E5Q=; b=tpRMzpeOoIUi05hpw4WE9JDnSB+yH69XaC73LpezlRFmRKHTa6WUo6fjIqw3PEmH9O ZcQAwuy/Rxa9Kym41OFavMyeSWgUMEcHkE6Oe8MggKHIujr8UaznmH8xcW7YwbOi7ZlV bVJgpz/SJIN4FrFCnvEInGNek/NP9vcy6HpLWWKLcC22sZ9rgeudkJ0PK7BCfyqUAAbt QyXkh9ZEbwFTWW0RD/cg0IefCy7c8JJzFhT1rjRjBN0K62fKC7JytzFv0R9jg0FyCWrl wWY8Wo7tiQX4H8O8CXWEJfym/uM5DWLQNsCM8bh97XHLjYyqffmurqI/cseUu+uOBFMB pCqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741209166; x=1741813966; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+HdrhctNSRPqibWATjlfkSbi305qwbCuRWPmEde3E5Q=; b=YLpPZ0axeJBGPNHOAZZY3okcrjeSgMxh6pvKlydZ8b7ApFI1ysjrE/hODWXJ1XtWCy 5afd43LJymKwWTgsGt0GD5yzWfjlahME+jTwrYKC98qFLJU0i0I/UPmafdsbU+ANDxbi q0DrSVsYDuMldi2gQXl5Gym+gipE5ZHMrCa4ASQPyliPv6PRRl5thsyDtDU6UzjBz6o5 tDFknmVYfYKyR0m62lZ29j0qm7egn+kcZXD48vQyX2nAswjqx0QWU+FjGAe3usPdZUdc Pn5KFJYC/omnm6aNESZE78kJ1T6VObPWQLCGMazyl6VM7zXKvvSzZ3OyiNIpM9ed6YkF B6NQ== X-Gm-Message-State: AOJu0YwPhBvhfYkn4/W3Zfh0Ykxfn7FT1L7/RR19B3F+8zoLNCyTYVJa kOnZiqFyK29HRqhQxckL13sQRo9jWWDjIDO3b+P7PRFlMGMmTaEywbY/FqFAzzJa90Dc8voFKFH taC1ROA== X-Gm-Gg: ASbGncvg861OMIyLO4y8qFMpD484NFMLj87RIP+fkji1Bnc4u6dvv51WZ8mP1Xhny2Y eWbM1vK38PHmoZdc9QSemX/TyEMg/ZqlWQVBxqyzCBosxwC85ZPY1E/7o2kwKHATaW6PNwSadXs DroTOVn4jBsyUNWXaty7RWfJ6R27ioc6iiz91Os5VSh9H4CorAv9TxQqTQYI1pA7wDcgL2vG0sB IHAAI96y7vUI/cVlTMOn/YQPaIkD7+p+xRWz/5kPJWHLyWWHkfWVQBOX+rrMsPS6CUMHhMQAv5r Uxx7bZsUa6OWyav1kTMRoupu5rb+/g7pW+iJeaxKsQ== X-Google-Smtp-Source: AGHT+IH4foH7Cl+tvYD9TDDLPV/SyS8wxg3WAn2r8efZr6It58SvH5pWbC2zL/GPeFHltEJVLdYXWQ== X-Received: by 2002:a05:622a:1ba1:b0:471:bd14:a783 with SMTP id d75a77b69052e-4751a65466emr13784881cf.25.1741209165896; Wed, 05 Mar 2025 13:12:45 -0800 (PST) Received: from boreas.. ([140.174.215.88]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-474eced9880sm43726851cf.17.2025.03.05.13.12.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Mar 2025 13:12:45 -0800 (PST) From: Emil Tsalapatis To: bpf@vger.kernel.org Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, yonghong.song@linux.dev, tj@kernel.org, memxor@gmail.com, houtao@huaweicloud.com, Emil Tsalapatis Subject: [PATCH v4 3/3] bpf: fix missing kdoc string fields in cpumask.c Date: Wed, 5 Mar 2025 16:12:35 -0500 Message-ID: <20250305211235.368399-4-emil@etsalapatis.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250305211235.368399-1-emil@etsalapatis.com> References: <20250305211235.368399-1-emil@etsalapatis.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net Some bpf_cpumask-related kfuncs have kdoc strings that are missing return values. Add a the missing descriptions for the return values. Reported-by: Alexei Starovoitov Signed-off-by: Emil Tsalapatis (Meta) --- kernel/bpf/cpumask.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/kernel/bpf/cpumask.c b/kernel/bpf/cpumask.c index 14080ca694b0..c6c1ec6d2b2c 100644 --- a/kernel/bpf/cpumask.c +++ b/kernel/bpf/cpumask.c @@ -45,6 +45,10 @@ __bpf_kfunc_start_defs(); * * bpf_cpumask_create() allocates memory using the BPF memory allocator, and * will not block. It may return NULL if no memory is available. + * + * Return: + * * A pointer to a new struct bpf_cpumask instance on success. + * * NULL if the BPF memory allocator is out of memory. */ __bpf_kfunc struct bpf_cpumask *bpf_cpumask_create(void) { @@ -71,6 +75,10 @@ __bpf_kfunc struct bpf_cpumask *bpf_cpumask_create(void) * Acquires a reference to a BPF cpumask. The cpumask returned by this function * must either be embedded in a map as a kptr, or freed with * bpf_cpumask_release(). + * + * Return: + * * The struct bpf_cpumask pointer passed to the function. + * */ __bpf_kfunc struct bpf_cpumask *bpf_cpumask_acquire(struct bpf_cpumask *cpumask) { @@ -106,6 +114,9 @@ CFI_NOSEAL(bpf_cpumask_release_dtor); * * Find the index of the first nonzero bit of the cpumask. A struct bpf_cpumask * pointer may be safely passed to this function. + * + * Return: + * * The index of the first nonzero bit in the struct cpumask. */ __bpf_kfunc u32 bpf_cpumask_first(const struct cpumask *cpumask) { @@ -119,6 +130,9 @@ __bpf_kfunc u32 bpf_cpumask_first(const struct cpumask *cpumask) * * Find the index of the first unset bit of the cpumask. A struct bpf_cpumask * pointer may be safely passed to this function. + * + * Return: + * * The index of the first zero bit in the struct cpumask. */ __bpf_kfunc u32 bpf_cpumask_first_zero(const struct cpumask *cpumask) { @@ -133,6 +147,9 @@ __bpf_kfunc u32 bpf_cpumask_first_zero(const struct cpumask *cpumask) * * Find the index of the first nonzero bit of the AND of two cpumasks. * struct bpf_cpumask pointers may be safely passed to @src1 and @src2. + * + * Return: + * * The index of the first bit that is nonzero in both cpumask instances. */ __bpf_kfunc u32 bpf_cpumask_first_and(const struct cpumask *src1, const struct cpumask *src2) @@ -414,6 +431,9 @@ __bpf_kfunc u32 bpf_cpumask_any_and_distribute(const struct cpumask *src1, * @cpumask: The cpumask being queried. * * Count the number of set bits in the given cpumask. + * + * Return: + * * The number of bits set in the mask. */ __bpf_kfunc u32 bpf_cpumask_weight(const struct cpumask *cpumask) {