Skip to contentSkip to conversation

powerpc/xive: 2 small tweaks in 'xive_irq_bitmap_add()'

PATCH In review Christophe JAILLET 4 participants 7 messages Aug 1, 2019 – Aug 10, 2019

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

cover powerpc/xive: 2 small tweaks in 'xive_irq_bitmap_add()'

The first patch uses GFP_KERNEL instead of GFP_ATOMIC. The 2nd adds a check for memory allocation failure.

Christophe JAILLET (2):
powerpc/xive: Use GFP_KERNEL instead of GFP_ATOMIC in

    'xive_irq_bitmap_add()'

powerpc/xive: Add a check for memory allocation failure

 arch/powerpc/sysdev/xive/spapr.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/2 powerpc/xive: Use GFP_KERNEL instead of GFP_ATOMIC in 'xive_irq_bitmap_add()'

There is no need to use GFP_ATOMIC here. GFP_KERNEL should be enough. GFP_KERNEL is also already used for another allocation just a few lines below.

---
 arch/powerpc/sysdev/xive/spapr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/sysdev/xive/spapr.c +1 -1
index 8ef9cf4ebb1c..b4f5eb9e0f82 100644
@@ -45,7 +45,7 @@ static int xive_irq_bitmap_add(int base, int count)
 {
 	struct xive_irq_bitmap *xibm;
 
-	xibm = kzalloc(sizeof(*xibm), GFP_ATOMIC);
+	xibm = kzalloc(sizeof(*xibm), GFP_KERNEL);
 	if (!xibm)
 		return -ENOMEM;
 
Signature · 1 line
2.20.1
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] powerpc/xive: Use GFP_KERNEL instead of GFP_ATOMIC in 'xive_irq_bitmap_add()'

Quoted 3 lines · Christophe JAILLET

There is no need to use GFP_ATOMIC here. GFP_KERNEL should be enough. GFP_KERNEL is also already used for another allocation just a few lines below.

This is correct.

Quoted 1 line

Thanks,

C.

Quoted 18 lines
---
 arch/powerpc/sysdev/xive/spapr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/sysdev/xive/spapr.c +1 -1
index 8ef9cf4ebb1c..b4f5eb9e0f82 100644
@@ -45,7 +45,7 @@ static int xive_irq_bitmap_add(int base, int count)
 {
 	struct xive_irq_bitmap *xibm;
 
-	xibm = kzalloc(sizeof(*xibm), GFP_ATOMIC);
+	xibm = kzalloc(sizeof(*xibm), GFP_KERNEL);
 	if (!xibm)
 		return -ENOMEM;
 
Reviewed-by on v1 1/2
#3 lore raw

Re: [PATCH 1/2] powerpc/xive: Use GFP_KERNEL instead of GFP_ATOMIC in 'xive_irq_bitmap_add()'

In reply to Christophe JAILLET
Quoted 6 lines · On Thu, 1 Aug 2019 10:32:31 +0200 Christophe JAILLET…

There is no need to use GFP_ATOMIC here. GFP_KERNEL should be enough. GFP_KERNEL is also already used for another allocation just a few lines below.

---

Good catch.

Quoted 16 lines
 arch/powerpc/sysdev/xive/spapr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/sysdev/xive/spapr.c +1 -1
index 8ef9cf4ebb1c..b4f5eb9e0f82 100644
@@ -45,7 +45,7 @@ static int xive_irq_bitmap_add(int base, int count)
 {
 	struct xive_irq_bitmap *xibm;
 
-	xibm = kzalloc(sizeof(*xibm), GFP_ATOMIC);
+	xibm = kzalloc(sizeof(*xibm), GFP_KERNEL);
 	if (!xibm)
 		return -ENOMEM;
 
#4 lore raw

Re: [PATCH 1/2] powerpc/xive: Use GFP_KERNEL instead of GFP_ATOMIC in 'xive_irq_bitmap_add()'

In reply to Christophe JAILLET
Quoted 7 lines · Christophe JAILLET

There is no need to use GFP_ATOMIC here. GFP_KERNEL should be enough. GFP_KERNEL is also already used for another allocation just a few lines below.

Series applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/2705ec100b46390851542fa97e920cc21ffaac4f

cheers

#5 lore raw

PATCH 2/2 powerpc/xive: Add a check for memory allocation failure

In reply to Christophe JAILLET

The result of this kzalloc is not checked. Add a check and corresponding error handling code.

---
Note that 'xive_irq_bitmap_add()' failures are not handled in 'xive_spapr_init()'
I guess that it is not really an issue. This function is _init, so if a memory allocation occures here, it is likely that the system will already be in bad shape.
Anyway, the check added here would at least keep the data linked in 'xive_irq_bitmaps' usable.

---
 arch/powerpc/sysdev/xive/spapr.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/powerpc/sysdev/xive/spapr.c +4 -0
index b4f5eb9e0f82..52198131c75e 100644
@@ -53,6 +53,10 @@ static int xive_irq_bitmap_add(int base, int count)
 	xibm->base = base;
 	xibm->count = count;
 	xibm->bitmap = kzalloc(xibm->count, GFP_KERNEL);
+	if (!xibm->bitmap) {
+		kfree(xibm);
+		return -ENOMEM;
+	}
 	list_add(&xibm->list, &xive_irq_bitmaps);
 
 	pr_info("Using IRQ range [%x-%x]", xibm->base,
Signature · 1 line
2.20.1
Reviewed-by on v1 2/2
#6 lore raw

Re: [PATCH 2/2] powerpc/xive: Add a check for memory allocation failure

Quoted 5 lines · On Thu, 1 Aug 2019 10:32:42 +0200 Christophe JAILLET…

The result of this kzalloc is not checked. Add a check and corresponding error handling code.

---

Quoted 5 lines

Note that 'xive_irq_bitmap_add()' failures are not handled in 'xive_spapr_init()'
I guess that it is not really an issue. This function is _init, so if a memory allocation occures here, it is likely that the system will already be in bad shape.

Hmm not sure... The allocation could also fail if the "ibm,xive-lisn-ranges" property contains an insanely big range, eg. count = 1 << 31. The system isn't necessarily in bad shape in this case, but XIVE is definitely unusable and we should let a chance to the kernel to switch to XICS in this case.

I guess it is worth adding proper error handling in xive_spapr_init() as well.

Quoted 21 lines

Anyway, the check added here would at least keep the data linked in 'xive_irq_bitmaps' usable.

---
 arch/powerpc/sysdev/xive/spapr.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/powerpc/sysdev/xive/spapr.c +4 -0
index b4f5eb9e0f82..52198131c75e 100644
@@ -53,6 +53,10 @@ static int xive_irq_bitmap_add(int base, int count)
 	xibm->base = base;
 	xibm->count = count;
 	xibm->bitmap = kzalloc(xibm->count, GFP_KERNEL);
+	if (!xibm->bitmap) {
+		kfree(xibm);
+		return -ENOMEM;
+	}
 	list_add(&xibm->list, &xive_irq_bitmaps);
 
 	pr_info("Using IRQ range [%x-%x]", xibm->base,