From 4d43b29e7d6c783cac9c3af4723f87a6c0ec141f Mon Sep 17 00:00:00 2001 From: wangqiang Date: Thu, 12 Sep 2024 16:30:49 +0800 Subject: [PATCH] Enable check and disable partial usecases of shmoverride_linked_static --- ...secases_of_shmoverride_linked_static.patch | 32 ++++++++++++++ ....16-remap_segments_with_MAP_SHARED-2.patch | 42 ------------------- ...-2.16-remap_segments_with_MAP_SHARED.patch | 31 -------------- ...fix-max-segment-cannot-adopt-the-x86.patch | 23 ---------- libhugetlbfs.spec | 14 ++++--- 5 files changed, 41 insertions(+), 101 deletions(-) create mode 100644 backport-disable_partial_usecases_of_shmoverride_linked_static.patch delete mode 100644 libhugetlbfs-2.16-remap_segments_with_MAP_SHARED-2.patch delete mode 100644 libhugetlbfs-2.16-remap_segments_with_MAP_SHARED.patch delete mode 100644 libhugetlbfs-fix-max-segment-cannot-adopt-the-x86.patch diff --git a/backport-disable_partial_usecases_of_shmoverride_linked_static.patch b/backport-disable_partial_usecases_of_shmoverride_linked_static.patch new file mode 100644 index 0000000..6115b4d --- /dev/null +++ b/backport-disable_partial_usecases_of_shmoverride_linked_static.patch @@ -0,0 +1,32 @@ +From 2cefe6bf1fe99370de2a2d07b463887a5fa0a5de Mon Sep 17 00:00:00 2001 +From: Chunsheng Luo +Date: Mon, 4 Mar 2024 20:53:12 +0800 +Subject: [PATCH] test: disable partial usecases of shmoverride_linked_static + +Since we use dlsym to hijack shmget, we can't use -static when +using shm huge, as it will cause an error: "ERROR: RTLD_NEXT +used in code not dynamically loaded." + +Signed-off-by: Chunsheng Luo +--- + tests/run_tests.py | 7 +++++-- + 1 file changed, 5 insertions(+), 2 deletions(-) + +diff --git a/tests/run_tests.py b/tests/run_tests.py +index c7ca0c1..4793262 100755 +--- a/tests/run_tests.py ++++ b/tests/run_tests.py +@@ -732,8 +732,11 @@ def functional_tests(): + # Test overriding of shmget() + do_shm_test("shmoverride_linked") + do_shm_test("shmoverride_linked", HUGETLB_SHM="yes") +- do_shm_test("shmoverride_linked_static") +- do_shm_test("shmoverride_linked_static", HUGETLB_SHM="yes") ++ ++ #Since we use dlsym to hijack shmget, we can't use -static when using shm huge, ++ #as it will cause an error: 'ERROR: RTLD_NEXT used in code not dynamically loaded. ++ #do_shm_test("shmoverride_linked_static") ++ #do_shm_test("shmoverride_linked_static", HUGETLB_SHM="yes") + do_shm_test("shmoverride_unlinked", LD_PRELOAD="libhugetlbfs.so") + do_shm_test("shmoverride_unlinked", LD_PRELOAD="libhugetlbfs.so", HUGETLB_SHM="yes") + diff --git a/libhugetlbfs-2.16-remap_segments_with_MAP_SHARED-2.patch b/libhugetlbfs-2.16-remap_segments_with_MAP_SHARED-2.patch deleted file mode 100644 index 625296a..0000000 --- a/libhugetlbfs-2.16-remap_segments_with_MAP_SHARED-2.patch +++ /dev/null @@ -1,42 +0,0 @@ -diff -Naur libhugetlbfs-2.16/elflink.c libhugetlbfs-2.16.new//elflink.c ---- libhugetlbfs-2.16/elflink.c 2017-11-09 20:30:38.000000000 -0500 -+++ libhugetlbfs-2.16.new//elflink.c 2017-11-09 22:36:56.000000000 -0500 -@@ -1131,7 +1131,10 @@ - start = ALIGN_DOWN((unsigned long)seg[i].vaddr, hpage_size); - offset = (unsigned long)(seg[i].vaddr - start); - mapsize = ALIGN(offset + seg[i].memsz, hpage_size); -- mmap_flags = MAP_SHARED|MAP_FIXED; -+ if(__hugetlb_opts.share_mapping) -+ mmap_flags = MAP_SHARED|MAP_FIXED; -+ else -+ mmap_flags = MAP_PRIVATE|MAP_FIXED; - - /* If requested, make no reservations */ - if (__hugetlb_opts.no_reserve) -diff -Naur libhugetlbfs-2.16/hugeutils.c libhugetlbfs-2.16.new//hugeutils.c ---- libhugetlbfs-2.16/hugeutils.c 2013-03-09 21:59:52.000000000 -0500 -+++ libhugetlbfs-2.16.new//hugeutils.c 2017-11-09 22:36:45.000000000 -0500 -@@ -387,6 +387,12 @@ - env = getenv("HUGETLB_NO_RESERVE"); - if (env && !strcasecmp(env, "yes")) - __hugetlb_opts.no_reserve = true; -+ -+ /* Determine if data segment share memory mapping */ -+ __hugetlb_opts.share_mapping = false; -+ env = getenv("HUGETLB_SHAREMAPPING"); -+ if (env && !strcasecmp(env, "yes")) -+ __hugetlb_opts.share_mapping = true; - } - - void hugetlbfs_setup_kernel_page_size() -diff -Naur libhugetlbfs-2.16/libhugetlbfs_internal.h libhugetlbfs-2.16.new//libhugetlbfs_internal.h ---- libhugetlbfs-2.16/libhugetlbfs_internal.h 2013-03-09 21:59:52.000000000 -0500 -+++ libhugetlbfs-2.16.new//libhugetlbfs_internal.h 2017-11-09 22:35:53.000000000 -0500 -@@ -73,6 +73,7 @@ - char *def_page_size; - char *morecore; - char *heapbase; -+ bool share_mapping; - }; - - /* diff --git a/libhugetlbfs-2.16-remap_segments_with_MAP_SHARED.patch b/libhugetlbfs-2.16-remap_segments_with_MAP_SHARED.patch deleted file mode 100644 index 0bee1e7..0000000 --- a/libhugetlbfs-2.16-remap_segments_with_MAP_SHARED.patch +++ /dev/null @@ -1,31 +0,0 @@ -From 7c371e7de53554166711e0bcc37df94d0a78edd3 Mon Sep 17 00:00:00 2001 -From: sangyan -Date: Fri, 21 Apr 2017 14:35:03 +0800 -Subject: [PATCH] elflink.c: remap segments with MAP_SHARED flag - -Mmapping segment with MAP_PRIVATE will create a private -copy-on-write mapping, as a result updates to the mapping -will cost extra pages. It will cost double number of pages -in the worst case, so we change to MAP_SHARED flag. - -It is also safe to mmap a unlinked file or a read-only file. ---- - elflink.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/elflink.c b/elflink.c -index b746b26..8187ee0 100644 ---- a/elflink.c -+++ b/elflink.c -@@ -1131,7 +1131,7 @@ static void remap_segments(struct seg_info *seg, int num) - start = ALIGN_DOWN((unsigned long)seg[i].vaddr, hpage_size); - offset = (unsigned long)(seg[i].vaddr - start); - mapsize = ALIGN(offset + seg[i].memsz, hpage_size); -- mmap_flags = MAP_PRIVATE|MAP_FIXED; -+ mmap_flags = MAP_SHARED|MAP_FIXED; - - /* If requested, make no reservations */ - if (__hugetlb_opts.no_reserve) --- -1.8.3.1 - diff --git a/libhugetlbfs-fix-max-segment-cannot-adopt-the-x86.patch b/libhugetlbfs-fix-max-segment-cannot-adopt-the-x86.patch deleted file mode 100644 index 82dcb0c..0000000 --- a/libhugetlbfs-fix-max-segment-cannot-adopt-the-x86.patch +++ /dev/null @@ -1,23 +0,0 @@ -From 09972e4b31efed122c8747c2840bea4fa6615c6c Mon Sep 17 00:00:00 2001 -From: wuxu -Date: Sun, 9 Aug 2020 15:54:55 +0000 -Subject: [PATCH] libhugetlbfs: fix max segment cannot adopt the x86 - -Signed-off-by: wuxu - -diff --git a/elflink.c b/elflink.c -index 2e71522..0f3c228 100644 ---- a/elflink.c -+++ b/elflink.c -@@ -158,7 +158,7 @@ static void unmapped_abort(const char *fmt, ...) - /* The directory to use for sharing readonly segments */ - static char share_readonly_path[PATH_MAX+1]; - --#define MAX_HTLB_SEGS 3 -+#define MAX_HTLB_SEGS 4 - #define MAX_SEGS 10 - - struct seg_info { --- -1.8.3.1 - diff --git a/libhugetlbfs.spec b/libhugetlbfs.spec index 4f033f0..0404e36 100644 --- a/libhugetlbfs.spec +++ b/libhugetlbfs.spec @@ -2,7 +2,7 @@ Name: libhugetlbfs Version: 2.23 -Release: 4 +Release: 5 Summary: A library which provides easy access to huge pages of memory License: LGPLv2+ URL: https://github.com/libhugetlbfs/libhugetlbfs @@ -13,10 +13,8 @@ Patch1: Disable-hugepage-backed-malloc-if-__morecore-is-not-.patch Patch2: libhugetlbfs-2.23-sw.patch Patch3: add-loongarch-support.patch -#Patch9000:libhugetlbfs-2.16-remap_segments_with_MAP_SHARED.patch -#Patch9001:libhugetlbfs-2.16-remap_segments_with_MAP_SHARED-2.patch -Patch9002:libhugetlbfs-make-cflags.patch -#Patch9003:libhugetlbfs-fix-max-segment-cannot-adopt-the-x86.patch +Patch9002: libhugetlbfs-make-cflags.patch +Patch9003: backport-disable_partial_usecases_of_shmoverride_linked_static.patch BuildRequires: gcc glibc-devel glibc-static @@ -47,6 +45,9 @@ Userspace utilities for configuring the hugepage environment %set_build_flags make BUILDTYPE=NATIVEONLY +%check +make BUILDTYPE=NATIVEONLY check + %install %make_install PREFIX=%{_prefix} LDSCRIPTDIR=%{ldscriptdir} BUILDTYPE=NATIVEONLY make install-helper PREFIX=%{_prefix} DESTDIR=$RPM_BUILD_ROOT LDSCRIPTDIR=%{ldscriptdir} BUILDTYPE=NATIVEONLY @@ -88,6 +89,9 @@ touch $RPM_BUILD_ROOT%{_sysconfdir}/security/limits.d/hugepages.conf %changelog +* Thu Sep 12 2024 wangqiang - 2.23-5 +- Enable check and disable partial usecases of shmoverride_linked_static + * Mon May 6 2024 yueyaoqiang - 2.23-4 - add libhugetlbfs_privutils.so for libhugetlbfs test -- Gitee