dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Srinivasan Shanmugam" <srinivasan.shanmugam@amd.com>
Cc: dri-devel@lists.freedesktop.org, intel-xe@lists.freedesktop.org
Subject: Re: [PATCH v7 4/4] drm: Add per-signal compare functionality to drm_user_fence
Date: Wed, 02 Sep 2026 15:29:49 +0000	[thread overview]
Message-ID: <20260902152950.52B391F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260902152049.183685-4-srinivasan.shanmugam@amd.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] copy_from_user_nofault() disables page faults, causing legitimate completion events to be permanently dropped if the CPU PTE is not populated.
- [Medium] drm_user_fence_set_compare() returns void and silently ignores invalid configuration arguments.
--

commit ff537705b8c71e85d2a5b3d68ffe3a36096823b1
Author: Srinivasan Shanmugam <srinivasan.shanmugam@amd.com>

drm: Add per-signal compare functionality to drm_user_fence
    
This patch adds optional compare fields to drm_user_fence to support per-signal
filtering, as used in the EOP eventfd path. It introduces
drm_user_fence_set_compare to configure the comparison and modifies the worker
to read the userspace value using copy_from_user_nofault before signaling.

> diff --git a/drivers/gpu/drm/drm_user_fence.c b/drivers/gpu/drm/drm_user_fence.c
> index 0f229b7210a9b..06a5683db10d9 100644
> --- a/drivers/gpu/drm/drm_user_fence.c
> +++ b/drivers/gpu/drm/drm_user_fence.c

[ ... ]

> @@ -30,13 +39,46 @@ static void drm_user_fence_do_work(struct drm_work_fence *wfence)

[ ... ]

> +	if (ufence->cmp_op != DRM_USER_FENCE_CMP_NONE &&
> +	    !(wfence->fence && wfence->fence->error)) {
> +		if (!mm) {
> +			call_worker = false;
> +		} else {
> +			__le64 raw;
> +
> +			/*
> +			 * Use copy_from_user_nofault() to prevent a
> +			 * userfaultfd-registered page from blocking this
> +			 * workqueue thread indefinitely (DoS).
> +			 */
> +			if (copy_from_user_nofault(&raw, ufence->cmp_addr,
> +						   sizeof(raw))) {
> +				call_worker = false;

[Severity: High]
Because copy_from_user_nofault disables page faults in drm_user_fence_do_work,
will this return -EFAULT and permanently drop legitimate completion events if
the CPU PTE is not populated?

This can happen if the page is not resident, such as when NUMA balancing
sets PROT_NONE, or if the memory uses lazy mapping and the CPU hasn't
touched it since the GPU wrote to it.

> +			} else {
> +				/* GPU writes LE; convert before comparing. */
> +				u64 cur_val = le64_to_cpu(raw);

[ ... ]

> @@ -63,8 +105,47 @@ void drm_user_fence_init(struct drm_user_fence *ufence,

[ ... ]

> +void drm_user_fence_set_compare(struct drm_user_fence *ufence,
> +				u64 __user *addr, u64 value,
> +				enum drm_user_fence_cmp op)
> +{
> +	/*
> +	 * get_user() of u64 is not atomic on 32-bit — caller should not
> +	 * reach here on non-64-bit kernels.
> +	 */
> +	if (WARN_ON_ONCE(!IS_ENABLED(CONFIG_64BIT)))
> +		return;

[Severity: Medium]
Because this function returns void, does this early return on unsupported
architectures silently fail without the caller knowing?

If a driver attempts to configure a comparison here, it appears it would
silently leave cmp_op disabled as DRM_USER_FENCE_CMP_NONE, treating the
fence as an unconditional signal.

Could this function return an error code instead so the driver can
propagate the failure to userspace?

> +
> +	if (op != DRM_USER_FENCE_CMP_NONE) {
> +		if (!addr || !IS_ALIGNED((unsigned long)addr, sizeof(u64)))
> +			return;

[Severity: Medium]
Similarly, if a driver passes an unaligned userspace address, does this
return silently bypass the intended logic and leave the fence as an
unconditional signal?

> +	}
> +
> +	ufence->cmp_addr  = addr;
> +	ufence->cmp_value = value;
> +	ufence->cmp_op    = op;
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260902152049.183685-1-srinivasan.shanmugam@amd.com?part=4

  reply	other threads:[~2026-09-02 15:29 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-27  6:21 [PATCH 0/2] drm: Add Common drm_user_fence helper and Convert XE Srinivasan Shanmugam
2026-08-27  6:21 ` [PATCH 1/2] drm: Add common drm_user_fence helper Srinivasan Shanmugam
2026-08-27  6:32   ` sashiko-bot
2026-08-27  6:21 ` [PATCH 2/2] drm/xe: Convert xe_user_fence to drm_user_fence Srinivasan Shanmugam
2026-08-27  6:37   ` sashiko-bot
2026-08-31  5:41 ` [PATCH v5 0/4] drm: Add common drm_work_fence/drm_user_fence helpers and convert XE Srinivasan Shanmugam
2026-08-31 10:16   ` Thomas Hellström
2026-08-31 11:13     ` SHANMUGAM, SRINIVASAN
2026-08-31 12:22       ` Thomas Hellström
2026-08-31 12:36         ` SHANMUGAM, SRINIVASAN
2026-08-31 12:40           ` Thomas Hellström
2026-08-31  5:41 ` [PATCH v5 1/4] drm: Add drm_work_fence helper Srinivasan Shanmugam
2026-08-31  5:41 ` [PATCH v5 2/4] drm: Add drm_user_fence helper Srinivasan Shanmugam
2026-08-31  5:41 ` [PATCH v5 3/4] drm/xe: Convert xe_user_fence to drm_user_fence Srinivasan Shanmugam
2026-08-31  5:56   ` sashiko-bot
2026-08-31  5:41 ` [PATCH v5 4/4] drm: Add per-signal compare functionality " Srinivasan Shanmugam
2026-08-31  5:51   ` sashiko-bot
2026-08-31 13:45 ` [PATCH v6 0/4] drm: Add common drm_work_fence/drm_user_fence helpers and convert XE Srinivasan Shanmugam
2026-08-31 13:45 ` [PATCH v6 1/4] drm: Add drm_work_fence helper Srinivasan Shanmugam
2026-08-31 20:21   ` Matthew Brost
2026-09-01  7:39     ` SHANMUGAM, SRINIVASAN
2026-09-01 10:04       ` Matthew Brost
2026-09-02 15:20   ` [PATCH v7 " Srinivasan Shanmugam
2026-09-02 15:20     ` [PATCH v7 2/4] drm: Add drm_user_fence helper Srinivasan Shanmugam
2026-09-02 15:20     ` [PATCH v7 3/4] drm/xe: Convert xe_user_fence to drm_user_fence Srinivasan Shanmugam
2026-09-02 15:34       ` sashiko-bot
2026-09-02 15:20     ` [PATCH v7 4/4] drm: Add per-signal compare functionality " Srinivasan Shanmugam
2026-09-02 15:29       ` sashiko-bot [this message]
2026-08-31 13:45 ` [PATCH v6 2/4] drm: Add drm_user_fence helper Srinivasan Shanmugam
2026-08-31 20:36   ` Matthew Brost
2026-08-31 13:45 ` [PATCH v6 3/4] drm/xe: Convert xe_user_fence to drm_user_fence Srinivasan Shanmugam
2026-08-31 13:45 ` [PATCH v6 4/4] drm: Add per-signal compare functionality " Srinivasan Shanmugam
2026-08-31 14:25   ` sashiko-bot

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=20260902152950.52B391F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=srinivasan.shanmugam@amd.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