Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3471172ybi; Fri, 19 Jul 2019 03:51:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqzMO9STs0MvMijOeVXseSOSXmtpIjiu53W9PiWBpCqXj/6AJAyCynmyGPss29kh8WwiBQ5S X-Received: by 2002:a63:6ec6:: with SMTP id j189mr54749237pgc.168.1563533485975; Fri, 19 Jul 2019 03:51:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563533485; cv=none; d=google.com; s=arc-20160816; b=l51L9opO8+PCOgX2RFYdZVvGZTSORENebRqjDiQKyHstVsJPIwJzztdK0S4r18atoA 9X773aiar0LNiosdvxVqnO6ZzgSd0pTMkWhQuP+QKh1An78llhcAYJaPVOje02jJh4kP HCYOmYizbDe0Jj1o+grkV2ZBPwovg313QISzna6N2OGqF6EVpQ2KqxODExNwQIGjH6wr Q1I1hWkpfv1XLqcu6DLUuX2wuIgBKzxivrwF64Xi7YzdlvBOidicaZYLOlWaJsCUQQ2z n3+9R1NCMzqoGbfJEmZZptckIs+3pWtlD+jOctEbU0IDMvNgxZwUcpv17zDAjFCuqJ0f 4ZYw== 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; bh=UjiCZvNWmZCduj/S62pvhT1aWlUCbx4Qk8s2qnWEWu8=; b=blvTOBRYqr+KPfCcDMfgF1f3ZV9t22YjSAfrF/X+85ElMEk5Zmf4tbcdqt6HbWuhUJ a8jo8D4Vagf83vMzHU00cEG9SBTPUcGSAdnVZc4EYYMdnDPee6dtwu61tOrgnNmFX8iM 9M1oi7FdDe4Fv4BsyYY4EFI3tEYrgLSV3enGVDtBrNoQrJa3I9br06uAzPH9fnYd2oqO jzS5uSPMQDYm6zNcyjszZcOMS3+bKnFq8l/+vFM2rwXtVdJLZN5YrJRfX2CVpUIcXKUv Kk0+ZzPcn+qBDOK11xMsgrRb6oA0ZfQQsWZj96C6oYGwHhNXMNpbhKBytXGNNjXrd+5z IeuQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x185si1709270pgb.161.2019.07.19.03.51.10; Fri, 19 Jul 2019 03:51:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727618AbfGSKiT (ORCPT + 99 others); Fri, 19 Jul 2019 06:38:19 -0400 Received: from foss.arm.com ([217.140.110.172]:41702 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725853AbfGSKiT (ORCPT ); Fri, 19 Jul 2019 06:38:19 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3BFB9337; Fri, 19 Jul 2019 03:38:18 -0700 (PDT) Received: from [10.1.197.57] (e110467-lin.cambridge.arm.com [10.1.197.57]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3345C3F59C; Fri, 19 Jul 2019 03:38:17 -0700 (PDT) Subject: Re: [PATCH dma 1/1] dma-direct: correct the physical addr in dma_direct_sync_sg_for_cpu/device To: fugang.duan@nxp.com, hch@lst.de, m.szyprowski@samsung.com Cc: festevam@gmail.com, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, aisheng.dong@nxp.com, Al Farleigh References: <20190719092648.11085-1-fugang.duan@nxp.com> From: Robin Murphy Message-ID: Date: Fri, 19 Jul 2019 11:38:16 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <20190719092648.11085-1-fugang.duan@nxp.com> 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 On 19/07/2019 10:26, fugang.duan@nxp.com wrote: > From: Fugang Duan > > dma_map_sg() may use swiotlb buffer when kernel parameter include > "swiotlb=force" or the dma_addr is out of dev->dma_mask range. After > DMA complete the memory moving from device to memory, then user call > dma_sync_sg_for_cpu() to sync with DMA buffer, and copy the original > virtual buffer to other space. > > So dma_direct_sync_sg_for_cpu() should use swiotlb physical addr, not > the original physical addr from sg_phys(sg). > > dma_direct_sync_sg_for_device() also has the similar issue, correct it. Yikes, that was unfortunate. There aren't too many users of dma_sync_sg*(), but I note that a few of them are in and around v4l2, so this could well explain the video brokenness that Al reported. AFAICS the fix looks appropriate; Reviewed-by: Robin Murphy > Fixes: 55897af63091("dma-direct: merge swiotlb_dma_ops into the dma_direct code") > Signed-off-by: Fugang Duan > --- > kernel/dma/direct.c | 18 +++++++++++------- > 1 file changed, 11 insertions(+), 7 deletions(-) > > diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c > index b90e1ae..0e87f86 100644 > --- a/kernel/dma/direct.c > +++ b/kernel/dma/direct.c > @@ -242,12 +242,14 @@ void dma_direct_sync_sg_for_device(struct device *dev, > int i; > > for_each_sg(sgl, sg, nents, i) { > - if (unlikely(is_swiotlb_buffer(sg_phys(sg)))) > - swiotlb_tbl_sync_single(dev, sg_phys(sg), sg->length, > + phys_addr_t paddr = dma_to_phys(dev, sg_dma_address(sg)); > + > + if (unlikely(is_swiotlb_buffer(paddr))) > + swiotlb_tbl_sync_single(dev, paddr, sg->length, > dir, SYNC_FOR_DEVICE); > > if (!dev_is_dma_coherent(dev)) > - arch_sync_dma_for_device(dev, sg_phys(sg), sg->length, > + arch_sync_dma_for_device(dev, paddr, sg->length, > dir); > } > } > @@ -279,11 +281,13 @@ void dma_direct_sync_sg_for_cpu(struct device *dev, > int i; > > for_each_sg(sgl, sg, nents, i) { > + phys_addr_t paddr = dma_to_phys(dev, sg_dma_address(sg)); > + > if (!dev_is_dma_coherent(dev)) > - arch_sync_dma_for_cpu(dev, sg_phys(sg), sg->length, dir); > - > - if (unlikely(is_swiotlb_buffer(sg_phys(sg)))) > - swiotlb_tbl_sync_single(dev, sg_phys(sg), sg->length, dir, > + arch_sync_dma_for_cpu(dev, paddr, sg->length, dir); > + > + if (unlikely(is_swiotlb_buffer(paddr))) > + swiotlb_tbl_sync_single(dev, paddr, sg->length, dir, > SYNC_FOR_CPU); > } > >