Thank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [High] drm/nouveau/nvkm: missing Signed-off-by trailer in commit message - [Medium] drm/nouveau/nvkm: NULL deref in nvkm_devinit_dtor() after ctor iounmap() - [Medium] drm/nouveau/nvkm: NULL device->dev in nvkm_device_del() on ctor failure - [Low] drm/nouveau/nvkm: Fixes trailer cites unrelated commit 0d5dd3f301bb --
commit 9d8c7debf78767e0a5b65084a841f14aa7a58bd6 Author: Dave Airlie <[email protected]> > drm/nouveau/nvkm: fix device leak on ctor failure > > When adding a new failure path from device_ctor, the missing > clean up paths in the current code were uncovered. > > The device_del path doesn't work because it relies on initialisation > that hadn't been done yet. > > This patch cleans up the failure paths and initialises the > things needed for the nvkm_device_del path to work. > > Fixes: 0d5dd3f301bb ("drm/nouveau/lib: various tweaks") [Severity: High] The commit message is missing a Signed-off-by: trailer. [Severity: Low] Does the Fixes: tag point to the right commit? 0d5dd3f301bb ("drm/nouveau/lib: various tweaks") only changed list_add() to list_add_tail() in nvkm_device_create_(). The split into nvkm_device_ctor(), nvkm_device_pci_new(), and nvkm_device_tegra_new() where ctor failure paths skipped nvkm_device_del() was introduced in 7974dd1bdb43 ("drm/nouveau/device: separate construction of pci/tegra devices"). > diff --git a/drivers/gpu/drm/nouveau/nvkm/engine/device/base.c > b/drivers/gpu/drm/nouveau/nvkm/engine/device/base.c > index a2ed8c4fe52a0..625bb019736af 100644 > --- a/drivers/gpu/drm/nouveau/nvkm/engine/device/base.c > +++ b/drivers/gpu/drm/nouveau/nvkm/engine/device/base.c > @@ -3152,10 +3152,19 @@ nvkm_device_ctor(const struct nvkm_device_func *func, > unsigned chipset; > > mutex_lock(&nv_devices_mutex); > + > + /* Set up the state that nvkm_device_del() relies on before anything > + * that can fail, so that a device whose construction failed can be > + * cleaned up by the caller with nvkm_device_del(). > + */ > + device->func = func; > + INIT_LIST_HEAD(&device->head); > + INIT_LIST_HEAD(&device->subdev); > + nvkm_intr_ctor(device); > + > if (nvkm_device_find_locked(handle)) > goto done; > > - device->func = func; > device->quirk = quirk; > device->dev = dev; [Severity: Medium] Should device->dev = dev also be set before nvkm_device_find_locked()? If nvkm_device_find_locked() returns an existing device on Tegra, nvkm_device_tegra_new() now calls nvkm_device_del(), which runs nvkm_device_tegra_dtor() -> nvkm_device_tegra_remove_iommu(): drivers/gpu/drm/nouveau/nvkm/engine/device/tegra.c:nvkm_device_tegra_remove_iommu() { if (tdev->iommu.domain) { nvkm_mm_fini(&tdev->iommu.mm); iommu_detach_device(tdev->iommu.domain, tdev->device.dev); iommu_domain_free(tdev->iommu.domain); } } Because nvkm_device_tegra_probe_iommu() has already attached tdev->iommu.domain before calling nvkm_device_ctor(), leaving tdev->device.dev as NULL causes a NULL pointer dereference inside iommu_detach_device(). [ ... ] > diff --git a/drivers/gpu/drm/nouveau/nvkm/engine/device/pci.c > b/drivers/gpu/drm/nouveau/nvkm/engine/device/pci.c > index 248623b91e295..269ccd4b482e9 100644 > --- a/drivers/gpu/drm/nouveau/nvkm/engine/device/pci.c > +++ b/drivers/gpu/drm/nouveau/nvkm/engine/device/pci.c > @@ -1705,8 +1705,10 @@ nvkm_device_pci_new(struct pci_dev *pci_dev, const > char *cfg, const char *dbg, > PCI_FUNC(pci_dev->devfn), name, > cfg, dbg, &pdev->device); > > - if (ret) > + if (ret) { > + nvkm_device_del(pdevice); > return ret; > + } [Severity: Medium] Can calling nvkm_device_del() after nvkm_device_ctor() fails cause a NULL pointer dereference in subdevice destructors? When nvkm_device_ctor() fails after constructing early subdevices (for example, if a later subdevice constructor or nvkm_intr_install() fails), its error path unmaps and clears device->pri before returning: drivers/gpu/drm/nouveau/nvkm/engine/device/base.c:nvkm_device_ctor() { ... done: if (ret && device->pri) { iounmap(device->pri); device->pri = NULL; } mutex_unlock(&nv_devices_mutex); return ret; } nvkm_device_del() then destroys the already constructed subdevices on device->subdev. When it reaches nvkm_devinit_dtor(), nvkm_lockvgac() attempts MMIO accesses through the NULL device->pri pointer. Since nvkm_device_del() already unmaps device->pri after destroying subdevices, should nvkm_device_ctor() leave device->pri mapped for nvkm_device_del() to clean up? -- Sashiko AI review ยท https://sashiko.dev/#/patchset/[email protected]?part=1
