From nobody Mon Sep 16 20:29:12 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=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 1712733910724400.1787012821711; Wed, 10 Apr 2024 00:25:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ruSJz-0002k7-80; Wed, 10 Apr 2024 03:24:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ruSJk-00023X-4s; Wed, 10 Apr 2024 03:24:26 -0400 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ruSJh-0003yN-K6; Wed, 10 Apr 2024 03:24:23 -0400 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id A2FA25D680; Wed, 10 Apr 2024 10:25:03 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 45908B02C1; Wed, 10 Apr 2024 10:23:05 +0300 (MSK) Received: (nullmailer pid 4191696 invoked by uid 1000); Wed, 10 Apr 2024 07:23:04 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, Peng Fan , Stefano Stabellini , Anthony PERARD , Michael Tokarev Subject: [Stable-8.2.3 17/87] xen: Drop out of coroutine context xen_invalidate_map_cache_entry Date: Wed, 10 Apr 2024 10:21:50 +0300 Message-Id: <20240410072303.4191455-17-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZM-MESSAGEID: 1712733913070100003 Content-Type: text/plain; charset="utf-8" From: Peng Fan xen_invalidate_map_cache_entry is not expected to run in a coroutine. Without this, there is crash: signo=3Dsigno@entry=3D6, no_tid=3Dno_tid@entry=3D0) at pthread_kill.c:44 threadid=3D) at pthread_kill.c:78 at /usr/src/debug/glibc/2.38+git-r0/sysdeps/posix/raise.c:26 fmt=3D0xffff9e1ca8a8 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=3Dassertion@entry=3D0xaaaae0d25740 "!qemu_in_coroutine()", file=3Dfile@entry=3D0xaaaae0d301a8 "../qemu-xen-dir-remote/block/graph-= lock.c", line=3Dline@entry=3D260, function=3Dfunction@entry=3D0xaaaae0e522c0 <__PRETTY_FUNCTION__.3> "bdr= v_graph_rdlock_main_loop") at assert.c:92 assertion=3Dassertion@entry=3D0xaaaae0d25740 "!qemu_in_coroutine()", file=3Dfile@entry=3D0xaaaae0d301a8 "../qemu-xen-dir-remote/block/graph-= lock.c", line=3Dline@entry=3D260, function=3Dfunction@entry=3D0xaaaae0e522c0 <__PRETTY_FUNCTION__.3> "bdr= v_graph_rdlock_main_loop") at assert.c:101 at ../qemu-xen-dir-remote/block/graph-lock.c:260 at /home/Freenix/work/sw-stash/xen/upstream/tools/qemu-xen-dir-remote/i= nclude/block/graph-lock.h:259 host=3Dhost@entry=3D0xffff742c8000, size=3Dsize@entry=3D2097152) at ../qemu-xen-dir-remote/block/io.c:3362 host=3D0xffff742c8000, size=3D2097152) at ../qemu-xen-dir-remote/block/block-backend.c:2859 host=3D, size=3D, max_size=3D) at ../qemu-xen-dir-remote/block/block-ram-registrar.c:33 size=3D2097152, max_size=3D2097152) at ../qemu-xen-dir-remote/hw/core/numa.c:883 buffer=3Dbuffer@entry=3D0xffff743c5000 "") at ../qemu-xen-dir-remote/hw/xen/xen-mapcache.c:475 buffer=3Dbuffer@entry=3D0xffff743c5000 "") at ../qemu-xen-dir-remote/hw/xen/xen-mapcache.c:487 as=3Das@entry=3D0xaaaae1ca3ae8 , buffer=3D0xffff7= 43c5000, len=3D, is_write=3Dis_write@entry=3Dtrue, access_len=3Daccess_len@entry=3D32768) at ../qemu-xen-dir-remote/system/physmem.c:3199 dir=3DDMA_DIRECTION_FROM_DEVICE, len=3D, buffer=3D, as=3D0xaaaae1ca3ae8 ) at /home/Freenix/work/sw-stash/xen/upstream/tools/qemu-xen-dir-remote/i= nclude/sysemu/dma.h:236 elem=3Delem@entry=3D0xaaaaf620aa30, len=3Dlen@entry=3D32769) at ../qemu-xen-dir-remote/hw/virtio/virtio.c:758 elem=3Delem@entry=3D0xaaaaf620aa30, len=3Dlen@entry=3D32769, idx=3Didx@= entry=3D0) at ../qemu-xen-dir-remote/hw/virtio/virtio.c:919 elem=3Delem@entry=3D0xaaaaf620aa30, len=3D32769) at ../qemu-xen-dir-remote/hw/virtio/virtio.c:994 req=3Dreq@entry=3D0xaaaaf620aa30, status=3Dstatus@entry=3D0 '\000') at ../qemu-xen-dir-remote/hw/block/virtio-blk.c:67 ret=3D0) at ../qemu-xen-dir-remote/hw/block/virtio-blk.c:136 at ../qemu-xen-dir-remote/block/block-backend.c:1559 --Type for more, q to quit, c to continue without paging-- at ../qemu-xen-dir-remote/block/block-backend.c:1614 i1=3D) at ../qemu-xen-dir-remote/util/coroutine-ucontext= .c:177 at ../sysdeps/unix/sysv/linux/aarch64/setcontext.S:123 Signed-off-by: Peng Fan Reviewed-by: Stefano Stabellini Message-Id: <20240124021450.21656-1-peng.fan@oss.nxp.com> Signed-off-by: Anthony PERARD (cherry picked from commit 9253d83062268209533df4b29859e5b51a2dc324) Signed-off-by: Michael Tokarev diff --git a/hw/xen/xen-mapcache.c b/hw/xen/xen-mapcache.c index f7d974677d..8d62b3d2ed 100644 --- a/hw/xen/xen-mapcache.c +++ b/hw/xen/xen-mapcache.c @@ -481,11 +481,37 @@ static void xen_invalidate_map_cache_entry_unlocked(u= int8_t *buffer) g_free(entry); } =20 -void xen_invalidate_map_cache_entry(uint8_t *buffer) +typedef struct XenMapCacheData { + Coroutine *co; + uint8_t *buffer; +} XenMapCacheData; + +static void xen_invalidate_map_cache_entry_bh(void *opaque) { + XenMapCacheData *data =3D opaque; + mapcache_lock(); - xen_invalidate_map_cache_entry_unlocked(buffer); + xen_invalidate_map_cache_entry_unlocked(data->buffer); mapcache_unlock(); + + aio_co_wake(data->co); +} + +void coroutine_mixed_fn xen_invalidate_map_cache_entry(uint8_t *buffer) +{ + if (qemu_in_coroutine()) { + XenMapCacheData data =3D { + .co =3D qemu_coroutine_self(), + .buffer =3D buffer, + }; + aio_bh_schedule_oneshot(qemu_get_current_aio_context(), + xen_invalidate_map_cache_entry_bh, &data); + qemu_coroutine_yield(); + } else { + mapcache_lock(); + xen_invalidate_map_cache_entry_unlocked(buffer); + mapcache_unlock(); + } } =20 void xen_invalidate_map_cache(void) --=20 2.39.2