| Commit message (Collapse) | Author | Age | Files | Lines |
|
|
|
|
|
|
| |
The minimal sample merged upstream used `Vec` instead of
`String` in order to minimize `alloc` further.
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
|
|
|
|
|
|
|
|
|
|
|
| |
When `Ref` was first introduced, we still had `alloc`'s `Arc` being used
in the codebase, so we chose a different name. Now that `Arc` is gone,
we can reclaim the name, which is desirable because it is consistent
with userspace.
This is a pure refactor with no functional changes intended.
Signed-off-by: Wedson Almeida Filho <wedsonaf@gmail.com>
|
|\
| |
| | |
rust: add missing dependency to rust netfilter sample
|
| |
| |
| |
| | |
Signed-off-by: Gary Guo <gary@garyguo.net>
|
|/
|
|
|
|
|
|
|
|
|
| |
For simplicity (avoid parsing), escape sequences and raw string literals
are not yet handled.
Module names, aliases and license strings are restricted to ASCII only.
Link: https://github.com/Rust-for-Linux/linux/issues/252
Link: https://lore.kernel.org/lkml/YukvvPOOu8uZl7+n@yadro.com/
Signed-off-by: Gary Guo <gary@garyguo.net>
|
|
|
|
|
|
|
| |
This reduces the amount of code needed to implement a module that
only implements a file system.
Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
|
|
|
|
|
|
|
|
|
|
|
|
| |
They are also allowed to specify the type of superblock keying.
With this change, drivers get a new callback, `fill_super`, that they
need to implement to initialise new superblocks.
In subsequent commits, they'll be able to populate the root with
entries, but for now it's empty.
Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
|
|
|
|
|
|
|
| |
This allows file system contexts to be further initialised with
parameters from userspace before a fs is mounted or reconfigured.
Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
|
|
|
|
|
|
|
|
| |
This brings it in line with other cases (e.g., `irq::flags`,
`fs::flags`, `mm::virt::flags`) and allows users to `use` all constants
at once, for example, `use kernel::file::flags::*` if they so choose.
Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
|
|\ |
|
| |
| |
| |
| |
| |
| | |
Also make fs mountable, but empty for now.
Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
|
| |
| |
| |
| |
| |
| |
| | |
This provides a temporary place to put "pure tests" for Rust
funtionality and wrappers.
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
|
| |
| |
| |
| |
| |
| |
| |
| |
| | |
Also add sample that uses the new public API. The registered file system
cannot be mounted yet, but can be seen in /proc/filesystems.
More functionality will be added in subsequent commits.
Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
|
| |
| |
| |
| | |
Signed-off-by: Gary Guo <gary@garyguo.net>
|
| |
| |
| |
| |
| |
| |
| | |
This example uses Rust async for the server and a workqueue-based
executor to run async tasks.
Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
For Rust, the `module!` macro is best placed in the beginning
of the file, since it gives general information about the module,
nearby the documentation.
This also makes it consistent with the other samples.
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
Since commit bf7fbeeae6db ("module: Cure the MODULE_LICENSE "GPL" vs.
"GPL v2" bogosity"), Documentation/process/license-rules.rst explains
that `MODULE_LICENSE` arguments can simply use `GPL` instead of `GPL v2`,
because it is not meant to replace the proper licensing information.
Since the `license:` field of the `module!` macro is the same as
`MODULE_LICENSE`, use the simpler form in Rust too.
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
|
| |
| |
| |
| |
| |
| |
| | |
It just prints the head and total lengths plus the first 10 bytes of the
IPv4/IPv6 packets received and sent.
Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
|
| |
| |
| |
| |
| |
| |
| |
| | |
Since it's already in the `kernel` crate, prefixing it with `Kernel` is
redundant. This is also for consistency with other types (e.g., we
renamed `KernelResult` to `Result`).
Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
This is so that we can `use` them with a wildcard (which we do in the
prelude), which allows us to simplify expressions like
`Err(Error::EINVAL)` to `Err(EINVAL)`.
This is a pure refactor, no functional changes are intended.
Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
|
| |
| |
| |
| |
| |
| |
| |
| |
| | |
This is to avoid repeating the "file" prefix and for consistency with
other modules that also have operations like `power::Operations`.
This is a pure refactor, no functional changes are intended.
Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
This is for the associated type to have a clearer meaning, and to bring
it in line with other traits like `irq::Chip` and `gpio::Chip` where the
context data type is simply `Data`.
This is a pure refactor with no functional changes intended.
Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
This allows us to use Rust for any scripts used during compilation
as long as Rust is already available, instead of e.g. C, shell
scripts or Perl (Python does not seem to be required for compilation,
which would be another natural & modern option to consider).
After all, Rust is a good language for scripts too and the goal is to
have first-class support for Rust in the kernel, so one should be able
to write host programs in it too, just like with C. Not to mention
the other benefits (e.g. static typing) compared to the currently
available options. Eventually, if having a Rust toolchain ever becomes
mandatory (whether or not Rust support is optional and/or enabled),
this becomes even a better idea. Ideally, other kernel developers
will also want to start using Rust for kernel tooling, which may help
making that happen.
A downside of Rust for this use case is `rustc`'s compilation speed,
which may become concerning if e.g. a lot of programs are used.
Another downside, shared with C, is the small standard library.
I considered adding C object linking support, but it requires creating
an archive of the C objects just for linking and a bunch of other bits
which become hard to justify when we do not have a current use case
for it. Like above, if having a Rust toolchain ever becomes mandatory
for kernel compilation, then finding a use case where C code is needed
becomes much easier. Or even the other way around, we could take
advantage of Rust inside existing C programs, too.
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
|
|/
|
|
|
|
|
|
| |
The previous commit adds a generic way to check file flags. Better not
to have two ways to do the same thing, especially when the second way is
highly specialized.
Signed-off-by: Daniel Xu <dxu@dxuuu.xyz>
|
|
|
|
|
|
|
|
|
|
|
| |
The registration now holds an owned C string while the miscdev is
registered, and frees it on drop.
Now names are formatted with the `fmt` macro instead of being static
C strings. This enables scenarios when the device name is constructed at
runtime, i.e., where a static C string does not exist.
Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
|
|\
| |
| | |
samples/rust: add static mutex and condvar to sync sample
|
| |
| |
| |
| |
| |
| |
| | |
The sample includes local instances, this patch adds an example of how
to use static mutexes and conditional varibles.
Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
|
|/
|
|
|
|
|
|
|
|
|
|
| |
Includes: capitalization, end of sentence/title periods,
list marker and list indentation.
Also included a fix for a spurious space and missing code quotes.
No change in content intended otherwise.
`alloc` is excluded since we try not to diverge from upstream.
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
|
|
|
|
|
|
|
|
| |
We introduce the `Options` type that holds the optional paremeters.
Users who want to specify them do so by calling methods on the `Options`
instance followed by a call to `register` or `register_new`.
Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Instead of enabling the features per-module, do it globally.
This removes the need to write boilerplate such as `#![no_std]`
in kernel modules, which does not bring much value given
the allowed features are constrained anyway.
There is the question of whether to enable only the most common ones
(`allocator_api` and `global_asm`) in order to easily see uncommon
features being used. However, we only have other three features,
and they are either going to get stabilized/workarounded/removed
at some point and/or they are easy to spot anyway.
We are using `-Zcrate-attr` for convenience here, but we do not
really depend on it: like for other unstable features, if this was
the last feature to get stabilized, we would simply workaround it.
Furthermore, it is likely we will change how modules are compiled
in a way that makes this not needed.
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
|
|
|
|
|
|
|
|
| |
This is a minimal sample of registering a driver for a platform device.
The driver doesn't really do anything, and serves as a template for
future new platform drivers.
Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
|
|
|
|
|
|
|
|
|
|
|
|
| |
This is a requirement because a shared reference to the context data can
be used in arbitrary threads (requires `Sync`) and it can be destroyed
in an arbitrary read (requires `Send`), whenever the refcount on the
file goes to zero.
We change the default to `()` so that we don't have to impose the same
requirements on `Self`.
Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
|
|
|
|
|
|
|
|
|
|
|
|
| |
It is currently used to allow a single `FileOperations` implementation
to be shared by multiple `FileOpener` instances. But Binder is the only
intended user I've seen so far.
So we have the extra complexity because of a single exceptional case.
This commit simplifies things for the majority: they just need to
implement `FileOperations::open`.
Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
|
|
|
|
|
|
|
|
| |
This is for cases when drivers need to get information from `File`
during `open`, for example, the credentials. Such a need occurs is
Binder.
Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
|
|
|
|
|
|
|
|
|
|
| |
The feature, although still unstable, is no longer incomplete. It
allows us to use a lifetime in the `Borrow` assocciated type, which
allows us to simplify some of the code around borrowing the wrapped
value and also allows us to wrap raw pointers and integers without
violating `Deref` recommendations.
Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
|
|
|
|
| |
Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
|
|\
| |
| | |
rust: remove instances of `Pin<Ref<T>>`.
|
| |
| |
| |
| |
| |
| | |
Since `Ref<T>` is already pinned, there is no need to wrap it in `Pin`.
Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
|
|/
|
|
|
|
|
|
| |
Now that the trait signature of KernelModule has changed, we can add
the necessary deps to the prelude considering they'll be needed in each
non-specialized module init
Signed-off-by: Milan <milan@mdaverde.com>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
These changes allow the init of modules to be implemented in other
modules (e.g., the main kernel crate, which isn't a separate module).
This, in turn, allows us to define module macros for specific types of
modules without procmacros (albeit with the limitation that `type` must
be the first parameter).
As an example, I redefined `module_misc_device` as a regular macro.
This is in preparation for adding macros for pci, amba, and platform
modules without the need for more procmacros.
Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
|
|
|
|
|
|
|
|
| |
This removes the need to explicitly declare a generic parameter.
Although it is just syntactic sugar, it looks less intimidating to
readers not familiar with Rust.
Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
|
|
|
|
| |
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
|
|
|
|
|
|
|
|
|
| |
In preparation for enabling `no_global_oom_handling` for `alloc`,
we need to stop using methods that will disappear when enabling
the configuration option. Instead, we use the new methods
we just added.
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
|
|
|
|
|
|
|
| |
This prevents initialising synchronisation primitives when there are
multiple references to them.
Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
|
|
|
|
|
|
|
|
|
|
|
| |
In the `init_with_lockdep` macro, the macros were evaluated inside an
unsafe block, so they could contain unsafe operations without requiring
an explicit unsafe block on the call site.
Fixed by evaluating `$obj` and `$name` outside an unsafe block.
Reported-by: Sven Van Asbroeck <thesven73@gmail.com>
Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
|
|
|
|
| |
Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
|
|
|
|
|
|
|
|
| |
This is similar to a previous change to `FileOperations`. It is in
preparation for allowing ioctl handlers to take `&Ref<T>` as the first
argument, which will be needed in a subsequent change to `Ref<T>`.
Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
|
|
|
|
|
|
|
|
|
|
|
|
| |
This allows `FileOperations` implementers to have arbitrary (wrapped)
values as `private_data` (as opposed to only wrapped `Self`).
It also allows wrappers to dictate the borrowed type. For now all
wrappers of `T` just borrow `&T`, but in a subsequent PR `Ref<T>` will
borrow to `&Ref<T>`, which allows implementations to increment the
refcount.
Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
|
|
|
|
|
|
|
|
| |
Includes rust-lang/rust#83592, rust-lang/rust#85276 and
rust-lang/rust#85700 which are needed to build correctly again after
rustc's upgrade to LLVM 12.
Signed-off-by: Boris-Chengbiao Zhou <bobo1239@web.de>
|
|
|
|
|
|
|
| |
`pr_cont` is a discouraged feature. While we still support it in
print.rs, remove it from the prelude so it's less likely to get used.
Signed-off-by: Gary Guo <gary@garyguo.net>
|