{"id":2231874,"url":"http://patchwork.ozlabs.org/api/1.2/patches/2231874/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-ide/patch/20260501125410.1204490-6-cassel@kernel.org/","project":{"id":13,"url":"http://patchwork.ozlabs.org/api/1.2/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":"<20260501125410.1204490-6-cassel@kernel.org>","list_archive_url":null,"date":"2026-05-01T12:54:11","name":"[1/3] ata: libata-pmp: fix ata_pmp_qc_defer_cmd_switch()","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"71bd256cd69076e0fcd5abfee9920ca82f0cfaa4","submitter":{"id":87751,"url":"http://patchwork.ozlabs.org/api/1.2/people/87751/?format=json","name":"Niklas Cassel","email":"cassel@kernel.org"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linux-ide/patch/20260501125410.1204490-6-cassel@kernel.org/mbox/","series":[{"id":502457,"url":"http://patchwork.ozlabs.org/api/1.2/series/502457/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-ide/list/?series=502457","date":"2026-05-01T12:54:13","name":"ata: fix deferred QC handling for port multipliers","version":1,"mbox":"http://patchwork.ozlabs.org/series/502457/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2231874/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2231874/checks/","tags":{},"related":[],"headers":{"Return-Path":"\n <linux-ide+bounces-5617-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=dTZ77YbJ;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=172.234.253.10; helo=sea.lore.kernel.org;\n envelope-from=linux-ide+bounces-5617-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=\"dTZ77YbJ\"","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=10.30.226.201"],"Received":["from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])\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 4g6WGC2wq6z1yJv\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 01 May 2026 22:54:43 +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 7290C3019B98\n\tfor <incoming@patchwork.ozlabs.org>; Fri,  1 May 2026 12:54:21 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id 328FC3A5E6D;\n\tFri,  1 May 2026 12:54:20 +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 0F6EF3A545E\n\tfor <linux-ide@vger.kernel.org>; Fri,  1 May 2026 12:54:20 +0000 (UTC)","by smtp.kernel.org (Postfix) with ESMTPSA id 6DF91C2BCB4;\n\tFri,  1 May 2026 12:54:18 +0000 (UTC)"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1777640060; cv=none;\n b=m/14+qF7wMUqC58N8LkHOi6g8HTeo1N9A0BoyjUWU76GLQSd58Ef9v28+vO6XbpDWIZfkyeDz7m37i75nw4vlRVjkRAlYBje1Q8bmTOEm7XhvPmHmnPRn7WV4xs1HaNG+A0GoZ1aiJJFQj0DXoXqZ2ZEFvPfLPvYn/qJlhxsz+4=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1777640060; c=relaxed/simple;\n\tbh=L8uQm7kM3a+kcQdyEEYhxRl8Ejj5hBxFkHbbLREeoek=;\n\th=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:\n\t MIME-Version;\n b=dO6LYoK//b/qQ3TxNBoCVAqY0pu5NzurZxafbX1+X4oLmgrkADminucSuEYIqIdsiDOmwy9RvtbB4FtsrOZy4R3wU/MluSlbJaE6JzxOp56QxcuvOPu9t0qZeQfxUR8cXDhY8u8YtNCMXcPx3ssGOUmt1cVeeUoyAvZdr/uIYe8=","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=dTZ77YbJ; 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=1777640059;\n\tbh=L8uQm7kM3a+kcQdyEEYhxRl8Ejj5hBxFkHbbLREeoek=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=dTZ77YbJLkuGmr/M6iuhXIcIGm04N7nOgyL188IRADLz3NpQz9R5+Gq1O9i58Il0u\n\t pD/X9AcATBJaqFEJfgLEaNUWgxrJbgEZmufMhcXuu+yqcy1s+i2+Lpzz0ikWgHYgwj\n\t 4VRbQzM5z3/2xR1308b4w0d+fmQPmwEWt7i8woSWVkATiL2vtmweh2x4gWGLuxBZne\n\t cXx1JxIS86AIOENT58ZLL0o2E+XjWYxZ7tp3KENjQnPVKVfzGdGzsTT9WN6m5v3AOp\n\t /QVVqzcMdl7oIdC4bEkea6mYALhFbXOsCzw8xPVvjeBpkgAk0YSbVBZZwvT5ZIIdod\n\t pqgycEnfsbpPw==","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\tTejun Heo <htejun@gmail.com>,\n\tJeff Garzik <jeff@garzik.org>","Cc":"linux-ide@vger.kernel.org","Subject":"[PATCH 1/3] ata: libata-pmp: fix ata_pmp_qc_defer_cmd_switch()","Date":"Fri,  1 May 2026 14:54:11 +0200","Message-ID":"<20260501125410.1204490-6-cassel@kernel.org>","X-Mailer":"git-send-email 2.54.0","In-Reply-To":"<20260501125410.1204490-5-cassel@kernel.org>","References":"<20260501125410.1204490-5-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=2598; i=cassel@kernel.org;\n h=from:subject; bh=L8uQm7kM3a+kcQdyEEYhxRl8Ejj5hBxFkHbbLREeoek=;\n b=owGbwMvMwCV2MsVw8cxjvkWMp9WSGDK/LCpSuytYuGeVhe9M8VLlMyKih/8nyszM7P8czLlS4\n GjzPvsVHaUsDGJcDLJiiiy+P1z2F3e7TzmueMcGZg4rE8gQBi5OAZjIJ1+GP5zfP86M72ZstGl4\n fPWq0lrp6QtcWVoyD/zSk79ka8pWkMbIML83M65K9311isuei/sN3bieNm3SU2naIvna7Phcd80\n ERgA=","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.\n\nThis is implemented in sata_pmp_qc_defer_cmd_switch() by setting\nap->excl_link if there is no link currently being exclusive, and setting\nqc->flags ATA_QCFLAG_CLEAR_EXCL to clear the exlusive link in\n__ata_qc_complete().\n\nATA_QCFLAG_CLEAR_EXCL is only set if this is the first link to become\nactive, or if (since CBS can only have one active link) the current link\nis active. __ata_qc_complete() clears ap->excl_link as long as\nATA_QCFLAG_CLEAR_EXCL is set, it does not matter if there are still\noutstanding requests to the same link. This works because\nsata_pmp_qc_defer_cmd_switch() will only allow new commands to be queued\nif (ap->nr_active_links == 0 || ata_link_active(link)).\n\nHowever, since sata_pmp_qc_defer_cmd_switch() does a:\nreturn ata_std_qc_defer(qc); before setting ap->excl_link, this means that\nin the case where ap->excl_link == NULL and ata_std_qc_defer() returns 0\n(i.e. the QC should not be deferred), we would not set ap->excl_link.\n\nAdditionally, think of the following example:\nNCQ command1 to drive1 issued:\nsets ATA_QCFLAG_CLEAR_EXCL\ndoes not set ap->excl_link\n\nNCQ command2 to drive1 issued:\nsets ATA_QCFLAG_CLEAR_EXCL\ndoes not set ap->excl_link\n\nNCQ command3 to drive2 issued:\nap->excl_link gets set\ndoes not set ATA_QCFLAG_CLEAR_EXCL\nreturns ATA_DEFER_PORT\n\nFor command3, it seems wrong to set ap->excl_link while also deferring the\ncommand with ATA_DEFER_PORT.\n\nModify sata_pmp_qc_defer_cmd_switch() to only set ap->excl_link if we can\nactually issue a command (i.e. if we don't return ATA_DEFER_PORT or\nATA_DEFER_LINK).\n\nFixes: 31f88384443b (\"libata-pmp: implement qc_defer for command switching PMP support\")\nSigned-off-by: Niklas Cassel <cassel@kernel.org>\n---\n drivers/ata/libata-pmp.c | 9 ++++++---\n 1 file changed, 6 insertions(+), 3 deletions(-)","diff":"diff --git a/drivers/ata/libata-pmp.c b/drivers/ata/libata-pmp.c\nindex e3adc008fed1..0575e1e283d8 100644\n--- a/drivers/ata/libata-pmp.c\n+++ b/drivers/ata/libata-pmp.c\n@@ -113,11 +113,14 @@ int sata_pmp_qc_defer_cmd_switch(struct ata_queued_cmd *qc)\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\tint ret;\n+\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)\n+\t\t\t\tap->excl_link = link;\n+\t\t\treturn ret;\n \t\t}\n-\n-\t\tap->excl_link = link;\n \t}\n \n \treturn ATA_DEFER_PORT;\n","prefixes":["1/3"]}