Received: by 2002:a17:90a:bc8d:0:0:0:0 with SMTP id x13csp1162218pjr; Thu, 21 May 2020 01:22:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyI5p2bDWDGtb9UDn78twxslcwAnIXa0nmIV1T2sKOhHSTMr5iEjqpNgSXEYQVRIlvyE/dj X-Received: by 2002:a50:a985:: with SMTP id n5mr6944043edc.338.1590049379123; Thu, 21 May 2020 01:22:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590049379; cv=none; d=google.com; s=arc-20160816; b=UXF04vIvBy4t7CW3JUYXIVooEhfaevLwG6ufqs5TaMPQ/eJRFp3UiHVL+9gM+oTVLX Wty4Uf2eO6uaO5LT3pIuYaCPSYXYyqe6rM/0j/giWbD4qKG2dLQo7fjortLY/4fnLkLW PUQq74aF072wa+rRFC5Q8mfaRbPrZa12U/GRbdIVsnPtGCNgKF8A8bVPdYOc5Ay8pTUV k3TZp0SMAkwb8f0bqtkX9XJ6BwcHMLvESOe/9/t5nHmsaN4S85AtcAoVnN3SUhNh8ZAk c2UX7DS/84tiB7jkVGDIk0Z/l5ngrWyS5OaYpl8vx4MqpMxZVKGenDrgOOxmTlpPW2a9 Lyvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=eaQg7A9nmVi1QmaGDxLtL8MFACOo/B2TJw/SJawKC+A=; b=TPVGAGty+Mmb9eVuBdByS60xvVQFpwm3yBJCsYlzqn95ZndTinEYN0x3MLJfcmSbnY 8tL4JcWOaPS93fJV8mOZAZsLx1Vr8qixFyPwlTInnX5O0a6ZZV2yHqVJsPGALO4W8IVo j9Gkdw4SOGdfgb88OTMlxObCl7ysRhlUVJZU0Oc2cWgdBwKpAgPmlQHzA7zfhGpJEur/ A9owg2OKAdweD0BKt1bjex3clZUTxVV9iNKodcYPobRIoI9K0oo4bK8CRJXfWdGsNMRq 2f2ZY0YM67gRXcatXGEH2x3i2Qnwx1IlAL5c1cw8YRH7Vu1ffWljsCwB3nKkDETxbGyy t5YQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@xen.org header.s=20200302mail header.b=GUZo9Faz; 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 a17si2619432edj.251.2020.05.21.01.22.36; Thu, 21 May 2020 01:22:59 -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=@xen.org header.s=20200302mail header.b=GUZo9Faz; 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 S1728527AbgEUISj (ORCPT + 99 others); Thu, 21 May 2020 04:18:39 -0400 Received: from mail.xenproject.org ([104.130.215.37]:53938 "EHLO mail.xenproject.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728473AbgEUISj (ORCPT ); Thu, 21 May 2020 04:18:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:Content-Type:In-Reply-To: MIME-Version:Date:Message-ID:From:References:Cc:To:Subject:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=eaQg7A9nmVi1QmaGDxLtL8MFACOo/B2TJw/SJawKC+A=; b=GUZo9FazFxZSxKd+FOJykkk6iR ft986fw1d+t4MM0L17Mc3bMzOa6eTJEFNAZXMNnsRs5LyxArZp9tRwrtrfc6YDYkjko+A+ixiieRj fDJWdmUATQn+Lyi1010A53/Hl1nCmPSj/bPn4V/xMvMXabBtglTgOwrqCOA5ZHynXwFU=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jbgPV-0004ZD-Vs; Thu, 21 May 2020 08:18:37 +0000 Received: from 54-240-197-225.amazon.com ([54.240.197.225] helo=a483e7b01a66.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1jbgPV-0007G4-OR; Thu, 21 May 2020 08:18:37 +0000 Subject: Re: [PATCH 09/10] xen/arm: introduce phys/dma translations in xen_dma_sync_for_* To: Stefano Stabellini , jgross@suse.com, boris.ostrovsky@oracle.com, konrad.wilk@oracle.com Cc: xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, Stefano Stabellini References: <20200520234520.22563-9-sstabellini@kernel.org> From: Julien Grall Message-ID: <83c1120f-fe63-dc54-7b82-15a91c748de8@xen.org> Date: Thu, 21 May 2020 09:18:35 +0100 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: <20200520234520.22563-9-sstabellini@kernel.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 21/05/2020 00:45, Stefano Stabellini wrote: > From: Stefano Stabellini > > Add phys_to_dma/dma_to_phys calls to > xen_dma_sync_for_cpu, xen_dma_sync_for_device, and > xen_arch_need_swiotlb. > > In xen_arch_need_swiotlb, take the opportunity to switch to the simpler > pfn_valid check we use everywhere else. > > dma_cache_maint is fixed by the next patch. Like patch #8, this explains what the code is doing not why this is necessary. > > Signed-off-by: Stefano Stabellini > --- > arch/arm/xen/mm.c | 10 +++++----- > 1 file changed, 5 insertions(+), 5 deletions(-) > > diff --git a/arch/arm/xen/mm.c b/arch/arm/xen/mm.c > index f2414ea40a79..7639251bcc79 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); > @@ -97,8 +98,7 @@ bool xen_arch_need_swiotlb(struct device *dev, > phys_addr_t phys, > 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 > @@ -115,7 +115,7 @@ bool xen_arch_need_swiotlb(struct device *dev, > * require a bounce buffer because the device doesn't support coherent > * memory and we are not able to flush the cache. > */ > - return (!hypercall_cflush && (xen_pfn != bfn) && > + return (!hypercall_cflush && !pfn_valid(bfn) && I believe this change is incorrect. The bfn is a frame based on Xen page granularity (always 4K) while pfn_valid() is expecting a frame based on the Kernel page granularity. > !dev_is_dma_coherent(dev)); > } > > Cheers, -- Julien Grall