[RFC PATCH 2/5] drm/gem: track mm struct of allocating process in gem object
Lucas Stach
l.stach at pengutronix.de
Fri Sep 9 11:16:37 UTC 2022
This keeps around a weak reference to the struct mm of the process
allocating the GEM object. This allows us to charge/uncharge the
process with the allocated backing store memory, even if this is
happening from another context.
Signed-off-by: Lucas Stach <l.stach at pengutronix.de>
---
drivers/gpu/drm/drm_gem.c | 5 +++++
include/drm/drm_gem.h | 12 ++++++++++++
2 files changed, 17 insertions(+)
diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c
index 86d670c71286..b882f935cd4b 100644
--- a/drivers/gpu/drm/drm_gem.c
+++ b/drivers/gpu/drm/drm_gem.c
@@ -36,6 +36,7 @@
#include <linux/pagemap.h>
#include <linux/pagevec.h>
#include <linux/shmem_fs.h>
+#include <linux/sched/mm.h>
#include <linux/slab.h>
#include <linux/string_helpers.h>
#include <linux/types.h>
@@ -157,6 +158,9 @@ void drm_gem_private_object_init(struct drm_device *dev,
obj->dev = dev;
obj->filp = NULL;
+ mmgrab(current->mm);
+ obj->mm = current->mm;
+
kref_init(&obj->refcount);
obj->handle_count = 0;
obj->size = size;
@@ -949,6 +953,7 @@ drm_gem_object_release(struct drm_gem_object *obj)
if (obj->filp)
fput(obj->filp);
+ mmdrop(obj->mm);
dma_resv_fini(&obj->_resv);
drm_gem_free_mmap_offset(obj);
}
diff --git a/include/drm/drm_gem.h b/include/drm/drm_gem.h
index 87cffc9efa85..d021a083c282 100644
--- a/include/drm/drm_gem.h
+++ b/include/drm/drm_gem.h
@@ -234,6 +234,18 @@ struct drm_gem_object {
*/
struct drm_vma_offset_node vma_node;
+ /**
+ * @mm:
+ *
+ * mm struct of the process creating the object. Used to account the
+ * allocated backing store memory.
+ *
+ * Note that this is a weak reference created by mmgrab(), so any
+ * manipulation needs to make sure the address space is still around by
+ * calling mmget_not_zero().
+ */
+ struct mm_struct *mm;
+
/**
* @size:
*
--
2.30.2
More information about the dri-devel
mailing list