[v06,1/9] hotplug/cpu: Conditionally acquire/release DRC index

Message ID a86bdaf8-ad27-ffb4-aa89-77294c98010f@linux.vnet.ibm.com
State Superseded
Headers show
Series
  • powerpc/hotplug: Update affinity for migrated CPUs
Related show

Commit Message

Michael Bringmann July 9, 2018, 2:58 p.m.
powerpc/cpu: Modify dlpar_cpu_add and dlpar_cpu_remove to allow the
skipping of DRC index acquire or release operations during the CPU
add or remove operations.  This is intended to support subsequent
changes to provide a 'CPU readd' operation.

Signed-off-by: Michael Bringmann <mwb@linux.vnet.ibm.com>
---
Changes in patch:
  -- Move new validity check added to pseries_smp_notifier
     to another patch
---
 arch/powerpc/platforms/pseries/hotplug-cpu.c |   68 +++++++++++++++-----------
 1 file changed, 39 insertions(+), 29 deletions(-)

Comments

Naveen N. Rao July 11, 2018, 4 p.m. | #1
Michael Bringmann wrote:
> powerpc/cpu: Modify dlpar_cpu_add and dlpar_cpu_remove to allow the
> skipping of DRC index acquire or release operations during the CPU
> add or remove operations.  This is intended to support subsequent
> changes to provide a 'CPU readd' operation.
> 
> Signed-off-by: Michael Bringmann <mwb@linux.vnet.ibm.com>
> ---
> Changes in patch:
>   -- Move new validity check added to pseries_smp_notifier
>      to another patch
> ---
>  arch/powerpc/platforms/pseries/hotplug-cpu.c |   68 +++++++++++++++-----------
>  1 file changed, 39 insertions(+), 29 deletions(-)
> 
> diff --git a/arch/powerpc/platforms/pseries/hotplug-cpu.c b/arch/powerpc/platforms/pseries/hotplug-cpu.c
> index 6ef77ca..3632db2 100644
> --- a/arch/powerpc/platforms/pseries/hotplug-cpu.c
> +++ b/arch/powerpc/platforms/pseries/hotplug-cpu.c
> @@ -432,7 +432,7 @@ static bool valid_cpu_drc_index(struct device_node *parent, u32 drc_index)
>  	return found;
>  }
> 
> -static ssize_t dlpar_cpu_add(u32 drc_index)
> +static ssize_t dlpar_cpu_add(u32 drc_index, bool acquire_drc)
>  {
>  	struct device_node *dn, *parent;
>  	int rc, saved_rc;
> @@ -457,19 +457,22 @@ static ssize_t dlpar_cpu_add(u32 drc_index)
>  		return -EINVAL;
>  	}
> 
> -	rc = dlpar_acquire_drc(drc_index);
> -	if (rc) {
> -		pr_warn("Failed to acquire DRC, rc: %d, drc index: %x\n",
> -			rc, drc_index);
> -		of_node_put(parent);
> -		return -EINVAL;
> +	if (acquire_drc) {
> +		rc = dlpar_acquire_drc(drc_index);
> +		if (rc) {
> +			pr_warn("Failed to acquire DRC, rc: %d, drc index: %x\n",
> +				rc, drc_index);
> +			of_node_put(parent);
> +			return -EINVAL;
> +		}
>  	}
> 
>  	dn = dlpar_configure_connector(cpu_to_be32(drc_index), parent);
>  	if (!dn) {
>  		pr_warn("Failed call to configure-connector, drc index: %x\n",
>  			drc_index);
> -		dlpar_release_drc(drc_index);
> +		if (acquire_drc)
> +			dlpar_release_drc(drc_index);
>  		of_node_put(parent);
>  		return -EINVAL;
>  	}
> @@ -484,8 +487,9 @@ static ssize_t dlpar_cpu_add(u32 drc_index)
>  		pr_warn("Failed to attach node %s, rc: %d, drc index: %x\n",
>  			dn->name, rc, drc_index);
> 
> -		rc = dlpar_release_drc(drc_index);
> -		if (!rc)
> +		if (acquire_drc)
> +			rc = dlpar_release_drc(drc_index);
> +		if (!rc || acquire_drc)
>  			dlpar_free_cc_nodes(dn);

(!rc) can only be true if acquire_drc is true, so we seem to be only 
invoking dlpar_free_cc_nodes() if acquire_drc is true. Would it be 
better to frame that condition in this manner:

	if (acquire_drc) {
		rc = dlpar_release_drc(drc_index):
		if (!rc)
			dlpar_free_cc_nodes(dn);
	}

> 
>  		return saved_rc;
> @@ -498,7 +502,7 @@ static ssize_t dlpar_cpu_add(u32 drc_index)
>  			dn->name, rc, drc_index);
> 
>  		rc = dlpar_detach_node(dn);
> -		if (!rc)
> +		if (!rc && acquire_drc)
>  			dlpar_release_drc(drc_index);
> 
>  		return saved_rc;
> @@ -566,7 +570,8 @@ static int dlpar_offline_cpu(struct device_node *dn)
> 
>  }
> 
> -static ssize_t dlpar_cpu_remove(struct device_node *dn, u32 drc_index)
> +static ssize_t dlpar_cpu_remove(struct device_node *dn, u32 drc_index,
> +				bool release_drc)
>  {
>  	int rc;
> 
> @@ -579,12 +584,14 @@ static ssize_t dlpar_cpu_remove(struct device_node *dn, u32 drc_index)
>  		return -EINVAL;
>  	}
> 
> -	rc = dlpar_release_drc(drc_index);
> -	if (rc) {
> -		pr_warn("Failed to release drc (%x) for CPU %s, rc: %d\n",
> -			drc_index, dn->name, rc);
> -		dlpar_online_cpu(dn);
> -		return rc;
> +	if (release_drc) {
> +		rc = dlpar_release_drc(drc_index);
> +		if (rc) {
> +			pr_warn("Failed to release drc (%x) for CPU %s, rc: %d\n",
> +				drc_index, dn->name, rc);
> +			dlpar_online_cpu(dn);
> +			return rc;
> +		}
>  	}
> 
>  	rc = dlpar_detach_node(dn);
> @@ -593,7 +600,10 @@ static ssize_t dlpar_cpu_remove(struct device_node *dn, u32 drc_index)
> 
>  		pr_warn("Failed to detach CPU %s, rc: %d", dn->name, rc);
> 
> -		rc = dlpar_acquire_drc(drc_index);
> +		if (release_drc)
> +			rc = dlpar_acquire_drc(drc_index);
> +		else
> +			rc = 0;
>  		if (!rc)
>  			dlpar_online_cpu(dn);

Here, we seem to want to invoke dlpar_online_cpu() unconditionally if 
release_drc is false. So, to make that explicit, would it be better to 
frame that as:
	if (release_drc)
		rc = dlpar_acquire_drc(drc_index);
	if (!release_drc || !rc)
		dlpar_online_cpu(dn);

- Naveen

> 
> @@ -622,7 +632,7 @@ static struct device_node *cpu_drc_index_to_dn(u32 drc_index)
>  	return dn;
>  }
> 
> -static int dlpar_cpu_remove_by_index(u32 drc_index)
> +static int dlpar_cpu_remove_by_index(u32 drc_index, bool release_drc)
>  {
>  	struct device_node *dn;
>  	int rc;
> @@ -634,7 +644,7 @@ static int dlpar_cpu_remove_by_index(u32 drc_index)
>  		return -ENODEV;
>  	}
> 
> -	rc = dlpar_cpu_remove(dn, drc_index);
> +	rc = dlpar_cpu_remove(dn, drc_index, release_drc);
>  	of_node_put(dn);
>  	return rc;
>  }
> @@ -699,7 +709,7 @@ static int dlpar_cpu_remove_by_count(u32 cpus_to_remove)
>  	}
> 
>  	for (i = 0; i < cpus_to_remove; i++) {
> -		rc = dlpar_cpu_remove_by_index(cpu_drcs[i]);
> +		rc = dlpar_cpu_remove_by_index(cpu_drcs[i], true);
>  		if (rc)
>  			break;
> 
> @@ -710,7 +720,7 @@ static int dlpar_cpu_remove_by_count(u32 cpus_to_remove)
>  		pr_warn("CPU hot-remove failed, adding back removed CPUs\n");
> 
>  		for (i = 0; i < cpus_removed; i++)
> -			dlpar_cpu_add(cpu_drcs[i]);
> +			dlpar_cpu_add(cpu_drcs[i], true);
> 
>  		rc = -EINVAL;
>  	} else {
> @@ -780,7 +790,7 @@ static int dlpar_cpu_add_by_count(u32 cpus_to_add)
>  	}
> 
>  	for (i = 0; i < cpus_to_add; i++) {
> -		rc = dlpar_cpu_add(cpu_drcs[i]);
> +		rc = dlpar_cpu_add(cpu_drcs[i], true);
>  		if (rc)
>  			break;
> 
> @@ -791,7 +801,7 @@ static int dlpar_cpu_add_by_count(u32 cpus_to_add)
>  		pr_warn("CPU hot-add failed, removing any added CPUs\n");
> 
>  		for (i = 0; i < cpus_added; i++)
> -			dlpar_cpu_remove_by_index(cpu_drcs[i]);
> +			dlpar_cpu_remove_by_index(cpu_drcs[i], true);
> 
>  		rc = -EINVAL;
>  	} else {
> @@ -817,7 +827,7 @@ int dlpar_cpu(struct pseries_hp_errorlog *hp_elog)
>  		if (hp_elog->id_type == PSERIES_HP_ELOG_ID_DRC_COUNT)
>  			rc = dlpar_cpu_remove_by_count(count);
>  		else if (hp_elog->id_type == PSERIES_HP_ELOG_ID_DRC_INDEX)
> -			rc = dlpar_cpu_remove_by_index(drc_index);
> +			rc = dlpar_cpu_remove_by_index(drc_index, true);
>  		else
>  			rc = -EINVAL;
>  		break;
> @@ -825,7 +835,7 @@ int dlpar_cpu(struct pseries_hp_errorlog *hp_elog)
>  		if (hp_elog->id_type == PSERIES_HP_ELOG_ID_DRC_COUNT)
>  			rc = dlpar_cpu_add_by_count(count);
>  		else if (hp_elog->id_type == PSERIES_HP_ELOG_ID_DRC_INDEX)
> -			rc = dlpar_cpu_add(drc_index);
> +			rc = dlpar_cpu_add(drc_index, true);
>  		else
>  			rc = -EINVAL;
>  		break;
> @@ -850,7 +860,7 @@ static ssize_t dlpar_cpu_probe(const char *buf, size_t count)
>  	if (rc)
>  		return -EINVAL;
> 
> -	rc = dlpar_cpu_add(drc_index);
> +	rc = dlpar_cpu_add(drc_index, true);
> 
>  	return rc ? rc : count;
>  }
> @@ -871,7 +881,7 @@ static ssize_t dlpar_cpu_release(const char *buf, size_t count)
>  		return -EINVAL;
>  	}
> 
> -	rc = dlpar_cpu_remove(dn, drc_index);
> +	rc = dlpar_cpu_remove(dn, drc_index, true);
>  	of_node_put(dn);
> 
>  	return rc ? rc : count;
> 
>
Michael Bringmann July 13, 2018, 3:54 p.m. | #2
See below.  Code cleanups accepted for next revision.

On 07/11/2018 11:00 AM, Naveen N. Rao wrote:
> Michael Bringmann wrote:
>> powerpc/cpu: Modify dlpar_cpu_add and dlpar_cpu_remove to allow the
>> skipping of DRC index acquire or release operations during the CPU
>> add or remove operations.  This is intended to support subsequent
>> changes to provide a 'CPU readd' operation.
>>
>> Signed-off-by: Michael Bringmann <mwb@linux.vnet.ibm.com>
>> ---
>> Changes in patch:
>>   -- Move new validity check added to pseries_smp_notifier
>>      to another patch
>> ---
>>  arch/powerpc/platforms/pseries/hotplug-cpu.c |   68 +++++++++++++++-----------
>>  1 file changed, 39 insertions(+), 29 deletions(-)
>>
>> diff --git a/arch/powerpc/platforms/pseries/hotplug-cpu.c b/arch/powerpc/platforms/pseries/hotplug-cpu.c
>> index 6ef77ca..3632db2 100644
>> --- a/arch/powerpc/platforms/pseries/hotplug-cpu.c
>> +++ b/arch/powerpc/platforms/pseries/hotplug-cpu.c
>> @@ -432,7 +432,7 @@ static bool valid_cpu_drc_index(struct device_node *parent, u32 drc_index)
>>      return found;
>>  }
>>
>> -static ssize_t dlpar_cpu_add(u32 drc_index)
>> +static ssize_t dlpar_cpu_add(u32 drc_index, bool acquire_drc)
>>  {
>>      struct device_node *dn, *parent;
>>      int rc, saved_rc;
>> @@ -457,19 +457,22 @@ static ssize_t dlpar_cpu_add(u32 drc_index)
>>          return -EINVAL;
>>      }
>>
>> -    rc = dlpar_acquire_drc(drc_index);
>> -    if (rc) {
>> -        pr_warn("Failed to acquire DRC, rc: %d, drc index: %x\n",
>> -            rc, drc_index);
>> -        of_node_put(parent);
>> -        return -EINVAL;
>> +    if (acquire_drc) {
>> +        rc = dlpar_acquire_drc(drc_index);
>> +        if (rc) {
>> +            pr_warn("Failed to acquire DRC, rc: %d, drc index: %x\n",
>> +                rc, drc_index);
>> +            of_node_put(parent);
>> +            return -EINVAL;
>> +        }
>>      }
>>
>>      dn = dlpar_configure_connector(cpu_to_be32(drc_index), parent);
>>      if (!dn) {
>>          pr_warn("Failed call to configure-connector, drc index: %x\n",
>>              drc_index);
>> -        dlpar_release_drc(drc_index);
>> +        if (acquire_drc)
>> +            dlpar_release_drc(drc_index);
>>          of_node_put(parent);
>>          return -EINVAL;
>>      }
>> @@ -484,8 +487,9 @@ static ssize_t dlpar_cpu_add(u32 drc_index)
>>          pr_warn("Failed to attach node %s, rc: %d, drc index: %x\n",
>>              dn->name, rc, drc_index);
>>
>> -        rc = dlpar_release_drc(drc_index);
>> -        if (!rc)
>> +        if (acquire_drc)
>> +            rc = dlpar_release_drc(drc_index);
>> +        if (!rc || acquire_drc)
>>              dlpar_free_cc_nodes(dn);
> 
> (!rc) can only be true if acquire_drc is true, so we seem to be only invoking dlpar_free_cc_nodes() if acquire_drc is true. Would it be better to frame that condition in this manner:
> 
>     if (acquire_drc) {
>         rc = dlpar_release_drc(drc_index):
>         if (!rc)
>             dlpar_free_cc_nodes(dn);
>     }
> 

Okay.

>>
>>          return saved_rc;
>> @@ -498,7 +502,7 @@ static ssize_t dlpar_cpu_add(u32 drc_index)
>>              dn->name, rc, drc_index);
>>
>>          rc = dlpar_detach_node(dn);
>> -        if (!rc)
>> +        if (!rc && acquire_drc)
>>              dlpar_release_drc(drc_index);
>>
>>          return saved_rc;
>> @@ -566,7 +570,8 @@ static int dlpar_offline_cpu(struct device_node *dn)
>>
>>  }
>>
>> -static ssize_t dlpar_cpu_remove(struct device_node *dn, u32 drc_index)
>> +static ssize_t dlpar_cpu_remove(struct device_node *dn, u32 drc_index,
>> +                bool release_drc)
>>  {
>>      int rc;
>>
>> @@ -579,12 +584,14 @@ static ssize_t dlpar_cpu_remove(struct device_node *dn, u32 drc_index)
>>          return -EINVAL;
>>      }
>>
>> -    rc = dlpar_release_drc(drc_index);
>> -    if (rc) {
>> -        pr_warn("Failed to release drc (%x) for CPU %s, rc: %d\n",
>> -            drc_index, dn->name, rc);
>> -        dlpar_online_cpu(dn);
>> -        return rc;
>> +    if (release_drc) {
>> +        rc = dlpar_release_drc(drc_index);
>> +        if (rc) {
>> +            pr_warn("Failed to release drc (%x) for CPU %s, rc: %d\n",
>> +                drc_index, dn->name, rc);
>> +            dlpar_online_cpu(dn);
>> +            return rc;
>> +        }
>>      }
>>
>>      rc = dlpar_detach_node(dn);
>> @@ -593,7 +600,10 @@ static ssize_t dlpar_cpu_remove(struct device_node *dn, u32 drc_index)
>>
>>          pr_warn("Failed to detach CPU %s, rc: %d", dn->name, rc);
>>
>> -        rc = dlpar_acquire_drc(drc_index);
>> +        if (release_drc)
>> +            rc = dlpar_acquire_drc(drc_index);
>> +        else
>> +            rc = 0;
>>          if (!rc)
>>              dlpar_online_cpu(dn);
> 
> Here, we seem to want to invoke dlpar_online_cpu() unconditionally if release_drc is false. So, to make that explicit, would it be better to frame that as:
>     if (release_drc)
>         rc = dlpar_acquire_drc(drc_index);
>     if (!release_drc || !rc)
>         dlpar_online_cpu(dn);
> 
> - Naveen

Okay.

> 
>>
>> @@ -622,7 +632,7 @@ static struct device_node *cpu_drc_index_to_dn(u32 drc_index)
>>      return dn;
>>  }
>>
>> -static int dlpar_cpu_remove_by_index(u32 drc_index)
>> +static int dlpar_cpu_remove_by_index(u32 drc_index, bool release_drc)
>>  {
>>      struct device_node *dn;
>>      int rc;
>> @@ -634,7 +644,7 @@ static int dlpar_cpu_remove_by_index(u32 drc_index)
>>          return -ENODEV;
>>      }
>>
>> -    rc = dlpar_cpu_remove(dn, drc_index);
>> +    rc = dlpar_cpu_remove(dn, drc_index, release_drc);
>>      of_node_put(dn);
>>      return rc;
>>  }
>> @@ -699,7 +709,7 @@ static int dlpar_cpu_remove_by_count(u32 cpus_to_remove)
>>      }
>>
>>      for (i = 0; i < cpus_to_remove; i++) {
>> -        rc = dlpar_cpu_remove_by_index(cpu_drcs[i]);
>> +        rc = dlpar_cpu_remove_by_index(cpu_drcs[i], true);
>>          if (rc)
>>              break;
>>
>> @@ -710,7 +720,7 @@ static int dlpar_cpu_remove_by_count(u32 cpus_to_remove)
>>          pr_warn("CPU hot-remove failed, adding back removed CPUs\n");
>>
>>          for (i = 0; i < cpus_removed; i++)
>> -            dlpar_cpu_add(cpu_drcs[i]);
>> +            dlpar_cpu_add(cpu_drcs[i], true);
>>
>>          rc = -EINVAL;
>>      } else {
>> @@ -780,7 +790,7 @@ static int dlpar_cpu_add_by_count(u32 cpus_to_add)
>>      }
>>
>>      for (i = 0; i < cpus_to_add; i++) {
>> -        rc = dlpar_cpu_add(cpu_drcs[i]);
>> +        rc = dlpar_cpu_add(cpu_drcs[i], true);
>>          if (rc)
>>              break;
>>
>> @@ -791,7 +801,7 @@ static int dlpar_cpu_add_by_count(u32 cpus_to_add)
>>          pr_warn("CPU hot-add failed, removing any added CPUs\n");
>>
>>          for (i = 0; i < cpus_added; i++)
>> -            dlpar_cpu_remove_by_index(cpu_drcs[i]);
>> +            dlpar_cpu_remove_by_index(cpu_drcs[i], true);
>>
>>          rc = -EINVAL;
>>      } else {
>> @@ -817,7 +827,7 @@ int dlpar_cpu(struct pseries_hp_errorlog *hp_elog)
>>          if (hp_elog->id_type == PSERIES_HP_ELOG_ID_DRC_COUNT)
>>              rc = dlpar_cpu_remove_by_count(count);
>>          else if (hp_elog->id_type == PSERIES_HP_ELOG_ID_DRC_INDEX)
>> -            rc = dlpar_cpu_remove_by_index(drc_index);
>> +            rc = dlpar_cpu_remove_by_index(drc_index, true);
>>          else
>>              rc = -EINVAL;
>>          break;
>> @@ -825,7 +835,7 @@ int dlpar_cpu(struct pseries_hp_errorlog *hp_elog)
>>          if (hp_elog->id_type == PSERIES_HP_ELOG_ID_DRC_COUNT)
>>              rc = dlpar_cpu_add_by_count(count);
>>          else if (hp_elog->id_type == PSERIES_HP_ELOG_ID_DRC_INDEX)
>> -            rc = dlpar_cpu_add(drc_index);
>> +            rc = dlpar_cpu_add(drc_index, true);
>>          else
>>              rc = -EINVAL;
>>          break;
>> @@ -850,7 +860,7 @@ static ssize_t dlpar_cpu_probe(const char *buf, size_t count)
>>      if (rc)
>>          return -EINVAL;
>>
>> -    rc = dlpar_cpu_add(drc_index);
>> +    rc = dlpar_cpu_add(drc_index, true);
>>
>>      return rc ? rc : count;
>>  }
>> @@ -871,7 +881,7 @@ static ssize_t dlpar_cpu_release(const char *buf, size_t count)
>>          return -EINVAL;
>>      }
>>
>> -    rc = dlpar_cpu_remove(dn, drc_index);
>> +    rc = dlpar_cpu_remove(dn, drc_index, true);
>>      of_node_put(dn);
>>
>>      return rc ? rc : count;
>>
>>
> 
>

Patch

diff --git a/arch/powerpc/platforms/pseries/hotplug-cpu.c b/arch/powerpc/platforms/pseries/hotplug-cpu.c
index 6ef77ca..3632db2 100644
--- a/arch/powerpc/platforms/pseries/hotplug-cpu.c
+++ b/arch/powerpc/platforms/pseries/hotplug-cpu.c
@@ -432,7 +432,7 @@  static bool valid_cpu_drc_index(struct device_node *parent, u32 drc_index)
 	return found;
 }
 
-static ssize_t dlpar_cpu_add(u32 drc_index)
+static ssize_t dlpar_cpu_add(u32 drc_index, bool acquire_drc)
 {
 	struct device_node *dn, *parent;
 	int rc, saved_rc;
@@ -457,19 +457,22 @@  static ssize_t dlpar_cpu_add(u32 drc_index)
 		return -EINVAL;
 	}
 
-	rc = dlpar_acquire_drc(drc_index);
-	if (rc) {
-		pr_warn("Failed to acquire DRC, rc: %d, drc index: %x\n",
-			rc, drc_index);
-		of_node_put(parent);
-		return -EINVAL;
+	if (acquire_drc) {
+		rc = dlpar_acquire_drc(drc_index);
+		if (rc) {
+			pr_warn("Failed to acquire DRC, rc: %d, drc index: %x\n",
+				rc, drc_index);
+			of_node_put(parent);
+			return -EINVAL;
+		}
 	}
 
 	dn = dlpar_configure_connector(cpu_to_be32(drc_index), parent);
 	if (!dn) {
 		pr_warn("Failed call to configure-connector, drc index: %x\n",
 			drc_index);
-		dlpar_release_drc(drc_index);
+		if (acquire_drc)
+			dlpar_release_drc(drc_index);
 		of_node_put(parent);
 		return -EINVAL;
 	}
@@ -484,8 +487,9 @@  static ssize_t dlpar_cpu_add(u32 drc_index)
 		pr_warn("Failed to attach node %s, rc: %d, drc index: %x\n",
 			dn->name, rc, drc_index);
 
-		rc = dlpar_release_drc(drc_index);
-		if (!rc)
+		if (acquire_drc)
+			rc = dlpar_release_drc(drc_index);
+		if (!rc || acquire_drc)
 			dlpar_free_cc_nodes(dn);
 
 		return saved_rc;
@@ -498,7 +502,7 @@  static ssize_t dlpar_cpu_add(u32 drc_index)
 			dn->name, rc, drc_index);
 
 		rc = dlpar_detach_node(dn);
-		if (!rc)
+		if (!rc && acquire_drc)
 			dlpar_release_drc(drc_index);
 
 		return saved_rc;
@@ -566,7 +570,8 @@  static int dlpar_offline_cpu(struct device_node *dn)
 
 }
 
-static ssize_t dlpar_cpu_remove(struct device_node *dn, u32 drc_index)
+static ssize_t dlpar_cpu_remove(struct device_node *dn, u32 drc_index,
+				bool release_drc)
 {
 	int rc;
 
@@ -579,12 +584,14 @@  static ssize_t dlpar_cpu_remove(struct device_node *dn, u32 drc_index)
 		return -EINVAL;
 	}
 
-	rc = dlpar_release_drc(drc_index);
-	if (rc) {
-		pr_warn("Failed to release drc (%x) for CPU %s, rc: %d\n",
-			drc_index, dn->name, rc);
-		dlpar_online_cpu(dn);
-		return rc;
+	if (release_drc) {
+		rc = dlpar_release_drc(drc_index);
+		if (rc) {
+			pr_warn("Failed to release drc (%x) for CPU %s, rc: %d\n",
+				drc_index, dn->name, rc);
+			dlpar_online_cpu(dn);
+			return rc;
+		}
 	}
 
 	rc = dlpar_detach_node(dn);
@@ -593,7 +600,10 @@  static ssize_t dlpar_cpu_remove(struct device_node *dn, u32 drc_index)
 
 		pr_warn("Failed to detach CPU %s, rc: %d", dn->name, rc);
 
-		rc = dlpar_acquire_drc(drc_index);
+		if (release_drc)
+			rc = dlpar_acquire_drc(drc_index);
+		else
+			rc = 0;
 		if (!rc)
 			dlpar_online_cpu(dn);
 
@@ -622,7 +632,7 @@  static struct device_node *cpu_drc_index_to_dn(u32 drc_index)
 	return dn;
 }
 
-static int dlpar_cpu_remove_by_index(u32 drc_index)
+static int dlpar_cpu_remove_by_index(u32 drc_index, bool release_drc)
 {
 	struct device_node *dn;
 	int rc;
@@ -634,7 +644,7 @@  static int dlpar_cpu_remove_by_index(u32 drc_index)
 		return -ENODEV;
 	}
 
-	rc = dlpar_cpu_remove(dn, drc_index);
+	rc = dlpar_cpu_remove(dn, drc_index, release_drc);
 	of_node_put(dn);
 	return rc;
 }
@@ -699,7 +709,7 @@  static int dlpar_cpu_remove_by_count(u32 cpus_to_remove)
 	}
 
 	for (i = 0; i < cpus_to_remove; i++) {
-		rc = dlpar_cpu_remove_by_index(cpu_drcs[i]);
+		rc = dlpar_cpu_remove_by_index(cpu_drcs[i], true);
 		if (rc)
 			break;
 
@@ -710,7 +720,7 @@  static int dlpar_cpu_remove_by_count(u32 cpus_to_remove)
 		pr_warn("CPU hot-remove failed, adding back removed CPUs\n");
 
 		for (i = 0; i < cpus_removed; i++)
-			dlpar_cpu_add(cpu_drcs[i]);
+			dlpar_cpu_add(cpu_drcs[i], true);
 
 		rc = -EINVAL;
 	} else {
@@ -780,7 +790,7 @@  static int dlpar_cpu_add_by_count(u32 cpus_to_add)
 	}
 
 	for (i = 0; i < cpus_to_add; i++) {
-		rc = dlpar_cpu_add(cpu_drcs[i]);
+		rc = dlpar_cpu_add(cpu_drcs[i], true);
 		if (rc)
 			break;
 
@@ -791,7 +801,7 @@  static int dlpar_cpu_add_by_count(u32 cpus_to_add)
 		pr_warn("CPU hot-add failed, removing any added CPUs\n");
 
 		for (i = 0; i < cpus_added; i++)
-			dlpar_cpu_remove_by_index(cpu_drcs[i]);
+			dlpar_cpu_remove_by_index(cpu_drcs[i], true);
 
 		rc = -EINVAL;
 	} else {
@@ -817,7 +827,7 @@  int dlpar_cpu(struct pseries_hp_errorlog *hp_elog)
 		if (hp_elog->id_type == PSERIES_HP_ELOG_ID_DRC_COUNT)
 			rc = dlpar_cpu_remove_by_count(count);
 		else if (hp_elog->id_type == PSERIES_HP_ELOG_ID_DRC_INDEX)
-			rc = dlpar_cpu_remove_by_index(drc_index);
+			rc = dlpar_cpu_remove_by_index(drc_index, true);
 		else
 			rc = -EINVAL;
 		break;
@@ -825,7 +835,7 @@  int dlpar_cpu(struct pseries_hp_errorlog *hp_elog)
 		if (hp_elog->id_type == PSERIES_HP_ELOG_ID_DRC_COUNT)
 			rc = dlpar_cpu_add_by_count(count);
 		else if (hp_elog->id_type == PSERIES_HP_ELOG_ID_DRC_INDEX)
-			rc = dlpar_cpu_add(drc_index);
+			rc = dlpar_cpu_add(drc_index, true);
 		else
 			rc = -EINVAL;
 		break;
@@ -850,7 +860,7 @@  static ssize_t dlpar_cpu_probe(const char *buf, size_t count)
 	if (rc)
 		return -EINVAL;
 
-	rc = dlpar_cpu_add(drc_index);
+	rc = dlpar_cpu_add(drc_index, true);
 
 	return rc ? rc : count;
 }
@@ -871,7 +881,7 @@  static ssize_t dlpar_cpu_release(const char *buf, size_t count)
 		return -EINVAL;
 	}
 
-	rc = dlpar_cpu_remove(dn, drc_index);
+	rc = dlpar_cpu_remove(dn, drc_index, true);
 	of_node_put(dn);
 
 	return rc ? rc : count;