Bug 219094

Summary: gen_kheaders.sh gets stuck in an infinite loop (on tmpfs)
Product: File System Reporter: Hong, Yifan (jacky8hyf)
Component: OtherAssignee: fs_other
Status: NEW ---    
Severity: normal CC: fdmanana, hughd, jacky8hyf, rob
Priority: P3    
Hardware: All   
OS: Linux   
Kernel Version: Subsystem:
Regression: No Bisected commit-id:

Description Hong, Yifan 2024-07-24 23:11:03 UTC
I have hit a similar bug to https://bugzilla.kernel.org/show_bug.cgi?id=217681, but on tmpfs. 

Here's a small reproducer for the bug, from https://bugzilla.kernel.org/show_bug.cgi?id=217681#c1:

```
#include <sys/types.h>
#include <dirent.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
  DIR *dir = opendir(".");
  struct dirent *dd;

  while ((dd = readdir(dir))) {
    printf("%s\n", dd->d_name);
    rename(dd->d_name, "TEMPFILE");
    rename("TEMPFILE", dd->d_name);
  }
  closedir(dir);
}
```

Run in a directory with multiple (2000) files, it does not complete on tmpfs. I created a tmpfs mount point via

```
mount -o size=1G -t tmpfs none ~/tmpfs/mount/
```

The other bug was fixed on btrfs via https://lore.kernel.org/linux-btrfs/c9ceb0e15d92d0634600603b38965d9b6d986b6d.1691923900.git.fdmanana@suse.com/. Could anyone please see if the issue can be ported to tmpfs as well? Thanks in advance!

I am using a `Linux version 6.6.15` kernel, if that's useful to anyone.
Comment 1 Hugh Dickins 2024-07-26 01:05:45 UTC
Please send responses by email reply-to-all rather than through bugzilla.

On Thu, 25 Jul 2024, bugzilla-daemon@kernel.org wrote:

> https://bugzilla.kernel.org/show_bug.cgi?id=219094
> 
> Hong, Yifan (jacky8hyf@gmail.com) reports:
> 
> I have hit a similar bug to
> https://bugzilla.kernel.org/show_bug.cgi?id=217681, but on tmpfs. 
> 
> Here's a small reproducer for the bug, from
> https://bugzilla.kernel.org/show_bug.cgi?id=217681#c1:
> 
> ```
> #include <sys/types.h>
> #include <dirent.h>
> #include <stdio.h>
> 
> int main(int argc, char *argv[])
> {
>   DIR *dir = opendir(".");
>   struct dirent *dd;
> 
>   while ((dd = readdir(dir))) {
>     printf("%s\n", dd->d_name);
>     rename(dd->d_name, "TEMPFILE");
>     rename("TEMPFILE", dd->d_name);
>   }
>   closedir(dir);
> }
> ```
> 
> Run in a directory with multiple (2000) files, it does not complete on tmpfs.
> I created a tmpfs mount point via
> 
> ```
> mount -o size=1G -t tmpfs none ~/tmpfs/mount/
> ```
> 
> The other bug was fixed on btrfs via
> https://lore.kernel.org/linux-btrfs/c9ceb0e15d92d0634600603b38965d9b6d986b6d.1691923900.git.fdmanana@suse.com/.
> Could anyone please see if the issue can be ported to tmpfs as well? Thanks
> in advance!
> 
> I am using a `Linux version 6.6.15` kernel, if that's useful to anyone.

Thank you for reporting, Yifan; and thank you for the easy reproducer, Rob.

Yes, it appears that tmpfs was okay for this up to v6.5, but cannot cope
from v6.6 onwards - a likely-sounding fix went into v6.10, but that must
have been for something different, v6.10 still failing on this repro.

Chuck, I'm hoping that you will have time to spare to solve this in latest;
and then we shall want a backport (of only this fix, or more?) for v6.6 LTS.

Thanks!
Hugh
Comment 2 Chuck Lever 2024-07-26 13:21:11 UTC
> On Jul 25, 2024, at 9:05 PM, Hugh Dickins <hughd@google.com> wrote:
> 
> Please send responses by email reply-to-all rather than through bugzilla.
> 
> On Thu, 25 Jul 2024, bugzilla-daemon@kernel.org wrote:
> 
>> https://bugzilla.kernel.org/show_bug.cgi?id=219094
>> 
>> Hong, Yifan (jacky8hyf@gmail.com) reports:
>> 
>> I have hit a similar bug to
>> https://bugzilla.kernel.org/show_bug.cgi?id=217681, but on tmpfs. 
>> 
>> Here's a small reproducer for the bug, from
>> https://bugzilla.kernel.org/show_bug.cgi?id=217681#c1:
>> 
>> ```
>> #include <sys/types.h>
>> #include <dirent.h>
>> #include <stdio.h>
>> 
>> int main(int argc, char *argv[])
>> {
>>  DIR *dir = opendir(".");
>>  struct dirent *dd;
>> 
>>  while ((dd = readdir(dir))) {
>>    printf("%s\n", dd->d_name);
>>    rename(dd->d_name, "TEMPFILE");
>>    rename("TEMPFILE", dd->d_name);
>>  }
>>  closedir(dir);
>> }
>> ```
>> 
>> Run in a directory with multiple (2000) files, it does not complete on
>> tmpfs. I created a tmpfs mount point via
>> 
>> ```
>> mount -o size=1G -t tmpfs none ~/tmpfs/mount/
>> ```
>> 
>> The other bug was fixed on btrfs via
>> https://lore.kernel.org/linux-btrfs/c9ceb0e15d92d0634600603b38965d9b6d986b6d.1691923900.git.fdmanana@suse.com/.
>> Could anyone please see if the issue can be ported to tmpfs as well? Thanks
>> in advance!
>> 
>> I am using a `Linux version 6.6.15` kernel, if that's useful to anyone.
> 
> Thank you for reporting, Yifan; and thank you for the easy reproducer, Rob.
> 
> Yes, it appears that tmpfs was okay for this up to v6.5, but cannot cope
> from v6.6 onwards - a likely-sounding fix went into v6.10, but that must
> have been for something different, v6.10 still failing on this repro.
> 
> Chuck, I'm hoping that you will have time to spare to solve this in latest;
> and then we shall want a backport (of only this fix, or more?) for v6.6 LTS.

Well, I don't have time, but I will indeed have a look. ;-)
This does look awfully similar to the rename bug I fixed
recently in this code.

Meanwhile, can I ask that someone else begin collecting these
reproducers to add to fstests? Christian and I have both run
fstests repeatedly against tmpfs and it does not seem to find
these corner cases.

--
Chuck Lever
Comment 3 Filipe David Manana 2024-07-26 15:28:48 UTC
(In reply to Chuck Lever from comment #2)
> > On Jul 25, 2024, at 9:05 PM, Hugh Dickins <hughd@google.com> wrote:
> > 
> > Please send responses by email reply-to-all rather than through bugzilla.
> > 
> > On Thu, 25 Jul 2024, bugzilla-daemon@kernel.org wrote:
> > 
> >> https://bugzilla.kernel.org/show_bug.cgi?id=219094
> >> 
> >> Hong, Yifan (jacky8hyf@gmail.com) reports:
> >> 
> >> I have hit a similar bug to
> >> https://bugzilla.kernel.org/show_bug.cgi?id=217681, but on tmpfs. 
> >> 
> >> Here's a small reproducer for the bug, from
> >> https://bugzilla.kernel.org/show_bug.cgi?id=217681#c1:
> >> 
> >> ```
> >> #include <sys/types.h>
> >> #include <dirent.h>
> >> #include <stdio.h>
> >> 
> >> int main(int argc, char *argv[])
> >> {
> >>  DIR *dir = opendir(".");
> >>  struct dirent *dd;
> >> 
> >>  while ((dd = readdir(dir))) {
> >>    printf("%s\n", dd->d_name);
> >>    rename(dd->d_name, "TEMPFILE");
> >>    rename("TEMPFILE", dd->d_name);
> >>  }
> >>  closedir(dir);
> >> }
> >> ```
> >> 
> >> Run in a directory with multiple (2000) files, it does not complete on
> >> tmpfs. I created a tmpfs mount point via
> >> 
> >> ```
> >> mount -o size=1G -t tmpfs none ~/tmpfs/mount/
> >> ```
> >> 
> >> The other bug was fixed on btrfs via
> >>
> https://lore.kernel.org/linux-btrfs/c9ceb0e15d92d0634600603b38965d9b6d986b6d.1691923900.git.fdmanana@suse.com/.
> >> Could anyone please see if the issue can be ported to tmpfs as well?
> Thanks
> >> in advance!
> >> 
> >> I am using a `Linux version 6.6.15` kernel, if that's useful to anyone.
> > 
> > Thank you for reporting, Yifan; and thank you for the easy reproducer, Rob.
> > 
> > Yes, it appears that tmpfs was okay for this up to v6.5, but cannot cope
> > from v6.6 onwards - a likely-sounding fix went into v6.10, but that must
> > have been for something different, v6.10 still failing on this repro.
> > 
> > Chuck, I'm hoping that you will have time to spare to solve this in latest;
> > and then we shall want a backport (of only this fix, or more?) for v6.6
> LTS.
> 
> Well, I don't have time, but I will indeed have a look. ;-)
> This does look awfully similar to the rename bug I fixed
> recently in this code.
> 
> Meanwhile, can I ask that someone else begin collecting these
> reproducers to add to fstests? Christian and I have both run
> fstests repeatedly against tmpfs and it does not seem to find
> these corner cases.

This issue was raised exactly because there's a test case for fstests exercising the problem, see the thread (you even replied to it):

https://lore.kernel.org/fstests/20240720083538.2999155-1-yangerkun@huawei.com/


> 
> --
> Chuck Lever