From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.4 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E4201C433DF for ; Tue, 25 Aug 2020 05:56:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C451C2071E for ; Tue, 25 Aug 2020 05:56:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="pATiSDC3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728986AbgHYF4W (ORCPT ); Tue, 25 Aug 2020 01:56:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728885AbgHYF4V (ORCPT ); Tue, 25 Aug 2020 01:56:21 -0400 Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F5ADC061755 for ; Mon, 24 Aug 2020 22:56:21 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id nv17so666951pjb.3 for ; Mon, 24 Aug 2020 22:56:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=71pJ7QjjJTQjXRcSuqPTAeCxZZrph96zOEgdE6uAIWA=; b=pATiSDC3PXXEIOS5eCee9BI1TKY+gifYdWc8S3H5T9Ugb6PmWvWZiiG1zM94yJkVJg YR57iDUo4MW7cmhd7780f1XhepjGUzoOquzMPb/dVJNEHfOpp1OKPhsZFJFuW7+hnGMs zmGx7wohYpQ4/gznF6irL1C/EjihtZnLDu4W/WHbvwcaYkeCmi3n1Y/Ji040tNuxcPsy /474JPL02xH44nzV5S+y5yl/YV+YWTyc61eVa094QdyxBsCF3TlIqKCFYIhRd46O57wb NEaWBXbwYH8Wq6doaEwpxrAnHPRRkNcFXJzoJPm1ZyeGDp4gjwSC/9fhCkcQawH+cE86 g7fA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=71pJ7QjjJTQjXRcSuqPTAeCxZZrph96zOEgdE6uAIWA=; b=Q7z8HuKs16dI0eQ0fdY1BVrOZRkIeR6sZRj1g43iTOzwKkot/rOpMmQEuKWR/kKmK8 iR2wHzuQ3xMt+nkYoYbu2YhmY8dXf0uc4Uqxz4D4MWHQLebiGP8moTsHtFphO3o+wpug mqPRvQU0vCGGW6z8w3qWBjbd9EkCtxZrDsYhLcDr8TyIUoYZfYgE2LsZBDMp63Z2YKzP 28Dg9NrpGFUkR3FWKKUhdF1aLIAzk7wd0r1S8dgOgwlnveKriaKi7XrQpe4MkEVUMwJU 8aBOadRGFBjxmIFbxi5CHbS1ZGvPbYSLqkoEeuToRSbn717/Tnyr/d4y596XyDzWmpor EXzQ== X-Gm-Message-State: AOAM532q3xGLBW8EH5YS2/+bfjV6+9L3efSt47iiXnNzP1lbivq5SKrb fWmRvkVsSoDJipzRZZT6hhgxJQ== X-Google-Smtp-Source: ABdhPJweOS+a1mkYGjwfO83Wk2UMcViQ1NsZH/J7DF0Ov5svgz1gpDZKEYJvuHXGVQ578h3cRMmbIQ== X-Received: by 2002:a17:90a:d594:: with SMTP id v20mr276936pju.227.1598334981146; Mon, 24 Aug 2020 22:56:21 -0700 (PDT) Received: from localhost ([122.172.43.13]) by smtp.gmail.com with ESMTPSA id j3sm1355761pjw.23.2020.08.24.22.56.20 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Aug 2020 22:56:20 -0700 (PDT) Date: Tue, 25 Aug 2020 11:26:18 +0530 From: Viresh Kumar To: Ionela Voinescu Cc: rjw@rjwysocki.net, dietmar.eggemann@arm.com, catalin.marinas@arm.com, sudeep.holla@arm.com, will@kernel.org, valentin.schneider@arm.com, linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 1/5] arch_topology: validate input frequencies to arch_set_freq_scale() Message-ID: <20200825055618.ybght3enlpuwo3va@vireshk-i7> References: <20200824210252.27486-1-ionela.voinescu@arm.com> <20200824210252.27486-2-ionela.voinescu@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200824210252.27486-2-ionela.voinescu@arm.com> User-Agent: NeoMutt/20180716-391-311a52 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 24-08-20, 22:02, Ionela Voinescu wrote: > The current frequency passed to arch_set_freq_scale() could end up > being 0, signaling an error in setting a new frequency. Also, if the > maximum frequency in 0, this will result in a division by 0 error. > > Therefore, validate these input values before using them for the > setting of the frequency scale factor. > > Signed-off-by: Ionela Voinescu > Cc: Sudeep Holla > Cc: Rafael J. Wysocki > --- > drivers/base/arch_topology.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c > index 75f72d684294..1aca82fcceb8 100644 > --- a/drivers/base/arch_topology.c > +++ b/drivers/base/arch_topology.c > @@ -33,6 +33,9 @@ void arch_set_freq_scale(struct cpumask *cpus, unsigned long cur_freq, > unsigned long scale; > int i; > > + if (!cur_freq || !max_freq) We should probably use unlikely() here. Rafael: Shouldn't this have a WARN_ON_ONCE() as well ? > + return; > + > /* > * If the use of counters for FIE is enabled, just return as we don't > * want to update the scale factor with information from CPUFREQ. > -- > 2.17.1 -- viresh From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B7155C433E1 for ; Tue, 25 Aug 2020 05:57:55 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 83E6F2071E for ; Tue, 25 Aug 2020 05:57:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="alxp6wQa"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="pATiSDC3" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 83E6F2071E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=G3CqUItCbvtPx2+Lb8HRx85t5wqoju2HcQ6Rr9f+Qf0=; b=alxp6wQagGZWwug/TNv0wjIFN UPm60Xjzp+b6T7DUrhNTXli83G3LagN1I1huhsF9fXDDbtUxrcP9UhGogYYt1VRBYWF+X7wYsRMoZ 2ex0FHc3ntiwhuFY5oxGU0ZPOQH6t9pN+2J6iWuCvq0z9yKRYx2p+ZofXgACH9A1TXF0m9CIDi0+i dYy5x316r2A+B/mPrpd/+Y+GkRJFcPUo5SCSAhntBRerFYqoox/YdoAxe5SmAsi7txuODMbB/rM2v mcpflh3uJZyr1hrfX5LmikCTaamyKB+AIOAW081ps6aKYsk7V8cm/qnXzNcsepKi4MgIkOBpBjmEa Jdufi1krQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kARwa-0000ZD-8M; Tue, 25 Aug 2020 05:56:28 +0000 Received: from mail-pj1-x1042.google.com ([2607:f8b0:4864:20::1042]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kARwV-0000YV-IR for linux-arm-kernel@lists.infradead.org; Tue, 25 Aug 2020 05:56:26 +0000 Received: by mail-pj1-x1042.google.com with SMTP id z18so668973pjr.2 for ; Mon, 24 Aug 2020 22:56:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=71pJ7QjjJTQjXRcSuqPTAeCxZZrph96zOEgdE6uAIWA=; b=pATiSDC3PXXEIOS5eCee9BI1TKY+gifYdWc8S3H5T9Ugb6PmWvWZiiG1zM94yJkVJg YR57iDUo4MW7cmhd7780f1XhepjGUzoOquzMPb/dVJNEHfOpp1OKPhsZFJFuW7+hnGMs zmGx7wohYpQ4/gznF6irL1C/EjihtZnLDu4W/WHbvwcaYkeCmi3n1Y/Ji040tNuxcPsy /474JPL02xH44nzV5S+y5yl/YV+YWTyc61eVa094QdyxBsCF3TlIqKCFYIhRd46O57wb NEaWBXbwYH8Wq6doaEwpxrAnHPRRkNcFXJzoJPm1ZyeGDp4gjwSC/9fhCkcQawH+cE86 g7fA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=71pJ7QjjJTQjXRcSuqPTAeCxZZrph96zOEgdE6uAIWA=; b=CIjA86SsuH1AKbP4NG9q3/Lcy2gIFNkPiodytm2r/PjL/MPxsPVILKZyWup02Rwkxd SczejirwJWDEB01YV9jC2ISVgMrqmPmR1L7eKs6Cv8765Qc5BCHm+BdeY4TKjN72LSj6 g3t9abEm4pjVFs3ASfOgMrvuwex2kBmPClnBMARpHxNL6m2KzT+jKN1FtCAhoHFI72Nc p18/QKA4h+o9CBvzd2OCQWQfWAoMZd+rOdeE04kG/gTn6TwWlkSCHzeZA5A9qlfRFPgz DL+a1C8hjjbei0bd6MvPTjXVV0ZfNPbFUAwW5AUt9LsZfQFBtjJgIzAqk8+Q6jHLwVY0 dQ+g== X-Gm-Message-State: AOAM532YfwZk+M6eqAtx0lZwgo6oG1gJkajJXeiYxlHflxN1/ZWW1YK6 ysfmah7cz3FGi6De60DswGxPyw== X-Google-Smtp-Source: ABdhPJweOS+a1mkYGjwfO83Wk2UMcViQ1NsZH/J7DF0Ov5svgz1gpDZKEYJvuHXGVQ578h3cRMmbIQ== X-Received: by 2002:a17:90a:d594:: with SMTP id v20mr276936pju.227.1598334981146; Mon, 24 Aug 2020 22:56:21 -0700 (PDT) Received: from localhost ([122.172.43.13]) by smtp.gmail.com with ESMTPSA id j3sm1355761pjw.23.2020.08.24.22.56.20 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Aug 2020 22:56:20 -0700 (PDT) Date: Tue, 25 Aug 2020 11:26:18 +0530 From: Viresh Kumar To: Ionela Voinescu Subject: Re: [PATCH v3 1/5] arch_topology: validate input frequencies to arch_set_freq_scale() Message-ID: <20200825055618.ybght3enlpuwo3va@vireshk-i7> References: <20200824210252.27486-1-ionela.voinescu@arm.com> <20200824210252.27486-2-ionela.voinescu@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200824210252.27486-2-ionela.voinescu@arm.com> User-Agent: NeoMutt/20180716-391-311a52 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200825_015624_787310_0CF5F0F3 X-CRM114-Status: GOOD ( 20.67 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-pm@vger.kernel.org, catalin.marinas@arm.com, rjw@rjwysocki.net, linux-kernel@vger.kernel.org, dietmar.eggemann@arm.com, sudeep.holla@arm.com, will@kernel.org, valentin.schneider@arm.com, linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 24-08-20, 22:02, Ionela Voinescu wrote: > The current frequency passed to arch_set_freq_scale() could end up > being 0, signaling an error in setting a new frequency. Also, if the > maximum frequency in 0, this will result in a division by 0 error. > > Therefore, validate these input values before using them for the > setting of the frequency scale factor. > > Signed-off-by: Ionela Voinescu > Cc: Sudeep Holla > Cc: Rafael J. Wysocki > --- > drivers/base/arch_topology.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c > index 75f72d684294..1aca82fcceb8 100644 > --- a/drivers/base/arch_topology.c > +++ b/drivers/base/arch_topology.c > @@ -33,6 +33,9 @@ void arch_set_freq_scale(struct cpumask *cpus, unsigned long cur_freq, > unsigned long scale; > int i; > > + if (!cur_freq || !max_freq) We should probably use unlikely() here. Rafael: Shouldn't this have a WARN_ON_ONCE() as well ? > + return; > + > /* > * If the use of counters for FIE is enabled, just return as we don't > * want to update the scale factor with information from CPUFREQ. > -- > 2.17.1 -- viresh _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel