From nobody Sat May 4 17:12:16 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520530918510671.0371325010585; Thu, 8 Mar 2018 09:41:58 -0800 (PST) Received: from localhost ([::1]:40540 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1etzY7-0000Iv-LR for importer@patchew.org; Thu, 08 Mar 2018 12:41:51 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59842) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1etzW1-0007Q9-3P for qemu-devel@nongnu.org; Thu, 08 Mar 2018 12:39:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1etzW0-0008Js-0y for qemu-devel@nongnu.org; Thu, 08 Mar 2018 12:39:41 -0500 Received: from smtp.citrix.com ([66.165.176.89]:42122) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1etzVz-0008JW-OT for qemu-devel@nongnu.org; Thu, 08 Mar 2018 12:39:39 -0500 X-IronPort-AV: E=Sophos;i="5.47,441,1515456000"; d="scan'208";a="467104086" From: Ian Jackson To: Date: Thu, 8 Mar 2018 17:39:07 +0000 Message-ID: <1520530757-4477-2-git-send-email-ian.jackson@eu.citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1520530757-4477-1-git-send-email-ian.jackson@eu.citrix.com> References: <1520530757-4477-1-git-send-email-ian.jackson@eu.citrix.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 66.165.176.89 Subject: [Qemu-devel] [PATCH 01/11] xen: link against xentoolcore X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , Stefano Stabellini , Ian Jackson , Ross Lagerwall , Anthony PERARD , xen-devel@lists.xenproject.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Anthony PERARD Xen libraries in 4.10 include a new xentoolcore library. This contains the xentoolcore_restrict_all function which we are about to want to use. Signed-off-by: Ian Jackson Acked-by: Stefano Stabellini --- v5: More truthful commit message. --- configure | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/configure b/configure index 6f3921c..0a8059f 100755 --- a/configure +++ b/configure @@ -2179,7 +2179,7 @@ if test "$xen" !=3D "no" ; then $($pkg_config --modversion xencontrol | sed 's/\./ /g') )" xen=3Dyes xen_pc=3D"xencontrol xenstore xenguest xenforeignmemory xengnttab" - xen_pc=3D"$xen_pc xenevtchn xendevicemodel" + xen_pc=3D"$xen_pc xenevtchn xendevicemodel xentoolcore" QEMU_CFLAGS=3D"$QEMU_CFLAGS $($pkg_config --cflags $xen_pc)" libs_softmmu=3D"$($pkg_config --libs $xen_pc) $libs_softmmu" LDFLAGS=3D"$($pkg_config --libs $xen_pc) $LDFLAGS" @@ -2211,18 +2211,20 @@ EOF cat > $TMPC < +#include int main(void) { xenforeignmemory_handle *xfmem; =20 xfmem =3D xenforeignmemory_open(0, 0); xenforeignmemory_map2(xfmem, 0, 0, 0, 0, 0, 0, 0); + xentoolcore_restrict_all(0); =20 return 0; } EOF - compile_prog "" "$xen_libs -lxendevicemodel $xen_stable_libs" + compile_prog "" "$xen_libs -lxendevicemodel $xen_stable_libs -lxen= toolcore" then - xen_stable_libs=3D"-lxendevicemodel $xen_stable_libs" + xen_stable_libs=3D"-lxendevicemodel $xen_stable_libs -lxentoolcore" xen_ctrl_version=3D41000 xen=3Dyes elif --=20 2.1.4 From nobody Sat May 4 17:12:16 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520531469882603.0283875642474; Thu, 8 Mar 2018 09:51:09 -0800 (PST) Received: from localhost ([::1]:40591 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1etzh7-0007fI-5d for importer@patchew.org; Thu, 08 Mar 2018 12:51:09 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59921) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1etzW3-0007Qb-0L for qemu-devel@nongnu.org; Thu, 08 Mar 2018 12:39:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1etzW0-0008KO-BX for qemu-devel@nongnu.org; Thu, 08 Mar 2018 12:39:43 -0500 Received: from smtp.citrix.com ([66.165.176.89]:42122) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1etzW0-0008JW-4E for qemu-devel@nongnu.org; Thu, 08 Mar 2018 12:39:40 -0500 X-IronPort-AV: E=Sophos;i="5.47,441,1515456000"; d="scan'208";a="467104087" From: Ian Jackson To: Date: Thu, 8 Mar 2018 17:39:08 +0000 Message-ID: <1520530757-4477-3-git-send-email-ian.jackson@eu.citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1520530757-4477-1-git-send-email-ian.jackson@eu.citrix.com> References: <1520530757-4477-1-git-send-email-ian.jackson@eu.citrix.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 66.165.176.89 Subject: [Qemu-devel] [PATCH 02/11] xen: restrict: use xentoolcore_restrict_all X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , Stefano Stabellini , Ian Jackson , Ross Lagerwall , Anthony PERARD , xen-devel@lists.xenproject.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" And insist that it works. Drop individual use of xendevicemodel_restrict and xenforeignmemory_restrict. These are not actually effective in this version of qemu, because qemu has a large number of fds open onto various Xen control devices. The restriction arrangements are still not right, because the restriction needs to be done very late - after qemu has opened all of its control fds. xentoolcore_restrict_all and xentoolcore.h are available in Xen 4.10 and later, only. Provide a compatibility stub. And drop the compatibility stubs for the old functions. Signed-off-by: Ian Jackson Reviewed-by: Anthony PERARD Acked-by: Stefano Stabellini --- v2: Modify the compatibility code, too. Bump this patch ahead of "defer call to xen_restrict until running" Retain call to xentoolcore_restrict_all --- include/hw/xen/xen_common.h | 46 +++++++++++------------------------------= ---- 1 file changed, 11 insertions(+), 35 deletions(-) diff --git a/include/hw/xen/xen_common.h b/include/hw/xen/xen_common.h index 64a978e..1766bb9 100644 --- a/include/hw/xen/xen_common.h +++ b/include/hw/xen/xen_common.h @@ -91,6 +91,16 @@ static inline void *xenforeignmemory_map2(xenforeignmemo= ry_handle *h, return xenforeignmemory_map(h, dom, prot, pages, arr, err); } =20 +static inline int xentoolcore_restrict_all(domid_t domid) +{ + errno =3D ENOTTY; + return -1; +} + +#else /* CONFIG_XEN_CTRL_INTERFACE_VERSION >=3D 41000 */ + +#include + #endif =20 #if CONFIG_XEN_CTRL_INTERFACE_VERSION < 40900 @@ -218,20 +228,6 @@ static inline int xendevicemodel_set_mem_type( return xc_hvm_set_mem_type(dmod, domid, mem_type, first_pfn, nr); } =20 -static inline int xendevicemodel_restrict( - xendevicemodel_handle *dmod, domid_t domid) -{ - errno =3D ENOTTY; - return -1; -} - -static inline int xenforeignmemory_restrict( - xenforeignmemory_handle *fmem, domid_t domid) -{ - errno =3D ENOTTY; - return -1; -} - #else /* CONFIG_XEN_CTRL_INTERFACE_VERSION >=3D 40900 */ =20 #undef XC_WANT_COMPAT_DEVICEMODEL_API @@ -290,28 +286,8 @@ static inline int xen_modified_memory(domid_t domid, u= int64_t first_pfn, static inline int xen_restrict(domid_t domid) { int rc; - - /* Attempt to restrict devicemodel operations */ - rc =3D xendevicemodel_restrict(xen_dmod, domid); + rc =3D xentoolcore_restrict_all(domid); trace_xen_domid_restrict(rc ? errno : 0); - - if (rc < 0) { - /* - * If errno is ENOTTY then restriction is not implemented so - * there's no point in trying to restrict other types of - * operation, but it should not be treated as a failure. - */ - if (errno =3D=3D ENOTTY) { - return 0; - } - - return rc; - } - - /* Restrict foreignmemory operations */ - rc =3D xenforeignmemory_restrict(xen_fmem, domid); - trace_xen_domid_restrict(rc ? errno : 0); - return rc; } =20 --=20 2.1.4 From nobody Sat May 4 17:12:16 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520531328050399.68819039065875; Thu, 8 Mar 2018 09:48:48 -0800 (PST) Received: from localhost ([::1]:40576 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1etzek-0005bi-3O for importer@patchew.org; Thu, 08 Mar 2018 12:48:42 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59914) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1etzW2-0007Qa-SC for qemu-devel@nongnu.org; Thu, 08 Mar 2018 12:39:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1etzW1-0008Lt-1n for qemu-devel@nongnu.org; Thu, 08 Mar 2018 12:39:42 -0500 Received: from smtp.citrix.com ([66.165.176.89]:42122) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1etzW0-0008JW-Pa for qemu-devel@nongnu.org; Thu, 08 Mar 2018 12:39:40 -0500 X-IronPort-AV: E=Sophos;i="5.47,441,1515456000"; d="scan'208";a="467104089" From: Ian Jackson To: Date: Thu, 8 Mar 2018 17:39:09 +0000 Message-ID: <1520530757-4477-4-git-send-email-ian.jackson@eu.citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1520530757-4477-1-git-send-email-ian.jackson@eu.citrix.com> References: <1520530757-4477-1-git-send-email-ian.jackson@eu.citrix.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 66.165.176.89 Subject: [Qemu-devel] [PATCH 03/11] xen: defer call to xen_restrict until just before os_setup_post X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , Stefano Stabellini , Eduardo Habkost , "Michael S. Tsirkin" , Ian Jackson , Ross Lagerwall , Paolo Bonzini , Anthony PERARD , xen-devel@lists.xenproject.org, Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" We need to restrict *all* the control fds that qemu opens. Looking in /proc/PID/fd shows there are many; their allocation seems scattered throughout Xen support code in qemu. We must postpone the restrict call until roughly the same time as qemu changes its uid, chroots (if applicable), and so on. There doesn't seem to be an appropriate hook already. The RunState change hook fires at different times depending on exactly what mode qemu is operating in. And it appears that no-one but the Xen code wants a hook at this phase of execution. So, introduce a bare call to a new function xen_setup_post, just before os_setup_post. Also provide the appropriate stub for when Xen compilation is disabled. We do the restriction before rather than after os_setup_post, because xen_restrict may need to open /dev/null, and os_setup_post might have called chroot. Currently this does not work with migration, because when running as the Xen device model qemu needs to signal to the toolstack that it is ready. It currently does this using xenstore, and for incoming migration (but not for ordinary startup) that happens after os_setup_post. It is correct that this happens late: we want the incoming migration stream to be processed by a restricted qemu. The fix for this will be to do the startup notification a different way, without using xenstore. (QMP is probably a reasonable choice.) So for now this restriction feature cannot be used in conjunction with migration. (Note that this is not a regression in this patch, because previously the -xen-restrict-domid call was, in fact, simply ineffective!) We will revisit this in the Xen 4.11 release cycle. Signed-off-by: Ian Jackson Reviewed-by: Anthony PERARD CC: Paolo Bonzini (maintainer:X86) CC: Richard Henderson (maintainer:X86) CC: Eduardo Habkost (maintainer:X86) CC: Michael S. Tsirkin (supporter:PC) Reviewed-by: Eduardo Habkost reviewed-bys on some non-Xen specific patches: #7 #8 #11. --- v5: Discuss problems with migration startup notification in the commit message. v3: Do xen_setup_post just before, not just after, os_setup_post, to improve interaction with chroot. Thanks to Ross Lagerwall. Signed-off-by: Ian Jackson --- hw/i386/xen/xen-hvm.c | 8 -------- hw/xen/xen-common.c | 13 +++++++++++++ include/sysemu/sysemu.h | 2 ++ stubs/xen-hvm.c | 5 +++++ vl.c | 1 + 5 files changed, 21 insertions(+), 8 deletions(-) diff --git a/hw/i386/xen/xen-hvm.c b/hw/i386/xen/xen-hvm.c index f24b7d4..9c3b6b3 100644 --- a/hw/i386/xen/xen-hvm.c +++ b/hw/i386/xen/xen-hvm.c @@ -1254,14 +1254,6 @@ void xen_hvm_init(PCMachineState *pcms, MemoryRegion= **ram_memory) goto err; } =20 - if (xen_domid_restrict) { - rc =3D xen_restrict(xen_domid); - if (rc < 0) { - error_report("failed to restrict: error %d", errno); - goto err; - } - } - xen_create_ioreq_server(xen_domid, &state->ioservid); =20 state->exit.notify =3D xen_exit_notifier; diff --git a/hw/xen/xen-common.c b/hw/xen/xen-common.c index 83099dd..f73b416 100644 --- a/hw/xen/xen-common.c +++ b/hw/xen/xen-common.c @@ -117,6 +117,19 @@ static void xen_change_state_handler(void *opaque, int= running, } } =20 +void xen_setup_post(void) +{ + int rc; + + if (xen_domid_restrict) { + rc =3D xen_restrict(xen_domid); + if (rc < 0) { + perror("xen: failed to restrict"); + exit(1); + } + } +} + static int xen_init(MachineState *ms) { xen_xc =3D xc_interface_open(0, 0, 0); diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index d24ad09..6b785a4 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -92,6 +92,8 @@ void qemu_remove_machine_init_done_notifier(Notifier *not= ify); =20 void qemu_announce_self(void); =20 +void xen_setup_post(void); + extern int autostart; =20 typedef enum { diff --git a/stubs/xen-hvm.c b/stubs/xen-hvm.c index 0067bcc..48ca8da 100644 --- a/stubs/xen-hvm.c +++ b/stubs/xen-hvm.c @@ -13,6 +13,7 @@ #include "hw/xen/xen.h" #include "exec/memory.h" #include "qapi/qapi-commands-misc.h" +#include "sysemu/sysemu.h" =20 int xen_pci_slot_get_pirq(PCIDevice *pci_dev, int irq_num) { @@ -61,3 +62,7 @@ void xen_hvm_init(PCMachineState *pcms, MemoryRegion **ra= m_memory) void qmp_xen_set_global_dirty_log(bool enable, Error **errp) { } + +void xen_setup_post(void) +{ +} diff --git a/vl.c b/vl.c index dae986b..e6e8e1e 100644 --- a/vl.c +++ b/vl.c @@ -4719,6 +4719,7 @@ int main(int argc, char **argv, char **envp) vm_start(); } =20 + xen_setup_post(); os_setup_post(); =20 main_loop(); --=20 2.1.4 From nobody Sat May 4 17:12:16 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520530915510486.6053228426613; Thu, 8 Mar 2018 09:41:55 -0800 (PST) Received: from localhost ([::1]:40541 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1etzY8-0000L4-TM for importer@patchew.org; Thu, 08 Mar 2018 12:41:52 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59869) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1etzW1-0007QD-U0 for qemu-devel@nongnu.org; Thu, 08 Mar 2018 12:39:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1etzW0-0008LB-NM for qemu-devel@nongnu.org; Thu, 08 Mar 2018 12:39:41 -0500 Received: from smtp.citrix.com ([66.165.176.89]:42122) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1etzW0-0008JW-GC for qemu-devel@nongnu.org; Thu, 08 Mar 2018 12:39:40 -0500 X-IronPort-AV: E=Sophos;i="5.47,441,1515456000"; d="scan'208";a="467104088" From: Ian Jackson To: Date: Thu, 8 Mar 2018 17:39:10 +0000 Message-ID: <1520530757-4477-5-git-send-email-ian.jackson@eu.citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1520530757-4477-1-git-send-email-ian.jackson@eu.citrix.com> References: <1520530757-4477-1-git-send-email-ian.jackson@eu.citrix.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 66.165.176.89 Subject: [Qemu-devel] [PATCH 04/11] xen: destroy_hvm_domain: Move reason into a variable X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , Stefano Stabellini , Ian Jackson , Ross Lagerwall , Anthony PERARD , xen-devel@lists.xenproject.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" We are going to want to reuse this. No functional change. Signed-off-by: Ian Jackson Reviewed-by: Anthony PERARD Acked-by: Stefano Stabellini --- hw/i386/xen/xen-hvm.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/hw/i386/xen/xen-hvm.c b/hw/i386/xen/xen-hvm.c index 9c3b6b3..3590d99 100644 --- a/hw/i386/xen/xen-hvm.c +++ b/hw/i386/xen/xen-hvm.c @@ -1387,12 +1387,13 @@ void destroy_hvm_domain(bool reboot) xc_interface *xc_handle; int sts; =20 + unsigned int reason =3D reboot ? SHUTDOWN_reboot : SHUTDOWN_poweroff; + xc_handle =3D xc_interface_open(0, 0, 0); if (xc_handle =3D=3D NULL) { fprintf(stderr, "Cannot acquire xenctrl handle\n"); } else { - sts =3D xc_domain_shutdown(xc_handle, xen_domid, - reboot ? SHUTDOWN_reboot : SHUTDOWN_power= off); + sts =3D xc_domain_shutdown(xc_handle, xen_domid, reason); if (sts !=3D 0) { fprintf(stderr, "xc_domain_shutdown failed to issue %s, " "sts %d, %s\n", reboot ? "reboot" : "poweroff", --=20 2.1.4 From nobody Sat May 4 17:12:16 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520531172642784.9704148038921; Thu, 8 Mar 2018 09:46:12 -0800 (PST) Received: from localhost ([::1]:40567 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1etzcJ-00049f-5S for importer@patchew.org; Thu, 08 Mar 2018 12:46:11 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59888) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1etzW2-0007QJ-BK for qemu-devel@nongnu.org; Thu, 08 Mar 2018 12:39:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1etzW1-0008Ll-0e for qemu-devel@nongnu.org; Thu, 08 Mar 2018 12:39:42 -0500 Received: from smtp.citrix.com ([66.165.176.89]:31749) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1etzW0-0008KY-PI for qemu-devel@nongnu.org; Thu, 08 Mar 2018 12:39:40 -0500 X-IronPort-AV: E=Sophos;i="5.47,441,1515456000"; d="scan'208";a="467104090" From: Ian Jackson To: Date: Thu, 8 Mar 2018 17:39:11 +0000 Message-ID: <1520530757-4477-6-git-send-email-ian.jackson@eu.citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1520530757-4477-1-git-send-email-ian.jackson@eu.citrix.com> References: <1520530757-4477-1-git-send-email-ian.jackson@eu.citrix.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 66.165.176.89 Subject: [Qemu-devel] [PATCH 05/11] xen: move xc_interface compatibility fallback further up the file X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , Stefano Stabellini , Ian Jackson , Ross Lagerwall , Anthony PERARD , xen-devel@lists.xenproject.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" We are going to want to use the dummy xendevicemodel_handle type in new stub functions in the CONFIG_XEN_CTRL_INTERFACE_VERSION < 41000 section. So we need to provide that definition, or (as applicable) include the appropriate header, earlier in the file. (Ideally the newer compatibility layers would be at the bottom of the file, so that they can naturally benefit from the compatibility layers for earlier version. But that's rather too much for this series.) No functional change. Signed-off-by: Ian Jackson Acked-by: Anthony PERARD Acked-by: Stefano Stabellini --- v2: New patch in v2 of the series --- include/hw/xen/xen_common.h | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/include/hw/xen/xen_common.h b/include/hw/xen/xen_common.h index 1766bb9..60c4ebb 100644 --- a/include/hw/xen/xen_common.h +++ b/include/hw/xen/xen_common.h @@ -78,6 +78,17 @@ static inline void *xenforeignmemory_map(xc_interface *h= , uint32_t dom, =20 extern xenforeignmemory_handle *xen_fmem; =20 +#if CONFIG_XEN_CTRL_INTERFACE_VERSION < 40900 + +typedef xc_interface xendevicemodel_handle; + +#else /* CONFIG_XEN_CTRL_INTERFACE_VERSION >=3D 40900 */ + +#undef XC_WANT_COMPAT_DEVICEMODEL_API +#include + +#endif + #if CONFIG_XEN_CTRL_INTERFACE_VERSION < 41000 =20 #define XEN_COMPAT_PHYSMAP @@ -105,8 +116,6 @@ static inline int xentoolcore_restrict_all(domid_t domi= d) =20 #if CONFIG_XEN_CTRL_INTERFACE_VERSION < 40900 =20 -typedef xc_interface xendevicemodel_handle; - static inline xendevicemodel_handle *xendevicemodel_open( struct xentoollog_logger *logger, unsigned int open_flags) { @@ -228,11 +237,6 @@ static inline int xendevicemodel_set_mem_type( return xc_hvm_set_mem_type(dmod, domid, mem_type, first_pfn, nr); } =20 -#else /* CONFIG_XEN_CTRL_INTERFACE_VERSION >=3D 40900 */ - -#undef XC_WANT_COMPAT_DEVICEMODEL_API -#include - #endif =20 extern xendevicemodel_handle *xen_dmod; --=20 2.1.4 From nobody Sat May 4 17:12:16 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 152053117107322.01550495873107; Thu, 8 Mar 2018 09:46:11 -0800 (PST) Received: from localhost ([::1]:40566 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1etzcI-00047j-CK for importer@patchew.org; Thu, 08 Mar 2018 12:46:10 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59882) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1etzW2-0007QI-98 for qemu-devel@nongnu.org; Thu, 08 Mar 2018 12:39:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1etzW1-0008MX-Cr for qemu-devel@nongnu.org; Thu, 08 Mar 2018 12:39:42 -0500 Received: from smtp.citrix.com ([66.165.176.89]:31749) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1etzW1-0008KY-39 for qemu-devel@nongnu.org; Thu, 08 Mar 2018 12:39:41 -0500 X-IronPort-AV: E=Sophos;i="5.47,441,1515456000"; d="scan'208";a="467104091" From: Ian Jackson To: Date: Thu, 8 Mar 2018 17:39:12 +0000 Message-ID: <1520530757-4477-7-git-send-email-ian.jackson@eu.citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1520530757-4477-1-git-send-email-ian.jackson@eu.citrix.com> References: <1520530757-4477-1-git-send-email-ian.jackson@eu.citrix.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 66.165.176.89 Subject: [Qemu-devel] [PATCH 06/11] xen: destroy_hvm_domain: Try xendevicemodel_shutdown X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , Stefano Stabellini , Ian Jackson , Ross Lagerwall , Anthony PERARD , xen-devel@lists.xenproject.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" xc_interface_open etc. is not going to work if we have dropped privilege, but xendevicemodel_shutdown will if everything is new enough. xendevicemodel_shutdown is only availabe in Xen 4.10 and later, so provide a stub for earlier versions. Signed-off-by: Ian Jackson Reviewed-by: Anthony PERARD --- v6: Do not print message about harmless condition in ENOTTY case. v2: Add compatibility stub for Xen < 4.10. Fix coding style. Signed-off-by: Ian Jackson --- hw/i386/xen/xen-hvm.c | 11 +++++++++++ include/hw/xen/xen_common.h | 7 +++++++ 2 files changed, 18 insertions(+) diff --git a/hw/i386/xen/xen-hvm.c b/hw/i386/xen/xen-hvm.c index 3590d99..b95748d 100644 --- a/hw/i386/xen/xen-hvm.c +++ b/hw/i386/xen/xen-hvm.c @@ -1386,9 +1386,20 @@ void destroy_hvm_domain(bool reboot) { xc_interface *xc_handle; int sts; + int rc; =20 unsigned int reason =3D reboot ? SHUTDOWN_reboot : SHUTDOWN_poweroff; =20 + if (xen_dmod) { + rc =3D xendevicemodel_shutdown(xen_dmod, xen_domid, reason); + if (!rc) { + return; + } + if (errno !=3D ENOTTY /* old Xen */) + perror("xendevicemodel_shutdown failed"); + /* well, try the old thing then */ + } + xc_handle =3D xc_interface_open(0, 0, 0); if (xc_handle =3D=3D NULL) { fprintf(stderr, "Cannot acquire xenctrl handle\n"); diff --git a/include/hw/xen/xen_common.h b/include/hw/xen/xen_common.h index 60c4ebb..4bd30a3 100644 --- a/include/hw/xen/xen_common.h +++ b/include/hw/xen/xen_common.h @@ -108,6 +108,13 @@ static inline int xentoolcore_restrict_all(domid_t dom= id) return -1; } =20 +static inline int xendevicemodel_shutdown(xendevicemodel_handle *dmod, + domid_t domid, unsigned int reas= on) +{ + errno =3D ENOTTY; + return -1; +} + #else /* CONFIG_XEN_CTRL_INTERFACE_VERSION >=3D 41000 */ =20 #include --=20 2.1.4 From nobody Sat May 4 17:12:16 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520531060570757.8214688521897; Thu, 8 Mar 2018 09:44:20 -0800 (PST) Received: from localhost ([::1]:40554 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1etzaV-0002Vo-Qe for importer@patchew.org; Thu, 08 Mar 2018 12:44:19 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59902) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1etzW2-0007QM-Ih for qemu-devel@nongnu.org; Thu, 08 Mar 2018 12:39:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1etzW1-0008MZ-CC for qemu-devel@nongnu.org; Thu, 08 Mar 2018 12:39:42 -0500 Received: from smtp.citrix.com ([66.165.176.89]:42122) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1etzW1-0008JW-3h for qemu-devel@nongnu.org; Thu, 08 Mar 2018 12:39:41 -0500 X-IronPort-AV: E=Sophos;i="5.47,441,1515456000"; d="scan'208";a="467104094" From: Ian Jackson To: Date: Thu, 8 Mar 2018 17:39:13 +0000 Message-ID: <1520530757-4477-8-git-send-email-ian.jackson@eu.citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1520530757-4477-1-git-send-email-ian.jackson@eu.citrix.com> References: <1520530757-4477-1-git-send-email-ian.jackson@eu.citrix.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 66.165.176.89 Subject: [Qemu-devel] [PATCH 07/11] os-posix: Provide new -runas : facility X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , Stefano Stabellini , Ian Jackson , Markus Armbruster , Ross Lagerwall , Paolo Bonzini , Anthony PERARD , xen-devel@lists.xenproject.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This allows the caller to specify a uid and gid to use, even if there is no corresponding password entry. This will be useful in certain Xen configurations. We don't support just -runas because: (i) deprivileging without calling setgroups would be ineffective (ii) given only a uid we don't know what gid we ought to use (since uids may eppear in multiple passwd file entries with different gids). Signed-off-by: Ian Jackson Reviewed-by: Anthony PERARD CC: Paolo Bonzini CC: Markus Armbruster CC: Daniel P. Berrange --- v6: Use qemu_strtoul for the first strtoul. Use error_report rather than fprintf to print usage error message. Fix an error message which still referred to . rather than : v5: Use : rather than . to separate uid from gid v4: Changed to reuse option -runas v3: Error messages fixed. Thanks to Peter Maydell and Ross Lagerwall. v2: Coding style fixes. Signed-off-by: Ian Jackson --- os-posix.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++------= ---- qemu-options.hx | 3 ++- 2 files changed, 53 insertions(+), 12 deletions(-) diff --git a/os-posix.c b/os-posix.c index b9c2343..32d7cf0 100644 --- a/os-posix.c +++ b/os-posix.c @@ -42,6 +42,8 @@ #endif =20 static struct passwd *user_pwd; +static uid_t user_uid =3D (uid_t)-1; +static gid_t user_gid =3D (gid_t)-1; static const char *chroot_dir; static int daemonize; static int daemon_pipe; @@ -127,6 +129,34 @@ void os_set_proc_name(const char *s) #endif } =20 + +static bool os_parse_runas_uid_gid(const char *optarg) +{ + unsigned long lv; + char *ep; + uid_t got_uid; + gid_t got_gid; + int rc; + + errno =3D 0; + rc =3D qemu_strtoul(optarg, &ep, 0, &lv); + got_uid =3D lv; /* overflow here is ID in C99 */ + if (rc || *ep !=3D ':' || got_uid !=3D lv || got_uid =3D=3D (uid_t)-1)= { + return false; + } + + lv =3D 0; + rc =3D qemu_strtoul(ep + 1, 0, 0, &lv); + got_gid =3D lv; /* overflow here is ID in C99 */ + if (rc || got_gid !=3D lv || got_gid =3D=3D (gid_t)-1) { + return false; + } + + user_uid =3D got_uid; + user_gid =3D got_gid; + return true; +} + /* * Parse OS specific command line options. * return 0 if option handled, -1 otherwise @@ -144,8 +174,8 @@ void os_parse_cmd_args(int index, const char *optarg) #endif case QEMU_OPTION_runas: user_pwd =3D getpwnam(optarg); - if (!user_pwd) { - fprintf(stderr, "User \"%s\" doesn't exist\n", optarg); + if (!user_pwd && !os_parse_runas_uid_gid(optarg)) { + error_report("User doesn't exist (and is not :)"); exit(1); } break; @@ -165,18 +195,28 @@ void os_parse_cmd_args(int index, const char *optarg) =20 static void change_process_uid(void) { - if (user_pwd) { - if (setgid(user_pwd->pw_gid) < 0) { - fprintf(stderr, "Failed to setgid(%d)\n", user_pwd->pw_gid); + if (user_pwd || user_uid !=3D (uid_t)-1) { + gid_t intended_gid =3D user_pwd ? user_pwd->pw_gid : user_gid; + uid_t intended_uid =3D user_pwd ? user_pwd->pw_uid : user_uid; + if (setgid(intended_gid) < 0) { + fprintf(stderr, "Failed to setgid(%d)\n", intended_gid); exit(1); } - if (initgroups(user_pwd->pw_name, user_pwd->pw_gid) < 0) { - fprintf(stderr, "Failed to initgroups(\"%s\", %d)\n", - user_pwd->pw_name, user_pwd->pw_gid); - exit(1); + if (user_pwd) { + if (initgroups(user_pwd->pw_name, user_pwd->pw_gid) < 0) { + fprintf(stderr, "Failed to initgroups(\"%s\", %d)\n", + user_pwd->pw_name, user_pwd->pw_gid); + exit(1); + } + } else { + if (setgroups(1, &user_gid) < 0) { + fprintf(stderr, "Failed to setgroups(1, [%d])", + user_gid); + exit(1); + } } - if (setuid(user_pwd->pw_uid) < 0) { - fprintf(stderr, "Failed to setuid(%d)\n", user_pwd->pw_uid); + if (setuid(intended_uid) < 0) { + fprintf(stderr, "Failed to setuid(%d)\n", intended_uid); exit(1); } if (setuid(0) !=3D -1) { diff --git a/qemu-options.hx b/qemu-options.hx index 6585058..211f2a6 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -3763,7 +3763,8 @@ ETEXI =20 #ifndef _WIN32 DEF("runas", HAS_ARG, QEMU_OPTION_runas, \ - "-runas user change to user id user just before starting the VM\n", + "-runas user change to user id user just before starting the VM\n"= \ + " user can be numeric uid:gid instead\n", QEMU_ARCH_ALL) #endif STEXI --=20 2.1.4 From nobody Sat May 4 17:12:16 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520530918354436.1396133532321; Thu, 8 Mar 2018 09:41:58 -0800 (PST) Received: from localhost ([::1]:40543 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1etzYA-0000MQ-Cu for importer@patchew.org; Thu, 08 Mar 2018 12:41:54 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59913) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1etzW2-0007QZ-Rk for qemu-devel@nongnu.org; Thu, 08 Mar 2018 12:39:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1etzW1-0008Mm-Ki for qemu-devel@nongnu.org; Thu, 08 Mar 2018 12:39:42 -0500 Received: from smtp.citrix.com ([66.165.176.89]:31749) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1etzW1-0008KY-DL for qemu-devel@nongnu.org; Thu, 08 Mar 2018 12:39:41 -0500 X-IronPort-AV: E=Sophos;i="5.47,441,1515456000"; d="scan'208";a="467104095" From: Ian Jackson To: Date: Thu, 8 Mar 2018 17:39:14 +0000 Message-ID: <1520530757-4477-9-git-send-email-ian.jackson@eu.citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1520530757-4477-1-git-send-email-ian.jackson@eu.citrix.com> References: <1520530757-4477-1-git-send-email-ian.jackson@eu.citrix.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 66.165.176.89 Subject: [Qemu-devel] [PATCH 08/11] configure: do_compiler: Dump some extra info under bash X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , Janosch Frank , Thomas Huth , Stefano Stabellini , Peter Maydell , "Kent R. Spillner" , Ian Jackson , Ross Lagerwall , Paolo Bonzini , Anthony PERARD , xen-devel@lists.xenproject.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This makes it much easier to find a particular thing in config.log. The information may be lacking in other shells, resulting in harmless empty output. (This is why we don't use the proper ${FUNCNAME[*]} array syntax - other shells will choke on that.) The extra output is only printed if configure is run with bash. On systems where /bin/sh is not bash, it is necessary to say bash ./configure to get the extra debug info in the log. Signed-off-by: Ian Jackson CC: Kent R. Spillner CC: Janosch Frank CC: Thomas Huth CC: Peter Maydell CC: Paolo Bonzini --- v6: Fix commit message wording. v4: No longer tag this patch RFC. --- configure | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/configure b/configure index 0a8059f..841c146 100755 --- a/configure +++ b/configure @@ -60,6 +60,10 @@ do_compiler() { # is compiler binary to execute. local compiler=3D"$1" shift + echo >>config.log " +funcs: ${FUNCNAME} +lines: ${BASH_LINENO} +files: ${BASH_SOURCE}" echo $compiler "$@" >> config.log $compiler "$@" >> config.log 2>&1 || return $? # Test passed. If this is an --enable-werror build, rerun --=20 2.1.4 From nobody Sat May 4 17:12:16 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520530915951387.78452377969813; Thu, 8 Mar 2018 09:41:55 -0800 (PST) Received: from localhost ([::1]:40542 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1etzY9-0000LE-DM for importer@patchew.org; Thu, 08 Mar 2018 12:41:53 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59838) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1etzW1-0007Q6-1t for qemu-devel@nongnu.org; Thu, 08 Mar 2018 12:39:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1etzVw-0008HR-M0 for qemu-devel@nongnu.org; Thu, 08 Mar 2018 12:39:41 -0500 Received: from smtp.citrix.com ([66.165.176.89]:50174) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1etzVw-0008H2-DE for qemu-devel@nongnu.org; Thu, 08 Mar 2018 12:39:36 -0500 X-IronPort-AV: E=Sophos;i="5.47,441,1515456000"; d="scan'208";a="467104075" From: Ian Jackson To: Date: Thu, 8 Mar 2018 17:39:15 +0000 Message-ID: <1520530757-4477-10-git-send-email-ian.jackson@eu.citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1520530757-4477-1-git-send-email-ian.jackson@eu.citrix.com> References: <1520530757-4477-1-git-send-email-ian.jackson@eu.citrix.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 66.165.176.89 Subject: [Qemu-devel] [PATCH 09/11] xen: Use newly added dmops for mapping VGA memory X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , Stefano Stabellini , Ian Jackson , Ross Lagerwall , Anthony PERARD , xen-devel@lists.xenproject.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ross Lagerwall Xen unstable (to be in 4.11) has two new dmops, relocate_memory and pin_memory_cacheattr. Use these to set up the VGA memory, replacing the previous calls to libxc. This allows the VGA console to work properly when QEMU is running restricted (-xen-domid-restrict). Wrapper functions are provided to allow QEMU to work with older versions of Xen. Tweak the error handling while making this change: * Report pin_memory_cacheattr errors. * Report errors even when DEBUG_HVM is not set. This is useful for trying to understand why VGA is not working, since otherwise it just fails silently. * Fix the return values when an error occurs. The functions now consistently return -1 and set errno. CC: Ian Jackson Signed-off-by: Ross Lagerwall Reviewed-by: Ian Jackson --- v6: New patch in this version of the series --- configure | 19 ++++++++++++++++++ hw/i386/xen/xen-hvm.c | 49 ++++++++++++++++++++++++-----------------= ---- include/hw/xen/xen_common.h | 31 ++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 23 deletions(-) diff --git a/configure b/configure index 841c146..9a83836 100755 --- a/configure +++ b/configure @@ -2213,6 +2213,25 @@ EOF # Xen unstable elif cat > $TMPC < +int main(void) { + xendevicemodel_handle *xd; + + xd =3D xendevicemodel_open(0, 0); + xendevicemodel_pin_memory_cacheattr(xd, 0, 0, 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=3Dyes + elif + cat > $TMPC < #include diff --git a/hw/i386/xen/xen-hvm.c b/hw/i386/xen/xen-hvm.c index b95748d..22bd537 100644 --- a/hw/i386/xen/xen-hvm.c +++ b/hw/i386/xen/xen-hvm.c @@ -347,7 +347,7 @@ static int xen_add_to_physmap(XenIOState *state, MemoryRegion *mr, hwaddr offset_within_region) { - unsigned long i =3D 0; + unsigned long nr_pages; int rc =3D 0; XenPhysmap *physmap =3D NULL; hwaddr pfn, start_gpfn; @@ -396,22 +396,26 @@ go_physmap: =20 pfn =3D phys_offset >> TARGET_PAGE_BITS; start_gpfn =3D start_addr >> TARGET_PAGE_BITS; - for (i =3D 0; i < size >> TARGET_PAGE_BITS; i++) { - unsigned long idx =3D pfn + i; - xen_pfn_t gpfn =3D start_gpfn + i; - - rc =3D xen_xc_domain_add_to_physmap(xen_xc, xen_domid, XENMAPSPACE= _gmfn, idx, gpfn); - if (rc) { - DPRINTF("add_to_physmap MFN %"PRI_xen_pfn" to PFN %" - PRI_xen_pfn" failed: %d (errno: %d)\n", idx, gpfn, rc,= errno); - return -rc; - } + nr_pages =3D size >> TARGET_PAGE_BITS; + rc =3D xendevicemodel_relocate_memory(xen_dmod, xen_domid, nr_pages, p= fn, + start_gpfn); + if (rc) { + int saved_errno =3D errno; + + error_report("relocate_memory %lu pages from GFN %"PRI_xen_pfn + " to GFN %"PRI_xen_pfn" failed: %s\n", + nr_pages, pfn, start_gpfn, strerror(saved_errno)); + errno =3D saved_errno; + return -1; } =20 - xc_domain_pin_memory_cacheattr(xen_xc, xen_domid, + rc =3D xendevicemodel_pin_memory_cacheattr(xen_dmod, xen_domid, start_addr >> TARGET_PAGE_BITS, (start_addr + size - 1) >> TARGET_PAGE_= BITS, XEN_DOMCTL_MEM_CACHEATTR_WB); + if (rc) { + error_report("pin_memory_cacheattr failed: %s\n", strerror(errno)); + } return xen_save_physmap(state, physmap); } =20 @@ -419,7 +423,6 @@ static int xen_remove_from_physmap(XenIOState *state, hwaddr start_addr, ram_addr_t size) { - unsigned long i =3D 0; int rc =3D 0; XenPhysmap *physmap =3D NULL; hwaddr phys_offset =3D 0; @@ -438,16 +441,16 @@ static int xen_remove_from_physmap(XenIOState *state, size >>=3D TARGET_PAGE_BITS; start_addr >>=3D TARGET_PAGE_BITS; phys_offset >>=3D TARGET_PAGE_BITS; - for (i =3D 0; i < size; i++) { - xen_pfn_t idx =3D start_addr + i; - xen_pfn_t gpfn =3D phys_offset + i; - - rc =3D xen_xc_domain_add_to_physmap(xen_xc, xen_domid, XENMAPSPACE= _gmfn, idx, gpfn); - if (rc) { - fprintf(stderr, "add_to_physmap MFN %"PRI_xen_pfn" to PFN %" - PRI_xen_pfn" failed: %d (errno: %d)\n", idx, gpfn, rc,= errno); - return -rc; - } + rc =3D xendevicemodel_relocate_memory(xen_dmod, xen_domid, size, start= _addr, + phys_offset); + if (rc) { + int saved_errno =3D errno; + + error_report("relocate_memory %lu pages from GFN %"PRI_xen_pfn + " to GFN %"PRI_xen_pfn" failed: %s\n", + size, start_addr, phys_offset, strerror(saved_errno)); + errno =3D saved_errno; + return -1; } =20 QLIST_REMOVE(physmap, list); diff --git a/include/hw/xen/xen_common.h b/include/hw/xen/xen_common.h index 4bd30a3..a236eb1 100644 --- a/include/hw/xen/xen_common.h +++ b/include/hw/xen/xen_common.h @@ -89,6 +89,37 @@ typedef xc_interface xendevicemodel_handle; =20 #endif =20 +#if CONFIG_XEN_CTRL_INTERFACE_VERSION < 41100 + +static inline int xendevicemodel_relocate_memory( + xendevicemodel_handle *dmod, domid_t domid, uint32_t size, uint64_t sr= c_gfn, + uint64_t dst_gfn) +{ + uint32_t i; + int rc; + + for (i =3D 0; i < size; i++) { + unsigned long idx =3D src_gfn + i; + xen_pfn_t gpfn =3D dst_gfn + i; + + rc =3D xc_domain_add_to_physmap(xen_xc, domid, XENMAPSPACE_gmfn, i= dx, + gpfn); + if (rc) + return rc; + } + + return 0; +} + +static inline int xendevicemodel_pin_memory_cacheattr( + xendevicemodel_handle *dmod, domid_t domid, uint64_t start, uint64_t e= nd, + uint32_t type) +{ + return xc_domain_pin_memory_cacheattr(xen_xc, domid, start, end, type); +} + +#endif /* CONFIG_XEN_CTRL_INTERFACE_VERSION < 41100 */ + #if CONFIG_XEN_CTRL_INTERFACE_VERSION < 41000 =20 #define XEN_COMPAT_PHYSMAP --=20 2.1.4 From nobody Sat May 4 17:12:16 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520531059916118.04044798599966; Thu, 8 Mar 2018 09:44:19 -0800 (PST) Received: from localhost ([::1]:40553 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1etzaR-0002SP-ON for importer@patchew.org; Thu, 08 Mar 2018 12:44:15 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59840) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1etzW1-0007Q7-2s for qemu-devel@nongnu.org; Thu, 08 Mar 2018 12:39:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1etzVw-0008HH-Do for qemu-devel@nongnu.org; Thu, 08 Mar 2018 12:39:41 -0500 Received: from smtp.citrix.com ([66.165.176.89]:44779) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1etzVw-0008GN-7L for qemu-devel@nongnu.org; Thu, 08 Mar 2018 12:39:36 -0500 X-IronPort-AV: E=Sophos;i="5.47,441,1515456000"; d="scan'208";a="467104074" From: Ian Jackson To: Date: Thu, 8 Mar 2018 17:39:16 +0000 Message-ID: <1520530757-4477-11-git-send-email-ian.jackson@eu.citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1520530757-4477-1-git-send-email-ian.jackson@eu.citrix.com> References: <1520530757-4477-1-git-send-email-ian.jackson@eu.citrix.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 66.165.176.89 Subject: [Qemu-devel] [PATCH 10/11] xen: Expect xenstore write to fail when restricted X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , Stefano Stabellini , Ian Jackson , Ross Lagerwall , Anthony PERARD , xen-devel@lists.xenproject.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ross Lagerwall Saving the current state to xenstore may fail when running restricted (in particular, after a migration). Therefore, don't report the error or exit when running restricted. Toolstacks that want to allow running QEMU restricted should instead make use of QMP events to listen for state changes. CC: Ian Jackson Signed-off-by: Ross Lagerwall Reviewed-by: Ian Jackson --- v6: New patch in this version of the series --- hw/xen/xen-common.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/hw/xen/xen-common.c b/hw/xen/xen-common.c index f73b416..8ede246 100644 --- a/hw/xen/xen-common.c +++ b/hw/xen/xen-common.c @@ -101,7 +101,12 @@ static void xenstore_record_dm_state(struct xs_handle = *xs, const char *state) } =20 snprintf(path, sizeof (path), "device-model/%u/state", xen_domid); - if (!xs_write(xs, XBT_NULL, path, state, strlen(state))) { + /* + * This call may fail when running restricted so don't make it fatal in + * that case. Toolstacks should instead use QMP to listen for state ch= anges. + */ + if (!xs_write(xs, XBT_NULL, path, state, strlen(state)) && + !xen_domid_restrict) { error_report("error recording dm state"); exit(1); } --=20 2.1.4 From nobody Sat May 4 17:12:16 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 152053132798244.931721529431684; Thu, 8 Mar 2018 09:48:47 -0800 (PST) Received: from localhost ([::1]:40575 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1etzej-0005b8-3g for importer@patchew.org; Thu, 08 Mar 2018 12:48:41 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59923) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1etzW3-0007Qc-1h for qemu-devel@nongnu.org; Thu, 08 Mar 2018 12:39:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1etzW1-0008Mr-Lv for qemu-devel@nongnu.org; Thu, 08 Mar 2018 12:39:43 -0500 Received: from smtp.citrix.com ([66.165.176.89]:42122) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1etzW1-0008JW-Dx for qemu-devel@nongnu.org; Thu, 08 Mar 2018 12:39:41 -0500 X-IronPort-AV: E=Sophos;i="5.47,441,1515456000"; d="scan'208";a="467104098" From: Ian Jackson To: Date: Thu, 8 Mar 2018 17:39:17 +0000 Message-ID: <1520530757-4477-12-git-send-email-ian.jackson@eu.citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1520530757-4477-1-git-send-email-ian.jackson@eu.citrix.com> References: <1520530757-4477-1-git-send-email-ian.jackson@eu.citrix.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 66.165.176.89 Subject: [Qemu-devel] [PATCH 11/11] scripts/get_maintainer.pl: Print proper error message for missing $file X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , Thomas Huth , Stefano Stabellini , Ian Jackson , Ross Lagerwall , Paolo Bonzini , Anthony PERARD , xen-devel@lists.xenproject.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" If you pass scripts/get_maintainer.pl the name of a FIFO or other exciting object (/dev/stdin, for example), it would falsely print "file not found". Instead: stat the object rather than using -f so that we do not mind if the object is not a file; and print the errno value in the error message. Signed-off-by: Ian Jackson CC: Thomas Huth CC: Paolo Bonzini CC: Stefano Stabellini CC: Anthony PERARD --- v6: New patch in this version of the series --- scripts/get_maintainer.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/get_maintainer.pl b/scripts/get_maintainer.pl index 07369aa..43fb5f5 100755 --- a/scripts/get_maintainer.pl +++ b/scripts/get_maintainer.pl @@ -381,8 +381,8 @@ foreach my $file (@ARGV) { ##if $file is a directory and it lacks a trailing slash, add one if ((-d $file)) { $file =3D~ s@([^/])$@$1/@; - } elsif (!(-f $file)) { - die "$P: file '${file}' not found\n"; + } elsif (!(stat $file)) { + die "$P: file '${file}' not found: $!\n"; } } if ($from_filename) { --=20 2.1.4