From nobody Tue Nov 11 15:56:23 2025 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; dkim=fail; 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; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1564436103; cv=none; d=zoho.com; s=zohoarc; b=JlUdzOZzEebloRmfZTid5rNpyPWx4jxAfEEThQJQfpTicm4nIq120xkRq41v8iC3AW6KqtCXMpJ8hP6q8VdvKa2AVL9HduS3vYurksWI46CemPtmvFsSGKJYYNnaKKKB1F8ZHSgGsviP/fPIY0o6MATSpZv4JOC4RSVXULLNRik= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1564436103; h=Content-Transfer-Encoding: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=3I4jA2sDRFUkEhkPZXl6uyUAXLMqFsLByymO+/orOv4=; b=gQnmV9xlmeOavDBvxf44cuvp31h6RxRjSPZSj/XNJyQ2hfX0Ke9gEWeAkJV+Qkf4tOnZvnDYALcNRzpfZX2kMaULaMmf6N62+sF6Wvrq+Lp90jXc21mdWqAYajSpKl5zAtXS+LdTRZoXiSS+O9WTmYizDgGmzuyW3gRn/5zbAec= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; 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; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1564436103249185.7164962508092; Mon, 29 Jul 2019 14:35:03 -0700 (PDT) Received: from localhost ([::1]:56544 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsDIM-0007mY-8v for importer@patchew.org; Mon, 29 Jul 2019 17:35:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59617) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsDHe-0007Jf-Ko for qemu-devel@nongnu.org; Mon, 29 Jul 2019 17:34:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsDHd-0004qZ-Js for qemu-devel@nongnu.org; Mon, 29 Jul 2019 17:34:18 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:45122) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsDHd-0004oQ-CB for qemu-devel@nongnu.org; Mon, 29 Jul 2019 17:34:17 -0400 Received: by mail-wr1-x441.google.com with SMTP id f9so63386422wre.12 for ; Mon, 29 Jul 2019 14:34:17 -0700 (PDT) Received: from donizetti.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id o7sm51562163wmc.36.2019.07.29.14.34.14 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 29 Jul 2019 14:34:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=3I4jA2sDRFUkEhkPZXl6uyUAXLMqFsLByymO+/orOv4=; b=VqfQvRZWoa6T//DCafbEVb+ntQYy9VjUi1/v4EwT+85eO0UCB/iDZKDPxM78thFt6e EA9nUzM2HvWjMqvOG0EldajmBX4xRVVV89frn4lDCxD64LLgtK21ejnlsgc3CHDTRozX 5DPqCwZFSerNNTZac2FnmeTqWWHJ4EU4OirW1JD66RI/Fm55v+cruqV28Jjcg/OjTtbv EP8efjWZnKWKHjK+7mBHmONfD3f34f+Ee2eR1dQG4xt7X4tYKF3gQBEfQXF62O3wfkWo 1sTYPuOe+SW+1vRodJx/hinbhdKAHcuXGxyg+B2/O3BYOZrJnqg0zKXfuFC59JtuGHpR dRpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; bh=3I4jA2sDRFUkEhkPZXl6uyUAXLMqFsLByymO+/orOv4=; b=kBREPCbP+xGVhSvbopZbS9a7craq/KxRzi0iQ4aLM0THWEY9IRBnSPI26aWvJvTmA5 0f/hclc3Bif5eb5+vMWso9PgTdh5xKuE5KMxe9GEfCII+dcMVNUgyflyGW7bRHlI6DGc d/YuodDS/00jQTN7rwZRSgVpgWoy2tT6j4MMIFPmWwb5Q0JlL0dx5Eg8FvJF3GN4wB8i B8mfvfiMLuG1tZX0AyNHiataKsWm7bk878KAajgy99ylDFY72f1JaiuFUJo63ZyjwZeL DEkMrthQFThSSjugdGdyNN5LyH8uXiIO84wLeDRwYCkPfLgyVmkg3lMBeqzvW/mK0MeK 9G/Q== X-Gm-Message-State: APjAAAURks389ky67t/ojqjpNs0cePD1ZirLHsFkJ5buDqs39I0DedEh DLJc2bX7S4JiTfmmrvpH1+aqWLuGLdQ= X-Google-Smtp-Source: APXvYqwptaiXD44N+M68U4OYRANVxvHHChqnhjD1zY9Q/c2cIbIE6XQR0J8tUVLCLdhxvrhJcSzAUA== X-Received: by 2002:a05:6000:1043:: with SMTP id c3mr68814531wrx.236.1564436055177; Mon, 29 Jul 2019 14:34:15 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 29 Jul 2019 23:34:16 +0200 Message-Id: <20190729213416.1972-1-pbonzini@redhat.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::441 Subject: [Qemu-devel] [PATCH] dma-helpers: ensure AIO callback is invoked after cancellation 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: John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" dma_aio_cancel unschedules the BH if there is one, which corresponds to the reschedule_dma case of dma_blk_cb. This can stall the DMA permanently, because dma_complete will never get invoked and therefore nobody will ever invoke the original AIO callback in dbs->common.cb. Fix this by invoking the callback (which is ensured to happen after a bdrv_aio_cancel_async, or done manually in the dbs->bh case), and add assertions to check that the DMA state machine is indeed waiting for dma_complete or reschedule_dma, but never both. Reported-by: John Snow Signed-off-by: Paolo Bonzini --- dma-helpers.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/dma-helpers.c b/dma-helpers.c index 2d7e02d..d3871dc 100644 --- a/dma-helpers.c +++ b/dma-helpers.c @@ -90,6 +90,7 @@ static void reschedule_dma(void *opaque) { DMAAIOCB *dbs =3D (DMAAIOCB *)opaque; =20 + assert(!dbs->acb && dbs->bh); qemu_bh_delete(dbs->bh); dbs->bh =3D NULL; dma_blk_cb(dbs, 0); @@ -111,15 +112,12 @@ static void dma_complete(DMAAIOCB *dbs, int ret) { trace_dma_complete(dbs, ret, dbs->common.cb); =20 + assert(!dbs->acb && !dbs->bh); dma_blk_unmap(dbs); if (dbs->common.cb) { dbs->common.cb(dbs->common.opaque, ret); } qemu_iovec_destroy(&dbs->iov); - if (dbs->bh) { - qemu_bh_delete(dbs->bh); - dbs->bh =3D NULL; - } qemu_aio_unref(dbs); } =20 @@ -179,14 +177,21 @@ static void dma_aio_cancel(BlockAIOCB *acb) =20 trace_dma_aio_cancel(dbs); =20 + assert(!(dbs->acb && dbs->bh)); if (dbs->acb) { + /* This will invoke dma_blk_cb. */ blk_aio_cancel_async(dbs->acb); + return; } + if (dbs->bh) { cpu_unregister_map_client(dbs->bh); qemu_bh_delete(dbs->bh); dbs->bh =3D NULL; } + if (dbs->common.cb) { + dbs->common.cb(dbs->common.opaque, -ECANCELED); + } } =20 static AioContext *dma_get_aio_context(BlockAIOCB *acb) --=20 1.8.3.1