Skip to content

Commit

Permalink
rust: thread: Add Thread support
Browse files Browse the repository at this point in the history
Signed-off-by: Boqun Feng <[email protected]>
  • Loading branch information
fbq committed Apr 29, 2021
1 parent 4e54cd1 commit fe0c634
Show file tree
Hide file tree
Showing 21 changed files with 685 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,10 @@ jobs:
grep '] rust_sync: Rust synchronisation primitives sample (init)$' qemu-stdout.log
grep '] rust_sync: Rust synchronisation primitives sample (exit)$' qemu-stdout.log
- run: |
grep '] rust_thread: Rust thread APIs sample (init)$' qemu-stdout.log
grep '] rust_thread: Rust thread APIs sample (exit)$' qemu-stdout.log
- run: |
grep '] rust_chrdev: Rust character device sample (init)$' qemu-stdout.log
grep '] rust_chrdev: Rust character device sample (exit)$' qemu-stdout.log
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/kernel-arm-debug.config
Original file line number Diff line number Diff line change
Expand Up @@ -1660,6 +1660,7 @@ CONFIG_SAMPLE_RUST_MINIMAL=m
CONFIG_SAMPLE_RUST_PRINT=m
CONFIG_SAMPLE_RUST_MODULE_PARAMETERS=m
CONFIG_SAMPLE_RUST_SYNC=m
CONFIG_SAMPLE_RUST_THREAD=m
CONFIG_SAMPLE_RUST_CHRDEV=m
CONFIG_SAMPLE_RUST_MISCDEV=m
CONFIG_SAMPLE_RUST_STACK_PROBING=m
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/kernel-arm-release.config
Original file line number Diff line number Diff line change
Expand Up @@ -1584,6 +1584,7 @@ CONFIG_SAMPLE_RUST_MINIMAL=m
CONFIG_SAMPLE_RUST_PRINT=m
CONFIG_SAMPLE_RUST_MODULE_PARAMETERS=m
CONFIG_SAMPLE_RUST_SYNC=m
CONFIG_SAMPLE_RUST_THREAD=m
CONFIG_SAMPLE_RUST_CHRDEV=m
CONFIG_SAMPLE_RUST_MISCDEV=m
CONFIG_SAMPLE_RUST_STACK_PROBING=m
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/kernel-arm64-debug.config
Original file line number Diff line number Diff line change
Expand Up @@ -1426,6 +1426,7 @@ CONFIG_SAMPLE_RUST_MINIMAL=m
CONFIG_SAMPLE_RUST_PRINT=m
CONFIG_SAMPLE_RUST_MODULE_PARAMETERS=m
CONFIG_SAMPLE_RUST_SYNC=m
CONFIG_SAMPLE_RUST_THREAD=m
CONFIG_SAMPLE_RUST_CHRDEV=m
CONFIG_SAMPLE_RUST_MISCDEV=m
CONFIG_SAMPLE_RUST_STACK_PROBING=m
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/kernel-arm64-release.config
Original file line number Diff line number Diff line change
Expand Up @@ -1344,6 +1344,7 @@ CONFIG_SAMPLE_RUST_MINIMAL=m
CONFIG_SAMPLE_RUST_PRINT=m
CONFIG_SAMPLE_RUST_MODULE_PARAMETERS=m
CONFIG_SAMPLE_RUST_SYNC=m
CONFIG_SAMPLE_RUST_THREAD=m
CONFIG_SAMPLE_RUST_CHRDEV=m
CONFIG_SAMPLE_RUST_MISCDEV=m
CONFIG_SAMPLE_RUST_STACK_PROBING=m
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/kernel-ppc64le-debug.config
Original file line number Diff line number Diff line change
Expand Up @@ -1486,6 +1486,7 @@ CONFIG_SAMPLE_RUST_MINIMAL=m
CONFIG_SAMPLE_RUST_PRINT=m
CONFIG_SAMPLE_RUST_MODULE_PARAMETERS=m
CONFIG_SAMPLE_RUST_SYNC=m
CONFIG_SAMPLE_RUST_THREAD=m
CONFIG_SAMPLE_RUST_CHRDEV=m
CONFIG_SAMPLE_RUST_MISCDEV=m
CONFIG_SAMPLE_RUST_STACK_PROBING=m
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/kernel-ppc64le-release.config
Original file line number Diff line number Diff line change
Expand Up @@ -1448,6 +1448,7 @@ CONFIG_SAMPLE_RUST_MINIMAL=m
CONFIG_SAMPLE_RUST_PRINT=m
CONFIG_SAMPLE_RUST_MODULE_PARAMETERS=m
CONFIG_SAMPLE_RUST_SYNC=m
CONFIG_SAMPLE_RUST_THREAD=m
CONFIG_SAMPLE_RUST_CHRDEV=m
CONFIG_SAMPLE_RUST_MISCDEV=m
CONFIG_SAMPLE_RUST_STACK_PROBING=m
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/kernel-riscv64-debug.config
Original file line number Diff line number Diff line change
Expand Up @@ -1348,6 +1348,7 @@ CONFIG_SAMPLE_RUST_MINIMAL=m
CONFIG_SAMPLE_RUST_PRINT=m
CONFIG_SAMPLE_RUST_MODULE_PARAMETERS=m
CONFIG_SAMPLE_RUST_SYNC=m
CONFIG_SAMPLE_RUST_THREAD=m
CONFIG_SAMPLE_RUST_CHRDEV=m
CONFIG_SAMPLE_RUST_MISCDEV=m
CONFIG_SAMPLE_RUST_STACK_PROBING=m
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/kernel-riscv64-release.config
Original file line number Diff line number Diff line change
Expand Up @@ -1313,6 +1313,7 @@ CONFIG_SAMPLE_RUST_MINIMAL=m
CONFIG_SAMPLE_RUST_PRINT=m
CONFIG_SAMPLE_RUST_MODULE_PARAMETERS=m
CONFIG_SAMPLE_RUST_SYNC=m
CONFIG_SAMPLE_RUST_THREAD=m
CONFIG_SAMPLE_RUST_CHRDEV=m
CONFIG_SAMPLE_RUST_MISCDEV=m
CONFIG_SAMPLE_RUST_STACK_PROBING=m
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/kernel-x86_64-debug.config
Original file line number Diff line number Diff line change
Expand Up @@ -1438,6 +1438,7 @@ CONFIG_SAMPLE_RUST_MINIMAL=m
CONFIG_SAMPLE_RUST_PRINT=m
CONFIG_SAMPLE_RUST_MODULE_PARAMETERS=m
CONFIG_SAMPLE_RUST_SYNC=m
CONFIG_SAMPLE_RUST_THREAD=m
CONFIG_SAMPLE_RUST_CHRDEV=m
CONFIG_SAMPLE_RUST_MISCDEV=m
CONFIG_SAMPLE_RUST_STACK_PROBING=m
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/kernel-x86_64-release.config
Original file line number Diff line number Diff line change
Expand Up @@ -1386,6 +1386,7 @@ CONFIG_SAMPLE_RUST_MINIMAL=m
CONFIG_SAMPLE_RUST_PRINT=m
CONFIG_SAMPLE_RUST_MODULE_PARAMETERS=m
CONFIG_SAMPLE_RUST_SYNC=m
CONFIG_SAMPLE_RUST_THREAD=m
CONFIG_SAMPLE_RUST_CHRDEV=m
CONFIG_SAMPLE_RUST_MISCDEV=m
CONFIG_SAMPLE_RUST_STACK_PROBING=m
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/qemu-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ busybox rmmod rust_module_parameters.ko
busybox insmod rust_sync.ko
busybox rmmod rust_sync.ko

busybox insmod rust_thread.ko
busybox rmmod rust_thread.ko

busybox insmod rust_chrdev.ko
busybox rmmod rust_chrdev.ko

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/qemu-initramfs.desc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ file /rust_minimal.ko samples/rust/rust_minimal.ko 0755
file /rust_print.ko samples/rust/rust_print.ko 0755 0 0
file /rust_module_parameters.ko samples/rust/rust_module_parameters.ko 0755 0 0
file /rust_sync.ko samples/rust/rust_sync.ko 0755 0 0
file /rust_thread.ko samples/rust/rust_thread.ko 0755 0 0
file /rust_chrdev.ko samples/rust/rust_chrdev.ko 0755 0 0
file /rust_miscdev.ko samples/rust/rust_miscdev.ko 0755 0 0
file /rust_stack_probing.ko samples/rust/rust_stack_probing.ko 0755 0 0
Expand Down
13 changes: 13 additions & 0 deletions rust/helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <linux/build_bug.h>
#include <linux/uaccess.h>
#include <linux/sched/signal.h>
#include <linux/sched/task.h>
#include <linux/gfp.h>
#include <linux/highmem.h>
#include <linux/uio.h>
Expand Down Expand Up @@ -105,6 +106,18 @@ size_t rust_helper_copy_to_iter(const void *addr, size_t bytes, struct iov_iter
}
EXPORT_SYMBOL_GPL(rust_helper_copy_to_iter);

void rust_helper_get_task_struct(struct task_struct *task)
{
(void)get_task_struct(task);
}
EXPORT_SYMBOL(rust_helper_get_task_struct);

void rust_helper_put_task_struct(struct task_struct *task)
{
put_task_struct(task);
}
EXPORT_SYMBOL(rust_helper_put_task_struct);

#if !defined(CONFIG_ARM)
// See https://github.com/rust-lang/rust-bindgen/issues/1671
static_assert(__builtin_types_compatible_p(size_t, uintptr_t),
Expand Down
2 changes: 2 additions & 0 deletions rust/kernel/bindings_helper.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/* SPDX-License-Identifier: GPL-2.0 */

#include <linux/cdev.h>
#include <linux/err.h>
#include <linux/fs.h>
#include <linux/kthread.h>
#include <linux/module.h>
#include <linux/random.h>
#include <linux/slab.h>
Expand Down
6 changes: 3 additions & 3 deletions rust/kernel/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@ impl From<AllocError> for Error {
}
}

/// Convert a kernel pointer to [`KernelResult`]
/// Converts a kernel pointer to [`KernelResult`].
///
/// # Pointer value range
///
/// (According to include/linux/err.h)
/// According to `include/linux/err.h`,
/// [0, .., `core::usize::MAX - bindings::MAX_ERRNO`) is the range for normal values of pointer,
/// [`core::unsize::MAX - bindings::MAX_ERRNO`,..,`core::usize::MAX] is the range for error value
/// [`core::unsize::MAX - bindings::MAX_ERRNO`,..,`core::usize::MAX] is the range for error values
/// stored in pointer.
pub fn ptr_to_result<T>(ptr: *mut T) -> KernelResult<*mut T> {
let value = ptr as usize;
Expand Down
1 change: 1 addition & 0 deletions rust/kernel/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pub mod print;
pub mod random;
mod static_assert;
pub mod sync;
pub mod thread;

#[cfg(CONFIG_SYSCTL)]
pub mod sysctl;
Expand Down
Loading

0 comments on commit fe0c634

Please sign in to comment.