All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH -next] nfsd: use DEFINE_SPINLOCK() for spinlock
@ 2020-07-25  8:56 Qinglang Miao
  2020-07-31 12:30 ` Chuck Lever
  0 siblings, 1 reply; 6+ messages in thread
From: Qinglang Miao @ 2020-07-25  8:56 UTC (permalink / raw)
  To: J. Bruce Fields, Chuck Lever, Greg Kroah-Hartman; +Cc: linux-nfs, linux-kernel

nfsd_drc_lock can be initialized automatically with
DEFINE_SPINLOCK() rather than explicitly calling spin_lock_init().

Signed-off-by: Qinglang Miao <miaoqinglang@huawei.com>
---
 fs/nfsd/nfssvc.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/fs/nfsd/nfssvc.c b/fs/nfsd/nfssvc.c
index b603dfcdd..20f0a27fe 100644
--- a/fs/nfsd/nfssvc.c
+++ b/fs/nfsd/nfssvc.c
@@ -88,7 +88,7 @@ DEFINE_MUTEX(nfsd_mutex);
  * version 4.1 DRC caches.
  * nfsd_drc_pages_used tracks the current version 4.1 DRC memory usage.
  */
-spinlock_t	nfsd_drc_lock;
+DEFINE_SPINLOCK(nfsd_drc_lock);
 unsigned long	nfsd_drc_max_mem;
 unsigned long	nfsd_drc_mem_used;
 
@@ -568,7 +568,6 @@ static void set_max_drc(void)
 	nfsd_drc_max_mem = (nr_free_buffer_pages()
 					>> NFSD_DRC_SIZE_SHIFT) * PAGE_SIZE;
 	nfsd_drc_mem_used = 0;
-	spin_lock_init(&nfsd_drc_lock);
 	dprintk("%s nfsd_drc_max_mem %lu \n", __func__, nfsd_drc_max_mem);
 }
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH -next] nfsd: use DEFINE_SPINLOCK() for spinlock
  2020-07-25  8:56 [PATCH -next] nfsd: use DEFINE_SPINLOCK() for spinlock Qinglang Miao
@ 2020-07-31 12:30 ` Chuck Lever
  0 siblings, 0 replies; 6+ messages in thread
From: Chuck Lever @ 2020-07-31 12:30 UTC (permalink / raw)
  To: Qinglang Miao, Bruce Fields
  Cc: Greg Kroah-Hartman, Linux NFS Mailing List, open list

Hello-

> On Jul 25, 2020, at 4:56 AM, Qinglang Miao <miaoqinglang@huawei.com> wrote:
> 
> nfsd_drc_lock can be initialized automatically with
> DEFINE_SPINLOCK() rather than explicitly calling spin_lock_init().
> 
> Signed-off-by: Qinglang Miao <miaoqinglang@huawei.com>

Thanks for your patch.

I am quite honestly on the fence about this one. It doesn't
seem to make a difference behaviorally or in terms of code
legibility.

A broader clean-up that moves set_max_drc and those global
variables into nfs4state.c might be better, but again, there
isn't much to justify such a change.

Bruce, any thoughts?


> ---
> fs/nfsd/nfssvc.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/fs/nfsd/nfssvc.c b/fs/nfsd/nfssvc.c
> index b603dfcdd..20f0a27fe 100644
> --- a/fs/nfsd/nfssvc.c
> +++ b/fs/nfsd/nfssvc.c
> @@ -88,7 +88,7 @@ DEFINE_MUTEX(nfsd_mutex);
>  * version 4.1 DRC caches.
>  * nfsd_drc_pages_used tracks the current version 4.1 DRC memory usage.
>  */
> -spinlock_t	nfsd_drc_lock;
> +DEFINE_SPINLOCK(nfsd_drc_lock);
> unsigned long	nfsd_drc_max_mem;
> unsigned long	nfsd_drc_mem_used;
> 
> @@ -568,7 +568,6 @@ static void set_max_drc(void)
> 	nfsd_drc_max_mem = (nr_free_buffer_pages()
> 					>> NFSD_DRC_SIZE_SHIFT) * PAGE_SIZE;
> 	nfsd_drc_mem_used = 0;
> -	spin_lock_init(&nfsd_drc_lock);
> 	dprintk("%s nfsd_drc_max_mem %lu \n", __func__, nfsd_drc_max_mem);
> }
> 
> -- 
> 2.25.1
> 

--
Chuck Lever




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH -next] NFSD: Use DEFINE_SPINLOCK() for spinlock
  2021-04-06 12:08 [PATCH -next] NFSD: Use " Huang Guobin
  2021-04-06 15:46 ` Chuck Lever III
@ 2021-04-06 15:58 ` Chuck Lever III
  1 sibling, 0 replies; 6+ messages in thread
From: Chuck Lever III @ 2021-04-06 15:58 UTC (permalink / raw)
  To: Huang Guobin
  Cc: Bruce Fields, Jeff Layton, Linux NFS Mailing List, linux-kernel

Hello-

> On Apr 6, 2021, at 8:08 AM, Huang Guobin <huangguobin4@huawei.com> wrote:
> 
> From: Guobin Huang <huangguobin4@huawei.com>
> 
> spinlock can be initialized automatically with DEFINE_SPINLOCK()
> rather than explicitly calling spin_lock_init().
> 
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Signed-off-by: Guobin Huang <huangguobin4@huawei.com>

This change has been pushed to the for-next topic branch in

git://git.kernel.org/pub/scm/linux/kernel/git/cel/linux.git


> ---
> fs/nfsd/nfssvc.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/fs/nfsd/nfssvc.c b/fs/nfsd/nfssvc.c
> index b2eef4112bc2..82ba034fa579 100644
> --- a/fs/nfsd/nfssvc.c
> +++ b/fs/nfsd/nfssvc.c
> @@ -84,7 +84,7 @@ DEFINE_MUTEX(nfsd_mutex);
>  * version 4.1 DRC caches.
>  * nfsd_drc_pages_used tracks the current version 4.1 DRC memory usage.
>  */
> -spinlock_t	nfsd_drc_lock;
> +DEFINE_SPINLOCK(nfsd_drc_lock);
> unsigned long	nfsd_drc_max_mem;
> unsigned long	nfsd_drc_mem_used;
> 
> @@ -563,7 +563,6 @@ static void set_max_drc(void)
> 	nfsd_drc_max_mem = (nr_free_buffer_pages()
> 					>> NFSD_DRC_SIZE_SHIFT) * PAGE_SIZE;
> 	nfsd_drc_mem_used = 0;
> -	spin_lock_init(&nfsd_drc_lock);
> 	dprintk("%s nfsd_drc_max_mem %lu \n", __func__, nfsd_drc_max_mem);
> }
> 
> 

--
Chuck Lever




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH -next] NFSD: Use DEFINE_SPINLOCK() for spinlock
  2021-04-06 15:46 ` Chuck Lever III
@ 2021-04-06 15:55   ` Bruce Fields
  0 siblings, 0 replies; 6+ messages in thread
From: Bruce Fields @ 2021-04-06 15:55 UTC (permalink / raw)
  To: Chuck Lever III; +Cc: Huang Guobin, Jeff Layton, Linux NFS Mailing List, LKML

On Tue, Apr 06, 2021 at 03:46:34PM +0000, Chuck Lever III wrote:
> 
> 
> > On Apr 6, 2021, at 8:08 AM, Huang Guobin <huangguobin4@huawei.com> wrote:
> > 
> > From: Guobin Huang <huangguobin4@huawei.com>
> > 
> > spinlock can be initialized automatically with DEFINE_SPINLOCK()
> > rather than explicitly calling spin_lock_init().
> > 
> > Reported-by: Hulk Robot <hulkci@huawei.com>
> > Signed-off-by: Guobin Huang <huangguobin4@huawei.com>
> 
> This same patch was sent last July, without the Reported-by:
> 
> https://lore.kernel.org/linux-nfs/1617710898-49064-1-git-send-email-huangguobin4@huawei.com/T/#u
> 
> If I'm reading the code correctly, it appears that set_max_drc()
> can be called more than once by user space API functions via
> nfsd_create_serv().
> 
> It seems to me we want to guarantee that nfsd_drc_lock is
> initialized exactly once, and using DEFINE_SPINLOCK() would
> do just that.
> 
> Likewise, re-initializing nfsd_drc_mem_used is probably not good
> to do either, but clobbering a spinlock like that might lead to
> a crash.
> 
> Bruce, any further thoughts?

The other nfsd_drc_lock users run in nfsd threads, which shouldn't be
running yet at the point we call set_max_drc.

Reinitializing the lock each time is pretty weird, though, ACK to the
patch even if it's just cleanup.

--b.

> 
> 
> > ---
> > fs/nfsd/nfssvc.c | 3 +--
> > 1 file changed, 1 insertion(+), 2 deletions(-)
> > 
> > diff --git a/fs/nfsd/nfssvc.c b/fs/nfsd/nfssvc.c
> > index b2eef4112bc2..82ba034fa579 100644
> > --- a/fs/nfsd/nfssvc.c
> > +++ b/fs/nfsd/nfssvc.c
> > @@ -84,7 +84,7 @@ DEFINE_MUTEX(nfsd_mutex);
> >  * version 4.1 DRC caches.
> >  * nfsd_drc_pages_used tracks the current version 4.1 DRC memory usage.
> >  */
> > -spinlock_t	nfsd_drc_lock;
> > +DEFINE_SPINLOCK(nfsd_drc_lock);
> > unsigned long	nfsd_drc_max_mem;
> > unsigned long	nfsd_drc_mem_used;
> > 
> > @@ -563,7 +563,6 @@ static void set_max_drc(void)
> > 	nfsd_drc_max_mem = (nr_free_buffer_pages()
> > 					>> NFSD_DRC_SIZE_SHIFT) * PAGE_SIZE;
> > 	nfsd_drc_mem_used = 0;
> > -	spin_lock_init(&nfsd_drc_lock);
> > 	dprintk("%s nfsd_drc_max_mem %lu \n", __func__, nfsd_drc_max_mem);
> > }
> > 
> > 
> 
> --
> Chuck Lever
> 
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH -next] NFSD: Use DEFINE_SPINLOCK() for spinlock
  2021-04-06 12:08 [PATCH -next] NFSD: Use " Huang Guobin
@ 2021-04-06 15:46 ` Chuck Lever III
  2021-04-06 15:55   ` Bruce Fields
  2021-04-06 15:58 ` Chuck Lever III
  1 sibling, 1 reply; 6+ messages in thread
From: Chuck Lever III @ 2021-04-06 15:46 UTC (permalink / raw)
  To: Huang Guobin, Bruce Fields; +Cc: Jeff Layton, Linux NFS Mailing List, LKML



> On Apr 6, 2021, at 8:08 AM, Huang Guobin <huangguobin4@huawei.com> wrote:
> 
> From: Guobin Huang <huangguobin4@huawei.com>
> 
> spinlock can be initialized automatically with DEFINE_SPINLOCK()
> rather than explicitly calling spin_lock_init().
> 
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Signed-off-by: Guobin Huang <huangguobin4@huawei.com>

This same patch was sent last July, without the Reported-by:

https://lore.kernel.org/linux-nfs/1617710898-49064-1-git-send-email-huangguobin4@huawei.com/T/#u

If I'm reading the code correctly, it appears that set_max_drc()
can be called more than once by user space API functions via
nfsd_create_serv().

It seems to me we want to guarantee that nfsd_drc_lock is
initialized exactly once, and using DEFINE_SPINLOCK() would
do just that.

Likewise, re-initializing nfsd_drc_mem_used is probably not good
to do either, but clobbering a spinlock like that might lead to
a crash.

Bruce, any further thoughts?


> ---
> fs/nfsd/nfssvc.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/fs/nfsd/nfssvc.c b/fs/nfsd/nfssvc.c
> index b2eef4112bc2..82ba034fa579 100644
> --- a/fs/nfsd/nfssvc.c
> +++ b/fs/nfsd/nfssvc.c
> @@ -84,7 +84,7 @@ DEFINE_MUTEX(nfsd_mutex);
>  * version 4.1 DRC caches.
>  * nfsd_drc_pages_used tracks the current version 4.1 DRC memory usage.
>  */
> -spinlock_t	nfsd_drc_lock;
> +DEFINE_SPINLOCK(nfsd_drc_lock);
> unsigned long	nfsd_drc_max_mem;
> unsigned long	nfsd_drc_mem_used;
> 
> @@ -563,7 +563,6 @@ static void set_max_drc(void)
> 	nfsd_drc_max_mem = (nr_free_buffer_pages()
> 					>> NFSD_DRC_SIZE_SHIFT) * PAGE_SIZE;
> 	nfsd_drc_mem_used = 0;
> -	spin_lock_init(&nfsd_drc_lock);
> 	dprintk("%s nfsd_drc_max_mem %lu \n", __func__, nfsd_drc_max_mem);
> }
> 
> 

--
Chuck Lever




^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH -next] NFSD: Use DEFINE_SPINLOCK() for spinlock
@ 2021-04-06 12:08 Huang Guobin
  2021-04-06 15:46 ` Chuck Lever III
  2021-04-06 15:58 ` Chuck Lever III
  0 siblings, 2 replies; 6+ messages in thread
From: Huang Guobin @ 2021-04-06 12:08 UTC (permalink / raw)
  To: huangguobin4, J. Bruce Fields, Chuck Lever, Jeff Layton
  Cc: linux-nfs, linux-kernel

From: Guobin Huang <huangguobin4@huawei.com>

spinlock can be initialized automatically with DEFINE_SPINLOCK()
rather than explicitly calling spin_lock_init().

Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Guobin Huang <huangguobin4@huawei.com>
---
 fs/nfsd/nfssvc.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/fs/nfsd/nfssvc.c b/fs/nfsd/nfssvc.c
index b2eef4112bc2..82ba034fa579 100644
--- a/fs/nfsd/nfssvc.c
+++ b/fs/nfsd/nfssvc.c
@@ -84,7 +84,7 @@ DEFINE_MUTEX(nfsd_mutex);
  * version 4.1 DRC caches.
  * nfsd_drc_pages_used tracks the current version 4.1 DRC memory usage.
  */
-spinlock_t	nfsd_drc_lock;
+DEFINE_SPINLOCK(nfsd_drc_lock);
 unsigned long	nfsd_drc_max_mem;
 unsigned long	nfsd_drc_mem_used;
 
@@ -563,7 +563,6 @@ static void set_max_drc(void)
 	nfsd_drc_max_mem = (nr_free_buffer_pages()
 					>> NFSD_DRC_SIZE_SHIFT) * PAGE_SIZE;
 	nfsd_drc_mem_used = 0;
-	spin_lock_init(&nfsd_drc_lock);
 	dprintk("%s nfsd_drc_max_mem %lu \n", __func__, nfsd_drc_max_mem);
 }
 


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-04-06 15:59 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-25  8:56 [PATCH -next] nfsd: use DEFINE_SPINLOCK() for spinlock Qinglang Miao
2020-07-31 12:30 ` Chuck Lever
2021-04-06 12:08 [PATCH -next] NFSD: Use " Huang Guobin
2021-04-06 15:46 ` Chuck Lever III
2021-04-06 15:55   ` Bruce Fields
2021-04-06 15:58 ` Chuck Lever III

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.