From nobody Wed Oct 22 06:35:00 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1519399743179933.3711171814457; Fri, 23 Feb 2018 07:29:03 -0800 (PST) Received: from localhost ([::1]:45180 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1epFHS-0006GY-Br for importer@patchew.org; Fri, 23 Feb 2018 10:29:02 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41530) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1epFFK-0004aM-PI for qemu-devel@nongnu.org; Fri, 23 Feb 2018 10:26:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1epFFJ-0005VQ-Mw for qemu-devel@nongnu.org; Fri, 23 Feb 2018 10:26:50 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54270 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1epFFE-0005QJ-Ms; Fri, 23 Feb 2018 10:26:44 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 515A6F63FE; Fri, 23 Feb 2018 15:26:44 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-117-249.ams2.redhat.com [10.36.117.249]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3970020A846E; Fri, 23 Feb 2018 15:26:43 +0000 (UTC) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 23 Feb 2018 16:26:36 +0100 Message-Id: <20180223152640.11459-2-pbonzini@redhat.com> In-Reply-To: <20180223152640.11459-1-pbonzini@redhat.com> References: <20180223152640.11459-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 23 Feb 2018 15:26:44 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 23 Feb 2018 15:26:44 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'pbonzini@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH 1/5] ide: push call to end_transfer_func out of start_transfer callback X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Lieven , John Snow , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Split the PIO transfer across two callbacks, thus pushing the (possibly recursive) call to end_transfer_func up one level and out of the AHCI-specific code. Signed-off-by: Paolo Bonzini --- hw/ide/ahci.c | 7 ++++++- hw/ide/core.c | 9 ++++++--- include/hw/ide/internal.h | 1 + 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c index e22d7be05f..937bad55fb 100644 --- a/hw/ide/ahci.c +++ b/hw/ide/ahci.c @@ -1321,8 +1321,12 @@ out: =20 /* Update number of transferred bytes, destroy sglist */ dma_buf_commit(s, size); +} =20 - s->end_transfer_func(s); +static void ahci_end_transfer(IDEDMA *dma) +{ + AHCIDevice *ad =3D DO_UPCAST(AHCIDevice, dma, dma); + IDEState *s =3D &ad->port.ifs[0]; =20 if (!(s->status & DRQ_STAT)) { /* done with PIO send/receive */ @@ -1444,6 +1448,7 @@ static const IDEDMAOps ahci_dma_ops =3D { .restart =3D ahci_restart, .restart_dma =3D ahci_restart_dma, .start_transfer =3D ahci_start_transfer, + .end_transfer =3D ahci_end_transfer, .prepare_buf =3D ahci_dma_prepare_buf, .commit_buf =3D ahci_commit_buf, .rw_buf =3D ahci_dma_rw_buf, diff --git a/hw/ide/core.c b/hw/ide/core.c index 257b429381..92f4424dc3 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -532,16 +532,19 @@ static void ide_clear_retry(IDEState *s) void ide_transfer_start(IDEState *s, uint8_t *buf, int size, EndTransferFunc *end_transfer_func) { - s->end_transfer_func =3D end_transfer_func; s->data_ptr =3D buf; s->data_end =3D buf + size; ide_set_retry(s); if (!(s->status & ERR_STAT)) { s->status |=3D DRQ_STAT; } - if (s->bus->dma->ops->start_transfer) { - s->bus->dma->ops->start_transfer(s->bus->dma); + if (!s->bus->dma->ops->start_transfer) { + s->end_transfer_func =3D end_transfer_func; + return; } + s->bus->dma->ops->start_transfer(s->bus->dma); + end_transfer_func(s); + s->bus->dma->ops->end_transfer(s->bus->dma); } =20 static void ide_cmd_done(IDEState *s) diff --git a/include/hw/ide/internal.h b/include/hw/ide/internal.h index 88212f59df..efaabbd815 100644 --- a/include/hw/ide/internal.h +++ b/include/hw/ide/internal.h @@ -445,6 +445,7 @@ struct IDEState { struct IDEDMAOps { DMAStartFunc *start_dma; DMAVoidFunc *start_transfer; + DMAVoidFunc *end_transfer; DMAInt32Func *prepare_buf; DMAu32Func *commit_buf; DMAIntFunc *rw_buf; --=20 2.14.3 From nobody Wed Oct 22 06:35:00 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1519399732895383.10770951786617; Fri, 23 Feb 2018 07:28:52 -0800 (PST) Received: from localhost ([::1]:45179 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1epFHI-00068G-2W for importer@patchew.org; Fri, 23 Feb 2018 10:28:52 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41525) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1epFFK-0004aH-MD for qemu-devel@nongnu.org; Fri, 23 Feb 2018 10:26:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1epFFJ-0005VH-K6 for qemu-devel@nongnu.org; Fri, 23 Feb 2018 10:26:50 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:42646 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1epFFG-0005RT-1r; Fri, 23 Feb 2018 10:26:46 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9F5EF8D6D6; Fri, 23 Feb 2018 15:26:45 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-117-249.ams2.redhat.com [10.36.117.249]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9332920A846E; Fri, 23 Feb 2018 15:26:44 +0000 (UTC) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 23 Feb 2018 16:26:37 +0100 Message-Id: <20180223152640.11459-3-pbonzini@redhat.com> In-Reply-To: <20180223152640.11459-1-pbonzini@redhat.com> References: <20180223152640.11459-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 23 Feb 2018 15:26:45 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 23 Feb 2018 15:26:45 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'pbonzini@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH 2/5] ide: push end_transfer callback to ide_transfer_halt X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Lieven , John Snow , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The callback must be invoked once we get out of the DRQ phase; because all end_transfer_funcs end up invoking ide_transfer_stop, call it there. While at it, remove the "notify" argument from ide_transfer_halt; the code can simply be moved to ide_transfer_stop. Old PATA controllers have no end_transfer callback, so there is no change there. For AHCI the end_transfer_func already called ide_transfer_stop so the effect is that the PIO FIS is written before the D2H FIS rather than after, which is arguably an improvement. However, ahci_end_transfer is now called _after_ the DRQ_STAT has been cleared, so remove the status check in ahci_end_transfer; it was only there to ensure the FIS was not written more than once, and this cannot happen anymore. Signed-off-by: Paolo Bonzini --- hw/ide/ahci.c | 7 ++----- hw/ide/core.c | 15 +++++++-------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c index 937bad55fb..c3c6843b76 100644 --- a/hw/ide/ahci.c +++ b/hw/ide/ahci.c @@ -1326,12 +1326,9 @@ out: static void ahci_end_transfer(IDEDMA *dma) { AHCIDevice *ad =3D DO_UPCAST(AHCIDevice, dma, dma); - IDEState *s =3D &ad->port.ifs[0]; =20 - if (!(s->status & DRQ_STAT)) { - /* done with PIO send/receive */ - ahci_write_fis_pio(ad, le32_to_cpu(ad->cur_cmd->status)); - } + /* done with PIO send/receive */ + ahci_write_fis_pio(ad, le32_to_cpu(ad->cur_cmd->status)); } =20 static void ahci_start_dma(IDEDMA *dma, IDEState *s, diff --git a/hw/ide/core.c b/hw/ide/core.c index 92f4424dc3..c4710a6f55 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -544,7 +544,6 @@ void ide_transfer_start(IDEState *s, uint8_t *buf, int = size, } s->bus->dma->ops->start_transfer(s->bus->dma); end_transfer_func(s); - s->bus->dma->ops->end_transfer(s->bus->dma); } =20 static void ide_cmd_done(IDEState *s) @@ -555,26 +554,26 @@ static void ide_cmd_done(IDEState *s) } =20 static void ide_transfer_halt(IDEState *s, - void(*end_transfer_func)(IDEState *), - bool notify) + void(*end_transfer_func)(IDEState *)) { s->end_transfer_func =3D end_transfer_func; s->data_ptr =3D s->io_buffer; s->data_end =3D s->io_buffer; s->status &=3D ~DRQ_STAT; - if (notify) { - ide_cmd_done(s); - } } =20 void ide_transfer_stop(IDEState *s) { - ide_transfer_halt(s, ide_transfer_stop, true); + ide_transfer_halt(s, ide_transfer_stop); + if (s->bus->dma->ops->end_transfer) { + s->bus->dma->ops->end_transfer(s->bus->dma); + } + ide_cmd_done(s); } =20 static void ide_transfer_cancel(IDEState *s) { - ide_transfer_halt(s, ide_transfer_cancel, false); + ide_transfer_halt(s, ide_transfer_cancel); } =20 int64_t ide_get_sector(IDEState *s) --=20 2.14.3 From nobody Wed Oct 22 06:35:00 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1519399733211244.66210362319646; Fri, 23 Feb 2018 07:28:53 -0800 (PST) Received: from localhost ([::1]:45178 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1epFHI-00066c-DQ for importer@patchew.org; Fri, 23 Feb 2018 10:28:52 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41516) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1epFFK-0004a1-Ex for qemu-devel@nongnu.org; Fri, 23 Feb 2018 10:26:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1epFFJ-0005VC-JW for qemu-devel@nongnu.org; Fri, 23 Feb 2018 10:26:50 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54274 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1epFFH-0005Si-D5; Fri, 23 Feb 2018 10:26:47 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EC045EB6ED; Fri, 23 Feb 2018 15:26:46 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-117-249.ams2.redhat.com [10.36.117.249]) by smtp.corp.redhat.com (Postfix) with ESMTP id E04B720A8471; Fri, 23 Feb 2018 15:26:45 +0000 (UTC) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 23 Feb 2018 16:26:38 +0100 Message-Id: <20180223152640.11459-4-pbonzini@redhat.com> In-Reply-To: <20180223152640.11459-1-pbonzini@redhat.com> References: <20180223152640.11459-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 23 Feb 2018 15:26:46 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 23 Feb 2018 15:26:46 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'pbonzini@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH 3/5] ide: do not set s->end_transfer_func to ide_transfer_cancel X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Lieven , John Snow , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" There is code checking s->end_transfer_func and it was not taught about ide_transfer_cancel. We can just use ide_transfer_stop because s->end_transfer_func is only ever called in the DRQ phase: after ide_transfer_cancel, the value of s->end_transfer_func is only used as a marker and never used to actually invoke the function. Signed-off-by: Paolo Bonzini --- hw/ide/core.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/hw/ide/core.c b/hw/ide/core.c index c4710a6f55..447d9624df 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -553,10 +553,9 @@ static void ide_cmd_done(IDEState *s) } } =20 -static void ide_transfer_halt(IDEState *s, - void(*end_transfer_func)(IDEState *)) +static void ide_transfer_halt(IDEState *s) { - s->end_transfer_func =3D end_transfer_func; + s->end_transfer_func =3D ide_transfer_stop; s->data_ptr =3D s->io_buffer; s->data_end =3D s->io_buffer; s->status &=3D ~DRQ_STAT; @@ -564,7 +563,7 @@ static void ide_transfer_halt(IDEState *s, =20 void ide_transfer_stop(IDEState *s) { - ide_transfer_halt(s, ide_transfer_stop); + ide_transfer_halt(s); if (s->bus->dma->ops->end_transfer) { s->bus->dma->ops->end_transfer(s->bus->dma); } @@ -573,7 +572,7 @@ void ide_transfer_stop(IDEState *s) =20 static void ide_transfer_cancel(IDEState *s) { - ide_transfer_halt(s, ide_transfer_cancel); + ide_transfer_halt(s); } =20 int64_t ide_get_sector(IDEState *s) --=20 2.14.3 From nobody Wed Oct 22 06:35:00 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1519399868472946.4709830944768; Fri, 23 Feb 2018 07:31:08 -0800 (PST) Received: from localhost ([::1]:45199 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1epFJT-0008LU-NX for importer@patchew.org; Fri, 23 Feb 2018 10:31:07 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41556) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1epFFL-0004bE-Go for qemu-devel@nongnu.org; Fri, 23 Feb 2018 10:26:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1epFFK-0005W9-KK for qemu-devel@nongnu.org; Fri, 23 Feb 2018 10:26:51 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:37148 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1epFFI-0005Tu-Lr; Fri, 23 Feb 2018 10:26:48 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 416338182D3A; Fri, 23 Feb 2018 15:26:48 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-117-249.ams2.redhat.com [10.36.117.249]) by smtp.corp.redhat.com (Postfix) with ESMTP id 38B1420A846E; Fri, 23 Feb 2018 15:26:47 +0000 (UTC) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 23 Feb 2018 16:26:39 +0100 Message-Id: <20180223152640.11459-5-pbonzini@redhat.com> In-Reply-To: <20180223152640.11459-1-pbonzini@redhat.com> References: <20180223152640.11459-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 23 Feb 2018 15:26:48 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 23 Feb 2018 15:26:48 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'pbonzini@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH 4/5] atapi: call ide_set_irq before ide_transfer_start X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Lieven , John Snow , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The ATAPI_INT_REASON_IO interrupt is raised when I/O starts, but in the AHCI case ide_set_irq was actually called at the end of a mutual recursion. Move it early, with the side effect that ide_transfer_start becomes a tail call in ide_atapi_cmd_reply_end. Signed-off-by: Paolo Bonzini --- hw/ide/atapi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c index c0509c8bf5..be99a929cf 100644 --- a/hw/ide/atapi.c +++ b/hw/ide/atapi.c @@ -287,6 +287,7 @@ void ide_atapi_cmd_reply_end(IDEState *s) } else { /* a new transfer is needed */ s->nsector =3D (s->nsector & ~7) | ATAPI_INT_REASON_IO; + ide_set_irq(s->bus); byte_count_limit =3D atapi_byte_count_limit(s); trace_ide_atapi_cmd_reply_end_bcl(s, byte_count_limit); size =3D s->packet_transfer_size; @@ -307,10 +308,9 @@ void ide_atapi_cmd_reply_end(IDEState *s) s->packet_transfer_size -=3D size; s->elementary_transfer_size -=3D size; s->io_buffer_index +=3D size; + trace_ide_atapi_cmd_reply_end_new(s, s->status); ide_transfer_start(s, s->io_buffer + s->io_buffer_index - size, size, ide_atapi_cmd_reply_end); - ide_set_irq(s->bus); - trace_ide_atapi_cmd_reply_end_new(s, s->status); } } } --=20 2.14.3 From nobody Wed Oct 22 06:35:00 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1519399966487418.2574186834074; Fri, 23 Feb 2018 07:32:46 -0800 (PST) Received: from localhost ([::1]:45204 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1epFL3-0000xR-7J for importer@patchew.org; Fri, 23 Feb 2018 10:32:45 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41587) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1epFFN-0004eK-Vm for qemu-devel@nongnu.org; Fri, 23 Feb 2018 10:26:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1epFFM-0005XL-S7 for qemu-devel@nongnu.org; Fri, 23 Feb 2018 10:26:53 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:48302 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1epFFJ-0005VN-VA; Fri, 23 Feb 2018 10:26:50 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8C8694040856; Fri, 23 Feb 2018 15:26:49 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-117-249.ams2.redhat.com [10.36.117.249]) by smtp.corp.redhat.com (Postfix) with ESMTP id 82E6020A846E; Fri, 23 Feb 2018 15:26:48 +0000 (UTC) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 23 Feb 2018 16:26:40 +0100 Message-Id: <20180223152640.11459-6-pbonzini@redhat.com> In-Reply-To: <20180223152640.11459-1-pbonzini@redhat.com> References: <20180223152640.11459-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 23 Feb 2018 15:26:49 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 23 Feb 2018 15:26:49 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'pbonzini@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH 5/5] ide: introduce ide_transfer_start_norecurse X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Lieven , John Snow , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" For the case where the end_transfer_func is also the caller of ide_transfer_start, the mutual recursion can lead to unlimited stack usage. Introduce a new version that can be used to change tail recursion into a loop, and use it in trace_ide_atapi_cmd_reply_end. Signed-off-by: Paolo Bonzini --- hw/ide/atapi.c | 35 +++++++++++++++++++---------------- hw/ide/core.c | 16 ++++++++++++---- include/hw/ide/internal.h | 2 ++ 3 files changed, 33 insertions(+), 20 deletions(-) diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c index be99a929cf..4df4a66bbe 100644 --- a/hw/ide/atapi.c +++ b/hw/ide/atapi.c @@ -248,12 +248,7 @@ void ide_atapi_cmd_reply_end(IDEState *s) trace_ide_atapi_cmd_reply_end(s, s->packet_transfer_size, s->elementary_transfer_size, s->io_buffer_index); - if (s->packet_transfer_size <=3D 0) { - /* end of transfer */ - ide_atapi_cmd_ok(s); - ide_set_irq(s->bus); - trace_ide_atapi_cmd_reply_end_eot(s, s->status); - } else { + while (s->packet_transfer_size > 0) { /* see if a new sector must be read */ if (s->lba !=3D -1 && s->io_buffer_index >=3D s->cd_sector_size) { if (!s->elementary_transfer_size) { @@ -279,11 +274,6 @@ void ide_atapi_cmd_reply_end(IDEState *s) size =3D s->cd_sector_size - s->io_buffer_index; if (size > s->elementary_transfer_size) size =3D s->elementary_transfer_size; - s->packet_transfer_size -=3D size; - s->elementary_transfer_size -=3D size; - s->io_buffer_index +=3D size; - ide_transfer_start(s, s->io_buffer + s->io_buffer_index - size, - size, ide_atapi_cmd_reply_end); } else { /* a new transfer is needed */ s->nsector =3D (s->nsector & ~7) | ATAPI_INT_REASON_IO; @@ -305,14 +295,27 @@ void ide_atapi_cmd_reply_end(IDEState *s) if (size > (s->cd_sector_size - s->io_buffer_index)) size =3D (s->cd_sector_size - s->io_buffer_index); } - s->packet_transfer_size -=3D size; - s->elementary_transfer_size -=3D size; - s->io_buffer_index +=3D size; trace_ide_atapi_cmd_reply_end_new(s, s->status); - ide_transfer_start(s, s->io_buffer + s->io_buffer_index - size, - size, ide_atapi_cmd_reply_end); + } + s->packet_transfer_size -=3D size; + s->elementary_transfer_size -=3D size; + s->io_buffer_index +=3D size; + + /* Some adapters process PIO data right away. In that case, we ne= ed + * to avoid mutual recursion between ide_transfer_start + * and ide_atapi_cmd_reply_end. + */ + if (!ide_transfer_start_norecurse(s, + s->io_buffer + s->io_buffer_inde= x - size, + size, ide_atapi_cmd_reply_end)) { + return; } } + + /* end of transfer */ + ide_atapi_cmd_ok(s); + ide_set_irq(s->bus); + trace_ide_atapi_cmd_reply_end_eot(s, s->status); } =20 /* send a reply of 'size' bytes in s->io_buffer to an ATAPI command */ diff --git a/hw/ide/core.c b/hw/ide/core.c index 447d9624df..ddefeb086d 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -529,8 +529,8 @@ static void ide_clear_retry(IDEState *s) } =20 /* prepare data transfer and tell what to do after */ -void ide_transfer_start(IDEState *s, uint8_t *buf, int size, - EndTransferFunc *end_transfer_func) +bool ide_transfer_start_norecurse(IDEState *s, uint8_t *buf, int size, + EndTransferFunc *end_transfer_func) { s->data_ptr =3D buf; s->data_end =3D buf + size; @@ -540,10 +540,18 @@ void ide_transfer_start(IDEState *s, uint8_t *buf, in= t size, } if (!s->bus->dma->ops->start_transfer) { s->end_transfer_func =3D end_transfer_func; - return; + return false; } s->bus->dma->ops->start_transfer(s->bus->dma); - end_transfer_func(s); + return true; +} + +void ide_transfer_start(IDEState *s, uint8_t *buf, int size, + EndTransferFunc *end_transfer_func) +{ + if (ide_transfer_start_norecurse(s, buf, size, end_transfer_func)) { + end_transfer_func(s); + } } =20 static void ide_cmd_done(IDEState *s) diff --git a/include/hw/ide/internal.h b/include/hw/ide/internal.h index efaabbd815..1bd93d0a30 100644 --- a/include/hw/ide/internal.h +++ b/include/hw/ide/internal.h @@ -624,6 +624,8 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val); =20 void ide_transfer_start(IDEState *s, uint8_t *buf, int size, EndTransferFunc *end_transfer_func); +bool ide_transfer_start_norecurse(IDEState *s, uint8_t *buf, int size, + EndTransferFunc *end_transfer_func); void ide_transfer_stop(IDEState *s); void ide_set_inactive(IDEState *s, bool more); BlockAIOCB *ide_issue_trim( --=20 2.14.3