Faith Ekstrand
2024-May-09 20:53 UTC
[PATCH v4] drm/nouveau: use tile_mode and pte_kind for VM_BIND bo allocations
On Thu, May 9, 2024 at 3:44?PM Mohamed Ahmed < mohamedahmedegypt2001 at gmail.com> wrote:> Allows PTE kind and tile mode on BO create with VM_BIND, > and adds a GETPARAM to indicate this change. This is needed to support > modifiers in NVK and ensure correctness when dealing with the nouveau > GL driver. > > The userspace modifiers implementation this is for can be found here: > https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24795 > > Fixes: b88baab82871 ("drm/nouveau: implement new VM_BIND uAPI") > Signed-off-by: Mohamed Ahmed <mohamedahmedegypt2001 at gmail.com> >Reviewed-by: Faith Ekstrand <faith.ekstrand at collabora.com>> --- > drivers/gpu/drm/nouveau/nouveau_abi16.c | 3 ++ > drivers/gpu/drm/nouveau/nouveau_bo.c | 44 +++++++++++-------------- > include/uapi/drm/nouveau_drm.h | 7 ++++ > 3 files changed, 29 insertions(+), 25 deletions(-) > > diff --git a/drivers/gpu/drm/nouveau/nouveau_abi16.c > b/drivers/gpu/drm/nouveau/nouveau_abi16.c > index 80f74ee0f..47e53e17b 100644 > --- a/drivers/gpu/drm/nouveau/nouveau_abi16.c > +++ b/drivers/gpu/drm/nouveau/nouveau_abi16.c > @@ -272,6 +272,9 @@ nouveau_abi16_ioctl_getparam(ABI16_IOCTL_ARGS) > getparam->value > (u64)ttm_resource_manager_usage(vram_mgr); > break; > } > + case NOUVEAU_GETPARAM_HAS_VMA_TILEMODE: > + getparam->value = 1; > + break; > default: > NV_PRINTK(dbg, cli, "unknown parameter %lld\n", > getparam->param); > return -EINVAL; > diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c > b/drivers/gpu/drm/nouveau/nouveau_bo.c > index db8cbf615..186add400 100644 > --- a/drivers/gpu/drm/nouveau/nouveau_bo.c > +++ b/drivers/gpu/drm/nouveau/nouveau_bo.c > @@ -241,28 +241,28 @@ nouveau_bo_alloc(struct nouveau_cli *cli, u64 *size, > int *align, u32 domain, > } > > nvbo->contig = !(tile_flags & NOUVEAU_GEM_TILE_NONCONTIG); > - if (!nouveau_cli_uvmm(cli) || internal) { > - /* for BO noVM allocs, don't assign kinds */ > - if (cli->device.info.family >= NV_DEVICE_INFO_V0_FERMI) { > - nvbo->kind = (tile_flags & 0x0000ff00) >> 8; > - if (!nvif_mmu_kind_valid(mmu, nvbo->kind)) { > - kfree(nvbo); > - return ERR_PTR(-EINVAL); > - } > > - nvbo->comp = mmu->kind[nvbo->kind] != nvbo->kind; > - } else if (cli->device.info.family >> NV_DEVICE_INFO_V0_TESLA) { > - nvbo->kind = (tile_flags & 0x00007f00) >> 8; > - nvbo->comp = (tile_flags & 0x00030000) >> 16; > - if (!nvif_mmu_kind_valid(mmu, nvbo->kind)) { > - kfree(nvbo); > - return ERR_PTR(-EINVAL); > - } > - } else { > - nvbo->zeta = (tile_flags & 0x00000007); > + if (cli->device.info.family >= NV_DEVICE_INFO_V0_FERMI) { > + nvbo->kind = (tile_flags & 0x0000ff00) >> 8; > + if (!nvif_mmu_kind_valid(mmu, nvbo->kind)) { > + kfree(nvbo); > + return ERR_PTR(-EINVAL); > + } > + > + nvbo->comp = mmu->kind[nvbo->kind] != nvbo->kind; > + } else if (cli->device.info.family >= NV_DEVICE_INFO_V0_TESLA) { > + nvbo->kind = (tile_flags & 0x00007f00) >> 8; > + nvbo->comp = (tile_flags & 0x00030000) >> 16; > + if (!nvif_mmu_kind_valid(mmu, nvbo->kind)) { > + kfree(nvbo); > + return ERR_PTR(-EINVAL); > } > - nvbo->mode = tile_mode; > + } else { > + nvbo->zeta = (tile_flags & 0x00000007); > + } > + nvbo->mode = tile_mode; > > + if (!nouveau_cli_uvmm(cli) || internal) { > /* Determine the desirable target GPU page size for the > buffer. */ > for (i = 0; i < vmm->page_nr; i++) { > /* Because we cannot currently allow VMM maps to > fail > @@ -304,12 +304,6 @@ nouveau_bo_alloc(struct nouveau_cli *cli, u64 *size, > int *align, u32 domain, > } > nvbo->page = vmm->page[pi].shift; > } else { > - /* reject other tile flags when in VM mode. */ > - if (tile_mode) > - return ERR_PTR(-EINVAL); > - if (tile_flags & ~NOUVEAU_GEM_TILE_NONCONTIG) > - return ERR_PTR(-EINVAL); > - > /* Determine the desirable target GPU page size for the > buffer. */ > for (i = 0; i < vmm->page_nr; i++) { > /* Because we cannot currently allow VMM maps to > fail > diff --git a/include/uapi/drm/nouveau_drm.h > b/include/uapi/drm/nouveau_drm.h > index cd84227f1..5402f77ee 100644 > --- a/include/uapi/drm/nouveau_drm.h > +++ b/include/uapi/drm/nouveau_drm.h > @@ -68,6 +68,13 @@ extern "C" { > */ > #define NOUVEAU_GETPARAM_VRAM_USED 19 > > +/* > + * NOUVEAU_GETPARAM_HAS_VMA_TILEMODE > + * > + * Query whether tile mode and PTE kind are accepted with VM allocs or > not. > + */ > +#define NOUVEAU_GETPARAM_HAS_VMA_TILEMODE 20 > + > struct drm_nouveau_getparam { > __u64 param; > __u64 value; > -- > 2.44.0 > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <https://lists.freedesktop.org/archives/nouveau/attachments/20240509/5fdd35ca/attachment.htm>
Danilo Krummrich
2024-May-13 20:28 UTC
[PATCH v4] drm/nouveau: use tile_mode and pte_kind for VM_BIND bo allocations
Hi Mohamed, Thank you for fixing this up! On 5/9/24 22:43, Mohamed Ahmed wrote:> Allows PTE kind and tile mode on BO create with VM_BIND, > and adds a GETPARAM to indicate this change. This is needed to supportIt's usually better to use imperative verb form for commit messages. No need to send a new version though.> modifiers in NVK and ensure correctness when dealing with the nouveau > GL driver. > > The userspace modifiers implementation this is for can be found here: > https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24795 > > Fixes: b88baab82871 ("drm/nouveau: implement new VM_BIND uAPI") > Signed-off-by: Mohamed Ahmed <mohamedahmedegypt2001 at gmail.com>Applied to drm-misc-next-fixes. Generally, please make sure to use scripts/get_maintainer.pl before sending patches. - Danilo> --- > drivers/gpu/drm/nouveau/nouveau_abi16.c | 3 ++ > drivers/gpu/drm/nouveau/nouveau_bo.c | 44 +++++++++++-------------- > include/uapi/drm/nouveau_drm.h | 7 ++++ > 3 files changed, 29 insertions(+), 25 deletions(-) > > diff --git a/drivers/gpu/drm/nouveau/nouveau_abi16.c b/drivers/gpu/drm/nouveau/nouveau_abi16.c > index 80f74ee0f..47e53e17b 100644 > --- a/drivers/gpu/drm/nouveau/nouveau_abi16.c > +++ b/drivers/gpu/drm/nouveau/nouveau_abi16.c > @@ -272,6 +272,9 @@ nouveau_abi16_ioctl_getparam(ABI16_IOCTL_ARGS) > getparam->value = (u64)ttm_resource_manager_usage(vram_mgr); > break; > } > + case NOUVEAU_GETPARAM_HAS_VMA_TILEMODE: > + getparam->value = 1; > + break; > default: > NV_PRINTK(dbg, cli, "unknown parameter %lld\n", getparam->param); > return -EINVAL; > diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c b/drivers/gpu/drm/nouveau/nouveau_bo.c > index db8cbf615..186add400 100644 > --- a/drivers/gpu/drm/nouveau/nouveau_bo.c > +++ b/drivers/gpu/drm/nouveau/nouveau_bo.c > @@ -241,28 +241,28 @@ nouveau_bo_alloc(struct nouveau_cli *cli, u64 *size, int *align, u32 domain, > } > > nvbo->contig = !(tile_flags & NOUVEAU_GEM_TILE_NONCONTIG); > - if (!nouveau_cli_uvmm(cli) || internal) { > - /* for BO noVM allocs, don't assign kinds */ > - if (cli->device.info.family >= NV_DEVICE_INFO_V0_FERMI) { > - nvbo->kind = (tile_flags & 0x0000ff00) >> 8; > - if (!nvif_mmu_kind_valid(mmu, nvbo->kind)) { > - kfree(nvbo); > - return ERR_PTR(-EINVAL); > - } > > - nvbo->comp = mmu->kind[nvbo->kind] != nvbo->kind; > - } else if (cli->device.info.family >= NV_DEVICE_INFO_V0_TESLA) { > - nvbo->kind = (tile_flags & 0x00007f00) >> 8; > - nvbo->comp = (tile_flags & 0x00030000) >> 16; > - if (!nvif_mmu_kind_valid(mmu, nvbo->kind)) { > - kfree(nvbo); > - return ERR_PTR(-EINVAL); > - } > - } else { > - nvbo->zeta = (tile_flags & 0x00000007); > + if (cli->device.info.family >= NV_DEVICE_INFO_V0_FERMI) { > + nvbo->kind = (tile_flags & 0x0000ff00) >> 8; > + if (!nvif_mmu_kind_valid(mmu, nvbo->kind)) { > + kfree(nvbo); > + return ERR_PTR(-EINVAL); > + } > + > + nvbo->comp = mmu->kind[nvbo->kind] != nvbo->kind; > + } else if (cli->device.info.family >= NV_DEVICE_INFO_V0_TESLA) { > + nvbo->kind = (tile_flags & 0x00007f00) >> 8; > + nvbo->comp = (tile_flags & 0x00030000) >> 16; > + if (!nvif_mmu_kind_valid(mmu, nvbo->kind)) { > + kfree(nvbo); > + return ERR_PTR(-EINVAL); > } > - nvbo->mode = tile_mode; > + } else { > + nvbo->zeta = (tile_flags & 0x00000007); > + } > + nvbo->mode = tile_mode; > > + if (!nouveau_cli_uvmm(cli) || internal) { > /* Determine the desirable target GPU page size for the buffer. */ > for (i = 0; i < vmm->page_nr; i++) { > /* Because we cannot currently allow VMM maps to fail > @@ -304,12 +304,6 @@ nouveau_bo_alloc(struct nouveau_cli *cli, u64 *size, int *align, u32 domain, > } > nvbo->page = vmm->page[pi].shift; > } else { > - /* reject other tile flags when in VM mode. */ > - if (tile_mode) > - return ERR_PTR(-EINVAL); > - if (tile_flags & ~NOUVEAU_GEM_TILE_NONCONTIG) > - return ERR_PTR(-EINVAL); > - > /* Determine the desirable target GPU page size for the buffer. */ > for (i = 0; i < vmm->page_nr; i++) { > /* Because we cannot currently allow VMM maps to fail > diff --git a/include/uapi/drm/nouveau_drm.h b/include/uapi/drm/nouveau_drm.h > index cd84227f1..5402f77ee 100644 > --- a/include/uapi/drm/nouveau_drm.h > +++ b/include/uapi/drm/nouveau_drm.h > @@ -68,6 +68,13 @@ extern "C" { > */ > #define NOUVEAU_GETPARAM_VRAM_USED 19 > > +/* > + * NOUVEAU_GETPARAM_HAS_VMA_TILEMODE > + * > + * Query whether tile mode and PTE kind are accepted with VM allocs or not. > + */ > +#define NOUVEAU_GETPARAM_HAS_VMA_TILEMODE 20 > + > struct drm_nouveau_getparam { > __u64 param; > __u64 value;
Petr Vorel
2025-Sep-25 16:33 UTC
[PATCH v4] drm/nouveau: use tile_mode and pte_kind for VM_BIND bo allocations
From: Mohamed Ahmed <mohamedahmedegypt2001 at gmail.com>> Allows PTE kind and tile mode on BO create with VM_BIND, > and adds a GETPARAM to indicate this change. This is needed to support > modifiers in NVK and ensure correctness when dealing with the nouveau > GL driver. > > The userspace modifiers implementation this is for can be found here: > https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24795 > > Fixes: b88baab82871 ("drm/nouveau: implement new VM_BIND uAPI") > Signed-off-by: Mohamed Ahmed <mohamedahmedegypt2001 at gmail.com> > --- > drivers/gpu/drm/nouveau/nouveau_abi16.c | 3 ++ > drivers/gpu/drm/nouveau/nouveau_bo.c | 44 +++++++++++-------------- > include/uapi/drm/nouveau_drm.h | 7 ++++ > 3 files changed, 29 insertions(+), 25 deletions(-) > > diff --git a/drivers/gpu/drm/nouveau/nouveau_abi16.c b/drivers/gpu/drm/nouveau/nouveau_abi16.c > index 80f74ee0f..47e53e17b 100644 > --- a/drivers/gpu/drm/nouveau/nouveau_abi16.c > +++ b/drivers/gpu/drm/nouveau/nouveau_abi16.c > @@ -272,6 +272,9 @@ nouveau_abi16_ioctl_getparam(ABI16_IOCTL_ARGS) > getparam->value = (u64)ttm_resource_manager_usage(vram_mgr); > break; > } > + case NOUVEAU_GETPARAM_HAS_VMA_TILEMODE: > + getparam->value = 1;FYI the patch causes freezes GUI on NVIDIA GA107GLM RTX A1000 when {un,}plugging dock. With just this single line reverted "fixes" it. Because I the code looks perfectly OK, I suspect some problem in Mesa, I reported it [1]. More details in the ticket, but I post snippet of dmesg also here in case the problem is obvious. Kind regards, Petr [ 2491.400629] [ T3978] usb 1-6: USB disconnect, device number 5 [ 2491.400652] [ T3978] usb 1-6.1: USB disconnect, device number 7 [ 2491.400712] [ T240] pcieport 0000:21:03.0: pciehp: Slot(3): Link Down [ 2491.400736] [ T240] pcieport 0000:21:03.0: pciehp: Slot(3): Card not present [ 2491.402380] [ T240] igc 0000:6d:00.0 enp109s0: PHC removed [ 2491.403032] [ T240] igc 0000:6d:00.0 enp109s0: PCIe link lost, device now detached [ 2491.404016] [ T3978] usb 1-6.2: USB disconnect, device number 8 [ 2491.405175] [ T3978] usb 1-6.4: USB disconnect, device number 9 [ 2491.405184] [ T3978] usb 1-6.4.4: USB disconnect, device number 10 [ 2491.405193] [ T3978] usb 1-6.4.4.2: USB disconnect, device number 11 [ 2491.440942] [ T244] thinkpad_acpi: undocked from hotplug port replicator [ 2491.483469] [ T240] pcieport 0000:4a:03.0: Unable to change power state from D3hot to D0, device inaccessible [ 2491.485458] [ T240] pcieport 0000:4a:02.0: Unable to change power state from D3hot to D0, device inaccessible [ 2491.487157] [ T240] pcieport 0000:4a:01.0: Unable to change power state from D3hot to D0, device inaccessible [ 2491.489618] [ T240] pcieport 0000:4a:00.0: Unable to change power state from D3hot to D0, device inaccessible [ 2491.491320] [ T240] pci_bus 0000:4b: busn_res: [bus 4b] is released [ 2491.497475] [ T240] pci_bus 0000:4c: busn_res: [bus 4c-56] is released [ 2491.503333] [ T240] pci_bus 0000:57: busn_res: [bus 57-61] is released [ 2491.505943] [ T240] pci_bus 0000:62: busn_res: [bus 62-6c] is released [ 2491.512474] [ T240] pci_bus 0000:6d: busn_res: [bus 6d] is released [ 2491.513238] [ T240] pci_bus 0000:4a: busn_res: [bus 4a-6d] is released [ 2491.552238] [ T3481] usb 4-2: USB disconnect, device number 2 [ 2491.552268] [ T3481] usb 4-2.4: USB disconnect, device number 3 [ 2491.552280] [ T3481] usb 4-2.4.4: USB disconnect, device number 4 [ 2491.564055] [ T3978] usb 1-6.4.4.4: USB disconnect, device number 12 [ 2491.959763] [ T3667] thunderbolt 0-3: device disconnected [1] https://gitlab.freedesktop.org/mesa/mesa/-/issues/13974> + break; > default: > NV_PRINTK(dbg, cli, "unknown parameter %lld\n", getparam->param); > return -EINVAL; > diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c b/drivers/gpu/drm/nouveau/nouveau_bo.c > index db8cbf615..186add400 100644 > --- a/drivers/gpu/drm/nouveau/nouveau_bo.c > +++ b/drivers/gpu/drm/nouveau/nouveau_bo.c > @@ -241,28 +241,28 @@ nouveau_bo_alloc(struct nouveau_cli *cli, u64 *size, int *align, u32 domain, > } > > nvbo->contig = !(tile_flags & NOUVEAU_GEM_TILE_NONCONTIG); > - if (!nouveau_cli_uvmm(cli) || internal) { > - /* for BO noVM allocs, don't assign kinds */ > - if (cli->device.info.family >= NV_DEVICE_INFO_V0_FERMI) { > - nvbo->kind = (tile_flags & 0x0000ff00) >> 8; > - if (!nvif_mmu_kind_valid(mmu, nvbo->kind)) { > - kfree(nvbo); > - return ERR_PTR(-EINVAL); > - } > > - nvbo->comp = mmu->kind[nvbo->kind] != nvbo->kind; > - } else if (cli->device.info.family >= NV_DEVICE_INFO_V0_TESLA) { > - nvbo->kind = (tile_flags & 0x00007f00) >> 8; > - nvbo->comp = (tile_flags & 0x00030000) >> 16; > - if (!nvif_mmu_kind_valid(mmu, nvbo->kind)) { > - kfree(nvbo); > - return ERR_PTR(-EINVAL); > - } > - } else { > - nvbo->zeta = (tile_flags & 0x00000007); > + if (cli->device.info.family >= NV_DEVICE_INFO_V0_FERMI) { > + nvbo->kind = (tile_flags & 0x0000ff00) >> 8; > + if (!nvif_mmu_kind_valid(mmu, nvbo->kind)) { > + kfree(nvbo); > + return ERR_PTR(-EINVAL); > + } > + > + nvbo->comp = mmu->kind[nvbo->kind] != nvbo->kind; > + } else if (cli->device.info.family >= NV_DEVICE_INFO_V0_TESLA) { > + nvbo->kind = (tile_flags & 0x00007f00) >> 8; > + nvbo->comp = (tile_flags & 0x00030000) >> 16; > + if (!nvif_mmu_kind_valid(mmu, nvbo->kind)) { > + kfree(nvbo); > + return ERR_PTR(-EINVAL); > } > - nvbo->mode = tile_mode; > + } else { > + nvbo->zeta = (tile_flags & 0x00000007); > + } > + nvbo->mode = tile_mode; > > + if (!nouveau_cli_uvmm(cli) || internal) { > /* Determine the desirable target GPU page size for the buffer. */ > for (i = 0; i < vmm->page_nr; i++) { > /* Because we cannot currently allow VMM maps to fail > @@ -304,12 +304,6 @@ nouveau_bo_alloc(struct nouveau_cli *cli, u64 *size, int *align, u32 domain, > } > nvbo->page = vmm->page[pi].shift; > } else { > - /* reject other tile flags when in VM mode. */ > - if (tile_mode) > - return ERR_PTR(-EINVAL); > - if (tile_flags & ~NOUVEAU_GEM_TILE_NONCONTIG) > - return ERR_PTR(-EINVAL); > - > /* Determine the desirable target GPU page size for the buffer. */ > for (i = 0; i < vmm->page_nr; i++) { > /* Because we cannot currently allow VMM maps to fail > diff --git a/include/uapi/drm/nouveau_drm.h b/include/uapi/drm/nouveau_drm.h > index cd84227f1..5402f77ee 100644 > --- a/include/uapi/drm/nouveau_drm.h > +++ b/include/uapi/drm/nouveau_drm.h > @@ -68,6 +68,13 @@ extern "C" { > */ > #define NOUVEAU_GETPARAM_VRAM_USED 19 > > +/* > + * NOUVEAU_GETPARAM_HAS_VMA_TILEMODE > + * > + * Query whether tile mode and PTE kind are accepted with VM allocs or not. > + */ > +#define NOUVEAU_GETPARAM_HAS_VMA_TILEMODE 20 > + > struct drm_nouveau_getparam { > __u64 param; > __u64 value;