Linux PCI subsystem development
 help / color / mirror / Atom feed
* [PATCH 0/3] ntb_hw_switchtec enable 256 LUTs
@ 2025-02-13 22:53 Maciej Grochowski
  2025-02-13 22:53 ` [PATCH 1/3] [PATCH 1/3] ntb: ntb_hw_switchtec: Fix shift-out-of-bounds for 0 mw lut Maciej Grochowski
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Maciej Grochowski @ 2025-02-13 22:53 UTC (permalink / raw)
  To: kurt.schwemmer, logang
  Cc: jdmason, dave.jiang, allenbh, linux-pci, ntb, Maciej Grochowski

Microchip NTB devices support up to 512 LUTs shared across all NT
partitions. This short patch series increases MAX_MWS to 256 and also
address issues when the number of mw is equal to 0 or MAX_MWS

Maciej Grochowski (3):
  ntb: ntb_hw_switchtec: Fix shift-out-of-bounds for 0 mw lut
  ntb: ntb_hw_switchtec: Fix array-index-out-of-bounds access
  ntb: ntb_hw_switchtec: Increase MAX_MWS limit to 256

 drivers/ntb/hw/mscc/ntb_hw_switchtec.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

-- 
2.20.1


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

* [PATCH 1/3] [PATCH 1/3] ntb: ntb_hw_switchtec: Fix shift-out-of-bounds for 0 mw lut
  2025-02-13 22:53 [PATCH 0/3] ntb_hw_switchtec enable 256 LUTs Maciej Grochowski
@ 2025-02-13 22:53 ` Maciej Grochowski
  2025-02-13 22:53 ` [PATCH 2/3] [PATCH 2/3] ntb: ntb_hw_switchtec: Fix array-index-out-of-bounds access Maciej Grochowski
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Maciej Grochowski @ 2025-02-13 22:53 UTC (permalink / raw)
  To: kurt.schwemmer, logang
  Cc: jdmason, dave.jiang, allenbh, linux-pci, ntb, Maciej Grochowski

Number of MW LUTs depends on NTB configuration and can be set to zero,
in such scenario rounddown_pow_of_two will cause undefined behaviour and
should not be performed.
This patch ensures that rounddown_pow_of_two is called on valid value.

Signed-off-by: Maciej Grochowski <Maciej.Grochowski@sony.com>
---
 drivers/ntb/hw/mscc/ntb_hw_switchtec.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/ntb/hw/mscc/ntb_hw_switchtec.c b/drivers/ntb/hw/mscc/ntb_hw_switchtec.c
index ad1786be2554..6ab094b0850a 100644
--- a/drivers/ntb/hw/mscc/ntb_hw_switchtec.c
+++ b/drivers/ntb/hw/mscc/ntb_hw_switchtec.c
@@ -1202,7 +1202,8 @@ static void switchtec_ntb_init_mw(struct switchtec_ntb *sndev)
 				       sndev->mmio_self_ctrl);
 
 	sndev->nr_lut_mw = ioread16(&sndev->mmio_self_ctrl->lut_table_entries);
-	sndev->nr_lut_mw = rounddown_pow_of_two(sndev->nr_lut_mw);
+	if (sndev->nr_lut_mw)
+		sndev->nr_lut_mw = rounddown_pow_of_two(sndev->nr_lut_mw);
 
 	dev_dbg(&sndev->stdev->dev, "MWs: %d direct, %d lut\n",
 		sndev->nr_direct_mw, sndev->nr_lut_mw);
@@ -1212,7 +1213,8 @@ static void switchtec_ntb_init_mw(struct switchtec_ntb *sndev)
 
 	sndev->peer_nr_lut_mw =
 		ioread16(&sndev->mmio_peer_ctrl->lut_table_entries);
-	sndev->peer_nr_lut_mw = rounddown_pow_of_two(sndev->peer_nr_lut_mw);
+	if (sndev->peer_nr_lut_mw)
+		sndev->peer_nr_lut_mw = rounddown_pow_of_two(sndev->peer_nr_lut_mw);
 
 	dev_dbg(&sndev->stdev->dev, "Peer MWs: %d direct, %d lut\n",
 		sndev->peer_nr_direct_mw, sndev->peer_nr_lut_mw);
-- 
2.20.1


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

* [PATCH 2/3] [PATCH 2/3] ntb: ntb_hw_switchtec: Fix array-index-out-of-bounds access
  2025-02-13 22:53 [PATCH 0/3] ntb_hw_switchtec enable 256 LUTs Maciej Grochowski
  2025-02-13 22:53 ` [PATCH 1/3] [PATCH 1/3] ntb: ntb_hw_switchtec: Fix shift-out-of-bounds for 0 mw lut Maciej Grochowski
@ 2025-02-13 22:53 ` Maciej Grochowski
  2025-02-13 22:53 ` [PATCH 3/3] [PATCH 3/3] ntb: ntb_hw_switchtec: Increase MAX_MWS limit to 256 Maciej Grochowski
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Maciej Grochowski @ 2025-02-13 22:53 UTC (permalink / raw)
  To: kurt.schwemmer, logang
  Cc: jdmason, dave.jiang, allenbh, linux-pci, ntb, Maciej Grochowski

Number of MW LUTs depends on NTB configuration and can be set to MAX_MWS,
This patch protects against invalid index out of bounds access to mw_sizes
When invalid access print message to user that configuration is not valid.

Signed-off-by: Maciej Grochowski <Maciej.Grochowski@sony.com>
---
 drivers/ntb/hw/mscc/ntb_hw_switchtec.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/ntb/hw/mscc/ntb_hw_switchtec.c b/drivers/ntb/hw/mscc/ntb_hw_switchtec.c
index 6ab094b0850a..51a3766b3f67 100644
--- a/drivers/ntb/hw/mscc/ntb_hw_switchtec.c
+++ b/drivers/ntb/hw/mscc/ntb_hw_switchtec.c
@@ -1316,6 +1316,11 @@ static void switchtec_ntb_init_shared(struct switchtec_ntb *sndev)
 	for (i = 0; i < sndev->nr_lut_mw; i++) {
 		int idx = sndev->nr_direct_mw + i;
 
+		if (idx >= MAX_MWS) {
+			dev_err(&sndev->stdev->dev,
+				"Total number of MW cannot be bigger than %d", MAX_MWS);
+			break;
+
 		sndev->self_shared->mw_sizes[idx] = LUT_SIZE;
 	}
 }
-- 
2.20.1


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

* [PATCH 3/3] [PATCH 3/3] ntb: ntb_hw_switchtec: Increase MAX_MWS limit to 256
  2025-02-13 22:53 [PATCH 0/3] ntb_hw_switchtec enable 256 LUTs Maciej Grochowski
  2025-02-13 22:53 ` [PATCH 1/3] [PATCH 1/3] ntb: ntb_hw_switchtec: Fix shift-out-of-bounds for 0 mw lut Maciej Grochowski
  2025-02-13 22:53 ` [PATCH 2/3] [PATCH 2/3] ntb: ntb_hw_switchtec: Fix array-index-out-of-bounds access Maciej Grochowski
@ 2025-02-13 22:53 ` Maciej Grochowski
  2025-02-13 22:58 ` [PATCH 0/3] ntb_hw_switchtec enable 256 LUTs Dave Jiang
  2025-02-14  0:49 ` Logan Gunthorpe
  4 siblings, 0 replies; 6+ messages in thread
From: Maciej Grochowski @ 2025-02-13 22:53 UTC (permalink / raw)
  To: kurt.schwemmer, logang
  Cc: jdmason, dave.jiang, allenbh, linux-pci, ntb, Maciej Grochowski

Microchip NTB switchtec devices supports up to 512 LUT's across all
NT partitions. This patch enable symmetric NTB configuration to utilize 
all 512 memory windows across 2 peers partitions.

Signed-off-by: Maciej Grochowski <Maciej.Grochowski@sony.com>
---
 drivers/ntb/hw/mscc/ntb_hw_switchtec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/ntb/hw/mscc/ntb_hw_switchtec.c b/drivers/ntb/hw/mscc/ntb_hw_switchtec.c
index 51a3766b3f67..98cd4121bef2 100644
--- a/drivers/ntb/hw/mscc/ntb_hw_switchtec.c
+++ b/drivers/ntb/hw/mscc/ntb_hw_switchtec.c
@@ -29,7 +29,7 @@ MODULE_PARM_DESC(use_lut_mws,
 		 "Enable the use of the LUT based memory windows");
 
 #define SWITCHTEC_NTB_MAGIC 0x45CC0001
-#define MAX_MWS     128
+#define MAX_MWS     256
 
 struct shared_mw {
 	u32 magic;
-- 
2.20.1


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

* Re: [PATCH 0/3] ntb_hw_switchtec enable 256 LUTs
  2025-02-13 22:53 [PATCH 0/3] ntb_hw_switchtec enable 256 LUTs Maciej Grochowski
                   ` (2 preceding siblings ...)
  2025-02-13 22:53 ` [PATCH 3/3] [PATCH 3/3] ntb: ntb_hw_switchtec: Increase MAX_MWS limit to 256 Maciej Grochowski
@ 2025-02-13 22:58 ` Dave Jiang
  2025-02-14  0:49 ` Logan Gunthorpe
  4 siblings, 0 replies; 6+ messages in thread
From: Dave Jiang @ 2025-02-13 22:58 UTC (permalink / raw)
  To: Maciej Grochowski, kurt.schwemmer, logang
  Cc: jdmason, allenbh, linux-pci, ntb



On 2/13/25 3:53 PM, Maciej Grochowski wrote:
> Microchip NTB devices support up to 512 LUTs shared across all NT
> partitions. This short patch series increases MAX_MWS to 256 and also
> address issues when the number of mw is equal to 0 or MAX_MWS
> 
> Maciej Grochowski (3):
>   ntb: ntb_hw_switchtec: Fix shift-out-of-bounds for 0 mw lut
>   ntb: ntb_hw_switchtec: Fix array-index-out-of-bounds access
>   ntb: ntb_hw_switchtec: Increase MAX_MWS limit to 256
> 
>  drivers/ntb/hw/mscc/ntb_hw_switchtec.c | 13 ++++++++++---
>  1 file changed, 10 insertions(+), 3 deletions(-)
> 
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
for the series

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

* Re: [PATCH 0/3] ntb_hw_switchtec enable 256 LUTs
  2025-02-13 22:53 [PATCH 0/3] ntb_hw_switchtec enable 256 LUTs Maciej Grochowski
                   ` (3 preceding siblings ...)
  2025-02-13 22:58 ` [PATCH 0/3] ntb_hw_switchtec enable 256 LUTs Dave Jiang
@ 2025-02-14  0:49 ` Logan Gunthorpe
  4 siblings, 0 replies; 6+ messages in thread
From: Logan Gunthorpe @ 2025-02-14  0:49 UTC (permalink / raw)
  To: Maciej Grochowski, kurt.schwemmer
  Cc: jdmason, dave.jiang, allenbh, linux-pci, ntb



On 2025-02-13 15:53, Maciej Grochowski wrote:
> Microchip NTB devices support up to 512 LUTs shared across all NT
> partitions. This short patch series increases MAX_MWS to 256 and also
> address issues when the number of mw is equal to 0 or MAX_MWS
> 
> Maciej Grochowski (3):
>   ntb: ntb_hw_switchtec: Fix shift-out-of-bounds for 0 mw lut
>   ntb: ntb_hw_switchtec: Fix array-index-out-of-bounds access
>   ntb: ntb_hw_switchtec: Increase MAX_MWS limit to 256
> 
>  drivers/ntb/hw/mscc/ntb_hw_switchtec.c | 13 ++++++++++---
>  1 file changed, 10 insertions(+), 3 deletions(-)
> 

All these patches look good to me. Thanks!

Reviewed-by: Logan Gunthorpe <logang@deltatee.com>

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

end of thread, other threads:[~2025-02-14  1:19 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-13 22:53 [PATCH 0/3] ntb_hw_switchtec enable 256 LUTs Maciej Grochowski
2025-02-13 22:53 ` [PATCH 1/3] [PATCH 1/3] ntb: ntb_hw_switchtec: Fix shift-out-of-bounds for 0 mw lut Maciej Grochowski
2025-02-13 22:53 ` [PATCH 2/3] [PATCH 2/3] ntb: ntb_hw_switchtec: Fix array-index-out-of-bounds access Maciej Grochowski
2025-02-13 22:53 ` [PATCH 3/3] [PATCH 3/3] ntb: ntb_hw_switchtec: Increase MAX_MWS limit to 256 Maciej Grochowski
2025-02-13 22:58 ` [PATCH 0/3] ntb_hw_switchtec enable 256 LUTs Dave Jiang
2025-02-14  0:49 ` Logan Gunthorpe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox