From patchwork Fri Sep 22 03:02:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "lan,Tianyu" X-Patchwork-Id: 9965613 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 27310600C5 for ; Fri, 22 Sep 2017 09:12:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 22CC0297BA for ; Fri, 22 Sep 2017 09:12:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 17AD329817; Fri, 22 Sep 2017 09:12:58 +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=-2.7 required=2.0 tests=BAYES_00, DATE_IN_PAST_06_12, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 80049297BA for ; Fri, 22 Sep 2017 09:12:57 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dvJz9-00054b-Kv; Fri, 22 Sep 2017 09:10:59 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dvJz8-00050v-C2 for xen-devel@lists.xen.org; Fri, 22 Sep 2017 09:10:58 +0000 Received: from [85.158.139.211] by server-11.bemta-5.messagelabs.com id 53/9C-01810-1A3D4C95; Fri, 22 Sep 2017 09:10:57 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrNLMWRWlGSWpSXmKPExsXS1tYhorvw8pF Ig/snmS2WfFzM4sDocXT3b6YAxijWzLyk/IoE1oy1lzsYC+YrV1w6eo29gfGadBcjF4eQwHRG iX1tUxi7GDk5JAR4JY4sm8EKYQdIbP/3mB2iqINRYv29h+wgCTYBdYkTiyeCNYgISEtc+3yZE aSIWWAxo8TeDavAEsICgRKTfh9mA7FZBFQlvn/fzNLFyMHBK+Aqsfx7BMQCBYkpD98zg9icQO FffduZQGwhAReJ1qX7mSYw8i5gZFjFqFGcWlSWWqRrZKSXVJSZnlGSm5iZo2toYKqXm1pcnJi empOYVKyXnJ+7iREYEPUMDIw7GPe0+x1ilORgUhLl/XvpSKQQX1J+SmVGYnFGfFFpTmrxIUYZ Dg4lCd52kJxgUWp6akVaZg4wNGHSEhw8SiK8aiBp3uKCxNzizHSI1ClGXY6Om3f/MAmx5OXnp UqJ8+qBFAmAFGWU5sGNgMXJJUZZKWFeRgYGBiGegtSi3MwSVPlXjOIcjErCvNkgU3gy80rgNr 0COoIJ6Ijy1WBHlCQipKQaGJMjVxV7lU9wq1tysOLOz6yOheumn7tuxjFj/vHUA/sjHjyePjX w1OMX2lo3Tj9tNmH7NE9Ls/RFTd+FnVfXLD6h5fElLHS1+b+vqzTO6no8EnBa8e2xUmpPUecX zY3SZg2X3vXPOKyx6V3BN57NtapsP2WPzP+wYqW9uF8x34pZUz5pvH59MSpEiaU4I9FQi7moO BEAcsis3o4CAAA= X-Env-Sender: tianyu.lan@intel.com X-Msg-Ref: server-6.tower-206.messagelabs.com!1506071453!109924144!2 X-Originating-IP: [134.134.136.20] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTM0LjEzNC4xMzYuMjAgPT4gMzU1MzU4\n X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 13611 invoked from network); 22 Sep 2017 09:10:56 -0000 Received: from mga02.intel.com (HELO mga02.intel.com) (134.134.136.20) by server-6.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 22 Sep 2017 09:10:56 -0000 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 Sep 2017 02:10:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.42,427,1500966000"; d="scan'208"; a="1222293568" Received: from sky-ws.sh.intel.com (HELO localhost) ([10.239.48.141]) by fmsmga002.fm.intel.com with ESMTP; 22 Sep 2017 02:10:54 -0700 From: Lan Tianyu To: xen-devel@lists.xen.org Date: Thu, 21 Sep 2017 23:02:06 -0400 Message-Id: <1506049330-11196-26-git-send-email-tianyu.lan@intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1506049330-11196-1-git-send-email-tianyu.lan@intel.com> References: <1506049330-11196-1-git-send-email-tianyu.lan@intel.com> Cc: Lan Tianyu , kevin.tian@intel.com, andrew.cooper3@citrix.com, jbeulich@suse.com, Chao Gao , roger.pau@citrix.com Subject: [Xen-devel] [PATCH V3 25/29] x86/vmsi: Hook delivering remapping format msi to guest X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Chao Gao In two situations, hypervisor delivers a msi to a hvm guest. One is when qemu sends a request to hypervisor through XEN_DMOP_inject_msi. The other is when a physical interrupt arrives and it has been bound to a guest msi. For the former, the msi is routed to common vIOMMU layer if it is in remapping format. For the latter, if the pt irq is bound to a guest remapping msi, a new remapping msi is constructed based on the binding information and routed to common vIOMMU layer. Signed-off-by: Chao Gao Signed-off-by: Lan Tianyu --- xen/arch/x86/hvm/irq.c | 7 +++++++ xen/arch/x86/hvm/vmsi.c | 14 +++++++++++++- xen/drivers/passthrough/io.c | 21 ++++++++++----------- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/xen/arch/x86/hvm/irq.c b/xen/arch/x86/hvm/irq.c index e425df9..e99ba7d 100644 --- a/xen/arch/x86/hvm/irq.c +++ b/xen/arch/x86/hvm/irq.c @@ -23,9 +23,11 @@ #include #include #include +#include #include #include #include +#include /* Must be called with hvm_domain->irq_lock hold */ static void assert_gsi(struct domain *d, unsigned ioapic_gsi) @@ -339,6 +341,11 @@ int hvm_inject_msi(struct domain *d, uint64_t addr, uint32_t data) uint8_t trig_mode = (data & MSI_DATA_TRIGGER_MASK) >> MSI_DATA_TRIGGER_SHIFT; uint8_t vector = data & MSI_DATA_VECTOR_MASK; + struct arch_irq_remapping_request request; + + irq_request_msi_fill(&request, 0, addr, data); + if ( viommu_check_irq_remapping(d, &request) ) + return viommu_handle_irq_request(d, &request); if ( !vector ) { diff --git a/xen/arch/x86/hvm/vmsi.c b/xen/arch/x86/hvm/vmsi.c index 7f21853..1244df1 100644 --- a/xen/arch/x86/hvm/vmsi.c +++ b/xen/arch/x86/hvm/vmsi.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -39,6 +40,7 @@ #include #include #include +#include static void vmsi_inj_irq( struct vlapic *target, @@ -115,7 +117,17 @@ void vmsi_deliver_pirq(struct domain *d, const struct hvm_pirq_dpci *pirq_dpci) ASSERT(pirq_dpci->flags & HVM_IRQ_DPCI_GUEST_MSI); - vmsi_deliver(d, vector, dest, dest_mode, delivery_mode, trig_mode); + if ( pirq_dpci->flags & HVM_IRQ_DPCI_GUEST_REMAPPED ) + { + struct arch_irq_remapping_request request; + + irq_request_msi_fill(&request, pirq_dpci->gmsi.intremap.source_id, + pirq_dpci->gmsi.intremap.addr, + pirq_dpci->gmsi.intremap.data); + viommu_handle_irq_request(d, &request); + } + else + vmsi_deliver(d, vector, dest, dest_mode, delivery_mode, trig_mode); } /* Return value, -1 : multi-dests, non-negative value: dest_vcpu_id */ diff --git a/xen/drivers/passthrough/io.c b/xen/drivers/passthrough/io.c index 6196334..349a8cf 100644 --- a/xen/drivers/passthrough/io.c +++ b/xen/drivers/passthrough/io.c @@ -942,21 +942,20 @@ static void __msi_pirq_eoi(struct hvm_pirq_dpci *pirq_dpci) static int _hvm_dpci_msi_eoi(struct domain *d, struct hvm_pirq_dpci *pirq_dpci, void *arg) { - int vector = (long)arg; + uint8_t vector, dlm, vector_target = (long)arg; + uint32_t dest; + bool dm; - if ( (pirq_dpci->flags & HVM_IRQ_DPCI_MACH_MSI) && - (pirq_dpci->gmsi.legacy.gvec == vector) ) + if ( pirq_dpci->flags & HVM_IRQ_DPCI_MACH_MSI ) { - unsigned int dest = MASK_EXTR(pirq_dpci->gmsi.legacy.gflags, - XEN_DOMCTL_VMSI_X86_DEST_ID_MASK); - bool dest_mode = pirq_dpci->gmsi.legacy.gflags & - XEN_DOMCTL_VMSI_X86_DM_MASK; + if ( pirq_dpci_2_msi_attr(d, pirq_dpci, &vector, &dest, &dm, &dlm) ) + return 0; - if ( vlapic_match_dest(vcpu_vlapic(current), NULL, 0, dest, - dest_mode) ) + if ( vector == vector_target && + vlapic_match_dest(vcpu_vlapic(current), NULL, 0, dest, dm) ) { - __msi_pirq_eoi(pirq_dpci); - return 1; + __msi_pirq_eoi(pirq_dpci); + return 1; } }