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=-6.5 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS 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 9F327C55185 for ; Wed, 22 Apr 2020 14:54:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7A33D2076E for ; Wed, 22 Apr 2020 14:54:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="UUrQV2YD" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726721AbgDVOyE (ORCPT ); Wed, 22 Apr 2020 10:54:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725934AbgDVOyE (ORCPT ); Wed, 22 Apr 2020 10:54:04 -0400 Received: from merlin.infradead.org (unknown [IPv6:2001:8b0:10b:1231::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03CB5C03C1A9; Wed, 22 Apr 2020 07:54:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=C/y0MT4RUP0Ak6RuYzOz+uq54Hlm5rIbVfYvdumz+DM=; b=UUrQV2YDRusF3q4mtsyE/OglW+ U6JQFBF+3KcYfY7tjK+1QSbpmnSpKbp0FQEukWKyUX5k1kTTlBNKnSHilBSlB3pqEDAVNJZ/pHo4a zYgNUSBw8W/iY24GB0zmPhRnlYzY+nDJE/wb167ntBElVK2e5ENkXqzpxo6dWG6pnauv1YaZFu48A kzkSovg89bUxZz5vghqkSykuvsyd2vKZjRiE4udPWELuOoPACF7LwCTxdaVgiMZAZPW0sv2RHGs/s qNhCOEWrh95kiNuxy8LDPyIhj1cL/HyP6dkVzmx82qtF5inj36eqJfFWCCsKHhaKI+YjcVHe6A1fh kv0SMH1A==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jRGkr-0002YT-JX; Wed, 22 Apr 2020 14:53:37 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 4E49C3010C4; Wed, 22 Apr 2020 16:53:34 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 30D18203AA838; Wed, 22 Apr 2020 16:53:34 +0200 (CEST) Date: Wed, 22 Apr 2020 16:53:34 +0200 From: Peter Zijlstra To: Giovanni Gherdovich Cc: Ingo Molnar , "Rafael J . Wysocki" , x86@kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Linus Torvalds , Srinivas Pandruvada , Thomas Gleixner , Borislav Petkov , Len Brown Subject: Re: [PATCH] x86, sched: Prevent divisions by zero in frequency invariant accounting Message-ID: <20200422145334.GM20730@hirez.programming.kicks-ass.net> References: <20200422144055.18171-1-ggherdovich@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200422144055.18171-1-ggherdovich@suse.cz> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 22, 2020 at 04:40:55PM +0200, Giovanni Gherdovich wrote: > The product mcnt * arch_max_freq_ratio could be zero if it overflows u64. > > For context, a large value for arch_max_freq_ratio would be 5000, > corresponding to a turbo_freq/base_freq ratio of 5 (normally it's more like > 1500-2000). A large increment frequency for the MPERF counter would be 5GHz > (the base clock of all CPUs on the market today is less than that). With > these figures, a CPU would need to go without a scheduler tick for around 8 > days for the u64 overflow to happen. It is unlikely, but the check is > warranted. > > Signed-off-by: Giovanni Gherdovich > Fixes: 1567c3e3467c ("x86, sched: Add support for frequency invariance") > --- > arch/x86/kernel/smpboot.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c > index 8c89e4d9ad28..fb71395cbcad 100644 > --- a/arch/x86/kernel/smpboot.c > +++ b/arch/x86/kernel/smpboot.c > @@ -2055,14 +2055,14 @@ void arch_scale_freq_tick(void) > > acnt = aperf - this_cpu_read(arch_prev_aperf); > mcnt = mperf - this_cpu_read(arch_prev_mperf); > - if (!mcnt) > - return; > > this_cpu_write(arch_prev_aperf, aperf); > this_cpu_write(arch_prev_mperf, mperf); > > acnt <<= 2*SCHED_CAPACITY_SHIFT; > mcnt *= arch_max_freq_ratio; > + if (!mcnt) > + return; Should we not pr_warn() and disable the whole thing when this happens?