Re: [PATCH v2 3/5] VSOCK: support receive mergeable rx buffer in guest

2018-12-17 Thread jiangyiwen
On 2018/12/14 0:20, Stefan Hajnoczi wrote:
> On Wed, Dec 12, 2018 at 05:31:39PM +0800, jiangyiwen wrote:
>> +static struct virtio_vsock_pkt *receive_mergeable(struct virtqueue *vq,
>> +struct virtio_vsock *vsock, unsigned int *total_len)
>> +{
>> +struct virtio_vsock_pkt *pkt;
>> +u16 num_buf;
>> +void *buf;
>> +unsigned int len;
>> +size_t vsock_hlen = sizeof(struct virtio_vsock_pkt);
>> +
>> +buf = virtqueue_get_buf(vq, );
>> +if (!buf)
>> +return NULL;
>> +
>> +*total_len = len;
>> +vsock->rx_buf_nr--;
>> +
>> +if (unlikely(len < vsock_hlen)) {
>> +put_page(virt_to_head_page(buf));
>> +return NULL;
>> +}
>> +
>> +pkt = buf;
>> +num_buf = le16_to_cpu(pkt->mrg_rxbuf_hdr.num_buffers);
>> +if (!num_buf || num_buf > VIRTIO_VSOCK_MAX_VEC_NUM) {
>> +put_page(virt_to_head_page(buf));
>> +return NULL;
>> +}
>> +
>> +/* Initialize pkt residual structure */
>> +memset(>work, 0, vsock_hlen - sizeof(struct virtio_vsock_hdr) -
>> +sizeof(struct virtio_vsock_mrg_rxbuf_hdr));
> 
> struct virtio_vsock_pkt is an internal driver state structure.  It must
> be able to change without breaking the host<->guest device interface.
> Exposing struct virtio_vsock_pkt across the device interface makes this
> impossible.
> 
> One way to solve this is by placing a header length field at the
> beginning of the mergeable buffer.  That way the device knows at which
> offset the payload should be placed and the driver can continue to use
> the allocation scheme you've chosen (where a single page contains the
> virtio_vsock_pkt and payload).
> 
> Another issue is that virtio requires exclusive read OR write
> descriptors.  You cannot have a descriptor that is both read and write.
> So there's not a huge advantage to combining the driver state struct and
> payload, except maybe the driver can save a memory allocation.
> 

Right, I will separate pkt and payload in different pages, as you mentioned
in another patch.

Thanks,
Yiwen.

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


Re: [PATCH v2 3/5] VSOCK: support receive mergeable rx buffer in guest

2018-12-17 Thread jiangyiwen
On 2018/12/13 22:29, Michael S. Tsirkin wrote:
> On Thu, Dec 13, 2018 at 10:38:09AM +0800, jiangyiwen wrote:
>> Hi Michael,
>>
>> On 2018/12/12 23:31, Michael S. Tsirkin wrote:
>>> On Wed, Dec 12, 2018 at 05:31:39PM +0800, jiangyiwen wrote:
 Guest receive mergeable rx buffer, it can merge
 scatter rx buffer into a big buffer and then copy
 to user space.

 In addition, it also use iovec to replace buf in struct
 virtio_vsock_pkt, keep tx and rx consistency. The only
 difference is now tx still uses a segment of continuous
 physical memory to implement.

 Signed-off-by: Yiwen Jiang 
 ---
  drivers/vhost/vsock.c   |  31 +++---
  include/linux/virtio_vsock.h|   6 +-
  net/vmw_vsock/virtio_transport.c| 105 
 
  net/vmw_vsock/virtio_transport_common.c |  59 ++
  4 files changed, 166 insertions(+), 35 deletions(-)
>>>
>>>
>>> This was supposed to be a guest patch, why is vhost changed here?
>>>
>>
>> In mergeable rx buff cases, it need to scatter big packets into several
>> buffers, so I add kvec variable in struct virtio_vsock_pkt, at the same
>> time, in order to keep tx and rx consistency, I use kvec to replace
>> variable buf, because vhost use the variable pkt->buf, so this patch
>> caused vhost is changed.
> 
> You'd want to split these patches imho.
> 

Ok, I should do it.

 diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c
 index dc52b0f..c7ab0dd 100644
 --- a/drivers/vhost/vsock.c
 +++ b/drivers/vhost/vsock.c
 @@ -179,6 +179,8 @@ static int get_rx_bufs(struct vhost_virtqueue *vq,
size_t nbytes;
size_t len;
s16 headcount;
 +  size_t remain_len;
 +  int i;

spin_lock_bh(>send_pkt_list_lock);
if (list_empty(>send_pkt_list)) {
 @@ -221,11 +223,19 @@ static int get_rx_bufs(struct vhost_virtqueue *vq,
break;
}

 -  nbytes = copy_to_iter(pkt->buf, pkt->len, _iter);
 -  if (nbytes != pkt->len) {
 -  virtio_transport_free_pkt(pkt);
 -  vq_err(vq, "Faulted on copying pkt buf\n");
 -  break;
 +  remain_len = pkt->len;
 +  for (i = 0; i < pkt->nr_vecs; i++) {
 +  int tmp_len;
 +
 +  tmp_len = min(remain_len, pkt->vec[i].iov_len);
 +  nbytes = copy_to_iter(pkt->vec[i].iov_base, tmp_len, 
 _iter);
 +  if (nbytes != tmp_len) {
 +  virtio_transport_free_pkt(pkt);
 +  vq_err(vq, "Faulted on copying pkt buf\n");
 +  break;
 +  }
 +
 +  remain_len -= tmp_len;
}

vhost_add_used_n(vq, vq->heads, headcount);
 @@ -341,6 +351,7 @@ static void vhost_transport_send_pkt_work(struct 
 vhost_work *work)
struct iov_iter iov_iter;
size_t nbytes;
size_t len;
 +  void *buf;

if (in != 0) {
vq_err(vq, "Expected 0 input buffers, got %u\n", in);
 @@ -375,13 +386,17 @@ static void vhost_transport_send_pkt_work(struct 
 vhost_work *work)
return NULL;
}

 -  pkt->buf = kmalloc(pkt->len, GFP_KERNEL);
 -  if (!pkt->buf) {
 +  buf = kmalloc(pkt->len, GFP_KERNEL);
 +  if (!buf) {
kfree(pkt);
return NULL;
}

 -  nbytes = copy_from_iter(pkt->buf, pkt->len, _iter);
 +  pkt->vec[0].iov_base = buf;
 +  pkt->vec[0].iov_len = pkt->len;
 +  pkt->nr_vecs = 1;
 +
 +  nbytes = copy_from_iter(buf, pkt->len, _iter);
if (nbytes != pkt->len) {
vq_err(vq, "Expected %u byte payload, got %zu bytes\n",
   pkt->len, nbytes);
 diff --git a/include/linux/virtio_vsock.h b/include/linux/virtio_vsock.h
 index da9e1fe..734eeed 100644
 --- a/include/linux/virtio_vsock.h
 +++ b/include/linux/virtio_vsock.h
 @@ -13,6 +13,8 @@
  #define VIRTIO_VSOCK_DEFAULT_RX_BUF_SIZE  (1024 * 4)
  #define VIRTIO_VSOCK_MAX_BUF_SIZE 0xUL
  #define VIRTIO_VSOCK_MAX_PKT_BUF_SIZE (1024 * 64)
 +/* virtio_vsock_pkt + max_pkt_len(default MAX_PKT_BUF_SIZE) */
 +#define VIRTIO_VSOCK_MAX_VEC_NUM ((VIRTIO_VSOCK_MAX_PKT_BUF_SIZE / 
 PAGE_SIZE) + 1)

  /* Virtio-vsock feature */
  #define VIRTIO_VSOCK_F_MRG_RXBUF 0 /* Host can merge receive buffers. */
 @@ -55,10 +57,12 @@ struct virtio_vsock_pkt {
struct list_head list;
/* socket refcnt not held, only use for cancellation */
struct vsock_sock *vsk;
 -  void *buf;
 +  struct kvec vec[VIRTIO_VSOCK_MAX_VEC_NUM];
 +  int 

Re: [PATCH v2 3/5] VSOCK: support receive mergeable rx buffer in guest

2018-12-16 Thread Stefan Hajnoczi
On Wed, Dec 12, 2018 at 05:31:39PM +0800, jiangyiwen wrote:
> +static struct virtio_vsock_pkt *receive_mergeable(struct virtqueue *vq,
> + struct virtio_vsock *vsock, unsigned int *total_len)
> +{
> + struct virtio_vsock_pkt *pkt;
> + u16 num_buf;
> + void *buf;
> + unsigned int len;
> + size_t vsock_hlen = sizeof(struct virtio_vsock_pkt);
> +
> + buf = virtqueue_get_buf(vq, );
> + if (!buf)
> + return NULL;
> +
> + *total_len = len;
> + vsock->rx_buf_nr--;
> +
> + if (unlikely(len < vsock_hlen)) {
> + put_page(virt_to_head_page(buf));
> + return NULL;
> + }
> +
> + pkt = buf;
> + num_buf = le16_to_cpu(pkt->mrg_rxbuf_hdr.num_buffers);
> + if (!num_buf || num_buf > VIRTIO_VSOCK_MAX_VEC_NUM) {
> + put_page(virt_to_head_page(buf));
> + return NULL;
> + }
> +
> + /* Initialize pkt residual structure */
> + memset(>work, 0, vsock_hlen - sizeof(struct virtio_vsock_hdr) -
> + sizeof(struct virtio_vsock_mrg_rxbuf_hdr));

struct virtio_vsock_pkt is an internal driver state structure.  It must
be able to change without breaking the host<->guest device interface.
Exposing struct virtio_vsock_pkt across the device interface makes this
impossible.

One way to solve this is by placing a header length field at the
beginning of the mergeable buffer.  That way the device knows at which
offset the payload should be placed and the driver can continue to use
the allocation scheme you've chosen (where a single page contains the
virtio_vsock_pkt and payload).

Another issue is that virtio requires exclusive read OR write
descriptors.  You cannot have a descriptor that is both read and write.
So there's not a huge advantage to combining the driver state struct and
payload, except maybe the driver can save a memory allocation.


signature.asc
Description: PGP signature
___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

Re: [PATCH v2 3/5] VSOCK: support receive mergeable rx buffer in guest

2018-12-16 Thread Michael S. Tsirkin
On Thu, Dec 13, 2018 at 10:38:09AM +0800, jiangyiwen wrote:
> Hi Michael,
> 
> On 2018/12/12 23:31, Michael S. Tsirkin wrote:
> > On Wed, Dec 12, 2018 at 05:31:39PM +0800, jiangyiwen wrote:
> >> Guest receive mergeable rx buffer, it can merge
> >> scatter rx buffer into a big buffer and then copy
> >> to user space.
> >>
> >> In addition, it also use iovec to replace buf in struct
> >> virtio_vsock_pkt, keep tx and rx consistency. The only
> >> difference is now tx still uses a segment of continuous
> >> physical memory to implement.
> >>
> >> Signed-off-by: Yiwen Jiang 
> >> ---
> >>  drivers/vhost/vsock.c   |  31 +++---
> >>  include/linux/virtio_vsock.h|   6 +-
> >>  net/vmw_vsock/virtio_transport.c| 105 
> >> 
> >>  net/vmw_vsock/virtio_transport_common.c |  59 ++
> >>  4 files changed, 166 insertions(+), 35 deletions(-)
> > 
> > 
> > This was supposed to be a guest patch, why is vhost changed here?
> > 
> 
> In mergeable rx buff cases, it need to scatter big packets into several
> buffers, so I add kvec variable in struct virtio_vsock_pkt, at the same
> time, in order to keep tx and rx consistency, I use kvec to replace
> variable buf, because vhost use the variable pkt->buf, so this patch
> caused vhost is changed.

You'd want to split these patches imho.

> >> diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c
> >> index dc52b0f..c7ab0dd 100644
> >> --- a/drivers/vhost/vsock.c
> >> +++ b/drivers/vhost/vsock.c
> >> @@ -179,6 +179,8 @@ static int get_rx_bufs(struct vhost_virtqueue *vq,
> >>size_t nbytes;
> >>size_t len;
> >>s16 headcount;
> >> +  size_t remain_len;
> >> +  int i;
> >>
> >>spin_lock_bh(>send_pkt_list_lock);
> >>if (list_empty(>send_pkt_list)) {
> >> @@ -221,11 +223,19 @@ static int get_rx_bufs(struct vhost_virtqueue *vq,
> >>break;
> >>}
> >>
> >> -  nbytes = copy_to_iter(pkt->buf, pkt->len, _iter);
> >> -  if (nbytes != pkt->len) {
> >> -  virtio_transport_free_pkt(pkt);
> >> -  vq_err(vq, "Faulted on copying pkt buf\n");
> >> -  break;
> >> +  remain_len = pkt->len;
> >> +  for (i = 0; i < pkt->nr_vecs; i++) {
> >> +  int tmp_len;
> >> +
> >> +  tmp_len = min(remain_len, pkt->vec[i].iov_len);
> >> +  nbytes = copy_to_iter(pkt->vec[i].iov_base, tmp_len, 
> >> _iter);
> >> +  if (nbytes != tmp_len) {
> >> +  virtio_transport_free_pkt(pkt);
> >> +  vq_err(vq, "Faulted on copying pkt buf\n");
> >> +  break;
> >> +  }
> >> +
> >> +  remain_len -= tmp_len;
> >>}
> >>
> >>vhost_add_used_n(vq, vq->heads, headcount);
> >> @@ -341,6 +351,7 @@ static void vhost_transport_send_pkt_work(struct 
> >> vhost_work *work)
> >>struct iov_iter iov_iter;
> >>size_t nbytes;
> >>size_t len;
> >> +  void *buf;
> >>
> >>if (in != 0) {
> >>vq_err(vq, "Expected 0 input buffers, got %u\n", in);
> >> @@ -375,13 +386,17 @@ static void vhost_transport_send_pkt_work(struct 
> >> vhost_work *work)
> >>return NULL;
> >>}
> >>
> >> -  pkt->buf = kmalloc(pkt->len, GFP_KERNEL);
> >> -  if (!pkt->buf) {
> >> +  buf = kmalloc(pkt->len, GFP_KERNEL);
> >> +  if (!buf) {
> >>kfree(pkt);
> >>return NULL;
> >>}
> >>
> >> -  nbytes = copy_from_iter(pkt->buf, pkt->len, _iter);
> >> +  pkt->vec[0].iov_base = buf;
> >> +  pkt->vec[0].iov_len = pkt->len;
> >> +  pkt->nr_vecs = 1;
> >> +
> >> +  nbytes = copy_from_iter(buf, pkt->len, _iter);
> >>if (nbytes != pkt->len) {
> >>vq_err(vq, "Expected %u byte payload, got %zu bytes\n",
> >>   pkt->len, nbytes);
> >> diff --git a/include/linux/virtio_vsock.h b/include/linux/virtio_vsock.h
> >> index da9e1fe..734eeed 100644
> >> --- a/include/linux/virtio_vsock.h
> >> +++ b/include/linux/virtio_vsock.h
> >> @@ -13,6 +13,8 @@
> >>  #define VIRTIO_VSOCK_DEFAULT_RX_BUF_SIZE  (1024 * 4)
> >>  #define VIRTIO_VSOCK_MAX_BUF_SIZE 0xUL
> >>  #define VIRTIO_VSOCK_MAX_PKT_BUF_SIZE (1024 * 64)
> >> +/* virtio_vsock_pkt + max_pkt_len(default MAX_PKT_BUF_SIZE) */
> >> +#define VIRTIO_VSOCK_MAX_VEC_NUM ((VIRTIO_VSOCK_MAX_PKT_BUF_SIZE / 
> >> PAGE_SIZE) + 1)
> >>
> >>  /* Virtio-vsock feature */
> >>  #define VIRTIO_VSOCK_F_MRG_RXBUF 0 /* Host can merge receive buffers. */
> >> @@ -55,10 +57,12 @@ struct virtio_vsock_pkt {
> >>struct list_head list;
> >>/* socket refcnt not held, only use for cancellation */
> >>struct vsock_sock *vsk;
> >> -  void *buf;
> >> +  struct kvec vec[VIRTIO_VSOCK_MAX_VEC_NUM];
> >> +  int nr_vecs;
> >>u32 len;
> >>u32 off;
> >>bool reply;
> >> +  bool 

Re: [PATCH v2 3/5] VSOCK: support receive mergeable rx buffer in guest

2018-12-15 Thread jiangyiwen
Hi Michael,

On 2018/12/12 23:31, Michael S. Tsirkin wrote:
> On Wed, Dec 12, 2018 at 05:31:39PM +0800, jiangyiwen wrote:
>> Guest receive mergeable rx buffer, it can merge
>> scatter rx buffer into a big buffer and then copy
>> to user space.
>>
>> In addition, it also use iovec to replace buf in struct
>> virtio_vsock_pkt, keep tx and rx consistency. The only
>> difference is now tx still uses a segment of continuous
>> physical memory to implement.
>>
>> Signed-off-by: Yiwen Jiang 
>> ---
>>  drivers/vhost/vsock.c   |  31 +++---
>>  include/linux/virtio_vsock.h|   6 +-
>>  net/vmw_vsock/virtio_transport.c| 105 
>> 
>>  net/vmw_vsock/virtio_transport_common.c |  59 ++
>>  4 files changed, 166 insertions(+), 35 deletions(-)
> 
> 
> This was supposed to be a guest patch, why is vhost changed here?
> 

In mergeable rx buff cases, it need to scatter big packets into several
buffers, so I add kvec variable in struct virtio_vsock_pkt, at the same
time, in order to keep tx and rx consistency, I use kvec to replace
variable buf, because vhost use the variable pkt->buf, so this patch
caused vhost is changed.

>> diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c
>> index dc52b0f..c7ab0dd 100644
>> --- a/drivers/vhost/vsock.c
>> +++ b/drivers/vhost/vsock.c
>> @@ -179,6 +179,8 @@ static int get_rx_bufs(struct vhost_virtqueue *vq,
>>  size_t nbytes;
>>  size_t len;
>>  s16 headcount;
>> +size_t remain_len;
>> +int i;
>>
>>  spin_lock_bh(>send_pkt_list_lock);
>>  if (list_empty(>send_pkt_list)) {
>> @@ -221,11 +223,19 @@ static int get_rx_bufs(struct vhost_virtqueue *vq,
>>  break;
>>  }
>>
>> -nbytes = copy_to_iter(pkt->buf, pkt->len, _iter);
>> -if (nbytes != pkt->len) {
>> -virtio_transport_free_pkt(pkt);
>> -vq_err(vq, "Faulted on copying pkt buf\n");
>> -break;
>> +remain_len = pkt->len;
>> +for (i = 0; i < pkt->nr_vecs; i++) {
>> +int tmp_len;
>> +
>> +tmp_len = min(remain_len, pkt->vec[i].iov_len);
>> +nbytes = copy_to_iter(pkt->vec[i].iov_base, tmp_len, 
>> _iter);
>> +if (nbytes != tmp_len) {
>> +virtio_transport_free_pkt(pkt);
>> +vq_err(vq, "Faulted on copying pkt buf\n");
>> +break;
>> +}
>> +
>> +remain_len -= tmp_len;
>>  }
>>
>>  vhost_add_used_n(vq, vq->heads, headcount);
>> @@ -341,6 +351,7 @@ static void vhost_transport_send_pkt_work(struct 
>> vhost_work *work)
>>  struct iov_iter iov_iter;
>>  size_t nbytes;
>>  size_t len;
>> +void *buf;
>>
>>  if (in != 0) {
>>  vq_err(vq, "Expected 0 input buffers, got %u\n", in);
>> @@ -375,13 +386,17 @@ static void vhost_transport_send_pkt_work(struct 
>> vhost_work *work)
>>  return NULL;
>>  }
>>
>> -pkt->buf = kmalloc(pkt->len, GFP_KERNEL);
>> -if (!pkt->buf) {
>> +buf = kmalloc(pkt->len, GFP_KERNEL);
>> +if (!buf) {
>>  kfree(pkt);
>>  return NULL;
>>  }
>>
>> -nbytes = copy_from_iter(pkt->buf, pkt->len, _iter);
>> +pkt->vec[0].iov_base = buf;
>> +pkt->vec[0].iov_len = pkt->len;
>> +pkt->nr_vecs = 1;
>> +
>> +nbytes = copy_from_iter(buf, pkt->len, _iter);
>>  if (nbytes != pkt->len) {
>>  vq_err(vq, "Expected %u byte payload, got %zu bytes\n",
>> pkt->len, nbytes);
>> diff --git a/include/linux/virtio_vsock.h b/include/linux/virtio_vsock.h
>> index da9e1fe..734eeed 100644
>> --- a/include/linux/virtio_vsock.h
>> +++ b/include/linux/virtio_vsock.h
>> @@ -13,6 +13,8 @@
>>  #define VIRTIO_VSOCK_DEFAULT_RX_BUF_SIZE(1024 * 4)
>>  #define VIRTIO_VSOCK_MAX_BUF_SIZE   0xUL
>>  #define VIRTIO_VSOCK_MAX_PKT_BUF_SIZE   (1024 * 64)
>> +/* virtio_vsock_pkt + max_pkt_len(default MAX_PKT_BUF_SIZE) */
>> +#define VIRTIO_VSOCK_MAX_VEC_NUM ((VIRTIO_VSOCK_MAX_PKT_BUF_SIZE / 
>> PAGE_SIZE) + 1)
>>
>>  /* Virtio-vsock feature */
>>  #define VIRTIO_VSOCK_F_MRG_RXBUF 0 /* Host can merge receive buffers. */
>> @@ -55,10 +57,12 @@ struct virtio_vsock_pkt {
>>  struct list_head list;
>>  /* socket refcnt not held, only use for cancellation */
>>  struct vsock_sock *vsk;
>> -void *buf;
>> +struct kvec vec[VIRTIO_VSOCK_MAX_VEC_NUM];
>> +int nr_vecs;
>>  u32 len;
>>  u32 off;
>>  bool reply;
>> +bool mergeable;
>>  };
>>
>>  struct virtio_vsock_pkt_info {
>> diff --git a/net/vmw_vsock/virtio_transport.c 
>> b/net/vmw_vsock/virtio_transport.c
>> index c4a465c..148b58a 100644
>> --- a/net/vmw_vsock/virtio_transport.c
>> +++ 

Re: [PATCH v2 3/5] VSOCK: support receive mergeable rx buffer in guest

2018-12-14 Thread Michael S. Tsirkin
On Wed, Dec 12, 2018 at 05:31:39PM +0800, jiangyiwen wrote:
> Guest receive mergeable rx buffer, it can merge
> scatter rx buffer into a big buffer and then copy
> to user space.
> 
> In addition, it also use iovec to replace buf in struct
> virtio_vsock_pkt, keep tx and rx consistency. The only
> difference is now tx still uses a segment of continuous
> physical memory to implement.
> 
> Signed-off-by: Yiwen Jiang 
> ---
>  drivers/vhost/vsock.c   |  31 +++---
>  include/linux/virtio_vsock.h|   6 +-
>  net/vmw_vsock/virtio_transport.c| 105 
> 
>  net/vmw_vsock/virtio_transport_common.c |  59 ++
>  4 files changed, 166 insertions(+), 35 deletions(-)


This was supposed to be a guest patch, why is vhost changed here?

> diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c
> index dc52b0f..c7ab0dd 100644
> --- a/drivers/vhost/vsock.c
> +++ b/drivers/vhost/vsock.c
> @@ -179,6 +179,8 @@ static int get_rx_bufs(struct vhost_virtqueue *vq,
>   size_t nbytes;
>   size_t len;
>   s16 headcount;
> + size_t remain_len;
> + int i;
> 
>   spin_lock_bh(>send_pkt_list_lock);
>   if (list_empty(>send_pkt_list)) {
> @@ -221,11 +223,19 @@ static int get_rx_bufs(struct vhost_virtqueue *vq,
>   break;
>   }
> 
> - nbytes = copy_to_iter(pkt->buf, pkt->len, _iter);
> - if (nbytes != pkt->len) {
> - virtio_transport_free_pkt(pkt);
> - vq_err(vq, "Faulted on copying pkt buf\n");
> - break;
> + remain_len = pkt->len;
> + for (i = 0; i < pkt->nr_vecs; i++) {
> + int tmp_len;
> +
> + tmp_len = min(remain_len, pkt->vec[i].iov_len);
> + nbytes = copy_to_iter(pkt->vec[i].iov_base, tmp_len, 
> _iter);
> + if (nbytes != tmp_len) {
> + virtio_transport_free_pkt(pkt);
> + vq_err(vq, "Faulted on copying pkt buf\n");
> + break;
> + }
> +
> + remain_len -= tmp_len;
>   }
> 
>   vhost_add_used_n(vq, vq->heads, headcount);
> @@ -341,6 +351,7 @@ static void vhost_transport_send_pkt_work(struct 
> vhost_work *work)
>   struct iov_iter iov_iter;
>   size_t nbytes;
>   size_t len;
> + void *buf;
> 
>   if (in != 0) {
>   vq_err(vq, "Expected 0 input buffers, got %u\n", in);
> @@ -375,13 +386,17 @@ static void vhost_transport_send_pkt_work(struct 
> vhost_work *work)
>   return NULL;
>   }
> 
> - pkt->buf = kmalloc(pkt->len, GFP_KERNEL);
> - if (!pkt->buf) {
> + buf = kmalloc(pkt->len, GFP_KERNEL);
> + if (!buf) {
>   kfree(pkt);
>   return NULL;
>   }
> 
> - nbytes = copy_from_iter(pkt->buf, pkt->len, _iter);
> + pkt->vec[0].iov_base = buf;
> + pkt->vec[0].iov_len = pkt->len;
> + pkt->nr_vecs = 1;
> +
> + nbytes = copy_from_iter(buf, pkt->len, _iter);
>   if (nbytes != pkt->len) {
>   vq_err(vq, "Expected %u byte payload, got %zu bytes\n",
>  pkt->len, nbytes);
> diff --git a/include/linux/virtio_vsock.h b/include/linux/virtio_vsock.h
> index da9e1fe..734eeed 100644
> --- a/include/linux/virtio_vsock.h
> +++ b/include/linux/virtio_vsock.h
> @@ -13,6 +13,8 @@
>  #define VIRTIO_VSOCK_DEFAULT_RX_BUF_SIZE (1024 * 4)
>  #define VIRTIO_VSOCK_MAX_BUF_SIZE0xUL
>  #define VIRTIO_VSOCK_MAX_PKT_BUF_SIZE(1024 * 64)
> +/* virtio_vsock_pkt + max_pkt_len(default MAX_PKT_BUF_SIZE) */
> +#define VIRTIO_VSOCK_MAX_VEC_NUM ((VIRTIO_VSOCK_MAX_PKT_BUF_SIZE / 
> PAGE_SIZE) + 1)
> 
>  /* Virtio-vsock feature */
>  #define VIRTIO_VSOCK_F_MRG_RXBUF 0 /* Host can merge receive buffers. */
> @@ -55,10 +57,12 @@ struct virtio_vsock_pkt {
>   struct list_head list;
>   /* socket refcnt not held, only use for cancellation */
>   struct vsock_sock *vsk;
> - void *buf;
> + struct kvec vec[VIRTIO_VSOCK_MAX_VEC_NUM];
> + int nr_vecs;
>   u32 len;
>   u32 off;
>   bool reply;
> + bool mergeable;
>  };
> 
>  struct virtio_vsock_pkt_info {
> diff --git a/net/vmw_vsock/virtio_transport.c 
> b/net/vmw_vsock/virtio_transport.c
> index c4a465c..148b58a 100644
> --- a/net/vmw_vsock/virtio_transport.c
> +++ b/net/vmw_vsock/virtio_transport.c
> @@ -155,8 +155,10 @@ static int virtio_transport_send_pkt_loopback(struct 
> virtio_vsock *vsock,
> 
>   sg_init_one(, >hdr, sizeof(pkt->hdr));
>   sgs[out_sg++] = 
> - if (pkt->buf) {
> - sg_init_one(, pkt->buf, pkt->len);
> + if (pkt->len) {
> + /* Currently only support a segment of memory in tx */
> +