All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Keir Fraser <keir.xen@gmail.com>
Cc: Ian Campbell <Ian.Campbell@eu.citrix.com>,
	"xen-devel@lists.xensource.com" <xen-devel@lists.xensource.com>,
	Jan Beulich <JBeulich@novell.com>
Subject: Re: [PATCH 4 of 7] APIC: record local APIC state on boot [Reformatted]
Date: Wed, 15 Jun 2011 14:38:38 +0100	[thread overview]
Message-ID: <4DF8B5DE.5090208@citrix.com> (raw)
In-Reply-To: <CA1E675B.1C3DC%keir.xen@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 888 bytes --]



On 15/06/11 13:42, Keir Fraser wrote:
> On 15/06/2011 13:33, "Andrew Cooper" <andrew.cooper3@citrix.com> wrote:
>
>> It turns out that we do require apic_boot_mode to be accessible outside
>> in a later reformatted patch so that cant be static any more.
>>
>> Suggested changes for acpi_mode_to_str have been taken, along with
>> removing its declaration from apic.h and putting it at the top of apic.c
> I applied some of you series already to xen-unstable tip. Please re-send the
> remaining bits you need as a new series against tip.
>
>  -- Keir
Ah - I am working against the wrong unstable.  Here is the change
against staging unstable.

Also, is it wise having extern enum apic_mode
current_local_apic_mode(void); is apic.h if the function itself is
static inside apic.c? 

-- 
Andrew Cooper - Dom0 Kernel Engineer, Citrix XenServer
T: +44 (0)1223 225 900, http://www.citrix.com


[-- Attachment #2: apic-record-boot-mode.patch --]
[-- Type: text/x-patch, Size: 4304 bytes --]

APIC: record local APIC state on boot

Xen does not store the boot local APIC state which leads to problems
when shutting down for a kexec jump.  This patch records the boot
state so we can return to the boot state when kexecing.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>

diff -r e32752440713 xen/arch/x86/apic.c
--- a/xen/arch/x86/apic.c	Wed Jun 15 12:02:13 2011 +0100
+++ b/xen/arch/x86/apic.c	Wed Jun 15 13:30:08 2011 +0100
@@ -74,6 +74,11 @@ u8 __read_mostly apic_verbosity;
 static bool_t __initdata opt_x2apic = 1;
 boolean_param("x2apic", opt_x2apic);
 
+enum apic_mode apic_boot_mode = APIC_MODE_INVALID;
+
+/* enum apic_mode -> str function for logging/debug */
+static const char * apic_mode_to_str(const enum apic_mode);
+
 bool_t __read_mostly x2apic_enabled = 0;
 bool_t __read_mostly directed_eoi_enabled = 0;
 
@@ -1438,6 +1443,62 @@ int __init APIC_init_uniprocessor (void)
     return 0;
 }
 
+/* Needs to be called during startup.  It records the state the BIOS
+ * leaves the local APIC so we can undo upon kexec.
+ */
+void __init record_boot_APIC_mode(void)
+{
+    /* Sanity check - we should only ever run once, but could possibly
+     * be called several times */
+    if ( APIC_MODE_INVALID != apic_boot_mode )
+        return;
+
+    apic_boot_mode = current_local_apic_mode();
+
+    apic_printk(APIC_DEBUG, "APIC boot state is '%s'\n",
+                apic_mode_to_str(apic_boot_mode));
+}
+
+/* Look at the bits in MSR_IA32_APICBASE and work out which
+ * APIC mode we are in */
+enum apic_mode current_local_apic_mode(void)
+{
+    u64 msr_contents;
+
+    rdmsrl(MSR_IA32_APICBASE, msr_contents);
+
+    /* Reading EXTD bit from the MSR is only valid if CPUID
+     * says so, else reserved */
+    if ( cpu_has(&current_cpu_data, X86_FEATURE_X2APIC)
+         && (msr_contents & MSR_IA32_APICBASE_EXTD) )
+        return APIC_MODE_X2APIC;
+
+    /* EN bit should always be valid as long as we can read the MSR
+     */
+    if ( msr_contents & MSR_IA32_APICBASE_ENABLE )
+        return APIC_MODE_XAPIC;
+
+    return APIC_MODE_DISABLED;
+}
+
+
+static const char * __init apic_mode_to_str(const enum apic_mode mode)
+{
+    switch ( mode )
+    {
+        case APIC_MODE_INVALID:
+            return "invalid";
+        case APIC_MODE_DISABLED:
+            return "disabled";
+        case APIC_MODE_XAPIC:
+            return "xapic";
+        case APIC_MODE_X2APIC:
+            return "x2apic";
+        default:
+            return "unrecognised";
+    }
+}
+
 void check_for_unexpected_msi(unsigned int vector)
 {
     unsigned long v = apic_read(APIC_ISR + ((vector & ~0x1f) >> 1));
diff -r e32752440713 xen/arch/x86/genapic/probe.c
--- a/xen/arch/x86/genapic/probe.c	Wed Jun 15 12:02:13 2011 +0100
+++ b/xen/arch/x86/genapic/probe.c	Wed Jun 15 13:30:08 2011 +0100
@@ -60,6 +60,8 @@ void __init generic_apic_probe(void)
 { 
 	int i, changed;
 
+	record_boot_APIC_mode();
+
 	check_x2apic_preenabled();
 	cmdline_apic = changed = (genapic != NULL);
 
diff -r e32752440713 xen/include/asm-x86/apic.h
--- a/xen/include/asm-x86/apic.h	Wed Jun 15 12:02:13 2011 +0100
+++ b/xen/include/asm-x86/apic.h	Wed Jun 15 13:30:08 2011 +0100
@@ -21,6 +21,20 @@
 #define IO_APIC_REDIR_DEST_LOGICAL	0x00800
 #define IO_APIC_REDIR_DEST_PHYSICAL	0x00000
 
+/* Possible APIC states */
+enum apic_mode { APIC_MODE_INVALID,  /* Not set yet */
+                 APIC_MODE_DISABLED, /* If uniprocessor, or smp in
+                                      * uniprocessor mode */
+                 APIC_MODE_XAPIC,    /* xAPIC mode - default upon
+                                      * chipset reset */
+                 APIC_MODE_X2APIC    /* x2APIC mode - common for large
+                                      * smp machines */
+};
+
+/* Bootstrap processor local APIC boot mode - so we can undo our changes
+ * to the APIC state */
+extern enum apic_mode apic_boot_mode;
+
 extern u8 apic_verbosity;
 extern bool_t x2apic_enabled;
 extern bool_t directed_eoi_enabled;
@@ -203,6 +217,8 @@ extern void disable_APIC_timer(void);
 extern void enable_APIC_timer(void);
 extern int lapic_suspend(void);
 extern int lapic_resume(void);
+extern void record_boot_APIC_mode(void);
+extern enum apic_mode current_local_apic_mode(void);
 
 extern int check_nmi_watchdog (void);
 

[-- Attachment #3: Type: text/plain, Size: 138 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel

  reply	other threads:[~2011-06-15 13:38 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-13 17:02 [PATCH 0 of 7] Fix kexec in Xen (take 4) Andrew Cooper
2011-06-13 17:02 ` [PATCH 1 of 7] APIC BUG: fix potential Protection Fault during shutdown Andrew Cooper
2011-06-14  8:44   ` Jan Beulich
2011-06-14  9:44     ` Andrew Cooper
2011-06-13 17:02 ` [PATCH 2 of 7] KEXEC BUG: nmi_shootdown_cpus doesn't look after the interrupt flag Andrew Cooper
2011-06-14  8:46   ` Jan Beulich
2011-06-14  9:46     ` Keir Fraser
2011-06-15 11:01       ` [PATCH 2 of 7] KEXEC BUG: nmi_shootdown_cpus doesn't look after the interrupt flag [Reformatted] Andrew Cooper
2011-06-14  9:51     ` [PATCH 2 of 7] KEXEC BUG: nmi_shootdown_cpus doesn't look after the interrupt flag Andrew Cooper
2011-06-13 17:02 ` [PATCH 3 of 7] IOMMU: Sanitise pointer work Andrew Cooper
2011-06-13 18:13   ` Keir Fraser
2011-06-14  9:53     ` Andrew Cooper
2011-06-14 11:51       ` Keir Fraser
2011-06-13 17:02 ` [PATCH 4 of 7] APIC: record local APIC state on boot Andrew Cooper
2011-06-14  8:57   ` Jan Beulich
2011-06-14 10:48     ` Ian Campbell
2011-06-14 11:21       ` Jan Beulich
2011-06-15 12:33         ` [PATCH 4 of 7] APIC: record local APIC state on boot [Reformatted] Andrew Cooper
2011-06-15 12:42           ` Keir Fraser
2011-06-15 13:38             ` Andrew Cooper [this message]
2011-06-15 14:49               ` Andrew Cooper
2011-06-15 12:50           ` Jan Beulich
2011-06-13 17:02 ` [PATCH 5 of 7] IOMMU VTD BUG: disable Extended Interrupt Mode when disabling Interupt Remapping Andrew Cooper
2011-06-14  9:02   ` Jan Beulich
2011-06-14  9:59     ` Andrew Cooper
2011-06-14 21:20     ` Kay, Allen M
2011-06-15  6:48       ` Jan Beulich
2011-06-15  7:45         ` Ian Campbell
2011-06-15 14:49           ` [PATCH 5 of 7] IOMMU VTD BUG: disable Extended Interrupt Mode when disabling Interupt Remapping [Reformatted] Andrew Cooper
2011-06-14 21:45   ` [PATCH 5 of 7] IOMMU VTD BUG: disable Extended Interrupt Mode when disabling Interupt Remapping Kay, Allen M
2011-06-13 17:02 ` [PATCH 6 of 7] IOMMU: add crash_shutdown iommu_op Andrew Cooper
2011-06-14 12:10   ` Keir Fraser
2011-06-15 12:50     ` Andrew Cooper
2011-06-14 22:15   ` Kay, Allen M
2011-06-15 13:06     ` Andrew Cooper
2011-06-15 16:39       ` Kay, Allen M
2011-06-15 15:00     ` [PATCH 6 of 7] IOMMU: add crash_shutdown iommu_op [Reformatted] Andrew Cooper
2011-06-13 17:02 ` [PATCH 7 of 7] KEXEC: correctly revert x2apic state when kexecing Andrew Cooper
2011-06-14 12:11   ` Keir Fraser
2011-06-14 13:05     ` Andrew Cooper
2011-06-13 18:15 ` [PATCH 0 of 7] Fix kexec in Xen (take 4) Keir Fraser
2011-06-16 13:05   ` Andrew Cooper
2011-06-16 13:13     ` Keir Fraser

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=4DF8B5DE.5090208@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=Ian.Campbell@eu.citrix.com \
    --cc=JBeulich@novell.com \
    --cc=keir.xen@gmail.com \
    --cc=xen-devel@lists.xensource.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.