From: Andrew Donnellan <hidden> Date: 2019-02-07 05:35:16
Some older gccs (<GCC 7), when invoked with -fsanitize-coverage=trace-pc,
cause a spurious uninitialised variable warning in dt_cpu_ftrs.c:
arch/powerpc/kernel/dt_cpu_ftrs.c: In function ‘cpufeatures_process_feature’:
arch/powerpc/kernel/dt_cpu_ftrs.c:686:7: warning: ‘m’ may be used uninitialized in this function [-Wmaybe-uninitialized]
if (m->cpu_ftr_bit_mask)
An upcoming patch will enable support for kcov, which requires
-fsanitize-coverage=trace-pc.
Work around this by explicitly initialising m to NULL.
Signed-off-by: Andrew Donnellan <redacted>
---
arch/powerpc/kernel/dt_cpu_ftrs.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
@@ -5,6 +5,7 @@subdir-ccflags-y:=$(callcc-disable-warning,builtin-requires-header)GCOV_PROFILE:=n+KCOV_INSTRUMENT:=nUBSAN_SANITIZE:=n# Disable ftrace for the entire directory
On Thu, Feb 07, 2019 at 04:33:23PM +1100, Andrew Donnellan wrote:
Some older gccs (<GCC 7), when invoked with -fsanitize-coverage=trace-pc,
cause a spurious uninitialised variable warning in dt_cpu_ftrs.c:
arch/powerpc/kernel/dt_cpu_ftrs.c: In function ‘cpufeatures_process_feature’:
arch/powerpc/kernel/dt_cpu_ftrs.c:686:7: warning: ‘m’ may be used uninitialized in this function [-Wmaybe-uninitialized]
if (m->cpu_ftr_bit_mask)
It seems to me the warning is correct? If enable_unknown is false and no
cpu_feature is found, it will in
if (m->cpu_ftr_bit_mask)
cur_cpu_spec->cpu_features |= m->cpu_ftr_bit_mask;
enable random features (whatever was last in the table), or indeed access
via NULL if the table is length 0? So maybe this should be
if (known && m->cpu_ftr_bit_mask)
cur_cpu_spec->cpu_features |= m->cpu_ftr_bit_mask;
instead? (The code would be much clearer if all the known vs. !known
codepath was fully separated here).
Segher
From: Andrew Donnellan <hidden> Date: 2019-02-07 07:01:40
On 7/2/19 5:37 pm, Segher Boessenkool wrote:
On Thu, Feb 07, 2019 at 04:33:23PM +1100, Andrew Donnellan wrote:
quoted
Some older gccs (<GCC 7), when invoked with -fsanitize-coverage=trace-pc,
cause a spurious uninitialised variable warning in dt_cpu_ftrs.c:
arch/powerpc/kernel/dt_cpu_ftrs.c: In function ‘cpufeatures_process_feature’:
arch/powerpc/kernel/dt_cpu_ftrs.c:686:7: warning: ‘m’ may be used uninitialized in this function [-Wmaybe-uninitialized]
if (m->cpu_ftr_bit_mask)
It seems to me the warning is correct? If enable_unknown is false and no
cpu_feature is found, it will in
if (m->cpu_ftr_bit_mask)
cur_cpu_spec->cpu_features |= m->cpu_ftr_bit_mask;
enable random features (whatever was last in the table), or indeed access
via NULL if the table is length 0? So maybe this should be
if (known && m->cpu_ftr_bit_mask)
cur_cpu_spec->cpu_features |= m->cpu_ftr_bit_mask;
instead? (The code would be much clearer if all the known vs. !known
codepath was fully separated here).
The table is never length 0, it's a statically defined array.
Segher
--
Andrew Donnellan OzLabs, ADL Canberra
andrew.donnellan@au1.ibm.com IBM Australia Limited
On Thu, Feb 07, 2019 at 05:59:48PM +1100, Andrew Donnellan wrote:
On 7/2/19 5:37 pm, Segher Boessenkool wrote:
quoted
On Thu, Feb 07, 2019 at 04:33:23PM +1100, Andrew Donnellan wrote:
quoted
Some older gccs (<GCC 7), when invoked with -fsanitize-coverage=trace-pc,
cause a spurious uninitialised variable warning in dt_cpu_ftrs.c:
arch/powerpc/kernel/dt_cpu_ftrs.c: In function
‘cpufeatures_process_feature’:
arch/powerpc/kernel/dt_cpu_ftrs.c:686:7: warning: ‘m’ may be used
uninitialized in this function [-Wmaybe-uninitialized]
if (m->cpu_ftr_bit_mask)
It seems to me the warning is correct? If enable_unknown is false and no
cpu_feature is found, it will in
if (m->cpu_ftr_bit_mask)
cur_cpu_spec->cpu_features |= m->cpu_ftr_bit_mask;
enable random features (whatever was last in the table), or indeed access
via NULL if the table is length 0? So maybe this should be
if (known && m->cpu_ftr_bit_mask)
cur_cpu_spec->cpu_features |= m->cpu_ftr_bit_mask;
instead? (The code would be much clearer if all the known vs. !known
codepath was fully separated here).
The table is never length 0, it's a statically defined array.
Sure, and presumably that is why newer GCC doesn't warn. But what about
the other point? Is this code ever correct? Enabling random features
(in cur_cpu_spec->cpu_features) when the name isn't found seems wrong.
Segher
From: Andrew Donnellan <hidden> Date: 2019-02-08 00:37:11
(+ Nick)
On 7/2/19 6:49 pm, Segher Boessenkool wrote:
On Thu, Feb 07, 2019 at 05:59:48PM +1100, Andrew Donnellan wrote:
quoted
On 7/2/19 5:37 pm, Segher Boessenkool wrote:
quoted
On Thu, Feb 07, 2019 at 04:33:23PM +1100, Andrew Donnellan wrote:
quoted
Some older gccs (<GCC 7), when invoked with -fsanitize-coverage=trace-pc,
cause a spurious uninitialised variable warning in dt_cpu_ftrs.c:
arch/powerpc/kernel/dt_cpu_ftrs.c: In function
‘cpufeatures_process_feature’:
arch/powerpc/kernel/dt_cpu_ftrs.c:686:7: warning: ‘m’ may be used
uninitialized in this function [-Wmaybe-uninitialized]
if (m->cpu_ftr_bit_mask)
It seems to me the warning is correct? If enable_unknown is false and no
cpu_feature is found, it will in
if (m->cpu_ftr_bit_mask)
cur_cpu_spec->cpu_features |= m->cpu_ftr_bit_mask;
enable random features (whatever was last in the table), or indeed access
via NULL if the table is length 0? So maybe this should be
if (known && m->cpu_ftr_bit_mask)
cur_cpu_spec->cpu_features |= m->cpu_ftr_bit_mask;
instead? (The code would be much clearer if all the known vs. !known
codepath was fully separated here).
The table is never length 0, it's a statically defined array.
Sure, and presumably that is why newer GCC doesn't warn. But what about
the other point? Is this code ever correct? Enabling random features
(in cur_cpu_spec->cpu_features) when the name isn't found seems wrong.
Now that I'm replying without being 2 minutes before a meeting :)
The warning is still spurious, but the logic looks very suspicious.
I think your solution looks correct, though the whole function could be
cleaned up a bit.
I also notice that if enable_unknown == false, then I think an unknown
feature will still print "enabling" and return true, which seems wrong.
How does something like the following look, which I could send instead
and will probably solve the spurious warnings issues anyway?
diff --git a/arch/powerpc/kernel/dt_cpu_ftrs.c
b/arch/powerpc/kernel/dt_cpu_ftrs.c
index 2192b2114513..0f13048dc0dd 100644
From: Michael Ellerman <mpe@ellerman.id.au> Date: 2019-02-08 03:05:10
Andrew Donnellan [off-list ref] writes:
(+ Nick)
On 7/2/19 6:49 pm, Segher Boessenkool wrote:
quoted
On Thu, Feb 07, 2019 at 05:59:48PM +1100, Andrew Donnellan wrote:
quoted
On 7/2/19 5:37 pm, Segher Boessenkool wrote:
quoted
On Thu, Feb 07, 2019 at 04:33:23PM +1100, Andrew Donnellan wrote:
quoted
Some older gccs (<GCC 7), when invoked with -fsanitize-coverage=trace-pc,
cause a spurious uninitialised variable warning in dt_cpu_ftrs.c:
arch/powerpc/kernel/dt_cpu_ftrs.c: In function
‘cpufeatures_process_feature’:
arch/powerpc/kernel/dt_cpu_ftrs.c:686:7: warning: ‘m’ may be used
uninitialized in this function [-Wmaybe-uninitialized]
if (m->cpu_ftr_bit_mask)
It seems to me the warning is correct? If enable_unknown is false and no
cpu_feature is found, it will in
if (m->cpu_ftr_bit_mask)
cur_cpu_spec->cpu_features |= m->cpu_ftr_bit_mask;
enable random features (whatever was last in the table), or indeed access
via NULL if the table is length 0? So maybe this should be
if (known && m->cpu_ftr_bit_mask)
cur_cpu_spec->cpu_features |= m->cpu_ftr_bit_mask;
instead? (The code would be much clearer if all the known vs. !known
codepath was fully separated here).
The table is never length 0, it's a statically defined array.
Sure, and presumably that is why newer GCC doesn't warn. But what about
the other point? Is this code ever correct? Enabling random features
(in cur_cpu_spec->cpu_features) when the name isn't found seems wrong.
Now that I'm replying without being 2 minutes before a meeting :)
The warning is still spurious, but the logic looks very suspicious.
I think your solution looks correct, though the whole function could be
cleaned up a bit.
I also notice that if enable_unknown == false, then I think an unknown
feature will still print "enabling" and return true, which seems wrong.
How does something like the following look, which I could send instead
and will probably solve the spurious warnings issues anyway?
I'd prefer a minimal fix that we can backport. How about:
@@ -675,12 +675,10 @@ static bool __init cpufeatures_process_feature(struct dt_cpu_feature *f)}}-if(!known&&enable_unknown){-if(!feat_try_enable_unknown(f)){-pr_info("not enabling: %s (unknown and unsupported by kernel)\n",-f->name);-returnfalse;-}+if(!known&&(!enable_unknown||!feat_try_enable_unknown(f))){+pr_info("not enabling: %s (unknown and unsupported by kernel)\n",+f->name);+returnfalse;}if(m->cpu_ftr_bit_mask)
cur_cpu_spec->cpu_features |= m->cpu_ftr_bit_mask;
This still set the wrong mask here, which is the bug you're trying to fix.
It should only do this if "known", afaics.
Segher
@@ -675,12 +675,10 @@ static bool __init cpufeatures_process_feature(struct dt_cpu_feature *f)}}-if(!known&&enable_unknown){-if(!feat_try_enable_unknown(f)){-pr_info("not enabling: %s (unknown and unsupported by kernel)\n",-f->name);-returnfalse;-}+if(!known&&(!enable_unknown||!feat_try_enable_unknown(f))){+pr_info("not enabling: %s (unknown and unsupported by kernel)\n",+f->name);+returnfalse;}if(m->cpu_ftr_bit_mask)
cur_cpu_spec->cpu_features |= m->cpu_ftr_bit_mask;
This still set the wrong mask here, which is the bug you're trying to fix.
It should only do this if "known", afaics.
I've got a v2 ready to send which fixes both things.
Segher
--
Andrew Donnellan OzLabs, ADL Canberra
andrew.donnellan@au1.ibm.com IBM Australia Limited