Skip to contentSkip to conversation

nvdimm: avoid bogus -Wmaybe-uninitialized warning

PATCH In review Arnd Bergmann 4 participants 6 messages Aug 1, 2017 – Aug 2, 2017 libnvdimm: non-volatile memory device

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvdimm: avoid bogus -Wmaybe-uninitialized warning

Removing the btt_rw_page/pmem_rw_page functions had a surprising side-effect of introducing a false-positive warning in another function, due to changed inlining decisions in gcc:

In file included from drivers/nvdimm/pmem.c:36:0:
drivers/nvdimm/pmem.c: In function 'pmem_make_request':
drivers/nvdimm/nd.h:407:2: error: 'start' may be used uninitialized in this function [-Werror=maybe-uninitialized] drivers/nvdimm/pmem.c:174:16: note: 'start' was declared here
In file included from drivers/nvdimm/btt.c:27:0:
drivers/nvdimm/btt.c: In function 'btt_make_request':
drivers/nvdimm/nd.h:407:2: error: 'start' may be used uninitialized in this function [-Werror=maybe-uninitialized] drivers/nvdimm/btt.c:1202:16: note: 'start' was declared here

The problem is that gcc fails to track the value of the 'do_acct' variable here and has to read it back from stack, but it does remember that 'start' may be uninitialized sometimes.

This shuts up the warning by making nd_iostat_start() always initialize the 'start' variable. In those cases that gcc successfully tracks the state of the variable, this will have no effect.

Fixes 503a5e89b1de ("drivers/nvdimm/btt.c: remove btt_rw_page()")
Fixes 58100d6e735e ("drivers/nvdimm/pmem.c: remove pmem_rw_page()")
---
 drivers/nvdimm/nd.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/nvdimm/nd.h +3 -1
index e1b5715bd91f..64f79a156456 100644
@@ -392,8 +392,10 @@ static inline bool nd_iostat_start(struct bio *bio, unsigned long *start)
 {
 	struct gendisk *disk = bio->bi_bdev->bd_disk;
 
-	if (!blk_queue_io_stat(disk->queue))
+	if (!blk_queue_io_stat(disk->queue)) {
+		*start = 0;
 		return false;
+	}
 
 	*start = jiffies;
 	generic_start_io_acct(bio_data_dir(bio),
Signature · 6 lines
2.9.0

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
Reviewed-by on v1 1/1
#1 lore raw
Quoted 17 lines · Arnd Bergmann

Removing the btt_rw_page/pmem_rw_page functions had a surprising side-effect of introducing a false-positive warning in another function, due to changed inlining decisions in gcc:

In file included from drivers/nvdimm/pmem.c:36:0:
drivers/nvdimm/pmem.c: In function 'pmem_make_request':
drivers/nvdimm/nd.h:407:2: error: 'start' may be used uninitialized in this function [-Werror=maybe-uninitialized] drivers/nvdimm/pmem.c:174:16: note: 'start' was declared here
In file included from drivers/nvdimm/btt.c:27:0:
drivers/nvdimm/btt.c: In function 'btt_make_request':
drivers/nvdimm/nd.h:407:2: error: 'start' may be used uninitialized in this function [-Werror=maybe-uninitialized] drivers/nvdimm/btt.c:1202:16: note: 'start' was declared here

The problem is that gcc fails to track the value of the 'do_acct' variable here and has to read it back from stack, but it does remember that 'start' may be uninitialized sometimes.

Quoted 7 lines

This shuts up the warning by making nd_iostat_start() always initialize the 'start' variable. In those cases that gcc successfully tracks the state of the variable, this will have no effect.

Fixes 503a5e89b1de ("drivers/nvdimm/btt.c: remove btt_rw_page()")
Fixes 58100d6e735e ("drivers/nvdimm/pmem.c: remove pmem_rw_page()")

This change looks fine:

I believe the patches removing the btt_rw_page() and btt_rw_page() are on hold until I can get some performance numbers to justify them.

Dan, do you want to take this as is, or do you want me to include it in my larger rw_page() series if/when that gets revived?
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

#2 lore raw
Quoted 28 lines · Ross Zwisler
Quoted 17 lines · Arnd Bergmann

Removing the btt_rw_page/pmem_rw_page functions had a surprising side-effect of introducing a false-positive warning in another function, due to changed inlining decisions in gcc:

In file included from drivers/nvdimm/pmem.c:36:0:
drivers/nvdimm/pmem.c: In function 'pmem_make_request':
drivers/nvdimm/nd.h:407:2: error: 'start' may be used uninitialized in this function [-Werror=maybe-uninitialized] drivers/nvdimm/pmem.c:174:16: note: 'start' was declared here
In file included from drivers/nvdimm/btt.c:27:0:
drivers/nvdimm/btt.c: In function 'btt_make_request':
drivers/nvdimm/nd.h:407:2: error: 'start' may be used uninitialized in this function [-Werror=maybe-uninitialized] drivers/nvdimm/btt.c:1202:16: note: 'start' was declared here

The problem is that gcc fails to track the value of the 'do_acct' variable here and has to read it back from stack, but it does remember that 'start' may be uninitialized sometimes.

Quoted 7 lines

This shuts up the warning by making nd_iostat_start() always initialize the 'start' variable. In those cases that gcc successfully tracks the state of the variable, this will have no effect.

Fixes 503a5e89b1de ("drivers/nvdimm/btt.c: remove btt_rw_page()")
Fixes 58100d6e735e ("drivers/nvdimm/pmem.c: remove pmem_rw_page()")

This change looks fine:

Quoted 7 lines

I believe the patches removing the btt_rw_page() and btt_rw_page() are on hold until I can get some performance numbers to justify them.

Dan, do you want to take this as is, or do you want me to include it in my larger rw_page() series if/when that gets revived?

I'd say include it with your set.
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

#3 lore raw
In reply to Arnd Bergmann
Quoted 27 lines · On Tue, 1 Aug 2017 13:48:48 +0200 Arnd Bergmann <[email protected]> wrote:

Removing the btt_rw_page/pmem_rw_page functions had a surprising side-effect of introducing a false-positive warning in another function, due to changed inlining decisions in gcc:

In file included from drivers/nvdimm/pmem.c:36:0:
drivers/nvdimm/pmem.c: In function 'pmem_make_request':
drivers/nvdimm/nd.h:407:2: error: 'start' may be used uninitialized in this function [-Werror=maybe-uninitialized] drivers/nvdimm/pmem.c:174:16: note: 'start' was declared here
In file included from drivers/nvdimm/btt.c:27:0:
drivers/nvdimm/btt.c: In function 'btt_make_request':
drivers/nvdimm/nd.h:407:2: error: 'start' may be used uninitialized in this function [-Werror=maybe-uninitialized] drivers/nvdimm/btt.c:1202:16: note: 'start' was declared here

The problem is that gcc fails to track the value of the 'do_acct' variable here and has to read it back from stack, but it does remember that 'start' may be uninitialized sometimes.

This shuts up the warning by making nd_iostat_start() always initialize the 'start' variable. In those cases that gcc successfully tracks the state of the variable, this will have no effect.

...

drivers/nvdimm/nd.h +0 -0
@@ -392,8 +392,10 @@ static inline bool nd_iostat_start(struct bio *bio, unsigned long *start)
 {

drivers/nvdimm/nd.h static inline bool nd_iostat_start(struct bio *bio, unsigned long *start) · line 401

Quoted 10 lines
drivers/nvdimm/nd.h +3 -1
 	struct gendisk *disk = bio->bi_bdev->bd_disk;
 
-	if (!blk_queue_io_stat(disk->queue))
+	if (!blk_queue_io_stat(disk->queue)) {
+		*start = 0;
 		return false;
+	}
 
 	*start = jiffies;
 	generic_start_io_acct(bio_data_dir(bio),

Well that's sad.

The future of btt-remove-btt_rw_page.patch and friends is shrouded in mystery, but if we proceed that way then yes, I guess we'll need to work around such gcc glitches.

But let's not leave apparently-unneeded code in place without telling people why it is in fact needed?

drivers/nvdimm/nd.h renamed from drivers/nvdimm/nd.h~nvdimm-avoid-bogus-wmaybe-uninitialized-warning-fix +1 -1
@@ -393,7 +393,7 @@ static inline bool nd_iostat_start(struc
 	struct gendisk *disk = bio->bi_bdev->bd_disk;
 
 	if (!blk_queue_io_stat(disk->queue)) {
-		*start = 0;
+		*start = 0;	/* Suppress bogus warning */
 		return false;
 	}
 

_

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

#4 lore raw
Quoted 42 lines · Andrew Morton
Quoted 27 lines · On Tue, 1 Aug 2017 13:48:48 +0200 Arnd Bergmann <[email protected]> wrote:

Removing the btt_rw_page/pmem_rw_page functions had a surprising side-effect of introducing a false-positive warning in another function, due to changed inlining decisions in gcc:

In file included from drivers/nvdimm/pmem.c:36:0:
drivers/nvdimm/pmem.c: In function 'pmem_make_request':
drivers/nvdimm/nd.h:407:2: error: 'start' may be used uninitialized in this function [-Werror=maybe-uninitialized] drivers/nvdimm/pmem.c:174:16: note: 'start' was declared here
In file included from drivers/nvdimm/btt.c:27:0:
drivers/nvdimm/btt.c: In function 'btt_make_request':
drivers/nvdimm/nd.h:407:2: error: 'start' may be used uninitialized in this function [-Werror=maybe-uninitialized] drivers/nvdimm/btt.c:1202:16: note: 'start' was declared here

The problem is that gcc fails to track the value of the 'do_acct' variable here and has to read it back from stack, but it does remember that 'start' may be uninitialized sometimes.

This shuts up the warning by making nd_iostat_start() always initialize the 'start' variable. In those cases that gcc successfully tracks the state of the variable, this will have no effect.

...

drivers/nvdimm/nd.h +0 -0
@@ -392,8 +392,10 @@ static inline bool nd_iostat_start(struct bio *bio, unsigned long *start)
 {

drivers/nvdimm/nd.h static inline bool nd_iostat_start(struct bio *bio, unsigned long *start) · line 401

Quoted 10 lines
drivers/nvdimm/nd.h +3 -1
 	struct gendisk *disk = bio->bi_bdev->bd_disk;
 
-	if (!blk_queue_io_stat(disk->queue))
+	if (!blk_queue_io_stat(disk->queue)) {
+		*start = 0;
 		return false;
+	}
 
 	*start = jiffies;
 	generic_start_io_acct(bio_data_dir(bio),

Well that's sad.

Quoted 6 lines

The future of btt-remove-btt_rw_page.patch and friends is shrouded in mystery, but if we proceed that way then yes, I guess we'll need to work around such gcc glitches.

But let's not leave apparently-unneeded code in place without telling people why it is in fact needed?

Maybe it's just cleaner to initialize 'start' in all the callers, so we don't have a mysterious line and have to remember why it's there / comment it?

I'll throw a patch like that in my series if/when I repost.
_______________________________________________
Linux-nvdimm mailing list [email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

#5 lore raw
Quoted 23 lines · Ross Zwisler
Quoted 22 lines · Andrew Morton
Quoted 4 lines · On Tue, 1 Aug 2017 13:48:48 +0200 Arnd Bergmann <[email protected]> wrote:
drivers/nvdimm/nd.h +0 -0
@@ -392,8 +392,10 @@ static inline bool nd_iostat_start(struct bio *bio, unsigned long *start)
 {

drivers/nvdimm/nd.h static inline bool nd_iostat_start(struct bio *bio, unsigned long *start) · line 401

Quoted 10 lines
drivers/nvdimm/nd.h +3 -1
    struct gendisk *disk = bio->bi_bdev->bd_disk;
 
-   if (!blk_queue_io_stat(disk->queue))
+   if (!blk_queue_io_stat(disk->queue)) {
+           *start = 0;
            return false;
+   }
 
    *start = jiffies;
    generic_start_io_acct(bio_data_dir(bio),

Well that's sad.

The future of btt-remove-btt_rw_page.patch and friends is shrouded in mystery, but if we proceed that way then yes, I guess we'll need to work around such gcc glitches.

Quoted 5 lines
Quoted 2 lines

But let's not leave apparently-unneeded code in place without telling people why it is in fact needed?

Maybe it's just cleaner to initialize 'start' in all the callers, so we don't have a mysterious line and have to remember why it's there / comment it?

I considered that but decided that would be worse, since it shuts up more potential warnings about actual uninitialized use of the variable, and is slightly harder for the compiler to optimize away. You also end up having to add a comment in multiple places. Note that Andrew already added a comment when he applied my patch to his mmotm tree.

Arnd
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm