All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] powerpc/pseries: cleanups for dlpar_memory_add* functions
@ 2021-06-22 13:39 Daniel Henrique Barboza
  2021-06-22 13:39 ` [PATCH 1/3] powerpc/pseries: skip reserved LMBs in dlpar_memory_add_by_count() Daniel Henrique Barboza
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Daniel Henrique Barboza @ 2021-06-22 13:39 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Daniel Henrique Barboza

Hi,

These are a couple of cleanups for the dlpar_memory_add* functions
that are similar to those I did a month or so ago in
dlpar_memory_remove_by_count and dlpar_memory_remove_by_ic. 



Daniel Henrique Barboza (3):
  powerpc/pseries: skip reserved LMBs in dlpar_memory_add_by_count()
  powerpc/pseries: break early in dlpar_memory_add_by_count() loops
  powerpc/pseries: fail quicker in dlpar_memory_add_by_ic()

 .../platforms/pseries/hotplug-memory.c        | 34 ++++++++++++-------
 1 file changed, 21 insertions(+), 13 deletions(-)

-- 
2.31.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/3] powerpc/pseries: skip reserved LMBs in dlpar_memory_add_by_count()
  2021-06-22 13:39 [PATCH 0/3] powerpc/pseries: cleanups for dlpar_memory_add* functions Daniel Henrique Barboza
@ 2021-06-22 13:39 ` Daniel Henrique Barboza
  2021-06-24  8:39   ` Laurent Dufour
  2021-06-22 13:39 ` [PATCH 2/3] powerpc/pseries: break early in dlpar_memory_add_by_count() loops Daniel Henrique Barboza
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 9+ messages in thread
From: Daniel Henrique Barboza @ 2021-06-22 13:39 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Daniel Henrique Barboza

The function is counting reserved LMBs as available to be added, but
they aren't. This will cause the function to miscalculate the available
LMBs and can trigger errors later on when executing dlpar_add_lmb().

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
---
 arch/powerpc/platforms/pseries/hotplug-memory.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/powerpc/platforms/pseries/hotplug-memory.c b/arch/powerpc/platforms/pseries/hotplug-memory.c
index 36f66556a7c6..28a7fd90232f 100644
--- a/arch/powerpc/platforms/pseries/hotplug-memory.c
+++ b/arch/powerpc/platforms/pseries/hotplug-memory.c
@@ -683,6 +683,9 @@ static int dlpar_memory_add_by_count(u32 lmbs_to_add)
 
 	/* Validate that there are enough LMBs to satisfy the request */
 	for_each_drmem_lmb(lmb) {
+		if (lmb->flags & DRCONF_MEM_RESERVED)
+			continue;
+
 		if (!(lmb->flags & DRCONF_MEM_ASSIGNED))
 			lmbs_available++;
 
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/3] powerpc/pseries: break early in dlpar_memory_add_by_count() loops
  2021-06-22 13:39 [PATCH 0/3] powerpc/pseries: cleanups for dlpar_memory_add* functions Daniel Henrique Barboza
  2021-06-22 13:39 ` [PATCH 1/3] powerpc/pseries: skip reserved LMBs in dlpar_memory_add_by_count() Daniel Henrique Barboza
@ 2021-06-22 13:39 ` Daniel Henrique Barboza
  2021-06-24  8:45   ` Laurent Dufour
  2021-06-25  6:21   ` Michael Ellerman
  2021-06-22 13:39 ` [PATCH 3/3] powerpc/pseries: fail quicker in dlpar_memory_add_by_ic() Daniel Henrique Barboza
  2021-06-25  6:21 ` [PATCH 0/3] powerpc/pseries: cleanups for dlpar_memory_add* functions Michael Ellerman
  3 siblings, 2 replies; 9+ messages in thread
From: Daniel Henrique Barboza @ 2021-06-22 13:39 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Daniel Henrique Barboza

After a successful dlpar_add_lmb() call the LMB is marked as reserved.
Later on, depending whether we added enough LMBs or not, we rely on
the marked LMBs to see which ones might need to be removed, and we
remove the reservation of all of them.

These are done in for_each_drmem_lmb() loops without any break
condition. This means that we're going to check all LMBs of the partition
even after going through all the reserved ones.

This patch adds break conditions in both loops to avoid this. The
'lmbs_added' variable was renamed to 'lmbs_reserved', and it's now
being decremented each time a lmb reservation is removed, indicating
if there are still marked LMBs to be processed.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
---
 arch/powerpc/platforms/pseries/hotplug-memory.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/platforms/pseries/hotplug-memory.c b/arch/powerpc/platforms/pseries/hotplug-memory.c
index 28a7fd90232f..c0a03e1537cb 100644
--- a/arch/powerpc/platforms/pseries/hotplug-memory.c
+++ b/arch/powerpc/platforms/pseries/hotplug-memory.c
@@ -673,7 +673,7 @@ static int dlpar_memory_add_by_count(u32 lmbs_to_add)
 {
 	struct drmem_lmb *lmb;
 	int lmbs_available = 0;
-	int lmbs_added = 0;
+	int lmbs_reserved = 0;
 	int rc;
 
 	pr_info("Attempting to hot-add %d LMB(s)\n", lmbs_to_add);
@@ -714,13 +714,12 @@ static int dlpar_memory_add_by_count(u32 lmbs_to_add)
 		 * requested LMBs cannot be added.
 		 */
 		drmem_mark_lmb_reserved(lmb);
-
-		lmbs_added++;
-		if (lmbs_added == lmbs_to_add)
+		lmbs_reserved++;
+		if (lmbs_reserved == lmbs_to_add)
 			break;
 	}
 
-	if (lmbs_added != lmbs_to_add) {
+	if (lmbs_reserved != lmbs_to_add) {
 		pr_err("Memory hot-add failed, removing any added LMBs\n");
 
 		for_each_drmem_lmb(lmb) {
@@ -735,6 +734,10 @@ static int dlpar_memory_add_by_count(u32 lmbs_to_add)
 				dlpar_release_drc(lmb->drc_index);
 
 			drmem_remove_lmb_reservation(lmb);
+			lmbs_reserved--;
+
+			if (lmbs_reserved == 0)
+				break;
 		}
 		rc = -EINVAL;
 	} else {
@@ -745,6 +748,10 @@ static int dlpar_memory_add_by_count(u32 lmbs_to_add)
 			pr_debug("Memory at %llx (drc index %x) was hot-added\n",
 				 lmb->base_addr, lmb->drc_index);
 			drmem_remove_lmb_reservation(lmb);
+			lmbs_reserved--;
+
+			if (lmbs_reserved == 0)
+				break;
 		}
 		rc = 0;
 	}
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 3/3] powerpc/pseries: fail quicker in dlpar_memory_add_by_ic()
  2021-06-22 13:39 [PATCH 0/3] powerpc/pseries: cleanups for dlpar_memory_add* functions Daniel Henrique Barboza
  2021-06-22 13:39 ` [PATCH 1/3] powerpc/pseries: skip reserved LMBs in dlpar_memory_add_by_count() Daniel Henrique Barboza
  2021-06-22 13:39 ` [PATCH 2/3] powerpc/pseries: break early in dlpar_memory_add_by_count() loops Daniel Henrique Barboza
@ 2021-06-22 13:39 ` Daniel Henrique Barboza
  2021-06-24  8:48   ` Laurent Dufour
  2021-06-25  6:21 ` [PATCH 0/3] powerpc/pseries: cleanups for dlpar_memory_add* functions Michael Ellerman
  3 siblings, 1 reply; 9+ messages in thread
From: Daniel Henrique Barboza @ 2021-06-22 13:39 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Daniel Henrique Barboza

The validation done at the start of dlpar_memory_add_by_ic() is an all
of nothing scenario - if any LMBs in the range is marked as RESERVED we
can fail right away.

We then can remove the 'lmbs_available' var and its check with
'lmbs_to_add' since the whole LMB range was already validated in the
previous step.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
---
 arch/powerpc/platforms/pseries/hotplug-memory.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/arch/powerpc/platforms/pseries/hotplug-memory.c b/arch/powerpc/platforms/pseries/hotplug-memory.c
index c0a03e1537cb..377d852f5a9a 100644
--- a/arch/powerpc/platforms/pseries/hotplug-memory.c
+++ b/arch/powerpc/platforms/pseries/hotplug-memory.c
@@ -796,7 +796,6 @@ static int dlpar_memory_add_by_index(u32 drc_index)
 static int dlpar_memory_add_by_ic(u32 lmbs_to_add, u32 drc_index)
 {
 	struct drmem_lmb *lmb, *start_lmb, *end_lmb;
-	int lmbs_available = 0;
 	int rc;
 
 	pr_info("Attempting to hot-add %u LMB(s) at index %x\n",
@@ -811,15 +810,14 @@ static int dlpar_memory_add_by_ic(u32 lmbs_to_add, u32 drc_index)
 
 	/* Validate that the LMBs in this range are not reserved */
 	for_each_drmem_lmb_in_range(lmb, start_lmb, end_lmb) {
-		if (lmb->flags & DRCONF_MEM_RESERVED)
-			break;
-
-		lmbs_available++;
+		/* Fail immediately if the whole range can't be hot-added */
+		if (lmb->flags & DRCONF_MEM_RESERVED) {
+			pr_err("Memory at %llx (drc index %x) is reserved\n",
+					lmb->base_addr, lmb->drc_index);
+			return -EINVAL;
+		}
 	}
 
-	if (lmbs_available < lmbs_to_add)
-		return -EINVAL;
-
 	for_each_drmem_lmb_in_range(lmb, start_lmb, end_lmb) {
 		if (lmb->flags & DRCONF_MEM_ASSIGNED)
 			continue;
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/3] powerpc/pseries: skip reserved LMBs in dlpar_memory_add_by_count()
  2021-06-22 13:39 ` [PATCH 1/3] powerpc/pseries: skip reserved LMBs in dlpar_memory_add_by_count() Daniel Henrique Barboza
@ 2021-06-24  8:39   ` Laurent Dufour
  0 siblings, 0 replies; 9+ messages in thread
From: Laurent Dufour @ 2021-06-24  8:39 UTC (permalink / raw)
  To: Daniel Henrique Barboza, linuxppc-dev

Le 22/06/2021 à 15:39, Daniel Henrique Barboza a écrit :
> The function is counting reserved LMBs as available to be added, but
> they aren't. This will cause the function to miscalculate the available
> LMBs and can trigger errors later on when executing dlpar_add_lmb().

Indeed I'm wondering if dlpar_add_lmb() would fail in that case, so that's even 
better to check for that flag earlier.

Reviewed-by: Laurent Dufour <ldufour@linux.ibm.com>

> Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
> ---
>   arch/powerpc/platforms/pseries/hotplug-memory.c | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/arch/powerpc/platforms/pseries/hotplug-memory.c b/arch/powerpc/platforms/pseries/hotplug-memory.c
> index 36f66556a7c6..28a7fd90232f 100644
> --- a/arch/powerpc/platforms/pseries/hotplug-memory.c
> +++ b/arch/powerpc/platforms/pseries/hotplug-memory.c
> @@ -683,6 +683,9 @@ static int dlpar_memory_add_by_count(u32 lmbs_to_add)
>   
>   	/* Validate that there are enough LMBs to satisfy the request */
>   	for_each_drmem_lmb(lmb) {
> +		if (lmb->flags & DRCONF_MEM_RESERVED)
> +			continue;
> +
>   		if (!(lmb->flags & DRCONF_MEM_ASSIGNED))
>   			lmbs_available++;
>   
> 


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/3] powerpc/pseries: break early in dlpar_memory_add_by_count() loops
  2021-06-22 13:39 ` [PATCH 2/3] powerpc/pseries: break early in dlpar_memory_add_by_count() loops Daniel Henrique Barboza
@ 2021-06-24  8:45   ` Laurent Dufour
  2021-06-25  6:21   ` Michael Ellerman
  1 sibling, 0 replies; 9+ messages in thread
From: Laurent Dufour @ 2021-06-24  8:45 UTC (permalink / raw)
  To: Daniel Henrique Barboza, linuxppc-dev

Le 22/06/2021 à 15:39, Daniel Henrique Barboza a écrit :
> After a successful dlpar_add_lmb() call the LMB is marked as reserved.
> Later on, depending whether we added enough LMBs or not, we rely on
> the marked LMBs to see which ones might need to be removed, and we
> remove the reservation of all of them.
> 
> These are done in for_each_drmem_lmb() loops without any break
> condition. This means that we're going to check all LMBs of the partition
> even after going through all the reserved ones.
> 
> This patch adds break conditions in both loops to avoid this. The
> 'lmbs_added' variable was renamed to 'lmbs_reserved', and it's now
> being decremented each time a lmb reservation is removed, indicating
> if there are still marked LMBs to be processed.

Reviewed-by: Laurent Dufour <ldufour@linux.ibm.com>

> Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
> ---
>   arch/powerpc/platforms/pseries/hotplug-memory.c | 17 ++++++++++++-----
>   1 file changed, 12 insertions(+), 5 deletions(-)
> 
> diff --git a/arch/powerpc/platforms/pseries/hotplug-memory.c b/arch/powerpc/platforms/pseries/hotplug-memory.c
> index 28a7fd90232f..c0a03e1537cb 100644
> --- a/arch/powerpc/platforms/pseries/hotplug-memory.c
> +++ b/arch/powerpc/platforms/pseries/hotplug-memory.c
> @@ -673,7 +673,7 @@ static int dlpar_memory_add_by_count(u32 lmbs_to_add)
>   {
>   	struct drmem_lmb *lmb;
>   	int lmbs_available = 0;
> -	int lmbs_added = 0;
> +	int lmbs_reserved = 0;
>   	int rc;
>   
>   	pr_info("Attempting to hot-add %d LMB(s)\n", lmbs_to_add);
> @@ -714,13 +714,12 @@ static int dlpar_memory_add_by_count(u32 lmbs_to_add)
>   		 * requested LMBs cannot be added.
>   		 */
>   		drmem_mark_lmb_reserved(lmb);
> -
> -		lmbs_added++;
> -		if (lmbs_added == lmbs_to_add)
> +		lmbs_reserved++;
> +		if (lmbs_reserved == lmbs_to_add)
>   			break;
>   	}
>   
> -	if (lmbs_added != lmbs_to_add) {
> +	if (lmbs_reserved != lmbs_to_add) {
>   		pr_err("Memory hot-add failed, removing any added LMBs\n");
>   
>   		for_each_drmem_lmb(lmb) {
> @@ -735,6 +734,10 @@ static int dlpar_memory_add_by_count(u32 lmbs_to_add)
>   				dlpar_release_drc(lmb->drc_index);
>   
>   			drmem_remove_lmb_reservation(lmb);
> +			lmbs_reserved--;
> +
> +			if (lmbs_reserved == 0)
> +				break;
>   		}
>   		rc = -EINVAL;
>   	} else {
> @@ -745,6 +748,10 @@ static int dlpar_memory_add_by_count(u32 lmbs_to_add)
>   			pr_debug("Memory at %llx (drc index %x) was hot-added\n",
>   				 lmb->base_addr, lmb->drc_index);
>   			drmem_remove_lmb_reservation(lmb);
> +			lmbs_reserved--;
> +
> +			if (lmbs_reserved == 0)
> +				break;
>   		}
>   		rc = 0;
>   	}
> 


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 3/3] powerpc/pseries: fail quicker in dlpar_memory_add_by_ic()
  2021-06-22 13:39 ` [PATCH 3/3] powerpc/pseries: fail quicker in dlpar_memory_add_by_ic() Daniel Henrique Barboza
@ 2021-06-24  8:48   ` Laurent Dufour
  0 siblings, 0 replies; 9+ messages in thread
From: Laurent Dufour @ 2021-06-24  8:48 UTC (permalink / raw)
  To: Daniel Henrique Barboza, linuxppc-dev

Le 22/06/2021 à 15:39, Daniel Henrique Barboza a écrit :
> The validation done at the start of dlpar_memory_add_by_ic() is an all
> of nothing scenario - if any LMBs in the range is marked as RESERVED we
> can fail right away.
> 
> We then can remove the 'lmbs_available' var and its check with
> 'lmbs_to_add' since the whole LMB range was already validated in the
> previous step.

Reviewed-by: Laurent Dufour <ldufour@linux.ibm.com>

> Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
> ---
>   arch/powerpc/platforms/pseries/hotplug-memory.c | 14 ++++++--------
>   1 file changed, 6 insertions(+), 8 deletions(-)
> 
> diff --git a/arch/powerpc/platforms/pseries/hotplug-memory.c b/arch/powerpc/platforms/pseries/hotplug-memory.c
> index c0a03e1537cb..377d852f5a9a 100644
> --- a/arch/powerpc/platforms/pseries/hotplug-memory.c
> +++ b/arch/powerpc/platforms/pseries/hotplug-memory.c
> @@ -796,7 +796,6 @@ static int dlpar_memory_add_by_index(u32 drc_index)
>   static int dlpar_memory_add_by_ic(u32 lmbs_to_add, u32 drc_index)
>   {
>   	struct drmem_lmb *lmb, *start_lmb, *end_lmb;
> -	int lmbs_available = 0;
>   	int rc;
>   
>   	pr_info("Attempting to hot-add %u LMB(s) at index %x\n",
> @@ -811,15 +810,14 @@ static int dlpar_memory_add_by_ic(u32 lmbs_to_add, u32 drc_index)
>   
>   	/* Validate that the LMBs in this range are not reserved */
>   	for_each_drmem_lmb_in_range(lmb, start_lmb, end_lmb) {
> -		if (lmb->flags & DRCONF_MEM_RESERVED)
> -			break;
> -
> -		lmbs_available++;
> +		/* Fail immediately if the whole range can't be hot-added */
> +		if (lmb->flags & DRCONF_MEM_RESERVED) {
> +			pr_err("Memory at %llx (drc index %x) is reserved\n",
> +					lmb->base_addr, lmb->drc_index);
> +			return -EINVAL;
> +		}
>   	}
>   
> -	if (lmbs_available < lmbs_to_add)
> -		return -EINVAL;
> -
>   	for_each_drmem_lmb_in_range(lmb, start_lmb, end_lmb) {
>   		if (lmb->flags & DRCONF_MEM_ASSIGNED)
>   			continue;
> 


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 0/3] powerpc/pseries: cleanups for dlpar_memory_add* functions
  2021-06-22 13:39 [PATCH 0/3] powerpc/pseries: cleanups for dlpar_memory_add* functions Daniel Henrique Barboza
                   ` (2 preceding siblings ...)
  2021-06-22 13:39 ` [PATCH 3/3] powerpc/pseries: fail quicker in dlpar_memory_add_by_ic() Daniel Henrique Barboza
@ 2021-06-25  6:21 ` Michael Ellerman
  3 siblings, 0 replies; 9+ messages in thread
From: Michael Ellerman @ 2021-06-25  6:21 UTC (permalink / raw)
  To: Daniel Henrique Barboza, linuxppc-dev

On Tue, 22 Jun 2021 10:39:20 -0300, Daniel Henrique Barboza wrote:
> These are a couple of cleanups for the dlpar_memory_add* functions
> that are similar to those I did a month or so ago in
> dlpar_memory_remove_by_count and dlpar_memory_remove_by_ic.
> 
> 
> 
> Daniel Henrique Barboza (3):
>   powerpc/pseries: skip reserved LMBs in dlpar_memory_add_by_count()
>   powerpc/pseries: break early in dlpar_memory_add_by_count() loops
>   powerpc/pseries: fail quicker in dlpar_memory_add_by_ic()
> 
> [...]

Applied to powerpc/next.

[1/3] powerpc/pseries: skip reserved LMBs in dlpar_memory_add_by_count()
      https://git.kernel.org/powerpc/c/b3e3b4db7a9bafdd81735e6f8db0c5ee9b9d0b5f
[2/3] powerpc/pseries: break early in dlpar_memory_add_by_count() loops
      https://git.kernel.org/powerpc/c/c2aaddcc65b343fad4ed184e625abd3e68f63b9b
[3/3] powerpc/pseries: fail quicker in dlpar_memory_add_by_ic()
      https://git.kernel.org/powerpc/c/0e5962b2ec3d07204fd995ed07870bff3322525c

cheers

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/3] powerpc/pseries: break early in dlpar_memory_add_by_count() loops
  2021-06-22 13:39 ` [PATCH 2/3] powerpc/pseries: break early in dlpar_memory_add_by_count() loops Daniel Henrique Barboza
  2021-06-24  8:45   ` Laurent Dufour
@ 2021-06-25  6:21   ` Michael Ellerman
  1 sibling, 0 replies; 9+ messages in thread
From: Michael Ellerman @ 2021-06-25  6:21 UTC (permalink / raw)
  To: Daniel Henrique Barboza, linuxppc-dev

On Tue, 22 Jun 2021 10:39:22 -0300, Daniel Henrique Barboza wrote:
> After a successful dlpar_add_lmb() call the LMB is marked as reserved.
> Later on, depending whether we added enough LMBs or not, we rely on
> the marked LMBs to see which ones might need to be removed, and we
> remove the reservation of all of them.
> 
> These are done in for_each_drmem_lmb() loops without any break
> condition. This means that we're going to check all LMBs of the partition
> even after going through all the reserved ones.
> 
> [...]

Applied to powerpc/next.

[2/3] powerpc/pseries: break early in dlpar_memory_add_by_count() loops
      https://git.kernel.org/powerpc/c/c2aaddcc65b343fad4ed184e625abd3e68f63b9b

cheers

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-06-25  6:25 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-22 13:39 [PATCH 0/3] powerpc/pseries: cleanups for dlpar_memory_add* functions Daniel Henrique Barboza
2021-06-22 13:39 ` [PATCH 1/3] powerpc/pseries: skip reserved LMBs in dlpar_memory_add_by_count() Daniel Henrique Barboza
2021-06-24  8:39   ` Laurent Dufour
2021-06-22 13:39 ` [PATCH 2/3] powerpc/pseries: break early in dlpar_memory_add_by_count() loops Daniel Henrique Barboza
2021-06-24  8:45   ` Laurent Dufour
2021-06-25  6:21   ` Michael Ellerman
2021-06-22 13:39 ` [PATCH 3/3] powerpc/pseries: fail quicker in dlpar_memory_add_by_ic() Daniel Henrique Barboza
2021-06-24  8:48   ` Laurent Dufour
2021-06-25  6:21 ` [PATCH 0/3] powerpc/pseries: cleanups for dlpar_memory_add* functions Michael Ellerman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.