[PATCH v3 03/14] fs: aio: Remove redundant rcu_read_lock/unlock() in spin_lock

From: pengdonglin
Date: Tue Sep 16 2025 - 00:51:18 EST


From: pengdonglin <pengdonglin@xxxxxxxxxx>

Since commit a8bb74acd8efe ("rcu: Consolidate RCU-sched update-side function definitions")
there is no difference between rcu_read_lock(), rcu_read_lock_bh() and
rcu_read_lock_sched() in terms of RCU read section and the relevant grace
period. That means that spin_lock(), which implies rcu_read_lock_sched(),
also implies rcu_read_lock().

There is no need no explicitly start a RCU read section if one has already
been started implicitly by spin_lock().

Simplify the code and remove the inner rcu_read_lock() invocation.

Cc: Benjamin LaHaise <bcrl@xxxxxxxxx>
Signed-off-by: pengdonglin <pengdonglin@xxxxxxxxxx>
Signed-off-by: pengdonglin <dolinux.peng@xxxxxxxxx>
---
fs/aio.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/fs/aio.c b/fs/aio.c
index 7fc7b6221312..e3f9a5a391b5 100644
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -359,15 +359,14 @@ static int aio_ring_mremap(struct vm_area_struct *vma)
int i, res = -EINVAL;

spin_lock(&mm->ioctx_lock);
- rcu_read_lock();
- table = rcu_dereference(mm->ioctx_table);
+ table = rcu_dereference_check(mm->ioctx_table, lockdep_is_held(&mm->ioctx_lock));
if (!table)
goto out_unlock;

for (i = 0; i < table->nr; i++) {
struct kioctx *ctx;

- ctx = rcu_dereference(table->table[i]);
+ ctx = rcu_dereference_check(table->table[i], lockdep_is_held(&mm->ioctx_lock));
if (ctx && ctx->aio_ring_file == file) {
if (!atomic_read(&ctx->dead)) {
ctx->user_id = ctx->mmap_base = vma->vm_start;
@@ -378,7 +377,6 @@ static int aio_ring_mremap(struct vm_area_struct *vma)
}

out_unlock:
- rcu_read_unlock();
spin_unlock(&mm->ioctx_lock);
return res;
}
--
2.34.1