* [PATCH v2 2/2] drm/xe: Allow mixed mappings for userptr
[not found] <20251010104149.72783-1-thomas.hellstrom@linux.intel.com>
@ 2025-10-14 11:08 ` Thomas Hellström
2025-10-15 12:54 ` Maarten Lankhorst
0 siblings, 1 reply; 2+ messages in thread
From: Thomas Hellström @ 2025-10-14 11:08 UTC (permalink / raw)
To: dri-devel
+ dri-devel.
From: Matthew Brost <matthew.brost@intel.com>
Compute kernels often issue memory copies immediately after completion.
If the memory being copied is an SVM pointer that was faulted into the
device and then bound via userptr, it is undesirable to move that
memory. Worse, if userptr is mixed between system and device memory,
the
bind operation may be rejected.
Xe already has the necessary plumbing to support userptr with mixed
mappings. This update modifies GPUSVM's get_pages to correctly locate
pages in such mixed mapping scenarios.
v2:
- Rebase (Thomas Hellström)
v3:
- Remove Fixes tag.
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
Reviewed-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Reviewed-by: Matthew Auld <matthew.auld@intel.com>
---
drivers/gpu/drm/drm_gpusvm.c | 6 ++++--
drivers/gpu/drm/xe/xe_userptr.c | 4 +++-
include/drm/drm_gpusvm.h | 4 ++++
3 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/drivers/gpu/drm/drm_gpusvm.c
b/drivers/gpu/drm/drm_gpusvm.c
index cb906765897e..73e550c8ff8c 100644
--- a/drivers/gpu/drm/drm_gpusvm.c
+++ b/drivers/gpu/drm/drm_gpusvm.c
@@ -1363,7 +1363,8 @@ int drm_gpusvm_get_pages(struct drm_gpusvm
*gpusvm,
order = drm_gpusvm_hmm_pfn_to_order(pfns[i], i,
npages);
if (is_device_private_page(page) ||
is_device_coherent_page(page)) {
- if (zdd != page->zone_device_data && i > 0) {
+ if (!ctx->allow_mixed &&
+ zdd != page->zone_device_data && i > 0) {
err = -EOPNOTSUPP;
goto err_unmap;
}
@@ -1399,7 +1400,8 @@ int drm_gpusvm_get_pages(struct drm_gpusvm
*gpusvm,
} else {
dma_addr_t addr;
- if (is_zone_device_page(page) || pagemap) {
+ if (is_zone_device_page(page) ||
+ (pagemap && !ctx->allow_mixed)) {
err = -EOPNOTSUPP;
goto err_unmap;
}
diff --git a/drivers/gpu/drm/xe/xe_userptr.c
b/drivers/gpu/drm/xe/xe_userptr.c
index f16e92cd8090..0d9130b1958a 100644
--- a/drivers/gpu/drm/xe/xe_userptr.c
+++ b/drivers/gpu/drm/xe/xe_userptr.c
@@ -3,6 +3,7 @@
* Copyright © 2025 Intel Corporation
*/
+#include "xe_svm.h"
#include "xe_userptr.h"
#include <linux/mm.h>
@@ -54,7 +55,8 @@ int xe_vma_userptr_pin_pages(struct xe_userptr_vma
*uvma)
struct xe_device *xe = vm->xe;
struct drm_gpusvm_ctx ctx = {
.read_only = xe_vma_read_only(vma),
- .device_private_page_owner = NULL,
+ .device_private_page_owner = xe_svm_devm_owner(xe),
+ .allow_mixed = true,
};
lockdep_assert_held(&vm->lock);
diff --git a/include/drm/drm_gpusvm.h b/include/drm/drm_gpusvm.h
index b92faa9a26b2..632e100e6efb 100644
--- a/include/drm/drm_gpusvm.h
+++ b/include/drm/drm_gpusvm.h
@@ -235,6 +235,9 @@ struct drm_gpusvm {
* @read_only: operating on read-only memory
* @devmem_possible: possible to use device memory
* @devmem_only: use only device memory
+ * @allow_mixed: Allow mixed mappings in get pages. Mixing between
system and
+ * single dpagemap is supported, mixing between multiple
dpagemap
+ * is unsupported.
*
* Context that is DRM GPUSVM is operating in (i.e. user arguments).
*/
@@ -246,6 +249,7 @@ struct drm_gpusvm_ctx {
unsigned int read_only :1;
unsigned int devmem_possible :1;
unsigned int devmem_only :1;
+ unsigned int allow_mixed :1;
};
int drm_gpusvm_init(struct drm_gpusvm *gpusvm,
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2 2/2] drm/xe: Allow mixed mappings for userptr
2025-10-14 11:08 ` [PATCH v2 2/2] drm/xe: Allow mixed mappings for userptr Thomas Hellström
@ 2025-10-15 12:54 ` Maarten Lankhorst
0 siblings, 0 replies; 2+ messages in thread
From: Maarten Lankhorst @ 2025-10-15 12:54 UTC (permalink / raw)
To: Thomas Hellström, dri-devel
Acked-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Den 2025-10-14 kl. 13:08, skrev Thomas Hellström:
> + dri-devel.
>
> From: Matthew Brost <matthew.brost@intel.com>
>
> Compute kernels often issue memory copies immediately after completion.
> If the memory being copied is an SVM pointer that was faulted into the
> device and then bound via userptr, it is undesirable to move that
> memory. Worse, if userptr is mixed between system and device memory,
> the
> bind operation may be rejected.
>
> Xe already has the necessary plumbing to support userptr with mixed
> mappings. This update modifies GPUSVM's get_pages to correctly locate
> pages in such mixed mapping scenarios.
>
> v2:
> - Rebase (Thomas Hellström)
> v3:
> - Remove Fixes tag.
>
> Signed-off-by: Matthew Brost <matthew.brost@intel.com>
> Reviewed-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
> Reviewed-by: Matthew Auld <matthew.auld@intel.com>
> ---
> drivers/gpu/drm/drm_gpusvm.c | 6 ++++--
> drivers/gpu/drm/xe/xe_userptr.c | 4 +++-
> include/drm/drm_gpusvm.h | 4 ++++
> 3 files changed, 11 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_gpusvm.c
> b/drivers/gpu/drm/drm_gpusvm.c
> index cb906765897e..73e550c8ff8c 100644
> --- a/drivers/gpu/drm/drm_gpusvm.c
> +++ b/drivers/gpu/drm/drm_gpusvm.c
> @@ -1363,7 +1363,8 @@ int drm_gpusvm_get_pages(struct drm_gpusvm
> *gpusvm,
> order = drm_gpusvm_hmm_pfn_to_order(pfns[i], i,
> npages);
> if (is_device_private_page(page) ||
> is_device_coherent_page(page)) {
> - if (zdd != page->zone_device_data && i > 0) {
> + if (!ctx->allow_mixed &&
> + zdd != page->zone_device_data && i > 0) {
> err = -EOPNOTSUPP;
> goto err_unmap;
> }
> @@ -1399,7 +1400,8 @@ int drm_gpusvm_get_pages(struct drm_gpusvm
> *gpusvm,
> } else {
> dma_addr_t addr;
>
> - if (is_zone_device_page(page) || pagemap) {
> + if (is_zone_device_page(page) ||
> + (pagemap && !ctx->allow_mixed)) {
> err = -EOPNOTSUPP;
> goto err_unmap;
> }
> diff --git a/drivers/gpu/drm/xe/xe_userptr.c
> b/drivers/gpu/drm/xe/xe_userptr.c
> index f16e92cd8090..0d9130b1958a 100644
> --- a/drivers/gpu/drm/xe/xe_userptr.c
> +++ b/drivers/gpu/drm/xe/xe_userptr.c
> @@ -3,6 +3,7 @@
> * Copyright © 2025 Intel Corporation
> */
>
> +#include "xe_svm.h"
> #include "xe_userptr.h"
>
> #include <linux/mm.h>
> @@ -54,7 +55,8 @@ int xe_vma_userptr_pin_pages(struct xe_userptr_vma
> *uvma)
> struct xe_device *xe = vm->xe;
> struct drm_gpusvm_ctx ctx = {
> .read_only = xe_vma_read_only(vma),
> - .device_private_page_owner = NULL,
> + .device_private_page_owner = xe_svm_devm_owner(xe),
> + .allow_mixed = true,
> };
>
> lockdep_assert_held(&vm->lock);
> diff --git a/include/drm/drm_gpusvm.h b/include/drm/drm_gpusvm.h
> index b92faa9a26b2..632e100e6efb 100644
> --- a/include/drm/drm_gpusvm.h
> +++ b/include/drm/drm_gpusvm.h
> @@ -235,6 +235,9 @@ struct drm_gpusvm {
> * @read_only: operating on read-only memory
> * @devmem_possible: possible to use device memory
> * @devmem_only: use only device memory
> + * @allow_mixed: Allow mixed mappings in get pages. Mixing between
> system and
> + * single dpagemap is supported, mixing between multiple
> dpagemap
> + * is unsupported.
> *
> * Context that is DRM GPUSVM is operating in (i.e. user arguments).
> */
> @@ -246,6 +249,7 @@ struct drm_gpusvm_ctx {
> unsigned int read_only :1;
> unsigned int devmem_possible :1;
> unsigned int devmem_only :1;
> + unsigned int allow_mixed :1;
> };
>
> int drm_gpusvm_init(struct drm_gpusvm *gpusvm,
>
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-10-15 12:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20251010104149.72783-1-thomas.hellstrom@linux.intel.com>
2025-10-14 11:08 ` [PATCH v2 2/2] drm/xe: Allow mixed mappings for userptr Thomas Hellström
2025-10-15 12:54 ` Maarten Lankhorst
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox