Skip to contentSkip to conversation

dm raid: fix compat_features validation

PATCH Superseded Andy Whitcroft 3 participants 9 messages Oct 11, 2016 – Oct 14, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dm raid: fix compat_features validation

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

drivers/md/dm-raid.c +1 -1
index 8abde6b..6ddea60 100644
@@ -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;
 	}
Signature · 1 line
2.9.3
#1 lore raw
Quoted 14 lines · Andy Whitcroft

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")
---
 drivers/md/dm-raid.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 5 lines

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

#2 lore raw
In reply to Andy Whitcroft

Andy,

good catch.

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

I.e.:

drivers/md/dm-raid.c +2 -1
index 8abde6b..2a39700 100644
@@ -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;
        }
Quoted 33 lines · Andy Whitcroft

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

drivers/md/dm-raid.c +1 -1
index 8abde6b..6ddea60 100644
@@ -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;
  	}
#3 lore raw
Quoted 11 lines · Heinz Mauelshagen

Andy,

good catch.

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

{

(quoted diff) +2 -0
+       if (le32_to_cpu(sb->compat_features) &&
+           le32_to_cpu(sb->compat_features) != FEATURE_FLAG_SUPPORTS_V190)
Quoted 5 lines
{
                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

#4 lore raw
Quoted 16 lines · Andy Whitcroft
Quoted 10 lines · Heinz Mauelshagen

Andy,

good catch.

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

{

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

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.

Quoted 7 lines

-apw

--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel

#5 lore raw

PATCH v2 1/1 dm raid: fix compat_features validation

From a30fba068e41214cb0ffcb14e68722482765e0c9 Mon Sep 17 00:00:00 2001
From: Andy Whitcroft <[email protected]>
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")
---
 drivers/md/dm-raid.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

V2: simplify checks as per maintainer.

drivers/md/dm-raid.c +2 -1
index 8abde6b..2a39700 100644
@@ -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;
 	}
Signature · 1 line
2.9.3
Acked-by on v2 1/1
#6 lore raw
Quoted 9 lines · Andy Whitcroft

From a30fba068e41214cb0ffcb14e68722482765e0c9 Mon Sep 17 00:00:00 2001
From: Andy Whitcroft <[email protected]>
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.

Quoted 25 lines

Check compat_features for the only valid combination.

Fixes ecbfb9f118bce4 ("dm raid: add raid level takeover support")
---
  drivers/md/dm-raid.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)

V2: simplify checks as per maintainer.

drivers/md/dm-raid.c +2 -1
index 8abde6b..2a39700 100644
@@ -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;
  	}
#7 lore raw
In reply to Heinz Mauelshagen
Quoted 23 lines · Heinz Mauelshagen
Quoted 20 lines · Andy Whitcroft
Quoted 10 lines · Heinz Mauelshagen

Andy,

good catch.

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

{

(quoted diff) +2 -0
+       if (le32_to_cpu(sb->compat_features) &&
+           le32_to_cpu(sb->compat_features) != FEATURE_FLAG_SUPPORTS_V190)
Quoted 5 lines
{
                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:

Quoted 6 lines
Quoted 3 lines

+ 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

#8 lore raw
Quoted 27 lines · Mike Snitzer
Quoted 24 lines · Heinz Mauelshagen
Quoted 22 lines · Andy Whitcroft
Quoted 10 lines · Heinz Mauelshagen

Andy,

good catch.

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

{

(quoted diff) +2 -0
+       if (le32_to_cpu(sb->compat_features) &&
+           le32_to_cpu(sb->compat_features) != FEATURE_FLAG_SUPPORTS_V190)
Quoted 5 lines
{
                 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)) {

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

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.

If we'll have to introduce more feature flags in the future (e.g. for clustered raid1 support), this is going to be based on the test_bit() API for consistency with any other flag processing we do in the target.

Heinz

Quoted 5 lines

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