shmget02: check if CONFIG_HUGETLBFS enabled in kernel
PATCH 1/1 shmget02: check if CONFIG_HUGETLBFS enabled in kernel
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.
--- .../kernel/syscalls/ipc/shmget/shmget02.c | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+)
testcases/kernel/syscalls/ipc/shmget/shmget02.c +21 -0
@@ -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,11 +63,29 @@ static struct tcase { {&shmkey1, SHM_SIZE, IPC_CREAT | SHM_HUGETLB, 0, 0, ENOMEM} }; +inline static int hugetlbfs_enabled () +{ +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];pid_t pid; +if (((tc->flags &SHM_HUGETLB ) ==SHM_HUGETLB ) && !hugetlbfs_enabled ()) + { +tst_brk (TCONF , +"Unsuitable kernel config: CONFIG_HUGETLBFS missing" ); +return ; + } +if (tc->exp_user ==0 && tc->exp_group ==0 ) {TST_EXP_FAIL2 (shmget (*tc->shmkey, tc->size, tc->flags), tc->exp_err,"shmget(%i, %lu, %i)" , *tc->shmkey, tc->size, tc->flags);
Signature · 1 line
2.32.0
PATCH 1/1 shmget02: check if CONFIG_HUGETLBFS enabled in kernel
Hi!
Quoted 44 lines
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 <[email protected]>--- .../kernel/syscalls/ipc/shmget/shmget02.c | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+)testcases/kernel/syscalls/ipc/shmget/shmget02.c +14
-0@@ -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,11 +63,29 @@ static struct tcase { {&shmkey1, SHM_SIZE, IPC_CREAT | SHM_HUGETLB, 0, 0, ENOMEM} }; +inline static int hugetlbfs_enabled () +{ +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)
testcases/kernel/syscalls/ipc/shmget/shmget02.c static struct tcase { · line 87
Quoted 10 lines
testcases/kernel/syscalls/ipc/shmget/shmget02.c +6
-0{struct tcase *tc = &tcases[n];pid_t pid; +if (((tc->flags &SHM_HUGETLB ) ==SHM_HUGETLB ) && !hugetlbfs_enabled ()) + { +tst_brk (TCONF , +"Unsuitable kernel config: CONFIG_HUGETLBFS missing" ); +return ; + }
We whould really update the tcases array in the setup instead as this will re-read the whole kernel config on each do_test() iteration.
Something as:
static void setup(void)
{
...
if (!hugetlb_supported()) {
tst_res(TINFO, "SHM_HUGETLB not supported by kernel");
for (i = 0; i < ARRAY_SIZE(tcases); i++) {
if (tcases[i].flags & SHM_HUGETLB)
tcases[i].exp_err = EINVAL;
}
}
...
}Quoted 9 lines
testcases/kernel/syscalls/ipc/shmget/shmget02.c +0
-0if (tc->exp_user ==0 && tc->exp_group ==0 ) {TST_EXP_FAIL2 (shmget (*tc->shmkey, tc->size, tc->flags), tc->exp_err,"shmget(%i, %lu, %i)" , *tc->shmkey, tc->size, tc->flags);Signature · 5 lines
2.32.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 1/1 shmget02: check if CONFIG_HUGETLBFS enabled in kernel
Hello Cyril,
Thanks a lot for reviewing.
I agree that reading kconfig every time is not fun. But would it be better to read it once into global variable? My concern is that your solution implicitly changes expected values that might confuse people who occasionally don't look at the bottom of program.
How about:
inline void _hugetlbfs_supported()
{
struct tst_kconfig_var kconfig = {
.id = CONFIG_HUGETLBFS,
.id_len = sizeof(CONFIG_HUGETLBFS)-1,
};
tst_kconfig_read(&kconfig, 1);hugetlbfs_supported = kconfig.choice == 'y';
}
....
static void do_test(unsigned int n)
{
struct tcase *tc = &tcases[n];pid_t pid;
if (((tc->flags & SHM_HUGETLB) == SHM_HUGETLB) && ! hugetlbfs_supported) {
tst_brk(TCONF,
"Unsuitable kernel config: CONFIG_HUGETLBFS missing");
}
....
---
Thanks,
Bogdan Lezhepekov, SUSE
________________________________
From: Cyril Hrubis <[email protected]>
Sent: Monday, August 2, 2021 17:42
To: Bogdan Lezhepekov <[email protected]>
Cc: [email protected] <[email protected]>
Subject: Re: [LTP] [PATCH v1] shmget02: check if CONFIG_HUGETLBFS enabled in kernel
Hi!
Quoted 44 lines
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 <[email protected]>--- .../kernel/syscalls/ipc/shmget/shmget02.c | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+)testcases/kernel/syscalls/ipc/shmget/shmget02.c +14
-0@@ -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,11 +63,29 @@ static struct tcase { {&shmkey1, SHM_SIZE, IPC_CREAT | SHM_HUGETLB, 0, 0, ENOMEM} }; +inline static int hugetlbfs_enabled () +{ +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)
testcases/kernel/syscalls/ipc/shmget/shmget02.c static struct tcase { · line 87
Quoted 10 lines
testcases/kernel/syscalls/ipc/shmget/shmget02.c +6
-0{struct tcase *tc = &tcases[n];pid_t pid; +if (((tc->flags &SHM_HUGETLB ) ==SHM_HUGETLB ) && !hugetlbfs_enabled ()) + { +tst_brk (TCONF , +"Unsuitable kernel config: CONFIG_HUGETLBFS missing" ); +return ; + }
We whould really update the tcases array in the setup instead as this will re-read the whole kernel config on each do_test() iteration.
Something as:
static void setup(void)
{
...
if (!hugetlb_supported()) {
tst_res(TINFO, "SHM_HUGETLB not supported by kernel");
for (i = 0; i < ARRAY_SIZE(tcases); i++) {
if (tcases[i].flags & SHM_HUGETLB)
tcases[i].exp_err = EINVAL;
}
}
...
}Quoted 9 lines
testcases/kernel/syscalls/ipc/shmget/shmget02.c +0
-1if (tc->exp_user ==0 && tc->exp_group ==0 ) {TST_EXP_FAIL2 (shmget (*tc->shmkey, tc->size, tc->flags), tc->exp_err,"shmget(%i, %lu, %i)" , *tc->shmkey, tc->size, tc->flags); --2.32.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
--
Cyril Hrubis
[email protected]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20210802/052d3e18/attachment-0001.htm>
PATCH 1/1 shmget02: check if CONFIG_HUGETLBFS enabled in kernel
Hi!
Quoted 23 lines
Thanks a lot for reviewing.
I agree that reading kconfig every time is not fun. But would it be better to read it once into global variable? My concern is that your solution implicitly changes expected values that might confuse people who occasionally don't look at the bottom of program.
How about:
inline void
_hugetlbfs_supported()
{
structtst_kconfig_varkconfig = {
.id =CONFIG_HUGETLBFS,
.id_len = sizeof(CONFIG_HUGETLBFS)-1,
};
tst_kconfig_read(&kconfig, 1);hugetlbfs_supported= kconfig.choice == 'y';
}
....static void
do_test(unsigned int n)
{
struct tcase *tc = &tcases[n];pid_tpid;
Quoted 6 lines
if (((
tc->flags&SHM_HUGETLB) ==SHM_HUGETLB) && !hugetlbfs_supported) {
tst_brk(TCONF,
"Unsuitable kernel config:CONFIG_HUGETLBFSmissing");
}
....
This does not check that we get a proper error when SHM_HUGETLB is not supported by the kernel though, which is something that should be checked as well.
Signature · 2 lines
Cyril Hrubis [email protected]