All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH v3] shmget02: check if CONFIG_HUGETLBFS enabled in kernel
@ 2021-08-04  9:39 Bogdan Lezhepekov
  2021-08-04 14:39 ` Cyril Hrubis
  0 siblings, 1 reply; 3+ messages in thread
From: Bogdan Lezhepekov @ 2021-08-04  9:39 UTC (permalink / raw)
  To: ltp

Two tests call shmget with a flag SHM_HUGETLB, trying to
allocate the segment using "huge" pages. The hugetlbpage
support needs to be enabled in kernel (CONFIG_HUGETLBFS),
otherwise shmget returns EINVAL.

Signed-off-by: Bogdan Lezhepekov <bogdan.lezhepekov@suse.com>
---
 .../kernel/syscalls/ipc/shmget/shmget02.c     | 24 +++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/testcases/kernel/syscalls/ipc/shmget/shmget02.c b/testcases/kernel/syscalls/ipc/shmget/shmget02.c
index 66a4b94ee..7616178be 100644
--- a/testcases/kernel/syscalls/ipc/shmget/shmget02.c
+++ b/testcases/kernel/syscalls/ipc/shmget/shmget02.c
@@ -32,10 +32,13 @@
 #include <sys/shm.h>
 #include <grp.h>
 #include "tst_safe_sysv_ipc.h"
+#include "tst_kconfig.h"
 #include "tst_test.h"
 #include "libnewipc.h"
 #include "lapi/shm.h"
 
+#define CONFIG_HUGETLBFS "CONFIG_HUGETLBFS"
+
 static int shm_id = -1;
 static key_t shmkey, shmkey1;
 static struct passwd *pw;
@@ -60,6 +63,17 @@ static struct tcase {
 	{&shmkey1, SHM_SIZE, IPC_CREAT | SHM_HUGETLB, 0, 0, ENOMEM}
 };
 
+static int hugetlbfs_supported(void)
+{
+	struct tst_kconfig_var kconfig = {
+		.id = CONFIG_HUGETLBFS,
+		.id_len = sizeof(CONFIG_HUGETLBFS)-1,
+	};
+
+	tst_kconfig_read(&kconfig, 1);
+	return kconfig.choice == 'y';
+}
+
 static void do_test(unsigned int n)
 {
 	struct tcase *tc = &tcases[n];
@@ -94,6 +108,16 @@ static void setup(void)
 	SAFE_SETRLIMIT(RLIMIT_MEMLOCK, &rl);
 	shm_id = SAFE_SHMGET(shmkey, SHM_SIZE, IPC_CREAT | IPC_EXCL);
 	pw = SAFE_GETPWNAM("nobody");
+
+	if (!hugetlbfs_supported()) {
+
+		tst_res(TINFO, "SHM_HUGETLB not supported by kernel");
+
+		for (int i = 0; i < ARRAY_SIZE(tcases); i++) {
+			if (tcases[i].flags & SHM_HUGETLB)
+				tcases[i].exp_err = EINVAL;
+		}
+	}
 }
 
 static void cleanup(void)
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [LTP] [PATCH v3] shmget02: check if CONFIG_HUGETLBFS enabled in kernel
  2021-08-04  9:39 [LTP] [PATCH v3] shmget02: check if CONFIG_HUGETLBFS enabled in kernel Bogdan Lezhepekov
@ 2021-08-04 14:39 ` Cyril Hrubis
  2021-08-04 15:24   ` Bogdan Lezhepekov
  0 siblings, 1 reply; 3+ messages in thread
From: Cyril Hrubis @ 2021-08-04 14:39 UTC (permalink / raw)
  To: ltp

Hi!
Pushed with a minor change, thanks.

The inline variable definition is valid on in C99 and we still have to
support old distributions that compile LTP with GNU89 which does not
allow it. I've also changed the type to unsigned in order to avoid a
warning.

Full diff:

diff --git a/testcases/kernel/syscalls/ipc/shmget/shmget02.c b/testcases/kernel/syscalls/ipc/shmget/shmget02.c
index 7856c2b8e..effd33799 100644
--- a/testcases/kernel/syscalls/ipc/shmget/shmget02.c
+++ b/testcases/kernel/syscalls/ipc/shmget/shmget02.c
@@ -110,10 +110,11 @@ static void setup(void)
 	pw = SAFE_GETPWNAM("nobody");
 
 	if (!hugetlbfs_supported()) {
+		unsigned int i;
 
 		tst_res(TINFO, "SHM_HUGETLB not supported by kernel");
 
-		for (int i = 0; i < ARRAY_SIZE(tcases); i++) {
+		for (i = 0; i < ARRAY_SIZE(tcases); i++) {
 			if (tcases[i].flags & SHM_HUGETLB)
 				tcases[i].exp_err = EINVAL;
 		}

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [LTP] [PATCH v3] shmget02: check if CONFIG_HUGETLBFS enabled in kernel
  2021-08-04 14:39 ` Cyril Hrubis
@ 2021-08-04 15:24   ` Bogdan Lezhepekov
  0 siblings, 0 replies; 3+ messages in thread
From: Bogdan Lezhepekov @ 2021-08-04 15:24 UTC (permalink / raw)
  To: ltp

Hi Cyril,

Taken a note for future, thanks!

-Bogdan
________________________________
From: Cyril Hrubis <chrubis@suse.cz>
Sent: Wednesday, August 4, 2021 17:39
To: Bogdan Lezhepekov <bogdan.lezhepekov@suse.com>
Cc: ltp@lists.linux.it <ltp@lists.linux.it>
Subject: Re: [LTP] [PATCH v3] shmget02: check if CONFIG_HUGETLBFS enabled in kernel

Hi!
Pushed with a minor change, thanks.

The inline variable definition is valid on in C99 and we still have to
support old distributions that compile LTP with GNU89 which does not
allow it. I've also changed the type to unsigned in order to avoid a
warning.

Full diff:

diff --git a/testcases/kernel/syscalls/ipc/shmget/shmget02.c b/testcases/kernel/syscalls/ipc/shmget/shmget02.c
index 7856c2b8e..effd33799 100644
--- a/testcases/kernel/syscalls/ipc/shmget/shmget02.c
+++ b/testcases/kernel/syscalls/ipc/shmget/shmget02.c
@@ -110,10 +110,11 @@ static void setup(void)
         pw = SAFE_GETPWNAM("nobody");

         if (!hugetlbfs_supported()) {
+               unsigned int i;

                 tst_res(TINFO, "SHM_HUGETLB not supported by kernel");

-               for (int i = 0; i < ARRAY_SIZE(tcases); i++) {
+               for (i = 0; i < ARRAY_SIZE(tcases); i++) {
                         if (tcases[i].flags & SHM_HUGETLB)
                                 tcases[i].exp_err = EINVAL;
                 }

--
Cyril Hrubis
chrubis@suse.cz

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20210804/d934f373/attachment.htm>

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-08-04 15:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-04  9:39 [LTP] [PATCH v3] shmget02: check if CONFIG_HUGETLBFS enabled in kernel Bogdan Lezhepekov
2021-08-04 14:39 ` Cyril Hrubis
2021-08-04 15:24   ` Bogdan Lezhepekov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.