Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp967360lqd; Thu, 25 Apr 2024 02:01:07 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW4qFsphW4v0KLFa9ISlRVQqvxQhBOBLOtBt7LR0pCJIp30lfYht/1rBzn+Qq5ps44HrsljFmXmVh38uwi4FEuWZlHD/QxM8Q45bmTG3Q== X-Google-Smtp-Source: AGHT+IHpS/ueUl1VfMeM52FdWCgv2YmizqkcchE+qn0AQX0QB4I6Z7+DC3hswd9jIrAX8+Dj3Bs7 X-Received: by 2002:a17:903:289:b0:1e5:3684:617e with SMTP id j9-20020a170903028900b001e53684617emr6386456plr.52.1714035667590; Thu, 25 Apr 2024 02:01:07 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714035667; cv=pass; d=google.com; s=arc-20160816; b=LL7Q2F6K8SRrVKhE65EZuWBTLv7h6MTAWhHT1JsFinXhGiqt9jOi4M98Jtzq03+sRt fT4mjEeENdqXVfFQsdriNcC0wuxAeNqp+YttV2JQQVoWTB7kM7OadCQkN+x4rzx7edrr wHelEVWcAMormmv3WsfrPk3GbAlqgIVAkq7mUn/a/jgtXMIihJXfPEFo0zKK6smFyCgV ZtwDl3AxWABrRHXD+JGRDH1Z3MIQYN0X26KXnCTuWJM3ZWFNmqh7B08+xTDPu96PLSGd fdXJPyYCpr9g+eVYvSs7bBhngy+PzB6e1EREhNDLCDM37XPEQSn6EL9WcE3YYOqI43OL 4Pqw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:user-agent :references:in-reply-to:subject:cc:to:from:dkim-signature; bh=uvEI4foK1L+IEvRMU+9j0M20skVBYn6iR5gFVtibc6U=; fh=GIWPBBD+4Csi6b1NSOBwwsZF3lIwNosJuBiQqxrhLy4=; b=HgTVinrQ+9GUSgFnkkguGLQt//Vb4XnEyRLpI3GXA4sOsvyR+LXeO6MWvNif66HSzH sGW1ZfhtcwokAU0kR8jcRnV6NArMgqEoIR77u8LWX94kcTvnI3UwuSOzofQdNoGwIPv0 y5PHfAorGs5gnpxyUTfJ1a0K/dME6+j1IaChG8hNy7njRhX9HwkvVdkLITxVOLIJG27x lOVdTumpuX4uSTBNqP99lZOkUhGAhUPlJV8LwFGxvLBPDXLcf6n6auwaqWKb4suYuscV TERmYg+55Utrn/W6o5O3e37i7P+PiFu9faKyU4iV9QeaRn9O2TZzexi1BMyUAJTppYq7 jSsA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@metaspace-dk.20230601.gappssmtp.com header.s=20230601 header.b=K6S6L3sE; arc=pass (i=1 dkim=pass dkdomain=metaspace-dk.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-158229-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-158229-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id e13-20020a170902ef4d00b001dd693cc79csi13051435plx.620.2024.04.25.02.01.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Apr 2024 02:01:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-158229-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@metaspace-dk.20230601.gappssmtp.com header.s=20230601 header.b=K6S6L3sE; arc=pass (i=1 dkim=pass dkdomain=metaspace-dk.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-158229-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-158229-linux.lists.archive=gmail.com@vger.kernel.org" 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 0F1CB281A79 for ; Thu, 25 Apr 2024 09:01:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9A0927F486; Thu, 25 Apr 2024 09:00:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=metaspace-dk.20230601.gappssmtp.com header.i=@metaspace-dk.20230601.gappssmtp.com header.b="K6S6L3sE" Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) (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 9E33180056 for ; Thu, 25 Apr 2024 09:00:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714035655; cv=none; b=lT3IZv5dTh227/lX6mev1KqVjXZNDhH+L1syMkO6fPnl22F1hX07OgD+23cQEkuVHzgvQYsgKPcT5OuB54C8vP3W8+jKk7Tzvob9t5/bd7iT+R55cmX/Lsy+tiNxnwg8ELVvHTH2iTl7x9ax5vvW+EBpy1Ugxj6b+DeNBo7b6os= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714035655; c=relaxed/simple; bh=hxPa/xW4XemSSh+6kDeb4Xm5EBcoU8VCtmv3JFmprx0=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=s0JUL07SPLSDp1azZ/HTfaYLMoTwfjzCWfMlWuS5aNWiKYrQhrPyPdF3na6gGi71Ss2Sm408NCOhgvEGqI/ZjX8bHZJtP/qsw+wA2F327jsqJAard63oTDAavPX4jFH/BfFHkrzuQ/MxmZdFyCHyNaQ+Tcp76F2Ms3smfE7P6X0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=metaspace.dk; spf=none smtp.mailfrom=metaspace.dk; dkim=pass (2048-bit key) header.d=metaspace-dk.20230601.gappssmtp.com header.i=@metaspace-dk.20230601.gappssmtp.com header.b=K6S6L3sE; arc=none smtp.client-ip=209.85.208.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=metaspace.dk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=metaspace.dk Received: by mail-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-56e6a1edecfso1009617a12.1 for ; Thu, 25 Apr 2024 02:00:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=metaspace-dk.20230601.gappssmtp.com; s=20230601; t=1714035652; x=1714640452; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:user-agent :references:in-reply-to:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=uvEI4foK1L+IEvRMU+9j0M20skVBYn6iR5gFVtibc6U=; b=K6S6L3sE/hgQ53jCSXJEtfsrfFMOaT7ixm7ZY9B5+94FrHh7v+HO6L3Sz1CA1rd/wE kQE6fTwyPKEd92A4ATGdaAyqW8AeoUK/N+QsEmEOSgy96a3hvOi0HXUlhl0gt/98x9fi GBupEEYnVkz45EyRaCAjxIIOj+dZUHtaLuWufT7ZeHMbiINx8VvDPdWxH+bcpRG46wAI ePAcu9L2BWnKCZo9iRKEva6tjNmd9rroq9R4rtmkGKzNt0hxwveTj6FlEteRKEIob+v4 Ty/ic2C26x4MIaL3k3o/oYeqQDDEFAlGieVLLow1LU6Zjlj5XX1GArsl1Dvit4WgiSvs VqHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714035652; x=1714640452; h=content-transfer-encoding:mime-version:message-id:date:user-agent :references:in-reply-to:subject:cc:to:from:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=uvEI4foK1L+IEvRMU+9j0M20skVBYn6iR5gFVtibc6U=; b=AVmd6vXxhlXa4V3kQ8xUvVfHqyMhaKF6t83sLgvswsL16d8oUqqmSZAlxyeYzwunMR h/BxIGVhNcv5Dnc1NkOsZ2QYPcC/kP6zXO2T/zU0Nrbo8B/cFUkdtl3Wo3+2IqY7QoKD jQUQKVmH0Vp4CDOMKHp60M9MrTgqPywbgk/nIs3vVVkbA56s3uHmAXNAH96B+ZCChwMo Jm5fwaySflVEqbor4fMJm19kjo9LYTmSCoACAa1sJkvqPDsohfTyTbVPJc4mTmxSNCGW ueZAWT66cdCUdwFtE1BunszGIQDAUW7lby4DkVPtj89qDt8Ml+IohaIbCbe7Y9eCir4n 8D4Q== X-Forwarded-Encrypted: i=1; AJvYcCVX1rjgAOEUKqeHX3FqPohx7C8KXB+1nhXz9xqO1aGFVbZKfGTTOEkW3MODa+4htV9kKvrw4XWRVUiisluKzAhZoaIEAd1g3ZKmDy2/ X-Gm-Message-State: AOJu0YyaRK586pPw62uOjfPkz9/02d8CkWt/i6Pgd3J5AZIay9erdHFH oXcj7NF22+NIZjD2Dq1YYY+urW0D81ci4RcHN4Q9Jc7gInReTf2dYvllI0uxiVI= X-Received: by 2002:a17:906:1b45:b0:a52:30d3:41dd with SMTP id p5-20020a1709061b4500b00a5230d341ddmr3498691ejg.41.1714035651546; Thu, 25 Apr 2024 02:00:51 -0700 (PDT) Received: from localhost ([79.142.230.34]) by smtp.gmail.com with ESMTPSA id cf5-20020a170906b2c500b00a587868c5d2sm3315093ejb.195.2024.04.25.02.00.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Apr 2024 02:00:51 -0700 (PDT) From: Andreas Hindborg To: Alice Ryhl Cc: Boqun Feng , 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 Subject: Re: [PATCH 2/2] rust: time: Use wrapping_sub() for Ktime::sub() In-Reply-To: (Alice Ryhl's message of "Fri, 12 Apr 2024 15:51:12 +0200") References: <20240411230801.1504496-1-boqun.feng@gmail.com> <20240411230801.1504496-3-boqun.feng@gmail.com> User-Agent: mu4e 1.12.4; emacs 29.3 Date: Thu, 25 Apr 2024 11:00:31 +0200 Message-ID: <877cgln7f4.fsf@metaspace.dk> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Alice Ryhl writes: > On Fri, Apr 12, 2024 at 3:18=E2=80=AFPM Boqun Feng = wrote: >> >> 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", = 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. >> > >> > 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. I would agree. If users do not want panics on overflow, they disable RUST_OVERFLOW_CHECKS. If the config is enabled, overflows in ktime sub should panic, even if it does not do so in equivalent C code. BR Andreas