public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Wei Gao via ltp <ltp@lists.linux.it>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v5] madvise11.c:Check loadable module before rmmod
Date: Tue, 14 Mar 2023 05:37:25 -0400	[thread overview]
Message-ID: <20230314093725.3814-1-wegao@suse.com> (raw)
In-Reply-To: <20230313134133.8396-1-wegao@suse.com>

Following fail msg will popup if we try to rmmod buildin module:
rmmod: ERROR: Module hwpoison_inject is builtin

So need add extra check.

Signed-off-by: Wei Gao <wegao@suse.com>
---
 include/tst_kernel.h                          | 10 ++++++
 lib/tst_kernel.c                              | 36 +++++++++++--------
 testcases/kernel/syscalls/madvise/madvise11.c |  2 +-
 3 files changed, 33 insertions(+), 15 deletions(-)

diff --git a/include/tst_kernel.h b/include/tst_kernel.h
index 9e17bb71e..0c1262e2f 100644
--- a/include/tst_kernel.h
+++ b/include/tst_kernel.h
@@ -10,6 +10,16 @@
  */
 int tst_kernel_bits(void);
 
+/*
+ * Checks builtin module for the kernel driver.
+ *
+ * @param driver The name of the driver.
+ * @return Returns 0 if builtin driver
+ * -1 when driver is missing or config file not available.
+ * On Android *always* 0 (always expect the driver is available).
+ */
+int tst_check_builtin_driver(const char *driver);
+
 /**
  * Checks support for the kernel driver.
  *
diff --git a/lib/tst_kernel.c b/lib/tst_kernel.c
index ecf4b917e..be3ec92da 100644
--- a/lib/tst_kernel.c
+++ b/lib/tst_kernel.c
@@ -90,7 +90,7 @@ int tst_kernel_bits(void)
 	return kernel_bits;
 }
 
-static int tst_search_driver(const char *driver, const char *file)
+static int tst_search_driver_(const char *driver, const char *file)
 {
 	struct stat st;
 	char buf[PATH_MAX];
@@ -144,28 +144,19 @@ static int tst_search_driver(const char *driver, const char *file)
 	return ret;
 }
 
-static int tst_check_driver_(const char *driver)
-{
-	if (!tst_search_driver(driver, "modules.dep") ||
-		!tst_search_driver(driver, "modules.builtin"))
-		return 0;
-
-	return -1;
-}
-
-int tst_check_driver(const char *driver)
+static int tst_search_driver(const char *driver, const char *file)
 {
 #ifdef __ANDROID__
 	/*
 	 * Android may not have properly installed modules.* files. We could
-	 * search modules in /system/lib/modules, but to to determine built-in
+	 * search modules in /system/lib/modules, but to determine built-in
 	 * drivers we need modules.builtin. Therefore assume all drivers are
 	 * available.
 	 */
 	return 0;
 #endif
 
-	if (!tst_check_driver_(driver))
+	if (!tst_search_driver_(driver, file))
 		return 0;
 
 	int ret = -1;
@@ -183,9 +174,26 @@ int tst_check_driver(const char *driver)
 		while ((ix = strchr(ix, find)))
 			*ix++ = replace;
 
-		ret = tst_check_driver_(driver2);
+		ret = tst_search_driver_(driver2, file);
 		free(driver2);
 	}
 
 	return ret;
 }
+
+int tst_check_builtin_driver(const char *driver)
+{
+	if (!tst_search_driver(driver, "modules.builtin"))
+		return 0;
+
+	return -1;
+}
+
+int tst_check_driver(const char *driver)
+{
+	if (!tst_search_driver(driver, "modules.dep") ||
+		!tst_search_driver(driver, "modules.builtin"))
+		return 0;
+
+	return -1;
+}
diff --git a/testcases/kernel/syscalls/madvise/madvise11.c b/testcases/kernel/syscalls/madvise/madvise11.c
index 7e291d571..4d99d5289 100644
--- a/testcases/kernel/syscalls/madvise/madvise11.c
+++ b/testcases/kernel/syscalls/madvise/madvise11.c
@@ -300,7 +300,7 @@ static int open_unpoison_pfn(void)
 	struct mntent *mnt;
 	FILE *mntf;
 
-	if (!find_in_file("/proc/modules", HW_MODULE))
+	if (!find_in_file("/proc/modules", HW_MODULE) && tst_check_builtin_driver(HW_MODULE))
 		hwpoison_probe = 1;
 
 	/* probe hwpoison only if it isn't already there */
-- 
2.35.3


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

  reply	other threads:[~2023-03-14  9:37 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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       ` Wei Gao via ltp [this message]
2023-03-21 16:50         ` [LTP] [PATCH v5] " 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230314093725.3814-1-wegao@suse.com \
    --to=ltp@lists.linux.it \
    --cc=wegao@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox