shithub: riscv

Download patch

ref: 48c5da7a64804bf649ff815c778064dfe8c59711
parent: 45411c31dc8d2e7a1b5d572acbca38581f01f242
author: aiju <devnull@localhost>
date: Mon Jun 12 07:25:12 EDT 2017

ethervirtio: report correct length; fail gracefully if we can't initialize queues

--- a/sys/src/9/pc/ethervirtio.c
+++ b/sys/src/9/pc/ethervirtio.c
@@ -324,7 +324,7 @@
 
 			blocks[i] = nil;
 
-			b->wp = b->rp + u->len;
+			b->wp = b->rp + u->len - VheaderSize;
 			etheriq(edev, b, 1);
 			q->lastused++;
 		}
@@ -591,12 +591,20 @@
 		for(i=0; i<nelem(c->queue); i++){
 			outs(c->port+Qselect, i);
 			n = ins(c->port+Qsize);
-			if(n == 0 || (n & (n-1)) != 0)
+			if(n == 0 || (n & (n-1)) != 0){
+				if(i < 2)
+					print("ethervirtio: queue %d has invalid size %d\n", i, n);
 				break;
+			}
 			if(initqueue(&c->queue[i], n) < 0)
 				break;
 			coherence();
 			outl(c->port+Qaddr, PADDR(c->queue[i].desc)/VBY2PG);
+		}
+		if(i < 2){
+			print("ethervirtio: no queues\n");
+			free(c);
+			continue;
 		}
 		c->nqueue = i;