Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933420AbcJLW5G convert rfc822-to-8bit (ORCPT ); Wed, 12 Oct 2016 18:57:06 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:39711 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753843AbcJLW46 (ORCPT ); Wed, 12 Oct 2016 18:56:58 -0400 X-IBM-Helo: d03dlp01.boulder.ibm.com X-IBM-MailFrom: miltonm@us.ibm.com X-IBM-RcptTo: linux-kernel@vger.kernel.org In-Reply-To: Subject: Re: [PATCH v2 01/31] af9005: don't do DMA on stack From: "Milton Miller II" To: Mauro Carvalho Chehab Cc: linux-kernel@vger.kernel.org Date: Wed, 12 Oct 2016 22:56:48 +0000 MIME-Version: 1.0 Sensitivity: Importance: Normal X-Priority: 3 (Normal) References: X-Mailer: IBM iNotes ($HaikuForm 858.2) | IBM Domino Build V851SAAS_09122016_FP8.1 October 04, 2016 X-LLNOutbound: False X-Disclaimed: 23643 X-TNEFEvaluated: 1 Content-Transfer-Encoding: 8BIT Content-Type: text/plain; charset=UTF-8 x-cbid: 16101222-0020-0000-0000-00000A01F378 X-IBM-ISS-SpamDetectors: Score=0.400847; BY=0.120558; FL=0; FP=0; FZ=0; HX=0; KW=0; PH=0; SC=0.400847; ST=0; TS=0; UL=0; ISC= X-IBM-ISS-DetailInfo: BY=3.00005900; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000186; SDB=6.00767561; UDB=6.00367280; UTC=2016-10-12 22:56:48 x-cbparentid: 16101222-3816-0000-0000-000000D03C10 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00005900; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000186; SDB=6.00767561; UDB=6.00367280; IPR=6.00543722; BA=6.00004805; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00012969; XFM=3.00000011; UTC=2016-10-12 22:56:55 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused Message-Id: X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2016-10-12_13:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1609300000 definitions=main-1610120382 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1497 Lines: 33 On Tue, 11 Oct 2016 07:09:16 -0300, Mauro wrote: > struct af9005_device_state { > > u8 sequence; > > int led_state; > > + unsigned char data[256]; > > + struct mutex data_mutex; > > }; This will not work on DMA incoherent architectures. When the data cache is invalidated at the end of the DMA, the stores to the mutex will be thrown away and the system will not be happy as changed to the mutex are lost. The data allocation needs to be a separate kmalloc, as is somewhat obtusely documented around line 226 of DMA-API.txt[1]. A separate kmalloc will be aligned to be in separate cache lines. Excerpt from DMA-API.txt: Warnings: Memory coherency operates at a granularity called the cache line width. In order for memory mapped by this API to operate correctly, the mapped region must begin exactly on a cache line boundary and end exactly on one (to prevent two separately mapped regions from sharing a single cache line). Since the cache line size may not be known at compile time, the API will not enforce this requirement. Therefore, it is recommended that driver writers who don't take special care to determine the cache line size at run time only map virtual regions that begin and end on page boundaries (which are guaranteed also to be cache line boundaries). [1]https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/DMA-API.txt#n226 milton PS: I normally read lkml from various web archives, sorry for loss of threading and cc.