Skip to contentSkip to conversation

drm/amdgpu: allow write access to mapped userptrs

PATCH Applied Christian König 3 participants 6 messages Mar 11, 2016 – Mar 18, 2016

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

PATCH 1/1 drm/amdgpu: allow write access to mapped userptrs

From: Christian König <[email protected]>

With the updated MMU notifier we should also be able to handle the writeback case correctly.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +3 -5
index 7f6b4d9..5d280f6 100644
@@ -258,12 +258,10 @@ int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data,
 	    AMDGPU_GEM_USERPTR_REGISTER))
 		return -EINVAL;
 
-	if (!(args->flags & AMDGPU_GEM_USERPTR_READONLY) && (
-	     !(args->flags & AMDGPU_GEM_USERPTR_ANONONLY) ||
-	     !(args->flags & AMDGPU_GEM_USERPTR_REGISTER))) {
+	if (!(args->flags & AMDGPU_GEM_USERPTR_READONLY) &&
+	     !(args->flags & AMDGPU_GEM_USERPTR_REGISTER)) {
 
-		/* if we want to write to it we must require anonymous
-		   memory and install a MMU notifier */
+		/* if we want to write to it we must install a MMU notifier */
 		return -EACCES;
 	}
 
Signature · 6 lines
2.5.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Applied
#1 lore raw
Quoted 6 lines · Christian König

From: Christian König <[email protected]>

With the updated MMU notifier we should also be able to handle the writeback case correctly.

Applied. thanks!

Alex

Quoted 25 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +3 -6
index 7f6b4d9..5d280f6 100644
@@ -258,12 +258,10 @@ int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data,
            AMDGPU_GEM_USERPTR_REGISTER))
                return -EINVAL;
 
-       if (!(args->flags & AMDGPU_GEM_USERPTR_READONLY) && (
-            !(args->flags & AMDGPU_GEM_USERPTR_ANONONLY) ||
-            !(args->flags & AMDGPU_GEM_USERPTR_REGISTER))) {
+       if (!(args->flags & AMDGPU_GEM_USERPTR_READONLY) &&
+            !(args->flags & AMDGPU_GEM_USERPTR_REGISTER)) {
 
-               /* if we want to write to it we must require anonymous
-                  memory and install a MMU notifier */
+               /* if we want to write to it we must install a MMU notifier */
                return -EACCES;
        }
 
--
Quoted 2 lines

2.5.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#2 lore raw
In reply to Christian König
Quoted 5 lines · Christian König

From: Christian König <[email protected]>

With the updated MMU notifier we should also be able to handle the writeback case correctly.

Out of curiosity what are you refering too ? I do not see anything special on amdgpu_mn.c logs and i do not see why you could not use then for write before.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#3 lore raw

Am 17.03.2016 um 20:18 schrieb Jerome Glisse:

Quoted 10 lines
Quoted 5 lines · Christian König

From: Christian König <[email protected]>

With the updated MMU notifier we should also be able to handle the writeback case correctly.

Out of curiosity what are you refering too ? I do not see anything special on amdgpu_mn.c logs and i do not see why you could not use then for write before.

We moved the get_user_pages() outside of reserving the BO and tested that quite extensively.

And don't ask me why that shouldn't have worked. It was you who gave the advise to not allow it.

I think the rational was something like that the writeback code disables CPU writes, compute a CRC and start to write the page to disk. When the GPU could write to the page in that moment the CRC won't match any more and we would get errors reported from the disk driver.

But I think that the MMU notifier should catch that case as well.

Cheers,
Christian.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#4 lore raw
Quoted 18 lines · Christian König

Am 17.03.2016 um 20:18 schrieb Jerome Glisse:

Quoted 10 lines
Quoted 5 lines · Christian König

From: Christian König <[email protected]>

With the updated MMU notifier we should also be able to handle the writeback case correctly.

Out of curiosity what are you refering too ? I do not see anything special on amdgpu_mn.c logs and i do not see why you could not use then for write before.

We moved the get_user_pages() outside of reserving the BO and tested that quite extensively.

And don't ask me why that shouldn't have worked. It was you who gave the advise to not allow it.

Quoted 6 lines

I think the rational was something like that the writeback code disables CPU writes, compute a CRC and start to write the page to disk. When the GPU could write to the page in that moment the CRC won't match any more and we would get errors reported from the disk driver.

But I think that the MMU notifier should catch that case as well.

So to make sure we talk about same code i am looking at drm-next-4.6 :
https://cgit.freedesktop.org/~agd5f/linux/tree/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c?h=drm-next-4.6&id=390be2824fa4211c2e973c69b72e04000559bba3

In which you only register invalidate_range_start and it is not enough to handle page write back (see mm/rmap.c page_mkclean_one() call from page_mkclean()). So this patch is kind of dangerous as it could end up with filesystem corruption (depending on fs and how unlucky you are).

So you either need to add invalidate_page() callback to mmu_notifier or at very least reinstate the AMDGPU_GEM_USERPTR_ANONONLY flag.

Cheers,
Jérôme
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#5 lore raw

Am 18.03.2016 um 11:02 schrieb Jerome Glisse:

Quoted 27 lines · Christian König
Quoted 17 lines

Am 17.03.2016 um 20:18 schrieb Jerome Glisse:

Quoted 10 lines
Quoted 5 lines · Christian König

From: Christian König <[email protected]>

With the updated MMU notifier we should also be able to handle the writeback case correctly.

Out of curiosity what are you refering too ? I do not see anything special on amdgpu_mn.c logs and i do not see why you could not use then for write before.

We moved the get_user_pages() outside of reserving the BO and tested that quite extensively.

And don't ask me why that shouldn't have worked. It was you who gave the advise to not allow it.

Quoted 6 lines

I think the rational was something like that the writeback code disables CPU writes, compute a CRC and start to write the page to disk. When the GPU could write to the page in that moment the CRC won't match any more and we would get errors reported from the disk driver.

But I think that the MMU notifier should catch that case as well.

So to make sure we talk about same code i am looking at drm-next-4.6 :
https://cgit.freedesktop.org/~agd5f/linux/tree/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c?h=drm-next-4.6&id=390be2824fa4211c2e973c69b72e04000559bba3

Quoted 7 lines

In which you only register invalidate_range_start and it is not enough to handle page write back (see mm/rmap.c page_mkclean_one() call from page_mkclean()). So this patch is kind of dangerous as it could end up with filesystem corruption (depending on fs and how unlucky you are).

So you either need to add invalidate_page() callback to mmu_notifier or at very least reinstate the AMDGPU_GEM_USERPTR_ANONONLY flag.

Oh, crap. Yeah thanks for the info. I will be looking into that.

Either I can come up with a quick solution or we need to revert that once more.

Regards,
Christian.

Quoted 3 lines

Cheers,
Jérôme

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel