* [PATCH 25.11 0/3] remove fallbacks for old Linux versions
@ 2025-06-30 13:29 Bruce Richardson
2025-06-30 13:29 ` [PATCH 25.11 1/3] eal/linux: " Bruce Richardson
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Bruce Richardson @ 2025-06-30 13:29 UTC (permalink / raw)
To: dev; +Cc: Bruce Richardson
We no longer support versions of linux before 4.19[1], therefore
all supported linux versions support F_ADD_SEALS (Linux 3.17+) and
MFD_HUGETLB (Linux 4.14+), so no need to have #ifdefs and fallbacks to
support systems which do not support those features.
[1] https://doc.dpdk.org/guides/linux_gsg/sys_reqs.html#system-software
Bruce Richardson (3):
eal/linux: remove fallbacks for old Linux versions
vhost: : remove fallbacks for old Linux versions
memif: : remove fallbacks for old Linux versions
drivers/net/memif/rte_eth_memif.h | 41 -------
lib/eal/linux/eal_memalloc.c | 174 +++++-------------------------
lib/eal/linux/eal_memory.c | 7 --
lib/vhost/vhost_user.c | 7 --
4 files changed, 24 insertions(+), 205 deletions(-)
--
2.48.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 25.11 1/3] eal/linux: remove fallbacks for old Linux versions
2025-06-30 13:29 [PATCH 25.11 0/3] remove fallbacks for old Linux versions Bruce Richardson
@ 2025-06-30 13:29 ` Bruce Richardson
2025-06-30 13:29 ` [PATCH 25.11 2/3] vhost: : " Bruce Richardson
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Bruce Richardson @ 2025-06-30 13:29 UTC (permalink / raw)
To: dev; +Cc: Bruce Richardson, Anatoly Burakov
All supported linux versions support F_ADD_SEALS (Linux 3.17+) and
MFD_HUGETLB (Linux 4.14+), so no need to have #ifdefs and fallbacks to
support systems which do not support those features.
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
lib/eal/linux/eal_memalloc.c | 174 +++++------------------------------
lib/eal/linux/eal_memory.c | 7 --
2 files changed, 24 insertions(+), 157 deletions(-)
diff --git a/lib/eal/linux/eal_memalloc.c b/lib/eal/linux/eal_memalloc.c
index e354efc95d..1e60e21620 100644
--- a/lib/eal/linux/eal_memalloc.c
+++ b/lib/eal/linux/eal_memalloc.c
@@ -16,10 +16,7 @@
#include <fcntl.h>
#include <signal.h>
#include <setjmp.h>
-#ifdef F_ADD_SEALS /* if file sealing is supported, so is memfd */
#include <linux/memfd.h>
-#define MEMFD_SUPPORTED
-#endif
#ifdef RTE_EAL_NUMA_AWARE_HUGEPAGES
#include <numa.h>
#include <numaif.h>
@@ -47,24 +44,6 @@ const int anonymous_hugepages_supported =
#define RTE_MAP_HUGE_SHIFT 26
#endif
-/*
- * we've already checked memfd support at compile-time, but we also need to
- * check if we can create hugepage files with memfd.
- *
- * also, this is not a constant, because while we may be *compiled* with memfd
- * hugetlbfs support, we might not be *running* on a system that supports memfd
- * and/or memfd with hugetlbfs, so we need to be able to adjust this flag at
- * runtime, and fall back to anonymous memory.
- */
-static int memfd_create_supported =
-#ifdef MFD_HUGETLB
- 1;
-#define RTE_MFD_HUGETLB MFD_HUGETLB
-#else
- 0;
-#define RTE_MFD_HUGETLB 4U
-#endif
-
/*
* not all kernel version support fallocate on hugetlbfs, so fall back to
* ftruncate and disallow deallocation if fallocate is not supported.
@@ -236,11 +215,10 @@ get_seg_memfd(struct hugepage_info *hi __rte_unused,
unsigned int list_idx __rte_unused,
unsigned int seg_idx __rte_unused)
{
-#ifdef MEMFD_SUPPORTED
int fd;
char segname[250]; /* as per manpage, limit is 249 bytes plus null */
- int flags = RTE_MFD_HUGETLB | pagesz_flags(hi->hugepage_sz);
+ int flags = MFD_HUGETLB | pagesz_flags(hi->hugepage_sz);
const struct internal_config *internal_conf =
eal_get_internal_configuration();
@@ -273,8 +251,6 @@ get_seg_memfd(struct hugepage_info *hi __rte_unused,
}
}
return fd;
-#endif
- return -1;
}
static int
@@ -539,66 +515,40 @@ alloc_seg(struct rte_memseg *ms, void *addr, int socket_id,
EAL_LOG(ERR, "Anonymous hugepages not supported, in-memory mode cannot allocate memory");
return -1;
}
- if (internal_conf->in_memory && !memfd_create_supported &&
- internal_conf->single_file_segments) {
- EAL_LOG(ERR, "Single-file segments are not supported without memfd support");
- return -1;
- }
- /* in-memory without memfd is a special case */
+ /* use memfd for in-memory mode */
int mmap_flags;
- if (internal_conf->in_memory && !memfd_create_supported) {
- const int in_memory_flags = MAP_HUGETLB | MAP_FIXED |
- MAP_PRIVATE | MAP_ANONYMOUS;
- int pagesz_flag;
+ /* takes out a read lock on segment or segment list */
+ fd = get_seg_fd(path, sizeof(path), hi, list_idx, seg_idx, &dirty);
+ if (fd < 0) {
+ EAL_LOG(ERR, "Couldn't get fd on hugepage file");
+ return -1;
+ }
- pagesz_flag = pagesz_flags(alloc_sz);
- fd = -1;
- dirty = false;
- mmap_flags = in_memory_flags | pagesz_flag;
+ if (internal_conf->single_file_segments) {
+ map_offset = seg_idx * alloc_sz;
+ ret = resize_hugefile(fd, map_offset, alloc_sz, true, &dirty);
+ if (ret < 0)
+ goto resized;
- /* single-file segments codepath will never be active
- * here because in-memory mode is incompatible with the
- * fallback path, and it's stopped at EAL initialization
- * stage.
- */
- map_offset = 0;
+ fd_list[list_idx].count++;
} else {
- /* takes out a read lock on segment or segment list */
- fd = get_seg_fd(path, sizeof(path), hi, list_idx, seg_idx,
- &dirty);
- if (fd < 0) {
- EAL_LOG(ERR, "Couldn't get fd on hugepage file");
- return -1;
+ map_offset = 0;
+ if (ftruncate(fd, alloc_sz) < 0) {
+ EAL_LOG(DEBUG, "%s(): ftruncate() failed: %s", __func__, strerror(errno));
+ goto resized;
}
-
- if (internal_conf->single_file_segments) {
- map_offset = seg_idx * alloc_sz;
- ret = resize_hugefile(fd, map_offset, alloc_sz, true,
- &dirty);
- if (ret < 0)
- goto resized;
-
- fd_list[list_idx].count++;
- } else {
- map_offset = 0;
- if (ftruncate(fd, alloc_sz) < 0) {
- EAL_LOG(DEBUG, "%s(): ftruncate() failed: %s",
+ if (internal_conf->hugepage_file.unlink_before_mapping &&
+ !internal_conf->in_memory) {
+ if (unlink(path)) {
+ EAL_LOG(DEBUG, "%s(): unlink() failed: %s",
__func__, strerror(errno));
goto resized;
}
- if (internal_conf->hugepage_file.unlink_before_mapping &&
- !internal_conf->in_memory) {
- if (unlink(path)) {
- EAL_LOG(DEBUG, "%s(): unlink() failed: %s",
- __func__, strerror(errno));
- goto resized;
- }
- }
}
- mmap_flags = MAP_SHARED | MAP_POPULATE | MAP_FIXED;
}
+ mmap_flags = MAP_SHARED | MAP_POPULATE | MAP_FIXED;
huge_register_sigbus();
@@ -754,12 +704,6 @@ free_seg(struct rte_memseg *ms, struct hugepage_info *hi,
eal_mem_set_dump(ms->addr, ms->len, false);
- /* if we're using anonymous hugepages, nothing to be done */
- if (internal_conf->in_memory && !memfd_create_supported) {
- memset(ms, 0, sizeof(*ms));
- return 0;
- }
-
/* if we are not in single file segments mode, we're going to unmap the
* segment and thus drop the lock on original fd, but hugepage dir is
* now locked so we can take out another one without races.
@@ -1624,16 +1568,6 @@ eal_memalloc_get_seg_fd(int list_idx, int seg_idx)
const struct internal_config *internal_conf =
eal_get_internal_configuration();
- if (internal_conf->in_memory || internal_conf->no_hugetlbfs) {
-#ifndef MEMFD_SUPPORTED
- /* in in-memory or no-huge mode, we rely on memfd support */
- return -ENOTSUP;
-#endif
- /* memfd supported, but hugetlbfs memfd may not be */
- if (!internal_conf->no_hugetlbfs && !memfd_create_supported)
- return -ENOTSUP;
- }
-
if (internal_conf->single_file_segments) {
fd = fd_list[list_idx].memseg_list_fd;
} else if (fd_list[list_idx].len == 0) {
@@ -1647,37 +1581,6 @@ eal_memalloc_get_seg_fd(int list_idx, int seg_idx)
return fd;
}
-static int
-test_memfd_create(void)
-{
-#ifdef MEMFD_SUPPORTED
- const struct internal_config *internal_conf =
- eal_get_internal_configuration();
- unsigned int i;
- for (i = 0; i < internal_conf->num_hugepage_sizes; i++) {
- uint64_t pagesz = internal_conf->hugepage_info[i].hugepage_sz;
- int pagesz_flag = pagesz_flags(pagesz);
- int flags;
-
- flags = pagesz_flag | RTE_MFD_HUGETLB;
- int fd = memfd_create("test", flags);
- if (fd < 0) {
- /* we failed - let memalloc know this isn't working */
- if (errno == EINVAL) {
- memfd_create_supported = 0;
- return 0; /* not supported */
- }
-
- /* we got other error - something's wrong */
- return -1; /* error */
- }
- close(fd);
- return 1; /* supported */
- }
-#endif
- return 0; /* not supported */
-}
-
int
eal_memalloc_get_seg_fd_offset(int list_idx, int seg_idx, size_t *offset)
{
@@ -1685,16 +1588,6 @@ eal_memalloc_get_seg_fd_offset(int list_idx, int seg_idx, size_t *offset)
const struct internal_config *internal_conf =
eal_get_internal_configuration();
- if (internal_conf->in_memory || internal_conf->no_hugetlbfs) {
-#ifndef MEMFD_SUPPORTED
- /* in in-memory or no-huge mode, we rely on memfd support */
- return -ENOTSUP;
-#endif
- /* memfd supported, but hugetlbfs memfd may not be */
- if (!internal_conf->no_hugetlbfs && !memfd_create_supported)
- return -ENOTSUP;
- }
-
if (internal_conf->single_file_segments) {
size_t pgsz = mcfg->memsegs[list_idx].page_sz;
@@ -1747,26 +1640,7 @@ eal_memalloc_init(void)
return -1;
if (rte_eal_process_type() == RTE_PROC_PRIMARY &&
internal_conf->in_memory) {
- int mfd_res = test_memfd_create();
-
- if (mfd_res < 0) {
- EAL_LOG(ERR, "Unable to check if memfd is supported");
- return -1;
- }
- if (mfd_res == 1)
- EAL_LOG(DEBUG, "Using memfd for anonymous memory");
- else
- EAL_LOG(INFO, "Using memfd is not supported, falling back to anonymous hugepages");
-
- /* we only support single-file segments mode with in-memory mode
- * if we support hugetlbfs with memfd_create. this code will
- * test if we do.
- */
- if (internal_conf->single_file_segments &&
- mfd_res != 1) {
- EAL_LOG(ERR, "Single-file segments mode cannot be used without memfd support");
- return -1;
- }
+ EAL_LOG(DEBUG, "Using memfd for anonymous memory");
/* this cannot ever happen but better safe than sorry */
if (!anonymous_hugepages_supported) {
EAL_LOG(ERR, "Using anonymous memory is not supported");
diff --git a/lib/eal/linux/eal_memory.c b/lib/eal/linux/eal_memory.c
index e433c1afee..ee964446c7 100644
--- a/lib/eal/linux/eal_memory.c
+++ b/lib/eal/linux/eal_memory.c
@@ -20,9 +20,6 @@
#include <limits.h>
#include <signal.h>
#include <setjmp.h>
-#ifdef F_ADD_SEALS /* if file sealing is supported, so is memfd */
-#define MEMFD_SUPPORTED
-#endif
#ifdef RTE_EAL_NUMA_AWARE_HUGEPAGES
#include <numa.h>
#include <numaif.h>
@@ -1161,9 +1158,7 @@ eal_legacy_hugepage_init(void)
size_t mem_sz;
struct rte_memseg_list *msl;
int n_segs, fd, flags;
-#ifdef MEMFD_SUPPORTED
int memfd;
-#endif
uint64_t page_sz;
/* nohuge mode is legacy mode */
@@ -1188,7 +1183,6 @@ eal_legacy_hugepage_init(void)
fd = -1;
flags = MAP_PRIVATE | MAP_ANONYMOUS;
-#ifdef MEMFD_SUPPORTED
/* create a memfd and store it in the segment fd table */
memfd = memfd_create("nohuge", 0);
if (memfd < 0) {
@@ -1213,7 +1207,6 @@ eal_legacy_hugepage_init(void)
flags = MAP_SHARED;
}
}
-#endif
/* preallocate address space for the memory, so that it can be
* fit into the DMA mask.
*/
--
2.48.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 25.11 2/3] vhost: : remove fallbacks for old Linux versions
2025-06-30 13:29 [PATCH 25.11 0/3] remove fallbacks for old Linux versions Bruce Richardson
2025-06-30 13:29 ` [PATCH 25.11 1/3] eal/linux: " Bruce Richardson
@ 2025-06-30 13:29 ` Bruce Richardson
2025-06-30 13:29 ` [PATCH 25.11 3/3] memif: " Bruce Richardson
2025-06-30 15:02 ` [PATCH 25.11 0/3] " Stephen Hemminger
3 siblings, 0 replies; 5+ messages in thread
From: Bruce Richardson @ 2025-06-30 13:29 UTC (permalink / raw)
To: dev; +Cc: Bruce Richardson, Maxime Coquelin, Chenbo Xia
All supported linux versions support F_ADD_SEALS (Linux 3.17+) and
MFD_HUGETLB (Linux 4.14+), so no need to have #ifdefs and fallbacks to
support systems which do not support those features.
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
lib/vhost/vhost_user.c | 7 -------
1 file changed, 7 deletions(-)
diff --git a/lib/vhost/vhost_user.c b/lib/vhost/vhost_user.c
index b73dec6a22..4bfb13fb98 100644
--- a/lib/vhost/vhost_user.c
+++ b/lib/vhost/vhost_user.c
@@ -36,10 +36,7 @@
#ifdef RTE_LIBRTE_VHOST_POSTCOPY
#include <linux/userfaultfd.h>
#endif
-#ifdef F_ADD_SEALS /* if file sealing is supported, so is memfd */
#include <linux/memfd.h>
-#define MEMFD_SUPPORTED
-#endif
#include <eal_export.h>
#include <rte_common.h>
@@ -1627,11 +1624,7 @@ inflight_mem_alloc(struct virtio_net *dev, const char *name, size_t size, int *f
char fname[20] = "/tmp/memfd-XXXXXX";
*fd = -1;
-#ifdef MEMFD_SUPPORTED
mfd = memfd_create(name, MFD_CLOEXEC);
-#else
- RTE_SET_USED(name);
-#endif
if (mfd == -1) {
mfd = mkstemp(fname);
if (mfd == -1) {
--
2.48.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 25.11 3/3] memif: : remove fallbacks for old Linux versions
2025-06-30 13:29 [PATCH 25.11 0/3] remove fallbacks for old Linux versions Bruce Richardson
2025-06-30 13:29 ` [PATCH 25.11 1/3] eal/linux: " Bruce Richardson
2025-06-30 13:29 ` [PATCH 25.11 2/3] vhost: : " Bruce Richardson
@ 2025-06-30 13:29 ` Bruce Richardson
2025-06-30 15:02 ` [PATCH 25.11 0/3] " Stephen Hemminger
3 siblings, 0 replies; 5+ messages in thread
From: Bruce Richardson @ 2025-06-30 13:29 UTC (permalink / raw)
To: dev; +Cc: Bruce Richardson, Jakub Grajciar
All supported linux versions support F_ADD_SEALS (Linux 3.17+) and
MFD_HUGETLB (Linux 4.14+), so no need to have #ifdefs and fallbacks to
support systems which do not support those features.
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
drivers/net/memif/rte_eth_memif.h | 41 -------------------------------
1 file changed, 41 deletions(-)
diff --git a/drivers/net/memif/rte_eth_memif.h b/drivers/net/memif/rte_eth_memif.h
index 8e45a3ab78..d4e625ab51 100644
--- a/drivers/net/memif/rte_eth_memif.h
+++ b/drivers/net/memif/rte_eth_memif.h
@@ -169,37 +169,6 @@ int memif_init_regions_and_queues(struct rte_eth_dev *dev);
*/
const char *memif_version(void);
-#ifndef MFD_HUGETLB
-#ifndef __NR_memfd_create
-
-#if defined __x86_64__
-#define __NR_memfd_create 319
-#elif defined __x86_32__
-#define __NR_memfd_create 1073742143
-#elif defined __arm__
-#define __NR_memfd_create 385
-#elif defined __aarch64__
-#define __NR_memfd_create 279
-#elif defined __powerpc__
-#define __NR_memfd_create 360
-#elif defined __i386__
-#define __NR_memfd_create 356
-#elif defined __riscv
-#define __NR_memfd_create 279
-#elif defined __loongarch__
-#define __NR_memfd_create 279
-#else
-#error "__NR_memfd_create unknown for this architecture"
-#endif
-
-#endif /* __NR_memfd_create */
-
-static inline int memfd_create(const char *name, unsigned int flags)
-{
- return syscall(__NR_memfd_create, name, flags);
-}
-#endif /* MFD_HUGETLB */
-
#ifndef F_LINUX_SPECIFIC_BASE
#define F_LINUX_SPECIFIC_BASE 1024
#endif
@@ -208,14 +177,4 @@ static inline int memfd_create(const char *name, unsigned int flags)
#define MFD_ALLOW_SEALING 0x0002U
#endif
-#ifndef F_ADD_SEALS
-#define F_ADD_SEALS (F_LINUX_SPECIFIC_BASE + 9)
-#define F_GET_SEALS (F_LINUX_SPECIFIC_BASE + 10)
-
-#define F_SEAL_SEAL 0x0001 /* prevent further seals from being set */
-#define F_SEAL_SHRINK 0x0002 /* prevent file from shrinking */
-#define F_SEAL_GROW 0x0004 /* prevent file from growing */
-#define F_SEAL_WRITE 0x0008 /* prevent writes */
-#endif
-
#endif /* RTE_ETH_MEMIF_H */
--
2.48.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 25.11 0/3] remove fallbacks for old Linux versions
2025-06-30 13:29 [PATCH 25.11 0/3] remove fallbacks for old Linux versions Bruce Richardson
` (2 preceding siblings ...)
2025-06-30 13:29 ` [PATCH 25.11 3/3] memif: " Bruce Richardson
@ 2025-06-30 15:02 ` Stephen Hemminger
3 siblings, 0 replies; 5+ messages in thread
From: Stephen Hemminger @ 2025-06-30 15:02 UTC (permalink / raw)
To: Bruce Richardson; +Cc: dev
On Mon, 30 Jun 2025 13:29:01 +0000
Bruce Richardson <bruce.richardson@intel.com> wrote:
> We no longer support versions of linux before 4.19[1], therefore
> all supported linux versions support F_ADD_SEALS (Linux 3.17+) and
> MFD_HUGETLB (Linux 4.14+), so no need to have #ifdefs and fallbacks to
> support systems which do not support those features.
>
> [1] https://doc.dpdk.org/guides/linux_gsg/sys_reqs.html#system-software
>
> Bruce Richardson (3):
> eal/linux: remove fallbacks for old Linux versions
> vhost: : remove fallbacks for old Linux versions
> memif: : remove fallbacks for old Linux versions
>
> drivers/net/memif/rte_eth_memif.h | 41 -------
> lib/eal/linux/eal_memalloc.c | 174 +++++-------------------------
> lib/eal/linux/eal_memory.c | 7 --
> lib/vhost/vhost_user.c | 7 --
> 4 files changed, 24 insertions(+), 205 deletions(-)
>
Series-Acked-by: Stephen Hemminger <stephen@networkplumber.org>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-06-30 15:02 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-06-30 13:29 [PATCH 25.11 0/3] remove fallbacks for old Linux versions Bruce Richardson
2025-06-30 13:29 ` [PATCH 25.11 1/3] eal/linux: " Bruce Richardson
2025-06-30 13:29 ` [PATCH 25.11 2/3] vhost: : " Bruce Richardson
2025-06-30 13:29 ` [PATCH 25.11 3/3] memif: " Bruce Richardson
2025-06-30 15:02 ` [PATCH 25.11 0/3] " Stephen Hemminger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).