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: 8124461 Return-Path: X-Original-To: patchwork-xen-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 DFF9FBEEE5 for ; Tue, 26 Jan 2016 15:55:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6B55F201F2 for ; Tue, 26 Jan 2016 15:55:13 +0000 (UTC) Received: from lists.xen.org (lists.xenproject.org [50.57.142.19]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 51CBF2011E for ; Tue, 26 Jan 2016 15:55:08 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aO5vB-0000Ob-VS; Tue, 26 Jan 2016 15:52:45 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aO5vA-0000N7-9d for xen-devel@lists.xensource.com; Tue, 26 Jan 2016 15:52:44 +0000 Received: from [85.158.139.211] by server-1.bemta-5.messagelabs.com id FA/10-15353-B4697A65; Tue, 26 Jan 2016 15:52:43 +0000 X-Env-Sender: prvs=826ae1113=Stefano.Stabellini@citrix.com X-Msg-Ref: server-16.tower-206.messagelabs.com!1453823560!17958194!2 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 36521 invoked from network); 26 Jan 2016 15:52:43 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-16.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 26 Jan 2016 15:52:43 -0000 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 Cc: Ian Campbell , xen-devel@lists.xensource.com, qemu-devel@nongnu.org, Stefano Stabellini Subject: [Xen-devel] [PULL 7/8] xen: domainbuild: reopen libxenctrl interface after forking for domain watcher. X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, 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 */