Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp50897ybg; Mon, 8 Jun 2020 16:10:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxhOmJicG6z8qQsBOXK+WLxzDD7zL+vNW33IvkE9G/KxaunQwHXAo1Rhk9XabhzzbN1CXtq X-Received: by 2002:a17:906:17c5:: with SMTP id u5mr22481451eje.275.1591657802758; Mon, 08 Jun 2020 16:10:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591657802; cv=none; d=google.com; s=arc-20160816; b=fgv9NWWUxN4Zyy3kG4GQHSOYXmwpLmN72fxAeARcbQtztti3xOwioSztGG28T4+DTY t9Nw1yUHhLUNDQBndszHDADhcSIjEAxtx+WTPg2cyjk6Tbyo4IE6M+PeQSOaC/KuYY7K Bh5hF61I/F228FUnn9kzS+sjrEz8iss/Wlv4YhxdsIm4vyskyEZKNTLxCefOfEgyOKdL QK36ZlTUr7u7JRQGcdEjDyQsQYFWPixGko0sbw8+DG8SMnrUE1O8yg3nx1RDZQkwAMgm Urm5TYGiiSAZNfDvU7hpBvh2FZ8LytgOaS6+haVYjpeKEEaqEpVQNGIdwT5dLLodege+ fFCg== 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=Nnaog3gDLTnJ++IYs99VVazAJZgqtAnCXS2mlx/tiRA=; b=kTAeHyIBj/nf/LbmhEw9ZBlEvjH1IcHl+noBegePk0XCiQ3YJFYrOQ0HaZ3hrXB3qO /o9og4yaKlSw3XYEOW561r+EAvY8p3etyHiB7Km3d7W8ycqa82IHDwZjB4noDr6vcGID r/ls0wqB7NymFGG8z+wFTJjgChmmXTTwP+eIjVwfiGjuNVyo269oi9Jo+UzGIUi5PkZG PuBWUnqGweYDVddgXSbITGGHpyzwoIcot4qoav4olOpOjxoEkeGOfFeCNy6M9+Kvv4ob N7eoniz4YQXQvK5uerACpfqZ2FDFA2Wcn+KDbnmeOBB+k3J3iqym5Bu7dkAhrh5Jsxl1 klCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=IAKP9+uy; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o18si9593698ejb.193.2020.06.08.16.09.40; Mon, 08 Jun 2020 16:10:02 -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=pass header.i=@kernel.org header.s=default header.b=IAKP9+uy; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727902AbgFHXH1 (ORCPT + 99 others); Mon, 8 Jun 2020 19:07:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:50536 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727119AbgFHXG7 (ORCPT ); Mon, 8 Jun 2020 19:06:59 -0400 Received: from localhost (c-67-164-102-47.hsd1.ca.comcast.net [67.164.102.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6C48520820; Mon, 8 Jun 2020 23:06:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591657618; bh=9kgiWfc80bQ1pFTP10CoDvlD9i3E2sMoZB2p3Vvgd/g=; h=Date:From:To:cc:Subject:In-Reply-To:References:From; b=IAKP9+uyhx+Mw+/ttmtWvmUV5DWr7Hx4rynsr/VlhWY7naVEcoN2oD/N3/5SjrSVB EmHPS5CiBaqDmNLIqVqDyRmUgYL0/hy7nAFMhxlSh1iB+5l18sVCmDe/ECVJA17l06 HJUi2skFlwTFsob6tOCCspquwIIueUlnqfhHl8Bo= Date: Mon, 8 Jun 2020 16:06:57 -0700 (PDT) From: Stefano Stabellini X-X-Sender: sstabellini@sstabellini-ThinkPad-T480s To: Christoph Hellwig cc: Stefano Stabellini , 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 In-Reply-To: <20200608070850.GD15742@infradead.org> Message-ID: References: <20200603222247.11681-8-sstabellini@kernel.org> <20200608070850.GD15742@infradead.org> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) 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 Mon, 8 Jun 2020, Christoph Hellwig wrote: > 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. Yeah, that is true, I am not sure why I chose that confusing name. I'll rename it. > 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. I understand what you are suggesting about having something like: xen_phys_to_dma(...) { phys_addr_t phys = xen_phys_to_bus(dev, paddr) return phys_to_dma(phys); } I thought about it myself. I'll do it. But I don't think I understood the comment about XEN_PFN_PHYS. > Similar for the reverse direction. OK