[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YhSnnHpIeDReK/eL@alley>
Date: Tue, 22 Feb 2022 10:06:36 +0100
From: Petr Mladek <pmladek@...e.com>
To: Miguel Ojeda <ojeda@...nel.org>
Cc: Linus Torvalds <torvalds@...ux-foundation.org>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org,
Wedson Almeida Filho <wedsonaf@...gle.com>,
Alex Gaynor <alex.gaynor@...il.com>,
Geoffrey Thomas <geofft@...reload.com>,
Finn Behrens <me@...enk.de>,
Adam Bratschi-Kaye <ark.email@...il.com>,
Michael Ellerman <mpe@...erman.id.au>,
Sumera Priyadarsini <sylphrenadin@...il.com>,
Sven Van Asbroeck <thesven73@...il.com>,
Gary Guo <gary@...yguo.net>,
Boris-Chengbiao Zhou <bobo1239@....de>,
Boqun Feng <boqun.feng@...il.com>,
Fox Chen <foxhlchen@...il.com>,
Dan Robertson <daniel.robertson@...rlab.io>,
Viktor Garske <viktor@...ar.de>,
Dariusz Sosnowski <dsosnowski@...snowski.pl>,
Léo Lanteri Thauvin
<leseulartichaut@...il.com>, Niklas Mohrin <dev@...lasmohrin.de>,
Gioh Kim <gurugio@...il.com>, Daniel Xu <dxu@...uu.xyz>,
Milan Landaverde <milan@...verde.com>,
Morgan Bartlett <mjmouse9999@...il.com>,
Maciej Falkowski <m.falkowski@...sung.com>,
Jiapeng Chong <jiapeng.chong@...ux.alibaba.com>,
Sergey Senozhatsky <senozhatsky@...omium.org>,
Steven Rostedt <rostedt@...dmis.org>,
John Ogness <john.ogness@...utronix.de>
Subject: Re: [PATCH v4 10/20] rust: add `kernel` crate
On Sat 2022-02-12 14:03:36, Miguel Ojeda wrote:
> From: Wedson Almeida Filho <wedsonaf@...gle.com>
>
> The `kernel` crate currently includes all the abstractions that wrap
> kernel features written in C.
>
> These abstractions call the C side of the kernel via the generated
> bindings with the `bindgen` tool. Modules developed in Rust should
> never call the bindings themselves.
>
> In the future, as the abstractions grow in number, we may need
> to split this crate into several, possibly following a similar
> subdivision in subsystems as the kernel itself and/or moving
> the code to the actual subsystems.
>
> diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
> index 82abfaf3c2aa..c042386667f2 100644
> --- a/kernel/printk/printk.c
> +++ b/kernel/printk/printk.c
> @@ -392,7 +392,10 @@ static struct latched_seq clear_seq = {
> /* the maximum size of a formatted record (i.e. with prefix added per line) */
> #define CONSOLE_LOG_MAX 1024
>
> -/* the maximum size allowed to be reserved for a record */
> +/*
> + * The maximum size allowed to be reserved for a record.
> + * Keep in sync with rust/kernel/print.rs.
> + */
> #define LOG_LINE_MAX (CONSOLE_LOG_MAX - PREFIX_MAX)
What exactly should we keep in sync, please?
I see only handling of KERN_* prefix in print.rs. I do not see there
any counter part of LOG_LINE_MAX, CONSOLE_LOG_MAX, or PREFIX_MAX.
Also note that PREFIX_MAX is the maximal lenght of the prefix printed
on console. It is log level + time stamp + caller id. For example:
<12>[ 123.632345][ T3260]
It seems that print.rs defines max size of the prefix in the printk
format where the log level is defined using KERN_* pair of characters.
>
> #define LOG_LEVEL(v) ((v) & 0x07)
> diff --git a/rust/kernel/print.rs b/rust/kernel/print.rs
> new file mode 100644
> index 000000000000..dba4ef10c722
> --- /dev/null
> +++ b/rust/kernel/print.rs
> @@ -0,0 +1,417 @@
> +/// Format strings.
> +///
> +/// Public but hidden since it should only be used from public macros.
> +#[doc(hidden)]
> +pub mod format_strings {
> + use crate::bindings;
> +
> + /// The length we copy from the `KERN_*` kernel prefixes.
> + const LENGTH_PREFIX: usize = 2;
> +
> + /// The length of the fixed format strings.
> + pub const LENGTH: usize = 10;
I am sorry but I am not familiar with rust. What are these limits
2 and 10 used for, please?
I guess that 2 is the size of a single KERN_* identifier.
But what is 10?
Note that printk() format prefix is typically just a single KERN_*
identifier. But there might be more. Well, in practice only the
following combination makes sense: KERN_CONT + KERN_<LEVEL>.
> + /// Generates a fixed format string for the kernel's [`_printk`].
> + ///
> + /// The format string is always the same for a given level, i.e. for a
> + /// given `prefix`, which are the kernel's `KERN_*` constants.
> + ///
> + /// [`_printk`]: ../../../../include/linux/printk.h
> + const fn generate(is_cont: bool, prefix: &[u8; 3]) -> [u8; LENGTH] {
> + // Ensure the `KERN_*` macros are what we expect.
> + assert!(prefix[0] == b'\x01');
> + if is_cont {
> + assert!(prefix[1] == b'c');
> + } else {
> + assert!(prefix[1] >= b'0' && prefix[1] <= b'7');
> + }
> + assert!(prefix[2] == b'\x00');
> +
> + let suffix: &[u8; LENGTH - LENGTH_PREFIX] = if is_cont {
> + b"%pA\0\0\0\0\0"
> + } else {
> + b"%s: %pA\0"
> + };
> +
> + [
> + prefix[0], prefix[1], suffix[0], suffix[1], suffix[2], suffix[3], suffix[4], suffix[5],
> + suffix[6], suffix[7],
> + ]
> + }
Finally, is there any way to test whether any change in the printk
code breaks the rust support?
Best Regards,
Petr
Powered by blists - more mailing lists