From patchwork Fri Oct 28 02:37:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wu, Feng" X-Patchwork-Id: 9400993 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 191C9606DB for ; Fri, 28 Oct 2016 03:12:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 08D822A4DE for ; Fri, 28 Oct 2016 03:12:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F21322A4E0; Fri, 28 Oct 2016 03:12:12 +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 A32642A4DF for ; Fri, 28 Oct 2016 03:12:12 +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 1bzxXq-0006MX-FT; Fri, 28 Oct 2016 03:09:26 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bzxXp-0006Ly-TO for xen-devel@lists.xen.org; Fri, 28 Oct 2016 03:09:26 +0000 Received: from [85.158.143.35] by server-3.bemta-6.messagelabs.com id 77/E9-18083-561C2185; Fri, 28 Oct 2016 03:09:25 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrPLMWRWlGSWpSXmKPExsVywNwkQjfloFC Ewe3D+hZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8bZhatZCh6KVex/u4S1gfG8UBcjJ4eQQKXE rpfb2EBsCQFeiSPLZrBC2AESsy5eYeli5AKq6WOUWPGikR0kwSagKHHw4iGwIhEBaYlrny8zg hQxCyxglGi8eJQZJCEsoC2x+swksCIWAVWJji3zwTbwCjhINB14zQixQU5iw+7/YDangKPEz0 N3GCEucpCYs+MV6wRG3gWMDKsYNYpTi8pSi3SNDPWSijLTM0pyEzNzdA0NzPRyU4uLE9NTcxK TivWS83M3MQIDggEIdjD+WRZwiFGSg0lJlPfCZKEIIb6k/JTKjMTijPii0pzU4kOMMhwcShK8 T/YD5QSLUtNTK9Iyc4ChCZOW4OBREuHdvg8ozVtckJhbnJkOkTrFqCglzjvvAFBCACSRUZoH1 waLh0uMslLCvIxAhwjxFKQW5WaWoMq/YhTnYFQS5l0LMoUnM68EbvoroMVMQIunpwuALC5JRE hJNTBK/RPYavrueMaPS1PyJxmHPqxJNyu9rGfO9vTZvpOfqvNP8J/rEutfd1B+aSmjr/Rapt4 FbDM+L12yyC+H4aGgrc/f8Lt7qxjrSh0qF6XI1/s8kj/wznnuveO9n7+6HGX6sHC6UX9uiVDs cuN3MzUsls98KHQ/6c3d5TaM08Vvnt++vqbSKXyuEktxRqKhFnNRcSIAlJkmToICAAA= X-Env-Sender: feng.wu@intel.com X-Msg-Ref: server-8.tower-21.messagelabs.com!1477624162!40309673!1 X-Originating-IP: [192.55.52.88] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTkyLjU1LjUyLjg4ID0+IDM3NDcyNQ==\n X-StarScan-Received: X-StarScan-Version: 9.0.13; banners=-,-,- X-VirusChecked: Checked Received: (qmail 55814 invoked from network); 28 Oct 2016 03:09:24 -0000 Received: from mga01.intel.com (HELO mga01.intel.com) (192.55.52.88) by server-8.tower-21.messagelabs.com with DHE-RSA-CAMELLIA256-SHA encrypted SMTP; 28 Oct 2016 03:09:24 -0000 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP; 27 Oct 2016 20:09:24 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.31,407,1473145200"; d="scan'208"; a="1077010870" Received: from unknown (HELO feng-bdw-de-pi.bj.intel.com) ([10.238.154.53]) by fmsmga002.fm.intel.com with ESMTP; 27 Oct 2016 20:09:22 -0700 From: Feng Wu To: xen-devel@lists.xen.org Date: Fri, 28 Oct 2016 10:37:38 +0800 Message-Id: <1477622259-3476-7-git-send-email-feng.wu@intel.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1477622259-3476-1-git-send-email-feng.wu@intel.com> References: <1477622259-3476-1-git-send-email-feng.wu@intel.com> Cc: kevin.tian@intel.com, Feng Wu , george.dunlap@eu.citrix.com, andrew.cooper3@citrix.com, dario.faggioli@citrix.com, jbeulich@suse.com Subject: [Xen-devel] [PATCH v6 6/7] VT-d: Some cleanups 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 Use type-safe structure assignment instead of memcpy() Use sizeof(*iremap_entry). Besides that, this patch also handle another cleanup, in msi_msg_to_remap_entry() we don't need to copy all the content of old IRTE to the new IRE, we only need to save the 'IM' field to 'new_ire' if the entry is present. Signed-off-by: Feng Wu --- v6: - More descripion about the patch xen/drivers/passthrough/vtd/intremap.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/xen/drivers/passthrough/vtd/intremap.c b/xen/drivers/passthrough/vtd/intremap.c index 97e80a6..39dcb3a 100644 --- a/xen/drivers/passthrough/vtd/intremap.c +++ b/xen/drivers/passthrough/vtd/intremap.c @@ -183,8 +183,8 @@ static void free_remap_entry(struct iommu *iommu, int index) GET_IREMAP_ENTRY(ir_ctrl->iremap_maddr, index, iremap_entries, iremap_entry); - memset(iremap_entry, 0, sizeof(struct iremap_entry)); - iommu_flush_cache_entry(iremap_entry, sizeof(struct iremap_entry)); + memset(iremap_entry, 0, sizeof(*iremap_entry)); + iommu_flush_cache_entry(iremap_entry, sizeof(*iremap_entry)); iommu_flush_iec_index(iommu, 0, index); unmap_vtd_domain_page(iremap_entries); @@ -310,7 +310,7 @@ static int ioapic_rte_to_remap_entry(struct iommu *iommu, GET_IREMAP_ENTRY(ir_ctrl->iremap_maddr, index, iremap_entries, iremap_entry); - memcpy(&new_ire, iremap_entry, sizeof(struct iremap_entry)); + new_ire = *iremap_entry; if ( rte_upper ) { @@ -353,8 +353,8 @@ static int ioapic_rte_to_remap_entry(struct iommu *iommu, remap_rte->format = 1; /* indicate remap format */ } - memcpy(iremap_entry, &new_ire, sizeof(struct iremap_entry)); - iommu_flush_cache_entry(iremap_entry, sizeof(struct iremap_entry)); + *iremap_entry = new_ire; + iommu_flush_cache_entry(iremap_entry, sizeof(*iremap_entry)); iommu_flush_iec_index(iommu, 0, index); unmap_vtd_domain_page(iremap_entries); @@ -643,7 +643,8 @@ static int msi_msg_to_remap_entry( GET_IREMAP_ENTRY(ir_ctrl->iremap_maddr, index, iremap_entries, iremap_entry); - memcpy(&new_ire, iremap_entry, sizeof(struct iremap_entry)); + if ( iremap_entry->remap.p ) + new_ire.remap.im = iremap_entry->remap.im; /* Set interrupt remapping table entry */ new_ire.remap.fpd = 0; @@ -691,8 +692,8 @@ static int msi_msg_to_remap_entry( new_ire.remap.p && !new_ire.remap.im ) pi_get_new_irte(&new_ire, iremap_entry); - memcpy(iremap_entry, &new_ire, sizeof(struct iremap_entry)); - iommu_flush_cache_entry(iremap_entry, sizeof(struct iremap_entry)); + *iremap_entry = new_ire; + iommu_flush_cache_entry(iremap_entry, sizeof(*iremap_entry)); iommu_flush_iec_index(iommu, 0, index); }