Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3818501yba; Tue, 23 Apr 2019 10:07:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqw0IodsiItKwNgcjZ7j9lZ9lJAjbyfso5PjvJt0YcKBs0dzR0oi+Sfn6VN/AptPvx8qKHaC X-Received: by 2002:aa7:82c5:: with SMTP id f5mr27934784pfn.256.1556039244277; Tue, 23 Apr 2019 10:07:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556039244; cv=none; d=google.com; s=arc-20160816; b=j7Ws8yT9qpkwTBSkqNByIPSnW2nRHEr9mQ7QC7620ZVLwupMYS7uDeIJMO++5NUs1L RFTyN20oRZdNUPjFjp77EHajMLhlO6eyVuD0lJl8b/udYA1ofzpd7K/KB8QXXT/URaQx hMBq5fN1Uq1DT5WuaDBsbkt4hGC6KJSDMtNWeusDXWqmxtkQIPkJsxkI7nXfH2mhqVOI aIHIao9wE2kSa1DN1NoPA12dNdkVrRFbmttXqNqNXIoiYgs9QGW2WYmCoKJ9IPe5bSRc qc9xJk/cA8VNIxEqMcvme0IrFH6/GiD6AqUnWulRLXr/Cqs11wgGwcKQ0B/nQ7P9kuDq 6ddg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date:dkim-signature; bh=JDaBNHIZUW4RfT8RGsybZgYCVdEPG19Oh7WqTyUVue4=; b=cz+/l7Qm6dS0wRbNcfB+bk96V5n0GuBApBnKMxDaAGAyoAmZJpbI+4fCT2BhP0Hzom ssnRb8MP3DwzquRsZ/STXLwM1IlZInZeb5jM6o0HHmGP0h2IyJPdDW2gj4fli6KL/8zh BTHstN3LGjlCg0ME4In5VYwh73Ek1mJYxua88We5STdm9tUq/yBvFeqsJ1KpkTDoXWRg vlXWRiPZ9VMJsqGfUJIGVRxbjg/0EFDl926cjis1mEL7XtuspPmPKnYdTXgjYWprjKi7 lPGh7qdQfMU9tsAmCZGdi4KjvvtavF5IoNm1oMrOgdFj9Q0ROmn9xS+kYZ/mFDK4xnPy Id7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=kzTSDLON; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l94si15431621plb.29.2019.04.23.10.07.07; Tue, 23 Apr 2019 10:07:24 -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; dkim=pass header.i=@kernel.org header.s=default header.b=kzTSDLON; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729317AbfDWRGJ (ORCPT + 99 others); Tue, 23 Apr 2019 13:06:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:47478 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727740AbfDWRGI (ORCPT ); Tue, 23 Apr 2019 13:06:08 -0400 Received: from localhost (c-67-164-102-47.hsd1.ca.comcast.net [67.164.102.47]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B075821850; Tue, 23 Apr 2019 17:06:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556039168; bh=i2JIjq6aZqmQv7kstuBZrccA+R9sQNWobjLeh+18V/c=; h=Date:From:To:cc:Subject:In-Reply-To:References:From; b=kzTSDLONeEaMkdNJaBpJTVTxUi+JRdWZL1srIKm1BwEa7hE/v6ODhR8nbhgBcoPV2 D1k5kEj+JoiESav7hOBHHdfBDpl5MVGxwuicWbeF+Db629CAgchY99DQ5GTJJFMwrX j/5/0K6m7DUqpkm5w+odQmi4iMADi08L+czZz7Jo= Date: Tue, 23 Apr 2019 10:05:54 -0700 (PDT) From: Stefano Stabellini X-X-Sender: sstabellini@sstabellini-ThinkPad-X260 To: Juergen Gross cc: xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org, konrad.wilk@oracle.com, boris.ostrovsky@oracle.com, sstabellini@kernel.org Subject: Re: [PATCH 3/3] xen/swiotlb: remember having called xen_create_contiguous_region() In-Reply-To: <20190423105457.17502-4-jgross@suse.com> Message-ID: References: <20190423105457.17502-1-jgross@suse.com> <20190423105457.17502-4-jgross@suse.com> User-Agent: Alpine 2.10 (DEB 1266 2009-07-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 23 Apr 2019, Juergen Gross wrote: > 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. Although the patch looks OK, this sentence puzzles me. Why do you say that the memory in question is owned by swiotlb-xen? Because it was returned by xen_alloc_coherent_pages? Both the x86 and the Arm implementation return fresh new memory, hence, it should be safe to set the PageOwnerPriv1 flag? My concern with this approach is with the semantics of PG_owner_priv_1. Is a page marked with PG_owner_priv_1 only supposed to be used by the owner? > 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); > }