Received: by 10.223.185.116 with SMTP id b49csp6228331wrg; Wed, 28 Feb 2018 06:08:12 -0800 (PST) X-Google-Smtp-Source: AG47ELuOZUsbMczWMzYC+V2P4/PGH5Mu2V/IsBYPU+LvuJwCBGD8JHU0pb8HIvLz6kZ9JfP3/h8a X-Received: by 2002:a17:902:b683:: with SMTP id c3-v6mr14114522pls.154.1519826892678; Wed, 28 Feb 2018 06:08:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519826892; cv=none; d=google.com; s=arc-20160816; b=wg6H5KLv1AHwlfoJYhlwc6Idrec/rbM8K7CMBO4/6QHWL63LrEIVzjwG6oKm8TgweH JZ5ztBiAAk3sZkyQwEZVdX52/9v0rAT7EZViFSW04TO0PvksGbvJtUtF4KLQPS+525a3 vpeC7R+5sKYq0UbY/VRzfU5vWnv3PHM3Ua+1yU7nBF32VTMZMH0S0JhsPJCTgeLXaiqw J7JGaCV9DKRF5XS4cdAU1EJzK+TV59GvRIsZY/mlVYaJTSXpLeIdwjL0H2vm9iC/95VX KiRFguncF4qQ/D+xgsL4tEryhSWA7BoqqWDlZyccWIlG7faysDloM+hbKxWpXYQhZvp9 QWaw== 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=IvHaAEGoHNi0Cwh6WTOB2oSDwhvqCqjVqgQpb1f4Nnk=; b=wX2Tkd4Jrzde/aGYD6adUD/MMAIkV4FHBEAbV6V5+fimoQVRpupiK12Cr2AswWF3Bu phVTxKmrGXOzHG/qGdUfvoAFWMRgmvaGJWrvkuFH3wxvd3fiD3Ld4razxSbcAYRAEIqK uUlLC2QYfsscjF06Id8ffDpS/9eFiYo4XyRuZ1Xaf+W+XkrUjD6nJ1tIfP3C6WIHUYXW KZrBL8TGgHF2/Sw2Ufix4FWPKMwWrF1YXjpFoCQKe9bGQD26IKwAzccpDECpybc+DClI PY4Tojo/gCLGjEAhbsu7vZupnJgWAGkYrZMCE0xtd2F1CgmZA3rHVgXGSrS675ia8ras Zvuw== 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 q4si1071362pgc.269.2018.02.28.06.07.49; Wed, 28 Feb 2018 06:08:12 -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 S932105AbeB1OHD (ORCPT + 99 others); Wed, 28 Feb 2018 09:07:03 -0500 Received: from terminus.zytor.com ([198.137.202.136]:42923 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752157AbeB1OHC (ORCPT ); Wed, 28 Feb 2018 09:07:02 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTP id w1SE6ob2020960; Wed, 28 Feb 2018 06:06:50 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w1SE6n10020957; Wed, 28 Feb 2018 06:06:49 -0800 Date: Wed, 28 Feb 2018 06:06:49 -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: mingo@kernel.org, douly.fnst@cn.fujitsu.com, tglx@linutronix.de, hpa@zytor.com, linux-kernel@vger.kernel.org, andy.shevchenko@gmail.com Reply-To: andy.shevchenko@gmail.com, hpa@zytor.com, linux-kernel@vger.kernel.org, mingo@kernel.org, douly.fnst@cn.fujitsu.com, tglx@linutronix.de In-Reply-To: <20180226232554.14108.16881.stgit@tlendack-t1.amdoffice.net> References: <20180226232554.14108.16881.stgit@tlendack-t1.amdoffice.net> 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: 0da89dfa7a6a85e2bab44462fe960ce41eecc4c9 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=-0.8 required=5.0 tests=ALL_TRUSTED,BAYES_00, FREEMAIL_FORGED_REPLYTO autolearn=no 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: 0da89dfa7a6a85e2bab44462fe960ce41eecc4c9 Gitweb: https://git.kernel.org/tip/0da89dfa7a6a85e2bab44462fe960ce41eecc4c9 Author: Dou Liyang AuthorDate: Mon, 26 Feb 2018 10:39:56 +0800 Committer: Thomas Gleixner CommitDate: Wed, 28 Feb 2018 15:02:58 +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/20180226232554.14108.16881.stgit@tlendack-t1.amdoffice.net --- 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