From patchwork Fri May 6 20:53:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFkaW0gS3LEjW3DocWZ?= X-Patchwork-Id: 9036201 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id B69259F372 for ; Fri, 6 May 2016 20:56:36 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DBA1620219 for ; Fri, 6 May 2016 20:56:35 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 36874202FE for ; Fri, 6 May 2016 20:56:35 +0000 (UTC) Received: from localhost ([::1]:60216 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aymnX-0002aT-F0 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 06 May 2016 16:56:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44518) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aymls-0007tX-5n for qemu-devel@nongnu.org; Fri, 06 May 2016 16:54:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aymlg-00078f-Ds for qemu-devel@nongnu.org; Fri, 06 May 2016 16:54:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49042) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aymlg-000754-6G for qemu-devel@nongnu.org; Fri, 06 May 2016 16:54:36 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 02BF97F6CF; Fri, 6 May 2016 20:54:25 +0000 (UTC) Received: from potion (dhcp-1-215.brq.redhat.com [10.34.1.215]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with SMTP id u46KsLQG011201; Fri, 6 May 2016 16:54:22 -0400 Received: by potion (sSMTP sendmail emulation); Fri, 06 May 2016 22:54:21 +0200 From: =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= To: qemu-devel@nongnu.org Date: Fri, 6 May 2016 22:53:48 +0200 Message-Id: <1462568028-31037-5-git-send-email-rkrcmar@redhat.com> In-Reply-To: <1462568028-31037-1-git-send-email-rkrcmar@redhat.com> References: <1462568028-31037-1-git-send-email-rkrcmar@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 4/4] kvm: support MSI_X2APIC capability X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Lan, Tianyu" , Eduardo Habkost , Peter Xu , Jan Kiszka , Igor Mammedov , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The capability alows us to express x2APIC destinations. Signed-off-by: Radim Kr?má? --- include/sysemu/kvm.h | 1 + kvm-all.c | 14 +++++++++++++- target-i386/kvm.c | 4 ++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h index b7a20eb6ae69..e356438fdf5f 100644 --- a/include/sysemu/kvm.h +++ b/include/sysemu/kvm.h @@ -213,6 +213,7 @@ int kvm_has_pit_state2(void); int kvm_has_many_ioeventfds(void); int kvm_has_gsi_routing(void); int kvm_has_intx_set_mask(void); +bool kvm_has_msi_x2apic(void); int kvm_init_vcpu(CPUState *cpu); int kvm_cpu_exec(CPUState *cpu); diff --git a/kvm-all.c b/kvm-all.c index 8106efb19519..270152615fc2 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -81,6 +81,7 @@ struct KVMState #endif int many_ioeventfds; int intx_set_mask; + bool msi_x2apic; /* The man page (and posix) say ioctl numbers are signed int, but * they're not. Linux, glibc and *BSD all treat ioctl numbers as * unsigned, and treating them as signed here can break things */ @@ -1143,6 +1144,9 @@ int kvm_irqchip_send_msi(KVMState *s, MSIMessage msg) msi.address_hi = msg.address >> 32; msi.data = le32_to_cpu(msg.data); msi.flags = 0; + if (kvm_has_msi_x2apic()) { + msi.flags |= KVM_SIGNAL_MSI_X2APIC; + } memset(msi.pad, 0, sizeof(msi.pad)); return kvm_vm_ioctl(s, KVM_SIGNAL_MSI, &msi); @@ -1159,7 +1163,8 @@ int kvm_irqchip_send_msi(KVMState *s, MSIMessage msg) route = g_malloc0(sizeof(KVMMSIRoute)); route->kroute.gsi = virq; - route->kroute.type = KVM_IRQ_ROUTING_MSI; + route->kroute.type = kvm_has_msi_x2apic() ? KVM_IRQ_ROUTING_MSI_X2APIC + : KVM_IRQ_ROUTING_MSI; route->kroute.flags = 0; route->kroute.u.msi.address_lo = (uint32_t)msg.address; route->kroute.u.msi.address_hi = msg.address >> 32; @@ -1623,6 +1628,8 @@ static int kvm_init(MachineState *ms) s->intx_set_mask = kvm_check_extension(s, KVM_CAP_PCI_2_3); + s->msi_x2apic = kvm_check_extension(s, KVM_CAP_MSI_X2APIC); + s->irq_set_ioctl = KVM_IRQ_LINE; if (kvm_check_extension(s, KVM_CAP_IRQ_INJECT_STATUS)) { s->irq_set_ioctl = KVM_IRQ_LINE_STATUS; @@ -2104,6 +2111,11 @@ int kvm_has_intx_set_mask(void) return kvm_state->intx_set_mask; } +bool kvm_has_msi_x2apic(void) +{ + return kvm_state->msi_x2apic; +} + void kvm_setup_guest_memory(void *start, size_t size) { if (!kvm_has_sync_mmu()) { diff --git a/target-i386/kvm.c b/target-i386/kvm.c index 80b325146a5e..4c9c53ad3e76 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -3351,6 +3351,10 @@ int kvm_arch_fixup_msi_route(struct kvm_irq_routing_entry *route, route->u.msi.address_hi = dst.address >> VTD_MSI_ADDR_HI_SHIFT; route->u.msi.address_lo = dst.address & VTD_MSI_ADDR_LO_MASK; route->u.msi.data = dst.data; + + if (kvm_has_msi_x2apic()) { + route->type = KVM_IRQ_ROUTING_MSI_X2APIC; + } } return 0;