Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796121367; b=QufLYmW4l3tnAAWR4W8OpalkoT+nVnmbFWDo0EatVDxtsqCeScUyo45xojLuRDH34GZp IiuYf/GzFEeJbehO2zRqTzGGwnJdQcOrkZ9QDfq8/vTbu6Br3UiYGZj21gMmpz/+qRtUN NDG9gpvtxdf+YttzDsE/iQJ1ugqwqWq2WLFcD6XcLOaAkBO3guM6EF7cgow6iBz4B0xOi CcWCHyggaIsVf02fc/DLtvvq/pZ8T2wknfjyJqrno2DQWlFUBy0N/nrst/AUDOn/SHgIR nmoBXwKu3M3Arq6IVP3GMexU+t92zaGBT1N/OEXU9ssXLej6FdFt+F/rxRmZ1K/rxvA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796121367; h=Received:DKIM-Signature:From:To:Cc:Subject:In-Reply-To:References: Date:Message-ID:MIME-Version:Content-Type; bh=46V3TE6FHpeELmWDSU5GHuM5gbN3QRNx7+LXlEUZw2E=; b=U0k8bDTo0cJjmgdWSfbqhkTzdBcjEBm2Dl3oFvv8iDm54ExZ5Evw0f5PWiJ8L2mG5RfU fjg9rCk30fG2if/aqbkthd/aHAJGfb4zoPFc0u56u5royhwDVphLMEODmmOukhob2/2MC W07COdy4k9W9PSaXj/hl6ikIr0yMmKhLc71BwQJQMuTOjLZO2Mbavl/lVhf3vva43tGUG 26VJg/c4WCZsF0PwTABYIC1lizBxNmYxyzpp8f2NpqLCfRhsDvopHhdCIP1zDXVnnWFt3 421LD/7Smsp9VVq0wCfyMe1rPGGSNP9sVs2JuWv7kjgWUNLGzDdI1JHSRPUuYmisuVg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=IGNulyjo; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 23578606A320; Tue, 1 Dec 2026 10:36:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=IGNulyjo Received: by smtp.kernel.org (Postfix) with ESMTPSA id A07D91F000C1; Tue, 1 Dec 2026 10:36:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796121366; bh=46V3TE6FHpeELmWDSU5GHuM5gbN3QRNx7+LXlEUZw2E=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=IGNulyjowNxmkyYzIi3jY4KeQFIdYoz4UzNmXBgi2PQL+j9uZLSP4Cfu8at12wMba L1O+GQvj2tSHxP6kr/TPuRNo1KwZhVgd9v8d2aqVW3t40me2ls2vQl4SXnYF6TZAEF JCXS/bwpX8hoWEbYyBfbg6vupwn0PHv5jXsdiBc9tWcUp+ulULglcypYZ3byFKMxr8 eKTjpinR1E35UowJyhlNFsNJJBIKUTTuHd8u2ZcxJdhc2HlGgNQoUzqiP6yF4WFaHm UMhLD61/gPKos8uwFo8hQdCcgBakjMSFJ3BgScNO0Cswd7OcDY191MQM08UoTGUYMg Qa+35lxyMQjuw== From: Andreas Hindborg To: Franklin-Qi , Lyude Paul , Miguel Ojeda , Alice Ryhl Cc: FUJITA Tomonori , Boqun Feng , Danilo Krummrich , rust-for-linux@vger.kernel.org, Thomas Gleixner , John Stultz , Stephen Boyd , Frederic Weisbecker , Anna-Maria Behnsen , Georgios Androutsopoulos , stable@vger.kernel.org Subject: Re: [PATCH] rust: time: keep Instant invariant when adding/subtracting Delta In-Reply-To: <179610727734.137620.3884652165779521586@gmail.com> References: <179610727734.137620.3884652165779521586@gmail.com> Date: Tue, 01 Dec 2026 11:07:17 +0100 Message-ID: <87mrqps4a2.fsf@t14s.mail-host-address-is-not-set> X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain "Franklin-Qi" writes: > Instant documents inner in 0..=KTIME_MAX, but Add/Sub only > asserted non-negativity under CONFIG_RUST_OVERFLOW_CHECKS. With checks > disabled, a negative result can be returned and later Instant-Instant > subtraction may no longer be overflow-safe. > > Always assert the result is non-negative, and document the panic in the > operators' rustdoc. > > Fixes: 22b65a40574e ("rust: time: Implement Add/Sub for Instant") > Cc: stable@vger.kernel.org > Reported-by: Georgios Androutsopoulos > Closes: https://github.com/Rust-for-Linux/linux/issues/1272 > Signed-off-by: Franklin-Qi > --- > Note: Per discussion on the GitHub issue with Miguel Ojeda, this uses an > unconditional assert to preserve the Instant invariant (not clamp + > warn_once), and documents the panic condition in the operators' rustdoc. I agree that allowing the invariant to be broken is wrong, but could you elaborate pros/cons wrt. clamping instead of panicking here? I am more in favor of clamp + warn_once, since it does not crash the kernel. We could also consider panic if overflow checks enabled and clamp + warn if not. But this may be too confusing? Best regards, Andreas Hindborg