diff mbox series

[v1] hugetlbfs: fix hugetlbfs_statfs() locking

Message ID 20220429202207.3045-1-almasrymina@google.com (mailing list archive)
State New
Headers show
Series [v1] hugetlbfs: fix hugetlbfs_statfs() locking | expand

Commit Message

Mina Almasry April 29, 2022, 8:22 p.m. UTC
After commit db71ef79b59b ("hugetlb: make free_huge_page irq safe"),
the subpool lock should be locked with spin_lock_irq() and all call
sites was modified as such, except for the ones in hugetlbfs_statfs().

Fixes: db71ef79b59b ("hugetlb: make free_huge_page irq safe")
Signed-Off-By: Mina Almasry <almasrymina@google.com>
---
 fs/hugetlbfs/inode.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

--
2.36.0.464.gb9c8b46e94-goog

Comments

Andrew Morton April 29, 2022, 8:33 p.m. UTC | #1
On Fri, 29 Apr 2022 13:22:06 -0700 Mina Almasry <almasrymina@google.com> wrote:

> After commit db71ef79b59b ("hugetlb: make free_huge_page irq safe"),
> the subpool lock should be locked with spin_lock_irq() and all call
> sites was modified as such, except for the ones in hugetlbfs_statfs().
> 
> ...
>
> --- a/fs/hugetlbfs/inode.c
> +++ b/fs/hugetlbfs/inode.c
> @@ -1048,12 +1048,12 @@ static int hugetlbfs_statfs(struct dentry *dentry, struct kstatfs *buf)
>  		if (sbinfo->spool) {
>  			long free_pages;
> 
> -			spin_lock(&sbinfo->spool->lock);
> +			spin_lock_irq(&sbinfo->spool->lock);
>  			buf->f_blocks = sbinfo->spool->max_hpages;
>  			free_pages = sbinfo->spool->max_hpages
>  				- sbinfo->spool->used_hpages;
>  			buf->f_bavail = buf->f_bfree = free_pages;
> -			spin_unlock(&sbinfo->spool->lock);
> +			spin_unlock_irq(&sbinfo->spool->lock);
>  			buf->f_files = sbinfo->max_inodes;
>  			buf->f_ffree = sbinfo->free_inodes;
>  		}

Looks good.

This seems to be theoretically deadlockable and less theoretically
lockdep splattable, so I'm inclined to cc:stable on this.

I wonder why we didn't do that with db71ef79b59bb2e78dc4.
Mike Kravetz April 29, 2022, 8:59 p.m. UTC | #2
On 4/29/22 13:33, Andrew Morton wrote:
> On Fri, 29 Apr 2022 13:22:06 -0700 Mina Almasry <almasrymina@google.com> wrote:
> 
>> After commit db71ef79b59b ("hugetlb: make free_huge_page irq safe"),
>> the subpool lock should be locked with spin_lock_irq() and all call
>> sites was modified as such, except for the ones in hugetlbfs_statfs().
>>
>> ...
>>
>> --- a/fs/hugetlbfs/inode.c
>> +++ b/fs/hugetlbfs/inode.c
>> @@ -1048,12 +1048,12 @@ static int hugetlbfs_statfs(struct dentry *dentry, struct kstatfs *buf)
>>  		if (sbinfo->spool) {
>>  			long free_pages;
>>
>> -			spin_lock(&sbinfo->spool->lock);
>> +			spin_lock_irq(&sbinfo->spool->lock);
>>  			buf->f_blocks = sbinfo->spool->max_hpages;
>>  			free_pages = sbinfo->spool->max_hpages
>>  				- sbinfo->spool->used_hpages;
>>  			buf->f_bavail = buf->f_bfree = free_pages;
>> -			spin_unlock(&sbinfo->spool->lock);
>> +			spin_unlock_irq(&sbinfo->spool->lock);
>>  			buf->f_files = sbinfo->max_inodes;
>>  			buf->f_ffree = sbinfo->free_inodes;
>>  		}
> 
> Looks good.

Agree, thanks Mina!
Reviewed-by: Mike Kravetz <mike.kravetz@oracle.com>

> 
> This seems to be theoretically deadlockable and less theoretically
> lockdep splattable, so I'm inclined to cc:stable on this.
> 
> I wonder why we didn't do that with db71ef79b59bb2e78dc4.
> 

I do not think it was considered because the "less theoretically lockdep splattable" was so rare.

IIRC, the issue of possibly freeing hugetlb pages in IRQ context existed
from almost the beginning of hugetlb.  It was first discovered and 'addressed'
with c77c0a8ac4c5.  That was not cc:stable.  Then it was discovered that c77c0a8ac4c5 was not complete, so db71ef79b59b effectively replaced c77c0a8ac4c5.  That also was not cc:stable.  I guess we could cc:stable this.

Mina, did you find this with lockdep or just code inspection?
Mina Almasry May 2, 2022, 11:19 p.m. UTC | #3
On Fri, Apr 29, 2022 at 1:59 PM Mike Kravetz <mike.kravetz@oracle.com> wrote:
>
> On 4/29/22 13:33, Andrew Morton wrote:
> > On Fri, 29 Apr 2022 13:22:06 -0700 Mina Almasry <almasrymina@google.com> wrote:
> >
> >> After commit db71ef79b59b ("hugetlb: make free_huge_page irq safe"),
> >> the subpool lock should be locked with spin_lock_irq() and all call
> >> sites was modified as such, except for the ones in hugetlbfs_statfs().
> >>
> >> ...
> >>
> >> --- a/fs/hugetlbfs/inode.c
> >> +++ b/fs/hugetlbfs/inode.c
> >> @@ -1048,12 +1048,12 @@ static int hugetlbfs_statfs(struct dentry *dentry, struct kstatfs *buf)
> >>              if (sbinfo->spool) {
> >>                      long free_pages;
> >>
> >> -                    spin_lock(&sbinfo->spool->lock);
> >> +                    spin_lock_irq(&sbinfo->spool->lock);
> >>                      buf->f_blocks = sbinfo->spool->max_hpages;
> >>                      free_pages = sbinfo->spool->max_hpages
> >>                              - sbinfo->spool->used_hpages;
> >>                      buf->f_bavail = buf->f_bfree = free_pages;
> >> -                    spin_unlock(&sbinfo->spool->lock);
> >> +                    spin_unlock_irq(&sbinfo->spool->lock);
> >>                      buf->f_files = sbinfo->max_inodes;
> >>                      buf->f_ffree = sbinfo->free_inodes;
> >>              }
> >
> > Looks good.
>
> Agree, thanks Mina!
> Reviewed-by: Mike Kravetz <mike.kravetz@oracle.com>
>
> >
> > This seems to be theoretically deadlockable and less theoretically
> > lockdep splattable, so I'm inclined to cc:stable on this.
> >
> > I wonder why we didn't do that with db71ef79b59bb2e78dc4.
> >
>
> I do not think it was considered because the "less theoretically lockdep splattable" was so rare.
>
> IIRC, the issue of possibly freeing hugetlb pages in IRQ context existed
> from almost the beginning of hugetlb.  It was first discovered and 'addressed'
> with c77c0a8ac4c5.  That was not cc:stable.  Then it was discovered that c77c0a8ac4c5 was not complete, so db71ef79b59b effectively replaced c77c0a8ac4c5.  That also was not cc:stable.  I guess we could cc:stable this.
>
> Mina, did you find this with lockdep or just code inspection?

Greg Thelen found this by code inspection. He was reviewing a related
fix and noticed this particular instance of locking wasn't _irq(), and
based on previous changes it ought to be. Lockdep did not complain
about this.

> --
> Mike Kravetz
diff mbox series

Patch

diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
index dd3a088db11d..591599829e2a 100644
--- a/fs/hugetlbfs/inode.c
+++ b/fs/hugetlbfs/inode.c
@@ -1048,12 +1048,12 @@  static int hugetlbfs_statfs(struct dentry *dentry, struct kstatfs *buf)
 		if (sbinfo->spool) {
 			long free_pages;

-			spin_lock(&sbinfo->spool->lock);
+			spin_lock_irq(&sbinfo->spool->lock);
 			buf->f_blocks = sbinfo->spool->max_hpages;
 			free_pages = sbinfo->spool->max_hpages
 				- sbinfo->spool->used_hpages;
 			buf->f_bavail = buf->f_bfree = free_pages;
-			spin_unlock(&sbinfo->spool->lock);
+			spin_unlock_irq(&sbinfo->spool->lock);
 			buf->f_files = sbinfo->max_inodes;
 			buf->f_ffree = sbinfo->free_inodes;
 		}