* Re: [PATCH] md: raid10: remove VLAIS
2017-10-05 18:28 [PATCH] md: raid10: remove VLAIS Matthias Kaehlcke
@ 2017-10-05 19:49 ` Guenter Roeck
2017-10-05 22:05 ` Shaohua Li
2017-10-05 23:58 ` NeilBrown
2 siblings, 0 replies; 7+ messages in thread
From: Guenter Roeck @ 2017-10-05 19:49 UTC (permalink / raw)
To: Matthias Kaehlcke
Cc: Shaohua Li, linux-raid, linux-kernel, Arnd Bergmann,
Michael Davidson, Guenter Roeck
On Thu, Oct 5, 2017 at 11:28 AM, Matthias Kaehlcke <mka@chromium.org> wrote:
> The raid10 driver can't be built with clang since it uses a variable
> length array in a structure (VLAIS):
>
> drivers/md/raid10.c:4583:17: error: fields must have a constant size:
> 'variable length array in structure' extension will never be supported
>
> Allocate the r10bio struct with kmalloc instead of using the VLAIS
> construct.
>
> Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
Reviewed-by: Guenter Roeck <groeck@chromium.org>
> ---
> drivers/md/raid10.c | 13 ++++++++-----
> 1 file changed, 8 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
> index 374df5796649..9616163eaf8c 100644
> --- a/drivers/md/raid10.c
> +++ b/drivers/md/raid10.c
> @@ -4578,15 +4578,16 @@ static int handle_reshape_read_error(struct mddev *mddev,
> /* Use sync reads to get the blocks from somewhere else */
> int sectors = r10_bio->sectors;
> struct r10conf *conf = mddev->private;
> - struct {
> - struct r10bio r10_bio;
> - struct r10dev devs[conf->copies];
> - } on_stack;
> - struct r10bio *r10b = &on_stack.r10_bio;
> + struct r10bio *r10b;
> int slot = 0;
> int idx = 0;
> struct page **pages;
>
> + r10b = kmalloc(sizeof(*r10b) +
> + sizeof(struct r10dev) * conf->copies, GFP_KERNEL);
> + if (!r10b)
> + return -ENOMEM;
> +
> /* reshape IOs share pages from .devs[0].bio */
> pages = get_resync_pages(r10_bio->devs[0].bio)->pages;
>
> @@ -4635,11 +4636,13 @@ static int handle_reshape_read_error(struct mddev *mddev,
> /* couldn't read this block, must give up */
> set_bit(MD_RECOVERY_INTR,
> &mddev->recovery);
> + kfree(r10b);
> return -EIO;
> }
> sectors -= s;
> idx++;
> }
> + kfree(r10b);
> return 0;
> }
>
> --
> 2.14.2.920.gcf0c67979c-goog
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] md: raid10: remove VLAIS
2017-10-05 18:28 [PATCH] md: raid10: remove VLAIS Matthias Kaehlcke
2017-10-05 19:49 ` Guenter Roeck
@ 2017-10-05 22:05 ` Shaohua Li
2017-10-05 23:58 ` NeilBrown
2 siblings, 0 replies; 7+ messages in thread
From: Shaohua Li @ 2017-10-05 22:05 UTC (permalink / raw)
To: Matthias Kaehlcke
Cc: linux-raid, linux-kernel, Arnd Bergmann, Michael Davidson,
Guenter Roeck
On Thu, Oct 05, 2017 at 11:28:47AM -0700, Matthias Kaehlcke wrote:
> The raid10 driver can't be built with clang since it uses a variable
> length array in a structure (VLAIS):
>
> drivers/md/raid10.c:4583:17: error: fields must have a constant size:
> 'variable length array in structure' extension will never be supported
>
> Allocate the r10bio struct with kmalloc instead of using the VLAIS
> construct.
>
> Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
> ---
> drivers/md/raid10.c | 13 ++++++++-----
> 1 file changed, 8 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
> index 374df5796649..9616163eaf8c 100644
> --- a/drivers/md/raid10.c
> +++ b/drivers/md/raid10.c
> @@ -4578,15 +4578,16 @@ static int handle_reshape_read_error(struct mddev *mddev,
> /* Use sync reads to get the blocks from somewhere else */
> int sectors = r10_bio->sectors;
> struct r10conf *conf = mddev->private;
> - struct {
> - struct r10bio r10_bio;
> - struct r10dev devs[conf->copies];
> - } on_stack;
> - struct r10bio *r10b = &on_stack.r10_bio;
> + struct r10bio *r10b;
> int slot = 0;
> int idx = 0;
> struct page **pages;
>
> + r10b = kmalloc(sizeof(*r10b) +
> + sizeof(struct r10dev) * conf->copies, GFP_KERNEL);
> + if (!r10b)
> + return -ENOMEM;
I'll apply this patch with 'set_bit(MD_RECOVERY_INTR, &mddev->recovery);' added here, thanks!
> +
> /* reshape IOs share pages from .devs[0].bio */
> pages = get_resync_pages(r10_bio->devs[0].bio)->pages;
>
> @@ -4635,11 +4636,13 @@ static int handle_reshape_read_error(struct mddev *mddev,
> /* couldn't read this block, must give up */
> set_bit(MD_RECOVERY_INTR,
> &mddev->recovery);
> + kfree(r10b);
> return -EIO;
> }
> sectors -= s;
> idx++;
> }
> + kfree(r10b);
> return 0;
> }
>
> --
> 2.14.2.920.gcf0c67979c-goog
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] md: raid10: remove VLAIS
2017-10-05 18:28 [PATCH] md: raid10: remove VLAIS Matthias Kaehlcke
2017-10-05 19:49 ` Guenter Roeck
2017-10-05 22:05 ` Shaohua Li
@ 2017-10-05 23:58 ` NeilBrown
2017-10-06 0:19 ` Matthias Kaehlcke
2 siblings, 1 reply; 7+ messages in thread
From: NeilBrown @ 2017-10-05 23:58 UTC (permalink / raw)
To: Shaohua Li
Cc: linux-raid, linux-kernel, Arnd Bergmann, Michael Davidson,
Guenter Roeck, Matthias Kaehlcke
[-- Attachment #1: Type: text/plain, Size: 2429 bytes --]
On Thu, Oct 05 2017, Matthias Kaehlcke wrote:
> The raid10 driver can't be built with clang since it uses a variable
> length array in a structure (VLAIS):
>
> drivers/md/raid10.c:4583:17: error: fields must have a constant size:
> 'variable length array in structure' extension will never be supported
>
> Allocate the r10bio struct with kmalloc instead of using the VLAIS
> construct.
>
> Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
> ---
> drivers/md/raid10.c | 13 ++++++++-----
> 1 file changed, 8 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
> index 374df5796649..9616163eaf8c 100644
> --- a/drivers/md/raid10.c
> +++ b/drivers/md/raid10.c
> @@ -4578,15 +4578,16 @@ static int handle_reshape_read_error(struct mddev *mddev,
> /* Use sync reads to get the blocks from somewhere else */
> int sectors = r10_bio->sectors;
> struct r10conf *conf = mddev->private;
> - struct {
> - struct r10bio r10_bio;
> - struct r10dev devs[conf->copies];
> - } on_stack;
> - struct r10bio *r10b = &on_stack.r10_bio;
> + struct r10bio *r10b;
> int slot = 0;
> int idx = 0;
> struct page **pages;
>
> + r10b = kmalloc(sizeof(*r10b) +
> + sizeof(struct r10dev) * conf->copies, GFP_KERNEL);
GFP_KERNEL isn't a good idea here.
This could wait for writeback, and if writeback tries to write to the
region of the array which is being reshaped, it might deadlock.
GFP_NOIO is safer.
given that conf->copies is almost always 2 it might be nicer to
have
struct {
struct r10bio r10_bio;
struct r10dev devs[2];
} on_stack;
struct r10bio *r10b;
if (conf->copies <= ARRAY_SIZE(on_stack.devs))
r10b = &on_stack.r10_bio;
else
r10b = kmalloc(sizeof(*r10b) +
sizeof(struct r10dev) * conf->copies, GFP_NOIO);
Thanks,
NeilBrown
> + if (!r10b)
> + return -ENOMEM;
> +
> /* reshape IOs share pages from .devs[0].bio */
> pages = get_resync_pages(r10_bio->devs[0].bio)->pages;
>
> @@ -4635,11 +4636,13 @@ static int handle_reshape_read_error(struct mddev *mddev,
> /* couldn't read this block, must give up */
> set_bit(MD_RECOVERY_INTR,
> &mddev->recovery);
> + kfree(r10b);
> return -EIO;
> }
> sectors -= s;
> idx++;
> }
> + kfree(r10b);
> return 0;
> }
>
> --
> 2.14.2.920.gcf0c67979c-goog
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] md: raid10: remove VLAIS
2017-10-05 23:58 ` NeilBrown
@ 2017-10-06 0:19 ` Matthias Kaehlcke
2017-10-06 2:22 ` NeilBrown
0 siblings, 1 reply; 7+ messages in thread
From: Matthias Kaehlcke @ 2017-10-06 0:19 UTC (permalink / raw)
To: NeilBrown
Cc: Shaohua Li, linux-raid, linux-kernel, Arnd Bergmann,
Michael Davidson, Guenter Roeck
Hi Neil,
El Fri, Oct 06, 2017 at 10:58:59AM +1100 NeilBrown ha dit:
> On Thu, Oct 05 2017, Matthias Kaehlcke wrote:
>
> > The raid10 driver can't be built with clang since it uses a variable
> > length array in a structure (VLAIS):
> >
> > drivers/md/raid10.c:4583:17: error: fields must have a constant size:
> > 'variable length array in structure' extension will never be supported
> >
> > Allocate the r10bio struct with kmalloc instead of using the VLAIS
> > construct.
> >
> > Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
> > ---
> > drivers/md/raid10.c | 13 ++++++++-----
> > 1 file changed, 8 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
> > index 374df5796649..9616163eaf8c 100644
> > --- a/drivers/md/raid10.c
> > +++ b/drivers/md/raid10.c
> > @@ -4578,15 +4578,16 @@ static int handle_reshape_read_error(struct mddev *mddev,
> > /* Use sync reads to get the blocks from somewhere else */
> > int sectors = r10_bio->sectors;
> > struct r10conf *conf = mddev->private;
> > - struct {
> > - struct r10bio r10_bio;
> > - struct r10dev devs[conf->copies];
> > - } on_stack;
> > - struct r10bio *r10b = &on_stack.r10_bio;
> > + struct r10bio *r10b;
> > int slot = 0;
> > int idx = 0;
> > struct page **pages;
> >
> > + r10b = kmalloc(sizeof(*r10b) +
> > + sizeof(struct r10dev) * conf->copies, GFP_KERNEL);
>
> GFP_KERNEL isn't a good idea here.
> This could wait for writeback, and if writeback tries to write to the
> region of the array which is being reshaped, it might deadlock.
>
> GFP_NOIO is safer.
Good point, thanks!
> given that conf->copies is almost always 2 it might be nicer to
> have
>
> struct {
> struct r10bio r10_bio;
> struct r10dev devs[2];
> } on_stack;
>
> struct r10bio *r10b;
>
> if (conf->copies <= ARRAY_SIZE(on_stack.devs))
> r10b = &on_stack.r10_bio;
> else
> r10b = kmalloc(sizeof(*r10b) +
> sizeof(struct r10dev) * conf->copies, GFP_NOIO);
It would add also add an extra condition to determine if r10b needs to
be freed or not.
Given that array reshaping is a rare operation and an error during
this operation is an exceptional condition I think the simpler code
with always dynamic allocation is preferable. That said I'm fine with
reworking the patch according to your suggestion if you or Shaohua
prefer it.
Matthias
> > + if (!r10b)
> > + return -ENOMEM;
> > +
> > /* reshape IOs share pages from .devs[0].bio */
> > pages = get_resync_pages(r10_bio->devs[0].bio)->pages;
> >
> > @@ -4635,11 +4636,13 @@ static int handle_reshape_read_error(struct mddev *mddev,
> > /* couldn't read this block, must give up */
> > set_bit(MD_RECOVERY_INTR,
> > &mddev->recovery);
> > + kfree(r10b);
> > return -EIO;
> > }
> > sectors -= s;
> > idx++;
> > }
> > + kfree(r10b);
> > return 0;
> > }
> >
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] md: raid10: remove VLAIS
2017-10-06 0:19 ` Matthias Kaehlcke
@ 2017-10-06 2:22 ` NeilBrown
2017-10-06 4:40 ` Shaohua Li
0 siblings, 1 reply; 7+ messages in thread
From: NeilBrown @ 2017-10-06 2:22 UTC (permalink / raw)
To: Matthias Kaehlcke
Cc: Shaohua Li, linux-raid, linux-kernel, Arnd Bergmann,
Michael Davidson, Guenter Roeck
[-- Attachment #1: Type: text/plain, Size: 3313 bytes --]
On Thu, Oct 05 2017, Matthias Kaehlcke wrote:
> Hi Neil,
>
> El Fri, Oct 06, 2017 at 10:58:59AM +1100 NeilBrown ha dit:
>
>> On Thu, Oct 05 2017, Matthias Kaehlcke wrote:
>>
>> > The raid10 driver can't be built with clang since it uses a variable
>> > length array in a structure (VLAIS):
>> >
>> > drivers/md/raid10.c:4583:17: error: fields must have a constant size:
>> > 'variable length array in structure' extension will never be supported
>> >
>> > Allocate the r10bio struct with kmalloc instead of using the VLAIS
>> > construct.
>> >
>> > Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
>> > ---
>> > drivers/md/raid10.c | 13 ++++++++-----
>> > 1 file changed, 8 insertions(+), 5 deletions(-)
>> >
>> > diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
>> > index 374df5796649..9616163eaf8c 100644
>> > --- a/drivers/md/raid10.c
>> > +++ b/drivers/md/raid10.c
>> > @@ -4578,15 +4578,16 @@ static int handle_reshape_read_error(struct mddev *mddev,
>> > /* Use sync reads to get the blocks from somewhere else */
>> > int sectors = r10_bio->sectors;
>> > struct r10conf *conf = mddev->private;
>> > - struct {
>> > - struct r10bio r10_bio;
>> > - struct r10dev devs[conf->copies];
>> > - } on_stack;
>> > - struct r10bio *r10b = &on_stack.r10_bio;
>> > + struct r10bio *r10b;
>> > int slot = 0;
>> > int idx = 0;
>> > struct page **pages;
>> >
>> > + r10b = kmalloc(sizeof(*r10b) +
>> > + sizeof(struct r10dev) * conf->copies, GFP_KERNEL);
>>
>> GFP_KERNEL isn't a good idea here.
>> This could wait for writeback, and if writeback tries to write to the
>> region of the array which is being reshaped, it might deadlock.
>>
>> GFP_NOIO is safer.
>
> Good point, thanks!
>
>> given that conf->copies is almost always 2 it might be nicer to
>> have
>>
>> struct {
>> struct r10bio r10_bio;
>> struct r10dev devs[2];
>> } on_stack;
>>
>> struct r10bio *r10b;
>>
>> if (conf->copies <= ARRAY_SIZE(on_stack.devs))
>> r10b = &on_stack.r10_bio;
>> else
>> r10b = kmalloc(sizeof(*r10b) +
>> sizeof(struct r10dev) * conf->copies, GFP_NOIO);
>
> It would add also add an extra condition to determine if r10b needs to
> be freed or not.
True.
>
> Given that array reshaping is a rare operation and an error during
> this operation is an exceptional condition I think the simpler code
> with always dynamic allocation is preferable. That said I'm fine with
> reworking the patch according to your suggestion if you or Shaohua
> prefer it.
I don't feel strongly about it. As long as the GFP_KERNEL->GFP_NOIO
change happens I'm OK with this patch.
Thanks,
NeilBrown
>
> Matthias
>
>> > + if (!r10b)
>> > + return -ENOMEM;
>> > +
>> > /* reshape IOs share pages from .devs[0].bio */
>> > pages = get_resync_pages(r10_bio->devs[0].bio)->pages;
>> >
>> > @@ -4635,11 +4636,13 @@ static int handle_reshape_read_error(struct mddev *mddev,
>> > /* couldn't read this block, must give up */
>> > set_bit(MD_RECOVERY_INTR,
>> > &mddev->recovery);
>> > + kfree(r10b);
>> > return -EIO;
>> > }
>> > sectors -= s;
>> > idx++;
>> > }
>> > + kfree(r10b);
>> > return 0;
>> > }
>> >
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] md: raid10: remove VLAIS
2017-10-06 2:22 ` NeilBrown
@ 2017-10-06 4:40 ` Shaohua Li
0 siblings, 0 replies; 7+ messages in thread
From: Shaohua Li @ 2017-10-06 4:40 UTC (permalink / raw)
To: NeilBrown
Cc: Matthias Kaehlcke, linux-raid, linux-kernel, Arnd Bergmann,
Michael Davidson, Guenter Roeck
On Fri, Oct 06, 2017 at 01:22:12PM +1100, Neil Brown wrote:
> On Thu, Oct 05 2017, Matthias Kaehlcke wrote:
>
> > Hi Neil,
> >
> > El Fri, Oct 06, 2017 at 10:58:59AM +1100 NeilBrown ha dit:
> >
> >> On Thu, Oct 05 2017, Matthias Kaehlcke wrote:
> >>
> >> > The raid10 driver can't be built with clang since it uses a variable
> >> > length array in a structure (VLAIS):
> >> >
> >> > drivers/md/raid10.c:4583:17: error: fields must have a constant size:
> >> > 'variable length array in structure' extension will never be supported
> >> >
> >> > Allocate the r10bio struct with kmalloc instead of using the VLAIS
> >> > construct.
> >> >
> >> > Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
> >> > ---
> >> > drivers/md/raid10.c | 13 ++++++++-----
> >> > 1 file changed, 8 insertions(+), 5 deletions(-)
> >> >
> >> > diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
> >> > index 374df5796649..9616163eaf8c 100644
> >> > --- a/drivers/md/raid10.c
> >> > +++ b/drivers/md/raid10.c
> >> > @@ -4578,15 +4578,16 @@ static int handle_reshape_read_error(struct mddev *mddev,
> >> > /* Use sync reads to get the blocks from somewhere else */
> >> > int sectors = r10_bio->sectors;
> >> > struct r10conf *conf = mddev->private;
> >> > - struct {
> >> > - struct r10bio r10_bio;
> >> > - struct r10dev devs[conf->copies];
> >> > - } on_stack;
> >> > - struct r10bio *r10b = &on_stack.r10_bio;
> >> > + struct r10bio *r10b;
> >> > int slot = 0;
> >> > int idx = 0;
> >> > struct page **pages;
> >> >
> >> > + r10b = kmalloc(sizeof(*r10b) +
> >> > + sizeof(struct r10dev) * conf->copies, GFP_KERNEL);
> >>
> >> GFP_KERNEL isn't a good idea here.
> >> This could wait for writeback, and if writeback tries to write to the
> >> region of the array which is being reshaped, it might deadlock.
> >>
> >> GFP_NOIO is safer.
> >
> > Good point, thanks!
> >
> >> given that conf->copies is almost always 2 it might be nicer to
> >> have
> >>
> >> struct {
> >> struct r10bio r10_bio;
> >> struct r10dev devs[2];
> >> } on_stack;
> >>
> >> struct r10bio *r10b;
> >>
> >> if (conf->copies <= ARRAY_SIZE(on_stack.devs))
> >> r10b = &on_stack.r10_bio;
> >> else
> >> r10b = kmalloc(sizeof(*r10b) +
> >> sizeof(struct r10dev) * conf->copies, GFP_NOIO);
> >
> > It would add also add an extra condition to determine if r10b needs to
> > be freed or not.
>
> True.
>
> >
> > Given that array reshaping is a rare operation and an error during
> > this operation is an exceptional condition I think the simpler code
> > with always dynamic allocation is preferable. That said I'm fine with
> > reworking the patch according to your suggestion if you or Shaohua
> > prefer it.
>
> I don't feel strongly about it. As long as the GFP_KERNEL->GFP_NOIO
> change happens I'm OK with this patch.
Let's use GFP_NOIO then, should not be big deal. I updated the patch.
Thanks,
Shaohua
^ permalink raw reply [flat|nested] 7+ messages in thread