Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp17561123ybl; Thu, 2 Jan 2020 07:44:33 -0800 (PST) X-Google-Smtp-Source: APXvYqy02QrFRiSwFh3wjzsDB0BkD/nPc9BwUD7OoGyX6g/tsqwoBtEiK8O+td2ZvJ97MQelN7ST X-Received: by 2002:a05:6830:3001:: with SMTP id a1mr78814570otn.254.1577979873635; Thu, 02 Jan 2020 07:44:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577979873; cv=none; d=google.com; s=arc-20160816; b=0kYS8niUjuk43bye92csnFio8Xzl3dp2cLklSn9eALtIE3KWhjigiWiJ20MeX9picH 7JSmnY0FXRywNF8hMYMStkpW83yK5nj3amKmvAcoMWoF2Sy/kRf0pGKzs6Bj60doGd6C hoewzm5iz9ju9jWU5XD0kslj7Hlnw4QX880pVuzkMithQxiKwUK15ei9Vn3OqHa40FvT TRQDLtSw6d7s78LsOenw7lYTCGn574/9TtAHVVOtc31sEc+QxbOl20j3m0BJzqUYB7u7 z7UdGQYd/Y/zrSKbSnpc1fAYce4gu3fphGdKeKwIaiHJlgT5FWXBCEXA8DfXeAn3Q2Et MWKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=0vZRRD8jY5OF3vrGLNd+w2DBHc3dKT0cOUjbE/l4V90=; b=p943Mdm72lRR2wSyuHDIKCdPcLIRMakzUx30PZQPYF0dXvYxOJ8QA0C5D0by+tsjuS gKd0IyDdaqSjzXhCxECMhZq8ptMw/EFqI/9iqv6UEghxnSjAjKNng4pCkglb4Qc8+wWL tAGJG9rs8x6fQUKI0anwZ7LNOyLP5yoYcFwskZ4Y+WaN+dO7HSCM3gWOzWajwxrdDYSV FWxxnYGECyx7m4dzOWXjYN+O4CUVWQcfdK04DJQoCH9co0nmZI0vz017DjKLe6q8R5DJ MrTGbOgmKjTV9mi/wMLsVLWd0XTabPRbnNtMgCmMCgxm8vbN8kuzZdqs6iqx+AoJcFhM QBIw== 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 k14si1806304oig.69.2020.01.02.07.44.21; Thu, 02 Jan 2020 07:44:33 -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 S1728750AbgABPmd (ORCPT + 99 others); Thu, 2 Jan 2020 10:42:33 -0500 Received: from mail.kernel.org ([198.145.29.99]:33976 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728561AbgABPmd (ORCPT ); Thu, 2 Jan 2020 10:42:33 -0500 Received: from gandalf.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 187862072C; Thu, 2 Jan 2020 15:42:32 +0000 (UTC) Date: Thu, 2 Jan 2020 10:42:30 -0500 From: Steven Rostedt To: Wen Yang Cc: Ingo Molnar , xlpang@linux.alibaba.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH] ftrace: avoid potential division by zero Message-ID: <20200102104230.6125d776@gandalf.local.home> In-Reply-To: <20200101093219.3639-1-wenyang@linux.alibaba.com> References: <20200101093219.3639-1-wenyang@linux.alibaba.com> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 1 Jan 2020 17:32:19 +0800 Wen Yang wrote: > The ftrace_profile->counter is unsigned long and > do_div truncates it to 32 bits, which means it can test > non-zero and be truncated to zero for division. > Fix this issue by using div64_ul() instead. Thanks, but since we are using div64_ul() which has different semantics than do_div() let's clean up the code that was written to deal with the strange do_div() semantics. > > Signed-off-by: Wen Yang > Cc: Steven Rostedt > Cc: Ingo Molnar > Cc: linux-kernel@vger.kernel.org > --- > kernel/trace/ftrace.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c > index ac99a35..a490ba5 100644 > --- a/kernel/trace/ftrace.c > +++ b/kernel/trace/ftrace.c > @@ -527,7 +527,7 @@ static int function_stat_show(struct seq_file *m, void *v) > > #ifdef CONFIG_FUNCTION_GRAPH_TRACER > avg = rec->time; > - do_div(avg, rec->counter); > + avg = div64_ul(avg, rec->counter); The above should be: avg = div64_ul(rec->time, rec->counter); and get rid of the pre-assigning of avg. > if (tracing_thresh && (avg < tracing_thresh)) > goto out; > #endif > @@ -553,7 +553,8 @@ static int function_stat_show(struct seq_file *m, void *v) > * Divide only 1000 for ns^2 -> us^2 conversion. > * trace_print_graph_duration will divide 1000 again. > */ > - do_div(stddev, rec->counter * (rec->counter - 1) * 1000); > + stddev = div64_ul(stddev, > + rec->counter * (rec->counter - 1) * 1000); This can stay as is, because of the complex dividend in the equation. Thanks, -- Steve > } > > trace_seq_init(&s);