Re: [Intel-gfx] [RFC 02/10] drm/i915/vm_bind: Bind and unbind mappings

2022-07-26 Thread Tvrtko Ursulin



On 26/07/2022 06:07, Niranjana Vishwanathapura wrote:

On Mon, Jul 18, 2022 at 11:55:41AM +0100, Tvrtko Ursulin wrote:


On 01/07/2022 23:50, Niranjana Vishwanathapura wrote:

Bind and unbind the mappings upon VM_BIND and VM_UNBIND calls.

Signed-off-by: Niranjana Vishwanathapura 


Signed-off-by: Prathap Kumar Valsan 
---
 drivers/gpu/drm/i915/Makefile |   1 +
 drivers/gpu/drm/i915/gem/i915_gem_create.c    |  10 +-
 drivers/gpu/drm/i915/gem/i915_gem_object.h    |   2 +
 drivers/gpu/drm/i915/gem/i915_gem_vm_bind.h   |  38 +++
 .../drm/i915/gem/i915_gem_vm_bind_object.c    | 233 ++
 drivers/gpu/drm/i915/gt/intel_gtt.c   |   7 +
 drivers/gpu/drm/i915/gt/intel_gtt.h   |   9 +
 drivers/gpu/drm/i915/i915_driver.c    |  11 +-
 drivers/gpu/drm/i915/i915_vma.c   |   7 +-
 drivers/gpu/drm/i915/i915_vma.h   |   2 -
 drivers/gpu/drm/i915/i915_vma_types.h |   8 +
 11 files changed, 318 insertions(+), 10 deletions(-)
 create mode 100644 drivers/gpu/drm/i915/gem/i915_gem_vm_bind.h
 create mode 100644 drivers/gpu/drm/i915/gem/i915_gem_vm_bind_object.c

diff --git a/drivers/gpu/drm/i915/Makefile 
b/drivers/gpu/drm/i915/Makefile

index 522ef9b4aff3..4e1627e96c6e 100644
--- a/drivers/gpu/drm/i915/Makefile
+++ b/drivers/gpu/drm/i915/Makefile
@@ -165,6 +165,7 @@ gem-y += \
 gem/i915_gem_ttm_move.o \
 gem/i915_gem_ttm_pm.o \
 gem/i915_gem_userptr.o \
+    gem/i915_gem_vm_bind_object.o \
 gem/i915_gem_wait.o \
 gem/i915_gemfs.o
 i915-y += \
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_create.c 
b/drivers/gpu/drm/i915/gem/i915_gem_create.c

index 33673fe7ee0a..927a87e5ec59 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_create.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_create.c
@@ -15,10 +15,10 @@
 #include "i915_trace.h"
 #include "i915_user_extensions.h"
-static u32 object_max_page_size(struct intel_memory_region 
**placements,

-    unsigned int n_placements)
+u32 i915_gem_object_max_page_size(struct intel_memory_region 
**placements,

+  unsigned int n_placements)
 {
-    u32 max_page_size = 0;
+    u32 max_page_size = I915_GTT_PAGE_SIZE_4K;
 int i;
 for (i = 0; i < n_placements; i++) {
@@ -28,7 +28,6 @@ static u32 object_max_page_size(struct 
intel_memory_region **placements,

 max_page_size = max_t(u32, max_page_size, mr->min_page_size);
 }
-    GEM_BUG_ON(!max_page_size);
 return max_page_size;
 }
@@ -99,7 +98,8 @@ __i915_gem_object_create_user_ext(struct 
drm_i915_private *i915, u64 size,

 i915_gem_flush_free_objects(i915);
-    size = round_up(size, object_max_page_size(placements, 
n_placements));

+    size = round_up(size, i915_gem_object_max_page_size(placements,
+    n_placements));
 if (size == 0)
 return ERR_PTR(-EINVAL);
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_object.h 
b/drivers/gpu/drm/i915/gem/i915_gem_object.h

index 6f0a3ce35567..650de2224843 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_object.h
+++ b/drivers/gpu/drm/i915/gem/i915_gem_object.h
@@ -47,6 +47,8 @@ static inline bool i915_gem_object_size_2big(u64 size)
 }
 void i915_gem_init__objects(struct drm_i915_private *i915);
+u32 i915_gem_object_max_page_size(struct intel_memory_region 
**placements,

+  unsigned int n_placements);
 void i915_objects_module_exit(void);
 int i915_objects_module_init(void);
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_vm_bind.h 
b/drivers/gpu/drm/i915/gem/i915_gem_vm_bind.h

new file mode 100644
index ..642cdb559f17
--- /dev/null
+++ b/drivers/gpu/drm/i915/gem/i915_gem_vm_bind.h
@@ -0,0 +1,38 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Copyright © 2022 Intel Corporation
+ */
+
+#ifndef __I915_GEM_VM_BIND_H
+#define __I915_GEM_VM_BIND_H
+
+#include "i915_drv.h"
+
+#define assert_vm_bind_held(vm)   
lockdep_assert_held(&(vm)->vm_bind_lock)

+
+static inline void i915_gem_vm_bind_lock(struct i915_address_space *vm)
+{
+    mutex_lock(&vm->vm_bind_lock);
+}
+
+static inline int
+i915_gem_vm_bind_lock_interruptible(struct i915_address_space *vm)
+{
+    return mutex_lock_interruptible(&vm->vm_bind_lock);
+}
+
+static inline void i915_gem_vm_bind_unlock(struct i915_address_space 
*vm)

+{
+    mutex_unlock(&vm->vm_bind_lock);
+}
+
+struct i915_vma *
+i915_gem_vm_bind_lookup_vma(struct i915_address_space *vm, u64 va);
+void i915_gem_vm_bind_remove(struct i915_vma *vma, bool release_obj);
+int i915_gem_vm_bind_obj(struct i915_address_space *vm,
+ struct drm_i915_gem_vm_bind *va,
+ struct drm_file *file);
+int i915_gem_vm_unbind_obj(struct i915_address_space *vm,
+   struct drm_i915_gem_vm_unbind *va);
+
+#endif /* __I915_GEM_VM_BIND_H */
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_vm_bind_object.c 
b/drivers/gpu/drm/i915/gem/i915_gem_vm_bind_object.c

new file mode 100644
index ..43ceb4dcca6c
--- /dev/null
+++ b/drivers/gpu/drm/i915/ge

Re: [Intel-gfx] [RFC 02/10] drm/i915/vm_bind: Bind and unbind mappings

2022-07-25 Thread Niranjana Vishwanathapura

On Mon, Jul 18, 2022 at 11:55:41AM +0100, Tvrtko Ursulin wrote:


On 01/07/2022 23:50, Niranjana Vishwanathapura wrote:

Bind and unbind the mappings upon VM_BIND and VM_UNBIND calls.

Signed-off-by: Niranjana Vishwanathapura 
Signed-off-by: Prathap Kumar Valsan 
---
 drivers/gpu/drm/i915/Makefile |   1 +
 drivers/gpu/drm/i915/gem/i915_gem_create.c|  10 +-
 drivers/gpu/drm/i915/gem/i915_gem_object.h|   2 +
 drivers/gpu/drm/i915/gem/i915_gem_vm_bind.h   |  38 +++
 .../drm/i915/gem/i915_gem_vm_bind_object.c| 233 ++
 drivers/gpu/drm/i915/gt/intel_gtt.c   |   7 +
 drivers/gpu/drm/i915/gt/intel_gtt.h   |   9 +
 drivers/gpu/drm/i915/i915_driver.c|  11 +-
 drivers/gpu/drm/i915/i915_vma.c   |   7 +-
 drivers/gpu/drm/i915/i915_vma.h   |   2 -
 drivers/gpu/drm/i915/i915_vma_types.h |   8 +
 11 files changed, 318 insertions(+), 10 deletions(-)
 create mode 100644 drivers/gpu/drm/i915/gem/i915_gem_vm_bind.h
 create mode 100644 drivers/gpu/drm/i915/gem/i915_gem_vm_bind_object.c

diff --git a/drivers/gpu/drm/i915/Makefile b/drivers/gpu/drm/i915/Makefile
index 522ef9b4aff3..4e1627e96c6e 100644
--- a/drivers/gpu/drm/i915/Makefile
+++ b/drivers/gpu/drm/i915/Makefile
@@ -165,6 +165,7 @@ gem-y += \
gem/i915_gem_ttm_move.o \
gem/i915_gem_ttm_pm.o \
gem/i915_gem_userptr.o \
+   gem/i915_gem_vm_bind_object.o \
gem/i915_gem_wait.o \
gem/i915_gemfs.o
 i915-y += \
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_create.c 
b/drivers/gpu/drm/i915/gem/i915_gem_create.c
index 33673fe7ee0a..927a87e5ec59 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_create.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_create.c
@@ -15,10 +15,10 @@
 #include "i915_trace.h"
 #include "i915_user_extensions.h"
-static u32 object_max_page_size(struct intel_memory_region **placements,
-   unsigned int n_placements)
+u32 i915_gem_object_max_page_size(struct intel_memory_region **placements,
+ unsigned int n_placements)
 {
-   u32 max_page_size = 0;
+   u32 max_page_size = I915_GTT_PAGE_SIZE_4K;
int i;
for (i = 0; i < n_placements; i++) {
@@ -28,7 +28,6 @@ static u32 object_max_page_size(struct intel_memory_region 
**placements,
max_page_size = max_t(u32, max_page_size, mr->min_page_size);
}
-   GEM_BUG_ON(!max_page_size);
return max_page_size;
 }
@@ -99,7 +98,8 @@ __i915_gem_object_create_user_ext(struct drm_i915_private 
*i915, u64 size,
i915_gem_flush_free_objects(i915);
-   size = round_up(size, object_max_page_size(placements, n_placements));
+   size = round_up(size, i915_gem_object_max_page_size(placements,
+   n_placements));
if (size == 0)
return ERR_PTR(-EINVAL);
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_object.h 
b/drivers/gpu/drm/i915/gem/i915_gem_object.h
index 6f0a3ce35567..650de2224843 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_object.h
+++ b/drivers/gpu/drm/i915/gem/i915_gem_object.h
@@ -47,6 +47,8 @@ static inline bool i915_gem_object_size_2big(u64 size)
 }
 void i915_gem_init__objects(struct drm_i915_private *i915);
+u32 i915_gem_object_max_page_size(struct intel_memory_region **placements,
+ unsigned int n_placements);
 void i915_objects_module_exit(void);
 int i915_objects_module_init(void);
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_vm_bind.h 
b/drivers/gpu/drm/i915/gem/i915_gem_vm_bind.h
new file mode 100644
index ..642cdb559f17
--- /dev/null
+++ b/drivers/gpu/drm/i915/gem/i915_gem_vm_bind.h
@@ -0,0 +1,38 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Copyright © 2022 Intel Corporation
+ */
+
+#ifndef __I915_GEM_VM_BIND_H
+#define __I915_GEM_VM_BIND_H
+
+#include "i915_drv.h"
+
+#define assert_vm_bind_held(vm)   lockdep_assert_held(&(vm)->vm_bind_lock)
+
+static inline void i915_gem_vm_bind_lock(struct i915_address_space *vm)
+{
+   mutex_lock(&vm->vm_bind_lock);
+}
+
+static inline int
+i915_gem_vm_bind_lock_interruptible(struct i915_address_space *vm)
+{
+   return mutex_lock_interruptible(&vm->vm_bind_lock);
+}
+
+static inline void i915_gem_vm_bind_unlock(struct i915_address_space *vm)
+{
+   mutex_unlock(&vm->vm_bind_lock);
+}
+
+struct i915_vma *
+i915_gem_vm_bind_lookup_vma(struct i915_address_space *vm, u64 va);
+void i915_gem_vm_bind_remove(struct i915_vma *vma, bool release_obj);
+int i915_gem_vm_bind_obj(struct i915_address_space *vm,
+struct drm_i915_gem_vm_bind *va,
+struct drm_file *file);
+int i915_gem_vm_unbind_obj(struct i915_address_space *vm,
+  struct drm_i915_gem_vm_unbind *va);
+
+#endif /* __I915_GEM_VM_BIND_H */
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_vm_bind_object.c 
b/drivers/gpu/drm/i915/gem/i915_gem_vm_bind_object

Re: [Intel-gfx] [RFC 02/10] drm/i915/vm_bind: Bind and unbind mappings

2022-07-18 Thread Tvrtko Ursulin



On 01/07/2022 23:50, Niranjana Vishwanathapura wrote:

Bind and unbind the mappings upon VM_BIND and VM_UNBIND calls.

Signed-off-by: Niranjana Vishwanathapura 
Signed-off-by: Prathap Kumar Valsan 
---
  drivers/gpu/drm/i915/Makefile |   1 +
  drivers/gpu/drm/i915/gem/i915_gem_create.c|  10 +-
  drivers/gpu/drm/i915/gem/i915_gem_object.h|   2 +
  drivers/gpu/drm/i915/gem/i915_gem_vm_bind.h   |  38 +++
  .../drm/i915/gem/i915_gem_vm_bind_object.c| 233 ++
  drivers/gpu/drm/i915/gt/intel_gtt.c   |   7 +
  drivers/gpu/drm/i915/gt/intel_gtt.h   |   9 +
  drivers/gpu/drm/i915/i915_driver.c|  11 +-
  drivers/gpu/drm/i915/i915_vma.c   |   7 +-
  drivers/gpu/drm/i915/i915_vma.h   |   2 -
  drivers/gpu/drm/i915/i915_vma_types.h |   8 +
  11 files changed, 318 insertions(+), 10 deletions(-)
  create mode 100644 drivers/gpu/drm/i915/gem/i915_gem_vm_bind.h
  create mode 100644 drivers/gpu/drm/i915/gem/i915_gem_vm_bind_object.c

diff --git a/drivers/gpu/drm/i915/Makefile b/drivers/gpu/drm/i915/Makefile
index 522ef9b4aff3..4e1627e96c6e 100644
--- a/drivers/gpu/drm/i915/Makefile
+++ b/drivers/gpu/drm/i915/Makefile
@@ -165,6 +165,7 @@ gem-y += \
gem/i915_gem_ttm_move.o \
gem/i915_gem_ttm_pm.o \
gem/i915_gem_userptr.o \
+   gem/i915_gem_vm_bind_object.o \
gem/i915_gem_wait.o \
gem/i915_gemfs.o
  i915-y += \
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_create.c 
b/drivers/gpu/drm/i915/gem/i915_gem_create.c
index 33673fe7ee0a..927a87e5ec59 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_create.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_create.c
@@ -15,10 +15,10 @@
  #include "i915_trace.h"
  #include "i915_user_extensions.h"
  
-static u32 object_max_page_size(struct intel_memory_region **placements,

-   unsigned int n_placements)
+u32 i915_gem_object_max_page_size(struct intel_memory_region **placements,
+ unsigned int n_placements)
  {
-   u32 max_page_size = 0;
+   u32 max_page_size = I915_GTT_PAGE_SIZE_4K;
int i;
  
  	for (i = 0; i < n_placements; i++) {

@@ -28,7 +28,6 @@ static u32 object_max_page_size(struct intel_memory_region 
**placements,
max_page_size = max_t(u32, max_page_size, mr->min_page_size);
}
  
-	GEM_BUG_ON(!max_page_size);

return max_page_size;
  }
  
@@ -99,7 +98,8 @@ __i915_gem_object_create_user_ext(struct drm_i915_private *i915, u64 size,
  
  	i915_gem_flush_free_objects(i915);
  
-	size = round_up(size, object_max_page_size(placements, n_placements));

+   size = round_up(size, i915_gem_object_max_page_size(placements,
+   n_placements));
if (size == 0)
return ERR_PTR(-EINVAL);
  
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_object.h b/drivers/gpu/drm/i915/gem/i915_gem_object.h

index 6f0a3ce35567..650de2224843 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_object.h
+++ b/drivers/gpu/drm/i915/gem/i915_gem_object.h
@@ -47,6 +47,8 @@ static inline bool i915_gem_object_size_2big(u64 size)
  }
  
  void i915_gem_init__objects(struct drm_i915_private *i915);

+u32 i915_gem_object_max_page_size(struct intel_memory_region **placements,
+ unsigned int n_placements);
  
  void i915_objects_module_exit(void);

  int i915_objects_module_init(void);
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_vm_bind.h 
b/drivers/gpu/drm/i915/gem/i915_gem_vm_bind.h
new file mode 100644
index ..642cdb559f17
--- /dev/null
+++ b/drivers/gpu/drm/i915/gem/i915_gem_vm_bind.h
@@ -0,0 +1,38 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Copyright © 2022 Intel Corporation
+ */
+
+#ifndef __I915_GEM_VM_BIND_H
+#define __I915_GEM_VM_BIND_H
+
+#include "i915_drv.h"
+
+#define assert_vm_bind_held(vm)   lockdep_assert_held(&(vm)->vm_bind_lock)
+
+static inline void i915_gem_vm_bind_lock(struct i915_address_space *vm)
+{
+   mutex_lock(&vm->vm_bind_lock);
+}
+
+static inline int
+i915_gem_vm_bind_lock_interruptible(struct i915_address_space *vm)
+{
+   return mutex_lock_interruptible(&vm->vm_bind_lock);
+}
+
+static inline void i915_gem_vm_bind_unlock(struct i915_address_space *vm)
+{
+   mutex_unlock(&vm->vm_bind_lock);
+}
+
+struct i915_vma *
+i915_gem_vm_bind_lookup_vma(struct i915_address_space *vm, u64 va);
+void i915_gem_vm_bind_remove(struct i915_vma *vma, bool release_obj);
+int i915_gem_vm_bind_obj(struct i915_address_space *vm,
+struct drm_i915_gem_vm_bind *va,
+struct drm_file *file);
+int i915_gem_vm_unbind_obj(struct i915_address_space *vm,
+  struct drm_i915_gem_vm_unbind *va);
+
+#endif /* __I915_GEM_VM_BIND_H */
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_vm_bind_object.c 
b/drivers/gpu/drm/i915/gem/i915_gem_vm_bind_object.c
new file mode 100644
index 0

Re: [Intel-gfx] [RFC 02/10] drm/i915/vm_bind: Bind and unbind mappings

2022-07-08 Thread Niranjana Vishwanathapura

On Thu, Jul 07, 2022 at 10:14:38AM +0200, Thomas Hellström wrote:

On Wed, 2022-07-06 at 22:43 -0700, Niranjana Vishwanathapura wrote:

On Wed, Jul 06, 2022 at 06:21:03PM +0200, Thomas Hellström wrote:
> On Fri, 2022-07-01 at 15:50 -0700, Niranjana Vishwanathapura wrote:
> > Bind and unbind the mappings upon VM_BIND and VM_UNBIND calls.
> >
> > Signed-off-by: Niranjana Vishwanathapura
> > 
> > Signed-off-by: Prathap Kumar Valsan
> > 
> > ---
> >  drivers/gpu/drm/i915/Makefile |   1 +
> >  drivers/gpu/drm/i915/gem/i915_gem_create.c    |  10 +-
> >  drivers/gpu/drm/i915/gem/i915_gem_object.h    |   2 +
> >  drivers/gpu/drm/i915/gem/i915_gem_vm_bind.h   |  38 +++
> >  .../drm/i915/gem/i915_gem_vm_bind_object.c    | 233
> > ++
> >  drivers/gpu/drm/i915/gt/intel_gtt.c   |   7 +
> >  drivers/gpu/drm/i915/gt/intel_gtt.h   |   9 +
> >  drivers/gpu/drm/i915/i915_driver.c    |  11 +-
> >  drivers/gpu/drm/i915/i915_vma.c   |   7 +-
> >  drivers/gpu/drm/i915/i915_vma.h   |   2 -
> >  drivers/gpu/drm/i915/i915_vma_types.h |   8 +
> >  11 files changed, 318 insertions(+), 10 deletions(-)
> >  create mode 100644 drivers/gpu/drm/i915/gem/i915_gem_vm_bind.h
> >  create mode 100644
> > drivers/gpu/drm/i915/gem/i915_gem_vm_bind_object.c
> >
> > diff --git a/drivers/gpu/drm/i915/Makefile
> > b/drivers/gpu/drm/i915/Makefile
> > index 522ef9b4aff3..4e1627e96c6e 100644
> > --- a/drivers/gpu/drm/i915/Makefile
> > +++ b/drivers/gpu/drm/i915/Makefile
> > @@ -165,6 +165,7 @@ gem-y += \
> > gem/i915_gem_ttm_move.o \
> > gem/i915_gem_ttm_pm.o \
> > gem/i915_gem_userptr.o \
> > +   gem/i915_gem_vm_bind_object.o \
> > gem/i915_gem_wait.o \
> > gem/i915_gemfs.o
> >  i915-y += \
> > diff --git a/drivers/gpu/drm/i915/gem/i915_gem_create.c
> > b/drivers/gpu/drm/i915/gem/i915_gem_create.c
> > index 33673fe7ee0a..927a87e5ec59 100644
> > --- a/drivers/gpu/drm/i915/gem/i915_gem_create.c
> > +++ b/drivers/gpu/drm/i915/gem/i915_gem_create.c
> > @@ -15,10 +15,10 @@
> >  #include "i915_trace.h"
> >  #include "i915_user_extensions.h"
> >  
> > -static u32 object_max_page_size(struct intel_memory_region
> > **placements,
> > -   unsigned int n_placements)
> > +u32 i915_gem_object_max_page_size(struct intel_memory_region
> > **placements,
>
> Kerneldoc.

This is an existing function that is being modified. As I
mentioned in other thread, we probably need a prep patch early
in this series to add missing kernel-docs in i915 which this
patch series would later update.


Here we make a static function extern, which according to the patch
submission guidelines, mandates a kerneloc comment, so it's not so much
that the function is modified. We should be fine adding kerneldoc in
the patch that makes the function extern.



Ok, sounds good.





>
> > + unsigned int n_placements)
> >  {
> > -   u32 max_page_size = 0;
> > +   u32 max_page_size = I915_GTT_PAGE_SIZE_4K;
> > int i;
> >  
> > for (i = 0; i < n_placements; i++) {
> > @@ -28,7 +28,6 @@ static u32 object_max_page_size(struct
> > intel_memory_region **placements,
> > max_page_size = max_t(u32, max_page_size, mr-
> > > min_page_size);
> > }
> >  
> > -   GEM_BUG_ON(!max_page_size);
> > return max_page_size;
> >  }
>
> Should this change be separated out? It's not immediately clear to
> a
> reviewer why it is included.

It is being removed as max_page_size now has a non-zero default
value and hence this check is not valid anymore.


But that in itself deserves an explanation in the patch commit message.
So that's why I wondered whether it wouldn't be better to separate it
out?


Yah, we can have this change in a separate patch before we introduce
VM_BIND feature.





>
> >  
> > @@ -99,7 +98,8 @@ __i915_gem_object_create_user_ext(struct
> > drm_i915_private *i915, u64 size,
> >  
> > i915_gem_flush_free_objects(i915);
> >  
> > -   size = round_up(size, object_max_page_size(placements,
> > n_placements));
> > +   size = round_up(size,
> > i915_gem_object_max_page_size(placements,
> > +  
> > n_placements));
> > if (size == 0)
> > return ERR_PTR(-EINVAL);
> >  
> > diff --git a/drivers/gpu/drm/i915/gem/i915_gem_object.h
> > b/drivers/gpu/drm/i915/gem/i915_gem_object.h
> > index 6f0a3ce35567..650de2224843 100644
> > --- a/drivers/gpu/drm/i915/gem/i915_gem_object.h
> > +++ b/drivers/gpu/drm/i915/gem/i915_gem_object.h
> > @@ -47,6 +47,8 @@ static inline bool
> > i915_gem_object_size_2big(u64
> > size)
> >  }
> >  
> >  void i915_gem_init__objects(struct drm_i915_private *i915);
> > +u32 i915_gem_object_max_page_size(struct intel_memory_region
> > **placements,
> > + unsigned int n_placements);
> >  
> >  void i915_objects_module_exi

Re: [Intel-gfx] [RFC 02/10] drm/i915/vm_bind: Bind and unbind mappings

2022-07-07 Thread Thomas Hellström
On Wed, 2022-07-06 at 22:43 -0700, Niranjana Vishwanathapura wrote:
> On Wed, Jul 06, 2022 at 06:21:03PM +0200, Thomas Hellström wrote:
> > On Fri, 2022-07-01 at 15:50 -0700, Niranjana Vishwanathapura wrote:
> > > Bind and unbind the mappings upon VM_BIND and VM_UNBIND calls.
> > > 
> > > Signed-off-by: Niranjana Vishwanathapura
> > > 
> > > Signed-off-by: Prathap Kumar Valsan
> > > 
> > > ---
> > >  drivers/gpu/drm/i915/Makefile |   1 +
> > >  drivers/gpu/drm/i915/gem/i915_gem_create.c    |  10 +-
> > >  drivers/gpu/drm/i915/gem/i915_gem_object.h    |   2 +
> > >  drivers/gpu/drm/i915/gem/i915_gem_vm_bind.h   |  38 +++
> > >  .../drm/i915/gem/i915_gem_vm_bind_object.c    | 233
> > > ++
> > >  drivers/gpu/drm/i915/gt/intel_gtt.c   |   7 +
> > >  drivers/gpu/drm/i915/gt/intel_gtt.h   |   9 +
> > >  drivers/gpu/drm/i915/i915_driver.c    |  11 +-
> > >  drivers/gpu/drm/i915/i915_vma.c   |   7 +-
> > >  drivers/gpu/drm/i915/i915_vma.h   |   2 -
> > >  drivers/gpu/drm/i915/i915_vma_types.h |   8 +
> > >  11 files changed, 318 insertions(+), 10 deletions(-)
> > >  create mode 100644 drivers/gpu/drm/i915/gem/i915_gem_vm_bind.h
> > >  create mode 100644
> > > drivers/gpu/drm/i915/gem/i915_gem_vm_bind_object.c
> > > 
> > > diff --git a/drivers/gpu/drm/i915/Makefile
> > > b/drivers/gpu/drm/i915/Makefile
> > > index 522ef9b4aff3..4e1627e96c6e 100644
> > > --- a/drivers/gpu/drm/i915/Makefile
> > > +++ b/drivers/gpu/drm/i915/Makefile
> > > @@ -165,6 +165,7 @@ gem-y += \
> > > gem/i915_gem_ttm_move.o \
> > > gem/i915_gem_ttm_pm.o \
> > > gem/i915_gem_userptr.o \
> > > +   gem/i915_gem_vm_bind_object.o \
> > > gem/i915_gem_wait.o \
> > > gem/i915_gemfs.o
> > >  i915-y += \
> > > diff --git a/drivers/gpu/drm/i915/gem/i915_gem_create.c
> > > b/drivers/gpu/drm/i915/gem/i915_gem_create.c
> > > index 33673fe7ee0a..927a87e5ec59 100644
> > > --- a/drivers/gpu/drm/i915/gem/i915_gem_create.c
> > > +++ b/drivers/gpu/drm/i915/gem/i915_gem_create.c
> > > @@ -15,10 +15,10 @@
> > >  #include "i915_trace.h"
> > >  #include "i915_user_extensions.h"
> > >  
> > > -static u32 object_max_page_size(struct intel_memory_region
> > > **placements,
> > > -   unsigned int n_placements)
> > > +u32 i915_gem_object_max_page_size(struct intel_memory_region
> > > **placements,
> > 
> > Kerneldoc.
> 
> This is an existing function that is being modified. As I
> mentioned in other thread, we probably need a prep patch early
> in this series to add missing kernel-docs in i915 which this
> patch series would later update.

Here we make a static function extern, which according to the patch
submission guidelines, mandates a kerneloc comment, so it's not so much
that the function is modified. We should be fine adding kerneldoc in
the patch that makes the function extern.


> 
> > 
> > > + unsigned int n_placements)
> > >  {
> > > -   u32 max_page_size = 0;
> > > +   u32 max_page_size = I915_GTT_PAGE_SIZE_4K;
> > > int i;
> > >  
> > > for (i = 0; i < n_placements; i++) {
> > > @@ -28,7 +28,6 @@ static u32 object_max_page_size(struct
> > > intel_memory_region **placements,
> > > max_page_size = max_t(u32, max_page_size, mr-
> > > > min_page_size);
> > > }
> > >  
> > > -   GEM_BUG_ON(!max_page_size);
> > > return max_page_size;
> > >  }
> > 
> > Should this change be separated out? It's not immediately clear to
> > a
> > reviewer why it is included.
> 
> It is being removed as max_page_size now has a non-zero default
> value and hence this check is not valid anymore.

But that in itself deserves an explanation in the patch commit message.
So that's why I wondered whether it wouldn't be better to separate it
out?

> 
> > 
> > >  
> > > @@ -99,7 +98,8 @@ __i915_gem_object_create_user_ext(struct
> > > drm_i915_private *i915, u64 size,
> > >  
> > > i915_gem_flush_free_objects(i915);
> > >  
> > > -   size = round_up(size, object_max_page_size(placements,
> > > n_placements));
> > > +   size = round_up(size,
> > > i915_gem_object_max_page_size(placements,
> > > +  
> > > n_placements));
> > > if (size == 0)
> > > return ERR_PTR(-EINVAL);
> > >  
> > > diff --git a/drivers/gpu/drm/i915/gem/i915_gem_object.h
> > > b/drivers/gpu/drm/i915/gem/i915_gem_object.h
> > > index 6f0a3ce35567..650de2224843 100644
> > > --- a/drivers/gpu/drm/i915/gem/i915_gem_object.h
> > > +++ b/drivers/gpu/drm/i915/gem/i915_gem_object.h
> > > @@ -47,6 +47,8 @@ static inline bool
> > > i915_gem_object_size_2big(u64
> > > size)
> > >  }
> > >  
> > >  void i915_gem_init__objects(struct drm_i915_private *i915);
> > > +u32 i915_gem_object_max_page_size(struct intel_memory_region
> > > **placements,
> > > + unsigned int 

Re: [Intel-gfx] [RFC 02/10] drm/i915/vm_bind: Bind and unbind mappings

2022-07-06 Thread Niranjana Vishwanathapura

On Thu, Jul 07, 2022 at 03:41:26AM +0200, Andi Shyti wrote:

Hi,

[...]


> @@ -28,7 +28,6 @@ static u32 object_max_page_size(struct
> intel_memory_region **placements,
> max_page_size = max_t(u32, max_page_size, mr-
> >min_page_size);
> }
>  
> -   GEM_BUG_ON(!max_page_size);
> return max_page_size;
>  }

Should this change be separated out? It's not immediately clear to a
reviewer why it is included.


no, it's not, indeed... and is it correct to assume that the
default size is I915_GTT_PAGE_SIZE_4K?



Currently, supported minimum page sizes are either 4K or 64K.
So, we start with 4K as default and check if there is a bigger
min_page_size.

Niranjana


[...]


> +#define assert_vm_bind_held(vm)   lockdep_assert_held(&(vm)-
> >vm_bind_lock)
> +
> +static inline void i915_gem_vm_bind_lock(struct i915_address_space
> *vm)
> +{
> +   mutex_lock(&vm->vm_bind_lock);
> +}
> +
> +static inline int
> +i915_gem_vm_bind_lock_interruptible(struct i915_address_space *vm)
> +{
> +   return mutex_lock_interruptible(&vm->vm_bind_lock);
> +}
> +
> +static inline void i915_gem_vm_bind_unlock(struct i915_address_space
> *vm)
> +{
> +   mutex_unlock(&vm->vm_bind_lock);
> +}
> +

Kerneldoc for the inlines.


do we really need these oneline wrappers?

Andi


Re: [Intel-gfx] [RFC 02/10] drm/i915/vm_bind: Bind and unbind mappings

2022-07-06 Thread Niranjana Vishwanathapura

On Wed, Jul 06, 2022 at 06:21:03PM +0200, Thomas Hellström wrote:

On Fri, 2022-07-01 at 15:50 -0700, Niranjana Vishwanathapura wrote:

Bind and unbind the mappings upon VM_BIND and VM_UNBIND calls.

Signed-off-by: Niranjana Vishwanathapura

Signed-off-by: Prathap Kumar Valsan 
---
 drivers/gpu/drm/i915/Makefile |   1 +
 drivers/gpu/drm/i915/gem/i915_gem_create.c    |  10 +-
 drivers/gpu/drm/i915/gem/i915_gem_object.h    |   2 +
 drivers/gpu/drm/i915/gem/i915_gem_vm_bind.h   |  38 +++
 .../drm/i915/gem/i915_gem_vm_bind_object.c    | 233
++
 drivers/gpu/drm/i915/gt/intel_gtt.c   |   7 +
 drivers/gpu/drm/i915/gt/intel_gtt.h   |   9 +
 drivers/gpu/drm/i915/i915_driver.c    |  11 +-
 drivers/gpu/drm/i915/i915_vma.c   |   7 +-
 drivers/gpu/drm/i915/i915_vma.h   |   2 -
 drivers/gpu/drm/i915/i915_vma_types.h |   8 +
 11 files changed, 318 insertions(+), 10 deletions(-)
 create mode 100644 drivers/gpu/drm/i915/gem/i915_gem_vm_bind.h
 create mode 100644
drivers/gpu/drm/i915/gem/i915_gem_vm_bind_object.c

diff --git a/drivers/gpu/drm/i915/Makefile
b/drivers/gpu/drm/i915/Makefile
index 522ef9b4aff3..4e1627e96c6e 100644
--- a/drivers/gpu/drm/i915/Makefile
+++ b/drivers/gpu/drm/i915/Makefile
@@ -165,6 +165,7 @@ gem-y += \
gem/i915_gem_ttm_move.o \
gem/i915_gem_ttm_pm.o \
gem/i915_gem_userptr.o \
+   gem/i915_gem_vm_bind_object.o \
gem/i915_gem_wait.o \
gem/i915_gemfs.o
 i915-y += \
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_create.c
b/drivers/gpu/drm/i915/gem/i915_gem_create.c
index 33673fe7ee0a..927a87e5ec59 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_create.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_create.c
@@ -15,10 +15,10 @@
 #include "i915_trace.h"
 #include "i915_user_extensions.h"
 
-static u32 object_max_page_size(struct intel_memory_region
**placements,
-   unsigned int n_placements)
+u32 i915_gem_object_max_page_size(struct intel_memory_region
**placements,


Kerneldoc.


This is an existing function that is being modified. As I
mentioned in other thread, we probably need a prep patch early
in this series to add missing kernel-docs in i915 which this
patch series would later update.




+ unsigned int n_placements)
 {
-   u32 max_page_size = 0;
+   u32 max_page_size = I915_GTT_PAGE_SIZE_4K;
int i;
 
for (i = 0; i < n_placements; i++) {
@@ -28,7 +28,6 @@ static u32 object_max_page_size(struct
intel_memory_region **placements,
max_page_size = max_t(u32, max_page_size, mr-
>min_page_size);
}
 
-   GEM_BUG_ON(!max_page_size);
return max_page_size;
 }


Should this change be separated out? It's not immediately clear to a
reviewer why it is included.


It is being removed as max_page_size now has a non-zero default
value and hence this check is not valid anymore.




 
@@ -99,7 +98,8 @@ __i915_gem_object_create_user_ext(struct
drm_i915_private *i915, u64 size,
 
i915_gem_flush_free_objects(i915);
 
-   size = round_up(size, object_max_page_size(placements,
n_placements));
+   size = round_up(size,
i915_gem_object_max_page_size(placements,
+  
n_placements));
if (size == 0)
return ERR_PTR(-EINVAL);
 
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_object.h
b/drivers/gpu/drm/i915/gem/i915_gem_object.h
index 6f0a3ce35567..650de2224843 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_object.h
+++ b/drivers/gpu/drm/i915/gem/i915_gem_object.h
@@ -47,6 +47,8 @@ static inline bool i915_gem_object_size_2big(u64
size)
 }
 
 void i915_gem_init__objects(struct drm_i915_private *i915);
+u32 i915_gem_object_max_page_size(struct intel_memory_region
**placements,
+ unsigned int n_placements);
 
 void i915_objects_module_exit(void);
 int i915_objects_module_init(void);
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_vm_bind.h
b/drivers/gpu/drm/i915/gem/i915_gem_vm_bind.h
new file mode 100644
index ..642cdb559f17
--- /dev/null
+++ b/drivers/gpu/drm/i915/gem/i915_gem_vm_bind.h
@@ -0,0 +1,38 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Copyright © 2022 Intel Corporation
+ */
+
+#ifndef __I915_GEM_VM_BIND_H
+#define __I915_GEM_VM_BIND_H
+
+#include "i915_drv.h"
+
+#define assert_vm_bind_held(vm)   lockdep_assert_held(&(vm)-
>vm_bind_lock)
+
+static inline void i915_gem_vm_bind_lock(struct i915_address_space
*vm)
+{
+   mutex_lock(&vm->vm_bind_lock);
+}
+
+static inline int
+i915_gem_vm_bind_lock_interruptible(struct i915_address_space *vm)
+{
+   return mutex_lock_interruptible(&vm->vm_bind_lock);
+}
+
+static inline void i915_gem_vm_bind_unlock(struct i915_address_space
*vm)
+{
+   mutex_unlock(&vm->vm_bind_lock);
+}
+


Kerneldoc for the inlines.


+struct i915_vma *
+i915_gem_vm_bind_lookup_vma(struct i915_address_space *vm, u64 

Re: [Intel-gfx] [RFC 02/10] drm/i915/vm_bind: Bind and unbind mappings

2022-07-06 Thread Andi Shyti
Hi,

[...]

> > @@ -28,7 +28,6 @@ static u32 object_max_page_size(struct
> > intel_memory_region **placements,
> > max_page_size = max_t(u32, max_page_size, mr-
> > >min_page_size);
> > }
> >  
> > -   GEM_BUG_ON(!max_page_size);
> > return max_page_size;
> >  }
> 
> Should this change be separated out? It's not immediately clear to a
> reviewer why it is included.

no, it's not, indeed... and is it correct to assume that the
default size is I915_GTT_PAGE_SIZE_4K?

[...]

> > +#define assert_vm_bind_held(vm)   lockdep_assert_held(&(vm)-
> > >vm_bind_lock)
> > +
> > +static inline void i915_gem_vm_bind_lock(struct i915_address_space
> > *vm)
> > +{
> > +   mutex_lock(&vm->vm_bind_lock);
> > +}
> > +
> > +static inline int
> > +i915_gem_vm_bind_lock_interruptible(struct i915_address_space *vm)
> > +{
> > +   return mutex_lock_interruptible(&vm->vm_bind_lock);
> > +}
> > +
> > +static inline void i915_gem_vm_bind_unlock(struct i915_address_space
> > *vm)
> > +{
> > +   mutex_unlock(&vm->vm_bind_lock);
> > +}
> > +
> 
> Kerneldoc for the inlines.

do we really need these oneline wrappers?

Andi


Re: [Intel-gfx] [RFC 02/10] drm/i915/vm_bind: Bind and unbind mappings

2022-07-06 Thread Thomas Hellström
On Fri, 2022-07-01 at 15:50 -0700, Niranjana Vishwanathapura wrote:
> Bind and unbind the mappings upon VM_BIND and VM_UNBIND calls.
> 
> Signed-off-by: Niranjana Vishwanathapura
> 
> Signed-off-by: Prathap Kumar Valsan 
> ---
>  drivers/gpu/drm/i915/Makefile |   1 +
>  drivers/gpu/drm/i915/gem/i915_gem_create.c    |  10 +-
>  drivers/gpu/drm/i915/gem/i915_gem_object.h    |   2 +
>  drivers/gpu/drm/i915/gem/i915_gem_vm_bind.h   |  38 +++
>  .../drm/i915/gem/i915_gem_vm_bind_object.c    | 233
> ++
>  drivers/gpu/drm/i915/gt/intel_gtt.c   |   7 +
>  drivers/gpu/drm/i915/gt/intel_gtt.h   |   9 +
>  drivers/gpu/drm/i915/i915_driver.c    |  11 +-
>  drivers/gpu/drm/i915/i915_vma.c   |   7 +-
>  drivers/gpu/drm/i915/i915_vma.h   |   2 -
>  drivers/gpu/drm/i915/i915_vma_types.h |   8 +
>  11 files changed, 318 insertions(+), 10 deletions(-)
>  create mode 100644 drivers/gpu/drm/i915/gem/i915_gem_vm_bind.h
>  create mode 100644
> drivers/gpu/drm/i915/gem/i915_gem_vm_bind_object.c
> 
> diff --git a/drivers/gpu/drm/i915/Makefile
> b/drivers/gpu/drm/i915/Makefile
> index 522ef9b4aff3..4e1627e96c6e 100644
> --- a/drivers/gpu/drm/i915/Makefile
> +++ b/drivers/gpu/drm/i915/Makefile
> @@ -165,6 +165,7 @@ gem-y += \
> gem/i915_gem_ttm_move.o \
> gem/i915_gem_ttm_pm.o \
> gem/i915_gem_userptr.o \
> +   gem/i915_gem_vm_bind_object.o \
> gem/i915_gem_wait.o \
> gem/i915_gemfs.o
>  i915-y += \
> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_create.c
> b/drivers/gpu/drm/i915/gem/i915_gem_create.c
> index 33673fe7ee0a..927a87e5ec59 100644
> --- a/drivers/gpu/drm/i915/gem/i915_gem_create.c
> +++ b/drivers/gpu/drm/i915/gem/i915_gem_create.c
> @@ -15,10 +15,10 @@
>  #include "i915_trace.h"
>  #include "i915_user_extensions.h"
>  
> -static u32 object_max_page_size(struct intel_memory_region
> **placements,
> -   unsigned int n_placements)
> +u32 i915_gem_object_max_page_size(struct intel_memory_region
> **placements,

Kerneldoc.

> + unsigned int n_placements)
>  {
> -   u32 max_page_size = 0;
> +   u32 max_page_size = I915_GTT_PAGE_SIZE_4K;
> int i;
>  
> for (i = 0; i < n_placements; i++) {
> @@ -28,7 +28,6 @@ static u32 object_max_page_size(struct
> intel_memory_region **placements,
> max_page_size = max_t(u32, max_page_size, mr-
> >min_page_size);
> }
>  
> -   GEM_BUG_ON(!max_page_size);
> return max_page_size;
>  }

Should this change be separated out? It's not immediately clear to a
reviewer why it is included.

>  
> @@ -99,7 +98,8 @@ __i915_gem_object_create_user_ext(struct
> drm_i915_private *i915, u64 size,
>  
> i915_gem_flush_free_objects(i915);
>  
> -   size = round_up(size, object_max_page_size(placements,
> n_placements));
> +   size = round_up(size,
> i915_gem_object_max_page_size(placements,
> +  
> n_placements));
> if (size == 0)
> return ERR_PTR(-EINVAL);
>  
> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_object.h
> b/drivers/gpu/drm/i915/gem/i915_gem_object.h
> index 6f0a3ce35567..650de2224843 100644
> --- a/drivers/gpu/drm/i915/gem/i915_gem_object.h
> +++ b/drivers/gpu/drm/i915/gem/i915_gem_object.h
> @@ -47,6 +47,8 @@ static inline bool i915_gem_object_size_2big(u64
> size)
>  }
>  
>  void i915_gem_init__objects(struct drm_i915_private *i915);
> +u32 i915_gem_object_max_page_size(struct intel_memory_region
> **placements,
> + unsigned int n_placements);
>  
>  void i915_objects_module_exit(void);
>  int i915_objects_module_init(void);
> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_vm_bind.h
> b/drivers/gpu/drm/i915/gem/i915_gem_vm_bind.h
> new file mode 100644
> index ..642cdb559f17
> --- /dev/null
> +++ b/drivers/gpu/drm/i915/gem/i915_gem_vm_bind.h
> @@ -0,0 +1,38 @@
> +/* SPDX-License-Identifier: MIT */
> +/*
> + * Copyright © 2022 Intel Corporation
> + */
> +
> +#ifndef __I915_GEM_VM_BIND_H
> +#define __I915_GEM_VM_BIND_H
> +
> +#include "i915_drv.h"
> +
> +#define assert_vm_bind_held(vm)   lockdep_assert_held(&(vm)-
> >vm_bind_lock)
> +
> +static inline void i915_gem_vm_bind_lock(struct i915_address_space
> *vm)
> +{
> +   mutex_lock(&vm->vm_bind_lock);
> +}
> +
> +static inline int
> +i915_gem_vm_bind_lock_interruptible(struct i915_address_space *vm)
> +{
> +   return mutex_lock_interruptible(&vm->vm_bind_lock);
> +}
> +
> +static inline void i915_gem_vm_bind_unlock(struct i915_address_space
> *vm)
> +{
> +   mutex_unlock(&vm->vm_bind_lock);
> +}
> +

Kerneldoc for the inlines.

> +struct i915_vma *
> +i915_gem_vm_bind_lookup_vma(struct i915_address_space *vm, u64 va);
> +void i915_gem_vm_bind_remove(struct i915_vma *vma, bool
> release_obj);
> +int i915_gem_vm_bind_obj(struct i915_address_space *vm

[Intel-gfx] [RFC 02/10] drm/i915/vm_bind: Bind and unbind mappings

2022-07-01 Thread Niranjana Vishwanathapura
Bind and unbind the mappings upon VM_BIND and VM_UNBIND calls.

Signed-off-by: Niranjana Vishwanathapura 
Signed-off-by: Prathap Kumar Valsan 
---
 drivers/gpu/drm/i915/Makefile |   1 +
 drivers/gpu/drm/i915/gem/i915_gem_create.c|  10 +-
 drivers/gpu/drm/i915/gem/i915_gem_object.h|   2 +
 drivers/gpu/drm/i915/gem/i915_gem_vm_bind.h   |  38 +++
 .../drm/i915/gem/i915_gem_vm_bind_object.c| 233 ++
 drivers/gpu/drm/i915/gt/intel_gtt.c   |   7 +
 drivers/gpu/drm/i915/gt/intel_gtt.h   |   9 +
 drivers/gpu/drm/i915/i915_driver.c|  11 +-
 drivers/gpu/drm/i915/i915_vma.c   |   7 +-
 drivers/gpu/drm/i915/i915_vma.h   |   2 -
 drivers/gpu/drm/i915/i915_vma_types.h |   8 +
 11 files changed, 318 insertions(+), 10 deletions(-)
 create mode 100644 drivers/gpu/drm/i915/gem/i915_gem_vm_bind.h
 create mode 100644 drivers/gpu/drm/i915/gem/i915_gem_vm_bind_object.c

diff --git a/drivers/gpu/drm/i915/Makefile b/drivers/gpu/drm/i915/Makefile
index 522ef9b4aff3..4e1627e96c6e 100644
--- a/drivers/gpu/drm/i915/Makefile
+++ b/drivers/gpu/drm/i915/Makefile
@@ -165,6 +165,7 @@ gem-y += \
gem/i915_gem_ttm_move.o \
gem/i915_gem_ttm_pm.o \
gem/i915_gem_userptr.o \
+   gem/i915_gem_vm_bind_object.o \
gem/i915_gem_wait.o \
gem/i915_gemfs.o
 i915-y += \
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_create.c 
b/drivers/gpu/drm/i915/gem/i915_gem_create.c
index 33673fe7ee0a..927a87e5ec59 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_create.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_create.c
@@ -15,10 +15,10 @@
 #include "i915_trace.h"
 #include "i915_user_extensions.h"
 
-static u32 object_max_page_size(struct intel_memory_region **placements,
-   unsigned int n_placements)
+u32 i915_gem_object_max_page_size(struct intel_memory_region **placements,
+ unsigned int n_placements)
 {
-   u32 max_page_size = 0;
+   u32 max_page_size = I915_GTT_PAGE_SIZE_4K;
int i;
 
for (i = 0; i < n_placements; i++) {
@@ -28,7 +28,6 @@ static u32 object_max_page_size(struct intel_memory_region 
**placements,
max_page_size = max_t(u32, max_page_size, mr->min_page_size);
}
 
-   GEM_BUG_ON(!max_page_size);
return max_page_size;
 }
 
@@ -99,7 +98,8 @@ __i915_gem_object_create_user_ext(struct drm_i915_private 
*i915, u64 size,
 
i915_gem_flush_free_objects(i915);
 
-   size = round_up(size, object_max_page_size(placements, n_placements));
+   size = round_up(size, i915_gem_object_max_page_size(placements,
+   n_placements));
if (size == 0)
return ERR_PTR(-EINVAL);
 
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_object.h 
b/drivers/gpu/drm/i915/gem/i915_gem_object.h
index 6f0a3ce35567..650de2224843 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_object.h
+++ b/drivers/gpu/drm/i915/gem/i915_gem_object.h
@@ -47,6 +47,8 @@ static inline bool i915_gem_object_size_2big(u64 size)
 }
 
 void i915_gem_init__objects(struct drm_i915_private *i915);
+u32 i915_gem_object_max_page_size(struct intel_memory_region **placements,
+ unsigned int n_placements);
 
 void i915_objects_module_exit(void);
 int i915_objects_module_init(void);
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_vm_bind.h 
b/drivers/gpu/drm/i915/gem/i915_gem_vm_bind.h
new file mode 100644
index ..642cdb559f17
--- /dev/null
+++ b/drivers/gpu/drm/i915/gem/i915_gem_vm_bind.h
@@ -0,0 +1,38 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Copyright © 2022 Intel Corporation
+ */
+
+#ifndef __I915_GEM_VM_BIND_H
+#define __I915_GEM_VM_BIND_H
+
+#include "i915_drv.h"
+
+#define assert_vm_bind_held(vm)   lockdep_assert_held(&(vm)->vm_bind_lock)
+
+static inline void i915_gem_vm_bind_lock(struct i915_address_space *vm)
+{
+   mutex_lock(&vm->vm_bind_lock);
+}
+
+static inline int
+i915_gem_vm_bind_lock_interruptible(struct i915_address_space *vm)
+{
+   return mutex_lock_interruptible(&vm->vm_bind_lock);
+}
+
+static inline void i915_gem_vm_bind_unlock(struct i915_address_space *vm)
+{
+   mutex_unlock(&vm->vm_bind_lock);
+}
+
+struct i915_vma *
+i915_gem_vm_bind_lookup_vma(struct i915_address_space *vm, u64 va);
+void i915_gem_vm_bind_remove(struct i915_vma *vma, bool release_obj);
+int i915_gem_vm_bind_obj(struct i915_address_space *vm,
+struct drm_i915_gem_vm_bind *va,
+struct drm_file *file);
+int i915_gem_vm_unbind_obj(struct i915_address_space *vm,
+  struct drm_i915_gem_vm_unbind *va);
+
+#endif /* __I915_GEM_VM_BIND_H */
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_vm_bind_object.c 
b/drivers/gpu/drm/i915/gem/i915_gem_vm_bind_object.c
new file mode 100644
index ..43ceb4dcca6c
--- /dev/null
+++ b/drivers/gpu/drm/i915/gem/i9