From patchwork Fri Jul 29 16:29:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 9252689 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 BA97B60757 for ; Fri, 29 Jul 2016 16:32:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AC05A283E1 for ; Fri, 29 Jul 2016 16:32:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A087D283E3; Fri, 29 Jul 2016 16:32:03 +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 37F0C283E1 for ; Fri, 29 Jul 2016 16:32:03 +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 1bTAfS-0003ja-FJ; Fri, 29 Jul 2016 16:29:46 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bTAfS-0003hd-28 for xen-devel@lists.xenproject.org; Fri, 29 Jul 2016 16:29:46 +0000 Received: from [85.158.139.211] by server-12.bemta-5.messagelabs.com id B4/7F-01026-9748B975; Fri, 29 Jul 2016 16:29:45 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrAIsWRWlGSWpSXmKPExsXitHRDpG5Fy+x wgy3n9Sy+b5nM5MDocfjDFZYAxijWzLyk/IoE1oyv2/4xFexQqVhz+AZzA+Mq6S5GTg4JAX+J lvbLrCA2m4COxMW5O9m6GDk4RARUJG7vNQAxmQXKJWbciAepEBawlFh64AUbiM0ioCrx/083I 0gJr4CLxJfPmRADdSUenvvNChLmFHCV+L+qGsQUAqpoaAoFqeAVEJQ4OfMJC4jNLKAp0br9Nz uELS/RvHU2M4gtJKAo0T/vARvERG6J26enMk9g5J+FpH0WkvZZSNoXMDKvYtQoTi0qSy3SNTT WSyrKTM8oyU3MzNE1NDDVy00tLk5MT81JTCrWS87P3cQIDD0GINjB+G+b5yFGSQ4mJVHeBStm hQvxJeWnVGYkFmfEF5XmpBYfYtTg4BDYvHb1BUYplrz8vFQlCd7bTbPDhQSLUtNTK9Iyc4DRA VMqwcGjJMK7pREozVtckJhbnJkOkTrFqCglzqvfDJQQAElklObBtcEi8hKjrJQwLyPQUUI8Ba lFuZklqPKvGMU5GJWEeZlBpvBk5pXATX8FtJgJaHFx7AyQxSWJCCmpBsZumbfV9fabQzN22+g 02zSlzypKFP3f2fxM/8ONrPJHDV9jzrxenM/X2Oiw9uhR1WstEmsyrTOPLpExrb6hs/DgNJ0M 2e6ZHbceqnx5lH0vYv6ktaVnYvT0Y5wuL9i09es81y3d0h2/JfQ7b7asnNuyLkvtK+cmr7YHc zKFe6VOh3kpf5jRuVCJpTgj0VCLuag4EQBQVkvcwwIAAA== X-Env-Sender: prvs=011b0443a=roger.pau@citrix.com X-Msg-Ref: server-12.tower-206.messagelabs.com!1469809781!15677055!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: 8.77; banners=-,-,- X-VirusChecked: Checked Received: (qmail 4089 invoked from network); 29 Jul 2016 16:29:44 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-12.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 29 Jul 2016 16:29:44 -0000 X-IronPort-AV: E=Sophos;i="5.28,440,1464652800"; d="scan'208";a="369281741" From: Roger Pau Monne To: Date: Fri, 29 Jul 2016 18:29:03 +0200 Message-ID: <1469809747-11176-9-git-send-email-roger.pau@citrix.com> X-Mailer: git-send-email 2.7.4 (Apple Git-66) In-Reply-To: <1469809747-11176-1-git-send-email-roger.pau@citrix.com> References: <1469809747-11176-1-git-send-email-roger.pau@citrix.com> MIME-Version: 1.0 X-DLP: MIA2 Cc: Andrew Cooper , Jan Beulich , Roger Pau Monne Subject: [Xen-devel] [PATCH RFC 08/12] xen/x86: setup PVHv2 Dom0 CPUs 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 Initialize Dom0 BSP/APs and setup the memory and IO permissions. Signed-off-by: Roger Pau Monné --- Cc: Jan Beulich Cc: Andrew Cooper --- The logic used to setup the CPUID leaves is extremely simplistic (and probably wrong for hardware different than mine). I'm not sure what's the best way to deal with this, the code that currently sets the CPUID leaves for HVM guests lives in libxc, maybe moving it xen/common would be better? --- xen/arch/x86/domain_build.c | 103 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) diff --git a/xen/arch/x86/domain_build.c b/xen/arch/x86/domain_build.c index df6354a..89ef59e 100644 --- a/xen/arch/x86/domain_build.c +++ b/xen/arch/x86/domain_build.c @@ -40,6 +40,7 @@ #include #include +#include static long __initdata dom0_nrpages; static long __initdata dom0_min_nrpages; @@ -1948,6 +1949,101 @@ out: return rc; } +static int __init hvm_setup_cpus(struct domain *d, paddr_t entry, + paddr_t start_info) +{ + vcpu_hvm_context_t cpu_ctx; + struct vcpu *v = d->vcpu[0]; + int cpu, i, rc; + struct { + uint32_t index; + uint32_t count; + } cpuid_leaves[] = { + {0, XEN_CPUID_INPUT_UNUSED}, + {1, XEN_CPUID_INPUT_UNUSED}, + {2, XEN_CPUID_INPUT_UNUSED}, + {4, 0}, + {4, 1}, + {4, 2}, + {4, 3}, + {4, 4}, + {7, 0}, + {0xa, XEN_CPUID_INPUT_UNUSED}, + {0xd, 0}, + {0x80000000, XEN_CPUID_INPUT_UNUSED}, + {0x80000001, XEN_CPUID_INPUT_UNUSED}, + {0x80000002, XEN_CPUID_INPUT_UNUSED}, + {0x80000003, XEN_CPUID_INPUT_UNUSED}, + {0x80000004, XEN_CPUID_INPUT_UNUSED}, + {0x80000005, XEN_CPUID_INPUT_UNUSED}, + {0x80000006, XEN_CPUID_INPUT_UNUSED}, + {0x80000007, XEN_CPUID_INPUT_UNUSED}, + {0x80000008, XEN_CPUID_INPUT_UNUSED}, + }; + + printk("** Setting up BSP/APs **\n"); + + cpu = v->processor; + for ( i = 1; i < d->max_vcpus; i++ ) + { + cpu = cpumask_cycle(cpu, &dom0_cpus); + setup_dom0_vcpu(d, i, cpu); + } + + memset(&cpu_ctx, 0, sizeof(cpu_ctx)); + + cpu_ctx.mode = VCPU_HVM_MODE_32B; + + cpu_ctx.cpu_regs.x86_32.ebx = start_info; + cpu_ctx.cpu_regs.x86_32.eip = entry; + cpu_ctx.cpu_regs.x86_32.cr0 = X86_CR0_PE | X86_CR0_ET; + + cpu_ctx.cpu_regs.x86_32.cs_limit = ~0u; + cpu_ctx.cpu_regs.x86_32.ds_limit = ~0u; + cpu_ctx.cpu_regs.x86_32.ss_limit = ~0u; + cpu_ctx.cpu_regs.x86_32.tr_limit = 0x67; + cpu_ctx.cpu_regs.x86_32.cs_ar = 0xc9b; + cpu_ctx.cpu_regs.x86_32.ds_ar = 0xc93; + cpu_ctx.cpu_regs.x86_32.ss_ar = 0xc93; + cpu_ctx.cpu_regs.x86_32.tr_ar = 0x8b; + + rc = arch_set_info_hvm_guest(v, &cpu_ctx); + if ( rc ) + { + printk("Unable to setup Dom0 BSP context: %d\n", rc); + return rc; + } + clear_bit(_VPF_down, &v->pause_flags); + + for ( i = 0; i < ARRAY_SIZE(cpuid_leaves); i++ ) + { + d->arch.cpuids[i].input[0] = cpuid_leaves[i].index; + d->arch.cpuids[i].input[1] = cpuid_leaves[i].count; + if ( d->arch.cpuids[i].input[1] == XEN_CPUID_INPUT_UNUSED ) + cpuid(d->arch.cpuids[i].input[0], &d->arch.cpuids[i].eax, + &d->arch.cpuids[i].ebx, &d->arch.cpuids[i].ecx, + &d->arch.cpuids[i].edx); + else + cpuid_count(d->arch.cpuids[i].input[0], d->arch.cpuids[i].input[1], + &d->arch.cpuids[i].eax, &d->arch.cpuids[i].ebx, + &d->arch.cpuids[i].ecx, &d->arch.cpuids[i].edx); + /* XXX: we need to do much more filtering here. */ + if ( d->arch.cpuids[i].input[0] == 1 ) + d->arch.cpuids[i].ecx &= ~X86_FEATURE_VMX; + } + + rc = setup_permissions(d); + if ( rc ) + { + panic("Unable to setup Dom0 permissions: %d\n", rc); + return rc; + } + + update_domain_wallclock_time(d); + + return 0; +} + static int __init construct_dom0_hvm(struct domain *d, const module_t *image, unsigned long image_headroom, module_t *initrd, @@ -1982,6 +2078,13 @@ static int __init construct_dom0_hvm(struct domain *d, const module_t *image, return rc; } + rc = hvm_setup_cpus(d, entry, start_info); + if ( rc ) + { + printk("Failed to setup Dom0 CPUs: %d\n", rc); + return rc; + } + return 0; }