All of lore.kernel.org
 help / color / mirror / Atom feed
From: ramesh.thomas at intel.com
To: accel-config@lists.01.org
Subject: [Accel-config] [PATCH v2 5/5] accel-config: Manage idxd_mdev and idxd kernel
Date: Tue, 08 Dec 2020 16:16:18 -0500	[thread overview]
Message-ID: <20201208211617.351761-6-ramesh.thomas@intel.com> (raw)
In-Reply-To: 20201208211617.351761-1-ramesh.thomas@intel.com

[-- Attachment #1: Type: text/plain, Size: 3044 bytes --]

From: Ramesh Thomas <ramesh.thomas(a)intel.com>

modules
To: accel-config(a)lists.01.org
Cc: tony.luck(a)intel.com,
    dave.jiang(a)intel.com

Two interdependent modules, idxd_mdev and idxd needs to be loaded.
Loading of either loads the other module, however idxd cannot be
unloaded without unloading idxd_mdev. If at start, idxd_mdev is not
loaded, load it and check for idxd. On error, unref modules and context
and exit. At the end, do a reset of driver by unloading idxd_mdev and
reloading it.

Signed-off-by: Ramesh Thomas <ramesh.thomas(a)intel.com>
Reviewed-by: Dave Jiang <dave.jiang(a)intel.com>
---
 test/libaccfg.c | 36 ++++++++++++++++++++++++++----------
 1 file changed, 26 insertions(+), 10 deletions(-)

diff --git a/test/libaccfg.c b/test/libaccfg.c
index 94d6156..88108a9 100644
--- a/test/libaccfg.c
+++ b/test/libaccfg.c
@@ -1039,7 +1039,7 @@ static struct _test_case test_cases[] = {
 };
 
 static int idxd_kmod_init(struct kmod_ctx **ctx, struct kmod_module **mod,
-		int log_level)
+		struct kmod_module **mdev_mod, int log_level)
 {
 	struct log_ctx log_ctx;
 	int rc;
@@ -1057,11 +1057,25 @@ static int idxd_kmod_init(struct kmod_ctx **ctx, struct kmod_module **mod,
 		kmod_unref(*ctx);
 		return rc;
 	}
-
-	rc = kmod_module_get_initstate(*mod);
+	rc = kmod_module_new_from_name(*ctx, "idxd_mdev", mdev_mod);
+	if (rc < 0) {
+		kmod_module_unref(*mod);
+		kmod_unref(*ctx);
+		return rc;
+	}
+	rc = kmod_module_get_initstate(*mdev_mod);
 	if (rc == -ENOENT)
-		rc = kmod_module_probe_insert_module(*mod, 0, NULL, NULL, NULL,
+		rc = kmod_module_probe_insert_module(*mdev_mod, 0, NULL, NULL, NULL,
 				NULL);
+	if (rc >= 0)
+		rc = kmod_module_get_initstate(*mod);
+
+	if (rc < 0) {
+		kmod_module_unref(*mod);
+		kmod_module_unref(*mdev_mod);
+		kmod_unref(*ctx);
+	}
+
 	return rc;
 }
 
@@ -1071,14 +1085,14 @@ int test_libaccfg(int loglevel, struct accfg_test *test,
 	unsigned int i;
 	int err, result = EXIT_FAILURE;
 	struct kmod_ctx *kmod_ctx;
-	struct kmod_module *mod;
+	struct kmod_module *mod, *mdev_mod;
 	struct accfg_device *device;
 
 	if (!accfg_test_attempt(test, KERNEL_VERSION(5, 6, 0)))
 		return EXIT_SKIP;
 
 	accfg_set_log_priority(ctx, loglevel);
-	err = idxd_kmod_init(&kmod_ctx, &mod, loglevel);
+	err = idxd_kmod_init(&kmod_ctx, &mod, &mdev_mod, loglevel);
 	if (err < 0) {
 		accfg_test_skip(test);
 		fprintf(stderr, "idxd kmod unavailable skipping tests\n");
@@ -1123,11 +1137,13 @@ int test_libaccfg(int loglevel, struct accfg_test *test,
 
 	if (i >= ARRAY_SIZE(test_cases))
 		result = EXIT_SUCCESS;
-	else
-		test_cleanup(ctx);
 
-	kmod_module_remove_module(mod, 0);
-	kmod_module_probe_insert_module(mod, 0, NULL, NULL, NULL, NULL);
+	test_cleanup(ctx);
+
+	kmod_module_remove_module(mdev_mod, 0);
+	kmod_module_probe_insert_module(mdev_mod, 0, NULL, NULL, NULL, NULL);
+	kmod_module_unref(mod);
+	kmod_module_unref(mdev_mod);
 	kmod_unref(kmod_ctx);
 
 	return result;
-- 
2.26.2

                 reply	other threads:[~2020-12-08 21:16 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20201208211617.351761-6-ramesh.thomas@intel.com \
    --to=accel-config@lists.01.org \
    /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 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.