From patchwork Tue Jan 26 15:52:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 8124491 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 7F050BEEE5 for ; Tue, 26 Jan 2016 15:56:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DC65020260 for ; Tue, 26 Jan 2016 15:56:24 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2D1152025B for ; Tue, 26 Jan 2016 15:56:24 +0000 (UTC) Received: from localhost ([::1]:44787 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aO5yh-0005Fy-LF for patchwork-qemu-devel@patchwork.kernel.org; Tue, 26 Jan 2016 10:56:23 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53884) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aO5vA-0006fE-7i for qemu-devel@nongnu.org; Tue, 26 Jan 2016 10:52:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aO5v9-0000Eb-4E for qemu-devel@nongnu.org; Tue, 26 Jan 2016 10:52:44 -0500 Received: from smtp.citrix.com ([66.165.176.89]:34729) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aO5v8-0000DV-W8 for qemu-devel@nongnu.org; Tue, 26 Jan 2016 10:52:43 -0500 X-IronPort-AV: E=Sophos;i="5.22,350,1449532800"; d="scan'208";a="327722914" From: Stefano Stabellini To: Date: Tue, 26 Jan 2016 15:52:06 +0000 Message-ID: <1453823527-22312-7-git-send-email-stefano.stabellini@eu.citrix.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: MIME-Version: 1.0 X-DLP: MIA1 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 66.165.176.89 Cc: Ian Campbell , xen-devel@lists.xensource.com, qemu-devel@nongnu.org, Stefano Stabellini Subject: [Qemu-devel] [PULL 7/8] xen: domainbuild: reopen libxenctrl interface after forking for domain watcher. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Ian Campbell Using an existing libxenctrl handle after a fork was never particularly safe (especially if foreign mappings existed at the time of the fork) and the xc fd has been unavailable for many releases. Reopen the handle after fork and therefore do away with xc_fd(). Signed-off-by: Ian Campbell Acked-by: Stefano Stabellini --- hw/xenpv/xen_domainbuild.c | 9 ++++++--- include/hw/xen/xen_common.h | 17 ----------------- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/hw/xenpv/xen_domainbuild.c b/hw/xenpv/xen_domainbuild.c index ac0e5ac..f9be029 100644 --- a/hw/xenpv/xen_domainbuild.c +++ b/hw/xenpv/xen_domainbuild.c @@ -174,12 +174,15 @@ static int xen_domain_watcher(void) for (i = 3; i < n; i++) { if (i == fd[0]) continue; - if (i == xc_fd(xen_xc)) { - continue; - } close(i); } + /* + * Reopen xc interface, since the original is unsafe after fork + * and was closed above. + */ + xen_xc = xc_interface_open(0, 0, 0); + /* ignore term signals */ signal(SIGINT, SIG_IGN); signal(SIGTERM, SIG_IGN); diff --git a/include/hw/xen/xen_common.h b/include/hw/xen/xen_common.h index 19f1577..be7a915 100644 --- a/include/hw/xen/xen_common.h +++ b/include/hw/xen/xen_common.h @@ -116,12 +116,6 @@ static inline XenXC xen_xc_interface_open(void *logger, void *dombuild_logger, /* See below for xenforeignmemory_* APIs */ -static inline int xc_fd(int xen_xc) -{ - return xen_xc; -} - - static inline int xc_domain_populate_physmap_exact (XenXC xc_handle, uint32_t domid, unsigned long nr_extents, unsigned int extent_order, unsigned int mem_flags, xen_pfn_t *extent_start) @@ -193,11 +187,6 @@ static inline XenXC xen_xc_interface_open(void *logger, void *dombuild_logger, /* See below for xenforeignmemory_* APIs */ -/* FIXME There is no way to have the xen fd */ -static inline int xc_fd(xc_interface *xen_xc) -{ - return -1; -} #else /* CONFIG_XEN_CTRL_INTERFACE_VERSION >= 471 */ typedef xc_interface *XenXC; @@ -214,12 +203,6 @@ static inline XenXC xen_xc_interface_open(void *logger, void *dombuild_logger, { return xc_interface_open(logger, dombuild_logger, open_flags); } - -/* FIXME There is now way to have the xen fd */ -static inline int xc_fd(xc_interface *xen_xc) -{ - return -1; -} #endif /* Xen before 4.2 */