All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] f2fs: UBSAN: set boolean value iostat_enable correctly
@ 2019-01-14 14:05 Sheng Yong
  2019-01-14 14:05 ` [PATCH 2/2] f2fs: add brackets for macros Sheng Yong
  2019-01-15  1:56 ` [PATCH 1/2] f2fs: UBSAN: set boolean value iostat_enable correctly Chao Yu
  0 siblings, 2 replies; 5+ messages in thread
From: Sheng Yong @ 2019-01-14 14:05 UTC (permalink / raw)
  To: jaegeuk, yuchao0; +Cc: linux-f2fs-devel

When setting /sys/fs/f2fs/<DEV>/iostat_enable with non-boolean value,
UBSAN reports the following warning.

[ 7562.295484] ================================================================================
[ 7562.296531] UBSAN: Undefined behaviour in fs/f2fs/f2fs.h:2776:10
[ 7562.297651] load of value 64 is not a valid value for type '_Bool'
[ 7562.298642] CPU: 1 PID: 7487 Comm: dd Not tainted 4.20.0-rc4+ #79
[ 7562.298653] Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006
[ 7562.298662] Call Trace:
[ 7562.298760]  dump_stack+0x46/0x5b
[ 7562.298811]  ubsan_epilogue+0x9/0x40
[ 7562.298830]  __ubsan_handle_load_invalid_value+0x72/0x90
[ 7562.298863]  f2fs_file_write_iter+0x29f/0x3f0
[ 7562.298905]  __vfs_write+0x115/0x160
[ 7562.298922]  vfs_write+0xa7/0x190
[ 7562.298934]  ksys_write+0x50/0xc0
[ 7562.298973]  do_syscall_64+0x4a/0xe0
[ 7562.298992]  entry_SYSCALL_64_after_hwframe+0x44/0xa9
[ 7562.299001] RIP: 0033:0x7fa45ec19c00
[ 7562.299004] Code: 73 01 c3 48 8b 0d 88 92 2c 00 f7 d8 64 89 01 48 83 c8 ff c3 66 0f 1f 44 00 00 83 3d dd eb 2c 00 00 75 10 b8 01 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 31 c3 48 83 ec 08 e8 ce 8f 01 00 48 89 04 24
[ 7562.299044] RSP: 002b:00007ffca52b49e8 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
[ 7562.299052] RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007fa45ec19c00
[ 7562.299059] RDX: 0000000000000400 RSI: 000000000093f000 RDI: 0000000000000001
[ 7562.299065] RBP: 000000000093f000 R08: 0000000000000004 R09: 0000000000000000
[ 7562.299071] R10: 00007ffca52b47b0 R11: 0000000000000246 R12: 0000000000000400
[ 7562.299077] R13: 000000000093f000 R14: 000000000093f400 R15: 0000000000000000
[ 7562.299091] ================================================================================

So, if iostat_enable is enabled, set its value as `true'.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
---
 fs/f2fs/sysfs.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c
index 0575edbe3ed6..b192627742a9 100644
--- a/fs/f2fs/sysfs.c
+++ b/fs/f2fs/sysfs.c
@@ -278,10 +278,17 @@ static ssize_t __sbi_store(struct f2fs_attr *a,
 		return count;
 	}
 
-	*ui = t;
 
-	if (!strcmp(a->attr.name, "iostat_enable") && *ui == 0)
-		f2fs_reset_iostat(sbi);
+	if (!strcmp(a->attr.name, "iostat_enable")) {
+		if (t == 0)
+			f2fs_reset_iostat(sbi);
+		else
+			sbi->iostat_enable = true;
+		return count;
+	}
+
+	*ui = (unsigned int)t;
+
 	return count;
 }
 
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] f2fs: add brackets for macros
  2019-01-14 14:05 [PATCH 1/2] f2fs: UBSAN: set boolean value iostat_enable correctly Sheng Yong
@ 2019-01-14 14:05 ` Sheng Yong
  2019-01-15  1:56   ` Chao Yu
       [not found]   ` <CGME20190115015747epcas1p33dc7f43481d4d12b6103874d185466d1@epcms2p1>
  2019-01-15  1:56 ` [PATCH 1/2] f2fs: UBSAN: set boolean value iostat_enable correctly Chao Yu
  1 sibling, 2 replies; 5+ messages in thread
From: Sheng Yong @ 2019-01-14 14:05 UTC (permalink / raw)
  To: jaegeuk, yuchao0; +Cc: linux-f2fs-devel

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
---
 fs/f2fs/f2fs.h | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index eeede26339a8..70eb7b085b2e 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -254,7 +254,7 @@ struct discard_entry {
 /* max discard pend list number */
 #define MAX_PLIST_NUM		512
 #define plist_idx(blk_num)	((blk_num) >= MAX_PLIST_NUM ?		\
-					(MAX_PLIST_NUM - 1) : (blk_num - 1))
+					(MAX_PLIST_NUM - 1) : ((blk_num) - 1))
 
 enum {
 	D_PREP,			/* initial */
@@ -2764,9 +2764,9 @@ static inline int get_inline_xattr_addrs(struct inode *inode)
 
 #define F2FS_OLD_ATTRIBUTE_SIZE	(offsetof(struct f2fs_inode, i_addr))
 #define F2FS_FITS_IN_INODE(f2fs_inode, extra_isize, field)		\
-		((offsetof(typeof(*f2fs_inode), field) +	\
+		((offsetof(typeof(*(f2fs_inode)), field) +	\
 		sizeof((f2fs_inode)->field))			\
-		<= (F2FS_OLD_ATTRIBUTE_SIZE + extra_isize))	\
+		<= (F2FS_OLD_ATTRIBUTE_SIZE + (extra_isize)))	\
 
 static inline void f2fs_reset_iostat(struct f2fs_sb_info *sbi)
 {
@@ -2795,8 +2795,8 @@ static inline void f2fs_update_iostat(struct f2fs_sb_info *sbi,
 
 #define __is_large_section(sbi)		((sbi)->segs_per_sec > 1)
 
-#define __is_meta_io(fio) (PAGE_TYPE_OF_BIO(fio->type) == META &&	\
-				(!is_read_io(fio->op) || fio->is_meta))
+#define __is_meta_io(fio) (PAGE_TYPE_OF_BIO((fio)->type) == META &&	\
+				(!is_read_io((fio)->op) || (fio)->is_meta))
 
 bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi,
 					block_t blkaddr, int type);
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] f2fs: UBSAN: set boolean value iostat_enable correctly
  2019-01-14 14:05 [PATCH 1/2] f2fs: UBSAN: set boolean value iostat_enable correctly Sheng Yong
  2019-01-14 14:05 ` [PATCH 2/2] f2fs: add brackets for macros Sheng Yong
@ 2019-01-15  1:56 ` Chao Yu
  1 sibling, 0 replies; 5+ messages in thread
From: Chao Yu @ 2019-01-15  1:56 UTC (permalink / raw)
  To: Sheng Yong, jaegeuk; +Cc: linux-f2fs-devel

On 2019/1/14 22:05, Sheng Yong wrote:
> When setting /sys/fs/f2fs/<DEV>/iostat_enable with non-boolean value,
> UBSAN reports the following warning.
> 
> [ 7562.295484] ================================================================================
> [ 7562.296531] UBSAN: Undefined behaviour in fs/f2fs/f2fs.h:2776:10
> [ 7562.297651] load of value 64 is not a valid value for type '_Bool'
> [ 7562.298642] CPU: 1 PID: 7487 Comm: dd Not tainted 4.20.0-rc4+ #79
> [ 7562.298653] Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006
> [ 7562.298662] Call Trace:
> [ 7562.298760]  dump_stack+0x46/0x5b
> [ 7562.298811]  ubsan_epilogue+0x9/0x40
> [ 7562.298830]  __ubsan_handle_load_invalid_value+0x72/0x90
> [ 7562.298863]  f2fs_file_write_iter+0x29f/0x3f0
> [ 7562.298905]  __vfs_write+0x115/0x160
> [ 7562.298922]  vfs_write+0xa7/0x190
> [ 7562.298934]  ksys_write+0x50/0xc0
> [ 7562.298973]  do_syscall_64+0x4a/0xe0
> [ 7562.298992]  entry_SYSCALL_64_after_hwframe+0x44/0xa9
> [ 7562.299001] RIP: 0033:0x7fa45ec19c00
> [ 7562.299004] Code: 73 01 c3 48 8b 0d 88 92 2c 00 f7 d8 64 89 01 48 83 c8 ff c3 66 0f 1f 44 00 00 83 3d dd eb 2c 00 00 75 10 b8 01 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 31 c3 48 83 ec 08 e8 ce 8f 01 00 48 89 04 24
> [ 7562.299044] RSP: 002b:00007ffca52b49e8 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
> [ 7562.299052] RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007fa45ec19c00
> [ 7562.299059] RDX: 0000000000000400 RSI: 000000000093f000 RDI: 0000000000000001
> [ 7562.299065] RBP: 000000000093f000 R08: 0000000000000004 R09: 0000000000000000
> [ 7562.299071] R10: 00007ffca52b47b0 R11: 0000000000000246 R12: 0000000000000400
> [ 7562.299077] R13: 000000000093f000 R14: 000000000093f400 R15: 0000000000000000
> [ 7562.299091] ================================================================================
> 
> So, if iostat_enable is enabled, set its value as `true'.
> 
> Signed-off-by: Sheng Yong <shengyong1@huawei.com>
> ---
>  fs/f2fs/sysfs.c | 13 ++++++++++---
>  1 file changed, 10 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c
> index 0575edbe3ed6..b192627742a9 100644
> --- a/fs/f2fs/sysfs.c
> +++ b/fs/f2fs/sysfs.c
> @@ -278,10 +278,17 @@ static ssize_t __sbi_store(struct f2fs_attr *a,
>  		return count;
>  	}
>  
> -	*ui = t;
>  
> -	if (!strcmp(a->attr.name, "iostat_enable") && *ui == 0)
> -		f2fs_reset_iostat(sbi);
> +	if (!strcmp(a->attr.name, "iostat_enable")) {

		bool enable = !!*ui;

		if (!enable)
			f2fs_reset_iostat(sbi);
		sbi->iostat_enable = enable;

		return count;

> +		if (t == 0)
> +			f2fs_reset_iostat(sbi);
> +		else
> +			sbi->iostat_enable = true;
> +		return count;
> +	}
> +
> +	*ui = (unsigned int)t;
> +
>  	return count;
>  }
>  
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] f2fs: add brackets for macros
  2019-01-14 14:05 ` [PATCH 2/2] f2fs: add brackets for macros Sheng Yong
@ 2019-01-15  1:56   ` Chao Yu
       [not found]   ` <CGME20190115015747epcas1p33dc7f43481d4d12b6103874d185466d1@epcms2p1>
  1 sibling, 0 replies; 5+ messages in thread
From: Chao Yu @ 2019-01-15  1:56 UTC (permalink / raw)
  To: Sheng Yong, jaegeuk; +Cc: linux-f2fs-devel

On 2019/1/14 22:05, Sheng Yong wrote:
> Signed-off-by: Sheng Yong <shengyong1@huawei.com>

Reviewed-by: Chao Yu <yuchao0@huawei.com>

Thanks,

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: (2)  [PATCH 2/2] f2fs: add brackets for macros
       [not found]   ` <CGME20190115015747epcas1p33dc7f43481d4d12b6103874d185466d1@epcms2p1>
@ 2019-01-15  2:26     ` Chul Lee
  0 siblings, 0 replies; 5+ messages in thread
From: Chul Lee @ 2019-01-15  2:26 UTC (permalink / raw)
  To: jaegeuk; +Cc: linux-f2fs-devel

 
 
--------- Original Message ---------
Sender : Chao Yu <yuchao0@huawei.com>
Date   : 2019-01-15 10:57 (GMT+9)
Title  : Re: [f2fs-dev] [PATCH 2/2] f2fs: add brackets for macros
To : Sheng Yong<shengyong1@huawei.com>, jaegeuk@kernel.org
CC : linux-f2fs-devel@lists.sourceforge.net
 
On 2019/1/14 22:05, Sheng Yong wrote:
> Signed-off-by: Sheng Yong <shengyong1@huawei.com>
 
Reviewed-by: Chao Yu <yuchao0@huawei.com>
 
Thanks,
 
 
 
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
 


_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-01-15  2:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-14 14:05 [PATCH 1/2] f2fs: UBSAN: set boolean value iostat_enable correctly Sheng Yong
2019-01-14 14:05 ` [PATCH 2/2] f2fs: add brackets for macros Sheng Yong
2019-01-15  1:56   ` Chao Yu
     [not found]   ` <CGME20190115015747epcas1p33dc7f43481d4d12b6103874d185466d1@epcms2p1>
2019-01-15  2:26     ` (2) " Chul Lee
2019-01-15  1:56 ` [PATCH 1/2] f2fs: UBSAN: set boolean value iostat_enable correctly Chao Yu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.