Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp878372ybc; Tue, 12 Nov 2019 10:35:11 -0800 (PST) X-Google-Smtp-Source: APXvYqwfVofte+gk+y1wSYlUmLCMKe8bmmU8+xQhrT2ZMTbW+V+4wy7O4b3lV6x3tVUpT/D0FsSZ X-Received: by 2002:a17:906:6b01:: with SMTP id q1mr10253059ejr.162.1573583711646; Tue, 12 Nov 2019 10:35:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573583711; cv=none; d=google.com; s=arc-20160816; b=isKLmQ+iAJFYDiPjzxFyQ8PRBsiFSJ/8Epn9W6XG0b5cjyIdOl0mDJUCK5JFPLanMr pECku4fHT5Hm8BJxSUV79cZI3e3IiCUmYzNDHtuIz7FJmTIfGQv/hXWR3v/xF4XmiyG7 YHMjLXiZ6/b35PiFa+RKI0dEjK3ZVozt6drXouysjQZUMBr/yJDHAWPqWHDLfAxClJVI 4nRKtjOyKLECQfNUIw5JF4YnbpSaNguabmHKZiepgdaOz535n3ZGgKL1QDhP+gln0MUF 5u5a4d0njTPG5qDtOdW+yHV9f0XzT6eF8TQoZpnW34ruTR4TUjZKyAcwqeJKMwvR00eg SCyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=MzMUKm7mW+HiS0KEQh6EiE2vBd+rpZ1avgmO/GjuR8I=; b=rAQjm2bs4EDqbFmroxcMKonCHGfp53x3IQKctKA98CZbrEQIf/kEZzl2laLuPPRld5 RTbVAwgt5kV1SWhiKYbYY9batt5jdXghpJPWFyi9xvg4Q2JHJAYY8nniGQpSewgT9SCW yYWVHapMcIVhwCUrsHPSorh9QqiTgrSElHb62keoABsqV8uSTxJHq5Q+em7LSCqdawVy yZFvz14zNz/KhrmA7pMSh+myNF+Ov9BAzW3ELAhV1DR/NnqhOcMftu23eK3Ebm8AgfJC go5oEir7EL/x9CF78hme7EsIcyDyfYqVxq7mNVbwmk3lG+BAL2lCYnA1VJrNOJisdpR8 8gpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=eAThWRNS; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f12si15875670edc.1.2019.11.12.10.34.44; Tue, 12 Nov 2019 10:35:11 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=eAThWRNS; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727049AbfKLSdf (ORCPT + 99 others); Tue, 12 Nov 2019 13:33:35 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:46083 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726995AbfKLSdf (ORCPT ); Tue, 12 Nov 2019 13:33:35 -0500 Received: by mail-wr1-f66.google.com with SMTP id b3so19634059wrs.13 for ; Tue, 12 Nov 2019 10:33:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=MzMUKm7mW+HiS0KEQh6EiE2vBd+rpZ1avgmO/GjuR8I=; b=eAThWRNSQOzWC8Xx6+6jsVEniEBzDbLr/wjeljUOoxx683Mx+TQM0py2RJ6BdmGM0V 3LZddmT1dxWMQyJdnA2cPCJTzHtnjev0mBRtfzAe5JRm/tPdkncQptAlGGOFT3DxCnOF qixjtpn776Y5Xm3uNY+fhZd7MfeMb6Vz0IdbkfGNH7lLOPlw36i2vHJEs9sH4duCoj6p OaCXftU6JEM7Cf3odOVhMSq0lxDNwSFmPksFWa9rCWEogaohxtzZz5E4OGpPZlmhjaMA RxAPU4DDbjLv2V80wd9MmoE67eQh2w9pQV8tAAtOoXI06zrazZuRTc95HVceTiPzZ0/6 zIjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=MzMUKm7mW+HiS0KEQh6EiE2vBd+rpZ1avgmO/GjuR8I=; b=VKB5N/EgUic/m4xBL5teUr/TUeU7l8whd4Pzx8eJGTfE8sXOo+awkGu3GyC3zoOM7S HvwpyDyXM/yexzdOlGggvmsGL3a4OO++RCoB6cV7Lo4S1zTrJy8d/WH2HyTfGn7xIUDn f7y96Mk/xPb9cnPuLikCbJjJWbiBvx4/f+CmLJIUXWUluSG5/QL1VHMHTLBH19py3nLr 02d+wIgxh1/XFgPUD3fMip4l9PB6EJy+gS88/9GaVwfPvGxgfGvNNA5qvp7ceeaQ5fJK cZ6FKlJW1s7VFL/ptz0a15FkkbujdJCLcW+cuWHM9jTVnKgwPKBCDRaMtLrRksW2clex zpLg== X-Gm-Message-State: APjAAAXkCC8q8jI1gRmuDPVrgfJ9XpfKI5SkOkp4ObBVIMqVAanrAVZv cOqVsMF0ovA+Lg67SqfStSEbuSPNpAf6u0OrYWZL5g== X-Received: by 2002:adf:ffd0:: with SMTP id x16mr3612529wrs.86.1573583612669; Tue, 12 Nov 2019 10:33:32 -0800 (PST) MIME-Version: 1.0 References: <20191112154144.GC168812@cmpxchg.org> In-Reply-To: <20191112154144.GC168812@cmpxchg.org> From: Suren Baghdasaryan Date: Tue, 12 Nov 2019 10:33:21 -0800 Message-ID: Subject: Re: [PATCH] psi:fix divide by zero in psi_update_stats To: Johannes Weiner Cc: tim , Ingo Molnar , Peter Zijlstra , LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 12, 2019 at 7:41 AM Johannes Weiner wrote: > > On Fri, Nov 08, 2019 at 03:33:24PM +0800, tim wrote: > > In psi_update_stats, it is possible that period has value like > > 0xXXXXXXXX00000000 where the lower 32 bit is 0, then it calls div_u64 which > > truncates u64 period to u32, results in zero divisor. > > Use div64_u64() instead of div_u64() if the divisor is u64 to avoid > > truncation to 32-bit on 64-bit platforms. > > > > Signed-off-by: xiejingfeng > > This is legit. When we stop the periodic averaging worker due to an > idle CPU, the period after restart can be much longer than the ~4 sec > in the lower 32 bits. See the missed_periods logic in update_averages. > > What is surprising is that you can hit this repeatedly, as the odds > are 1 in 4,294,967,296. An extremely coarse clock source? > > Acked-by: Johannes Weiner > > There are several more instances of div_u64 in psi.c. They all look > fine to me except for one in the psi poll() windowing code, where we > divide by the window size, which can be up to 10s. CCing Suren. > > --- > From 009cece5f37a38f4baeb1bebdcb432ac9ae66ef8 Mon Sep 17 00:00:00 2001 > From: Johannes Weiner > Date: Tue, 12 Nov 2019 10:35:26 -0500 > Subject: [PATCH] psi: fix a division error in psi poll() > > The psi window size is a u64 an can be up to 10 seconds right now, > which exceeds the lower 32 bits of the variable. But div_u64 is meant > only for 32-bit divisors. Use div64_u64 for the 64-bit divisor. > > Signed-off-by: Johannes Weiner > --- > kernel/sched/psi.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c > index 517e3719027e..84af7aa158bf 100644 > --- a/kernel/sched/psi.c > +++ b/kernel/sched/psi.c > @@ -481,7 +481,7 @@ static u64 window_update(struct psi_window *win, u64 now, u64 value) > u32 remaining; > > remaining = win->size - elapsed; > - growth += div_u64(win->prev_growth * remaining, win->size); > + growth += div64_u64(win->prev_growth * remaining, win->size); > } > > return growth; > -- > 2.24.0 > Reviewed-by: Suren Baghdasaryan