Skip to contentSkip to conversation

dax: fix assertion in dax_iomap_rw()

PATCH In review Jan Kara 2 participants 2 messages Oct 2, 2025

Subsystems (2)
lore
Share & tools
lore

Jan Kara

author reviewer
#0 lore raw

PATCH 1/1 dax: fix assertion in dax_iomap_rw()

dax_iomap_rw() asserts that inode lock is held when reading from it. The assert triggers on erofs as it indeed doesn't hold any locks in this case - naturally because there's nothing to race against when the filesystem is read-only. Check the locking only if the filesystem is actually writeable.

---
 fs/dax.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/dax.c +1 -1
index 20ecf652c129..187f8c325744 100644
@@ -1752,7 +1752,7 @@ dax_iomap_rw(struct kiocb *iocb, struct iov_iter *iter,
 	if (iov_iter_rw(iter) == WRITE) {
 		lockdep_assert_held_write(&iomi.inode->i_rwsem);
 		iomi.flags |= IOMAP_WRITE;
-	} else {
+	} else if (!IS_RDONLY(iomi.inode)) {
 		lockdep_assert_held(&iomi.inode->i_rwsem);
 	}
 
Signature · 1 line
2.51.0
#1 lore raw

Hi Jan,

Quoted 17 lines · Jan Kara

dax_iomap_rw() asserts that inode lock is held when reading from it. The assert triggers on erofs as it indeed doesn't hold any locks in this case - naturally because there's nothing to race against when the filesystem is read-only. Check the locking only if the filesystem is actually writeable.

---
  fs/dax.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
fs/dax.c +0 -0
index 20ecf652c129..187f8c325744 100644

fs/dax.c dax_iomap_rw(struct kiocb *iocb, struct iov_iter *iter, · line 1755

Quoted 5 lines
fs/dax.c +1 -1
@@ -1752,7 +1752,7 @@ dax_iomap_rw(struct kiocb *iocb, struct iov_iter *iter,
  	if (iov_iter_rw(iter) == WRITE) {
  		lockdep_assert_held_write(&iomi.inode->i_rwsem);
  		iomi.flags |= IOMAP_WRITE;
-	} else {
+	} else if (!IS_RDONLY(iomi.inode)) {

Thanks, Yuezheng also wrote a similiar patch
days ago (but it seems he didn't cc more related
people),
https://lore.kernel.org/r/[email protected]

both patches look good to me, thanks for the fix.

Thanks,
Gao Xiang

Quoted 3 lines
fs/dax.c +0 -0
  		lockdep_assert_held(&iomi.inode->i_rwsem);
  	}