Skip to content

Commit c265861

Browse files
ionela-voinescuctmarinas
authored andcommitted
clocksource/drivers/arm_arch_timer: validate arch_timer_rate
Using an arch timer with a frequency of less than 1MHz can potentially result in incorrect functionality in systems that assume a reasonable rate of the arch timer of 1 to 50MHz, described as typical in the architecture specification. Therefore, warn if the arch timer rate is below 1MHz, which is considered atypical and worth emphasizing. Suggested-by: Valentin Schneider <[email protected]> Signed-off-by: Ionela Voinescu <[email protected]> Acked-by: Marc Zyngier <[email protected]> Cc: Marc Zyngier <[email protected]> Cc: Mark Rutland <[email protected]> Signed-off-by: Catalin Marinas <[email protected]>
1 parent cd0ed03 commit c265861

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

drivers/clocksource/arm_arch_timer.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,17 @@ static int arch_timer_starting_cpu(unsigned int cpu)
885885
return 0;
886886
}
887887

888+
static int validate_timer_rate(void)
889+
{
890+
if (!arch_timer_rate)
891+
return -EINVAL;
892+
893+
/* Arch timer frequency < 1MHz can cause trouble */
894+
WARN_ON(arch_timer_rate < 1000000);
895+
896+
return 0;
897+
}
898+
888899
/*
889900
* For historical reasons, when probing with DT we use whichever (non-zero)
890901
* rate was probed first, and don't verify that others match. If the first node
@@ -900,7 +911,7 @@ static void arch_timer_of_configure_rate(u32 rate, struct device_node *np)
900911
arch_timer_rate = rate;
901912

902913
/* Check the timer frequency. */
903-
if (arch_timer_rate == 0)
914+
if (validate_timer_rate())
904915
pr_warn("frequency not available\n");
905916
}
906917

@@ -1594,9 +1605,10 @@ static int __init arch_timer_acpi_init(struct acpi_table_header *table)
15941605
* CNTFRQ value. This *must* be correct.
15951606
*/
15961607
arch_timer_rate = arch_timer_get_cntfrq();
1597-
if (!arch_timer_rate) {
1608+
ret = validate_timer_rate();
1609+
if (ret) {
15981610
pr_err(FW_BUG "frequency not available.\n");
1599-
return -EINVAL;
1611+
return ret;
16001612
}
16011613

16021614
arch_timer_uses_ppi = arch_timer_select_ppi();

0 commit comments

Comments
 (0)