<feed xmlns='http://www.w3.org/2005/Atom'>
<title>netbsd/sys/kern/vfs_wapbl.c, branch lockdoc-10.99.5-vfs</title>
<subtitle>NetBSD fork for lockdoc analysis</subtitle>
<link rel='alternate' type='text/html' href='http://git.infra.scholz.ruhr/netbsd/'/>
<entry>
<title>Reorganize b_cache logging, un-deprecate variable name logging</title>
<updated>2023-08-20T16:36:09+00:00</updated>
<author>
<name>Merlin Scholz</name>
<email>merlin@scholz.ruhr</email>
</author>
<published>2023-08-20T16:36:09+00:00</published>
<link rel='alternate' type='text/html' href='http://git.infra.scholz.ruhr/netbsd/commit/?id=6545533869a1eba7272e380cbf5ca103e9181251'/>
<id>6545533869a1eba7272e380cbf5ca103e9181251</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>Add logging for buf-&gt;b_cflags BC_BUSY changes</title>
<updated>2023-08-19T17:16:22+00:00</updated>
<author>
<name>Merlin Scholz</name>
<email>merlin@scholz.ruhr</email>
</author>
<published>2023-08-19T17:16:22+00:00</published>
<link rel='alternate' type='text/html' href='http://git.infra.scholz.ruhr/netbsd/commit/?id=e7b3826cda40b7e543318c19b9093dcceb8b4237'/>
<id>e7b3826cda40b7e543318c19b9093dcceb8b4237</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>sys: Use membar_release/acquire around reference drop.</title>
<updated>2022-04-09T23:38:31+00:00</updated>
<author>
<name>riastradh</name>
<email>riastradh@NetBSD.org</email>
</author>
<published>2022-04-09T23:38:31+00:00</published>
<link rel='alternate' type='text/html' href='http://git.infra.scholz.ruhr/netbsd/commit/?id=1e11a48f28e95996681facbeddec6f993a79e81f'/>
<id>1e11a48f28e95996681facbeddec6f993a79e81f</id>
<content type='text'>
This just goes through my recent reference count membar audit and
changes membar_exit to membar_release and membar_enter to
membar_acquire -- this should make everything cheaper on most CPUs
without hurting correctness, because membar_acquire is generally
cheaper than membar_enter.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This just goes through my recent reference count membar audit and
changes membar_exit to membar_release and membar_enter to
membar_acquire -- this should make everything cheaper on most CPUs
without hurting correctness, because membar_acquire is generally
cheaper than membar_enter.</pre>
</div>
</content>
</entry>
<entry>
<title>fix various typos, mainly in comments.</title>
<updated>2022-04-04T19:33:44+00:00</updated>
<author>
<name>andvar</name>
<email>andvar@NetBSD.org</email>
</author>
<published>2022-04-04T19:33:44+00:00</published>
<link rel='alternate' type='text/html' href='http://git.infra.scholz.ruhr/netbsd/commit/?id=753f02d291ad2a0d00db3c459b65898c4d50ead6'/>
<id>753f02d291ad2a0d00db3c459b65898c4d50ead6</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>sys: Membar audit around reference count releases.</title>
<updated>2022-03-12T15:32:30+00:00</updated>
<author>
<name>riastradh</name>
<email>riastradh@NetBSD.org</email>
</author>
<published>2022-03-12T15:32:30+00:00</published>
<link rel='alternate' type='text/html' href='http://git.infra.scholz.ruhr/netbsd/commit/?id=3eb56af6f9905ba277963986804bb85a91e37e15'/>
<id>3eb56af6f9905ba277963986804bb85a91e37e15</id>
<content type='text'>
If two threads are using an object that is freed when the reference
count goes to zero, we need to ensure that all memory operations
related to the object happen before freeing the object.

Using an atomic_dec_uint_nv(&amp;refcnt) == 0 ensures that only one
thread takes responsibility for freeing, but it's not enough to
ensure that the other thread's memory operations happen before the
freeing.

Consider:

	  Thread A			  Thread B
	obj-&gt;foo = 42;			obj-&gt;baz = 73;
	mumble(&amp;obj-&gt;bar);		grumble(&amp;obj-&gt;quux);
	/* membar_exit(); */		/* membar_exit(); */
	atomic_dec -- not last		atomic_dec -- last
					/* membar_enter(); */
					KASSERT(invariant(obj-&gt;foo,
					    obj-&gt;bar));
					free_stuff(obj);

The memory barriers ensure that

	obj-&gt;foo = 42;
	mumble(&amp;obj-&gt;bar);

in thread A happens before

	KASSERT(invariant(obj-&gt;foo, obj-&gt;bar));
	free_stuff(obj);

in thread B.  Without them, this ordering is not guaranteed.

So in general it is necessary to do

	membar_exit();
	if (atomic_dec_uint_nv(&amp;obj-&gt;refcnt) != 0)
		return;
	membar_enter();

to release a reference, for the `last one out hit the lights' style
of reference counting.  (This is in contrast to the style where one
thread blocks new references and then waits under a lock for existing
ones to drain with a condvar -- no membar needed thanks to mutex(9).)

I searched for atomic_dec to find all these.  Obviously we ought to
have a better abstraction for this because there's so much copypasta.
This is a stop-gap measure to fix actual bugs until we have that.  It
would be nice if an abstraction could gracefully handle the different
styles of reference counting in use -- some years ago I drafted an
API for this, but making it cover everything got a little out of hand
(particularly with struct vnode::v_usecount) and I ended up setting
it aside to work on psref/localcount instead for better scalability.

I got bored of adding #ifdef __HAVE_ATOMIC_AS_MEMBAR everywhere, so I
only put it on things that look performance-critical on 5sec review.
We should really adopt membar_enter_preatomic/membar_exit_postatomic
or something (except they are applicable only to atomic r/m/w, not to
atomic_load/store_*, making the naming annoying) and get rid of all
the ifdefs.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
If two threads are using an object that is freed when the reference
count goes to zero, we need to ensure that all memory operations
related to the object happen before freeing the object.

Using an atomic_dec_uint_nv(&amp;refcnt) == 0 ensures that only one
thread takes responsibility for freeing, but it's not enough to
ensure that the other thread's memory operations happen before the
freeing.

Consider:

	  Thread A			  Thread B
	obj-&gt;foo = 42;			obj-&gt;baz = 73;
	mumble(&amp;obj-&gt;bar);		grumble(&amp;obj-&gt;quux);
	/* membar_exit(); */		/* membar_exit(); */
	atomic_dec -- not last		atomic_dec -- last
					/* membar_enter(); */
					KASSERT(invariant(obj-&gt;foo,
					    obj-&gt;bar));
					free_stuff(obj);

The memory barriers ensure that

	obj-&gt;foo = 42;
	mumble(&amp;obj-&gt;bar);

in thread A happens before

	KASSERT(invariant(obj-&gt;foo, obj-&gt;bar));
	free_stuff(obj);

in thread B.  Without them, this ordering is not guaranteed.

So in general it is necessary to do

	membar_exit();
	if (atomic_dec_uint_nv(&amp;obj-&gt;refcnt) != 0)
		return;
	membar_enter();

to release a reference, for the `last one out hit the lights' style
of reference counting.  (This is in contrast to the style where one
thread blocks new references and then waits under a lock for existing
ones to drain with a condvar -- no membar needed thanks to mutex(9).)

I searched for atomic_dec to find all these.  Obviously we ought to
have a better abstraction for this because there's so much copypasta.
This is a stop-gap measure to fix actual bugs until we have that.  It
would be nice if an abstraction could gracefully handle the different
styles of reference counting in use -- some years ago I drafted an
API for this, but making it cover everything got a little out of hand
(particularly with struct vnode::v_usecount) and I ended up setting
it aside to work on psref/localcount instead for better scalability.

I got bored of adding #ifdef __HAVE_ATOMIC_AS_MEMBAR everywhere, so I
only put it on things that look performance-critical on 5sec review.
We should really adopt membar_enter_preatomic/membar_exit_postatomic
or something (except they are applicable only to atomic r/m/w, not to
atomic_load/store_*, making the naming annoying) and get rid of all
the ifdefs.</pre>
</div>
</content>
</entry>
<entry>
<title>initialize wc_unused to 0, to avoid writing uninitialized memory to disk.</title>
<updated>2021-08-03T20:25:43+00:00</updated>
<author>
<name>chs</name>
<email>chs@NetBSD.org</email>
</author>
<published>2021-08-03T20:25:43+00:00</published>
<link rel='alternate' type='text/html' href='http://git.infra.scholz.ruhr/netbsd/commit/?id=af1d8dbfece77d5ecb8d95d3191f91986142c4ee'/>
<id>af1d8dbfece77d5ecb8d95d3191f91986142c4ee</id>
<content type='text'>
detected by KMSAN.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
detected by KMSAN.</pre>
</div>
</content>
</entry>
<entry>
<title>fix wapbl_discard() to actually discard the queued bufs properly - need</title>
<updated>2020-04-12T17:02:52+00:00</updated>
<author>
<name>jdolecek</name>
<email>jdolecek@NetBSD.org</email>
</author>
<published>2020-04-12T17:02:52+00:00</published>
<link rel='alternate' type='text/html' href='http://git.infra.scholz.ruhr/netbsd/commit/?id=eacbac8c1566203315b6422964cacd2e715f32a5'/>
<id>eacbac8c1566203315b6422964cacd2e715f32a5</id>
<content type='text'>
to set BC_INVAL for them, and also need to explicitly remove them
from the BQ_LOCKED queue

fixes DIAGNOSTIC panic when force unmounting unresponsive disk device
PR kern/51178 by Michael van Elst</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
to set BC_INVAL for them, and also need to explicitly remove them
from the BQ_LOCKED queue

fixes DIAGNOSTIC panic when force unmounting unresponsive disk device
PR kern/51178 by Michael van Elst</pre>
</div>
</content>
</entry>
<entry>
<title>fix race between wapbl_discard() and wapbl_biodone() on forced</title>
<updated>2020-04-12T08:51:41+00:00</updated>
<author>
<name>jdolecek</name>
<email>jdolecek@NetBSD.org</email>
</author>
<published>2020-04-12T08:51:41+00:00</published>
<link rel='alternate' type='text/html' href='http://git.infra.scholz.ruhr/netbsd/commit/?id=a12b9e8f77eb8bfc24b19c35cf1affcf132b052d'/>
<id>a12b9e8f77eb8bfc24b19c35cf1affcf132b052d</id>
<content type='text'>
unmount on shutdown with slow I/O device

wapbl_discard() needs to hold both wl_mtx and bufcache_lock while
manipulating wl_entries - the rw lock is not enough, because
wapbl_biodone() only takes wl_mtx while removing the finished entry
from list

wapbl_biodone() must take bufcache_lock before reading we-&gt;we_wapbl,
so it's blocked until wapbl_discard() finishes, and takes !wl path
appropriately

this is supposed to fix panic on shutdown:
[ 67549.6304123] forcefully unmounting / (/dev/wd0a)...
...
[ 67549.7272030] panic: mutex_vector_enter,510: uninitialized lock (lock=0xffffa722a4f4f5b0, from=ffffffff80a884fa)
...
[ 67549.7272030] wapbl_biodone() at netbsd:wapbl_biodone+0x4d
[ 67549.7272030] biointr() at netbsd:biointr+0x7d
[ 67549.7272030] softint_dispatch() at netbsd:softint_dispatch+0x12c
[ 67549.7272030] Xsoftintr() at netbsd:Xsoftintr+0x4f</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
unmount on shutdown with slow I/O device

wapbl_discard() needs to hold both wl_mtx and bufcache_lock while
manipulating wl_entries - the rw lock is not enough, because
wapbl_biodone() only takes wl_mtx while removing the finished entry
from list

wapbl_biodone() must take bufcache_lock before reading we-&gt;we_wapbl,
so it's blocked until wapbl_discard() finishes, and takes !wl path
appropriately

this is supposed to fix panic on shutdown:
[ 67549.6304123] forcefully unmounting / (/dev/wd0a)...
...
[ 67549.7272030] panic: mutex_vector_enter,510: uninitialized lock (lock=0xffffa722a4f4f5b0, from=ffffffff80a884fa)
...
[ 67549.7272030] wapbl_biodone() at netbsd:wapbl_biodone+0x4d
[ 67549.7272030] biointr() at netbsd:biointr+0x7d
[ 67549.7272030] softint_dispatch() at netbsd:softint_dispatch+0x12c
[ 67549.7272030] Xsoftintr() at netbsd:Xsoftintr+0x4f</pre>
</div>
</content>
</entry>
<entry>
<title>Use the module subsystem's ability to process SYSCTL_SETUP() entries to</title>
<updated>2020-03-16T21:20:09+00:00</updated>
<author>
<name>pgoyette</name>
<email>pgoyette@NetBSD.org</email>
</author>
<published>2020-03-16T21:20:09+00:00</published>
<link rel='alternate' type='text/html' href='http://git.infra.scholz.ruhr/netbsd/commit/?id=76af92acdba119819283afe38a0a0578e91d7e4c'/>
<id>76af92acdba119819283afe38a0a0578e91d7e4c</id>
<content type='text'>
automate installation of sysctl nodes.

Note that there are still a number of device and pseudo-device modules
that create entries tied to individual device units, rather than to the
module itself.  These are not changed.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
automate installation of sysctl nodes.

Note that there are still a number of device and pseudo-device modules
that create entries tied to individual device units, rather than to the
module itself.  These are not changed.</pre>
</div>
</content>
</entry>
<entry>
<title>OR into bp-&gt;b_cflags; don't overwrite.</title>
<updated>2020-03-14T15:31:29+00:00</updated>
<author>
<name>ad</name>
<email>ad@NetBSD.org</email>
</author>
<published>2020-03-14T15:31:29+00:00</published>
<link rel='alternate' type='text/html' href='http://git.infra.scholz.ruhr/netbsd/commit/?id=44a65f485f886e0fe4eed08487250a55b949f1cd'/>
<id>44a65f485f886e0fe4eed08487250a55b949f1cd</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
</feed>
