lkml.org 
[lkml]   [2020]   [Nov]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: [PATCH RFC 12/12] vdpa_sim_blk: implement ramdisk behaviour
On Tue, Nov 17, 2020 at 11:36:36AM +0000, Stefan Hajnoczi wrote:
>On Fri, Nov 13, 2020 at 02:47:12PM +0100, Stefano Garzarella wrote:
>> diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c b/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c
>> index 8e41b3ab98d5..68e74383322f 100644
>> --- a/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c
>> +++ b/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c
>> @@ -7,6 +7,7 @@
>> */
>>
>> #include <linux/module.h>
>> +#include <linux/blkdev.h>
>> #include <uapi/linux/virtio_blk.h>
>>
>> #include "vdpa_sim.h"
>> @@ -24,10 +25,137 @@
>>
>> static struct vdpasim *vdpasim_blk_dev;
>>
>> +static int vdpasim_blk_handle_req(struct vdpasim *vdpasim,
>> + struct vdpasim_virtqueue *vq)
>
>This function has a non-standard int return value. Please document it.

Yes, I'll do.

>
>> +{
>> + size_t wrote = 0, to_read = 0, to_write = 0;
>> + struct virtio_blk_outhdr hdr;
>> + uint8_t status;
>> + uint32_t type;
>> + ssize_t bytes;
>> + loff_t offset;
>> + int i, ret;
>> +
>> + vringh_kiov_cleanup(&vq->riov);
>> + vringh_kiov_cleanup(&vq->wiov);
>> +
>> + ret = vringh_getdesc_iotlb(&vq->vring, &vq->riov, &vq->wiov,
>> + &vq->head, GFP_ATOMIC);
>> + if (ret != 1)
>> + return ret;
>> +
>> + for (i = 0; i < vq->wiov.used; i++)
>> + to_write += vq->wiov.iov[i].iov_len;
>> + to_write -= 1; /* last byte is the status */
>
>What if vq->wiov.used == 0?

Right, we should discard the descriptor.

>
>> +
>> + for (i = 0; i < vq->riov.used; i++)
>> + to_read += vq->riov.iov[i].iov_len;
>> +
>> + bytes = vringh_iov_pull_iotlb(&vq->vring, &vq->riov, &hdr, sizeof(hdr));
>> + if (bytes != sizeof(hdr))
>> + return 0;
>> +
>> + to_read -= bytes;
>> +
>> + type = le32_to_cpu(hdr.type);
>> + offset = le64_to_cpu(hdr.sector) << SECTOR_SHIFT;
>> + status = VIRTIO_BLK_S_OK;
>> +
>> + switch (type) {
>> + case VIRTIO_BLK_T_IN:
>> + if (offset + to_write > VDPASIM_BLK_CAPACITY << SECTOR_SHIFT) {
>
>Integer overflow is not handled.

I'll fix.

Thanks,
Stefano

\
 
 \ /
  Last update: 2020-11-17 15:35    [W:0.078 / U:0.804 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site