Skip to contentSkip to conversation

drm/i915: set O_LARGEFILE in __create_shmem()

PATCH In review 陈涛涛 Taotao Chen 5 participants 9 messages Aug 22, 2025 – Oct 2, 2025

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

PATCH v2 1/2 drm/i915: set O_LARGEFILE in __create_shmem()

From: Taotao Chen <[email protected]>

Without O_LARGEFILE, file->f_op->write_iter calls generic_write_check_limits(), which enforces a 2GB (MAX_NON_LFS) limit, causing -EFBIG on large writes.

In shmem_pwrite(), this error is later masked as -EIO due to the error handling order, leading to igt failures like gen9_exec_parse(bb-large).

Set O_LARGEFILE in __create_shmem() to prevent -EFBIG on large writes.

Fixes 048832a3f400 ("drm/i915: Refactor shmem_pwrite() to use kiocb and write_iter")

---
v2:
- Add force_o_largefile() guard before setting O_LARGEFILE

 drivers/gpu/drm/i915/gem/i915_gem_shmem.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/gpu/drm/i915/gem/i915_gem_shmem.c +7 -0
index e3d188455f67..b9dae15c1d16 100644
@@ -514,6 +514,13 @@ static int __create_shmem(struct drm_i915_private *i915,
 	if (IS_ERR(filp))
 		return PTR_ERR(filp);
 
+	/*
+	 * Prevent -EFBIG by allowing large writes beyond MAX_NON_LFS on shmem
+	 * objects by setting O_LARGEFILE.
+	 */
+	if (force_o_largefile())
+		filp->f_flags |= O_LARGEFILE;
+
 	obj->filp = filp;
 	return 0;
 }
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 2/2 drm/i915: Fix incorrect error handling in shmem_pwrite()

From: Taotao Chen <[email protected]>

shmem_pwrite() currently checks for short writes before negative error codes, which can overwrite real errors (e.g., -EFBIG) with -EIO. Reorder the checks to return negative errors first, then handle short writes.

---
v2:
- Drop Fixes tag
- Add Reviewed-by from Andi
- Add code comments (suggested by Rodrigo)

 drivers/gpu/drm/i915/gem/i915_gem_shmem.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_shmem.c +12 -3
index b9dae15c1d16..26dda55a07ff 100644
@@ -441,11 +441,20 @@ shmem_pwrite(struct drm_i915_gem_object *obj,
 	written = file->f_op->write_iter(&kiocb, &iter);
 	BUG_ON(written == -EIOCBQUEUED);
 
-	if (written != size)
-		return -EIO;
-
+	/*
+	 * First, check if write_iter returned a negative error.
+	 * If the write failed, return the real error code immediately.
+	 * This prevents it from being overwritten by the short write check below.
+	 */
 	if (written < 0)
 		return written;
+	/*
+	 * Check for a short write (written bytes != requested size).
+	 * Even if some data was written, return -EIO to indicate that the
+	 * write was not fully completed.
+	 */
+	if (written != size)
+		return -EIO;
 
 	return 0;
 }
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v2 2/2] drm/i915: Fix incorrect error handling in shmem_pwrite()

Going to hit us with a katana, Taotao?

Quoted 49 lines · 陈涛涛 Taotao Chen

From: Taotao Chen <[email protected]>

shmem_pwrite() currently checks for short writes before negative error codes, which can overwrite real errors (e.g., -EFBIG) with -EIO. Reorder the checks to return negative errors first, then handle short writes.

---
v2:
- Drop Fixes tag
- Add Reviewed-by from Andi
- Add code comments (suggested by Rodrigo)

 drivers/gpu/drm/i915/gem/i915_gem_shmem.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_shmem.c +12 -4
index b9dae15c1d16..26dda55a07ff 100644
@@ -441,11 +441,20 @@ shmem_pwrite(struct drm_i915_gem_object *obj,
        written = file->f_op->write_iter(&kiocb, &iter);
        BUG_ON(written == -EIOCBQUEUED);
 
-       if (written != size)
-               return -EIO;
-
+       /*
+        * First, check if write_iter returned a negative error.
+        * If the write failed, return the real error code immediately.
+        * This prevents it from being overwritten by the short write check below.
+        */
        if (written < 0)
                return written;
+       /*
+        * Check for a short write (written bytes != requested size).
+        * Even if some data was written, return -EIO to indicate that the
+        * write was not fully completed.
+        */
+       if (written != size)
+               return -EIO;
 
        return 0;
 }
--

2.34.1

#3 lore raw

✗ LGCI.VerificationFailed: failure for series starting with [v2,1/2] drm/i915: set O_LARGEFILE in __create_shmem()

In reply to 陈涛涛 Taotao Chen
== Series Details ==

== Series Details ==

Series: series starting with [v2,1/2] drm/i915: set O_LARGEFILE in __create_shmem()
URL : https://patchwork.freedesktop.org/series/153326/
State : failure

== Summary ==

Address '[email protected]' is not on the allowlist, which prevents CI from being triggered for this patch. If you want Intel GFX CI to accept this address, please contact the script maintainers at [email protected]. Exception occurred during validation, bailing out!

Reviewed-by on v2 1/2
#4 lore raw
In reply to 陈涛涛 Taotao Chen

Hi Taotao,

Quoted 9 lines · 陈涛涛 Taotao Chen

From: Taotao Chen <[email protected]>

Without O_LARGEFILE, file->f_op->write_iter calls generic_write_check_limits(), which enforces a 2GB (MAX_NON_LFS) limit, causing -EFBIG on large writes.

In shmem_pwrite(), this error is later masked as -EIO due to the error handling order, leading to igt failures like gen9_exec_parse(bb-large).

Quoted 6 lines

Set O_LARGEFILE in __create_shmem() to prevent -EFBIG on large writes.

Fixes 048832a3f400 ("drm/i915: Refactor shmem_pwrite() to use kiocb and write_iter")

looks good to me:

Thanks,
Andi

#5 lore raw
In reply to 陈涛涛 Taotao Chen
Quoted 30 lines · 陈涛涛 Taotao Chen

From: Taotao Chen <[email protected]>

Without O_LARGEFILE, file->f_op->write_iter calls generic_write_check_limits(), which enforces a 2GB (MAX_NON_LFS) limit, causing -EFBIG on large writes.

In shmem_pwrite(), this error is later masked as -EIO due to the error handling order, leading to igt failures like gen9_exec_parse(bb-large).

Set O_LARGEFILE in __create_shmem() to prevent -EFBIG on large writes.

Fixes 048832a3f400 ("drm/i915: Refactor shmem_pwrite() to use kiocb and write_iter")

---
v2:
- Add force_o_largefile() guard before setting O_LARGEFILE

  drivers/gpu/drm/i915/gem/i915_gem_shmem.c | 7 +++++++
  1 file changed, 7 insertions(+)
drivers/gpu/drm/i915/gem/i915_gem_shmem.c +0 -0
index e3d188455f67..b9dae15c1d16 100644
@@ -514,6 +514,13 @@ static int __create_shmem(struct drm_i915_private *i915,
  	if (IS_ERR(filp))
  		return PTR_ERR(filp);
 

drivers/gpu/drm/i915/gem/i915_gem_shmem.c static int __create_shmem(struct drm_i915_private *i915, · line 526

Quoted 10 lines
drivers/gpu/drm/i915/gem/i915_gem_shmem.c +7 -0
+	/*
+	 * Prevent -EFBIG by allowing large writes beyond MAX_NON_LFS on shmem
+	 * objects by setting O_LARGEFILE.
+	 */
+	if (force_o_largefile())
+		filp->f_flags |= O_LARGEFILE;
+
  	obj->filp = filp;
  	return 0;
  }

Hi,

Just a gentle ping on this patch. Any further comments or plans to pick it up?

Thanks,
Taotao

#6 lore raw

Hi Taotao,

Quoted 13 lines
Quoted 13 lines

Without O_LARGEFILE, file->f_op->write_iter calls generic_write_check_limits(), which enforces a 2GB (MAX_NON_LFS) limit, causing -EFBIG on large writes.

In shmem_pwrite(), this error is later masked as -EIO due to the error handling order, leading to igt failures like gen9_exec_parse(bb-large).

Set O_LARGEFILE in __create_shmem() to prevent -EFBIG on large writes.

Fixes 048832a3f400 ("drm/i915: Refactor shmem_pwrite() to use kiocb and write_iter")

...

Quoted 2 lines

Just a gentle ping on this patch. Any further comments or plans to pick it up?

Unfortunately your patch has not been picked up by our CI, now I re-run the test.

In any case, your second patch can't be merged yet because your previous one(*) has been applied to the wrong branch from Christian while it should have gone through drm-intel-gt-next. Now we need to wait for a backmerge.

In any case, if the tests succeed, I can already apply your first patch so that it gets included in the Wednesday's pull request.

While the second patch, that is not a fix, has plenty of time and can wait the backmerge.

Andi

(*) 048832a3f400 ("drm/i915: Refactor shmem_pwrite() to use kiocb and write_iter")

#7 lore raw

✗ LGCI.VerificationFailed: failure for series starting with [v2,1/2] drm/i915: set O_LARGEFILE in __create_shmem() (rev2)

In reply to 陈涛涛 Taotao Chen
== Series Details ==

== Series Details ==

Series: series starting with [v2,1/2] drm/i915: set O_LARGEFILE in __create_shmem() (rev2)
URL : https://patchwork.freedesktop.org/series/153326/
State : failure

== Summary ==

Address '[email protected]' is not on the allowlist, which prevents CI from being triggered for this patch. If you want Intel GFX CI to accept this address, please contact the script maintainers at [email protected]. Exception occurred during validation, bailing out!

#8 lore raw
In reply to 陈涛涛 Taotao Chen

Hi Taotao,

Both patches merged to drm-intel-gt-next.

Thank you,
Andi

Quoted 42 lines · 陈涛涛 Taotao Chen

From: Taotao Chen <[email protected]>

Without O_LARGEFILE, file->f_op->write_iter calls generic_write_check_limits(), which enforces a 2GB (MAX_NON_LFS) limit, causing -EFBIG on large writes.

In shmem_pwrite(), this error is later masked as -EIO due to the error handling order, leading to igt failures like gen9_exec_parse(bb-large).

Set O_LARGEFILE in __create_shmem() to prevent -EFBIG on large writes.

Fixes 048832a3f400 ("drm/i915: Refactor shmem_pwrite() to use kiocb and write_iter")

---
v2:
- Add force_o_largefile() guard before setting O_LARGEFILE

 drivers/gpu/drm/i915/gem/i915_gem_shmem.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/gpu/drm/i915/gem/i915_gem_shmem.c +7 -0
index e3d188455f67..b9dae15c1d16 100644
@@ -514,6 +514,13 @@ static int __create_shmem(struct drm_i915_private *i915,
 	if (IS_ERR(filp))
 		return PTR_ERR(filp);
 
+	/*
+	 * Prevent -EFBIG by allowing large writes beyond MAX_NON_LFS on shmem
+	 * objects by setting O_LARGEFILE.
+	 */
+	if (force_o_largefile())
+		filp->f_flags |= O_LARGEFILE;
+
 	obj->filp = filp;
 	return 0;
 }
Signature · 1 line
2.34.1