drm/nouveau: Enable atomic modesetting by default
Subsystems (3)
Lyude Paul
maintainerv6 cover drm/nouveau: Enable atomic modesetting by default
Nouveau is one of the very few modern hardware drivers in the kernel that doesn't have atomic modesetting enabled by default, in part because when it was originally written by Ben there wasn't much in the way of good atomic modesetting clients to actually test things out with.
Nowadays however, atomic modesetting is very much the norm - and support in userspace for non-atomic drivers is starting to bitrot a bit - leading to its own set of issues. At the same time, many of those issues are fixed by just turning on atomic in nouveau. Plus, I've been running nouveau with atomic modesetting on by default for most of the machines I work on, and I've already fixed quite a number of issues to the point where things seem quite stable (excluding a single screen flashing bug on my desktop, which I am not particularly convinced has anything to do with atomic modesetting).
This patch series enables atomic modesetting by default, at least for NV50 and newer. NV04 is left unchanged, as atomic modesetting was never implemented for it. This series also enforces leaving atomic modesetting disabled on <NV50, and adds the value of nouveau.atomic to our kernel debug output.
Previous version of this patch series:
https://patchwork.freedesktop.org/series/171310/
Lyude Paul (5):
drm/nouveau: Fix cleanup bug in nouveau_drm_device_new() drm/nouveau: Print the nouveau.atomic parameter in
nouveau_display_options()
drm/nouveau: Fix drm_driver struct/nouveau.atomic parameter handling drm/nouveau/kms: Only allow enabling atomic modesetting on nv50+ drm/nouveau/kms/nv50-: Enable atomic modesetting by default
drivers/gpu/drm/nouveau/nouveau_drm.c | 111 ++++++++++++++++---------- 1 file changed, 68 insertions(+), 43 deletions(-)
base-commit: 9b388fc3d0e63a4f5b022d326151e176e8d82e25
Signature · 1 line
2.55.0
Lyude Paul
maintainerPATCH v6 1/5 drm/nouveau: Fix cleanup bug in nouveau_drm_device_new()
Sashiko caught this while reviewing the patches for enabling atomic by default - if we fail to allocate the DRM device pointer, we'll attempt to free the error pointer that it returns rather than the actual struct. Let's fix this while we're at it.
---
V3:
* Don't use devm, that will just break during unbind (Sashiko). V5:
* Fix silly rebasing error
* Go back to the old style of error handling since we're not using a second allocation for drm_driver anymore.
drivers/gpu/drm/nouveau/nouveau_drm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/nouveau/nouveau_drm.c +2 -1
@@ -749,7 +749,8 @@ nouveau_drm_device_new(const struct drm_driver *drm_driver, struct device *paren drm->dev =drm_dev_alloc (drm_driver, parent);if (IS_ERR (drm->dev)) { ret =PTR_ERR (drm->dev); - goto done; +kfree (drm); +return ERR_PTR (ret); } drm->dev->dev_private = drm;
Signature · 1 line
2.55.0
Lyude Paul
maintainerPATCH v6 2/5 drm/nouveau: Print the nouveau.atomic parameter in nouveau_display_options()
In reply to Lyude PaulSeems like we never remembered to start printing the value for this, so let's start to aid in troubleshooting in case we run into any issues with atomic.
--- drivers/gpu/drm/nouveau/nouveau_drm.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/nouveau/nouveau_drm.c +1 -0
@@ -1417,6 +1417,7 @@ static void nouveau_display_options(void)DRM_DEBUG_DRIVER ("... debug : %s\n" , nouveau_debug);DRM_DEBUG_DRIVER ("... noaccel : %d\n" , nouveau_noaccel);DRM_DEBUG_DRIVER ("... modeset : %d\n" , nouveau_modeset); +DRM_DEBUG_DRIVER ("... atomic : %d\n" , nouveau_atomic);DRM_DEBUG_DRIVER ("... runpm : %d\n" , nouveau_runtime_pm);DRM_DEBUG_DRIVER ("... vram_pushbuf : %d\n" , nouveau_vram_pushbuf);DRM_DEBUG_DRIVER ("... hdmimhz : %d\n" , nouveau_hdmimhz);
Signature · 1 line
2.55.0
Lyude Paul
maintainerPATCH v6 3/5 drm/nouveau: Fix drm_driver struct/nouveau.atomic parameter handling
In reply to Lyude PaulThe way we handled the nouveau.atomic module parameter before was fairly broken, and had a number of issues:
- It was only ever actually parsed in the case of PCI devices.
- When nouveau.atomic was enabled, it would add the cap for atomic modesetting to the global driver_pci structure. This meant that if one GPU on a system supported atomic and another didn't, it would still get enabled for both.
Looking into this exposed further silliness in the way that we actually handle the drm_driver struct. We have one global structure for platform devices, and another for PCI devices - both of which are literally identical.
So before we start preparing to enable atomic modesetting by default, let's fix this. Instead of sharing driver_pci and driver_platform, we instead create driver_legacy_kms and driver_atomic_kms, each of which is identical except for the DRIVER_ATOMIC capabilities flag, and then assign either depending on the nouveau_atomic module parameter.
Doing this is also preferable, as the next step for enabling atomic modesetting by default will be ensuring that we don't enable it for legacy devices that still don't support it. This requires only checking the atomic modesetting module parameter after the NVKM device is ready, as this allows us to check the GPU family that nouveau is running on.
---
V2:
* s/driver_pci/drm_driver/
* Dynamically allocate drm_driver struct, get rid of duplicate global driver structs to fix another Sashiko issue.
V3:
* Don't use devm (sashiko)
V4:
* Don't return 0 by mistake (thanks C)
V6:
* Don't embed drm_driver into drm_device, just create two separate hardcoded structs
* Move the check earlier
drivers/gpu/drm/nouveau/nouveau_drm.c | 100 +++++++++++++++----------- 1 file changed, 58 insertions(+), 42 deletions(-)
drivers/gpu/drm/nouveau/nouveau_drm.c +58 -42
@@ -111,9 +111,8 @@ MODULE_PARM_DESC(runpm, "disable (0), force enable (1), optimus only default (-1static int nouveau_runtime_pm =-1 ;module_param_named (runpm, nouveau_runtime_pm, int,0400 ); -static struct drm_driver driver_stub; -static struct drm_driver driver_pci; -static struct drm_driver driver_platform; +static const struct drm_driver driver_legacy_kms; +static const struct drm_driver driver_atomic_kms;#ifdef CONFIG_DEBUG_FS struct dentry *nouveau_debugfs_root;
@@ -727,8 +726,7 @@ nouveau_drm_device_del(struct nouveau_drm *drm) }static struct nouveau_drm * -nouveau_drm_device_new (const struct drm_driver *drm_driver,struct device *parent, -struct nvkm_device *device) +nouveau_drm_device_new (struct device *parent,struct nvkm_device *device) {static const struct nvif_mclass mmus[] = {
@@ -737,16 +735,21 @@ nouveau_drm_device_new(const struct drm_driver *drm_driver, struct device *paren { NVIF_CLASS_MMU_NV04 , -1 }, {} }; +const struct drm_driver *driver;struct nouveau_drm *drm;int ret; +if (nouveau_atomic) + driver = &driver_atomic_kms; +else + driver = &driver_legacy_kms; + drm =kzalloc_obj (*drm);if (!drm)return ERR_PTR (-ENOMEM ); drm->nvkm = device; - - drm->dev =drm_dev_alloc (drm_driver, parent); + drm->dev =drm_dev_alloc (driver, parent);if (IS_ERR (drm->dev)) { ret =PTR_ERR (drm->dev);kfree (drm);
@@ -874,16 +877,13 @@ static int nouveau_drm_probe(struct pci_dev *pdev,return ret;/* Remove conflicting drivers (vesafb, efifb etc). */ - ret =aperture_remove_conflicting_pci_devices (pdev, driver_pci.name); + ret =aperture_remove_conflicting_pci_devices (pdev,DRIVER_NAME );if (ret) goto fail_nvkm;pci_set_master (pdev); -if (nouveau_atomic) - driver_pci.driver_features |=DRIVER_ATOMIC ; - - drm =nouveau_drm_device_new (&driver_pci, &pdev->dev, device); + drm =nouveau_drm_device_new (&pdev->dev, device);if (IS_ERR (drm)) { ret =PTR_ERR (drm); goto fail_nvkm;
@@ -1360,35 +1360,54 @@ nouveau_driver_fops = { .fop_flags = FOP_UNSIGNED_OFFSET, }; -static struct drm_driver -driver_stub = { - .driver_features =DRIVER_GEM | -DRIVER_SYNCOBJ |DRIVER_SYNCOBJ_TIMELINE | -DRIVER_MODESET | -DRIVER_RENDER , - .open = nouveau_drm_open, - .postclose = nouveau_drm_postclose, - -#if defined(CONFIG_DEBUG_FS) - .debugfs_init = nouveau_drm_debugfs_init, +#ifdef CONFIG_DEBUG_FS +#define NOUVEAU_DEBUGFS_OPS .debugfs_init = nouveau_drm_debugfs_init, +#else +#define NOUVEAU_DEBUGFS_OPS #endif - .ioctls = nouveau_ioctls, - .num_ioctls =ARRAY_SIZE (nouveau_ioctls), - .fops = &nouveau_driver_fops, - - .gem_prime_import_sg_table = nouveau_gem_prime_import_sg_table, - - .dumb_create = nouveau_display_dumb_create, - .dumb_map_offset = drm_gem_ttm_dumb_map_offset, - -DRM_FBDEV_TTM_DRIVER_OPS , +#define NOUVEAU_DRIVER_OPS \ + .open = nouveau_drm_open, \ + .postclose = nouveau_drm_postclose, \ + \ + NOUVEAU_DEBUGFS_OPS \ + \ + .ioctls = nouveau_ioctls, \ + .num_ioctls = ARRAY_SIZE(nouveau_ioctls), \ + .fops = &nouveau_driver_fops, \ + \ + .gem_prime_import_sg_table = nouveau_gem_prime_import_sg_table, \ + \ + .dumb_create = nouveau_display_dumb_create, \ + .dumb_map_offset = drm_gem_ttm_dumb_map_offset, \ + \ + DRM_FBDEV_TTM_DRIVER_OPS, \ + \ + .name = DRIVER_NAME, \ + .desc = DRIVER_DESC, \ + .major = DRIVER_MAJOR, \ + .minor = DRIVER_MINOR, \ + .patchlevel = DRIVER_PATCHLEVEL + +static const struct drm_driver +driver_legacy_kms = { + .driver_features =DRIVER_GEM + |DRIVER_SYNCOBJ + |DRIVER_SYNCOBJ_TIMELINE + |DRIVER_MODESET + |DRIVER_RENDER , +NOUVEAU_DRIVER_OPS , +}; - .name =DRIVER_NAME , - .desc =DRIVER_DESC , - .major =DRIVER_MAJOR , - .minor =DRIVER_MINOR , - .patchlevel =DRIVER_PATCHLEVEL , +static const struct drm_driver +driver_atomic_kms = { + .driver_features =DRIVER_GEM + |DRIVER_SYNCOBJ + |DRIVER_SYNCOBJ_TIMELINE + |DRIVER_MODESET + |DRIVER_RENDER + |DRIVER_ATOMIC , +NOUVEAU_DRIVER_OPS , }; static struct pci_device_id
@@ -1457,7 +1476,7 @@ nouveau_platform_device_create(const struct nvkm_device_tegra_func *func,if (err) goto err_free; - drm =nouveau_drm_device_new (&driver_platform, &pdev->dev, *pdevice); + drm =nouveau_drm_device_new (&pdev->dev, *pdevice);if (IS_ERR (drm)) { err =PTR_ERR (drm); goto err_free;
@@ -1482,9 +1501,6 @@ nouveau_drm_init(void) {int ret; - driver_pci = driver_stub; - driver_platform = driver_stub; -nouveau_display_options ();if (nouveau_modeset ==-1 ) {
Signature · 1 line
2.55.0
Lyude Paul
maintainerPATCH v6 4/5 drm/nouveau/kms: Only allow enabling atomic modesetting on nv50+
In reply to Lyude PaulAtomic modesetting support was never added for pre-nv50 chipsets, so make sure we don't allow it to be forced on. Additionally, print a small warning when it's not supported.
---
V2:
* Check against info.family, not info.chipset
V6:
* Check against device->card_type so we can perform the check before setting up nvif
drivers/gpu/drm/nouveau/nouveau_drm.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
drivers/gpu/drm/nouveau/nouveau_drm.c +10 -3
@@ -739,10 +739,17 @@ nouveau_drm_device_new(struct device *parent, struct nvkm_device *device)struct nouveau_drm *drm;int ret; -if (nouveau_atomic) - driver = &driver_atomic_kms; -else +if (device->card_type >=NV_50 ) { +if (nouveau_atomic) + driver = &driver_atomic_kms; +else + driver = &driver_legacy_kms; + }else { +if (nouveau_atomic) +dev_warn (parent,"Atomic modesetting not supported (needs nv50+)\n" ); + driver = &driver_legacy_kms; + } drm =kzalloc_obj (*drm);if (!drm)
Signature · 1 line
2.55.0
Lyude Paul
maintainerPATCH v6 5/5 drm/nouveau/kms/nv50-: Enable atomic modesetting by default
In reply to Lyude PaulNouveau is one of the very few modern hardware drivers in the kernel that doesn't have atomic modesetting enabled by default, in part because when it was originally written by Ben there wasn't much in the way of good atomic modesetting clients to actually test things out with.
Nowadays however, atomic modesetting is very much the norm - and support in userspace for non-atomic drivers is starting to bitrot a bit - leading to its own set of issues. At the same time, many of those issues are fixed by just turning on atomic in nouveau. Plus, I've been running nouveau with atomic modesetting on by default for most of the machines I work on, and I've already fixed quite a number of issues to the point where things seem quite stable (excluding a single screen flashing bug on my desktop, which I am not particularly convinced has anything to do with atomic modesetting).
Now that we've protected against breaking things for chipsets where atomic isn't supported (<nv50) - let's enable it by default on generations of hardware that support it. We'll leave the module parameter around for the time being, as turning it off may be helpful in the possibility that we hit regressions.
--- drivers/gpu/drm/nouveau/nouveau_drm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/nouveau/nouveau_drm.c +1 -1
@@ -745,7 +745,7 @@ nouveau_drm_device_new(struct device *parent, struct nvkm_device *device)else driver = &driver_legacy_kms; }else { -if (nouveau_atomic) +if (nouveau_atomic !=-1 )dev_warn (parent,"Atomic modesetting not supported (needs nv50+)\n" ); driver = &driver_legacy_kms;
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v6 5/5] drm/nouveau/kms/nv50-: Enable atomic modesetting by default
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The patch completely fails to enable atomic modesetting by default on nv50+ hardware and…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The patch completely fails to enable atomic modesetting by default on nv50+ hardware and introduces a spurious warning on every boot for legacy hardware. --
--- Patch [5]: [PATCH v6 5/5] drm/nouveau/kms/nv50-: Enable atomic modesetting by default --- commit 72a6dbf310da7445e59ffec7fdf8ec40a1396882
Author: Lyude Paul <[email protected]>
drm/nouveau/kms/nv50-: Enable atomic modesetting by default
This commit aims to enable atomic modesetting by default on nv50+ hardware while retaining a module parameter to turn it off if regressions occur.
drivers/gpu/drm/nouveau/nouveau_drm.c nouveau_drm_device_new(struct device *parent, struct nvkm_device *device) · line 748
Quoted 10 lines
drivers/gpu/drm/nouveau/nouveau_drm.c +1
-1@@ -745,7 +745,7 @@ nouveau_drm_device_new(struct device *parent, struct nvkm_device *device)else driver = &driver_legacy_kms; }else { -if (nouveau_atomic) +if (nouveau_atomic !=-1 )
[Severity: Medium]
Does this inadvertently leave atomic modesetting disabled by default on nv50+ hardware, and introduce a regression where spurious warnings are printed on older hardware?
Looking at nouveau_drm_device_new(), the check above this else block for nv50+ hardware remains unmodified:
if (device->card_type >= NV_50) {
if (nouveau_atomic)
driver = &driver_atomic_kms;
else
driver = &driver_legacy_kms;
}Since the module parameter nouveau_atomic remains initialized to 0, atomic modesetting remains disabled by default on nv50+, which seems to defeat the purpose described in the commit message.
Additionally, for pre-nv50 hardware, the modified condition (nouveau_atomic != -1) now evaluates to true by default (0 != -1), which will cause this dev_warn() to print spuriously on every boot.
Quoted 3 lines
drivers/gpu/drm/nouveau/nouveau_drm.c +0
-0dev_warn (parent,"Atomic modesetting not supported (needs nv50+)\n" ); driver = &driver_legacy_kms;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5