From patchwork Tue Mar 15 16:14:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 8590391 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id D2D239F294 for ; Tue, 15 Mar 2016 16:27:17 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D194C202F0 for ; Tue, 15 Mar 2016 16:27:16 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id BB641202EC for ; Tue, 15 Mar 2016 16:27:15 +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 1afrln-00010H-CY; Tue, 15 Mar 2016 16:24:31 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1afrlm-0000zm-HT for xen-devel@lists.xenproject.org; Tue, 15 Mar 2016 16:24:30 +0000 Received: from [193.109.254.147] by server-1.bemta-14.messagelabs.com id 5D/15-02901-D3738E65; Tue, 15 Mar 2016 16:24:29 +0000 X-Env-Sender: prvs=875e259b5=Paul.Durrant@citrix.com X-Msg-Ref: server-12.tower-27.messagelabs.com!1458059066!31320135!2 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 8.11; banners=-,-,- X-VirusChecked: Checked Received: (qmail 51024 invoked from network); 15 Mar 2016 16:24:28 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-12.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 15 Mar 2016 16:24:28 -0000 X-IronPort-AV: E=Sophos;i="5.24,340,1454976000"; d="scan'208";a="345757371" From: Paul Durrant To: Date: Tue, 15 Mar 2016 16:14:15 +0000 Message-ID: <1458058456-7345-2-git-send-email-paul.durrant@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1458058456-7345-1-git-send-email-paul.durrant@citrix.com> References: <1458058456-7345-1-git-send-email-paul.durrant@citrix.com> MIME-Version: 1.0 X-DLP: MIA1 Cc: Andrew Cooper , Paul Durrant , Keir Fraser , Jan Beulich Subject: [Xen-devel] [PATCH 1/2] x86/hvm/viridian: keep APIC assist page mapped... 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-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, 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 ... for the lifetime of the domain. If Xen is to make use of the APIC assist enlightenment then a persistent mapping needs to be kept, rather than the temporary one which is currently used only to initialize the page content. Signed-off-by: Paul Durrant Cc: Keir Fraser Cc: Jan Beulich Cc: Andrew Cooper --- xen/arch/x86/hvm/viridian.c | 54 +++++++++++++++++++++++++++----------- xen/include/asm-x86/hvm/viridian.h | 6 ++++- 2 files changed, 43 insertions(+), 17 deletions(-) diff --git a/xen/arch/x86/hvm/viridian.c b/xen/arch/x86/hvm/viridian.c index 6bd844b..c779290 100644 --- a/xen/arch/x86/hvm/viridian.c +++ b/xen/arch/x86/hvm/viridian.c @@ -163,7 +163,7 @@ static void dump_apic_assist(const struct vcpu *v) { const union viridian_apic_assist *aa; - aa = &v->arch.hvm_vcpu.viridian.apic_assist; + aa = &v->arch.hvm_vcpu.viridian.apic_assist.msr; printk(XENLOG_G_INFO "%pv: VIRIDIAN APIC_ASSIST: enabled: %x pfn: %lx\n", v, aa->fields.enabled, (unsigned long)aa->fields.pfn); @@ -217,9 +217,9 @@ static void enable_hypercall_page(struct domain *d) static void initialize_apic_assist(struct vcpu *v) { struct domain *d = v->domain; - unsigned long gmfn = v->arch.hvm_vcpu.viridian.apic_assist.fields.pfn; + unsigned long gmfn = v->arch.hvm_vcpu.viridian.apic_assist.msr.fields.pfn; struct page_info *page = get_page_from_gfn(d, gmfn, NULL, P2M_ALLOC); - uint8_t *p; + void *va; /* * We don't yet make use of the APIC assist page but by setting @@ -231,21 +231,40 @@ static void initialize_apic_assist(struct vcpu *v) * details of how Windows uses the page. */ - if ( !page || !get_page_type(page, PGT_writable_page) ) + if ( !page ) + return; + + if ( !get_page_type(page, PGT_writable_page) ) { - if ( page ) - put_page(page); - gdprintk(XENLOG_WARNING, "Bad GMFN %lx (MFN %lx)\n", gmfn, - page ? page_to_mfn(page) : INVALID_MFN); + put_page(page); return; } - p = __map_domain_page(page); + va = __map_domain_page_global(page); + if ( !va ) + { + put_page_and_type(page); + return; + } - *(u32 *)p = 0; + *(uint32_t *)va = 0; - unmap_domain_page(p); + v->arch.hvm_vcpu.viridian.apic_assist.page = page; + v->arch.hvm_vcpu.viridian.apic_assist.va = va; +} + +static void teardown_apic_assist(struct vcpu *v) +{ + struct page_info *page = v->arch.hvm_vcpu.viridian.apic_assist.page; + void *va = v->arch.hvm_vcpu.viridian.apic_assist.va; + + if ( !va ) + return; + + v->arch.hvm_vcpu.viridian.apic_assist.va = NULL; + v->arch.hvm_vcpu.viridian.apic_assist.page = NULL; + unmap_domain_page_global(va); put_page_and_type(page); } @@ -374,9 +393,9 @@ int wrmsr_viridian_regs(uint32_t idx, uint64_t val) case VIRIDIAN_MSR_APIC_ASSIST: perfc_incr(mshv_wrmsr_apic_msr); - v->arch.hvm_vcpu.viridian.apic_assist.raw = val; + v->arch.hvm_vcpu.viridian.apic_assist.msr.raw = val; dump_apic_assist(v); - if (v->arch.hvm_vcpu.viridian.apic_assist.fields.enabled) + if ( v->arch.hvm_vcpu.viridian.apic_assist.msr.fields.enabled ) initialize_apic_assist(v); break; @@ -485,7 +504,7 @@ int rdmsr_viridian_regs(uint32_t idx, uint64_t *val) case VIRIDIAN_MSR_APIC_ASSIST: perfc_incr(mshv_rdmsr_apic_msr); - *val = v->arch.hvm_vcpu.viridian.apic_assist.raw; + *val = v->arch.hvm_vcpu.viridian.apic_assist.msr.raw; break; case VIRIDIAN_MSR_REFERENCE_TSC: @@ -530,6 +549,7 @@ int viridian_vcpu_init(struct vcpu *v) void viridian_vcpu_deinit(struct vcpu *v) { free_cpumask_var(v->arch.hvm_vcpu.viridian.flush_cpumask); + teardown_apic_assist(v); } int viridian_hypercall(struct cpu_user_regs *regs) @@ -728,7 +748,7 @@ static int viridian_save_vcpu_ctxt(struct domain *d, hvm_domain_context_t *h) for_each_vcpu( d, v ) { struct hvm_viridian_vcpu_context ctxt; - ctxt.apic_assist = v->arch.hvm_vcpu.viridian.apic_assist.raw; + ctxt.apic_assist = v->arch.hvm_vcpu.viridian.apic_assist.msr.raw; if ( hvm_save_entry(VIRIDIAN_VCPU, v->vcpu_id, h, &ctxt) != 0 ) return 1; @@ -754,7 +774,9 @@ static int viridian_load_vcpu_ctxt(struct domain *d, hvm_domain_context_t *h) if ( hvm_load_entry(VIRIDIAN_VCPU, h, &ctxt) != 0 ) return -EINVAL; - v->arch.hvm_vcpu.viridian.apic_assist.raw = ctxt.apic_assist; + v->arch.hvm_vcpu.viridian.apic_assist.msr.raw = ctxt.apic_assist; + if ( v->arch.hvm_vcpu.viridian.apic_assist.msr.fields.enabled ) + initialize_apic_assist(v); return 0; } diff --git a/xen/include/asm-x86/hvm/viridian.h b/xen/include/asm-x86/hvm/viridian.h index 2eec85e..c60c113 100644 --- a/xen/include/asm-x86/hvm/viridian.h +++ b/xen/include/asm-x86/hvm/viridian.h @@ -21,7 +21,11 @@ union viridian_apic_assist struct viridian_vcpu { - union viridian_apic_assist apic_assist; + struct { + union viridian_apic_assist msr; + struct page_info *page; + void *va; + } apic_assist; cpumask_var_t flush_cpumask; };