Skip to content

Commit 56cf7ef

Browse files
Icenowykeithbusch
authored andcommitted
nvme-pci: skip CMB blocks incompatible with PCI P2P DMA
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 <uwu@icenowy.me> Signed-off-by: Keith Busch <kbusch@kernel.org>
1 parent 6a3572e commit 56cf7ef

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

drivers/nvme/host/pci.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1982,6 +1982,18 @@ static void nvme_map_cmb(struct nvme_dev *dev)
19821982
if (offset > bar_size)
19831983
return;
19841984

1985+
/*
1986+
* Controllers may support a CMB size larger than their BAR, for
1987+
* example, due to being behind a bridge. Reduce the CMB to the
1988+
* reported size of the BAR
1989+
*/
1990+
size = min(size, bar_size - offset);
1991+
1992+
if (!IS_ALIGNED(size, memremap_compat_align()) ||
1993+
!IS_ALIGNED(pci_resource_start(pdev, bar),
1994+
memremap_compat_align()))
1995+
return;
1996+
19851997
/*
19861998
* Tell the controller about the host side address mapping the CMB,
19871999
* and enable CMB decoding for the NVMe 1.4+ scheme:
@@ -1992,14 +2004,6 @@ static void nvme_map_cmb(struct nvme_dev *dev)
19922004
dev->bar + NVME_REG_CMBMSC);
19932005
}
19942006

1995-
/*
1996-
* Controllers may support a CMB size larger than their BAR,
1997-
* for example, due to being behind a bridge. Reduce the CMB to
1998-
* the reported size of the BAR
1999-
*/
2000-
if (size > bar_size - offset)
2001-
size = bar_size - offset;
2002-
20032007
if (pci_p2pdma_add_resource(pdev, bar, size, offset)) {
20042008
dev_warn(dev->ctrl.device,
20052009
"failed to register the CMB\n");

0 commit comments

Comments
 (0)