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(-)
--
2.34.1
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.
Signed-off-by: Ryusuke Konishi <[email protected]>
Reported-by: kernel test robot <[email protected]>
Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
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(-)
diff --git a/fs/nilfs2/mdt.c b/fs/nilfs2/mdt.c
index 4f792a0ad0f0..323eb8442e0a 100644
--- a/fs/nilfs2/mdt.c
+++ b/fs/nilfs2/mdt.c
@@ -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;
diff --git a/include/trace/events/nilfs2.h b/include/trace/events/nilfs2.h
index 8efc6236f57c..84ee31fc04cc 100644
--- a/include/trace/events/nilfs2.h
+++ b/include/trace/events/nilfs2.h
@@ -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(
--
2.34.1
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.
Signed-off-by: Ryusuke Konishi <[email protected]>
Fixes: e339ad31f599 ("nilfs2: introduce secondary super block")
---
fs/nilfs2/the_nilfs.c | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/fs/nilfs2/the_nilfs.c b/fs/nilfs2/the_nilfs.c
index db322068678f..f41d7b6d432c 100644
--- a/fs/nilfs2/the_nilfs.c
+++ b/fs/nilfs2/the_nilfs.c
@@ -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;
}
--
2.34.1
On 4/30/24 10:00, Ryusuke Konishi wrote:
> trace_nilfs2_mdt_submit_block(inode, inode->i_ino, blkoff,
> - 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.
On Wed, May 1, 2024 at 11:42 PM Bart Van Assche wrote:
>
> On 4/30/24 10:00, Ryusuke Konishi wrote:
> > trace_nilfs2_mdt_submit_block(inode, inode->i_ino, blkoff,
> > - 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.
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
On Thu, May 2, 2024 at 12:30 AM Ryusuke Konishi wrote:
>
> On Wed, May 1, 2024 at 11:42 PM Bart Van Assche wrote:
> >
> > On 4/30/24 10:00, Ryusuke Konishi wrote:
> > > trace_nilfs2_mdt_submit_block(inode, inode->i_ino, blkoff,
> > > - 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.
>
> 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
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
On 5/2/24 12:01 PM, Ryusuke Konishi wrote:
> 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?
diff --git a/include/trace/events/nilfs2.h b/include/trace/events/nilfs2.h
index 8efc6236f57c..67fd2e002ca7 100644
--- a/include/trace/events/nilfs2.h
+++ b/include/trace/events/nilfs2.h
@@ -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 */
On Sun, May 5, 2024 at 9:47 PM Bart Van Assche wrote:
>
> On 5/2/24 12:01 PM, Ryusuke Konishi wrote:
> > 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?
>
> diff --git a/include/trace/events/nilfs2.h b/include/trace/events/nilfs2.h
> index 8efc6236f57c..67fd2e002ca7 100644
> --- a/include/trace/events/nilfs2.h
> +++ b/include/trace/events/nilfs2.h
> @@ -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
On 5/5/24 12:04 PM, Ryusuke Konishi wrote:
> 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?
diff --git a/include/trace/events/nilfs2.h b/include/trace/events/nilfs2.h
index 8efc6236f57c..b1a364a33a62 100644
--- a/include/trace/events/nilfs2.h
+++ b/include/trace/events/nilfs2.h
@@ -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.
On Tue, May 7, 2024 at 2:26 AM Bart Van Assche wrote:
>
> On 5/5/24 12:04 PM, Ryusuke Konishi wrote:
> > 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?
>
> diff --git a/include/trace/events/nilfs2.h b/include/trace/events/nilfs2.h
> index 8efc6236f57c..b1a364a33a62 100644
> --- a/include/trace/events/nilfs2.h
> +++ b/include/trace/events/nilfs2.h
> @@ -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.
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