Skip to contentSkip to conversation

include/linux/fs.h: add inode_lock_killable()

PATCH Applied Max Kellermann 3 participants 9 messages May 13, 2025 – May 15, 2025 VFS

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/4 include/linux/fs.h: add inode_lock_killable()

Prepare for making inode operations killable while they're waiting for the lock.

---
 include/linux/fs.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
include/linux/fs.h +10 -0
index 016b0fe1536e..5e4ac873228d 100644
@@ -867,6 +867,11 @@ static inline void inode_lock(struct inode *inode)
 	down_write(&inode->i_rwsem);
 }
 
+static inline __must_check int inode_lock_killable(struct inode *inode)
+{
+	return down_write_killable(&inode->i_rwsem);
+}
+
 static inline void inode_unlock(struct inode *inode)
 {
 	up_write(&inode->i_rwsem);
@@ -877,6 +882,11 @@ static inline void inode_lock_shared(struct inode *inode)
 	down_read(&inode->i_rwsem);
 }
 
+static inline __must_check int inode_lock_shared_killable(struct inode *inode)
+{
+	return down_read_killable(&inode->i_rwsem);
+}
+
 static inline void inode_unlock_shared(struct inode *inode)
 {
 	up_read(&inode->i_rwsem);
Signature · 1 line
2.47.2
#1 lore raw

PATCH v2 2/4 fs/open: make chmod_common() and chown_common() killable

Allows killing processes that are waiting for the inode lock.

---
v2: split into separate patches

This part was reviewed by Christian Brauner here:
https://lore.kernel.org/linux-fsdevel/20250512-unrat-kapital-2122d3777c5d@brauner/

---
 fs/open.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
fs/open.c +7 -2
index a9063cca9911..d2f2df52c458 100644
@@ -635,7 +635,9 @@ int chmod_common(const struct path *path, umode_t mode)
 	if (error)
 		return error;
 retry_deleg:
-	inode_lock(inode);
+	error = inode_lock_killable(inode);
+	if (error)
+		goto out_mnt_unlock;
 	error = security_path_chmod(path, mode);
 	if (error)
 		goto out_unlock;
@@ -650,6 +652,7 @@ int chmod_common(const struct path *path, umode_t mode)
 		if (!error)
 			goto retry_deleg;
 	}
+out_mnt_unlock:
 	mnt_drop_write(path->mnt);
 	return error;
 }
@@ -769,7 +772,9 @@ int chown_common(const struct path *path, uid_t user, gid_t group)
 		return -EINVAL;
 	if ((group != (gid_t)-1) && !setattr_vfsgid(&newattrs, gid))
 		return -EINVAL;
-	inode_lock(inode);
+	error = inode_lock_killable(inode);
+	if (error)
+		return error;
 	if (!S_ISDIR(inode->i_mode))
 		newattrs.ia_valid |= ATTR_KILL_SUID | ATTR_KILL_PRIV |
 				     setattr_should_drop_sgid(idmap, inode);
Signature · 1 line
2.47.2
reviewer Reviewed-by on v2 2/4
#2 lore raw

Re: [PATCH v2 2/4] fs/open: make chmod_common() and chown_common() killable

Quoted 3 lines · Max Kellermann

Allows killing processes that are waiting for the inode lock.

Looks good. Feel free to add:

Honza

Quoted 48 lines

---
v2: split into separate patches

This part was reviewed by Christian Brauner here:
https://lore.kernel.org/linux-fsdevel/20250512-unrat-kapital-2122d3777c5d@brauner/

---
 fs/open.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
fs/open.c +7 -2
index a9063cca9911..d2f2df52c458 100644
@@ -635,7 +635,9 @@ int chmod_common(const struct path *path, umode_t mode)
 	if (error)
 		return error;
 retry_deleg:
-	inode_lock(inode);
+	error = inode_lock_killable(inode);
+	if (error)
+		goto out_mnt_unlock;
 	error = security_path_chmod(path, mode);
 	if (error)
 		goto out_unlock;
@@ -650,6 +652,7 @@ int chmod_common(const struct path *path, umode_t mode)
 		if (!error)
 			goto retry_deleg;
 	}
+out_mnt_unlock:
 	mnt_drop_write(path->mnt);
 	return error;
 }
@@ -769,7 +772,9 @@ int chown_common(const struct path *path, uid_t user, gid_t group)
 		return -EINVAL;
 	if ((group != (gid_t)-1) && !setattr_vfsgid(&newattrs, gid))
 		return -EINVAL;
-	inode_lock(inode);
+	error = inode_lock_killable(inode);
+	if (error)
+		return error;
 	if (!S_ISDIR(inode->i_mode))
 		newattrs.ia_valid |= ATTR_KILL_SUID | ATTR_KILL_PRIV |
 				     setattr_should_drop_sgid(idmap, inode);
Signature · 1 line
2.47.2
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#3 lore raw

PATCH v2 3/4 fs/open: make do_truncate() killable

In reply to Max Kellermann

Allows killing processes that are waiting for the inode lock.

---
v2: split into separate patches

Review here (though nothing about do_truncate()):
https://lore.kernel.org/linux-fsdevel/20250512-unrat-kapital-2122d3777c5d@brauner/

---
 fs/open.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
fs/open.c +4 -1
index d2f2df52c458..7828234a7caa 100644
@@ -60,7 +60,10 @@ int do_truncate(struct mnt_idmap *idmap, struct dentry *dentry,
 	if (ret)
 		newattrs.ia_valid |= ret | ATTR_FORCE;
 
-	inode_lock(dentry->d_inode);
+	ret = inode_lock_killable(dentry->d_inode);
+	if (ret)
+		return ret;
+
 	/* Note any delegations or leases have already been broken: */
 	ret = notify_change(idmap, dentry, &newattrs, NULL);
 	inode_unlock(dentry->d_inode);
Signature · 1 line
2.47.2
reviewer Reviewed-by on v2 3/4
#4 lore raw

Re: [PATCH v2 3/4] fs/open: make do_truncate() killable

Quoted 3 lines · Max Kellermann

Allows killing processes that are waiting for the inode lock.

Looks good. Feel free to add:

Honza

Quoted 30 lines

---
v2: split into separate patches

Review here (though nothing about do_truncate()):
https://lore.kernel.org/linux-fsdevel/20250512-unrat-kapital-2122d3777c5d@brauner/

---
 fs/open.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
fs/open.c +4 -1
index d2f2df52c458..7828234a7caa 100644
@@ -60,7 +60,10 @@ int do_truncate(struct mnt_idmap *idmap, struct dentry *dentry,
 	if (ret)
 		newattrs.ia_valid |= ret | ATTR_FORCE;
 
-	inode_lock(dentry->d_inode);
+	ret = inode_lock_killable(dentry->d_inode);
+	if (ret)
+		return ret;
+
 	/* Note any delegations or leases have already been broken: */
 	ret = notify_change(idmap, dentry, &newattrs, NULL);
 	inode_unlock(dentry->d_inode);
Signature · 1 line
2.47.2
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#5 lore raw

PATCH v2 4/4 fs/read_write: make default_llseek() killable

In reply to Max Kellermann

Allows killing processes that are waiting for the inode lock.

---
v2: split into separate patches

TODO: review whether all callers can handle EINTR; see
https://lore.kernel.org/linux-fsdevel/20250512-unrat-kapital-2122d3777c5d@brauner/
and
https://lore.kernel.org/linux-fsdevel/hzrj5b7x3rvtxt4qgjxdihhi5vjoc5gw3i35pbyopa7ccucizo@q5c42kjlkly3/

---
 fs/read_write.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/read_write.c +3 -1
index bb0ed26a0b3a..0ef70e128c4a 100644
@@ -332,7 +332,9 @@ loff_t default_llseek(struct file *file, loff_t offset, int whence)
 	struct inode *inode = file_inode(file);
 	loff_t retval;
 
-	inode_lock(inode);
+	retval = inode_lock_killable(inode);
+	if (retval)
+		return retval;
 	switch (whence) {
 		case SEEK_END:
 			offset += i_size_read(inode);
Signature · 1 line
2.47.2
reviewer Reviewed-by on v2 4/4
#6 lore raw

Re: [PATCH v2 4/4] fs/read_write: make default_llseek() killable

Quoted 3 lines · Max Kellermann

Allows killing processes that are waiting for the inode lock.

Looks good. Feel free to add:

Quoted 3 lines

v2: split into separate patches

TODO: review whether all callers can handle EINTR; see

I did a quick audit and everything seems OK AFAICT.

Honza

Quoted 27 lines

https://lore.kernel.org/linux-fsdevel/20250512-unrat-kapital-2122d3777c5d@brauner/
and
https://lore.kernel.org/linux-fsdevel/hzrj5b7x3rvtxt4qgjxdihhi5vjoc5gw3i35pbyopa7ccucizo@q5c42kjlkly3/

---
 fs/read_write.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/read_write.c +3 -1
index bb0ed26a0b3a..0ef70e128c4a 100644
@@ -332,7 +332,9 @@ loff_t default_llseek(struct file *file, loff_t offset, int whence)
 	struct inode *inode = file_inode(file);
 	loff_t retval;
 
-	inode_lock(inode);
+	retval = inode_lock_killable(inode);
+	if (retval)
+		return retval;
 	switch (whence) {
 		case SEEK_END:
 			offset += i_size_read(inode);
Signature · 1 line
2.47.2
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
maintainer Applied
#7 lore raw
In reply to Max Kellermann
Quoted 4 lines · Max Kellermann

Prepare for making inode operations killable while they're waiting for the lock.

Applied to the vfs-6.16.misc branch of the vfs/vfs.git tree. Patches in the vfs-6.16.misc branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs-6.16.misc

[1/4] include/linux/fs.h: add inode_lock_killable()

      https://git.kernel.org/vfs/vfs/c/d8c5507cd140
[2/4] fs/open: make chmod_common() and chown_common() killable
      https://git.kernel.org/vfs/vfs/c/28a3f6ab2fe0
[3/4] fs/open: make do_truncate() killable
      https://git.kernel.org/vfs/vfs/c/d68687564280
[4/4] fs/read_write: make default_llseek() killable
      https://git.kernel.org/vfs/vfs/c/2e1a8fbff51b
reviewer Reviewed-by on v2 1/4
#8 lore raw
In reply to Max Kellermann
Quoted 4 lines · Max Kellermann

Prepare for making inode operations killable while they're waiting for the lock.

Looks good. Feel free to add:

Honza

Quoted 35 lines
---
 include/linux/fs.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
include/linux/fs.h +10 -0
index 016b0fe1536e..5e4ac873228d 100644
@@ -867,6 +867,11 @@ static inline void inode_lock(struct inode *inode)
 	down_write(&inode->i_rwsem);
 }
 
+static inline __must_check int inode_lock_killable(struct inode *inode)
+{
+	return down_write_killable(&inode->i_rwsem);
+}
+
 static inline void inode_unlock(struct inode *inode)
 {
 	up_write(&inode->i_rwsem);
@@ -877,6 +882,11 @@ static inline void inode_lock_shared(struct inode *inode)
 	down_read(&inode->i_rwsem);
 }
 
+static inline __must_check int inode_lock_shared_killable(struct inode *inode)
+{
+	return down_read_killable(&inode->i_rwsem);
+}
+
 static inline void inode_unlock_shared(struct inode *inode)
 {
 	up_read(&inode->i_rwsem);
Signature · 1 line
2.47.2
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR