From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F2411C282DD for ; Tue, 23 Apr 2019 10:55:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C164C20811 for ; Tue, 23 Apr 2019 10:55:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727592AbfDWKzQ (ORCPT ); Tue, 23 Apr 2019 06:55:16 -0400 Received: from mx2.suse.de ([195.135.220.15]:52968 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726443AbfDWKzC (ORCPT ); Tue, 23 Apr 2019 06:55:02 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id DF68FAE64; Tue, 23 Apr 2019 10:55:01 +0000 (UTC) From: Juergen Gross To: xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org Cc: konrad.wilk@oracle.com, boris.ostrovsky@oracle.com, sstabellini@kernel.org, Juergen Gross Subject: [PATCH 3/3] xen/swiotlb: remember having called xen_create_contiguous_region() Date: Tue, 23 Apr 2019 12:54:57 +0200 Message-Id: <20190423105457.17502-4-jgross@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190423105457.17502-1-jgross@suse.com> References: <20190423105457.17502-1-jgross@suse.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Instead of always calling xen_destroy_contiguous_region() in case the memory is DMA-able for the used device, do so only in case it has been made DMA-able via xen_create_contiguous_region() before. This will avoid a lot of xen_destroy_contiguous_region() calls for 64-bit capable devices. As the memory in question is owned by swiotlb-xen the PG_owner_priv_1 flag of the first allocated page can be used for remembering. Signed-off-by: Juergen Gross --- drivers/xen/swiotlb-xen.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c index 43b6e65ae256..a72f181d8e20 100644 --- a/drivers/xen/swiotlb-xen.c +++ b/drivers/xen/swiotlb-xen.c @@ -321,6 +321,7 @@ xen_swiotlb_alloc_coherent(struct device *hwdev, size_t size, xen_free_coherent_pages(hwdev, size, ret, (dma_addr_t)phys, attrs); return NULL; } + SetPageOwnerPriv1(virt_to_page(ret)); } memset(ret, 0, size); return ret; @@ -344,9 +345,11 @@ xen_swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr, /* Convert the size to actually allocated. */ size = 1UL << (order + XEN_PAGE_SHIFT); - if ((dev_addr + size - 1 <= dma_mask) && - !WARN_ON(range_straddles_page_boundary(phys, size))) - xen_destroy_contiguous_region(phys, order); + if (PageOwnerPriv1(virt_to_page(vaddr))) { + if (!WARN_ON(range_straddles_page_boundary(phys, size))) + xen_destroy_contiguous_region(phys, order); + ClearPageOwnerPriv1(virt_to_page(vaddr)); + } xen_free_coherent_pages(hwdev, size, vaddr, (dma_addr_t)phys, attrs); } -- 2.16.4 From mboxrd@z Thu Jan 1 00:00:00 1970 From: Juergen Gross Subject: [PATCH 3/3] xen/swiotlb: remember having called xen_create_contiguous_region() Date: Tue, 23 Apr 2019 12:54:57 +0200 Message-ID: <20190423105457.17502-4-jgross@suse.com> References: <20190423105457.17502-1-jgross@suse.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <20190423105457.17502-1-jgross-IBi9RG/b67k@public.gmane.org> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: iommu-bounces-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org Errors-To: iommu-bounces-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org To: xen-devel-GuqFBffKawtpuQazS67q72D2FQJk+8+b@public.gmane.org, linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org Cc: Juergen Gross , boris.ostrovsky-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org, sstabellini-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org, konrad.wilk-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org List-Id: iommu@lists.linux-foundation.org Instead of always calling xen_destroy_contiguous_region() in case the memory is DMA-able for the used device, do so only in case it has been made DMA-able via xen_create_contiguous_region() before. This will avoid a lot of xen_destroy_contiguous_region() calls for 64-bit capable devices. As the memory in question is owned by swiotlb-xen the PG_owner_priv_1 flag of the first allocated page can be used for remembering. Signed-off-by: Juergen Gross --- drivers/xen/swiotlb-xen.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c index 43b6e65ae256..a72f181d8e20 100644 --- a/drivers/xen/swiotlb-xen.c +++ b/drivers/xen/swiotlb-xen.c @@ -321,6 +321,7 @@ xen_swiotlb_alloc_coherent(struct device *hwdev, size_t size, xen_free_coherent_pages(hwdev, size, ret, (dma_addr_t)phys, attrs); return NULL; } + SetPageOwnerPriv1(virt_to_page(ret)); } memset(ret, 0, size); return ret; @@ -344,9 +345,11 @@ xen_swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr, /* Convert the size to actually allocated. */ size = 1UL << (order + XEN_PAGE_SHIFT); - if ((dev_addr + size - 1 <= dma_mask) && - !WARN_ON(range_straddles_page_boundary(phys, size))) - xen_destroy_contiguous_region(phys, order); + if (PageOwnerPriv1(virt_to_page(vaddr))) { + if (!WARN_ON(range_straddles_page_boundary(phys, size))) + xen_destroy_contiguous_region(phys, order); + ClearPageOwnerPriv1(virt_to_page(vaddr)); + } xen_free_coherent_pages(hwdev, size, vaddr, (dma_addr_t)phys, attrs); } -- 2.16.4 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BA84CC10F14 for ; Tue, 23 Apr 2019 10:55:14 +0000 (UTC) Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 94E9720811 for ; Tue, 23 Apr 2019 10:55:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 94E9720811 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=iommu-bounces@lists.linux-foundation.org Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id D2335F4A; Tue, 23 Apr 2019 10:55:04 +0000 (UTC) Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id C0434F3B for ; Tue, 23 Apr 2019 10:55:03 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 56B83829 for ; Tue, 23 Apr 2019 10:55:03 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id DF68FAE64; Tue, 23 Apr 2019 10:55:01 +0000 (UTC) From: Juergen Gross To: xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org Subject: [PATCH 3/3] xen/swiotlb: remember having called xen_create_contiguous_region() Date: Tue, 23 Apr 2019 12:54:57 +0200 Message-Id: <20190423105457.17502-4-jgross@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190423105457.17502-1-jgross@suse.com> References: <20190423105457.17502-1-jgross@suse.com> Cc: Juergen Gross , boris.ostrovsky@oracle.com, sstabellini@kernel.org, konrad.wilk@oracle.com X-BeenThere: iommu@lists.linux-foundation.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: Development issues for Linux IOMMU support List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Sender: iommu-bounces@lists.linux-foundation.org Errors-To: iommu-bounces@lists.linux-foundation.org Message-ID: <20190423105457.zRdfMk2ZzHoCq2Yjqx4LT5Ov_cO221QTLUvRPAo5vEw@z> Instead of always calling xen_destroy_contiguous_region() in case the memory is DMA-able for the used device, do so only in case it has been made DMA-able via xen_create_contiguous_region() before. This will avoid a lot of xen_destroy_contiguous_region() calls for 64-bit capable devices. As the memory in question is owned by swiotlb-xen the PG_owner_priv_1 flag of the first allocated page can be used for remembering. Signed-off-by: Juergen Gross --- drivers/xen/swiotlb-xen.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c index 43b6e65ae256..a72f181d8e20 100644 --- a/drivers/xen/swiotlb-xen.c +++ b/drivers/xen/swiotlb-xen.c @@ -321,6 +321,7 @@ xen_swiotlb_alloc_coherent(struct device *hwdev, size_t size, xen_free_coherent_pages(hwdev, size, ret, (dma_addr_t)phys, attrs); return NULL; } + SetPageOwnerPriv1(virt_to_page(ret)); } memset(ret, 0, size); return ret; @@ -344,9 +345,11 @@ xen_swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr, /* Convert the size to actually allocated. */ size = 1UL << (order + XEN_PAGE_SHIFT); - if ((dev_addr + size - 1 <= dma_mask) && - !WARN_ON(range_straddles_page_boundary(phys, size))) - xen_destroy_contiguous_region(phys, order); + if (PageOwnerPriv1(virt_to_page(vaddr))) { + if (!WARN_ON(range_straddles_page_boundary(phys, size))) + xen_destroy_contiguous_region(phys, order); + ClearPageOwnerPriv1(virt_to_page(vaddr)); + } xen_free_coherent_pages(hwdev, size, vaddr, (dma_addr_t)phys, attrs); } -- 2.16.4 _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF030C10F14 for ; Tue, 23 Apr 2019 10:55:20 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 96B0520811 for ; Tue, 23 Apr 2019 10:55:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 96B0520811 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hIt4s-00089Y-IF; Tue, 23 Apr 2019 10:55:06 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hIt4r-00089D-B5 for xen-devel@lists.xenproject.org; Tue, 23 Apr 2019 10:55:05 +0000 X-Inumbo-ID: 3eabcef4-65b6-11e9-a3a6-2f5c97fa70e5 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 3eabcef4-65b6-11e9-a3a6-2f5c97fa70e5; Tue, 23 Apr 2019 10:55:02 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id DF68FAE64; Tue, 23 Apr 2019 10:55:01 +0000 (UTC) From: Juergen Gross To: xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org Date: Tue, 23 Apr 2019 12:54:57 +0200 Message-Id: <20190423105457.17502-4-jgross@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190423105457.17502-1-jgross@suse.com> References: <20190423105457.17502-1-jgross@suse.com> Subject: [Xen-devel] [PATCH 3/3] xen/swiotlb: remember having called xen_create_contiguous_region() X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , boris.ostrovsky@oracle.com, sstabellini@kernel.org, konrad.wilk@oracle.com MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: base64 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" SW5zdGVhZCBvZiBhbHdheXMgY2FsbGluZyB4ZW5fZGVzdHJveV9jb250aWd1b3VzX3JlZ2lvbigp IGluIGNhc2UgdGhlCm1lbW9yeSBpcyBETUEtYWJsZSBmb3IgdGhlIHVzZWQgZGV2aWNlLCBkbyBz byBvbmx5IGluIGNhc2UgaXQgaGFzIGJlZW4KbWFkZSBETUEtYWJsZSB2aWEgeGVuX2NyZWF0ZV9j b250aWd1b3VzX3JlZ2lvbigpIGJlZm9yZS4KClRoaXMgd2lsbCBhdm9pZCBhIGxvdCBvZiB4ZW5f ZGVzdHJveV9jb250aWd1b3VzX3JlZ2lvbigpIGNhbGxzIGZvcgo2NC1iaXQgY2FwYWJsZSBkZXZp Y2VzLgoKQXMgdGhlIG1lbW9yeSBpbiBxdWVzdGlvbiBpcyBvd25lZCBieSBzd2lvdGxiLXhlbiB0 aGUgUEdfb3duZXJfcHJpdl8xCmZsYWcgb2YgdGhlIGZpcnN0IGFsbG9jYXRlZCBwYWdlIGNhbiBi ZSB1c2VkIGZvciByZW1lbWJlcmluZy4KClNpZ25lZC1vZmYtYnk6IEp1ZXJnZW4gR3Jvc3MgPGpn cm9zc0BzdXNlLmNvbT4KLS0tCiBkcml2ZXJzL3hlbi9zd2lvdGxiLXhlbi5jIHwgOSArKysrKyst LS0KIDEgZmlsZSBjaGFuZ2VkLCA2IGluc2VydGlvbnMoKyksIDMgZGVsZXRpb25zKC0pCgpkaWZm IC0tZ2l0IGEvZHJpdmVycy94ZW4vc3dpb3RsYi14ZW4uYyBiL2RyaXZlcnMveGVuL3N3aW90bGIt eGVuLmMK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