From patchwork Mon Oct 7 22:15:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wei X-Patchwork-Id: 13825343 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) (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 19FE218E04E for ; Mon, 7 Oct 2024 22:16:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728339395; cv=none; b=C1pi3RKA0OXtdkVqYFYcYWa+Qd084kkXuKBKn5ey/B80/HfTEzWkIQ/xNNHAnWSACnL6o8yLmXhCRuGVJyxlufVcUrTtnbC7cCqZSEMJ7ZA+66XciVVwTOM9HIwLjTZXSCXjC5iy42D9lvKEEdtUabUc9H8eXtIMitBTRMf/x1k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728339395; c=relaxed/simple; bh=PzvHDCZ7021Z0HKhDmIQWr7NYdzsNljWLWXKZ7LyhwI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pyY6vifndb1X9ThX9jB2nBA1mtreDDLGanxcdCfD8kM9+fT6wQ+CydRzquxQe8AhzMtZr7miGiOAjfFfdL0uAzRQfGyPSk114DfzwqwPQH6dMS736fAuFDzK61Wi3pbLcRaxBcjj5rU6bfM4Zrz72UVU+RwRTN5d+XAB84sCzCU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=davidwei.uk; spf=none smtp.mailfrom=davidwei.uk; dkim=pass (2048-bit key) header.d=davidwei-uk.20230601.gappssmtp.com header.i=@davidwei-uk.20230601.gappssmtp.com header.b=AAMLnG2x; arc=none smtp.client-ip=209.85.215.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=davidwei.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=davidwei.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=davidwei-uk.20230601.gappssmtp.com header.i=@davidwei-uk.20230601.gappssmtp.com header.b="AAMLnG2x" Received: by mail-pg1-f171.google.com with SMTP id 41be03b00d2f7-7e9ad969a4fso3023337a12.3 for ; Mon, 07 Oct 2024 15:16:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=davidwei-uk.20230601.gappssmtp.com; s=20230601; t=1728339393; x=1728944193; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=T9pcBB36/ecxZhukt1XlNbWeZgVQ3rKv4Hy/wLZFefI=; b=AAMLnG2x+FkHGh/nWF9+ABrYdLcH0rqncL4q3Xk9JfT2yOVeLpQ9JYG86qSkCrojRG +El+lxnKMyA72pVUurfwJ5C/V76En9UK371eI6ktWt6WiQm+j93rLlan8YLK0RwQxHBL 9Imn1+txtA0JMqzWu59HBh2F0JwcHUq+rzpc6N01NapD67d9XCGcX0/ZkJjI7Si97p2N C7UjhS9n+Fj2MNNW803b+KE+epeswJCBOpYGvHynNV25DEArE8GWsJrPgxD6o/dkqgvk AxbWPKjD1QU49uFbLRJ47jIFv1MpPEAp9nFNcVlaVH10leH1VYi9qZKzO7BHcaP1kSvi C/xA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728339393; x=1728944193; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=T9pcBB36/ecxZhukt1XlNbWeZgVQ3rKv4Hy/wLZFefI=; b=gXCjskXGv4KXAiIvNPRQYy0SvL8Ox/v5pJUJg4B/JSyw4OZbuj0j4KWo9sKQIDxwnz l+jPhKfYJOhqg8v7xX0qncoEkvr+r/axhtXfVUd3zX41nE1TtUSYVKjCrDOXj3Tey0yS kUu4BkO/8nKG4baZsNCCk+bS7HuDmN+xasP5dr3aLguAq1R4bU7ZnPSBMB76N9SmH+Kt dl4neIkwWpMjJc2tAp8zZ9Kx9VosQrSUJS/R7Y9TvlJ+riqdxldH6jDOJi87sAIKjl8I 9iqDve8Yj+BJqHUdsqIaaHrdaQetNkR8XXNZ6D13qhXM+qehxAOFQf3WLlBNmFJ6i54F abrg== X-Forwarded-Encrypted: i=1; AJvYcCUO4CezqPBtgY9LErfFVZITeBiS+qQEcbG0eu6sWTJsZHbJzaAW9eAFMy/W7BnD0CrlL1t8R5k=@vger.kernel.org X-Gm-Message-State: AOJu0YwFl+7qBLpdHxYFikqF2dZpfDR3ea6HphP0FCx0eVuZZPmJVZWU i++M13h/eT9KKaqt9j+lZnYYnTuoa7VHuUErBG5o0sM2kjjqes3jjsSh5oAY0FqEwhHhwtKXFX6 w X-Google-Smtp-Source: AGHT+IETMvKxdjMQtaM8iuhPGelqYhvGKkMtsR+IfLNdg5zFQkOW4alFDxqcPGfPi/W8pkNtVtb7ew== X-Received: by 2002:a05:6a20:6f9c:b0:1d1:13de:68c6 with SMTP id adf61e73a8af0-1d6dfa406b7mr20127507637.29.1728339393417; Mon, 07 Oct 2024 15:16:33 -0700 (PDT) Received: from localhost (fwdproxy-prn-037.fbsv.net. [2a03:2880:ff:25::face:b00c]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71df0d7d02asm4887626b3a.197.2024.10.07.15.16.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Oct 2024 15:16:33 -0700 (PDT) From: David Wei To: io-uring@vger.kernel.org, netdev@vger.kernel.org Cc: David Wei , Jens Axboe , Pavel Begunkov , Jakub Kicinski , Paolo Abeni , "David S. Miller" , Eric Dumazet , Jesper Dangaard Brouer , David Ahern , Mina Almasry Subject: [PATCH v1 05/15] net: prepare for non devmem TCP memory providers Date: Mon, 7 Oct 2024 15:15:53 -0700 Message-ID: <20241007221603.1703699-6-dw@davidwei.uk> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241007221603.1703699-1-dw@davidwei.uk> References: <20241007221603.1703699-1-dw@davidwei.uk> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Pavel Begunkov There is a good bunch of places in generic paths assuming that the only page pool memory provider is devmem TCP. As we want to reuse the net_iov and provider infrastructure, we need to patch it up and explicitly check the provider type when we branch into devmem TCP code. Signed-off-by: Pavel Begunkov Signed-off-by: David Wei --- net/core/devmem.c | 4 ++-- net/core/page_pool_user.c | 15 +++++++++------ net/ipv4/tcp.c | 6 ++++++ 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/net/core/devmem.c b/net/core/devmem.c index 83d13eb441b6..b0733cf42505 100644 --- a/net/core/devmem.c +++ b/net/core/devmem.c @@ -314,10 +314,10 @@ void dev_dmabuf_uninstall(struct net_device *dev) unsigned int i; for (i = 0; i < dev->real_num_rx_queues; i++) { - binding = dev->_rx[i].mp_params.mp_priv; - if (!binding) + if (dev->_rx[i].mp_params.mp_ops != &dmabuf_devmem_ops) continue; + binding = dev->_rx[i].mp_params.mp_priv; xa_for_each(&binding->bound_rxqs, xa_idx, rxq) if (rxq == &dev->_rx[i]) { xa_erase(&binding->bound_rxqs, xa_idx); diff --git a/net/core/page_pool_user.c b/net/core/page_pool_user.c index 48335766c1bf..0d6cb7fb562c 100644 --- a/net/core/page_pool_user.c +++ b/net/core/page_pool_user.c @@ -214,7 +214,7 @@ static int page_pool_nl_fill(struct sk_buff *rsp, const struct page_pool *pool, const struct genl_info *info) { - struct net_devmem_dmabuf_binding *binding = pool->mp_priv; + struct net_devmem_dmabuf_binding *binding; size_t inflight, refsz; void *hdr; @@ -244,8 +244,11 @@ page_pool_nl_fill(struct sk_buff *rsp, const struct page_pool *pool, pool->user.detach_time)) goto err_cancel; - if (binding && nla_put_u32(rsp, NETDEV_A_PAGE_POOL_DMABUF, binding->id)) - goto err_cancel; + if (pool->mp_ops == &dmabuf_devmem_ops) { + binding = pool->mp_priv; + if (nla_put_u32(rsp, NETDEV_A_PAGE_POOL_DMABUF, binding->id)) + goto err_cancel; + } genlmsg_end(rsp, hdr); @@ -353,16 +356,16 @@ void page_pool_unlist(struct page_pool *pool) int page_pool_check_memory_provider(struct net_device *dev, struct netdev_rx_queue *rxq) { - struct net_devmem_dmabuf_binding *binding = rxq->mp_params.mp_priv; + void *mp_priv = rxq->mp_params.mp_priv; struct page_pool *pool; struct hlist_node *n; - if (!binding) + if (!mp_priv) return 0; mutex_lock(&page_pools_lock); hlist_for_each_entry_safe(pool, n, &dev->page_pools, user.list) { - if (pool->mp_priv != binding) + if (pool->mp_priv != mp_priv) continue; if (pool->slow.queue_idx == get_netdev_rx_queue_index(rxq)) { diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 5feef46426f4..2140fa1ec9f8 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -277,6 +277,7 @@ #include #include #include +#include #include #include @@ -2475,6 +2476,11 @@ static int tcp_recvmsg_dmabuf(struct sock *sk, const struct sk_buff *skb, } niov = skb_frag_net_iov(frag); + if (niov->pp->mp_ops != &dmabuf_devmem_ops) { + err = -ENODEV; + goto out; + } + end = start + skb_frag_size(frag); copy = end - offset;