Received: by 2002:ab2:7407:0:b0:1f4:b336:87c4 with SMTP id e7csp114344lqn; Thu, 11 Apr 2024 16:08:46 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXGdL5OdPkW2oWNOz4pjVaZqx5mYCBBfJ7v8z/Gvczr5tSeSaxxfiUCGjweS53eJ7DZ9gOm0uhAXPAh1FY9JNNU/NlLZHZrC72ydm1GxQ== X-Google-Smtp-Source: AGHT+IEffiiEFXOfEcSdmcg5EomX8xw2eMBNk3Fm9rRpQFua53/umCPavBuchn9giark0jjSjRn2 X-Received: by 2002:a17:906:b298:b0:a4e:2b9e:5b73 with SMTP id q24-20020a170906b29800b00a4e2b9e5b73mr529565ejz.49.1712876926717; Thu, 11 Apr 2024 16:08:46 -0700 (PDT) Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id dm7-20020a170907948700b00a52277db982si785895ejc.462.2024.04.11.16.08.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 16:08:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-141698-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=gc0LHZjH; arc=fail (body hash mismatch); spf=pass (google.com: domain of linux-kernel+bounces-141698-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-141698-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (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 am.mirrors.kernel.org (Postfix) with ESMTPS id 25D391F23260 for ; Thu, 11 Apr 2024 23:08:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 10B5E4AEDF; Thu, 11 Apr 2024 23:08:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gc0LHZjH" Received: from mail-qt1-f179.google.com (mail-qt1-f179.google.com [209.85.160.179]) (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 B328D47F51; Thu, 11 Apr 2024 23:08:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712876894; cv=none; b=DQUTwoZdPq4Q/pl5tYqKDZ2d2zvbUe5/H+WSJHI8xWpqwCDYR9n74dMVGND9qQx/wnQXnf/hLxjmsfxdkka7LCYj/eCkEROFIDanVSPTAXdtc3gThOi5EaF9JRN9CpvSdHrKKTsUiBOZN38El9aUebTGKTMXw5Ey+eRnClXjYzE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712876894; c=relaxed/simple; bh=YGi08gU0thy2xo5L/Jd2ML51rJYD3cHypCbeOJyorH8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GtTHJL4IZ/mMEQiR1w9O8wDt3p+JK2B0ysnkonvbNEv2etGUzE1l0GVA0VSfCOqLCqM+V3NmRHQCHLHPC5K9k6CEW2bCAr3JKIGMBdrdmlo2eIXUnrv05HKyhtNGqPFmk8DUzaNHgU4hp1FpZycinH6azm8ovaz4iUvnTx4nIl4= 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=gc0LHZjH; arc=none smtp.client-ip=209.85.160.179 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-qt1-f179.google.com with SMTP id d75a77b69052e-434832aa162so1246851cf.1; Thu, 11 Apr 2024 16:08:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712876891; x=1713481691; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:feedback-id:from:to:cc:subject :date:message-id:reply-to; bh=1cp6Y65O98WYlbmp5ogw9D72luMzjnNhAIcpF72RIPQ=; b=gc0LHZjHgdfkz3zXH1No0O7X+blRnls3JAsJtxUo8cHZGuOTjQSbnVp5x5Xz6oHbRV 0NVmKrgf8s567991xYwlQXrHR2EO0AAQWlgLc3RIjea2ndIcy8sQ06f2M+srnNIDabtQ KmVkhm0qKIHiAXcY7Gg7DdTF7OItpkuP/ZzOtbInB22LCZC0LRyZEysEIniCcS5CW3x0 8tzLkdDWnnfBbiRYdU4pOyaGMMZNepk7AkFlSy2s9kFXxk1JBQbpGp04d8LK9SZtfloz 7y2yg0eZIVt8AgZF6mSbjQbst1wyVuFOZ7PHwRmSsbDg/tCBta8pLlQ5O0ReJUE+6kkA Gt6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712876891; x=1713481691; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:feedback-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=1cp6Y65O98WYlbmp5ogw9D72luMzjnNhAIcpF72RIPQ=; b=Q0iM5PXTqbEM5vePQW4Lm6pjsXzciKDmydxs9ad/BfXpyq8vbsihB6r5VSuZfXouvT Wyl3svPLQoOVN6h3RUjf1ASNvLX6CtxUur6tdoTO4nwtnsU6rBT/Y9uRIpj07V32HkY0 +DlQbifEULsITgEQdi7md5AOLzBUJgmUZD+nphNQEVR5AbVb7riy5od5NaFQBDepIP1e uKaZScZNug+K/uKqHrMMsWvaD3nTCO2y+cceNBMckbt3BdHL0i8XZRSxywhHxxHQ75bC Z/QuGeZrtQgg4jizRQj6aV6eqnTo4Rt1q8F4M+BRATNJDAx7pEVdzVjXaQ0HX7TMAOyy KXGw== X-Forwarded-Encrypted: i=1; AJvYcCV//Hda/nqd2bW0n/IBgvwky3f6GQRcrrTmhveIhcI+91m+GIevINds7dUoF1uS/+L19GsUZVm6bQvoqFZ5M4BGw27p1i2LD/smMqUhZylLIFk1Vi/LIrOCj2hE81G1A6S/YrZleW+WTX/J1gs= X-Gm-Message-State: AOJu0YyPwH94mARV4qvQOXX6+GgsERF0PXkAHLej0bAbwwHSihhfnM9A /F9iR2PEbiDqEhgMd9bIU25ebmKpbqLlgeGRybSNNfXRMl8XgNZjlf9fmg== X-Received: by 2002:a05:622a:11d3:b0:434:3c23:d84b with SMTP id n19-20020a05622a11d300b004343c23d84bmr1201401qtk.31.1712876891595; Thu, 11 Apr 2024 16:08:11 -0700 (PDT) Received: from fauth1-smtp.messagingengine.com (fauth1-smtp.messagingengine.com. [103.168.172.200]) by smtp.gmail.com with ESMTPSA id d19-20020ac86693000000b00434f6c1458bsm1477812qtp.17.2024.04.11.16.08.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 16:08:11 -0700 (PDT) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfauth.nyi.internal (Postfix) with ESMTP id 8CD801200066; Thu, 11 Apr 2024 19:08:10 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Thu, 11 Apr 2024 19:08:10 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudehledgudelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepuehoqhhu nhcuhfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrihhlrdgtohhmqeenucggtffrrg htthgvrhhnpefghfffvefhhfdvgfejgfekvdelgfekgeevueehlefhiedvgeffjefgteeu gfehieenucffohhmrghinhepkhgvrhhnvghlrdhorhhgnecuvehluhhsthgvrhfuihiivg eptdenucfrrghrrghmpehmrghilhhfrhhomhepsghoqhhunhdomhgvshhmthhprghuthhh phgvrhhsohhnrghlihhthidqieelvdeghedtieegqddujeejkeehheehvddqsghoqhhunh drfhgvnhhgpeepghhmrghilhdrtghomhesfhhigihmvgdrnhgrmhgv X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 11 Apr 2024 19:08:10 -0400 (EDT) From: Boqun Feng To: Thomas Gleixner , Miguel Ojeda Cc: John Stultz , Stephen Boyd , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , bjorn3_gh@protonmail.com, Benno Lossin , Andreas Hindborg , Alice Ryhl , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] rust: time: Use wrapping_sub() for Ktime::sub() Date: Thu, 11 Apr 2024 16:08:01 -0700 Message-ID: <20240411230801.1504496-3-boqun.feng@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240411230801.1504496-1-boqun.feng@gmail.com> References: <20240411230801.1504496-1-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-Transfer-Encoding: 8bit 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. 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