lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date: Thu, 07 Mar 2024 21:45:33 +0000
From: "Daniel Almeida" <daniel.almeida@...labora.com>
To: "Nicolas Dufresne" <nicolas@...fresne.ca>
Cc: wedsonaf@...il.com, ojeda@...nel.org, mchehab@...nel.org, hverkuil@...all.nl, rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org, linux-media@...r.kernel.org, kernel@...labora.com
Subject: Re: [RFC PATCH v2 2/2] media: rkvdec: rewrite parts of the driver in Rust

Hi Nicolas,

> struct reg123 {
>   val1 :3  // bit 31-29
>   val2 :20 // bit 28-9
>   val3 :9  // bit 8-0
> };

What you're describing can be modeled as Ranges in Rust:

```
use core::ops::Range;

struct Foo {
    reg1: Range<u32>,
    reg2: Range<u32>,
    reg3: Range<u32>
}

const FOO_REGMAP: Foo = Foo {
        reg1: 0..3,
        reg2: 3..24,
        reg3: 24..32
};
```

It becomes more useful when you pair that with a bit writer. For an example of previous art, see Faith's work: [0]

This has asserts in the right places so that you do not shoot yourself in the foot. IMHO, such a data structure can be shared with the whole Rust code in the kernel.

You can then describe your writes using the ranges, e.g.: [1] 

But as we've established, instead of writing the ranges down directly, you can simply refer to them as FOO_REGMAP.reg1, FOO_REGMAP.reg2 and so on.

I believe this is both more readable and safer.

[0]: https://gitlab.freedesktop.org/mesa/mesa/-/blob/main/src/nouveau/compiler/bitview/lib.rs?ref_type=heads

[1]: https://gitlab.freedesktop.org/mesa/mesa/-/blob/main/src/nouveau/compiler/nak/encode_sm70.rs?ref_type=heads#L228


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ