Skip to contentSkip to conversation

nbd-client: enter read_reply_co during init to avoid crash

PATCH Superseded Stefan Hajnoczi 5 participants 15 messages Aug 24, 2017 – Aug 25, 2017 Block layer

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover nbd-client: enter read_reply_co during init to avoid crash

See Patch 1 for the segfault fix. Patches 2 & 3 add qemu-iotests coverage.

This is a rare crash that we'll probably only see in testing. It only seems to happen with UNIX domain sockets.

Stefan Hajnoczi (3):
nbd-client: enter read_reply_co during init to avoid crash
qemu-iotests: improve nbd-fault-injector.py startup protocol
qemu-iotests: test NBD over UNIX domain sockets in 083

 block/nbd-client.c                       |   2 +-
 tests/qemu-iotests/083                   | 138 ++++++++++++++++++-----------
 tests/qemu-iotests/083.out               | 145 +++++++++++++++++++++++++++----
 tests/qemu-iotests/common.filter         |   4 +-
 tests/qemu-iotests/nbd-fault-injector.py |   4 +
 5 files changed, 220 insertions(+), 73 deletions(-)
Signature · 1 line
2.13.5
#1 lore raw

PATCH 1/3 nbd-client: enter read_reply_co during init to avoid crash

The following segfault is encountered if the NBD server closes the UNIX domain socket immediately after negotiation:

Program terminated with signal SIGSEGV, Segmentation fault. #0 aio_co_schedule (ctx=0x0, co=0xd3c0ff2ef0) at util/async.c:441
441 QSLIST_INSERT_HEAD_ATOMIC(&ctx->scheduled_coroutines,
(gdb) bt

  #0  0x000000d3c01a50f8 in aio_co_schedule (ctx=0x0, co=0xd3c0ff2ef0) at util/async.c:441
  #1  0x000000d3c012fa90 in nbd_coroutine_end (bs=bs@entry=0xd3c0fec650, request=<optimized out>) at block/nbd-client.c:207
  #2  0x000000d3c012fb58 in nbd_client_co_preadv (bs=0xd3c0fec650, offset=0, bytes=<optimized out>, qiov=0x7ffc10a91b20, flags=0) at block/nbd-client.c:237
  #3  0x000000d3c0128e63 in bdrv_driver_preadv (bs=bs@entry=0xd3c0fec650, offset=offset@entry=0, bytes=bytes@entry=512, qiov=qiov@entry=0x7ffc10a91b20, flags=0) at block/io.c:836
  #4  0x000000d3c012c3e0 in bdrv_aligned_preadv (child=child@entry=0xd3c0ff51d0, req=req@entry=0x7f31885d6e90, offset=offset@entry=0, bytes=bytes@entry=512, align=align@entry=1, qiov=qiov@entry=0x7ffc10a91b20, flags=0) at block/io.c:1086
  #5  0x000000d3c012c6b8 in bdrv_co_preadv (child=0xd3c0ff51d0, offset=offset@entry=0, bytes=bytes@entry=512, qiov=qiov@entry=0x7ffc10a91b20, flags=flags@entry=0) at block/io.c:1182
  #6  0x000000d3c011cc17 in blk_co_preadv (blk=0xd3c0ff4f80, offset=0, bytes=512, qiov=0x7ffc10a91b20, flags=0) at block/block-backend.c:1032
  #7  0x000000d3c011ccec in blk_read_entry (opaque=0x7ffc10a91b40) at block/block-backend.c:1079
  #8  0x000000d3c01bbb96 in coroutine_trampoline (i0=<optimized out>, i1=<optimized out>) at util/coroutine-ucontext.c:79
  #9  0x00007f3196cb8600 in __start_context () at /lib64/libc.so.6

The problem is that nbd_client_init() uses nbd_client_attach_aio_context() -> aio_co_schedule(new_context, client->read_reply_co). Execution of read_reply_co is deferred to a BH which doesn't run until later.

In the mean time blk_co_preadv() can be called and nbd_coroutine_end() calls aio_wake() on read_reply_co. At this point in time read_reply_co's ctx isn't set because it has never been entered yet.

This patch enters read_reply_co directly in nbd_client_attach_aio_context(). This is safe because new_context is acquired by the caller. This ensures that read_reply_co reaches its first yield point and its ctx is set up.

Note this only happens with UNIX domain sockets on Linux. It doesn't seem possible to reproduce this with TCP sockets.

---
 block/nbd-client.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/nbd-client.c +1 -1
index 25bcaa2346..0a7f32779e 100644
@@ -371,7 +371,7 @@ void nbd_client_attach_aio_context(BlockDriverState *bs,
 {
     NBDClientSession *client = nbd_get_client_session(bs);
     qio_channel_attach_aio_context(QIO_CHANNEL(client->ioc), new_context);
-    aio_co_schedule(new_context, client->read_reply_co);
+    qemu_aio_coroutine_enter(new_context, client->read_reply_co);
 }
 
 void nbd_client_close(BlockDriverState *bs)
Signature · 1 line
2.13.5
#7 lore raw

PATCH 2/3 qemu-iotests: improve nbd-fault-injector.py startup protocol

In reply to Stefan Hajnoczi

Currently 083 waits for the nbd-fault-injector.py server to start up by looping until netstat shows the TCP listen socket.

The startup protocol can be simplified by passing a 0 port number to nbd-fault-injector.py. The kernel will allocate a port in bind(2) and the final port number can be printed by nbd-fault-injector.py.

This should make it slightly nicer and less TCP-specific to wait for server startup. This patch changes nbd-fault-injector.py, the next one will rewrite server startup in 083.

---
 tests/qemu-iotests/nbd-fault-injector.py | 4 ++++
 1 file changed, 4 insertions(+)
tests/qemu-iotests/nbd-fault-injector.py +4 -0
index 6c07191a5a..1c10dcb51c 100755
@@ -235,11 +235,15 @@ def open_socket(path):
         sock = socket.socket()
         sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
         sock.bind((host, int(port)))
+
+        # If given port was 0 the final port number is now available
+        path = '%s:%d' % sock.getsockname()
     else:
         sock = socket.socket(socket.AF_UNIX)
         sock.bind(path)
     sock.listen(0)
     print 'Listening on %s' % path
+    sys.stdout.flush() # another process may be waiting, show message now
     return sock
 
 def usage(args):
Signature · 1 line
2.13.5
#9 lore raw

PATCH 3/3 qemu-iotests: test NBD over UNIX domain sockets in 083

In reply to Stefan Hajnoczi

083 only tests TCP. Some failures might be specific to UNIX domain sockets.

A few adjustments are necessary:

1. Generating a port number and waiting for server startup is TCP-specific. Use the new nbd-fault-injector.py startup protocol to fetch the address. This is a little more elegant because we don't need netstat anymore.

2. The NBD filter does not work for the UNIX domain sockets URIs we generate and must be extended.

3. Run all tests twice: once for TCP and once for UNIX domain sockets.

---
 tests/qemu-iotests/083           | 138 +++++++++++++++++++++++--------------
 tests/qemu-iotests/083.out       | 145 ++++++++++++++++++++++++++++++++++-----
 tests/qemu-iotests/common.filter |   4 +-
 3 files changed, 215 insertions(+), 72 deletions(-)
tests/qemu-iotests/083 +85 -53
index bff9360048..0306f112da 100755
@@ -27,6 +27,14 @@ echo "QA output created by $seq"
 here=`pwd`
 status=1	# failure is the default!
 
+_cleanup()
+{
+	rm -f nbd.sock
+	rm -f nbd-fault-injector.out
+	rm -f nbd-fault-injector.conf
+}
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
 # get standard environment, filters and checks
 . ./common.rc
 . ./common.filter
@@ -35,81 +43,105 @@ _supported_fmt generic
 _supported_proto nbd
 _supported_os Linux
 
-# Pick a TCP port based on our pid.  This way multiple instances of this test
-# can run in parallel without conflicting.
-choose_tcp_port() {
-	echo $((($$ % 31744) + 1024)) # 1024 <= port < 32768
-}
-
-wait_for_tcp_port() {
-	while ! (netstat --tcp --listening --numeric | \
-		 grep "$1.*0\\.0\\.0\\.0:\\*.*LISTEN") >/dev/null 2>&1; do
-		sleep 0.1
-	done
-}
-
 check_disconnect() {
+	local event export_name=foo extra_args nbd_addr nbd_url proto when
+
+	while true; do
+		case $1 in
+		--classic-negotiation)
+			shift
+			extra_args=--classic-negotiation
+			export_name=
+			;;
+		--tcp)
+			shift
+			proto=tcp
+			;;
+		--unix)
+			shift
+			proto=unix
+			;;
+		*)
+			break
+			;;
+		esac
+	done
+
 	event=$1
 	when=$2
-	negotiation=$3
 	echo "=== Check disconnect $when $event ==="
 	echo
 
-	port=$(choose_tcp_port)
-
 	cat > "$TEST_DIR/nbd-fault-injector.conf" <<EOF
 [inject-error]
 event=$event
 when=$when
 EOF
 
-	if [ "$negotiation" = "--classic-negotiation" ]; then
-		extra_args=--classic-negotiation
-		nbd_url="nbd:127.0.0.1:$port"
+	if [ "$proto" = "tcp" ]; then
+		nbd_addr="127.0.0.1:0"
 	else
-		nbd_url="nbd:127.0.0.1:$port:exportname=foo"
+		nbd_addr="$TEST_DIR/nbd.sock"
+	fi
+
+	rm -f "$TEST_DIR/nbd.sock"
+
+	$PYTHON nbd-fault-injector.py $extra_args "$nbd_addr" "$TEST_DIR/nbd-fault-injector.conf" >"$TEST_DIR/nbd-fault-injector.out" 2>&1 &
+
+	# Wait for server to be ready
+	while ! grep -q 'Listening on ' "$TEST_DIR/nbd-fault-injector.out"; do
+		sleep 0.1
+	done
+
+	# Extract the final address (port number has now been assigned in tcp case)
+	nbd_addr=$(sed 's/Listening on \(.*\)$/\1/' "$TEST_DIR/nbd-fault-injector.out")
+
+	if [ "$proto" = "tcp" ]; then
+		nbd_url="nbd+tcp://$nbd_addr/$export_name"
+	else
+		nbd_url="nbd+unix:///$export_name?socket=$nbd_addr"
 	fi
 
-	$PYTHON nbd-fault-injector.py $extra_args "127.0.0.1:$port" "$TEST_DIR/nbd-fault-injector.conf" >/dev/null 2>&1 &
-	wait_for_tcp_port "127\\.0\\.0\\.1:$port"
 	$QEMU_IO -c "read 0 512" "$nbd_url" 2>&1 | _filter_qemu_io | _filter_nbd
 
 	echo
 }
 
-for event in neg1 "export" neg2 request reply data; do
-	for when in before after; do
-		check_disconnect "$event" "$when"
-	done
-
-	# Also inject short replies from the NBD server
-	case "$event" in
-	neg1)
-		for when in 8 16; do
-			check_disconnect "$event" "$when"
-		done
-		;;
-	"export")
-		for when in 4 12 16; do
-			check_disconnect "$event" "$when"
-		done
-		;;
-	neg2)
-		for when in 8 10; do
-			check_disconnect "$event" "$when"
+for proto in tcp unix; do
+	for event in neg1 "export" neg2 request reply data; do
+		for when in before after; do
+			check_disconnect "--$proto" "$event" "$when"
 		done
-		;;
-	reply)
-		for when in 4 8; do
-			check_disconnect "$event" "$when"
-		done
-		;;
-	esac
-done
 
-# Also check classic negotiation without export information
-for when in before 8 16 24 28 after; do
-	check_disconnect "neg-classic" "$when" --classic-negotiation
+		# Also inject short replies from the NBD server
+		case "$event" in
+		neg1)
+			for when in 8 16; do
+				check_disconnect "--$proto" "$event" "$when"
+			done
+			;;
+		"export")
+			for when in 4 12 16; do
+				check_disconnect "--$proto" "$event" "$when"
+			done
+			;;
+		neg2)
+			for when in 8 10; do
+				check_disconnect "--$proto" "$event" "$when"
+			done
+			;;
+		reply)
+			for when in 4 8; do
+				check_disconnect "--$proto" "$event" "$when"
+			done
+			;;
+		esac
+	done
+
+	# Also check classic negotiation without export information
+	for when in before 8 16 24 28 after; do
+		check_disconnect "--$proto" --classic-negotiation "neg-classic" "$when"
+	done
 done
 
 # success, all done
tests/qemu-iotests/083.out +128 -17

205 lines not on this page · raw message

tests/qemu-iotests/common.filter +2 -2
index 7a58e57317..9d5442ecd9 100644
@@ -170,9 +170,9 @@ _filter_nbd()
     #
     # Filter out the TCP port number since this changes between runs.
     sed -e '/nbd\/.*\.c:/d' \
-        -e 's#nbd:\(//\)\?127\.0\.0\.1:[0-9]*#nbd:\1127.0.0.1:PORT#g' \
+        -e 's#127\.0\.0\.1:[0-9]*#127.0.0.1:PORT#g' \
         -e "s#?socket=$TEST_DIR#?socket=TEST_DIR#g" \
-        -e 's#\(exportname=foo\|PORT\): Failed to .*$#\1#'
+        -e 's#\(foo\|PORT/\?\|.sock\): Failed to .*$#\1#'
 }
 
 # make sure this script returns success
Signature · 1 line
2.13.5
#11 lore raw
In reply to Stefan Hajnoczi
Quoted 4 lines · Stefan Hajnoczi

See Patch 1 for the segfault fix. Patches 2 & 3 add qemu-iotests coverage.

This is a rare crash that we'll probably only see in testing. It only seems to happen with UNIX domain sockets.

Rare enough that I don't think it is 2.10-rc4 material. I'll review, and if I don't find anything needing a respin, I'll add it to my NBD queue for 2.11.

Quoted 13 lines

Stefan Hajnoczi (3):
nbd-client: enter read_reply_co during init to avoid crash
qemu-iotests: improve nbd-fault-injector.py startup protocol
qemu-iotests: test NBD over UNIX domain sockets in 083

 block/nbd-client.c                       |   2 +-
 tests/qemu-iotests/083                   | 138 ++++++++++++++++++-----------
 tests/qemu-iotests/083.out               | 145 +++++++++++++++++++++++++++----
 tests/qemu-iotests/common.filter         |   4 +-
 tests/qemu-iotests/nbd-fault-injector.py |   4 +
 5 files changed, 220 insertions(+), 73 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
#12 lore raw
Quoted 9 lines · Eric Blake
Quoted 4 lines · Stefan Hajnoczi

See Patch 1 for the segfault fix. Patches 2 & 3 add qemu-iotests coverage.

This is a rare crash that we'll probably only see in testing. It only seems to happen with UNIX domain sockets.

Rare enough that I don't think it is 2.10-rc4 material. I'll review, and if I don't find anything needing a respin, I'll add it to my NBD queue for 2.11.

Great. This is 2.11 material.

Stefan

#2 lore raw
In reply to Stefan Hajnoczi
Quoted 4 lines · Stefan Hajnoczi

This patch enters read_reply_co directly in nbd_client_attach_aio_context(). This is safe because new_context is acquired by the caller. This ensures that read_reply_co reaches its first yield point and its ctx is set up.

I'm not very confident with this patch. aio_context_acquire/release is going to go away, and this then becomes possible

main context new_context
qemu_aio_coroutine_enter
send request wait for reply
read first reply
wake coroutine

where the "wake coroutine" part thinks it's running in new_context, and thus simply enters the coroutine instead of using the bottom half.

But blk_co_preadv() should need the read_reply_co itself, in order to be woken up after reading the reply header. The core issue here is that nbd_co_receive_reply was never called, I suspect. And if it was never called, read_reply_co should not be woken up by nbd_coroutine_end.

So the fix is:

1) assign NULL to s->recv_coroutine[i] when nbd_co_send_request fails

2) move this to nbd_co_receive_reply:

    s->recv_coroutine[i] = NULL;

    /* Kick the read_reply_co to get the next reply.  */
    if (s->read_reply_co) {
        aio_co_wake(s->read_reply_co);
    }

Does this make sense? (Note that the read_reply_co idea actually came from you, or from my recollections of your proposed design :)).

Paolo

Quoted 20 lines

Note this only happens with UNIX domain sockets on Linux. It doesn't seem possible to reproduce this with TCP sockets.

---
 block/nbd-client.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/nbd-client.c +1 -1
index 25bcaa2346..0a7f32779e 100644
@@ -371,7 +371,7 @@ void nbd_client_attach_aio_context(BlockDriverState *bs,
 {
     NBDClientSession *client = nbd_get_client_session(bs);
     qio_channel_attach_aio_context(QIO_CHANNEL(client->ioc), new_context);
-    aio_co_schedule(new_context, client->read_reply_co);
+    qemu_aio_coroutine_enter(new_context, client->read_reply_co);
 }
#3 lore raw
Quoted 37 lines · Paolo Bonzini
Quoted 4 lines · Stefan Hajnoczi

This patch enters read_reply_co directly in nbd_client_attach_aio_context(). This is safe because new_context is acquired by the caller. This ensures that read_reply_co reaches its first yield point and its ctx is set up.

I'm not very confident with this patch. aio_context_acquire/release is going to go away, and this then becomes possible

main context new_context
qemu_aio_coroutine_enter
send request wait for reply
read first reply
wake coroutine

where the "wake coroutine" part thinks it's running in new_context, and thus simply enters the coroutine instead of using the bottom half.

But blk_co_preadv() should need the read_reply_co itself, in order to be woken up after reading the reply header. The core issue here is that nbd_co_receive_reply was never called, I suspect. And if it was never called, read_reply_co should not be woken up by nbd_coroutine_end.

So the fix is:

1) assign NULL to s->recv_coroutine[i] when nbd_co_send_request fails

2) move this to nbd_co_receive_reply:

    s->recv_coroutine[i] = NULL;

    /* Kick the read_reply_co to get the next reply.  */
    if (s->read_reply_co) {
        aio_co_wake(s->read_reply_co);
    }
Quoted 2 lines

Does this make sense? (Note that the read_reply_co idea actually came from you, or from my recollections of your proposed design :)).

How much of this overlaps with Vladimir's proposal?
https://lists.gnu.org/archive/html/qemu-devel/2017-08/msg00846.html

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
Reviewed-by on v1 2/3
#8 lore raw

Re: [Qemu-devel] [PATCH 2/3] qemu-iotests: improve nbd-fault-injector.py startup protocol

In reply to Stefan Hajnoczi
Quoted 7 lines · Stefan Hajnoczi

Currently 083 waits for the nbd-fault-injector.py server to start up by looping until netstat shows the TCP listen socket.

The startup protocol can be simplified by passing a 0 port number to nbd-fault-injector.py. The kernel will allocate a port in bind(2) and the final port number can be printed by nbd-fault-injector.py.

Quoted 8 lines

This should make it slightly nicer and less TCP-specific to wait for server startup. This patch changes nbd-fault-injector.py, the next one will rewrite server startup in 083.

---
 tests/qemu-iotests/nbd-fault-injector.py | 4 ++++
 1 file changed, 4 insertions(+)
Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
#4 lore raw
In reply to Eric Blake
Quoted 38 lines · Eric Blake
Quoted 37 lines · Paolo Bonzini
Quoted 4 lines · Stefan Hajnoczi

This patch enters read_reply_co directly in nbd_client_attach_aio_context(). This is safe because new_context is acquired by the caller. This ensures that read_reply_co reaches its first yield point and its ctx is set up.

I'm not very confident with this patch. aio_context_acquire/release is going to go away, and this then becomes possible

main context new_context
qemu_aio_coroutine_enter
send request wait for reply
read first reply
wake coroutine

where the "wake coroutine" part thinks it's running in new_context, and thus simply enters the coroutine instead of using the bottom half.

But blk_co_preadv() should need the read_reply_co itself, in order to be woken up after reading the reply header. The core issue here is that nbd_co_receive_reply was never called, I suspect. And if it was never called, read_reply_co should not be woken up by nbd_coroutine_end.

So the fix is:

1) assign NULL to s->recv_coroutine[i] when nbd_co_send_request fails

2) move this to nbd_co_receive_reply:

    s->recv_coroutine[i] = NULL;

    /* Kick the read_reply_co to get the next reply.  */
    if (s->read_reply_co) {
        aio_co_wake(s->read_reply_co);
    }
Quoted 5 lines
Quoted 2 lines

Does this make sense? (Note that the read_reply_co idea actually came from you, or from my recollections of your proposed design :)).

How much of this overlaps with Vladimir's proposal?
https://lists.gnu.org/archive/html/qemu-devel/2017-08/msg00846.html

The above should be about 15 lines added, 10 removed. :)

Paolo

Reviewed-by on v1 3/3
#10 lore raw

Re: [Qemu-devel] [PATCH 3/3] qemu-iotests: test NBD over UNIX domain sockets in 083

In reply to Stefan Hajnoczi
Quoted 13 lines · Stefan Hajnoczi

083 only tests TCP. Some failures might be specific to UNIX domain sockets.

A few adjustments are necessary:

1. Generating a port number and waiting for server startup is TCP-specific. Use the new nbd-fault-injector.py startup protocol to fetch the address. This is a little more elegant because we don't need netstat anymore.

2. The NBD filter does not work for the UNIX domain sockets URIs we generate and must be extended.

Quoted 8 lines

3. Run all tests twice: once for TCP and once for UNIX domain sockets.

---
 tests/qemu-iotests/083           | 138 +++++++++++++++++++++++--------------
 tests/qemu-iotests/083.out       | 145 ++++++++++++++++++++++++++++++++++-----
 tests/qemu-iotests/common.filter |   4 +-
 3 files changed, 215 insertions(+), 72 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
#6 lore raw
In reply to Paolo Bonzini
Quoted 37 lines · Paolo Bonzini
Quoted 4 lines · Stefan Hajnoczi

This patch enters read_reply_co directly in nbd_client_attach_aio_context(). This is safe because new_context is acquired by the caller. This ensures that read_reply_co reaches its first yield point and its ctx is set up.

I'm not very confident with this patch. aio_context_acquire/release is going to go away, and this then becomes possible

main context new_context
qemu_aio_coroutine_enter
send request wait for reply
read first reply
wake coroutine

where the "wake coroutine" part thinks it's running in new_context, and thus simply enters the coroutine instead of using the bottom half.

But blk_co_preadv() should need the read_reply_co itself, in order to be woken up after reading the reply header. The core issue here is that nbd_co_receive_reply was never called, I suspect. And if it was never called, read_reply_co should not be woken up by nbd_coroutine_end.

So the fix is:

1) assign NULL to s->recv_coroutine[i] when nbd_co_send_request fails

2) move this to nbd_co_receive_reply:

    s->recv_coroutine[i] = NULL;

    /* Kick the read_reply_co to get the next reply.  */
    if (s->read_reply_co) {
        aio_co_wake(s->read_reply_co);
    }
Quoted 2 lines

Does this make sense? (Note that the read_reply_co idea actually came from you, or from my recollections of your proposed design :)).

Yes, I think that would work.

Stefan

#13 lore raw
In reply to Stefan Hajnoczi
Quoted 4 lines · Stefan Hajnoczi
Quoted 3 lines · Eric Blake
Quoted 2 lines · Stefan Hajnoczi

See Patch 1 for the segfault fix. Patches 2 & 3 add qemu-iotests coverage.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

This is a rare crash that we'll probably only see in testing. It only seems to happen with UNIX domain sockets.

Rare enough that I don't think it is 2.10-rc4 material. I'll review, and if I don't find anything needing a respin, I'll add it to my NBD queue for 2.11.

Great. This is 2.11 material.

Hmm - I wonder if https://bugs.launchpad.net/qemu/+bug/1712818 is related to this. I really don't want to delay 2.10 further (downstream distros can backport fixes) - but comment 3 stating that crashes are less frequent but still possible with -rc4 is not good.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
#5 lore raw
In reply to Paolo Bonzini
Quoted 38 lines · Paolo Bonzini
Quoted 37 lines · Eric Blake
Quoted 36 lines · Paolo Bonzini
Quoted 4 lines · Stefan Hajnoczi

This patch enters read_reply_co directly in nbd_client_attach_aio_context(). This is safe because new_context is acquired by the caller. This ensures that read_reply_co reaches its first yield point and its ctx is set up.

I'm not very confident with this patch. aio_context_acquire/release is going to go away, and this then becomes possible

main context new_context
qemu_aio_coroutine_enter
send request wait for reply
read first reply
wake coroutine

where the "wake coroutine" part thinks it's running in new_context, and thus simply enters the coroutine instead of using the bottom half.

But blk_co_preadv() should need the read_reply_co itself, in order to be woken up after reading the reply header. The core issue here is that nbd_co_receive_reply was never called, I suspect. And if it was never called, read_reply_co should not be woken up by nbd_coroutine_end.

So the fix is:

1) assign NULL to s->recv_coroutine[i] when nbd_co_send_request fails

2) move this to nbd_co_receive_reply:

     s->recv_coroutine[i] = NULL;

     /* Kick the read_reply_co to get the next reply.  */
     if (s->read_reply_co) {
         aio_co_wake(s->read_reply_co);
     }
Quoted 9 lines
Quoted 4 lines
Quoted 2 lines

Does this make sense? (Note that the read_reply_co idea actually came from you, or from my recollections of your proposed design :)).

How much of this overlaps with Vladimir's proposal?
https://lists.gnu.org/archive/html/qemu-devel/2017-08/msg00846.html

The above should be about 15 lines added, 10 removed. :)

Paolo

I'll be on vocation for the next two weeks and will continue this work after it.

I think we have a lot of conflicts already with my series after different fixes,

so I'll rebase on them all, no problem.

PS: I think recent problems and bugs in nbd are related to not very good separation between

block/nbd-client.c and nbd/client.c. Ideally, I think, block/nbd-client should not

directly access the ioc, it should just call one or two high level functions of

nbd/client. The big problem of this separation is CMD_READ reply - only real client

knows, should we read a payload or not. I have two ideas on it:

1. We can add this information to request handle, then nbd/client will now by handle,

  that it should read the payload.. The length of payload should be in handle too. It looks

 possible, as handle is 64bit when request len is 32bit.

2. Move part of NBDClientSession to nbd/client, with NBDClientRequest requests[MAX_NBD_REQUESTS];

  to nbd/client, to implement one public function nbd_request(state, *request, *reply), which will do all the

 work for block/nbd-client..

Signature · 2 lines
Best regards,
Vladimir
#14 lore raw
In reply to Eric Blake
Quoted 12 lines · Eric Blake
Quoted 11 lines · Stefan Hajnoczi
Quoted 9 lines · Eric Blake
Quoted 4 lines · Stefan Hajnoczi

See Patch 1 for the segfault fix. Patches 2 & 3 add qemu-iotests coverage.

This is a rare crash that we'll probably only see in testing. It only seems to happen with UNIX domain sockets.

Rare enough that I don't think it is 2.10-rc4 material. I'll review, and if I don't find anything needing a respin, I'll add it to my NBD queue for 2.11.

Quoted 6 lines
Quoted 1 line

Great. This is 2.11 material.

Hmm - I wonder if https://bugs.launchpad.net/qemu/+bug/1712818 is related to this. I really don't want to delay 2.10 further (downstream distros can backport fixes) - but comment 3 stating that crashes are less frequent but still possible with -rc4 is not good.

Well, I won't be able to review or write the patch, so I think it's better to wait.

Paolo