shithub: riscv

Download patch

ref: ad5c6c0dfabd5feb39a85eec7c95a703c91feabe
parent: 0bf1028ead0432d814276ef4341943f4d5cb184d
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sat Mar 30 15:26:20 EDT 2024

qio: fix deadlock with qdiscard()

Both qflush() and qdiscard() appear to
be interrupt level, and must not call
the kick routine of the queue, see
the deadlock in tcp:

0xffffffff80f2fb10 304: loopbackread cinap_lenrek pc 0xffffffff8019a053 kproc (Queueing) ut 0 st 1959 qpc 0xffffffff8014f98e
gotolabel()+0x0 /sys/src/9/pc64/l.s:573
procswitch()+0x50 /sys/src/9/port/proc.c:161
sched()+0xed /sys/src/9/port/proc.c:214
qlock(q=0xffffffff8283ab48)+0x14f /sys/src/9/port/qlock.c:108
tcpkick()+0x5a /sys/src/9/ip/tcp.c:593
iunlock_reader(q=0xffffffff820d1e48)+0x3b /sys/src/9/port/qio.c:480
qdiscard(q=0xffffffff820d1e48,len=0xffffffff00000001)+0x53 /sys/src/9/port/qio.c:1188
update(seg=0xffffffff80f2f968,s=0xffffffff8283ab48)+0x16b /sys/src/9/ip/tcp.c:2032
tcpiput(tcp=0xffffffff809ea2b8,bp=0xffffffff823150c8,ifc=0xffffffff80f39850)+0x1107 /sys/src/9/ip/tcp.c:2387
ipmuxiput(bp=0xffffffff823150c8,ifc=0xffffffff80f39850)+0xa6 /sys/src/9/ip/ipmux.c:765
ipiput4(bp=0xffffffff823150c8,ifc=0xffffffff80f39850,f=0xffffffff809ef7f8)+0x5d9 /sys/src/9/ip/ip.c:408
loopbackread()+0x100 /sys/src/9/ip/loopbackmedium.c:100
linkproc()+0x19 /sys/src/9/port/proc.c:1569

--- a/sys/src/9/port/qio.c
+++ b/sys/src/9/port/qio.c
@@ -1183,7 +1183,7 @@
 		}
 		q->dlen -= n;
 	}
-	iunlock_reader(q);
+	iunlock_consumer(q);
 
 	freeblist(tofree);
 
@@ -1203,7 +1203,7 @@
 	q->bfirst = nil;
 	q->rp = q->wp;
 	q->dlen = 0;
-	iunlock_reader(q);
+	iunlock_consumer(q);
 
 	freeblist(tofree);
 }