From patchwork Fri Nov 17 06:22:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Gao X-Patchwork-Id: 10062345 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 563D26023A for ; Fri, 17 Nov 2017 06:27:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 491002A539 for ; Fri, 17 Nov 2017 06:27:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3DF382A990; Fri, 17 Nov 2017 06:27:33 +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=-4.2 required=2.0 tests=BAYES_00, 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 ABEF62A539 for ; Fri, 17 Nov 2017 06:27:32 +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 1eFa5y-0001Zl-Mi; Fri, 17 Nov 2017 06:25:46 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eFa5x-0001XR-U3 for xen-devel@lists.xen.org; Fri, 17 Nov 2017 06:25:46 +0000 Received: from [85.158.139.211] by server-9.bemta-5.messagelabs.com id 30/6F-25868-9E08E0A5; Fri, 17 Nov 2017 06:25:45 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrPLMWRWlGSWpSXmKPExsXS1tYhofuigS/ KYEOfhsWSj4tZHBg9ju7+zRTAGMWamZeUX5HAmrHi9Gemgk86FXemXGNrYHyk1MXIxSEkMJ1R orunl6WLkZNDQoBX4siyGaxdjBxAdoDEl057kLCQQJXE6r5WRhCbTUBZ4uLXXjYQW0RAWuLa5 8tgcWaB58wS8xq1QGxhgSSJ/RdbmEBsFgFViQ07LoDV8Ao4S9x6so4RYpWCxJSH75lBbE6g+P 43B5kgdjlJHFw3jWkCI+8CRoZVjBrFqUVlqUW6hqZ6SUWZ6RkluYmZObqGBqZ6uanFxYnpqTm JScV6yfm5mxiBwcAABDsYG7Z7HmKU5GBSEuXlMeeLEuJLyk+pzEgszogvKs1JLT7EKMPBoSTB e6weKCdYlJqeWpGWmQMMS5i0BAePkghvIjA0hXiLCxJzizPTIVKnGI05ns183cDMMe1qaxOzE Etefl6qlDjvfZBJAiClGaV5cINg8XKJUVZKmJcR6DQhnoLUotzMElT5V4ziHIxKwryVIFN4Mv NK4Pa9AjqFCegUmxvcIKeUJCKkpBoYde4YJCV1vPVn9m7WufxRfOreSKY3Wc9OTFr8Zbbesq8 J/9Xt6u5HKd561jq35ZZpV//eZL/Mqz0vK4rLHDIvRhn7n3h1rFLzG5vRA/PJX+odez3d3fVn C31qSYw+9OVkzNHC+TVskUar51QwN9tqO39hnRPX2vmXuS3G5LdBjz1r0fHYqceUWIozEg21m IuKEwGBg1sMkgIAAA== X-Env-Sender: chao.gao@intel.com X-Msg-Ref: server-11.tower-206.messagelabs.com!1510899922!87798367!8 X-Originating-IP: [134.134.136.24] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTM0LjEzNC4xMzYuMjQgPT4gMzkwOTcx\n X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 53909 invoked from network); 17 Nov 2017 06:25:44 -0000 Received: from mga09.intel.com (HELO mga09.intel.com) (134.134.136.24) by server-11.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 17 Nov 2017 06:25:44 -0000 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Nov 2017 22:25:43 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.44,407,1505804400"; d="scan'208"; a="1245165339" Received: from skl-4s-chao.sh.intel.com ([10.239.48.9]) by fmsmga002.fm.intel.com with ESMTP; 16 Nov 2017 22:25:41 -0800 From: Chao Gao To: xen-devel@lists.xen.org Date: Fri, 17 Nov 2017 14:22:29 +0800 Message-Id: <1510899755-40237-23-git-send-email-chao.gao@intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1510899755-40237-1-git-send-email-chao.gao@intel.com> References: <1510899755-40237-1-git-send-email-chao.gao@intel.com> Cc: Lan Tianyu , Kevin Tian , Stefano Stabellini , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Ian Jackson , Tim Deegan , Jan Beulich , Andrew Cooper , Chao Gao , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [Xen-devel] [PATCH v4 22/28] x86/vmsi: Hook delivering remapping format msi to guest and handling eoi 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 When delivering guest msi, firstly, the format of the msi is determined by the 'check_irq_remmapping' method of viommu. Then, msi of non-remapping format is delivered as normal and remapping format msi is handled by viommu. When handling eoi, the interrupt attributes (vector, affinity) are used to search the physical irq. It is clear that for remapping format msi, the interrupt attributs should be decodes from IRTE. Signed-off-by: Chao Gao Signed-off-by: Lan Tianyu --- xen/arch/x86/hvm/irq.c | 6 ++++++ xen/arch/x86/hvm/vmsi.c | 33 +++++++++++++++++++++------------ xen/drivers/passthrough/io.c | 35 +++++++++++++++++++++++++++-------- 3 files changed, 54 insertions(+), 20 deletions(-) diff --git a/xen/arch/x86/hvm/irq.c b/xen/arch/x86/hvm/irq.c index e425df9..b561480 100644 --- a/xen/arch/x86/hvm/irq.c +++ b/xen/arch/x86/hvm/irq.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -339,6 +340,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, 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 5edb0e7..9dc5631 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 @@ -101,21 +102,29 @@ int vmsi_deliver( void vmsi_deliver_pirq(struct domain *d, const struct hvm_pirq_dpci *pirq_dpci) { - uint8_t vector = pirq_dpci->gmsi.data & MSI_DATA_VECTOR_MASK; - uint8_t dest = MASK_EXTR(pirq_dpci->gmsi.addr, MSI_ADDR_DEST_ID_MASK); - bool dest_mode = pirq_dpci->gmsi.addr & MSI_ADDR_DESTMODE_MASK; - uint8_t delivery_mode = MASK_EXTR(pirq_dpci->gmsi.data, - MSI_DATA_DELIVERY_MODE_MASK); - bool trig_mode = pirq_dpci->gmsi.data & MSI_DATA_TRIGGER_MASK; - - HVM_DBG_LOG(DBG_LEVEL_IOAPIC, - "msi: dest=%x dest_mode=%x delivery_mode=%x " - "vector=%x trig_mode=%x\n", - dest, dest_mode, delivery_mode, vector, trig_mode); + struct arch_irq_remapping_request request; ASSERT(pirq_dpci->flags & HVM_IRQ_DPCI_GUEST_MSI); - vmsi_deliver(d, vector, dest, dest_mode, delivery_mode, trig_mode); + irq_request_msi_fill(&request, pirq_dpci->gmsi.addr, pirq_dpci->gmsi.data); + if ( viommu_check_irq_remapping(d, &request) ) + viommu_handle_irq_request(d, &request); + else + { + uint8_t vector = pirq_dpci->gmsi.data & MSI_DATA_VECTOR_MASK; + uint8_t dest = MASK_EXTR(pirq_dpci->gmsi.addr, MSI_ADDR_DEST_ID_MASK); + bool dest_mode = pirq_dpci->gmsi.addr & MSI_ADDR_DESTMODE_MASK; + uint8_t delivery_mode = MASK_EXTR(pirq_dpci->gmsi.data, + MSI_DATA_DELIVERY_MODE_MASK); + bool trig_mode = pirq_dpci->gmsi.data & MSI_DATA_TRIGGER_MASK; + + HVM_DBG_LOG(DBG_LEVEL_IOAPIC, + "msi: dest=%x dest_mode=%x delivery_mode=%x " + "vector=%x trig_mode=%x\n", + dest, dest_mode, delivery_mode, vector, trig_mode); + + 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 9198ef5..34a3cf1 100644 --- a/xen/drivers/passthrough/io.c +++ b/xen/drivers/passthrough/io.c @@ -872,16 +872,35 @@ 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; - - if ( (pirq_dpci->flags & HVM_IRQ_DPCI_MACH_MSI) && - (pirq_dpci->gmsi.gvec == vector) ) + if ( pirq_dpci->flags & HVM_IRQ_DPCI_MACH_MSI ) { - uint32_t dest = MASK_EXTR(pirq_dpci->gmsi.addr, MSI_ADDR_DEST_ID_MASK); - bool dest_mode = pirq_dpci->gmsi.addr & MSI_ADDR_DESTMODE_MASK; + uint8_t vector, vector_target = (long)arg; + uint32_t dest; + bool dm; + struct arch_irq_remapping_request request; + + irq_request_msi_fill(&request, pirq_dpci->gmsi.addr, + pirq_dpci->gmsi.data); + if ( viommu_check_irq_remapping(d, &request) ) + { + struct arch_irq_remapping_info info; + + if ( viommu_get_irq_info(d, &request, &info) ) + return 0; + + vector = info.vector; + dest = info.dest; + dm = info.dest_mode; + } + else + { + vector = pirq_dpci->gmsi.data & MSI_DATA_VECTOR_MASK; + dest = MASK_EXTR(pirq_dpci->gmsi.addr, MSI_ADDR_DEST_ID_MASK); + dm = pirq_dpci->gmsi.addr & MSI_ADDR_DESTMODE_MASK; + } - 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;