Received: by 2002:ab2:7041:0:b0:1f4:bcc8:f211 with SMTP id x1csp160498lql; Fri, 12 Apr 2024 06:52:29 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWv7MXIFSnssGZucZTE2ZHQ6rVxAZWVGgJW5jNE7GHKqkGs5JdgJaf3diTl/RxkMm42gAc7Pkvr+w2dbGqtHZooFpJ74J2vrQrgdq2Zjg== X-Google-Smtp-Source: AGHT+IHlRZ2ZTfW0f3VUkyg0XqFWeaowhrcSLuhcCgfvDJZvNGP0FRNPxRnTSFS7jueto7MyvJtk X-Received: by 2002:a17:90b:fc5:b0:2a5:3637:1968 with SMTP id gd5-20020a17090b0fc500b002a536371968mr2831917pjb.9.1712929948753; Fri, 12 Apr 2024 06:52:28 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712929948; cv=pass; d=google.com; s=arc-20160816; b=C+XuRtyThKVLC2gaqAHYRW3emaM+7ZfeYjf6R32JVHaByr27DLO6agtf/OBPXr6cC5 SQvFIsSFUP7M80gAqeyMSxO4lPfksGeABsHEIO0hAa6/id7Re5S78CodSELi/gZmJTnb PMSPSVBo9Ln5fWBXmbC0N/ipmmnfzTdCtgCJfhB15QEHY2k6m+e6+fjm03c0h/YypfWs rJWcsCrgnc6VwJziwKR9KQQz2CHuxKTtczbHVXMYXo7JfkzdVKHFbm1D51jmL5OFvYHE m+Si6BsMgc5pQz86O1oFulXxMDcGU9pUAa4mm/8zWp8K0E034YjH1vfgT2bKfinwH9ZX MtgQ== 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=tJnR5552tR98GvdFl2I9gJzxKsxtaACk6KQyxfOH2CQ=; fh=ZA6HXeH/tfVoSkf0NHzt8YknbIbLXrExnkP1AHQkmvQ=; b=Tn4StcUckO79mWXe/0JQimHS78Y7juTFT39Eltw3I8I1YIfa/xOOr0KV+dCHPGihIn i/M1aq0fiWCbr6N4soGWNMS/O5AajgiZNqsUqQWXkU04/IgjHoGxFcesuXVZgLDAW5++ Yq3xoD/EIVdcEsWZmEInPHC4AcRI54UTWtaf+ap0T38mfwxdDrVIokUzhCmf5yWHec87 7/iwhC3Gs6kSIlawUDhcpKKe97a0EstRC5B9s5O+O3u/cQQmKJOO6O3p1bSn55VOgM8q ga350uF1dfMZm9SErzC/GSjn4+JZQMnXw6Nh8KBXP49OPP9zJZl8rtYttEWt1mYI2QLa akCQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="dphFY/ob"; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-142766-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142766-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id bx24-20020a17090af49800b0029ba20feef7si5398956pjb.188.2024.04.12.06.52.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 06:52:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-142766-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="dphFY/ob"; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-142766-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142766-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id B1B5E28312F for ; Fri, 12 Apr 2024 13:51:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C83EA85950; Fri, 12 Apr 2024 13:51:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="dphFY/ob" Received: from mail-ua1-f50.google.com (mail-ua1-f50.google.com [209.85.222.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 7ECF18564A for ; Fri, 12 Apr 2024 13:51:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712929887; cv=none; b=qwsfH/VeDUrsS0uF7CYmb/f9pncbQU3/Jo25Y0Lv/xcdVfp44XwpoKYB6MtKoJDdcCOeB9vc/9MfOFo+Jpw18YZxo7T9DqpC2wtbCuEplRNxn+QSz0TXQgK5TxXi412WkcyLw5JBr7JfOBxfn/cGT/iCCEyNUwW4xjgszx+ukzo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712929887; c=relaxed/simple; bh=53Cs+42uICznC+Xas0chinXqpYt7sWkCvzQ690iV654=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=AfxA8NscJBBQNPwSYX1mgJIXEl8hslnIn8+RuNcUvCWtVu67XSlkghhcSEhmtsA0I0P3eRzih84kZK3sF76ZpXjZq+w9EJ8atAauudJsVRuhE6vSCqVa/nZzUYvmvsTuVVL9U1Z44T8XQHcMBo2mFKrxWCfmuLhsRpieJSi/Blg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=dphFY/ob; arc=none smtp.client-ip=209.85.222.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-ua1-f50.google.com with SMTP id a1e0cc1a2514c-7e61a25900cso211832241.3 for ; Fri, 12 Apr 2024 06:51:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712929884; x=1713534684; 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=tJnR5552tR98GvdFl2I9gJzxKsxtaACk6KQyxfOH2CQ=; b=dphFY/obs5pjYf4o3FSjgCLJBTcJ5+J+d6Nj3Xr8Vh3rlZExJMe13QB67253zP/c/l QIR+hqVyoDeIivtI1e2aZDdRbH9wM0RpMn6C1cGzUoes85ok1cNlCAvIq3M9+p/Pk/ba Hc/coAOxhbGvVSzefTAA1fnoP/6TXU5bJRkuSNQD45a6cPrEM5vwTfnjowBMuEMC6CUb gxUIlHDNSO360mWTLE9uP/qildXmKhKNqhqxPu2GD0GpJHf9zY+WXuV0RwjsRIgEsv9t RgzCAvmf9PPTWpNqAyDyI8ojxFQxtPhC2B6N8FuNww4p8k/o+Z9P2GfIDrqIO1Y43Mwf B0cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712929884; x=1713534684; 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=tJnR5552tR98GvdFl2I9gJzxKsxtaACk6KQyxfOH2CQ=; b=n4Z3thGdBPRFWLRRaMHQYL9vpJIlZc+0o85jhe0qEnQN1UNngyLEj4SprnU5U9EfgP Kh5paiAEEqAqXXNKUvbuQpBvIVjb8l4wd9qZPtjhumYYt+iO+1gFoZ5dZUqYV0DwrRwW ctoqAtD0IHTVCUF7PBKqTnMUMx5npPD2p3S7ZhglbEMvQQAZ3HmyGeO/m2v0T7M7AK5O I5mBdDoGF5R2T14M6mhwDi25LoVuyaKTZEkuEhvJKsZJUVuDzOzvE37qLCuGJ5MuZL9D 35qQyD0OqjsAPPi/88yNPRpUatszCy2cY98nvglbQYzmjabB3/P3E6wHX173rpoPVdSX 6C7w== X-Forwarded-Encrypted: i=1; AJvYcCV+VOHDa+pGzI0Wx5xDUiTYFLKOXAgoTnMbSKFmfULqCAMOqLNHrqDLnNt3jQurlklZV4jcG86KInfwHs/Y2+GjGdwrVpjJBbCDWnx8 X-Gm-Message-State: AOJu0Yy7thXfbmlPQYb1hK2tvMapgZkeH4Gl1tCQBw3CSz12+Z+k3STh vlAKqa6NNvLtUqLFGsYcSZCs+Ix6X5ETggRHn7f5BKSpEv5pmQnDMNEu49pPbQy8W1V9n9/xhza TP11N49RiE4389C81MiFMFjKMUP4c9f0T5Inw X-Received: by 2002:a05:6102:160b:b0:47a:3ce6:6cfb with SMTP id cu11-20020a056102160b00b0047a3ce66cfbmr3725899vsb.19.1712929884209; Fri, 12 Apr 2024 06:51:24 -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: From: Alice Ryhl Date: Fri, 12 Apr 2024 15:51:12 +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 , 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 3:18=E2=80=AFPM Boqun Feng w= rote: > > On Fri, Apr 12, 2024 at 10:36:05AM +0200, Alice Ryhl wrote: > > On Fri, Apr 12, 2024 at 1:08=E2=80=AFAM Boqun Feng wrote: > > > > > > Currently since Rust code is compiled with "-Coverflow-checks=3Dy", s= o 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 n= ot > > > clear that the overflow checking is helpful, since for example, the > > > current binder usage[1] doesn't have the checking. > > > > I don't think this is a good idea at all. Any code that triggers an > > overflow in Ktime::sub is wrong, and anyone who enables > > CONFIG_RUST_OVERFLOW_CHECKS does so because they want such bugs to be > > caught. You may have been able to find one example of a subtraction > > that doesn't have a risk of overflow, but overflow bugs really do > > The point is you won't panic the kernel because of an overflow. I > agree that overflow is something we want to catch, but currently > ktime_t doesn't panic if overflow happens. What the CONFIG_RUST_OVERFLOW_CHECKS option does is enable panics on overflow. So I don't understand how "it panics on overflow" is an argument for removing the overflow check. That's what you asked for! One could perhaps argue about whether CONFIG_RUST_OVERFLOW_CHECKS is a good idea (I think it is), but that is orthogonal. When CONFIG_RUST_OVERFLOW_CHECKS is enabled, you should respect the flag. Alice