Skip to contentSkip to conversation

Add backward compatibility

PATCH In review ramesh.thomas at intel.com 2 participants 8 messages Jan 23, 2021 – Jan 25, 2021

lore
Share & tools
lore

ramesh.thomas at intel.com

#0 lore raw

cover Add backward compatibility

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

This patch set provides backward compatibility for older kernels that does not support mdev.

If mdev feature is not available, following actions are taken:
- The library will disable mdev features and will return -NOENT
- The mdev commands would print an error message and exit
- The test program would skip mdev tests

Ramesh Thomas (6):
accel-config: Combine symbols in same release into single group
accel-config: Allow other functionality if mdev support unavailable
accel-config: Add API to check for mdev support availability
accel-config: Add check for mdev support availability in commands
accel-config: Make idxd_mdev module optional
accel-config: Disable mdev operations if mdev support unavailable

 accfg/lib/libaccel-config.sym |  7 ++---
 accfg/lib/libaccfg.c          | 20 +++++++++++++--
 accfg/libaccel_config.h       |  1 +
 accfg/mdev.c                  | 10 ++++++++
 test/libaccfg.c               | 48 +++++++++++++++++++++++++----------
 5 files changed, 66 insertions(+), 20 deletions(-)
Signature · 1 line
2.26.2
#1 lore raw

PATCH 1/6 accel-config: Combine symbols in same release into single group

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

2 sets of functions added during the same release were put in separate groups. Combine the groups into one.

Signed-off-by Ramesh Thomas <ramesh.thomas(a)intel.com>
---
 accfg/lib/libaccel-config.sym | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
accfg/lib/libaccel-config.sym +1 -5
index 73c8417..00f97d5 100644
@@ -132,10 +132,6 @@ global:
 	accfg_wq_get_max_transfer_size;
 	accfg_wq_set_max_batch_size;
 	accfg_wq_set_max_transfer_size;
-} LIBACCFG_6;
-
-LIBACCFG_8 {
-global:
 	accfg_device_first_mdev;
 	accfg_device_next_mdev;
 	accfg_mdev_get_uuid;
@@ -143,4 +139,4 @@ global:
 	accfg_mdev_basenames;
 	accfg_create_mdev;
 	accfg_remove_mdev;
-} LIBACCFG_7;
+} LIBACCFG_6;
Signature · 1 line
2.26.2
#2 lore raw

PATCH 2/6 accel-config: Allow other functionality if mdev support unavailable

In reply to ramesh.thomas at intel.com

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

In older drivers mdev is not supported. To provide backward compatibility disable mdev if not supported and allow other functionality.

Signed-off-by Ramesh Thomas <ramesh.thomas(a)intel.com>
---
 accfg/lib/libaccfg.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
accfg/lib/libaccfg.c +12 -2
index b1de896..69f0f71 100644
@@ -568,7 +568,11 @@ static void *add_device(void *parent, int id, const char *ctl_base, char *dev_pr
 		goto err_dev_path;
 	}
 	free(device->mdev_path);
-	device->mdev_path = p;
+	if (access(p, R_OK)) {
+		free(p);
+		device->mdev_path = NULL;
+	} else
+		device->mdev_path = p;
 
 	device->device_buf = calloc(1, strlen(device->device_path) +
 			MAX_PARAM_LEN);
@@ -583,7 +587,7 @@ static void *add_device(void *parent, int id, const char *ctl_base, char *dev_pr
 	if (rc < 0)
 		goto err_dev_path;
 
-	if (add_device_mdevs(ctx, device))
+	if (device->mdev_path && add_device_mdevs(ctx, device))
 		goto err_dev_path;
 
 	list_add_tail(&ctx->devices, &device->list);
@@ -1012,6 +1016,9 @@ ACCFG_EXPORT int accfg_create_mdev(struct accfg_device *device,
 	unsigned int version;
 	int rc;
 
+	if (!device->mdev_path)
+		return -ENOENT;
+
 	if (type >= ACCFG_MDEV_TYPE_UNKNOWN || type < 0)
 		return -EINVAL;
 
@@ -1069,6 +1076,9 @@ 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)
+		return -ENOENT;
+
 	/* remove all mdevs if null uuid is passed */
 	all = uuid_is_null(uuid);
 	list_for_each_safe(&device->mdev_list, entry, next, list) {
Signature · 1 line
2.26.2
#3 lore raw

PATCH 3/6 accel-config: Add API to check for mdev support availability

In reply to ramesh.thomas at intel.com

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

Add a function to check for mdev support availability to allow mdev command implementations to bail out if support is not available.

Signed-off-by Ramesh Thomas <ramesh.thomas(a)intel.com>
---
 accfg/lib/libaccel-config.sym | 1 +
 accfg/lib/libaccfg.c          | 6 ++++++
 accfg/libaccel_config.h       | 1 +
 3 files changed, 8 insertions(+)
accfg/lib/libaccel-config.sym +1 -0
index 00f97d5..4de2a49 100644
@@ -139,4 +139,5 @@ global:
 	accfg_mdev_basenames;
 	accfg_create_mdev;
 	accfg_remove_mdev;
+	accfg_device_get_mdev_enabled;
 } LIBACCFG_6;
accfg/lib/libaccfg.c +6 -0
index 69f0f71..a596c90 100644
@@ -1229,6 +1229,12 @@ ACCFG_EXPORT bool accfg_device_get_pasid_enabled(
 	return device->pasid_enabled;
 }
 
+ACCFG_EXPORT bool accfg_device_get_mdev_enabled(
+		struct accfg_device *device)
+{
+	return device->mdev_path != NULL;
+}
+
 ACCFG_EXPORT int accfg_device_get_errors(struct accfg_device *device,
 		struct accfg_error *error)
 {
accfg/libaccel_config.h +1 -0
index 7fa3c2b..239d393 100644
@@ -172,6 +172,7 @@ unsigned long accfg_device_get_op_cap(struct accfg_device *device);
 unsigned long accfg_device_get_gen_cap(struct accfg_device *device);
 unsigned int accfg_device_get_configurable(struct accfg_device *device);
 bool accfg_device_get_pasid_enabled(struct accfg_device  *device);
+bool accfg_device_get_mdev_enabled(struct accfg_device *device);
 int accfg_device_get_errors(struct accfg_device *device, struct accfg_error *error);
 enum accfg_device_state accfg_device_get_state(struct accfg_device *device);
 unsigned int accfg_device_get_max_tokens(struct accfg_device *device);
Signature · 1 line
2.26.2
#4 lore raw

PATCH 4/6 accel-config: Add check for mdev support availability in commands

In reply to ramesh.thomas at intel.com

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

Add check for mdev support availability in mdev commands and exit with error message if support is not available.

Signed-off-by Ramesh Thomas <ramesh.thomas(a)intel.com>
---
 accfg/mdev.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
accfg/mdev.c +10 -0
index 652b734..3bde7eb 100644
@@ -90,6 +90,11 @@ int cmd_create_mdev(int argc, const char **argv, void *ctx)
 		usage_with_options(u, options);
 	}
 
+	if (!accfg_device_get_mdev_enabled(device)) {
+		fprintf(stderr, "mdev support not available\n");
+		return 0;
+	}
+
 	argc = parse_options(argc, argv, options, u, 0);
 	if (opt_called)
 		return 0;
@@ -138,6 +143,11 @@ int cmd_remove_mdev(int argc, const char **argv, void *ctx)
 		usage_with_options(u, options);
 	}
 
+	if (!accfg_device_get_mdev_enabled(device)) {
+		fprintf(stderr, "mdev support not available\n");
+		return 0;
+	}
+
 	argc = parse_options(argc, argv, options, u, 0);
 	if (opt_called)
 		return 0;
Signature · 1 line
2.26.2
#5 lore raw

PATCH 5/6 accel-config: Make idxd_mdev module optional

In reply to ramesh.thomas at intel.com

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

Add conditional load and unload of idxd_mdev and make existence of the module optional.

Signed-off-by Ramesh Thomas <ramesh.thomas(a)intel.com>
---
 test/libaccfg.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)
test/libaccfg.c +14 -7
index 88108a9..031b7fa 100644
@@ -1067,12 +1067,16 @@ static int idxd_kmod_init(struct kmod_ctx **ctx, struct kmod_module **mod,
 	if (rc == -ENOENT)
 		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);
+		*mdev_mod = NULL;
+	}
+	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);
 	}
 
@@ -1140,10 +1144,13 @@ int test_libaccfg(int loglevel, struct accfg_test *test,
 
 	test_cleanup(ctx);
 
-	kmod_module_remove_module(mdev_mod, 0);
-	kmod_module_probe_insert_module(mdev_mod, 0, NULL, NULL, NULL, NULL);
+	if (mdev_mod) {
+		kmod_module_remove_module(mdev_mod, 0);
+		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_module_unref(mdev_mod);
 	kmod_unref(kmod_ctx);
 
 	return result;
Signature · 1 line
2.26.2
#6 lore raw

PATCH 6/6 accel-config: Disable mdev operations if mdev support unavailable

In reply to ramesh.thomas at intel.com

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

If idxd_mdev module is not found disable mdev tests and operations.

Signed-off-by Ramesh Thomas <ramesh.thomas(a)intel.com>
---
 test/libaccfg.c | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)
test/libaccfg.c +21 -6
index 031b7fa..0ff43ca 100644
@@ -34,6 +34,8 @@
 #define PORTAL_SIZE	4096
 #define BUF_SIZE	4096
 
+static bool mdev_disabled;
+
 struct accfg_wq_ctx {
 	int major;
 	int minor;
@@ -491,12 +493,14 @@ static int device_test_reset(struct accfg_ctx *ctx, const char *dev_name,
 	/* make sure device is disabled before configuration */
 	if (accfg_device_is_active(device)) {
 
-		/* Remove all mdevs */
-		uuid_clear(uuid);
-		rc = accfg_remove_mdev(device, uuid);
-		if (rc && !forced) {
-			fprintf(stderr, "mdev removal failed\n");
-			return rc;
+		if (!mdev_disabled) {
+			/* Remove all mdevs */
+			uuid_clear(uuid);
+			rc = accfg_remove_mdev(device, uuid);
+			if (rc && !forced) {
+				fprintf(stderr, "mdev removal failed\n");
+				return rc;
+			}
 		}
 
 		/* make sure each wq is disabled */
@@ -1008,6 +1012,7 @@ struct _test_case {
 	do_test_fn test_fn;
 	char *desc;
 	bool enabled;
+	bool mdev;
 };
 
 static struct _test_case test_cases[] = {
@@ -1015,26 +1020,31 @@ static struct _test_case test_cases[] = {
 		.test_fn = test_config,
 		.desc = "set and get configurations",
 		.enabled = true,
+		.mdev = false,
 	},
 	{
 		.test_fn = test_max_wq_size,
 		.desc = "max wq size",
 		.enabled = true,
+		.mdev = false,
 	},
 	{
 		.test_fn = test_wq_boundary_conditions,
 		.desc = "wq boundary conditions",
 		.enabled = true,
+		.mdev = false,
 	},
 	{
 		.test_fn = test_mdev_1swq,
 		.desc = "1swq type mdev creation and removal",
 		.enabled = true,
+		.mdev = true,
 	},
 	{
 		.test_fn = test_mdev_1dwq,
 		.desc = "1dwq type mdev creation and removal",
 		.enabled = true,
+		.mdev = true,
 	},
 };
 
@@ -1070,6 +1080,7 @@ static int idxd_kmod_init(struct kmod_ctx **ctx, struct kmod_module **mod,
 	if (rc < 0) {
 		kmod_module_unref(*mdev_mod);
 		*mdev_mod = NULL;
+		mdev_disabled = true;
 	}
 	rc = kmod_module_get_initstate(*mod);
 	if (rc == -ENOENT)
@@ -1130,6 +1141,10 @@ int test_libaccfg(int loglevel, struct accfg_test *test,
 			fprintf(stderr, "\naccfg-test%d *disabled*\n", i);
 			continue;
 		}
+
+		if (test_cases[i].mdev && mdev_disabled)
+			continue;
+
 		printf("\nRunning accfg-test%d: %s\n", i, test_cases[i].desc);
 		err = test_cases[i].test_fn(ctx);
 		if (err < 0) {
Signature · 1 line
2.26.2
Reviewed-by on the v1 series
#7 lore raw
In reply to ramesh.thomas at intel.com
Quoted 18 lines · ramesh.thomas(a)intel.com

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

This patch set provides backward compatibility for older kernels that does not support mdev.

If mdev feature is not available, following actions are taken:
- The library will disable mdev features and will return -NOENT
- The mdev commands would print an error message and exit
- The test program would skip mdev tests

Ramesh Thomas (6):
accel-config: Combine symbols in same release into single group
accel-config: Allow other functionality if mdev support unavailable
accel-config: Add API to check for mdev support availability
accel-config: Add check for mdev support availability in commands
accel-config: Make idxd_mdev module optional
accel-config: Disable mdev operations if mdev support unavailable

Quoted 6 lines
  accfg/lib/libaccel-config.sym |  7 ++---
  accfg/lib/libaccfg.c          | 20 +++++++++++++--
  accfg/libaccel_config.h       |  1 +
  accfg/mdev.c                  | 10 ++++++++
  test/libaccfg.c               | 48 +++++++++++++++++++++++++----------
  5 files changed, 66 insertions(+), 20 deletions(-)
Reviewed-by Dave Jiang <dave.jiang(a)intel.com> for the series. Thanks Ramesh