CV-Bowen commented on code in PR #21408:
URL: https://github.com/apache/nuttx/pull/21408#discussion_r4470605712
##########
drivers/virtio/virtio.c:
##########
@@ -356,3 +359,108 @@ int virtio_unregister_device(FAR struct virtio_device
*device)
nxmutex_unlock(&g_virtio_bus.lock);
return ret;
}
+
+#ifdef CONFIG_ARCH_ADDRENV
+
+/****************************************************************************
+ * Name: virtio_addrenv_free_largest
+ *
+ * Description:
+ * Return the largest buffer virtio_addrenv_map() can bounce, for a
+ * transport whose device reaches guest physical memory directly.
+ *
+ * Input Parameters:
+ * vdev - The virtio device
+ *
+ * Returned Value:
+ * The largest mappable length in bytes.
+ *
+ ****************************************************************************/
+
+size_t virtio_addrenv_free_largest(FAR struct virtio_device *vdev)
+{
+ struct mallinfo info = kmm_mallinfo();
+
+ /* mxordblk counts the chunk header kmm_malloc() needs as well. */
+
+ return info.mxordblk > 64 ? info.mxordblk - 64 : 0;
+}
+
+/****************************************************************************
+ * Name: virtio_addrenv_map
+ *
+ * Description:
+ * Map a buffer for a transport whose device reaches guest physical memory
+ * directly. A user address is only virtually contiguous, while the device
+ * accesses len bytes from the physical address of its first byte, so it
+ * is bounced through the kernel heap. A kernel address is linearly
+ * mapped and used as is.
+ *
+ * Input Parameters:
+ * vdev - The virtio device
+ * buf - The buffer to map
+ * len - The buffer length in bytes
+ * dir - The transfer direction
+ *
+ * Returned Value:
+ * The address to give the device, or NULL when out of memory.
+ *
+ ****************************************************************************/
+
+FAR void *virtio_addrenv_map(FAR struct virtio_device *vdev, FAR void *buf,
+ size_t len, enum virtio_dma_map dir)
+{
+ FAR void *bounce;
+
+ if (!up_addrenv_user_vaddr((uintptr_t)buf))
+ {
+ return buf;
+ }
+
+ bounce = kmm_malloc(len);
Review Comment:
Fixed without clearing: virtio_blk_rdwr_one() now unmaps resp first and
unmaps the data with length 0 when the request failed, so a bounce copies
nothing back. With blkdebug failing reads, read() of 4096 bytes returns EIO and
changes 0 bytes (1931af4f1ef changed 4096). rptun_map_buf() needs no memset for
the same reason.
##########
drivers/virtio/virtio.c:
##########
@@ -356,3 +359,108 @@ int virtio_unregister_device(FAR struct virtio_device
*device)
nxmutex_unlock(&g_virtio_bus.lock);
return ret;
}
+
+#ifdef CONFIG_ARCH_ADDRENV
+
+/****************************************************************************
+ * Name: virtio_addrenv_free_largest
+ *
+ * Description:
+ * Return the largest buffer virtio_addrenv_map() can bounce, for a
+ * transport whose device reaches guest physical memory directly.
+ *
+ * Input Parameters:
+ * vdev - The virtio device
+ *
+ * Returned Value:
+ * The largest mappable length in bytes.
+ *
+ ****************************************************************************/
+
+size_t virtio_addrenv_free_largest(FAR struct virtio_device *vdev)
+{
+ struct mallinfo info = kmm_mallinfo();
+
+ /* mxordblk counts the chunk header kmm_malloc() needs as well. */
+
+ return info.mxordblk > 64 ? info.mxordblk - 64 : 0;
Review Comment:
Fixed: virtio_addrenv_free_largest() returns a fixed 64 KiB and does not
touch the heap.
##########
drivers/virtio/virtio-blk.c:
##########
@@ -147,62 +151,123 @@ static void virtio_blk_wait_complete(FAR struct
virtqueue *vq,
}
/****************************************************************************
- * Name: virtio_blk_rdwr
+ * Name: virtio_blk_rdwr_one
*
* Description:
- * Common function for read and write
+ * Transfer a single chunk, sized to the shared memory a bounce transport
+ * can map at once. Map req/data/resp, submit, wait, then unmap.
+ *
+ * Returned Value:
+ * The number of sectors transferred (> 0) on success, 0 when the shared
+ * memory cannot hold even one sector this round, or a negated errno on
Review Comment:
Fixed: updated the comments in virtio-blk.c and virtio-rng.c.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]