lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <1285027196.9954.45.camel@ank32.eng.vmware.com>
Date:	Mon, 20 Sep 2010 16:59:56 -0700
From:	Alok Kataria <akataria@...are.com>
To:	Thomas Gleixner <tglx@...utronix.de>
Cc:	"H. Peter Anvin" <hpa@...or.com>, Ingo Molnar <mingo@...e.hu>,
	the arch/x86 maintainers <x86@...nel.org>,
	LKML <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] x86,apic: V2 Add apic calibration hook.


On Mon, 2010-09-20 at 16:34 -0700, Alok Kataria wrote:

> Below is the preparatory change, will followup with the 2nd patch which
> introduces the actual hook.

Below is the 2nd patch.
--
Add apic timer calibration hook.

From: Alok N Kataria <akataria@...are.com>

Add a new function ptr calibrate_apic_clock to x86_init_timers structure.
On native this does the usual apic calibration. On VMware's platform we
override it with a routine which gets that information from the hypervisor.

Signed-off-by: Alok N Kataria <akataria@...are.com>

Index: linux-x86-tree.git/arch/x86/include/asm/apic.h
===================================================================
--- linux-x86-tree.git.orig/arch/x86/include/asm/apic.h	2010-09-20 16:05:58.000000000 -0700
+++ linux-x86-tree.git/arch/x86/include/asm/apic.h	2010-09-20 16:36:42.000000000 -0700
@@ -17,6 +17,10 @@
 
 #define ARCH_APICTIMER_STOPS_ON_C3	1
 
+/* Clock divisor */
+#define APIC_DIVISOR	16
+#define LAPIC_CAL_LOOPS	(HZ/10)
+
 /*
  * Debugging macros
  */
@@ -238,6 +242,8 @@ extern void setup_boot_APIC_clock(void);
 extern void setup_secondary_APIC_clock(void);
 extern int APIC_init_uniprocessor(void);
 extern void enable_NMI_through_LVT0(void);
+extern int native_calibrate_apic_clock(void);
+extern int initialize_lapic_timer(long delta, unsigned int calibration_result);
 
 /*
  * On 32bit this is mach-xxx local
Index: linux-x86-tree.git/arch/x86/include/asm/x86_init.h
===================================================================
--- linux-x86-tree.git.orig/arch/x86/include/asm/x86_init.h	2010-09-20 16:06:11.000000000 -0700
+++ linux-x86-tree.git/arch/x86/include/asm/x86_init.h	2010-09-20 16:54:08.000000000 -0700
@@ -83,11 +83,13 @@ struct x86_init_paging {
  *				boot cpu
  * @tsc_pre_init:		platform function called before TSC init
  * @timer_init:			initialize the platform timer (default PIT/HPET)
+ * @calibrate_apic_clock:	calibrate APIC clock freq (ticks per HZ)
  */
 struct x86_init_timers {
 	void (*setup_percpu_clockev)(void);
 	void (*tsc_pre_init)(void);
 	void (*timer_init)(void);
+	int (*calibrate_apic_clock)(void);
 };
 
 /**
Index: linux-x86-tree.git/arch/x86/kernel/cpu/vmware.c
===================================================================
--- linux-x86-tree.git.orig/arch/x86/kernel/cpu/vmware.c	2010-09-20 16:05:30.000000000 -0700
+++ linux-x86-tree.git/arch/x86/kernel/cpu/vmware.c	2010-09-20 16:40:35.000000000 -0700
@@ -26,6 +26,7 @@
 #include <asm/div64.h>
 #include <asm/x86_init.h>
 #include <asm/hypervisor.h>
+#include <asm/apic.h>
 
 #define CPUID_VMWARE_INFO_LEAF	0x40000000
 #define VMWARE_HYPERVISOR_MAGIC	0x564D5868
@@ -72,17 +73,40 @@ static unsigned long vmware_get_tsc_khz(
 	return tsc_hz;
 }
 
+static int __init vmware_calibrate_apic_clock(void)
+{
+	unsigned int calibration_result;
+	uint32_t eax, ebx, ecx, edx;
+	int err;
+	long delta;
+	unsigned long flags;
+
+	VMWARE_PORT(GETHZ, eax, ebx, ecx, edx);
+	BUG_ON(!ecx);
+	calibration_result = ecx / HZ;
+
+	printk(KERN_INFO "APIC bus freq read from hypervisor\n");
+
+	delta  = (calibration_result * LAPIC_CAL_LOOPS) / APIC_DIVISOR;
+	local_irq_save(flags);
+	err = initialize_lapic_timer(delta, calibration_result);
+	local_irq_restore(flags);
+
+	return err;
+}
+
 static void __init vmware_platform_setup(void)
 {
 	uint32_t eax, ebx, ecx, edx;
 
 	VMWARE_PORT(GETHZ, eax, ebx, ecx, edx);
 
-	if (ebx != UINT_MAX)
+	if (ebx != UINT_MAX) {
 		x86_platform.calibrate_tsc = vmware_get_tsc_khz;
-	else
+		x86_init.timers.calibrate_apic_clock = vmware_calibrate_apic_clock;
+	} else
 		printk(KERN_WARNING
-		       "Failed to get TSC freq from the hypervisor\n");
+		       "Failed to setup VMware hypervisor platform\n");
 }
 
 /*
Index: linux-x86-tree.git/arch/x86/kernel/x86_init.c
===================================================================
--- linux-x86-tree.git.orig/arch/x86/kernel/x86_init.c	2010-09-20 16:05:07.000000000 -0700
+++ linux-x86-tree.git/arch/x86/kernel/x86_init.c	2010-09-20 16:41:21.000000000 -0700
@@ -68,6 +68,7 @@ struct x86_init_ops x86_init __initdata 
 		.setup_percpu_clockev	= setup_boot_APIC_clock,
 		.tsc_pre_init		= x86_init_noop,
 		.timer_init		= hpet_time_init,
+		.calibrate_apic_clock	= native_calibrate_apic_clock
 	},
 
 	.iommu = {
Index: linux-x86-tree.git/arch/x86/kernel/apic/apic.c
===================================================================
--- linux-x86-tree.git.orig/arch/x86/kernel/apic/apic.c	2010-09-20 16:10:13.000000000 -0700
+++ linux-x86-tree.git/arch/x86/kernel/apic/apic.c	2010-09-20 16:42:12.000000000 -0700
@@ -326,13 +326,6 @@ int lapic_get_maxlvt(void)
 }
 
 /*
- * Local APIC timer
- */
-
-/* Clock divisor */
-#define APIC_DIVISOR 16
-
-/*
  * This function sets up the local APIC timer, with a timeout of
  * 'clocks' APIC bus clock. During calibration we actually call
  * this function twice on the boot CPU, once with a bogus timeout
@@ -500,8 +493,6 @@ static void __cpuinit setup_APIC_timer(v
  * back to normal later in the boot process).
  */
 
-#define LAPIC_CAL_LOOPS		(HZ/10)
-
 static __initdata int lapic_cal_loops = -1;
 static __initdata long lapic_cal_t1, lapic_cal_t2;
 static __initdata unsigned long long lapic_cal_tsc1, lapic_cal_tsc2;


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ