Skip to content

Commit fe0c634

Browse files
committed
rust: thread: Add Thread support
Signed-off-by: Boqun Feng <[email protected]>
1 parent 4e54cd1 commit fe0c634

21 files changed

+685
-3
lines changed

.github/workflows/ci.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,10 @@ jobs:
304304
grep '] rust_sync: Rust synchronisation primitives sample (init)$' qemu-stdout.log
305305
grep '] rust_sync: Rust synchronisation primitives sample (exit)$' qemu-stdout.log
306306
307+
- run: |
308+
grep '] rust_thread: Rust thread APIs sample (init)$' qemu-stdout.log
309+
grep '] rust_thread: Rust thread APIs sample (exit)$' qemu-stdout.log
310+
307311
- run: |
308312
grep '] rust_chrdev: Rust character device sample (init)$' qemu-stdout.log
309313
grep '] rust_chrdev: Rust character device sample (exit)$' qemu-stdout.log

.github/workflows/kernel-arm-debug.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1660,6 +1660,7 @@ CONFIG_SAMPLE_RUST_MINIMAL=m
16601660
CONFIG_SAMPLE_RUST_PRINT=m
16611661
CONFIG_SAMPLE_RUST_MODULE_PARAMETERS=m
16621662
CONFIG_SAMPLE_RUST_SYNC=m
1663+
CONFIG_SAMPLE_RUST_THREAD=m
16631664
CONFIG_SAMPLE_RUST_CHRDEV=m
16641665
CONFIG_SAMPLE_RUST_MISCDEV=m
16651666
CONFIG_SAMPLE_RUST_STACK_PROBING=m

.github/workflows/kernel-arm-release.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,6 +1584,7 @@ CONFIG_SAMPLE_RUST_MINIMAL=m
15841584
CONFIG_SAMPLE_RUST_PRINT=m
15851585
CONFIG_SAMPLE_RUST_MODULE_PARAMETERS=m
15861586
CONFIG_SAMPLE_RUST_SYNC=m
1587+
CONFIG_SAMPLE_RUST_THREAD=m
15871588
CONFIG_SAMPLE_RUST_CHRDEV=m
15881589
CONFIG_SAMPLE_RUST_MISCDEV=m
15891590
CONFIG_SAMPLE_RUST_STACK_PROBING=m

.github/workflows/kernel-arm64-debug.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,6 +1426,7 @@ CONFIG_SAMPLE_RUST_MINIMAL=m
14261426
CONFIG_SAMPLE_RUST_PRINT=m
14271427
CONFIG_SAMPLE_RUST_MODULE_PARAMETERS=m
14281428
CONFIG_SAMPLE_RUST_SYNC=m
1429+
CONFIG_SAMPLE_RUST_THREAD=m
14291430
CONFIG_SAMPLE_RUST_CHRDEV=m
14301431
CONFIG_SAMPLE_RUST_MISCDEV=m
14311432
CONFIG_SAMPLE_RUST_STACK_PROBING=m

.github/workflows/kernel-arm64-release.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,6 +1344,7 @@ CONFIG_SAMPLE_RUST_MINIMAL=m
13441344
CONFIG_SAMPLE_RUST_PRINT=m
13451345
CONFIG_SAMPLE_RUST_MODULE_PARAMETERS=m
13461346
CONFIG_SAMPLE_RUST_SYNC=m
1347+
CONFIG_SAMPLE_RUST_THREAD=m
13471348
CONFIG_SAMPLE_RUST_CHRDEV=m
13481349
CONFIG_SAMPLE_RUST_MISCDEV=m
13491350
CONFIG_SAMPLE_RUST_STACK_PROBING=m

.github/workflows/kernel-ppc64le-debug.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,6 +1486,7 @@ CONFIG_SAMPLE_RUST_MINIMAL=m
14861486
CONFIG_SAMPLE_RUST_PRINT=m
14871487
CONFIG_SAMPLE_RUST_MODULE_PARAMETERS=m
14881488
CONFIG_SAMPLE_RUST_SYNC=m
1489+
CONFIG_SAMPLE_RUST_THREAD=m
14891490
CONFIG_SAMPLE_RUST_CHRDEV=m
14901491
CONFIG_SAMPLE_RUST_MISCDEV=m
14911492
CONFIG_SAMPLE_RUST_STACK_PROBING=m

.github/workflows/kernel-ppc64le-release.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,6 +1448,7 @@ CONFIG_SAMPLE_RUST_MINIMAL=m
14481448
CONFIG_SAMPLE_RUST_PRINT=m
14491449
CONFIG_SAMPLE_RUST_MODULE_PARAMETERS=m
14501450
CONFIG_SAMPLE_RUST_SYNC=m
1451+
CONFIG_SAMPLE_RUST_THREAD=m
14511452
CONFIG_SAMPLE_RUST_CHRDEV=m
14521453
CONFIG_SAMPLE_RUST_MISCDEV=m
14531454
CONFIG_SAMPLE_RUST_STACK_PROBING=m

.github/workflows/kernel-riscv64-debug.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,6 +1348,7 @@ CONFIG_SAMPLE_RUST_MINIMAL=m
13481348
CONFIG_SAMPLE_RUST_PRINT=m
13491349
CONFIG_SAMPLE_RUST_MODULE_PARAMETERS=m
13501350
CONFIG_SAMPLE_RUST_SYNC=m
1351+
CONFIG_SAMPLE_RUST_THREAD=m
13511352
CONFIG_SAMPLE_RUST_CHRDEV=m
13521353
CONFIG_SAMPLE_RUST_MISCDEV=m
13531354
CONFIG_SAMPLE_RUST_STACK_PROBING=m

.github/workflows/kernel-riscv64-release.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,6 +1313,7 @@ CONFIG_SAMPLE_RUST_MINIMAL=m
13131313
CONFIG_SAMPLE_RUST_PRINT=m
13141314
CONFIG_SAMPLE_RUST_MODULE_PARAMETERS=m
13151315
CONFIG_SAMPLE_RUST_SYNC=m
1316+
CONFIG_SAMPLE_RUST_THREAD=m
13161317
CONFIG_SAMPLE_RUST_CHRDEV=m
13171318
CONFIG_SAMPLE_RUST_MISCDEV=m
13181319
CONFIG_SAMPLE_RUST_STACK_PROBING=m

.github/workflows/kernel-x86_64-debug.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,6 +1438,7 @@ CONFIG_SAMPLE_RUST_MINIMAL=m
14381438
CONFIG_SAMPLE_RUST_PRINT=m
14391439
CONFIG_SAMPLE_RUST_MODULE_PARAMETERS=m
14401440
CONFIG_SAMPLE_RUST_SYNC=m
1441+
CONFIG_SAMPLE_RUST_THREAD=m
14411442
CONFIG_SAMPLE_RUST_CHRDEV=m
14421443
CONFIG_SAMPLE_RUST_MISCDEV=m
14431444
CONFIG_SAMPLE_RUST_STACK_PROBING=m

.github/workflows/kernel-x86_64-release.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,6 +1386,7 @@ CONFIG_SAMPLE_RUST_MINIMAL=m
13861386
CONFIG_SAMPLE_RUST_PRINT=m
13871387
CONFIG_SAMPLE_RUST_MODULE_PARAMETERS=m
13881388
CONFIG_SAMPLE_RUST_SYNC=m
1389+
CONFIG_SAMPLE_RUST_THREAD=m
13891390
CONFIG_SAMPLE_RUST_CHRDEV=m
13901391
CONFIG_SAMPLE_RUST_MISCDEV=m
13911392
CONFIG_SAMPLE_RUST_STACK_PROBING=m

.github/workflows/qemu-init.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ busybox rmmod rust_module_parameters.ko
1212
busybox insmod rust_sync.ko
1313
busybox rmmod rust_sync.ko
1414

15+
busybox insmod rust_thread.ko
16+
busybox rmmod rust_thread.ko
17+
1518
busybox insmod rust_chrdev.ko
1619
busybox rmmod rust_chrdev.ko
1720

.github/workflows/qemu-initramfs.desc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ file /rust_minimal.ko samples/rust/rust_minimal.ko 0755
99
file /rust_print.ko samples/rust/rust_print.ko 0755 0 0
1010
file /rust_module_parameters.ko samples/rust/rust_module_parameters.ko 0755 0 0
1111
file /rust_sync.ko samples/rust/rust_sync.ko 0755 0 0
12+
file /rust_thread.ko samples/rust/rust_thread.ko 0755 0 0
1213
file /rust_chrdev.ko samples/rust/rust_chrdev.ko 0755 0 0
1314
file /rust_miscdev.ko samples/rust/rust_miscdev.ko 0755 0 0
1415
file /rust_stack_probing.ko samples/rust/rust_stack_probing.ko 0755 0 0

rust/helpers.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <linux/build_bug.h>
55
#include <linux/uaccess.h>
66
#include <linux/sched/signal.h>
7+
#include <linux/sched/task.h>
78
#include <linux/gfp.h>
89
#include <linux/highmem.h>
910
#include <linux/uio.h>
@@ -105,6 +106,18 @@ size_t rust_helper_copy_to_iter(const void *addr, size_t bytes, struct iov_iter
105106
}
106107
EXPORT_SYMBOL_GPL(rust_helper_copy_to_iter);
107108

109+
void rust_helper_get_task_struct(struct task_struct *task)
110+
{
111+
(void)get_task_struct(task);
112+
}
113+
EXPORT_SYMBOL(rust_helper_get_task_struct);
114+
115+
void rust_helper_put_task_struct(struct task_struct *task)
116+
{
117+
put_task_struct(task);
118+
}
119+
EXPORT_SYMBOL(rust_helper_put_task_struct);
120+
108121
#if !defined(CONFIG_ARM)
109122
// See https://github.com/rust-lang/rust-bindgen/issues/1671
110123
static_assert(__builtin_types_compatible_p(size_t, uintptr_t),

rust/kernel/bindings_helper.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
/* SPDX-License-Identifier: GPL-2.0 */
22

33
#include <linux/cdev.h>
4+
#include <linux/err.h>
45
#include <linux/fs.h>
6+
#include <linux/kthread.h>
57
#include <linux/module.h>
68
#include <linux/random.h>
79
#include <linux/slab.h>

rust/kernel/error.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,13 @@ impl From<AllocError> for Error {
106106
}
107107
}
108108

109-
/// Convert a kernel pointer to [`KernelResult`]
109+
/// Converts a kernel pointer to [`KernelResult`].
110110
///
111111
/// # Pointer value range
112112
///
113-
/// (According to include/linux/err.h)
113+
/// According to `include/linux/err.h`,
114114
/// [0, .., `core::usize::MAX - bindings::MAX_ERRNO`) is the range for normal values of pointer,
115-
/// [`core::unsize::MAX - bindings::MAX_ERRNO`,..,`core::usize::MAX] is the range for error value
115+
/// [`core::unsize::MAX - bindings::MAX_ERRNO`,..,`core::usize::MAX] is the range for error values
116116
/// stored in pointer.
117117
pub fn ptr_to_result<T>(ptr: *mut T) -> KernelResult<*mut T> {
118118
let value = ptr as usize;

rust/kernel/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ pub mod print;
5555
pub mod random;
5656
mod static_assert;
5757
pub mod sync;
58+
pub mod thread;
5859

5960
#[cfg(CONFIG_SYSCTL)]
6061
pub mod sysctl;

0 commit comments

Comments
 (0)