Received: by 10.223.164.202 with SMTP id h10csp1055661wrb; Thu, 9 Nov 2017 20:27:36 -0800 (PST) X-Google-Smtp-Source: ABhQp+Tq9G4tIEJ5mws+TWt/Zh3qDJFeU3H/bQtEyj60CsCr9CuUmmxiOP7+aD2ClIDDcGMtDEMa X-Received: by 10.98.194.16 with SMTP id l16mr2881571pfg.139.1510288056612; Thu, 09 Nov 2017 20:27:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510288056; cv=none; d=google.com; s=arc-20160816; b=laEdDuM9uaTd/ufn2gLXvAc7zFRAXBaI4Pl8Tle+zkr4DvFT2sbDZKsqQapdm/+HPI +cMez5Nr5bqSuo2jO3vvfBxt68MnLtZPxv8Ts14USnHSWdbl4vJMEJD2WLo8I28FOnZe 3aC5WG7IDfNxELdsxMGJZZKg/wLpZNFlbmKxxcjBUzQBaym0AUTKl0cyP9vw5iRSyPIC xH1fOIOeZ8cQDWfgqGlPahKrzu9Q2chE9dB9wt9LqmS2lURbRW3E3Egy9ytm2dtzsqA9 dBaVbs7Negxzk8P5X241SwfzN1Qsnw6sITRKK30+T9dFt/gQbyZpygakwU4p/GMc1RRU KP+Q== 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:mime-version :references:in-reply-to:organization:message-id:date:subject:cc:to :from:dkim-signature:arc-authentication-results; bh=CChK/QU/JWpiL51/YDZUiwxVoaZzZb1qDjl7xPMEqoQ=; b=L2i0GNxQQjVzGspr1FtXnn6Pvw8K3QwLpVUj3VN7AyB8n4H6cCMaGMGSINbZmxSIEo 4X2vnhR8DVseYlYXT/0E6ziGGPsyP/XBxgIVY0506Ka5Q+k8sz8aEtaUK9rbfC0/Flb2 cov0zUaCoiJ5rT0UnHvUhqQRAE2tLvPhllgB3WhjNUWll5r4vnMb8Zx+/N7QxGPDmnou /2k5fO9p4cm8psK0HkcQ4agwYeFvx8HwXiA0Nm2Q4cSWbPWE7OPY+3ElOI9fr2trTWow fhQC6uvf1I1kNv7vxBIEM7iVy+eNlEQAfvgo9MQRRlrjOfOdUQZPR5kqQfuXy6uTJdkX bNTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=SzTuoJHt; 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 n21si8165681plp.211.2017.11.09.20.27.24; Thu, 09 Nov 2017 20:27:36 -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; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=SzTuoJHt; 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 S1755894AbdKJE0u (ORCPT + 83 others); Thu, 9 Nov 2017 23:26:50 -0500 Received: from galahad.ideasonboard.com ([185.26.127.97]:34373 "EHLO galahad.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755232AbdKJE0t (ORCPT ); Thu, 9 Nov 2017 23:26:49 -0500 Received: from avalon.localnet (unknown [49.229.154.219]) by galahad.ideasonboard.com (Postfix) with ESMTPSA id 45E0C2017E; Fri, 10 Nov 2017 05:25:37 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1510287937; bh=ktLOFZQflYQ2jQ2gp8r8ZKjPqXC/FgzNZWORhYNusdY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SzTuoJHtVyIQuBJb8vVRe74Ul1IoR2EnQ4c3imItxiow1N4Z1uTd+C6ll7wUN+WEo Ulws63OHvbq8+JnJhYrCtFx5sFALXngygbfrCcuD6ZTqBNrlPW9wNZ5tGq2tQdrI4Y 0w+9VKlO93tjvMioV15ZjrDsEdji3wyzesazk7nA= From: Laurent Pinchart To: dri-devel@lists.freedesktop.org Cc: Liviu Dudau , Brian Starkey , David Airlie , Liviu Dudau , LKML , Mali DP Maintainers , Daniel Vetter Subject: Re: [PATCH] drm: gem_cma_helper.c: Allow importing of contiguous scatterlists with nents > 1 Date: Fri, 10 Nov 2017 06:26:54 +0200 Message-ID: <2213365.Z1vsgl9bDt@avalon> Organization: Ideas on Board Oy In-Reply-To: <20171101141419.3180-1-Liviu.Dudau@arm.com> References: <20171101141419.3180-1-Liviu.Dudau@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Liviu, Thank you for the patch. On Wednesday, 1 November 2017 16:14:19 EET Liviu Dudau wrote: > drm_gem_cma_prime_import_sg_table() will fail if the number of entries > in the sg_table > 1. However, you can have a device that uses an IOMMU > engine and can map a discontiguous buffer with multiple entries that > have consecutive sg_dma_addresses, effectively making it contiguous. > Allow for that scenario by testing the entries in the sg_table for > contiguous coverage. > > Reviewed-by: Brian Starkey > Signed-off-by: Liviu Dudau > --- > > Hi, > > This patch is the only change I need in order to be able to use existing > IOMMU domain infrastructure with the Mali DP driver. I have tested the > patch and I know it works correctly for my setup, but I would like to get > some comments on whether I am on the right path or if CMA really wants to > see an sg_table with only one entry. CMA, as the memory allocator, doesn't care as it doesn't even see the sg table. The drm_gem_cma_helper is badly named as it doesn't depend on CMA, it should have been called drm_gem_dma_contig_helper or something similar. The assumption at the base of that helper library is that the memory is DMA contiguous. Your patch guarantees that, so it should be fine. I've quickly checked the drivers using drm_gem_cma_prime_import_sg_table and none of them use cma_obj->sgt, so I think there's no risk of breakage. However, I would prefer if you updated the drm_gem_cma_object structure documentation to explicitly state that the sgt can contain multiple entries but that those entries are guaranteed to have contiguous DMA addresses. With the documentation update, Reviewed-by: Laurent Pinchart > drivers/gpu/drm/drm_gem_cma_helper.c | 22 ++++++++++++++++++++-- > 1 file changed, 20 insertions(+), 2 deletions(-) > > diff --git a/drivers/gpu/drm/drm_gem_cma_helper.c > b/drivers/gpu/drm/drm_gem_cma_helper.c index 020e7668dfaba..43b179212052d > 100644 > --- a/drivers/gpu/drm/drm_gem_cma_helper.c > +++ b/drivers/gpu/drm/drm_gem_cma_helper.c > @@ -482,8 +482,26 @@ drm_gem_cma_prime_import_sg_table(struct drm_device > *dev, { > struct drm_gem_cma_object *cma_obj; > > - if (sgt->nents != 1) > - return ERR_PTR(-EINVAL); > + if (sgt->nents != 1) { > + /* check if the entries in the sg_table are contiguous */ > + dma_addr_t next_addr = sg_dma_address(sgt->sgl); > + struct scatterlist *s; > + unsigned int i; > + > + for_each_sg(sgt->sgl, s, sgt->nents, i) { > + /* > + * sg_dma_address(s) is only valid for entries > + * that have sg_dma_len(s) != 0 > + */ > + if (!sg_dma_len(s)) > + continue; > + > + if (sg_dma_address(s) != next_addr) > + return ERR_PTR(-EINVAL); > + > + next_addr = sg_dma_address(s) + sg_dma_len(s); > + } > + } > > /* Create a CMA GEM buffer. */ > cma_obj = __drm_gem_cma_create(dev, attach->dmabuf->size); -- Regards, Laurent Pinchart From 1582873431061747190@xxx Wed Nov 01 14:15:37 +0000 2017 X-GM-THRID: 1582873431061747190 X-Gmail-Labels: Inbox,Category Forums