Received: by 2002:ab2:3319:0:b0:1ef:7a0f:c32d with SMTP id i25csp311758lqc; Thu, 7 Mar 2024 19:58:51 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVzTH1H9woqWjfzbZ59wBAdG7173vhq/oAnThpLL7xgkd0Z6eZdCdm7MD1YxwazbG4BE7q7+FHRUuI6PxPwsMirKiIVB7y8wubPdU07DQ== X-Google-Smtp-Source: AGHT+IGzdauCRdEEm7gHjAoo2ddR5Uv10GqzomT7W5uV5Du014kiiQUofEW16vDTEZyhdxmSJU0U X-Received: by 2002:a2e:868b:0:b0:2d3:fb52:eb0f with SMTP id l11-20020a2e868b000000b002d3fb52eb0fmr2751433lji.34.1709870331633; Thu, 07 Mar 2024 19:58:51 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709870331; cv=pass; d=google.com; s=arc-20160816; b=nuC29EQy8PKuzdJFM03WQIwLZLuV/IahCI73QZmVyEJ0BydYzfDrGpUTSACPHDDhId Y13APT6R82sD9POw76wEGjD/UY2L5RMd/9HXaz0h6St1NKj4TevFp4CNIl0u2nViuGjI d21nnfpel9bop1f5W9KQqDnZbohEu6pgoOzpPfN4Aw1U82568EzgFyg5mP8rCcWfHTgP NJfOGHFWly7hAa8bITcEFMjkS+VURlrvZgk98jtzij/LhlNKCnMABw9Z6RohY/eLsbjL hArYXCNJnFISSqDAgxAgW+GsPxG3+zqBo0BJS1NeHnI1hvmlYIlyV4hzLD0UOS2RGuv3 M/IA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=u4R5X5jQ0ayQFQZu8wpyQceGBlFMgR9mKl4mXYNPId0=; fh=B1BtIOBOChwbeLy8Qxxy+ouVvXks4BqUpbQpFRQYws4=; b=HC0LhucymYMHED3IE6ryWmC5ZjtTVy7UDqoGOydwwsoBvbYAUsXm66mIYlLzGIUkh/ ZSyw/D15upgUP/TbY4CYO6H6/1Q1Wc4WnSVq65Ij7H/Z3wp7HMMkyTnXnf9fKwWzQEcG 7r3YK6sun/ryv0QyUOe+E5WH7MbFODVrX/H2t5KdBWDD2MHAubwQGNSjE9mIlmToquaf SOB+q/EuSZj15UiPPhEqIy8zNmc4Df/Yzhcf2Qk+y1GHDH9bytNTZfyfMrhkQcq5pnlL AAyEQiZcouOvwsTIWBem1jBB9AHZJBr4VY26lXojaoXVtoYA3e4OaV/KW9/KlqRBJCdW AtMg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZADXQRtg; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-96493-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-96493-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id p7-20020aa7c887000000b005680b18b8c9si1378209eds.225.2024.03.07.19.58.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Mar 2024 19:58:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-96493-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZADXQRtg; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-96493-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-96493-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 33D6B1F21F1F for ; Fri, 8 Mar 2024 03:58:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A105B2D052; Fri, 8 Mar 2024 03:58:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ZADXQRtg" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 820532C190; Fri, 8 Mar 2024 03:58:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709870312; cv=none; b=jE+T3TVAaPGExfSWnw0azJsuKJv6Bjo+gI36j3pWmCSKe4ARCHTLXDsgj4JP3sjbwK8SLd38XPcNSv/m2BuQducyNYDZyGxZIqXLlpcTcQHV0eD51T5mRDnSWpe85OIp17ysvLqxuQ7eE3KVPts7BGaS2Qw+ohIVEqxv59smoKo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709870312; c=relaxed/simple; bh=mF6Wbp6MtxfNFDHq0iHrXjjYNWZxisqag9vARhbWvOU=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=aKAPJFYD9DEFLLVE4606nXAd8E8OxP0B5e30PgkuP9WQk26yef/Lj4H8OIVd/PflCyZlyWEZjTE1w90LkK9HjdMXqCFyHZtOszITWqhhg0AhoR6QlXF0+tG/p8xz3o1k1FdFKCfWoCk1Y7RuhFuz2gwJu3tQ2IO6cXm9FwMgva4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZADXQRtg; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id BCA81C433F1; Fri, 8 Mar 2024 03:58:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709870312; bh=mF6Wbp6MtxfNFDHq0iHrXjjYNWZxisqag9vARhbWvOU=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=ZADXQRtggZVF7jCXRnr/Nx++UqGw2O1E+U/KttSTtzSSlM9bBjttGEo/A8hRic7ge O+gDFK9MJBHmJ2YDam/9YZE3gp0xxBazL1mTi5MDwug/eJk53dwV/etCOw6KZlAWuN 2i1Oe8pKYSCdgSopwQohIoatN4yPvCX5Cuzbnr/d5jvVAjw1Ie2U1uJLT8OtOKVyTs N5lwkQbIk4pRTkVTCTO3QA4II1m8BzPZ9ti7U330EoXvcxzor4u0v+kBt/tUSkRAKp tt8z4/H4M6CWk2MTdlJfmcAQM/5mZHnYRX7fG89CTjTzKp4ec7OLIdHAisaNLAPPMH kRchFPzFcbV0A== Date: Thu, 7 Mar 2024 19:58:28 -0800 From: Jakub Kicinski To: Mina Almasry Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-alpha@vger.kernel.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, sparclinux@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-arch@vger.kernel.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, "David S. Miller" , Eric Dumazet , Paolo Abeni , Jonathan Corbet , Richard Henderson , Ivan Kokshaysky , Matt Turner , Thomas Bogendoerfer , "James E.J. Bottomley" , Helge Deller , Andreas Larsson , Jesper Dangaard Brouer , Ilias Apalodimas , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Arnd Bergmann , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , David Ahern , Willem de Bruijn , Shuah Khan , Sumit Semwal , "Christian =?UTF-8?B?S8O2bmln?=" , Pavel Begunkov , David Wei , Jason Gunthorpe , Yunsheng Lin , Shailend Chand , Harshitha Ramamurthy , Shakeel Butt , Jeroen de Borst , Praveen Kaligineedi , Willem de Bruijn , Kaiyuan Zhang Subject: Re: [RFC PATCH net-next v6 05/15] netdev: support binding dma-buf to netdevice Message-ID: <20240307195828.183a76c2@kernel.org> In-Reply-To: <20240305020153.2787423-6-almasrymina@google.com> References: <20240305020153.2787423-1-almasrymina@google.com> <20240305020153.2787423-6-almasrymina@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Mon, 4 Mar 2024 18:01:40 -0800 Mina Almasry wrote: > + if (!dev || !dev->netdev_ops) > + return -EINVAL; too defensive > + if (!dev->netdev_ops->ndo_queue_stop || > + !dev->netdev_ops->ndo_queue_mem_free || > + !dev->netdev_ops->ndo_queue_mem_alloc || > + !dev->netdev_ops->ndo_queue_start) > + return -EOPNOTSUPP; > + > + new_mem = dev->netdev_ops->ndo_queue_mem_alloc(dev, rxq_idx); > + if (!new_mem) > + return -ENOMEM; > + > + err = dev->netdev_ops->ndo_queue_stop(dev, rxq_idx, &old_mem); > + if (err) > + goto err_free_new_mem; > + > + err = dev->netdev_ops->ndo_queue_start(dev, rxq_idx, new_mem); > + if (err) > + goto err_start_queue; > + > + dev->netdev_ops->ndo_queue_mem_free(dev, old_mem); nice :) > + rxq = __netif_get_rx_queue(dev, rxq_idx); > + > + if (rxq->binding) nit: a few places have an empty line between call and error check > + return -EEXIST; > + if (!capable(CAP_NET_ADMIN)) > + return -EPERM; this can be a flag on the netlink policy, no? flags: [ admin-perm ] on the op > + dmabuf = dma_buf_get(dmabuf_fd); > + if (IS_ERR_OR_NULL(dmabuf)) > + return -EBADFD; > + hdr = genlmsg_put(rsp, info->snd_portid, info->snd_seq, genlmsg_iput() > +static int netdev_netlink_notify(struct notifier_block *nb, unsigned long state, > + void *_notify) > +{ > + struct netlink_notify *notify = _notify; > + struct netdev_dmabuf_binding *rbinding; > + > + if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC) > + return NOTIFY_DONE; > + > + rtnl_lock(); > + > + list_for_each_entry(rbinding, &netdev_rbinding_list, list) { > + if (rbinding->owner_nlportid == notify->portid) { > + netdev_unbind_dmabuf(rbinding); > + break; > + } > + } > + > + rtnl_unlock(); > + > + return NOTIFY_OK; > +} While you were not looking we added three new members to the netlink family: * @sock_priv_size: the size of per-socket private memory * @sock_priv_init: the per-socket private memory initializer * @sock_priv_destroy: the per-socket private memory destructor You should be able to associate state with a netlink socket and have it auto-destroyed if the socket closes. LMK if that doesn't work for you, I was hoping it would fit nicely. I just realized now that the code gen doesn't know how to spit those members out, but I'll send a patch tomorrow, you can hack it manually until that gets in.