Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp195301ybg; Mon, 8 Jun 2020 20:49:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwZE89K1QEE3JVc1GgipAJHib4kjoaExTRtYCiZh2xlvqKHdJicSwFSExqpDVKg7gTrKCMy X-Received: by 2002:a50:f985:: with SMTP id q5mr2165926edn.180.1591674576704; Mon, 08 Jun 2020 20:49:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591674576; cv=none; d=google.com; s=arc-20160816; b=A6wxIX6kFUW6WjYd4pjqgSIxEiXxvdur7/nLhJw5t4+oPijbYKs+4e5Yrt6wggwiNH 6NncHD3GiEePU3asE2ZJqKj9gC6r/r8lw0dZPIoa110nUvlKO40Hmk49/PhK/pd4J8WK 2TPsVGssceUFG5gEfCWTKBRqhE/utYw4VFMRiGIHwtLfe42C0haWUwf2ffCFQlVATZAg K5+CiOTJQolpHNKgjmUxLeBjYAWzpzSgJjQvUNrgrGvUs4xXGZCALH4g7rjYkFpHcLH4 q0Pp6jvBXD51KRJbBff3oWSOHVq30CAN2oIec3kbj+tP5ZMPTT4BMGZjHBZzhZKAEVwV Hjvw== 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=0bbzZfQR6SmLfuN1cTIB4qwf3g9v7glPEDXIL6zx6EU=; b=E65FV836D0+dqxqeEIbT9daCrgco4+IorEeCPW4ZXVTLnXkFbh1mEVuYe9PnGCK4Md zYhFN+bbplQJIOvd9m/dNsDbgH4fHE1yEdUapPcoDCgkR/sMI6sUZU1vLIcSrlegQVxa gjJuGyjlnynGqvxEWxw6cXKC5D3ASh52bcoIWjnB1POLcExJSYvGCp59s+pBv/gx6l8v 3DMGW4OzS1h0bfKGx91yq36AukaZm6dNmOpJxveAkMTELt8XogfIatui6+ytinUHme5Z U87Ghizd3VsBTWuXwCc0BFqpngNKxj/Yr1sse+IPU5kLBHutpLbmF3HVPo9thoCX08ts SFKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=szvpOm92; 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 s15si9943733ejz.132.2020.06.08.20.49.13; Mon, 08 Jun 2020 20:49:36 -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=szvpOm92; 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 S1727120AbgFIDqr (ORCPT + 99 others); Mon, 8 Jun 2020 23:46:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:33454 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726918AbgFIDqr (ORCPT ); Mon, 8 Jun 2020 23:46:47 -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 290FA20775; Tue, 9 Jun 2020 03:46:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591674406; bh=CLVBI8sBETJZRH84szWPKCZET1iujXSN9tbuwfeKbHg=; h=Date:From:To:cc:Subject:In-Reply-To:References:From; b=szvpOm92h48+ZA24If+05vk6Wfwxi/L131yipzhT9g8mQHN4DH0DTIT7B+iggFhDF X57oYj2xWOE309TL6GGGSydM1y7maSWzRK7sQ/B6AMBiK4FDXcucquhA+GlQKDnfXn 8/07/ySp7LJP2CL1E0l3cM4c8dfuklUuSvf8DBRo= Date: Mon, 8 Jun 2020 20:46:45 -0700 (PDT) From: Stefano Stabellini X-X-Sender: sstabellini@sstabellini-ThinkPad-T480s To: Stefano Stabellini cc: Christoph Hellwig , 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: 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, Stefano Stabellini wrote: > 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. You meant to move the #define from the header to swiotlb-xen.c, didn't you, and to use a cast to u64 instead of phys_addr_t?