From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from ale.deltatee.com (ale.deltatee.com [204.191.154.188]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A45F83A5E9F; Tue, 28 Jul 2026 17:24:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=204.191.154.188 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785259468; cv=none; b=Gmr9UjS/Mw5yi3qBpysehTFs5JjM69dGFG+WBD4QaWkHjrzMiKSOjcyM7wTkMU4N6jU9Niqqx+bQgI65ADOXMaSA1tMxWeicqg27/zhjnagwcPLlCPwiGEUB417hZn/b2j6NjmxebKF+7RZr3OnnTVEaaQuwhXbqTbVE2poBWa4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785259468; c=relaxed/simple; bh=ZPC6ghhCqsMrK87BUv1t3zX8JsRmF0Kr687Mia/l1FY=; h=From:To:Cc:Date:Message-ID:In-Reply-To:References:MIME-Version: Subject; b=E42PYJ4PKIulF2KgzzNds1XuiHjmKypZsbycY85dTJfsospiR/FZtUbnhK23w+dWpUfcRoQJngkqwQazN/gXOVAPiPG9W1KPelOieiral3gkcQoXG2/2G3m0vboAujoqICaf9MxTPi/2Df5RqXHcUGPOAO5MAnp9Of+nM/37fF4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=deltatee.com; spf=pass smtp.mailfrom=deltatee.com; dkim=pass (2048-bit key) header.d=deltatee.com header.i=@deltatee.com header.b=H9l/UTAb; arc=none smtp.client-ip=204.191.154.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=deltatee.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=deltatee.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=deltatee.com header.i=@deltatee.com header.b="H9l/UTAb" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=deltatee.com; s=20200525; h=Subject:MIME-Version:References:In-Reply-To: Message-ID:Date:Cc:To:From:content-disposition; bh=hPftQcQVknl4RJ4A76V5p6ISXP3pirJAXoAlUaAoIDM=; b=H9l/UTAbb3jW156ZFWd0zpBej3 edCnX4itqPTdvgBdnUiPgO2ev5LquJo7eXtYVQ09sVWpN/bnl7L9O9mxZGw4pzPRPMi8TSY9tuMqR Npz472K1EBCeinzTD1Lwpa99IuKOHEC/ueWXA9775Cl0VPYg/z4tfi7H8ZQFtcO3jyBWyZvhacWaL 910r2HjRbsahvrh02+93gnLFwd8QxW1qXHdwGGNFmujl/yR+RlceaTlWqipsP5b3VI3c4BWqcZ3Tr lWP+xX9dyguKTJFUnhdWl2wg0HHNRq3YIVt/zzKsUbBR/VAl4Df0HEvK7Omab1DX2LyS9gh44+GaZ 9EWfLXxg==; Received: from cgy1-donard.priv.deltatee.com ([172.16.1.31]) by ale.deltatee.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wolTz-00000000oZj-2g3t; Tue, 28 Jul 2026 11:20:48 -0600 Received: from gunthorp by cgy1-donard.priv.deltatee.com with local (Exim 4.98.2) (envelope-from ) id 1wolOq-00000000TDl-3cy7; Tue, 28 Jul 2026 11:15:28 -0600 From: Logan Gunthorpe To: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, dmaengine@vger.kernel.org, Vinod Koul Cc: Frank Li , Kelvin Cao , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Dave Jiang , George Ge , Jaeyoung Chung , Logan Gunthorpe , Sashiko , Frank Li Date: Tue, 28 Jul 2026 11:15:21 -0600 Message-ID: <20260728171523.112244-11-logang@deltatee.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260728171523.112244-1-logang@deltatee.com> References: <20260728171523.112244-1-logang@deltatee.com> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 172.16.1.31 X-SA-Exim-Rcpt-To: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, dmaengine@vger.kernel.org, linux@weissschuh.net, dave.jiang@intel.com, kelvin.cao@microchip.com, george.ge@microchip.com, jjy600901@snu.ac.kr, logang@deltatee.com, vkoul@kernel.org, sashiko-bot@kernel.org, Frank.li@nxp.com, Frank.Li@nxp.com X-SA-Exim-Mail-From: gunthorp@deltatee.com X-Spam-Level: Subject: [PATCH v4 10/12] dmaengine: ioat: disable relaxed ordering before registering the device X-SA-Exim-Version: 4.2.1 (built Sun, 23 Feb 2025 07:57:16 +0000) X-SA-Exim-Scanned: Yes (on ale.deltatee.com) ioat3_dma_probe() disabled PCIe relaxed ordering after calling dma_async_device_register(), so if an error occurs and the code jumps to err_disable_interrupts, the function returns with the device still registered in the core's dma_device_list while the caller frees the ioatdma_device struct, leaving a dangling registration that anything walking the device list can dereference after it's been freed. Move the capability read/write ahead of dma_async_device_register() instead. Nothing after registration depends on relaxed ordering already being disabled, and nothing before it depends on the device being registered, so this is a plain reordering. It also means every remaining step after registration can't fail, so there's no need to ever have to unregister the device once registered. Fixes: 511deae0261c ("dmaengine: ioatdma: disable relaxed ordering for ioatdma") Reported-by: Sashiko Link: https://lore.kernel.org/dmaengine/20260707165906.249F41F000E9@smtp.kernel.org Acked-by: Dave Jiang Reviewed-by: Frank Li Signed-off-by: Logan Gunthorpe --- drivers/dma/ioat/init.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/dma/ioat/init.c b/drivers/dma/ioat/init.c index 737496391109..a57024c4b066 100644 --- a/drivers/dma/ioat/init.c +++ b/drivers/dma/ioat/init.c @@ -1170,15 +1170,6 @@ static int ioat3_dma_probe(struct ioatdma_device *ioat_dma, int dca) ioat_chan->reg_base + IOAT_DCACTRL_OFFSET); } - err = dma_async_device_register(&ioat_dma->dma_dev); - if (err) - goto err_disable_interrupts; - - ioat_kobject_add(ioat_dma, &ioat_ktype); - - if (dca) - ioat_dma->dca = ioat_dca_init(pdev, ioat_dma->reg_base); - /* disable relaxed ordering */ err = pcie_capability_read_word(pdev, PCI_EXP_DEVCTL, &val16); if (err) { @@ -1194,6 +1185,15 @@ static int ioat3_dma_probe(struct ioatdma_device *ioat_dma, int dca) goto err_disable_interrupts; } + err = dma_async_device_register(&ioat_dma->dma_dev); + if (err) + goto err_disable_interrupts; + + ioat_kobject_add(ioat_dma, &ioat_ktype); + + if (dca) + ioat_dma->dca = ioat_dca_init(pdev, ioat_dma->reg_base); + if (ioat_dma->cap & IOAT_CAP_DPS) writeb(ioat_pending_level + 1, ioat_dma->reg_base + IOAT_PREFETCH_LIMIT_OFFSET); -- 2.47.3