]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
accel/ivpu: Prevent recovery invocation during probe and resume
authorKarol Wachowski <karol.wachowski@intel.com>
Mon, 30 Sep 2024 19:53:13 +0000 (21:53 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 5 Dec 2024 12:53:14 +0000 (13:53 +0100)
[ Upstream commit 5eaa497411197c41b0813d61ba3fbd6267049082 ]

Refactor IPC send and receive functions to allow correct
handling of operations that should not trigger a recovery process.

Expose ivpu_send_receive_internal(), which is now utilized by the D0i3
entry, DCT initialization, and HWS initialization functions.
These functions have been modified to return error codes gracefully,
rather than initiating recovery.

The updated functions are invoked within ivpu_probe() and ivpu_resume(),
ensuring that any errors encountered during these stages result in a proper
teardown or shutdown sequence. The previous approach of triggering recovery
within these functions could lead to a race condition, potentially causing
undefined behavior and kernel crashes due to null pointer dereferences.

Fixes: 45e45362e095 ("accel/ivpu: Introduce ivpu_ipc_send_receive_active()")
Signed-off-by: Karol Wachowski <karol.wachowski@intel.com>
Reviewed-by: Jacek Lawrynowicz <jacek.lawrynowicz@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20240930195322.461209-23-jacek.lawrynowicz@linux.intel.com
Signed-off-by: Jacek Lawrynowicz <jacek.lawrynowicz@linux.intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/accel/ivpu/ivpu_ipc.c
drivers/accel/ivpu/ivpu_ipc.h
drivers/accel/ivpu/ivpu_jsm_msg.c

index 78b32a8232419eccf8fa50a931d1874f93d0dff2..29b723039a345988225e0b7bb3956bb26aec8a4d 100644 (file)
@@ -291,15 +291,16 @@ int ivpu_ipc_receive(struct ivpu_device *vdev, struct ivpu_ipc_consumer *cons,
        return ret;
 }
 
-static int
+int
 ivpu_ipc_send_receive_internal(struct ivpu_device *vdev, struct vpu_jsm_msg *req,
                               enum vpu_ipc_msg_type expected_resp_type,
-                              struct vpu_jsm_msg *resp, u32 channel,
-                              unsigned long timeout_ms)
+                              struct vpu_jsm_msg *resp, u32 channel, unsigned long timeout_ms)
 {
        struct ivpu_ipc_consumer cons;
        int ret;
 
+       drm_WARN_ON(&vdev->drm, pm_runtime_status_suspended(vdev->drm.dev));
+
        ivpu_ipc_consumer_add(vdev, &cons, channel, NULL);
 
        ret = ivpu_ipc_send(vdev, &cons, req);
@@ -325,19 +326,21 @@ consumer_del:
        return ret;
 }
 
-int ivpu_ipc_send_receive_active(struct ivpu_device *vdev, struct vpu_jsm_msg *req,
-                                enum vpu_ipc_msg_type expected_resp, struct vpu_jsm_msg *resp,
-                                u32 channel, unsigned long timeout_ms)
+int ivpu_ipc_send_receive(struct ivpu_device *vdev, struct vpu_jsm_msg *req,
+                         enum vpu_ipc_msg_type expected_resp, struct vpu_jsm_msg *resp,
+                         u32 channel, unsigned long timeout_ms)
 {
        struct vpu_jsm_msg hb_req = { .type = VPU_JSM_MSG_QUERY_ENGINE_HB };
        struct vpu_jsm_msg hb_resp;
        int ret, hb_ret;
 
-       drm_WARN_ON(&vdev->drm, pm_runtime_status_suspended(vdev->drm.dev));
+       ret = ivpu_rpm_get(vdev);
+       if (ret < 0)
+               return ret;
 
        ret = ivpu_ipc_send_receive_internal(vdev, req, expected_resp, resp, channel, timeout_ms);
        if (ret != -ETIMEDOUT)
-               return ret;
+               goto rpm_put;
 
        hb_ret = ivpu_ipc_send_receive_internal(vdev, &hb_req, VPU_JSM_MSG_QUERY_ENGINE_HB_DONE,
                                                &hb_resp, VPU_IPC_CHAN_ASYNC_CMD,
@@ -345,21 +348,7 @@ int ivpu_ipc_send_receive_active(struct ivpu_device *vdev, struct vpu_jsm_msg *r
        if (hb_ret == -ETIMEDOUT)
                ivpu_pm_trigger_recovery(vdev, "IPC timeout");
 
-       return ret;
-}
-
-int ivpu_ipc_send_receive(struct ivpu_device *vdev, struct vpu_jsm_msg *req,
-                         enum vpu_ipc_msg_type expected_resp, struct vpu_jsm_msg *resp,
-                         u32 channel, unsigned long timeout_ms)
-{
-       int ret;
-
-       ret = ivpu_rpm_get(vdev);
-       if (ret < 0)
-               return ret;
-
-       ret = ivpu_ipc_send_receive_active(vdev, req, expected_resp, resp, channel, timeout_ms);
-
+rpm_put:
        ivpu_rpm_put(vdev);
        return ret;
 }
index 4fe38141045ea370c40e86b22e682401abb18c2c..fb4de7fb8210ea7a1953c6f92dbebde6e676ef74 100644 (file)
@@ -101,10 +101,9 @@ int ivpu_ipc_send(struct ivpu_device *vdev, struct ivpu_ipc_consumer *cons,
 int ivpu_ipc_receive(struct ivpu_device *vdev, struct ivpu_ipc_consumer *cons,
                     struct ivpu_ipc_hdr *ipc_buf, struct vpu_jsm_msg *jsm_msg,
                     unsigned long timeout_ms);
-
-int ivpu_ipc_send_receive_active(struct ivpu_device *vdev, struct vpu_jsm_msg *req,
-                                enum vpu_ipc_msg_type expected_resp, struct vpu_jsm_msg *resp,
-                                u32 channel, unsigned long timeout_ms);
+int ivpu_ipc_send_receive_internal(struct ivpu_device *vdev, struct vpu_jsm_msg *req,
+                                  enum vpu_ipc_msg_type expected_resp_type,
+                                  struct vpu_jsm_msg *resp, u32 channel, unsigned long timeout_ms);
 int ivpu_ipc_send_receive(struct ivpu_device *vdev, struct vpu_jsm_msg *req,
                          enum vpu_ipc_msg_type expected_resp, struct vpu_jsm_msg *resp,
                          u32 channel, unsigned long timeout_ms);
index 46ef16c3c06910a43c7dd504e3955d6ca9ee33f0..88105963c1b2889e65980e2e23d2f10e6b7e0533 100644 (file)
@@ -270,9 +270,8 @@ int ivpu_jsm_pwr_d0i3_enter(struct ivpu_device *vdev)
 
        req.payload.pwr_d0i3_enter.send_response = 1;
 
-       ret = ivpu_ipc_send_receive_active(vdev, &req, VPU_JSM_MSG_PWR_D0I3_ENTER_DONE,
-                                          &resp, VPU_IPC_CHAN_GEN_CMD,
-                                          vdev->timeout.d0i3_entry_msg);
+       ret = ivpu_ipc_send_receive_internal(vdev, &req, VPU_JSM_MSG_PWR_D0I3_ENTER_DONE, &resp,
+                                            VPU_IPC_CHAN_GEN_CMD, vdev->timeout.d0i3_entry_msg);
        if (ret)
                return ret;
 
@@ -430,8 +429,8 @@ int ivpu_jsm_hws_setup_priority_bands(struct ivpu_device *vdev)
 
        req.payload.hws_priority_band_setup.normal_band_percentage = 10;
 
-       ret = ivpu_ipc_send_receive_active(vdev, &req, VPU_JSM_MSG_SET_PRIORITY_BAND_SETUP_RSP,
-                                          &resp, VPU_IPC_CHAN_ASYNC_CMD, vdev->timeout.jsm);
+       ret = ivpu_ipc_send_receive_internal(vdev, &req, VPU_JSM_MSG_SET_PRIORITY_BAND_SETUP_RSP,
+                                            &resp, VPU_IPC_CHAN_ASYNC_CMD, vdev->timeout.jsm);
        if (ret)
                ivpu_warn_ratelimited(vdev, "Failed to set priority bands: %d\n", ret);
 
@@ -544,9 +543,8 @@ int ivpu_jsm_dct_enable(struct ivpu_device *vdev, u32 active_us, u32 inactive_us
        req.payload.pwr_dct_control.dct_active_us = active_us;
        req.payload.pwr_dct_control.dct_inactive_us = inactive_us;
 
-       return ivpu_ipc_send_receive_active(vdev, &req, VPU_JSM_MSG_DCT_ENABLE_DONE,
-                                           &resp, VPU_IPC_CHAN_ASYNC_CMD,
-                                           vdev->timeout.jsm);
+       return ivpu_ipc_send_receive_internal(vdev, &req, VPU_JSM_MSG_DCT_ENABLE_DONE, &resp,
+                                             VPU_IPC_CHAN_ASYNC_CMD, vdev->timeout.jsm);
 }
 
 int ivpu_jsm_dct_disable(struct ivpu_device *vdev)
@@ -554,7 +552,6 @@ int ivpu_jsm_dct_disable(struct ivpu_device *vdev)
        struct vpu_jsm_msg req = { .type = VPU_JSM_MSG_DCT_DISABLE };
        struct vpu_jsm_msg resp;
 
-       return ivpu_ipc_send_receive_active(vdev, &req, VPU_JSM_MSG_DCT_DISABLE_DONE,
-                                           &resp, VPU_IPC_CHAN_ASYNC_CMD,
-                                           vdev->timeout.jsm);
+       return ivpu_ipc_send_receive_internal(vdev, &req, VPU_JSM_MSG_DCT_DISABLE_DONE, &resp,
+                                             VPU_IPC_CHAN_ASYNC_CMD, vdev->timeout.jsm);
 }