From patchwork Fri Nov 17 06:24:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Gao X-Patchwork-Id: 10062367 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 AE5C86023A for ; Fri, 17 Nov 2017 06:28:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A132A2A539 for ; Fri, 17 Nov 2017 06:28:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 951E02A990; Fri, 17 Nov 2017 06:28:20 +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 F419B2A539 for ; Fri, 17 Nov 2017 06:28:19 +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 1eFa6d-0002Zi-7C; Fri, 17 Nov 2017 06:26:27 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eFa6c-0002XY-Jb for xen-devel@lists.xenproject.org; Fri, 17 Nov 2017 06:26:26 +0000 Received: from [85.158.143.35] by server-11.bemta-6.messagelabs.com id 62/42-09576-1118E0A5; Fri, 17 Nov 2017 06:26:25 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpjkeJIrShJLcpLzFFi42Jpa+sQ0RVs5Is yOHZPxuL7lslMDowehz9cYQlgjGLNzEvKr0hgzdgxayZ7wQvlijk/LBsYl8p2MXJxCAlMZ5TY fvcYaxcjJ4eEAK/EkWUzoGxfiZWPj7KD2EICVRKbnrxjBrHZBJQlLn7tZQOxRQQkJX53nWYGG cQs0MIssXnTTBaQhLCAu8TzM+fBBrEIqEpM3bcNLM4r4CRx/OlOJogFChJTHr4HG8op4CyxqP cTC8QyJ4nWlzuYJjDyLmBkWMWoUZxaVJZapGtkqZdUlJmeUZKbmJmja2hgppebWlycmJ6ak5h UrJecn7uJERgODECwg/HAosBDjJIcTEqivDzmfFFCfEn5KZUZicUZ8UWlOanFhxhlODiUJHiZ GoBygkWp6akVaZk5wMCESUtw8CiJ8BbUA6V5iwsSc4sz0yFSpxgtOY5tuvyHiePZzNcNzBzTr rY2MQux5OXnpUqJ8/qCzBMAacgozYMbB4ueS4yyUsK8jEAHCvEUpBblZpagyr9iFOdgVBLm1Q OZwpOZVwK39RXQQUxAB9nc4AY5qCQRISXVwLgp4+3/9VdKVvp2vE748TVbPtjUmN9d4XZhhaz R1U1t3Xy3dxtcPSJ0bLa8I/+kp1UevE4XnYNWiITbXj9xb8W/uycNm2azWXxsMTr4tuya2YPN Z2qONExeGrHbIvPSsm3MRut4crZ3L5H2CmcyE9zoF7Ai31Ntk1aA/FNzpVk8P501ZnmqL1BiK c5INNRiLipOBAAI2yfAmQIAAA== X-Env-Sender: chao.gao@intel.com X-Msg-Ref: server-3.tower-21.messagelabs.com!1510899982!78918016!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 7781 invoked from network); 17 Nov 2017 06:26:25 -0000 Received: from mga02.intel.com (HELO mga02.intel.com) (134.134.136.20) by server-3.tower-21.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 17 Nov 2017 06:26:25 -0000 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Nov 2017 22:26:24 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,407,1505804400"; d="scan'208";a="2622234" Received: from skl-4s-chao.sh.intel.com ([10.239.48.9]) by fmsmga004.fm.intel.com with ESMTP; 16 Nov 2017 22:26:22 -0800 From: Chao Gao To: qemu-devel@nongnu.org Date: Fri, 17 Nov 2017 14:24:25 +0800 Message-Id: <1510899865-40323-4-git-send-email-chao.gao@intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1510899865-40323-1-git-send-email-chao.gao@intel.com> References: <1510899865-40323-1-git-send-email-chao.gao@intel.com> Cc: Lan Tianyu , Stefano Stabellini , Eduardo Habkost , "Michael S. Tsirkin" , Anthony Perard , Paolo Bonzini , Marcel Apfelbaum , xen-devel@lists.xenproject.org, Chao Gao , Richard Henderson Subject: [Xen-devel] [PATCH v3 3/3] msi: Handle remappable format interrupt request 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 According to VT-d spec Interrupt Remapping and Interrupt Posting -> Interrupt Remapping -> Interrupt Request Formats On Intel 64 Platforms, fields of MSI data register have changed. This patch avoids wrongly regarding a remappable format interrupt request as an interrupt binded with a pirq. Signed-off-by: Chao Gao Signed-off-by: Lan Tianyu --- v3: - clarify the interrupt format bit is Intel-specific, then it is improper to define MSI_ADDR_IF_MASK in a common header. --- hw/i386/xen/xen-hvm.c | 10 +++++++++- hw/pci/msi.c | 5 +++-- hw/pci/msix.c | 4 +++- hw/xen/xen_pt_msi.c | 2 +- include/hw/xen/xen.h | 2 +- stubs/xen-hvm.c | 2 +- 6 files changed, 18 insertions(+), 7 deletions(-) diff --git a/hw/i386/xen/xen-hvm.c b/hw/i386/xen/xen-hvm.c index 8028bed..52dc8af 100644 --- a/hw/i386/xen/xen-hvm.c +++ b/hw/i386/xen/xen-hvm.c @@ -145,8 +145,16 @@ void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len) } } -int xen_is_pirq_msi(uint32_t msi_data) +int xen_is_pirq_msi(uint32_t msi_addr_lo, uint32_t msi_data) { + /* If the MSI address is configured in remapping format, the MSI will not + * be remapped into a pirq. This 'if' test excludes Intel-specific + * remappable msi. + */ +#define MSI_ADDR_IF_MASK 0x00000010 + if (msi_addr_lo & MSI_ADDR_IF_MASK) { + return 0; + } /* If vector is 0, the msi is remapped into a pirq, passed as * dest_id. */ diff --git a/hw/pci/msi.c b/hw/pci/msi.c index 5e05ce5..d05c876 100644 --- a/hw/pci/msi.c +++ b/hw/pci/msi.c @@ -289,7 +289,7 @@ void msi_reset(PCIDevice *dev) static bool msi_is_masked(const PCIDevice *dev, unsigned int vector) { uint16_t flags = pci_get_word(dev->config + msi_flags_off(dev)); - uint32_t mask, data; + uint32_t mask, data, addr_lo; bool msi64bit = flags & PCI_MSI_FLAGS_64BIT; assert(vector < PCI_MSI_VECTORS_MAX); @@ -298,7 +298,8 @@ static bool msi_is_masked(const PCIDevice *dev, unsigned int vector) } data = pci_get_word(dev->config + msi_data_off(dev, msi64bit)); - if (xen_is_pirq_msi(data)) { + addr_lo = pci_get_long(dev->config + msi_address_lo_off(dev)); + if (xen_is_pirq_msi(addr_lo, data)) { return false; } diff --git a/hw/pci/msix.c b/hw/pci/msix.c index c944c02..4cb01db 100644 --- a/hw/pci/msix.c +++ b/hw/pci/msix.c @@ -83,9 +83,11 @@ static bool msix_vector_masked(PCIDevice *dev, unsigned int vector, bool fmask) { unsigned offset = vector * PCI_MSIX_ENTRY_SIZE; uint8_t *data = &dev->msix_table[offset + PCI_MSIX_ENTRY_DATA]; + uint8_t *addr_lo = &dev->msix_table[offset + PCI_MSIX_ENTRY_LOWER_ADDR]; /* MSIs on Xen can be remapped into pirqs. In those cases, masking * and unmasking go through the PV evtchn path. */ - if (xen_enabled() && xen_is_pirq_msi(pci_get_long(data))) { + if (xen_enabled() && xen_is_pirq_msi(pci_get_long(addr_lo), + pci_get_long(data))) { return false; } return fmask || dev->msix_table[offset + PCI_MSIX_ENTRY_VECTOR_CTRL] & diff --git a/hw/xen/xen_pt_msi.c b/hw/xen/xen_pt_msi.c index f7d6e76..0e5bf83 100644 --- a/hw/xen/xen_pt_msi.c +++ b/hw/xen/xen_pt_msi.c @@ -96,7 +96,7 @@ static int msi_msix_setup(XenPCIPassthroughState *s, assert((!is_msix && msix_entry == 0) || is_msix); - if (xen_is_pirq_msi(data)) { + if (xen_is_pirq_msi(addr, data)) { *ppirq = msi_ext_dest_id(addr >> 32) | msi_dest_id(addr); if (!*ppirq) { /* this probably identifies an misconfiguration of the guest, diff --git a/include/hw/xen/xen.h b/include/hw/xen/xen.h index 7efcdaa..0d6c83e 100644 --- a/include/hw/xen/xen.h +++ b/include/hw/xen/xen.h @@ -34,7 +34,7 @@ int xen_pci_slot_get_pirq(PCIDevice *pci_dev, int irq_num); void xen_piix3_set_irq(void *opaque, int irq_num, int level); void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len); void xen_hvm_inject_msi(uint64_t addr, uint32_t data); -int xen_is_pirq_msi(uint32_t msi_data); +int xen_is_pirq_msi(uint32_t msi_addr_lo, uint32_t msi_data); qemu_irq *xen_interrupt_controller_init(void); diff --git a/stubs/xen-hvm.c b/stubs/xen-hvm.c index 3ca6c51..aeb1592 100644 --- a/stubs/xen-hvm.c +++ b/stubs/xen-hvm.c @@ -31,7 +31,7 @@ void xen_hvm_inject_msi(uint64_t addr, uint32_t data) { } -int xen_is_pirq_msi(uint32_t msi_data) +int xen_is_pirq_msi(uint32_t msi_addr_lo, uint32_t msi_data) { return 0; }