Skip to contentSkip to conversation

net/tap RSS BPF rewrite

RFC New Stephen Hemminger 7 participants 206 messages Jan 30, 2024 – May 28, 2024 Page 2 of 3

Subsystems (2)
lore
Share & tools
lore
#106 lore raw

PATCH v10 6/9 net/tap: use libbpf to load new BPF program

In reply to Stephen Hemminger

There were multiple issues in the RSS queue support in the TAP driver. This required extensive rework of the BPF support.

Change the BPF loading to use bpftool to
create a skeleton header file, and load with libbpf. The BPF is always compiled from source so less chance that source and instructions diverge. Also resolves issue where libbpf and source get out of sync. The program
is only loaded once, so if multiple rules are created only one BPF program is loaded in kernel.

The new BPF program only needs a single action.
No need for action and re-classification step.

It also fixes the missing bits from the original.
- supports setting RSS key per flow
- level of hash can be L3 or L3/L4.

---
 drivers/net/tap/bpf/meson.build |  36 ++-
 drivers/net/tap/bpf/tap_rss.c   |  45 ++--
 drivers/net/tap/meson.build     |  35 ++-
 drivers/net/tap/rte_eth_tap.c   |  14 +-
 drivers/net/tap/rte_eth_tap.h   |   6 +-
 drivers/net/tap/tap_flow.c      | 418 ++++++++------------------------
 drivers/net/tap/tap_flow.h      |  17 +-
 drivers/net/tap/tap_rss.h       |  10 +-
 drivers/net/tap/tap_tcmsgs.h    |   4 +-
 9 files changed, 189 insertions(+), 396 deletions(-)
drivers/net/tap/bpf/meson.build +31 -5
index f2c03a19fd..45e8c3b498 100644
@@ -1,17 +1,26 @@
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright 2024 Stephen Hemminger <[email protected]>
 
-enable_tap_rss = false
-
-libbpf = dependency('libbpf', required: false, method: 'pkg-config')
+# Loading BPF requires libbpf
+# and the bpf_map__XXX API's were introduced in 0.8.0
+libbpf = dependency('libbpf', version: '>= 1.0',
+                    required: false, method: 'pkg-config')
 if not libbpf.found()
     message('net/tap: no RSS support missing libbpf')
     subdir_done()
 endif
 
+# Making skeleton needs bpftool
 # Debian install this in /usr/sbin which is not in $PATH
-bpftool = find_program('bpftool', '/usr/sbin/bpftool', required: false, version: '>= 5.6.0')
-if not bpftool.found()
+bpftool_supports_skel = false
+bpftool = find_program('bpftool', '/usr/sbin/bpftool', required: false)
+if bpftool.found()
+    # Some Ubuntu versions have non-functional bpftool
+    bpftool_supports_skel = run_command(bpftool, 'gen', 'help',
+                                        check:false).returncode() == 0
+endif
+
+if not bpftool_supports_skel
     message('net/tap: no RSS support missing bpftool')
     subdir_done()
 endif
@@ -42,6 +51,7 @@ clang_flags = [
     '-O2',
     '-Wall',
     '-Wextra',
+    max_queues,
     '-target',
     'bpf',
     '-g',
@@ -67,6 +77,22 @@ skel_h_cmd = [
     '@INPUT@'
 ]
 
+vmlinux_h_cmd = [
+    bpftool,
+    'btf',
+    'dump',
+    'file',
+    '/sys/kernel/btf/vmlinux',
+    'format',
+    'c'
+]
+
+vmlinux_h = custom_target(
+    'vmlinux.h',
+    output: 'vmlinux.h',
+    command: vmlinux_h_cmd,
+    capture: true)
+
 tap_rss_o = custom_target(
     'tap_rss.bpf.o',
     input: 'tap_rss.c',
drivers/net/tap/bpf/tap_rss.c +24 -21

67 lines not on this page · raw message

drivers/net/tap/meson.build +16 -19
index 66647a1c62..26074059fa 100644
@@ -5,36 +5,33 @@ if not is_linux
     build = false
     reason = 'only supported on Linux'
 endif
+
 sources = files(
         'rte_eth_tap.c',
         'tap_intr.c',
         'tap_netlink.c',
 )
 
+deps = ['bus_vdev', 'gso', 'hash']
+
+max_queues = '-DTAP_MAX_QUEUES=16'
+cflags += max_queues
+
+require_iova_in_mbuf = false
+
 if cc.has_header_symbol('linux/pkt_cls.h', 'TCA_FLOWER_ACT')
     cflags += '-DHAVE_TCA_FLOWER'
     sources += files(
-        'tap_bpf_api.c',
         'tap_flow.c',
         'tap_tcmsgs.c',
     )
-endif
-
-deps = ['bus_vdev', 'gso', 'hash']
 
-cflags += '-DTAP_MAX_QUEUES=16'
-
-# input array for meson symbol search:
-# [ "MACRO to define if found", "header for the search",
-#   "enum/define", "symbol to search" ]
-#
-args = [
-        [ 'HAVE_TC_ACT_BPF', 'linux/tc_act/tc_bpf.h', 'TCA_ACT_BPF_UNSPEC' ],
-]
-config = configuration_data()
-foreach arg:args
-    config.set(arg[0], cc.has_header_symbol(arg[1], arg[2]))
-endforeach
-configure_file(output : 'tap_autoconf.h', configuration : config)
+    enable_tap_rss = false
 
-require_iova_in_mbuf = false
+    subdir('bpf')
+    if enable_tap_rss
+        cflags += '-DHAVE_BPF_RSS'
+        ext_deps += libbpf
+        sources += tap_rss_skel_h
+    endif
+endif
drivers/net/tap/rte_eth_tap.c +7 -7
index 3f4fe95a09..793730de08 100644
@@ -1131,6 +1131,7 @@ tap_dev_close(struct rte_eth_dev *dev)
 		tap_flow_implicit_flush(internals, NULL);
 		tap_nl_final(internals->nlsk_fd);
 		internals->nlsk_fd = -1;
+		tap_flow_bpf_destroy(internals);
 	}
 #endif
 
@@ -1956,6 +1957,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 	strlcpy(pmd->name, tap_name, sizeof(pmd->name));
 	pmd->type = type;
 	pmd->ka_fd = -1;
+
 #ifdef HAVE_TCA_FLOWER
 	pmd->nlsk_fd = -1;
 #endif
@@ -2038,13 +2040,6 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 	/* Make network device persist after application exit */
 	pmd->persist = persist;
 
-	pmd->if_index = if_nametoindex(pmd->name);
-	if (!pmd->if_index) {
-		TAP_LOG(ERR, "%s: failed to get if_index.", pmd->name);
-		goto disable_rte_flow;
-	}
-
-
 #ifdef HAVE_TCA_FLOWER
 	/*
 	 * Set up everything related to rte_flow:
@@ -2060,6 +2055,11 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 			pmd->name);
 		goto disable_rte_flow;
 	}
+	pmd->if_index = if_nametoindex(pmd->name);
+	if (!pmd->if_index) {
+		TAP_LOG(ERR, "%s: failed to get if_index.", pmd->name);
+		goto disable_rte_flow;
+	}
 	if (qdisc_create_multiq(pmd->nlsk_fd, pmd->if_index) < 0) {
 		TAP_LOG(ERR, "%s: failed to create multiq qdisc.",
 			pmd->name);
drivers/net/tap/rte_eth_tap.h +2 -4
index af18b29090..ce4322ad04 100644
@@ -81,10 +81,8 @@ struct pmd_internals {
 #ifdef HAVE_TCA_FLOWER
 	int nlsk_fd;                      /* Netlink socket fd */
 	int flow_isolate;                 /* 1 if flow isolation is enabled */
-	int rss_enabled;                  /* 1 if RSS is enabled, else 0 */
-	/* implicit rules set when RSS is enabled */
-	int map_fd;                       /* BPF RSS map fd */
-	int bpf_fd[RTE_PMD_TAP_MAX_QUEUES];/* List of bpf fds per queue */
+
+	struct tap_rss *rss;		  /* BPF program */
 
 	LIST_HEAD(tap_flows, rte_flow) flows;        /* rte_flow rules */
 	/* implicit rte_flow rules set when a remote device is active */
drivers/net/tap/tap_flow.c +97 -321

555 lines not on this page · raw message

drivers/net/tap/tap_flow.h +6 -11
index 240fbc3dfa..8b19347a93 100644
@@ -9,7 +9,11 @@
 #include <rte_flow.h>
 #include <rte_flow_driver.h>
 #include <rte_eth_tap.h>
-#include <tap_autoconf.h>
+
+/**
+ * Mask of unsupported RSS types
+ */
+#define TAP_RSS_HF_MASK (~(RTE_ETH_RSS_IP | RTE_ETH_RSS_UDP | RTE_ETH_RSS_TCP))
 
 /**
  * In TC, priority 0 means we require the kernel to allocate one for us.
@@ -41,11 +45,6 @@ enum implicit_rule_index {
 	TAP_REMOTE_MAX_IDX,
 };
 
-enum bpf_fd_idx {
-	SEC_L3_L4,
-	SEC_MAX,
-};
-
 int tap_dev_flow_ops_get(struct rte_eth_dev *dev,
 			 const struct rte_flow_ops **ops);
 int tap_flow_flush(struct rte_eth_dev *dev, struct rte_flow_error *error);
@@ -57,10 +56,6 @@ int tap_flow_implicit_destroy(struct pmd_internals *pmd,
 int tap_flow_implicit_flush(struct pmd_internals *pmd,
 			    struct rte_flow_error *error);
 
-int tap_flow_bpf_cls_q(__u32 queue_idx);
-int tap_flow_bpf_calc_l3_l4_hash(__u32 key_idx, int map_fd);
-int tap_flow_bpf_rss_map_create(unsigned int key_size, unsigned int value_size,
-			unsigned int max_entries);
-int tap_flow_bpf_update_rss_elem(int fd, void *key, void *value);
+void tap_flow_bpf_destroy(struct pmd_internals *pmd);
 
 #endif /* _TAP_FLOW_H_ */
drivers/net/tap/tap_rss.h +4 -6
index 6009be7031..65bd8991b1 100644
@@ -5,16 +5,14 @@
 #ifndef _TAP_RSS_H_
 #define _TAP_RSS_H_
 
-#ifndef TAP_MAX_QUEUES
-#define TAP_MAX_QUEUES 16
+/* Size of the map from BPF classid to queue table */
+#ifndef TAP_RSS_MAX
+#define TAP_RSS_MAX	32
 #endif
 
-/* Fixed RSS hash key size in bytes. */
+/* Standard Toeplitz hash key size */
 #define TAP_RSS_HASH_KEY_SIZE 40
 
-/* Supported RSS */
-#define TAP_RSS_HF_MASK (~(RTE_ETH_RSS_IP | RTE_ETH_RSS_UDP | RTE_ETH_RSS_TCP))
-
 /* hashed fields for RSS */
 enum hash_field {
 	HASH_FIELD_IPV4_L3,	/* IPv4 src/dst addr */
drivers/net/tap/tap_tcmsgs.h +2 -2
index a64cb29d6f..9411626661 100644
@@ -6,7 +6,6 @@
 #ifndef _TAP_TCMSGS_H_
 #define _TAP_TCMSGS_H_
 
-#include <tap_autoconf.h>
 #include <linux/if_ether.h>
 #include <linux/rtnetlink.h>
 #include <linux/pkt_sched.h>
@@ -14,9 +13,10 @@
 #include <linux/tc_act/tc_mirred.h>
 #include <linux/tc_act/tc_gact.h>
 #include <linux/tc_act/tc_skbedit.h>
-#ifdef HAVE_TC_ACT_BPF
+#ifdef HAVE_BPF_RSS
 #include <linux/tc_act/tc_bpf.h>
 #endif
+
 #include <inttypes.h>
 
 #include <rte_ether.h>
Signature · 1 line
2.43.0
#107 lore raw

PATCH v10 7/9 net/tap: remove no longer used files

In reply to Stephen Hemminger

The BPF api was replaced by use of libbpf.
And the BPF instruction header was replaced by the skeleton.

---
 drivers/net/tap/tap_bpf_api.c   |  196 ----
 drivers/net/tap/tap_bpf_insns.h | 1741 -------------------------------
 2 files changed, 1937 deletions(-)
 delete mode 100644 drivers/net/tap/tap_bpf_api.c
 delete mode 100644 drivers/net/tap/tap_bpf_insns.h
drivers/net/tap/tap_bpf_api.c deleted +0 -196
deleted file mode 100644
index 9e05e2ddf1..0000000000
@@ -1,196 +0,0 @@
-/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright 2017 Mellanox Technologies, Ltd
- */
-
-#include <unistd.h>
-#include <syscall.h>
-#include <linux/bpf.h>
-
-#include <tap_flow.h>
-#include <tap_autoconf.h>
-
-#include <tap_bpf_insns.h>
-
-
-static int bpf_load(enum bpf_prog_type type, const struct bpf_insn *insns,
-		size_t insns_cnt, const char *license);
-
-/**
- * Load BPF program (section cls_q) into the kernel and return a bpf fd
- *
- * @param queue_idx
- *   Queue index matching packet cb
- *
- * @return
- *   -1 if the BPF program couldn't be loaded. An fd (int) otherwise.
- */
-int tap_flow_bpf_cls_q(__u32 queue_idx)
-{
-	cls_q_insns[1].imm = queue_idx;
-
-	return bpf_load(BPF_PROG_TYPE_SCHED_CLS,
-		(struct bpf_insn *)cls_q_insns,
-		RTE_DIM(cls_q_insns),
-		"Dual BSD/GPL");
-}
-
-/**
- * Load BPF program (section l3_l4) into the kernel and return a bpf fd.
- *
- * @param[in] key_idx
- *   RSS MAP key index
- *
- * @param[in] map_fd
- *   BPF RSS map file descriptor
- *
- * @return
- *   -1 if the BPF program couldn't be loaded. An fd (int) otherwise.
- */
-int tap_flow_bpf_calc_l3_l4_hash(__u32 key_idx, int map_fd)
-{
-	l3_l4_hash_insns[4].imm = key_idx;
-	l3_l4_hash_insns[9].imm = map_fd;
-
-	return bpf_load(BPF_PROG_TYPE_SCHED_ACT,
-		(struct bpf_insn *)l3_l4_hash_insns,
-		RTE_DIM(l3_l4_hash_insns),
-		"Dual BSD/GPL");
-}
-
-/**
- * Helper function to convert a pointer to unsigned 64 bits
- *
- * @param[in] ptr
- *   pointer to address
- *
- * @return
- *   64 bit unsigned long type of pointer address
- */
-static inline __u64 ptr_to_u64(const void *ptr)
-{
-	return (__u64)(unsigned long)ptr;
-}
-
-/**
- * Call BPF system call
- *
- * @param[in] cmd
- *   BPF command for program loading, map creation, map entry update, etc
- *
- * @param[in] attr
- *   System call attributes relevant to system call command
- *
- * @param[in] size
- *   size of attr parameter
- *
- * @return
- *   -1 if BPF system call failed, 0 otherwise
- */
-static inline int sys_bpf(enum bpf_cmd cmd, union bpf_attr *attr,
-			unsigned int size)
-{
-#ifdef __NR_bpf
-	return syscall(__NR_bpf, cmd, attr, size);
-#else
-	TAP_LOG(ERR, "No bpf syscall, kernel headers too old?\n");
-	errno = ENOSYS;
-	return -1;
-#endif
-}
-
-/**
- * Load BPF instructions to kernel
- *
- * @param[in] type
- *   BPF program type: classifier or action
- *
- * @param[in] insns
- *   Array of BPF instructions (equivalent to BPF instructions)
- *
- * @param[in] insns_cnt
- *   Number of BPF instructions (size of array)
- *
- * @param[in] license
- *   License string that must be acknowledged by the kernel
- *
- * @return
- *   -1 if the BPF program couldn't be loaded, fd (file descriptor) otherwise
- */
-static int bpf_load(enum bpf_prog_type type,
-		  const struct bpf_insn *insns,
-		  size_t insns_cnt,
-		  const char *license)
-{
-	union bpf_attr attr = {};
-
-	bzero(&attr, sizeof(attr));
-	attr.prog_type = type;
-	attr.insn_cnt = (__u32)insns_cnt;
-	attr.insns = ptr_to_u64(insns);
-	attr.license = ptr_to_u64(license);
-	attr.log_buf = ptr_to_u64(NULL);
-	attr.log_level = 0;
-	attr.kern_version = 0;
-
-	return sys_bpf(BPF_PROG_LOAD, &attr, sizeof(attr));
-}
-
-/**
- * Create BPF map for RSS rules
- *
- * @param[in] key_size
- *   map RSS key size
- *
- * @param[in] value_size
- *   Map RSS value size
- *
- * @param[in] max_entries
- *   Map max number of RSS entries (limit on max RSS rules)
- *
- * @return
- *   -1 if BPF map couldn't be created, map fd otherwise
- */
-int tap_flow_bpf_rss_map_create(unsigned int key_size,
-		unsigned int value_size,
-		unsigned int max_entries)
-{
-	union bpf_attr attr = {};
-
-	bzero(&attr, sizeof(attr));
-	attr.map_type    = BPF_MAP_TYPE_HASH;
-	attr.key_size    = key_size;
-	attr.value_size  = value_size;
-	attr.max_entries = max_entries;
-
-	return sys_bpf(BPF_MAP_CREATE, &attr, sizeof(attr));
-}
-
-/**
- * Update RSS entry in BPF map
- *
- * @param[in] fd
- *   RSS map fd
- *
- * @param[in] key
- *   Pointer to RSS key whose entry is updated
- *
- * @param[in] value
- *   Pointer to RSS new updated value
- *
- * @return
- *   -1 if RSS entry failed to be updated, 0 otherwise
- */
-int tap_flow_bpf_update_rss_elem(int fd, void *key, void *value)
-{
-	union bpf_attr attr = {};
-
-	bzero(&attr, sizeof(attr));
-
-	attr.map_type = BPF_MAP_TYPE_HASH;
-	attr.map_fd = fd;
-	attr.key = ptr_to_u64(key);
-	attr.value = ptr_to_u64(value);
-	attr.flags = BPF_ANY;
-
-	return sys_bpf(BPF_MAP_UPDATE_ELEM, &attr, sizeof(attr));
-}
drivers/net/tap/tap_bpf_insns.h deleted +0 -1741

1,741 lines not on this page · raw message

Signature · 1 line
2.43.0
#108 lore raw

PATCH v10 8/9 net/tap: simplify internals

In reply to Stephen Hemminger

The names of Linux network devices are IFNAMSIZ(16) not the same as DPDK which has up to 64 characters. Don't need to hold onto the whole ifreq to save the remote interface flags.

Make sure packet and byte counters are read once, so that global and per-queue values add up. No need for seperate rx_nombuf counter since there is an alloc_failed value in ethdev.

---
 drivers/net/tap/rte_eth_tap.c | 114 +++++++++++++++++++---------------
 drivers/net/tap/rte_eth_tap.h |  12 ++--
 2 files changed, 71 insertions(+), 55 deletions(-)
drivers/net/tap/rte_eth_tap.c +65 -49
index 793730de08..dd9ecb391d 100644
@@ -46,6 +46,11 @@
 #include <tap_netlink.h>
 #include <tap_tcmsgs.h>
 
+/* Used to snapshot statistics */
+#ifndef READ_ONCE
+#define READ_ONCE(var) (*((volatile typeof(var) *)(&(var))))
+#endif
+
 /* Linux based path to the TUN device */
 #define TUN_TAP_DEV_PATH        "/dev/net/tun"
 #define DEFAULT_TAP_NAME        "dtap"
@@ -212,7 +217,7 @@ tun_alloc(struct pmd_internals *pmd, int is_keepalive, int persistent)
 	 * and need to find the resulting device.
 	 */
 	TAP_LOG(DEBUG, "Device name is '%s'", ifr.ifr_name);
-	strlcpy(pmd->name, ifr.ifr_name, RTE_ETH_NAME_MAX_LEN);
+	strlcpy(pmd->name, ifr.ifr_name, IFNAMSIZ);
 
 	if (is_keepalive) {
 		/*
@@ -466,7 +471,8 @@ pmd_rx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 			struct rte_mbuf *buf = rte_pktmbuf_alloc(rxq->mp);
 
 			if (unlikely(!buf)) {
-				rxq->stats.rx_nombuf++;
+				rte_eth_devices[rxq->in_port].data->rx_mbuf_alloc_failed++;
+
 				/* No new buf has been allocated: do nothing */
 				if (!new_tail || !seg)
 					goto end;
@@ -1047,43 +1053,44 @@ tap_dev_info(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 static int
 tap_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *tap_stats)
 {
-	unsigned int i, imax;
-	unsigned long rx_total = 0, tx_total = 0, tx_err_total = 0;
-	unsigned long rx_bytes_total = 0, tx_bytes_total = 0;
-	unsigned long rx_nombuf = 0, ierrors = 0;
+	unsigned int i;
 	const struct pmd_internals *pmd = dev->data->dev_private;
+	uint64_t bytes, packets;
 
 	/* rx queue statistics */
-	imax = (dev->data->nb_rx_queues < RTE_ETHDEV_QUEUE_STAT_CNTRS) ?
-		dev->data->nb_rx_queues : RTE_ETHDEV_QUEUE_STAT_CNTRS;
-	for (i = 0; i < imax; i++) {
-		tap_stats->q_ipackets[i] = pmd->rxq[i].stats.ipackets;
-		tap_stats->q_ibytes[i] = pmd->rxq[i].stats.ibytes;
-		rx_total += tap_stats->q_ipackets[i];
-		rx_bytes_total += tap_stats->q_ibytes[i];
-		rx_nombuf += pmd->rxq[i].stats.rx_nombuf;
-		ierrors += pmd->rxq[i].stats.ierrors;
+	for (i = 0; i < dev->data->nb_rx_queues; i++) {
+		const struct rx_queue *rxq = &pmd->rxq[i];
+
+		packets = READ_ONCE(rxq->stats.ipackets);
+		bytes = READ_ONCE(rxq->stats.ibytes);
+
+		tap_stats->ipackets += packets;
+		tap_stats->ibytes += bytes;
+		tap_stats->ierrors += rxq->stats.ierrors;
+
+		if (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) {
+			tap_stats->q_ipackets[i] = packets;
+			tap_stats->q_ibytes[i] =  bytes;
+		}
 	}
 
 	/* tx queue statistics */
-	imax = (dev->data->nb_tx_queues < RTE_ETHDEV_QUEUE_STAT_CNTRS) ?
-		dev->data->nb_tx_queues : RTE_ETHDEV_QUEUE_STAT_CNTRS;
-
-	for (i = 0; i < imax; i++) {
-		tap_stats->q_opackets[i] = pmd->txq[i].stats.opackets;
-		tap_stats->q_obytes[i] = pmd->txq[i].stats.obytes;
-		tx_total += tap_stats->q_opackets[i];
-		tx_err_total += pmd->txq[i].stats.errs;
-		tx_bytes_total += tap_stats->q_obytes[i];
-	}
-
-	tap_stats->ipackets = rx_total;
-	tap_stats->ibytes = rx_bytes_total;
-	tap_stats->ierrors = ierrors;
-	tap_stats->rx_nombuf = rx_nombuf;
-	tap_stats->opackets = tx_total;
-	tap_stats->oerrors = tx_err_total;
-	tap_stats->obytes = tx_bytes_total;
+	for (i = 0; i < dev->data->nb_tx_queues; i++) {
+		const struct tx_queue *txq = &pmd->txq[i];
+
+		packets = READ_ONCE(txq->stats.opackets);
+		bytes = READ_ONCE(txq->stats.obytes);
+
+		tap_stats->opackets += packets;
+		tap_stats->obytes += bytes;
+		tap_stats->oerrors += txq->stats.errs;
+
+		if (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) {
+			tap_stats->q_opackets[i] = packets;
+			tap_stats->q_obytes[i] = bytes;
+		}
+	}
+
 	return 0;
 }
 
@@ -1097,7 +1104,6 @@ tap_stats_reset(struct rte_eth_dev *dev)
 		pmd->rxq[i].stats.ipackets = 0;
 		pmd->rxq[i].stats.ibytes = 0;
 		pmd->rxq[i].stats.ierrors = 0;
-		pmd->rxq[i].stats.rx_nombuf = 0;
 
 		pmd->txq[i].stats.opackets = 0;
 		pmd->txq[i].stats.errs = 0;
@@ -1151,9 +1157,13 @@ tap_dev_close(struct rte_eth_dev *dev)
 	}
 
 	if (internals->remote_if_index) {
+		struct ifreq remote_ifr;
+
+		strlcpy(remote_ifr.ifr_name, internals->remote_iface, IFNAMSIZ);
+		remote_ifr.ifr_flags = internals->remote_flags;
+
 		/* Restore initial remote state */
-		int ret = ioctl(internals->ioctl_sock, SIOCSIFFLAGS,
-				&internals->remote_initial_flags);
+		int ret = ioctl(internals->ioctl_sock, SIOCSIFFLAGS, &remote_ifr);
 		if (ret)
 			TAP_LOG(ERR, "restore remote state failed: %d", ret);
 
@@ -2074,16 +2084,22 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 	LIST_INIT(&pmd->flows);
 
 	if (strlen(remote_iface)) {
+		struct ifreq remote_ifr;
+
 		pmd->remote_if_index = if_nametoindex(remote_iface);
 		if (!pmd->remote_if_index) {
 			TAP_LOG(ERR, "%s: failed to get %s if_index.",
 				pmd->name, remote_iface);
 			goto error_remote;
 		}
-		strlcpy(pmd->remote_iface, remote_iface, RTE_ETH_NAME_MAX_LEN);
+		strlcpy(pmd->remote_iface, remote_iface, IFNAMSIZ);
+
+		memset(&remote_ifr, 0, sizeof(ifr));
+		strlcpy(remote_ifr.ifr_name, remote_iface, IFNAMSIZ);
 
 		/* Save state of remote device */
-		tap_ioctl(pmd, SIOCGIFFLAGS, &pmd->remote_initial_flags, 0, REMOTE_ONLY);
+		tap_ioctl(pmd, SIOCGIFFLAGS, &remote_ifr, 0, REMOTE_ONLY);
+		pmd->remote_flags = remote_ifr.ifr_flags;
 
 		/* Replicate remote MAC address */
 		if (tap_ioctl(pmd, SIOCGIFHWADDR, &ifr, 0, REMOTE_ONLY) < 0) {
@@ -2197,10 +2213,10 @@ set_interface_name(const char *key __rte_unused,
 				value);
 			return -1;
 		}
-		strlcpy(name, value, RTE_ETH_NAME_MAX_LEN);
+		strlcpy(name, value, IFNAMSIZ);
 	} else {
 		/* use tap%d which causes kernel to choose next available */
-		strlcpy(name, DEFAULT_TAP_NAME "%d", RTE_ETH_NAME_MAX_LEN);
+		strlcpy(name, DEFAULT_TAP_NAME "%d", IFNAMSIZ);
 	}
 	return 0;
 }
@@ -2218,7 +2234,7 @@ set_remote_iface(const char *key __rte_unused,
 				value);
 			return -1;
 		}
-		strlcpy(name, value, RTE_ETH_NAME_MAX_LEN);
+		strlcpy(name, value, IFNAMSIZ);
 	}
 
 	return 0;
@@ -2269,13 +2285,13 @@ rte_pmd_tun_probe(struct rte_vdev_device *dev)
 	const char *name, *params;
 	int ret;
 	struct rte_kvargs *kvlist = NULL;
-	char tun_name[RTE_ETH_NAME_MAX_LEN];
-	char remote_iface[RTE_ETH_NAME_MAX_LEN];
+	char tun_name[IFNAMSIZ];
+	char remote_iface[IFNAMSIZ];
 	struct rte_eth_dev *eth_dev;
 
 	name = rte_vdev_device_name(dev);
 	params = rte_vdev_device_args(dev);
-	memset(remote_iface, 0, RTE_ETH_NAME_MAX_LEN);
+	memset(remote_iface, 0, IFNAMSIZ);
 
 	if (rte_eal_process_type() == RTE_PROC_SECONDARY &&
 	    strlen(params) == 0) {
@@ -2291,7 +2307,7 @@ rte_pmd_tun_probe(struct rte_vdev_device *dev)
 	}
 
 	/* use tun%d which causes kernel to choose next available */
-	strlcpy(tun_name, DEFAULT_TUN_NAME "%d", RTE_ETH_NAME_MAX_LEN);
+	strlcpy(tun_name, DEFAULT_TUN_NAME "%d", IFNAMSIZ);
 
 	if (params && (params[0] != '\0')) {
 		TAP_LOG(DEBUG, "parameters (%s)", params);
@@ -2431,8 +2447,8 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev)
 	int ret;
 	struct rte_kvargs *kvlist = NULL;
 	int speed;
-	char tap_name[RTE_ETH_NAME_MAX_LEN];
-	char remote_iface[RTE_ETH_NAME_MAX_LEN];
+	char tap_name[IFNAMSIZ];
+	char remote_iface[IFNAMSIZ];
 	struct rte_ether_addr user_mac = { .addr_bytes = {0} };
 	struct rte_eth_dev *eth_dev;
 	int tap_devices_count_increased = 0;
@@ -2486,8 +2502,8 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev)
 	speed = RTE_ETH_SPEED_NUM_10G;
 
 	/* use tap%d which causes kernel to choose next available */
-	strlcpy(tap_name, DEFAULT_TAP_NAME "%d", RTE_ETH_NAME_MAX_LEN);
-	memset(remote_iface, 0, RTE_ETH_NAME_MAX_LEN);
+	strlcpy(tap_name, DEFAULT_TAP_NAME "%d", IFNAMSIZ);
+	memset(remote_iface, 0, IFNAMSIZ);
 
 	if (params && (params[0] != '\0')) {
 		TAP_LOG(DEBUG, "parameters (%s)", params);
drivers/net/tap/rte_eth_tap.h +6 -6
index ce4322ad04..ca510e2c6b 100644
@@ -68,15 +68,16 @@ struct tx_queue {
 
 struct pmd_internals {
 	struct rte_eth_dev *dev;          /* Ethernet device. */
-	char remote_iface[RTE_ETH_NAME_MAX_LEN]; /* Remote netdevice name */
-	char name[RTE_ETH_NAME_MAX_LEN];  /* Internal Tap device name */
+	char remote_iface[IFNAMSIZ];	  /* Remote netdevice name */
+	char name[IFNAMSIZ];		  /* Internal Tap device name */
 	int type;                         /* Type field - TUN|TAP */
 	int persist;			  /* 1 if keep link up, else 0 */
 	struct rte_ether_addr eth_addr;   /* Mac address of the device port */
-	struct ifreq remote_initial_flags;/* Remote netdevice flags on init */
+	uint16_t remote_flags;		  /* Remote netdevice flags on init */
 	int remote_if_index;              /* remote netdevice IF_INDEX */
 	int if_index;                     /* IF_INDEX for the port */
 	int ioctl_sock;                   /* socket for ioctl calls */
+	int ka_fd;                        /* keep-alive file descriptor */
 
 #ifdef HAVE_TCA_FLOWER
 	int nlsk_fd;                      /* Netlink socket fd */
@@ -88,12 +89,11 @@ struct pmd_internals {
 	/* implicit rte_flow rules set when a remote device is active */
 	LIST_HEAD(tap_implicit_flows, rte_flow) implicit_flows;
 #endif
+	struct rte_intr_handle *intr_handle;         /* LSC interrupt handle. */
+	struct rte_mempool *gso_ctx_mp;     /* Mempool for GSO packets */
 
 	struct rx_queue rxq[RTE_PMD_TAP_MAX_QUEUES]; /* List of RX queues */
 	struct tx_queue txq[RTE_PMD_TAP_MAX_QUEUES]; /* List of TX queues */
-	struct rte_intr_handle *intr_handle;         /* LSC interrupt handle. */
-	int ka_fd;                        /* keep-alive file descriptor */
-	struct rte_mempool *gso_ctx_mp;     /* Mempool for GSO packets */
 };
 
 struct pmd_process_private {
Signature · 1 line
2.43.0
#109 lore raw

PATCH v10 9/9 net/tap: update documentation

In reply to Stephen Hemminger

The driver support of flows has changed and the wording in the guide was awkward.

Drop references to DPDK pktgen in this documentation since it is not required and confusing.

---
 doc/guides/nics/tap.rst                | 274 +++++++------------------
 doc/guides/rel_notes/release_24_07.rst |   7 +
 2 files changed, 84 insertions(+), 197 deletions(-)
doc/guides/nics/tap.rst +77 -197
index d4f45c02a1..55e38fb25b 100644
@@ -1,47 +1,51 @@
 ..  SPDX-License-Identifier: BSD-3-Clause
     Copyright(c) 2016 Intel Corporation.
 
-Tun|Tap Poll Mode Driver
-========================
+TAP Poll Mode Driver
+====================
 
-The ``rte_eth_tap.c`` PMD creates a device using TAP interfaces on the
-local host. The PMD allows for DPDK and the host to communicate using a raw
-device interface on the host and in the DPDK application.
+The TAP Poll Mode Driver (PMD) is a virtual device for injecting packets to be processed
+by the Linux kernel. This PMD is useful when writing DPDK application
+for offloading network functionality (such as tunneling) from the kernel.
 
-The device created is a TAP device, which sends/receives packet in a raw
-format with a L2 header. The usage for a TAP PMD is for connectivity to the
-local host using a TAP interface. When the TAP PMD is initialized it will
-create a number of tap devices in the host accessed via ``ifconfig -a`` or
-``ip`` command. The commands can be used to assign and query the virtual like
-device.
+From the kernel point of view, the TAP device looks like a regular network interface.
+The network device can be managed by standard tools such as ``ip`` and ``ethtool`` commands.
+It is also possible to use existing packet tools such as  ``wireshark`` or ``tcpdump``.
 
-These TAP interfaces can be used with Wireshark or tcpdump or Pktgen-DPDK
-along with being able to be used as a network connection to the DPDK
-application. The method enable one or more interfaces is to use the
-``--vdev=net_tap0`` option on the DPDK application command line. Each
-``--vdev=net_tap1`` option given will create an interface named dtap0, dtap1,
-and so on.
+From the DPDK application, the TAP device looks like a DPDK ethdev.
+Packets are sent and received in L2 (Ethernet) format. The standare DPDK
+API's to query for information, statistics and send and receive packets
+work as expected.
 
-The interface name can be changed by adding the ``iface=foo0``, for example::
+Requirements
+~~~~~~~~~~~~
+
+The TAP PMD requires kernel support for multiple queues in TAP device as
+well as the multi-queue ``multiq`` and incoming ``ingress`` queue disciplines.
+These are standard kernel features in most Linux distributions.
+
+Arguments
+---------
+
+TAP devices are created with the command line
+``--vdev=net_tap0`` option. This option maybe specified more the once by repeating
+with a different ``net_tapX`` device.
+
+By default, the Linux interfaces are named ``dtap0``, ``dtap1``, etc.
+The interface name can be specified by adding the ``iface=foo0``, for example::
 
    --vdev=net_tap0,iface=foo0 --vdev=net_tap1,iface=foo1, ...
 
-Normally the PMD will generate a random MAC address, but when testing or with
-a static configuration the developer may need a fixed MAC address style.
-Using the option ``mac=fixed`` you can create a fixed known MAC address::
+Normally the PMD will generate a random MAC address.
+If a static address is desired instead, the ``mac=fixed`` can be used.
 
    --vdev=net_tap0,mac=fixed
 
-The MAC address will have a fixed value with the last octet incrementing by one
-for each interface string containing ``mac=fixed``. The MAC address is formatted
-as 02:'d':'t':'a':'p':[00-FF]. Convert the characters to hex and you get the
-actual MAC address: ``02:64:74:61:70:[00-FF]``.
-
-   --vdev=net_tap0,mac="02:64:74:61:70:11"
+With the fixed option, the MAC address will have the first octets:
+as 02:'d':'t':'a':'p':[00-FF] and the last octets are the interface number.
 
-The MAC address will have a user value passed as string. The MAC address is in
-format with delimiter ``:``. The string is byte converted to hex and you get
-the actual MAC address: ``02:64:74:61:70:11``.
+To specify a specific MAC address use the conventional representation.
+The string is byte converted to hex, the result is MAC address: ``02:64:74:61:70:11``.
 
 It is possible to specify a remote netdevice to capture packets from by adding
 ``remote=foo1``, for example::
@@ -59,40 +63,20 @@ netdevice that has no support in the DPDK. It is possible to add explicit
 rte_flow rules on the tap PMD to capture specific traffic (see next section for
 examples).
 
-After the DPDK application is started you can send and receive packets on the
-interface using the standard rx_burst/tx_burst APIs in DPDK. From the host
-point of view you can use any host tool like tcpdump, Wireshark, ping, Pktgen
-and others to communicate with the DPDK application. The DPDK application may
-not understand network protocols like IPv4/6, UDP or TCP unless the
-application has been written to understand these protocols.
-
-If you need the interface as a real network interface meaning running and has
-a valid IP address then you can do this with the following commands::
-
-   sudo ip link set dtap0 up; sudo ip addr add 192.168.0.250/24 dev dtap0
-   sudo ip link set dtap1 up; sudo ip addr add 192.168.1.250/24 dev dtap1
-
-Please change the IP addresses as you see fit.
-
-If routing is enabled on the host you can also communicate with the DPDK App
-over the internet via a standard socket layer application as long as you
-account for the protocol handling in the application.
-
-If you have a Network Stack in your DPDK application or something like it you
-can utilize that stack to handle the network protocols. Plus you would be able
-to address the interface using an IP address assigned to the internal
-interface.
-
 Normally, when the DPDK application exits,
 the TAP device is marked down and is removed.
-But this behaviour can be overridden by the use of the persist flag, example::
+But this behavior can be overridden by the use of the persist flag, example::
 
   --vdev=net_tap0,iface=tap0,persist ...
 
-The TUN PMD allows user to create a TUN device on host. The PMD allows user
-to transmit and receive packets via DPDK API calls with L3 header and payload.
-The devices in host can be accessed via ``ifconfig`` or ``ip`` command. TUN
-interfaces are passed to DPDK ``rte_eal_init`` arguments as ``--vdev=net_tunX``,
+TUN devices
+-----------
+
+The TAP device can be used an L3 tunnel only device (TUN).
+This type of device does not include the Ethernet (L2) header; all packets
+are sent and received as IP packets.
+
+TUN devices are created with the command line arguments ``--vdev=net_tunX``,
 where X stands for unique id, example::
 
    --vdev=net_tun0 --vdev=net_tun1,iface=foo1, ...
@@ -103,27 +87,33 @@ options. Default interface name is ``dtunX``, where X stands for unique id.
 Flow API support
 ----------------
 
-The tap PMD supports major flow API pattern items and actions, when running on
-linux kernels above 4.2 ("Flower" classifier required).
-The kernel support can be checked with this command::
+The TAP PMD supports major flow API pattern items and actions.
+
+Requirements
+~~~~~~~~~~~~
 
-   zcat /proc/config.gz | ( grep 'CLS_FLOWER=' || echo 'not supported' ) |
-   tee -a /dev/stderr | grep -q '=m' &&
-   lsmod | ( grep cls_flower || echo 'try modprobe cls_flower' )
+Flow support in TAP driver requires the Linux kernel support of flow based
+traffic control filter ``flower``. This was added in Linux 4.3 kernel.
 
-Supported items:
+The implementation of RSS action uses an eBPF module that requires additional
+libraries and tools. Building the RSS support requires the ``clang``
+compiler to compile the C code to BPF target; ``bpftool`` to convert the
+compiled BPF object to a header file; and ``libbpf`` to load the eBPF
+action into the kernel.
 
-- eth: src and dst (with variable masks), and eth_type (0xffff mask).
-- vlan: vid, pcp, but not eid. (requires kernel 4.9)
-- ipv4/6: src and dst (with variable masks), and ip_proto (0xffff mask).
-- udp/tcp: src and dst port (0xffff) mask.
+Supported match items:
+
+  - eth: src and dst (with variable masks), and eth_type (0xffff mask).
+  - vlan: vid, pcp, but not eid. (requires kernel 4.9)
+  - ipv4/6: src and dst (with variable masks), and ip_proto (0xffff mask).
+  - udp/tcp: src and dst port (0xffff) mask.
 
 Supported actions:
 
 - DROP
 - QUEUE
 - PASSTHRU
-- RSS (requires kernel 4.9)
+- RSS
 
 It is generally not possible to provide a "last" item. However, if the "last"
 item, once masked, is identical to the masked spec, then it is supported.
@@ -133,7 +123,7 @@ full mask (exact match).
 
 As rules are translated to TC, it is possible to show them with something like::
 
-   tc -s filter show dev tap1 parent 1:
+   tc -s filter show dev dtap1 parent 1:
 
 Examples of testpmd flow rules
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -174,135 +164,25 @@ The IPC synchronization of Rx/Tx queues is currently limited:
   - Maximum 8 queues shared
   - Synchronized on probing, but not on later port update
 
-Example
--------
-
-The following is a simple example of using the TAP PMD with the Pktgen
-packet generator. It requires that the ``socat`` utility is installed on the
-test system.
-
-Build DPDK, then pull down Pktgen and build pktgen using the DPDK SDK/Target
-used to build the dpdk you pulled down.
-
-Run pktgen from the pktgen directory in a terminal with a commandline like the
-following::
-
-    sudo ./app/app/x86_64-native-linux-gcc/app/pktgen -l 1-5 -n 4        \
-     --proc-type auto --log-level debug --socket-mem 512,512 --file-prefix pg   \
-     --vdev=net_tap0 --vdev=net_tap1 -b 05:00.0 -b 05:00.1                  \
-     -b 04:00.0 -b 04:00.1 -b 04:00.2 -b 04:00.3                            \
-     -b 81:00.0 -b 81:00.1 -b 81:00.2 -b 81:00.3                            \
-     -b 82:00.0 -b 83:00.0 -- -T -P -m [2:3].0 -m [4:5].1                   \
-     -f themes/black-yellow.theme
-
-.. Note:
-
-   Change the ``-b`` options to exclude all of your physical ports. The
-   following command line is all one line.
-
-   Also, ``-f themes/black-yellow.theme`` is optional if the default colors
-   work on your system configuration. See the Pktgen docs for more
-   information.
-
-Verify with ``ifconfig -a`` command in a different xterm window, should have a
-``dtap0`` and ``dtap1`` interfaces created.
-
-Next set the links for the two interfaces to up via the commands below::
-
-    sudo ip link set dtap0 up; sudo ip addr add 192.168.0.250/24 dev dtap0
-    sudo ip link set dtap1 up; sudo ip addr add 192.168.1.250/24 dev dtap1
-
-Then use socat to create a loopback for the two interfaces::
-
-    sudo socat interface:dtap0 interface:dtap1
-
-Then on the Pktgen command line interface you can start sending packets using
-the commands ``start 0`` and ``start 1`` or you can start both at the same
-time with ``start all``. The command ``str`` is an alias for ``start all`` and
-``stp`` is an alias for ``stop all``.
-
-While running you should see the 64 byte counters increasing to verify the
-traffic is being looped back. You can use ``set all size XXX`` to change the
-size of the packets after you stop the traffic. Use pktgen ``help``
-command to see a list of all commands. You can also use the ``-f`` option to
-load commands at startup in command line or Lua script in pktgen.
 
 RSS specifics
 -------------
-Packet distribution in TAP is done by the kernel which has a default
-distribution. This feature is adding RSS distribution based on eBPF code.
-The default eBPF code calculates RSS hash based on Toeplitz algorithm for
-a fixed RSS key. It is calculated on fixed packet offsets. For IPv4 and IPv6 it
-is calculated over src/dst addresses (8 or 32 bytes for IPv4 or IPv6
-respectively) and src/dst TCP/UDP ports (4 bytes).
-
-The RSS algorithm is written in file ``tap_bpf_program.c`` which
-does not take part in TAP PMD compilation. Instead this file is compiled
-in advance to eBPF object file. The eBPF object file is then parsed and
-translated into eBPF byte code in the format of C arrays of eBPF
-instructions. The C array of eBPF instructions is part of TAP PMD tree and
-is taking part in TAP PMD compilation. At run time the C arrays are uploaded to
-the kernel via BPF system calls and the RSS hash is calculated by the
-kernel.
-
-It is possible to support different RSS hash algorithms by updating file
-``tap_bpf_program.c``  In order to add a new RSS hash algorithm follow these
-steps:
-
-#. Write the new RSS implementation in file ``tap_bpf_program.c``
-
-   BPF programs which are uploaded to the kernel correspond to
-   C functions under different ELF sections.
-
-#. Install ``LLVM`` library and ``clang`` compiler versions 3.7 and above
-
-#. Use make to compile  `tap_bpf_program.c`` via ``LLVM`` into an object file
-   and extract the resulting instructions into ``tap_bpf_insn.h``::
-
-    cd bpf; make
-
-#. Recompile the TAP PMD.
-
-The C arrays are uploaded to the kernel using BPF system calls.
-
-``tc`` (traffic control) is a well known user space utility program used to
-configure the Linux kernel packet scheduler. It is usually packaged as
-part of the ``iproute2`` package.
-Since commit 11c39b5e9 ("tc: add eBPF support to f_bpf") ``tc`` can be used
-to uploads eBPF code to the kernel and can be patched in order to print the
-C arrays of eBPF instructions just before calling the BPF system call.
-Please refer to ``iproute2`` package file ``lib/bpf.c`` function
-``bpf_prog_load()``.
-
-An example utility for eBPF instruction generation in the format of C arrays will
-be added in next releases
-
-TAP reports on supported RSS functions as part of dev_infos_get callback:
-``RTE_ETH_RSS_IP``, ``RTE_ETH_RSS_UDP`` and ``RTE_ETH_RSS_TCP``.
-**Known limitation:** TAP supports all of the above hash functions together
-and not in partial combinations.
-
-Systems supporting flow API
----------------------------
-
-- "tc flower" classifier requires linux kernel above 4.2
-- eBPF/RSS requires linux kernel above 4.9
-
-+--------------------+-----------------------+
-| RH7.3              | No flow rule support  |
-+--------------------+-----------------------+
-| RH7.4              | No RSS action support |
-+--------------------+-----------------------+
-| RH7.5              | No RSS action support |
-+--------------------+-----------------------+
-| SLES 15,           | No limitation         |
-| kernel 4.12        |                       |
-+--------------------+-----------------------+
-| Azure Ubuntu 16.04,| No limitation         |
-| kernel 4.13        |                       |
-+--------------------+-----------------------+
+The default packet distribution in TAP without flow rules is done by the
+kernel which has a default flow based distribution.
+When flow rules are used to distribute packets across a set of queues
+an eBPF program is used to calculate the RSS based on Toeplitz algorithm for
+with the given key.
+
+The hash is calculated for IPv4 and IPv6, over src/dst addresses
+(8 or 32 bytes for IPv4 or IPv6 respectively) and
+optionally the src/dst TCP/UDP ports (4 bytes).
+
 
 Limitations
 -----------
 
-* Rx/Tx must have the same number of queues.
+- Since TAP device uses a file descriptors to talk to the kernel.
+  The same number of queues must be specified for receive and transmit.
+
+- The RSS algorithm only support L3 or L4 functions. It does not support
+  finer grain selections (for example: only IPV6 packets with extension headers).
doc/guides/rel_notes/release_24_07.rst +7 -0
index a69f24cf99..8652271ed2 100644
@@ -55,6 +55,13 @@ New Features
      Also, make sure to start the actual text at the margin.
      =======================================================
 
+* **TAP PMD updates.**
+
+  * Fixed support of RSS flow action to work with current Linux
+    kernels and BPF tooling. Will only be enabled if clang and bpftool
+    are available.
+
+  * Support up to 8 queues when used by secondary process
 
 Removed Items
 -------------
Signature · 1 line
2.43.0
#110 lore raw

v11 cover net/tap fix RSS (BPF) flow support

In reply to Stephen Hemminger

The support of doing RSS for rte_flow_action was a cool idea but it has been broken for several releases of DPDK as the kernel and BPF infrastructure changed.

This series cleans up the BPF program, implements several features that were never completed in the original code and changes to use the current BPF toolchain.

The result should be easier to read and maintain. I do not intend to support backporting this to stable releases due to lack of demand and dealing with older distros.

v11 - checkpatch and review comments
add bugzilla id's

Stephen Hemminger (9):
net/tap: do not duplicate fd's
net/tap: remove unused fields
net/tap: validate and setup parameters for BPF RSS net/tap: do not build flow support if header is out of date net/tap: rewrite the RSS BPF program
net/tap: use libbpf to load new BPF program net/tap: remove no longer used files
net/tap: simplify internals
net/tap: update documentation

 .gitignore                             |    3 -
 doc/guides/nics/tap.rst                |  274 ++--
 doc/guides/rel_notes/release_24_07.rst |    7 +
 drivers/net/tap/bpf/Makefile           |   19 -
 drivers/net/tap/bpf/README             |   49 +
 drivers/net/tap/bpf/bpf_api.h          |  276 ----
 drivers/net/tap/bpf/bpf_elf.h          |   53 -
 drivers/net/tap/bpf/bpf_extract.py     |   86 --
 drivers/net/tap/bpf/meson.build        |  107 ++
 drivers/net/tap/bpf/tap_bpf_program.c  |  255 ----
 drivers/net/tap/bpf/tap_rss.c          |  267 ++++
 drivers/net/tap/meson.build            |   42 +-
 drivers/net/tap/rte_eth_tap.c          |  334 ++---
 drivers/net/tap/rte_eth_tap.h          |   32 +-
 drivers/net/tap/tap_bpf.h              |  121 --
 drivers/net/tap/tap_bpf_api.c          |  190 ---
 drivers/net/tap/tap_bpf_insns.h        | 1743 ------------------------
 drivers/net/tap/tap_flow.c             |  557 ++------
 drivers/net/tap/tap_flow.h             |   17 +-
 drivers/net/tap/tap_intr.c             |    7 +-
 drivers/net/tap/tap_rss.h              |   21 +-
 drivers/net/tap/tap_tcmsgs.h           |    4 +-
 22 files changed, 881 insertions(+), 3583 deletions(-)
 delete mode 100644 drivers/net/tap/bpf/Makefile
 create mode 100644 drivers/net/tap/bpf/README
 delete mode 100644 drivers/net/tap/bpf/bpf_api.h
 delete mode 100644 drivers/net/tap/bpf/bpf_elf.h
 delete mode 100644 drivers/net/tap/bpf/bpf_extract.py
 create mode 100644 drivers/net/tap/bpf/meson.build
 delete mode 100644 drivers/net/tap/bpf/tap_bpf_program.c
 create mode 100644 drivers/net/tap/bpf/tap_rss.c
 delete mode 100644 drivers/net/tap/tap_bpf.h
 delete mode 100644 drivers/net/tap/tap_bpf_api.c
 delete mode 100644 drivers/net/tap/tap_bpf_insns.h
Signature · 1 line
2.43.0
#111 lore raw

PATCH v11 1/9 net/tap: do not duplicate fd's

The TAP device can use same file descriptor for both rx and tx queues. This allows up to 8 queues (versus 4) to be used with secondary process.

Bugzilla ID: 1381

---
 drivers/net/tap/rte_eth_tap.c | 192 ++++++++++++++--------------------
 drivers/net/tap/rte_eth_tap.h |   3 +-
 drivers/net/tap/tap_flow.c    |   3 +-
 drivers/net/tap/tap_intr.c    |   7 +-
 4 files changed, 85 insertions(+), 120 deletions(-)
drivers/net/tap/rte_eth_tap.c +78 -114
index 69d9da695b..b84fc01856 100644
@@ -124,8 +124,7 @@ enum ioctl_mode {
 /* Message header to synchronize queues via IPC */
 struct ipc_queues {
 	char port_name[RTE_DEV_NAME_MAX_LEN];
-	int rxq_count;
-	int txq_count;
+	int q_count;
 	/*
 	 * The file descriptors are in the dedicated part
 	 * of the Unix message to be translated by the kernel.
@@ -446,7 +445,7 @@ pmd_rx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 		uint16_t data_off = rte_pktmbuf_headroom(mbuf);
 		int len;
 
-		len = readv(process_private->rxq_fds[rxq->queue_id],
+		len = readv(process_private->fds[rxq->queue_id],
 			*rxq->iovecs,
 			1 + (rxq->rxmode->offloads & RTE_ETH_RX_OFFLOAD_SCATTER ?
 			     rxq->nb_rx_desc : 1));
@@ -643,7 +642,7 @@ tap_write_mbufs(struct tx_queue *txq, uint16_t num_mbufs,
 		}
 
 		/* copy the tx frame data */
-		n = writev(process_private->txq_fds[txq->queue_id], iovecs, k);
+		n = writev(process_private->fds[txq->queue_id], iovecs, k);
 		if (n <= 0)
 			return -1;
 
@@ -851,7 +850,6 @@ tap_mp_req_on_rxtx(struct rte_eth_dev *dev)
 	struct rte_mp_msg msg;
 	struct ipc_queues *request_param = (struct ipc_queues *)msg.param;
 	int err;
-	int fd_iterator = 0;
 	struct pmd_process_private *process_private = dev->process_private;
 	int i;
 
@@ -859,16 +857,13 @@ tap_mp_req_on_rxtx(struct rte_eth_dev *dev)
 	strlcpy(msg.name, TAP_MP_REQ_START_RXTX, sizeof(msg.name));
 	strlcpy(request_param->port_name, dev->data->name, sizeof(request_param->port_name));
 	msg.len_param = sizeof(*request_param);
-	for (i = 0; i < dev->data->nb_tx_queues; i++) {
-		msg.fds[fd_iterator++] = process_private->txq_fds[i];
-		msg.num_fds++;
-		request_param->txq_count++;
-	}
-	for (i = 0; i < dev->data->nb_rx_queues; i++) {
-		msg.fds[fd_iterator++] = process_private->rxq_fds[i];
-		msg.num_fds++;
-		request_param->rxq_count++;
-	}
+
+	/* rx and tx share file descriptors and nb_tx_queues == nb_rx_queues */
+	for (i = 0; i < dev->data->nb_rx_queues; i++)
+		msg.fds[i] = process_private->fds[i];
+
+	request_param->q_count = dev->data->nb_rx_queues;
+	msg.num_fds = dev->data->nb_rx_queues;
 
 	err = rte_mp_sendmsg(&msg);
 	if (err < 0) {
@@ -910,8 +905,6 @@ tap_mp_req_start_rxtx(const struct rte_mp_msg *request, __rte_unused const void
 	struct rte_eth_dev *dev;
 	const struct ipc_queues *request_param =
 		(const struct ipc_queues *)request->param;
-	int fd_iterator;
-	int queue;
 	struct pmd_process_private *process_private;
 
 	dev = rte_eth_dev_get_by_name(request_param->port_name);
@@ -920,14 +913,13 @@ tap_mp_req_start_rxtx(const struct rte_mp_msg *request, __rte_unused const void
 			request_param->port_name);
 		return -1;
 	}
+
 	process_private = dev->process_private;
-	fd_iterator = 0;
-	TAP_LOG(DEBUG, "tap_attach rx_q:%d tx_q:%d\n", request_param->rxq_count,
-		request_param->txq_count);
-	for (queue = 0; queue < request_param->txq_count; queue++)
-		process_private->txq_fds[queue] = request->fds[fd_iterator++];
-	for (queue = 0; queue < request_param->rxq_count; queue++)
-		process_private->rxq_fds[queue] = request->fds[fd_iterator++];
+	TAP_LOG(DEBUG, "tap_attach q:%d\n", request_param->q_count);
+
+	for (int q = 0; q < request_param->q_count; q++)
+		process_private->fds[q] = request->fds[q];
+
 
 	return 0;
 }
@@ -1115,13 +1107,21 @@ tap_stats_reset(struct rte_eth_dev *dev)
 	return 0;
 }
 
+static void
+tap_queue_close(struct pmd_process_private *process_private, uint16_t qid)
+{
+	if (process_private->fds[qid] != -1) {
+		close(process_private->fds[qid]);
+		process_private->fds[qid] = -1;
+	}
+}
+
 static int
 tap_dev_close(struct rte_eth_dev *dev)
 {
 	int i;
 	struct pmd_internals *internals = dev->data->dev_private;
 	struct pmd_process_private *process_private = dev->process_private;
-	struct rx_queue *rxq;
 
 	if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
 		rte_free(dev->process_private);
@@ -1141,19 +1141,14 @@ tap_dev_close(struct rte_eth_dev *dev)
 	}
 
 	for (i = 0; i < RTE_PMD_TAP_MAX_QUEUES; i++) {
-		if (process_private->rxq_fds[i] != -1) {
-			rxq = &internals->rxq[i];
-			close(process_private->rxq_fds[i]);
-			process_private->rxq_fds[i] = -1;
-			tap_rxq_pool_free(rxq->pool);
-			rte_free(rxq->iovecs);
-			rxq->pool = NULL;
-			rxq->iovecs = NULL;
-		}
-		if (process_private->txq_fds[i] != -1) {
-			close(process_private->txq_fds[i]);
-			process_private->txq_fds[i] = -1;
-		}
+		struct rx_queue *rxq = &internals->rxq[i];
+
+		tap_queue_close(process_private, i);
+
+		tap_rxq_pool_free(rxq->pool);
+		rte_free(rxq->iovecs);
+		rxq->pool = NULL;
+		rxq->iovecs = NULL;
 	}
 
 	if (internals->remote_if_index) {
@@ -1206,15 +1201,16 @@ tap_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
 
 	if (!rxq)
 		return;
+
 	process_private = rte_eth_devices[rxq->in_port].process_private;
-	if (process_private->rxq_fds[rxq->queue_id] != -1) {
-		close(process_private->rxq_fds[rxq->queue_id]);
-		process_private->rxq_fds[rxq->queue_id] = -1;
-		tap_rxq_pool_free(rxq->pool);
-		rte_free(rxq->iovecs);
-		rxq->pool = NULL;
-		rxq->iovecs = NULL;
-	}
+
+	tap_rxq_pool_free(rxq->pool);
+	rte_free(rxq->iovecs);
+	rxq->pool = NULL;
+	rxq->iovecs = NULL;
+
+	if (dev->data->tx_queues[qid] == NULL)
+		tap_queue_close(process_private, qid);
 }
 
 static void
@@ -1225,12 +1221,10 @@ tap_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
 
 	if (!txq)
 		return;
-	process_private = rte_eth_devices[txq->out_port].process_private;
 
-	if (process_private->txq_fds[txq->queue_id] != -1) {
-		close(process_private->txq_fds[txq->queue_id]);
-		process_private->txq_fds[txq->queue_id] = -1;
-	}
+	process_private = rte_eth_devices[txq->out_port].process_private;
+	if (dev->data->rx_queues[qid] == NULL)
+		tap_queue_close(process_private, qid);
 }
 
 static int
@@ -1482,52 +1476,31 @@ tap_setup_queue(struct rte_eth_dev *dev,
 		uint16_t qid,
 		int is_rx)
 {
-	int ret;
-	int *fd;
-	int *other_fd;
-	const char *dir;
+	int fd, ret;
 	struct pmd_internals *pmd = dev->data->dev_private;
 	struct pmd_process_private *process_private = dev->process_private;
 	struct rx_queue *rx = &internals->rxq[qid];
 	struct tx_queue *tx = &internals->txq[qid];
-	struct rte_gso_ctx *gso_ctx;
+	struct rte_gso_ctx *gso_ctx = is_rx ? NULL : &tx->gso_ctx;
+	const char *dir = is_rx ? "rx" : "tx";
 
-	if (is_rx) {
-		fd = &process_private->rxq_fds[qid];
-		other_fd = &process_private->txq_fds[qid];
-		dir = "rx";
-		gso_ctx = NULL;
-	} else {
-		fd = &process_private->txq_fds[qid];
-		other_fd = &process_private->rxq_fds[qid];
-		dir = "tx";
-		gso_ctx = &tx->gso_ctx;
-	}
-	if (*fd != -1) {
+	fd = process_private->fds[qid];
+	if (fd != -1) {
 		/* fd for this queue already exists */
 		TAP_LOG(DEBUG, "%s: fd %d for %s queue qid %d exists",
-			pmd->name, *fd, dir, qid);
+			pmd->name, fd, dir, qid);
 		gso_ctx = NULL;
-	} else if (*other_fd != -1) {
-		/* Only other_fd exists. dup it */
-		*fd = dup(*other_fd);
-		if (*fd < 0) {
-			*fd = -1;
-			TAP_LOG(ERR, "%s: dup() failed.", pmd->name);
-			return -1;
-		}
-		TAP_LOG(DEBUG, "%s: dup fd %d for %s queue qid %d (%d)",
-			pmd->name, *other_fd, dir, qid, *fd);
 	} else {
-		/* Both RX and TX fds do not exist (equal -1). Create fd */
-		*fd = tun_alloc(pmd, 0, 0);
-		if (*fd < 0) {
-			*fd = -1; /* restore original value */
+		fd = tun_alloc(pmd, 0, 0);
+		if (fd < 0) {
 			TAP_LOG(ERR, "%s: tun_alloc() failed.", pmd->name);
 			return -1;
 		}
+
 		TAP_LOG(DEBUG, "%s: add %s queue for qid %d fd %d",
-			pmd->name, dir, qid, *fd);
+			pmd->name, dir, qid, fd);
+
+		process_private->fds[qid] = fd;
 	}
 
 	tx->mtu = &dev->data->mtu;
@@ -1540,7 +1513,7 @@ tap_setup_queue(struct rte_eth_dev *dev,
 
 	tx->type = pmd->type;
 
-	return *fd;
+	return fd;
 }
 
 static int
@@ -1620,7 +1593,7 @@ tap_rx_queue_setup(struct rte_eth_dev *dev,
 
 	TAP_LOG(DEBUG, "  RX TUNTAP device name %s, qid %d on fd %d",
 		internals->name, rx_queue_id,
-		process_private->rxq_fds[rx_queue_id]);
+		process_private->fds[rx_queue_id]);
 
 	return 0;
 
@@ -1664,7 +1637,7 @@ tap_tx_queue_setup(struct rte_eth_dev *dev,
 	TAP_LOG(DEBUG,
 		"  TX TUNTAP device name %s, qid %d on fd %d csum %s",
 		internals->name, tx_queue_id,
-		process_private->txq_fds[tx_queue_id],
+		process_private->fds[tx_queue_id],
 		txq->csum ? "on" : "off");
 
 	return 0;
@@ -2001,10 +1974,9 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 	dev->intr_handle = pmd->intr_handle;
 
 	/* Presetup the fds to -1 as being not valid */
-	for (i = 0; i < RTE_PMD_TAP_MAX_QUEUES; i++) {
-		process_private->rxq_fds[i] = -1;
-		process_private->txq_fds[i] = -1;
-	}
+	for (i = 0; i < RTE_PMD_TAP_MAX_QUEUES; i++)
+		process_private->fds[i] = -1;
+
 
 	if (pmd->type == ETH_TUNTAP_TYPE_TAP) {
 		if (rte_is_zero_ether_addr(mac_addr))
@@ -2332,7 +2304,6 @@ tap_mp_attach_queues(const char *port_name, struct rte_eth_dev *dev)
 	struct ipc_queues *request_param = (struct ipc_queues *)request.param;
 	struct ipc_queues *reply_param;
 	struct pmd_process_private *process_private = dev->process_private;
-	int queue, fd_iterator;
 
 	/* Prepare the request */
 	memset(&request, 0, sizeof(request));
@@ -2352,18 +2323,17 @@ tap_mp_attach_queues(const char *port_name, struct rte_eth_dev *dev)
 	TAP_LOG(DEBUG, "Received IPC reply for %s", reply_param->port_name);
 
 	/* Attach the queues from received file descriptors */
-	if (reply_param->rxq_count + reply_param->txq_count != reply->num_fds) {
+	if (reply_param->q_count != reply->num_fds) {
 		TAP_LOG(ERR, "Unexpected number of fds received");
 		return -1;
 	}
 
-	dev->data->nb_rx_queues = reply_param->rxq_count;
-	dev->data->nb_tx_queues = reply_param->txq_count;
-	fd_iterator = 0;
-	for (queue = 0; queue < reply_param->rxq_count; queue++)
-		process_private->rxq_fds[queue] = reply->fds[fd_iterator++];
-	for (queue = 0; queue < reply_param->txq_count; queue++)
-		process_private->txq_fds[queue] = reply->fds[fd_iterator++];
+	dev->data->nb_rx_queues = reply_param->q_count;
+	dev->data->nb_tx_queues = reply_param->q_count;
+
+	for (int q = 0; q < reply_param->q_count; q++)
+		process_private->fds[q] = reply->fds[q];
+
 	free(reply);
 	return 0;
 }
@@ -2393,25 +2363,19 @@ tap_mp_sync_queues(const struct rte_mp_msg *request, const void *peer)
 
 	/* Fill file descriptors for all queues */
 	reply.num_fds = 0;
-	reply_param->rxq_count = 0;
-	if (dev->data->nb_rx_queues + dev->data->nb_tx_queues >
-			RTE_MP_MAX_FD_NUM){
-		TAP_LOG(ERR, "Number of rx/tx queues exceeds max number of fds");
+	reply_param->q_count = 0;
+
+	RTE_ASSERT(dev->data->nb_rx_queues == dev->data->nb_tx_queues);
+	if (dev->data->nb_rx_queues > RTE_MP_MAX_FD_NUM) {
+		TAP_LOG(ERR, "Number of rx/tx queues %u exceeds max number of fds %u",
+			dev->data->nb_rx_queues, RTE_MP_MAX_FD_NUM);
 		return -1;
 	}
 
 	for (queue = 0; queue < dev->data->nb_rx_queues; queue++) {
-		reply.fds[reply.num_fds++] = process_private->rxq_fds[queue];
-		reply_param->rxq_count++;
-	}
-	RTE_ASSERT(reply_param->rxq_count == dev->data->nb_rx_queues);
-
-	reply_param->txq_count = 0;
-	for (queue = 0; queue < dev->data->nb_tx_queues; queue++) {
-		reply.fds[reply.num_fds++] = process_private->txq_fds[queue];
-		reply_param->txq_count++;
+		reply.fds[reply.num_fds++] = process_private->fds[queue];
+		reply_param->q_count++;
 	}
-	RTE_ASSERT(reply_param->txq_count == dev->data->nb_tx_queues);
 
 	/* Send reply */
 	strlcpy(reply.name, request->name, sizeof(reply.name));
drivers/net/tap/rte_eth_tap.h +1 -2
index 5ac93f93e9..dc8201020b 100644
@@ -96,8 +96,7 @@ struct pmd_internals {
 };
 
 struct pmd_process_private {
-	int rxq_fds[RTE_PMD_TAP_MAX_QUEUES];
-	int txq_fds[RTE_PMD_TAP_MAX_QUEUES];
+	int fds[RTE_PMD_TAP_MAX_QUEUES];
 };
 
 /* tap_intr.c */
drivers/net/tap/tap_flow.c +2 -1
index fa50fe45d7..a78fd50cd4 100644
@@ -1595,8 +1595,9 @@ tap_flow_isolate(struct rte_eth_dev *dev,
 	 * If netdevice is there, setup appropriate flow rules immediately.
 	 * Otherwise it will be set when bringing up the netdevice (tun_alloc).
 	 */
-	if (!process_private->rxq_fds[0])
+	if (process_private->fds[0] == -1)
 		return 0;
+
 	if (set) {
 		struct rte_flow *remote_flow;
 
drivers/net/tap/tap_intr.c +4 -3
index a9097def1a..1908f71f97 100644
@@ -68,9 +68,11 @@ tap_rx_intr_vec_install(struct rte_eth_dev *dev)
 	}
 	for (i = 0; i < n; i++) {
 		struct rx_queue *rxq = pmd->dev->data->rx_queues[i];
+		int fd = process_private->fds[i];
 
 		/* Skip queues that cannot request interrupts. */
-		if (!rxq || process_private->rxq_fds[i] == -1) {
+		if (!rxq || fd == -1) {
+			/* Use invalid intr_vec[] index to disable entry. */
 			/* Use invalid intr_vec[] index to disable entry. */
 			if (rte_intr_vec_list_index_set(intr_handle, i,
 			RTE_INTR_VEC_RXTX_OFFSET + RTE_MAX_RXTX_INTR_VEC_ID))
@@ -80,8 +82,7 @@ tap_rx_intr_vec_install(struct rte_eth_dev *dev)
 		if (rte_intr_vec_list_index_set(intr_handle, i,
 					RTE_INTR_VEC_RXTX_OFFSET + count))
 			return -rte_errno;
-		if (rte_intr_efds_index_set(intr_handle, count,
-						   process_private->rxq_fds[i]))
+		if (rte_intr_efds_index_set(intr_handle, count, fd))
 			return -rte_errno;
 		count++;
 	}
Signature · 1 line
2.43.0
#112 lore raw

PATCH v11 2/9 net/tap: remove unused fields

In reply to Stephen Hemminger

The driver doesn't support these other hash types, and there is no reason to implement these in future. The rss_flows list was set but never used.

---
 drivers/net/tap/rte_eth_tap.h | 4 +---
 drivers/net/tap/tap_flow.c    | 1 -
 drivers/net/tap/tap_rss.h     | 6 ------
 3 files changed, 1 insertion(+), 10 deletions(-)
drivers/net/tap/rte_eth_tap.h +1 -3
index dc8201020b..1bcf92ce80 100644
@@ -77,14 +77,12 @@ struct pmd_internals {
 	int ioctl_sock;                   /* socket for ioctl calls */
 	int nlsk_fd;                      /* Netlink socket fd */
 	int flow_isolate;                 /* 1 if flow isolation is enabled */
-	int flower_support;               /* 1 if kernel supports, else 0 */
-	int flower_vlan_support;          /* 1 if kernel supports, else 0 */
 	int rss_enabled;                  /* 1 if RSS is enabled, else 0 */
 	int persist;			  /* 1 if keep link up, else 0 */
 	/* implicit rules set when RSS is enabled */
 	int map_fd;                       /* BPF RSS map fd */
 	int bpf_fd[RTE_PMD_TAP_MAX_QUEUES];/* List of bpf fds per queue */
-	LIST_HEAD(tap_rss_flows, rte_flow) rss_flows;
+
 	LIST_HEAD(tap_flows, rte_flow) flows;        /* rte_flow rules */
 	/* implicit rte_flow rules set when a remote device is active */
 	LIST_HEAD(tap_implicit_flows, rte_flow) implicit_flows;
drivers/net/tap/tap_flow.c +0 -1
index a78fd50cd4..8fccd599f0 100644
@@ -1958,7 +1958,6 @@ static int rss_enable(struct pmd_internals *pmd,
 				errno, strerror(errno));
 			return err;
 		}
-		LIST_INSERT_HEAD(&pmd->rss_flows, rss_flow, next);
 	}
 
 	pmd->rss_enabled = 1;
drivers/net/tap/tap_rss.h +0 -6
index dff46a012f..8766ffc244 100644
@@ -21,12 +21,6 @@ enum hash_field {
 	HASH_FIELD_IPV4_L3_L4,	/* IPv4 src/dst addr + L4 src/dst ports */
 	HASH_FIELD_IPV6_L3,	/* IPv6 src/dst addr */
 	HASH_FIELD_IPV6_L3_L4,	/* IPv6 src/dst addr + L4 src/dst ports */
-	HASH_FIELD_L2_SRC,	/* Ethernet src addr */
-	HASH_FIELD_L2_DST,	/* Ethernet dst addr */
-	HASH_FIELD_L3_SRC,	/* L3 src addr */
-	HASH_FIELD_L3_DST,	/* L3 dst addr */
-	HASH_FIELD_L4_SRC,	/* TCP/UDP src ports */
-	HASH_FIELD_L4_DST,	/* TCP/UDP dst ports */
 };
 
 struct rss_key {
Signature · 1 line
2.43.0
#113 lore raw

PATCH v11 3/9 net/tap: validate and setup parameters for BPF RSS

In reply to Stephen Hemminger

The flow RSS support via BPF was not using the key, or hash type parameters. Which is good because they were never properly setup.

Fix the setup and validate the flow parameters, the BPF side gets fixed later.

---
 drivers/net/tap/tap_flow.c | 65 +++++++++++++++++++++++++++++++++++---
 drivers/net/tap/tap_rss.h  |  5 ++-
 2 files changed, 62 insertions(+), 8 deletions(-)
drivers/net/tap/tap_flow.c +60 -5
index 8fccd599f0..8cf64364a7 100644
@@ -11,9 +11,11 @@
 
 #include <rte_byteorder.h>
 #include <rte_jhash.h>
+#include <rte_thash.h>
 #include <rte_random.h>
 #include <rte_malloc.h>
 #include <rte_eth_tap.h>
+
 #include <tap_flow.h>
 #include <tap_autoconf.h>
 #include <tap_tcmsgs.h>
@@ -2061,6 +2063,21 @@ static int bpf_rss_key(enum bpf_rss_key_e cmd, __u32 *key_idx)
 	return err;
 }
 
+
+/* Default RSS hash key also used by mlx devices */
+static const uint8_t rss_hash_default_key[] = {
+	0x2c, 0xc6, 0x81, 0xd1,
+	0x5b, 0xdb, 0xf4, 0xf7,
+	0xfc, 0xa2, 0x83, 0x19,
+	0xdb, 0x1a, 0x3e, 0x94,
+	0x6b, 0x9e, 0x38, 0xd9,
+	0x2c, 0x9c, 0x03, 0xd1,
+	0xad, 0x99, 0x44, 0xa7,
+	0xd9, 0x56, 0x3d, 0x59,
+	0x06, 0x3c, 0x25, 0xf3,
+	0xfc, 0x1f, 0xdc, 0x2a,
+};
+
 /**
  * Add RSS hash calculations and queue selection
  *
@@ -2079,11 +2096,11 @@ static int rss_add_actions(struct rte_flow *flow, struct pmd_internals *pmd,
 			   const struct rte_flow_action_rss *rss,
 			   struct rte_flow_error *error)
 {
-	/* 4096 is the maximum number of instructions for a BPF program */
+	struct rss_key rss_entry = { };
+	const uint8_t *key_in;
+	uint32_t hash_type = 0;
 	unsigned int i;
 	int err;
-	struct rss_key rss_entry = { .hash_fields = 0,
-				     .key_size = 0 };
 
 	/* Check supported RSS features */
 	if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT)
@@ -2095,6 +2112,41 @@ static int rss_add_actions(struct rte_flow *flow, struct pmd_internals *pmd,
 			(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
 			 "a nonzero RSS encapsulation level is not supported");
 
+	if (rss->queue_num == 0 || rss->queue_num >= TAP_MAX_QUEUES)
+		return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
+					  "invalid number of queues");
+
+	/* allow RSS key_len 0 in case of NULL (default) RSS key. */
+	if (rss->key_len == 0) {
+		if (rss->key != NULL)
+			return rte_flow_error_set(error, ENOTSUP,
+						  RTE_FLOW_ERROR_TYPE_ACTION_CONF,
+						  &rss->key_len, "RSS hash key length 0");
+		key_in = rss_hash_default_key;
+	} else {
+		if (rss->key_len != TAP_RSS_HASH_KEY_SIZE)
+			return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+						  NULL, "RSS hash invalid key length");
+		if (rss->key == NULL)
+			return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+						  NULL, "RSS hash key is NULL");
+		key_in = rss->key;
+	}
+
+	if (rss->types & TAP_RSS_HF_MASK)
+		return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+					  NULL, "RSS hash type not supported");
+
+	if (rss->types & (RTE_ETH_RSS_NONFRAG_IPV4_UDP | RTE_ETH_RSS_NONFRAG_IPV4_TCP))
+		hash_type |= RTE_BIT32(HASH_FIELD_IPV4_L3_L4);
+	else if (rss->types & (RTE_ETH_RSS_IPV4 | RTE_ETH_RSS_FRAG_IPV4))
+		hash_type |= RTE_BIT32(HASH_FIELD_IPV4_L3);
+
+	if (rss->types & (RTE_ETH_RSS_NONFRAG_IPV6_UDP | RTE_ETH_RSS_NONFRAG_IPV6_TCP))
+		hash_type |= RTE_BIT32(HASH_FIELD_IPV6_L3_L4);
+	else if (rss->types & (RTE_ETH_RSS_IPV6 | RTE_ETH_RSS_FRAG_IPV6 | RTE_ETH_RSS_IPV6_EX))
+		hash_type |= RTE_BIT32(HASH_FIELD_IPV6_L3);
+
 	/* Get a new map key for a new RSS rule */
 	err = bpf_rss_key(KEY_CMD_GET, &flow->key_idx);
 	if (err < 0) {
@@ -2109,8 +2161,11 @@ static int rss_add_actions(struct rte_flow *flow, struct pmd_internals *pmd,
 	rss_entry.nb_queues = rss->queue_num;
 	for (i = 0; i < rss->queue_num; i++)
 		rss_entry.queues[i] = rss->queue[i];
-	rss_entry.hash_fields =
-		(1 << HASH_FIELD_IPV4_L3_L4) | (1 << HASH_FIELD_IPV6_L3_L4);
+
+	rss_entry.hash_fields = hash_type;
+	rte_convert_rss_key((const uint32_t *)key_in, (uint32_t *)rss_entry.key,
+			    TAP_RSS_HASH_KEY_SIZE);
+
 
 	/* Add this RSS entry to map */
 	err = tap_flow_bpf_update_rss_elem(pmd->map_fd,
drivers/net/tap/tap_rss.h +2 -3
index 8766ffc244..6009be7031 100644
@@ -24,11 +24,10 @@ enum hash_field {
 };
 
 struct rss_key {
-	 __u8 key[128];
 	__u32 hash_fields;
-	__u32 key_size;
-	__u32 queues[TAP_MAX_QUEUES];
+	__u8 key[TAP_RSS_HASH_KEY_SIZE];
 	__u32 nb_queues;
+	__u32 queues[TAP_MAX_QUEUES];
 } __attribute__((packed));
 
 #endif /* _TAP_RSS_H_ */
Signature · 1 line
2.43.0
#114 lore raw

PATCH v11 4/9 net/tap: do not build flow support if header is out of date

In reply to Stephen Hemminger

The proper place for finding bpf structures and functions is in linux/bpf.h. The original version was trying to workaround the case where the build environment was running on old pre BPF version of Glibc, but the target environment had BPF.

Having own private (and divergent) version headers leads to future problems when BPF definitions evolve.

If the build infrastructure is so old that TC flower is not supported, then the TAP device will build without any flow support.

---
 drivers/net/tap/bpf/bpf_extract.py |   1 -
 drivers/net/tap/meson.build        |  17 ++--
 drivers/net/tap/rte_eth_tap.c      |  38 +++++++--
 drivers/net/tap/rte_eth_tap.h      |   7 +-
 drivers/net/tap/tap_bpf.h          | 121 -----------------------------
 drivers/net/tap/tap_bpf_api.c      |  20 +++--
 drivers/net/tap/tap_bpf_insns.h    |   2 -
 drivers/net/tap/tap_flow.c         |  90 ---------------------
 8 files changed, 60 insertions(+), 236 deletions(-)
 delete mode 100644 drivers/net/tap/tap_bpf.h
drivers/net/tap/bpf/bpf_extract.py +0 -1
index b630c42b80..73c4dafe4e 100644
@@ -65,7 +65,6 @@ def write_header(out, source):
         print(f' * Auto-generated from {source}', file=out)
     print(" * This not the original source file. Do NOT edit it.", file=out)
     print(" */\n", file=out)
-    print("#include <tap_bpf.h>", file=out)
 
 
 def main():
drivers/net/tap/meson.build +9 -8
index 5099ccdff1..66647a1c62 100644
@@ -7,13 +7,19 @@ if not is_linux
 endif
 sources = files(
         'rte_eth_tap.c',
-        'tap_bpf_api.c',
-        'tap_flow.c',
         'tap_intr.c',
         'tap_netlink.c',
-        'tap_tcmsgs.c',
 )
 
+if cc.has_header_symbol('linux/pkt_cls.h', 'TCA_FLOWER_ACT')
+    cflags += '-DHAVE_TCA_FLOWER'
+    sources += files(
+        'tap_bpf_api.c',
+        'tap_flow.c',
+        'tap_tcmsgs.c',
+    )
+endif
+
 deps = ['bus_vdev', 'gso', 'hash']
 
 cflags += '-DTAP_MAX_QUEUES=16'
@@ -23,12 +29,7 @@ cflags += '-DTAP_MAX_QUEUES=16'
 #   "enum/define", "symbol to search" ]
 #
 args = [
-        [ 'HAVE_TC_FLOWER', 'linux/pkt_cls.h', 'TCA_FLOWER_UNSPEC' ],
-        [ 'HAVE_TC_VLAN_ID', 'linux/pkt_cls.h', 'TCA_FLOWER_KEY_VLAN_PRIO' ],
-        [ 'HAVE_TC_BPF', 'linux/pkt_cls.h', 'TCA_BPF_UNSPEC' ],
-        [ 'HAVE_TC_BPF_FD', 'linux/pkt_cls.h', 'TCA_BPF_FD' ],
         [ 'HAVE_TC_ACT_BPF', 'linux/tc_act/tc_bpf.h', 'TCA_ACT_BPF_UNSPEC' ],
-        [ 'HAVE_TC_ACT_BPF_FD', 'linux/tc_act/tc_bpf.h', 'TCA_ACT_BPF_FD' ],
 ]
 config = configuration_data()
 foreach arg:args
drivers/net/tap/rte_eth_tap.c +32 -6
index b84fc01856..9058a47295 100644
@@ -1133,12 +1133,15 @@ tap_dev_close(struct rte_eth_dev *dev)
 
 	if (!internals->persist)
 		tap_link_set_down(dev);
+
+#ifdef HAVE_TCA_FLOWER
 	if (internals->nlsk_fd != -1) {
 		tap_flow_flush(dev, NULL);
 		tap_flow_implicit_flush(internals, NULL);
 		tap_nl_final(internals->nlsk_fd);
 		internals->nlsk_fd = -1;
 	}
+#endif
 
 	for (i = 0; i < RTE_PMD_TAP_MAX_QUEUES; i++) {
 		struct rx_queue *rxq = &internals->rxq[i];
@@ -1261,6 +1264,7 @@ tap_promisc_enable(struct rte_eth_dev *dev)
 	if (ret != 0)
 		return ret;
 
+#ifdef HAVE_TCA_FLOWER
 	if (pmd->remote_if_index && !pmd->flow_isolate) {
 		dev->data->promiscuous = 1;
 		ret = tap_flow_implicit_create(pmd, TAP_REMOTE_PROMISC);
@@ -1274,7 +1278,7 @@ tap_promisc_enable(struct rte_eth_dev *dev)
 			return ret;
 		}
 	}
-
+#endif
 	return 0;
 }
 
@@ -1289,6 +1293,7 @@ tap_promisc_disable(struct rte_eth_dev *dev)
 	if (ret != 0)
 		return ret;
 
+#ifdef HAVE_TCA_FLOWER
 	if (pmd->remote_if_index && !pmd->flow_isolate) {
 		dev->data->promiscuous = 0;
 		ret = tap_flow_implicit_destroy(pmd, TAP_REMOTE_PROMISC);
@@ -1302,6 +1307,7 @@ tap_promisc_disable(struct rte_eth_dev *dev)
 			return ret;
 		}
 	}
+#endif
 
 	return 0;
 }
@@ -1317,6 +1323,7 @@ tap_allmulti_enable(struct rte_eth_dev *dev)
 	if (ret != 0)
 		return ret;
 
+#ifdef HAVE_TCA_FLOWER
 	if (pmd->remote_if_index && !pmd->flow_isolate) {
 		dev->data->all_multicast = 1;
 		ret = tap_flow_implicit_create(pmd, TAP_REMOTE_ALLMULTI);
@@ -1330,6 +1337,7 @@ tap_allmulti_enable(struct rte_eth_dev *dev)
 			return ret;
 		}
 	}
+#endif
 
 	return 0;
 }
@@ -1345,6 +1353,7 @@ tap_allmulti_disable(struct rte_eth_dev *dev)
 	if (ret != 0)
 		return ret;
 
+#ifdef HAVE_TCA_FLOWER
 	if (pmd->remote_if_index && !pmd->flow_isolate) {
 		dev->data->all_multicast = 0;
 		ret = tap_flow_implicit_destroy(pmd, TAP_REMOTE_ALLMULTI);
@@ -1358,6 +1367,7 @@ tap_allmulti_disable(struct rte_eth_dev *dev)
 			return ret;
 		}
 	}
+#endif
 
 	return 0;
 }
@@ -1403,6 +1413,8 @@ tap_mac_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr)
 	if (ret < 0)
 		return ret;
 	rte_memcpy(&pmd->eth_addr, mac_addr, RTE_ETHER_ADDR_LEN);
+
+#ifdef HAVE_TCA_FLOWER
 	if (pmd->remote_if_index && !pmd->flow_isolate) {
 		/* Replace MAC redirection rule after a MAC change */
 		ret = tap_flow_implicit_destroy(pmd, TAP_REMOTE_LOCAL_MAC);
@@ -1420,6 +1432,7 @@ tap_mac_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr)
 			return ret;
 		}
 	}
+#endif
 
 	return 0;
 }
@@ -1894,7 +1907,9 @@ static const struct eth_dev_ops ops = {
 	.stats_reset            = tap_stats_reset,
 	.dev_supported_ptypes_get = tap_dev_supported_ptypes_get,
 	.rss_hash_update        = tap_rss_hash_update,
+#ifdef HAVE_TCA_FLOWER
 	.flow_ops_get           = tap_dev_flow_ops_get,
+#endif
 };
 
 static int
@@ -1934,7 +1949,9 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 	strlcpy(pmd->name, tap_name, sizeof(pmd->name));
 	pmd->type = type;
 	pmd->ka_fd = -1;
+#ifdef HAVE_TCA_FLOWER
 	pmd->nlsk_fd = -1;
+#endif
 	pmd->gso_ctx_mp = NULL;
 
 	pmd->ioctl_sock = socket(AF_INET, SOCK_DGRAM, 0);
@@ -2014,6 +2031,14 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 	/* Make network device persist after application exit */
 	pmd->persist = persist;
 
+	pmd->if_index = if_nametoindex(pmd->name);
+	if (!pmd->if_index) {
+		TAP_LOG(ERR, "%s: failed to get if_index.", pmd->name);
+		goto disable_rte_flow;
+	}
+
+
+#ifdef HAVE_TCA_FLOWER
 	/*
 	 * Set up everything related to rte_flow:
 	 * - netlink socket
@@ -2028,11 +2053,6 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 			pmd->name);
 		goto disable_rte_flow;
 	}
-	pmd->if_index = if_nametoindex(pmd->name);
-	if (!pmd->if_index) {
-		TAP_LOG(ERR, "%s: failed to get if_index.", pmd->name);
-		goto disable_rte_flow;
-	}
 	if (qdisc_create_multiq(pmd->nlsk_fd, pmd->if_index) < 0) {
 		TAP_LOG(ERR, "%s: failed to create multiq qdisc.",
 			pmd->name);
@@ -2043,6 +2063,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 			pmd->name);
 		goto disable_rte_flow;
 	}
+
 	LIST_INIT(&pmd->flows);
 
 	if (strlen(remote_iface)) {
@@ -2095,6 +2116,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 			goto error_remote;
 		}
 	}
+#endif
 
 	rte_eth_dev_probing_finish(dev);
 	return 0;
@@ -2109,14 +2131,18 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 	rte_eth_dev_probing_finish(dev);
 	return 0;
 
+#ifdef HAVE_TCA_FLOWER
 error_remote:
 	TAP_LOG(ERR, " Can't set up remote feature: %s(%d)",
 		strerror(errno), errno);
 	tap_flow_implicit_flush(pmd, NULL);
+#endif
 
 error_exit:
+#ifdef HAVE_TCA_FLOWER
 	if (pmd->nlsk_fd != -1)
 		close(pmd->nlsk_fd);
+#endif
 	if (pmd->ka_fd != -1)
 		close(pmd->ka_fd);
 	if (pmd->ioctl_sock != -1)
drivers/net/tap/rte_eth_tap.h +6 -1
index 1bcf92ce80..af18b29090 100644
@@ -16,6 +16,7 @@
 #include <ethdev_driver.h>
 #include <rte_ether.h>
 #include <rte_gso.h>
+
 #include "tap_log.h"
 
 #ifdef IFF_MULTI_QUEUE
@@ -70,15 +71,17 @@ struct pmd_internals {
 	char remote_iface[RTE_ETH_NAME_MAX_LEN]; /* Remote netdevice name */
 	char name[RTE_ETH_NAME_MAX_LEN];  /* Internal Tap device name */
 	int type;                         /* Type field - TUN|TAP */
+	int persist;			  /* 1 if keep link up, else 0 */
 	struct rte_ether_addr eth_addr;   /* Mac address of the device port */
 	struct ifreq remote_initial_flags;/* Remote netdevice flags on init */
 	int remote_if_index;              /* remote netdevice IF_INDEX */
 	int if_index;                     /* IF_INDEX for the port */
 	int ioctl_sock;                   /* socket for ioctl calls */
+
+#ifdef HAVE_TCA_FLOWER
 	int nlsk_fd;                      /* Netlink socket fd */
 	int flow_isolate;                 /* 1 if flow isolation is enabled */
 	int rss_enabled;                  /* 1 if RSS is enabled, else 0 */
-	int persist;			  /* 1 if keep link up, else 0 */
 	/* implicit rules set when RSS is enabled */
 	int map_fd;                       /* BPF RSS map fd */
 	int bpf_fd[RTE_PMD_TAP_MAX_QUEUES];/* List of bpf fds per queue */
@@ -86,6 +89,8 @@ struct pmd_internals {
 	LIST_HEAD(tap_flows, rte_flow) flows;        /* rte_flow rules */
 	/* implicit rte_flow rules set when a remote device is active */
 	LIST_HEAD(tap_implicit_flows, rte_flow) implicit_flows;
+#endif
+
 	struct rx_queue rxq[RTE_PMD_TAP_MAX_QUEUES]; /* List of RX queues */
 	struct tx_queue txq[RTE_PMD_TAP_MAX_QUEUES]; /* List of TX queues */
 	struct rte_intr_handle *intr_handle;         /* LSC interrupt handle. */
drivers/net/tap/tap_bpf.h deleted +0 -121

121 lines not on this page · raw message

drivers/net/tap/tap_bpf_api.c +13 -7
index 15283f8917..9e05e2ddf1 100644
@@ -2,19 +2,19 @@
  * Copyright 2017 Mellanox Technologies, Ltd
  */
 
-#include <errno.h>
-#include <string.h>
 #include <unistd.h>
-#include <sys/queue.h>
+#include <syscall.h>
+#include <linux/bpf.h>
 
-#include <rte_malloc.h>
-#include <rte_eth_tap.h>
 #include <tap_flow.h>
 #include <tap_autoconf.h>
-#include <tap_tcmsgs.h>
-#include <tap_bpf.h>
+
 #include <tap_bpf_insns.h>
 
+
+static int bpf_load(enum bpf_prog_type type, const struct bpf_insn *insns,
+		size_t insns_cnt, const char *license);
+
 /**
  * Load BPF program (section cls_q) into the kernel and return a bpf fd
  *
@@ -89,7 +89,13 @@ static inline __u64 ptr_to_u64(const void *ptr)
 static inline int sys_bpf(enum bpf_cmd cmd, union bpf_attr *attr,
 			unsigned int size)
 {
+#ifdef __NR_bpf
 	return syscall(__NR_bpf, cmd, attr, size);
+#else
+	TAP_LOG(ERR, "No bpf syscall, kernel headers too old?\n");
+	errno = ENOSYS;
+	return -1;
+#endif
 }
 
 /**
drivers/net/tap/tap_bpf_insns.h +0 -2
index 53fa76c4e6..cdf2febf05 100644
@@ -3,8 +3,6 @@
  * This not the original source file. Do NOT edit it.
  */
 
-#include <tap_bpf.h>
-
 static struct bpf_insn cls_q_insns[] = {
 	{0x61,    2,    1,       52, 0x00000000},
 	{0x18,    3,    0,        0, 0xdeadbeef},
drivers/net/tap/tap_flow.c +0 -90

96 lines not on this page · raw message

Signature · 1 line
2.43.0
#115 lore raw

PATCH v11 5/9 net/tap: rewrite the RSS BPF program

In reply to Stephen Hemminger

Rewrite of the BPF program used to do queue based RSS.

Important changes:
- uses newer BPF map format BTF
- accepts key as parameter rather than constant default
- can do L3 or L4 hashing
- supports IPv4 options
- supports IPv6 extension headers
- restructured for readability

The usage of BPF is different as well:
- the incoming configuration is looked up based on class parameters rather than patching the BPF code.
- the resulting queue is placed in skb by using skb mark than requiring a second pass through classifier step.

Note: This version only works with later patch to enable it on the DPDK driver side. It is submitted as an incremental patch to allow for easier review. Bisection still works because the old instruction are still present for now.

---
 .gitignore                            |   3 -
 drivers/net/tap/bpf/Makefile          |  19 --
 drivers/net/tap/bpf/README            |  49 +++++
 drivers/net/tap/bpf/bpf_api.h         | 276 --------------------------
 drivers/net/tap/bpf/bpf_elf.h         |  53 -----
 drivers/net/tap/bpf/bpf_extract.py    |  85 --------
 drivers/net/tap/bpf/meson.build       |  81 ++++++++
 drivers/net/tap/bpf/tap_bpf_program.c | 255 ------------------------
 drivers/net/tap/bpf/tap_rss.c         | 267 +++++++++++++++++++++++++
 9 files changed, 397 insertions(+), 691 deletions(-)
 delete mode 100644 drivers/net/tap/bpf/Makefile
 create mode 100644 drivers/net/tap/bpf/README
 delete mode 100644 drivers/net/tap/bpf/bpf_api.h
 delete mode 100644 drivers/net/tap/bpf/bpf_elf.h
 delete mode 100644 drivers/net/tap/bpf/bpf_extract.py
 create mode 100644 drivers/net/tap/bpf/meson.build
 delete mode 100644 drivers/net/tap/bpf/tap_bpf_program.c
 create mode 100644 drivers/net/tap/bpf/tap_rss.c
.gitignore +0 -3
index 3f444dcace..01a47a7606 100644
@@ -36,9 +36,6 @@ TAGS
 # ignore python bytecode files
 *.pyc
 
-# ignore BPF programs
-drivers/net/tap/bpf/tap_bpf_program.o
-
 # DTS results
 dts/output
 
drivers/net/tap/bpf/Makefile deleted +0 -19
deleted file mode 100644
index 9efeeb1bc7..0000000000
@@ -1,19 +0,0 @@
-# SPDX-License-Identifier: BSD-3-Clause
-# This file is not built as part of normal DPDK build.
-# It is used to generate the eBPF code for TAP RSS.
-
-CLANG=clang
-CLANG_OPTS=-O2
-TARGET=../tap_bpf_insns.h
-
-all: $(TARGET)
-
-clean:
-	rm tap_bpf_program.o $(TARGET)
-
-tap_bpf_program.o: tap_bpf_program.c
-	$(CLANG) $(CLANG_OPTS) -emit-llvm -c $< -o - | \
-	llc -march=bpf -filetype=obj -o $@
-
-$(TARGET): tap_bpf_program.o
-	python3 bpf_extract.py -stap_bpf_program.c -o $@ $<
drivers/net/tap/bpf/README new file +49 -0

49 lines not on this page · raw message

drivers/net/tap/bpf/bpf_api.h deleted +0 -276

276 lines not on this page · raw message

drivers/net/tap/bpf/bpf_elf.h deleted +0 -53

53 lines not on this page · raw message

drivers/net/tap/bpf/bpf_extract.py deleted +0 -85

85 lines not on this page · raw message

drivers/net/tap/bpf/meson.build new file +81 -0

81 lines not on this page · raw message

drivers/net/tap/bpf/tap_bpf_program.c deleted +0 -255

255 lines not on this page · raw message

drivers/net/tap/bpf/tap_rss.c new file +267 -0

267 lines not on this page · raw message

Signature · 1 line
2.43.0
#116 lore raw

PATCH v11 6/9 net/tap: use libbpf to load new BPF program

In reply to Stephen Hemminger

There were multiple issues in the RSS queue support in the TAP driver. This required extensive rework of the BPF support.

Change the BPF loading to use bpftool to
create a skeleton header file, and load with libbpf. The BPF is always compiled from source so less chance that source and instructions diverge. Also resolves issue where libbpf and source get out of sync. The program
is only loaded once, so if multiple rules are created only one BPF program is loaded in kernel.

The new BPF program only needs a single action.
No need for action and re-classification step.

It also fixes the missing bits from the original.
- supports setting RSS key per flow
- level of hash can be L3 or L3/L4.

Bugzilla ID: 1329

---
 drivers/net/tap/bpf/meson.build |  36 ++-
 drivers/net/tap/meson.build     |  35 ++-
 drivers/net/tap/rte_eth_tap.c   |  14 +-
 drivers/net/tap/rte_eth_tap.h   |   6 +-
 drivers/net/tap/tap_flow.c      | 416 ++++++++------------------------
 drivers/net/tap/tap_flow.h      |  17 +-
 drivers/net/tap/tap_rss.h       |  10 +-
 drivers/net/tap/tap_tcmsgs.h    |   4 +-
 8 files changed, 165 insertions(+), 373 deletions(-)
drivers/net/tap/bpf/meson.build +31 -5
index f2c03a19fd..45e8c3b498 100644
@@ -1,17 +1,26 @@
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright 2024 Stephen Hemminger <[email protected]>
 
-enable_tap_rss = false
-
-libbpf = dependency('libbpf', required: false, method: 'pkg-config')
+# Loading BPF requires libbpf
+# and the bpf_map__XXX API's were introduced in 0.8.0
+libbpf = dependency('libbpf', version: '>= 1.0',
+                    required: false, method: 'pkg-config')
 if not libbpf.found()
     message('net/tap: no RSS support missing libbpf')
     subdir_done()
 endif
 
+# Making skeleton needs bpftool
 # Debian install this in /usr/sbin which is not in $PATH
-bpftool = find_program('bpftool', '/usr/sbin/bpftool', required: false, version: '>= 5.6.0')
-if not bpftool.found()
+bpftool_supports_skel = false
+bpftool = find_program('bpftool', '/usr/sbin/bpftool', required: false)
+if bpftool.found()
+    # Some Ubuntu versions have non-functional bpftool
+    bpftool_supports_skel = run_command(bpftool, 'gen', 'help',
+                                        check:false).returncode() == 0
+endif
+
+if not bpftool_supports_skel
     message('net/tap: no RSS support missing bpftool')
     subdir_done()
 endif
@@ -42,6 +51,7 @@ clang_flags = [
     '-O2',
     '-Wall',
     '-Wextra',
+    max_queues,
     '-target',
     'bpf',
     '-g',
@@ -67,6 +77,22 @@ skel_h_cmd = [
     '@INPUT@'
 ]
 
+vmlinux_h_cmd = [
+    bpftool,
+    'btf',
+    'dump',
+    'file',
+    '/sys/kernel/btf/vmlinux',
+    'format',
+    'c'
+]
+
+vmlinux_h = custom_target(
+    'vmlinux.h',
+    output: 'vmlinux.h',
+    command: vmlinux_h_cmd,
+    capture: true)
+
 tap_rss_o = custom_target(
     'tap_rss.bpf.o',
     input: 'tap_rss.c',
drivers/net/tap/meson.build +16 -19
index 66647a1c62..26074059fa 100644
@@ -5,36 +5,33 @@ if not is_linux
     build = false
     reason = 'only supported on Linux'
 endif
+
 sources = files(
         'rte_eth_tap.c',
         'tap_intr.c',
         'tap_netlink.c',
 )
 
+deps = ['bus_vdev', 'gso', 'hash']
+
+max_queues = '-DTAP_MAX_QUEUES=16'
+cflags += max_queues
+
+require_iova_in_mbuf = false
+
 if cc.has_header_symbol('linux/pkt_cls.h', 'TCA_FLOWER_ACT')
     cflags += '-DHAVE_TCA_FLOWER'
     sources += files(
-        'tap_bpf_api.c',
         'tap_flow.c',
         'tap_tcmsgs.c',
     )
-endif
-
-deps = ['bus_vdev', 'gso', 'hash']
 
-cflags += '-DTAP_MAX_QUEUES=16'
-
-# input array for meson symbol search:
-# [ "MACRO to define if found", "header for the search",
-#   "enum/define", "symbol to search" ]
-#
-args = [
-        [ 'HAVE_TC_ACT_BPF', 'linux/tc_act/tc_bpf.h', 'TCA_ACT_BPF_UNSPEC' ],
-]
-config = configuration_data()
-foreach arg:args
-    config.set(arg[0], cc.has_header_symbol(arg[1], arg[2]))
-endforeach
-configure_file(output : 'tap_autoconf.h', configuration : config)
+    enable_tap_rss = false
 
-require_iova_in_mbuf = false
+    subdir('bpf')
+    if enable_tap_rss
+        cflags += '-DHAVE_BPF_RSS'
+        ext_deps += libbpf
+        sources += tap_rss_skel_h
+    endif
+endif
drivers/net/tap/rte_eth_tap.c +7 -7
index 9058a47295..d847565073 100644
@@ -1140,6 +1140,7 @@ tap_dev_close(struct rte_eth_dev *dev)
 		tap_flow_implicit_flush(internals, NULL);
 		tap_nl_final(internals->nlsk_fd);
 		internals->nlsk_fd = -1;
+		tap_flow_bpf_destroy(internals);
 	}
 #endif
 
@@ -1949,6 +1950,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 	strlcpy(pmd->name, tap_name, sizeof(pmd->name));
 	pmd->type = type;
 	pmd->ka_fd = -1;
+
 #ifdef HAVE_TCA_FLOWER
 	pmd->nlsk_fd = -1;
 #endif
@@ -2031,13 +2033,6 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 	/* Make network device persist after application exit */
 	pmd->persist = persist;
 
-	pmd->if_index = if_nametoindex(pmd->name);
-	if (!pmd->if_index) {
-		TAP_LOG(ERR, "%s: failed to get if_index.", pmd->name);
-		goto disable_rte_flow;
-	}
-
-
 #ifdef HAVE_TCA_FLOWER
 	/*
 	 * Set up everything related to rte_flow:
@@ -2053,6 +2048,11 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 			pmd->name);
 		goto disable_rte_flow;
 	}
+	pmd->if_index = if_nametoindex(pmd->name);
+	if (!pmd->if_index) {
+		TAP_LOG(ERR, "%s: failed to get if_index.", pmd->name);
+		goto disable_rte_flow;
+	}
 	if (qdisc_create_multiq(pmd->nlsk_fd, pmd->if_index) < 0) {
 		TAP_LOG(ERR, "%s: failed to create multiq qdisc.",
 			pmd->name);
drivers/net/tap/rte_eth_tap.h +2 -4
index af18b29090..ce4322ad04 100644
@@ -81,10 +81,8 @@ struct pmd_internals {
 #ifdef HAVE_TCA_FLOWER
 	int nlsk_fd;                      /* Netlink socket fd */
 	int flow_isolate;                 /* 1 if flow isolation is enabled */
-	int rss_enabled;                  /* 1 if RSS is enabled, else 0 */
-	/* implicit rules set when RSS is enabled */
-	int map_fd;                       /* BPF RSS map fd */
-	int bpf_fd[RTE_PMD_TAP_MAX_QUEUES];/* List of bpf fds per queue */
+
+	struct tap_rss *rss;		  /* BPF program */
 
 	LIST_HEAD(tap_flows, rte_flow) flows;        /* rte_flow rules */
 	/* implicit rte_flow rules set when a remote device is active */
drivers/net/tap/tap_flow.c +97 -319

555 lines not on this page · raw message

drivers/net/tap/tap_flow.h +6 -11
index 240fbc3dfa..8b19347a93 100644
@@ -9,7 +9,11 @@
 #include <rte_flow.h>
 #include <rte_flow_driver.h>
 #include <rte_eth_tap.h>
-#include <tap_autoconf.h>
+
+/**
+ * Mask of unsupported RSS types
+ */
+#define TAP_RSS_HF_MASK (~(RTE_ETH_RSS_IP | RTE_ETH_RSS_UDP | RTE_ETH_RSS_TCP))
 
 /**
  * In TC, priority 0 means we require the kernel to allocate one for us.
@@ -41,11 +45,6 @@ enum implicit_rule_index {
 	TAP_REMOTE_MAX_IDX,
 };
 
-enum bpf_fd_idx {
-	SEC_L3_L4,
-	SEC_MAX,
-};
-
 int tap_dev_flow_ops_get(struct rte_eth_dev *dev,
 			 const struct rte_flow_ops **ops);
 int tap_flow_flush(struct rte_eth_dev *dev, struct rte_flow_error *error);
@@ -57,10 +56,6 @@ int tap_flow_implicit_destroy(struct pmd_internals *pmd,
 int tap_flow_implicit_flush(struct pmd_internals *pmd,
 			    struct rte_flow_error *error);
 
-int tap_flow_bpf_cls_q(__u32 queue_idx);
-int tap_flow_bpf_calc_l3_l4_hash(__u32 key_idx, int map_fd);
-int tap_flow_bpf_rss_map_create(unsigned int key_size, unsigned int value_size,
-			unsigned int max_entries);
-int tap_flow_bpf_update_rss_elem(int fd, void *key, void *value);
+void tap_flow_bpf_destroy(struct pmd_internals *pmd);
 
 #endif /* _TAP_FLOW_H_ */
drivers/net/tap/tap_rss.h +4 -6
index 6009be7031..65bd8991b1 100644
@@ -5,16 +5,14 @@
 #ifndef _TAP_RSS_H_
 #define _TAP_RSS_H_
 
-#ifndef TAP_MAX_QUEUES
-#define TAP_MAX_QUEUES 16
+/* Size of the map from BPF classid to queue table */
+#ifndef TAP_RSS_MAX
+#define TAP_RSS_MAX	32
 #endif
 
-/* Fixed RSS hash key size in bytes. */
+/* Standard Toeplitz hash key size */
 #define TAP_RSS_HASH_KEY_SIZE 40
 
-/* Supported RSS */
-#define TAP_RSS_HF_MASK (~(RTE_ETH_RSS_IP | RTE_ETH_RSS_UDP | RTE_ETH_RSS_TCP))
-
 /* hashed fields for RSS */
 enum hash_field {
 	HASH_FIELD_IPV4_L3,	/* IPv4 src/dst addr */
drivers/net/tap/tap_tcmsgs.h +2 -2
index a64cb29d6f..9411626661 100644
@@ -6,7 +6,6 @@
 #ifndef _TAP_TCMSGS_H_
 #define _TAP_TCMSGS_H_
 
-#include <tap_autoconf.h>
 #include <linux/if_ether.h>
 #include <linux/rtnetlink.h>
 #include <linux/pkt_sched.h>
@@ -14,9 +13,10 @@
 #include <linux/tc_act/tc_mirred.h>
 #include <linux/tc_act/tc_gact.h>
 #include <linux/tc_act/tc_skbedit.h>
-#ifdef HAVE_TC_ACT_BPF
+#ifdef HAVE_BPF_RSS
 #include <linux/tc_act/tc_bpf.h>
 #endif
+
 #include <inttypes.h>
 
 #include <rte_ether.h>
Signature · 1 line
2.43.0
#117 lore raw

PATCH v11 7/9 net/tap: remove no longer used files

In reply to Stephen Hemminger

The BPF api was replaced by use of libbpf.
And the BPF instruction header was replaced by the skeleton.

---
 drivers/net/tap/tap_bpf_api.c   |  196 ----
 drivers/net/tap/tap_bpf_insns.h | 1741 -------------------------------
 2 files changed, 1937 deletions(-)
 delete mode 100644 drivers/net/tap/tap_bpf_api.c
 delete mode 100644 drivers/net/tap/tap_bpf_insns.h
drivers/net/tap/tap_bpf_api.c deleted +0 -196
deleted file mode 100644
index 9e05e2ddf1..0000000000
@@ -1,196 +0,0 @@
-/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright 2017 Mellanox Technologies, Ltd
- */
-
-#include <unistd.h>
-#include <syscall.h>
-#include <linux/bpf.h>
-
-#include <tap_flow.h>
-#include <tap_autoconf.h>
-
-#include <tap_bpf_insns.h>
-
-
-static int bpf_load(enum bpf_prog_type type, const struct bpf_insn *insns,
-		size_t insns_cnt, const char *license);
-
-/**
- * Load BPF program (section cls_q) into the kernel and return a bpf fd
- *
- * @param queue_idx
- *   Queue index matching packet cb
- *
- * @return
- *   -1 if the BPF program couldn't be loaded. An fd (int) otherwise.
- */
-int tap_flow_bpf_cls_q(__u32 queue_idx)
-{
-	cls_q_insns[1].imm = queue_idx;
-
-	return bpf_load(BPF_PROG_TYPE_SCHED_CLS,
-		(struct bpf_insn *)cls_q_insns,
-		RTE_DIM(cls_q_insns),
-		"Dual BSD/GPL");
-}
-
-/**
- * Load BPF program (section l3_l4) into the kernel and return a bpf fd.
- *
- * @param[in] key_idx
- *   RSS MAP key index
- *
- * @param[in] map_fd
- *   BPF RSS map file descriptor
- *
- * @return
- *   -1 if the BPF program couldn't be loaded. An fd (int) otherwise.
- */
-int tap_flow_bpf_calc_l3_l4_hash(__u32 key_idx, int map_fd)
-{
-	l3_l4_hash_insns[4].imm = key_idx;
-	l3_l4_hash_insns[9].imm = map_fd;
-
-	return bpf_load(BPF_PROG_TYPE_SCHED_ACT,
-		(struct bpf_insn *)l3_l4_hash_insns,
-		RTE_DIM(l3_l4_hash_insns),
-		"Dual BSD/GPL");
-}
-
-/**
- * Helper function to convert a pointer to unsigned 64 bits
- *
- * @param[in] ptr
- *   pointer to address
- *
- * @return
- *   64 bit unsigned long type of pointer address
- */
-static inline __u64 ptr_to_u64(const void *ptr)
-{
-	return (__u64)(unsigned long)ptr;
-}
-
-/**
- * Call BPF system call
- *
- * @param[in] cmd
- *   BPF command for program loading, map creation, map entry update, etc
- *
- * @param[in] attr
- *   System call attributes relevant to system call command
- *
- * @param[in] size
- *   size of attr parameter
- *
- * @return
- *   -1 if BPF system call failed, 0 otherwise
- */
-static inline int sys_bpf(enum bpf_cmd cmd, union bpf_attr *attr,
-			unsigned int size)
-{
-#ifdef __NR_bpf
-	return syscall(__NR_bpf, cmd, attr, size);
-#else
-	TAP_LOG(ERR, "No bpf syscall, kernel headers too old?\n");
-	errno = ENOSYS;
-	return -1;
-#endif
-}
-
-/**
- * Load BPF instructions to kernel
- *
- * @param[in] type
- *   BPF program type: classifier or action
- *
- * @param[in] insns
- *   Array of BPF instructions (equivalent to BPF instructions)
- *
- * @param[in] insns_cnt
- *   Number of BPF instructions (size of array)
- *
- * @param[in] license
- *   License string that must be acknowledged by the kernel
- *
- * @return
- *   -1 if the BPF program couldn't be loaded, fd (file descriptor) otherwise
- */
-static int bpf_load(enum bpf_prog_type type,
-		  const struct bpf_insn *insns,
-		  size_t insns_cnt,
-		  const char *license)
-{
-	union bpf_attr attr = {};
-
-	bzero(&attr, sizeof(attr));
-	attr.prog_type = type;
-	attr.insn_cnt = (__u32)insns_cnt;
-	attr.insns = ptr_to_u64(insns);
-	attr.license = ptr_to_u64(license);
-	attr.log_buf = ptr_to_u64(NULL);
-	attr.log_level = 0;
-	attr.kern_version = 0;
-
-	return sys_bpf(BPF_PROG_LOAD, &attr, sizeof(attr));
-}
-
-/**
- * Create BPF map for RSS rules
- *
- * @param[in] key_size
- *   map RSS key size
- *
- * @param[in] value_size
- *   Map RSS value size
- *
- * @param[in] max_entries
- *   Map max number of RSS entries (limit on max RSS rules)
- *
- * @return
- *   -1 if BPF map couldn't be created, map fd otherwise
- */
-int tap_flow_bpf_rss_map_create(unsigned int key_size,
-		unsigned int value_size,
-		unsigned int max_entries)
-{
-	union bpf_attr attr = {};
-
-	bzero(&attr, sizeof(attr));
-	attr.map_type    = BPF_MAP_TYPE_HASH;
-	attr.key_size    = key_size;
-	attr.value_size  = value_size;
-	attr.max_entries = max_entries;
-
-	return sys_bpf(BPF_MAP_CREATE, &attr, sizeof(attr));
-}
-
-/**
- * Update RSS entry in BPF map
- *
- * @param[in] fd
- *   RSS map fd
- *
- * @param[in] key
- *   Pointer to RSS key whose entry is updated
- *
- * @param[in] value
- *   Pointer to RSS new updated value
- *
- * @return
- *   -1 if RSS entry failed to be updated, 0 otherwise
- */
-int tap_flow_bpf_update_rss_elem(int fd, void *key, void *value)
-{
-	union bpf_attr attr = {};
-
-	bzero(&attr, sizeof(attr));
-
-	attr.map_type = BPF_MAP_TYPE_HASH;
-	attr.map_fd = fd;
-	attr.key = ptr_to_u64(key);
-	attr.value = ptr_to_u64(value);
-	attr.flags = BPF_ANY;
-
-	return sys_bpf(BPF_MAP_UPDATE_ELEM, &attr, sizeof(attr));
-}
drivers/net/tap/tap_bpf_insns.h deleted +0 -1741

1,741 lines not on this page · raw message

Signature · 1 line
2.43.0
#118 lore raw

PATCH v11 8/9 net/tap: simplify internals

In reply to Stephen Hemminger

The names of Linux network devices are IFNAMSIZ(16) not the same as DPDK which has up to 64 characters. Don't need to hold onto the whole ifreq to save the remote interface flags.

Make sure packet and byte counters are read once, so that global and per-queue values add up. No need for separate rx_nombuf counter since there is an alloc_failed value in ethdev.

---
 drivers/net/tap/rte_eth_tap.c | 114 +++++++++++++++++++---------------
 drivers/net/tap/rte_eth_tap.h |  12 ++--
 2 files changed, 71 insertions(+), 55 deletions(-)
drivers/net/tap/rte_eth_tap.c +65 -49
index d847565073..2af6b763e6 100644
@@ -46,6 +46,11 @@
 #include <tap_netlink.h>
 #include <tap_tcmsgs.h>
 
+/* Used to snapshot statistics */
+#ifndef READ_ONCE
+#define READ_ONCE(var) (*((volatile typeof(var) *)(&(var))))
+#endif
+
 /* Linux based path to the TUN device */
 #define TUN_TAP_DEV_PATH        "/dev/net/tun"
 #define DEFAULT_TAP_NAME        "dtap"
@@ -212,7 +217,7 @@ tun_alloc(struct pmd_internals *pmd, int is_keepalive, int persistent)
 	 * and need to find the resulting device.
 	 */
 	TAP_LOG(DEBUG, "Device name is '%s'", ifr.ifr_name);
-	strlcpy(pmd->name, ifr.ifr_name, RTE_ETH_NAME_MAX_LEN);
+	strlcpy(pmd->name, ifr.ifr_name, IFNAMSIZ);
 
 	if (is_keepalive) {
 		/*
@@ -466,7 +471,8 @@ pmd_rx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 			struct rte_mbuf *buf = rte_pktmbuf_alloc(rxq->mp);
 
 			if (unlikely(!buf)) {
-				rxq->stats.rx_nombuf++;
+				rte_eth_devices[rxq->in_port].data->rx_mbuf_alloc_failed++;
+
 				/* No new buf has been allocated: do nothing */
 				if (!new_tail || !seg)
 					goto end;
@@ -1047,43 +1053,44 @@ tap_dev_info(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 static int
 tap_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *tap_stats)
 {
-	unsigned int i, imax;
-	unsigned long rx_total = 0, tx_total = 0, tx_err_total = 0;
-	unsigned long rx_bytes_total = 0, tx_bytes_total = 0;
-	unsigned long rx_nombuf = 0, ierrors = 0;
+	unsigned int i;
 	const struct pmd_internals *pmd = dev->data->dev_private;
+	uint64_t bytes, packets;
 
 	/* rx queue statistics */
-	imax = (dev->data->nb_rx_queues < RTE_ETHDEV_QUEUE_STAT_CNTRS) ?
-		dev->data->nb_rx_queues : RTE_ETHDEV_QUEUE_STAT_CNTRS;
-	for (i = 0; i < imax; i++) {
-		tap_stats->q_ipackets[i] = pmd->rxq[i].stats.ipackets;
-		tap_stats->q_ibytes[i] = pmd->rxq[i].stats.ibytes;
-		rx_total += tap_stats->q_ipackets[i];
-		rx_bytes_total += tap_stats->q_ibytes[i];
-		rx_nombuf += pmd->rxq[i].stats.rx_nombuf;
-		ierrors += pmd->rxq[i].stats.ierrors;
+	for (i = 0; i < dev->data->nb_rx_queues; i++) {
+		const struct rx_queue *rxq = &pmd->rxq[i];
+
+		packets = READ_ONCE(rxq->stats.ipackets);
+		bytes = READ_ONCE(rxq->stats.ibytes);
+
+		tap_stats->ipackets += packets;
+		tap_stats->ibytes += bytes;
+		tap_stats->ierrors += rxq->stats.ierrors;
+
+		if (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) {
+			tap_stats->q_ipackets[i] = packets;
+			tap_stats->q_ibytes[i] =  bytes;
+		}
 	}
 
 	/* tx queue statistics */
-	imax = (dev->data->nb_tx_queues < RTE_ETHDEV_QUEUE_STAT_CNTRS) ?
-		dev->data->nb_tx_queues : RTE_ETHDEV_QUEUE_STAT_CNTRS;
-
-	for (i = 0; i < imax; i++) {
-		tap_stats->q_opackets[i] = pmd->txq[i].stats.opackets;
-		tap_stats->q_obytes[i] = pmd->txq[i].stats.obytes;
-		tx_total += tap_stats->q_opackets[i];
-		tx_err_total += pmd->txq[i].stats.errs;
-		tx_bytes_total += tap_stats->q_obytes[i];
-	}
-
-	tap_stats->ipackets = rx_total;
-	tap_stats->ibytes = rx_bytes_total;
-	tap_stats->ierrors = ierrors;
-	tap_stats->rx_nombuf = rx_nombuf;
-	tap_stats->opackets = tx_total;
-	tap_stats->oerrors = tx_err_total;
-	tap_stats->obytes = tx_bytes_total;
+	for (i = 0; i < dev->data->nb_tx_queues; i++) {
+		const struct tx_queue *txq = &pmd->txq[i];
+
+		packets = READ_ONCE(txq->stats.opackets);
+		bytes = READ_ONCE(txq->stats.obytes);
+
+		tap_stats->opackets += packets;
+		tap_stats->obytes += bytes;
+		tap_stats->oerrors += txq->stats.errs;
+
+		if (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) {
+			tap_stats->q_opackets[i] = packets;
+			tap_stats->q_obytes[i] = bytes;
+		}
+	}
+
 	return 0;
 }
 
@@ -1097,7 +1104,6 @@ tap_stats_reset(struct rte_eth_dev *dev)
 		pmd->rxq[i].stats.ipackets = 0;
 		pmd->rxq[i].stats.ibytes = 0;
 		pmd->rxq[i].stats.ierrors = 0;
-		pmd->rxq[i].stats.rx_nombuf = 0;
 
 		pmd->txq[i].stats.opackets = 0;
 		pmd->txq[i].stats.errs = 0;
@@ -1156,9 +1162,13 @@ tap_dev_close(struct rte_eth_dev *dev)
 	}
 
 	if (internals->remote_if_index) {
+		struct ifreq remote_ifr;
+
+		strlcpy(remote_ifr.ifr_name, internals->remote_iface, IFNAMSIZ);
+		remote_ifr.ifr_flags = internals->remote_flags;
+
 		/* Restore initial remote state */
-		int ret = ioctl(internals->ioctl_sock, SIOCSIFFLAGS,
-				&internals->remote_initial_flags);
+		int ret = ioctl(internals->ioctl_sock, SIOCSIFFLAGS, &remote_ifr);
 		if (ret)
 			TAP_LOG(ERR, "restore remote state failed: %d", ret);
 
@@ -2067,16 +2077,22 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 	LIST_INIT(&pmd->flows);
 
 	if (strlen(remote_iface)) {
+		struct ifreq remote_ifr;
+
 		pmd->remote_if_index = if_nametoindex(remote_iface);
 		if (!pmd->remote_if_index) {
 			TAP_LOG(ERR, "%s: failed to get %s if_index.",
 				pmd->name, remote_iface);
 			goto error_remote;
 		}
-		strlcpy(pmd->remote_iface, remote_iface, RTE_ETH_NAME_MAX_LEN);
+		strlcpy(pmd->remote_iface, remote_iface, IFNAMSIZ);
+
+		memset(&remote_ifr, 0, sizeof(ifr));
+		strlcpy(remote_ifr.ifr_name, remote_iface, IFNAMSIZ);
 
 		/* Save state of remote device */
-		tap_ioctl(pmd, SIOCGIFFLAGS, &pmd->remote_initial_flags, 0, REMOTE_ONLY);
+		tap_ioctl(pmd, SIOCGIFFLAGS, &remote_ifr, 0, REMOTE_ONLY);
+		pmd->remote_flags = remote_ifr.ifr_flags;
 
 		/* Replicate remote MAC address */
 		if (tap_ioctl(pmd, SIOCGIFHWADDR, &ifr, 0, REMOTE_ONLY) < 0) {
@@ -2190,10 +2206,10 @@ set_interface_name(const char *key __rte_unused,
 				value);
 			return -1;
 		}
-		strlcpy(name, value, RTE_ETH_NAME_MAX_LEN);
+		strlcpy(name, value, IFNAMSIZ);
 	} else {
 		/* use tap%d which causes kernel to choose next available */
-		strlcpy(name, DEFAULT_TAP_NAME "%d", RTE_ETH_NAME_MAX_LEN);
+		strlcpy(name, DEFAULT_TAP_NAME "%d", IFNAMSIZ);
 	}
 	return 0;
 }
@@ -2211,7 +2227,7 @@ set_remote_iface(const char *key __rte_unused,
 				value);
 			return -1;
 		}
-		strlcpy(name, value, RTE_ETH_NAME_MAX_LEN);
+		strlcpy(name, value, IFNAMSIZ);
 	}
 
 	return 0;
@@ -2262,13 +2278,13 @@ rte_pmd_tun_probe(struct rte_vdev_device *dev)
 	const char *name, *params;
 	int ret;
 	struct rte_kvargs *kvlist = NULL;
-	char tun_name[RTE_ETH_NAME_MAX_LEN];
-	char remote_iface[RTE_ETH_NAME_MAX_LEN];
+	char tun_name[IFNAMSIZ];
+	char remote_iface[IFNAMSIZ];
 	struct rte_eth_dev *eth_dev;
 
 	name = rte_vdev_device_name(dev);
 	params = rte_vdev_device_args(dev);
-	memset(remote_iface, 0, RTE_ETH_NAME_MAX_LEN);
+	memset(remote_iface, 0, IFNAMSIZ);
 
 	if (rte_eal_process_type() == RTE_PROC_SECONDARY &&
 	    strlen(params) == 0) {
@@ -2284,7 +2300,7 @@ rte_pmd_tun_probe(struct rte_vdev_device *dev)
 	}
 
 	/* use tun%d which causes kernel to choose next available */
-	strlcpy(tun_name, DEFAULT_TUN_NAME "%d", RTE_ETH_NAME_MAX_LEN);
+	strlcpy(tun_name, DEFAULT_TUN_NAME "%d", IFNAMSIZ);
 
 	if (params && (params[0] != '\0')) {
 		TAP_LOG(DEBUG, "parameters (%s)", params);
@@ -2424,8 +2440,8 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev)
 	int ret;
 	struct rte_kvargs *kvlist = NULL;
 	int speed;
-	char tap_name[RTE_ETH_NAME_MAX_LEN];
-	char remote_iface[RTE_ETH_NAME_MAX_LEN];
+	char tap_name[IFNAMSIZ];
+	char remote_iface[IFNAMSIZ];
 	struct rte_ether_addr user_mac = { .addr_bytes = {0} };
 	struct rte_eth_dev *eth_dev;
 	int tap_devices_count_increased = 0;
@@ -2479,8 +2495,8 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev)
 	speed = RTE_ETH_SPEED_NUM_10G;
 
 	/* use tap%d which causes kernel to choose next available */
-	strlcpy(tap_name, DEFAULT_TAP_NAME "%d", RTE_ETH_NAME_MAX_LEN);
-	memset(remote_iface, 0, RTE_ETH_NAME_MAX_LEN);
+	strlcpy(tap_name, DEFAULT_TAP_NAME "%d", IFNAMSIZ);
+	memset(remote_iface, 0, IFNAMSIZ);
 
 	if (params && (params[0] != '\0')) {
 		TAP_LOG(DEBUG, "parameters (%s)", params);
drivers/net/tap/rte_eth_tap.h +6 -6
index ce4322ad04..ca510e2c6b 100644
@@ -68,15 +68,16 @@ struct tx_queue {
 
 struct pmd_internals {
 	struct rte_eth_dev *dev;          /* Ethernet device. */
-	char remote_iface[RTE_ETH_NAME_MAX_LEN]; /* Remote netdevice name */
-	char name[RTE_ETH_NAME_MAX_LEN];  /* Internal Tap device name */
+	char remote_iface[IFNAMSIZ];	  /* Remote netdevice name */
+	char name[IFNAMSIZ];		  /* Internal Tap device name */
 	int type;                         /* Type field - TUN|TAP */
 	int persist;			  /* 1 if keep link up, else 0 */
 	struct rte_ether_addr eth_addr;   /* Mac address of the device port */
-	struct ifreq remote_initial_flags;/* Remote netdevice flags on init */
+	uint16_t remote_flags;		  /* Remote netdevice flags on init */
 	int remote_if_index;              /* remote netdevice IF_INDEX */
 	int if_index;                     /* IF_INDEX for the port */
 	int ioctl_sock;                   /* socket for ioctl calls */
+	int ka_fd;                        /* keep-alive file descriptor */
 
 #ifdef HAVE_TCA_FLOWER
 	int nlsk_fd;                      /* Netlink socket fd */
@@ -88,12 +89,11 @@ struct pmd_internals {
 	/* implicit rte_flow rules set when a remote device is active */
 	LIST_HEAD(tap_implicit_flows, rte_flow) implicit_flows;
 #endif
+	struct rte_intr_handle *intr_handle;         /* LSC interrupt handle. */
+	struct rte_mempool *gso_ctx_mp;     /* Mempool for GSO packets */
 
 	struct rx_queue rxq[RTE_PMD_TAP_MAX_QUEUES]; /* List of RX queues */
 	struct tx_queue txq[RTE_PMD_TAP_MAX_QUEUES]; /* List of TX queues */
-	struct rte_intr_handle *intr_handle;         /* LSC interrupt handle. */
-	int ka_fd;                        /* keep-alive file descriptor */
-	struct rte_mempool *gso_ctx_mp;     /* Mempool for GSO packets */
 };
 
 struct pmd_process_private {
Signature · 1 line
2.43.0
#119 lore raw

PATCH v11 9/9 net/tap: update documentation

In reply to Stephen Hemminger

The driver support of flows has changed and the wording in the guide was awkward.

Drop references to DPDK pktgen in this documentation since it is not required and confusing.

---
 doc/guides/nics/tap.rst                | 274 +++++++------------------
 doc/guides/rel_notes/release_24_07.rst |   7 +
 2 files changed, 84 insertions(+), 197 deletions(-)
doc/guides/nics/tap.rst +77 -197
index d4f45c02a1..55e38fb25b 100644
@@ -1,47 +1,51 @@
 ..  SPDX-License-Identifier: BSD-3-Clause
     Copyright(c) 2016 Intel Corporation.
 
-Tun|Tap Poll Mode Driver
-========================
+TAP Poll Mode Driver
+====================
 
-The ``rte_eth_tap.c`` PMD creates a device using TAP interfaces on the
-local host. The PMD allows for DPDK and the host to communicate using a raw
-device interface on the host and in the DPDK application.
+The TAP Poll Mode Driver (PMD) is a virtual device for injecting packets to be processed
+by the Linux kernel. This PMD is useful when writing DPDK application
+for offloading network functionality (such as tunneling) from the kernel.
 
-The device created is a TAP device, which sends/receives packet in a raw
-format with a L2 header. The usage for a TAP PMD is for connectivity to the
-local host using a TAP interface. When the TAP PMD is initialized it will
-create a number of tap devices in the host accessed via ``ifconfig -a`` or
-``ip`` command. The commands can be used to assign and query the virtual like
-device.
+From the kernel point of view, the TAP device looks like a regular network interface.
+The network device can be managed by standard tools such as ``ip`` and ``ethtool`` commands.
+It is also possible to use existing packet tools such as  ``wireshark`` or ``tcpdump``.
 
-These TAP interfaces can be used with Wireshark or tcpdump or Pktgen-DPDK
-along with being able to be used as a network connection to the DPDK
-application. The method enable one or more interfaces is to use the
-``--vdev=net_tap0`` option on the DPDK application command line. Each
-``--vdev=net_tap1`` option given will create an interface named dtap0, dtap1,
-and so on.
+From the DPDK application, the TAP device looks like a DPDK ethdev.
+Packets are sent and received in L2 (Ethernet) format. The standare DPDK
+API's to query for information, statistics and send and receive packets
+work as expected.
 
-The interface name can be changed by adding the ``iface=foo0``, for example::
+Requirements
+~~~~~~~~~~~~
+
+The TAP PMD requires kernel support for multiple queues in TAP device as
+well as the multi-queue ``multiq`` and incoming ``ingress`` queue disciplines.
+These are standard kernel features in most Linux distributions.
+
+Arguments
+---------
+
+TAP devices are created with the command line
+``--vdev=net_tap0`` option. This option maybe specified more the once by repeating
+with a different ``net_tapX`` device.
+
+By default, the Linux interfaces are named ``dtap0``, ``dtap1``, etc.
+The interface name can be specified by adding the ``iface=foo0``, for example::
 
    --vdev=net_tap0,iface=foo0 --vdev=net_tap1,iface=foo1, ...
 
-Normally the PMD will generate a random MAC address, but when testing or with
-a static configuration the developer may need a fixed MAC address style.
-Using the option ``mac=fixed`` you can create a fixed known MAC address::
+Normally the PMD will generate a random MAC address.
+If a static address is desired instead, the ``mac=fixed`` can be used.
 
    --vdev=net_tap0,mac=fixed
 
-The MAC address will have a fixed value with the last octet incrementing by one
-for each interface string containing ``mac=fixed``. The MAC address is formatted
-as 02:'d':'t':'a':'p':[00-FF]. Convert the characters to hex and you get the
-actual MAC address: ``02:64:74:61:70:[00-FF]``.
-
-   --vdev=net_tap0,mac="02:64:74:61:70:11"
+With the fixed option, the MAC address will have the first octets:
+as 02:'d':'t':'a':'p':[00-FF] and the last octets are the interface number.
 
-The MAC address will have a user value passed as string. The MAC address is in
-format with delimiter ``:``. The string is byte converted to hex and you get
-the actual MAC address: ``02:64:74:61:70:11``.
+To specify a specific MAC address use the conventional representation.
+The string is byte converted to hex, the result is MAC address: ``02:64:74:61:70:11``.
 
 It is possible to specify a remote netdevice to capture packets from by adding
 ``remote=foo1``, for example::
@@ -59,40 +63,20 @@ netdevice that has no support in the DPDK. It is possible to add explicit
 rte_flow rules on the tap PMD to capture specific traffic (see next section for
 examples).
 
-After the DPDK application is started you can send and receive packets on the
-interface using the standard rx_burst/tx_burst APIs in DPDK. From the host
-point of view you can use any host tool like tcpdump, Wireshark, ping, Pktgen
-and others to communicate with the DPDK application. The DPDK application may
-not understand network protocols like IPv4/6, UDP or TCP unless the
-application has been written to understand these protocols.
-
-If you need the interface as a real network interface meaning running and has
-a valid IP address then you can do this with the following commands::
-
-   sudo ip link set dtap0 up; sudo ip addr add 192.168.0.250/24 dev dtap0
-   sudo ip link set dtap1 up; sudo ip addr add 192.168.1.250/24 dev dtap1
-
-Please change the IP addresses as you see fit.
-
-If routing is enabled on the host you can also communicate with the DPDK App
-over the internet via a standard socket layer application as long as you
-account for the protocol handling in the application.
-
-If you have a Network Stack in your DPDK application or something like it you
-can utilize that stack to handle the network protocols. Plus you would be able
-to address the interface using an IP address assigned to the internal
-interface.
-
 Normally, when the DPDK application exits,
 the TAP device is marked down and is removed.
-But this behaviour can be overridden by the use of the persist flag, example::
+But this behavior can be overridden by the use of the persist flag, example::
 
   --vdev=net_tap0,iface=tap0,persist ...
 
-The TUN PMD allows user to create a TUN device on host. The PMD allows user
-to transmit and receive packets via DPDK API calls with L3 header and payload.
-The devices in host can be accessed via ``ifconfig`` or ``ip`` command. TUN
-interfaces are passed to DPDK ``rte_eal_init`` arguments as ``--vdev=net_tunX``,
+TUN devices
+-----------
+
+The TAP device can be used an L3 tunnel only device (TUN).
+This type of device does not include the Ethernet (L2) header; all packets
+are sent and received as IP packets.
+
+TUN devices are created with the command line arguments ``--vdev=net_tunX``,
 where X stands for unique id, example::
 
    --vdev=net_tun0 --vdev=net_tun1,iface=foo1, ...
@@ -103,27 +87,33 @@ options. Default interface name is ``dtunX``, where X stands for unique id.
 Flow API support
 ----------------
 
-The tap PMD supports major flow API pattern items and actions, when running on
-linux kernels above 4.2 ("Flower" classifier required).
-The kernel support can be checked with this command::
+The TAP PMD supports major flow API pattern items and actions.
+
+Requirements
+~~~~~~~~~~~~
 
-   zcat /proc/config.gz | ( grep 'CLS_FLOWER=' || echo 'not supported' ) |
-   tee -a /dev/stderr | grep -q '=m' &&
-   lsmod | ( grep cls_flower || echo 'try modprobe cls_flower' )
+Flow support in TAP driver requires the Linux kernel support of flow based
+traffic control filter ``flower``. This was added in Linux 4.3 kernel.
 
-Supported items:
+The implementation of RSS action uses an eBPF module that requires additional
+libraries and tools. Building the RSS support requires the ``clang``
+compiler to compile the C code to BPF target; ``bpftool`` to convert the
+compiled BPF object to a header file; and ``libbpf`` to load the eBPF
+action into the kernel.
 
-- eth: src and dst (with variable masks), and eth_type (0xffff mask).
-- vlan: vid, pcp, but not eid. (requires kernel 4.9)
-- ipv4/6: src and dst (with variable masks), and ip_proto (0xffff mask).
-- udp/tcp: src and dst port (0xffff) mask.
+Supported match items:
+
+  - eth: src and dst (with variable masks), and eth_type (0xffff mask).
+  - vlan: vid, pcp, but not eid. (requires kernel 4.9)
+  - ipv4/6: src and dst (with variable masks), and ip_proto (0xffff mask).
+  - udp/tcp: src and dst port (0xffff) mask.
 
 Supported actions:
 
 - DROP
 - QUEUE
 - PASSTHRU
-- RSS (requires kernel 4.9)
+- RSS
 
 It is generally not possible to provide a "last" item. However, if the "last"
 item, once masked, is identical to the masked spec, then it is supported.
@@ -133,7 +123,7 @@ full mask (exact match).
 
 As rules are translated to TC, it is possible to show them with something like::
 
-   tc -s filter show dev tap1 parent 1:
+   tc -s filter show dev dtap1 parent 1:
 
 Examples of testpmd flow rules
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -174,135 +164,25 @@ The IPC synchronization of Rx/Tx queues is currently limited:
   - Maximum 8 queues shared
   - Synchronized on probing, but not on later port update
 
-Example
--------
-
-The following is a simple example of using the TAP PMD with the Pktgen
-packet generator. It requires that the ``socat`` utility is installed on the
-test system.
-
-Build DPDK, then pull down Pktgen and build pktgen using the DPDK SDK/Target
-used to build the dpdk you pulled down.
-
-Run pktgen from the pktgen directory in a terminal with a commandline like the
-following::
-
-    sudo ./app/app/x86_64-native-linux-gcc/app/pktgen -l 1-5 -n 4        \
-     --proc-type auto --log-level debug --socket-mem 512,512 --file-prefix pg   \
-     --vdev=net_tap0 --vdev=net_tap1 -b 05:00.0 -b 05:00.1                  \
-     -b 04:00.0 -b 04:00.1 -b 04:00.2 -b 04:00.3                            \
-     -b 81:00.0 -b 81:00.1 -b 81:00.2 -b 81:00.3                            \
-     -b 82:00.0 -b 83:00.0 -- -T -P -m [2:3].0 -m [4:5].1                   \
-     -f themes/black-yellow.theme
-
-.. Note:
-
-   Change the ``-b`` options to exclude all of your physical ports. The
-   following command line is all one line.
-
-   Also, ``-f themes/black-yellow.theme`` is optional if the default colors
-   work on your system configuration. See the Pktgen docs for more
-   information.
-
-Verify with ``ifconfig -a`` command in a different xterm window, should have a
-``dtap0`` and ``dtap1`` interfaces created.
-
-Next set the links for the two interfaces to up via the commands below::
-
-    sudo ip link set dtap0 up; sudo ip addr add 192.168.0.250/24 dev dtap0
-    sudo ip link set dtap1 up; sudo ip addr add 192.168.1.250/24 dev dtap1
-
-Then use socat to create a loopback for the two interfaces::
-
-    sudo socat interface:dtap0 interface:dtap1
-
-Then on the Pktgen command line interface you can start sending packets using
-the commands ``start 0`` and ``start 1`` or you can start both at the same
-time with ``start all``. The command ``str`` is an alias for ``start all`` and
-``stp`` is an alias for ``stop all``.
-
-While running you should see the 64 byte counters increasing to verify the
-traffic is being looped back. You can use ``set all size XXX`` to change the
-size of the packets after you stop the traffic. Use pktgen ``help``
-command to see a list of all commands. You can also use the ``-f`` option to
-load commands at startup in command line or Lua script in pktgen.
 
 RSS specifics
 -------------
-Packet distribution in TAP is done by the kernel which has a default
-distribution. This feature is adding RSS distribution based on eBPF code.
-The default eBPF code calculates RSS hash based on Toeplitz algorithm for
-a fixed RSS key. It is calculated on fixed packet offsets. For IPv4 and IPv6 it
-is calculated over src/dst addresses (8 or 32 bytes for IPv4 or IPv6
-respectively) and src/dst TCP/UDP ports (4 bytes).
-
-The RSS algorithm is written in file ``tap_bpf_program.c`` which
-does not take part in TAP PMD compilation. Instead this file is compiled
-in advance to eBPF object file. The eBPF object file is then parsed and
-translated into eBPF byte code in the format of C arrays of eBPF
-instructions. The C array of eBPF instructions is part of TAP PMD tree and
-is taking part in TAP PMD compilation. At run time the C arrays are uploaded to
-the kernel via BPF system calls and the RSS hash is calculated by the
-kernel.
-
-It is possible to support different RSS hash algorithms by updating file
-``tap_bpf_program.c``  In order to add a new RSS hash algorithm follow these
-steps:
-
-#. Write the new RSS implementation in file ``tap_bpf_program.c``
-
-   BPF programs which are uploaded to the kernel correspond to
-   C functions under different ELF sections.
-
-#. Install ``LLVM`` library and ``clang`` compiler versions 3.7 and above
-
-#. Use make to compile  `tap_bpf_program.c`` via ``LLVM`` into an object file
-   and extract the resulting instructions into ``tap_bpf_insn.h``::
-
-    cd bpf; make
-
-#. Recompile the TAP PMD.
-
-The C arrays are uploaded to the kernel using BPF system calls.
-
-``tc`` (traffic control) is a well known user space utility program used to
-configure the Linux kernel packet scheduler. It is usually packaged as
-part of the ``iproute2`` package.
-Since commit 11c39b5e9 ("tc: add eBPF support to f_bpf") ``tc`` can be used
-to uploads eBPF code to the kernel and can be patched in order to print the
-C arrays of eBPF instructions just before calling the BPF system call.
-Please refer to ``iproute2`` package file ``lib/bpf.c`` function
-``bpf_prog_load()``.
-
-An example utility for eBPF instruction generation in the format of C arrays will
-be added in next releases
-
-TAP reports on supported RSS functions as part of dev_infos_get callback:
-``RTE_ETH_RSS_IP``, ``RTE_ETH_RSS_UDP`` and ``RTE_ETH_RSS_TCP``.
-**Known limitation:** TAP supports all of the above hash functions together
-and not in partial combinations.
-
-Systems supporting flow API
----------------------------
-
-- "tc flower" classifier requires linux kernel above 4.2
-- eBPF/RSS requires linux kernel above 4.9
-
-+--------------------+-----------------------+
-| RH7.3              | No flow rule support  |
-+--------------------+-----------------------+
-| RH7.4              | No RSS action support |
-+--------------------+-----------------------+
-| RH7.5              | No RSS action support |
-+--------------------+-----------------------+
-| SLES 15,           | No limitation         |
-| kernel 4.12        |                       |
-+--------------------+-----------------------+
-| Azure Ubuntu 16.04,| No limitation         |
-| kernel 4.13        |                       |
-+--------------------+-----------------------+
+The default packet distribution in TAP without flow rules is done by the
+kernel which has a default flow based distribution.
+When flow rules are used to distribute packets across a set of queues
+an eBPF program is used to calculate the RSS based on Toeplitz algorithm for
+with the given key.
+
+The hash is calculated for IPv4 and IPv6, over src/dst addresses
+(8 or 32 bytes for IPv4 or IPv6 respectively) and
+optionally the src/dst TCP/UDP ports (4 bytes).
+
 
 Limitations
 -----------
 
-* Rx/Tx must have the same number of queues.
+- Since TAP device uses a file descriptors to talk to the kernel.
+  The same number of queues must be specified for receive and transmit.
+
+- The RSS algorithm only support L3 or L4 functions. It does not support
+  finer grain selections (for example: only IPV6 packets with extension headers).
doc/guides/rel_notes/release_24_07.rst +7 -0
index a69f24cf99..8652271ed2 100644
@@ -55,6 +55,13 @@ New Features
      Also, make sure to start the actual text at the margin.
      =======================================================
 
+* **TAP PMD updates.**
+
+  * Fixed support of RSS flow action to work with current Linux
+    kernels and BPF tooling. Will only be enabled if clang and bpftool
+    are available.
+
+  * Support up to 8 queues when used by secondary process
 
 Removed Items
 -------------
Signature · 1 line
2.43.0
#120 lore raw

v12 cover net/tap: RSS and other fixes

In reply to Stephen Hemminger

The support of doing RSS for rte_flow_action was a cool idea but it has been broken for several releases of DPDK as the kernel and BPF infrastructure changed.

This series cleans up the BPF program, implements several features that were never completed in the original code and changes to use the current BPF tool chain.

The result should be easier to read and maintain. I do not intend to support backporting this to stable releases due to lack of demand and dealing with older distros.

v12 - separate out the fix for rxq fd in flow_isolate
cleanup log messages
bug fix for queue full

Stephen Hemminger (12):
net/tap: fix fd check in flow_isolate
net/tap: do not duplicate fd's
net/tap: remove unused fields
net/tap: validate and setup parameters for BPF RSS net/tap: do not build flow support if header is out of date net/tap: rewrite the RSS BPF program
net/tap: use libbpf to load new BPF program net/tap: remove no longer used files
net/tap: simplify internals
net/tap: remove extraneous newlines
net/tap: do not mark queue full as error
net/tap: update documentation

 .gitignore                             |    3 -
 doc/guides/nics/tap.rst                |  274 ++--
 doc/guides/rel_notes/release_24_07.rst |    7 +
 drivers/net/tap/bpf/Makefile           |   19 -
 drivers/net/tap/bpf/README             |   49 +
 drivers/net/tap/bpf/bpf_api.h          |  276 ----
 drivers/net/tap/bpf/bpf_elf.h          |   53 -
 drivers/net/tap/bpf/bpf_extract.py     |   86 --
 drivers/net/tap/bpf/meson.build        |  107 ++
 drivers/net/tap/bpf/tap_bpf_program.c  |  255 ----
 drivers/net/tap/bpf/tap_rss.c          |  267 ++++
 drivers/net/tap/meson.build            |   42 +-
 drivers/net/tap/rte_eth_tap.c          |  384 +++---
 drivers/net/tap/rte_eth_tap.h          |   42 +-
 drivers/net/tap/tap_bpf.h              |  121 --
 drivers/net/tap/tap_bpf_api.c          |  190 ---
 drivers/net/tap/tap_bpf_insns.h        | 1743 ------------------------
 drivers/net/tap/tap_flow.c             |  557 ++------
 drivers/net/tap/tap_flow.h             |   17 +-
 drivers/net/tap/tap_intr.c             |    7 +-
 drivers/net/tap/tap_rss.h              |   21 +-
 drivers/net/tap/tap_tcmsgs.h           |    4 +-
 22 files changed, 907 insertions(+), 3617 deletions(-)
 delete mode 100644 drivers/net/tap/bpf/Makefile
 create mode 100644 drivers/net/tap/bpf/README
 delete mode 100644 drivers/net/tap/bpf/bpf_api.h
 delete mode 100644 drivers/net/tap/bpf/bpf_elf.h
 delete mode 100644 drivers/net/tap/bpf/bpf_extract.py
 create mode 100644 drivers/net/tap/bpf/meson.build
 delete mode 100644 drivers/net/tap/bpf/tap_bpf_program.c
 create mode 100644 drivers/net/tap/bpf/tap_rss.c
 delete mode 100644 drivers/net/tap/tap_bpf.h
 delete mode 100644 drivers/net/tap/tap_bpf_api.c
 delete mode 100644 drivers/net/tap/tap_bpf_insns.h
Signature · 1 line
2.43.0
#121 lore raw

PATCH v12 1/12 net/tap: fix fd check in flow_isolate

The check for receive queue fd in flow_isolate is incorrect. If queue has not been setup then fd will be -1 not 0.

---
 drivers/net/tap/tap_flow.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/tap/tap_flow.c +1 -1
index fa50fe45d7..79cd6a12ca 100644
@@ -1595,7 +1595,7 @@ tap_flow_isolate(struct rte_eth_dev *dev,
 	 * If netdevice is there, setup appropriate flow rules immediately.
 	 * Otherwise it will be set when bringing up the netdevice (tun_alloc).
 	 */
-	if (!process_private->rxq_fds[0])
+	if (process_private->rxq_fds[0] == -1)
 		return 0;
 	if (set) {
 		struct rte_flow *remote_flow;
Signature · 1 line
2.43.0
#123 lore raw

PATCH v12 2/12 net/tap: do not duplicate fd's

In reply to Stephen Hemminger

The TAP device can use same file descriptor for both rx and tx queues. This allows up to 8 queues (versus 4) to be used with secondary process.

Bugzilla ID: 1381

---
 drivers/net/tap/rte_eth_tap.c | 192 ++++++++++++++--------------------
 drivers/net/tap/rte_eth_tap.h |   3 +-
 drivers/net/tap/tap_flow.c    |   3 +-
 drivers/net/tap/tap_intr.c    |   7 +-
 4 files changed, 85 insertions(+), 120 deletions(-)
drivers/net/tap/rte_eth_tap.c +78 -114
index 69d9da695b..b84fc01856 100644
@@ -124,8 +124,7 @@ enum ioctl_mode {
 /* Message header to synchronize queues via IPC */
 struct ipc_queues {
 	char port_name[RTE_DEV_NAME_MAX_LEN];
-	int rxq_count;
-	int txq_count;
+	int q_count;
 	/*
 	 * The file descriptors are in the dedicated part
 	 * of the Unix message to be translated by the kernel.
@@ -446,7 +445,7 @@ pmd_rx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 		uint16_t data_off = rte_pktmbuf_headroom(mbuf);
 		int len;
 
-		len = readv(process_private->rxq_fds[rxq->queue_id],
+		len = readv(process_private->fds[rxq->queue_id],
 			*rxq->iovecs,
 			1 + (rxq->rxmode->offloads & RTE_ETH_RX_OFFLOAD_SCATTER ?
 			     rxq->nb_rx_desc : 1));
@@ -643,7 +642,7 @@ tap_write_mbufs(struct tx_queue *txq, uint16_t num_mbufs,
 		}
 
 		/* copy the tx frame data */
-		n = writev(process_private->txq_fds[txq->queue_id], iovecs, k);
+		n = writev(process_private->fds[txq->queue_id], iovecs, k);
 		if (n <= 0)
 			return -1;
 
@@ -851,7 +850,6 @@ tap_mp_req_on_rxtx(struct rte_eth_dev *dev)
 	struct rte_mp_msg msg;
 	struct ipc_queues *request_param = (struct ipc_queues *)msg.param;
 	int err;
-	int fd_iterator = 0;
 	struct pmd_process_private *process_private = dev->process_private;
 	int i;
 
@@ -859,16 +857,13 @@ tap_mp_req_on_rxtx(struct rte_eth_dev *dev)
 	strlcpy(msg.name, TAP_MP_REQ_START_RXTX, sizeof(msg.name));
 	strlcpy(request_param->port_name, dev->data->name, sizeof(request_param->port_name));
 	msg.len_param = sizeof(*request_param);
-	for (i = 0; i < dev->data->nb_tx_queues; i++) {
-		msg.fds[fd_iterator++] = process_private->txq_fds[i];
-		msg.num_fds++;
-		request_param->txq_count++;
-	}
-	for (i = 0; i < dev->data->nb_rx_queues; i++) {
-		msg.fds[fd_iterator++] = process_private->rxq_fds[i];
-		msg.num_fds++;
-		request_param->rxq_count++;
-	}
+
+	/* rx and tx share file descriptors and nb_tx_queues == nb_rx_queues */
+	for (i = 0; i < dev->data->nb_rx_queues; i++)
+		msg.fds[i] = process_private->fds[i];
+
+	request_param->q_count = dev->data->nb_rx_queues;
+	msg.num_fds = dev->data->nb_rx_queues;
 
 	err = rte_mp_sendmsg(&msg);
 	if (err < 0) {
@@ -910,8 +905,6 @@ tap_mp_req_start_rxtx(const struct rte_mp_msg *request, __rte_unused const void
 	struct rte_eth_dev *dev;
 	const struct ipc_queues *request_param =
 		(const struct ipc_queues *)request->param;
-	int fd_iterator;
-	int queue;
 	struct pmd_process_private *process_private;
 
 	dev = rte_eth_dev_get_by_name(request_param->port_name);
@@ -920,14 +913,13 @@ tap_mp_req_start_rxtx(const struct rte_mp_msg *request, __rte_unused const void
 			request_param->port_name);
 		return -1;
 	}
+
 	process_private = dev->process_private;
-	fd_iterator = 0;
-	TAP_LOG(DEBUG, "tap_attach rx_q:%d tx_q:%d\n", request_param->rxq_count,
-		request_param->txq_count);
-	for (queue = 0; queue < request_param->txq_count; queue++)
-		process_private->txq_fds[queue] = request->fds[fd_iterator++];
-	for (queue = 0; queue < request_param->rxq_count; queue++)
-		process_private->rxq_fds[queue] = request->fds[fd_iterator++];
+	TAP_LOG(DEBUG, "tap_attach q:%d\n", request_param->q_count);
+
+	for (int q = 0; q < request_param->q_count; q++)
+		process_private->fds[q] = request->fds[q];
+
 
 	return 0;
 }
@@ -1115,13 +1107,21 @@ tap_stats_reset(struct rte_eth_dev *dev)
 	return 0;
 }
 
+static void
+tap_queue_close(struct pmd_process_private *process_private, uint16_t qid)
+{
+	if (process_private->fds[qid] != -1) {
+		close(process_private->fds[qid]);
+		process_private->fds[qid] = -1;
+	}
+}
+
 static int
 tap_dev_close(struct rte_eth_dev *dev)
 {
 	int i;
 	struct pmd_internals *internals = dev->data->dev_private;
 	struct pmd_process_private *process_private = dev->process_private;
-	struct rx_queue *rxq;
 
 	if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
 		rte_free(dev->process_private);
@@ -1141,19 +1141,14 @@ tap_dev_close(struct rte_eth_dev *dev)
 	}
 
 	for (i = 0; i < RTE_PMD_TAP_MAX_QUEUES; i++) {
-		if (process_private->rxq_fds[i] != -1) {
-			rxq = &internals->rxq[i];
-			close(process_private->rxq_fds[i]);
-			process_private->rxq_fds[i] = -1;
-			tap_rxq_pool_free(rxq->pool);
-			rte_free(rxq->iovecs);
-			rxq->pool = NULL;
-			rxq->iovecs = NULL;
-		}
-		if (process_private->txq_fds[i] != -1) {
-			close(process_private->txq_fds[i]);
-			process_private->txq_fds[i] = -1;
-		}
+		struct rx_queue *rxq = &internals->rxq[i];
+
+		tap_queue_close(process_private, i);
+
+		tap_rxq_pool_free(rxq->pool);
+		rte_free(rxq->iovecs);
+		rxq->pool = NULL;
+		rxq->iovecs = NULL;
 	}
 
 	if (internals->remote_if_index) {
@@ -1206,15 +1201,16 @@ tap_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
 
 	if (!rxq)
 		return;
+
 	process_private = rte_eth_devices[rxq->in_port].process_private;
-	if (process_private->rxq_fds[rxq->queue_id] != -1) {
-		close(process_private->rxq_fds[rxq->queue_id]);
-		process_private->rxq_fds[rxq->queue_id] = -1;
-		tap_rxq_pool_free(rxq->pool);
-		rte_free(rxq->iovecs);
-		rxq->pool = NULL;
-		rxq->iovecs = NULL;
-	}
+
+	tap_rxq_pool_free(rxq->pool);
+	rte_free(rxq->iovecs);
+	rxq->pool = NULL;
+	rxq->iovecs = NULL;
+
+	if (dev->data->tx_queues[qid] == NULL)
+		tap_queue_close(process_private, qid);
 }
 
 static void
@@ -1225,12 +1221,10 @@ tap_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
 
 	if (!txq)
 		return;
-	process_private = rte_eth_devices[txq->out_port].process_private;
 
-	if (process_private->txq_fds[txq->queue_id] != -1) {
-		close(process_private->txq_fds[txq->queue_id]);
-		process_private->txq_fds[txq->queue_id] = -1;
-	}
+	process_private = rte_eth_devices[txq->out_port].process_private;
+	if (dev->data->rx_queues[qid] == NULL)
+		tap_queue_close(process_private, qid);
 }
 
 static int
@@ -1482,52 +1476,31 @@ tap_setup_queue(struct rte_eth_dev *dev,
 		uint16_t qid,
 		int is_rx)
 {
-	int ret;
-	int *fd;
-	int *other_fd;
-	const char *dir;
+	int fd, ret;
 	struct pmd_internals *pmd = dev->data->dev_private;
 	struct pmd_process_private *process_private = dev->process_private;
 	struct rx_queue *rx = &internals->rxq[qid];
 	struct tx_queue *tx = &internals->txq[qid];
-	struct rte_gso_ctx *gso_ctx;
+	struct rte_gso_ctx *gso_ctx = is_rx ? NULL : &tx->gso_ctx;
+	const char *dir = is_rx ? "rx" : "tx";
 
-	if (is_rx) {
-		fd = &process_private->rxq_fds[qid];
-		other_fd = &process_private->txq_fds[qid];
-		dir = "rx";
-		gso_ctx = NULL;
-	} else {
-		fd = &process_private->txq_fds[qid];
-		other_fd = &process_private->rxq_fds[qid];
-		dir = "tx";
-		gso_ctx = &tx->gso_ctx;
-	}
-	if (*fd != -1) {
+	fd = process_private->fds[qid];
+	if (fd != -1) {
 		/* fd for this queue already exists */
 		TAP_LOG(DEBUG, "%s: fd %d for %s queue qid %d exists",
-			pmd->name, *fd, dir, qid);
+			pmd->name, fd, dir, qid);
 		gso_ctx = NULL;
-	} else if (*other_fd != -1) {
-		/* Only other_fd exists. dup it */
-		*fd = dup(*other_fd);
-		if (*fd < 0) {
-			*fd = -1;
-			TAP_LOG(ERR, "%s: dup() failed.", pmd->name);
-			return -1;
-		}
-		TAP_LOG(DEBUG, "%s: dup fd %d for %s queue qid %d (%d)",
-			pmd->name, *other_fd, dir, qid, *fd);
 	} else {
-		/* Both RX and TX fds do not exist (equal -1). Create fd */
-		*fd = tun_alloc(pmd, 0, 0);
-		if (*fd < 0) {
-			*fd = -1; /* restore original value */
+		fd = tun_alloc(pmd, 0, 0);
+		if (fd < 0) {
 			TAP_LOG(ERR, "%s: tun_alloc() failed.", pmd->name);
 			return -1;
 		}
+
 		TAP_LOG(DEBUG, "%s: add %s queue for qid %d fd %d",
-			pmd->name, dir, qid, *fd);
+			pmd->name, dir, qid, fd);
+
+		process_private->fds[qid] = fd;
 	}
 
 	tx->mtu = &dev->data->mtu;
@@ -1540,7 +1513,7 @@ tap_setup_queue(struct rte_eth_dev *dev,
 
 	tx->type = pmd->type;
 
-	return *fd;
+	return fd;
 }
 
 static int
@@ -1620,7 +1593,7 @@ tap_rx_queue_setup(struct rte_eth_dev *dev,
 
 	TAP_LOG(DEBUG, "  RX TUNTAP device name %s, qid %d on fd %d",
 		internals->name, rx_queue_id,
-		process_private->rxq_fds[rx_queue_id]);
+		process_private->fds[rx_queue_id]);
 
 	return 0;
 
@@ -1664,7 +1637,7 @@ tap_tx_queue_setup(struct rte_eth_dev *dev,
 	TAP_LOG(DEBUG,
 		"  TX TUNTAP device name %s, qid %d on fd %d csum %s",
 		internals->name, tx_queue_id,
-		process_private->txq_fds[tx_queue_id],
+		process_private->fds[tx_queue_id],
 		txq->csum ? "on" : "off");
 
 	return 0;
@@ -2001,10 +1974,9 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 	dev->intr_handle = pmd->intr_handle;
 
 	/* Presetup the fds to -1 as being not valid */
-	for (i = 0; i < RTE_PMD_TAP_MAX_QUEUES; i++) {
-		process_private->rxq_fds[i] = -1;
-		process_private->txq_fds[i] = -1;
-	}
+	for (i = 0; i < RTE_PMD_TAP_MAX_QUEUES; i++)
+		process_private->fds[i] = -1;
+
 
 	if (pmd->type == ETH_TUNTAP_TYPE_TAP) {
 		if (rte_is_zero_ether_addr(mac_addr))
@@ -2332,7 +2304,6 @@ tap_mp_attach_queues(const char *port_name, struct rte_eth_dev *dev)
 	struct ipc_queues *request_param = (struct ipc_queues *)request.param;
 	struct ipc_queues *reply_param;
 	struct pmd_process_private *process_private = dev->process_private;
-	int queue, fd_iterator;
 
 	/* Prepare the request */
 	memset(&request, 0, sizeof(request));
@@ -2352,18 +2323,17 @@ tap_mp_attach_queues(const char *port_name, struct rte_eth_dev *dev)
 	TAP_LOG(DEBUG, "Received IPC reply for %s", reply_param->port_name);
 
 	/* Attach the queues from received file descriptors */
-	if (reply_param->rxq_count + reply_param->txq_count != reply->num_fds) {
+	if (reply_param->q_count != reply->num_fds) {
 		TAP_LOG(ERR, "Unexpected number of fds received");
 		return -1;
 	}
 
-	dev->data->nb_rx_queues = reply_param->rxq_count;
-	dev->data->nb_tx_queues = reply_param->txq_count;
-	fd_iterator = 0;
-	for (queue = 0; queue < reply_param->rxq_count; queue++)
-		process_private->rxq_fds[queue] = reply->fds[fd_iterator++];
-	for (queue = 0; queue < reply_param->txq_count; queue++)
-		process_private->txq_fds[queue] = reply->fds[fd_iterator++];
+	dev->data->nb_rx_queues = reply_param->q_count;
+	dev->data->nb_tx_queues = reply_param->q_count;
+
+	for (int q = 0; q < reply_param->q_count; q++)
+		process_private->fds[q] = reply->fds[q];
+
 	free(reply);
 	return 0;
 }
@@ -2393,25 +2363,19 @@ tap_mp_sync_queues(const struct rte_mp_msg *request, const void *peer)
 
 	/* Fill file descriptors for all queues */
 	reply.num_fds = 0;
-	reply_param->rxq_count = 0;
-	if (dev->data->nb_rx_queues + dev->data->nb_tx_queues >
-			RTE_MP_MAX_FD_NUM){
-		TAP_LOG(ERR, "Number of rx/tx queues exceeds max number of fds");
+	reply_param->q_count = 0;
+
+	RTE_ASSERT(dev->data->nb_rx_queues == dev->data->nb_tx_queues);
+	if (dev->data->nb_rx_queues > RTE_MP_MAX_FD_NUM) {
+		TAP_LOG(ERR, "Number of rx/tx queues %u exceeds max number of fds %u",
+			dev->data->nb_rx_queues, RTE_MP_MAX_FD_NUM);
 		return -1;
 	}
 
 	for (queue = 0; queue < dev->data->nb_rx_queues; queue++) {
-		reply.fds[reply.num_fds++] = process_private->rxq_fds[queue];
-		reply_param->rxq_count++;
-	}
-	RTE_ASSERT(reply_param->rxq_count == dev->data->nb_rx_queues);
-
-	reply_param->txq_count = 0;
-	for (queue = 0; queue < dev->data->nb_tx_queues; queue++) {
-		reply.fds[reply.num_fds++] = process_private->txq_fds[queue];
-		reply_param->txq_count++;
+		reply.fds[reply.num_fds++] = process_private->fds[queue];
+		reply_param->q_count++;
 	}
-	RTE_ASSERT(reply_param->txq_count == dev->data->nb_tx_queues);
 
 	/* Send reply */
 	strlcpy(reply.name, request->name, sizeof(reply.name));
drivers/net/tap/rte_eth_tap.h +1 -2
index 5ac93f93e9..dc8201020b 100644
@@ -96,8 +96,7 @@ struct pmd_internals {
 };
 
 struct pmd_process_private {
-	int rxq_fds[RTE_PMD_TAP_MAX_QUEUES];
-	int txq_fds[RTE_PMD_TAP_MAX_QUEUES];
+	int fds[RTE_PMD_TAP_MAX_QUEUES];
 };
 
 /* tap_intr.c */
drivers/net/tap/tap_flow.c +2 -1
index 79cd6a12ca..a78fd50cd4 100644
@@ -1595,8 +1595,9 @@ tap_flow_isolate(struct rte_eth_dev *dev,
 	 * If netdevice is there, setup appropriate flow rules immediately.
 	 * Otherwise it will be set when bringing up the netdevice (tun_alloc).
 	 */
-	if (process_private->rxq_fds[0] == -1)
+	if (process_private->fds[0] == -1)
 		return 0;
+
 	if (set) {
 		struct rte_flow *remote_flow;
 
drivers/net/tap/tap_intr.c +4 -3
index a9097def1a..1908f71f97 100644
@@ -68,9 +68,11 @@ tap_rx_intr_vec_install(struct rte_eth_dev *dev)
 	}
 	for (i = 0; i < n; i++) {
 		struct rx_queue *rxq = pmd->dev->data->rx_queues[i];
+		int fd = process_private->fds[i];
 
 		/* Skip queues that cannot request interrupts. */
-		if (!rxq || process_private->rxq_fds[i] == -1) {
+		if (!rxq || fd == -1) {
+			/* Use invalid intr_vec[] index to disable entry. */
 			/* Use invalid intr_vec[] index to disable entry. */
 			if (rte_intr_vec_list_index_set(intr_handle, i,
 			RTE_INTR_VEC_RXTX_OFFSET + RTE_MAX_RXTX_INTR_VEC_ID))
@@ -80,8 +82,7 @@ tap_rx_intr_vec_install(struct rte_eth_dev *dev)
 		if (rte_intr_vec_list_index_set(intr_handle, i,
 					RTE_INTR_VEC_RXTX_OFFSET + count))
 			return -rte_errno;
-		if (rte_intr_efds_index_set(intr_handle, count,
-						   process_private->rxq_fds[i]))
+		if (rte_intr_efds_index_set(intr_handle, count, fd))
 			return -rte_errno;
 		count++;
 	}
Signature · 1 line
2.43.0
Acked-by on v12 2/12
#124 lore raw

Re: [PATCH v12 02/12] net/tap: do not duplicate fd's

Quoted 3 lines · Stephen Hemminger

The TAP device can use same file descriptor for both rx and tx queues. This allows up to 8 queues (versus 4) to be used with secondary process.

It would be nice to briefly update where this limit comes from, as removing this limitation can be longer term solution for this issue.

Quoted 3 lines

Bugzilla ID: 1381

Can you please move the relevant release notes update to this patch? So we can distribute the release notes update to patches instead of dedicated update for it.

Except from above change,

#125 lore raw

Re: [PATCH v12 02/12] net/tap: do not duplicate fd's

Quoted 7 lines · On Mon, 20 May 2024 18:46:30 +0100 Ferruh Yigit <[email protected]> wrote:
Quoted 3 lines · Stephen Hemminger

The TAP device can use same file descriptor for both rx and tx queues. This allows up to 8 queues (versus 4) to be used with secondary process.

It would be nice to briefly update where this limit comes from, as removing this limitation can be longer term solution for this issue.

Sure, the limit comes from a too low value in RTE_MP_MAX_FD_NUM (8) It should have been set to the max Linux supports which is SCM_MAX_FD (253).

But fixing it their breaks the ABI, and needs to wait for 24.11. Impacts AF_XDP as well.

By not duplicating we can make TAP work with 8 queues and still get MP support. Good idea anyway not to waste fd's.

Quoted 12 lines
Quoted 4 lines

Bugzilla ID: 1381

Can you please move the relevant release notes update to this patch? So we can distribute the release notes update to patches instead of dedicated update for it.

Except from above change,

#126 lore raw

PATCH v12 3/12 net/tap: remove unused fields

In reply to Stephen Hemminger

The driver doesn't support these other hash types, and there is no reason to implement these in future. The rss_flows list was set but never used.

---
 drivers/net/tap/rte_eth_tap.h | 4 +---
 drivers/net/tap/tap_flow.c    | 1 -
 drivers/net/tap/tap_rss.h     | 6 ------
 3 files changed, 1 insertion(+), 10 deletions(-)
drivers/net/tap/rte_eth_tap.h +1 -3
index dc8201020b..1bcf92ce80 100644
@@ -77,14 +77,12 @@ struct pmd_internals {
 	int ioctl_sock;                   /* socket for ioctl calls */
 	int nlsk_fd;                      /* Netlink socket fd */
 	int flow_isolate;                 /* 1 if flow isolation is enabled */
-	int flower_support;               /* 1 if kernel supports, else 0 */
-	int flower_vlan_support;          /* 1 if kernel supports, else 0 */
 	int rss_enabled;                  /* 1 if RSS is enabled, else 0 */
 	int persist;			  /* 1 if keep link up, else 0 */
 	/* implicit rules set when RSS is enabled */
 	int map_fd;                       /* BPF RSS map fd */
 	int bpf_fd[RTE_PMD_TAP_MAX_QUEUES];/* List of bpf fds per queue */
-	LIST_HEAD(tap_rss_flows, rte_flow) rss_flows;
+
 	LIST_HEAD(tap_flows, rte_flow) flows;        /* rte_flow rules */
 	/* implicit rte_flow rules set when a remote device is active */
 	LIST_HEAD(tap_implicit_flows, rte_flow) implicit_flows;
drivers/net/tap/tap_flow.c +0 -1
index a78fd50cd4..8fccd599f0 100644
@@ -1958,7 +1958,6 @@ static int rss_enable(struct pmd_internals *pmd,
 				errno, strerror(errno));
 			return err;
 		}
-		LIST_INSERT_HEAD(&pmd->rss_flows, rss_flow, next);
 	}
 
 	pmd->rss_enabled = 1;
drivers/net/tap/tap_rss.h +0 -6
index dff46a012f..8766ffc244 100644
@@ -21,12 +21,6 @@ enum hash_field {
 	HASH_FIELD_IPV4_L3_L4,	/* IPv4 src/dst addr + L4 src/dst ports */
 	HASH_FIELD_IPV6_L3,	/* IPv6 src/dst addr */
 	HASH_FIELD_IPV6_L3_L4,	/* IPv6 src/dst addr + L4 src/dst ports */
-	HASH_FIELD_L2_SRC,	/* Ethernet src addr */
-	HASH_FIELD_L2_DST,	/* Ethernet dst addr */
-	HASH_FIELD_L3_SRC,	/* L3 src addr */
-	HASH_FIELD_L3_DST,	/* L3 dst addr */
-	HASH_FIELD_L4_SRC,	/* TCP/UDP src ports */
-	HASH_FIELD_L4_DST,	/* TCP/UDP dst ports */
 };
 
 struct rss_key {
Signature · 1 line
2.43.0
#128 lore raw

PATCH v12 4/12 net/tap: validate and setup parameters for BPF RSS

In reply to Stephen Hemminger

The flow RSS support via BPF was not using the key, or hash type parameters. Which is good because they were never properly setup.

Fix the setup and validate the flow parameters, the BPF side gets fixed later.

---
 drivers/net/tap/tap_flow.c | 65 +++++++++++++++++++++++++++++++++++---
 drivers/net/tap/tap_rss.h  |  5 ++-
 2 files changed, 62 insertions(+), 8 deletions(-)
drivers/net/tap/tap_flow.c +60 -5
index 8fccd599f0..8cf64364a7 100644
@@ -11,9 +11,11 @@
 
 #include <rte_byteorder.h>
 #include <rte_jhash.h>
+#include <rte_thash.h>
 #include <rte_random.h>
 #include <rte_malloc.h>
 #include <rte_eth_tap.h>
+
 #include <tap_flow.h>
 #include <tap_autoconf.h>
 #include <tap_tcmsgs.h>
@@ -2061,6 +2063,21 @@ static int bpf_rss_key(enum bpf_rss_key_e cmd, __u32 *key_idx)
 	return err;
 }
 
+
+/* Default RSS hash key also used by mlx devices */
+static const uint8_t rss_hash_default_key[] = {
+	0x2c, 0xc6, 0x81, 0xd1,
+	0x5b, 0xdb, 0xf4, 0xf7,
+	0xfc, 0xa2, 0x83, 0x19,
+	0xdb, 0x1a, 0x3e, 0x94,
+	0x6b, 0x9e, 0x38, 0xd9,
+	0x2c, 0x9c, 0x03, 0xd1,
+	0xad, 0x99, 0x44, 0xa7,
+	0xd9, 0x56, 0x3d, 0x59,
+	0x06, 0x3c, 0x25, 0xf3,
+	0xfc, 0x1f, 0xdc, 0x2a,
+};
+
 /**
  * Add RSS hash calculations and queue selection
  *
@@ -2079,11 +2096,11 @@ static int rss_add_actions(struct rte_flow *flow, struct pmd_internals *pmd,
 			   const struct rte_flow_action_rss *rss,
 			   struct rte_flow_error *error)
 {
-	/* 4096 is the maximum number of instructions for a BPF program */
+	struct rss_key rss_entry = { };
+	const uint8_t *key_in;
+	uint32_t hash_type = 0;
 	unsigned int i;
 	int err;
-	struct rss_key rss_entry = { .hash_fields = 0,
-				     .key_size = 0 };
 
 	/* Check supported RSS features */
 	if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT)
@@ -2095,6 +2112,41 @@ static int rss_add_actions(struct rte_flow *flow, struct pmd_internals *pmd,
 			(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
 			 "a nonzero RSS encapsulation level is not supported");
 
+	if (rss->queue_num == 0 || rss->queue_num >= TAP_MAX_QUEUES)
+		return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
+					  "invalid number of queues");
+
+	/* allow RSS key_len 0 in case of NULL (default) RSS key. */
+	if (rss->key_len == 0) {
+		if (rss->key != NULL)
+			return rte_flow_error_set(error, ENOTSUP,
+						  RTE_FLOW_ERROR_TYPE_ACTION_CONF,
+						  &rss->key_len, "RSS hash key length 0");
+		key_in = rss_hash_default_key;
+	} else {
+		if (rss->key_len != TAP_RSS_HASH_KEY_SIZE)
+			return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+						  NULL, "RSS hash invalid key length");
+		if (rss->key == NULL)
+			return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+						  NULL, "RSS hash key is NULL");
+		key_in = rss->key;
+	}
+
+	if (rss->types & TAP_RSS_HF_MASK)
+		return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+					  NULL, "RSS hash type not supported");
+
+	if (rss->types & (RTE_ETH_RSS_NONFRAG_IPV4_UDP | RTE_ETH_RSS_NONFRAG_IPV4_TCP))
+		hash_type |= RTE_BIT32(HASH_FIELD_IPV4_L3_L4);
+	else if (rss->types & (RTE_ETH_RSS_IPV4 | RTE_ETH_RSS_FRAG_IPV4))
+		hash_type |= RTE_BIT32(HASH_FIELD_IPV4_L3);
+
+	if (rss->types & (RTE_ETH_RSS_NONFRAG_IPV6_UDP | RTE_ETH_RSS_NONFRAG_IPV6_TCP))
+		hash_type |= RTE_BIT32(HASH_FIELD_IPV6_L3_L4);
+	else if (rss->types & (RTE_ETH_RSS_IPV6 | RTE_ETH_RSS_FRAG_IPV6 | RTE_ETH_RSS_IPV6_EX))
+		hash_type |= RTE_BIT32(HASH_FIELD_IPV6_L3);
+
 	/* Get a new map key for a new RSS rule */
 	err = bpf_rss_key(KEY_CMD_GET, &flow->key_idx);
 	if (err < 0) {
@@ -2109,8 +2161,11 @@ static int rss_add_actions(struct rte_flow *flow, struct pmd_internals *pmd,
 	rss_entry.nb_queues = rss->queue_num;
 	for (i = 0; i < rss->queue_num; i++)
 		rss_entry.queues[i] = rss->queue[i];
-	rss_entry.hash_fields =
-		(1 << HASH_FIELD_IPV4_L3_L4) | (1 << HASH_FIELD_IPV6_L3_L4);
+
+	rss_entry.hash_fields = hash_type;
+	rte_convert_rss_key((const uint32_t *)key_in, (uint32_t *)rss_entry.key,
+			    TAP_RSS_HASH_KEY_SIZE);
+
 
 	/* Add this RSS entry to map */
 	err = tap_flow_bpf_update_rss_elem(pmd->map_fd,
drivers/net/tap/tap_rss.h +2 -3
index 8766ffc244..6009be7031 100644
@@ -24,11 +24,10 @@ enum hash_field {
 };
 
 struct rss_key {
-	 __u8 key[128];
 	__u32 hash_fields;
-	__u32 key_size;
-	__u32 queues[TAP_MAX_QUEUES];
+	__u8 key[TAP_RSS_HASH_KEY_SIZE];
 	__u32 nb_queues;
+	__u32 queues[TAP_MAX_QUEUES];
 } __attribute__((packed));
 
 #endif /* _TAP_RSS_H_ */
Signature · 1 line
2.43.0
#129 lore raw

Re: [PATCH v12 04/12] net/tap: validate and setup parameters for BPF RSS

Quoted 9 lines · Stephen Hemminger

The flow RSS support via BPF was not using the key, or hash type parameters. Which is good because they were never properly setup.

Fix the setup and validate the flow parameters, the BPF side gets fixed later.

<...>

Quoted 15 lines
drivers/net/tap/tap_flow.c +11 -0
@@ -2095,6 +2112,41 @@ static int rss_add_actions(struct rte_flow *flow, struct pmd_internals *pmd,
 			(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
 			 "a nonzero RSS encapsulation level is not supported");
 
+	if (rss->queue_num == 0 || rss->queue_num >= TAP_MAX_QUEUES)
+		return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
+					  "invalid number of queues");
+
+	/* allow RSS key_len 0 in case of NULL (default) RSS key. */
+	if (rss->key_len == 0) {
+		if (rss->key != NULL)
+			return rte_flow_error_set(error, ENOTSUP,
+						  RTE_FLOW_ERROR_TYPE_ACTION_CONF,
+						  &rss->key_len, "RSS hash key length 0");
+		key_in = rss_hash_default_key;

drivers/net/tap/tap_flow.c static int rss_add_actions(struct rte_flow *flow, struct pmd_internals *pmd, · line 2135

Quoted 10 lines
drivers/net/tap/tap_flow.c +9 -0
+	} else {
+		if (rss->key_len != TAP_RSS_HASH_KEY_SIZE)
+			return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+						  NULL, "RSS hash invalid key length");
+		if (rss->key == NULL)
+			return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+						  NULL, "RSS hash key is NULL");
+		key_in = rss->key;
+	}
 

Does it make sense to add above expectations (like if "key_len == 0" default key used, or 'key_len' expectations, etc..) to the function comment?

<...>

drivers/net/tap/tap_flow.c static int rss_add_actions(struct rte_flow *flow, struct pmd_internals *pmd, · line 2169

Quoted 12 lines
drivers/net/tap/tap_flow.c +5 -2
@@ -2109,8 +2161,11 @@ static int rss_add_actions(struct rte_flow *flow, struct pmd_internals *pmd,
 	rss_entry.nb_queues = rss->queue_num;
 	for (i = 0; i < rss->queue_num; i++)
 		rss_entry.queues[i] = rss->queue[i];
-	rss_entry.hash_fields =
-		(1 << HASH_FIELD_IPV4_L3_L4) | (1 << HASH_FIELD_IPV6_L3_L4);
+
+	rss_entry.hash_fields = hash_type;
+	rte_convert_rss_key((const uint32_t *)key_in, (uint32_t *)rss_entry.key,
+			    TAP_RSS_HASH_KEY_SIZE);
+
 

Why 'rte_convert_rss_key()' is required? Is this making an assumption on the CPU architecture?

#130 lore raw

Re: [PATCH v12 04/12] net/tap: validate and setup parameters for BPF RSS

Quoted 5 lines · On Mon, 20 May 2024 18:47:08 +0100 Ferruh Yigit <[email protected]> wrote:
Quoted 2 lines

+

Why 'rte_convert_rss_key()' is required? Is this making an assumption on the CPU architecture?

What is happening here is that the key passed in is in cpu native order, but the SW RSS algorithm needs it to be in big-endian to work with IP protocols that are big-endian.

In rte_thash the code to convert key is: rte_convert_rss_key() and the code use the converted key is rte_softrss_be().

The BPF code doesn't (and cant easily because of license/validator) use the same exact routine but it is equivalent to rte_softrss_be and uses pre-converted key for performance.

#131 lore raw

Re: [PATCH v12 04/12] net/tap: validate and setup parameters for BPF RSS

Quoted 14 lines · Stephen Hemminger
Quoted 5 lines · On Mon, 20 May 2024 18:47:08 +0100 Ferruh Yigit <[email protected]> wrote:
Quoted 2 lines

+

Why 'rte_convert_rss_key()' is required? Is this making an assumption on the CPU architecture?

What is happening here is that the key passed in is in cpu native order, but the SW RSS algorithm needs it to be in big-endian to work with IP protocols that are big-endian.

Quoted 7 lines

In rte_thash the code to convert key is: rte_convert_rss_key() and the code use the converted key is rte_softrss_be().

The BPF code doesn't (and cant easily because of license/validator) use the same exact routine but it is equivalent to rte_softrss_be and uses pre-converted key for performance.

got it, thanks for clarification. If there will be a new version, I think it helps others to add a comment before the call, up to you.

#132 lore raw

PATCH v12 5/12 net/tap: do not build flow support if header is out of date

In reply to Stephen Hemminger

The proper place for finding bpf structures and functions is in linux/bpf.h. The original version was trying to workaround the case where the build environment was running on old pre BPF version of Glibc, but the target environment had BPF.

Having own private (and divergent) version headers leads to future problems when BPF definitions evolve.

If the build infrastructure is so old that TC flower is not supported, then the TAP device will build without any flow support.

---
 drivers/net/tap/bpf/bpf_extract.py |   1 -
 drivers/net/tap/meson.build        |  17 ++--
 drivers/net/tap/rte_eth_tap.c      |  38 +++++++--
 drivers/net/tap/rte_eth_tap.h      |   7 +-
 drivers/net/tap/tap_bpf.h          | 121 -----------------------------
 drivers/net/tap/tap_bpf_api.c      |  20 +++--
 drivers/net/tap/tap_bpf_insns.h    |   2 -
 drivers/net/tap/tap_flow.c         |  90 ---------------------
 8 files changed, 60 insertions(+), 236 deletions(-)
 delete mode 100644 drivers/net/tap/tap_bpf.h
drivers/net/tap/bpf/bpf_extract.py +0 -1
index b630c42b80..73c4dafe4e 100644
@@ -65,7 +65,6 @@ def write_header(out, source):
         print(f' * Auto-generated from {source}', file=out)
     print(" * This not the original source file. Do NOT edit it.", file=out)
     print(" */\n", file=out)
-    print("#include <tap_bpf.h>", file=out)
 
 
 def main():
drivers/net/tap/meson.build +9 -8
index 5099ccdff1..66647a1c62 100644
@@ -7,13 +7,19 @@ if not is_linux
 endif
 sources = files(
         'rte_eth_tap.c',
-        'tap_bpf_api.c',
-        'tap_flow.c',
         'tap_intr.c',
         'tap_netlink.c',
-        'tap_tcmsgs.c',
 )
 
+if cc.has_header_symbol('linux/pkt_cls.h', 'TCA_FLOWER_ACT')
+    cflags += '-DHAVE_TCA_FLOWER'
+    sources += files(
+        'tap_bpf_api.c',
+        'tap_flow.c',
+        'tap_tcmsgs.c',
+    )
+endif
+
 deps = ['bus_vdev', 'gso', 'hash']
 
 cflags += '-DTAP_MAX_QUEUES=16'
@@ -23,12 +29,7 @@ cflags += '-DTAP_MAX_QUEUES=16'
 #   "enum/define", "symbol to search" ]
 #
 args = [
-        [ 'HAVE_TC_FLOWER', 'linux/pkt_cls.h', 'TCA_FLOWER_UNSPEC' ],
-        [ 'HAVE_TC_VLAN_ID', 'linux/pkt_cls.h', 'TCA_FLOWER_KEY_VLAN_PRIO' ],
-        [ 'HAVE_TC_BPF', 'linux/pkt_cls.h', 'TCA_BPF_UNSPEC' ],
-        [ 'HAVE_TC_BPF_FD', 'linux/pkt_cls.h', 'TCA_BPF_FD' ],
         [ 'HAVE_TC_ACT_BPF', 'linux/tc_act/tc_bpf.h', 'TCA_ACT_BPF_UNSPEC' ],
-        [ 'HAVE_TC_ACT_BPF_FD', 'linux/tc_act/tc_bpf.h', 'TCA_ACT_BPF_FD' ],
 ]
 config = configuration_data()
 foreach arg:args
drivers/net/tap/rte_eth_tap.c +32 -6
index b84fc01856..9058a47295 100644
@@ -1133,12 +1133,15 @@ tap_dev_close(struct rte_eth_dev *dev)
 
 	if (!internals->persist)
 		tap_link_set_down(dev);
+
+#ifdef HAVE_TCA_FLOWER
 	if (internals->nlsk_fd != -1) {
 		tap_flow_flush(dev, NULL);
 		tap_flow_implicit_flush(internals, NULL);
 		tap_nl_final(internals->nlsk_fd);
 		internals->nlsk_fd = -1;
 	}
+#endif
 
 	for (i = 0; i < RTE_PMD_TAP_MAX_QUEUES; i++) {
 		struct rx_queue *rxq = &internals->rxq[i];
@@ -1261,6 +1264,7 @@ tap_promisc_enable(struct rte_eth_dev *dev)
 	if (ret != 0)
 		return ret;
 
+#ifdef HAVE_TCA_FLOWER
 	if (pmd->remote_if_index && !pmd->flow_isolate) {
 		dev->data->promiscuous = 1;
 		ret = tap_flow_implicit_create(pmd, TAP_REMOTE_PROMISC);
@@ -1274,7 +1278,7 @@ tap_promisc_enable(struct rte_eth_dev *dev)
 			return ret;
 		}
 	}
-
+#endif
 	return 0;
 }
 
@@ -1289,6 +1293,7 @@ tap_promisc_disable(struct rte_eth_dev *dev)
 	if (ret != 0)
 		return ret;
 
+#ifdef HAVE_TCA_FLOWER
 	if (pmd->remote_if_index && !pmd->flow_isolate) {
 		dev->data->promiscuous = 0;
 		ret = tap_flow_implicit_destroy(pmd, TAP_REMOTE_PROMISC);
@@ -1302,6 +1307,7 @@ tap_promisc_disable(struct rte_eth_dev *dev)
 			return ret;
 		}
 	}
+#endif
 
 	return 0;
 }
@@ -1317,6 +1323,7 @@ tap_allmulti_enable(struct rte_eth_dev *dev)
 	if (ret != 0)
 		return ret;
 
+#ifdef HAVE_TCA_FLOWER
 	if (pmd->remote_if_index && !pmd->flow_isolate) {
 		dev->data->all_multicast = 1;
 		ret = tap_flow_implicit_create(pmd, TAP_REMOTE_ALLMULTI);
@@ -1330,6 +1337,7 @@ tap_allmulti_enable(struct rte_eth_dev *dev)
 			return ret;
 		}
 	}
+#endif
 
 	return 0;
 }
@@ -1345,6 +1353,7 @@ tap_allmulti_disable(struct rte_eth_dev *dev)
 	if (ret != 0)
 		return ret;
 
+#ifdef HAVE_TCA_FLOWER
 	if (pmd->remote_if_index && !pmd->flow_isolate) {
 		dev->data->all_multicast = 0;
 		ret = tap_flow_implicit_destroy(pmd, TAP_REMOTE_ALLMULTI);
@@ -1358,6 +1367,7 @@ tap_allmulti_disable(struct rte_eth_dev *dev)
 			return ret;
 		}
 	}
+#endif
 
 	return 0;
 }
@@ -1403,6 +1413,8 @@ tap_mac_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr)
 	if (ret < 0)
 		return ret;
 	rte_memcpy(&pmd->eth_addr, mac_addr, RTE_ETHER_ADDR_LEN);
+
+#ifdef HAVE_TCA_FLOWER
 	if (pmd->remote_if_index && !pmd->flow_isolate) {
 		/* Replace MAC redirection rule after a MAC change */
 		ret = tap_flow_implicit_destroy(pmd, TAP_REMOTE_LOCAL_MAC);
@@ -1420,6 +1432,7 @@ tap_mac_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr)
 			return ret;
 		}
 	}
+#endif
 
 	return 0;
 }
@@ -1894,7 +1907,9 @@ static const struct eth_dev_ops ops = {
 	.stats_reset            = tap_stats_reset,
 	.dev_supported_ptypes_get = tap_dev_supported_ptypes_get,
 	.rss_hash_update        = tap_rss_hash_update,
+#ifdef HAVE_TCA_FLOWER
 	.flow_ops_get           = tap_dev_flow_ops_get,
+#endif
 };
 
 static int
@@ -1934,7 +1949,9 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 	strlcpy(pmd->name, tap_name, sizeof(pmd->name));
 	pmd->type = type;
 	pmd->ka_fd = -1;
+#ifdef HAVE_TCA_FLOWER
 	pmd->nlsk_fd = -1;
+#endif
 	pmd->gso_ctx_mp = NULL;
 
 	pmd->ioctl_sock = socket(AF_INET, SOCK_DGRAM, 0);
@@ -2014,6 +2031,14 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 	/* Make network device persist after application exit */
 	pmd->persist = persist;
 
+	pmd->if_index = if_nametoindex(pmd->name);
+	if (!pmd->if_index) {
+		TAP_LOG(ERR, "%s: failed to get if_index.", pmd->name);
+		goto disable_rte_flow;
+	}
+
+
+#ifdef HAVE_TCA_FLOWER
 	/*
 	 * Set up everything related to rte_flow:
 	 * - netlink socket
@@ -2028,11 +2053,6 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 			pmd->name);
 		goto disable_rte_flow;
 	}
-	pmd->if_index = if_nametoindex(pmd->name);
-	if (!pmd->if_index) {
-		TAP_LOG(ERR, "%s: failed to get if_index.", pmd->name);
-		goto disable_rte_flow;
-	}
 	if (qdisc_create_multiq(pmd->nlsk_fd, pmd->if_index) < 0) {
 		TAP_LOG(ERR, "%s: failed to create multiq qdisc.",
 			pmd->name);
@@ -2043,6 +2063,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 			pmd->name);
 		goto disable_rte_flow;
 	}
+
 	LIST_INIT(&pmd->flows);
 
 	if (strlen(remote_iface)) {
@@ -2095,6 +2116,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 			goto error_remote;
 		}
 	}
+#endif
 
 	rte_eth_dev_probing_finish(dev);
 	return 0;
@@ -2109,14 +2131,18 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 	rte_eth_dev_probing_finish(dev);
 	return 0;
 
+#ifdef HAVE_TCA_FLOWER
 error_remote:
 	TAP_LOG(ERR, " Can't set up remote feature: %s(%d)",
 		strerror(errno), errno);
 	tap_flow_implicit_flush(pmd, NULL);
+#endif
 
 error_exit:
+#ifdef HAVE_TCA_FLOWER
 	if (pmd->nlsk_fd != -1)
 		close(pmd->nlsk_fd);
+#endif
 	if (pmd->ka_fd != -1)
 		close(pmd->ka_fd);
 	if (pmd->ioctl_sock != -1)
drivers/net/tap/rte_eth_tap.h +6 -1
index 1bcf92ce80..af18b29090 100644
@@ -16,6 +16,7 @@
 #include <ethdev_driver.h>
 #include <rte_ether.h>
 #include <rte_gso.h>
+
 #include "tap_log.h"
 
 #ifdef IFF_MULTI_QUEUE
@@ -70,15 +71,17 @@ struct pmd_internals {
 	char remote_iface[RTE_ETH_NAME_MAX_LEN]; /* Remote netdevice name */
 	char name[RTE_ETH_NAME_MAX_LEN];  /* Internal Tap device name */
 	int type;                         /* Type field - TUN|TAP */
+	int persist;			  /* 1 if keep link up, else 0 */
 	struct rte_ether_addr eth_addr;   /* Mac address of the device port */
 	struct ifreq remote_initial_flags;/* Remote netdevice flags on init */
 	int remote_if_index;              /* remote netdevice IF_INDEX */
 	int if_index;                     /* IF_INDEX for the port */
 	int ioctl_sock;                   /* socket for ioctl calls */
+
+#ifdef HAVE_TCA_FLOWER
 	int nlsk_fd;                      /* Netlink socket fd */
 	int flow_isolate;                 /* 1 if flow isolation is enabled */
 	int rss_enabled;                  /* 1 if RSS is enabled, else 0 */
-	int persist;			  /* 1 if keep link up, else 0 */
 	/* implicit rules set when RSS is enabled */
 	int map_fd;                       /* BPF RSS map fd */
 	int bpf_fd[RTE_PMD_TAP_MAX_QUEUES];/* List of bpf fds per queue */
@@ -86,6 +89,8 @@ struct pmd_internals {
 	LIST_HEAD(tap_flows, rte_flow) flows;        /* rte_flow rules */
 	/* implicit rte_flow rules set when a remote device is active */
 	LIST_HEAD(tap_implicit_flows, rte_flow) implicit_flows;
+#endif
+
 	struct rx_queue rxq[RTE_PMD_TAP_MAX_QUEUES]; /* List of RX queues */
 	struct tx_queue txq[RTE_PMD_TAP_MAX_QUEUES]; /* List of TX queues */
 	struct rte_intr_handle *intr_handle;         /* LSC interrupt handle. */
drivers/net/tap/tap_bpf.h deleted +0 -121

121 lines not on this page · raw message

drivers/net/tap/tap_bpf_api.c +13 -7
index 15283f8917..9e05e2ddf1 100644
@@ -2,19 +2,19 @@
  * Copyright 2017 Mellanox Technologies, Ltd
  */
 
-#include <errno.h>
-#include <string.h>
 #include <unistd.h>
-#include <sys/queue.h>
+#include <syscall.h>
+#include <linux/bpf.h>
 
-#include <rte_malloc.h>
-#include <rte_eth_tap.h>
 #include <tap_flow.h>
 #include <tap_autoconf.h>
-#include <tap_tcmsgs.h>
-#include <tap_bpf.h>
+
 #include <tap_bpf_insns.h>
 
+
+static int bpf_load(enum bpf_prog_type type, const struct bpf_insn *insns,
+		size_t insns_cnt, const char *license);
+
 /**
  * Load BPF program (section cls_q) into the kernel and return a bpf fd
  *
@@ -89,7 +89,13 @@ static inline __u64 ptr_to_u64(const void *ptr)
 static inline int sys_bpf(enum bpf_cmd cmd, union bpf_attr *attr,
 			unsigned int size)
 {
+#ifdef __NR_bpf
 	return syscall(__NR_bpf, cmd, attr, size);
+#else
+	TAP_LOG(ERR, "No bpf syscall, kernel headers too old?\n");
+	errno = ENOSYS;
+	return -1;
+#endif
 }
 
 /**
drivers/net/tap/tap_bpf_insns.h +0 -2
index 53fa76c4e6..cdf2febf05 100644
@@ -3,8 +3,6 @@
  * This not the original source file. Do NOT edit it.
  */
 
-#include <tap_bpf.h>
-
 static struct bpf_insn cls_q_insns[] = {
 	{0x61,    2,    1,       52, 0x00000000},
 	{0x18,    3,    0,        0, 0xdeadbeef},
drivers/net/tap/tap_flow.c +0 -90

96 lines not on this page · raw message

Signature · 1 line
2.43.0
Acked-by on v12 5/12
#133 lore raw

Re: [PATCH v12 05/12] net/tap: do not build flow support if header is out of date

Quoted 5 lines · Stephen Hemminger

The proper place for finding bpf structures and functions is in linux/bpf.h. The original version was trying to workaround the case where the build environment was running on old pre BPF version of Glibc, but the target environment had BPF.

Quoted 8 lines

Having own private (and divergent) version headers leads to future problems when BPF definitions evolve.

If the build infrastructure is so old that TC flower is not supported, then the TAP device will build without any flow support.

Simplification is good, but I hope it doesn't break too many platforms.

#134 lore raw

PATCH v12 6/12 net/tap: rewrite the RSS BPF program

In reply to Stephen Hemminger

Rewrite of the BPF program used to do queue based RSS.

Important changes:
- uses newer BPF map format BTF
- accepts key as parameter rather than constant default
- can do L3 or L4 hashing
- supports IPv4 options
- supports IPv6 extension headers
- restructured for readability

The usage of BPF is different as well:
- the incoming configuration is looked up based on class parameters rather than patching the BPF code.
- the resulting queue is placed in skb by using skb mark than requiring a second pass through classifier step.

Note: This version only works with later patch to enable it on the DPDK driver side. It is submitted as an incremental patch to allow for easier review. Bisection still works because the old instruction are still present for now.

---
 .gitignore                            |   3 -
 drivers/net/tap/bpf/Makefile          |  19 --
 drivers/net/tap/bpf/README            |  49 +++++
 drivers/net/tap/bpf/bpf_api.h         | 276 --------------------------
 drivers/net/tap/bpf/bpf_elf.h         |  53 -----
 drivers/net/tap/bpf/bpf_extract.py    |  85 --------
 drivers/net/tap/bpf/meson.build       |  81 ++++++++
 drivers/net/tap/bpf/tap_bpf_program.c | 255 ------------------------
 drivers/net/tap/bpf/tap_rss.c         | 267 +++++++++++++++++++++++++
 9 files changed, 397 insertions(+), 691 deletions(-)
 delete mode 100644 drivers/net/tap/bpf/Makefile
 create mode 100644 drivers/net/tap/bpf/README
 delete mode 100644 drivers/net/tap/bpf/bpf_api.h
 delete mode 100644 drivers/net/tap/bpf/bpf_elf.h
 delete mode 100644 drivers/net/tap/bpf/bpf_extract.py
 create mode 100644 drivers/net/tap/bpf/meson.build
 delete mode 100644 drivers/net/tap/bpf/tap_bpf_program.c
 create mode 100644 drivers/net/tap/bpf/tap_rss.c
.gitignore +0 -3
index 3f444dcace..01a47a7606 100644
@@ -36,9 +36,6 @@ TAGS
 # ignore python bytecode files
 *.pyc
 
-# ignore BPF programs
-drivers/net/tap/bpf/tap_bpf_program.o
-
 # DTS results
 dts/output
 
drivers/net/tap/bpf/Makefile deleted +0 -19
deleted file mode 100644
index 9efeeb1bc7..0000000000
@@ -1,19 +0,0 @@
-# SPDX-License-Identifier: BSD-3-Clause
-# This file is not built as part of normal DPDK build.
-# It is used to generate the eBPF code for TAP RSS.
-
-CLANG=clang
-CLANG_OPTS=-O2
-TARGET=../tap_bpf_insns.h
-
-all: $(TARGET)
-
-clean:
-	rm tap_bpf_program.o $(TARGET)
-
-tap_bpf_program.o: tap_bpf_program.c
-	$(CLANG) $(CLANG_OPTS) -emit-llvm -c $< -o - | \
-	llc -march=bpf -filetype=obj -o $@
-
-$(TARGET): tap_bpf_program.o
-	python3 bpf_extract.py -stap_bpf_program.c -o $@ $<
drivers/net/tap/bpf/README new file +49 -0

49 lines not on this page · raw message

drivers/net/tap/bpf/bpf_api.h deleted +0 -276

276 lines not on this page · raw message

drivers/net/tap/bpf/bpf_elf.h deleted +0 -53

53 lines not on this page · raw message

drivers/net/tap/bpf/bpf_extract.py deleted +0 -85

85 lines not on this page · raw message

drivers/net/tap/bpf/meson.build new file +81 -0

81 lines not on this page · raw message

drivers/net/tap/bpf/tap_bpf_program.c deleted +0 -255

255 lines not on this page · raw message

drivers/net/tap/bpf/tap_rss.c new file +267 -0

267 lines not on this page · raw message

Signature · 1 line
2.43.0
#135 lore raw

PATCH v12 7/12 net/tap: use libbpf to load new BPF program

In reply to Stephen Hemminger

There were multiple issues in the RSS queue support in the TAP driver. This required extensive rework of the BPF support.

Change the BPF loading to use bpftool to
create a skeleton header file, and load with libbpf. The BPF is always compiled from source so less chance that source and instructions diverge. Also resolves issue where libbpf and source get out of sync. The program
is only loaded once, so if multiple rules are created only one BPF program is loaded in kernel.

The new BPF program only needs a single action.
No need for action and re-classification step.

It also fixes the missing bits from the original.
- supports setting RSS key per flow
- level of hash can be L3 or L3/L4.

Bugzilla ID: 1329

---
 drivers/net/tap/bpf/meson.build |  36 ++-
 drivers/net/tap/meson.build     |  35 ++-
 drivers/net/tap/rte_eth_tap.c   |  14 +-
 drivers/net/tap/rte_eth_tap.h   |   6 +-
 drivers/net/tap/tap_flow.c      | 416 ++++++++------------------------
 drivers/net/tap/tap_flow.h      |  17 +-
 drivers/net/tap/tap_rss.h       |  10 +-
 drivers/net/tap/tap_tcmsgs.h    |   4 +-
 8 files changed, 165 insertions(+), 373 deletions(-)
drivers/net/tap/bpf/meson.build +31 -5
index f2c03a19fd..45e8c3b498 100644
@@ -1,17 +1,26 @@
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright 2024 Stephen Hemminger <[email protected]>
 
-enable_tap_rss = false
-
-libbpf = dependency('libbpf', required: false, method: 'pkg-config')
+# Loading BPF requires libbpf
+# and the bpf_map__XXX API's were introduced in 0.8.0
+libbpf = dependency('libbpf', version: '>= 1.0',
+                    required: false, method: 'pkg-config')
 if not libbpf.found()
     message('net/tap: no RSS support missing libbpf')
     subdir_done()
 endif
 
+# Making skeleton needs bpftool
 # Debian install this in /usr/sbin which is not in $PATH
-bpftool = find_program('bpftool', '/usr/sbin/bpftool', required: false, version: '>= 5.6.0')
-if not bpftool.found()
+bpftool_supports_skel = false
+bpftool = find_program('bpftool', '/usr/sbin/bpftool', required: false)
+if bpftool.found()
+    # Some Ubuntu versions have non-functional bpftool
+    bpftool_supports_skel = run_command(bpftool, 'gen', 'help',
+                                        check:false).returncode() == 0
+endif
+
+if not bpftool_supports_skel
     message('net/tap: no RSS support missing bpftool')
     subdir_done()
 endif
@@ -42,6 +51,7 @@ clang_flags = [
     '-O2',
     '-Wall',
     '-Wextra',
+    max_queues,
     '-target',
     'bpf',
     '-g',
@@ -67,6 +77,22 @@ skel_h_cmd = [
     '@INPUT@'
 ]
 
+vmlinux_h_cmd = [
+    bpftool,
+    'btf',
+    'dump',
+    'file',
+    '/sys/kernel/btf/vmlinux',
+    'format',
+    'c'
+]
+
+vmlinux_h = custom_target(
+    'vmlinux.h',
+    output: 'vmlinux.h',
+    command: vmlinux_h_cmd,
+    capture: true)
+
 tap_rss_o = custom_target(
     'tap_rss.bpf.o',
     input: 'tap_rss.c',
drivers/net/tap/meson.build +16 -19
index 66647a1c62..26074059fa 100644
@@ -5,36 +5,33 @@ if not is_linux
     build = false
     reason = 'only supported on Linux'
 endif
+
 sources = files(
         'rte_eth_tap.c',
         'tap_intr.c',
         'tap_netlink.c',
 )
 
+deps = ['bus_vdev', 'gso', 'hash']
+
+max_queues = '-DTAP_MAX_QUEUES=16'
+cflags += max_queues
+
+require_iova_in_mbuf = false
+
 if cc.has_header_symbol('linux/pkt_cls.h', 'TCA_FLOWER_ACT')
     cflags += '-DHAVE_TCA_FLOWER'
     sources += files(
-        'tap_bpf_api.c',
         'tap_flow.c',
         'tap_tcmsgs.c',
     )
-endif
-
-deps = ['bus_vdev', 'gso', 'hash']
 
-cflags += '-DTAP_MAX_QUEUES=16'
-
-# input array for meson symbol search:
-# [ "MACRO to define if found", "header for the search",
-#   "enum/define", "symbol to search" ]
-#
-args = [
-        [ 'HAVE_TC_ACT_BPF', 'linux/tc_act/tc_bpf.h', 'TCA_ACT_BPF_UNSPEC' ],
-]
-config = configuration_data()
-foreach arg:args
-    config.set(arg[0], cc.has_header_symbol(arg[1], arg[2]))
-endforeach
-configure_file(output : 'tap_autoconf.h', configuration : config)
+    enable_tap_rss = false
 
-require_iova_in_mbuf = false
+    subdir('bpf')
+    if enable_tap_rss
+        cflags += '-DHAVE_BPF_RSS'
+        ext_deps += libbpf
+        sources += tap_rss_skel_h
+    endif
+endif
drivers/net/tap/rte_eth_tap.c +7 -7
index 9058a47295..d847565073 100644
@@ -1140,6 +1140,7 @@ tap_dev_close(struct rte_eth_dev *dev)
 		tap_flow_implicit_flush(internals, NULL);
 		tap_nl_final(internals->nlsk_fd);
 		internals->nlsk_fd = -1;
+		tap_flow_bpf_destroy(internals);
 	}
 #endif
 
@@ -1949,6 +1950,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 	strlcpy(pmd->name, tap_name, sizeof(pmd->name));
 	pmd->type = type;
 	pmd->ka_fd = -1;
+
 #ifdef HAVE_TCA_FLOWER
 	pmd->nlsk_fd = -1;
 #endif
@@ -2031,13 +2033,6 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 	/* Make network device persist after application exit */
 	pmd->persist = persist;
 
-	pmd->if_index = if_nametoindex(pmd->name);
-	if (!pmd->if_index) {
-		TAP_LOG(ERR, "%s: failed to get if_index.", pmd->name);
-		goto disable_rte_flow;
-	}
-
-
 #ifdef HAVE_TCA_FLOWER
 	/*
 	 * Set up everything related to rte_flow:
@@ -2053,6 +2048,11 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 			pmd->name);
 		goto disable_rte_flow;
 	}
+	pmd->if_index = if_nametoindex(pmd->name);
+	if (!pmd->if_index) {
+		TAP_LOG(ERR, "%s: failed to get if_index.", pmd->name);
+		goto disable_rte_flow;
+	}
 	if (qdisc_create_multiq(pmd->nlsk_fd, pmd->if_index) < 0) {
 		TAP_LOG(ERR, "%s: failed to create multiq qdisc.",
 			pmd->name);
drivers/net/tap/rte_eth_tap.h +2 -4
index af18b29090..ce4322ad04 100644
@@ -81,10 +81,8 @@ struct pmd_internals {
 #ifdef HAVE_TCA_FLOWER
 	int nlsk_fd;                      /* Netlink socket fd */
 	int flow_isolate;                 /* 1 if flow isolation is enabled */
-	int rss_enabled;                  /* 1 if RSS is enabled, else 0 */
-	/* implicit rules set when RSS is enabled */
-	int map_fd;                       /* BPF RSS map fd */
-	int bpf_fd[RTE_PMD_TAP_MAX_QUEUES];/* List of bpf fds per queue */
+
+	struct tap_rss *rss;		  /* BPF program */
 
 	LIST_HEAD(tap_flows, rte_flow) flows;        /* rte_flow rules */
 	/* implicit rte_flow rules set when a remote device is active */
drivers/net/tap/tap_flow.c +97 -319

555 lines not on this page · raw message

drivers/net/tap/tap_flow.h +6 -11
index 240fbc3dfa..8b19347a93 100644
@@ -9,7 +9,11 @@
 #include <rte_flow.h>
 #include <rte_flow_driver.h>
 #include <rte_eth_tap.h>
-#include <tap_autoconf.h>
+
+/**
+ * Mask of unsupported RSS types
+ */
+#define TAP_RSS_HF_MASK (~(RTE_ETH_RSS_IP | RTE_ETH_RSS_UDP | RTE_ETH_RSS_TCP))
 
 /**
  * In TC, priority 0 means we require the kernel to allocate one for us.
@@ -41,11 +45,6 @@ enum implicit_rule_index {
 	TAP_REMOTE_MAX_IDX,
 };
 
-enum bpf_fd_idx {
-	SEC_L3_L4,
-	SEC_MAX,
-};
-
 int tap_dev_flow_ops_get(struct rte_eth_dev *dev,
 			 const struct rte_flow_ops **ops);
 int tap_flow_flush(struct rte_eth_dev *dev, struct rte_flow_error *error);
@@ -57,10 +56,6 @@ int tap_flow_implicit_destroy(struct pmd_internals *pmd,
 int tap_flow_implicit_flush(struct pmd_internals *pmd,
 			    struct rte_flow_error *error);
 
-int tap_flow_bpf_cls_q(__u32 queue_idx);
-int tap_flow_bpf_calc_l3_l4_hash(__u32 key_idx, int map_fd);
-int tap_flow_bpf_rss_map_create(unsigned int key_size, unsigned int value_size,
-			unsigned int max_entries);
-int tap_flow_bpf_update_rss_elem(int fd, void *key, void *value);
+void tap_flow_bpf_destroy(struct pmd_internals *pmd);
 
 #endif /* _TAP_FLOW_H_ */
drivers/net/tap/tap_rss.h +4 -6
index 6009be7031..65bd8991b1 100644
@@ -5,16 +5,14 @@
 #ifndef _TAP_RSS_H_
 #define _TAP_RSS_H_
 
-#ifndef TAP_MAX_QUEUES
-#define TAP_MAX_QUEUES 16
+/* Size of the map from BPF classid to queue table */
+#ifndef TAP_RSS_MAX
+#define TAP_RSS_MAX	32
 #endif
 
-/* Fixed RSS hash key size in bytes. */
+/* Standard Toeplitz hash key size */
 #define TAP_RSS_HASH_KEY_SIZE 40
 
-/* Supported RSS */
-#define TAP_RSS_HF_MASK (~(RTE_ETH_RSS_IP | RTE_ETH_RSS_UDP | RTE_ETH_RSS_TCP))
-
 /* hashed fields for RSS */
 enum hash_field {
 	HASH_FIELD_IPV4_L3,	/* IPv4 src/dst addr */
drivers/net/tap/tap_tcmsgs.h +2 -2
index a64cb29d6f..9411626661 100644
@@ -6,7 +6,6 @@
 #ifndef _TAP_TCMSGS_H_
 #define _TAP_TCMSGS_H_
 
-#include <tap_autoconf.h>
 #include <linux/if_ether.h>
 #include <linux/rtnetlink.h>
 #include <linux/pkt_sched.h>
@@ -14,9 +13,10 @@
 #include <linux/tc_act/tc_mirred.h>
 #include <linux/tc_act/tc_gact.h>
 #include <linux/tc_act/tc_skbedit.h>
-#ifdef HAVE_TC_ACT_BPF
+#ifdef HAVE_BPF_RSS
 #include <linux/tc_act/tc_bpf.h>
 #endif
+
 #include <inttypes.h>
 
 #include <rte_ether.h>
Signature · 1 line
2.43.0
#136 lore raw

Re: [PATCH v12 07/12] net/tap: use libbpf to load new BPF program

Quoted 14 lines · Stephen Hemminger

There were multiple issues in the RSS queue support in the TAP driver. This required extensive rework of the BPF support.

Change the BPF loading to use bpftool to
create a skeleton header file, and load with libbpf. The BPF is always compiled from source so less chance that source and instructions diverge. Also resolves issue where libbpf and source get out of sync. The program
is only loaded once, so if multiple rules are created only one BPF program is loaded in kernel.

The new BPF program only needs a single action.
No need for action and re-classification step.

Quoted 8 lines

It also fixes the missing bits from the original.
- supports setting RSS key per flow
- level of hash can be L3 or L3/L4.

Bugzilla ID: 1329

The libbpf version in my Ubuntu box, installed with package manager, is 'libbpf.so.0.5.0', so it doesn't satisfy the requirement and bpf support is not compiled for me.

@Christian, 'libbpf.so.0.5.0'seems old, it is from 2021, do you know is there a reason Ubuntu stick to this version? And can we expect an update soon?

@Patric, I assume test environment also doesn't have 'libbpf', version:
'>= 1.0' which we need to test this feature.
Is it possible to update test environment to justify this dependency?

I think we need to verify at least build (with and without dependency met) for the set.

#137 lore raw

Re: [PATCH v12 07/12] net/tap: use libbpf to load new BPF program

Quoted 35 lines · On Mon, 20 May 2024 18:49:19 +0100 Ferruh Yigit <[email protected]> wrote:
Quoted 14 lines · Stephen Hemminger

There were multiple issues in the RSS queue support in the TAP driver. This required extensive rework of the BPF support.

Change the BPF loading to use bpftool to
create a skeleton header file, and load with libbpf. The BPF is always compiled from source so less chance that source and instructions diverge. Also resolves issue where libbpf and source get out of sync. The program
is only loaded once, so if multiple rules are created only one BPF program is loaded in kernel.

The new BPF program only needs a single action.
No need for action and re-classification step.

Quoted 8 lines

It also fixes the missing bits from the original.
- supports setting RSS key per flow
- level of hash can be L3 or L3/L4.

Bugzilla ID: 1329

The libbpf version in my Ubuntu box, installed with package manager, is 'libbpf.so.0.5.0', so it doesn't satisfy the requirement and bpf support is not compiled for me.

@Christian, 'libbpf.so.0.5.0'seems old, it is from 2021, do you know is there a reason Ubuntu stick to this version? And can we expect an update soon?

Quoted 6 lines

@Patric, I assume test environment also doesn't have 'libbpf', version:
'>= 1.0' which we need to test this feature.
Is it possible to update test environment to justify this dependency?

I think we need to verify at least build (with and without dependency met) for the set.

The BPF API changed a lot, and it is not really possible to support both.

#138 lore raw

Re: [PATCH v12 07/12] net/tap: use libbpf to load new BPF program

Quoted 43 lines · Stephen Hemminger
Quoted 39 lines · On Mon, 20 May 2024 18:49:19 +0100 Ferruh Yigit <[email protected]> wrote:
Quoted 14 lines · Stephen Hemminger

There were multiple issues in the RSS queue support in the TAP driver. This required extensive rework of the BPF support.

Change the BPF loading to use bpftool to
create a skeleton header file, and load with libbpf. The BPF is always compiled from source so less chance that source and instructions diverge. Also resolves issue where libbpf and source get out of sync. The program
is only loaded once, so if multiple rules are created only one BPF program is loaded in kernel.

The new BPF program only needs a single action.
No need for action and re-classification step.

Quoted 8 lines

It also fixes the missing bits from the original.
- supports setting RSS key per flow
- level of hash can be L3 or L3/L4.

Bugzilla ID: 1329

The libbpf version in my Ubuntu box, installed with package manager, is 'libbpf.so.0.5.0', so it doesn't satisfy the requirement and bpf support is not compiled for me.

@Christian, 'libbpf.so.0.5.0'seems old, it is from 2021, do you know is there a reason Ubuntu stick to this version? And can we expect an update soon?

@Patric, I assume test environment also doesn't have 'libbpf', version:
'>= 1.0' which we need to test this feature.
Is it possible to update test environment to justify this dependency?

Quoted 5 lines
Quoted 2 lines

I think we need to verify at least build (with and without dependency met) for the set.

The BPF API changed a lot, and it is not really possible to support both.

It can be done, but it is a _lot_ of work and requires a lot of shims, so for something optional it's not really worth it. Given libbpf 1.0 also broke ABI, Ubuntu 22.04 and older cannot really get a new version as it's incompatible, so this pmd will simply be skipped there. I think it's fine. 24.04 has a new one.

#139 lore raw

Re: [PATCH v12 07/12] net/tap: use libbpf to load new BPF program

Quoted 48 lines · Luca Boccassi
Quoted 46 lines · Stephen Hemminger
Quoted 41 lines · On Mon, 20 May 2024 18:49:19 +0100 Ferruh Yigit <[email protected]> wrote:
Quoted 14 lines · Stephen Hemminger

There were multiple issues in the RSS queue support in the TAP driver. This required extensive rework of the BPF support.

Change the BPF loading to use bpftool to
create a skeleton header file, and load with libbpf. The BPF is always compiled from source so less chance that source and instructions diverge. Also resolves issue where libbpf and source get out of sync. The program
is only loaded once, so if multiple rules are created only one BPF program is loaded in kernel.

The new BPF program only needs a single action.
No need for action and re-classification step.

Quoted 8 lines

It also fixes the missing bits from the original.
- supports setting RSS key per flow
- level of hash can be L3 or L3/L4.

Bugzilla ID: 1329

The libbpf version in my Ubuntu box, installed with package manager, is 'libbpf.so.0.5.0', so it doesn't satisfy the requirement and bpf support is not compiled for me.

@Christian, 'libbpf.so.0.5.0'seems old, it is from 2021, do you know is there a reason Ubuntu stick to this version? And can we expect an update soon?

@Patric, I assume test environment also doesn't have 'libbpf', version:
'>= 1.0' which we need to test this feature.
Is it possible to update test environment to justify this dependency?

I think we need to verify at least build (with and without dependency met) for the set.

Quoted 9 lines
Quoted 2 lines

The BPF API changed a lot, and it is not really possible to support both.

It can be done, but it is a _lot_ of work and requires a lot of shims, so for something optional it's not really worth it. Given libbpf 1.0 also broke ABI, Ubuntu 22.04 and older cannot really get a new version as it's incompatible, so this pmd will simply be skipped there. I think it's fine. 24.04 has a new one.

Does Ubuntu 24.04 have libbpf >= 1.0 ?

#140 lore raw

Re: [PATCH v12 07/12] net/tap: use libbpf to load new BPF program

Quoted 53 lines · Ferruh Yigit
Quoted 51 lines · Luca Boccassi
Quoted 48 lines · Stephen Hemminger
Quoted 35 lines · On Mon, 20 May 2024 18:49:19 +0100 Ferruh Yigit <[email protected]> wrote:
Quoted 14 lines · Stephen Hemminger

There were multiple issues in the RSS queue support in the TAP driver. This required extensive rework of the BPF support.

Change the BPF loading to use bpftool to
create a skeleton header file, and load with libbpf. The BPF is always compiled from source so less chance that source and instructions diverge. Also resolves issue where libbpf and source get out of sync. The program
is only loaded once, so if multiple rules are created only one BPF program is loaded in kernel.

The new BPF program only needs a single action.
No need for action and re-classification step.

Quoted 8 lines

It also fixes the missing bits from the original.
- supports setting RSS key per flow
- level of hash can be L3 or L3/L4.

Bugzilla ID: 1329

The libbpf version in my Ubuntu box, installed with package manager, is 'libbpf.so.0.5.0', so it doesn't satisfy the requirement and bpf support is not compiled for me.

@Christian, 'libbpf.so.0.5.0'seems old, it is from 2021, do you know is there a reason Ubuntu stick to this version? And can we expect an update soon?

Quoted 6 lines

@Patric, I assume test environment also doesn't have 'libbpf', version:
'>= 1.0' which we need to test this feature.
Is it possible to update test environment to justify this dependency?

I think we need to verify at least build (with and without dependency met) for the set.

The BPF API changed a lot, and it is not really possible to support both.

Quoted 8 lines
Quoted 6 lines

It can be done, but it is a _lot_ of work and requires a lot of shims, so for something optional it's not really worth it. Given libbpf 1.0 also broke ABI, Ubuntu 22.04 and older cannot really get a new version as it's incompatible, so this pmd will simply be skipped there. I think it's fine. 24.04 has a new one.

Does Ubuntu 24.04 have libbpf >= 1.0 ?

Yes:

https://packages.ubuntu.com/search?keywords=libbpf-dev&searchon=names&suite=all&section=all

#141 lore raw

Re: [PATCH v12 07/12] net/tap: use libbpf to load new BPF program

In reply to Ferruh Yigit
Quoted 9 lines · On Mon, 20 May 2024 23:08:04 +0100 Ferruh Yigit <[email protected]> wrote:
Quoted 7 lines

It can be done, but it is a _lot_ of work and requires a lot of shims, so for something optional it's not really worth it. Given libbpf 1.0 also broke ABI, Ubuntu 22.04 and older cannot really get a new version as it's incompatible, so this pmd will simply be skipped there. I think it's fine. 24.04 has a new one.

Does Ubuntu 24.04 have libbpf >= 1.0 ?

Yes it does.

Tried this on a 24.04 VM, needed to install pkg-config and clang. But then it builds.

It does have some other fortify warnings (in rte_pcapng.c) but these are unrelated and exist on main branch as well.

#142 lore raw

Re: [PATCH v12 07/12] net/tap: use libbpf to load new BPF program

In reply to Stephen Hemminger
Quoted 42 lines · Stephen Hemminger
Quoted 39 lines · On Mon, 20 May 2024 18:49:19 +0100 Ferruh Yigit <[email protected]> wrote:
Quoted 14 lines · Stephen Hemminger

There were multiple issues in the RSS queue support in the TAP driver. This required extensive rework of the BPF support.

Change the BPF loading to use bpftool to
create a skeleton header file, and load with libbpf. The BPF is always compiled from source so less chance that source and instructions diverge. Also resolves issue where libbpf and source get out of sync. The program
is only loaded once, so if multiple rules are created only one BPF program is loaded in kernel.

The new BPF program only needs a single action.
No need for action and re-classification step.

Quoted 8 lines

It also fixes the missing bits from the original.
- supports setting RSS key per flow
- level of hash can be L3 or L3/L4.

Bugzilla ID: 1329

The libbpf version in my Ubuntu box, installed with package manager, is 'libbpf.so.0.5.0', so it doesn't satisfy the requirement and bpf support is not compiled for me.

@Christian, 'libbpf.so.0.5.0'seems old, it is from 2021, do you know is there a reason Ubuntu stick to this version? And can we expect an update soon?

@Patric, I assume test environment also doesn't have 'libbpf', version:
'>= 1.0' which we need to test this feature.
Is it possible to update test environment to justify this dependency?

Quoted 6 lines
Quoted 2 lines

I think we need to verify at least build (with and without dependency met) for the set.

The BPF API changed a lot, and it is not really possible to support both.

I didn't mean to support both library versions.

My point was to test both "libbpf >= 1.0" requirement satisfied case and unsatisfied (tap ebpf disabled) case.

#143 lore raw

Re: [PATCH v12 07/12] net/tap: use libbpf to load new BPF program

In reply to Ferruh Yigit
Quoted 5 lines · Ferruh Yigit

@Patric, I assume test environment also doesn't have 'libbpf', version:
'>= 1.0' which we need to test this feature.
Is it possible to update test environment to justify this dependency?

Hi, the libbpf version on our Ubuntu 22.04 container images is 0.5.0. I can check for our baremetal servers also, but I figure they will be the same.

It sounds like the subsequent conversation is suggesting this upgrade is not viable anyhow, but to address the question in terms of Community Lab methodology, yes we are happy to modify our environments or images in any way if the community wants, but we try to run testing without upgrading the core packages the distro ships with. I.e. we would not run testing with CentOS 7 today, as it ships with gcc 4.8.5 (not supported for DPDK), even though technically we could upgrade gcc to a new version and meet all the DPDK dependencies.

But yes I see Stephen ran from a 24.04 VM and validated the build with the new libbpf.

By the way, I was wondering recently whether it was appropriate to add an Ubuntu 24.04 environment to the Community Lab immediately, or if it's premature in some sense. I don't want to derail this thread with that question, but if anyone is interested in this coverage going online, please write to the CI mailing list saying so.

#144 lore raw

Re: [PATCH v12 07/12] net/tap: use libbpf to load new BPF program

Quoted 20 lines · Patrick Robb
Quoted 5 lines · Ferruh Yigit

@Patric, I assume test environment also doesn't have 'libbpf', version:
'>= 1.0' which we need to test this feature.
Is it possible to update test environment to justify this dependency?

Hi, the libbpf version on our Ubuntu 22.04 container images is 0.5.0. I can check for our baremetal servers also, but I figure they will be the same.

It sounds like the subsequent conversation is suggesting this upgrade is not viable anyhow, but to address the question in terms of Community Lab methodology, yes we are happy to modify our environments or images in any way if the community wants, but we try to run testing without upgrading the core packages the distro ships with. I.e. we would not run testing with CentOS 7 today, as it ships with gcc 4.8.5 (not supported for DPDK), even though technically we could upgrade gcc to a new version and meet all the DPDK dependencies.

Quoted 9 lines

But yes I see Stephen ran from a 24.04 VM and validated the build with the new libbpf.

By the way, I was wondering recently whether it was appropriate to add an Ubuntu 24.04 environment to the Community Lab immediately, or if it's premature in some sense. I don't want to derail this thread with that question, but if anyone is interested in this coverage going online, please write to the CI mailing list saying so.

If we can have an Ubuntu 24.04 environment, this addresses the libbpf testing concern.

@Christian can comment better, but as far as I can see although upgrade from previous LTS is not supported yet, it is possible to install Ubuntu 24.04 from scratch.

#145 lore raw

Re: [PATCH v12 07/12] net/tap: use libbpf to load new BPF program

Quoted 9 lines · Ferruh Yigit

If we can have an Ubuntu 24.04 environment, this addresses the libbpf testing concern.

@Christian can comment better, but as far as I can see although upgrade from previous LTS is not supported yet, it is possible to install Ubuntu 24.04 from scratch.

Okay Ferruh I see on DockerHub that a 24.04 image is published. We will write the DPDK CI container template engine Dockerfile for this and start testing with it, unlesss any concerns are raised here by Christian or others.

#146 lore raw

Re: [PATCH v12 07/12] net/tap: use libbpf to load new BPF program

In reply to Ferruh Yigit
Quoted 31 lines · Ferruh Yigit
Quoted 20 lines · Patrick Robb
Quoted 5 lines · Ferruh Yigit

@Patric, I assume test environment also doesn't have 'libbpf', version:
'>= 1.0' which we need to test this feature.
Is it possible to update test environment to justify this dependency?

Hi, the libbpf version on our Ubuntu 22.04 container images is 0.5.0. I can check for our baremetal servers also, but I figure they will be the same.

It sounds like the subsequent conversation is suggesting this upgrade is not viable anyhow, but to address the question in terms of Community Lab methodology, yes we are happy to modify our environments or images in any way if the community wants, but we try to run testing without upgrading the core packages the distro ships with. I.e. we would not run testing with CentOS 7 today, as it ships with gcc 4.8.5 (not supported for DPDK), even though technically we could upgrade gcc to a new version and meet all the DPDK dependencies.

Quoted 9 lines

But yes I see Stephen ran from a 24.04 VM and validated the build with the new libbpf.

By the way, I was wondering recently whether it was appropriate to add an Ubuntu 24.04 environment to the Community Lab immediately, or if it's premature in some sense. I don't want to derail this thread with that question, but if anyone is interested in this coverage going online, please write to the CI mailing list saying so.

Quoted 2 lines

If we can have an Ubuntu 24.04 environment, this addresses the libbpf testing concern.

I think it would be good to add as well. 24.04 will be an LTS, so it should be support for long time.

Quoted 3 lines

@Christian can comment better, but as far as I can see although upgrade from previous LTS is not supported yet, it is possible to install Ubuntu 24.04 from scratch.

There is a sortof procedure to do it by going via 23.10 first, but it isn't probably the best approach. I guess installing from scratch may be the best approach.

#147 lore raw

Re: [PATCH v12 07/12] net/tap: use libbpf to load new BPF program

Quoted 7 lines · On Tue, 21 May 2024 11:06:59 -0400 Aaron Conole <[email protected]> wrote:
Quoted 3 lines

If we can have an Ubuntu 24.04 environment, this addresses the libbpf testing concern.

I think it would be good to add as well. 24.04 will be an LTS, so it should be support for long time.

Quoted 7 lines
Quoted 3 lines

@Christian can comment better, but as far as I can see although upgrade from previous LTS is not supported yet, it is possible to install Ubuntu 24.04 from scratch.

There is a sortof procedure to do it by going via 23.10 first, but it isn't probably the best approach. I guess installing from scratch may be the best approach.

Thanks, we need to have 24.04 test setup since when I tried it there were new warnings from fortify.

#148 lore raw

PATCH v12 8/12 net/tap: remove no longer used files

In reply to Stephen Hemminger

The BPF api was replaced by use of libbpf.
And the BPF instruction header was replaced by the skeleton.

---
 drivers/net/tap/tap_bpf_api.c   |  196 ----
 drivers/net/tap/tap_bpf_insns.h | 1741 -------------------------------
 2 files changed, 1937 deletions(-)
 delete mode 100644 drivers/net/tap/tap_bpf_api.c
 delete mode 100644 drivers/net/tap/tap_bpf_insns.h
drivers/net/tap/tap_bpf_api.c deleted +0 -196
deleted file mode 100644
index 9e05e2ddf1..0000000000
@@ -1,196 +0,0 @@
-/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright 2017 Mellanox Technologies, Ltd
- */
-
-#include <unistd.h>
-#include <syscall.h>
-#include <linux/bpf.h>
-
-#include <tap_flow.h>
-#include <tap_autoconf.h>
-
-#include <tap_bpf_insns.h>
-
-
-static int bpf_load(enum bpf_prog_type type, const struct bpf_insn *insns,
-		size_t insns_cnt, const char *license);
-
-/**
- * Load BPF program (section cls_q) into the kernel and return a bpf fd
- *
- * @param queue_idx
- *   Queue index matching packet cb
- *
- * @return
- *   -1 if the BPF program couldn't be loaded. An fd (int) otherwise.
- */
-int tap_flow_bpf_cls_q(__u32 queue_idx)
-{
-	cls_q_insns[1].imm = queue_idx;
-
-	return bpf_load(BPF_PROG_TYPE_SCHED_CLS,
-		(struct bpf_insn *)cls_q_insns,
-		RTE_DIM(cls_q_insns),
-		"Dual BSD/GPL");
-}
-
-/**
- * Load BPF program (section l3_l4) into the kernel and return a bpf fd.
- *
- * @param[in] key_idx
- *   RSS MAP key index
- *
- * @param[in] map_fd
- *   BPF RSS map file descriptor
- *
- * @return
- *   -1 if the BPF program couldn't be loaded. An fd (int) otherwise.
- */
-int tap_flow_bpf_calc_l3_l4_hash(__u32 key_idx, int map_fd)
-{
-	l3_l4_hash_insns[4].imm = key_idx;
-	l3_l4_hash_insns[9].imm = map_fd;
-
-	return bpf_load(BPF_PROG_TYPE_SCHED_ACT,
-		(struct bpf_insn *)l3_l4_hash_insns,
-		RTE_DIM(l3_l4_hash_insns),
-		"Dual BSD/GPL");
-}
-
-/**
- * Helper function to convert a pointer to unsigned 64 bits
- *
- * @param[in] ptr
- *   pointer to address
- *
- * @return
- *   64 bit unsigned long type of pointer address
- */
-static inline __u64 ptr_to_u64(const void *ptr)
-{
-	return (__u64)(unsigned long)ptr;
-}
-
-/**
- * Call BPF system call
- *
- * @param[in] cmd
- *   BPF command for program loading, map creation, map entry update, etc
- *
- * @param[in] attr
- *   System call attributes relevant to system call command
- *
- * @param[in] size
- *   size of attr parameter
- *
- * @return
- *   -1 if BPF system call failed, 0 otherwise
- */
-static inline int sys_bpf(enum bpf_cmd cmd, union bpf_attr *attr,
-			unsigned int size)
-{
-#ifdef __NR_bpf
-	return syscall(__NR_bpf, cmd, attr, size);
-#else
-	TAP_LOG(ERR, "No bpf syscall, kernel headers too old?\n");
-	errno = ENOSYS;
-	return -1;
-#endif
-}
-
-/**
- * Load BPF instructions to kernel
- *
- * @param[in] type
- *   BPF program type: classifier or action
- *
- * @param[in] insns
- *   Array of BPF instructions (equivalent to BPF instructions)
- *
- * @param[in] insns_cnt
- *   Number of BPF instructions (size of array)
- *
- * @param[in] license
- *   License string that must be acknowledged by the kernel
- *
- * @return
- *   -1 if the BPF program couldn't be loaded, fd (file descriptor) otherwise
- */
-static int bpf_load(enum bpf_prog_type type,
-		  const struct bpf_insn *insns,
-		  size_t insns_cnt,
-		  const char *license)
-{
-	union bpf_attr attr = {};
-
-	bzero(&attr, sizeof(attr));
-	attr.prog_type = type;
-	attr.insn_cnt = (__u32)insns_cnt;
-	attr.insns = ptr_to_u64(insns);
-	attr.license = ptr_to_u64(license);
-	attr.log_buf = ptr_to_u64(NULL);
-	attr.log_level = 0;
-	attr.kern_version = 0;
-
-	return sys_bpf(BPF_PROG_LOAD, &attr, sizeof(attr));
-}
-
-/**
- * Create BPF map for RSS rules
- *
- * @param[in] key_size
- *   map RSS key size
- *
- * @param[in] value_size
- *   Map RSS value size
- *
- * @param[in] max_entries
- *   Map max number of RSS entries (limit on max RSS rules)
- *
- * @return
- *   -1 if BPF map couldn't be created, map fd otherwise
- */
-int tap_flow_bpf_rss_map_create(unsigned int key_size,
-		unsigned int value_size,
-		unsigned int max_entries)
-{
-	union bpf_attr attr = {};
-
-	bzero(&attr, sizeof(attr));
-	attr.map_type    = BPF_MAP_TYPE_HASH;
-	attr.key_size    = key_size;
-	attr.value_size  = value_size;
-	attr.max_entries = max_entries;
-
-	return sys_bpf(BPF_MAP_CREATE, &attr, sizeof(attr));
-}
-
-/**
- * Update RSS entry in BPF map
- *
- * @param[in] fd
- *   RSS map fd
- *
- * @param[in] key
- *   Pointer to RSS key whose entry is updated
- *
- * @param[in] value
- *   Pointer to RSS new updated value
- *
- * @return
- *   -1 if RSS entry failed to be updated, 0 otherwise
- */
-int tap_flow_bpf_update_rss_elem(int fd, void *key, void *value)
-{
-	union bpf_attr attr = {};
-
-	bzero(&attr, sizeof(attr));
-
-	attr.map_type = BPF_MAP_TYPE_HASH;
-	attr.map_fd = fd;
-	attr.key = ptr_to_u64(key);
-	attr.value = ptr_to_u64(value);
-	attr.flags = BPF_ANY;
-
-	return sys_bpf(BPF_MAP_UPDATE_ELEM, &attr, sizeof(attr));
-}
drivers/net/tap/tap_bpf_insns.h deleted +0 -1741

1,741 lines not on this page · raw message

Signature · 1 line
2.43.0
#149 lore raw

Re: [PATCH v12 08/12] net/tap: remove no longer used files

Quoted 3 lines · Stephen Hemminger

The BPF api was replaced by use of libbpf.
And the BPF instruction header was replaced by the skeleton.

Mentioned 'skeleton' here is auto generated skeleton header file 'tap_rss.skel.h', right? Should we elaborate this?

Quoted 5 lines
---
 drivers/net/tap/tap_bpf_api.c   |  196 ----
 drivers/net/tap/tap_bpf_insns.h | 1741 -------------------------------

Good to get rid of this binary like header file, thanks.

#150 lore raw

PATCH v12 9/12 net/tap: simplify internals

In reply to Stephen Hemminger

The names of Linux network devices are IFNAMSIZ(16) not the same as DPDK which has up to 64 characters. Don't need to hold onto the whole ifreq to save the remote interface flags.

Make sure packet and byte counters are read once, so that global and per-queue values add up. No need for separate rx_nombuf counter since there is an alloc_failed value in ethdev.

Keep only the statistics that are used. I.e no ipackets on tx queues etc.

---
 drivers/net/tap/rte_eth_tap.c | 138 ++++++++++++++++++----------------
 drivers/net/tap/rte_eth_tap.h |  22 +++---
 2 files changed, 83 insertions(+), 77 deletions(-)
drivers/net/tap/rte_eth_tap.c +74 -64
index d847565073..3614aaf1dc 100644
@@ -46,6 +46,11 @@
 #include <tap_netlink.h>
 #include <tap_tcmsgs.h>
 
+/* Used to snapshot statistics */
+#ifndef READ_ONCE
+#define READ_ONCE(var) (*((volatile typeof(var) *)(&(var))))
+#endif
+
 /* Linux based path to the TUN device */
 #define TUN_TAP_DEV_PATH        "/dev/net/tun"
 #define DEFAULT_TAP_NAME        "dtap"
@@ -212,7 +217,7 @@ tun_alloc(struct pmd_internals *pmd, int is_keepalive, int persistent)
 	 * and need to find the resulting device.
 	 */
 	TAP_LOG(DEBUG, "Device name is '%s'", ifr.ifr_name);
-	strlcpy(pmd->name, ifr.ifr_name, RTE_ETH_NAME_MAX_LEN);
+	strlcpy(pmd->name, ifr.ifr_name, IFNAMSIZ);
 
 	if (is_keepalive) {
 		/*
@@ -454,7 +459,7 @@ pmd_rx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 
 		/* Packet couldn't fit in the provided mbuf */
 		if (unlikely(rxq->pi.flags & TUN_PKT_STRIP)) {
-			rxq->stats.ierrors++;
+			rxq->stats.errors++;
 			continue;
 		}
 
@@ -466,7 +471,8 @@ pmd_rx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 			struct rte_mbuf *buf = rte_pktmbuf_alloc(rxq->mp);
 
 			if (unlikely(!buf)) {
-				rxq->stats.rx_nombuf++;
+				rte_eth_devices[rxq->in_port].data->rx_mbuf_alloc_failed++;
+
 				/* No new buf has been allocated: do nothing */
 				if (!new_tail || !seg)
 					goto end;
@@ -511,8 +517,8 @@ pmd_rx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 		num_rx_bytes += mbuf->pkt_len;
 	}
 end:
-	rxq->stats.ipackets += num_rx;
-	rxq->stats.ibytes += num_rx_bytes;
+	rxq->stats.packets += num_rx;
+	rxq->stats.bytes += num_rx_bytes;
 
 	if (trigger && num_rx < nb_pkts)
 		rxq->trigger_seen = trigger;
@@ -692,7 +698,7 @@ pmd_tx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 			tso_segsz = mbuf_in->tso_segsz + hdrs_len;
 			if (unlikely(tso_segsz == hdrs_len) ||
 				tso_segsz > *txq->mtu) {
-				txq->stats.errs++;
+				txq->stats.errors++;
 				break;
 			}
 			gso_ctx->gso_size = tso_segsz;
@@ -730,7 +736,7 @@ pmd_tx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 		ret = tap_write_mbufs(txq, num_mbufs, mbuf,
 				&num_packets, &num_tx_bytes);
 		if (ret == -1) {
-			txq->stats.errs++;
+			txq->stats.errors++;
 			/* free tso mbufs */
 			if (num_tso_mbufs > 0)
 				rte_pktmbuf_free_bulk(mbuf, num_tso_mbufs);
@@ -748,9 +754,8 @@ pmd_tx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 		}
 	}
 
-	txq->stats.opackets += num_packets;
-	txq->stats.errs += nb_pkts - num_tx;
-	txq->stats.obytes += num_tx_bytes;
+	txq->stats.packets += num_packets;
+	txq->stats.bytes += num_tx_bytes;
 
 	return num_tx;
 }
@@ -1047,43 +1052,44 @@ tap_dev_info(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 static int
 tap_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *tap_stats)
 {
-	unsigned int i, imax;
-	unsigned long rx_total = 0, tx_total = 0, tx_err_total = 0;
-	unsigned long rx_bytes_total = 0, tx_bytes_total = 0;
-	unsigned long rx_nombuf = 0, ierrors = 0;
+	unsigned int i;
 	const struct pmd_internals *pmd = dev->data->dev_private;
+	uint64_t bytes, packets;
 
 	/* rx queue statistics */
-	imax = (dev->data->nb_rx_queues < RTE_ETHDEV_QUEUE_STAT_CNTRS) ?
-		dev->data->nb_rx_queues : RTE_ETHDEV_QUEUE_STAT_CNTRS;
-	for (i = 0; i < imax; i++) {
-		tap_stats->q_ipackets[i] = pmd->rxq[i].stats.ipackets;
-		tap_stats->q_ibytes[i] = pmd->rxq[i].stats.ibytes;
-		rx_total += tap_stats->q_ipackets[i];
-		rx_bytes_total += tap_stats->q_ibytes[i];
-		rx_nombuf += pmd->rxq[i].stats.rx_nombuf;
-		ierrors += pmd->rxq[i].stats.ierrors;
+	for (i = 0; i < dev->data->nb_rx_queues; i++) {
+		const struct rx_queue *rxq = &pmd->rxq[i];
+
+		packets = READ_ONCE(rxq->stats.packets);
+		bytes = READ_ONCE(rxq->stats.bytes);
+
+		tap_stats->ipackets += packets;
+		tap_stats->ibytes += bytes;
+		tap_stats->ierrors += rxq->stats.errors;
+
+		if (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) {
+			tap_stats->q_ipackets[i] = packets;
+			tap_stats->q_ibytes[i] = bytes;
+		}
 	}
 
 	/* tx queue statistics */
-	imax = (dev->data->nb_tx_queues < RTE_ETHDEV_QUEUE_STAT_CNTRS) ?
-		dev->data->nb_tx_queues : RTE_ETHDEV_QUEUE_STAT_CNTRS;
-
-	for (i = 0; i < imax; i++) {
-		tap_stats->q_opackets[i] = pmd->txq[i].stats.opackets;
-		tap_stats->q_obytes[i] = pmd->txq[i].stats.obytes;
-		tx_total += tap_stats->q_opackets[i];
-		tx_err_total += pmd->txq[i].stats.errs;
-		tx_bytes_total += tap_stats->q_obytes[i];
-	}
-
-	tap_stats->ipackets = rx_total;
-	tap_stats->ibytes = rx_bytes_total;
-	tap_stats->ierrors = ierrors;
-	tap_stats->rx_nombuf = rx_nombuf;
-	tap_stats->opackets = tx_total;
-	tap_stats->oerrors = tx_err_total;
-	tap_stats->obytes = tx_bytes_total;
+	for (i = 0; i < dev->data->nb_tx_queues; i++) {
+		const struct tx_queue *txq = &pmd->txq[i];
+
+		packets = READ_ONCE(txq->stats.packets);
+		bytes = READ_ONCE(txq->stats.bytes);
+
+		tap_stats->opackets += packets;
+		tap_stats->obytes += bytes;
+		tap_stats->oerrors += txq->stats.errors;
+
+		if (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) {
+			tap_stats->q_opackets[i] = packets;
+			tap_stats->q_obytes[i] = bytes;
+		}
+	}
+
 	return 0;
 }
 
@@ -1094,14 +1100,8 @@ tap_stats_reset(struct rte_eth_dev *dev)
 	struct pmd_internals *pmd = dev->data->dev_private;
 
 	for (i = 0; i < RTE_PMD_TAP_MAX_QUEUES; i++) {
-		pmd->rxq[i].stats.ipackets = 0;
-		pmd->rxq[i].stats.ibytes = 0;
-		pmd->rxq[i].stats.ierrors = 0;
-		pmd->rxq[i].stats.rx_nombuf = 0;
-
-		pmd->txq[i].stats.opackets = 0;
-		pmd->txq[i].stats.errs = 0;
-		pmd->txq[i].stats.obytes = 0;
+		memset(&pmd->rxq[i].stats, 0, sizeof(struct pkt_stats));
+		memset(&pmd->txq[i].stats, 0, sizeof(struct pkt_stats));
 	}
 
 	return 0;
@@ -1156,9 +1156,13 @@ tap_dev_close(struct rte_eth_dev *dev)
 	}
 
 	if (internals->remote_if_index) {
+		struct ifreq remote_ifr;
+
+		strlcpy(remote_ifr.ifr_name, internals->remote_iface, IFNAMSIZ);
+		remote_ifr.ifr_flags = internals->remote_flags;
+
 		/* Restore initial remote state */
-		int ret = ioctl(internals->ioctl_sock, SIOCSIFFLAGS,
-				&internals->remote_initial_flags);
+		int ret = ioctl(internals->ioctl_sock, SIOCSIFFLAGS, &remote_ifr);
 		if (ret)
 			TAP_LOG(ERR, "restore remote state failed: %d", ret);
 
@@ -2067,16 +2071,22 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 	LIST_INIT(&pmd->flows);
 
 	if (strlen(remote_iface)) {
+		struct ifreq remote_ifr;
+
 		pmd->remote_if_index = if_nametoindex(remote_iface);
 		if (!pmd->remote_if_index) {
 			TAP_LOG(ERR, "%s: failed to get %s if_index.",
 				pmd->name, remote_iface);
 			goto error_remote;
 		}
-		strlcpy(pmd->remote_iface, remote_iface, RTE_ETH_NAME_MAX_LEN);
+		strlcpy(pmd->remote_iface, remote_iface, IFNAMSIZ);
+
+		memset(&remote_ifr, 0, sizeof(ifr));
+		strlcpy(remote_ifr.ifr_name, remote_iface, IFNAMSIZ);
 
 		/* Save state of remote device */
-		tap_ioctl(pmd, SIOCGIFFLAGS, &pmd->remote_initial_flags, 0, REMOTE_ONLY);
+		tap_ioctl(pmd, SIOCGIFFLAGS, &remote_ifr, 0, REMOTE_ONLY);
+		pmd->remote_flags = remote_ifr.ifr_flags;
 
 		/* Replicate remote MAC address */
 		if (tap_ioctl(pmd, SIOCGIFHWADDR, &ifr, 0, REMOTE_ONLY) < 0) {
@@ -2190,10 +2200,10 @@ set_interface_name(const char *key __rte_unused,
 				value);
 			return -1;
 		}
-		strlcpy(name, value, RTE_ETH_NAME_MAX_LEN);
+		strlcpy(name, value, IFNAMSIZ);
 	} else {
 		/* use tap%d which causes kernel to choose next available */
-		strlcpy(name, DEFAULT_TAP_NAME "%d", RTE_ETH_NAME_MAX_LEN);
+		strlcpy(name, DEFAULT_TAP_NAME "%d", IFNAMSIZ);
 	}
 	return 0;
 }
@@ -2211,7 +2221,7 @@ set_remote_iface(const char *key __rte_unused,
 				value);
 			return -1;
 		}
-		strlcpy(name, value, RTE_ETH_NAME_MAX_LEN);
+		strlcpy(name, value, IFNAMSIZ);
 	}
 
 	return 0;
@@ -2262,13 +2272,13 @@ rte_pmd_tun_probe(struct rte_vdev_device *dev)
 	const char *name, *params;
 	int ret;
 	struct rte_kvargs *kvlist = NULL;
-	char tun_name[RTE_ETH_NAME_MAX_LEN];
-	char remote_iface[RTE_ETH_NAME_MAX_LEN];
+	char tun_name[IFNAMSIZ];
+	char remote_iface[IFNAMSIZ];
 	struct rte_eth_dev *eth_dev;
 
 	name = rte_vdev_device_name(dev);
 	params = rte_vdev_device_args(dev);
-	memset(remote_iface, 0, RTE_ETH_NAME_MAX_LEN);
+	memset(remote_iface, 0, IFNAMSIZ);
 
 	if (rte_eal_process_type() == RTE_PROC_SECONDARY &&
 	    strlen(params) == 0) {
@@ -2284,7 +2294,7 @@ rte_pmd_tun_probe(struct rte_vdev_device *dev)
 	}
 
 	/* use tun%d which causes kernel to choose next available */
-	strlcpy(tun_name, DEFAULT_TUN_NAME "%d", RTE_ETH_NAME_MAX_LEN);
+	strlcpy(tun_name, DEFAULT_TUN_NAME "%d", IFNAMSIZ);
 
 	if (params && (params[0] != '\0')) {
 		TAP_LOG(DEBUG, "parameters (%s)", params);
@@ -2424,8 +2434,8 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev)
 	int ret;
 	struct rte_kvargs *kvlist = NULL;
 	int speed;
-	char tap_name[RTE_ETH_NAME_MAX_LEN];
-	char remote_iface[RTE_ETH_NAME_MAX_LEN];
+	char tap_name[IFNAMSIZ];
+	char remote_iface[IFNAMSIZ];
 	struct rte_ether_addr user_mac = { .addr_bytes = {0} };
 	struct rte_eth_dev *eth_dev;
 	int tap_devices_count_increased = 0;
@@ -2479,8 +2489,8 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev)
 	speed = RTE_ETH_SPEED_NUM_10G;
 
 	/* use tap%d which causes kernel to choose next available */
-	strlcpy(tap_name, DEFAULT_TAP_NAME "%d", RTE_ETH_NAME_MAX_LEN);
-	memset(remote_iface, 0, RTE_ETH_NAME_MAX_LEN);
+	strlcpy(tap_name, DEFAULT_TAP_NAME "%d", IFNAMSIZ);
+	memset(remote_iface, 0, IFNAMSIZ);
 
 	if (params && (params[0] != '\0')) {
 		TAP_LOG(DEBUG, "parameters (%s)", params);
drivers/net/tap/rte_eth_tap.h +9 -13
index ce4322ad04..8f9ab613c7 100644
@@ -34,13 +34,9 @@ enum rte_tuntap_type {
 };
 
 struct pkt_stats {
-	uint64_t opackets;              /* Number of output packets */
-	uint64_t ipackets;              /* Number of input packets */
-	uint64_t obytes;                /* Number of bytes on output */
-	uint64_t ibytes;                /* Number of bytes on input */
-	uint64_t errs;                  /* Number of TX error packets */
-	uint64_t ierrors;               /* Number of RX error packets */
-	uint64_t rx_nombuf;             /* Nb of RX mbuf alloc failures */
+	uint64_t packets;       /* Number of packets */
+	uint64_t bytes;         /* Number of bytes */
+	uint64_t errors;        /* Number of errors */
 };
 
 struct rx_queue {
@@ -68,15 +64,16 @@ struct tx_queue {
 
 struct pmd_internals {
 	struct rte_eth_dev *dev;          /* Ethernet device. */
-	char remote_iface[RTE_ETH_NAME_MAX_LEN]; /* Remote netdevice name */
-	char name[RTE_ETH_NAME_MAX_LEN];  /* Internal Tap device name */
+	char remote_iface[IFNAMSIZ];	  /* Remote netdevice name */
+	char name[IFNAMSIZ];		  /* Internal Tap device name */
 	int type;                         /* Type field - TUN|TAP */
 	int persist;			  /* 1 if keep link up, else 0 */
 	struct rte_ether_addr eth_addr;   /* Mac address of the device port */
-	struct ifreq remote_initial_flags;/* Remote netdevice flags on init */
+	uint16_t remote_flags;		  /* Remote netdevice flags on init */
 	int remote_if_index;              /* remote netdevice IF_INDEX */
 	int if_index;                     /* IF_INDEX for the port */
 	int ioctl_sock;                   /* socket for ioctl calls */
+	int ka_fd;                        /* keep-alive file descriptor */
 
 #ifdef HAVE_TCA_FLOWER
 	int nlsk_fd;                      /* Netlink socket fd */
@@ -88,12 +85,11 @@ struct pmd_internals {
 	/* implicit rte_flow rules set when a remote device is active */
 	LIST_HEAD(tap_implicit_flows, rte_flow) implicit_flows;
 #endif
+	struct rte_intr_handle *intr_handle;         /* LSC interrupt handle. */
+	struct rte_mempool *gso_ctx_mp;     /* Mempool for GSO packets */
 
 	struct rx_queue rxq[RTE_PMD_TAP_MAX_QUEUES]; /* List of RX queues */
 	struct tx_queue txq[RTE_PMD_TAP_MAX_QUEUES]; /* List of TX queues */
-	struct rte_intr_handle *intr_handle;         /* LSC interrupt handle. */
-	int ka_fd;                        /* keep-alive file descriptor */
-	struct rte_mempool *gso_ctx_mp;     /* Mempool for GSO packets */
 };
 
 struct pmd_process_private {
Signature · 1 line
2.43.0
#151 lore raw

Re: [PATCH v12 09/12] net/tap: simplify internals

Quoted 11 lines · Stephen Hemminger

The names of Linux network devices are IFNAMSIZ(16) not the same as DPDK which has up to 64 characters. Don't need to hold onto the whole ifreq to save the remote interface flags.

Make sure packet and byte counters are read once, so that global and per-queue values add up. No need for separate rx_nombuf counter since there is an alloc_failed value in ethdev.

Keep only the statistics that are used. I.e no ipackets on tx queues etc.

This patch does multiple things, although each not very complex, I think splitting the patch makes it simpler to review.

Quoted 11 lines
---
 drivers/net/tap/rte_eth_tap.c | 138 ++++++++++++++++++----------------
 drivers/net/tap/rte_eth_tap.h |  22 +++---
 2 files changed, 83 insertions(+), 77 deletions(-)
drivers/net/tap/rte_eth_tap.c +0 -0
index d847565073..3614aaf1dc 100644

drivers/net/tap/rte_eth_tap.c line 54

Quoted 9 lines
drivers/net/tap/rte_eth_tap.c +5 -0
@@ -46,6 +46,11 @@
 #include <tap_netlink.h>
 #include <tap_tcmsgs.h>
 
+/* Used to snapshot statistics */
+#ifndef READ_ONCE
+#define READ_ONCE(var) (*((volatile typeof(var) *)(&(var))))
+#endif
+
 

Why 'READ_ONCE' is required?

As it is a function that provides pointer as parameter, won't stat values will be read from memory anyway?

<...>

drivers/net/tap/rte_eth_tap.c pmd_tx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) · line 757

Quoted 7 lines
drivers/net/tap/rte_eth_tap.c +0 -2
@@ -748,9 +754,8 @@ pmd_tx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 		}
 	}
 
-	txq->stats.opackets += num_packets;
-	txq->stats.errs += nb_pkts - num_tx;
 

As I commented before, we can't just drop this. Please check code in the function that has comment:
"/* stats.errs will be incremented */"

That code relies on this update, if we remove here something should replace it.

<...>

Quoted 23 lines
drivers/net/tap/rte_eth_tap.c +5 -3
 struct pmd_internals {
 	struct rte_eth_dev *dev;          /* Ethernet device. */
-	char remote_iface[RTE_ETH_NAME_MAX_LEN]; /* Remote netdevice name */
-	char name[RTE_ETH_NAME_MAX_LEN];  /* Internal Tap device name */
+	char remote_iface[IFNAMSIZ];	  /* Remote netdevice name */
+	char name[IFNAMSIZ];		  /* Internal Tap device name */
 	int type;                         /* Type field - TUN|TAP */
 	int persist;			  /* 1 if keep link up, else 0 */
 	struct rte_ether_addr eth_addr;   /* Mac address of the device port */
-	struct ifreq remote_initial_flags;/* Remote netdevice flags on init */
+	uint16_t remote_flags;		  /* Remote netdevice flags on init */
 	int remote_if_index;              /* remote netdevice IF_INDEX */
 	int if_index;                     /* IF_INDEX for the port */
 	int ioctl_sock;                   /* socket for ioctl calls */
+	int ka_fd;                        /* keep-alive file descriptor */
 
 #ifdef HAVE_TCA_FLOWER
 	int nlsk_fd;                      /* Netlink socket fd */
@@ -88,12 +85,11 @@ struct pmd_internals {
 	/* implicit rte_flow rules set when a remote device is active */
 	LIST_HEAD(tap_implicit_flows, rte_flow) implicit_flows;
 #endif
+	struct rte_intr_handle *intr_handle;         /* LSC interrupt handle. */

drivers/net/tap/rte_eth_tap.c struct pmd_internals { · line 95

Quoted 10 lines
drivers/net/tap/rte_eth_tap.c +1 -3
+	struct rte_mempool *gso_ctx_mp;     /* Mempool for GSO packets */
 
 	struct rx_queue rxq[RTE_PMD_TAP_MAX_QUEUES]; /* List of RX queues */
 	struct tx_queue txq[RTE_PMD_TAP_MAX_QUEUES]; /* List of TX queues */
-	struct rte_intr_handle *intr_handle;         /* LSC interrupt handle. */
-	int ka_fd;                        /* keep-alive file descriptor */
-	struct rte_mempool *gso_ctx_mp;     /* Mempool for GSO packets */
 };
 
 

Are the order of fields changed intentionally, for a specific reason?

#152 lore raw

Re: [PATCH v12 09/12] net/tap: simplify internals

Quoted 9 lines · On Mon, 20 May 2024 18:51:37 +0100 Ferruh Yigit <[email protected]> wrote:
Quoted 8 lines · Stephen Hemminger

The names of Linux network devices are IFNAMSIZ(16) not the same as DPDK which has up to 64 characters. Don't need to hold onto the whole ifreq to save the remote interface flags.

Make sure packet and byte counters are read once, so that global and per-queue values add up. No need for separate rx_nombuf counter since there is an alloc_failed value in ethdev.

Quoted 6 lines
Quoted 3 lines

Keep only the statistics that are used. I.e no ipackets on tx queues etc.

This patch does multiple things, although each not very complex, I think splitting the patch makes it simpler to review.

The patch got dropped in next rev.
The statistics stuff should be addressed by other series about generic SW stats since many drivers have some bugs in this area.

#153 lore raw

Re: [PATCH v12 09/12] net/tap: simplify internals

Quoted 16 lines · Stephen Hemminger
Quoted 13 lines · On Mon, 20 May 2024 18:51:37 +0100 Ferruh Yigit <[email protected]> wrote:
Quoted 11 lines · Stephen Hemminger

The names of Linux network devices are IFNAMSIZ(16) not the same as DPDK which has up to 64 characters. Don't need to hold onto the whole ifreq to save the remote interface flags.

Make sure packet and byte counters are read once, so that global and per-queue values add up. No need for separate rx_nombuf counter since there is an alloc_failed value in ethdev.

Keep only the statistics that are used. I.e no ipackets on tx queues etc.

Quoted 7 lines
Quoted 2 lines

This patch does multiple things, although each not very complex, I think splitting the patch makes it simpler to review.

The patch got dropped in next rev.
The statistics stuff should be addressed by other series about generic SW stats since many drivers have some bugs in this area.

It still exists in v15, I can drop while merging if included unintentionally.

#154 lore raw

PATCH v12 10/12 net/tap: remove extraneous newlines

In reply to Stephen Hemminger

Some log messages contained extra newlines.

---
 drivers/net/tap/rte_eth_tap.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)
drivers/net/tap/rte_eth_tap.c +8 -9
index 3614aaf1dc..2484a82ccb 100644
@@ -235,9 +235,8 @@ tun_alloc(struct pmd_internals *pmd, int is_keepalive, int persistent)
 
 	flags = fcntl(fd, F_GETFL);
 	if (flags == -1) {
-		TAP_LOG(WARNING,
-			"Unable to get %s current flags\n",
-			ifr.ifr_name);
+		TAP_LOG(WARNING, "Unable to get %s current flags: %s",
+			ifr.ifr_name, strerror(errno));
 		goto error;
 	}
 
@@ -279,7 +278,7 @@ tun_alloc(struct pmd_internals *pmd, int is_keepalive, int persistent)
 
 		if (sigaction(signo, &sa, NULL) == -1) {
 			TAP_LOG(WARNING,
-				"Unable to set rt-signal %d handler\n", signo);
+				"Unable to set rt-signal %d handler", signo);
 			goto error;
 		}
 
@@ -290,11 +289,11 @@ tun_alloc(struct pmd_internals *pmd, int is_keepalive, int persistent)
 	}
 
 	if (signo == SIGRTMAX) {
-		TAP_LOG(WARNING, "All rt-signals are in use\n");
+		TAP_LOG(WARNING, "All rt-signals are in use");
 
 		/* Disable trigger globally in case of error */
 		tap_trigger = 0;
-		TAP_LOG(NOTICE, "No Rx trigger signal available\n");
+		TAP_LOG(NOTICE, "No Rx trigger signal available");
 	} else {
 		/* Enable signal on file descriptor */
 		if (fcntl(fd, F_SETSIG, signo) < 0) {
@@ -920,7 +919,7 @@ tap_mp_req_start_rxtx(const struct rte_mp_msg *request, __rte_unused const void
 	}
 
 	process_private = dev->process_private;
-	TAP_LOG(DEBUG, "tap_attach q:%d\n", request_param->q_count);
+	TAP_LOG(DEBUG, "tap_attach q:%d", request_param->q_count);
 
 	for (int q = 0; q < request_param->q_count; q++)
 		process_private->fds[q] = request->fds[q];
@@ -1463,7 +1462,7 @@ tap_gso_ctx_setup(struct rte_gso_ctx *gso_ctx, struct rte_eth_dev *dev)
 		if (ret < 0 || ret >= (int)sizeof(pool_name)) {
 			TAP_LOG(ERR,
 				"%s: failed to create mbuf pool name for device %s,"
-				"device name too long or output error, ret: %d\n",
+				"device name too long or output error, ret: %d",
 				pmd->name, dev->device->name, ret);
 			return -ENAMETOOLONG;
 		}
@@ -1473,7 +1472,7 @@ tap_gso_ctx_setup(struct rte_gso_ctx *gso_ctx, struct rte_eth_dev *dev)
 			SOCKET_ID_ANY);
 		if (!pmd->gso_ctx_mp) {
 			TAP_LOG(ERR,
-				"%s: failed to create mbuf pool for device %s\n",
+				"%s: failed to create mbuf pool for device %s",
 				pmd->name, dev->device->name);
 			return -1;
 		}
Signature · 1 line
2.43.0
#156 lore raw

PATCH v12 11/12 net/tap: do not mark queue full as error

In reply to Stephen Hemminger

If tap device in kernel returns EAGAIN that means it is full. That is not an error.

---
 drivers/net/tap/rte_eth_tap.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/net/tap/rte_eth_tap.c +8 -5
index 2484a82ccb..485bd35912 100644
@@ -542,7 +542,6 @@ tap_write_mbufs(struct tx_queue *txq, uint16_t num_mbufs,
 		struct rte_mbuf *seg = mbuf;
 		uint64_t l4_ol_flags;
 		int proto;
-		int n;
 		int j;
 		int k; /* current index in iovecs for copying segments */
 
@@ -647,14 +646,18 @@ tap_write_mbufs(struct tx_queue *txq, uint16_t num_mbufs,
 		}
 
 		/* copy the tx frame data */
-		n = writev(process_private->fds[txq->queue_id], iovecs, k);
-		if (n <= 0)
-			return -1;
+		if (unlikely(writev(process_private->fds[txq->queue_id], iovecs, k) < 0)) {
+			TAP_LOG(DEBUG, "writev (qid=%u fd=%d) %s",
+				txq->queue_id, process_private->fds[txq->queue_id],
+				strerror(errno));
+			return (errno == EAGAIN) ? 0 : -1;
+		}
 
 		(*num_packets)++;
 		(*num_tx_bytes) += rte_pktmbuf_pkt_len(mbuf);
 	}
-	return 0;
+
+	return 1;
 }
 
 /* Callback to handle sending packets from the tap interface
Signature · 1 line
2.43.0
#157 lore raw

Re: [PATCH v12 11/12] net/tap: do not mark queue full as error

Quoted 22 lines · Stephen Hemminger

If tap device in kernel returns EAGAIN that means it is full. That is not an error.

---
 drivers/net/tap/rte_eth_tap.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/net/tap/rte_eth_tap.c +0 -1
index 2484a82ccb..485bd35912 100644
@@ -542,7 +542,6 @@ tap_write_mbufs(struct tx_queue *txq, uint16_t num_mbufs,
 		struct rte_mbuf *seg = mbuf;
 		uint64_t l4_ol_flags;
 		int proto;
-		int n;
 		int j;
 		int k; /* current index in iovecs for copying segments */
 
@@ -647,14 +646,18 @@ tap_write_mbufs(struct tx_queue *txq, uint16_t num_mbufs,
 		}

drivers/net/tap/rte_eth_tap.c tap_write_mbufs(struct tx_queue *txq, uint16_t num_mbufs, · line 653

Quoted 10 lines
drivers/net/tap/rte_eth_tap.c +4 -3
 
 		/* copy the tx frame data */
-		n = writev(process_private->fds[txq->queue_id], iovecs, k);
-		if (n <= 0)
-			return -1;
+		if (unlikely(writev(process_private->fds[txq->queue_id], iovecs, k) < 0)) {
+			TAP_LOG(DEBUG, "writev (qid=%u fd=%d) %s",
+				txq->queue_id, process_private->fds[txq->queue_id],
+				strerror(errno));
 

Do we really want logging in datapath?

drivers/net/tap/rte_eth_tap.c tap_write_mbufs(struct tx_queue *txq, uint16_t num_mbufs, · line 655

Quoted 2 lines
drivers/net/tap/rte_eth_tap.c +1 -0
+			return (errno == EAGAIN) ? 0 : -1;
 

Nack.

Returning '0' will cause 'pmd_tx_burst()' to continue and increase 'num_tx', this will mislead as packet sent successfully.

We should have three return values from 'tap_write_mbufs()':
<0 -> Error, 'pmd_tx_burst()' should break, stats.errors updated.
0 -> 'pmd_tx_burst()' should break, valid num_tx returned

drivers/net/tap/rte_eth_tap.c tap_write_mbufs(struct tx_queue *txq, uint16_t num_mbufs, · line 660

Quoted 11 lines

0 -> 'pmd_tx_burst()' work as it is.

drivers/net/tap/rte_eth_tap.c +3 -1
+		}
 
 		(*num_packets)++;
 		(*num_tx_bytes) += rte_pktmbuf_pkt_len(mbuf);
 	}
-	return 0;
+
+	return 1;

Why '1', wouldn't it be better to return number of packets written successfully.

#158 lore raw

Re: [PATCH v12 11/12] net/tap: do not mark queue full as error

Quoted 51 lines · On Mon, 20 May 2024 18:52:27 +0100 Ferruh Yigit <[email protected]> wrote:
Quoted 22 lines · Stephen Hemminger

If tap device in kernel returns EAGAIN that means it is full. That is not an error.

---
 drivers/net/tap/rte_eth_tap.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/net/tap/rte_eth_tap.c +0 -1
index 2484a82ccb..485bd35912 100644
@@ -542,7 +542,6 @@ tap_write_mbufs(struct tx_queue *txq, uint16_t num_mbufs,
 		struct rte_mbuf *seg = mbuf;
 		uint64_t l4_ol_flags;
 		int proto;
-		int n;
 		int j;
 		int k; /* current index in iovecs for copying segments */
 
@@ -647,14 +646,18 @@ tap_write_mbufs(struct tx_queue *txq, uint16_t num_mbufs,
 		}

drivers/net/tap/rte_eth_tap.c tap_write_mbufs(struct tx_queue *txq, uint16_t num_mbufs, · line 653

Quoted 10 lines
drivers/net/tap/rte_eth_tap.c +4 -3
 
 		/* copy the tx frame data */
-		n = writev(process_private->fds[txq->queue_id], iovecs, k);
-		if (n <= 0)
-			return -1;
+		if (unlikely(writev(process_private->fds[txq->queue_id], iovecs, k) < 0)) {
+			TAP_LOG(DEBUG, "writev (qid=%u fd=%d) %s",
+				txq->queue_id, process_private->fds[txq->queue_id],
+				strerror(errno));
 

Do we really want logging in datapath?

drivers/net/tap/rte_eth_tap.c tap_write_mbufs(struct tx_queue *txq, uint16_t num_mbufs, · line 655

Quoted 2 lines
drivers/net/tap/rte_eth_tap.c +1 -0
+			return (errno == EAGAIN) ? 0 : -1;
 

Nack.

Returning '0' will cause 'pmd_tx_burst()' to continue and increase 'num_tx', this will mislead as packet sent successfully.

We should have three return values from 'tap_write_mbufs()':
<0 -> Error, 'pmd_tx_burst()' should break, stats.errors updated.
0 -> 'pmd_tx_burst()' should break, valid num_tx returned

Quoted 4 lines

0 -> 'pmd_tx_burst()' work as it is.

drivers/net/tap/rte_eth_tap.c +1 -0
+		}
Quoted 11 lines

drivers/net/tap/rte_eth_tap.c tap_write_mbufs(struct tx_queue *txq, uint16_t num_mbufs, · line 660

Quoted 7 lines
drivers/net/tap/rte_eth_tap.c +2 -1
 		(*num_packets)++;
 		(*num_tx_bytes) += rte_pktmbuf_pkt_len(mbuf);
 	}
-	return 0;
+
+	return 1;

Why '1', wouldn't it be better to return number of packets written successfully.

Decided to drop this patch. Doing GSO inside the TAP device is the wrong place to do it. Kernel already has API to do GSO and checksum offload and it will be simpler and faster to use that. When TAP device is updated not to do the GSO here, this code goes away and handling the full condition properly gets much easier.

When TAP is doing GSO there are lots of corner cases where a expanded GSO packet could get only partially sent.

#159 lore raw

PATCH v12 12/12 net/tap: update documentation

In reply to Stephen Hemminger

The driver support of flows has changed and the wording in the guide was awkward.

Drop references to DPDK pktgen in this documentation since it is not required and confusing.

---
 doc/guides/nics/tap.rst                | 274 +++++++------------------
 doc/guides/rel_notes/release_24_07.rst |   7 +
 2 files changed, 84 insertions(+), 197 deletions(-)
doc/guides/nics/tap.rst +77 -197
index d4f45c02a1..55e38fb25b 100644
@@ -1,47 +1,51 @@
 ..  SPDX-License-Identifier: BSD-3-Clause
     Copyright(c) 2016 Intel Corporation.
 
-Tun|Tap Poll Mode Driver
-========================
+TAP Poll Mode Driver
+====================
 
-The ``rte_eth_tap.c`` PMD creates a device using TAP interfaces on the
-local host. The PMD allows for DPDK and the host to communicate using a raw
-device interface on the host and in the DPDK application.
+The TAP Poll Mode Driver (PMD) is a virtual device for injecting packets to be processed
+by the Linux kernel. This PMD is useful when writing DPDK application
+for offloading network functionality (such as tunneling) from the kernel.
 
-The device created is a TAP device, which sends/receives packet in a raw
-format with a L2 header. The usage for a TAP PMD is for connectivity to the
-local host using a TAP interface. When the TAP PMD is initialized it will
-create a number of tap devices in the host accessed via ``ifconfig -a`` or
-``ip`` command. The commands can be used to assign and query the virtual like
-device.
+From the kernel point of view, the TAP device looks like a regular network interface.
+The network device can be managed by standard tools such as ``ip`` and ``ethtool`` commands.
+It is also possible to use existing packet tools such as  ``wireshark`` or ``tcpdump``.
 
-These TAP interfaces can be used with Wireshark or tcpdump or Pktgen-DPDK
-along with being able to be used as a network connection to the DPDK
-application. The method enable one or more interfaces is to use the
-``--vdev=net_tap0`` option on the DPDK application command line. Each
-``--vdev=net_tap1`` option given will create an interface named dtap0, dtap1,
-and so on.
+From the DPDK application, the TAP device looks like a DPDK ethdev.
+Packets are sent and received in L2 (Ethernet) format. The standare DPDK
+API's to query for information, statistics and send and receive packets
+work as expected.
 
-The interface name can be changed by adding the ``iface=foo0``, for example::
+Requirements
+~~~~~~~~~~~~
+
+The TAP PMD requires kernel support for multiple queues in TAP device as
+well as the multi-queue ``multiq`` and incoming ``ingress`` queue disciplines.
+These are standard kernel features in most Linux distributions.
+
+Arguments
+---------
+
+TAP devices are created with the command line
+``--vdev=net_tap0`` option. This option maybe specified more the once by repeating
+with a different ``net_tapX`` device.
+
+By default, the Linux interfaces are named ``dtap0``, ``dtap1``, etc.
+The interface name can be specified by adding the ``iface=foo0``, for example::
 
    --vdev=net_tap0,iface=foo0 --vdev=net_tap1,iface=foo1, ...
 
-Normally the PMD will generate a random MAC address, but when testing or with
-a static configuration the developer may need a fixed MAC address style.
-Using the option ``mac=fixed`` you can create a fixed known MAC address::
+Normally the PMD will generate a random MAC address.
+If a static address is desired instead, the ``mac=fixed`` can be used.
 
    --vdev=net_tap0,mac=fixed
 
-The MAC address will have a fixed value with the last octet incrementing by one
-for each interface string containing ``mac=fixed``. The MAC address is formatted
-as 02:'d':'t':'a':'p':[00-FF]. Convert the characters to hex and you get the
-actual MAC address: ``02:64:74:61:70:[00-FF]``.
-
-   --vdev=net_tap0,mac="02:64:74:61:70:11"
+With the fixed option, the MAC address will have the first octets:
+as 02:'d':'t':'a':'p':[00-FF] and the last octets are the interface number.
 
-The MAC address will have a user value passed as string. The MAC address is in
-format with delimiter ``:``. The string is byte converted to hex and you get
-the actual MAC address: ``02:64:74:61:70:11``.
+To specify a specific MAC address use the conventional representation.
+The string is byte converted to hex, the result is MAC address: ``02:64:74:61:70:11``.
 
 It is possible to specify a remote netdevice to capture packets from by adding
 ``remote=foo1``, for example::
@@ -59,40 +63,20 @@ netdevice that has no support in the DPDK. It is possible to add explicit
 rte_flow rules on the tap PMD to capture specific traffic (see next section for
 examples).
 
-After the DPDK application is started you can send and receive packets on the
-interface using the standard rx_burst/tx_burst APIs in DPDK. From the host
-point of view you can use any host tool like tcpdump, Wireshark, ping, Pktgen
-and others to communicate with the DPDK application. The DPDK application may
-not understand network protocols like IPv4/6, UDP or TCP unless the
-application has been written to understand these protocols.
-
-If you need the interface as a real network interface meaning running and has
-a valid IP address then you can do this with the following commands::
-
-   sudo ip link set dtap0 up; sudo ip addr add 192.168.0.250/24 dev dtap0
-   sudo ip link set dtap1 up; sudo ip addr add 192.168.1.250/24 dev dtap1
-
-Please change the IP addresses as you see fit.
-
-If routing is enabled on the host you can also communicate with the DPDK App
-over the internet via a standard socket layer application as long as you
-account for the protocol handling in the application.
-
-If you have a Network Stack in your DPDK application or something like it you
-can utilize that stack to handle the network protocols. Plus you would be able
-to address the interface using an IP address assigned to the internal
-interface.
-
 Normally, when the DPDK application exits,
 the TAP device is marked down and is removed.
-But this behaviour can be overridden by the use of the persist flag, example::
+But this behavior can be overridden by the use of the persist flag, example::
 
   --vdev=net_tap0,iface=tap0,persist ...
 
-The TUN PMD allows user to create a TUN device on host. The PMD allows user
-to transmit and receive packets via DPDK API calls with L3 header and payload.
-The devices in host can be accessed via ``ifconfig`` or ``ip`` command. TUN
-interfaces are passed to DPDK ``rte_eal_init`` arguments as ``--vdev=net_tunX``,
+TUN devices
+-----------
+
+The TAP device can be used an L3 tunnel only device (TUN).
+This type of device does not include the Ethernet (L2) header; all packets
+are sent and received as IP packets.
+
+TUN devices are created with the command line arguments ``--vdev=net_tunX``,
 where X stands for unique id, example::
 
    --vdev=net_tun0 --vdev=net_tun1,iface=foo1, ...
@@ -103,27 +87,33 @@ options. Default interface name is ``dtunX``, where X stands for unique id.
 Flow API support
 ----------------
 
-The tap PMD supports major flow API pattern items and actions, when running on
-linux kernels above 4.2 ("Flower" classifier required).
-The kernel support can be checked with this command::
+The TAP PMD supports major flow API pattern items and actions.
+
+Requirements
+~~~~~~~~~~~~
 
-   zcat /proc/config.gz | ( grep 'CLS_FLOWER=' || echo 'not supported' ) |
-   tee -a /dev/stderr | grep -q '=m' &&
-   lsmod | ( grep cls_flower || echo 'try modprobe cls_flower' )
+Flow support in TAP driver requires the Linux kernel support of flow based
+traffic control filter ``flower``. This was added in Linux 4.3 kernel.
 
-Supported items:
+The implementation of RSS action uses an eBPF module that requires additional
+libraries and tools. Building the RSS support requires the ``clang``
+compiler to compile the C code to BPF target; ``bpftool`` to convert the
+compiled BPF object to a header file; and ``libbpf`` to load the eBPF
+action into the kernel.
 
-- eth: src and dst (with variable masks), and eth_type (0xffff mask).
-- vlan: vid, pcp, but not eid. (requires kernel 4.9)
-- ipv4/6: src and dst (with variable masks), and ip_proto (0xffff mask).
-- udp/tcp: src and dst port (0xffff) mask.
+Supported match items:
+
+  - eth: src and dst (with variable masks), and eth_type (0xffff mask).
+  - vlan: vid, pcp, but not eid. (requires kernel 4.9)
+  - ipv4/6: src and dst (with variable masks), and ip_proto (0xffff mask).
+  - udp/tcp: src and dst port (0xffff) mask.
 
 Supported actions:
 
 - DROP
 - QUEUE
 - PASSTHRU
-- RSS (requires kernel 4.9)
+- RSS
 
 It is generally not possible to provide a "last" item. However, if the "last"
 item, once masked, is identical to the masked spec, then it is supported.
@@ -133,7 +123,7 @@ full mask (exact match).
 
 As rules are translated to TC, it is possible to show them with something like::
 
-   tc -s filter show dev tap1 parent 1:
+   tc -s filter show dev dtap1 parent 1:
 
 Examples of testpmd flow rules
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -174,135 +164,25 @@ The IPC synchronization of Rx/Tx queues is currently limited:
   - Maximum 8 queues shared
   - Synchronized on probing, but not on later port update
 
-Example
--------
-
-The following is a simple example of using the TAP PMD with the Pktgen
-packet generator. It requires that the ``socat`` utility is installed on the
-test system.
-
-Build DPDK, then pull down Pktgen and build pktgen using the DPDK SDK/Target
-used to build the dpdk you pulled down.
-
-Run pktgen from the pktgen directory in a terminal with a commandline like the
-following::
-
-    sudo ./app/app/x86_64-native-linux-gcc/app/pktgen -l 1-5 -n 4        \
-     --proc-type auto --log-level debug --socket-mem 512,512 --file-prefix pg   \
-     --vdev=net_tap0 --vdev=net_tap1 -b 05:00.0 -b 05:00.1                  \
-     -b 04:00.0 -b 04:00.1 -b 04:00.2 -b 04:00.3                            \
-     -b 81:00.0 -b 81:00.1 -b 81:00.2 -b 81:00.3                            \
-     -b 82:00.0 -b 83:00.0 -- -T -P -m [2:3].0 -m [4:5].1                   \
-     -f themes/black-yellow.theme
-
-.. Note:
-
-   Change the ``-b`` options to exclude all of your physical ports. The
-   following command line is all one line.
-
-   Also, ``-f themes/black-yellow.theme`` is optional if the default colors
-   work on your system configuration. See the Pktgen docs for more
-   information.
-
-Verify with ``ifconfig -a`` command in a different xterm window, should have a
-``dtap0`` and ``dtap1`` interfaces created.
-
-Next set the links for the two interfaces to up via the commands below::
-
-    sudo ip link set dtap0 up; sudo ip addr add 192.168.0.250/24 dev dtap0
-    sudo ip link set dtap1 up; sudo ip addr add 192.168.1.250/24 dev dtap1
-
-Then use socat to create a loopback for the two interfaces::
-
-    sudo socat interface:dtap0 interface:dtap1
-
-Then on the Pktgen command line interface you can start sending packets using
-the commands ``start 0`` and ``start 1`` or you can start both at the same
-time with ``start all``. The command ``str`` is an alias for ``start all`` and
-``stp`` is an alias for ``stop all``.
-
-While running you should see the 64 byte counters increasing to verify the
-traffic is being looped back. You can use ``set all size XXX`` to change the
-size of the packets after you stop the traffic. Use pktgen ``help``
-command to see a list of all commands. You can also use the ``-f`` option to
-load commands at startup in command line or Lua script in pktgen.
 
 RSS specifics
 -------------
-Packet distribution in TAP is done by the kernel which has a default
-distribution. This feature is adding RSS distribution based on eBPF code.
-The default eBPF code calculates RSS hash based on Toeplitz algorithm for
-a fixed RSS key. It is calculated on fixed packet offsets. For IPv4 and IPv6 it
-is calculated over src/dst addresses (8 or 32 bytes for IPv4 or IPv6
-respectively) and src/dst TCP/UDP ports (4 bytes).
-
-The RSS algorithm is written in file ``tap_bpf_program.c`` which
-does not take part in TAP PMD compilation. Instead this file is compiled
-in advance to eBPF object file. The eBPF object file is then parsed and
-translated into eBPF byte code in the format of C arrays of eBPF
-instructions. The C array of eBPF instructions is part of TAP PMD tree and
-is taking part in TAP PMD compilation. At run time the C arrays are uploaded to
-the kernel via BPF system calls and the RSS hash is calculated by the
-kernel.
-
-It is possible to support different RSS hash algorithms by updating file
-``tap_bpf_program.c``  In order to add a new RSS hash algorithm follow these
-steps:
-
-#. Write the new RSS implementation in file ``tap_bpf_program.c``
-
-   BPF programs which are uploaded to the kernel correspond to
-   C functions under different ELF sections.
-
-#. Install ``LLVM`` library and ``clang`` compiler versions 3.7 and above
-
-#. Use make to compile  `tap_bpf_program.c`` via ``LLVM`` into an object file
-   and extract the resulting instructions into ``tap_bpf_insn.h``::
-
-    cd bpf; make
-
-#. Recompile the TAP PMD.
-
-The C arrays are uploaded to the kernel using BPF system calls.
-
-``tc`` (traffic control) is a well known user space utility program used to
-configure the Linux kernel packet scheduler. It is usually packaged as
-part of the ``iproute2`` package.
-Since commit 11c39b5e9 ("tc: add eBPF support to f_bpf") ``tc`` can be used
-to uploads eBPF code to the kernel and can be patched in order to print the
-C arrays of eBPF instructions just before calling the BPF system call.
-Please refer to ``iproute2`` package file ``lib/bpf.c`` function
-``bpf_prog_load()``.
-
-An example utility for eBPF instruction generation in the format of C arrays will
-be added in next releases
-
-TAP reports on supported RSS functions as part of dev_infos_get callback:
-``RTE_ETH_RSS_IP``, ``RTE_ETH_RSS_UDP`` and ``RTE_ETH_RSS_TCP``.
-**Known limitation:** TAP supports all of the above hash functions together
-and not in partial combinations.
-
-Systems supporting flow API
----------------------------
-
-- "tc flower" classifier requires linux kernel above 4.2
-- eBPF/RSS requires linux kernel above 4.9
-
-+--------------------+-----------------------+
-| RH7.3              | No flow rule support  |
-+--------------------+-----------------------+
-| RH7.4              | No RSS action support |
-+--------------------+-----------------------+
-| RH7.5              | No RSS action support |
-+--------------------+-----------------------+
-| SLES 15,           | No limitation         |
-| kernel 4.12        |                       |
-+--------------------+-----------------------+
-| Azure Ubuntu 16.04,| No limitation         |
-| kernel 4.13        |                       |
-+--------------------+-----------------------+
+The default packet distribution in TAP without flow rules is done by the
+kernel which has a default flow based distribution.
+When flow rules are used to distribute packets across a set of queues
+an eBPF program is used to calculate the RSS based on Toeplitz algorithm for
+with the given key.
+
+The hash is calculated for IPv4 and IPv6, over src/dst addresses
+(8 or 32 bytes for IPv4 or IPv6 respectively) and
+optionally the src/dst TCP/UDP ports (4 bytes).
+
 
 Limitations
 -----------
 
-* Rx/Tx must have the same number of queues.
+- Since TAP device uses a file descriptors to talk to the kernel.
+  The same number of queues must be specified for receive and transmit.
+
+- The RSS algorithm only support L3 or L4 functions. It does not support
+  finer grain selections (for example: only IPV6 packets with extension headers).
doc/guides/rel_notes/release_24_07.rst +7 -0
index a69f24cf99..8652271ed2 100644
@@ -55,6 +55,13 @@ New Features
      Also, make sure to start the actual text at the margin.
      =======================================================
 
+* **TAP PMD updates.**
+
+  * Fixed support of RSS flow action to work with current Linux
+    kernels and BPF tooling. Will only be enabled if clang and bpftool
+    are available.
+
+  * Support up to 8 queues when used by secondary process
 
 Removed Items
 -------------
Signature · 1 line
2.43.0
#160 lore raw

Re: [PATCH v12 12/12] net/tap: update documentation

Quoted 12 lines · Stephen Hemminger

The driver support of flows has changed and the wording in the guide was awkward.

Drop references to DPDK pktgen in this documentation since it is not required and confusing.

---
 doc/guides/nics/tap.rst                | 274 +++++++------------------
 doc/guides/rel_notes/release_24_07.rst |   7 +
 2 files changed, 84 insertions(+), 197 deletions(-)

If there are document changes related to the changes in the previous commits, can it be possible to distribute those changes to the relevant commits?

It is better if we can eliminate this individual patch completely.

#161 lore raw

Re: [PATCH v12 12/12] net/tap: update documentation

Quoted 14 lines · On Mon, 20 May 2024 18:53:19 +0100 Ferruh Yigit <[email protected]> wrote:
Quoted 12 lines · Stephen Hemminger

The driver support of flows has changed and the wording in the guide was awkward.

Drop references to DPDK pktgen in this documentation since it is not required and confusing.

---
 doc/guides/nics/tap.rst                | 274 +++++++------------------
 doc/guides/rel_notes/release_24_07.rst |   7 +
 2 files changed, 84 insertions(+), 197 deletions(-)
Quoted 6 lines

If there are document changes related to the changes in the previous commits, can it be possible to distribute those changes to the relevant commits?

It is better if we can eliminate this individual patch completely.

Will put release note with the individual patches.

The overall documentation for this PMD was very much out of date, and the problems were not really related to earlier commits.

#162 lore raw

v13 cover net/tap: make RSS work again

In reply to Stephen Hemminger

The support of doing RSS for rte_flow_action was a cool idea but it has been broken for several releases of DPDK as the underlying kernel and BPF infrastructure changed.

This series cleans up the BPF program, implements several features that were never completed in the original code and changes to use the current BPF tool chain.

The result should be easier to read and maintain. I do not intend to support backporting this to stable releases due to lack of demand and dealing with older distros.

v13 - Incorporate review feedback.
Drop change to statistics and queue full handling; these will get fixed in another series.

Stephen Hemminger (11):
net/tap: fix fd check in flow_isolate
net/tap: do not duplicate fd's
net/tap: remove unused fields
net/tap: validate and setup parameters for BPF RSS net/tap: do not build flow support if header is out of date net/tap: rewrite the RSS BPF program
net/tap: use libbpf to load new BPF program net/tap: remove no longer used files
net/tap: simplify internals
net/tap: remove extraneous newlines
net/tap: update documentation

 .gitignore                             |    3 -
 doc/guides/nics/tap.rst                |  274 ++--
 doc/guides/rel_notes/release_24_07.rst |    7 +
 drivers/net/tap/bpf/Makefile           |   19 -
 drivers/net/tap/bpf/README             |   49 +
 drivers/net/tap/bpf/bpf_api.h          |  276 ----
 drivers/net/tap/bpf/bpf_elf.h          |   53 -
 drivers/net/tap/bpf/bpf_extract.py     |   86 --
 drivers/net/tap/bpf/meson.build        |  107 ++
 drivers/net/tap/bpf/tap_bpf_program.c  |  255 ----
 drivers/net/tap/bpf/tap_rss.c          |  267 ++++
 drivers/net/tap/meson.build            |   42 +-
 drivers/net/tap/rte_eth_tap.c          |  373 +++--
 drivers/net/tap/rte_eth_tap.h          |   42 +-
 drivers/net/tap/tap_bpf.h              |  121 --
 drivers/net/tap/tap_bpf_api.c          |  190 ---
 drivers/net/tap/tap_bpf_insns.h        | 1743 ------------------------
 drivers/net/tap/tap_flow.c             |  565 +++-----
 drivers/net/tap/tap_flow.h             |   17 +-
 drivers/net/tap/tap_intr.c             |    7 +-
 drivers/net/tap/tap_rss.h              |   21 +-
 drivers/net/tap/tap_tcmsgs.h           |    4 +-
 22 files changed, 909 insertions(+), 3612 deletions(-)
 delete mode 100644 drivers/net/tap/bpf/Makefile
 create mode 100644 drivers/net/tap/bpf/README
 delete mode 100644 drivers/net/tap/bpf/bpf_api.h
 delete mode 100644 drivers/net/tap/bpf/bpf_elf.h
 delete mode 100644 drivers/net/tap/bpf/bpf_extract.py
 create mode 100644 drivers/net/tap/bpf/meson.build
 delete mode 100644 drivers/net/tap/bpf/tap_bpf_program.c
 create mode 100644 drivers/net/tap/bpf/tap_rss.c
 delete mode 100644 drivers/net/tap/tap_bpf.h
 delete mode 100644 drivers/net/tap/tap_bpf_api.c
 delete mode 100644 drivers/net/tap/tap_bpf_insns.h
Signature · 1 line
2.43.0
#163 lore raw

PATCH v13 1/11 net/tap: fix fd check in flow_isolate

The check for receive queue fd in flow_isolate is incorrect. If queue has not been setup then fd will be -1 not 0.

---
 drivers/net/tap/tap_flow.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/tap/tap_flow.c +1 -1
index fa50fe45d7..79cd6a12ca 100644
@@ -1595,7 +1595,7 @@ tap_flow_isolate(struct rte_eth_dev *dev,
 	 * If netdevice is there, setup appropriate flow rules immediately.
 	 * Otherwise it will be set when bringing up the netdevice (tun_alloc).
 	 */
-	if (!process_private->rxq_fds[0])
+	if (process_private->rxq_fds[0] == -1)
 		return 0;
 	if (set) {
 		struct rte_flow *remote_flow;
Signature · 1 line
2.43.0
#164 lore raw

PATCH v13 2/11 net/tap: do not duplicate fd's

In reply to Stephen Hemminger

The TAP device can use same file descriptor for both rx and tx queues which reduces the number of fd's required.

MP process support passes file descriptors from primary to secondary process; but because of the restriction on max fd's passed RTE_MP_MAX_FD_NUM (8) the TAP device was restricted to only 4 queues if using secondary.
This allows up to 8 queues (versus 4).

The restriction on max fd's should be changed in eal in future, but it will break ABI compatibility. The max Linux supports which is SCM_MAX_FD (253).

---
 doc/guides/rel_notes/release_24_07.rst |   4 +
 drivers/net/tap/rte_eth_tap.c          | 192 ++++++++++---------------
 drivers/net/tap/rte_eth_tap.h          |   3 +-
 drivers/net/tap/tap_flow.c             |   3 +-
 drivers/net/tap/tap_intr.c             |   7 +-
 5 files changed, 89 insertions(+), 120 deletions(-)
doc/guides/rel_notes/release_24_07.rst +4 -0
index a69f24cf99..fa9692924b 100644
@@ -55,6 +55,10 @@ New Features
      Also, make sure to start the actual text at the margin.
      =======================================================
 
+* **Update Tap PMD driver.
+
+  * Updated to support up to 8 queues when used by secondary process.
+
 
 Removed Items
 -------------
drivers/net/tap/rte_eth_tap.c +78 -114

337 lines not on this page · raw message

drivers/net/tap/rte_eth_tap.h +1 -2
index 5ac93f93e9..dc8201020b 100644
@@ -96,8 +96,7 @@ struct pmd_internals {
 };
 
 struct pmd_process_private {
-	int rxq_fds[RTE_PMD_TAP_MAX_QUEUES];
-	int txq_fds[RTE_PMD_TAP_MAX_QUEUES];
+	int fds[RTE_PMD_TAP_MAX_QUEUES];
 };
 
 /* tap_intr.c */
drivers/net/tap/tap_flow.c +2 -1
index 79cd6a12ca..a78fd50cd4 100644
@@ -1595,8 +1595,9 @@ tap_flow_isolate(struct rte_eth_dev *dev,
 	 * If netdevice is there, setup appropriate flow rules immediately.
 	 * Otherwise it will be set when bringing up the netdevice (tun_alloc).
 	 */
-	if (process_private->rxq_fds[0] == -1)
+	if (process_private->fds[0] == -1)
 		return 0;
+
 	if (set) {
 		struct rte_flow *remote_flow;
 
drivers/net/tap/tap_intr.c +4 -3
index a9097def1a..1908f71f97 100644
@@ -68,9 +68,11 @@ tap_rx_intr_vec_install(struct rte_eth_dev *dev)
 	}
 	for (i = 0; i < n; i++) {
 		struct rx_queue *rxq = pmd->dev->data->rx_queues[i];
+		int fd = process_private->fds[i];
 
 		/* Skip queues that cannot request interrupts. */
-		if (!rxq || process_private->rxq_fds[i] == -1) {
+		if (!rxq || fd == -1) {
+			/* Use invalid intr_vec[] index to disable entry. */
 			/* Use invalid intr_vec[] index to disable entry. */
 			if (rte_intr_vec_list_index_set(intr_handle, i,
 			RTE_INTR_VEC_RXTX_OFFSET + RTE_MAX_RXTX_INTR_VEC_ID))
@@ -80,8 +82,7 @@ tap_rx_intr_vec_install(struct rte_eth_dev *dev)
 		if (rte_intr_vec_list_index_set(intr_handle, i,
 					RTE_INTR_VEC_RXTX_OFFSET + count))
 			return -rte_errno;
-		if (rte_intr_efds_index_set(intr_handle, count,
-						   process_private->rxq_fds[i]))
+		if (rte_intr_efds_index_set(intr_handle, count, fd))
 			return -rte_errno;
 		count++;
 	}
Signature · 1 line
2.43.0
#165 lore raw

PATCH v13 3/11 net/tap: remove unused fields

In reply to Stephen Hemminger

The driver doesn't support these other hash types, and there is no reason to implement these in future. The rss_flows list was set but never used.

---
 drivers/net/tap/rte_eth_tap.h | 4 +---
 drivers/net/tap/tap_flow.c    | 1 -
 drivers/net/tap/tap_rss.h     | 6 ------
 3 files changed, 1 insertion(+), 10 deletions(-)
drivers/net/tap/rte_eth_tap.h +1 -3
index dc8201020b..1bcf92ce80 100644
@@ -77,14 +77,12 @@ struct pmd_internals {
 	int ioctl_sock;                   /* socket for ioctl calls */
 	int nlsk_fd;                      /* Netlink socket fd */
 	int flow_isolate;                 /* 1 if flow isolation is enabled */
-	int flower_support;               /* 1 if kernel supports, else 0 */
-	int flower_vlan_support;          /* 1 if kernel supports, else 0 */
 	int rss_enabled;                  /* 1 if RSS is enabled, else 0 */
 	int persist;			  /* 1 if keep link up, else 0 */
 	/* implicit rules set when RSS is enabled */
 	int map_fd;                       /* BPF RSS map fd */
 	int bpf_fd[RTE_PMD_TAP_MAX_QUEUES];/* List of bpf fds per queue */
-	LIST_HEAD(tap_rss_flows, rte_flow) rss_flows;
+
 	LIST_HEAD(tap_flows, rte_flow) flows;        /* rte_flow rules */
 	/* implicit rte_flow rules set when a remote device is active */
 	LIST_HEAD(tap_implicit_flows, rte_flow) implicit_flows;
drivers/net/tap/tap_flow.c +0 -1
index a78fd50cd4..8fccd599f0 100644
@@ -1958,7 +1958,6 @@ static int rss_enable(struct pmd_internals *pmd,
 				errno, strerror(errno));
 			return err;
 		}
-		LIST_INSERT_HEAD(&pmd->rss_flows, rss_flow, next);
 	}
 
 	pmd->rss_enabled = 1;
drivers/net/tap/tap_rss.h +0 -6
index dff46a012f..8766ffc244 100644
@@ -21,12 +21,6 @@ enum hash_field {
 	HASH_FIELD_IPV4_L3_L4,	/* IPv4 src/dst addr + L4 src/dst ports */
 	HASH_FIELD_IPV6_L3,	/* IPv6 src/dst addr */
 	HASH_FIELD_IPV6_L3_L4,	/* IPv6 src/dst addr + L4 src/dst ports */
-	HASH_FIELD_L2_SRC,	/* Ethernet src addr */
-	HASH_FIELD_L2_DST,	/* Ethernet dst addr */
-	HASH_FIELD_L3_SRC,	/* L3 src addr */
-	HASH_FIELD_L3_DST,	/* L3 dst addr */
-	HASH_FIELD_L4_SRC,	/* TCP/UDP src ports */
-	HASH_FIELD_L4_DST,	/* TCP/UDP dst ports */
 };
 
 struct rss_key {
Signature · 1 line
2.43.0
#166 lore raw

PATCH v13 4/11 net/tap: validate and setup parameters for BPF RSS

In reply to Stephen Hemminger

The flow RSS support via BPF was not using the key, or hash type parameters. Which is good because they were never properly setup.

Fix the setup and validate the flow parameters, the BPF side gets fixed later.

---
 drivers/net/tap/tap_flow.c | 75 +++++++++++++++++++++++++++++++++++---
 drivers/net/tap/tap_rss.h  |  5 +--
 2 files changed, 72 insertions(+), 8 deletions(-)
drivers/net/tap/tap_flow.c +70 -5
index 8fccd599f0..dd4e69b876 100644
@@ -11,9 +11,11 @@
 
 #include <rte_byteorder.h>
 #include <rte_jhash.h>
+#include <rte_thash.h>
 #include <rte_random.h>
 #include <rte_malloc.h>
 #include <rte_eth_tap.h>
+
 #include <tap_flow.h>
 #include <tap_autoconf.h>
 #include <tap_tcmsgs.h>
@@ -2061,6 +2063,21 @@ static int bpf_rss_key(enum bpf_rss_key_e cmd, __u32 *key_idx)
 	return err;
 }
 
+
+/* Default RSS hash key also used by mlx devices */
+static const uint8_t rss_hash_default_key[] = {
+	0x2c, 0xc6, 0x81, 0xd1,
+	0x5b, 0xdb, 0xf4, 0xf7,
+	0xfc, 0xa2, 0x83, 0x19,
+	0xdb, 0x1a, 0x3e, 0x94,
+	0x6b, 0x9e, 0x38, 0xd9,
+	0x2c, 0x9c, 0x03, 0xd1,
+	0xad, 0x99, 0x44, 0xa7,
+	0xd9, 0x56, 0x3d, 0x59,
+	0x06, 0x3c, 0x25, 0xf3,
+	0xfc, 0x1f, 0xdc, 0x2a,
+};
+
 /**
  * Add RSS hash calculations and queue selection
  *
@@ -2079,11 +2096,11 @@ static int rss_add_actions(struct rte_flow *flow, struct pmd_internals *pmd,
 			   const struct rte_flow_action_rss *rss,
 			   struct rte_flow_error *error)
 {
-	/* 4096 is the maximum number of instructions for a BPF program */
+	struct rss_key rss_entry = { };
+	const uint8_t *key_in;
+	uint32_t hash_type = 0;
 	unsigned int i;
 	int err;
-	struct rss_key rss_entry = { .hash_fields = 0,
-				     .key_size = 0 };
 
 	/* Check supported RSS features */
 	if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT)
@@ -2095,6 +2112,51 @@ static int rss_add_actions(struct rte_flow *flow, struct pmd_internals *pmd,
 			(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
 			 "a nonzero RSS encapsulation level is not supported");
 
+	if (rss->queue_num == 0 || rss->queue_num >= TAP_MAX_QUEUES)
+		return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
+					  "invalid number of queues");
+
+	/*
+	 * Follow the semantics of RSS key (see rte_ethdev.h)
+	 * There are two valid cases:
+	 *   1. key_length of zero, and key must be NULL;
+	 *      this uses the default driver key.
+	 *
+	 *   2. key_length is the TAP_RSS_HASH_KEY_SIZE (40 bytes)
+	 *      and the key must not be NULL.
+	 *
+	 * Anything else is an error.
+	 */
+	if (rss->key_len == 0) {
+		if (rss->key != NULL)
+			return rte_flow_error_set(error, ENOTSUP,
+						  RTE_FLOW_ERROR_TYPE_ACTION_CONF,
+						  &rss->key_len, "RSS hash key length 0");
+		key_in = rss_hash_default_key;
+	} else {
+		if (rss->key_len != TAP_RSS_HASH_KEY_SIZE)
+			return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+						  NULL, "RSS hash invalid key length");
+		if (rss->key == NULL)
+			return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+						  NULL, "RSS hash key is NULL");
+		key_in = rss->key;
+	}
+
+	if (rss->types & TAP_RSS_HF_MASK)
+		return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+					  NULL, "RSS hash type not supported");
+
+	if (rss->types & (RTE_ETH_RSS_NONFRAG_IPV4_UDP | RTE_ETH_RSS_NONFRAG_IPV4_TCP))
+		hash_type |= RTE_BIT32(HASH_FIELD_IPV4_L3_L4);
+	else if (rss->types & (RTE_ETH_RSS_IPV4 | RTE_ETH_RSS_FRAG_IPV4))
+		hash_type |= RTE_BIT32(HASH_FIELD_IPV4_L3);
+
+	if (rss->types & (RTE_ETH_RSS_NONFRAG_IPV6_UDP | RTE_ETH_RSS_NONFRAG_IPV6_TCP))
+		hash_type |= RTE_BIT32(HASH_FIELD_IPV6_L3_L4);
+	else if (rss->types & (RTE_ETH_RSS_IPV6 | RTE_ETH_RSS_FRAG_IPV6 | RTE_ETH_RSS_IPV6_EX))
+		hash_type |= RTE_BIT32(HASH_FIELD_IPV6_L3);
+
 	/* Get a new map key for a new RSS rule */
 	err = bpf_rss_key(KEY_CMD_GET, &flow->key_idx);
 	if (err < 0) {
@@ -2109,8 +2171,11 @@ static int rss_add_actions(struct rte_flow *flow, struct pmd_internals *pmd,
 	rss_entry.nb_queues = rss->queue_num;
 	for (i = 0; i < rss->queue_num; i++)
 		rss_entry.queues[i] = rss->queue[i];
-	rss_entry.hash_fields =
-		(1 << HASH_FIELD_IPV4_L3_L4) | (1 << HASH_FIELD_IPV6_L3_L4);
+
+	rss_entry.hash_fields = hash_type;
+	rte_convert_rss_key((const uint32_t *)key_in, (uint32_t *)rss_entry.key,
+			    TAP_RSS_HASH_KEY_SIZE);
+
 
 	/* Add this RSS entry to map */
 	err = tap_flow_bpf_update_rss_elem(pmd->map_fd,
drivers/net/tap/tap_rss.h +2 -3
index 8766ffc244..6009be7031 100644
@@ -24,11 +24,10 @@ enum hash_field {
 };
 
 struct rss_key {
-	 __u8 key[128];
 	__u32 hash_fields;
-	__u32 key_size;
-	__u32 queues[TAP_MAX_QUEUES];
+	__u8 key[TAP_RSS_HASH_KEY_SIZE];
 	__u32 nb_queues;
+	__u32 queues[TAP_MAX_QUEUES];
 } __attribute__((packed));
 
 #endif /* _TAP_RSS_H_ */
Signature · 1 line
2.43.0
#167 lore raw

PATCH v13 5/11 net/tap: do not build flow support if header is out of date

In reply to Stephen Hemminger

The proper place for finding bpf structures and functions is in linux/bpf.h. The original version was trying to workaround the case where the build environment was running on old pre BPF version of Glibc, but the target environment had BPF.

Having own private (and divergent) version headers leads to future problems when BPF definitions evolve.

If the build infrastructure is so old that TC flower is not supported, then the TAP device will build without any flow support.

---
 drivers/net/tap/bpf/bpf_extract.py |   1 -
 drivers/net/tap/meson.build        |  17 ++--
 drivers/net/tap/rte_eth_tap.c      |  38 +++++++--
 drivers/net/tap/rte_eth_tap.h      |   7 +-
 drivers/net/tap/tap_bpf.h          | 121 -----------------------------
 drivers/net/tap/tap_bpf_api.c      |  20 +++--
 drivers/net/tap/tap_bpf_insns.h    |   2 -
 drivers/net/tap/tap_flow.c         |  90 ---------------------
 8 files changed, 60 insertions(+), 236 deletions(-)
 delete mode 100644 drivers/net/tap/tap_bpf.h
drivers/net/tap/bpf/bpf_extract.py +0 -1
index b630c42b80..73c4dafe4e 100644
@@ -65,7 +65,6 @@ def write_header(out, source):
         print(f' * Auto-generated from {source}', file=out)
     print(" * This not the original source file. Do NOT edit it.", file=out)
     print(" */\n", file=out)
-    print("#include <tap_bpf.h>", file=out)
 
 
 def main():
drivers/net/tap/meson.build +9 -8
index 5099ccdff1..66647a1c62 100644
@@ -7,13 +7,19 @@ if not is_linux
 endif
 sources = files(
         'rte_eth_tap.c',
-        'tap_bpf_api.c',
-        'tap_flow.c',
         'tap_intr.c',
         'tap_netlink.c',
-        'tap_tcmsgs.c',
 )
 
+if cc.has_header_symbol('linux/pkt_cls.h', 'TCA_FLOWER_ACT')
+    cflags += '-DHAVE_TCA_FLOWER'
+    sources += files(
+        'tap_bpf_api.c',
+        'tap_flow.c',
+        'tap_tcmsgs.c',
+    )
+endif
+
 deps = ['bus_vdev', 'gso', 'hash']
 
 cflags += '-DTAP_MAX_QUEUES=16'
@@ -23,12 +29,7 @@ cflags += '-DTAP_MAX_QUEUES=16'
 #   "enum/define", "symbol to search" ]
 #
 args = [
-        [ 'HAVE_TC_FLOWER', 'linux/pkt_cls.h', 'TCA_FLOWER_UNSPEC' ],
-        [ 'HAVE_TC_VLAN_ID', 'linux/pkt_cls.h', 'TCA_FLOWER_KEY_VLAN_PRIO' ],
-        [ 'HAVE_TC_BPF', 'linux/pkt_cls.h', 'TCA_BPF_UNSPEC' ],
-        [ 'HAVE_TC_BPF_FD', 'linux/pkt_cls.h', 'TCA_BPF_FD' ],
         [ 'HAVE_TC_ACT_BPF', 'linux/tc_act/tc_bpf.h', 'TCA_ACT_BPF_UNSPEC' ],
-        [ 'HAVE_TC_ACT_BPF_FD', 'linux/tc_act/tc_bpf.h', 'TCA_ACT_BPF_FD' ],
 ]
 config = configuration_data()
 foreach arg:args
drivers/net/tap/rte_eth_tap.c +32 -6
index b84fc01856..9058a47295 100644
@@ -1133,12 +1133,15 @@ tap_dev_close(struct rte_eth_dev *dev)
 
 	if (!internals->persist)
 		tap_link_set_down(dev);
+
+#ifdef HAVE_TCA_FLOWER
 	if (internals->nlsk_fd != -1) {
 		tap_flow_flush(dev, NULL);
 		tap_flow_implicit_flush(internals, NULL);
 		tap_nl_final(internals->nlsk_fd);
 		internals->nlsk_fd = -1;
 	}
+#endif
 
 	for (i = 0; i < RTE_PMD_TAP_MAX_QUEUES; i++) {
 		struct rx_queue *rxq = &internals->rxq[i];
@@ -1261,6 +1264,7 @@ tap_promisc_enable(struct rte_eth_dev *dev)
 	if (ret != 0)
 		return ret;
 
+#ifdef HAVE_TCA_FLOWER
 	if (pmd->remote_if_index && !pmd->flow_isolate) {
 		dev->data->promiscuous = 1;
 		ret = tap_flow_implicit_create(pmd, TAP_REMOTE_PROMISC);
@@ -1274,7 +1278,7 @@ tap_promisc_enable(struct rte_eth_dev *dev)
 			return ret;
 		}
 	}
-
+#endif
 	return 0;
 }
 
@@ -1289,6 +1293,7 @@ tap_promisc_disable(struct rte_eth_dev *dev)
 	if (ret != 0)
 		return ret;
 
+#ifdef HAVE_TCA_FLOWER
 	if (pmd->remote_if_index && !pmd->flow_isolate) {
 		dev->data->promiscuous = 0;
 		ret = tap_flow_implicit_destroy(pmd, TAP_REMOTE_PROMISC);
@@ -1302,6 +1307,7 @@ tap_promisc_disable(struct rte_eth_dev *dev)
 			return ret;
 		}
 	}
+#endif
 
 	return 0;
 }
@@ -1317,6 +1323,7 @@ tap_allmulti_enable(struct rte_eth_dev *dev)
 	if (ret != 0)
 		return ret;
 
+#ifdef HAVE_TCA_FLOWER
 	if (pmd->remote_if_index && !pmd->flow_isolate) {
 		dev->data->all_multicast = 1;
 		ret = tap_flow_implicit_create(pmd, TAP_REMOTE_ALLMULTI);
@@ -1330,6 +1337,7 @@ tap_allmulti_enable(struct rte_eth_dev *dev)
 			return ret;
 		}
 	}
+#endif
 
 	return 0;
 }
@@ -1345,6 +1353,7 @@ tap_allmulti_disable(struct rte_eth_dev *dev)
 	if (ret != 0)
 		return ret;
 
+#ifdef HAVE_TCA_FLOWER
 	if (pmd->remote_if_index && !pmd->flow_isolate) {
 		dev->data->all_multicast = 0;
 		ret = tap_flow_implicit_destroy(pmd, TAP_REMOTE_ALLMULTI);
@@ -1358,6 +1367,7 @@ tap_allmulti_disable(struct rte_eth_dev *dev)
 			return ret;
 		}
 	}
+#endif
 
 	return 0;
 }
@@ -1403,6 +1413,8 @@ tap_mac_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr)
 	if (ret < 0)
 		return ret;
 	rte_memcpy(&pmd->eth_addr, mac_addr, RTE_ETHER_ADDR_LEN);
+
+#ifdef HAVE_TCA_FLOWER
 	if (pmd->remote_if_index && !pmd->flow_isolate) {
 		/* Replace MAC redirection rule after a MAC change */
 		ret = tap_flow_implicit_destroy(pmd, TAP_REMOTE_LOCAL_MAC);
@@ -1420,6 +1432,7 @@ tap_mac_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr)
 			return ret;
 		}
 	}
+#endif
 
 	return 0;
 }
@@ -1894,7 +1907,9 @@ static const struct eth_dev_ops ops = {
 	.stats_reset            = tap_stats_reset,
 	.dev_supported_ptypes_get = tap_dev_supported_ptypes_get,
 	.rss_hash_update        = tap_rss_hash_update,
+#ifdef HAVE_TCA_FLOWER
 	.flow_ops_get           = tap_dev_flow_ops_get,
+#endif
 };
 
 static int
@@ -1934,7 +1949,9 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 	strlcpy(pmd->name, tap_name, sizeof(pmd->name));
 	pmd->type = type;
 	pmd->ka_fd = -1;
+#ifdef HAVE_TCA_FLOWER
 	pmd->nlsk_fd = -1;
+#endif
 	pmd->gso_ctx_mp = NULL;
 
 	pmd->ioctl_sock = socket(AF_INET, SOCK_DGRAM, 0);
@@ -2014,6 +2031,14 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 	/* Make network device persist after application exit */
 	pmd->persist = persist;
 
+	pmd->if_index = if_nametoindex(pmd->name);
+	if (!pmd->if_index) {
+		TAP_LOG(ERR, "%s: failed to get if_index.", pmd->name);
+		goto disable_rte_flow;
+	}
+
+
+#ifdef HAVE_TCA_FLOWER
 	/*
 	 * Set up everything related to rte_flow:
 	 * - netlink socket
@@ -2028,11 +2053,6 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 			pmd->name);
 		goto disable_rte_flow;
 	}
-	pmd->if_index = if_nametoindex(pmd->name);
-	if (!pmd->if_index) {
-		TAP_LOG(ERR, "%s: failed to get if_index.", pmd->name);
-		goto disable_rte_flow;
-	}
 	if (qdisc_create_multiq(pmd->nlsk_fd, pmd->if_index) < 0) {
 		TAP_LOG(ERR, "%s: failed to create multiq qdisc.",
 			pmd->name);
@@ -2043,6 +2063,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 			pmd->name);
 		goto disable_rte_flow;
 	}
+
 	LIST_INIT(&pmd->flows);
 
 	if (strlen(remote_iface)) {
@@ -2095,6 +2116,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 			goto error_remote;
 		}
 	}
+#endif
 
 	rte_eth_dev_probing_finish(dev);
 	return 0;
@@ -2109,14 +2131,18 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 	rte_eth_dev_probing_finish(dev);
 	return 0;
 
+#ifdef HAVE_TCA_FLOWER
 error_remote:
 	TAP_LOG(ERR, " Can't set up remote feature: %s(%d)",
 		strerror(errno), errno);
 	tap_flow_implicit_flush(pmd, NULL);
+#endif
 
 error_exit:
+#ifdef HAVE_TCA_FLOWER
 	if (pmd->nlsk_fd != -1)
 		close(pmd->nlsk_fd);
+#endif
 	if (pmd->ka_fd != -1)
 		close(pmd->ka_fd);
 	if (pmd->ioctl_sock != -1)
drivers/net/tap/rte_eth_tap.h +6 -1
index 1bcf92ce80..af18b29090 100644
@@ -16,6 +16,7 @@
 #include <ethdev_driver.h>
 #include <rte_ether.h>
 #include <rte_gso.h>
+
 #include "tap_log.h"
 
 #ifdef IFF_MULTI_QUEUE
@@ -70,15 +71,17 @@ struct pmd_internals {
 	char remote_iface[RTE_ETH_NAME_MAX_LEN]; /* Remote netdevice name */
 	char name[RTE_ETH_NAME_MAX_LEN];  /* Internal Tap device name */
 	int type;                         /* Type field - TUN|TAP */
+	int persist;			  /* 1 if keep link up, else 0 */
 	struct rte_ether_addr eth_addr;   /* Mac address of the device port */
 	struct ifreq remote_initial_flags;/* Remote netdevice flags on init */
 	int remote_if_index;              /* remote netdevice IF_INDEX */
 	int if_index;                     /* IF_INDEX for the port */
 	int ioctl_sock;                   /* socket for ioctl calls */
+
+#ifdef HAVE_TCA_FLOWER
 	int nlsk_fd;                      /* Netlink socket fd */
 	int flow_isolate;                 /* 1 if flow isolation is enabled */
 	int rss_enabled;                  /* 1 if RSS is enabled, else 0 */
-	int persist;			  /* 1 if keep link up, else 0 */
 	/* implicit rules set when RSS is enabled */
 	int map_fd;                       /* BPF RSS map fd */
 	int bpf_fd[RTE_PMD_TAP_MAX_QUEUES];/* List of bpf fds per queue */
@@ -86,6 +89,8 @@ struct pmd_internals {
 	LIST_HEAD(tap_flows, rte_flow) flows;        /* rte_flow rules */
 	/* implicit rte_flow rules set when a remote device is active */
 	LIST_HEAD(tap_implicit_flows, rte_flow) implicit_flows;
+#endif
+
 	struct rx_queue rxq[RTE_PMD_TAP_MAX_QUEUES]; /* List of RX queues */
 	struct tx_queue txq[RTE_PMD_TAP_MAX_QUEUES]; /* List of TX queues */
 	struct rte_intr_handle *intr_handle;         /* LSC interrupt handle. */
drivers/net/tap/tap_bpf.h deleted +0 -121

121 lines not on this page · raw message

drivers/net/tap/tap_bpf_api.c +13 -7
index 15283f8917..9e05e2ddf1 100644
@@ -2,19 +2,19 @@
  * Copyright 2017 Mellanox Technologies, Ltd
  */
 
-#include <errno.h>
-#include <string.h>
 #include <unistd.h>
-#include <sys/queue.h>
+#include <syscall.h>
+#include <linux/bpf.h>
 
-#include <rte_malloc.h>
-#include <rte_eth_tap.h>
 #include <tap_flow.h>
 #include <tap_autoconf.h>
-#include <tap_tcmsgs.h>
-#include <tap_bpf.h>
+
 #include <tap_bpf_insns.h>
 
+
+static int bpf_load(enum bpf_prog_type type, const struct bpf_insn *insns,
+		size_t insns_cnt, const char *license);
+
 /**
  * Load BPF program (section cls_q) into the kernel and return a bpf fd
  *
@@ -89,7 +89,13 @@ static inline __u64 ptr_to_u64(const void *ptr)
 static inline int sys_bpf(enum bpf_cmd cmd, union bpf_attr *attr,
 			unsigned int size)
 {
+#ifdef __NR_bpf
 	return syscall(__NR_bpf, cmd, attr, size);
+#else
+	TAP_LOG(ERR, "No bpf syscall, kernel headers too old?\n");
+	errno = ENOSYS;
+	return -1;
+#endif
 }
 
 /**
drivers/net/tap/tap_bpf_insns.h +0 -2
index 53fa76c4e6..cdf2febf05 100644
@@ -3,8 +3,6 @@
  * This not the original source file. Do NOT edit it.
  */
 
-#include <tap_bpf.h>
-
 static struct bpf_insn cls_q_insns[] = {
 	{0x61,    2,    1,       52, 0x00000000},
 	{0x18,    3,    0,        0, 0xdeadbeef},
drivers/net/tap/tap_flow.c +0 -90

96 lines not on this page · raw message

Signature · 1 line
2.43.0
#168 lore raw

PATCH v13 6/11 net/tap: rewrite the RSS BPF program

In reply to Stephen Hemminger

Rewrite of the BPF program used to do queue based RSS.

Important changes:
- uses newer BPF map format BTF
- accepts key as parameter rather than constant default
- can do L3 or L4 hashing
- supports IPv4 options
- supports IPv6 extension headers
- restructured for readability

The usage of BPF is different as well:
- the incoming configuration is looked up based on class parameters rather than patching the BPF code.
- the resulting queue is placed in skb by using skb mark than requiring a second pass through classifier step.

Note: This version only works with later patch to enable it on the DPDK driver side. It is submitted as an incremental patch to allow for easier review. Bisection still works because the old instruction are still present for now.

---
 .gitignore                            |   3 -
 drivers/net/tap/bpf/Makefile          |  19 --
 drivers/net/tap/bpf/README            |  49 +++++
 drivers/net/tap/bpf/bpf_api.h         | 276 --------------------------
 drivers/net/tap/bpf/bpf_elf.h         |  53 -----
 drivers/net/tap/bpf/bpf_extract.py    |  85 --------
 drivers/net/tap/bpf/meson.build       |  81 ++++++++
 drivers/net/tap/bpf/tap_bpf_program.c | 255 ------------------------
 drivers/net/tap/bpf/tap_rss.c         | 267 +++++++++++++++++++++++++
 9 files changed, 397 insertions(+), 691 deletions(-)
 delete mode 100644 drivers/net/tap/bpf/Makefile
 create mode 100644 drivers/net/tap/bpf/README
 delete mode 100644 drivers/net/tap/bpf/bpf_api.h
 delete mode 100644 drivers/net/tap/bpf/bpf_elf.h
 delete mode 100644 drivers/net/tap/bpf/bpf_extract.py
 create mode 100644 drivers/net/tap/bpf/meson.build
 delete mode 100644 drivers/net/tap/bpf/tap_bpf_program.c
 create mode 100644 drivers/net/tap/bpf/tap_rss.c
.gitignore +0 -3
index 3f444dcace..01a47a7606 100644
@@ -36,9 +36,6 @@ TAGS
 # ignore python bytecode files
 *.pyc
 
-# ignore BPF programs
-drivers/net/tap/bpf/tap_bpf_program.o
-
 # DTS results
 dts/output
 
drivers/net/tap/bpf/Makefile deleted +0 -19
deleted file mode 100644
index 9efeeb1bc7..0000000000
@@ -1,19 +0,0 @@
-# SPDX-License-Identifier: BSD-3-Clause
-# This file is not built as part of normal DPDK build.
-# It is used to generate the eBPF code for TAP RSS.
-
-CLANG=clang
-CLANG_OPTS=-O2
-TARGET=../tap_bpf_insns.h
-
-all: $(TARGET)
-
-clean:
-	rm tap_bpf_program.o $(TARGET)
-
-tap_bpf_program.o: tap_bpf_program.c
-	$(CLANG) $(CLANG_OPTS) -emit-llvm -c $< -o - | \
-	llc -march=bpf -filetype=obj -o $@
-
-$(TARGET): tap_bpf_program.o
-	python3 bpf_extract.py -stap_bpf_program.c -o $@ $<
drivers/net/tap/bpf/README new file +49 -0

49 lines not on this page · raw message

drivers/net/tap/bpf/bpf_api.h deleted +0 -276

276 lines not on this page · raw message

drivers/net/tap/bpf/bpf_elf.h deleted +0 -53

53 lines not on this page · raw message

drivers/net/tap/bpf/bpf_extract.py deleted +0 -85

85 lines not on this page · raw message

drivers/net/tap/bpf/meson.build new file +81 -0

81 lines not on this page · raw message

drivers/net/tap/bpf/tap_bpf_program.c deleted +0 -255

255 lines not on this page · raw message

drivers/net/tap/bpf/tap_rss.c new file +267 -0

267 lines not on this page · raw message

Signature · 1 line
2.43.0
#169 lore raw

PATCH v13 7/11 net/tap: use libbpf to load new BPF program

In reply to Stephen Hemminger

There were multiple issues in the RSS queue support in the TAP driver. This required extensive rework of the BPF support.

Change the BPF loading to use bpftool to
create a skeleton header file, and load with libbpf. The BPF is always compiled from source so less chance that source and instructions diverge. Also resolves issue where libbpf and source get out of sync. The program
is only loaded once, so if multiple rules are created only one BPF program is loaded in kernel.

The new BPF program only needs a single action.
No need for action and re-classification step.

It also fixes the missing bits from the original.
- supports setting RSS key per flow
- level of hash can be L3 or L3/L4.

Bugzilla ID: 1329

---
 doc/guides/rel_notes/release_24_07.rst |   3 +
 drivers/net/tap/bpf/meson.build        |  36 ++-
 drivers/net/tap/meson.build            |  35 +--
 drivers/net/tap/rte_eth_tap.c          |  14 +-
 drivers/net/tap/rte_eth_tap.h          |   6 +-
 drivers/net/tap/tap_flow.c             | 416 ++++++-------------------
 drivers/net/tap/tap_flow.h             |  17 +-
 drivers/net/tap/tap_rss.h              |  10 +-
 drivers/net/tap/tap_tcmsgs.h           |   4 +-
 9 files changed, 168 insertions(+), 373 deletions(-)
doc/guides/rel_notes/release_24_07.rst +3 -0
index fa9692924b..77562bbe3e 100644
@@ -59,6 +59,9 @@ New Features
 
   * Updated to support up to 8 queues when used by secondary process.
 
+  * Fixed support of RSS flow action to work with current Linux
+    kernels and BPF tooling. Will only be enabled if clang, libbpf 1.0
+    and bpftool are available.
 
 Removed Items
 -------------
drivers/net/tap/bpf/meson.build +31 -5
index f2c03a19fd..45e8c3b498 100644
@@ -1,17 +1,26 @@
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright 2024 Stephen Hemminger <[email protected]>
 
-enable_tap_rss = false
-
-libbpf = dependency('libbpf', required: false, method: 'pkg-config')
+# Loading BPF requires libbpf
+# and the bpf_map__XXX API's were introduced in 0.8.0
+libbpf = dependency('libbpf', version: '>= 1.0',
+                    required: false, method: 'pkg-config')
 if not libbpf.found()
     message('net/tap: no RSS support missing libbpf')
     subdir_done()
 endif
 
+# Making skeleton needs bpftool
 # Debian install this in /usr/sbin which is not in $PATH
-bpftool = find_program('bpftool', '/usr/sbin/bpftool', required: false, version: '>= 5.6.0')
-if not bpftool.found()
+bpftool_supports_skel = false
+bpftool = find_program('bpftool', '/usr/sbin/bpftool', required: false)
+if bpftool.found()
+    # Some Ubuntu versions have non-functional bpftool
+    bpftool_supports_skel = run_command(bpftool, 'gen', 'help',
+                                        check:false).returncode() == 0
+endif
+
+if not bpftool_supports_skel
     message('net/tap: no RSS support missing bpftool')
     subdir_done()
 endif
@@ -42,6 +51,7 @@ clang_flags = [
     '-O2',
     '-Wall',
     '-Wextra',
+    max_queues,
     '-target',
     'bpf',
     '-g',
@@ -67,6 +77,22 @@ skel_h_cmd = [
     '@INPUT@'
 ]
 
+vmlinux_h_cmd = [
+    bpftool,
+    'btf',
+    'dump',
+    'file',
+    '/sys/kernel/btf/vmlinux',
+    'format',
+    'c'
+]
+
+vmlinux_h = custom_target(
+    'vmlinux.h',
+    output: 'vmlinux.h',
+    command: vmlinux_h_cmd,
+    capture: true)
+
 tap_rss_o = custom_target(
     'tap_rss.bpf.o',
     input: 'tap_rss.c',
drivers/net/tap/meson.build +16 -19
index 66647a1c62..26074059fa 100644
@@ -5,36 +5,33 @@ if not is_linux
     build = false
     reason = 'only supported on Linux'
 endif
+
 sources = files(
         'rte_eth_tap.c',
         'tap_intr.c',
         'tap_netlink.c',
 )
 
+deps = ['bus_vdev', 'gso', 'hash']
+
+max_queues = '-DTAP_MAX_QUEUES=16'
+cflags += max_queues
+
+require_iova_in_mbuf = false
+
 if cc.has_header_symbol('linux/pkt_cls.h', 'TCA_FLOWER_ACT')
     cflags += '-DHAVE_TCA_FLOWER'
     sources += files(
-        'tap_bpf_api.c',
         'tap_flow.c',
         'tap_tcmsgs.c',
     )
-endif
-
-deps = ['bus_vdev', 'gso', 'hash']
 
-cflags += '-DTAP_MAX_QUEUES=16'
-
-# input array for meson symbol search:
-# [ "MACRO to define if found", "header for the search",
-#   "enum/define", "symbol to search" ]
-#
-args = [
-        [ 'HAVE_TC_ACT_BPF', 'linux/tc_act/tc_bpf.h', 'TCA_ACT_BPF_UNSPEC' ],
-]
-config = configuration_data()
-foreach arg:args
-    config.set(arg[0], cc.has_header_symbol(arg[1], arg[2]))
-endforeach
-configure_file(output : 'tap_autoconf.h', configuration : config)
+    enable_tap_rss = false
 
-require_iova_in_mbuf = false
+    subdir('bpf')
+    if enable_tap_rss
+        cflags += '-DHAVE_BPF_RSS'
+        ext_deps += libbpf
+        sources += tap_rss_skel_h
+    endif
+endif
drivers/net/tap/rte_eth_tap.c +7 -7
index 9058a47295..d847565073 100644
@@ -1140,6 +1140,7 @@ tap_dev_close(struct rte_eth_dev *dev)
 		tap_flow_implicit_flush(internals, NULL);
 		tap_nl_final(internals->nlsk_fd);
 		internals->nlsk_fd = -1;
+		tap_flow_bpf_destroy(internals);
 	}
 #endif
 
@@ -1949,6 +1950,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 	strlcpy(pmd->name, tap_name, sizeof(pmd->name));
 	pmd->type = type;
 	pmd->ka_fd = -1;
+
 #ifdef HAVE_TCA_FLOWER
 	pmd->nlsk_fd = -1;
 #endif
@@ -2031,13 +2033,6 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 	/* Make network device persist after application exit */
 	pmd->persist = persist;
 
-	pmd->if_index = if_nametoindex(pmd->name);
-	if (!pmd->if_index) {
-		TAP_LOG(ERR, "%s: failed to get if_index.", pmd->name);
-		goto disable_rte_flow;
-	}
-
-
 #ifdef HAVE_TCA_FLOWER
 	/*
 	 * Set up everything related to rte_flow:
@@ -2053,6 +2048,11 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 			pmd->name);
 		goto disable_rte_flow;
 	}
+	pmd->if_index = if_nametoindex(pmd->name);
+	if (!pmd->if_index) {
+		TAP_LOG(ERR, "%s: failed to get if_index.", pmd->name);
+		goto disable_rte_flow;
+	}
 	if (qdisc_create_multiq(pmd->nlsk_fd, pmd->if_index) < 0) {
 		TAP_LOG(ERR, "%s: failed to create multiq qdisc.",
 			pmd->name);
drivers/net/tap/rte_eth_tap.h +2 -4
index af18b29090..ce4322ad04 100644
@@ -81,10 +81,8 @@ struct pmd_internals {
 #ifdef HAVE_TCA_FLOWER
 	int nlsk_fd;                      /* Netlink socket fd */
 	int flow_isolate;                 /* 1 if flow isolation is enabled */
-	int rss_enabled;                  /* 1 if RSS is enabled, else 0 */
-	/* implicit rules set when RSS is enabled */
-	int map_fd;                       /* BPF RSS map fd */
-	int bpf_fd[RTE_PMD_TAP_MAX_QUEUES];/* List of bpf fds per queue */
+
+	struct tap_rss *rss;		  /* BPF program */
 
 	LIST_HEAD(tap_flows, rte_flow) flows;        /* rte_flow rules */
 	/* implicit rte_flow rules set when a remote device is active */
drivers/net/tap/tap_flow.c +97 -319

555 lines not on this page · raw message

drivers/net/tap/tap_flow.h +6 -11
index 240fbc3dfa..8b19347a93 100644
@@ -9,7 +9,11 @@
 #include <rte_flow.h>
 #include <rte_flow_driver.h>
 #include <rte_eth_tap.h>
-#include <tap_autoconf.h>
+
+/**
+ * Mask of unsupported RSS types
+ */
+#define TAP_RSS_HF_MASK (~(RTE_ETH_RSS_IP | RTE_ETH_RSS_UDP | RTE_ETH_RSS_TCP))
 
 /**
  * In TC, priority 0 means we require the kernel to allocate one for us.
@@ -41,11 +45,6 @@ enum implicit_rule_index {
 	TAP_REMOTE_MAX_IDX,
 };
 
-enum bpf_fd_idx {
-	SEC_L3_L4,
-	SEC_MAX,
-};
-
 int tap_dev_flow_ops_get(struct rte_eth_dev *dev,
 			 const struct rte_flow_ops **ops);
 int tap_flow_flush(struct rte_eth_dev *dev, struct rte_flow_error *error);
@@ -57,10 +56,6 @@ int tap_flow_implicit_destroy(struct pmd_internals *pmd,
 int tap_flow_implicit_flush(struct pmd_internals *pmd,
 			    struct rte_flow_error *error);
 
-int tap_flow_bpf_cls_q(__u32 queue_idx);
-int tap_flow_bpf_calc_l3_l4_hash(__u32 key_idx, int map_fd);
-int tap_flow_bpf_rss_map_create(unsigned int key_size, unsigned int value_size,
-			unsigned int max_entries);
-int tap_flow_bpf_update_rss_elem(int fd, void *key, void *value);
+void tap_flow_bpf_destroy(struct pmd_internals *pmd);
 
 #endif /* _TAP_FLOW_H_ */
drivers/net/tap/tap_rss.h +4 -6
index 6009be7031..65bd8991b1 100644
@@ -5,16 +5,14 @@
 #ifndef _TAP_RSS_H_
 #define _TAP_RSS_H_
 
-#ifndef TAP_MAX_QUEUES
-#define TAP_MAX_QUEUES 16
+/* Size of the map from BPF classid to queue table */
+#ifndef TAP_RSS_MAX
+#define TAP_RSS_MAX	32
 #endif
 
-/* Fixed RSS hash key size in bytes. */
+/* Standard Toeplitz hash key size */
 #define TAP_RSS_HASH_KEY_SIZE 40
 
-/* Supported RSS */
-#define TAP_RSS_HF_MASK (~(RTE_ETH_RSS_IP | RTE_ETH_RSS_UDP | RTE_ETH_RSS_TCP))
-
 /* hashed fields for RSS */
 enum hash_field {
 	HASH_FIELD_IPV4_L3,	/* IPv4 src/dst addr */
drivers/net/tap/tap_tcmsgs.h +2 -2
index a64cb29d6f..9411626661 100644
@@ -6,7 +6,6 @@
 #ifndef _TAP_TCMSGS_H_
 #define _TAP_TCMSGS_H_
 
-#include <tap_autoconf.h>
 #include <linux/if_ether.h>
 #include <linux/rtnetlink.h>
 #include <linux/pkt_sched.h>
@@ -14,9 +13,10 @@
 #include <linux/tc_act/tc_mirred.h>
 #include <linux/tc_act/tc_gact.h>
 #include <linux/tc_act/tc_skbedit.h>
-#ifdef HAVE_TC_ACT_BPF
+#ifdef HAVE_BPF_RSS
 #include <linux/tc_act/tc_bpf.h>
 #endif
+
 #include <inttypes.h>
 
 #include <rte_ether.h>
Signature · 1 line
2.43.0
#170 lore raw

PATCH v13 8/11 net/tap: remove no longer used files

In reply to Stephen Hemminger

The BPF api was replaced by use of libbpf. And the BPF instruction header is replaced by the new tap_rss.skel.h which is generated via bpftool.

---
 drivers/net/tap/tap_bpf_api.c   |  196 ----
 drivers/net/tap/tap_bpf_insns.h | 1741 -------------------------------
 2 files changed, 1937 deletions(-)
 delete mode 100644 drivers/net/tap/tap_bpf_api.c
 delete mode 100644 drivers/net/tap/tap_bpf_insns.h
drivers/net/tap/tap_bpf_api.c deleted +0 -196
deleted file mode 100644
index 9e05e2ddf1..0000000000
@@ -1,196 +0,0 @@
-/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright 2017 Mellanox Technologies, Ltd
- */
-
-#include <unistd.h>
-#include <syscall.h>
-#include <linux/bpf.h>
-
-#include <tap_flow.h>
-#include <tap_autoconf.h>
-
-#include <tap_bpf_insns.h>
-
-
-static int bpf_load(enum bpf_prog_type type, const struct bpf_insn *insns,
-		size_t insns_cnt, const char *license);
-
-/**
- * Load BPF program (section cls_q) into the kernel and return a bpf fd
- *
- * @param queue_idx
- *   Queue index matching packet cb
- *
- * @return
- *   -1 if the BPF program couldn't be loaded. An fd (int) otherwise.
- */
-int tap_flow_bpf_cls_q(__u32 queue_idx)
-{
-	cls_q_insns[1].imm = queue_idx;
-
-	return bpf_load(BPF_PROG_TYPE_SCHED_CLS,
-		(struct bpf_insn *)cls_q_insns,
-		RTE_DIM(cls_q_insns),
-		"Dual BSD/GPL");
-}
-
-/**
- * Load BPF program (section l3_l4) into the kernel and return a bpf fd.
- *
- * @param[in] key_idx
- *   RSS MAP key index
- *
- * @param[in] map_fd
- *   BPF RSS map file descriptor
- *
- * @return
- *   -1 if the BPF program couldn't be loaded. An fd (int) otherwise.
- */
-int tap_flow_bpf_calc_l3_l4_hash(__u32 key_idx, int map_fd)
-{
-	l3_l4_hash_insns[4].imm = key_idx;
-	l3_l4_hash_insns[9].imm = map_fd;
-
-	return bpf_load(BPF_PROG_TYPE_SCHED_ACT,
-		(struct bpf_insn *)l3_l4_hash_insns,
-		RTE_DIM(l3_l4_hash_insns),
-		"Dual BSD/GPL");
-}
-
-/**
- * Helper function to convert a pointer to unsigned 64 bits
- *
- * @param[in] ptr
- *   pointer to address
- *
- * @return
- *   64 bit unsigned long type of pointer address
- */
-static inline __u64 ptr_to_u64(const void *ptr)
-{
-	return (__u64)(unsigned long)ptr;
-}
-
-/**
- * Call BPF system call
- *
- * @param[in] cmd
- *   BPF command for program loading, map creation, map entry update, etc
- *
- * @param[in] attr
- *   System call attributes relevant to system call command
- *
- * @param[in] size
- *   size of attr parameter
- *
- * @return
- *   -1 if BPF system call failed, 0 otherwise
- */
-static inline int sys_bpf(enum bpf_cmd cmd, union bpf_attr *attr,
-			unsigned int size)
-{
-#ifdef __NR_bpf
-	return syscall(__NR_bpf, cmd, attr, size);
-#else
-	TAP_LOG(ERR, "No bpf syscall, kernel headers too old?\n");
-	errno = ENOSYS;
-	return -1;
-#endif
-}
-
-/**
- * Load BPF instructions to kernel
- *
- * @param[in] type
- *   BPF program type: classifier or action
- *
- * @param[in] insns
- *   Array of BPF instructions (equivalent to BPF instructions)
- *
- * @param[in] insns_cnt
- *   Number of BPF instructions (size of array)
- *
- * @param[in] license
- *   License string that must be acknowledged by the kernel
- *
- * @return
- *   -1 if the BPF program couldn't be loaded, fd (file descriptor) otherwise
- */
-static int bpf_load(enum bpf_prog_type type,
-		  const struct bpf_insn *insns,
-		  size_t insns_cnt,
-		  const char *license)
-{
-	union bpf_attr attr = {};
-
-	bzero(&attr, sizeof(attr));
-	attr.prog_type = type;
-	attr.insn_cnt = (__u32)insns_cnt;
-	attr.insns = ptr_to_u64(insns);
-	attr.license = ptr_to_u64(license);
-	attr.log_buf = ptr_to_u64(NULL);
-	attr.log_level = 0;
-	attr.kern_version = 0;
-
-	return sys_bpf(BPF_PROG_LOAD, &attr, sizeof(attr));
-}
-
-/**
- * Create BPF map for RSS rules
- *
- * @param[in] key_size
- *   map RSS key size
- *
- * @param[in] value_size
- *   Map RSS value size
- *
- * @param[in] max_entries
- *   Map max number of RSS entries (limit on max RSS rules)
- *
- * @return
- *   -1 if BPF map couldn't be created, map fd otherwise
- */
-int tap_flow_bpf_rss_map_create(unsigned int key_size,
-		unsigned int value_size,
-		unsigned int max_entries)
-{
-	union bpf_attr attr = {};
-
-	bzero(&attr, sizeof(attr));
-	attr.map_type    = BPF_MAP_TYPE_HASH;
-	attr.key_size    = key_size;
-	attr.value_size  = value_size;
-	attr.max_entries = max_entries;
-
-	return sys_bpf(BPF_MAP_CREATE, &attr, sizeof(attr));
-}
-
-/**
- * Update RSS entry in BPF map
- *
- * @param[in] fd
- *   RSS map fd
- *
- * @param[in] key
- *   Pointer to RSS key whose entry is updated
- *
- * @param[in] value
- *   Pointer to RSS new updated value
- *
- * @return
- *   -1 if RSS entry failed to be updated, 0 otherwise
- */
-int tap_flow_bpf_update_rss_elem(int fd, void *key, void *value)
-{
-	union bpf_attr attr = {};
-
-	bzero(&attr, sizeof(attr));
-
-	attr.map_type = BPF_MAP_TYPE_HASH;
-	attr.map_fd = fd;
-	attr.key = ptr_to_u64(key);
-	attr.value = ptr_to_u64(value);
-	attr.flags = BPF_ANY;
-
-	return sys_bpf(BPF_MAP_UPDATE_ELEM, &attr, sizeof(attr));
-}
drivers/net/tap/tap_bpf_insns.h deleted +0 -1741

1,741 lines not on this page · raw message

Signature · 1 line
2.43.0
#171 lore raw

PATCH v13 9/11 net/tap: simplify internals

In reply to Stephen Hemminger

The names of Linux network devices are IFNAMSIZ(16) not the same as DPDK which has up to 64 characters. Don't need to hold onto the whole ifreq to save the remote interface flags.

Make sure packet and byte counters are read once, so that global and per-queue values add up. No need for separate rx_nombuf counter since there is an alloc_failed value in ethdev.

Keep only the statistics that are used. I.e no ipackets on tx queues etc.

---
 drivers/net/tap/rte_eth_tap.c | 138 ++++++++++++++++++----------------
 drivers/net/tap/rte_eth_tap.h |  22 +++---
 2 files changed, 83 insertions(+), 77 deletions(-)
drivers/net/tap/rte_eth_tap.c +74 -64
index d847565073..3614aaf1dc 100644
@@ -46,6 +46,11 @@
 #include <tap_netlink.h>
 #include <tap_tcmsgs.h>
 
+/* Used to snapshot statistics */
+#ifndef READ_ONCE
+#define READ_ONCE(var) (*((volatile typeof(var) *)(&(var))))
+#endif
+
 /* Linux based path to the TUN device */
 #define TUN_TAP_DEV_PATH        "/dev/net/tun"
 #define DEFAULT_TAP_NAME        "dtap"
@@ -212,7 +217,7 @@ tun_alloc(struct pmd_internals *pmd, int is_keepalive, int persistent)
 	 * and need to find the resulting device.
 	 */
 	TAP_LOG(DEBUG, "Device name is '%s'", ifr.ifr_name);
-	strlcpy(pmd->name, ifr.ifr_name, RTE_ETH_NAME_MAX_LEN);
+	strlcpy(pmd->name, ifr.ifr_name, IFNAMSIZ);
 
 	if (is_keepalive) {
 		/*
@@ -454,7 +459,7 @@ pmd_rx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 
 		/* Packet couldn't fit in the provided mbuf */
 		if (unlikely(rxq->pi.flags & TUN_PKT_STRIP)) {
-			rxq->stats.ierrors++;
+			rxq->stats.errors++;
 			continue;
 		}
 
@@ -466,7 +471,8 @@ pmd_rx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 			struct rte_mbuf *buf = rte_pktmbuf_alloc(rxq->mp);
 
 			if (unlikely(!buf)) {
-				rxq->stats.rx_nombuf++;
+				rte_eth_devices[rxq->in_port].data->rx_mbuf_alloc_failed++;
+
 				/* No new buf has been allocated: do nothing */
 				if (!new_tail || !seg)
 					goto end;
@@ -511,8 +517,8 @@ pmd_rx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 		num_rx_bytes += mbuf->pkt_len;
 	}
 end:
-	rxq->stats.ipackets += num_rx;
-	rxq->stats.ibytes += num_rx_bytes;
+	rxq->stats.packets += num_rx;
+	rxq->stats.bytes += num_rx_bytes;
 
 	if (trigger && num_rx < nb_pkts)
 		rxq->trigger_seen = trigger;
@@ -692,7 +698,7 @@ pmd_tx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 			tso_segsz = mbuf_in->tso_segsz + hdrs_len;
 			if (unlikely(tso_segsz == hdrs_len) ||
 				tso_segsz > *txq->mtu) {
-				txq->stats.errs++;
+				txq->stats.errors++;
 				break;
 			}
 			gso_ctx->gso_size = tso_segsz;
@@ -730,7 +736,7 @@ pmd_tx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 		ret = tap_write_mbufs(txq, num_mbufs, mbuf,
 				&num_packets, &num_tx_bytes);
 		if (ret == -1) {
-			txq->stats.errs++;
+			txq->stats.errors++;
 			/* free tso mbufs */
 			if (num_tso_mbufs > 0)
 				rte_pktmbuf_free_bulk(mbuf, num_tso_mbufs);
@@ -748,9 +754,8 @@ pmd_tx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 		}
 	}
 
-	txq->stats.opackets += num_packets;
-	txq->stats.errs += nb_pkts - num_tx;
-	txq->stats.obytes += num_tx_bytes;
+	txq->stats.packets += num_packets;
+	txq->stats.bytes += num_tx_bytes;
 
 	return num_tx;
 }
@@ -1047,43 +1052,44 @@ tap_dev_info(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 static int
 tap_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *tap_stats)
 {
-	unsigned int i, imax;
-	unsigned long rx_total = 0, tx_total = 0, tx_err_total = 0;
-	unsigned long rx_bytes_total = 0, tx_bytes_total = 0;
-	unsigned long rx_nombuf = 0, ierrors = 0;
+	unsigned int i;
 	const struct pmd_internals *pmd = dev->data->dev_private;
+	uint64_t bytes, packets;
 
 	/* rx queue statistics */
-	imax = (dev->data->nb_rx_queues < RTE_ETHDEV_QUEUE_STAT_CNTRS) ?
-		dev->data->nb_rx_queues : RTE_ETHDEV_QUEUE_STAT_CNTRS;
-	for (i = 0; i < imax; i++) {
-		tap_stats->q_ipackets[i] = pmd->rxq[i].stats.ipackets;
-		tap_stats->q_ibytes[i] = pmd->rxq[i].stats.ibytes;
-		rx_total += tap_stats->q_ipackets[i];
-		rx_bytes_total += tap_stats->q_ibytes[i];
-		rx_nombuf += pmd->rxq[i].stats.rx_nombuf;
-		ierrors += pmd->rxq[i].stats.ierrors;
+	for (i = 0; i < dev->data->nb_rx_queues; i++) {
+		const struct rx_queue *rxq = &pmd->rxq[i];
+
+		packets = READ_ONCE(rxq->stats.packets);
+		bytes = READ_ONCE(rxq->stats.bytes);
+
+		tap_stats->ipackets += packets;
+		tap_stats->ibytes += bytes;
+		tap_stats->ierrors += rxq->stats.errors;
+
+		if (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) {
+			tap_stats->q_ipackets[i] = packets;
+			tap_stats->q_ibytes[i] = bytes;
+		}
 	}
 
 	/* tx queue statistics */
-	imax = (dev->data->nb_tx_queues < RTE_ETHDEV_QUEUE_STAT_CNTRS) ?
-		dev->data->nb_tx_queues : RTE_ETHDEV_QUEUE_STAT_CNTRS;
-
-	for (i = 0; i < imax; i++) {
-		tap_stats->q_opackets[i] = pmd->txq[i].stats.opackets;
-		tap_stats->q_obytes[i] = pmd->txq[i].stats.obytes;
-		tx_total += tap_stats->q_opackets[i];
-		tx_err_total += pmd->txq[i].stats.errs;
-		tx_bytes_total += tap_stats->q_obytes[i];
-	}
-
-	tap_stats->ipackets = rx_total;
-	tap_stats->ibytes = rx_bytes_total;
-	tap_stats->ierrors = ierrors;
-	tap_stats->rx_nombuf = rx_nombuf;
-	tap_stats->opackets = tx_total;
-	tap_stats->oerrors = tx_err_total;
-	tap_stats->obytes = tx_bytes_total;
+	for (i = 0; i < dev->data->nb_tx_queues; i++) {
+		const struct tx_queue *txq = &pmd->txq[i];
+
+		packets = READ_ONCE(txq->stats.packets);
+		bytes = READ_ONCE(txq->stats.bytes);
+
+		tap_stats->opackets += packets;
+		tap_stats->obytes += bytes;
+		tap_stats->oerrors += txq->stats.errors;
+
+		if (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) {
+			tap_stats->q_opackets[i] = packets;
+			tap_stats->q_obytes[i] = bytes;
+		}
+	}
+
 	return 0;
 }
 
@@ -1094,14 +1100,8 @@ tap_stats_reset(struct rte_eth_dev *dev)
 	struct pmd_internals *pmd = dev->data->dev_private;
 
 	for (i = 0; i < RTE_PMD_TAP_MAX_QUEUES; i++) {
-		pmd->rxq[i].stats.ipackets = 0;
-		pmd->rxq[i].stats.ibytes = 0;
-		pmd->rxq[i].stats.ierrors = 0;
-		pmd->rxq[i].stats.rx_nombuf = 0;
-
-		pmd->txq[i].stats.opackets = 0;
-		pmd->txq[i].stats.errs = 0;
-		pmd->txq[i].stats.obytes = 0;
+		memset(&pmd->rxq[i].stats, 0, sizeof(struct pkt_stats));
+		memset(&pmd->txq[i].stats, 0, sizeof(struct pkt_stats));
 	}
 
 	return 0;
@@ -1156,9 +1156,13 @@ tap_dev_close(struct rte_eth_dev *dev)
 	}
 
 	if (internals->remote_if_index) {
+		struct ifreq remote_ifr;
+
+		strlcpy(remote_ifr.ifr_name, internals->remote_iface, IFNAMSIZ);
+		remote_ifr.ifr_flags = internals->remote_flags;
+
 		/* Restore initial remote state */
-		int ret = ioctl(internals->ioctl_sock, SIOCSIFFLAGS,
-				&internals->remote_initial_flags);
+		int ret = ioctl(internals->ioctl_sock, SIOCSIFFLAGS, &remote_ifr);
 		if (ret)
 			TAP_LOG(ERR, "restore remote state failed: %d", ret);
 
@@ -2067,16 +2071,22 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 	LIST_INIT(&pmd->flows);
 
 	if (strlen(remote_iface)) {
+		struct ifreq remote_ifr;
+
 		pmd->remote_if_index = if_nametoindex(remote_iface);
 		if (!pmd->remote_if_index) {
 			TAP_LOG(ERR, "%s: failed to get %s if_index.",
 				pmd->name, remote_iface);
 			goto error_remote;
 		}
-		strlcpy(pmd->remote_iface, remote_iface, RTE_ETH_NAME_MAX_LEN);
+		strlcpy(pmd->remote_iface, remote_iface, IFNAMSIZ);
+
+		memset(&remote_ifr, 0, sizeof(ifr));
+		strlcpy(remote_ifr.ifr_name, remote_iface, IFNAMSIZ);
 
 		/* Save state of remote device */
-		tap_ioctl(pmd, SIOCGIFFLAGS, &pmd->remote_initial_flags, 0, REMOTE_ONLY);
+		tap_ioctl(pmd, SIOCGIFFLAGS, &remote_ifr, 0, REMOTE_ONLY);
+		pmd->remote_flags = remote_ifr.ifr_flags;
 
 		/* Replicate remote MAC address */
 		if (tap_ioctl(pmd, SIOCGIFHWADDR, &ifr, 0, REMOTE_ONLY) < 0) {
@@ -2190,10 +2200,10 @@ set_interface_name(const char *key __rte_unused,
 				value);
 			return -1;
 		}
-		strlcpy(name, value, RTE_ETH_NAME_MAX_LEN);
+		strlcpy(name, value, IFNAMSIZ);
 	} else {
 		/* use tap%d which causes kernel to choose next available */
-		strlcpy(name, DEFAULT_TAP_NAME "%d", RTE_ETH_NAME_MAX_LEN);
+		strlcpy(name, DEFAULT_TAP_NAME "%d", IFNAMSIZ);
 	}
 	return 0;
 }
@@ -2211,7 +2221,7 @@ set_remote_iface(const char *key __rte_unused,
 				value);
 			return -1;
 		}
-		strlcpy(name, value, RTE_ETH_NAME_MAX_LEN);
+		strlcpy(name, value, IFNAMSIZ);
 	}
 
 	return 0;
@@ -2262,13 +2272,13 @@ rte_pmd_tun_probe(struct rte_vdev_device *dev)
 	const char *name, *params;
 	int ret;
 	struct rte_kvargs *kvlist = NULL;
-	char tun_name[RTE_ETH_NAME_MAX_LEN];
-	char remote_iface[RTE_ETH_NAME_MAX_LEN];
+	char tun_name[IFNAMSIZ];
+	char remote_iface[IFNAMSIZ];
 	struct rte_eth_dev *eth_dev;
 
 	name = rte_vdev_device_name(dev);
 	params = rte_vdev_device_args(dev);
-	memset(remote_iface, 0, RTE_ETH_NAME_MAX_LEN);
+	memset(remote_iface, 0, IFNAMSIZ);
 
 	if (rte_eal_process_type() == RTE_PROC_SECONDARY &&
 	    strlen(params) == 0) {
@@ -2284,7 +2294,7 @@ rte_pmd_tun_probe(struct rte_vdev_device *dev)
 	}
 
 	/* use tun%d which causes kernel to choose next available */
-	strlcpy(tun_name, DEFAULT_TUN_NAME "%d", RTE_ETH_NAME_MAX_LEN);
+	strlcpy(tun_name, DEFAULT_TUN_NAME "%d", IFNAMSIZ);
 
 	if (params && (params[0] != '\0')) {
 		TAP_LOG(DEBUG, "parameters (%s)", params);
@@ -2424,8 +2434,8 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev)
 	int ret;
 	struct rte_kvargs *kvlist = NULL;
 	int speed;
-	char tap_name[RTE_ETH_NAME_MAX_LEN];
-	char remote_iface[RTE_ETH_NAME_MAX_LEN];
+	char tap_name[IFNAMSIZ];
+	char remote_iface[IFNAMSIZ];
 	struct rte_ether_addr user_mac = { .addr_bytes = {0} };
 	struct rte_eth_dev *eth_dev;
 	int tap_devices_count_increased = 0;
@@ -2479,8 +2489,8 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev)
 	speed = RTE_ETH_SPEED_NUM_10G;
 
 	/* use tap%d which causes kernel to choose next available */
-	strlcpy(tap_name, DEFAULT_TAP_NAME "%d", RTE_ETH_NAME_MAX_LEN);
-	memset(remote_iface, 0, RTE_ETH_NAME_MAX_LEN);
+	strlcpy(tap_name, DEFAULT_TAP_NAME "%d", IFNAMSIZ);
+	memset(remote_iface, 0, IFNAMSIZ);
 
 	if (params && (params[0] != '\0')) {
 		TAP_LOG(DEBUG, "parameters (%s)", params);
drivers/net/tap/rte_eth_tap.h +9 -13
index ce4322ad04..8f9ab613c7 100644
@@ -34,13 +34,9 @@ enum rte_tuntap_type {
 };
 
 struct pkt_stats {
-	uint64_t opackets;              /* Number of output packets */
-	uint64_t ipackets;              /* Number of input packets */
-	uint64_t obytes;                /* Number of bytes on output */
-	uint64_t ibytes;                /* Number of bytes on input */
-	uint64_t errs;                  /* Number of TX error packets */
-	uint64_t ierrors;               /* Number of RX error packets */
-	uint64_t rx_nombuf;             /* Nb of RX mbuf alloc failures */
+	uint64_t packets;       /* Number of packets */
+	uint64_t bytes;         /* Number of bytes */
+	uint64_t errors;        /* Number of errors */
 };
 
 struct rx_queue {
@@ -68,15 +64,16 @@ struct tx_queue {
 
 struct pmd_internals {
 	struct rte_eth_dev *dev;          /* Ethernet device. */
-	char remote_iface[RTE_ETH_NAME_MAX_LEN]; /* Remote netdevice name */
-	char name[RTE_ETH_NAME_MAX_LEN];  /* Internal Tap device name */
+	char remote_iface[IFNAMSIZ];	  /* Remote netdevice name */
+	char name[IFNAMSIZ];		  /* Internal Tap device name */
 	int type;                         /* Type field - TUN|TAP */
 	int persist;			  /* 1 if keep link up, else 0 */
 	struct rte_ether_addr eth_addr;   /* Mac address of the device port */
-	struct ifreq remote_initial_flags;/* Remote netdevice flags on init */
+	uint16_t remote_flags;		  /* Remote netdevice flags on init */
 	int remote_if_index;              /* remote netdevice IF_INDEX */
 	int if_index;                     /* IF_INDEX for the port */
 	int ioctl_sock;                   /* socket for ioctl calls */
+	int ka_fd;                        /* keep-alive file descriptor */
 
 #ifdef HAVE_TCA_FLOWER
 	int nlsk_fd;                      /* Netlink socket fd */
@@ -88,12 +85,11 @@ struct pmd_internals {
 	/* implicit rte_flow rules set when a remote device is active */
 	LIST_HEAD(tap_implicit_flows, rte_flow) implicit_flows;
 #endif
+	struct rte_intr_handle *intr_handle;         /* LSC interrupt handle. */
+	struct rte_mempool *gso_ctx_mp;     /* Mempool for GSO packets */
 
 	struct rx_queue rxq[RTE_PMD_TAP_MAX_QUEUES]; /* List of RX queues */
 	struct tx_queue txq[RTE_PMD_TAP_MAX_QUEUES]; /* List of TX queues */
-	struct rte_intr_handle *intr_handle;         /* LSC interrupt handle. */
-	int ka_fd;                        /* keep-alive file descriptor */
-	struct rte_mempool *gso_ctx_mp;     /* Mempool for GSO packets */
 };
 
 struct pmd_process_private {
Signature · 1 line
2.43.0
#172 lore raw

PATCH v13 10/11 net/tap: remove extraneous newlines

In reply to Stephen Hemminger

Some log messages contained extra newlines.

---
 drivers/net/tap/rte_eth_tap.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)
drivers/net/tap/rte_eth_tap.c +8 -9
index 3614aaf1dc..2484a82ccb 100644
@@ -235,9 +235,8 @@ tun_alloc(struct pmd_internals *pmd, int is_keepalive, int persistent)
 
 	flags = fcntl(fd, F_GETFL);
 	if (flags == -1) {
-		TAP_LOG(WARNING,
-			"Unable to get %s current flags\n",
-			ifr.ifr_name);
+		TAP_LOG(WARNING, "Unable to get %s current flags: %s",
+			ifr.ifr_name, strerror(errno));
 		goto error;
 	}
 
@@ -279,7 +278,7 @@ tun_alloc(struct pmd_internals *pmd, int is_keepalive, int persistent)
 
 		if (sigaction(signo, &sa, NULL) == -1) {
 			TAP_LOG(WARNING,
-				"Unable to set rt-signal %d handler\n", signo);
+				"Unable to set rt-signal %d handler", signo);
 			goto error;
 		}
 
@@ -290,11 +289,11 @@ tun_alloc(struct pmd_internals *pmd, int is_keepalive, int persistent)
 	}
 
 	if (signo == SIGRTMAX) {
-		TAP_LOG(WARNING, "All rt-signals are in use\n");
+		TAP_LOG(WARNING, "All rt-signals are in use");
 
 		/* Disable trigger globally in case of error */
 		tap_trigger = 0;
-		TAP_LOG(NOTICE, "No Rx trigger signal available\n");
+		TAP_LOG(NOTICE, "No Rx trigger signal available");
 	} else {
 		/* Enable signal on file descriptor */
 		if (fcntl(fd, F_SETSIG, signo) < 0) {
@@ -920,7 +919,7 @@ tap_mp_req_start_rxtx(const struct rte_mp_msg *request, __rte_unused const void
 	}
 
 	process_private = dev->process_private;
-	TAP_LOG(DEBUG, "tap_attach q:%d\n", request_param->q_count);
+	TAP_LOG(DEBUG, "tap_attach q:%d", request_param->q_count);
 
 	for (int q = 0; q < request_param->q_count; q++)
 		process_private->fds[q] = request->fds[q];
@@ -1463,7 +1462,7 @@ tap_gso_ctx_setup(struct rte_gso_ctx *gso_ctx, struct rte_eth_dev *dev)
 		if (ret < 0 || ret >= (int)sizeof(pool_name)) {
 			TAP_LOG(ERR,
 				"%s: failed to create mbuf pool name for device %s,"
-				"device name too long or output error, ret: %d\n",
+				"device name too long or output error, ret: %d",
 				pmd->name, dev->device->name, ret);
 			return -ENAMETOOLONG;
 		}
@@ -1473,7 +1472,7 @@ tap_gso_ctx_setup(struct rte_gso_ctx *gso_ctx, struct rte_eth_dev *dev)
 			SOCKET_ID_ANY);
 		if (!pmd->gso_ctx_mp) {
 			TAP_LOG(ERR,
-				"%s: failed to create mbuf pool for device %s\n",
+				"%s: failed to create mbuf pool for device %s",
 				pmd->name, dev->device->name);
 			return -1;
 		}
Signature · 1 line
2.43.0
#173 lore raw

PATCH v13 11/11 net/tap: update documentation

In reply to Stephen Hemminger

The driver support of flows has changed and the wording in the guide was awkward.

Drop references to DPDK pktgen in this documentation since it is not required, confusing and abandoned.

---
 doc/guides/nics/tap.rst | 274 +++++++++++-----------------------------
 1 file changed, 77 insertions(+), 197 deletions(-)
doc/guides/nics/tap.rst +77 -197
index d4f45c02a1..55e38fb25b 100644
@@ -1,47 +1,51 @@
 ..  SPDX-License-Identifier: BSD-3-Clause
     Copyright(c) 2016 Intel Corporation.
 
-Tun|Tap Poll Mode Driver
-========================
+TAP Poll Mode Driver
+====================
 
-The ``rte_eth_tap.c`` PMD creates a device using TAP interfaces on the
-local host. The PMD allows for DPDK and the host to communicate using a raw
-device interface on the host and in the DPDK application.
+The TAP Poll Mode Driver (PMD) is a virtual device for injecting packets to be processed
+by the Linux kernel. This PMD is useful when writing DPDK application
+for offloading network functionality (such as tunneling) from the kernel.
 
-The device created is a TAP device, which sends/receives packet in a raw
-format with a L2 header. The usage for a TAP PMD is for connectivity to the
-local host using a TAP interface. When the TAP PMD is initialized it will
-create a number of tap devices in the host accessed via ``ifconfig -a`` or
-``ip`` command. The commands can be used to assign and query the virtual like
-device.
+From the kernel point of view, the TAP device looks like a regular network interface.
+The network device can be managed by standard tools such as ``ip`` and ``ethtool`` commands.
+It is also possible to use existing packet tools such as  ``wireshark`` or ``tcpdump``.
 
-These TAP interfaces can be used with Wireshark or tcpdump or Pktgen-DPDK
-along with being able to be used as a network connection to the DPDK
-application. The method enable one or more interfaces is to use the
-``--vdev=net_tap0`` option on the DPDK application command line. Each
-``--vdev=net_tap1`` option given will create an interface named dtap0, dtap1,
-and so on.
+From the DPDK application, the TAP device looks like a DPDK ethdev.
+Packets are sent and received in L2 (Ethernet) format. The standare DPDK
+API's to query for information, statistics and send and receive packets
+work as expected.
 
-The interface name can be changed by adding the ``iface=foo0``, for example::
+Requirements
+~~~~~~~~~~~~
+
+The TAP PMD requires kernel support for multiple queues in TAP device as
+well as the multi-queue ``multiq`` and incoming ``ingress`` queue disciplines.
+These are standard kernel features in most Linux distributions.
+
+Arguments
+---------
+
+TAP devices are created with the command line
+``--vdev=net_tap0`` option. This option maybe specified more the once by repeating
+with a different ``net_tapX`` device.
+
+By default, the Linux interfaces are named ``dtap0``, ``dtap1``, etc.
+The interface name can be specified by adding the ``iface=foo0``, for example::
 
    --vdev=net_tap0,iface=foo0 --vdev=net_tap1,iface=foo1, ...
 
-Normally the PMD will generate a random MAC address, but when testing or with
-a static configuration the developer may need a fixed MAC address style.
-Using the option ``mac=fixed`` you can create a fixed known MAC address::
+Normally the PMD will generate a random MAC address.
+If a static address is desired instead, the ``mac=fixed`` can be used.
 
    --vdev=net_tap0,mac=fixed
 
-The MAC address will have a fixed value with the last octet incrementing by one
-for each interface string containing ``mac=fixed``. The MAC address is formatted
-as 02:'d':'t':'a':'p':[00-FF]. Convert the characters to hex and you get the
-actual MAC address: ``02:64:74:61:70:[00-FF]``.
-
-   --vdev=net_tap0,mac="02:64:74:61:70:11"
+With the fixed option, the MAC address will have the first octets:
+as 02:'d':'t':'a':'p':[00-FF] and the last octets are the interface number.
 
-The MAC address will have a user value passed as string. The MAC address is in
-format with delimiter ``:``. The string is byte converted to hex and you get
-the actual MAC address: ``02:64:74:61:70:11``.
+To specify a specific MAC address use the conventional representation.
+The string is byte converted to hex, the result is MAC address: ``02:64:74:61:70:11``.
 
 It is possible to specify a remote netdevice to capture packets from by adding
 ``remote=foo1``, for example::
@@ -59,40 +63,20 @@ netdevice that has no support in the DPDK. It is possible to add explicit
 rte_flow rules on the tap PMD to capture specific traffic (see next section for
 examples).
 
-After the DPDK application is started you can send and receive packets on the
-interface using the standard rx_burst/tx_burst APIs in DPDK. From the host
-point of view you can use any host tool like tcpdump, Wireshark, ping, Pktgen
-and others to communicate with the DPDK application. The DPDK application may
-not understand network protocols like IPv4/6, UDP or TCP unless the
-application has been written to understand these protocols.
-
-If you need the interface as a real network interface meaning running and has
-a valid IP address then you can do this with the following commands::
-
-   sudo ip link set dtap0 up; sudo ip addr add 192.168.0.250/24 dev dtap0
-   sudo ip link set dtap1 up; sudo ip addr add 192.168.1.250/24 dev dtap1
-
-Please change the IP addresses as you see fit.
-
-If routing is enabled on the host you can also communicate with the DPDK App
-over the internet via a standard socket layer application as long as you
-account for the protocol handling in the application.
-
-If you have a Network Stack in your DPDK application or something like it you
-can utilize that stack to handle the network protocols. Plus you would be able
-to address the interface using an IP address assigned to the internal
-interface.
-
 Normally, when the DPDK application exits,
 the TAP device is marked down and is removed.
-But this behaviour can be overridden by the use of the persist flag, example::
+But this behavior can be overridden by the use of the persist flag, example::
 
   --vdev=net_tap0,iface=tap0,persist ...
 
-The TUN PMD allows user to create a TUN device on host. The PMD allows user
-to transmit and receive packets via DPDK API calls with L3 header and payload.
-The devices in host can be accessed via ``ifconfig`` or ``ip`` command. TUN
-interfaces are passed to DPDK ``rte_eal_init`` arguments as ``--vdev=net_tunX``,
+TUN devices
+-----------
+
+The TAP device can be used an L3 tunnel only device (TUN).
+This type of device does not include the Ethernet (L2) header; all packets
+are sent and received as IP packets.
+
+TUN devices are created with the command line arguments ``--vdev=net_tunX``,
 where X stands for unique id, example::
 
    --vdev=net_tun0 --vdev=net_tun1,iface=foo1, ...
@@ -103,27 +87,33 @@ options. Default interface name is ``dtunX``, where X stands for unique id.
 Flow API support
 ----------------
 
-The tap PMD supports major flow API pattern items and actions, when running on
-linux kernels above 4.2 ("Flower" classifier required).
-The kernel support can be checked with this command::
+The TAP PMD supports major flow API pattern items and actions.
+
+Requirements
+~~~~~~~~~~~~
 
-   zcat /proc/config.gz | ( grep 'CLS_FLOWER=' || echo 'not supported' ) |
-   tee -a /dev/stderr | grep -q '=m' &&
-   lsmod | ( grep cls_flower || echo 'try modprobe cls_flower' )
+Flow support in TAP driver requires the Linux kernel support of flow based
+traffic control filter ``flower``. This was added in Linux 4.3 kernel.
 
-Supported items:
+The implementation of RSS action uses an eBPF module that requires additional
+libraries and tools. Building the RSS support requires the ``clang``
+compiler to compile the C code to BPF target; ``bpftool`` to convert the
+compiled BPF object to a header file; and ``libbpf`` to load the eBPF
+action into the kernel.
 
-- eth: src and dst (with variable masks), and eth_type (0xffff mask).
-- vlan: vid, pcp, but not eid. (requires kernel 4.9)
-- ipv4/6: src and dst (with variable masks), and ip_proto (0xffff mask).
-- udp/tcp: src and dst port (0xffff) mask.
+Supported match items:
+
+  - eth: src and dst (with variable masks), and eth_type (0xffff mask).
+  - vlan: vid, pcp, but not eid. (requires kernel 4.9)
+  - ipv4/6: src and dst (with variable masks), and ip_proto (0xffff mask).
+  - udp/tcp: src and dst port (0xffff) mask.
 
 Supported actions:
 
 - DROP
 - QUEUE
 - PASSTHRU
-- RSS (requires kernel 4.9)
+- RSS
 
 It is generally not possible to provide a "last" item. However, if the "last"
 item, once masked, is identical to the masked spec, then it is supported.
@@ -133,7 +123,7 @@ full mask (exact match).
 
 As rules are translated to TC, it is possible to show them with something like::
 
-   tc -s filter show dev tap1 parent 1:
+   tc -s filter show dev dtap1 parent 1:
 
 Examples of testpmd flow rules
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -174,135 +164,25 @@ The IPC synchronization of Rx/Tx queues is currently limited:
   - Maximum 8 queues shared
   - Synchronized on probing, but not on later port update
 
-Example
--------
-
-The following is a simple example of using the TAP PMD with the Pktgen
-packet generator. It requires that the ``socat`` utility is installed on the
-test system.
-
-Build DPDK, then pull down Pktgen and build pktgen using the DPDK SDK/Target
-used to build the dpdk you pulled down.
-
-Run pktgen from the pktgen directory in a terminal with a commandline like the
-following::
-
-    sudo ./app/app/x86_64-native-linux-gcc/app/pktgen -l 1-5 -n 4        \
-     --proc-type auto --log-level debug --socket-mem 512,512 --file-prefix pg   \
-     --vdev=net_tap0 --vdev=net_tap1 -b 05:00.0 -b 05:00.1                  \
-     -b 04:00.0 -b 04:00.1 -b 04:00.2 -b 04:00.3                            \
-     -b 81:00.0 -b 81:00.1 -b 81:00.2 -b 81:00.3                            \
-     -b 82:00.0 -b 83:00.0 -- -T -P -m [2:3].0 -m [4:5].1                   \
-     -f themes/black-yellow.theme
-
-.. Note:
-
-   Change the ``-b`` options to exclude all of your physical ports. The
-   following command line is all one line.
-
-   Also, ``-f themes/black-yellow.theme`` is optional if the default colors
-   work on your system configuration. See the Pktgen docs for more
-   information.
-
-Verify with ``ifconfig -a`` command in a different xterm window, should have a
-``dtap0`` and ``dtap1`` interfaces created.
-
-Next set the links for the two interfaces to up via the commands below::
-
-    sudo ip link set dtap0 up; sudo ip addr add 192.168.0.250/24 dev dtap0
-    sudo ip link set dtap1 up; sudo ip addr add 192.168.1.250/24 dev dtap1
-
-Then use socat to create a loopback for the two interfaces::
-
-    sudo socat interface:dtap0 interface:dtap1
-
-Then on the Pktgen command line interface you can start sending packets using
-the commands ``start 0`` and ``start 1`` or you can start both at the same
-time with ``start all``. The command ``str`` is an alias for ``start all`` and
-``stp`` is an alias for ``stop all``.
-
-While running you should see the 64 byte counters increasing to verify the
-traffic is being looped back. You can use ``set all size XXX`` to change the
-size of the packets after you stop the traffic. Use pktgen ``help``
-command to see a list of all commands. You can also use the ``-f`` option to
-load commands at startup in command line or Lua script in pktgen.
 
 RSS specifics
 -------------
-Packet distribution in TAP is done by the kernel which has a default
-distribution. This feature is adding RSS distribution based on eBPF code.
-The default eBPF code calculates RSS hash based on Toeplitz algorithm for
-a fixed RSS key. It is calculated on fixed packet offsets. For IPv4 and IPv6 it
-is calculated over src/dst addresses (8 or 32 bytes for IPv4 or IPv6
-respectively) and src/dst TCP/UDP ports (4 bytes).
-
-The RSS algorithm is written in file ``tap_bpf_program.c`` which
-does not take part in TAP PMD compilation. Instead this file is compiled
-in advance to eBPF object file. The eBPF object file is then parsed and
-translated into eBPF byte code in the format of C arrays of eBPF
-instructions. The C array of eBPF instructions is part of TAP PMD tree and
-is taking part in TAP PMD compilation. At run time the C arrays are uploaded to
-the kernel via BPF system calls and the RSS hash is calculated by the
-kernel.
-
-It is possible to support different RSS hash algorithms by updating file
-``tap_bpf_program.c``  In order to add a new RSS hash algorithm follow these
-steps:
-
-#. Write the new RSS implementation in file ``tap_bpf_program.c``
-
-   BPF programs which are uploaded to the kernel correspond to
-   C functions under different ELF sections.
-
-#. Install ``LLVM`` library and ``clang`` compiler versions 3.7 and above
-
-#. Use make to compile  `tap_bpf_program.c`` via ``LLVM`` into an object file
-   and extract the resulting instructions into ``tap_bpf_insn.h``::
-
-    cd bpf; make
-
-#. Recompile the TAP PMD.
-
-The C arrays are uploaded to the kernel using BPF system calls.
-
-``tc`` (traffic control) is a well known user space utility program used to
-configure the Linux kernel packet scheduler. It is usually packaged as
-part of the ``iproute2`` package.
-Since commit 11c39b5e9 ("tc: add eBPF support to f_bpf") ``tc`` can be used
-to uploads eBPF code to the kernel and can be patched in order to print the
-C arrays of eBPF instructions just before calling the BPF system call.
-Please refer to ``iproute2`` package file ``lib/bpf.c`` function
-``bpf_prog_load()``.
-
-An example utility for eBPF instruction generation in the format of C arrays will
-be added in next releases
-
-TAP reports on supported RSS functions as part of dev_infos_get callback:
-``RTE_ETH_RSS_IP``, ``RTE_ETH_RSS_UDP`` and ``RTE_ETH_RSS_TCP``.
-**Known limitation:** TAP supports all of the above hash functions together
-and not in partial combinations.
-
-Systems supporting flow API
----------------------------
-
-- "tc flower" classifier requires linux kernel above 4.2
-- eBPF/RSS requires linux kernel above 4.9
-
-+--------------------+-----------------------+
-| RH7.3              | No flow rule support  |
-+--------------------+-----------------------+
-| RH7.4              | No RSS action support |
-+--------------------+-----------------------+
-| RH7.5              | No RSS action support |
-+--------------------+-----------------------+
-| SLES 15,           | No limitation         |
-| kernel 4.12        |                       |
-+--------------------+-----------------------+
-| Azure Ubuntu 16.04,| No limitation         |
-| kernel 4.13        |                       |
-+--------------------+-----------------------+
+The default packet distribution in TAP without flow rules is done by the
+kernel which has a default flow based distribution.
+When flow rules are used to distribute packets across a set of queues
+an eBPF program is used to calculate the RSS based on Toeplitz algorithm for
+with the given key.
+
+The hash is calculated for IPv4 and IPv6, over src/dst addresses
+(8 or 32 bytes for IPv4 or IPv6 respectively) and
+optionally the src/dst TCP/UDP ports (4 bytes).
+
 
 Limitations
 -----------
 
-* Rx/Tx must have the same number of queues.
+- Since TAP device uses a file descriptors to talk to the kernel.
+  The same number of queues must be specified for receive and transmit.
+
+- The RSS algorithm only support L3 or L4 functions. It does not support
+  finer grain selections (for example: only IPV6 packets with extension headers).
Signature · 1 line
2.43.0
#174 lore raw

Re: [PATCH v13 00/11] net/tap: make RSS work again

In reply to Stephen Hemminger
Quoted 16 lines · Stephen Hemminger

The support of doing RSS for rte_flow_action was a cool idea but it has been broken for several releases of DPDK as the underlying kernel and BPF infrastructure changed.

This series cleans up the BPF program, implements several features that were never completed in the original code and changes to use the current BPF tool chain.

The result should be easier to read and maintain. I do not intend to support backporting this to stable releases due to lack of demand and dealing with older distros.

v13 - Incorporate review feedback.
Drop change to statistics and queue full handling; these will get fixed in another series.

Quoted 13 lines

Stephen Hemminger (11):
net/tap: fix fd check in flow_isolate
net/tap: do not duplicate fd's
net/tap: remove unused fields
net/tap: validate and setup parameters for BPF RSS net/tap: do not build flow support if header is out of date net/tap: rewrite the RSS BPF program
net/tap: use libbpf to load new BPF program net/tap: remove no longer used files
net/tap: simplify internals
net/tap: remove extraneous newlines
net/tap: update documentation

Thanks Stephen for the update, I don't have any new comment, but there are some outstanding questions on v12 9/12, can you please check them?

#175 lore raw

Re: [PATCH v13 00/11] net/tap: make RSS work again

Quoted 31 lines · Ferruh Yigit
Quoted 16 lines · Stephen Hemminger

The support of doing RSS for rte_flow_action was a cool idea but it has been broken for several releases of DPDK as the underlying kernel and BPF infrastructure changed.

This series cleans up the BPF program, implements several features that were never completed in the original code and changes to use the current BPF tool chain.

The result should be easier to read and maintain. I do not intend to support backporting this to stable releases due to lack of demand and dealing with older distros.

v13 - Incorporate review feedback.
Drop change to statistics and queue full handling; these will get fixed in another series.

Quoted 13 lines

Stephen Hemminger (11):
net/tap: fix fd check in flow_isolate
net/tap: do not duplicate fd's
net/tap: remove unused fields
net/tap: validate and setup parameters for BPF RSS net/tap: do not build flow support if header is out of date net/tap: rewrite the RSS BPF program
net/tap: use libbpf to load new BPF program net/tap: remove no longer used files
net/tap: simplify internals
net/tap: remove extraneous newlines
net/tap: update documentation

Quoted 3 lines

Thanks Stephen for the update, I don't have any new comment, but there are some outstanding questions on v12 9/12, can you please check them?

Ah, I forgot that './devtools/check-meson.py' tool is complaining about some meson code.

#176 lore raw

Re: [PATCH v13 00/11] net/tap: make RSS work again

Quoted 32 lines · Ferruh Yigit
Quoted 31 lines · Ferruh Yigit
Quoted 29 lines · Stephen Hemminger

The support of doing RSS for rte_flow_action was a cool idea but it has been broken for several releases of DPDK as the underlying kernel and BPF infrastructure changed.

This series cleans up the BPF program, implements several features that were never completed in the original code and changes to use the current BPF tool chain.

The result should be easier to read and maintain. I do not intend to support backporting this to stable releases due to lack of demand and dealing with older distros.

v13 - Incorporate review feedback.
Drop change to statistics and queue full handling; these will get fixed in another series.

Stephen Hemminger (11):
net/tap: fix fd check in flow_isolate
net/tap: do not duplicate fd's
net/tap: remove unused fields
net/tap: validate and setup parameters for BPF RSS net/tap: do not build flow support if header is out of date net/tap: rewrite the RSS BPF program
net/tap: use libbpf to load new BPF program net/tap: remove no longer used files
net/tap: simplify internals
net/tap: remove extraneous newlines
net/tap: update documentation

Quoted 7 lines
Quoted 3 lines

Thanks Stephen for the update, I don't have any new comment, but there are some outstanding questions on v12 9/12, can you please check them?

Ah, I forgot that './devtools/check-meson.py' tool is complaining about some meson code.

Hi Patric,

I guess './devtools/check-meson.py' checks are missing in the CI, I don't remember seeing any complain about it in the CI.

Is it possible to add this task to the CI task-list backlog?

#177 lore raw

Re: [PATCH v13 00/11] net/tap: make RSS work again

Quoted 9 lines · Ferruh Yigit

Hi Patric,

I guess './devtools/check-meson.py' checks are missing in the CI, I don't remember seeing any complain about it in the CI.

Is it possible to add this task to the CI task-list backlog?

Correct, this script is not run in CI. I'll make a thread on the CI mailing list.

#178 lore raw

Re: [PATCH v13 00/11] net/tap: make RSS work again

Quoted 5 lines · Patrick Robb
Quoted 4 lines · Ferruh Yigit

Hi Patric,

Quoted 9 lines
Quoted 5 lines

I guess './devtools/check-meson.py' checks are missing in the CI, I don't remember seeing any complain about it in the CI.

Is it possible to add this task to the CI task-list backlog?

Correct, this script is not run in CI. I'll make a thread on the CI mailing list.

Thank you.

#179 lore raw

v14 cover net/tap: make RSS work again

In reply to Stephen Hemminger

The support of doing RSS for rte_flow_action was a cool idea but it has been broken for several releases of DPDK as the underlying kernel and BPF infrastructure changed.

This series cleans up the BPF program, implements several features that were never completed in the original code and changes to use the current BPF tool chain.

The result should be easier to read and maintain. I do not intend to support backporting this to stable releases due to lack of demand and dealing with older distros.

v14 - fix indentation in meson.build file used by tap/bpf

Stephen Hemminger (11):
net/tap: fix fd check in flow_isolate
net/tap: do not duplicate fd's
net/tap: remove unused fields
net/tap: validate and setup parameters for BPF RSS net/tap: do not build flow support if header is out of date net/tap: rewrite the RSS BPF program
net/tap: use libbpf to load new BPF program net/tap: remove no longer used files
net/tap: simplify internals
net/tap: remove extraneous newlines
net/tap: update documentation

 .gitignore                             |    3 -
 doc/guides/nics/tap.rst                |  274 ++--
 doc/guides/rel_notes/release_24_07.rst |    7 +
 drivers/net/tap/bpf/Makefile           |   19 -
 drivers/net/tap/bpf/README             |   49 +
 drivers/net/tap/bpf/bpf_api.h          |  276 ----
 drivers/net/tap/bpf/bpf_elf.h          |   53 -
 drivers/net/tap/bpf/bpf_extract.py     |   86 --
 drivers/net/tap/bpf/meson.build        |   94 ++
 drivers/net/tap/bpf/tap_bpf_program.c  |  255 ----
 drivers/net/tap/bpf/tap_rss.c          |  267 ++++
 drivers/net/tap/meson.build            |   42 +-
 drivers/net/tap/rte_eth_tap.c          |  373 +++--
 drivers/net/tap/rte_eth_tap.h          |   42 +-
 drivers/net/tap/tap_bpf.h              |  121 --
 drivers/net/tap/tap_bpf_api.c          |  190 ---
 drivers/net/tap/tap_bpf_insns.h        | 1743 ------------------------
 drivers/net/tap/tap_flow.c             |  565 +++-----
 drivers/net/tap/tap_flow.h             |   17 +-
 drivers/net/tap/tap_intr.c             |    7 +-
 drivers/net/tap/tap_rss.h              |   21 +-
 drivers/net/tap/tap_tcmsgs.h           |    4 +-
 22 files changed, 896 insertions(+), 3612 deletions(-)
 delete mode 100644 drivers/net/tap/bpf/Makefile
 create mode 100644 drivers/net/tap/bpf/README
 delete mode 100644 drivers/net/tap/bpf/bpf_api.h
 delete mode 100644 drivers/net/tap/bpf/bpf_elf.h
 delete mode 100644 drivers/net/tap/bpf/bpf_extract.py
 create mode 100644 drivers/net/tap/bpf/meson.build
 delete mode 100644 drivers/net/tap/bpf/tap_bpf_program.c
 create mode 100644 drivers/net/tap/bpf/tap_rss.c
 delete mode 100644 drivers/net/tap/tap_bpf.h
 delete mode 100644 drivers/net/tap/tap_bpf_api.c
 delete mode 100644 drivers/net/tap/tap_bpf_insns.h
Signature · 1 line
2.43.0
#180 lore raw

PATCH v14 1/11 net/tap: fix fd check in flow_isolate

The check for receive queue fd in flow_isolate is incorrect. If queue has not been setup then fd will be -1 not 0.

---
 drivers/net/tap/tap_flow.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/tap/tap_flow.c +1 -1
index fa50fe45d7..79cd6a12ca 100644
@@ -1595,7 +1595,7 @@ tap_flow_isolate(struct rte_eth_dev *dev,
 	 * If netdevice is there, setup appropriate flow rules immediately.
 	 * Otherwise it will be set when bringing up the netdevice (tun_alloc).
 	 */
-	if (!process_private->rxq_fds[0])
+	if (process_private->rxq_fds[0] == -1)
 		return 0;
 	if (set) {
 		struct rte_flow *remote_flow;
Signature · 1 line
2.43.0
#181 lore raw

PATCH v14 2/11 net/tap: do not duplicate fd's

In reply to Stephen Hemminger

The TAP device can use same file descriptor for both rx and tx queues which reduces the number of fd's required.

MP process support passes file descriptors from primary to secondary process; but because of the restriction on max fd's passed RTE_MP_MAX_FD_NUM (8) the TAP device was restricted to only 4 queues if using secondary.
This allows up to 8 queues (versus 4).

The restriction on max fd's should be changed in eal in future, but it will break ABI compatibility. The max Linux supports which is SCM_MAX_FD (253).

---
 doc/guides/rel_notes/release_24_07.rst |   4 +
 drivers/net/tap/rte_eth_tap.c          | 192 ++++++++++---------------
 drivers/net/tap/rte_eth_tap.h          |   3 +-
 drivers/net/tap/tap_flow.c             |   3 +-
 drivers/net/tap/tap_intr.c             |   7 +-
 5 files changed, 89 insertions(+), 120 deletions(-)
doc/guides/rel_notes/release_24_07.rst +4 -0
index a69f24cf99..fa9692924b 100644
@@ -55,6 +55,10 @@ New Features
      Also, make sure to start the actual text at the margin.
      =======================================================
 
+* **Update Tap PMD driver.
+
+  * Updated to support up to 8 queues when used by secondary process.
+
 
 Removed Items
 -------------
drivers/net/tap/rte_eth_tap.c +78 -114

337 lines not on this page · raw message

drivers/net/tap/rte_eth_tap.h +1 -2
index 5ac93f93e9..dc8201020b 100644
@@ -96,8 +96,7 @@ struct pmd_internals {
 };
 
 struct pmd_process_private {
-	int rxq_fds[RTE_PMD_TAP_MAX_QUEUES];
-	int txq_fds[RTE_PMD_TAP_MAX_QUEUES];
+	int fds[RTE_PMD_TAP_MAX_QUEUES];
 };
 
 /* tap_intr.c */
drivers/net/tap/tap_flow.c +2 -1
index 79cd6a12ca..a78fd50cd4 100644
@@ -1595,8 +1595,9 @@ tap_flow_isolate(struct rte_eth_dev *dev,
 	 * If netdevice is there, setup appropriate flow rules immediately.
 	 * Otherwise it will be set when bringing up the netdevice (tun_alloc).
 	 */
-	if (process_private->rxq_fds[0] == -1)
+	if (process_private->fds[0] == -1)
 		return 0;
+
 	if (set) {
 		struct rte_flow *remote_flow;
 
drivers/net/tap/tap_intr.c +4 -3
index a9097def1a..1908f71f97 100644
@@ -68,9 +68,11 @@ tap_rx_intr_vec_install(struct rte_eth_dev *dev)
 	}
 	for (i = 0; i < n; i++) {
 		struct rx_queue *rxq = pmd->dev->data->rx_queues[i];
+		int fd = process_private->fds[i];
 
 		/* Skip queues that cannot request interrupts. */
-		if (!rxq || process_private->rxq_fds[i] == -1) {
+		if (!rxq || fd == -1) {
+			/* Use invalid intr_vec[] index to disable entry. */
 			/* Use invalid intr_vec[] index to disable entry. */
 			if (rte_intr_vec_list_index_set(intr_handle, i,
 			RTE_INTR_VEC_RXTX_OFFSET + RTE_MAX_RXTX_INTR_VEC_ID))
@@ -80,8 +82,7 @@ tap_rx_intr_vec_install(struct rte_eth_dev *dev)
 		if (rte_intr_vec_list_index_set(intr_handle, i,
 					RTE_INTR_VEC_RXTX_OFFSET + count))
 			return -rte_errno;
-		if (rte_intr_efds_index_set(intr_handle, count,
-						   process_private->rxq_fds[i]))
+		if (rte_intr_efds_index_set(intr_handle, count, fd))
 			return -rte_errno;
 		count++;
 	}
Signature · 1 line
2.43.0
#182 lore raw

PATCH v14 3/11 net/tap: remove unused fields

In reply to Stephen Hemminger

The driver doesn't support these other hash types, and there is no reason to implement these in future. The rss_flows list was set but never used.

---
 drivers/net/tap/rte_eth_tap.h | 4 +---
 drivers/net/tap/tap_flow.c    | 1 -
 drivers/net/tap/tap_rss.h     | 6 ------
 3 files changed, 1 insertion(+), 10 deletions(-)
drivers/net/tap/rte_eth_tap.h +1 -3
index dc8201020b..1bcf92ce80 100644
@@ -77,14 +77,12 @@ struct pmd_internals {
 	int ioctl_sock;                   /* socket for ioctl calls */
 	int nlsk_fd;                      /* Netlink socket fd */
 	int flow_isolate;                 /* 1 if flow isolation is enabled */
-	int flower_support;               /* 1 if kernel supports, else 0 */
-	int flower_vlan_support;          /* 1 if kernel supports, else 0 */
 	int rss_enabled;                  /* 1 if RSS is enabled, else 0 */
 	int persist;			  /* 1 if keep link up, else 0 */
 	/* implicit rules set when RSS is enabled */
 	int map_fd;                       /* BPF RSS map fd */
 	int bpf_fd[RTE_PMD_TAP_MAX_QUEUES];/* List of bpf fds per queue */
-	LIST_HEAD(tap_rss_flows, rte_flow) rss_flows;
+
 	LIST_HEAD(tap_flows, rte_flow) flows;        /* rte_flow rules */
 	/* implicit rte_flow rules set when a remote device is active */
 	LIST_HEAD(tap_implicit_flows, rte_flow) implicit_flows;
drivers/net/tap/tap_flow.c +0 -1
index a78fd50cd4..8fccd599f0 100644
@@ -1958,7 +1958,6 @@ static int rss_enable(struct pmd_internals *pmd,
 				errno, strerror(errno));
 			return err;
 		}
-		LIST_INSERT_HEAD(&pmd->rss_flows, rss_flow, next);
 	}
 
 	pmd->rss_enabled = 1;
drivers/net/tap/tap_rss.h +0 -6
index dff46a012f..8766ffc244 100644
@@ -21,12 +21,6 @@ enum hash_field {
 	HASH_FIELD_IPV4_L3_L4,	/* IPv4 src/dst addr + L4 src/dst ports */
 	HASH_FIELD_IPV6_L3,	/* IPv6 src/dst addr */
 	HASH_FIELD_IPV6_L3_L4,	/* IPv6 src/dst addr + L4 src/dst ports */
-	HASH_FIELD_L2_SRC,	/* Ethernet src addr */
-	HASH_FIELD_L2_DST,	/* Ethernet dst addr */
-	HASH_FIELD_L3_SRC,	/* L3 src addr */
-	HASH_FIELD_L3_DST,	/* L3 dst addr */
-	HASH_FIELD_L4_SRC,	/* TCP/UDP src ports */
-	HASH_FIELD_L4_DST,	/* TCP/UDP dst ports */
 };
 
 struct rss_key {
Signature · 1 line
2.43.0
#183 lore raw

PATCH v14 4/11 net/tap: validate and setup parameters for BPF RSS

In reply to Stephen Hemminger

The flow RSS support via BPF was not using the key, or hash type parameters. Which is good because they were never properly setup.

Fix the setup and validate the flow parameters, the BPF side gets fixed later.

---
 drivers/net/tap/tap_flow.c | 75 +++++++++++++++++++++++++++++++++++---
 drivers/net/tap/tap_rss.h  |  5 +--
 2 files changed, 72 insertions(+), 8 deletions(-)
drivers/net/tap/tap_flow.c +70 -5
index 8fccd599f0..dd4e69b876 100644
@@ -11,9 +11,11 @@
 
 #include <rte_byteorder.h>
 #include <rte_jhash.h>
+#include <rte_thash.h>
 #include <rte_random.h>
 #include <rte_malloc.h>
 #include <rte_eth_tap.h>
+
 #include <tap_flow.h>
 #include <tap_autoconf.h>
 #include <tap_tcmsgs.h>
@@ -2061,6 +2063,21 @@ static int bpf_rss_key(enum bpf_rss_key_e cmd, __u32 *key_idx)
 	return err;
 }
 
+
+/* Default RSS hash key also used by mlx devices */
+static const uint8_t rss_hash_default_key[] = {
+	0x2c, 0xc6, 0x81, 0xd1,
+	0x5b, 0xdb, 0xf4, 0xf7,
+	0xfc, 0xa2, 0x83, 0x19,
+	0xdb, 0x1a, 0x3e, 0x94,
+	0x6b, 0x9e, 0x38, 0xd9,
+	0x2c, 0x9c, 0x03, 0xd1,
+	0xad, 0x99, 0x44, 0xa7,
+	0xd9, 0x56, 0x3d, 0x59,
+	0x06, 0x3c, 0x25, 0xf3,
+	0xfc, 0x1f, 0xdc, 0x2a,
+};
+
 /**
  * Add RSS hash calculations and queue selection
  *
@@ -2079,11 +2096,11 @@ static int rss_add_actions(struct rte_flow *flow, struct pmd_internals *pmd,
 			   const struct rte_flow_action_rss *rss,
 			   struct rte_flow_error *error)
 {
-	/* 4096 is the maximum number of instructions for a BPF program */
+	struct rss_key rss_entry = { };
+	const uint8_t *key_in;
+	uint32_t hash_type = 0;
 	unsigned int i;
 	int err;
-	struct rss_key rss_entry = { .hash_fields = 0,
-				     .key_size = 0 };
 
 	/* Check supported RSS features */
 	if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT)
@@ -2095,6 +2112,51 @@ static int rss_add_actions(struct rte_flow *flow, struct pmd_internals *pmd,
 			(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
 			 "a nonzero RSS encapsulation level is not supported");
 
+	if (rss->queue_num == 0 || rss->queue_num >= TAP_MAX_QUEUES)
+		return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
+					  "invalid number of queues");
+
+	/*
+	 * Follow the semantics of RSS key (see rte_ethdev.h)
+	 * There are two valid cases:
+	 *   1. key_length of zero, and key must be NULL;
+	 *      this uses the default driver key.
+	 *
+	 *   2. key_length is the TAP_RSS_HASH_KEY_SIZE (40 bytes)
+	 *      and the key must not be NULL.
+	 *
+	 * Anything else is an error.
+	 */
+	if (rss->key_len == 0) {
+		if (rss->key != NULL)
+			return rte_flow_error_set(error, ENOTSUP,
+						  RTE_FLOW_ERROR_TYPE_ACTION_CONF,
+						  &rss->key_len, "RSS hash key length 0");
+		key_in = rss_hash_default_key;
+	} else {
+		if (rss->key_len != TAP_RSS_HASH_KEY_SIZE)
+			return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+						  NULL, "RSS hash invalid key length");
+		if (rss->key == NULL)
+			return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+						  NULL, "RSS hash key is NULL");
+		key_in = rss->key;
+	}
+
+	if (rss->types & TAP_RSS_HF_MASK)
+		return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+					  NULL, "RSS hash type not supported");
+
+	if (rss->types & (RTE_ETH_RSS_NONFRAG_IPV4_UDP | RTE_ETH_RSS_NONFRAG_IPV4_TCP))
+		hash_type |= RTE_BIT32(HASH_FIELD_IPV4_L3_L4);
+	else if (rss->types & (RTE_ETH_RSS_IPV4 | RTE_ETH_RSS_FRAG_IPV4))
+		hash_type |= RTE_BIT32(HASH_FIELD_IPV4_L3);
+
+	if (rss->types & (RTE_ETH_RSS_NONFRAG_IPV6_UDP | RTE_ETH_RSS_NONFRAG_IPV6_TCP))
+		hash_type |= RTE_BIT32(HASH_FIELD_IPV6_L3_L4);
+	else if (rss->types & (RTE_ETH_RSS_IPV6 | RTE_ETH_RSS_FRAG_IPV6 | RTE_ETH_RSS_IPV6_EX))
+		hash_type |= RTE_BIT32(HASH_FIELD_IPV6_L3);
+
 	/* Get a new map key for a new RSS rule */
 	err = bpf_rss_key(KEY_CMD_GET, &flow->key_idx);
 	if (err < 0) {
@@ -2109,8 +2171,11 @@ static int rss_add_actions(struct rte_flow *flow, struct pmd_internals *pmd,
 	rss_entry.nb_queues = rss->queue_num;
 	for (i = 0; i < rss->queue_num; i++)
 		rss_entry.queues[i] = rss->queue[i];
-	rss_entry.hash_fields =
-		(1 << HASH_FIELD_IPV4_L3_L4) | (1 << HASH_FIELD_IPV6_L3_L4);
+
+	rss_entry.hash_fields = hash_type;
+	rte_convert_rss_key((const uint32_t *)key_in, (uint32_t *)rss_entry.key,
+			    TAP_RSS_HASH_KEY_SIZE);
+
 
 	/* Add this RSS entry to map */
 	err = tap_flow_bpf_update_rss_elem(pmd->map_fd,
drivers/net/tap/tap_rss.h +2 -3
index 8766ffc244..6009be7031 100644
@@ -24,11 +24,10 @@ enum hash_field {
 };
 
 struct rss_key {
-	 __u8 key[128];
 	__u32 hash_fields;
-	__u32 key_size;
-	__u32 queues[TAP_MAX_QUEUES];
+	__u8 key[TAP_RSS_HASH_KEY_SIZE];
 	__u32 nb_queues;
+	__u32 queues[TAP_MAX_QUEUES];
 } __attribute__((packed));
 
 #endif /* _TAP_RSS_H_ */
Signature · 1 line
2.43.0
#184 lore raw

PATCH v14 5/11 net/tap: do not build flow support if header is out of date

In reply to Stephen Hemminger

The proper place for finding bpf structures and functions is in linux/bpf.h. The original version was trying to workaround the case where the build environment was running on old pre BPF version of Glibc, but the target environment had BPF.

Having own private (and divergent) version headers leads to future problems when BPF definitions evolve.

If the build infrastructure is so old that TC flower is not supported, then the TAP device will build without any flow support.

---
 drivers/net/tap/bpf/bpf_extract.py |   1 -
 drivers/net/tap/meson.build        |  17 ++--
 drivers/net/tap/rte_eth_tap.c      |  38 +++++++--
 drivers/net/tap/rte_eth_tap.h      |   7 +-
 drivers/net/tap/tap_bpf.h          | 121 -----------------------------
 drivers/net/tap/tap_bpf_api.c      |  20 +++--
 drivers/net/tap/tap_bpf_insns.h    |   2 -
 drivers/net/tap/tap_flow.c         |  90 ---------------------
 8 files changed, 60 insertions(+), 236 deletions(-)
 delete mode 100644 drivers/net/tap/tap_bpf.h
drivers/net/tap/bpf/bpf_extract.py +0 -1
index b630c42b80..73c4dafe4e 100644
@@ -65,7 +65,6 @@ def write_header(out, source):
         print(f' * Auto-generated from {source}', file=out)
     print(" * This not the original source file. Do NOT edit it.", file=out)
     print(" */\n", file=out)
-    print("#include <tap_bpf.h>", file=out)
 
 
 def main():
drivers/net/tap/meson.build +9 -8
index 5099ccdff1..66647a1c62 100644
@@ -7,13 +7,19 @@ if not is_linux
 endif
 sources = files(
         'rte_eth_tap.c',
-        'tap_bpf_api.c',
-        'tap_flow.c',
         'tap_intr.c',
         'tap_netlink.c',
-        'tap_tcmsgs.c',
 )
 
+if cc.has_header_symbol('linux/pkt_cls.h', 'TCA_FLOWER_ACT')
+    cflags += '-DHAVE_TCA_FLOWER'
+    sources += files(
+        'tap_bpf_api.c',
+        'tap_flow.c',
+        'tap_tcmsgs.c',
+    )
+endif
+
 deps = ['bus_vdev', 'gso', 'hash']
 
 cflags += '-DTAP_MAX_QUEUES=16'
@@ -23,12 +29,7 @@ cflags += '-DTAP_MAX_QUEUES=16'
 #   "enum/define", "symbol to search" ]
 #
 args = [
-        [ 'HAVE_TC_FLOWER', 'linux/pkt_cls.h', 'TCA_FLOWER_UNSPEC' ],
-        [ 'HAVE_TC_VLAN_ID', 'linux/pkt_cls.h', 'TCA_FLOWER_KEY_VLAN_PRIO' ],
-        [ 'HAVE_TC_BPF', 'linux/pkt_cls.h', 'TCA_BPF_UNSPEC' ],
-        [ 'HAVE_TC_BPF_FD', 'linux/pkt_cls.h', 'TCA_BPF_FD' ],
         [ 'HAVE_TC_ACT_BPF', 'linux/tc_act/tc_bpf.h', 'TCA_ACT_BPF_UNSPEC' ],
-        [ 'HAVE_TC_ACT_BPF_FD', 'linux/tc_act/tc_bpf.h', 'TCA_ACT_BPF_FD' ],
 ]
 config = configuration_data()
 foreach arg:args
drivers/net/tap/rte_eth_tap.c +32 -6
index b84fc01856..9058a47295 100644
@@ -1133,12 +1133,15 @@ tap_dev_close(struct rte_eth_dev *dev)
 
 	if (!internals->persist)
 		tap_link_set_down(dev);
+
+#ifdef HAVE_TCA_FLOWER
 	if (internals->nlsk_fd != -1) {
 		tap_flow_flush(dev, NULL);
 		tap_flow_implicit_flush(internals, NULL);
 		tap_nl_final(internals->nlsk_fd);
 		internals->nlsk_fd = -1;
 	}
+#endif
 
 	for (i = 0; i < RTE_PMD_TAP_MAX_QUEUES; i++) {
 		struct rx_queue *rxq = &internals->rxq[i];
@@ -1261,6 +1264,7 @@ tap_promisc_enable(struct rte_eth_dev *dev)
 	if (ret != 0)
 		return ret;
 
+#ifdef HAVE_TCA_FLOWER
 	if (pmd->remote_if_index && !pmd->flow_isolate) {
 		dev->data->promiscuous = 1;
 		ret = tap_flow_implicit_create(pmd, TAP_REMOTE_PROMISC);
@@ -1274,7 +1278,7 @@ tap_promisc_enable(struct rte_eth_dev *dev)
 			return ret;
 		}
 	}
-
+#endif
 	return 0;
 }
 
@@ -1289,6 +1293,7 @@ tap_promisc_disable(struct rte_eth_dev *dev)
 	if (ret != 0)
 		return ret;
 
+#ifdef HAVE_TCA_FLOWER
 	if (pmd->remote_if_index && !pmd->flow_isolate) {
 		dev->data->promiscuous = 0;
 		ret = tap_flow_implicit_destroy(pmd, TAP_REMOTE_PROMISC);
@@ -1302,6 +1307,7 @@ tap_promisc_disable(struct rte_eth_dev *dev)
 			return ret;
 		}
 	}
+#endif
 
 	return 0;
 }
@@ -1317,6 +1323,7 @@ tap_allmulti_enable(struct rte_eth_dev *dev)
 	if (ret != 0)
 		return ret;
 
+#ifdef HAVE_TCA_FLOWER
 	if (pmd->remote_if_index && !pmd->flow_isolate) {
 		dev->data->all_multicast = 1;
 		ret = tap_flow_implicit_create(pmd, TAP_REMOTE_ALLMULTI);
@@ -1330,6 +1337,7 @@ tap_allmulti_enable(struct rte_eth_dev *dev)
 			return ret;
 		}
 	}
+#endif
 
 	return 0;
 }
@@ -1345,6 +1353,7 @@ tap_allmulti_disable(struct rte_eth_dev *dev)
 	if (ret != 0)
 		return ret;
 
+#ifdef HAVE_TCA_FLOWER
 	if (pmd->remote_if_index && !pmd->flow_isolate) {
 		dev->data->all_multicast = 0;
 		ret = tap_flow_implicit_destroy(pmd, TAP_REMOTE_ALLMULTI);
@@ -1358,6 +1367,7 @@ tap_allmulti_disable(struct rte_eth_dev *dev)
 			return ret;
 		}
 	}
+#endif
 
 	return 0;
 }
@@ -1403,6 +1413,8 @@ tap_mac_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr)
 	if (ret < 0)
 		return ret;
 	rte_memcpy(&pmd->eth_addr, mac_addr, RTE_ETHER_ADDR_LEN);
+
+#ifdef HAVE_TCA_FLOWER
 	if (pmd->remote_if_index && !pmd->flow_isolate) {
 		/* Replace MAC redirection rule after a MAC change */
 		ret = tap_flow_implicit_destroy(pmd, TAP_REMOTE_LOCAL_MAC);
@@ -1420,6 +1432,7 @@ tap_mac_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr)
 			return ret;
 		}
 	}
+#endif
 
 	return 0;
 }
@@ -1894,7 +1907,9 @@ static const struct eth_dev_ops ops = {
 	.stats_reset            = tap_stats_reset,
 	.dev_supported_ptypes_get = tap_dev_supported_ptypes_get,
 	.rss_hash_update        = tap_rss_hash_update,
+#ifdef HAVE_TCA_FLOWER
 	.flow_ops_get           = tap_dev_flow_ops_get,
+#endif
 };
 
 static int
@@ -1934,7 +1949,9 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 	strlcpy(pmd->name, tap_name, sizeof(pmd->name));
 	pmd->type = type;
 	pmd->ka_fd = -1;
+#ifdef HAVE_TCA_FLOWER
 	pmd->nlsk_fd = -1;
+#endif
 	pmd->gso_ctx_mp = NULL;
 
 	pmd->ioctl_sock = socket(AF_INET, SOCK_DGRAM, 0);
@@ -2014,6 +2031,14 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 	/* Make network device persist after application exit */
 	pmd->persist = persist;
 
+	pmd->if_index = if_nametoindex(pmd->name);
+	if (!pmd->if_index) {
+		TAP_LOG(ERR, "%s: failed to get if_index.", pmd->name);
+		goto disable_rte_flow;
+	}
+
+
+#ifdef HAVE_TCA_FLOWER
 	/*
 	 * Set up everything related to rte_flow:
 	 * - netlink socket
@@ -2028,11 +2053,6 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 			pmd->name);
 		goto disable_rte_flow;
 	}
-	pmd->if_index = if_nametoindex(pmd->name);
-	if (!pmd->if_index) {
-		TAP_LOG(ERR, "%s: failed to get if_index.", pmd->name);
-		goto disable_rte_flow;
-	}
 	if (qdisc_create_multiq(pmd->nlsk_fd, pmd->if_index) < 0) {
 		TAP_LOG(ERR, "%s: failed to create multiq qdisc.",
 			pmd->name);
@@ -2043,6 +2063,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 			pmd->name);
 		goto disable_rte_flow;
 	}
+
 	LIST_INIT(&pmd->flows);
 
 	if (strlen(remote_iface)) {
@@ -2095,6 +2116,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 			goto error_remote;
 		}
 	}
+#endif
 
 	rte_eth_dev_probing_finish(dev);
 	return 0;
@@ -2109,14 +2131,18 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 	rte_eth_dev_probing_finish(dev);
 	return 0;
 
+#ifdef HAVE_TCA_FLOWER
 error_remote:
 	TAP_LOG(ERR, " Can't set up remote feature: %s(%d)",
 		strerror(errno), errno);
 	tap_flow_implicit_flush(pmd, NULL);
+#endif
 
 error_exit:
+#ifdef HAVE_TCA_FLOWER
 	if (pmd->nlsk_fd != -1)
 		close(pmd->nlsk_fd);
+#endif
 	if (pmd->ka_fd != -1)
 		close(pmd->ka_fd);
 	if (pmd->ioctl_sock != -1)
drivers/net/tap/rte_eth_tap.h +6 -1
index 1bcf92ce80..af18b29090 100644
@@ -16,6 +16,7 @@
 #include <ethdev_driver.h>
 #include <rte_ether.h>
 #include <rte_gso.h>
+
 #include "tap_log.h"
 
 #ifdef IFF_MULTI_QUEUE
@@ -70,15 +71,17 @@ struct pmd_internals {
 	char remote_iface[RTE_ETH_NAME_MAX_LEN]; /* Remote netdevice name */
 	char name[RTE_ETH_NAME_MAX_LEN];  /* Internal Tap device name */
 	int type;                         /* Type field - TUN|TAP */
+	int persist;			  /* 1 if keep link up, else 0 */
 	struct rte_ether_addr eth_addr;   /* Mac address of the device port */
 	struct ifreq remote_initial_flags;/* Remote netdevice flags on init */
 	int remote_if_index;              /* remote netdevice IF_INDEX */
 	int if_index;                     /* IF_INDEX for the port */
 	int ioctl_sock;                   /* socket for ioctl calls */
+
+#ifdef HAVE_TCA_FLOWER
 	int nlsk_fd;                      /* Netlink socket fd */
 	int flow_isolate;                 /* 1 if flow isolation is enabled */
 	int rss_enabled;                  /* 1 if RSS is enabled, else 0 */
-	int persist;			  /* 1 if keep link up, else 0 */
 	/* implicit rules set when RSS is enabled */
 	int map_fd;                       /* BPF RSS map fd */
 	int bpf_fd[RTE_PMD_TAP_MAX_QUEUES];/* List of bpf fds per queue */
@@ -86,6 +89,8 @@ struct pmd_internals {
 	LIST_HEAD(tap_flows, rte_flow) flows;        /* rte_flow rules */
 	/* implicit rte_flow rules set when a remote device is active */
 	LIST_HEAD(tap_implicit_flows, rte_flow) implicit_flows;
+#endif
+
 	struct rx_queue rxq[RTE_PMD_TAP_MAX_QUEUES]; /* List of RX queues */
 	struct tx_queue txq[RTE_PMD_TAP_MAX_QUEUES]; /* List of TX queues */
 	struct rte_intr_handle *intr_handle;         /* LSC interrupt handle. */
drivers/net/tap/tap_bpf.h deleted +0 -121

121 lines not on this page · raw message

drivers/net/tap/tap_bpf_api.c +13 -7
index 15283f8917..9e05e2ddf1 100644
@@ -2,19 +2,19 @@
  * Copyright 2017 Mellanox Technologies, Ltd
  */
 
-#include <errno.h>
-#include <string.h>
 #include <unistd.h>
-#include <sys/queue.h>
+#include <syscall.h>
+#include <linux/bpf.h>
 
-#include <rte_malloc.h>
-#include <rte_eth_tap.h>
 #include <tap_flow.h>
 #include <tap_autoconf.h>
-#include <tap_tcmsgs.h>
-#include <tap_bpf.h>
+
 #include <tap_bpf_insns.h>
 
+
+static int bpf_load(enum bpf_prog_type type, const struct bpf_insn *insns,
+		size_t insns_cnt, const char *license);
+
 /**
  * Load BPF program (section cls_q) into the kernel and return a bpf fd
  *
@@ -89,7 +89,13 @@ static inline __u64 ptr_to_u64(const void *ptr)
 static inline int sys_bpf(enum bpf_cmd cmd, union bpf_attr *attr,
 			unsigned int size)
 {
+#ifdef __NR_bpf
 	return syscall(__NR_bpf, cmd, attr, size);
+#else
+	TAP_LOG(ERR, "No bpf syscall, kernel headers too old?\n");
+	errno = ENOSYS;
+	return -1;
+#endif
 }
 
 /**
drivers/net/tap/tap_bpf_insns.h +0 -2
index 53fa76c4e6..cdf2febf05 100644
@@ -3,8 +3,6 @@
  * This not the original source file. Do NOT edit it.
  */
 
-#include <tap_bpf.h>
-
 static struct bpf_insn cls_q_insns[] = {
 	{0x61,    2,    1,       52, 0x00000000},
 	{0x18,    3,    0,        0, 0xdeadbeef},
drivers/net/tap/tap_flow.c +0 -90

96 lines not on this page · raw message

Signature · 1 line
2.43.0
#185 lore raw

PATCH v14 6/11 net/tap: rewrite the RSS BPF program

In reply to Stephen Hemminger

Rewrite of the BPF program used to do queue based RSS.

Important changes:
- uses newer BPF map format BTF
- accepts key as parameter rather than constant default
- can do L3 or L4 hashing
- supports IPv4 options
- supports IPv6 extension headers
- restructured for readability

The usage of BPF is different as well:
- the incoming configuration is looked up based on class parameters rather than patching the BPF code.
- the resulting queue is placed in skb by using skb mark than requiring a second pass through classifier step.

Note: This version only works with later patch to enable it on the DPDK driver side. It is submitted as an incremental patch to allow for easier review. Bisection still works because the old instruction are still present for now.

---
 .gitignore                            |   3 -
 drivers/net/tap/bpf/Makefile          |  19 --
 drivers/net/tap/bpf/README            |  49 +++++
 drivers/net/tap/bpf/bpf_api.h         | 276 --------------------------
 drivers/net/tap/bpf/bpf_elf.h         |  53 -----
 drivers/net/tap/bpf/bpf_extract.py    |  85 --------
 drivers/net/tap/bpf/meson.build       |  81 ++++++++
 drivers/net/tap/bpf/tap_bpf_program.c | 255 ------------------------
 drivers/net/tap/bpf/tap_rss.c         | 267 +++++++++++++++++++++++++
 9 files changed, 397 insertions(+), 691 deletions(-)
 delete mode 100644 drivers/net/tap/bpf/Makefile
 create mode 100644 drivers/net/tap/bpf/README
 delete mode 100644 drivers/net/tap/bpf/bpf_api.h
 delete mode 100644 drivers/net/tap/bpf/bpf_elf.h
 delete mode 100644 drivers/net/tap/bpf/bpf_extract.py
 create mode 100644 drivers/net/tap/bpf/meson.build
 delete mode 100644 drivers/net/tap/bpf/tap_bpf_program.c
 create mode 100644 drivers/net/tap/bpf/tap_rss.c
.gitignore +0 -3
index 3f444dcace..01a47a7606 100644
@@ -36,9 +36,6 @@ TAGS
 # ignore python bytecode files
 *.pyc
 
-# ignore BPF programs
-drivers/net/tap/bpf/tap_bpf_program.o
-
 # DTS results
 dts/output
 
drivers/net/tap/bpf/Makefile deleted +0 -19
deleted file mode 100644
index 9efeeb1bc7..0000000000
@@ -1,19 +0,0 @@
-# SPDX-License-Identifier: BSD-3-Clause
-# This file is not built as part of normal DPDK build.
-# It is used to generate the eBPF code for TAP RSS.
-
-CLANG=clang
-CLANG_OPTS=-O2
-TARGET=../tap_bpf_insns.h
-
-all: $(TARGET)
-
-clean:
-	rm tap_bpf_program.o $(TARGET)
-
-tap_bpf_program.o: tap_bpf_program.c
-	$(CLANG) $(CLANG_OPTS) -emit-llvm -c $< -o - | \
-	llc -march=bpf -filetype=obj -o $@
-
-$(TARGET): tap_bpf_program.o
-	python3 bpf_extract.py -stap_bpf_program.c -o $@ $<
drivers/net/tap/bpf/README new file +49 -0

49 lines not on this page · raw message

drivers/net/tap/bpf/bpf_api.h deleted +0 -276

276 lines not on this page · raw message

drivers/net/tap/bpf/bpf_elf.h deleted +0 -53

53 lines not on this page · raw message

drivers/net/tap/bpf/bpf_extract.py deleted +0 -85

85 lines not on this page · raw message

drivers/net/tap/bpf/meson.build new file +81 -0

81 lines not on this page · raw message

drivers/net/tap/bpf/tap_bpf_program.c deleted +0 -255

255 lines not on this page · raw message

drivers/net/tap/bpf/tap_rss.c new file +267 -0

267 lines not on this page · raw message

Signature · 1 line
2.43.0
#186 lore raw

PATCH v14 7/11 net/tap: use libbpf to load new BPF program

In reply to Stephen Hemminger

There were multiple issues in the RSS queue support in the TAP driver. This required extensive rework of the BPF support.

Change the BPF loading to use bpftool to
create a skeleton header file, and load with libbpf. The BPF is always compiled from source so less chance that source and instructions diverge. Also resolves issue where libbpf and source get out of sync. The program
is only loaded once, so if multiple rules are created only one BPF program is loaded in kernel.

The new BPF program only needs a single action.
No need for action and re-classification step.

It also fixes the missing bits from the original.
- supports setting RSS key per flow
- level of hash can be L3 or L3/L4.

Bugzilla ID: 1329

---
 doc/guides/rel_notes/release_24_07.rst |   3 +
 drivers/net/tap/bpf/meson.build        |  81 +++--
 drivers/net/tap/meson.build            |  39 ++-
 drivers/net/tap/rte_eth_tap.c          |  14 +-
 drivers/net/tap/rte_eth_tap.h          |   6 +-
 drivers/net/tap/tap_flow.c             | 416 ++++++-------------------
 drivers/net/tap/tap_flow.h             |  17 +-
 drivers/net/tap/tap_rss.h              |  10 +-
 drivers/net/tap/tap_tcmsgs.h           |   4 +-
 9 files changed, 186 insertions(+), 404 deletions(-)
doc/guides/rel_notes/release_24_07.rst +3 -0
index fa9692924b..77562bbe3e 100644
@@ -59,6 +59,9 @@ New Features
 
   * Updated to support up to 8 queues when used by secondary process.
 
+  * Fixed support of RSS flow action to work with current Linux
+    kernels and BPF tooling. Will only be enabled if clang, libbpf 1.0
+    and bpftool are available.
 
 Removed Items
 -------------
drivers/net/tap/bpf/meson.build +47 -34

107 lines not on this page · raw message

drivers/net/tap/meson.build +18 -21
index 66647a1c62..5e5a3ad3c6 100644
@@ -5,36 +5,33 @@ if not is_linux
     build = false
     reason = 'only supported on Linux'
 endif
+
 sources = files(
         'rte_eth_tap.c',
         'tap_intr.c',
         'tap_netlink.c',
 )
 
+deps = ['bus_vdev', 'gso', 'hash']
+
+max_queues = '-DTAP_MAX_QUEUES=16'
+cflags += max_queues
+
+require_iova_in_mbuf = false
+
 if cc.has_header_symbol('linux/pkt_cls.h', 'TCA_FLOWER_ACT')
     cflags += '-DHAVE_TCA_FLOWER'
     sources += files(
-        'tap_bpf_api.c',
-        'tap_flow.c',
-        'tap_tcmsgs.c',
+            'tap_flow.c',
+            'tap_tcmsgs.c',
     )
-endif
-
-deps = ['bus_vdev', 'gso', 'hash']
 
-cflags += '-DTAP_MAX_QUEUES=16'
-
-# input array for meson symbol search:
-# [ "MACRO to define if found", "header for the search",
-#   "enum/define", "symbol to search" ]
-#
-args = [
-        [ 'HAVE_TC_ACT_BPF', 'linux/tc_act/tc_bpf.h', 'TCA_ACT_BPF_UNSPEC' ],
-]
-config = configuration_data()
-foreach arg:args
-    config.set(arg[0], cc.has_header_symbol(arg[1], arg[2]))
-endforeach
-configure_file(output : 'tap_autoconf.h', configuration : config)
+    enable_tap_rss = false
 
-require_iova_in_mbuf = false
+    subdir('bpf')
+    if enable_tap_rss
+        cflags += '-DHAVE_BPF_RSS'
+        ext_deps += libbpf
+        sources += tap_rss_skel_h
+    endif
+endif
drivers/net/tap/rte_eth_tap.c +7 -7
index 9058a47295..d847565073 100644
@@ -1140,6 +1140,7 @@ tap_dev_close(struct rte_eth_dev *dev)
 		tap_flow_implicit_flush(internals, NULL);
 		tap_nl_final(internals->nlsk_fd);
 		internals->nlsk_fd = -1;
+		tap_flow_bpf_destroy(internals);
 	}
 #endif
 
@@ -1949,6 +1950,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 	strlcpy(pmd->name, tap_name, sizeof(pmd->name));
 	pmd->type = type;
 	pmd->ka_fd = -1;
+
 #ifdef HAVE_TCA_FLOWER
 	pmd->nlsk_fd = -1;
 #endif
@@ -2031,13 +2033,6 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 	/* Make network device persist after application exit */
 	pmd->persist = persist;
 
-	pmd->if_index = if_nametoindex(pmd->name);
-	if (!pmd->if_index) {
-		TAP_LOG(ERR, "%s: failed to get if_index.", pmd->name);
-		goto disable_rte_flow;
-	}
-
-
 #ifdef HAVE_TCA_FLOWER
 	/*
 	 * Set up everything related to rte_flow:
@@ -2053,6 +2048,11 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 			pmd->name);
 		goto disable_rte_flow;
 	}
+	pmd->if_index = if_nametoindex(pmd->name);
+	if (!pmd->if_index) {
+		TAP_LOG(ERR, "%s: failed to get if_index.", pmd->name);
+		goto disable_rte_flow;
+	}
 	if (qdisc_create_multiq(pmd->nlsk_fd, pmd->if_index) < 0) {
 		TAP_LOG(ERR, "%s: failed to create multiq qdisc.",
 			pmd->name);
drivers/net/tap/rte_eth_tap.h +2 -4
index af18b29090..ce4322ad04 100644
@@ -81,10 +81,8 @@ struct pmd_internals {
 #ifdef HAVE_TCA_FLOWER
 	int nlsk_fd;                      /* Netlink socket fd */
 	int flow_isolate;                 /* 1 if flow isolation is enabled */
-	int rss_enabled;                  /* 1 if RSS is enabled, else 0 */
-	/* implicit rules set when RSS is enabled */
-	int map_fd;                       /* BPF RSS map fd */
-	int bpf_fd[RTE_PMD_TAP_MAX_QUEUES];/* List of bpf fds per queue */
+
+	struct tap_rss *rss;		  /* BPF program */
 
 	LIST_HEAD(tap_flows, rte_flow) flows;        /* rte_flow rules */
 	/* implicit rte_flow rules set when a remote device is active */
drivers/net/tap/tap_flow.c +97 -319

555 lines not on this page · raw message

drivers/net/tap/tap_flow.h +6 -11
index 240fbc3dfa..8b19347a93 100644
@@ -9,7 +9,11 @@
 #include <rte_flow.h>
 #include <rte_flow_driver.h>
 #include <rte_eth_tap.h>
-#include <tap_autoconf.h>
+
+/**
+ * Mask of unsupported RSS types
+ */
+#define TAP_RSS_HF_MASK (~(RTE_ETH_RSS_IP | RTE_ETH_RSS_UDP | RTE_ETH_RSS_TCP))
 
 /**
  * In TC, priority 0 means we require the kernel to allocate one for us.
@@ -41,11 +45,6 @@ enum implicit_rule_index {
 	TAP_REMOTE_MAX_IDX,
 };
 
-enum bpf_fd_idx {
-	SEC_L3_L4,
-	SEC_MAX,
-};
-
 int tap_dev_flow_ops_get(struct rte_eth_dev *dev,
 			 const struct rte_flow_ops **ops);
 int tap_flow_flush(struct rte_eth_dev *dev, struct rte_flow_error *error);
@@ -57,10 +56,6 @@ int tap_flow_implicit_destroy(struct pmd_internals *pmd,
 int tap_flow_implicit_flush(struct pmd_internals *pmd,
 			    struct rte_flow_error *error);
 
-int tap_flow_bpf_cls_q(__u32 queue_idx);
-int tap_flow_bpf_calc_l3_l4_hash(__u32 key_idx, int map_fd);
-int tap_flow_bpf_rss_map_create(unsigned int key_size, unsigned int value_size,
-			unsigned int max_entries);
-int tap_flow_bpf_update_rss_elem(int fd, void *key, void *value);
+void tap_flow_bpf_destroy(struct pmd_internals *pmd);
 
 #endif /* _TAP_FLOW_H_ */
drivers/net/tap/tap_rss.h +4 -6
index 6009be7031..65bd8991b1 100644
@@ -5,16 +5,14 @@
 #ifndef _TAP_RSS_H_
 #define _TAP_RSS_H_
 
-#ifndef TAP_MAX_QUEUES
-#define TAP_MAX_QUEUES 16
+/* Size of the map from BPF classid to queue table */
+#ifndef TAP_RSS_MAX
+#define TAP_RSS_MAX	32
 #endif
 
-/* Fixed RSS hash key size in bytes. */
+/* Standard Toeplitz hash key size */
 #define TAP_RSS_HASH_KEY_SIZE 40
 
-/* Supported RSS */
-#define TAP_RSS_HF_MASK (~(RTE_ETH_RSS_IP | RTE_ETH_RSS_UDP | RTE_ETH_RSS_TCP))
-
 /* hashed fields for RSS */
 enum hash_field {
 	HASH_FIELD_IPV4_L3,	/* IPv4 src/dst addr */
drivers/net/tap/tap_tcmsgs.h +2 -2
index a64cb29d6f..9411626661 100644
@@ -6,7 +6,6 @@
 #ifndef _TAP_TCMSGS_H_
 #define _TAP_TCMSGS_H_
 
-#include <tap_autoconf.h>
 #include <linux/if_ether.h>
 #include <linux/rtnetlink.h>
 #include <linux/pkt_sched.h>
@@ -14,9 +13,10 @@
 #include <linux/tc_act/tc_mirred.h>
 #include <linux/tc_act/tc_gact.h>
 #include <linux/tc_act/tc_skbedit.h>
-#ifdef HAVE_TC_ACT_BPF
+#ifdef HAVE_BPF_RSS
 #include <linux/tc_act/tc_bpf.h>
 #endif
+
 #include <inttypes.h>
 
 #include <rte_ether.h>
Signature · 1 line
2.43.0
#187 lore raw

PATCH v14 8/11 net/tap: remove no longer used files

In reply to Stephen Hemminger

The BPF api was replaced by use of libbpf. And the BPF instruction header is replaced by the new tap_rss.skel.h which is generated via bpftool.

---
 drivers/net/tap/tap_bpf_api.c   |  196 ----
 drivers/net/tap/tap_bpf_insns.h | 1741 -------------------------------
 2 files changed, 1937 deletions(-)
 delete mode 100644 drivers/net/tap/tap_bpf_api.c
 delete mode 100644 drivers/net/tap/tap_bpf_insns.h
drivers/net/tap/tap_bpf_api.c deleted +0 -196
deleted file mode 100644
index 9e05e2ddf1..0000000000
@@ -1,196 +0,0 @@
-/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright 2017 Mellanox Technologies, Ltd
- */
-
-#include <unistd.h>
-#include <syscall.h>
-#include <linux/bpf.h>
-
-#include <tap_flow.h>
-#include <tap_autoconf.h>
-
-#include <tap_bpf_insns.h>
-
-
-static int bpf_load(enum bpf_prog_type type, const struct bpf_insn *insns,
-		size_t insns_cnt, const char *license);
-
-/**
- * Load BPF program (section cls_q) into the kernel and return a bpf fd
- *
- * @param queue_idx
- *   Queue index matching packet cb
- *
- * @return
- *   -1 if the BPF program couldn't be loaded. An fd (int) otherwise.
- */
-int tap_flow_bpf_cls_q(__u32 queue_idx)
-{
-	cls_q_insns[1].imm = queue_idx;
-
-	return bpf_load(BPF_PROG_TYPE_SCHED_CLS,
-		(struct bpf_insn *)cls_q_insns,
-		RTE_DIM(cls_q_insns),
-		"Dual BSD/GPL");
-}
-
-/**
- * Load BPF program (section l3_l4) into the kernel and return a bpf fd.
- *
- * @param[in] key_idx
- *   RSS MAP key index
- *
- * @param[in] map_fd
- *   BPF RSS map file descriptor
- *
- * @return
- *   -1 if the BPF program couldn't be loaded. An fd (int) otherwise.
- */
-int tap_flow_bpf_calc_l3_l4_hash(__u32 key_idx, int map_fd)
-{
-	l3_l4_hash_insns[4].imm = key_idx;
-	l3_l4_hash_insns[9].imm = map_fd;
-
-	return bpf_load(BPF_PROG_TYPE_SCHED_ACT,
-		(struct bpf_insn *)l3_l4_hash_insns,
-		RTE_DIM(l3_l4_hash_insns),
-		"Dual BSD/GPL");
-}
-
-/**
- * Helper function to convert a pointer to unsigned 64 bits
- *
- * @param[in] ptr
- *   pointer to address
- *
- * @return
- *   64 bit unsigned long type of pointer address
- */
-static inline __u64 ptr_to_u64(const void *ptr)
-{
-	return (__u64)(unsigned long)ptr;
-}
-
-/**
- * Call BPF system call
- *
- * @param[in] cmd
- *   BPF command for program loading, map creation, map entry update, etc
- *
- * @param[in] attr
- *   System call attributes relevant to system call command
- *
- * @param[in] size
- *   size of attr parameter
- *
- * @return
- *   -1 if BPF system call failed, 0 otherwise
- */
-static inline int sys_bpf(enum bpf_cmd cmd, union bpf_attr *attr,
-			unsigned int size)
-{
-#ifdef __NR_bpf
-	return syscall(__NR_bpf, cmd, attr, size);
-#else
-	TAP_LOG(ERR, "No bpf syscall, kernel headers too old?\n");
-	errno = ENOSYS;
-	return -1;
-#endif
-}
-
-/**
- * Load BPF instructions to kernel
- *
- * @param[in] type
- *   BPF program type: classifier or action
- *
- * @param[in] insns
- *   Array of BPF instructions (equivalent to BPF instructions)
- *
- * @param[in] insns_cnt
- *   Number of BPF instructions (size of array)
- *
- * @param[in] license
- *   License string that must be acknowledged by the kernel
- *
- * @return
- *   -1 if the BPF program couldn't be loaded, fd (file descriptor) otherwise
- */
-static int bpf_load(enum bpf_prog_type type,
-		  const struct bpf_insn *insns,
-		  size_t insns_cnt,
-		  const char *license)
-{
-	union bpf_attr attr = {};
-
-	bzero(&attr, sizeof(attr));
-	attr.prog_type = type;
-	attr.insn_cnt = (__u32)insns_cnt;
-	attr.insns = ptr_to_u64(insns);
-	attr.license = ptr_to_u64(license);
-	attr.log_buf = ptr_to_u64(NULL);
-	attr.log_level = 0;
-	attr.kern_version = 0;
-
-	return sys_bpf(BPF_PROG_LOAD, &attr, sizeof(attr));
-}
-
-/**
- * Create BPF map for RSS rules
- *
- * @param[in] key_size
- *   map RSS key size
- *
- * @param[in] value_size
- *   Map RSS value size
- *
- * @param[in] max_entries
- *   Map max number of RSS entries (limit on max RSS rules)
- *
- * @return
- *   -1 if BPF map couldn't be created, map fd otherwise
- */
-int tap_flow_bpf_rss_map_create(unsigned int key_size,
-		unsigned int value_size,
-		unsigned int max_entries)
-{
-	union bpf_attr attr = {};
-
-	bzero(&attr, sizeof(attr));
-	attr.map_type    = BPF_MAP_TYPE_HASH;
-	attr.key_size    = key_size;
-	attr.value_size  = value_size;
-	attr.max_entries = max_entries;
-
-	return sys_bpf(BPF_MAP_CREATE, &attr, sizeof(attr));
-}
-
-/**
- * Update RSS entry in BPF map
- *
- * @param[in] fd
- *   RSS map fd
- *
- * @param[in] key
- *   Pointer to RSS key whose entry is updated
- *
- * @param[in] value
- *   Pointer to RSS new updated value
- *
- * @return
- *   -1 if RSS entry failed to be updated, 0 otherwise
- */
-int tap_flow_bpf_update_rss_elem(int fd, void *key, void *value)
-{
-	union bpf_attr attr = {};
-
-	bzero(&attr, sizeof(attr));
-
-	attr.map_type = BPF_MAP_TYPE_HASH;
-	attr.map_fd = fd;
-	attr.key = ptr_to_u64(key);
-	attr.value = ptr_to_u64(value);
-	attr.flags = BPF_ANY;
-
-	return sys_bpf(BPF_MAP_UPDATE_ELEM, &attr, sizeof(attr));
-}
drivers/net/tap/tap_bpf_insns.h deleted +0 -1741

1,741 lines not on this page · raw message

Signature · 1 line
2.43.0
#188 lore raw

PATCH v14 9/11 net/tap: simplify internals

In reply to Stephen Hemminger

The names of Linux network devices are IFNAMSIZ(16) not the same as DPDK which has up to 64 characters. Don't need to hold onto the whole ifreq to save the remote interface flags.

Make sure packet and byte counters are read once, so that global and per-queue values add up. No need for separate rx_nombuf counter since there is an alloc_failed value in ethdev.

Keep only the statistics that are used. I.e no ipackets on tx queues etc.

---
 drivers/net/tap/rte_eth_tap.c | 138 ++++++++++++++++++----------------
 drivers/net/tap/rte_eth_tap.h |  22 +++---
 2 files changed, 83 insertions(+), 77 deletions(-)
drivers/net/tap/rte_eth_tap.c +74 -64
index d847565073..3614aaf1dc 100644
@@ -46,6 +46,11 @@
 #include <tap_netlink.h>
 #include <tap_tcmsgs.h>
 
+/* Used to snapshot statistics */
+#ifndef READ_ONCE
+#define READ_ONCE(var) (*((volatile typeof(var) *)(&(var))))
+#endif
+
 /* Linux based path to the TUN device */
 #define TUN_TAP_DEV_PATH        "/dev/net/tun"
 #define DEFAULT_TAP_NAME        "dtap"
@@ -212,7 +217,7 @@ tun_alloc(struct pmd_internals *pmd, int is_keepalive, int persistent)
 	 * and need to find the resulting device.
 	 */
 	TAP_LOG(DEBUG, "Device name is '%s'", ifr.ifr_name);
-	strlcpy(pmd->name, ifr.ifr_name, RTE_ETH_NAME_MAX_LEN);
+	strlcpy(pmd->name, ifr.ifr_name, IFNAMSIZ);
 
 	if (is_keepalive) {
 		/*
@@ -454,7 +459,7 @@ pmd_rx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 
 		/* Packet couldn't fit in the provided mbuf */
 		if (unlikely(rxq->pi.flags & TUN_PKT_STRIP)) {
-			rxq->stats.ierrors++;
+			rxq->stats.errors++;
 			continue;
 		}
 
@@ -466,7 +471,8 @@ pmd_rx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 			struct rte_mbuf *buf = rte_pktmbuf_alloc(rxq->mp);
 
 			if (unlikely(!buf)) {
-				rxq->stats.rx_nombuf++;
+				rte_eth_devices[rxq->in_port].data->rx_mbuf_alloc_failed++;
+
 				/* No new buf has been allocated: do nothing */
 				if (!new_tail || !seg)
 					goto end;
@@ -511,8 +517,8 @@ pmd_rx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 		num_rx_bytes += mbuf->pkt_len;
 	}
 end:
-	rxq->stats.ipackets += num_rx;
-	rxq->stats.ibytes += num_rx_bytes;
+	rxq->stats.packets += num_rx;
+	rxq->stats.bytes += num_rx_bytes;
 
 	if (trigger && num_rx < nb_pkts)
 		rxq->trigger_seen = trigger;
@@ -692,7 +698,7 @@ pmd_tx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 			tso_segsz = mbuf_in->tso_segsz + hdrs_len;
 			if (unlikely(tso_segsz == hdrs_len) ||
 				tso_segsz > *txq->mtu) {
-				txq->stats.errs++;
+				txq->stats.errors++;
 				break;
 			}
 			gso_ctx->gso_size = tso_segsz;
@@ -730,7 +736,7 @@ pmd_tx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 		ret = tap_write_mbufs(txq, num_mbufs, mbuf,
 				&num_packets, &num_tx_bytes);
 		if (ret == -1) {
-			txq->stats.errs++;
+			txq->stats.errors++;
 			/* free tso mbufs */
 			if (num_tso_mbufs > 0)
 				rte_pktmbuf_free_bulk(mbuf, num_tso_mbufs);
@@ -748,9 +754,8 @@ pmd_tx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 		}
 	}
 
-	txq->stats.opackets += num_packets;
-	txq->stats.errs += nb_pkts - num_tx;
-	txq->stats.obytes += num_tx_bytes;
+	txq->stats.packets += num_packets;
+	txq->stats.bytes += num_tx_bytes;
 
 	return num_tx;
 }
@@ -1047,43 +1052,44 @@ tap_dev_info(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 static int
 tap_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *tap_stats)
 {
-	unsigned int i, imax;
-	unsigned long rx_total = 0, tx_total = 0, tx_err_total = 0;
-	unsigned long rx_bytes_total = 0, tx_bytes_total = 0;
-	unsigned long rx_nombuf = 0, ierrors = 0;
+	unsigned int i;
 	const struct pmd_internals *pmd = dev->data->dev_private;
+	uint64_t bytes, packets;
 
 	/* rx queue statistics */
-	imax = (dev->data->nb_rx_queues < RTE_ETHDEV_QUEUE_STAT_CNTRS) ?
-		dev->data->nb_rx_queues : RTE_ETHDEV_QUEUE_STAT_CNTRS;
-	for (i = 0; i < imax; i++) {
-		tap_stats->q_ipackets[i] = pmd->rxq[i].stats.ipackets;
-		tap_stats->q_ibytes[i] = pmd->rxq[i].stats.ibytes;
-		rx_total += tap_stats->q_ipackets[i];
-		rx_bytes_total += tap_stats->q_ibytes[i];
-		rx_nombuf += pmd->rxq[i].stats.rx_nombuf;
-		ierrors += pmd->rxq[i].stats.ierrors;
+	for (i = 0; i < dev->data->nb_rx_queues; i++) {
+		const struct rx_queue *rxq = &pmd->rxq[i];
+
+		packets = READ_ONCE(rxq->stats.packets);
+		bytes = READ_ONCE(rxq->stats.bytes);
+
+		tap_stats->ipackets += packets;
+		tap_stats->ibytes += bytes;
+		tap_stats->ierrors += rxq->stats.errors;
+
+		if (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) {
+			tap_stats->q_ipackets[i] = packets;
+			tap_stats->q_ibytes[i] = bytes;
+		}
 	}
 
 	/* tx queue statistics */
-	imax = (dev->data->nb_tx_queues < RTE_ETHDEV_QUEUE_STAT_CNTRS) ?
-		dev->data->nb_tx_queues : RTE_ETHDEV_QUEUE_STAT_CNTRS;
-
-	for (i = 0; i < imax; i++) {
-		tap_stats->q_opackets[i] = pmd->txq[i].stats.opackets;
-		tap_stats->q_obytes[i] = pmd->txq[i].stats.obytes;
-		tx_total += tap_stats->q_opackets[i];
-		tx_err_total += pmd->txq[i].stats.errs;
-		tx_bytes_total += tap_stats->q_obytes[i];
-	}
-
-	tap_stats->ipackets = rx_total;
-	tap_stats->ibytes = rx_bytes_total;
-	tap_stats->ierrors = ierrors;
-	tap_stats->rx_nombuf = rx_nombuf;
-	tap_stats->opackets = tx_total;
-	tap_stats->oerrors = tx_err_total;
-	tap_stats->obytes = tx_bytes_total;
+	for (i = 0; i < dev->data->nb_tx_queues; i++) {
+		const struct tx_queue *txq = &pmd->txq[i];
+
+		packets = READ_ONCE(txq->stats.packets);
+		bytes = READ_ONCE(txq->stats.bytes);
+
+		tap_stats->opackets += packets;
+		tap_stats->obytes += bytes;
+		tap_stats->oerrors += txq->stats.errors;
+
+		if (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) {
+			tap_stats->q_opackets[i] = packets;
+			tap_stats->q_obytes[i] = bytes;
+		}
+	}
+
 	return 0;
 }
 
@@ -1094,14 +1100,8 @@ tap_stats_reset(struct rte_eth_dev *dev)
 	struct pmd_internals *pmd = dev->data->dev_private;
 
 	for (i = 0; i < RTE_PMD_TAP_MAX_QUEUES; i++) {
-		pmd->rxq[i].stats.ipackets = 0;
-		pmd->rxq[i].stats.ibytes = 0;
-		pmd->rxq[i].stats.ierrors = 0;
-		pmd->rxq[i].stats.rx_nombuf = 0;
-
-		pmd->txq[i].stats.opackets = 0;
-		pmd->txq[i].stats.errs = 0;
-		pmd->txq[i].stats.obytes = 0;
+		memset(&pmd->rxq[i].stats, 0, sizeof(struct pkt_stats));
+		memset(&pmd->txq[i].stats, 0, sizeof(struct pkt_stats));
 	}
 
 	return 0;
@@ -1156,9 +1156,13 @@ tap_dev_close(struct rte_eth_dev *dev)
 	}
 
 	if (internals->remote_if_index) {
+		struct ifreq remote_ifr;
+
+		strlcpy(remote_ifr.ifr_name, internals->remote_iface, IFNAMSIZ);
+		remote_ifr.ifr_flags = internals->remote_flags;
+
 		/* Restore initial remote state */
-		int ret = ioctl(internals->ioctl_sock, SIOCSIFFLAGS,
-				&internals->remote_initial_flags);
+		int ret = ioctl(internals->ioctl_sock, SIOCSIFFLAGS, &remote_ifr);
 		if (ret)
 			TAP_LOG(ERR, "restore remote state failed: %d", ret);
 
@@ -2067,16 +2071,22 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 	LIST_INIT(&pmd->flows);
 
 	if (strlen(remote_iface)) {
+		struct ifreq remote_ifr;
+
 		pmd->remote_if_index = if_nametoindex(remote_iface);
 		if (!pmd->remote_if_index) {
 			TAP_LOG(ERR, "%s: failed to get %s if_index.",
 				pmd->name, remote_iface);
 			goto error_remote;
 		}
-		strlcpy(pmd->remote_iface, remote_iface, RTE_ETH_NAME_MAX_LEN);
+		strlcpy(pmd->remote_iface, remote_iface, IFNAMSIZ);
+
+		memset(&remote_ifr, 0, sizeof(ifr));
+		strlcpy(remote_ifr.ifr_name, remote_iface, IFNAMSIZ);
 
 		/* Save state of remote device */
-		tap_ioctl(pmd, SIOCGIFFLAGS, &pmd->remote_initial_flags, 0, REMOTE_ONLY);
+		tap_ioctl(pmd, SIOCGIFFLAGS, &remote_ifr, 0, REMOTE_ONLY);
+		pmd->remote_flags = remote_ifr.ifr_flags;
 
 		/* Replicate remote MAC address */
 		if (tap_ioctl(pmd, SIOCGIFHWADDR, &ifr, 0, REMOTE_ONLY) < 0) {
@@ -2190,10 +2200,10 @@ set_interface_name(const char *key __rte_unused,
 				value);
 			return -1;
 		}
-		strlcpy(name, value, RTE_ETH_NAME_MAX_LEN);
+		strlcpy(name, value, IFNAMSIZ);
 	} else {
 		/* use tap%d which causes kernel to choose next available */
-		strlcpy(name, DEFAULT_TAP_NAME "%d", RTE_ETH_NAME_MAX_LEN);
+		strlcpy(name, DEFAULT_TAP_NAME "%d", IFNAMSIZ);
 	}
 	return 0;
 }
@@ -2211,7 +2221,7 @@ set_remote_iface(const char *key __rte_unused,
 				value);
 			return -1;
 		}
-		strlcpy(name, value, RTE_ETH_NAME_MAX_LEN);
+		strlcpy(name, value, IFNAMSIZ);
 	}
 
 	return 0;
@@ -2262,13 +2272,13 @@ rte_pmd_tun_probe(struct rte_vdev_device *dev)
 	const char *name, *params;
 	int ret;
 	struct rte_kvargs *kvlist = NULL;
-	char tun_name[RTE_ETH_NAME_MAX_LEN];
-	char remote_iface[RTE_ETH_NAME_MAX_LEN];
+	char tun_name[IFNAMSIZ];
+	char remote_iface[IFNAMSIZ];
 	struct rte_eth_dev *eth_dev;
 
 	name = rte_vdev_device_name(dev);
 	params = rte_vdev_device_args(dev);
-	memset(remote_iface, 0, RTE_ETH_NAME_MAX_LEN);
+	memset(remote_iface, 0, IFNAMSIZ);
 
 	if (rte_eal_process_type() == RTE_PROC_SECONDARY &&
 	    strlen(params) == 0) {
@@ -2284,7 +2294,7 @@ rte_pmd_tun_probe(struct rte_vdev_device *dev)
 	}
 
 	/* use tun%d which causes kernel to choose next available */
-	strlcpy(tun_name, DEFAULT_TUN_NAME "%d", RTE_ETH_NAME_MAX_LEN);
+	strlcpy(tun_name, DEFAULT_TUN_NAME "%d", IFNAMSIZ);
 
 	if (params && (params[0] != '\0')) {
 		TAP_LOG(DEBUG, "parameters (%s)", params);
@@ -2424,8 +2434,8 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev)
 	int ret;
 	struct rte_kvargs *kvlist = NULL;
 	int speed;
-	char tap_name[RTE_ETH_NAME_MAX_LEN];
-	char remote_iface[RTE_ETH_NAME_MAX_LEN];
+	char tap_name[IFNAMSIZ];
+	char remote_iface[IFNAMSIZ];
 	struct rte_ether_addr user_mac = { .addr_bytes = {0} };
 	struct rte_eth_dev *eth_dev;
 	int tap_devices_count_increased = 0;
@@ -2479,8 +2489,8 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev)
 	speed = RTE_ETH_SPEED_NUM_10G;
 
 	/* use tap%d which causes kernel to choose next available */
-	strlcpy(tap_name, DEFAULT_TAP_NAME "%d", RTE_ETH_NAME_MAX_LEN);
-	memset(remote_iface, 0, RTE_ETH_NAME_MAX_LEN);
+	strlcpy(tap_name, DEFAULT_TAP_NAME "%d", IFNAMSIZ);
+	memset(remote_iface, 0, IFNAMSIZ);
 
 	if (params && (params[0] != '\0')) {
 		TAP_LOG(DEBUG, "parameters (%s)", params);
drivers/net/tap/rte_eth_tap.h +9 -13
index ce4322ad04..8f9ab613c7 100644
@@ -34,13 +34,9 @@ enum rte_tuntap_type {
 };
 
 struct pkt_stats {
-	uint64_t opackets;              /* Number of output packets */
-	uint64_t ipackets;              /* Number of input packets */
-	uint64_t obytes;                /* Number of bytes on output */
-	uint64_t ibytes;                /* Number of bytes on input */
-	uint64_t errs;                  /* Number of TX error packets */
-	uint64_t ierrors;               /* Number of RX error packets */
-	uint64_t rx_nombuf;             /* Nb of RX mbuf alloc failures */
+	uint64_t packets;       /* Number of packets */
+	uint64_t bytes;         /* Number of bytes */
+	uint64_t errors;        /* Number of errors */
 };
 
 struct rx_queue {
@@ -68,15 +64,16 @@ struct tx_queue {
 
 struct pmd_internals {
 	struct rte_eth_dev *dev;          /* Ethernet device. */
-	char remote_iface[RTE_ETH_NAME_MAX_LEN]; /* Remote netdevice name */
-	char name[RTE_ETH_NAME_MAX_LEN];  /* Internal Tap device name */
+	char remote_iface[IFNAMSIZ];	  /* Remote netdevice name */
+	char name[IFNAMSIZ];		  /* Internal Tap device name */
 	int type;                         /* Type field - TUN|TAP */
 	int persist;			  /* 1 if keep link up, else 0 */
 	struct rte_ether_addr eth_addr;   /* Mac address of the device port */
-	struct ifreq remote_initial_flags;/* Remote netdevice flags on init */
+	uint16_t remote_flags;		  /* Remote netdevice flags on init */
 	int remote_if_index;              /* remote netdevice IF_INDEX */
 	int if_index;                     /* IF_INDEX for the port */
 	int ioctl_sock;                   /* socket for ioctl calls */
+	int ka_fd;                        /* keep-alive file descriptor */
 
 #ifdef HAVE_TCA_FLOWER
 	int nlsk_fd;                      /* Netlink socket fd */
@@ -88,12 +85,11 @@ struct pmd_internals {
 	/* implicit rte_flow rules set when a remote device is active */
 	LIST_HEAD(tap_implicit_flows, rte_flow) implicit_flows;
 #endif
+	struct rte_intr_handle *intr_handle;         /* LSC interrupt handle. */
+	struct rte_mempool *gso_ctx_mp;     /* Mempool for GSO packets */
 
 	struct rx_queue rxq[RTE_PMD_TAP_MAX_QUEUES]; /* List of RX queues */
 	struct tx_queue txq[RTE_PMD_TAP_MAX_QUEUES]; /* List of TX queues */
-	struct rte_intr_handle *intr_handle;         /* LSC interrupt handle. */
-	int ka_fd;                        /* keep-alive file descriptor */
-	struct rte_mempool *gso_ctx_mp;     /* Mempool for GSO packets */
 };
 
 struct pmd_process_private {
Signature · 1 line
2.43.0
#189 lore raw

PATCH v14 10/11 net/tap: remove extraneous newlines

In reply to Stephen Hemminger

Some log messages contained extra newlines.

---
 drivers/net/tap/rte_eth_tap.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)
drivers/net/tap/rte_eth_tap.c +8 -9
index 3614aaf1dc..2484a82ccb 100644
@@ -235,9 +235,8 @@ tun_alloc(struct pmd_internals *pmd, int is_keepalive, int persistent)
 
 	flags = fcntl(fd, F_GETFL);
 	if (flags == -1) {
-		TAP_LOG(WARNING,
-			"Unable to get %s current flags\n",
-			ifr.ifr_name);
+		TAP_LOG(WARNING, "Unable to get %s current flags: %s",
+			ifr.ifr_name, strerror(errno));
 		goto error;
 	}
 
@@ -279,7 +278,7 @@ tun_alloc(struct pmd_internals *pmd, int is_keepalive, int persistent)
 
 		if (sigaction(signo, &sa, NULL) == -1) {
 			TAP_LOG(WARNING,
-				"Unable to set rt-signal %d handler\n", signo);
+				"Unable to set rt-signal %d handler", signo);
 			goto error;
 		}
 
@@ -290,11 +289,11 @@ tun_alloc(struct pmd_internals *pmd, int is_keepalive, int persistent)
 	}
 
 	if (signo == SIGRTMAX) {
-		TAP_LOG(WARNING, "All rt-signals are in use\n");
+		TAP_LOG(WARNING, "All rt-signals are in use");
 
 		/* Disable trigger globally in case of error */
 		tap_trigger = 0;
-		TAP_LOG(NOTICE, "No Rx trigger signal available\n");
+		TAP_LOG(NOTICE, "No Rx trigger signal available");
 	} else {
 		/* Enable signal on file descriptor */
 		if (fcntl(fd, F_SETSIG, signo) < 0) {
@@ -920,7 +919,7 @@ tap_mp_req_start_rxtx(const struct rte_mp_msg *request, __rte_unused const void
 	}
 
 	process_private = dev->process_private;
-	TAP_LOG(DEBUG, "tap_attach q:%d\n", request_param->q_count);
+	TAP_LOG(DEBUG, "tap_attach q:%d", request_param->q_count);
 
 	for (int q = 0; q < request_param->q_count; q++)
 		process_private->fds[q] = request->fds[q];
@@ -1463,7 +1462,7 @@ tap_gso_ctx_setup(struct rte_gso_ctx *gso_ctx, struct rte_eth_dev *dev)
 		if (ret < 0 || ret >= (int)sizeof(pool_name)) {
 			TAP_LOG(ERR,
 				"%s: failed to create mbuf pool name for device %s,"
-				"device name too long or output error, ret: %d\n",
+				"device name too long or output error, ret: %d",
 				pmd->name, dev->device->name, ret);
 			return -ENAMETOOLONG;
 		}
@@ -1473,7 +1472,7 @@ tap_gso_ctx_setup(struct rte_gso_ctx *gso_ctx, struct rte_eth_dev *dev)
 			SOCKET_ID_ANY);
 		if (!pmd->gso_ctx_mp) {
 			TAP_LOG(ERR,
-				"%s: failed to create mbuf pool for device %s\n",
+				"%s: failed to create mbuf pool for device %s",
 				pmd->name, dev->device->name);
 			return -1;
 		}
Signature · 1 line
2.43.0
#190 lore raw

PATCH v14 11/11 net/tap: update documentation

In reply to Stephen Hemminger

The driver support of flows has changed and the wording in the guide was awkward.

Drop references to DPDK pktgen in this documentation since it is not required, confusing and abandoned.

---
 doc/guides/nics/tap.rst | 274 +++++++++++-----------------------------
 1 file changed, 77 insertions(+), 197 deletions(-)
doc/guides/nics/tap.rst +77 -197
index d4f45c02a1..55e38fb25b 100644
@@ -1,47 +1,51 @@
 ..  SPDX-License-Identifier: BSD-3-Clause
     Copyright(c) 2016 Intel Corporation.
 
-Tun|Tap Poll Mode Driver
-========================
+TAP Poll Mode Driver
+====================
 
-The ``rte_eth_tap.c`` PMD creates a device using TAP interfaces on the
-local host. The PMD allows for DPDK and the host to communicate using a raw
-device interface on the host and in the DPDK application.
+The TAP Poll Mode Driver (PMD) is a virtual device for injecting packets to be processed
+by the Linux kernel. This PMD is useful when writing DPDK application
+for offloading network functionality (such as tunneling) from the kernel.
 
-The device created is a TAP device, which sends/receives packet in a raw
-format with a L2 header. The usage for a TAP PMD is for connectivity to the
-local host using a TAP interface. When the TAP PMD is initialized it will
-create a number of tap devices in the host accessed via ``ifconfig -a`` or
-``ip`` command. The commands can be used to assign and query the virtual like
-device.
+From the kernel point of view, the TAP device looks like a regular network interface.
+The network device can be managed by standard tools such as ``ip`` and ``ethtool`` commands.
+It is also possible to use existing packet tools such as  ``wireshark`` or ``tcpdump``.
 
-These TAP interfaces can be used with Wireshark or tcpdump or Pktgen-DPDK
-along with being able to be used as a network connection to the DPDK
-application. The method enable one or more interfaces is to use the
-``--vdev=net_tap0`` option on the DPDK application command line. Each
-``--vdev=net_tap1`` option given will create an interface named dtap0, dtap1,
-and so on.
+From the DPDK application, the TAP device looks like a DPDK ethdev.
+Packets are sent and received in L2 (Ethernet) format. The standare DPDK
+API's to query for information, statistics and send and receive packets
+work as expected.
 
-The interface name can be changed by adding the ``iface=foo0``, for example::
+Requirements
+~~~~~~~~~~~~
+
+The TAP PMD requires kernel support for multiple queues in TAP device as
+well as the multi-queue ``multiq`` and incoming ``ingress`` queue disciplines.
+These are standard kernel features in most Linux distributions.
+
+Arguments
+---------
+
+TAP devices are created with the command line
+``--vdev=net_tap0`` option. This option maybe specified more the once by repeating
+with a different ``net_tapX`` device.
+
+By default, the Linux interfaces are named ``dtap0``, ``dtap1``, etc.
+The interface name can be specified by adding the ``iface=foo0``, for example::
 
    --vdev=net_tap0,iface=foo0 --vdev=net_tap1,iface=foo1, ...
 
-Normally the PMD will generate a random MAC address, but when testing or with
-a static configuration the developer may need a fixed MAC address style.
-Using the option ``mac=fixed`` you can create a fixed known MAC address::
+Normally the PMD will generate a random MAC address.
+If a static address is desired instead, the ``mac=fixed`` can be used.
 
    --vdev=net_tap0,mac=fixed
 
-The MAC address will have a fixed value with the last octet incrementing by one
-for each interface string containing ``mac=fixed``. The MAC address is formatted
-as 02:'d':'t':'a':'p':[00-FF]. Convert the characters to hex and you get the
-actual MAC address: ``02:64:74:61:70:[00-FF]``.
-
-   --vdev=net_tap0,mac="02:64:74:61:70:11"
+With the fixed option, the MAC address will have the first octets:
+as 02:'d':'t':'a':'p':[00-FF] and the last octets are the interface number.
 
-The MAC address will have a user value passed as string. The MAC address is in
-format with delimiter ``:``. The string is byte converted to hex and you get
-the actual MAC address: ``02:64:74:61:70:11``.
+To specify a specific MAC address use the conventional representation.
+The string is byte converted to hex, the result is MAC address: ``02:64:74:61:70:11``.
 
 It is possible to specify a remote netdevice to capture packets from by adding
 ``remote=foo1``, for example::
@@ -59,40 +63,20 @@ netdevice that has no support in the DPDK. It is possible to add explicit
 rte_flow rules on the tap PMD to capture specific traffic (see next section for
 examples).
 
-After the DPDK application is started you can send and receive packets on the
-interface using the standard rx_burst/tx_burst APIs in DPDK. From the host
-point of view you can use any host tool like tcpdump, Wireshark, ping, Pktgen
-and others to communicate with the DPDK application. The DPDK application may
-not understand network protocols like IPv4/6, UDP or TCP unless the
-application has been written to understand these protocols.
-
-If you need the interface as a real network interface meaning running and has
-a valid IP address then you can do this with the following commands::
-
-   sudo ip link set dtap0 up; sudo ip addr add 192.168.0.250/24 dev dtap0
-   sudo ip link set dtap1 up; sudo ip addr add 192.168.1.250/24 dev dtap1
-
-Please change the IP addresses as you see fit.
-
-If routing is enabled on the host you can also communicate with the DPDK App
-over the internet via a standard socket layer application as long as you
-account for the protocol handling in the application.
-
-If you have a Network Stack in your DPDK application or something like it you
-can utilize that stack to handle the network protocols. Plus you would be able
-to address the interface using an IP address assigned to the internal
-interface.
-
 Normally, when the DPDK application exits,
 the TAP device is marked down and is removed.
-But this behaviour can be overridden by the use of the persist flag, example::
+But this behavior can be overridden by the use of the persist flag, example::
 
   --vdev=net_tap0,iface=tap0,persist ...
 
-The TUN PMD allows user to create a TUN device on host. The PMD allows user
-to transmit and receive packets via DPDK API calls with L3 header and payload.
-The devices in host can be accessed via ``ifconfig`` or ``ip`` command. TUN
-interfaces are passed to DPDK ``rte_eal_init`` arguments as ``--vdev=net_tunX``,
+TUN devices
+-----------
+
+The TAP device can be used an L3 tunnel only device (TUN).
+This type of device does not include the Ethernet (L2) header; all packets
+are sent and received as IP packets.
+
+TUN devices are created with the command line arguments ``--vdev=net_tunX``,
 where X stands for unique id, example::
 
    --vdev=net_tun0 --vdev=net_tun1,iface=foo1, ...
@@ -103,27 +87,33 @@ options. Default interface name is ``dtunX``, where X stands for unique id.
 Flow API support
 ----------------
 
-The tap PMD supports major flow API pattern items and actions, when running on
-linux kernels above 4.2 ("Flower" classifier required).
-The kernel support can be checked with this command::
+The TAP PMD supports major flow API pattern items and actions.
+
+Requirements
+~~~~~~~~~~~~
 
-   zcat /proc/config.gz | ( grep 'CLS_FLOWER=' || echo 'not supported' ) |
-   tee -a /dev/stderr | grep -q '=m' &&
-   lsmod | ( grep cls_flower || echo 'try modprobe cls_flower' )
+Flow support in TAP driver requires the Linux kernel support of flow based
+traffic control filter ``flower``. This was added in Linux 4.3 kernel.
 
-Supported items:
+The implementation of RSS action uses an eBPF module that requires additional
+libraries and tools. Building the RSS support requires the ``clang``
+compiler to compile the C code to BPF target; ``bpftool`` to convert the
+compiled BPF object to a header file; and ``libbpf`` to load the eBPF
+action into the kernel.
 
-- eth: src and dst (with variable masks), and eth_type (0xffff mask).
-- vlan: vid, pcp, but not eid. (requires kernel 4.9)
-- ipv4/6: src and dst (with variable masks), and ip_proto (0xffff mask).
-- udp/tcp: src and dst port (0xffff) mask.
+Supported match items:
+
+  - eth: src and dst (with variable masks), and eth_type (0xffff mask).
+  - vlan: vid, pcp, but not eid. (requires kernel 4.9)
+  - ipv4/6: src and dst (with variable masks), and ip_proto (0xffff mask).
+  - udp/tcp: src and dst port (0xffff) mask.
 
 Supported actions:
 
 - DROP
 - QUEUE
 - PASSTHRU
-- RSS (requires kernel 4.9)
+- RSS
 
 It is generally not possible to provide a "last" item. However, if the "last"
 item, once masked, is identical to the masked spec, then it is supported.
@@ -133,7 +123,7 @@ full mask (exact match).
 
 As rules are translated to TC, it is possible to show them with something like::
 
-   tc -s filter show dev tap1 parent 1:
+   tc -s filter show dev dtap1 parent 1:
 
 Examples of testpmd flow rules
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -174,135 +164,25 @@ The IPC synchronization of Rx/Tx queues is currently limited:
   - Maximum 8 queues shared
   - Synchronized on probing, but not on later port update
 
-Example
--------
-
-The following is a simple example of using the TAP PMD with the Pktgen
-packet generator. It requires that the ``socat`` utility is installed on the
-test system.
-
-Build DPDK, then pull down Pktgen and build pktgen using the DPDK SDK/Target
-used to build the dpdk you pulled down.
-
-Run pktgen from the pktgen directory in a terminal with a commandline like the
-following::
-
-    sudo ./app/app/x86_64-native-linux-gcc/app/pktgen -l 1-5 -n 4        \
-     --proc-type auto --log-level debug --socket-mem 512,512 --file-prefix pg   \
-     --vdev=net_tap0 --vdev=net_tap1 -b 05:00.0 -b 05:00.1                  \
-     -b 04:00.0 -b 04:00.1 -b 04:00.2 -b 04:00.3                            \
-     -b 81:00.0 -b 81:00.1 -b 81:00.2 -b 81:00.3                            \
-     -b 82:00.0 -b 83:00.0 -- -T -P -m [2:3].0 -m [4:5].1                   \
-     -f themes/black-yellow.theme
-
-.. Note:
-
-   Change the ``-b`` options to exclude all of your physical ports. The
-   following command line is all one line.
-
-   Also, ``-f themes/black-yellow.theme`` is optional if the default colors
-   work on your system configuration. See the Pktgen docs for more
-   information.
-
-Verify with ``ifconfig -a`` command in a different xterm window, should have a
-``dtap0`` and ``dtap1`` interfaces created.
-
-Next set the links for the two interfaces to up via the commands below::
-
-    sudo ip link set dtap0 up; sudo ip addr add 192.168.0.250/24 dev dtap0
-    sudo ip link set dtap1 up; sudo ip addr add 192.168.1.250/24 dev dtap1
-
-Then use socat to create a loopback for the two interfaces::
-
-    sudo socat interface:dtap0 interface:dtap1
-
-Then on the Pktgen command line interface you can start sending packets using
-the commands ``start 0`` and ``start 1`` or you can start both at the same
-time with ``start all``. The command ``str`` is an alias for ``start all`` and
-``stp`` is an alias for ``stop all``.
-
-While running you should see the 64 byte counters increasing to verify the
-traffic is being looped back. You can use ``set all size XXX`` to change the
-size of the packets after you stop the traffic. Use pktgen ``help``
-command to see a list of all commands. You can also use the ``-f`` option to
-load commands at startup in command line or Lua script in pktgen.
 
 RSS specifics
 -------------
-Packet distribution in TAP is done by the kernel which has a default
-distribution. This feature is adding RSS distribution based on eBPF code.
-The default eBPF code calculates RSS hash based on Toeplitz algorithm for
-a fixed RSS key. It is calculated on fixed packet offsets. For IPv4 and IPv6 it
-is calculated over src/dst addresses (8 or 32 bytes for IPv4 or IPv6
-respectively) and src/dst TCP/UDP ports (4 bytes).
-
-The RSS algorithm is written in file ``tap_bpf_program.c`` which
-does not take part in TAP PMD compilation. Instead this file is compiled
-in advance to eBPF object file. The eBPF object file is then parsed and
-translated into eBPF byte code in the format of C arrays of eBPF
-instructions. The C array of eBPF instructions is part of TAP PMD tree and
-is taking part in TAP PMD compilation. At run time the C arrays are uploaded to
-the kernel via BPF system calls and the RSS hash is calculated by the
-kernel.
-
-It is possible to support different RSS hash algorithms by updating file
-``tap_bpf_program.c``  In order to add a new RSS hash algorithm follow these
-steps:
-
-#. Write the new RSS implementation in file ``tap_bpf_program.c``
-
-   BPF programs which are uploaded to the kernel correspond to
-   C functions under different ELF sections.
-
-#. Install ``LLVM`` library and ``clang`` compiler versions 3.7 and above
-
-#. Use make to compile  `tap_bpf_program.c`` via ``LLVM`` into an object file
-   and extract the resulting instructions into ``tap_bpf_insn.h``::
-
-    cd bpf; make
-
-#. Recompile the TAP PMD.
-
-The C arrays are uploaded to the kernel using BPF system calls.
-
-``tc`` (traffic control) is a well known user space utility program used to
-configure the Linux kernel packet scheduler. It is usually packaged as
-part of the ``iproute2`` package.
-Since commit 11c39b5e9 ("tc: add eBPF support to f_bpf") ``tc`` can be used
-to uploads eBPF code to the kernel and can be patched in order to print the
-C arrays of eBPF instructions just before calling the BPF system call.
-Please refer to ``iproute2`` package file ``lib/bpf.c`` function
-``bpf_prog_load()``.
-
-An example utility for eBPF instruction generation in the format of C arrays will
-be added in next releases
-
-TAP reports on supported RSS functions as part of dev_infos_get callback:
-``RTE_ETH_RSS_IP``, ``RTE_ETH_RSS_UDP`` and ``RTE_ETH_RSS_TCP``.
-**Known limitation:** TAP supports all of the above hash functions together
-and not in partial combinations.
-
-Systems supporting flow API
----------------------------
-
-- "tc flower" classifier requires linux kernel above 4.2
-- eBPF/RSS requires linux kernel above 4.9
-
-+--------------------+-----------------------+
-| RH7.3              | No flow rule support  |
-+--------------------+-----------------------+
-| RH7.4              | No RSS action support |
-+--------------------+-----------------------+
-| RH7.5              | No RSS action support |
-+--------------------+-----------------------+
-| SLES 15,           | No limitation         |
-| kernel 4.12        |                       |
-+--------------------+-----------------------+
-| Azure Ubuntu 16.04,| No limitation         |
-| kernel 4.13        |                       |
-+--------------------+-----------------------+
+The default packet distribution in TAP without flow rules is done by the
+kernel which has a default flow based distribution.
+When flow rules are used to distribute packets across a set of queues
+an eBPF program is used to calculate the RSS based on Toeplitz algorithm for
+with the given key.
+
+The hash is calculated for IPv4 and IPv6, over src/dst addresses
+(8 or 32 bytes for IPv4 or IPv6 respectively) and
+optionally the src/dst TCP/UDP ports (4 bytes).
+
 
 Limitations
 -----------
 
-* Rx/Tx must have the same number of queues.
+- Since TAP device uses a file descriptors to talk to the kernel.
+  The same number of queues must be specified for receive and transmit.
+
+- The RSS algorithm only support L3 or L4 functions. It does not support
+  finer grain selections (for example: only IPV6 packets with extension headers).
Signature · 1 line
2.43.0
#191 lore raw

v15 cover net/tap: make RSS work again

In reply to Stephen Hemminger

The support of doing RSS for rte_flow_action was a cool idea but it has been broken for several releases of DPDK as the underlying kernel and BPF infrastructure changed.

This series cleans up the BPF program, implements several features that were never completed in the original code and changes to use the current BPF tool chain.

The result should be easier to read and maintain. I do not intend to support backporting this to stable releases due to lack of demand and dealing with older distros.

v15 - fix formatting in new release note

Stephen Hemminger (11):
net/tap: fix fd check in flow_isolate
net/tap: do not duplicate fd's
net/tap: remove unused fields
net/tap: validate and setup parameters for BPF RSS net/tap: do not build flow support if header is out of date net/tap: rewrite the RSS BPF program
net/tap: use libbpf to load new BPF program net/tap: remove no longer used files
net/tap: simplify internals
net/tap: remove extraneous newlines
net/tap: update documentation

 .gitignore                             |    3 -
 doc/guides/nics/tap.rst                |  274 ++--
 doc/guides/rel_notes/release_24_07.rst |    7 +
 drivers/net/tap/bpf/Makefile           |   19 -
 drivers/net/tap/bpf/README             |   49 +
 drivers/net/tap/bpf/bpf_api.h          |  276 ----
 drivers/net/tap/bpf/bpf_elf.h          |   53 -
 drivers/net/tap/bpf/bpf_extract.py     |   86 --
 drivers/net/tap/bpf/meson.build        |   94 ++
 drivers/net/tap/bpf/tap_bpf_program.c  |  255 ----
 drivers/net/tap/bpf/tap_rss.c          |  267 ++++
 drivers/net/tap/meson.build            |   42 +-
 drivers/net/tap/rte_eth_tap.c          |  373 +++--
 drivers/net/tap/rte_eth_tap.h          |   42 +-
 drivers/net/tap/tap_bpf.h              |  121 --
 drivers/net/tap/tap_bpf_api.c          |  190 ---
 drivers/net/tap/tap_bpf_insns.h        | 1743 ------------------------
 drivers/net/tap/tap_flow.c             |  565 +++-----
 drivers/net/tap/tap_flow.h             |   17 +-
 drivers/net/tap/tap_intr.c             |    7 +-
 drivers/net/tap/tap_rss.h              |   21 +-
 drivers/net/tap/tap_tcmsgs.h           |    4 +-
 22 files changed, 896 insertions(+), 3612 deletions(-)
 delete mode 100644 drivers/net/tap/bpf/Makefile
 create mode 100644 drivers/net/tap/bpf/README
 delete mode 100644 drivers/net/tap/bpf/bpf_api.h
 delete mode 100644 drivers/net/tap/bpf/bpf_elf.h
 delete mode 100644 drivers/net/tap/bpf/bpf_extract.py
 create mode 100644 drivers/net/tap/bpf/meson.build
 delete mode 100644 drivers/net/tap/bpf/tap_bpf_program.c
 create mode 100644 drivers/net/tap/bpf/tap_rss.c
 delete mode 100644 drivers/net/tap/tap_bpf.h
 delete mode 100644 drivers/net/tap/tap_bpf_api.c
 delete mode 100644 drivers/net/tap/tap_bpf_insns.h
Signature · 1 line
2.43.0
#192 lore raw

PATCH v15 1/11 net/tap: fix fd check in flow_isolate

The check for receive queue fd in flow_isolate is incorrect. If queue has not been setup then fd will be -1 not 0.

---
 drivers/net/tap/tap_flow.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/tap/tap_flow.c +1 -1
index fa50fe45d7..79cd6a12ca 100644
@@ -1595,7 +1595,7 @@ tap_flow_isolate(struct rte_eth_dev *dev,
 	 * If netdevice is there, setup appropriate flow rules immediately.
 	 * Otherwise it will be set when bringing up the netdevice (tun_alloc).
 	 */
-	if (!process_private->rxq_fds[0])
+	if (process_private->rxq_fds[0] == -1)
 		return 0;
 	if (set) {
 		struct rte_flow *remote_flow;
Signature · 1 line
2.43.0
#193 lore raw

PATCH v15 2/11 net/tap: do not duplicate fd's

In reply to Stephen Hemminger

The TAP device can use same file descriptor for both rx and tx queues which reduces the number of fd's required.

MP process support passes file descriptors from primary to secondary process; but because of the restriction on max fd's passed RTE_MP_MAX_FD_NUM (8) the TAP device was restricted to only 4 queues if using secondary.
This allows up to 8 queues (versus 4).

The restriction on max fd's should be changed in eal in future, but it will break ABI compatibility. The max Linux supports which is SCM_MAX_FD (253).

---
 doc/guides/rel_notes/release_24_07.rst |   4 +
 drivers/net/tap/rte_eth_tap.c          | 192 ++++++++++---------------
 drivers/net/tap/rte_eth_tap.h          |   3 +-
 drivers/net/tap/tap_flow.c             |   3 +-
 drivers/net/tap/tap_intr.c             |   7 +-
 5 files changed, 89 insertions(+), 120 deletions(-)
doc/guides/rel_notes/release_24_07.rst +4 -0
index a69f24cf99..a6295359b1 100644
@@ -55,6 +55,10 @@ New Features
      Also, make sure to start the actual text at the margin.
      =======================================================
 
+* **Update Tap PMD driver.**
+
+  * Updated to support up to 8 queues when used by secondary process.
+
 
 Removed Items
 -------------
drivers/net/tap/rte_eth_tap.c +78 -114

337 lines not on this page · raw message

drivers/net/tap/rte_eth_tap.h +1 -2
index 5ac93f93e9..dc8201020b 100644
@@ -96,8 +96,7 @@ struct pmd_internals {
 };
 
 struct pmd_process_private {
-	int rxq_fds[RTE_PMD_TAP_MAX_QUEUES];
-	int txq_fds[RTE_PMD_TAP_MAX_QUEUES];
+	int fds[RTE_PMD_TAP_MAX_QUEUES];
 };
 
 /* tap_intr.c */
drivers/net/tap/tap_flow.c +2 -1
index 79cd6a12ca..a78fd50cd4 100644
@@ -1595,8 +1595,9 @@ tap_flow_isolate(struct rte_eth_dev *dev,
 	 * If netdevice is there, setup appropriate flow rules immediately.
 	 * Otherwise it will be set when bringing up the netdevice (tun_alloc).
 	 */
-	if (process_private->rxq_fds[0] == -1)
+	if (process_private->fds[0] == -1)
 		return 0;
+
 	if (set) {
 		struct rte_flow *remote_flow;
 
drivers/net/tap/tap_intr.c +4 -3
index a9097def1a..1908f71f97 100644
@@ -68,9 +68,11 @@ tap_rx_intr_vec_install(struct rte_eth_dev *dev)
 	}
 	for (i = 0; i < n; i++) {
 		struct rx_queue *rxq = pmd->dev->data->rx_queues[i];
+		int fd = process_private->fds[i];
 
 		/* Skip queues that cannot request interrupts. */
-		if (!rxq || process_private->rxq_fds[i] == -1) {
+		if (!rxq || fd == -1) {
+			/* Use invalid intr_vec[] index to disable entry. */
 			/* Use invalid intr_vec[] index to disable entry. */
 			if (rte_intr_vec_list_index_set(intr_handle, i,
 			RTE_INTR_VEC_RXTX_OFFSET + RTE_MAX_RXTX_INTR_VEC_ID))
@@ -80,8 +82,7 @@ tap_rx_intr_vec_install(struct rte_eth_dev *dev)
 		if (rte_intr_vec_list_index_set(intr_handle, i,
 					RTE_INTR_VEC_RXTX_OFFSET + count))
 			return -rte_errno;
-		if (rte_intr_efds_index_set(intr_handle, count,
-						   process_private->rxq_fds[i]))
+		if (rte_intr_efds_index_set(intr_handle, count, fd))
 			return -rte_errno;
 		count++;
 	}
Signature · 1 line
2.43.0
#194 lore raw

PATCH v15 3/11 net/tap: remove unused fields

In reply to Stephen Hemminger

The driver doesn't support these other hash types, and there is no reason to implement these in future. The rss_flows list was set but never used.

---
 drivers/net/tap/rte_eth_tap.h | 4 +---
 drivers/net/tap/tap_flow.c    | 1 -
 drivers/net/tap/tap_rss.h     | 6 ------
 3 files changed, 1 insertion(+), 10 deletions(-)
drivers/net/tap/rte_eth_tap.h +1 -3
index dc8201020b..1bcf92ce80 100644
@@ -77,14 +77,12 @@ struct pmd_internals {
 	int ioctl_sock;                   /* socket for ioctl calls */
 	int nlsk_fd;                      /* Netlink socket fd */
 	int flow_isolate;                 /* 1 if flow isolation is enabled */
-	int flower_support;               /* 1 if kernel supports, else 0 */
-	int flower_vlan_support;          /* 1 if kernel supports, else 0 */
 	int rss_enabled;                  /* 1 if RSS is enabled, else 0 */
 	int persist;			  /* 1 if keep link up, else 0 */
 	/* implicit rules set when RSS is enabled */
 	int map_fd;                       /* BPF RSS map fd */
 	int bpf_fd[RTE_PMD_TAP_MAX_QUEUES];/* List of bpf fds per queue */
-	LIST_HEAD(tap_rss_flows, rte_flow) rss_flows;
+
 	LIST_HEAD(tap_flows, rte_flow) flows;        /* rte_flow rules */
 	/* implicit rte_flow rules set when a remote device is active */
 	LIST_HEAD(tap_implicit_flows, rte_flow) implicit_flows;
drivers/net/tap/tap_flow.c +0 -1
index a78fd50cd4..8fccd599f0 100644
@@ -1958,7 +1958,6 @@ static int rss_enable(struct pmd_internals *pmd,
 				errno, strerror(errno));
 			return err;
 		}
-		LIST_INSERT_HEAD(&pmd->rss_flows, rss_flow, next);
 	}
 
 	pmd->rss_enabled = 1;
drivers/net/tap/tap_rss.h +0 -6
index dff46a012f..8766ffc244 100644
@@ -21,12 +21,6 @@ enum hash_field {
 	HASH_FIELD_IPV4_L3_L4,	/* IPv4 src/dst addr + L4 src/dst ports */
 	HASH_FIELD_IPV6_L3,	/* IPv6 src/dst addr */
 	HASH_FIELD_IPV6_L3_L4,	/* IPv6 src/dst addr + L4 src/dst ports */
-	HASH_FIELD_L2_SRC,	/* Ethernet src addr */
-	HASH_FIELD_L2_DST,	/* Ethernet dst addr */
-	HASH_FIELD_L3_SRC,	/* L3 src addr */
-	HASH_FIELD_L3_DST,	/* L3 dst addr */
-	HASH_FIELD_L4_SRC,	/* TCP/UDP src ports */
-	HASH_FIELD_L4_DST,	/* TCP/UDP dst ports */
 };
 
 struct rss_key {
Signature · 1 line
2.43.0
#195 lore raw

PATCH v15 4/11 net/tap: validate and setup parameters for BPF RSS

In reply to Stephen Hemminger

The flow RSS support via BPF was not using the key, or hash type parameters. Which is good because they were never properly setup.

Fix the setup and validate the flow parameters, the BPF side gets fixed later.

---
 drivers/net/tap/tap_flow.c | 75 +++++++++++++++++++++++++++++++++++---
 drivers/net/tap/tap_rss.h  |  5 +--
 2 files changed, 72 insertions(+), 8 deletions(-)
drivers/net/tap/tap_flow.c +70 -5
index 8fccd599f0..dd4e69b876 100644
@@ -11,9 +11,11 @@
 
 #include <rte_byteorder.h>
 #include <rte_jhash.h>
+#include <rte_thash.h>
 #include <rte_random.h>
 #include <rte_malloc.h>
 #include <rte_eth_tap.h>
+
 #include <tap_flow.h>
 #include <tap_autoconf.h>
 #include <tap_tcmsgs.h>
@@ -2061,6 +2063,21 @@ static int bpf_rss_key(enum bpf_rss_key_e cmd, __u32 *key_idx)
 	return err;
 }
 
+
+/* Default RSS hash key also used by mlx devices */
+static const uint8_t rss_hash_default_key[] = {
+	0x2c, 0xc6, 0x81, 0xd1,
+	0x5b, 0xdb, 0xf4, 0xf7,
+	0xfc, 0xa2, 0x83, 0x19,
+	0xdb, 0x1a, 0x3e, 0x94,
+	0x6b, 0x9e, 0x38, 0xd9,
+	0x2c, 0x9c, 0x03, 0xd1,
+	0xad, 0x99, 0x44, 0xa7,
+	0xd9, 0x56, 0x3d, 0x59,
+	0x06, 0x3c, 0x25, 0xf3,
+	0xfc, 0x1f, 0xdc, 0x2a,
+};
+
 /**
  * Add RSS hash calculations and queue selection
  *
@@ -2079,11 +2096,11 @@ static int rss_add_actions(struct rte_flow *flow, struct pmd_internals *pmd,
 			   const struct rte_flow_action_rss *rss,
 			   struct rte_flow_error *error)
 {
-	/* 4096 is the maximum number of instructions for a BPF program */
+	struct rss_key rss_entry = { };
+	const uint8_t *key_in;
+	uint32_t hash_type = 0;
 	unsigned int i;
 	int err;
-	struct rss_key rss_entry = { .hash_fields = 0,
-				     .key_size = 0 };
 
 	/* Check supported RSS features */
 	if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT)
@@ -2095,6 +2112,51 @@ static int rss_add_actions(struct rte_flow *flow, struct pmd_internals *pmd,
 			(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
 			 "a nonzero RSS encapsulation level is not supported");
 
+	if (rss->queue_num == 0 || rss->queue_num >= TAP_MAX_QUEUES)
+		return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
+					  "invalid number of queues");
+
+	/*
+	 * Follow the semantics of RSS key (see rte_ethdev.h)
+	 * There are two valid cases:
+	 *   1. key_length of zero, and key must be NULL;
+	 *      this uses the default driver key.
+	 *
+	 *   2. key_length is the TAP_RSS_HASH_KEY_SIZE (40 bytes)
+	 *      and the key must not be NULL.
+	 *
+	 * Anything else is an error.
+	 */
+	if (rss->key_len == 0) {
+		if (rss->key != NULL)
+			return rte_flow_error_set(error, ENOTSUP,
+						  RTE_FLOW_ERROR_TYPE_ACTION_CONF,
+						  &rss->key_len, "RSS hash key length 0");
+		key_in = rss_hash_default_key;
+	} else {
+		if (rss->key_len != TAP_RSS_HASH_KEY_SIZE)
+			return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+						  NULL, "RSS hash invalid key length");
+		if (rss->key == NULL)
+			return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+						  NULL, "RSS hash key is NULL");
+		key_in = rss->key;
+	}
+
+	if (rss->types & TAP_RSS_HF_MASK)
+		return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+					  NULL, "RSS hash type not supported");
+
+	if (rss->types & (RTE_ETH_RSS_NONFRAG_IPV4_UDP | RTE_ETH_RSS_NONFRAG_IPV4_TCP))
+		hash_type |= RTE_BIT32(HASH_FIELD_IPV4_L3_L4);
+	else if (rss->types & (RTE_ETH_RSS_IPV4 | RTE_ETH_RSS_FRAG_IPV4))
+		hash_type |= RTE_BIT32(HASH_FIELD_IPV4_L3);
+
+	if (rss->types & (RTE_ETH_RSS_NONFRAG_IPV6_UDP | RTE_ETH_RSS_NONFRAG_IPV6_TCP))
+		hash_type |= RTE_BIT32(HASH_FIELD_IPV6_L3_L4);
+	else if (rss->types & (RTE_ETH_RSS_IPV6 | RTE_ETH_RSS_FRAG_IPV6 | RTE_ETH_RSS_IPV6_EX))
+		hash_type |= RTE_BIT32(HASH_FIELD_IPV6_L3);
+
 	/* Get a new map key for a new RSS rule */
 	err = bpf_rss_key(KEY_CMD_GET, &flow->key_idx);
 	if (err < 0) {
@@ -2109,8 +2171,11 @@ static int rss_add_actions(struct rte_flow *flow, struct pmd_internals *pmd,
 	rss_entry.nb_queues = rss->queue_num;
 	for (i = 0; i < rss->queue_num; i++)
 		rss_entry.queues[i] = rss->queue[i];
-	rss_entry.hash_fields =
-		(1 << HASH_FIELD_IPV4_L3_L4) | (1 << HASH_FIELD_IPV6_L3_L4);
+
+	rss_entry.hash_fields = hash_type;
+	rte_convert_rss_key((const uint32_t *)key_in, (uint32_t *)rss_entry.key,
+			    TAP_RSS_HASH_KEY_SIZE);
+
 
 	/* Add this RSS entry to map */
 	err = tap_flow_bpf_update_rss_elem(pmd->map_fd,
drivers/net/tap/tap_rss.h +2 -3
index 8766ffc244..6009be7031 100644
@@ -24,11 +24,10 @@ enum hash_field {
 };
 
 struct rss_key {
-	 __u8 key[128];
 	__u32 hash_fields;
-	__u32 key_size;
-	__u32 queues[TAP_MAX_QUEUES];
+	__u8 key[TAP_RSS_HASH_KEY_SIZE];
 	__u32 nb_queues;
+	__u32 queues[TAP_MAX_QUEUES];
 } __attribute__((packed));
 
 #endif /* _TAP_RSS_H_ */
Signature · 1 line
2.43.0
#196 lore raw

PATCH v15 5/11 net/tap: do not build flow support if header is out of date

In reply to Stephen Hemminger

The proper place for finding bpf structures and functions is in linux/bpf.h. The original version was trying to workaround the case where the build environment was running on old pre BPF version of Glibc, but the target environment had BPF.

Having own private (and divergent) version headers leads to future problems when BPF definitions evolve.

If the build infrastructure is so old that TC flower is not supported, then the TAP device will build without any flow support.

---
 drivers/net/tap/bpf/bpf_extract.py |   1 -
 drivers/net/tap/meson.build        |  17 ++--
 drivers/net/tap/rte_eth_tap.c      |  38 +++++++--
 drivers/net/tap/rte_eth_tap.h      |   7 +-
 drivers/net/tap/tap_bpf.h          | 121 -----------------------------
 drivers/net/tap/tap_bpf_api.c      |  20 +++--
 drivers/net/tap/tap_bpf_insns.h    |   2 -
 drivers/net/tap/tap_flow.c         |  90 ---------------------
 8 files changed, 60 insertions(+), 236 deletions(-)
 delete mode 100644 drivers/net/tap/tap_bpf.h
drivers/net/tap/bpf/bpf_extract.py +0 -1
index b630c42b80..73c4dafe4e 100644
@@ -65,7 +65,6 @@ def write_header(out, source):
         print(f' * Auto-generated from {source}', file=out)
     print(" * This not the original source file. Do NOT edit it.", file=out)
     print(" */\n", file=out)
-    print("#include <tap_bpf.h>", file=out)
 
 
 def main():
drivers/net/tap/meson.build +9 -8
index 5099ccdff1..66647a1c62 100644
@@ -7,13 +7,19 @@ if not is_linux
 endif
 sources = files(
         'rte_eth_tap.c',
-        'tap_bpf_api.c',
-        'tap_flow.c',
         'tap_intr.c',
         'tap_netlink.c',
-        'tap_tcmsgs.c',
 )
 
+if cc.has_header_symbol('linux/pkt_cls.h', 'TCA_FLOWER_ACT')
+    cflags += '-DHAVE_TCA_FLOWER'
+    sources += files(
+        'tap_bpf_api.c',
+        'tap_flow.c',
+        'tap_tcmsgs.c',
+    )
+endif
+
 deps = ['bus_vdev', 'gso', 'hash']
 
 cflags += '-DTAP_MAX_QUEUES=16'
@@ -23,12 +29,7 @@ cflags += '-DTAP_MAX_QUEUES=16'
 #   "enum/define", "symbol to search" ]
 #
 args = [
-        [ 'HAVE_TC_FLOWER', 'linux/pkt_cls.h', 'TCA_FLOWER_UNSPEC' ],
-        [ 'HAVE_TC_VLAN_ID', 'linux/pkt_cls.h', 'TCA_FLOWER_KEY_VLAN_PRIO' ],
-        [ 'HAVE_TC_BPF', 'linux/pkt_cls.h', 'TCA_BPF_UNSPEC' ],
-        [ 'HAVE_TC_BPF_FD', 'linux/pkt_cls.h', 'TCA_BPF_FD' ],
         [ 'HAVE_TC_ACT_BPF', 'linux/tc_act/tc_bpf.h', 'TCA_ACT_BPF_UNSPEC' ],
-        [ 'HAVE_TC_ACT_BPF_FD', 'linux/tc_act/tc_bpf.h', 'TCA_ACT_BPF_FD' ],
 ]
 config = configuration_data()
 foreach arg:args
drivers/net/tap/rte_eth_tap.c +32 -6
index b84fc01856..9058a47295 100644
@@ -1133,12 +1133,15 @@ tap_dev_close(struct rte_eth_dev *dev)
 
 	if (!internals->persist)
 		tap_link_set_down(dev);
+
+#ifdef HAVE_TCA_FLOWER
 	if (internals->nlsk_fd != -1) {
 		tap_flow_flush(dev, NULL);
 		tap_flow_implicit_flush(internals, NULL);
 		tap_nl_final(internals->nlsk_fd);
 		internals->nlsk_fd = -1;
 	}
+#endif
 
 	for (i = 0; i < RTE_PMD_TAP_MAX_QUEUES; i++) {
 		struct rx_queue *rxq = &internals->rxq[i];
@@ -1261,6 +1264,7 @@ tap_promisc_enable(struct rte_eth_dev *dev)
 	if (ret != 0)
 		return ret;
 
+#ifdef HAVE_TCA_FLOWER
 	if (pmd->remote_if_index && !pmd->flow_isolate) {
 		dev->data->promiscuous = 1;
 		ret = tap_flow_implicit_create(pmd, TAP_REMOTE_PROMISC);
@@ -1274,7 +1278,7 @@ tap_promisc_enable(struct rte_eth_dev *dev)
 			return ret;
 		}
 	}
-
+#endif
 	return 0;
 }
 
@@ -1289,6 +1293,7 @@ tap_promisc_disable(struct rte_eth_dev *dev)
 	if (ret != 0)
 		return ret;
 
+#ifdef HAVE_TCA_FLOWER
 	if (pmd->remote_if_index && !pmd->flow_isolate) {
 		dev->data->promiscuous = 0;
 		ret = tap_flow_implicit_destroy(pmd, TAP_REMOTE_PROMISC);
@@ -1302,6 +1307,7 @@ tap_promisc_disable(struct rte_eth_dev *dev)
 			return ret;
 		}
 	}
+#endif
 
 	return 0;
 }
@@ -1317,6 +1323,7 @@ tap_allmulti_enable(struct rte_eth_dev *dev)
 	if (ret != 0)
 		return ret;
 
+#ifdef HAVE_TCA_FLOWER
 	if (pmd->remote_if_index && !pmd->flow_isolate) {
 		dev->data->all_multicast = 1;
 		ret = tap_flow_implicit_create(pmd, TAP_REMOTE_ALLMULTI);
@@ -1330,6 +1337,7 @@ tap_allmulti_enable(struct rte_eth_dev *dev)
 			return ret;
 		}
 	}
+#endif
 
 	return 0;
 }
@@ -1345,6 +1353,7 @@ tap_allmulti_disable(struct rte_eth_dev *dev)
 	if (ret != 0)
 		return ret;
 
+#ifdef HAVE_TCA_FLOWER
 	if (pmd->remote_if_index && !pmd->flow_isolate) {
 		dev->data->all_multicast = 0;
 		ret = tap_flow_implicit_destroy(pmd, TAP_REMOTE_ALLMULTI);
@@ -1358,6 +1367,7 @@ tap_allmulti_disable(struct rte_eth_dev *dev)
 			return ret;
 		}
 	}
+#endif
 
 	return 0;
 }
@@ -1403,6 +1413,8 @@ tap_mac_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr)
 	if (ret < 0)
 		return ret;
 	rte_memcpy(&pmd->eth_addr, mac_addr, RTE_ETHER_ADDR_LEN);
+
+#ifdef HAVE_TCA_FLOWER
 	if (pmd->remote_if_index && !pmd->flow_isolate) {
 		/* Replace MAC redirection rule after a MAC change */
 		ret = tap_flow_implicit_destroy(pmd, TAP_REMOTE_LOCAL_MAC);
@@ -1420,6 +1432,7 @@ tap_mac_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr)
 			return ret;
 		}
 	}
+#endif
 
 	return 0;
 }
@@ -1894,7 +1907,9 @@ static const struct eth_dev_ops ops = {
 	.stats_reset            = tap_stats_reset,
 	.dev_supported_ptypes_get = tap_dev_supported_ptypes_get,
 	.rss_hash_update        = tap_rss_hash_update,
+#ifdef HAVE_TCA_FLOWER
 	.flow_ops_get           = tap_dev_flow_ops_get,
+#endif
 };
 
 static int
@@ -1934,7 +1949,9 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 	strlcpy(pmd->name, tap_name, sizeof(pmd->name));
 	pmd->type = type;
 	pmd->ka_fd = -1;
+#ifdef HAVE_TCA_FLOWER
 	pmd->nlsk_fd = -1;
+#endif
 	pmd->gso_ctx_mp = NULL;
 
 	pmd->ioctl_sock = socket(AF_INET, SOCK_DGRAM, 0);
@@ -2014,6 +2031,14 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 	/* Make network device persist after application exit */
 	pmd->persist = persist;
 
+	pmd->if_index = if_nametoindex(pmd->name);
+	if (!pmd->if_index) {
+		TAP_LOG(ERR, "%s: failed to get if_index.", pmd->name);
+		goto disable_rte_flow;
+	}
+
+
+#ifdef HAVE_TCA_FLOWER
 	/*
 	 * Set up everything related to rte_flow:
 	 * - netlink socket
@@ -2028,11 +2053,6 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 			pmd->name);
 		goto disable_rte_flow;
 	}
-	pmd->if_index = if_nametoindex(pmd->name);
-	if (!pmd->if_index) {
-		TAP_LOG(ERR, "%s: failed to get if_index.", pmd->name);
-		goto disable_rte_flow;
-	}
 	if (qdisc_create_multiq(pmd->nlsk_fd, pmd->if_index) < 0) {
 		TAP_LOG(ERR, "%s: failed to create multiq qdisc.",
 			pmd->name);
@@ -2043,6 +2063,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 			pmd->name);
 		goto disable_rte_flow;
 	}
+
 	LIST_INIT(&pmd->flows);
 
 	if (strlen(remote_iface)) {
@@ -2095,6 +2116,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 			goto error_remote;
 		}
 	}
+#endif
 
 	rte_eth_dev_probing_finish(dev);
 	return 0;
@@ -2109,14 +2131,18 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 	rte_eth_dev_probing_finish(dev);
 	return 0;
 
+#ifdef HAVE_TCA_FLOWER
 error_remote:
 	TAP_LOG(ERR, " Can't set up remote feature: %s(%d)",
 		strerror(errno), errno);
 	tap_flow_implicit_flush(pmd, NULL);
+#endif
 
 error_exit:
+#ifdef HAVE_TCA_FLOWER
 	if (pmd->nlsk_fd != -1)
 		close(pmd->nlsk_fd);
+#endif
 	if (pmd->ka_fd != -1)
 		close(pmd->ka_fd);
 	if (pmd->ioctl_sock != -1)
drivers/net/tap/rte_eth_tap.h +6 -1
index 1bcf92ce80..af18b29090 100644
@@ -16,6 +16,7 @@
 #include <ethdev_driver.h>
 #include <rte_ether.h>
 #include <rte_gso.h>
+
 #include "tap_log.h"
 
 #ifdef IFF_MULTI_QUEUE
@@ -70,15 +71,17 @@ struct pmd_internals {
 	char remote_iface[RTE_ETH_NAME_MAX_LEN]; /* Remote netdevice name */
 	char name[RTE_ETH_NAME_MAX_LEN];  /* Internal Tap device name */
 	int type;                         /* Type field - TUN|TAP */
+	int persist;			  /* 1 if keep link up, else 0 */
 	struct rte_ether_addr eth_addr;   /* Mac address of the device port */
 	struct ifreq remote_initial_flags;/* Remote netdevice flags on init */
 	int remote_if_index;              /* remote netdevice IF_INDEX */
 	int if_index;                     /* IF_INDEX for the port */
 	int ioctl_sock;                   /* socket for ioctl calls */
+
+#ifdef HAVE_TCA_FLOWER
 	int nlsk_fd;                      /* Netlink socket fd */
 	int flow_isolate;                 /* 1 if flow isolation is enabled */
 	int rss_enabled;                  /* 1 if RSS is enabled, else 0 */
-	int persist;			  /* 1 if keep link up, else 0 */
 	/* implicit rules set when RSS is enabled */
 	int map_fd;                       /* BPF RSS map fd */
 	int bpf_fd[RTE_PMD_TAP_MAX_QUEUES];/* List of bpf fds per queue */
@@ -86,6 +89,8 @@ struct pmd_internals {
 	LIST_HEAD(tap_flows, rte_flow) flows;        /* rte_flow rules */
 	/* implicit rte_flow rules set when a remote device is active */
 	LIST_HEAD(tap_implicit_flows, rte_flow) implicit_flows;
+#endif
+
 	struct rx_queue rxq[RTE_PMD_TAP_MAX_QUEUES]; /* List of RX queues */
 	struct tx_queue txq[RTE_PMD_TAP_MAX_QUEUES]; /* List of TX queues */
 	struct rte_intr_handle *intr_handle;         /* LSC interrupt handle. */
drivers/net/tap/tap_bpf.h deleted +0 -121

121 lines not on this page · raw message

drivers/net/tap/tap_bpf_api.c +13 -7
index 15283f8917..9e05e2ddf1 100644
@@ -2,19 +2,19 @@
  * Copyright 2017 Mellanox Technologies, Ltd
  */
 
-#include <errno.h>
-#include <string.h>
 #include <unistd.h>
-#include <sys/queue.h>
+#include <syscall.h>
+#include <linux/bpf.h>
 
-#include <rte_malloc.h>
-#include <rte_eth_tap.h>
 #include <tap_flow.h>
 #include <tap_autoconf.h>
-#include <tap_tcmsgs.h>
-#include <tap_bpf.h>
+
 #include <tap_bpf_insns.h>
 
+
+static int bpf_load(enum bpf_prog_type type, const struct bpf_insn *insns,
+		size_t insns_cnt, const char *license);
+
 /**
  * Load BPF program (section cls_q) into the kernel and return a bpf fd
  *
@@ -89,7 +89,13 @@ static inline __u64 ptr_to_u64(const void *ptr)
 static inline int sys_bpf(enum bpf_cmd cmd, union bpf_attr *attr,
 			unsigned int size)
 {
+#ifdef __NR_bpf
 	return syscall(__NR_bpf, cmd, attr, size);
+#else
+	TAP_LOG(ERR, "No bpf syscall, kernel headers too old?\n");
+	errno = ENOSYS;
+	return -1;
+#endif
 }
 
 /**
drivers/net/tap/tap_bpf_insns.h +0 -2
index 53fa76c4e6..cdf2febf05 100644
@@ -3,8 +3,6 @@
  * This not the original source file. Do NOT edit it.
  */
 
-#include <tap_bpf.h>
-
 static struct bpf_insn cls_q_insns[] = {
 	{0x61,    2,    1,       52, 0x00000000},
 	{0x18,    3,    0,        0, 0xdeadbeef},
drivers/net/tap/tap_flow.c +0 -90

96 lines not on this page · raw message

Signature · 1 line
2.43.0
#197 lore raw

PATCH v15 6/11 net/tap: rewrite the RSS BPF program

In reply to Stephen Hemminger

Rewrite of the BPF program used to do queue based RSS.

Important changes:
- uses newer BPF map format BTF
- accepts key as parameter rather than constant default
- can do L3 or L4 hashing
- supports IPv4 options
- supports IPv6 extension headers
- restructured for readability

The usage of BPF is different as well:
- the incoming configuration is looked up based on class parameters rather than patching the BPF code.
- the resulting queue is placed in skb by using skb mark than requiring a second pass through classifier step.

Note: This version only works with later patch to enable it on the DPDK driver side. It is submitted as an incremental patch to allow for easier review. Bisection still works because the old instruction are still present for now.

---
 .gitignore                            |   3 -
 drivers/net/tap/bpf/Makefile          |  19 --
 drivers/net/tap/bpf/README            |  49 +++++
 drivers/net/tap/bpf/bpf_api.h         | 276 --------------------------
 drivers/net/tap/bpf/bpf_elf.h         |  53 -----
 drivers/net/tap/bpf/bpf_extract.py    |  85 --------
 drivers/net/tap/bpf/meson.build       |  81 ++++++++
 drivers/net/tap/bpf/tap_bpf_program.c | 255 ------------------------
 drivers/net/tap/bpf/tap_rss.c         | 267 +++++++++++++++++++++++++
 9 files changed, 397 insertions(+), 691 deletions(-)
 delete mode 100644 drivers/net/tap/bpf/Makefile
 create mode 100644 drivers/net/tap/bpf/README
 delete mode 100644 drivers/net/tap/bpf/bpf_api.h
 delete mode 100644 drivers/net/tap/bpf/bpf_elf.h
 delete mode 100644 drivers/net/tap/bpf/bpf_extract.py
 create mode 100644 drivers/net/tap/bpf/meson.build
 delete mode 100644 drivers/net/tap/bpf/tap_bpf_program.c
 create mode 100644 drivers/net/tap/bpf/tap_rss.c
.gitignore +0 -3
index 3f444dcace..01a47a7606 100644
@@ -36,9 +36,6 @@ TAGS
 # ignore python bytecode files
 *.pyc
 
-# ignore BPF programs
-drivers/net/tap/bpf/tap_bpf_program.o
-
 # DTS results
 dts/output
 
drivers/net/tap/bpf/Makefile deleted +0 -19
deleted file mode 100644
index 9efeeb1bc7..0000000000
@@ -1,19 +0,0 @@
-# SPDX-License-Identifier: BSD-3-Clause
-# This file is not built as part of normal DPDK build.
-# It is used to generate the eBPF code for TAP RSS.
-
-CLANG=clang
-CLANG_OPTS=-O2
-TARGET=../tap_bpf_insns.h
-
-all: $(TARGET)
-
-clean:
-	rm tap_bpf_program.o $(TARGET)
-
-tap_bpf_program.o: tap_bpf_program.c
-	$(CLANG) $(CLANG_OPTS) -emit-llvm -c $< -o - | \
-	llc -march=bpf -filetype=obj -o $@
-
-$(TARGET): tap_bpf_program.o
-	python3 bpf_extract.py -stap_bpf_program.c -o $@ $<
drivers/net/tap/bpf/README new file +49 -0

49 lines not on this page · raw message

drivers/net/tap/bpf/bpf_api.h deleted +0 -276

276 lines not on this page · raw message

drivers/net/tap/bpf/bpf_elf.h deleted +0 -53

53 lines not on this page · raw message

drivers/net/tap/bpf/bpf_extract.py deleted +0 -85

85 lines not on this page · raw message

drivers/net/tap/bpf/meson.build new file +81 -0

81 lines not on this page · raw message

drivers/net/tap/bpf/tap_bpf_program.c deleted +0 -255

255 lines not on this page · raw message

drivers/net/tap/bpf/tap_rss.c new file +267 -0

267 lines not on this page · raw message

Signature · 1 line
2.43.0
#198 lore raw

PATCH v15 7/11 net/tap: use libbpf to load new BPF program

In reply to Stephen Hemminger

There were multiple issues in the RSS queue support in the TAP driver. This required extensive rework of the BPF support.

Change the BPF loading to use bpftool to
create a skeleton header file, and load with libbpf. The BPF is always compiled from source so less chance that source and instructions diverge. Also resolves issue where libbpf and source get out of sync. The program
is only loaded once, so if multiple rules are created only one BPF program is loaded in kernel.

The new BPF program only needs a single action.
No need for action and re-classification step.

It also fixes the missing bits from the original.
- supports setting RSS key per flow
- level of hash can be L3 or L3/L4.

Bugzilla ID: 1329

---
 doc/guides/rel_notes/release_24_07.rst |   3 +
 drivers/net/tap/bpf/meson.build        |  81 +++--
 drivers/net/tap/meson.build            |  39 ++-
 drivers/net/tap/rte_eth_tap.c          |  14 +-
 drivers/net/tap/rte_eth_tap.h          |   6 +-
 drivers/net/tap/tap_flow.c             | 416 ++++++-------------------
 drivers/net/tap/tap_flow.h             |  17 +-
 drivers/net/tap/tap_rss.h              |  10 +-
 drivers/net/tap/tap_tcmsgs.h           |   4 +-
 9 files changed, 186 insertions(+), 404 deletions(-)
doc/guides/rel_notes/release_24_07.rst +3 -0
index a6295359b1..37a6e98637 100644
@@ -59,6 +59,9 @@ New Features
 
   * Updated to support up to 8 queues when used by secondary process.
 
+  * Fixed support of RSS flow action to work with current Linux
+    kernels and BPF tooling. Will only be enabled if clang, libbpf 1.0
+    and bpftool are available.
 
 Removed Items
 -------------
drivers/net/tap/bpf/meson.build +47 -34

107 lines not on this page · raw message

drivers/net/tap/meson.build +18 -21
index 66647a1c62..5e5a3ad3c6 100644
@@ -5,36 +5,33 @@ if not is_linux
     build = false
     reason = 'only supported on Linux'
 endif
+
 sources = files(
         'rte_eth_tap.c',
         'tap_intr.c',
         'tap_netlink.c',
 )
 
+deps = ['bus_vdev', 'gso', 'hash']
+
+max_queues = '-DTAP_MAX_QUEUES=16'
+cflags += max_queues
+
+require_iova_in_mbuf = false
+
 if cc.has_header_symbol('linux/pkt_cls.h', 'TCA_FLOWER_ACT')
     cflags += '-DHAVE_TCA_FLOWER'
     sources += files(
-        'tap_bpf_api.c',
-        'tap_flow.c',
-        'tap_tcmsgs.c',
+            'tap_flow.c',
+            'tap_tcmsgs.c',
     )
-endif
-
-deps = ['bus_vdev', 'gso', 'hash']
 
-cflags += '-DTAP_MAX_QUEUES=16'
-
-# input array for meson symbol search:
-# [ "MACRO to define if found", "header for the search",
-#   "enum/define", "symbol to search" ]
-#
-args = [
-        [ 'HAVE_TC_ACT_BPF', 'linux/tc_act/tc_bpf.h', 'TCA_ACT_BPF_UNSPEC' ],
-]
-config = configuration_data()
-foreach arg:args
-    config.set(arg[0], cc.has_header_symbol(arg[1], arg[2]))
-endforeach
-configure_file(output : 'tap_autoconf.h', configuration : config)
+    enable_tap_rss = false
 
-require_iova_in_mbuf = false
+    subdir('bpf')
+    if enable_tap_rss
+        cflags += '-DHAVE_BPF_RSS'
+        ext_deps += libbpf
+        sources += tap_rss_skel_h
+    endif
+endif
drivers/net/tap/rte_eth_tap.c +7 -7
index 9058a47295..d847565073 100644
@@ -1140,6 +1140,7 @@ tap_dev_close(struct rte_eth_dev *dev)
 		tap_flow_implicit_flush(internals, NULL);
 		tap_nl_final(internals->nlsk_fd);
 		internals->nlsk_fd = -1;
+		tap_flow_bpf_destroy(internals);
 	}
 #endif
 
@@ -1949,6 +1950,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 	strlcpy(pmd->name, tap_name, sizeof(pmd->name));
 	pmd->type = type;
 	pmd->ka_fd = -1;
+
 #ifdef HAVE_TCA_FLOWER
 	pmd->nlsk_fd = -1;
 #endif
@@ -2031,13 +2033,6 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 	/* Make network device persist after application exit */
 	pmd->persist = persist;
 
-	pmd->if_index = if_nametoindex(pmd->name);
-	if (!pmd->if_index) {
-		TAP_LOG(ERR, "%s: failed to get if_index.", pmd->name);
-		goto disable_rte_flow;
-	}
-
-
 #ifdef HAVE_TCA_FLOWER
 	/*
 	 * Set up everything related to rte_flow:
@@ -2053,6 +2048,11 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 			pmd->name);
 		goto disable_rte_flow;
 	}
+	pmd->if_index = if_nametoindex(pmd->name);
+	if (!pmd->if_index) {
+		TAP_LOG(ERR, "%s: failed to get if_index.", pmd->name);
+		goto disable_rte_flow;
+	}
 	if (qdisc_create_multiq(pmd->nlsk_fd, pmd->if_index) < 0) {
 		TAP_LOG(ERR, "%s: failed to create multiq qdisc.",
 			pmd->name);
drivers/net/tap/rte_eth_tap.h +2 -4
index af18b29090..ce4322ad04 100644
@@ -81,10 +81,8 @@ struct pmd_internals {
 #ifdef HAVE_TCA_FLOWER
 	int nlsk_fd;                      /* Netlink socket fd */
 	int flow_isolate;                 /* 1 if flow isolation is enabled */
-	int rss_enabled;                  /* 1 if RSS is enabled, else 0 */
-	/* implicit rules set when RSS is enabled */
-	int map_fd;                       /* BPF RSS map fd */
-	int bpf_fd[RTE_PMD_TAP_MAX_QUEUES];/* List of bpf fds per queue */
+
+	struct tap_rss *rss;		  /* BPF program */
 
 	LIST_HEAD(tap_flows, rte_flow) flows;        /* rte_flow rules */
 	/* implicit rte_flow rules set when a remote device is active */
drivers/net/tap/tap_flow.c +97 -319

555 lines not on this page · raw message

drivers/net/tap/tap_flow.h +6 -11
index 240fbc3dfa..8b19347a93 100644
@@ -9,7 +9,11 @@
 #include <rte_flow.h>
 #include <rte_flow_driver.h>
 #include <rte_eth_tap.h>
-#include <tap_autoconf.h>
+
+/**
+ * Mask of unsupported RSS types
+ */
+#define TAP_RSS_HF_MASK (~(RTE_ETH_RSS_IP | RTE_ETH_RSS_UDP | RTE_ETH_RSS_TCP))
 
 /**
  * In TC, priority 0 means we require the kernel to allocate one for us.
@@ -41,11 +45,6 @@ enum implicit_rule_index {
 	TAP_REMOTE_MAX_IDX,
 };
 
-enum bpf_fd_idx {
-	SEC_L3_L4,
-	SEC_MAX,
-};
-
 int tap_dev_flow_ops_get(struct rte_eth_dev *dev,
 			 const struct rte_flow_ops **ops);
 int tap_flow_flush(struct rte_eth_dev *dev, struct rte_flow_error *error);
@@ -57,10 +56,6 @@ int tap_flow_implicit_destroy(struct pmd_internals *pmd,
 int tap_flow_implicit_flush(struct pmd_internals *pmd,
 			    struct rte_flow_error *error);
 
-int tap_flow_bpf_cls_q(__u32 queue_idx);
-int tap_flow_bpf_calc_l3_l4_hash(__u32 key_idx, int map_fd);
-int tap_flow_bpf_rss_map_create(unsigned int key_size, unsigned int value_size,
-			unsigned int max_entries);
-int tap_flow_bpf_update_rss_elem(int fd, void *key, void *value);
+void tap_flow_bpf_destroy(struct pmd_internals *pmd);
 
 #endif /* _TAP_FLOW_H_ */
drivers/net/tap/tap_rss.h +4 -6
index 6009be7031..65bd8991b1 100644
@@ -5,16 +5,14 @@
 #ifndef _TAP_RSS_H_
 #define _TAP_RSS_H_
 
-#ifndef TAP_MAX_QUEUES
-#define TAP_MAX_QUEUES 16
+/* Size of the map from BPF classid to queue table */
+#ifndef TAP_RSS_MAX
+#define TAP_RSS_MAX	32
 #endif
 
-/* Fixed RSS hash key size in bytes. */
+/* Standard Toeplitz hash key size */
 #define TAP_RSS_HASH_KEY_SIZE 40
 
-/* Supported RSS */
-#define TAP_RSS_HF_MASK (~(RTE_ETH_RSS_IP | RTE_ETH_RSS_UDP | RTE_ETH_RSS_TCP))
-
 /* hashed fields for RSS */
 enum hash_field {
 	HASH_FIELD_IPV4_L3,	/* IPv4 src/dst addr */
drivers/net/tap/tap_tcmsgs.h +2 -2
index a64cb29d6f..9411626661 100644
@@ -6,7 +6,6 @@
 #ifndef _TAP_TCMSGS_H_
 #define _TAP_TCMSGS_H_
 
-#include <tap_autoconf.h>
 #include <linux/if_ether.h>
 #include <linux/rtnetlink.h>
 #include <linux/pkt_sched.h>
@@ -14,9 +13,10 @@
 #include <linux/tc_act/tc_mirred.h>
 #include <linux/tc_act/tc_gact.h>
 #include <linux/tc_act/tc_skbedit.h>
-#ifdef HAVE_TC_ACT_BPF
+#ifdef HAVE_BPF_RSS
 #include <linux/tc_act/tc_bpf.h>
 #endif
+
 #include <inttypes.h>
 
 #include <rte_ether.h>
Signature · 1 line
2.43.0