From: Chao Gao <chao.gao@intel.com>
To: xen-devel@lists.xen.org
Cc: Ian Jackson <ian.jackson@eu.citrix.com>,
Andrew Cooper <andrew.cooper3@citrix.com>,
Wei Liu <wei.liu2@citrix.com>, Jan Beulich <jbeulich@suse.com>,
Chao Gao <chao.gao@intel.com>
Subject: [RFC Patch v4 4/8] hvmloader: boot cpu through broadcast
Date: Wed, 6 Dec 2017 15:50:10 +0800 [thread overview]
Message-ID: <1512546614-9937-5-git-send-email-chao.gao@intel.com> (raw)
In-Reply-To: <1512546614-9937-1-git-send-email-chao.gao@intel.com>
Intel SDM Extended XAPIC (X2APIC) -> "Initialization by System Software"
has the following description:
"The ACPI interfaces for the x2APIC are described in Section 5.2, “ACPI System
Description Tables,” of the Advanced Configuration and Power Interface
Specification, Revision 4.0a (http://www.acpi.info/spec.htm). The default
behavior for BIOS is to pass the control to the operating system with the
local x2APICs in xAPIC mode if all APIC IDs reported by CPUID.0BH:EDX are less
than 255, and in x2APIC mode if there are any logical processor reporting an
APIC ID of 255 or greater."
In this patch, hvmloader enables x2apic mode for all vcpus if there are cpus
with APIC ID > 255. To wake up processors whose APIC ID is greater than 255,
the SIPI is broadcasted to all APs. It is the way how Seabios wakes up APs.
APs may compete for the stack, thus a lock is introduced to protect the stack.
Signed-off-by: Chao Gao <chao.gao@intel.com>
---
v4:
- new
---
tools/firmware/hvmloader/apic_regs.h | 4 +++
tools/firmware/hvmloader/smp.c | 64 ++++++++++++++++++++++++++++++++----
2 files changed, 61 insertions(+), 7 deletions(-)
diff --git a/tools/firmware/hvmloader/apic_regs.h b/tools/firmware/hvmloader/apic_regs.h
index f737b47..bc39ecd 100644
--- a/tools/firmware/hvmloader/apic_regs.h
+++ b/tools/firmware/hvmloader/apic_regs.h
@@ -105,6 +105,10 @@
#define APIC_TDR_DIV_64 0x9
#define APIC_TDR_DIV_128 0xA
+#define MSR_IA32_APICBASE 0x1b
+#define MSR_IA32_APICBASE_EXTD (1<<10)
+#define MSR_IA32_APICBASE_MSR 0x800
+
#endif
/*
diff --git a/tools/firmware/hvmloader/smp.c b/tools/firmware/hvmloader/smp.c
index 082b17f..e3dade4 100644
--- a/tools/firmware/hvmloader/smp.c
+++ b/tools/firmware/hvmloader/smp.c
@@ -26,7 +26,9 @@
#define AP_BOOT_EIP 0x1000
extern char ap_boot_start[], ap_boot_end[];
-static int ap_callin, ap_cpuid;
+static int ap_callin;
+static int enable_x2apic;
+static bool lock = 1;
asm (
" .text \n"
@@ -47,7 +49,15 @@ asm (
" mov %eax,%ds \n"
" mov %eax,%es \n"
" mov %eax,%ss \n"
- " movl $stack_top,%esp \n"
+ "3: movb $1, %bl \n"
+ " mov $lock,%edx \n"
+ " movzbl %bl,%eax \n"
+ " xchg %al, (%edx) \n"
+ " test %al,%al \n"
+ " je 2f \n"
+ " pause \n"
+ " jmp 3b \n"
+ "2: movl $stack_top,%esp \n"
" movl %esp,%ebp \n"
" call ap_start \n"
"1: hlt \n"
@@ -68,14 +78,34 @@ asm (
" .text \n"
);
+unsigned int ap_cpuid(void)
+{
+ if ( !(rdmsr(MSR_IA32_APICBASE) & MSR_IA32_APICBASE_EXTD) )
+ {
+ uint32_t eax, ebx, ecx, edx;
+
+ cpuid(1, &eax, &ebx, &ecx, &edx);
+ return ebx >> 24;
+ }
+ else
+ return rdmsr(MSR_IA32_APICBASE_MSR + (APIC_ID >> 4));
+}
+
void ap_start(void); /* non-static avoids unused-function compiler warning */
/*static*/ void ap_start(void)
{
- printf(" - CPU%d ... ", ap_cpuid);
+ printf(" - CPU%d ... ", ap_cpuid());
cacheattr_init();
printf("done.\n");
wmb();
- ap_callin = 1;
+ ap_callin++;
+
+ if ( enable_x2apic )
+ wrmsr(MSR_IA32_APICBASE, rdmsr(MSR_IA32_APICBASE) |
+ MSR_IA32_APICBASE_EXTD);
+
+ /* Release the lock */
+ asm volatile ( "xchgb %1, %b0" : : "m" (lock), "r" (0) : "memory" );
}
static void lapic_wait_ready(void)
@@ -89,7 +119,6 @@ static void boot_cpu(unsigned int cpu)
unsigned int icr2 = SET_APIC_DEST_FIELD(LAPIC_ID(cpu));
/* Initialise shared variables. */
- ap_cpuid = cpu;
ap_callin = 0;
wmb();
@@ -118,6 +147,21 @@ static void boot_cpu(unsigned int cpu)
lapic_wait_ready();
}
+static void boot_cpu_broadcast_x2apic(unsigned int nr_cpus)
+{
+ wrmsr(MSR_IA32_APICBASE_MSR + (APIC_ICR >> 4),
+ APIC_DEST_ALLBUT | APIC_DM_INIT);
+
+ wrmsr(MSR_IA32_APICBASE_MSR + (APIC_ICR >> 4),
+ APIC_DEST_ALLBUT | APIC_DM_STARTUP | (AP_BOOT_EIP >> 12));
+
+ while ( ap_callin != nr_cpus )
+ cpu_relax();
+
+ wrmsr(MSR_IA32_APICBASE_MSR + (APIC_ICR >> 4),
+ APIC_DEST_ALLBUT | APIC_DM_INIT);
+}
+
void smp_initialise(void)
{
unsigned int i, nr_cpus = hvm_info->nr_vcpus;
@@ -125,9 +169,15 @@ void smp_initialise(void)
memcpy((void *)AP_BOOT_EIP, ap_boot_start, ap_boot_end - ap_boot_start);
printf("Multiprocessor initialisation:\n");
+ if ( nr_cpus > MADT_MAX_LOCAL_APIC )
+ enable_x2apic = 1;
+
ap_start();
- for ( i = 1; i < nr_cpus; i++ )
- boot_cpu(i);
+ if ( nr_cpus > MADT_MAX_LOCAL_APIC )
+ boot_cpu_broadcast_x2apic(nr_cpus);
+ else
+ for ( i = 1; i < nr_cpus; i++ )
+ boot_cpu(i);
}
/*
--
1.8.3.1
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
next prev parent reply other threads:[~2017-12-06 7:50 UTC|newest]
Thread overview: 56+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-06 7:50 [RFC Patch v4 0/8] Extend resources to support more vcpus in single VM Chao Gao
2017-12-06 7:50 ` [RFC Patch v4 1/8] ioreq: remove most 'buf' parameter from static functions Chao Gao
2017-12-06 14:44 ` Paul Durrant
2017-12-06 8:37 ` Chao Gao
2017-12-06 7:50 ` [RFC Patch v4 2/8] ioreq: bump the number of IOREQ page to 4 pages Chao Gao
2017-12-06 15:04 ` Paul Durrant
2017-12-06 9:02 ` Chao Gao
2017-12-06 16:10 ` Paul Durrant
2017-12-07 8:41 ` Paul Durrant
2017-12-07 6:56 ` Chao Gao
2017-12-08 11:06 ` Paul Durrant
2017-12-12 1:03 ` Chao Gao
2017-12-12 9:07 ` Paul Durrant
2017-12-12 23:39 ` Chao Gao
2017-12-13 10:49 ` Paul Durrant
2017-12-13 17:50 ` Paul Durrant
2017-12-14 14:50 ` Paul Durrant
2017-12-15 0:35 ` Chao Gao
2017-12-15 9:40 ` Paul Durrant
2018-04-18 8:19 ` Jan Beulich
2017-12-06 7:50 ` [RFC Patch v4 3/8] xl/acpi: unify the computation of lapic_id Chao Gao
2018-02-22 18:05 ` Wei Liu
2017-12-06 7:50 ` Chao Gao [this message]
2018-02-22 18:44 ` [RFC Patch v4 4/8] hvmloader: boot cpu through broadcast Wei Liu
2018-02-23 8:41 ` Jan Beulich
2018-02-23 16:42 ` Roger Pau Monné
2018-02-24 5:49 ` Chao Gao
2018-02-26 8:28 ` Jan Beulich
2018-02-26 12:33 ` Chao Gao
2018-02-26 14:19 ` Roger Pau Monné
2018-04-18 8:38 ` Jan Beulich
2018-04-18 11:20 ` Chao Gao
2018-04-18 11:50 ` Jan Beulich
2017-12-06 7:50 ` [RFC Patch v4 5/8] Tool/ACPI: DSDT extension to support more vcpus Chao Gao
2017-12-06 7:50 ` [RFC Patch v4 6/8] hvmload: Add x2apic entry support in the MADT and SRAT build Chao Gao
2018-04-18 8:48 ` Jan Beulich
2017-12-06 7:50 ` [RFC Patch v4 7/8] x86/hvm: bump the number of pages of shadow memory Chao Gao
2018-02-27 14:17 ` George Dunlap
2018-04-18 8:53 ` Jan Beulich
2018-04-18 11:39 ` Chao Gao
2018-04-18 11:50 ` Andrew Cooper
2018-04-18 11:59 ` Jan Beulich
2017-12-06 7:50 ` [RFC Patch v4 8/8] x86/hvm: bump the maximum number of vcpus to 512 Chao Gao
2018-02-22 18:46 ` Wei Liu
2018-02-23 8:50 ` Jan Beulich
2018-02-23 17:18 ` Wei Liu
2018-02-23 18:11 ` Roger Pau Monné
2018-02-24 6:26 ` Chao Gao
2018-02-26 8:26 ` Jan Beulich
2018-02-26 13:11 ` Chao Gao
2018-02-26 16:10 ` Jan Beulich
2018-03-01 5:21 ` Chao Gao
2018-03-01 7:17 ` Juergen Gross
2018-03-01 7:37 ` Jan Beulich
2018-03-01 7:11 ` Chao Gao
2018-02-27 14:59 ` George Dunlap
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1512546614-9937-5-git-send-email-chao.gao@intel.com \
--to=chao.gao@intel.com \
--cc=andrew.cooper3@citrix.com \
--cc=ian.jackson@eu.citrix.com \
--cc=jbeulich@suse.com \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).