Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp4950408imm; Fri, 18 May 2018 13:35:58 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpnHe9Moy8tUEyN8oa58DTrm7D30qK++qQzSay7eNM4xTfu9zJmYI860bBc6XgXpFrvjeNp X-Received: by 2002:a62:b909:: with SMTP id z9-v6mr10842853pfe.254.1526675758782; Fri, 18 May 2018 13:35:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526675758; cv=none; d=google.com; s=arc-20160816; b=iywv1tt/2Ikd7ve1s+v9g2NA7o7UTRvVCMGOrD6wStrUnjSh9Fv4W/5EuWxrMqWCLK naMctEiXDW/vnMMw2zOdWinpZueCJppMfEEgMzBPO5HWxVVnKoxA9zdxaKqxA86ckwPK MkFYt6wh8KbDHnZUkyEnc4TKk+RheYnixOyBY8v38KsrwRsv/e0XkJuHnO/Q+Mz+vN/M yqAjhbwoUBhlfLlVo6uWj274tFiv4M3EBjLMviY6IiSlCNs3yxRFRu6wtXk9GFxzvlA3 xs3f4Y5PcJt+zFSW8IBmWBKOgGSVjQ18eXCqvSZN4vuSseeqEOSknxKSTthlY6Dn+mLz CHYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=VzDEENoeGwcEvcfU+j0TaVz1sJDdhssKTZEnq702hIU=; b=fc+zQ5YMnXaDoFQePkICfBRSp/FjLlAxzb/L9u/S/UJZH8cBVLRcTg7TL/bV9z6LZ4 anlVu5ZSWF6PgUsJ2N4HPRledgPOkTR2bMunIOMbOhbY54i/jqFKtE32ELFEGq3RdLvO HgIhbL/QcmyYpKV8A8wZ5vBYFLjvP3HOr2KmEZKxVVLnEjAgis8XyeOB6aP3y/oN79BW NXAQNqOz7JD+13EBk821P1O5Eoaerc0lJSpKSTu0S4uznrWtq4ied9+nVFvdqL4yJl7V 2Sz0hr0ebGwMYDonf8TqK6XfoNeKYSd+c1nLomOAtumPiDhkXBSwlIQxclXNafXEUviM 2f/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@synopsys.com header.s=mail header.b=mJfGEZ5x; 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=pass (p=NONE sp=NONE dis=NONE) header.from=synopsys.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a35-v6si8191857pli.85.2018.05.18.13.35.44; Fri, 18 May 2018 13:35:58 -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=pass header.i=@synopsys.com header.s=mail header.b=mJfGEZ5x; 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=pass (p=NONE sp=NONE dis=NONE) header.from=synopsys.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752259AbeERUfa (ORCPT + 99 others); Fri, 18 May 2018 16:35:30 -0400 Received: from smtprelay6.synopsys.com ([198.182.37.59]:59177 "EHLO smtprelay.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751952AbeERUfY (ORCPT ); Fri, 18 May 2018 16:35:24 -0400 Received: from mailhost.synopsys.com (mailhost2.synopsys.com [10.13.184.66]) by smtprelay.synopsys.com (Postfix) with ESMTP id 3A9C91E04F9; Fri, 18 May 2018 22:35:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1526675722; bh=5SnhL9L4n8QDv3+McUU1T64AirRaFEc+JXOHSTXPBno=; h=Subject:To:CC:References:From:Date:In-Reply-To:From; b=mJfGEZ5xP58/cakcVnbVlM7BrNMA9GzpanRiAuH6uaFRkk8MDGoy3pdMLVMAaFBnb qEiUt+GQrk9lU2KP+JJCbwY6bcqGY4zz2xP624MpDvlU2MB9YBVcEzw0insHKP28Sf D9VtwQetDlPsCIGsA0i10D6ME32AL3sFiMDtOGbbIPqw4UM9UgB79FO1ihBNVpW5DS dndarr6oz8Llb+iBQrWxyqMTBd8toA9AskoRWh+QF0c4n78d8fCLwT+oPo44xDsdDI YLFR/vBzI0MEWYdGkvUPikC2gMdSgiBbf0yUkOTtEMv3FuQ6tWbcwSFH/5rTfwM7hx FyipUOc+qgPCQ== Received: from US01WEHTC2.internal.synopsys.com (us01wehtc2.internal.synopsys.com [10.12.239.237]) by mailhost.synopsys.com (Postfix) with ESMTP id 4C3DB3DCC; Fri, 18 May 2018 13:35:21 -0700 (PDT) Received: from IN01WEHTCB.internal.synopsys.com (10.144.199.106) by US01WEHTC2.internal.synopsys.com (10.12.239.237) with Microsoft SMTP Server (TLS) id 14.3.361.1; Fri, 18 May 2018 13:35:21 -0700 Received: from IN01WEHTCA.internal.synopsys.com (10.144.199.103) by IN01WEHTCB.internal.synopsys.com (10.144.199.105) with Microsoft SMTP Server (TLS) id 14.3.361.1; Sat, 19 May 2018 02:05:18 +0530 Received: from [10.10.161.52] (10.10.161.52) by IN01WEHTCA.internal.synopsys.com (10.144.199.243) with Microsoft SMTP Server (TLS) id 14.3.361.1; Sat, 19 May 2018 02:05:18 +0530 Subject: Re: dma_sync_*_for_cpu and direction=TO_DEVICE (was Re: [PATCH 02/20] dma-mapping: provide a generic dma-noncoherent implementation) To: Russell King - ARM Linux 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" References: <20180511075945.16548-1-hch@lst.de> <20180511075945.16548-3-hch@lst.de> <5ac5b1e3-9b96-9c7c-4dfe-f65be45ec179@synopsys.com> <20180518175004.GF17671@n2100.armlinux.org.uk> From: Vineet Gupta Message-ID: Date: Fri, 18 May 2018 13:35:08 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <20180518175004.GF17671@n2100.armlinux.org.uk> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Originating-IP: [10.10.161.52] Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 05/18/2018 10:50 AM, Russell King - ARM Linux wrote: > 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) As an aside, do these imply a state machine of sorts - does a driver needs to always call map_single first ? My original point of contention/confusion is the specific combinations of API and direction, specifically for_cpu(TO_DEV) and for_device(TO_CPU) Semantically what does dma_sync_single_for_cpu(TO_DEV) even imply for a non dma coherent arch. Your tables below have "none" for both, implying it is unlikely to be a real combination (for ARM and ARC atleast). The other case, actually @dir TO_CPU, independent of for_{cpu, device}  implies driver intends to touch it after the call, so it would invalidate any stray lines, unconditionally (and not just for speculative prefetch case). > 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. Can you please explain in some more detail, TO_CPU row, why invalidate is conditional sometimes.