Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2338549pxb; Fri, 17 Sep 2021 07:39:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw210+p5vLLqIa659A8nNCaTZNVMzDeBiiTFj2AoPn+bHVITMHCWDdUCimgp1814tPJHx6/ X-Received: by 2002:a5d:8588:: with SMTP id f8mr8929015ioj.46.1631889593997; Fri, 17 Sep 2021 07:39:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631889593; cv=none; d=google.com; s=arc-20160816; b=B0Ciwa4uQiIqTGOJ/louq7Ggl1x75D5XCTRqpbUgNeuZJ7XSOzzdpNohaSKolVAv+S Ui8RdItmVG9A3N0dqcZE+y/B0aGjLObOyzfX3u7Anu2O3fP8L7X8yAkpjK6w+3fhgh5Y myOr6UEhfA2+WzOpcdEvj0vnu3LeDuPwcO86Kq0xAtTC6JqzEj4YPGTyTltSCVIf3JcY ho7RE4uO1pDSzqJR3UshfeMzQBe8OvyorZ6pgHV4Fech9THb/DNCzaBvyI8vLo/cKUaP o8Su+29PDe/13SjeX3gGN6SyrbOCQsBAYspB5egIM3OQh8GtzKx39USyBrmP4PkiYND7 14ag== 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:mail-followup-to:message-id:subject:cc:to:from:date :dkim-signature; bh=ohehD+AgX2cOYuT0Vdlc+XEexxlJP7h+rPjbbPGV0JI=; b=t3uVGvHzrargJ7sewzM9qM82o+B2b3080NFAgH++CbS0ppu0Y3SPojdC6fYaLcQp3W lCAnmdGdhv6rlY+GqFAF8fnFGQM34XYEJHXaWwVOpW7ZDF0R3EBGTAVYnW57QE83/l03 542CeWY+HrI04LcbPhQ+8TQQJtIRW2KfgxHmNL8CeiqscHKVIMbP/x+dGlhOzd7s4Jow 6MAIPK+lTERNWaOICZsPyAiDidiRFSdveaXgQGsjsgxYF4xP4eZ0/jb5YpF0eMELzxUs 8Bys8xGJbQkisIM0Gr2LOtHEPATqOF/crUeS4xjZb6+2DsL2dugjJtbV5NdCShbjKRaI QKSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=R10SS4VV; 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 h15si5400674jaa.28.2021.09.17.07.39.41; Fri, 17 Sep 2021 07:39:53 -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=R10SS4VV; 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 S231237AbhIQMb3 (ORCPT + 99 others); Fri, 17 Sep 2021 08:31:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232338AbhIQMb1 (ORCPT ); Fri, 17 Sep 2021 08:31:27 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 576A3C061764 for ; Fri, 17 Sep 2021 05:30:04 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id d6so14842714wrc.11 for ; Fri, 17 Sep 2021 05:30:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to; bh=ohehD+AgX2cOYuT0Vdlc+XEexxlJP7h+rPjbbPGV0JI=; b=R10SS4VV0BCpiZybmOMrjaWEfv3d2ZD+2k6TYKYqIZCusUIZXiqYs5rTuV6bruYLls zYGmlZhSOPyZgErxGr8GftAAzypBiEQnXw94kdl46vb10zeP8O7zkrXWklJipXggLivr Ihoa4mj+eAbhnzb6QO020N9VvyKryVDicfnPg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :in-reply-to; bh=ohehD+AgX2cOYuT0Vdlc+XEexxlJP7h+rPjbbPGV0JI=; b=T3tzlPPWn4V8wTdvH0ax/J43kEsXoTPY+u0/TmbcJel2i3CrM/2Jg2/RwvlpuKGxdx /X+h5Bz6LcSxw28jD+UhNHxzJ/UUJ3x0/vX/CsPPMtpeUkguiXVS5Zm9tJAiRgjMv61A ovYa1iX7Rn8kPhmBSf8KxUCpafBVcVfik5nHmVwAq1+TP3M+4y8CegLPPQjc5xPZ3NC8 ng8vNHLmWpl6XlcBRW/1IVHkWI30dKyZHNYDe2byxJ1Hy3DTEidaQn2WQMjdfPHr/89v Cr+ISbj2Sa9scpkz6wwHadGrAMzMIwjeTf8SR0tvVEXVQ4OF2jOKGSlqbE9yefLEcyK9 bGyQ== X-Gm-Message-State: AOAM5314yqZqOADUY16louN8hII7JH047SAXqMZ2GabSQz5I8BVuGLY9 SlB+dvCbkCJWJRkFhuRROwjA2Q== X-Received: by 2002:a05:6000:124b:: with SMTP id j11mr11906176wrx.147.1631881802837; Fri, 17 Sep 2021 05:30:02 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id z6sm6483202wmp.1.2021.09.17.05.30.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Sep 2021 05:30:02 -0700 (PDT) Date: Fri, 17 Sep 2021 14:30:00 +0200 From: Daniel Vetter To: Jason Gunthorpe Cc: Oded Gabbay , "Linux-Kernel@Vger. Kernel. Org" , Greg Kroah-Hartman , Christian =?iso-8859-1?Q?K=F6nig?= , Gal Pressman , Yossi Leybovich , Maling list - DRI developers , linux-rdma , Linux Media Mailing List , Doug Ledford , Dave Airlie , Alex Deucher , Leon Romanovsky , Christoph Hellwig , amd-gfx list , "moderated list:DMA BUFFER SHARING FRAMEWORK" Subject: Re: [PATCH v6 0/2] Add p2p via dmabuf to habanalabs Message-ID: Mail-Followup-To: Jason Gunthorpe , Oded Gabbay , "Linux-Kernel@Vger. Kernel. Org" , Greg Kroah-Hartman , Christian =?iso-8859-1?Q?K=F6nig?= , Gal Pressman , Yossi Leybovich , Maling list - DRI developers , linux-rdma , Linux Media Mailing List , Doug Ledford , Dave Airlie , Alex Deucher , Leon Romanovsky , Christoph Hellwig , amd-gfx list , "moderated list:DMA BUFFER SHARING FRAMEWORK" References: <20210912165309.98695-1-ogabbay@kernel.org> <20210914161218.GF3544071@ziepe.ca> <20210916131014.GK3544071@ziepe.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210916131014.GK3544071@ziepe.ca> X-Operating-System: Linux phenom 5.10.0-8-amd64 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 16, 2021 at 10:10:14AM -0300, Jason Gunthorpe wrote: > On Thu, Sep 16, 2021 at 02:31:34PM +0200, Daniel Vetter wrote: > > On Wed, Sep 15, 2021 at 10:45:36AM +0300, Oded Gabbay wrote: > > > On Tue, Sep 14, 2021 at 7:12 PM Jason Gunthorpe wrote: > > > > > > > > On Tue, Sep 14, 2021 at 04:18:31PM +0200, Daniel Vetter wrote: > > > > > On Sun, Sep 12, 2021 at 07:53:07PM +0300, Oded Gabbay wrote: > > > > > > Hi, > > > > > > Re-sending this patch-set following the release of our user-space TPC > > > > > > compiler and runtime library. > > > > > > > > > > > > I would appreciate a review on this. > > > > > > > > > > I think the big open we have is the entire revoke discussions. Having the > > > > > option to let dma-buf hang around which map to random local memory ranges, > > > > > without clear ownership link and a way to kill it sounds bad to me. > > > > > > > > > > I think there's a few options: > > > > > - We require revoke support. But I've heard rdma really doesn't like that, > > > > > I guess because taking out an MR while holding the dma_resv_lock would > > > > > be an inversion, so can't be done. Jason, can you recap what exactly the > > > > > hold-up was again that makes this a no-go? > > > > > > > > RDMA HW can't do revoke. > > > > Like why? I'm assuming when the final open handle or whatever for that MR > > is closed, you do clean up everything? Or does that MR still stick around > > forever too? > > It is a combination of uAPI and HW specification. > > revoke here means you take a MR object and tell it to stop doing DMA > without causing the MR object to be destructed. > > All the drivers can of course destruct the MR, but doing such a > destruction without explicit synchronization with user space opens > things up to a serious use-after potential that could be a security > issue. > > When the open handle closes the userspace is synchronized with the > kernel and we can destruct the HW objects safely. > > So, the special HW feature required is 'stop doing DMA but keep the > object in an error state' which isn't really implemented, and doesn't > extend very well to other object types beyond simple MRs. Yeah revoke without destroying the MR doesn't work, and it sounds like revoke by destroying the MR just moves the can of worms around to another place. > > 1. User A opens gaudi device, sets up dma-buf export > > > > 2. User A registers that with RDMA, or anything else that doesn't support > > revoke. > > > > 3. User A closes gaudi device > > > > 4. User B opens gaudi device, assumes that it has full control over the > > device and uploads some secrets, which happen to end up in the dma-buf > > region user A set up > > I would expect this is blocked so long as the DMABUF exists - eg the > DMABUF will hold a fget on the FD of #1 until the DMABUF is closed, so > that #3 can't actually happen. > > > It's not mlocked memory, it's mlocked memory and I can exfiltrate > > it. > > That's just bug, don't make buggy drivers :) Well yeah, but given that habanalabs hand rolled this I can't just check for the usual things we have to enforce this in drm. And generally you can just open chardevs arbitrarily, and multiple users fighting over each another. The troubles only start when you have private state or memory allocations of some kind attached to the struct file (instead of the underlying device), or something else that requires device exclusivity. There's no standard way to do that. Plus in many cases you really want revoke on top (can't get that here unfortunately it seems), and the attempts to get towards a generic revoke() just never went anywhere. So again it's all hand-rolled per-subsystem. *insert lament about us not having done this through a proper subsystem* Anyway it sounds like the code takes care of that. -Daniel -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch