Re: [PATCH 4/8] mm/swap: Use local_lock for protection

Matthew Wilcox
2020-05-20T02:17:42Z

On Tue, May 19, 2020 at 04:58:37PM -0700, Andrew Morton wrote:
> On Tue, 19 May 2020 22:19:08 +0200 Sebastian Andrzej Siewior <bigeasy@linutronix.de> wrote:
> > + local_lock(swapvec_lock);
>
> It's quite peculiar that these operations appear to be pass-by-value.
> All other locking operations are pass-by-reference - spin_lock(&lock),
> not spin_lock(lock). This is what the eye expects to see and it's
> simply more logical - calling code shouldn't have to "know" that the
> locking operations are implemented as cpp macros. And we'd be in a
> mess if someone tried to convert these to real C functions.

The funny thing is that the documentation gets this right:

+The mapping of local_lock to spinlock_t on PREEMPT_RT kernels has a few
+implications. For example, on a non-PREEMPT_RT kernel the following code
+sequence works as expected::
+
+ local_lock_irq(&local_lock);
+ raw_spin_lock(&lock);

but apparently the implementation changed without the documentation matching.