From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C99A9225408 for ; Wed, 7 Jan 2026 23:19:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767827992; cv=none; b=d8htceH1eX0mABxa2hwWxCbRJ70M3mkCSnv/2ZBHZnUdWxynpqZ/po1fO0q1t05uEH8IMmmubOVl09zZRPpfb9s6BtPfGd+UVgGK9o8d5s+T/g4s2wBZY9zALutxufBbJLzqMPtyuzjfQBg3SzOIe9LKn62I8KTk8U+ZWnTTbjM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767827992; c=relaxed/simple; bh=VBVlmTyDsmFzPanb+UWhVbw316hjKaMVO3k3rPdnwsk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=hBKlVS5LUPwwNjhBnwy7RuErUZp+9sw3YM23EnPypLsiSCOeV/uS6I8NW248znukP5HM5AjIMg7vp30n6xbmNYv21urYb69luqKRM0upYqWUUsFnmFUM2uHavp0jjwW3b2VEtx7MiHZyRD4YLoJqVNJkfP4JbSq4yrnQFFWX000= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=qP9qwocK; arc=none smtp.client-ip=209.85.214.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="qP9qwocK" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-2a35ae38bdfso113465ad.1 for ; Wed, 07 Jan 2026 15:19:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1767827990; x=1768432790; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=YrTegim1IGH1EM+qnfVQluY5KhY2cqE1cUaOvjCI5uc=; b=qP9qwocKAK4V2EVXeoEr+Oc0dN8UYLKTSoDrnT9rke/iv669fzeObH5EB7bKDdsEP2 4HTpJCP+4HF0fXhWLLM3jUNVpr9RJFN2bO8LEDKjZ6/XXJzOfaJEDrgvggkztGjFhcZR 6eHhk6BCF6B7rj6Sl88YF4ffjAmBm2Xt00ya4JKA095+VL0RkObThgspUQVC7Q9sS7Uv 8BypPv45wjYedirNqZKfk8AuLnsyHvs0pwBsQ6Cs8WQli/kmecJ+JcIx55tCPEdGh0om KqEELbRLoz7q3B4Wf3xeNBqeS20Vho6DudTBUxHGjL/mCC5vm9KfJXcI/APIMIfYKVaO oaWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767827990; x=1768432790; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YrTegim1IGH1EM+qnfVQluY5KhY2cqE1cUaOvjCI5uc=; b=gSqp+j5geRY0HPshMGu96hQq6CQgCIPD6/KSPjqpaxj8CCL5YZNQnXZ0EdG5SJq1Sp qtBk+Bb8c5+J1q/RzQl5LUAZXy6HqL9xe81IBinY2bgBBILH0PaBUKiboL8UAzXbvQwO HKsdI3ylJMZ3GXlOWl1qorb5GAzC1mwb15LaVHc/+GxWC4wgkmxubknNV2ToyqHNNkEV shf9azdrIPcUeBvQ5pal0FHZL3bL32A98eY5eDCatyKrESFp8tKVjLsj/n6W1BukE9vS +YiV65uPwstzVOaY1g+oJ/Zuja+HwmLO+CXy6LwuyuD+zKJMdr/qmbNWPQ5rVb+LW29v h36g== X-Forwarded-Encrypted: i=1; AJvYcCW7vFEi+oT23cJLSHwGAwCye0XQ9GLKebJWlMdc0SLSpA0FnY4F2Jr5zRt8B+pFQZKcC5TuXd1fdgSwlTY=@vger.kernel.org X-Gm-Message-State: AOJu0YyMT777JDO8mZTFctigbepVoDXlMAgD/vVZE9oVh+qmrqg4Ijt6 Zv7Wu+u/dOHmtyV3J7/BecnMy9W+Xq0YxKZi4u+QBIKtBHy1EgEkvsaLyJVblkRILg== X-Gm-Gg: AY/fxX7vg60g3PYZYnB/uz2v9oNP0Nt7cRdVY4EcTdAyJaVwJQ293zQ2D+pcRQD0p/m I2CyOyKbqZwHQsxV4ExHn7qlOPa0qDI+H4YGzk//WPXDUuMV4A9MGGd1yV9Id86mRvxqvXuApsf P12W9jlySQ3E38hobXOOAw0GZ52LfLwDfds8LSSkYTtmWqbJNFWg4tB4X7sJSL+7f3UfzO9CMFV eBSP+Qtx+OspNdkqOtKHAYrEUCgUb01Oq/0bmuAj4iBPxTtOESZTwRn/s9GSTr1L0CyW2tnKcU4 6h5fGiYSMOYqlnLKIjKW8cqQM/MmGiaMLgJm1qLF4Fsh6S1e1emSCtuMS9TNgA/yqsyEGp6nTye iPOU59vBXb9TmHPC/2OZBEq8Hgl36M/zu5gDDHhlKMjRE9Y5R9ci72plNXC9PB3O3u8wfkhzFbU thNh2TzD0m/e9x1tPiTFY9/xEdvKcKskCCNTQH9rONOmZhJrcvNA== X-Received: by 2002:a17:902:e786:b0:2a0:89b0:71d7 with SMTP id d9443c01a7336-2a3ff095070mr392195ad.13.1767827989556; Wed, 07 Jan 2026 15:19:49 -0800 (PST) Received: from google.com (210.53.125.34.bc.googleusercontent.com. [34.125.53.210]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c4cc05cd9d9sm6402603a12.16.2026.01.07.15.19.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jan 2026 15:19:48 -0800 (PST) Date: Wed, 7 Jan 2026 23:19:44 +0000 From: Carlos Llamas To: Thomas Gleixner Cc: Wake Liu , Anna-Maria Behnsen , Frederic Weisbecker , John Stultz , Shuah Khan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Stephen Boyd Subject: Re: [PATCH v2] selftests/timers: Consolidate and fix 32-bit overflow in timespec_sub Message-ID: References: <20250915191944.9779-1-wakel@google.com> <87qzw06y8t.ffs@tglx> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87qzw06y8t.ffs@tglx> On Sun, Sep 21, 2025 at 09:49:54AM +0200, Thomas Gleixner wrote: > On Tue, Sep 16 2025 at 03:19, Wake Liu wrote: > > The timespec_sub function, as implemented in several timer > > timespec_sub() > > https://www.kernel.org/doc/html/latest/process/maintainer-tip.html#function-references-in-changelogs > > > selftests, is prone to integer overflow on 32-bit systems. > > > > The calculation `NSEC_PER_SEC * b.tv_sec` is performed using > > 32-bit arithmetic, and the result overflows before being > > stored in the 64-bit `ret` variable. This leads to incorrect > > time delta calculations and test failures. > > > > As suggested by tglx, this patch fixes the issue by: > > s/this patch fixes/fix/ > > > > > 1. Creating a new `static inline` helper function, > > `timespec_to_ns`, which safely converts a `timespec` to > > nanoseconds by casting `tv_sec` to `long long` before > > multiplying with `NSEC_PER_SEC`. > > > > 2. Placing the new helper and a rewritten `timespec_sub` into > > a common header: tools/testing/selftests/timers/helpers.h. > > > > 3. Removing the duplicated, buggy implementations from all > > timer selftests and replacing them with an #include of the > > new header. > > > > This consolidates the code and ensures the calculation is > > correctly performed using 64-bit arithmetic across all tests. > > This lacks a Signed-off-by. > > > Changes in v2: > > - Per tglx's feedback, instead of changing NSEC_PER_SEC globally, > > this version consolidates the buggy timespec_sub() implementations > > into a new 32-bit safe inline function in a shared header. > > - Amended the commit message to be more descriptive. > > change logs go behind the '---' separator as they are not part of the > commit message. It's documented how to format a change log properly. > > > -#define UNREASONABLE_LAT (NSEC_PER_SEC * 5) /* hopefully we resume in 5 secs */ > > +#define UNREASONABLE_LAT (NSEC_PER_SEC * 5LL) /* hopefully we resume in 5 secs */ > > How is this change and the pile of similar ones related to $subject and > why are they required in the first place? > > > index 000000000000..652f20247091 > > --- /dev/null > > +++ b/tools/testing/selftests/timers/helpers.h > > @@ -0,0 +1,31 @@ > > Lacks a SPDX identifier. > > scripts/checkpatch.pl exists for a reason. > > Thanks, > > tglx I also just stumbled into this. However, doing a little bit of research it seems this was introduced by commit 80fa614e2fbc ("selftests: timers: Remove local NSEC_PER_SEC and USEC_PER_SEC defines"), which explicitly changes the local definitions in favor of the internal kernel header, but that doesn't seem right. I think we should probably revert that commit instead? -- Carlos Llamas