Received: by 2002:ab2:7407:0:b0:1f4:b336:87c4 with SMTP id e7csp269610lqn; Fri, 12 Apr 2024 00:15:06 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXfxiRkocOBQaMWFHqL146OCxvsRg/joIZJmFQLPVpkrzzs+WvgwF3OAZMjvuE/L0zBIG5GdqSNMmdgjR1FoSP8fhGwneuyrZQo7AmgCQ== X-Google-Smtp-Source: AGHT+IHlF7Sn2HVAF1JMkbivweNBVcCq3SycWIvlqJbhneQRhuEY8IWX1/kTOVs8aUfJm1F2Htet X-Received: by 2002:ad4:55f3:0:b0:69b:fdb:b426 with SMTP id bu19-20020ad455f3000000b0069b0fdbb426mr2995894qvb.10.1712906106148; Fri, 12 Apr 2024 00:15:06 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712906106; cv=pass; d=google.com; s=arc-20160816; b=xWWsPCMY45wgGkje2/jcUuiSbMF3zs3j0hTt1q/X6nhZzkxqtv3ZHDNU5GtokHzy37 uEpW/N2paRT2zP+2Qy2XNU1Nm2XefzIiZDbEIgHDkcomicZLSae2NRDJIrx/tvz33aAB BHJGrX20ynuTLjPBPL2WWOvwjIaurMO/WtiiUTO+ArMujuOJ325yMxhDqCN3SMKlyeFU 8pDK5Oa7xleu4Ben4kQtuOauTmI8/sPIbIFBzi9zXmRWGsdjEqMvNXYFxhp8PJcFHaQr ELQHCYGLVVuiVksvx8oBDaC/b5L5noCoqbs3G1qI95/BIk2YoFqGoteUri4dfx0vpIll vWZg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=MxjuXSodxN0WQ8ThAopn8ROQU7DctnnRsgD3NHjlTsY=; fh=o03xtfs0PfYU5ftxVdYeXYO1D5jmmV9Pk0GHDfQga+Y=; b=RyIA3phq17OsXEszxs94INdm8jSkuLQ7r0k4/IoPGVzIJXd9TFOB1S8jEgyXVS6XyW /CHUN+wfMFyS+V6MZvWJh1PWUXOTbnwU/0/jqWjMyQwMPFnBMqyOLc4BZHxDYzrT9ra0 VaKubkVcFzi+UjNWfA7RgJrH5MBeqE1UV4kxSxVBDYdK/XGS+TR2WFh7t/FYAbr1j+7s J+FJZcObmvmBP2PfjKfUpLAkkd9Gxy6C8NuOw7LUvEjyNGd1p2KFmSFzfFAtHsGvcYqd oKtqyT6xUabsaU1s+Aj/7LRf88m4Zs42eJiVeZUU8KypWcAgJfo9XxPafAERPfPvOEzn HPzg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="OT9uW/3l"; 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-142121-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142121-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. [147.75.199.223]) by mx.google.com with ESMTPS id mg7-20020a056214560700b0069b31abd287si3142723qvb.363.2024.04.12.00.15.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 00:15:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-142121-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="OT9uW/3l"; 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-142121-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142121-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 DBA841C22450 for ; Fri, 12 Apr 2024 07:15:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 469EF48CF0; Fri, 12 Apr 2024 07:14:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OT9uW/3l" Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) (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 3EDA046544; Fri, 12 Apr 2024 07:14:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712906097; cv=none; b=WmuODTOmYDywhBdDIjFIjr/ivR12FHdHzfvVPm+B458uO4R3YPGIgDhYGf1EVgtWQ26c0K6OSWmIPpy5HiEMP7CG6n7+GDc7BA1Mos90hBkttADNkPXDZBUPUt9UF7oFKcTqXdKKMb87eAw21oAGa0v7mrpZV/VYkTtSCyND4Io= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712906097; c=relaxed/simple; bh=MxjuXSodxN0WQ8ThAopn8ROQU7DctnnRsgD3NHjlTsY=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=S7Plc8rUwMESOFG0/vMH9iHArsA9Lv7k3/q+2bIBPeSPvDuG/MKvamYerWq5f8kyQH9ZXjvEMq7rl6Xhj2/YxsWCPBEolVIan72qdjGfnvcSjekMMGkJjEII7GsyEDATisGLGqLYCtp2QYf7vwVqrRteqdNvQAK6UIxChL5cNZg= 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=OT9uW/3l; arc=none smtp.client-ip=209.85.216.50 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-pj1-f50.google.com with SMTP id 98e67ed59e1d1-2a2d248a2e1so1145617a91.0; Fri, 12 Apr 2024 00:14:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712906095; x=1713510895; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=MxjuXSodxN0WQ8ThAopn8ROQU7DctnnRsgD3NHjlTsY=; b=OT9uW/3liF5k0D8AB8st/Y9QGc2nHpOwuk8/CkYs/dHq16WcstQF3GhnNCgRqD/y9F gVvlz/EVUoZTqIirkhoOjFYwbIT2KmIFLJeOLNvok2FNxhzxDdssOer4+bWXPTYCOlhe fxbI1V0C+sAUodQNNGn49q/m7sloop8khhqNvjcmciM5aRC7EfCKRZke/M9zaOErAM0u EyOk0HzQoNz/lPGVMoJMl3eaYF5PrcFJxdPLJtM6tkaj9se52RZNFyeDUvdL2Sr6s0LH 43xxKi4Ve/h6DT63lXHbenEgyxD2IjsnteNBm/x1lYD3m4rRkk7H5nQmgwPzi3nsTIcD o92Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712906095; x=1713510895; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MxjuXSodxN0WQ8ThAopn8ROQU7DctnnRsgD3NHjlTsY=; b=AGOXZONGMtf1RWNtNNn9ezHGHKdTaN4g231pupStj+7gbULWJH/7rKxUu04P/TlaL0 lvl7mbQxZKiTrVqHTYH543H5jIik0qyNRw70sr9OCmhZG0mzrmFA41nFvQNNvgcoVs04 81CYUlyRIF09fhoSbkK59MtJCw/Nz7b6jBNssnkh60oWx60uRjkreVTa5KZ9WqqaaD1o Q3Gtrx0FBkjeWnjP1o9pwu7fLYAKkmCrox9noq42Zrg6Jt0Z9ISf80U3agmWPwegO7zm mcndv+AmoRvtdjBwqQi17Aq8jRa3cxtjnXH0ZyR1wtghc2ss20/5PZGzzAOAKYrwUqAP 6Y5w== X-Forwarded-Encrypted: i=1; AJvYcCVrC2SdM64V8pxFPmLjk2x0IrlGEDE3C+EGee8a9CKwFWfYm4MjomwlHmp/Je/1CpHE4IZ9Xn6d9hsSNXxkPTbluBCJ9g9xzpeL4iLm3S0OWBSJShBW9DPFxKZaUfT1c5LDFLCOwTpIK74gu2A= X-Gm-Message-State: AOJu0YzhWGxIngYXraaWLCK+M6qTNvILMF1Ztm6qhP75s3DDs8YZWD6i gn9Gj0dVozGUrHKJ+qmv/kVJ4/BZ6Fbdj0C33OSM8F7laG4r8wFR0DWpmKdvs+1TqhGlfHhSi4B zwplE9rtm1hgKGqbR0PQ7lF8dUVI66+aP X-Received: by 2002:a17:90a:38c6:b0:2a4:6ce7:37ad with SMTP id x64-20020a17090a38c600b002a46ce737admr2659214pjb.5.1712906095465; Fri, 12 Apr 2024 00:14:55 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240411230801.1504496-1-boqun.feng@gmail.com> <20240411230801.1504496-3-boqun.feng@gmail.com> In-Reply-To: <20240411230801.1504496-3-boqun.feng@gmail.com> From: Miguel Ojeda Date: Fri, 12 Apr 2024 09:14:03 +0200 Message-ID: Subject: Re: [PATCH 2/2] rust: time: Use wrapping_sub() for Ktime::sub() To: Boqun Feng Cc: Thomas Gleixner , 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Apr 12, 2024 at 1:08=E2=80=AFAM Boqun Feng w= rote: > > Currently since Rust code is compiled with "-Coverflow-checks=3Dy", so a Nit: it is enabled by default, but configurable (`CONFIG_RUST_OVERFLOW_CHEC= KS`). > 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. > > Therefore make `Ktime::sub()` have the same semantics as `ktime_sub()`: > overflow behaves like 2s-complement wrapping sub. If `ktime_sub()`'s callers rely on wrapping in some cases, then an alternative we should consider is having a method for explicitly wrapping, like the integers. This would allow callers to decide and it would make the expected semantics clear since the beginning (which is the easiest time to add this kind of thing) for Rust code. Otherwise, I agree we should at least document the preconditions clearly. Having said that, I see a `ktime_add_unsafe()` too, which was added due to a UBSAN report for `ktime_add()` in commit 979515c56458 ("time: Avoid undefined behaviour in ktime_add_safe()"). There is also a private `ktime_add_safe()` too, which is a saturating one. So, given that, can callers actually rely on wrapping for these functions, or not? The documentation on the C side could perhaps be clarified here (including the mention of UB in `ktime_add_unsafe()` -- we use `-fno-strict-overflow`) and perhaps using the `wrapping_*()` C functions too. In addition, Binder calls `ktime_ms_delta()`, not `ktime_sub()`, right? In that case the arguments are called `later` and `earlier`, perhaps those have a different expectation even if `ktime_sub()` is allowed to overflow and thus it would make sense to check in that function only instead? (and document accordingly) Thanks! Cheers, Miguel