From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.179 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796198601; b=1OE2elXmMbPjPdXdCi+z0Jf9Eyz6XycAvVJpKljVars1PvS8FmtdoqXNv1RWgv+cRKIL CVe0qWLPyvVi2VQN7xhetdR7jXKYSYnU3jEe0rinwvbftX9g++UmxGWjzoYyV/sZoLTui wMtJvGkKe7q73mAgNhMqMxOVgW4wHcJHmc9oH4IOaBbLlXFtuJOCicMxmyx8DJU5ceELx xTxgMMhJPgc+c88lv1zbwtDuTn73UhH9U1/Qi2q4i1rjYORtozSm+qsRVDqIrsmQFD87I 52A+o7LqTu1QgkafZeoVWlqo5Ap57R7zahkZuY5S3YlX02g6HXcMa7rLfuLxN0bO97w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796198601; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=i43716M8STXZvL+/EvQu4Zeq1Io5NuMh1E5mkREiZUw=; b=1SO8kuKBeAoUt9zRAoueZr4KkSZiKvfqhT6lBI7U1z4zpuE60QQn5yFgRzefTCd+e8pF sdOfr5AJOmPfIq/gtw936FNwrlZ41yipNh401cDxMg5tz3SR7GC6Gg70T+4FqmBvoll7v efzc9x92QbRsD4BKrl0Zcny2+IW0kviSRQBAOLibJiAx4sT8h+SEzwjMrcb7MN9QRqh8f FShk+JRedHqUWQ5eUqpS7KTH+4jiBga5TPbDM1D8B62mkF4/kSrqQiVEKLjUD+tTsbc4/ BOSQfuz4ti5LusxWpyR9UFoVd3hb2FI2HXV0laoEAWE3iHmx+/NwO0gZ9BlTmNTLHDw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=RyNLtesc; arc=none smtp.remote-ip=209.85.214.179 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 45F32606A327 for ; Wed, 2 Dec 2026 08:03:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 45F32606A327 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=RyNLtesc Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-2f04bea9a93so111154185ad.3 for ; Wed, 02 Dec 2026 00:03:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796198600; x=1796803400; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=i43716M8STXZvL+/EvQu4Zeq1Io5NuMh1E5mkREiZUw=; b=RyNLtescW+o4AwmZ0fHj55jv2LODYVKObG8PSHDd9uV6G1r5RLn4FbbBcriRHXl2XD pKmxU+IYK+eHrt9G7vD0/YexqYZGazsK7OQnV1x1RaqnCcchLF4O1ntzwYVNNdtVPuX7 KCisr7CTvOlIaFdXXCxmAC1H4l+bf1Lfq/7+AXuUzLfel044fJHzRDfbmKkTqnSCPc+o cBfD7AD/7ZzpYzr+p19Fsou7EAVaTB+KbHNymO0tMEtOMZzoRH7nwwy2Gnb58hkRHbLa BfUo1GSfYLVE2+K78pwQ9qWP7GC6gPhT/kQVbGRE+YU/Q1/LnHL6PJm7mCoOYj6g19bH 3bEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796198600; x=1796803400; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=i43716M8STXZvL+/EvQu4Zeq1Io5NuMh1E5mkREiZUw=; b=tw2S4COHdTHkMh/iYk0wC4v3Yf8uGtnzBj15a4PqB6aSUrYg6y7Dto5tv6+f/Kfoy5 KjEdfK0zgONc0vif31ySwbAB3X712BzdSzmhoOZa/0yECAVgMtAc1yJxVYoycAfB+TTe K2x8lvrFSf/SxZviCYvNQieFJVKu/8l6S/bIeelkn5KVd/BFROzkRhG4dk/PrCebgj/q KLkFix372fEtyolrgM7cwA7DkMhf7Qczk6dWuPH+pyN5sLVy3F+hu49OTcN2Cm9J+vzq mkAWnBBH9vRejuW+StYdMX6iR94tvqvMtIEOhMcPpHfyzy3IDb5cwYOrvN/o3Uab3RWE cX9w== X-Forwarded-Encrypted: i=1; AL+hErHaGjOXIAMX7OM1T+UkoIT86s1tYygECwMqs/d6LI+bUmxrfOkjrKEBA1xnrDVZE/n4wKVSzZHtHhpGKltGgw==@vger.kernel.org X-Gm-Message-State: APuU4Z8tXAvYwZSwY6V3XgFYOC08IoHgcFjCLc6lub3y8pe8+s3y7SHX UeeaW1K9M6BCcP7KQWFL91AP3Hh5PopS/nL5btPFNyQeqTfU0LHmdjwF X-Gm-Gg: AZFdTZflUhgo1Q+FP3DsruFCUVOWzlU8vo5+jJyIK2tVfba9ZLe6dELCElYaH3GDFh1 /Cs+OD57NNmYCdBtvqDStJRCPtNv4KGIXhqbkpZf7Fteg7YJep9X7Za1bNPYbeaWed5eCgYDyCb AiULynL6RHG+i2ku1/VqkU/kie4ESlxkgcOxyWeN3OASuILpdCEkp08K8UmJbe+HmUr4RCM5jcK 610v4OQITDNNVDbcxXSbD2N3q98/C6Kax8cp7o5T0RqUHyZnDrvrvkJ7Y+xGFjU7Vm2AB2O5BkL B5pTDnCPP6wa9WfPTxQyrXfuml0xRx61vQ8D5M7qv44QoOF7Df3YHRtvTElN6qlLaTrYQDHFTiE LBVatfScO3u1jFcS40toDcj5XZ9NKkyCkHmLk5JYRmfRFYuI5JlUfNhp9NWxPpZsg+T/RxKKaXs JTPPF3F5SUnz+RB+Snr5TbBVRkhVYaxkvRCWFhqMQS07vFiMjxP88CKnVgoYRFkPd0FqYZYJzLz R/vmLsiWvWcEnyzbdYQ3eF5hih9yujzgRwHiFyID99ZC9wu3tKIi7x7mWuA5MgSHQs9S8JgfmCT f3WGKKTnduE203lr34ydOlwLaTkuncim X-Received: by 2002:a17:903:2984:b0:2f0:257a:9add with SMTP id d9443c01a7336-2f03f215ad9mr412668095ad.38.1796198600248; Wed, 02 Dec 2026 00:03:20 -0800 (PST) Received: from ysq-QiTianM428-A376 ([111.201.209.250]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2f03f15663fsm195953135ad.76.2026.12.02.00.03.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 00:03:19 -0800 (PST) From: Franklin-Qi To: Andreas Hindborg Cc: Miguel Ojeda , Lyude Paul , Miguel Ojeda , Alice Ryhl , FUJITA Tomonori , Boqun Feng , Danilo Krummrich , rust-for-linux@vger.kernel.org Subject: Re: [PATCH] rust: time: keep Instant invariant when adding/subtracting Delta Date: Wed, 2 Dec 2026 16:03:06 +0800 Message-ID: <20261202080306.898547-1-yusq77@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <87mrqps4a2.fsf@t14s.mail-host-address-is-not-set> References: <179610727734.137620.3884652165779521586@gmail.com> <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-Transfer-Encoding: 8bit Hi Andreas, Miguel, Thanks for the review. On Tue, Dec 1, 2026 at 11:07 AM Andreas Hindborg wrote: > could you elaborate pros/cons wrt. clamping instead of panicking here? Unconditional panic keeps the invariant simple to reason about, but it turns an out-of-range Delta into a kernel crash even in configurations where plain integer arithmetic would not panic. Clamping + warn_once keeps the kernel running and the invariant intact, at the cost of silently changing the value (hence the warning). > We could also consider panic if overflow checks enabled and clamp + > warn if not. But this may be too confusing? I agree with Miguel that this hybrid is consistent with the existing behaviour (the panic under CONFIG_RUST_OVERFLOW_CHECKS is not new), so I went with it in v2, which I'm sending in a separate thread shortly: - CONFIG_RUST_OVERFLOW_CHECKS=y: panic when the result overflows or is negative, as before. - Otherwise: saturating_add()/saturating_sub(), a negative result is clamped to 0 with a pr_warn_once!(), and a result past KTIME_MAX saturates to KTIME_MAX (instead of wrapping and then being clamped to 0). - The panic/clamp conditions are documented in the rustdoc. I also checked it in QEMU with a small test module: with overflow checks disabled the out-of-range cases are clamped/saturated and in-range arithmetic is unchanged (without the patch the same cases yield an out-of-range Instant); with overflow checks enabled they panic as before. Best regards, Franklin