Skip to content

Commit dd3e840

Browse files
mbrost05rodrigovivi
authored andcommitted
drm/xe: Drop HW fence pointer to HW fence ctx
The HW fence ctx objects are not ref counted rather tied to the life of an LRC object. HW fences reference the HW fence ctx, HW fences can outlive LRCs thus resulting in UAF. Drop the HW fence pointer to HW fence ctx rather just store what is needed directly in HW fence. v2: - Fix typo in commit (Ashutosh) - Use snprintf (Ashutosh) Fixes: dd08ebf ("drm/xe: Introduce a new DRM driver for Intel GPUs") Signed-off-by: Matthew Brost <[email protected]> Reviewed-by: Ashutosh Dixit <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] (cherry picked from commit 60db6f5) Signed-off-by: Rodrigo Vivi <[email protected]>
1 parent a6f7835 commit dd3e840

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

drivers/gpu/drm/xe/xe_hw_fence.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,20 +148,20 @@ static const char *xe_hw_fence_get_driver_name(struct dma_fence *dma_fence)
148148
{
149149
struct xe_hw_fence *fence = to_xe_hw_fence(dma_fence);
150150

151-
return dev_name(gt_to_xe(fence->ctx->gt)->drm.dev);
151+
return dev_name(fence->xe->drm.dev);
152152
}
153153

154154
static const char *xe_hw_fence_get_timeline_name(struct dma_fence *dma_fence)
155155
{
156156
struct xe_hw_fence *fence = to_xe_hw_fence(dma_fence);
157157

158-
return fence->ctx->name;
158+
return fence->name;
159159
}
160160

161161
static bool xe_hw_fence_signaled(struct dma_fence *dma_fence)
162162
{
163163
struct xe_hw_fence *fence = to_xe_hw_fence(dma_fence);
164-
struct xe_device *xe = gt_to_xe(fence->ctx->gt);
164+
struct xe_device *xe = fence->xe;
165165
u32 seqno = xe_map_rd(xe, &fence->seqno_map, 0, u32);
166166

167167
return dma_fence->error ||
@@ -253,7 +253,8 @@ void xe_hw_fence_init(struct dma_fence *fence, struct xe_hw_fence_ctx *ctx,
253253
struct xe_hw_fence *hw_fence =
254254
container_of(fence, typeof(*hw_fence), dma);
255255

256-
hw_fence->ctx = ctx;
256+
hw_fence->xe = gt_to_xe(ctx->gt);
257+
snprintf(hw_fence->name, sizeof(hw_fence->name), "%s", ctx->name);
257258
hw_fence->seqno_map = seqno_map;
258259
INIT_LIST_HEAD(&hw_fence->irq_link);
259260

drivers/gpu/drm/xe/xe_hw_fence_types.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/list.h>
1313
#include <linux/spinlock.h>
1414

15+
struct xe_device;
1516
struct xe_gt;
1617

1718
/**
@@ -61,8 +62,10 @@ struct xe_hw_fence_ctx {
6162
struct xe_hw_fence {
6263
/** @dma: base dma fence for hardware fence context */
6364
struct dma_fence dma;
64-
/** @ctx: hardware fence context */
65-
struct xe_hw_fence_ctx *ctx;
65+
/** @xe: Xe device for hw fence driver name */
66+
struct xe_device *xe;
67+
/** @name: name of hardware fence context */
68+
char name[MAX_FENCE_NAME_LEN];
6669
/** @seqno_map: I/O map for seqno */
6770
struct iosys_map seqno_map;
6871
/** @irq_link: Link in struct xe_hw_fence_irq.pending */

drivers/gpu/drm/xe/xe_trace.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ DECLARE_EVENT_CLASS(xe_hw_fence,
309309
TP_ARGS(fence),
310310

311311
TP_STRUCT__entry(
312-
__string(dev, __dev_name_gt(fence->ctx->gt))
312+
__string(dev, __dev_name_xe(fence->xe))
313313
__field(u64, ctx)
314314
__field(u32, seqno)
315315
__field(struct xe_hw_fence *, fence)

0 commit comments

Comments
 (0)