[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 1/5] ebpf: pass and check RSS key length to the loader
From: |
Maxime Coquelin |
Subject: |
[PATCH 1/5] ebpf: pass and check RSS key length to the loader |
Date: |
Fri, 8 Apr 2022 14:28:09 +0200 |
This patch is preliminary rework to support RSS with
Vhost-user backends. The Vhost-user implementation will
allow RSS hash key of 40 bytes or more as allowed by the
Virtio specification, whereas the eBPF-based Vhost-kernel
solution only supports 40 bytes keys.
This patch adds the RSS key length to the loader, and
validate it is 40 bytes before copying it.
Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
ebpf/ebpf_rss-stub.c | 3 ++-
ebpf/ebpf_rss.c | 11 +++++++----
ebpf/ebpf_rss.h | 3 ++-
hw/net/virtio-net.c | 3 ++-
4 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/ebpf/ebpf_rss-stub.c b/ebpf/ebpf_rss-stub.c
index e71e229190..ffc5c5574f 100644
--- a/ebpf/ebpf_rss-stub.c
+++ b/ebpf/ebpf_rss-stub.c
@@ -29,7 +29,8 @@ bool ebpf_rss_load(struct EBPFRSSContext *ctx)
}
bool ebpf_rss_set_all(struct EBPFRSSContext *ctx, struct EBPFRSSConfig *config,
- uint16_t *indirections_table, uint8_t *toeplitz_key)
+ uint16_t *indirections_table, uint8_t *toeplitz_key,
+ uint8_t key_len)
{
return false;
}
diff --git a/ebpf/ebpf_rss.c b/ebpf/ebpf_rss.c
index 118c68da83..4a63854175 100644
--- a/ebpf/ebpf_rss.c
+++ b/ebpf/ebpf_rss.c
@@ -110,14 +110,16 @@ static bool ebpf_rss_set_indirections_table(struct
EBPFRSSContext *ctx,
}
static bool ebpf_rss_set_toepliz_key(struct EBPFRSSContext *ctx,
- uint8_t *toeplitz_key)
+ uint8_t *toeplitz_key,
+ size_t len)
{
uint32_t map_key = 0;
/* prepare toeplitz key */
uint8_t toe[VIRTIO_NET_RSS_MAX_KEY_SIZE] = {};
- if (!ebpf_rss_is_loaded(ctx) || toeplitz_key == NULL) {
+ if (!ebpf_rss_is_loaded(ctx) || toeplitz_key == NULL ||
+ len != VIRTIO_NET_RSS_MAX_KEY_SIZE) {
return false;
}
memcpy(toe, toeplitz_key, VIRTIO_NET_RSS_MAX_KEY_SIZE);
@@ -131,7 +133,8 @@ static bool ebpf_rss_set_toepliz_key(struct EBPFRSSContext
*ctx,
}
bool ebpf_rss_set_all(struct EBPFRSSContext *ctx, struct EBPFRSSConfig *config,
- uint16_t *indirections_table, uint8_t *toeplitz_key)
+ uint16_t *indirections_table, uint8_t *toeplitz_key,
+ uint8_t key_len)
{
if (!ebpf_rss_is_loaded(ctx) || config == NULL ||
indirections_table == NULL || toeplitz_key == NULL) {
@@ -147,7 +150,7 @@ bool ebpf_rss_set_all(struct EBPFRSSContext *ctx, struct
EBPFRSSConfig *config,
return false;
}
- if (!ebpf_rss_set_toepliz_key(ctx, toeplitz_key)) {
+ if (!ebpf_rss_set_toepliz_key(ctx, toeplitz_key, key_len)) {
return false;
}
diff --git a/ebpf/ebpf_rss.h b/ebpf/ebpf_rss.h
index bf3f2572c7..db23ccd25f 100644
--- a/ebpf/ebpf_rss.h
+++ b/ebpf/ebpf_rss.h
@@ -37,7 +37,8 @@ bool ebpf_rss_is_loaded(struct EBPFRSSContext *ctx);
bool ebpf_rss_load(struct EBPFRSSContext *ctx);
bool ebpf_rss_set_all(struct EBPFRSSContext *ctx, struct EBPFRSSConfig *config,
- uint16_t *indirections_table, uint8_t *toeplitz_key);
+ uint16_t *indirections_table, uint8_t *toeplitz_key,
+ uint8_t key_len);
void ebpf_rss_unload(struct EBPFRSSContext *ctx);
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 1067e72b39..73145d6390 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -1201,7 +1201,8 @@ static bool virtio_net_attach_epbf_rss(VirtIONet *n)
rss_data_to_rss_config(&n->rss_data, &config);
if (!ebpf_rss_set_all(&n->ebpf_rss, &config,
- n->rss_data.indirections_table, n->rss_data.key)) {
+ n->rss_data.indirections_table, n->rss_data.key,
+ VIRTIO_NET_RSS_MAX_KEY_SIZE)) {
return false;
}
--
2.35.1
- [PATCH 0/5] Vhost-user: add Virtio RSS support, Maxime Coquelin, 2022/04/08
- [PATCH 5/5] vhost-user: add RSS support, Maxime Coquelin, 2022/04/08
- [PATCH 4/5] docs: introduce RSS support in Vhost-user specification, Maxime Coquelin, 2022/04/08
- [PATCH 3/5] virtio-net: add RSS support for Vhost backends, Maxime Coquelin, 2022/04/08
- [PATCH 1/5] ebpf: pass and check RSS key length to the loader,
Maxime Coquelin <=
- [PATCH 2/5] virtio-net: prepare for variable RSS key and indir table lengths, Maxime Coquelin, 2022/04/08
- Re: [PATCH 0/5] Vhost-user: add Virtio RSS support, Jason Wang, 2022/04/15