From owner-svn-src-head@freebsd.org Tue Jun 26 15:00:55 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 4FD1A102A450; Tue, 26 Jun 2018 15:00:55 +0000 (UTC) (envelope-from royger@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 05C0874325; Tue, 26 Jun 2018 15:00:55 +0000 (UTC) (envelope-from royger@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id DB07615C31; Tue, 26 Jun 2018 15:00:54 +0000 (UTC) (envelope-from royger@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w5QF0sOh071234; Tue, 26 Jun 2018 15:00:54 GMT (envelope-from royger@FreeBSD.org) Received: (from royger@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w5QF0s1I071232; Tue, 26 Jun 2018 15:00:54 GMT (envelope-from royger@FreeBSD.org) Message-Id: <201806261500.w5QF0s1I071232@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: royger set sender to royger@FreeBSD.org using -f From: =?UTF-8?Q?Roger_Pau_Monn=c3=a9?= Date: Tue, 26 Jun 2018 15:00:54 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r335668 - head/sys/x86/xen X-SVN-Group: head X-SVN-Commit-Author: royger X-SVN-Commit-Paths: head/sys/x86/xen X-SVN-Commit-Revision: 335668 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Jun 2018 15:00:55 -0000 Author: royger Date: Tue Jun 26 15:00:54 2018 New Revision: 335668 URL: https://svnweb.freebsd.org/changeset/base/335668 Log: xen: obtain vCPU ID from CPUID The Xen vCPU ID can be fetched from the cpuid instead of inferring it from the ACPI ID. Sponsored by: Citrix Systems R&D Modified: head/sys/x86/xen/hvm.c Modified: head/sys/x86/xen/hvm.c ============================================================================== --- head/sys/x86/xen/hvm.c Tue Jun 26 14:48:23 2018 (r335667) +++ head/sys/x86/xen/hvm.c Tue Jun 26 15:00:54 2018 (r335668) @@ -56,6 +56,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include @@ -103,6 +104,9 @@ TUNABLE_INT("hw.xen.disable_pv_disks", &xen_disable_pv TUNABLE_INT("hw.xen.disable_pv_nics", &xen_disable_pv_nics); /*---------------------- XEN Hypervisor Probe and Setup ----------------------*/ + +static uint32_t cpuid_base; + static uint32_t xen_hvm_cpuid_base(void) { @@ -123,21 +127,21 @@ xen_hvm_cpuid_base(void) static int xen_hvm_init_hypercall_stubs(enum xen_hvm_init_type init_type) { - uint32_t base, regs[4]; + uint32_t regs[4]; if (xen_pv_domain()) { /* hypercall page is already set in the PV case */ return (0); } - base = xen_hvm_cpuid_base(); - if (base == 0) + cpuid_base = xen_hvm_cpuid_base(); + if (cpuid_base == 0) return (ENXIO); if (init_type == XEN_HVM_INIT_COLD) { int major, minor; - do_cpuid(base + 1, regs); + do_cpuid(cpuid_base + 1, regs); major = regs[0] >> 16; minor = regs[0] & 0xffff; @@ -165,7 +169,7 @@ xen_hvm_init_hypercall_stubs(enum xen_hvm_init_type in /* * Find the hypercall pages. */ - do_cpuid(base + 2, regs); + do_cpuid(cpuid_base + 2, regs); if (regs[0] != 1) return (EINVAL); @@ -371,31 +375,14 @@ xen_hvm_sysinit(void *arg __unused) { xen_hvm_init(XEN_HVM_INIT_COLD); } +SYSINIT(xen_hvm_init, SI_SUB_HYPERVISOR, SI_ORDER_FIRST, xen_hvm_sysinit, NULL); static void -xen_set_vcpu_id(void) -{ - struct pcpu *pc; - int i; - - if (!xen_hvm_domain()) - return; - - /* Set vcpu_id to acpi_id */ - CPU_FOREACH(i) { - pc = pcpu_find(i); - pc->pc_vcpu_id = pc->pc_acpi_id; - if (bootverbose) - printf("XEN: CPU %u has VCPU ID %u\n", - i, pc->pc_vcpu_id); - } -} - -static void xen_hvm_cpu_init(void) { struct vcpu_register_vcpu_info info; struct vcpu_info *vcpu_info; + uint32_t regs[4]; int cpu, rc; if (!xen_domain()) @@ -410,6 +397,22 @@ xen_hvm_cpu_init(void) return; } + /* + * Set vCPU ID. If available fetch the ID from CPUID, if not just use + * the ACPI ID. + */ + KASSERT(cpuid_base != 0, ("Invalid base Xen CPUID leaf")); + cpuid_count(cpuid_base + 4, 0, regs); + PCPU_SET(vcpu_id, (regs[0] & XEN_HVM_CPUID_VCPU_ID_PRESENT) ? + regs[1] : PCPU_GET(acpi_id)); + + /* + * Set the vCPU info. + * + * NB: the vCPU info for vCPUs < 32 can be fetched from the shared info + * page, but in order to make sure the mapping code is correct always + * attempt to map the vCPU info at a custom place. + */ vcpu_info = DPCPU_PTR(vcpu_local_info); cpu = PCPU_GET(vcpu_id); info.mfn = vtophys(vcpu_info) >> PAGE_SHIFT; @@ -421,7 +424,4 @@ xen_hvm_cpu_init(void) else DPCPU_SET(vcpu_info, vcpu_info); } - -SYSINIT(xen_hvm_init, SI_SUB_HYPERVISOR, SI_ORDER_FIRST, xen_hvm_sysinit, NULL); SYSINIT(xen_hvm_cpu_init, SI_SUB_INTR, SI_ORDER_FIRST, xen_hvm_cpu_init, NULL); -SYSINIT(xen_set_vcpu_id, SI_SUB_CPU, SI_ORDER_ANY, xen_set_vcpu_id, NULL);