From patchwork Tue Apr 25 14:39:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 9698323 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2702C6020A for ; Tue, 25 Apr 2017 14:38:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0B25728484 for ; Tue, 25 Apr 2017 14:38:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F38DF2857D; Tue, 25 Apr 2017 14:38:02 +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=-6.9 required=2.0 tests=BAYES_00,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 87A132857D for ; Tue, 25 Apr 2017 14:38:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1948243AbdDYOiB (ORCPT ); Tue, 25 Apr 2017 10:38:01 -0400 Received: from foss.arm.com ([217.140.101.70]:42160 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1948187AbdDYOhn (ORCPT ); Tue, 25 Apr 2017 10:37:43 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 199A41A09; Tue, 25 Apr 2017 07:37:43 -0700 (PDT) Received: from e104803-lin.lan (unknown [10.1.207.46]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E854F3F220; Tue, 25 Apr 2017 07:37:41 -0700 (PDT) From: Andre Przywara To: Will Deacon , Marc Zyngier Cc: Jean-Philippe Brucker , kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [kvmtool PATCH v10 12/15] PCI: inject PCI device ID on MSI injection Date: Tue, 25 Apr 2017 15:39:29 +0100 Message-Id: <20170425143932.17235-13-andre.przywara@arm.com> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20170425143932.17235-1-andre.przywara@arm.com> References: <20170425143932.17235-1-andre.przywara@arm.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The ITS emulation requires a unique device ID to be passed along the MSI payload when kvmtool wants to trigger an MSI in the guest. According to the proposed changes to the interface add the PCI bus/device/function triple to the structure passed with the ioctl. Check the respective capability before actually adding the device ID to the kvm_msi struct. Signed-off-by: Andre Przywara --- arm/gic.c | 3 +++ include/kvm/kvm.h | 1 + virtio/pci.c | 8 +++++++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/arm/gic.c b/arm/gic.c index 056fd09..651ede7 100644 --- a/arm/gic.c +++ b/arm/gic.c @@ -245,6 +245,9 @@ static int gic__init_gic(struct kvm *kvm) return ret; } + kvm->msix_needs_devid = kvm__supports_vm_extension(kvm, + KVM_CAP_MSI_DEVID); + return 0; } late_init(gic__init_gic) diff --git a/include/kvm/kvm.h b/include/kvm/kvm.h index a76a25d..90463b8 100644 --- a/include/kvm/kvm.h +++ b/include/kvm/kvm.h @@ -63,6 +63,7 @@ struct kvm { struct list_head mem_banks; bool nmi_disabled; + bool msix_needs_devid; const char *vmlinux; struct disk_image **disks; diff --git a/virtio/pci.c b/virtio/pci.c index 04176c1..f0e884c 100644 --- a/virtio/pci.c +++ b/virtio/pci.c @@ -334,7 +334,8 @@ static void virtio_pci__msix_mmio_callback(struct kvm_cpu *vcpu, update_msix_map(vpci, table, vecnum); } -static void virtio_pci__signal_msi(struct kvm *kvm, struct virtio_pci *vpci, int vec) +static void virtio_pci__signal_msi(struct kvm *kvm, struct virtio_pci *vpci, + int vec) { struct kvm_msi msi = { .address_lo = vpci->msix_table[vec].msg.address_lo, @@ -342,6 +343,11 @@ static void virtio_pci__signal_msi(struct kvm *kvm, struct virtio_pci *vpci, int .data = vpci->msix_table[vec].msg.data, }; + if (kvm->msix_needs_devid) { + msi.flags = KVM_MSI_VALID_DEVID; + msi.devid = vpci->dev_hdr.dev_num << 3; + } + ioctl(kvm->vm_fd, KVM_SIGNAL_MSI, &msi); }