Skip to content

Commit

Permalink
stage1/kvm: fix qemu memfd build failure
Browse files Browse the repository at this point in the history
This is a backport of a qemu upstream patch to fix a memfd related
failure. It first adds infrastructure to apply the patch to qemu at
build time.

Ref: https://git.qemu.org/?p=qemu.git;a=commit;h=75e5b70e6b5dcc4f2219992d7cffa462aa406af0
Ref: rkt#3921 (comment)
  • Loading branch information
lucab committed Apr 13, 2018
1 parent b84c860 commit 8009390
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 2 deletions.
26 changes: 24 additions & 2 deletions stage1/usr_from_kvm/qemu.mk
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
$(call setup-stamp-file,QEMU_STAMP)
QEMU_TMPDIR := $(UFK_TMPDIR)/qemu
QEMU_SRCDIR := $(QEMU_TMPDIR)/src
QEMU_STUFFDIR := $(MK_SRCDIR)/qemu
QEMU_PATCHESDIR := $(QEMU_STUFFDIR)/patches
QEMU_PATCHES := $(abspath $(QEMU_PATCHESDIR)/*.patch)

QEMU_BINARY := $(QEMU_SRCDIR)/x86_64-softmmu/qemu-system-x86_64
QEMU_BIOS_BINARIES := bios-256k.bin \
kvmvapic.bin \
Expand All @@ -22,11 +26,14 @@ QEMU_GIT := git://git.qemu-project.org/qemu.git
QEMU_GIT_COMMIT := v2.8.0

$(call setup-stamp-file,QEMU_BUILD_STAMP,/build)
$(call setup-stamp-file,QEMU_PATCH_STAMP,/patch_qemu)
$(call setup-stamp-file,QEMU_BIOS_BUILD_STAMP,/bios_build)
$(call setup-stamp-file,QEMU_CONF_STAMP,/conf)
$(call setup-stamp-file,QEMU_DIR_CLEAN_STAMP,/dir-clean)
$(call setup-filelist-file,QEMU_DIR_FILELIST,/dir)
$(call setup-clean-file,QEMU_CLEANMK,/src)
$(call setup-dep-file,QEMU_PATCHES_DEPMK)
$(call setup-filelist-file,QEMU_PATCHES_FILELIST,/patches)

S1_RF_SECONDARY_STAMPS += $(QEMU_STAMP)
S1_RF_INSTALL_FILES += $(QEMU_BINARY):$(QEMU_ACI_BINARY):-
Expand All @@ -37,7 +44,17 @@ INSTALL_DIRS += \
# Bios files needs to be removed (source will be removed by QEMU_DIR_CLEAN_STAMP)
CLEAN_FILES += $(foreach bios,$(QEMU_BIOS_BINARIES),$(HV_ACIROOTFSDIR)/${bios})

$(call generate-stamp-rule,$(QEMU_STAMP),$(QEMU_CONF_STAMP) $(QEMU_BUILD_STAMP) $(QEMU_ACI_BINARY) $(QEMU_BIOS_BUILD_STAMP) $(QEMU_DIR_CLEAN_STAMP),,)
$(call generate-stamp-rule,$(QEMU_PATCH_STAMP),$(QEMU_CONF_STAMP),, \
shopt -s nullglob; \
for p in $(QEMU_PATCHES); do \
$(call vb,v2,PATCH,$$$${p#$(MK_TOPLEVEL_ABS_SRCDIR)/}) \
patch $(call vl3,--silent) --directory="$(QEMU_SRCDIR)" --strip=1 --forward <"$$$${p}"; \
done)

# Generate a filelist of patches. Can happen anytime.
$(call generate-patches-filelist,$(QEMU_PATCHES_FILELIST),$(QEMU_PATCHESDIR))

$(call generate-stamp-rule,$(QEMU_STAMP),$(QEMU_PATCH_STAMP) $(QEMU_CONF_STAMP) $(QEMU_BUILD_STAMP) $(QEMU_ACI_BINARY) $(QEMU_BIOS_BUILD_STAMP) $(QEMU_DIR_CLEAN_STAMP),,)

$(QEMU_BINARY): $(QEMU_BUILD_STAMP)

Expand All @@ -47,7 +64,7 @@ $(call generate-stamp-rule,$(QEMU_BIOS_BUILD_STAMP),$(QEMU_CONF_STAMP) $(UFK_CBU
cp $(QEMU_SRCDIR)/pc-bios/$$$${bios} $(HV_ACIROOTFSDIR)/$$$${bios} $(call vl2,>/dev/null); \
done)

$(call generate-stamp-rule,$(QEMU_BUILD_STAMP),$(QEMU_CONF_STAMP),, \
$(call generate-stamp-rule,$(QEMU_BUILD_STAMP),$(QEMU_CONF_STAMP) $(QEMU_PATCH_STAMP),, \
$(call vb,vt,BUILD EXT,qemu) \
$$(MAKE) $(call vl2,--silent) -C "$(QEMU_SRCDIR)" $(call vl2,>/dev/null))

Expand All @@ -63,6 +80,11 @@ $(call generate-deep-filelist,$(QEMU_DIR_FILELIST),$(QEMU_SRCDIR))
# Generate clean.mk cleaning qemu directory
$(call generate-clean-mk,$(QEMU_DIR_CLEAN_STAMP),$(QEMU_CLEANMK),$(QEMU_DIR_FILELIST),$(QEMU_SRCDIR))

# Generate dep.mk on patches, so if they change, the project has to be
# reset to original checkout and patches reapplied.
$(call generate-glob-deps,$(QEMU_DEPS_STAMP),$(QEMU_SRCDIR)/Makefile,$(QEMU_PATCHES_DEPMK),.patch,$(QEMU_PATCHES_FILELIST),$(QEMU_PATCHESDIR),normal)


GCL_REPOSITORY := $(QEMU_GIT)
GCL_DIRECTORY := $(QEMU_SRCDIR)
GCL_COMMITTISH := $(QEMU_GIT_COMMIT)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
From 75e5b70e6b5dcc4f2219992d7cffa462aa406af0 Mon Sep 17 00:00:00 2001
From: Paolo Bonzini <[email protected]>
Date: Tue, 28 Nov 2017 11:51:27 +0100
Subject: [PATCH] memfd: fix configure test
MIME-Version: 1.0
Content-Type: text/plain; charset=utf8
Content-Transfer-Encoding: 8bit

Recent glibc added memfd_create in sys/mman.h. This conflicts with
the definition in util/memfd.c:

/builddir/build/BUILD/qemu-2.11.0-rc1/util/memfd.c:40:12: error: static declaration of memfd_create follows non-static declaration

Fix the configure test, and remove the sys/memfd.h inclusion since the
file actually does not exist---it is a typo in the memfd_create(2) man
page.

Cc: Marc-André Lureau <[email protected]>
Signed-off-by: Paolo Bonzini <[email protected]>
---
configure | 2 +-
util/memfd.c | 4 +---
2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/configure b/configure
index 9c8aa5a..99ccc17 100755
--- a/configure
+++ b/configure
@@ -3923,7 +3923,7 @@ fi
# check if memfd is supported
memfd=no
cat > $TMPC << EOF
-#include <sys/memfd.h>
+#include <sys/mman.h>

int main(void)
{
diff --git a/util/memfd.c b/util/memfd.c
index 4571d1a..412e94a 100644
--- a/util/memfd.c
+++ b/util/memfd.c
@@ -31,9 +31,7 @@

#include "qemu/memfd.h"

-#ifdef CONFIG_MEMFD
-#include <sys/memfd.h>
-#elif defined CONFIG_LINUX
+#if defined CONFIG_LINUX && !defined CONFIG_MEMFD
#include <sys/syscall.h>
#include <asm/unistd.h>

--
1.8.3.1

0 comments on commit 8009390

Please sign in to comment.