Received: by 10.223.185.116 with SMTP id b49csp7199291wrg; Thu, 1 Mar 2018 01:18:18 -0800 (PST) X-Google-Smtp-Source: AG47ELullpO6/SCQ7IDOkIqHNOsDDLAmK3aw8nDkyPj2pspKmsD2uGO9xHnCAExtDSAmpG5/Yw0D X-Received: by 2002:a17:902:3183:: with SMTP id x3-v6mr1274103plb.383.1519895897896; Thu, 01 Mar 2018 01:18:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519895897; cv=none; d=google.com; s=arc-20160816; b=S+39nYbsGtF7NQ2u/0zJJzkxMwgcghBytGaJmTY640qO+twZZ9H0D8MVPWNvL9ytX5 BpdFZ/pYYQHl7whE+IjM2rCWK3nsf3sU2rRcBX+SX84drU/4pnd2An5OhvzOytE4I2ae ZTiit7cMG9dTl/lfpPPuubtYF2SW/c7zROCdFc8cB7WBzNIzc+3NHHofe35PEPdzmu26 iKPN4gBodBIrbh6Auq1ZL22j6KiQN5MlWWQ7LyW3ehnv4L6dZ531Ba0j/jnuPApilG7d ttPwLQFtowvazaSgAt1wMdvLDq+qRP9H0qsVXiqt2Z7d3bFImS1MrWKUdcFpn0bIwsT4 OWOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:arc-authentication-results; bh=NAu/VYfcuhb4Avb3n1gwUTO7PIh/UlgteDznT4gNPqI=; b=h64Ev9qxTDO9bpCLUNP4T4JklNK3+HsloPVErI405gW+mCQhXz2mFAjpBfRq+fPCVJ LJ6TxcG04yT/Fx+P+fOrmFhkbWftT2Dxpcz9AQI0s1BZLEaG6VNvnvHXElpiWfEGnoVp +MYeQdn2MJgc7Rx/qcobEzwowHKq6pInMESx/Pg6IPSJdXz7McnbetJwGLOl7khn44q+ g/cxGCUm6xjhFPkyHgfhjizMYrrUk7fdzmYx/Blc744dNHZKotmIQMFoTYJUcBWu6zjc 9npOaM8mpAsg1CKzyuM3TrOg7CxxHpcgLerTrGaeZN2C8MFGYnWQ0uCxHPYJb31mddWT ecOA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 60-v6si1351338plc.66.2018.03.01.01.18.03; Thu, 01 Mar 2018 01:18:17 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966830AbeCAJQt (ORCPT + 99 others); Thu, 1 Mar 2018 04:16:49 -0500 Received: from terminus.zytor.com ([198.137.202.136]:51395 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966724AbeCAJQo (ORCPT ); Thu, 1 Mar 2018 04:16:44 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTP id w219GVcr009267; Thu, 1 Mar 2018 01:16:31 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w219GUC1009264; Thu, 1 Mar 2018 01:16:30 -0800 Date: Thu, 1 Mar 2018 01:16:30 -0800 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Dou Liyang Message-ID: Cc: douly.fnst@cn.fujitsu.com, mingo@kernel.org, andy.shevchenko@gmail.com, tglx@linutronix.de, hpa@zytor.com, linux-kernel@vger.kernel.org Reply-To: linux-kernel@vger.kernel.org, hpa@zytor.com, tglx@linutronix.de, andy.shevchenko@gmail.com, douly.fnst@cn.fujitsu.com, mingo@kernel.org In-Reply-To: <20180301055930.2396-2-douly.fnst@cn.fujitsu.com> References: <20180301055930.2396-2-douly.fnst@cn.fujitsu.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/apic] x86/apic: Move pending interrupt check code into it's own function Git-Commit-ID: 9b217f33017715903d0956dfc58f82d2a2d00e63 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 9b217f33017715903d0956dfc58f82d2a2d00e63 Gitweb: https://git.kernel.org/tip/9b217f33017715903d0956dfc58f82d2a2d00e63 Author: Dou Liyang AuthorDate: Thu, 1 Mar 2018 13:59:28 +0800 Committer: Thomas Gleixner CommitDate: Thu, 1 Mar 2018 10:12:20 +0100 x86/apic: Move pending interrupt check code into it's own function The pending interrupt check code is mixed with the local APIC setup code, that looks messy. Extract the related code, move it into a new function named apic_pending_intr_clear(). Signed-off-by: Dou Liyang Signed-off-by: Thomas Gleixner Reviewed-by: Andy Shevchenko Cc: bhe@redhat.com Cc: ebiederm@xmission.com Link: https://lkml.kernel.org/r/20180301055930.2396-2-douly.fnst@cn.fujitsu.com --- arch/x86/kernel/apic/apic.c | 100 ++++++++++++++++++++++++-------------------- 1 file changed, 55 insertions(+), 45 deletions(-) diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c index 2ceac9f6c5d7..69d2936e3154 100644 --- a/arch/x86/kernel/apic/apic.c +++ b/arch/x86/kernel/apic/apic.c @@ -1408,6 +1408,56 @@ static void lapic_setup_esr(void) oldvalue, value); } +static void apic_pending_intr_clear(void) +{ + long long max_loops = cpu_khz ? cpu_khz : 1000000; + unsigned long long tsc = 0, ntsc; + unsigned int value, queued; + int i, j, acked = 0; + + if (boot_cpu_has(X86_FEATURE_TSC)) + tsc = rdtsc(); + /* + * After a crash, we no longer service the interrupts and a pending + * interrupt from previous kernel might still have ISR bit set. + * + * Most probably by now CPU has serviced that pending interrupt and + * it might not have done the ack_APIC_irq() because it thought, + * interrupt came from i8259 as ExtInt. LAPIC did not get EOI so it + * does not clear the ISR bit and cpu thinks it has already serivced + * the interrupt. Hence a vector might get locked. It was noticed + * for timer irq (vector 0x31). Issue an extra EOI to clear ISR. + */ + do { + queued = 0; + for (i = APIC_ISR_NR - 1; i >= 0; i--) + queued |= apic_read(APIC_IRR + i*0x10); + + for (i = APIC_ISR_NR - 1; i >= 0; i--) { + value = apic_read(APIC_ISR + i*0x10); + for (j = 31; j >= 0; j--) { + if (value & (1< 256) { + printk(KERN_ERR "LAPIC pending interrupts after %d EOI\n", + acked); + break; + } + if (queued) { + if (boot_cpu_has(X86_FEATURE_TSC) && cpu_khz) { + ntsc = rdtsc(); + max_loops = (cpu_khz << 10) - (ntsc - tsc); + } else + max_loops--; + } + } while (queued && max_loops > 0); + WARN_ON(max_loops <= 0); +} + /** * setup_local_APIC - setup the local APIC * @@ -1417,13 +1467,11 @@ static void lapic_setup_esr(void) static void setup_local_APIC(void) { int cpu = smp_processor_id(); - unsigned int value, queued; - int i, j, acked = 0; - unsigned long long tsc = 0, ntsc; - long long max_loops = cpu_khz ? cpu_khz : 1000000; + unsigned int value; +#ifdef CONFIG_X86_32 + int i; +#endif - if (boot_cpu_has(X86_FEATURE_TSC)) - tsc = rdtsc(); if (disable_apic) { disable_ioapic_support(); @@ -1475,45 +1523,7 @@ static void setup_local_APIC(void) value &= ~APIC_TPRI_MASK; apic_write(APIC_TASKPRI, value); - /* - * After a crash, we no longer service the interrupts and a pending - * interrupt from previous kernel might still have ISR bit set. - * - * Most probably by now CPU has serviced that pending interrupt and - * it might not have done the ack_APIC_irq() because it thought, - * interrupt came from i8259 as ExtInt. LAPIC did not get EOI so it - * does not clear the ISR bit and cpu thinks it has already serivced - * the interrupt. Hence a vector might get locked. It was noticed - * for timer irq (vector 0x31). Issue an extra EOI to clear ISR. - */ - do { - queued = 0; - for (i = APIC_ISR_NR - 1; i >= 0; i--) - queued |= apic_read(APIC_IRR + i*0x10); - - for (i = APIC_ISR_NR - 1; i >= 0; i--) { - value = apic_read(APIC_ISR + i*0x10); - for (j = 31; j >= 0; j--) { - if (value & (1< 256) { - printk(KERN_ERR "LAPIC pending interrupts after %d EOI\n", - acked); - break; - } - if (queued) { - if (boot_cpu_has(X86_FEATURE_TSC) && cpu_khz) { - ntsc = rdtsc(); - max_loops = (cpu_khz << 10) - (ntsc - tsc); - } else - max_loops--; - } - } while (queued && max_loops > 0); - WARN_ON(max_loops <= 0); + apic_pending_intr_clear(); /* * Now that we are all set up, enable the APIC