Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Shekhar Chauhan <shekhar.chauhan@intel.com>
To: Umesh Nerlige Ramappa <umesh.nerlige.ramappa@intel.com>,
	<intel-xe@lists.freedesktop.org>, <harish.chegondi@intel.com>
Cc: <matthew.brost@intel.com>
Subject: Re: [PATCH v8 2/8] drm/xe/oa: Use the drm device address_space for the OA stream fd
Date: Fri, 20 Nov 2026 12:53:46 +0530	[thread overview]
Message-ID: <e6ecfa7e-3949-4907-8676-3d39f9663df6@intel.com> (raw)
In-Reply-To: <20261119002737.3899877-12-umesh.nerlige.ramappa@intel.com>


On 11/19/2026 5:57, Umesh Nerlige Ramappa wrote:
> anon_inode_getfd() hands back a file whose f_mapping points at the
> address_space of the kernel-wide singleton anon_inode_inode, shared by
> every other anon_inode_getfd()/anon_inode_getfile() user in the system.
> Any code that needs to invalidate userspace mappings of the OA buffer
> via that mapping (e.g. unmap_mapping_range()) would end up operating on
> an address_space it doesn't own, with the potential to affect unrelated
> mappings.
>
> Keep the anon inode singleton and only point the file's f_mapping at the
> drm device's address_space (drm.anon_inode->i_mapping), same as drm_file
> does for drm fds. f_mapping must be set before the fd is visible to
> userspace, so reserve the fd with get_unused_fd_flags(), create the file
> with anon_inode_getfile() and install it with fd_install() after setting
> f_mapping.
>
> To keep the OA buffer mmaps of different streams apart from each other
> and from GEM mmaps in that shared address_space, reserve a GEM fake
> offset for the OA buffer with drm_gem_create_mmap_offset(), and move
> the vma to that offset in xe_oa_mmap() by setting vm_pgoff, the same
> way drm_gem_prime_mmap() does. f_op->mmap runs before the vma is linked
> into the address_space, so the vma is tracked at the OA buffer's own
> range, and drm_vma_node_unmap() on the OA buffer only zaps mappings of
> that buffer. The TTM fault handler already subtracts the fake offset
> from vm_pgoff, so faults resolve to the right pages unchanged.
>
> drm_dev_unplug() now also zaps OA buffer mmaps along with all other
> mmaps of the drm device.
>
> Signed-off-by: Umesh Nerlige Ramappa <umesh.nerlige.ramappa@intel.com>

Apart from changes for this series, EU_STALL still uses 
anon_inode_getfd().  I suppose Harish or someone will address that?

But, with that aside, the current changes LGTM, and with that,

Reviewed-by: Shekhar Chauhan <shekhar.chauhan@intel.com>

> ---
>   drivers/gpu/drm/xe/xe_oa.c | 41 +++++++++++++++++++++++++++++++++++++-
>   1 file changed, 40 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/xe/xe_oa.c b/drivers/gpu/drm/xe/xe_oa.c
> index fdd2d11ce4e7..d574b0ecf39b 100644
> --- a/drivers/gpu/drm/xe/xe_oa.c
> +++ b/drivers/gpu/drm/xe/xe_oa.c
> @@ -917,6 +917,7 @@ static int xe_oa_alloc_oa_buffer(struct xe_oa_stream *stream, size_t size)
>   		XE_BO_FLAG_VRAM_IF_DGFX(xe_device_get_root_tile(stream->oa->xe)) :
>   		XE_BO_FLAG_SYSTEM;
>   	struct xe_bo *bo;
> +	int ret;
>   
>   	bo = xe_bo_create_pin_map_novm(stream->oa->xe, stream->gt->tile,
>   				       size, ttm_bo_type_kernel,
> @@ -924,6 +925,17 @@ static int xe_oa_alloc_oa_buffer(struct xe_oa_stream *stream, size_t size)
>   	if (IS_ERR(bo))
>   		return PTR_ERR(bo);
>   
> +	/*
> +	 * Reserve a range for the OA buffer in the drm device's address_space, so that its
> +	 * userspace mmaps don't overlap with those of GEM BOs or other OA buffers and can be
> +	 * unmapped on their own. Not granted to any drm_file, so not mmap'able via drm fds.
> +	 */
> +	ret = drm_gem_create_mmap_offset(&bo->ttm.base);
> +	if (ret) {
> +		xe_bo_unpin_map_no_vm(bo);
> +		return ret;
> +	}
> +
>   	/*
>   	 * ttm_bo_type_kernel BOs are not zeroed on allocation, so the buffer can
>   	 * hold stale data from previously freed pages. Since the OA buffer is
> @@ -1731,6 +1743,15 @@ static int xe_oa_mmap(struct file *file, struct vm_area_struct *vma)
>   		return ret;
>   	}
>   
> +	/*
> +	 * Userspace always maps the OA buffer at offset 0, the mapping is moved to the OA
> +	 * buffer's own range in the drm device's address_space below
> +	 */
> +	if (vma->vm_pgoff) {
> +		drm_dbg(&stream->oa->xe->drm, "Wrong mmap offset, must be 0\n");
> +		return -EINVAL;
> +	}
> +
>   	/* Can mmap the entire OA buffer or nothing (no partial OA buffer mmaps) */
>   	if (vma->vm_end - vma->vm_start != xe_bo_size(bo)) {
>   		drm_dbg(&stream->oa->xe->drm, "Wrong mmap size, must be OA buffer size\n");
> @@ -1748,6 +1769,8 @@ static int xe_oa_mmap(struct file *file, struct vm_area_struct *vma)
>   	vm_flags_mod(vma, VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP | VM_DONTCOPY,
>   		     VM_MAYWRITE | VM_MAYEXEC);
>   
> +	vma->vm_pgoff = drm_vma_node_start(&bo->ttm.base.vma_node);
> +
>   	return drm_gem_mmap_obj(&bo->ttm.base, xe_bo_size(bo), vma);
>   }
>   
> @@ -1878,6 +1901,7 @@ static int xe_oa_stream_open_ioctl_locked(struct xe_oa *oa,
>   {
>   	struct xe_oa_stream *stream;
>   	struct drm_syncobj *ufence_syncobj;
> +	struct file *file;
>   	int stream_fd;
>   	int ret;
>   
> @@ -1919,12 +1943,27 @@ static int xe_oa_stream_open_ioctl_locked(struct xe_oa *oa,
>   			goto err_destroy;
>   	}
>   
> -	stream_fd = anon_inode_getfd("[xe_oa]", &xe_oa_fops, stream, 0);
> +	stream_fd = get_unused_fd_flags(0);
>   	if (stream_fd < 0) {
>   		ret = stream_fd;
>   		goto err_disable;
>   	}
>   
> +	file = anon_inode_getfile("[xe_oa]", &xe_oa_fops, stream, 0);
> +	if (IS_ERR(file)) {
> +		ret = PTR_ERR(file);
> +		put_unused_fd(stream_fd);
> +		goto err_disable;
> +	}
> +
> +	/*
> +	 * Don't use the address_space of the anon inode singleton, which is shared with
> +	 * unrelated anon files. Use the drm device's address_space instead, same as drm fds.
> +	 * OA buffer mmaps live at the OA buffer's own fake offset range there.
> +	 */
> +	file->f_mapping = oa->xe->drm.anon_inode->i_mapping;
> +	fd_install(stream_fd, file);
> +
>   	if (stream->sample)
>   		xe_reg_whitelist_oa_regs(stream->gt);
>   

-- 
Shekhar Chauhan
Linux Graphics Software Engineer
Linux Platform Enabling
Intel Corporation


  parent reply	other threads:[~2026-11-20  7:24 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19  0:27 [PATCH v8 0/8] Cleanup OA stream on PCI unbind/remove Umesh Nerlige Ramappa
2026-11-19  0:27 ` [PATCH v8 1/8] drm/xe/oa: Ignore a HW tail pointer outside the OA buffer Umesh Nerlige Ramappa
2026-11-19  0:39   ` sashiko-bot
2026-11-20  7:21   ` Shekhar Chauhan
2026-11-19  0:27 ` [PATCH v8 2/8] drm/xe/oa: Use the drm device address_space for the OA stream fd Umesh Nerlige Ramappa
2026-11-19  0:39   ` sashiko-bot
2026-11-20  7:23   ` Shekhar Chauhan [this message]
2026-11-19  0:27 ` [PATCH v8 3/8] drm/xe/oa: Wait for in-flight OA batches before stream HW teardown Umesh Nerlige Ramappa
2026-11-20  7:24   ` Shekhar Chauhan
2026-11-19  0:27 ` [PATCH v8 4/8] drm/xe: Reject vm_ops->access on BO mappings of an unplugged device Umesh Nerlige Ramappa
2026-11-19  0:39   ` sashiko-bot
2026-11-19 22:36   ` Matthew Brost
2026-11-19  0:27 ` [PATCH v8 5/8] drm/xe/oa: Fence OA ioctls and mmap against device unplug and wedging Umesh Nerlige Ramappa
2026-11-20  7:25   ` Shekhar Chauhan
2026-11-19  0:27 ` [PATCH v8 6/8] drm/xe/oa: Take the runtime PM reference in xe_oa_destroy_locked() Umesh Nerlige Ramappa
2026-11-20  7:27   ` Shekhar Chauhan
2026-11-19  0:27 ` [PATCH v8 7/8] drm/xe/oa: Free the OA buffer and the stream after the stream destroy Umesh Nerlige Ramappa
2026-11-19  0:48   ` sashiko-bot
2026-11-20  7:29   ` Shekhar Chauhan
2026-11-19  0:27 ` [PATCH v8 8/8] drm/xe/oa: Quiesce OA streams on driver unbind and PCI reset Umesh Nerlige Ramappa
2026-11-19  1:11   ` sashiko-bot
2026-11-20  7:31     ` Shekhar Chauhan
2026-11-19  6:05 ` ✓ CI.KUnit: success for Cleanup OA stream on PCI unbind/remove (rev8) Patchwork
2026-11-19  6:46 ` ✓ 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=e6ecfa7e-3949-4907-8676-3d39f9663df6@intel.com \
    --to=shekhar.chauhan@intel.com \
    --cc=harish.chegondi@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=matthew.brost@intel.com \
    --cc=umesh.nerlige.ramappa@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