From patchwork Tue Feb 7 17:58:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrii Anisov X-Patchwork-Id: 9560787 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 2DFB96047A for ; Tue, 7 Feb 2017 18:00:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2023728415 for ; Tue, 7 Feb 2017 18:00:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 135A12845C; Tue, 7 Feb 2017 18:00:32 +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=-3.6 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID 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 8E06228415 for ; Tue, 7 Feb 2017 18:00:31 +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 1cbA1r-0001Ul-Eg; Tue, 07 Feb 2017 17:58:11 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cbA1q-0001UE-A6 for xen-devel@lists.xenproject.org; Tue, 07 Feb 2017 17:58:10 +0000 Received: from [85.158.143.35] by server-3.bemta-6.messagelabs.com id 38/61-22349-1BA0A985; Tue, 07 Feb 2017 17:58:09 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrKIsWRWlGSWpSXmKPExsXiVRvkoruBa1a EQWeXicX3LZOZHBg9Dn+4whLAGMWamZeUX5HAmvH0jmXBc9GKQ92RDYwPhboYuTiEBGYwSkxo uc8C4rAIvGSRmNv+kg3EkRDoZ5XY82caexcjJ5ATI7G77TgLhF0h8eTLTDYQW0hATWLfoessE PY8Jokvc9JAbDYBXYnrrx4wgdgiAkoS91ZNZgIZyizQxSjxevVusISwgL/Epk2PwAaxCKhKdG /oZAWxeQXcJX5P3cgEsUxO4ua5TmYQm1PAQ2Ll7ResEMvcJf6+/MU0gVFgASPDKkaN4tSistQ iXUMTvaSizPSMktzEzBxdQwMzvdzU4uLE9NScxKRiveT83E2MwMBiAIIdjNc3BhxilORgUhLl Pb17ZoQQX1J+SmVGYnFGfFFpTmrxIUYZDg4lCd43nLMihASLUtNTK9Iyc4AhDpOW4OBREuEtA UnzFhck5hZnpkOkTjEac5y6cfolE8euXZdfMgmx5OXnpUqJ884DKRUAKc0ozYMbBIu9S4yyUs K8jECnCfEUpBblZpagyr9iFOdgVBLm7QKZwpOZVwK37xXQKUxAp2y7Mg3klJJEhJRUA+OyOTs bLjfYy0j3G56rUfG0u+umW7vx0InunHdTfup5T/zYcvZB7XXJzf9uTGvT0ys4lPVxyZeb6+9/ u3A0+LWHd1CMbmjbDqPuTX9+bGc5fPWYDsO3P9+37z3vJsj6rWGJ0+VeEcnOz0XqX8N94mSLH 11X5gsrnF31Omj55oJ5oq6HfwZXi75TYinOSDTUYi4qTgQAnLGXp7gCAAA= X-Env-Sender: andrii.anisov@gmail.com X-Msg-Ref: server-16.tower-21.messagelabs.com!1486490288!52075459!1 X-Originating-IP: [74.125.82.68] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.1.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 40058 invoked from network); 7 Feb 2017 17:58:08 -0000 Received: from mail-wm0-f68.google.com (HELO mail-wm0-f68.google.com) (74.125.82.68) by server-16.tower-21.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 7 Feb 2017 17:58:08 -0000 Received: by mail-wm0-f68.google.com with SMTP id c85so29741941wmi.1 for ; Tue, 07 Feb 2017 09:58:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=erX8IJBHBULEN8azClYVlq8h/kv5xG0klbCy7j9IFMo=; b=KW9NGkcV4FSFcqqt+r5KHGVri869PrRsSkgN9Nyvw6SK0BBcMhnRkHsDYBhUCvy5qu ZjzmxBV2m6YxFprnuG75e2D6xFLJWiJb3lKPmDhdvuUvCFfqMKQNz8fv2kFehtEwWU6r 5m96+1rr+btNSY5c20CInx8FAHxrN4ntMwo0vIQ7bEQC78Sm+elYMQdTeU2qL/Ds3uzW VsBGMFw0R9xzP1VouDgHj/nL2ae7SbXft9D29Yhfwdro66xhZhGZKBuI7CdqtnAf7iHO nP0ELz2Wkf6x9PRfFN3D4qNzxXDMvuW23VIpcQHzTLes0pBBBg6Krq9EIW1Fq8Sv0F/V 6H6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=erX8IJBHBULEN8azClYVlq8h/kv5xG0klbCy7j9IFMo=; b=CDyHSl6j9BdayasPyEHYqWLcTxr/2mANG5tjSzmiqsiJnp45UFPRgEi6ONmm7E35M6 sLCvBOaFF1Yx+IW0elnv4hJ1tGe4cgyURgwPueSbL1T3VldEcwtFsD0AFAfJCp+2f0By lkXo/0ezgVg1UugdGFxfP+v1b9Nr5LDnW+TVFwIUOzT7y2pP95mxjogTWxoDMS/4KgJP uYSozKVQnGkoEb3JMmAA91BNd6LJ/NqssqlUZdj+6p+L+oNUrjL+x4xucIogcmVkdtWZ JGonuVb6sKProIGXqLD2CKCuu+5PEvPbxGfJTmSjAsOoNpRI9+NNaNc95JYgyfoCbgPH pV5w== X-Gm-Message-State: AMke39k+x6km9KtdrGo2Dbo1CgPg8HmMt9RbDTYxgJVvAQGskMo1yAhcS3cPYl1iI0Vihg== X-Received: by 10.28.13.16 with SMTP id 16mr13647971wmn.101.1486490288513; Tue, 07 Feb 2017 09:58:08 -0800 (PST) Received: from aanisov-work.kyiv.epam.com (ll-56.209.223.85.sovam.net.ua. [85.223.209.56]) by smtp.gmail.com with ESMTPSA id z134sm19809549wmc.20.2017.02.07.09.58.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 07 Feb 2017 09:58:08 -0800 (PST) From: Andrii Anisov To: xen-devel@lists.xenproject.org Date: Tue, 7 Feb 2017 19:58:03 +0200 Message-Id: <1486490283-20941-3-git-send-email-andrii.anisov@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1486490283-20941-1-git-send-email-andrii.anisov@gmail.com> References: <1486490283-20941-1-git-send-email-andrii.anisov@gmail.com> Cc: julien.grall@arm.com, sstabellini@kernel.org, andrii_anisov@epam.com, oleksandr.dmytryshyn@globallogic.com Subject: [Xen-devel] [PATCH v4 2/2] swiotlb-xen: implement xen_swiotlb_get_sgtable callback 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: Andrii Anisov Signed-off-by: Andrii Anisov Signed-off-by: Stefano Stabellini --- arch/arm/xen/mm.c | 1 + drivers/xen/swiotlb-xen.c | 28 ++++++++++++++++++++++++++++ include/xen/swiotlb-xen.h | 6 ++++++ 3 files changed, 35 insertions(+) diff --git a/arch/arm/xen/mm.c b/arch/arm/xen/mm.c index cd1684e..76ea48a 100644 --- a/arch/arm/xen/mm.c +++ b/arch/arm/xen/mm.c @@ -199,6 +199,7 @@ static struct dma_map_ops xen_swiotlb_dma_ops = { .dma_supported = xen_swiotlb_dma_supported, .set_dma_mask = xen_swiotlb_set_dma_mask, .mmap = xen_swiotlb_dma_mmap, + .get_sgtable = xen_swiotlb_get_sgtable, }; int __init xen_mm_init(void) diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c index 728d4e0..e8cef1a 100644 --- a/drivers/xen/swiotlb-xen.c +++ b/drivers/xen/swiotlb-xen.c @@ -700,3 +700,31 @@ xen_swiotlb_dma_mmap(struct device *dev, struct vm_area_struct *vma, return dma_common_mmap(dev, vma, cpu_addr, dma_addr, size); } EXPORT_SYMBOL_GPL(xen_swiotlb_dma_mmap); + +/* + * This function should be called with the pages from the current domain only, + * passing pages mapped from other domains would lead to memory corruption. + */ +int +xen_swiotlb_get_sgtable(struct device *dev, struct sg_table *sgt, + void *cpu_addr, dma_addr_t handle, size_t size, + unsigned long attrs) +{ +#if defined(CONFIG_ARM) || defined(CONFIG_ARM64) + if (__generic_dma_ops(dev)->get_sgtable) { +#if 0 + /* + * This check verifies that the page belongs to the current domain and + * is not one mapped from another domain. + * This check is for debug only, and should not go to production build + */ + unsigned long bfn = PHYS_PFN(dma_to_phys(dev, handle)); + BUG_ON (!page_is_ram(bfn)); +#endif + return __generic_dma_ops(dev)->get_sgtable(dev, sgt, cpu_addr, + handle, size, attrs); + } +#endif + return dma_common_get_sgtable(dev, sgt, cpu_addr, handle, size); +} +EXPORT_SYMBOL_GPL(xen_swiotlb_get_sgtable); diff --git a/include/xen/swiotlb-xen.h b/include/xen/swiotlb-xen.h index a315c87..1f6d78f 100644 --- a/include/xen/swiotlb-xen.h +++ b/include/xen/swiotlb-xen.h @@ -2,6 +2,7 @@ #define __LINUX_SWIOTLB_XEN_H #include +#include #include extern int xen_swiotlb_init(int verbose, bool early); @@ -60,4 +61,9 @@ extern int xen_swiotlb_dma_mmap(struct device *dev, struct vm_area_struct *vma, void *cpu_addr, dma_addr_t dma_addr, size_t size, unsigned long attrs); + +extern int +xen_swiotlb_get_sgtable(struct device *dev, struct sg_table *sgt, + void *cpu_addr, dma_addr_t handle, size_t size, + unsigned long attrs); #endif /* __LINUX_SWIOTLB_XEN_H */