linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] powerpc/xive: 2 small tweaks in 'xive_irq_bitmap_add()'
@ 2019-08-01  8:31 Christophe JAILLET
  2019-08-01  8:32 ` [PATCH 1/2] powerpc/xive: Use GFP_KERNEL instead of GFP_ATOMIC " Christophe JAILLET
  2019-08-01  8:32 ` [PATCH 2/2] powerpc/xive: Add a check for memory allocation failure Christophe JAILLET
  0 siblings, 2 replies; 7+ messages in thread
From: Christophe JAILLET @ 2019-08-01  8:31 UTC (permalink / raw)
  To: benh, paulus, mpe, allison, tglx, clg, groug
  Cc: linuxppc-dev, linux-kernel, kernel-janitors, Christophe JAILLET

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(-)

-- 
2.20.1


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

* [PATCH 1/2] powerpc/xive: Use GFP_KERNEL instead of GFP_ATOMIC in 'xive_irq_bitmap_add()'
  2019-08-01  8:31 [PATCH 0/2] powerpc/xive: 2 small tweaks in 'xive_irq_bitmap_add()' Christophe JAILLET
@ 2019-08-01  8:32 ` Christophe JAILLET
  2019-08-01  8:58   ` Cédric Le Goater
                     ` (2 more replies)
  2019-08-01  8:32 ` [PATCH 2/2] powerpc/xive: Add a check for memory allocation failure Christophe JAILLET
  1 sibling, 3 replies; 7+ messages in thread
From: Christophe JAILLET @ 2019-08-01  8:32 UTC (permalink / raw)
  To: benh, paulus, mpe, allison, tglx, clg, groug
  Cc: linuxppc-dev, linux-kernel, kernel-janitors, 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.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 arch/powerpc/sysdev/xive/spapr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/sysdev/xive/spapr.c b/arch/powerpc/sysdev/xive/spapr.c
index 8ef9cf4ebb1c..b4f5eb9e0f82 100644
--- a/arch/powerpc/sysdev/xive/spapr.c
+++ b/arch/powerpc/sysdev/xive/spapr.c
@@ -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;
 
-- 
2.20.1


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

* [PATCH 2/2] powerpc/xive: Add a check for memory allocation failure
  2019-08-01  8:31 [PATCH 0/2] powerpc/xive: 2 small tweaks in 'xive_irq_bitmap_add()' Christophe JAILLET
  2019-08-01  8:32 ` [PATCH 1/2] powerpc/xive: Use GFP_KERNEL instead of GFP_ATOMIC " Christophe JAILLET
@ 2019-08-01  8:32 ` Christophe JAILLET
  2019-08-01  9:41   ` Greg Kurz
  1 sibling, 1 reply; 7+ messages in thread
From: Christophe JAILLET @ 2019-08-01  8:32 UTC (permalink / raw)
  To: benh, paulus, mpe, allison, tglx, clg, groug
  Cc: linuxppc-dev, linux-kernel, kernel-janitors, Christophe JAILLET

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

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
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(+)

diff --git a/arch/powerpc/sysdev/xive/spapr.c b/arch/powerpc/sysdev/xive/spapr.c
index b4f5eb9e0f82..52198131c75e 100644
--- a/arch/powerpc/sysdev/xive/spapr.c
+++ b/arch/powerpc/sysdev/xive/spapr.c
@@ -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,
-- 
2.20.1


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

* Re: [PATCH 1/2] powerpc/xive: Use GFP_KERNEL instead of GFP_ATOMIC in 'xive_irq_bitmap_add()'
  2019-08-01  8:32 ` [PATCH 1/2] powerpc/xive: Use GFP_KERNEL instead of GFP_ATOMIC " Christophe JAILLET
@ 2019-08-01  8:58   ` Cédric Le Goater
  2019-08-01  9:23   ` Greg Kurz
  2019-08-10 10:20   ` Michael Ellerman
  2 siblings, 0 replies; 7+ messages in thread
From: Cédric Le Goater @ 2019-08-01  8:58 UTC (permalink / raw)
  To: Christophe JAILLET, benh, paulus, mpe, allison, tglx, groug
  Cc: linuxppc-dev, linux-kernel, kernel-janitors

On 01/08/2019 10:32, Christophe JAILLET wrote:
> 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.
 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>


Reviewed-by: Cédric Le Goater <clg@kaod.org>

Thanks,

C.

> ---
>  arch/powerpc/sysdev/xive/spapr.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/powerpc/sysdev/xive/spapr.c b/arch/powerpc/sysdev/xive/spapr.c
> index 8ef9cf4ebb1c..b4f5eb9e0f82 100644
> --- a/arch/powerpc/sysdev/xive/spapr.c
> +++ b/arch/powerpc/sysdev/xive/spapr.c
> @@ -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;
>  
> 


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

* Re: [PATCH 1/2] powerpc/xive: Use GFP_KERNEL instead of GFP_ATOMIC in 'xive_irq_bitmap_add()'
  2019-08-01  8:32 ` [PATCH 1/2] powerpc/xive: Use GFP_KERNEL instead of GFP_ATOMIC " Christophe JAILLET
  2019-08-01  8:58   ` Cédric Le Goater
@ 2019-08-01  9:23   ` Greg Kurz
  2019-08-10 10:20   ` Michael Ellerman
  2 siblings, 0 replies; 7+ messages in thread
From: Greg Kurz @ 2019-08-01  9:23 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: benh, paulus, mpe, allison, tglx, clg, linuxppc-dev,
	linux-kernel, kernel-janitors

On Thu,  1 Aug 2019 10:32:31 +0200
Christophe JAILLET <christophe.jaillet@wanadoo.fr> wrote:

> 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.
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---

Good catch.

Reviewed-by: Greg Kurz <groug@kaod.org>

>  arch/powerpc/sysdev/xive/spapr.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/powerpc/sysdev/xive/spapr.c b/arch/powerpc/sysdev/xive/spapr.c
> index 8ef9cf4ebb1c..b4f5eb9e0f82 100644
> --- a/arch/powerpc/sysdev/xive/spapr.c
> +++ b/arch/powerpc/sysdev/xive/spapr.c
> @@ -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;
>  


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

* Re: [PATCH 2/2] powerpc/xive: Add a check for memory allocation failure
  2019-08-01  8:32 ` [PATCH 2/2] powerpc/xive: Add a check for memory allocation failure Christophe JAILLET
@ 2019-08-01  9:41   ` Greg Kurz
  0 siblings, 0 replies; 7+ messages in thread
From: Greg Kurz @ 2019-08-01  9:41 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: benh, paulus, mpe, allison, tglx, clg, linuxppc-dev,
	linux-kernel, kernel-janitors

On Thu,  1 Aug 2019 10:32:42 +0200
Christophe JAILLET <christophe.jaillet@wanadoo.fr> wrote:

> The result of this kzalloc is not checked. Add a check and corresponding
> error handling code.
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---

Reviewed-by: Greg Kurz <groug@kaod.org>

> 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.

> 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(+)
> 
> diff --git a/arch/powerpc/sysdev/xive/spapr.c b/arch/powerpc/sysdev/xive/spapr.c
> index b4f5eb9e0f82..52198131c75e 100644
> --- a/arch/powerpc/sysdev/xive/spapr.c
> +++ b/arch/powerpc/sysdev/xive/spapr.c
> @@ -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,


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

* Re: [PATCH 1/2] powerpc/xive: Use GFP_KERNEL instead of GFP_ATOMIC in 'xive_irq_bitmap_add()'
  2019-08-01  8:32 ` [PATCH 1/2] powerpc/xive: Use GFP_KERNEL instead of GFP_ATOMIC " Christophe JAILLET
  2019-08-01  8:58   ` Cédric Le Goater
  2019-08-01  9:23   ` Greg Kurz
@ 2019-08-10 10:20   ` Michael Ellerman
  2 siblings, 0 replies; 7+ messages in thread
From: Michael Ellerman @ 2019-08-10 10:20 UTC (permalink / raw)
  To: Christophe JAILLET, benh, paulus, allison, tglx, clg, groug
  Cc: kernel-janitors, Christophe JAILLET, linuxppc-dev, linux-kernel

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 502 bytes --]

On Thu, 2019-08-01 at 08:32:31 UTC, Christophe JAILLET wrote:
> 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.
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> Reviewed-by: Cédric Le Goater <clg@kaod.org>
> Reviewed-by: Greg Kurz <groug@kaod.org>

Series applied to powerpc next, thanks.

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

cheers

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

end of thread, other threads:[~2019-08-10 10:20 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-01  8:31 [PATCH 0/2] powerpc/xive: 2 small tweaks in 'xive_irq_bitmap_add()' Christophe JAILLET
2019-08-01  8:32 ` [PATCH 1/2] powerpc/xive: Use GFP_KERNEL instead of GFP_ATOMIC " Christophe JAILLET
2019-08-01  8:58   ` Cédric Le Goater
2019-08-01  9:23   ` Greg Kurz
2019-08-10 10:20   ` Michael Ellerman
2019-08-01  8:32 ` [PATCH 2/2] powerpc/xive: Add a check for memory allocation failure Christophe JAILLET
2019-08-01  9:41   ` Greg Kurz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).