From nobody Sun Nov 29 10:11:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1795806842; cv=none; d=zohomail.com; s=zohoarc; b=iH5QsAXGNJUktpa+4EBaqgO6oWMi8Y0cZW31viDKBK2XEKu4J8xV0pkWz8hYoLHTTBrOWdY3B4wswbVSiwU+QcnlwXpNiHIHjGky43Az4OQM8HVR5apxObExDwHydXmdgRyOjTtf5yzfehw1JIs7lIqQnaxyHSTJh+Z3Z9uoFNc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1795806842; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=NIA6vEM+YcWX1sXh5hJuHyoqPH1OUdZMzydKosMLNqA=; b=VelmSoWP+s9kDRMbsVIWYX/+NjqYsAQP7kaRAmses3553OnuA1hIJObRzGNhNozCKYLOhGOWKwR0RQW8r1sb74RL4ThRDxhQayZIAMpmPvzZly1fILPQVRP4MVJ2q7O9EkytMn24uJRHLJp1mJJcB3q6ILCky/ltkwSYOduxWOc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1795806842120387.4578952498508; Fri, 27 Nov 2026 11:14:02 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xX1Nf-0001m5-F9; Fri, 27 Nov 2026 14:13:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xX1NY-0001k2-G7; Fri, 27 Nov 2026 14:13:05 -0500 Received: from sea.source.kernel.org ([172.234.252.31]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xX1NW-0005r6-J3; Fri, 27 Nov 2026 14:13:04 -0500 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 3ED15418B9; Fri, 27 Nov 2026 19:13:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B586A1F000C1; Fri, 27 Nov 2026 19:12:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795806780; bh=NIA6vEM+YcWX1sXh5hJuHyoqPH1OUdZMzydKosMLNqA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=WpSzX5NGFodGaasMPe1dhH+2niF5Ygcp6j5HOhl2ghqLKEf0Ih//HWps7P3F0PgHv uD909N/IFSflYlmJmLVjfsJtrZRRMvjy1MnJOhwrHp1ZBDcOBdsjRehM+XAEHtSAUO tZYG4Np+GGB9rQBBQdMfyfeliU+CmT4KhrfGJ6rrL6pCotL364/ncMDSsbIlN/7J+A 3nfTnerdR2tdaz6BVh/jgjSs8YR62vfvHcI6EgOFOdYK0jdI1ky1cbR26LZ5LM2SuR D+wX2pYz9GR6HooSsxKD5qzEamL6azgZCONajk8ajP4R8SIEDB+BbhKxU8VIstmJzV aaJrqbevkYnfw== From: Niklas Cassel To: John Snow , "Denis V. Lunev" Cc: Damien Le Moal , Niklas Cassel , qemu-block@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH 01/13] hw/ide: report the SMART state in IDENTIFY DEVICE Date: Fri, 27 Nov 2026 20:12:36 +0100 Message-ID: <20261127191250.3298004-2-cassel@kernel.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261127191250.3298004-1-cassel@kernel.org> References: <20261127191250.3298004-1-cassel@kernel.org> 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+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=172.234.252.31; envelope-from=cassel@kernel.org; helo=sea.source.kernel.org X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1795806844007158500 Content-Type: text/plain; charset="utf-8" Currently, IDENTIFY DEVICE word 85 bit 0 always reports the SMART feature set as enabled, regardless if it has been disabled using SET FEATURES or SMART DISABLE OPERATIONS. Add a helper to build word85, such that the SMART feature set and the write cache is reported in IDENTIFY DEVICE correctly. Also, just like the write cache state is re-initialized after migration, re-initialize the SMART state after migration. Signed-off-by: Niklas Cassel --- hw/ide/core.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/hw/ide/core.c b/hw/ide/core.c index 06e6bb6067..7e3f882969 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -138,6 +138,14 @@ static void ide_identify_size(IDEState *s) put_le16(p + 103, s->nb_sectors >> 48); } =20 +/* IDENTIFY DEVICE word 85: the commands and feature sets that are enabled= */ +static uint16_t ide_identify_word85(IDEState *s) +{ + /* 14 =3D NOP supported, 5=3DWCACHE enabled, 0=3DSMART feature set ena= bled */ + return (1 << 14) | (blk_enable_write_cache(s->blk) ? 1 << 5 : 0) | + (s->smart_enabled ? 1 : 0); +} + static void ide_identify(IDEState *s) { uint16_t *p; @@ -204,12 +212,7 @@ static void ide_identify(IDEState *s) } else { put_le16(p + 84, (1 << 14) | 0); } - /* 14 =3D NOP supported, 5=3DWCACHE enabled, 0=3DSMART feature set ena= bled */ - if (blk_enable_write_cache(s->blk)) { - put_le16(p + 85, (1 << 14) | (1 << 5) | 1); - } else { - put_le16(p + 85, (1 << 14) | 1); - } + put_le16(p + 85, ide_identify_word85(s)); /* 13=3Dflush_cache_ext,12=3Dflush_cache,10=3Dlba48 */ put_le16(p + 86, (1 << 13) | (1 <<12) | (1 << 10)); /* 14=3Dset to 1, 8=3Dhas WWN, 1=3DSMART self test, 0=3DSMART error lo= gging */ @@ -1714,12 +1717,12 @@ static bool cmd_set_features(IDEState *s, uint8_t c= md) case 0x02: /* write cache enable */ blk_set_enable_write_cache(s->blk, true); identify_data =3D (uint16_t *)s->identify_data; - put_le16(identify_data + 85, (1 << 14) | (1 << 5) | 1); + put_le16(identify_data + 85, ide_identify_word85(s)); return true; case 0x82: /* write cache disable */ blk_set_enable_write_cache(s->blk, false); identify_data =3D (uint16_t *)s->identify_data; - put_le16(identify_data + 85, (1 << 14) | 1); + put_le16(identify_data + 85, ide_identify_word85(s)); ide_flush_cache(s); return false; case 0xcc: /* reverting to power-on defaults enable */ @@ -1942,11 +1945,9 @@ static bool cmd_smart(IDEState *s, uint8_t cmd) =20 switch (s->feature) { case SMART_DISABLE: - s->smart_enabled =3D 0; - return true; - case SMART_ENABLE: - s->smart_enabled =3D 1; + s->smart_enabled =3D s->feature =3D=3D SMART_ENABLE; + put_le16((uint16_t *)s->identify_data + 85, ide_identify_word85(s)= ); return true; =20 case SMART_ATTR_AUTOSAVE: @@ -2901,6 +2902,7 @@ static int ide_drive_post_load(void *opaque, int vers= ion_id) =20 if (s->blk && s->identify_set) { blk_set_enable_write_cache(s->blk, !!(s->identify_data[85] & (1 <<= 5))); + s->smart_enabled =3D s->identify_data[85] & 1; } return 0; } --=20 2.56.1 From nobody Sun Nov 29 10:11:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1795806841; cv=none; d=zohomail.com; s=zohoarc; b=kTI4aZkod0BCR6iUoTVJOaiga0s8hJZg4YOKwdoy12oJSLNk5EuQTHUj/RHTSCAK0uNs59f9OSw2ecVdv7R30NL3k85ilGt4w4VJEtq+P/EfnX2JkbMWu62Oux4xfmeY40oVJQPJxdQv+GL8Qb1OL36O/8Wejq8kkcOZ08Qzljc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1795806841; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=IUugToqMokQ3XaxPMoFuFHHc5lLNWbQ5b99sDropAdA=; b=JOUOuLOuYvOoXgOBbkm9Jfc8aQFcXR4LmYnnaQyPRDHsXN1NpX1l8QvusxEqS2YD9vGjfCYkNCLJV4Pu1yyvjvRqNNIPHJQBc9g4qb0kmZv5xbGEX7OzplggKLQwyHxjS+P7LHWt971XJ27QSfMtyEPMSwO7gWw64XytEtAUkzk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1795806841838133.9582468897794; Fri, 27 Nov 2026 11:14:01 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xX1Nm-0001on-TY; Fri, 27 Nov 2026 14:13:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xX1Na-0001kW-Ak; Fri, 27 Nov 2026 14:13:06 -0500 Received: from sea.source.kernel.org ([172.234.252.31]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xX1NY-0005sY-59; Fri, 27 Nov 2026 14:13:06 -0500 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id B3CA6449CE; Fri, 27 Nov 2026 19:13:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A7AD61F00893; Fri, 27 Nov 2026 19:13:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795806782; bh=IUugToqMokQ3XaxPMoFuFHHc5lLNWbQ5b99sDropAdA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=i+H3aYnQvBG8XfnA/cPOnSeyfys3qQS4qOh+FovR5FccZc/sZeQmt0gu48vsCdXVE wFGwNF4WvFoz7GUkIXdefQAqzbjUqFTp1J9Ci950XsSR/0mvayxsPyBhAWhQbpkC+5 VGMsk1MJf12GYghJmVL6MSlZCesZUsCx9zUbm5Em46JDrw5tATenvucxzUucl3hpcK qLpnzxa3pNzPSnlInyIw6oK9TtjlhQM+gdZbYfEbgkwAXQ35HyMRc39PppFoFT01jh qllkYsTeF5Kvx9X8L0D3NUnljPol2+y0KTntPVXp3eKmAUBkeERQjT5km9ot2zp+gr wE+J1b0uGO6hg== From: Niklas Cassel To: John Snow , "Denis V. Lunev" , Fabiano Rosas , Laurent Vivier , Paolo Bonzini Cc: Damien Le Moal , Niklas Cassel , qemu-block@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH 02/13] hw/ide/ahci: stop processing commands after a fatal error Date: Fri, 27 Nov 2026 20:12:37 +0100 Message-ID: <20261127191250.3298004-3-cassel@kernel.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261127191250.3298004-1-cassel@kernel.org> References: <20261127191250.3298004-1-cassel@kernel.org> 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+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=172.234.252.31; envelope-from=cassel@kernel.org; helo=sea.source.kernel.org X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1795806843767158500 Content-Type: text/plain; charset="utf-8" As per AHCI 1.3.1, 6.2.2, after a fatal error, the HBA should not process any further commands until software clears PxCMD.ST. This was previously missing in the QEMU model, which emulates both both the drive and the HBA. Previously, QEMU went on processing commands, and as a failed command keeps its bit in PxCI, check_cmd() executed it again when the host issued another command without restarting the port. Add a new state that halts the port after a fatal error. Linux, SeaBIOS and libqos already restart the port using PxCMD.ST after an error. Add a qtest that checks that a command issued after a failed WRITE DMA EXT, without restarting the port, is not processed, and that the failed write is not executed again. Fixes: 1a16ce64fda1 ("hw/ide/ahci: PxCI should not get cleared when ERR_STA= T is set") Signed-off-by: Niklas Cassel --- hw/ide/ahci-internal.h | 4 +++ hw/ide/ahci.c | 39 ++++++++++++++++++++++++- tests/qtest/ahci-test.c | 63 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+), 1 deletion(-) diff --git a/hw/ide/ahci-internal.h b/hw/ide/ahci-internal.h index a318f36811..ca11a370c7 100644 --- a/hw/ide/ahci-internal.h +++ b/hw/ide/ahci-internal.h @@ -165,6 +165,9 @@ enum AHCIPortIRQ { #define DEF_PORT_IRQ (PORT_IRQ_ERROR | PORT_IRQ_SG_DONE | = \ PORT_IRQ_SDB_FIS | PORT_IRQ_DMAS_FIS | = \ PORT_IRQ_PIOS_FIS | PORT_IRQ_D2H_REG_FI= S) +/* The fatal errors, after which the HBA stops (AHCI 1.3.1 6.2.2) */ +#define PORT_IRQ_FATAL (PORT_IRQ_TF_ERR | PORT_IRQ_HBUS_ERR | = \ + PORT_IRQ_HBUS_DATA_ERR | PORT_IRQ_IF_ER= R) =20 /* PORT_CMD bits */ #define PORT_CMD_ATAPI (1 << 24) /* Device is ATAPI */ @@ -318,6 +321,7 @@ struct AHCIDevice { bool done_first_drq; int32_t busy_slot; bool init_d2h_sent; + bool halted; /* fatal error (PxIS.TFES), until PxCMD.ST is cleared */ AHCICmdHdr *cur_cmd; NCQTransferState ncq_tfs[AHCI_MAX_CMDS]; MemReentrancyGuard mem_reentrancy_guard; diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c index 86f6297dc9..3b872c6cf1 100644 --- a/hw/ide/ahci.c +++ b/hw/ide/ahci.c @@ -208,6 +208,13 @@ static void ahci_trigger_irq(AHCIState *s, AHCIDevice = *d, irqstat & d->port_regs.irq_mask); =20 d->port_regs.irq_stat =3D irqstat; + /* + * A fatal error halts the port until PxCMD.ST is cleared + * (AHCI 1.3.1 6.2.2). + */ + if (irq & PORT_IRQ_FATAL) { + d->halted =3D true; + } ahci_check_irq(s); } =20 @@ -301,6 +308,7 @@ static void ahci_port_write(AHCIState *s, int port, int= offset, uint32_t val) if ((pr->cmd & PORT_CMD_START) && !(val & PORT_CMD_START)) { pr->scr_act =3D 0; pr->cmd_issue =3D 0; + s->dev[port].halted =3D false; } =20 /* Block any Read-only fields from being set; @@ -565,7 +573,13 @@ static void check_cmd(AHCIState *s, int port) uint8_t slot; =20 if ((pr->cmd & PORT_CMD_START) && pr->cmd_issue) { - for (slot =3D 0; (slot < 32) && pr->cmd_issue; slot++) { + /* + * After a fatal error the HBA processes no commands until software + * clears PxCMD.ST (AHCI 1.3.1 6.2.2). A command can fail before + * handle_cmd() returns, so check before each slot. + */ + for (slot =3D 0; (slot < 32) && pr->cmd_issue && !s->dev[port].hal= ted; + slot++) { if (pr->cmd_issue & (1U << slot)) { handle_cmd(s, port, slot); } @@ -664,6 +678,7 @@ static void ahci_reset_port(AHCIState *s, int port, IDE= ResetKind kind) pr->cmd_issue =3D 0; d->busy_slot =3D -1; d->init_d2h_sent =3D false; + d->halted =3D false; =20 ide_state =3D &s->dev[port].port.ifs[0]; if (!ide_state->blk) { @@ -1738,6 +1753,24 @@ static const VMStateDescription vmstate_ncq_tfs =3D { }, }; =20 +static bool ahci_device_halted_needed(void *opaque) +{ + AHCIDevice *ad =3D opaque; + + return ad->halted; +} + +static const VMStateDescription vmstate_ahci_device_halted =3D { + .name =3D "ahci port/halted", + .version_id =3D 1, + .minimum_version_id =3D 1, + .needed =3D ahci_device_halted_needed, + .fields =3D (const VMStateField[]) { + VMSTATE_BOOL(halted, AHCIDevice), + VMSTATE_END_OF_LIST() + }, +}; + static const VMStateDescription vmstate_ahci_device =3D { .name =3D "ahci port", .version_id =3D 1, @@ -1767,6 +1800,10 @@ static const VMStateDescription vmstate_ahci_device = =3D { 1, vmstate_ncq_tfs, NCQTransferState), VMSTATE_END_OF_LIST() }, + .subsections =3D (const VMStateDescription * const []) { + &vmstate_ahci_device_halted, + NULL + }, }; =20 static int ahci_state_post_load(void *opaque, int version_id) diff --git a/tests/qtest/ahci-test.c b/tests/qtest/ahci-test.c index 291f29e762..6acb2327e3 100644 --- a/tests/qtest/ahci-test.c +++ b/tests/qtest/ahci-test.c @@ -1169,6 +1169,68 @@ static void test_flush_retry(void) ahci_shutdown(ahci); } =20 +/* + * After a command fails, the HBA processes no further commands until soft= ware + * clears PxCMD.ST (AHCI 1.3.1 6.2.2), so it does not execute the failed + * command again either. + */ +static void test_halt_after_error(void) +{ + g_autofree unsigned char *before =3D g_malloc(512); + g_autofree unsigned char *tx =3D g_malloc(512); + g_autofree unsigned char *rx =3D g_malloc(512); + AHCIQState *ahci; + AHCICommand *cmd; + uint32_t pending; + uint64_t ptr; + unsigned px; + + prepare_blkdebug_script(debug_path, "write_aio"); + ahci =3D ahci_boot_and_enable("-drive file=3Dblkdebug:%s:%s,if=3Dnone,= id=3Ddrive0," + "format=3D%s -M q35 -device ide-hd,drive= =3Ddrive0", + debug_path, tmp_path, imgfmt); + px =3D ahci_port_select(ahci); + ahci_port_clear(ahci, px); + ahci_io(ahci, px, CMD_READ_DMA_EXT, before, 512, 0); + memset(tx, before[0] ^ 0xff, 512); + + /* A WRITE DMA EXT that fails with the injected I/O error */ + ptr =3D ahci_alloc(ahci, 512); + qtest_bufwrite(ahci->parent->qts, ptr, tx, 512); + cmd =3D ahci_command_create(CMD_WRITE_DMA_EXT); + ahci_command_set_buffer(cmd, ptr); + ahci_command_set_size(cmd, 512); + ahci_command_commit(ahci, cmd, px); + ahci_command_issue(ahci, cmd); + /* Not ahci_command_verify(), which would restart the port */ + g_assert_cmphex(ahci_px_rreg(ahci, px, AHCI_PX_IS) & AHCI_PX_IS_TFES, + !=3D, 0); + ahci_command_free(cmd); + + /* A command issued without restarting the port is not processed */ + cmd =3D ahci_command_create(CMD_READ_DMA_EXT); + ahci_command_set_buffer(cmd, ptr); + ahci_command_set_size(cmd, 512); + ahci_command_commit(ahci, cmd, px); + ahci_command_issue_async(ahci, cmd); + /* Nothing to poll for: give the command time to be processed */ + g_usleep(50 * 1000); + pending =3D ahci_px_rreg(ahci, px, AHCI_PX_CI) & + (1u << ahci_command_slot(cmd)); + ahci_command_free(cmd); + ahci_free(ahci, ptr); + + /* Restarting the port drops it; the sector still has its old data */ + ahci_px_clr(ahci, px, AHCI_PX_CMD, AHCI_PX_CMD_ST); + ahci_port_clear(ahci, px); + ahci_px_set(ahci, px, AHCI_PX_CMD, AHCI_PX_CMD_ST); + ahci_io(ahci, px, CMD_READ_DMA_EXT, rx, 512, 0); + g_assert_cmphex(memcmp(rx, before, 512), =3D=3D, 0); + g_assert_cmphex(pending, !=3D, 0); + + ahci_shutdown(ahci); +} + /** * Basic sanity test to boot a machine, find an AHCI device, and shutdown. */ @@ -2404,6 +2466,7 @@ int main(int argc, char **argv) =20 qtest_add_func("/ahci/flush/simple", test_flush); qtest_add_func("/ahci/flush/retry", test_flush_retry); + qtest_add_func("/ahci/io/dma/halt_after_error", test_halt_after_error); qtest_add_func("/ahci/flush/migrate", test_flush_migrate); =20 qtest_add_func("/ahci/migrate/sanity", test_migrate_sanity); --=20 2.56.1 From nobody Sun Nov 29 10:11:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1795806888; cv=none; d=zohomail.com; s=zohoarc; b=BeYI9SFXMVtqh2ed200Rg6SHqAYX+NrcoqntTCdq6w3WAa13YbgJ63Bz4Edj9my4JJ5nN4Z4omTAr3pw9TZzuNWCh1MS2OoOvAD33oPeWV51Olpj7sAZYIGl0uY/vsxy8y2V1lXPhc+hRTOQNrPFlXuSEHYvTSJZtI325S6gcsI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1795806888; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=hiMVmofQ9le2uPTR29ckErclhqD5uTB1ww31I+XjsWE=; b=a5zurRwC0WNX9z/4LGnoNakSOsT4FzSTbW6T+4mvYAAN/q6sBd/o/sygIwZGLJ0JQOLZKBbI+wiQmniuGEGGhBoZ16XguWssBfIat+P6lHgQcSxSCKXKdUcXxOF2UcIGAaWDLhnW1pySX1Kciu5UjzQsuMfymiREqNwq/WInmpo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1795806888667969.4259729644456; Fri, 27 Nov 2026 11:14:48 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xX1Nn-0001p1-1g; Fri, 27 Nov 2026 14:13:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xX1Nc-0001lU-9o; Fri, 27 Nov 2026 14:13:09 -0500 Received: from tor.source.kernel.org ([172.105.4.254]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xX1Na-00065B-E9; Fri, 27 Nov 2026 14:13:08 -0500 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 626E6611C7; Fri, 27 Nov 2026 19:13:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 23E9E1F00893; Fri, 27 Nov 2026 19:13:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795806785; bh=hiMVmofQ9le2uPTR29ckErclhqD5uTB1ww31I+XjsWE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Uzetn6X4t+JSzNts8ly/qXjiYnDz9D077n8BUTrFmGRjxI5qlhvQWcKFkmMqGKipT 1d2D8mhj7lqIq4NhOkFobRtEOEWfpw8vCW36RuGxUVRt8Ja6Gzr6+0UJnzu64+Nnia eu37I+kcVFgBK91NdmXQ5dOYyrym1mulqjpgc2Eswl/ZjADeAroKdGEOUm2KvWG1QK gKJYMnuyaqVLwsBfLaxSf3FPtYKEH9+lP7Zxji2iU4I9MDJ+3I3rPpoh2MwxsdXjGY CcbeJgKkV3XjUOJuwPYYs8cP0K6RSL1B1m3jCAHkUl0zvih1hLXUH3gtVM+Vn2vKhu xr1quBbjIHPjA== From: Niklas Cassel To: John Snow , "Denis V. Lunev" , Fabiano Rosas , Laurent Vivier , Paolo Bonzini Cc: Damien Le Moal , Niklas Cassel , qemu-block@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH 03/13] hw/ide/ahci: clear a stale error status when an NCQ command is queued Date: Fri, 27 Nov 2026 20:12:38 +0100 Message-ID: <20261127191250.3298004-4-cassel@kernel.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261127191250.3298004-1-cassel@kernel.org> References: <20261127191250.3298004-1-cassel@kernel.org> 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+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=172.105.4.254; envelope-from=cassel@kernel.org; helo=tor.source.kernel.org X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1795806890186158500 Content-Type: text/plain; charset="utf-8" Successfully queueing an NCQ command should clear ERR_STAT, BUSY and DRQ, see ACS-6 table 369 and SATA 3.5a DFPDMAQ2. Simply restarting the port after a fatal error does not clear ERR_STAT. The task file status in PxTFD only changes when the device sends a FIS, i.e. when queueing a new NCQ command. Without this, we would incorrectly again enter the HBA stopped state when queueing a new NCQ command after restarting the port. Add a qtest that issues an NCQ command after a failed WRITE DMA EXT. Fixes: 2967dc8209dd ("hw/ide/ahci: write D2H FIS when processing NCQ comman= d") Signed-off-by: Niklas Cassel --- hw/ide/ahci.c | 9 ++++-- tests/qtest/ahci-test.c | 61 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 3 deletions(-) diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c index 3b872c6cf1..e3ae46e869 100644 --- a/hw/ide/ahci.c +++ b/hw/ide/ahci.c @@ -1150,13 +1150,16 @@ static void process_ncq_command(AHCIState *s, int p= ort, const uint8_t *cmd_fis, =20 /* * A NCQ command clears the bit in PxCI after the command has been QUE= UED - * successfully (ERROR not set, BUSY and DRQ cleared). - * - * For NCQ commands, PxCI will always be cleared here. + * successfully (ERROR not set, BUSY and DRQ cleared). A device reports + * this status for every command that it queues (SATA 3.5a DFPDMAQ2, + * ACS-6 table 369), whatever the status of the previous command was, = so + * PxCI will always be cleared here. * * (Once the NCQ command is COMPLETED, the device will send a SDB FIS = with * the interrupt bit set, which will clear PxSACT and raise an interru= pt.) */ + ad->port.ifs[0].status =3D READY_STAT | SEEK_STAT; + ad->port.ifs[0].error =3D 0; ahci_clear_cmd_issue(ad, slot); =20 /* diff --git a/tests/qtest/ahci-test.c b/tests/qtest/ahci-test.c index 6acb2327e3..2b668ea708 100644 --- a/tests/qtest/ahci-test.c +++ b/tests/qtest/ahci-test.c @@ -1169,6 +1169,66 @@ static void test_flush_retry(void) ahci_shutdown(ahci); } =20 +/* + * An NCQ command issued after a failed non-NCQ command is queued with BSY, + * DRQ and ERR cleared (SATA 3.5a DFPDMAQ2), so its PxCI bit is cleared and + * it completes without the error of the earlier command. + */ +static void test_ncq_after_error(void) +{ + AHCIQState *ahci; + AHCICommand *cmd; + uint32_t bit; + uint64_t ptr; + uint8_t px; + int i; + + prepare_blkdebug_script(debug_path, "write_aio"); + ahci =3D ahci_boot_and_enable("-drive file=3Dblkdebug:%s:%s,if=3Dnone,= id=3Ddrive0," + "format=3D%s -M q35 -device ide-hd,drive= =3Ddrive0", + debug_path, tmp_path, imgfmt); + px =3D ahci_port_select(ahci); + ahci_port_clear(ahci, px); + + /* A WRITE DMA EXT that fails with the injected I/O error */ + ptr =3D ahci_alloc(ahci, 512); + cmd =3D ahci_command_create(CMD_WRITE_DMA_EXT); + ahci_command_set_buffer(cmd, ptr); + ahci_command_set_size(cmd, 512); + ahci_command_commit(ahci, cmd, px); + ahci_command_issue(ahci, cmd); + g_assert_cmphex(ahci_px_rreg(ahci, px, AHCI_PX_IS) & AHCI_PX_IS_TFES, + !=3D, 0); + ahci_command_free(cmd); + + /* Restart the port, as after any error (AHCI 1.3.1 6.2.2.1) */ + ahci_px_clr(ahci, px, AHCI_PX_CMD, AHCI_PX_CMD_ST); + ahci_port_clear(ahci, px); + ahci_px_set(ahci, px, AHCI_PX_CMD, AHCI_PX_CMD_ST); + + cmd =3D ahci_command_create(READ_FPDMA_QUEUED); + ahci_command_set_buffer(cmd, ptr); + ahci_command_set_size(cmd, 512); + ahci_command_commit(ahci, cmd, px); + ahci_command_issue_async(ahci, cmd); + bit =3D 1u << ahci_command_slot(cmd); + for (i =3D 0; i < 100000 && (ahci_px_rreg(ahci, px, AHCI_PX_SACT) & bi= t); + i++) { + usleep(50); + } + g_assert_cmphex(ahci_px_rreg(ahci, px, AHCI_PX_SACT) & bit, =3D=3D, 0); + /* The command was acknowledged without an error, and PxCI cleared */ + g_assert_cmphex(ahci_px_rreg(ahci, px, AHCI_PX_IS) & AHCI_PX_IS_TFES, + =3D=3D, 0); + g_assert_cmphex(ahci_px_rreg(ahci, px, AHCI_PX_CI) & bit, =3D=3D, 0); + /* STS.ERR and the ERR field: nothing left from the failed command */ + g_assert_cmphex(ahci_px_rreg(ahci, px, AHCI_PX_TFD) & 0xff01, =3D=3D, = 0); + + ahci_command_free(cmd); + ahci_free(ahci, ptr); + ahci_shutdown(ahci); +} + /* * After a command fails, the HBA processes no further commands until soft= ware * clears PxCMD.ST (AHCI 1.3.1 6.2.2), so it does not execute the failed @@ -2466,6 +2526,7 @@ int main(int argc, char **argv) =20 qtest_add_func("/ahci/flush/simple", test_flush); qtest_add_func("/ahci/flush/retry", test_flush_retry); + qtest_add_func("/ahci/io/ncq/after_error", test_ncq_after_error); qtest_add_func("/ahci/io/dma/halt_after_error", test_halt_after_error); qtest_add_func("/ahci/flush/migrate", test_flush_migrate); =20 --=20 2.56.1 From nobody Sun Nov 29 10:11:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1795806883; cv=none; d=zohomail.com; s=zohoarc; b=GrVfzTowZ6k05dsxPGk9p/W0N8ELT9XqdT5/o07OoJL4t+a8F5tOuFELyh91daaXY/UEVNFYDwXhoIxGVIoZzrrofR3Bx1OK8yUtuCGWlHuVGGw88I+QU6/ltxinvwL7mdWCP0RwhZL1zkAy5h8ILCIGmLykP+5BmrgERUdD0sM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1795806883; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=uroSrAqj9LH1phzTsP/8O/Nv8k16SbW9CDugRtmdQFI=; b=Bz9AdjPCE8epu6FOHe3ZgAOw8bpPYu+AO5MH06iGA1A/og6u8yvGfHNeMsX7tDtmK95jhiJr8BSsfqzUkXwFoaM3BLKNhyf4jlwL88xMZeAy4y0BhzONLe0C48OeGnQuqj8CfmEWMZ/UirHouCAaJft1MPnGNEBTsEnX/QQHh7Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17958068833621022.0116894546545; Fri, 27 Nov 2026 11:14:43 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xX1No-0001qA-Rq; Fri, 27 Nov 2026 14:13:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xX1Ne-0001m4-3C; Fri, 27 Nov 2026 14:13:11 -0500 Received: from sea.source.kernel.org ([2600:3c0a:e001:78e:0:1991:8:25]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xX1Nc-0006EC-Ds; Fri, 27 Nov 2026 14:13:09 -0500 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 1FA8540950; Fri, 27 Nov 2026 19:13:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 980A41F00893; Fri, 27 Nov 2026 19:13:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795806787; bh=uroSrAqj9LH1phzTsP/8O/Nv8k16SbW9CDugRtmdQFI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Uk/Ya73gIeqWvwwczqzQ5D3cVNMEb/5NeZsR6OeLBMiw2Swf7q7SCj1WClArSQo9W /h+5ybhZk2K+4BblgGusEernqjBlq/bC4T4ExqEkHruHEzXBJ4UvAbkgT2xaM4C0ru Oyj6AaL5lFpj1zRMwDEMFeoYPIzVsPqjD3PsC+N3wWWSBJnPz0jM0K5vKJyj2ssI01 kyEAJtzviBsMt/FASWdv9gzo/UMdxIRxPTya+DX9J0b612K/ERt2UIcZ2UEw/jEWYN Ga+HJQYJWiWq7F6eR5OeDoXl9BLL8PPthWI6gWcjY/t9VWzDm9OVWmoFRfrQn8M6pR 9BKX9HiFFfaUg== From: Niklas Cassel To: John Snow , "Denis V. Lunev" Cc: Damien Le Moal , Niklas Cassel , qemu-block@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH 04/13] hw/ide/ahci: complete unsupported NCQ commands Date: Fri, 27 Nov 2026 20:12:39 +0100 Message-ID: <20261127191250.3298004-5-cassel@kernel.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261127191250.3298004-1-cassel@kernel.org> References: <20261127191250.3298004-1-cassel@kernel.org> 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+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2600:3c0a:e001:78e:0:1991:8:25; envelope-from=cassel@kernel.org; helo=sea.source.kernel.org X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1795806883905158500 Content-Type: text/plain; charset="utf-8" execute_ncq_command() aborts an NCQ command that it does not implement (e.g. SEND FPDMA QUEUED) with ncq_err(), but does not call ncq_finish(). This means that no Set Device Bits FIS is sent, so the command never completes. Linux will eventually notice a timeout and reset the port, however, the the proper thing to do is to send a SDB FIS after calling ncq_err() such that the host gets an IRQ. Fixes: 72a065dbb13d ("ahci: add is_ncq predicate helper") Signed-off-by: Niklas Cassel --- hw/ide/ahci.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c index e3ae46e869..e14b298ea6 100644 --- a/hw/ide/ahci.c +++ b/hw/ide/ahci.c @@ -1127,6 +1127,7 @@ static void execute_ncq_command(NCQTransferState *ncq= _tfs) trace_execute_ncq_command_unsup(ad->hba, port, ncq_tfs->tag, ncq_tfs->cmd); ncq_err(ncq_tfs); + ncq_finish(ncq_tfs); } } =20 --=20 2.56.1 From nobody Sun Nov 29 10:11:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1795806888; cv=none; d=zohomail.com; s=zohoarc; b=jKtzHaZRJ8GfYsu++psp7IGu762JbUEx8wL5KYgyTB1idYahjkoGfvAHSyoqEwngHZQtvn3NExLTZR/CT+dG+RNhCBf9qCcE3aW24NFeuskMI7ZJD1w4o3Se7AxC3Am8AA/bQnmLHsjAHJzxT6XpOfPMcKh9uiZF2aqqeejo1XI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1795806888; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=I66ZUzIQuqcrXx7SqYgs1MhOeg24vg65RHc3fAuZ9x8=; b=eAc9uah7zM5ksFpfNXVpP7f44d6Zkp4tvByzsI5odxEep8OJD8XQ2P5sinjUfea/RgDNj9fdxhvU2uij9YbZgrONhGAy+yHOdKMoaIWdCnudj2bnDA6wZb3/mwwDmIo4SXzP4Rr5sbpDAuo2Zbxj7gm7Izwa4vOT0wkyA+qb7LA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1795806888747904.3066309082437; Fri, 27 Nov 2026 11:14:48 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xX1Oc-0002F7-0O; Fri, 27 Nov 2026 14:14:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xX1Ni-0001nZ-4H; Fri, 27 Nov 2026 14:13:15 -0500 Received: from tor.source.kernel.org ([172.105.4.254]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xX1Nf-0006T2-Dr; Fri, 27 Nov 2026 14:13:13 -0500 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 6054361364; Fri, 27 Nov 2026 19:13:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 996F81F00897; Fri, 27 Nov 2026 19:13:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795806789; bh=I66ZUzIQuqcrXx7SqYgs1MhOeg24vg65RHc3fAuZ9x8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=A1XAu+Ruhf5m7EyPL/mhydO31oMJNfo7I2Z0JO3pVw1WjVAZVeICKA/u1ipG/hIwo gv6JsMMNICl87IRQ5tY89jE3x2plBp/OUECThjtAvm8bMFUQNqWGA5Q2qc/ZR3jLca D0m/UKuSFckvCOy21CDREFmlo7wh/wjjDHS52+BRP5FgV9RQH3nQIgj25wB4EjutAu VkL5+4NLhVmbwWWOum+ioVEOqodcKJ1dJDiFOmbovpCa5gb+cshKD3i7cZ0nZi2OPn 8YT6twKrl3Wpn+3No/ldUhYuSpUc70MecpbDCV366bUFMvZlKeNq6yLpYM2I9jMayO RWM7lIjPJcKRw== From: Niklas Cassel To: John Snow , "Denis V. Lunev" , Fabiano Rosas , Laurent Vivier , Paolo Bonzini Cc: Damien Le Moal , Niklas Cassel , qemu-block@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH 05/13] hw/ide: add General Purpose Logging (GPL) feature set support Date: Fri, 27 Nov 2026 20:12:40 +0100 Message-ID: <20261127191250.3298004-6-cassel@kernel.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261127191250.3298004-1-cassel@kernel.org> References: <20261127191250.3298004-1-cassel@kernel.org> 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+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=172.105.4.254; envelope-from=cassel@kernel.org; helo=tor.source.kernel.org X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1795806890221158500 Content-Type: text/plain; charset="utf-8" Implement the General Purpose Logging feature set (ACS-6 4.11). Commands READ LOG EXT (PIO) and READ LOG DMA EXT (DMA) are implemented. WRITE LOG EXT and WRITE LOG DMA EXT are not implemented. (E.g. Linux never writes to any log.) In this base commit, the only log implemented is the General Purpose Log Directory (00h), which lists no other log yet. As with NCQ, only a disk behind AHCI exposes this feature set. On other controllers, a disk neither advertises it nor accepts the new commands, i.e. they work as before. The main reason to add GPL support is to add the NCQ Command Error log, the SATA NCQ Send and Receive log, the Serial ATA page of the IDENTIFY DEVICE data log, and RECEIVE FPDMA QUEUED. Neither of these features/logs makes sense for non-NCQ devices. Add qtests that read the log directory over AHCI, with PIO and DMA, and check that an IDE disk does not advertise the feature set. Signed-off-by: Niklas Cassel --- hw/ide/core.c | 134 ++++++++++++++++++++++++++++++++++---- hw/ide/ide-internal.h | 10 ++- hw/ide/trace-events | 1 + include/hw/ide/ide-dev.h | 1 + tests/qtest/ahci-test.c | 51 +++++++++++++++ tests/qtest/ide-test.c | 3 + tests/qtest/libqos/ahci.c | 4 ++ tests/qtest/libqos/ahci.h | 2 + 8 files changed, 192 insertions(+), 14 deletions(-) diff --git a/hw/ide/core.c b/hw/ide/core.c index 7e3f882969..d09b0fa736 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -68,7 +68,8 @@ const char *IDE_DMA_CMD_lookup[IDE_DMA__COUNT] =3D { [IDE_DMA_READ] =3D "DMA READ", [IDE_DMA_WRITE] =3D "DMA WRITE", [IDE_DMA_TRIM] =3D "DMA TRIM", - [IDE_DMA_ATAPI] =3D "DMA ATAPI" + [IDE_DMA_ATAPI] =3D "DMA ATAPI", + [IDE_DMA_READ_LOG] =3D "DMA READ LOG" }; =20 static const char *IDE_DMA_CMD_str(enum ide_dma_cmd enval) @@ -150,6 +151,7 @@ static void ide_identify(IDEState *s) { uint16_t *p; IDEDevice *dev =3D s->unit ? s->bus->slave : s->bus->master; + uint16_t gpl =3D s->ncq_queues ? 1 << 5 : 0; =20 p =3D (uint16_t *)s->identify_data; if (s->identify_set) { @@ -196,8 +198,8 @@ static void ide_identify(IDEState *s) =20 if (s->ncq_queues) { put_le16(p + 75, s->ncq_queues - 1); - /* NCQ supported */ - put_le16(p + 76, (1 << 8)); + /* 15=3DREAD LOG DMA EXT equivalent to READ LOG EXT, 8=3DNCQ suppo= rted */ + put_le16(p + 76, (1 << 15) | (1 << 8)); } =20 put_le16(p + 80, 0xf0); /* ata3 -> ata6 supported */ @@ -206,20 +208,21 @@ static void ide_identify(IDEState *s) put_le16(p + 82, (1 << 14) | (1 << 5) | 1); /* 13=3Dflush_cache_ext,12=3Dflush_cache,10=3Dlba48 */ put_le16(p + 83, (1 << 14) | (1 << 13) | (1 <<12) | (1 << 10)); - /* 14=3Dset to 1, 8=3Dhas WWN, 1=3DSMART self test, 0=3DSMART error lo= gging */ + /* 14=3Dset to 1, 8=3Dhas WWN, 5=3DGPL, 1=3DSMART self test, 0=3DSMART= error log */ if (s->wwn) { - put_le16(p + 84, (1 << 14) | (1 << 8) | 0); + put_le16(p + 84, (1 << 14) | (1 << 8) | gpl | 0); } else { - put_le16(p + 84, (1 << 14) | 0); + put_le16(p + 84, (1 << 14) | gpl | 0); } put_le16(p + 85, ide_identify_word85(s)); - /* 13=3Dflush_cache_ext,12=3Dflush_cache,10=3Dlba48 */ - put_le16(p + 86, (1 << 13) | (1 <<12) | (1 << 10)); - /* 14=3Dset to 1, 8=3Dhas WWN, 1=3DSMART self test, 0=3DSMART error lo= gging */ + /* 15=3Dwords 119-120 valid,13=3Dflush_cache_ext,12=3Dflush_cache,10= =3Dlba48 */ + put_le16(p + 86, (s->ncq_queues ? 1 << 15 : 0) | + (1 << 13) | (1 << 12) | (1 << 10)); + /* 14=3Dset to 1, 8=3Dhas WWN, 5=3DGPL, 1=3DSMART self test, 0=3DSMART= error log */ if (s->wwn) { - put_le16(p + 87, (1 << 14) | (1 << 8) | 0); + put_le16(p + 87, (1 << 14) | (1 << 8) | gpl | 0); } else { - put_le16(p + 87, (1 << 14) | 0); + put_le16(p + 87, (1 << 14) | gpl | 0); } put_le16(p + 88, 0x3f | (1 << 13)); /* udma5 set and supported */ put_le16(p + 93, 1 | (1 << 14) | 0x2000); @@ -237,6 +240,15 @@ static void ide_identify(IDEState *s) put_le16(p + 110, s->wwn >> 16); put_le16(p + 111, s->wwn); } + if (s->ncq_queues) { + /* + * 14=3Dset to 1, + * 3=3DREAD LOG DMA EXT/WRITE LOG DMA EXT (GPL DMA) supported + */ + put_le16(p + 119, (1 << 14) | (1 << 3)); + /* 14=3Dset to 1, 3=3DGPL DMA enabled */ + put_le16(p + 120, (1 << 14) | (1 << 3)); + } if (dev && dev->conf.discard_granularity) { put_le16(p + 169, 1); /* TRIM support */ } @@ -1034,6 +1046,20 @@ void ide_start_dma(IDEState *s, BlockCompletionFunc = *cb) } } =20 +static void ide_buffer_dma_cb(void *opaque, int ret) +{ + IDEState *s =3D opaque; + + /* + * The data was generated synchronously into the I/O buffer before the + * transfer was started, so there is never a block I/O error to handle. + */ + s->bus->dma->ops->rw_buf(s->bus->dma, 1); + s->status =3D READY_STAT | SEEK_STAT; + ide_bus_set_irq(s->bus); + ide_set_inactive(s, false); +} + static void ide_sector_write(IDEState *s); =20 static void ide_sector_write_timer_cb(void *opaque) @@ -1626,6 +1652,86 @@ static bool cmd_write_dma(IDEState *s, uint8_t cmd) return false; } =20 +/* + * Fill the I/O buffer with the General Purpose Logging data requested by a + * READ LOG EXT / READ LOG DMA EXT command and return the number of bytes = to + * transfer, or a negative value if the command must be aborted (ACS-6 7.2= 5). + */ +static int ide_read_log(IDEState *s) +{ + uint8_t log_address =3D s->sector; + uint16_t page =3D s->lcyl | ((uint16_t)s->hob_lcyl << 8); + uint32_t count =3D s->nsector; /* LOG PAGE COUNT, in 512-byte pages */ + uint16_t log_size; + + switch (log_address) { + case IDE_GPL_LOG_DIRECTORY: + log_size =3D 1; + break; + default: + /* Log (or its associated feature set) not supported (ACS-6 7.25.5= ). */ + return -1; + } + + /* + * A LOG PAGE COUNT of zero is invalid, and the requested pages must l= ie + * within the log as reported by the General Purpose Log Directory + * (ACS-6 7.25.5). The callers turn a zero COUNT into 65536, which the + * range check rejects; checking for zero guards a caller that does no= t. + */ + if (count =3D=3D 0 || page >=3D log_size || count > log_size - page) { + return -1; + } + + switch (log_address) { + case IDE_GPL_LOG_DIRECTORY: + /* General Purpose Log Directory (ACS-6 9.2) */ + memset(s->io_buffer, 0, count * 512); + /* word 0: General Purpose Logging Version */ + put_le16((uint16_t *)s->io_buffer, 0x0001); + break; + } + + return count * 512; +} + +/* READ LOG EXT (PIO) and READ LOG DMA EXT, both 48-bit GPL commands */ +static bool cmd_read_log(IDEState *s, uint8_t cmd) +{ + bool dma =3D (cmd =3D=3D WIN_READ_LOG_DMA_EXT); + int size; + + if (!s->blk) { + ide_abort_command(s); + return true; + } + + /* These commands are always 48-bit; COUNT holds the LOG PAGE COUNT. */ + ide_cmd_lba48_transform(s, 1); + + trace_ide_read_log(s, s->sector, s->lcyl | ((uint16_t)s->hob_lcyl << 8= ), + s->nsector, dma ? "dma" : "pio"); + + size =3D ide_read_log(s); + if (size < 0) { + ide_abort_command(s); + return true; + } + + if (dma) { + s->dma_cmd =3D IDE_DMA_READ_LOG; + s->io_buffer_index =3D 0; + s->io_buffer_size =3D size; + ide_start_dma(s, ide_buffer_dma_cb); + return false; + } + + s->status =3D READY_STAT | SEEK_STAT; + ide_transfer_start(s, s->io_buffer, size, ide_transfer_stop); + ide_bus_set_irq(s->bus); + return false; +} + static bool cmd_flush_cache(IDEState *s, uint8_t cmd) { ide_flush_cache(s); @@ -2107,6 +2213,7 @@ abort_cmd: =20 /* Set the Disk Seek Completed status bit during completion */ #define SET_DSC (1u << 8) +#define AHCI_ONLY (1u << 9) =20 /* See ACS-2 T13/2015-D Table B.2 Command codes */ static const struct { @@ -2125,6 +2232,8 @@ static const struct { [WIN_READDMA_EXT] =3D { cmd_read_dma, HD_CFA_OK }, [WIN_READ_NATIVE_MAX_EXT] =3D { cmd_read_native_max, HD_CFA_OK | S= ET_DSC }, [WIN_MULTREAD_EXT] =3D { cmd_read_multiple, HD_CFA_OK }, + [WIN_READ_LOG_EXT] =3D { cmd_read_log, HD_OK | AHCI_ONLY }, + [WIN_READ_LOG_DMA_EXT] =3D { cmd_read_log, HD_OK | AHCI_ONLY }, [WIN_WRITE] =3D { cmd_write_pio, HD_CFA_OK }, [WIN_WRITE_ONCE] =3D { cmd_write_pio, HD_CFA_OK }, [WIN_WRITE_EXT] =3D { cmd_write_pio, HD_CFA_OK }, @@ -2176,7 +2285,8 @@ static const struct { static bool ide_cmd_permitted(IDEState *s, uint32_t cmd) { return cmd < ARRAY_SIZE(ide_cmd_table) - && (ide_cmd_table[cmd].flags & (1u << s->drive_kind)); + && (ide_cmd_table[cmd].flags & (1u << s->drive_kind)) + && (s->ncq_queues || !(ide_cmd_table[cmd].flags & AHCI_ONLY)); } =20 void ide_bus_exec_cmd(IDEBus *bus, uint32_t val) diff --git a/hw/ide/ide-internal.h b/hw/ide/ide-internal.h index 094772209d..389e15049e 100644 --- a/hw/ide/ide-internal.h +++ b/hw/ide/ide-internal.h @@ -81,7 +81,7 @@ /* READ STREAM DMA EXT 0x2A */ /* READ STREAM EXT 0x2B */ /* reserved 0x2C..0x2E */ -/* READ LOG EXT 0x2F */ +#define WIN_READ_LOG_EXT 0x2F /* 48-Bit */ #define WIN_WRITE 0x30 /* 28-Bit */ #define WIN_WRITE_ONCE 0x31 /* 28-Bit w/o retries, obsole= te since ATA5 */ /* obsolete since ATA4 0x32..0x33 */ @@ -104,7 +104,7 @@ /* reserved 0x43..0x44 */ /* WRITE UNCORRECTABLE EXT 0x45 */ /* reserved 0x46 */ -/* READ LOG DMA EXT 0x47 */ +#define WIN_READ_LOG_DMA_EXT 0x47 /* 48-Bit */ /* reserved 0x48..0x4F */ /* obsolete since ATA4 0x50 */ /* CONFIGURE STREAM 0x51 */ @@ -207,6 +207,12 @@ /* feature values for Data Set Management */ #define DSM_TRIM 0x01 =20 +/* + * Log addresses for the General Purpose Logging feature set, accessed via + * READ LOG EXT / READ LOG DMA EXT (see ACS-6 9.1 table 222). + */ +#define IDE_GPL_LOG_DIRECTORY 0x00 /* General Purpose Log Direct= ory */ + #if (IDE_DMA_BUF_SECTORS < MAX_MULT_SECTORS) #error "IDE_DMA_BUF_SECTORS must be bigger or equal to MAX_MULT_SECTORS" #endif diff --git a/hw/ide/trace-events b/hw/ide/trace-events index c44eec6c58..102f39436c 100644 --- a/hw/ide/trace-events +++ b/hw/ide/trace-events @@ -17,6 +17,7 @@ ide_cancel_dma_sync_buffered(void *fn, void *req) "invoki= ng cb %p of buffered re ide_cancel_dma_sync_remaining(void) "draining all remaining requests" ide_sector_read(int64_t sector_num, int nsectors) "sector=3D%"PRId64" nsec= tors=3D%d" ide_sector_write(int64_t sector_num, int nsectors) "sector=3D%"PRId64" nse= ctors=3D%d" +ide_read_log(void *s, uint8_t log, uint16_t page, uint32_t count, const ch= ar *kind) "IDEState %p; log=3D0x%02x page=3D%u count=3D%u %s" ide_reset(void *s) "IDEstate %p" ide_bus_reset_aio(void) "aio_cancel" ide_dma_cb(void *s, int64_t sector_num, int n, const char *dma) "IDEState = %p; sector_num=3D%"PRId64" n=3D%d cmd=3D%s" diff --git a/include/hw/ide/ide-dev.h b/include/hw/ide/ide-dev.h index f5eaaf68e6..258b216b44 100644 --- a/include/hw/ide/ide-dev.h +++ b/include/hw/ide/ide-dev.h @@ -47,6 +47,7 @@ enum ide_dma_cmd { IDE_DMA_WRITE, IDE_DMA_TRIM, IDE_DMA_ATAPI, + IDE_DMA_READ_LOG, IDE_DMA__COUNT }; =20 diff --git a/tests/qtest/ahci-test.c b/tests/qtest/ahci-test.c index 2b668ea708..8ff30616d5 100644 --- a/tests/qtest/ahci-test.c +++ b/tests/qtest/ahci-test.c @@ -1055,6 +1055,55 @@ static void test_specify(void) ahci_shutdown(ahci); } =20 +/* + * Exercise the General Purpose Logging feature set via READ LOG EXT (PIO)= or + * READ LOG DMA EXT. Reads are performed one log page at a time so the same + * helper can drive both the PIO and DMA variants. + */ +static void ahci_test_read_log(AHCIQState *ahci, uint8_t read_log_cmd) +{ + uint16_t id[256]; + uint16_t dir[256]; + unsigned px; + + px =3D ahci_port_select(ahci); + ahci_port_clear(ahci, px); + + /* + * The device must advertise the GPL feature set (IDENTIFY word 84/87)= and + * READ LOG DMA EXT support (word 86 bit 15 makes word 119 valid; word= 119 + * bit 3 =3D GPL DMA supported). + */ + ahci_io(ahci, px, CMD_IDENTIFY, &id, 512, 0); + g_assert_cmphex(le16_to_cpu(id[84]) & (1 << 5), =3D=3D, (1 << 5)); + g_assert_cmphex(le16_to_cpu(id[87]) & (1 << 5), =3D=3D, (1 << 5)); + g_assert_cmphex(le16_to_cpu(id[86]) & (1 << 15), =3D=3D, (1 << 15)); + g_assert_cmphex(le16_to_cpu(id[119]) & (1 << 3), =3D=3D, (1 << 3)); + + /* General Purpose Log Directory (log address 00h, page 0). */ + ahci_io(ahci, px, read_log_cmd, &dir, 512, 0x00); + /* word 0: General Purpose Logging Version */ + g_assert_cmphex(le16_to_cpu(dir[0]), =3D=3D, 0x0001); +} + +static void test_read_log_dma(void) +{ + AHCIQState *ahci; + + ahci =3D ahci_boot_and_enable(NULL); + ahci_test_read_log(ahci, CMD_READ_LOG_DMA_EXT); + ahci_shutdown(ahci); +} + +static void test_read_log_pio(void) +{ + AHCIQState *ahci; + + ahci =3D ahci_boot_and_enable(NULL); + ahci_test_read_log(ahci, CMD_READ_LOG_EXT); + ahci_shutdown(ahci); +} + /** * Fragmented DMA test: Perform a standard 4K DMA read/write * test, but make sure the physical regions are fragmented to @@ -2511,6 +2560,8 @@ int main(int argc, char **argv) qtest_add_func("/ahci/hba_spec", test_hba_spec); qtest_add_func("/ahci/hba_enable", test_hba_enable); qtest_add_func("/ahci/identify", test_identify); + qtest_add_func("/ahci/io/dma/read_log", test_read_log_dma); + qtest_add_func("/ahci/io/pio/read_log", test_read_log_pio); =20 for (i =3D MODE_BEGIN; i < NUM_MODES; i++) { for (j =3D ADDR_MODE_BEGIN; j < NUM_ADDR_MODES; j++) { diff --git a/tests/qtest/ide-test.c b/tests/qtest/ide-test.c index cf109b0799..d82efdfdda 100644 --- a/tests/qtest/ide-test.c +++ b/tests/qtest/ide-test.c @@ -746,6 +746,9 @@ static void test_identify(void) =20 /* Write cache enabled bit */ assert_bit_set(buf[85], 0x20); + assert_bit_clear(buf[84], 0x20); + assert_bit_clear(buf[86], 0x8000); + g_assert_cmphex(buf[119], =3D=3D, 0); =20 ide_test_quit(qts); free_pci_device(dev); diff --git a/tests/qtest/libqos/ahci.c b/tests/qtest/libqos/ahci.c index 53a98bd6cb..e64fcade36 100644 --- a/tests/qtest/libqos/ahci.c +++ b/tests/qtest/libqos/ahci.c @@ -67,6 +67,10 @@ AHCICommandProp ahci_command_properties[] =3D { .lba48 =3D true, .write =3D true }, { .cmd =3D CMD_IDENTIFY, .data =3D true, .pio =3D true, .size =3D 512, .read =3D true }, + { .cmd =3D CMD_READ_LOG_EXT, .data =3D true, .pio =3D true, + .lba48 =3D true, .read =3D true }, + { .cmd =3D CMD_READ_LOG_DMA_EXT, .data =3D true, .dma =3D true, + .lba48 =3D true, .read =3D true }, { .cmd =3D READ_FPDMA_QUEUED, .data =3D true, .dma =3D true, .lba48 =3D true, .read =3D true, .ncq =3D= true }, { .cmd =3D WRITE_FPDMA_QUEUED, .data =3D true, .dma =3D true, diff --git a/tests/qtest/libqos/ahci.h b/tests/qtest/libqos/ahci.h index f098c91b47..9c4195eee9 100644 --- a/tests/qtest/libqos/ahci.h +++ b/tests/qtest/libqos/ahci.h @@ -280,6 +280,8 @@ enum { CMD_FLUSH_CACHE =3D 0xE7, CMD_INIT_DP =3D 0x91, /* INITIALIZE DEVICE PARAMETERS */ CMD_IDENTIFY =3D 0xEC, + CMD_READ_LOG_EXT =3D 0x2F, + CMD_READ_LOG_DMA_EXT =3D 0x47, CMD_PACKET =3D 0xA0, CMD_PACKET_ID =3D 0xA1, /* NCQ */ --=20 2.56.1 From nobody Sun Nov 29 10:11:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1795806935; cv=none; d=zohomail.com; s=zohoarc; b=cAuwCgAN0gpwCHqn+OR5IuH0u3/Qc8U6gh3dIcntc/9lfdyOQ4KHGODN8SQvQIQAB8fJr1X1ZSFnawupala2XMETMcP9GIN/CFYlBWmDqSAbD07eDy2wk5Qb2phpNKVC8Ap5DAmK+HDqtv8Q25jFCajC/RT+GX8ecN+EBlM7n6M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1795806935; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=uy9Q7GY0lmCcJqUfxyPIVDl+ko/IhNroj3ddpgWPNb0=; b=e/Jsi49EZKaLDQOTYQCGVQ5tI84uEleHwNilMMeYOWaA9kY95ZBTJxp7DHZgg4Ui2ZlLWkIr803kVOktLcjimCo9R4vEqE/NkIChsVifMqJBc/TK+mBjEU6smmIB765n9/8gv4bptwsg8gHcOO7/Ys8pj3QL6hUno3aC4GDTxIA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1795806935438265.138412937936; Fri, 27 Nov 2026 11:15:35 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xX1OI-0001zb-Ts; Fri, 27 Nov 2026 14:13:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xX1Nk-0001oF-Pu; Fri, 27 Nov 2026 14:13:17 -0500 Received: from tor.source.kernel.org ([172.105.4.254]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xX1Ni-0006h4-7G; Fri, 27 Nov 2026 14:13:16 -0500 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 05D0D611E2; Fri, 27 Nov 2026 19:13:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9FBE91F0089C; Fri, 27 Nov 2026 19:13:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795806792; bh=uy9Q7GY0lmCcJqUfxyPIVDl+ko/IhNroj3ddpgWPNb0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=IpYMfesHd/91aKGyJH4M2Sa2amXT9Jf3nmNGHPzFMUUWvZLF8cAQQgbp8Nb1I3el3 mAbBQify0wtBwRWZON5nEuRVE4NxCB/kZhraANrz66ycuutoIHXnaSPoDPjzNO/uzq TGcr79VNTk2hzUzg9ko9FQ5V+4ONSNcV49AD3BvHLqBppksDo+qigPm8nMsL9OzwDY pry74YPUysGpHESIUUyDayxnUB4x+lSSUBC04f2oBNvR1clAmzG34FyHAFBq2FvbGr VIEmKsiJEJgSRoKTY0v6J5RRY7SsM1+PyUMJRmqrAgRTy456V9owzhmTSeMZCJ6YRb BacjvqxkyasGg== From: Niklas Cassel To: John Snow , "Denis V. Lunev" , Fabiano Rosas , Laurent Vivier , Paolo Bonzini Cc: Damien Le Moal , Niklas Cassel , qemu-block@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH 06/13] hw/ide: add the IDENTIFY DEVICE data log Date: Fri, 27 Nov 2026 20:12:41 +0100 Message-ID: <20261127191250.3298004-7-cassel@kernel.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261127191250.3298004-1-cassel@kernel.org> References: <20261127191250.3298004-1-cassel@kernel.org> 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+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=172.105.4.254; envelope-from=cassel@kernel.org; helo=tor.source.kernel.org X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1795806936425158500 Content-Type: text/plain; charset="utf-8" Add the IDENTIFY DEVICE data log (30h). The IDENTIFY DEVICE data log is a mandatory log in the GPL feature set. Implement it with pages 00h to 06h and 08h, which are all the pages that ACS-6 9.11.1 makes mandatory for a SATA device, and list it in the General Purpose Log Directory. The Supported Capabilities (03h), Current Settings (04h) and Serial ATA (08h) pages copy their bits from the IDENTIFY DEVICE data, so that they cannot disagree with it. Extend the read log qtests to check the pages, and to read two pages with one READ LOG DMA EXT. Signed-off-by: Niklas Cassel --- hw/ide/core.c | 195 ++++++++++++++++++++++++++++++++++++++++ hw/ide/ide-internal.h | 9 ++ tests/qtest/ahci-test.c | 70 +++++++++++++++ 3 files changed, 274 insertions(+) diff --git a/hw/ide/core.c b/hw/ide/core.c index d09b0fa736..1304202ea2 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -1652,6 +1652,192 @@ static bool cmd_write_dma(IDEState *s, uint8_t cmd) return false; } =20 +/* + * An IDENTIFY DEVICE data bit, and the bit of an IDENTIFY DEVICE data log= QWord + * that holds a copy of it. + */ +typedef struct IDEIdentifyBit { + uint8_t word; + uint8_t bit; + uint8_t qword_bit; +} IDEIdentifyBit; + +/* The Supported Capabilities QWord of page 03h, terminated by a zero word= */ +static const IDEIdentifyBit ide_supported_capabilities[] =3D { + { 69, 14, 39 }, /* DRAT SUPPORTED */ + { 69, 5, 31 }, /* RZAT SUPPORTED */ + { 82, 14, 29 }, /* NOP SUPPORTED */ + { 82, 5, 24 }, /* VOLATILE WRITE CACHE SUPPORTED */ + { 82, 0, 23 }, /* SMART */ + { 83, 13, 22 }, /* FLUSH CACHE EXT SUPPORTED */ + { 83, 10, 20 }, /* 48-BIT SUPPORTED */ + { 84, 6, 12 }, /* WRITE FUA EXT SUPPORTED */ + { 84, 5, 11 }, /* GPL SUPPORTED */ + { 84, 1, 8 }, /* SMART SELF-TEST SUPPORTED */ + { 84, 0, 7 }, /* SMART ERROR LOGGING SUPPORTED */ + { 119, 6, 5 }, /* SENSE DATA SUPPORTED */ + { 119, 3, 2 }, /* GPL DMA SUPPORTED */ + { 0 } +}; + +/* The SATA Capabilities QWord of page 08h, terminated by a zero word */ +static const IDEIdentifyBit ide_sata_capabilities[] =3D { + { 76, 1, 0 }, /* SATA GEN1 SIGNALING SPEED SUPPORTED */ + { 76, 2, 1 }, /* SATA GEN2 SIGNALING SPEED SUPPORTED */ + { 76, 3, 2 }, /* SATA GEN3 SIGNALING SPEED SUPPORTED */ + { 76, 8, 7 }, /* NCQ FEATURE SET SUPPORTED */ + { 76, 9, 8 }, /* RECEIPT OF HOST INITIATED POWER MANAGEMENT ... = */ + { 76, 10, 9 }, /* SATA PHY EVENT COUNTERS LOG SUPPORTED */ + { 76, 11, 10 }, /* UNLOAD WHILE NCQ COMMANDS ARE OUTSTANDING ... */ + { 76, 12, 11 }, /* NCQ PRIORITY INFORMATION SUPPORTED */ + { 76, 13, 12 }, /* HOST AUTOMATIC PARTIAL TO SLUMBER ... */ + { 76, 14, 13 }, /* DEVICE AUTOMATIC PARTIAL TO SLUMBER ... */ + { 76, 15, 14 }, /* READ LOG DMA EXT AS EQUIVALENT TO READ LOG EXT = ... */ + { 77, 4, 15 }, /* NCQ STREAMING SUPPORTED */ + { 77, 5, 16 }, /* NCQ QUEUE MANAGEMENT COMMAND SUPPORTED */ + { 77, 6, 17 }, /* SEND AND RECEIVE QUEUED COMMANDS SUPPORTED */ + { 78, 1, 18 }, /* NONZERO BUFFER OFFSETS SUPPORTED */ + { 78, 2, 19 }, /* DMA SETUP AUTO-ACTIVATION SUPPORTED */ + { 78, 3, 20 }, /* DEVICE INITIATED POWER MANAGEMENT SUPPORTED */ + { 78, 4, 21 }, /* IN-ORDER DATA DELIVERY SUPPORTED */ + { 78, 5, 22 }, /* HARDWARE FEATURE CONTROL SUPPORTED */ + { 78, 6, 23 }, /* SOFTWARE SETTINGS PRESERVATION SUPPORTED */ + { 78, 7, 24 }, /* NCQ AUTOSENSE SUPPORTED */ + { 78, 8, 25 }, /* DEVICE SLEEP SUPPORTED */ + { 0 } +}; + +/* The Current Settings QWord of page 04h, terminated by a zero word */ +static const IDEIdentifyBit ide_current_settings[] =3D { + { 85, 5, 13 }, /* VOLATILE WRITE CACHE ENABLED */ + { 85, 0, 6 }, /* SMART ENABLED */ + { 0 } +}; + +/* A QWord with bit 63 set, and a copy of the IDENTIFY DEVICE data @bits */ +static uint64_t ide_identify_bits(IDEState *s, const IDEIdentifyBit *bits) +{ + uint64_t qword =3D 1ULL << 63; + + for (; bits->word; bits++) { + if (lduw_le_p(s->identify_data + 2 * bits->word) & (1 << bits->bit= )) { + qword |=3D 1ULL << bits->qword_bit; + } + } + return qword; +} + +/* + * Build the IDENTIFY DEVICE data log (log address 30h, ACS-6 9.11) pages + * [page, page + count) into the I/O buffer. Page 00h (List of Supported + * pages), page 01h (a copy of the IDENTIFY DEVICE data), page 02h (Capaci= ty), + * page 03h (Supported Capabilities), page 04h (Current Settings), page 05h + * (Strings), page 06h (Security) and page 08h (Serial ATA) are implemente= d; + * any other page is returned as zeros (ACS-6 9.11.1). + */ +static void ide_fill_identify_device_log(IDEState *s, uint16_t page, + uint16_t count) +{ + uint16_t i; + + /* Update the cached IDENTIFY DEVICE data; this clobbers io_buffer. */ + ide_identify(s); + memset(s->io_buffer, 0, count * 512); + + for (i =3D 0; i < count; i++) { + uint8_t *buf =3D s->io_buffer + i * 512; + + switch (page + i) { + case 0x00: + /* + * List of Supported IDENTIFY DEVICE data log pages (ACS-6 9.1= 1.2) + */ + put_le16((uint16_t *)buf, 0x0001); /* REVISION NUMBER field */ + buf[8] =3D 8; /* number of entries */ + buf[9] =3D 0x00; /* page 00h is supported = */ + buf[10] =3D 0x01; /* page 01h is supported = */ + buf[11] =3D 0x02; /* page 02h is supported = */ + buf[12] =3D 0x03; /* page 03h is supported = */ + buf[13] =3D 0x04; /* page 04h is supported = */ + buf[14] =3D 0x05; /* page 05h is supported = */ + buf[15] =3D 0x06; /* page 06h is supported = */ + buf[16] =3D 0x08; /* page 08h is supported = */ + break; + case 0x01: + /* Copy of IDENTIFY DEVICE data, words 0..255 (ACS-6 9.11.3) */ + memcpy(buf, s->identify_data, sizeof(s->identify_data)); + break; + case 0x02: + /* Capacity (ACS-6 9.11.4) */ + /* header QWord: 63=3Dset to one, PAGE NUMBER=3D02h, REVISION= =3D0001h */ + stq_le_p(buf, (1ULL << 63) | (0x02ULL << 16) | 0x0001); + /* + * Device Capacity QWord: 63=3Dset to one, 47:0=3DACCESSIBLE C= APACITY + * (one greater than the maximum user-accessible LBA) + */ + stq_le_p(buf + 8, (1ULL << 63) | + ((uint64_t)s->nb_sectors & 0xffffffffffffULL)); + break; + case 0x03: + /* Supported Capabilities (ACS-6 9.11.5) */ + /* header QWord: 63=3Dset to one, PAGE NUMBER=3D03h, REVISION= =3D0001h */ + stq_le_p(buf, (1ULL << 63) | (0x03ULL << 16) | 0x0001); + /* capabilities QWord: 63=3Dvalid, the rest copies IDENTIFY da= ta */ + stq_le_p(buf + 8, ide_identify_bits(s, ide_supported_capabilit= ies)); + break; + case 0x04: + /* Current Settings (ACS-6 9.11.6) */ + /* header QWord: 63=3Dset to one, PAGE NUMBER=3D04h, REVISION= =3D0001h */ + stq_le_p(buf, (1ULL << 63) | (0x04ULL << 16) | 0x0001); + /* Current Settings: 63=3Dset to one, rest copies IDENTIFY dat= a */ + stq_le_p(buf + 8, ide_identify_bits(s, ide_current_settings)); + break; + case 0x05: + /* Strings */ + /* header QWord: 63=3Dset to one, PAGE NUMBER=3D05h, REVISION= =3D0001h */ + stq_le_p(buf, (1ULL << 63) | (0x05ULL << 16) | 0x0001); + /* + * SERIAL NUMBER, FIRMWARE REVISION, MODEL NUMBER and ADDITION= AL + * PRODUCT IDENTIFIER: copies of IDENTIFY DEVICE data words 10= ..19, + * 23..26, 27..46 and 170..173 + */ + memcpy(buf + 8, s->identify_data + 2 * 10, 20); + memcpy(buf + 32, s->identify_data + 2 * 23, 8); + memcpy(buf + 48, s->identify_data + 2 * 27, 40); + memcpy(buf + 96, s->identify_data + 2 * 170, 8); + break; + case 0x06: + /* Security: the Security feature set is not supported */ + /* header QWord: 63=3Dset to one, PAGE NUMBER=3D06h, REVISION= =3D0001h */ + stq_le_p(buf, (1ULL << 63) | (0x06ULL << 16) | 0x0001); + /* + * Master Password Identifier, Security Status, the times requ= ired + * for an Enhanced and a Normal Erase, Trusted Computing featu= re + * set and Security Capabilities: valid, with nothing supported + */ + stq_le_p(buf + 8, 1ULL << 63); + stq_le_p(buf + 16, 1ULL << 63); + stq_le_p(buf + 24, 1ULL << 63); + stq_le_p(buf + 32, 1ULL << 63); + stq_le_p(buf + 40, 1ULL << 63); + stq_le_p(buf + 48, 1ULL << 63); + break; + case 0x08: + /* Serial ATA */ + /* header QWord: 63=3Dset to one, PAGE NUMBER=3D08h, REVISION= =3D0001h */ + stq_le_p(buf, (1ULL << 63) | (0x08ULL << 16) | 0x0001); + /* SATA Capabilities: 63=3Dset to one, rest copies IDENTIFY da= ta */ + stq_le_p(buf + 8, ide_identify_bits(s, ide_sata_capabilities)); + /* Current SATA Settings: 63=3Dset to one, nothing enabled */ + stq_le_p(buf + 16, 1ULL << 63); + break; + default: + /* Unsupported page: returned as all zeros. */ + break; + } + } +} + /* * Fill the I/O buffer with the General Purpose Logging data requested by a * READ LOG EXT / READ LOG DMA EXT command and return the number of bytes = to @@ -1668,6 +1854,9 @@ static int ide_read_log(IDEState *s) case IDE_GPL_LOG_DIRECTORY: log_size =3D 1; break; + case IDE_GPL_LOG_IDENTIFY_DEVICE: + log_size =3D IDE_GPL_LOG_IDENTIFY_DEVICE_LEN; + break; default: /* Log (or its associated feature set) not supported (ACS-6 7.25.5= ). */ return -1; @@ -1689,6 +1878,12 @@ static int ide_read_log(IDEState *s) memset(s->io_buffer, 0, count * 512); /* word 0: General Purpose Logging Version */ put_le16((uint16_t *)s->io_buffer, 0x0001); + /* word N: number of log pages at log address N */ + put_le16((uint16_t *)s->io_buffer + IDE_GPL_LOG_IDENTIFY_DEVICE, + IDE_GPL_LOG_IDENTIFY_DEVICE_LEN); + break; + case IDE_GPL_LOG_IDENTIFY_DEVICE: + ide_fill_identify_device_log(s, page, count); break; } =20 diff --git a/hw/ide/ide-internal.h b/hw/ide/ide-internal.h index 389e15049e..8da6d72450 100644 --- a/hw/ide/ide-internal.h +++ b/hw/ide/ide-internal.h @@ -212,6 +212,15 @@ * READ LOG EXT / READ LOG DMA EXT (see ACS-6 9.1 table 222). */ #define IDE_GPL_LOG_DIRECTORY 0x00 /* General Purpose Log Direct= ory */ +#define IDE_GPL_LOG_IDENTIFY_DEVICE 0x30 /* IDENTIFY DEVICE data log */ + +/* + * Number of 512-byte pages in the IDENTIFY DEVICE data log. Pages 00h (li= st + * of supported pages), 01h (copy of IDENTIFY DEVICE data), 02h (Capacity), + * 03h (Supported Capabilities), 04h (Current Settings), 05h (Strings), 06h + * (Security) and 08h (Serial ATA) are implemented. + */ +#define IDE_GPL_LOG_IDENTIFY_DEVICE_LEN 9 =20 #if (IDE_DMA_BUF_SECTORS < MAX_MULT_SECTORS) #error "IDE_DMA_BUF_SECTORS must be bigger or equal to MAX_MULT_SECTORS" diff --git a/tests/qtest/ahci-test.c b/tests/qtest/ahci-test.c index 8ff30616d5..ba9ea5c435 100644 --- a/tests/qtest/ahci-test.c +++ b/tests/qtest/ahci-test.c @@ -1064,6 +1064,9 @@ static void ahci_test_read_log(AHCIQState *ahci, uint= 8_t read_log_cmd) { uint16_t id[256]; uint16_t dir[256]; + uint16_t page[256]; + uint8_t *page8 =3D (uint8_t *)page; + uint64_t nb, cap; unsigned px; =20 px =3D ahci_port_select(ahci); @@ -1084,14 +1087,81 @@ static void ahci_test_read_log(AHCIQState *ahci, ui= nt8_t read_log_cmd) ahci_io(ahci, px, read_log_cmd, &dir, 512, 0x00); /* word 0: General Purpose Logging Version */ g_assert_cmphex(le16_to_cpu(dir[0]), =3D=3D, 0x0001); + /* word 30h: number of pages in the IDENTIFY DEVICE data log */ + g_assert_cmphex(le16_to_cpu(dir[0x30]), =3D=3D, 9); + + /* IDENTIFY DEVICE data log (log address 30h), page 0: list of pages. = */ + ahci_io(ahci, px, read_log_cmd, &page, 512, 0x30); + g_assert_cmphex(le16_to_cpu(page[0]), =3D=3D, 0x0001); /* REVISION NUM= BER */ + g_assert_cmpint(page8[8], =3D=3D, 8); /* number of en= tries */ + g_assert_cmpint(page8[9], =3D=3D, 0x00); /* page 00h sup= ported */ + g_assert_cmpint(page8[10], =3D=3D, 0x01); /* page 01h sup= ported */ + g_assert_cmpint(page8[11], =3D=3D, 0x02); /* page 02h sup= ported */ + g_assert_cmpint(page8[12], =3D=3D, 0x03); /* page 03h sup= ported */ + g_assert_cmpint(page8[13], =3D=3D, 0x04); /* page 04h sup= ported */ + g_assert_cmpint(page8[14], =3D=3D, 0x05); /* page 05h sup= ported */ + g_assert_cmpint(page8[15], =3D=3D, 0x06); /* page 06h sup= ported */ + g_assert_cmpint(page8[16], =3D=3D, 0x08); /* page 08h sup= ported */ + + /* IDENTIFY DEVICE data log page 1: a copy of the IDENTIFY data. */ + ahci_io(ahci, px, read_log_cmd, &page, 512, 0x30 | (1 << 8)); + g_assert_cmphex(memcmp(page, id, 512), =3D=3D, 0); + + /* IDENTIFY DEVICE data log page 2 (page number 2): Capacity. */ + ahci_io(ahci, px, read_log_cmd, &page, 512, 0x30 | (2 << 8)); + g_assert_cmphex(le16_to_cpu(page[0]), =3D=3D, 0x0001); /* REVISION N= UMBER */ + g_assert_cmpint(page8[2], =3D=3D, 0x02); /* PAGE NUMBE= R */ + g_assert_cmpint(page8[7] & (1 << 7), =3D=3D, (1 << 7)); /* header bit= 63 */ + g_assert_cmpint(page8[15] & (1 << 7), =3D=3D, (1 << 7)); /* capacity v= alid */ + /* ACCESSIBLE CAPACITY (bits 47:0) must match IDENTIFY words 100..103 = */ + nb =3D (uint64_t)le16_to_cpu(id[100]) | + ((uint64_t)le16_to_cpu(id[101]) << 16) | + ((uint64_t)le16_to_cpu(id[102]) << 32) | + ((uint64_t)le16_to_cpu(id[103]) << 48); + cap =3D (uint64_t)page8[8] | ((uint64_t)page8[9] << 8) | + ((uint64_t)page8[10] << 16) | ((uint64_t)page8[11] << 24) | + ((uint64_t)page8[12] << 32) | ((uint64_t)page8[13] << 40); + g_assert_cmpuint(cap, =3D=3D, nb); + + /* IDENTIFY DEVICE data log page 3: Supported Capabilities. */ + ahci_io(ahci, px, read_log_cmd, &page, 512, 0x30 | (3 << 8)); + g_assert_cmphex(le16_to_cpu(page[0]), =3D=3D, 0x0001); /* REVISION N= UMBER */ + g_assert_cmpint(page8[2], =3D=3D, 0x03); /* PAGE NUMBE= R */ + g_assert_cmpint(page8[7] & (1 << 7), =3D=3D, (1 << 7)); /* header bit= 63 */ + g_assert_cmpint(page8[8] & (1 << 2), =3D=3D, (1 << 2)); /* GPL DMA su= pported */ + g_assert_cmpint(page8[9] & (1 << 3), =3D=3D, (1 << 3)); /* GPL (bit 1= 1) */ + g_assert_cmpint(page8[10] & (1 << 4), =3D=3D, (1 << 4)); /* 48-BIT (bi= t 20) */ + + /* IDENTIFY DEVICE data log page 5: Strings, as in the IDENTIFY data. = */ + ahci_io(ahci, px, read_log_cmd, &page, 512, 0x30 | (5 << 8)); + g_assert_cmpint(page8[2], =3D=3D, 0x05); /* PAGE NUMBE= R */ + g_assert_cmphex(memcmp(page8 + 8, &id[10], 20), =3D=3D, 0); /* SERIAL= */ + g_assert_cmphex(memcmp(page8 + 48, &id[27], 40), =3D=3D, 0); /* MODEL = */ + + /* IDENTIFY DEVICE data log page 8: Serial ATA. */ + ahci_io(ahci, px, read_log_cmd, &page, 512, 0x30 | (8 << 8)); + g_assert_cmpint(page8[2], =3D=3D, 0x08); /* PAGE NUMBE= R */ + g_assert_cmpint(page8[8] & (1 << 7), =3D=3D, (1 << 7)); /* NCQ suppor= ted */ } =20 static void test_read_log_dma(void) { AHCIQState *ahci; + uint16_t id[256]; + uint16_t idlog[512]; /* two consecutive 512-byte log pages */ + unsigned px; =20 ahci =3D ahci_boot_and_enable(NULL); ahci_test_read_log(ahci, CMD_READ_LOG_DMA_EXT); + + /* Also exercise a multi-page DMA transfer: both pages of log 30h. */ + px =3D ahci_port_select(ahci); + ahci_port_clear(ahci, px); + ahci_io(ahci, px, CMD_IDENTIFY, &id, 512, 0); + ahci_io(ahci, px, CMD_READ_LOG_DMA_EXT, &idlog, 1024, 0x30); + g_assert_cmphex(le16_to_cpu(idlog[0]), =3D=3D, 0x0001); /* page 0 he= ader */ + g_assert_cmphex(memcmp(&idlog[256], id, 512), =3D=3D, 0); /* page 1: I= DENTIFY */ + ahci_shutdown(ahci); } =20 --=20 2.56.1 From nobody Sun Nov 29 10:11:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1795806928; cv=none; d=zohomail.com; s=zohoarc; b=bRLwE67T9+gKuEnSxN/CczI62fYNkEu2evGnATEfquCwpoaDNwgysW6g+o2Zws1QYxxArqag3EJh88LQePfG/OenqfB1zKs9lZMYcsA47qpr1BGQjyTfTVI/9tqCljER69WNiArrlzVysWm5giKLBh6NfLmUJJoLK9w5F5UVT5Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1795806928; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=7/d4oXOftvFIEymis9AxaKWSO5atWwQC1FuOYQwdsjg=; b=VdSlNc1KHoFksqKvIvhvBlA8GJbkIuKYlYYMi5mg5b6FFauT/UeSh28Ifls5byBGar8weBJcAKah+BoIlmB+GSTGJReVrsuNiqYppdFOba8TRYeHeeAIK/bMU9gxQfWVFEGOd6v0I2fD4lyUtSFoCCuvl9E0Nt6W0f6DhZERDDA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1795806928369732.9829280452151; Fri, 27 Nov 2026 11:15:28 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xX1Pb-0003Hq-O2; Fri, 27 Nov 2026 14:15:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xX1Np-0001qK-Bg; Fri, 27 Nov 2026 14:13:22 -0500 Received: from sea.source.kernel.org ([2600:3c0a:e001:78e:0:1991:8:25]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xX1Nl-0006tV-1r; Fri, 27 Nov 2026 14:13:21 -0500 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id C255F41279; Fri, 27 Nov 2026 19:13:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 52F2F1F00899; Fri, 27 Nov 2026 19:13:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795806795; bh=7/d4oXOftvFIEymis9AxaKWSO5atWwQC1FuOYQwdsjg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=E07EMSdtyKl36rCtXYacF6pXVoLCBEcI8tmwVNk6LoPnvm7L1DpSLruzjnHGxIR2x 3WcX8bipuOxUXzWcyYPA6zozpcWo2ou6SD+kCaz+c9Sb082Dw65mRIIbaGy9EclIOD EF75m3qacpqVMb19KglllKeKReBKX/wXh4vZz/fwNltXMQ11XgbIMhrACGPWpWlQAi Z6EJVEXK4OM//l8wdD7CStfqAhPAUz0wPDcrQRjbKCuDFCJuSOG1xqZYccvnqEdqDq MTlzo+vvrQuNPc4X5JxHcLfRC8T1X/g0bK+NgJO9BLvRhdnFFTxk9P7PJZUYZndkg+ hrR0dx/4pF7xw== From: Niklas Cassel To: John Snow , "Denis V. Lunev" , Fabiano Rosas , Laurent Vivier , Paolo Bonzini Cc: Damien Le Moal , Niklas Cassel , qemu-block@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH 07/13] hw/ide/ahci: add RECEIVE FPDMA QUEUED support Date: Fri, 27 Nov 2026 20:12:42 +0100 Message-ID: <20261127191250.3298004-8-cassel@kernel.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261127191250.3298004-1-cassel@kernel.org> References: <20261127191250.3298004-1-cassel@kernel.org> 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+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2600:3c0a:e001:78e:0:1991:8:25; envelope-from=cassel@kernel.org; helo=sea.source.kernel.org X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1795806930529158501 Content-Type: text/plain; charset="utf-8" The command RECEIVE FPDMA QUEUED allows the device to encapsulate a non-NCQ command in a the RECEIVE FPDMA QUEUED command. Add support for subcommand 01h only: the NCQ encapsulation of READ LOG DMA EXT. It shares the log generation with READ LOG (DMA) EXT, and an invalid log or subcommand aborts the command. Add a qtest that reads logs over NCQ, and the libqos support for RECEIVE FPDMA QUEUED. Signed-off-by: Niklas Cassel --- hw/ide/ahci-internal.h | 4 ++ hw/ide/ahci.c | 44 ++++++++++++++++++++++ hw/ide/core.c | 39 ++++++++++++++++---- hw/ide/ide-internal.h | 10 +++++ hw/ide/trace-events | 1 + tests/qtest/ahci-test.c | 77 +++++++++++++++++++++++++++++++++++++++ tests/qtest/libqos/ahci.c | 15 ++++++++ tests/qtest/libqos/ahci.h | 11 +++++- 8 files changed, 191 insertions(+), 10 deletions(-) diff --git a/hw/ide/ahci-internal.h b/hw/ide/ahci-internal.h index ca11a370c7..5f51341d87 100644 --- a/hw/ide/ahci-internal.h +++ b/hw/ide/ahci-internal.h @@ -246,6 +246,9 @@ enum AHCIPortIRQ { #define RECEIVE_FPDMA_QUEUED 0x65 #define SEND_FPDMA_QUEUED 0x64 =20 +/* RECEIVE FPDMA QUEUED subcommands (ACS-6 table 95) */ +#define RECEIVE_FPDMA_READ_LOG_DMA_EXT 0x01 + #define NCQ_FIS_FUA_MASK 0x80 #define NCQ_FIS_RARC_MASK 0x01 =20 @@ -302,6 +305,7 @@ typedef struct NCQTransferState { uint64_t lba; uint8_t tag; uint8_t cmd; + uint8_t subcmd; /* SUBCOMMAND field, for RECEIVE/SEND FPDMA QUEUED */ uint8_t slot; bool used; bool halt; diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c index e14b298ea6..21938703da 100644 --- a/hw/ide/ahci.c +++ b/hw/ide/ahci.c @@ -1093,6 +1093,43 @@ static int is_ncq(uint8_t ata_cmd) } } =20 +/* + * RECEIVE FPDMA QUEUED (ACS-6 7.33) transfers device-generated data to the + * host. Only subcommand 01h (the NCQ encapsulation of READ LOG DMA EXT, s= ee + * ACS-6 7.26.6) is supported. The log data is generated synchronously into + * the I/O buffer and copied into the command's scatter/gather list, so th= ere + * is no block backend I/O involved. + */ +static void execute_ncq_receive_fpdma_queued(NCQTransferState *ncq_tfs) +{ + IDEState *ide_state =3D &ncq_tfs->drive->port.ifs[0]; + + switch (ncq_tfs->subcmd) { + case RECEIVE_FPDMA_READ_LOG_DMA_EXT: { + /* Encapsulated READ LOG DMA EXT inputs (ACS-6 table 87). */ + uint8_t log_address =3D ncq_tfs->lba & 0xff; + uint16_t page =3D ((ncq_tfs->lba >> 8) & 0xff) | + (((ncq_tfs->lba >> 32) & 0xff) << 8); + int size =3D ide_read_log(ide_state, log_address, page, + ncq_tfs->sector_count); + + if (size < 0) { + ncq_err(ncq_tfs); + break; + } + dma_buf_read(ide_state->io_buffer, size, NULL, &ncq_tfs->sglist, + MEMTXATTRS_UNSPECIFIED); + ide_state->status =3D READY_STAT | SEEK_STAT; + break; + } + default: + ncq_err(ncq_tfs); + break; + } + + ncq_finish(ncq_tfs); +} + static void execute_ncq_command(NCQTransferState *ncq_tfs) { AHCIDevice *ad =3D ncq_tfs->drive; @@ -1123,6 +1160,11 @@ static void execute_ncq_command(NCQTransferState *nc= q_tfs) BDRV_SECTOR_SIZE, ncq_cb, ncq_tfs); break; + case RECEIVE_FPDMA_QUEUED: + trace_execute_ncq_command_receive(ad->hba, port, ncq_tfs->tag, + ncq_tfs->subcmd); + execute_ncq_receive_fpdma_queued(ncq_tfs); + break; default: trace_execute_ncq_command_unsup(ad->hba, port, ncq_tfs->tag, ncq_tfs->cmd); @@ -1175,6 +1217,8 @@ static void process_ncq_command(AHCIState *s, int por= t, const uint8_t *cmd_fis, ncq_tfs->slot =3D slot; ncq_tfs->cmdh =3D &((AHCICmdHdr *)ad->lst)[slot]; ncq_tfs->cmd =3D ncq_fis->command; + /* SUBCOMMAND field is COUNT bits 12:8, i.e. the low 5 bits of "prio" = */ + ncq_tfs->subcmd =3D ncq_fis->prio & 0x1f; ncq_tfs->lba =3D ((uint64_t)ncq_fis->lba5 << 40) | ((uint64_t)ncq_fis->lba4 << 32) | ((uint64_t)ncq_fis->lba3 << 24) | diff --git a/hw/ide/core.c b/hw/ide/core.c index 1304202ea2..0ccac398b2 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -200,6 +200,8 @@ static void ide_identify(IDEState *s) put_le16(p + 75, s->ncq_queues - 1); /* 15=3DREAD LOG DMA EXT equivalent to READ LOG EXT, 8=3DNCQ suppo= rted */ put_le16(p + 76, (1 << 15) | (1 << 8)); + /* 6=3DSEND AND RECEIVE QUEUED COMMANDS supported (SATA NCQ log 13= h) */ + put_le16(p + 77, (1 << 6)); } =20 put_le16(p + 80, 0xf0); /* ata3 -> ata6 supported */ @@ -1839,21 +1841,28 @@ static void ide_fill_identify_device_log(IDEState *= s, uint16_t page, } =20 /* - * Fill the I/O buffer with the General Purpose Logging data requested by a - * READ LOG EXT / READ LOG DMA EXT command and return the number of bytes = to - * transfer, or a negative value if the command must be aborted (ACS-6 7.2= 5). + * Fill the I/O buffer with the General Purpose Logging data selected by + * log_address, page and count (the LOG PAGE COUNT, in 512-byte pages) and + * return the number of bytes to transfer, or a negative value if the comm= and + * must be aborted (ACS-6 7.25). Shared by the READ LOG EXT / READ LOG DMA= EXT + * commands and by the RECEIVE FPDMA QUEUED NCQ encapsulation (ACS-6 7.26.= 6). */ -static int ide_read_log(IDEState *s) +int ide_read_log(IDEState *s, uint8_t log_address, uint16_t page, + uint32_t count) { - uint8_t log_address =3D s->sector; - uint16_t page =3D s->lcyl | ((uint16_t)s->hob_lcyl << 8); - uint32_t count =3D s->nsector; /* LOG PAGE COUNT, in 512-byte pages */ uint16_t log_size; =20 switch (log_address) { case IDE_GPL_LOG_DIRECTORY: log_size =3D 1; break; + case IDE_GPL_LOG_NCQ_SEND_RECV: + /* Only meaningful for devices that support the NCQ feature set. */ + if (!s->ncq_queues) { + return -1; + } + log_size =3D 1; + break; case IDE_GPL_LOG_IDENTIFY_DEVICE: log_size =3D IDE_GPL_LOG_IDENTIFY_DEVICE_LEN; break; @@ -1881,6 +1890,19 @@ static int ide_read_log(IDEState *s) /* word N: number of log pages at log address N */ put_le16((uint16_t *)s->io_buffer + IDE_GPL_LOG_IDENTIFY_DEVICE, IDE_GPL_LOG_IDENTIFY_DEVICE_LEN); + if (s->ncq_queues) { + put_le16((uint16_t *)s->io_buffer + IDE_GPL_LOG_NCQ_SEND_RECV,= 1); + } + break; + case IDE_GPL_LOG_NCQ_SEND_RECV: + /* SATA NCQ Send and Receive log (ACS-6 9.19) */ + memset(s->io_buffer, 0, count * 512); + /* + * "Supports Read Log" DWord (offset 8): advertise READ LOG DMA EX= T as + * RECEIVE FPDMA QUEUED subcommand 01h. Bit 0 =3D QUEUED READ LOG = DMA EXT + * SUPPORTED, bit 1 =3D SEQUENTIAL QUEUED READ LOG DMA EXT SUPPORT= ED. + */ + stl_le_p(s->io_buffer + 8, (1 << 1) | (1 << 0)); break; case IDE_GPL_LOG_IDENTIFY_DEVICE: ide_fill_identify_device_log(s, page, count); @@ -1907,7 +1929,8 @@ static bool cmd_read_log(IDEState *s, uint8_t cmd) trace_ide_read_log(s, s->sector, s->lcyl | ((uint16_t)s->hob_lcyl << 8= ), s->nsector, dma ? "dma" : "pio"); =20 - size =3D ide_read_log(s); + size =3D ide_read_log(s, s->sector, s->lcyl | ((uint16_t)s->hob_lcyl <= < 8), + s->nsector); if (size < 0) { ide_abort_command(s); return true; diff --git a/hw/ide/ide-internal.h b/hw/ide/ide-internal.h index 8da6d72450..382e2a4915 100644 --- a/hw/ide/ide-internal.h +++ b/hw/ide/ide-internal.h @@ -212,6 +212,7 @@ * READ LOG EXT / READ LOG DMA EXT (see ACS-6 9.1 table 222). */ #define IDE_GPL_LOG_DIRECTORY 0x00 /* General Purpose Log Direct= ory */ +#define IDE_GPL_LOG_NCQ_SEND_RECV 0x13 /* SATA NCQ Send and Receive = log */ #define IDE_GPL_LOG_IDENTIFY_DEVICE 0x30 /* IDENTIFY DEVICE data log */ =20 /* @@ -445,6 +446,15 @@ void ide_bus_register_restart_cb(IDEBus *bus); =20 void ide_bus_exec_cmd(IDEBus *bus, uint32_t val); =20 +/* + * Fill the IDEState I/O buffer with a General Purpose Logging log page. + * Returns the number of bytes generated, or a negative value if the reque= st + * is invalid. Shared between the READ LOG (DMA) EXT commands and the + * RECEIVE FPDMA QUEUED NCQ encapsulation. + */ +int ide_read_log(IDEState *s, uint8_t log_address, uint16_t page, + uint32_t count); + 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, diff --git a/hw/ide/trace-events b/hw/ide/trace-events index 102f39436c..8b98b11d23 100644 --- a/hw/ide/trace-events +++ b/hw/ide/trace-events @@ -98,6 +98,7 @@ ahci_populate_sglist_bad_offset(void *s, int port, int of= f_idx, int64_t off_pos) ncq_finish(void *s, int port, uint8_t tag) "ahci(%p)[%d][tag:%d]: NCQ tran= sfer finished" execute_ncq_command_read(void *s, int port, uint8_t tag, int count, int64_= t lba) "ahci(%p)[%d][tag:%d]: NCQ reading %d sectors from LBA %"PRId64 execute_ncq_command_write(void *s, int port, uint8_t tag, int count, int64= _t lba) "ahci(%p)[%d][tag:%d]: NCQ writing %d sectors to LBA %"PRId64 +execute_ncq_command_receive(void *s, int port, uint8_t tag, uint8_t subcmd= ) "ahci(%p)[%d][tag:%d]: NCQ RECEIVE FPDMA QUEUED subcommand 0x%02x" execute_ncq_command_unsup(void *s, int port, uint8_t tag, uint8_t cmd) "ah= ci(%p)[%d][tag:%d]: error: unsupported NCQ command (0x%02x) received" process_ncq_command_mismatch(void *s, int port, uint8_t tag, uint8_t slot)= "ahci(%p)[%d][tag:%d]: Warning: NCQ slot (%d) did not match the given tag" process_ncq_command_aux(void *s, int port, uint8_t tag) "ahci(%p)[%d][tag:= %d]: Warn: Attempt to use NCQ auxiliary fields" diff --git a/tests/qtest/ahci-test.c b/tests/qtest/ahci-test.c index ba9ea5c435..5e924010f0 100644 --- a/tests/qtest/ahci-test.c +++ b/tests/qtest/ahci-test.c @@ -1805,6 +1805,82 @@ static void test_ncq_simple(void) ahci_shutdown(ahci); } =20 +/* + * Read one 512-byte General Purpose Logging log page into @buffer using + * RECEIVE FPDMA QUEUED subcommand 01h (the NCQ encapsulation of + * READ LOG DMA EXT). + */ +static void ahci_ncq_read_log(AHCIQState *ahci, uint8_t port, uint8_t log, + uint16_t page, void *buffer) +{ + AHCICommand *cmd; + uint64_t ptr; + uint64_t lba =3D log | ((uint64_t)(page & 0xff) << 8) | + ((uint64_t)(page >> 8) << 32); + + ptr =3D ahci_alloc(ahci, 512); + g_assert(ptr); + qtest_memset(ahci->parent->qts, ptr, 0x00, 512); + + cmd =3D ahci_command_create(RECEIVE_FPDMA_QUEUED); + ahci_command_set_buffer(cmd, ptr); + ahci_command_set_size(cmd, 512); + ahci_command_set_offset(cmd, lba); + ahci_command_set_ncq_subcmd(cmd, NCQ_RECEIVE_READ_LOG_DMA_EXT); + ahci_command_commit(ahci, cmd, port); + ahci_command_issue(ahci, cmd); + ahci_command_verify(ahci, cmd); + ahci_command_free(cmd); + + qtest_bufread(ahci->parent->qts, ptr, buffer, 512); + ahci_free(ahci, ptr); +} + +static void test_ncq_read_log(void) +{ + AHCIQState *ahci; + uint16_t id[256]; + uint16_t dir[256]; + uint16_t page[256]; + uint8_t *page8 =3D (uint8_t *)page; + unsigned px; + + ahci =3D ahci_boot_and_enable(NULL); + px =3D ahci_port_select(ahci); + ahci_port_clear(ahci, px); + + /* Fetch IDENTIFY DEVICE data (PIO) to compare against the log copy. */ + ahci_io(ahci, px, CMD_IDENTIFY, &id, 512, 0); + /* word 77 bit 6: SEND AND RECEIVE QUEUED COMMANDS supported */ + g_assert_cmphex(le16_to_cpu(id[77]) & (1 << 6), =3D=3D, (1 << 6)); + + /* General Purpose Log Directory (log 00h) over NCQ. */ + ahci_ncq_read_log(ahci, px, 0x00, 0, dir); + g_assert_cmphex(le16_to_cpu(dir[0]), =3D=3D, 0x0001); /* GPL version */ + g_assert_cmphex(le16_to_cpu(dir[0x13]), =3D=3D, 1); /* NCQ Send/Recv= log */ + g_assert_cmphex(le16_to_cpu(dir[0x30]), =3D=3D, 9); /* IDENTIFY log = size */ + + /* SATA NCQ Send and Receive log (log 13h). */ + ahci_ncq_read_log(ahci, px, 0x13, 0, page); + /* + * "Supports Read Log" DWord (offset 8): bit 0 QUEUED READ LOG DMA EXT= and + * bit 1 SEQUENTIAL QUEUED READ LOG DMA EXT (subcommand 01h). + */ + g_assert_cmpuint(page8[8] | (page8[9] << 8) | (page8[10] << 16) | + ((uint32_t)page8[11] << 24), =3D=3D, 0x3); + + /* IDENTIFY DEVICE data log (log 30h) page 0: list of supported pages.= */ + ahci_ncq_read_log(ahci, px, 0x30, 0, page); + g_assert_cmphex(le16_to_cpu(page[0]), =3D=3D, 0x0001); /* REVISION NUM= BER */ + g_assert_cmpint(page8[8], =3D=3D, 8); /* number of en= tries */ + + /* IDENTIFY DEVICE data log (log 30h) page 1: copy of IDENTIFY data. */ + ahci_ncq_read_log(ahci, px, 0x30, 1, page); + g_assert_cmphex(memcmp(page, id, 512), =3D=3D, 0); + + ahci_shutdown(ahci); +} + static int prepare_iso(size_t size, unsigned char **buf, char **name) { g_autofree char *cdrom_path =3D NULL; @@ -2662,6 +2738,7 @@ int main(int argc, char **argv) qtest_add_func("/ahci/reset/pending_callback", test_reset_pending_call= back); =20 qtest_add_func("/ahci/io/ncq/simple", test_ncq_simple); + qtest_add_func("/ahci/io/ncq/read_log", test_ncq_read_log); qtest_add_func("/ahci/migrate/ncq/simple", test_migrate_ncq); qtest_add_func("/ahci/io/ncq/retry", test_halted_ncq); qtest_add_func("/ahci/migrate/ncq/halted", test_migrate_halted_ncq); diff --git a/tests/qtest/libqos/ahci.c b/tests/qtest/libqos/ahci.c index e64fcade36..d50ff4767b 100644 --- a/tests/qtest/libqos/ahci.c +++ b/tests/qtest/libqos/ahci.c @@ -75,6 +75,8 @@ AHCICommandProp ahci_command_properties[] =3D { .lba48 =3D true, .read =3D true, .ncq =3D= true }, { .cmd =3D WRITE_FPDMA_QUEUED, .data =3D true, .dma =3D true, .lba48 =3D true, .write =3D true, .ncq = =3D true }, + { .cmd =3D RECEIVE_FPDMA_QUEUED, .data =3D true, .dma =3D true, + .lba48 =3D true, .read =3D true, .ncq =3D= true }, { .cmd =3D CMD_READ_MAX, .lba28 =3D true }, { .cmd =3D CMD_READ_MAX_EXT, .lba48 =3D true }, { .cmd =3D CMD_FLUSH_CACHE, .data =3D false }, @@ -1204,6 +1206,19 @@ void ahci_command_set_count(AHCICommand *cmd, uint16= _t count) cmd->fis.count =3D count; } =20 +/* + * Set the SUBCOMMAND field (COUNT bits 12:8) of an NCQ command, e.g. the + * RECEIVE FPDMA QUEUED subcommand. It occupies the low 5 bits of the "pri= o" + * (COUNT 15:8) byte. + */ +void ahci_command_set_ncq_subcmd(AHCICommand *cmd, uint8_t subcmd) +{ + NCQFIS *nfis =3D (NCQFIS *)&(cmd->fis); + + g_assert(cmd->props->ncq); + nfis->prio =3D (nfis->prio & ~0x1f) | (subcmd & 0x1f); +} + void ahci_command_expect_error(AHCICommand *cmd, uint8_t err) { cmd->interrupts |=3D AHCI_PX_IS_TFES; diff --git a/tests/qtest/libqos/ahci.h b/tests/qtest/libqos/ahci.h index 9c4195eee9..9b40eabe35 100644 --- a/tests/qtest/libqos/ahci.h +++ b/tests/qtest/libqos/ahci.h @@ -285,8 +285,14 @@ enum { CMD_PACKET =3D 0xA0, CMD_PACKET_ID =3D 0xA1, /* NCQ */ - READ_FPDMA_QUEUED =3D 0x60, - WRITE_FPDMA_QUEUED =3D 0x61, + READ_FPDMA_QUEUED =3D 0x60, + WRITE_FPDMA_QUEUED =3D 0x61, + RECEIVE_FPDMA_QUEUED =3D 0x65, +}; + +/* RECEIVE FPDMA QUEUED subcommands */ +enum { + NCQ_RECEIVE_READ_LOG_DMA_EXT =3D 0x01, }; =20 /* ATAPI Commands */ @@ -647,6 +653,7 @@ void ahci_command_set_prd_size(AHCICommand *cmd, unsign= ed prd_size); void ahci_command_set_sizes(AHCICommand *cmd, uint64_t xbytes, unsigned prd_size); void ahci_command_set_count(AHCICommand *cmd, uint16_t count); +void ahci_command_set_ncq_subcmd(AHCICommand *cmd, uint8_t subcmd); void ahci_command_expect_error(AHCICommand *cmd, uint8_t err); void ahci_command_set_acmd(AHCICommand *cmd, void *acmd); void ahci_command_enable_atapi_dma(AHCICommand *cmd); --=20 2.56.1 From nobody Sun Nov 29 10:11:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1795806943; cv=none; d=zohomail.com; s=zohoarc; b=FjO4ZnHf/NsndJao5PmCLuNrMbWnmco+Aku87mcm7ZEKmulVAc39WTdBBhuutHjuye3p0JVXTmF4hQYDrrAZ/HTQOQpOQTDLItwveaxYEWhA2wVmDzqXaMbFdlmTSkCsTUzcWU0M2t95HS77MzXfHF9775PvtuBzd5WhOrvhK+o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1795806943; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=MXLr2BgN6g0wofnlccPy2ARfsaXGggCj8CNKnrzWPHE=; b=a4zM/Gfrk97ZqviT2TJ1iQI/euMyGjlvtjauEPTqXc6DrdSlJllhA2uIJDzE5EGnOm/CX/jJjIWMB1s7Algj44sbM3Nks+zTF/vDewIH094lkIgy2PefvAshbb5cZrWOJdY0H5HDm9UP754pVfpjkxGFSvLCS/Wsm7hg1EOTwCY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1795806943002328.35401192151517; Fri, 27 Nov 2026 11:15:43 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xX1Pj-0003qq-OI; Fri, 27 Nov 2026 14:15:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xX1Nq-0001qp-M7; Fri, 27 Nov 2026 14:13:22 -0500 Received: from sea.source.kernel.org ([172.234.252.31]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xX1Nn-0006xi-Uo; Fri, 27 Nov 2026 14:13:22 -0500 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id B014B43259; Fri, 27 Nov 2026 19:13:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 63C151F00899; Fri, 27 Nov 2026 19:13:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795806798; bh=MXLr2BgN6g0wofnlccPy2ARfsaXGggCj8CNKnrzWPHE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=CCD/+peET8E8BGPYOVRimn6cYVEfz+0eYRy76bdJdrA2JxBliMpwbAvLJdilxPSVN vchoIvBe2qbz9tGa7yxKureW7Ab20GpMWU7Q5asvTJc/RF7phsGD6A8gPIiLjdfXfK b3rEkMhxDffEdqp1vs0l+GiDrCdpB1yTY2tQUlT3xua/paTVyp0vqSxfwJAuenSMlH BB6NCTBZKnVYXBqeiDReczR5b4jL2Z9sYKDE5jMpUOAtHqNKFqh1yElcaZKdoDcmLE QnCXhREMQcqwsQ9tH6drXccU5WeeDn+n1X8KmF/N/Yfd8RIwvEn6cZXw64E8VnDS8a ItaixkYA9DZug== From: Niklas Cassel To: John Snow , "Denis V. Lunev" , Fabiano Rosas , Laurent Vivier , Paolo Bonzini Cc: Damien Le Moal , Niklas Cassel , qemu-block@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH 08/13] hw/ide: add Sense Data Reporting feature set support Date: Fri, 27 Nov 2026 20:12:43 +0100 Message-ID: <20261127191250.3298004-9-cassel@kernel.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261127191250.3298004-1-cassel@kernel.org> References: <20261127191250.3298004-1-cassel@kernel.org> 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+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=172.234.252.31; envelope-from=cassel@kernel.org; helo=sea.source.kernel.org X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1795806944385158500 Content-Type: text/plain; charset="utf-8" Implement the Sense Data Reporting feature set (ACS-6 4.25). When it is enabled, a failed command sets SENSE DATA AVAILABLE, and REQUEST SENSE DATA EXT (0Bh) returns the sense key, ASC and ASCQ. The sense data is discarded on a reset and when another command is accepted. An unsupported command reports INVALID COMMAND OPERATION CODE (ACS-6 6.8.18), and an invalid input field reports INVALID FIELD IN CDB (6.8.19), both with ILLEGAL REQUEST. Other errors make no sense data available. As with NCQ and GPL, only a disk behind AHCI offers the feature set. This feature will be used to populate the NCQ Command Error log and to implement NCQ Autosense. Add a qtest that checks the sense data of an aborted SET FEATURES. Signed-off-by: Niklas Cassel --- hw/ide/ahci.c | 3 + hw/ide/core.c | 146 +++++++++++++++++++++++++++++++++++--- hw/ide/ide-internal.h | 3 +- include/hw/ide/ide-dev.h | 4 ++ tests/qtest/ahci-test.c | 69 ++++++++++++++++++ tests/qtest/libqos/ahci.c | 10 +++ tests/qtest/libqos/ahci.h | 5 +- 7 files changed, 230 insertions(+), 10 deletions(-) diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c index 21938703da..d74d185607 100644 --- a/hw/ide/ahci.c +++ b/hw/ide/ahci.c @@ -1225,6 +1225,9 @@ static void process_ncq_command(AHCIState *s, int por= t, const uint8_t *cmd_fis, ((uint64_t)ncq_fis->lba2 << 16) | ((uint64_t)ncq_fis->lba1 << 8) | (uint64_t)ncq_fis->lba0; + + /* Accepting an NCQ command makes the sense data unavailable (ACS-6 4.= 25) */ + ad->port.ifs[0].sense_data_avail =3D false; ncq_tfs->tag =3D tag; =20 /* Sanity-check the NCQ packet */ diff --git a/hw/ide/core.c b/hw/ide/core.c index 0ccac398b2..2d8bca0762 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -37,6 +37,8 @@ #include "system/dma.h" #include "hw/block/block.h" #include "system/block-backend.h" +#include "scsi/constants.h" +#include "scsi/utils.h" #include "qapi/error.h" #include "qemu/cutils.h" #include "system/replay.h" @@ -244,12 +246,13 @@ static void ide_identify(IDEState *s) } if (s->ncq_queues) { /* - * 14=3Dset to 1, + * 14=3Dset to 1, 6=3DSense Data Reporting supported, * 3=3DREAD LOG DMA EXT/WRITE LOG DMA EXT (GPL DMA) supported */ - put_le16(p + 119, (1 << 14) | (1 << 3)); - /* 14=3Dset to 1, 3=3DGPL DMA enabled */ - put_le16(p + 120, (1 << 14) | (1 << 3)); + put_le16(p + 119, (1 << 14) | (1 << 6) | (1 << 3)); + /* 14=3Dset to 1, 6=3DSense Data Reporting enabled, 3=3DGPL DMA en= abled */ + put_le16(p + 120, (1 << 14) | (1 << 3) | + (s->sense_data_enabled ? (1 << 6) : 0)); } if (dev && dev->conf.discard_granularity) { put_le16(p + 169, 1); /* TRIM support */ @@ -555,11 +558,41 @@ BlockAIOCB *ide_issue_trim( return &iocb->common; } =20 -void ide_abort_command(IDEState *s) +/* + * Record sense data for the Sense Data Reporting feature set (ACS-6 4.25). + * When the feature is enabled the SENSE DATA AVAILABLE bit is reported in= the + * STATUS field so the host can retrieve the sense with REQUEST SENSE DATA= EXT. + * When it is disabled this is a no-op, so the ATAPI sense_key/asc are left + * untouched for packet devices. + */ +static void ide_set_sense(IDEState *s, SCSISense sense) +{ + /* + * NO SENSE means that there is no sense data to report (ACS-6 6.8.31): + * none is made available, and the host relies on the ERROR field. + */ + if (!s->sense_data_enabled || sense.key =3D=3D NO_SENSE) { + return; + } + s->sense_key =3D sense.key; + s->asc =3D sense.asc; + s->ascq =3D sense.ascq; + s->sense_data_avail =3D true; + s->status |=3D SENSE_DATA_STAT; +} + +/* Abort the command, and record @sense for Sense Data Reporting */ +static void ide_abort_command_with_sense(IDEState *s, SCSISense sense) { s->status =3D READY_STAT | ERR_STAT; s->error =3D ABRT_ERR; ide_transfer_stop(s); + ide_set_sense(s, sense); +} + +void ide_abort_command(IDEState *s) +{ + ide_abort_command_with_sense(s, SENSE_CODE(NO_SENSE)); } =20 static void ide_set_retry(IDEState *s) @@ -1432,6 +1465,14 @@ static void ide_reset(IDEState *s, IDEResetKind kind) s->select =3D (ATA_DEV_ALWAYS_ON); s->status =3D READY_STAT | SEEK_STAT; =20 + /* + * Sense data does not survive a reset (ACS-6 4.25), but the enabled + * state of the Sense Data Reporting feature set does: a power-on reset + * should disable it (ACS-6 9.11.5.2.46), but IDE_RESET_HARDWARE also + * covers COMRESET, which must not change it. + */ + s->sense_data_avail =3D false; + s->lba48 =3D 0; =20 /* ATAPI specific */ @@ -1712,6 +1753,7 @@ static const IDEIdentifyBit ide_sata_capabilities[] = =3D { /* The Current Settings QWord of page 04h, terminated by a zero word */ static const IDEIdentifyBit ide_current_settings[] =3D { { 85, 5, 13 }, /* VOLATILE WRITE CACHE ENABLED */ + { 120, 6, 10 }, /* SENSE DATA ENABLED */ { 85, 0, 6 }, /* SMART ENABLED */ { 0 } }; @@ -1932,7 +1974,7 @@ static bool cmd_read_log(IDEState *s, uint8_t cmd) size =3D ide_read_log(s, s->sector, s->lcyl | ((uint16_t)s->hob_lcyl <= < 8), s->nsector); if (size < 0) { - ide_abort_command(s); + ide_abort_command_with_sense(s, SENSE_CODE(INVALID_FIELD)); return true; } =20 @@ -2020,6 +2062,38 @@ static bool cmd_specify(IDEState *s, uint8_t cmd) return true; } =20 +/* + * REQUEST SENSE DATA EXT (0Bh), Sense Data Reporting feature set (ACS-6 7= .35) + */ +static bool cmd_request_sense_data_ext(IDEState *s, uint8_t cmd) +{ + /* + * Return the most recent sense data in the LBA field (ACS-6 table 371= ): + * LBA 7:0 =3D ASCQ, LBA 15:8 =3D ASC, LBA 19:16 =3D SENSE KEY. The CO= UNT and + * upper LBA fields (progress indication / vendor specific) are zeroed. + */ + s->nsector =3D 0; + s->hob_nsector =3D 0; + s->hob_sector =3D 0; + s->hob_lcyl =3D 0; + s->hob_hcyl =3D 0; + + if (s->sense_data_avail) { + s->sector =3D s->ascq; + s->lcyl =3D s->asc; + s->hcyl =3D s->sense_key & 0x0f; + s->status |=3D SENSE_DATA_STAT; + /* The sense data is consumed by reading it (ACS-6 4.25). */ + s->sense_data_avail =3D false; + } else { + s->sector =3D 0; + s->lcyl =3D 0; + s->hcyl =3D 0; + } + + return true; +} + static bool cmd_set_features(IDEState *s, uint8_t cmd) { uint16_t *identify_data; @@ -2049,6 +2123,20 @@ static bool cmd_set_features(IDEState *s, uint8_t cm= d) put_le16(identify_data + 85, ide_identify_word85(s)); ide_flush_cache(s); return false; + case 0xc3: /* enable/disable the Sense Data Reporting feature set */ + if (!s->ncq_queues) { + goto abort_cmd; + } + s->sense_data_enabled =3D s->nsector & 0x01; + identify_data =3D (uint16_t *)s->identify_data; + if (s->sense_data_enabled) { + put_le16(identify_data + 120, + le16_to_cpu(identify_data[120]) | (1 << 6)); + } else { + put_le16(identify_data + 120, + le16_to_cpu(identify_data[120]) & ~(1 << 6)); + } + return true; case 0xcc: /* reverting to power-on defaults enable */ s->reset_reverts =3D true; return true; @@ -2101,7 +2189,7 @@ static bool cmd_set_features(IDEState *s, uint8_t cmd) } =20 abort_cmd: - ide_abort_command(s); + ide_abort_command_with_sense(s, SENSE_CODE(INVALID_FIELD)); return true; } =20 @@ -2443,6 +2531,8 @@ static const struct { [CFA_REQ_EXT_ERROR_CODE] =3D { cmd_cfa_req_ext_error_code, CFA_OK= }, [WIN_DSM] =3D { cmd_data_set_management, HD_CFA_OK= }, [WIN_DEVICE_RESET] =3D { cmd_device_reset, CD_OK }, + [WIN_REQUEST_SENSE_DATA_EXT] =3D { cmd_request_sense_data_ext, + HD_OK | AHCI_ONLY }, [WIN_RECAL] =3D { cmd_nop, HD_CFA_OK | SET_DSC}, [WIN_READ] =3D { cmd_read_pio, ALL_OK }, [WIN_READ_ONCE] =3D { cmd_read_pio, HD_CFA_OK }, @@ -2507,6 +2597,15 @@ static bool ide_cmd_permitted(IDEState *s, uint32_t = cmd) && (s->ncq_queues || !(ide_cmd_table[cmd].flags & AHCI_ONLY)); } =20 +/* + * Whether the sense data stays available once this command is accepted + * (ACS-6 4.25): REQUEST SENSE DATA EXT returns it. + */ +static bool ide_cmd_keeps_sense_data(IDEState *s, uint8_t cmd) +{ + return cmd =3D=3D WIN_REQUEST_SENSE_DATA_EXT; +} + void ide_bus_exec_cmd(IDEBus *bus, uint32_t val) { IDEState *s; @@ -2529,7 +2628,7 @@ void ide_bus_exec_cmd(IDEBus *bus, uint32_t val) } =20 if (!ide_cmd_permitted(s, val)) { - ide_abort_command(s); + ide_abort_command_with_sense(s, SENSE_CODE(INVALID_OPCODE)); ide_bus_set_irq(s->bus); return; } @@ -2538,6 +2637,15 @@ void ide_bus_exec_cmd(IDEBus *bus, uint32_t val) s->error =3D 0; s->io_buffer_offset =3D 0; =20 + /* + * Accepting a command makes the sense data unavailable, unless the co= mmand + * reads it (ACS-6 4.25); a failing command records fresh sense of its= own + * below. + */ + if (!ide_cmd_keeps_sense_data(s, val)) { + s->sense_data_avail =3D false; + } + complete =3D ide_cmd_table[val].handler(s, val); if (complete) { s->status &=3D ~BUSY_STAT; @@ -3368,6 +3476,27 @@ static const VMStateDescription vmstate_ide_tray_sta= te =3D { } }; =20 +static bool ide_sense_data_needed(void *opaque) +{ + IDEState *s =3D opaque; + + return s->sense_data_enabled || s->sense_data_avail; +} + +/* sense_key and asc travel with the main structure (ATAPI shares them) */ +static const VMStateDescription vmstate_ide_sense_data =3D { + .name =3D "ide_drive/sense_data", + .version_id =3D 1, + .minimum_version_id =3D 1, + .needed =3D ide_sense_data_needed, + .fields =3D (const VMStateField[]) { + VMSTATE_BOOL(sense_data_enabled, IDEState), + VMSTATE_BOOL(sense_data_avail, IDEState), + VMSTATE_UINT8(ascq, IDEState), + VMSTATE_END_OF_LIST() + } +}; + static const VMStateDescription vmstate_ide_drive_pio_state =3D { .name =3D "ide_drive/pio_state", .version_id =3D 1, @@ -3423,6 +3552,7 @@ const VMStateDescription vmstate_ide_drive =3D { &vmstate_ide_drive_reset_reverts, &vmstate_ide_tray_state, &vmstate_ide_atapi_gesn_state, + &vmstate_ide_sense_data, NULL } }; diff --git a/hw/ide/ide-internal.h b/hw/ide/ide-internal.h index 382e2a4915..0fb4776356 100644 --- a/hw/ide/ide-internal.h +++ b/hw/ide/ide-internal.h @@ -26,6 +26,7 @@ /* Bits of HD_STATUS */ #define ERR_STAT 0x01 #define INDEX_STAT 0x02 +#define SENSE_DATA_STAT 0x02 /* SENSE DATA AVAILABLE (ACS-6 6.2= .9) */ #define ECC_STAT 0x04 /* Corrected error */ #define DRQ_STAT 0x08 #define SEEK_STAT 0x10 @@ -65,7 +66,7 @@ /* reserved 0x07 */ #define WIN_DEVICE_RESET 0x08 /* reserved 0x09..0x0a */ -/* REQUEST SENSE DATA EXT 0x0B */ +#define WIN_REQUEST_SENSE_DATA_EXT 0x0B /* 48-Bit */ /* reserved 0x0C..0x0F */ #define WIN_RECAL 0x10 /* obsolete since ATA4 */ /* obsolete since ATA3, retired in ATA4 0x11..0x1F */ diff --git a/include/hw/ide/ide-dev.h b/include/hw/ide/ide-dev.h index 258b216b44..01b7952957 100644 --- a/include/hw/ide/ide-dev.h +++ b/include/hw/ide/ide-dev.h @@ -96,6 +96,10 @@ struct IDEState { struct unreported_events events; uint8_t sense_key; uint8_t asc; + /* Sense Data Reporting feature set (ATA HD) */ + uint8_t ascq; + bool sense_data_enabled; + bool sense_data_avail; bool tray_open; bool tray_locked; uint8_t cdrom_changed; diff --git a/tests/qtest/ahci-test.c b/tests/qtest/ahci-test.c index 5e924010f0..e7df8c9fc8 100644 --- a/tests/qtest/ahci-test.c +++ b/tests/qtest/ahci-test.c @@ -1174,6 +1174,63 @@ static void test_read_log_pio(void) ahci_shutdown(ahci); } =20 +/* Restart command list processing after a task file error (AHCI 6.2.2) */ +static void ahci_port_restart(AHCIQState *ahci, unsigned px) +{ + ahci_px_clr(ahci, px, AHCI_PX_CMD, AHCI_PX_CMD_ST); + ahci_port_clear(ahci, px); + ahci_px_set(ahci, px, AHCI_PX_CMD, AHCI_PX_CMD_ST); +} + +/* Issue a non-data command; return the D2H Register FIS it completes with= */ +static RegD2HFIS ahci_nodata_cmd(AHCIQState *ahci, unsigned px, uint8_t op, + uint16_t feature, uint16_t count, uint8_t= err) +{ + AHCICommand *cmd =3D ahci_command_create(op); + RegD2HFIS d2h; + + ahci_command_set_feature(cmd, feature); + ahci_command_set_count(cmd, count); + if (err) { + ahci_command_expect_error(cmd, err); + } + ahci_command_commit(ahci, cmd, px); + ahci_command_issue(ahci, cmd); + ahci_command_verify(ahci, cmd); + ahci_command_free(cmd); + qtest_memread(ahci->parent->qts, ahci->port[px].fb + 0x40, &d2h, + sizeof(d2h)); + return d2h; +} + +/* + * Boot with the Sense Data Reporting feature set enabled, and make sense = data + * available: SET FEATURES with an unsupported subcommand is aborted, which + * records ILLEGAL REQUEST / INVALID FIELD IN CDB. + */ +static AHCIQState *ahci_boot_with_sense_data(unsigned *px) +{ + AHCIQState *ahci; + + ahci =3D ahci_boot_and_enable("-drive if=3Dnone,id=3Ddrive0,file=3D%s,= format=3D%s " + "-M q35 -device ide-hd,drive=3Ddrive0", + tmp_path, imgfmt); + *px =3D ahci_port_select(ahci); + ahci_port_clear(ahci, *px); + ahci_nodata_cmd(ahci, *px, CMD_SET_FEATURES, 0xc3, 1, 0); + ahci_nodata_cmd(ahci, *px, CMD_SET_FEATURES, 0x47, 0, ATA_ERR_ABRT); + ahci_port_restart(ahci, *px); + return ahci; +} + +/* REQUEST SENSE DATA EXT: the sense key, ASC and ASCQ as KKAAQQh */ +static uint32_t ahci_sense(AHCIQState *ahci, unsigned px) +{ + RegD2HFIS fis =3D ahci_nodata_cmd(ahci, px, CMD_REQ_SENSE_DATA, 0, 0, = 0); + + return (fis.lba_lo[2] & 0x0f) << 16 | fis.lba_lo[1] << 8 | fis.lba_lo[= 0]; +} + /** * Fragmented DMA test: Perform a standard 4K DMA read/write * test, but make sure the physical regions are fragmented to @@ -2617,6 +2674,16 @@ static void create_ahci_io_test(enum IOMode type, en= um AddrMode addr, =20 /*************************************************************************= *****/ =20 +static void test_sense_data_set_features(void) +{ + unsigned px; + AHCIQState *ahci =3D ahci_boot_with_sense_data(&px); + + ahci_nodata_cmd(ahci, px, CMD_SET_FEATURES, 0x47, 0, ATA_ERR_ABRT); + g_assert_cmphex(ahci_sense(ahci, px), =3D=3D, 0x052400); + ahci_shutdown(ahci); +} + int main(int argc, char **argv) { const char *arch, *base; @@ -2708,6 +2775,8 @@ int main(int argc, char **argv) qtest_add_func("/ahci/identify", test_identify); qtest_add_func("/ahci/io/dma/read_log", test_read_log_dma); qtest_add_func("/ahci/io/pio/read_log", test_read_log_pio); + qtest_add_func("/ahci/io/sense_data/set_features", + test_sense_data_set_features); =20 for (i =3D MODE_BEGIN; i < NUM_MODES; i++) { for (j =3D ADDR_MODE_BEGIN; j < NUM_ADDR_MODES; j++) { diff --git a/tests/qtest/libqos/ahci.c b/tests/qtest/libqos/ahci.c index d50ff4767b..a4790c2f0c 100644 --- a/tests/qtest/libqos/ahci.c +++ b/tests/qtest/libqos/ahci.c @@ -71,6 +71,8 @@ AHCICommandProp ahci_command_properties[] =3D { .lba48 =3D true, .read =3D true }, { .cmd =3D CMD_READ_LOG_DMA_EXT, .data =3D true, .dma =3D true, .lba48 =3D true, .read =3D true }, + { .cmd =3D CMD_SET_FEATURES, .data =3D false }, + { .cmd =3D CMD_REQ_SENSE_DATA, .lba48 =3D true }, { .cmd =3D READ_FPDMA_QUEUED, .data =3D true, .dma =3D true, .lba48 =3D true, .read =3D true, .ncq =3D= true }, { .cmd =3D WRITE_FPDMA_QUEUED, .data =3D true, .dma =3D true, @@ -1219,6 +1221,14 @@ void ahci_command_set_ncq_subcmd(AHCICommand *cmd, u= int8_t subcmd) nfis->prio =3D (nfis->prio & ~0x1f) | (subcmd & 0x1f); } =20 +/* Set the 16-bit FEATURE field of a (non-NCQ) command. */ +void ahci_command_set_feature(AHCICommand *cmd, uint16_t feature) +{ + g_assert(!cmd->props->ncq); + cmd->fis.feature_low =3D feature & 0xff; + cmd->fis.feature_high =3D (feature >> 8) & 0xff; +} + void ahci_command_expect_error(AHCICommand *cmd, uint8_t err) { cmd->interrupts |=3D AHCI_PX_IS_TFES; diff --git a/tests/qtest/libqos/ahci.h b/tests/qtest/libqos/ahci.h index 9b40eabe35..a23ea8b2f0 100644 --- a/tests/qtest/libqos/ahci.h +++ b/tests/qtest/libqos/ahci.h @@ -282,6 +282,8 @@ enum { CMD_IDENTIFY =3D 0xEC, CMD_READ_LOG_EXT =3D 0x2F, CMD_READ_LOG_DMA_EXT =3D 0x47, + CMD_SET_FEATURES =3D 0xEF, + CMD_REQ_SENSE_DATA =3D 0x0B, CMD_PACKET =3D 0xA0, CMD_PACKET_ID =3D 0xA1, /* NCQ */ @@ -654,9 +656,10 @@ void ahci_command_set_sizes(AHCICommand *cmd, uint64_t= xbytes, unsigned prd_size); void ahci_command_set_count(AHCICommand *cmd, uint16_t count); void ahci_command_set_ncq_subcmd(AHCICommand *cmd, uint8_t subcmd); -void ahci_command_expect_error(AHCICommand *cmd, uint8_t err); void ahci_command_set_acmd(AHCICommand *cmd, void *acmd); void ahci_command_enable_atapi_dma(AHCICommand *cmd); +void ahci_command_set_feature(AHCICommand *cmd, uint16_t feature); +void ahci_command_expect_error(AHCICommand *cmd, uint8_t err); void ahci_command_adjust(AHCICommand *cmd, uint64_t lba_sect, uint64_t gbu= ffer, uint64_t xbytes, unsigned prd_size); =20 --=20 2.56.1 From nobody Sun Nov 29 10:11:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1795806891; cv=none; d=zohomail.com; s=zohoarc; b=eQK6RTP6Z4ML0lJEd1tRRZ7tZyuC+AOR1/OYEDNdE7Fp1qYJStnoywGVLKnRDZHCc4aRb8cyu6zBn7VlZx/Nh8bWC84s7YKFReqiO5pfV7uXFneSHUq25icLErvL4mzPLfdFRMNSrZRd8L2imv6K+1WYdmO23tItNKJ4fKsyK0o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1795806891; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=PGSOanl9FMlh1JHYI/Ey4bBrmsXYkjx2r5nfBWUKPbM=; b=L3nm7j/hTIfDd0gTwVo/qQpwF+vHRh5w4WlCOPMTZxmXBauU8SNha4hnIY31g9ZLS3AZ5fsesphKE/CTSNapF+xeI2n+Fpcem1VH0PScRG6ZMuAMHQ7hSPBnav+2lhW+O2CBKW0h31JnmusWjDvqo242WiL2aZ42lhp7ffDw8UY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1795806891030335.31801304781345; Fri, 27 Nov 2026 11:14:51 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xX1Ob-0002FI-Uo; Fri, 27 Nov 2026 14:14:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xX1Nu-0001sa-Ix; Fri, 27 Nov 2026 14:13:28 -0500 Received: from sea.source.kernel.org ([172.234.252.31]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xX1Nq-0007AI-Th; Fri, 27 Nov 2026 14:13:26 -0500 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id BAC9140F67; Fri, 27 Nov 2026 19:13:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4CCE11F0089C; Fri, 27 Nov 2026 19:13:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795806801; bh=PGSOanl9FMlh1JHYI/Ey4bBrmsXYkjx2r5nfBWUKPbM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=RwEY30oGoGXnWj4n+a7ywnJU5L3SUNkuHvxjwp/wTKHFihuI4B809VKTvH4OIRqfa zByYV5MxF/pBY4GQvmlu6vQ2mckxFIJGvMj1N112eom2TKXCABNDOx82OGIjWk442K 4rUmlpC7X5yj7HiLq34P26Hg8vdBoiFecf7K5yDwfMltC44UvhU0w7qUWlxUZd8xU9 /14ZoZF2cqFoRUVKRheMYxjrIuLhQWjbDxyKnSeRFl7bJAxn7tZuqsd7G9I+VHbkMP HQ6lmSluKDjL0u0U3Gh4bZL62rgzM0AKbiQdXKVIfQjc2eC9LqmbVm2cXy4ljIxAcN hpmcckZtNx58A== From: Niklas Cassel To: John Snow , "Denis V. Lunev" , Fabiano Rosas , Laurent Vivier , Paolo Bonzini Cc: Damien Le Moal , Niklas Cassel , qemu-block@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH 09/13] hw/ide: implement the NCQ Command Error log (10h) Date: Fri, 27 Nov 2026 20:12:44 +0100 Message-ID: <20261127191250.3298004-10-cassel@kernel.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261127191250.3298004-1-cassel@kernel.org> References: <20261127191250.3298004-1-cassel@kernel.org> 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+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=172.234.252.31; envelope-from=cassel@kernel.org; helo=sea.source.kernel.org X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1795806892131158500 Content-Type: text/plain; charset="utf-8" As per ACS-6 9.15, when an NCQ command fails, the device enter the NCQ error state, and the host shall read the NCQ Command Error log (10h) to find out which command that failed. The NCQ Command Error log is a mandatory part of the NCQ feature set. QEMU did not implement this mandatory part, making it impossible for the host to know which command that failed. Record the failed command in the log, with its sense data through NCQ Autosense. Report INVALID COMMAND OPERATION CODE for an unsupported NCQ command, INVALID FIELD IN CDB for an invalid RECEIVE FPDMA QUEUED, and none for a failed read or write. A PRDT that is too short for the transfer is detected by the HBA, not the device (AHCI 1.3.1 6.1.5), so for that case, the command is only released and OFS raised, without recording an error. Once the device has entered the NCQ error state (see DFPDMAQ11 to DFPDMAQ15), the outstanding NCQ commands neither complete nor fail, and new commands are aborted (except for a READ LOG of the NCQ Command Error log) or the port is reset. Add qtests for the log contents, the error state and the sense data. Signed-off-by: Niklas Cassel --- hw/ide/ahci.c | 87 ++++++++++++--- hw/ide/core.c | 145 +++++++++++++++++++++++- hw/ide/ide-internal.h | 9 ++ include/hw/ide/ide-dev.h | 17 +++ tests/qtest/ahci-test.c | 231 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 473 insertions(+), 16 deletions(-) diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c index d74d185607..a1fe0cc72d 100644 --- a/hw/ide/ahci.c +++ b/hw/ide/ahci.c @@ -779,9 +779,9 @@ static void ahci_unmap_clb_address(AHCIDevice *ad) ad->lst =3D NULL; } =20 -static void ahci_write_fis_sdb(AHCIState *s, NCQTransferState *ncq_tfs) +static void ahci_write_fis_sdb(AHCIDevice *ad, bool irq) { - AHCIDevice *ad =3D ncq_tfs->drive; + AHCIState *s =3D ad->hba; AHCIPortRegs *pr =3D &ad->port_regs; IDEState *ide_state; SDBFIS *sdb_fis; @@ -796,7 +796,7 @@ static void ahci_write_fis_sdb(AHCIState *s, NCQTransfe= rState *ncq_tfs) =20 sdb_fis->type =3D SATA_FIS_TYPE_SDB; /* Interrupt pending & Notification bit */ - sdb_fis->flags =3D 0x40; /* Interrupt bit, always 1 for NCQ */ + sdb_fis->flags =3D irq ? 0x40 : 0; /* Interrupt bit */ sdb_fis->status =3D ide_state->status & 0x77; sdb_fis->error =3D ide_state->error; /* update SAct field in SDB_FIS */ @@ -1021,12 +1021,17 @@ out: return r; } =20 -static void ncq_err(NCQTransferState *ncq_tfs) +static void ncq_err(NCQTransferState *ncq_tfs, SCSISense sense) { IDEState *ide_state =3D &ncq_tfs->drive->port.ifs[0]; =20 - ide_state->error =3D ABRT_ERR; - ide_state->status =3D READY_STAT | ERR_STAT; + /* + * Record the failure (status/error registers and the NCQ Command Error + * log, 10h) so that the host can retrieve it after being notified of = the + * error via the Set Device Bits FIS. + */ + ide_ncq_cmd_error(ide_state, ncq_tfs->tag, ncq_tfs->lba, + ncq_tfs->sector_count, sense); qemu_sglist_destroy(&ncq_tfs->sglist); ncq_tfs->used =3D 0; } @@ -1040,7 +1045,7 @@ static void ncq_finish(NCQTransferState *ncq_tfs) ncq_tfs->drive->finished |=3D (1 << ncq_tfs->tag); } =20 - ahci_write_fis_sdb(ncq_tfs->drive->hba, ncq_tfs); + ahci_write_fis_sdb(ncq_tfs->drive, true); =20 trace_ncq_finish(ncq_tfs->drive->hba, ncq_tfs->drive->port_no, ncq_tfs->tag); @@ -1058,6 +1063,17 @@ static void ncq_cb(void *opaque, int ret) =20 ncq_tfs->aiocb =3D NULL; =20 + /* + * The device stopped processing NCQ commands when another one failed + * (SATA 3.5a DFPDMAQ11): this one neither completes nor fails. + */ + if (ide_state->ncq_err.active) { + block_acct_failed(blk_get_stats(ide_state->blk), &ncq_tfs->acct); + qemu_sglist_destroy(&ncq_tfs->sglist); + ncq_tfs->used =3D 0; + return; + } + if (ret < 0) { bool is_read =3D ncq_tfs->cmd =3D=3D READ_FPDMA_QUEUED; BlockErrorAction action =3D blk_get_error_action(ide_state->blk, @@ -1066,7 +1082,7 @@ static void ncq_cb(void *opaque, int ret) ncq_tfs->halt =3D true; ide_state->bus->error_status =3D IDE_RETRY_HBA; } else if (action =3D=3D BLOCK_ERROR_ACTION_REPORT) { - ncq_err(ncq_tfs); + ncq_err(ncq_tfs, SENSE_CODE(NO_SENSE)); } blk_error_action(ide_state->blk, action, is_read, -ret); } else { @@ -1114,7 +1130,7 @@ static void execute_ncq_receive_fpdma_queued(NCQTrans= ferState *ncq_tfs) ncq_tfs->sector_count); =20 if (size < 0) { - ncq_err(ncq_tfs); + ncq_err(ncq_tfs, SENSE_CODE(INVALID_FIELD)); break; } dma_buf_read(ide_state->io_buffer, size, NULL, &ncq_tfs->sglist, @@ -1123,7 +1139,7 @@ static void execute_ncq_receive_fpdma_queued(NCQTrans= ferState *ncq_tfs) break; } default: - ncq_err(ncq_tfs); + ncq_err(ncq_tfs, SENSE_CODE(INVALID_FIELD)); break; } =20 @@ -1168,7 +1184,7 @@ static void execute_ncq_command(NCQTransferState *ncq= _tfs) default: trace_execute_ncq_command_unsup(ad->hba, port, ncq_tfs->tag, ncq_tfs->cmd); - ncq_err(ncq_tfs); + ncq_err(ncq_tfs, SENSE_CODE(INVALID_OPCODE)); ncq_finish(ncq_tfs); } } @@ -1184,6 +1200,18 @@ static void process_ncq_command(AHCIState *s, int po= rt, const uint8_t *cmd_fis, size_t size; =20 g_assert(is_ncq(ncq_fis->command)); + + /* + * After an NCQ command failed, any other command is aborted (SATA 3.5a + * DFPDMAQ12, DFPDMAQ13), until the host reads the NCQ Command Error l= og. + */ + if (ad->port.ifs[0].ncq_err.active) { + ad->port.ifs[0].status =3D READY_STAT | ERR_STAT; + ad->port.ifs[0].error =3D ABRT_ERR; + ahci_write_fis_d2h(ad, false); + return; + } + if (ncq_tfs->used) { /* error - already in use */ qemu_log_mask(LOG_GUEST_ERROR, "%s: tag %d already used\n", @@ -1226,8 +1254,15 @@ static void process_ncq_command(AHCIState *s, int po= rt, const uint8_t *cmd_fis, ((uint64_t)ncq_fis->lba1 << 8) | (uint64_t)ncq_fis->lba0; =20 - /* Accepting an NCQ command makes the sense data unavailable (ACS-6 4.= 25) */ - ad->port.ifs[0].sense_data_avail =3D false; + /* + * Accepting an NCQ command makes the sense data unavailable, unless it + * reads the NCQ Command Error log (ACS-6 4.25). + */ + if (!(ncq_fis->command =3D=3D RECEIVE_FPDMA_QUEUED && + ncq_tfs->subcmd =3D=3D RECEIVE_FPDMA_READ_LOG_DMA_EXT && + (ncq_tfs->lba & 0xff) =3D=3D IDE_GPL_LOG_NCQ_CMD_ERROR)) { + ad->port.ifs[0].sense_data_avail =3D false; + } ncq_tfs->tag =3D tag; =20 /* Sanity-check the NCQ packet */ @@ -1260,7 +1295,12 @@ static void process_ncq_command(AHCIState *s, int po= rt, const uint8_t *cmd_fis, error_report("ahci: PRDT length for NCQ command (0x" DMA_ADDR_FMT = ") " "is smaller than the requested size (0x%zx)", ncq_tfs->sglist.size, size); - ncq_err(ncq_tfs); + /* + * The HBA detected the overflow, not the device (AHCI 1.3.1 6.1.5= ): + * release the command without recording an NCQ error. + */ + qemu_sglist_destroy(&ncq_tfs->sglist); + ncq_tfs->used =3D 0; ahci_trigger_irq(ad->hba, ad, AHCI_PORT_IRQ_BIT_OFS); return; } else if (ncq_tfs->sglist.size !=3D size) { @@ -1394,6 +1434,25 @@ static void handle_reg_h2d_fis(AHCIState *s, int por= t, */ ad->busy_slot =3D slot; =20 + /* + * Reading the NCQ Command Error log ends the NCQ error state: the dev= ice + * discards the queued commands, and reports this with a Set Device Bi= ts + * FIS that has ERR cleared and all ACT bits set, but no interrupt (SA= TA + * 3.5a DFPDMAQ14, DFPDMAQ15; IDENTIFY DEVICE word 76 bit 15 is set for + * NCQ devices, which allows READ LOG DMA EXT). + */ + if (ide_state->ncq_err.active && + (cmd_fis[2] =3D=3D WIN_READ_LOG_EXT || + cmd_fis[2] =3D=3D WIN_READ_LOG_DMA_EXT) && + cmd_fis[4] =3D=3D IDE_GPL_LOG_NCQ_CMD_ERROR) { + ahci_cancel_ncq_requests(ad); + ide_state->ncq_err.active =3D false; + ide_state->status =3D READY_STAT | SEEK_STAT; + ide_state->error =3D 0; + ad->finished =3D 0xffffffff; + ahci_write_fis_sdb(ad, false); + } + /* We're ready to process the command in FIS byte 2. */ ide_bus_exec_cmd(&s->dev[port].port, cmd_fis[2]); } diff --git a/hw/ide/core.c b/hw/ide/core.c index 2d8bca0762..cc38a3ef65 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -204,6 +204,8 @@ static void ide_identify(IDEState *s) put_le16(p + 76, (1 << 15) | (1 << 8)); /* 6=3DSEND AND RECEIVE QUEUED COMMANDS supported (SATA NCQ log 13= h) */ put_le16(p + 77, (1 << 6)); + /* SATA features supported: 7=3DNCQ Autosense (sense in NCQ error = log) */ + put_le16(p + 78, (1 << 7)); } =20 put_le16(p + 80, 0xf0); /* ata3 -> ata6 supported */ @@ -595,6 +597,42 @@ void ide_abort_command(IDEState *s) ide_abort_command_with_sense(s, SENSE_CODE(NO_SENSE)); } =20 +/* + * Record the most recent NCQ command failure so that it can be reported + * through the NCQ Command Error log (10h) when the host reads it. Unlike = the + * Sense Data Reporting feature set, the NCQ Autosense sense data is always + * recorded (its presence in the log is gated on NCQ Autosense support). + */ +void ide_ncq_cmd_error(IDEState *s, uint8_t tag, uint64_t lba, + uint16_t count, SCSISense sense) +{ + s->status =3D READY_STAT | ERR_STAT; + s->error =3D ABRT_ERR; + + /* + * The device processes no other command until the host reads the log = or + * resets the device (SATA 3.5a DFPDMAQ11, DFPDMAQ13). + */ + s->ncq_err.active =3D true; + s->ncq_err.valid =3D true; + s->ncq_err.tag =3D tag; + /* + * The STATUS field in the log advertises SENSE DATA AVAILABLE (ACS-6 = 6.2.9) + * if there is sense data, so that a host supporting NCQ Autosense rea= ds the + * sense key / ASC / ASCQ from the log (libata only does so when this = bit + * is set). NO SENSE means that there is none (ACS-6 6.8.31). + */ + s->ncq_err.status =3D s->status | + (sense.key !=3D NO_SENSE ? SENSE_DATA_STAT : 0); + s->ncq_err.error =3D s->error; + s->ncq_err.device =3D 1 << 6; /* LBA addressing */ + s->ncq_err.lba =3D lba; + s->ncq_err.count =3D count; + s->ncq_err.sense_key =3D sense.key; + s->ncq_err.asc =3D sense.asc; + s->ncq_err.ascq =3D sense.ascq; +} + static void ide_set_retry(IDEState *s) { s->bus->retry_unit =3D s->unit; @@ -1472,6 +1510,7 @@ static void ide_reset(IDEState *s, IDEResetKind kind) * covers COMRESET, which must not change it. */ s->sense_data_avail =3D false; + s->ncq_err.active =3D false; =20 s->lba48 =3D 0; =20 @@ -1882,6 +1921,54 @@ static void ide_fill_identify_device_log(IDEState *s= , uint16_t page, } } =20 +/* + * Fill the NCQ Command Error log (Log Address 10h) - ACS-6 9.15, SATA 3.5a + * 13.7.4. Page 0 reports the most recent NCQ command failure. + */ +static void ide_fill_ncq_cmd_error_log(IDEState *s, uint16_t page, + uint32_t count) +{ + uint32_t p; + + memset(s->io_buffer, 0, count * 512); + + for (p =3D 0; p < count; p++) { + uint8_t *buf =3D s->io_buffer + p * 512; + unsigned int sum =3D 0; + int i; + + if (page + p =3D=3D 0) { + if (s->ncq_err.valid) { + /* NQ=3D0, DEFERRED=3D0, NCQ TAG field valid (ACS-6 9.15.2= ). */ + buf[0] =3D s->ncq_err.tag & 0x1f; + buf[2] =3D s->ncq_err.status; + buf[3] =3D s->ncq_err.error; + buf[4] =3D s->ncq_err.lba; + buf[5] =3D s->ncq_err.lba >> 8; + buf[6] =3D s->ncq_err.lba >> 16; + buf[7] =3D s->ncq_err.device; + buf[8] =3D s->ncq_err.lba >> 24; + buf[9] =3D s->ncq_err.lba >> 32; + buf[10] =3D s->ncq_err.lba >> 40; + buf[12] =3D s->ncq_err.count; + buf[13] =3D s->ncq_err.count >> 8; + buf[14] =3D s->ncq_err.sense_key; + buf[15] =3D s->ncq_err.asc; + buf[16] =3D s->ncq_err.ascq; + } else { + /* NQ=3D1: the NCQ TAG field is not valid (ACS-6 9.15.3). = */ + buf[0] =3D 1 << 7; + } + } + + /* Each page ends with a checksum making its bytes sum to zero. */ + for (i =3D 0; i < 511; i++) { + sum +=3D buf[i]; + } + buf[511] =3D -sum; + } +} + /* * Fill the I/O buffer with the General Purpose Logging data selected by * log_address, page and count (the LOG PAGE COUNT, in 512-byte pages) and @@ -1898,6 +1985,12 @@ int ide_read_log(IDEState *s, uint8_t log_address, u= int16_t page, case IDE_GPL_LOG_DIRECTORY: log_size =3D 1; break; + case IDE_GPL_LOG_NCQ_CMD_ERROR: + if (!s->ncq_queues) { + return -1; + } + log_size =3D 1; + break; case IDE_GPL_LOG_NCQ_SEND_RECV: /* Only meaningful for devices that support the NCQ feature set. */ if (!s->ncq_queues) { @@ -1933,6 +2026,7 @@ int ide_read_log(IDEState *s, uint8_t log_address, ui= nt16_t page, put_le16((uint16_t *)s->io_buffer + IDE_GPL_LOG_IDENTIFY_DEVICE, IDE_GPL_LOG_IDENTIFY_DEVICE_LEN); if (s->ncq_queues) { + put_le16((uint16_t *)s->io_buffer + IDE_GPL_LOG_NCQ_CMD_ERROR,= 1); put_le16((uint16_t *)s->io_buffer + IDE_GPL_LOG_NCQ_SEND_RECV,= 1); } break; @@ -1946,6 +2040,9 @@ int ide_read_log(IDEState *s, uint8_t log_address, ui= nt16_t page, */ stl_le_p(s->io_buffer + 8, (1 << 1) | (1 << 0)); break; + case IDE_GPL_LOG_NCQ_CMD_ERROR: + ide_fill_ncq_cmd_error_log(s, page, count); + break; case IDE_GPL_LOG_IDENTIFY_DEVICE: ide_fill_identify_device_log(s, page, count); break; @@ -2599,11 +2696,14 @@ static bool ide_cmd_permitted(IDEState *s, uint32_t= cmd) =20 /* * Whether the sense data stays available once this command is accepted - * (ACS-6 4.25): REQUEST SENSE DATA EXT returns it. + * (ACS-6 4.25): REQUEST SENSE DATA EXT returns it, and reading the NCQ + * Command Error log does not discard it. */ static bool ide_cmd_keeps_sense_data(IDEState *s, uint8_t cmd) { - return cmd =3D=3D WIN_REQUEST_SENSE_DATA_EXT; + return cmd =3D=3D WIN_REQUEST_SENSE_DATA_EXT || + ((cmd =3D=3D WIN_READ_LOG_EXT || cmd =3D=3D WIN_READ_LOG_DMA_EX= T) && + s->sector =3D=3D IDE_GPL_LOG_NCQ_CMD_ERROR); } =20 void ide_bus_exec_cmd(IDEBus *bus, uint32_t val) @@ -2627,6 +2727,18 @@ void ide_bus_exec_cmd(IDEBus *bus, uint32_t val) } } =20 + /* + * After an NCQ command failed, any other command is aborted (SATA 3.5a + * DFPDMAQ13). The HBA ends that state before issuing a read of the NCQ + * Command Error log. + */ + if (s->ncq_err.active) { + ide_abort_command(s); + ide_cmd_done(s); + ide_bus_set_irq(s->bus); + return; + } + if (!ide_cmd_permitted(s, val)) { ide_abort_command_with_sense(s, SENSE_CODE(INVALID_OPCODE)); ide_bus_set_irq(s->bus); @@ -3497,6 +3609,34 @@ static const VMStateDescription vmstate_ide_sense_da= ta =3D { } }; =20 +static bool ide_ncq_err_needed(void *opaque) +{ + IDEState *s =3D opaque; + + return s->ncq_err.valid; +} + +static const VMStateDescription vmstate_ide_ncq_err =3D { + .name =3D "ide_drive/ncq_err", + .version_id =3D 1, + .minimum_version_id =3D 1, + .needed =3D ide_ncq_err_needed, + .fields =3D (const VMStateField[]) { + VMSTATE_BOOL(ncq_err.valid, IDEState), + VMSTATE_BOOL(ncq_err.active, IDEState), + VMSTATE_UINT8(ncq_err.tag, IDEState), + VMSTATE_UINT8(ncq_err.status, IDEState), + VMSTATE_UINT8(ncq_err.error, IDEState), + VMSTATE_UINT8(ncq_err.device, IDEState), + VMSTATE_UINT8(ncq_err.sense_key, IDEState), + VMSTATE_UINT8(ncq_err.asc, IDEState), + VMSTATE_UINT8(ncq_err.ascq, IDEState), + VMSTATE_UINT16(ncq_err.count, IDEState), + VMSTATE_UINT64(ncq_err.lba, IDEState), + VMSTATE_END_OF_LIST() + } +}; + static const VMStateDescription vmstate_ide_drive_pio_state =3D { .name =3D "ide_drive/pio_state", .version_id =3D 1, @@ -3553,6 +3693,7 @@ const VMStateDescription vmstate_ide_drive =3D { &vmstate_ide_tray_state, &vmstate_ide_atapi_gesn_state, &vmstate_ide_sense_data, + &vmstate_ide_ncq_err, NULL } }; diff --git a/hw/ide/ide-internal.h b/hw/ide/ide-internal.h index 0fb4776356..b39b5460c3 100644 --- a/hw/ide/ide-internal.h +++ b/hw/ide/ide-internal.h @@ -8,6 +8,7 @@ */ =20 #include "hw/ide/ide-bus.h" +#include "scsi/utils.h" =20 /* debug IDE devices */ #define USE_DMA_CDROM @@ -213,6 +214,7 @@ * READ LOG EXT / READ LOG DMA EXT (see ACS-6 9.1 table 222). */ #define IDE_GPL_LOG_DIRECTORY 0x00 /* General Purpose Log Direct= ory */ +#define IDE_GPL_LOG_NCQ_CMD_ERROR 0x10 /* NCQ Command Error log */ #define IDE_GPL_LOG_NCQ_SEND_RECV 0x13 /* SATA NCQ Send and Receive = log */ #define IDE_GPL_LOG_IDENTIFY_DEVICE 0x30 /* IDENTIFY DEVICE data log */ =20 @@ -456,6 +458,13 @@ void ide_bus_exec_cmd(IDEBus *bus, uint32_t val); int ide_read_log(IDEState *s, uint8_t log_address, uint16_t page, uint32_t count); =20 +/* + * Record the most recent NCQ command failure, with its sense data, so tha= t it + * can be reported through the NCQ Command Error log (10h). + */ +void ide_ncq_cmd_error(IDEState *s, uint8_t tag, uint64_t lba, + uint16_t count, SCSISense sense); + 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, diff --git a/include/hw/ide/ide-dev.h b/include/hw/ide/ide-dev.h index 01b7952957..8cdce3b517 100644 --- a/include/hw/ide/ide-dev.h +++ b/include/hw/ide/ide-dev.h @@ -51,6 +51,22 @@ enum ide_dma_cmd { IDE_DMA__COUNT }; =20 +/* The NCQ Command Error log (10h) and the NCQ error state */ +typedef struct IDENCQError { + bool valid; /* the log holds a failed NCQ command */ + /* NCQ error: waiting for log 10h or a reset (SATA 3.5a DFPDMAQ13) */ + bool active; + uint8_t tag; + uint8_t status; + uint8_t error; + uint8_t device; + uint8_t sense_key; + uint8_t asc; + uint8_t ascq; + uint16_t count; + uint64_t lba; +} IDENCQError; + /* NOTE: IDEState represents in fact one drive */ struct IDEState { IDEBus *bus; @@ -100,6 +116,7 @@ struct IDEState { uint8_t ascq; bool sense_data_enabled; bool sense_data_avail; + IDENCQError ncq_err; bool tray_open; bool tray_locked; uint8_t cdrom_changed; diff --git a/tests/qtest/ahci-test.c b/tests/qtest/ahci-test.c index e7df8c9fc8..df9295906c 100644 --- a/tests/qtest/ahci-test.c +++ b/tests/qtest/ahci-test.c @@ -1938,6 +1938,231 @@ static void test_ncq_read_log(void) ahci_shutdown(ahci); } =20 +/* + * A failed NCQ command is reported through the NCQ Command Error log (10h= ): + * the host is notified via the Set Device Bits FIS and then reads the log= to + * learn which tag failed and why. Here an injected I/O error fails a WRITE + * FPDMA QUEUED. The error has no more specific reason, so the log has no + * sense data. + */ +static void test_ncq_cmd_error(void) +{ + AHCIQState *ahci; + AHCICommand *cmd; + uint16_t dir[256]; + uint8_t *log; + uint64_t ptr; + unsigned px; + unsigned int sum =3D 0; + int i; + + prepare_blkdebug_script(debug_path, "write_aio"); + ahci =3D ahci_boot_and_enable("-drive file=3Dblkdebug:%s:%s,if=3Dnone,= id=3Ddrive0," + "format=3D%s,cache=3Dwriteback," + "rerror=3Dreport,werror=3Dreport " + "-M q35 -device ide-hd,drive=3Ddrive0", + debug_path, tmp_path, imgfmt); + px =3D ahci_port_select(ahci); + ahci_port_clear(ahci, px); + + /* The NCQ Command Error log (10h) is advertised, one page long. */ + ahci_io(ahci, px, CMD_READ_LOG_DMA_EXT, dir, 512, 0x00); + g_assert_cmphex(le16_to_cpu(dir[0x10]), =3D=3D, 1); + + /* An NCQ write of one sector at LBA 8 that fails with an I/O error. */ + ptr =3D ahci_alloc(ahci, 512); + g_assert(ptr); + cmd =3D ahci_command_create(WRITE_FPDMA_QUEUED); + ahci_command_set_buffer(cmd, ptr); + ahci_command_set_size(cmd, 512); + ahci_command_set_offset(cmd, 8); + ahci_command_expect_error(cmd, ATA_ERR_ABRT); + ahci_command_commit(ahci, cmd, px); + ahci_command_issue(ahci, cmd); + ahci_command_verify(ahci, cmd); + ahci_command_free(cmd); + ahci_free(ahci, ptr); + + /* Read the NCQ Command Error log; page 0 records the failure. */ + log =3D g_malloc0(512); + ahci_io(ahci, px, CMD_READ_LOG_DMA_EXT, log, 512, 0x10); + + g_assert_cmphex(log[0] & (1 << 7), =3D=3D, 0); /* NQ=3D0: NCQ tag is v= alid */ + g_assert_cmphex(log[2], =3D=3D, 0x41); /* STATUS: DRDY | ERR */ + g_assert_cmphex(log[3], =3D=3D, 0x04); /* ERROR: ABRT */ + g_assert_cmphex(log[4], =3D=3D, 8); /* LBA (7:0) */ + g_assert_cmphex(log[12], =3D=3D, 1); /* COUNT (7:0) */ + /* No sense data: SENSE KEY, ASC and ASCQ are zero. */ + g_assert_cmphex(log[14], =3D=3D, 0x00); + g_assert_cmphex(log[15], =3D=3D, 0x00); + g_assert_cmphex(log[16], =3D=3D, 0x00); + for (i =3D 0; i < 512; i++) { + sum +=3D log[i]; + } + g_assert_cmphex(sum & 0xff, =3D=3D, 0); /* checksum: bytes sum = to zero */ + + g_free(log); + ahci_shutdown(ahci); +} + +/* The sense key that REQUEST SENSE DATA EXT returns (LBA 19:16) */ +static uint8_t ahci_sense_key(AHCIQState *ahci, unsigned px) +{ + return ahci_nodata_cmd(ahci, px, CMD_REQ_SENSE_DATA, 0, 0, 0).lba_lo[2= ] & + 0x0f; +} + +/* READ LOG DMA EXT of the NCQ Command Error log (10h) */ +static void ahci_read_ncq_log(AHCIQState *ahci, unsigned px) +{ + uint8_t log[512]; + + ahci_io(ahci, px, CMD_READ_LOG_DMA_EXT, log, 512, 0x10); +} + +/* + * Reading the NCQ Command Error log does not make the sense data unavaila= ble + * (ACS-6 4.25), with READ LOG DMA EXT or with RECEIVE FPDMA QUEUED. + */ +static void test_sense_data_ncq_log(void) +{ + AHCICommand *cmd; + uint64_t ptr; + unsigned px; + AHCIQState *ahci =3D ahci_boot_with_sense_data(&px); + + ahci_read_ncq_log(ahci, px); + g_assert_cmphex(ahci_sense_key(ahci, px), =3D=3D, 0x05); /* ILLEGAL RE= QUEST */ + + ahci_nodata_cmd(ahci, px, CMD_SET_FEATURES, 0x47, 0, ATA_ERR_ABRT); + ahci_port_restart(ahci, px); + ptr =3D ahci_alloc(ahci, 512); + cmd =3D ahci_command_create(RECEIVE_FPDMA_QUEUED); + ahci_command_set_ncq_subcmd(cmd, 0x01); /* READ LOG DMA EXT */ + ahci_command_set_buffer(cmd, ptr); + ahci_command_set_size(cmd, 512); + ahci_command_set_offset(cmd, 0x10); /* LOG ADDRESS 10h */ + ahci_command_commit(ahci, cmd, px); + ahci_command_issue(ahci, cmd); + ahci_command_verify(ahci, cmd); + ahci_command_free(cmd); + ahci_free(ahci, ptr); + g_assert_cmphex(ahci_sense_key(ahci, px), =3D=3D, 0x05); + + ahci_shutdown(ahci); +} + +/* Accepting an NCQ command makes the sense data unavailable (ACS-6 4.25).= */ +static void test_sense_data_ncq_cmd(void) +{ + uint8_t buf[512]; + unsigned px; + AHCIQState *ahci =3D ahci_boot_with_sense_data(&px); + + ahci_io(ahci, px, READ_FPDMA_QUEUED, buf, 512, 0); + g_assert_cmphex(ahci_sense_key(ahci, px), =3D=3D, 0); + + ahci_shutdown(ahci); +} + +/* Issue a 512-byte NCQ command that the device is expected to abort */ +static void ahci_ncq_expect_abort(AHCIQState *ahci, unsigned px, uint8_t o= p, + uint8_t subcmd, uint64_t lba, uint64_t p= tr) +{ + AHCICommand *cmd =3D ahci_command_create(op); + + if (subcmd) { + ahci_command_set_ncq_subcmd(cmd, subcmd); + } + ahci_command_set_buffer(cmd, ptr); + ahci_command_set_size(cmd, 512); + ahci_command_set_offset(cmd, lba); + ahci_command_expect_error(cmd, ATA_ERR_ABRT); + ahci_command_commit(ahci, cmd, px); + ahci_command_issue(ahci, cmd); + ahci_command_verify(ahci, cmd); + ahci_command_free(cmd); +} + +/* + * After an NCQ command fails, the device processes no other command until= the + * host reads the NCQ Command Error log or resets the device (SATA 3.5a + * DFPDMAQ11, DFPDMAQ13). Reading the log discards the queued commands wit= h a + * Set Device Bits FIS that has ERR cleared and ACT set to FFFFFFFFh + * (DFPDMAQ15), after which commands are processed again. + */ +static void test_ncq_error_state(void) +{ + uint8_t buf[512], sdb[8]; + AHCIQState *ahci; + uint64_t ptr; + unsigned px; + + prepare_blkdebug_script(debug_path, "write_aio"); + ahci =3D ahci_boot_and_enable("-drive file=3Dblkdebug:%s:%s,if=3Dnone,= id=3Ddrive0," + "format=3D%s,rerror=3Dreport,werror=3Drepo= rt " + "-M q35 -device ide-hd,drive=3Ddrive0", + debug_path, tmp_path, imgfmt); + px =3D ahci_port_select(ahci); + ahci_port_clear(ahci, px); + ptr =3D ahci_alloc(ahci, 512); + + /* A WRITE FPDMA QUEUED that fails with the injected I/O error */ + ahci_ncq_expect_abort(ahci, px, WRITE_FPDMA_QUEUED, 0, 0, ptr); + + /* + * Any other command is aborted: a non-NCQ command, an NCQ command, and + * an NCQ read of the NCQ Command Error log itself. + */ + ahci_nodata_cmd(ahci, px, CMD_SET_FEATURES, 0x02, 0, ATA_ERR_ABRT); + ahci_ncq_expect_abort(ahci, px, READ_FPDMA_QUEUED, 0, 0, ptr); + ahci_ncq_expect_abort(ahci, px, RECEIVE_FPDMA_QUEUED, 0x01, 0x10, ptr); + + /* READ LOG DMA EXT of the log reports the failed command ... */ + ahci_io(ahci, px, CMD_READ_LOG_DMA_EXT, buf, 512, 0x10); + g_assert_cmphex(buf[0] & (1 << 7), =3D=3D, 0); /* NQ=3D0 */ + /* ... after discarding the queued commands */ + qtest_memread(ahci->parent->qts, ahci->port[px].fb + 0x58, sdb, + sizeof(sdb)); + g_assert_cmphex(sdb[0], =3D=3D, 0xa1); /* Set Device Bit= s FIS */ + g_assert_cmphex(sdb[1] & 0x40, =3D=3D, 0); /* Interrupt bit = */ + g_assert_cmphex(sdb[2] & 0x01, =3D=3D, 0); /* STATUS: ERR */ + g_assert_cmphex(sdb[3], =3D=3D, 0); /* ERROR */ + g_assert_cmphex((uint32_t)ldl_le_p(sdb + 4), =3D=3D, 0xffffffff); /* A= CT */ + + /* Commands are processed again */ + ahci_io(ahci, px, READ_FPDMA_QUEUED, buf, 512, 0); + ahci_nodata_cmd(ahci, px, CMD_SET_FEATURES, 0x02, 0, 0); + + ahci_free(ahci, ptr); + ahci_shutdown(ahci); +} + +/* + * IDENTIFY DEVICE data log page 04h (Current Settings) is supported, and + * reports whether the Sense Data Reporting feature set is enabled. + */ +static void test_sense_data_current_settings(void) +{ + uint8_t page[512]; + uint64_t settings; + unsigned px; + AHCIQState *ahci =3D ahci_boot_with_sense_data(&px); + + ahci_io(ahci, px, CMD_READ_LOG_DMA_EXT, page, 512, 0x30); + g_assert_cmphex(page[8], =3D=3D, 8); /* number of entr= ies */ + g_assert_cmphex(page[13], =3D=3D, 0x04); /* page 04h liste= d */ + + ahci_io(ahci, px, CMD_READ_LOG_DMA_EXT, page, 512, 0x30 | (0x04 << 8)); + g_assert_cmphex(page[2], =3D=3D, 0x04); /* PAGE NUMBER */ + memcpy(&settings, page + 8, sizeof(settings)); + /* 63=3Dvalid, 10=3DSENSE DATA ENABLED */ + g_assert_cmphex(le64_to_cpu(settings) & (1ULL << 63), =3D=3D, 1ULL << = 63); + g_assert_cmphex(le64_to_cpu(settings) & (1ULL << 10), =3D=3D, 1ULL << = 10); + + ahci_shutdown(ahci); +} + static int prepare_iso(size_t size, unsigned char **buf, char **name) { g_autofree char *cdrom_path =3D NULL; @@ -2808,6 +3033,12 @@ int main(int argc, char **argv) =20 qtest_add_func("/ahci/io/ncq/simple", test_ncq_simple); qtest_add_func("/ahci/io/ncq/read_log", test_ncq_read_log); + qtest_add_func("/ahci/io/ncq/error", test_ncq_cmd_error); + qtest_add_func("/ahci/io/ncq/error_state", test_ncq_error_state); + qtest_add_func("/ahci/io/ncq/sense_data/log", test_sense_data_ncq_log); + qtest_add_func("/ahci/io/ncq/sense_data/cmd", test_sense_data_ncq_cmd); + qtest_add_func("/ahci/io/sense_data/current_settings", + test_sense_data_current_settings); qtest_add_func("/ahci/migrate/ncq/simple", test_migrate_ncq); qtest_add_func("/ahci/io/ncq/retry", test_halted_ncq); qtest_add_func("/ahci/migrate/ncq/halted", test_migrate_halted_ncq); --=20 2.56.1 From nobody Sun Nov 29 10:11:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1795806906; cv=none; d=zohomail.com; s=zohoarc; b=HaYh154zoCb4jZWhHzJEQ/g/6mB31P0huXi2IlRHXhaipZ59QpDd9uYkw5YPpGXmochvA3MpLY52kLfu3XI3HRofygw5TJJuchzoZE9EqPb192KHCzWFAzy5l0NOF/Wy0CHFAKau6U3es86BgFIQdmuWrU39GLIdfsvNN+Or7wY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1795806906; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=71ol14pMDqXmxoUQL+BUY6CQ2OI0HWn3mjoVb/ADuBs=; b=U2tf8I4Vu6E6Q+LP6ETaaVCQjq9tYpuw9laGoKL/4R/x81kB0lL6R0LoRFdlSzaDKco4D3Bvvf7px9ffpmYnRwDHyWd6W8RTCC+0Bt14cqCJAlbRQZrVBStU9kB5AlPhQ+hBqvTVeIP/85M7x1RV/6z5yzucDSboujsoOSn8lYg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1795806906883618.2277021378901; Fri, 27 Nov 2026 11:15:06 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xX1PF-0002oN-AD; Fri, 27 Nov 2026 14:14:50 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xX1Nw-0001t8-Ss; Fri, 27 Nov 2026 14:13:29 -0500 Received: from sea.source.kernel.org ([172.234.252.31]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xX1Nu-0007NY-1T; Fri, 27 Nov 2026 14:13:27 -0500 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id CB35742B9B; Fri, 27 Nov 2026 19:13:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5A4641F00898; Fri, 27 Nov 2026 19:13:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795806804; bh=71ol14pMDqXmxoUQL+BUY6CQ2OI0HWn3mjoVb/ADuBs=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=F3ooy7zVQD0QtR43CPUs1gBtNFGvVKOwR128YLOHSHTJceewtvdyxAffaML/h337O vZpUAH/ZY+akcfTqOidspyFrjknHPqEX5TYsCQZAOPEL27EnAnR+Mfq3IRCKD0km5B sthzHucJdwurqyIVnCBLqGajRdkKsZY1nc3WuxH8mLPaBkAwJtO86Z0BKPFLTbHnlm 2hy2W/blP3u2ceHWXK4b+iRu5NipxuMZgb4rnIxEWYMDvOtN+uoPHm4FEFo0gDyUEC sZxSsKrA1XBAtIh8x/MWfmIcFfsV+QCnU3Y5hB0a/Jdt8jjOS66pRAPnjGVlBmaoPp 4VeLMEY3uUhRA== From: Niklas Cassel To: John Snow , "Denis V. Lunev" , Fabiano Rosas , Laurent Vivier , Paolo Bonzini Cc: Damien Le Moal , Niklas Cassel , qemu-block@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH 10/13] tests/qtest/libqos: skip some checks for commands expected to fail Date: Fri, 27 Nov 2026 20:12:45 +0100 Message-ID: <20261127191250.3298004-11-cassel@kernel.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261127191250.3298004-1-cassel@kernel.org> References: <20261127191250.3298004-1-cassel@kernel.org> 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+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=172.234.252.31; envelope-from=cassel@kernel.org; helo=sea.source.kernel.org X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1795806908042158500 Content-Type: text/plain; charset="utf-8" A command that fails with an error may transfer fewer bytes than requested, or none at all. In this case the device sends no PIO Setup FIS. For example, a READ SECTORS EXT or READ DMA EXT of a sector past the end of the disk is aborted before any data is transferred. Thus PRDBC stays 0, and the PIO read gets no PIO Setup FIS, so ahci_command_verify() fails although the command failed as expected. Skip the PRDBC and PIO Setup FIS checks for commands that are expected to fail. Signed-off-by: Niklas Cassel --- tests/qtest/libqos/ahci.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/qtest/libqos/ahci.c b/tests/qtest/libqos/ahci.c index a4790c2f0c..cd6f75331e 100644 --- a/tests/qtest/libqos/ahci.c +++ b/tests/qtest/libqos/ahci.c @@ -586,8 +586,12 @@ void ahci_port_check_cmd_sanity(AHCIQState *ahci, AHCI= Command *cmd) AHCICommandHeader cmdh; =20 ahci_get_command_header(ahci, cmd->port, cmd->slot, &cmdh); - /* Physical Region Descriptor Byte Count is not required to work for N= CQ. */ - if (!cmd->props->ncq) { + /* + * Physical Region Descriptor Byte Count is not required to work for N= CQ. + * A command that failed with an error may also have transferred fewer + * bytes than requested, so skip the check when an error is expected. + */ + if (!cmd->props->ncq && !cmd->errors) { g_assert_cmphex(cmd->xbytes, =3D=3D, cmdh.prdbc); } } @@ -1347,7 +1351,8 @@ void ahci_command_verify(AHCIQState *ahci, AHCIComman= d *cmd) if (cmd->interrupts & AHCI_PX_IS_DHRS) { ahci_port_check_d2h_sanity(ahci, port, slot); } - if (cmd->props->pio) { + /* A command aborted before any data transfer gets no PIO Setup FIS */ + if (cmd->props->pio && !cmd->errors) { ahci_port_check_pio_sanity(ahci, cmd); } } --=20 2.56.1 From nobody Sun Nov 29 10:11:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1795807006; cv=none; d=zohomail.com; s=zohoarc; b=EQOUQz/OlhmAE0J6zJulRHCGdDAQW9XB6RKzEmRd7JcqnhY+fjV01vrCzcf+0DmTtVqmmi/AvjLU2ku4P6YXaOFrohcuDOC7KFb6gCR6kanX3yge7bt/XjxLRosL01k/xjU8mgxFL9BrBDf0fQ/ay1Fbu3VtZ1Sg9CnrsGZ+kqc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1795807006; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=uH9rO0SpgQ1tyK3SiuL4yZ2fsEwXztY/Qnmg8eVQnvM=; b=aQOlbEFswOGSP1ELIdxvlMFxMKAP767cIOYCSQJ2QtoZjdrrwzH/t/nol2ce2dal176Rtc7H7X1GQqm/JSNb3ZjlECNSK1xAnDb1IxRN1VzbJlyXX7U7f4eTsfjnSUZyk5RPMAq/R66kx408Tvyt6ORewMM+hWvBsKqN3sWCw3M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1795807006197793.6764318934152; Fri, 27 Nov 2026 11:16:46 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xX1Oi-0002SR-9h; Fri, 27 Nov 2026 14:14:17 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xX1Ny-0001up-TA; Fri, 27 Nov 2026 14:13:31 -0500 Received: from tor.source.kernel.org ([172.105.4.254]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xX1Nw-0007Zu-VQ; Fri, 27 Nov 2026 14:13:30 -0500 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 74C1161B64; Fri, 27 Nov 2026 19:13:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3B8C41F0092A; Fri, 27 Nov 2026 19:13:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795806807; bh=uH9rO0SpgQ1tyK3SiuL4yZ2fsEwXztY/Qnmg8eVQnvM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=alUXyH1boswBgtxwkeTdV2DJ2mKx8vh8BrjRKHo8vA4BLXn/3lZ8HIkIvw6MD0xJp CoKjpJHLHq/9fu5pvishiX0T6Evt4sYZni+aEHQyFmBJdPUCsJInDPjdCDuGlFWoUm a5U3bGcEGb3d1griMznZ1qlx8JZMmRzLXBZU8bIRqx7VrIUQLnFyMg2dQvFv4QrMDC v7YFbC93JM8xrhWkgZmwI6Xh2Gnc0BCS5ayhfGUKMwXrmdpxrhjmkjqwva6lngLX69 enApZEcni0aHHu0x7vyXRz47b4MafKcKO7/K1a4p8nqhVv9Eb9TOF/G44eQQpE0Sec 1YOAXqwKaP9Kg== From: Niklas Cassel To: John Snow , "Denis V. Lunev" , Fabiano Rosas , Laurent Vivier , Paolo Bonzini Cc: Damien Le Moal , Niklas Cassel , qemu-block@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH 11/13] hw/ide: report out-of-range accesses as ILLEGAL REQUEST Date: Fri, 27 Nov 2026 20:12:46 +0100 Message-ID: <20261127191250.3298004-12-cassel@kernel.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261127191250.3298004-1-cassel@kernel.org> References: <20261127191250.3298004-1-cassel@kernel.org> 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+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=172.105.4.254; envelope-from=cassel@kernel.org; helo=tor.source.kernel.org X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1795807007075158500 Content-Type: text/plain; charset="utf-8" A non-queued read or write beyond the last logical sector is aborted by ide_sect_range_ok() before any block I/O is done, without sense data. Report sense data ILLEGAL REQUEST / LOGICAL BLOCK ADDRESS OUT OF RANGE for non-NCQ commands trying to do this. Add a qtest for it. Signed-off-by: Niklas Cassel --- hw/ide/core.c | 22 ++++++++++++++-------- tests/qtest/ahci-test.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/hw/ide/core.c b/hw/ide/core.c index cc38a3ef65..a8c8a104b6 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -757,8 +757,9 @@ void ide_set_sector(IDEState *s, int64_t sector_num) } } =20 -static void ide_rw_error(IDEState *s) { - ide_abort_command(s); +static void ide_rw_error(IDEState *s, SCSISense sense) +{ + ide_abort_command_with_sense(s, sense); ide_bus_set_irq(s->bus); } =20 @@ -913,7 +914,7 @@ static void ide_sector_read(IDEState *s) trace_ide_sector_read(sector_num, n); =20 if (!ide_sect_range_ok(s, sector_num, n)) { - ide_rw_error(s); + ide_rw_error(s, SENSE_CODE(LBA_OUT_OF_RANGE)); block_acct_invalid(blk_get_stats(s->blk), BLOCK_ACCT_READ); return; } @@ -945,14 +946,19 @@ void ide_set_inactive(IDEState *s, bool more) ide_cmd_done(s); } =20 -void ide_dma_error(IDEState *s) +static void ide_dma_error_with_sense(IDEState *s, SCSISense sense) { ide_dma_buf_commit(s, 0); - ide_abort_command(s); + ide_abort_command_with_sense(s, sense); ide_set_inactive(s, false); ide_bus_set_irq(s->bus); } =20 +void ide_dma_error(IDEState *s) +{ + ide_dma_error_with_sense(s, SENSE_CODE(NO_SENSE)); +} + int ide_handle_rw_error(IDEState *s, int error, int op) { bool is_read =3D (op & IDE_RETRY_READ) !=3D 0; @@ -968,7 +974,7 @@ int ide_handle_rw_error(IDEState *s, int error, int op) } else if (IS_IDE_RETRY_ATAPI(op)) { ide_atapi_io_error(s, -error); } else { - ide_rw_error(s); + ide_rw_error(s, SENSE_CODE(NO_SENSE)); } } blk_error_action(s->blk, action, is_read, error); @@ -1056,7 +1062,7 @@ static void ide_dma_cb(void *opaque, int ret) =20 if ((s->dma_cmd =3D=3D IDE_DMA_READ || s->dma_cmd =3D=3D IDE_DMA_WRITE= ) && !ide_sect_range_ok(s, sector_num, n)) { - ide_dma_error(s); + ide_dma_error_with_sense(s, SENSE_CODE(LBA_OUT_OF_RANGE)); block_acct_failed(blk_get_stats(s->blk), &s->acct); return; } @@ -1206,7 +1212,7 @@ static void ide_sector_write(IDEState *s) trace_ide_sector_write(sector_num, n); =20 if (!ide_sect_range_ok(s, sector_num, n)) { - ide_rw_error(s); + ide_rw_error(s, SENSE_CODE(LBA_OUT_OF_RANGE)); block_acct_invalid(blk_get_stats(s->blk), BLOCK_ACCT_WRITE); return; } diff --git a/tests/qtest/ahci-test.c b/tests/qtest/ahci-test.c index df9295906c..c95a95540d 100644 --- a/tests/qtest/ahci-test.c +++ b/tests/qtest/ahci-test.c @@ -1231,6 +1231,24 @@ static uint32_t ahci_sense(AHCIQState *ahci, unsigne= d px) return (fis.lba_lo[2] & 0x0f) << 16 | fis.lba_lo[1] << 8 | fis.lba_lo[= 0]; } =20 +/* Issue a 512-byte data-in command at @lba that is expected to be aborted= */ +static void ahci_read_expect_abort(AHCIQState *ahci, unsigned px, uint8_t = op, + uint64_t lba) +{ + uint64_t ptr =3D ahci_alloc(ahci, 512); + AHCICommand *cmd =3D ahci_command_create(op); + + ahci_command_set_buffer(cmd, ptr); + ahci_command_set_size(cmd, 512); + ahci_command_set_offset(cmd, lba); + ahci_command_expect_error(cmd, ATA_ERR_ABRT); + ahci_command_commit(ahci, cmd, px); + ahci_command_issue(ahci, cmd); + ahci_command_verify(ahci, cmd); + ahci_command_free(cmd); + ahci_free(ahci, ptr); +} + /** * Fragmented DMA test: Perform a standard 4K DMA read/write * test, but make sure the physical regions are fragmented to @@ -2909,6 +2927,19 @@ static void test_sense_data_set_features(void) ahci_shutdown(ahci); } =20 +static void test_sense_data_lba_range(void) +{ + const uint64_t lba =3D (uint64_t)test_image_size_mb * 1024 * 1024 / 51= 2; + unsigned px; + AHCIQState *ahci =3D ahci_boot_with_sense_data(&px); + + ahci_read_expect_abort(ahci, px, CMD_READ_PIO_EXT, lba); + g_assert_cmphex(ahci_sense(ahci, px), =3D=3D, 0x052100); + ahci_read_expect_abort(ahci, px, CMD_READ_DMA_EXT, lba); + g_assert_cmphex(ahci_sense(ahci, px), =3D=3D, 0x052100); + ahci_shutdown(ahci); +} + int main(int argc, char **argv) { const char *arch, *base; @@ -3002,6 +3033,7 @@ int main(int argc, char **argv) qtest_add_func("/ahci/io/pio/read_log", test_read_log_pio); qtest_add_func("/ahci/io/sense_data/set_features", test_sense_data_set_features); + qtest_add_func("/ahci/io/sense_data/lba_range", test_sense_data_lba_ra= nge); =20 for (i =3D MODE_BEGIN; i < NUM_MODES; i++) { for (j =3D ADDR_MODE_BEGIN; j < NUM_ADDR_MODES; j++) { --=20 2.56.1 From nobody Sun Nov 29 10:11:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1795806929; cv=none; d=zohomail.com; s=zohoarc; b=Gu0p27MFgp8oq+6rH9Djj3uLHmE1iOzoMCjLIgFBR32KSAJqcEyeVdRBQAx/K7kXCv/3DEIDlnrmdfrMvdMxhAoF1zCOeMAiWj/ovCuURnXtkjw7yA96r4Lo2VlTXAXHuDSoZnBfVP4RPcJ9fy2nktW9eTqiiW5VmZKEk288oLA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1795806929; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=wXRk9ealON7sNtDWqzBA3DTMK8pxgtg5MhZcE1SMGPQ=; b=imd+b2zLfgpx+GbkxCXqND8ZZ/OxcWYN7MnJy01G+4KZVTl1l0xm83ECWtYWcyzSNASYaq1gB4K3nBdxcMbe+ykPndKHQp/snu8TR9W74wWV8YtAPuD34T6erTA8qitLVP9RobhAMONliy7DDFF0/uXvkePXPUJ4G4dklH4BaAk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 179580692984895.1514723069073; Fri, 27 Nov 2026 11:15:29 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xX1Pk-0003rL-Ay; Fri, 27 Nov 2026 14:15:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xX1O2-0001w2-B7; Fri, 27 Nov 2026 14:13:40 -0500 Received: from sea.source.kernel.org ([172.234.252.31]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xX1Nz-0007k4-FV; Fri, 27 Nov 2026 14:13:33 -0500 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 40AE740B0B; Fri, 27 Nov 2026 19:13:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1241B1F00893; Fri, 27 Nov 2026 19:13:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795806810; bh=wXRk9ealON7sNtDWqzBA3DTMK8pxgtg5MhZcE1SMGPQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=GT5IsWtf0xEWwhqFNylA48xHRfC5760EoDQRvN+PWHWsYSblX5N+ohcunukYa02Sv ILu8ycoNc2+0M0RlyJLtIcBdhYWzGN2nk53N3t45YrFgwUMe0IA6tJJg3HBGMnnVUv M7Jc9iKfOK7ErV/U64oiRN9iBRHC5HMAL8ePGLazEYnhUvUFvKF4pwsN7YoXf3BXHq 4TbRbqeBWc+tZtnQmJNDUy28WcfLfW6yB49ZymEz51yH/XHJFReUG48xJJL95atl50 FJQPiQwd0gFJUlgMqbE2Bxioq0jhvLA+bv+5PjWPYepFwyPgLjlOhnV/o50W+XSShe X4lJ2pQoa2iww== From: Niklas Cassel To: John Snow , "Denis V. Lunev" , Fabiano Rosas , Laurent Vivier , Paolo Bonzini Cc: Damien Le Moal , Niklas Cassel , qemu-block@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH 12/13] hw/ide/ahci: check the LBA range of NCQ commands Date: Fri, 27 Nov 2026 20:12:47 +0100 Message-ID: <20261127191250.3298004-13-cassel@kernel.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261127191250.3298004-1-cassel@kernel.org> References: <20261127191250.3298004-1-cassel@kernel.org> 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+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=172.234.252.31; envelope-from=cassel@kernel.org; helo=sea.source.kernel.org X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1795806930503158500 Content-Type: text/plain; charset="utf-8" A NCQ command were not range checked before being accepted. The NCQ command was queued and then failed with EIO by the block layer. Check the range with ide_sect_range_ok() when the command is accepted, and abort it there instead of queuing it (ACS-6 7.24.6). Report sense data LOGICAL BLOCK ADDRESS OUT OF RANGE in the NCQ Command Error log, and account the request as invalid. Add a test. Signed-off-by: Niklas Cassel --- hw/ide/ahci.c | 44 +++++++++++++++++++++++++--------- hw/ide/core.c | 3 +-- hw/ide/ide-internal.h | 3 +++ tests/qtest/ahci-test.c | 52 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 89 insertions(+), 13 deletions(-) diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c index a1fe0cc72d..9f9d2a070d 100644 --- a/hw/ide/ahci.c +++ b/hw/ide/ahci.c @@ -1219,6 +1219,39 @@ static void process_ncq_command(AHCIState *s, int po= rt, const uint8_t *cmd_fis, return; } =20 + ncq_tfs->lba =3D ((uint64_t)ncq_fis->lba5 << 40) | + ((uint64_t)ncq_fis->lba4 << 32) | + ((uint64_t)ncq_fis->lba3 << 24) | + ((uint64_t)ncq_fis->lba2 << 16) | + ((uint64_t)ncq_fis->lba1 << 8) | + (uint64_t)ncq_fis->lba0; + ncq_tfs->sector_count =3D ((ncq_fis->sector_count_high << 8) | + ncq_fis->sector_count_low); + if (!ncq_tfs->sector_count) { + ncq_tfs->sector_count =3D 0x10000; + } + + /* + * A READ or WRITE FPDMA QUEUED beyond the last logical sector is not + * queued: the device aborts it when accepting it (ACS-6 7.24.6, table + * 398), and then waits for the host to read the NCQ Command Error log + * (SATA 3.5a DFPDMAQ12, DFPDMAQ13). Like the non-queued reads and wri= tes + * (see ide_sect_range_ok()), it thus never reaches the block layer, so + * the rerror/werror policy does not apply to it. + */ + if ((ncq_fis->command =3D=3D READ_FPDMA_QUEUED || + ncq_fis->command =3D=3D WRITE_FPDMA_QUEUED) && + !ide_sect_range_ok(&ad->port.ifs[0], ncq_tfs->lba, + ncq_tfs->sector_count)) { + block_acct_invalid(blk_get_stats(ad->port.ifs[0].blk), + ncq_fis->command =3D=3D READ_FPDMA_QUEUED ? + BLOCK_ACCT_READ : BLOCK_ACCT_WRITE); + ide_ncq_cmd_error(&ad->port.ifs[0], tag, ncq_tfs->lba, + ncq_tfs->sector_count, SENSE_CODE(LBA_OUT_OF_RAN= GE)); + ahci_write_fis_d2h(ad, true); + return; + } + /* * A NCQ command clears the bit in PxCI after the command has been QUE= UED * successfully (ERROR not set, BUSY and DRQ cleared). A device reports @@ -1247,12 +1280,6 @@ static void process_ncq_command(AHCIState *s, int po= rt, const uint8_t *cmd_fis, ncq_tfs->cmd =3D ncq_fis->command; /* SUBCOMMAND field is COUNT bits 12:8, i.e. the low 5 bits of "prio" = */ ncq_tfs->subcmd =3D ncq_fis->prio & 0x1f; - ncq_tfs->lba =3D ((uint64_t)ncq_fis->lba5 << 40) | - ((uint64_t)ncq_fis->lba4 << 32) | - ((uint64_t)ncq_fis->lba3 << 24) | - ((uint64_t)ncq_fis->lba2 << 16) | - ((uint64_t)ncq_fis->lba1 << 8) | - (uint64_t)ncq_fis->lba0; =20 /* * Accepting an NCQ command makes the sense data unavailable, unless it @@ -1283,11 +1310,6 @@ static void process_ncq_command(AHCIState *s, int po= rt, const uint8_t *cmd_fis, trace_process_ncq_command_rarc(s, port, tag); } =20 - ncq_tfs->sector_count =3D ((ncq_fis->sector_count_high << 8) | - ncq_fis->sector_count_low); - if (!ncq_tfs->sector_count) { - ncq_tfs->sector_count =3D 0x10000; - } size =3D ncq_tfs->sector_count * BDRV_SECTOR_SIZE; ahci_populate_sglist(ad, &ncq_tfs->sglist, ncq_tfs->cmdh, size, 0); =20 diff --git a/hw/ide/core.c b/hw/ide/core.c index a8c8a104b6..31bb617390 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -429,8 +429,7 @@ static void ide_set_signature(IDEState *s) } } =20 -static bool ide_sect_range_ok(IDEState *s, - uint64_t sector, uint64_t nb_sectors) +bool ide_sect_range_ok(IDEState *s, uint64_t sector, uint64_t nb_sectors) { uint64_t total_sectors; =20 diff --git a/hw/ide/ide-internal.h b/hw/ide/ide-internal.h index b39b5460c3..2de12c8105 100644 --- a/hw/ide/ide-internal.h +++ b/hw/ide/ide-internal.h @@ -465,6 +465,9 @@ int ide_read_log(IDEState *s, uint8_t log_address, uint= 16_t page, void ide_ncq_cmd_error(IDEState *s, uint8_t tag, uint64_t lba, uint16_t count, SCSISense sense); =20 +/* Whether a command may access nb_sectors sectors from sector */ +bool ide_sect_range_ok(IDEState *s, uint64_t sector, uint64_t nb_sectors); + 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, diff --git a/tests/qtest/ahci-test.c b/tests/qtest/ahci-test.c index c95a95540d..06d090cc04 100644 --- a/tests/qtest/ahci-test.c +++ b/tests/qtest/ahci-test.c @@ -2181,6 +2181,57 @@ static void test_sense_data_current_settings(void) ahci_shutdown(ahci); } =20 +/* + * An NCQ command beyond the last logical sector is aborted with ILLEGAL + * REQUEST / LOGICAL BLOCK ADDRESS OUT OF RANGE in the NCQ Command Error l= og, + * without reaching the block layer: even with rerror=3Dstop and werror=3D= stop, it + * is reported to the guest rather than stopping the VM. + */ +static void test_ncq_lba_range(void) +{ + const uint64_t lba =3D mb_to_sectors(test_image_size_mb); /* past the = end */ + const uint8_t cmds[] =3D { READ_FPDMA_QUEUED, WRITE_FPDMA_QUEUED }; + AHCIQState *ahci; + uint8_t log[512]; + uint64_t ptr; + unsigned px; + int i; + + ahci =3D ahci_boot_and_enable("-drive if=3Dnone,id=3Ddrive0,file=3D%s,= format=3D%s," + "rerror=3Dstop,werror=3Dstop " + "-M q35 -device ide-hd,drive=3Ddrive0", + tmp_path, imgfmt); + px =3D ahci_port_select(ahci); + ahci_port_clear(ahci, px); + ptr =3D ahci_alloc(ahci, 512); + g_assert(ptr); + + for (i =3D 0; i < ARRAY_SIZE(cmds); i++) { + AHCICommand *cmd =3D ahci_command_create(cmds[i]); + + ahci_command_set_buffer(cmd, ptr); + ahci_command_set_size(cmd, 512); + ahci_command_set_offset(cmd, lba); + ahci_command_expect_error(cmd, ATA_ERR_ABRT); + ahci_command_commit(ahci, cmd, px); + ahci_command_issue(ahci, cmd); + ahci_command_verify(ahci, cmd); + ahci_command_free(cmd); + + ahci_io(ahci, px, CMD_READ_LOG_DMA_EXT, log, 512, 0x10); + g_assert_cmphex(log[3], =3D=3D, 0x04); /* ERROR: ABRT */ + g_assert_cmphex(log[4] | log[5] << 8 | log[6] << 16 | + (uint64_t)log[8] << 24 | (uint64_t)log[9] << 32 | + (uint64_t)log[10] << 40, =3D=3D, lba); + g_assert_cmphex(log[14], =3D=3D, 0x05); /* ILLEGAL REQUEST= */ + g_assert_cmphex(log[15], =3D=3D, 0x21); /* LBA OUT OF RANG= E */ + g_assert_cmphex(log[16], =3D=3D, 0x00); + } + + ahci_free(ahci, ptr); + ahci_shutdown(ahci); +} + static int prepare_iso(size_t size, unsigned char **buf, char **name) { g_autofree char *cdrom_path =3D NULL; @@ -3071,6 +3122,7 @@ int main(int argc, char **argv) qtest_add_func("/ahci/io/ncq/sense_data/cmd", test_sense_data_ncq_cmd); qtest_add_func("/ahci/io/sense_data/current_settings", test_sense_data_current_settings); + qtest_add_func("/ahci/io/ncq/lba_range", test_ncq_lba_range); qtest_add_func("/ahci/migrate/ncq/simple", test_migrate_ncq); qtest_add_func("/ahci/io/ncq/retry", test_halted_ncq); qtest_add_func("/ahci/migrate/ncq/halted", test_migrate_halted_ncq); --=20 2.56.1 From nobody Sun Nov 29 10:11:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1795806929; cv=none; d=zohomail.com; s=zohoarc; b=HMolBixutsr5RWg2TKw4Vh/LsL11kU5pYIWl+Fu3r0aT1BpsQcx7Y/A13S3Re78HyiRoV7nvS1Z5oXJtJRAA2gXRm/KMR8dMx5GMy8Xj9K0Un+s54AboEsysIk7kWA/ICkfaOS+SjMYtwV2BOgHattr+MMiBNctAcAYoWxs3fhE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1795806929; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=RmIEuSSk+Y3n+MfaYNg9vFBdjEvhvGaZXB+lPSu4Wrw=; b=kmDefkdcp++hFs02BcgCoUY7JsbjNi2lruNtRSwunck0vEZMecTeDiJPytEN44xtOCkWeAyIxdvUk7UbyyZ7ungujFCnmeOos4D0bX5g0vrN44xAHz1bPHRgB5mG89M9m8UjHr8BkM2UB5odbg087g9MQPIqMgPWhBwN/RoFQQk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1795806929862824.7160776209244; Fri, 27 Nov 2026 11:15:29 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xX1Pb-0003Hd-Ol; Fri, 27 Nov 2026 14:15:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xX1O4-0001wV-LD; Fri, 27 Nov 2026 14:13:40 -0500 Received: from tor.source.kernel.org ([172.105.4.254]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xX1O2-0007yN-GW; Fri, 27 Nov 2026 14:13:35 -0500 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 976F661521; Fri, 27 Nov 2026 19:13:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 03E191F00898; Fri, 27 Nov 2026 19:13:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795806812; bh=RmIEuSSk+Y3n+MfaYNg9vFBdjEvhvGaZXB+lPSu4Wrw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=N6ac8AqvALlKNFY6Lkz4JhP3wfUt8GXkXZ2iCVwbcfKHgOhFEUPi4Kgz7jptu7UQZ YlRc8ReadbeCNfcP3wyKiMuuxVCEhYXvDdvUizmYY90/m4XL4pGmgdl4CtAopyLEdI QMh8ybK/I2NvkayxjjorqdNCx65uHCl6AtSPbTWBcAyx/IhCByCkRi/BStVmoFbLO+ mAYsuNEJSxxTZpJGCQRAQqsy93EKZUdk+A7aGwXVcOQEZhpB4x/sryG/qoNt6d/tHy u9s+sh0cNUwFg0YHVE0dwtq+/xtXcGrPGXjvgQVn1uT8OK2rlwbALv1Us6iIPEooS0 DUY5DA9qi1hcA== From: Niklas Cassel To: John Snow , "Denis V. Lunev" , Fabiano Rosas , Laurent Vivier , Paolo Bonzini Cc: Damien Le Moal , Niklas Cassel , qemu-block@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH 13/13] hw/ide: report ACS-6 compliance behind AHCI Date: Fri, 27 Nov 2026 20:12:48 +0100 Message-ID: <20261127191250.3298004-14-cassel@kernel.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261127191250.3298004-1-cassel@kernel.org> References: <20261127191250.3298004-1-cassel@kernel.org> 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+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=172.105.4.254; envelope-from=cassel@kernel.org; helo=tor.source.kernel.org X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1795806930453158501 Content-Type: text/plain; charset="utf-8" Behind AHCI, a disk now implements the General Purpose Logging and Sense Data Reporting feature sets, the NCQ logs and RECEIVE FPDMA QUEUED. Report compliance with ACS-6 in IDENTIFY DEVICE: word 80 sets every major version bit from ATA/ATAPI-4 to ACS-6 (bits 13:4), and word 81 reports the latest ACS-6 minor version, ACS-6 version 11 (0070h). A disk on another controller has none of these, and keeps reporting ATA/ATAPI-4 to ATA/ATAPI-7, with the ATA/ATAPI-5 minor version (0016h). Correct the comment of that major version, which named ATA-3 to ATA/ATAPI-6. Check both in the identify qtests. Signed-off-by: Niklas Cassel --- hw/ide/core.c | 9 +++++++-- tests/qtest/ahci-test.c | 2 ++ tests/qtest/ide-test.c | 2 ++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/hw/ide/core.c b/hw/ide/core.c index 31bb617390..7890780b90 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -208,8 +208,13 @@ static void ide_identify(IDEState *s) put_le16(p + 78, (1 << 7)); } =20 - put_le16(p + 80, 0xf0); /* ata3 -> ata6 supported */ - put_le16(p + 81, 0x16); /* conforms to ata5 */ + if (s->ncq_queues) { + put_le16(p + 80, 0x3ff0); /* ATA/ATAPI-4 -> ACS-6 supported */ + put_le16(p + 81, 0x70); /* conforms to ACS-6 version 11 */ + } else { + put_le16(p + 80, 0xf0); /* ATA/ATAPI-4 -> ATA/ATAPI-7 supported */ + put_le16(p + 81, 0x16); /* conforms to ata5 */ + } /* 14=3DNOP supported, 5=3DWCACHE supported, 0=3DSMART supported */ put_le16(p + 82, (1 << 14) | (1 << 5) | 1); /* 13=3Dflush_cache_ext,12=3Dflush_cache,10=3Dlba48 */ diff --git a/tests/qtest/ahci-test.c b/tests/qtest/ahci-test.c index 06d090cc04..c34c98d5cb 100644 --- a/tests/qtest/ahci-test.c +++ b/tests/qtest/ahci-test.c @@ -851,6 +851,8 @@ static void ahci_test_identify(AHCIQState *ahci) =20 sect_size =3D le16_to_cpu(*((uint16_t *)(&buff[5]))); g_assert_cmphex(sect_size, =3D=3D, AHCI_SECTOR_SIZE); + g_assert_cmphex(le16_to_cpu(buff[80]), =3D=3D, 0x3ff0); + g_assert_cmphex(le16_to_cpu(buff[81]), =3D=3D, 0x70); } =20 static void ahci_test_io_rw_simple(AHCIQState *ahci, unsigned bufsize, diff --git a/tests/qtest/ide-test.c b/tests/qtest/ide-test.c index d82efdfdda..c6438326ea 100644 --- a/tests/qtest/ide-test.c +++ b/tests/qtest/ide-test.c @@ -749,6 +749,8 @@ static void test_identify(void) assert_bit_clear(buf[84], 0x20); assert_bit_clear(buf[86], 0x8000); g_assert_cmphex(buf[119], =3D=3D, 0); + g_assert_cmphex(buf[80], =3D=3D, 0xf0); + g_assert_cmphex(buf[81], =3D=3D, 0x16); =20 ide_test_quit(qts); free_pci_device(dev); --=20 2.56.1