linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
To: linux-kernel@vger.kernel.org
Cc: "André Almeida" <andrealmeid@igalia.com>,
	"Darren Hart" <dvhart@infradead.org>,
	"Davidlohr Bueso" <dave@stgolabs.net>,
	"Ingo Molnar" <mingo@redhat.com>,
	"Juri Lelli" <juri.lelli@redhat.com>,
	"Peter Zijlstra" <peterz@infradead.org>,
	"Thomas Gleixner" <tglx@linutronix.de>,
	"Valentin Schneider" <vschneid@redhat.com>,
	"Borislav Petkov" <bp@alien8.de>,
	"Waiman Long" <longman@redhat.com>,
	"Dan Carpenter" <dan.carpenter@linaro.org>,
	"Anders Roxell" <anders.roxell@linaro.org>,
	"Sebastian Andrzej Siewior" <bigeasy@linutronix.de>
Subject: [PATCH 5/5] selftests/futex: fix futex_wait() for 32bit ARM
Date: Wed, 27 Aug 2025 15:00:11 +0200	[thread overview]
Message-ID: <20250827130011.677600-6-bigeasy@linutronix.de> (raw)
In-Reply-To: <20250827130011.677600-1-bigeasy@linutronix.de>

From: Dan Carpenter <dan.carpenter@linaro.org>

On 32bit ARM systems gcc-12 will use 32bit timestamps while gcc-13 and
later will use 64bit timestamps.  The problem is that SYS_futex will
continue pointing at the 32bit system call.  This makes the futex_wait
test fail like this:

waiter failed errno 110
not ok 1 futex_wake private returned: 0 Success
waiter failed errno 110
not ok 2 futex_wake shared (page anon) returned: 0 Success
waiter failed errno 110
not ok 3 futex_wake shared (file backed) returned: 0 Success

Instead of compiling differently depending on the gcc version, use the
-D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64 options to ensure that we are
building with 64bit timestamps.  Then use ifdefs to make SYS_futex point
to the 64bit system call.

Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Tested-by: Anders Roxell <anders.roxell@linaro.org>
Link: https://lore.kernel.org/r/ebd4a415169f9a3153bbd3c1fe6244511c9d1cb3.1756217858.git.dan.carpenter@linaro.org
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 tools/testing/selftests/futex/functional/Makefile |  2 +-
 tools/testing/selftests/futex/include/futextest.h | 11 +++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/futex/functional/Makefile b/tools/testing/selftests/futex/functional/Makefile
index 8cfb87f7f7c50..ddfa61d857b9b 100644
--- a/tools/testing/selftests/futex/functional/Makefile
+++ b/tools/testing/selftests/futex/functional/Makefile
@@ -1,6 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0
 INCLUDES := -I../include -I../../ $(KHDR_INCLUDES)
-CFLAGS := $(CFLAGS) -g -O2 -Wall -pthread $(INCLUDES) $(KHDR_INCLUDES)
+CFLAGS := $(CFLAGS) -g -O2 -Wall -pthread -D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64 $(INCLUDES) $(KHDR_INCLUDES)
 LDLIBS := -lpthread -lrt -lnuma
 
 LOCAL_HDRS := \
diff --git a/tools/testing/selftests/futex/include/futextest.h b/tools/testing/selftests/futex/include/futextest.h
index 7a5fd1d5355e7..3d48e9789d9fe 100644
--- a/tools/testing/selftests/futex/include/futextest.h
+++ b/tools/testing/selftests/futex/include/futextest.h
@@ -58,6 +58,17 @@ typedef volatile u_int32_t futex_t;
 #define SYS_futex SYS_futex_time64
 #endif
 
+/*
+ * On 32bit systems if we use "-D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64" or if
+ * we are using a newer compiler then the size of the timestamps will be 64bit,
+ * however, the SYS_futex will still point to the 32bit futex system call.
+ */
+#if __SIZEOF_POINTER__ == 4 && defined(SYS_futex_time64) && \
+	defined(_TIME_BITS) && _TIME_BITS == 64
+# undef SYS_futex
+# define SYS_futex SYS_futex_time64
+#endif
+
 /**
  * futex() - SYS_futex syscall wrapper
  * @uaddr:	address of first futex
-- 
2.50.1


  parent reply	other threads:[~2025-08-27 13:00 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-27 13:00 [PATCH 0/5] selftests/futex: Collected fixups Sebastian Andrzej Siewior
2025-08-27 13:00 ` [PATCH 1/5] selftests/futex: Remove the -g parameter from futex_priv_hash Sebastian Andrzej Siewior
2025-08-27 15:38   ` André Almeida
2025-09-01 14:28   ` [tip: locking/futex] " tip-bot2 for Sebastian Andrzej Siewior
2025-08-27 13:00 ` [PATCH 2/5] selftests/futex: Fix some futex_numa_mpol subtests Sebastian Andrzej Siewior
2025-08-27 15:40   ` André Almeida
2025-08-29  6:27     ` Sebastian Andrzej Siewior
2025-09-01 14:28   ` [tip: locking/futex] " tip-bot2 for Waiman Long
2025-08-27 13:00 ` [PATCH 3/5] selftests/futex: fix format-security warnings in futex_priv_hash Sebastian Andrzej Siewior
2025-09-01 14:28   ` [tip: locking/futex] selftests/futex: Fix " tip-bot2 for Nai-Chen Cheng
2025-08-27 13:00 ` [PATCH 4/5] selftests/futex: fix typos and grammar " Sebastian Andrzej Siewior
2025-08-27 15:49   ` André Almeida
2025-09-01 14:28   ` [tip: locking/futex] selftests/futex: Fix " tip-bot2 for Gopi Krishna Menon
2025-08-27 13:00 ` Sebastian Andrzej Siewior [this message]
2025-08-27 15:50   ` [PATCH 5/5] selftests/futex: fix futex_wait() for 32bit ARM André Almeida
2025-09-01 14:28   ` [tip: locking/futex] selftests/futex: Fix " tip-bot2 for Dan Carpenter

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=20250827130011.677600-6-bigeasy@linutronix.de \
    --to=bigeasy@linutronix.de \
    --cc=anders.roxell@linaro.org \
    --cc=andrealmeid@igalia.com \
    --cc=bp@alien8.de \
    --cc=dan.carpenter@linaro.org \
    --cc=dave@stgolabs.net \
    --cc=dvhart@infradead.org \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=longman@redhat.com \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=vschneid@redhat.com \
    /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).