shithub: riscv

Download patch

ref: 853049c3b9a3c84b6de4eaa5edab039c4d3df98c
parent: 543ccb37f47db89be6b6fe0e651f095897bbee08
author: aiju <devnull@localhost>
date: Mon Aug 28 13:19:13 EDT 2017

vmx(1): don't realloc virtio queues -- breaks pointers

--- a/sys/src/cmd/vmx/virtio.c
+++ b/sys/src/cmd/vmx/virtio.c
@@ -70,7 +70,7 @@
 	u16int qsel;
 	u8int devstat, isrstat;
 	VIOQueue *qu;
-	int nqu;
+	int nqu, allocqu;
 	u32int (*io)(int, u16int, u32int, int, VIODev *);
 	void (*reset)(VIODev *);
 	union {
@@ -360,7 +360,7 @@
 }
 
 VIODev *
-mkviodev(u16int devid, u32int pciclass, u32int subid)
+mkviodev(u16int devid, u32int pciclass, u32int subid, int queues)
 {
 	VIODev *d;
 	
@@ -368,6 +368,8 @@
 	d->pci = mkpcidev(allocbdf(), devid << 16 | 0x1AF4, pciclass << 8, 1);
 	d->pci->subid = subid << 16;
 	mkpcibar(d->pci, BARIO, 0, 256, vioio, d);
+	d->qu = emalloc(queues * sizeof(VIOQueue));
+	d->allocqu = queues;
 	return d;
 }
 
@@ -384,12 +386,8 @@
 {
 	VIOQueue *q;
 
-	assert(sz > 0 && sz <= 32768 && (sz & sz - 1) == 0 && fn != nil);
-	d->qu = realloc(d->qu, (d->nqu + 1) * sizeof(VIOQueue));
-	if(d->qu == nil)
-		sysfatal("realloc: %r");
+	assert(sz > 0 && sz <= 32768 && (sz & sz - 1) == 0 && fn != nil && d->nqu < d->allocqu);
 	q = d->qu + d->nqu++;
-	memset(q, 0, sizeof(VIOQueue));
 	q->Rendez.l = q;
 	q->livebufrend.l = q;
 	q->size = sz;
@@ -660,7 +658,7 @@
 		if(cfd >= 0) fprint(cfd, "promiscuous");
 	}
 	
-	d = mkviodev(0x1000, 0x020000, 1);
+	d = mkviodev(0x1000, 0x020000, 1, 3);
 	mkvioqueue(d, 1024, viowakeup);
 	mkvioqueue(d, 1024, viowakeup);
 	mkvioqueue(d, 32, vionetcmd);
@@ -767,7 +765,7 @@
 	
 	fd = open(fn, ORDWR);
 	if(fd < 0) return -1;
-	d = mkviodev(0x1000, 0x018000, 2);
+	d = mkviodev(0x1000, 0x018000, 2, 1);
 	mkvioqueue(d, 32, viowakeup);
 	d->io = vioblkio;
 	d->blk.fd = fd;