From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 18E9CCCD183 for ; Thu, 9 Oct 2025 17:18:40 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BD1E610E27B; Thu, 9 Oct 2025 17:18:39 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="uNC7TuaN"; dkim-atps=neutral Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6503410E27B for ; Thu, 9 Oct 2025 17:18:38 +0000 (UTC) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id E40E245B3B; Thu, 9 Oct 2025 17:18:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CFC0BC4CEE7; Thu, 9 Oct 2025 17:18:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1760030317; bh=kFsIMObArLcyoFFIMA4L5RDZSvrQbbMBoX1+KItsqQU=; h=Date:Subject:Cc:To:From:References:In-Reply-To:From; b=uNC7TuaNBQ719jUSqL2ej2bN+y/WjYBNMvCjjaLce+TWEK2i7X7xetVsaFN0tggaQ /kHdfDbiFPi9VIL+/2DAvZ7X+4lPJe87kjLeoLFqTj28gjko1F3HqQ6Jh+E4PRicjT usCom3hlJ5aN2hHwmsMPsmFraTCddLbfEkJ9+M+jahqgMFdfAeSXOGqpBHomAUHlF9 1rQ3EI69b/izWALKWqMneqA7y56ccCEe28uZBvvhLs9V/1hFxWWRAxD9Cy/UuT6d0d XrU2mJEWZmkvKyHd6mGkxDhM9vwlEf5055TosfKJjLXCdPmIreLB27+Qtgla5JEgtU 0RgEaTJJ2DG9g== Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Thu, 09 Oct 2025 19:18:33 +0200 Message-Id: Subject: Re: [PATCH RFC v2 3/3] gpu: nova-core: use BoundedInt Cc: "Alexandre Courbot" , "Joel Fernandes" , "Jesung Yang" , "Miguel Ojeda" , "Alex Gaynor" , "Boqun Feng" , "Gary Guo" , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , "Benno Lossin" , "Andreas Hindborg" , "Alice Ryhl" , "Trevor Gross" , , , To: "Yury Norov" From: "Danilo Krummrich" References: <20251009-bounded_ints-v2-0-ff3d7fee3ffd@nvidia.com> <20251009-bounded_ints-v2-3-ff3d7fee3ffd@nvidia.com> In-Reply-To: X-BeenThere: nouveau@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Nouveau development list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: nouveau-bounces@lists.freedesktop.org Sender: "Nouveau" On Thu Oct 9, 2025 at 6:40 PM CEST, Yury Norov wrote: > On Thu, Oct 09, 2025 at 09:37:10PM +0900, Alexandre Courbot wrote: >> Use BoundedInt with the register!() macro and adapt the nova-core code >> accordingly. This makes it impossible to trim values when setting a >> register field, because either the value of the field has been inferred >> at compile-time to fit within the bounds of the field, or the user has >> been forced to check at runtime that it does indeed fit. > > In C23 we've got _BitInt(), which works like: > > unsigned _BitInt(2) a =3D 5; // compile-time error > > Can you consider a similar name and syntax in rust? Rust is a different language and has its own syntax, I think we should not = try to use C syntax instead. >> regs::NV_PFALCON_FALCON_DMATRFBASE1::default() >> - .set_base((dma_start >> 40) as u16) >> + .try_set_base(dma_start >> 40)? >> .write(bar, &E::ID); > > Does it mean that something like the following syntax is possible? > > regs::NV_PFALCON_FALCON_DMATRFBASE1::default() > .try_set_base1(base1 >> 40)? // fail here Note that try_set_base1() returns a Result [1], which is handled immediatel= y by the question mark operator [2]. I.e. if try_set_base1() returns an error it= is propagated to the caller right away without executing any of the code below= . > .try_set_base2(base2 >> 40)? // skip > .write(bar, &E::ID) else { pr_err!(); return -EINVAL }; > > This is my main concern: Rust is advertised a as runtime-safe language > (at lease safer than C), but current design isn't safe against one of > the most common errors: type overflow. Where do you see a potential runtime overflows in the register!() code? [1] https://rust.docs.kernel.org/kernel/error/type.Result.html [2] https://doc.rust-lang.org/reference/expressions/operator-expr.html?high= light=3Dquestion%20mark#the-question-mark-operator