From dc7d3470e6329495194194cff35e777eb551c6ab Mon Sep 17 00:00:00 2001 From: ouyangxiangzhen Date: Fri, 6 Sep 2024 19:03:03 +0800 Subject: [PATCH] arch/x86_64: Fix wrong RDTSCP implementation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit RDTSCP instruction reads the current value of the processor’s time-stamp counter (a 64-bit MSR) into the EDX:EAX registers, and it also reads the value of the IA32_TSC_AUX MSR (address C0000103H) into the ECX register. However, the current RDTSCP implementation does not provide a hint for the compiler that ECX has been changed, resulting in register corrupted and subtle errors. Signed-off-by: ouyangxiangzhen --- arch/x86_64/include/intel64/irq.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86_64/include/intel64/irq.h b/arch/x86_64/include/intel64/irq.h index 90e9372a91..3979c907dc 100644 --- a/arch/x86_64/include/intel64/irq.h +++ b/arch/x86_64/include/intel64/irq.h @@ -535,7 +535,7 @@ static inline uint64_t rdtscp(void) uint32_t lo; uint32_t hi; - asm volatile("rdtscp" : "=a" (lo), "=d" (hi)::"memory"); + asm volatile("rdtscp" : "=a" (lo), "=d" (hi)::"ecx", "memory"); return (uint64_t)lo | (((uint64_t)hi) << 32); }