Skip to contentSkip to conversation

arm: a37xx: pci: Extend validation for PCIe resources and oubound windows

PATCH In review Pali Rohár 3 participants 10 messages Jul 8, 2021 – Jul 15, 2021

Subsystems (4)
lore
Share & tools
lore
#1 lore raw

PATCH 2/3 arm: a37xx: pci: Optimize a3700_fdt_fix_pcie_regions() when fixup offset is zero

In reply to Pali Rohár

If fixup offset is zero then there is nothing to fix. All calculation in this case just increase addresses by value zero which results in identity. So in this case skip whole fixup re-calculation as it is not needed.

This is just an optimization for special case when fix_offset is zero which skips code path which does only identity operations (meaning nothing). No functional changes.

---
 arch/arm/mach-mvebu/armada3700/cpu.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/arm/mach-mvebu/armada3700/cpu.c +4 -0
index 4dd9de471b4e..64838b16c4d8 100644
@@ -339,6 +339,10 @@ int a3700_fdt_fix_pcie_regions(void *blob)
 	/* Calculate fixup offset from first child address (in last cell) */
 	fix_offset = base - fdt32_to_cpu(ranges[2]);
 
+	/* If fixup offset is zero then there is nothing to fix */
+	if (!fix_offset)
+		return 0;
+
 	/*
 	 * Fix address (last cell) of each child address and each parent
 	 * address
Signature · 1 line
2.20.1
#0 lore raw

PATCH 1/3 arm: a37xx: pci: Extend validation for PCIe resources and oubound windows

Remapped address of PCIe outbound window may have set only bits from the mask. Add additional check that remapped address which is calculated from PCIe bus address specified in DTS file is valid.

Remove also useless clearing of low 16 bits in win_mask. As win_size is power of two and is at least 0x10000 it means that it always has zero low 16 bits.

---
 drivers/pci/pci-aardvark.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/pci/pci-aardvark.c +4 -3
index 96aa039bdc26..77ce9d0c8d87 100644
@@ -609,21 +609,22 @@ static void pcie_advk_set_ob_region(struct pcie_advk *pcie, int *wins,
 	 * match with given mask.
 	 * So every PCIe window size must be a power of two and every start
 	 * address must be aligned to window size. Minimal size is 64 KiB
-	 * because lower 16 bits of mask must be zero.
+	 * because lower 16 bits of mask must be zero. Remapped address
+	 * may have set only bits from the mask.
 	 */
 	while (*wins < OB_WIN_COUNT && size > 0) {
 		/* Calculate the largest aligned window size */
 		win_size = (1ULL << (fls64(size) - 1)) |
 			   (phys_start ? (1ULL << __ffs64(phys_start)) : 0);
 		win_size = 1ULL << __ffs64(win_size);
-		if (win_size < 0x10000)
+		win_mask = ~(win_size - 1);
+		if (win_size < 0x10000 || (bus_start & ~win_mask))
 			break;
 
 		dev_dbg(pcie->dev,
 			"Configuring PCIe window %d: [0x%llx-0x%llx] as 0x%x\n",
 			*wins, (u64)phys_start, (u64)phys_start + win_size,
 			actions);
-		win_mask = ~(win_size - 1) & ~0xffff;
 		pcie_advk_set_ob_win(pcie, *wins, phys_start, bus_start,
 				     win_mask, actions);
 
Signature · 1 line
2.20.1
#4 lore raw

PATCH 3/3 arm: a37xx: pci: Fix typo in comment

---
 drivers/pci/pci-aardvark.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/pci-aardvark.c +1 -1
index 77ce9d0c8d87..1b9bae7cca72 100644
@@ -605,7 +605,7 @@ static void pcie_advk_set_ob_region(struct pcie_advk *pcie, int *wins,
 
 	/*
 	 * The n-th PCIe window is configured by tuple (match, remap, mask)
-	 * and an access to address A uses this window it if A matches the
+	 * and an access to address A uses this window if A matches the
 	 * match with given mask.
 	 * So every PCIe window size must be a power of two and every start
 	 * address must be aligned to window size. Minimal size is 64 KiB
Signature · 1 line
2.20.1
Reviewed-by on v1 3/3
#5 lore raw

RE: [EXT] [PATCH 3/3] arm: a37xx: pci: Fix typo in comment

Quoted 30 lines

-----Original Message-----
From: Pali Rohár <[email protected]>
Sent: Thursday, July 8, 2021 21:19
To: Stefan Roese <[email protected]>; Kostya Porotchkin <[email protected]>
Cc: Marek Behún <[email protected]>; [email protected]
Subject: [EXT] [PATCH 3/3] arm: a37xx: pci: Fix typo in comment

External Email

----------------------------------------------------------------------

---
 drivers/pci/pci-aardvark.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/pci-aardvark.c index renamed from drivers/pci/pci-aardvark.c +0 -0

77ce9d0c8d87..1b9bae7cca72 100644

drivers/pci/pci-aardvark.c +1 -1
@@ -605,7 +605,7 @@ static void pcie_advk_set_ob_region(struct pcie_advk
 *pcie, int *wins,
 
 	/*
 	 * The n-th PCIe window is configured by tuple (match, remap, mask)
-	 * and an access to address A uses this window it if A matches the
+	 * and an access to address A uses this window if A matches the
 	 * match with given mask.
 	 * So every PCIe window size must be a power of two and every start
Quoted 3 lines

* address must be aligned to window size. Minimal size is 64 KiB
--
2.20.1

Reviewed-by on v1 1/3
#7 lore raw
In reply to Pali Rohár
Quoted 58 lines

-----Original Message-----
From: Pali Rohár <[email protected]>
Sent: Thursday, July 8, 2021 21:19
To: Stefan Roese <[email protected]>; Kostya Porotchkin <[email protected]>
Cc: Marek Behún <[email protected]>; [email protected]
Subject: [EXT] [PATCH 1/3] arm: a37xx: pci: Extend validation for PCIe resources and oubound windows

External Email

----------------------------------------------------------------------
Remapped address of PCIe outbound window may have set only bits from the mask. Add additional check that remapped address which is calculated from PCIe bus address specified in DTS file is valid.

Remove also useless clearing of low 16 bits in win_mask. As win_size is power of two and is at least 0x10000 it means that it always has zero low 16 bits.

---
 drivers/pci/pci-aardvark.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/pci/pci-aardvark.c index renamed from drivers/pci/pci-aardvark.c +0 -0

96aa039bdc26..77ce9d0c8d87 100644

drivers/pci/pci-aardvark.c +4 -3
@@ -609,21 +609,22 @@ static void pcie_advk_set_ob_region(struct
 pcie_advk *pcie, int *wins,
 	 * match with given mask.
 	 * So every PCIe window size must be a power of two and every start
 	 * address must be aligned to window size. Minimal size is 64 KiB
-	 * because lower 16 bits of mask must be zero.
+	 * because lower 16 bits of mask must be zero. Remapped address
+	 * may have set only bits from the mask.
 	 */
 	while (*wins < OB_WIN_COUNT && size > 0) {
 		/* Calculate the largest aligned window size */
 		win_size = (1ULL << (fls64(size) - 1)) |
 			   (phys_start ? (1ULL << __ffs64(phys_start)) : 0);
 		win_size = 1ULL << __ffs64(win_size);
-		if (win_size < 0x10000)
+		win_mask = ~(win_size - 1);
+		if (win_size < 0x10000 || (bus_start & ~win_mask))
 			break;
 
 		dev_dbg(pcie->dev,
 			"Configuring PCIe window %d: [0x%llx-0x%llx] as
 0x%x\n",
 			*wins, (u64)phys_start, (u64)phys_start + win_size,
 			actions);
-		win_mask = ~(win_size - 1) & ~0xffff;
 		pcie_advk_set_ob_win(pcie, *wins, phys_start, bus_start,

win_mask, actions);

Quoted 2 lines

--
2.20.1

Reviewed-by on v1 2/3
#2 lore raw

RE: [EXT] [PATCH 2/3] arm: a37xx: pci: Optimize a3700_fdt_fix_pcie_regions() when fixup offset is zero

In reply to Pali Rohár
Quoted 43 lines

-----Original Message-----
From: Pali Rohár <[email protected]>
Sent: Thursday, July 8, 2021 21:19
To: Stefan Roese <[email protected]>; Kostya Porotchkin <[email protected]>
Cc: Marek Behún <[email protected]>; [email protected]
Subject: [EXT] [PATCH 2/3] arm: a37xx: pci: Optimize a3700_fdt_fix_pcie_regions() when fixup offset is zero

External Email

----------------------------------------------------------------------
If fixup offset is zero then there is nothing to fix. All calculation in this case just increase addresses by value zero which results in identity.
So in this case skip whole fixup re-calculation as it is not needed.

This is just an optimization for special case when fix_offset is zero which skips code path which does only identity operations (meaning nothing). No functional changes.

---
 arch/arm/mach-mvebu/armada3700/cpu.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/arm/mach- renamed from arch/arm/mach-mvebu/armada3700/cpu.c +0 -0

mvebu/armada3700/cpu.c
index 4dd9de471b4e..64838b16c4d8 100644

arch/arm/mach-mvebu/armada3700/cpu.c +4 -1
@@ -339,6 +339,10 @@ int a3700_fdt_fix_pcie_regions(void *blob)
 	/* Calculate fixup offset from first child address (in last cell) */
 	fix_offset = base - fdt32_to_cpu(ranges[2]);
 
+	/* If fixup offset is zero then there is nothing to fix */
+	if (!fix_offset)
+		return 0;
+
 	/*
 	 * Fix address (last cell) of each child address and each parent
 	 * address
--
Quoted 1 line

2.20.1

Reviewed-by on v1 1/3
#8 lore raw
In reply to Pali Rohár
Quoted 9 lines · Pali Rohár

Remapped address of PCIe outbound window may have set only bits from the mask. Add additional check that remapped address which is calculated from PCIe bus address specified in DTS file is valid.

Remove also useless clearing of low 16 bits in win_mask. As win_size is power of two and is at least 0x10000 it means that it always has zero low 16 bits.

Thanks,
Stefan

Quoted 25 lines
---
  drivers/pci/pci-aardvark.c | 7 ++++---
  1 file changed, 4 insertions(+), 3 deletions(-)
drivers/pci/pci-aardvark.c +4 -2
index 96aa039bdc26..77ce9d0c8d87 100644
@@ -609,21 +609,22 @@ static void pcie_advk_set_ob_region(struct pcie_advk *pcie, int *wins,
  	 * match with given mask.
  	 * So every PCIe window size must be a power of two and every start
  	 * address must be aligned to window size. Minimal size is 64 KiB
-	 * because lower 16 bits of mask must be zero.
+	 * because lower 16 bits of mask must be zero. Remapped address
+	 * may have set only bits from the mask.
  	 */
  	while (*wins < OB_WIN_COUNT && size > 0) {
  		/* Calculate the largest aligned window size */
  		win_size = (1ULL << (fls64(size) - 1)) |
  			   (phys_start ? (1ULL << __ffs64(phys_start)) : 0);
  		win_size = 1ULL << __ffs64(win_size);
-		if (win_size < 0x10000)
+		win_mask = ~(win_size - 1);
+		if (win_size < 0x10000 || (bus_start & ~win_mask))

drivers/pci/pci-aardvark.c static void pcie_advk_set_ob_region(struct pcie_advk *pcie, int *wins, · line 630

Quoted 10 lines
drivers/pci/pci-aardvark.c +0 -1
  			break;
 
  		dev_dbg(pcie->dev,
  			"Configuring PCIe window %d: [0x%llx-0x%llx] as 0x%x\n",
  			*wins, (u64)phys_start, (u64)phys_start + win_size,
  			actions);
-		win_mask = ~(win_size - 1) & ~0xffff;
  		pcie_advk_set_ob_win(pcie, *wins, phys_start, bus_start,
  				     win_mask, actions);
 

Viele Grüße,
Stefan

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: [email protected]
Reviewed-by on v1 2/3
#3 lore raw

Re: [PATCH 2/3] arm: a37xx: pci: Optimize a3700_fdt_fix_pcie_regions() when fixup offset is zero

In reply to Pali Rohár
Quoted 9 lines · Pali Rohár

If fixup offset is zero then there is nothing to fix. All calculation in this case just increase addresses by value zero which results in identity. So in this case skip whole fixup re-calculation as it is not needed.

This is just an optimization for special case when fix_offset is zero which skips code path which does only identity operations (meaning nothing). No functional changes.

Thanks,
Stefan

Quoted 10 lines
---
  arch/arm/mach-mvebu/armada3700/cpu.c | 4 ++++
  1 file changed, 4 insertions(+)
arch/arm/mach-mvebu/armada3700/cpu.c +0 -0
index 4dd9de471b4e..64838b16c4d8 100644

arch/arm/mach-mvebu/armada3700/cpu.c int a3700_fdt_fix_pcie_regions(void *blob) · line 348

Quoted 10 lines
arch/arm/mach-mvebu/armada3700/cpu.c +4 -0
@@ -339,6 +339,10 @@ int a3700_fdt_fix_pcie_regions(void *blob)
  	/* Calculate fixup offset from first child address (in last cell) */
  	fix_offset = base - fdt32_to_cpu(ranges[2]);
 
+	/* If fixup offset is zero then there is nothing to fix */
+	if (!fix_offset)
+		return 0;
+
  	/*
  	 * Fix address (last cell) of each child address and each parent
  	 * address

Viele Grüße,
Stefan

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: [email protected]
Reviewed-by on v1 3/3
#6 lore raw

Re: [PATCH 3/3] arm: a37xx: pci: Fix typo in comment

In reply to Pali Rohár
Quoted 1 line · Pali Rohár

Thanks,
Stefan

Quoted 10 lines
---
  drivers/pci/pci-aardvark.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/pci-aardvark.c +0 -0
index 77ce9d0c8d87..1b9bae7cca72 100644

drivers/pci/pci-aardvark.c static void pcie_advk_set_ob_region(struct pcie_advk *pcie, int *wins, · line 611

Quoted 8 lines
drivers/pci/pci-aardvark.c +1 -1
@@ -605,7 +605,7 @@ static void pcie_advk_set_ob_region(struct pcie_advk *pcie, int *wins,
 
  	/*
  	 * The n-th PCIe window is configured by tuple (match, remap, mask)
-	 * and an access to address A uses this window it if A matches the
+	 * and an access to address A uses this window if A matches the
  	 * match with given mask.
  	 * So every PCIe window size must be a power of two and every start
  	 * address must be aligned to window size. Minimal size is 64 KiB

Viele Grüße,
Stefan

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: [email protected]
#9 lore raw
In reply to Pali Rohár
Quoted 9 lines · Pali Rohár

Remapped address of PCIe outbound window may have set only bits from the mask. Add additional check that remapped address which is calculated from PCIe bus address specified in DTS file is valid.

Remove also useless clearing of low 16 bits in win_mask. As win_size is power of two and is at least 0x10000 it means that it always has zero low 16 bits.

All patches:

Applied to u-boot-marvell/master

Thanks,
Stefan

Quoted 25 lines
---
  drivers/pci/pci-aardvark.c | 7 ++++---
  1 file changed, 4 insertions(+), 3 deletions(-)
drivers/pci/pci-aardvark.c +4 -2
index 96aa039bdc26..77ce9d0c8d87 100644
@@ -609,21 +609,22 @@ static void pcie_advk_set_ob_region(struct pcie_advk *pcie, int *wins,
  	 * match with given mask.
  	 * So every PCIe window size must be a power of two and every start
  	 * address must be aligned to window size. Minimal size is 64 KiB
-	 * because lower 16 bits of mask must be zero.
+	 * because lower 16 bits of mask must be zero. Remapped address
+	 * may have set only bits from the mask.
  	 */
  	while (*wins < OB_WIN_COUNT && size > 0) {
  		/* Calculate the largest aligned window size */
  		win_size = (1ULL << (fls64(size) - 1)) |
  			   (phys_start ? (1ULL << __ffs64(phys_start)) : 0);
  		win_size = 1ULL << __ffs64(win_size);
-		if (win_size < 0x10000)
+		win_mask = ~(win_size - 1);
+		if (win_size < 0x10000 || (bus_start & ~win_mask))

drivers/pci/pci-aardvark.c static void pcie_advk_set_ob_region(struct pcie_advk *pcie, int *wins, · line 630

Quoted 10 lines
drivers/pci/pci-aardvark.c +0 -1
  			break;
 
  		dev_dbg(pcie->dev,
  			"Configuring PCIe window %d: [0x%llx-0x%llx] as 0x%x\n",
  			*wins, (u64)phys_start, (u64)phys_start + win_size,
  			actions);
-		win_mask = ~(win_size - 1) & ~0xffff;
  		pcie_advk_set_ob_win(pcie, *wins, phys_start, bus_start,
  				     win_mask, actions);
 

Viele Grüße,
Stefan

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: [email protected]