Skip to content

Allow SpinLockIrq to use a normal Guard interface

Boqun Feng lkml llvm oe-kbuild-all rust-for-linux 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest6 patches 26 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/6irq & spin_lock: Add counted interrupt disabling/enablinginclude/linux/irqflags.h include/linux/irqflags_types.h include/linux/spinlock.h +4 more+108 -116 replies
2/6rust: Introduce interrupt modulerust/helpers/helpers.c rust/helpers/interrupt.c rust/kernel/interrupt.rs +1 more+84 -02 replies
3/6rust: helper: Add spin_{un,}lock_irq_{enable,disable}() helpersrust/helpers/spinlock.c+10 -00 replies
4/6rust: sync: Add SpinLockIrqrust/kernel/sync.rs rust/kernel/sync/lock/spinlock.rs+92 -12 replies
5/6rust: sync: Introduce lock::Backend::Contextrust/kernel/sync/lock.rs rust/kernel/sync/lock/mutex.rs rust/kernel/sync/lock/spinlock.rs+15 -11 reply
6/6rust: sync: lock: Add `Backend::BackendInContext`rust/kernel/sync/lock.rs rust/kernel/sync/lock/mutex.rs rust/kernel/sync/lock/spinlock.rs+33 -20 replies

Reviews trailers per patch

None of the 6 patches has a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchAndreas HindborgDirk BehmeLyude Paul
SeriesT-b T-b R-b
1/6
2/6
3/6
4/6
5/6
6/6

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 3 reviewers.

Read the v1 thread

Cover letter [POC 0/6] Allow SpinLockIrq to use a normal Guard interface

Hi Thomas,

So this series is what I proposed, previously, because the nested interrupt API in C is local_irq_save() and local_irq_restore(), the following Rust code has the problem of enabling interrupt earlier:

	// l1 and l2 are interrupt disabling locks, their guards (i.e.
	// return of lock()) can be used to track interrupt state.

	// interrupts are enabled in the beginning.
	
	let g1 = l1.lock(); // previous interrupt state is enabled.
	let g2 = l2.lock(); // previous interrupt state is disabled.

	drop(g1); // release l1, if we use g1's state, interrupt will be
		  // enabled. But this is obviously wrong. Because g2
		  // can only exist with interrupt disabled.

With the new interrupt disable and enable API, instead of a "unsigned long", a percpu variable is used to track the outermost interrupt state and the nested level, so that "drop(g1);" above won't enable interrupts.

Although this requires extra cost, but I think it might be worth paying, because this could make Rust's SpinLockIrq simply use a guard interface as SpinLock.

Of course, looking for any comments and suggestions.

Boqun Feng (3):
irq & spin_lock: Add counted interrupt disabling/enabling
rust: helper: Add spin_{un,}lock_irq_{enable,disable}() helpers
rust: sync: lock: Add Backend::BackendInContext

Lyude Paul (3):
rust: Introduce interrupt module
rust: sync: Add SpinLockIrq
rust: sync: Introduce lock::Backend::Context

 include/linux/irqflags.h          |  32 +++++++++-
 include/linux/irqflags_types.h    |   6 ++
 include/linux/spinlock.h          |  13 ++++
 include/linux/spinlock_api_smp.h  |  29 +++++++++
 include/linux/spinlock_rt.h       |  10 +++
 kernel/locking/spinlock.c         |  16 +++++
 kernel/softirq.c                  |   3 +
 rust/helpers/helpers.c            |   1 +
 rust/helpers/interrupt.c          |  18 ++++++
 rust/helpers/spinlock.c           |  10 +++
 rust/kernel/interrupt.rs          |  64 +++++++++++++++++++
 rust/kernel/lib.rs                |   1 +
 rust/kernel/sync.rs               |   2 +-
 rust/kernel/sync/lock.rs          |  33 +++++++++-
 rust/kernel/sync/lock/mutex.rs    |   2 +
 rust/kernel/sync/lock/spinlock.rs | 103 ++++++++++++++++++++++++++++++
 16 files changed, 340 insertions(+), 3 deletions(-)
 create mode 100644 rust/helpers/interrupt.c
 create mode 100644 rust/kernel/interrupt.rs
Signature · 1 line
2.45.2