Skip to content

Commit

Permalink
drm/xe/uapi: Return correct error code for xe_wait_user_fence_ioctl
Browse files Browse the repository at this point in the history
Currently xe_wait_user_fence_ioctl is not checking exec_queue state
and blocking until timeout, with this patch wakeup the blocking wait
if exec_queue reset happen and returning proper error code

Signed-off-by: Bommu Krishnaiah <krishnaiah.bommu@intel.com>
Cc: Oak Zeng <oak.zeng@intel.com>
Cc: Kempczynski Zbigniew <Zbigniew.Kempczynski@intel.com>
Cc: Matthew Brost <matthew.brost@intel.com>
Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
Reviewed-by: Matthew Brost <matthew.brost@intel.com>
Acked-by: José Roberto de Souza <jose.souza@intel.com>
Acked-by: Mateusz Naklicki <mateusz.naklicki@intel.com>
Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
  • Loading branch information
Bommu Krishnaiah authored and Rodrigo Vivi committed Dec 21, 2023
1 parent 9212da0 commit e670f0b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 6 deletions.
2 changes: 2 additions & 0 deletions drivers/gpu/drm/xe/xe_exec_queue_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ struct xe_exec_queue_ops {
* signalled when this function is called.
*/
void (*resume)(struct xe_exec_queue *q);
/** @reset_status: check exec queue reset status */
bool (*reset_status)(struct xe_exec_queue *q);
};

#endif
7 changes: 7 additions & 0 deletions drivers/gpu/drm/xe/xe_execlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,12 @@ static void execlist_exec_queue_resume(struct xe_exec_queue *q)
/* NIY */
}

static bool execlist_exec_queue_reset_status(struct xe_exec_queue *q)
{
/* NIY */
return false;
}

static const struct xe_exec_queue_ops execlist_exec_queue_ops = {
.init = execlist_exec_queue_init,
.kill = execlist_exec_queue_kill,
Expand All @@ -453,6 +459,7 @@ static const struct xe_exec_queue_ops execlist_exec_queue_ops = {
.suspend = execlist_exec_queue_suspend,
.suspend_wait = execlist_exec_queue_suspend_wait,
.resume = execlist_exec_queue_resume,
.reset_status = execlist_exec_queue_reset_status,
};

int xe_execlist_init(struct xe_gt *gt)
Expand Down
10 changes: 10 additions & 0 deletions drivers/gpu/drm/xe/xe_guc_submit.c
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,10 @@ static void simple_error_capture(struct xe_exec_queue *q)
static void xe_guc_exec_queue_trigger_cleanup(struct xe_exec_queue *q)
{
struct xe_guc *guc = exec_queue_to_guc(q);
struct xe_device *xe = guc_to_xe(guc);

/** to wakeup xe_wait_user_fence ioctl if exec queue is reset */
wake_up_all(&xe->ufence_wq);

if (xe_exec_queue_is_lr(q))
queue_work(guc_to_gt(guc)->ordered_wq, &q->guc->lr_tdr);
Expand Down Expand Up @@ -1394,6 +1398,11 @@ static void guc_exec_queue_resume(struct xe_exec_queue *q)
guc_exec_queue_add_msg(q, msg, RESUME);
}

static bool guc_exec_queue_reset_status(struct xe_exec_queue *q)
{
return exec_queue_reset(q);
}

/*
* All of these functions are an abstraction layer which other parts of XE can
* use to trap into the GuC backend. All of these functions, aside from init,
Expand All @@ -1411,6 +1420,7 @@ static const struct xe_exec_queue_ops guc_exec_queue_ops = {
.suspend = guc_exec_queue_suspend,
.suspend_wait = guc_exec_queue_suspend_wait,
.resume = guc_exec_queue_resume,
.reset_status = guc_exec_queue_reset_status,
};

static void guc_exec_queue_stop(struct xe_guc *guc, struct xe_exec_queue *q)
Expand Down
30 changes: 24 additions & 6 deletions drivers/gpu/drm/xe/xe_wait_user_fence.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "xe_device.h"
#include "xe_gt.h"
#include "xe_macros.h"
#include "xe_exec_queue.h"

static int do_compare(u64 addr, u64 value, u64 mask, u16 op)
{
Expand Down Expand Up @@ -100,10 +101,12 @@ int xe_wait_user_fence_ioctl(struct drm_device *dev, void *data,
struct drm_file *file)
{
struct xe_device *xe = to_xe_device(dev);
struct xe_file *xef = to_xe_file(file);
DEFINE_WAIT_FUNC(w_wait, woken_wake_function);
struct drm_xe_wait_user_fence *args = data;
struct xe_exec_queue *q = NULL;
u64 addr = args->addr;
int err;
int err = 0;
long timeout;
ktime_t start;

Expand All @@ -121,6 +124,12 @@ int xe_wait_user_fence_ioctl(struct drm_device *dev, void *data,
if (XE_IOCTL_DBG(xe, addr & 0x7))
return -EINVAL;

if (args->exec_queue_id) {
q = xe_exec_queue_lookup(xef, args->exec_queue_id);
if (XE_IOCTL_DBG(xe, !q))
return -ENOENT;
}

timeout = to_jiffies_timeout(xe, args);

start = ktime_get();
Expand All @@ -136,6 +145,14 @@ int xe_wait_user_fence_ioctl(struct drm_device *dev, void *data,
break;
}

if (q) {
if (q->ops->reset_status(q)) {
drm_info(&xe->drm, "exec gueue reset detected\n");
err = -EIO;
break;
}
}

if (!timeout) {
err = -ETIME;
break;
Expand All @@ -151,10 +168,11 @@ int xe_wait_user_fence_ioctl(struct drm_device *dev, void *data,
args->timeout = 0;
}

if (XE_IOCTL_DBG(xe, err < 0))
return err;
else if (XE_IOCTL_DBG(xe, !timeout))
return -ETIME;
if (!timeout && !(err < 0))
err = -ETIME;

if (q)
xe_exec_queue_put(q);

return 0;
return err;
}

0 comments on commit e670f0b

Please sign in to comment.