Received: by 2002:ab2:7a09:0:b0:1f8:46dc:890e with SMTP id k9csp124779lqo; Wed, 15 May 2024 09:20:00 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVhB971vNzL5zKTfkx9Ma+exanSU8XeD5G6W8NzOFMZz1AGmNRXq4OrczyUe+i9ubQHNBC8smpD2KZSX1/PKJngnsaryxyK9EadVfAvfQ== X-Google-Smtp-Source: AGHT+IEJD/666+qyxHdl55Dy/S+eUQuoRuxJ5lkp+vm28zOMxsdh5039fCc1JsdHvKgO5DthIQL4 X-Received: by 2002:a17:90b:1084:b0:2b8:5186:9cb7 with SMTP id 98e67ed59e1d1-2b851869d7bmr13014731a91.29.1715789999968; Wed, 15 May 2024 09:19:59 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715789999; cv=pass; d=google.com; s=arc-20160816; b=h3YYjTfHeNz2NQOWcZk5kgFy/vtbMeK4JT2yBieIPjamsm8m6/Jb/tL4+zH+PRM8C7 Ce/+jjkJQWgBmOsWQiSHa0P4p5iDGnPzQTbsUp8TGoHBvFdB1TEKqR2W74aCCw8Ctq1Y EuKDI3PvWAObSkRaJp8b5dKwv2er6jkyojN4RL7/jnAYjv1uK6trkhYTJV6K56gEHPqe SrG2BWvd9AZHPlJYzAc3ocGjIyierzP1I+O+/xG95dDgH62vzBVRwTKk9Y1OdU2HX5lI w8psvYknCRnHxF5THnoiGSBKeFus8FLfeYSIAbGQpc4gLcTutImHk4dao4aevb+7yhe+ FGqw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:from:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=fdHvJkxYgHA+IRrFREj5QbL1lv8V1e57nVmevFIQbVs=; fh=GUUvpOnCcvaQDecTFfpmE7NJp/grGwpOHU1gD62XIpE=; b=FBLYLQFg2SU7BAx1YmN86+lqET08a1yByrpD1DPcXnHSFes3MzamatG5UNOb91ZJQi AX68kbb9WRqCFmkgVLrinFBr3S4zShv3FdrU7MRtyyPOF0V7aBgQredlR3LzHDLTSPEo zHXdeWweh0e98vWj1/YJmcTqcXNreQPBr2+t0s87zrlNeaMRKYdc62iywbmi4WkZflLw 3G/lA05MnWZdptaegitKmNE1ZMhnwI8hcH8aXkHaHiIO9lADWWTSAwGkUy33Lpi0p28o Dg0FL6kK6Rb20Buli1gCIQNTuUBHB5cuhGyvjuuxhEDhH1yPLxv270/n6+qPn+JDjHoV /eUQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@blackwall-org.20230601.gappssmtp.com header.s=20230601 header.b=DK+gEtqm; arc=pass (i=1 dkim=pass dkdomain=blackwall-org.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-179757-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-179757-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 98e67ed59e1d1-2b670e32f76si12706314a91.36.2024.05.15.09.19.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 09:19:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-179757-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@blackwall-org.20230601.gappssmtp.com header.s=20230601 header.b=DK+gEtqm; arc=pass (i=1 dkim=pass dkdomain=blackwall-org.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-179757-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-179757-linux.lists.archive=gmail.com@vger.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 743C428582F for ; Wed, 15 May 2024 10:20:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8E648604CE; Wed, 15 May 2024 10:19:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=blackwall-org.20230601.gappssmtp.com header.i=@blackwall-org.20230601.gappssmtp.com header.b="DK+gEtqm" Received: from mail-ed1-f42.google.com (mail-ed1-f42.google.com [209.85.208.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 445F85FB8B for ; Wed, 15 May 2024 10:19:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715768395; cv=none; b=UFcMig6Di+PgfevAUMt8FDOT/KnE37FMA9i+0AUBapxaZQZRPydAvintxfC+xPeeWsSw9evw9ZUgBweYxpS7jB8QOk7wS67ykPeK+Bqx2T51ZMwFgm5UVWFZVeyamClcyuiy0SSzJpSyfJVJNL24Nk2Xqy96IwX+3K/JPE/l48Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715768395; c=relaxed/simple; bh=+EMK6b7qfktIFvrX/yoLCEmiPgCxTGiziO7yYK3P3rU=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=LHRwecfeBD6AYxEOvf2MGQYFmZSllmXGXXppMWmfVi6o5QNi8H4YsT8BOwrLYaDVGXWnD000Q2sAKSzokIw9TJrVv7R/kTf6DZhqXzNeSOALIz8G9h58K/I00Xi/+aVeHfcdV/kCGbHergfwIiAZeeFaYSgKPub52Kjt1Hoh0WE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=blackwall.org; spf=none smtp.mailfrom=blackwall.org; dkim=pass (2048-bit key) header.d=blackwall-org.20230601.gappssmtp.com header.i=@blackwall-org.20230601.gappssmtp.com header.b=DK+gEtqm; arc=none smtp.client-ip=209.85.208.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=blackwall.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=blackwall.org Received: by mail-ed1-f42.google.com with SMTP id 4fb4d7f45d1cf-56e69888a36so1432349a12.3 for ; Wed, 15 May 2024 03:19:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=blackwall-org.20230601.gappssmtp.com; s=20230601; t=1715768391; x=1716373191; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:from:subject:user-agent:mime-version:date:message-id:from:to :cc:subject:date:message-id:reply-to; bh=fdHvJkxYgHA+IRrFREj5QbL1lv8V1e57nVmevFIQbVs=; b=DK+gEtqmkb0jZ/CHh7UFa0VObjCqX95pEIy9AVKWg8R9+uBAQeX1wq1kySemn5w3pJ 0k9SCtvjvzqxKGOAZKIQaSUiQlw/2yQ4e13tjG9Q+SL1gECZK5IzNkOCLLXybSi6QDmr yUqNDnXq7FbT9kkRg3qgpIOdVsAmgeGaSzsfm2qyrDNgDJTa1YPWz8fhKcqKqGLu5lZu TaTYgVSAMqtgIczhmzHNK2pu1kQqag85ESBXKoX+eVPkXy2wAFkr9UQGJRkCh8bRVbnA Pbz/mZLWkbtj2rebXLzLoMhm+rQiiremoorBu9eXu0nPNa7FIhkhLZ6OLaoOfcZuNqtJ WOoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715768391; x=1716373191; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:from:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=fdHvJkxYgHA+IRrFREj5QbL1lv8V1e57nVmevFIQbVs=; b=GMZabEO+q2Mbd+bcTfHJLkaWpvtSxD3Qbw2K77VJFgITZxoKSp6AhCQzCa4zoq2kBW eowjMIUV9XzLq2KgpblNVTnGk2LPsd6soG18hSe3EP6bvgS1rk4HxlMvgfNYg19Z+zP9 eE76ZpieUSg42I/zy+svYlKWDi7qxiNoY1lDu14ihfj0FltjlD0W6lnOOGG67wOdOU4s h2hLLYvW97E3KRi546Dw8hrgwI71E1lBvw1eR0IIX3dENQaVQcloRx/X2vQjW7iEDN1k 1H04JmgkrC3emtmDyOG4+ZXu/gMi2++AJ2QQG2D6kAV7RYochVgpX/hLkMONYzumPoFH r5IA== X-Forwarded-Encrypted: i=1; AJvYcCVD3yXqSVQmfj+Yy8roDczRDImIQCm+edXlpmpeywYS9600yCvvTXwY2Y8jLFSHGaDnU72h/i+EyjUh2vM5CBo7YZr2yIRycjGqF6EW X-Gm-Message-State: AOJu0YzNs9vcR8gyY9HDCrOp8tjACk1lErFAsktQanMVgU/TdT1z5kEC CoI8GSg46H9EfHeZD6Obp86HChyFoSCo67EWLHvobMeBxwfY1Hu50AKTz5daeUs= X-Received: by 2002:a50:d59d:0:b0:572:7e7e:4296 with SMTP id 4fb4d7f45d1cf-5734d5c152dmr11481093a12.3.1715768391400; Wed, 15 May 2024 03:19:51 -0700 (PDT) Received: from [192.168.0.245] ([62.73.69.208]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-574b18dff66sm6291338a12.27.2024.05.15.03.19.48 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 15 May 2024 03:19:50 -0700 (PDT) Message-ID: Date: Wed, 15 May 2024 13:19:47 +0300 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH net-next v9 04/14] netdev: support binding dma-buf to netdevice From: Nikolay Aleksandrov To: Mina Almasry , 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 Cc: Donald Hunter , Jakub Kicinski , "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 , Steffen Klassert , Herbert Xu , David Ahern , Willem de Bruijn , Shuah Khan , Sumit Semwal , =?UTF-8?Q?Christian_K=C3=B6nig?= , Pavel Begunkov , David Wei , Jason Gunthorpe , Yunsheng Lin , Shailend Chand , Harshitha Ramamurthy , Shakeel Butt , Jeroen de Borst , Praveen Kaligineedi , Willem de Bruijn , Kaiyuan Zhang References: <20240510232128.1105145-1-almasrymina@google.com> <20240510232128.1105145-5-almasrymina@google.com> <59b1ec87-03dc-4336-8ce1-cb97e5abb7d6@blackwall.org> Content-Language: en-US In-Reply-To: <59b1ec87-03dc-4336-8ce1-cb97e5abb7d6@blackwall.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 15/05/2024 13:01, Nikolay Aleksandrov wrote: > On 11/05/2024 02:21, Mina Almasry wrote: >> Add a netdev_dmabuf_binding struct which represents the >> dma-buf-to-netdevice binding. The netlink API will bind the dma-buf to >> rx queues on the netdevice. On the binding, the dma_buf_attach >> & dma_buf_map_attachment will occur. The entries in the sg_table from >> mapping will be inserted into a genpool to make it ready >> for allocation. >> >> The chunks in the genpool are owned by a dmabuf_chunk_owner struct which >> holds the dma-buf offset of the base of the chunk and the dma_addr of >> the chunk. Both are needed to use allocations that come from this chunk. >> >> We create a new type that represents an allocation from the genpool: >> net_iov. We setup the net_iov allocation size in the >> genpool to PAGE_SIZE for simplicity: to match the PAGE_SIZE normally >> allocated by the page pool and given to the drivers. >> >> The user can unbind the dmabuf from the netdevice by closing the netlink >> socket that established the binding. We do this so that the binding is >> automatically unbound even if the userspace process crashes. >> >> The binding and unbinding leaves an indicator in struct netdev_rx_queue >> that the given queue is bound, but the binding doesn't take effect until >> the driver actually reconfigures its queues, and re-initializes its page >> pool. >> >> The netdev_dmabuf_binding struct is refcounted, and releases its >> resources only when all the refs are released. >> >> Signed-off-by: Willem de Bruijn >> Signed-off-by: Kaiyuan Zhang >> Signed-off-by: Mina Almasry >> >> --- >> >> v9: https://lore.kernel.org/all/20240403002053.2376017-5-almasrymina@google.com/ >> - Removed net_devmem_restart_rx_queues and put it in its own patch >> (David). >> >> v8: >> - move dmabuf_devmem_ops usage to later patch to avoid patch-by-patch >> build error. >> >> v7: >> - Use IS_ERR() instead of IS_ERR_OR_NULL() for the dma_buf_get() return >> value. >> - Changes netdev_* naming in devmem.c to net_devmem_* (Yunsheng). >> - DMA_BIDIRECTIONAL -> DMA_FROM_DEVICE (Yunsheng). >> - Added a comment around recovering of the old rx queue in >> net_devmem_restart_rx_queue(), and added freeing of old_mem if the >> restart of the old queue fails. (Yunsheng). >> - Use kernel-family sock-priv (Jakub). >> - Put pp_memory_provider_params in netdev_rx_queue instead of the >> dma-buf specific binding (Pavel & David). >> - Move queue management ops to queue_mgmt_ops instead of netdev_ops >> (Jakub). >> - Remove excess whitespaces (Jakub). >> - Use genlmsg_iput (Jakub). >> >> v6: >> - Validate rx queue index >> - Refactor new functions into devmem.c (Pavel) >> >> v5: >> - Renamed page_pool_iov to net_iov, and moved that support to devmem.h >> or netmem.h. >> >> v1: >> - Introduce devmem.h instead of bloating netdevice.h (Jakub) >> - ENOTSUPP -> EOPNOTSUPP (checkpatch.pl I think) >> - Remove unneeded rcu protection for binding->list (rtnl protected) >> - Removed extraneous err_binding_put: label. >> - Removed dma_addr += len (Paolo). >> - Don't override err on netdev_bind_dmabuf_to_queue failure. >> - Rename devmem -> dmabuf (David). >> - Add id to dmabuf binding (David/Stan). >> - Fix missing xa_destroy bound_rq_list. >> - Use queue api to reset bound RX queues (Jakub). >> - Update netlink API for rx-queue type (tx/re) (Jakub). >> >> RFC v3: >> - Support multi rx-queue binding >> >> --- >> Documentation/netlink/specs/netdev.yaml | 4 + >> include/net/devmem.h | 111 +++++++++++ >> include/net/netdev_rx_queue.h | 2 + >> include/net/netmem.h | 10 + >> include/net/page_pool/types.h | 5 + >> net/core/Makefile | 2 +- >> net/core/dev.c | 3 + >> net/core/devmem.c | 254 ++++++++++++++++++++++++ >> net/core/netdev-genl-gen.c | 4 + >> net/core/netdev-genl-gen.h | 4 + >> net/core/netdev-genl.c | 105 +++++++++- >> 11 files changed, 501 insertions(+), 3 deletions(-) >> create mode 100644 include/net/devmem.h >> create mode 100644 net/core/devmem.c >> > [snip] >> +/* Protected by rtnl_lock() */ >> +static DEFINE_XARRAY_FLAGS(net_devmem_dmabuf_bindings, XA_FLAGS_ALLOC1); >> + >> +void net_devmem_unbind_dmabuf(struct net_devmem_dmabuf_binding *binding) >> +{ >> + struct netdev_rx_queue *rxq; >> + unsigned long xa_idx; >> + unsigned int rxq_idx; >> + >> + if (!binding) >> + return; >> + >> + if (binding->list.next) >> + list_del(&binding->list); >> + > > minor nit: > In theory list.next can still be != null if it's poisoned (e.g. after del). You can > use the list api here (!list_empty(&binding->list) -> list_del_init(&binding->list)) > if you initialize it in net_devmem_bind_dmabuf(), then you'll also get nice list > debugging. > On second thought nevermind this, sorry for the noise. >> + xa_for_each(&binding->bound_rxq_list, xa_idx, rxq) { >> + if (rxq->mp_params.mp_priv == binding) { >> + /* We hold the rtnl_lock while binding/unbinding >> + * dma-buf, so we can't race with another thread that >> + * is also modifying this value. However, the page_pool >> + * may read this config while it's creating its >> + * rx-queues. WRITE_ONCE() here to match the >> + * READ_ONCE() in the page_pool. >> + */ >> + WRITE_ONCE(rxq->mp_params.mp_ops, NULL); >> + WRITE_ONCE(rxq->mp_params.mp_priv, NULL); >> + >> + rxq_idx = get_netdev_rx_queue_index(rxq); >> + >> + netdev_rx_queue_restart(binding->dev, rxq_idx); >> + } >> + } >> + >> + xa_erase(&net_devmem_dmabuf_bindings, binding->id); >> + >> + net_devmem_dmabuf_binding_put(binding); >> +} > [snip] > > Cheers, > Nik >