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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1582744258-42744-2-git-send-email-kyung.min.park@intel.com>
Date:   Wed, 26 Feb 2020 11:10:57 -0800
From:   Kyung Min Park <kyung.min.park@...el.com>
To:     x86@...nel.org, linux-kernel@...r.kernel.org
Cc:     tglx@...utronix.de, mingo@...hat.com, hpa@...or.com,
        gregkh@...uxfoundation.org, ak@...ux.intel.com,
        tony.luck@...el.com, ashok.raj@...el.com, ravi.v.shankar@...el.com,
        fenghua.yu@...el.com
Subject: [PATCH 1/2] x86/asm: Define a few helpers in delay_waitx()

Refactor code to make it easier to add a new model specific function to
delay for a number of cycles.

No functional change.

Reviewed-by: Tony Luck <tony.luck@...el.com>
Co-developed-by: Fenghua Yu <fenghua.yu@...el.com>
Signed-off-by: Fenghua Yu <fenghua.yu@...el.com>
Signed-off-by: Kyung Min Park <kyung.min.park@...el.com>
---
 arch/x86/lib/delay.c | 58 +++++++++++++++++++++++++++++++++-------------------
 1 file changed, 37 insertions(+), 21 deletions(-)

diff --git a/arch/x86/lib/delay.c b/arch/x86/lib/delay.c
index c126571..6be29cf 100644
--- a/arch/x86/lib/delay.c
+++ b/arch/x86/lib/delay.c
@@ -90,9 +90,36 @@ static void delay_tsc(unsigned long __loops)
  * counts with TSC frequency. The input value is the loop of the
  * counter, it will exit when the timer expires.
  */
-static void delay_mwaitx(unsigned long __loops)
+static void mwaitx(u64 unused, u64 loops)
 {
-	u64 start, end, delay, loops = __loops;
+	u64 delay;
+
+	delay = min_t(u64, MWAITX_MAX_LOOPS, loops);
+	/*
+	 * Use cpu_tss_rw as a cacheline-aligned, seldomly
+	 * accessed per-cpu variable as the monitor target.
+	 */
+	__monitorx(raw_cpu_ptr(&cpu_tss_rw), 0, 0);
+
+	/*
+	 * AMD, like Intel, supports the EAX hint and EAX=0xf
+	 * means, do not enter any deep C-state and we use it
+	 * here in delay() to minimize wakeup latency.
+	 */
+	__mwaitx(MWAITX_DISABLE_CSTATES, delay, MWAITX_ECX_TIMER_ENABLE);
+}
+
+static void (*wait_func)(u64, u64);
+
+/*
+ * Call a vendor specific function to delay for a given
+ * amount of time. Because these functions may return
+ * earlier than requested, check for actual elapsed time
+ * and call again until done.
+ */
+static void delay_iterate(unsigned long __loops)
+{
+	u64 start, end, loops = __loops;
 
 	/*
 	 * Timer value of 0 causes MWAITX to wait indefinitely, unless there
@@ -104,20 +131,8 @@ static void delay_mwaitx(unsigned long __loops)
 	start = rdtsc_ordered();
 
 	for (;;) {
-		delay = min_t(u64, MWAITX_MAX_LOOPS, loops);
-
-		/*
-		 * Use cpu_tss_rw as a cacheline-aligned, seldomly
-		 * accessed per-cpu variable as the monitor target.
-		 */
-		__monitorx(raw_cpu_ptr(&cpu_tss_rw), 0, 0);
 
-		/*
-		 * AMD, like Intel's MWAIT version, supports the EAX hint and
-		 * EAX=0xf0 means, do not enter any deep C-state and we use it
-		 * here in delay() to minimize wakeup latency.
-		 */
-		__mwaitx(MWAITX_DISABLE_CSTATES, delay, MWAITX_ECX_TIMER_ENABLE);
+		wait_func(start, loops);
 
 		end = rdtsc_ordered();
 
@@ -134,22 +149,23 @@ static void delay_mwaitx(unsigned long __loops)
  * Since we calibrate only once at boot, this
  * function should be set once at boot and not changed
  */
-static void (*delay_fn)(unsigned long) = delay_loop;
+static void (*delay_platform)(unsigned long) = delay_loop;
 
 void use_tsc_delay(void)
 {
-	if (delay_fn == delay_loop)
-		delay_fn = delay_tsc;
+	if (delay_platform == delay_loop)
+		delay_platform = delay_tsc;
 }
 
 void use_mwaitx_delay(void)
 {
-	delay_fn = delay_mwaitx;
+	wait_func = mwaitx;
+	delay_platform = delay_iterate;
 }
 
 int read_current_timer(unsigned long *timer_val)
 {
-	if (delay_fn == delay_tsc) {
+	if (delay_platform == delay_tsc) {
 		*timer_val = rdtsc();
 		return 0;
 	}
@@ -158,7 +174,7 @@ int read_current_timer(unsigned long *timer_val)
 
 void __delay(unsigned long loops)
 {
-	delay_fn(loops);
+	delay_platform(loops);
 }
 EXPORT_SYMBOL(__delay);
 
-- 
2.7.4

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ