Skip to contentSkip to conversation

Support driver in kernel 5.10 and bug fixes

PATCH Superseded ramesh.thomas at intel.com 2 participants 8 messages Dec 8, 2020

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

ramesh.thomas at intel.com

#0 lore raw

cover Support driver in kernel 5.10 and bug fixes

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

Updated to match new driver changes in kernel 5.10. mdev types are named idxd-<accel type>-<mdev type>-v<hw version>. Driver loading in test takes care of interdependency between 2 required kernel modules - idxd_mdev and idxd.

Some bug fixes.

Ramesh Thomas (5):
accel-config: Support new driver changes in kernel ver 5.10
accel-config: Fix a segmentation fault issue in add device
accel-config: Fix a return value error
accel-config: Add freeing of mdev list
accel-config: Manage idxd_mdev and idxd kernel

 accfg/lib/libaccfg.c | 56 ++++++++++++++++++++++++++------------------
 test/libaccfg.c      | 36 ++++++++++++++++++++--------
 2 files changed, 59 insertions(+), 33 deletions(-)
Signature · 1 line
2.26.2
#1 lore raw

PATCH 1/5 accel-config: Support new driver changes in kernel ver 5.10

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

New driver ver 1.0 in kernl 5.10 has changed the format of mdev type name. Add changes in library to read the new type names while scanning for and creation of mdevs.

Signed-off-by Ramesh Thomas <ramesh.thomas(a)intel.com>
---
 accfg/lib/libaccfg.c | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)
accfg/lib/libaccfg.c +7 -12
index b003644..eda6b45 100644
@@ -416,18 +416,10 @@ static int device_parse_type(struct accfg_device *device)
 static int mdev_str_to_type(char *mdev_type_str)
 {
 	char **b;
-	char *s;
-	int l, i;
-
-	s = strchr(mdev_type_str, '-');
-	if (!s)
-		s = mdev_type_str;
-	else
-		s++;
-	l = (int) (strchrnul(s, '-') - s);
+	int i;
 
 	for (b = accfg_mdev_basenames, i = 0; *b != NULL; b++, i++)
-		if (!strncmp(*b, s, l))
+		if (strstr(mdev_type_str, *b))
 			return i;
 
 	return ACCFG_MDEV_TYPE_UNKNOWN;
@@ -1002,6 +994,7 @@ ACCFG_EXPORT int accfg_create_mdev(struct accfg_device *device,
 	struct accfg_device_mdev *mdev;
 	char uuid_str[UUID_STR_LEN];
 	char mdev_path[PATH_MAX];
+	unsigned int version;
 	int rc;
 
 	if (type >= ACCFG_MDEV_TYPE_UNKNOWN || type < 0)
@@ -1016,8 +1009,10 @@ ACCFG_EXPORT int accfg_create_mdev(struct accfg_device *device,
 	mdev->type = type;
 
 	uuid_unparse(mdev->uuid, uuid_str);
-	sprintf(mdev_path, "%s/%s/idxd-%s/create", device->mdev_path,
-			MDEV_POSTFIX, accfg_mdev_basenames[type]);
+	version = device->version  >> 8;
+	sprintf(mdev_path, "%s/%s/idxd-%s-%s-v%d/create", device->mdev_path,
+			MDEV_POSTFIX, device->device_type_str,
+			accfg_mdev_basenames[type], version);
 	rc = sysfs_write_attr(ctx, mdev_path, uuid_str);
 	if (rc < 0) {
 		err(ctx, "create mdev failed %d\n", rc);
Signature · 1 line
2.26.2
#2 lore raw

PATCH 2/5 accel-config: Fix a segmentation fault issue in add device

In reply to ramesh.thomas at intel.com

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

During device init, newly created device should be added to device linked list only at the end in the success path. Adding of mdev was done after that, resulting in invalid linked list state if the mdev scanning failed causing the add device function to fail. Move it before adding device to linked list.

Signed-off-by Ramesh Thomas <ramesh.thomas(a)intel.com>
---
 accfg/lib/libaccfg.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
accfg/lib/libaccfg.c +3 -2
index eda6b45..5835129 100644
@@ -568,12 +568,13 @@ static void *add_device(void *parent, int id, const char *ctl_base, char *dev_pr
 	rc = device_parse_type(device);
 	if (rc < 0)
 		goto err_dev_path;
-	list_add_tail(&ctx->devices, &device->list);
-	free(path);
 
 	if (add_device_mdevs(ctx, device))
 		goto err_dev_path;
 
+	list_add_tail(&ctx->devices, &device->list);
+	free(path);
+
 	return device;
 
 err_dev_path:
Signature · 1 line
2.26.2
#3 lore raw

PATCH 3/5 accel-config: Fix a return value error

In reply to ramesh.thomas at intel.com

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

device_parse_type did not return error even if device type name was invalid. Changed the implementation to iterate through basenames array and return the index of matched device type name. This assumes device type enum is equal to index of corresponding device type names in basenames array. If type is not found, return -1 indicating error.

Signed-off-by Ramesh Thomas <ramesh.thomas(a)intel.com>
---
 accfg/lib/libaccfg.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
accfg/lib/libaccfg.c +9 -9
index 5835129..b1e6d86 100644
@@ -400,17 +400,17 @@ static int device_parse(struct accfg_ctx *ctx, const char *base_path,
 
 static int device_parse_type(struct accfg_device *device)
 {
-	if (!device)
-		return -EINVAL;
+	char **b;
+	int i;
 
-	if (!strcmp(device->device_type_str, "dsa"))
-		device->type = ACCFG_DEVICE_DSA;
-	else if (!strcmp(device->device_type_str, "iax"))
-		device->type = ACCFG_DEVICE_IAX;
-	else
-		device->type = ACCFG_DEVICE_TYPE_UNKNOWN;
+	for (b = accfg_basenames, i = 0; *b != NULL; b++, i++) {
+		if (!strcmp(device->device_type_str, *b)) {
+			device->type = i;
+			return 0;
+		}
+	}
 
-	return 0;
+	return -1;
 }
 
 static int mdev_str_to_type(char *mdev_type_str)
Signature · 1 line
2.26.2
#4 lore raw

[Accel-config] Re: [PATCH v1 3/5] accel-config: Fix a return value error

Quoted 31 lines · On Tue, 8 Dec 2020 15:36:45 -0500 <ramesh.thomas(a)intel.com> wrote:

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

device_parse_type did not return error even if device type name was invalid. Changed the implementation to iterate through basenames array and return the index of matched device type name. This assumes device type enum is equal to index of corresponding device type names in basenames array. If type is not found, return -1 indicating error.

Signed-off-by Ramesh Thomas <ramesh.thomas(a)intel.com>
---
 accfg/lib/libaccfg.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
accfg/lib/libaccfg.c +2 -7
index 5835129..b1e6d86 100644
@@ -400,17 +400,17 @@ static int device_parse(struct accfg_ctx *ctx,
 const char *base_path, 
 static int device_parse_type(struct accfg_device *device)
 {
-	if (!device)
-		return -EINVAL;
+	char **b;
+	int i;
 
-	if (!strcmp(device->device_type_str, "dsa"))
-		device->type = ACCFG_DEVICE_DSA;
-	else if (!strcmp(device->device_type_str, "iax"))
-		device->type = ACCFG_DEVICE_IAX;
-	else

accfg/lib/libaccfg.c static int device_parse(struct accfg_ctx *ctx, · line 413

Quoted 10 lines
accfg/lib/libaccfg.c +7 -2
-		device->type = ACCFG_DEVICE_TYPE_UNKNOWN;
+	for (b = accfg_basenames, i = 0; *b != NULL; b++, i++) {
+		if (!strcmp(device->device_type_str, *b)) {
+			device->type = i;
+			return 0;
+		}
+	}
 
-	return 0;
+	return -1;

-ENODEV? -ENOENT? probably better than just -1.

Quoted 3 lines
accfg/lib/libaccfg.c +0 -0
 }
 
 static int mdev_str_to_type(char *mdev_type_str)
#5 lore raw

PATCH 4/5 accel-config: Add freeing of mdev list

In reply to ramesh.thomas at intel.com

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

Per device mdev list was not getting freed at error exit and when device was getting freed. Add freeing of list for a given device.

Signed-off-by Ramesh Thomas <ramesh.thomas(a)intel.com>
---
 accfg/lib/libaccfg.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
accfg/lib/libaccfg.c +14 -0
index b1e6d86..2b3bbb3 100644
@@ -153,6 +153,16 @@ static char *accfg_get_param_str(struct accfg_ctx *ctx, int dfd, char *name)
 	return strdup(buf);
 }
 
+static void free_mdevs(struct accfg_device *device)
+{
+	struct accfg_device_mdev *mdev, *next;
+
+	list_for_each_safe(&device->mdev_list, mdev, next, list) {
+		list_del_from(&device->mdev_list, &mdev->list);
+		free(mdev);
+	}
+}
+
 static void free_engine(struct accfg_engine *engine)
 {
 	struct accfg_device *device = engine->device;
@@ -195,6 +205,7 @@ static void free_device(struct accfg_device *device, struct list_head *head)
 		free_wq(wq);
 	list_for_each_safe(&device->engines, engine, engine_next, list)
 		free_engine(engine);
+	free_mdevs(device);
 
 	if (head)
 		list_del_from(head, &device->list);
@@ -473,6 +484,9 @@ exit_add_mdev:
 		free(d[n1]);
 	free(d);
 
+	if (rc)
+		free_mdevs(dev);
+
 	return rc;
 }
 
Signature · 1 line
2.26.2
#6 lore raw

PATCH 5/5 accel-config: Manage idxd_mdev and idxd kernel

In reply to ramesh.thomas at intel.com

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>
---
 test/libaccfg.c | 36 ++++++++++++++++++++++++++----------
 1 file changed, 26 insertions(+), 10 deletions(-)
test/libaccfg.c +26 -10
index 94d6156..88108a9 100644
@@ -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;
Signature · 1 line
2.26.2
#7 lore raw
In reply to ramesh.thomas at intel.com
Quoted 1 line · On Tue, 8 Dec 2020 15:36:42 -0500 <ramesh.thomas(a)intel.com> wrote:

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

Besides commit 3 comment, all Reviewed-by: Dave Jiang <dave.jiang(a)intel.com>

Quoted 20 lines

Updated to match new driver changes in kernel 5.10. mdev types are named idxd-<accel type>-<mdev type>-v<hw version>. Driver loading in test takes care of interdependency between 2 required kernel modules - idxd_mdev and idxd.

Some bug fixes.

Ramesh Thomas (5):
accel-config: Support new driver changes in kernel ver 5.10
accel-config: Fix a segmentation fault issue in add device
accel-config: Fix a return value error
accel-config: Add freeing of mdev list
accel-config: Manage idxd_mdev and idxd kernel

 accfg/lib/libaccfg.c | 56

++++++++++++++++++++++++++------------------ test/libaccfg.c |
36 ++++++++++++++++++++-------- 2 files changed, 59 insertions(+), 33 deletions(-)