Skip to contentSkip to conversation

migration: usefaultfd cleanups

PATCH Superseded Michael S. Tsirkin 3 participants 10 messages Mar 20, 2018

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v2 cover migration: usefaultfd cleanups

We normally do not need to bother with ifdefs around specific system-calls. userfaultfd turns out to be different because our unistd import into linux-headers is incomplete: it's missing asm-generic bits, some arm and mips headers.

Fix it up, and drop ifdefs for usefaultfd.

Tested on x86 only.

Pls consider merging this through the migration tree.

Michael S. Tsirkin (3):
update-linux-headers.sh: add unistd.h
linux-headers: add asm-generic/unistd.h
postcopy: drop unnecessary conditions

 linux-headers/asm-arm/bitsperlong.h     |   1 +
 linux-headers/asm-arm64/bitsperlong.h   |  24 +
 linux-headers/asm-generic/bitsperlong.h |  16 +
 linux-headers/asm-generic/unistd.h      | 944 ++++++++++++++++++++++++++++++++
 linux-headers/asm-mips/bitsperlong.h    |   9 +
 linux-headers/asm-mips/unistd.h         |  44 +-
 linux-headers/asm-powerpc/bitsperlong.h |  13 +
 linux-headers/asm-s390/bitsperlong.h    |  14 +
 linux-headers/asm-x86/bitsperlong.h     |  14 +
 migration/postcopy-ram.c                |   4 +-
 tests/migration-test.c                  |   2 +-
 scripts/update-linux-headers.sh         |  17 +-
 12 files changed, 1085 insertions(+), 17 deletions(-)
 create mode 100644 linux-headers/asm-arm/bitsperlong.h
 create mode 100644 linux-headers/asm-arm64/bitsperlong.h
 create mode 100644 linux-headers/asm-generic/bitsperlong.h
 create mode 100644 linux-headers/asm-generic/unistd.h
 create mode 100644 linux-headers/asm-mips/bitsperlong.h
 create mode 100644 linux-headers/asm-powerpc/bitsperlong.h
 create mode 100644 linux-headers/asm-s390/bitsperlong.h
 create mode 100644 linux-headers/asm-x86/bitsperlong.h
Signature · 1 line
MST
#1 lore raw

PATCH v2 1/3 update-linux-headers.sh: add unistd.h

Add the header and its dependencies.

---
 scripts/update-linux-headers.sh | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)
scripts/update-linux-headers.sh +10 -7
index d18e2f1..e528bda 100755
@@ -80,11 +80,6 @@ for arch in $ARCHLIST; do
         continue
     fi
 
-    # Blacklist architectures which have KVM headers but are actually dead
-    if [ "$arch" = "ia64" -o "$arch" = "mips" ]; then
-        continue
-    fi
-
     if [ "$arch" = x86 ]; then
         arch_var=SRCARCH
     else
@@ -95,9 +90,17 @@ for arch in $ARCHLIST; do
 
     rm -rf "$output/linux-headers/asm-$arch"
     mkdir -p "$output/linux-headers/asm-$arch"
-    for header in kvm.h kvm_para.h unistd.h; do
+    for header in unistd.h bitsperlong.h; do
         cp "$tmpdir/include/asm/$header" "$output/linux-headers/asm-$arch"
     done
+
+    # Blacklist architectures which have KVM headers but are actually dead
+    if [ "$arch" != "ia64" -a "$arch" != "mips" ]; then
+        for header in kvm.h kvm_para.h; do
+            cp "$tmpdir/include/asm/$header" "$output/linux-headers/asm-$arch"
+        done
+    fi
+
     if [ $arch = powerpc ]; then
         cp "$tmpdir/include/asm/epapr_hcalls.h" "$output/linux-headers/asm-powerpc/"
     fi
@@ -130,7 +133,7 @@ for header in kvm.h kvm_para.h vfio.h vfio_ccw.h vhost.h \
 done
 rm -rf "$output/linux-headers/asm-generic"
 mkdir -p "$output/linux-headers/asm-generic"
-for header in kvm_para.h; do
+for header in kvm_para.h bitsperlong.h unistd.h; do
     cp "$tmpdir/include/asm-generic/$header" "$output/linux-headers/asm-generic"
 done
 if [ -L "$linux/source" ]; then
Signature · 1 line
MST
#2 lore raw

Re: [Qemu-devel] [PATCH v2 1/3] update-linux-headers.sh: add unistd.h

Quoted 24 lines · Michael S. Tsirkin

Add the header and its dependencies.

---
 scripts/update-linux-headers.sh | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)
scripts/update-linux-headers.sh +0 -5
index d18e2f1..e528bda 100755
@@ -80,11 +80,6 @@ for arch in $ARCHLIST; do
         continue
     fi
 
-    # Blacklist architectures which have KVM headers but are actually dead
-    if [ "$arch" = "ia64" -o "$arch" = "mips" ]; then
-        continue
-    fi
-
     if [ "$arch" = x86 ]; then
         arch_var=SRCARCH
     else

scripts/update-linux-headers.sh for arch in $ARCHLIST; do · line 98

Quoted 10 lines
scripts/update-linux-headers.sh +4 -1
@@ -95,9 +90,17 @@ for arch in $ARCHLIST; do
 
     rm -rf "$output/linux-headers/asm-$arch"
     mkdir -p "$output/linux-headers/asm-$arch"
-    for header in kvm.h kvm_para.h unistd.h; do
+    for header in unistd.h bitsperlong.h; do
         cp "$tmpdir/include/asm/$header" "$output/linux-headers/asm-$arch"
     done
+
+    # Blacklist architectures which have KVM headers but are actually dead
+    if [ "$arch" != "ia64" -a "$arch" != "mips" ]; then

We don't need to blacklist ia64 here, beacues it doesn't have the kvm headers in the kernel any more, so it is already being skipped because of the condition at the top of the loop that ignores any arch which doesn't have a kvm.h.

For MIPS, KVM is supposed to be properly supported these days, right? That sounds like we should not be blacklisting them either, but instead sorting out whatever issues it was that made us exclude them.

Quoted 18 lines
scripts/update-linux-headers.sh +6 -2
+        for header in kvm.h kvm_para.h; do
+            cp "$tmpdir/include/asm/$header" "$output/linux-headers/asm-$arch"
+        done
+    fi
+
     if [ $arch = powerpc ]; then
         cp "$tmpdir/include/asm/epapr_hcalls.h" "$output/linux-headers/asm-powerpc/"
     fi
@@ -130,7 +133,7 @@ for header in kvm.h kvm_para.h vfio.h vfio_ccw.h vhost.h \
 done
 rm -rf "$output/linux-headers/asm-generic"
 mkdir -p "$output/linux-headers/asm-generic"
-for header in kvm_para.h; do
+for header in kvm_para.h bitsperlong.h unistd.h; do
     cp "$tmpdir/include/asm-generic/$header" "$output/linux-headers/asm-generic"
 done
 if [ -L "$linux/source" ]; then
--
Quoted 1 line

MST

thanks
-- PMM

#3 lore raw

Re: [Qemu-devel] [PATCH v2 1/3] update-linux-headers.sh: add unistd.h

Quoted 26 lines · Peter Maydell
Quoted 25 lines · Michael S. Tsirkin

Add the header and its dependencies.

---
 scripts/update-linux-headers.sh | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)
scripts/update-linux-headers.sh +0 -5
index d18e2f1..e528bda 100755
@@ -80,11 +80,6 @@ for arch in $ARCHLIST; do
         continue
     fi
 
-    # Blacklist architectures which have KVM headers but are actually dead
-    if [ "$arch" = "ia64" -o "$arch" = "mips" ]; then
-        continue
-    fi
-
     if [ "$arch" = x86 ]; then
         arch_var=SRCARCH
     else
@@ -95,9 +90,17 @@ for arch in $ARCHLIST; do
 
Quoted 14 lines

scripts/update-linux-headers.sh for arch in $ARCHLIST; do · line 98

Quoted 9 lines
scripts/update-linux-headers.sh +4 -1
     rm -rf "$output/linux-headers/asm-$arch"
     mkdir -p "$output/linux-headers/asm-$arch"
-    for header in kvm.h kvm_para.h unistd.h; do
+    for header in unistd.h bitsperlong.h; do
         cp "$tmpdir/include/asm/$header" "$output/linux-headers/asm-$arch"
     done
+
+    # Blacklist architectures which have KVM headers but are actually dead
+    if [ "$arch" != "ia64" -a "$arch" != "mips" ]; then

We don't need to blacklist ia64 here, beacues it doesn't have the kvm headers in the kernel any more, so it is already being skipped because of the condition at the top of the loop that ignores any arch which doesn't have a kvm.h.

OK.

Quoted 3 lines

For MIPS, KVM is supposed to be properly supported these days, right? That sounds like we should not be blacklisting them either, but instead sorting out whatever issues it was that made us exclude them.

I agree but I'd rather someone else looked at this.

Quoted 22 lines
Quoted 18 lines
scripts/update-linux-headers.sh +6 -2
+        for header in kvm.h kvm_para.h; do
+            cp "$tmpdir/include/asm/$header" "$output/linux-headers/asm-$arch"
+        done
+    fi
+
     if [ $arch = powerpc ]; then
         cp "$tmpdir/include/asm/epapr_hcalls.h" "$output/linux-headers/asm-powerpc/"
     fi
@@ -130,7 +133,7 @@ for header in kvm.h kvm_para.h vfio.h vfio_ccw.h vhost.h \
 done
 rm -rf "$output/linux-headers/asm-generic"
 mkdir -p "$output/linux-headers/asm-generic"
-for header in kvm_para.h; do
+for header in kvm_para.h bitsperlong.h unistd.h; do
     cp "$tmpdir/include/asm-generic/$header" "$output/linux-headers/asm-generic"
 done
 if [ -L "$linux/source" ]; then
--
Quoted 1 line

MST

thanks
-- PMM

#4 lore raw

Re: [Qemu-devel] [PATCH v2 1/3] update-linux-headers.sh: add unistd.h

Quoted 5 lines · Michael S. Tsirkin
Quoted 3 lines

For MIPS, KVM is supposed to be properly supported these days, right? That sounds like we should not be blacklisting them either, but instead sorting out whatever issues it was that made us exclude them.

I agree but I'd rather someone else looked at this.

Yeah, this doesn't look like the best time to change that.

Thanks,

Paolo

#5 lore raw

PATCH v2 2/3 linux-headers: add asm-generic/unistd.h

In reply to Michael S. Tsirkin

ARM64 and MIPS depend on asm-generic/unistd.h for syscall numbers. This adds asm-generic/unistd.h and it's dependencies.

---
 linux-headers/asm-arm/bitsperlong.h     |   1 +
 linux-headers/asm-arm64/bitsperlong.h   |  24 +
 linux-headers/asm-generic/bitsperlong.h |  16 +
 linux-headers/asm-generic/unistd.h      | 944 ++++++++++++++++++++++++++++++++
 linux-headers/asm-mips/bitsperlong.h    |   9 +
 linux-headers/asm-mips/unistd.h         |  44 +-
 linux-headers/asm-powerpc/bitsperlong.h |  13 +
 linux-headers/asm-s390/bitsperlong.h    |  14 +
 linux-headers/asm-x86/bitsperlong.h     |  14 +
 9 files changed, 1073 insertions(+), 6 deletions(-)
 create mode 100644 linux-headers/asm-arm/bitsperlong.h
 create mode 100644 linux-headers/asm-arm64/bitsperlong.h
 create mode 100644 linux-headers/asm-generic/bitsperlong.h
 create mode 100644 linux-headers/asm-generic/unistd.h
 create mode 100644 linux-headers/asm-mips/bitsperlong.h
 create mode 100644 linux-headers/asm-powerpc/bitsperlong.h
 create mode 100644 linux-headers/asm-s390/bitsperlong.h
 create mode 100644 linux-headers/asm-x86/bitsperlong.h
linux-headers/asm-arm/bitsperlong.h new file +1 -0
new file mode 100644
index 0000000..6dc0bb0
@@ -0,0 +1 @@
+#include <asm-generic/bitsperlong.h>
linux-headers/asm-arm64/bitsperlong.h new file +24 -0
new file mode 100644
index 0000000..485d60b
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+/*
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_BITSPERLONG_H
+#define __ASM_BITSPERLONG_H
+
+#define __BITS_PER_LONG 64
+
+#include <asm-generic/bitsperlong.h>
+
+#endif	/* __ASM_BITSPERLONG_H */
linux-headers/asm-generic/bitsperlong.h new file +16 -0
new file mode 100644
index 0000000..0aac245
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+#ifndef __ASM_GENERIC_BITS_PER_LONG
+#define __ASM_GENERIC_BITS_PER_LONG
+
+/*
+ * There seems to be no way of detecting this automatically from user
+ * space, so 64 bit architectures should override this in their
+ * bitsperlong.h. In particular, an architecture that supports
+ * both 32 and 64 bit user space must not rely on CONFIG_64BIT
+ * to decide it, but rather check a compiler provided macro.
+ */
+#ifndef __BITS_PER_LONG
+#define __BITS_PER_LONG 32
+#endif
+
+#endif /* __ASM_GENERIC_BITS_PER_LONG */
linux-headers/asm-generic/unistd.h new file +944 -0

944 lines not on this page · raw message

linux-headers/asm-mips/bitsperlong.h new file +9 -0
new file mode 100644
index 0000000..7268380
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+#ifndef __ASM_MIPS_BITSPERLONG_H
+#define __ASM_MIPS_BITSPERLONG_H
+
+#define __BITS_PER_LONG _MIPS_SZLONG
+
+#include <asm-generic/bitsperlong.h>
+
+#endif /* __ASM_MIPS_BITSPERLONG_H */
linux-headers/asm-mips/unistd.h +38 -6

88 lines not on this page · raw message

linux-headers/asm-powerpc/bitsperlong.h new file +13 -0
new file mode 100644
index 0000000..46ece3e
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+#ifndef __ASM_POWERPC_BITSPERLONG_H
+#define __ASM_POWERPC_BITSPERLONG_H
+
+#if defined(__powerpc64__)
+# define __BITS_PER_LONG 64
+#else
+# define __BITS_PER_LONG 32
+#endif
+
+#include <asm-generic/bitsperlong.h>
+
+#endif /* __ASM_POWERPC_BITSPERLONG_H */
linux-headers/asm-s390/bitsperlong.h new file +14 -0
new file mode 100644
index 0000000..cceaf47
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+#ifndef __ASM_S390_BITSPERLONG_H
+#define __ASM_S390_BITSPERLONG_H
+
+#ifndef __s390x__
+#define __BITS_PER_LONG 32
+#else
+#define __BITS_PER_LONG 64
+#endif
+
+#include <asm-generic/bitsperlong.h>
+
+#endif /* __ASM_S390_BITSPERLONG_H */
+
linux-headers/asm-x86/bitsperlong.h new file +14 -0
new file mode 100644
index 0000000..5d72c84
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+#ifndef __ASM_X86_BITSPERLONG_H
+#define __ASM_X86_BITSPERLONG_H
+
+#if defined(__x86_64__) && !defined(__ILP32__)
+# define __BITS_PER_LONG 64
+#else
+# define __BITS_PER_LONG 32
+#endif
+
+#include <asm-generic/bitsperlong.h>
+
+#endif /* __ASM_X86_BITSPERLONG_H */
+
Signature · 1 line
MST
#6 lore raw

PATCH v2 3/3 postcopy: drop unnecessary conditions

In reply to Michael S. Tsirkin

We have our own copy of unistd so there is no
need to check for symbols present there.

---
 migration/postcopy-ram.c | 4 +---
 tests/migration-test.c   | 2 +-
 2 files changed, 2 insertions(+), 4 deletions(-)
migration/postcopy-ram.c +1 -3
index efd7793..027c02c 100644
@@ -86,7 +86,7 @@ int postcopy_notify(enum PostcopyNotifyReason reason, Error **errp)
 #include <asm/types.h> /* for __u64 */
 #endif
 
-#if defined(__linux__) && defined(__NR_userfaultfd) && defined(CONFIG_EVENTFD)
+#if defined(__linux__) && defined(CONFIG_EVENTFD)
 #include <sys/eventfd.h>
 #include <linux/userfaultfd.h>
 
@@ -97,7 +97,6 @@ int postcopy_notify(enum PostcopyNotifyReason reason, Error **errp)
  *
  * Returns: true on success
  *
- * __NR_userfaultfd - should be checked before
  *  @features: out parameter will contain uffdio_api.features provided by kernel
  *              in case of success
  */
@@ -107,7 +106,6 @@ static bool receive_ufd_features(uint64_t *features)
     int ufd;
     bool ret = true;
 
-    /* if we are here __NR_userfaultfd should exists */
     ufd = syscall(__NR_userfaultfd, O_CLOEXEC);
     if (ufd == -1) {
         error_report("%s: syscall __NR_userfaultfd failed: %s", __func__,
tests/migration-test.c +1 -1
index 422bf1a..e5dcedb 100644
@@ -32,7 +32,7 @@ bool got_stop;
 #include <sys/vfs.h>
 #endif
 
-#if defined(__linux__) && defined(__NR_userfaultfd) && defined(CONFIG_EVENTFD)
+#if defined(__linux__) && defined(CONFIG_EVENTFD)
 #include <sys/eventfd.h>
 #include <sys/ioctl.h>
 #include <linux/userfaultfd.h>
Signature · 1 line
MST
#7 lore raw

Re: [Qemu-devel] [PATCH v2 3/3] postcopy: drop unnecessary conditions

Quoted 4 lines · Michael S. Tsirkin

We have our own copy of unistd so there is no
need to check for symbols present there.

I just sent a mail in the other thread about this, but we only have our own copy of unistd if the host architecture supports KVM. If it doesn't then we're going to be using the system's copy of the includes...

thanks
-- PMM

#8 lore raw

Re: [Qemu-devel] [PATCH v2 3/3] postcopy: drop unnecessary conditions

Quoted 6 lines · Peter Maydell
Quoted 4 lines · Michael S. Tsirkin

We have our own copy of unistd so there is no
need to check for symbols present there.

Quoted 7 lines

I just sent a mail in the other thread about this, but we only have our own copy of unistd if the host architecture supports KVM. If it doesn't then we're going to be using the system's copy of the includes...

thanks
-- PMM

Hmm good point.

I guess I should leave postcopy alone then, and just update the headers?

That can go through my tree ...

Signature · 1 line
MST
#9 lore raw

Re: [Qemu-devel] [PATCH v2 3/3] postcopy: drop unnecessary conditions

In reply to Michael S. Tsirkin
Quoted 4 lines · Michael S. Tsirkin

We have our own copy of unistd so there is no
need to check for symbols present there.

Self-Nack

pls ignore - we do not have unistd.h on all systems unfortunately.

Will send v3 without this patch and with more tweaks.

Quoted 50 lines
---
 migration/postcopy-ram.c | 4 +---
 tests/migration-test.c   | 2 +-
 2 files changed, 2 insertions(+), 4 deletions(-)
migration/postcopy-ram.c +1 -3
index efd7793..027c02c 100644
@@ -86,7 +86,7 @@ int postcopy_notify(enum PostcopyNotifyReason reason, Error **errp)
 #include <asm/types.h> /* for __u64 */
 #endif
 
-#if defined(__linux__) && defined(__NR_userfaultfd) && defined(CONFIG_EVENTFD)
+#if defined(__linux__) && defined(CONFIG_EVENTFD)
 #include <sys/eventfd.h>
 #include <linux/userfaultfd.h>
 
@@ -97,7 +97,6 @@ int postcopy_notify(enum PostcopyNotifyReason reason, Error **errp)
  *
  * Returns: true on success
  *
- * __NR_userfaultfd - should be checked before
  *  @features: out parameter will contain uffdio_api.features provided by kernel
  *              in case of success
  */
@@ -107,7 +106,6 @@ static bool receive_ufd_features(uint64_t *features)
     int ufd;
     bool ret = true;
 
-    /* if we are here __NR_userfaultfd should exists */
     ufd = syscall(__NR_userfaultfd, O_CLOEXEC);
     if (ufd == -1) {
         error_report("%s: syscall __NR_userfaultfd failed: %s", __func__,
tests/migration-test.c +1 -1
index 422bf1a..e5dcedb 100644
@@ -32,7 +32,7 @@ bool got_stop;
 #include <sys/vfs.h>
 #endif
 
-#if defined(__linux__) && defined(__NR_userfaultfd) && defined(CONFIG_EVENTFD)
+#if defined(__linux__) && defined(CONFIG_EVENTFD)
 #include <sys/eventfd.h>
 #include <sys/ioctl.h>
 #include <linux/userfaultfd.h>
Signature · 1 line
MST