From: Chris Leech <cleech@redhat.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Christoph Hellwig <hch@lst.de>, Rasesh Mody <rmody@marvell.com>,
Ariel Elior <aelior@marvell.com>,
Sudarsana Kalluru <skalluru@marvell.com>,
Manish Chopra <manishc@marvell.com>
Cc: Nilesh Javali <njavali@marvell.com>,
Manish Rangankar <mrangankar@marvell.com>,
Jerry Snitselaar <jsnitsel@redhat.com>,
John Meneghini <jmeneghi@redhat.com>,
Lee Duncan <lduncan@suse.com>,
Mike Christie <michael.christie@oracle.com>,
Hannes Reinecke <hare@kernel.org>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 2/3] cnic,bnx2,bnx2x: page align uio mmap allocations
Date: Fri, 29 Sep 2023 10:00:22 -0700 [thread overview]
Message-ID: <20230929170023.1020032-3-cleech@redhat.com> (raw)
In-Reply-To: <20230929170023.1020032-1-cleech@redhat.com>
Allocations in these drivers that will be mmaped through a uio device
should be made in multiples of PAGE_SIZE to avoid exposing additional
kernel memory unintentionally.
Signed-off-by: Chris Leech <cleech@redhat.com>
---
drivers/net/ethernet/broadcom/bnx2.c | 1 +
drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c | 8 ++++----
drivers/net/ethernet/broadcom/cnic.c | 9 +++++----
3 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/drivers/net/ethernet/broadcom/bnx2.c b/drivers/net/ethernet/broadcom/bnx2.c
index 0d917a9699c5..84a04eec654a 100644
--- a/drivers/net/ethernet/broadcom/bnx2.c
+++ b/drivers/net/ethernet/broadcom/bnx2.c
@@ -837,6 +837,7 @@ bnx2_alloc_stats_blk(struct net_device *dev)
BNX2_SBLK_MSIX_ALIGN_SIZE);
bp->status_stats_size = status_blk_size +
sizeof(struct statistics_block);
+ bp->status_stats_size = PAGE_ALIGN(bp->status_stats_size);
status_blk = dma_alloc_coherent(&bp->pdev->dev, bp->status_stats_size,
&bp->status_blk_mapping, GFP_KERNEL);
if (!status_blk)
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
index 0d8e61c63c7c..2fcde42a05c1 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
@@ -8270,10 +8270,10 @@ void bnx2x_free_mem_cnic(struct bnx2x *bp)
if (!CHIP_IS_E1x(bp))
BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
- sizeof(struct host_hc_status_block_e2));
+ PAGE_ALIGN(sizeof(struct host_hc_status_block_e2)));
else
BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
- sizeof(struct host_hc_status_block_e1x));
+ PAGE_ALIGN(sizeof(struct host_hc_status_block_e1x)));
BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
}
@@ -8316,12 +8316,12 @@ int bnx2x_alloc_mem_cnic(struct bnx2x *bp)
if (!CHIP_IS_E1x(bp)) {
/* size = the status block + ramrod buffers */
bp->cnic_sb.e2_sb = BNX2X_PCI_ALLOC(&bp->cnic_sb_mapping,
- sizeof(struct host_hc_status_block_e2));
+ PAGE_ALIGN(sizeof(struct host_hc_status_block_e2)));
if (!bp->cnic_sb.e2_sb)
goto alloc_mem_err;
} else {
bp->cnic_sb.e1x_sb = BNX2X_PCI_ALLOC(&bp->cnic_sb_mapping,
- sizeof(struct host_hc_status_block_e1x));
+ PAGE_ALIGN(sizeof(struct host_hc_status_block_e1x)));
if (!bp->cnic_sb.e1x_sb)
goto alloc_mem_err;
}
diff --git a/drivers/net/ethernet/broadcom/cnic.c b/drivers/net/ethernet/broadcom/cnic.c
index 7926aaef8f0c..67ec397bd171 100644
--- a/drivers/net/ethernet/broadcom/cnic.c
+++ b/drivers/net/ethernet/broadcom/cnic.c
@@ -1026,13 +1026,14 @@ static int __cnic_alloc_uio_rings(struct cnic_uio_dev *udev, int pages)
return 0;
udev->l2_ring_size = pages * CNIC_PAGE_SIZE;
+ udev->l2_ring_size = PAGE_ALIGN(udev->l2_ring_size);
udev->l2_ring = dma_alloc_coherent(&udev->pdev->dev, udev->l2_ring_size,
&udev->l2_ring_map, GFP_KERNEL);
if (!udev->l2_ring)
return -ENOMEM;
udev->l2_buf_size = (cp->l2_rx_ring_size + 1) * cp->l2_single_buf_size;
- udev->l2_buf_size = CNIC_PAGE_ALIGN(udev->l2_buf_size);
+ udev->l2_buf_size = PAGE_ALIGN(udev->l2_buf_size);
udev->l2_buf = dma_alloc_coherent(&udev->pdev->dev, udev->l2_buf_size,
&udev->l2_buf_map, GFP_KERNEL);
if (!udev->l2_buf) {
@@ -1108,9 +1109,9 @@ static int cnic_init_uio(struct cnic_dev *dev)
uinfo->mem[1].addr = (unsigned long) cp->status_blk.gen &
CNIC_PAGE_MASK;
if (cp->ethdev->drv_state & CNIC_DRV_STATE_USING_MSIX)
- uinfo->mem[1].size = BNX2_SBLK_MSIX_ALIGN_SIZE * 9;
+ uinfo->mem[1].size = PAGE_ALIGN(BNX2_SBLK_MSIX_ALIGN_SIZE * 9);
else
- uinfo->mem[1].size = BNX2_SBLK_MSIX_ALIGN_SIZE;
+ uinfo->mem[1].size = PAGE_ALIGN(BNX2_SBLK_MSIX_ALIGN_SIZE);
uinfo->name = "bnx2_cnic";
} else if (test_bit(CNIC_F_BNX2X_CLASS, &dev->flags)) {
@@ -1118,7 +1119,7 @@ static int cnic_init_uio(struct cnic_dev *dev)
uinfo->mem[1].addr = (unsigned long) cp->bnx2x_def_status_blk &
CNIC_PAGE_MASK;
- uinfo->mem[1].size = sizeof(*cp->bnx2x_def_status_blk);
+ uinfo->mem[1].size = PAGE_ALIGN(sizeof(*cp->bnx2x_def_status_blk));
uinfo->name = "bnx2x_cnic";
}
--
2.41.0
next prev parent reply other threads:[~2023-09-29 17:00 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-29 17:00 [PATCH 0/3] UIO_MEM_DMA_COHERENT for cnic/bnx2/bnx2x Chris Leech
2023-09-29 17:00 ` [PATCH 1/3] uio: introduce UIO_DMA_COHERENT type Chris Leech
2023-09-30 7:10 ` Greg Kroah-Hartman
2023-09-30 18:08 ` Chris Leech
2023-10-02 6:09 ` Christoph Hellwig
2023-09-29 17:00 ` Chris Leech [this message]
2023-09-29 17:18 ` [PATCH 2/3] cnic,bnx2,bnx2x: page align uio mmap allocations Jacob Keller
2023-10-02 6:11 ` Christoph Hellwig
2023-09-29 17:00 ` [PATCH 3/3] cnic,bnx2,bnx2x: use UIO_MEM_DMA_COHERENT Chris Leech
2023-09-29 17:19 ` Jacob Keller
2023-09-30 7:06 ` Greg Kroah-Hartman
2023-09-30 9:10 ` Jerry Snitselaar
2023-09-30 18:29 ` Greg Kroah-Hartman
2023-09-30 18:19 ` Chris Leech
2023-09-30 18:28 ` Greg Kroah-Hartman
2023-10-01 10:44 ` Hannes Reinecke
2023-10-01 11:57 ` Greg Kroah-Hartman
2023-10-01 14:22 ` Jerry Snitselaar
2023-10-02 6:04 ` Christoph Hellwig
2023-10-02 7:50 ` Jerry Snitselaar
2023-10-02 8:46 ` Greg Kroah-Hartman
2023-10-02 8:59 ` Hannes Reinecke
2023-10-05 10:39 ` Paolo Abeni
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230929170023.1020032-3-cleech@redhat.com \
--to=cleech@redhat.com \
--cc=aelior@marvell.com \
--cc=gregkh@linuxfoundation.org \
--cc=hare@kernel.org \
--cc=hch@lst.de \
--cc=jmeneghi@redhat.com \
--cc=jsnitsel@redhat.com \
--cc=lduncan@suse.com \
--cc=linux-kernel@vger.kernel.org \
--cc=manishc@marvell.com \
--cc=michael.christie@oracle.com \
--cc=mrangankar@marvell.com \
--cc=netdev@vger.kernel.org \
--cc=njavali@marvell.com \
--cc=rmody@marvell.com \
--cc=skalluru@marvell.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).