Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3733388pxj; Mon, 21 Jun 2021 05:29:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwHp2W3ZZYxTZgXkDE4xePveD4BOQXs/U30jvhXlwY21BnJPWRzecvfx7IhCOMfuPDx9uar X-Received: by 2002:a92:b74b:: with SMTP id c11mr9887196ilm.246.1624278588200; Mon, 21 Jun 2021 05:29:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624278588; cv=none; d=google.com; s=arc-20160816; b=dnKgSKEM0KQ8Qm6NzGpUor3aeXiIYr65t8FQnQYpbhwGch/VlZP0FcbJBqJ0fjfmeE J2iB3A1ROQj8yeX3WdLztckdwWYBjTPqPcKLpg++flP46Kwio6SPvPftnjJ6QqbbAZr+ 5zN+ODTTR36nWaA/jyzR16AcwlsNLULy7Kdsr+fuq2vXx5GbIpvCUQRa5q0Tzgin3USv LBnbMKnCSzdqhbSq+42ld3ieyuAWsK6sSqij8kOB0Z/x7Wf4bBFxlbXZgYjdrAJsQUL8 IZOddAuoD81EN7a0a5jGTkv31r7Nab019J8DUbotW2RWRMLgP6DER40WjflQor8W2KgA ztoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=HHQC6lOkJEn8B4ZK4mW/HBR6aX7M4uga90R1ZErZgKw=; b=MT/+HqcTsLJAMrzs/JFNx1RSL1xAdS8LwLzZtfkFvUEfhzDLa/CpdxmDWFjfOiSHXk Aup8FsLpLstcT8x0BAy8AUnFVIg1I9a8uAb9UX+9nFitJQqubKO3VgPpqZFz2YwEio4F R7/WZtBJ9tqeMJ8/PCHPozpZSqb8x99SHSw+uc1TK/Be8R+bTQIareKWkYpxrLFHhCNQ rDjapLwjGq0jBp/qwBZpUPOekjTHBSZ6aCFcPnjP1qTzwkrHi3tM1Ya1OqSKC08CZnhq lK7KpilgH0EMwomTnR1CqPYFCxpnl8K6RZcrROgTfoIYdd62Td7FyiFyIJFExw7yhtDV cFbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=Td38oUyS; 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 y5si14233094ilu.5.2021.06.21.05.29.35; Mon, 21 Jun 2021 05:29:48 -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=@ffwll.ch header.s=google header.b=Td38oUyS; 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 S229747AbhFUMbP (ORCPT + 99 others); Mon, 21 Jun 2021 08:31:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229699AbhFUMbO (ORCPT ); Mon, 21 Jun 2021 08:31:14 -0400 Received: from mail-ot1-x32c.google.com (mail-ot1-x32c.google.com [IPv6:2607:f8b0:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C708DC061756 for ; Mon, 21 Jun 2021 05:28:59 -0700 (PDT) Received: by mail-ot1-x32c.google.com with SMTP id h24-20020a9d64180000b029036edcf8f9a6so17538664otl.3 for ; Mon, 21 Jun 2021 05:28:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=HHQC6lOkJEn8B4ZK4mW/HBR6aX7M4uga90R1ZErZgKw=; b=Td38oUyS/9/MPrT4jo5WsEx4w0MWOF/8bM1XyUzvOBwwzScRQorv0t2fw+zHCf7ir0 h8zpP6oNobDqmDV0rX43vwv23S4wvsx20o1++gTR06+eOXnxOdhaB+3kQbyaZz/2S0tV GQVwEXVWhC4IEfs607x4fPCPD20Mejq78fTdQ= 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=HHQC6lOkJEn8B4ZK4mW/HBR6aX7M4uga90R1ZErZgKw=; b=an+PLT7uy98BR1y563dZJezYprGEqKttccUG1tvmaQ9Lff9Dik5gOaGyN7GAVcksE/ d7wiDnG6coRHRfd/c+3GiMG9tiyJ4qbLy46wWBWmRpJ3FQbSeTGWxQE6PeXdcBm4z3M1 guJ85egov2mmwY+BKeSy4Rd16+jlnBIv50TAjzmdSbi8yXTnR9ZzLurMJMQKw04be+Tv advWeA6bzqs8dX2EfrXikr0eovLCp/2RNnsuoMTS/rfSaTRViDTnw2ytP1MRMNas3GJA 9/sQ98yW/cM06B2jWrdmvQe6TqdeDyw3jNcNVwElYyyVJabkS5/Km7F1Cf/3JtCpNfWq JfHQ== X-Gm-Message-State: AOAM531jivx7sU2QlOlKHFFPlHy7cxwBFj0+r0kA2JrLd6oFqz6pkGDC 89NJ0RaSr/NPuN+Nku0xkY/UJ26jbEUlPBvgzcriUg== X-Received: by 2002:a9d:12eb:: with SMTP id g98mr20269296otg.303.1624278539116; Mon, 21 Jun 2021 05:28:59 -0700 (PDT) MIME-Version: 1.0 References: <20210618123615.11456-1-ogabbay@kernel.org> In-Reply-To: <20210618123615.11456-1-ogabbay@kernel.org> From: Daniel Vetter Date: Mon, 21 Jun 2021 14:28:48 +0200 Message-ID: Subject: Re: [PATCH v3 1/2] habanalabs: define uAPI to export FD for DMA-BUF To: Oded Gabbay , Jason Gunthorpe , linux-rdma , "open list:DMA BUFFER SHARING FRAMEWORK" , Doug Ledford , "airlied@gmail.com" Cc: Linux Kernel Mailing List , Greg KH , Sumit Semwal , =?UTF-8?Q?Christian_K=C3=B6nig?= , Gal Pressman , sleybo@amazon.com, dri-devel , Tomer Tayar , "moderated list:DMA BUFFER SHARING FRAMEWORK" , amd-gfx list , Alex Deucher , Leon Romanovsky , Christoph Hellwig Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 18, 2021 at 2:36 PM Oded Gabbay wrote: > User process might want to share the device memory with another > driver/device, and to allow it to access it over PCIe (P2P). > > To enable this, we utilize the dma-buf mechanism and add a dma-buf > exporter support, so the other driver can import the device memory and > access it. > > The device memory is allocated using our existing allocation uAPI, > where the user will get a handle that represents the allocation. > > The user will then need to call the new > uAPI (HL_MEM_OP_EXPORT_DMABUF_FD) and give the handle as a parameter. > > The driver will return a FD that represents the DMA-BUF object that > was created to match that allocation. > > Signed-off-by: Oded Gabbay > Reviewed-by: Tomer Tayar Mission acomplished, we've gone full circle, and the totally-not-a-gpu driver is now trying to use gpu infrastructure. And seems to have gained vram meanwhile too. Next up is going to be synchronization using dma_fence so you can pass buffers back&forth without stalls among drivers. Bonus points for this being at v3 before it shows up on dri-devel and cc's dma-buf folks properly (not quite all, I added the missing people). I think we roughly have two options here a) Greg continues to piss off dri-devel folks while trying to look cute&cuddly and steadfastly claiming that this accelator doesn't work like any of the other accelerator drivers we have in drivers/gpu/drm. All while the driver ever more looks like one of these other accel drivers. b) We finally do what we should have done years back and treat this as a proper driver submission and review it on dri-devel instead of sneaking it in through other channels because the merge criteria dri-devel has are too onerous and people who don't have experience with accel stacks for the past 20 years or so don't like them. "But this probably means a new driver and big disruption!" Not my problem, I'm not the dude who has to come up with an excuse for this because I didn't merge the driver in the first place. I do get to throw a "we all told you so" in though, but that's not helping. Also I'm wondering which is the other driver that we share buffers with. The gaudi stuff doesn't have real struct pages as backing storage, it only fills out the dma_addr_t. That tends to blow up with other drivers, and the only place where this is guaranteed to work is if you have a dynamic importer which sets the allow_peer2peer flag. Adding maintainers from other subsystems who might want to chime in here. So even aside of the big question as-is this is broken. Currently only 2 drivers set allow_peer2peer, so those are the only ones who can consume these buffers from device memory. Pinging those folks specifically. Doug/Jason from infiniband: Should we add linux-rdma to the dma-buf wildcard match so that you can catch these next time around too? At least when people use scripts/get_maintainers.pl correctly. All the other subsystems using dma-buf are on there already (dri-devel, linux-media and linaro-mm-sig for android/arm embedded stuff). Cheers, Daniel > --- > include/uapi/misc/habanalabs.h | 28 +++++++++++++++++++++++++++- > 1 file changed, 27 insertions(+), 1 deletion(-) > > diff --git a/include/uapi/misc/habanalabs.h b/include/uapi/misc/habanalabs.h > index a47a731e4527..aa3d8e0ba060 100644 > --- a/include/uapi/misc/habanalabs.h > +++ b/include/uapi/misc/habanalabs.h > @@ -808,6 +808,10 @@ union hl_wait_cs_args { > #define HL_MEM_OP_UNMAP 3 > /* Opcode to map a hw block */ > #define HL_MEM_OP_MAP_BLOCK 4 > +/* Opcode to create DMA-BUF object for an existing device memory allocation > + * and to export an FD of that DMA-BUF back to the caller > + */ > +#define HL_MEM_OP_EXPORT_DMABUF_FD 5 > > /* Memory flags */ > #define HL_MEM_CONTIGUOUS 0x1 > @@ -878,11 +882,26 @@ struct hl_mem_in { > /* Virtual address returned from HL_MEM_OP_MAP */ > __u64 device_virt_addr; > } unmap; > + > + /* HL_MEM_OP_EXPORT_DMABUF_FD */ > + struct { > + /* Handle returned from HL_MEM_OP_ALLOC. In Gaudi, > + * where we don't have MMU for the device memory, the > + * driver expects a physical address (instead of > + * a handle) in the device memory space. > + */ > + __u64 handle; > + /* Size of memory allocation. Relevant only for GAUDI */ > + __u64 mem_size; > + } export_dmabuf_fd; > }; > > /* HL_MEM_OP_* */ > __u32 op; > - /* HL_MEM_* flags */ > + /* HL_MEM_* flags. > + * For the HL_MEM_OP_EXPORT_DMABUF_FD opcode, this field holds the > + * DMA-BUF file/FD flags. > + */ > __u32 flags; > /* Context ID - Currently not in use */ > __u32 ctx_id; > @@ -919,6 +938,13 @@ struct hl_mem_out { > > __u32 pad; > }; > + > + /* Returned in HL_MEM_OP_EXPORT_DMABUF_FD. Represents the > + * DMA-BUF object that was created to describe a memory > + * allocation on the device's memory space. The FD should be > + * passed to the importer driver > + */ > + __u64 fd; > }; > }; > > -- > 2.25.1 > -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch