Skip to contentSkip to conversation

pstore/ram: Add support for dynamically allocated ramoops memory regions

PATCH In review Isaac J. Manjarres 7 participants 13 messages Jun 22, 2023 – Jul 6, 2023 Pstore filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pstore/ram: Add support for dynamically allocated ramoops memory regions

From: "Isaac J. Manjarres" <[email protected]>

The reserved memory region for ramoops is assumed to be at a fixed and known location when read from the devicetree. This is not desirable in environments where it is preferred for the region to be dynamically allocated early during boot (i.e. the memory region is defined with the "alloc-ranges" property instead of the "reg" property).

If the location of the ramoops region is not fixed via the "reg" devicetree property, the call to platform_get_resource() will fail because resources of type IORESOURCE_MEM must be described with the "reg" property.

Since ramoops regions are part of the reserved-memory devicetree node, they exist in the reserved_mem array. This means that the of_reserved_mem_lookup() function can be used to retrieve the reserved_mem structure for the ramoops region, and that structure contains the base and size of the region, even if it has been dynamically allocated.

Thus invoke of_reserved_mem_lookup() in case the call to platform_get_resource() fails in order to support dynamically allocated ramoops memory regions.

---
 fs/pstore/ram.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)
fs/pstore/ram.c +14 -5
index ade66dbe5f39..e4bbba187011 100644
@@ -20,6 +20,7 @@
 #include <linux/compiler.h>
 #include <linux/of.h>
 #include <linux/of_address.h>
+#include <linux/of_reserved_mem.h>
 
 #include "internal.h"
 #include "ram_internal.h"
@@ -643,6 +644,7 @@ static int ramoops_parse_dt(struct platform_device *pdev,
 {
 	struct device_node *of_node = pdev->dev.of_node;
 	struct device_node *parent_node;
+	struct reserved_mem *rmem;
 	struct resource *res;
 	u32 value;
 	int ret;
@@ -651,13 +653,20 @@ static int ramoops_parse_dt(struct platform_device *pdev,
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	if (!res) {
-		dev_err(&pdev->dev,
-			"failed to locate DT /reserved-memory resource\n");
-		return -EINVAL;
+		rmem = of_reserved_mem_lookup(of_node);
+		if (rmem) {
+			pdata->mem_size = rmem->size;
+			pdata->mem_address = rmem->base;
+		} else {
+			dev_err(&pdev->dev,
+				"failed to locate DT /reserved-memory resource\n");
+			return -EINVAL;
+		}
+	} else {
+		pdata->mem_size = resource_size(res);
+		pdata->mem_address = res->start;
 	}
 
-	pdata->mem_size = resource_size(res);
-	pdata->mem_address = res->start;
 	/*
 	 * Setting "unbuffered" is deprecated and will be ignored if
 	 * "mem_type" is also specified.
Signature · 1 line
2.41.0.178.g377b9f9a00-goog
#1 lore raw
Quoted 9 lines · Isaac J. Manjarres' via kernel-team

From: "Isaac J. Manjarres" <[email protected]>

The reserved memory region for ramoops is assumed to be at a fixed and known location when read from the devicetree. This is not desirable in environments where it is preferred for the region to be dynamically allocated early during boot (i.e. the memory region is defined with the "alloc-ranges" property instead of the "reg" property).

Thanks for sending this out, Isaac!

Apologies, I've forgotten much of the details around dt bindings here, so forgive my questions:
If the memory is dynamically allocated from a specific range, is it guaranteed to be consistently the same address boot to boot?

Quoted 6 lines

Since ramoops regions are part of the reserved-memory devicetree node, they exist in the reserved_mem array. This means that the of_reserved_mem_lookup() function can be used to retrieve the reserved_mem structure for the ramoops region, and that structure contains the base and size of the region, even if it has been dynamically allocated.

I think this is answering my question above, but it's a little opaque, so I'm not sure.

Quoted 33 lines

Thus invoke of_reserved_mem_lookup() in case the call to platform_get_resource() fails in order to support dynamically allocated ramoops memory regions.

---
 fs/pstore/ram.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)
fs/pstore/ram.c +2 -0
index ade66dbe5f39..e4bbba187011 100644
@@ -20,6 +20,7 @@
 #include <linux/compiler.h>
 #include <linux/of.h>
 #include <linux/of_address.h>
+#include <linux/of_reserved_mem.h>
 
 #include "internal.h"
 #include "ram_internal.h"
@@ -643,6 +644,7 @@ static int ramoops_parse_dt(struct platform_device *pdev,
 {
        struct device_node *of_node = pdev->dev.of_node;
        struct device_node *parent_node;
+       struct reserved_mem *rmem;
        struct resource *res;
        u32 value;
        int ret;

fs/pstore/ram.c static int ramoops_parse_dt(struct platform_device *pdev, · line 656

Quoted 7 lines
fs/pstore/ram.c +1 -3
@@ -651,13 +653,20 @@ static int ramoops_parse_dt(struct platform_device *pdev,
 
        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
        if (!res) {
-               dev_err(&pdev->dev,
-                       "failed to locate DT /reserved-memory resource\n");
-               return -EINVAL;
+               rmem = of_reserved_mem_lookup(of_node);

Nit: you could keep rmem scoped locally here.

Otherwise the code looks sane, I just suspect the commit message could be more clear in explaining the need/utility of the dts entry using alloc-ranges.

thanks
-john

#2 lore raw
Quoted 26 lines · John Stultz
Quoted 9 lines · Isaac J. Manjarres' via kernel-team

From: "Isaac J. Manjarres" <[email protected]>

The reserved memory region for ramoops is assumed to be at a fixed and known location when read from the devicetree. This is not desirable in environments where it is preferred for the region to be dynamically allocated early during boot (i.e. the memory region is defined with the "alloc-ranges" property instead of the "reg" property).

Thanks for sending this out, Isaac!

Apologies, I've forgotten much of the details around dt bindings here, so forgive my questions:
If the memory is dynamically allocated from a specific range, is it guaranteed to be consistently the same address boot to boot?

Quoted 6 lines

Since ramoops regions are part of the reserved-memory devicetree node, they exist in the reserved_mem array. This means that the of_reserved_mem_lookup() function can be used to retrieve the reserved_mem structure for the ramoops region, and that structure contains the base and size of the region, even if it has been dynamically allocated.

Quoted 2 lines

I think this is answering my question above, but it's a little opaque, so I'm not sure.

Yeah, I had exactly the same question: will this be the same boot-to-boot?

Quoted 9 lines
Quoted 9 lines

Thus invoke of_reserved_mem_lookup() in case the call to platform_get_resource() fails in order to support dynamically allocated ramoops memory regions.

I think this should have "Co-developed-by:"s for each person, since this isn't explicitly a S-o-B chain...

Quoted 35 lines
Quoted 25 lines
---
 fs/pstore/ram.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)
fs/pstore/ram.c +2 -0
index ade66dbe5f39..e4bbba187011 100644
@@ -20,6 +20,7 @@
 #include <linux/compiler.h>
 #include <linux/of.h>
 #include <linux/of_address.h>
+#include <linux/of_reserved_mem.h>
 
 #include "internal.h"
 #include "ram_internal.h"
@@ -643,6 +644,7 @@ static int ramoops_parse_dt(struct platform_device *pdev,
 {
        struct device_node *of_node = pdev->dev.of_node;
        struct device_node *parent_node;
+       struct reserved_mem *rmem;
        struct resource *res;
        u32 value;
        int ret;

fs/pstore/ram.c static int ramoops_parse_dt(struct platform_device *pdev, · line 656

Quoted 7 lines
fs/pstore/ram.c +1 -3
@@ -651,13 +653,20 @@ static int ramoops_parse_dt(struct platform_device *pdev,
 
        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
        if (!res) {
-               dev_err(&pdev->dev,
-                       "failed to locate DT /reserved-memory resource\n");
-               return -EINVAL;
+               rmem = of_reserved_mem_lookup(of_node);

Nit: you could keep rmem scoped locally here.

Quoted 3 lines

Otherwise the code looks sane, I just suspect the commit message could be more clear in explaining the need/utility of the dts entry using alloc-ranges.

I haven't looked closely at the API here, but does this need a "put" like the "get" stuff? (I assume not, given the "lookup" is on a node...)

-Kees

Signature · 1 line
Kees Cook
#3 lore raw
Quoted 22 lines · Kees Cook
Quoted 21 lines · John Stultz
Quoted 6 lines

The reserved memory region for ramoops is assumed to be at a fixed and known location when read from the devicetree. This is not desirable in environments where it is preferred for the region to be dynamically allocated early during boot (i.e. the memory region is defined with the "alloc-ranges" property instead of the "reg" property).

Thanks for sending this out, Isaac!

Apologies, I've forgotten much of the details around dt bindings here, so forgive my questions:
If the memory is dynamically allocated from a specific range, is it guaranteed to be consistently the same address boot to boot?

Quoted 6 lines

Since ramoops regions are part of the reserved-memory devicetree node, they exist in the reserved_mem array. This means that the of_reserved_mem_lookup() function can be used to retrieve the reserved_mem structure for the ramoops region, and that structure contains the base and size of the region, even if it has been dynamically allocated.

Quoted 5 lines
Quoted 2 lines

I think this is answering my question above, but it's a little opaque, so I'm not sure.

Yeah, I had exactly the same question: will this be the same boot-to-boot?

Hi Kees,

Thank you for taking a look at this patch and for your review! When the alloc-ranges property is used to describe a memory region, the memory region will always be allocated within that range, but it's not guaranteed to be allocated at the same base address across reboots.

I had proposed re-wording the end of the commit message in my response to John as follows:

"...and that structure contains the address of the base of the region that was allocated at boot anywhere within the range specified by the "alloc-ranges" devicetree property."

Does that clarify things better?

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Thus invoke of_reserved_mem_lookup() in case the call to platform_get_resource() fails in order to support dynamically allocated ramoops memory regions.

Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

I think this should have "Co-developed-by:"s for each person, since this isn't explicitly a S-o-B chain...

Noted. I'll fix this up for v2 of the patch.

Quoted 19 lines
Quoted 19 lines
Quoted 9 lines
fs/pstore/ram.c +1 -0
@@ -643,6 +644,7 @@ static int ramoops_parse_dt(struct platform_device *pdev,
 {
        struct device_node *of_node = pdev->dev.of_node;
        struct device_node *parent_node;
+       struct reserved_mem *rmem;
        struct resource *res;
        u32 value;
        int ret;

fs/pstore/ram.c static int ramoops_parse_dt(struct platform_device *pdev, · line 656

Quoted 7 lines
fs/pstore/ram.c +1 -3
@@ -651,13 +653,20 @@ static int ramoops_parse_dt(struct platform_device *pdev,
 
        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
        if (!res) {
-               dev_err(&pdev->dev,
-                       "failed to locate DT /reserved-memory resource\n");
-               return -EINVAL;
+               rmem = of_reserved_mem_lookup(of_node);

Nit: you could keep rmem scoped locally here.

Quoted 6 lines
Quoted 3 lines

Otherwise the code looks sane, I just suspect the commit message could be more clear in explaining the need/utility of the dts entry using alloc-ranges.

I haven't looked closely at the API here, but does this need a "put" like the "get" stuff? (I assume not, given the "lookup" is on a node...)

No, it doesn't need a put, since of_reserved_mem_lookup() doesn't acquire a reference to anything.

Thanks,
Isaac

maintainer
#4 lore raw
Quoted 36 lines · Isaac Manjarres
Quoted 22 lines · Kees Cook
Quoted 21 lines · John Stultz
Quoted 6 lines

The reserved memory region for ramoops is assumed to be at a fixed and known location when read from the devicetree. This is not desirable in environments where it is preferred for the region to be dynamically allocated early during boot (i.e. the memory region is defined with the "alloc-ranges" property instead of the "reg" property).

Thanks for sending this out, Isaac!

Apologies, I've forgotten much of the details around dt bindings here, so forgive my questions:
If the memory is dynamically allocated from a specific range, is it guaranteed to be consistently the same address boot to boot?

Quoted 6 lines

Since ramoops regions are part of the reserved-memory devicetree node, they exist in the reserved_mem array. This means that the of_reserved_mem_lookup() function can be used to retrieve the reserved_mem structure for the ramoops region, and that structure contains the base and size of the region, even if it has been dynamically allocated.

Quoted 5 lines
Quoted 2 lines

I think this is answering my question above, but it's a little opaque, so I'm not sure.

Yeah, I had exactly the same question: will this be the same boot-to-boot?

Hi Kees,

Thank you for taking a look at this patch and for your review! When the alloc-ranges property is used to describe a memory region, the memory region will always be allocated within that range, but it's not guaranteed to be allocated at the same base address across reboots.

Quoted 8 lines

I had proposed re-wording the end of the commit message in my response to John as follows:

"...and that structure contains the address of the base of the region that was allocated at boot anywhere within the range specified by the "alloc-ranges" devicetree property."

Does that clarify things better?

I am probably misunderstanding something still, but it it varies from boot to boot, what utility is there for pstore if it changes? I.e. the things written during the last boot would then no longer accessible at the next boot? E.g.:

Boot 1.
Get address Foo.
Crash, write to Foo.
Boot 2.
Get address Bar, different from Foo.
Nothing found at Bar, so nothing populated in pstorefs; crash report from Boot 1 unavailable.

I feel like there is something I don't understand about the Foo/Bar addresses in my example.

-Kees

Signature · 1 line
Kees Cook
#5 lore raw
Quoted 48 lines · Kees Cook
Quoted 36 lines · Isaac Manjarres
Quoted 22 lines · Kees Cook
Quoted 21 lines · John Stultz
Quoted 6 lines

The reserved memory region for ramoops is assumed to be at a fixed and known location when read from the devicetree. This is not desirable in environments where it is preferred for the region to be dynamically allocated early during boot (i.e. the memory region is defined with the "alloc-ranges" property instead of the "reg" property).

Thanks for sending this out, Isaac!

Apologies, I've forgotten much of the details around dt bindings here, so forgive my questions:
If the memory is dynamically allocated from a specific range, is it guaranteed to be consistently the same address boot to boot?

Quoted 6 lines

Since ramoops regions are part of the reserved-memory devicetree node, they exist in the reserved_mem array. This means that the of_reserved_mem_lookup() function can be used to retrieve the reserved_mem structure for the ramoops region, and that structure contains the base and size of the region, even if it has been dynamically allocated.

Quoted 5 lines
Quoted 2 lines

I think this is answering my question above, but it's a little opaque, so I'm not sure.

Yeah, I had exactly the same question: will this be the same boot-to-boot?

Hi Kees,

Thank you for taking a look at this patch and for your review! When the alloc-ranges property is used to describe a memory region, the memory region will always be allocated within that range, but it's not guaranteed to be allocated at the same base address across reboots.

Quoted 8 lines

I had proposed re-wording the end of the commit message in my response to John as follows:

"...and that structure contains the address of the base of the region that was allocated at boot anywhere within the range specified by the "alloc-ranges" devicetree property."

Does that clarify things better?

I am probably misunderstanding something still, but it it varies from boot to boot, what utility is there for pstore if it changes? I.e. the things written during the last boot would then no longer accessible at the next boot? E.g.:

Quoted 9 lines

Boot 1.
Get address Foo.
Crash, write to Foo.
Boot 2.
Get address Bar, different from Foo.
Nothing found at Bar, so nothing populated in pstorefs; crash report from Boot 1 unavailable.

I feel like there is something I don't understand about the Foo/Bar addresses in my example.

I believe this is being added to support the QCOM SoC minidump feature. Mukesh has posted it on the mailing lists here:

https://lore.kernel.org/all/[email protected]/

https://lore.kernel.org/all/[email protected]/

Mukesh, could you comment whether this patch is wanted for us in the version you have posted? It looks like maybe not based on the commit text in patch #9.

- Elliot

#6 lore raw
Quoted 61 lines · Elliot Berman
Quoted 48 lines · Kees Cook
Quoted 36 lines · Isaac Manjarres
Quoted 22 lines · Kees Cook
Quoted 21 lines · John Stultz
Quoted 6 lines

The reserved memory region for ramoops is assumed to be at a fixed and known location when read from the devicetree. This is not desirable in environments where it is preferred for the region to be dynamically allocated early during boot (i.e. the memory region is defined with the "alloc-ranges" property instead of the "reg" property).

Thanks for sending this out, Isaac!

Apologies, I've forgotten much of the details around dt bindings here, so forgive my questions:
If the memory is dynamically allocated from a specific range, is it guaranteed to be consistently the same address boot to boot?

Quoted 6 lines

Since ramoops regions are part of the reserved-memory devicetree node, they exist in the reserved_mem array. This means that the of_reserved_mem_lookup() function can be used to retrieve the reserved_mem structure for the ramoops region, and that structure contains the base and size of the region, even if it has been dynamically allocated.

Quoted 5 lines
Quoted 2 lines

I think this is answering my question above, but it's a little opaque, so I'm not sure.

Yeah, I had exactly the same question: will this be the same boot-to-boot?

Hi Kees,

Thank you for taking a look at this patch and for your review! When the alloc-ranges property is used to describe a memory region, the memory region will always be allocated within that range, but it's not guaranteed to be allocated at the same base address across reboots.

Quoted 8 lines

I had proposed re-wording the end of the commit message in my response to John as follows:

"...and that structure contains the address of the base of the region that was allocated at boot anywhere within the range specified by the "alloc-ranges" devicetree property."

Does that clarify things better?

I am probably misunderstanding something still, but it it varies from boot to boot, what utility is there for pstore if it changes? I.e. the things written during the last boot would then no longer accessible at the next boot? E.g.:

Quoted 9 lines

Boot 1.
Get address Foo.
Crash, write to Foo.
Boot 2.
Get address Bar, different from Foo.
Nothing found at Bar, so nothing populated in pstorefs; crash report from Boot 1 unavailable.

I feel like there is something I don't understand about the Foo/Bar addresses in my example.

Quoted 7 lines

I believe this is being added to support the QCOM SoC minidump feature. Mukesh has posted it on the mailing lists here:

https://lore.kernel.org/all/[email protected]/

https://lore.kernel.org/all/[email protected]/

Mukesh, could you comment whether this patch is wanted for us in the version you have posted? It looks like maybe not based on the commit text in patch #9.

No, this is no needed after patch #9 .

I have tried multiple attempt already to get this patch in

https://lore.kernel.org/lkml/[email protected]/

later tried the approach of patch #9 along with minidump series..

- Mukesh

Quoted 2 lines

 - Elliot

#7 lore raw
Quoted 83 lines · Mukesh Ojha
Quoted 72 lines · Elliot Berman
Quoted 62 lines · Kees Cook
Quoted 38 lines · Isaac Manjarres
Quoted 24 lines · Kees Cook
Quoted 23 lines · John Stultz
Quoted 8 lines

The reserved memory region for ramoops is assumed to be at a fixed and known location when read from the devicetree. This is not desirable
in environments where it is preferred for the region to be dynamically
allocated early during boot (i.e. the memory region is defined with the "alloc-ranges" property instead of the "reg" property).

Thanks for sending this out, Isaac!

Apologies, I've forgotten much of the details around dt bindings here, so forgive my questions:
If the memory is dynamically allocated from a specific range, is it guaranteed to be consistently the same address boot to boot?

Quoted 6 lines

Since ramoops regions are part of the reserved-memory devicetree node, they exist in the reserved_mem array. This means that the of_reserved_mem_lookup() function can be used to retrieve the reserved_mem structure for the ramoops region, and that structure contains the base and size of the region, even if it has been dynamically allocated.

Quoted 5 lines
Quoted 2 lines

I think this is answering my question above, but it's a little opaque, so I'm not sure.

Yeah, I had exactly the same question: will this be the same boot-to-boot?

Hi Kees,

Thank you for taking a look at this patch and for your review! When the alloc-ranges property is used to describe a memory region, the memory region will always be allocated within that range, but it's not guaranteed to be allocated at the same base address across reboots.

Quoted 8 lines

I had proposed re-wording the end of the commit message in my response to John as follows:

"...and that structure contains the address of the base of the region that was allocated at boot anywhere within the range specified by the "alloc-ranges" devicetree property."

Does that clarify things better?

I am probably misunderstanding something still, but it it varies from boot to boot, what utility is there for pstore if it changes? I.e. the things written during the last boot would then no longer accessible at the next boot? E.g.:

Boot 1.
Get address Foo.
Crash, write to Foo.
Boot 2.
Get address Bar, different from Foo.
Nothing found at Bar, so nothing populated in pstorefs; crash report from Boot 1 unavailable.

Quoted 3 lines

I feel like there is something I don't understand about the Foo/Bar addresses in my example.

I believe this is being added to support the QCOM SoC minidump feature. Mukesh has posted it on the mailing lists here:

Quoted 7 lines

https://lore.kernel.org/all/[email protected]/

https://lore.kernel.org/all/[email protected]/

Mukesh, could you comment whether this patch is wanted for us in the version you have posted? It looks like maybe not based on the commit text in patch #9.

Quoted 7 lines

No, this is no needed after patch #9 .

I have tried multiple attempt already to get this patch in

https://lore.kernel.org/lkml/[email protected]/

later tried the approach of patch #9 along with minidump series..

For all dynamic reserved-memory-ramoops thingy, I think Rob made clear statement:

"I don't think dynamic ramoops location should be defined in DT."

https://lore.kernel.org/lkml/CAL_JsqKV6EEpsDNdj1BTN6nODb=hsHkzsdkCzzWwnTrygn0K-A@mail.gmail.com/

Please do not send three versions of the same patch hoping one will sneak in.

Best regards,
Krzysztof

#8 lore raw
Quoted 10 lines · Krzysztof Kozlowski
Quoted 5 lines · Mukesh Ojha

I have tried multiple attempt already to get this patch in

https://lore.kernel.org/lkml/[email protected]/

later tried the approach of patch #9 along with minidump series..

For all dynamic reserved-memory-ramoops thingy, I think Rob made clear statement:

Quoted 6 lines

"I don't think dynamic ramoops location should be defined in DT."

https://lore.kernel.org/lkml/CAL_JsqKV6EEpsDNdj1BTN6nODb=hsHkzsdkCzzWwnTrygn0K-A@mail.gmail.com/

Please do not send three versions of the same patch hoping one will sneak in.

If I understand correctly, the driving issue here is that minidump wants to be able to find the crash report "externally". Perhaps pstore could provide either a known symbol that contains the address that was used, or could add something to the kernel crash image (like is done for KASLR), so that an external consumer of the kernel crash image could find it?

And then the RAM backend for pstore could gain an option for "just allocate regular RAM" for holding the dump? In other words, the address is chosen by pstore, but an external consumer could still locate it.

-Kees

Signature · 1 line
Kees Cook
#9 lore raw
Quoted 25 lines · Kees Cook
Quoted 10 lines · Krzysztof Kozlowski
Quoted 5 lines · Mukesh Ojha

I have tried multiple attempt already to get this patch in

https://lore.kernel.org/lkml/[email protected]/

later tried the approach of patch #9 along with minidump series..

For all dynamic reserved-memory-ramoops thingy, I think Rob made clear statement:

Quoted 6 lines

"I don't think dynamic ramoops location should be defined in DT."

https://lore.kernel.org/lkml/CAL_JsqKV6EEpsDNdj1BTN6nODb=hsHkzsdkCzzWwnTrygn0K-A@mail.gmail.com/

Please do not send three versions of the same patch hoping one will sneak in.

If I understand correctly, the driving issue here is that minidump wants to be able to find the crash report "externally". Perhaps pstore could provide either a known symbol that contains the address that was used, or could add something to the kernel crash image (like is done for KASLR), so that an external consumer of the kernel crash image could find it?

Quoted 3 lines

And then the RAM backend for pstore could gain an option for "just allocate regular RAM" for holding the dump? In other words, the address is chosen by pstore, but an external consumer could still locate it.

Yes, in-short, it wants RAM backend (fs/pstore/ram.c) to use regular ram instead of fixed ram address range and at the same time it should be able to query the address used.

So, registering with minidump is what telling upfront what address range content would we be getting in final crash dump.

-Mukesh

Quoted 3 lines

-Kees

#10 lore raw
In reply to Elliot Berman
Quoted 10 lines · Elliot Berman
Quoted 9 lines

Boot 1.
Get address Foo.
Crash, write to Foo.
Boot 2.
Get address Bar, different from Foo.
Nothing found at Bar, so nothing populated in pstorefs; crash report from Boot 1 unavailable.

I feel like there is something I don't understand about the Foo/Bar addresses in my example.

Quoted 6 lines

I believe this is being added to support the QCOM SoC minidump feature. Mukesh has posted it on the mailing lists here:

https://lore.kernel.org/all/[email protected]/

https://lore.kernel.org/all/[email protected]/

And since this is coming bypassing DT maintainers and clearly against Rob's feedback so far, that's a no.

Quoted 4 lines

Mukesh, could you comment whether this patch is wanted for us in the version you have posted? It looks like maybe not based on the commit text in patch #9.

Best regards,
Krzysztof

#11 lore raw
In reply to John Stultz
Quoted 7 lines · John Stultz
Quoted 6 lines

The reserved memory region for ramoops is assumed to be at a fixed and known location when read from the devicetree. This is not desirable in environments where it is preferred for the region to be dynamically allocated early during boot (i.e. the memory region is defined with the "alloc-ranges" property instead of the "reg" property).

Quoted 6 lines

Thanks for sending this out, Isaac!

Apologies, I've forgotten much of the details around dt bindings here, so forgive my questions:
If the memory is dynamically allocated from a specific range, is it guaranteed to be consistently the same address boot to boot?

Hi John,

Thanks for reviewing this patch! When you use the "alloc-ranges" property, you specify a range for the memory region to reside in. This means that the region will lie somewhere in between the range you specified, but it is not guaranteed to be in the same location across reboots.

Quoted 9 lines
Quoted 6 lines

Since ramoops regions are part of the reserved-memory devicetree node, they exist in the reserved_mem array. This means that the of_reserved_mem_lookup() function can be used to retrieve the reserved_mem structure for the ramoops region, and that structure contains the base and size of the region, even if it has been dynamically allocated.

I think this is answering my question above, but it's a little opaque, so I'm not sure.

How about re-wording the end as such?

"...and that structure contains the address of the base of the region that was allocated at boot anywhere within the range specified by the "alloc-ranges" devicetree property."

Quoted 10 lines
Quoted 10 lines
fs/pstore/ram.c +1 -0
@@ -643,6 +644,7 @@ static int ramoops_parse_dt(struct platform_device *pdev,
 {
        struct device_node *of_node = pdev->dev.of_node;
        struct device_node *parent_node;
+       struct reserved_mem *rmem;
        struct resource *res;
        u32 value;
        int ret;
@@ -651,13 +653,20 @@ static int ramoops_parse_dt(struct platform_device *pdev,
 
Quoted 8 lines

fs/pstore/ram.c static int ramoops_parse_dt(struct platform_device *pdev, · line 656

Quoted 6 lines
fs/pstore/ram.c +1 -3
        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
        if (!res) {
-               dev_err(&pdev->dev,
-                       "failed to locate DT /reserved-memory resource\n");
-               return -EINVAL;
+               rmem = of_reserved_mem_lookup(of_node);

Nit: you could keep rmem scoped locally here.

Noted! Thanks for the feedback.

Quoted 3 lines

Otherwise the code looks sane, I just suspect the commit message could be more clear in explaining the need/utility of the dts entry using alloc-ranges.

Got it; please let me know if the edit I suggested earlier clarifies things.

Thanks,
Isaac

#12 lore raw
In reply to Isaac J. Manjarres
Quoted 20 lines · Isaac J. Manjarres

From: "Isaac J. Manjarres" <[email protected]>

The reserved memory region for ramoops is assumed to be at a fixed and known location when read from the devicetree. This is not desirable in environments where it is preferred for the region to be dynamically allocated early during boot (i.e. the memory region is defined with the "alloc-ranges" property instead of the "reg" property).

If the location of the ramoops region is not fixed via the "reg" devicetree property, the call to platform_get_resource() will fail because resources of type IORESOURCE_MEM must be described with the "reg" property.

Since ramoops regions are part of the reserved-memory devicetree node, they exist in the reserved_mem array. This means that the of_reserved_mem_lookup() function can be used to retrieve the reserved_mem structure for the ramoops region, and that structure contains the base and size of the region, even if it has been dynamically allocated.

Quoted 3 lines

Thus invoke of_reserved_mem_lookup() in case the call to platform_get_resource() fails in order to support dynamically allocated ramoops memory regions.

You missed change to Devicetree binding, so the reg is still required for all DT-based platforms. For such, this patch is just half-baked.

You also did not CC DT maintainers, which would be nice considering some improper advises for minidump like here:
https://lore.kernel.org/lkml/[email protected]/

DT is not for some dynamically allocated properties or dynamic system configuration. You don't need DT for that. Therefore if you remove the reg, I question the entire point of this binding.

See also:
https://lore.kernel.org/lkml/CAL_JsqJ_TTnGjjB2d8_FKHpWBRG5GHLoWnabCKjsdeZ4QFdNEg@mail.gmail.com/

https://lore.kernel.org/lkml/[email protected]/

Best regards,
Krzysztof