Received: by 10.223.185.116 with SMTP id b49csp6235185wrg; Wed, 28 Feb 2018 06:13:56 -0800 (PST) X-Google-Smtp-Source: AH8x227Q5ZpeVMDLoOirl2fy1pY9Y2cLLD3G8M8FC3/bfzTGoU4aIbpUB6ySB+I2WA4tRo9nFyXl X-Received: by 10.99.94.197 with SMTP id s188mr14089159pgb.363.1519827236028; Wed, 28 Feb 2018 06:13:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519827235; cv=none; d=google.com; s=arc-20160816; b=Ng39mshlhO/DKkmZ+R+08/xgMDIBGe3ppRQfpduMEwEOCPcddWi/yvwlNljM3UahAu wFtAzUG9uxJw5j4Rc2PITvlsH76TWeU4eDxFzLne+4mJkVnyIUh1AJ0U/q4nqYyLeAv/ /mOytouz4MHvUPpssZJYfMZ8BdCo3cw4mmg5ElNvSvH6yvB5NK6V7WRUJIdWYe63q6lO W6IaBKS22DVCvyrEKpnJD/wrEP+XNzk6LvLnvF2/iLOcksTguIK2ze6Fux+WNTJ+jyfV hDdkY/ht5m93fDlZEPnws/Je2MnaVX6z0M/44UvjAfFkzrtjLUAMJuPoeXHSu3uoICFe kWHw== 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=vpqkpaJldRadJEWjO+tkerns7RkMWVI3hmtAKl1yYvI=; b=cZqFQgGdZ2CkHFnOl7uHNdXMhg3gASFwJGot3820trgMBtsQdvf1RoA5oHEbAaU/8a ILuZUooQJu2ZOvE4wMWf6FlznOsiKPdkbQf0bE1D9//PgpbDLBsTd2YLJYNdLJLfeGHy GEWgFAnFynim4h5RBY4PCkXE8c2Dvs74Da8lOHX8g+3sbwynHlWRcYMFGcaLvRpvqof8 x2wVGgqUXuXjs5VkWBKOn3soCxTIMq95WEJ/a5/S2WbsgMF9F71DqsOZFGxYosRlzqtN pxZua91WH5YyQLqC2m4RWTQWdEetFxv/iScHddeKT8tc9cXXGGmezI9Fjk6HCSMMUVHW 7zOw== 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 z7si1272028pfg.278.2018.02.28.06.13.39; Wed, 28 Feb 2018 06:13:55 -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 S1752591AbeB1OMz (ORCPT + 99 others); Wed, 28 Feb 2018 09:12:55 -0500 Received: from terminus.zytor.com ([198.137.202.136]:49307 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752417AbeB1OMy (ORCPT ); Wed, 28 Feb 2018 09:12:54 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTP id w1SECkad022223; Wed, 28 Feb 2018 06:12:46 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w1SECje0022220; Wed, 28 Feb 2018 06:12:45 -0800 Date: Wed, 28 Feb 2018 06:12:45 -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: andy.shevchenko@gmail.com, tglx@linutronix.de, hpa@zytor.com, linux-kernel@vger.kernel.org, douly.fnst@cn.fujitsu.com, mingo@kernel.org Reply-To: linux-kernel@vger.kernel.org, douly.fnst@cn.fujitsu.com, mingo@kernel.org, andy.shevchenko@gmail.com, hpa@zytor.com, tglx@linutronix.de In-Reply-To: <20180226023957.22861-1-douly.fnst@cn.fujitsu.com> References: <20180226023957.22861-1-douly.fnst@cn.fujitsu.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/apic] x86/apic: Move pending intr check code into it's own function Git-Commit-ID: 2066f4d67e7d9cbe44e451d782cdcc0a0d12e5d3 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: 2066f4d67e7d9cbe44e451d782cdcc0a0d12e5d3 Gitweb: https://git.kernel.org/tip/2066f4d67e7d9cbe44e451d782cdcc0a0d12e5d3 Author: Dou Liyang AuthorDate: Mon, 26 Feb 2018 10:39:56 +0800 Committer: Thomas Gleixner CommitDate: Wed, 28 Feb 2018 15:09:11 +0100 x86/apic: Move pending intr 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/20180226023957.22861-1-douly.fnst@cn.fujitsu.com --- arch/x86/kernel/apic/apic.c | 98 ++++++++++++++++++++++++--------------------- 1 file changed, 52 insertions(+), 46 deletions(-) diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c index 2ceac9f6c5d7..3fda9734db25 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,7 @@ 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; - - if (boot_cpu_has(X86_FEATURE_TSC)) - tsc = rdtsc(); + unsigned int value; if (disable_apic) { disable_ioapic_support(); @@ -1475,45 +1519,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