From: "Zhu, Lingshan" <lingshan.zhu@intel.com>
To: Jason Wang <jasowang@redhat.com>, mst@redhat.com
Cc: virtualization@lists.linux-foundation.org
Subject: Re: [PATCH 4/5] synchronize irqs in the reset routine
Date: Thu, 27 Apr 2023 17:07:12 +0800 [thread overview]
Message-ID: <d5bfd95a-a3b9-bfd3-8690-4e739428f0b9@intel.com> (raw)
In-Reply-To: <329f4dbf-442e-2171-bad4-cceb9efd6dc7@redhat.com>
On 4/26/2023 1:06 PM, Jason Wang wrote:
>
> 在 2023/4/1 04:48, Zhu Lingshan 写道:
>> This commit synchronize irqs of the virtqueues
>> and config space in the reset routine.
>> Thus ifcvf_stop_hw() and reset() are refactored as well.
>>
>> Signed-off-by: Zhu Lingshan <lingshan.zhu@intel.com>
>> ---
>> drivers/vdpa/ifcvf/ifcvf_base.c | 61 ++++++++++++++++++++++++++-------
>> drivers/vdpa/ifcvf/ifcvf_main.c | 45 +++---------------------
>> 2 files changed, 54 insertions(+), 52 deletions(-)
>>
>> diff --git a/drivers/vdpa/ifcvf/ifcvf_base.c
>> b/drivers/vdpa/ifcvf/ifcvf_base.c
>> index 79e313c5e10e..49949aec20ef 100644
>> --- a/drivers/vdpa/ifcvf/ifcvf_base.c
>> +++ b/drivers/vdpa/ifcvf/ifcvf_base.c
>> @@ -170,12 +170,7 @@ void ifcvf_set_status(struct ifcvf_hw *hw, u8
>> status)
>> void ifcvf_reset(struct ifcvf_hw *hw)
>> {
>> - hw->config_cb.callback = NULL;
>> - hw->config_cb.private = NULL;
>> -
>> ifcvf_set_status(hw, 0);
>> - /* flush set_status, make sure VF is stopped, reset */
>> - ifcvf_get_status(hw);
>
>
> If we don't flush or poll how can we know the reset is done?
>
> E.g modern virtio-pci did:
>
> /* 0 status means a reset. */
> vp_modern_set_status(mdev, 0);
> /* After writing 0 to device_status, the driver MUST wait for
> a read of
> * device_status to return 0 before reinitializing the device.
> * This will flush out the status write, and flush in device
> writes,
> * including MSI-X interrupts, if any.
> */
> while (vp_modern_get_status(mdev))
> msleep(1);
> /* Flush pending VQ/configuration callbacks. */
> vp_synchronize_vectors(vdev);
Thanks, I can implement a similar get_status() here.
>
>> }
>> u64 ifcvf_get_hw_features(struct ifcvf_hw *hw)
>> @@ -368,20 +363,62 @@ void ifcvf_set_vq_ready(struct ifcvf_hw *hw,
>> u16 qid, bool ready)
>> vp_iowrite16(ready, &cfg->queue_enable);
>> }
>> -static void ifcvf_hw_disable(struct ifcvf_hw *hw)
>> +static void synchronize_per_vq_irq(struct ifcvf_hw *hw)
>> {
>> - u32 i;
>> + u16 qid;
>> - ifcvf_set_config_vector(hw, VIRTIO_MSI_NO_VECTOR);
>> - for (i = 0; i < hw->nr_vring; i++) {
>> - ifcvf_set_vq_vector(hw, i, VIRTIO_MSI_NO_VECTOR);
>> + for (qid = 0; qid < hw->nr_vring; qid++) {
>> + if (hw->vring[qid].irq != -EINVAL)
>> + synchronize_irq(hw->vring[qid].irq);
>> }
>> }
>> +static void synchronize_vqs_reused_irq(struct ifcvf_hw *hw)
>> +{
>> + if (hw->vqs_reused_irq != -EINVAL)
>> + synchronize_irq(hw->vqs_reused_irq);
>> +}
>> +
>> +static void synchronize_vq_irq(struct ifcvf_hw *hw)
>> +{
>> + u8 status = hw->msix_vector_status;
>> +
>> + if (status == MSIX_VECTOR_PER_VQ_AND_CONFIG)
>> + synchronize_per_vq_irq(hw);
>> + else
>> + synchronize_vqs_reused_irq(hw);
>> +}
>
>
> I wonder if we need to go with such complicated ways,can we
> synchronize through the vectors like virtio-pci did?
>
> for (i = 0; i < vp_dev->msix_vectors; ++i)
> synchronize_irq(pci_irq_vector(vp_dev->pci_dev, i));
> ?
I can record the number of msix_vectors and sycn irq based on it in V2.
>
>
>> +
>> +static void synchronize_config_irq(struct ifcvf_hw *hw)
>> +{
>> + if (hw->config_irq != -EINVAL)
>> + synchronize_irq(hw->config_irq);
>> +}
>> +
>> +static void ifcvf_reset_vring(struct ifcvf_hw *hw)
>> +{
>> + u16 qid;
>> +
>> + for (qid = 0; qid < hw->nr_vring; qid++) {
>> + synchronize_vq_irq(hw);
>
> Since IRQ could be shared, this will result extra complexity, like a
> irq could be flushed multiple times?
No for this code path, E.g., if the all vqs share one irq, it will only
be flushed once in synchronize_vqs_reused_irq()
Thanks
>
> Thanks
>
>
>> + hw->vring[qid].cb.callback = NULL;
>> + hw->vring[qid].cb.private = NULL;
>> + ifcvf_set_vq_vector(hw, qid, VIRTIO_MSI_NO_VECTOR);
>> + }
>> +}
>> +
>> +static void ifcvf_reset_config_handler(struct ifcvf_hw *hw)
>> +{
>> + synchronize_config_irq(hw);
>> + hw->config_cb.callback = NULL;
>> + hw->config_cb.private = NULL;
>> + ifcvf_set_config_vector(hw, VIRTIO_MSI_NO_VECTOR);
>> +}
>> +
>> void ifcvf_stop_hw(struct ifcvf_hw *hw)
>> {
>> - ifcvf_hw_disable(hw);
>> - ifcvf_reset(hw);
>> + ifcvf_reset_vring(hw);
>> + ifcvf_reset_config_handler(hw);
>> }
>> void ifcvf_notify_queue(struct ifcvf_hw *hw, u16 qid)
>> diff --git a/drivers/vdpa/ifcvf/ifcvf_main.c
>> b/drivers/vdpa/ifcvf/ifcvf_main.c
>> index 968687159e44..15c6157ee841 100644
>> --- a/drivers/vdpa/ifcvf/ifcvf_main.c
>> +++ b/drivers/vdpa/ifcvf/ifcvf_main.c
>> @@ -346,33 +346,6 @@ static int ifcvf_request_irq(struct ifcvf_hw *vf)
>> return 0;
>> }
>> -static int ifcvf_stop_datapath(struct ifcvf_adapter *adapter)
>> -{
>> - struct ifcvf_hw *vf = adapter->vf;
>> - int i;
>> -
>> - for (i = 0; i < vf->nr_vring; i++)
>> - vf->vring[i].cb.callback = NULL;
>> -
>> - ifcvf_stop_hw(vf);
>> -
>> - return 0;
>> -}
>> -
>> -static void ifcvf_reset_vring(struct ifcvf_adapter *adapter)
>> -{
>> - struct ifcvf_hw *vf = adapter->vf;
>> - int i;
>> -
>> - for (i = 0; i < vf->nr_vring; i++) {
>> - vf->vring[i].last_avail_idx = 0;
>> - vf->vring[i].cb.callback = NULL;
>> - vf->vring[i].cb.private = NULL;
>> - }
>> -
>> - ifcvf_reset(vf);
>> -}
>> -
>> static struct ifcvf_adapter *vdpa_to_adapter(struct vdpa_device
>> *vdpa_dev)
>> {
>> return container_of(vdpa_dev, struct ifcvf_adapter, vdpa);
>> @@ -462,23 +435,15 @@ static void ifcvf_vdpa_set_status(struct
>> vdpa_device *vdpa_dev, u8 status)
>> static int ifcvf_vdpa_reset(struct vdpa_device *vdpa_dev)
>> {
>> - struct ifcvf_adapter *adapter;
>> - struct ifcvf_hw *vf;
>> - u8 status_old;
>> -
>> - vf = vdpa_to_vf(vdpa_dev);
>> - adapter = vdpa_to_adapter(vdpa_dev);
>> - status_old = ifcvf_get_status(vf);
>> + struct ifcvf_hw *vf = vdpa_to_vf(vdpa_dev);
>> + u8 status = ifcvf_get_status(vf);
>> - if (status_old == 0)
>> - return 0;
>> + ifcvf_stop_hw(vf);
>> - if (status_old & VIRTIO_CONFIG_S_DRIVER_OK) {
>> - ifcvf_stop_datapath(adapter);
>> + if (status & VIRTIO_CONFIG_S_DRIVER_OK)
>> ifcvf_free_irq(vf);
>> - }
>> - ifcvf_reset_vring(adapter);
>> + ifcvf_reset(vf);
>> return 0;
>> }
>
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
next prev parent reply other threads:[~2023-04-27 9:07 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-31 20:48 [PATCH 0/5] vDPA/ifcvf: implement immediate initialization mechanism Zhu Lingshan
2023-03-31 20:48 ` [PATCH 1/5] virt queue ops take immediate actions Zhu Lingshan
2023-04-26 3:39 ` Jason Wang
2023-04-27 8:02 ` Zhu, Lingshan
2023-03-31 20:48 ` [PATCH 2/5] get_driver_features from virito registers Zhu Lingshan
2023-04-24 4:50 ` Michael S. Tsirkin
2023-04-24 7:24 ` Zhu, Lingshan
2023-04-26 4:02 ` Jason Wang
2023-04-27 8:28 ` Zhu, Lingshan
2023-03-31 20:48 ` [PATCH 3/5] retire ifcvf_start_datapath and ifcvf_add_status Zhu Lingshan
2023-04-26 4:04 ` Jason Wang
2023-03-31 20:48 ` [PATCH 4/5] synchronize irqs in the reset routine Zhu Lingshan
2023-04-26 5:06 ` Jason Wang
2023-04-27 9:07 ` Zhu, Lingshan [this message]
2023-03-31 20:48 ` [PATCH 5/5] a vendor driver should not set _CONFIG_S_FAILED Zhu Lingshan
2023-04-26 5:10 ` Jason Wang
2023-04-03 5:28 ` [PATCH 0/5] vDPA/ifcvf: implement immediate initialization mechanism Jason Wang
2023-04-03 10:10 ` Zhu, Lingshan
2023-04-20 9:17 ` Zhu, Lingshan
2023-04-24 3:50 ` Jason Wang
2023-04-24 4:52 ` Michael S. Tsirkin
2023-04-24 5:20 ` Jason Wang
2023-04-24 9:53 ` Michael S. Tsirkin
2023-04-24 4:51 ` Michael S. Tsirkin
2023-04-24 7:25 ` Zhu, Lingshan
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=d5bfd95a-a3b9-bfd3-8690-4e739428f0b9@intel.com \
--to=lingshan.zhu@intel.com \
--cc=jasowang@redhat.com \
--cc=mst@redhat.com \
--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