2019-04-24 09:51:52

by Chao Yu

[permalink] [raw]
Subject: [PATCH] f2fs: fix to do sanity with enabled features in image

This patch fixes to do sanity with enabled features in image, if
there are features kernel can not recognize, just fail the mount.

Signed-off-by: Chao Yu <[email protected]>
---
fs/f2fs/f2fs.h | 13 +++++++++++++
fs/f2fs/super.c | 9 +++++++++
2 files changed, 22 insertions(+)

diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index f5ffc09705eb..15b640967e12 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -151,6 +151,19 @@ struct f2fs_mount_info {
#define F2FS_FEATURE_VERITY 0x0400 /* reserved */
#define F2FS_FEATURE_SB_CHKSUM 0x0800

+#define F2FS_ALL_FEATURES (F2FS_FEATURE_ENCRYPT | \
+ F2FS_FEATURE_BLKZONED | \
+ F2FS_FEATURE_ATOMIC_WRITE | \
+ F2FS_FEATURE_EXTRA_ATTR | \
+ F2FS_FEATURE_PRJQUOTA | \
+ F2FS_FEATURE_INODE_CHKSUM | \
+ F2FS_FEATURE_FLEXIBLE_INLINE_XATTR | \
+ F2FS_FEATURE_QUOTA_INO | \
+ F2FS_FEATURE_INODE_CRTIME | \
+ F2FS_FEATURE_LOST_FOUND | \
+ F2FS_FEATURE_VERITY | \
+ F2FS_FEATURE_SB_CHKSUM)
+
#define __F2FS_HAS_FEATURE(raw_super, mask) \
((raw_super->feature & cpu_to_le32(mask)) != 0)
#define F2FS_HAS_FEATURE(sbi, mask) __F2FS_HAS_FEATURE(sbi->raw_super, mask)
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index 4f8e9ab48b26..57f2fc6d14ba 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -2573,6 +2573,15 @@ static int sanity_check_raw_super(struct f2fs_sb_info *sbi,
return 1;
}

+ /* check whether kernel supports all features */
+ if (le32_to_cpu(raw_super->feature) & (~F2FS_ALL_FEATURES)) {
+ f2fs_msg(sb, KERN_INFO,
+ "Unsupported feature:%u: supported:%u",
+ le32_to_cpu(raw_super->feature),
+ F2FS_ALL_FEATURES);
+ return 1;
+ }
+
/* check CP/SIT/NAT/SSA/MAIN_AREA area boundary */
if (sanity_check_area_boundary(sbi, bh))
return 1;
--
2.18.0.rc1


2019-04-28 13:39:15

by Jaegeuk Kim

[permalink] [raw]
Subject: Re: [PATCH] f2fs: fix to do sanity with enabled features in image

On 04/24, Chao Yu wrote:
> This patch fixes to do sanity with enabled features in image, if
> there are features kernel can not recognize, just fail the mount.

We need to figure out per-feature-based rejection, since some of them can
be set without layout change.

>
> Signed-off-by: Chao Yu <[email protected]>
> ---
> fs/f2fs/f2fs.h | 13 +++++++++++++
> fs/f2fs/super.c | 9 +++++++++
> 2 files changed, 22 insertions(+)
>
> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
> index f5ffc09705eb..15b640967e12 100644
> --- a/fs/f2fs/f2fs.h
> +++ b/fs/f2fs/f2fs.h
> @@ -151,6 +151,19 @@ struct f2fs_mount_info {
> #define F2FS_FEATURE_VERITY 0x0400 /* reserved */
> #define F2FS_FEATURE_SB_CHKSUM 0x0800
>
> +#define F2FS_ALL_FEATURES (F2FS_FEATURE_ENCRYPT | \
> + F2FS_FEATURE_BLKZONED | \
> + F2FS_FEATURE_ATOMIC_WRITE | \
> + F2FS_FEATURE_EXTRA_ATTR | \
> + F2FS_FEATURE_PRJQUOTA | \
> + F2FS_FEATURE_INODE_CHKSUM | \
> + F2FS_FEATURE_FLEXIBLE_INLINE_XATTR | \
> + F2FS_FEATURE_QUOTA_INO | \
> + F2FS_FEATURE_INODE_CRTIME | \
> + F2FS_FEATURE_LOST_FOUND | \
> + F2FS_FEATURE_VERITY | \
> + F2FS_FEATURE_SB_CHKSUM)
> +
> #define __F2FS_HAS_FEATURE(raw_super, mask) \
> ((raw_super->feature & cpu_to_le32(mask)) != 0)
> #define F2FS_HAS_FEATURE(sbi, mask) __F2FS_HAS_FEATURE(sbi->raw_super, mask)
> diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
> index 4f8e9ab48b26..57f2fc6d14ba 100644
> --- a/fs/f2fs/super.c
> +++ b/fs/f2fs/super.c
> @@ -2573,6 +2573,15 @@ static int sanity_check_raw_super(struct f2fs_sb_info *sbi,
> return 1;
> }
>
> + /* check whether kernel supports all features */
> + if (le32_to_cpu(raw_super->feature) & (~F2FS_ALL_FEATURES)) {
> + f2fs_msg(sb, KERN_INFO,
> + "Unsupported feature:%u: supported:%u",
> + le32_to_cpu(raw_super->feature),
> + F2FS_ALL_FEATURES);
> + return 1;
> + }
> +
> /* check CP/SIT/NAT/SSA/MAIN_AREA area boundary */
> if (sanity_check_area_boundary(sbi, bh))
> return 1;
> --
> 2.18.0.rc1

2019-04-29 14:00:33

by Chao Yu

[permalink] [raw]
Subject: Re: [PATCH] f2fs: fix to do sanity with enabled features in image

On 2019-4-28 21:38, Jaegeuk Kim wrote:
> On 04/24, Chao Yu wrote:
>> This patch fixes to do sanity with enabled features in image, if
>> there are features kernel can not recognize, just fail the mount.
>
> We need to figure out per-feature-based rejection, since some of them can
> be set without layout change.

So any suggestion on how to implement this?

Maybe:

if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0))
check 4.14+ features
else if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0))
check 4.9+ features
else if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 4, 0))
check 4.4+ features

Thanks,

>
>>
>> Signed-off-by: Chao Yu <[email protected]>
>> ---
>> fs/f2fs/f2fs.h | 13 +++++++++++++
>> fs/f2fs/super.c | 9 +++++++++
>> 2 files changed, 22 insertions(+)
>>
>> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
>> index f5ffc09705eb..15b640967e12 100644
>> --- a/fs/f2fs/f2fs.h
>> +++ b/fs/f2fs/f2fs.h
>> @@ -151,6 +151,19 @@ struct f2fs_mount_info {
>> #define F2FS_FEATURE_VERITY 0x0400 /* reserved */
>> #define F2FS_FEATURE_SB_CHKSUM 0x0800
>>
>> +#define F2FS_ALL_FEATURES (F2FS_FEATURE_ENCRYPT | \
>> + F2FS_FEATURE_BLKZONED | \
>> + F2FS_FEATURE_ATOMIC_WRITE | \
>> + F2FS_FEATURE_EXTRA_ATTR | \
>> + F2FS_FEATURE_PRJQUOTA | \
>> + F2FS_FEATURE_INODE_CHKSUM | \
>> + F2FS_FEATURE_FLEXIBLE_INLINE_XATTR | \
>> + F2FS_FEATURE_QUOTA_INO | \
>> + F2FS_FEATURE_INODE_CRTIME | \
>> + F2FS_FEATURE_LOST_FOUND | \
>> + F2FS_FEATURE_VERITY | \
>> + F2FS_FEATURE_SB_CHKSUM)
>> +
>> #define __F2FS_HAS_FEATURE(raw_super, mask) \
>> ((raw_super->feature & cpu_to_le32(mask)) != 0)
>> #define F2FS_HAS_FEATURE(sbi, mask) __F2FS_HAS_FEATURE(sbi->raw_super, mask)
>> diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
>> index 4f8e9ab48b26..57f2fc6d14ba 100644
>> --- a/fs/f2fs/super.c
>> +++ b/fs/f2fs/super.c
>> @@ -2573,6 +2573,15 @@ static int sanity_check_raw_super(struct f2fs_sb_info *sbi,
>> return 1;
>> }
>>
>> + /* check whether kernel supports all features */
>> + if (le32_to_cpu(raw_super->feature) & (~F2FS_ALL_FEATURES)) {
>> + f2fs_msg(sb, KERN_INFO,
>> + "Unsupported feature:%u: supported:%u",
>> + le32_to_cpu(raw_super->feature),
>> + F2FS_ALL_FEATURES);
>> + return 1;
>> + }
>> +
>> /* check CP/SIT/NAT/SSA/MAIN_AREA area boundary */
>> if (sanity_check_area_boundary(sbi, bh))
>> return 1;
>> --
>> 2.18.0.rc1

2019-04-29 20:56:34

by Juhyung Park

[permalink] [raw]
Subject: Re: [f2fs-dev] [PATCH] f2fs: fix to do sanity with enabled features in image

Hi Chao and Jaegeuk,

On Wed, Apr 24, 2019 at 6:49 PM Chao Yu <[email protected]> wrote:
>
> This patch fixes to do sanity with enabled features in image, if
> there are features kernel can not recognize, just fail the mount.
>

Surprised to see that this wasn't implemented yet.
I was actually about to suggest this method to prevent mounting of the
new extended bitmap layout images altogether for older kernels(by
renaming the new, fixed layout to v2 or something), but looks like
that isn't an option. :(

Also, something similar should be also done with fsck, if not already.
The results from using older fsck with images with newer features
would be disastrous.

I'm still very busy currently with my other projects.
Sorry for the delays in testing new patchsets for layout fixes.

And I apologize in advance in case I miss the Linux 5.2 merge window
deadline, but I'd like to see it being fixed properly before shipping
those patches to production.

> + /* check whether kernel supports all features */
> + if (le32_to_cpu(raw_super->feature) & (~F2FS_ALL_FEATURES)) {
> + f2fs_msg(sb, KERN_INFO,
> + "Unsupported feature:%u: supported:%u",
> + le32_to_cpu(raw_super->feature),
> + F2FS_ALL_FEATURES);
> + return 1;
> + }

This should probably be a KERN_ERR instead of KERN_INFO.

Thanks.

2019-05-01 03:24:00

by Jaegeuk Kim

[permalink] [raw]
Subject: Re: [PATCH] f2fs: fix to do sanity with enabled features in image

On 04/29, Chao Yu wrote:
> On 2019-4-28 21:38, Jaegeuk Kim wrote:
> > On 04/24, Chao Yu wrote:
> >> This patch fixes to do sanity with enabled features in image, if
> >> there are features kernel can not recognize, just fail the mount.
> >
> > We need to figure out per-feature-based rejection, since some of them can
> > be set without layout change.
>
> So any suggestion on how to implement this?

Which features do we need to disallow? When we introduce new features, they
didn't hurt the previous flow by checking f2fs_sb_has_###().

>
> Maybe:
>
> if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0))
> check 4.14+ features
> else if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0))
> check 4.9+ features
> else if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 4, 0))
> check 4.4+ features
>
> Thanks,
>
> >
> >>
> >> Signed-off-by: Chao Yu <[email protected]>
> >> ---
> >> fs/f2fs/f2fs.h | 13 +++++++++++++
> >> fs/f2fs/super.c | 9 +++++++++
> >> 2 files changed, 22 insertions(+)
> >>
> >> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
> >> index f5ffc09705eb..15b640967e12 100644
> >> --- a/fs/f2fs/f2fs.h
> >> +++ b/fs/f2fs/f2fs.h
> >> @@ -151,6 +151,19 @@ struct f2fs_mount_info {
> >> #define F2FS_FEATURE_VERITY 0x0400 /* reserved */
> >> #define F2FS_FEATURE_SB_CHKSUM 0x0800
> >>
> >> +#define F2FS_ALL_FEATURES (F2FS_FEATURE_ENCRYPT | \
> >> + F2FS_FEATURE_BLKZONED | \
> >> + F2FS_FEATURE_ATOMIC_WRITE | \
> >> + F2FS_FEATURE_EXTRA_ATTR | \
> >> + F2FS_FEATURE_PRJQUOTA | \
> >> + F2FS_FEATURE_INODE_CHKSUM | \
> >> + F2FS_FEATURE_FLEXIBLE_INLINE_XATTR | \
> >> + F2FS_FEATURE_QUOTA_INO | \
> >> + F2FS_FEATURE_INODE_CRTIME | \
> >> + F2FS_FEATURE_LOST_FOUND | \
> >> + F2FS_FEATURE_VERITY | \
> >> + F2FS_FEATURE_SB_CHKSUM)
> >> +
> >> #define __F2FS_HAS_FEATURE(raw_super, mask) \
> >> ((raw_super->feature & cpu_to_le32(mask)) != 0)
> >> #define F2FS_HAS_FEATURE(sbi, mask) __F2FS_HAS_FEATURE(sbi->raw_super, mask)
> >> diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
> >> index 4f8e9ab48b26..57f2fc6d14ba 100644
> >> --- a/fs/f2fs/super.c
> >> +++ b/fs/f2fs/super.c
> >> @@ -2573,6 +2573,15 @@ static int sanity_check_raw_super(struct f2fs_sb_info *sbi,
> >> return 1;
> >> }
> >>
> >> + /* check whether kernel supports all features */
> >> + if (le32_to_cpu(raw_super->feature) & (~F2FS_ALL_FEATURES)) {
> >> + f2fs_msg(sb, KERN_INFO,
> >> + "Unsupported feature:%u: supported:%u",
> >> + le32_to_cpu(raw_super->feature),
> >> + F2FS_ALL_FEATURES);
> >> + return 1;
> >> + }
> >> +
> >> /* check CP/SIT/NAT/SSA/MAIN_AREA area boundary */
> >> if (sanity_check_area_boundary(sbi, bh))
> >> return 1;
> >> --
> >> 2.18.0.rc1

2019-05-05 02:54:41

by Chao Yu

[permalink] [raw]
Subject: Re: [PATCH] f2fs: fix to do sanity with enabled features in image

On 2019/5/1 11:22, Jaegeuk Kim wrote:
> On 04/29, Chao Yu wrote:
>> On 2019-4-28 21:38, Jaegeuk Kim wrote:
>>> On 04/24, Chao Yu wrote:
>>>> This patch fixes to do sanity with enabled features in image, if
>>>> there are features kernel can not recognize, just fail the mount.
>>>
>>> We need to figure out per-feature-based rejection, since some of them can
>>> be set without layout change.
>>
>> So any suggestion on how to implement this?
>
> Which features do we need to disallow? When we introduce new features, they

I guess it should be the new features.

> didn't hurt the previous flow by checking f2fs_sb_has_###().

Yes, but new features may use new disk layout, if old kernel handled it with old
disk layout, there must be problematic.

e.g. format image with -O extra_attr, and mount it with kernel who don't
recognize new inode layout.

Thanks,

>
>>
>> Maybe:
>>
>> if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0))
>> check 4.14+ features
>> else if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0))
>> check 4.9+ features
>> else if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 4, 0))
>> check 4.4+ features
>>
>> Thanks,
>>
>>>
>>>>
>>>> Signed-off-by: Chao Yu <[email protected]>
>>>> ---
>>>> fs/f2fs/f2fs.h | 13 +++++++++++++
>>>> fs/f2fs/super.c | 9 +++++++++
>>>> 2 files changed, 22 insertions(+)
>>>>
>>>> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
>>>> index f5ffc09705eb..15b640967e12 100644
>>>> --- a/fs/f2fs/f2fs.h
>>>> +++ b/fs/f2fs/f2fs.h
>>>> @@ -151,6 +151,19 @@ struct f2fs_mount_info {
>>>> #define F2FS_FEATURE_VERITY 0x0400 /* reserved */
>>>> #define F2FS_FEATURE_SB_CHKSUM 0x0800
>>>>
>>>> +#define F2FS_ALL_FEATURES (F2FS_FEATURE_ENCRYPT | \
>>>> + F2FS_FEATURE_BLKZONED | \
>>>> + F2FS_FEATURE_ATOMIC_WRITE | \
>>>> + F2FS_FEATURE_EXTRA_ATTR | \
>>>> + F2FS_FEATURE_PRJQUOTA | \
>>>> + F2FS_FEATURE_INODE_CHKSUM | \
>>>> + F2FS_FEATURE_FLEXIBLE_INLINE_XATTR | \
>>>> + F2FS_FEATURE_QUOTA_INO | \
>>>> + F2FS_FEATURE_INODE_CRTIME | \
>>>> + F2FS_FEATURE_LOST_FOUND | \
>>>> + F2FS_FEATURE_VERITY | \
>>>> + F2FS_FEATURE_SB_CHKSUM)
>>>> +
>>>> #define __F2FS_HAS_FEATURE(raw_super, mask) \
>>>> ((raw_super->feature & cpu_to_le32(mask)) != 0)
>>>> #define F2FS_HAS_FEATURE(sbi, mask) __F2FS_HAS_FEATURE(sbi->raw_super, mask)
>>>> diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
>>>> index 4f8e9ab48b26..57f2fc6d14ba 100644
>>>> --- a/fs/f2fs/super.c
>>>> +++ b/fs/f2fs/super.c
>>>> @@ -2573,6 +2573,15 @@ static int sanity_check_raw_super(struct f2fs_sb_info *sbi,
>>>> return 1;
>>>> }
>>>>
>>>> + /* check whether kernel supports all features */
>>>> + if (le32_to_cpu(raw_super->feature) & (~F2FS_ALL_FEATURES)) {
>>>> + f2fs_msg(sb, KERN_INFO,
>>>> + "Unsupported feature:%u: supported:%u",
>>>> + le32_to_cpu(raw_super->feature),
>>>> + F2FS_ALL_FEATURES);
>>>> + return 1;
>>>> + }
>>>> +
>>>> /* check CP/SIT/NAT/SSA/MAIN_AREA area boundary */
>>>> if (sanity_check_area_boundary(sbi, bh))
>>>> return 1;
>>>> --
>>>> 2.18.0.rc1
> .
>

2019-05-09 01:17:08

by Chao Yu

[permalink] [raw]
Subject: Re: [f2fs-dev] [PATCH] f2fs: fix to do sanity with enabled features in image

On 2019/5/5 10:51, Chao Yu wrote:
> On 2019/5/1 11:22, Jaegeuk Kim wrote:
>> On 04/29, Chao Yu wrote:
>>> On 2019-4-28 21:38, Jaegeuk Kim wrote:
>>>> On 04/24, Chao Yu wrote:
>>>>> This patch fixes to do sanity with enabled features in image, if
>>>>> there are features kernel can not recognize, just fail the mount.
>>>>
>>>> We need to figure out per-feature-based rejection, since some of them can
>>>> be set without layout change.
>>>
>>> So any suggestion on how to implement this?
>>
>> Which features do we need to disallow? When we introduce new features, they
>
> I guess it should be the new features.
>
>> didn't hurt the previous flow by checking f2fs_sb_has_###().
>
> Yes, but new features may use new disk layout, if old kernel handled it with old
> disk layout, there must be problematic.
>
> e.g. format image with -O extra_attr, and mount it with kernel who don't
> recognize new inode layout.

Jaegeuk,

Any thoughts?

Thanks,

>
> Thanks,
>
>>
>>>
>>> Maybe:
>>>
>>> if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0))
>>> check 4.14+ features
>>> else if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0))
>>> check 4.9+ features
>>> else if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 4, 0))
>>> check 4.4+ features
>>>
>>> Thanks,
>>>
>>>>
>>>>>
>>>>> Signed-off-by: Chao Yu <[email protected]>
>>>>> ---
>>>>> fs/f2fs/f2fs.h | 13 +++++++++++++
>>>>> fs/f2fs/super.c | 9 +++++++++
>>>>> 2 files changed, 22 insertions(+)
>>>>>
>>>>> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
>>>>> index f5ffc09705eb..15b640967e12 100644
>>>>> --- a/fs/f2fs/f2fs.h
>>>>> +++ b/fs/f2fs/f2fs.h
>>>>> @@ -151,6 +151,19 @@ struct f2fs_mount_info {
>>>>> #define F2FS_FEATURE_VERITY 0x0400 /* reserved */
>>>>> #define F2FS_FEATURE_SB_CHKSUM 0x0800
>>>>>
>>>>> +#define F2FS_ALL_FEATURES (F2FS_FEATURE_ENCRYPT | \
>>>>> + F2FS_FEATURE_BLKZONED | \
>>>>> + F2FS_FEATURE_ATOMIC_WRITE | \
>>>>> + F2FS_FEATURE_EXTRA_ATTR | \
>>>>> + F2FS_FEATURE_PRJQUOTA | \
>>>>> + F2FS_FEATURE_INODE_CHKSUM | \
>>>>> + F2FS_FEATURE_FLEXIBLE_INLINE_XATTR | \
>>>>> + F2FS_FEATURE_QUOTA_INO | \
>>>>> + F2FS_FEATURE_INODE_CRTIME | \
>>>>> + F2FS_FEATURE_LOST_FOUND | \
>>>>> + F2FS_FEATURE_VERITY | \
>>>>> + F2FS_FEATURE_SB_CHKSUM)
>>>>> +
>>>>> #define __F2FS_HAS_FEATURE(raw_super, mask) \
>>>>> ((raw_super->feature & cpu_to_le32(mask)) != 0)
>>>>> #define F2FS_HAS_FEATURE(sbi, mask) __F2FS_HAS_FEATURE(sbi->raw_super, mask)
>>>>> diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
>>>>> index 4f8e9ab48b26..57f2fc6d14ba 100644
>>>>> --- a/fs/f2fs/super.c
>>>>> +++ b/fs/f2fs/super.c
>>>>> @@ -2573,6 +2573,15 @@ static int sanity_check_raw_super(struct f2fs_sb_info *sbi,
>>>>> return 1;
>>>>> }
>>>>>
>>>>> + /* check whether kernel supports all features */
>>>>> + if (le32_to_cpu(raw_super->feature) & (~F2FS_ALL_FEATURES)) {
>>>>> + f2fs_msg(sb, KERN_INFO,
>>>>> + "Unsupported feature:%u: supported:%u",
>>>>> + le32_to_cpu(raw_super->feature),
>>>>> + F2FS_ALL_FEATURES);
>>>>> + return 1;
>>>>> + }
>>>>> +
>>>>> /* check CP/SIT/NAT/SSA/MAIN_AREA area boundary */
>>>>> if (sanity_check_area_boundary(sbi, bh))
>>>>> return 1;
>>>>> --
>>>>> 2.18.0.rc1
>> .
>>
>
>
> _______________________________________________
> Linux-f2fs-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
> .
>

2019-07-16 10:05:11

by Chao Yu

[permalink] [raw]
Subject: Re: [f2fs-dev] [PATCH] f2fs: fix to do sanity with enabled features in image

Hi Jaegeuk,

On 2019/5/9 9:15, Chao Yu wrote:
> On 2019/5/5 10:51, Chao Yu wrote:
>> On 2019/5/1 11:22, Jaegeuk Kim wrote:
>>> On 04/29, Chao Yu wrote:
>>>> On 2019-4-28 21:38, Jaegeuk Kim wrote:
>>>>> On 04/24, Chao Yu wrote:
>>>>>> This patch fixes to do sanity with enabled features in image, if
>>>>>> there are features kernel can not recognize, just fail the mount.
>>>>>
>>>>> We need to figure out per-feature-based rejection, since some of them can
>>>>> be set without layout change.

What about adding one field in superblock for compatible features in future?

sb.feature(F2FS_FEATURE_LAST, max] stores uncompatible features
sb.compatible_feature stores compatible features

If we follow above rule when adding one feature, then, we can fail the mount if
sb.feature(F2FS_FEATURE_LAST, max] is valid.

Thanks,

>>>>
>>>> So any suggestion on how to implement this?
>>>
>>> Which features do we need to disallow? When we introduce new features, they
>>
>> I guess it should be the new features.
>>
>>> didn't hurt the previous flow by checking f2fs_sb_has_###().
>>
>> Yes, but new features may use new disk layout, if old kernel handled it with old
>> disk layout, there must be problematic.
>>
>> e.g. format image with -O extra_attr, and mount it with kernel who don't
>> recognize new inode layout.
>
> Jaegeuk,
>
> Any thoughts?
>
> Thanks,
>
>>
>> Thanks,
>>
>>>
>>>>
>>>> Maybe:
>>>>
>>>> if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0))
>>>> check 4.14+ features
>>>> else if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0))
>>>> check 4.9+ features
>>>> else if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 4, 0))
>>>> check 4.4+ features
>>>>
>>>> Thanks,
>>>>
>>>>>
>>>>>>
>>>>>> Signed-off-by: Chao Yu <[email protected]>
>>>>>> ---
>>>>>> fs/f2fs/f2fs.h | 13 +++++++++++++
>>>>>> fs/f2fs/super.c | 9 +++++++++
>>>>>> 2 files changed, 22 insertions(+)
>>>>>>
>>>>>> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
>>>>>> index f5ffc09705eb..15b640967e12 100644
>>>>>> --- a/fs/f2fs/f2fs.h
>>>>>> +++ b/fs/f2fs/f2fs.h
>>>>>> @@ -151,6 +151,19 @@ struct f2fs_mount_info {
>>>>>> #define F2FS_FEATURE_VERITY 0x0400 /* reserved */
>>>>>> #define F2FS_FEATURE_SB_CHKSUM 0x0800
>>>>>>
>>>>>> +#define F2FS_ALL_FEATURES (F2FS_FEATURE_ENCRYPT | \
>>>>>> + F2FS_FEATURE_BLKZONED | \
>>>>>> + F2FS_FEATURE_ATOMIC_WRITE | \
>>>>>> + F2FS_FEATURE_EXTRA_ATTR | \
>>>>>> + F2FS_FEATURE_PRJQUOTA | \
>>>>>> + F2FS_FEATURE_INODE_CHKSUM | \
>>>>>> + F2FS_FEATURE_FLEXIBLE_INLINE_XATTR | \
>>>>>> + F2FS_FEATURE_QUOTA_INO | \
>>>>>> + F2FS_FEATURE_INODE_CRTIME | \
>>>>>> + F2FS_FEATURE_LOST_FOUND | \
>>>>>> + F2FS_FEATURE_VERITY | \
>>>>>> + F2FS_FEATURE_SB_CHKSUM)
>>>>>> +
>>>>>> #define __F2FS_HAS_FEATURE(raw_super, mask) \
>>>>>> ((raw_super->feature & cpu_to_le32(mask)) != 0)
>>>>>> #define F2FS_HAS_FEATURE(sbi, mask) __F2FS_HAS_FEATURE(sbi->raw_super, mask)
>>>>>> diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
>>>>>> index 4f8e9ab48b26..57f2fc6d14ba 100644
>>>>>> --- a/fs/f2fs/super.c
>>>>>> +++ b/fs/f2fs/super.c
>>>>>> @@ -2573,6 +2573,15 @@ static int sanity_check_raw_super(struct f2fs_sb_info *sbi,
>>>>>> return 1;
>>>>>> }
>>>>>>
>>>>>> + /* check whether kernel supports all features */
>>>>>> + if (le32_to_cpu(raw_super->feature) & (~F2FS_ALL_FEATURES)) {
>>>>>> + f2fs_msg(sb, KERN_INFO,
>>>>>> + "Unsupported feature:%u: supported:%u",
>>>>>> + le32_to_cpu(raw_super->feature),
>>>>>> + F2FS_ALL_FEATURES);
>>>>>> + return 1;
>>>>>> + }
>>>>>> +
>>>>>> /* check CP/SIT/NAT/SSA/MAIN_AREA area boundary */
>>>>>> if (sanity_check_area_boundary(sbi, bh))
>>>>>> return 1;
>>>>>> --
>>>>>> 2.18.0.rc1
>>> .
>>>
>>
>>
>> _______________________________________________
>> Linux-f2fs-devel mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
>> .
>>
>
>
> _______________________________________________
> Linux-f2fs-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
> .
>

2019-07-23 11:32:08

by Jaegeuk Kim

[permalink] [raw]
Subject: Re: [f2fs-dev] [PATCH] f2fs: fix to do sanity with enabled features in image

On 07/16, Chao Yu wrote:
> Hi Jaegeuk,
>
> On 2019/5/9 9:15, Chao Yu wrote:
> > On 2019/5/5 10:51, Chao Yu wrote:
> >> On 2019/5/1 11:22, Jaegeuk Kim wrote:
> >>> On 04/29, Chao Yu wrote:
> >>>> On 2019-4-28 21:38, Jaegeuk Kim wrote:
> >>>>> On 04/24, Chao Yu wrote:
> >>>>>> This patch fixes to do sanity with enabled features in image, if
> >>>>>> there are features kernel can not recognize, just fail the mount.
> >>>>>
> >>>>> We need to figure out per-feature-based rejection, since some of them can
> >>>>> be set without layout change.
>
> What about adding one field in superblock for compatible features in future?
>
> sb.feature(F2FS_FEATURE_LAST, max] stores uncompatible features
> sb.compatible_feature stores compatible features
>
> If we follow above rule when adding one feature, then, we can fail the mount if
> sb.feature(F2FS_FEATURE_LAST, max] is valid.

How about adding required_features flag in sb to check part of features only?

>
> Thanks,
>
> >>>>
> >>>> So any suggestion on how to implement this?
> >>>
> >>> Which features do we need to disallow? When we introduce new features, they
> >>
> >> I guess it should be the new features.
> >>
> >>> didn't hurt the previous flow by checking f2fs_sb_has_###().
> >>
> >> Yes, but new features may use new disk layout, if old kernel handled it with old
> >> disk layout, there must be problematic.
> >>
> >> e.g. format image with -O extra_attr, and mount it with kernel who don't
> >> recognize new inode layout.
> >
> > Jaegeuk,
> >
> > Any thoughts?
> >
> > Thanks,
> >
> >>
> >> Thanks,
> >>
> >>>
> >>>>
> >>>> Maybe:
> >>>>
> >>>> if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0))
> >>>> check 4.14+ features
> >>>> else if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0))
> >>>> check 4.9+ features
> >>>> else if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 4, 0))
> >>>> check 4.4+ features
> >>>>
> >>>> Thanks,
> >>>>
> >>>>>
> >>>>>>
> >>>>>> Signed-off-by: Chao Yu <[email protected]>
> >>>>>> ---
> >>>>>> fs/f2fs/f2fs.h | 13 +++++++++++++
> >>>>>> fs/f2fs/super.c | 9 +++++++++
> >>>>>> 2 files changed, 22 insertions(+)
> >>>>>>
> >>>>>> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
> >>>>>> index f5ffc09705eb..15b640967e12 100644
> >>>>>> --- a/fs/f2fs/f2fs.h
> >>>>>> +++ b/fs/f2fs/f2fs.h
> >>>>>> @@ -151,6 +151,19 @@ struct f2fs_mount_info {
> >>>>>> #define F2FS_FEATURE_VERITY 0x0400 /* reserved */
> >>>>>> #define F2FS_FEATURE_SB_CHKSUM 0x0800
> >>>>>>
> >>>>>> +#define F2FS_ALL_FEATURES (F2FS_FEATURE_ENCRYPT | \
> >>>>>> + F2FS_FEATURE_BLKZONED | \
> >>>>>> + F2FS_FEATURE_ATOMIC_WRITE | \
> >>>>>> + F2FS_FEATURE_EXTRA_ATTR | \
> >>>>>> + F2FS_FEATURE_PRJQUOTA | \
> >>>>>> + F2FS_FEATURE_INODE_CHKSUM | \
> >>>>>> + F2FS_FEATURE_FLEXIBLE_INLINE_XATTR | \
> >>>>>> + F2FS_FEATURE_QUOTA_INO | \
> >>>>>> + F2FS_FEATURE_INODE_CRTIME | \
> >>>>>> + F2FS_FEATURE_LOST_FOUND | \
> >>>>>> + F2FS_FEATURE_VERITY | \
> >>>>>> + F2FS_FEATURE_SB_CHKSUM)
> >>>>>> +
> >>>>>> #define __F2FS_HAS_FEATURE(raw_super, mask) \
> >>>>>> ((raw_super->feature & cpu_to_le32(mask)) != 0)
> >>>>>> #define F2FS_HAS_FEATURE(sbi, mask) __F2FS_HAS_FEATURE(sbi->raw_super, mask)
> >>>>>> diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
> >>>>>> index 4f8e9ab48b26..57f2fc6d14ba 100644
> >>>>>> --- a/fs/f2fs/super.c
> >>>>>> +++ b/fs/f2fs/super.c
> >>>>>> @@ -2573,6 +2573,15 @@ static int sanity_check_raw_super(struct f2fs_sb_info *sbi,
> >>>>>> return 1;
> >>>>>> }
> >>>>>>
> >>>>>> + /* check whether kernel supports all features */
> >>>>>> + if (le32_to_cpu(raw_super->feature) & (~F2FS_ALL_FEATURES)) {
> >>>>>> + f2fs_msg(sb, KERN_INFO,
> >>>>>> + "Unsupported feature:%u: supported:%u",
> >>>>>> + le32_to_cpu(raw_super->feature),
> >>>>>> + F2FS_ALL_FEATURES);
> >>>>>> + return 1;
> >>>>>> + }
> >>>>>> +
> >>>>>> /* check CP/SIT/NAT/SSA/MAIN_AREA area boundary */
> >>>>>> if (sanity_check_area_boundary(sbi, bh))
> >>>>>> return 1;
> >>>>>> --
> >>>>>> 2.18.0.rc1
> >>> .
> >>>
> >>
> >>
> >> _______________________________________________
> >> Linux-f2fs-devel mailing list
> >> [email protected]
> >> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
> >> .
> >>
> >
> >
> > _______________________________________________
> > Linux-f2fs-devel mailing list
> > [email protected]
> > https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
> > .
> >

2019-07-23 16:19:36

by Chao Yu

[permalink] [raw]
Subject: Re: [f2fs-dev] [PATCH] f2fs: fix to do sanity with enabled features in image

On 2019/7/23 9:35, Jaegeuk Kim wrote:
> On 07/16, Chao Yu wrote:
>> Hi Jaegeuk,
>>
>> On 2019/5/9 9:15, Chao Yu wrote:
>>> On 2019/5/5 10:51, Chao Yu wrote:
>>>> On 2019/5/1 11:22, Jaegeuk Kim wrote:
>>>>> On 04/29, Chao Yu wrote:
>>>>>> On 2019-4-28 21:38, Jaegeuk Kim wrote:
>>>>>>> On 04/24, Chao Yu wrote:
>>>>>>>> This patch fixes to do sanity with enabled features in image, if
>>>>>>>> there are features kernel can not recognize, just fail the mount.
>>>>>>>
>>>>>>> We need to figure out per-feature-based rejection, since some of them can
>>>>>>> be set without layout change.
>>
>> What about adding one field in superblock for compatible features in future?
>>
>> sb.feature(F2FS_FEATURE_LAST, max] stores uncompatible features
>> sb.compatible_feature stores compatible features
>>
>> If we follow above rule when adding one feature, then, we can fail the mount if
>> sb.feature(F2FS_FEATURE_LAST, max] is valid.
>
> How about adding required_features flag in sb to check part of features only?

You mean all incompatible features can be add into sb.required_features later
like this?

__le32 required_features; /* incompatible feature to old kernel */

And we can check required_features with supported features in current kernel?

if (le32_to_cpu(raw_super->required_features) &
(~NOW_SUPPORTED_FEATURES_IN_CURRENT_KERNEL)) {
print msg & ret error;
}

Thanks,

>
>>
>> Thanks,
>>
>>>>>>
>>>>>> So any suggestion on how to implement this?
>>>>>
>>>>> Which features do we need to disallow? When we introduce new features, they
>>>>
>>>> I guess it should be the new features.
>>>>
>>>>> didn't hurt the previous flow by checking f2fs_sb_has_###().
>>>>
>>>> Yes, but new features may use new disk layout, if old kernel handled it with old
>>>> disk layout, there must be problematic.
>>>>
>>>> e.g. format image with -O extra_attr, and mount it with kernel who don't
>>>> recognize new inode layout.
>>>
>>> Jaegeuk,
>>>
>>> Any thoughts?
>>>
>>> Thanks,
>>>
>>>>
>>>> Thanks,
>>>>
>>>>>
>>>>>>
>>>>>> Maybe:
>>>>>>
>>>>>> if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0))
>>>>>> check 4.14+ features
>>>>>> else if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0))
>>>>>> check 4.9+ features
>>>>>> else if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 4, 0))
>>>>>> check 4.4+ features
>>>>>>
>>>>>> Thanks,
>>>>>>
>>>>>>>
>>>>>>>>
>>>>>>>> Signed-off-by: Chao Yu <[email protected]>
>>>>>>>> ---
>>>>>>>> fs/f2fs/f2fs.h | 13 +++++++++++++
>>>>>>>> fs/f2fs/super.c | 9 +++++++++
>>>>>>>> 2 files changed, 22 insertions(+)
>>>>>>>>
>>>>>>>> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
>>>>>>>> index f5ffc09705eb..15b640967e12 100644
>>>>>>>> --- a/fs/f2fs/f2fs.h
>>>>>>>> +++ b/fs/f2fs/f2fs.h
>>>>>>>> @@ -151,6 +151,19 @@ struct f2fs_mount_info {
>>>>>>>> #define F2FS_FEATURE_VERITY 0x0400 /* reserved */
>>>>>>>> #define F2FS_FEATURE_SB_CHKSUM 0x0800
>>>>>>>>
>>>>>>>> +#define F2FS_ALL_FEATURES (F2FS_FEATURE_ENCRYPT | \
>>>>>>>> + F2FS_FEATURE_BLKZONED | \
>>>>>>>> + F2FS_FEATURE_ATOMIC_WRITE | \
>>>>>>>> + F2FS_FEATURE_EXTRA_ATTR | \
>>>>>>>> + F2FS_FEATURE_PRJQUOTA | \
>>>>>>>> + F2FS_FEATURE_INODE_CHKSUM | \
>>>>>>>> + F2FS_FEATURE_FLEXIBLE_INLINE_XATTR | \
>>>>>>>> + F2FS_FEATURE_QUOTA_INO | \
>>>>>>>> + F2FS_FEATURE_INODE_CRTIME | \
>>>>>>>> + F2FS_FEATURE_LOST_FOUND | \
>>>>>>>> + F2FS_FEATURE_VERITY | \
>>>>>>>> + F2FS_FEATURE_SB_CHKSUM)
>>>>>>>> +
>>>>>>>> #define __F2FS_HAS_FEATURE(raw_super, mask) \
>>>>>>>> ((raw_super->feature & cpu_to_le32(mask)) != 0)
>>>>>>>> #define F2FS_HAS_FEATURE(sbi, mask) __F2FS_HAS_FEATURE(sbi->raw_super, mask)
>>>>>>>> diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
>>>>>>>> index 4f8e9ab48b26..57f2fc6d14ba 100644
>>>>>>>> --- a/fs/f2fs/super.c
>>>>>>>> +++ b/fs/f2fs/super.c
>>>>>>>> @@ -2573,6 +2573,15 @@ static int sanity_check_raw_super(struct f2fs_sb_info *sbi,
>>>>>>>> return 1;
>>>>>>>> }
>>>>>>>>
>>>>>>>> + /* check whether kernel supports all features */
>>>>>>>> + if (le32_to_cpu(raw_super->feature) & (~F2FS_ALL_FEATURES)) {
>>>>>>>> + f2fs_msg(sb, KERN_INFO,
>>>>>>>> + "Unsupported feature:%u: supported:%u",
>>>>>>>> + le32_to_cpu(raw_super->feature),
>>>>>>>> + F2FS_ALL_FEATURES);
>>>>>>>> + return 1;
>>>>>>>> + }
>>>>>>>> +
>>>>>>>> /* check CP/SIT/NAT/SSA/MAIN_AREA area boundary */
>>>>>>>> if (sanity_check_area_boundary(sbi, bh))
>>>>>>>> return 1;
>>>>>>>> --
>>>>>>>> 2.18.0.rc1
>>>>> .
>>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> Linux-f2fs-devel mailing list
>>>> [email protected]
>>>> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
>>>> .
>>>>
>>>
>>>
>>> _______________________________________________
>>> Linux-f2fs-devel mailing list
>>> [email protected]
>>> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
>>> .
>>>
> .
>

2019-07-29 05:49:24

by Jaegeuk Kim

[permalink] [raw]
Subject: Re: [f2fs-dev] [PATCH] f2fs: fix to do sanity with enabled features in image

On 07/23, Chao Yu wrote:
> On 2019/7/23 9:35, Jaegeuk Kim wrote:
> > On 07/16, Chao Yu wrote:
> >> Hi Jaegeuk,
> >>
> >> On 2019/5/9 9:15, Chao Yu wrote:
> >>> On 2019/5/5 10:51, Chao Yu wrote:
> >>>> On 2019/5/1 11:22, Jaegeuk Kim wrote:
> >>>>> On 04/29, Chao Yu wrote:
> >>>>>> On 2019-4-28 21:38, Jaegeuk Kim wrote:
> >>>>>>> On 04/24, Chao Yu wrote:
> >>>>>>>> This patch fixes to do sanity with enabled features in image, if
> >>>>>>>> there are features kernel can not recognize, just fail the mount.
> >>>>>>>
> >>>>>>> We need to figure out per-feature-based rejection, since some of them can
> >>>>>>> be set without layout change.
> >>
> >> What about adding one field in superblock for compatible features in future?
> >>
> >> sb.feature(F2FS_FEATURE_LAST, max] stores uncompatible features
> >> sb.compatible_feature stores compatible features
> >>
> >> If we follow above rule when adding one feature, then, we can fail the mount if
> >> sb.feature(F2FS_FEATURE_LAST, max] is valid.
> >
> > How about adding required_features flag in sb to check part of features only?
>
> You mean all incompatible features can be add into sb.required_features later
> like this?
>
> __le32 required_features; /* incompatible feature to old kernel */
>
> And we can check required_features with supported features in current kernel?

Yeah, I think so.

>
> if (le32_to_cpu(raw_super->required_features) &
> (~NOW_SUPPORTED_FEATURES_IN_CURRENT_KERNEL)) {
> print msg & ret error;
> }
>
> Thanks,
>
> >
> >>
> >> Thanks,
> >>
> >>>>>>
> >>>>>> So any suggestion on how to implement this?
> >>>>>
> >>>>> Which features do we need to disallow? When we introduce new features, they
> >>>>
> >>>> I guess it should be the new features.
> >>>>
> >>>>> didn't hurt the previous flow by checking f2fs_sb_has_###().
> >>>>
> >>>> Yes, but new features may use new disk layout, if old kernel handled it with old
> >>>> disk layout, there must be problematic.
> >>>>
> >>>> e.g. format image with -O extra_attr, and mount it with kernel who don't
> >>>> recognize new inode layout.
> >>>
> >>> Jaegeuk,
> >>>
> >>> Any thoughts?
> >>>
> >>> Thanks,
> >>>
> >>>>
> >>>> Thanks,
> >>>>
> >>>>>
> >>>>>>
> >>>>>> Maybe:
> >>>>>>
> >>>>>> if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0))
> >>>>>> check 4.14+ features
> >>>>>> else if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0))
> >>>>>> check 4.9+ features
> >>>>>> else if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 4, 0))
> >>>>>> check 4.4+ features
> >>>>>>
> >>>>>> Thanks,
> >>>>>>
> >>>>>>>
> >>>>>>>>
> >>>>>>>> Signed-off-by: Chao Yu <[email protected]>
> >>>>>>>> ---
> >>>>>>>> fs/f2fs/f2fs.h | 13 +++++++++++++
> >>>>>>>> fs/f2fs/super.c | 9 +++++++++
> >>>>>>>> 2 files changed, 22 insertions(+)
> >>>>>>>>
> >>>>>>>> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
> >>>>>>>> index f5ffc09705eb..15b640967e12 100644
> >>>>>>>> --- a/fs/f2fs/f2fs.h
> >>>>>>>> +++ b/fs/f2fs/f2fs.h
> >>>>>>>> @@ -151,6 +151,19 @@ struct f2fs_mount_info {
> >>>>>>>> #define F2FS_FEATURE_VERITY 0x0400 /* reserved */
> >>>>>>>> #define F2FS_FEATURE_SB_CHKSUM 0x0800
> >>>>>>>>
> >>>>>>>> +#define F2FS_ALL_FEATURES (F2FS_FEATURE_ENCRYPT | \
> >>>>>>>> + F2FS_FEATURE_BLKZONED | \
> >>>>>>>> + F2FS_FEATURE_ATOMIC_WRITE | \
> >>>>>>>> + F2FS_FEATURE_EXTRA_ATTR | \
> >>>>>>>> + F2FS_FEATURE_PRJQUOTA | \
> >>>>>>>> + F2FS_FEATURE_INODE_CHKSUM | \
> >>>>>>>> + F2FS_FEATURE_FLEXIBLE_INLINE_XATTR | \
> >>>>>>>> + F2FS_FEATURE_QUOTA_INO | \
> >>>>>>>> + F2FS_FEATURE_INODE_CRTIME | \
> >>>>>>>> + F2FS_FEATURE_LOST_FOUND | \
> >>>>>>>> + F2FS_FEATURE_VERITY | \
> >>>>>>>> + F2FS_FEATURE_SB_CHKSUM)
> >>>>>>>> +
> >>>>>>>> #define __F2FS_HAS_FEATURE(raw_super, mask) \
> >>>>>>>> ((raw_super->feature & cpu_to_le32(mask)) != 0)
> >>>>>>>> #define F2FS_HAS_FEATURE(sbi, mask) __F2FS_HAS_FEATURE(sbi->raw_super, mask)
> >>>>>>>> diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
> >>>>>>>> index 4f8e9ab48b26..57f2fc6d14ba 100644
> >>>>>>>> --- a/fs/f2fs/super.c
> >>>>>>>> +++ b/fs/f2fs/super.c
> >>>>>>>> @@ -2573,6 +2573,15 @@ static int sanity_check_raw_super(struct f2fs_sb_info *sbi,
> >>>>>>>> return 1;
> >>>>>>>> }
> >>>>>>>>
> >>>>>>>> + /* check whether kernel supports all features */
> >>>>>>>> + if (le32_to_cpu(raw_super->feature) & (~F2FS_ALL_FEATURES)) {
> >>>>>>>> + f2fs_msg(sb, KERN_INFO,
> >>>>>>>> + "Unsupported feature:%u: supported:%u",
> >>>>>>>> + le32_to_cpu(raw_super->feature),
> >>>>>>>> + F2FS_ALL_FEATURES);
> >>>>>>>> + return 1;
> >>>>>>>> + }
> >>>>>>>> +
> >>>>>>>> /* check CP/SIT/NAT/SSA/MAIN_AREA area boundary */
> >>>>>>>> if (sanity_check_area_boundary(sbi, bh))
> >>>>>>>> return 1;
> >>>>>>>> --
> >>>>>>>> 2.18.0.rc1
> >>>>> .
> >>>>>
> >>>>
> >>>>
> >>>> _______________________________________________
> >>>> Linux-f2fs-devel mailing list
> >>>> [email protected]
> >>>> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
> >>>> .
> >>>>
> >>>
> >>>
> >>> _______________________________________________
> >>> Linux-f2fs-devel mailing list
> >>> [email protected]
> >>> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
> >>> .
> >>>
> > .
> >

2019-07-29 07:11:12

by Chao Yu

[permalink] [raw]
Subject: Re: [f2fs-dev] [PATCH] f2fs: fix to do sanity with enabled features in image

On 2019/7/29 13:47, Jaegeuk Kim wrote:
> On 07/23, Chao Yu wrote:
>> On 2019/7/23 9:35, Jaegeuk Kim wrote:
>>> On 07/16, Chao Yu wrote:
>>>> Hi Jaegeuk,
>>>>
>>>> On 2019/5/9 9:15, Chao Yu wrote:
>>>>> On 2019/5/5 10:51, Chao Yu wrote:
>>>>>> On 2019/5/1 11:22, Jaegeuk Kim wrote:
>>>>>>> On 04/29, Chao Yu wrote:
>>>>>>>> On 2019-4-28 21:38, Jaegeuk Kim wrote:
>>>>>>>>> On 04/24, Chao Yu wrote:
>>>>>>>>>> This patch fixes to do sanity with enabled features in image, if
>>>>>>>>>> there are features kernel can not recognize, just fail the mount.
>>>>>>>>>
>>>>>>>>> We need to figure out per-feature-based rejection, since some of them can
>>>>>>>>> be set without layout change.
>>>>
>>>> What about adding one field in superblock for compatible features in future?
>>>>
>>>> sb.feature(F2FS_FEATURE_LAST, max] stores uncompatible features
>>>> sb.compatible_feature stores compatible features
>>>>
>>>> If we follow above rule when adding one feature, then, we can fail the mount if
>>>> sb.feature(F2FS_FEATURE_LAST, max] is valid.
>>>
>>> How about adding required_features flag in sb to check part of features only?
>>
>> You mean all incompatible features can be add into sb.required_features later
>> like this?
>>
>> __le32 required_features; /* incompatible feature to old kernel */
>>
>> And we can check required_features with supported features in current kernel?
>
> Yeah, I think so.

Copied, let me update the patch.

Thanks,

>
>>
>> if (le32_to_cpu(raw_super->required_features) &
>> (~NOW_SUPPORTED_FEATURES_IN_CURRENT_KERNEL)) {
>> print msg & ret error;
>> }
>>
>> Thanks,
>>
>>>
>>>>
>>>> Thanks,
>>>>
>>>>>>>>
>>>>>>>> So any suggestion on how to implement this?
>>>>>>>
>>>>>>> Which features do we need to disallow? When we introduce new features, they
>>>>>>
>>>>>> I guess it should be the new features.
>>>>>>
>>>>>>> didn't hurt the previous flow by checking f2fs_sb_has_###().
>>>>>>
>>>>>> Yes, but new features may use new disk layout, if old kernel handled it with old
>>>>>> disk layout, there must be problematic.
>>>>>>
>>>>>> e.g. format image with -O extra_attr, and mount it with kernel who don't
>>>>>> recognize new inode layout.
>>>>>
>>>>> Jaegeuk,
>>>>>
>>>>> Any thoughts?
>>>>>
>>>>> Thanks,
>>>>>
>>>>>>
>>>>>> Thanks,
>>>>>>
>>>>>>>
>>>>>>>>
>>>>>>>> Maybe:
>>>>>>>>
>>>>>>>> if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0))
>>>>>>>> check 4.14+ features
>>>>>>>> else if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0))
>>>>>>>> check 4.9+ features
>>>>>>>> else if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 4, 0))
>>>>>>>> check 4.4+ features
>>>>>>>>
>>>>>>>> Thanks,
>>>>>>>>
>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> Signed-off-by: Chao Yu <[email protected]>
>>>>>>>>>> ---
>>>>>>>>>> fs/f2fs/f2fs.h | 13 +++++++++++++
>>>>>>>>>> fs/f2fs/super.c | 9 +++++++++
>>>>>>>>>> 2 files changed, 22 insertions(+)
>>>>>>>>>>
>>>>>>>>>> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
>>>>>>>>>> index f5ffc09705eb..15b640967e12 100644
>>>>>>>>>> --- a/fs/f2fs/f2fs.h
>>>>>>>>>> +++ b/fs/f2fs/f2fs.h
>>>>>>>>>> @@ -151,6 +151,19 @@ struct f2fs_mount_info {
>>>>>>>>>> #define F2FS_FEATURE_VERITY 0x0400 /* reserved */
>>>>>>>>>> #define F2FS_FEATURE_SB_CHKSUM 0x0800
>>>>>>>>>>
>>>>>>>>>> +#define F2FS_ALL_FEATURES (F2FS_FEATURE_ENCRYPT | \
>>>>>>>>>> + F2FS_FEATURE_BLKZONED | \
>>>>>>>>>> + F2FS_FEATURE_ATOMIC_WRITE | \
>>>>>>>>>> + F2FS_FEATURE_EXTRA_ATTR | \
>>>>>>>>>> + F2FS_FEATURE_PRJQUOTA | \
>>>>>>>>>> + F2FS_FEATURE_INODE_CHKSUM | \
>>>>>>>>>> + F2FS_FEATURE_FLEXIBLE_INLINE_XATTR | \
>>>>>>>>>> + F2FS_FEATURE_QUOTA_INO | \
>>>>>>>>>> + F2FS_FEATURE_INODE_CRTIME | \
>>>>>>>>>> + F2FS_FEATURE_LOST_FOUND | \
>>>>>>>>>> + F2FS_FEATURE_VERITY | \
>>>>>>>>>> + F2FS_FEATURE_SB_CHKSUM)
>>>>>>>>>> +
>>>>>>>>>> #define __F2FS_HAS_FEATURE(raw_super, mask) \
>>>>>>>>>> ((raw_super->feature & cpu_to_le32(mask)) != 0)
>>>>>>>>>> #define F2FS_HAS_FEATURE(sbi, mask) __F2FS_HAS_FEATURE(sbi->raw_super, mask)
>>>>>>>>>> diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
>>>>>>>>>> index 4f8e9ab48b26..57f2fc6d14ba 100644
>>>>>>>>>> --- a/fs/f2fs/super.c
>>>>>>>>>> +++ b/fs/f2fs/super.c
>>>>>>>>>> @@ -2573,6 +2573,15 @@ static int sanity_check_raw_super(struct f2fs_sb_info *sbi,
>>>>>>>>>> return 1;
>>>>>>>>>> }
>>>>>>>>>>
>>>>>>>>>> + /* check whether kernel supports all features */
>>>>>>>>>> + if (le32_to_cpu(raw_super->feature) & (~F2FS_ALL_FEATURES)) {
>>>>>>>>>> + f2fs_msg(sb, KERN_INFO,
>>>>>>>>>> + "Unsupported feature:%u: supported:%u",
>>>>>>>>>> + le32_to_cpu(raw_super->feature),
>>>>>>>>>> + F2FS_ALL_FEATURES);
>>>>>>>>>> + return 1;
>>>>>>>>>> + }
>>>>>>>>>> +
>>>>>>>>>> /* check CP/SIT/NAT/SSA/MAIN_AREA area boundary */
>>>>>>>>>> if (sanity_check_area_boundary(sbi, bh))
>>>>>>>>>> return 1;
>>>>>>>>>> --
>>>>>>>>>> 2.18.0.rc1
>>>>>>> .
>>>>>>>
>>>>>>
>>>>>>
>>>>>> _______________________________________________
>>>>>> Linux-f2fs-devel mailing list
>>>>>> [email protected]
>>>>>> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
>>>>>> .
>>>>>>
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> Linux-f2fs-devel mailing list
>>>>> [email protected]
>>>>> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
>>>>> .
>>>>>
>>> .
>>>
> .
>