Author: gb
Date: Sun Feb  4 16:04:48 2007
New Revision: 116153

Added:
   packages/cooker/virtualbox/current/SOURCES/vbox-1.3.3-disable-nmi.patch
Modified:
   packages/cooker/virtualbox/current/SPECS/virtualbox.spec

Log:
SILENT try to disable NMI on x86_64 too.


Added: packages/cooker/virtualbox/current/SOURCES/vbox-1.3.3-disable-nmi.patch
==============================================================================
--- (empty file)
+++ packages/cooker/virtualbox/current/SOURCES/vbox-1.3.3-disable-nmi.patch     
Sun Feb  4 16:04:48 2007
@@ -0,0 +1,219 @@
+2007-02-04  Gwenole Beauchesne  <[EMAIL PROTECTED]>
+
+       * Try to disable the NMI watchdog on x86_64 too.
+
+--- vbox-1.3.3/src/VBox/HostDrivers/Support/linux/SUPDrv-linux.c.disable-nmi   
2007-01-29 11:56:27.000000000 +0100
++++ vbox-1.3.3/src/VBox/HostDrivers/Support/linux/SUPDrv-linux.c       
2007-02-04 15:40:29.000000000 +0100
+@@ -276,6 +276,150 @@ static struct miscdevice gMiscDevice =
+ };
+ #endif
+ 
++#ifdef CONFIG_X86_LOCAL_APIC
++/* Machinery to disable NMI. XXX: this doesn't try to restore it on module 
unload. */
++# ifdef __AMD64__
++#  define DO_DISABLE_NMI 1
++# endif
++
++# if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19)
++extern int nmi_active;
++#  define nmi_atomic_read(P)    *(P)
++#  define nmi_atomic_set(P, V)  *(P) = (V)
++#  define nmi_atomic_dec(P)     nmi_atomic_set(P, 0)
++# else
++#  define nmi_atomic_read(P)    atomic_read(P)
++#  define nmi_atomic_set(P, V)  atomic_set(P, V)
++#  define nmi_atomic_dec(P)     atomic_dec(P)
++# endif
++
++# ifndef X86_FEATURE_ARCH_PERFMON
++#  define X86_FEATURE_ARCH_PERFMON (3*32+9) /* Intel Architectural PerfMon */
++# endif
++# ifndef MSR_ARCH_PERFMON_EVENTSEL0
++#  define MSR_ARCH_PERFMON_EVENTSEL0 0x186
++# endif
++# ifndef ARCH_PERFMON_UNHALTED_CORE_CYCLES_PRESENT
++#  define ARCH_PERFMON_UNHALTED_CORE_CYCLES_PRESENT (1 << 0)
++# endif
++
++# if DO_DISABLE_NMI
++#  if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17)
++#   error "FIXME: not tested on kernels newer than 2.6.17"
++#  endif
++
++/** Stop AMD NMI watchdog. */
++static int stop_k7_watchdog(void)
++{
++    wrmsr(MSR_K7_EVNTSEL0, 0, 0);
++    return 1;
++}
++
++/** Stop Intel NMI watchdog. */
++static int stop_p4_watchdog(void)
++{
++#  if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 12)
++    if (boot_cpu_data.x86 == 15)
++    {
++        wrmsr(MSR_P4_IQ_CCCR0, 0, 0);
++        wrmsr(MSR_P4_CRU_ESCR0, 0, 0);
++        return 1;
++    }
++#  elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 3)
++    wrmsr(MSR_IA32_EVNTSEL0, 0, 0);
++    return 1;
++#  endif
++    return 0;
++}
++
++static int stop_intel_arch_watchdog(void)
++{
++#  if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 18)
++    unsigned ebx;
++
++    ebx = cpuid_ebx(10);
++    if (!(ebx & ARCH_PERFMON_UNHALTED_CORE_CYCLES_PRESENT))
++        wrmsr(MSR_ARCH_PERFMON_EVENTSEL0, 0, 0);
++    return 1;
++#  endif
++    return 0;
++}
++
++/** Stop NMI watchdog. */
++static void stop_apic_nmi_watchdog(void *unused)
++{
++    int stopped = 0;
++
++    /* only support LOCAL and IO APICs for now */
++    if ((nmi_watchdog != NMI_LOCAL_APIC) &&
++        (nmi_watchdog != NMI_IO_APIC))
++        return;
++
++    if (nmi_watchdog == NMI_LOCAL_APIC)
++    {
++        switch (boot_cpu_data.x86_vendor)
++        {
++        case X86_VENDOR_AMD:
++            if (strstr(boot_cpu_data.x86_model_id, "Screwdriver"))
++                return;
++            stopped = stop_k7_watchdog();
++            break;
++        case X86_VENDOR_INTEL:
++            if (cpu_has(&boot_cpu_data, X86_FEATURE_ARCH_PERFMON))
++            {
++                stopped = stop_intel_arch_watchdog();
++                break;
++            }
++            stopped = stop_p4_watchdog();
++            break;
++        default:
++            return;
++        }
++    }
++
++    if (stopped)
++        nmi_atomic_dec(&nmi_active);
++}
++
++/** Disable LAPIC NMI watchdog. */
++static void disable_lapic_nmi_watchdog(void)
++{
++    BUG_ON(nmi_watchdog != NMI_LOCAL_APIC);
++
++    if (nmi_atomic_read(&nmi_active) <= 0)
++        return;
++
++    on_each_cpu(stop_apic_nmi_watchdog, NULL, 0, 1);
++
++    BUG_ON(nmi_atomic_read(&nmi_active) != 0);
++
++    /* tell do_nmi() and others that we're not active any more */
++    nmi_watchdog = NMI_NONE;
++}
++
++/** Shutdown NMI. */
++static void nmi_cpu_shutdown(void * dummy)
++{
++    unsigned int vERR, vPC;
++
++    vPC = apic_read(APIC_LVTPC);
++
++    if ((GET_APIC_DELIVERY_MODE(vPC) == APIC_MODE_NMI) && !(vPC & 
APIC_LVT_MASKED))
++    {
++        vERR = apic_read(APIC_LVTERR);
++        apic_write(APIC_LVTERR, vERR | APIC_LVT_MASKED);
++        apic_write(APIC_LVTPC,  vPC  | APIC_LVT_MASKED);
++        apic_write(APIC_LVTERR, vERR);
++    }
++}
++
++static void nmi_shutdown(void)
++{
++    on_each_cpu(nmi_cpu_shutdown, NULL, 0, 1);
++}
++# endif
++#endif
++
+ 
+ /**
+  * Initialize module.
+@@ -300,7 +444,33 @@ static int __init VBoxSupDrvInit(void)
+      * First test: NMI actiated? Works only works with Linux 2.6 -- 2.4 does 
not export
+      *             the nmi_watchdog variable.
+      */
+-#  if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19)
++#  if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19) || (defined 
CONFIG_X86_64 && LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 3))
++    /*
++     * Try to disable NMI
++     */
++#   if DO_DISABLE_NMI
++    if (nmi_atomic_read(&nmi_active) > 0)
++    {
++        printk(KERN_INFO DEVICE_NAME ": Trying to deactivate NMI 
watchdog...\n");
++
++        switch (nmi_watchdog)
++        {
++        case NMI_LOCAL_APIC:
++            disable_lapic_nmi_watchdog();
++            break;
++        case NMI_NONE:
++            nmi_atomic_dec(&nmi_active);
++            break;
++        }
++
++        if (nmi_atomic_read(&nmi_active) == 0)
++        {
++            nmi_shutdown();
++            printk(KERN_INFO DEVICE_NAME ": Successfully done.\n");
++        }
++    }
++#   endif
++
+     /*
+      * Permanent IO_APIC mode active? No way to handle this!
+      */
+@@ -318,7 +488,7 @@ static int __init VBoxSupDrvInit(void)
+     /*
+      * See arch/i386/kernel/nmi.c on >= 2.6.19: -1 means it can never enabled 
again
+      */
+-    atomic_set(&nmi_active, -1);
++    nmi_atomic_set(&nmi_active, -1);
+     printk(KERN_INFO DEVICE_NAME ": Trying to deactivate NMI watchdog 
permanently...\n");
+ 
+     /*
+@@ -353,7 +523,7 @@ static int __init VBoxSupDrvInit(void)
+             /* performance counter generates NMI and is not masked? */
+             if ((GET_APIC_DELIVERY_MODE(v) == APIC_MODE_NMI) && !(v & 
APIC_LVT_MASKED))
+             {
+-# if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19)
++# if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19) || (defined CONFIG_X86_64 
&& LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 3))
+                 printk(KERN_ERR DEVICE_NAME
+                 ": NMI watchdog either active or at least initialized. Please 
disable the NMI\n"
+                                 DEVICE_NAME
+@@ -372,7 +542,7 @@ nmi_activated:
+             }
+         }
+     }
+-# if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19)
++# if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19) || (defined CONFIG_X86_64 
&& LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 3))
+     printk(KERN_INFO DEVICE_NAME ": Successfully done.\n");
+ # endif /* >= 2.6.19 */
+ #endif /* CONFIG_X86_LOCAL_APIC */

Modified: packages/cooker/virtualbox/current/SPECS/virtualbox.spec
==============================================================================
--- packages/cooker/virtualbox/current/SPECS/virtualbox.spec    (original)
+++ packages/cooker/virtualbox/current/SPECS/virtualbox.spec    Sun Feb  4 
16:04:48 2007
@@ -33,6 +33,7 @@
 Source12:      virtualbox.48.png
 Patch0:                vbox-1.3.3-mdvconfig.patch
 Patch1:                vbox-1.3.3-64bit-fixes.patch
+Patch2:                vbox-1.3.3-disable-nmi.patch
 License:       GPL
 Group:         Emulators
 Url:           http://www.virtualbox.org/
@@ -73,6 +74,7 @@
 %setup -q -n %{pkgname}-%{ver}
 %patch0 -p1 -b .mdvconfig
 %patch1 -p1 -b .64bit-fixes
+%patch2 -p1 -b .disable-nmi
 
 %build
 export LIBPATH_LIB="%{_lib}"

Reply via email to