Re: [PATCH] mm, vmstat: Make sure mutex is a global static

From: Michal Hocko
Date: Thu Nov 09 2017 - 02:50:23 EST


On Wed 08-11-17 07:21:20, Kees Cook wrote:
> On Tue, Nov 7, 2017 at 11:43 PM, Vlastimil Babka <vbabka@xxxxxxx> wrote:
> > On 11/07/2017 10:38 PM, Kees Cook wrote:
[...]
> >> +static DEFINE_MUTEX(vm_numa_stat_lock);
> >> +
> >> int sysctl_vm_numa_stat_handler(struct ctl_table *table, int write,
> >> void __user *buffer, size_t *length, loff_t *ppos)
> >> {
> >> int ret, oldval;
> >> - DEFINE_MUTEX(vm_numa_stat_lock);
> >
> > Yeah it was Michal who suggested scoping the mutex here instead of
> > global scope, but I think he didn't mean to remove the 'static'
> > qualifier, and we both missed that in the review :(
> > So the scope under sysctl_vm_numa_stat_handler() should be okay, just
> > with the 'static' added.
>
> That part is a matter of taste, I guess. :) But yes, static is important.

The primary reason I prefer function scope lock is that it is less
tempting to reuse the lock for something else that way. But this is
hardly something to insist on. So I am ok with the file scope as well.
--
Michal Hocko
SUSE Labs