From patchwork Fri Nov 17 06:22:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Gao X-Patchwork-Id: 10062325 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 12BD5604D4 for ; Fri, 17 Nov 2017 06:27:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 05B202A539 for ; Fri, 17 Nov 2017 06:27:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EE86A2A990; Fri, 17 Nov 2017 06:27:17 +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 9F0E82A825 for ; Fri, 17 Nov 2017 06:27:17 +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 1eFa5B-0000b8-Mp; Fri, 17 Nov 2017 06:24:57 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eFa5A-0000Zo-0Q for xen-devel@lists.xen.org; Fri, 17 Nov 2017 06:24:56 +0000 Received: from [85.158.143.35] by server-3.bemta-6.messagelabs.com id 96/E9-00303-7B08E0A5; Fri, 17 Nov 2017 06:24:55 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrPLMWRWlGSWpSXmKPExsVywNwkVndbA1+ UwYUWa4slHxezODB6HN39mymAMYo1My8pvyKBNWP/5+csBX+FK2adecfewPiCv4uRi0NIYDqj xOJdL1m6GDk5JAR4JY4sm8EKYQdIdFzqZ+pi5AAqqpI4eqccJMwmoCxx8WsvG4gtIiAtce3zZ UaQOcwCz5kllqz7ywiSEBawlZh/ZTE7iM0ioCqx88xMsDivgJPEuQt7GCHmK0hMefieGcTmFH CW2P/mIBOILQRUc3DdNKYJjLwLGBlWMaoXpxaVpRbpWuolFWWmZ5TkJmbm6BoamOnlphYXJ6a n5iQmFesl5+duYgQGAwMQ7GC8uyngEKMkB5OSKC+POV+UEF9SfkplRmJxRnxRaU5q8SFGGQ4O JQler3qgnGBRanpqRVpmDjAsYdISHDxKIrwFIGne4oLE3OLMdIjUKUZjjmczXzcwc0y72trEL MSSl5+XKiXOWwxSKgBSmlGaBzcIFi+XGGWlhHkZgU4T4ilILcrNLEGVf8UozsGoJMxbCTKFJz OvBG7fK6BTmIBOsbnBDXJKSSJCSqqBUdid/1Cp1l63qw9/rdjM5P/ie9PB6h96Wk8X14psVos 5zG11Xbs6e0NIWe1iJiPZ+b8537kVSy3b/3dqYk9eYBWbVMqPz7oWT5ZnVAalrPGUPrN4y99I lh06m9tU1i2/uTt1qcLT40tnuf6/XmrvvumbLUPikSu/c6NlLzP3fRFfpPFyTpOnshJLcUaio RZzUXEiAIrNQVySAgAA X-Env-Sender: chao.gao@intel.com X-Msg-Ref: server-12.tower-21.messagelabs.com!1510899867!82378134!9 X-Originating-IP: [192.55.52.93] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTkyLjU1LjUyLjkzID0+IDMyNDY2NQ==\n X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 56627 invoked from network); 17 Nov 2017 06:24:54 -0000 Received: from mga11.intel.com (HELO mga11.intel.com) (192.55.52.93) by server-12.tower-21.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 17 Nov 2017 06:24:54 -0000 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Nov 2017 22:24:54 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.44,407,1505804400"; d="scan'208"; a="1245165071" Received: from skl-4s-chao.sh.intel.com ([10.239.48.9]) by fmsmga002.fm.intel.com with ESMTP; 16 Nov 2017 22:24:51 -0800 From: Chao Gao To: xen-devel@lists.xen.org Date: Fri, 17 Nov 2017 14:22:15 +0800 Message-Id: <1510899755-40237-9-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 08/28] x86/vvtd: Add MMIO handler for VVTD 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 This patch adds VVTD MMIO handler to deal with MMIO access. Signed-off-by: Chao Gao Signed-off-by: Lan Tianyu --- v4: - only trap the register emulated in vvtd_in_range(). i.e. replace PAGE_SIZE with the VVTD_MAX_OFFSET --- xen/drivers/passthrough/vtd/vvtd.c | 55 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/xen/drivers/passthrough/vtd/vvtd.c b/xen/drivers/passthrough/vtd/vvtd.c index 9f76ccf..d78d878 100644 --- a/xen/drivers/passthrough/vtd/vvtd.c +++ b/xen/drivers/passthrough/vtd/vvtd.c @@ -94,6 +94,60 @@ static inline uint64_t vvtd_get_reg_quad(const struct vvtd *vvtd, uint32_t reg) return *(uint64_t*)VVTD_REG_POS(vvtd, reg); } +static void *domain_vvtd(const struct domain *d) +{ + if ( is_hvm_domain(d) && d->arch.hvm_domain.viommu ) + return d->arch.hvm_domain.viommu->priv; + else + return NULL; +} + +static int vvtd_in_range(struct vcpu *v, unsigned long addr) +{ + struct vvtd *vvtd = domain_vvtd(v->domain); + + if ( vvtd ) + return (addr >= vvtd->base_addr) && + (addr < vvtd->base_addr + VVTD_MAX_OFFSET); + return 0; +} + +static int vvtd_read(struct vcpu *v, unsigned long addr, + unsigned int len, unsigned long *pval) +{ + struct vvtd *vvtd = domain_vvtd(v->domain); + unsigned int offset = addr - vvtd->base_addr; + + vvtd_info("Read offset %x len %d\n", offset, len); + + if ( (len != 4 && len != 8) || (offset & (len - 1)) ) + return X86EMUL_OKAY; + + if ( len == 4 ) + *pval = vvtd_get_reg(vvtd, offset); + else + *pval = vvtd_get_reg_quad(vvtd, offset); + + return X86EMUL_OKAY; +} + +static int vvtd_write(struct vcpu *v, unsigned long addr, + unsigned int len, unsigned long val) +{ + struct vvtd *vvtd = domain_vvtd(v->domain); + unsigned int offset = addr - vvtd->base_addr; + + vvtd_info("Write offset %x len %d val %lx\n", offset, len, val); + + return X86EMUL_OKAY; +} + +static const struct hvm_mmio_ops vvtd_mmio_ops = { + .check = vvtd_in_range, + .read = vvtd_read, + .write = vvtd_write +}; + static void vvtd_reset(struct vvtd *vvtd) { uint64_t cap = cap_set_num_fault_regs(VVTD_FRCD_NUM) @@ -126,6 +180,7 @@ static int vvtd_create(struct domain *d, struct viommu *viommu) vvtd_reset(vvtd); vvtd->base_addr = viommu->base_address; vvtd->domain = d; + register_mmio_handler(d, &vvtd_mmio_ops); viommu->priv = vvtd;