Skip to contentSkip to conversation

drm/i915: Don't prefault the entire obj if the vma is smaller

PATCH In review [email protected] 3 participants 6 messages Jun 17, 2014 – Jun 18, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/i915: Don't prefault the entire obj if the vma is smaller

From: Ville Syrjälä <[email protected]>

Take the minimum of the object size and the vma size and prefault only that much. Avoids a SIGBUS when mmapping only a portion of the object.

Prefaulting was introduced here:
commit b90b91d87038f6b257b40a02b42ed4f9705e06f0
Author: Chris Wilson <[email protected]>
Date: Tue Jun 10 12:14:40 2014 +0100

drm/i915: Prefault the entire object on first page fault

---
 drivers/gpu/drm/i915/i915_gem.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_gem.c +4 -1
index 6f8c206..4ef80d1 100644
@@ -1578,9 +1578,12 @@ int i915_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
 	pfn >>= PAGE_SHIFT;
 
 	if (!obj->fault_mappable) {
+		unsigned long size = min_t(unsigned long,
+					   vma->vm_end - vma->vm_start,
+					   obj->base.size);
 		int i;
 
-		for (i = 0; i < obj->base.size >> PAGE_SHIFT; i++) {
+		for (i = 0; i < size >> PAGE_SHIFT; i++) {
 			ret = vm_insert_pfn(vma,
 					    (unsigned long)vma->vm_start + i * PAGE_SIZE,
 					    pfn + i);
Signature · 6 lines
1.8.5.5

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#1 lore raw
Quoted 11 lines · On Tue, Jun 17, 2014 at 8:03 PM, <[email protected]> wrote:

From: Ville Syrjälä <[email protected]>

Take the minimum of the object size and the vma size and prefault only that much. Avoids a SIGBUS when mmapping only a portion of the object.

Prefaulting was introduced here:
commit b90b91d87038f6b257b40a02b42ed4f9705e06f0
Author: Chris Wilson <[email protected]>
Date: Tue Jun 10 12:14:40 2014 +0100

Quoted 4 lines

drm/i915: Prefault the entire object on first page fault

Do we have an igt for this?
-Daniel

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#2 lore raw
Quoted 12 lines · Daniel Vetter
Quoted 11 lines · On Tue, Jun 17, 2014 at 8:03 PM, <[email protected]> wrote:

From: Ville Syrjälä <[email protected]>

Take the minimum of the object size and the vma size and prefault only that much. Avoids a SIGBUS when mmapping only a portion of the object.

Prefaulting was introduced here:
commit b90b91d87038f6b257b40a02b42ed4f9705e06f0
Author: Chris Wilson <[email protected]>
Date: Tue Jun 10 12:14:40 2014 +0100

Quoted 6 lines
Quoted 4 lines

drm/i915: Prefault the entire object on first page fault

Do we have an igt for this?

Well, written one since trivial to do and merged the patch. Thanks. -Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#3 lore raw
In reply to [email protected]
Quoted 24 lines · On Tue, Jun 17, 2014 at 09:03:00PM +0300, [email protected] wrote:

From: Ville Syrjälä <[email protected]>

Take the minimum of the object size and the vma size and prefault only that much. Avoids a SIGBUS when mmapping only a portion of the object.

Prefaulting was introduced here:
commit b90b91d87038f6b257b40a02b42ed4f9705e06f0
Author: Chris Wilson <[email protected]>
Date: Tue Jun 10 12:14:40 2014 +0100

drm/i915: Prefault the entire object on first page fault

---
 drivers/gpu/drm/i915/i915_gem.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_gem.c +0 -0
index 6f8c206..4ef80d1 100644

drivers/gpu/drm/i915/i915_gem.c int i915_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf) · line 1583

Quoted 6 lines
drivers/gpu/drm/i915/i915_gem.c +3 -0
@@ -1578,9 +1578,12 @@ int i915_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
 	pfn >>= PAGE_SHIFT;
 
 	if (!obj->fault_mappable) {
+		unsigned long size = min_t(unsigned long,
+					   vma->vm_end - vma->vm_start,
+					   obj->base.size);

The vma should be the same size as the obj... Unless it gets coalesced... I wonder if that is even legal for our objects because I was under the impression that we depended upon it in other places. -Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#4 lore raw
Quoted 27 lines · Chris Wilson
Quoted 26 lines · On Tue, Jun 17, 2014 at 09:03:00PM +0300, [email protected] wrote:

From: Ville Syrjälä <[email protected]>

Take the minimum of the object size and the vma size and prefault only that much. Avoids a SIGBUS when mmapping only a portion of the object.

Prefaulting was introduced here:
commit b90b91d87038f6b257b40a02b42ed4f9705e06f0
Author: Chris Wilson <[email protected]>
Date: Tue Jun 10 12:14:40 2014 +0100

drm/i915: Prefault the entire object on first page fault

---
 drivers/gpu/drm/i915/i915_gem.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_gem.c +0 -0
index 6f8c206..4ef80d1 100644
@@ -1578,9 +1578,12 @@ int i915_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
 	pfn >>= PAGE_SHIFT;
 
Quoted 8 lines

drivers/gpu/drm/i915/i915_gem.c int i915_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf) · line 1583

Quoted 4 lines
drivers/gpu/drm/i915/i915_gem.c +3 -0
 	if (!obj->fault_mappable) {
+		unsigned long size = min_t(unsigned long,
+					   vma->vm_end - vma->vm_start,
+					   obj->base.size);

The vma should be the same size as the obj... Unless it gets coalesced... I wonder if that is even legal for our objects because I was under the impression that we depended upon it in other places.

You have to map from the first page otherwise the lookup won't find it. But apparently we have at least igts that hit this (Rodrigo's psr test as an example). And it's easy to test and easy to fix, so figured ok to merge.
-Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#5 lore raw
Quoted 37 lines · Daniel Vetter
Quoted 27 lines · Chris Wilson
Quoted 26 lines · On Tue, Jun 17, 2014 at 09:03:00PM +0300, [email protected] wrote:

From: Ville Syrjälä <[email protected]>

Take the minimum of the object size and the vma size and prefault only that much. Avoids a SIGBUS when mmapping only a portion of the object.

Prefaulting was introduced here:
commit b90b91d87038f6b257b40a02b42ed4f9705e06f0
Author: Chris Wilson <[email protected]>
Date: Tue Jun 10 12:14:40 2014 +0100

drm/i915: Prefault the entire object on first page fault

---
 drivers/gpu/drm/i915/i915_gem.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_gem.c +0 -0
index 6f8c206..4ef80d1 100644
@@ -1578,9 +1578,12 @@ int i915_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
 	pfn >>= PAGE_SHIFT;
 
Quoted 8 lines

drivers/gpu/drm/i915/i915_gem.c int i915_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf) · line 1583

Quoted 4 lines
drivers/gpu/drm/i915/i915_gem.c +3 -0
 	if (!obj->fault_mappable) {
+		unsigned long size = min_t(unsigned long,
+					   vma->vm_end - vma->vm_start,
+					   obj->base.size);

The vma should be the same size as the obj... Unless it gets coalesced... I wonder if that is even legal for our objects because I was under the impression that we depended upon it in other places.

Quoted 4 lines

You have to map from the first page otherwise the lookup won't find it. But apparently we have at least igts that hit this (Rodrigo's psr test as an example). And it's easy to test and easy to fix, so figured ok to merge.

Oh, userspace is mapping less than the obj. Yes, I now see that drm_gem_obj_mmap() allows that. I ruled out that we merged our vma together, as the core doesn't merge vma with vma->vm_ops->close (which we do). And for what it is worth, these switched to using vma->vm_end - vma->vm_start in the next, postponed, patch.
-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre