Return-Path: Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:60982 "EHLO mx0b-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753289AbbGaWL6 (ORCPT ); Fri, 31 Jul 2015 18:11:58 -0400 Received: from pps.filterd (m0004077 [127.0.0.1]) by mx0b-00082601.pphosted.com (8.14.5/8.14.5) with SMTP id t6VM8DKe005642 for ; Fri, 31 Jul 2015 15:11:57 -0700 Received: from mail.thefacebook.com ([199.201.64.23]) by mx0b-00082601.pphosted.com with ESMTP id 1w0hd9g1fe-1 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT) for ; Fri, 31 Jul 2015 15:11:57 -0700 Received: from facebook.com (2401:db00:20:7003:face:0:4d:0) by mx-out.facebook.com (10.103.99.99) with ESMTP id 27a5a8ea37d111e5a3e50002c9dfb610-957fd2b0 for ; Fri, 31 Jul 2015 15:11:55 -0700 From: Shaohua Li To: , CC: , Suresh Siddha , Thomas Gleixner , "H. Peter Anvin" , Ingo Molnar , , Subject: [PATCH] x86: serialize LVTT and TSC_DEADLINE write Date: Fri, 31 Jul 2015 15:11:55 -0700 Message-ID: <75ed9226b028a31e37861fbba51cdffbcfe04eda.1438300532.git.shli@fb.com> MIME-Version: 1.0 Content-Type: text/plain Sender: stable-owner@vger.kernel.org List-ID: We saw a strange issue with local APIC timer. Some random CPU doesn't receive any local APIC timer interrupt, which causes different issues. The cpu uses TSC-Deadline mode for local APIC timer and APIC is in xAPIC mode. When this happens, manually writing TSC_DEADLINE MSR can trigger interrupt again and the system goes normal. Currently we only see this issue in E5-2660 v2 and E5-2680 v2 CPU. Compiler version seems mattering too, it's quite easy to reproduce the issue with v4.7 gcc. Since the local APIC timer interrupt number is 0, we either lose the first interrupt or TSC_DEADLINE MSR isn't set correctly. After some debugging, we believe it's the serialize issue described in Intel SDM. In xAPIC mode, write to APIC LVTT and write to TSC_DEADLINE isn't serialized. Debug shows read TSC_DEADLINE MSR followed the very first MSR write returns 0 in the buggy cpu. The patch uses the algorithm Intel SDM described. The issue only happens in xAPIC mode, but it doesn't bother to check the APIC mode I guess. Without this patch, we see the issue after ~5 reboots. With it, we don't see it after 24hr reboot test. Cc: Suresh Siddha Cc: Thomas Gleixner Cc: H. Peter Anvin Cc: Ingo Molnar Cc: stable@vger.kernel.org v3.7+ Signed-off-by: Shaohua Li --- arch/x86/kernel/apic/apic.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c index dcb5285..b7890b3 100644 --- a/arch/x86/kernel/apic/apic.c +++ b/arch/x86/kernel/apic/apic.c @@ -336,6 +336,22 @@ static void __setup_APIC_LVTT(unsigned int clocks, int oneshot, int irqen) apic_write(APIC_LVTT, lvtt_value); if (lvtt_value & APIC_LVT_TIMER_TSCDEADLINE) { + u64 msr; + + /* + * See Intel SDM: TSC-Deadline Mode chapter. In xAPIC mode, + * writing APIC LVTT and TSC_DEADLINE MSR isn't serialized. + * This uses the algorithm described in Intel SDM to serialize + * the two writes + * */ + while (1) { + wrmsrl(MSR_IA32_TSC_DEADLINE, -1L); + rdmsrl(MSR_IA32_TSC_DEADLINE, msr); + if (msr) + break; + } + wrmsrl(MSR_IA32_TSC_DEADLINE, 0); + printk_once(KERN_DEBUG "TSC deadline timer enabled\n"); return; } -- 1.8.5.6