Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp645985imu; Tue, 27 Nov 2018 19:10:09 -0800 (PST) X-Google-Smtp-Source: AFSGD/WbBiz6UwhzBJNCElyPwIQdOITVAso3LSV5u/HahEH74oxtiJeb27RIyZpkR5vbGWyZlN96 X-Received: by 2002:a65:624c:: with SMTP id q12mr31836675pgv.379.1543374609861; Tue, 27 Nov 2018 19:10:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543374609; cv=none; d=google.com; s=arc-20160816; b=vLbAZqe65QJXCfyanlr+NageTyt9tQ9SrlkEDblUOMPO105yOu/Vsevg+NoIYO1qKH RDePZa/NcBn1VcPEsGfzGELOsJsISBV5Oo049mIui1oHJVJ/crPjwPSU9UG9kDy07V8d Z+m8M0tEYPkAfv7U93ZXezJkHZdAPo572xg4Az9X67I8yzwi/WTq69MHXgIAYzbzPZdX QT8lvgYm7QU3LT3kYAmW2eExDkRfRHQrbv8qC1XkZ0hvLZxvHNZvmgKMPO1HMBNis+GZ b++U5Kn4ziOUTPzp5SXlIRHg2Zbl4gsM7v2G0B/HXwlNN4P4sQJiey6Ewt/zDHcCS3O+ OWUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=rX3YCYRauTXbohemKf+2i0TtPdpUG5WLNNRme1MxHFI=; b=s1Y2AePfPLTUgD7yGlYZM7HvQQlwssCP/qkt2Jde90O+KfMUWfpGiXv2nM4/S9fl8g 1EjvZMLFBoeVN/fwEQcfsIoc2yQfSorsqSVOxgrc46g5fAcitdQ0XMKvW4n9okN6V+1p mqIGjXEQaWtUA/HTq2y57oBYbKdIx2EfBEaJTvDjFL09Vl1igl7mhjZOqnAmdFzIgnPU PAmFfC/D7Rb2YhIEVDrKXHwXU0RKUs2fXuDFETSEI96D9sY4LSfMSm7dH4S4dbJip0xR v7nqQ2Zi4e10T8WDJxuYpnuS/mhAHtDbn5l02YFO01EWlv6aEOGmgnKvN0aIQwfLjDUH EU5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=VZtHmVvX; 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t10si5628849pgn.551.2018.11.27.19.09.54; Tue, 27 Nov 2018 19:10:09 -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 header.i=@chromium.org header.s=google header.b=VZtHmVvX; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727148AbeK1OJT (ORCPT + 99 others); Wed, 28 Nov 2018 09:09:19 -0500 Received: from mail-yw1-f68.google.com ([209.85.161.68]:41817 "EHLO mail-yw1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726953AbeK1OJT (ORCPT ); Wed, 28 Nov 2018 09:09:19 -0500 Received: by mail-yw1-f68.google.com with SMTP id f65so10116886ywc.8 for ; Tue, 27 Nov 2018 19:09:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=rX3YCYRauTXbohemKf+2i0TtPdpUG5WLNNRme1MxHFI=; b=VZtHmVvXbm16SG9AiR3dDfpaM8YQd8YvHUvRqvsfyPaNRgPVSa35h2fd3qqUFyUoeP Olfpt4ISgyD5/YS0GDfXOb0Fc1V6rWtlt8wKQARFmttS0w+BCjF49j0zBjvXgf3ODF2H s5/j0IRXnsBpp9NX5qhTydvdewwCPnjncfcFE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=rX3YCYRauTXbohemKf+2i0TtPdpUG5WLNNRme1MxHFI=; b=Bp+oxpW5HoZK3bx+T1uZN/szhp//wzyB0Oo+NQ5KWynKoQe2jLOqsQB+UBCQUQUWNn xlQVEcMNiTU2vSMQd/oONfoWmRUbRgnbsVXOY4ohwK7jratkqqdO5AZmZSxasWNxwsYC jgQpjR4HJNwIQWmHjnbAgaj1S65jaE7EMOoyqKzQpz+NQor3JrcMwB5/vAp/MbDpMfJ2 rUOfcaaDc/qvosetor/UCbtqTViAFNCvCGbQCS6P3/LH6mLjAiGrWCqZxL29pt/7zhLM w0qtxV1dVSc8nxufEXew0i/+W0Wnl7mTDC9D7SYPvF8a07ZuFfeMUU1RZ8dK9EJCllVk pA4A== X-Gm-Message-State: AGRZ1gKVOh0Auts2faD4SkWglohH8pC3DwISQX9FKNbTlw90k2wQjlwt h5+FIY2+WPpcyg/dGz/x7rp5hz4AiyVTLQ== X-Received: by 2002:a0d:ea16:: with SMTP id t22mr37176094ywe.341.1543374556766; Tue, 27 Nov 2018 19:09:16 -0800 (PST) Received: from mail-yw1-f54.google.com (mail-yw1-f54.google.com. [209.85.161.54]) by smtp.gmail.com with ESMTPSA id e194sm4476392ywa.85.2018.11.27.19.09.15 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Nov 2018 19:09:15 -0800 (PST) Received: by mail-yw1-f54.google.com with SMTP id q11so10140867ywa.0 for ; Tue, 27 Nov 2018 19:09:15 -0800 (PST) X-Received: by 2002:a81:3194:: with SMTP id x142mr34808824ywx.92.1543374555271; Tue, 27 Nov 2018 19:09:15 -0800 (PST) MIME-Version: 1.0 References: <20181126213710.3084-1-vivek.gautam@codeaurora.org> In-Reply-To: <20181126213710.3084-1-vivek.gautam@codeaurora.org> From: Tomasz Figa Date: Wed, 28 Nov 2018 12:09:03 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 1/1] drm: msm: Replace dma_map_sg with dma_sync_sg* To: Vivek Gautam Cc: David Airlie , Rob Clark , Linux Kernel Mailing List , freedreno , dri-devel , linux-arm-msm , jcrouse@codeaurora.org, Sean Paul Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Vivek, On Tue, Nov 27, 2018 at 6:37 AM Vivek Gautam wrote: > > dma_map_sg() expects a DMA domain. However, the drm devices > have been traditionally using unmanaged iommu domain which > is non-dma type. Using dma mapping APIs with that domain is bad. > > Replace dma_map_sg() calls with dma_sync_sg_for_device{|cpu}() > to do the cache maintenance. > > Signed-off-by: Vivek Gautam > Suggested-by: Tomasz Figa > Cc: Rob Clark > Cc: Jordan Crouse > Cc: Sean Paul > --- > > Changes since v1: > - Addressed Jordan's and Tomasz's comments for > - moving sg dma addresses preparation out of the coditional > check to the main path so we do it irrespective of whether > the buffer is cached or uncached. > - Enhance the comment to explain this dma addresses prepartion. > Thanks for the patch. Some comments inline. > drivers/gpu/drm/msm/msm_gem.c | 31 ++++++++++++++++++++++--------- > 1 file changed, 22 insertions(+), 9 deletions(-) > > diff --git a/drivers/gpu/drm/msm/msm_gem.c b/drivers/gpu/drm/msm/msm_gem.c > index 00c795ced02c..1811ac23a31c 100644 > --- a/drivers/gpu/drm/msm/msm_gem.c > +++ b/drivers/gpu/drm/msm/msm_gem.c > @@ -81,6 +81,8 @@ static struct page **get_pages(struct drm_gem_object *obj) > struct drm_device *dev = obj->dev; > struct page **p; > int npages = obj->size >> PAGE_SHIFT; > + struct scatterlist *s; > + int i; > > if (use_pages(obj)) > p = drm_gem_get_pages(obj); > @@ -104,12 +106,21 @@ static struct page **get_pages(struct drm_gem_object *obj) > return ptr; > } > > - /* For non-cached buffers, ensure the new pages are clean > + /* > + * dma_sync_sg_*() flush the physical pages, so point > + * sg->dma_address to the physical ones for the right behavior. The two halves of the sequence don't really relate to each other. An sglist has the `page` field for the purpose of pointing to physical pages. The `dma_address` field is for DMA addresses, which are not equivalent to physical addresses. I'd rewrite it like this; /* * Some implementations of the DMA mapping ops expect * physical addresses of the pages to be stored as DMA * addresses of the sglist entries. To work around it, * set them here explicitly. */ > + */ > + for_each_sg(msm_obj->sgt->sgl, s, msm_obj->sgt->nents, i) > + sg_dma_address(s) = sg_phys(s); > + > + /* > + * For non-cached buffers, ensure the new pages are clean > * because display controller, GPU, etc. are not coherent: > */ > - if (msm_obj->flags & (MSM_BO_WC|MSM_BO_UNCACHED)) > - dma_map_sg(dev->dev, msm_obj->sgt->sgl, > - msm_obj->sgt->nents, DMA_BIDIRECTIONAL); > + if (msm_obj->flags & (MSM_BO_WC | MSM_BO_UNCACHED)) > + dma_sync_sg_for_device(dev->dev, msm_obj->sgt->sgl, > + msm_obj->sgt->nents, > + DMA_TO_DEVICE); Why changing from DMA_BIDIRECTIONAL? > } > > return msm_obj->pages; > @@ -133,14 +144,16 @@ static void put_pages(struct drm_gem_object *obj) > > if (msm_obj->pages) { > if (msm_obj->sgt) { > - /* For non-cached buffers, ensure the new > + /* > + * For non-cached buffers, ensure the new > * pages are clean because display controller, > * GPU, etc. are not coherent: > */ > - if (msm_obj->flags & (MSM_BO_WC|MSM_BO_UNCACHED)) > - dma_unmap_sg(obj->dev->dev, msm_obj->sgt->sgl, > - msm_obj->sgt->nents, > - DMA_BIDIRECTIONAL); > + if (msm_obj->flags & (MSM_BO_WC | MSM_BO_UNCACHED)) > + dma_sync_sg_for_cpu(obj->dev->dev, > + msm_obj->sgt->sgl, > + msm_obj->sgt->nents, > + DMA_FROM_DEVICE); Ditto. Best regards, Tomasz