From: Matthew Brost <matthew.brost@intel.com>
To: Jonathan Cavitt <jonathan.cavitt@intel.com>
Cc: <intel-xe@lists.freedesktop.org>, <saurabhg.gupta@intel.com>,
<alex.zuo@intel.com>, <daniele.ceraolospurio@intel.com>,
<rodrigo.vivi@intel.com>, <michal.wajdeczko@intel.com>,
<stuart.summers@intel.com>, <ashutosh.dixit@intel.com>
Subject: Re: [PATCH v3 1/2] drm/xe/guc: READ/WRITE_ONCE g2h_fence->done
Date: Tue, 23 Dec 2025 13:36:15 -0800 [thread overview]
Message-ID: <aUsLT59alCPEistt@lstrano-desk.jf.intel.com> (raw)
In-Reply-To: <20251222201957.63245-5-jonathan.cavitt@intel.com>
On Mon, Dec 22, 2025 at 08:19:59PM +0000, Jonathan Cavitt wrote:
> Use READ_ONCE and WRITE_ONCE when operating on g2h_fence->done
> to prevent the compiler from ignoring important modifications
> to its value.
>
> Fixes: dd08ebf6c352 ("drm/xe: Introduce a new DRM driver for Intel GPUs")
> Suggested-by: Matthew Brost <matthew.brost@intel.com>
Reviewed-by: Matthew Brost <matthew.brost@intel.com>
> Signed-off-by: Jonathan Cavitt <jonathan.cavitt@intel.com>
> Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
> ---
> drivers/gpu/drm/xe/xe_guc_ct.c | 14 ++++++++++----
> 1 file changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/xe/xe_guc_ct.c b/drivers/gpu/drm/xe/xe_guc_ct.c
> index c3df9b3f1b4d..f2148a8bf208 100644
> --- a/drivers/gpu/drm/xe/xe_guc_ct.c
> +++ b/drivers/gpu/drm/xe/xe_guc_ct.c
> @@ -206,7 +206,9 @@ static void g2h_fence_cancel(struct g2h_fence *g2h_fence)
> {
> g2h_fence->cancel = true;
> g2h_fence->fail = true;
> - g2h_fence->done = true;
> +
> + /* WRITE_ONCE pairs with READ_ONCEs in guc_ct_send_recv. */
> + WRITE_ONCE(g2h_fence->done, true);
> }
>
> static bool g2h_fence_needs_alloc(struct g2h_fence *g2h_fence)
> @@ -1294,10 +1296,13 @@ static int guc_ct_send_recv(struct xe_guc_ct *ct, const u32 *action, u32 len,
> return ret;
> }
>
> - ret = wait_event_timeout(ct->g2h_fence_wq, g2h_fence.done, HZ);
> + /* READ_ONCEs pairs with WRITE_ONCEs in parse_g2h_response
> + * and g2h_fence_cancel.
> + */
> + ret = wait_event_timeout(ct->g2h_fence_wq, READ_ONCE(g2h_fence.done), HZ);
> if (!ret) {
> LNL_FLUSH_WORK(&ct->g2h_worker);
> - if (g2h_fence.done) {
> + if (READ_ONCE(g2h_fence.done)) {
> xe_gt_warn(gt, "G2H fence %u, action %04x, done\n",
> g2h_fence.seqno, action[0]);
> ret = 1;
> @@ -1498,7 +1503,8 @@ static int parse_g2h_response(struct xe_guc_ct *ct, u32 *msg, u32 len)
>
> g2h_release_space(ct, GUC_CTB_HXG_MSG_MAX_LEN);
>
> - g2h_fence->done = true;
> + /* WRITE_ONCE pairs with READ_ONCEs in guc_ct_send_recv. */
> + WRITE_ONCE(g2h_fence->done, true);
> smp_mb();
>
> wake_up_all(&ct->g2h_fence_wq);
> --
> 2.43.0
>
next prev parent reply other threads:[~2025-12-23 21:36 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-22 20:19 [PATCH v3 0/2] drm/xe/guc: Prevent compiler read/write optimization breaks Jonathan Cavitt
2025-12-22 20:19 ` [PATCH v3 1/2] drm/xe/guc: READ/WRITE_ONCE g2h_fence->done Jonathan Cavitt
2025-12-23 21:36 ` Matthew Brost [this message]
2025-12-22 20:20 ` [PATCH v3 2/2] drm/xe/guc: READ/WRITE_ONCE ct->state Jonathan Cavitt
2025-12-23 21:36 ` Matthew Brost
2025-12-23 21:45 ` Rodrigo Vivi
2025-12-23 2:05 ` ✓ CI.KUnit: success for drm/xe/guc: Prevent compiler read/write optimization breaks (rev2) Patchwork
2025-12-23 2:43 ` ✓ Xe.CI.BAT: " Patchwork
2025-12-23 13:20 ` ✓ Xe.CI.Full: " 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=aUsLT59alCPEistt@lstrano-desk.jf.intel.com \
--to=matthew.brost@intel.com \
--cc=alex.zuo@intel.com \
--cc=ashutosh.dixit@intel.com \
--cc=daniele.ceraolospurio@intel.com \
--cc=intel-xe@lists.freedesktop.org \
--cc=jonathan.cavitt@intel.com \
--cc=michal.wajdeczko@intel.com \
--cc=rodrigo.vivi@intel.com \
--cc=saurabhg.gupta@intel.com \
--cc=stuart.summers@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