linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] mtd: ubi: fix improper return value
@ 2016-12-04  6:12 Pan Bian
  2016-12-04 12:48 ` Marek Vasut
  0 siblings, 1 reply; 8+ messages in thread
From: Pan Bian @ 2016-12-04  6:12 UTC (permalink / raw)
  To: Artem Bityutskiy, Richard Weinberger, David Woodhouse,
	Brian Norris, Boris Brezillon, Marek Vasut, Cyrille Pitchen,
	linux-mtd
  Cc: linux-kernel, Pan Bian

From: Pan Bian <bianpan2016@163.com>

When __vmalloc() returns a NULL pointer, the region is not checked, and
we cannot make sure that only 0xFF bytes are present at offset. Thus,
returning 0 seems improper.

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=189081

Signed-off-by: Pan Bian <bianpan2016@163.com>
---
 drivers/mtd/ubi/io.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c
index b6fb8f9..b54fe05 100644
--- a/drivers/mtd/ubi/io.c
+++ b/drivers/mtd/ubi/io.c
@@ -1413,7 +1413,7 @@ int ubi_self_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len)
 	buf = __vmalloc(len, GFP_NOFS, PAGE_KERNEL);
 	if (!buf) {
 		ubi_err(ubi, "cannot allocate memory to check for 0xFFs");
-		return 0;
+		return -ENOMEM;
 	}
 
 	err = mtd_read(ubi->mtd, addr, len, &read, buf);
-- 
1.9.1

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

* Re: [PATCH 1/1] mtd: ubi: fix improper return value
  2016-12-04  6:12 [PATCH 1/1] mtd: ubi: fix improper return value Pan Bian
@ 2016-12-04 12:48 ` Marek Vasut
  2016-12-04 20:33   ` Joe Perches
  0 siblings, 1 reply; 8+ messages in thread
From: Marek Vasut @ 2016-12-04 12:48 UTC (permalink / raw)
  To: Pan Bian, Artem Bityutskiy, Richard Weinberger, David Woodhouse,
	Brian Norris, Boris Brezillon, Cyrille Pitchen, linux-mtd
  Cc: linux-kernel, Pan Bian

On 12/04/2016 07:12 AM, Pan Bian wrote:
> From: Pan Bian <bianpan2016@163.com>
> 
> When __vmalloc() returns a NULL pointer, the region is not checked, and
> we cannot make sure that only 0xFF bytes are present at offset. Thus,
> returning 0 seems improper.
> 
> Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=189081
> 
> Signed-off-by: Pan Bian <bianpan2016@163.com>
> ---
>  drivers/mtd/ubi/io.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c
> index b6fb8f9..b54fe05 100644
> --- a/drivers/mtd/ubi/io.c
> +++ b/drivers/mtd/ubi/io.c
> @@ -1413,7 +1413,7 @@ int ubi_self_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len)
>  	buf = __vmalloc(len, GFP_NOFS, PAGE_KERNEL);
>  	if (!buf) {
>  		ubi_err(ubi, "cannot allocate memory to check for 0xFFs");
> -		return 0;
> +		return -ENOMEM;

I wonder if you shouldn't also nuke the ubi_err() , because when you run
out of memory, printk() will likely also fail.

>  	}
>  
>  	err = mtd_read(ubi->mtd, addr, len, &read, buf);
> 


-- 
Best regards,
Marek Vasut

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

* Re: [PATCH 1/1] mtd: ubi: fix improper return value
  2016-12-04 12:48 ` Marek Vasut
@ 2016-12-04 20:33   ` Joe Perches
  2016-12-04 20:52     ` Richard Weinberger
  2016-12-04 21:36     ` Marek Vasut
  0 siblings, 2 replies; 8+ messages in thread
From: Joe Perches @ 2016-12-04 20:33 UTC (permalink / raw)
  To: Marek Vasut, Pan Bian, Artem Bityutskiy, Richard Weinberger,
	David Woodhouse, Brian Norris, Boris Brezillon, Cyrille Pitchen,
	linux-mtd
  Cc: linux-kernel, Pan Bian

On Sun, 2016-12-04 at 13:48 +0100, Marek Vasut wrote:
> On 12/04/2016 07:12 AM, Pan Bian wrote:
> > From: Pan Bian <bianpan2016@163.com>
> > 
> > When __vmalloc() returns a NULL pointer, the region is not checked, and
> > we cannot make sure that only 0xFF bytes are present at offset. Thus,
> > returning 0 seems improper.
> > 
> > Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=189081
> > 
> > Signed-off-by: Pan Bian <bianpan2016@163.com>
> > ---
> >  drivers/mtd/ubi/io.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c
[]
> > @@ -1413,7 +1413,7 @@ int ubi_self_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len)
> >  	buf = __vmalloc(len, GFP_NOFS, PAGE_KERNEL);
> >  	if (!buf) {
> >  		ubi_err(ubi, "cannot allocate memory to check for 0xFFs");
> > -		return 0;
> > +		return -ENOMEM;
> 
> I wonder if you shouldn't also nuke the ubi_err() , because when you run
> out of memory, printk() will likely also fail.

No, not really.  printk doesn't allocate memory.

But the ubi_err should be removed because all memory
allocations that fail without a specific GFP_NOWARN
flag already have a dump_stack() call.

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

* Re: [PATCH 1/1] mtd: ubi: fix improper return value
  2016-12-04 20:33   ` Joe Perches
@ 2016-12-04 20:52     ` Richard Weinberger
  2016-12-05  7:09       ` Artem Bityutskiy
  2016-12-04 21:36     ` Marek Vasut
  1 sibling, 1 reply; 8+ messages in thread
From: Richard Weinberger @ 2016-12-04 20:52 UTC (permalink / raw)
  To: Joe Perches, Marek Vasut, Pan Bian, Artem Bityutskiy,
	David Woodhouse, Brian Norris, Boris Brezillon, Cyrille Pitchen,
	linux-mtd
  Cc: linux-kernel, Pan Bian

On 04.12.2016 21:33, Joe Perches wrote:
>>> diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c
> []
>>> @@ -1413,7 +1413,7 @@ int ubi_self_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len)
>>>  	buf = __vmalloc(len, GFP_NOFS, PAGE_KERNEL);
>>>  	if (!buf) {
>>>  		ubi_err(ubi, "cannot allocate memory to check for 0xFFs");
>>> -		return 0;
>>> +		return -ENOMEM;
>>
>> I wonder if you shouldn't also nuke the ubi_err() , because when you run
>> out of memory, printk() will likely also fail.
> 
> No, not really.  printk doesn't allocate memory.
> 
> But the ubi_err should be removed because all memory
> allocations that fail without a specific GFP_NOWARN
> flag already have a dump_stack() call.

We should better think about how to get ubi_self_check_all_ff() fixed.
When enabled on a modern NAND, vmalloc() is likely to fail now and then
since len is the erase block size and can be up to a few mega bytes.

Thanks,
//richard

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

* Re: [PATCH 1/1] mtd: ubi: fix improper return value
  2016-12-04 20:33   ` Joe Perches
  2016-12-04 20:52     ` Richard Weinberger
@ 2016-12-04 21:36     ` Marek Vasut
  1 sibling, 0 replies; 8+ messages in thread
From: Marek Vasut @ 2016-12-04 21:36 UTC (permalink / raw)
  To: Joe Perches, Pan Bian, Artem Bityutskiy, Richard Weinberger,
	David Woodhouse, Brian Norris, Boris Brezillon, Cyrille Pitchen,
	linux-mtd
  Cc: linux-kernel, Pan Bian

On 12/04/2016 09:33 PM, Joe Perches wrote:
> On Sun, 2016-12-04 at 13:48 +0100, Marek Vasut wrote:
>> On 12/04/2016 07:12 AM, Pan Bian wrote:
>>> From: Pan Bian <bianpan2016@163.com>
>>>
>>> When __vmalloc() returns a NULL pointer, the region is not checked, and
>>> we cannot make sure that only 0xFF bytes are present at offset. Thus,
>>> returning 0 seems improper.
>>>
>>> Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=189081
>>>
>>> Signed-off-by: Pan Bian <bianpan2016@163.com>
>>> ---
>>>  drivers/mtd/ubi/io.c | 2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c
> []
>>> @@ -1413,7 +1413,7 @@ int ubi_self_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len)
>>>  	buf = __vmalloc(len, GFP_NOFS, PAGE_KERNEL);
>>>  	if (!buf) {
>>>  		ubi_err(ubi, "cannot allocate memory to check for 0xFFs");
>>> -		return 0;
>>> +		return -ENOMEM;
>>
>> I wonder if you shouldn't also nuke the ubi_err() , because when you run
>> out of memory, printk() will likely also fail.
> 
> No, not really.  printk doesn't allocate memory.
> 
> But the ubi_err should be removed because all memory
> allocations that fail without a specific GFP_NOWARN
> flag already have a dump_stack() call.

Ah, thanks for the correction :-)

-- 
Best regards,
Marek Vasut

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

* Re: [PATCH 1/1] mtd: ubi: fix improper return value
  2016-12-04 20:52     ` Richard Weinberger
@ 2016-12-05  7:09       ` Artem Bityutskiy
  2016-12-05  8:23         ` Boris Brezillon
  0 siblings, 1 reply; 8+ messages in thread
From: Artem Bityutskiy @ 2016-12-05  7:09 UTC (permalink / raw)
  To: Richard Weinberger, Joe Perches, Marek Vasut, Pan Bian,
	David Woodhouse, Brian Norris, Boris Brezillon, Cyrille Pitchen,
	linux-mtd
  Cc: linux-kernel, Pan Bian

On Sun, 2016-12-04 at 21:52 +0100, Richard Weinberger wrote:
> We should better think about how to get ubi_self_check_all_ff()
> fixed.
> When enabled on a modern NAND, vmalloc() is likely to fail now and
> then
> since len is the erase block size and can be up to a few mega bytes.

I did an attempt to switch from virtually continuous buffers to an
array of page pointers, but never finished.

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

* Re: [PATCH 1/1] mtd: ubi: fix improper return value
  2016-12-05  7:09       ` Artem Bityutskiy
@ 2016-12-05  8:23         ` Boris Brezillon
  2016-12-05  9:49           ` Artem Bityutskiy
  0 siblings, 1 reply; 8+ messages in thread
From: Boris Brezillon @ 2016-12-05  8:23 UTC (permalink / raw)
  To: Artem Bityutskiy
  Cc: Richard Weinberger, Joe Perches, Marek Vasut, Pan Bian,
	David Woodhouse, Brian Norris, Cyrille Pitchen, linux-mtd,
	linux-kernel, Pan Bian

On Mon, 05 Dec 2016 09:09:34 +0200
Artem Bityutskiy <dedekind1@gmail.com> wrote:

> On Sun, 2016-12-04 at 21:52 +0100, Richard Weinberger wrote:
> > We should better think about how to get ubi_self_check_all_ff()
> > fixed.
> > When enabled on a modern NAND, vmalloc() is likely to fail now and
> > then
> > since len is the erase block size and can be up to a few mega bytes.  
> 
> I did an attempt to switch from virtually continuous buffers to an
> array of page pointers, but never finished.

I started to implement that too but unfortunately never had the time to
finish it :-(.
Don't know why you were trying to move to kzalloc-ed buffer, but my
goal was to avoid the extra copy when the controller transfers data
using DMA, and the recent posts regarding vmalloc-ed buffers and DMA
might solve the issue.

This being said, UBI and UBIFS tend to allocate big portions of
memory (usually a full eraseblock), and sometime this is
overkill.
For example, I'm not sure we need to allocate that much memory to do
things like 'check if this portion is all filled with 0xff'. Allocating
a ->max_write_size buffer and iterating over write-units should be
almost as efficient and still consume less memory. But this has nothing
to do with the vmalloc vs kmalloc debate ;-).

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

* Re: [PATCH 1/1] mtd: ubi: fix improper return value
  2016-12-05  8:23         ` Boris Brezillon
@ 2016-12-05  9:49           ` Artem Bityutskiy
  0 siblings, 0 replies; 8+ messages in thread
From: Artem Bityutskiy @ 2016-12-05  9:49 UTC (permalink / raw)
  To: Boris Brezillon
  Cc: Richard Weinberger, Joe Perches, Marek Vasut, Pan Bian,
	David Woodhouse, Brian Norris, Cyrille Pitchen, linux-mtd,
	linux-kernel, Pan Bian

On Mon, 2016-12-05 at 09:23 +0100, Boris Brezillon wrote:
> I started to implement that too but unfortunately never had the time
> to
> finish it :-(.
> Don't know why you were trying to move to kzalloc-ed buffer, but my
> goal was to avoid the extra copy when the controller transfers data
> using DMA, and the recent posts regarding vmalloc-ed buffers and DMA
> might solve the issue.

Yes, I wanted to do that globally for UBI/UBIFS to get rid of vmalloc.

> This being said, UBI and UBIFS tend to allocate big portions of
> memory (usually a full eraseblock), and sometime this is
> overkill.

Those checks were just hacky debugging functions at the beginning, then
they got cleaned up without a re-write.

> For example, I'm not sure we need to allocate that much memory to do
> things like 'check if this portion is all filled with 0xff'. 

Because memcmp() is was very easy to use. Back then the focus was
getting other things work well, and efforts were saved on less
important parts. And 128KiB was not terribly bad. Today, these less
important things are important.

> Allocating
> a ->max_write_size buffer and iterating over write-units should be
> almost as efficient and still consume less memory. But this has
> nothing
> to do with the vmalloc vs kmalloc debate ;-).

Well, this is related. Someone may start small and take care of these
first :-)

Artem.

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

end of thread, other threads:[~2016-12-05  9:50 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-04  6:12 [PATCH 1/1] mtd: ubi: fix improper return value Pan Bian
2016-12-04 12:48 ` Marek Vasut
2016-12-04 20:33   ` Joe Perches
2016-12-04 20:52     ` Richard Weinberger
2016-12-05  7:09       ` Artem Bityutskiy
2016-12-05  8:23         ` Boris Brezillon
2016-12-05  9:49           ` Artem Bityutskiy
2016-12-04 21:36     ` Marek Vasut

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