NVIDIA GPU driver infrastructure
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Dave Airlie" <airlied@redhat.com>,
	"Lyude Paul" <lyude@redhat.com>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"Alexandre Courbot" <acourbot@nvidia.com>
Cc: dri-devel@lists.freedesktop.org, nova-gpu@lists.linux.dev
Subject: Re: [PATCH v2 1/3] drm/nouveau/nvkm: fix device leak on ctor failure
Date: Mon, 23 Nov 2026 03:14:16 +0000	[thread overview]
Message-ID: <sashiko-outbox-228586@kernel.org> (raw)
In-Reply-To: <20261123-nova-nouveau-gsp-v2-1-5e8c27aa8555@redhat.com>

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 <airlied@redhat.com>

> 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/20261123-nova-nouveau-gsp-v2-0-5e8c27aa8555@redhat.com?part=1

  reply	other threads:[~2026-11-23  3:14 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23  2:50 [PATCH v2 0/3] nova/nouveau: add configs/module options to control binding behaviour (v2) Dave Airlie via B4 Relay
2026-11-23  2:50 ` [PATCH v2 1/3] drm/nouveau/nvkm: fix device leak on ctor failure Dave Airlie via B4 Relay
2026-11-23  3:14   ` sashiko-bot [this message]
2026-11-23 13:47     ` Danilo Krummrich
2026-11-23  2:50 ` [PATCH v2 2/3] drm/nouveau: add option to leave GSP-capable GPUs to other drivers Dave Airlie via B4 Relay
2026-11-23  2:58   ` sashiko-bot
2026-11-23 17:31   ` Timur Tabi
2026-11-23 21:11     ` David Airlie
2026-11-23 21:14       ` Danilo Krummrich
2026-11-23 21:16       ` Timur Tabi
2026-11-23  2:50 ` [PATCH v2 3/3] nova-core: only bind to GPUs when explicitly requested Dave Airlie via B4 Relay
2026-11-23  2:55   ` sashiko-bot
2026-11-23 15:18   ` Danilo Krummrich
2026-11-23 16:53     ` Danilo Krummrich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-228586@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=airlied@redhat.com \
    --cc=dakr@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=lyude@redhat.com \
    --cc=nova-gpu@lists.linux.dev \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox