Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753817AbcDSJfW (ORCPT ); Tue, 19 Apr 2016 05:35:22 -0400 Received: from terminus.zytor.com ([198.137.202.10]:56550 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753787AbcDSJfO (ORCPT ); Tue, 19 Apr 2016 05:35:14 -0400 Date: Tue, 19 Apr 2016 02:34:27 -0700 From: tip-bot for Davidlohr Bueso Message-ID: Cc: hpa@zytor.com, torvalds@linux-foundation.org, linux-kernel@vger.kernel.org, tglx@linutronix.de, Waiman.Long@hpe.com, paulmck@linux.vnet.ibm.com, dbueso@suse.de, akpm@linux-foundation.org, mingo@kernel.org, dave@stgolabs.net, peterz@infradead.org Reply-To: dbueso@suse.de, akpm@linux-foundation.org, peterz@infradead.org, mingo@kernel.org, dave@stgolabs.net, tglx@linutronix.de, linux-kernel@vger.kernel.org, hpa@zytor.com, torvalds@linux-foundation.org, paulmck@linux.vnet.ibm.com, Waiman.Long@hpe.com In-Reply-To: <1460961103-24953-1-git-send-email-dave@stgolabs.net> References: <1460961103-24953-1-git-send-email-dave@stgolabs.net> To: linux-tip-commits@vger.kernel.org Subject: [tip:locking/urgent] locking/pvqspinlock: Fix division by zero in qstat_read() Git-Commit-ID: 6687659568e2ec5b3ac24b39c5d26ce8b9d90434 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2560 Lines: 67 Commit-ID: 6687659568e2ec5b3ac24b39c5d26ce8b9d90434 Gitweb: http://git.kernel.org/tip/6687659568e2ec5b3ac24b39c5d26ce8b9d90434 Author: Davidlohr Bueso AuthorDate: Sun, 17 Apr 2016 23:31:41 -0700 Committer: Ingo Molnar CommitDate: Tue, 19 Apr 2016 10:49:19 +0200 locking/pvqspinlock: Fix division by zero in qstat_read() While playing with the qstat statistics (in /qlockstat/) I ran into the following splat on a VM when opening pv_hash_hops: divide error: 0000 [#1] SMP ... RIP: 0010:[] [] qstat_read+0x12e/0x1e0 ... Call Trace: [] ? mem_cgroup_commit_charge+0x6c/0xd0 [] ? page_add_new_anon_rmap+0x8c/0xd0 [] ? handle_mm_fault+0x1439/0x1b40 [] ? do_mmap+0x449/0x550 [] ? __vfs_read+0x23/0xd0 [] ? rw_verify_area+0x52/0xd0 [] ? vfs_read+0x81/0x120 [] ? SyS_read+0x42/0xa0 [] ? entry_SYSCALL_64_fastpath+0x1e/0xa8 Fix this by verifying that qstat_pv_kick_unlock is in fact non-zero, similarly to what the qstat_pv_latency_wake case does, as if nothing else, this can come from resetting the statistics, thus having 0 kicks should be quite valid in this context. Signed-off-by: Davidlohr Bueso Reviewed-by: Waiman Long Cc: Andrew Morton Cc: Linus Torvalds Cc: Paul E. McKenney Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: dave@stgolabs.net Cc: waiman.long@hpe.com Link: http://lkml.kernel.org/r/1460961103-24953-1-git-send-email-dave@stgolabs.net Signed-off-by: Ingo Molnar --- kernel/locking/qspinlock_stat.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/kernel/locking/qspinlock_stat.h b/kernel/locking/qspinlock_stat.h index eb2a2c9..d734b75 100644 --- a/kernel/locking/qspinlock_stat.h +++ b/kernel/locking/qspinlock_stat.h @@ -136,10 +136,12 @@ static ssize_t qstat_read(struct file *file, char __user *user_buf, } if (counter == qstat_pv_hash_hops) { - u64 frac; + u64 frac = 0; - frac = 100ULL * do_div(stat, kicks); - frac = DIV_ROUND_CLOSEST_ULL(frac, kicks); + if (kicks) { + frac = 100ULL * do_div(stat, kicks); + frac = DIV_ROUND_CLOSEST_ULL(frac, kicks); + } /* * Return a X.XX decimal number