2018-06-29 19:07:04

by Kees Cook

[permalink] [raw]
Subject: [PATCH] powerpc/msi: Remove VLA usage

In the quest to remove all stack VLA usage from the kernel[1], this
switches from an unchanging variable to a constant expression to eliminate
the VLA generation.

[1] https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com

Cc: Benjamin Herrenschmidt <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Michael Ellerman <[email protected]>
Cc: Andrew Morton <[email protected]>
Cc: Randy Dunlap <[email protected]>
Cc: Tyrel Datwyler <[email protected]>
Cc: Rob Herring <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: [email protected]
Signed-off-by: Kees Cook <[email protected]>
---
arch/powerpc/sysdev/msi_bitmap.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/arch/powerpc/sysdev/msi_bitmap.c b/arch/powerpc/sysdev/msi_bitmap.c
index 6243a7e537d0..e64a411d1a00 100644
--- a/arch/powerpc/sysdev/msi_bitmap.c
+++ b/arch/powerpc/sysdev/msi_bitmap.c
@@ -225,22 +225,23 @@ static void __init test_of_node(void)
struct device_node of_node;
struct property prop;
struct msi_bitmap bmp;
- int size = 256;
- DECLARE_BITMAP(expected, size);
+#define SIZE_EXPECTED 256
+ DECLARE_BITMAP(expected, SIZE_EXPECTED);

/* There should really be a struct device_node allocator */
memset(&of_node, 0, sizeof(of_node));
of_node_init(&of_node);
of_node.full_name = node_name;

- WARN_ON(msi_bitmap_alloc(&bmp, size, &of_node));
+ WARN_ON(msi_bitmap_alloc(&bmp, SIZE_EXPECTED, &of_node));

/* No msi-available-ranges, so expect > 0 */
WARN_ON(msi_bitmap_reserve_dt_hwirqs(&bmp) <= 0);

/* Should all still be free */
- WARN_ON(bitmap_find_free_region(bmp.bitmap, size, get_count_order(size)));
- bitmap_release_region(bmp.bitmap, 0, get_count_order(size));
+ WARN_ON(bitmap_find_free_region(bmp.bitmap, SIZE_EXPECTED,
+ get_count_order(SIZE_EXPECTED)));
+ bitmap_release_region(bmp.bitmap, 0, get_count_order(SIZE_EXPECTED));

/* Now create a fake msi-available-ranges property */

@@ -256,8 +257,8 @@ static void __init test_of_node(void)
WARN_ON(msi_bitmap_reserve_dt_hwirqs(&bmp));

/* Check we got the expected result */
- WARN_ON(bitmap_parselist(expected_str, expected, size));
- WARN_ON(!bitmap_equal(expected, bmp.bitmap, size));
+ WARN_ON(bitmap_parselist(expected_str, expected, SIZE_EXPECTED));
+ WARN_ON(!bitmap_equal(expected, bmp.bitmap, SIZE_EXPECTED));

msi_bitmap_free(&bmp);
kfree(bmp.bitmap);
--
2.17.1


--
Kees Cook
Pixel Security


2018-07-17 03:57:46

by Kees Cook

[permalink] [raw]
Subject: Re: [PATCH] powerpc/msi: Remove VLA usage

On Fri, Jun 29, 2018 at 11:52 AM, Kees Cook <[email protected]> wrote:
> In the quest to remove all stack VLA usage from the kernel[1], this
> switches from an unchanging variable to a constant expression to eliminate
> the VLA generation.
>
> [1] https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com
>
> Signed-off-by: Kees Cook <[email protected]>

Friendly ping! Michael, can you take this?

-Kees


> ---
> arch/powerpc/sysdev/msi_bitmap.c | 15 ++++++++-------
> 1 file changed, 8 insertions(+), 7 deletions(-)
>
> diff --git a/arch/powerpc/sysdev/msi_bitmap.c b/arch/powerpc/sysdev/msi_bitmap.c
> index 6243a7e537d0..e64a411d1a00 100644
> --- a/arch/powerpc/sysdev/msi_bitmap.c
> +++ b/arch/powerpc/sysdev/msi_bitmap.c
> @@ -225,22 +225,23 @@ static void __init test_of_node(void)
> struct device_node of_node;
> struct property prop;
> struct msi_bitmap bmp;
> - int size = 256;
> - DECLARE_BITMAP(expected, size);
> +#define SIZE_EXPECTED 256
> + DECLARE_BITMAP(expected, SIZE_EXPECTED);
>
> /* There should really be a struct device_node allocator */
> memset(&of_node, 0, sizeof(of_node));
> of_node_init(&of_node);
> of_node.full_name = node_name;
>
> - WARN_ON(msi_bitmap_alloc(&bmp, size, &of_node));
> + WARN_ON(msi_bitmap_alloc(&bmp, SIZE_EXPECTED, &of_node));
>
> /* No msi-available-ranges, so expect > 0 */
> WARN_ON(msi_bitmap_reserve_dt_hwirqs(&bmp) <= 0);
>
> /* Should all still be free */
> - WARN_ON(bitmap_find_free_region(bmp.bitmap, size, get_count_order(size)));
> - bitmap_release_region(bmp.bitmap, 0, get_count_order(size));
> + WARN_ON(bitmap_find_free_region(bmp.bitmap, SIZE_EXPECTED,
> + get_count_order(SIZE_EXPECTED)));
> + bitmap_release_region(bmp.bitmap, 0, get_count_order(SIZE_EXPECTED));
>
> /* Now create a fake msi-available-ranges property */
>
> @@ -256,8 +257,8 @@ static void __init test_of_node(void)
> WARN_ON(msi_bitmap_reserve_dt_hwirqs(&bmp));
>
> /* Check we got the expected result */
> - WARN_ON(bitmap_parselist(expected_str, expected, size));
> - WARN_ON(!bitmap_equal(expected, bmp.bitmap, size));
> + WARN_ON(bitmap_parselist(expected_str, expected, SIZE_EXPECTED));
> + WARN_ON(!bitmap_equal(expected, bmp.bitmap, SIZE_EXPECTED));
>
> msi_bitmap_free(&bmp);
> kfree(bmp.bitmap);
> --
> 2.17.1
>
>
> --
> Kees Cook
> Pixel Security



--
Kees Cook
Pixel Security

2018-07-17 21:15:06

by Tyrel Datwyler

[permalink] [raw]
Subject: Re: [PATCH] powerpc/msi: Remove VLA usage

On 06/29/2018 11:52 AM, Kees Cook wrote:
> In the quest to remove all stack VLA usage from the kernel[1], this
> switches from an unchanging variable to a constant expression to eliminate
> the VLA generation.
>
> [1] https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com
>
> Cc: Benjamin Herrenschmidt <[email protected]>
> Cc: Paul Mackerras <[email protected]>
> Cc: Michael Ellerman <[email protected]>
> Cc: Andrew Morton <[email protected]>
> Cc: Randy Dunlap <[email protected]>
> Cc: Tyrel Datwyler <[email protected]>
> Cc: Rob Herring <[email protected]>
> Cc: Ingo Molnar <[email protected]>
> Cc: [email protected]
> Signed-off-by: Kees Cook <[email protected]>
> ---

Reviewed-by: Tyrel Datwyler <[email protected]>

2018-07-19 06:08:45

by Michael Ellerman

[permalink] [raw]
Subject: Re: powerpc/msi: Remove VLA usage

On Fri, 2018-06-29 at 18:52:54 UTC, Kees Cook wrote:
> In the quest to remove all stack VLA usage from the kernel[1], this
> switches from an unchanging variable to a constant expression to eliminate
> the VLA generation.
>
> [1] https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com
>
> Cc: Benjamin Herrenschmidt <[email protected]>
> Cc: Paul Mackerras <[email protected]>
> Cc: Michael Ellerman <[email protected]>
> Cc: Andrew Morton <[email protected]>
> Cc: Randy Dunlap <[email protected]>
> Cc: Tyrel Datwyler <[email protected]>
> Cc: Rob Herring <[email protected]>
> Cc: Ingo Molnar <[email protected]>
> Cc: [email protected]
> Signed-off-by: Kees Cook <[email protected]>

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/1b80ac648483189e45f60d4ddbb54b

cheers

2018-07-19 12:18:08

by Michael Ellerman

[permalink] [raw]
Subject: Re: [PATCH] powerpc/msi: Remove VLA usage

Kees Cook <[email protected]> writes:

> On Fri, Jun 29, 2018 at 11:52 AM, Kees Cook <[email protected]> wrote:
>> In the quest to remove all stack VLA usage from the kernel[1], this
>> switches from an unchanging variable to a constant expression to eliminate
>> the VLA generation.
>>
>> [1] https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com
>>
>> Signed-off-by: Kees Cook <[email protected]>
>
> Friendly ping! Michael, can you take this?

Yep, sorry. I actually applied it weeks ago but hadn't pushed.

cheers

2018-07-19 18:34:48

by Kees Cook

[permalink] [raw]
Subject: Re: [PATCH] powerpc/msi: Remove VLA usage

On Thu, Jul 19, 2018 at 5:17 AM, Michael Ellerman <[email protected]> wrote:
> Kees Cook <[email protected]> writes:
>
>> On Fri, Jun 29, 2018 at 11:52 AM, Kees Cook <[email protected]> wrote:
>>> In the quest to remove all stack VLA usage from the kernel[1], this
>>> switches from an unchanging variable to a constant expression to eliminate
>>> the VLA generation.
>>>
>>> [1] https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com
>>>
>>> Signed-off-by: Kees Cook <[email protected]>
>>
>> Friendly ping! Michael, can you take this?
>
> Yep, sorry. I actually applied it weeks ago but hadn't pushed.

No worries! Thanks! :)

-Kees

--
Kees Cook
Pixel Security