dri-devel Archive mirror
 help / color / mirror / Atom feed
From: Lucas De Marchi <lucas.demarchi@intel.com>
To: Shuicheng Lin <shuicheng.lin@intel.com>
Cc: intel-xe@lists.freedesktop.org,
	"Nirmoy Das" <nirmoy.das@intel.com>,
	"Matthew Brost" <matthew.brost@intel.com>,
	dri-devel@lists.freedesktop.org,
	"Christian König" <christian.koenig@amd.com>
Subject: Re: [PATCH] drm/xe: Fix UBSAN shift-out-of-bounds failure
Date: Wed, 8 May 2024 22:38:03 -0500	[thread overview]
Message-ID: <dc7rmhsjbvtqddqvz465zo6esyiy7xengp43jepmvpaxvksuzv@bl6sq3upfy44> (raw)
In-Reply-To: <20240507130411.630361-1-shuicheng.lin@intel.com>

On Tue, May 07, 2024 at 01:04:11PM GMT, Shuicheng Lin wrote:
>Here is the failure stack:
>[   12.988209] ------------[ cut here ]------------
>[   12.988216] UBSAN: shift-out-of-bounds in ./include/linux/log2.h:57:13
>[   12.988232] shift exponent 64 is too large for 64-bit type 'long unsigned int'
>[   12.988235] CPU: 4 PID: 1310 Comm: gnome-shell Tainted: G     U             6.9.0-rc6+prerelease1158+ #19
>[   12.988237] Hardware name: Intel Corporation Raptor Lake Client Platform/RPL-S ADP-S DDR5 UDIMM CRB, BIOS RPLSFWI1.R00.3301.A02.2208050712 08/05/2022
>[   12.988239] Call Trace:
>[   12.988240]  <TASK>
>[   12.988242]  dump_stack_lvl+0xd7/0xf0
>[   12.988248]  dump_stack+0x10/0x20
>[   12.988250]  ubsan_epilogue+0x9/0x40
>[   12.988253]  __ubsan_handle_shift_out_of_bounds+0x10e/0x170
>[   12.988260]  dma_resv_reserve_fences.cold+0x2b/0x48
>[   12.988262]  ? ww_mutex_lock_interruptible+0x3c/0x110
>[   12.988267]  drm_exec_prepare_obj+0x45/0x60 [drm_exec]
>[   12.988271]  ? vm_bind_ioctl_ops_execute+0x5b/0x740 [xe]
>[   12.988345]  vm_bind_ioctl_ops_execute+0x78/0x740 [xe]
>
>It is caused by the value 0 of parameter num_fences in function drm_exec_prepare_obj.
>And lead to in function __rounddown_pow_of_two, "0 - 1" causes the shift-out-of-bounds.

ok

>For num_fences == 0 case, drm_exec_prepare_obj is the same as drm_exec_lock_obj in
>function, so call drm_exec_lock_obj instead to solve it.

this is not true and per discussion in this thread it's not going to
change. drm_exec_prepare_obj() should not be called with num_fences ==
0. So I'd reworded with something like below so we have all breadcrumbs
for anyone trying to understand the changes later:

	By design drm_exec_prepare_obj() should be called only when there are
	fences to be reserved. If num_fences is 0, calling drm_exec_lock_obj()
	is sufficient as was done in commit 9377de4cb3e8 ("drm/xe/vm: Avoid
	reserving zero fences")

>
>Cc: Nirmoy Das <nirmoy.das@intel.com>
>Cc: Matthew Brost <matthew.brost@intel.com>
>Signed-off-by: Shuicheng Lin <shuicheng.lin@intel.com>

with the reword,

Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>

And also add:
Link: https://lore.kernel.org/all/24d4a9a9-c622-4f56-8672-21f4c6785476@amd.com

Could you also submit a patch to add the warning like mentioned by
Christian?

thanks
Lucas De Marchi

>---
> drivers/gpu/drm/xe/xe_vm.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
>diff --git a/drivers/gpu/drm/xe/xe_vm.c b/drivers/gpu/drm/xe/xe_vm.c
>index d17192c8b7de..c5b1694b292f 100644
>--- a/drivers/gpu/drm/xe/xe_vm.c
>+++ b/drivers/gpu/drm/xe/xe_vm.c
>@@ -2692,7 +2692,7 @@ static int vma_lock_and_validate(struct drm_exec *exec, struct xe_vma *vma,
>
> 	if (bo) {
> 		if (!bo->vm)
>-			err = drm_exec_prepare_obj(exec, &bo->ttm.base, 0);
>+			err = drm_exec_lock_obj(exec, &bo->ttm.base);
> 		if (!err && validate)
> 			err = xe_bo_validate(bo, xe_vma_vm(vma), true);
> 	}
>@@ -2777,7 +2777,7 @@ static int vm_bind_ioctl_ops_lock_and_prep(struct drm_exec *exec,
> 	struct xe_vma_op *op;
> 	int err;
>
>-	err = drm_exec_prepare_obj(exec, xe_vm_obj(vm), 0);
>+	err = drm_exec_lock_obj(exec, xe_vm_obj(vm));
> 	if (err)
> 		return err;
>
>-- 
>2.25.1
>

      parent reply	other threads:[~2024-05-09  3:38 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20240507080456.613786-1-shuicheng.lin@intel.com>
     [not found] ` <2a9a7bb2-c74d-44fb-b9d2-cbb42e462d0f@linux.intel.com>
     [not found]   ` <96b6a562-eeaf-49f9-9ade-d58fb061086d@linux.intel.com>
2024-05-07 13:18     ` [PATCH] drm/xe: Fix UBSAN shift-out-of-bounds failure Lucas De Marchi
2024-05-07 13:23       ` Christian König
     [not found] ` <20240507130411.630361-1-shuicheng.lin@intel.com>
2024-05-09  3:38   ` Lucas De Marchi [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=dc7rmhsjbvtqddqvz465zo6esyiy7xengp43jepmvpaxvksuzv@bl6sq3upfy44 \
    --to=lucas.demarchi@intel.com \
    --cc=christian.koenig@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=matthew.brost@intel.com \
    --cc=nirmoy.das@intel.com \
    --cc=shuicheng.lin@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).