Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 26 Aug 2009 23:37:55 +0100
From:      Andrew Brampton <brampton+freebsd@gmail.com>
To:        freebsd-current@freebsd.org
Subject:   [patch] rw_try_wlock does not set recursive bit when recursing
Message-ID:  <d41814900908261537r1726c420p11d3547afde98bbc@mail.gmail.com>

next in thread | raw e-mail | index | archive | help
--0016364c7b992403cd0472131ac0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit

Hi,
The following sequence of commands fails on line 4 with an assertion
that the lock is not currently held:

1: rw_wlock(&rw);
2: if ( rw_try_wlock(&rw) )
3:    rw_wunlock(&rw);
4: rw_wunlock(&rw);

This is because after line 3 is executed the rw lock is no longer
held. I tracked this bug down to _rw_try_wlock which correctly
increments rw_recurse, but does not set the RW_LOCK_RECURSED bit.
Without this bit the third line unlocks the lock and leaves it in a
unlocked state (when it should still be locked). Adding a line to set
this bit makes _rw_try_wlock match the code in _rw_wlock_hard.

I have attached a one line patch which fixes this problem on my 7.2
system, and looking over the CURRENT source it should also apply
cleanly (but I have not tested it on CURRENT). I have also attached
another (slightly longer) patch which fixes the problem as well as
adding an a extra assert. It is up to the FreeBSD developer to decide
which patch they prefer.

thanks
Andrew

--0016364c7b992403cd0472131ac0
Content-Type: text/plain; charset=US-ASCII;
	name="rw_try_wlock.simple-assert.diff.txt"
Content-Disposition: attachment; 
	filename="rw_try_wlock.simple-assert.diff.txt"
Content-Transfer-Encoding: base64
X-Attachment-Id: f_fyumbnii0

SW5kZXg6IGtlcm5fcndsb2NrLmMKPT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PQotLS0ga2Vybl9yd2xvY2suYwkocmV2aXNp
b24gMTkxNzY1KQorKysga2Vybl9yd2xvY2suYwkod29ya2luZyBjb3B5KQpAQCAtMjAyLDggKzIw
MiwxMiBAQCBfcndfdHJ5X3dsb2NrKHN0cnVjdCByd2xvY2sgKnJ3LCBjb25zdCBjaGFyICpmaWxl
LAogCUtBU1NFUlQocnctPnJ3X2xvY2sgIT0gUldfREVTVFJPWUVELAogCSAgICAoInJ3X3RyeV93
bG9jaygpIG9mIGRlc3Ryb3llZCByd2xvY2sgQCAlczolZCIsIGZpbGUsIGxpbmUpKTsKIAotCWlm
IChyd193bG9ja2VkKHJ3KSAmJiAocnctPmxvY2tfb2JqZWN0LmxvX2ZsYWdzICYgUldfUkVDVVJT
RSkgIT0gMCkgeworCWlmIChyd193bG9ja2VkKHJ3KSkgeworCQlLQVNTRVJUKHJ3LT5sb2NrX29i
amVjdC5sb19mbGFncyAmIFJXX1JFQ1VSU0UsCisJCSAgICAoIiVzOiByZWN1cnNpbmcgYnV0IG5v
bi1yZWN1cnNpdmUgcncgJXMgQCAlczolZFxuIiwKKwkJICAgIF9fZnVuY19fLCBydy0+bG9ja19v
YmplY3QubG9fbmFtZSwgZmlsZSwgbGluZSkpOwogCQlydy0+cndfcmVjdXJzZSsrOworCQlhdG9t
aWNfc2V0X3B0cigmcnctPnJ3X2xvY2ssIFJXX0xPQ0tfUkVDVVJTRUQpOwogCQlydmFsID0gMTsK
IAl9IGVsc2UKIAkJcnZhbCA9IGF0b21pY19jbXBzZXRfYWNxX3B0cigmcnctPnJ3X2xvY2ssIFJX
X1VOTE9DS0VELAo=
--0016364c7b992403cd0472131ac0
Content-Type: text/plain; charset=US-ASCII; name="rw_try_wlock.simple.diff.txt"
Content-Disposition: attachment; filename="rw_try_wlock.simple.diff.txt"
Content-Transfer-Encoding: base64
X-Attachment-Id: f_fyumbnim1

SW5kZXg6IGtlcm5fcndsb2NrLmMKPT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PQotLS0ga2Vybl9yd2xvY2suYwkocmV2aXNp
b24gMTkxNzY1KQorKysga2Vybl9yd2xvY2suYwkod29ya2luZyBjb3B5KQpAQCAtMjA0LDYgKzIw
NCw3IEBAIF9yd190cnlfd2xvY2soc3RydWN0IHJ3bG9jayAqcncsIGNvbnN0IGNoYXIgKmZpbGUs
CiAKIAlpZiAocndfd2xvY2tlZChydykgJiYgKHJ3LT5sb2NrX29iamVjdC5sb19mbGFncyAmIFJX
X1JFQ1VSU0UpICE9IDApIHsKIAkJcnctPnJ3X3JlY3Vyc2UrKzsKKwkJYXRvbWljX3NldF9wdHIo
JnJ3LT5yd19sb2NrLCBSV19MT0NLX1JFQ1VSU0VEKTsKIAkJcnZhbCA9IDE7CiAJfSBlbHNlCiAJ
CXJ2YWwgPSBhdG9taWNfY21wc2V0X2FjcV9wdHIoJnJ3LT5yd19sb2NrLCBSV19VTkxPQ0tFRCwK
--0016364c7b992403cd0472131ac0--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?d41814900908261537r1726c420p11d3547afde98bbc>