From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-183.mta1.migadu.com (out-183.mta1.migadu.com [95.215.58.183]) (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 7640333A9C4 for ; Thu, 19 Feb 2026 14:30:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.183 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771511420; cv=none; b=KTchwOBn5cfVCWvqUC4XP52kP1k9TsweD6Xn+O6uMo1qDrYr3wgTRyn+zHBwVSNZfedi1rvMaNiVEMZhKu0hBfJcod72cW+uso72zxFTTShMe++xZsuCii15HyTN/Jm0Rl/bQKy2VPr/CgAxf4HE/TV9RqlCkm+frsGQUZGxN40= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771511420; c=relaxed/simple; bh=CG2uCtipwOOt8HU/0TWfy6Fc9mWxrM+FVH2EaxMB+0k=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=HxcT9GfenTKA2LsVRYFVMaGmr9UbUZOfTfmrFVLj5T/ohMohUJOMPDeDhcjZVp3b2dpCsTzjrUvDtOrY222Fwox4hfzT7bLFEH6Kpnj/EglKnbXShfpWEI0skNDAuWjDvTIjU/ksrr0KcH/4cza0jqS0c6Ph2oAJgtMsdJTqoIs= 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=lR2culyr; arc=none smtp.client-ip=95.215.58.183 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="lR2culyr" 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=1771511415; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=LRtR7BaGNupDWJtUJ58LFj4w6zAqDSzxcIixhPEboME=; b=lR2culyrTuf+k/z/wvJ7a4TUVJtUKioslDuE04IeFiNfDyawkkQoEMJkVNpSWGmNExEPFF Zzz9Cu/xfdoAwYIVGaS/KJNhqdaV5GF/Ud+dTmgeV5uAC/UIabDJL1FUIHTlOxvi0sV8O9 J8IYCsIie3aBLLg+bK95zRLvhIVzVaM= From: Leon Hwang To: bpf@vger.kernel.org Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Puranjay Mohan , Xu Kuohai , Catalin Marinas , Will Deacon , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H . Peter Anvin" , Shuah Khan , Leon Hwang , Peilin Ye , Luis Gerhorst , Viktor Malik , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, kernel-patches-bot@fb.com Subject: [PATCH bpf-next v2 0/6] bpf: Introduce 64-bit bitops kfuncs Date: Thu, 19 Feb 2026 22:29:22 +0800 Message-ID: <20260219142933.13904-1-leon.hwang@linux.dev> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT This series adds generic 64-bit bitops kfuncs and JIT inlining support on x86_64 and arm64. The new kfuncs are: * bpf_clz64(): Count leading zeros. * bpf_ctz64(): Count trailing zeros. * bpf_ffs64(): Find first set bit, 1-based index, returns 0 when input is 0. * bpf_fls64(): Find last set bit, 1-based index. * bpf_bitrev64(): Reverse bits. * bpf_popcnt64(): Population count. * bpf_rol64(): Rotate left. * bpf_ror64(): Rotate right. Defined zero-input behavior: * bpf_clz64(0) = 64 * bpf_ctz64(0) = 64 * bpf_ffs64(0) = 0 * bpf_fls64(0) = 0 bpf_ffs64() was previously discussed in "bpf: Add generic kfunc bpf_ffs64()" [1]. The main concern in that discussion was ABI overhead: a regular kfunc call follows the BPF calling convention and can introduce extra spill/fill compared to dedicated instructions. This series keeps the user-facing API as kfuncs while avoiding that overhead on hot paths. When the JIT/backend and CPU support it, calls are inlined into native instructions; otherwise they fall back to regular function calls. Links: [1] https://lore.kernel.org/bpf/20240131155607.51157-1-hffilwlqm@gmail.com/ Changes: v1 -> v2: * Drop RFC. * Add __cpu_feature annotation for CPU-feature-gated tests. * Add JIT disassembly tests for 64-bit bitops kfuncs * Address comments from Alexei: * Drop KF_MUST_INLINE. * Drop internal BPF_ALU64 opcode BPF_BITOPS. * Mark all of the kfuncs as fastcall and do push/pop in JIT when necessary. * v1: https://lore.kernel.org/bpf/20260209155919.19015-1-leon.hwang@linux.dev/ Leon Hwang (6): bpf: Introduce 64-bit bitops kfuncs bpf, x86: Add 64-bit bitops kfuncs support for x86_64 bpf, arm64: Add 64-bit bitops kfuncs support selftests/bpf: Add tests for 64-bit bitops kfuncs selftests/bpf: Add __cpu_feature annotation for CPU-feature-gated tests selftests/bpf: Add JIT disassembly tests for 64-bit bitops kfuncs arch/arm64/net/bpf_jit_comp.c | 123 ++++++++++++ arch/x86/net/bpf_jit_comp.c | 141 +++++++++++++ include/linux/filter.h | 10 + kernel/bpf/core.c | 6 + kernel/bpf/helpers.c | 50 +++++ kernel/bpf/verifier.c | 53 ++++- .../testing/selftests/bpf/bpf_experimental.h | 9 + .../testing/selftests/bpf/prog_tests/bitops.c | 188 ++++++++++++++++++ tools/testing/selftests/bpf/progs/bitops.c | 68 +++++++ .../testing/selftests/bpf/progs/bitops_jit.c | 153 ++++++++++++++ tools/testing/selftests/bpf/progs/bpf_misc.h | 7 + tools/testing/selftests/bpf/test_loader.c | 150 ++++++++++++++ 12 files changed, 957 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/bpf/prog_tests/bitops.c create mode 100644 tools/testing/selftests/bpf/progs/bitops.c create mode 100644 tools/testing/selftests/bpf/progs/bitops_jit.c -- 2.52.0