From: Matthew Auld <matthew.auld@intel.com>
To: intel-xe@lists.freedesktop.org
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
Subject: [Intel-xe] [PATCH v9 8/8] drm/xe: Use atomic for mem_access.ref
Date: Tue, 23 May 2023 10:47:27 +0100 [thread overview]
Message-ID: <20230523094727.162266-8-matthew.auld@intel.com> (raw)
In-Reply-To: <20230523094727.162266-1-matthew.auld@intel.com>
From: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
xe_guc_ct_fast_path() is called from an irq context, and cannot lock
the mutex used by xe_device_mem_access_ongoing().
Fortunately it is easy to fix if we switch the ref over to an atomic.
Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Signed-off-by: Matthew Auld <matthew.auld@intel.com>
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Cc: Matthew Brost <matthew.brost@intel.com>
Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
---
drivers/gpu/drm/xe/xe_device.c | 34 ++++++++++++----------------
drivers/gpu/drm/xe/xe_device_types.h | 6 ++---
2 files changed, 18 insertions(+), 22 deletions(-)
diff --git a/drivers/gpu/drm/xe/xe_device.c b/drivers/gpu/drm/xe/xe_device.c
index ac11cd7c3b67..b69fefbac845 100644
--- a/drivers/gpu/drm/xe/xe_device.c
+++ b/drivers/gpu/drm/xe/xe_device.c
@@ -412,30 +412,23 @@ u32 xe_device_ccs_bytes(struct xe_device *xe, u64 size)
DIV_ROUND_UP(size, NUM_BYTES_PER_CCS_BYTE) : 0;
}
-void xe_device_assert_mem_access(struct xe_device *xe)
-{
- if (xe_pm_read_callback_task(xe) == current)
- return;
-
- XE_WARN_ON(!xe->mem_access.ref);
-}
-
bool xe_device_mem_access_ongoing(struct xe_device *xe)
{
- bool ret;
-
if (xe_pm_read_callback_task(xe) == current)
return true;
- mutex_lock(&xe->mem_access.lock);
- ret = xe->mem_access.ref;
- mutex_unlock(&xe->mem_access.lock);
+ return atomic_read(&xe->mem_access.ref);
+}
- return ret;
+void xe_device_assert_mem_access(struct xe_device *xe)
+{
+ XE_WARN_ON(!xe_device_mem_access_ongoing(xe));
}
void xe_device_mem_access_get(struct xe_device *xe)
{
+ int ref;
+
/*
* This looks racy, but should be fine since the pm_callback_task only
* transitions from NULL -> current (and back to NULL again), during the
@@ -455,23 +448,26 @@ void xe_device_mem_access_get(struct xe_device *xe)
* for example just on the 0 -> 1.
*/
mutex_lock(&xe->mem_access.lock);
- if (xe->mem_access.ref == 0)
+ if (atomic_read(&xe->mem_access.ref) == 0)
xe->mem_access.hold_rpm = xe_pm_runtime_resume_and_get(xe);
- xe->mem_access.ref++;
+ ref = atomic_inc_return(&xe->mem_access.ref);
mutex_unlock(&xe->mem_access.lock);
- XE_WARN_ON(xe->mem_access.ref == S32_MAX);
+ XE_WARN_ON(ref == S32_MAX);
}
void xe_device_mem_access_put(struct xe_device *xe)
{
+ int ref;
+
if (xe_pm_read_callback_task(xe) == current)
return;
mutex_lock(&xe->mem_access.lock);
- if (--xe->mem_access.ref == 0 && xe->mem_access.hold_rpm)
+ ref = atomic_dec_return(&xe->mem_access.ref);
+ if (ref == 0 && xe->mem_access.hold_rpm)
xe_pm_runtime_put(xe);
mutex_unlock(&xe->mem_access.lock);
- XE_WARN_ON(xe->mem_access.ref < 0);
+ XE_WARN_ON(ref < 0);
}
diff --git a/drivers/gpu/drm/xe/xe_device_types.h b/drivers/gpu/drm/xe/xe_device_types.h
index b5a56e112c0a..f1515aff8437 100644
--- a/drivers/gpu/drm/xe/xe_device_types.h
+++ b/drivers/gpu/drm/xe/xe_device_types.h
@@ -261,9 +261,9 @@ struct xe_device {
*/
struct {
/**
- * @lock: Protects @ref and serializes multiple callers.
+ * @lock: Serializes multiple callers.
*
- * Also used as lockdep aid to hopefully ensure that it sees
+ * But mainly used as lockdep aid to hopefully ensure that it sees
* that the runtime_pm callbacks can be called while holding
* @lock, and therefore any locks that the caller is holding
* also have a clear dependency on the @lock and any locks the
@@ -274,7 +274,7 @@ struct xe_device {
*/
struct mutex lock;
/** @ref: ref count of memory accesses */
- s32 ref;
+ atomic_t ref;
/** @hold_rpm: need to put rpm ref back at the end */
bool hold_rpm;
} mem_access;
--
2.40.1
next prev parent reply other threads:[~2023-05-23 9:47 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-23 9:47 [Intel-xe] [PATCH v9 1/8] Revert "drm/xe: Use atomic instead of mutex for xe_device_mem_access_ongoing" Matthew Auld
2023-05-23 9:47 ` [Intel-xe] [PATCH v9 2/8] drm/xe: don't allocate under ct->lock Matthew Auld
2023-05-23 9:47 ` [Intel-xe] [PATCH v9 3/8] drm/xe: keep pulling mem_access_get further back Matthew Auld
2023-05-23 9:47 ` [Intel-xe] [PATCH v9 4/8] drm/xe: tweak lock ordering for freq_lock Matthew Auld
2023-05-23 13:07 ` Rodrigo Vivi
2023-05-23 13:13 ` Matthew Auld
2023-05-23 9:47 ` [Intel-xe] [PATCH v9 5/8] drm/xe/ggtt: prime ggtt->lock against FS_RECLAIM Matthew Auld
2023-05-23 9:47 ` [Intel-xe] [PATCH v9 6/8] drm/xe/ct: drop mem_access_get from g2h_worker_func() Matthew Auld
2023-05-23 13:04 ` Rodrigo Vivi
2023-05-23 13:10 ` Matthew Auld
2023-05-23 9:47 ` [Intel-xe] [PATCH v9 7/8] drm/xe: fix xe_device_mem_access_get() races Matthew Auld
2023-05-23 9:47 ` Matthew Auld [this message]
2023-05-23 9:49 ` [Intel-xe] ✓ CI.Patch_applied: success for series starting with [v9,1/8] Revert "drm/xe: Use atomic instead of mutex for xe_device_mem_access_ongoing" Patchwork
2023-05-23 9:51 ` [Intel-xe] ✓ CI.KUnit: " Patchwork
2023-05-23 9:55 ` [Intel-xe] ✓ CI.Build: " Patchwork
2023-05-23 10:19 ` [Intel-xe] ○ CI.BAT: info " Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230523094727.162266-8-matthew.auld@intel.com \
--to=matthew.auld@intel.com \
--cc=intel-xe@lists.freedesktop.org \
--cc=rodrigo.vivi@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox