Skip to contentSkip to conversation

drm/i915/gem: Set the VM owner before publishing the VM

PATCH In review Changyul Lee 3 participants 3 messages Nov 20 – Nov 23

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/i915/gem: Set the VM owner before publishing the VM

i915_gem_vm_create_ioctl() adds the VM to the file's VM table before setting its owner (vm.fpriv). A concurrent lookup can therefore see the VM without an owner and allocate page tables that are missing from the client's memory accounting. Concurrent VM destruction can also free the VM before the owner assignment, causing a write to freed memory.

Set the owner before inserting the VM into the table with xa_alloc(). If xa_alloc() fails, err_put still releases the VM.

Fixes ca02a0119f81 ("drm/i915: Record which client owns a VM")

---
Found with a static analysis tool we are developing.

Compile-tested only, with x86_64_defconfig and W=1.

 drivers/gpu/drm/i915/gem/i915_gem_context.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/gem/i915_gem_context.c +2 -1
index c58ffa5a8fa6..489b221091d1 100644
@@ -1838,6 +1838,8 @@ int i915_gem_vm_create_ioctl(struct drm_device *dev, void *data,
 			goto err_put;
 	}
 
+	ppgtt->vm.fpriv = file_priv;
+
 	err = xa_alloc(&file_priv->vm_xa, &id, &ppgtt->vm,
 		       xa_limit_32b, GFP_KERNEL);
 	if (err)
@@ -1845,7 +1847,6 @@ int i915_gem_vm_create_ioctl(struct drm_device *dev, void *data,
 
 	GEM_BUG_ON(id == 0); /* reserved for invalid/unassigned ppgtt */
 	args->vm_id = id;
-	ppgtt->vm.fpriv = file_priv;
 	return 0;
 
 err_put:

base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3

Signature · 1 line
2.43.0
maintainer
#1 lore raw

Quoting Changyul Lee (2026-11-20 04:42:10)

Quoted 4 lines

i915_gem_vm_create_ioctl() adds the VM to the file's VM table before setting its owner (vm.fpriv). A concurrent lookup can therefore see the VM without an owner and allocate page tables that are missing from the client's memory accounting.

This commit message is just not making any sense.

The ID used in the supposed lookup is returned from this very IOCTL.

Quoted 3 lines

Concurrent VM destruction can
also free the VM before the owner assignment, causing a write to freed memory.

Could you explain in your own terms the call sequence that'll lead to this?

Quoted 2 lines

Set the owner before inserting the VM into the table with xa_alloc(). If xa_alloc() fails, err_put still releases the VM.

Very LLM'esque to just explain what the code does to inflate the patch description.

Quoted 4 lines
Fixes ca02a0119f81 ("drm/i915: Record which client owns a VM")

---
Found with a static analysis tool we are developing.

Unless a competent human developer looked the patches through before submitting and wrote the patch descriptions, please redirect further submissions to /dev/null.

Regards, Joonas

Quoted 32 lines

Compile-tested only, with x86_64_defconfig and W=1.

 drivers/gpu/drm/i915/gem/i915_gem_context.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/gem/i915_gem_context.c +2 -1
index c58ffa5a8fa6..489b221091d1 100644
@@ -1838,6 +1838,8 @@ int i915_gem_vm_create_ioctl(struct drm_device *dev, void *data,
                        goto err_put;
        }
 
+       ppgtt->vm.fpriv = file_priv;
+
        err = xa_alloc(&file_priv->vm_xa, &id, &ppgtt->vm,
                       xa_limit_32b, GFP_KERNEL);
        if (err)
@@ -1845,7 +1847,6 @@ int i915_gem_vm_create_ioctl(struct drm_device *dev, void *data,
 
        GEM_BUG_ON(id == 0); /* reserved for invalid/unassigned ppgtt */
        args->vm_id = id;
-       ppgtt->vm.fpriv = file_priv;
        return 0;
 
 err_put:

base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3

Signature · 1 line
2.43.0
#2 lore raw

✗ LGCI.VerificationFailed: failure for drm/i915/gem: Set the VM owner before publishing the VM

In reply to Changyul Lee
== Series Details ==

== Series Details ==

Series: drm/i915/gem: Set the VM owner before publishing the VM
URL : https://patchwork.freedesktop.org/series/179390/
State : failure

== Summary ==

Series author address '[email protected]' is not on the allowlist, which prevents CI from being automatically triggered. If you want CI to run for this series, ask Patchwork project owners to click 'retest' on the series in Patchwork. Exception occurred during validation, bailing out!
Build URL: http://gfx-ci.igk.intel.com:8080/job/CI_PW_kernel/193730/ (on built-in)