Skip to contentSkip to conversation

linux-user: Fix assorted Qemu user mode issues

PATCH Superseded Aleksandar Markovic 3 participants 7 messages Oct 10, 2016

v8 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v8 cover linux-user: Fix assorted Qemu user mode issues

From: Aleksandar Markovic <[email protected]>

v7->v8:

- patches for clock_adjtime() and syncfs() fixed so that certain older system can detect absence of support for these system calls and exclude appropriate code segments from building
- implemented better error condition handling for clock_adjtime()
- added strace support for syncfs()
- improved commit messages

NOTE: v8 contains only these two patches, since it was noticed that older
systems may have build problems with such support; other patches are fine in that sense. Also, these two patches in v8 assume that patch 1 from v7 (adjtimex() support) is already applied.

v6->v7:

- rebased to the latest code (there was a large linux-user change since v6, consisting of 26 patches)
- slightly changed order of patches
- changed PATH_MAX to 128 in sysfs() patch (last remaining item that was supposed to be in the previous version)

v5->v6:

- rebased to the latest code
- reworked all patches according to review feedback
- added two new patches on syncfs() and mq_open()
- some improvements in commit messages

v4->v5:

- removed three cleanup patches

v3->v4:

- rebased to the latest code
- added patch on clock_adjtime() support
- minor commit messages improvements

v2->v3:

- rebased to the latest code
- merged patches on adjtimex(), sysfs(), and ustat() from another series
- added patch on socketcall() support
- cleanup patches reorganized

v1->v2:

- improved usage of "#ifdefs" in patch on syslog()
- removed EIDRM-related code from patch on msgrcv(), since this error code is already handled well
- added three cleanup patches

(v1 for some reason did not appear on qemu-devel, but mails are sent)

This series fixes certain Qemu user mode issues. The fixes mainly originate from observation of LTP tests failures for execution in Qemu user mode on various platforms.

Aleksandar Markovic (2):
linux-user: Add support for clock_adjtime() syscall
linux-user: Add support for syncfs() syscall

 configure              | 36 ++++++++++++++++++++++++
 linux-user/strace.c    | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++
 linux-user/strace.list |  5 +++-
 linux-user/syscall.c   | 30 ++++++++++++++++++++
 4 files changed, 146 insertions(+), 1 deletion(-)
Signature · 1 line
2.9.3
#1 lore raw

PATCH v8 1/2 linux-user: Add support for clock_adjtime() syscall

From: Aleksandar Markovic <[email protected]>

This patch implements Qemu user mode clock_adjtime() syscall support.

The implementation is based on invocation of host's clock_adjtime(). There are fairly complex rules regarding conditions for each error code that could be returned by clock_adjtime(). They are all taken into account while conversions of pointers to timex structure between target and host are done. By passing NULL as the second argument in certain cases, it is assured that the emulated clock_adjtime() will return the correct error code for all cases of its input.

---
 configure              | 18 ++++++++++++
 linux-user/strace.c    | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++
 linux-user/strace.list |  3 ++
 linux-user/syscall.c   | 25 +++++++++++++++++
 4 files changed, 122 insertions(+)
configure +18 -0
index 5751d8e..044e0cd 100755
@@ -3898,6 +3898,21 @@ if compile_prog "" "" ; then
   setns=yes
 fi
 
+# clock_adjtime probe
+clock_adjtime=no
+cat > $TMPC <<EOF
+#include <time.h>
+
+int main(void)
+{
+    return clock_adjtime(0, 0);
+}
+EOF
+clock_adjtime=no
+if compile_prog "" "" ; then
+  clock_adjtime=yes
+fi
+
 # Check if tools are available to build documentation.
 if test "$docs" != "no" ; then
   if has makeinfo && has pod2man; then
@@ -5183,6 +5198,9 @@ fi
 if test "$setns" = "yes" ; then
   echo "CONFIG_SETNS=y" >> $config_host_mak
 fi
+if test "$clock_adjtime" = "yes" ; then
+  echo "CONFIG_CLOCK_ADJTIME=y" >> $config_host_mak
+fi
 if test "$inotify" = "yes" ; then
   echo "CONFIG_INOTIFY=y" >> $config_host_mak
 fi
linux-user/strace.c +76 -0

88 lines not on this page · raw message

linux-user/strace.list +3 -0
index f6dd044..9355075 100644
@@ -79,6 +79,9 @@
 #ifdef TARGET_NR_chroot
 { TARGET_NR_chroot, "chroot" , NULL, NULL, NULL },
 #endif
+#ifdef TARGET_NR_clock_adjtime
+{ TARGET_NR_clock_adjtime, "clock_adjtime" , NULL, print_clock_adjtime, NULL },
+#endif
 #ifdef TARGET_NR_clock_getres
 { TARGET_NR_clock_getres, "clock_getres" , NULL, NULL, NULL },
 #endif
linux-user/syscall.c +25 -0
index 35363cc..25be16b 100644
@@ -48,6 +48,7 @@ int __clone2(int (*fn)(void *), void *child_stack_base,
 #include <sys/shm.h>
 #include <sys/sem.h>
 #include <sys/statfs.h>
+#include <time.h>
 #include <utime.h>
 #include <sys/sysinfo.h>
 #include <sys/signalfd.h>
@@ -9624,6 +9625,30 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
             }
         }
         break;
+#if defined(TARGET_NR_clock_adjtime) && defined(CONFIG_CLOCK_ADJTIME)
+    case TARGET_NR_clock_adjtime:
+        {
+            struct timex htx, *phtx = &htx;
+
+            if (target_to_host_timex(phtx, arg2) != 0) {
+                /*
+                 * rather than returning -EFAULT, we here pass NULL as the
+                 * second argument of host's clock_adjtime, in order to let
+                 * the logic inside the kernel decide whether the returned
+                 * error code should be EFAULT, or perhaps, under some
+                 * circumstances related to arg1, EINVAL or EOPNOTSUPP
+                 */
+                phtx = NULL;
+            }
+            ret = get_errno(clock_adjtime(arg1, phtx));
+            if (!is_error(ret) && phtx) {
+                if (host_to_target_timex(arg2, phtx) != 0) {
+                    goto efault;
+                }
+            }
+        }
+        break;
+#endif
 #ifdef TARGET_NR_create_module
     case TARGET_NR_create_module:
 #endif
Signature · 1 line
2.9.3
#2 lore raw

Re: [Qemu-devel] [PATCH v8 1/2] linux-user: Add support for clock_adjtime() syscall

Quoted 11 lines · Aleksandar Markovic

From: Aleksandar Markovic <[email protected]>

This patch implements Qemu user mode clock_adjtime() syscall support.

The implementation is based on invocation of host's clock_adjtime(). There are fairly complex rules regarding conditions for each error code that could be returned by clock_adjtime(). They are all taken into account while conversions of pointers to timex structure between target and host are done. By passing NULL as the second argument in certain cases, it is assured that the emulated clock_adjtime() will return the correct error code for all cases of its input.

Is this ordering of which error conditions are checked first actually mandated by the clock_adjtime() documentation, or is this just placating an LTP test case that does two wrong things at once when it's really only trying to test one of them? If the latter, I think it's better to fix the broken LTP test case. (For instance
https://github.com/linux-test-project/ltp/commit/3d4b0e9aa524fc6418d34614299ac2df1e8045ae
is a fix for an issue like that in handling the read syscall.)

thanks
-- PMM

#3 lore raw

Re: [Qemu-devel] [PATCH v8 1/2] linux-user: Add support for clock_adjtime() syscall

Hi,

Thanks for bringing up this issue. LTP was not the reference for this implementation. Man page does not exist. The reference was kernel source. Apart from source code analysis. test examples were utilized to confirm the same behavior on real and emulated systems.

Yours,
Aleksandar

________________________________________
From: Peter Maydell [[email protected]]
Sent: Monday, October 10, 2016 3:25 AM
To: Aleksandar Markovic
Cc: QEMU Developers; Riku Voipio; Laurent Vivier; Petar Jovanovic; Miodrag Dinic; Aleksandar Rikalo; Aleksandar Markovic
Subject: Re: [PATCH v8 1/2] linux-user: Add support for clock_adjtime() syscall

Quoted 11 lines · Aleksandar Markovic

From: Aleksandar Markovic <[email protected]>

This patch implements Qemu user mode clock_adjtime() syscall support.

The implementation is based on invocation of host's clock_adjtime(). There are fairly complex rules regarding conditions for each error code that could be returned by clock_adjtime(). They are all taken into account while conversions of pointers to timex structure between target and host are done. By passing NULL as the second argument in certain cases, it is assured that the emulated clock_adjtime() will return the correct error code for all cases of its input.

Is this ordering of which error conditions are checked first actually mandated by the clock_adjtime() documentation, or is this just placating an LTP test case that does two wrong things at once when it's really only trying to test one of them? If the latter, I think it's better to fix the broken LTP test case. (For instance
https://github.com/linux-test-project/ltp/commit/3d4b0e9aa524fc6418d34614299ac2df1e8045ae
is a fix for an issue like that in handling the read syscall.)

thanks
-- PMM

#4 lore raw

Re: [Qemu-devel] [PATCH v8 1/2] linux-user: Add support for clock_adjtime() syscall

Quoted 4 lines · Aleksandar Markovic

Thanks for bringing up this issue. LTP was not the reference for this implementation. Man page does not exist. The reference was kernel source. Apart from source code analysis. test examples were utilized to confirm the same behavior on real and emulated systems.

If no real world code or even LTP test code is relying on the order in which error conditions are checked for, and the API is not documented to make that kind of distinction, then I think we should implement this the same way we do all other syscalls, ie just check for EFAULT first.

thanks
-- PMM

#5 lore raw

Re: [Qemu-devel] [PATCH v8 1/2] linux-user: Add support for clock_adjtime() syscall

Sure, I am going to send a new and corrected version of the series in short time.

Thanks,
Aleksandar
________________________________________
From: Peter Maydell [[email protected]]
Sent: Monday, October 10, 2016 3:35 AM
To: Aleksandar Markovic
Cc: Aleksandar Markovic; QEMU Developers; Riku Voipio; Laurent Vivier; Petar Jovanovic; Miodrag Dinic; Aleksandar Rikalo
Subject: Re: [PATCH v8 1/2] linux-user: Add support for clock_adjtime() syscall

Quoted 4 lines · Aleksandar Markovic

Thanks for bringing up this issue. LTP was not the reference for this implementation. Man page does not exist. The reference was kernel source. Apart from source code analysis. test examples were utilized to confirm the same behavior on real and emulated systems.

If no real world code or even LTP test code is relying on the order in which error conditions are checked for, and the API is not documented to make that kind of distinction, then I think we should implement this the same way we do all other syscalls, ie just check for EFAULT first.

thanks
-- PMM

#6 lore raw

PATCH v8 2/2 linux-user: Add support for syncfs() syscall

In reply to Aleksandar Markovic

From: Aleksandar Markovic <[email protected]>

This patch implements Qemu user mode syncfs() syscall support. Syscall syncfs() syncs the filesystem containing file determined by the open file descriptor passed as the argument to syncfs().

The implementation consists of a straightforward invocation of host's syncfs(). Configure and strace support is included as well.

---
 configure              | 18 ++++++++++++++++++
 linux-user/strace.list |  2 +-
 linux-user/syscall.c   |  5 +++++
 3 files changed, 24 insertions(+), 1 deletion(-)
configure +18 -0
index 044e0cd..7b9984b 100755
@@ -3913,6 +3913,21 @@ if compile_prog "" "" ; then
   clock_adjtime=yes
 fi
 
+# syncfs probe
+syncfs=no
+cat > $TMPC <<EOF
+#include <unistd.h>
+
+int main(void)
+{
+    return syncfs(0);
+}
+EOF
+syncfs=no
+if compile_prog "" "" ; then
+  syncfs=yes
+fi
+
 # Check if tools are available to build documentation.
 if test "$docs" != "no" ; then
   if has makeinfo && has pod2man; then
@@ -5201,6 +5216,9 @@ fi
 if test "$clock_adjtime" = "yes" ; then
   echo "CONFIG_CLOCK_ADJTIME=y" >> $config_host_mak
 fi
+if test "$syncfs" = "yes" ; then
+  echo "CONFIG_SYNCFS=y" >> $config_host_mak
+fi
 if test "$inotify" = "yes" ; then
   echo "CONFIG_INOTIFY=y" >> $config_host_mak
 fi
linux-user/strace.list +1 -1
index 9355075..c549f99 100644
@@ -1462,7 +1462,7 @@
 { TARGET_NR_sync_file_range, "sync_file_range" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_syncfs
-{ TARGET_NR_syncfs, "syncfs" , NULL, NULL, NULL },
+{ TARGET_NR_syncfs, "syncfs" , "%s(%d)", NULL, NULL },
 #endif
 #ifdef TARGET_NR_syscall
 { TARGET_NR_syscall, "syscall" , NULL, NULL, NULL },
linux-user/syscall.c +5 -0
index 25be16b..850f4cc 100644
@@ -8071,6 +8071,11 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         sync();
         ret = 0;
         break;
+#if defined(TARGET_NR_syncfs) && defined(CONFIG_SYNCFS)
+    case TARGET_NR_syncfs:
+        ret = get_errno(syncfs(arg1));
+        break;
+#endif
     case TARGET_NR_kill:
         ret = get_errno(safe_kill(arg1, target_to_host_signal(arg2)));
         break;
Signature · 1 line
2.9.3