vfs: fix up the assert in i_readcount_dec

Message ID 20230811194814.1612336-1-mjguzik@gmail.com
State New
Headers
Series vfs: fix up the assert in i_readcount_dec |

Commit Message

Mateusz Guzik Aug. 11, 2023, 7:48 p.m. UTC
  Drops a race where 2 threads could spot a positive value and both
proceed to dec to -1, without reporting anything.

Signed-off-by: Mateusz Guzik <mjguzik@gmail.com>
---
 include/linux/fs.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
  

Comments

Christian Brauner Aug. 14, 2023, 3:52 p.m. UTC | #1
On Fri, 11 Aug 2023 21:48:14 +0200, Mateusz Guzik wrote:
> Drops a race where 2 threads could spot a positive value and both
> proceed to dec to -1, without reporting anything.
> 
> 

Applied to the vfs.misc branch of the vfs/vfs.git tree.
Patches in the vfs.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.misc

[1/1] vfs: fix up the assert in i_readcount_dec
      https://git.kernel.org/vfs/vfs/c/fbdf4da0ad64
  

Patch

diff --git a/include/linux/fs.h b/include/linux/fs.h
index 562f2623c9c9..21c8f8ae014d 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2613,8 +2613,7 @@  static inline bool inode_is_open_for_write(const struct inode *inode)
 #if defined(CONFIG_IMA) || defined(CONFIG_FILE_LOCKING)
 static inline void i_readcount_dec(struct inode *inode)
 {
-	BUG_ON(!atomic_read(&inode->i_readcount));
-	atomic_dec(&inode->i_readcount);
+	BUG_ON(atomic_dec_return(&inode->i_readcount) < 0);
 }
 static inline void i_readcount_inc(struct inode *inode)
 {