rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] rust: error: add missing error codes
@ 2023-05-04  6:48 Alice Ryhl
  2023-05-04 12:40 ` Martin Rodriguez Reboredo
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Alice Ryhl @ 2023-05-04  6:48 UTC (permalink / raw)
  To: Miguel Ojeda, Wedson Almeida Filho, Alex Gaynor
  Cc: Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
	Alice Ryhl, rust-for-linux, linux-kernel, patches

This adds the error codes from `include/linux/errno.h` to the list of
Rust error constants. These errors were not included originally, because
they are not supposed to be visible from userspace. However, they are
still a perfectly valid error to use when writing a kernel driver. For
example, you might want to return ERESTARTSYS if you receive a signal
during a call to `schedule`.

This patch inserts an annotation to skip rustfmt on the list of error
codes. Without it, three of the error codes are split over several
lines, which looks terribly inconsistent.

Signed-off-by: Alice Ryhl <aliceryhl@google.com>
---
 rust/kernel/error.rs | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/rust/kernel/error.rs b/rust/kernel/error.rs
index 5f4114b30b94..de4fa8640f29 100644
--- a/rust/kernel/error.rs
+++ b/rust/kernel/error.rs
@@ -14,6 +14,7 @@ use core::num::TryFromIntError;
 use core::str::Utf8Error;
 
 /// Contains the C-compatible error codes.
+#[rustfmt::skip]
 pub mod code {
     macro_rules! declare_err {
         ($err:tt $(,)? $($doc:expr),+) => {
@@ -58,6 +59,25 @@ pub mod code {
     declare_err!(EPIPE, "Broken pipe.");
     declare_err!(EDOM, "Math argument out of domain of func.");
     declare_err!(ERANGE, "Math result not representable.");
+    declare_err!(ERESTARTSYS, "Restart the system call.");
+    declare_err!(ERESTARTNOINTR, "System call was interrupted by a signal and will be restarted.");
+    declare_err!(ERESTARTNOHAND, "Restart if no handler.");
+    declare_err!(ENOIOCTLCMD, "No ioctl command.");
+    declare_err!(ERESTART_RESTARTBLOCK, "Restart by calling sys_restart_syscall.");
+    declare_err!(EPROBE_DEFER, "Driver requests probe retry.");
+    declare_err!(EOPENSTALE, "Open found a stale dentry.");
+    declare_err!(ENOPARAM, "Parameter not supported.");
+    declare_err!(EBADHANDLE, "Illegal NFS file handle.");
+    declare_err!(ENOTSYNC, "Update synchronization mismatch.");
+    declare_err!(EBADCOOKIE, "Cookie is stale.");
+    declare_err!(ENOTSUPP, "Operation is not supported.");
+    declare_err!(ETOOSMALL, "Buffer or request is too small.");
+    declare_err!(ESERVERFAULT, "An untranslatable error occurred.");
+    declare_err!(EBADTYPE, "Type not supported by server.");
+    declare_err!(EJUKEBOX, "Request initiated, but will not complete before timeout.");
+    declare_err!(EIOCBQUEUED, "iocb queued, will get completion event.");
+    declare_err!(ERECALLCONFLICT, "Conflict with recalled state.");
+    declare_err!(ENOGRACE, "NFS file lock reclaim refused.");
 }
 
 /// Generic integer kernel error.

base-commit: ea76e08f4d901a450619831a255e9e0a4c0ed162
-- 
2.40.1.521.gf1e218fcd8-goog


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] rust: error: add missing error codes
  2023-05-04  6:48 [PATCH v2] rust: error: add missing error codes Alice Ryhl
@ 2023-05-04 12:40 ` Martin Rodriguez Reboredo
  2023-05-08 11:47 ` Gary Guo
  2023-05-31 17:11 ` Miguel Ojeda
  2 siblings, 0 replies; 8+ messages in thread
From: Martin Rodriguez Reboredo @ 2023-05-04 12:40 UTC (permalink / raw)
  To: Alice Ryhl, Miguel Ojeda, Wedson Almeida Filho, Alex Gaynor
  Cc: Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
	rust-for-linux, linux-kernel, patches

On 5/4/23 03:48, Alice Ryhl wrote:
> This adds the error codes from `include/linux/errno.h` to the list of
> Rust error constants. These errors were not included originally, because
> they are not supposed to be visible from userspace. However, they are
> still a perfectly valid error to use when writing a kernel driver. For
> example, you might want to return ERESTARTSYS if you receive a signal
> during a call to `schedule`.
> 
> This patch inserts an annotation to skip rustfmt on the list of error
> codes. Without it, three of the error codes are split over several
> lines, which looks terribly inconsistent.
> 
> Signed-off-by: Alice Ryhl <aliceryhl@google.com>
> ---
>   rust/kernel/error.rs | 20 ++++++++++++++++++++
>   1 file changed, 20 insertions(+)
> 
> [...]

Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] rust: error: add missing error codes
  2023-05-04  6:48 [PATCH v2] rust: error: add missing error codes Alice Ryhl
  2023-05-04 12:40 ` Martin Rodriguez Reboredo
@ 2023-05-08 11:47 ` Gary Guo
  2023-05-09  8:07   ` Alice Ryhl
  2023-05-31 17:11 ` Miguel Ojeda
  2 siblings, 1 reply; 8+ messages in thread
From: Gary Guo @ 2023-05-08 11:47 UTC (permalink / raw)
  To: Alice Ryhl
  Cc: Miguel Ojeda, Wedson Almeida Filho, Alex Gaynor, Boqun Feng,
	Björn Roy Baron, Benno Lossin, rust-for-linux, linux-kernel,
	patches

On Thu,  4 May 2023 06:48:54 +0000
Alice Ryhl <aliceryhl@google.com> wrote:

> This adds the error codes from `include/linux/errno.h` to the list of
> Rust error constants. These errors were not included originally, because
> they are not supposed to be visible from userspace. However, they are
> still a perfectly valid error to use when writing a kernel driver. For
> example, you might want to return ERESTARTSYS if you receive a signal
> during a call to `schedule`.

`include/linux/errno.h` also includes all of `asm/errno.h`,
which defines EDEADLK - EHWPOISON, which is not included in this patch.
I feel like these error codes should be added first?

> 
> This patch inserts an annotation to skip rustfmt on the list of error
> codes. Without it, three of the error codes are split over several
> lines, which looks terribly inconsistent.
> 
> Signed-off-by: Alice Ryhl <aliceryhl@google.com>
> ---
>  rust/kernel/error.rs | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
> 
> diff --git a/rust/kernel/error.rs b/rust/kernel/error.rs
> index 5f4114b30b94..de4fa8640f29 100644
> --- a/rust/kernel/error.rs
> +++ b/rust/kernel/error.rs
> @@ -14,6 +14,7 @@ use core::num::TryFromIntError;
>  use core::str::Utf8Error;
>  
>  /// Contains the C-compatible error codes.
> +#[rustfmt::skip]
>  pub mod code {
>      macro_rules! declare_err {
>          ($err:tt $(,)? $($doc:expr),+) => {
> @@ -58,6 +59,25 @@ pub mod code {
>      declare_err!(EPIPE, "Broken pipe.");
>      declare_err!(EDOM, "Math argument out of domain of func.");
>      declare_err!(ERANGE, "Math result not representable.");
> +    declare_err!(ERESTARTSYS, "Restart the system call.");
> +    declare_err!(ERESTARTNOINTR, "System call was interrupted by a signal and will be restarted.");
> +    declare_err!(ERESTARTNOHAND, "Restart if no handler.");
> +    declare_err!(ENOIOCTLCMD, "No ioctl command.");
> +    declare_err!(ERESTART_RESTARTBLOCK, "Restart by calling sys_restart_syscall.");
> +    declare_err!(EPROBE_DEFER, "Driver requests probe retry.");
> +    declare_err!(EOPENSTALE, "Open found a stale dentry.");
> +    declare_err!(ENOPARAM, "Parameter not supported.");
> +    declare_err!(EBADHANDLE, "Illegal NFS file handle.");
> +    declare_err!(ENOTSYNC, "Update synchronization mismatch.");
> +    declare_err!(EBADCOOKIE, "Cookie is stale.");
> +    declare_err!(ENOTSUPP, "Operation is not supported.");
> +    declare_err!(ETOOSMALL, "Buffer or request is too small.");
> +    declare_err!(ESERVERFAULT, "An untranslatable error occurred.");
> +    declare_err!(EBADTYPE, "Type not supported by server.");
> +    declare_err!(EJUKEBOX, "Request initiated, but will not complete before timeout.");
> +    declare_err!(EIOCBQUEUED, "iocb queued, will get completion event.");
> +    declare_err!(ERECALLCONFLICT, "Conflict with recalled state.");
> +    declare_err!(ENOGRACE, "NFS file lock reclaim refused.");
>  }
>  
>  /// Generic integer kernel error.
> 
> base-commit: ea76e08f4d901a450619831a255e9e0a4c0ed162


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] rust: error: add missing error codes
  2023-05-08 11:47 ` Gary Guo
@ 2023-05-09  8:07   ` Alice Ryhl
  2023-05-09  8:46     ` Greg KH
  0 siblings, 1 reply; 8+ messages in thread
From: Alice Ryhl @ 2023-05-09  8:07 UTC (permalink / raw)
  To: gary
  Cc: alex.gaynor, aliceryhl, benno.lossin, bjorn3_gh, boqun.feng,
	linux-kernel, ojeda, patches, rust-for-linux, wedsonaf

On Mon, 8 May 2023 12:47:01 +0100
Gary Guo <gary@garyguo.net> wrote:
> On Thu,  4 May 2023 06:48:54 +0000
> Alice Ryhl <aliceryhl@google.com> wrote:
> > This adds the error codes from `include/linux/errno.h` to the list of
> > Rust error constants. These errors were not included originally, because
> > they are not supposed to be visible from userspace. However, they are
> > still a perfectly valid error to use when writing a kernel driver. For
> > example, you might want to return ERESTARTSYS if you receive a signal
> > during a call to `schedule`.
> 
> `include/linux/errno.h` also includes all of `asm/errno.h`,
> which defines EDEADLK - EHWPOISON, which is not included in this patch.
> I feel like these error codes should be added first?

It seems like there are a lot of asm/errno.h files:

$ find . -name errno.h
./arch/powerpc/include/uapi/asm/errno.h
./arch/mips/include/asm/errno.h
./arch/mips/include/uapi/asm/errno.h
./arch/alpha/include/uapi/asm/errno.h
./arch/parisc/include/uapi/asm/errno.h
./arch/sparc/include/uapi/asm/errno.h
./arch/x86/include/generated/uapi/asm/errno.h
./tools/arch/powerpc/include/uapi/asm/errno.h
./tools/arch/mips/include/asm/errno.h
./tools/arch/mips/include/uapi/asm/errno.h
./tools/arch/alpha/include/uapi/asm/errno.h
./tools/arch/parisc/include/uapi/asm/errno.h
./tools/arch/sparc/include/uapi/asm/errno.h
./tools/arch/x86/include/uapi/asm/errno.h
./tools/include/nolibc/errno.h
./tools/include/uapi/asm/errno.h
./tools/include/uapi/asm-generic/errno.h
./include/uapi/asm-generic/errno.h
./include/uapi/linux/errno.h
./include/linux/errno.h

How should I proceed with this? You mention EDEADLK - EHWPOISON, but its
not clear to me which asm/errno.h file I should base this on.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] rust: error: add missing error codes
  2023-05-09  8:07   ` Alice Ryhl
@ 2023-05-09  8:46     ` Greg KH
  2023-05-09 11:10       ` Miguel Ojeda
  0 siblings, 1 reply; 8+ messages in thread
From: Greg KH @ 2023-05-09  8:46 UTC (permalink / raw)
  To: Alice Ryhl
  Cc: gary, alex.gaynor, benno.lossin, bjorn3_gh, boqun.feng,
	linux-kernel, ojeda, patches, rust-for-linux, wedsonaf

On Tue, May 09, 2023 at 08:07:00AM +0000, Alice Ryhl wrote:
> On Mon, 8 May 2023 12:47:01 +0100
> Gary Guo <gary@garyguo.net> wrote:
> > On Thu,  4 May 2023 06:48:54 +0000
> > Alice Ryhl <aliceryhl@google.com> wrote:
> > > This adds the error codes from `include/linux/errno.h` to the list of
> > > Rust error constants. These errors were not included originally, because
> > > they are not supposed to be visible from userspace. However, they are
> > > still a perfectly valid error to use when writing a kernel driver. For
> > > example, you might want to return ERESTARTSYS if you receive a signal
> > > during a call to `schedule`.
> > 
> > `include/linux/errno.h` also includes all of `asm/errno.h`,
> > which defines EDEADLK - EHWPOISON, which is not included in this patch.
> > I feel like these error codes should be added first?
> 
> It seems like there are a lot of asm/errno.h files:
> 
> $ find . -name errno.h
> ./arch/powerpc/include/uapi/asm/errno.h
> ./arch/mips/include/asm/errno.h
> ./arch/mips/include/uapi/asm/errno.h
> ./arch/alpha/include/uapi/asm/errno.h
> ./arch/parisc/include/uapi/asm/errno.h
> ./arch/sparc/include/uapi/asm/errno.h
> ./arch/x86/include/generated/uapi/asm/errno.h
> ./tools/arch/powerpc/include/uapi/asm/errno.h
> ./tools/arch/mips/include/asm/errno.h
> ./tools/arch/mips/include/uapi/asm/errno.h
> ./tools/arch/alpha/include/uapi/asm/errno.h
> ./tools/arch/parisc/include/uapi/asm/errno.h
> ./tools/arch/sparc/include/uapi/asm/errno.h
> ./tools/arch/x86/include/uapi/asm/errno.h
> ./tools/include/nolibc/errno.h
> ./tools/include/uapi/asm/errno.h
> ./tools/include/uapi/asm-generic/errno.h

You can ignore the tool ones.

> ./include/uapi/asm-generic/errno.h
> ./include/uapi/linux/errno.h
> ./include/linux/errno.h
> 
> How should I proceed with this? You mention EDEADLK - EHWPOISON, but its
> not clear to me which asm/errno.h file I should base this on.

It depends on which arch you are building for.  That's why we have
per-platform errno.h files, the values are different for different ones.
So you need to handle them all properly somehow.  How is rust going to
handle per-arch stuff like this?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] rust: error: add missing error codes
  2023-05-09  8:46     ` Greg KH
@ 2023-05-09 11:10       ` Miguel Ojeda
  2023-05-15 18:07         ` Andreas Hindborg
  0 siblings, 1 reply; 8+ messages in thread
From: Miguel Ojeda @ 2023-05-09 11:10 UTC (permalink / raw)
  To: Greg KH
  Cc: Alice Ryhl, gary, alex.gaynor, benno.lossin, bjorn3_gh,
	boqun.feng, linux-kernel, ojeda, patches, rust-for-linux,
	wedsonaf

On Tue, May 9, 2023 at 10:46 AM Greg KH <gregkh@linuxfoundation.org> wrote:
>
> It depends on which arch you are building for.  That's why we have
> per-platform errno.h files, the values are different for different ones.
> So you need to handle them all properly somehow.  How is rust going to
> handle per-arch stuff like this?

We can do conditional compilation in the same file, possibly with a
Rust macro which takes a nice table that shows all arches at once.

We can also split into files like C and move it to each `arch/`, there
are a couple of approaches for this. This is best for `MAINTAINERS`,
although these headers almost never change, so it is not a big
advantage.

We could also automatically do everything based on the C headers, too.
Back then it felt to me like too much complexity for little gain,
given those C headers almost never change, but now it may be worth it.
Or, instead, having a test that verifies they are the same instead,
and that way we don't introduce complexity for the build itself.

Alice only needs `ERESTARTSYS` so far, as far as I understand, so
perhaps it is simplest to only add the rest of the non-generic ones
for the moment; and gather opinions on the approaches above meanwhile.

Cheers,
Miguel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] rust: error: add missing error codes
  2023-05-09 11:10       ` Miguel Ojeda
@ 2023-05-15 18:07         ` Andreas Hindborg
  0 siblings, 0 replies; 8+ messages in thread
From: Andreas Hindborg @ 2023-05-15 18:07 UTC (permalink / raw)
  To: Miguel Ojeda
  Cc: Greg KH, Alice Ryhl, gary, alex.gaynor, benno.lossin, bjorn3_gh,
	boqun.feng, linux-kernel, ojeda, patches, rust-for-linux,
	wedsonaf


Miguel Ojeda <miguel.ojeda.sandonis@gmail.com> writes:

> On Tue, May 9, 2023 at 10:46 AM Greg KH <gregkh@linuxfoundation.org> wrote:
>>
>> It depends on which arch you are building for.  That's why we have
>> per-platform errno.h files, the values are different for different ones.
>> So you need to handle them all properly somehow.  How is rust going to
>> handle per-arch stuff like this?
>
> We can do conditional compilation in the same file, possibly with a
> Rust macro which takes a nice table that shows all arches at once.
>
> We can also split into files like C and move it to each `arch/`, there
> are a couple of approaches for this. This is best for `MAINTAINERS`,
> although these headers almost never change, so it is not a big
> advantage.
>
> We could also automatically do everything based on the C headers, too.
> Back then it felt to me like too much complexity for little gain,
> given those C headers almost never change, but now it may be worth it.
> Or, instead, having a test that verifies they are the same instead,
> and that way we don't introduce complexity for the build itself.
>
> Alice only needs `ERESTARTSYS` so far, as far as I understand, so
> perhaps it is simplest to only add the rest of the non-generic ones
> for the moment; and gather opinions on the approaches above meanwhile.

Let's add the ones we need for now. When we need target specific error
codes we can have a `mod` for each arch, gate behind the target
feature and conditionally reexport them.

BR Andreas


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] rust: error: add missing error codes
  2023-05-04  6:48 [PATCH v2] rust: error: add missing error codes Alice Ryhl
  2023-05-04 12:40 ` Martin Rodriguez Reboredo
  2023-05-08 11:47 ` Gary Guo
@ 2023-05-31 17:11 ` Miguel Ojeda
  2 siblings, 0 replies; 8+ messages in thread
From: Miguel Ojeda @ 2023-05-31 17:11 UTC (permalink / raw)
  To: Alice Ryhl
  Cc: Miguel Ojeda, Wedson Almeida Filho, Alex Gaynor, Boqun Feng,
	Gary Guo, Björn Roy Baron, Benno Lossin, rust-for-linux,
	linux-kernel, patches

On Thu, May 4, 2023 at 8:49 AM Alice Ryhl <aliceryhl@google.com> wrote:
>
> This adds the error codes from `include/linux/errno.h` to the list of
> Rust error constants. These errors were not included originally, because
> they are not supposed to be visible from userspace. However, they are
> still a perfectly valid error to use when writing a kernel driver. For
> example, you might want to return ERESTARTSYS if you receive a signal
> during a call to `schedule`.
>
> This patch inserts an annotation to skip rustfmt on the list of error
> codes. Without it, three of the error codes are split over several
> lines, which looks terribly inconsistent.
>
> Signed-off-by: Alice Ryhl <aliceryhl@google.com>

Applied to `rust-next` -- thanks everyone!

Cheers,
Miguel

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-05-31 17:11 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-04  6:48 [PATCH v2] rust: error: add missing error codes Alice Ryhl
2023-05-04 12:40 ` Martin Rodriguez Reboredo
2023-05-08 11:47 ` Gary Guo
2023-05-09  8:07   ` Alice Ryhl
2023-05-09  8:46     ` Greg KH
2023-05-09 11:10       ` Miguel Ojeda
2023-05-15 18:07         ` Andreas Hindborg
2023-05-31 17:11 ` Miguel Ojeda

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).