[Intel-xe] [PATCH 3/3] drm/xe/pvc: Avoid any races around ccs_mode update
Niranjana Vishwanathapura
niranjana.vishwanathapura at intel.com
Thu Nov 16 03:34:36 UTC 2023
Ensure that there are no drm clients when changing CCS mode.
Allow exec_queue creation only with enabled CCS engines.
Signed-off-by: Niranjana Vishwanathapura <niranjana.vishwanathapura at intel.com>
---
drivers/gpu/drm/xe/xe_device.c | 9 +++++++++
drivers/gpu/drm/xe/xe_device_types.h | 9 +++++++++
drivers/gpu/drm/xe/xe_gt_sysfs.c | 10 ++++++++++
3 files changed, 28 insertions(+)
diff --git a/drivers/gpu/drm/xe/xe_device.c b/drivers/gpu/drm/xe/xe_device.c
index 1202f8007f79..792465f178fe 100644
--- a/drivers/gpu/drm/xe/xe_device.c
+++ b/drivers/gpu/drm/xe/xe_device.c
@@ -73,6 +73,10 @@ static int xe_file_open(struct drm_device *dev, struct drm_file *file)
mutex_init(&xef->exec_queue.lock);
xa_init_flags(&xef->exec_queue.xa, XA_FLAGS_ALLOC1);
+ spin_lock(&xe->clients.lock);
+ xe->clients.count++;
+ spin_unlock(&xe->clients.lock);
+
file->driver_priv = xef;
return 0;
}
@@ -105,6 +109,10 @@ static void xe_file_close(struct drm_device *dev, struct drm_file *file)
xa_destroy(&xef->vm.xa);
mutex_destroy(&xef->vm.lock);
+ spin_lock(&xe->clients.lock);
+ xe->clients.count--;
+ spin_unlock(&xe->clients.lock);
+
xe_drm_client_put(xef->client);
kfree(xef);
}
@@ -228,6 +236,7 @@ struct xe_device *xe_device_create(struct pci_dev *pdev,
xe->info.force_execlist = force_execlist;
spin_lock_init(&xe->irq.lock);
+ spin_lock_init(&xe->clients.lock);
init_waitqueue_head(&xe->ufence_wq);
diff --git a/drivers/gpu/drm/xe/xe_device_types.h b/drivers/gpu/drm/xe/xe_device_types.h
index be11cadccbd4..3d92cd5d1237 100644
--- a/drivers/gpu/drm/xe/xe_device_types.h
+++ b/drivers/gpu/drm/xe/xe_device_types.h
@@ -297,6 +297,15 @@ struct xe_device {
struct ttm_resource_manager sys_mgr;
} mem;
+ /** @clients: drm clients info */
+ struct {
+ /** @lock: Protects drm clients info */
+ spinlock_t lock;
+
+ /** @count: number of drm clients */
+ u64 count;
+ } clients;
+
/** @usm: unified memory state */
struct {
/** @asid: convert a ASID to VM */
diff --git a/drivers/gpu/drm/xe/xe_gt_sysfs.c b/drivers/gpu/drm/xe/xe_gt_sysfs.c
index 36f7bd34bc78..6fca6bdeb902 100644
--- a/drivers/gpu/drm/xe/xe_gt_sysfs.c
+++ b/drivers/gpu/drm/xe/xe_gt_sysfs.c
@@ -48,6 +48,7 @@ ccs_mode_store(struct device *kdev, struct device_attribute *attr,
const char *buff, size_t count)
{
struct xe_gt *gt = kobj_to_gt(&kdev->kobj);
+ struct xe_device *xe = gt_to_xe(gt);
u32 num_engines, num_slices;
int ret;
@@ -66,12 +67,21 @@ ccs_mode_store(struct device *kdev, struct device_attribute *attr,
return -EINVAL;
}
+ /* CCS mode can only be updated when there are no drm clients */
+ spin_lock(&xe->clients.lock);
+ if (xe->clients.count) {
+ spin_unlock(&xe->clients.lock);
+ return -EBUSY;
+ }
+
if (gt->ccs_mode.num_engines != num_engines) {
xe_gt_info(gt, "Setting compute mode to %d\n", num_engines);
gt->ccs_mode.num_engines = num_engines;
xe_gt_reset_async(gt);
}
+ spin_unlock(&xe->clients.lock);
+
return count;
}
--
2.21.0.rc0.32.g243a4c7e27
More information about the Intel-xe
mailing list