From nobody Mon May 6 02:39:39 2024 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 1523979911155489.37194135192146; Tue, 17 Apr 2018 08:45:11 -0700 (PDT) Received: from localhost ([::1]:46210 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f8Sn8-0005Td-Ch for importer@patchew.org; Tue, 17 Apr 2018 11:45:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53432) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f8Si9-0001L6-H4 for qemu-devel@nongnu.org; Tue, 17 Apr 2018 11:40:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f8Si8-0005K5-34 for qemu-devel@nongnu.org; Tue, 17 Apr 2018 11:40:01 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:34604 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 1f8Si3-0005GT-AG; Tue, 17 Apr 2018 11:39:55 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 41B348DC47; Tue, 17 Apr 2018 15:39:52 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-116-72.ams2.redhat.com [10.36.116.72]) by smtp.corp.redhat.com (Postfix) with ESMTP id 72DD42026990; Tue, 17 Apr 2018 15:39:51 +0000 (UTC) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 17 Apr 2018 17:39:40 +0200 Message-Id: <20180417153945.20737-2-pbonzini@redhat.com> In-Reply-To: <20180417153945.20737-1-pbonzini@redhat.com> References: <20180417153945.20737-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Tue, 17 Apr 2018 15:39:52 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Tue, 17 Apr 2018 15:39:52 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'pbonzini@redhat.com' RCPT:'' Content-Transfer-Encoding: quoted-printable 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/6] ahci: move PIO Setup FIS before transfer, fix it for ATAPI commands 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: jsnow@redhat.com, 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-Type: text/plain; charset="utf-8" The PIO Setup FIS is written in the PIO:Entry state, which comes before the ATA and ATAPI data transfer states. As a result, the PIO Setup FIS interrupt is now raised before DMA ends for ATAPI commands, and tests have to be adjusted. This is also hinted by the description of the command header in the AHCI specification, where the "A" bit is described as When =E2=80=981=E2=80=99, indicates that a PIO setup FIS shall be sent = by the device indicating a transfer for the ATAPI command. and also by the description of the ACMD (ATAPI command region): The ATAPI command must be either 12 or 16 bytes in length. The length transmitted by the HBA is determined by the PIO setup FIS that is sent by the device requesting the ATAPI command. QEMU, which conflates the "generator" and the "receiver" of the FIS into one device, always uses ATAPI_PACKET_SIZE, aka 12, for the length. Signed-off-by: Paolo Bonzini --- hw/ide/ahci.c | 15 ++++++--------- tests/libqos/ahci.c | 30 ++++++++++++++++++++++++++---- tests/libqos/ahci.h | 2 ++ 3 files changed, 34 insertions(+), 13 deletions(-) diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c index e22d7be05f..45ce195fb8 100644 --- a/hw/ide/ahci.c +++ b/hw/ide/ahci.c @@ -1291,11 +1291,12 @@ static void ahci_start_transfer(IDEDMA *dma) int is_write =3D opts & AHCI_CMD_WRITE; int is_atapi =3D opts & AHCI_CMD_ATAPI; int has_sglist =3D 0; + uint16_t fis_len; =20 if (is_atapi && !ad->done_atapi_packet) { /* already prepopulated iobuffer */ ad->done_atapi_packet =3D true; - size =3D 0; + fis_len =3D size; goto out; } =20 @@ -1315,19 +1316,15 @@ static void ahci_start_transfer(IDEDMA *dma) } } =20 + /* Update number of transferred bytes, destroy sglist */ + dma_buf_commit(s, size); + fis_len =3D le32_to_cpu(ad->cur_cmd->status); out: /* declare that we processed everything */ s->data_ptr =3D s->data_end; - - /* Update number of transferred bytes, destroy sglist */ - dma_buf_commit(s, size); + ahci_write_fis_pio(ad, fis_len); =20 s->end_transfer_func(s); - - if (!(s->status & DRQ_STAT)) { - /* 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/tests/libqos/ahci.c b/tests/libqos/ahci.c index bc201d762b..04f33e246c 100644 --- a/tests/libqos/ahci.c +++ b/tests/libqos/ahci.c @@ -477,6 +477,23 @@ void ahci_port_check_d2h_sanity(AHCIQState *ahci, uint= 8_t port, uint8_t slot) g_free(d2h); } =20 +void ahci_port_check_pio_sanity_atapi(AHCIQState *ahci, uint8_t port, + uint8_t slot) +{ + PIOSetupFIS *pio =3D g_malloc0(0x20); + + /* We cannot check the Status or E_Status registers, because + * the status may have again changed between the PIO Setup FIS + * and the conclusion of the command with the D2H Register FIS. */ + qtest_memread(ahci->parent->qts, ahci->port[port].fb + 0x20, pio, 0x20= ); + g_assert_cmphex(pio->fis_type, =3D=3D, 0x5f); + + g_assert(le16_to_cpu(pio->tx_count) =3D=3D 12 || + le16_to_cpu(pio->tx_count) =3D=3D 16); + + g_free(pio); +} + void ahci_port_check_pio_sanity(AHCIQState *ahci, uint8_t port, uint8_t slot, size_t buffsize) { @@ -831,9 +848,9 @@ void ahci_command_enable_atapi_dma(AHCICommand *cmd) RegH2DFIS *fis =3D &(cmd->fis); g_assert(cmd->props->atapi); fis->feature_low |=3D 0x01; - cmd->interrupts &=3D ~AHCI_PX_IS_PSS; + /* PIO is still used to transfer the ATAPI command */ + g_assert(cmd->props->pio); cmd->props->dma =3D true; - cmd->props->pio =3D false; /* BUG: We expect the DMA Setup interrupt for DMA commands */ /* cmd->interrupts |=3D AHCI_PX_IS_DSS; */ } @@ -845,7 +862,7 @@ AHCICommand *ahci_command_create(uint8_t command_name) =20 g_assert(props); cmd =3D g_new0(AHCICommand, 1); - g_assert(!(props->dma && props->pio)); + g_assert(!(props->dma && props->pio) || props->atapi); g_assert(!(props->lba28 && props->lba48)); g_assert(!(props->read && props->write)); g_assert(!props->size || props->data); @@ -1216,7 +1233,12 @@ void ahci_command_verify(AHCIQState *ahci, AHCIComma= nd *cmd) ahci_port_check_d2h_sanity(ahci, port, slot); } if (cmd->props->pio) { - ahci_port_check_pio_sanity(ahci, port, slot, cmd->xbytes); + /* For ATAPI, we might have only used PIO for the command. */ + if (cmd->props->atapi && (!cmd->xbytes || cmd->props->dma)) { + ahci_port_check_pio_sanity_atapi(ahci, port, slot); + } else { + ahci_port_check_pio_sanity(ahci, port, slot, cmd->xbytes); + } } } =20 diff --git a/tests/libqos/ahci.h b/tests/libqos/ahci.h index 715ca1e226..cdba8099dd 100644 --- a/tests/libqos/ahci.h +++ b/tests/libqos/ahci.h @@ -598,6 +598,8 @@ void ahci_port_check_nonbusy(AHCIQState *ahci, uint8_t = port, uint8_t slot); void ahci_port_check_d2h_sanity(AHCIQState *ahci, uint8_t port, uint8_t sl= ot); void ahci_port_check_pio_sanity(AHCIQState *ahci, uint8_t port, uint8_t slot, size_t buffsize); +void ahci_port_check_pio_sanity_atapi(AHCIQState *ahci, uint8_t port, + uint8_t slot); void ahci_port_check_cmd_sanity(AHCIQState *ahci, AHCICommand *cmd); =20 /* Misc */ --=20 2.17.0 From nobody Mon May 6 02:39:39 2024 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 1523979762743425.88564890705686; Tue, 17 Apr 2018 08:42:42 -0700 (PDT) Received: from localhost ([::1]:46101 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f8Skj-0003C8-Vz for importer@patchew.org; Tue, 17 Apr 2018 11:42:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53413) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f8Si9-0001KX-66 for qemu-devel@nongnu.org; Tue, 17 Apr 2018 11:40:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f8Si8-0005KB-4U for qemu-devel@nongnu.org; Tue, 17 Apr 2018 11:40:01 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:42412 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 1f8Si3-0005GU-AN; Tue, 17 Apr 2018 11:39:55 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5241B81A88CC; Tue, 17 Apr 2018 15:39:53 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-116-72.ams2.redhat.com [10.36.116.72]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8298A2026DFD; Tue, 17 Apr 2018 15:39:52 +0000 (UTC) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 17 Apr 2018 17:39:41 +0200 Message-Id: <20180417153945.20737-3-pbonzini@redhat.com> In-Reply-To: <20180417153945.20737-1-pbonzini@redhat.com> References: <20180417153945.20737-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Tue, 17 Apr 2018 15:39:53 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Tue, 17 Apr 2018 15:39:53 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.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/6] ide: push end_transfer_func out of start_transfer callback, rename 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: jsnow@redhat.com, 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" Now that end_transfer_func is a tail call in ahci_start_transfer, formalize the fact that the callback (of which ahci_start_transfer is the sole implementation) takes care of the transfer too: rename it to pio_transfer and, if it is present, call the end_transfer_func as soon as it returns. Signed-off-by: Paolo Bonzini Reviewed-by: John Snow --- hw/ide/ahci.c | 15 +++++++-------- hw/ide/core.c | 8 +++++--- hw/ide/trace-events | 2 +- include/hw/ide/internal.h | 2 +- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c index 45ce195fb8..10bcc65308 100644 --- a/hw/ide/ahci.c +++ b/hw/ide/ahci.c @@ -1280,8 +1280,8 @@ out: return 0; } =20 -/* DMA dev <-> ram */ -static void ahci_start_transfer(IDEDMA *dma) +/* Transfer PIO data between RAM and device */ +static void ahci_pio_transfer(IDEDMA *dma) { AHCIDevice *ad =3D DO_UPCAST(AHCIDevice, dma, dma); IDEState *s =3D &ad->port.ifs[0]; @@ -1304,9 +1304,9 @@ static void ahci_start_transfer(IDEDMA *dma) has_sglist =3D 1; } =20 - trace_ahci_start_transfer(ad->hba, ad->port_no, is_write ? "writ" : "r= ead", - size, is_atapi ? "atapi" : "ata", - has_sglist ? "" : "o"); + trace_ahci_pio_transfer(ad->hba, ad->port_no, is_write ? "writ" : "rea= d", + size, is_atapi ? "atapi" : "ata", + has_sglist ? "" : "o"); =20 if (has_sglist && size) { if (is_write) { @@ -1319,12 +1319,11 @@ static void ahci_start_transfer(IDEDMA *dma) /* Update number of transferred bytes, destroy sglist */ dma_buf_commit(s, size); fis_len =3D le32_to_cpu(ad->cur_cmd->status); + out: /* declare that we processed everything */ s->data_ptr =3D s->data_end; ahci_write_fis_pio(ad, fis_len); - - s->end_transfer_func(s); } =20 static void ahci_start_dma(IDEDMA *dma, IDEState *s, @@ -1440,7 +1439,7 @@ static const IDEDMAOps ahci_dma_ops =3D { .start_dma =3D ahci_start_dma, .restart =3D ahci_restart, .restart_dma =3D ahci_restart_dma, - .start_transfer =3D ahci_start_transfer, + .pio_transfer =3D ahci_pio_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 866c659498..7932b7c069 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -527,16 +527,18 @@ 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->pio_transfer) { + s->end_transfer_func =3D end_transfer_func; + return; } + s->bus->dma->ops->pio_transfer(s->bus->dma); + end_transfer_func(s); } =20 static void ide_cmd_done(IDEState *s) diff --git a/hw/ide/trace-events b/hw/ide/trace-events index 0c39cabe72..77814618ee 100644 --- a/hw/ide/trace-events +++ b/hw/ide/trace-events @@ -101,7 +101,7 @@ handle_cmd_badport(void *s, int port) "ahci(%p)[%d]: gu= est accessed unused port" handle_cmd_badfis(void *s, int port) "ahci(%p)[%d]: guest provided an inva= lid cmd FIS" handle_cmd_badmap(void *s, int port, uint64_t len) "ahci(%p)[%d]: dma_memo= ry_map failed, 0x%02"PRIx64" !=3D 0x80" handle_cmd_unhandled_fis(void *s, int port, uint8_t b0, uint8_t b1, uint8_= t b2) "ahci(%p)[%d]: unhandled FIS type. cmd_fis: 0x%02x-%02x-%02x" -ahci_start_transfer(void *s, int port, const char *rw, uint32_t size, cons= t char *tgt, const char *sgl) "ahci(%p)[%d]: %sing %d bytes on %s w/%s sgli= st" +ahci_pio_transfer(void *s, int port, const char *rw, uint32_t size, const = char *tgt, const char *sgl) "ahci(%p)[%d]: %sing %d bytes on %s w/%s sglist" ahci_start_dma(void *s, int port) "ahci(%p)[%d]: start dma" ahci_dma_prepare_buf(void *s, int port, int32_t io_buffer_size, int32_t li= mit) "ahci(%p)[%d]: prepare buf limit=3D%"PRId32" prepared=3D%"PRId32 ahci_dma_prepare_buf_fail(void *s, int port) "ahci(%p)[%d]: sglist populat= ion failed" diff --git a/include/hw/ide/internal.h b/include/hw/ide/internal.h index 88212f59df..f3de6f9b73 100644 --- a/include/hw/ide/internal.h +++ b/include/hw/ide/internal.h @@ -444,7 +444,7 @@ struct IDEState { =20 struct IDEDMAOps { DMAStartFunc *start_dma; - DMAVoidFunc *start_transfer; + DMAVoidFunc *pio_transfer; DMAInt32Func *prepare_buf; DMAu32Func *commit_buf; DMAIntFunc *rw_buf; --=20 2.17.0 From nobody Mon May 6 02:39:39 2024 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 15239797338371003.4466281076678; Tue, 17 Apr 2018 08:42:13 -0700 (PDT) Received: from localhost ([::1]:46098 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f8SkG-0002pm-Vr for importer@patchew.org; Tue, 17 Apr 2018 11:42:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53395) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f8Si8-0001K0-Pa for qemu-devel@nongnu.org; Tue, 17 Apr 2018 11:40:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f8Si7-0005Jr-W9 for qemu-devel@nongnu.org; Tue, 17 Apr 2018 11:40:00 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:56336 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 1f8Si3-0005GV-A8; Tue, 17 Apr 2018 11:39:55 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8D8AC406E973; Tue, 17 Apr 2018 15:39:54 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-116-72.ams2.redhat.com [10.36.116.72]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9CB37202660D; Tue, 17 Apr 2018 15:39:53 +0000 (UTC) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 17 Apr 2018 17:39:42 +0200 Message-Id: <20180417153945.20737-4-pbonzini@redhat.com> In-Reply-To: <20180417153945.20737-1-pbonzini@redhat.com> References: <20180417153945.20737-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Tue, 17 Apr 2018 15:39:54 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Tue, 17 Apr 2018 15:39:54 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.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/6] ide: call ide_cmd_done from ide_transfer_stop 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: jsnow@redhat.com, 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 code can simply be moved to the sole caller that has notify =3D=3D true. Signed-off-by: Paolo Bonzini Reviewed-by: John Snow --- hw/ide/core.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/hw/ide/core.c b/hw/ide/core.c index 7932b7c069..edda171b47 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -549,26 +549,23 @@ 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); + 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.17.0 From nobody Mon May 6 02:39:39 2024 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 1523980052637408.2183077908261; Tue, 17 Apr 2018 08:47:32 -0700 (PDT) Received: from localhost ([::1]:46313 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f8SpP-0007OL-EM for importer@patchew.org; Tue, 17 Apr 2018 11:47:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53471) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f8SiD-0001Q8-7r for qemu-devel@nongnu.org; Tue, 17 Apr 2018 11:40:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f8Si7-0005JU-La for qemu-devel@nongnu.org; Tue, 17 Apr 2018 11:40:05 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:42416 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 1f8Si4-0005HE-56; Tue, 17 Apr 2018 11:39:56 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B649D81A88B7; Tue, 17 Apr 2018 15:39:55 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-116-72.ams2.redhat.com [10.36.116.72]) by smtp.corp.redhat.com (Postfix) with ESMTP id 022762024CA1; Tue, 17 Apr 2018 15:39:54 +0000 (UTC) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 17 Apr 2018 17:39:43 +0200 Message-Id: <20180417153945.20737-5-pbonzini@redhat.com> In-Reply-To: <20180417153945.20737-1-pbonzini@redhat.com> References: <20180417153945.20737-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Tue, 17 Apr 2018 15:39:55 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Tue, 17 Apr 2018 15:39:55 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.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/6] ide: make ide_transfer_stop idempotent 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: jsnow@redhat.com, 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. ide_transfer_cancel can then be removed, since it would just be calling ide_transfer_halt. Signed-off-by: Paolo Bonzini Reviewed-by: John Snow --- hw/ide/core.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/hw/ide/core.c b/hw/ide/core.c index edda171b47..bc3648eb13 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -548,10 +548,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; @@ -559,15 +558,10 @@ 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); ide_cmd_done(s); } =20 -static void ide_transfer_cancel(IDEState *s) -{ - ide_transfer_halt(s, ide_transfer_cancel); -} - int64_t ide_get_sector(IDEState *s) { int64_t sector_num; @@ -1362,7 +1356,7 @@ static bool cmd_nop(IDEState *s, uint8_t cmd) static bool cmd_device_reset(IDEState *s, uint8_t cmd) { /* Halt PIO (in the DRQ phase), then DMA */ - ide_transfer_cancel(s); + ide_transfer_halt(s); ide_cancel_dma_sync(s); =20 /* Reset any PIO commands, reset signature, etc */ --=20 2.17.0 From nobody Mon May 6 02:39:39 2024 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 1523979760934932.3608745616357; Tue, 17 Apr 2018 08:42:40 -0700 (PDT) Received: from localhost ([::1]:46100 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f8Ski-0003AP-1n for importer@patchew.org; Tue, 17 Apr 2018 11:42:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53403) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f8Si8-0001K9-T0 for qemu-devel@nongnu.org; Tue, 17 Apr 2018 11:40:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f8Si7-0005Jm-UA for qemu-devel@nongnu.org; Tue, 17 Apr 2018 11:40:00 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:34610 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 1f8Si5-0005Hj-6L; Tue, 17 Apr 2018 11:39:57 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BCA168DC47; Tue, 17 Apr 2018 15:39:56 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-116-72.ams2.redhat.com [10.36.116.72]) by smtp.corp.redhat.com (Postfix) with ESMTP id 04BAD2026990; Tue, 17 Apr 2018 15:39:55 +0000 (UTC) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 17 Apr 2018 17:39:44 +0200 Message-Id: <20180417153945.20737-6-pbonzini@redhat.com> In-Reply-To: <20180417153945.20737-1-pbonzini@redhat.com> References: <20180417153945.20737-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Tue, 17 Apr 2018 15:39:56 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Tue, 17 Apr 2018 15:39:56 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.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/6] 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: jsnow@redhat.com, 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 Acked-by: John Snow --- 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..7168ff55a7 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; @@ -304,13 +305,12 @@ 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); } + trace_ide_atapi_cmd_reply_end_new(s, s->status); 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); - ide_set_irq(s->bus); - trace_ide_atapi_cmd_reply_end_new(s, s->status); } } } --=20 2.17.0 From nobody Mon May 6 02:39:39 2024 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1523979898443975.421997550499; Tue, 17 Apr 2018 08:44:58 -0700 (PDT) Received: from localhost ([::1]:46203 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f8Smk-00058w-AT for importer@patchew.org; Tue, 17 Apr 2018 11:44:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53476) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f8SiD-0001Qb-M3 for qemu-devel@nongnu.org; Tue, 17 Apr 2018 11:40:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f8Si9-0005LF-FK for qemu-devel@nongnu.org; Tue, 17 Apr 2018 11:40:05 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:58886 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 1f8Si6-0005IK-DK; Tue, 17 Apr 2018 11:39:58 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F246AEFDE1; Tue, 17 Apr 2018 15:39:57 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-116-72.ams2.redhat.com [10.36.116.72]) by smtp.corp.redhat.com (Postfix) with ESMTP id 091992026DFD; Tue, 17 Apr 2018 15:39:56 +0000 (UTC) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 17 Apr 2018 17:39:45 +0200 Message-Id: <20180417153945.20737-7-pbonzini@redhat.com> In-Reply-To: <20180417153945.20737-1-pbonzini@redhat.com> References: <20180417153945.20737-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 17 Apr 2018 15:39:58 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 17 Apr 2018 15:39:58 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.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 6/6] 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: jsnow@redhat.com, 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 Reviewed-by: John Snow --- hw/ide/atapi.c | 42 +++++++++++++++++++++------------------ hw/ide/core.c | 16 +++++++++++---- include/hw/ide/internal.h | 2 ++ 3 files changed, 37 insertions(+), 23 deletions(-) diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c index 7168ff55a7..39e473f9c2 100644 --- a/hw/ide/atapi.c +++ b/hw/ide/atapi.c @@ -245,15 +245,11 @@ static uint16_t atapi_byte_count_limit(IDEState *s) void ide_atapi_cmd_reply_end(IDEState *s) { int byte_count_limit, size, ret; - 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) { + trace_ide_atapi_cmd_reply_end(s, s->packet_transfer_size, + s->elementary_transfer_size, + s->io_buffer_index); + /* 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 +275,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; @@ -306,13 +297,26 @@ void ide_atapi_cmd_reply_end(IDEState *s) size =3D (s->cd_sector_size - s->io_buffer_index); } trace_ide_atapi_cmd_reply_end_new(s, s->status); - 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); + } + 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 */ + trace_ide_atapi_cmd_reply_end_eot(s, s->status); + ide_atapi_cmd_ok(s); + ide_set_irq(s->bus); } =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 bc3648eb13..9884df0e2e 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -524,8 +524,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; @@ -535,10 +535,18 @@ void ide_transfer_start(IDEState *s, uint8_t *buf, in= t size, } if (!s->bus->dma->ops->pio_transfer) { s->end_transfer_func =3D end_transfer_func; - return; + return false; } s->bus->dma->ops->pio_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 f3de6f9b73..594081e57f 100644 --- a/include/hw/ide/internal.h +++ b/include/hw/ide/internal.h @@ -623,6 +623,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.17.0