]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
powerpc/64s: Fix logic when handling unknown CPU features
authorMichael Ellerman <mpe@ellerman.id.au>
Mon, 11 Feb 2019 00:20:01 +0000 (11:20 +1100)
committerKhalid Elmously <khalid.elmously@canonical.com>
Fri, 14 Feb 2020 05:29:37 +0000 (00:29 -0500)
BugLink: https://bugs.launchpad.net/bugs/1863019
[ Upstream commit 8cfaf106918a8c13abb24c641556172afbb9545c ]

In cpufeatures_process_feature(), if a provided CPU feature is unknown and
enable_unknown is false, we erroneously print that the feature is being
enabled and return true, even though no feature has been enabled, and
may also set feature bits based on the last entry in the match table.

Fix this so that we only set feature bits from the match table if we have
actually enabled a feature from that table, and when failing to enable an
unknown feature, always print the "not enabling" message and return false.

Coincidentally, some older gccs (<GCC 7), when invoked with
-fsanitize-coverage=trace-pc, cause a spurious uninitialised variable
warning in this function:

  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 this option.
This patch avoids the warning.

Fixes: 5a61ef74f269 ("powerpc/64s: Support new device tree binding for discovering CPU features")
Reported-by: Segher Boessenkool <segher@kernel.crashing.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
[ajd: add commit message]
Signed-off-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
arch/powerpc/kernel/dt_cpu_ftrs.c

index 9940436c40c1c7e8eef80b61885b17af0f0630a9..989a7cc73c2318a3ae8ffff90243d7260a5d0ac0 100644 (file)
@@ -706,8 +706,10 @@ static bool __init cpufeatures_process_feature(struct dt_cpu_feature *f)
                m = &dt_cpu_feature_match_table[i];
                if (!strcmp(f->name, m->name)) {
                        known = true;
-                       if (m->enable(f))
+                       if (m->enable(f)) {
+                               cur_cpu_spec->cpu_features |= m->cpu_ftr_bit_mask;
                                break;
+                       }
 
                        pr_info("not enabling: %s (disabled or unsupported by kernel)\n",
                                f->name);
@@ -715,17 +717,12 @@ 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);
-                       return false;
-               }
+       if (!known && (!enable_unknown || !feat_try_enable_unknown(f))) {
+               pr_info("not enabling: %s (unknown and unsupported by kernel)\n",
+                       f->name);
+               return false;
        }
 
-       if (m->cpu_ftr_bit_mask)
-               cur_cpu_spec->cpu_features |= m->cpu_ftr_bit_mask;
-
        if (known)
                pr_debug("enabling: %s\n", f->name);
        else