From patchwork Fri Apr 8 20:31:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 8786211 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 30D09C0554 for ; Fri, 8 Apr 2016 21:01:05 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2EAA0202EB for ; Fri, 8 Apr 2016 21:01:04 +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 BC1B2202B8 for ; Fri, 8 Apr 2016 21:01:02 +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 1aodUN-0002L4-9g; Fri, 08 Apr 2016 20:58:47 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1aodUL-0002KP-QX for xen-devel@lists.xen.org; Fri, 08 Apr 2016 20:58:45 +0000 Received: from [85.158.139.211] by server-6.bemta-5.messagelabs.com id 21/B7-01795-58B18075; Fri, 08 Apr 2016 20:58:45 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupjkeJIrShJLcpLzFFi42JxWrrBXrdFmiP c4NB6bYslHxezODB6HN39mymAMYo1My8pvyKBNePViTdsBX/lK1a/6GRuYHwi2cXIySEh4C/x /sJ6JhCbTUBfYveLT2C2iIC6xOmOi6xdjBwczAK6Eqt+aoCYwgIeEq+npYNUsAioSCyd/YoVx OYV8JJYefwrO8REOYnzx38yg9icQPEz286A1QgJeEpcnjmfBcJWk7jWf4kdoldQ4uTMJ2BxZg EJiYMvXjBDzOGWuH16KvMERr5ZSMpmISlbwMi0ilG9OLWoLLVI11gvqSgzPaMkNzEzR9fQwFQ vN7W4ODE9NScxqVgvOT93EyMwnBiAYAfj3n9OhxglOZiURHm3PWQPF+JLyk+pzEgszogvKs1J LT7EKMPBoSTBO1WKI1xIsCg1PbUiLTMHGNgwaQkOHiUR3nKQNG9xQWJucWY6ROoUo6KUOG81S EIAJJFRmgfXBoumS4yyUsK8jECHCPEUpBblZpagyr9iFOdgVBLmXQEyhSczrwRu+iugxUxAiy /ws4EsLklESEk1MHKtj4pbtNBuEWNHgntG5A3mUhOl8zYSG24ZLNi1nfvU4kVX7hh/eX/plGN VT4rd+9RlHVvND8303LL0XMzqpuXRVRuY54Zn3Nu3b/K0P88WP5G4vYA1nO3YlJdcn8+eUKnZ yPqGxWfNJaeKaZpzPNL3LbFYaa34/5oX6+++asv6DN+VHsn7Y18rsRRnJBpqMRcVJwIAPCty9 KECAAA= X-Env-Sender: prvs=8997c7931=Andrew.Cooper3@citrix.com X-Msg-Ref: server-15.tower-206.messagelabs.com!1460149121!25394025!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.28; banners=-,-,- X-VirusChecked: Checked Received: (qmail 65081 invoked from network); 8 Apr 2016 20:58:44 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-15.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 8 Apr 2016 20:58:44 -0000 X-IronPort-AV: E=Sophos;i="5.24,454,1454976000"; d="scan'208";a="352601094" From: Andrew Cooper To: Xen-devel Date: Fri, 8 Apr 2016 21:31:48 +0100 Message-ID: <1460147517-11706-13-git-send-email-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1460147517-11706-1-git-send-email-andrew.cooper3@citrix.com> References: <1460147517-11706-1-git-send-email-andrew.cooper3@citrix.com> MIME-Version: 1.0 X-DLP: MIA2 Cc: Andrew Cooper Subject: [Xen-devel] [PATCH v6 12/21] x86/pv: Provide custom cpumasks for PV domains 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=-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 And use them in preference to cpumask_defaults on context switch. HVM domains must not be masked (to avoid interfering with cpuid calls within the guest), so always lazily context switch to the host default. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich Reviewed-by: Konrad Rzeszutek Wilk --- v2: * s/cpumasks/cpuidmasks/ * Use structure assignment * Fix error path in arch_domain_create() v3: * Indentation fixes. * Only allocate PV cpuidmasks if the host is has cpumasks to use. --- xen/arch/x86/cpu/amd.c | 4 +++- xen/arch/x86/cpu/intel.c | 5 ++++- xen/arch/x86/domain.c | 14 ++++++++++++++ xen/include/asm-x86/domain.h | 2 ++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/cpu/amd.c b/xen/arch/x86/cpu/amd.c index 3e2f4a8..d5afc3e 100644 --- a/xen/arch/x86/cpu/amd.c +++ b/xen/arch/x86/cpu/amd.c @@ -206,7 +206,9 @@ static void __init noinline probe_masking_msrs(void) static void amd_ctxt_switch_levelling(const struct domain *nextd) { struct cpuidmasks *these_masks = &this_cpu(cpuidmasks); - const struct cpuidmasks *masks = &cpuidmask_defaults; + const struct cpuidmasks *masks = + (nextd && is_pv_domain(nextd) && nextd->arch.pv_domain.cpuidmasks) + ? nextd->arch.pv_domain.cpuidmasks : &cpuidmask_defaults; #define LAZY(cap, msr, field) \ ({ \ diff --git a/xen/arch/x86/cpu/intel.c b/xen/arch/x86/cpu/intel.c index e21c32d..fe4736e 100644 --- a/xen/arch/x86/cpu/intel.c +++ b/xen/arch/x86/cpu/intel.c @@ -154,7 +154,7 @@ static void __init probe_masking_msrs(void) static void intel_ctxt_switch_levelling(const struct domain *nextd) { struct cpuidmasks *these_masks = &this_cpu(cpuidmasks); - const struct cpuidmasks *masks = &cpuidmask_defaults; + const struct cpuidmasks *masks; if (cpu_has_cpuid_faulting) { /* @@ -178,6 +178,9 @@ static void intel_ctxt_switch_levelling(const struct domain *nextd) return; } + masks = (nextd && is_pv_domain(nextd) && nextd->arch.pv_domain.cpuidmasks) + ? nextd->arch.pv_domain.cpuidmasks : &cpuidmask_defaults; + #define LAZY(msr, field) \ ({ \ if (unlikely(these_masks->field != masks->field) && \ diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index cba77a2..a64bfdc 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -577,6 +577,14 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags, goto fail; clear_page(d->arch.pv_domain.gdt_ldt_l1tab); + if ( levelling_caps & ~LCAP_faulting ) + { + d->arch.pv_domain.cpuidmasks = xmalloc(struct cpuidmasks); + if ( !d->arch.pv_domain.cpuidmasks ) + goto fail; + *d->arch.pv_domain.cpuidmasks = cpuidmask_defaults; + } + rc = create_perdomain_mapping(d, GDT_LDT_VIRT_START, GDT_LDT_MBYTES << (20 - PAGE_SHIFT), NULL, NULL); @@ -672,7 +680,10 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags, paging_final_teardown(d); free_perdomain_mappings(d); if ( is_pv_domain(d) ) + { + xfree(d->arch.pv_domain.cpuidmasks); free_xenheap_page(d->arch.pv_domain.gdt_ldt_l1tab); + } psr_domain_free(d); return rc; } @@ -692,7 +703,10 @@ void arch_domain_destroy(struct domain *d) free_perdomain_mappings(d); if ( is_pv_domain(d) ) + { free_xenheap_page(d->arch.pv_domain.gdt_ldt_l1tab); + xfree(d->arch.pv_domain.cpuidmasks); + } free_xenheap_page(d->shared_info); cleanup_domain_irq_mapping(d); diff --git a/xen/include/asm-x86/domain.h b/xen/include/asm-x86/domain.h index de60def..90f021f 100644 --- a/xen/include/asm-x86/domain.h +++ b/xen/include/asm-x86/domain.h @@ -252,6 +252,8 @@ struct pv_domain /* map_domain_page() mapping cache. */ struct mapcache_domain mapcache; + + struct cpuidmasks *cpuidmasks; }; struct monitor_write_data {