Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp7150668ybi; Mon, 8 Jul 2019 15:39:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqzQY+uIMpj1YTBT6Jx8Ih3W07/fUxmFk5XFQVr6T9XRkRpyqkjWaAvECtRaJyKXnw6yqqYZ X-Received: by 2002:a65:5a44:: with SMTP id z4mr26729889pgs.41.1562625596980; Mon, 08 Jul 2019 15:39:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562625596; cv=none; d=google.com; s=arc-20160816; b=VsfproZMznWYjf+EnH3jgxRaIPWurRQbodXHNroSkzjA5T1mKjAsUFPFYiV/D0+5Wy hmoyvfmmf3ixigjZ64sFJau9aT4/hiNNdCecyoZJhBx3zMbDi9xDY7aRGD8cEpoXRgbH scY2cbzzm9Nq2gWzYCAW9bheGdpMr6urhXSNswgU7ls9pvcUPON2f+ZEZKlNo1fP9ygY b2ex2+dHJhwvrFqwoZvy+F1nTn4rKVkckqvCri7/n+imu6BOmoKQM2Wx3itXt26JAySC lzoBtB8X9JC2vYfIHUbp3t81tsax2sC/KXa8vuBlB1Njm5bI8ASfPsxysx/aMMuBrdLd 74eA== 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=eFmH3EOpddKyd1ROlufmgBHPmor/P9WAbCAmUNwd/IM=; b=ag3rwctSDwfXcebVfGRsQHaozDxTCcq7Aq5ufiz95a6Pthia3yWGBHsJcNWYN+opfU uvFzXxXk07EkrFidZ9FaSMxleeiflVxvc2f1HYWn+7S7tVV9niZHh+z4Xqd6MxHM+7lo PKqpM0S6deZN1zTmFfrxckX7nQgiB8C2EK6VJ8L1NRC941dvAA7wpI3tP7c/m/MNN7B+ pFz1ynzYdlF90AW7LMsk5HZ9XQOEyLPcjyebVzZX3DVzT80EfSy3F8rNAPuDdjQG1HBT PsX0nC8uMgLWRL8P5doPcDbqwyHE64w/xWn/sCzmkMdDmYCOVOjNGZxCpaDjMd/wjkh5 hIkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="sAFhJQ/+"; 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 b9si91752pls.201.2019.07.08.15.39.42; Mon, 08 Jul 2019 15:39:56 -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="sAFhJQ/+"; 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 S2390596AbfGHPem (ORCPT + 99 others); Mon, 8 Jul 2019 11:34:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:37014 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390575AbfGHPei (ORCPT ); Mon, 8 Jul 2019 11:34:38 -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 A696221537; Mon, 8 Jul 2019 15:34:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562600078; bh=LM5F0Foz7CGLRgH2lWz/bad1ZpG8VxUk5A261MLxHCk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sAFhJQ/+J/jh+eCs73yxhRAUaOeSSZ4e2Lm/TdGr93GLKkYS9jr86myuohuEI6t/W XIvVMCYmG1JWzO9B1TTHALecas07e/8k6uRja76SxHbIiXK5l/KII9+l03ZS01SdOa pa435e6xhFf/Dn8yYcIrY3ya/zo0e9wHkut6oAuc= 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 5.1 86/96] KVM: LAPIC: Fix pending interrupt in IRR blocked by software disable LAPIC Date: Mon, 8 Jul 2019 17:13:58 +0200 Message-Id: <20190708150531.088265193@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190708150526.234572443@linuxfoundation.org> References: <20190708150526.234572443@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 @@ -2331,7 +2331,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);