From patchwork Fri Sep 22 03:02:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "lan,Tianyu" X-Patchwork-Id: 9965619 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 A4F3B600C5 for ; Fri, 22 Sep 2017 09:13:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A0BC5297BA for ; Fri, 22 Sep 2017 09:13:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 957BC2980B; Fri, 22 Sep 2017 09:13:08 +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 0828B297BA for ; Fri, 22 Sep 2017 09:13:08 +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 1dvJzN-0005Tk-12; Fri, 22 Sep 2017 09:11:13 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dvJzL-0005Qh-QU for xen-devel@lists.xen.org; Fri, 22 Sep 2017 09:11:11 +0000 Received: from [85.158.137.68] by server-6.bemta-3.messagelabs.com id 37/54-02225-FA3D4C95; Fri, 22 Sep 2017 09:11:11 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrFLMWRWlGSWpSXmKPExsXS1taRorvu8pF Ig/ur5C2WfFzM4sDocXT3b6YAxijWzLyk/IoE1ozpe28zFyyVq5j54xNzA+NliS5GTg4hgUqJ Be09zCC2hACvxJFlM1ghbH+Jnu2f2LoYuYBqOhglLl2fBlbEJqAucWLxREYQW0RAWuLa58uMI EXMAosZJZ63HGQHSQgLOEm075wL1sAioCrx+/xKsDivgKvElCkr2SA2KEhMefgerIYTKP6rbz sTxEUuEq1L9zNNYORdwMiwilG9OLWoLLVI11AvqSgzPaMkNzEzR9fQwFgvN7W4ODE9NScxqVg vOT93EyMwHBiAYAfj8o9OhxglOZiURHnfnz8SKcSXlJ9SmZFYnBFfVJqTWnyIUYaDQ0mC1+8S UE6wKDU9tSItMwcYmDBpCQ4eJRHeRJA0b3FBYm5xZjpE6hSjLkfHzbt/mIRY8vLzUqXEefVAi gRAijJK8+BGwKLkEqOslDAvI9BRQjwFqUW5mSWo8q8YxTkYlYR5V4JM4cnMK4Hb9AroCCagI8 pXgx1RkoiQkmpg5FgoYfmeW8zWrafhYtatz7P3R4k9bRHclZKmO8v8/e1MA5a+xXu+MVwzNr/ P/fCf5dxpE169NeC0ePNkglWk6cYobw3tjzPv9/yM3ux2faqbj5C62fXap8abt15LZ+NyW1As /XuJ+Q7nHc1W7N8fqJ2efoeTo/+L3+Wgqz1/te3MTl46ZRNTqcRSnJFoqMVcVJwIAA0CrRGNA gAA X-Env-Sender: tianyu.lan@intel.com X-Msg-Ref: server-9.tower-31.messagelabs.com!1506071468!60537813!1 X-Originating-IP: [134.134.136.100] X-SpamReason: No, hits=0.8 required=7.0 tests=DATE_IN_PAST_06_12 X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 22172 invoked from network); 22 Sep 2017 09:11:10 -0000 Received: from mga07.intel.com (HELO mga07.intel.com) (134.134.136.100) by server-9.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 22 Sep 2017 09:11:10 -0000 Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga105.jf.intel.com with ESMTP; 22 Sep 2017 02:11:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.42,427,1500966000"; d="scan'208";a="154276774" Received: from sky-ws.sh.intel.com (HELO localhost) ([10.239.48.141]) by fmsmga005.fm.intel.com with ESMTP; 22 Sep 2017 02:11:06 -0700 From: Lan Tianyu To: xen-devel@lists.xen.org Date: Thu, 21 Sep 2017 23:02:10 -0400 Message-Id: <1506049330-11196-30-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 29/29] x86/vvtd: save and restore emulated VT-d 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 Provide a save-restore pair to save/restore registers and non-register status. Signed-off-by: Chao Gao Signed-off-by: Lan Tianyu --- v3: - use one entry to save both vvtd registers and other intermediate state --- xen/drivers/passthrough/vtd/vvtd.c | 66 ++++++++++++++++++++++++++-------- xen/include/public/arch-x86/hvm/save.h | 25 ++++++++++++- 2 files changed, 76 insertions(+), 15 deletions(-) diff --git a/xen/drivers/passthrough/vtd/vvtd.c b/xen/drivers/passthrough/vtd/vvtd.c index 668d0c9..2aecd93 100644 --- a/xen/drivers/passthrough/vtd/vvtd.c +++ b/xen/drivers/passthrough/vtd/vvtd.c @@ -28,11 +28,13 @@ #include #include #include +#include #include #include #include #include #include +#include #include "iommu.h" #include "vtd.h" @@ -40,20 +42,6 @@ /* Supported capabilities by vvtd */ unsigned int vvtd_caps = VIOMMU_CAP_IRQ_REMAPPING; -struct hvm_hw_vvtd_status { - uint32_t eim_enabled : 1, - intremap_enabled : 1; - uint32_t fault_index; - uint32_t irt_max_entry; - /* Interrupt remapping table base gfn */ - uint64_t irt; -}; - -union hvm_hw_vvtd_regs { - uint32_t data32[256]; - uint64_t data64[128]; -}; - struct vvtd { /* Address range of remapping hardware register-set */ uint64_t base_addr; @@ -1057,6 +1045,56 @@ static bool vvtd_is_remapping(struct domain *d, return 0; } +static int vvtd_load(struct domain *d, hvm_domain_context_t *h) +{ + struct hvm_hw_vvtd *hw_vvtd; + + if ( !domain_vvtd(d) ) + return -ENODEV; + + hw_vvtd = xmalloc(struct hvm_hw_vvtd); + if ( !hw_vvtd ) + return -ENOMEM; + + if ( hvm_load_entry(VVTD, h, hw_vvtd) ) + { + xfree(hw_vvtd); + return -EINVAL; + } + + memcpy(&domain_vvtd(d)->status, &hw_vvtd->status, + sizeof(struct hvm_hw_vvtd_status)); + memcpy(domain_vvtd(d)->regs, &hw_vvtd->regs, + sizeof(union hvm_hw_vvtd_regs)); + xfree(hw_vvtd); + + return 0; +} + +static int vvtd_save(struct domain *d, hvm_domain_context_t *h) +{ + struct hvm_hw_vvtd *hw_vvtd; + int ret; + + if ( !domain_vvtd(d) ) + return 0; + + hw_vvtd = xmalloc(struct hvm_hw_vvtd); + if ( !hw_vvtd ) + return -ENOMEM; + + memcpy(&hw_vvtd->status, &domain_vvtd(d)->status, + sizeof(struct hvm_hw_vvtd_status)); + memcpy(&hw_vvtd->regs, domain_vvtd(d)->regs, + sizeof(union hvm_hw_vvtd_regs)); + ret = hvm_save_entry(VVTD, 0, h, hw_vvtd); + xfree(hw_vvtd); + + return ret; +} + +HVM_REGISTER_SAVE_RESTORE(VVTD, vvtd_save, vvtd_load, 1, HVMSR_PER_DOM); + static void vvtd_reset(struct vvtd *vvtd, uint64_t capability) { uint64_t cap = cap_set_num_fault_regs(1ULL) | diff --git a/xen/include/public/arch-x86/hvm/save.h b/xen/include/public/arch-x86/hvm/save.h index fd7bf3f..181abb2 100644 --- a/xen/include/public/arch-x86/hvm/save.h +++ b/xen/include/public/arch-x86/hvm/save.h @@ -639,10 +639,33 @@ struct hvm_msr { #define CPU_MSR_CODE 20 +union hvm_hw_vvtd_regs { + uint32_t data32[256]; + uint64_t data64[128]; +}; + +struct hvm_hw_vvtd_status +{ + uint32_t eim_enabled : 1, + intremap_enabled : 1; + uint32_t fault_index; + uint32_t irt_max_entry; + /* Interrupt remapping table base gfn */ + uint64_t irt; +}; + +struct hvm_hw_vvtd +{ + union hvm_hw_vvtd_regs regs; + struct hvm_hw_vvtd_status status; +}; + +DECLARE_HVM_SAVE_TYPE(VVTD, 21, struct hvm_hw_vvtd); + /* * Largest type-code in use */ -#define HVM_SAVE_CODE_MAX 20 +#define HVM_SAVE_CODE_MAX 21 #endif /* __XEN_PUBLIC_HVM_SAVE_X86_H__ */