From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751382AbdCPGnV (ORCPT ); Thu, 16 Mar 2017 02:43:21 -0400 Received: from mail-wr0-f195.google.com ([209.85.128.195]:33346 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751054AbdCPGnS (ORCPT ); Thu, 16 Mar 2017 02:43:18 -0400 Date: Thu, 16 Mar 2017 07:42:09 +0100 From: Ingo Molnar To: Mark Rutland Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Ingo Molnar Subject: Re: [PATCH] lockdep: avoid signed overflow Message-ID: <20170316064208.GB7130@gmail.com> References: <1489595492-11745-1-git-send-email-mark.rutland@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1489595492-11745-1-git-send-email-mark.rutland@arm.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Mark Rutland wrote: > The counters in struct lockdep_stats are all (signed) ints. For some > counters (e.g. hardirqs_on_events, hardirqs_off_events), it's easy to > trigger an overflow in a short period of time, rendering the information > exposed under /proc/lockdep_stats erroneous, and causing UBSAN to > scream. > diff --git a/kernel/locking/lockdep_internals.h b/kernel/locking/lockdep_internals.h > index c2b8849..9fd970e 100644 > --- a/kernel/locking/lockdep_internals.h > +++ b/kernel/locking/lockdep_internals.h > @@ -132,23 +132,23 @@ extern void get_usage_chars(struct lock_class *class, > * and we want to avoid too much cache bouncing. > */ > struct lockdep_stats { > - int chain_lookup_hits; > - int chain_lookup_misses; > - int hardirqs_on_events; > - int hardirqs_off_events; > - int redundant_hardirqs_on; > - int redundant_hardirqs_off; > - int softirqs_on_events; > - int softirqs_off_events; > - int redundant_softirqs_on; > - int redundant_softirqs_off; > - int nr_unused_locks; > - int nr_cyclic_checks; > - int nr_cyclic_check_recursions; > - int nr_find_usage_forwards_checks; > - int nr_find_usage_forwards_recursions; > - int nr_find_usage_backwards_checks; > - int nr_find_usage_backwards_recursions; > + unsigned long chain_lookup_hits; > + unsigned long chain_lookup_misses; > + unsigned long hardirqs_on_events; > + unsigned long hardirqs_off_events; > + unsigned long redundant_hardirqs_on; > + unsigned long redundant_hardirqs_off; > + unsigned long softirqs_on_events; > + unsigned long softirqs_off_events; > + unsigned long redundant_softirqs_on; > + unsigned long redundant_softirqs_off; > + unsigned long nr_unused_locks; > + unsigned long nr_cyclic_checks; > + unsigned long nr_cyclic_check_recursions; > + unsigned long nr_find_usage_forwards_checks; > + unsigned long nr_find_usage_forwards_recursions; > + unsigned long nr_find_usage_backwards_checks; > + unsigned long nr_find_usage_backwards_recursions; Presumably it's just as easy to overflow on 32-bit CPUs, so this should probably be u64 or such. Thanks, Ingo