From nobody Tue Nov 26 18:27:21 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=oss.nxp.com); dmarc=fail(p=none dis=none) header.from=oss.nxp.com ARC-Seal: i=2; a=rsa-sha256; t=1705412407; cv=pass; d=zohomail.com; s=zohoarc; b=YghsouBoN3jxB+lKo1Xs4seKoKq1V19o6UAeKNtFY8xDSmpp3sITwfjuo7gXMhZ031uZcyOklYLzqkLUfkynI65Zwm5KDm6kDYT/KFp/7aVbTU/JYlU8heXFbzUe63OD3nPXO26gks5drKKmiQf8GwIdNOlCyVEqRp4Qg8fEBMQ= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705412407; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=2U3E52DW1E9L3OhbwVGkXyBGddYCJr05awnT7+GVbJI=; b=iwrl7owMKytffJW8mwWUFcsxl4LqcaIyBQi7KzMp18loay4Sq1JQoUMtHLGarGJhkS6dPcn1uUtbfVsMb6ew6tHZ64ApVnxa6idSKwMeU9PfsVouVCPA7c08LfH4a/M6LEOm/jadSRLguOrQuyw2wCOdQMl3Wccpau+n/1y8+A8= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=oss.nxp.com); dmarc=fail header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1705412407346656.64464088759; Tue, 16 Jan 2024 05:40:07 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.667775.1039369 (Exim 4.92) (envelope-from ) id 1rPjfH-0001Dg-TF; Tue, 16 Jan 2024 13:39:39 +0000 Received: by outflank-mailman (output) from mailman id 667775.1039369; Tue, 16 Jan 2024 13:39:39 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rPjfH-0001DZ-Og; Tue, 16 Jan 2024 13:39:39 +0000 Received: by outflank-mailman (input) for mailman id 667775; Tue, 16 Jan 2024 13:39:38 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rPjfG-0001DS-6W for xen-devel@lists.xenproject.org; Tue, 16 Jan 2024 13:39:38 +0000 Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on2087.outbound.protection.outlook.com [40.107.7.87]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id aff7bd15-b474-11ee-9b0f-b553b5be7939; Tue, 16 Jan 2024 14:39:35 +0100 (CET) Received: from DU0PR04MB9417.eurprd04.prod.outlook.com (2603:10a6:10:358::11) by VI1PR04MB7165.eurprd04.prod.outlook.com (2603:10a6:800:125::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7181.23; Tue, 16 Jan 2024 13:39:05 +0000 Received: from DU0PR04MB9417.eurprd04.prod.outlook.com ([fe80::c499:8cef:9bb1:ced6]) by DU0PR04MB9417.eurprd04.prod.outlook.com ([fe80::c499:8cef:9bb1:ced6%3]) with mapi id 15.20.7181.022; Tue, 16 Jan 2024 13:39:05 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: aff7bd15-b474-11ee-9b0f-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=m46DZNX6uuNfw3kfH6RUhOccnw+wub7vWobPBDfePxFT1ii5gKPmWD6cS+iDK+CWTWMzu6VMBK9e8BqD+MZzoFKCXw3CgcBoqo1lJOf/N61AayMmUPSQyeGpWkJQRqujwhiRIHGptHXL3SeCo+MSvv7fpQgCy5vLKGvfvdxMRFbDSY7TIESKH29gWjdR+av51PunzMilOqhqVEEITO7A8onZQWWbXLq2tzNlH6JjAObOXSTDpAEI+rLWl0/oruv8Md1Fn5QjTBdPMg+BOrBlcsxecN+lUX5oqTH8LPV2jjZM84McxkRgr8DSycc2/IMQ42VW+nw8xLFjsK0FWBaDiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=2U3E52DW1E9L3OhbwVGkXyBGddYCJr05awnT7+GVbJI=; b=Hqr9VMzieG7k/8ErrHHdFXicspAcPaZoRbMn3xOLMix6kmGsw5wfAYP+i4sHoS7/xBu5NTp7SbZyEi/CyrO7z1+uh2k3x0Ps8hckjlDtK4WjpkHNIvDdRdo4IRK50kC6o+5Degorx0TKgSNosH5nrKu0ap2uYxdo97bGyQgxPu99Z+MfRaI01c2jN1ffuW6jnIBReSd7GrJl5aJaYccWh5jKt/NUg8bUidJZOaa6GPOeZTFGrkgCvz5PKOEtGN8EHqM5eZDwmrl4cXDf+yZsGHsiKw7Y8V+infay5xJ+8xWh8VtXBulMopGl1iCX+nDwNwwMs8lKV2jFFHaCM2Ja5w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector2-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=2U3E52DW1E9L3OhbwVGkXyBGddYCJr05awnT7+GVbJI=; b=M+OwdT3ltHWziOOjbww5uwjUX8/CGPsPNRYLMwshPiB9B3FjL03fescWZfzzWWIuE67ID6Ig1FGV5Rn62xDfF+gG4MueO7ft2REAOwR7+374GxxqEJJPpVMc4RvShnC3M1qxNI56D9J+WH13DHG/zL5I4PZ7IlU39ap8FkB7T80= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; From: "Peng Fan (OSS)" To: sstabellini@kernel.org, anthony.perard@citrix.com, paul@xen.org, vikram.garhwal@amd.com, viresh.kumar@linaro.org Cc: xen-devel@lists.xenproject.org, qemu-devel@nongnu.org, Peng Fan Subject: [PATCH] xen: Drop out of coroutine context xen_invalidate_map_cache_entry Date: Tue, 16 Jan 2024 22:36:22 +0800 Message-Id: <20240116143622.6641-1-peng.fan@oss.nxp.com> X-Mailer: git-send-email 2.35.3 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SI2P153CA0017.APCP153.PROD.OUTLOOK.COM (2603:1096:4:140::10) To DU0PR04MB9417.eurprd04.prod.outlook.com (2603:10a6:10:358::11) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU0PR04MB9417:EE_|VI1PR04MB7165:EE_ X-MS-Office365-Filtering-Correlation-Id: ab96e1b3-9e2a-4afb-fa7e-08dc169881f4 X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ITbcP3AkQVCnDyJwonkpEyUr6qh/O+ZJA5WYa+WC2NhGg4K6heknvGj/RZhtF6tg1nx8vqSSG548a+hKKrbS+77stmLcPiAEJ1QURx+3TEsI6hHrs9kNF73zOYdgN7OfSu3MxeJYDAdXfRnHCrC/8kyr3P55DJqbdeVpp2Y8dsmULC0wEerJCQEQjht5F3+6iBJ6RXRgnewXQKqS6ebcSZFhWnztG40hCzGT2UaMXRTm+/amdSOciYGTQ5SqeOw5grLoBeBsNhljgh1x0kpOY/oa8BvvDc7JHSLIiCOzXv542vDNfeyoZBATAam/kjpOqfnGTSDqjvzJeQ0i15CWO1oM1bs86VSEEbZxntDbSRvYnPwhvNtKsM/veInoV7pUtZNplvznOzrGuvcj98tOnGzRKgQIEnG9423auUtpMe5B40YDUFaBt1/RwUldOzn6tPn3SzHgTQcsD+yj3GQpbNkat2tt5pKsrdWTGCtx2SDB7ghKfEsGxuF4ni9wgFZIY6vyAU+cI9h6586fif23R+KHBYu3WElFB0wtXLRl7U0DfnUg5q290aeGdjRXPO1pe9zVN6Wz8IKtmGHvjEcjqHezluy2xpOp3g8xM4lMPNxQSQXXh7wizkPFDyKaMIY0 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DU0PR04MB9417.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(346002)(39860400002)(366004)(136003)(396003)(376002)(230922051799003)(64100799003)(1800799012)(451199024)(186009)(26005)(52116002)(1076003)(38100700002)(38350700005)(86362001)(2616005)(2906002)(83380400001)(6512007)(478600001)(6506007)(6666004)(8936002)(8676002)(316002)(4326008)(41300700001)(66476007)(6486002)(5660300002)(66556008)(66946007);DIR:OUT;SFP:1101; X-MS-Exchange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X1gQoAy7N?= =?us-ascii?Q?9P2yXP+W60d0rP6TYOx8HEkcIBRJQ+TE+BfF8kHurQ/DjD2rVLMYeyHbIWDG?= =?us-ascii?Q?C1PraVW0lCd9t2kYwkzokFxNUFtZjtjDXT7bz0tm+tzDCuBk5MKCUMFOBvhh?= =?us-ascii?Q?2kbCoCxk9M6dHpb1l5aPl5vysWowmtpBbUnBbkcr7HseNnv0iNzLfikQVgDV?= =?us-ascii?Q?EUzxV4Kut9o3diyILOfZk2BMCxDrzSWwlULdoxjz6pn3TlcU+SQfVXaZAyTR?= =?us-ascii?Q?o4MEWjk9PwC/gj0Et646rpjfiWvyaEssdrZIQWOdMTjPn9n7Ckk7aytF9/QJ?= =?us-ascii?Q?+yvZT1Rz+m5KZkOB/B8J1cNkz1CmD98L9U9ze1xJ2ewwOgptEmHSnH9j0+Zp?= =?us-ascii?Q?4z3yQlj6+kk6YyMwo9CBlu7FTq6Ud+3Pm/AB4X1Z3xBOSk3d6w0uVeChYRdb?= =?us-ascii?Q?xah+p1A0rCp7XhUBvgV5+WKNc77u4pVFRYcR+bbaaZQQKitcNLXlfeqXggoc?= =?us-ascii?Q?9vgbjHrS7LUUbm/pzCm3ytSr55GgmVVprmbWU2DFTxOiQBzmotl0aKqbBz8R?= =?us-ascii?Q?pb9BA7Hpml0hsyBA9NsghaAF0xQ9VY56Gq/M6rVx4vBPRIKoMwFu59ssGNS+?= =?us-ascii?Q?sngE+sj6rFgOSRxtjH8D6RCA+Z2E3Wvdv+7j4FxkoXVrE1hcEKn/jDm0hqfB?= =?us-ascii?Q?BlGP1TYqBJq8mOu/Xo969dM4jxsQhSHOhokrDQASaqJXoWpHutNjPpT2c4Ux?= =?us-ascii?Q?q0cQfint5NWhlb3hgq27DrjKnvLmj+lYNQcEn3Yr?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: ab96e1b3-9e2a-4afb-fa7e-08dc169881f4 X-MS-Exchange-CrossTenant-AuthSource: DU0PR04MB9417.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jan 2024 13:39:05.3808 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: sZTaoXNRwsYtgOX/r3mpqE5cPXCkItBJJVC2H+qedwgKQiezY43BUs+WcRLkJi5ZbPmVt6DCBB0lcT5jcDBbIw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB7165 X-ZohoMail-DKIM: pass (identity @NXP1.onmicrosoft.com) X-ZM-MESSAGEID: 1705412407891100001 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 --- hw/xen/xen-mapcache.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/hw/xen/xen-mapcache.c b/hw/xen/xen-mapcache.c index f7d974677d..4e1bb665ee 100644 --- a/hw/xen/xen-mapcache.c +++ b/hw/xen/xen-mapcache.c @@ -481,11 +481,38 @@ 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; + int ret; +} 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.35.3