Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp5329516ybv; Tue, 11 Feb 2020 13:38:00 -0800 (PST) X-Google-Smtp-Source: APXvYqwBInh2e8pvEt7agh8ZmM0MoWC81Nqg3a24hxcJpINiDvOUqr6cBhWC9ZJ0alltkJmpeSZl X-Received: by 2002:a05:6808:1:: with SMTP id u1mr4308014oic.74.1581457080503; Tue, 11 Feb 2020 13:38:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581457080; cv=none; d=google.com; s=arc-20160816; b=bk24tdilbU/GNoWn3BEWCiUxYR51vq4L+l8S/Q9ZSOVYo336WmYQvQOtF0wYgDlRiI XrbVJPCmHM2wTR+sgIcTQT/2PB2Jzfx0K63Lw2oh0F28vG0qAvQphxFiM3+OAmzH6ZIG eVWADIMBwiPu6SoHkCtITtAogz9+ztEie7U1OIQKFwkyEYk1IN2VcefP8b3xw1HyUBiF Wogs+Ne5pY0ce6xXXcoY+2dYbmOPd6/r2F8Gk5Q6lEhhkpiqLlEluKxIJgeb2BH8DHR7 AGr1TCt10V+dCGuoo+TLMKPep7N5ZP58av91NdTTyXWYVtHNJQJ9fneo3gGtqabEvehB UVLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=4+rPRab7ju97Zu6/C77NmwBo8nrHbqFsQ6uxAcZjgDw=; b=A/cCL9qaPwJJz6Dlx740523C3kDWV0yYd5AmL2ni2L7z9S6F2/k078L8+QPRTZTsp+ 9kChdNwVeChf6TBJEVcxwG1CJ9AJlb8QGyofuamk6YQ7nt+gZzfXCYOgcHKbJh70dbYd pviMZT0SS9qj/lP8dsDUMQ0k2grIAeAkgjPOR9vot6GG/Ve1RT40JU3uC1/dNz1XW2Cn aBbIAlPOkZeYK0cJxRsosiTjh7o7VjlHuZ69ILAji1WnJ32UpZzA9RU2+vdBSDqV9V+d YLMGPUDEz/h+vlW4g6ZNfadfP3FbnLW530bxzkyXoSIry5qdI5akq0jPZyhUhlAP8JNO kIeA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 22si2075617oin.34.2020.02.11.13.37.48; Tue, 11 Feb 2020 13:38:00 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731530AbgBKSqr (ORCPT + 99 others); Tue, 11 Feb 2020 13:46:47 -0500 Received: from foss.arm.com ([217.140.110.172]:52450 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727958AbgBKSqq (ORCPT ); Tue, 11 Feb 2020 13:46:46 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 42FE81FB; Tue, 11 Feb 2020 10:46:46 -0800 (PST) Received: from e108754-lin.cambridge.arm.com (e108754-lin.cambridge.arm.com [10.1.198.52]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 0C5A23F68F; Tue, 11 Feb 2020 10:46:43 -0800 (PST) From: Ionela Voinescu To: catalin.marinas@arm.com, will@kernel.org, mark.rutland@arm.com, maz@kernel.org, suzuki.poulose@arm.com, sudeep.holla@arm.com, lukasz.luba@arm.com, valentin.schneider@arm.com, rjw@rjwysocki.net, ionela.voinescu@arm.com Cc: peterz@infradead.org, mingo@redhat.com, vincent.guittot@linaro.org, viresh.kumar@linaro.org, linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Subject: [PATCH v3 7/7] clocksource/drivers/arm_arch_timer: validate arch_timer_rate Date: Tue, 11 Feb 2020 18:45:42 +0000 Message-Id: <20200211184542.29585-8-ionela.voinescu@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200211184542.29585-1-ionela.voinescu@arm.com> References: <20200211184542.29585-1-ionela.voinescu@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Valentin Schneider Using an arch timer with a frequency of less than 1MHz can result in an incorrect functionality of the system which assumes a reasonable rate. One example is the use of activity monitors for frequency invariance which uses the rate of the arch timer as the known rate of the constant cycle counter in computing its ratio compared to the maximum frequency of a CPU. For arch timer frequencies less than 1MHz this ratio could end up being 0 which is an invalid value for its use. Therefore, warn if the arch timer rate is below 1MHz which contravenes the recommended architecture interval of 1 to 50MHz. Signed-off-by: Ionela Voinescu Cc: Mark Rutland Cc: Marc Zyngier --- drivers/clocksource/arm_arch_timer.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c index 9a5464c625b4..4faa930eabf8 100644 --- a/drivers/clocksource/arm_arch_timer.c +++ b/drivers/clocksource/arm_arch_timer.c @@ -885,6 +885,17 @@ static int arch_timer_starting_cpu(unsigned int cpu) return 0; } +static int validate_timer_rate(void) +{ + if (!arch_timer_rate) + return -EINVAL; + + /* Arch timer frequency < 1MHz can cause trouble */ + WARN_ON(arch_timer_rate < 1000000); + + return 0; +} + /* * For historical reasons, when probing with DT we use whichever (non-zero) * 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) arch_timer_rate = rate; /* Check the timer frequency. */ - if (arch_timer_rate == 0) + if (validate_timer_rate()) pr_warn("frequency not available\n"); } @@ -1594,9 +1605,10 @@ static int __init arch_timer_acpi_init(struct acpi_table_header *table) * CNTFRQ value. This *must* be correct. */ arch_timer_rate = arch_timer_get_cntfrq(); - if (!arch_timer_rate) { + ret = validate_timer_rate(); + if (ret) { pr_err(FW_BUG "frequency not available.\n"); - return -EINVAL; + return ret; } arch_timer_uses_ppi = arch_timer_select_ppi(); -- 2.17.1