Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1890803ybv; Fri, 14 Feb 2020 07:47:04 -0800 (PST) X-Google-Smtp-Source: APXvYqxeIfM1tyWH0zH070nshdrqFEdZ44QebL/qQ8cdxSydgOvt1BYCANwmKCAECob9jn3Mj9VI X-Received: by 2002:a05:6808:315:: with SMTP id i21mr2202317oie.139.1581695224375; Fri, 14 Feb 2020 07:47:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581695224; cv=none; d=google.com; s=arc-20160816; b=fL2LqFqSgSmgWUeVl7uCiUxrVqm+QbLpTVFUH9KcmO/DkHjJJg/FbWedMGtbdRhWmy cjJdZ5AShuGguBcjF6274wqI6LLhj9YYg9KqdObsrx7iro7hamwspmFPKAXuutePen40 ZvnXTce70CEEHPaqqAEidjoxRZlgO6YtSYVwZPoJklHE5u8SVLCBj3smnSwXXKSguJud rJIhGPJdJY4V55vRx1p3xj+0LPw+7B3tTlUIz0wzaYov/M8o0oHNvApawv2wA2rn5+jn dfZGmZEWDfgn4e8UChQlhWV6hnMb8JZdyYUdAwmWm+7xQUToOdrbBruN0X/xMFIpuoG5 TqxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=SuJmaZkXTlzTGgsMHD4LO4LQ/jYmj3/zgJksJ3iRMC8=; b=enFCovb9n8sLr89oWueog5YtXK4gdb/OxGxyPqqfbJqNzcSUXaDnFX6wRq/ZHxJ003 GP3ZsRgSW+cn/KVCrmRtHZaBJ4hoVJOB9n7mkiu2/2WH8wcjNoqDtiSoXx6Eb89lwrvf PbHjLAm9LZjTFBM97UJgh0iMJd8NiJ3or7TZHBfudvm79lgGem+Qq7+H7wrLXd2P9chS bLvPP54VJxWwRbnCsNLnhH0c5ZMCzrS7Ixqsu7NZg812NDB/FLa8JY4UltS0dOt7CGCx 8KmwV9wsnDR/lp8uigEC5jqa88/ZEiV4cXg/y9dJ0FMv6HtU3mb1XKYPw49XZHMj6lnE 5hOw== 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 n7si2889458oie.95.2020.02.14.07.46.52; Fri, 14 Feb 2020 07:47:04 -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 S1729655AbgBNPp2 (ORCPT + 99 others); Fri, 14 Feb 2020 10:45:28 -0500 Received: from foss.arm.com ([217.140.110.172]:35094 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729627AbgBNPp1 (ORCPT ); Fri, 14 Feb 2020 10:45:27 -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 CA4AC328; Fri, 14 Feb 2020 07:45:26 -0800 (PST) Received: from localhost (e108754-lin.cambridge.arm.com [10.1.198.52]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 6B5D83F68E; Fri, 14 Feb 2020 07:45:26 -0800 (PST) Date: Fri, 14 Feb 2020 15:45:25 +0000 From: Ionela Voinescu To: Thomas Gleixner Cc: 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, 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: Re: [PATCH v3 7/7] clocksource/drivers/arm_arch_timer: validate arch_timer_rate Message-ID: <20200214154525.GA21875@arm.com> References: <20200211184542.29585-1-ionela.voinescu@arm.com> <20200211184542.29585-8-ionela.voinescu@arm.com> <87mu9mgg41.fsf@nanos.tec.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <87mu9mgg41.fsf@nanos.tec.linutronix.de> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Thomas, On Friday 14 Feb 2020 at 01:35:58 (+0100), Thomas Gleixner wrote: > Ionela Voinescu writes: > > > 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 > > So this patch is from Valentin. Where is his Signed-off-by? > Yes, sorry about this. This was based on a diff that Valentin provided in v2. I'll change the author as agreed at: https://lore.kernel.org/lkml/20200212103249.GA19041@arm.com/ > > > > +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); > > This does not make sense to me. If the rate is out of bounds then why > warn an just continue instead of making it fail? > Because it's not a hard restriction, it's just atypical for the rate to be below 1Mhz. The spec only mentions a typical range of 1 to 50MHz and the warning is only here to flag a potentially problematic rate, below what is assumed typical in the spec. In [1], where I'm actually relying on arch_timer_rate being higher than than 1/SCHED_CAPACITY_SCALEĀ² of the maximum frequency, I am making it fail, as, for that scenario, it is a hard restriction. + * We use a factor of 2 * SCHED_CAPACITY_SHIFT -> SCHED_CAPACITY_SCALEĀ² + * in order to ensure a good resolution for arch_max_freq_scale for + * very low arch timer frequencies (up to the KHz range which should be + * unlikely). + */ + ratio = (u64)arch_timer_get_rate() << (2 * SCHED_CAPACITY_SHIFT); + ratio = div64_u64(ratio, max_freq_hz); + if (!ratio) { + pr_err("System timer frequency too low.\n"); + return -EINVAL; + } + [1] https://lore.kernel.org/lkml/89339501-5ee4-e871-3076-c8b02c6fbf6e@arm.com/ Thanks, Ionela. > Thanks, > > tglx