Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3097989ybl; Sun, 15 Dec 2019 02:52:53 -0800 (PST) X-Google-Smtp-Source: APXvYqyymP0Z8a1uK3l2SSqPcP9aRYC/kJMbt7vA0qnQbhJqXD5fS4hNA1robKNc2jUbmrlGNljD X-Received: by 2002:a9d:6a5a:: with SMTP id h26mr26571071otn.103.1576407173074; Sun, 15 Dec 2019 02:52:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576407173; cv=none; d=google.com; s=arc-20160816; b=k4e9P2wIeAT2a8gA9Z1ogE8xNpSeVpQndhnFjl+d11+/l59ib6ZVBtth/ad9y/VjRl xPKsJP+/jRlyBDPo4qs1SAexKrHwjLoscnzXNS/5dHlPvdGZf7+bws6WwWdYYFh+28UJ /d2kRxllWbHwGtUh5Q1rzdsQUj4b9GdcTIIqCNOpfyIpa2fhpLkL5B4qUiB51ID2D05z xedRM1RWSN+pf+d+Wh7yFKy+9wbrN1eAG1BHv1MQSK0+DLCJe91oR10NqIQwK2x8PYSM JaBpk0AwTxcN+apbVSCuLGLySOpSmyARHM6wiBYjfwKs/9uRdj6Ys/3d9rLB6LWPUiqt 4KgQ== 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-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=1J5Cn/yHzePxXN4n7Fgso10E+FoU9K6EYrjMWMes8/o=; b=UhedqiRow2OyGEzohuDIUd7/QEEBb3Imq2Ekv2boFspZsryNdx1zTwG6O7sgKj989V YyTsLQOxrDMYpACE88kUKHCFUM/u9dUmj7u1XZR+jHW6dZiS40glkstpoWnTm8oJmR8F ubIe+ZC0IY7+ub+++Xq4Sph6KII72BiN0u+8PHS3phYWUG+MeZr5iyhOZ/Lj3wb+qupV ueqdEUjSKioINTraX/J2SzyYuH5TzZtGR2WWXJuhdjJEWDCwQQNxNEzlUWJx4zchz9sQ wH8oIfbtRAtKVtMr0vX3qnw0NyKgoUUAvnhYssoTyZghFL5BXXa1TUgf1UlGWl4EmQ0c kQZA== 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 h3si8752782otk.60.2019.12.15.02.52.39; Sun, 15 Dec 2019 02:52:53 -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 S1726125AbfLOKwA (ORCPT + 99 others); Sun, 15 Dec 2019 05:52:00 -0500 Received: from relay1-d.mail.gandi.net ([217.70.183.193]:51337 "EHLO relay1-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726081AbfLOKv7 (ORCPT ); Sun, 15 Dec 2019 05:51:59 -0500 X-Originating-IP: 88.190.179.123 Received: from localhost (unknown [88.190.179.123]) (Authenticated sender: repk@triplefau.lt) by relay1-d.mail.gandi.net (Postfix) with ESMTPSA id 2EAAD240003; Sun, 15 Dec 2019 10:51:55 +0000 (UTC) Date: Sun, 15 Dec 2019 12:00:20 +0100 From: Remi Pommarel To: Jerome Brunet Cc: Neil Armstrong , Michael Turquette , Stephen Boyd , Kevin Hilman , linux-amlogic@lists.infradead.org, linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] clk: meson: pll: Fix by 0 division in __pll_params_to_rate() Message-ID: <20191215110020.GA7304@voidbox> References: <20191208212206.16808-1-repk@triplefau.lt> <1jo8whesj2.fsf@starbuckisacylon.baylibre.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1jo8whesj2.fsf@starbuckisacylon.baylibre.com> User-Agent: Mutt/1.12.2 (2019-09-21) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Dec 09, 2019 at 10:51:13AM +0100, Jerome Brunet wrote: > > On Sun 08 Dec 2019 at 22:22, Remi Pommarel wrote: > > > Some meson pll registers can be initialized with 0 as N value, introducing > > the following division by 0 when computing rate : > > > > UBSAN: Undefined behaviour in drivers/clk/meson/clk-pll.c:75:9 > > division by zero > > CPU: 0 PID: 1 Comm: swapper/0 Not tainted 5.4.0-rc3-608075-g86c9af8630e1-dirty #400 > > Call trace: > > dump_backtrace+0x0/0x1c0 > > show_stack+0x14/0x20 > > dump_stack+0xc4/0x100 > > ubsan_epilogue+0x14/0x68 > > __ubsan_handle_divrem_overflow+0x98/0xb8 > > __pll_params_to_rate+0xdc/0x140 > > meson_clk_pll_recalc_rate+0x278/0x3a0 > > __clk_register+0x7c8/0xbb0 > > devm_clk_hw_register+0x54/0xc0 > > meson_eeclkc_probe+0xf4/0x1a0 > > platform_drv_probe+0x54/0xd8 > > really_probe+0x16c/0x438 > > driver_probe_device+0xb0/0xf0 > > device_driver_attach+0x94/0xa0 > > __driver_attach+0x70/0x108 > > bus_for_each_dev+0xd8/0x128 > > driver_attach+0x30/0x40 > > bus_add_driver+0x1b0/0x2d8 > > driver_register+0xbc/0x1d0 > > __platform_driver_register+0x78/0x88 > > axg_driver_init+0x18/0x20 > > do_one_initcall+0xc8/0x24c > > kernel_init_freeable+0x2b0/0x344 > > kernel_init+0x10/0x128 > > ret_from_fork+0x10/0x18 > > > > This checks if N is null before doing the division. > > Thanks for reporting this > > > > > Fixes: 8289aafa4f36 ("clk: meson: improve pll driver results with > > frac") > > In mainline, the commit above went in with sha1 3c4fe763d64d. > > Also, this commit is not really responsible for the problem. Having HW > initialized with N = 0 would have failed since the beginning, I believe. > > In this case the correct fixes would be: > Fixes: 7a29a869434e ("clk: meson: Add support for Meson clock controller") > > > > Signed-off-by: Remi Pommarel > > --- > > drivers/clk/meson/clk-pll.c | 4 ++++ > > 1 file changed, 4 insertions(+) > > > > diff --git a/drivers/clk/meson/clk-pll.c b/drivers/clk/meson/clk-pll.c > > index ddb1e5634739..6649659f216a 100644 > > --- a/drivers/clk/meson/clk-pll.c > > +++ b/drivers/clk/meson/clk-pll.c > > @@ -66,6 +66,10 @@ static unsigned long __pll_params_to_rate(unsigned long parent_rate, > > (1 << pll->frac.width)); > > } > > > > + /* Avoid by zero division */ > > + if (n == 0) > > + return 0; > > This can only really happen after init, in recalc() rate. > > I would much prefer if you could check the n value right after it is > read (meson_parm_read()) in .recalc_rate() and add a comment explaining > that some HW may have this parameter set 0 on init. > Sure will do. Thanks for reviewing this. -- Remi > > + > > return DIV_ROUND_UP_ULL(rate, n); > > } >