Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2397874pxb; Fri, 29 Oct 2021 00:04:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyz78eEU8/HwRD60fD2FG7XAzdp+yhBZeorzmMeZH5pcwmN94ogTaKSelxsWVDODwk8THFn X-Received: by 2002:a17:90a:bc85:: with SMTP id x5mr9617429pjr.166.1635491095870; Fri, 29 Oct 2021 00:04:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635491095; cv=none; d=google.com; s=arc-20160816; b=oWfAYC5bxUzvZpfGlKtB7HkzTdtc70UBzAbm4L3n5/nKXvD96owXMrvezldZsjLkYy upSqoNEM1KsaDdNZUqxFD7JtXF3XFuLRXTVCDeHolCOQDK+b0Z1QZMd9Ibphzq+aU213 ZfIVm+F7q1vJDWbWRrggd8Sud7R94DXLlrbXewnKk73ciM6v7tqpK07rztzx0xM6MFvL ph+oF+p2Og54/EzOgX53wD93rNg8qCKkIlDMfwVRd+/+dyva+iJMnu6ONoXjTe4b5fvV co761w+9EIDJ4/nPr+sCbIm40EVUC8mg2kT279p/uGCrcqh60RLgtDtx4CL+ie0LNZBg /5kw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=r3BsV1GTEqKXRyiYvYJGLvk2Pn1r3f4nsDFd9biBydc=; b=N0iV614Us3GIpe304os+zhdHKoJe7zYD7/m/0N+x3wpU5IhGdLOxLUFa85JL0qSlsu BRNe9xl/n90t7UbUjhTaXLwzLrXyUYq/kFUG+f70TRRY59M1bFfwVvL1JYnA7z9luLQQ nkd4Ch40L10fau5O2GmGLi/rDdsNN4JGXoRWgsrdG/EMW3cUVZK7XMaDHOaox+zzTyNb 1vuQe2ppGev2LTHvq4MlVt3hCc6WP/QG8SaAW9Pk4IbJIqP1BpGkBZuXflkHDCwQAi2l 5gYI8lKmpA66snfm/DI7mutA1QZ7xcaY59fnTThPgw8jP0eYfW9gkh186AhIHhWxzOWu O/nw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@igel-co-jp.20210112.gappssmtp.com header.s=20210112 header.b=1miiAeJB; 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 68si3129483pfe.367.2021.10.29.00.04.42; Fri, 29 Oct 2021 00:04:55 -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=@igel-co-jp.20210112.gappssmtp.com header.s=20210112 header.b=1miiAeJB; 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 S232169AbhJ2HFr (ORCPT + 99 others); Fri, 29 Oct 2021 03:05:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232180AbhJ2HFo (ORCPT ); Fri, 29 Oct 2021 03:05:44 -0400 Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD644C061243 for ; Fri, 29 Oct 2021 00:03:15 -0700 (PDT) Received: by mail-pg1-x532.google.com with SMTP id r28so9115063pga.0 for ; Fri, 29 Oct 2021 00:03:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=igel-co-jp.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=r3BsV1GTEqKXRyiYvYJGLvk2Pn1r3f4nsDFd9biBydc=; b=1miiAeJBD4YHde618x7VUYA3a8mA3M9i9cwKp+Hot/5+6jc/hdle2k/q2vrIoRW6pq jT1WM/yegfAfiaTwfqIrwef7lJ7qOke/IYttmFIK+ELo34L50cDydN0cGctNM7TdVUHU aeh98mybKRQ1WA/0B8kSHysJgPlyfYGJ4GBGP52iCTcRzswlgX1ERw2XKQq8a3ZErNeY RtzSMASWb1oVsKSwSsnYhei+Zc+ilVBUP65qwnB2Ja3n9+jfOLqIuTiK7I8UeFAw1ovF hWzC1RrYP7IkudA4rIHRJTisF5cILo9P/5CGMTnWtid4Dcq2i41os5gZWTx/azWf7UIc ZqCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=r3BsV1GTEqKXRyiYvYJGLvk2Pn1r3f4nsDFd9biBydc=; b=NljGdnybIQjhZ7Sdk7oxZsdx5Q677dUHHqa/PUe3/oLkEB0A9v+8mxsEHsOoMNBjtL d5S5l/UwLiPmO7GjTcnL5EOrnTIuivHhYqiCMzG0uWoF3wMquKo3xyCq1bfSqTyqqd0e KkhjTvYGV8UxM0z6Ti0kSwVEe0o8BIaizMUxk3TQ7vWMXoJmE3782G4mR8XIPcqBfcSX g0Grla1G8390YunYWFn9lIAFwBv9UhxHOfRQIrbA1W5dYN6wQsqHZM3yThBTFDCPKIQ8 rjYgGscIDK3SIosi5mJE5h6PzZCTf0ENY1njWdbaL0C7yY403KXHZ8o3CfaIPkYIu/Uc IqMw== X-Gm-Message-State: AOAM533CHGoE8Q8Yit9pssttX8qGzyuhaBhcl4zkWQAJyjfIgy+k5pKg kHUkFrDxBq6bVLJMbQQjpG+XXA== X-Received: by 2002:a05:6a00:1897:b0:47b:ff8c:3b05 with SMTP id x23-20020a056a00189700b0047bff8c3b05mr9180742pfh.37.1635490995256; Fri, 29 Oct 2021 00:03:15 -0700 (PDT) Received: from tyrell.hq.igel.co.jp (napt.igel.co.jp. [219.106.231.132]) by smtp.gmail.com with ESMTPSA id p16sm6039787pfh.97.2021.10.29.00.03.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Oct 2021 00:03:14 -0700 (PDT) From: Shunsuke Mie To: Zhu Yanjun Cc: Shunsuke Mie , =?UTF-8?q?Christian=20K=C3=B6nig?= , Alex Deucher , Daniel Vetter , Doug Ledford , Jason Gunthorpe , Jianxin Xiong , Leon Romanovsky , Maor Gottlieb , Sean Hefty , Sumit Semwal , dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org, dhobsong@igel.co.jp, taki@igel.co.jp, etom@igel.co.jp Subject: [RFC PATCH v3 1/2] RDMA/umem: Change for rdma devices has not dma device Date: Fri, 29 Oct 2021 16:02:57 +0900 Message-Id: <20211029070258.59299-2-mie@igel.co.jp> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211029070258.59299-1-mie@igel.co.jp> References: <20211029070258.59299-1-mie@igel.co.jp> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Current implementation requires a dma device for RDMA driver to use dma-buf memory space as RDMA buffer. However, software RDMA drivers has not dma device and copy RDMA data using CPU instead of hardware. This patch changes to be hold a dma-buf on struct ib_umem_dmabuf. This allows the software RDMA driver to map dma-buf memory for CPU memory accessing. Signed-off-by: Shunsuke Mie --- drivers/infiniband/core/umem_dmabuf.c | 20 ++++++++++++++++---- include/rdma/ib_umem.h | 1 + 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/drivers/infiniband/core/umem_dmabuf.c b/drivers/infiniband/core/umem_dmabuf.c index e824baf4640d..ebbb0a259fd4 100644 --- a/drivers/infiniband/core/umem_dmabuf.c +++ b/drivers/infiniband/core/umem_dmabuf.c @@ -117,9 +117,6 @@ struct ib_umem_dmabuf *ib_umem_dmabuf_get(struct ib_device *device, if (check_add_overflow(offset, (unsigned long)size, &end)) return ret; - if (unlikely(!ops || !ops->move_notify)) - return ret; - dmabuf = dma_buf_get(fd); if (IS_ERR(dmabuf)) return ERR_CAST(dmabuf); @@ -133,6 +130,8 @@ struct ib_umem_dmabuf *ib_umem_dmabuf_get(struct ib_device *device, goto out_release_dmabuf; } + umem_dmabuf->dmabuf = dmabuf; + umem = &umem_dmabuf->umem; umem->ibdev = device; umem->length = size; @@ -143,6 +142,13 @@ struct ib_umem_dmabuf *ib_umem_dmabuf_get(struct ib_device *device, if (!ib_umem_num_pages(umem)) goto out_free_umem; + /* Software RDMA drivers has not dma device. Just get dmabuf from fd */ + if (!device->dma_device) + goto done; + + if (unlikely(!ops || !ops->move_notify)) + goto out_free_umem; + umem_dmabuf->attach = dma_buf_dynamic_attach( dmabuf, device->dma_device, @@ -152,6 +158,7 @@ struct ib_umem_dmabuf *ib_umem_dmabuf_get(struct ib_device *device, ret = ERR_CAST(umem_dmabuf->attach); goto out_free_umem; } +done: return umem_dmabuf; out_free_umem: @@ -165,13 +172,18 @@ EXPORT_SYMBOL(ib_umem_dmabuf_get); void ib_umem_dmabuf_release(struct ib_umem_dmabuf *umem_dmabuf) { - struct dma_buf *dmabuf = umem_dmabuf->attach->dmabuf; + struct dma_buf *dmabuf = umem_dmabuf->dmabuf; + + if (!umem_dmabuf->attach) + goto free_dmabuf; dma_resv_lock(dmabuf->resv, NULL); ib_umem_dmabuf_unmap_pages(umem_dmabuf); dma_resv_unlock(dmabuf->resv); dma_buf_detach(dmabuf, umem_dmabuf->attach); + +free_dmabuf: dma_buf_put(dmabuf); kfree(umem_dmabuf); } diff --git a/include/rdma/ib_umem.h b/include/rdma/ib_umem.h index 5ae9dff74dac..11c0cf7e0dd8 100644 --- a/include/rdma/ib_umem.h +++ b/include/rdma/ib_umem.h @@ -32,6 +32,7 @@ struct ib_umem { struct ib_umem_dmabuf { struct ib_umem umem; struct dma_buf_attachment *attach; + struct dma_buf *dmabuf; struct sg_table *sgt; struct scatterlist *first_sg; struct scatterlist *last_sg; -- 2.17.1