Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3437659yba; Tue, 23 Apr 2019 03:57:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqyGzz8aoAy57DNwqbfIrXXKelvKzxxuVu3jcHMUnDjtRy01g4OkgoTLYAlAlA5xNEIW4SNL X-Received: by 2002:a17:902:b28:: with SMTP id 37mr24890518plq.322.1556017042695; Tue, 23 Apr 2019 03:57:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556017042; cv=none; d=google.com; s=arc-20160816; b=PPqbS2Cx5VTONyTGqOMG3eAbm23FeeSORrglplOXYxMJejqxdTnTitPVcBf9jB1iHw BXBX9NoyExhF91I0d1jymlRp0zcWnqM1J05zMFZ4J7B0TDKn93NRB1AiETGY3yhH+GgZ 0aitDKVaqqktksI5ddm9ak4DQrceGdbClcdg1dPyRK7eWbdzokxxND5NkJQCKpCxJaRg iSUAY+GfMLenmHKeO+5KHHfPnddCxoTtMEAb6KL0fe8xOig76R9DRD57g3Wzb8KuWLqV I+t5uDdmutZLt/WJJ6NgTktwUsS9AmNRuFW6V2IpeiHVRq+QxQdKpyEkuIpIQLdFtLBR 5YAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=OOx+lbRxRwDUxqMHUXI10V2atjDML1c8GCmzTtnzwAo=; b=Bw3BPthnxumvkMIVM/gyeQ8+Xs9q5wE5uYVwlJsigwpmXdZatE0dgkl+2Rg+U0mkbk auZp5l38LVllSU91eHzLHkZt00PdZnzCkRjW9QP5dOV0lUACqWzdJ6V2kQoJULHEftlC poNnhFtJOA6dYtcGkccQ+Xl44h11P7RPNpEArg+0Zp+JiuZ6JQzble2Jf6D2dwM1T1Go ZgpEC+Yzvpt+SZ8XxY4hIHgPJLz4jp3mjQhZd+Jxe2pe4B93HL0sG2jSGUymLAqJBPtb 9D5/TfuiTlRKC1jpUsC8iGogdttxLVqKZ8l37eFQz2PCK7SKengLVjCiTII+hFqQrWds SK/Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p88si15592452pfi.142.2019.04.23.03.57.07; Tue, 23 Apr 2019 03:57:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727426AbfDWKzQ (ORCPT + 99 others); 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