From patchwork Thu Oct 5 18:23:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 9987751 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9A66D6029B for ; Thu, 5 Oct 2017 18:26:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8B05E28D36 for ; Thu, 5 Oct 2017 18:26:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7FD0728D39; Thu, 5 Oct 2017 18:26:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B148428D36 for ; Thu, 5 Oct 2017 18:26:28 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e0AoK-0006ZW-0f; Thu, 05 Oct 2017 18:23:52 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e0AoJ-0006Yz-H2 for xen-devel@lists.xen.org; Thu, 05 Oct 2017 18:23:51 +0000 Received: from [85.158.137.68] by server-13.bemta-3.messagelabs.com id A9/AC-01908-6B876D95; Thu, 05 Oct 2017 18:23:50 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprBIsWRWlGSWpSXmKPExsXitHRDpO62imu RBkeucFss+biYxYHR4+ju30wBjFGsmXlJ+RUJrBlLVl5hLtgeUrF13wnmBsY/Tl2MnBwSAv4S 82/8YgGx2QT0JXa/+MQEYosIqEuc7rjI2sXIxcEsMIdRYuOVzcwgCWGBdImDn/6wg9gsAioSv X8OsIHYvAKeElMXtLFADJWTOH/8J1g9p4CXxNZlc8DiQkA169q2sULYahLX+i+xQ/QKSpyc+Q SshllAQuLgixfMExh5ZyFJzUKSWsDItIpRozi1qCy1SNfIUC+pKDM9oyQ3MTNH19DAWC83tbg 4MT01JzGpWC85P3cTIzB86hkYGHcw9uz1O8QoycGkJMqrVXAtUogvKT+lMiOxOCO+qDQntfgQ owwHh5IE79dyoJxgUWp6akVaZg4wkGHSEhw8SiK8HSBp3uKCxNzizHSI1ClGY45jmy7/YeLou Hn3D5MQS15+XqqUOO85kFIBkNKM0jy4QbAIu8QoKyXMy8jAwCDEU5BalJtZgir/ilGcg1FJmF cMGK9CPJl5JXD7XgGdwgR0ypymKyCnlCQipKQaGFsrq3XNYkLimHbLscz+6Zljf9vOXY3dTcR 0/2NJt6ZtPA9z4tnbHRjElRYqhu9fZu14KvuecJOpz24ZxqUeUvNtD3atXu/yN6SkQdblF8Nq hs6FR48rZdeFTVectOB8U7Jy53+93PdvFaJUTh14edXt0cOlm4vnPFisebjRO+ex4Jme6Tf4l ViKMxINtZiLihMBKmfE0KsCAAA= X-Env-Sender: prvs=444660210=Andrew.Cooper3@citrix.com X-Msg-Ref: server-5.tower-31.messagelabs.com!1507227826!114886925!3 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: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 37326 invoked from network); 5 Oct 2017 18:23:49 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-5.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 5 Oct 2017 18:23:49 -0000 X-IronPort-AV: E=Sophos;i="5.42,481,1500940800"; d="scan'208";a="442680594" From: Andrew Cooper To: Xen-devel Date: Thu, 5 Oct 2017 19:23:42 +0100 Message-ID: <1507227824-11744-5-git-send-email-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1507227824-11744-1-git-send-email-andrew.cooper3@citrix.com> References: <1507227824-11744-1-git-send-email-andrew.cooper3@citrix.com> MIME-Version: 1.0 Cc: Andrew Cooper , Julien Grall , Ian Jackson , Wei Liu Subject: [Xen-devel] [PATCH for-4.10 4/5] tools/dombuilder: Fix asymetry when setting up console and xenstore rings X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP libxl always uses xc_dom_gnttab_init(), which internally calls xc_dom_gnttab{_hvm,}_seed() to set up the grants point at the console and xenstore rings. For HVM guests, libxl then asks Xen for the information set up previously, and calls xc_dom_gnttab_hvm_seed() a second time, which is wasteful. ARM construction expects libxl to have set up dom->{console,xenstore}_evtchn earlier, so only actually functions because of this second call. Rationalise everything and make it consistent for all guests. 1) Users of the domain builder are expected to provide dom->{console,xenstore}_{evtchn,domid} unconditionally. This is checked by setting invalid values in xc_dom_allocate(), and checking in xc_dom_boot_image(). 2) For x86 HVM and ARM guests, the event channels are given to Xen at the same time as the ring gfns. ARM already did this, but x86 is updated to match. x86 PV already provides this information in the start_info page. 3) Libxl is updated to drop all relevent functionality from hvm_build_set_params(), and behave consistently with PV guests when it comes to the handling of dom->{console,xenstore}_{evtchn,domid,gfn}. This removes several redundant hypercalls (including a foreign mapping) from the x86 HVM and ARM construction paths. Signed-off-by: Andrew Cooper Acked-by: Wei Liu --- CC: Ian Jackson CC: Wei Liu CC: Julien Grall --- tools/libxc/include/xc_dom.h | 12 ++++++++---- tools/libxc/xc_dom_arm.c | 2 +- tools/libxc/xc_dom_boot.c | 36 ++++++++++++++++++++++++++++++++++++ tools/libxc/xc_dom_compat_linux.c | 2 ++ tools/libxc/xc_dom_core.c | 5 +++++ tools/libxc/xc_dom_x86.c | 4 ++++ tools/libxl/libxl_dom.c | 28 ++++++++++------------------ tools/libxl/libxl_internal.h | 1 - 8 files changed, 66 insertions(+), 24 deletions(-) diff --git a/tools/libxc/include/xc_dom.h b/tools/libxc/include/xc_dom.h index 80b4fbd..790869b 100644 --- a/tools/libxc/include/xc_dom.h +++ b/tools/libxc/include/xc_dom.h @@ -20,6 +20,8 @@ #include #define INVALID_PFN ((xen_pfn_t)-1) +#define INVALID_EVTCHN (~0u) +#define INVALID_DOMID (-1) #define X86_HVM_NR_SPECIAL_PAGES 8 #define X86_HVM_END_SPECIAL_REGION 0xff000u @@ -104,10 +106,16 @@ struct xc_dom_image { * Details for the toolstack-prepared rings. * * *_gfn fields are allocated by the domain builder. + * *_{evtchn,domid} fields must be provided by the caller. */ xen_pfn_t console_gfn; xen_pfn_t xenstore_gfn; + unsigned int console_evtchn; + unsigned int xenstore_evtchn; + domid_t console_domid; + domid_t xenstore_domid; + /* * initrd parameters as specified in start_info page * Depending on capabilities of the booted kernel this may be a virtual @@ -165,10 +173,6 @@ struct xc_dom_image { /* misc xen domain config stuff */ unsigned long flags; - unsigned int console_evtchn; - unsigned int xenstore_evtchn; - domid_t console_domid; - domid_t xenstore_domid; xen_pfn_t shared_info_mfn; xc_interface *xch; diff --git a/tools/libxc/xc_dom_arm.c b/tools/libxc/xc_dom_arm.c index c7aa44a..d668df1 100644 --- a/tools/libxc/xc_dom_arm.c +++ b/tools/libxc/xc_dom_arm.c @@ -99,7 +99,7 @@ static int alloc_magic_pages(struct xc_dom_image *dom) dom->xenstore_gfn); xc_hvm_param_set(dom->xch, dom->guest_domid, HVM_PARAM_MONITOR_RING_PFN, base + MEMACCESS_PFN_OFFSET); - /* allocated by toolstack */ + xc_hvm_param_set(dom->xch, dom->guest_domid, HVM_PARAM_CONSOLE_EVTCHN, dom->console_evtchn); xc_hvm_param_set(dom->xch, dom->guest_domid, HVM_PARAM_STORE_EVTCHN, diff --git a/tools/libxc/xc_dom_boot.c b/tools/libxc/xc_dom_boot.c index a84a95e..8d4fefa 100644 --- a/tools/libxc/xc_dom_boot.c +++ b/tools/libxc/xc_dom_boot.c @@ -163,6 +163,39 @@ void *xc_dom_boot_domU_map(struct xc_dom_image *dom, xen_pfn_t pfn, return ptr; } +static int xc_dom_check_required_fields(struct xc_dom_image *dom) +{ + int rc = 0; + + if ( dom->console_evtchn == INVALID_EVTCHN ) + { + xc_dom_panic(dom->xch, XC_INVALID_PARAM, + "%s: Caller didn't set dom->console_evtchn", __func__); + rc = -1; + } + if ( dom->console_domid == INVALID_DOMID ) + { + xc_dom_panic(dom->xch, XC_INVALID_PARAM, + "%s: Caller didn't set dom->console_domid", __func__); + rc = -1; + } + + if ( dom->xenstore_evtchn == INVALID_EVTCHN ) + { + xc_dom_panic(dom->xch, XC_INVALID_PARAM, + "%s: Caller didn't set dom->xenstore_evtchn", __func__); + rc = -1; + } + if ( dom->xenstore_domid == INVALID_DOMID ) + { + xc_dom_panic(dom->xch, XC_INVALID_PARAM, + "%s: Caller didn't set dom->xenstore_domid", __func__); + rc = -1; + } + + return rc; +} + int xc_dom_boot_image(struct xc_dom_image *dom) { xc_dominfo_t info; @@ -170,6 +203,9 @@ int xc_dom_boot_image(struct xc_dom_image *dom) DOMPRINTF_CALLED(dom->xch); + if ( (rc = xc_dom_check_required_fields(dom)) != 0 ) + return rc; + /* misc stuff*/ if ( (rc = dom->arch_hooks->bootearly(dom)) != 0 ) return rc; diff --git a/tools/libxc/xc_dom_compat_linux.c b/tools/libxc/xc_dom_compat_linux.c index 6d27ec2..2ad43e4 100644 --- a/tools/libxc/xc_dom_compat_linux.c +++ b/tools/libxc/xc_dom_compat_linux.c @@ -61,7 +61,9 @@ int xc_linux_build(xc_interface *xch, uint32_t domid, dom->flags |= flags; dom->console_evtchn = console_evtchn; + dom->console_domid = 0; dom->xenstore_evtchn = store_evtchn; + dom->xenstore_domid = 0; if ( (rc = xc_dom_boot_xen_init(dom, xch, domid)) != 0 ) goto out; diff --git a/tools/libxc/xc_dom_core.c b/tools/libxc/xc_dom_core.c index b5f316a..7087c50 100644 --- a/tools/libxc/xc_dom_core.c +++ b/tools/libxc/xc_dom_core.c @@ -779,6 +779,11 @@ struct xc_dom_image *xc_dom_allocate(xc_interface *xch, dom->parms.elf_paddr_offset = UNSET_ADDR; dom->parms.p2m_base = UNSET_ADDR; + dom->console_evtchn = INVALID_EVTCHN; + dom->xenstore_evtchn = INVALID_EVTCHN; + dom->console_domid = INVALID_DOMID; + dom->xenstore_domid = INVALID_DOMID; + dom->flags = SIF_VIRT_P2M_4TOOLS; dom->alloc_malloc += sizeof(*dom); diff --git a/tools/libxc/xc_dom_x86.c b/tools/libxc/xc_dom_x86.c index aa0ced1..05f4b80 100644 --- a/tools/libxc/xc_dom_x86.c +++ b/tools/libxc/xc_dom_x86.c @@ -617,6 +617,8 @@ static int alloc_magic_pages_hvm(struct xc_dom_image *dom) dom->xenstore_gfn = special_pfn(SPECIALPAGE_XENSTORE); xc_clear_domain_page(dom->xch, dom->guest_domid, dom->xenstore_gfn); xc_hvm_param_set(xch, domid, HVM_PARAM_STORE_PFN, dom->xenstore_gfn); + xc_hvm_param_set(dom->xch, dom->guest_domid, HVM_PARAM_STORE_EVTCHN, + dom->xenstore_evtchn); xc_hvm_param_set(xch, domid, HVM_PARAM_BUFIOREQ_PFN, special_pfn(SPECIALPAGE_BUFIOREQ)); @@ -626,6 +628,8 @@ static int alloc_magic_pages_hvm(struct xc_dom_image *dom) dom->console_gfn = special_pfn(SPECIALPAGE_CONSOLE); xc_clear_domain_page(dom->xch, dom->guest_domid, dom->console_gfn); xc_hvm_param_set(xch, domid, HVM_PARAM_CONSOLE_PFN, dom->console_gfn); + xc_hvm_param_set(dom->xch, dom->guest_domid, HVM_PARAM_CONSOLE_EVTCHN, + dom->console_evtchn); xc_hvm_param_set(xch, domid, HVM_PARAM_PAGING_RING_PFN, special_pfn(SPECIALPAGE_PAGING)); diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c index 0389a06..fcdeef0 100644 --- a/tools/libxl/libxl_dom.c +++ b/tools/libxl/libxl_dom.c @@ -862,14 +862,10 @@ int libxl__build_pv(libxl__gc *gc, uint32_t domid, } static int hvm_build_set_params(xc_interface *handle, uint32_t domid, - libxl_domain_build_info *info, - int store_evtchn, unsigned long *store_mfn, - int console_evtchn, unsigned long *console_mfn, - domid_t store_domid, domid_t console_domid) + libxl_domain_build_info *info) { struct hvm_info_table *va_hvm; uint8_t *va_map, sum; - uint64_t str_mfn, cons_mfn; int i; if (info->type == LIBXL_DOMAIN_TYPE_HVM) { @@ -890,15 +886,6 @@ static int hvm_build_set_params(xc_interface *handle, uint32_t domid, munmap(va_map, XC_PAGE_SIZE); } - xc_hvm_param_get(handle, domid, HVM_PARAM_STORE_PFN, &str_mfn); - xc_hvm_param_get(handle, domid, HVM_PARAM_CONSOLE_PFN, &cons_mfn); - xc_hvm_param_set(handle, domid, HVM_PARAM_STORE_EVTCHN, store_evtchn); - xc_hvm_param_set(handle, domid, HVM_PARAM_CONSOLE_EVTCHN, console_evtchn); - - *store_mfn = str_mfn; - *console_mfn = cons_mfn; - - xc_dom_gnttab_hvm_seed(handle, domid, *console_mfn, *store_mfn, console_domid, store_domid); return 0; } @@ -1159,6 +1146,11 @@ int libxl__build_hvm(libxl__gc *gc, uint32_t domid, dom->container_type = XC_DOM_HVM_CONTAINER; + dom->console_evtchn = state->console_port; + dom->console_domid = state->console_domid; + dom->xenstore_evtchn = state->store_port; + dom->xenstore_domid = state->store_domid; + /* The params from the configuration file are in Mb, which are then * multiplied by 1 Kb. This was then divided off when calling * the old xc_hvm_build_target_mem() which then turned them to bytes. @@ -1263,10 +1255,7 @@ int libxl__build_hvm(libxl__gc *gc, uint32_t domid, goto out; } - rc = hvm_build_set_params(ctx->xch, domid, info, state->store_port, - &state->store_mfn, state->console_port, - &state->console_mfn, state->store_domid, - state->console_domid); + rc = hvm_build_set_params(ctx->xch, domid, info); if (rc != 0) { LOG(ERROR, "hvm build set params failed"); goto out; @@ -1278,6 +1267,9 @@ int libxl__build_hvm(libxl__gc *gc, uint32_t domid, goto out; } + state->console_mfn = dom->console_gfn; + state->store_mfn = dom->xenstore_gfn; + xc_dom_release(dom); return 0; diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index bcb6b0a..8a8ef4a 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -115,7 +115,6 @@ #define STUBDOM_SPECIAL_CONSOLES 3 #define TAP_DEVICE_SUFFIX "-emu" #define DOMID_XS_PATH "domid" -#define INVALID_DOMID ~0 /* Size macros. */ #define __AC(X,Y) (X##Y)