Re: svn commit: r363069 - head/sys/kern

2020-07-10 Thread Peter Holm
On Fri, Jul 10, 2020 at 11:25:52AM +0200, Mateusz Guzik wrote:
> On 7/10/20, Mateusz Guzik  wrote:
> > On 7/10/20, Peter Holm  wrote:
> >> On Fri, Jul 10, 2020 at 06:47:58AM +, Mateusz Guzik wrote:
> >>> Author: mjg
> >>> Date: Fri Jul 10 06:47:58 2020
> >>> New Revision: 363069
> >>> URL: https://svnweb.freebsd.org/changeset/base/363069
> >>>
> >>> Log:
> >>>   vfs: depessimize getfsstat when only the count is requested
> >>>
> >>>   This avoids relocking mountlist_mtx for each entry.
> >>>
> >>> Modified:
> >>>   head/sys/kern/vfs_syscalls.c
> >>>
> >>> Modified: head/sys/kern/vfs_syscalls.c
> >>> ==
> >>> --- head/sys/kern/vfs_syscalls.c  Fri Jul 10 06:46:42 2020
> >>> (r363068)
> >>
> >> Could this one be yours?
> >>
> >> 20200710 09:46:31 all (267/723): procfs.sh
> >> panic: lock (sleep mutex) mountlist not locked @ kern/vfs_syscalls.c:561
> >> cpuid = 4
> >> time = 1594367192
> >> KDB: stack backtrace:
> >> db_trace_self_wrapper() at db_trace_self_wrapper+0x2b/frame
> >> 0xfe00377a6910
> >> vpanic() at vpanic+0x182/frame 0xfe00377a6960
> >> panic() at panic+0x43/frame 0xfe00377a69c0
> >> witness_unlock() at witness_unlock+0x147/frame 0xfe00377a6a00
> >> __mtx_unlock_flags() at __mtx_unlock_flags+0x4d/frame 0xfe00377a6a30
> >> kern_getfsstat() at kern_getfsstat+0x40b/frame 0xfe00377a6ab0
> >> sys_getfsstat() at sys_getfsstat+0x22/frame 0xfe00377a6ad0
> >> amd64_syscall() at amd64_syscall+0x159/frame 0xfe00377a6bf0
> >> fast_syscall_common() at fast_syscall_common+0x101/frame
> >> 0xfe00377a6bf0
> >> --- syscall (557, FreeBSD ELF64, sys_getfsstat), rip = 0x80032db1a, rsp =
> >> 0x7fffd738, rbp = 0x7fffd790 ---
> >> KDB: enter: panic
> >>
> >> https://people.freebsd.org/~pho/stress/log/mjguzik030.txt
> >>
> >
> > Does this fix it for you?
> >
> > diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c
> > index f37a54809e24..2caf09f3412c 100644
> > --- a/sys/kern/vfs_syscalls.c
> > +++ b/sys/kern/vfs_syscalls.c
> > @@ -551,7 +551,7 @@ kern_getfsstat(struct thread *td, struct statfs
> > **buf, size_t bufsize,
> >
> > if (count == maxcount) {
> > vfs_unbusy(mp);
> > -   break;
> > +   goto out;
> > }
> >
> > mtx_lock(_mtx);
> >
> 
> Reproduced and verified the above fixes it, committed here:
> https://svnweb.freebsd.org/changeset/base/363072
> 
> -- 
> Mateusz Guzik 

Yes, thank you. This fixed the problem for me.

- Peter
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r363069 - head/sys/kern

2020-07-10 Thread Mateusz Guzik
On 7/10/20, Mateusz Guzik  wrote:
> On 7/10/20, Peter Holm  wrote:
>> On Fri, Jul 10, 2020 at 06:47:58AM +, Mateusz Guzik wrote:
>>> Author: mjg
>>> Date: Fri Jul 10 06:47:58 2020
>>> New Revision: 363069
>>> URL: https://svnweb.freebsd.org/changeset/base/363069
>>>
>>> Log:
>>>   vfs: depessimize getfsstat when only the count is requested
>>>
>>>   This avoids relocking mountlist_mtx for each entry.
>>>
>>> Modified:
>>>   head/sys/kern/vfs_syscalls.c
>>>
>>> Modified: head/sys/kern/vfs_syscalls.c
>>> ==
>>> --- head/sys/kern/vfs_syscalls.cFri Jul 10 06:46:42 2020
>>> (r363068)
>>
>> Could this one be yours?
>>
>> 20200710 09:46:31 all (267/723): procfs.sh
>> panic: lock (sleep mutex) mountlist not locked @ kern/vfs_syscalls.c:561
>> cpuid = 4
>> time = 1594367192
>> KDB: stack backtrace:
>> db_trace_self_wrapper() at db_trace_self_wrapper+0x2b/frame
>> 0xfe00377a6910
>> vpanic() at vpanic+0x182/frame 0xfe00377a6960
>> panic() at panic+0x43/frame 0xfe00377a69c0
>> witness_unlock() at witness_unlock+0x147/frame 0xfe00377a6a00
>> __mtx_unlock_flags() at __mtx_unlock_flags+0x4d/frame 0xfe00377a6a30
>> kern_getfsstat() at kern_getfsstat+0x40b/frame 0xfe00377a6ab0
>> sys_getfsstat() at sys_getfsstat+0x22/frame 0xfe00377a6ad0
>> amd64_syscall() at amd64_syscall+0x159/frame 0xfe00377a6bf0
>> fast_syscall_common() at fast_syscall_common+0x101/frame
>> 0xfe00377a6bf0
>> --- syscall (557, FreeBSD ELF64, sys_getfsstat), rip = 0x80032db1a, rsp =
>> 0x7fffd738, rbp = 0x7fffd790 ---
>> KDB: enter: panic
>>
>> https://people.freebsd.org/~pho/stress/log/mjguzik030.txt
>>
>
> Does this fix it for you?
>
> diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c
> index f37a54809e24..2caf09f3412c 100644
> --- a/sys/kern/vfs_syscalls.c
> +++ b/sys/kern/vfs_syscalls.c
> @@ -551,7 +551,7 @@ kern_getfsstat(struct thread *td, struct statfs
> **buf, size_t bufsize,
>
> if (count == maxcount) {
> vfs_unbusy(mp);
> -   break;
> +   goto out;
> }
>
> mtx_lock(_mtx);
>

Reproduced and verified the above fixes it, committed here:
https://svnweb.freebsd.org/changeset/base/363072

-- 
Mateusz Guzik 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r363069 - head/sys/kern

2020-07-10 Thread Mateusz Guzik
On 7/10/20, Peter Holm  wrote:
> On Fri, Jul 10, 2020 at 06:47:58AM +, Mateusz Guzik wrote:
>> Author: mjg
>> Date: Fri Jul 10 06:47:58 2020
>> New Revision: 363069
>> URL: https://svnweb.freebsd.org/changeset/base/363069
>>
>> Log:
>>   vfs: depessimize getfsstat when only the count is requested
>>
>>   This avoids relocking mountlist_mtx for each entry.
>>
>> Modified:
>>   head/sys/kern/vfs_syscalls.c
>>
>> Modified: head/sys/kern/vfs_syscalls.c
>> ==
>> --- head/sys/kern/vfs_syscalls.c Fri Jul 10 06:46:42 2020
>> (r363068)
>
> Could this one be yours?
>
> 20200710 09:46:31 all (267/723): procfs.sh
> panic: lock (sleep mutex) mountlist not locked @ kern/vfs_syscalls.c:561
> cpuid = 4
> time = 1594367192
> KDB: stack backtrace:
> db_trace_self_wrapper() at db_trace_self_wrapper+0x2b/frame
> 0xfe00377a6910
> vpanic() at vpanic+0x182/frame 0xfe00377a6960
> panic() at panic+0x43/frame 0xfe00377a69c0
> witness_unlock() at witness_unlock+0x147/frame 0xfe00377a6a00
> __mtx_unlock_flags() at __mtx_unlock_flags+0x4d/frame 0xfe00377a6a30
> kern_getfsstat() at kern_getfsstat+0x40b/frame 0xfe00377a6ab0
> sys_getfsstat() at sys_getfsstat+0x22/frame 0xfe00377a6ad0
> amd64_syscall() at amd64_syscall+0x159/frame 0xfe00377a6bf0
> fast_syscall_common() at fast_syscall_common+0x101/frame 0xfe00377a6bf0
> --- syscall (557, FreeBSD ELF64, sys_getfsstat), rip = 0x80032db1a, rsp =
> 0x7fffd738, rbp = 0x7fffd790 ---
> KDB: enter: panic
>
> https://people.freebsd.org/~pho/stress/log/mjguzik030.txt
>

Does this fix it for you?

diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c
index f37a54809e24..2caf09f3412c 100644
--- a/sys/kern/vfs_syscalls.c
+++ b/sys/kern/vfs_syscalls.c
@@ -551,7 +551,7 @@ kern_getfsstat(struct thread *td, struct statfs
**buf, size_t bufsize,

if (count == maxcount) {
vfs_unbusy(mp);
-   break;
+   goto out;
}

mtx_lock(_mtx);

-- 
Mateusz Guzik 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r363069 - head/sys/kern

2020-07-10 Thread Peter Holm
On Fri, Jul 10, 2020 at 06:47:58AM +, Mateusz Guzik wrote:
> Author: mjg
> Date: Fri Jul 10 06:47:58 2020
> New Revision: 363069
> URL: https://svnweb.freebsd.org/changeset/base/363069
> 
> Log:
>   vfs: depessimize getfsstat when only the count is requested
>   
>   This avoids relocking mountlist_mtx for each entry.
> 
> Modified:
>   head/sys/kern/vfs_syscalls.c
> 
> Modified: head/sys/kern/vfs_syscalls.c
> ==
> --- head/sys/kern/vfs_syscalls.c  Fri Jul 10 06:46:42 2020
> (r363068)

Could this one be yours?

20200710 09:46:31 all (267/723): procfs.sh
panic: lock (sleep mutex) mountlist not locked @ kern/vfs_syscalls.c:561
cpuid = 4
time = 1594367192
KDB: stack backtrace:
db_trace_self_wrapper() at db_trace_self_wrapper+0x2b/frame 0xfe00377a6910
vpanic() at vpanic+0x182/frame 0xfe00377a6960
panic() at panic+0x43/frame 0xfe00377a69c0
witness_unlock() at witness_unlock+0x147/frame 0xfe00377a6a00
__mtx_unlock_flags() at __mtx_unlock_flags+0x4d/frame 0xfe00377a6a30
kern_getfsstat() at kern_getfsstat+0x40b/frame 0xfe00377a6ab0
sys_getfsstat() at sys_getfsstat+0x22/frame 0xfe00377a6ad0
amd64_syscall() at amd64_syscall+0x159/frame 0xfe00377a6bf0
fast_syscall_common() at fast_syscall_common+0x101/frame 0xfe00377a6bf0
--- syscall (557, FreeBSD ELF64, sys_getfsstat), rip = 0x80032db1a, rsp = 
0x7fffd738, rbp = 0x7fffd790 ---
KDB: enter: panic

https://people.freebsd.org/~pho/stress/log/mjguzik030.txt

- Peter
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r363069 - head/sys/kern

2020-07-10 Thread Mateusz Guzik
Author: mjg
Date: Fri Jul 10 06:47:58 2020
New Revision: 363069
URL: https://svnweb.freebsd.org/changeset/base/363069

Log:
  vfs: depessimize getfsstat when only the count is requested
  
  This avoids relocking mountlist_mtx for each entry.

Modified:
  head/sys/kern/vfs_syscalls.c

Modified: head/sys/kern/vfs_syscalls.c
==
--- head/sys/kern/vfs_syscalls.cFri Jul 10 06:46:42 2020
(r363068)
+++ head/sys/kern/vfs_syscalls.cFri Jul 10 06:47:58 2020
(r363069)
@@ -441,7 +441,46 @@ restart:
tofree = sfsp = *buf = malloc(maxcount * sizeof(struct statfs),
M_STATFS, M_WAITOK);
}
+
count = 0;
+
+   /*
+* If there is no target buffer they only want the count.
+*
+* This could be TAILQ_FOREACH but it is open-coded to match the 
original
+* code below.
+*/
+   if (sfsp == NULL) {
+   mtx_lock(_mtx);
+   for (mp = TAILQ_FIRST(); mp != NULL; mp = nmp) {
+   if (prison_canseemount(td->td_ucred, mp) != 0) {
+   nmp = TAILQ_NEXT(mp, mnt_list);
+   continue;
+   }
+#ifdef MAC
+   if (mac_mount_check_stat(td->td_ucred, mp) != 0) {
+   nmp = TAILQ_NEXT(mp, mnt_list);
+   continue;
+   }
+#endif
+   count++;
+   nmp = TAILQ_NEXT(mp, mnt_list);
+   }
+   mtx_unlock(_mtx);
+   *countp = count;
+   return (0);
+   }
+
+   /*
+* They want the entire thing.
+*
+* Short-circuit the corner case of no room for anything, avoids
+* relocking below.
+*/
+   if (maxcount < 1) {
+   goto out;
+   }
+
mtx_lock(_mtx);
for (mp = TAILQ_FIRST(); mp != NULL; mp = nmp) {
if (prison_canseemount(td->td_ucred, mp) != 0) {
@@ -473,53 +512,55 @@ restart:
continue;
}
}
-   if (sfsp != NULL && count < maxcount) {
-   sp = >mnt_stat;
-   /*
-* If MNT_NOWAIT is specified, do not refresh
-* the fsstat cache.
-*/
-   if (mode != MNT_NOWAIT) {
-   error = VFS_STATFS(mp, sp);
-   if (error != 0) {
-   mtx_lock(_mtx);
-   nmp = TAILQ_NEXT(mp, mnt_list);
-   vfs_unbusy(mp);
-   continue;
-   }
+   sp = >mnt_stat;
+   /*
+* If MNT_NOWAIT is specified, do not refresh
+* the fsstat cache.
+*/
+   if (mode != MNT_NOWAIT) {
+   error = VFS_STATFS(mp, sp);
+   if (error != 0) {
+   mtx_lock(_mtx);
+   nmp = TAILQ_NEXT(mp, mnt_list);
+   vfs_unbusy(mp);
+   continue;
}
-   if (priv_check_cred_vfs_generation(td->td_ucred)) {
-   sptmp = malloc(sizeof(struct statfs), M_STATFS,
-   M_WAITOK);
-   *sptmp = *sp;
-   sptmp->f_fsid.val[0] = sptmp->f_fsid.val[1] = 0;
-   prison_enforce_statfs(td->td_ucred, mp, sptmp);
-   sp = sptmp;
-   } else
-   sptmp = NULL;
-   if (bufseg == UIO_SYSSPACE) {
-   bcopy(sp, sfsp, sizeof(*sp));
-   free(sptmp, M_STATFS);
-   } else /* if (bufseg == UIO_USERSPACE) */ {
-   error = copyout(sp, sfsp, sizeof(*sp));
-   free(sptmp, M_STATFS);
-   if (error != 0) {
-   vfs_unbusy(mp);
-   return (error);
-   }
+   }
+   if (priv_check_cred_vfs_generation(td->td_ucred)) {
+   sptmp = malloc(sizeof(struct statfs), M_STATFS,
+   M_WAITOK);
+   *sptmp = *sp;
+   sptmp->f_fsid.val[0] = sptmp->f_fsid.val[1] = 0;
+   prison_enforce_statfs(td->td_ucred, mp, sptmp);
+   sp = sptmp;
+   } else
+