virtio_balloon: check virtqueue_add_outbuf() return value
The purpose of this patch is, virtqueue_add_outbuf() adding data to virtqueue may succeed or fail. If successful, it will call virtqueue_kick() to notifie the host backend driver, but if the virtqueue_add_outbuf() fails, the data is not successfully added to the virtqueue, and the host back-end driver does not need to be notified for processing.
Thanks.
-----邮件原件-----
发件人: Michael S. Tsirkin <[email protected]>
发送时间: 2022年5月27日 18:25
收件人: Bo Liu (刘波)-浪潮信息 <[email protected]>
抄送: [email protected]; [email protected]; [email protected]; [email protected] 主题: Re: [PATCH] virtio_balloon: check virtqueue_add_outbuf() return value
Quoted 3 lines · Bo Liu
virtqueue_add_outbuf()can fail, when it fails, there is no need to call the funciontvirtqueue_kick().Signed-off-by Bo Liu <[email protected]>
Sorry don't get it.
What's the point of this patch really?
Quoted 18 lines
--- drivers/virtio/virtio_balloon.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)(quoted diff) +0
-0
b/drivers/virtio/virtio_balloon.cindexb9737da6c4dd..0d7da4d95e1e100644drivers/virtio/virtio_balloon.c +1
-0@@ -153,16 +153,18 @@ static void tell_host(struct virtio_balloon *vb, struct virtqueue *vq) {struct scatterlist sg;unsigned int len; +int err;sg_init_one (&sg, vb->pfns,sizeof (vb->pfns[0 ]) * vb->num_pfns);/* We should always be able to add one buffer to an empty queue. */
drivers/virtio/virtio_balloon.c static void tell_host(struct virtio_balloon *vb, · line 165
Quoted 10 lines
drivers/virtio/virtio_balloon.c +4
-5-virtqueue_add_outbuf (vq, &sg,1 , vb,GFP_KERNEL ); -virtqueue_kick (vq); - -/* When host has read buffer, this completes via balloon_ack */ -wait_event (vb->acked,virtqueue_get_buf (vq, &len)); + err =virtqueue_add_outbuf (vq, &sg,1 , vb,GFP_KERNEL ); +if (!err) { +virtqueue_kick (vq); +/* When host has read buffer, this completes via balloon_ack
*/
Quoted 6 lines
drivers/virtio/virtio_balloon.c +2
-0+wait_event (vb->acked,virtqueue_get_buf (vq, &len)); + } } static int virtballoon_free_page_report(struct
page_reporting_dev_info*pr_dev_info, @@ -382,6 +384,7 @@ static void
stats_handle_request(struct virtio_balloon *vb)
drivers/virtio/virtio_balloon.c static void stats_handle_request(struct virtio_balloon
Quoted 8 lines
drivers/virtio/virtio_balloon.c +1
-0struct virtqueue *vq;struct scatterlist sg;unsigned int len, num_stats; +int err; num_stats =update_balloon_stats (vb);@@ -389,8 +392,9 @@ static void stats_handle_request(struct virtio_balloon
*vb)
Quoted 13 lines
drivers/virtio/virtio_balloon.c +3
-3if (!virtqueue_get_buf (vq, &len))return ;sg_init_one (&sg, vb->stats,sizeof (vb->stats[0 ]) * num_stats); -virtqueue_add_outbuf (vq, &sg,1 , vb,GFP_KERNEL ); -virtqueue_kick (vq); + err =virtqueue_add_outbuf (vq, &sg,1 , vb,GFP_KERNEL ); +if (!err) +virtqueue_kick (vq); }static inline s64 towards_target (struct virtio_balloon *vb) --2.27.0
Michael S. Tsirkin
maintainerQuoted 7 lines · Bo Liu (刘波)-浪潮信息
The purpose of this patch is,
virtqueue_add_outbuf()adding data to virtqueue may succeed or fail. If successful, it will callvirtqueue_kick()to notifie the host backend driver, but if thevirtqueue_add_outbuf()fails, the data is not successfully added to the virtqueue, and the host back-end driver does not need to be notified for processing.Thanks.
Why is it a problem if we do?
Signature · 1 line
MST