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 use. However before handing them

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 currently running >>> processes.

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

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

2022-09-26 Thread Felix Kuehling
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 currently running processes. This leads to a kernel crash when the

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

2022-09-26 Thread John Hubbard
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 going away and there >> +

[Nouveau] [PATCH -next] drm/nouveau/disp: fix cast removes address space of expression warnings

2022-09-26 Thread ruanjinjie
When build Linux kernel with 'make C=2', encounter the following warnings: ./drivers/gpu/drm/nouveau/dispnv50/disp.c:134:34: warning: cast removes address space '__iomem' of expression ./drivers/gpu/drm/nouveau/dispnv50/disp.c:197:34: warning: cast removes address space '__iomem' of expression

[Nouveau] [PATCH -next] drm/nouveau/disp: make gv100_disp_core_mthd_base static

2022-09-26 Thread ruanjinjie
The symbol is not used outside of the file, so mark it static. Fixes the following warning: ./drivers/gpu/drm/nouveau/nvkm/engine/disp/gv100.c:591:1: warning: symbol 'gv100_disp_core_mthd_base' was not declared. Should it be static? Signed-off-by: ruanjinjie ---

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

2022-09-26 Thread Lyude Paul
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 currently running > processes. This leads to a kernel crash when the pages are either freed > or accessed from

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

2022-09-26 Thread Lyude Paul
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 fault handling, however a future > patch implementing

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

2022-09-26 Thread Jason Gunthorpe
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 use. However before handing them back to the > owning device

Re: [Nouveau] [PATCH v2 10/33] drm/modes: Add a function to generate analog display modes

2022-09-26 Thread Thomas Zimmermann
Hi Am 26.09.22 um 14:42 schrieb Maxime Ripard: On Mon, Sep 26, 2022 at 01:17:52PM +0200, Thomas Zimmermann wrote: Hi Am 26.09.22 um 12:34 schrieb Geert Uytterhoeven: Hi Maxime, On Mon, Sep 26, 2022 at 12:17 PM Maxime Ripard wrote: On Fri, Sep 23, 2022 at 11:05:48AM +0200, Thomas

Re: [Nouveau] [PATCH v2 09/33] drm/connector: Add TV standard property

2022-09-26 Thread Noralf Trønnes
Den 26.09.2022 12.01, skrev Maxime Ripard: > On Sat, Sep 24, 2022 at 05:52:29PM +0200, Noralf Trønnes wrote: >> Den 22.09.2022 16.25, skrev Maxime Ripard: >>> The TV mode property has been around for a while now to select and get the >>> current TV mode output on an analog TV connector. >>> >>>

Re: [Nouveau] [PATCH v2 10/33] drm/modes: Add a function to generate analog display modes

2022-09-26 Thread Maxime Ripard
On Mon, Sep 26, 2022 at 01:17:52PM +0200, Thomas Zimmermann wrote: > Hi > > Am 26.09.22 um 12:34 schrieb Geert Uytterhoeven: > > Hi Maxime, > > > > On Mon, Sep 26, 2022 at 12:17 PM Maxime Ripard wrote: > > > On Fri, Sep 23, 2022 at 11:05:48AM +0200, Thomas Zimmermann wrote: > > > > > + /*

Re: [Nouveau] [PATCH v2 06/33] drm/connector: Rename legacy TV property

2022-09-26 Thread Thomas Zimmermann
Hi Am 26.09.22 um 11:50 schrieb Maxime Ripard: Hi Thomas, On Fri, Sep 23, 2022 at 10:19:08AM +0200, Thomas Zimmermann wrote: Hi Am 22.09.22 um 16:25 schrieb Maxime Ripard: The current tv_mode has driver-specific values that don't allow to easily share code using it, either at the userspace

Re: [Nouveau] [PATCH v2 02/33] drm/tests: Add Kunit Helpers

2022-09-26 Thread Noralf Trønnes
Den 26.09.2022 11.36, skrev Maxime Ripard: > Hi Noralf, > > On Sat, Sep 24, 2022 at 08:06:17PM +0200, Noralf Trønnes wrote: >> Den 24.09.2022 19.56, skrev Noralf Trønnes: >>> >>> >>> Den 22.09.2022 16.25, skrev Maxime Ripard: As the number of kunit tests in KMS grows further, we start to

Re: [Nouveau] [PATCH v2 10/33] drm/modes: Add a function to generate analog display modes

2022-09-26 Thread Thomas Zimmermann
Hi Am 26.09.22 um 12:34 schrieb Geert Uytterhoeven: Hi Maxime, On Mon, Sep 26, 2022 at 12:17 PM Maxime Ripard wrote: On Fri, Sep 23, 2022 at 11:05:48AM +0200, Thomas Zimmermann wrote: + /* 63.556us * 13.5MHz = 858 pixels */ I kind of get what the comment wants to tell me, but the units

Re: [Nouveau] [PATCH v2 10/33] drm/modes: Add a function to generate analog display modes

2022-09-26 Thread Thomas Zimmermann
Hi Am 26.09.22 um 12:18 schrieb Maxime Ripard: On Fri, Sep 23, 2022 at 12:16:13PM +0200, Thomas Zimmermann wrote: Hi Am 23.09.22 um 11:18 schrieb Jani Nikula: On Fri, 23 Sep 2022, Thomas Zimmermann wrote: Am 22.09.22 um 16:25 schrieb Maxime Ripard: + drm_dbg_kms(dev, +

Re: [Nouveau] [PATCH v2 10/33] drm/modes: Add a function to generate analog display modes

2022-09-26 Thread Geert Uytterhoeven
Hi Maxime, On Mon, Sep 26, 2022 at 12:17 PM Maxime Ripard wrote: > On Fri, Sep 23, 2022 at 11:05:48AM +0200, Thomas Zimmermann wrote: > > > + /* 63.556us * 13.5MHz = 858 pixels */ > > > > I kind of get what the comment wants to tell me, but the units don't add up. > > I'm not sure how it

Re: [Nouveau] [PATCH v2 10/33] drm/modes: Add a function to generate analog display modes

2022-09-26 Thread Maxime Ripard
On Fri, Sep 23, 2022 at 12:16:13PM +0200, Thomas Zimmermann wrote: > Hi > > Am 23.09.22 um 11:18 schrieb Jani Nikula: > > On Fri, 23 Sep 2022, Thomas Zimmermann wrote: > > > Am 22.09.22 um 16:25 schrieb Maxime Ripard: > > > > + drm_dbg_kms(dev, > > > > + "Generating a

Re: [Nouveau] [PATCH v2 10/33] drm/modes: Add a function to generate analog display modes

2022-09-26 Thread Maxime Ripard
Hi, On Fri, Sep 23, 2022 at 11:05:48AM +0200, Thomas Zimmermann wrote: > > + /* 63.556us * 13.5MHz = 858 pixels */ > > I kind of get what the comment wants to tell me, but the units don't add up. I'm not sure how it doesn't add up? We have a frequency in Hz (equivalent to s^-1) and a

Re: [Nouveau] [PATCH v2 09/33] drm/connector: Add TV standard property

2022-09-26 Thread Maxime Ripard
On Sat, Sep 24, 2022 at 05:52:29PM +0200, Noralf Trønnes wrote: > Den 22.09.2022 16.25, skrev Maxime Ripard: > > The TV mode property has been around for a while now to select and get the > > current TV mode output on an analog TV connector. > > > > Despite that property name being generic, its

Re: [Nouveau] [PATCH v2 06/33] drm/connector: Rename legacy TV property

2022-09-26 Thread Maxime Ripard
Hi Thomas, On Fri, Sep 23, 2022 at 10:19:08AM +0200, Thomas Zimmermann wrote: > Hi > > Am 22.09.22 um 16:25 schrieb Maxime Ripard: > > The current tv_mode has driver-specific values that don't allow to > > easily share code using it, either at the userspace or kernel level. > > > > Since we're

Re: [Nouveau] [PATCH v2 02/33] drm/tests: Add Kunit Helpers

2022-09-26 Thread Maxime Ripard
Hi Noralf, On Sat, Sep 24, 2022 at 08:06:17PM +0200, Noralf Trønnes wrote: > Den 24.09.2022 19.56, skrev Noralf Trønnes: > > > > > > Den 22.09.2022 16.25, skrev Maxime Ripard: > >> As the number of kunit tests in KMS grows further, we start to have > >> multiple test suites that, for example,

[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
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 currently running processes. This leads to a kernel crash when the pages are either freed or accessed from the CPU because the GPU and associated data structures and

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

2022-09-26 Thread Alistair Popple
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 fault handling, however a future patch implementing eviction of data during teardown needs similar functionality.

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

2022-09-26 Thread Alistair Popple
Device drivers can use the migrate_vma family of functions to migrate existing private anonymous mappings to device private pages. These pages are backed by memory on the device with drivers being responsible for copying data to and from device memory. Device private pages are freed via the

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

2022-09-26 Thread Alistair Popple
migrate_device_coherent_page() reuses the existing migrate_vma family of functions to migrate a specific page without providing a valid mapping or vma. This looks a bit odd because it means we are calling migrate_vma_*() without setting a valid vma, however it was considered acceptable at the time

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

2022-09-26 Thread Alistair Popple
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 use. However before handing them back to the owning device driver we add an extra reference count such that free pages have a reference

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

2022-09-26 Thread Alistair Popple
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 migration of the device private page can free the page and possibly the underlying pgmap.

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

2022-09-26 Thread Alistair Popple
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 from accessing a struct page which no longer exists because it has been removed or accessing fields within the struct page