Page MenuHomeFreeBSD

Reduce chance of RCU deadlock in the LinuxKPI by implementing the section feature of the concurrency kit, CK.
ClosedPublic

Authored by hselasky on Mar 28 2021, 7:41 AM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Apr 1, 1:14 PM
Unknown Object (File)
Feb 2 2024, 3:38 AM
Unknown Object (File)
Jan 10 2024, 4:21 AM
Unknown Object (File)
Jan 10 2024, 4:21 AM
Unknown Object (File)
Jan 10 2024, 4:21 AM
Unknown Object (File)
Jan 10 2024, 4:21 AM
Unknown Object (File)
Jan 10 2024, 4:09 AM
Unknown Object (File)
Jan 5 2024, 5:43 PM
Subscribers

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

sys/compat/linuxkpi/common/include/linux/sched.h
85

rcu_section should have ck_epoch_section_t[] type and not unsigned int[].

If there are issues with inclusion of ck_epoch.h into sched.h, then some way to ensure the type equality should be established.

sys/compat/linuxkpi/common/src/linux_rcu.c
203

You should assert that the increment does not overflow.

241

You need to assert that rcu_recurse[type] > 0 before decrement.

255

This container_of() was quite puzzling to me until I realized that it is in fact a type cast. See my note near rcu_section[].

hselasky added inline comments.
sys/compat/linuxkpi/common/include/linux/sched.h
85

See my comment in the end.

sys/compat/linuxkpi/common/src/linux_rcu.c
255

Changed into a regular cast. The problem is that EPOCH header files do not live under sys/ and require special C-flags currently.

kib added inline comments.
sys/compat/linuxkpi/common/src/linux_rcu.c
94

New code should prefer _Static_assert() over CTASSERT().

This revision is now accepted and ready to land.Mar 28 2021, 2:50 PM

Why exactly does the RCU implementation not use epoch(9) directly?

sys/compat/linuxkpi/common/src/linux_rcu.c
222–224

Is this line too long?

Why exactly does the RCU implementation not use epoch(9) directly?

@markj: Because EPOCH(9) is not sleepable.

This revision now requires review to proceed.Mar 28 2021, 3:37 PM
hselasky added inline comments.
sys/compat/linuxkpi/common/src/linux_rcu.c
94

The style in LinuxKPI is CTASSERT() for now.

Why exactly does the RCU implementation not use epoch(9) directly?

@markj: Because EPOCH(9) is not sleepable.

Neither is RCU. "Sleepable" RCU corresponds to "bounded sleep" in FreeBSD (per the definition in locking.9), and preemptible epoch sections permit that already. Do we have some code which expects to perform unbounded sleep in an SRCU read section?

The change looks ok to me in any case.

This revision is now accepted and ready to land.Mar 28 2021, 4:50 PM

Neither is RCU. "Sleepable" RCU corresponds to "bounded sleep" in FreeBSD (per the definition in locking.9), and preemptible epoch sections permit that already.

Even if this problem is solved, there would be an issue with the epoch tracker structure, that RCU has no such equivalent.
Keep in mind that the LinuxKPI "lowers" mutexes one level. spinlock->mutex, mutex->sxlock and so on.

I need to check if Linux allows mutexes inside RCU. If so, we need sleepable support.

Do we have some code which expects to perform unbounded sleep in an SRCU read section?

There is some code which use SRCU, and it can sleep for a while, blocking the synchronize function of course.
The logic in RCU in FreeBSD is a bit different than with EPOCH. I understand it would be great if the two could merge, but I'm not sure how.

--HPS