Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Matthew Brost <matthew.brost@intel.com>
To: Shuicheng Lin <shuicheng.lin@intel.com>
Cc: intel-xe@lists.freedesktop.org,
	"Koen Koning" <koen.koning@intel.com>,
	"Peter Senna Tschudin" <peter.senna@linux.intel.com>,
	stable@vger.kernel.org, "Michal Mrozek" <michal.mrozek@intel.com>,
	"Carl Zhang" <carl.zhang@intel.com>,
	"José Roberto de Souza" <jose.souza@intel.com>,
	"Lionel Landwerlin" <lionel.g.landwerlin@intel.com>,
	"Ivan Briano" <ivan.briano@intel.com>,
	"Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
	"Ashutosh Dixit" <ashutosh.dixit@intel.com>
Subject: Re: [PATCH 1/3] drm/xe/exec: Limit num_syncs to prevent oversized allocations
Date: Fri, 5 Dec 2025 13:23:33 -0800	[thread overview]
Message-ID: <aTNNVbxLg9DBDmP2@lstrano-desk.jf.intel.com> (raw)
In-Reply-To: <20251205190506.2426471-6-shuicheng.lin@intel.com>

On Fri, Dec 05, 2025 at 07:05:08PM +0000, Shuicheng Lin wrote:
> The exec ioctl allows userspace to specify an arbitrary num_syncs
> value. Without bounds checking, a very large num_syncs can force
> an excessively large allocation, leading to kernel warnings from
> the page allocator as below.
> 
> Introduce XE_MAX_SYNCS (set to 1024) and reject any request
> exceeding this limit.
> 
> "
> ------------[ cut here ]------------
> WARNING: CPU: 0 PID: 1217 at mm/page_alloc.c:5124 __alloc_frozen_pages_noprof+0x2f8/0x2180 mm/page_alloc.c:5124
> ...
> Call Trace:
>  <TASK>
>  alloc_pages_mpol+0xe4/0x330 mm/mempolicy.c:2416
>  ___kmalloc_large_node+0xd8/0x110 mm/slub.c:4317
>  __kmalloc_large_node_noprof+0x18/0xe0 mm/slub.c:4348
>  __do_kmalloc_node mm/slub.c:4364 [inline]
>  __kmalloc_noprof+0x3d4/0x4b0 mm/slub.c:4388
>  kmalloc_noprof include/linux/slab.h:909 [inline]
>  kmalloc_array_noprof include/linux/slab.h:948 [inline]
>  xe_exec_ioctl+0xa47/0x1e70 drivers/gpu/drm/xe/xe_exec.c:158
>  drm_ioctl_kernel+0x1f1/0x3e0 drivers/gpu/drm/drm_ioctl.c:797
>  drm_ioctl+0x5e7/0xc50 drivers/gpu/drm/drm_ioctl.c:894
>  xe_drm_ioctl+0x10b/0x170 drivers/gpu/drm/xe/xe_device.c:224
>  vfs_ioctl fs/ioctl.c:51 [inline]
>  __do_sys_ioctl fs/ioctl.c:598 [inline]
>  __se_sys_ioctl fs/ioctl.c:584 [inline]
>  __x64_sys_ioctl+0x18b/0x210 fs/ioctl.c:584
>  do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
>  do_syscall_64+0xbb/0x380 arch/x86/entry/syscall_64.c:94
>  entry_SYSCALL_64_after_hwframe+0x77/0x7f
> ...
> "
> 
> v2: Add "Reported-by" and Cc stable kernels.
> v3: Change XE_MAX_SYNCS from 64 to 1024. (Matt & Ashutosh)
> 
> Closes: https://gitlab.freedesktop.org/drm/xe/kernel/-/issues/6450
> Fixes: dd08ebf6c352 ("drm/xe: Introduce a new DRM driver for Intel GPUs")
> Reported-by: Koen Koning <koen.koning@intel.com>
> Reported-by: Peter Senna Tschudin <peter.senna@linux.intel.com>
> Cc: <stable@vger.kernel.org> # v6.12+
> Cc: Matthew Brost <matthew.brost@intel.com>
> Cc: Michal Mrozek <michal.mrozek@intel.com>
> Cc: Carl Zhang <carl.zhang@intel.com>
> Cc: José Roberto de Souza <jose.souza@intel.com>
> Cc: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
> Cc: Ivan Briano <ivan.briano@intel.com>
> Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
> Cc: Ashutosh Dixit <ashutosh.dixit@intel.com>
> Signed-off-by: Shuicheng Lin <shuicheng.lin@intel.com>
> ---
>  drivers/gpu/drm/xe/xe_exec.c | 5 +++++
>  include/uapi/drm/xe_drm.h    | 1 +
>  2 files changed, 6 insertions(+)
> 
> diff --git a/drivers/gpu/drm/xe/xe_exec.c b/drivers/gpu/drm/xe/xe_exec.c
> index 4d81210e41f5..fdc7d410defa 100644
> --- a/drivers/gpu/drm/xe/xe_exec.c
> +++ b/drivers/gpu/drm/xe/xe_exec.c
> @@ -162,6 +162,11 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
>  	}
>  
>  	if (args->num_syncs) {
> +		if (XE_IOCTL_DBG(xe, args->num_syncs > XE_MAX_SYNCS)) {
> +			err = -EINVAL;
> +			goto err_exec_queue;
> +		}
> +
>  		syncs = kcalloc(args->num_syncs, sizeof(*syncs), GFP_KERNEL);
>  		if (!syncs) {
>  			err = -ENOMEM;
> diff --git a/include/uapi/drm/xe_drm.h b/include/uapi/drm/xe_drm.h
> index 876a076fa6c0..ae040989fca8 100644
> --- a/include/uapi/drm/xe_drm.h
> +++ b/include/uapi/drm/xe_drm.h
> @@ -1237,6 +1237,7 @@ struct drm_xe_vm_bind {
>  	/** @pad2: MBZ */
>  	__u32 pad2;
>  
> +#define XE_MAX_SYNCS 1024

s/XE_MAX_SYNCS/DRM_XE_MAX_SYNCS/

I think this patch and the next can be squashed into the same patch
since they fix the same baseline patch but keep the OA part seperate.

Matt

>  	/** @num_syncs: amount of syncs to wait on */
>  	__u32 num_syncs;
>  
> -- 
> 2.50.1
> 

  reply	other threads:[~2025-12-05 21:23 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-05 19:05 [PATCH 0/3] Limit num_syncs to prevent oversized allocations Shuicheng Lin
2025-12-05 19:05 ` [PATCH 1/3] drm/xe/exec: " Shuicheng Lin
2025-12-05 21:23   ` Matthew Brost [this message]
2025-12-05 19:05 ` [PATCH 2/3] drm/xe/vm: " Shuicheng Lin
2025-12-05 19:05 ` [PATCH 3/3] drm/xe/oa: " Shuicheng Lin
2025-12-05 20:36   ` Dixit, Ashutosh
2025-12-05 20:55     ` Matthew Brost
2025-12-05 21:06       ` Dixit, Ashutosh
2025-12-05 22:03 ` ✗ CI.checkpatch: warning for " Patchwork
2025-12-05 22:05 ` ✓ CI.KUnit: success " Patchwork
2025-12-05 23:08 ` ✓ Xe.CI.BAT: " Patchwork

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=aTNNVbxLg9DBDmP2@lstrano-desk.jf.intel.com \
    --to=matthew.brost@intel.com \
    --cc=ashutosh.dixit@intel.com \
    --cc=carl.zhang@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=ivan.briano@intel.com \
    --cc=jose.souza@intel.com \
    --cc=koen.koning@intel.com \
    --cc=lionel.g.landwerlin@intel.com \
    --cc=michal.mrozek@intel.com \
    --cc=peter.senna@linux.intel.com \
    --cc=shuicheng.lin@intel.com \
    --cc=stable@vger.kernel.org \
    --cc=thomas.hellstrom@linux.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