linux-rdma.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RESEND 1/2] RDMA/mlx5: Fix number of allocated XLT entries
@ 2021-09-08  8:18 Niklas Schnelle
  2021-09-08  8:18 ` [PATCH RESEND 2/2] RDMA/mlx5: Fix xlt_chunk_align calculation Niklas Schnelle
  2021-09-08 11:45 ` [PATCH RESEND 1/2] RDMA/mlx5: Fix number of allocated XLT entries Jason Gunthorpe
  0 siblings, 2 replies; 3+ messages in thread
From: Niklas Schnelle @ 2021-09-08  8:18 UTC (permalink / raw)
  To: Leon Romanovsky, Jason Gunthorpe, Doug Ledford
  Cc: linux-rdma, linux-kernel, Niklas Schnelle

In commit 8010d74b9965b ("RDMA/mlx5: Split the WR setup out of
mlx5_ib_update_xlt()") the allocation logic was split out of
mlx5_ib_update_xlt() and the logic was changed to enable better OOM
handling. Sadly this change introduced a miscalculation of the number of
entries that were actually allocated when under memory pressure where it
can actually become 0 which on s390 lets dma_map_single() fail.

It can also lead to corruption of the free pages list when the wrong
number of entries is used in the calculation of sg->length which is used
as argument for free_pages().

Fix this by using the allocation size instead of misusing
get_order(size).

Cc: stable@vger.kernel.org
Fixes: 8010d74b9965b ("RDMA/mlx5: Split the WR setup out of mlx5_ib_update_xlt()")
Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>
---
 drivers/infiniband/hw/mlx5/mr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/infiniband/hw/mlx5/mr.c b/drivers/infiniband/hw/mlx5/mr.c
index 3f1c5a4f158b..19713cdd7b78 100644
--- a/drivers/infiniband/hw/mlx5/mr.c
+++ b/drivers/infiniband/hw/mlx5/mr.c
@@ -1024,7 +1024,7 @@ static void *mlx5_ib_alloc_xlt(size_t *nents, size_t ent_size, gfp_t gfp_mask)
 
 	if (size > MLX5_SPARE_UMR_CHUNK) {
 		size = MLX5_SPARE_UMR_CHUNK;
-		*nents = get_order(size) / ent_size;
+		*nents = size / ent_size;
 		res = (void *)__get_free_pages(gfp_mask | __GFP_NOWARN,
 					       get_order(size));
 		if (res)
-- 
2.25.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH RESEND 2/2] RDMA/mlx5: Fix xlt_chunk_align calculation
  2021-09-08  8:18 [PATCH RESEND 1/2] RDMA/mlx5: Fix number of allocated XLT entries Niklas Schnelle
@ 2021-09-08  8:18 ` Niklas Schnelle
  2021-09-08 11:45 ` [PATCH RESEND 1/2] RDMA/mlx5: Fix number of allocated XLT entries Jason Gunthorpe
  1 sibling, 0 replies; 3+ messages in thread
From: Niklas Schnelle @ 2021-09-08  8:18 UTC (permalink / raw)
  To: Leon Romanovsky, Jason Gunthorpe, Doug Ledford
  Cc: linux-rdma, linux-kernel, Niklas Schnelle

The XLT chunk alignment depends on ent_size not sizeof(ent_size) aka
sizeof(size_t).

Cc: stable@vger.kernel.org
Fixes: 8010d74b9965b ("RDMA/mlx5: Split the WR setup out of mlx5_ib_update_xlt()")
Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>
---
 drivers/infiniband/hw/mlx5/mr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/infiniband/hw/mlx5/mr.c b/drivers/infiniband/hw/mlx5/mr.c
index 19713cdd7b78..061dbee55cac 100644
--- a/drivers/infiniband/hw/mlx5/mr.c
+++ b/drivers/infiniband/hw/mlx5/mr.c
@@ -995,7 +995,7 @@ static struct mlx5_ib_mr *alloc_cacheable_mr(struct ib_pd *pd,
 static void *mlx5_ib_alloc_xlt(size_t *nents, size_t ent_size, gfp_t gfp_mask)
 {
 	const size_t xlt_chunk_align =
-		MLX5_UMR_MTT_ALIGNMENT / sizeof(ent_size);
+		MLX5_UMR_MTT_ALIGNMENT / ent_size;
 	size_t size;
 	void *res = NULL;
 
-- 
2.25.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH RESEND 1/2] RDMA/mlx5: Fix number of allocated XLT entries
  2021-09-08  8:18 [PATCH RESEND 1/2] RDMA/mlx5: Fix number of allocated XLT entries Niklas Schnelle
  2021-09-08  8:18 ` [PATCH RESEND 2/2] RDMA/mlx5: Fix xlt_chunk_align calculation Niklas Schnelle
@ 2021-09-08 11:45 ` Jason Gunthorpe
  1 sibling, 0 replies; 3+ messages in thread
From: Jason Gunthorpe @ 2021-09-08 11:45 UTC (permalink / raw)
  To: Niklas Schnelle; +Cc: Leon Romanovsky, Doug Ledford, linux-rdma, linux-kernel

On Wed, Sep 08, 2021 at 10:18:48AM +0200, Niklas Schnelle wrote:
> In commit 8010d74b9965b ("RDMA/mlx5: Split the WR setup out of
> mlx5_ib_update_xlt()") the allocation logic was split out of
> mlx5_ib_update_xlt() and the logic was changed to enable better OOM
> handling. Sadly this change introduced a miscalculation of the number of
> entries that were actually allocated when under memory pressure where it
> can actually become 0 which on s390 lets dma_map_single() fail.
> 
> It can also lead to corruption of the free pages list when the wrong
> number of entries is used in the calculation of sg->length which is used
> as argument for free_pages().
> 
> Fix this by using the allocation size instead of misusing
> get_order(size).
> 
> Cc: stable@vger.kernel.org
> Fixes: 8010d74b9965b ("RDMA/mlx5: Split the WR setup out of mlx5_ib_update_xlt()")
> Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>
> ---
>  drivers/infiniband/hw/mlx5/mr.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Both patches applied to for-rc, thanks

Jason

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-09-08 11:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-08  8:18 [PATCH RESEND 1/2] RDMA/mlx5: Fix number of allocated XLT entries Niklas Schnelle
2021-09-08  8:18 ` [PATCH RESEND 2/2] RDMA/mlx5: Fix xlt_chunk_align calculation Niklas Schnelle
2021-09-08 11:45 ` [PATCH RESEND 1/2] RDMA/mlx5: Fix number of allocated XLT entries Jason Gunthorpe

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).