From nobody Mon Feb 9 02:02:30 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1560173900; cv=none; d=zoho.com; s=zohoarc; b=SCo8Ou4PA5G8SLVLlFwc4OurWgYha65dmbB1cOQiE5sE0anvpLSlw3Qvg2AsJIUKmhp8k+oZzzRRtrC/OcWb1LHIr01AL1eKC7KShC5IEKp98AuHGWmIkm8cRPlPnjvC/ZzJ7rBDD6M9fkIbH7UyvOP36KZ4qxrAZqts9VDKgu4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560173900; h=Content-Type:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=r/1cPRkx5WVDQ+ZoQ0X1XLrgK8zjs1Twb2lBlpg4x3I=; b=DXKoBKY/vUoqHvT/rQfNrUWxGfBx6J5ErE5oHCUkuBymFgCGAuTYNWMOXgsIzgJ361G5FDRN98WUWv5VTuqrk6BaRE0Two+prB5HrT5WtAkjAMr7WQknwhiDnChDi5ZYbz/+Vq4/McN8rCZA2RB3Y8o3mfEDHuPOMHAZ0Es9h+w= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1560173900546136.97388904830916; Mon, 10 Jun 2019 06:38:20 -0700 (PDT) Received: from localhost ([::1]:46566 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1haKV9-0000mp-AI for importer@patchew.org; Mon, 10 Jun 2019 09:38:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47396) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1haKSj-0007TR-46 for qemu-devel@nongnu.org; Mon, 10 Jun 2019 09:35:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1haKSh-0000QF-Lm for qemu-devel@nongnu.org; Mon, 10 Jun 2019 09:35:49 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:2174 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1haKSL-00008R-Bh; Mon, 10 Jun 2019 09:35:30 -0400 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 7358E5FE7A8A56D645A7; Mon, 10 Jun 2019 21:35:14 +0800 (CST) Received: from HGHY1l002846723.china.huawei.com (10.177.251.193) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.439.0; Mon, 10 Jun 2019 21:35:07 +0800 From: Zhengui li To: , , , Date: Mon, 10 Jun 2019 21:34:44 +0800 Message-ID: <1560173684-6264-1-git-send-email-lizhengui@huawei.com> X-Mailer: git-send-email 2.7.2.windows.1 MIME-Version: 1.0 X-Originating-IP: [10.177.251.193] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 45.249.212.190 Subject: [Qemu-devel] [PATCH] file-posix: unlock qemu_global_mutex before pread when attach disk X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lizhengui@huawei.com, qemu-block@nongnu.org, eric.fangyi@huawei.com, qemu-devel@nongnu.org, jiangyiwen@huawei.com, wangjie88@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" virtual machine cpu soft lockup when attach a disk to the vm in the case that backend storage network has a large delay or IO pressure is too large. The bt of qemu main thread: #0 0x0000ffff9d78402c in pread64 () from /lib64/libpthread.so.0 #1 0x0000aaaace3357d8 in pread64 (__offset=3D0, __nbytes=3D4096, __buf=3D0x= aaaad47a5200, __fd=3D202) at /usr/include/bits/unistd.h:99 #2 raw_is_io_aligned (fd=3Dfd@entry=3D202, buf=3Dbuf@entry=3D0xaaaad47a5200= , len=3Dlen@entry=3D4096) at block/raw_posix.c:294 #3 0x0000aaaace33597c in raw_probe_alignment (bs=3Dbs@entry=3D0xaaaad32ea92= 0, fd=3D202, errp=3Derrp@entry=3D0xfffffef7a330) at block/raw_posix.c:349 #4 0x0000aaaace335a48 in raw_refresh_limits (bs=3D0xaaaad32ea920, errp=3D0x= fffffef7a330) at block/raw_posix.c:811 #5 0x0000aaaace3404b0 in bdrv_refresh_limits (bs=3D0xaaaad32ea920, errp=3D0= xfffffef7a330, errp@entry=3D0xfffffef7a360) at block/io.c:122 #6 0x0000aaaace340504 in bdrv_refresh_limits (bs=3Dbs@entry=3D0xaaaad09ce80= 0, errp=3Derrp@entry=3D0xfffffef7a3b0) at block/io.c:97 #7 0x0000aaaace2eb9f0 in bdrv_open_common (bs=3Dbs@entry=3D0xaaaad09ce800, = file=3Dfile@entry=3D0xaaaad0e89800, options=3D, errp=3Derrp@= entry=3D0xfffffef7a450) at block.c:1194 #8 0x0000aaaace2eedec in bdrv_open_inherit (filename=3D, fil= ename@entry=3D0xaaaad25f92d0 "/dev/mapper/36384c4f100630193359db7a80000011d= ", reference=3Dreference@entry=3D0x0, options=3D, options@entry= =3D0xaaaad3d0f4b0, flags=3D, flags@entry=3D128, parent=3Dpar= ent@entry=3D0x0, child_role=3Dchild_role@entry=3D0x0, errp=3Derrp@entry=3D0xfffffef7a710) at= block.c:1895 #9 0x0000aaaace2ef510 in bdrv_open (filename=3Dfilename@entry=3D0xaaaad25f9= 2d0 "/dev/mapper/36384c4f100630193359db7a80000011d", reference=3Dreference@= entry=3D0x0, options=3Doptions@entry=3D0xaaaad3d0f4b0, flags=3Dflags@entry=3D128, errp= =3Derrp@entry=3D0xfffffef7a710) at block.c:1979 #10 0x0000aaaace331ef0 in blk_new_open (filename=3Dfilename@entry=3D0xaaaad= 25f92d0 "/dev/mapper/36384c4f100630193359db7a80000011d", reference=3Drefere= nce@entry=3D0x0, options=3Doptions@entry=3D0xaaaad3d0f4b0, flags=3D128, errp=3Derrp@entry=3D= 0xfffffef7a710) at block/block_backend.c:213 #11 0x0000aaaace0da1f4 in blockdev_init (file=3Dfile@entry=3D0xaaaad25f92d0= "/dev/mapper/36384c4f100630193359db7a80000011d", bs_opts=3Dbs_opts@entry= =3D0xaaaad3d0f4b0, errp=3Derrp@entry=3D0xfffffef7a710) at blockdev.c:603 #12 0x0000aaaace0dc478 in drive_new (all_opts=3Dall_opts@entry=3D0xaaaad4dc= 31d0, block_default_type=3D) at blockdev.c:1116 #13 0x0000aaaace0e3ee0 in add_init_drive ( optstr=3Doptstr@entry=3D0xaaaad0872ec0 "file=3D/dev/mapper/36384c4f10063019= 3359db7a80000011d,format=3Draw,if=3Dnone,id=3Ddrive-scsi0-0-0-3,cache=3Dnon= e,aio=3Dnative") at device_hotplug.c:46 #14 0x0000aaaace0e3f78 in hmp_drive_add (mon=3D0xfffffef7a810, qdict=3D0xaa= aad0c8f000) at device_hotplug.c:67 #15 0x0000aaaacdf7d688 in handle_hmp_command (mon=3D0xfffffef7a810, cmdline= =3D) at /usr/src/debug/qemu-kvm-2.8.1/monitor.c:3199 #16 0x0000aaaacdf7d778 in qmp_human_monitor_command ( command_line=3D0xaaaacfc8e3c0 "drive_add dummy file=3D/dev/mapper/36384c4f1= 00630193359db7a80000011d,format=3Draw,if=3Dnone,id=3Ddrive-scsi0-0-0-3,cach= e=3Dnone,aio=3Dnative", has_cpu_index=3Dfalse, cpu_index=3D0, errp=3Derrp@entry=3D0xfffffef7a968) a= t /usr/src/debug/qemu-kvm-2.8.1/monitor.c:660 #17 0x0000aaaace0fdb30 in qmp_marshal_human_monitor_command (args=3D, ret=3D0xfffffef7a9e0, errp=3D0xfffffef7a9d8) at qmp-marshal.c:2223 #18 0x0000aaaace3b6ad0 in do_qmp_dispatch (request=3D, errp= =3D0xfffffef7aa20, errp@entry=3D0xfffffef7aa40) at qapi/qmp_dispatch.c:115 #19 0x0000aaaace3b6d58 in qmp_dispatch (request=3D) at qapi/= qmp_dispatch.c:142 #20 0x0000aaaacdf79398 in handle_qmp_command (parser=3D, tok= ens=3D) at /usr/src/debug/qemu-kvm-2.8.1/monitor.c:4010 #21 0x0000aaaace3bd6c0 in json_message_process_token (lexer=3D0xaaaacf834c8= 0, input=3D, type=3DJSON_RCURLY, x=3D214, y=3D274) at qobjec= t/json_streamer.c:105 #22 0x0000aaaace3f3d4c in json_lexer_feed_char (lexer=3Dlexer@entry=3D0xaaa= acf834c80, ch=3D, flush=3Dflush@entry=3Dfalse) at qobject/js= on_lexer.c:319 #23 0x0000aaaace3f3e6c in json_lexer_feed (lexer=3D0xaaaacf834c80, buffer= =3D, size=3D) at qobject/json_lexer.c:369 #24 0x0000aaaacdf77c64 in monitor_qmp_read (opaque=3D, buf= =3D, size=3D) at /usr/src/debug/qemu-kvm-2.8.= 1/monitor.c:4040 #25 0x0000aaaace0eab18 in tcp_chr_read (chan=3D, cond=3D, opaque=3D0xaaaacf90b280) at qemu_char.c:3260 #26 0x0000ffff9dadf200 in g_main_context_dispatch () from /lib64/libglib-2.= 0.so.0 #27 0x0000aaaace3c4a00 in glib_pollfds_poll () at util/main_loop.c:230 --Type for more, q to quit, c to continue without paging-- #28 0x0000aaaace3c4a88 in os_host_main_loop_wait (timeout=3D= ) at util/main_loop.c:278 #29 0x0000aaaace3c4bf0 in main_loop_wait (nonblocking=3D) at= util/main_loop.c:534 #30 0x0000aaaace0f5d08 in main_loop () at vl.c:2120 #31 0x0000aaaacdf3a770 in main (argc=3D, argv=3D, envp=3D) at vl.c:5017 when do qmp sush as drive_add, qemu main thread locks the qemu_global_mute= x and do pread in raw_probe_alignmen. Pread is a synchronous operation. If backend storage network has a large delay or= IO pressure is too large, the pread operation will not return for a long = time, which make vcpu thread can't acquire qemu_global_mutex for a long time and make t= he vcpu thread unable to be scheduled for a long time. So virtual machine = cpu soft lockup happened. qemu main thread should not hold qemu_global_mutex for a long time when do = qmp that involving IO synchronous operation sush pread , ioctl, etc. So this patch unlock qemu_global_mutex before IO synchronous operation sush= pread. --- block/file-posix.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/block/file-posix.c b/block/file-posix.c index 1cf4ee4..192c779 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -297,7 +297,9 @@ static int probe_physical_blocksize(int fd, unsigned in= t *blk_size) */ static bool raw_is_io_aligned(int fd, void *buf, size_t len) { + qemu_mutex_unlock_iothread(); ssize_t ret =3D pread(fd, buf, len, 0); + qemu_mutex_lock_iothread(); =20 if (ret >=3D 0) { return true; --=20 2.7.2.windows.1