Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp47813lqd; Tue, 23 Apr 2024 14:13:05 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUAcHGkrpj0C5mpDETIxcI9RZCGJO9MRNvCI3gUpiiaiDbO1oRgp5t7fj6nSaoWOga+xIw0RqMqLLECUUm/BO+eH1Z/paVZvjiM6yPJSA== X-Google-Smtp-Source: AGHT+IEl23XQGRMN9HKNJZ0k6woUBX2TtvUFohL5S7mutILlBXrxiyKjoaLC53qiGswpQpvWilOQ X-Received: by 2002:ac8:5acd:0:b0:439:f138:36f7 with SMTP id d13-20020ac85acd000000b00439f13836f7mr690961qtd.53.1713906784899; Tue, 23 Apr 2024 14:13:04 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713906784; cv=pass; d=google.com; s=arc-20160816; b=TWP8XyeGGnEoar0dm1ZdzWh3OTP8gvIrNiADShUngrsvooreSmyYejjkn1Mkf6+PUO +dmr7631AB8OeKoe+mDk/r0ru1DlCmMC02Mgg6V60J22UExMfZg52QRp7qCpI7nmFyXy YjbnUI+YJo4Nx2ZQxoBSoTbnIgbcZti2sf/TCjd02OsRWKa1RYTujwEktcax7+uO8Gtx OhaDKr7EIisrnxNXMrrgZ+9kmCv38uvN+7Nqm8fIdZgrS0ZJzVt6gwrkE7Z8i+Q8Crbf 3SqmiE9Xy9pk0qKOLlYlBAgmEYtYuOe16bDSzjncbnDKPX+hQ7Q8ACCoF4WPhCBhTh5V wSgw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:feedback-id:dkim-signature; bh=UC62SSmjBqgn/WCf7krMQgCSYCyzmYRam3I6GpOx66w=; fh=Pr/EAEheV0903gNbCpAheB6rYmtHH/YfXfK0nvgyl6c=; b=LrQbZK2JGy5S3mroyhujxadVRm235zox8OFlw+aC8++BOpbAvOUQ5+JbtlPszLTt11 tiAWQLMZyqJPnkMB3hIKW7nicB90dLFf8L/B6Fj5cY4CuHVms7vluJdV4X3U3W5MyUmc 5nWw+bqE0ganOEOeXxcdrt/+hRBO6DKH/ciIySdI4rVx5Qj3mAnvxK2ZvgD5kzuXBWjM GAkL/rAzx6Fxt5uFhSYqAycU5luRW8ZEfqP6UVt7hMZfhfylGqsZ2btzoN7vawtN45Uo x0HD4xo4gJORNv02tGnqK1ex7VhHyqzUXV6A8xwD1AqsGcDYsQkESOzMS4TDNb9KmoSI muRQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=d9jN9Hpf; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-155910-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-155910-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id ga20-20020a05622a591400b00439b4079514si6406717qtb.647.2024.04.23.14.13.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 14:13:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-155910-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=d9jN9Hpf; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-155910-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-155910-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id DAF201C242CA for ; Tue, 23 Apr 2024 21:12:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CAE15143878; Tue, 23 Apr 2024 21:11:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="d9jN9Hpf" Received: from mail-oi1-f177.google.com (mail-oi1-f177.google.com [209.85.167.177]) (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 8A653142E97; Tue, 23 Apr 2024 21:11:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713906718; cv=none; b=SPOHQ5hauxuJqGOw2ytLIBQJ+lBfejf5aGdOy4Xke3KmLN5VKP7DEFBiGun/V7PqFcQb+1lT+EzxoK+sl4K0+uBsHXA0T5v0hyipibNgNf/fV9Rj/fj8JiykfX6Qxbj4kOiPCA9LNw+tb0GKJG5NbYynE4CwsJ1sCZtM76YnQSU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713906718; c=relaxed/simple; bh=BCvCUEpG1dWWFdyB0viZeQh4dMtu9PpK7XpuEOqeMzo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=lrcgPo6Yl5XwJ8Lv6vD039GeDfKBVTPtpiqqs7zy0I2JZ27omV3mqWMuJMLHzPJEE4wU5oKyJ93d0BM0lezuauMmNakpahV7kBFWbIFq5y5nsmt/3aUACIZKWv9dyqztx1HrLKjFVXtc0F9eTYlgVffJ5vgOVq/ZHXJvchm51Q0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=d9jN9Hpf; arc=none smtp.client-ip=209.85.167.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-oi1-f177.google.com with SMTP id 5614622812f47-3c71c7e2d40so1726494b6e.3; Tue, 23 Apr 2024 14:11:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713906716; x=1714511516; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:feedback-id:from:to:cc:subject:date :message-id:reply-to; bh=UC62SSmjBqgn/WCf7krMQgCSYCyzmYRam3I6GpOx66w=; b=d9jN9HpfIo8iJv6ZDqv8rYemaZArEhCPuBTJKaSlExHukviS4a4wqjyec/vSkzDGNH Xb09Us79+KphWzOJSE8s5cWdm43V/lg04q/XldJMOBgXRQJqbFOalMEpCjr0UwSwBAPJ i3CUYOq0DQUErv90L5GXCMHJdqulgHhhBZ5ghM5v/OGw27QSdNgN9aQC7xAgx7b4UTKx QB2GYNuciNtlTSFwviBzWU0oqy4nbxZXOWo7RTeNIg6UoFBCnWDn6kkx6aX0nPmOBjuP todJsCfiOoCC2P65orQvrKd4axaVqx+37+NBIt/z/wxeLFDmo0UQCT/yYj6S/yvgshFA 4dyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713906716; x=1714511516; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:feedback-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UC62SSmjBqgn/WCf7krMQgCSYCyzmYRam3I6GpOx66w=; b=AnN5aRhCzwFb1GCdlkgDmNKxH1V24aXbnZXFk3U2q5nPOOMdflA1ny8YDsk9jM2CgN VIHCPNXvhyxlfLnjFr4hv9UooSfoHRiAjG/qhhY4OzwUx690pnG6eaVuTn5XUGwCPHUf hWB9EOX2v4HrV6WM4s1LwvvFAgQ4YJ/JX4EApuyu+FSOwrE6Apn6mm0eWKghdD4kCAVk 9lUu1jLI8g+Xt143Kvb1aELXjqOgIxn4im2nmgGIe5fiB5N6uHZcxTFJWX036JfgId8j OWeiH/FaUKi2RVFh3Pyw+G2yWynvZg1sMk/4Yz4HUwL3mdDXAR8pdidzVKsAtwzlRwmG yl1w== X-Forwarded-Encrypted: i=1; AJvYcCXsm6NXvZbqv1MEEK0C4oDIRfl+8GF+fxyELID7gcLsH/wVwVGzyODy3S8ja8q6wYtXS8MMgqoHsSJRmOwY1ymgLpZ+PYnDFEwoyz0o/tDsZJ56dmuoEXIsxrkN0DNOj6UlPiVP2UWQUKj4nLA= X-Gm-Message-State: AOJu0YyK7ib+uaDVwRSDJOQkMGTkyIoBhgVN+brAeGMoOLaYEmzQVv/0 orrROYZ1/CHZ3hkEjXF+4azc7evtId5Hh7KpmfisXdB+FJ63hyaJ X-Received: by 2002:a05:6808:3946:b0:3c7:2607:c541 with SMTP id en6-20020a056808394600b003c72607c541mr531525oib.13.1713906716541; Tue, 23 Apr 2024 14:11:56 -0700 (PDT) Received: from fauth1-smtp.messagingengine.com (fauth1-smtp.messagingengine.com. [103.168.172.200]) by smtp.gmail.com with ESMTPSA id ez4-20020ad45904000000b00690c77505bdsm4599305qvb.37.2024.04.23.14.11.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 14:11:55 -0700 (PDT) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfauth.nyi.internal (Postfix) with ESMTP id 4C93F1200032; Tue, 23 Apr 2024 17:11:27 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Tue, 23 Apr 2024 17:11:27 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudeluddgudeitdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpeeuohhq uhhnucfhvghnghcuoegsohhquhhnrdhfvghnghesghhmrghilhdrtghomheqnecuggftrf grthhtvghrnhephfetvdfgtdeukedvkeeiteeiteejieehvdetheduudejvdektdekfeeg vddvhedtnecuffhomhgrihhnpehkvghrnhgvlhdrohhrghenucevlhhushhtvghrufhiii gvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegsohhquhhnodhmvghsmhhtphgruhht hhhpvghrshhonhgrlhhithihqdeiledvgeehtdeigedqudejjeekheehhedvqdgsohhquh hnrdhfvghngheppehgmhgrihhlrdgtohhmsehfihigmhgvrdhnrghmvg X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 23 Apr 2024 17:11:26 -0400 (EDT) Date: Tue, 23 Apr 2024 14:11:22 -0700 From: Boqun Feng To: Thomas Gleixner , Miguel Ojeda Cc: John Stultz , Stephen Boyd , Alex Gaynor , Wedson Almeida Filho , Gary Guo , bjorn3_gh@protonmail.com, Benno Lossin , Andreas Hindborg , Alice Ryhl , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Kees Cook Subject: Re: [PATCH 2/2] rust: time: Use wrapping_sub() for Ktime::sub() Message-ID: References: <20240411230801.1504496-1-boqun.feng@gmail.com> <20240411230801.1504496-3-boqun.feng@gmail.com> 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: <20240411230801.1504496-3-boqun.feng@gmail.com> On Thu, Apr 11, 2024 at 04:08:01PM -0700, Boqun Feng wrote: > Currently since Rust code is compiled with "-Coverflow-checks=y", so a > normal substraction may be compiled as an overflow checking and panic > if overflow happens: > > subq %rsi, %rdi > jo .LBB0_2 > movq %rdi, %rax > retq > .LBB0_2: > pushq %rax > leaq str.0(%rip), %rdi > leaq .L__unnamed_1(%rip), %rdx > movl $33, %esi > callq *core::panicking::panic::h59297120e85ea178@GOTPCREL(%rip) > > although overflow detection is nice to have, however this makes > `Ktime::sub()` behave differently than `ktime_sub()`, moreover it's not > clear that the overflow checking is helpful, since for example, the > current binder usage[1] doesn't have the checking. > Ping. Thomas, John and Stepthen. Could you take a look at this, and the discussion between Miguel and me? The key question is the behavior when ktime_sub() hits a overflow, I think. Thanks! (Cc Kees as well) Regards, Boqun > Therefore make `Ktime::sub()` have the same semantics as `ktime_sub()`: > overflow behaves like 2s-complement wrapping sub. > > Link: https://lore.kernel.org/lkml/5ac8c0d09392290be789423f0dd78a520b830fab.1682333709.git.zhangchuang3@xiaomi.com/ [1] > Signed-off-by: Boqun Feng > --- > rust/kernel/time.rs | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/rust/kernel/time.rs b/rust/kernel/time.rs > index e3bb5e89f88d..3cb15d3079f4 100644 > --- a/rust/kernel/time.rs > +++ b/rust/kernel/time.rs > @@ -77,7 +77,9 @@ impl core::ops::Sub for Ktime { > #[inline] > fn sub(self, other: Ktime) -> Ktime { > Self { > - inner: self.inner - other.inner, > + // Mirrors `ktime_sub()`, kernel defines signed overflow to behave like 2s-complement, > + // hence `wrapping_sub()` is used. > + inner: self.inner.wrapping_sub(other.inner), > } > } > } > -- > 2.44.0 >