Re: [PATCH] mm: Remove double faults once write a device pfn

2024-01-24 Thread Alistair Popple
"Zhou, Xianrong" writes: > [AMD Official Use Only - General] > >> > The vmf_insert_pfn_prot could cause unnecessary double faults on a >> > device pfn. Because currently the vmf_insert_pfn_prot does not >> > make the pfn writable so the pte entry is normally read-only or >> >

Re: [Nouveau] [PATCH v2] mm: Take a page reference when removing device exclusive entries

2023-03-29 Thread Alistair Popple
Christoph Hellwig writes: > s/page/folio/ in the entire commit log? I debated that but settled on leaving it as is because device exclusive entries only deal with non-compound pages for now and didn't want to give any other impression. Happy to change that though if people think it would be

[Nouveau] [PATCH v2] mm: Take a page reference when removing device exclusive entries

2023-03-29 Thread Alistair Popple
changes. Signed-off-by: Alistair Popple Reviewed-by: Ralph Campbell Reviewed-by: John Hubbard Fixes: b756a3b5e7ea ("mm: device exclusive memory access") Cc: sta...@vger.kernel.org --- Changes for v2: - Rebased to Linus master - Reworded commit message - Switched to using foli

Re: [Nouveau] [PATCH] mm: Take a page reference when removing device exclusive entries

2023-03-29 Thread Alistair Popple
Alistair Popple writes: > John Hubbard writes: > >> On 3/28/23 20:16, Matthew Wilcox wrote: >> ... >>>> + if (!get_page_unless_zero(vmf->page)) >>>> + return 0; >>> From a folio point of view: what the hell are you doing here

Re: [Nouveau] [PATCH] mm: Take a page reference when removing device exclusive entries

2023-03-29 Thread Alistair Popple
John Hubbard writes: > On 3/28/23 20:16, Matthew Wilcox wrote: > ... >>> + if (!get_page_unless_zero(vmf->page)) >>> + return 0; >> From a folio point of view: what the hell are you doing here? Tail >> pages don't have individual refcounts; all the refcounts are actually I had

Re: [Nouveau] [PATCH] mm: Take a page reference when removing device exclusive entries

2023-03-28 Thread Alistair Popple
John Hubbard writes: >> warnings such as PAGE_FLAGS_CHECK_AT_FREE due to the page being locked >> when the refcount drops to zero. Note that during removal of the >> device exclusive entry the PTE is currently re-checked under the PTL >> so no futher bad page accesses occur once it is locked.

[Nouveau] [PATCH] mm: Take a page reference when removing device exclusive entries

2023-03-27 Thread Alistair Popple
re-checked under the PTL so no futher bad page accesses occur once it is locked. Signed-off-by: Alistair Popple Fixes: b756a3b5e7ea ("mm: device exclusive memory access") Cc: sta...@vger.kernel.org --- mm/memory.c | 14 +- 1 file changed, 13 insertions(+), 1 deletion(-)

Re: [Nouveau] [PATCH v2 0/8] Fix several device private page reference counting issues

2022-10-25 Thread Alistair Popple
"Vlastimil Babka (SUSE)" writes: > On 9/28/22 14:01, Alistair Popple wrote: >> This series aims to fix a number of page reference counting issues in >> drivers dealing with device private ZONE_DEVICE pages. These result in >> use-after-free type bugs, either fro

[Nouveau] [PATCH] nouveau: Fix migrate_to_ram() for faulting page

2022-10-19 Thread Alistair Popple
his change was inadvertently dropped from that patch causing GPU to CPU migration to fail so add it here. Signed-off-by: Alistair Popple Fixes: 16ce101db85d ("mm/memory.c: fix race when faulting a device private page") Cc: John Hubbard Cc: Ralph Campbell Cc: Lyude Paul Cc: Ben Skeggs

Re: [Nouveau] [PATCH v2 1/8] mm/memory.c: Fix race when faulting a device private page

2022-10-02 Thread Alistair Popple
Felix Kuehling writes: > On 2022-09-28 08:01, Alistair Popple wrote: >> When the CPU tries to access a device private page the migrate_to_ram() >> callback associated with the pgmap for the page is called. However no >> reference is taken on the faulting page. T

Re: [Nouveau] [PATCH 2/7] mm: Free device private pages have zero refcount

2022-09-29 Thread Alistair Popple
Dan Williams writes: > Alistair Popple wrote: >> >> Jason Gunthorpe writes: >> >> > On Mon, Sep 26, 2022 at 04:03:06PM +1000, Alistair Popple wrote: >> >> Since 27674ef6c73f ("mm: remove the extra ZONE_DEVICE struct page >> >>

Re: [Nouveau] [PATCH v2 8/8] hmm-tests: Add test for migrate_device_range()

2022-09-29 Thread Alistair Popple
Andrew Morton writes: > On Wed, 28 Sep 2022 22:01:22 +1000 Alistair Popple wrote: > >> @@ -1401,22 +1494,7 @@ static int dmirror_device_init(struct dmirror_device >> *mdevice, int id) >> >> static void dmirror_device_remove(struct dmirror_device *mdevice

Re: [Nouveau] [PATCH 1/7] mm/memory.c: Fix race when faulting a device private page

2022-09-28 Thread Alistair Popple
Michael Ellerman writes: > Alistair Popple writes: >> When the CPU tries to access a device private page the migrate_to_ram() >> callback associated with the pgmap for the page is called. However no >> reference is taken on the faulting page. Therefore a concurrent >&

[Nouveau] [PATCH v2 8/8] hmm-tests: Add test for migrate_device_range()

2022-09-28 Thread Alistair Popple
Signed-off-by: Alistair Popple Cc: Jason Gunthorpe Cc: Ralph Campbell Cc: John Hubbard Cc: Alex Sierra Cc: Felix Kuehling --- lib/test_hmm.c | 120 +- lib/test_hmm_uapi.h| 1 +- tools/testing/selftests/vm/hmm-tests.c

[Nouveau] [PATCH v2 7/8] nouveau/dmem: Evict device private memory during release

2022-09-28 Thread Alistair Popple
device pages have been freed which may never happen. Fix this by migrating device mappings back to normal CPU memory prior to freeing the GPU memory chunks and associated device private pages. Signed-off-by: Alistair Popple Cc: Lyude Paul Cc: Ben Skeggs Cc: Ralph Campbell Cc: John Hubbard

[Nouveau] [PATCH v2 5/8] mm/migrate_device.c: Add migrate_device_range()

2022-09-28 Thread Alistair Popple
n free up device memory. To allow that this patch introduces the migrate_device family of functions which are functionally similar to migrate_vma but which skips the initial lookup based on mapping. Signed-off-by: Alistair Popple Cc: "Huang, Ying" Cc: Zi Yan Cc: Matthew Wilcox Cc:

[Nouveau] [PATCH v2 6/8] nouveau/dmem: Refactor nouveau_dmem_fault_copy_one()

2022-09-28 Thread Alistair Popple
. Refactor out the core functionality so that it is not specific to fault handling. Signed-off-by: Alistair Popple Reviewed-by: Lyude Paul Cc: Ben Skeggs Cc: Ralph Campbell Cc: John Hubbard --- drivers/gpu/drm/nouveau/nouveau_dmem.c | 58 +-- 1 file changed, 28 insertions

[Nouveau] [PATCH v2 4/8] mm/migrate_device.c: Refactor migrate_vma and migrate_deivce_coherent_page()

2022-09-28 Thread Alistair Popple
this isn't true for device private memory, and a future change requires similar functionality for device private memory. So refactor the code into something more sensible for migrating device memory without a vma. Signed-off-by: Alistair Popple Cc: "Huang, Ying" Cc: Zi Yan Cc: Matthew

[Nouveau] [PATCH v2 3/8] mm/memremap.c: Take a pgmap reference on page allocation

2022-09-28 Thread Alistair Popple
ough pages are still mapped by the kernel which can lead to kernel crashes, particularly if a driver frees the pagemap. To fix this drivers should take a pagemap reference when allocating the page. This reference can then be returned when the page is freed. Signed-off-by: Alistair Popple Fixes: 27

[Nouveau] [PATCH v2 1/8] mm/memory.c: Fix race when faulting a device private page

2022-09-28 Thread Alistair Popple
if it's expected or not. Signed-off-by: Alistair Popple Cc: Jason Gunthorpe Cc: John Hubbard Cc: Ralph Campbell Cc: Michael Ellerman Cc: Felix Kuehling Cc: Lyude Paul --- arch/powerpc/kvm/book3s_hv_uvmem.c | 15 ++- drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 17

[Nouveau] [PATCH v2 2/8] mm: Free device private pages have zero refcount

2022-09-28 Thread Alistair Popple
functions such as get_page_unless_zero(). Signed-off-by: Alistair Popple Cc: Jason Gunthorpe Cc: Michael Ellerman Cc: Felix Kuehling Cc: Alex Deucher Cc: Christian König Cc: Ben Skeggs Cc: Lyude Paul Cc: Ralph Campbell Cc: Alex Sierra Cc: John Hubbard Cc: Dan Williams --- This will conflict with Dan's ser

[Nouveau] [PATCH v2 0/8] Fix several device private page reference counting issues

2022-09-28 Thread Alistair Popple
-...@lists.freedesktop.org Cc: nouveau@lists.freedesktop.org Cc: dri-de...@lists.freedesktop.org Alistair Popple (8): mm/memory.c: Fix race when faulting a device private page mm: Free device private pages have zero refcount mm/memremap.c: Take a pgmap reference on page allocation mm

Re: [Nouveau] [PATCH 5/7] nouveau/dmem: Refactor nouveau_dmem_fault_copy_one()

2022-09-28 Thread Alistair Popple
Lyude Paul writes: > On Mon, 2022-09-26 at 16:03 +1000, Alistair Popple wrote: >> nouveau_dmem_fault_copy_one() is used during handling of CPU faults via >> the migrate_to_ram() callback and is used to copy data from GPU to CPU >> memory. It is currently specific to fa

Re: [Nouveau] [PATCH 2/7] mm: Free device private pages have zero refcount

2022-09-26 Thread Alistair Popple
Jason Gunthorpe writes: > On Mon, Sep 26, 2022 at 04:03:06PM +1000, Alistair Popple wrote: >> Since 27674ef6c73f ("mm: remove the extra ZONE_DEVICE struct page >> refcount") device private pages have no longer had an extra reference >> count when the page is in u

Re: [Nouveau] [PATCH 6/7] nouveau/dmem: Evict device private memory during release

2022-09-26 Thread Alistair Popple
Felix Kuehling writes: > On 2022-09-26 17:35, Lyude Paul wrote: >> On Mon, 2022-09-26 at 16:03 +1000, Alistair Popple wrote: >>> When the module is unloaded or a GPU is unbound from the module it is >>> possible for device private pages to be left mapped in curr

Re: [Nouveau] [PATCH 6/7] nouveau/dmem: Evict device private memory during release

2022-09-26 Thread Alistair Popple
John Hubbard writes: > On 9/26/22 14:35, Lyude Paul wrote: >>> + for (i = 0; i < npages; i++) { >>> + if (src_pfns[i] & MIGRATE_PFN_MIGRATE) { >>> + struct page *dpage; >>> + >>> + /* >>> +* _GFP_NOFAIL because the GPU is

[Nouveau] [PATCH 7/7] hmm-tests: Add test for migrate_device_range()

2022-09-26 Thread Alistair Popple
Signed-off-by: Alistair Popple --- lib/test_hmm.c | 119 +- lib/test_hmm_uapi.h| 1 +- tools/testing/selftests/vm/hmm-tests.c | 49 +++- 3 files changed, 148 insertions(+), 21 deletions(-) diff --git a/lib/test_hmm.c

[Nouveau] [PATCH 6/7] nouveau/dmem: Evict device private memory during release

2022-09-26 Thread Alistair Popple
and callbacks have all been freed. Fix this by migrating any mappings back to normal CPU memory prior to freeing the GPU memory chunks and associated device private pages. Signed-off-by: Alistair Popple --- I assume the AMD driver might have a similar issue. However I can't see where device private

[Nouveau] [PATCH 5/7] nouveau/dmem: Refactor nouveau_dmem_fault_copy_one()

2022-09-26 Thread Alistair Popple
. Refactor out the core functionality so that it is not specific to fault handling. Signed-off-by: Alistair Popple --- drivers/gpu/drm/nouveau/nouveau_dmem.c | 59 +-- 1 file changed, 29 insertions(+), 30 deletions(-) diff --git a/drivers/gpu/drm/nouveau/nouveau_dmem.c b

[Nouveau] [PATCH 4/7] mm/migrate_device.c: Add migrate_device_range()

2022-09-26 Thread Alistair Popple
n free up device memory. To allow that this patch introduces the migrate_device family of functions which are functionally similar to migrate_vma but which skips the initial lookup based on mapping. Signed-off-by: Alistair Popple --- include/linux/migrate.h | 7 +++- mm/migrate_device.c

[Nouveau] [PATCH 3/7] mm/migrate_device.c: Refactor migrate_vma and migrate_deivce_coherent_page()

2022-09-26 Thread Alistair Popple
this isn't true for device private memory, and a future change requires similar functionality for device private memory. So refactor the code into something more sensible for migrating device memory without a vma. Signed-off-by: Alistair Popple --- mm/migrate_device.c | 150

[Nouveau] [PATCH 2/7] mm: Free device private pages have zero refcount

2022-09-26 Thread Alistair Popple
functions such as get_page_unless_zero(). Signed-off-by: Alistair Popple --- arch/powerpc/kvm/book3s_hv_uvmem.c | 1 + drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 1 + drivers/gpu/drm/nouveau/nouveau_dmem.c | 1 + lib/test_hmm.c | 1 + mm/memremap.c| 5

[Nouveau] [PATCH 1/7] mm/memory.c: Fix race when faulting a device private page

2022-09-26 Thread Alistair Popple
if it's expected or not. Signed-off-by: Alistair Popple --- arch/powerpc/kvm/book3s_hv_uvmem.c | 15 ++- drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 17 +++-- drivers/gpu/drm/amd/amdkfd/kfd_migrate.h | 2 +- drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 11 +--- include

[Nouveau] [PATCH 0/7] Fix several device private page reference counting issues

2022-09-26 Thread Alistair Popple
. Unfortunately I lack the hardware to test on either of these so would appreciate it if someone with access could test those. Alistair Popple (7): mm/memory.c: Fix race when faulting a device private page mm: Free device private pages have zero refcount mm/migrate_device.c: Refactor

[Nouveau] [PATCH] mm/migrate.c: Remove MIGRATE_PFN_LOCKED

2021-10-25 Thread Alistair Popple
complexity. So clean this up by removing the retry and MIGRATE_PFN_LOCKED flag. Destination pages are also meant to have the MIGRATE_PFN_LOCKED flag set, but nothing actually checks that. Signed-off-by: Alistair Popple --- Documentation/vm/hmm.rst | 2 +- arch/powerpc/kvm

Re: [Nouveau] nouveau: failed to initialise sync

2021-07-06 Thread Alistair Popple
o be send to stable as well. > > Regards, > Christian. > > Am 06.07.21 um 04:44 schrieb Alistair Popple: > > I am also hitting this with upstream. Reverting d02117f8efaa ("drm/ttm: > > remove > > special handling for non GEM drivers") also fixed it fo

Re: [Nouveau] nouveau: failed to initialise sync

2021-07-05 Thread Alistair Popple
I am also hitting this with upstream. Reverting d02117f8efaa ("drm/ttm: remove special handling for non GEM drivers") also fixed it for me. The change log for that commit reads: drm/ttm: remove special handling for non GEM drivers vmwgfx is the only driver actually using this. Move

Re: [Nouveau] [PATCH v11 00/10] Add support for SVM atomics in Nouveau

2021-06-16 Thread Alistair Popple
On Thursday, 17 June 2021 9:35:29 AM AEST Andrew Morton wrote: > On Wed, 16 Jun 2021 20:59:27 +1000 Alistair Popple wrote: > > > This is my series to add support for SVM atomics in Nouveau > > Can we please have a nice [0/n] overview for this patchset? > Sorry

[Nouveau] Update: [PATCH v11 00/10] Add support for SVM atomics in Nouveau

2021-06-16 Thread Alistair Popple
ednesday, 16 June 2021 8:59:27 PM AEST Alistair Popple wrote: Alistair Popple (10): mm: Remove special swap entry functions mm/swapops: Rework swap entry manipulation code mm/rmap: Split try_to_munlock from try_to_unmap mm/rmap: Split migration into its own function mm: Rename migrate_pgm

[Nouveau] [PATCH v11 10/10] nouveau/svm: Implement atomic SVM access

2021-06-16 Thread Alistair Popple
to proceed. Signed-off-by: Alistair Popple Reviewed-by: Ben Skeggs --- v10: * Added a fix from Colin King to check the return code of make_device_exclusive. v9: * Added Ben's Reviewed-By v7: * Removed magic values for fault access levels * Improved readability of fault comparison code v4

[Nouveau] [PATCH v11 09/10] nouveau/svm: Refactor nouveau_range_fault

2021-06-16 Thread Alistair Popple
Call mmu_interval_notifier_insert() as part of nouveau_range_fault(). This doesn't introduce any functional change but makes it easier for a subsequent patch to alter the behaviour of nouveau_range_fault() to support GPU atomic operations. Signed-off-by: Alistair Popple Reviewed-by: Ben Skeggs

[Nouveau] [PATCH v11 08/10] mm: Selftests for exclusive device memory

2021-06-16 Thread Alistair Popple
Adds some selftests for exclusive device memory. Signed-off-by: Alistair Popple Acked-by: Jason Gunthorpe Tested-by: Ralph Campbell Reviewed-by: Ralph Campbell --- v10: * Squashed a fix from Colin King. Not sure what the right attribution tag for that would be though? --- lib/test_hmm.c

[Nouveau] [PATCH v11 07/10] mm: Device exclusive memory access

2021-06-16 Thread Alistair Popple
the PTEs present and to break COW. Signed-off-by: Alistair Popple Reviewed-by: Christoph Hellwig --- v10: * Make device exclusive code conditional on CONFIG_DEVICE_PRIVATE. * Updates to code comments and more minor code cleanups. v9: * Split rename of migrate_pgmap_owner into a separate patch

[Nouveau] [PATCH v11 06/10] mm/memory.c: Allow different return codes for copy_nonpresent_pte()

2021-06-16 Thread Alistair Popple
requires. Instead make copy_nonpresent_pte() return an error code if further processing is required and read the value for the swap entry in the main loop under the ptl. Signed-off-by: Alistair Popple Reviewed-by: Peter Xu --- v11: Rebase on mmots v10: Use a unique error code and only check return

[Nouveau] [PATCH v11 05/10] mm: Rename migrate_pgmap_owner

2021-06-16 Thread Alistair Popple
to 'owner' and create a new notifier initialisation function to initialise this field. Signed-off-by: Alistair Popple Suggested-by: Peter Xu Reviewed-by: Peter Xu --- v9: Previously part of the next patch in the series ('mm: Device exclusive memory access') but now split out as a separate change

[Nouveau] [PATCH v11 04/10] mm/rmap: Split migration into its own function

2021-06-16 Thread Alistair Popple
try_to_migrate() for PageAnon or try_to_unmap(). Signed-off-by: Alistair Popple Reviewed-by: Christoph Hellwig Reviewed-by: Ralph Campbell --- v5: * Added comments about how PMD splitting works for migration vs. unmapping * Tightened up the flag check in try_to_migrate() to be explicit about

[Nouveau] [PATCH v11 02/10] mm/swapops: Rework swap entry manipulation code

2021-06-16 Thread Alistair Popple
-by: Alistair Popple Reviewed-by: Christoph Hellwig Reviewed-by: Jason Gunthorpe Reviewed-by: Ralph Campbell --- include/linux/swapops.h | 56 ++--- mm/debug_vm_pgtable.c | 12 - mm/hmm.c| 2 +- mm/huge_memory.c| 26

[Nouveau] [PATCH v11 03/10] mm/rmap: Split try_to_munlock from try_to_unmap

2021-06-16 Thread Alistair Popple
rather than overload try_to_unmap_one() with unrelated behaviour split this out into it's own function and remove the flag. Signed-off-by: Alistair Popple Reviewed-by: Ralph Campbell Reviewed-by: Christoph Hellwig --- v11: * Rebased on Hugh's series v10: * More comment fixes * Restored the check

[Nouveau] [PATCH v11 01/10] mm: Remove special swap entry functions

2021-06-16 Thread Alistair Popple
pfn_swap_entry_to_page(). Also open-code the various entry_to_pfn() functions as this results is shorter code that is easier to understand. Signed-off-by: Alistair Popple Reviewed-by: Ralph Campbell Reviewed-by: Christoph Hellwig --- v11: * Rebased on mmotm v9: * Rebased on v5.13-rc2 v8

[Nouveau] [PATCH v11 00/10] Add support for SVM atomics in Nouveau

2021-06-16 Thread Alistair Popple
66167-1-colin.k...@canonical.com/). Not sure what the best way of attributing that is though given it was against next. [PATCH 09/10] nouveau/svm: Refactor nouveau_range_fault - No changes. [PATCH 10/10] nouveau/svm: Implement atomic SVM access - No changes. Alistair Popple (10): mm: R

Re: [Nouveau] [PATCH v10 07/10] mm: Device exclusive memory access

2021-06-15 Thread Alistair Popple
On Wednesday, 16 June 2021 2:25:09 AM AEST Peter Xu wrote: > On Tue, Jun 15, 2021 at 01:08:11PM +1000, Alistair Popple wrote: > > On Saturday, 12 June 2021 1:01:42 AM AEST Peter Xu wrote: > > > On Fri, Jun 11, 2021 at 01:43:20PM +1000, Alistair Popple wrote: [...] > &g

Re: [Nouveau] [PATCH v10 07/10] mm: Device exclusive memory access

2021-06-14 Thread Alistair Popple
On Saturday, 12 June 2021 1:01:42 AM AEST Peter Xu wrote: > On Fri, Jun 11, 2021 at 01:43:20PM +1000, Alistair Popple wrote: > > On Friday, 11 June 2021 11:00:34 AM AEST Peter Xu wrote: > > > On Fri, Jun 11, 2021 at 09:17:14AM +1000, Alistair Popple wrote: > > > > O

Re: [Nouveau] [PATCH v10 07/10] mm: Device exclusive memory access

2021-06-10 Thread Alistair Popple
On Friday, 11 June 2021 11:00:34 AM AEST Peter Xu wrote: > On Fri, Jun 11, 2021 at 09:17:14AM +1000, Alistair Popple wrote: > > On Friday, 11 June 2021 9:04:19 AM AEST Peter Xu wrote: > > > On Fri, Jun 11, 2021 at 12:21:26AM +1000, Alistair Popple wrote: > > > &g

Re: [Nouveau] [PATCH v10 07/10] mm: Device exclusive memory access

2021-06-10 Thread Alistair Popple
On Friday, 11 June 2021 9:04:19 AM AEST Peter Xu wrote: > External email: Use caution opening links or attachments > > > On Fri, Jun 11, 2021 at 12:21:26AM +1000, Alistair Popple wrote: > > > Hmm, the thing is.. to me FOLL_SPLIT_PMD should have similar effect to >

Re: [Nouveau] [PATCH v10 07/10] mm: Device exclusive memory access

2021-06-10 Thread Alistair Popple
On Friday, 11 June 2021 4:04:35 AM AEST Peter Xu wrote: > External email: Use caution opening links or attachments > > > On Thu, Jun 10, 2021 at 10:18:25AM +1000, Alistair Popple wrote: > > > > The main problem is split_huge_pmd_address() unconditionally calls a mmu >

Re: [Nouveau] [PATCH v10 07/10] mm: Device exclusive memory access

2021-06-09 Thread Alistair Popple
On Thursday, 10 June 2021 2:05:06 AM AEST Peter Xu wrote: > On Wed, Jun 09, 2021 at 07:38:04PM +1000, Alistair Popple wrote: > > On Wednesday, 9 June 2021 4:33:52 AM AEST Peter Xu wrote: > > > On Mon, Jun 07, 2021 at 05:58:52PM +1000, Alistair Popple wrote: [...] > > For

Re: [Nouveau] [PATCH v10 07/10] mm: Device exclusive memory access

2021-06-09 Thread Alistair Popple
On Wednesday, 9 June 2021 4:33:52 AM AEST Peter Xu wrote: > On Mon, Jun 07, 2021 at 05:58:52PM +1000, Alistair Popple wrote: > > [...] > > > +static bool page_make_device_exclusive_one(struct page *page, > > + struct vm_area_struct *vma, unsigned

[Nouveau] [PATCH v10 10/10] nouveau/svm: Implement atomic SVM access

2021-06-07 Thread Alistair Popple
to proceed. Signed-off-by: Alistair Popple Reviewed-by: Ben Skeggs --- v10: * Added a fix from Colin King to check the return code of make_device_exclusive. v9: * Added Ben's Reviewed-By v7: * Removed magic values for fault access levels * Improved readability of fault comparison code v4

[Nouveau] [PATCH v10 09/10] nouveau/svm: Refactor nouveau_range_fault

2021-06-07 Thread Alistair Popple
Call mmu_interval_notifier_insert() as part of nouveau_range_fault(). This doesn't introduce any functional change but makes it easier for a subsequent patch to alter the behaviour of nouveau_range_fault() to support GPU atomic operations. Signed-off-by: Alistair Popple Reviewed-by: Ben Skeggs

[Nouveau] [PATCH v10 08/10] mm: Selftests for exclusive device memory

2021-06-07 Thread Alistair Popple
Adds some selftests for exclusive device memory. Signed-off-by: Alistair Popple Acked-by: Jason Gunthorpe Tested-by: Ralph Campbell Reviewed-by: Ralph Campbell --- lib/test_hmm.c | 124 +++ lib/test_hmm_uapi.h| 2 + tools/testing

[Nouveau] [PATCH v10 07/10] mm: Device exclusive memory access

2021-06-07 Thread Alistair Popple
the PTEs present and to break COW. Signed-off-by: Alistair Popple Reviewed-by: Christoph Hellwig --- v10: * Make device exclusive code conditional on CONFIG_DEVICE_PRIVATE. * Updates to code comments and more minor code cleanups. v9: * Split rename of migrate_pgmap_owner into a separate patch

[Nouveau] [PATCH v10 06/10] mm/memory.c: Allow different return codes for copy_nonpresent_pte()

2021-06-07 Thread Alistair Popple
requires. Instead make copy_nonpresent_pte() return an error code if further processing is required and read the value for the swap entry in the main loop under the ptl. Signed-off-by: Alistair Popple --- v10: Use a unique error code and only check return codes for handling. v9: New for v9 to allow

[Nouveau] [PATCH v10 05/10] mm: Rename migrate_pgmap_owner

2021-06-07 Thread Alistair Popple
to 'owner' and create a new notifier initialisation function to initialise this field. Signed-off-by: Alistair Popple Suggested-by: Peter Xu --- v9: Previously part of the next patch in the series ('mm: Device exclusive memory access') but now split out as a separate change as suggested by Peter Xu

[Nouveau] [PATCH v10 04/10] mm/rmap: Split migration into its own function

2021-06-07 Thread Alistair Popple
try_to_migrate() for PageAnon or try_to_unmap(). Signed-off-by: Alistair Popple Reviewed-by: Christoph Hellwig Reviewed-by: Ralph Campbell --- v5: * Added comments about how PMD splitting works for migration vs. unmapping * Tightened up the flag check in try_to_migrate() to be explicit about

[Nouveau] [PATCH v10 03/10] mm/rmap: Split try_to_munlock from try_to_unmap

2021-06-07 Thread Alistair Popple
rather than overload try_to_unmap_one() with unrelated behaviour split this out into it's own function and remove the flag. Signed-off-by: Alistair Popple Reviewed-by: Ralph Campbell Reviewed-by: Christoph Hellwig --- v10: * More comment fixes * Restored the check of VM_LOCKED under that ptl

[Nouveau] [PATCH v10 02/10] mm/swapops: Rework swap entry manipulation code

2021-06-07 Thread Alistair Popple
-by: Alistair Popple Reviewed-by: Christoph Hellwig Reviewed-by: Jason Gunthorpe Reviewed-by: Ralph Campbell --- include/linux/swapops.h | 56 ++--- mm/debug_vm_pgtable.c | 12 - mm/hmm.c| 2 +- mm/huge_memory.c| 26

[Nouveau] [PATCH v10 01/10] mm: Remove special swap entry functions

2021-06-07 Thread Alistair Popple
pfn_swap_entry_to_page(). Also open-code the various entry_to_pfn() functions as this results is shorter code that is easier to understand. Signed-off-by: Alistair Popple Reviewed-by: Ralph Campbell Reviewed-by: Christoph Hellwig --- v9: * Rebased on v5.13-rc2 v8: * No changes v7: * Reworded commit

[Nouveau] [PATCH v10 00/10] Add support for SVM atomics in Nouveau

2021-06-07 Thread Alistair Popple
Further testing has been performed by adding support for testing exclusive access to the hmm-tests kselftests. Alistair Popple (10): mm: Remove special swap entry functions mm/swapops: Rework swap entry manipulation code mm/rmap: Split try_to_munlock from try_to_unmap mm/rmap: Split m

Re: [Nouveau] [PATCH v9 03/10] mm/rmap: Split try_to_munlock from try_to_unmap

2021-06-06 Thread Alistair Popple
On Saturday, 5 June 2021 10:41:03 AM AEST Shakeel Butt wrote: > External email: Use caution opening links or attachments > > > On Fri, Jun 4, 2021 at 1:49 PM Liam Howlett wrote: > > > > * Shakeel Butt [210525 19:45]: > > > On Tue, May 25, 2021 at 11:40 AM Liam Howlett wrote: > > > > > > >

Re: [Nouveau] [PATCH v9 07/10] mm: Device exclusive memory access

2021-06-03 Thread Alistair Popple
On Friday, 4 June 2021 12:47:40 AM AEST Peter Xu wrote: > External email: Use caution opening links or attachments > > On Thu, Jun 03, 2021 at 09:39:32PM +1000, Alistair Popple wrote: > > Reclaim won't run on the page due to the extra references from the special > > swap entr

Re: [Nouveau] [PATCH v9 07/10] mm: Device exclusive memory access

2021-06-03 Thread Alistair Popple
On Thursday, 3 June 2021 12:37:30 AM AEST Peter Xu wrote: > External email: Use caution opening links or attachments > > On Wed, Jun 02, 2021 at 06:50:37PM +1000, Balbir Singh wrote: > > On Wed, May 26, 2021 at 12:17:18AM -0700, John Hubbard wrote: > > > On 5/25/21 4:51 AM, Balbir Singh wrote: >

Re: [Nouveau] [PATCH v9 07/10] mm: Device exclusive memory access

2021-05-27 Thread Alistair Popple
On Thursday, 27 May 2021 11:04:57 PM AEST Peter Xu wrote: > On Thu, May 27, 2021 at 01:35:39PM +1000, Alistair Popple wrote: > > > > + * > > > > + * @MMU_NOTIFY_EXCLUSIVE: to signal a device driver that the device > > > > will > > > > no + * l

Re: [Nouveau] [PATCH v9 07/10] mm: Device exclusive memory access

2021-05-26 Thread Alistair Popple
On Thursday, 27 May 2021 5:28:32 AM AEST Peter Xu wrote: > On Mon, May 24, 2021 at 11:27:22PM +1000, Alistair Popple wrote: > > Some devices require exclusive write access to shared virtual > > memory (SVM) ranges to perform atomic operations on that memory. This > > req

Re: [Nouveau] [PATCH v9 06/10] mm/memory.c: Allow different return codes for copy_nonpresent_pte()

2021-05-26 Thread Alistair Popple
On Thursday, 27 May 2021 5:50:05 AM AEST Peter Xu wrote: > On Mon, May 24, 2021 at 11:27:21PM +1000, Alistair Popple wrote: > > Currently if copy_nonpresent_pte() returns a non-zero value it is > > assumed to be a swap entry which requires further processing outside the > > l

Re: [Nouveau] [PATCH][next] nouveau/svm: Fix missing failure check on call to make_device_exclusive_range

2021-05-26 Thread Alistair Popple
On Thursday, 27 May 2021 12:04:59 AM AEST Colin King wrote: > The call to make_device_exclusive_range can potentially fail leaving > pointer page not initialized that leads to an uninitialized pointer > read issue. Fix this by adding a check to see if the call failed and > returning the error

Re: [Nouveau] [PATCH v9 07/10] mm: Device exclusive memory access

2021-05-26 Thread Alistair Popple
On Wednesday, 26 May 2021 5:17:18 PM AEST John Hubbard wrote: > On 5/25/21 4:51 AM, Balbir Singh wrote: > ... > > >> How beneficial is this code to nouveau users? I see that it permits a > >> part of OpenCL to be implemented, but how useful/important is this in > >> the real world? > > > > That

Re: [Nouveau] [PATCH v9 07/10] mm: Device exclusive memory access

2021-05-25 Thread Alistair Popple
On Tuesday, 25 May 2021 11:31:17 AM AEST John Hubbard wrote: > On 5/24/21 3:11 PM, Andrew Morton wrote: > >> ... > >> > >> Documentation/vm/hmm.rst | 17 > >> include/linux/mmu_notifier.h | 6 ++ > >> include/linux/rmap.h | 4 + > >> include/linux/swap.h | 7

[Nouveau] [PATCH v9 10/10] nouveau/svm: Implement atomic SVM access

2021-05-24 Thread Alistair Popple
to proceed. Signed-off-by: Alistair Popple Reviewed-by: Ben Skeggs --- v9: * Added Ben's Reviewed-By v7: * Removed magic values for fault access levels * Improved readability of fault comparison code v4: * Check that page table entries haven't changed before mapping on the device

[Nouveau] [PATCH v9 09/10] nouveau/svm: Refactor nouveau_range_fault

2021-05-24 Thread Alistair Popple
Call mmu_interval_notifier_insert() as part of nouveau_range_fault(). This doesn't introduce any functional change but makes it easier for a subsequent patch to alter the behaviour of nouveau_range_fault() to support GPU atomic operations. Signed-off-by: Alistair Popple Reviewed-by: Ben Skeggs

[Nouveau] [PATCH v9 07/10] mm: Device exclusive memory access

2021-05-24 Thread Alistair Popple
the PTEs present and to break COW. Signed-off-by: Alistair Popple Reviewed-by: Christoph Hellwig --- v9: * Split rename of migrate_pgmap_owner into a separate patch. * Added comments explaining SWP_DEVICE_EXCLUSIVE_* entries. * Renamed try_to_protect{_one} to page_make_device_exclusive{_one} based

[Nouveau] [PATCH v9 08/10] mm: Selftests for exclusive device memory

2021-05-24 Thread Alistair Popple
Adds some selftests for exclusive device memory. Signed-off-by: Alistair Popple Acked-by: Jason Gunthorpe Tested-by: Ralph Campbell Reviewed-by: Ralph Campbell --- lib/test_hmm.c | 124 +++ lib/test_hmm_uapi.h| 2 + tools/testing

[Nouveau] [PATCH v9 04/10] mm/rmap: Split migration into its own function

2021-05-24 Thread Alistair Popple
try_to_migrate() for PageAnon or try_to_unmap(). Signed-off-by: Alistair Popple Reviewed-by: Christoph Hellwig Reviewed-by: Ralph Campbell --- v5: * Added comments about how PMD splitting works for migration vs. unmapping * Tightened up the flag check in try_to_migrate() to be explicit about

[Nouveau] [PATCH v9 06/10] mm/memory.c: Allow different return codes for copy_nonpresent_pte()

2021-05-24 Thread Alistair Popple
requires. Instead make copy_nonpresent_pte() return an error code if further processing is required and read the value for the swap entry in the main loop under the ptl. Signed-off-by: Alistair Popple --- v9: New for v9 to allow device exclusive handling to occur in copy_nonpresent_pte(). --- mm

[Nouveau] [PATCH v9 05/10] mm: Rename migrate_pgmap_owner

2021-05-24 Thread Alistair Popple
to 'owner' and create a new notifier initialisation function to initialise this field. Signed-off-by: Alistair Popple Suggested-by: Peter Xu --- v9: Previously part of the next patch in the series ('mm: Device exclusive memory access') but now split out as a separate change as suggested by Peter Xu

[Nouveau] [PATCH v9 03/10] mm/rmap: Split try_to_munlock from try_to_unmap

2021-05-24 Thread Alistair Popple
rather than overload try_to_unmap_one() with unrelated behaviour split this out into it's own function and remove the flag. Signed-off-by: Alistair Popple Reviewed-by: Ralph Campbell Reviewed-by: Christoph Hellwig --- v9: * Improved comments v8: * Renamed try_to_munlock to page_mlock to better

[Nouveau] [PATCH v9 02/10] mm/swapops: Rework swap entry manipulation code

2021-05-24 Thread Alistair Popple
-by: Alistair Popple Reviewed-by: Christoph Hellwig Reviewed-by: Jason Gunthorpe Reviewed-by: Ralph Campbell --- include/linux/swapops.h | 56 ++--- mm/debug_vm_pgtable.c | 12 - mm/hmm.c| 2 +- mm/huge_memory.c| 26

[Nouveau] [PATCH v9 01/10] mm: Remove special swap entry functions

2021-05-24 Thread Alistair Popple
pfn_swap_entry_to_page(). Also open-code the various entry_to_pfn() functions as this results is shorter code that is easier to understand. Signed-off-by: Alistair Popple Reviewed-by: Ralph Campbell Reviewed-by: Christoph Hellwig --- v9: * Rebased on v5.13-rc2 v8: * No changes v7: * Reworded commit

[Nouveau] [PATCH v9 00/10] Add support for SVM atomics in Nouveau

2021-05-24 Thread Alistair Popple
erformed by adding support for testing exclusive access to the hmm-tests kselftests. Alistair Popple (10): mm: Remove special swap entry functions mm/swapops: Rework swap entry manipulation code mm/rmap: Split try_to_munlock from try_to_unmap mm/rmap: Split migration into its own function mm

Re: [Nouveau] [PATCH v8 5/8] mm: Device exclusive memory access

2021-05-21 Thread Alistair Popple
On Tuesday, 18 May 2021 11:19:05 PM AEST Alistair Popple wrote: [...] > > > +/* > > > + * Restore a potential device exclusive pte to a working pte entry > > > + */ > > > +static vm_fault_t remove_device_exclusive_entry(struct vm_fault *vmf) > > >

Re: [Nouveau] [PATCH v8 3/8] mm/rmap: Split try_to_munlock from try_to_unmap

2021-05-20 Thread Alistair Popple
On Friday, 21 May 2021 6:24:27 AM AEST Liam Howlett wrote: [...] > > > > diff --git a/mm/rmap.c b/mm/rmap.c > > > > index 977e70803ed8..f09d522725b9 100644 > > > > --- a/mm/rmap.c > > > > +++ b/mm/rmap.c > > > > @@ -1405,10 +1405,6 @@ static bool try_to_unmap_one(struct page *page, > > > >

Re: [Nouveau] [PATCH v8 5/8] mm: Device exclusive memory access

2021-05-19 Thread Alistair Popple
On Wednesday, 19 May 2021 10:15:41 PM AEST Peter Xu wrote: > External email: Use caution opening links or attachments > > On Wed, May 19, 2021 at 09:04:53PM +1000, Alistair Popple wrote: > > Failing fork() because we couldn't take a lock doesn't seem like the right > > approa

Re: [Nouveau] [PATCH v8 5/8] mm: Device exclusive memory access

2021-05-19 Thread Alistair Popple
On Wednesday, 19 May 2021 10:21:08 PM AEST Peter Xu wrote: > External email: Use caution opening links or attachments > > On Wed, May 19, 2021 at 09:35:10PM +1000, Alistair Popple wrote: > > I think the approach you are describing is similar to what > > migrate_vma_collec

Re: [Nouveau] [PATCH v8 5/8] mm: Device exclusive memory access

2021-05-19 Thread Alistair Popple
On Wednesday, 19 May 2021 10:24:27 PM AEST Peter Xu wrote: > External email: Use caution opening links or attachments > > On Wed, May 19, 2021 at 08:49:01PM +1000, Alistair Popple wrote: > > On Wednesday, 19 May 2021 7:16:38 AM AEST Peter Xu wrote: > > > External email: U

Re: [Nouveau] [PATCH v8 3/8] mm/rmap: Split try_to_munlock from try_to_unmap

2021-05-19 Thread Alistair Popple
On Wednesday, 19 May 2021 6:04:51 AM AEST Liam Howlett wrote: > External email: Use caution opening links or attachments > > * Alistair Popple [210407 04:43]: > > The behaviour of try_to_unmap_one() is difficult to follow because it > > performs different operations based

Re: [Nouveau] [PATCH v8 5/8] mm: Device exclusive memory access

2021-05-19 Thread Alistair Popple
On Wednesday, 19 May 2021 3:27:42 AM AEST Peter Xu wrote: > > > The odd part is the remote GUP should have walked the page table > > > already, so since the target here is the vaddr to replace, the 1st page > > > table walk should be able to both trylock/lock the page, then modify > > > the pte

Re: [Nouveau] [PATCH v8 5/8] mm: Device exclusive memory access

2021-05-19 Thread Alistair Popple
On Wednesday, 19 May 2021 9:45:05 AM AEST Peter Xu wrote: > External email: Use caution opening links or attachments > > On Tue, May 18, 2021 at 08:03:27PM -0300, Jason Gunthorpe wrote: > > Logically during fork all these device exclusive pages should be > > reverted back to their CPU pages,

Re: [Nouveau] [PATCH v8 5/8] mm: Device exclusive memory access

2021-05-19 Thread Alistair Popple
On Wednesday, 19 May 2021 7:16:38 AM AEST Peter Xu wrote: > External email: Use caution opening links or attachments > > > On Wed, Apr 07, 2021 at 06:42:35PM +1000, Alistair Popple wrote: > > [...] > > > +static bool try_to_protect(struct page

Re: [Nouveau] [PATCH v8 5/8] mm: Device exclusive memory access

2021-05-18 Thread Alistair Popple
On Tuesday, 18 May 2021 12:08:34 PM AEST Peter Xu wrote: > > v6: > > * Fixed a bisectablity issue due to incorrectly applying the rename of > > > > migrate_pgmap_owner to the wrong patches for Nouveau and hmm_test. > > > > v5: > > * Renamed range->migrate_pgmap_owner to range->owner. > > May

Re: [Nouveau] [PATCH v8 1/8] mm: Remove special swap entry functions

2021-05-18 Thread Alistair Popple
On Tuesday, 18 May 2021 12:17:32 PM AEST Peter Xu wrote: > On Wed, Apr 07, 2021 at 06:42:31PM +1000, Alistair Popple wrote: > > +static inline struct page *pfn_swap_entry_to_page(swp_entry_t entry) > > +{ > > + struct page *p = pfn_to_

Re: [Nouveau] [PATCH v8 0/8] Add support for SVM atomics in Nouveau

2021-05-06 Thread Alistair Popple
at https://ozlabs.org/~apopple/opencl_svm_atomics/ . - Alistair On Wednesday, 7 April 2021 6:42:30 PM AEST Alistair Popple wrote: > This is the eighth version of a series to add support to Nouveau for atomic > memory operations on OpenCL shared virtual memory (SVM) regions. > > The

  1   2   3   >