[PATCH 2/2] powerpc/papr_scm: Force a scm-unbind if initial scm-bind fails

Vaibhav Jain vaibhav at linux.ibm.com
Tue Jun 25 00:59:13 AEST 2019


In some cases initial bind of scm memory for an lpar can fail if
previously it wasn't released using a scm-unbind hcall. This situation
can arise due to panic of the previous kernel or forced lpar reset. In
such cases the H_SCM_BIND_MEM return a H_OVERLAP error.

To mitigate such cases the patch updates drc_pmem_bind() to force a
call to drc_pmem_unbind() in case the initial bind of scm memory fails
with H_OVERLAP error. In case scm-bind operation again fails after the
forced scm-unbind then we follow the existing error path.

Signed-off-by: Vaibhav Jain <vaibhav at linux.ibm.com>
---
 arch/powerpc/platforms/pseries/papr_scm.c | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/platforms/pseries/papr_scm.c b/arch/powerpc/platforms/pseries/papr_scm.c
index d790e4e4ffb3..049d7927c0a4 100644
--- a/arch/powerpc/platforms/pseries/papr_scm.c
+++ b/arch/powerpc/platforms/pseries/papr_scm.c
@@ -44,19 +44,26 @@ struct papr_scm_priv {
 	struct nd_interleave_set nd_set;
 };
 
+/* Forward declaration */
+static int drc_pmem_unbind(struct papr_scm_priv *);
+
 static int drc_pmem_bind(struct papr_scm_priv *p)
 {
 	unsigned long ret[PLPAR_HCALL_BUFSIZE];
 	uint64_t rc, token;
-	uint64_t saved = 0;
+	uint64_t saved;
+	bool tried_unbind = false;
 
+	dev_dbg(&p->pdev->dev, "bind drc %x\n", p->drc_index);
 	/*
 	 * When the hypervisor cannot map all the requested memory in a single
 	 * hcall it returns H_BUSY and we call again with the token until
 	 * we get H_SUCCESS. Aborting the retry loop before getting H_SUCCESS
 	 * leave the system in an undefined state, so we wait.
 	 */
+retry:
 	token = 0;
+	saved = 0;
 
 	do {
 		rc = plpar_hcall(H_SCM_BIND_MEM, ret, p->drc_index, 0,
@@ -68,8 +75,18 @@ static int drc_pmem_bind(struct papr_scm_priv *p)
 	} while (rc == H_BUSY);
 
 	if (rc) {
-		dev_err(&p->pdev->dev, "bind err: %lld\n", rc);
-		return -ENXIO;
+		/* retry after unbinding */
+		if (rc == H_OVERLAP &&  !tried_unbind) {
+			dev_warn(&p->pdev->dev, "Un-binding and retrying\n");
+			/* Try unbind and ignore any errors */
+			tried_unbind = true;
+			drc_pmem_unbind(p);
+			goto retry;
+
+		} else {
+			dev_err(&p->pdev->dev, "bind err: %lld\n", rc);
+			return -ENXIO;
+		}
 	}
 
 	p->bound_addr = saved;
-- 
2.21.0



More information about the Linuxppc-dev mailing list