Re: [Nouveau] ensure device private pages have an owner v2

2020-03-16 Thread Bharata B Rao
On Mon, Mar 16, 2020 at 08:32:12PM +0100, Christoph Hellwig wrote: > When acting on device private mappings a driver needs to know if the > device (or other entity in case of kvmppc) actually owns this private > mapping. This series adds an owner field and converts the migrate_vma > code over to c

Re: [Nouveau] [PATCH 4/4] mm: check the device private page owner in hmm_range_fault

2020-03-16 Thread Ralph Campbell
On 3/16/20 12:32 PM, Christoph Hellwig wrote: Hmm range fault will succeed for any kind of device private memory, even if it doesn't belong to the calling entity. While nouveau has some crude checks for that, they are broken because they assume nouveau is the only user of device private memory

Re: [Nouveau] [PATCH 3/4] mm: simplify device private page handling in hmm_range_fault

2020-03-16 Thread Ralph Campbell
On 3/16/20 12:32 PM, Christoph Hellwig wrote: Remove the code to fault device private pages back into system memory that has never been used by any driver. Also replace the usage of the HMM_PFN_DEVICE_PRIVATE flag in the pfns array with a simple is_device_private_page check in nouveau. Signed

Re: [Nouveau] [PATCH 2/4] mm: handle multiple owners of device private pages in migrate_vma

2020-03-16 Thread Ralph Campbell
On 3/16/20 12:32 PM, Christoph Hellwig wrote: Add a new src_owner field to struct migrate_vma. If the field is set, only device private pages with page->pgmap->owner equal to that field are migrated. If the field is not set only "normal" pages are migrated. Signed-off-by: Christoph Hellwig

Re: [Nouveau] [PATCH 3/4] mm: simplify device private page handling in hmm_range_fault

2020-03-16 Thread Christoph Hellwig
On Mon, Mar 16, 2020 at 04:59:23PM -0300, Jason Gunthorpe wrote: > However, between patch 3 and 4 doesn't this break amd gpu as it will > return device_private pages now if not requested? Squash the two? No change in behavior in this patch as long as HMM_PFN_DEVICE_PRIVATE isn't set in ->pfns or -

Re: [Nouveau] [PATCH 1/4] memremap: add an owner field to struct dev_pagemap

2020-03-16 Thread Ralph Campbell
On 3/16/20 12:32 PM, Christoph Hellwig wrote: Add a new opaque owner field to struct dev_pagemap, which will allow the hmm and migrate_vma code to identify who owns ZONE_DEVICE memory, and refuse to work on mappings not owned by the calling entity. Signed-off-by: Christoph Hellwig This look

Re: [Nouveau] [PATCH 2/2] mm: remove device private page support from hmm_range_fault

2020-03-16 Thread Ralph Campbell
On 3/16/20 1:09 PM, Jason Gunthorpe wrote: On Mon, Mar 16, 2020 at 07:49:35PM +0100, Christoph Hellwig wrote: On Mon, Mar 16, 2020 at 11:42:19AM -0700, Ralph Campbell wrote: On 3/16/20 10:52 AM, Christoph Hellwig wrote: No driver has actually used properly wire up and support this feature.

Re: [Nouveau] [PATCH 2/2] mm: remove device private page support from hmm_range_fault

2020-03-16 Thread Jason Gunthorpe
On Mon, Mar 16, 2020 at 07:49:35PM +0100, Christoph Hellwig wrote: > On Mon, Mar 16, 2020 at 11:42:19AM -0700, Ralph Campbell wrote: > > > > On 3/16/20 10:52 AM, Christoph Hellwig wrote: > >> No driver has actually used properly wire up and support this feature. > >> There is various code related t

Re: [Nouveau] [PATCH 3/4] mm: simplify device private page handling in hmm_range_fault

2020-03-16 Thread Jason Gunthorpe
On Mon, Mar 16, 2020 at 08:32:15PM +0100, Christoph Hellwig wrote: > diff --git a/mm/hmm.c b/mm/hmm.c > index 180e398170b0..cfad65f6a67b 100644 > +++ b/mm/hmm.c > @@ -118,15 +118,6 @@ static inline void hmm_pte_need_fault(const struct > hmm_vma_walk *hmm_vma_walk, > /* We aren't ask to do an

Re: [Nouveau] [PATCH 2/2] mm: remove device private page support from hmm_range_fault

2020-03-16 Thread Ralph Campbell
On 3/16/20 11:49 AM, Christoph Hellwig wrote: On Mon, Mar 16, 2020 at 11:42:19AM -0700, Ralph Campbell wrote: On 3/16/20 10:52 AM, Christoph Hellwig wrote: No driver has actually used properly wire up and support this feature. There is various code related to it in nouveau, but as far as I c

Re: [Nouveau] [PATCH 4/4] mm: check the device private page owner in hmm_range_fault

2020-03-16 Thread Jason Gunthorpe
On Mon, Mar 16, 2020 at 08:32:16PM +0100, Christoph Hellwig wrote: > Hmm range fault will succeed for any kind of device private memory, > even if it doesn't belong to the calling entity. While nouveau > has some crude checks for that, they are broken because they assume > nouveau is the only user

[Nouveau] [PATCH 4/4] mm: check the device private page owner in hmm_range_fault

2020-03-16 Thread Christoph Hellwig
Hmm range fault will succeed for any kind of device private memory, even if it doesn't belong to the calling entity. While nouveau has some crude checks for that, they are broken because they assume nouveau is the only user of device private memory. Fix this by passing in an expected pgmap owner

[Nouveau] [PATCH 3/4] mm: simplify device private page handling in hmm_range_fault

2020-03-16 Thread Christoph Hellwig
Remove the code to fault device private pages back into system memory that has never been used by any driver. Also replace the usage of the HMM_PFN_DEVICE_PRIVATE flag in the pfns array with a simple is_device_private_page check in nouveau. Signed-off-by: Christoph Hellwig --- drivers/gpu/drm/a

[Nouveau] [PATCH 2/4] mm: handle multiple owners of device private pages in migrate_vma

2020-03-16 Thread Christoph Hellwig
Add a new src_owner field to struct migrate_vma. If the field is set, only device private pages with page->pgmap->owner equal to that field are migrated. If the field is not set only "normal" pages are migrated. Signed-off-by: Christoph Hellwig Fixes: df6ad69838fc ("mm/device-public-memory: dev

[Nouveau] ensure device private pages have an owner v2

2020-03-16 Thread Christoph Hellwig
When acting on device private mappings a driver needs to know if the device (or other entity in case of kvmppc) actually owns this private mapping. This series adds an owner field and converts the migrate_vma code over to check it. I looked into doing the same for hmm_range_fault, but as far as I

[Nouveau] [PATCH 1/4] memremap: add an owner field to struct dev_pagemap

2020-03-16 Thread Christoph Hellwig
Add a new opaque owner field to struct dev_pagemap, which will allow the hmm and migrate_vma code to identify who owns ZONE_DEVICE memory, and refuse to work on mappings not owned by the calling entity. Signed-off-by: Christoph Hellwig --- arch/powerpc/kvm/book3s_hv_uvmem.c | 2 ++ drivers/g

Re: [Nouveau] [PATCH 2/2] mm: remove device private page support from hmm_range_fault

2020-03-16 Thread Christoph Hellwig
On Mon, Mar 16, 2020 at 04:04:43PM -0300, Jason Gunthorpe wrote: > > This is not actually true. OpenCL 2.x does support SVM with nouveau and > > device private memory via clEnqueueSVMMigrateMem(). > > Also, Ben Skeggs has accepted a set of patches to map GPU memory after being > > migrated and this

Re: [Nouveau] [PATCH 2/2] mm: remove device private page support from hmm_range_fault

2020-03-16 Thread Jason Gunthorpe
On Mon, Mar 16, 2020 at 11:42:19AM -0700, Ralph Campbell wrote: > > On 3/16/20 10:52 AM, Christoph Hellwig wrote: > > No driver has actually used properly wire up and support this feature. > > There is various code related to it in nouveau, but as far as I can tell > > it never actually got turned

Re: [Nouveau] [PATCH 2/2] mm: remove device private page support from hmm_range_fault

2020-03-16 Thread Christoph Hellwig
On Mon, Mar 16, 2020 at 07:49:35PM +0100, Christoph Hellwig wrote: > On Mon, Mar 16, 2020 at 11:42:19AM -0700, Ralph Campbell wrote: > > > > On 3/16/20 10:52 AM, Christoph Hellwig wrote: > >> No driver has actually used properly wire up and support this feature. > >> There is various code related t

Re: [Nouveau] [PATCH 2/2] mm: remove device private page support from hmm_range_fault

2020-03-16 Thread Christoph Hellwig
On Mon, Mar 16, 2020 at 11:42:19AM -0700, Ralph Campbell wrote: > > On 3/16/20 10:52 AM, Christoph Hellwig wrote: >> No driver has actually used properly wire up and support this feature. >> There is various code related to it in nouveau, but as far as I can tell >> it never actually got turned on,

Re: [Nouveau] [PATCH 2/2] mm: remove device private page support from hmm_range_fault

2020-03-16 Thread Ralph Campbell
On 3/16/20 10:52 AM, Christoph Hellwig wrote: No driver has actually used properly wire up and support this feature. There is various code related to it in nouveau, but as far as I can tell it never actually got turned on, and the only changes since the initial commit are global cleanups. Thi

Re: [Nouveau] [PATCH 1/2] mm: handle multiple owners of device private pages in migrate_vma

2020-03-16 Thread Christoph Hellwig
On Mon, Mar 16, 2020 at 03:17:07PM -0300, Jason Gunthorpe wrote: > On Mon, Mar 16, 2020 at 06:52:58PM +0100, Christoph Hellwig wrote: > > Add a new opaque owner field to struct dev_pagemap, which will allow > > the hmm and migrate_vma code to identify who owns ZONE_DEVICE memory, > > and refuse to

Re: [Nouveau] [PATCH 1/2] mm: handle multiple owners of device private pages in migrate_vma

2020-03-16 Thread Jason Gunthorpe
On Mon, Mar 16, 2020 at 06:52:58PM +0100, Christoph Hellwig wrote: > Add a new opaque owner field to struct dev_pagemap, which will allow > the hmm and migrate_vma code to identify who owns ZONE_DEVICE memory, > and refuse to work on mappings not owned by the calling entity. Using a pointer seems

[Nouveau] [PATCH 2/2] mm: remove device private page support from hmm_range_fault

2020-03-16 Thread Christoph Hellwig
No driver has actually used properly wire up and support this feature. There is various code related to it in nouveau, but as far as I can tell it never actually got turned on, and the only changes since the initial commit are global cleanups. Signed-off-by: Christoph Hellwig --- drivers/gpu/drm

[Nouveau] ensure device private pages have an owner

2020-03-16 Thread Christoph Hellwig
When acting on device private mappings a driver needs to know if the device (or other entity in case of kvmppc) actually owns this private mapping. This series adds an owner field and converts the migrate_vma code over to check it. I looked into doing the same for hmm_range_fault, but as far as I

[Nouveau] [PATCH 1/2] mm: handle multiple owners of device private pages in migrate_vma

2020-03-16 Thread Christoph Hellwig
Add a new opaque owner field to struct dev_pagemap, which will allow the hmm and migrate_vma code to identify who owns ZONE_DEVICE memory, and refuse to work on mappings not owned by the calling entity. Signed-off-by: Christoph Hellwig --- arch/powerpc/kvm/book3s_hv_uvmem.c | 4 drivers