Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1211909imu; Wed, 28 Nov 2018 06:20:55 -0800 (PST) X-Google-Smtp-Source: AFSGD/UAqIrMWEQbHXU2ok6BVGnZUo5Ohqkj9BOBh0wGiXNKk/GHwMHB3XqD9IrlP16DEk1FK1fo X-Received: by 2002:a62:6e07:: with SMTP id j7mr21369613pfc.135.1543414855550; Wed, 28 Nov 2018 06:20:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543414855; cv=none; d=google.com; s=arc-20160816; b=xRqsEGEQDZgsDCKhIGxliSOvg9niAPyn2AipAD7M0k2ErJtioTY9s1s/maI4g1uVuv rKF2qi6VEGI94T5odd6JqOz/XVAXYhvM9WLfNzP5kBFgg6e7B6Q07F1dADxOumlFJ7aB GnqcOTL65fwXck/aF1ItOUL0VRHv3rseXO7d1edEOgWD4pivDYHsN9qlHmcyskwnSwbZ 4XkQV6PPzt5tngfkFM0NGxpAhZwaM2av2ikNYOk5aFmBdIY+SbGLt+7dJ18/fKEmOjcT RswtjgLcnZ9VFAlnrNOUFhzhSMjy275hVaS04i+UtXUdRgBPqdgDTAd+gHxLzkqOgLDF Z0Hg== 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; bh=Vcavd8QXp54dGaJnj7jhGh0bcCpKEektAHPyUXgJ9DY=; b=ekS9gMBR7SZMbfUBIBlP/QhiG2WTdFwST5In+g3B1forMlYoYQcPToAWfQAr+rZRP6 SlCT9BWjznskBagYa40Wwmax4dcq7tugEJP5x/hv9Z7LWERLQK2sXMHQbHYuVTHGg2k4 22udxmuxMTSJXZRs+O5IGDSRBVya/NKeiP+NbTL1HAXdM2GqAMPAzsZFEhFtnb6+HLYM WdASsJKE6/wf35fedn2+5+RDDU3a0waAaG1+MskW7V+izUh6Vvicc41CeNh/zuAVWPsd gWW0tcaTIFcxOfekdQ4qbAMR2gETXi8VI/EQNoN3fXxPdfp5zi78JLzjP/UPEhQ8NRME VScQ== 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 191si7484476pgd.228.2018.11.28.06.20.36; Wed, 28 Nov 2018 06:20:55 -0800 (PST) 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 S1728163AbeK2BVl (ORCPT + 99 others); Wed, 28 Nov 2018 20:21:41 -0500 Received: from bmailout2.hostsharing.net ([83.223.90.240]:37219 "EHLO bmailout2.hostsharing.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727832AbeK2BVl (ORCPT ); Wed, 28 Nov 2018 20:21:41 -0500 Received: from h08.hostsharing.net (h08.hostsharing.net [83.223.95.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "*.hostsharing.net", Issuer "COMODO RSA Domain Validation Secure Server CA" (not verified)) by bmailout2.hostsharing.net (Postfix) with ESMTPS id 5467D2800B1D3; Wed, 28 Nov 2018 15:19:50 +0100 (CET) Received: by h08.hostsharing.net (Postfix, from userid 100393) id F30C3140749; Wed, 28 Nov 2018 15:19:49 +0100 (CET) Date: Wed, 28 Nov 2018 15:19:49 +0100 From: Lukas Wunner To: Christoph Hellwig Cc: Vivek Gautam , airlied@linux.ie, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, tfiga@chromium.org, Sean Paul , freedreno@lists.freedesktop.org Subject: Re: [PATCH v2 1/1] drm: msm: Replace dma_map_sg with dma_sync_sg* Message-ID: <20181128141949.6mww6g2ze3qkzxhj@wunner.de> References: <20181126213710.3084-1-vivek.gautam@codeaurora.org> <20181128073940.GA13072@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181128073940.GA13072@infradead.org> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 27, 2018 at 11:39:40PM -0800, Christoph Hellwig wrote: > > + /* > > + * dma_sync_sg_*() flush the physical pages, so point > > + * sg->dma_address to the physical ones for the right behavior. > > + */ > > + for_each_sg(msm_obj->sgt->sgl, s, msm_obj->sgt->nents, i) > > + sg_dma_address(s) = sg_phys(s); > > + > > I'm sorry, but this is completely bogus and not acceptable. > > The only place that is allowed to initialize sg_dma_address is > dma_map_sg. If the default dma ops don't work for your setup we have > major a problem and need to fix the dma api / iommu integration instead > of hacking around it. Somewhat related, I recently submitted a patch for the spi-bcm2835.c driver to overcome a limitation of the DMA engine and the spi0 master on the Raspberry Pi: http://lists.infradead.org/pipermail/linux-rpi-kernel/2018-November/008275.html If a buffer needs to be sent or received which was vmalloc'ed (hence is not contiguous in physical memory) and starts in the middle of a page with an offset not a multiple of 4, the buffer could not be transmitted with DMA so far because the spi0 master requires 4 byte writes to the FIFO and the DMA engine is incapable of combining multiple sglist entries of arbitrary length into a continuous stream of 4 byte chunks. The solution I've found is to transfer the first few bytes of the first sglist entry with programmed I/O such that the remainder has a length which is a multiple of 4. For this to work, I have to massage the first sglist entry, i.e. I have to add the number of bytes transmitted with PIO to the DMA address and subtract it from the sglist entry's length. After the DMA engine has done its job, I undo those changes to the sglist. Could you comment on the acceptibility of this approach? If you do not deem it acceptable, could you make a suggestion how the dma-mapping API shall be amended to support such use cases? (I sure hope the approach *is* acceptable, getting this to work at all required endless fiddling. The BCM2835 is in some ways a not so great SoC and could do with better documentation, to put it mildly.) (Note: I've since amended the above-linked patch to sync only the modified cachelines back to memory, not the full first sglist entry. I've also switched to the sg_dma_address() and sg_dma_len() syntax instead of referencing the sglist entry members directly, this appears to be more common in the tree even for l-values. I was going to post these changes as v2 shortly.) Thanks, Lukas