Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp7148204ybi; Mon, 8 Jul 2019 15:36:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqx6oyCiy/vMyAY9ZyvWp6zSqUuyhQFumVh+M89Fljn/mOji8I0mzI01JjRc2p5lic78BwNS X-Received: by 2002:a17:902:b206:: with SMTP id t6mr28231179plr.195.1562625399844; Mon, 08 Jul 2019 15:36:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562625399; cv=none; d=google.com; s=arc-20160816; b=zQnavmaHc1rYAdmWjk1EWSkoLfMbEWzpn2heRCyJN1X1Xz2ddsO8uFawFe7DbOnCoi dTc68VVNlfnKVA7QWY6UFO2uLK8hm7IJrdVHCStCIUg2vYCKNNerQ1LZqqQK9wU2sYWt vb/v+CJn3TLAmWR6fEkh4KVKAvCLQtYorjweV6hrvJfK4ri6X6/vrVWw7geQn943dtwc MGmX1L9YQZ+8jhyR+wuyLvTUzaOdFVddy1Z10VsgzB2JmGnz2zBg3+AQwFt4fNQpXu+V +16FEd9C+NXvEMQdbcDbhz0kUIkV1V6dC0g9B8v09X0pbPuXfxA7HTNIMy/Z5B3HJrWI RhAQ== 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=04U4VaZPEQ5MesqRjZOWPFxwxgFggA9uOVgu+9cbbsQ=; b=UxzH0Hd21vBxZ54b4jCYE4xzD5daXuE+0nQYxqQfYB4X2pwHUmOk7tqQeog9bz2ABC Q/qOFiRnYRSnwXukjGIlffkuy770lARzGp2zmBe0FWrbiyYe0tlw1njyvkFzaaEjVSah phn8Aj9JJ0+mNqRLuqaRClR+BFJGS52fE+JrsAgNxH4ubYTo17Ecm5uK+cbGfwyTcEAU jG13IE1WJUZA1T6VZOv7RVZrFUVtRvZOw1r9tAH0XcB0jCXeU2znRrSwl+bWBQ+gw0DU gThid9FUaagnxA5YxFoi+lH5YO1Wf1xrUt3Soe8cKJMLdV/O3hOg4LmbN7I3XZTq3p+b oHJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xrQ4omM7; 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 q85si20885724pfc.85.2019.07.08.15.36.25; Mon, 08 Jul 2019 15:36:39 -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=xrQ4omM7; 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 S2388097AbfGHPW7 (ORCPT + 99 others); Mon, 8 Jul 2019 11:22:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:49682 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729493AbfGHPW5 (ORCPT ); Mon, 8 Jul 2019 11:22:57 -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 85F8E214C6; Mon, 8 Jul 2019 15:22:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562599376; bh=frJ4X5lZTs/c6mGsUYgae9BT+bXQw78oMXGMLEz7q6s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xrQ4omM7sAktLwsrmno8A2pUtZpcv5ULmrJv3F+qeajaf09hu0aCxeY/xRIMVDkPa 269FE0pKb1HZ2TXvlaj8KqKoaZZRvuOa2XjOATNCmFMXWpd+7Q8ZpNO3oE3IiT1n4S wWHPCoJwsggDbQPljvumRmizCcMDwHIX0mCCIDR0= 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.9 098/102] KVM: LAPIC: Fix pending interrupt in IRR blocked by software disable LAPIC Date: Mon, 8 Jul 2019 17:13:31 +0200 Message-Id: <20190708150531.552030006@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190708150525.973820964@linuxfoundation.org> References: <20190708150525.973820964@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 @@ -1992,7 +1992,7 @@ int kvm_apic_has_interrupt(struct kvm_vc struct kvm_lapic *apic = vcpu->arch.apic; int highest_irr; - if (!apic_enabled(apic)) + if (!kvm_apic_hw_enabled(apic)) return -1; apic_update_ppr(apic);