All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mathieu Poirier <mathieu.poirier@linaro.org>
To: Francesco Valla <francesco@valla.it>
Cc: Bjorn Andersson <andersson@kernel.org>,
	Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>,
	Joakim Zhang <joakim.zhang@cixtech.com>,
	linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/4] remoteproc: virtio: Decouple vdev from the parent pdev
Date: Tue, 24 Nov 2026 10:55:41 -0600	[thread overview]
Message-ID: <awXBjZ9jqXW1ETNZ@p14s> (raw)
In-Reply-To: <20261114-remoteproc_pdev_decouple-v2-1-95235dd056aa@valla.it>

On Sat, Nov 14, 2026 at 09:06:33AM +0100, Francesco Valla wrote:
> The rproc-virtio platform device can have a lifetime different from the
> virtio_device it registers. During cleanup (e.g.: when a remoteproc is
> stopped) the platform device is de-registered by the remoteproc core,
> but the related virtio_device might be released later; if this happens,
> rproc_virtio_dev_release() will try to de-reference a NULL pointer as
> part of vdev_to_rvdev(). This can easily be reproduced with
> CONFIG_DEBUG_KOBJECT_RELEASE.

Can you provide steps to reproduce this problem?  Otherwise I'm good with the
simplifications provided by this patch.

Thanks,
Mathieu

> 
> Remove the access to the platform device structure from the cleanup path
> and interact instead with its backing device, whose refcount was
> explicitly increased during rproc_add_virtio_dev() and will be
> decremented as part of rproc_virtio_dev_release(). The same is done for
> the pdev de-reference inside vdev_to_rvdev(), even if no more used
> during cleanup, to maintain the same access pattern.
> 
> While at it, fix the comments on the specific matter.
> 
> Fixes: 1d7b61c06dc3 ("remoteproc: virtio: Create platform device for the remoteproc_virtio")
> Signed-off-by: Francesco Valla <francesco@valla.it>
> ---
>  drivers/remoteproc/remoteproc_virtio.c | 22 ++++++++--------------
>  1 file changed, 8 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/remoteproc/remoteproc_virtio.c b/drivers/remoteproc/remoteproc_virtio.c
> index 29a3a4c18097..b59f4acbb630 100644
> --- a/drivers/remoteproc/remoteproc_virtio.c
> +++ b/drivers/remoteproc/remoteproc_virtio.c
> @@ -49,11 +49,7 @@ static int copy_dma_range_map(struct device *to, struct device *from)
>  
>  static struct rproc_vdev *vdev_to_rvdev(struct virtio_device *vdev)
>  {
> -	struct platform_device *pdev;
> -
> -	pdev = container_of(vdev->dev.parent, struct platform_device, dev);
> -
> -	return platform_get_drvdata(pdev);
> +	return dev_get_drvdata(vdev->dev.parent);
>  }
>  
>  static struct rproc *vdev_to_rproc(struct virtio_device *vdev)
> @@ -348,7 +344,7 @@ static const struct virtio_config_ops rproc_virtio_config_ops = {
>  
>  /*
>   * This function is called whenever vdev is released, and is responsible
> - * to decrement the remote processor's refcount which was taken when vdev was
> + * to decrement the platform device's refcount which was taken when vdev was
>   * added.
>   *
>   * Never call this function directly; it will be called by the driver
> @@ -357,14 +353,13 @@ static const struct virtio_config_ops rproc_virtio_config_ops = {
>  static void rproc_virtio_dev_release(struct device *dev)
>  {
>  	struct virtio_device *vdev = dev_to_virtio(dev);
> -	struct rproc_vdev *rvdev = vdev_to_rvdev(vdev);
>  
> -	kfree(vdev);
> +	of_reserved_mem_device_release(dev->parent);
> +	dma_release_coherent_memory(dev->parent);
>  
> -	of_reserved_mem_device_release(&rvdev->pdev->dev);
> -	dma_release_coherent_memory(&rvdev->pdev->dev);
> +	put_device(dev->parent);
>  
> -	put_device(&rvdev->pdev->dev);
> +	kfree(vdev);
>  }
>  
>  /**
> @@ -372,8 +367,7 @@ static void rproc_virtio_dev_release(struct device *dev)
>   * @rvdev: the remote vdev
>   * @id: the device type identification (used to match it with a driver).
>   *
> - * This function registers a virtio device. This vdev's partent is
> - * the rproc device.
> + * This function registers a virtio device with the platform device as parent.
>   *
>   * Return: 0 on success or an appropriate error value otherwise
>   */
> @@ -448,7 +442,7 @@ static int rproc_add_virtio_dev(struct rproc_vdev *rvdev, int id)
>  	vdev->dev.parent = dev;
>  	vdev->dev.release = rproc_virtio_dev_release;
>  
> -	/* Reference the vdev and vring allocations */
> +	/* Reference the parent device, which will be used during teardown. */
>  	get_device(dev);
>  
>  	ret = register_virtio_device(vdev);
> 
> -- 
> 2.56.0
> 

  reply	other threads:[~2026-11-24 16:55 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-14  8:06 [PATCH v2 0/4] remoteproc: virtio: Fixes and cleanups in the vdev<->pdev relationship Francesco Valla
2026-11-14  8:06 ` [PATCH v2 1/4] remoteproc: virtio: Decouple vdev from the parent pdev Francesco Valla
2026-11-24 16:55   ` Mathieu Poirier [this message]
2026-11-24 20:00     ` Francesco Valla
2026-11-14  8:06 ` [PATCH v2 2/4] remoteproc: virtio: Rework memory release Francesco Valla
2026-11-14  8:06 ` [PATCH v2 3/4] remoteproc: virtio: Drop rvdevs list and associated functions Francesco Valla
2026-11-26 16:41   ` Mathieu Poirier
2026-11-26 16:59     ` Francesco Valla
2026-11-26 17:42       ` Mathieu Poirier
2026-11-14  8:06 ` [PATCH v2 4/4] remoteproc: virtio: Stop de-referencing pdev from its children Francesco Valla

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=awXBjZ9jqXW1ETNZ@p14s \
    --to=mathieu.poirier@linaro.org \
    --cc=andersson@kernel.org \
    --cc=arnaud.pouliquen@foss.st.com \
    --cc=francesco@valla.it \
    --cc=joakim.zhang@cixtech.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-remoteproc@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.