Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp2451133ybb; Sun, 5 Apr 2020 07:53:48 -0700 (PDT) X-Google-Smtp-Source: APiQypJGEXBqnbbKnr8CLsVOQ0VGRs8QB7Q9x1wmaj4im2VaMtl/uUpkVyFfKtnHFqh2cQRyLsZe X-Received: by 2002:a9d:748a:: with SMTP id t10mr15047485otk.244.1586098428524; Sun, 05 Apr 2020 07:53:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586098428; cv=none; d=google.com; s=arc-20160816; b=ACHLi3PsWFG/O/DeKYnFtodfgYFGWfJoLplJ+IuDfJ0zFQOfisjxUttP/Xbzo7J/Dz 9OEdRwvW91EambXEUumOovOlJ42PIG7D5pjqo77en8pqFexMWOp8hVX24WEw1NYQRjWy fyJgVnCSYbcbvNpeVIlOiPt7bxPzK5t6nrgueJ51NGh1rlmIIv7WSnJG7OXN3XujHbEW 83t7IXgD9PsaSiGHbtHsomvRnywzfrYVV0UDgez9GwvkFX7ZtZxMavVGd/4T9016gPky cZ4JLI78KtQSIC/McThk1zvMjeewU1R1sGlgYs86jPEBqVmjDY6oVQVzzpuHOThY2Dda oWfA== 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=v+dqDvCPt/897rtlW7rn+HRZ8CXQjFzk7KCjChk3k24=; b=0dptKxDKJLg0133qWknw542huiHiFD3iJA/CkI9cz51rdEX58qhWl/M/SbWDPlSAGp pvR2y4ZeeV39CD0lffYxthIjvmYjjeRdt7XknAY5PAxwle1KOe0MVQlfOL+Tx9fIOa6x 7cHSdPfDe6k6ZKT24HqhrDW7tCesP/87cAlxLb1NNe89zbueVKirmJeN5oIBlq9vnCMh LZW6JDSWjz5gfMxNd1V/klz3MnkS3tgslc8KUt/QJIfNvUCmKGXqbaBBZmLYXlhLZhOo 6DZ0H2mWfiyHLK3q+Je9T7/+ppwuHO3FKRoiGyQFXHFrX4Cc43WSCeg/MTUzO90kXS3w UpJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=hNmVs66K; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g7si6965252ots.270.2020.04.05.07.53.34; Sun, 05 Apr 2020 07:53:48 -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=@gmail.com header.s=20161025 header.b=hNmVs66K; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726701AbgDEOsC (ORCPT + 99 others); Sun, 5 Apr 2020 10:48:02 -0400 Received: from mail-yb1-f196.google.com ([209.85.219.196]:36189 "EHLO mail-yb1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726598AbgDEOsC (ORCPT ); Sun, 5 Apr 2020 10:48:02 -0400 Received: by mail-yb1-f196.google.com with SMTP id i4so7302084ybl.3; Sun, 05 Apr 2020 07:48:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=v+dqDvCPt/897rtlW7rn+HRZ8CXQjFzk7KCjChk3k24=; b=hNmVs66K30OIgjszWm08ENcKBGYBbmyqTsytRVdgaU8hiMRMsvs0UocE6U+1o2Cl9u UnhOtihY/4/dKGac5lGPw2uhsev2IFZLr7nh2SltrUZ/CEAjruNVEfJAu1xwfNj89yBo t6jqrh7D/AQWONdkAxfjoefdWy3JE2k1LgViJTxsqnKI8oqBHB3zDgVFJOdcN1e4HtKk S97UpoclL3VkZmeu2lhj3ko0vuHsCsOvnFaCraRWl7n0FiLQvAsO10Lhq/40WB0j27Cp rgtvjVLmOEJk+wJemh3IsBHV8fOnQ9E62iI/1KmyZP/yKFeKVUQI+nziwePMYfUfqQnE jRGA== 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=v+dqDvCPt/897rtlW7rn+HRZ8CXQjFzk7KCjChk3k24=; b=IdxxZSGg0Ugz65z5KHTOrDJ+41hRP+hwWq/ruKoh0FGIvZEdi+FkLKKnaguiGqg3M/ IXhU2oI9YGaHJo70+pjrTVwmEV5NSYeSnhxzmTkFLUAcbVhCEjtK2/GA9Gm5b6OYQCk4 i52/0IhjzMFZlkcoRd7QNhp8MK7ty5TIYfrucLTiiBy/fsAZqHL+cp0rV8ycj+LCKLMp TMc1xB4oHRedctYlDz3VkW9mEMun+k5ulscFo47MhEKD3NChP/2j8s/kMJF9yz1z06uY NtjsOeTbzU9y9R6WTWAzxgYq7VBu9j0m8P6yB4z0g6yqH4gXrfbzK657YI4/lddFiDNm +pdA== X-Gm-Message-State: AGi0PuZTfne1x3c1CgeYhBEEdw7WYWEzd5bKBOllqYzYPVoNjJXLTVU4 BPfXqlkYGAEzs5Szn7V0pmAe/hgIbV7KRWvaJcsWng== X-Received: by 2002:a25:dcd4:: with SMTP id y203mr30504136ybe.483.1586098080938; Sun, 05 Apr 2020 07:48:00 -0700 (PDT) MIME-Version: 1.0 References: <20200327162126.29705-1-m.szyprowski@samsung.com> In-Reply-To: <20200327162126.29705-1-m.szyprowski@samsung.com> From: Alex Deucher Date: Sun, 5 Apr 2020 10:47:49 -0400 Message-ID: Subject: Re: [PATCH v2] drm/prime: fix extracting of the DMA addresses from a scatterlist To: Marek Szyprowski Cc: Maling list - DRI developers , linux-samsung-soc@vger.kernel.org, LKML , Bartlomiej Zolnierkiewicz , David Airlie , Shane Francis , "Michael J . Ruhl" , "for 3.8" , Thomas Zimmermann , Alex Deucher 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 On Fri, Mar 27, 2020 at 12:23 PM Marek Szyprowski wrote: > > Scatterlist elements contains both pages and DMA addresses, but one > should not assume 1:1 relation between them. The sg->length is the size > of the physical memory chunk described by the sg->page, while > sg_dma_len(sg) is the size of the DMA (IO virtual) chunk described by > the sg_dma_address(sg). > > The proper way of extracting both: pages and DMA addresses of the whole > buffer described by a scatterlist it to iterate independently over the > sg->pages/sg->length and sg_dma_address(sg)/sg_dma_len(sg) entries. > > Fixes: 42e67b479eab ("drm/prime: use dma length macro when mapping sg") > Signed-off-by: Marek Szyprowski > Reviewed-by: Alex Deucher Applied. Thanks and sorry for the breakage. Alex > --- > drivers/gpu/drm/drm_prime.c | 37 +++++++++++++++++++++++++------------ > 1 file changed, 25 insertions(+), 12 deletions(-) > > diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c > index 1de2cde2277c..282774e469ac 100644 > --- a/drivers/gpu/drm/drm_prime.c > +++ b/drivers/gpu/drm/drm_prime.c > @@ -962,27 +962,40 @@ int drm_prime_sg_to_page_addr_arrays(struct sg_table *sgt, struct page **pages, > unsigned count; > struct scatterlist *sg; > struct page *page; > - u32 len, index; > + u32 page_len, page_index; > dma_addr_t addr; > + u32 dma_len, dma_index; > > - index = 0; > + /* > + * Scatterlist elements contains both pages and DMA addresses, but > + * one shoud not assume 1:1 relation between them. The sg->length is > + * the size of the physical memory chunk described by the sg->page, > + * while sg_dma_len(sg) is the size of the DMA (IO virtual) chunk > + * described by the sg_dma_address(sg). > + */ > + page_index = 0; > + dma_index = 0; > for_each_sg(sgt->sgl, sg, sgt->nents, count) { > - len = sg_dma_len(sg); > + page_len = sg->length; > page = sg_page(sg); > + dma_len = sg_dma_len(sg); > addr = sg_dma_address(sg); > > - while (len > 0) { > - if (WARN_ON(index >= max_entries)) > + while (pages && page_len > 0) { > + if (WARN_ON(page_index >= max_entries)) > return -1; > - if (pages) > - pages[index] = page; > - if (addrs) > - addrs[index] = addr; > - > + pages[page_index] = page; > page++; > + page_len -= PAGE_SIZE; > + page_index++; > + } > + while (addrs && dma_len > 0) { > + if (WARN_ON(dma_index >= max_entries)) > + return -1; > + addrs[dma_index] = addr; > addr += PAGE_SIZE; > - len -= PAGE_SIZE; > - index++; > + dma_len -= PAGE_SIZE; > + dma_index++; > } > } > return 0; > -- > 2.17.1 > > _______________________________________________ > dri-devel mailing list > dri-devel@lists.freedesktop.org > https://lists.freedesktop.org/mailman/listinfo/dri-devel