Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp103552ybg; Mon, 8 Jun 2020 17:40:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxKIUHDSu9dahfuVPRStNZNyzZyiQUIUAEwungtMuysVwt2uWT4jTkMp06PBWajE1qPF8EN X-Received: by 2002:a17:906:8595:: with SMTP id v21mr22476887ejx.30.1591663239111; Mon, 08 Jun 2020 17:40:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591663239; cv=none; d=google.com; s=arc-20160816; b=PZa60VDcQx8yWUp/h0qW8GYNNchN4W7lGkOWzfozjzDM8Gzbets7NwJWWs/TkG5LZN 7YhgQGmZ5W34f0233P4ZXuRJs4zaY6txrtWCSEXcT49FQohQieZHmByM20pvQ0H1oBg8 2s+qto6UaUcwS5KDZpi2b3qWHw+fr511Fr4XTSpZOuWS1bEevTARmFuf041yRJPNtodx +/h5h/acMEztcLGr5bJdglQAaETbbCHpfS6W/9FolK6t0zDh6N+kyGQBfYxYeFvghpOU AXWU+X12o6U4ZhNBSMIvxrhPH9Yu7hG6eC8PD9H/QNKyU1KjYWNppTBoTdC4AU9TciAC efdA== 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=cGaALQ5vEF33fbEEueOSfqDsxwQhbywHaBMdyvEayB0=; b=OU2nQGQ0XyOxGGexHf4Nc2wbj7roACvrmzqZNmvIxHuSImhY2bLBlJG9lsDOlE2OaD HPETLACy25Uou1jGsckeCQzDi8WdLXDLOobgptcX9yCNhjdgLCNY4RKxI0eJi55PvPKy ID+1fEe8x4JHLYDrM28A0TZs5Q4DhrQ4b44F03DFPlN3lONHjjSDFfaVarLBLtxHvrQh 6HXSczSP5WvCg86X9YNTvZJQUkXyOADCFZQiCXAUGhtNHhee3kzARDN4eY67xHGaog47 L9/TGkRcckBPUwQ5vuzgI/8Cs3AtVkuepwqKwZdu5jDmWdYboPwFUhvgv+1UlZRvWjFj MxfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=zmKl2ZEk; 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 n20si8901416edt.487.2020.06.08.17.40.16; Mon, 08 Jun 2020 17:40:39 -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=zmKl2ZEk; 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 S1732803AbgFIAie (ORCPT + 99 others); Mon, 8 Jun 2020 20:38:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:50214 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728371AbgFIAia (ORCPT ); Mon, 8 Jun 2020 20:38:30 -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 5DF5F207ED; Tue, 9 Jun 2020 00:38:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591663109; bh=dZEsuHc63lSqJBCxvHs+BfEmnrOBWd5r93zBgTcjIfE=; h=Date:From:To:cc:Subject:In-Reply-To:References:From; b=zmKl2ZEkH3EPkdd/jdWO6poHzl1BGkaJeJqk7D8IWfcwf0Oy+viDzCfDk0hL7we2P ZJgWIIVk9+QTjD+rtMZELhnH2B5Qf0fORt1zwpbXbC6xxcsEeq1IDhEyN/iT784RaK kOjRS48WEd1Wq7jjCOild9hhx4Jod2X0IvbE8uII= Date: Mon, 8 Jun 2020 17:38:28 -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 10/11] xen/arm: introduce phys/dma translations in xen_dma_sync_for_* In-Reply-To: <20200608071221.GF15742@infradead.org> Message-ID: References: <20200603222247.11681-10-sstabellini@kernel.org> <20200608071221.GF15742@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:46PM -0700, Stefano Stabellini wrote: > > From: Stefano Stabellini > > > > xen_dma_sync_for_cpu, xen_dma_sync_for_device, xen_arch_need_swiotlb are > > getting called passing dma addresses. On some platforms dma addresses > > could be different from physical addresses. Before doing any operations > > on these addresses we need to convert them back to physical addresses > > using dma_to_phys. > > > > Add dma_to_phys calls to xen_dma_sync_for_cpu, xen_dma_sync_for_device, > > and xen_arch_need_swiotlb. > > > > dma_cache_maint is fixed by the next patch. > > The calling conventions because really weird now because > xen_dma_sync_for_{device,cpu} already get both a phys_addr_t and > a dma_addr_t. > > > > > - if (pfn_valid(PFN_DOWN(handle))) > > + if (pfn_valid(PFN_DOWN(dma_to_phys(dev, handle)))) > > But here we translate the dma address to a phys addr > > > arch_sync_dma_for_cpu(paddr, size, dir); > > While this still uses the passed in paddr. I think the uses of > addresses in this code really needs a major rethink. Yeah, the pfn_valid check is a bit weird by definition because we are using it to understand whether the address belong to us or to another VM. To do the pfn_valid check we need to translate the dma address into something the CPU understands, hence, the dma_to_phys call. Why can't we use the already-provided paddr? Because paddr has been translated twice: 1) from dma to maybe-foreign phys address (could be ours, or another VM) 2) from maybe-foreign address to local (using our local mapping of the foreign page) In fact, it would be clearer if we had all three addresses as parameters of xen_dma_sync_for_cpu: the dma address, the maybe-foreign physical address (we tend to call it xenbus address, baddr), the local physical address. Something like: void xen_dma_sync_for_cpu(struct device *dev, dma_addr_t handle, phys_addr_t baddr, phys_addr_t paddr, size_t size, enum dma_data_direction dir) { if (pfn_valid(baddr)) arch_sync_dma_for_cpu(paddr, size, dir); else if (dir != DMA_TO_DEVICE) dma_cache_maint(dev, handle, size, GNTTAB_CACHE_INVAL); }