Skip to content

Commit f8e170a

Browse files
committed
Merge tag 'drm-xe-fixes-2024-08-15' of https://gitlab.freedesktop.org/drm/xe/kernel into drm-fixes
- Validate user fence during creation (Brost) - Fix use after free when client stats are captured (Umesh) - SRIOV fixes (Michal) - Runtime PM fixes (Brost) Signed-off-by: Dave Airlie <[email protected]> From: Rodrigo Vivi <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
2 parents 75eac7e + f002702 commit f8e170a

16 files changed

+247
-160
lines changed

drivers/gpu/drm/xe/xe_device.c

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,55 @@ static int xe_file_open(struct drm_device *dev, struct drm_file *file)
8787
spin_unlock(&xe->clients.lock);
8888

8989
file->driver_priv = xef;
90+
kref_init(&xef->refcount);
91+
9092
return 0;
9193
}
9294

95+
static void xe_file_destroy(struct kref *ref)
96+
{
97+
struct xe_file *xef = container_of(ref, struct xe_file, refcount);
98+
struct xe_device *xe = xef->xe;
99+
100+
xa_destroy(&xef->exec_queue.xa);
101+
mutex_destroy(&xef->exec_queue.lock);
102+
xa_destroy(&xef->vm.xa);
103+
mutex_destroy(&xef->vm.lock);
104+
105+
spin_lock(&xe->clients.lock);
106+
xe->clients.count--;
107+
spin_unlock(&xe->clients.lock);
108+
109+
xe_drm_client_put(xef->client);
110+
kfree(xef);
111+
}
112+
113+
/**
114+
* xe_file_get() - Take a reference to the xe file object
115+
* @xef: Pointer to the xe file
116+
*
117+
* Anyone with a pointer to xef must take a reference to the xe file
118+
* object using this call.
119+
*
120+
* Return: xe file pointer
121+
*/
122+
struct xe_file *xe_file_get(struct xe_file *xef)
123+
{
124+
kref_get(&xef->refcount);
125+
return xef;
126+
}
127+
128+
/**
129+
* xe_file_put() - Drop a reference to the xe file object
130+
* @xef: Pointer to the xe file
131+
*
132+
* Used to drop reference to the xef object
133+
*/
134+
void xe_file_put(struct xe_file *xef)
135+
{
136+
kref_put(&xef->refcount, xe_file_destroy);
137+
}
138+
93139
static void xe_file_close(struct drm_device *dev, struct drm_file *file)
94140
{
95141
struct xe_device *xe = to_xe_device(dev);
@@ -98,6 +144,8 @@ static void xe_file_close(struct drm_device *dev, struct drm_file *file)
98144
struct xe_exec_queue *q;
99145
unsigned long idx;
100146

147+
xe_pm_runtime_get(xe);
148+
101149
/*
102150
* No need for exec_queue.lock here as there is no contention for it
103151
* when FD is closing as IOCTLs presumably can't be modifying the
@@ -108,21 +156,14 @@ static void xe_file_close(struct drm_device *dev, struct drm_file *file)
108156
xe_exec_queue_kill(q);
109157
xe_exec_queue_put(q);
110158
}
111-
xa_destroy(&xef->exec_queue.xa);
112-
mutex_destroy(&xef->exec_queue.lock);
113159
mutex_lock(&xef->vm.lock);
114160
xa_for_each(&xef->vm.xa, idx, vm)
115161
xe_vm_close_and_put(vm);
116162
mutex_unlock(&xef->vm.lock);
117-
xa_destroy(&xef->vm.xa);
118-
mutex_destroy(&xef->vm.lock);
119163

120-
spin_lock(&xe->clients.lock);
121-
xe->clients.count--;
122-
spin_unlock(&xe->clients.lock);
164+
xe_file_put(xef);
123165

124-
xe_drm_client_put(xef->client);
125-
kfree(xef);
166+
xe_pm_runtime_put(xe);
126167
}
127168

128169
static const struct drm_ioctl_desc xe_ioctls[] = {

drivers/gpu/drm/xe/xe_device.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,7 @@ static inline bool xe_device_wedged(struct xe_device *xe)
170170

171171
void xe_device_declare_wedged(struct xe_device *xe);
172172

173+
struct xe_file *xe_file_get(struct xe_file *xef);
174+
void xe_file_put(struct xe_file *xef);
175+
173176
#endif

drivers/gpu/drm/xe/xe_device_types.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,9 @@ struct xe_file {
566566

567567
/** @client: drm client */
568568
struct xe_drm_client *client;
569+
570+
/** @refcount: ref count of this xe file */
571+
struct kref refcount;
569572
};
570573

571574
#endif

drivers/gpu/drm/xe/xe_drm_client.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,11 +251,8 @@ static void show_run_ticks(struct drm_printer *p, struct drm_file *file)
251251

252252
/* Accumulate all the exec queues from this client */
253253
mutex_lock(&xef->exec_queue.lock);
254-
xa_for_each(&xef->exec_queue.xa, i, q) {
254+
xa_for_each(&xef->exec_queue.xa, i, q)
255255
xe_exec_queue_update_run_ticks(q);
256-
xef->run_ticks[q->class] += q->run_ticks - q->old_run_ticks;
257-
q->old_run_ticks = q->run_ticks;
258-
}
259256
mutex_unlock(&xef->exec_queue.lock);
260257

261258
/* Get the total GPU cycles */

drivers/gpu/drm/xe/xe_exec_queue.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ static void __xe_exec_queue_free(struct xe_exec_queue *q)
3737
{
3838
if (q->vm)
3939
xe_vm_put(q->vm);
40+
41+
if (q->xef)
42+
xe_file_put(q->xef);
43+
4044
kfree(q);
4145
}
4246

@@ -649,6 +653,7 @@ int xe_exec_queue_create_ioctl(struct drm_device *dev, void *data,
649653
goto kill_exec_queue;
650654

651655
args->exec_queue_id = id;
656+
q->xef = xe_file_get(xef);
652657

653658
return 0;
654659

@@ -762,6 +767,7 @@ bool xe_exec_queue_is_idle(struct xe_exec_queue *q)
762767
*/
763768
void xe_exec_queue_update_run_ticks(struct xe_exec_queue *q)
764769
{
770+
struct xe_file *xef;
765771
struct xe_lrc *lrc;
766772
u32 old_ts, new_ts;
767773

@@ -773,6 +779,8 @@ void xe_exec_queue_update_run_ticks(struct xe_exec_queue *q)
773779
if (!q->vm || !q->vm->xef)
774780
return;
775781

782+
xef = q->vm->xef;
783+
776784
/*
777785
* Only sample the first LRC. For parallel submission, all of them are
778786
* scheduled together and we compensate that below by multiplying by
@@ -783,7 +791,7 @@ void xe_exec_queue_update_run_ticks(struct xe_exec_queue *q)
783791
*/
784792
lrc = q->lrc[0];
785793
new_ts = xe_lrc_update_timestamp(lrc, &old_ts);
786-
q->run_ticks += (new_ts - old_ts) * q->width;
794+
xef->run_ticks[q->class] += (new_ts - old_ts) * q->width;
787795
}
788796

789797
void xe_exec_queue_kill(struct xe_exec_queue *q)

drivers/gpu/drm/xe/xe_exec_queue_types.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ enum xe_exec_queue_priority {
3838
* a kernel object.
3939
*/
4040
struct xe_exec_queue {
41+
/** @xef: Back pointer to xe file if this is user created exec queue */
42+
struct xe_file *xef;
43+
4144
/** @gt: graphics tile this exec queue can submit to */
4245
struct xe_gt *gt;
4346
/**
@@ -139,10 +142,6 @@ struct xe_exec_queue {
139142
* Protected by @vm's resv. Unused if @vm == NULL.
140143
*/
141144
u64 tlb_flush_seqno;
142-
/** @old_run_ticks: prior hw engine class run time in ticks for this exec queue */
143-
u64 old_run_ticks;
144-
/** @run_ticks: hw engine class run time in ticks for this exec queue */
145-
u64 run_ticks;
146145
/** @lrc: logical ring context for this exec queue */
147146
struct xe_lrc *lrc[];
148147
};

drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1927,6 +1927,7 @@ static int pf_validate_vf_config(struct xe_gt *gt, unsigned int vfid)
19271927
{
19281928
struct xe_gt *primary_gt = gt_to_tile(gt)->primary_gt;
19291929
struct xe_device *xe = gt_to_xe(gt);
1930+
bool is_primary = !xe_gt_is_media_type(gt);
19301931
bool valid_ggtt, valid_ctxs, valid_dbs;
19311932
bool valid_any, valid_all;
19321933

@@ -1935,13 +1936,17 @@ static int pf_validate_vf_config(struct xe_gt *gt, unsigned int vfid)
19351936
valid_dbs = pf_get_vf_config_dbs(gt, vfid);
19361937

19371938
/* note that GuC doorbells are optional */
1938-
valid_any = valid_ggtt || valid_ctxs || valid_dbs;
1939-
valid_all = valid_ggtt && valid_ctxs;
1939+
valid_any = valid_ctxs || valid_dbs;
1940+
valid_all = valid_ctxs;
1941+
1942+
/* and GGTT/LMEM is configured on primary GT only */
1943+
valid_all = valid_all && valid_ggtt;
1944+
valid_any = valid_any || (valid_ggtt && is_primary);
19401945

19411946
if (IS_DGFX(xe)) {
19421947
bool valid_lmem = pf_get_vf_config_ggtt(primary_gt, vfid);
19431948

1944-
valid_any = valid_any || valid_lmem;
1949+
valid_any = valid_any || (valid_lmem && is_primary);
19451950
valid_all = valid_all && valid_lmem;
19461951
}
19471952

drivers/gpu/drm/xe/xe_gt_sriov_vf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,7 @@ static struct vf_runtime_reg *vf_lookup_reg(struct xe_gt *gt, u32 addr)
850850

851851
xe_gt_assert(gt, IS_SRIOV_VF(gt_to_xe(gt)));
852852

853-
return bsearch(&key, runtime->regs, runtime->regs_size, sizeof(key),
853+
return bsearch(&key, runtime->regs, runtime->num_regs, sizeof(key),
854854
vf_runtime_reg_cmp);
855855
}
856856

0 commit comments

Comments
 (0)