Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3961769pxv; Mon, 5 Jul 2021 09:55:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzNZyI4vXFQcnY0+OOsRzPc2Ngv9hCMx3wXbuTzxuqQh+nBhbS2qniaRg1vqVNmx6B+jMM2 X-Received: by 2002:a05:6402:10cc:: with SMTP id p12mr17729964edu.328.1625504108955; Mon, 05 Jul 2021 09:55:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625504108; cv=none; d=google.com; s=arc-20160816; b=ahzsf6cR5iDmyeLYKcs0amNE/3E/jU9qEFFr/5lGcnK3Q4U/+/W9sW17xlD9oJD64m QzaKHoUn7qpgENJrNySU+dbQKWeXZCzaFXrk/gOLoX9EqyL+IL2IlfkAOHafoAmcTj4s EPBE8ZuJNaxaQEN9u7No8VxC8gZ2cpWS/9RpAXqbWlJ7O0oy2+oPy8bM5DIujG2gLmVA YzA0qbmMD3LjDmpExZheA+lekAjguSmIjEQHmofljMcyKtOFvsP7g1ifuX1ztI/XGkwY VvsvbwIAgwxwgdxlAEiQ30rjeMnpyY+e5izJkvhlIsaChkDq52XB1Z6pSz4cw+mkj970 xr2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=TRW2liv0KvxRpEn1sZgxByQ6WPmBTh1GhCnSHVjnwbg=; b=uK61+5FmJL6Y9y8kJOqT2McuzB0Gzq2K9nWqOhuGpnfELfPgIbliKfNzDYsCQktYIE pNF+N+86rQPBUFdsbe9L9jYJLNFwKt6BvZQOAwhGvG5C8+qYCW6DnTMCaXAy53+t3iyp wd6P2Z+vDzJsSslBaS7nT96lWZ2u0pYiuMVQrD0veJB7/8yVw4S3xK0hcU8eLQzTZplY T1f3quM+/EzLRAzN2Sq6j4u9aZd+zUs2TPBbn+bkCd9eUSCIQzgFf6la49W5eEAs55kP okie1r/hiDGdDFQGNdiI/bal9tR/5mF0oGFHdrPVwz2ZLjdz/y91OCNblyj8b8DHdi7f vfSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=jBFIqWpk; 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 dr6si1727942ejc.411.2021.07.05.09.54.43; Mon, 05 Jul 2021 09:55:08 -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=@ziepe.ca header.s=google header.b=jBFIqWpk; 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 S229783AbhGEQzG (ORCPT + 99 others); Mon, 5 Jul 2021 12:55:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229743AbhGEQzF (ORCPT ); Mon, 5 Jul 2021 12:55:05 -0400 Received: from mail-qv1-xf29.google.com (mail-qv1-xf29.google.com [IPv6:2607:f8b0:4864:20::f29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F27DC06175F for ; Mon, 5 Jul 2021 09:52:28 -0700 (PDT) Received: by mail-qv1-xf29.google.com with SMTP id g15so6103927qvi.13 for ; Mon, 05 Jul 2021 09:52:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=TRW2liv0KvxRpEn1sZgxByQ6WPmBTh1GhCnSHVjnwbg=; b=jBFIqWpkHJUwhFRIEXpavqYg2lOBnFUgtfMCAa51Keo5p1e7uaLLRwx5ShUDeIlhdM 2If2zjmjcfC5T6RoGkkweicUk3Qsx+2vRdseYI/0mJ+ciw96iBmUkpkVkiJE+86t8cyr 2oJc7CwvfA5oUIWZzMzGPAFug62Z67fj3p3Z3WgSBFHsqz4/BWGoOCucw+iLuagpvAH1 PpbSwCitf8MOcMx6/0YLotNGXe8rFb+KOw2NMKF5n5y/HAuQN75chVqThR99yPOEQKYA xDWvGJSbbwBNR2Hg29azK+xEHKNYDfvZIIv02WRktmpruBPJPenBbq+963N6aPphnsv4 Bn7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=TRW2liv0KvxRpEn1sZgxByQ6WPmBTh1GhCnSHVjnwbg=; b=IpsB6ucoi6MdKKsDABXlEo0kq023Gzf093esI4Tq91VT4j4LJCd6r+bi2q6SOnEolS SV7YwQlpJhpj3UkvCe0NZ1R8o53EZptK4LvLK42ELCxbxjUxngLfHRBLyuHNOekZbECU dNwZnKidH1diGaugvfCuEhNCnunAh3pwqwvQDxVA17O3Uo16PD0gq8onGlialhXHMebg nYsihzOTqnDA16t5emZ5xSyHuycZdg2UMSMOCLn5ZM1maku4jHZHBc8T7vlxalkGPaN4 8tAMgQ3bYktikb1roOxpmEwi8c3dYGz5s9oe+7EVaiGN5a7R3a8g5bsWeGh9iNhqFYz2 PmlQ== X-Gm-Message-State: AOAM531QHzUW1GkQAd5I/MKjwyQxpEhu77W0tMl4GA/wsbvHMXyz6R7J ck/fAVAW4FP5H9f4G1fuHGqO3Q== X-Received: by 2002:a0c:ef51:: with SMTP id t17mr13560008qvs.14.1625503947734; Mon, 05 Jul 2021 09:52:27 -0700 (PDT) Received: from ziepe.ca (hlfxns017vw-47-55-113-94.dhcp-dynamic.fibreop.ns.bellaliant.net. [47.55.113.94]) by smtp.gmail.com with ESMTPSA id 82sm5694070qke.63.2021.07.05.09.52.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Jul 2021 09:52:27 -0700 (PDT) Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1m0Rpa-003sCS-IC; Mon, 05 Jul 2021 13:52:26 -0300 Date: Mon, 5 Jul 2021 13:52:26 -0300 From: Jason Gunthorpe To: Oded Gabbay Cc: linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org, sumit.semwal@linaro.org, christian.koenig@amd.com, daniel.vetter@ffwll.ch, galpress@amazon.com, sleybo@amazon.com, dri-devel@lists.freedesktop.org, linux-rdma@vger.kernel.org, linux-media@vger.kernel.org, dledford@redhat.com, airlied@gmail.com, alexander.deucher@amd.com, leonro@nvidia.com, hch@lst.de, amd-gfx@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, Tomer Tayar Subject: Re: [PATCH v4 2/2] habanalabs: add support for dma-buf exporter Message-ID: <20210705165226.GJ4604@ziepe.ca> References: <20210705130314.11519-1-ogabbay@kernel.org> <20210705130314.11519-3-ogabbay@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210705130314.11519-3-ogabbay@kernel.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 05, 2021 at 04:03:14PM +0300, Oded Gabbay wrote: > + rc = sg_alloc_table(*sgt, nents, GFP_KERNEL | __GFP_ZERO); > + if (rc) > + goto error_free; If you are not going to include a CPU list then I suggest setting sg_table->orig_nents == 0 And using only the nents which is the length of the DMA list. At least it gives some hope that other parts of the system could detect this. > + > + /* Merge pages and put them into the scatterlist */ > + cur_page = 0; > + for_each_sgtable_sg((*sgt), sg, i) { for_each_sgtable_sg should never be used when working with sg_dma_address() type stuff, here and everywhere else. The DMA list should be iterated using the for_each_sgtable_dma_sg() macro. > + /* In case we got a large memory area to export, we need to divide it > + * to smaller areas because each entry in the dmabuf sgt can only > + * describe unsigned int. > + */ Huh? This is forming a SGL, it should follow the SGL rules which means you have to fragment based on the dma_get_max_seg_size() of the importer device. > + hl_dmabuf->pages = kcalloc(hl_dmabuf->npages, sizeof(*hl_dmabuf->pages), > + GFP_KERNEL); > + if (!hl_dmabuf->pages) { > + rc = -ENOMEM; > + goto err_free_dmabuf_wrapper; > + } Why not just create the SGL directly? Is there a reason it needs to make a page list? Jason