Skip to content

Commit

Permalink
Add comment for virtqueue_add_outbuf
Browse files Browse the repository at this point in the history
  • Loading branch information
54shady committed Jul 27, 2023
1 parent 540fd9d commit 1bde99e
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions x86/crypto/virtio_mini.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,32 @@ static ssize_t virtio_mini_write(struct file* fil, const char *buf, size_t count
return ENOSPC;
}

/* 分配空间用于保存用户要发送的数据 */
to_send = kmalloc(count, GFP_KERNEL);
if (!to_send)
{
return 1;
}

/* 将用户的数据保存到to_send */
res = copy_from_user(to_send, buf, count);
if (res != 0) {
printk(KERN_INFO "Could not write %lu bytes!", res);
/* update count to actual number of bytes written */
count = count - res;
}

/*
* virtqueue中数据是存VirtQueueElement中的in_sg或out_sg散列中的
* 驱动中用对应的api来打包,这里virtqueue_add_outbuf
* 所以填充的out_sg
*
* 在设备中通过virtqueue_pop来获取到对应的VirtQueueElement后取出散列中的数据
* 1. 取出element
* vqe = virtqueue_pop(vq, sizeof(VirtQueueElement));
* 2. 取出element里的数据
* iov_to_buf(vqe->out_sg, vqe->out_num, 0, rcv_bufs, vqe->out_sg->iov_len);
*/
sg_init_one(&sg, to_send, count);
vmini->buf_lens[vmini->buffers++] = count;
virtqueue_add_outbuf(vq, &sg, 1, to_send, GFP_KERNEL);
Expand Down

0 comments on commit 1bde99e

Please sign in to comment.