Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp7151718ybi; Mon, 8 Jul 2019 15:41:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqxJkWgNq0jt9X0V44YNQSPE6q2GCsjVhqHf4KQmxCMdYm0rS65HKL2fMGJ/6tDFfOG+lTeC X-Received: by 2002:a63:5247:: with SMTP id s7mr25513860pgl.29.1562625683769; Mon, 08 Jul 2019 15:41:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562625683; cv=none; d=google.com; s=arc-20160816; b=DHP0LpPE9aEHuwni9xahAoJOqS+Sdz9uZcBfm/5T6IQ99LIqIGf0pwzUftMb/ivSGB TWvb4b/QMcd1qOWhWS6ir+ykur4lVhMGkoeTZpZWG/64i4ECgh0q/DivsBoxa0rLoELG p/Vw65FSvG4vK1qoO0ROrmooknR+fIWnVU4oGWcvVnk4y3W/WQbIe+vdtZP/cZAq6YjX V5qffoTxUGirzHlDFkNnpA60PD4buNe7BpcSbEtvQvSboXwmh9WEvcyU/wu661MWaIYS 4JLkNFSQvSeFcBRer5SiIPwZ8THgdCN2JrakyejiQQNdfSLgvZnx+CLwLTfOxybbcmci fC1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=alqD+aKht+PjKGjLaj2dNFyR299cYcTnVzJXT1oOsm8=; b=XqLJs6ylbPvsrPdrBhNeXW5+edIC2G8Rj7uKHvZe0l8YMKx/OD976342CYum09tSpl F9BYMhBFbC+BTOOt592wbRVsXWTuJyyoYPRR1geqTzLR51EVk7nqP7RKTNc/OL3h7ct0 r3WOyj5qt9HV6LdW4uWE6bB3YsofNLU1np3GfhsZ3Iup1+RrI/FjppbopnNQ5Thszmnn lNenl19PpRycCxF0wjcCmPG8/P00BZ/Zj/K346tvZCfD/6LkIut/SrzVIg4VKJv/hFGz bszS4bsIrGNiLvW94vlM20eic4coTou+bBc1uftP5lmb+OaUcSEhe1d7jcrUo7DMYv/T qhjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="CI/m3+aA"; 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 a11si19764697pgj.537.2019.07.08.15.41.08; Mon, 08 Jul 2019 15:41:23 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=default header.b="CI/m3+aA"; 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 S2390640AbfGHPir (ORCPT + 99 others); Mon, 8 Jul 2019 11:38:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:59034 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389809AbfGHPaH (ORCPT ); Mon, 8 Jul 2019 11:30:07 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C66DA21707; Mon, 8 Jul 2019 15:30:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562599805; bh=xvRlkvuBW/KaYctAaFfIuOV5/n9KBu7XEiPQHP4ruYA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CI/m3+aA8GFkxwook6assp3wiHeeZt02jBW6aDQEDHW6ZGkyNVE1YVZUNvg3ucRUm pHtmyMepvCcH+JMX5hvMLd5c3gQVMbUE/e7Y3s/VnKPE0b70r9XfbEIn44Zqc1GV31 ny+V+MDyGnlALjVavsSv+/lqHuR1ZBS/6VNY4t5U= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Rong Chen , Feng Tang , Thomas Gleixner , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Wanpeng Li Subject: [PATCH 4.19 83/90] KVM: LAPIC: Fix pending interrupt in IRR blocked by software disable LAPIC Date: Mon, 8 Jul 2019 17:13:50 +0200 Message-Id: <20190708150526.617437959@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190708150521.829733162@linuxfoundation.org> References: <20190708150521.829733162@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Wanpeng Li commit bb34e690e9340bc155ebed5a3d75fc63ff69e082 upstream. Thomas reported that: | Background: | | In preparation of supporting IPI shorthands I changed the CPU offline | code to software disable the local APIC instead of just masking it. | That's done by clearing the APIC_SPIV_APIC_ENABLED bit in the APIC_SPIV | register. | | Failure: | | When the CPU comes back online the startup code triggers occasionally | the warning in apic_pending_intr_clear(). That complains that the IRRs | are not empty. | | The offending vector is the local APIC timer vector who's IRR bit is set | and stays set. | | It took me quite some time to reproduce the issue locally, but now I can | see what happens. | | It requires apicv_enabled=0, i.e. full apic emulation. With apicv_enabled=1 | (and hardware support) it behaves correctly. | | Here is the series of events: | | Guest CPU | | goes down | | native_cpu_disable() | | apic_soft_disable(); | | play_dead() | | .... | | startup() | | if (apic_enabled()) | apic_pending_intr_clear() <- Not taken | | enable APIC | | apic_pending_intr_clear() <- Triggers warning because IRR is stale | | When this happens then the deadline timer or the regular APIC timer - | happens with both, has fired shortly before the APIC is disabled, but the | interrupt was not serviced because the guest CPU was in an interrupt | disabled region at that point. | | The state of the timer vector ISR/IRR bits: | | ISR IRR | before apic_soft_disable() 0 1 | after apic_soft_disable() 0 1 | | On startup 0 1 | | Now one would assume that the IRR is cleared after the INIT reset, but this | happens only on CPU0. | | Why? | | Because our CPU0 hotplug is just for testing to make sure nothing breaks | and goes through an NMI wakeup vehicle because INIT would send it through | the boots-trap code which is not really working if that CPU was not | physically unplugged. | | Now looking at a real world APIC the situation in that case is: | | ISR IRR | before apic_soft_disable() 0 1 | after apic_soft_disable() 0 1 | | On startup 0 0 | | Why? | | Once the dying CPU reenables interrupts the pending interrupt gets | delivered as a spurious interupt and then the state is clear. | | While that CPU0 hotplug test case is surely an esoteric issue, the APIC | emulation is still wrong, Even if the play_dead() code would not enable | interrupts then the pending IRR bit would turn into an ISR .. interrupt | when the APIC is reenabled on startup. >From SDM 10.4.7.2 Local APIC State After It Has Been Software Disabled * Pending interrupts in the IRR and ISR registers are held and require masking or handling by the CPU. In Thomas's testing, hardware cpu will not respect soft disable LAPIC when IRR has already been set or APICv posted-interrupt is in flight, so we can skip soft disable APIC checking when clearing IRR and set ISR, continue to respect soft disable APIC when attempting to set IRR. Reported-by: Rong Chen Reported-by: Feng Tang Reported-by: Thomas Gleixner Tested-by: Thomas Gleixner Cc: Paolo Bonzini Cc: Radim Krčmář Cc: Thomas Gleixner Cc: Rong Chen Cc: Feng Tang Cc: stable@vger.kernel.org Signed-off-by: Wanpeng Li Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/lapic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -2275,7 +2275,7 @@ int kvm_apic_has_interrupt(struct kvm_vc struct kvm_lapic *apic = vcpu->arch.apic; u32 ppr; - if (!apic_enabled(apic)) + if (!kvm_apic_hw_enabled(apic)) return -1; __apic_update_ppr(apic, &ppr);