Repository navigation
Conversation
Signed-off-by: Eduard Zateev <hackerowskiy@gmail.com>
tohojo
requested changes
Oct 26, 2026
tohojo
left a comment
Member
There was a problem hiding this comment.
I am OK with adding the API, but I don't think we should add a whole new code path for it. Rather, we can transparently introduce caching to the existing probe method, something like:
diff --git i/lib/libxdp/libxdp.c w/lib/libxdp/libxdp.c
index fa57b00329e1..7877e1da1b17 100644
--- i/lib/libxdp/libxdp.c
+++ w/lib/libxdp/libxdp.c
@@ -1694,7 +1694,7 @@ static const char *get_bpf_flag_name(__u32 flag)
}
}
-static bool kernel_has_bpf_flag(__u32 flag)
+static bool kernel_probe_bpf_flag(__u32 flag)
{
struct xdp_program *test_prog;
bool ret = false;
@@ -1723,6 +1723,38 @@ static bool kernel_has_bpf_flag(__u32 flag)
return ret;
}
+/* We cache the two flags defined as bits 5 and 6 in the kernel headers */
+#define FEATURE_CACHE_OFFSET 5
+#define FEATURE_CACHE_SIZE 2
+#define FEATURE_PROBED (1U << 0)
+#define FEATURE_AVAILABLE (1U << 1)
+static unsigned int feature_cache[FEATURE_CACHE_SIZE];
+
+static bool kernel_has_bpf_flag(__u32 flag) {
+ unsigned int value, slot = __builtin_ctz(flag) - FEATURE_CACHE_OFFSET;
+
+ if (slot >= FEATURE_CACHE_SIZE) {
+ pr_warn("Invalid probe flag %u - please report this as a bug!\n", flag);
+ return false;
+ }
+
+ value = __atomic_load_n(&feature_cache[slot], __ATOMIC_ACQUIRE);
+ if (value & FEATURE_PROBED)
+ goto out;
+
+ value = FEATURE_PROBED;
+ if (kernel_probe_bpf_flag(flag))
+ value |= FEATURE_AVAILABLE;
+
+ /* We assume probing always returns the same result, so we don't bother
+ * with a cmpxchg() when setting this.
+ */
+ __atomic_store_n(&feature_cache[slot], value, __ATOMIC_RELEASE);
+
+out:
+ return !!(value & FEATURE_AVAILABLE);
+}
+
static bool kernel_has_frags_support(void)
{
return kernel_has_bpf_flag(BPF_F_XDP_HAS_FRAGS);The new function then becomes simply:
void libxdp_cache_kernel_features(void)
{
(void)kernel_has_frags_support();
(void)kernel_has_dev_bound();
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add libxdp_cache_kernel_features() so applications can probe and cache XDP frags and device-bound support during single-threaded startup. Dispatcher attachments then reuse those results instead of repeating unsupported-feature probes and their libbpf diagnostics.
Document the API and its startup requirements, export it in the LIBXDP_1.7.0 ABI, and add a regression test for repeated calls.
Fixes #478.
Testing
The full privileged test runner was not run because this SSH account lacks sudo and the required namespace privileges.