[igt-dev] [PATCH i-g-t 1/3] lib/intel_allocator: Check validity of the file descriptor

Andrzej Turko andrzej.turko at linux.intel.com
Wed Jun 16 14:01:56 UTC 2021


All procedures for opening particular types of allocators
query the gtt size. Even if the user has provided the
boundaries of the address space managed by the allocator,
the query is performed for the sake of validation.

gem_aperture_size() called with an invalid id returns a
default value instead of failing. Thus, we need to
additionally check whether the file descriptor is valid.

Signed-off-by: Andrzej Turko <andrzej.turko at linux.intel.com>
Cc: Zbigniew Kempczyński <zbigniew.kempczynski at intel.com>
---
 lib/intel_allocator.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/lib/intel_allocator.c b/lib/intel_allocator.c
index 96f839d4b..c060e10c3 100644
--- a/lib/intel_allocator.c
+++ b/lib/intel_allocator.c
@@ -166,6 +166,15 @@ static inline void map_entry_free_func(struct igt_map_entry *entry)
 	free(entry->data);
 }
 
+static bool can_report_gtt_size(int fd)
+{
+	struct drm_i915_gem_context_param p = {
+		.param = I915_CONTEXT_PARAM_GTT_SIZE
+	};
+
+	return (__gem_context_get_param(fd, &p) == 0);
+}
+
 static uint64_t __handle_create(struct allocator *al)
 {
 	struct handle_entry *h = malloc(sizeof(*h));
@@ -271,6 +280,8 @@ static struct intel_allocator *intel_allocator_create(int fd,
 {
 	struct intel_allocator *ial = NULL;
 
+	igt_assert(can_report_gtt_size(fd));
+
 	switch (allocator_type) {
 	/*
 	 * Few words of explanation is required here.
-- 
2.25.1



More information about the igt-dev mailing list