Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1349532ybk; Thu, 14 May 2020 06:55:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzPmVcHEHcxTmKi767GhfEBlSbsM+oxrk+72Orw5goC/VLdZMdpK0qif/NvoB/P69F6P7AY X-Received: by 2002:a50:c045:: with SMTP id u5mr2167502edd.122.1589464539018; Thu, 14 May 2020 06:55:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589464539; cv=none; d=google.com; s=arc-20160816; b=rAg/vili7gZLx/dOcaiYxN9H8gMNKS66lpr/14A+f6qHUbQZXSIt5kIejzj4pYwa8h BCkIAaPto55NhXy0Tu4I2BfOWeHSso8YGyEp6f2sPzcgOovMVn5gk0Ikv0ghDaWxN0tn 2Zep6hPh1fuD1P5zchDJBKlz2MiYhdfEeZF4e3ICv87zTEYN4cUxJkkTf66fauFlUm0M X7nszSgQP2hTdf/as4fFlbkbYybzj5+EeqOb8Xli5O4zpqEANn7MVpjeoMVYZ5qITHZH GyHeCCSycW5lryxAbv78OTTa6ed0uMkZgyy8++8ySpMT6NYlGsov1Qot8x4S8A44ZeyU HWMg== 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=RUR5MybGXQozcExrFFet/sfsht0iRN6B8EV5p6WBYf4=; b=bvEbhiUA08HJEmZct780MN95+VJjAZ38+Ev3HcbmEY+twAV5aUFemKwPJb9vEfWH2F w0rweo8Lr358gw7rKTiEnvDD4HsiIboyZpfGgp8g1jBj5gb0A7PhkFCwSzAPstjhlx6H m4Ecv5J+gWKtL5a/0d4RmwZjLzt5jhateQWlbp7XXfwz3yAQ/qIkU0PpouWksZzY0AQr PW6fcFDg3kChAHucwIPhss5NdsXjCRw6VeWI2M6z6PcGIR9tdLyBTdS/1VkzKkiGUeIu V9gc5cB8H+JW0PPA1ZqlaAMEmG6KPbWAtY4i6qLRG/0a+RXfYOiGrROyxbK7DWyg8/22 kcRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=10yB1NOW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a19si1944793edn.349.2020.05.14.06.55.14; Thu, 14 May 2020 06:55:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=10yB1NOW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726088AbgENNvl (ORCPT + 99 others); Thu, 14 May 2020 09:51:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:46294 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726011AbgENNvl (ORCPT ); Thu, 14 May 2020 09:51:41 -0400 Received: from mail-ot1-f46.google.com (mail-ot1-f46.google.com [209.85.210.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B3D7B20756 for ; Thu, 14 May 2020 13:51:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589464300; bh=U4WS7dpPUSnHoDDXd9I/RGkZKydgvH6uscT6wgd5yaA=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=10yB1NOW59ZFLk88tVol6JSCXSW16g5KS52gy+76Le+Tx7PliiJwrDveF5QUp3aAc f61hKPaNOqkKM/2+UmfCiYuO4Jfs+HSy+dc4Gmiq0HieYQPdWNpKME8aLXz7MuovlT /hy6GRU1SUPCaSfNSwajP+sQsgP/LEet6da+KIJY= Received: by mail-ot1-f46.google.com with SMTP id w22so2191944otp.5 for ; Thu, 14 May 2020 06:51:40 -0700 (PDT) X-Gm-Message-State: AOAM532hsOYeLq5Rjs0YlfWhDtEGXgaQ4rmGGWirZqyUGe8n/A259ckL fz+1nFLwXqnGu9PtpPuIztvvdOxjOITOkPuBHA== X-Received: by 2002:a9d:1441:: with SMTP id h59mr3620806oth.192.1589464299942; Thu, 14 May 2020 06:51:39 -0700 (PDT) MIME-Version: 1.0 References: <20200513132114.6046-1-m.szyprowski@samsung.com> <20200513133245.6408-1-m.szyprowski@samsung.com> <20200513133245.6408-19-m.szyprowski@samsung.com> In-Reply-To: <20200513133245.6408-19-m.szyprowski@samsung.com> From: Rob Herring Date: Thu, 14 May 2020 08:51:27 -0500 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v5 19/38] drm: panfrost: fix common struct sg_table related issues To: Marek Szyprowski Cc: dri-devel , Linux IOMMU , linaro-mm-sig@lists.linaro.org, "linux-kernel@vger.kernel.org" , Christoph Hellwig , Robin Murphy , Bartlomiej Zolnierkiewicz , "moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE" , David Airlie , Daniel Vetter , Tomeu Vizoso 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 Wed, May 13, 2020 at 8:33 AM Marek Szyprowski wrote: > > The Documentation/DMA-API-HOWTO.txt states that the dma_map_sg() function > returns the number of the created entries in the DMA address space. > However the subsequent calls to the dma_sync_sg_for_{device,cpu}() and > dma_unmap_sg must be called with the original number of the entries > passed to the dma_map_sg(). > > struct sg_table is a common structure used for describing a non-contiguous > memory buffer, used commonly in the DRM and graphics subsystems. It > consists of a scatterlist with memory pages and DMA addresses (sgl entry), > as well as the number of scatterlist entries: CPU pages (orig_nents entry) > and DMA mapped pages (nents entry). > > It turned out that it was a common mistake to misuse nents and orig_nents > entries, calling DMA-mapping functions with a wrong number of entries or > ignoring the number of mapped entries returned by the dma_map_sg() > function. > > To avoid such issues, lets use a common dma-mapping wrappers operating > directly on the struct sg_table objects and use scatterlist page > iterators where possible. This, almost always, hides references to the > nents and orig_nents entries, making the code robust, easier to follow > and copy/paste safe. > > Signed-off-by: Marek Szyprowski > Reviewed-by: Steven Price > --- > For more information, see '[PATCH v5 00/38] DRM: fix struct sg_table nents > vs. orig_nents misuse' thread: > https://lore.kernel.org/linux-iommu/20200513132114.6046-1-m.szyprowski@samsung.com/T/ > --- > drivers/gpu/drm/panfrost/panfrost_gem.c | 4 ++-- > drivers/gpu/drm/panfrost/panfrost_mmu.c | 7 +++---- > 2 files changed, 5 insertions(+), 6 deletions(-) Reviewed-by: Rob Herring