From nobody Fri May 3 22:16:21 2024 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=reject dis=none) header.from=flawful.org ARC-Seal: i=1; a=rsa-sha256; t=1685627221; cv=none; d=zohomail.com; s=zohoarc; b=MOOPrCU+Q8+/R/HMMC0MK2NEYbudG+/I/XXgItCClnrU+HpPj9egkIuBIm3oaeS9VSh/s8SnNOED84q8/SqyLcE+e7+otrZNI+0ck/fG4B4+anrwDY8fO6Hfm+6JKFMoyBvVrxDSgkYsafLNDflqk7a8ABxNQk7MmQpWKa0o3zU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685627221; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=laqE+jDbGMxNloibp38IdoI5cMDWlF6ShBRxAGY56M8=; b=GIvIS1AAtfS+fSCOhYurEvA+K5uksMHq9hYWRUv60d0qyDDs0WOnmh5iQAye1agEY5zVQHS7c+BkPh+fq3vCHvEg8zDVtaFZ7M1LsgEIHNK6BFpHq/rEZRMMgxOdK2SYrCRea/b2lZjE0mCdbVhxnzP18csZAZ/VcdCMcjl6ddQ= 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=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1685627221536684.9856346341444; Thu, 1 Jun 2023 06:47:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q4icf-00085m-9y; Thu, 01 Jun 2023 09:45:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q4icZ-0007uW-Ke; Thu, 01 Jun 2023 09:45:46 -0400 Received: from mail-lj1-x235.google.com ([2a00:1450:4864:20::235]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q4icX-000896-If; Thu, 01 Jun 2023 09:45:43 -0400 Received: by mail-lj1-x235.google.com with SMTP id 38308e7fff4ca-2b1a3fa2cd2so7952381fa.1; Thu, 01 Jun 2023 06:45:40 -0700 (PDT) Received: from flawful.org (c-fcf6e255.011-101-6d6c6d3.bbcust.telenor.se. [85.226.246.252]) by smtp.gmail.com with ESMTPSA id o11-20020a2e730b000000b002a8c409f1f5sm3772670ljc.110.2023.06.01.06.45.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Jun 2023 06:45:39 -0700 (PDT) Received: by flawful.org (Postfix, from userid 112) id 4134F7A7; Thu, 1 Jun 2023 15:45:34 +0200 (CEST) Received: from x1-carbon.lan (unknown [129.253.182.62]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by flawful.org (Postfix) with ESMTPSA id 32E4A4C9; Thu, 1 Jun 2023 15:45:08 +0200 (CEST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685627139; x=1688219139; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature:dkim-signature :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=laqE+jDbGMxNloibp38IdoI5cMDWlF6ShBRxAGY56M8=; b=lt3cIbG8uWdGBKQTvqaB0Dv2XfYipjQai1dLtFujS8ZnzU89UGzGvOMNAat7E///sE QAMkgKQEmudYh3L4VvyWjEVK6cMP9ccl8fXqjQ3K6gAUIqOPWorfQvFk1pl1M32Of5w8 rnquLzoTDsWmHqnBe3fW9RG+Td5Sxp14Tm48gKuUeNJq1J6ieWumcqv1f4IqFDt/BoR6 3ufXWsgXQ8qLhbFMGgNQua+US2l6fMq5qThfx/+dsCH5nyTnm9eBEIYpazaCjilH/efY s3g8RnuQFCPAcgHsfbzv0q8lMXGa8+qbYJ3PvIcwiHCyAoM8Sr6fahzuuXJAb5D9XUJP i57w== X-Gm-Message-State: AC+VfDyv/IX4uXueDqxA+dOO8Zon99jBqi3Kd9idbDhMb1jUw/VkSoei H3aVZlF6abU91cQp9bCRwp5lfVeovG9WUmt6 X-Google-Smtp-Source: ACHHUZ6XElCyJNIqClx1J0XDu4W665uCGGOi1Eg5/RHroRKWHtInHuI10UzIreyz2SxD6HE7IwN1nA== X-Received: by 2002:a2e:9591:0:b0:2af:21d3:a4ca with SMTP id w17-20020a2e9591000000b002af21d3a4camr4871263ljh.47.1685627139235; Thu, 01 Jun 2023 06:45:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=flawful.org; s=mail; t=1685627136; bh=+7Lfn6Z7q7WKc/uSkZhwLaBrCOUaYvjqYUoBgBJpe9g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RbQk2vsVquc08z9v2k8sQg/fhwAApKnkh7D+tOWm74x0sQszgXzrsX1Kq46rOcq09 l0p6BpJ9EDguJIWwjcgHeyTGZx6Lnaw1rS1yU0Q+fS7bIaKzYPlMDA1j6PJgcZrCCK Wh/e59A2fnxVi/IhgePSqfhIppB0CIGf6qJyGEoQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=flawful.org; s=mail; t=1685627116; bh=+7Lfn6Z7q7WKc/uSkZhwLaBrCOUaYvjqYUoBgBJpe9g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZeO5/z/Z+ivdiJ1L3CXM94hHJA+1ipMLowSLEnM49McpDUUIqmyffMmzfBwwde7SV plRAz/vVBg8PbWNxKqXfXQScTa/QWQUTq8lwZTubEWFcBFlrslLSDWaZbPD2WBtkWT pidddvjgvvLSstzW15muHc1jvzkyvs6LOMQx06VQ= From: Niklas Cassel To: John Snow Cc: qemu-block@nongnu.org, qemu-devel@nongnu.org, Damien Le Moal , Niklas Cassel , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v2 1/8] hw/ide/ahci: remove stray backslash Date: Thu, 1 Jun 2023 15:44:27 +0200 Message-Id: <20230601134434.519805-2-nks@flawful.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230601134434.519805-1-nks@flawful.org> References: <20230601134434.519805-1-nks@flawful.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::235; envelope-from=nks.gnu@gmail.com; helo=mail-lj1-x235.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.248, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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 @flawful.org) (identity @flawful.org) X-ZM-MESSAGEID: 1685627222226100001 From: Niklas Cassel This backslash obviously does not belong here, so remove it. Signed-off-by: Niklas Cassel Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: John Snow --- hw/ide/ahci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c index 4e76d6b191..48d550f633 100644 --- a/hw/ide/ahci.c +++ b/hw/ide/ahci.c @@ -690,7 +690,7 @@ static void ahci_reset_port(AHCIState *s, int port) =20 s->dev[port].port_state =3D STATE_RUN; if (ide_state->drive_kind =3D=3D IDE_CD) { - ahci_set_signature(d, SATA_SIGNATURE_CDROM);\ + ahci_set_signature(d, SATA_SIGNATURE_CDROM); ide_state->status =3D SEEK_STAT | WRERR_STAT | READY_STAT; } else { ahci_set_signature(d, SATA_SIGNATURE_DISK); --=20 2.40.1 From nobody Fri May 3 22:16:21 2024 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=reject dis=none) header.from=flawful.org ARC-Seal: i=1; a=rsa-sha256; t=1685627223; cv=none; d=zohomail.com; s=zohoarc; b=Tx2rLi+NZlTifvn4hOxqEo9S1dpCyjb7fObXtgEj9Y5ASOlkqvOqCdM7be9GQGK0TLzaYfAUoVxZZXQ8UcNsNHCEHjAP1nxauAIcOS3eRjM7lFEJu8AKnKJ4s9Kkgs45AeIp/UmkMd2r9vyH4UgH1sjPrEYHypa8jDJVRUQM+6M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685627223; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=cy91cBRqAqiwy9cOS34w2pZldiLcmYPrCZe3pVyd0X4=; b=glU/Y+X1U3jyZ9YmZD8S6ePGaZiTwrqxeCdewNIBln0CqAqjBgF77fhcqcKpZIh0bTnFsVALn1z97dFEayQMrKSo44VmMZc2ADYNuYBjSCLVIBrqj+7Q3HD87sf2vz2Ra7KQsZ2coZbJ4Qh7ZpRE5F6YVRLaY3iJdviaXdGWnF8= 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=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1685627223784617.0447448524453; Thu, 1 Jun 2023 06:47:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q4ici-0008B8-Vf; Thu, 01 Jun 2023 09:45:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q4icf-00086S-Qh; Thu, 01 Jun 2023 09:45:50 -0400 Received: from mail-lf1-x12b.google.com ([2a00:1450:4864:20::12b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q4icd-00089l-Rp; Thu, 01 Jun 2023 09:45:49 -0400 Received: by mail-lf1-x12b.google.com with SMTP id 2adb3069b0e04-4f4db9987f8so2710772e87.1; Thu, 01 Jun 2023 06:45:46 -0700 (PDT) Received: from flawful.org (c-fcf6e255.011-101-6d6c6d3.bbcust.telenor.se. [85.226.246.252]) by smtp.gmail.com with ESMTPSA id v25-20020a197419000000b004f019d3eab4sm1098438lfe.23.2023.06.01.06.45.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Jun 2023 06:45:45 -0700 (PDT) Received: by flawful.org (Postfix, from userid 112) id 7F8D79AF; Thu, 1 Jun 2023 15:45:44 +0200 (CEST) Received: from x1-carbon.lan (unknown [129.253.182.62]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by flawful.org (Postfix) with ESMTPSA id 890776B1; Thu, 1 Jun 2023 15:45:20 +0200 (CEST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685627146; x=1688219146; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature:dkim-signature :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=cy91cBRqAqiwy9cOS34w2pZldiLcmYPrCZe3pVyd0X4=; b=UTge0G6gMBxeN3HRjzrCo5OyanpXxNF5KutLOrat+PS3KCMfy19i+a4E9drzYHV8Tx o8YDeLKhccLFAqwigKOeZDEqDDdqpjpdToA/he0oHSdYT7k6adLH7qK6eyxcatCpx0sy Q6UqXAeJZHGpC/P80cy3VD6ZduCx4hMXjAHreFTg/rhmbGMvpqWVk6KTSaMDpRC0swwE 7/tqQ51yiT0i3PqFujtCSzqk73lln1IEJt1LYVVN1CC9hxlIcvRvAlTJRXtcxWGfX9Yn OC5u1ujs906y85EuFoW8EiRi4CjnD5JlYU23Qn6Gf8DNhDPDvLo6ZGrzqaaZ9sdVcAAO KlRA== X-Gm-Message-State: AC+VfDwJcPBucRCDCibcX+Ol9FsLzt66lWywRNacg3nL91W52XRQM4dQ AXadsdz07oL0ZegL71kN0vExLvwbwj31B5bw X-Google-Smtp-Source: ACHHUZ54jJTPW/7vcHJEiiziFFE4xHgUEcSDtHoNaA+07y5AoD6H+ajva6eQPeNsfjTps1Ya0MLBcQ== X-Received: by 2002:a05:6512:128f:b0:4f3:7889:7603 with SMTP id u15-20020a056512128f00b004f378897603mr732954lfs.24.1685627145611; Thu, 01 Jun 2023 06:45:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=flawful.org; s=mail; t=1685627144; bh=DZ5fMdq9LwskNjWpW+fDBE+ZAvAUizJvqdAFmYrDvXM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QfNwrfKuk034MQfXnNgYBZU72/R/IVJKYF67nHmOVHmFbWuX8V1RbDTMGUg29M9sD 4PtR2tl0zHFeosuFPij5XtwlCJcMtjU5j3RJJ0oNZDWXypJb1z6mbxK3Nl+4u6+FJA 0shgnkreuOGADGy02OMLazHuqR8gMipa8Ld39wdU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=flawful.org; s=mail; t=1685627123; bh=DZ5fMdq9LwskNjWpW+fDBE+ZAvAUizJvqdAFmYrDvXM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=glzonshqe6WAvLqfb2JnDxAJsHCzpEtSZ7iEw4P2n1V89DXvpg0QZmCkIzbSYQjrm ozc34vwH3ctLrPm4L/sdNEPdAkeLgjmYYyjp6jfGkQ0zMxGuzk7/PPxir7EM2qcKUd EcUOEHD0UFn5oDoM+D1Wf5lG1PfO5IPkl1kLgLvg= From: Niklas Cassel To: John Snow Cc: qemu-block@nongnu.org, qemu-devel@nongnu.org, Damien Le Moal , Niklas Cassel Subject: [PATCH v2 2/8] hw/ide/core: set ERR_STAT in unsupported command completion Date: Thu, 1 Jun 2023 15:44:28 +0200 Message-Id: <20230601134434.519805-3-nks@flawful.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230601134434.519805-1-nks@flawful.org> References: <20230601134434.519805-1-nks@flawful.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=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::12b; envelope-from=nks.gnu@gmail.com; helo=mail-lf1-x12b.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.248, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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 @flawful.org) (identity @flawful.org) X-ZM-MESSAGEID: 1685627224121100005 Content-Type: text/plain; charset="utf-8" From: Niklas Cassel Currently, the first time sending an unsupported command (e.g. READ LOG DMA EXT) will not have ERR_STAT set in the completion. Sending the unsupported command again, will correctly have ERR_STAT set. When ide_cmd_permitted() returns false, it calls ide_abort_command(). ide_abort_command() first calls ide_transfer_stop(), which will call ide_transfer_halt() and ide_cmd_done(), after that ide_abort_command() sets ERR_STAT in status. ide_cmd_done() for AHCI will call ahci_write_fis_d2h() which writes the current status in the FIS, and raises an IRQ. (The status here will not have ERR_STAT set!). Thus, we cannot call ide_transfer_stop() before setting ERR_STAT, as ide_transfer_stop() will result in the FIS being written and an IRQ being raised. The reason why it works the second time, is that ERR_STAT will still be set from the previous command, so when writing the FIS, the completion will correctly have ERR_STAT set. Set ERR_STAT before writing the FIS (calling cmd_done), so that we will raise an error IRQ correctly when receiving an unsupported command. Signed-off-by: Niklas Cassel --- hw/ide/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/ide/core.c b/hw/ide/core.c index de48ff9f86..07971c0218 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -533,9 +533,9 @@ BlockAIOCB *ide_issue_trim( =20 void ide_abort_command(IDEState *s) { - ide_transfer_stop(s); s->status =3D READY_STAT | ERR_STAT; s->error =3D ABRT_ERR; + ide_transfer_stop(s); } =20 static void ide_set_retry(IDEState *s) --=20 2.40.1 From nobody Fri May 3 22:16:21 2024 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=reject dis=none) header.from=flawful.org ARC-Seal: i=1; a=rsa-sha256; t=1685627224; cv=none; d=zohomail.com; s=zohoarc; b=CY+BrylhF/CsoJCgj5W8msQCg71tJxfOivEtdMZbJdbUYt8g3j1E6bWDWV9RLmQpu6E1j7DoVyx+150oZu89QlhuWbRNJq4dLJlvFcb2Iv3BCl/sysP6S5GPO0VRqNYfgmGuN37JMoxqpcHNcCWol2VPoEQtLP2f366YjL0BiCk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685627224; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=stzNPKEEsb93NVPera4GoUbdc/j/tKWSRzl0WF+RC+A=; b=UhNJU2eEwpRXJ7PzMuk6phO/3n/rpPgnBAm0QO4kz4X6Rut77O4XK24c5kwryUnyNzrq1QOJtQbSzxUEWy5Y+0aM9vqXRnPbIQCGCTQlbKQ3z4lk2pxM6SehLcftNwrGaAkFNQLV37IRu9lmYOsYcsH0YPf+3JsQrBkLHdQoBmo= 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=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1685627224552764.5324068447721; Thu, 1 Jun 2023 06:47:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q4id8-0000CH-Jg; Thu, 01 Jun 2023 09:46:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q4icp-0008W0-VQ; Thu, 01 Jun 2023 09:46:00 -0400 Received: from mail-lf1-x131.google.com ([2a00:1450:4864:20::131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q4ico-0008Fy-6S; Thu, 01 Jun 2023 09:45:59 -0400 Received: by mail-lf1-x131.google.com with SMTP id 2adb3069b0e04-4f4e71a09a7so1191129e87.1; Thu, 01 Jun 2023 06:45:57 -0700 (PDT) Received: from flawful.org (c-fcf6e255.011-101-6d6c6d3.bbcust.telenor.se. [85.226.246.252]) by smtp.gmail.com with ESMTPSA id q24-20020a19a418000000b004f388c5f25dsm1089869lfc.257.2023.06.01.06.45.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Jun 2023 06:45:55 -0700 (PDT) Received: by flawful.org (Postfix, from userid 112) id AA09550A; Thu, 1 Jun 2023 15:45:54 +0200 (CEST) Received: from x1-carbon.lan (unknown [129.253.182.62]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by flawful.org (Postfix) with ESMTPSA id 3743A18B; Thu, 1 Jun 2023 15:45:24 +0200 (CEST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685627156; x=1688219156; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature:dkim-signature :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=stzNPKEEsb93NVPera4GoUbdc/j/tKWSRzl0WF+RC+A=; b=i7Wo51JZYFabcx0SsYO77405OI/bQ0OjiFSXsmKujfsqtmNJxAUw6hqcqvW3V8ghM5 45z8chTK8a5ghzPXFLaK5o/ZgmkEEmpea8P1OUjCK2047m7K3LvD1YQUoMb38Q54xEP4 qce1N+fMYOWS2UOoXRKMcjEi3gwwWlzFg8kNzu3jWAaVBb/Zt1mqO2lkHmIP2dnO7sbH 40WbEA+Dx1uDZF+G3NuIwV1ObrCLXwWKJ/OAmD7MEwBIFoFAKrfTCX2BMcZ4w7lLUhsJ FHEaf9PacpDOo6tqZdWGD4b7azJZc4UF72xNI30J4aLlXOW3MeThGBQ9FP+3lviQdv3T Ej/w== X-Gm-Message-State: AC+VfDxxCCN5wTjlkD6k/O1PNCk/DdlcCWxhVl4zB5wITVUitggcRkXU Yswf4UnFACv3OPxPi6hPq4UcusxnDgAgQrb0 X-Google-Smtp-Source: ACHHUZ6x/DoFfqzZgRyN0Bg9Wz6BmWELEci+CgUlzS6sYUPVr8GgNaJEAtBxciQmGu/ylcpJLCsDZw== X-Received: by 2002:ac2:4c35:0:b0:4f4:b38c:1f87 with SMTP id u21-20020ac24c35000000b004f4b38c1f87mr610556lfq.12.1685627155767; Thu, 01 Jun 2023 06:45:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=flawful.org; s=mail; t=1685627154; bh=Q3Hm6FMI2aGPQjjUBTN4kaiW9jrcrf+oWe6LEXPzIxY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=omiLWQKK3Kmdm283EFQTYENys7gXUQZaSMIdJ/ZMTvWBSkNJnAPp2oO3d5/VPC00s rHUNh1tnZb4bynnHp9bwQQqenXI8bZdb/XwgNc1U5NZ0z/UvOAQVJCxuHSCO5AJCe3 6C6zl6vyDuG5raNidMU2aOSXSdAjnd7cYCg2FEFA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=flawful.org; s=mail; t=1685627128; bh=Q3Hm6FMI2aGPQjjUBTN4kaiW9jrcrf+oWe6LEXPzIxY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UblLAnNZLBn4xhY9IkVZwuPUHNuCUhZP5mWL4ifl9IKCn1lwtvkCrNbNQbSGNs5/W Z8N+S7Pw+cfcWzjicTK4DFg4NsKt3Nb+feLQvNTlY67Jv4czkiyoGnOZ28zaBmXFkC 3OxsqeHF5qvY3K6zUn9CN+x7ovq/5GWXPnLjhNfg= From: Niklas Cassel To: John Snow Cc: qemu-block@nongnu.org, qemu-devel@nongnu.org, Damien Le Moal , Niklas Cassel Subject: [PATCH v2 3/8] hw/ide/ahci: write D2H FIS on when processing NCQ command Date: Thu, 1 Jun 2023 15:44:29 +0200 Message-Id: <20230601134434.519805-4-nks@flawful.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230601134434.519805-1-nks@flawful.org> References: <20230601134434.519805-1-nks@flawful.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=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::131; envelope-from=nks.gnu@gmail.com; helo=mail-lf1-x131.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.248, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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 @flawful.org) (identity @flawful.org) X-ZM-MESSAGEID: 1685627226358100011 Content-Type: text/plain; charset="utf-8" From: Niklas Cassel The way that BUSY + PxCI is cleared for NCQ (FPDMA QUEUED) commands is described in SATA 3.5a Gold: 11.15 FPDMA QUEUED command protocol DFPDMAQ2: ClearInterfaceBsy "Transmit Register Device to Host FIS with the BSY bit cleared to zero and the DRQ bit cleared to zero and Interrupt bit cleared to zero to mark interface ready for the next command." PxCI is currently cleared by handle_cmd(), but we don't write the D2H FIS to the FIS Receive Area that actually caused PxCI to be cleared. Similar to how ahci_pio_transfer() calls ahci_write_fis_pio() with an additional parameter to write a PIO Setup FIS without raising an IRQ, add a parameter to ahci_write_fis_d2h() so that ahci_write_fis_d2h() also can write the FIS to the FIS Receive Area without raising an IRQ. Change process_ncq_command() to call ahci_write_fis_d2h() without raising an IRQ (similar to ahci_pio_transfer()), such that the FIS Receive Area is in sync with the PxTFD shadow register. E.g. Linux reads status and error fields from the FIS Receive Area directly, so it is wise to keep the FIS Receive Area and the PxTFD shadow register in sync. Signed-off-by: Niklas Cassel --- hw/ide/ahci.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c index 48d550f633..4b272397fd 100644 --- a/hw/ide/ahci.c +++ b/hw/ide/ahci.c @@ -43,7 +43,7 @@ static void check_cmd(AHCIState *s, int port); static int handle_cmd(AHCIState *s, int port, uint8_t slot); static void ahci_reset_port(AHCIState *s, int port); -static bool ahci_write_fis_d2h(AHCIDevice *ad); +static bool ahci_write_fis_d2h(AHCIDevice *ad, bool d2h_fis_i); static void ahci_init_d2h(AHCIDevice *ad); static int ahci_dma_prepare_buf(const IDEDMA *dma, int32_t limit); static bool ahci_map_clb_address(AHCIDevice *ad); @@ -618,7 +618,7 @@ static void ahci_init_d2h(AHCIDevice *ad) return; } =20 - if (ahci_write_fis_d2h(ad)) { + if (ahci_write_fis_d2h(ad, true)) { ad->init_d2h_sent =3D true; /* We're emulating receiving the first Reg H2D Fis from the device; * Update the SIG register, but otherwise proceed as normal. */ @@ -850,7 +850,7 @@ static void ahci_write_fis_pio(AHCIDevice *ad, uint16_t= len, bool pio_fis_i) } } =20 -static bool ahci_write_fis_d2h(AHCIDevice *ad) +static bool ahci_write_fis_d2h(AHCIDevice *ad, bool d2h_fis_i) { AHCIPortRegs *pr =3D &ad->port_regs; uint8_t *d2h_fis; @@ -864,7 +864,7 @@ static bool ahci_write_fis_d2h(AHCIDevice *ad) d2h_fis =3D &ad->res_fis[RES_FIS_RFIS]; =20 d2h_fis[0] =3D SATA_FIS_TYPE_REGISTER_D2H; - d2h_fis[1] =3D (1 << 6); /* interrupt bit */ + d2h_fis[1] =3D d2h_fis_i ? (1 << 6) : 0; /* interrupt bit */ d2h_fis[2] =3D s->status; d2h_fis[3] =3D s->error; =20 @@ -890,7 +890,10 @@ static bool ahci_write_fis_d2h(AHCIDevice *ad) ahci_trigger_irq(ad->hba, ad, AHCI_PORT_IRQ_BIT_TFES); } =20 - ahci_trigger_irq(ad->hba, ad, AHCI_PORT_IRQ_BIT_DHRS); + if (d2h_fis_i) { + ahci_trigger_irq(ad->hba, ad, AHCI_PORT_IRQ_BIT_DHRS); + } + return true; } =20 @@ -1120,6 +1123,8 @@ static void process_ncq_command(AHCIState *s, int por= t, const uint8_t *cmd_fis, return; } =20 + ahci_write_fis_d2h(ad, false); + ncq_tfs->used =3D 1; ncq_tfs->drive =3D ad; ncq_tfs->slot =3D slot; @@ -1506,7 +1511,7 @@ static void ahci_cmd_done(const IDEDMA *dma) } =20 /* update d2h status */ - ahci_write_fis_d2h(ad); + ahci_write_fis_d2h(ad, true); =20 if (ad->port_regs.cmd_issue && !ad->check_bh) { ad->check_bh =3D qemu_bh_new_guarded(ahci_check_cmd_bh, ad, --=20 2.40.1 From nobody Fri May 3 22:16:21 2024 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=reject dis=none) header.from=flawful.org ARC-Seal: i=1; a=rsa-sha256; t=1685627271; cv=none; d=zohomail.com; s=zohoarc; b=g++6JyoyfcrzJVZ2GBWgvQynPehldOPJ3IiRml1KhDUYVmwiipXAls5r5h4CZldDBR+qsinIepWZhXt3lpJgDGAGAa972kNC4KsyhpiZH3lB98kDcZ76aZ8+qurqSkSLWDQ1p2vZmlcKCyCLMmLNaDZH6yWri0zXlLk2sFsXIGM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685627271; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=/ev5aaWOMtzj7uhrV2SRo+Ugfi/ZJw07xZsuBD2beIE=; b=D8e5RcsdImiW0OlCHcVHAYIEZ7zAYVZAtWJI2EDPBsm7Pz6kCwIwYScFdIAT6mQKug/tc/XXwMS//M0Z8yHH1fyV+8BMgZjsTIwgNbuLtiHGmB81QU++fsgn6Bu9dHRBQ3NidnOLqIJm9R9dq8hU9HFbFG+/brwE2T3D0pM1wUY= 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=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1685627271377815.44331717243; Thu, 1 Jun 2023 06:47:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q4ieS-0001Xo-Ot; Thu, 01 Jun 2023 09:47:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q4idT-0000bK-2J; Thu, 01 Jun 2023 09:46:46 -0400 Received: from mail-lj1-x229.google.com ([2a00:1450:4864:20::229]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q4idR-0008OO-1r; Thu, 01 Jun 2023 09:46:38 -0400 Received: by mail-lj1-x229.google.com with SMTP id 38308e7fff4ca-2afb2874e83so12356071fa.0; Thu, 01 Jun 2023 06:46:36 -0700 (PDT) Received: from flawful.org (c-fcf6e255.011-101-6d6c6d3.bbcust.telenor.se. [85.226.246.252]) by smtp.gmail.com with ESMTPSA id l20-20020a2e7014000000b002ab5421959fsm3799701ljc.90.2023.06.01.06.46.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Jun 2023 06:46:34 -0700 (PDT) Received: by flawful.org (Postfix, from userid 112) id 26AD44E8; Thu, 1 Jun 2023 15:46:26 +0200 (CEST) Received: from x1-carbon.lan (unknown [129.253.182.62]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by flawful.org (Postfix) with ESMTPSA id D8A9B4D7; Thu, 1 Jun 2023 15:45:31 +0200 (CEST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685627195; x=1688219195; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature:dkim-signature :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=/ev5aaWOMtzj7uhrV2SRo+Ugfi/ZJw07xZsuBD2beIE=; b=eVXz+l6Rs3/Xs7gwK5DrU9BYu7MxTW0ga0AwKe5UcwW1pOtbPLNpBcIUHEnlctAzpn L/9kK6tNFdD2wz9BxglgbtzQkSEvTGsB0o12nv3Bgbpj8h7kpGVhnnsFUYZXv4/GgOuV Uekb1ObppRz1b6vo2kQHtOLmc5dwQqD+YizKjd1lTlDAv6Ik51xhQRnFzYH91RWUu7YQ S0QrVzN0UQB91W447d1MeuoBXHaswbpnXMNsACZ1fnItaCNCqL67rOKxsaOf+HJVOXlM 8hzrTX7SHSfQvOmMMaMkOCU/oaN84vr9y91mgmrbi7/mZtXtWCIC1hwvBY2p6KZleLGl zegw== X-Gm-Message-State: AC+VfDzgW1Q0Le52eMYmpnsuhr4jzWVtOYlJR8YdBSLT5oj6JQD4EyT1 pw6CNAsUeNfPH2jwTTdVJFOe3sN2OtPm04s7 X-Google-Smtp-Source: ACHHUZ47S+I6WerkFdBKU9/WJFZdiO7yYLCEK3gqfbeMSsjF6nXSLCu8dqo1cqQ/pfPbJOwBZJRdYQ== X-Received: by 2002:a2e:99cb:0:b0:2af:e006:b83 with SMTP id l11-20020a2e99cb000000b002afe0060b83mr5099367ljj.18.1685627194664; Thu, 01 Jun 2023 06:46:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=flawful.org; s=mail; t=1685627186; bh=+crhlsOe8XqLHrztrhhxdpb8tqjExwekFotXDvFGgAE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BLZZ/qCT+v6SZYzPE7NjpqgbV2sYKdDsCalo7m+TLS0aeeyzL/5qckd3hNr70I/Ab 8BwMl4Pw3+OltH5LLSI8TwFTSO5CExvzgdFavASflrg3k+ehHeV21frvupWQSZkgrx wI32jiItpCtVOQ0/OWZgZqfmz9kyeGrWLRwFRouA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=flawful.org; s=mail; t=1685627135; bh=+crhlsOe8XqLHrztrhhxdpb8tqjExwekFotXDvFGgAE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=e0YJ86U1b0fK2JsaKm2cOleAeYENO9LmdqZvXuZ6dc5HNNl1U1dGTcla7Ils1kgx4 yaIWailYBPCsjKWPfHorGnOI/O4cnR/fWSu9N1G/0/57/Si4zJXaz4wvVDuQbzgrfl YE5EKsXdmEA3rgsYLWfKgTMK9YxeDYFNhx7fUoCs= From: Niklas Cassel To: John Snow Cc: qemu-block@nongnu.org, qemu-devel@nongnu.org, Damien Le Moal , Niklas Cassel Subject: [PATCH v2 4/8] hw/ide/ahci: simplify and document PxCI handling Date: Thu, 1 Jun 2023 15:44:30 +0200 Message-Id: <20230601134434.519805-5-nks@flawful.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230601134434.519805-1-nks@flawful.org> References: <20230601134434.519805-1-nks@flawful.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=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::229; envelope-from=nks.gnu@gmail.com; helo=mail-lj1-x229.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.248, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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 @flawful.org) (identity @flawful.org) X-ZM-MESSAGEID: 1685627272523100004 Content-Type: text/plain; charset="utf-8" From: Niklas Cassel The AHCI spec states that: For NCQ, PxCI is cleared on command queued successfully. For non-NCQ, PxCI is cleared on command completed successfully. (A non-NCQ command that completes with error does not clear PxCI.) The current QEMU implementation either clears PxCI in check_cmd(), or in ahci_cmd_done(). check_cmd() will clear PxCI for a command if handle_cmd() returns 0. handle_cmd() will return -1 if BUSY or DRQ is set. The QEMU implementation for NCQ commands will currently not set BUSY or DRQ, so they will always have PxCI cleared by handle_cmd(). ahci_cmd_done() will never even get called for NCQ commands. Non-NCQ commands are executed by ide_bus_exec_cmd(). Non-NCQ commands in QEMU are implemented either in a sync or in an async way. For non-NCQ commands implemented in a sync way, the command handler will return true, and when ide_bus_exec_cmd() sees that a command handler returns true, it will call ide_cmd_done() (which will call ahci_cmd_done()). For a command implemented in a sync way, ahci_cmd_done() will do nothing (since busy_slot is not set). Instead, after ide_bus_exec_cmd() has finished, check_cmd() will clear PxCI for these commands. For non-NCQ commands implemented in an async way (using either aiocb or pio_aiocb), the command handler will return false, ide_bus_exec_cmd() will not call ide_cmd_done(), instead it is expected that the async callback function will call ide_cmd_done() once the async command is done. handle_cmd() will set busy_slot, if and only if BUSY or DRQ is set, and this is checked _after_ ide_bus_exec_cmd() has returned. handle_cmd() will return -1, so check_cmd() will not clear PxCI. When the async callback calls ide_cmd_done() (which will call ahci_cmd_done()), it will see that busy_slot is set, and ahci_cmd_done() will clear PxCI. This seems racy, since busy_slot is set _after_ ide_bus_exec_cmd() has returned. The callback might come before busy_slot gets set. And it is quite confusing that ahci_cmd_done() will be called for all non-NCQ commands when the command is done, but will only clear PxCI in certain cases, even though it will always write a D2H FIS and raise an IRQ. Even worse, in the case where ahci_cmd_done() does not clear PxCI, it still raises an IRQ. Host software might thus read an old PxCI value, since PxCI is cleared (by check_cmd()) after the IRQ has been raised. Try to simplify this by always setting busy_slot for non-NCQ commands, such that ahci_cmd_done() will always be responsible for clearing PxCI for non-NCQ commands. For NCQ commands, clear PxCI when we receive the D2H FIS, but before raising the IRQ, see AHCI 1.3.1, section 5.3.8, states RegFIS:Entry and RegFIS:ClearCI. Signed-off-by: Niklas Cassel --- hw/ide/ahci.c | 70 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 50 insertions(+), 20 deletions(-) diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c index 4b272397fd..3deaf01add 100644 --- a/hw/ide/ahci.c +++ b/hw/ide/ahci.c @@ -41,9 +41,10 @@ #include "trace.h" =20 static void check_cmd(AHCIState *s, int port); -static int handle_cmd(AHCIState *s, int port, uint8_t slot); +static void handle_cmd(AHCIState *s, int port, uint8_t slot); static void ahci_reset_port(AHCIState *s, int port); static bool ahci_write_fis_d2h(AHCIDevice *ad, bool d2h_fis_i); +static void ahci_clear_cmd_issue(AHCIDevice *ad, uint8_t slot); static void ahci_init_d2h(AHCIDevice *ad); static int ahci_dma_prepare_buf(const IDEDMA *dma, int32_t limit); static bool ahci_map_clb_address(AHCIDevice *ad); @@ -591,9 +592,8 @@ static void check_cmd(AHCIState *s, int port) =20 if ((pr->cmd & PORT_CMD_START) && pr->cmd_issue) { for (slot =3D 0; (slot < 32) && pr->cmd_issue; slot++) { - if ((pr->cmd_issue & (1U << slot)) && - !handle_cmd(s, port, slot)) { - pr->cmd_issue &=3D ~(1U << slot); + if (pr->cmd_issue & (1U << slot)) { + handle_cmd(s, port, slot); } } } @@ -1123,6 +1123,22 @@ static void process_ncq_command(AHCIState *s, int po= rt, const uint8_t *cmd_fis, return; } =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. + * + * (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.) + */ + ahci_clear_cmd_issue(ad, slot); + + /* + * In reality, for NCQ commands, PxCI is cleared after receiving a D2H= FIS + * without the interrupt bit set, but since ahci_write_fis_d2h() can r= aise + * an IRQ on error, we need to call them in reverse order. + */ ahci_write_fis_d2h(ad, false); =20 ncq_tfs->used =3D 1; @@ -1197,6 +1213,7 @@ static void handle_reg_h2d_fis(AHCIState *s, int port, { IDEState *ide_state =3D &s->dev[port].port.ifs[0]; AHCICmdHdr *cmd =3D get_cmd_header(s, port, slot); + AHCIDevice *ad =3D &s->dev[port]; uint16_t opts =3D le16_to_cpu(cmd->opts); =20 if (cmd_fis[1] & 0x0F) { @@ -1273,11 +1290,19 @@ static void handle_reg_h2d_fis(AHCIState *s, int po= rt, /* Reset transferred byte counter */ cmd->status =3D 0; =20 + /* + * A non-NCQ command clears the bit in PxCI after the command has COMP= LETED + * successfully (ERROR not set, BUSY and DRQ cleared). + * + * For non-NCQ commands, PxCI will always be cleared by ahci_cmd_done(= ). + */ + ad->busy_slot =3D slot; + /* We're ready to process the command in FIS byte 2. */ ide_bus_exec_cmd(&s->dev[port].port, cmd_fis[2]); } =20 -static int handle_cmd(AHCIState *s, int port, uint8_t slot) +static void handle_cmd(AHCIState *s, int port, uint8_t slot) { IDEState *ide_state; uint64_t tbl_addr; @@ -1288,12 +1313,12 @@ static int handle_cmd(AHCIState *s, int port, uint8= _t slot) if (s->dev[port].port.ifs[0].status & (BUSY_STAT|DRQ_STAT)) { /* Engine currently busy, try again later */ trace_handle_cmd_busy(s, port); - return -1; + return; } =20 if (!s->dev[port].lst) { trace_handle_cmd_nolist(s, port); - return -1; + return; } cmd =3D get_cmd_header(s, port, slot); /* remember current slot handle for later */ @@ -1303,7 +1328,7 @@ static int handle_cmd(AHCIState *s, int port, uint8_t= slot) ide_state =3D &s->dev[port].port.ifs[0]; if (!ide_state->blk) { trace_handle_cmd_badport(s, port); - return -1; + return; } =20 tbl_addr =3D le64_to_cpu(cmd->tbl_addr); @@ -1312,7 +1337,7 @@ static int handle_cmd(AHCIState *s, int port, uint8_t= slot) DMA_DIRECTION_TO_DEVICE, MEMTXATTRS_UNSPECIFI= ED); if (!cmd_fis) { trace_handle_cmd_badfis(s, port); - return -1; + return; } else if (cmd_len !=3D 0x80) { ahci_trigger_irq(s, &s->dev[port], AHCI_PORT_IRQ_BIT_HBFS); trace_handle_cmd_badmap(s, port, cmd_len); @@ -1336,15 +1361,6 @@ static int handle_cmd(AHCIState *s, int port, uint8_= t slot) out: dma_memory_unmap(s->as, cmd_fis, cmd_len, DMA_DIRECTION_TO_DEVICE, cmd_len); - - if (s->dev[port].port.ifs[0].status & (BUSY_STAT|DRQ_STAT)) { - /* async command, complete later */ - s->dev[port].busy_slot =3D slot; - return -1; - } - - /* done handling the command */ - return 0; } =20 /* Transfer PIO data between RAM and device */ @@ -1498,6 +1514,16 @@ static int ahci_dma_rw_buf(const IDEDMA *dma, bool i= s_write) return 1; } =20 +static void ahci_clear_cmd_issue(AHCIDevice *ad, uint8_t slot) +{ + IDEState *ide_state =3D &ad->port.ifs[0]; + + if (!(ide_state->status & (BUSY_STAT | DRQ_STAT))) { + ad->port_regs.cmd_issue &=3D ~(1 << slot); + } +} + +/* Non-NCQ command is done - This function is never called for NCQ command= s. */ static void ahci_cmd_done(const IDEDMA *dma) { AHCIDevice *ad =3D DO_UPCAST(AHCIDevice, dma, dma); @@ -1506,11 +1532,15 @@ static void ahci_cmd_done(const IDEDMA *dma) =20 /* no longer busy */ if (ad->busy_slot !=3D -1) { - ad->port_regs.cmd_issue &=3D ~(1 << ad->busy_slot); + ahci_clear_cmd_issue(ad, ad->busy_slot); ad->busy_slot =3D -1; } =20 - /* update d2h status */ + /* + * In reality, for non-NCQ commands, PxCI is cleared after receiving a= D2H + * FIS with the interrupt bit set, but since ahci_write_fis_d2h() will= raise + * an IRQ, we need to call them in reverse order. + */ ahci_write_fis_d2h(ad, true); =20 if (ad->port_regs.cmd_issue && !ad->check_bh) { --=20 2.40.1 From nobody Fri May 3 22:16:21 2024 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=reject dis=none) header.from=flawful.org ARC-Seal: i=1; a=rsa-sha256; t=1685627288; cv=none; d=zohomail.com; s=zohoarc; b=b5+It66j/1uoPjZz86nuhO5eCvD15pJNsTT7d+eJo/VtYtYzhzJXaZ2cP1kQRdK2EXEvA3qmWsHbMgfm9MWttcVn0tGE2KRS5v9edifgP9Ml9K12FD7leuBsRmxwuXU7Ks9iySYeKWVarWNCeeaikgBaQVI6ZwrjTe/FMR3tvJM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685627288; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=lRUDXPgEIuqaCaSBtOJycBIS4yRVTfhduYGOGlOJRcw=; b=krAK6eNZDG2p7LQShL3XQHENrDEaepeYnuFd3TcbYYq0L0z0/tv4NKTtOSarBB4JLk5z7CUzegaSaFJGechOWYG54QSQvup65olbe3GpOsnvevHdZJDkZxS/WB6xeV0fsHnJSndm42uZN46ZnDO6+gXfVTlILTwydp1PITs/mYc= 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=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1685627288491786.5960109992272; Thu, 1 Jun 2023 06:48:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q4ieU-0001ga-Lp; Thu, 01 Jun 2023 09:47:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q4idT-0000eI-Se; Thu, 01 Jun 2023 09:46:45 -0400 Received: from mail-lj1-x233.google.com ([2a00:1450:4864:20::233]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q4idS-0008Od-1x; Thu, 01 Jun 2023 09:46:39 -0400 Received: by mail-lj1-x233.google.com with SMTP id 38308e7fff4ca-2af1822b710so12290751fa.1; Thu, 01 Jun 2023 06:46:37 -0700 (PDT) Received: from flawful.org (c-fcf6e255.011-101-6d6c6d3.bbcust.telenor.se. [85.226.246.252]) by smtp.gmail.com with ESMTPSA id c10-20020a2e9d8a000000b002af03f75edasm3762243ljj.80.2023.06.01.06.46.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Jun 2023 06:46:35 -0700 (PDT) Received: by flawful.org (Postfix, from userid 112) id 0844C9AF; Thu, 1 Jun 2023 15:46:30 +0200 (CEST) Received: from x1-carbon.lan (unknown [129.253.182.62]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by flawful.org (Postfix) with ESMTPSA id A69E08CC; Thu, 1 Jun 2023 15:45:36 +0200 (CEST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685627196; x=1688219196; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature:dkim-signature :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=lRUDXPgEIuqaCaSBtOJycBIS4yRVTfhduYGOGlOJRcw=; b=Fw7LPn5/BlTxtLp4z6I6QibWPBn6VKWwONVxvubijCqhuhvTQmB0AliRlJfValB3Xc qBxtHC5h4Kgjd5YKgesFYmVpvFJ8RaBBdqT4IwHUMbBvtSYYw4yGc/Q2NY8WOt/IzyJU ALXteHcgYVMvDmqyj37YDQLX4aEDKm2aAKy6DInfQayfQlCWNcixZeXlmTMra4RdqEhF rl8pFCLqB29k4F3gbhkhuAuBzGCSEkAWY+E85+VDBiSiSN3Ix3DUOUympCoKJg6Rn8qC KsUWP+JssLt2hJXSG57Dp069dP7Hzp4/UwRiAvenrC9C6BzFbLXjy4+LugnKVVgn7wWQ nqAA== X-Gm-Message-State: AC+VfDwREHLIsGa5zDYWC/cNKvO45I5xfAOJwCeFOAMAhX2kWbPcrTfc UsjvVCMQnVAA6x4/x/+xYhUNkVAQoGH6gntd X-Google-Smtp-Source: ACHHUZ5esnnLGzcbQ8bp2xkRGV5My+uf6LxFqF5DeiNuffXsjJ4phXtFgXvTm58TXE7nFM+oH0L3Nw== X-Received: by 2002:a2e:9cd8:0:b0:2a8:ac69:bfe with SMTP id g24-20020a2e9cd8000000b002a8ac690bfemr5028881ljj.42.1685627195886; Thu, 01 Jun 2023 06:46:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=flawful.org; s=mail; t=1685627194; bh=fmoGDhtmXtv2TR+hBxojsJtQ3DJAlcR2rp3dlui8BOQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ceYvwkdaShlNpo1WTWxdX5OzHe0NuxY2vX+FNJOa0UZaydSD6eM/j7JVqQNRgsMTd cq3PCN8WTp0QowD5eyjUn93P62ZT7S0s1GARhsrY8BIo4GIawZFYgBwTqmRopQcX+H HLkdPsy/DBu1D6Icths6kpEkXkYvrKMBBu35gjXQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=flawful.org; s=mail; t=1685627140; bh=fmoGDhtmXtv2TR+hBxojsJtQ3DJAlcR2rp3dlui8BOQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R+hsA9Cq5/4kWnsnp6kciMypYOjKl2Hr040/iqfd7W8ugCoF/uQqhe8eiDwpFo8wF Zp1M99pUwOGyFzgFD71gmCAXRisXNdElmCvy9k4f20hm534mS2u0Y3bB/EVsMp0alI DObhpCuSutimE+p6e+XHmrsdHDlX13zo2BQBkUBs= From: Niklas Cassel To: John Snow Cc: qemu-block@nongnu.org, qemu-devel@nongnu.org, Damien Le Moal , Niklas Cassel Subject: [PATCH v2 5/8] hw/ide/ahci: PxCI should not get cleared when ERR_STAT is set Date: Thu, 1 Jun 2023 15:44:31 +0200 Message-Id: <20230601134434.519805-6-nks@flawful.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230601134434.519805-1-nks@flawful.org> References: <20230601134434.519805-1-nks@flawful.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=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::233; envelope-from=nks.gnu@gmail.com; helo=mail-lj1-x233.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.248, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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 @flawful.org) (identity @flawful.org) X-ZM-MESSAGEID: 1685627290298100003 Content-Type: text/plain; charset="utf-8" From: Niklas Cassel For NCQ, PxCI is cleared on command queued successfully. For non-NCQ, PxCI is cleared on command completed successfully. Successfully means ERR_STAT, BUSY and DRQ are all cleared. A command that has ERR_STAT set, does not get to clear PxCI. See AHCI 1.3.1, section 5.3.8, states RegFIS:Entry and RegFIS:ClearCI, and 5.3.16.5 ERR:FatalTaskfile. In the case of non-NCQ commands, not clearing PxCI is needed in order for host software to be able to see which command slot that failed. Signed-off-by: Niklas Cassel --- hw/ide/ahci.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c index 3deaf01add..1237f94ddc 100644 --- a/hw/ide/ahci.c +++ b/hw/ide/ahci.c @@ -1518,7 +1518,8 @@ static void ahci_clear_cmd_issue(AHCIDevice *ad, uint= 8_t slot) { IDEState *ide_state =3D &ad->port.ifs[0]; =20 - if (!(ide_state->status & (BUSY_STAT | DRQ_STAT))) { + if (!(ide_state->status & ERR_STAT) && + !(ide_state->status & (BUSY_STAT | DRQ_STAT))) { ad->port_regs.cmd_issue &=3D ~(1 << slot); } } @@ -1527,6 +1528,7 @@ static void ahci_clear_cmd_issue(AHCIDevice *ad, uint= 8_t slot) static void ahci_cmd_done(const IDEDMA *dma) { AHCIDevice *ad =3D DO_UPCAST(AHCIDevice, dma, dma); + IDEState *ide_state =3D &ad->port.ifs[0]; =20 trace_ahci_cmd_done(ad->hba, ad->port_no); =20 @@ -1543,7 +1545,8 @@ static void ahci_cmd_done(const IDEDMA *dma) */ ahci_write_fis_d2h(ad, true); =20 - if (ad->port_regs.cmd_issue && !ad->check_bh) { + if (!(ide_state->status & ERR_STAT) && + ad->port_regs.cmd_issue && !ad->check_bh) { ad->check_bh =3D qemu_bh_new_guarded(ahci_check_cmd_bh, ad, &ad->mem_reentrancy_guard); qemu_bh_schedule(ad->check_bh); --=20 2.40.1 From nobody Fri May 3 22:16:21 2024 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=reject dis=none) header.from=flawful.org ARC-Seal: i=1; a=rsa-sha256; t=1685627272; cv=none; d=zohomail.com; s=zohoarc; b=DCDky/4eidOF4B9/W/ZW8hz+X0ex3PdxBKtuLwMc9+O2cCNY9Ze0KcWFNEN6RjUa03Vld89rngbCRHEKxJhwuPh6UfZBByMfWV7iSubp3jVFe9R3glZGOKlaeqNMPE8r85GZxVKBLUm8bGpHtYxK2A2Zwor7nvcoYqN8eS3oAq0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685627272; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=UYDWKGvKYC6by67JPxRh/7gjQRGbIlzsmtLuE8pp3NQ=; b=fqmX+3pMH803a4kDSsChbhOVC1eL0QA7BTE2RLimeqLpnhpJ2h76ePsleDmAdV3l47BcNzFw4hYYGL8uWP5X6S3xIKgpXWzMYf9OsOfUhukZ9CDtnXb4gVlDubeRusotjAkPv6M9PBSINy8YD6R8REFjPfFPoikiEOh2RYMDyg8= 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=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1685627272508126.72201290744852; Thu, 1 Jun 2023 06:47:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q4ieU-0001eE-Fi; Thu, 01 Jun 2023 09:47:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q4idV-0000eO-1U; Thu, 01 Jun 2023 09:46:45 -0400 Received: from mail-lf1-x131.google.com ([2a00:1450:4864:20::131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q4idS-0008Om-H9; Thu, 01 Jun 2023 09:46:40 -0400 Received: by mail-lf1-x131.google.com with SMTP id 2adb3069b0e04-4f3b5881734so1058984e87.0; Thu, 01 Jun 2023 06:46:37 -0700 (PDT) Received: from flawful.org (c-fcf6e255.011-101-6d6c6d3.bbcust.telenor.se. [85.226.246.252]) by smtp.gmail.com with ESMTPSA id x8-20020a2e8808000000b002a9f022e8bcsm3690202ljh.65.2023.06.01.06.46.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Jun 2023 06:46:36 -0700 (PDT) Received: by flawful.org (Postfix, from userid 112) id 40A4818B; Thu, 1 Jun 2023 15:46:35 +0200 (CEST) Received: from x1-carbon.lan (unknown [129.253.182.62]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by flawful.org (Postfix) with ESMTPSA id 94A857A7; Thu, 1 Jun 2023 15:45:41 +0200 (CEST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685627196; x=1688219196; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature:dkim-signature :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=UYDWKGvKYC6by67JPxRh/7gjQRGbIlzsmtLuE8pp3NQ=; b=UFiHB0XXKwmXF9g2Nh1el7A381w/5T+DRunnU5qgdmWo0KkRxo9rMK4ojrKgr45E9a 7FaMKiCvxM9WemUkX41ou6FIj5Ior6k0tgi8ag3+c0ifkRoV8+ynUVgzhldHoilj4k9R bQ61ZfquDf3OLvQsjdhOu8c2VUXrmeWz5TLWyEIgou5N1TIpTdefow3tudrm7fzuLvf8 QUpFoyJeEYEHVm9Qc3T+u7R9r4zxRIOD2ZX/kr2do5hhR4cC5xqf+4JPlEiErGlOmp6E HNIdNO/9xEGkP5bqsIqtVhwx8UkoXqrNYTyJzA1XN1zwvBXWbse0ITGoCPTk7qcVUsRl JjjQ== X-Gm-Message-State: AC+VfDzLgEEoa9vkIx7tmXAYB8g7XjASf0AkSKC+r3T0Vfsopsiyhs9o eHcQ5KCS22niQmZg4ywM6/xnxU6WhPfwIVra X-Google-Smtp-Source: ACHHUZ6oxm3rg5XywG8Q45WtAdpzTzumZcXzZ/0l6MLhX/Top97yf/uij6g3WymO3MwsFbtbm882tw== X-Received: by 2002:a05:651c:112:b0:2ad:92b9:83b4 with SMTP id a18-20020a05651c011200b002ad92b983b4mr4536080ljb.5.1685627196456; Thu, 01 Jun 2023 06:46:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=flawful.org; s=mail; t=1685627195; bh=8dATELxmRIkH+ezlgHYDRcOBfPchD3qIpLWy5BGqYcY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qsDhVUvNzjpcE9mFP04DSMmtVvjKguCVzQKcfC9yA9V9MFJiH6jCxqKh+cJcMgpUU Fo4k87fQASdPI9sIgcfxeJ835BWQcpTqBw78yrZp4S+jc/vq7yGdvk+SkEqfWJKVLa gcf5LYgpLHO3otglSkg/FKs4xcFhI2GZgyn0Vx0w= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=flawful.org; s=mail; t=1685627145; bh=8dATELxmRIkH+ezlgHYDRcOBfPchD3qIpLWy5BGqYcY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mNpQrXf4+le1c7Ccvfds/SYNocvC32n+RIEQ2zUxk4FZDoOqI3oj+9O6SN3OqYQg4 XkmipuGVMUY/Qb+l7KG82OeoNtrqEWT1aE4NyB69najXJsjc9Db81IU75YGQIfdG6X 5xEcQMevavKxcDDamQjnbBNd5Am1xf/KP6j36/wA= From: Niklas Cassel To: John Snow Cc: qemu-block@nongnu.org, qemu-devel@nongnu.org, Damien Le Moal , Niklas Cassel Subject: [PATCH v2 6/8] hw/ide/ahci: PxSACT and PxCI is cleared when PxCMD.ST is cleared Date: Thu, 1 Jun 2023 15:44:32 +0200 Message-Id: <20230601134434.519805-7-nks@flawful.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230601134434.519805-1-nks@flawful.org> References: <20230601134434.519805-1-nks@flawful.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=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::131; envelope-from=nks.gnu@gmail.com; helo=mail-lf1-x131.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.248, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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 @flawful.org) (identity @flawful.org) X-ZM-MESSAGEID: 1685627274217100009 Content-Type: text/plain; charset="utf-8" From: Niklas Cassel According to AHCI 1.3.1 definition of PxSACT: This field is cleared when PxCMD.ST is written from a '1' to a '0' by software. This field is not cleared by a COMRESET or a software reset. According to AHCI 1.3.1 definition of PxCI: This field is also cleared when PxCMD.ST is written from a '1' to a '0' by software. Clearing PxCMD.ST is part of the error recovery procedure, see AHCI 1.3.1, section "6.2 Error Recovery". If we don't clear PxCI on error recovery, the previous command will incorrectly still be marked as pending after error recovery. Signed-off-by: Niklas Cassel --- hw/ide/ahci.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c index 1237f94ddc..12aaadc554 100644 --- a/hw/ide/ahci.c +++ b/hw/ide/ahci.c @@ -329,6 +329,11 @@ static void ahci_port_write(AHCIState *s, int port, in= t offset, uint32_t val) ahci_check_irq(s); break; case AHCI_PORT_REG_CMD: + if ((pr->cmd & PORT_CMD_START) && !(val & PORT_CMD_START)) { + pr->scr_act =3D 0; + pr->cmd_issue =3D 0; + } + /* Block any Read-only fields from being set; * including LIST_ON and FIS_ON. * The spec requires to set ICC bits to zero after the ICC change --=20 2.40.1 From nobody Fri May 3 22:16:21 2024 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=reject dis=none) header.from=flawful.org ARC-Seal: i=1; a=rsa-sha256; t=1685627271; cv=none; d=zohomail.com; s=zohoarc; b=OvSeOq6trxGMWSEco+3jdYjLDsYvK/qNQQSpHknxeiBzyJO/4HpW9Dnhk4vGnhf66fLyYK4M5OhnCiewTR7PhP8UFVFY2k61zn064EIq4lZs4+xgrezAm12ckIg0v0SI0kiBZV5eb6NvS25h7ITLhfq+LEXb/4YXXAJAZoJXGag= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685627271; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=PVw/nyOLjJlLuDJ2e/yg0k3IjWpVDFSyPCJAnZ8lUhs=; b=kzSnTzZmoYb5o/2FfL6OtnRw8hoYz8phl4LbsvfKPyAFoj8lLsMiwehNKqX/CrC8FfuNv8U9HQgXeM0PJ5DXAZFoTODAd7/z+1UbZyDHO29YLQc3MezQ4D1kL1K5MvOJb68MMJaZxv2FaCmcyFtG55XARkpiVJQsCNCQDOpwINA= 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=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1685627271438819.4418948623098; Thu, 1 Jun 2023 06:47:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q4ieW-000243-Or; Thu, 01 Jun 2023 09:47:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q4ieH-0001Wg-Dn; Thu, 01 Jun 2023 09:47:40 -0400 Received: from mail-lf1-x134.google.com ([2a00:1450:4864:20::134]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q4idp-0008QV-RD; Thu, 01 Jun 2023 09:47:20 -0400 Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-4f3b9c88af8so1065814e87.2; Thu, 01 Jun 2023 06:46:54 -0700 (PDT) Received: from flawful.org (c-fcf6e255.011-101-6d6c6d3.bbcust.telenor.se. [85.226.246.252]) by smtp.gmail.com with ESMTPSA id q6-20020ac25106000000b004eb0dcc52ddsm1098438lfb.41.2023.06.01.06.46.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Jun 2023 06:46:53 -0700 (PDT) Received: by flawful.org (Postfix, from userid 112) id AC0427A7; Thu, 1 Jun 2023 15:46:50 +0200 (CEST) Received: from x1-carbon.lan (unknown [129.253.182.62]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by flawful.org (Postfix) with ESMTPSA id 720844C9; Thu, 1 Jun 2023 15:45:46 +0200 (CEST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685627213; x=1688219213; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature:dkim-signature :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=PVw/nyOLjJlLuDJ2e/yg0k3IjWpVDFSyPCJAnZ8lUhs=; b=LXn/3w+zzf9b1d3FsuchT0HwxFZoCk+f9tvO6llHJh1LeR6jTnkJ7IDIUYy+RK+qlF c8MeZZk9DEp8UQsYjbqmra4JjFYM58VsGDc5gBNPtR9VOyOWq+lB823f2LfO0CprwqmT fs/pkcGJIUrfiCeGZqYeOKjVBDbslJvBkJrMN7atUlfJteXCoq+CBergkAlTDbA/6c7z fx//EdJqBRyqbEROvNacLfpGqXEiamdCdlNE41Ja0qYPCRWwyQ5nqXt+Aztx+fcqd8uH eTX7BuahSy/PsvXBKZFTcYksvT/hDHVod+6VDxxlHi0kQ7/UB8TYwspSlCEMMUB+OONO PZQg== X-Gm-Message-State: AC+VfDyhvJ0zoabIUDtn5dLYbubtPEjXgOSfVKsJfvW2WL/DqpVG8cp2 t13JplBkVeEjcmahZe7Op1GNOnFT8kf3K3cd X-Google-Smtp-Source: ACHHUZ6m0LCf9l97hgbWzbVXGu/53nZM5uKrsrsM0+E0HKClDMULEmIKZTR77tULbG62VyGXb+27jA== X-Received: by 2002:ac2:5318:0:b0:4f5:bc19:68dd with SMTP id c24-20020ac25318000000b004f5bc1968ddmr1532607lfh.53.1685627213372; Thu, 01 Jun 2023 06:46:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=flawful.org; s=mail; t=1685627211; bh=EJ3qj6IemNXqj29g+yvQ2KmLufYZrgZ147654xg75oY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WJIeAxeD4PwkW8A8K5VGpwGx2Zl9ptTiQVrcJI+HyPfZfNI0xDqcSnRVfV9KN2ceX Nmec7L4xWyHFKC1VShRSMyFN7Y81ukw28o4DwhVkLGKIY87ydHqN6GfVw8kytLc0qt phvmtz4sqeZZDD5+4Qx9XuqzGxwryR2sJNw+RVCo= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=flawful.org; s=mail; t=1685627150; bh=EJ3qj6IemNXqj29g+yvQ2KmLufYZrgZ147654xg75oY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tr8PWKgmftRlRQnlFWGLQjJbWh88zs8pLCUOSQKnoxcRQFikxhYXvgfbU86jyYdC8 3Xxgc+psqqYBqX09t/IB6xEHCRicb0VuMLdPdo8WoCVv3OTVZV1059v8EeQOQzKoaY KARb98eKUf/TBJqvSrzUzFq0dKGsYFVDHFaKeQbQ= From: Niklas Cassel To: John Snow Cc: qemu-block@nongnu.org, qemu-devel@nongnu.org, Damien Le Moal , Niklas Cassel Subject: [PATCH v2 7/8] hw/ide/ahci: fix ahci_write_fis_sdb() Date: Thu, 1 Jun 2023 15:44:33 +0200 Message-Id: <20230601134434.519805-8-nks@flawful.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230601134434.519805-1-nks@flawful.org> References: <20230601134434.519805-1-nks@flawful.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=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::134; envelope-from=nks.gnu@gmail.com; helo=mail-lf1-x134.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.248, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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 @flawful.org) (identity @flawful.org) X-ZM-MESSAGEID: 1685627272346100003 Content-Type: text/plain; charset="utf-8" From: Niklas Cassel When there is an error, we need to raise a TFES error irq, see AHCI 1.3.1, 5.3.13.1 SDB:Entry. If ERR_STAT is set, we jump to state ERR:FatalTaskfile, which will raise a TFES IRQ unconditionally, regardless if the I bit is set in the FIS or not. Thus, we should never raise a normal IRQ after having sent an error IRQ. It is valid to signal successfully completed commands as finished in the same SDB FIS that generates the error IRQ. The important thing is that commands that did not complete successfully (e.g. commands that were aborted, do not get the finished bit set). Before this commit, there was never a TFES IRQ raised on NCQ error. Signed-off-by: Niklas Cassel --- hw/ide/ahci.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c index 12aaadc554..ef6c9fc378 100644 --- a/hw/ide/ahci.c +++ b/hw/ide/ahci.c @@ -806,8 +806,14 @@ static void ahci_write_fis_sdb(AHCIState *s, NCQTransf= erState *ncq_tfs) pr->scr_act &=3D ~ad->finished; ad->finished =3D 0; =20 - /* Trigger IRQ if interrupt bit is set (which currently, it always is)= */ - if (sdb_fis->flags & 0x40) { + /* + * TFES IRQ is always raised if ERR_STAT is set, regardless of I bit. + * If ERR_STAT is not set, trigger SDBS IRQ if interrupt bit is set + * (which currently, it always is). + */ + if (sdb_fis->status & ERR_STAT) { + ahci_trigger_irq(s, ad, AHCI_PORT_IRQ_BIT_TFES); + } else if (sdb_fis->flags & 0x40) { ahci_trigger_irq(s, ad, AHCI_PORT_IRQ_BIT_SDBS); } } --=20 2.40.1 From nobody Fri May 3 22:16:21 2024 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=reject dis=none) header.from=flawful.org ARC-Seal: i=1; a=rsa-sha256; t=1685627383; cv=none; d=zohomail.com; s=zohoarc; b=cSWslSke2DQVn5tg+k/l6jzqzUU0cXYuKKQ9vv8Rk6v5rkJqtCfK1sQBqvWGZKLVWpmaD/8AFcI6T4c/KFi+PtA6B4hOM+ykjMhIC+Nf/bG8SGslzQOt9YJlnMol/hO619si26ZSMb+UsB+LKt9AmgmzUMWWGPAcWnVPQ+RunCU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685627383; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=vpw0xLuydvT7GFr8RIfSnERhs9PDAhGa5JWXYO3jpus=; b=m/O41SVLMaLyHYFRKq4qSDnliRm5G9IYFqihCBVhYfJqOBCsm8jN7GVLZt20lBwCt/FwgNrwseP/Fi+H3l3qcSVBpae2aGSFw+a6MnlrTP5JLTHUHVZkoWmXykLWJxiGEjePC/ZLlemRrH4ZrfgZpB01w26k9sltIO/XqJlPY1w= 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=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1685627383634319.02882943911766; Thu, 1 Jun 2023 06:49:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q4iez-0002zh-C3; Thu, 01 Jun 2023 09:48:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q4ieK-0001Wq-2m; Thu, 01 Jun 2023 09:47:40 -0400 Received: from mail-lf1-x134.google.com ([2a00:1450:4864:20::134]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q4ieH-00004u-Iq; Thu, 01 Jun 2023 09:47:31 -0400 Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-4f4b80bf93aso1059724e87.0; Thu, 01 Jun 2023 06:47:05 -0700 (PDT) Received: from flawful.org (c-fcf6e255.011-101-6d6c6d3.bbcust.telenor.se. [85.226.246.252]) by smtp.gmail.com with ESMTPSA id q10-20020ac25a0a000000b004f0199e8770sm1100184lfn.65.2023.06.01.06.47.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Jun 2023 06:47:04 -0700 (PDT) Received: by flawful.org (Postfix, from userid 112) id 8E2D64E8; Thu, 1 Jun 2023 15:46:56 +0200 (CEST) Received: from x1-carbon.lan (unknown [129.253.182.62]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by flawful.org (Postfix) with ESMTPSA id A3160781; Thu, 1 Jun 2023 15:45:53 +0200 (CEST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685627225; x=1688219225; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature:dkim-signature :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=vpw0xLuydvT7GFr8RIfSnERhs9PDAhGa5JWXYO3jpus=; b=ky31UTFqWAmchhdgPFH20hFYC7p6JKXw9qxMQNX292NV5nsJdJKpr0j0KkT/37alo7 VCap6DY4q45i7wEjSSRRluSlMCCDTHzjSuTCkZ8E2Jbh9bSurVY+uoi919XKSWaaGx8z 1IawkovElOrJ+WLxZqZSW/4URWMneJL6z12qIlsFdraWrdsIpeVkrzJJ8TOQWI+pVgkq +CnQsdV9sgRKDJFtiY4+w2sTChTZ5yCuYzNUNClxlFcxkVHEbuhIyA7s/Yb+t/S7IM1n J1Q8WOK7oBNoFD2jNW9q1502JSxEj3dXsc+fhhRikJtjctFfE5AIiqngjxByHqh6zvaw CvCw== X-Gm-Message-State: AC+VfDzWCfPEEySea2lv/2HBG2MepXAEaZ8WEVucVRcbI8YWySVY2XcV 7tJ+cHGjgGi8RHcXJ1ZMEml66mHuQq7n9h+5 X-Google-Smtp-Source: ACHHUZ5PftWmFiLdgIXZk9KAGRijf23HCno8HFOF81O80BhsfozKdE5yWJ36F9XTBXjhPnuqaWFehw== X-Received: by 2002:ac2:548e:0:b0:4f4:7afe:c36 with SMTP id t14-20020ac2548e000000b004f47afe0c36mr1766690lfk.10.1685627224535; Thu, 01 Jun 2023 06:47:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=flawful.org; s=mail; t=1685627223; bh=wq7rsN/ynAZulkdl9oezyNlPiXKk6FZZrfXY0CHj0x0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HKekHvV0VbIDRnFD9w2n7wrZMVc6960Sxcdt1pOYEfmij5rrtRtvibw9rW7fjyRG0 9MrQtszd7OdqA3PNdkDtHbrLsCxj7j82Xf8dClkrwh+rVirhao5p7JQERatd58aSvB Ygzm7dBHhthA3tadHA/hL0uquNXfpSeY88ysJo3o= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=flawful.org; s=mail; t=1685627157; bh=wq7rsN/ynAZulkdl9oezyNlPiXKk6FZZrfXY0CHj0x0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bKMjdaoculQwaKvSnLZzFSh6s52oB+ycgmva3rXKuySnf7K6NT3UuRDB2HOgnvYt7 8f8HNmpUdIusJZIwnaN/LGWhivUN3kmuhe+f5PuUE57yi3awQz6T+H0oXi8+4d1/oq gIOS57GqTpmD4jI4qHhR10GBWJLF5aEtLobWfoWs= From: Niklas Cassel To: John Snow Cc: qemu-block@nongnu.org, qemu-devel@nongnu.org, Damien Le Moal , Niklas Cassel Subject: [PATCH v2 8/8] hw/ide/ahci: fix broken SError handling Date: Thu, 1 Jun 2023 15:44:34 +0200 Message-Id: <20230601134434.519805-9-nks@flawful.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230601134434.519805-1-nks@flawful.org> References: <20230601134434.519805-1-nks@flawful.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=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::134; envelope-from=nks.gnu@gmail.com; helo=mail-lf1-x134.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.248, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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 @flawful.org) (identity @flawful.org) X-ZM-MESSAGEID: 1685627384803100001 Content-Type: text/plain; charset="utf-8" From: Niklas Cassel When encountering an NCQ error, you should not write the NCQ tag to the SError register. This is completely wrong. The SError register has a clear definition, where each bit represents a different error, see PxSERR definition in AHCI 1.3.1. If we write a random value (like the NCQ tag) in SError, e.g. Linux will read SError, and will trigger arbitrary error handling depending on the NCQ tag that happened to be executing. In case of success, ncq_cb() will call ncq_finish(). In case of error, ncq_cb() will call ncq_err() (which will clear ncq_tfs->used), and then call ncq_finish(), thus using ncq_tfs->used is sufficient to tell if finished should get set or not. Signed-off-by: Niklas Cassel --- hw/ide/ahci.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c index ef6c9fc378..d0a774bc17 100644 --- a/hw/ide/ahci.c +++ b/hw/ide/ahci.c @@ -1012,7 +1012,6 @@ static void ncq_err(NCQTransferState *ncq_tfs) =20 ide_state->error =3D ABRT_ERR; ide_state->status =3D READY_STAT | ERR_STAT; - ncq_tfs->drive->port_regs.scr_err |=3D (1 << ncq_tfs->tag); qemu_sglist_destroy(&ncq_tfs->sglist); ncq_tfs->used =3D 0; } @@ -1022,7 +1021,7 @@ static void ncq_finish(NCQTransferState *ncq_tfs) /* If we didn't error out, set our finished bit. Errored commands * do not get a bit set for the SDB FIS ACT register, nor do they * clear the outstanding bit in scr_act (PxSACT). */ - if (!(ncq_tfs->drive->port_regs.scr_err & (1 << ncq_tfs->tag))) { + if (ncq_tfs->used) { ncq_tfs->drive->finished |=3D (1 << ncq_tfs->tag); } =20 --=20 2.40.1