From nobody Tue Jul 15 06:07:37 2025 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1650719274033810.6720123452162; Sat, 23 Apr 2022 06:07:54 -0700 (PDT) Received: from localhost ([::1]:45256 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1niFUO-0002LA-S3 for importer2@patchew.org; Sat, 23 Apr 2022 09:07:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42772) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1niFFZ-0007Ka-Oa for qemu-devel@nongnu.org; Sat, 23 Apr 2022 08:52:36 -0400 Received: from mail-ed1-x52b.google.com ([2a00:1450:4864:20::52b]:45912) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1niFFS-0005Ai-Nr for qemu-devel@nongnu.org; Sat, 23 Apr 2022 08:52:31 -0400 Received: by mail-ed1-x52b.google.com with SMTP id be20so5112978edb.12 for ; Sat, 23 Apr 2022 05:52:26 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:1c09:f536:3de6:228c]) by smtp.gmail.com with ESMTPSA id bo14-20020a170906d04e00b006ce98d9c3e3sm1655573ejb.194.2022.04.23.05.52.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Apr 2022 05:52:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9CRULFmGb8JuMU5SN8qBhe8UXJr2Mq7ocDKDHiBZkM8=; b=WaCMEYgFkJY/nnN+zVIDCKi18R5pE7rzv7MpAyQkN7GcucX4aJhay/Skz1LhsZAVVr +uUDiP/eJWhFCmWuew0oQa7+Z3aTMDgsNCgB3lqPdTPDKmv5kcoNfNkzJjo5ZO11951L fGStbVJ31bIxhXCGpuqoHl0QZ22yy3PixlF0VwDP87y/Np0x61BTtS4u4as2OXxotf2R 76kV3vNYkQoLRXDZtBlDMzcVE+cUFbjzWmLQfSpxkTy70P46OaBrNRhAOpQNO/DRoGS/ QqUTQ7TTXGWrIDaknEehuXDdF/685S00+rnhAPOnuTr4Q7gnoralExrgRN5H66caWj9M hnqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=9CRULFmGb8JuMU5SN8qBhe8UXJr2Mq7ocDKDHiBZkM8=; b=D6maLOIIv7qBk0biOL912HNwv8eqe57Pdh2bcVm8b19z4Pawdekr96+IlVF9JSIBIU 1wX+yCjnknZeuQldfLC3rAcKvg6zSw3c9sn4RXcd0xrnUHTbclOiAEtTxZ+1PnEMDdZQ OCwZsV9UJ2t81CVj927du00FSXvXvlB4TCd27nHexY5Tu1jVli0Wqu9M8uJqPJteQoG8 qCTgVu+wy3qCmlNJUAG2LFxgEC4LSOLv4Rcdkp/ZRUhvpb8HySR8k+fdT5PdR5EEUeo5 7aSpbsS/ysuMEwCwT3MAGjtY/scpUtlLT5rmCdnS9mPvERaj8j/ROMnQFm5LkNUYalMf w1Dg== X-Gm-Message-State: AOAM532hXKLN1ZY1KR8G3jdFWPQKI3i3FM0mRgYSlADgr62efvzUZc1L zlHIF+iSk0rpPOmd8KTbUobv0+5jkuBT2Q== X-Google-Smtp-Source: ABdhPJxS3Np07KoSu/ZpY5Bb9UykonoOGRZMZmATfT1KSIGORj+CMIUiBpr3iJsk+3pK16zsBIPyQw== X-Received: by 2002:a05:6402:34c9:b0:423:deb7:f69e with SMTP id w9-20020a05640234c900b00423deb7f69emr10075874edc.335.1650718345369; Sat, 23 Apr 2022 05:52:25 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v2 14/34] meson, configure: move Xen detection to meson Date: Sat, 23 Apr 2022 14:51:31 +0200 Message-Id: <20220423125151.27821-15-pbonzini@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220423125151.27821-1-pbonzini@redhat.com> References: <20220423125151.27821-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::52b; envelope-from=paolo.bonzini@gmail.com; helo=mail-ed1-x52b.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@redhat.com Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1650719275395100001 Content-Type: text/plain; charset="utf-8" This is quite a complicated check. I moved all the test programs to a single file in scripts/, picking the right program with #if and a -D flag in meson.build's cc.links() invocation. Signed-off-by: Paolo Bonzini --- configure | 322 +------------------------------------------ meson.build | 112 ++++++++++++--- scripts/xen-detect.c | 203 +++++++++++++++++++++++++++ 3 files changed, 296 insertions(+), 341 deletions(-) create mode 100644 scripts/xen-detect.c diff --git a/configure b/configure index 59c43bea05..a3ac5af863 100755 --- a/configure +++ b/configure @@ -292,7 +292,6 @@ EXTRA_CXXFLAGS=3D"" EXTRA_OBJCFLAGS=3D"" EXTRA_LDFLAGS=3D"" =20 -xen_ctrl_version=3D"$default_feature" vhost_kernel=3D"$default_feature" vhost_net=3D"$default_feature" vhost_crypto=3D"$default_feature" @@ -346,9 +345,6 @@ default_devices=3D"true" tcg=3D"enabled" cfi=3D"false" =20 -# 4. Detection partly done in configure -xen=3D${default_feature:+disabled} - # parse CC options second for opt do optarg=3D$(expr "x$opt" : 'x[^=3D]*=3D\(.*\)') @@ -866,10 +862,6 @@ for opt do ;; --enable-slirp=3D*) slirp=3D"$optarg" ;; - --disable-xen) xen=3D"disabled" - ;; - --enable-xen) xen=3D"enabled" - ;; --disable-tcg) tcg=3D"disabled" plugins=3D"no" ;; @@ -1697,312 +1689,6 @@ if ! has "$pkg_config_exe"; then error_exit "pkg-config binary '$pkg_config_exe' not found" fi =20 -########################################## -# xen probe - -if test "$xen" !=3D "disabled" ; then - # Check whether Xen library path is specified via --extra-ldflags to avo= id - # overriding this setting with pkg-config output. If not, try pkg-config - # to obtain all needed flags. - - if ! echo $EXTRA_LDFLAGS | grep tools/libxc > /dev/null && \ - $pkg_config --exists xencontrol ; then - xen_ctrl_version=3D"$(printf '%d%02d%02d' \ - $($pkg_config --modversion xencontrol | sed 's/\./ /g') )" - xen=3Denabled - xen_pc=3D"xencontrol xenstore xenforeignmemory xengnttab" - xen_pc=3D"$xen_pc xenevtchn xendevicemodel" - if $pkg_config --exists xentoolcore; then - xen_pc=3D"$xen_pc xentoolcore" - fi - xen_cflags=3D"$($pkg_config --cflags $xen_pc)" - xen_libs=3D"$($pkg_config --libs $xen_pc)" - else - - xen_libs=3D"-lxenstore -lxenctrl" - xen_stable_libs=3D"-lxenforeignmemory -lxengnttab -lxenevtchn" - - # First we test whether Xen headers and libraries are available. - # If no, we are done and there is no Xen support. - # If yes, more tests are run to detect the Xen version. - - # Xen (any) - cat > $TMPC < -int main(void) { - return 0; -} -EOF - if ! compile_prog "" "$xen_libs" ; then - # Xen not found - if test "$xen" =3D "enabled" ; then - feature_not_found "xen" "Install xen devel" - fi - xen=3Ddisabled - - # Xen unstable - elif - cat > $TMPC < -#include -int main(void) { - xendevicemodel_handle *xd; - xenforeignmemory_handle *xfmem; - - xd =3D xendevicemodel_open(0, 0); - xendevicemodel_pin_memory_cacheattr(xd, 0, 0, 0, 0); - - xfmem =3D xenforeignmemory_open(0, 0); - xenforeignmemory_map_resource(xfmem, 0, 0, 0, 0, 0, NULL, 0, 0); - - return 0; -} -EOF - compile_prog "" "$xen_libs -lxendevicemodel $xen_stable_libs -lxen= toolcore" - then - xen_stable_libs=3D"-lxendevicemodel $xen_stable_libs -lxentoolcore" - xen_ctrl_version=3D41100 - xen=3Denabled - elif - cat > $TMPC < -#include -int main(void) { - xenforeignmemory_handle *xfmem; - - xfmem =3D xenforeignmemory_open(0, 0); - xenforeignmemory_map2(xfmem, 0, 0, 0, 0, 0, 0, 0); - xentoolcore_restrict_all(0); - - return 0; -} -EOF - compile_prog "" "$xen_libs -lxendevicemodel $xen_stable_libs -lxen= toolcore" - then - xen_stable_libs=3D"-lxendevicemodel $xen_stable_libs -lxentoolcore" - xen_ctrl_version=3D41000 - xen=3Denabled - elif - cat > $TMPC < -int main(void) { - xendevicemodel_handle *xd; - - xd =3D xendevicemodel_open(0, 0); - xendevicemodel_close(xd); - - return 0; -} -EOF - compile_prog "" "$xen_libs -lxendevicemodel $xen_stable_libs" - then - xen_stable_libs=3D"-lxendevicemodel $xen_stable_libs" - xen_ctrl_version=3D40900 - xen=3Denabled - elif - cat > $TMPC < -#include -#include -#include -#include -#include -#include -#if !defined(HVM_MAX_VCPUS) -# error HVM_MAX_VCPUS not defined -#endif -int main(void) { - xc_interface *xc =3D NULL; - xenforeignmemory_handle *xfmem; - xenevtchn_handle *xe; - xengnttab_handle *xg; - xengnttab_grant_copy_segment_t* seg =3D NULL; - - xs_daemon_open(); - - xc =3D xc_interface_open(0, 0, 0); - xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0); - xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0); - xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000); - xc_hvm_create_ioreq_server(xc, 0, HVM_IOREQSRV_BUFIOREQ_ATOMIC, NULL); - - xfmem =3D xenforeignmemory_open(0, 0); - xenforeignmemory_map(xfmem, 0, 0, 0, 0, 0); - - xe =3D xenevtchn_open(0, 0); - xenevtchn_fd(xe); - - xg =3D xengnttab_open(0, 0); - xengnttab_grant_copy(xg, 0, seg); - - return 0; -} -EOF - compile_prog "" "$xen_libs $xen_stable_libs" - then - xen_ctrl_version=3D40800 - xen=3Denabled - elif - cat > $TMPC < -#include -#include -#include -#include -#include -#include -#if !defined(HVM_MAX_VCPUS) -# error HVM_MAX_VCPUS not defined -#endif -int main(void) { - xc_interface *xc =3D NULL; - xenforeignmemory_handle *xfmem; - xenevtchn_handle *xe; - xengnttab_handle *xg; - - xs_daemon_open(); - - xc =3D xc_interface_open(0, 0, 0); - xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0); - xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0); - xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000); - xc_hvm_create_ioreq_server(xc, 0, HVM_IOREQSRV_BUFIOREQ_ATOMIC, NULL); - - xfmem =3D xenforeignmemory_open(0, 0); - xenforeignmemory_map(xfmem, 0, 0, 0, 0, 0); - - xe =3D xenevtchn_open(0, 0); - xenevtchn_fd(xe); - - xg =3D xengnttab_open(0, 0); - xengnttab_map_grant_ref(xg, 0, 0, 0); - - return 0; -} -EOF - compile_prog "" "$xen_libs $xen_stable_libs" - then - xen_ctrl_version=3D40701 - xen=3Denabled - - # Xen 4.6 - elif - cat > $TMPC < -#include -#include -#include -#if !defined(HVM_MAX_VCPUS) -# error HVM_MAX_VCPUS not defined -#endif -int main(void) { - xc_interface *xc; - xs_daemon_open(); - xc =3D xc_interface_open(0, 0, 0); - xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0); - xc_gnttab_open(NULL, 0); - xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0); - xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000); - xc_hvm_create_ioreq_server(xc, 0, HVM_IOREQSRV_BUFIOREQ_ATOMIC, NULL); - xc_reserved_device_memory_map(xc, 0, 0, 0, 0, NULL, 0); - return 0; -} -EOF - compile_prog "" "$xen_libs" - then - xen_ctrl_version=3D40600 - xen=3Denabled - - # Xen 4.5 - elif - cat > $TMPC < -#include -#include -#include -#if !defined(HVM_MAX_VCPUS) -# error HVM_MAX_VCPUS not defined -#endif -int main(void) { - xc_interface *xc; - xs_daemon_open(); - xc =3D xc_interface_open(0, 0, 0); - xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0); - xc_gnttab_open(NULL, 0); - xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0); - xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000); - xc_hvm_create_ioreq_server(xc, 0, 0, NULL); - return 0; -} -EOF - compile_prog "" "$xen_libs" - then - xen_ctrl_version=3D40500 - xen=3Denabled - - elif - cat > $TMPC < -#include -#include -#include -#if !defined(HVM_MAX_VCPUS) -# error HVM_MAX_VCPUS not defined -#endif -int main(void) { - xc_interface *xc; - xs_daemon_open(); - xc =3D xc_interface_open(0, 0, 0); - xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0); - xc_gnttab_open(NULL, 0); - xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0); - xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000); - return 0; -} -EOF - compile_prog "" "$xen_libs" - then - xen_ctrl_version=3D40200 - xen=3Denabled - - else - if test "$xen" =3D "enabled" ; then - feature_not_found "xen (unsupported version)" \ - "Install a supported xen (xen 4.2 or newer)" - fi - xen=3Ddisabled - fi - - if test "$xen" =3D enabled; then - if test $xen_ctrl_version -ge 40701 ; then - xen_libs=3D"$xen_libs $xen_stable_libs " - fi - fi - fi -fi - ########################################## # glib support probe =20 @@ -2554,12 +2240,6 @@ if test "$modules" =3D "yes"; then fi echo "CONFIG_TLS_PRIORITY=3D\"$tls_priority\"" >> $config_host_mak =20 -if test "$xen" =3D "enabled" ; then - echo "CONFIG_XEN_BACKEND=3Dy" >> $config_host_mak - echo "CONFIG_XEN_CTRL_INTERFACE_VERSION=3D$xen_ctrl_version" >> $config_= host_mak - echo "XEN_CFLAGS=3D$xen_cflags" >> $config_host_mak - echo "XEN_LIBS=3D$xen_libs" >> $config_host_mak -fi if test "$vhost_scsi" =3D "yes" ; then echo "CONFIG_VHOST_SCSI=3Dy" >> $config_host_mak fi @@ -2837,7 +2517,7 @@ if test "$skip_meson" =3D no; then -Dwerror=3D$(if test "$werror" =3D yes; then echo true; else echo = false; fi) \ -Db_pie=3D$(if test "$pie" =3D yes; then echo true; else echo fals= e; fi) \ -Db_coverage=3D$(if test "$gcov" =3D yes; then echo true; else ech= o false; fi) \ - -Db_lto=3D$lto -Dcfi=3D$cfi -Dtcg=3D$tcg -Dxen=3D$xen \ + -Db_lto=3D$lto -Dcfi=3D$cfi -Dtcg=3D$tcg \ -Dcapstone=3D$capstone -Dfdt=3D$fdt -Dslirp=3D$slirp \ $(test -n "${LIB_FUZZING_ENGINE+xxx}" && echo "-Dfuzzing_engine=3D= $LIB_FUZZING_ENGINE") \ $(if test "$default_feature" =3D no; then echo "-Dauto_features=3D= disabled"; fi) \ diff --git a/meson.build b/meson.build index 77045cf7d4..47e874f0c3 100644 --- a/meson.build +++ b/meson.build @@ -348,12 +348,6 @@ accelerators =3D [] if get_option('kvm').allowed() and targetos =3D=3D 'linux' accelerators +=3D 'CONFIG_KVM' endif -if get_option('xen').allowed() and 'CONFIG_XEN_BACKEND' in config_host - accelerators +=3D 'CONFIG_XEN' - have_xen_pci_passthrough =3D get_option('xen_pci_passthrough').allowed()= and targetos =3D=3D 'linux' -else - have_xen_pci_passthrough =3D false -endif if get_option('whpx').allowed() and targetos =3D=3D 'windows' if get_option('whpx').enabled() and host_machine.cpu() !=3D 'x86_64' error('WHPX requires 64-bit host') @@ -425,13 +419,6 @@ endif if 'CONFIG_WHPX' not in accelerators and get_option('whpx').enabled() error('WHPX not available on this platform') endif -if not have_xen_pci_passthrough and get_option('xen_pci_passthrough').enab= led() - if 'CONFIG_XEN' in accelerators - error('Xen PCI passthrough not available on this platform') - else - error('Xen PCI passthrough requested but Xen not enabled') - endif -endif =20 ################ # Dependencies # @@ -1255,10 +1242,86 @@ if not get_option('rdma').auto() or have_system endif =20 xen =3D not_found -if 'CONFIG_XEN_BACKEND' in config_host - xen =3D declare_dependency(compile_args: config_host['XEN_CFLAGS'].split= (), - link_args: config_host['XEN_LIBS'].split()) +if get_option('xen').enabled() or (get_option('xen').auto() and have_syste= m) + xencontrol =3D dependency('xencontrol', required: false, + method: 'pkg-config', kwargs: static_kwargs) + if xencontrol.found() + xen_pc =3D declare_dependency(version: xencontrol.version(), + dependencies: [ + xencontrol, + # disabler: true makes xen_pc.found() return false if any is not f= ound + dependency('xenstore', required: false, + method: 'pkg-config', kwargs: static_kwargs, + disabler: true), + dependency('xenforeignmemory', required: false, + method: 'pkg-config', kwargs: static_kwargs, + disabler: true), + dependency('xengnttab', required: false, + method: 'pkg-config', kwargs: static_kwargs, + disabler: true), + dependency('xenevtchn', required: false, + method: 'pkg-config', kwargs: static_kwargs, + disabler: true), + dependency('xendevicemodel', required: false, + method: 'pkg-config', kwargs: static_kwargs, + disabler: true), + # optional, no "disabler: true" + dependency('xentoolcore', required: false, + method: 'pkg-config', kwargs: static_kwargs)]) + if xen_pc.found() + xen =3D xen_pc + endif + endif + if not xen.found() + xen_tests =3D [ '4.11.0', '4.10.0', '4.9.0', '4.8.0', '4.7.1', '4.6.0'= , '4.5.0', '4.2.0' ] + xen_libs =3D { + '4.11.0': [ 'xenstore', 'xenctrl', 'xendevicemodel', 'xenforeignmemo= ry', 'xengnttab', 'xenevtchn', 'xentoolcore' ], + '4.10.0': [ 'xenstore', 'xenctrl', 'xendevicemodel', 'xenforeignmemo= ry', 'xengnttab', 'xenevtchn', 'xentoolcore' ], + '4.9.0': [ 'xenstore', 'xenctrl', 'xendevicemodel', 'xenforeignmemor= y', 'xengnttab', 'xenevtchn' ], + '4.8.0': [ 'xenstore', 'xenctrl', 'xenforeignmemory', 'xengnttab', '= xenevtchn' ], + '4.7.1': [ 'xenstore', 'xenctrl', 'xenforeignmemory', 'xengnttab', '= xenevtchn' ], + '4.6.0': [ 'xenstore', 'xenctrl' ], + '4.5.0': [ 'xenstore', 'xenctrl' ], + '4.2.0': [ 'xenstore', 'xenctrl' ], + } + xen_deps =3D {} + foreach ver: xen_tests + # cache the various library tests to avoid polluting the logs + xen_test_deps =3D [] + foreach l: xen_libs[ver] + if l not in xen_deps + xen_deps +=3D { l: cc.find_library(l, required: false) } + endif + xen_test_deps +=3D xen_deps[l] + endforeach + + # Use -D to pick just one of the test programs in scripts/xen-detect= .c + xen_version =3D ver.split('.') + xen_ctrl_version =3D xen_version[0] + \ + ('0' + xen_version[1]).substring(-2) + \ + ('0' + xen_version[2]).substring(-2) + if cc.links(files('scripts/xen-detect.c'), + args: '-DCONFIG_XEN_CTRL_INTERFACE_VERSION=3D' + xen_ctr= l_version, + dependencies: xen_test_deps) + xen =3D declare_dependency(version: ver, dependencies: xen_test_de= ps) + break + endif + endforeach + endif + if xen.found() + accelerators +=3D 'CONFIG_XEN' + elif get_option('xen').enabled() + error('could not compile and link Xen test program') + endif endif +have_xen_pci_passthrough =3D get_option('xen_pci_passthrough') \ + .require(xen.found(), + error_message: 'Xen PCI passthrough requested but Xen not enabl= ed') \ + .require(targetos =3D=3D 'linux', + error_message: 'Xen PCI passthrough not available on this platf= orm') \ + .allowed() + + cacard =3D not_found if not get_option('smartcard').auto() or have_system cacard =3D dependency('libcacard', required: get_option('smartcard'), @@ -1632,6 +1695,15 @@ config_host_data.set('CONFIG_X11', x11.found()) config_host_data.set('CONFIG_DBUS_DISPLAY', dbus_display) config_host_data.set('CONFIG_CFI', get_option('cfi')) config_host_data.set('CONFIG_SELINUX', selinux.found()) +config_host_data.set('CONFIG_XEN_BACKEND', xen.found()) +if xen.found() + # protect from xen.version() having less than three components + xen_version =3D xen.version().split('.') + ['0', '0'] + xen_ctrl_version =3D xen_version[0] + \ + ('0' + xen_version[1]).substring(-2) + \ + ('0' + xen_version[2]).substring(-2) + config_host_data.set('CONFIG_XEN_CTRL_INTERFACE_VERSION', xen_ctrl_versi= on) +endif config_host_data.set('QEMU_VERSION', '"@0@"'.format(meson.project_version(= ))) config_host_data.set('QEMU_VERSION_MAJOR', meson.project_version().split('= .')[0]) config_host_data.set('QEMU_VERSION_MINOR', meson.project_version().split('= .')[1]) @@ -2356,7 +2428,7 @@ config_all +=3D config_all_devices config_all +=3D config_host config_all +=3D config_all_disas config_all +=3D { - 'CONFIG_XEN': config_host.has_key('CONFIG_XEN_BACKEND'), + 'CONFIG_XEN': xen.found(), 'CONFIG_SOFTMMU': have_system, 'CONFIG_USER_ONLY': have_user, 'CONFIG_ALL': true, @@ -3687,9 +3759,9 @@ if have_system summary_info +=3D {'HVF support': config_all.has_key('CONFIG_HVF')} summary_info +=3D {'WHPX support': config_all.has_key('CONFIG_WHPX'= )} summary_info +=3D {'NVMM support': config_all.has_key('CONFIG_NVMM'= )} - summary_info +=3D {'Xen support': config_host.has_key('CONFIG_XEN_= BACKEND')} - if config_host.has_key('CONFIG_XEN_BACKEND') - summary_info +=3D {'xen ctrl version': config_host['CONFIG_XEN_CTRL_I= NTERFACE_VERSION']} + summary_info +=3D {'Xen support': xen.found()} + if xen.found() + summary_info +=3D {'xen ctrl version': xen.version()} endif endif summary_info +=3D {'TCG support': config_all.has_key('CONFIG_TCG')} diff --git a/scripts/xen-detect.c b/scripts/xen-detect.c new file mode 100644 index 0000000000..85e8206490 --- /dev/null +++ b/scripts/xen-detect.c @@ -0,0 +1,203 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +/* Test programs for various Xen versions that QEMU supports. */ +#if CONFIG_XEN_CTRL_INTERFACE_VERSION =3D=3D 41100 + #undef XC_WANT_COMPAT_DEVICEMODEL_API + #define __XEN_TOOLS__ + #include + #include + int main(void) { + xendevicemodel_handle *xd; + xenforeignmemory_handle *xfmem; + + xd =3D xendevicemodel_open(0, 0); + xendevicemodel_pin_memory_cacheattr(xd, 0, 0, 0, 0); + + xfmem =3D xenforeignmemory_open(0, 0); + xenforeignmemory_map_resource(xfmem, 0, 0, 0, 0, 0, NULL, 0, 0); + + return 0; + } + +#elif CONFIG_XEN_CTRL_INTERFACE_VERSION =3D=3D 41000 + #undef XC_WANT_COMPAT_MAP_FOREIGN_API + #include + #include + int main(void) { + xenforeignmemory_handle *xfmem; + + xfmem =3D xenforeignmemory_open(0, 0); + xenforeignmemory_map2(xfmem, 0, 0, 0, 0, 0, 0, 0); + xentoolcore_restrict_all(0); + + return 0; + } + +#elif CONFIG_XEN_CTRL_INTERFACE_VERSION =3D=3D 40900 + #undef XC_WANT_COMPAT_DEVICEMODEL_API + #define __XEN_TOOLS__ + #include + int main(void) { + xendevicemodel_handle *xd; + + xd =3D xendevicemodel_open(0, 0); + xendevicemodel_close(xd); + + return 0; + } + +#elif CONFIG_XEN_CTRL_INTERFACE_VERSION =3D=3D 40800 + /* + * If we have stable libs the we don't want the libxc compat + * layers, regardless of what CFLAGS we may have been given. + * + * Also, check if xengnttab_grant_copy_segment_t is defined and + * grant copy operation is implemented. + */ + #undef XC_WANT_COMPAT_EVTCHN_API + #undef XC_WANT_COMPAT_GNTTAB_API + #undef XC_WANT_COMPAT_MAP_FOREIGN_API + #include + #include + #include + #include + #include + #include + #include + #if !defined(HVM_MAX_VCPUS) + # error HVM_MAX_VCPUS not defined + #endif + int main(void) { + xc_interface *xc =3D NULL; + xenforeignmemory_handle *xfmem; + xenevtchn_handle *xe; + xengnttab_handle *xg; + xengnttab_grant_copy_segment_t* seg =3D NULL; + + xs_daemon_open(); + + xc =3D xc_interface_open(0, 0, 0); + xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0); + xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0); + xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000); + xc_hvm_create_ioreq_server(xc, 0, HVM_IOREQSRV_BUFIOREQ_ATOMIC, NULL); + + xfmem =3D xenforeignmemory_open(0, 0); + xenforeignmemory_map(xfmem, 0, 0, 0, 0, 0); + + xe =3D xenevtchn_open(0, 0); + xenevtchn_fd(xe); + + xg =3D xengnttab_open(0, 0); + xengnttab_grant_copy(xg, 0, seg); + + return 0; + } + +#elif CONFIG_XEN_CTRL_INTERFACE_VERSION =3D=3D 40701 + /* + * If we have stable libs the we don't want the libxc compat + * layers, regardless of what CFLAGS we may have been given. + */ + #undef XC_WANT_COMPAT_EVTCHN_API + #undef XC_WANT_COMPAT_GNTTAB_API + #undef XC_WANT_COMPAT_MAP_FOREIGN_API + #include + #include + #include + #include + #include + #include + #include + #if !defined(HVM_MAX_VCPUS) + # error HVM_MAX_VCPUS not defined + #endif + int main(void) { + xc_interface *xc =3D NULL; + xenforeignmemory_handle *xfmem; + xenevtchn_handle *xe; + xengnttab_handle *xg; + + xs_daemon_open(); + + xc =3D xc_interface_open(0, 0, 0); + xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0); + xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0); + xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000); + xc_hvm_create_ioreq_server(xc, 0, HVM_IOREQSRV_BUFIOREQ_ATOMIC, NULL); + + xfmem =3D xenforeignmemory_open(0, 0); + xenforeignmemory_map(xfmem, 0, 0, 0, 0, 0); + + xe =3D xenevtchn_open(0, 0); + xenevtchn_fd(xe); + + xg =3D xengnttab_open(0, 0); + xengnttab_map_grant_ref(xg, 0, 0, 0); + + return 0; + } + +#elif CONFIG_XEN_CTRL_INTERFACE_VERSION =3D=3D 40600 + #include + #include + #include + #include + #if !defined(HVM_MAX_VCPUS) + # error HVM_MAX_VCPUS not defined + #endif + int main(void) { + xc_interface *xc; + xs_daemon_open(); + xc =3D xc_interface_open(0, 0, 0); + xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0); + xc_gnttab_open(NULL, 0); + xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0); + xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000); + xc_hvm_create_ioreq_server(xc, 0, HVM_IOREQSRV_BUFIOREQ_ATOMIC, NULL); + xc_reserved_device_memory_map(xc, 0, 0, 0, 0, NULL, 0); + return 0; + } + +#elif CONFIG_XEN_CTRL_INTERFACE_VERSION =3D=3D 40500 + #include + #include + #include + #include + #if !defined(HVM_MAX_VCPUS) + # error HVM_MAX_VCPUS not defined + #endif + int main(void) { + xc_interface *xc; + xs_daemon_open(); + xc =3D xc_interface_open(0, 0, 0); + xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0); + xc_gnttab_open(NULL, 0); + xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0); + xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000); + xc_hvm_create_ioreq_server(xc, 0, 0, NULL); + return 0; + } + +#elif CONFIG_XEN_CTRL_INTERFACE_VERSION =3D=3D 40200 + #include + #include + #include + #include + #if !defined(HVM_MAX_VCPUS) + # error HVM_MAX_VCPUS not defined + #endif + int main(void) { + xc_interface *xc; + xs_daemon_open(); + xc =3D xc_interface_open(0, 0, 0); + xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0); + xc_gnttab_open(NULL, 0); + xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0); + xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000); + return 0; + } + +#else +#error invalid CONFIG_XEN_CTRL_INTERFACE_VERSION +#endif --=20 2.35.1