summary refs log tree commit diff stats
path: root/tools
diff options
context:
space:
mode:
authorAkihiko Odaki <akihiko.odaki@daynix.com>2024-04-28 16:00:58 +0900
committerJason Wang <jasowang@redhat.com>2024-06-04 15:14:26 +0800
commit72fa42cfca7060fab00c534e71fc850b194a4c6d (patch)
tree2ffd19d4c918ad9d75ebed96382527befacfcb33 /tools
parenta4c960eedcd2c68ff784fb4d4cb8ddd5bff8814f (diff)
downloadfocaccia-qemu-72fa42cfca7060fab00c534e71fc850b194a4c6d.tar.gz
focaccia-qemu-72fa42cfca7060fab00c534e71fc850b194a4c6d.zip
ebpf: Fix RSS error handling
calculate_rss_hash() was using hash value 0 to tell if it calculated
a hash, but the hash value may be 0 on a rare occasion. Have a
distinct bool value for correctness.

Fixes: f3fa412de2 ("ebpf: Added eBPF RSS program.")
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/ebpf/rss.bpf.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/tools/ebpf/rss.bpf.c b/tools/ebpf/rss.bpf.c
index 9715d1170e..fa55e1fcb5 100644
--- a/tools/ebpf/rss.bpf.c
+++ b/tools/ebpf/rss.bpf.c
@@ -380,18 +380,19 @@ error:
     return err;
 }
 
-static inline __u32 calculate_rss_hash(struct __sk_buff *skb,
-        struct rss_config_t *config, struct toeplitz_key_data_t *toe)
+static inline bool calculate_rss_hash(struct __sk_buff *skb,
+                                      struct rss_config_t *config,
+                                      struct toeplitz_key_data_t *toe,
+                                      __u32 *result)
 {
     __u8 rss_input[HASH_CALCULATION_BUFFER_SIZE] = {};
     size_t bytes_written = 0;
-    __u32 result = 0;
     int err = 0;
     struct packet_hash_info_t packet_info = {};
 
     err = parse_packet(skb, &packet_info);
     if (err) {
-        return 0;
+        return false;
     }
 
     if (packet_info.is_ipv4) {
@@ -524,11 +525,13 @@ static inline __u32 calculate_rss_hash(struct __sk_buff *skb,
         }
     }
 
-    if (bytes_written) {
-        net_toeplitz_add(&result, rss_input, bytes_written, toe);
+    if (!bytes_written) {
+        return false;
     }
 
-    return result;
+    net_toeplitz_add(result, rss_input, bytes_written, toe);
+
+    return true;
 }
 
 SEC("socket")
@@ -549,8 +552,7 @@ int tun_rss_steering_prog(struct __sk_buff *skb)
             return config->default_queue;
         }
 
-        hash = calculate_rss_hash(skb, config, toe);
-        if (hash) {
+        if (calculate_rss_hash(skb, config, toe, &hash)) {
             __u32 table_idx = hash % config->indirections_len;
             __u16 *queue = 0;