Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp2068417lqo; Mon, 13 May 2024 07:06:42 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXPpEyi1WOuSq252yT9jIUUYxP65bGKeB1KhH/fgk90C13IPi2J/DP84xD58iHR45aB7iBwZX70YmELMAcLhs4ToLB/jLNN0ECyfUeM/A== X-Google-Smtp-Source: AGHT+IH+Q286tvi0s2WA8f56vZlKGA30QanV9F8ejDe+KGowZjWhpnQD5HCKpVTcDz04G/B3d5oh X-Received: by 2002:a0c:9c07:0:b0:6a0:ef09:dbaf with SMTP id 6a1803df08f44-6a15cbf6d27mr209539786d6.19.1715609202497; Mon, 13 May 2024 07:06:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715609202; cv=pass; d=google.com; s=arc-20160816; b=LRdupVGdweUUsv6KXdz5lQaKfYbwaCMSPxa4WyBbnvweAnafO9/4zbEBeWXc4OPTGw K/Jk+U91mPDnxhthvTNe5CL1TbqQRxg6q1rhqvb/3hoyUJ1pBxntZq2A0F31ZZJCHx1+ ffEWmCTazUPu+xFRilb75PCdWMU3Dk5ZMcb0xiTrsaPlLU/h4OlE/A6uYtNaxMrGTxEN axc7ktryHQjElyRaX1eDm27xSRMa6NI57nQJ4DVWoMwM/VZgGZjjXAWwqAqGYgsaKrBV H02r+PvcD1J0HYbD0Gnw38QmOf/y1JBiGzxncEwZojtqQEVblDVP8zvHS5e//PfF8Xaz O0pw== 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=97qvlrEWAPmxPYorX7UQV2kS8NfIOzG0eHj66y0TAo4=; fh=7Ti/8R+cPAxwQSa/Ml/ZOJ+Vvlc91He/vmNnUsFw81M=; b=1IRc+LkeLDat/iWAZgW0MWmvY8qnp2orhgpeR9CNU5nwJ+WqeqhaV8F26af3Is5JzQ qtWSZGIFtDs+MnGSRJui76iBd/bfVgvIk5EyVtq5vh/qbV+qEBDevHcywUqFWnx/SH7I 2I2UUAe4Amh/osk2YQl5mJPjdDugz7uh0UJxUx0HZnn/uqSVU3u30E5RNHG3x+actilj 4Zifs7UEHkJpJbpx7foC/KoioQHMWj33yrnQKFmnE04EH53/0TCmT9tnzgKVEzHsR7GC hMA8azU/ic8C0T3Eof/pFW5vxGPW3Ikqj0iwG/+QLfeByeFvh9VrU2wdK2WJrZqCcF7f /SwA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=MDnREElo; 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-177669-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-177669-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 6a1803df08f44-6a15f1ff14dsi96908056d6.148.2024.05.13.07.06.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 May 2024 07:06:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-177669-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=MDnREElo; 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-177669-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-177669-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 DD3061C2116E for ; Mon, 13 May 2024 14:06:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0BE33153828; Mon, 13 May 2024 14:06:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MDnREElo" Received: from mail-qk1-f169.google.com (mail-qk1-f169.google.com [209.85.222.169]) (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 A8BDA50279; Mon, 13 May 2024 14:06:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715609193; cv=none; b=SzwPi+yhdtw7jJM2ZkIp7ErMwGM3Ex+8ueeRiZYgm8G0JZeeJw/lps0iretTubHeijXXoc2OnqvCc/NyH3JNncbgI9ZNnr6sE59YT7bWHgiZ2eBxfkCCW5S7qEpYmWSgjvNhJ2YGiIQd/t06WK6GSv6/l3RSN6SOTBgPWy36ekA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715609193; c=relaxed/simple; bh=SxnE7rnuwXBi3EDidJwQErZKklISfFQ7ftxTwHnECuw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=snCVkR8JvT7vVEEKpKX2ZWRZzlKxrReVe708w1unVn1StWkHfu+8Z8jaNj3zTjXhv71p08jWaGtN6KmJWOAJAoMSAr2efqigup8JReOwiTJEr8lqVZDDMiLVYSJRjkkWcQmLz7i053nbm1IyzuMqzpWUujqhwXGH+9SYOTZTcw8= 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=MDnREElo; arc=none smtp.client-ip=209.85.222.169 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-qk1-f169.google.com with SMTP id af79cd13be357-792c7704e09so283321385a.1; Mon, 13 May 2024 07:06:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715609190; x=1716213990; 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=97qvlrEWAPmxPYorX7UQV2kS8NfIOzG0eHj66y0TAo4=; b=MDnREEloq4zsNQVJq2DJJAM63gmZFO240iTiYhQb/cppBcbaRVL32jBgo0QPVklonl bG6tx236JHycDZj1emQMFFub1KIlbLsMHNTMoR9cHvr6k0/OG+7HYlZ+W9qzHoNUAe24 tyTU14PLqT1WGAUMcDdoac/mD9t7Q+bckZ9UtHhdYMGzyotRTos+Byy7043jB94cuOC/ dYvfVRgDTtOl4vh7xdSFMgdFjD/+Ik1OqbKtrkB5hSQJV6tgEU5kUTD+x1VaSimIT9lD rmx211EtI70U6n8mgRRLdb0Kc9RS+hGcpHnpizD032mS0VeoYXvWJX4rJLnvlTuEAU+q +Vxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715609190; x=1716213990; 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=97qvlrEWAPmxPYorX7UQV2kS8NfIOzG0eHj66y0TAo4=; b=lsgdBf1kRlpiXeUfozUp88UIujhre05ti7eNvY38knkNXohS7T+rvDb7kRBWZVMbt5 vMwxjgP/e2jBiyW9p7Cp9vH09rsfv0hA1J5K+ijOzTmMWRwedloYxJrwgYfzIy5GUbfj kpFdHn9S/VRE9/Nq94Rb7KqFoIO2V2rkWz0vliMEA31p1swDd0vHuiwCzU3Dz6Advinw aRju6J1si9ll+p/rXFI+uCPjDOLlEmnV6itg1a82YYEAA2rxBgj80n0FcBv1Y/lRm7Zz COIaspGBHwa7rIk0qwImMQEFUTJVPKocxuna1myuU/hns7B3rs9RmZlJHJ8tp1C6HiX1 9hIw== X-Forwarded-Encrypted: i=1; AJvYcCW0vPuRng+/Eht8OPNvUrAUi0k2vwgYOiwiqMsnQLm+s6WK9lKWbVxWUiRMZR08EyWmTv6q0CWSZhK14Mt1RsVacjBva8Bk9b511ShbJeduYMDykh3onkmK97NpfPx2RwxpbBpAuZbD7QigHOc= X-Gm-Message-State: AOJu0YxbZQm4RxgPv++W+F//n6LRs95xKU5oA94qwd/G6MPJEX9YkLUK cF7n5ZXEYAR18jkm89ZLsgQYWWheXJsHfmbjRtYWf1AbgUJmwcwg X-Received: by 2002:a05:620a:4448:b0:790:9dad:ec52 with SMTP id af79cd13be357-792bbdd9cfemr2314253385a.13.1715609190525; Mon, 13 May 2024 07:06:30 -0700 (PDT) Received: from fauth2-smtp.messagingengine.com (fauth2-smtp.messagingengine.com. [103.168.172.201]) by smtp.gmail.com with ESMTPSA id af79cd13be357-792bf2fc3dbsm458274685a.96.2024.05.13.07.06.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 May 2024 07:06:29 -0700 (PDT) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfauth.nyi.internal (Postfix) with ESMTP id 0FBE11200066; Mon, 13 May 2024 10:06:29 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Mon, 13 May 2024 10:06:29 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdeggedgjedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvdenucfhrhhomhepuehoqhhu nhcuhfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrihhlrdgtohhmqeenucggtffrrg htthgvrhhnpeejiefhtdeuvdegvddtudffgfegfeehgfdtiedvveevleevhfekhefftdek ieehvdenucffohhmrghinheprhhushhtqdhlrghnghdrohhrghenucevlhhushhtvghruf hiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegsohhquhhnodhmvghsmhhtphgr uhhthhhpvghrshhonhgrlhhithihqdeiledvgeehtdeigedqudejjeekheehhedvqdgsoh hquhhnrdhfvghngheppehgmhgrihhlrdgtohhmsehfihigmhgvrdhnrghmvg X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 13 May 2024 10:06:28 -0400 (EDT) Date: Mon, 13 May 2024 07:06:19 -0700 From: Boqun Feng To: Thomas Gleixner Cc: Miguel Ojeda , 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: <87cypvnpwn.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: <87cypvnpwn.ffs@tglx> On Thu, May 09, 2024 at 02:14:16PM +0200, Thomas Gleixner wrote: > On Tue, Apr 23 2024 at 14:11, Boqun Feng wrote: > > 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! > > In principle ktime_sub() should not overflow for regular use cases. > > If the binder example overflows the substraction, then something is > seriously wrong. Though in that case as it's only for debug purposes > panicing would be totally counter productive. A warning might be > appropriate though. > Thanks! Looks to me, a reasonable implementation would be calling `overflowing_sub`[1] and print a warning if overflow happens: let (ret, overflow) = self.inner.overflowing_sub(other.inner); if overflow { pr_err!("Overflow on Ktime: {} - {}\n", self.inner, other.inner); } return ret; I will use this as a new version for more reviews. [1]: https://doc.rust-lang.org/std/primitive.i64.html#method.overflowing_sub Regards, Boqun > Thanks, > > tglx > >