Skip to content

Commit 3577dd3

Browse files
Anshuman Khandualwilldeacon
authored andcommitted
arm64/cpufeature: Add get_arm64_ftr_reg_nowarn()
There is no way to proceed when requested register could not be searched in arm64_ftr_reg[]. Requesting for a non present register would be an error as well. Hence lets just WARN_ON() when search fails in get_arm64_ftr_reg() rather than checking for return value and doing a BUG_ON() instead in some individual callers. But there are also caller instances that dont error out when register search fails. Add a new helper get_arm64_ftr_reg_nowarn() for such cases. Signed-off-by: Anshuman Khandual <[email protected]> Reviewed-by: Catalin Marinas <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Will Deacon <[email protected]> Cc: Suzuki K Poulose <[email protected]> Cc: Mark Brown <[email protected]> Cc: [email protected] Cc: [email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent 858b8a8 commit 3577dd3

File tree

1 file changed

+34
-10
lines changed

1 file changed

+34
-10
lines changed

arch/arm64/kernel/cpufeature.c

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -595,16 +595,16 @@ static int search_cmp_ftr_reg(const void *id, const void *regp)
595595
}
596596

597597
/*
598-
* get_arm64_ftr_reg - Lookup a feature register entry using its
599-
* sys_reg() encoding. With the array arm64_ftr_regs sorted in the
600-
* ascending order of sys_id , we use binary search to find a matching
598+
* get_arm64_ftr_reg_nowarn - Looks up a feature register entry using
599+
* its sys_reg() encoding. With the array arm64_ftr_regs sorted in the
600+
* ascending order of sys_id, we use binary search to find a matching
601601
* entry.
602602
*
603603
* returns - Upon success, matching ftr_reg entry for id.
604604
* - NULL on failure. It is upto the caller to decide
605605
* the impact of a failure.
606606
*/
607-
static struct arm64_ftr_reg *get_arm64_ftr_reg(u32 sys_id)
607+
static struct arm64_ftr_reg *get_arm64_ftr_reg_nowarn(u32 sys_id)
608608
{
609609
const struct __ftr_reg_entry *ret;
610610

@@ -618,6 +618,27 @@ static struct arm64_ftr_reg *get_arm64_ftr_reg(u32 sys_id)
618618
return NULL;
619619
}
620620

621+
/*
622+
* get_arm64_ftr_reg - Looks up a feature register entry using
623+
* its sys_reg() encoding. This calls get_arm64_ftr_reg_nowarn().
624+
*
625+
* returns - Upon success, matching ftr_reg entry for id.
626+
* - NULL on failure but with an WARN_ON().
627+
*/
628+
static struct arm64_ftr_reg *get_arm64_ftr_reg(u32 sys_id)
629+
{
630+
struct arm64_ftr_reg *reg;
631+
632+
reg = get_arm64_ftr_reg_nowarn(sys_id);
633+
634+
/*
635+
* Requesting a non-existent register search is an error. Warn
636+
* and let the caller handle it.
637+
*/
638+
WARN_ON(!reg);
639+
return reg;
640+
}
641+
621642
static u64 arm64_ftr_set_value(const struct arm64_ftr_bits *ftrp, s64 reg,
622643
s64 ftr_val)
623644
{
@@ -679,7 +700,8 @@ static void __init init_cpu_ftr_reg(u32 sys_reg, u64 new)
679700
const struct arm64_ftr_bits *ftrp;
680701
struct arm64_ftr_reg *reg = get_arm64_ftr_reg(sys_reg);
681702

682-
BUG_ON(!reg);
703+
if (!reg)
704+
return;
683705

684706
for (ftrp = reg->ftr_bits; ftrp->width; ftrp++) {
685707
u64 ftr_mask = arm64_ftr_mask(ftrp);
@@ -813,7 +835,9 @@ static int check_update_ftr_reg(u32 sys_id, int cpu, u64 val, u64 boot)
813835
{
814836
struct arm64_ftr_reg *regp = get_arm64_ftr_reg(sys_id);
815837

816-
BUG_ON(!regp);
838+
if (!regp)
839+
return 0;
840+
817841
update_cpu_ftr_reg(regp, val);
818842
if ((boot & regp->strict_mask) == (val & regp->strict_mask))
819843
return 0;
@@ -827,7 +851,7 @@ static void relax_cpu_ftr_reg(u32 sys_id, int field)
827851
const struct arm64_ftr_bits *ftrp;
828852
struct arm64_ftr_reg *regp = get_arm64_ftr_reg(sys_id);
829853

830-
if (WARN_ON(!regp))
854+
if (!regp)
831855
return;
832856

833857
for (ftrp = regp->ftr_bits; ftrp->width; ftrp++) {
@@ -1020,8 +1044,8 @@ u64 read_sanitised_ftr_reg(u32 id)
10201044
{
10211045
struct arm64_ftr_reg *regp = get_arm64_ftr_reg(id);
10221046

1023-
/* We shouldn't get a request for an unsupported register */
1024-
BUG_ON(!regp);
1047+
if (!regp)
1048+
return 0;
10251049
return regp->sys_val;
10261050
}
10271051

@@ -2626,7 +2650,7 @@ static int emulate_sys_reg(u32 id, u64 *valp)
26262650
if (sys_reg_CRm(id) == 0)
26272651
return emulate_id_reg(id, valp);
26282652

2629-
regp = get_arm64_ftr_reg(id);
2653+
regp = get_arm64_ftr_reg_nowarn(id);
26302654
if (regp)
26312655
*valp = arm64_ftr_reg_user_value(regp);
26322656
else

0 commit comments

Comments
 (0)