Skip to content

Commit 7d1b4ee

Browse files
committed
Merge branch 'bits/190-rust' into asahi-wip
2 parents d7b7c7f + 353d1a7 commit 7d1b4ee

56 files changed

Lines changed: 4435 additions & 151 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

MAINTAINERS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7383,6 +7383,7 @@ F: include/linux/property.h
73837383
F: include/linux/sysfs.h
73847384
F: lib/kobj*
73857385
F: rust/kernel/device.rs
7386+
F: rust/kernel/device/
73867387
F: rust/kernel/device_id.rs
73877388
F: rust/kernel/devres.rs
73887389
F: rust/kernel/driver.rs
@@ -16848,6 +16849,8 @@ F: include/linux/module*.h
1684816849
F: kernel/module/
1684916850
F: lib/test_kmod.c
1685016851
F: lib/tests/module/
16852+
F: rust/kernel/module_param.rs
16853+
F: rust/macros/module.rs
1685116854
F: scripts/module*
1685216855
F: tools/testing/selftests/kmod/
1685316856
F: tools/testing/selftests/module/

drivers/of/unittest-data/tests-platform.dtsi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
test-device@2 {
3838
compatible = "test,rust-device";
3939
reg = <0x2>;
40+
41+
test,u32-prop = <0xdeadbeef>;
42+
test,i16-array = /bits/ 16 <1 2 (-3) (-4)>;
4043
};
4144
};
4245

drivers/soc/apple/Kconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ config APPLE_SART
7474

7575
Say 'y' here if you have an Apple SoC.
7676

77+
config RUST_APPLE_RTKIT
78+
bool
79+
depends on RUST
80+
depends on APPLE_RTKIT
81+
7782
endmenu
7883

7984
endif

include/linux/xarray.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,8 @@ void *__xa_erase(struct xarray *, unsigned long index);
563563
void *__xa_store(struct xarray *, unsigned long index, void *entry, gfp_t);
564564
void *__xa_cmpxchg(struct xarray *, unsigned long index, void *old,
565565
void *entry, gfp_t);
566+
void *__xa_cmpxchg_raw(struct xarray *, unsigned long index, void *old,
567+
void *entry, gfp_t);
566568
int __must_check __xa_insert(struct xarray *, unsigned long index,
567569
void *entry, gfp_t);
568570
int __must_check __xa_alloc(struct xarray *, u32 *id, void *entry,

lib/xarray.c

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1738,9 +1738,6 @@ void *xa_store(struct xarray *xa, unsigned long index, void *entry, gfp_t gfp)
17381738
}
17391739
EXPORT_SYMBOL(xa_store);
17401740

1741-
static inline void *__xa_cmpxchg_raw(struct xarray *xa, unsigned long index,
1742-
void *old, void *entry, gfp_t gfp);
1743-
17441741
/**
17451742
* __xa_cmpxchg() - Conditionally replace an entry in the XArray.
17461743
* @xa: XArray.
@@ -1767,7 +1764,29 @@ void *__xa_cmpxchg(struct xarray *xa, unsigned long index,
17671764
}
17681765
EXPORT_SYMBOL(__xa_cmpxchg);
17691766

1770-
static inline void *__xa_cmpxchg_raw(struct xarray *xa, unsigned long index,
1767+
/**
1768+
* __xa_cmpxchg_raw() - Conditionally replace an entry in the XArray.
1769+
* @xa: XArray.
1770+
* @index: Index into array.
1771+
* @old: Old value to test against.
1772+
* @entry: New value to place in array.
1773+
* @gfp: Memory allocation flags.
1774+
*
1775+
* You must already be holding the xa_lock when calling this function.
1776+
* It will drop the lock if needed to allocate memory, and then reacquire
1777+
* it afterwards.
1778+
*
1779+
* If the entry at @index is the same as @old, replace it with @entry.
1780+
* If the return value is equal to @old, then the exchange was successful.
1781+
*
1782+
* This function is the same as __xa_cmpxchg() except that it does not coerce
1783+
* XA_ZERO_ENTRY to NULL on egress.
1784+
*
1785+
* Context: Any context. Expects xa_lock to be held on entry. May
1786+
* release and reacquire xa_lock if @gfp flags permit.
1787+
* Return: The old value at this index or xa_err() if an error happened.
1788+
*/
1789+
void *__xa_cmpxchg_raw(struct xarray *xa, unsigned long index,
17711790
void *old, void *entry, gfp_t gfp)
17721791
{
17731792
XA_STATE(xas, xa, index);
@@ -1787,6 +1806,7 @@ static inline void *__xa_cmpxchg_raw(struct xarray *xa, unsigned long index,
17871806

17881807
return xas_result(&xas, curr);
17891808
}
1809+
EXPORT_SYMBOL(__xa_cmpxchg_raw);
17901810

17911811
/**
17921812
* __xa_insert() - Store this entry in the XArray if no entry is present.

rust/Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -528,17 +528,19 @@ $(obj)/ffi.o: private skip_gendwarfksyms = 1
528528
$(obj)/ffi.o: $(src)/ffi.rs $(obj)/compiler_builtins.o FORCE
529529
+$(call if_changed_rule,rustc_library)
530530

531-
$(obj)/bindings.o: private rustc_target_flags = --extern ffi
531+
$(obj)/bindings.o: private rustc_target_flags = --extern ffi --extern pin_init
532532
$(obj)/bindings.o: $(src)/bindings/lib.rs \
533533
$(obj)/ffi.o \
534+
$(obj)/pin_init.o \
534535
$(obj)/bindings/bindings_generated.rs \
535536
$(obj)/bindings/bindings_helpers_generated.rs FORCE
536537
+$(call if_changed_rule,rustc_library)
537538

538-
$(obj)/uapi.o: private rustc_target_flags = --extern ffi
539+
$(obj)/uapi.o: private rustc_target_flags = --extern ffi --extern pin_init
539540
$(obj)/uapi.o: private skip_gendwarfksyms = 1
540541
$(obj)/uapi.o: $(src)/uapi/lib.rs \
541542
$(obj)/ffi.o \
543+
$(obj)/pin_init.o \
542544
$(obj)/uapi/uapi_generated.rs FORCE
543545
+$(call if_changed_rule,rustc_library)
544546

rust/bindgen_parameters

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,7 @@
3434
# We use const helpers to aid bindgen, to avoid conflicts when constants are
3535
# recognized, block generation of the non-helper constants.
3636
--blocklist-item ARCH_SLAB_MINALIGN
37+
38+
# Structs should implement Zeroable when all of their fields do.
39+
--with-derive-custom-struct .*=MaybeZeroable
40+
--with-derive-custom-union .*=MaybeZeroable

rust/bindings/bindings_helper.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,15 @@
5252
#include <linux/file.h>
5353
#include <linux/firmware.h>
5454
#include <linux/fs.h>
55+
#include <linux/ioport.h>
5556
#include <linux/jiffies.h>
5657
#include <linux/jump_label.h>
5758
#include <linux/mdio.h>
5859
#include <linux/miscdevice.h>
60+
#include <linux/of.h>
61+
#include <linux/of_address.h>
5962
#include <linux/of_device.h>
63+
#include <linux/of_reserved_mem.h>
6064
#include <linux/pci.h>
6165
#include <linux/phy.h>
6266
#include <linux/pid_namespace.h>
@@ -68,6 +72,7 @@
6872
#include <linux/sched.h>
6973
#include <linux/security.h>
7074
#include <linux/slab.h>
75+
#include <linux/soc/apple/rtkit.h>
7176
#include <linux/tracepoint.h>
7277
#include <linux/wait.h>
7378
#include <linux/workqueue.h>

rust/bindings/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,19 @@
2828
#[allow(clippy::undocumented_unsafe_blocks)]
2929
#[cfg_attr(CONFIG_RUSTC_HAS_UNNECESSARY_TRANSMUTES, allow(unnecessary_transmutes))]
3030
mod bindings_raw {
31+
use pin_init::{MaybeZeroable, Zeroable};
32+
3133
// Manual definition for blocklisted types.
3234
type __kernel_size_t = usize;
3335
type __kernel_ssize_t = isize;
3436
type __kernel_ptrdiff_t = isize;
3537

38+
// `bindgen` doesn't automatically do this, see
39+
// <https://github.com/rust-lang/rust-bindgen/issues/3196>
40+
//
41+
// SAFETY: `__BindgenBitfieldUnit<Storage>` is a newtype around `Storage`.
42+
unsafe impl<Storage> Zeroable for __BindgenBitfieldUnit<Storage> where Storage: Zeroable {}
43+
3644
// Use glob import here to expose all helpers.
3745
// Symbols defined within the module will take precedence to the glob import.
3846
pub use super::bindings_helper::*;

rust/helpers/device.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,13 @@ int rust_helper_devm_add_action(struct device *dev,
88
{
99
return devm_add_action(dev, action, data);
1010
}
11+
12+
void rust_helper_device_lock(struct device *dev)
13+
{
14+
device_lock(dev);
15+
}
16+
17+
void rust_helper_device_unlock(struct device *dev)
18+
{
19+
device_unlock(dev);
20+
}

0 commit comments

Comments
 (0)