linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: linux-ext4@vger.kernel.org
Subject: [PATCH 15/38] lib/ext2fs: remove 32-bit x86 bitops assembly
Date: Sat, 21 Jan 2023 12:32:07 -0800	[thread overview]
Message-ID: <20230121203230.27624-16-ebiggers@kernel.org> (raw)
In-Reply-To: <20230121203230.27624-1-ebiggers@kernel.org>

From: Eric Biggers <ebiggers@google.com>

The EXT2FS_ADDR() macro is causing -Warray-bounds warnings because it
(sort of) dereferences past the end of the input array.  It's not a
"real" dereference, since the result is passed as a memory operand to
inline asm.  But in the C language sense, it is a dereference.

Instead of trying to fix this code, let's consider that libext2fs *only*
implements the bit operations in assembly for 32-bit x86, which is
rarely used anymore.  The fact that compilers have also improved, and no
one has implemented these for another architecture, even x86_64,
suggests it's not useful either.  So, let's just remove this outdated
code, which was maybe useful in the 90s, but now just causes problems.

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 lib/ext2fs/bitops.c | 14 +------
 lib/ext2fs/bitops.h | 97 ---------------------------------------------
 2 files changed, 2 insertions(+), 109 deletions(-)

diff --git a/lib/ext2fs/bitops.c b/lib/ext2fs/bitops.c
index c4a1d4e09..ce2acc460 100644
--- a/lib/ext2fs/bitops.c
+++ b/lib/ext2fs/bitops.c
@@ -19,14 +19,8 @@
 #include "ext2_fs.h"
 #include "ext2fs.h"
 
-#ifndef _EXT2_HAVE_ASM_BITOPS_
-
 /*
- * For the benefit of those who are trying to port Linux to another
- * architecture, here are some C-language equivalents.  You should
- * recode these in the native assembly language, if at all possible.
- *
- * C language equivalents written by Theodore Ts'o, 9/26/92.
+ * C language bitmap functions written by Theodore Ts'o, 9/26/92.
  * Modified by Pete A. Zaitcev 7/14/95 to be portable to big endian
  * systems, as well as non-32 bit systems.
  */
@@ -65,8 +59,6 @@ int ext2fs_test_bit(unsigned int nr, const void * addr)
 	return (mask & *ADDR);
 }
 
-#endif	/* !_EXT2_HAVE_ASM_BITOPS_ */
-
 void ext2fs_warn_bitmap(errcode_t errcode, unsigned long arg,
 			const char *description)
 {
@@ -78,9 +70,7 @@ void ext2fs_warn_bitmap(errcode_t errcode, unsigned long arg,
 #endif
 }
 
-/*
- * C-only 64 bit ops.
- */
+/* Bitmap functions that take a 64-bit offset */
 
 int ext2fs_set_bit64(__u64 nr, void * addr)
 {
diff --git a/lib/ext2fs/bitops.h b/lib/ext2fs/bitops.h
index 505b3c9c3..9edf59447 100644
--- a/lib/ext2fs/bitops.h
+++ b/lib/ext2fs/bitops.h
@@ -219,14 +219,6 @@ extern errcode_t ext2fs_find_first_set_generic_bmap(ext2fs_generic_bitmap bitmap
  * functions at all; they will be included as normal functions in
  * inline.c
  */
-#ifdef NO_INLINE_FUNCS
-#if (defined(__GNUC__) && (defined(__i386__) || defined(__i486__) || \
-			   defined(__i586__)))
-	/* This prevents bitops.c from trying to include the C */
-	/* function version of these functions */
-#define _EXT2_HAVE_ASM_BITOPS_
-#endif
-#endif /* NO_INLINE_FUNCS */
 
 #if (defined(INCLUDE_INLINE_FUNCS) || !defined(NO_INLINE_FUNCS))
 #ifdef INCLUDE_INLINE_FUNCS
@@ -285,90 +277,6 @@ _INLINE_ void ext2fs_fast_clear_bit64(__u64 nr, void * addr)
 	*ADDR &= (unsigned char) ~(1 << (nr & 0x07));
 }
 
-
-#if ((defined __GNUC__) && !defined(_EXT2_USE_C_VERSIONS_) && \
-     (defined(__i386__) || defined(__i486__) || defined(__i586__)))
-
-#define _EXT2_HAVE_ASM_BITOPS_
-#define _EXT2_HAVE_ASM_SWAB_
-
-/*
- * These are done by inline assembly for speed reasons.....
- *
- * All bitoperations return 0 if the bit was cleared before the
- * operation and != 0 if it was not.  Bit 0 is the LSB of addr; bit 32
- * is the LSB of (addr+1).
- */
-
-/*
- * Some hacks to defeat gcc over-optimizations..
- */
-struct __dummy_h { unsigned long a[100]; };
-#define EXT2FS_ADDR (*(struct __dummy_h *) addr)
-#define EXT2FS_CONST_ADDR (*(const struct __dummy_h *) addr)
-
-_INLINE_ int ext2fs_set_bit(unsigned int nr, void * addr)
-{
-	int oldbit;
-
-	addr = (void *) (((unsigned char *) addr) + (nr >> 3));
-	__asm__ __volatile__("btsl %2,%1\n\tsbbl %0,%0"
-		:"=r" (oldbit),"+m" (EXT2FS_ADDR)
-		:"r" (nr & 7));
-	return oldbit;
-}
-
-_INLINE_ int ext2fs_clear_bit(unsigned int nr, void * addr)
-{
-	int oldbit;
-
-	addr = (void *) (((unsigned char *) addr) + (nr >> 3));
-	__asm__ __volatile__("btrl %2,%1\n\tsbbl %0,%0"
-		:"=r" (oldbit),"+m" (EXT2FS_ADDR)
-		:"r" (nr & 7));
-	return oldbit;
-}
-
-_INLINE_ int ext2fs_test_bit(unsigned int nr, const void * addr)
-{
-	int oldbit;
-
-	addr = (const void *) (((const unsigned char *) addr) + (nr >> 3));
-	__asm__ __volatile__("btl %2,%1\n\tsbbl %0,%0"
-		:"=r" (oldbit)
-		:"m" (EXT2FS_CONST_ADDR),"r" (nr & 7));
-	return oldbit;
-}
-
-_INLINE_ __u32 ext2fs_swab32(__u32 val)
-{
-#ifdef EXT2FS_REQUIRE_486
-	__asm__("bswap %0" : "=r" (val) : "0" (val));
-#else
-	__asm__("xchgb %b0,%h0\n\t"	/* swap lower bytes	*/
-		"rorl $16,%0\n\t"	/* swap words		*/
-		"xchgb %b0,%h0"		/* swap higher bytes	*/
-		:"=q" (val)
-		: "0" (val));
-#endif
-	return val;
-}
-
-_INLINE_ __u16 ext2fs_swab16(__u16 val)
-{
-	__asm__("xchgb %b0,%h0"		/* swap bytes		*/ \
-		: "=q" (val) \
-		:  "0" (val)); \
-		return val;
-}
-
-#undef EXT2FS_ADDR
-
-#endif	/* i386 */
-
-
-#if !defined(_EXT2_HAVE_ASM_SWAB_)
-
 _INLINE_ __u16 ext2fs_swab16(__u16 val)
 {
 	return (val >> 8) | (__u16) (val << 8);
@@ -380,8 +288,6 @@ _INLINE_ __u32 ext2fs_swab32(__u32 val)
 		((val<<8)&0xFF0000) | (val<<24));
 }
 
-#endif /* !_EXT2_HAVE_ASM_SWAB */
-
 _INLINE_ __u64 ext2fs_swab64(__u64 val)
 {
 	return (ext2fs_swab32((__u32) (val >> 32)) |
@@ -691,12 +597,9 @@ _INLINE_ void ext2fs_fast_unmark_block_bitmap_range2(ext2fs_block_bitmap bitmap,
 #undef _INLINE_
 #endif
 
-#ifndef _EXT2_HAVE_ASM_BITOPS_
 extern int ext2fs_set_bit(unsigned int nr,void * addr);
 extern int ext2fs_clear_bit(unsigned int nr, void * addr);
 extern int ext2fs_test_bit(unsigned int nr, const void * addr);
-#endif
-
 extern int ext2fs_set_bit64(__u64 nr,void * addr);
 extern int ext2fs_clear_bit64(__u64 nr, void * addr);
 extern int ext2fs_test_bit64(__u64 nr, const void * addr);
-- 
2.39.0


  parent reply	other threads:[~2023-01-21 20:37 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-21 20:31 [PATCH 00/38] e2fsprogs: misc fixes, and add a GitHub Actions file Eric Biggers
2023-01-21 20:31 ` [PATCH 01/38] configure.ac: only use Windows I/O manager on native Windows Eric Biggers
2023-01-21 20:31 ` [PATCH 02/38] configure.ac: disable tdb by default on Windows Eric Biggers
2023-01-21 20:31 ` [PATCH 03/38] configure.ac: automatically add include/mingw/ headers Eric Biggers
2023-01-21 20:31 ` [PATCH 04/38] configure: regenerate Eric Biggers
2023-01-21 20:31 ` [PATCH 05/38] config/install-sh: update to latest version Eric Biggers
2023-01-21 20:31 ` [PATCH 06/38] lib, misc: eliminate dependency on Winsock Eric Biggers
2023-01-21 20:31 ` [PATCH 07/38] lib/blkid: remove 32-bit x86 byteswap assembly Eric Biggers
2023-01-24 18:21   ` Andreas Dilger
2023-01-21 20:32 ` [PATCH 08/38] lib/blkid: fix unaligned access to hfs_mdb Eric Biggers
2023-01-21 20:32 ` [PATCH 09/38] lib/blkid: fix -Wunused-variable warning in blkid_get_dev_size() Eric Biggers
2023-01-21 20:32 ` [PATCH 10/38] lib/blkid: suppress -Wunused-result warning in blkid_flush_cache() Eric Biggers
2023-01-21 20:32 ` [PATCH 11/38] lib/blkid: suppress -Wstringop-truncation warning in blkid_strndup() Eric Biggers
2023-01-21 20:32 ` [PATCH 12/38] lib/e2p: fix a -Wunused-variable warning in getflags() Eric Biggers
2023-01-21 20:32 ` [PATCH 13/38] lib/{e2p,ss}: remove manual declarations of errno Eric Biggers
2023-01-21 20:32 ` [PATCH 14/38] lib/et: fix "unused variable" warnings when !HAVE_FCNTL Eric Biggers
2023-01-21 20:32 ` Eric Biggers [this message]
2023-01-21 20:32 ` [PATCH 16/38] lib/ext2fs: consistently use #ifdefs in ext2fs_print_bmap_statistics() Eric Biggers
2023-01-21 20:32 ` [PATCH 17/38] lib/ext2fs: remove unused variable in ext2fs_xattrs_read_inode() Eric Biggers
2023-01-21 20:32 ` [PATCH 18/38] lib/ext2fs: fix a printf format specifier in file_test() Eric Biggers
2023-01-21 20:32 ` [PATCH 19/38] lib/ext2fs: fix two compiler warnings in windows_io.c Eric Biggers
2023-01-21 20:32 ` [PATCH 20/38] lib/ext2fs: fix a -Wpointer-sign warning in ext2fs_mmp_start() Eric Biggers
2023-01-21 20:32 ` [PATCH 21/38] lib/{ext2fs,support}: fix 32-bit Windows build Eric Biggers
2023-01-21 20:32 ` [PATCH 22/38] lib/ss: fix 'make install' by creating man1dir Eric Biggers
2023-01-21 20:32 ` [PATCH 23/38] lib/support: remove unused label in get_devname() Eric Biggers
2023-01-21 20:32 ` [PATCH 24/38] lib/support: clean up definition of flags_array Eric Biggers
2023-01-21 20:32 ` [PATCH 25/38] lib/uuid: remove conflicting Windows implementation of gettimeofday() Eric Biggers
2023-01-21 20:32 ` [PATCH 26/38] e2fsck: use real functions for kernel slab functions Eric Biggers
2023-01-21 20:32 ` [PATCH 27/38] misc/create_inode: fix -Wunused-variable warnings in __populate_fs() Eric Biggers
2023-01-21 20:32 ` [PATCH 28/38] misc/create_inode: simplify logic in scandir() Eric Biggers
2023-01-21 20:32 ` [PATCH 29/38] misc/e4defrag: fix -Wstringop-truncation warnings Eric Biggers
2023-01-21 20:32 ` [PATCH 30/38] misc/fuse2fs: avoid error-prone strncpy() pattern Eric Biggers
2023-01-21 20:32 ` [PATCH 31/38] misc/mk_hugefiles: simplify get_partition_start() Eric Biggers
2023-01-21 20:32 ` [PATCH 32/38] misc/mke2fs: fix Windows build Eric Biggers
2023-01-21 20:32 ` [PATCH 33/38] misc/mke2fs: fix a -Wunused-variable warning in PRS() Eric Biggers
2023-01-21 20:32 ` [PATCH 34/38] misc/tune2fs: fix setting fsuuid::fsu_len Eric Biggers
2023-01-21 20:32 ` [PATCH 35/38] misc/tune2fs: fix -Wunused-variable warnings in handle_fslabel() Eric Biggers
2023-01-21 20:32 ` [PATCH 36/38] misc/util.c: enable MinGW alarm() when building for Windows Eric Biggers
2023-01-21 20:32 ` [PATCH 37/38] resize2fs: remove unused variable from adjust_superblock() Eric Biggers
2023-01-21 20:32 ` [PATCH 38/38] Add a configuration file for GitHub Actions Eric Biggers
2023-01-24 20:59 ` [PATCH 00/38] e2fsprogs: misc fixes, and add a GitHub Actions file Andreas Dilger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230121203230.27624-16-ebiggers@kernel.org \
    --to=ebiggers@kernel.org \
    --cc=linux-ext4@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).