Skip to contentSkip to conversation

linux-user: fix __NR_semtimedop undeclared error

PATCH Applied Laurent Vivier 5 participants 8 messages May 23, 2019 – May 28, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux-user: fix __NR_semtimedop undeclared error

In current code, __NR_msgrcv and__NR_semtimedop are supposed to be defined if __NR_msgsnd is defined.

But linux headers 5.2-rc1 for MIPS define __NR_msgsnd without defining __NR_semtimedop and it breaks the QEMU build.

__NR_semtimedop is defined in asm-mips/unistd_n64.h and asm-mips/unistd_n32.h but not in asm-mips/unistd_o32.h.

Commit d9cb4336159a ("linux headers: update against Linux 5.2-rc1") has updated asm-mips/unistd_o32.h and added __NR_msgsnd but not __NR_semtimedop. It introduces __NR_semtimedop_time64 instead.

This patch fixes the problem by checking for each __NR_XXX symbol before defining the corresponding syscall.

Fixes d9cb4336159a ("linux headers: update against Linux 5.2-rc1")
---
 linux-user/syscall.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)
linux-user/syscall.c +16 -8
index e311fcda0517..d316de25c9f2 100644
@@ -761,14 +761,7 @@ safe_syscall2(int, nanosleep, const struct timespec *, req,
 safe_syscall4(int, clock_nanosleep, const clockid_t, clock, int, flags,
               const struct timespec *, req, struct timespec *, rem)
 #endif
-#ifdef __NR_msgsnd
-safe_syscall4(int, msgsnd, int, msgid, const void *, msgp, size_t, sz,
-              int, flags)
-safe_syscall5(int, msgrcv, int, msgid, void *, msgp, size_t, sz,
-              long, msgtype, int, flags)
-safe_syscall4(int, semtimedop, int, semid, struct sembuf *, tsops,
-              unsigned, nsops, const struct timespec *, timeout)
-#else
+#if !defined(__NR_msgsnd) || !defined(__NR_msgrcv) || !defined(__NR_semtimedop)
 /* This host kernel architecture uses a single ipc syscall; fake up
  * wrappers for the sub-operations to hide this implementation detail.
  * Annoyingly we can't include linux/ipc.h to get the constant definitions
@@ -783,14 +776,29 @@ safe_syscall4(int, semtimedop, int, semid, struct sembuf *, tsops,
 
 safe_syscall6(int, ipc, int, call, long, first, long, second, long, third,
               void *, ptr, long, fifth)
+#endif
+#ifdef __NR_msgsnd
+safe_syscall4(int, msgsnd, int, msgid, const void *, msgp, size_t, sz,
+              int, flags)
+#else
 static int safe_msgsnd(int msgid, const void *msgp, size_t sz, int flags)
 {
     return safe_ipc(Q_IPCCALL(0, Q_MSGSND), msgid, sz, flags, (void *)msgp, 0);
 }
+#endif
+#ifdef __NR_msgrcv
+safe_syscall5(int, msgrcv, int, msgid, void *, msgp, size_t, sz,
+              long, msgtype, int, flags)
+#else
 static int safe_msgrcv(int msgid, void *msgp, size_t sz, long type, int flags)
 {
     return safe_ipc(Q_IPCCALL(1, Q_MSGRCV), msgid, sz, flags, msgp, type);
 }
+#endif
+#ifdef __NR_semtimedop
+safe_syscall4(int, semtimedop, int, semid, struct sembuf *, tsops,
+              unsigned, nsops, const struct timespec *, timeout)
+#else
 static int safe_semtimedop(int semid, struct sembuf *tsops, unsigned nsops,
                            const struct timespec *timeout)
 {
Signature · 1 line
2.20.1
Tested-by on v1 1/1
#1 lore raw
Quoted 9 lines · Laurent Vivier

In current code, __NR_msgrcv and__NR_semtimedop are supposed to be defined if __NR_msgsnd is defined.

But linux headers 5.2-rc1 for MIPS define __NR_msgsnd without defining __NR_semtimedop and it breaks the QEMU build.

__NR_semtimedop is defined in asm-mips/unistd_n64.h and asm-mips/unistd_n32.h but not in asm-mips/unistd_o32.h.

Quoted 6 lines

Commit d9cb4336159a ("linux headers: update against Linux 5.2-rc1") has updated asm-mips/unistd_o32.h and added __NR_msgsnd but not __NR_semtimedop. It introduces __NR_semtimedop_time64 instead.

This patch fixes the problem by checking for each __NR_XXX symbol before defining the corresponding syscall.

Thanks for the quick fix Laurent.

Quoted 4 lines
Fixes d9cb4336159a ("linux headers: update against Linux 5.2-rc1")
Quoted 55 lines
---
 linux-user/syscall.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)
linux-user/syscall.c +16 -8
index e311fcda0517..d316de25c9f2 100644
@@ -761,14 +761,7 @@ safe_syscall2(int, nanosleep, const struct timespec *, req,
 safe_syscall4(int, clock_nanosleep, const clockid_t, clock, int, flags,
               const struct timespec *, req, struct timespec *, rem)
 #endif
-#ifdef __NR_msgsnd
-safe_syscall4(int, msgsnd, int, msgid, const void *, msgp, size_t, sz,
-              int, flags)
-safe_syscall5(int, msgrcv, int, msgid, void *, msgp, size_t, sz,
-              long, msgtype, int, flags)
-safe_syscall4(int, semtimedop, int, semid, struct sembuf *, tsops,
-              unsigned, nsops, const struct timespec *, timeout)
-#else
+#if !defined(__NR_msgsnd) || !defined(__NR_msgrcv) || !defined(__NR_semtimedop)
 /* This host kernel architecture uses a single ipc syscall; fake up
  * wrappers for the sub-operations to hide this implementation detail.
  * Annoyingly we can't include linux/ipc.h to get the constant definitions
@@ -783,14 +776,29 @@ safe_syscall4(int, semtimedop, int, semid, struct sembuf *, tsops,
 
 safe_syscall6(int, ipc, int, call, long, first, long, second, long, third,
               void *, ptr, long, fifth)
+#endif
+#ifdef __NR_msgsnd
+safe_syscall4(int, msgsnd, int, msgid, const void *, msgp, size_t, sz,
+              int, flags)
+#else
 static int safe_msgsnd(int msgid, const void *msgp, size_t sz, int flags)
 {
     return safe_ipc(Q_IPCCALL(0, Q_MSGSND), msgid, sz, flags, (void *)msgp, 0);
 }
+#endif
+#ifdef __NR_msgrcv
+safe_syscall5(int, msgrcv, int, msgid, void *, msgp, size_t, sz,
+              long, msgtype, int, flags)
+#else
 static int safe_msgrcv(int msgid, void *msgp, size_t sz, long type, int flags)
 {
     return safe_ipc(Q_IPCCALL(1, Q_MSGRCV), msgid, sz, flags, msgp, type);
 }
+#endif
+#ifdef __NR_semtimedop
+safe_syscall4(int, semtimedop, int, semid, struct sembuf *, tsops,
+              unsigned, nsops, const struct timespec *, timeout)
+#else
 static int safe_semtimedop(int semid, struct sembuf *tsops, unsigned nsops,
                            const struct timespec *timeout)
 {
#2 lore raw
Quoted 17 lines · Philippe Mathieu-Daudé
Quoted 9 lines · Laurent Vivier

In current code, __NR_msgrcv and__NR_semtimedop are supposed to be defined if __NR_msgsnd is defined.

But linux headers 5.2-rc1 for MIPS define __NR_msgsnd without defining __NR_semtimedop and it breaks the QEMU build.

__NR_semtimedop is defined in asm-mips/unistd_n64.h and asm-mips/unistd_n32.h but not in asm-mips/unistd_o32.h.

Quoted 6 lines

Commit d9cb4336159a ("linux headers: update against Linux 5.2-rc1") has updated asm-mips/unistd_o32.h and added __NR_msgsnd but not __NR_semtimedop. It introduces __NR_semtimedop_time64 instead.

This patch fixes the problem by checking for each __NR_XXX symbol before defining the corresponding syscall.

Quoted 8 lines

Thanks for the quick fix Laurent.

Quoted 4 lines
Fixes d9cb4336159a ("linux headers: update against Linux 5.2-rc1")

Aleksandar, you have a pull request in preparation, if you agree with this patch you might want to include it ;)

Regards,

Phil.

Reviewed-by on v1 1/1
#3 lore raw
In reply to Laurent Vivier
Quoted 6 lines · On Thu, 23 May 2019 19:54:13 +0200 Laurent Vivier <[email protected]> wrote:

In current code, __NR_msgrcv and__NR_semtimedop are supposed to be defined if __NR_msgsnd is defined.

But linux headers 5.2-rc1 for MIPS define __NR_msgsnd without defining __NR_semtimedop and it breaks the QEMU build.

Quoted 6 lines

__NR_semtimedop is defined in asm-mips/unistd_n64.h and asm-mips/unistd_n32.h but not in asm-mips/unistd_o32.h.

Commit d9cb4336159a ("linux headers: update against Linux 5.2-rc1") has updated asm-mips/unistd_o32.h and added __NR_msgsnd but not __NR_semtimedop. It introduces __NR_semtimedop_time64 instead.

Thanks for looking into this! I still wonder whether something's b0rken in the kernel, though. But that needs to be followed up by the mips folks.

Quoted 3 lines

This patch fixes the problem by checking for each __NR_XXX symbol before defining the corresponding syscall.

This looks safe in any case.

Quoted 7 lines
Fixes d9cb4336159a ("linux headers: update against Linux 5.2-rc1")
---
 linux-user/syscall.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)
Reviewed-by Tested-by on v1 1/1
#4 lore raw
In reply to Laurent Vivier
Quoted 13 lines · Laurent Vivier

In current code, __NR_msgrcv and__NR_semtimedop are supposed to be defined if __NR_msgsnd is defined.

But linux headers 5.2-rc1 for MIPS define __NR_msgsnd without defining __NR_semtimedop and it breaks the QEMU build.

__NR_semtimedop is defined in asm-mips/unistd_n64.h and asm-mips/unistd_n32.h but not in asm-mips/unistd_o32.h.

Commit d9cb4336159a ("linux headers: update against Linux 5.2-rc1") has updated asm-mips/unistd_o32.h and added __NR_msgsnd but not __NR_semtimedop. It introduces __NR_semtimedop_time64 instead.

Quoted 6 lines

This patch fixes the problem by checking for each __NR_XXX symbol before defining the corresponding syscall.

Fixes d9cb4336159a ("linux headers: update against Linux 5.2-rc1")
Quoted 44 lines
---
 linux-user/syscall.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)
linux-user/syscall.c +11 -8
index e311fcda0517..d316de25c9f2 100644
@@ -761,14 +761,7 @@ safe_syscall2(int, nanosleep, const struct timespec *, req,
 safe_syscall4(int, clock_nanosleep, const clockid_t, clock, int, flags,
               const struct timespec *, req, struct timespec *, rem)
 #endif
-#ifdef __NR_msgsnd
-safe_syscall4(int, msgsnd, int, msgid, const void *, msgp, size_t, sz,
-              int, flags)
-safe_syscall5(int, msgrcv, int, msgid, void *, msgp, size_t, sz,
-              long, msgtype, int, flags)
-safe_syscall4(int, semtimedop, int, semid, struct sembuf *, tsops,
-              unsigned, nsops, const struct timespec *, timeout)
-#else
+#if !defined(__NR_msgsnd) || !defined(__NR_msgrcv) || !defined(__NR_semtimedop)
 /* This host kernel architecture uses a single ipc syscall; fake up
  * wrappers for the sub-operations to hide this implementation detail.
  * Annoyingly we can't include linux/ipc.h to get the constant definitions
@@ -783,14 +776,29 @@ safe_syscall4(int, semtimedop, int, semid, struct sembuf *, tsops,
 
 safe_syscall6(int, ipc, int, call, long, first, long, second, long, third,
               void *, ptr, long, fifth)
+#endif
+#ifdef __NR_msgsnd
+safe_syscall4(int, msgsnd, int, msgid, const void *, msgp, size_t, sz,
+              int, flags)
+#else
 static int safe_msgsnd(int msgid, const void *msgp, size_t sz, int flags)
 {
     return safe_ipc(Q_IPCCALL(0, Q_MSGSND), msgid, sz, flags, (void *)msgp, 0);
 }
+#endif
+#ifdef __NR_msgrcv
+safe_syscall5(int, msgrcv, int, msgid, void *, msgp, size_t, sz,
+              long, msgtype, int, flags)
+#else
 static int safe_msgrcv(int msgid, void *msgp, size_t sz, long type, int flags)
 {

linux-user/syscall.c safe_syscall4(int, semtimedop, int, semid, struct sembuf *, tsops, · line 804

Quoted 10 lines
linux-user/syscall.c +5 -0
     return safe_ipc(Q_IPCCALL(1, Q_MSGRCV), msgid, sz, flags, msgp, type);
 }
+#endif
+#ifdef __NR_semtimedop
+safe_syscall4(int, semtimedop, int, semid, struct sembuf *, tsops,
+              unsigned, nsops, const struct timespec *, timeout)
+#else
 static int safe_semtimedop(int semid, struct sembuf *tsops, unsigned nsops,
                            const struct timespec *timeout)
 {

--
Alex Bennée

#5 lore raw
Quoted 11 lines · Alex Bennée
Quoted 7 lines · Laurent Vivier

In current code, __NR_msgrcv and__NR_semtimedop are supposed to be defined if __NR_msgsnd is defined.

But linux headers 5.2-rc1 for MIPS define __NR_msgsnd without defining __NR_semtimedop and it breaks the QEMU build.

__NR_semtimedop is defined in asm-mips/unistd_n64.h and

asm-mips/unistd_n32.h

Quoted 4 lines
Quoted 4 lines

but not in asm-mips/unistd_o32.h.

Commit d9cb4336159a ("linux headers: update against Linux 5.2-rc1") has updated asm-mips/unistd_o32.h and added __NR_msgsnd but not

__NR_semtimedop.

Quoted 5 lines
Quoted 5 lines

It introduces __NR_semtimedop_time64 instead.

This patch fixes the problem by checking for each __NR_XXX symbol before defining the corresponding syscall.

Quoted 7 lines
Quoted 3 lines
Fixes d9cb4336159a ("linux headers: update against Linux 5.2-rc1")

This patch was applied to mips queue, sent today.

Regards,
Aleksandar

Quoted 9 lines

linux-user/syscall.c safe_syscall2(int, nanosleep, const struct

Quoted 9 lines
---
 linux-user/syscall.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)
linux-user/syscall.c +0 -0
index e311fcda0517..d316de25c9f2 100644
@@ -761,14 +761,7 @@ safe_syscall2(int, nanosleep, const struct

timespec *, req,

Quoted 4 lines
Quoted 4 lines
linux-user/syscall.c +0 -1
 safe_syscall4(int, clock_nanosleep, const clockid_t, clock, int, flags,
               const struct timespec *, req, struct timespec *, rem)
 #endif
-#ifdef __NR_msgsnd
Quoted 8 lines

linux-user/syscall.c safe_syscall2(int, nanosleep, const struct timespec *, req,

Quoted 8 lines
linux-user/syscall.c +1 -7
-safe_syscall4(int, msgsnd, int, msgid, const void *, msgp, size_t, sz,
-              int, flags)
-safe_syscall5(int, msgrcv, int, msgid, void *, msgp, size_t, sz,
-              long, msgtype, int, flags)
-safe_syscall4(int, semtimedop, int, semid, struct sembuf *, tsops,
-              unsigned, nsops, const struct timespec *, timeout)
-#else
+#if !defined(__NR_msgsnd) || !defined(__NR_msgrcv) ||

!defined(__NR_semtimedop)

Quoted 3 lines

linux-user/syscall.c safe_syscall2(int, nanosleep, const struct timespec *, req,

Quoted 3 lines
linux-user/syscall.c +0 -0
 /* This host kernel architecture uses a single ipc syscall; fake up
  * wrappers for the sub-operations to hide this implementation detail.
  * Annoyingly we can't include linux/ipc.h to get the constant

definitions

Quoted 1 line

linux-user/syscall.c safe_syscall4(int, semtimedop, int, semid, struct

Quoted 1 line
linux-user/syscall.c +0 -0
@@ -783,14 +776,29 @@ safe_syscall4(int, semtimedop, int, semid, struct

sembuf *, tsops,

Quoted 2 lines

linux-user/syscall.c safe_syscall4(int, semtimedop, int, semid, struct · line 776

Quoted 2 lines
linux-user/syscall.c +0 -0
 safe_syscall6(int, ipc, int, call, long, first, long, second, long,

third,

Quoted 7 lines

linux-user/syscall.c safe_syscall4(int, semtimedop, int, semid, struct sembuf *, tsops,

Quoted 7 lines
linux-user/syscall.c +5 -0
               void *, ptr, long, fifth)
+#endif
+#ifdef __NR_msgsnd
+safe_syscall4(int, msgsnd, int, msgid, const void *, msgp, size_t, sz,
+              int, flags)
+#else
 static int safe_msgsnd(int msgid, const void *msgp, size_t sz, int

flags)

Quoted 2 lines

linux-user/syscall.c safe_syscall4(int, semtimedop, int, semid, struct · line 785

Quoted 2 lines
linux-user/syscall.c +0 -0
 {
     return safe_ipc(Q_IPCCALL(0, Q_MSGSND), msgid, sz, flags, (void

*)msgp, 0);

Quoted 7 lines

linux-user/syscall.c safe_syscall4(int, semtimedop, int, semid, struct sembuf *, tsops,

Quoted 7 lines
linux-user/syscall.c +5 -0
 }
+#endif
+#ifdef __NR_msgrcv
+safe_syscall5(int, msgrcv, int, msgid, void *, msgp, size_t, sz,
+              long, msgtype, int, flags)
+#else
 static int safe_msgrcv(int msgid, void *msgp, size_t sz, long type,

int flags)

Quoted 2 lines

linux-user/syscall.c safe_syscall4(int, semtimedop, int, semid, struct · line 794

Quoted 2 lines
linux-user/syscall.c +0 -0
 {
     return safe_ipc(Q_IPCCALL(1, Q_MSGRCV), msgid, sz, flags, msgp,

type);

Quoted 7 lines

linux-user/syscall.c safe_syscall4(int, semtimedop, int, semid, struct sembuf *, tsops,

Quoted 7 lines
linux-user/syscall.c +5 -0
 }
+#endif
+#ifdef __NR_semtimedop
+safe_syscall4(int, semtimedop, int, semid, struct sembuf *, tsops,
+              unsigned, nsops, const struct timespec *, timeout)
+#else
 static int safe_semtimedop(int semid, struct sembuf *tsops, unsigned

nsops,

Quoted 6 lines

linux-user/syscall.c safe_syscall4(int, semtimedop, int, semid, struct sembuf *, tsops, · line 804

Quoted 2 lines
linux-user/syscall.c +0 -0
                            const struct timespec *timeout)
 {

--
Alex Bennée

#6 lore raw
In reply to Laurent Vivier
Quoted 16 lines · Laurent Vivier

In current code, __NR_msgrcv and__NR_semtimedop are supposed to be defined if __NR_msgsnd is defined.

But linux headers 5.2-rc1 for MIPS define __NR_msgsnd without defining __NR_semtimedop and it breaks the QEMU build.

__NR_semtimedop is defined in asm-mips/unistd_n64.h and asm-mips/unistd_n32.h but not in asm-mips/unistd_o32.h.

Commit d9cb4336159a ("linux headers: update against Linux 5.2-rc1") has updated asm-mips/unistd_o32.h and added __NR_msgsnd but not __NR_semtimedop. It introduces __NR_semtimedop_time64 instead.

This patch fixes the problem by checking for each __NR_XXX symbol before defining the corresponding syscall.

Quoted 6 lines
Fixes d9cb4336159a ("linux headers: update against Linux 5.2-rc1")
---
  linux-user/syscall.c | 24 ++++++++++++++++--------
  1 file changed, 16 insertions(+), 8 deletions(-)

This only fixes the problem at build time, but the changes in the kernel headers introduce also a regression at execution time:

if the host kernel doesn't implement the syscall, the syscall fails (ENOSYS) whereas it was working before because it was using ipc() instead. I have this problem with a Fedora 28 on ppc64 (5.0.16-100.fc28.ppc64) (LTP test msgctl07).

I'm preparing a fix.

Thanks,
Laurent

#7 lore raw
Quoted 10 lines · Laurent Vivier
Quoted 8 lines · Laurent Vivier

In current code, __NR_msgrcv and__NR_semtimedop are supposed to be defined if __NR_msgsnd is defined.

But linux headers 5.2-rc1 for MIPS define __NR_msgsnd without defining __NR_semtimedop and it breaks the QEMU build.

__NR_semtimedop is defined in asm-mips/unistd_n64.h and

asm-mips/unistd_n32.h

Quoted 4 lines
Quoted 4 lines

but not in asm-mips/unistd_o32.h.

Commit d9cb4336159a ("linux headers: update against Linux 5.2-rc1") has updated asm-mips/unistd_o32.h and added __NR_msgsnd but not

__NR_semtimedop.

Quoted 13 lines
Quoted 11 lines

It introduces __NR_semtimedop_time64 instead.

This patch fixes the problem by checking for each __NR_XXX symbol before defining the corresponding syscall.

Fixes d9cb4336159a ("linux headers: update against Linux 5.2-rc1")
---
  linux-user/syscall.c | 24 ++++++++++++++++--------
  1 file changed, 16 insertions(+), 8 deletions(-)
Quoted 1 line

This only fixes the problem at build time, but the changes in the kernel

headers introduce also a regression at execution time:

Quoted 2 lines

if the host kernel doesn't implement the syscall, the syscall fails

(ENOSYS) whereas it was working before because it was using ipc() instead. I have this problem with a Fedora 28 on ppc64 (5.0.16-100.fc28.ppc64) (LTP test msgctl07).

Quoted 3 lines

I'm preparing a fix.

OK, great that you found this behavior, thanks. Just want to tell you that meanwhile the original code of this patch got integrated into main source tree.

Regards,
Aleksandar

Quoted 2 lines

Thanks,
Laurent