Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp4163907ybg; Mon, 8 Jun 2020 00:13:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxPF7YvMgadAmd3oKw6mcxfqQCutm4cIQagZe64NMmM6fZrKoxP7ZzaqBIOZ9oXfeTzdrpe X-Received: by 2002:a50:fe07:: with SMTP id f7mr21274929edt.315.1591600400608; Mon, 08 Jun 2020 00:13:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591600400; cv=none; d=google.com; s=arc-20160816; b=YWrWEB69gaOn3xmdF3AQjx+itE8oAzKq7WUO3UGq5c1lKW3AoHrk1fPHnbFzJYjHwi K2NAyrVqU+B8UyHtgw58Qn6O6L3oEeMN4wNqunf9ESdxdO/HnOY+EG/RYm+GMraBKUHw mrN0zcV2M3LtEGN3jiAQO9LCfxJckDEc7rXg5AwBajRmDBu40jQV9bZm3eEPASmgWfK+ tYrX4TKfsxeto6uMnxdadwUBd3kgKtmZz7wrlE6yZpinvKytS+Rgm5/eQyUrg/Jq3MkH GUEIGQ9MSywWkVGPuPJLHwcJ9HKVtP1xm1POgpj5C0sPixHmd8C6yk5JnNO/hrdfD7Xr uPUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=GNcfAufzhmcZvITdjn5d4FK3irCQ3OWSgr/t5h/uSsM=; b=iW3BDtR+7E+kLhBCAjC5OacEUwObL9num3qd5oPro2g6qkUojMaTQ8rHOW+HenNTM1 2XywOWrcOOWicteVagSYl4kDXmLgcZ8mYsDC1YVDo0ZcOWUzKyAU01qx2aptSPF68Jgv ads069ToHSrYJ2tgRh2cHE1zcIqLG6vGgnGzmct4QLOjw5P8CdyJQnjWhC5ZoKnYOZ29 1MIrXBw9ag3J3Gr3Y9sLBrzchG62FZYNnz2SUXu+a4ZDFEgJoz6KJ14WQ39Ln7Iz+i2e oWgS43EqRYBxv/0KwBLFK7bXOied5mAr9i8KKSZlBa82n0Q28wWi5s3DB4zSc9qWTeXQ 7GDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=J02Cvmxj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id md20si824266ejb.203.2020.06.08.00.12.58; Mon, 08 Jun 2020 00:13:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=J02Cvmxj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728992AbgFHHIx (ORCPT + 99 others); Mon, 8 Jun 2020 03:08:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728053AbgFHHIx (ORCPT ); Mon, 8 Jun 2020 03:08:53 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 257A4C08C5C3 for ; Mon, 8 Jun 2020 00:08:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=GNcfAufzhmcZvITdjn5d4FK3irCQ3OWSgr/t5h/uSsM=; b=J02CvmxjrAcCbEc9Whcw7Qcvop VGY6Kx1ZJ43S5swYCuSo6bi3FcOwvKtkrC6CKxzaYQh41SWGb3hv0VaveFZyta/wB/6YAU7BrXBq5 B2egWBkq1tEH2dD7ZEULwRZ1nEDgwLv4tYTcyXuT859vDNGAXGCG3yYzoSGFFgu+bqlCB76t5tGnz BHbVcDrQUYrQ0n7rk2/3eIOzABLOenvBfBj7aKcNyzpfnmKddPQx2KKNEKfeP2zPYJsTuwQNHqAUM PlO8owPfU5BhcG6lNO519+O06CuPdLOAv8AntxWaunTGGsIaewGh3wx7SeMCSuUQjci9l8r5qiOyO Vo8h0lvw==; Received: from hch by bombadil.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1jiBtq-0003QO-AY; Mon, 08 Jun 2020 07:08:50 +0000 Date: Mon, 8 Jun 2020 00:08:50 -0700 From: Christoph Hellwig To: Stefano Stabellini Cc: jgross@suse.com, boris.ostrovsky@oracle.com, konrad.wilk@oracle.com, xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, tamas@tklengyel.com, roman@zededa.com, Stefano Stabellini Subject: Re: [PATCH v2 08/11] swiotlb-xen: introduce phys_to_dma/dma_to_phys translations Message-ID: <20200608070850.GD15742@infradead.org> References: <20200603222247.11681-8-sstabellini@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200603222247.11681-8-sstabellini@kernel.org> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 03, 2020 at 03:22:44PM -0700, Stefano Stabellini wrote: > From: Stefano Stabellini > > With some devices physical addresses are different than dma addresses. > To be able to deal with these cases, we need to call phys_to_dma on > physical addresses (including machine addresses in Xen terminology) > before returning them from xen_swiotlb_alloc_coherent and > xen_swiotlb_map_page. > > We also need to convert dma addresses back to physical addresses using > dma_to_phys in xen_swiotlb_free_coherent and xen_swiotlb_unmap_page if > we want to do any operations on them. > > Call dma_to_phys in is_xen_swiotlb_buffer. > Call phys_to_dma in xen_phys_to_bus. > Call dma_to_phys in xen_bus_to_phys. > > Everything is taken care of by these changes except for > xen_swiotlb_alloc_coherent and xen_swiotlb_free_coherent, which need a > few explicit phys_to_dma/dma_to_phys calls. > > Signed-off-by: Stefano Stabellini > Tested-by: Corey Minyard > Tested-by: Roman Shaposhnik > --- > Changes in v2: > - improve commit message > --- > drivers/xen/swiotlb-xen.c | 22 ++++++++++++---------- > 1 file changed, 12 insertions(+), 10 deletions(-) > > diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c > index 0a6cb67f0fc4..60ef07440905 100644 > --- a/drivers/xen/swiotlb-xen.c > +++ b/drivers/xen/swiotlb-xen.c > @@ -64,16 +64,16 @@ static inline dma_addr_t xen_phys_to_bus(struct device *dev, phys_addr_t paddr) > > dma |= paddr & ~XEN_PAGE_MASK; > > - return dma; > + return phys_to_dma(dev, dma); So looking at this function: The dma name for something passed to phys_to_dma is really weird. The fact that the comments says don't use XEN_PFN_PHYS beause of the type mismatch while nothing but swiotlb-xen is the only user of XEN_PFN_PHYS is also weird. I think XEN_PFN_PHYS needs to move to swiotlb-xen first, then use a hardcoded u64 for the size, and the split the function into a phys_to_xen_phys (or so) function where the result gets passed to phys_to_dma. Similar for the reverse direction.