From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 9F9892686AA; Tue, 8 Apr 2025 12:37:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744115853; cv=none; b=ZfxVcEnoGEbw3GX9xGENKGmNI9LWMu740GHow2wluGVGfErdQvCHoPyADAsKBbbKrEPfXjVxIxX6k41WWAv1j78lX1hU2WyOuqViAiBHLgX+qcBeirPuG4ccl4ZS0/2wBNxQA2HmEn6HUm4nnl6nec84ZSSr9JdY0/0W6pp6YJA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744115853; c=relaxed/simple; bh=7W1FRoWhAA6/MbB+mFA4ZXyHsvMFrvJFTMYVZXVcYyc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DXA++tPKZuqUXPUKX2n32NByiZikw+49iIXn8BI8V0YeErd45lIs/zHyVWV1O36pVwifXokqexmtNFSEY1MU5QRkvJKnUFYhRqPq7uyo3m9gDFfoTqCwca29xk+4rhXJNJARVUx2K0r2GklF6t+ShtF50KtPx7FTidMyztcTpLg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=UcHDV+iR; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="UcHDV+iR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F2FBBC4CEE5; Tue, 8 Apr 2025 12:37:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1744115853; bh=7W1FRoWhAA6/MbB+mFA4ZXyHsvMFrvJFTMYVZXVcYyc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UcHDV+iRGVt7Wp43DWLwccXPXPTw911nfdRs4qB1uGDfnetVNtYG1DG5C6RuiLWIC 2EJtsGrFG4AG6PeRaURKg6CigdTbfKKzssYTZkrzD21Rqu0NNlgRBho5vWTpr0dKEu R8UBpwmYjGWj9KdDMFlhqnLqdmYUeTpVzTPon1rU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Icenowy Zheng , Keith Busch , Sasha Levin Subject: [PATCH 6.1 130/204] nvme-pci: skip CMB blocks incompatible with PCI P2P DMA Date: Tue, 8 Apr 2025 12:51:00 +0200 Message-ID: <20250408104824.116474841@linuxfoundation.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250408104820.266892317@linuxfoundation.org> References: <20250408104820.266892317@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Icenowy Zheng [ Upstream commit 56cf7ef0d490b28fad8f8629fc135c5ab7c9f54e ] The PCI P2PDMA code will register the CMB block to the memory hot-plugging subsystem, which have an alignment requirement. Memory blocks that do not satisfy this alignment requirement (usually 2MB) will lead to a WARNING from memory hotplugging. Verify the CMB block's address and size against the alignment and only try to send CMB blocks compatible with it to prevent this warning. Tested on Intel DC D4502 SSD, which has a 512K CMB block that is too small for memory hotplugging (thus PCI P2PDMA). Signed-off-by: Icenowy Zheng Signed-off-by: Keith Busch Signed-off-by: Sasha Levin --- drivers/nvme/host/pci.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c index bfca71f958a06..da858463b2557 100644 --- a/drivers/nvme/host/pci.c +++ b/drivers/nvme/host/pci.c @@ -1928,6 +1928,18 @@ static void nvme_map_cmb(struct nvme_dev *dev) if (offset > bar_size) return; + /* + * Controllers may support a CMB size larger than their BAR, for + * example, due to being behind a bridge. Reduce the CMB to the + * reported size of the BAR + */ + size = min(size, bar_size - offset); + + if (!IS_ALIGNED(size, memremap_compat_align()) || + !IS_ALIGNED(pci_resource_start(pdev, bar), + memremap_compat_align())) + return; + /* * Tell the controller about the host side address mapping the CMB, * and enable CMB decoding for the NVMe 1.4+ scheme: @@ -1938,14 +1950,6 @@ static void nvme_map_cmb(struct nvme_dev *dev) dev->bar + NVME_REG_CMBMSC); } - /* - * Controllers may support a CMB size larger than their BAR, - * for example, due to being behind a bridge. Reduce the CMB to - * the reported size of the BAR - */ - if (size > bar_size - offset) - size = bar_size - offset; - if (pci_p2pdma_add_resource(pdev, bar, size, offset)) { dev_warn(dev->ctrl.device, "failed to register the CMB\n"); -- 2.39.5