From: Christoph Manszewski <[email protected]>

EU debug functionality relies on access to specific mmio registers.
Since VFs don't have access to those registers and in order to avoid
interference with VFs, make SR-IOV and eudebug functionality exclusive.
I.e. don't allow enabling eudebug in VF mode and don't allow enabling
eudebug when any VFs are enabled. Likewise, don't allow enabling
VFs when eudebug is enabled.

v2: initialize lock early (Sashiko)
v3: say why eudebug was refused (Claude)
v4: avoid racing with work (Sashiko)
v5: - don't log per VF probe (Sashiko)
v6: - cap_state under eudebug.lock (Mika)
v7: - poll stop comment: a PF waits the last round out (Sashiko)
v8: - move right after the interface documentation, the vm access, EU
      control, attention worker and live tests patches now cover their
      own parts (Mika)

Signed-off-by: Christoph Manszewski <[email protected]>
Signed-off-by: Maciej Patelczyk <[email protected]>
Signed-off-by: Mika Kuoppala <[email protected]>
---
 .../ABI/testing/sysfs-driver-intel-xe-eudebug |  4 ++++
 drivers/gpu/drm/xe/xe_eudebug.c               | 21 +++++++++++++++++++
 2 files changed, 25 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-driver-intel-xe-eudebug 
b/Documentation/ABI/testing/sysfs-driver-intel-xe-eudebug
index 26aff5116b8a..884a791789ad 100644
--- a/Documentation/ABI/testing/sysfs-driver-intel-xe-eudebug
+++ b/Documentation/ABI/testing/sysfs-driver-intel-xe-eudebug
@@ -34,3 +34,7 @@ Description:  RW. Controls whether the EU debugger interface 
is armed for
                CONFIG_DRM_XE_EUDEBUG and the interface was set up at probe
                time. If probe could not set it up, the attribute is absent
                and the connect ioctl fails with -EOPNOTSUPP.
+
+               On an SR-IOV VF the attribute is absent. On a PF, writing 1
+               while VFs are enabled fails with -EBUSY, and while the
+               interface is enabled enabling VFs fails with -EPERM.
diff --git a/drivers/gpu/drm/xe/xe_eudebug.c b/drivers/gpu/drm/xe/xe_eudebug.c
index d18ba28f43b1..ad8e1c02f20b 100644
--- a/drivers/gpu/drm/xe/xe_eudebug.c
+++ b/drivers/gpu/drm/xe/xe_eudebug.c
@@ -17,6 +17,7 @@
 #include "xe_eudebug.h"
 #include "xe_eudebug_types.h"
 #include "xe_macros.h"
+#include "xe_sriov_pf.h"
 #include "xe_vm.h"
 
 /**
@@ -1203,6 +1204,8 @@ void xe_eudebug_file_close(struct xe_file *xef)
 
 static int xe_eudebug_enable(struct xe_device *xe, bool enable)
 {
+       int ret;
+
        guard(mutex)(&xe->eudebug.lock);
 
        if (xe->eudebug.cap_state == XE_EUDEBUG_CAP_NOT_SUPPORTED)
@@ -1214,9 +1217,21 @@ static int xe_eudebug_enable(struct xe_device *xe, bool 
enable)
        if (enable == __xe_eudebug_is_enabled(xe))
                return 0;
 
+       /* Lock VFs out first, so that a refusal leaves nothing to take back */
+       if (enable && IS_SRIOV_PF(xe)) {
+               ret = xe_sriov_pf_lockdown(xe);
+               if (ret) {
+                       drm_dbg(&xe->drm, "Can't enable eudebug: VFs are 
enabled\n");
+                       return ret;
+               }
+       }
+
        set_cap_state(xe, enable ?
                      XE_EUDEBUG_CAP_ENABLED : XE_EUDEBUG_CAP_DISABLED);
 
+       if (!enable && IS_SRIOV_PF(xe))
+               xe_sriov_pf_end_lockdown(xe);
+
        return 0;
 }
 
@@ -1288,6 +1303,11 @@ void xe_eudebug_init(struct xe_device *xe)
        if (xe->eudebug.cap_state == XE_EUDEBUG_CAP_NOT_SUPPORTED)
                return;
 
+       if (IS_SRIOV_VF(xe)) {
+               drm_dbg(&xe->drm, "eudebug not available in SR-IOV VF mode\n");
+               goto out_not_supported;
+       }
+
        err = devm_add_action_or_reset(dev->dev, xe_eudebug_sysfs_fini, xe);
        if (err)
                goto out_err;
@@ -1307,6 +1327,7 @@ void xe_eudebug_init(struct xe_device *xe)
 out_err:
        drm_warn(&xe->drm, "eudebug disabled, init fail: %d\n", err);
 
+out_not_supported:
        scoped_guard(mutex, &xe->eudebug.lock)
                set_cap_state(xe, XE_EUDEBUG_CAP_NOT_SUPPORTED);
 }
-- 
2.53.0

Reply via email to