From: "Thomas Hellström" <thomas.hellstrom@linux.intel.com>
To: intel-xe@lists.freedesktop.org
Subject: [Intel-xe] [PATCH] xe/xe_bo: Reject bo creation of unaligned size
Date: Tue, 17 Oct 2023 18:32:43 +0200 [thread overview]
Message-ID: <20231017163243.14112-1-thomas.hellstrom@linux.intel.com> (raw)
From: Mauro Carvalho Chehab <mauro.chehab@linux.intel.com>
For xe bo creation we request passing size which matches system or
vram minimum page alignment. This way we want to ensure userspace
is aware of region constraints and not aligned allocations will be
rejected returning EINVAL.
Signed-off-by: Mauro Carvalho Chehab <mauro.chehab@linux.intel.com>
Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski@intel.com>
Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
---
drivers/gpu/drm/xe/xe_bo.c | 24 ++++++++++++++++--------
include/uapi/drm/xe_drm.h | 25 +++++++++++++++++--------
2 files changed, 33 insertions(+), 16 deletions(-)
diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
index 61789c0e88fb..beed93003d40 100644
--- a/drivers/gpu/drm/xe/xe_bo.c
+++ b/drivers/gpu/drm/xe/xe_bo.c
@@ -1201,6 +1201,7 @@ struct xe_bo *__xe_bo_create_locked(struct xe_device *xe, struct xe_bo *bo,
};
struct ttm_placement *placement;
uint32_t alignment;
+ size_t aligned_size;
int err;
/* Only kernel objects should set GT */
@@ -1211,23 +1212,30 @@ struct xe_bo *__xe_bo_create_locked(struct xe_device *xe, struct xe_bo *bo,
return ERR_PTR(-EINVAL);
}
- if (!bo) {
- bo = xe_bo_alloc();
- if (IS_ERR(bo))
- return bo;
- }
-
if (flags & (XE_BO_CREATE_VRAM_MASK | XE_BO_CREATE_STOLEN_BIT) &&
!(flags & XE_BO_CREATE_IGNORE_MIN_PAGE_SIZE_BIT) &&
xe->info.vram_flags & XE_VRAM_FLAGS_NEED64K) {
- size = ALIGN(size, SZ_64K);
+ aligned_size = ALIGN(size, SZ_64K);
+ if (type != ttm_bo_type_device)
+ size = ALIGN(size, SZ_64K);
flags |= XE_BO_INTERNAL_64K;
alignment = SZ_64K >> PAGE_SHIFT;
+
} else {
- size = ALIGN(size, PAGE_SIZE);
+ aligned_size = ALIGN(size, SZ_4K);
+ flags &= ~XE_BO_INTERNAL_64K;
alignment = SZ_4K >> PAGE_SHIFT;
}
+ if (type == ttm_bo_type_device && aligned_size != size)
+ return ERR_PTR(-EINVAL);
+
+ if (!bo) {
+ bo = xe_bo_alloc();
+ if (IS_ERR(bo))
+ return bo;
+ }
+
bo->tile = tile;
bo->size = size;
bo->flags = flags;
diff --git a/include/uapi/drm/xe_drm.h b/include/uapi/drm/xe_drm.h
index 24bf8f0f52e8..ed12dc212ff1 100644
--- a/include/uapi/drm/xe_drm.h
+++ b/include/uapi/drm/xe_drm.h
@@ -185,11 +185,13 @@ struct drm_xe_query_mem_region {
*
* When the kernel allocates memory for this region, the
* underlying pages will be at least @min_page_size in size.
- *
- * Important note: When userspace allocates a GTT address which
- * can point to memory allocated from this region, it must also
- * respect this minimum alignment. This is enforced by the
- * kernel.
+ * Buffer objects with an allowable placement in this region must be
+ * created with a size aligned to this value.
+ * GPU virtual address mappings of (parts of) buffer objects that
+ * may be placed in this region must also have their GPU virtual
+ * address and range aligned to this value.
+ * Affected IOCTLS will return %-EINVAL if alignment restrictions are
+ * not met.
*/
__u32 min_page_size;
/**
@@ -324,6 +326,14 @@ struct drm_xe_query_config {
#define XE_QUERY_CONFIG_REV_AND_DEVICE_ID 0
#define XE_QUERY_CONFIG_FLAGS 1
#define XE_QUERY_CONFIG_FLAGS_HAS_VRAM (0x1 << 0)
+ /*
+ * DRM_XE_QUERY_CONFIG_MIN_ALIGNMENT - This returns the
+ * maximum value of the &min_page_size across all memory regions
+ * the device implements. User-space code that does not want
+ * to track @min_page_size per region can use this value for
+ * a buffer-object size and GPU virtual address and -range
+ * alignment value that is valid for all regions.
+ */
#define XE_QUERY_CONFIG_MIN_ALIGNMENT 2
#define XE_QUERY_CONFIG_VA_BITS 3
#define XE_QUERY_CONFIG_GT_COUNT 4
@@ -501,9 +511,8 @@ struct drm_xe_gem_create {
__u64 extensions;
/**
- * @size: Requested size for the object
- *
- * The (page-aligned) allocated size for the object will be returned.
+ * @size: Size of the object to be created, must match region
+ * (system or vram) minimum alignment (&min_page_size).
*/
__u64 size;
--
2.41.0
next reply other threads:[~2023-10-17 16:33 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-17 16:32 Thomas Hellström [this message]
2023-10-17 16:54 ` [Intel-xe] ✓ CI.Patch_applied: success for xe/xe_bo: Reject bo creation of unaligned size (rev2) Patchwork
2023-10-17 16:54 ` [Intel-xe] ✗ CI.checkpatch: warning " Patchwork
2023-10-17 16:55 ` [Intel-xe] ✓ CI.KUnit: success " Patchwork
2023-10-17 17:02 ` [Intel-xe] ✓ CI.Build: " Patchwork
2023-10-17 17:03 ` [Intel-xe] ✓ CI.Hooks: " Patchwork
2023-10-17 17:04 ` [Intel-xe] ✓ CI.checksparse: " Patchwork
2023-10-17 17:37 ` [Intel-xe] ✗ CI.BAT: failure " Patchwork
-- strict thread matches above, loose matches on Subject: below --
2023-04-13 6:56 [Intel-xe] [PATCH] xe/xe_bo: Reject bo creation of unaligned size Zbigniew Kempczyński
2023-04-20 8:52 ` Thomas Hellström
2023-05-26 15:40 ` Souza, Jose
2023-05-31 12:52 ` Zbigniew Kempczyński
2023-05-31 13:04 ` Souza, Jose
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=20231017163243.14112-1-thomas.hellstrom@linux.intel.com \
--to=thomas.hellstrom@linux.intel.com \
--cc=intel-xe@lists.freedesktop.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.