[SeaBIOS] [PATCH 4/4] virtio: Allocate drive_s storage in low memory

Kevin O'Connor kevin at koconnor.net
Tue Jul 11 18:50:32 CEST 2017


Use the "low" memory segment instead of the f-segment for the drive_s
storage.  This can help avoid running out of memory in the f-segment.

Signed-off-by: Kevin O'Connor <kevin at koconnor.net>
---
 src/hw/virtio-blk.c  | 12 ++++++------
 src/hw/virtio-ring.c |  1 -
 src/hw/virtio-scsi.c |  3 +--
 3 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/src/hw/virtio-blk.c b/src/hw/virtio-blk.c
index ad16200..88d7e54 100644
--- a/src/hw/virtio-blk.c
+++ b/src/hw/virtio-blk.c
@@ -32,9 +32,9 @@ struct virtiodrive_s {
 static int
 virtio_blk_op(struct disk_op_s *op, int write)
 {
-    struct virtiodrive_s *vdrive_gf =
+    struct virtiodrive_s *vdrive =
         container_of(op->drive_fl, struct virtiodrive_s, drive);
-    struct vring_virtqueue *vq = vdrive_gf->vq;
+    struct vring_virtqueue *vq = vdrive->vq;
     struct virtio_blk_outhdr hdr = {
         .type = write ? VIRTIO_BLK_T_OUT : VIRTIO_BLK_T_IN,
         .ioprio = 0,
@@ -48,7 +48,7 @@ virtio_blk_op(struct disk_op_s *op, int write)
         },
         {
             .addr       = op->buf_fl,
-            .length     = vdrive_gf->drive.blksize * op->count,
+            .length     = vdrive->drive.blksize * op->count,
         },
         {
             .addr       = (void*)(&status),
@@ -61,7 +61,7 @@ virtio_blk_op(struct disk_op_s *op, int write)
         vring_add_buf(vq, sg, 2, 1, 0, 0);
     else
         vring_add_buf(vq, sg, 1, 2, 0, 0);
-    vring_kick(&vdrive_gf->vp, vq, 1);
+    vring_kick(&vdrive->vp, vq, 1);
 
     /* Wait for reply */
     while (!vring_more_used(vq))
@@ -73,7 +73,7 @@ virtio_blk_op(struct disk_op_s *op, int write)
     /* Clear interrupt status register.  Avoid leaving interrupts stuck if
      * VRING_AVAIL_F_NO_INTERRUPT was ignored and interrupts were raised.
      */
-    vp_get_isr(&vdrive_gf->vp);
+    vp_get_isr(&vdrive->vp);
 
     return status == VIRTIO_BLK_S_OK ? DISK_RET_SUCCESS : DISK_RET_EBADTRACK;
 }
@@ -99,7 +99,7 @@ init_virtio_blk(void *data)
     struct pci_device *pci = data;
     u8 status = VIRTIO_CONFIG_S_ACKNOWLEDGE | VIRTIO_CONFIG_S_DRIVER;
     dprintf(1, "found virtio-blk at %pP\n", pci);
-    struct virtiodrive_s *vdrive = malloc_fseg(sizeof(*vdrive));
+    struct virtiodrive_s *vdrive = malloc_low(sizeof(*vdrive));
     if (!vdrive) {
         warn_noalloc();
         return;
diff --git a/src/hw/virtio-ring.c b/src/hw/virtio-ring.c
index 7205a0a..0ed3189 100644
--- a/src/hw/virtio-ring.c
+++ b/src/hw/virtio-ring.c
@@ -16,7 +16,6 @@
  *
  */
 
-#include "biosvar.h" // GET_GLOBAL
 #include "output.h" // panic
 #include "virtio-ring.h"
 #include "virtio-pci.h"
diff --git a/src/hw/virtio-scsi.c b/src/hw/virtio-scsi.c
index 466b305..a87cad8 100644
--- a/src/hw/virtio-scsi.c
+++ b/src/hw/virtio-scsi.c
@@ -7,7 +7,6 @@
 //
 // This file may be distributed under the terms of the GNU LGPLv3 license.
 
-#include "biosvar.h" // GET_GLOBALFLAT
 #include "block.h" // struct drive_s
 #include "blockcmd.h" // scsi_drive_setup
 #include "config.h" // CONFIG_*
@@ -114,7 +113,7 @@ virtio_scsi_add_lun(u32 lun, struct drive_s *tmpl_drv)
 {
     struct virtio_lun_s *tmpl_vlun =
         container_of(tmpl_drv, struct virtio_lun_s, drive);
-    struct virtio_lun_s *vlun = malloc_fseg(sizeof(*vlun));
+    struct virtio_lun_s *vlun = malloc_low(sizeof(*vlun));
     if (!vlun) {
         warn_noalloc();
         return -1;
-- 
2.9.4




More information about the SeaBIOS mailing list