[PATCH] drm/xe/vm: don't ignore error when in_kthread

Matthew Brost matthew.brost at intel.com
Mon Feb 5 18:41:57 UTC 2024


On Fri, Feb 02, 2024 at 05:14:36PM +0000, Matthew Auld wrote:
> If GUP fails and we are in_kthread, we can have pinned = 0 and ret = 0.
> If that happens we call sg_alloc_append_table_from_pages() with n_pages
> = 0, which is not well behaved and can trigger:
> 
> kernel BUG at include/linux/scatterlist.h:115!
> 
> depending on if the pages array happens to be zeroed or not. Even if we
> don't hit that it crashes later when trying to dma_map the returned
> table.
> 
> Signed-off-by: Matthew Auld <matthew.auld at intel.com>
> Cc: Thomas Hellström <thomas.hellstrom at linux.intel.com>
> Cc: Matthew Brost <matthew.brost at intel.com>

Someone from Habana point this out a while back and forgot to follow up
on fixing this. Thanks for fixing this and looks correct.

Should we include a Fixes tag here? I am thinking so.

With a fixes tag:
Reviewed: Matthew Brost <matthew.brost at intel.com>

> ---
>  drivers/gpu/drm/xe/xe_vm.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/drivers/gpu/drm/xe/xe_vm.c b/drivers/gpu/drm/xe/xe_vm.c
> index 9c1c68a2fff7..63aeb3aead04 100644
> --- a/drivers/gpu/drm/xe/xe_vm.c
> +++ b/drivers/gpu/drm/xe/xe_vm.c
> @@ -114,11 +114,8 @@ int xe_vma_userptr_pin_pages(struct xe_userptr_vma *uvma)
>  					  num_pages - pinned,
>  					  read_only ? 0 : FOLL_WRITE,
>  					  &pages[pinned]);
> -		if (ret < 0) {
> -			if (in_kthread)
> -				ret = 0;
> +		if (ret < 0)
>  			break;
> -		}
>  
>  		pinned += ret;
>  		ret = 0;
> -- 
> 2.43.0
> 


More information about the Intel-xe mailing list