Skip to content

Commit caac3d0

Browse files
committed
cnic,bnx2,bnx2x: use UIO_MEM_DMA_COHERENT
JIRA: https://issues.redhat.com/browse/RHEL-26081 Upstream Status: Posted https://lore.kernel.org/all/20240201233400.3394996-1-cleech@redhat.com/ Author: Chris Leech <cleech@redhat.com> Date: Thu Feb 1 15:33:58 2024 -0800 cnic,bnx2,bnx2x: use UIO_MEM_DMA_COHERENT Use the UIO_MEM_DMA_COHERENT type to properly handle mmap for dma_alloc_coherent buffers. The cnic l2_ring and l2_buf mmaps have caused page refcount issues as the dma_alloc_coherent no longer provide __GFP_COMP allocation as per commit "dma-mapping: reject __GFP_COMP in dma_alloc_attrs". Fix this by having the uio device use dma_mmap_coherent. The bnx2 and bnx2x status block allocations are also dma_alloc_coherent, and should use dma_mmap_coherent. They don't allocate multiple pages, but this interface does not work correctly with an iommu enabled unless dma_mmap_coherent is used. Signed-off-by: Nilesh Javali <njavali@marvell.com> Acked-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Chris Leech <cleech@redhat.com> Signed-off-by: Chris Leech <cleech@redhat.com>
1 parent ba126da commit caac3d0

File tree

5 files changed

+22
-8
lines changed

5 files changed

+22
-8
lines changed

drivers/net/ethernet/broadcom/bnx2.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ static void bnx2_setup_cnic_irq_info(struct bnx2 *bp)
367367
cp->irq_arr[0].status_blk = (void *)
368368
((unsigned long) bnapi->status_blk.msi +
369369
(BNX2_SBLK_MSIX_ALIGN_SIZE * sb_id));
370+
cp->irq_arr[0].status_blk_map = bp->status_blk_mapping;
370371
cp->irq_arr[0].status_blk_num = sb_id;
371372
cp->num_irq = 1;
372373
}

drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14900,9 +14900,11 @@ void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
1490014900
else
1490114901
cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
1490214902

14903+
cp->irq_arr[0].status_blk_map = bp->cnic_sb_mapping;
1490314904
cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
1490414905
cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
1490514906
cp->irq_arr[1].status_blk = bp->def_status_blk;
14907+
cp->irq_arr[1].status_blk_map = bp->def_status_blk_mapping;
1490614908
cp->irq_arr[1].status_blk_num = DEF_SB_ID;
1490714909
cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
1490814910

drivers/net/ethernet/broadcom/cnic.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,31 +1107,38 @@ static int cnic_init_uio(struct cnic_dev *dev)
11071107
TX_MAX_TSS_RINGS + 1);
11081108
uinfo->mem[1].addr = (unsigned long) cp->status_blk.gen &
11091109
CNIC_PAGE_MASK;
1110+
uinfo->mem[1].dma_addr = cp->status_blk_map;
11101111
if (cp->ethdev->drv_state & CNIC_DRV_STATE_USING_MSIX)
1111-
uinfo->mem[1].size = BNX2_SBLK_MSIX_ALIGN_SIZE * 9;
1112+
uinfo->mem[1].size = PAGE_ALIGN(BNX2_SBLK_MSIX_ALIGN_SIZE * 9);
11121113
else
1113-
uinfo->mem[1].size = BNX2_SBLK_MSIX_ALIGN_SIZE;
1114+
uinfo->mem[1].size = PAGE_ALIGN(BNX2_SBLK_MSIX_ALIGN_SIZE);
11141115

11151116
uinfo->name = "bnx2_cnic";
11161117
} else if (test_bit(CNIC_F_BNX2X_CLASS, &dev->flags)) {
11171118
uinfo->mem[0].size = pci_resource_len(dev->pcidev, 0);
11181119

11191120
uinfo->mem[1].addr = (unsigned long) cp->bnx2x_def_status_blk &
11201121
CNIC_PAGE_MASK;
1121-
uinfo->mem[1].size = sizeof(*cp->bnx2x_def_status_blk);
1122+
uinfo->mem[1].dma_addr = cp->status_blk_map;
1123+
uinfo->mem[1].size = PAGE_ALIGN(sizeof(*cp->bnx2x_def_status_blk));
11221124

11231125
uinfo->name = "bnx2x_cnic";
11241126
}
11251127

1126-
uinfo->mem[1].memtype = UIO_MEM_LOGICAL;
1128+
uinfo->mem[1].dma_device = &dev->pcidev->dev;
1129+
uinfo->mem[1].memtype = UIO_MEM_DMA_COHERENT;
11271130

11281131
uinfo->mem[2].addr = (unsigned long) udev->l2_ring;
1129-
uinfo->mem[2].size = udev->l2_ring_size;
1130-
uinfo->mem[2].memtype = UIO_MEM_LOGICAL;
1132+
uinfo->mem[2].dma_addr = udev->l2_ring_map;
1133+
uinfo->mem[2].size = PAGE_ALIGN(udev->l2_ring_size);
1134+
uinfo->mem[2].dma_device = &dev->pcidev->dev;
1135+
uinfo->mem[2].memtype = UIO_MEM_DMA_COHERENT;
11311136

11321137
uinfo->mem[3].addr = (unsigned long) udev->l2_buf;
1133-
uinfo->mem[3].size = udev->l2_buf_size;
1134-
uinfo->mem[3].memtype = UIO_MEM_LOGICAL;
1138+
uinfo->mem[3].dma_addr = udev->l2_buf_map;
1139+
uinfo->mem[3].size = PAGE_ALIGN(udev->l2_buf_size);
1140+
uinfo->mem[3].dma_device = &dev->pcidev->dev;
1141+
uinfo->mem[3].memtype = UIO_MEM_DMA_COHERENT;
11351142

11361143
uinfo->version = CNIC_MODULE_VERSION;
11371144
uinfo->irq = UIO_IRQ_CUSTOM;
@@ -1313,6 +1320,7 @@ static int cnic_alloc_bnx2x_resc(struct cnic_dev *dev)
13131320
return 0;
13141321

13151322
cp->bnx2x_def_status_blk = cp->ethdev->irq_arr[1].status_blk;
1323+
cp->status_blk_map = cp->ethdev->irq_arr[1].status_blk_map;
13161324

13171325
cp->l2_rx_ring_size = 15;
13181326

@@ -5324,6 +5332,7 @@ static int cnic_start_hw(struct cnic_dev *dev)
53245332
pci_dev_get(dev->pcidev);
53255333
cp->func = PCI_FUNC(dev->pcidev->devfn);
53265334
cp->status_blk.gen = ethdev->irq_arr[0].status_blk;
5335+
cp->status_blk_map = ethdev->irq_arr[0].status_blk_map;
53275336
cp->status_blk_num = ethdev->irq_arr[0].status_blk_num;
53285337

53295338
err = cp->alloc_resc(dev);

drivers/net/ethernet/broadcom/cnic.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ struct cnic_local {
260260
#define SM_RX_ID 0
261261
#define SM_TX_ID 1
262262
} status_blk;
263+
dma_addr_t status_blk_map;
263264

264265
struct host_sp_status_block *bnx2x_def_status_blk;
265266

drivers/net/ethernet/broadcom/cnic_if.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ struct cnic_ops {
190190
struct cnic_irq {
191191
unsigned int vector;
192192
void *status_blk;
193+
dma_addr_t status_blk_map;
193194
u32 status_blk_num;
194195
u32 status_blk_num2;
195196
u32 irq_flags;

0 commit comments

Comments
 (0)