Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp6796684ybi; Mon, 8 Jul 2019 08:50:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqxA32xYsx9vkU6LuCBKpvstUkXUeV1ycgvq69OGbpkXcZ3VL2pZ3UUzZeGm7nc5gDYbtvRu X-Received: by 2002:a17:90a:374a:: with SMTP id u68mr18608860pjb.4.1562601032554; Mon, 08 Jul 2019 08:50:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562601032; cv=none; d=google.com; s=arc-20160816; b=rpkD8Mdr35M/eY4VC6jP/zEokn1EzZn2OBZlzD8GzsCZ8j47T4OexdfEq75mQB+ahy BKMtPwFpGklPJrJhSW3FC46S6ZZCjHT66cXph3k7M+ZJV+hGDrzrMHuHZu4CrYyezwR0 YEfLsuPfHmw+wUm2MtjYXqT1fvQRlh6FQnKsPeTQixZ2pQk8RQDVkc+YetVc2eBdkW6r kri4Kss9KirhvtY5nIdvLmA0JqTBd9Quv+gbEeTWu6O2WG4u9XUPj/y+7NBuNPbMD05f iD9j8Tt7v+APJD5wa9fVHBd5e9U1CFFVBDskrhS8Xf15ifGwDrWtKfjrbpTO/CdA74S/ 7brg== 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=ShbkJnrWY+DtcCSghLymXLnPq6phZiIQ0oSC8bK1uMY=; b=f5rWRvCKg2kn8MSGj1Ap+cXJP1BqOvSppL84J11uICIbDmdwcpCiFlpn38SIF8lJZJ AFuLD/QhEtmjZMexiaSY36k+4x9OVc+xOadNJ/y3OJkOdvHKxtkWqF+XWWMFnTbRVDjj CodwhW5Cxp9Ppyd4SHkKFT+BfPynu/DNXGhMwZJ8xghiET+31DI+3ETz4lSAzOmiavOi kC7d1feFOawx3Cw9v6hzvsSiG7EmrHxGaLfwb5MbMLLQebSLpOuA/2b0k6yK1fdKXRSH pPN8FuxHPL6O5n+cvISNot2Mxnv8w+R26u2VbsINiIHfWkjsOLVLR3WW5r0O5jmoZ5Ys 9c0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=FpByg06P; 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 o13si18019392pjr.101.2019.07.08.08.50.16; Mon, 08 Jul 2019 08:50:32 -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=FpByg06P; 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 S1731329AbfGHPZ4 (ORCPT + 99 others); Mon, 8 Jul 2019 11:25:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:53396 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388681AbfGHPZu (ORCPT ); Mon, 8 Jul 2019 11:25:50 -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 9284A204EC; Mon, 8 Jul 2019 15:25:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562599549; bh=H4G29Oxk1339cRsoFCBpWjqf39RTO8vLCCaVvbRG9Bo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FpByg06Px//mGGoKBiauz3UeI/Ej/R1JqRlWGiRgaDTB4jqc0LHCK+AwG2s2Xa3vV HP5I53UP1QXXvT7WrTdinV9awAblWChqZqj4FO6uk2/3A3FO9uKm86nPsK6FrbTKEc oWG3vP1rR4DOtPG+Pir67QsmuJzMYHZoOkKoClK0= 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.14 51/56] KVM: LAPIC: Fix pending interrupt in IRR blocked by software disable LAPIC Date: Mon, 8 Jul 2019 17:13:43 +0200 Message-Id: <20190708150524.090194311@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190708150514.376317156@linuxfoundation.org> References: <20190708150514.376317156@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 @@ -2161,7 +2161,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);