From patchwork Mon Feb 4 14:43:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 10795809 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9D015922 for ; Mon, 4 Feb 2019 14:43:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 865EB2B51A for ; Mon, 4 Feb 2019 14:43:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8468B2B757; Mon, 4 Feb 2019 14:43:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 140042B74E for ; Mon, 4 Feb 2019 14:43:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728344AbfBDOnt (ORCPT ); Mon, 4 Feb 2019 09:43:49 -0500 Received: from mail-qt1-f171.google.com ([209.85.160.171]:37029 "EHLO mail-qt1-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727347AbfBDOnt (ORCPT ); Mon, 4 Feb 2019 09:43:49 -0500 Received: by mail-qt1-f171.google.com with SMTP id t33so104608qtt.4 for ; Mon, 04 Feb 2019 06:43:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=Kfo2iiafTatreoHj6AFYyQl1fbXlUNmv7c+buwJXZf4=; b=tqA1RP6TjLPiUi3lEFOwNneUadt6i15R0a7MH08st7lC1NFhIazrM2CbgRP7t8ZVnL q/LBX5Mt4KasOy2pUoKbwrkQKEssX7QNLlubBb+AqD/P38cVbutkH7q8BXnTLwgni/s1 9I8KetmNTmfv15bZRq7OwE0bbyswuU37u4+FoGIw1BViEIieBwZXNLqbrtfFqnnrB5EI f+/3MZ/c3qF/lsy9qh9di36hzJxn1voagOKrHKD2VCCf8/A4WnYvXZ/qoDrFJmdRpNMq fMwbloh3lna8Rn4/bD0eXvjRqKIKNpK9nSly5J/aLytfY7Zil6JRXjGNXWxA/DaxcwDt tlnQ== X-Gm-Message-State: AJcUuke6kJyc4pwd2W59AKSyhaJKFc9q2pmy1fEahdG0S8dECce1SB6X Nnd+4J61rPad/TBdur0/Xqkl3A== X-Google-Smtp-Source: ALg8bN64E+UYqDnB7n8Gdu2HSC/f7c9gxu3VTkOi8uI8VySUTF2K+482es1CdH9pkhvjuSSifZlDLA== X-Received: by 2002:aed:2cc4:: with SMTP id g62mr49328353qtd.192.1549291428260; Mon, 04 Feb 2019 06:43:48 -0800 (PST) Received: from redhat.com (pool-173-76-246-42.bstnma.fios.verizon.net. [173.76.246.42]) by smtp.gmail.com with ESMTPSA id e26sm12416869qtg.69.2019.02.04.06.43.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 04 Feb 2019 06:43:47 -0800 (PST) Date: Mon, 4 Feb 2019 09:43:46 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Peter Xu , Paolo Bonzini , Marcelo Tosatti , Richard Henderson , Eduardo Habkost , kvm@vger.kernel.org Subject: [PULL 14/25] i386/kvm: ignore masked irqs when update msi routes Message-ID: <20190204142638.27021-15-mst@redhat.com> References: <20190204142638.27021-1-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20190204142638.27021-1-mst@redhat.com> X-Mailer: git-send-email 2.17.1.1206.gb667731e2e.dirty X-Mutt-Fcc: =sent Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Peter Xu When we are with intel-iommu device and with IR on, KVM will register an IEC notifier to detect interrupt updates from the guest and we'll kick off kvm_update_msi_routes_all() when it happens to make sure kernel IRQ cache is matching the latest. Though, kvm_update_msi_routes_all() is buggy in that it ignored the mask bit of either MSI/MSIX messages and it tries to translate the message even if the corresponding message was already masked by the guest driver (hence the MSI/MSIX message will be invalid). Without this patch, we can receive an error message when we reboot a guest with both an assigned vfio-pci device and intel-iommu enabled: qemu-system-x86_64: vtd_interrupt_remap_msi: MSI address low 32 bit invalid: 0x0 The error does not affect functionality of the guest since when we failed to translate we'll just silently continue (which makes sense since crashing the VM for this seems even worse), but still it's better to fix it up. Signed-off-by: Peter Xu Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- target/i386/kvm.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 9af4542fb8..beae1b99da 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -3894,7 +3894,7 @@ static QLIST_HEAD(, MSIRouteEntry) msi_route_list = \ static void kvm_update_msi_routes_all(void *private, bool global, uint32_t index, uint32_t mask) { - int cnt = 0; + int cnt = 0, vector; MSIRouteEntry *entry; MSIMessage msg; PCIDevice *dev; @@ -3902,11 +3902,19 @@ static void kvm_update_msi_routes_all(void *private, bool global, /* TODO: explicit route update */ QLIST_FOREACH(entry, &msi_route_list, list) { cnt++; + vector = entry->vector; dev = entry->dev; - if (!msix_enabled(dev) && !msi_enabled(dev)) { + if (msix_enabled(dev) && !msix_is_masked(dev, vector)) { + msg = msix_get_message(dev, vector); + } else if (msi_enabled(dev) && !msi_is_masked(dev, vector)) { + msg = msi_get_message(dev, vector); + } else { + /* + * Either MSI/MSIX is disabled for the device, or the + * specific message was masked out. Skip this one. + */ continue; } - msg = pci_get_msi_message(dev, entry->vector); kvm_irqchip_update_msi_route(kvm_state, entry->virq, msg, dev); } kvm_irqchip_commit_routes(kvm_state);