Re: [PATCH 6/7] afs: Remove erroneous seq |= 1 in volume lookup loop

From: Oleg Nesterov

Date: Tue Jun 09 2026 - 05:37:49 EST


On 06/09, David Howells wrote:
>
> From: Li RongQing <lirongqing@xxxxxxxxx>
>
> The `seq |= 1` operation in the volume lookup loop is incorrect because:
> seq is already incremented at start, making it odd in next iteration
> which triggers lock, but The `|= 1` operation causes seq to be even
> and unintended lockless operation
>
> Remove this erroneous operation to maintain proper lock sequencing.
>
> Fixes: 32222f09782f ("afs: Apply server breaks to mmap'd files in the call processor")
> Signed-off-by: Li RongQing <lirongqing@xxxxxxxxx>
> Signed-off-by: David Howells <dhowells@xxxxxxxxxx>
> Reviewed-by: Oleg Nesterov <oleg@xxxxxxxxxx>
> cc: Marc Dionne <marc.dionne@xxxxxxxxxxxx>
> cc: linux-afs@xxxxxxxxxxxxxxxxxxx
> ---
> fs/afs/callback.c | 1 -
> 1 file changed, 1 deletion(-)
>
> diff --git a/fs/afs/callback.c b/fs/afs/callback.c
> index 894d2bad6b6c..833ac3178ddc 100644
> --- a/fs/afs/callback.c
> +++ b/fs/afs/callback.c
> @@ -140,7 +140,6 @@ static struct afs_volume *afs_lookup_volume_rcu(struct afs_cell *cell,
> break;
> if (!need_seqretry(&cell->volume_lock, seq))
> break;
> - seq |= 1; /* Want a lock next time */

Yes, but now that we have scoped_seqlock_read() we can make another change
on top of this fix. afs_lookup_volume_rcu() can just do

static struct afs_volume *afs_lookup_volume_rcu(struct afs_cell *cell,
afs_volid_t vid)
{
struct afs_volume *volume = NULL;
struct rb_node *p;

scoped_seqlock_read (&cell->volume_lock, ss_lock) {
/* Unfortunately, rbtree walking doesn't give reliable results
* under just the RCU read lock, so we have to check for
* changes.
*/
p = rcu_dereference_raw(cell->volumes.rb_node);
while (p) {
volume = rb_entry(p, struct afs_volume, cell_node);

if (volume->vid < vid)
p = rcu_dereference_raw(p->rb_left);
else if (volume->vid > vid)
p = rcu_dereference_raw(p->rb_right);
else
break;
volume = NULL;
}

if (volume && afs_try_get_volume(volume, afs_volume_trace_get_callback))
break;
}

return volume;
}

Oleg.