mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-05 18:41:58 +09:00
afs: fix the usage of read_seqbegin_or_lock() in afs_lookup_volume_rcu()
[ Upstream commit 4121b4337146b64560d1e46ebec77196d9287802 ]
David Howells says:
(2) afs_lookup_volume_rcu().
There can be a lot of volumes known by a system. A thousand would
require a 10-step walk and this is drivable by remote operation, so I
think this should probably take a lock on the second pass too.
Make the "seq" counter odd on the 2nd pass, otherwise read_seqbegin_or_lock()
never takes the lock.
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Marc Dionne <marc.dionne@auristor.com>
cc: linux-afs@lists.infradead.org
Link: https://lore.kernel.org/r/20231130115606.GA21571@redhat.com/
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
91256fcd57
commit
eef7c4cd98
@@ -110,13 +110,14 @@ static struct afs_volume *afs_lookup_volume_rcu(struct afs_cell *cell,
|
|||||||
{
|
{
|
||||||
struct afs_volume *volume = NULL;
|
struct afs_volume *volume = NULL;
|
||||||
struct rb_node *p;
|
struct rb_node *p;
|
||||||
int seq = 0;
|
int seq = 1;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
/* Unfortunately, rbtree walking doesn't give reliable results
|
/* Unfortunately, rbtree walking doesn't give reliable results
|
||||||
* under just the RCU read lock, so we have to check for
|
* under just the RCU read lock, so we have to check for
|
||||||
* changes.
|
* changes.
|
||||||
*/
|
*/
|
||||||
|
seq++; /* 2 on the 1st/lockless path, otherwise odd */
|
||||||
read_seqbegin_or_lock(&cell->volume_lock, &seq);
|
read_seqbegin_or_lock(&cell->volume_lock, &seq);
|
||||||
|
|
||||||
p = rcu_dereference_raw(cell->volumes.rb_node);
|
p = rcu_dereference_raw(cell->volumes.rb_node);
|
||||||
|
|||||||
Reference in New Issue
Block a user