Commit b217432f authored by Tomasz Zawadzki's avatar Tomasz Zawadzki Committed by Konrad Sztyber
Browse files

lib/idxd: fix device reference counting in kernel IDXD



Context created by accfg_new() needs to be kept during
the configuration and usage of the DSA device.

The creation of the context increments the reference count,
which can be further managed by accfg_ref() and accfg_unref().

Before this patch, the context was created correctly but
was not assigned to kernel_idxd->ctx, which is used
in kernel_idxd_device_destruct(). This issue is now resolved.

This patch ensures that the system can handle any number of devices,
or no device at all. To accommodate this, an additional reference
is taken for each attached device. Once the configuration is complete,
the context reference used for configuration is released.

Signed-off-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
Change-Id: I5e44867bfe3ed64f98ead61551568c0d90d185a0
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/22762


Community-CI: Mellanox Build Bot
Reviewed-by: default avatarJim Harris <jim.harris@samsung.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
parent 9da18248
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ kernel_idxd_probe(void *cb_ctx, spdk_idxd_attach_cb attach_cb, spdk_idxd_probe_c
	struct accfg_ctx *ctx;
	struct accfg_device *device;

	/* Create a configuration context, incrementing the reference count. */
	rc = accfg_new(&ctx);
	if (rc < 0) {
		SPDK_ERRLOG("Unable to allocate accel-config context\n");
@@ -104,6 +105,9 @@ kernel_idxd_probe(void *cb_ctx, spdk_idxd_attach_cb attach_cb, spdk_idxd_probe_c
		kernel_idxd->idxd.version = accfg_device_get_version(device);
		kernel_idxd->idxd.pasid_enabled = pasid_enabled;

		/* Increment configuration context reference for each device. */
		kernel_idxd->ctx = accfg_ref(kernel_idxd->ctx);

		accfg_wq_foreach(device, wq) {
			enum accfg_wq_state wstate;
			enum accfg_wq_mode mode;
@@ -173,6 +177,9 @@ kernel_idxd_probe(void *cb_ctx, spdk_idxd_attach_cb attach_cb, spdk_idxd_probe_c
		}
	}

	/* Release the reference used for configuration. */
	accfg_unref(ctx);

	return 0;
}