{"id":2237930,"url":"http://patchwork.ozlabs.org/api/patches/2237930/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-ide/patch/20260513151359.1075403-9-cassel@kernel.org/","project":{"id":13,"url":"http://patchwork.ozlabs.org/api/projects/13/?format=json","name":"Linux IDE development","link_name":"linux-ide","list_id":"linux-ide.vger.kernel.org","list_email":"linux-ide@vger.kernel.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20260513151359.1075403-9-cassel@kernel.org>","list_archive_url":null,"date":"2026-05-13T15:14:02","name":"[v4,3/4] ata: libata-scsi: do not use the deferred QC feature on PMPs with CBS","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"5d5d0172e86e3d18f59905c1b327bbcc8a862cd8","submitter":{"id":87751,"url":"http://patchwork.ozlabs.org/api/people/87751/?format=json","name":"Niklas Cassel","email":"cassel@kernel.org"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linux-ide/patch/20260513151359.1075403-9-cassel@kernel.org/mbox/","series":[{"id":504179,"url":"http://patchwork.ozlabs.org/api/series/504179/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-ide/list/?series=504179","date":"2026-05-13T15:13:59","name":"ata: fix deferred QC handling for port multipliers","version":4,"mbox":"http://patchwork.ozlabs.org/series/504179/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2237930/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2237930/checks/","tags":{},"related":[],"headers":{"Return-Path":"\n <linux-ide+bounces-5742-incoming=patchwork.ozlabs.org@vger.kernel.org>","X-Original-To":["incoming@patchwork.ozlabs.org","linux-ide@vger.kernel.org"],"Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256\n header.s=k20201202 header.b=UaXFmM4W;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=2600:3c0a:e001:db::12fc:5321; helo=sea.lore.kernel.org;\n envelope-from=linux-ide+bounces-5742-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)","smtp.subspace.kernel.org;\n\tdkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org\n header.b=\"UaXFmM4W\"","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=10.30.226.201"],"Received":["from sea.lore.kernel.org (sea.lore.kernel.org\n [IPv6:2600:3c0a:e001:db::12fc:5321])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4gFz0k4jwwz1yLT\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 14 May 2026 02:08:54 +1000 (AEST)","from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby sea.lore.kernel.org (Postfix) with ESMTP id D191032BF17B\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 13 May 2026 15:18:06 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id BD67D4A1387;\n\tWed, 13 May 2026 15:14:15 +0000 (UTC)","from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org\n [10.30.226.201])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby smtp.subspace.kernel.org (Postfix) with ESMTPS id 99690494A00\n\tfor <linux-ide@vger.kernel.org>; Wed, 13 May 2026 15:14:15 +0000 (UTC)","by smtp.kernel.org (Postfix) with ESMTPSA id B0833C2BCB3;\n\tWed, 13 May 2026 15:14:13 +0000 (UTC)"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1778685255; cv=none;\n b=GCvSyTogkbKrTSjr0GbiTXJ4MFpRUz3m+yZvgLeEE1KQ6AvbcK/hdeS30aP9LMTBRFQVRcb+Nfac5niJV+AjC6z6GXpXbI3BYybSxFpZAyHfxnKB3fLEU2KtKMJ4Gh24GxJXJMD6iGlqDlr6heXiSSKvxw+Qp0MTClaMlFGEePo=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1778685255; c=relaxed/simple;\n\tbh=YrB9IdA6xIKP5/LObDbHkjJiP8FkYMQohK0ttu4BjEw=;\n\th=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:\n\t MIME-Version;\n b=VXtRQSlHPlNCS2Fh7ie6+PvEtlgV3/K9yOgYP46C5Jed3nq4ArsxJVZch77BS8UPg2U1ae1Hr8qtFge/0kIjro+H6aZpek7ngFHIqg2k7nmZSAfwekQ5R12ST+tdwOd+CMK8YkBGRBtZ4xNKisoh043ewVZ/azDqSERoMReoRX0=","ARC-Authentication-Results":"i=1; smtp.subspace.kernel.org;\n dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org\n header.b=UaXFmM4W; arc=none smtp.client-ip=10.30.226.201","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;\n\ts=k20201202; t=1778685255;\n\tbh=YrB9IdA6xIKP5/LObDbHkjJiP8FkYMQohK0ttu4BjEw=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=UaXFmM4WjzhEFb0nXja0zRa5/L/GMdgC3JqwsWHrJ8Qa1tVpE4qnAZV3dU+OuQnWA\n\t pMnDgAhUpUke6FNsD8km0TjzNNFIzKZSxHA6YB9c7ECXyZZGPMDh/xEidNJl5dsHMK\n\t BTo2im6NYEESiN+QVHZVR8tMxC4by2nqkRgMCRKCdLTQauWqkUfKsE8TjC5Ptdpkdu\n\t dwfong8IS8XgqcrmKagY24/uXfK3fooiAEZLMz/UL6v5aCf9aRM/90BW7GEq9Y5CA4\n\t Uvcc/VffpmtMOHHMBjP3mVNiQOmqkMqcLWiHbtCDMaVsjUp9Hhf1rajMTwsGKgyzuP\n\t VtO5NsCAdMABw==","From":"Niklas Cassel <cassel@kernel.org>","To":"Tommy Kelly <linux@tkel.ly>,\n\tDamien Le Moal <dlemoal@kernel.org>,\n\tNiklas Cassel <cassel@kernel.org>,\n\tJohn Garry <john.g.garry@oracle.com>,\n\t\"Martin K. Petersen\" <martin.petersen@oracle.com>","Cc":"linux-ide@vger.kernel.org","Subject":"[PATCH v4 3/4] ata: libata-scsi: do not use the deferred QC feature\n on PMPs with CBS","Date":"Wed, 13 May 2026 17:14:02 +0200","Message-ID":"<20260513151359.1075403-9-cassel@kernel.org>","X-Mailer":"git-send-email 2.54.0","In-Reply-To":"<20260513151359.1075403-6-cassel@kernel.org>","References":"<20260513151359.1075403-6-cassel@kernel.org>","Precedence":"bulk","X-Mailing-List":"linux-ide@vger.kernel.org","List-Id":"<linux-ide.vger.kernel.org>","List-Subscribe":"<mailto:linux-ide+subscribe@vger.kernel.org>","List-Unsubscribe":"<mailto:linux-ide+unsubscribe@vger.kernel.org>","MIME-Version":"1.0","X-Developer-Signature":"v=1; a=openpgp-sha256; l=5145; i=cassel@kernel.org;\n h=from:subject; bh=YrB9IdA6xIKP5/LObDbHkjJiP8FkYMQohK0ttu4BjEw=;\n b=owGbwMvMwCV2MsVw8cxjvkWMp9WSGLJYplr8YJn/WMRE9ZbIbobtRW+nfsv81njiW3q1b0ezu\n +YM3jtLO0pZGMS4GGTFFFl8f7jsL+52n3Jc8Y4NzBxWJpAhDFycAjCRiyWMDO3VnxRqTF78a97r\n IhFYnPEm8d6Ny/9Z3L0exjLtm/Duvgojw+xr8x5cEOVSLv8gqjh7/0bjdo0s3lU+c18/+zHvZvF\n WcSYA","X-Developer-Key":"i=cassel@kernel.org; a=openpgp;\n fpr=5ADE635C0E631CBBD5BE065A352FE6582ED9B5DA","Content-Transfer-Encoding":"8bit"},"content":"When using Port Multipliers (PMPs) with Command-Based Switching (CBS), you\ncan only issue commands to one link at a time. For PMPs with CBS, there is\nalready code to handle commands being sent to different links in\nsata_pmp_qc_defer_cmd_switch() using ap->excl_link. sata_sil24 also makes\nuse of ap->excl_link.\n\nA user on the list reported that commit 0ea84089dbf6 (\"ata: libata-scsi:\navoid Non-NCQ command starvation\") broke PMPs with CBS. The commit\nintroduced code that stores a deferred qc in ap->deferred_qc, to later be\nissued via a workqueue. It turns out that this change is incompatible with\nthe existing ap->excl_link handling used by PMPs with CBS.\n\nThus, modify sata_pmp_qc_defer_cmd_switch() and sil24_qc_defer() to return\nATA_DEFER_LINK_EXCL, and make sure that the deferred QC handling via\nworkqueue is not used for this return value.\n\nThis way, PMPs with CBS will work once again. Note that the starvation\nreferenced in commit 0ea84089dbf6 (\"ata: libata-scsi: avoid Non-NCQ\ncommand starvation\") can only happen on libsas ports, and libsas does not\nsupport Port Multipliers, thus there is no harm of reverting back to the\nprevious way of deferring commands for PMPs with CBS.\n\nNon-libsas ports connected to anything but a PMP with CBS (e.g. a normal\ndrive or a PMP with FBS) will continue using the deferred workqueue, since\nit does result in lower completion latencies for non-NCQ commands, even\nthough the workqueue is not strictly needed to avoid starvation for\nnon-libsas ports.\n\nIf we want to modify the scope of the workqueue issuing to also handle\nPMPs with CBS, then we should ensure that we can save both NCQ and non-NCQ\ncommands in ap->deferred_qc, while also removing the existing PMP CBS\nhandling using ap->excl_link, such that we don't duplicate features.\n\nWhile at it, also add a comment explaining how the ap->excl_link mechanism\nworks.\n\nFixes: 0ea84089dbf6 (\"ata: libata-scsi: avoid Non-NCQ command starvation\")\nSigned-off-by: Niklas Cassel <cassel@kernel.org>\n---\n drivers/ata/libata-pmp.c  | 13 ++++++++++++-\n drivers/ata/libata-scsi.c |  8 ++++++++\n drivers/ata/sata_sil24.c  |  6 +++++-\n include/linux/libata.h    |  1 +\n 4 files changed, 26 insertions(+), 2 deletions(-)","diff":"diff --git a/drivers/ata/libata-pmp.c b/drivers/ata/libata-pmp.c\nindex e3adc008fed1..7e889534d73b 100644\n--- a/drivers/ata/libata-pmp.c\n+++ b/drivers/ata/libata-pmp.c\n@@ -110,13 +110,24 @@ int sata_pmp_qc_defer_cmd_switch(struct ata_queued_cmd *qc)\n {\n \tstruct ata_link *link = qc->dev->link;\n \tstruct ata_port *ap = link->ap;\n+\tint ret;\n \n \tif (ap->excl_link == NULL || ap->excl_link == link) {\n \t\tif (ap->nr_active_links == 0 || ata_link_active(link)) {\n \t\t\tqc->flags |= ATA_QCFLAG_CLEAR_EXCL;\n-\t\t\treturn ata_std_qc_defer(qc);\n+\t\t\tret = ata_std_qc_defer(qc);\n+\t\t\tif (ret == ATA_DEFER_LINK)\n+\t\t\t\treturn ATA_DEFER_LINK_EXCL;\n+\t\t\treturn ret;\n \t\t}\n \n+\t\t/*\n+\t\t * Note: ap->excl_link contains the link that is next in line,\n+\t\t * i.e. implicit round robin. If there is only one link\n+\t\t * dispatching, ap->excl_link will be left unclaimed, allowing\n+\t\t * other links to set ap->excl_link, ensuring that the currently\n+\t\t * active link cannot queue any more.\n+\t\t */\n \t\tap->excl_link = link;\n \t}\n \ndiff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c\nindex 22642a0e6b84..02f2d7416c83 100644\n--- a/drivers/ata/libata-scsi.c\n+++ b/drivers/ata/libata-scsi.c\n@@ -1787,6 +1787,14 @@ static int ata_scsi_qc_issue(struct ata_port *ap, struct ata_queued_cmd *qc)\n \tcase ATA_DEFER_LINK:\n \t\tret = SCSI_MLQUEUE_DEVICE_BUSY;\n \t\tgoto defer_qc;\n+\tcase ATA_DEFER_LINK_EXCL:\n+\t\t/*\n+\t\t * Drivers making use of ap->excl_link cannot store the QC in\n+\t\t * ap->deferred_qc, because the ap->excl_link handling is\n+\t\t * incompatible with the ap->deferred_qc workqueue handling.\n+\t\t */\n+\t\tret = SCSI_MLQUEUE_DEVICE_BUSY;\n+\t\tgoto defer_qc;\n \tcase ATA_DEFER_PORT:\n \t\tret = SCSI_MLQUEUE_HOST_BUSY;\n \t\tgoto free_qc;\ndiff --git a/drivers/ata/sata_sil24.c b/drivers/ata/sata_sil24.c\nindex d642ece9f07a..57f1081b86db 100644\n--- a/drivers/ata/sata_sil24.c\n+++ b/drivers/ata/sata_sil24.c\n@@ -789,6 +789,7 @@ static int sil24_qc_defer(struct ata_queued_cmd *qc)\n \tstruct ata_link *link = qc->dev->link;\n \tstruct ata_port *ap = link->ap;\n \tu8 prot = qc->tf.protocol;\n+\tint ret;\n \n \t/*\n \t * There is a bug in the chip:\n@@ -826,7 +827,10 @@ static int sil24_qc_defer(struct ata_queued_cmd *qc)\n \t\tqc->flags |= ATA_QCFLAG_CLEAR_EXCL;\n \t}\n \n-\treturn ata_std_qc_defer(qc);\n+\tret = ata_std_qc_defer(qc);\n+\tif (ret == ATA_DEFER_LINK)\n+\t\treturn ATA_DEFER_LINK_EXCL;\n+\treturn ret;\n }\n \n static enum ata_completion_errors sil24_qc_prep(struct ata_queued_cmd *qc)\ndiff --git a/include/linux/libata.h b/include/linux/libata.h\nindex 5c085ef4eda7..360776016b50 100644\n--- a/include/linux/libata.h\n+++ b/include/linux/libata.h\n@@ -371,6 +371,7 @@ enum {\n \t/* return values for ->qc_defer */\n \tATA_DEFER_LINK\t\t= 1,\n \tATA_DEFER_PORT\t\t= 2,\n+\tATA_DEFER_LINK_EXCL\t= 3,\n \n \t/* desc_len for ata_eh_info and context */\n \tATA_EH_DESC_LEN\t\t= 80,\n","prefixes":["v4","3/4"]}