diff mbox

[v2,1/7] proc/kcore: don't grab lock for kclist_add()

Message ID 20180717193504.1d76fb1a43d0c8687d969143@linux-foundation.org (mailing list archive)
State New, archived
Headers show

Commit Message

Andrew Morton July 18, 2018, 2:35 a.m. UTC
On Thu, 12 Jul 2018 17:09:33 -0700 Omar Sandoval <osandov@osandov.com> wrote:

> From: Omar Sandoval <osandov@fb.com>
> 
> kclist_add() is only called at init time, so there's no point in
> grabbing any locks. We're also going to replace the rwlock with a rwsem,
> which we don't want to try grabbing during early boot.
> 
> ...
>
> --- a/fs/proc/kcore.c
> +++ b/fs/proc/kcore.c
> @@ -62,6 +62,7 @@ static LIST_HEAD(kclist_head);
>  static DEFINE_RWLOCK(kclist_lock);
>  static int kcore_need_update = 1;
>  
> +/* This doesn't grab kclist_lock, so it should only be used at init time. */
>  void
>  kclist_add(struct kcore_list *new, void *addr, size_t size, int type)
>  {
> @@ -69,9 +70,7 @@ kclist_add(struct kcore_list *new, void *addr, size_t size, int type)
>  	new->size = size;
>  	new->type = type;
>  
> -	write_lock(&kclist_lock);
>  	list_add_tail(&new->list, &kclist_head);
> -	write_unlock(&kclist_lock);
>  }

So we can mark kclist_add() as __init, yes?

That way we save a scrap of ram and if someone starts calling
kclist_add() from non-__init code we get a build-time warning.

Comments

Omar Sandoval July 18, 2018, 3:19 a.m. UTC | #1
On Tue, Jul 17, 2018 at 07:35:04PM -0700, Andrew Morton wrote:
> On Thu, 12 Jul 2018 17:09:33 -0700 Omar Sandoval <osandov@osandov.com> wrote:
> 
> > From: Omar Sandoval <osandov@fb.com>
> > 
> > kclist_add() is only called at init time, so there's no point in
> > grabbing any locks. We're also going to replace the rwlock with a rwsem,
> > which we don't want to try grabbing during early boot.
> > 
> > ...
> >
> > --- a/fs/proc/kcore.c
> > +++ b/fs/proc/kcore.c
> > @@ -62,6 +62,7 @@ static LIST_HEAD(kclist_head);
> >  static DEFINE_RWLOCK(kclist_lock);
> >  static int kcore_need_update = 1;
> >  
> > +/* This doesn't grab kclist_lock, so it should only be used at init time. */
> >  void
> >  kclist_add(struct kcore_list *new, void *addr, size_t size, int type)
> >  {
> > @@ -69,9 +70,7 @@ kclist_add(struct kcore_list *new, void *addr, size_t size, int type)
> >  	new->size = size;
> >  	new->type = type;
> >  
> > -	write_lock(&kclist_lock);
> >  	list_add_tail(&new->list, &kclist_head);
> > -	write_unlock(&kclist_lock);
> >  }
> 
> So we can mark kclist_add() as __init, yes?

Yes, thanks, I'll add that in v2.

> That way we save a scrap of ram and if someone starts calling
> kclist_add() from non-__init code we get a build-time warning.
> 
> --- a/fs/proc/kcore.c~proc-kcore-dont-grab-lock-for-kclist_add-fix
> +++ a/fs/proc/kcore.c
> @@ -63,7 +63,7 @@ static DEFINE_RWLOCK(kclist_lock);
>  static int kcore_need_update = 1;
>  
>  /* This doesn't grab kclist_lock, so it should only be used at init time. */
> -void
> +void __init
>  kclist_add(struct kcore_list *new, void *addr, size_t size, int type)
>  {
>  	new->addr = (unsigned long)addr;
> --- a/include/linux/kcore.h~proc-kcore-dont-grab-lock-for-kclist_add-fix
> +++ a/include/linux/kcore.h
> @@ -35,7 +35,7 @@ struct vmcoredd_node {
>  };
>  
>  #ifdef CONFIG_PROC_KCORE
> -extern void kclist_add(struct kcore_list *, void *, size_t, int type);
> +extern void __init kclist_add(struct kcore_list *, void *, size_t, int type);
>  #else
>  static inline
>  void kclist_add(struct kcore_list *new, void *addr, size_t size, int type)
> 
>
diff mbox

Patch

--- a/fs/proc/kcore.c~proc-kcore-dont-grab-lock-for-kclist_add-fix
+++ a/fs/proc/kcore.c
@@ -63,7 +63,7 @@  static DEFINE_RWLOCK(kclist_lock);
 static int kcore_need_update = 1;
 
 /* This doesn't grab kclist_lock, so it should only be used at init time. */
-void
+void __init
 kclist_add(struct kcore_list *new, void *addr, size_t size, int type)
 {
 	new->addr = (unsigned long)addr;
--- a/include/linux/kcore.h~proc-kcore-dont-grab-lock-for-kclist_add-fix
+++ a/include/linux/kcore.h
@@ -35,7 +35,7 @@  struct vmcoredd_node {
 };
 
 #ifdef CONFIG_PROC_KCORE
-extern void kclist_add(struct kcore_list *, void *, size_t, int type);
+extern void __init kclist_add(struct kcore_list *, void *, size_t, int type);
 #else
 static inline
 void kclist_add(struct kcore_list *new, void *addr, size_t size, int type)