Use best instruction set that the local kernel supports
authorMatt Corallo <git@bluematt.me>
Wed, 8 Dec 2021 20:14:50 +0000 (20:14 +0000)
committerMatt Corallo <git@bluematt.me>
Wed, 8 Dec 2021 23:25:22 +0000 (23:25 +0000)
install.sh
xdp.c

index b791d8ee5c0b98c692e14e9102cecd149b3b8a04..2a47a1dd1ffe57cddb1e8473ef633ae6d8771cc9 100755 (executable)
@@ -21,9 +21,9 @@ STATS_RULES="$(echo "$RULES" | ./genrules.py --8021q=drop-vlan --v6frag=ignore-p
 clang $CLANG_ARGS -g -std=c99 -pedantic -Wall -Wextra -Wno-pointer-arith -Wno-unused-variable -Wno-unused-function -O3 -emit-llvm -c xdp.c -o xdp.bc
 if [ "$2" != "" ]; then
        clang $4 -g -std=c99 -pedantic -Wall -Wextra -Wno-pointer-arith -O3 -emit-llvm -c "$2" -o wrapper.bc
-       llvm-link xdp.bc wrapper.bc | llc -O3 -march=bpf -filetype=obj -o xdp
+       llvm-link xdp.bc wrapper.bc | llc -O3 -march=bpf -mcpu=probe -filetype=obj -o xdp
 else
-       cat xdp.bc | llc -O3 -march=bpf -filetype=obj -o xdp
+       cat xdp.bc | llc -O3 -march=bpf -mcpu=probe -filetype=obj -o xdp
 fi
 
 echo "Before unload drop count was:"
diff --git a/xdp.c b/xdp.c
index f59019a180411681df1844e13806f8ce35ad1f80..187c220b0261fdaad0acc5ec7d48c6d36a4b86e5 100644 (file)
--- a/xdp.c
+++ b/xdp.c
@@ -273,9 +273,9 @@ static int check_v##IPV##_persrc_ratelimit(IP_TYPE key, void *map, size_t map_li
        struct persrc_rate##IPV##_entry *first_bucket = &buckets->entries[(hash % map_limit) & (~(SRC_HASH_BUCKET_COUNT - 1))]; \
        bpf_spin_lock(&buckets->lock); \
  \
-       int min_sent_idx = 0; \
+       uint64_t min_sent_idx = 0; /* Must be uint64_t or BPF verifier gets lost and thinks it can be any value */ \
        uint64_t min_sent_time = UINT64_MAX; \
-       for (int i = 0; i < SRC_HASH_BUCKET_COUNT; i++) { \
+       for (uint64_t i = 0; i < SRC_HASH_BUCKET_COUNT; i++) { \
                if (first_bucket[i].srcip == key) { \
                        min_sent_idx = i; \
                        break; \