[PATCH] drm/ttm: fix handling of errors on prefaulted pages

Paolo Bonzini <[email protected]> Tue, 4 Aug 2026 14:42:34 +0200
Newsgroups gmane.linux.kernel.stable,gmane.comp.video.dri.devel
Message-ID <[email protected]>
Commit fe662d846c95 ("drm/ttm: remove io_reserve_lru handling v3")
mechanically converted the goto out_io_unlock exits into return statements,
but it broke the promise that errors in speculative fault would not
be reported.

The old code was

		if (unlikely((ret & VM_FAULT_ERROR))) {
			if (i == 0)
				goto out_io_unlock;     /* return ret, i.e. the error */
			else
				break;                  /* return NOPAGE */
		}
		...
	}
	ret = VM_FAULT_NOPAGE;
out_io_unlock:
	...
	return ret;

while the new one does the opposite: it returns ret if i > 0 (previously it
would return VM_FAULT_NOPAGE), and VM_FAULT_NOPAGE if i == 0 (previously
it would return ret).

Fix the condition of the "if".

Cc: [email protected]
Fixes: fe662d846c95 ("drm/ttm: remove io_reserve_lru handling v3", 2020-09-03)
Cc: Christian Koenig <[email protected]> (maintainer:DRM TTM SUBSYSTEM)
Cc: Huang Rui <[email protected]> (maintainer:DRM TTM SUBSYSTEM)
Cc: Matthew Auld <[email protected]> (reviewer:DRM TTM SUBSYSTEM)
Cc: Matthew Brost <[email protected]> (reviewer:DRM TTM SUBSYSTEM)
Cc: Thomas Zimmermann <[email protected]> (maintainer:DRM DRIVERS AND MISC GPU PATCHES)
Cc: [email protected] (open list:DRM TTM SUBSYSTEM)
Signed-off-by: Paolo Bonzini <[email protected]>
---
 drivers/gpu/drm/ttm/ttm_bo_vm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c
index a80510489c45..6d59f3c0696c 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
@@ -267,7 +267,7 @@ vm_fault_t ttm_bo_vm_fault_reserved(struct vm_fault *vmf,
 
 		/* Never error on prefaulted PTEs */
 		if (unlikely((ret & VM_FAULT_ERROR))) {
-			if (i == 0)
+			if (i > 0)
 				return VM_FAULT_NOPAGE;
 			else
 				break;
-- 
2.55.0