Skip to contentSkip to conversation

powerpc/of: split out new_property() for reusing

PATCH Superseded Pingfan Liu 5 participants 12 messages Feb 28, 2020 – Mar 16, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 powerpc/of: split out new_property() for reusing

Splitting out new_property() for coming reusing and moving it to of_helpers.c.

Also do some coding style cleanup.

To: [email protected]
Cc: Benjamin Herrenschmidt <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Michael Ellerman <[email protected]>
Cc: Hari Bathini <[email protected]>
Cc: Aneesh Kumar K.V <[email protected]>
Cc: Oliver O'Halloran <[email protected]>
Cc: Dan Williams <[email protected]>
Cc: Andrew Donnellan <[email protected]>
Cc: Christophe Leroy <[email protected]>
Cc: [email protected]

---
 arch/powerpc/platforms/pseries/of_helpers.c | 28 ++++++++++++++++++++++++++++
 arch/powerpc/platforms/pseries/of_helpers.h |  3 +++
 arch/powerpc/platforms/pseries/reconfig.c   | 26 --------------------------
 3 files changed, 31 insertions(+), 26 deletions(-)
arch/powerpc/platforms/pseries/of_helpers.c +28 -0
index 66dfd82..1022e0f 100644
@@ -7,6 +7,34 @@
 
 #include "of_helpers.h"
 
+struct property *new_property(const char *name, const int length,
+		const unsigned char *value, struct property *last)
+{
+	struct property *new = kzalloc(sizeof(*new), GFP_KERNEL);
+
+	if (!new)
+		return NULL;
+
+	new->name = kstrdup(name, GFP_KERNEL);
+	if (!new->name)
+		goto cleanup;
+	new->value = kmalloc(length + 1, GFP_KERNEL);
+	if (!new->value)
+		goto cleanup;
+
+	memcpy(new->value, value, length);
+	*(((char *)new->value) + length) = 0;
+	new->length = length;
+	new->next = last;
+	return new;
+
+cleanup:
+	kfree(new->name);
+	kfree(new->value);
+	kfree(new);
+	return NULL;
+}
+
 /**
  * pseries_of_derive_parent - basically like dirname(1)
  * @path:  the full_name of a node to be added to the tree
arch/powerpc/platforms/pseries/of_helpers.h +3 -0
index decad65..34add82 100644
@@ -4,6 +4,9 @@
 
 #include <linux/of.h>
 
+struct property *new_property(const char *name, const int length,
+		const unsigned char *value, struct property *last);
+
 struct device_node *pseries_of_derive_parent(const char *path);
 
 #endif /* _PSERIES_OF_HELPERS_H */
arch/powerpc/platforms/pseries/reconfig.c +0 -26
index 7f7369f..8e5a2ba 100644
@@ -165,32 +165,6 @@ static char * parse_next_property(char *buf, char *end, char **name, int *length
 	return tmp;
 }
 
-static struct property *new_property(const char *name, const int length,
-				     const unsigned char *value, struct property *last)
-{
-	struct property *new = kzalloc(sizeof(*new), GFP_KERNEL);
-
-	if (!new)
-		return NULL;
-
-	if (!(new->name = kstrdup(name, GFP_KERNEL)))
-		goto cleanup;
-	if (!(new->value = kmalloc(length + 1, GFP_KERNEL)))
-		goto cleanup;
-
-	memcpy(new->value, value, length);
-	*(((char *)new->value) + length) = 0;
-	new->length = length;
-	new->next = last;
-	return new;
-
-cleanup:
-	kfree(new->name);
-	kfree(new->value);
-	kfree(new);
-	return NULL;
-}
-
 static int do_add_node(char *buf, size_t bufsize)
 {
 	char *path, *end, *name;
Signature · 1 line
2.7.5
#1 lore raw

PATCH v2 2/2 pSeries/papr_scm: buffer pmem's bound addr in dt for kexec kernel

At present, plpar_hcall(H_SCM_BIND_MEM, ...) takes a very long time, so if dumping to fsdax, it will take a very long time.

Take a closer look, during the papr_scm initialization, the only configuration is through drc_pmem_bind()-> plpar_hcall(H_SCM_BIND_MEM, ...), which helps to set up the bound address.

On pseries, for kexec -l/-p kernel, there is no reset of hardware, and this step can be stepped around to save times. So the pmem bound address can be passed to the 2nd kernel through a dynamic added property "bound-addr" in dt node 'ibm,pmemory'.

To: [email protected]
Cc: Benjamin Herrenschmidt <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Michael Ellerman <[email protected]>
Cc: Hari Bathini <[email protected]>
Cc: Aneesh Kumar K.V <[email protected]>
Cc: Oliver O'Halloran <[email protected]>
Cc: Dan Williams <[email protected]>
Cc: Andrew Donnellan <[email protected]>
Cc: Christophe Leroy <[email protected]>
Cc: [email protected]
---
note: This patch has not been tested since I can not get such a pseries with pmem.
Please kindly to give some suggestion, thanks.

 arch/powerpc/platforms/pseries/papr_scm.c | 32 +++++++++++++++++++++----------
 1 file changed, 22 insertions(+), 10 deletions(-)
arch/powerpc/platforms/pseries/papr_scm.c +22 -10
index 0b4467e..40cd214 100644
@@ -14,6 +14,7 @@
 #include <linux/delay.h>
 
 #include <asm/plpar_wrappers.h>
+#include "of_helpers.h"
 
 #define BIND_ANY_ADDR (~0ul)
 
@@ -383,7 +384,7 @@ static int papr_scm_probe(struct platform_device *pdev)
 {
 	struct device_node *dn = pdev->dev.of_node;
 	u32 drc_index, metadata_size;
-	u64 blocks, block_size;
+	u64 blocks, block_size, bound_addr = 0;
 	struct papr_scm_priv *p;
 	const char *uuid_str;
 	u64 uuid[2];
@@ -440,17 +441,28 @@ static int papr_scm_probe(struct platform_device *pdev)
 	p->metadata_size = metadata_size;
 	p->pdev = pdev;
 
-	/* request the hypervisor to bind this region to somewhere in memory */
-	rc = drc_pmem_bind(p);
+	of_property_read_u64(dn, "bound-addr", &bound_addr);
+	if (bound_addr) {
+		p->bound_addr = bound_addr;
+	} else {
+		struct property *property;
+		u64 big;
 
-	/* If phyp says drc memory still bound then force unbound and retry */
-	if (rc == H_OVERLAP)
-		rc = drc_pmem_query_n_bind(p);
+		/* request the hypervisor to bind this region to somewhere in memory */
+		rc = drc_pmem_bind(p);
 
-	if (rc != H_SUCCESS) {
-		dev_err(&p->pdev->dev, "bind err: %d\n", rc);
-		rc = -ENXIO;
-		goto err;
+		/* If phyp says drc memory still bound then force unbound and retry */
+		if (rc == H_OVERLAP)
+			rc = drc_pmem_query_n_bind(p);
+
+		if (rc != H_SUCCESS) {
+			dev_err(&p->pdev->dev, "bind err: %d\n", rc);
+			rc = -ENXIO;
+			goto err;
+		}
+		big = cpu_to_be64(p->bound_addr);
+		property = new_property("bound-addr", sizeof(u64), &big, NULL);
+		of_add_property(dn, property);
 	}
 
 	/* setup the resource for the newly bound range */
Signature · 1 line
2.7.5
#2 lore raw

v3 cover pseries/scm: buffer pmem's bound addr in dt for kexec kernel

In reply to Pingfan Liu

V2 -> V3:
in [2/2], EXPORT_SYMBOL(new_property) and EXPORT_SYMBOL_GPL(of_add_property)

To: [email protected]
Cc: Benjamin Herrenschmidt <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Michael Ellerman <[email protected]>
Cc: Hari Bathini <[email protected]>
Cc: Aneesh Kumar K.V <[email protected]>
Cc: Oliver O'Halloran <[email protected]>
Cc: Dan Williams <[email protected]>
Cc: Andrew Donnellan <[email protected]>
Cc: Christophe Leroy <[email protected]>
Cc: Rob Herring <[email protected]>
Cc: Frank Rowand <[email protected]>
Cc: [email protected]

Pingfan Liu (2):
powerpc/of: split out new_property() for reusing pseries/scm: buffer pmem's bound addr in dt for kexec kernel

 arch/powerpc/platforms/pseries/of_helpers.c | 29 +++++++++++++++++++++++++
 arch/powerpc/platforms/pseries/of_helpers.h |  3 +++
 arch/powerpc/platforms/pseries/papr_scm.c   | 33 ++++++++++++++++++++---------
 arch/powerpc/platforms/pseries/reconfig.c   | 26 -----------------------
 drivers/of/base.c                           |  1 +
 5 files changed, 56 insertions(+), 36 deletions(-)
Signature · 1 line
2.7.5
#3 lore raw

PATCH v3 1/2 powerpc/of: split out new_property() for reusing

Splitting out new_property() for coming reusing and moving it to of_helpers.c.

Also do some coding style cleanup.

To: [email protected]
Cc: Benjamin Herrenschmidt <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Michael Ellerman <[email protected]>
Cc: Hari Bathini <[email protected]>
Cc: Aneesh Kumar K.V <[email protected]>
Cc: Oliver O'Halloran <[email protected]>
Cc: Dan Williams <[email protected]>
Cc: Andrew Donnellan <[email protected]>
Cc: Christophe Leroy <[email protected]>
Cc: Rob Herring <[email protected]>
Cc: Frank Rowand <[email protected]>
Cc: [email protected]

---
 arch/powerpc/platforms/pseries/of_helpers.c | 28 ++++++++++++++++++++++++++++
 arch/powerpc/platforms/pseries/of_helpers.h |  3 +++
 arch/powerpc/platforms/pseries/reconfig.c   | 26 --------------------------
 3 files changed, 31 insertions(+), 26 deletions(-)
arch/powerpc/platforms/pseries/of_helpers.c +28 -0
index 66dfd82..1022e0f 100644
@@ -7,6 +7,34 @@
 
 #include "of_helpers.h"
 
+struct property *new_property(const char *name, const int length,
+		const unsigned char *value, struct property *last)
+{
+	struct property *new = kzalloc(sizeof(*new), GFP_KERNEL);
+
+	if (!new)
+		return NULL;
+
+	new->name = kstrdup(name, GFP_KERNEL);
+	if (!new->name)
+		goto cleanup;
+	new->value = kmalloc(length + 1, GFP_KERNEL);
+	if (!new->value)
+		goto cleanup;
+
+	memcpy(new->value, value, length);
+	*(((char *)new->value) + length) = 0;
+	new->length = length;
+	new->next = last;
+	return new;
+
+cleanup:
+	kfree(new->name);
+	kfree(new->value);
+	kfree(new);
+	return NULL;
+}
+
 /**
  * pseries_of_derive_parent - basically like dirname(1)
  * @path:  the full_name of a node to be added to the tree
arch/powerpc/platforms/pseries/of_helpers.h +3 -0
index decad65..34add82 100644
@@ -4,6 +4,9 @@
 
 #include <linux/of.h>
 
+struct property *new_property(const char *name, const int length,
+		const unsigned char *value, struct property *last);
+
 struct device_node *pseries_of_derive_parent(const char *path);
 
 #endif /* _PSERIES_OF_HELPERS_H */
arch/powerpc/platforms/pseries/reconfig.c +0 -26
index 7f7369f..8e5a2ba 100644
@@ -165,32 +165,6 @@ static char * parse_next_property(char *buf, char *end, char **name, int *length
 	return tmp;
 }
 
-static struct property *new_property(const char *name, const int length,
-				     const unsigned char *value, struct property *last)
-{
-	struct property *new = kzalloc(sizeof(*new), GFP_KERNEL);
-
-	if (!new)
-		return NULL;
-
-	if (!(new->name = kstrdup(name, GFP_KERNEL)))
-		goto cleanup;
-	if (!(new->value = kmalloc(length + 1, GFP_KERNEL)))
-		goto cleanup;
-
-	memcpy(new->value, value, length);
-	*(((char *)new->value) + length) = 0;
-	new->length = length;
-	new->next = last;
-	return new;
-
-cleanup:
-	kfree(new->name);
-	kfree(new->value);
-	kfree(new);
-	return NULL;
-}
-
 static int do_add_node(char *buf, size_t bufsize)
 {
 	char *path, *end, *name;
Signature · 1 line
2.7.5
#7 lore raw

PATCH v3 2/2 pseries/scm: buffer pmem's bound addr in dt for kexec kernel

In reply to Pingfan Liu

At present, plpar_hcall(H_SCM_BIND_MEM, ...) takes a very long time, so if dumping to fsdax, it will take a very long time.

Take a closer look, during the papr_scm initialization, the only configuration is through drc_pmem_bind()-> plpar_hcall(H_SCM_BIND_MEM, ...), which helps to set up the bound address.

On pseries, for kexec -l/-p kernel, there is no reset of hardware, and this step can be stepped around to save times. So the pmem bound address can be passed to the 2nd kernel through a dynamic added property "bound-addr" in dt node 'ibm,pmemory'.

To: [email protected]
Cc: Benjamin Herrenschmidt <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Michael Ellerman <[email protected]>
Cc: Hari Bathini <[email protected]>
Cc: Aneesh Kumar K.V <[email protected]>
Cc: Oliver O'Halloran <[email protected]>
Cc: Dan Williams <[email protected]>
Cc: Andrew Donnellan <[email protected]>
Cc: Christophe Leroy <[email protected]>
Cc: Rob Herring <[email protected]>
Cc: Frank Rowand <[email protected]>
Cc: [email protected]
---
note: This patch has not been tested since I can not get such a pseries with pmem.
Please kindly to give some suggestion, thanks.

---
 arch/powerpc/platforms/pseries/of_helpers.c |  1 +
 arch/powerpc/platforms/pseries/papr_scm.c   | 33 ++++++++++++++++++++---------
 drivers/of/base.c                           |  1 +
 3 files changed, 25 insertions(+), 10 deletions(-)
arch/powerpc/platforms/pseries/of_helpers.c +1 -0
index 1022e0f..2c7bab4 100644
@@ -34,6 +34,7 @@ struct property *new_property(const char *name, const int length,
 	kfree(new);
 	return NULL;
 }
+EXPORT_SYMBOL(new_property);
 
 /**
  * pseries_of_derive_parent - basically like dirname(1)
arch/powerpc/platforms/pseries/papr_scm.c +23 -10
index 0b4467e..54ae903 100644
@@ -14,6 +14,7 @@
 #include <linux/delay.h>
 
 #include <asm/plpar_wrappers.h>
+#include "of_helpers.h"
 
 #define BIND_ANY_ADDR (~0ul)
 
@@ -383,7 +384,7 @@ static int papr_scm_probe(struct platform_device *pdev)
 {
 	struct device_node *dn = pdev->dev.of_node;
 	u32 drc_index, metadata_size;
-	u64 blocks, block_size;
+	u64 blocks, block_size, bound_addr = 0;
 	struct papr_scm_priv *p;
 	const char *uuid_str;
 	u64 uuid[2];
@@ -440,17 +441,29 @@ static int papr_scm_probe(struct platform_device *pdev)
 	p->metadata_size = metadata_size;
 	p->pdev = pdev;
 
-	/* request the hypervisor to bind this region to somewhere in memory */
-	rc = drc_pmem_bind(p);
+	of_property_read_u64(dn, "bound-addr", &bound_addr);
+	if (bound_addr) {
+		p->bound_addr = bound_addr;
+	} else {
+		struct property *property;
+		u64 big;
 
-	/* If phyp says drc memory still bound then force unbound and retry */
-	if (rc == H_OVERLAP)
-		rc = drc_pmem_query_n_bind(p);
+		/* request the hypervisor to bind this region to somewhere in memory */
+		rc = drc_pmem_bind(p);
 
-	if (rc != H_SUCCESS) {
-		dev_err(&p->pdev->dev, "bind err: %d\n", rc);
-		rc = -ENXIO;
-		goto err;
+		/* If phyp says drc memory still bound then force unbound and retry */
+		if (rc == H_OVERLAP)
+			rc = drc_pmem_query_n_bind(p);
+
+		if (rc != H_SUCCESS) {
+			dev_err(&p->pdev->dev, "bind err: %d\n", rc);
+			rc = -ENXIO;
+			goto err;
+		}
+		big = cpu_to_be64(p->bound_addr);
+		property = new_property("bound-addr", sizeof(u64), (const unsigned char *)&big,
+			NULL);
+		of_add_property(dn, property);
 	}
 
 	/* setup the resource for the newly bound range */
drivers/of/base.c +1 -0
index ae03b12..602d2a9 100644
@@ -1817,6 +1817,7 @@ int of_add_property(struct device_node *np, struct property *prop)
 
 	return rc;
 }
+EXPORT_SYMBOL_GPL(of_add_property);
 
 int __of_remove_property(struct device_node *np, struct property *prop)
 {
Signature · 1 line
2.7.5
Reviewed-by on v3 1/2
#4 lore raw
In reply to Pingfan Liu
Quoted 6 lines · Pingfan Liu

Splitting out new_property() for coming reusing and moving it to of_helpers.c.

Also do some coding style cleanup.

Quoted 13 lines

To: [email protected]
Cc: Benjamin Herrenschmidt <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Michael Ellerman <[email protected]>
Cc: Hari Bathini <[email protected]>
Cc: Aneesh Kumar K.V <[email protected]>
Cc: Oliver O'Halloran <[email protected]>
Cc: Dan Williams <[email protected]>
Cc: Andrew Donnellan <[email protected]>
Cc: Christophe Leroy <[email protected]>
Cc: Rob Herring <[email protected]>
Cc: Frank Rowand <[email protected]>
Cc: [email protected]

Would this be useful to move into generic OF code?

Also if more functions are moving into of_helpers.c perhaps there should be a common function name prefix.

Otherwise your style cleanup looks good.

Signature · 2 lines
Andrew Donnellan              OzLabs, ADL Canberra
[email protected]             IBM Australia Limited
#5 lore raw
In reply to Pingfan Liu

Hi,

Quoted 2 lines · Pingfan Liu

Splitting out new_property() for coming reusing and moving it to of_helpers.c.

[...]

Quoted 17 lines
arch/powerpc/platforms/pseries/of_helpers.c +17 -0
+struct property *new_property(const char *name, const int length,
+		const unsigned char *value, struct property *last)
+{
+	struct property *new = kzalloc(sizeof(*new), GFP_KERNEL);
+
+	if (!new)
+		return NULL;
+
+	new->name = kstrdup(name, GFP_KERNEL);
+	if (!new->name)
+		goto cleanup;
+	new->value = kmalloc(length + 1, GFP_KERNEL);
+	if (!new->value)
+		goto cleanup;
+
+	memcpy(new->value, value, length);
+	*(((char *)new->value) + length) = 0;

arch/powerpc/platforms/pseries/of_helpers.c line 36

Quoted 10 lines
arch/powerpc/platforms/pseries/of_helpers.c +10 -0
+	new->length = length;
+	new->next = last;
+	return new;
+
+cleanup:
+	kfree(new->name);
+	kfree(new->value);
+	kfree(new);
+	return NULL;
+}

This function in its current form isn't suitable for more general use:

* It appears to be tailored to string properties - note the char * value parameter, the length + 1 allocation and nul termination.

* Most code shouldn't need the 'last' argument. The code where this currently resides builds a list of properties and attaches it to a new node, bypassing of_add_property().

Let's look at the call site you add in your next patch:

+ big = cpu_to_be64(p->bound_addr);
+ property = new_property("bound-addr", sizeof(u64), (const unsigned char *)&big,
+ NULL);
+ of_add_property(dn, property);

So you have to use a cast, and this is going to allocate (sizeof(u64) + 1) for the value, is that what you want?

I think you should leave that legacy pseries reconfig code undisturbed (frankly that stuff should get deprecated and removed) and if you want a generic helper it should look more like:

struct property *of_property_new(const char *name, size_t length,
const void *value, gfp_t allocflags)

__of_prop_dup() looks like a good model/guide here.

#6 lore raw
Quoted 56 lines · Nathan Lynch

Hi,

Quoted 2 lines · Pingfan Liu

Splitting out new_property() for coming reusing and moving it to of_helpers.c.

[...]

Quoted 17 lines
arch/powerpc/platforms/pseries/of_helpers.c +17 -0
+struct property *new_property(const char *name, const int length,
+             const unsigned char *value, struct property *last)
+{
+     struct property *new = kzalloc(sizeof(*new), GFP_KERNEL);
+
+     if (!new)
+             return NULL;
+
+     new->name = kstrdup(name, GFP_KERNEL);
+     if (!new->name)
+             goto cleanup;
+     new->value = kmalloc(length + 1, GFP_KERNEL);
+     if (!new->value)
+             goto cleanup;
+
+     memcpy(new->value, value, length);
+     *(((char *)new->value) + length) = 0;

arch/powerpc/platforms/pseries/of_helpers.c line 36

Quoted 10 lines
arch/powerpc/platforms/pseries/of_helpers.c +10 -0
+     new->length = length;
+     new->next = last;
+     return new;
+
+cleanup:
+     kfree(new->name);
+     kfree(new->value);
+     kfree(new);
+     return NULL;
+}

This function in its current form isn't suitable for more general use:

* It appears to be tailored to string properties - note the char * value parameter, the length + 1 allocation and nul termination.

* Most code shouldn't need the 'last' argument. The code where this currently resides builds a list of properties and attaches it to a new node, bypassing of_add_property().

Let's look at the call site you add in your next patch:

(quoted diff) +4 -0
+               big = cpu_to_be64(p->bound_addr);
+               property = new_property("bound-addr", sizeof(u64), (const unsigned char *)&big,
+                       NULL);
+               of_add_property(dn, property);

So you have to use a cast, and this is going to allocate (sizeof(u64) + 1) for the value, is that what you want?

Quoted 8 lines

I think you should leave that legacy pseries reconfig code undisturbed (frankly that stuff should get deprecated and removed) and if you want a generic helper it should look more like:

struct property *of_property_new(const char *name, size_t length,
const void *value, gfp_t allocflags)

__of_prop_dup() looks like a good model/guide here.

Thanks for your good suggestion.
I will re-code based on your suggestion, if [2/2] turns out acceptable.

Regards,
Pingfan

#8 lore raw

Re: [PATCHv3 2/2] pseries/scm: buffer pmem's bound addr in dt for kexec kernel

In reply to Pingfan Liu
Quoted 14 lines · Pingfan Liu

At present, plpar_hcall(H_SCM_BIND_MEM, ...) takes a very long time, so if dumping to fsdax, it will take a very long time.

Take a closer look, during the papr_scm initialization, the only configuration is through drc_pmem_bind()-> plpar_hcall(H_SCM_BIND_MEM, ...), which helps to set up the bound address.

On pseries, for kexec -l/-p kernel, there is no reset of hardware, and this step can be stepped around to save times. So the pmem bound address can be passed to the 2nd kernel through a dynamic added property "bound-addr" in dt node 'ibm,pmemory'.

Quoted 16 lines

To: [email protected]
Cc: Benjamin Herrenschmidt <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Michael Ellerman <[email protected]>
Cc: Hari Bathini <[email protected]>
Cc: Aneesh Kumar K.V <[email protected]>
Cc: Oliver O'Halloran <[email protected]>
Cc: Dan Williams <[email protected]>
Cc: Andrew Donnellan <[email protected]>
Cc: Christophe Leroy <[email protected]>
Cc: Rob Herring <[email protected]>
Cc: Frank Rowand <[email protected]>
Cc: [email protected]
---
note: This patch has not been tested since I can not get such a pseries with pmem.
Please kindly to give some suggestion, thanks.

There was some qemu patches to implement the Hcall interface floating around a while ago. I'm not sure they ever made it into upstream qemu though.

Quoted 64 lines
---
 arch/powerpc/platforms/pseries/of_helpers.c |  1 +
 arch/powerpc/platforms/pseries/papr_scm.c   | 33 ++++++++++++++++++++---------
 drivers/of/base.c                           |  1 +
 3 files changed, 25 insertions(+), 10 deletions(-)
arch/powerpc/platforms/pseries/of_helpers.c +1 -0
index 1022e0f..2c7bab4 100644
@@ -34,6 +34,7 @@ struct property *new_property(const char *name, const int length,
        kfree(new);
        return NULL;
 }
+EXPORT_SYMBOL(new_property);
 
 /**
  * pseries_of_derive_parent - basically like dirname(1)
arch/powerpc/platforms/pseries/papr_scm.c +12 -10
index 0b4467e..54ae903 100644
@@ -14,6 +14,7 @@
 #include <linux/delay.h>
 
 #include <asm/plpar_wrappers.h>
+#include "of_helpers.h"
 
 #define BIND_ANY_ADDR (~0ul)
 
@@ -383,7 +384,7 @@ static int papr_scm_probe(struct platform_device *pdev)
 {
        struct device_node *dn = pdev->dev.of_node;
        u32 drc_index, metadata_size;
-       u64 blocks, block_size;
+       u64 blocks, block_size, bound_addr = 0;
        struct papr_scm_priv *p;
        const char *uuid_str;
        u64 uuid[2];
@@ -440,17 +441,29 @@ static int papr_scm_probe(struct platform_device *pdev)
        p->metadata_size = metadata_size;
        p->pdev = pdev;
 
-       /* request the hypervisor to bind this region to somewhere in memory */
-       rc = drc_pmem_bind(p);
+       of_property_read_u64(dn, "bound-addr", &bound_addr);
+       if (bound_addr) {
+               p->bound_addr = bound_addr;
+       } else {
+               struct property *property;
+               u64 big;
 
-       /* If phyp says drc memory still bound then force unbound and retry */
-       if (rc == H_OVERLAP)
-               rc = drc_pmem_query_n_bind(p);
+               /* request the hypervisor to bind this region to somewhere in memory */
+               rc = drc_pmem_bind(p);
 
-       if (rc != H_SUCCESS) {
-               dev_err(&p->pdev->dev, "bind err: %d\n", rc);
-               rc = -ENXIO;
-               goto err;
+               /* If phyp says drc memory still bound then force unbound and retry */
+               if (rc == H_OVERLAP)

arch/powerpc/platforms/pseries/papr_scm.c static int papr_scm_probe(struct platform_device *pdev) · line 465

Quoted 10 lines
arch/powerpc/platforms/pseries/papr_scm.c +10 -0
+                       rc = drc_pmem_query_n_bind(p);
+
+               if (rc != H_SUCCESS) {
+                       dev_err(&p->pdev->dev, "bind err: %d\n", rc);
+                       rc = -ENXIO;
+                       goto err;
+               }
+               big = cpu_to_be64(p->bound_addr);
+               property = new_property("bound-addr", sizeof(u64), (const unsigned char *)&big,
+                       NULL);

That should probably be "linux,bound-addr"

The other thing that stands out to me is that you aren't removing the property when the region is unbound. As a general rule I'd prefer we didn't hack the DT at runtime, but if we are going to then we should make sure we're not putting anything wrong in there.

Quoted 19 lines
arch/powerpc/platforms/pseries/papr_scm.c +1 -0
+               of_add_property(dn, property);
        }
 
        /* setup the resource for the newly bound range */
drivers/of/base.c +1 -1
index ae03b12..602d2a9 100644
@@ -1817,6 +1817,7 @@ int of_add_property(struct device_node *np, struct property *prop)
 
        return rc;
 }
+EXPORT_SYMBOL_GPL(of_add_property);
 
 int __of_remove_property(struct device_node *np, struct property *prop)
 {
--

2.7.5

#9 lore raw

Re: [PATCHv3 2/2] pseries/scm: buffer pmem's bound addr in dt for kexec kernel

Appreciate for your kind review. And I have some comment as below.

Quoted 33 lines · Oliver O'Halloran
Quoted 14 lines · Pingfan Liu

At present, plpar_hcall(H_SCM_BIND_MEM, ...) takes a very long time, so if dumping to fsdax, it will take a very long time.

Take a closer look, during the papr_scm initialization, the only configuration is through drc_pmem_bind()-> plpar_hcall(H_SCM_BIND_MEM, ...), which helps to set up the bound address.

On pseries, for kexec -l/-p kernel, there is no reset of hardware, and this step can be stepped around to save times. So the pmem bound address can be passed to the 2nd kernel through a dynamic added property "bound-addr" in dt node 'ibm,pmemory'.

Quoted 16 lines

To: [email protected]
Cc: Benjamin Herrenschmidt <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Michael Ellerman <[email protected]>
Cc: Hari Bathini <[email protected]>
Cc: Aneesh Kumar K.V <[email protected]>
Cc: Oliver O'Halloran <[email protected]>
Cc: Dan Williams <[email protected]>
Cc: Andrew Donnellan <[email protected]>
Cc: Christophe Leroy <[email protected]>
Cc: Rob Herring <[email protected]>
Cc: Frank Rowand <[email protected]>
Cc: [email protected]
---
note: This patch has not been tested since I can not get such a pseries with pmem.
Please kindly to give some suggestion, thanks.

Quoted 3 lines

There was some qemu patches to implement the Hcall interface floating around a while ago. I'm not sure they ever made it into upstream qemu though.

Unfortunately, it does not appear in latest qemu code. I think probably virt-pmem has achieved the same feature.

Quoted 69 lines
Quoted 69 lines
---
 arch/powerpc/platforms/pseries/of_helpers.c |  1 +
 arch/powerpc/platforms/pseries/papr_scm.c   | 33 ++++++++++++++++++++---------
 drivers/of/base.c                           |  1 +
 3 files changed, 25 insertions(+), 10 deletions(-)
arch/powerpc/platforms/pseries/of_helpers.c +1 -0
index 1022e0f..2c7bab4 100644
@@ -34,6 +34,7 @@ struct property *new_property(const char *name, const int length,
        kfree(new);
        return NULL;
 }
+EXPORT_SYMBOL(new_property);
 
 /**
  * pseries_of_derive_parent - basically like dirname(1)
arch/powerpc/platforms/pseries/papr_scm.c +16 -10
index 0b4467e..54ae903 100644
@@ -14,6 +14,7 @@
 #include <linux/delay.h>
 
 #include <asm/plpar_wrappers.h>
+#include "of_helpers.h"
 
 #define BIND_ANY_ADDR (~0ul)
 
@@ -383,7 +384,7 @@ static int papr_scm_probe(struct platform_device *pdev)
 {
        struct device_node *dn = pdev->dev.of_node;
        u32 drc_index, metadata_size;
-       u64 blocks, block_size;
+       u64 blocks, block_size, bound_addr = 0;
        struct papr_scm_priv *p;
        const char *uuid_str;
        u64 uuid[2];
@@ -440,17 +441,29 @@ static int papr_scm_probe(struct platform_device *pdev)
        p->metadata_size = metadata_size;
        p->pdev = pdev;
 
-       /* request the hypervisor to bind this region to somewhere in memory */
-       rc = drc_pmem_bind(p);
+       of_property_read_u64(dn, "bound-addr", &bound_addr);
+       if (bound_addr) {
+               p->bound_addr = bound_addr;
+       } else {
+               struct property *property;
+               u64 big;
 
-       /* If phyp says drc memory still bound then force unbound and retry */
-       if (rc == H_OVERLAP)
-               rc = drc_pmem_query_n_bind(p);
+               /* request the hypervisor to bind this region to somewhere in memory */
+               rc = drc_pmem_bind(p);
 
-       if (rc != H_SUCCESS) {
-               dev_err(&p->pdev->dev, "bind err: %d\n", rc);
-               rc = -ENXIO;
-               goto err;
+               /* If phyp says drc memory still bound then force unbound and retry */
+               if (rc == H_OVERLAP)
+                       rc = drc_pmem_query_n_bind(p);
+
+               if (rc != H_SUCCESS) {
+                       dev_err(&p->pdev->dev, "bind err: %d\n", rc);
Quoted 8 lines

arch/powerpc/platforms/pseries/papr_scm.c static int papr_scm_probe(struct platform_device *pdev) · line 465

Quoted 6 lines
arch/powerpc/platforms/pseries/papr_scm.c +6 -0
+                       rc = -ENXIO;
+                       goto err;
+               }
+               big = cpu_to_be64(p->bound_addr);
+               property = new_property("bound-addr", sizeof(u64), (const unsigned char *)&big,
+                       NULL);

That should probably be "linux,bound-addr"

OK, thanks for suggestion.

Quoted 2 lines

The other thing that stands out to me is that you aren't removing the

Yes, you are right. I will fix it in V2.

Quoted 3 lines

property when the region is unbound. As a general rule I'd prefer we didn't hack the DT at runtime, but if we are going to then we should make sure we're not putting anything wrong in there.

Actually, the dynamically building of DT is widely used by "kexec -l".

The pre-condition for the hacked method is that the bound pmem-addr will not change. And on pseries, during kexec -l/-p, a machine reset will not be invoked, so the bound address should be changed.

Thanks,
Pingfan
[...]

#10 lore raw

Re: [PATCHv3 2/2] pseries/scm: buffer pmem's bound addr in dt for kexec kernel

In reply to Pingfan Liu
Quoted 3 lines · Pingfan Liu

At present, plpar_hcall(H_SCM_BIND_MEM, ...) takes a very long time, so if dumping to fsdax, it will take a very long time.

that should be fixed by

faa6d21153fd11e139dd880044521389b34a24f2

Author:       Aneesh Kumar K.V <[email protected]>
AuthorDate:   Tue Sep 3 18:04:52 2019 +0530
Commit:       Michael Ellerman <[email protected]>
CommitDate:   Wed Sep 25 08:32:59 2019 +1000

powerpc/nvdimm: use H_SCM_QUERY hcall on H_OVERLAP error

Right now we force an unbind of SCM memory at drcindex on H_OVERLAP error. This really slows down operations like kexec where we get the H_OVERLAP error because we don't go through a full hypervisor re init.

H_OVERLAP error for a H_SCM_BIND_MEM hcall indicates that SCM memory at drc index is already bound. Since we don't specify a logical memory address for bind hcall, we can use the H_SCM_QUERY hcall to query the already bound logical address.

Quoted 9 lines

Take a closer look, during the papr_scm initialization, the only configuration is through drc_pmem_bind()-> plpar_hcall(H_SCM_BIND_MEM, ...), which helps to set up the bound address.

On pseries, for kexec -l/-p kernel, there is no reset of hardware, and this step can be stepped around to save times. So the pmem bound address can be passed to the 2nd kernel through a dynamic added property "bound-addr" in dt node 'ibm,pmemory'.

-aneesh

#11 lore raw

Re: [PATCHv3 2/2] pseries/scm: buffer pmem's bound addr in dt for kexec kernel

Quoted 17 lines · Aneesh Kumar K.V
Quoted 3 lines · Pingfan Liu

At present, plpar_hcall(H_SCM_BIND_MEM, ...) takes a very long time, so if dumping to fsdax, it will take a very long time.

that should be fixed by

faa6d21153fd11e139dd880044521389b34a24f2

Author:       Aneesh Kumar K.V <[email protected]>
AuthorDate:   Tue Sep 3 18:04:52 2019 +0530
Commit:       Michael Ellerman <[email protected]>
CommitDate:   Wed Sep 25 08:32:59 2019 +1000

powerpc/nvdimm: use H_SCM_QUERY hcall on H_OVERLAP error

Quoted 8 lines

Right now we force an unbind of SCM memory at drcindex on H_OVERLAP error. This really slows down operations like kexec where we get the H_OVERLAP error because we don't go through a full hypervisor re init.

H_OVERLAP error for a H_SCM_BIND_MEM hcall indicates that SCM memory at drc index is already bound. Since we don't specify a logical memory address for bind hcall, we can use the H_SCM_QUERY hcall to query the already bound logical address.

Good to know it.

Thanks,
Pingfan

Quoted 16 lines
Quoted 4 lines
Quoted 9 lines

Take a closer look, during the papr_scm initialization, the only configuration is through drc_pmem_bind()-> plpar_hcall(H_SCM_BIND_MEM, ...), which helps to set up the bound address.

On pseries, for kexec -l/-p kernel, there is no reset of hardware, and this step can be stepped around to save times. So the pmem bound address can be passed to the 2nd kernel through a dynamic added property "bound-addr" in dt node 'ibm,pmemory'.

-aneesh