Skip to contentSkip to conversation

nilfs2: reduce build warnings with "make C=1"

PATCH In review Ryusuke Konishi 2 participants 10 messages Apr 30, 2024 – May 6, 2024

Subsystems (2)
lore
Share & tools
lore

Ryusuke Konishi

author maintainer
#0 lore raw

cover nilfs2: reduce build warnings with "make C=1"

Hi Andrew,

Please add these to the queue for the next merge window.

These two are cleanups that eliminate the warnings output by sparse (not including common one related to refcount_dec_and_lock). Neither is a bugfix.

Thanks,
Ryusuke Konishi

Ryusuke Konishi (2):
nilfs2: use integer type instead of enum req_op for event tracing
header
nilfs2: make superblock data array index computation sparse friendly

 fs/nilfs2/mdt.c               |  2 +-
 fs/nilfs2/the_nilfs.c         | 20 ++++++++++++++++++--
 include/trace/events/nilfs2.h |  4 ++--
 3 files changed, 21 insertions(+), 5 deletions(-)
Signature · 1 line
2.34.1
author maintainer
#1 lore raw

PATCH 1/2 nilfs2: use integer type instead of enum req_op for event tracing header

The sparse check with "make C=1" outputs warnings regarding references to the header file "include/trace/events/nilfs2.h" for event tracing:

fs/nilfs2/segment.c: note: in included file (through
include/trace/trace_events.h, include/trace/define_trace.h, include/trace/events/nilfs2.h):
./include/trace/events/nilfs2.h:191:1: warning: cast to restricted
blk_opf_t
./include/trace/events/nilfs2.h:191:1: warning: restricted blk_opf_t
degrades to integer
./include/trace/events/nilfs2.h:191:1: warning: restricted blk_opf_t
degrades to integer

Fix this issue by reverting the type of the parameter related to the bio operation mode in the event tracing definition from "enum req_op" to "int".

In order to prevent sparse warnings on the caller side (where trace_nilfs2_mdt_submit_block() is used), also add a typecast to an argument passed to the tracepoint.

Fixes ed4512590bd5 ("fs/nilfs2: Use the enum req_op and blk_opf_t types")
Cc Bart Van Assche <[email protected]>
Cc Jens Axboe <[email protected]>
---
 fs/nilfs2/mdt.c               | 2 +-
 include/trace/events/nilfs2.h | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
fs/nilfs2/mdt.c +1 -1
index 4f792a0ad0f0..323eb8442e0a 100644
@@ -152,7 +152,7 @@ nilfs_mdt_submit_block(struct inode *inode, unsigned long blkoff, blk_opf_t opf,
 	ret = 0;
 
 	trace_nilfs2_mdt_submit_block(inode, inode->i_ino, blkoff,
-				      opf & REQ_OP_MASK);
+				      (__force int)(opf & REQ_OP_MASK));
  out:
 	get_bh(bh);
 	*out_bh = bh;
include/trace/events/nilfs2.h +2 -2
index 8efc6236f57c..84ee31fc04cc 100644
@@ -192,7 +192,7 @@ TRACE_EVENT(nilfs2_mdt_submit_block,
 	    TP_PROTO(struct inode *inode,
 		     unsigned long ino,
 		     unsigned long blkoff,
-		     enum req_op mode),
+		     int mode),
 
 	    TP_ARGS(inode, ino, blkoff, mode),
 
@@ -200,7 +200,7 @@ TRACE_EVENT(nilfs2_mdt_submit_block,
 		    __field(struct inode *, inode)
 		    __field(unsigned long, ino)
 		    __field(unsigned long, blkoff)
-		    __field(enum req_op, mode)
+		    __field(int, mode)
 	    ),
 
 	    TP_fast_assign(
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH -mm 1/2] nilfs2: use integer type instead of enum req_op for event tracing header

fs/nilfs2/mdt.c nilfs_mdt_submit_block(struct inode *inode, unsigned long blkoff, blk_opf_t opf, · line 155

Quoted 3 lines · Ryusuke Konishi

trace_nilfs2_mdt_submit_block(inode, inode->i_ino, blkoff,

fs/nilfs2/mdt.c +1 -1
-				      opf & REQ_OP_MASK);
+				      (__force int)(opf & REQ_OP_MASK));

Please keep the enum req_op type instead of casting that type away with "__force int".

Thanks,

Bart.

author maintainer
#3 lore raw

Re: [PATCH -mm 1/2] nilfs2: use integer type instead of enum req_op for event tracing header

Quoted 6 lines · Bart Van Assche

fs/nilfs2/mdt.c nilfs_mdt_submit_block(struct inode *inode, unsigned long blkoff, blk_opf_t opf, · line 155

Quoted 3 lines · Ryusuke Konishi
      trace_nilfs2_mdt_submit_block(inode, inode->i_ino, blkoff,
fs/nilfs2/mdt.c +1 -1
-                                   opf & REQ_OP_MASK);
+                                   (__force int)(opf & REQ_OP_MASK));
Quoted 6 lines

Please keep the enum req_op type instead of casting that type away with "__force int".

Thanks,

Bart.

Hi Bart,

No, this type cast is necessary to prevent the following sparse warning:

CC [M] fs/nilfs2/mdt.o
CHECK fs/nilfs2/mdt.c
fs/nilfs2/mdt.c:155:43: warning: incorrect type in argument 4 (different base types)
fs/nilfs2/mdt.c:155:43: expected int mode
fs/nilfs2/mdt.c:155:43: got restricted blk_opf_t

What we're doing here is just changing the event tracing type back to int, and keeping blk_opf_t and enum req_op in the rest of the code.

I understand if you have enough reason to ignore the warnings, but Why do you have to keep enum req_op type instead of int for event tracing?

Regards,
Ryusuke Konishi

author maintainer
#4 lore raw

Re: [PATCH -mm 1/2] nilfs2: use integer type instead of enum req_op for event tracing header

Quoted 26 lines · Ryusuke Konishi
Quoted 6 lines · Bart Van Assche

fs/nilfs2/mdt.c nilfs_mdt_submit_block(struct inode *inode, unsigned long blkoff, blk_opf_t opf, · line 155

Quoted 3 lines · Ryusuke Konishi
      trace_nilfs2_mdt_submit_block(inode, inode->i_ino, blkoff,
fs/nilfs2/mdt.c +1 -1
-                                   opf & REQ_OP_MASK);
+                                   (__force int)(opf & REQ_OP_MASK));
Quoted 6 lines

Please keep the enum req_op type instead of casting that type away with "__force int".

Thanks,

Bart.

Hi Bart,

No, this type cast is necessary to prevent the following sparse warning:

CC [M] fs/nilfs2/mdt.o
CHECK fs/nilfs2/mdt.c
fs/nilfs2/mdt.c:155:43: warning: incorrect type in argument 4 (different base types)
fs/nilfs2/mdt.c:155:43: expected int mode
fs/nilfs2/mdt.c:155:43: got restricted blk_opf_t

Quoted 8 lines

What we're doing here is just changing the event tracing type back to int, and keeping blk_opf_t and enum req_op in the rest of the code.

I understand if you have enough reason to ignore the warnings, but Why do you have to keep enum req_op type instead of int for event tracing?

Regards,
Ryusuke Konishi

Hi Bart,

Sorry, I didn't realize you were digging into the issue and talking with the sparse and kbuild teams to resolve the issue.

Is there any hope for a solution?

If you haven't given up yet on solving the underlying problem, I would like to withdraw this patch.

Thanks,
Ryusuke Konishi

#5 lore raw

Re: [PATCH -mm 1/2] nilfs2: use integer type instead of enum req_op for event tracing header

Quoted 2 lines · Ryusuke Konishi

If you haven't given up yet on solving the underlying problem, I would like to withdraw this patch.

Has this untested change been considered?

include/trace/events/nilfs2.h +1 -1
index 8efc6236f57c..67fd2e002ca7 100644
@@ -214,7 +214,7 @@ TRACE_EVENT(nilfs2_mdt_submit_block,
 		      __entry->inode,
 		      __entry->ino,
 		      __entry->blkoff,
-		      __entry->mode)
+		      (__force u32)__entry->mode)
 );
 
 #endif /* _TRACE_NILFS2_H */
author maintainer
#6 lore raw

Re: [PATCH -mm 1/2] nilfs2: use integer type instead of enum req_op for event tracing header

Quoted 12 lines · Bart Van Assche
Quoted 2 lines · Ryusuke Konishi

If you haven't given up yet on solving the underlying problem, I would like to withdraw this patch.

Has this untested change been considered?

include/trace/events/nilfs2.h +0 -0
index 8efc6236f57c..67fd2e002ca7 100644

include/trace/events/nilfs2.h TRACE_EVENT(nilfs2_mdt_submit_block, · line 220

Quoted 8 lines
include/trace/events/nilfs2.h +1 -1
@@ -214,7 +214,7 @@ TRACE_EVENT(nilfs2_mdt_submit_block,
                      __entry->inode,
                      __entry->ino,
                      __entry->blkoff,
-                     __entry->mode)
+                     (__force u32)__entry->mode)
  );
 
  #endif /* _TRACE_NILFS2_H */

No, I didn't think of that. There was no warning in TP_printk() declaration of the nilfs2_mdt_submit_block trace point.

If you suggested this as an alternative idea, unfortunately the following warnings are still output:

CC [M] fs/nilfs2/segment.o
CHECK fs/nilfs2/segment.c
fs/nilfs2/segment.c: note: in included file (through include/trace/trace_events.h, include/trace/define_trace.h, include/trace/events/nilfs2.h):
./include/trace/events/nilfs2.h:191:1: warning: cast to restricted blk_opf_t ./include/trace/events/nilfs2.h:191:1: warning: restricted blk_opf_t degrades to integer
./include/trace/events/nilfs2.h:191:1: warning: restricted blk_opf_t degrades to integer

I also tried typecasting on the declaration header side of event tracing, but so far, the sparse warnings don't go away except for the patch I first proposed.

But, better suggestions or solutions to the underlying problem are welcome. (Again, should we put the patch on hold?)

Regards,
Ryusuke Konishi

#7 lore raw

Re: [PATCH -mm 1/2] nilfs2: use integer type instead of enum req_op for event tracing header

Quoted 3 lines · Ryusuke Konishi

I also tried typecasting on the declaration header side of event tracing, but so far, the sparse warnings don't go away except for the patch I first proposed.

How about this patch?

include/trace/events/nilfs2.h +5 -1
index 8efc6236f57c..b1a364a33a62 100644
@@ -200,7 +200,11 @@ TRACE_EVENT(nilfs2_mdt_submit_block,
 		    __field(struct inode *, inode)
 		    __field(unsigned long, ino)
 		    __field(unsigned long, blkoff)
-		    __field(enum req_op, mode)
+		    /*
+		     * Use field_struct to avoid is_signed_type() on the bitwise
+		     * type enum req_op.
+		     */
+		    __field_struct(enum req_op, mode)
 	    ),
 
 	    TP_fast_assign(

Thanks,

Bart.

author maintainer
#8 lore raw

Re: [PATCH -mm 1/2] nilfs2: use integer type instead of enum req_op for event tracing header

Quoted 26 lines · Bart Van Assche
Quoted 3 lines · Ryusuke Konishi

I also tried typecasting on the declaration header side of event tracing, but so far, the sparse warnings don't go away except for the patch I first proposed.

How about this patch?

include/trace/events/nilfs2.h +5 -1
index 8efc6236f57c..b1a364a33a62 100644
@@ -200,7 +200,11 @@ TRACE_EVENT(nilfs2_mdt_submit_block,
                    __field(struct inode *, inode)
                    __field(unsigned long, ino)
                    __field(unsigned long, blkoff)
-                   __field(enum req_op, mode)
+                   /*
+                    * Use field_struct to avoid is_signed_type() on the bitwise
+                    * type enum req_op.
+                    */
+                   __field_struct(enum req_op, mode)
            ),
 
            TP_fast_assign(
Quoted 3 lines

Thanks,

Bart.

Great! This patch removed the sparse warnings.

It passed multiple build methods and did not break either tracing or nilfs2 functionality in operational testing.

I never thought of using __field_struct for enum type, but looking at the definition it looks like it can be used to just avoid
is_signed_type() without any side effects. So, this patch looks
better than mine.

If you don't mind, could you complete this change as a patch by adding a commit message and related tags?

Thanks,
Ryusuke Konishi

author maintainer
#9 lore raw

PATCH 2/2 nilfs2: make superblock data array index computation sparse friendly

In reply to Ryusuke Konishi

Upon running sparse, "warning: dubious: x & !y" is output at an array index calculation within nilfs_load_super_block().

The calculation is not wrong, but to eliminate the sparse warning, replace it with an equivalent calculation.

Also, add a comment to make it easier to understand what the unintuitive array index calculation is doing and whether it's correct.

Fixes e339ad31f599 ("nilfs2: introduce secondary super block")
---
 fs/nilfs2/the_nilfs.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)
fs/nilfs2/the_nilfs.c +18 -2
index db322068678f..f41d7b6d432c 100644
@@ -592,7 +592,7 @@ static int nilfs_load_super_block(struct the_nilfs *nilfs,
 	struct nilfs_super_block **sbp = nilfs->ns_sbp;
 	struct buffer_head **sbh = nilfs->ns_sbh;
 	u64 sb2off, devsize = bdev_nr_bytes(nilfs->ns_bdev);
-	int valid[2], swp = 0;
+	int valid[2], swp = 0, older;
 
 	if (devsize < NILFS_SEG_MIN_BLOCKS * NILFS_MIN_BLOCK_SIZE + 4096) {
 		nilfs_err(sb, "device size too small");
@@ -648,9 +648,25 @@ static int nilfs_load_super_block(struct the_nilfs *nilfs,
 	if (swp)
 		nilfs_swap_super_block(nilfs);
 
+	/*
+	 * Calculate the array index of the older superblock data.
+	 * If one has been dropped, set index 0 pointing to the remaining one,
+	 * otherwise set index 1 pointing to the old one (including if both
+	 * are the same).
+	 *
+	 *  Divided case             valid[0]  valid[1]  swp  ->  older
+	 *  -------------------------------------------------------------
+	 *  Both SBs are invalid        0         0       N/A (Error)
+	 *  SB1 is invalid              0         1       1         0
+	 *  SB2 is invalid              1         0       0         0
+	 *  SB2 is newer                1         1       1         0
+	 *  SB2 is older or the same    1         1       0         1
+	 */
+	older = valid[1] ^ swp;
+
 	nilfs->ns_sbwcount = 0;
 	nilfs->ns_sbwtime = le64_to_cpu(sbp[0]->s_wtime);
-	nilfs->ns_prot_seq = le64_to_cpu(sbp[valid[1] & !swp]->s_last_seq);
+	nilfs->ns_prot_seq = le64_to_cpu(sbp[older]->s_last_seq);
 	*sbpp = sbp[0];
 	return 0;
 }
Signature · 1 line
2.34.1