2013-05-21 07:13:36

by Oskar Andero

[permalink] [raw]
Subject: [PATCH v2] mm: vmscan: add VM_BUG_ON on illegal return values from scan_objects

Add a VM_BUG_ON to catch any illegal value from the shrinkers. It's a
potential bug if scan_objects returns a negative other than -1 and
would lead to undefined behaviour.

Cc: Glauber Costa <[email protected]>
Cc: Dave Chinner <[email protected]>
Cc: Andrew Morton <[email protected]>
Cc: Hugh Dickins <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Signed-off-by: Oskar Andero <[email protected]>
---
mm/vmscan.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/mm/vmscan.c b/mm/vmscan.c
index 6bac41e..63fec86 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -293,6 +293,7 @@ shrink_slab_one(struct shrinker *shrinker, struct shrink_control *shrinkctl,
ret = shrinker->scan_objects(shrinker, shrinkctl);
if (ret == -1)
break;
+ VM_BUG_ON(ret < -1);
freed += ret;

count_vm_events(SLABS_SCANNED, nr_to_scan);
--
1.8.1.5


2013-05-21 07:17:17

by Pekka Enberg

[permalink] [raw]
Subject: Re: [PATCH v2] mm: vmscan: add VM_BUG_ON on illegal return values from scan_objects

On Tue, May 21, 2013 at 10:13 AM, Oskar Andero
<[email protected]> wrote:
> Add a VM_BUG_ON to catch any illegal value from the shrinkers. It's a
> potential bug if scan_objects returns a negative other than -1 and
> would lead to undefined behaviour.
>
> Cc: Glauber Costa <[email protected]>
> Cc: Dave Chinner <[email protected]>
> Cc: Andrew Morton <[email protected]>
> Cc: Hugh Dickins <[email protected]>
> Cc: Greg Kroah-Hartman <[email protected]>
> Signed-off-by: Oskar Andero <[email protected]>
> ---
> mm/vmscan.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/mm/vmscan.c b/mm/vmscan.c
> index 6bac41e..63fec86 100644
> --- a/mm/vmscan.c
> +++ b/mm/vmscan.c
> @@ -293,6 +293,7 @@ shrink_slab_one(struct shrinker *shrinker, struct shrink_control *shrinkctl,
> ret = shrinker->scan_objects(shrinker, shrinkctl);
> if (ret == -1)
> break;
> + VM_BUG_ON(ret < -1);

It seems to me relaxing the shrinker API restrictions and changing the
"ret == -1" to "ret < 0" would be a much more robust approach...

> freed += ret;
>
> count_vm_events(SLABS_SCANNED, nr_to_scan);
> --
> 1.8.1.5
>
> --
> To unsubscribe, send a message with 'unsubscribe linux-mm' in
> the body to [email protected]. For more info on Linux MM,
> see: http://www.linux-mm.org/ .
> Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

2013-05-21 07:27:47

by Glauber Costa

[permalink] [raw]
Subject: Re: [PATCH v2] mm: vmscan: add VM_BUG_ON on illegal return values from scan_objects

On 05/21/2013 11:17 AM, Pekka Enberg wrote:
> It seems to me relaxing the shrinker API restrictions and changing the
> "ret == -1" to "ret < 0" would be a much more robust approach...

Dave had already spoken against it, and I agree with him
Anybody returning any negative value different than -1 is definitely
doing something strange