Skip to contentSkip to conversation

accel/ivpu: Fixes for 6.3

PATCH In review Stanislaw Gruszka 3 participants 12 messages Feb 2, 2023 – Feb 6, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover accel/ivpu: Fixes for 6.3

Few fixes intended for 6.3.

Andrzej Kacprowski (2):
accel/ivpu: Fix FW API data alignment issues accel/ivpu: Send VPU_JSM_MSG_CONTEXT_DELETE when deleting context

Stanislaw Gruszka (2):
accel/ivpu: Set dma max_segment_size
accel/ivpu: Fix old dma_buf api usage

 drivers/accel/ivpu/ivpu_drv.c     |  2 +
 drivers/accel/ivpu/ivpu_fw.c      | 37 +++++++++++------
 drivers/accel/ivpu/ivpu_gem.c     |  8 +---
 drivers/accel/ivpu/ivpu_job.c     |  5 ++-
 drivers/accel/ivpu/ivpu_jsm_msg.c | 11 +++++
 drivers/accel/ivpu/ivpu_jsm_msg.h |  2 +-
 drivers/accel/ivpu/vpu_jsm_api.h  | 67 ++++++++++++++++++-------------
 7 files changed, 81 insertions(+), 51 deletions(-)
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/4 accel/ivpu: Fix FW API data alignment issues

From: Andrzej Kacprowski <[email protected]>

FW API structures have been updated to fix misaligned structure members.

Also changed JSM message header format to account for future improvements.

Added explicit check for minimum supported JSM API version.

---
 drivers/accel/ivpu/ivpu_fw.c     | 37 +++++++++++-------
 drivers/accel/ivpu/ivpu_job.c    |  5 ++-
 drivers/accel/ivpu/vpu_jsm_api.h | 67 ++++++++++++++++++--------------
 3 files changed, 65 insertions(+), 44 deletions(-)
drivers/accel/ivpu/ivpu_fw.c +24 -13
index b463c24adb70..f58951a0d81b 100644
@@ -32,10 +32,11 @@
 
 #define ADDR_TO_L2_CACHE_CFG(addr) ((addr) >> 31)
 
-#define IVPU_FW_CHECK_API(vdev, fw_hdr, name) ivpu_fw_check_api(vdev, fw_hdr, #name, \
-								  VPU_##name##_API_VER_INDEX, \
-								  VPU_##name##_API_VER_MAJOR, \
-								  VPU_##name##_API_VER_MINOR)
+#define IVPU_FW_CHECK_API(vdev, fw_hdr, name, min_major) \
+	ivpu_fw_check_api(vdev, fw_hdr, #name, \
+			  VPU_##name##_API_VER_INDEX, \
+			  VPU_##name##_API_VER_MAJOR, \
+			  VPU_##name##_API_VER_MINOR, min_major)
 
 static char *ivpu_firmware;
 module_param_named_unsafe(firmware, ivpu_firmware, charp, 0644);
@@ -63,19 +64,27 @@ static int ivpu_fw_request(struct ivpu_device *vdev)
 	return ret;
 }
 
-static void
+static int
 ivpu_fw_check_api(struct ivpu_device *vdev, const struct vpu_firmware_header *fw_hdr,
-		  const char *str, int index, u16 expected_major, u16 expected_minor)
+		  const char *str, int index, u16 expected_major, u16 expected_minor,
+		  u16 min_major)
 {
 	u16 major = (u16)(fw_hdr->api_version[index] >> 16);
 	u16 minor = (u16)(fw_hdr->api_version[index]);
 
+	if (major < min_major) {
+		ivpu_err(vdev, "Incompatible FW %s API version: %d.%d, required %d.0 or later\n",
+			 str, major, minor, min_major);
+		return -EINVAL;
+	}
 	if (major != expected_major) {
-		ivpu_warn(vdev, "Incompatible FW %s API version: %d.%d (expected %d.%d)\n",
+		ivpu_warn(vdev, "Major FW %s API version different: %d.%d (expected %d.%d)\n",
 			  str, major, minor, expected_major, expected_minor);
 	}
 	ivpu_dbg(vdev, FW_BOOT, "FW %s API version: %d.%d (expected %d.%d)\n",
 		 str, major, minor, expected_major, expected_minor);
+
+	return 0;
 }
 
 static int ivpu_fw_parse(struct ivpu_device *vdev)
@@ -131,6 +140,14 @@ static int ivpu_fw_parse(struct ivpu_device *vdev)
 		ivpu_err(vdev, "Invalid entry point: 0x%llx\n", fw_hdr->entry_point);
 		return -EINVAL;
 	}
+	ivpu_dbg(vdev, FW_BOOT, "Header version: 0x%x, format 0x%x\n",
+		 fw_hdr->header_version, fw_hdr->image_format);
+	ivpu_dbg(vdev, FW_BOOT, "FW version: %s\n", (char *)fw_hdr + VPU_FW_HEADER_SIZE);
+
+	if (IVPU_FW_CHECK_API(vdev, fw_hdr, BOOT, 3))
+		return -EINVAL;
+	if (IVPU_FW_CHECK_API(vdev, fw_hdr, JSM, 3))
+		return -EINVAL;
 
 	fw->runtime_addr = runtime_addr;
 	fw->runtime_size = runtime_size;
@@ -141,16 +158,10 @@ static int ivpu_fw_parse(struct ivpu_device *vdev)
 	fw->cold_boot_entry_point = fw_hdr->entry_point;
 	fw->entry_point = fw->cold_boot_entry_point;
 
-	ivpu_dbg(vdev, FW_BOOT, "Header version: 0x%x, format 0x%x\n",
-		 fw_hdr->header_version, fw_hdr->image_format);
 	ivpu_dbg(vdev, FW_BOOT, "Size: file %lu image %u runtime %u shavenn %u\n",
 		 fw->file->size, fw->image_size, fw->runtime_size, fw->shave_nn_size);
 	ivpu_dbg(vdev, FW_BOOT, "Address: runtime 0x%llx, load 0x%llx, entry point 0x%llx\n",
 		 fw->runtime_addr, image_load_addr, fw->entry_point);
-	ivpu_dbg(vdev, FW_BOOT, "FW version: %s\n", (char *)fw_hdr + VPU_FW_HEADER_SIZE);
-
-	IVPU_FW_CHECK_API(vdev, fw_hdr, BOOT);
-	IVPU_FW_CHECK_API(vdev, fw_hdr, JSM);
 
 	return 0;
 }
drivers/accel/ivpu/ivpu_job.c +3 -2
index 3276bd9107b4..94068aedf97c 100644
@@ -400,8 +400,9 @@ static int ivpu_direct_job_submission(struct ivpu_job *job)
 	if (ret)
 		goto err_xa_erase;
 
-	ivpu_dbg(vdev, JOB, "Job submitted: id %3u ctx %2d engine %d next %d\n",
-		 job->job_id, file_priv->ctx.id, job->engine_idx, cmdq->jobq->header.tail);
+	ivpu_dbg(vdev, JOB, "Job submitted: id %3u addr 0x%llx ctx %2d engine %d next %d\n",
+		 job->job_id, job->cmd_buf_vpu_addr, file_priv->ctx.id,
+		 job->engine_idx, cmdq->jobq->header.tail);
 
 	if (ivpu_test_mode == IVPU_TEST_MODE_NULL_HW) {
 		ivpu_job_done(vdev, job->job_id, VPU_JSM_STATUS_SUCCESS);
drivers/accel/ivpu/vpu_jsm_api.h +38 -29

244 lines not on this page · raw message

Signature · 1 line
2.25.1
#2 lore raw

Re: [PATCH 1/4] accel/ivpu: Fix FW API data alignment issues

Quoted 17 lines · Stanislaw Gruszka

From: Andrzej Kacprowski <[email protected]>

FW API structures have been updated to fix misaligned structure members.

Also changed JSM message header format to account for future improvements.

Added explicit check for minimum supported JSM API version.

/*
* Job format.

drivers/accel/ivpu/vpu_jsm_api.h struct vpu_job_queue_entry { · line 122

Quoted 5 lines
drivers/accel/ivpu/vpu_jsm_api.h +1 -1
@@ -119,7 +119,7 @@ struct vpu_job_queue_entry {
  	u64 root_page_table_update_counter; /**< Page tables update events counter */
  	u64 preemption_buffer_address; /**< Address of the preemption buffer to use for this job */
  	u64 preemption_buffer_size; /**< Size of the preemption buffer to use for this job */
-	u8 reserved[VPU_JOB_RESERVED_BYTES];
+	u8 reserved_0[VPU_JOB_RESERVED_BYTES];

This seems spurious, just adding "_0" to the name. Seems like the majority of the changes are like this (although you have a _1 at the very end). Are you anticipating adding additional reserved fields in the near future?

#3 lore raw

Re: [PATCH 1/4] accel/ivpu: Fix FW API data alignment issues

Hi,

Quoted 15 lines · Jeffrey Hugo
Quoted 12 lines · Stanislaw Gruszka

From: Andrzej Kacprowski <[email protected]>

FW API structures have been updated to fix misaligned structure members.

Also changed JSM message header format to account for future improvements.

Added explicit check for minimum supported JSM API version.

Quoted 11 lines
Quoted 8 lines

  /*
   * Job format.

(quoted diff) +0 -0
@@ -119,7 +119,7 @@ struct vpu_job_queue_entry {

      u64 root_page_table_update_counter; /**< Page tables update events counter */ u64 preemption_buffer_address; /**< Address of the preemption buffer to use for this job */ u64 preemption_buffer_size; /**< Size of the preemption buffer to use for this job */ -    u8 reserved[VPU_JOB_RESERVED_BYTES];
+    u8 reserved_0[VPU_JOB_RESERVED_BYTES];

This seems spurious, just adding "_0" to the name.  Seems like the majority of the changes are like this (although you have a _1 at the very end).  Are you anticipating adding additional reserved fields in the near future?

These headers are our HW/FW interface and we (as a KMD team) do not have full control over them.
The FW team has its own conventions which could probably treated the same as some auto generated HW interface headers accepted as-is. We could modify them on import but it would be harder then maintain them.
If this doesn't bug you too much I would prefer to leave them as-is, OK?

Regards,
Jacek

Reviewed-by
#4 lore raw

Re: [PATCH 1/4] accel/ivpu: Fix FW API data alignment issues

Quoted 30 lines · Jacek Lawrynowicz

Hi,

Quoted 15 lines · Jeffrey Hugo
Quoted 12 lines · Stanislaw Gruszka

From: Andrzej Kacprowski <[email protected]>

FW API structures have been updated to fix misaligned structure members.

Also changed JSM message header format to account for future improvements.

Added explicit check for minimum supported JSM API version.

Quoted 11 lines

drivers/accel/ivpu/vpu_jsm_api.h struct vpu_job_queue_entry { · line 122

Quoted 8 lines

  /*
   * Job format.

drivers/accel/ivpu/vpu_jsm_api.h +1 -1
@@ -119,7 +119,7 @@ struct vpu_job_queue_entry {
       u64 root_page_table_update_counter; /**< Page tables update events counter */
       u64 preemption_buffer_address; /**< Address of the preemption buffer to use for this job */
       u64 preemption_buffer_size; /**< Size of the preemption buffer to use for this job */
-    u8 reserved[VPU_JOB_RESERVED_BYTES];
+    u8 reserved_0[VPU_JOB_RESERVED_BYTES];

This seems spurious, just adding "_0" to the name.  Seems like the majority of the changes are like this (although you have a _1 at the very end).  Are you anticipating adding additional reserved fields in the near future?

Quoted 4 lines

These headers are our HW/FW interface and we (as a KMD team) do not have full control over them.
The FW team has its own conventions which could probably treated the same as some auto generated HW interface headers accepted as-is. We could modify them on import but it would be harder then maintain them.
If this doesn't bug you too much I would prefer to leave them as-is, OK?

Ah, these are pulled direct from the FW. Fair enough.

#5 lore raw

PATCH 2/4 accel/ivpu: Send VPU_JSM_MSG_CONTEXT_DELETE when deleting context

In reply to Stanislaw Gruszka

From: Andrzej Kacprowski <[email protected]>

The VPU_JSM_MSG_CONTEXT_DELETE will remove any resources associated with the SSID, that included any blobs create by the user space application.

The command can also remove doorbell registrations, but since this does not work in HW scheduling case, we do not depend on this capability and unregister the doorbells explicitly.

---
 drivers/accel/ivpu/ivpu_drv.c     |  1 +
 drivers/accel/ivpu/ivpu_jsm_msg.c | 11 +++++++++++
 drivers/accel/ivpu/ivpu_jsm_msg.h |  2 +-
 3 files changed, 13 insertions(+), 1 deletion(-)
drivers/accel/ivpu/ivpu_drv.c +1 -0
index a29e8ee0dce6..70c104851c6d 100644
@@ -90,6 +90,7 @@ static void file_priv_release(struct kref *ref)
 
 	ivpu_cmdq_release_all(file_priv);
 	ivpu_bo_remove_all_bos_from_context(&file_priv->ctx);
+	ivpu_jsm_context_release(vdev, file_priv->ctx.id);
 	ivpu_mmu_user_context_fini(vdev, &file_priv->ctx);
 	drm_WARN_ON(&vdev->drm, xa_erase_irq(&vdev->context_xa, file_priv->ctx.id) != file_priv);
 	mutex_destroy(&file_priv->lock);
drivers/accel/ivpu/ivpu_jsm_msg.c +11 -0
index af77dafac97e..831bfd2b2d39 100644
@@ -167,3 +167,14 @@ int ivpu_jsm_trace_set_config(struct ivpu_device *vdev, u32 trace_level, u32 tra
 
 	return ret;
 }
+
+int ivpu_jsm_context_release(struct ivpu_device *vdev, u32 host_ssid)
+{
+	struct vpu_jsm_msg req = { .type = VPU_JSM_MSG_SSID_RELEASE };
+	struct vpu_jsm_msg resp;
+
+	req.payload.ssid_release.host_ssid = host_ssid;
+
+	return ivpu_ipc_send_receive(vdev, &req, VPU_JSM_MSG_SSID_RELEASE_DONE, &resp,
+				     VPU_IPC_CHAN_ASYNC_CMD, vdev->timeout.jsm);
+}
drivers/accel/ivpu/ivpu_jsm_msg.h +1 -1
index 1a3e2e2740bd..ab50d7b017c1 100644
@@ -19,5 +19,5 @@ int ivpu_jsm_trace_get_capability(struct ivpu_device *vdev, u32 *trace_destinati
 				  u64 *trace_hw_component_mask);
 int ivpu_jsm_trace_set_config(struct ivpu_device *vdev, u32 trace_level, u32 trace_destination_mask,
 			      u64 trace_hw_component_mask);
-
+int ivpu_jsm_context_release(struct ivpu_device *vdev, u32 host_ssid);
 #endif
Signature · 1 line
2.25.1
Reviewed-by on v1 2/4
#6 lore raw

Re: [PATCH 2/4] accel/ivpu: Send VPU_JSM_MSG_CONTEXT_DELETE when deleting context

Quoted 6 lines · Stanislaw Gruszka

From: Andrzej Kacprowski <[email protected]>

The VPU_JSM_MSG_CONTEXT_DELETE will remove any resources associated with the SSID, that included any blobs create by the user space application.

Quoted 6 lines

The command can also remove doorbell registrations, but since this does not work in HW scheduling case, we do not depend on this capability and unregister the doorbells explicitly.

#7 lore raw

PATCH 3/4 accel/ivpu: Set dma max_segment_size

In reply to Stanislaw Gruszka

Avoid below spurious warning:

[  264.844029] DMA-API: intel_vpu 0000:00:0b.0: mapping sg segment longer than device claims to support [len=143360] [max=65536]
[  264.844038] WARNING: CPU: 0 PID: 1254 at kernel/dma/debug.c:1160 debug_dma_map_sg+0x6ca/0xb70
---
 drivers/accel/ivpu/ivpu_drv.c | 1 +
 1 file changed, 1 insertion(+)
drivers/accel/ivpu/ivpu_drv.c +1 -0
index 70c104851c6d..231f29bb5025 100644
@@ -428,6 +428,7 @@ static int ivpu_pci_init(struct ivpu_device *vdev)
 		ivpu_err(vdev, "Failed to set DMA mask: %d\n", ret);
 		return ret;
 	}
+	dma_set_max_seg_size(vdev->drm.dev, UINT_MAX);
 
 	/* Clear any pending errors */
 	pcie_capability_clear_word(pdev, PCI_EXP_DEVSTA, 0x3f);
Signature · 1 line
2.25.1
Reviewed-by on v1 3/4
#8 lore raw

Re: [PATCH 3/4] accel/ivpu: Set dma max_segment_size

Quoted 6 lines · Stanislaw Gruszka

Avoid below spurious warning:

[  264.844029] DMA-API: intel_vpu 0000:00:0b.0: mapping sg segment longer than device claims to support [len=143360] [max=65536]
[  264.844038] WARNING: CPU: 0 PID: 1254 at kernel/dma/debug.c:1160 debug_dma_map_sg+0x6ca/0xb70
#9 lore raw

PATCH 4/4 accel/ivpu: Fix old dma_buf api usage

In reply to Stanislaw Gruszka

Update according to new dma-buf locking scheme.

Remove redundant WARN_ON()'s, dma_buf functions internally have the same warnings already.

---
 drivers/accel/ivpu/ivpu_gem.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/accel/ivpu/ivpu_gem.c +2 -6
index d1f923971b4c..01d47d3bad5b 100644
@@ -42,9 +42,7 @@ static int prime_map_pages_locked(struct ivpu_bo *bo)
 	struct ivpu_device *vdev = ivpu_bo_to_vdev(bo);
 	struct sg_table *sgt;
 
-	WARN_ON(!bo->base.import_attach);
-
-	sgt = dma_buf_map_attachment(bo->base.import_attach, DMA_BIDIRECTIONAL);
+	sgt = dma_buf_map_attachment_unlocked(bo->base.import_attach, DMA_BIDIRECTIONAL);
 	if (IS_ERR(sgt)) {
 		ivpu_err(vdev, "Failed to map attachment: %ld\n", PTR_ERR(sgt));
 		return PTR_ERR(sgt);
@@ -56,9 +54,7 @@ static int prime_map_pages_locked(struct ivpu_bo *bo)
 
 static void prime_unmap_pages_locked(struct ivpu_bo *bo)
 {
-	WARN_ON(!bo->base.import_attach);
-
-	dma_buf_unmap_attachment(bo->base.import_attach, bo->sgt, DMA_BIDIRECTIONAL);
+	dma_buf_unmap_attachment_unlocked(bo->base.import_attach, bo->sgt, DMA_BIDIRECTIONAL);
 	bo->sgt = NULL;
 }
 
Signature · 1 line
2.25.1
#11 lore raw
In reply to Stanislaw Gruszka

Patchset applied to drm-misc-next and cherry-picked to drm-misc-next-fixes. Thanks.

Quoted 19 lines · Stanislaw Gruszka

Few fixes intended for 6.3.

Andrzej Kacprowski (2):
accel/ivpu: Fix FW API data alignment issues accel/ivpu: Send VPU_JSM_MSG_CONTEXT_DELETE when deleting context

Stanislaw Gruszka (2):
accel/ivpu: Set dma max_segment_size
accel/ivpu: Fix old dma_buf api usage

 drivers/accel/ivpu/ivpu_drv.c     |  2 +
 drivers/accel/ivpu/ivpu_fw.c      | 37 +++++++++++------
 drivers/accel/ivpu/ivpu_gem.c     |  8 +---
 drivers/accel/ivpu/ivpu_job.c     |  5 ++-
 drivers/accel/ivpu/ivpu_jsm_msg.c | 11 +++++
 drivers/accel/ivpu/ivpu_jsm_msg.h |  2 +-
 drivers/accel/ivpu/vpu_jsm_api.h  | 67 ++++++++++++++++++-------------
 7 files changed, 81 insertions(+), 51 deletions(-)