linux-stable/Documentation
Christian Brauner 0ede61d858
file: convert to SLAB_TYPESAFE_BY_RCU
In recent discussions around some performance improvements in the file
handling area we discussed switching the file cache to rely on
SLAB_TYPESAFE_BY_RCU which allows us to get rid of call_rcu() based
freeing for files completely. This is a pretty sensitive change overall
but it might actually be worth doing.

The main downside is the subtlety. The other one is that we should
really wait for Jann's patch to land that enables KASAN to handle
SLAB_TYPESAFE_BY_RCU UAFs. Currently it doesn't but a patch for this
exists.

With SLAB_TYPESAFE_BY_RCU objects may be freed and reused multiple times
which requires a few changes. So it isn't sufficient anymore to just
acquire a reference to the file in question under rcu using
atomic_long_inc_not_zero() since the file might have already been
recycled and someone else might have bumped the reference.

In other words, callers might see reference count bumps from newer
users. For this reason it is necessary to verify that the pointer is the
same before and after the reference count increment. This pattern can be
seen in get_file_rcu() and __files_get_rcu().

In addition, it isn't possible to access or check fields in struct file
without first aqcuiring a reference on it. Not doing that was always
very dodgy and it was only usable for non-pointer data in struct file.
With SLAB_TYPESAFE_BY_RCU it is necessary that callers first acquire a
reference under rcu or they must hold the files_lock of the fdtable.
Failing to do either one of this is a bug.

Thanks to Jann for pointing out that we need to ensure memory ordering
between reallocations and pointer check by ensuring that all subsequent
loads have a dependency on the second load in get_file_rcu() and
providing a fixup that was folded into this patch.

Cc: Jann Horn <jannh@google.com>
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2023-10-19 11:02:48 +02:00
..
ABI - Core Frameworks 2023-09-04 13:52:58 -07:00
accel
accounting
admin-guide perf tools changes for v6.6: 2023-09-09 20:06:17 -07:00
arch Add x86 shadow stack support 2023-08-31 12:20:12 -07:00
block Documentation work keeps chugging along; stuff for 6.6 includes: 2023-08-30 20:05:42 -07:00
bpf Including fixes from netfilter and bpf. 2023-09-07 18:33:07 -07:00
cdrom
core-api printk changes for 6.6 2023-09-04 13:20:19 -07:00
cpu-freq
crypto
dev-tools LoongArch changes for v6.6 2023-09-08 12:16:52 -07:00
devicetree RISC-V Patches for the 6.6 Merge Window, Part 2 (try 2) 2023-09-09 14:25:11 -07:00
doc-guide
driver-api ata changes for 6.6 2023-09-05 12:37:28 -07:00
fault-injection
fb
features LoongArch changes for v6.6 2023-09-08 12:16:52 -07:00
filesystems file: convert to SLAB_TYPESAFE_BY_RCU 2023-10-19 11:02:48 +02:00
firmware-guide Documentation work keeps chugging along; stuff for 6.6 includes: 2023-08-30 20:05:42 -07:00
firmware_class
fpga
gpu drm ci for 6.6-rc1 2023-09-10 11:55:26 -07:00
hid
hwmon Documentation work keeps chugging along; stuff for 6.6 includes: 2023-08-30 20:05:42 -07:00
i2c media updates for v6.6-rc1 2023-09-01 12:21:32 -07:00
iio
images
infiniband
input input: docs: pxrc: remove reference to phoenix-sim 2023-08-28 12:43:32 -06:00
isdn
kbuild Kbuild updates for v6.6 2023-09-05 11:01:47 -07:00
kernel-hacking
leds
litmus-tests
livepatch
locking
maintainer Documentation work keeps chugging along; stuff for 6.6 includes: 2023-08-30 20:05:42 -07:00
mhi
misc-devices
mm Add x86 shadow stack support 2023-08-31 12:20:12 -07:00
netlabel
netlink doc/netlink: Add spec for rt route messages 2023-08-27 17:17:11 -07:00
networking VFIO updates for v6.6-rc1 2023-08-30 20:36:01 -07:00
nvdimm
nvme
PCI Merge branch 'pci/misc' 2023-08-29 11:03:57 -05:00
pcmcia
peci
power
powerpc powerpc updates for 6.6 2023-08-31 12:43:10 -07:00
process Including fixes from netfilter and bpf. 2023-09-07 18:33:07 -07:00
RCU
riscv Merge patch series "RISC-V: Probe for misaligned access speed" 2023-09-08 11:24:12 -07:00
rust Documentation work keeps chugging along; stuff for 6.6 includes: 2023-08-30 20:05:42 -07:00
scheduler Documentation work keeps chugging along; stuff for 6.6 includes: 2023-08-30 20:05:42 -07:00
scsi SCSI misc on 20230902 2023-09-02 12:02:41 -07:00
security
sound ALSA: emu10k1: add separate documentation for E-MU cards 2023-08-26 09:25:17 +02:00
sphinx
sphinx-static
spi
staging
target
timers
tools
trace Probes updates for v6.6: 2023-09-02 11:10:50 -07:00
translations LoongArch changes for v6.6 2023-09-08 12:16:52 -07:00
usb USB / Thunderbolt / PHY driver update for 6.6-rc1 2023-09-01 09:23:34 -07:00
userspace-api Including fixes from netfilter and bpf. 2023-09-07 18:33:07 -07:00
virt ARM: 2023-09-07 13:52:20 -07:00
w1
watchdog
wmi Documentation work keeps chugging along; stuff for 6.6 includes: 2023-08-30 20:05:42 -07:00
.gitignore
atomic_bitops.txt
atomic_t.txt
Changes
CodingStyle
conf.py
docutils.conf
dontdiff
index.rst
Kconfig
Makefile
memory-barriers.txt
SubmittingPatches
subsystem-apis.rst