* tgt on arm64 and USE_SIGNALFD
@ 2024-02-14 20:14 Andreas Hasenack
2024-02-15 0:26 ` FUJITA Tomonori
0 siblings, 1 reply; 4+ messages in thread
From: Andreas Hasenack @ 2024-02-14 20:14 UTC (permalink / raw)
To: stgt, Sergio Durigan Junior
Hi,
is USE_SIGNALFD meant to be supported on arm64? The check in
bs/util.h[1] is looking for __NR_signalfd, but arm64 only has the
newer __NR_signalfd4[2]:
#if defined(__NR_signalfd) && defined(USE_SIGNALFD)
...
#else
#define __signalfd(fd, mask, flags) (-1)
struct signalfd_siginfo {
};
#endif
Since that #ifdef fails, the signalfd_siginfo struct gets redefined to
be empty, and this is tripping a gcc check later on in usr/bs.c[3]
when gcc thinks something is being written into siginfo which is now
zero bytes long:
struct signalfd_siginfo siginfo[16];
...
ret = read(fd, (char *)siginfo, sizeof(siginfo));
Build:
bs.c: In function ‘bs_sig_request_done’:
bs.c:196:15: error: ‘read’ writing 1 byte into a region of size 0
overflows the destination [-Werror=stringop-overflow=]
196 | ret = read(fd, (char *)siginfo, sizeof(siginfo));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bs.c:193:33: note: destination object ‘siginfo’ of size 0
193 | struct signalfd_siginfo siginfo[16];
| ^~~~~~~
This error happens with -D_FORTIFY_SOURCE=3 and -O of 1 or higher, and
looks like a gcc bug, and a few similar to this have been filed
already[4].
1. https://github.com/fujita/tgt/blob/master/usr/util.h#L106
2. https://github.com/bminor/glibc/blob/f9ac84f92f151e07586c55e14ed628d493a5929d/sysdeps/unix/sysv/linux/aarch64/arch-syscall.h#L255
3. https://github.com/fujita/tgt/blob/master/usr/bs.c#L196
4. https://gcc.gnu.org/bugzilla/buglist.cgi?quicksearch=writing%201%20byte%20into%20a%20region%20of%20size%200
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: tgt on arm64 and USE_SIGNALFD
2024-02-14 20:14 tgt on arm64 and USE_SIGNALFD Andreas Hasenack
@ 2024-02-15 0:26 ` FUJITA Tomonori
2024-02-15 13:39 ` Andreas Hasenack
0 siblings, 1 reply; 4+ messages in thread
From: FUJITA Tomonori @ 2024-02-15 0:26 UTC (permalink / raw)
To: andreas; +Cc: stgt, sergio.durigan
Hi,
On Wed, 14 Feb 2024 17:14:42 -0300
Andreas Hasenack <andreas@canonical.com> wrote:
> is USE_SIGNALFD meant to be supported on arm64? The check in
> bs/util.h[1] is looking for __NR_signalfd, but arm64 only has the
> newer __NR_signalfd4[2]:
>
> #if defined(__NR_signalfd) && defined(USE_SIGNALFD)
> ...
> #else
> #define __signalfd(fd, mask, flags) (-1)
> struct signalfd_siginfo {
> };
> #endif
I think that we don't need this hack anymore (it was necessary when
the signalfd feature was introduced). I've not tested on arm64 but
I guess that simply using sys/signalfd.h works like the following?
diff --git a/usr/bs.c b/usr/bs.c
index 8171a32..8da5a9b 100644
--- a/usr/bs.c
+++ b/usr/bs.c
@@ -311,7 +311,7 @@ static int bs_init_signalfd(void)
sigaddset(&mask, SIGUSR2);
sigprocmask(SIG_BLOCK, &mask, NULL);
- sig_fd = __signalfd(-1, &mask, 0);
+ sig_fd = signalfd(-1, &mask, 0);
if (sig_fd < 0)
return 1;
diff --git a/usr/util.h b/usr/util.h
index c709f9b..8aef6ab 100644
--- a/usr/util.h
+++ b/usr/util.h
@@ -14,11 +14,12 @@
#include <stdlib.h>
#include <string.h>
#include <limits.h>
+#include <linux/fs.h>
#include <linux/types.h>
#include <sys/ioctl.h>
-#include <linux/fs.h>
-#include <sys/types.h>
+#include <sys/signalfd.h>
#include <sys/stat.h>
+#include <sys/types.h>
#include "be_byteshift.h"
@@ -103,44 +104,6 @@ static inline int between(uint32_t seq1, uint32_t seq2, uint32_t seq3)
extern unsigned long pagesize, pageshift;
-#if defined(__NR_signalfd) && defined(USE_SIGNALFD)
-
-/*
- * workaround for broken linux/signalfd.h including
- * usr/include/linux/fcntl.h
- */
-#define _LINUX_FCNTL_H
-
-#include <linux/signalfd.h>
-
-static inline int __signalfd(int fd, const sigset_t *mask, int flags)
-{
- int fd2, ret;
-
- fd2 = syscall(__NR_signalfd, fd, mask, _NSIG / 8);
- if (fd2 < 0)
- return fd2;
-
- ret = fcntl(fd2, F_GETFL);
- if (ret < 0) {
- close(fd2);
- return -1;
- }
-
- ret = fcntl(fd2, F_SETFL, ret | O_NONBLOCK);
- if (ret < 0) {
- close(fd2);
- return -1;
- }
-
- return fd2;
-}
-#else
-#define __signalfd(fd, mask, flags) (-1)
-struct signalfd_siginfo {
-};
-#endif
-
/* convert string to integer, check for validity of the string numeric format
* and the natural boundaries of the integer value type (first get a 64-bit
* value and check that it fits the range of the destination integer).
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: tgt on arm64 and USE_SIGNALFD
2024-02-15 0:26 ` FUJITA Tomonori
@ 2024-02-15 13:39 ` Andreas Hasenack
2024-02-16 10:01 ` FUJITA Tomonori
0 siblings, 1 reply; 4+ messages in thread
From: Andreas Hasenack @ 2024-02-15 13:39 UTC (permalink / raw)
To: FUJITA Tomonori; +Cc: stgt, sergio.durigan
Hello,
On Wed, Feb 14, 2024 at 9:26 PM FUJITA Tomonori
<fujita.tomonori@gmail.com> wrote:
>
> Hi,
>
> On Wed, 14 Feb 2024 17:14:42 -0300
> Andreas Hasenack <andreas@canonical.com> wrote:
>
> > is USE_SIGNALFD meant to be supported on arm64? The check in
> > bs/util.h[1] is looking for __NR_signalfd, but arm64 only has the
> > newer __NR_signalfd4[2]:
> >
> > #if defined(__NR_signalfd) && defined(USE_SIGNALFD)
> > ...
> > #else
> > #define __signalfd(fd, mask, flags) (-1)
> > struct signalfd_siginfo {
> > };
> > #endif
>
> I think that we don't need this hack anymore (it was necessary when
> the signalfd feature was introduced). I've not tested on arm64 but
> I guess that simply using sys/signalfd.h works like the following?
Yes, thank you, that worked just fine!
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: tgt on arm64 and USE_SIGNALFD
2024-02-15 13:39 ` Andreas Hasenack
@ 2024-02-16 10:01 ` FUJITA Tomonori
0 siblings, 0 replies; 4+ messages in thread
From: FUJITA Tomonori @ 2024-02-16 10:01 UTC (permalink / raw)
To: andreas; +Cc: fujita.tomonori, stgt, sergio.durigan
On Thu, 15 Feb 2024 10:39:43 -0300
Andreas Hasenack <andreas@canonical.com> wrote:
> Hello,
>
> On Wed, Feb 14, 2024 at 9:26 PM FUJITA Tomonori
> <fujita.tomonori@gmail.com> wrote:
>>
>> Hi,
>>
>> On Wed, 14 Feb 2024 17:14:42 -0300
>> Andreas Hasenack <andreas@canonical.com> wrote:
>>
>> > is USE_SIGNALFD meant to be supported on arm64? The check in
>> > bs/util.h[1] is looking for __NR_signalfd, but arm64 only has the
>> > newer __NR_signalfd4[2]:
>> >
>> > #if defined(__NR_signalfd) && defined(USE_SIGNALFD)
>> > ...
>> > #else
>> > #define __signalfd(fd, mask, flags) (-1)
>> > struct signalfd_siginfo {
>> > };
>> > #endif
>>
>> I think that we don't need this hack anymore (it was necessary when
>> the signalfd feature was introduced). I've not tested on arm64 but
>> I guess that simply using sys/signalfd.h works like the following?
>
> Yes, thank you, that worked just fine!
Thanks!
I've added O_NONBLOCK flag and merged the following:
-
From: FUJITA Tomonori <fujita.tomonori@gmail.com>
Date: Fri, 16 Feb 2024 09:35:38 +0900
Subject: [PATCH] fix arm64 compile breakage
This removes the hack for signalfd, which uses __NR_signalfd to check
whether a system supports signalfd or not. arm64 uses _NR_signalfd4 so
tgt wrongly assumes that arm64 doesn't support signalfd.
This hack was introduced when some distributions doesn't have a header
file for signalfd. Now all the distributions should have so we can
simply use sys/signalfd.h
Reported-by: Andreas Hasenack <andreas@canonical.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
---
usr/bs.c | 2 +-
usr/util.h | 43 +++----------------------------------------
2 files changed, 4 insertions(+), 41 deletions(-)
diff --git a/usr/bs.c b/usr/bs.c
index 8171a32..21547d5 100644
--- a/usr/bs.c
+++ b/usr/bs.c
@@ -311,7 +311,7 @@ static int bs_init_signalfd(void)
sigaddset(&mask, SIGUSR2);
sigprocmask(SIG_BLOCK, &mask, NULL);
- sig_fd = __signalfd(-1, &mask, 0);
+ sig_fd = signalfd(-1, &mask, O_NONBLOCK);
if (sig_fd < 0)
return 1;
diff --git a/usr/util.h b/usr/util.h
index c709f9b..8aef6ab 100644
--- a/usr/util.h
+++ b/usr/util.h
@@ -14,11 +14,12 @@
#include <stdlib.h>
#include <string.h>
#include <limits.h>
+#include <linux/fs.h>
#include <linux/types.h>
#include <sys/ioctl.h>
-#include <linux/fs.h>
-#include <sys/types.h>
+#include <sys/signalfd.h>
#include <sys/stat.h>
+#include <sys/types.h>
#include "be_byteshift.h"
@@ -103,44 +104,6 @@ static inline int between(uint32_t seq1, uint32_t seq2, uint32_t seq3)
extern unsigned long pagesize, pageshift;
-#if defined(__NR_signalfd) && defined(USE_SIGNALFD)
-
-/*
- * workaround for broken linux/signalfd.h including
- * usr/include/linux/fcntl.h
- */
-#define _LINUX_FCNTL_H
-
-#include <linux/signalfd.h>
-
-static inline int __signalfd(int fd, const sigset_t *mask, int flags)
-{
- int fd2, ret;
-
- fd2 = syscall(__NR_signalfd, fd, mask, _NSIG / 8);
- if (fd2 < 0)
- return fd2;
-
- ret = fcntl(fd2, F_GETFL);
- if (ret < 0) {
- close(fd2);
- return -1;
- }
-
- ret = fcntl(fd2, F_SETFL, ret | O_NONBLOCK);
- if (ret < 0) {
- close(fd2);
- return -1;
- }
-
- return fd2;
-}
-#else
-#define __signalfd(fd, mask, flags) (-1)
-struct signalfd_siginfo {
-};
-#endif
-
/* convert string to integer, check for validity of the string numeric format
* and the natural boundaries of the integer value type (first get a 64-bit
* value and check that it fits the range of the destination integer).
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-02-16 10:01 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-14 20:14 tgt on arm64 and USE_SIGNALFD Andreas Hasenack
2024-02-15 0:26 ` FUJITA Tomonori
2024-02-15 13:39 ` Andreas Hasenack
2024-02-16 10:01 ` FUJITA Tomonori
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).