linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fs: Remove obsolete logic in i_size_read/write
@ 2025-07-16 12:53 Alex
  2025-07-16 13:12 ` Al Viro
  2025-07-17  5:05 ` kernel test robot
  0 siblings, 2 replies; 8+ messages in thread
From: Alex @ 2025-07-16 12:53 UTC (permalink / raw)
  To: viro, brauner, jack, torvalds, paulmck; +Cc: linux-fsdevel, Alex

The logic is used to protect load/store tearing on 32 bit platforms,
for example, after i_size_read returned, there is no guarantee that
inode->size won't be changed. Therefore, READ/WRITE_ONCE suffice, which
is already implied by smp_load_acquire/smp_store_release.

Signed-off-by: Alex <alex.fcyrx@gmail.com>
---
 include/linux/fs.h | 41 -----------------------------------------
 1 file changed, 41 deletions(-)

diff --git a/include/linux/fs.h b/include/linux/fs.h
index 4ec77da65f14..7f743881e20d 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -952,39 +952,10 @@ void filemap_invalidate_lock_two(struct address_space *mapping1,
 void filemap_invalidate_unlock_two(struct address_space *mapping1,
 				   struct address_space *mapping2);
 
-
-/*
- * NOTE: in a 32bit arch with a preemptable kernel and
- * an UP compile the i_size_read/write must be atomic
- * with respect to the local cpu (unlike with preempt disabled),
- * but they don't need to be atomic with respect to other cpus like in
- * true SMP (so they need either to either locally disable irq around
- * the read or for example on x86 they can be still implemented as a
- * cmpxchg8b without the need of the lock prefix). For SMP compiles
- * and 64bit archs it makes no difference if preempt is enabled or not.
- */
 static inline loff_t i_size_read(const struct inode *inode)
 {
-#if BITS_PER_LONG==32 && defined(CONFIG_SMP)
-	loff_t i_size;
-	unsigned int seq;
-
-	do {
-		seq = read_seqcount_begin(&inode->i_size_seqcount);
-		i_size = inode->i_size;
-	} while (read_seqcount_retry(&inode->i_size_seqcount, seq));
-	return i_size;
-#elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPTION)
-	loff_t i_size;
-
-	preempt_disable();
-	i_size = inode->i_size;
-	preempt_enable();
-	return i_size;
-#else
 	/* Pairs with smp_store_release() in i_size_write() */
 	return smp_load_acquire(&inode->i_size);
-#endif
 }
 
 /*
@@ -994,24 +965,12 @@ static inline loff_t i_size_read(const struct inode *inode)
  */
 static inline void i_size_write(struct inode *inode, loff_t i_size)
 {
-#if BITS_PER_LONG==32 && defined(CONFIG_SMP)
-	preempt_disable();
-	write_seqcount_begin(&inode->i_size_seqcount);
-	inode->i_size = i_size;
-	write_seqcount_end(&inode->i_size_seqcount);
-	preempt_enable();
-#elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPTION)
-	preempt_disable();
-	inode->i_size = i_size;
-	preempt_enable();
-#else
 	/*
 	 * Pairs with smp_load_acquire() in i_size_read() to ensure
 	 * changes related to inode size (such as page contents) are
 	 * visible before we see the changed inode size.
 	 */
 	smp_store_release(&inode->i_size, i_size);
-#endif
 }
 
 static inline unsigned iminor(const struct inode *inode)
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-07-17  5:06 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-16 12:53 [PATCH] fs: Remove obsolete logic in i_size_read/write Alex
2025-07-16 13:12 ` Al Viro
2025-07-16 13:28   ` Alex
2025-07-16 13:41     ` Matthew Wilcox
2025-07-16 13:44       ` Alex
2025-07-16 13:57         ` Matthew Wilcox
2025-07-16 14:38           ` Alex
2025-07-17  5:05 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).