Skip to contentSkip to conversation

net/af_xdp: use libxdp if available

RFC PATCH New Ciara Loftus 3 participants 10 messages Dec 10, 2021 – Feb 1, 2022

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

RFC PATCH 1/1 net/af_xdp: use libxdp if available

AF_XDP support is deprecated in libbpf since v0.7.0 [1]. The libxdp library now provides the functionality which once was in libbpf and which the AF_XDP PMD relies on. This commit updates the AF_XDP meson build to use the libxdp library if available. If it is not available, only versions of libbpf prior to v0.7.0 are allowed, as they still contain the required AF_XDP functionality.

libbpf still remains a dependency even if libxdp is present, as we use libbpf APIs for program loading.

[1] https://github.com/libbpf/libbpf/commit/277846bc6c15

---
 doc/guides/nics/af_xdp.rst             |  4 +--
 doc/guides/rel_notes/release_22_03.rst |  4 +++
 drivers/net/af_xdp/compat.h            |  4 +++
 drivers/net/af_xdp/meson.build         | 45 +++++++++++++++++++++-----
 drivers/net/af_xdp/rte_eth_af_xdp.c    |  1 -
 5 files changed, 46 insertions(+), 12 deletions(-)
doc/guides/nics/af_xdp.rst +1 -3
index c9d0e1ad6c..966f713c11 100644
@@ -43,9 +43,7 @@ Prerequisites
 This is a Linux-specific PMD, thus the following prerequisites apply:
 
 *  A Linux Kernel (version > v4.18) with XDP sockets configuration enabled;
-*  libbpf (within kernel version > v5.1-rc4) with latest af_xdp support installed,
-   User can install libbpf via `make install_lib` && `make install_headers` in
-   <kernel src tree>/tools/lib/bpf;
+*  Both libxdp and libbpf libraries installed, or, libbpf <=v0.6.0
 *  A Kernel bound interface to attach to;
 *  For need_wakeup feature, it requires kernel version later than v5.3-rc1;
 *  For PMD zero copy, it requires kernel version later than v5.4-rc1;
doc/guides/rel_notes/release_22_03.rst +4 -0
index 6d99d1eaa9..acf0f66fa8 100644
@@ -55,6 +55,10 @@ New Features
      Also, make sure to start the actual text at the margin.
      =======================================================
 
+* **Update AF_XDP PMD**
+
+  * Added libxdp support.
+
 
 Removed Items
 -------------
drivers/net/af_xdp/compat.h +4 -0
index 3880dc7dd7..245df1b109 100644
@@ -2,7 +2,11 @@
  * Copyright(c) 2020 Intel Corporation.
  */
 
+#ifdef RTE_LIBRTE_AF_XDP_PMD_LIBXDP
+#include <xdp/xsk.h>
+#else
 #include <bpf/xsk.h>
+#endif
 #include <linux/version.h>
 #include <poll.h>
 
drivers/net/af_xdp/meson.build +37 -8

57 lines not on this page · raw message

drivers/net/af_xdp/rte_eth_af_xdp.c +0 -1
index 96c2c9d939..5d89bebb01 100644
@@ -16,7 +16,6 @@
 #include <linux/sockios.h>
 #include "af_xdp_deps.h"
 #include <bpf/bpf.h>
-#include <bpf/xsk.h>
 
 #include <rte_ethdev.h>
 #include <ethdev_driver.h>
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/1 net/af_xdp: use libxdp if available

AF_XDP support is deprecated in libbpf since v0.7.0 [1]. The libxdp library now provides the functionality which once was in libbpf and which the AF_XDP PMD relies on. This commit updates the AF_XDP meson build to use the libxdp library if a version >= v1.3.0 is available. If it is not available, only versions of libbpf prior to v0.7.0 are allowed, as they still contain the required AF_XDP functionality.

libbpf still remains a dependency even if libxdp is present, as we use libbpf APIs for program loading.

The minimum required kernel version for libxdp for use with AF_XDP is v5.3. For the library to be fully-featured, a kernel v5.10 or newer is recommended. The full compatibility information can be found in the libxdp README.

v1.3.0 of libxdp includes an important fix required for linking with DPDK which is why this version or greater is required. Meson uses pkg-config to verify the version of libxdp on the system, so it is necessary that the library is discoverable using pkg-config in order for the PMD to use it. To verify this, you can run:
pkg-config --modversion libxdp

[1] https://github.com/libbpf/libbpf/commit/277846bc6c15

---
RFC -> v1:
* Set minimum libxdp version at v1.3.0
* Don't provide alternative to discovery via pkg-config
* Add missing newline to end of file

---
 doc/guides/nics/af_xdp.rst             |  6 ++--
 doc/guides/rel_notes/release_22_03.rst |  4 +++
 drivers/net/af_xdp/compat.h            |  4 +++
 drivers/net/af_xdp/meson.build         | 39 +++++++++++++++++++++-----
 drivers/net/af_xdp/rte_eth_af_xdp.c    |  1 -
 5 files changed, 42 insertions(+), 12 deletions(-)
doc/guides/nics/af_xdp.rst +2 -4
index c9d0e1ad6c..60f4536ac5 100644
@@ -43,9 +43,7 @@ Prerequisites
 This is a Linux-specific PMD, thus the following prerequisites apply:
 
 *  A Linux Kernel (version > v4.18) with XDP sockets configuration enabled;
-*  libbpf (within kernel version > v5.1-rc4) with latest af_xdp support installed,
-   User can install libbpf via `make install_lib` && `make install_headers` in
-   <kernel src tree>/tools/lib/bpf;
+*  Both libxdp >=v1.3.0 and libbpf libraries installed, or, libbpf <=v0.6.0
 *  A Kernel bound interface to attach to;
 *  For need_wakeup feature, it requires kernel version later than v5.3-rc1;
 *  For PMD zero copy, it requires kernel version later than v5.4-rc1;
@@ -143,4 +141,4 @@ Limitations
   NAPI context from a watchdog timer instead of from softirqs. More information
   on this feature can be found at [1].
 
-  [1] https://lwn.net/Articles/837010/
\ No newline at end of file
+  [1] https://lwn.net/Articles/837010/
doc/guides/rel_notes/release_22_03.rst +4 -0
index 6d99d1eaa9..1258bdac61 100644
@@ -55,6 +55,10 @@ New Features
      Also, make sure to start the actual text at the margin.
      =======================================================
 
+* **Update AF_XDP PMD**
+
+  * Added support for libxdp >=v1.3.0.
+
 
 Removed Items
 -------------
drivers/net/af_xdp/compat.h +4 -0
index 3880dc7dd7..245df1b109 100644
@@ -2,7 +2,11 @@
  * Copyright(c) 2020 Intel Corporation.
  */
 
+#ifdef RTE_LIBRTE_AF_XDP_PMD_LIBXDP
+#include <xdp/xsk.h>
+#else
 #include <bpf/xsk.h>
+#endif
 #include <linux/version.h>
 #include <poll.h>
 
drivers/net/af_xdp/meson.build +32 -7
index 3ed2b29784..cdc4c1ca06 100644
@@ -9,19 +9,44 @@ endif
 
 sources = files('rte_eth_af_xdp.c')
 
+xdp_dep = dependency('libxdp', version : '>=1.3.0', required: false, method: 'pkg-config')
 bpf_dep = dependency('libbpf', required: false, method: 'pkg-config')
 if not bpf_dep.found()
     bpf_dep = cc.find_library('bpf', required: false)
 endif
 
-if bpf_dep.found() and cc.has_header('bpf/xsk.h') and cc.has_header('linux/if_xdp.h')
-    ext_deps += bpf_dep
-    bpf_ver_dep = dependency('libbpf', version : '>=0.2.0',
-            required: false, method: 'pkg-config')
-    if bpf_ver_dep.found()
-        dpdk_conf.set('RTE_LIBRTE_AF_XDP_PMD_SHARED_UMEM', 1)
+if cc.has_header('linux/if_xdp.h')
+    if xdp_dep.found() and cc.has_header('xdp/xsk.h')
+        if bpf_dep.found() and cc.has_header('bpf/bpf.h')
+            dpdk_conf.set('RTE_LIBRTE_AF_XDP_PMD_LIBXDP', 1)
+            dpdk_conf.set('RTE_LIBRTE_AF_XDP_PMD_SHARED_UMEM', 1)
+            ext_deps += xdp_dep
+            ext_deps += bpf_dep
+        else
+            build = false
+            reason = 'missing dependency, libbpf'
+        endif
+    elif bpf_dep.found() and cc.has_header('bpf/xsk.h') and cc.has_header('bpf/bpf.h')
+        # libxdp not found. Rely solely on libbpf for xsk functionality
+        # which is only available in versions <= v0.6.0.
+        bpf_ver_dep = dependency('libbpf', version : '<=0.6.0',
+                                 required: false, method: 'pkg-config')
+        if bpf_ver_dep.found()
+            ext_deps += bpf_dep
+            bpf_shumem_ver_dep = dependency('libbpf', version : '>=0.2.0',
+                            required: false, method: 'pkg-config')
+            if bpf_shumem_ver_dep.found()
+                dpdk_conf.set('RTE_LIBRTE_AF_XDP_PMD_SHARED_UMEM', 1)
+            endif
+        else
+            build = false
+            reason = 'missing dependency, "libxdp" or "libbpf <= v0.6.0"'
+        endif
+    else
+        build = false
+        reason = 'missing dependency, "libxdp" and "libbpf"'
     endif
 else
     build = false
-    reason = 'missing dependency, "libbpf"'
+    reason = 'missing header, "linux/if_xdp.h"'
 endif
drivers/net/af_xdp/rte_eth_af_xdp.c +0 -1
index 96c2c9d939..5d89bebb01 100644
@@ -16,7 +16,6 @@
 #include <linux/sockios.h>
 #include "af_xdp_deps.h"
 #include <bpf/bpf.h>
-#include <bpf/xsk.h>
 
 #include <rte_ethdev.h>
 #include <ethdev_driver.h>
Signature · 1 line
2.17.1
#2 lore raw

PATCH v2 1/1 net/af_xdp: use libxdp if available

AF_XDP support is deprecated in libbpf since v0.7.0 [1]. The libxdp library now provides the functionality which once was in libbpf and which the AF_XDP PMD relies on. This commit updates the AF_XDP meson build to use the libxdp library if a version >= v1.2.2 is available. If it is not available, only versions of libbpf prior to v0.7.0 are allowed, as they still contain the required AF_XDP functionality.

libbpf still remains a dependency even if libxdp is present, as we use libbpf APIs for program loading.

The minimum required kernel version for libxdp for use with AF_XDP is v5.3. For the library to be fully-featured, a kernel v5.10 or newer is recommended. The full compatibility information can be found in the libxdp README.

v1.2.2 of libxdp includes an important fix required for linking with DPDK which is why this version or greater is required. Meson uses pkg-config to verify the version of libxdp on the system, so it is necessary that the library is discoverable using pkg-config in order for the PMD to use it. To verify this, you can run:
pkg-config --modversion libxdp

[1] https://github.com/libbpf/libbpf/commit/277846bc6c15

---
v2:
* Set minimum libxdp version at v1.2.2

RFC -> v1:
* Set minimum libxdp version at v1.3.0
* Don't provide alternative to discovery via pkg-config
* Add missing newline to end of file

---
 doc/guides/nics/af_xdp.rst             |  6 ++--
 doc/guides/rel_notes/release_22_03.rst |  4 +++
 drivers/net/af_xdp/compat.h            |  4 +++
 drivers/net/af_xdp/meson.build         | 39 +++++++++++++++++++++-----
 drivers/net/af_xdp/rte_eth_af_xdp.c    |  1 -
 5 files changed, 42 insertions(+), 12 deletions(-)
doc/guides/nics/af_xdp.rst +2 -4
index c9d0e1ad6c..db02ea1984 100644
@@ -43,9 +43,7 @@ Prerequisites
 This is a Linux-specific PMD, thus the following prerequisites apply:
 
 *  A Linux Kernel (version > v4.18) with XDP sockets configuration enabled;
-*  libbpf (within kernel version > v5.1-rc4) with latest af_xdp support installed,
-   User can install libbpf via `make install_lib` && `make install_headers` in
-   <kernel src tree>/tools/lib/bpf;
+*  Both libxdp >=v1.2.2 and libbpf libraries installed, or, libbpf <=v0.6.0
 *  A Kernel bound interface to attach to;
 *  For need_wakeup feature, it requires kernel version later than v5.3-rc1;
 *  For PMD zero copy, it requires kernel version later than v5.4-rc1;
@@ -143,4 +141,4 @@ Limitations
   NAPI context from a watchdog timer instead of from softirqs. More information
   on this feature can be found at [1].
 
-  [1] https://lwn.net/Articles/837010/
\ No newline at end of file
+  [1] https://lwn.net/Articles/837010/
doc/guides/rel_notes/release_22_03.rst +4 -0
index 8a202ec4f4..ad7283df65 100644
@@ -55,6 +55,10 @@ New Features
      Also, make sure to start the actual text at the margin.
      =======================================================
 
+* **Update AF_XDP PMD**
+
+  * Added support for libxdp >=v1.2.2.
+
 
 Removed Items
 -------------
drivers/net/af_xdp/compat.h +4 -0
index 3880dc7dd7..245df1b109 100644
@@ -2,7 +2,11 @@
  * Copyright(c) 2020 Intel Corporation.
  */
 
+#ifdef RTE_LIBRTE_AF_XDP_PMD_LIBXDP
+#include <xdp/xsk.h>
+#else
 #include <bpf/xsk.h>
+#endif
 #include <linux/version.h>
 #include <poll.h>
 
drivers/net/af_xdp/meson.build +32 -7
index 3ed2b29784..981d4c6087 100644
@@ -9,19 +9,44 @@ endif
 
 sources = files('rte_eth_af_xdp.c')
 
+xdp_dep = dependency('libxdp', version : '>=1.2.2', required: false, method: 'pkg-config')
 bpf_dep = dependency('libbpf', required: false, method: 'pkg-config')
 if not bpf_dep.found()
     bpf_dep = cc.find_library('bpf', required: false)
 endif
 
-if bpf_dep.found() and cc.has_header('bpf/xsk.h') and cc.has_header('linux/if_xdp.h')
-    ext_deps += bpf_dep
-    bpf_ver_dep = dependency('libbpf', version : '>=0.2.0',
-            required: false, method: 'pkg-config')
-    if bpf_ver_dep.found()
-        dpdk_conf.set('RTE_LIBRTE_AF_XDP_PMD_SHARED_UMEM', 1)
+if cc.has_header('linux/if_xdp.h')
+    if xdp_dep.found() and cc.has_header('xdp/xsk.h')
+        if bpf_dep.found() and cc.has_header('bpf/bpf.h')
+            dpdk_conf.set('RTE_LIBRTE_AF_XDP_PMD_LIBXDP', 1)
+            dpdk_conf.set('RTE_LIBRTE_AF_XDP_PMD_SHARED_UMEM', 1)
+            ext_deps += xdp_dep
+            ext_deps += bpf_dep
+        else
+            build = false
+            reason = 'missing dependency, libbpf'
+        endif
+    elif bpf_dep.found() and cc.has_header('bpf/xsk.h') and cc.has_header('bpf/bpf.h')
+        # libxdp not found. Rely solely on libbpf for xsk functionality
+        # which is only available in versions <= v0.6.0.
+        bpf_ver_dep = dependency('libbpf', version : '<=0.6.0',
+                                 required: false, method: 'pkg-config')
+        if bpf_ver_dep.found()
+            ext_deps += bpf_dep
+            bpf_shumem_ver_dep = dependency('libbpf', version : '>=0.2.0',
+                            required: false, method: 'pkg-config')
+            if bpf_shumem_ver_dep.found()
+                dpdk_conf.set('RTE_LIBRTE_AF_XDP_PMD_SHARED_UMEM', 1)
+            endif
+        else
+            build = false
+            reason = 'missing dependency, "libxdp" or "libbpf <= v0.6.0"'
+        endif
+    else
+        build = false
+        reason = 'missing dependency, "libxdp" and "libbpf"'
     endif
 else
     build = false
-    reason = 'missing dependency, "libbpf"'
+    reason = 'missing header, "linux/if_xdp.h"'
 endif
drivers/net/af_xdp/rte_eth_af_xdp.c +0 -1
index 96c2c9d939..5d89bebb01 100644
@@ -16,7 +16,6 @@
 #include <linux/sockios.h>
 #include "af_xdp_deps.h"
 #include <bpf/bpf.h>
-#include <bpf/xsk.h>
 
 #include <rte_ethdev.h>
 #include <ethdev_driver.h>
Signature · 1 line
2.17.1
#3 lore raw
Quoted 22 lines · Ciara Loftus

AF_XDP support is deprecated in libbpf since v0.7.0 [1]. The libxdp library now provides the functionality which once was in libbpf and which the AF_XDP PMD relies on. This commit updates the AF_XDP meson build to use the libxdp library if a version >= v1.2.2 is available. If it is not available, only versions of libbpf prior to v0.7.0 are allowed, as they still contain the required AF_XDP functionality.

libbpf still remains a dependency even if libxdp is present, as we use libbpf APIs for program loading.

The minimum required kernel version for libxdp for use with AF_XDP is v5.3. For the library to be fully-featured, a kernel v5.10 or newer is recommended. The full compatibility information can be found in the libxdp README.

v1.2.2 of libxdp includes an important fix required for linking with DPDK which is why this version or greater is required. Meson uses pkg-config to verify the version of libxdp on the system, so it is necessary that the library is discoverable using pkg-config in order for the PMD to use it. To verify this, you can run:
pkg-config --modversion libxdp

Quoted 3 lines

[1] https://github.com/libbpf/libbpf/commit/277846bc6c15

Hi Ciara,

couple of comments inline below.

/Bruce

Quoted 58 lines

---
v2:
* Set minimum libxdp version at v1.2.2

RFC -> v1:
* Set minimum libxdp version at v1.3.0
* Don't provide alternative to discovery via pkg-config
* Add missing newline to end of file

---
 doc/guides/nics/af_xdp.rst             |  6 ++--
 doc/guides/rel_notes/release_22_03.rst |  4 +++
 drivers/net/af_xdp/compat.h            |  4 +++
 drivers/net/af_xdp/meson.build         | 39 +++++++++++++++++++++-----
 drivers/net/af_xdp/rte_eth_af_xdp.c    |  1 -
 5 files changed, 42 insertions(+), 12 deletions(-)
doc/guides/nics/af_xdp.rst +2 -4
index c9d0e1ad6c..db02ea1984 100644
@@ -43,9 +43,7 @@ Prerequisites
 This is a Linux-specific PMD, thus the following prerequisites apply:
 
 *  A Linux Kernel (version > v4.18) with XDP sockets configuration enabled;
-*  libbpf (within kernel version > v5.1-rc4) with latest af_xdp support installed,
-   User can install libbpf via `make install_lib` && `make install_headers` in
-   <kernel src tree>/tools/lib/bpf;
+*  Both libxdp >=v1.2.2 and libbpf libraries installed, or, libbpf <=v0.6.0
 *  A Kernel bound interface to attach to;
 *  For need_wakeup feature, it requires kernel version later than v5.3-rc1;
 *  For PMD zero copy, it requires kernel version later than v5.4-rc1;
@@ -143,4 +141,4 @@ Limitations
   NAPI context from a watchdog timer instead of from softirqs. More information
   on this feature can be found at [1].
 
-  [1] https://lwn.net/Articles/837010/
\ No newline at end of file
+  [1] https://lwn.net/Articles/837010/
doc/guides/rel_notes/release_22_03.rst +4 -0
index 8a202ec4f4..ad7283df65 100644
@@ -55,6 +55,10 @@ New Features
      Also, make sure to start the actual text at the margin.
      =======================================================
 
+* **Update AF_XDP PMD**
+
+  * Added support for libxdp >=v1.2.2.
+
 
 Removed Items
 -------------
drivers/net/af_xdp/compat.h +0 -0
index 3880dc7dd7..245df1b109 100644

drivers/net/af_xdp/compat.h line 5

Quoted 4 lines
drivers/net/af_xdp/compat.h +1 -0
@@ -2,7 +2,11 @@
  * Copyright(c) 2020 Intel Corporation.
  */
 
+#ifdef RTE_LIBRTE_AF_XDP_PMD_LIBXDP

This is a really long macro name. With meson builds we have largely moved away from using "RTE_LIBRTE_" as a prefix, and also have dropped "PMD" from names too. The global enable macro for AF_XDP driver is now "RTE_NET_AF_XDP" so I'd suggest this macro could be shortened to "RTE_NET_AF_XDP_LIBXDP".

Quoted 22 lines
drivers/net/af_xdp/compat.h +3 -0
+#include <xdp/xsk.h>
+#else
 #include <bpf/xsk.h>
+#endif
 #include <linux/version.h>
 #include <poll.h>
 
drivers/net/af_xdp/meson.build +1 -1
index 3ed2b29784..981d4c6087 100644
@@ -9,19 +9,44 @@ endif
 
 sources = files('rte_eth_af_xdp.c')
 
+xdp_dep = dependency('libxdp', version : '>=1.2.2', required: false, method: 'pkg-config')
 bpf_dep = dependency('libbpf', required: false, method: 'pkg-config')
 if not bpf_dep.found()
     bpf_dep = cc.find_library('bpf', required: false)
 endif
 
-if bpf_dep.found() and cc.has_header('bpf/xsk.h') and cc.has_header('linux/if_xdp.h')

drivers/net/af_xdp/meson.build endif · line 22

Quoted 10 lines
drivers/net/af_xdp/meson.build +5 -5
-    ext_deps += bpf_dep
-    bpf_ver_dep = dependency('libbpf', version : '>=0.2.0',
-            required: false, method: 'pkg-config')
-    if bpf_ver_dep.found()
-        dpdk_conf.set('RTE_LIBRTE_AF_XDP_PMD_SHARED_UMEM', 1)
+if cc.has_header('linux/if_xdp.h')
+    if xdp_dep.found() and cc.has_header('xdp/xsk.h')
+        if bpf_dep.found() and cc.has_header('bpf/bpf.h')
+            dpdk_conf.set('RTE_LIBRTE_AF_XDP_PMD_LIBXDP', 1)
+            dpdk_conf.set('RTE_LIBRTE_AF_XDP_PMD_SHARED_UMEM', 1)

Do these defines need to be exposed to the end user, or are they for internal use only? If they don't need to be exposed to the user, I'd suggest changing them to cflags, rather than writing them to the build config. As well as reducing the info we show to the end user, not having them in the build config means that if they change, only this driver needs a rebuild, rather than the whole of DPDK. [Every DPDK file includes the build config, so a change there requires everything rebuild]

Quoted 6 lines
drivers/net/af_xdp/meson.build +6 -0
+            ext_deps += xdp_dep
+            ext_deps += bpf_dep
+        else
+            build = false
+            reason = 'missing dependency, libbpf'
+        endif

<snip>

#4 lore raw
Quoted 100 lines · Ciara Loftus
Quoted 11 lines

AF_XDP support is deprecated in libbpf since v0.7.0 [1]. The libxdp library now provides the functionality which once was in libbpf and which the AF_XDP PMD relies on. This commit updates the AF_XDP meson build to use the libxdp library if a version >= v1.2.2 is available. If it is not available, only versions of libbpf prior to v0.7.0 are allowed, as they still contain the required AF_XDP functionality.

libbpf still remains a dependency even if libxdp is present, as we use libbpf APIs for program loading.

The minimum required kernel version for libxdp for use with AF_XDP is

v5.3.

Quoted 2 lines

For the library to be fully-featured, a kernel v5.10 or newer is recommended. The full compatibility information can be found in the

libxdp

Quoted 9 lines

README.

v1.2.2 of libxdp includes an important fix required for linking with DPDK which is why this version or greater is required. Meson uses pkg-config to verify the version of libxdp on the system, so it is necessary that the library is discoverable using pkg-config in order for the PMD to use it. To verify this, you can run:
pkg-config --modversion libxdp

Quoted 3 lines

[1] https://github.com/libbpf/libbpf/commit/277846bc6c15

Hi Ciara,

couple of comments inline below.

/Bruce

Quoted 21 lines

---
v2:
* Set minimum libxdp version at v1.2.2

RFC -> v1:
* Set minimum libxdp version at v1.3.0
* Don't provide alternative to discovery via pkg-config
* Add missing newline to end of file

---
 doc/guides/nics/af_xdp.rst             |  6 ++--
 doc/guides/rel_notes/release_22_03.rst |  4 +++
 drivers/net/af_xdp/compat.h            |  4 +++
 drivers/net/af_xdp/meson.build         | 39 +++++++++++++++++++++-----
 drivers/net/af_xdp/rte_eth_af_xdp.c    |  1 -
 5 files changed, 42 insertions(+), 12 deletions(-)
doc/guides/nics/af_xdp.rst +0 -0
index c9d0e1ad6c..db02ea1984 100644

doc/guides/nics/af_xdp.rst Prerequisites · line 46

Quoted 4 lines
doc/guides/nics/af_xdp.rst +0 -1
@@ -43,9 +43,7 @@ Prerequisites
 This is a Linux-specific PMD, thus the following prerequisites apply:
 
 *  A Linux Kernel (version > v4.18) with XDP sockets configuration enabled;
-*  libbpf (within kernel version > v5.1-rc4) with latest af_xdp support

installed,

doc/guides/nics/af_xdp.rst Limitations · line 141

Quoted 8 lines
doc/guides/nics/af_xdp.rst +1 -2
-   User can install libbpf via `make install_lib` && `make install_headers` in
-   <kernel src tree>/tools/lib/bpf;
+*  Both libxdp >=v1.2.2 and libbpf libraries installed, or, libbpf <=v0.6.0
 *  A Kernel bound interface to attach to;
 *  For need_wakeup feature, it requires kernel version later than v5.3-rc1;
 *  For PMD zero copy, it requires kernel version later than v5.4-rc1;
@@ -143,4 +141,4 @@ Limitations
   NAPI context from a watchdog timer instead of from softirqs. More

information

Review

Quoted 6 lines
doc/guides/nics/af_xdp.rst +1 -1
   on this feature can be found at [1].
 
-  [1] https://lwn.net/Articles/837010/
\ No newline at end of file
+  [1] https://lwn.net/Articles/837010/
(quoted diff) +0 -0

b/doc/guides/rel_notes/release_22_03.rst

Quoted 22 lines

index 8a202ec4f4..ad7283df65 100644

doc/guides/rel_notes/release_22_03.rst +4 -0
@@ -55,6 +55,10 @@ New Features
      Also, make sure to start the actual text at the margin.
      =======================================================
 
+* **Update AF_XDP PMD**
+
+  * Added support for libxdp >=v1.2.2.
+
 
 Removed Items
 -------------
drivers/net/af_xdp/compat.h +0 -0
index 3880dc7dd7..245df1b109 100644
@@ -2,7 +2,11 @@
  * Copyright(c) 2020 Intel Corporation.
  */
 
Quoted 8 lines

drivers/net/af_xdp/compat.h line 5

Quoted 1 line
drivers/net/af_xdp/compat.h +1 -0
+#ifdef RTE_LIBRTE_AF_XDP_PMD_LIBXDP

This is a really long macro name. With meson builds we have largely moved away from using "RTE_LIBRTE_" as a prefix, and also have dropped "PMD" from
names too. The global enable macro for AF_XDP driver is now "RTE_NET_AF_XDP" so I'd suggest this macro could be shortened to "RTE_NET_AF_XDP_LIBXDP".

+1

Quoted 37 lines

Review

Quoted 9 lines
drivers/net/af_xdp/compat.h +3 -0
+#include <xdp/xsk.h>
+#else
 #include <bpf/xsk.h>
+#endif
 #include <linux/version.h>
 #include <poll.h>
 
(quoted diff) +0 -0

b/drivers/net/af_xdp/meson.build

drivers/net/af_xdp/meson.build endif · line 12

Quoted 8 lines

index 3ed2b29784..981d4c6087 100644

drivers/net/af_xdp/meson.build +1 -0
@@ -9,19 +9,44 @@ endif
 
 sources = files('rte_eth_af_xdp.c')
 
+xdp_dep = dependency('libxdp', version : '>=1.2.2', required: false,

method: 'pkg-config')

drivers/net/af_xdp/meson.build endif

Quoted 6 lines
drivers/net/af_xdp/meson.build +0 -1
 bpf_dep = dependency('libbpf', required: false, method: 'pkg-config')
 if not bpf_dep.found()
     bpf_dep = cc.find_library('bpf', required: false)
 endif
 
-if bpf_dep.found() and cc.has_header('bpf/xsk.h') and

cc.has_header('linux/if_xdp.h')

drivers/net/af_xdp/meson.build endif · line 22

Quoted 10 lines
drivers/net/af_xdp/meson.build +5 -5
-    ext_deps += bpf_dep
-    bpf_ver_dep = dependency('libbpf', version : '>=0.2.0',
-            required: false, method: 'pkg-config')
-    if bpf_ver_dep.found()
-        dpdk_conf.set('RTE_LIBRTE_AF_XDP_PMD_SHARED_UMEM', 1)
+if cc.has_header('linux/if_xdp.h')
+    if xdp_dep.found() and cc.has_header('xdp/xsk.h')
+        if bpf_dep.found() and cc.has_header('bpf/bpf.h')
+            dpdk_conf.set('RTE_LIBRTE_AF_XDP_PMD_LIBXDP', 1)
+            dpdk_conf.set('RTE_LIBRTE_AF_XDP_PMD_SHARED_UMEM', 1)
Quoted 7 lines

Do these defines need to be exposed to the end user, or are they for internal use only? If they don't need to be exposed to the user, I'd suggest changing them to cflags, rather than writing them to the build config. As well as reducing the info we show to the end user, not having them in the build config means that if they change, only this driver needs a rebuild, rather than the whole of DPDK. [Every DPDK file includes the build config, so a change there requires everything rebuild]

These don't need to be exposed to the end user. Thanks for the suggestion, it definitely makes more sense to use cflags instead. I'll add that in the v3.

Thanks,
Ciara

Quoted 8 lines
Quoted 7 lines
drivers/net/af_xdp/meson.build +6 -0
+            ext_deps += xdp_dep
+            ext_deps += bpf_dep
+        else
+            build = false
+            reason = 'missing dependency, libbpf'
+        endif

<snip>

#5 lore raw

PATCH v3 1/1 net/af_xdp: use libxdp if available

In reply to Ciara Loftus

AF_XDP support is deprecated in libbpf since v0.7.0 [1]. The libxdp library now provides the functionality which once was in libbpf and which the AF_XDP PMD relies on. This commit updates the AF_XDP meson build to use the libxdp library if a version >= v1.2.2 is available. If it is not available, only versions of libbpf prior to v0.7.0 are allowed, as they still contain the required AF_XDP functionality.

libbpf still remains a dependency even if libxdp is present, as we use libbpf APIs for program loading.

The minimum required kernel version for libxdp for use with AF_XDP is v5.3. For the library to be fully-featured, a kernel v5.10 or newer is recommended. The full compatibility information can be found in the libxdp README.

v1.2.2 of libxdp includes an important fix required for linking with DPDK which is why this version or greater is required. Meson uses pkg-config to verify the version of libxdp on the system, so it is necessary that the library is discoverable using pkg-config in order for the PMD to use it. To verify this, you can run: pkg-config --modversion libxdp

[1] https://github.com/libbpf/libbpf/commit/277846bc6c15

---
v3:
* Use cflags instead of writing to the build config
* Change flag names to suit convention.

v2:
* Set minimum libxdp version at v1.2.2

RFC -> v1:
* Set minimum libxdp version at v1.3.0
* Don't provide alternative to discovery via pkg-config
* Add missing newline to end of file

---
 doc/guides/nics/af_xdp.rst             |  6 ++--
 doc/guides/rel_notes/release_22_03.rst |  4 +++
 drivers/net/af_xdp/compat.h            |  6 +++-
 drivers/net/af_xdp/meson.build         | 39 +++++++++++++++++++++-----
 drivers/net/af_xdp/rte_eth_af_xdp.c    |  1 -
 5 files changed, 43 insertions(+), 13 deletions(-)
doc/guides/nics/af_xdp.rst +2 -4
index c9d0e1ad6c..db02ea1984 100644
@@ -43,9 +43,7 @@ Prerequisites
 This is a Linux-specific PMD, thus the following prerequisites apply:
 
 *  A Linux Kernel (version > v4.18) with XDP sockets configuration enabled;
-*  libbpf (within kernel version > v5.1-rc4) with latest af_xdp support installed,
-   User can install libbpf via `make install_lib` && `make install_headers` in
-   <kernel src tree>/tools/lib/bpf;
+*  Both libxdp >=v1.2.2 and libbpf libraries installed, or, libbpf <=v0.6.0
 *  A Kernel bound interface to attach to;
 *  For need_wakeup feature, it requires kernel version later than v5.3-rc1;
 *  For PMD zero copy, it requires kernel version later than v5.4-rc1;
@@ -143,4 +141,4 @@ Limitations
   NAPI context from a watchdog timer instead of from softirqs. More information
   on this feature can be found at [1].
 
-  [1] https://lwn.net/Articles/837010/
\ No newline at end of file
+  [1] https://lwn.net/Articles/837010/
doc/guides/rel_notes/release_22_03.rst +4 -0
index 3bc0630c7c..68ef02cb54 100644
@@ -69,6 +69,10 @@ New Features
 
   The new API ``rte_event_eth_rx_adapter_event_port_get()`` was added.
 
+* **Update AF_XDP PMD**
+
+  * Added support for libxdp >=v1.2.2.
+
 
 Removed Items
 -------------
drivers/net/af_xdp/compat.h +5 -1
index 3880dc7dd7..bf40c6572e 100644
@@ -2,12 +2,16 @@
  * Copyright(c) 2020 Intel Corporation.
  */
 
+#ifdef RTE_NET_AF_XDP_LIBXDP
+#include <xdp/xsk.h>
+#else
 #include <bpf/xsk.h>
+#endif
 #include <linux/version.h>
 #include <poll.h>
 
 #if KERNEL_VERSION(5, 10, 0) <= LINUX_VERSION_CODE && \
-	defined(RTE_LIBRTE_AF_XDP_PMD_SHARED_UMEM)
+	defined(RTE_NET_AF_XDP_SHARED_UMEM)
 #define ETH_AF_XDP_SHARED_UMEM 1
 #endif
 
drivers/net/af_xdp/meson.build +32 -7
index 3ed2b29784..93e895eab9 100644
@@ -9,19 +9,44 @@ endif
 
 sources = files('rte_eth_af_xdp.c')
 
+xdp_dep = dependency('libxdp', version : '>=1.2.2', required: false, method: 'pkg-config')
 bpf_dep = dependency('libbpf', required: false, method: 'pkg-config')
 if not bpf_dep.found()
     bpf_dep = cc.find_library('bpf', required: false)
 endif
 
-if bpf_dep.found() and cc.has_header('bpf/xsk.h') and cc.has_header('linux/if_xdp.h')
-    ext_deps += bpf_dep
-    bpf_ver_dep = dependency('libbpf', version : '>=0.2.0',
-            required: false, method: 'pkg-config')
-    if bpf_ver_dep.found()
-        dpdk_conf.set('RTE_LIBRTE_AF_XDP_PMD_SHARED_UMEM', 1)
+if cc.has_header('linux/if_xdp.h')
+    if xdp_dep.found() and cc.has_header('xdp/xsk.h')
+        if bpf_dep.found() and cc.has_header('bpf/bpf.h')
+            cflags += ['-DRTE_NET_AF_XDP_LIBXDP']
+            cflags += ['-DRTE_NET_AF_XDP_SHARED_UMEM']
+            ext_deps += xdp_dep
+            ext_deps += bpf_dep
+        else
+            build = false
+            reason = 'missing dependency, libbpf'
+        endif
+    elif bpf_dep.found() and cc.has_header('bpf/xsk.h') and cc.has_header('bpf/bpf.h')
+        # libxdp not found. Rely solely on libbpf for xsk functionality
+        # which is only available in versions <= v0.6.0.
+        bpf_ver_dep = dependency('libbpf', version : '<=0.6.0',
+                                 required: false, method: 'pkg-config')
+        if bpf_ver_dep.found()
+            ext_deps += bpf_dep
+            bpf_shumem_ver_dep = dependency('libbpf', version : '>=0.2.0',
+                            required: false, method: 'pkg-config')
+            if bpf_shumem_ver_dep.found()
+                cflags += ['-DRTE_NET_AF_XDP_SHARED_UMEM']
+            endif
+        else
+            build = false
+            reason = 'missing dependency, "libxdp" or "libbpf <= v0.6.0"'
+        endif
+    else
+        build = false
+        reason = 'missing dependency, "libxdp" and "libbpf"'
     endif
 else
     build = false
-    reason = 'missing dependency, "libbpf"'
+    reason = 'missing header, "linux/if_xdp.h"'
 endif
drivers/net/af_xdp/rte_eth_af_xdp.c +0 -1
index 96c2c9d939..5d89bebb01 100644
@@ -16,7 +16,6 @@
 #include <linux/sockios.h>
 #include "af_xdp_deps.h"
 #include <bpf/bpf.h>
-#include <bpf/xsk.h>
 
 #include <rte_ethdev.h>
 #include <ethdev_driver.h>
Signature · 1 line
2.17.1
#6 lore raw
Quoted 21 lines · Ciara Loftus

AF_XDP support is deprecated in libbpf since v0.7.0 [1]. The libxdp library now provides the functionality which once was in libbpf and which the AF_XDP PMD relies on. This commit updates the AF_XDP meson build to use the libxdp library if a version >= v1.2.2 is available. If it is not available, only versions of libbpf prior to v0.7.0 are allowed, as they still contain the required AF_XDP functionality.

libbpf still remains a dependency even if libxdp is present, as we use libbpf APIs for program loading.

The minimum required kernel version for libxdp for use with AF_XDP is v5.3. For the library to be fully-featured, a kernel v5.10 or newer is recommended. The full compatibility information can be found in the libxdp README.

v1.2.2 of libxdp includes an important fix required for linking with DPDK which is why this version or greater is required. Meson uses pkg-config to verify the version of libxdp on the system, so it is necessary that the library is discoverable using pkg-config in order for the PMD to use it. To verify this, you can run: pkg-config --modversion libxdp

Quoted 3 lines

[1] https://github.com/libbpf/libbpf/commit/277846bc6c15

Tested build with combination of following, build looks good libxdp 1.2.0, libxdp 1.2.2
libbpf 0.7.0, libbpf 0.4.0

But while running testpmd can't find the libxdp.so by default [1], although setting 'LD_LIBRARY_PATH' works (LD_LIBRARY_PATH=/usr/local/lib64/ for my case), this wasn't required for libbpf, just checking if this is expected?

Similarly for 'build/drivers/librte_net_af_xdp.so', ldd can find 'libbpf' but not libxdp.so (although they are in same folder):

$ ldd build/drivers/librte_net_af_xdp.so
        libxdp.so.1 => not found
        libbpf.so.0 => /usr/local/lib64/libbpf.so.0 (0x00007f2ceb86f000)
        ....

Again, 'LD_LIBRARY_PATH' works:

$ LD_LIBRARY_PATH=/usr/local/lib64/ ldd build/drivers/librte_net_af_xdp.so
        libxdp.so.1 => /usr/local/lib64/libxdp.so.1 (0x00007fefa792e000)
        libbpf.so.0 => /usr/local/lib64/libbpf.so.0 (0x00007fefa78dc000)

But same question, why 'LD_LIBRARY_PATH' is not required for libbpf, but required for libxdp, any idea?

[1]
./build/app/dpdk-testpmd: error while loading shared libraries: libxdp.so.1: cannot open shared object file: No such file or directory

#7 lore raw
Quoted 41 lines · Ferruh Yigit
Quoted 22 lines · Ciara Loftus

AF_XDP support is deprecated in libbpf since v0.7.0 [1]. The libxdp library now provides the functionality which once was in libbpf and which the AF_XDP PMD relies on. This commit updates the AF_XDP meson build to use the libxdp library if a version >= v1.2.2 is available. If it is not available, only versions of libbpf prior to v0.7.0 are allowed, as they still contain the required AF_XDP functionality.

libbpf still remains a dependency even if libxdp is present, as we use libbpf APIs for program loading.

The minimum required kernel version for libxdp for use with AF_XDP is v5.3. For the library to be fully-featured, a kernel v5.10 or newer is recommended. The full compatibility information can be found in the libxdp README.

v1.2.2 of libxdp includes an important fix required for linking with DPDK which is why this version or greater is required. Meson uses pkg-config to verify the version of libxdp on the system, so it is necessary that the library is discoverable using pkg-config in order for the PMD to use it. To verify this, you can run: pkg-config --modversion libxdp

Quoted 3 lines

[1] https://github.com/libbpf/libbpf/commit/277846bc6c15

Tested build with combination of following, build looks good libxdp 1.2.0, libxdp 1.2.2 libbpf 0.7.0, libbpf 0.4.0

But while running testpmd can't find the libxdp.so by default [1], although setting 'LD_LIBRARY_PATH' works (LD_LIBRARY_PATH=/usr/local/lib64/ for my case), this wasn't required for libbpf, just checking if this is expected?

Similarly for 'build/drivers/librte_net_af_xdp.so', ldd can find 'libbpf' but not libxdp.so (although they are in same folder): $ ldd build/drivers/librte_net_af_xdp.so libxdp.so.1 => not found libbpf.so.0 => /usr/local/lib64/libbpf.so.0 (0x00007f2ceb86f000) ....

Quoted 9 lines

Again, 'LD_LIBRARY_PATH' works: $ LD_LIBRARY_PATH=/usr/local/lib64/ ldd build/drivers/librte_net_af_xdp.so libxdp.so.1 => /usr/local/lib64/libxdp.so.1 (0x00007fefa792e000) libbpf.so.0 => /usr/local/lib64/libbpf.so.0 (0x00007fefa78dc000)

But same question, why 'LD_LIBRARY_PATH' is not required for libbpf, but required for libxdp, any idea?

Did you rerun "ldconfig" to refresh the ldd cache after installing the new library?

#8 lore raw
Quoted 48 lines · Bruce Richardson
Quoted 47 lines · Ferruh Yigit
Quoted 22 lines · Ciara Loftus

AF_XDP support is deprecated in libbpf since v0.7.0 [1]. The libxdp library now provides the functionality which once was in libbpf and which the AF_XDP PMD relies on. This commit updates the AF_XDP meson build to use the libxdp library if a version >= v1.2.2 is available. If it is not available, only versions of libbpf prior to v0.7.0 are allowed, as they still contain the required AF_XDP functionality.

libbpf still remains a dependency even if libxdp is present, as we use libbpf APIs for program loading.

The minimum required kernel version for libxdp for use with AF_XDP is v5.3. For the library to be fully-featured, a kernel v5.10 or newer is recommended. The full compatibility information can be found in the libxdp README.

v1.2.2 of libxdp includes an important fix required for linking with DPDK which is why this version or greater is required. Meson uses pkg-config to verify the version of libxdp on the system, so it is necessary that the library is discoverable using pkg-config in order for the PMD to use it. To verify this, you can run: pkg-config --modversion libxdp

Quoted 3 lines

[1] https://github.com/libbpf/libbpf/commit/277846bc6c15

Tested build with combination of following, build looks good libxdp 1.2.0, libxdp 1.2.2 libbpf 0.7.0, libbpf 0.4.0

But while running testpmd can't find the libxdp.so by default [1], although setting 'LD_LIBRARY_PATH' works (LD_LIBRARY_PATH=/usr/local/lib64/ for my case), this wasn't required for libbpf, just checking if this is expected?

Similarly for 'build/drivers/librte_net_af_xdp.so', ldd can find 'libbpf' but not libxdp.so (although they are in same folder): $ ldd build/drivers/librte_net_af_xdp.so libxdp.so.1 => not found libbpf.so.0 => /usr/local/lib64/libbpf.so.0 (0x00007f2ceb86f000) ....

Again, 'LD_LIBRARY_PATH' works: $ LD_LIBRARY_PATH=/usr/local/lib64/ ldd build/drivers/librte_net_af_xdp.so libxdp.so.1 => /usr/local/lib64/libxdp.so.1 (0x00007fefa792e000) libbpf.so.0 => /usr/local/lib64/libbpf.so.0 (0x00007fefa78dc000)

Quoted 5 lines
Quoted 3 lines

But same question, why 'LD_LIBRARY_PATH' is not required for libbpf, but required for libxdp, any idea?

Did you rerun "ldconfig" to refresh the ldd cache after installing the new library?

No I didn't.
But it works as expected next day without me doing anything, if the issue was ldconfig there can be regular periodic runs for it (I expect installing a new library automatically trigger the ldconfig).

Anyway, I am proceeding with patch as it is working now as expected.

Applied
#9 lore raw
In reply to Ciara Loftus
Quoted 21 lines · Ciara Loftus

AF_XDP support is deprecated in libbpf since v0.7.0 [1]. The libxdp library now provides the functionality which once was in libbpf and which the AF_XDP PMD relies on. This commit updates the AF_XDP meson build to use the libxdp library if a version >= v1.2.2 is available. If it is not available, only versions of libbpf prior to v0.7.0 are allowed, as they still contain the required AF_XDP functionality.

libbpf still remains a dependency even if libxdp is present, as we use libbpf APIs for program loading.

The minimum required kernel version for libxdp for use with AF_XDP is v5.3. For the library to be fully-featured, a kernel v5.10 or newer is recommended. The full compatibility information can be found in the libxdp README.

v1.2.2 of libxdp includes an important fix required for linking with DPDK which is why this version or greater is required. Meson uses pkg-config to verify the version of libxdp on the system, so it is necessary that the library is discoverable using pkg-config in order for the PMD to use it. To verify this, you can run: pkg-config --modversion libxdp

Quoted 3 lines

[1]https://github.com/libbpf/libbpf/commit/277846bc6c15

Applied to dpdk-next-net/main, thanks.