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>
This commit is contained in:
Akihiko Odaki 2024-04-28 16:00:58 +09:00 committed by Jason Wang
parent a4c960eedc
commit 72fa42cfca
2 changed files with 610 additions and 620 deletions

File diff suppressed because it is too large Load Diff

View File

@ -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;