ltp.lists.linux.it archive mirror
 help / color / mirror / Atom feed
* [LTP] [PATCH v1] madvise11.c:Check loadable module before rmmod
@ 2023-03-10 14:04 Wei Gao via ltp
  2023-03-10 14:52 ` Cyril Hrubis
                   ` (2 more replies)
  0 siblings, 3 replies; 28+ messages in thread
From: Wei Gao via ltp @ 2023-03-10 14:04 UTC (permalink / raw)
  To: ltp

Signed-off-by: Wei Gao <wegao@suse.com>
---
 testcases/kernel/syscalls/madvise/madvise11.c | 32 +++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)

diff --git a/testcases/kernel/syscalls/madvise/madvise11.c b/testcases/kernel/syscalls/madvise/madvise11.c
index 7e291d571..bac077fc8 100644
--- a/testcases/kernel/syscalls/madvise/madvise11.c
+++ b/testcases/kernel/syscalls/madvise/madvise11.c
@@ -33,6 +33,7 @@
 #define NUM_LOOPS	5
 #define NUM_PAGES	32
 #define NUM_PAGES_OFFSET	5
+#define MAX_BUF 4094
 
 /* Needed module to online back memory pages */
 #define HW_MODULE	"hwpoison_inject"
@@ -291,6 +292,31 @@ static void unpoison_this_pfn(unsigned long pfn, int fd)
 	SAFE_WRITE(0, fd, pfn_str, strlen(pfn_str));
 }
 
+static int is_loadable_module(const char *modname)
+{
+	char command[MAX_BUF];
+	char line[MAX_BUF];
+	char *token;
+
+	sprintf(command, "lsmod | grep '^%s'", modname);
+
+	FILE *fp = popen(command, "r");
+
+	if (fp == NULL)
+		tst_brk(TBROK, "Popen command %s failed", command);
+
+	if (fgets(line, MAX_BUF, fp) != NULL) {
+		token = strtok(line, " \t\n");
+		if (strcmp(token, modname) == 0) {
+			pclose(fp);
+			return 1;
+		}
+	}
+
+	pclose(fp);
+	return 0;
+}
+
 /* Find and open the <debugfs>/hwpoison/unpoison-pfn special file */
 static int open_unpoison_pfn(void)
 {
@@ -337,6 +363,7 @@ static void unpoison_pfn(char *begin_tag)
 	unsigned long *pfns;
 	const char *const cmd_rmmod[] = {"rmmod", HW_MODULE, NULL};
 	int found_pfns, fd;
+	int is_loadable = -1;
 
 	pfns = SAFE_MALLOC(sizeof(pfns) * maximum_pfns * run_iterations);
 
@@ -351,8 +378,9 @@ static void unpoison_pfn(char *begin_tag)
 
 		SAFE_CLOSE(fd);
 	}
-	/* remove hwpoison only if we probed it */
-	if (hwpoison_probe)
+	/* remove hwpoison only if we probed it and not built in*/
+	is_loadable = is_loadable_module(HW_MODULE);
+	if (hwpoison_probe && (is_loadable == 1))
 		SAFE_CMD(cmd_rmmod, NULL, NULL);
 }
 
-- 
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

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

end of thread, other threads:[~2023-03-24  5:51 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-10 14:04 [LTP] [PATCH v1] madvise11.c:Check loadable module before rmmod Wei Gao via ltp
2023-03-10 14:52 ` Cyril Hrubis
2023-03-11  2:23   ` Wei Gao via ltp
2023-03-12  0:47     ` Wei Gao via ltp
2023-03-13  8:55     ` Cyril Hrubis
2023-03-10 14:53 ` Cyril Hrubis
2023-03-11  2:35   ` Wei Gao via ltp
2023-03-11  2:33 ` [LTP] [PATCH v2] " Wei Gao via ltp
2023-03-12  0:44   ` [LTP] [PATCH v3] " Wei Gao via ltp
2023-03-13  9:19     ` Cyril Hrubis
2023-03-13 12:21       ` Wei Gao via ltp
2023-03-13 12:37         ` Cyril Hrubis
2023-03-13 13:46           ` Wei Gao via ltp
2023-03-13 14:06             ` Cyril Hrubis
2023-03-14  5:31               ` Wei Gao via ltp
2023-03-14  8:15                 ` Cyril Hrubis
2023-03-14  8:49                   ` Richard Palethorpe
2023-03-14  9:15                     ` Cyril Hrubis
2023-03-14 13:10                       ` Richard Palethorpe
2023-03-14  9:43                   ` Wei Gao via ltp
2023-03-13 13:41     ` [LTP] [PATCH v4] " Wei Gao via ltp
2023-03-14  9:37       ` [LTP] [PATCH v5] " Wei Gao via ltp
2023-03-21 16:50         ` Petr Vorel
2023-03-23  9:47         ` Cyril Hrubis
2023-03-23 12:10         ` [LTP] [PATCH v6 0/2] madvise11: Check if module is loadable " Wei Gao via ltp
2023-03-23 12:10           ` [LTP] [PATCH v6 1/2] tst_kernel: Add function check if the kernel module is built-in Wei Gao via ltp
2023-03-24  5:51             ` Petr Vorel
2023-03-23 12:10           ` [LTP] [PATCH v6 2/2] madvise11: Check if module is loadable before rmmod Wei Gao via ltp

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).