Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp2447088ybk; Sun, 17 May 2020 22:20:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzrBpdD4g5YpNBH7KD8cf8xtUxvj+iYinLiu8Qo2OaOIs1ov8VDu4xgmwIrb9M3RFnlcgrK X-Received: by 2002:a17:906:404a:: with SMTP id y10mr13256158ejj.130.1589779206958; Sun, 17 May 2020 22:20:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589779206; cv=none; d=google.com; s=arc-20160816; b=w+Pcjr9hkaKl1Z7CGG+E1wYvefYsaMy8zmtjol6bh3fIuBE1IvTxs/D9eJkwArDTnr NQTZ/c3JUDM87xpzVzZ+Y2SSSYS7FTwg927EWZB1FadHbCeyxKgdqRLmyc5tnUfM2tVJ sHultB6HEznhuK0mdC1xJzwaz7SXUgTvGV+z7mp/B1mB5KuOfLEgNT5SH6HMi4Y6uq9N 9D1S+iCWagYz5f31JP0/dceWIgrjqYjS5ihfVjavgFZJ/dMbf230g7f5/v8LO4r84g0k tQwlj7FprrKCk92yPmsMFsd0XfjEtw5obBw0xLVvSc/GDTPSD9MheGUct8MG0tCMqtIc Cq7Q== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=2aBH2l5a9qdUFjapKqel2+EsvytkfwpI8+433N3qSg8=; b=exZQw2rOjjeCxAcCT8Ig6Q+e4ZUFIv99szF1YKNFVGVrrBMb1mj7ThJwi9kBlp+xJ5 z+vErNaOZJ+SkYqQb0gz9aibRSyuXXxN9ectAmaCCHmwS34jqEsgKnTO8kYVH6sNG65s ti8Pd0XqYLreiDdwRNodjEm/11vrcdwitELdYaEwwfxGNjgy2lnBsrMtTdX7fDvusu61 3hBBllMYoO/DdF5rHK64JwvyEID4PKCL1M+j25CTnyLVmCKtNCpQK0hGW3UZSm32P9Ly 0xCVLecEdR1TMSPovHsScUfFRsDb79EUNortfC/SCAaaJ2OYK+KKP0aEYS/+lX6p0Cmp eVcA== ARC-Authentication-Results: i=1; mx.google.com; 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 y22si5905318ejb.39.2020.05.17.22.19.42; Sun, 17 May 2020 22:20:06 -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; 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 S1726499AbgERFRO (ORCPT + 99 others); Mon, 18 May 2020 01:17:14 -0400 Received: from mx2.suse.de ([195.135.220.15]:37726 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726040AbgERFRO (ORCPT ); Mon, 18 May 2020 01:17:14 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id EF326ABE4; Mon, 18 May 2020 05:17:14 +0000 (UTC) Subject: Re: [PATCH v5 27/38] xen: gntdev: fix common struct sg_table related issues To: Marek Szyprowski , dri-devel@lists.freedesktop.org, iommu@lists.linux-foundation.org, linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org Cc: Christoph Hellwig , Robin Murphy , Bartlomiej Zolnierkiewicz , linux-arm-kernel@lists.infradead.org, David Airlie , Daniel Vetter , Boris Ostrovsky , xen-devel@lists.xenproject.org References: <20200513132114.6046-1-m.szyprowski@samsung.com> <20200513133245.6408-1-m.szyprowski@samsung.com> <20200513133245.6408-27-m.szyprowski@samsung.com> From: =?UTF-8?B?SsO8cmdlbiBHcm/Dnw==?= Message-ID: Date: Mon, 18 May 2020 07:17:09 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <20200513133245.6408-27-m.szyprowski@samsung.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 13.05.20 15:32, 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 Acked-by: Juergen Gross Juergen