public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Igor Skalkin <Igor.Skalkin@opensynergy.com>
Cc: Jason Wang <jasowang@redhat.com>,
	virtualization@lists.linux-foundation.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] virtio-mmio: Introduce virtio_mmio hotplug
Date: Sun, 7 Aug 2022 18:56:57 -0400	[thread overview]
Message-ID: <20220807185612-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20220807215226.36507-1-Igor.Skalkin@opensynergy.com>

On Sun, Aug 07, 2022 at 11:52:26PM +0200, Igor Skalkin wrote:
> From: Igor Skalkin <igor.skalkin@opensynergy.com>
> 
> While the virtio device is not yet running, the virtual machine manager
> advertises the device with device_id set to 0.
> During virtio mmio probing, the device_id is checked, and if it is 0,
> the rest of the probing function is deferred until the interrupt arrives.
> 
> Signed-off-by: Igor Skalkin <igor.skalkin@opensynergy.com>

Given this is clearly an extension to host/guest ABI, please
propose this on the virtio TC mailing list.


> ---
> In our setup, we have a Linux host running virtio devices and virtualised
> Linux/Android Guest[s] running virtio drivers.
> Situation "the guest OS calls the probe() function for the virtio driver,
> but the virtio device has not yet started in the host OS." keeps happening.
> Also, some devices need to be hot-plugged later instead of starting during
> system sturtup.
> 
> Probing of the guest virtio drivers should be deferred until the host device
> has started.
> ---
>  drivers/virtio/virtio_mmio.c | 58 ++++++++++++++++++++++++++++++++++++
>  1 file changed, 58 insertions(+)
> 
> diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
> index 083ff1eb743d..c2e28a8faaaa 100644
> --- a/drivers/virtio/virtio_mmio.c
> +++ b/drivers/virtio/virtio_mmio.c
> @@ -91,6 +91,8 @@ struct virtio_mmio_device {
>  	/* a list of queues so we can dispatch IRQs */
>  	spinlock_t lock;
>  	struct list_head virtqueues;
> +
> +	struct work_struct hotplug_work;
>  };
>  
>  struct virtio_mmio_vq_info {
> @@ -592,6 +594,43 @@ static void virtio_mmio_release_dev(struct device *_d)
>  
>  /* Platform device */
>  
> +static irqreturn_t hotplug_interrupt(int irq, void *opaque)
> +{
> +	struct virtio_mmio_device *vm_dev = opaque;
> +
> +	if (readl(vm_dev->base + VIRTIO_MMIO_DEVICE_ID))
> +		schedule_work(&vm_dev->hotplug_work);
> +
> +	return IRQ_HANDLED;
> +}
> +
> +static int virtio_mmio_request_irq(irq_handler_t handler,
> +				   struct virtio_mmio_device *vm_dev)
> +{
> +	int err;
> +
> +	err = request_irq(platform_get_irq(vm_dev->pdev, 0), handler,
> +			  IRQF_SHARED, dev_name(&vm_dev->pdev->dev), vm_dev);
> +	if (err)
> +		dev_err(&vm_dev->pdev->dev, "request_irq(%s) returns %d\n",
> +			dev_name(&vm_dev->pdev->dev), err);
> +
> +	return err;
> +}
> +
> +static int finish_probe(struct virtio_mmio_device *vm_dev);
> +static void virtio_mmio_hotplug_work(struct work_struct *hotplug_work)
> +{
> +	struct virtio_mmio_device *vm_dev =
> +		container_of(hotplug_work, struct virtio_mmio_device,
> +			    hotplug_work);
> +
> +	free_irq(platform_get_irq(vm_dev->pdev, 0), vm_dev);
> +
> +	if (finish_probe(vm_dev))
> +		virtio_mmio_request_irq(hotplug_interrupt, vm_dev);
> +}
> +
>  static int virtio_mmio_probe(struct platform_device *pdev)
>  {
>  	struct virtio_mmio_device *vm_dev;
> @@ -628,6 +667,25 @@ static int virtio_mmio_probe(struct platform_device *pdev)
>  		return -ENXIO;
>  	}
>  
> +	vm_dev->vdev.id.device = readl(vm_dev->base + VIRTIO_MMIO_DEVICE_ID);
> +	if (!vm_dev->vdev.id.device) {
> +		rc = virtio_mmio_request_irq(hotplug_interrupt, vm_dev);
> +		if (rc)
> +			return rc;
> +
> +		INIT_WORK(&vm_dev->hotplug_work, virtio_mmio_hotplug_work);
> +
> +		return 0;
> +	}
> +
> +	return finish_probe(vm_dev);
> +}
> +
> +static int finish_probe(struct virtio_mmio_device *vm_dev)
> +{
> +	struct platform_device *pdev = vm_dev->pdev;
> +	int rc;
> +
>  	vm_dev->vdev.id.device = readl(vm_dev->base + VIRTIO_MMIO_DEVICE_ID);
>  	if (vm_dev->vdev.id.device == 0) {
>  		/*
> -- 
> 2.37.1


           reply	other threads:[~2022-08-07 22:57 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <20220807215226.36507-1-Igor.Skalkin@opensynergy.com>]

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=20220807185612-mutt-send-email-mst@kernel.org \
    --to=mst@redhat.com \
    --cc=Igor.Skalkin@opensynergy.com \
    --cc=jasowang@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=virtualization@lists.linux-foundation.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox