* [PATCH v3] drm/i915/gem: Explicitly return error value from eb_relocate helpers
@ 2026-12-03 16:57 Jonathan Cavitt
2026-12-03 18:08 ` sashiko-bot
2026-12-03 18:41 ` ✓ i915.CI.BAT: success for drm/i915/gem: Explicitly return error value from eb_relocate helpers (rev4) Patchwork
0 siblings, 2 replies; 3+ messages in thread
From: Jonathan Cavitt @ 2026-12-03 16:57 UTC (permalink / raw)
To: intel-gfx; +Cc: alex.zuo, jonathan.cavitt, joonas.lahtinen, krzysztof.karas
Static analysis issue:
The current implementations of the eb_relocate_vma and
eb_relocate_vma_slow functions cast the return value of
eb_relocate_entry to a signed long in order to determine if an error has
occurred. This is because the return value of eb_relocate_entry is a
u64 offset value on a success and a negative error value on a failure.
It is improper to perform a cast like this, so just have
eb_relocate_entry (and, by extension, its helper function
relocate_entry) return the error value, storing the offset separately in
a passed u64 pointer.
Interestingly, this value is only used for non-error-checking purposes
in the eb_relocate_vma case. We can simplify the eb_relocate_vma_slow
case by allowing the passed u64 pointer to be NULL because of this.
v2:
- Modify commit message (Karas)
- Reorder error and offset cases in eb_relocate_vma, as offset and
error are now uncorrelated (jcavitt)
- Fix uninitialized read issue (jcavitt)
v3:
- Rebase and fix spelling errors
Signed-off-by: Jonathan Cavitt <jonathan.cavitt@intel.com>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Krzysztof Karas <krzysztof.karas@intel.com>
---
.../gpu/drm/i915/gem/i915_gem_execbuffer.c | 48 +++++++++----------
1 file changed, 24 insertions(+), 24 deletions(-)
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c
index 7ed23dc392b8..2d5fd0d73f12 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c
@@ -1377,11 +1377,12 @@ static void clflush_write32(u32 *addr, u32 value, unsigned int flushes)
}
}
-static u64
+static int
relocate_entry(struct i915_vma *vma,
const struct drm_i915_gem_relocation_entry *reloc,
struct i915_execbuffer *eb,
- const struct i915_vma *target)
+ const struct i915_vma *target,
+ u64 *pin_offset)
{
u64 target_addr = relocation_target(reloc, target);
u64 offset = reloc->offset;
@@ -1406,13 +1407,16 @@ relocate_entry(struct i915_vma *vma,
goto repeat;
}
- return target->node.start | UPDATE;
+ if (pin_offset)
+ *pin_offset = target->node.start | UPDATE;
+ return 0;
}
-static u64
+static int
eb_relocate_entry(struct i915_execbuffer *eb,
struct eb_vma *ev,
- const struct drm_i915_gem_relocation_entry *reloc)
+ const struct drm_i915_gem_relocation_entry *reloc,
+ u64 *offset)
{
struct drm_i915_private *i915 = eb->i915;
struct eb_vma *target;
@@ -1509,7 +1513,7 @@ eb_relocate_entry(struct i915_execbuffer *eb,
ev->flags &= ~EXEC_OBJECT_ASYNC;
/* and update the user's relocation entry */
- return relocate_entry(ev->vma, reloc, eb, target->vma);
+ return relocate_entry(ev->vma, reloc, eb, target->vma, offset);
}
static int eb_relocate_vma(struct i915_execbuffer *eb, struct eb_vma *ev)
@@ -1520,6 +1524,7 @@ static int eb_relocate_vma(struct i915_execbuffer *eb, struct eb_vma *ev)
struct drm_i915_gem_relocation_entry __user *urelocs =
u64_to_user_ptr(entry->relocs_ptr);
unsigned long remain = entry->relocation_count;
+ int err = 0;
if (unlikely(remain > N_RELOC(INT_MAX)))
return -EINVAL;
@@ -1551,22 +1556,20 @@ static int eb_relocate_vma(struct i915_execbuffer *eb, struct eb_vma *ev)
copied = __copy_from_user_inatomic(r, urelocs, count * sizeof(r[0]));
pagefault_enable();
if (unlikely(copied)) {
- remain = -EFAULT;
+ err = -EFAULT;
goto out;
}
remain -= count;
do {
- u64 offset = eb_relocate_entry(eb, ev, r);
- int err;
+ u64 offset = 0;
+
+ err = eb_relocate_entry(eb, ev, r, &offset);
+ if (err)
+ goto out;
if (likely(offset == 0))
continue;
-
- if ((s64)offset < 0) {
- remain = (int)offset;
- goto out;
- }
/*
* Write back the presumed offset. We hold the
* objects' dma_resv locks here, so this must not
@@ -1603,12 +1606,13 @@ static int eb_relocate_vma(struct i915_execbuffer *eb, struct eb_vma *ev)
remain = -EFAULT;
goto out;
}
+ err = 0;
} while (r++, --count);
urelocs += ARRAY_SIZE(stack);
} while (remain);
out:
reloc_cache_reset(&eb->reloc_cache, eb);
- return remain;
+ return err;
}
static int
@@ -1618,18 +1622,14 @@ eb_relocate_vma_slow(struct i915_execbuffer *eb, struct eb_vma *ev)
struct drm_i915_gem_relocation_entry *relocs =
u64_to_ptr(typeof(*relocs), entry->relocs_ptr);
unsigned int i;
- int err;
+ int err = 0;
for (i = 0; i < entry->relocation_count; i++) {
- u64 offset = eb_relocate_entry(eb, ev, &relocs[i]);
-
- if ((s64)offset < 0) {
- err = (int)offset;
- goto err;
- }
+ err = eb_relocate_entry(eb, ev, &relocs[i], NULL);
+ if (err)
+ break;
}
- err = 0;
-err:
+
reloc_cache_reset(&eb->reloc_cache, eb);
return err;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v3] drm/i915/gem: Explicitly return error value from eb_relocate helpers
2026-12-03 16:57 [PATCH v3] drm/i915/gem: Explicitly return error value from eb_relocate helpers Jonathan Cavitt
@ 2026-12-03 18:08 ` sashiko-bot
2026-12-03 18:41 ` ✓ i915.CI.BAT: success for drm/i915/gem: Explicitly return error value from eb_relocate helpers (rev4) Patchwork
1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-12-03 18:08 UTC (permalink / raw)
To: Jonathan Cavitt, intel-gfx
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] drm/i915/gem: stale remain = -EFAULT in eb_relocate_vma()
--
commit 6d5dcf84817706043cd50b98c302e38dfccdf3a7
Author: Jonathan Cavitt <jonathan.cavitt@intel.com>
drm/i915/gem: Explicitly return error value from eb_relocate helpers
This commit changes relocate_entry() and eb_relocate_entry() to return an
int error code and pass the offset back through a u64 pointer argument.
It updates eb_relocate_vma() and eb_relocate_vma_slow() to check the
returned error directly instead of casting the offset to a signed type.
> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c
> index c41e1b9a40bca..d3272bf17bb04 100644
> --- a/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c
> +++ b/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c
[ ... ]
> @@ -1599,12 +1602,13 @@ static int eb_relocate_vma(struct i915_execbuffer *eb, struct eb_vma *ev)
> remain = -EFAULT;
> goto out;
> }
> + err = 0;
> } while (r++, --count);
> urelocs += ARRAY_SIZE(stack);
> } while (remain);
> out:
> reloc_cache_reset(&eb->reloc_cache, eb);
> - return remain;
> + return err;
> }
[Severity: Low]
Should remain = -EFAULT be updated now that the out label returns err
instead of remain?
Even though the put_user() error check is disabled with && 0, assigning
-EFAULT to unsigned long remain is now a dead store and leaves the
disabled error path inconsistent with the rest of eb_relocate_vma().
Reusing the outer err for put_user() also forces the manual err = 0 reset
so a put_user() failure does not leak out of the loop. Keeping a separate
local variable for put_user() and setting err = -EFAULT in the disabled
branch would avoid both.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203165741.2928732-1-jonathan.cavitt@intel.com?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread
* ✓ i915.CI.BAT: success for drm/i915/gem: Explicitly return error value from eb_relocate helpers (rev4)
2026-12-03 16:57 [PATCH v3] drm/i915/gem: Explicitly return error value from eb_relocate helpers Jonathan Cavitt
2026-12-03 18:08 ` sashiko-bot
@ 2026-12-03 18:41 ` Patchwork
1 sibling, 0 replies; 3+ messages in thread
From: Patchwork @ 2026-12-03 18:41 UTC (permalink / raw)
To: Jonathan Cavitt; +Cc: intel-gfx
[-- Attachment #1: Type: text/plain, Size: 2479 bytes --]
== Series Details ==
Series: drm/i915/gem: Explicitly return error value from eb_relocate helpers (rev4)
URL : https://patchwork.freedesktop.org/series/161167/
State : success
== Summary ==
CI Bug Log - changes from CI_DRM_19664 -> Patchwork_161167v4
====================================================
Summary
-------
**SUCCESS**
No regressions found.
External URL: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_161167v4/index.html
Participating hosts (40 -> 38)
------------------------------
Missing (2): bat-dg2-13 bat-adls-6
Known issues
------------
Here are the changes found in Patchwork_161167v4 that come from known issues:
### IGT changes ###
#### Issues hit ####
* igt@i915_selftest@live@sanitycheck:
- fi-kbl-7567u: [PASS][1] -> [DMESG-WARN][2] ([i915#13735]) +46 other tests dmesg-warn
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_19664/fi-kbl-7567u/igt@i915_selftest@live@sanitycheck.html
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_161167v4/fi-kbl-7567u/igt@i915_selftest@live@sanitycheck.html
* igt@kms_busy@basic@flip:
- fi-kbl-7567u: [PASS][3] -> [DMESG-WARN][4] ([i915#13735] / [i915#180])
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_19664/fi-kbl-7567u/igt@kms_busy@basic@flip.html
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_161167v4/fi-kbl-7567u/igt@kms_busy@basic@flip.html
* igt@kms_pm_rpm@basic-pci-d3-state:
- fi-kbl-7567u: [PASS][5] -> [DMESG-WARN][6] ([i915#13735] / [i915#15673] / [i915#180]) +52 other tests dmesg-warn
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_19664/fi-kbl-7567u/igt@kms_pm_rpm@basic-pci-d3-state.html
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_161167v4/fi-kbl-7567u/igt@kms_pm_rpm@basic-pci-d3-state.html
[i915#13735]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/13735
[i915#15673]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/15673
[i915#180]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/180
Build changes
-------------
* Linux: CI_DRM_19664 -> Patchwork_161167v4
CI-20190529: 20190529
CI_DRM_19664: f360b5218783450630793ca7a462fdcff2dfd2e5 @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_9223: 9223
Patchwork_161167v4: f360b5218783450630793ca7a462fdcff2dfd2e5 @ git://anongit.freedesktop.org/gfx-ci/linux
== Logs ==
For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_161167v4/index.html
[-- Attachment #2: Type: text/html, Size: 3351 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-12-03 18:41 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 16:57 [PATCH v3] drm/i915/gem: Explicitly return error value from eb_relocate helpers Jonathan Cavitt
2026-12-03 18:08 ` sashiko-bot
2026-12-03 18:41 ` ✓ i915.CI.BAT: success for drm/i915/gem: Explicitly return error value from eb_relocate helpers (rev4) Patchwork
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.