public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <djwong@kernel.org>
To: cem@kernel.org
Cc: Anthony Iliopoulos <ailiop@suse.com>, linux-xfs@vger.kernel.org
Subject: [PATCH v1.1 6/6] libxfs: fix atomic64_t detection on x86 32-bit architectures
Date: Tue, 12 Sep 2023 12:47:51 -0700	[thread overview]
Message-ID: <20230912194751.GB3415652@frogsfrogsfrogs> (raw)
In-Reply-To: <169454761010.3539425.13599600178844641233.stgit@frogsfrogsfrogs>

From: Darrick J. Wong <djwong@kernel.org>

xfsprogs during compilation tries to detect if liburcu supports atomic
64-bit ops on the platform it is being compiled on, and if not it falls
back to using pthread mutex locks.

The detection logic for that fallback relies on _uatomic_link_error()
which is a link-time trick used by liburcu that will cause compilation
errors on archs that lack the required support. That only works for the
generic liburcu code though, and it is not implemented for the
x86-specific code.

In practice this means that when xfsprogs is compiled on 32-bit x86
archs will successfully link to liburcu for atomic ops, but liburcu does
not support atomic64_t on those archs. It indicates this during runtime
by generating an illegal instruction that aborts execution, and thus
causes various xfsprogs utils to be segfaulting.

Fix this by requiring that unsigned longs are at least 64 bits in size,
which /usually/ means that 64-bit atomic counters are supported.  We
can't simply execute the liburcu atomic64_t detection code during
configure instead of only relying on the linker error because that
doesn't work for cross-compiled packages.

Fixes: 7448af588a2e ("libxfs: fix atomic64_t poorly for 32-bit architectures")
Reported-by: Anthony Iliopoulos <ailiop@suse.com>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
v1.1: This time with correct commit message.
---
 m4/package_urcu.m4 |    9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/m4/package_urcu.m4 b/m4/package_urcu.m4
index ef116e0cda7..4bb2b886f06 100644
--- a/m4/package_urcu.m4
+++ b/m4/package_urcu.m4
@@ -26,7 +26,11 @@ rcu_init();
 #
 # Make sure that calling uatomic_inc on a 64-bit integer doesn't cause a link
 # error on _uatomic_link_error, which is how liburcu signals that it doesn't
-# support atomic operations on 64-bit data types.
+# support atomic operations on 64-bit data types for its generic
+# implementation (which relies on compiler builtins). For certain archs
+# where liburcu carries its own implementation (such as x86_32), it
+# signals lack of support during runtime by emitting an illegal
+# instruction, so we also need to check CAA_BITS_PER_LONG to detect that.
 #
 AC_DEFUN([AC_HAVE_LIBURCU_ATOMIC64],
   [ AC_MSG_CHECKING([for atomic64_t support in liburcu])
@@ -34,8 +38,11 @@ AC_DEFUN([AC_HAVE_LIBURCU_ATOMIC64],
     [	AC_LANG_PROGRAM([[
 #define _GNU_SOURCE
 #include <urcu.h>
+#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
 	]], [[
 long long f = 3;
+
+BUILD_BUG_ON(CAA_BITS_PER_LONG < 64);
 uatomic_inc(&f);
 	]])
     ], have_liburcu_atomic64=yes

  reply	other threads:[~2023-09-12 19:47 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-12 19:39 [PATCHSET 0/6] xfsprogs: minor fixes Darrick J. Wong
2023-09-12 19:39 ` [PATCH 1/6] libfrog: fix overly sleep workqueues Darrick J. Wong
2023-09-13 12:41   ` Carlos Maiolino
2023-10-05 12:34   ` Carlos Maiolino
2023-09-12 19:39 ` [PATCH 2/6] libfrog: don't fail on XFS_FSOP_GEOM_FLAGS_NREXT64 in xfrog_bulkstat_single5 Darrick J. Wong
2023-09-13 12:50   ` Carlos Maiolino
2023-10-05 12:34   ` Carlos Maiolino
2023-09-12 19:39 ` [PATCH 3/6] libxfs: use XFS_IGET_CREATE when creating new files Darrick J. Wong
2023-09-13 12:58   ` Carlos Maiolino
2023-09-14 18:24   ` Bill O'Donnell
2023-10-05 12:35   ` Carlos Maiolino
2023-09-12 19:39 ` [PATCH 4/6] xfs_scrub: actually return errno from check_xattr_ns_names Darrick J. Wong
2023-09-13 13:00   ` Carlos Maiolino
2023-10-05 12:36   ` Carlos Maiolino
2023-09-12 19:40 ` [PATCH 5/6] xfs_repair: set aformat and anextents correctly when clearing the attr fork Darrick J. Wong
2023-09-13 13:02   ` Carlos Maiolino
2023-09-14 18:25   ` Bill O'Donnell
2023-10-05 12:37   ` Carlos Maiolino
2023-09-12 19:40 ` [PATCH 6/6] libxfs: fix atomic64_t detection on x86 32-bit architectures Darrick J. Wong
2023-09-12 19:47   ` Darrick J. Wong [this message]
2023-09-13 13:22     ` [PATCH v1.1 " Carlos Maiolino
2023-09-14 18:26     ` Bill O'Donnell
2023-10-05 12:45     ` Carlos Maiolino

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=20230912194751.GB3415652@frogsfrogsfrogs \
    --to=djwong@kernel.org \
    --cc=ailiop@suse.com \
    --cc=cem@kernel.org \
    --cc=linux-xfs@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