From patchwork Thu May 18 05:34:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "lan,Tianyu" X-Patchwork-Id: 9733879 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 87654601BC for ; Thu, 18 May 2017 11:42:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 76DBB20952 for ; Thu, 18 May 2017 11:42:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6B7D02621D; Thu, 18 May 2017 11:42:45 +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 EEA4C20952 for ; Thu, 18 May 2017 11:42:44 +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 1dBJnN-0004aw-Fg; Thu, 18 May 2017 11:40:41 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dBJnL-0004XC-NY for xen-devel@lists.xen.org; Thu, 18 May 2017 11:40:39 +0000 Received: from [85.158.137.68] by server-17.bemta-3.messagelabs.com id 8A/EC-02955-6388D195; Thu, 18 May 2017 11:40:38 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrLLMWRWlGSWpSXmKPExsVywNykQtesQzb SoPGugsWSj4tZHBg9ju7+zRTAGMWamZeUX5HAmrHs2Tr2guMaFav7f7I3MH6X62Lk4hASmMYo sWzpHPYuRk4OCQFeiSPLZrBC2H4Sz07fYIIo6mCU2HD2CRtIgk1AXeLE4omMILaIgLTEtc+Xw WxmgX2MEm+eq3YxcnAIC0RJ3NjpAmKyCKhKnL/CBFLBK+AqsX7qUTaI8QoSUx6+ZwaxOYHi27 beYgGxhQRcJBoX9rJOYORdwMiwilGjOLWoLLVI18hEL6koMz2jJDcxM0fX0MBYLze1uDgxPTU nMalYLzk/dxMjMBjqGRgYdzC+Ou53iFGSg0lJlPdwgWykEF9SfkplRmJxRnxRaU5q8SFGGQ4O JQlevnagnGBRanpqRVpmDjAsYdISHDxKIrwpIGne4oLE3OLMdIjUKUZFKXFeL5CEAEgiozQPr g0WC5cYZaWEeRkZGBiEeApSi3IzS1DlXzGKczAqCfNWgUzhycwrgZv+CmgxE9Di5gfSIItLEh FSUg2MPZq55z1j1vTev1/wPmeZjfK2H66786KDb5/oO+F0IcbVZ4vGo1MR3X5HIz/Nsan7HRE oPmnZzG3Sp2d6/TLbqmLGxzF3CufTLyt0XybevfRlSVj4ocezw7IsjI0/bxFdYMxz8kF2yelL 5S59WxgCOCwcrqYqhHG+n+cmFMqZs9ls13mppikxSizFGYmGWsxFxYkARP+9b4ACAAA= X-Env-Sender: tianyu.lan@intel.com X-Msg-Ref: server-8.tower-31.messagelabs.com!1495107635!101206705!2 X-Originating-IP: [192.55.52.120] X-SpamReason: No, hits=1.3 required=7.0 tests=BODY_RANDOM_LONG, DATE_IN_PAST_06_12 X-StarScan-Received: X-StarScan-Version: 9.4.12; banners=-,-,- X-VirusChecked: Checked Received: (qmail 10989 invoked from network); 18 May 2017 11:40:38 -0000 Received: from mga04.intel.com (HELO mga04.intel.com) (192.55.52.120) by server-8.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 18 May 2017 11:40:38 -0000 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 May 2017 04:40:37 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.38,358,1491289200"; d="scan'208";a="88640545" Received: from sky-ws.sh.intel.com (HELO localhost) ([10.239.48.124]) by orsmga002.jf.intel.com with ESMTP; 18 May 2017 04:40:35 -0700 From: Lan Tianyu To: xen-devel@lists.xen.org Date: Thu, 18 May 2017 01:34:43 -0400 Message-Id: <1495085696-10819-14-git-send-email-tianyu.lan@intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1495085696-10819-1-git-send-email-tianyu.lan@intel.com> References: <1495085696-10819-1-git-send-email-tianyu.lan@intel.com> Cc: Lan Tianyu , kevin.tian@intel.com, wei.liu2@citrix.com, andrew.cooper3@citrix.com, ian.jackson@eu.citrix.com, jbeulich@suse.com, Chao Gao Subject: [Xen-devel] [RFC PATCH V2 13/26] X86/vvtd: Set Interrupt Remapping Table Pointer through GCMD 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 Software sets this field to set/update the interrupt remapping table pointer used by hardware. The interrupt remapping table pointer is specified through the Interrupt Remapping Table Address (IRTA_REG) register. This patch emulates this operation and adds some new fields in VVTD to track info (e.g. the table's gfn and max supported entries) of interrupt remapping table. Signed-off-by: Chao Gao Signed-off-by: Lan Tianyu --- xen/arch/x86/hvm/vvtd.c | 70 +++++++++++++++++++++++++++++++++++++ xen/drivers/passthrough/vtd/iommu.h | 9 ++++- 2 files changed, 78 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/hvm/vvtd.c b/xen/arch/x86/hvm/vvtd.c index b0a23ee..b6fd34b 100644 --- a/xen/arch/x86/hvm/vvtd.c +++ b/xen/arch/x86/hvm/vvtd.c @@ -46,6 +46,13 @@ struct vvtd { uint64_t length; /* Point back to the owner domain */ struct domain *domain; + /* Is in Extended Interrupt Mode? */ + bool eim; + /* Max remapping entries in IRT */ + int irt_max_entry; + /* Interrupt remapping table base gfn */ + uint64_t irt; + struct hvm_hw_vvtd_regs *regs; struct page_info *regs_page; }; @@ -82,6 +89,11 @@ static inline struct vvtd *vcpu_vvtd(struct vcpu *v) return domain_vvtd(v->domain); } +static inline void __vvtd_set_bit(struct vvtd *vvtd, uint32_t reg, int nr) +{ + return __set_bit(nr, (uint32_t *)&vvtd->regs->data[reg]); +} + static inline void vvtd_set_reg(struct vvtd *vtd, uint32_t reg, uint32_t value) { @@ -108,6 +120,41 @@ static inline uint8_t vvtd_get_reg_byte(struct vvtd *vtd, uint32_t reg) vvtd_set_reg(vvtd, (reg) + 4, (val) >> 32); \ } while(0) +static int vvtd_handle_gcmd_sirtp(struct vvtd *vvtd, uint32_t val) +{ + uint64_t irta; + + if ( !(val & DMA_GCMD_SIRTP) ) + return X86EMUL_OKAY; + + vvtd_get_reg_quad(vvtd, DMAR_IRTA_REG, irta); + vvtd->irt = DMA_IRTA_ADDR(irta) >> PAGE_SHIFT; + vvtd->irt_max_entry = DMA_IRTA_SIZE(irta); + vvtd->eim = DMA_IRTA_EIME(irta); + VVTD_DEBUG(VVTD_DBG_RW, "Update IR info (addr=%lx eim=%d size=%d).", + vvtd->irt, vvtd->eim, vvtd->irt_max_entry); + __vvtd_set_bit(vvtd, DMAR_GSTS_REG, DMA_GSTS_SIRTPS_BIT); + + return X86EMUL_OKAY; +} + +static int vvtd_write_gcmd(struct vvtd *vvtd, uint32_t val) +{ + uint32_t orig = vvtd_get_reg(vvtd, DMAR_GSTS_REG); + uint32_t changed = orig ^ val; + + if ( !changed ) + return X86EMUL_OKAY; + if ( (changed & (changed - 1)) ) + VVTD_DEBUG(VVTD_DBG_RW, "Guest attempts to update multiple fields " + "of GCMD_REG in one write transation."); + + if ( changed & DMA_GCMD_SIRTP ) + vvtd_handle_gcmd_sirtp(vvtd, val); + + return X86EMUL_OKAY; +} + static int vvtd_range(struct vcpu *v, unsigned long addr) { struct vvtd *vvtd = vcpu_vvtd(v); @@ -175,12 +222,18 @@ static int vvtd_write(struct vcpu *v, unsigned long addr, { switch ( offset_aligned ) { + case DMAR_GCMD_REG: + ret = vvtd_write_gcmd(vvtd, val); + break; + case DMAR_IEDATA_REG: case DMAR_IEADDR_REG: case DMAR_IEUADDR_REG: case DMAR_FEDATA_REG: case DMAR_FEADDR_REG: case DMAR_FEUADDR_REG: + case DMAR_IRTA_REG: + case DMAR_IRTA_REG_HI: vvtd_set_reg(vvtd, offset_aligned, val); ret = X86EMUL_OKAY; break; @@ -190,6 +243,20 @@ static int vvtd_write(struct vcpu *v, unsigned long addr, break; } } + else if ( len == 8 ) + { + switch ( offset_aligned ) + { + case DMAR_IRTA_REG: + vvtd_set_reg_quad(vvtd, DMAR_IRTA_REG, val); + ret = X86EMUL_OKAY; + break; + + default: + ret = X86EMUL_UNHANDLEABLE; + break; + } + } else ret = X86EMUL_UNHANDLEABLE; @@ -266,6 +333,9 @@ static int vvtd_create(struct domain *d, struct viommu *viommu) vvtd->length = viommu->length; vvtd->domain = d; vvtd->status = 0; + vvtd->eim = 0; + vvtd->irt = 0; + vvtd->irt_max_entry = 0; register_mmio_handler(d, &vvtd_mmio_ops); return 0; diff --git a/xen/drivers/passthrough/vtd/iommu.h b/xen/drivers/passthrough/vtd/iommu.h index 2e9dcaa..fd040d0 100644 --- a/xen/drivers/passthrough/vtd/iommu.h +++ b/xen/drivers/passthrough/vtd/iommu.h @@ -195,9 +195,16 @@ #define DMA_GSTS_WBFS (((u64)1) << 27) #define DMA_GSTS_QIES (((u64)1) <<26) #define DMA_GSTS_IRES (((u64)1) <<25) -#define DMA_GSTS_SIRTPS (((u64)1) << 24) +#define DMA_GSTS_SIRTPS_BIT 24 +#define DMA_GSTS_SIRTPS (((u64)1) << DMA_GSTS_SIRTPS_BIT) #define DMA_GSTS_CFIS (((u64)1) <<23) +/* IRTA_REG */ +#define DMA_IRTA_ADDR(val) (val & ~0xfffULL) +#define DMA_IRTA_EIME(val) (!!(val & (1 << 11))) +#define DMA_IRTA_S(val) (val & 0xf) +#define DMA_IRTA_SIZE(val) (1UL << (DMA_IRTA_S(val) + 1)) + /* PMEN_REG */ #define DMA_PMEN_EPM (((u32)1) << 31) #define DMA_PMEN_PRS (((u32)1) << 0)