Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp859166ybg; Wed, 3 Jun 2020 16:00:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwdM8UzxMmTzH5KPQTCYM9tVRvArdk7X61vTw2ePmfqweQkRUPjvRu2MOJH55Ogt00nQ2KV X-Received: by 2002:a17:907:72ca:: with SMTP id du10mr1439976ejc.78.1591225201937; Wed, 03 Jun 2020 16:00:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591225201; cv=none; d=google.com; s=arc-20160816; b=Q2tTCt8XEgcd0T/3Npk0sL/H6VVKRdNAYJMT92hdZ9TyZ06MCb/FNLfy4XKTkNlxLi N9aVG6Ni6TA21FRje/PmNxxpvFkVJitDl5eYFA4yhryyvT8TqqWgSCjAMZZvLgI59OFW v8IkeOinfg9qem3pg76UpbW1CkU2TW7nsNErySoGxRCnHkPFKb/6VpmVEzNRw0gx80D1 YhJBmEEX7dnNBzmgUYZSUVzliXpsIK/Ae+LrBoTsrfNI4CGiA8xA4KkQeE7pjOS6P40o vklJsfzDxMtckRc3E9V/4AptOvktZ3LWHRtRH+PtRGH6EIp5qG7hPqpIBYtdQLTcXB7R v/mg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=YJdwOxeTjU6IqiR8d7kklSS/47H7sYKTrpLGAqzQYdI=; b=Em47cJPuQRPPa+I+nJIVK+GlhVfm9oCKuD1EmY9QFyXx7Xw1ElzicXp5LAFiPPH866 ijRgLJxZ0IIzNl/73YcD7kvheATlcrajdn+hG9zTlp+EkOKLUfIQft3dlKLR7N1koR6x i+TTctfB2KgVIicPgOWeBgZ//qZ0KqvjxCcXGeddy3vHBnyTPIutvKZ+lTPQY82ihCTo yClI/688G3JKFYHUMl6KR4n+otUo4ZGmkRsAaiTByeEKiZYNW3srpZ+hYhxif9OL9kfe mZIViYtLSfw5ErjdrUYC/5SNXUu3dqGAiZUNdveCJwdEcKGNl4K34zSbUj8ZfOvzEQp1 zDoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=RkQYce7A; 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 a99si547509edf.381.2020.06.03.15.59.39; Wed, 03 Jun 2020 16:00:01 -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=RkQYce7A; 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 S1726939AbgFCWW7 (ORCPT + 99 others); Wed, 3 Jun 2020 18:22:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:56598 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726903AbgFCWWy (ORCPT ); Wed, 3 Jun 2020 18:22:54 -0400 Received: from sstabellini-ThinkPad-T480s.hsd1.ca.comcast.net (c-67-164-102-47.hsd1.ca.comcast.net [67.164.102.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7467820734; Wed, 3 Jun 2020 22:22:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591222973; bh=Hrv3PVcXYaGZU+pmnuCIi7L6rjwMar9STJmksuaPXR4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RkQYce7A5IplQKy36VI3JG/7NujFadE1r+EI0c7RL3uFRJEv69DT3i7TAokkTisYb OkLyN10vvmp1i3ZZTO217L6kktfqJefvAssILhG2e3n3170XdT5olphDHA/tvEY80M ndiCNcRva4MAWM/5xUun6d1LH7Ih6/Zg1XaGuG24= From: Stefano Stabellini To: jgross@suse.com, boris.ostrovsky@oracle.com, konrad.wilk@oracle.com Cc: sstabellini@kernel.org, xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, tamas@tklengyel.com, roman@zededa.com, Stefano Stabellini Subject: [PATCH v2 10/11] xen/arm: introduce phys/dma translations in xen_dma_sync_for_* Date: Wed, 3 Jun 2020 15:22:46 -0700 Message-Id: <20200603222247.11681-10-sstabellini@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Signed-off-by: Stefano Stabellini Tested-by: Corey Minyard Tested-by: Roman Shaposhnik --- Changes in v2: - improve commit message - don't use pfn_valid --- arch/arm/xen/mm.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/arch/arm/xen/mm.c b/arch/arm/xen/mm.c index f2414ea40a79..bbad712a890d 100644 --- a/arch/arm/xen/mm.c +++ b/arch/arm/xen/mm.c @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only #include +#include #include #include #include @@ -75,7 +76,7 @@ void xen_dma_sync_for_cpu(struct device *dev, dma_addr_t handle, phys_addr_t paddr, size_t size, enum dma_data_direction dir) { - if (pfn_valid(PFN_DOWN(handle))) + if (pfn_valid(PFN_DOWN(dma_to_phys(dev, handle)))) arch_sync_dma_for_cpu(paddr, size, dir); else if (dir != DMA_TO_DEVICE) dma_cache_maint(handle, size, GNTTAB_CACHE_INVAL); @@ -85,7 +86,7 @@ void xen_dma_sync_for_device(struct device *dev, dma_addr_t handle, phys_addr_t paddr, size_t size, enum dma_data_direction dir) { - if (pfn_valid(PFN_DOWN(handle))) + if (pfn_valid(PFN_DOWN(dma_to_phys(dev, handle)))) arch_sync_dma_for_device(paddr, size, dir); else if (dir == DMA_FROM_DEVICE) dma_cache_maint(handle, size, GNTTAB_CACHE_INVAL); @@ -98,7 +99,7 @@ bool xen_arch_need_swiotlb(struct device *dev, dma_addr_t dev_addr) { unsigned int xen_pfn = XEN_PFN_DOWN(phys); - unsigned int bfn = XEN_PFN_DOWN(dev_addr); + unsigned int bfn = XEN_PFN_DOWN(dma_to_phys(dev, dev_addr)); /* * The swiotlb buffer should be used if -- 2.17.1