From: "Longpeng (Mike, Cloud Infrastructure Service Product Dept.)" <longpeng2@huawei.com>
To: Stefano Garzarella <sgarzare@redhat.com>
Cc: <stefanha@redhat.com>, <mst@redhat.com>, <jasowang@redhat.com>,
<virtualization@lists.linux-foundation.org>,
<arei.gonglei@huawei.com>, <yechuan@huawei.com>,
<huangzhichao@huawei.com>, <linux-kernel@vger.kernel.org>,
<xiehong@huawei.com>
Subject: Re: [PATCH] vp_vdpa: harden the logic of set status
Date: Fri, 11 Nov 2022 23:49:10 +0800 [thread overview]
Message-ID: <0f25506f-b9ca-1578-f944-cfb3936ced50@huawei.com> (raw)
In-Reply-To: <20221111151459.dyz42jclq26ai26q@sgarzare-redhat>
在 2022/11/11 23:14, Stefano Garzarella 写道:
> On Fri, Nov 11, 2022 at 10:55:05PM +0800, Longpeng(Mike) wrote:
>> From: Longpeng <longpeng2@huawei.com>
>>
>> 1. We should not set status to 0 when invoking vp_vdpa_set_status().
>>
>> 2. The driver MUST wait for a read of device_status to return 0 before
>> reinitializing the device.
>>
>> Signed-off-by: Longpeng <longpeng2@huawei.com>
>> ---
>> drivers/vdpa/virtio_pci/vp_vdpa.c | 11 ++++++++++-
>> 1 file changed, 10 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/vdpa/virtio_pci/vp_vdpa.c
>> b/drivers/vdpa/virtio_pci/vp_vdpa.c
>> index d448db0c4de3..d35fac5cde11 100644
>> --- a/drivers/vdpa/virtio_pci/vp_vdpa.c
>> +++ b/drivers/vdpa/virtio_pci/vp_vdpa.c
>> @@ -212,8 +212,12 @@ static void vp_vdpa_set_status(struct vdpa_device
>> *vdpa, u8 status)
>> {
>> struct vp_vdpa *vp_vdpa = vdpa_to_vp(vdpa);
>> struct virtio_pci_modern_device *mdev = vp_vdpa_to_mdev(vp_vdpa);
>> - u8 s = vp_vdpa_get_status(vdpa);
>
> Is this change really needed?
>
No need to get the status if we try to set status to 0 (trigger BUG).
>> + u8 s;
>> +
>> + /* We should never be setting status to 0. */
>> + BUG_ON(status == 0);
>
> IMHO panicking the kernel seems excessive in this case, please use
> WARN_ON and maybe return earlier.
>
Um...I referenced the vp_reset/vp_set_status,
>>
>> + s = vp_vdpa_get_status(vdpa);
>> if (status & VIRTIO_CONFIG_S_DRIVER_OK &&
>> !(s & VIRTIO_CONFIG_S_DRIVER_OK)) {
>> vp_vdpa_request_irq(vp_vdpa);
>> @@ -229,6 +233,11 @@ static int vp_vdpa_reset(struct vdpa_device *vdpa)
>> u8 s = vp_vdpa_get_status(vdpa);
>>
>> 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.
>> + */
>> + while (vp_modern_get_status(mdev))
>> + msleep(1);
>
> Should we set a limit after which we give up? A malfunctioning device
> could keep us here forever.
>
Yes, but the malfunctioning device maybe can not work anymore, how to
handle it?
> Thanks,
> Stefano
>
>>
>> if (s & VIRTIO_CONFIG_S_DRIVER_OK)
>> vp_vdpa_free_irq(vp_vdpa);
>> --
>> 2.23.0
>>
>
> .
next prev parent reply other threads:[~2022-11-11 15:49 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-11 14:55 Longpeng(Mike)
2022-11-11 15:14 ` Stefano Garzarella
2022-11-11 15:49 ` Longpeng (Mike, Cloud Infrastructure Service Product Dept.) [this message]
2022-11-11 16:35 ` Stefano Garzarella
2022-11-12 7:33 ` Longpeng (Mike, Cloud Infrastructure Service Product Dept.)
2022-11-14 4:21 ` Jason Wang
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=0f25506f-b9ca-1578-f944-cfb3936ced50@huawei.com \
--to=longpeng2@huawei.com \
--cc=arei.gonglei@huawei.com \
--cc=huangzhichao@huawei.com \
--cc=jasowang@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mst@redhat.com \
--cc=sgarzare@redhat.com \
--cc=stefanha@redhat.com \
--cc=virtualization@lists.linux-foundation.org \
--cc=xiehong@huawei.com \
--cc=yechuan@huawei.com \
/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
all inboxes | Powered by JetHome®