Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp845640ybk; Wed, 13 May 2020 14:52:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzV3PzJJ2aDCJeS4Xe/DwXkGwhdbkhb/6yxsO4JH+aJSCZn6uiaTKNJhck6A6YJS1AK/vjW X-Received: by 2002:a17:906:34c7:: with SMTP id h7mr1036388ejb.300.1589406778463; Wed, 13 May 2020 14:52:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589406778; cv=none; d=google.com; s=arc-20160816; b=i4Np8qhn4qfSGtF4i5EpyWZu0Q7t9SOfgc5CRwwLn3ROabJlmsYW5ZcRltFSu3ZBw7 s24SSRfes9VTqOStP//SiJYiHTjo6gEQvhqPHZzEimOCWtPMAYB4IDYFHfo/RizvSU2k DXPPdPaDfZGpx6/AtFwxoGF++zWfTwt0TupeMKxvq8VCi/exzofX3odlKnkU6rpPuDrb 899hR50+z+pxSoLwjn8H33hMsea1JGuHPJfAuN/KfhdM658MUaJqwSOAivknsLmA2YQy QarL8t1G0wzpUwZHDTmO55vcpnNRm8YeWaHDIO1ejt7Zph0txdwn45AyRwglsDIebcFq 6Atw== 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=c4GzEKN4UHscMkRfgK/KmlmDtv9fIM50sPFyVikryKQ=; b=aMP+uZhYyEhLpEHAoMIYBJ78nyXWXFqs2qL3db3LeJs59h7zPEOUF2ORFUzY1QM7cw DZ1p+mCqt6zTXKlPguFej9bC1Fte0+g8LXUEmvSMg3pagEFMQrM72VP1TjD5zSZxryd6 icMuASMHENZ/sjyHCkR0+KQ2FdZvh3SDi3oGcP6HYjP3Z+HllCU2HWj6/f9tBW/HaTFH ni073uEihGWEPc63Dg5+F2u6kg5YOP5gmO4o1iNgqfMghpmPkUHXXQzUvqEue3R240h3 QQj9MckTriLeZgeeJiqgAfBkfzX2kTe05M4yP/+e323CW2qIG+3i0S2h0a2cNHpUHPou pVTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@anholt-net.20150623.gappssmtp.com header.s=20150623 header.b=O8JCadTs; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gx8si623302ejb.196.2020.05.13.14.52.34; Wed, 13 May 2020 14:52:58 -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=@anholt-net.20150623.gappssmtp.com header.s=20150623 header.b=O8JCadTs; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729849AbgEMVvP (ORCPT + 99 others); Wed, 13 May 2020 17:51:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1729487AbgEMVvP (ORCPT ); Wed, 13 May 2020 17:51:15 -0400 Received: from mail-lj1-x243.google.com (mail-lj1-x243.google.com [IPv6:2a00:1450:4864:20::243]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 818D1C061A0C for ; Wed, 13 May 2020 14:51:13 -0700 (PDT) Received: by mail-lj1-x243.google.com with SMTP id b6so1302853ljj.1 for ; Wed, 13 May 2020 14:51:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anholt-net.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=c4GzEKN4UHscMkRfgK/KmlmDtv9fIM50sPFyVikryKQ=; b=O8JCadTsQl0Tyvlb72GDnj5fWwBBQal84Q4eYowAUSAU0My9xiciKbQ5opOHnfwl9N Qb5nQGHUjnL79yJetrBRfHA673D+DtgS7C/OXM/Jj+mCy4cl51SspGMJvwVFVu8mQw/d E0lrDdlhkaMITXDJ0+azix8pePd4EjeDt5g7yhokYKopEAlRvUP/8w/RAInfA6caXo+K ruac9LVx6zmyBPRvtCJoQCkeekvevefrJdyMNUMDpe0/sCo9HnlDe3w74ikeYyTigQIj aG+tjvBV7Sqetjfnq4VJ/fo8MRHFgz35H6NVpzXrbNEzRfRmIydljGEGOXoJVfCSbwOl 4D5A== 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=c4GzEKN4UHscMkRfgK/KmlmDtv9fIM50sPFyVikryKQ=; b=ACVyDMAYOLw5qmQaZV7qSNHqGvTFpUhcy8o+vJQ75lqlgZxo1mN/iDtogqK7Nu8CWw Gbr2VcJ01GpO0buq3+7tzt2s5pMSjNwh2V275lYL69pYA1pwchjmn80f+vpIGS4+hT80 pvyLzBiv5yvsirfs3dJCnpNwAPl58kWnaaFzcfrEu7PXIDAB53GXwYRsWnHvE/8F3Bzy DqjbsR0yjhZ5obpNBLcsRgr249YoW4+6u3kRHkrlQGrP6hxEadHwaZhrWPdn0YPjHY6v GCY4AFovu6u6FlDR7GVH45mWG0zhTHCUdhZhrXk7z4qgcWl8v7Cz7mD9FI6CU6XXxEOn g9Ew== X-Gm-Message-State: AOAM5334xaj9J5o3eoh/VM1uM9rJqbmRLdyEuq6LuxT50ru9+TH82fgg eNhuSGrDKuTKO028AgyPENtMC6niT55ZtlGcmNQcrA== X-Received: by 2002:a2e:8047:: with SMTP id p7mr641481ljg.206.1589406671985; Wed, 13 May 2020 14:51:11 -0700 (PDT) MIME-Version: 1.0 References: <20200513132114.6046-1-m.szyprowski@samsung.com> <20200513133245.6408-1-m.szyprowski@samsung.com> <20200513133245.6408-24-m.szyprowski@samsung.com> In-Reply-To: <20200513133245.6408-24-m.szyprowski@samsung.com> From: Eric Anholt Date: Wed, 13 May 2020 14:51:00 -0700 Message-ID: Subject: Re: [PATCH v5 24/38] drm: v3d: fix common struct sg_table related issues To: Marek Szyprowski Cc: DRI Development , iommu@lists.linux-foundation.org, linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org, Christoph Hellwig , Robin Murphy , Bartlomiej Zolnierkiewicz , linux-arm-kernel@lists.infradead.org, David Airlie , Daniel Vetter 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 6: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: Eric Anholt