Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1498935 > unrolled thread

[PATCH 1/1] dm raid: fix compat_features validation

Started byAndy Whitcroft <apw@canonical.com>
First post2016-10-11 16:40 +0200
Last post2016-10-11 18:00 +0200
Articles 8 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH 1/1] dm raid: fix compat_features validation Andy Whitcroft <apw@canonical.com> - 2016-10-11 16:40 +0200
    Re: [PATCH 1/1] dm raid: fix compat_features validation Mike Snitzer <snitzer@redhat.com> - 2016-10-11 16:50 +0200
    Re: [dm-devel] [PATCH 1/1] dm raid: fix compat_features validation Heinz Mauelshagen <heinzm@redhat.com> - 2016-10-11 17:10 +0200
      Re: [dm-devel] [PATCH 1/1] dm raid: fix compat_features validation Heinz Mauelshagen <heinzm@redhat.com> - 2016-10-11 17:50 +0200
        [PATCH 1/1 V2] dm raid: fix compat_features validation Andy Whitcroft <apw@canonical.com> - 2016-10-11 18:30 +0200
          Re: [PATCH 1/1 V2] dm raid: fix compat_features validation Heinz Mauelshagen <heinzm@redhat.com> - 2016-10-11 19:00 +0200
        Re: [PATCH 1/1] dm raid: fix compat_features validation Mike Snitzer <snitzer@redhat.com> - 2016-10-11 20:00 +0200
      Re: [dm-devel] [PATCH 1/1] dm raid: fix compat_features validation Andy Whitcroft <apw@canonical.com> - 2016-10-11 18:00 +0200

#1498935 — [PATCH 1/1] dm raid: fix compat_features validation

FromAndy Whitcroft <apw@canonical.com>
Date2016-10-11 16:40 +0200
Subject[PATCH 1/1] dm raid: fix compat_features validation
Message-ID<sr6nM-7Uu-35@gated-at.bofh.it>
In commit ecbfb9f118bce4 ("dm raid: add raid level takeover support") a new
compatible feature flag was added.  Validation for these compat_features
was added but this only passes for new raid mappings with this feature
flag.  This causes previously created raid mappings to be failed at import.

Check compat_features for any valid combinations.

Fixes: ecbfb9f118bce4 ("dm raid: add raid level takeover support")
BugLink: http://bugs.launchpad.net/bugs/1631298
Signed-off-by: Andy Whitcroft <apw@canonical.com>
---
 drivers/md/dm-raid.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

It very much looks like these are intended to be optional extended feature
flags.  That we should be accepting any valid flag and rejecting any bit
not in that set.  We should however not be ensuring that specific bits
are actually set.  Certainly as things stand raid sets built on previous
kernel versions cannot be assembled.

diff --git a/drivers/md/dm-raid.c b/drivers/md/dm-raid.c
index 8abde6b..6ddea60 100644
--- a/drivers/md/dm-raid.c
+++ b/drivers/md/dm-raid.c
@@ -2258,7 +2258,7 @@ static int super_validate(struct raid_set *rs, struct md_rdev *rdev)
 	if (!mddev->events && super_init_validation(rs, rdev))
 		return -EINVAL;
 
-	if (le32_to_cpu(sb->compat_features) != FEATURE_FLAG_SUPPORTS_V190) {
+	if (le32_to_cpu(sb->compat_features) & ~(FEATURE_FLAG_SUPPORTS_V190)) {
 		rs->ti->error = "Unable to assemble array: Unknown flag(s) in compatible feature flags";
 		return -EINVAL;
 	}
-- 
2.9.3

[toc] | [next] | [standalone]


#1498937

FromMike Snitzer <snitzer@redhat.com>
Date2016-10-11 16:50 +0200
Message-ID<sr6xr-7XD-1@gated-at.bofh.it>
In reply to#1498935
On Tue, Oct 11 2016 at 10:28am -0400,
Andy Whitcroft <apw@canonical.com> wrote:

> In commit ecbfb9f118bce4 ("dm raid: add raid level takeover support") a new
> compatible feature flag was added.  Validation for these compat_features
> was added but this only passes for new raid mappings with this feature
> flag.  This causes previously created raid mappings to be failed at import.
> 
> Check compat_features for any valid combinations.
> 
> Fixes: ecbfb9f118bce4 ("dm raid: add raid level takeover support")
> BugLink: http://bugs.launchpad.net/bugs/1631298
> Signed-off-by: Andy Whitcroft <apw@canonical.com>
> ---
>  drivers/md/dm-raid.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> It very much looks like these are intended to be optional extended feature
> flags.  That we should be accepting any valid flag and rejecting any bit
> not in that set.  We should however not be ensuring that specific bits
> are actually set.  Certainly as things stand raid sets built on previous
> kernel versions cannot be assembled.

Right, your patch looks good to me.  But I'll wait for confirmation from
Heinz before I stage your fix.

Thanks,
Mike

[toc] | [prev] | [next] | [standalone]


#1498960 — Re: [dm-devel] [PATCH 1/1] dm raid: fix compat_features validation

FromHeinz Mauelshagen <heinzm@redhat.com>
Date2016-10-11 17:10 +0200
SubjectRe: [dm-devel] [PATCH 1/1] dm raid: fix compat_features validation
Message-ID<sr6QO-8jN-13@gated-at.bofh.it>
In reply to#1498935
Andy,

good catch.

We should rather check for  V190 support only in case any
compat feature flags are actually set.

I.e.:

diff --git a/drivers/md/dm-raid.c b/drivers/md/dm-raid.c
index 8abde6b..2a39700 100644
--- a/drivers/md/dm-raid.c
+++ b/drivers/md/dm-raid.c
@@ -2258,7 +2258,8 @@ static int super_validate(struct raid_set *rs, 
struct md_rdev *rdev)
         if (!mddev->events && super_init_validation(rs, rdev))
                 return -EINVAL;

-       if (le32_to_cpu(sb->compat_features) != 
FEATURE_FLAG_SUPPORTS_V190) {
+       if (le32_to_cpu(sb->compat_features) &&
+           le32_to_cpu(sb->compat_features) != 
FEATURE_FLAG_SUPPORTS_V190) {
                 rs->ti->error = "Unable to assemble array: Unknown 
flag(s) in compatible feature flags";
                 return -EINVAL;
         }

On 10/11/2016 04:28 PM, Andy Whitcroft wrote:
> In commit ecbfb9f118bce4 ("dm raid: add raid level takeover support") a new
> compatible feature flag was added.  Validation for these compat_features
> was added but this only passes for new raid mappings with this feature
> flag.  This causes previously created raid mappings to be failed at import.
>
> Check compat_features for any valid combinations.
>
> Fixes: ecbfb9f118bce4 ("dm raid: add raid level takeover support")
> BugLink: http://bugs.launchpad.net/bugs/1631298
> Signed-off-by: Andy Whitcroft <apw@canonical.com>
> ---
>   drivers/md/dm-raid.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> It very much looks like these are intended to be optional extended feature
> flags.  That we should be accepting any valid flag and rejecting any bit
> not in that set.  We should however not be ensuring that specific bits
> are actually set.  Certainly as things stand raid sets built on previous
> kernel versions cannot be assembled.
>
> diff --git a/drivers/md/dm-raid.c b/drivers/md/dm-raid.c
> index 8abde6b..6ddea60 100644
> --- a/drivers/md/dm-raid.c
> +++ b/drivers/md/dm-raid.c
> @@ -2258,7 +2258,7 @@ static int super_validate(struct raid_set *rs, struct md_rdev *rdev)
>   	if (!mddev->events && super_init_validation(rs, rdev))
>   		return -EINVAL;
>   
> -	if (le32_to_cpu(sb->compat_features) != FEATURE_FLAG_SUPPORTS_V190) {
> +	if (le32_to_cpu(sb->compat_features) & ~(FEATURE_FLAG_SUPPORTS_V190)) {
>   		rs->ti->error = "Unable to assemble array: Unknown flag(s) in compatible feature flags";
>   		return -EINVAL;
>   	}

[toc] | [prev] | [next] | [standalone]


#1498979 — Re: [dm-devel] [PATCH 1/1] dm raid: fix compat_features validation

FromHeinz Mauelshagen <heinzm@redhat.com>
Date2016-10-11 17:50 +0200
SubjectRe: [dm-devel] [PATCH 1/1] dm raid: fix compat_features validation
Message-ID<sr7tw-4W-11@gated-at.bofh.it>
In reply to#1498960

On 10/11/2016 05:38 PM, Andy Whitcroft wrote:
> On Tue, Oct 11, 2016 at 05:04:34PM +0200, Heinz Mauelshagen wrote:
>> Andy,
>>
>> good catch.
>>
>> We should rather check for  V190 support only in case any
>> compat feature flags are actually set.
>>
>> {
>> +       if (le32_to_cpu(sb->compat_features) &&
>> +           le32_to_cpu(sb->compat_features) != FEATURE_FLAG_SUPPORTS_V190)
>> {
>>                  rs->ti->error = "Unable to assemble array: Unknown flag(s)
>> in compatible feature flags";
>>                  return -EINVAL;
>>          }
> If the feature flags are single bit combinations then I believe the
> below does check exactly that.  Checking for no 1s outside of the
> expected features, caring not for the value of the valid bits:
>
> +     if (le32_to_cpu(sb->compat_features) & ~(FEATURE_FLAG_SUPPORTS_V190)) {
>
> with the possibilty to or in additional feature bits as they are added.

Thanks,
I prefer this to be easier readable.

>
> -apw
>
> --
> dm-devel mailing list
> dm-devel@redhat.com
> https://www.redhat.com/mailman/listinfo/dm-devel

[toc] | [prev] | [next] | [standalone]


#1499002 — [PATCH 1/1 V2] dm raid: fix compat_features validation

FromAndy Whitcroft <apw@canonical.com>
Date2016-10-11 18:30 +0200
Subject[PATCH 1/1 V2] dm raid: fix compat_features validation
Message-ID<sr86d-wM-1@gated-at.bofh.it>
In reply to#1498979
From a30fba068e41214cb0ffcb14e68722482765e0c9 Mon Sep 17 00:00:00 2001
From: Andy Whitcroft <apw@canonical.com>
Date: Tue, 11 Oct 2016 15:16:57 +0100

In ecbfb9f118bce4 ("dm raid: add raid level takeover support") a new
compatible feature flag was added.  Validation for these compat_features
was added but this only passes for new raid mappings with this feature
flag.  This causes previously created raid mappings to be failed at
import.

Check compat_features for the only valid combination.

Fixes: ecbfb9f118bce4 ("dm raid: add raid level takeover support")
Signed-off-by: Andy Whitcroft <apw@canonical.com>
---
 drivers/md/dm-raid.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

V2: simplify checks as per maintainer.

diff --git a/drivers/md/dm-raid.c b/drivers/md/dm-raid.c
index 8abde6b..2a39700 100644
--- a/drivers/md/dm-raid.c
+++ b/drivers/md/dm-raid.c
@@ -2258,7 +2258,8 @@ static int super_validate(struct raid_set *rs, struct md_rdev *rdev)
 	if (!mddev->events && super_init_validation(rs, rdev))
 		return -EINVAL;
 
-	if (le32_to_cpu(sb->compat_features) != FEATURE_FLAG_SUPPORTS_V190) {
+	if (le32_to_cpu(sb->compat_features) &&
+	    le32_to_cpu(sb->compat_features) != FEATURE_FLAG_SUPPORTS_V190) {
 		rs->ti->error = "Unable to assemble array: Unknown flag(s) in compatible feature flags";
 		return -EINVAL;
 	}
-- 
2.9.3

[toc] | [prev] | [next] | [standalone]


#1499019 — Re: [PATCH 1/1 V2] dm raid: fix compat_features validation

FromHeinz Mauelshagen <heinzm@redhat.com>
Date2016-10-11 19:00 +0200
SubjectRe: [PATCH 1/1 V2] dm raid: fix compat_features validation
Message-ID<sr8zg-H0-37@gated-at.bofh.it>
In reply to#1499002
Acked-by: Heinz Mauelshagen <heinzm@redhat.com>

On 10/11/2016 06:21 PM, Andy Whitcroft wrote:
>  From a30fba068e41214cb0ffcb14e68722482765e0c9 Mon Sep 17 00:00:00 2001
> From: Andy Whitcroft <apw@canonical.com>
> Date: Tue, 11 Oct 2016 15:16:57 +0100
>
> In ecbfb9f118bce4 ("dm raid: add raid level takeover support") a new
> compatible feature flag was added.  Validation for these compat_features
> was added but this only passes for new raid mappings with this feature
> flag.  This causes previously created raid mappings to be failed at
> import.

Clarification:
to allow for feature checks, the compat_features member was
in the dm-raid superblock from the beginning (so before ecbfb9f118bce4).
It got renamed from features to compat_features because incompat_features
got introduced with that commit together with the problematic check
of compat_features you thankfully found.


>
> Check compat_features for the only valid combination.
>
> Fixes: ecbfb9f118bce4 ("dm raid: add raid level takeover support")
> Signed-off-by: Andy Whitcroft <apw@canonical.com>
> ---
>   drivers/md/dm-raid.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
>
> V2: simplify checks as per maintainer.
>
> diff --git a/drivers/md/dm-raid.c b/drivers/md/dm-raid.c
> index 8abde6b..2a39700 100644
> --- a/drivers/md/dm-raid.c
> +++ b/drivers/md/dm-raid.c
> @@ -2258,7 +2258,8 @@ static int super_validate(struct raid_set *rs, struct md_rdev *rdev)
>   	if (!mddev->events && super_init_validation(rs, rdev))
>   		return -EINVAL;
>   
> -	if (le32_to_cpu(sb->compat_features) != FEATURE_FLAG_SUPPORTS_V190) {
> +	if (le32_to_cpu(sb->compat_features) &&
> +	    le32_to_cpu(sb->compat_features) != FEATURE_FLAG_SUPPORTS_V190) {
>   		rs->ti->error = "Unable to assemble array: Unknown flag(s) in compatible feature flags";
>   		return -EINVAL;
>   	}

[toc] | [prev] | [next] | [standalone]


#1499087

FromMike Snitzer <snitzer@redhat.com>
Date2016-10-11 20:00 +0200
Message-ID<sr9vk-1fU-17@gated-at.bofh.it>
In reply to#1498979
On Tue, Oct 11 2016 at 11:44am -0400,
Heinz Mauelshagen <heinzm@redhat.com> wrote:

> 
> 
> On 10/11/2016 05:38 PM, Andy Whitcroft wrote:
> >On Tue, Oct 11, 2016 at 05:04:34PM +0200, Heinz Mauelshagen wrote:
> >>Andy,
> >>
> >>good catch.
> >>
> >>We should rather check for  V190 support only in case any
> >>compat feature flags are actually set.
> >>
> >>{
> >>+       if (le32_to_cpu(sb->compat_features) &&
> >>+           le32_to_cpu(sb->compat_features) != FEATURE_FLAG_SUPPORTS_V190)
> >>{
> >>                 rs->ti->error = "Unable to assemble array: Unknown flag(s)
> >>in compatible feature flags";
> >>                 return -EINVAL;
> >>         }
> >If the feature flags are single bit combinations then I believe the
> >below does check exactly that.  Checking for no 1s outside of the
> >expected features, caring not for the value of the valid bits:
> >
> >+     if (le32_to_cpu(sb->compat_features) & ~(FEATURE_FLAG_SUPPORTS_V190)) {
> >
> >with the possibilty to or in additional feature bits as they are added.
> 
> Thanks,
> I prefer this to be easier readable.

Readable or not, the code with the != is _not_ future-proof.  Whereas
Andy's solution is.  If/when a new compat feature comes along then
FEATURE_FLAG_SUPPORTS_V190 would be replaced to be a macro that ORs all
the new compat features together (e.g. FEATURE_FLAG_COMPAT).  E.g. how
dm-thin-metadata.c:__check_incompat_features() does.

We can go with the != code for now, since any future changes would
likely cause this test to be changed.  Or we could fix it now _for
real_.

Mike

[toc] | [prev] | [next] | [standalone]


#1498995 — Re: [dm-devel] [PATCH 1/1] dm raid: fix compat_features validation

FromAndy Whitcroft <apw@canonical.com>
Date2016-10-11 18:00 +0200
SubjectRe: [dm-devel] [PATCH 1/1] dm raid: fix compat_features validation
Message-ID<sr7tw-4W-13@gated-at.bofh.it>
In reply to#1498960
On Tue, Oct 11, 2016 at 05:04:34PM +0200, Heinz Mauelshagen wrote:
> 
> Andy,
> 
> good catch.
> 
> We should rather check for  V190 support only in case any
> compat feature flags are actually set.
> 
> {
> +       if (le32_to_cpu(sb->compat_features) &&
> +           le32_to_cpu(sb->compat_features) != FEATURE_FLAG_SUPPORTS_V190)
> {
>                 rs->ti->error = "Unable to assemble array: Unknown flag(s)
> in compatible feature flags";
>                 return -EINVAL;
>         }

If the feature flags are single bit combinations then I believe the
below does check exactly that.  Checking for no 1s outside of the
expected features, caring not for the value of the valid bits:

+     if (le32_to_cpu(sb->compat_features) & ~(FEATURE_FLAG_SUPPORTS_V190)) {

with the possibilty to or in additional feature bits as they are added.

-apw

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web