* [PATCH v2 1/2] of/unittest: Add empty dma-ranges address translation tests
2024-11-24 10:05 [PATCH v2 0/2] Preserve the flags portion on 1:1 dma-ranges mapping Andrea della Porta
@ 2024-11-24 10:05 ` Andrea della Porta
2024-11-24 10:05 ` [PATCH v2 2/2] of: address: Preserve the flags portion on 1:1 dma-ranges mapping Andrea della Porta
2024-11-27 13:44 ` [PATCH v2 0/2] " Rob Herring
2 siblings, 0 replies; 4+ messages in thread
From: Andrea della Porta @ 2024-11-24 10:05 UTC (permalink / raw)
To: Andrea della Porta, Michael Turquette, Stephen Boyd, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Florian Fainelli,
Broadcom internal kernel review list, Lorenzo Pieralisi,
Krzysztof Wilczynski, Manivannan Sadhasivam, Bjorn Helgaas,
Linus Walleij, Catalin Marinas, Will Deacon, Bartosz Golaszewski,
Derek Kiernan, Dragan Cvetic, Arnd Bergmann, Greg Kroah-Hartman,
Saravana Kannan, linux-clk, devicetree, linux-rpi-kernel,
linux-arm-kernel, linux-kernel, linux-pci, linux-gpio,
Masahiro Yamada, Stefan Wahren, Herve Codina, Luca Ceresoli,
Thomas Petazzoni, Andrew Lunn
Intermediate DT PCI nodes dynamically generated by enabling
CONFIG_PCI_DYNAMIC_OF_NODES have empty dma-ranges property. PCI address
specifiers have 3 cells and when dma-ranges is missing or empty,
of_translate_one() is currently dropping the flag portion of PCI addresses
which are subnodes of the aforementioned ones, failing the translation.
Add new tests covering this case.
With this test, we get 1 new failure which is fixed in subsequent
commit:
FAIL of_unittest_pci_empty_dma_ranges():1245 for_each_of_pci_range wrong CPU addr (ffffffffffffffff) on node /testcase-data/address-tests2/pcie@d1070000/pci@0,0/dev@0,0/local-bus@0
Signed-off-by: Andrea della Porta <andrea.porta@suse.com>
---
drivers/of/unittest-data/tests-address.dtsi | 2 ++
drivers/of/unittest.c | 39 +++++++++++++++++++++
2 files changed, 41 insertions(+)
diff --git a/drivers/of/unittest-data/tests-address.dtsi b/drivers/of/unittest-data/tests-address.dtsi
index 3344f15c3755..f02a181bb125 100644
--- a/drivers/of/unittest-data/tests-address.dtsi
+++ b/drivers/of/unittest-data/tests-address.dtsi
@@ -114,6 +114,7 @@ pcie@d1070000 {
device_type = "pci";
ranges = <0x82000000 0 0xe8000000 0 0xe8000000 0 0x7f00000>,
<0x81000000 0 0x00000000 0 0xefff0000 0 0x0010000>;
+ dma-ranges = <0x43000000 0x10 0x00 0x00 0x00 0x00 0x10000000>;
reg = <0x00000000 0xd1070000 0x20000>;
pci@0,0 {
@@ -142,6 +143,7 @@ local-bus@0 {
#size-cells = <0x01>;
ranges = <0xa0000000 0 0 0 0x2000000>,
<0xb0000000 1 0 0 0x1000000>;
+ dma-ranges = <0xc0000000 0x43000000 0x10 0x00 0x10000000>;
dev@e0000000 {
reg = <0xa0001000 0x1000>,
diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
index daf9a2dddd7e..80483e38d7b4 100644
--- a/drivers/of/unittest.c
+++ b/drivers/of/unittest.c
@@ -1213,6 +1213,44 @@ static void __init of_unittest_pci_dma_ranges(void)
of_node_put(np);
}
+static void __init of_unittest_pci_empty_dma_ranges(void)
+{
+ struct device_node *np;
+ struct of_pci_range range;
+ struct of_pci_range_parser parser;
+
+ if (!IS_ENABLED(CONFIG_PCI))
+ return;
+
+ np = of_find_node_by_path("/testcase-data/address-tests2/pcie@d1070000/pci@0,0/dev@0,0/local-bus@0");
+ if (!np) {
+ pr_err("missing testcase data\n");
+ return;
+ }
+
+ if (of_pci_dma_range_parser_init(&parser, np)) {
+ pr_err("missing dma-ranges property\n");
+ return;
+ }
+
+ /*
+ * Get the dma-ranges from the device tree
+ */
+ for_each_of_pci_range(&parser, &range) {
+ unittest(range.size == 0x10000000,
+ "for_each_of_pci_range wrong size on node %pOF size=%llx\n",
+ np, range.size);
+ unittest(range.cpu_addr == 0x00000000,
+ "for_each_of_pci_range wrong CPU addr (%llx) on node %pOF",
+ range.cpu_addr, np);
+ unittest(range.pci_addr == 0xc0000000,
+ "for_each_of_pci_range wrong DMA addr (%llx) on node %pOF",
+ range.pci_addr, np);
+ }
+
+ of_node_put(np);
+}
+
static void __init of_unittest_bus_ranges(void)
{
struct device_node *np;
@@ -4272,6 +4310,7 @@ static int __init of_unittest(void)
of_unittest_dma_get_max_cpu_address();
of_unittest_parse_dma_ranges();
of_unittest_pci_dma_ranges();
+ of_unittest_pci_empty_dma_ranges();
of_unittest_bus_ranges();
of_unittest_bus_3cell_ranges();
of_unittest_reg();
--
2.35.3
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH v2 2/2] of: address: Preserve the flags portion on 1:1 dma-ranges mapping
2024-11-24 10:05 [PATCH v2 0/2] Preserve the flags portion on 1:1 dma-ranges mapping Andrea della Porta
2024-11-24 10:05 ` [PATCH v2 1/2] of/unittest: Add empty dma-ranges address translation tests Andrea della Porta
@ 2024-11-24 10:05 ` Andrea della Porta
2024-11-27 13:44 ` [PATCH v2 0/2] " Rob Herring
2 siblings, 0 replies; 4+ messages in thread
From: Andrea della Porta @ 2024-11-24 10:05 UTC (permalink / raw)
To: Andrea della Porta, Michael Turquette, Stephen Boyd, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Florian Fainelli,
Broadcom internal kernel review list, Lorenzo Pieralisi,
Krzysztof Wilczynski, Manivannan Sadhasivam, Bjorn Helgaas,
Linus Walleij, Catalin Marinas, Will Deacon, Bartosz Golaszewski,
Derek Kiernan, Dragan Cvetic, Arnd Bergmann, Greg Kroah-Hartman,
Saravana Kannan, linux-clk, devicetree, linux-rpi-kernel,
linux-arm-kernel, linux-kernel, linux-pci, linux-gpio,
Masahiro Yamada, Stefan Wahren, Herve Codina, Luca Ceresoli,
Thomas Petazzoni, Andrew Lunn
Cc: stable
A missing or empty dma-ranges in a DT node implies a 1:1 mapping for dma
translations. In this specific case, the current behaviour is to zero out
the entire specifier so that the translation could be carried on as an
offset from zero. This includes address specifier that has flags (e.g.
PCI ranges).
Once the flags portion has been zeroed, the translation chain is broken
since the mapping functions will check the upcoming address specifier
against mismatching flags, always failing the 1:1 mapping and its entire
purpose of always succeeding.
Set to zero only the address portion while passing the flags through.
Fixes: dbbdee94734b ("of/address: Merge all of the bus translation code")
Cc: stable@vger.kernel.org
Signed-off-by: Andrea della Porta <andrea.porta@suse.com>
Tested-by: Herve Codina <herve.codina@bootlin.com>
---
drivers/of/address.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/of/address.c b/drivers/of/address.c
index 286f0c161e33..b3479586bd4d 100644
--- a/drivers/of/address.c
+++ b/drivers/of/address.c
@@ -455,7 +455,8 @@ static int of_translate_one(struct device_node *parent, struct of_bus *bus,
}
if (ranges == NULL || rlen == 0) {
offset = of_read_number(addr, na);
- memset(addr, 0, pna * 4);
+ /* set address to zero, pass flags through */
+ memset(addr + pbus->flag_cells, 0, (pna - pbus->flag_cells) * 4);
pr_debug("empty ranges; 1:1 translation\n");
goto finish;
}
--
2.35.3
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH v2 0/2] Preserve the flags portion on 1:1 dma-ranges mapping
2024-11-24 10:05 [PATCH v2 0/2] Preserve the flags portion on 1:1 dma-ranges mapping Andrea della Porta
2024-11-24 10:05 ` [PATCH v2 1/2] of/unittest: Add empty dma-ranges address translation tests Andrea della Porta
2024-11-24 10:05 ` [PATCH v2 2/2] of: address: Preserve the flags portion on 1:1 dma-ranges mapping Andrea della Porta
@ 2024-11-27 13:44 ` Rob Herring
2 siblings, 0 replies; 4+ messages in thread
From: Rob Herring @ 2024-11-27 13:44 UTC (permalink / raw)
To: Andrea della Porta
Cc: Michael Turquette, Stephen Boyd, Krzysztof Kozlowski,
Conor Dooley, Florian Fainelli,
Broadcom internal kernel review list, Lorenzo Pieralisi,
Krzysztof Wilczynski, Manivannan Sadhasivam, Bjorn Helgaas,
Linus Walleij, Catalin Marinas, Will Deacon, Bartosz Golaszewski,
Derek Kiernan, Dragan Cvetic, Arnd Bergmann, Greg Kroah-Hartman,
Saravana Kannan, linux-clk, devicetree, linux-rpi-kernel,
linux-arm-kernel, linux-kernel, linux-pci, linux-gpio,
Masahiro Yamada, Stefan Wahren, Herve Codina, Luca Ceresoli,
Thomas Petazzoni, Andrew Lunn
On Sun, Nov 24, 2024 at 11:05:35AM +0100, Andrea della Porta wrote:
> Empty dma-ranges in DT nodes using 3-cell address spcifier cause the
> flag portion to be dropped by of_translate_one(), failing the translation
> chain. This patch aims at fixing this issue.
>
> Part of this patchset was originally preparatory for a bigger patchset
> (see [1]). It has been split in a standalone one for better management
> and because it contains a bugfix which is probably of interest to stable
> branch.
> I've also added new tests to unittest to prove it.
>
> Many thanks,
> Andrea
>
> References:
> [1] - https://lore.kernel.org/all/3029857353c9499659369c1540ba887d7860670f.1730123575.git.andrea.porta@suse.com/
>
>
> Changes in V2:
>
> - Added blank lines between paragraphs in commit message for patch 2
> - Fixed a comment to explain the code behaviour in a straighter way
>
>
> Andrea della Porta (2):
> of/unittest: Add empty dma-ranges address translation tests
> of: address: Preserve the flags portion on 1:1 dma-ranges mapping
>
> drivers/of/address.c | 3 +-
> drivers/of/unittest-data/tests-address.dtsi | 2 ++
> drivers/of/unittest.c | 39 +++++++++++++++++++++
> 3 files changed, 43 insertions(+), 1 deletion(-)
Applied, thanks!
Rob
^ permalink raw reply [flat|nested] 4+ messages in thread