Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp4800167imm; Fri, 18 May 2018 10:51:23 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqJ0Zaf2J1HZqQB/uF8HtWRAgnO/6MP2ErHpYhwlZA1XJPt1Z2pMJiwgkRohDMsWSb/lsXu X-Received: by 2002:a17:902:6b09:: with SMTP id o9-v6mr10755614plk.256.1526665883929; Fri, 18 May 2018 10:51:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526665883; cv=none; d=google.com; s=arc-20160816; b=AyrmAOTuwZyxsesTA4xTkdjkB82KQ9D4KF8A6jBROBWDRhdzvAxMMeQSXzOmRE5YRp a133atO/ZzX3iJckt/SUwUiuQAVqQ7vB0gyOuFLXPj4d2BFpuUlbrHH/+o+ksekYJymC z/NH56MP5wG7/YIj9/1Xvmrfy4Ho+JjOv9nwr582+HAVLAWQkrtcm7rmDlx6ECPV0vOz w44vGOjLViSlYvSBUoQC4cHoMdJY4rP/Ae70ysg0gM5TsjssIZIizzslaKWYRpkJjCfZ ogpmFqj4evoDey5jqWem/bAEc3sT14AxVpCPqYQ5cYKwiGXR2Y/ZRim3Ji+sv9RDP6n6 2ouw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=w26Mcd9/t0aYDyhVFEe2HgthN89vmJWIhOy1q/AaIfU=; b=u7b/4SWZn/ldateF02/dZ3YxO4H5VbqBiBIkWhm0ZoBA0zcfxjR8Obj8tw40vA8Okq QSHzytxzU9xDbSmVFfmfItBwV0+U4ZoCRvQ3l2g71dGmhbYS+1bf4D9qgjOgXYcBzds1 oFXa3FGZ4zTzz5hSXk6Y/iGjBSE7gjF3JHdbp7rZO4Ug4mndw87n6Xicrc69mbYow3eE CHR1AvSj91v11JekzObSGo9okX0BUcOO454eWo98DG2eo4xQ4Nx5srFIpSX1q1/Krg1R J4dBCCdlq9KYnVdyC6a7bj9e4kFRTE+OVv/G16Hr/9V+95uigkmaMkwEtPUoQ8hUrAJg HJ5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@armlinux.org.uk header.s=pandora-2014 header.b=i17r7MKh; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q4-v6si7631842plb.251.2018.05.18.10.51.09; Fri, 18 May 2018 10:51:23 -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; dkim=fail header.i=@armlinux.org.uk header.s=pandora-2014 header.b=i17r7MKh; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752461AbeERRul (ORCPT + 99 others); Fri, 18 May 2018 13:50:41 -0400 Received: from pandora.armlinux.org.uk ([78.32.30.218]:51906 "EHLO pandora.armlinux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752422AbeERRub (ORCPT ); Fri, 18 May 2018 13:50:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2014; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding: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=w26Mcd9/t0aYDyhVFEe2HgthN89vmJWIhOy1q/AaIfU=; b=i17r7MKhB4mxAtM9FMUHnq9HI Snhe4YJo65vbUMqxeUmvws5sKluwAg8y+nYas2aFMeiYFkB/tMNDyGEjLD5B5JkKze9RK2uytEOND BuPtMh9WTv0KugmMGqK/cSSOnTouGqnRrX8KFMoy4C3dk30Yh5IYcDnrYI+a6f6Krgu00=; Received: from n2100.armlinux.org.uk ([2001:4d48:ad52:3201:214:fdff:fe10:4f86]:33580) by pandora.armlinux.org.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.90_1) (envelope-from ) id 1fJjWD-0007iQ-Nw; Fri, 18 May 2018 18:50:17 +0100 Received: from linux by n2100.armlinux.org.uk with local (Exim 4.90_1) (envelope-from ) id 1fJjW6-0007dC-Q3; Fri, 18 May 2018 18:50:11 +0100 Date: Fri, 18 May 2018 18:50:04 +0100 From: Russell King - ARM Linux To: Vineet Gupta Cc: Alexey Brodkin , "hch@lst.de" , "linux-arch@vger.kernel.org" , "linux-xtensa@linux-xtensa.org" , "monstr@monstr.eu" , "deanbo422@gmail.com" , "linux-c6x-dev@linux-c6x.org" , "linux-parisc@vger.kernel.org" , "linux-sh@vger.kernel.org" , "linux-m68k@lists.linux-m68k.org" , "linux-hexagon@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-mm@kvack.org" , "iommu@lists.linux-foundation.org" , "openrisc@lists.librecores.org" , "green.hu@gmail.com" , "linux-alpha@vger.kernel.org" , "sparclinux@vger.kernel.org" , "nios2-dev@lists.rocketboards.org" , Andrew Morton , "linux-snps-arc@lists.infradead.org" , "linux-arm-kernel@lists.infradead.org" Subject: Re: dma_sync_*_for_cpu and direction=TO_DEVICE (was Re: [PATCH 02/20] dma-mapping: provide a generic dma-noncoherent implementation) Message-ID: <20180518175004.GF17671@n2100.armlinux.org.uk> References: <20180511075945.16548-1-hch@lst.de> <20180511075945.16548-3-hch@lst.de> <5ac5b1e3-9b96-9c7c-4dfe-f65be45ec179@synopsys.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5ac5b1e3-9b96-9c7c-4dfe-f65be45ec179@synopsys.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 18, 2018 at 10:20:02AM -0700, Vineet Gupta wrote: > I never understood the need for this direction. And if memory serves me > right, at that time I was seeing twice the amount of cache flushing ! It's necessary. Take a moment to think carefully about this: dma_map_single(, dir) dma_sync_single_for_cpu(, dir) dma_sync_single_for_device(, dir) dma_unmap_single(, dir) In the case of a DMA-incoherent architecture, the operations done at each stage depend on the direction argument: map for_cpu for_device unmap TO_DEV writeback none writeback none TO_CPU invalidate invalidate* invalidate invalidate* BIDIR writeback invalidate writeback invalidate * - only necessary if the CPU speculatively prefetches. The multiple invalidations for the TO_CPU case handles different conditions that can result in data corruption, and for some CPUs, all four are necessary. This is what is implemented for 32-bit ARM, depending on the CPU capabilities, as we have DMA incoherent devices and we have CPUs that speculatively prefetch data, and so may load data into the caches while DMA is in operation. Things get more interesting if the implementation behind the DMA API has to copy data between the buffer supplied to the mapping and some DMA accessible buffer: map for_cpu for_device unmap TO_DEV copy to dma none copy to dma none TO_CPU none copy to cpu none copy to cpu BIDIR copy to dma copy to cpu copy to dma copy to cpu So, in both cases, the value of the direction argument defines what you need to do in each call. -- RMK's Patch system: http://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line in suburbia: sync at 8.8Mbps down 630kbps up According to speedtest.net: 8.21Mbps down 510kbps up