Skip to contentSkip to conversation

Some mdev and unit test fixes

PATCH In review ramesh.thomas at intel.com 2 participants 7 messages Apr 6, 2021

lore
Share & tools
lore

ramesh.thomas at intel.com

#0 lore raw

cover Some mdev and unit test fixes

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

These patches add some mdev and unit test fixes.

Ramesh Thomas (5):
accel-config: Update for driver deferred mdev registration
accel-config: mdev was missing as a wq type in json implementation accel-config/test: Fix some invalid wq test parameters accel-config/test: Skip tests if device is not configurable accel-config/test: Remove load/unload of kernel modules in test

 accfg/lib/libaccfg.c | 19 ++++++++++---------
 test/libaccfg.c      | 33 +++++++++++++++------------------
 util/json.c          |  3 ++-
 3 files changed, 27 insertions(+), 28 deletions(-)
Signature · 1 line
2.26.3
#1 lore raw

PATCH 1/5 accel-config: Update for driver deferred mdev registration

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

Mdev is now registered when the first mdev wq is created. It will be deregistered when the last mdev wq is removed. Change will check for presence of /sys/class/mdev_bus at the point of mdev use instead of initializing context at start.

Signed-off-by Ramesh Thomas <ramesh.thomas(a)intel.com>
---
 accfg/lib/libaccfg.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)
accfg/lib/libaccfg.c +10 -9
index a8d18ff..24ae65c 100644
@@ -108,6 +108,11 @@ const char *accfg_device_cmd_status[] = {
 	[ACCFG_CMD_STATUS_MAX]	= "",
 };
 
+static inline bool is_mdev_registered(struct accfg_device *device)
+{
+	return device->mdev_path && !access(device->mdev_path, R_OK);
+}
+
 static long accfg_get_param_long(struct accfg_ctx *ctx, int dfd, char *name)
 {
 	int fd = openat(dfd, name, O_RDONLY);
@@ -593,11 +598,7 @@ static void *add_device(void *parent, int id, const char *ctl_base,
 		goto err_dev_path;
 	}
 	free(device->mdev_path);
-	if (access(p, R_OK)) {
-		free(p);
-		device->mdev_path = NULL;
-	} else
-		device->mdev_path = p;
+	device->mdev_path = p;
 
 	device->device_buf = calloc(1, strlen(device->device_path) +
 			MAX_PARAM_LEN);
@@ -614,7 +615,7 @@ static void *add_device(void *parent, int id, const char *ctl_base,
 
 	device->bus_type_str = bus_type;
 
-	if (device->mdev_path && add_device_mdevs(ctx, device))
+	if (is_mdev_registered(device) && add_device_mdevs(ctx, device))
 		goto err_dev_path;
 
 	list_add_tail(&ctx->devices, &device->list);
@@ -1050,7 +1051,7 @@ ACCFG_EXPORT int accfg_create_mdev(struct accfg_device *device,
 	unsigned int version;
 	int rc;
 
-	if (!device->mdev_path)
+	if (!is_mdev_registered(device))
 		return -ENOENT;
 
 	if (type >= ACCFG_MDEV_TYPE_UNKNOWN || type < 0)
@@ -1110,7 +1111,7 @@ ACCFG_EXPORT int accfg_remove_mdev(struct accfg_device *device, uuid_t uuid)
 	struct accfg_device_mdev *entry, *next;
 	int rc, all;
 
-	if (!device->mdev_path)
+	if (!is_mdev_registered(device))
 		return -ENOENT;
 
 	/* remove all mdevs if null uuid is passed */
@@ -1266,7 +1267,7 @@ ACCFG_EXPORT bool accfg_device_get_pasid_enabled(
 ACCFG_EXPORT bool accfg_device_get_mdev_enabled(
 		struct accfg_device *device)
 {
-	return device->mdev_path != NULL;
+	return is_mdev_registered(device);
 }
 
 ACCFG_EXPORT int accfg_device_get_errors(struct accfg_device *device,
Signature · 1 line
2.26.3
#2 lore raw

PATCH 2/5 accel-config: mdev was missing as a wq type in json implementation

In reply to ramesh.thomas at intel.com

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

mdev was missing in the list of wq types in json implementation causing it to not recognize mdev type wqs.

Signed-off-by Ramesh Thomas <ramesh.thomas(a)intel.com>
---
 util/json.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
util/json.c +2 -1
index 2fd2b71..f2bb990 100644
@@ -20,7 +20,8 @@
 static const char *wq_type_str[] = {
 	"none",
 	"kernel",
-	"user"
+	"user",
+	"mdev"
 };
 
 /* adapted from mdadm::human_size_brief() */
Signature · 1 line
2.26.3
#3 lore raw

PATCH 3/5 accel-config/test: Fix some invalid wq test parameters

In reply to ramesh.thomas at intel.com

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

Mdev tests were passing wq type as "user" instead of "mdev" max_batch_size and max_transfer_size were using values that caused wq enable to fail

Signed-off-by Ramesh Thomas <ramesh.thomas(a)intel.com>
---
 test/libaccfg.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
test/libaccfg.c +6 -6
index 0ff43ca..0257ddb 100644
@@ -82,8 +82,8 @@ static struct wq_parameters wq00_param = {
 	.priority = 10,
 	.block_on_fault = 1,
 	.threshold = 15,
-	.max_batch_size = 1,
-	.max_transfer_size = 1,
+	.max_batch_size = 16,
+	.max_transfer_size = 16,
 	.mode = "shared",
 	.type = "user",
 	.name = "myapp1"
@@ -111,7 +111,7 @@ static struct wq_parameters wq02_param = {
 	.max_batch_size = (1 << 8),
 	.max_transfer_size = (1l << 30),
 	.mode = "shared",
-	.type = "user",
+	.type = "mdev",
 	.name = "guest1"
 };
 
@@ -123,7 +123,7 @@ static struct wq_parameters wq03_param = {
 	.max_batch_size = (1 << 9),
 	.max_transfer_size = (1l << 31),
 	.mode = "dedicated",
-	.type = "user",
+	.type = "mdev",
 	.name = "guest2"
 
 };
@@ -790,8 +790,8 @@ static int wq_bounds_test(struct accfg_ctx *ctx, const char *dev_name)
 	}
 
 	/* reset to valid values for following tests */
-	wq00_param.max_batch_size = 1;
-	wq00_param.max_transfer_size = 1;
+	wq00_param.max_batch_size = 16;
+	wq00_param.max_transfer_size = 16;
 	rc = config_wq(ctx, 0, 0, wq00_param, dev_name);
 	if (rc != 0) {
 		fprintf(stderr, "config wq wq0.0 failed\n");
Signature · 1 line
2.26.3
#4 lore raw

PATCH 4/5 accel-config/test: Skip tests if device is not configurable

In reply to ramesh.thomas at intel.com

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

None of the tests can be run if the devices are not configurable so skip.

Signed-off-by Ramesh Thomas <ramesh.thomas(a)intel.com>
---
 test/libaccfg.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
test/libaccfg.c +7 -1
index 0257ddb..951985d 100644
@@ -1116,7 +1116,7 @@ int test_libaccfg(int loglevel, struct accfg_test *test,
 
 	/*
 	 * iterate to check the state of each device, skip entire test if any of
-	 * them is active
+	 * them is active or not configurable
 	 */
 	accfg_device_foreach(ctx, device) {
 		if (accfg_device_is_active(device)) {
@@ -1134,6 +1134,12 @@ int test_libaccfg(int loglevel, struct accfg_test *test,
 			fprintf(stderr, "device has no pasid support, skipping tests\n");
 			return EXIT_SKIP;
 		}
+
+		if (!accfg_device_get_configurable(device)) {
+			accfg_test_skip(test);
+			fprintf(stderr, "device is not configuratble, skipping tests\n");
+			return EXIT_SKIP;
+		}
 	}
 
 	for (i = 0; i < ARRAY_SIZE(test_cases); i++) {
Signature · 1 line
2.26.3
#5 lore raw

PATCH 5/5 accel-config/test: Remove load/unload of kernel modules in test

In reply to ramesh.thomas at intel.com

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

Loading and unloading of kernel modules in test is unreliable due to dependencies across multiple modules. It is also not necessary because the test should be run only after necessary idxd kernel modules are loaded.

Signed-off-by Ramesh Thomas <ramesh.thomas(a)intel.com>
---
 test/libaccfg.c | 13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)
test/libaccfg.c +2 -11
index 951985d..ce21fb3 100644
@@ -1074,18 +1074,12 @@ static int idxd_kmod_init(struct kmod_ctx **ctx, struct kmod_module **mod,
 		return rc;
 	}
 	rc = kmod_module_get_initstate(*mdev_mod);
-	if (rc == -ENOENT)
-		rc = kmod_module_probe_insert_module(*mdev_mod, 0, NULL, NULL, NULL,
-				NULL);
 	if (rc < 0) {
 		kmod_module_unref(*mdev_mod);
 		*mdev_mod = NULL;
 		mdev_disabled = true;
 	}
 	rc = kmod_module_get_initstate(*mod);
-	if (rc == -ENOENT)
-		rc = kmod_module_probe_insert_module(*mod, 0, NULL, NULL, NULL,
-				NULL);
 	if (rc < 0) {
 		kmod_module_unref(*mod);
 		kmod_unref(*ctx);
@@ -1165,12 +1159,9 @@ int test_libaccfg(int loglevel, struct accfg_test *test,
 
 	test_cleanup(ctx);
 
-	if (mdev_mod) {
-		kmod_module_remove_module(mdev_mod, 0);
+	if (mdev_mod)
 		kmod_module_unref(mdev_mod);
-	}
-	kmod_module_remove_module(mod, 0);
-	kmod_module_probe_insert_module(mod, 0, NULL, NULL, NULL, NULL);
+
 	kmod_module_unref(mod);
 	kmod_unref(kmod_ctx);
 
Signature · 1 line
2.26.3
Reviewed-by on the v1 series
#6 lore raw
In reply to ramesh.thomas at intel.com
Quoted 11 lines · ramesh.thomas(a)intel.com

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

These patches add some mdev and unit test fixes.

Ramesh Thomas (5):
accel-config: Update for driver deferred mdev registration
accel-config: mdev was missing as a wq type in json implementation accel-config/test: Fix some invalid wq test parameters accel-config/test: Skip tests if device is not configurable accel-config/test: Remove load/unload of kernel modules in test

Quoted 4 lines
  accfg/lib/libaccfg.c | 19 ++++++++++---------
  test/libaccfg.c      | 33 +++++++++++++++------------------
  util/json.c          |  3 ++-
  3 files changed, 27 insertions(+), 28 deletions(-)

For the series

Reviewed-by Dave Jiang <dave.jiang(a)intel.com>