From patchwork Thu Jan 16 23:16:43 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wei X-Patchwork-Id: 13942445 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 0D8521DC98C for ; Thu, 16 Jan 2025 23:17:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737069433; cv=none; b=epzbTGPEo+68+kIHEvQyyTWfedcvy/xTe/95Vz8VdVnUbqocnR5H72da/COtty5u7BHE8WCPy5aZPpXeapub20vTWTzPc3R67orVI97L20jJ01HEp+ksy1J0fknT3fVNU9vhL7MKOMJpra2AerAmGl7q3YBRIEMxMbmUwnsV188= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737069433; c=relaxed/simple; bh=RN9FRieTmgxqv0c+YKrWG+l7gQJLp/gap7HunHQoqkE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GZhI7iEzc/T4Ql9r4vCuzw1RBvfHILQFLSC9P7eSdVx0bAhWTshqyH8+ZzodNLLcJl2mMgjVlrcO0jLI0cijRzkVp7UyFZdUk6cSzZMDy+9ZPM2qFnAzGxnPVtSOef2mdgu4apy13Sol3TZyXjA4j8XAdysJn6JYvL1/FN4yzxU= 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=od2ha1vm; arc=none smtp.client-ip=209.85.214.181 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="od2ha1vm" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-21654fdd5daso25847465ad.1 for ; Thu, 16 Jan 2025 15:17:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=davidwei-uk.20230601.gappssmtp.com; s=20230601; t=1737069431; x=1737674231; 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=4BJhQIF+q/BdwFZrWY61E+04UcDJKhF4LPhTAqO37Wg=; b=od2ha1vmCSnx2GPPc2VFpwBis9SehbZGYgEg6D85/YltIu0aibdL6cNBMudEYe26bu lSpXNQWqzWFRzYELuLvWX0CI4yECAoWWdFHisB5IJr6YAZfKfe4+poXBL/iGjjAjDFAr jxvdlxgnRKbNe8xaDmSecDKkf4TlPxD1cpQ7PFHC0maccd1URseX3xXKRY+8q4IsgsBs X9Q8WyqcVCRMwk1L36ewZ/IzGRYI5qeEsUapwjx97KwZukrAQZ719vy9v0lzkYodxiRz JFHO1paHwBENbRoqAHROPdYMf+a84V2+NFuQklf6jBZI6pOk0/Yz1bt79xNNfZBE+Go+ B5YA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737069431; x=1737674231; 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=4BJhQIF+q/BdwFZrWY61E+04UcDJKhF4LPhTAqO37Wg=; b=p6SutnsOBbE+LbrgSBmdCYIemuwZhLtV6u5lk+lr0NBiEmAVwgelNy2bW2mOECbM/O k5PpfhsCe/RagumMkDkXgQbQdZ5cHOwwHBCR4P9EtksOYvlgay9ZO+f+QbGt4za0Mdpy uXZmKC8OdrvuKrn1Vy4j7jI52gAZXnZ+aSJw/pCbYjEaUgiY2meWV7SI+CPfWjv3gJAF lqhUttVVrQOwh0dsQtQd2hWBZpQ23dVveP3Dboc2sKDPdXbnl5fCXrga/cnnpYNJIy1N hZPs3QWg3xXHu5THgEmi0bwmkY5VM8PsfkI6Du21uJIF5NnW54zLr5Sit9VHIvd8qDNO d6DQ== X-Forwarded-Encrypted: i=1; AJvYcCXlEZ6sJTlhL2ivx3KlZ2VLJgbKnM7eOvZOUM11m65tS/yysQNdUU8ORYZb15k+ccbCzFtFet4=@vger.kernel.org X-Gm-Message-State: AOJu0Yxx0SUEus+sSvzzWnd3+fQ8gxSOV2Mk1jbG2BK+INV5nWVDIvcG FjxvCjfF75N0qmpBpANSs8Kn9eWMIJVBCITSKHUXUcPSA0yhViDgbiU5D6wHDa8= X-Gm-Gg: ASbGncvpa8fTjRX8+hNqFlBbjLlqEqSDF7oLVMukPeGKTkDuy6a3InPRvTcM07KFi60 Oyh+XuvsUeZPv3Y/VvOFDB+kll9McPu5vS9T695BgiTdQY2WOgUAY4i9GBgPlBGlqY7eL2Wqv3M TW6HL9xf7k37V6G/cmRdavtje6G1Mqtw5lqQp2xAgJdZvbH1aDF933UqMGl9myGogIJGqxiRlDU ncoLAK9ya1ULLRdeukv7GrGb2SpQwzNmtjS+AbXRw== X-Google-Smtp-Source: AGHT+IE+7rz3+FtLlOzp302hQQdyqhKM3dH46xWgJ2OQJD08zD8IPa2x4VJMSn0MPslS5ttQnIdHyQ== X-Received: by 2002:a17:903:244d:b0:215:b5c6:9ed3 with SMTP id d9443c01a7336-21c353e4d1emr10178125ad.12.1737069431391; Thu, 16 Jan 2025 15:17:11 -0800 (PST) Received: from localhost ([2a03:2880:ff:1c::]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21c2d3ac461sm4986015ad.112.2025.01.16.15.17.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jan 2025 15:17:11 -0800 (PST) From: David Wei To: io-uring@vger.kernel.org, netdev@vger.kernel.org Cc: Jens Axboe , Pavel Begunkov , Jakub Kicinski , Paolo Abeni , "David S. Miller" , Eric Dumazet , Jesper Dangaard Brouer , David Ahern , Mina Almasry , Stanislav Fomichev , Joe Damato , Pedro Tammela Subject: [PATCH net-next v11 01/21] net: page_pool: don't cast mp param to devmem Date: Thu, 16 Jan 2025 15:16:43 -0800 Message-ID: <20250116231704.2402455-2-dw@davidwei.uk> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250116231704.2402455-1-dw@davidwei.uk> References: <20250116231704.2402455-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 page_pool_check_memory_provider() is a generic path and shouldn't assume anything about the actual type of the memory provider argument. It's fine while devmem is the only provider, but cast away the devmem specific binding types to avoid confusion. Reviewed-by: Jakub Kicinski Reviewed-by: Mina Almasry Signed-off-by: Pavel Begunkov Signed-off-by: David Wei --- net/core/page_pool_user.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/core/page_pool_user.c b/net/core/page_pool_user.c index 48335766c1bf..8d31c71bea1a 100644 --- a/net/core/page_pool_user.c +++ b/net/core/page_pool_user.c @@ -353,7 +353,7 @@ 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 *binding = rxq->mp_params.mp_priv; struct page_pool *pool; struct hlist_node *n; From patchwork Thu Jan 16 23:16:44 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wei X-Patchwork-Id: 13942446 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (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 E860C1DDC0F for ; Thu, 16 Jan 2025 23:17:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737069434; cv=none; b=t/lrX8ncFUSEF6FeTzB5MAlTwtgNDH2+uCBwinuDhfkhxDEX1fcr73lwR5v+qBvYnHwQ9uqsQbakOyQ+RAeRw1U7ShSTd0EiaUuBwPkm0xYaBJBeZOYbqq3+LQ8tBmyMErSLrI1EjgWapPFzGbKZORdu+cB4TTlSGaXUguLAiA4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737069434; c=relaxed/simple; bh=1iGhFb5yYmlt+N/E7uhnersaFVha+jc84E0nut9lM44=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LXxR8H698K9FzLq2u7fGiaL+YmxeGNBaEBj/y2G1Sl6YffFkSQPNhzzkF23aeabGug624zxtXYwQsNHTP3h73MpRSvkT4DrX7167PhI62k55Se9bJTAcMvO3CTOThaxhv111AHPfL4HXBJaropGX2zpVMqulcShDGj4Sk5PFRHw= 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=b3izO1BA; arc=none smtp.client-ip=209.85.214.179 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="b3izO1BA" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-21636268e43so34636195ad.2 for ; Thu, 16 Jan 2025 15:17:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=davidwei-uk.20230601.gappssmtp.com; s=20230601; t=1737069432; x=1737674232; 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=ls7TIJmWbtjH6cQ+zvuFtI+oK15m0KZtEVTJMdgXvRQ=; b=b3izO1BA5enllOrhuBplPAeuLTQsPKGKZND8TL+h7KLgVqGJfafX3s6OdSyRml9+pf pVK+6GIuQ55gkIGyNgHfuXeb0JgXQQMYM7zkIP33ai8UxhFrhLj2B/KQrugiKt4X7En6 zV+QKnpS7outUWrNaNa1Y6CTUj7D0Oixr1LhpZHJJ9TzV7byP9fvMaJTPn2hraNf4ZGQ opHZUI/fTtnjjQFtyt7bQFw+7K90S43ZpC5Ko1khIqDHjWKfT8pWtdgT2981xy+PSWgx u7wBvKz7QFNZ7RQL8PKkMYQcAxKzX047UPfmYD9WgzZo7vXUJBQLcJRs6bjQcoqeZbkE yFZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737069432; x=1737674232; 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=ls7TIJmWbtjH6cQ+zvuFtI+oK15m0KZtEVTJMdgXvRQ=; b=t2zMOMLR6VEf67iBJsf9yNw9XLEBGp5SbRgdcBEm3+/I1mKYg1PT7IwUStf21ChFcs WT3PQOUmjRbD71XWnXDkVwlxfze1uaHNfov9RDn0BkzpvZlIz6vDA6RAvl7n+u/7z231 uZEamLPpeqHsqiccmsMfEe1RJhiset5dFodZ6jHcUxVuWm3FNpmq82mjKrBRV5z2Q19Y Voq9iVMbAs9YjX0UKpJTOBXOqplennAapJgb6dbZrSw1hm6p2MyaDCLNjsLHvPjGIR8W PS00PLaWdbKPbNEiD0bkJFgWuDxESKoQ55bJitWmmGQFk9eG4G8Ssp8toLXB1rk4ZZmg cJyA== X-Forwarded-Encrypted: i=1; AJvYcCUL0NmQ2Gxgde+Fd3sUDeQS9+vke5LLAGCFwYIsvUsFK9qswdqBiEZE/i8bdoetr5CNCEEA5+4=@vger.kernel.org X-Gm-Message-State: AOJu0YyTNZ1HTtDYEdEMwxMDLYcIVnneY12GMHMI+xzNsyFimU4We2NR Okf20SzlxBccpgCzBiNdTLP07sYhCPVtRKIRkW/ay8Qm3cQBXU1c4sbx+yeunA4= X-Gm-Gg: ASbGnctz8wJpvGHI9gIYqBXCjKnegKr+ALRUjlNPouvmHH2YuILJJpG8GuOI78MxIVl ezhS9nnM3gTsAxLWZOHJeANElgtP9+QtQMFDrqT3qpWRzcnC6XPsVb9ATP6b3B4CYSM8oWm+lPp 4ItujA4QSAPo9WK61a4H2tlr56MDHLmhYiJk/VsrOkE6LKSpfuwNqV4fh85QiRTfywSFtm9MG34 e4UkpSRATEK+OSh4yV4reUFf/WK8mEuwsWM9yuAng== X-Google-Smtp-Source: AGHT+IE71cVmkTwlhEWppykLzPgYxNM7h4dJ+MNl7UXVZ10XHLjhkMrqkn8AlPhME2DxTq+/xg7ZYA== X-Received: by 2002:a17:902:d58e:b0:215:a57e:88e7 with SMTP id d9443c01a7336-21c352de0damr8272885ad.3.1737069432322; Thu, 16 Jan 2025 15:17:12 -0800 (PST) Received: from localhost ([2a03:2880:ff:1c::]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2f77611d5d1sm751552a91.4.2025.01.16.15.17.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jan 2025 15:17:12 -0800 (PST) From: David Wei To: io-uring@vger.kernel.org, netdev@vger.kernel.org Cc: Jens Axboe , Pavel Begunkov , Jakub Kicinski , Paolo Abeni , "David S. Miller" , Eric Dumazet , Jesper Dangaard Brouer , David Ahern , Mina Almasry , Stanislav Fomichev , Joe Damato , Pedro Tammela Subject: [PATCH net-next v11 02/21] net: prefix devmem specific helpers Date: Thu, 16 Jan 2025 15:16:44 -0800 Message-ID: <20250116231704.2402455-3-dw@davidwei.uk> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250116231704.2402455-1-dw@davidwei.uk> References: <20250116231704.2402455-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 Add prefixes to all helpers that are specific to devmem TCP, i.e. net_iov_binding[_id]. Reviewed-by: Jakub Kicinski Reviewed-by: Mina Almasry Signed-off-by: Pavel Begunkov Signed-off-by: David Wei --- net/core/devmem.c | 2 +- net/core/devmem.h | 14 +++++++------- net/ipv4/tcp.c | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/net/core/devmem.c b/net/core/devmem.c index 0b6ed7525b22..5e1a05082ab8 100644 --- a/net/core/devmem.c +++ b/net/core/devmem.c @@ -93,7 +93,7 @@ net_devmem_alloc_dmabuf(struct net_devmem_dmabuf_binding *binding) void net_devmem_free_dmabuf(struct net_iov *niov) { - struct net_devmem_dmabuf_binding *binding = net_iov_binding(niov); + struct net_devmem_dmabuf_binding *binding = net_devmem_iov_binding(niov); unsigned long dma_addr = net_devmem_get_dma_addr(niov); if (WARN_ON(!gen_pool_has_addr(binding->chunk_pool, dma_addr, diff --git a/net/core/devmem.h b/net/core/devmem.h index 76099ef9c482..99782ddeca40 100644 --- a/net/core/devmem.h +++ b/net/core/devmem.h @@ -86,11 +86,16 @@ static inline unsigned int net_iov_idx(const struct net_iov *niov) } static inline struct net_devmem_dmabuf_binding * -net_iov_binding(const struct net_iov *niov) +net_devmem_iov_binding(const struct net_iov *niov) { return net_iov_owner(niov)->binding; } +static inline u32 net_devmem_iov_binding_id(const struct net_iov *niov) +{ + return net_devmem_iov_binding(niov)->id; +} + static inline unsigned long net_iov_virtual_addr(const struct net_iov *niov) { struct dmabuf_genpool_chunk_owner *owner = net_iov_owner(niov); @@ -99,11 +104,6 @@ static inline unsigned long net_iov_virtual_addr(const struct net_iov *niov) ((unsigned long)net_iov_idx(niov) << PAGE_SHIFT); } -static inline u32 net_iov_binding_id(const struct net_iov *niov) -{ - return net_iov_owner(niov)->binding->id; -} - static inline void net_devmem_dmabuf_binding_get(struct net_devmem_dmabuf_binding *binding) { @@ -171,7 +171,7 @@ static inline unsigned long net_iov_virtual_addr(const struct net_iov *niov) return 0; } -static inline u32 net_iov_binding_id(const struct net_iov *niov) +static inline u32 net_devmem_iov_binding_id(const struct net_iov *niov) { return 0; } diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 0d704bda6c41..b872de9a8271 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -2494,7 +2494,7 @@ static int tcp_recvmsg_dmabuf(struct sock *sk, const struct sk_buff *skb, /* Will perform the exchange later */ dmabuf_cmsg.frag_token = tcp_xa_pool.tokens[tcp_xa_pool.idx]; - dmabuf_cmsg.dmabuf_id = net_iov_binding_id(niov); + dmabuf_cmsg.dmabuf_id = net_devmem_iov_binding_id(niov); offset += copy; remaining_len -= copy; From patchwork Thu Jan 16 23:16:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wei X-Patchwork-Id: 13942447 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (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 11F732419FD for ; Thu, 16 Jan 2025 23:17:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737069435; cv=none; b=ELbB8euuKKvWatZffRPiQerK8jErMJVYQFPfATPkBMjYlWXGT1kK2MxvRqdS8TAFz6+d3mKNyubukhIxSI7UTLnhP36N5sFESOVwdnIJSMZ46L1ZAEqQO9QptS+Un+r3LU1btMrl4XgM1bJIQW4PYnhc5SaxhrjO73wgqnk27xs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737069435; c=relaxed/simple; bh=fftsQD54m30KkQ06F0HSCCxYEgRnAKtG0MaaE99bB44=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pSM/9fupIf7whVS4NoWPUajybyEewXb93kOAY9HFdcWFZbcRW6DY++3U/myPlwO13KDCX1Ty129gJqngYxOg6SKSUjVuXSI/wtOb5Mp7o2RmRjizB4ZC6JbEO6DrE4EaUg3t3thyMDm/c+CQw5hksfQKasB0VwA1z11exXjtoKw= 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=ivUfg4gP; arc=none smtp.client-ip=209.85.214.182 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="ivUfg4gP" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-21631789fcdso33635045ad.1 for ; Thu, 16 Jan 2025 15:17:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=davidwei-uk.20230601.gappssmtp.com; s=20230601; t=1737069433; x=1737674233; 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=axZU4QRP62l11H6FtMZDn5bEkPEGXxbfZb1+1AX9eEw=; b=ivUfg4gP57Ua7TB3H32wtmqDpFkD5WGdl5l2OOLFjqbTHL3BtrXhgUgXbomWZjGisj Uy32ckXfLscKnWrgX//RTc0ID4Jf+imIXAqVYAqI52TL9l9K2TztdQLWd6GfvYjJN7ZH JStZH5AwvoBmZvvNpP43b6R2D1GxjnKlVfEc608Dsedq3WiErEwEZAjdaaTr4ngqKySB 5sd1/znhjMMtNHefqbgP2i3qg1yQY7fWER3P8oZl0cCYNzDKQv1r1WogyxMYvwCkTi0o T8mzv4FaEeca4tNdsWKIlzQtLB5x6F9y1INN+EGqH6jzculeZmpf0HPbwgbzhmnD0/Fm F2YA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737069433; x=1737674233; 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=axZU4QRP62l11H6FtMZDn5bEkPEGXxbfZb1+1AX9eEw=; b=haK/MaWo5SiZ+sQFJk6swbzlnYa4+DqXigaOZaXB77i1Vo7+ntCF0AfftL8K0hzRuY HEUer7iVd7jXQBAX1aRLA7x9xM4JoYYrEa/FNBS9QPe91w6Gzz0J9+vGz9DEdkqt3tKZ A8bsJtllSXN0DmkXeV6xBJj8u2ar1Jy/LZVXutmHbH7GsGgooNNCjAa33YtFUkIWsKvF yMK7bdxROpxH5XAfg0cNDyLt60IsZ3Uj/3rZa0WxLhIugHNN5Hg7vfSN9xizhp9Yzttx Y+vQMOtxtUVvcI9lJHkvbp458t2u/Dp4d2sY6G/SIxqqGd/EB4N9t5DRAxwnWl1/ilCH BMMg== X-Forwarded-Encrypted: i=1; AJvYcCVAPurVWgwk7iDNrCiacRM9cAgYZbHdunY9n1aGW13FBaVIEbFKbh1e0BJAcBXKPmBz3OPXwhM=@vger.kernel.org X-Gm-Message-State: AOJu0Yz83JkhOYizAx3kHGj32h4IPt7FxbtUN/ukoxp4qISnHgw/2N3e nY4RHEjIDMnQ2g1WklTpgWt8qdjTApgjwQ3NO3+nn/lthKQNo10PBK1Ie4xkY8c= X-Gm-Gg: ASbGnctuPXnllxxtXLI6noK5Ikg0uFuoM5K8QqQedKAbbMTkyY2N6DWw2U3QlPYFasu Xpqp5VYbhRiwO1w0DHAZ6CV9Tk0EtZFP2diwDybe0v0YbGoKbe/6jj1+ooeV5x4V3wosZNzi/Cr XNGT+AQ/HGNbRraQzqtDBH10K1aUfEvgqnoVp29vnatee5MZnP1J7V2QfdlBuM88VASqciv/S9U 75au/Z164744oL6GNrMAwbqkmqyFWAYix/QKzcAeQ== X-Google-Smtp-Source: AGHT+IELdAkwVkB/moWk+nhGhkHsj8OwbhRWiDKxdlS1CGlw8irwfZiVhywNyJPTRMr3N8Iwj09ZmQ== X-Received: by 2002:a05:6a00:2405:b0:725:4301:ed5a with SMTP id d2e1a72fcca58-72db1b312f0mr627053b3a.2.1737069433230; Thu, 16 Jan 2025 15:17:13 -0800 (PST) Received: from localhost ([2a03:2880:ff:18::]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72dab845971sm563895b3a.73.2025.01.16.15.17.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jan 2025 15:17:12 -0800 (PST) From: David Wei To: io-uring@vger.kernel.org, netdev@vger.kernel.org Cc: Jens Axboe , Pavel Begunkov , Jakub Kicinski , Paolo Abeni , "David S. Miller" , Eric Dumazet , Jesper Dangaard Brouer , David Ahern , Mina Almasry , Stanislav Fomichev , Joe Damato , Pedro Tammela Subject: [PATCH net-next v11 03/21] net: generalise net_iov chunk owners Date: Thu, 16 Jan 2025 15:16:45 -0800 Message-ID: <20250116231704.2402455-4-dw@davidwei.uk> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250116231704.2402455-1-dw@davidwei.uk> References: <20250116231704.2402455-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 Currently net_iov stores a pointer to struct dmabuf_genpool_chunk_owner, which serves as a useful abstraction to share data and provide a context. However, it's too devmem specific, and we want to reuse it for other memory providers, and for that we need to decouple net_iov from devmem. Make net_iov to point to a new base structure called net_iov_area, which dmabuf_genpool_chunk_owner extends. Reviewed-by: Mina Almasry Acked-by: Jakub Kicinski Signed-off-by: Pavel Begunkov Signed-off-by: David Wei --- include/net/netmem.h | 21 ++++++++++++++++++++- net/core/devmem.c | 25 +++++++++++++------------ net/core/devmem.h | 25 +++++++++---------------- 3 files changed, 42 insertions(+), 29 deletions(-) diff --git a/include/net/netmem.h b/include/net/netmem.h index 1b58faa4f20f..c61d5b21e7b4 100644 --- a/include/net/netmem.h +++ b/include/net/netmem.h @@ -24,11 +24,20 @@ struct net_iov { unsigned long __unused_padding; unsigned long pp_magic; struct page_pool *pp; - struct dmabuf_genpool_chunk_owner *owner; + struct net_iov_area *owner; unsigned long dma_addr; atomic_long_t pp_ref_count; }; +struct net_iov_area { + /* Array of net_iovs for this area. */ + struct net_iov *niovs; + size_t num_niovs; + + /* Offset into the dma-buf where this chunk starts. */ + unsigned long base_virtual; +}; + /* These fields in struct page are used by the page_pool and net stack: * * struct { @@ -54,6 +63,16 @@ NET_IOV_ASSERT_OFFSET(dma_addr, dma_addr); NET_IOV_ASSERT_OFFSET(pp_ref_count, pp_ref_count); #undef NET_IOV_ASSERT_OFFSET +static inline struct net_iov_area *net_iov_owner(const struct net_iov *niov) +{ + return niov->owner; +} + +static inline unsigned int net_iov_idx(const struct net_iov *niov) +{ + return niov - net_iov_owner(niov)->niovs; +} + /* netmem */ /** diff --git a/net/core/devmem.c b/net/core/devmem.c index 5e1a05082ab8..c250db6993d3 100644 --- a/net/core/devmem.c +++ b/net/core/devmem.c @@ -32,14 +32,15 @@ static void net_devmem_dmabuf_free_chunk_owner(struct gen_pool *genpool, { struct dmabuf_genpool_chunk_owner *owner = chunk->owner; - kvfree(owner->niovs); + kvfree(owner->area.niovs); kfree(owner); } static dma_addr_t net_devmem_get_dma_addr(const struct net_iov *niov) { - struct dmabuf_genpool_chunk_owner *owner = net_iov_owner(niov); + struct dmabuf_genpool_chunk_owner *owner; + owner = net_devmem_iov_to_chunk_owner(niov); return owner->base_dma_addr + ((dma_addr_t)net_iov_idx(niov) << PAGE_SHIFT); } @@ -82,7 +83,7 @@ net_devmem_alloc_dmabuf(struct net_devmem_dmabuf_binding *binding) offset = dma_addr - owner->base_dma_addr; index = offset / PAGE_SIZE; - niov = &owner->niovs[index]; + niov = &owner->area.niovs[index]; niov->pp_magic = 0; niov->pp = NULL; @@ -250,9 +251,9 @@ net_devmem_bind_dmabuf(struct net_device *dev, unsigned int dmabuf_fd, goto err_free_chunks; } - owner->base_virtual = virtual; + owner->area.base_virtual = virtual; owner->base_dma_addr = dma_addr; - owner->num_niovs = len / PAGE_SIZE; + owner->area.num_niovs = len / PAGE_SIZE; owner->binding = binding; err = gen_pool_add_owner(binding->chunk_pool, dma_addr, @@ -264,17 +265,17 @@ net_devmem_bind_dmabuf(struct net_device *dev, unsigned int dmabuf_fd, goto err_free_chunks; } - owner->niovs = kvmalloc_array(owner->num_niovs, - sizeof(*owner->niovs), - GFP_KERNEL); - if (!owner->niovs) { + owner->area.niovs = kvmalloc_array(owner->area.num_niovs, + sizeof(*owner->area.niovs), + GFP_KERNEL); + if (!owner->area.niovs) { err = -ENOMEM; goto err_free_chunks; } - for (i = 0; i < owner->num_niovs; i++) { - niov = &owner->niovs[i]; - niov->owner = owner; + for (i = 0; i < owner->area.num_niovs; i++) { + niov = &owner->area.niovs[i]; + niov->owner = &owner->area; page_pool_set_dma_addr_netmem(net_iov_to_netmem(niov), net_devmem_get_dma_addr(niov)); } diff --git a/net/core/devmem.h b/net/core/devmem.h index 99782ddeca40..a2b9913e9a17 100644 --- a/net/core/devmem.h +++ b/net/core/devmem.h @@ -10,6 +10,8 @@ #ifndef _NET_DEVMEM_H #define _NET_DEVMEM_H +#include + struct netlink_ext_ack; struct net_devmem_dmabuf_binding { @@ -51,17 +53,11 @@ struct net_devmem_dmabuf_binding { * allocations from this chunk. */ struct dmabuf_genpool_chunk_owner { - /* Offset into the dma-buf where this chunk starts. */ - unsigned long base_virtual; + struct net_iov_area area; + struct net_devmem_dmabuf_binding *binding; /* dma_addr of the start of the chunk. */ dma_addr_t base_dma_addr; - - /* Array of net_iovs for this chunk. */ - struct net_iov *niovs; - size_t num_niovs; - - struct net_devmem_dmabuf_binding *binding; }; void __net_devmem_dmabuf_binding_free(struct net_devmem_dmabuf_binding *binding); @@ -75,20 +71,17 @@ int net_devmem_bind_dmabuf_to_queue(struct net_device *dev, u32 rxq_idx, void dev_dmabuf_uninstall(struct net_device *dev); static inline struct dmabuf_genpool_chunk_owner * -net_iov_owner(const struct net_iov *niov) +net_devmem_iov_to_chunk_owner(const struct net_iov *niov) { - return niov->owner; -} + struct net_iov_area *owner = net_iov_owner(niov); -static inline unsigned int net_iov_idx(const struct net_iov *niov) -{ - return niov - net_iov_owner(niov)->niovs; + return container_of(owner, struct dmabuf_genpool_chunk_owner, area); } static inline struct net_devmem_dmabuf_binding * net_devmem_iov_binding(const struct net_iov *niov) { - return net_iov_owner(niov)->binding; + return net_devmem_iov_to_chunk_owner(niov)->binding; } static inline u32 net_devmem_iov_binding_id(const struct net_iov *niov) @@ -98,7 +91,7 @@ static inline u32 net_devmem_iov_binding_id(const struct net_iov *niov) static inline unsigned long net_iov_virtual_addr(const struct net_iov *niov) { - struct dmabuf_genpool_chunk_owner *owner = net_iov_owner(niov); + struct net_iov_area *owner = net_iov_owner(niov); return owner->base_virtual + ((unsigned long)net_iov_idx(niov) << PAGE_SHIFT); From patchwork Thu Jan 16 23:16:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wei X-Patchwork-Id: 13942448 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (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 D90F1242250 for ; Thu, 16 Jan 2025 23:17:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737069436; cv=none; b=qouhQMT6M+hSLLeV8wPIMlySrjIlpDdnaNQT1AH+A0pk8Zq4gYOldmhztg4xKa2cFeTHngbhRcCmtKv7NRdhjdCtlQYQAMQRqBvEUUR5g54UkZPwJTS/B4ijhpZPze5/4ROj+ZCpiWAF2OL5Rkyap3Dhx/t4eOfz9/P0Hj5Zdro= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737069436; c=relaxed/simple; bh=jcix8cTA8XcjU9cv7ZsMLrmB/iNbQuJzGglcZYJ7KpQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=F7CBAMnx4uKbwougJ3rIw8mail8oxHlKs+0xnxjK7kj6wQNH+DcCQzta+SwBL8Nu0qRTSux0qHncE1i6LPLXTTiwwU28yFLozV7yN4U9hL4GSid3gKalGRb5809pLf2ZvTdZkWbDysf6+fKAXTtAP98LVwa4CGXQw7bZKLY4LYc= 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=rNI6VMiM; arc=none smtp.client-ip=209.85.214.177 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="rNI6VMiM" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-2161eb94cceso18391015ad.2 for ; Thu, 16 Jan 2025 15:17:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=davidwei-uk.20230601.gappssmtp.com; s=20230601; t=1737069434; x=1737674234; 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=TJ1/x2oldCLUQ71TCzgIPzmYUprE3G9HK3SL6bSqPrg=; b=rNI6VMiMY2eXNhPEG48C9kfqKboEuPXX3cIwOTX2RrC2vHKtOVvnEflF5batQ1VdKS 34fRttXEEPq7EihCO/ZPF7TJS+uEffSvfwZvTuAW1QJrdA4X+a4PBMlA0mNEDzXBESjE OyAeJTc3MSu91Ii/8xnZ+dVwgpngxlvCzq6p6L/xuvXp5Iq7/3RXOjDEgUjwTRVgh0rg 4cce4HkIn9/bNRAsr6zUcnlr3Frjs+pardQM90Mcwsyfm4BQRDy2lcgVG6OENnOlG5rp 7uU6y9wGV5dtQKagZxKqJQxNLYgxYZwf0e9zl5piiQtYYaBOzUe72ZMGmdt/qaxzhIvl EPww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737069434; x=1737674234; 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=TJ1/x2oldCLUQ71TCzgIPzmYUprE3G9HK3SL6bSqPrg=; b=OeWaApz4IVNcIydYJ+ikp//XLvzmPrVquiWKa/5299jB448SXRooe7jvm3v/3ayVo5 swH4VujmKSbcJ8u3QiM4T8yn6ZHaDAQfmwTNxPrZB9cSz2KriiTevH6lMOit1ohhJ5jj VhmFTIo5rHhWJws7m3eutQoCdywiu7hBMklJii7DWOZMnVOYvkhK5o0ElOtZXwuvNzVj A+WURRWNv04HesoOrBaRP1s4iXtPF2R8dW5FSpvEP3cM+7T+5AaBmLrhMlw4mPx++Gmq uE51ybNz7AAmOlW7Jc0hAsE7vsZMw3slmfN8AiQk2N74ZNVm1OtvZihD5WNMOgFdjUiu n/fg== X-Forwarded-Encrypted: i=1; AJvYcCX3lFoxtAlBtZdzaQWonKMDNahMYFLIVEK9WzzSAfQ8A8csyWdqIpX3K3OeoErg9g/wIVRJ9qM=@vger.kernel.org X-Gm-Message-State: AOJu0YzPMVH5xBD9N8RaMjMyY3f3koteO6MiTJhauxWhXcgZeAra1znG e1hLFam5DQ4H511ewKukl4Ha7xCdtDyoBYwlvooOabGWqzH+WwTGBoIoT/nJnz4= X-Gm-Gg: ASbGncvIOQBoBoGW+erU+A/dUxHVSLnDs0fhPCa037nR4LUduT3jILqcixMCmxHIznc o4mTpQjd4QeUe0BtVsPPoW9Wd0bpT0ws54TOJ38iw1G+L/xrK8etyVdFBIyIFE01q124FJZV2KR wjHXdI2+1YeUbCF9jyJBiUZbZ3TPudgzy0ZBxRwxK1K1mcmq6uXGcPU3Egx6iRbPt4Av8cZMc50 +WKNHgurNVyCadMEdYiuDD7GUnuH7fFqZ0RQyZ7OA== X-Google-Smtp-Source: AGHT+IFcbJHs45sS+9Xvy4JwIrJ1eut9tKp+0CbdXcRg+snaemQgrSDo0z0cwi84eQ1NC0vOevjOfA== X-Received: by 2002:a05:6a00:21ca:b0:727:3fd5:b530 with SMTP id d2e1a72fcca58-72dafb36d75mr802226b3a.15.1737069434152; Thu, 16 Jan 2025 15:17:14 -0800 (PST) Received: from localhost ([2a03:2880:ff:16::]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72dabacdb13sm525506b3a.168.2025.01.16.15.17.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jan 2025 15:17:13 -0800 (PST) From: David Wei To: io-uring@vger.kernel.org, netdev@vger.kernel.org Cc: Jens Axboe , Pavel Begunkov , Jakub Kicinski , Paolo Abeni , "David S. Miller" , Eric Dumazet , Jesper Dangaard Brouer , David Ahern , Mina Almasry , Stanislav Fomichev , Joe Damato , Pedro Tammela Subject: [PATCH net-next v11 04/21] net: page_pool: create hooks for custom memory providers Date: Thu, 16 Jan 2025 15:16:46 -0800 Message-ID: <20250116231704.2402455-5-dw@davidwei.uk> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250116231704.2402455-1-dw@davidwei.uk> References: <20250116231704.2402455-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 A spin off from the original page pool memory providers patch by Jakub, which allows extending page pools with custom allocators. One of such providers is devmem TCP, and the other is io_uring zerocopy added in following patches. Co-developed-by: Jakub Kicinski # initial mp proposal Link: https://lore.kernel.org/netdev/20230707183935.997267-7-kuba@kernel.org/ Signed-off-by: Pavel Begunkov Signed-off-by: David Wei Signed-off-by: Jakub Kicinski --- include/net/page_pool/memory_provider.h | 15 +++++++++++++++ include/net/page_pool/types.h | 4 ++++ net/core/devmem.c | 15 ++++++++++++++- net/core/page_pool.c | 23 +++++++++++++++-------- 4 files changed, 48 insertions(+), 9 deletions(-) create mode 100644 include/net/page_pool/memory_provider.h diff --git a/include/net/page_pool/memory_provider.h b/include/net/page_pool/memory_provider.h new file mode 100644 index 000000000000..e49d0a52629d --- /dev/null +++ b/include/net/page_pool/memory_provider.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _NET_PAGE_POOL_MEMORY_PROVIDER_H +#define _NET_PAGE_POOL_MEMORY_PROVIDER_H + +#include +#include + +struct memory_provider_ops { + netmem_ref (*alloc_netmems)(struct page_pool *pool, gfp_t gfp); + bool (*release_netmem)(struct page_pool *pool, netmem_ref netmem); + int (*init)(struct page_pool *pool); + void (*destroy)(struct page_pool *pool); +}; + +#endif diff --git a/include/net/page_pool/types.h b/include/net/page_pool/types.h index ed4cd114180a..88f65c3e2ad9 100644 --- a/include/net/page_pool/types.h +++ b/include/net/page_pool/types.h @@ -152,8 +152,11 @@ struct page_pool_stats { */ #define PAGE_POOL_FRAG_GROUP_ALIGN (4 * sizeof(long)) +struct memory_provider_ops; + struct pp_memory_provider_params { void *mp_priv; + const struct memory_provider_ops *mp_ops; }; struct page_pool { @@ -216,6 +219,7 @@ struct page_pool { struct ptr_ring ring; void *mp_priv; + const struct memory_provider_ops *mp_ops; #ifdef CONFIG_PAGE_POOL_STATS /* recycle stats are per-cpu to avoid locking */ diff --git a/net/core/devmem.c b/net/core/devmem.c index c250db6993d3..48833c1dcbd4 100644 --- a/net/core/devmem.c +++ b/net/core/devmem.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include "devmem.h" @@ -26,6 +27,8 @@ /* Protected by rtnl_lock() */ static DEFINE_XARRAY_FLAGS(net_devmem_dmabuf_bindings, XA_FLAGS_ALLOC1); +static const struct memory_provider_ops dmabuf_devmem_ops; + static void net_devmem_dmabuf_free_chunk_owner(struct gen_pool *genpool, struct gen_pool_chunk *chunk, void *not_used) @@ -117,6 +120,7 @@ void net_devmem_unbind_dmabuf(struct net_devmem_dmabuf_binding *binding) WARN_ON(rxq->mp_params.mp_priv != binding); rxq->mp_params.mp_priv = NULL; + rxq->mp_params.mp_ops = NULL; rxq_idx = get_netdev_rx_queue_index(rxq); @@ -142,7 +146,7 @@ int net_devmem_bind_dmabuf_to_queue(struct net_device *dev, u32 rxq_idx, } rxq = __netif_get_rx_queue(dev, rxq_idx); - if (rxq->mp_params.mp_priv) { + if (rxq->mp_params.mp_ops) { NL_SET_ERR_MSG(extack, "designated queue already memory provider bound"); return -EEXIST; } @@ -160,6 +164,7 @@ int net_devmem_bind_dmabuf_to_queue(struct net_device *dev, u32 rxq_idx, return err; rxq->mp_params.mp_priv = binding; + rxq->mp_params.mp_ops = &dmabuf_devmem_ops; err = netdev_rx_queue_restart(dev, rxq_idx); if (err) @@ -169,6 +174,7 @@ int net_devmem_bind_dmabuf_to_queue(struct net_device *dev, u32 rxq_idx, err_xa_erase: rxq->mp_params.mp_priv = NULL; + rxq->mp_params.mp_ops = NULL; xa_erase(&binding->bound_rxqs, xa_idx); return err; @@ -388,3 +394,10 @@ bool mp_dmabuf_devmem_release_page(struct page_pool *pool, netmem_ref netmem) /* We don't want the page pool put_page()ing our net_iovs. */ return false; } + +static const struct memory_provider_ops dmabuf_devmem_ops = { + .init = mp_dmabuf_devmem_init, + .destroy = mp_dmabuf_devmem_destroy, + .alloc_netmems = mp_dmabuf_devmem_alloc_netmems, + .release_netmem = mp_dmabuf_devmem_release_page, +}; diff --git a/net/core/page_pool.c b/net/core/page_pool.c index 9733206d6406..24e2e2efb1eb 100644 --- a/net/core/page_pool.c +++ b/net/core/page_pool.c @@ -13,6 +13,7 @@ #include #include +#include #include #include @@ -285,13 +286,19 @@ static int page_pool_init(struct page_pool *pool, rxq = __netif_get_rx_queue(pool->slow.netdev, pool->slow.queue_idx); pool->mp_priv = rxq->mp_params.mp_priv; + pool->mp_ops = rxq->mp_params.mp_ops; } - if (pool->mp_priv) { + if (pool->mp_ops) { if (!pool->dma_map || !pool->dma_sync) return -EOPNOTSUPP; - err = mp_dmabuf_devmem_init(pool); + if (WARN_ON(!is_kernel_rodata((unsigned long)pool->mp_ops))) { + err = -EFAULT; + goto free_ptr_ring; + } + + err = pool->mp_ops->init(pool); if (err) { pr_warn("%s() mem-provider init failed %d\n", __func__, err); @@ -588,8 +595,8 @@ netmem_ref page_pool_alloc_netmems(struct page_pool *pool, gfp_t gfp) return netmem; /* Slow-path: cache empty, do real allocation */ - if (static_branch_unlikely(&page_pool_mem_providers) && pool->mp_priv) - netmem = mp_dmabuf_devmem_alloc_netmems(pool, gfp); + if (static_branch_unlikely(&page_pool_mem_providers) && pool->mp_ops) + netmem = pool->mp_ops->alloc_netmems(pool, gfp); else netmem = __page_pool_alloc_pages_slow(pool, gfp); return netmem; @@ -680,8 +687,8 @@ void page_pool_return_page(struct page_pool *pool, netmem_ref netmem) bool put; put = true; - if (static_branch_unlikely(&page_pool_mem_providers) && pool->mp_priv) - put = mp_dmabuf_devmem_release_page(pool, netmem); + if (static_branch_unlikely(&page_pool_mem_providers) && pool->mp_ops) + put = pool->mp_ops->release_netmem(pool, netmem); else __page_pool_release_page_dma(pool, netmem); @@ -1049,8 +1056,8 @@ static void __page_pool_destroy(struct page_pool *pool) page_pool_unlist(pool); page_pool_uninit(pool); - if (pool->mp_priv) { - mp_dmabuf_devmem_destroy(pool); + if (pool->mp_ops) { + pool->mp_ops->destroy(pool); static_branch_dec(&page_pool_mem_providers); } From patchwork Thu Jan 16 23:16:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wei X-Patchwork-Id: 13942449 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) (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 F29A21DDC0F for ; Thu, 16 Jan 2025 23:17:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737069437; cv=none; b=pfCtaHFZQCBkfKXzXHTucxqwFldGewBAEdavF2NEiiCUK1TKKN1HmrAWI253ItE+scTF40rfj3oZWxi8FPiwpgwGCTtvIIuEnHKE4vcMlq0sGpPVL7mv63r6es93ITBZ0JON720k4Hs8BHrRWKpfcL8hrRz0AgSeCxRUhDTGrmg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737069437; c=relaxed/simple; bh=pC+izCPPiOw4hj77bHjJXxuiiJXIs1YU+ft+8NS5olQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=S+2rpz+EmkhV9qwKIxPR/02PgPfm6qX50plNabJWDaw+/LAjfLGNwgwKjLxoq8Nwdog1YyRffxcnWZUe/un+/5SG8t2v4BbGKoKi5ote77oTbYq4Q+MfUoiG7zLaAbIxC994jizIBkRxVa3C0GF5d/L0CzaC8n86kKZ8WTaYfbk= 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=MhWOmsvZ; arc=none smtp.client-ip=209.85.216.51 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="MhWOmsvZ" Received: by mail-pj1-f51.google.com with SMTP id 98e67ed59e1d1-2eec9b3a1bbso2161128a91.3 for ; Thu, 16 Jan 2025 15:17:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=davidwei-uk.20230601.gappssmtp.com; s=20230601; t=1737069435; x=1737674235; 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=3FSAJNCphdORunxyfbKbeJpz17xsYuZAoUUdQ0kuFhk=; b=MhWOmsvZSKuJFs4nOFUyxc3wjG6PCpQOc7daLyTV1R5lAL1DNu4krWXdbrYIUS6Rf+ HqdCXNSNzpX74oeNYs06hijSF+FOAR01WUbUikx5gCBBtRXbItqm/htgMnQJljI83r9F NicwGwYdmNFe2JuvDys2FzDUjnNY/i/mZVGj5vfDLPDlLF07LvlC0eRs9aDQhS+8lKAQ sE5HAZv/l0m8KuGvSup0x/2F5Oiz056A7pNOiczmchgZkmDvrdWbz/qJNo9p9v3nsWsx UE8zw1yVGzHEpTyN7cIf8CYfjDeY5TeEMBTNO29Q6NWLI6RPPpHOSBH2StuRzpxFEzRg EMJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737069435; x=1737674235; 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=3FSAJNCphdORunxyfbKbeJpz17xsYuZAoUUdQ0kuFhk=; b=R3Gqpe7RuRnHOasHZzTX4kkiavLeo2Tc6GatTV9NYOlkuRfw90h95NAp6NI+C5ZmUO T7l5p4UtofeYs7YIkCjKM3ANtqFxh2DQ7B472Cqj/Z75eKqedf3Wdhzyck31zhFbgc0T 6QA/HQzjTeCqK63DRn+yw4DLL3Lb2qQYm/TsT+SgKfFfcCMUeVxN2zPx1jA+XNNjTCpn bZWSApEyovyqw93X6Aar4yUt58k9xUQD2+oasB5mPaydmoGmJRt2UnSJyyFWiym+jx2F E98Abj/igSOT+lbk+uAb+3d3PIx6+E11araaHE/h8noDpji9TOGj1sQu2ZB1cMgOX/Pv VS9g== X-Forwarded-Encrypted: i=1; AJvYcCUHsTLAca2X3uTb/pV8gRjAj4XAVEDa/0ykN1YXGT3cAPbdOnpfotRZ+fQLTbicN4sV9LkNTYY=@vger.kernel.org X-Gm-Message-State: AOJu0Yxd/kDzGNPhalE7wsgtetAKu3JYxN+DKlbJ7KK5VrpO89MflAb/ nmVp1jh29goBMCQbWj6AS3pOFEI3KSg4OJ9/ydNXNSes1ZufZ/67v3CZGkbwsa4= X-Gm-Gg: ASbGncsaTmy7BdcCLUcKecGk5QSI+CHH0Jy7tsk5IHCJe8BMUpvm81IPuH8KVwbdqQj 6leIZoz1Z++XKgr2YN+RB5vgxsaTEvRUs4qqK4sHhp7GMAycezVqeJJ/ju3Mu5SGFagzDoWjCbp LRALomNDExiaj6HQAckjK9GlI9wtF5lbTWWHh/DglC348ReTq/Sj8dujHVr7PF03GcvzTD9r4lA ous+EZEX+3P2BK8mpGsKQ9Dn065fUP8JMrNEhGIrQ== X-Google-Smtp-Source: AGHT+IHedyepUZITwcmVCPI/PDCZLlhzbajAfD5uFw0pI37FVETUFJhRTBupzGFiFEFPGnhoIgXD6w== X-Received: by 2002:a17:90a:e183:b0:2f5:63a:449c with SMTP id 98e67ed59e1d1-2f782d4ef30mr576843a91.28.1737069435153; Thu, 16 Jan 2025 15:17:15 -0800 (PST) Received: from localhost ([2a03:2880:ff:73::]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2f72c2bb480sm3855603a91.33.2025.01.16.15.17.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jan 2025 15:17:14 -0800 (PST) From: David Wei To: io-uring@vger.kernel.org, netdev@vger.kernel.org Cc: Jens Axboe , Pavel Begunkov , Jakub Kicinski , Paolo Abeni , "David S. Miller" , Eric Dumazet , Jesper Dangaard Brouer , David Ahern , Mina Almasry , Stanislav Fomichev , Joe Damato , Pedro Tammela Subject: [PATCH net-next v11 05/21] netdev: add io_uring memory provider info Date: Thu, 16 Jan 2025 15:16:47 -0800 Message-ID: <20250116231704.2402455-6-dw@davidwei.uk> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250116231704.2402455-1-dw@davidwei.uk> References: <20250116231704.2402455-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 Add a nested attribute for io_uring memory provider info. For now it is empty and its presence indicates that a particular page pool or queue has an io_uring memory provider attached. $ ./cli.py --spec netlink/specs/netdev.yaml --dump page-pool-get [{'id': 80, 'ifindex': 2, 'inflight': 64, 'inflight-mem': 262144, 'napi-id': 525}, {'id': 79, 'ifindex': 2, 'inflight': 320, 'inflight-mem': 1310720, 'io_uring': {}, 'napi-id': 525}, ... $ ./cli.py --spec netlink/specs/netdev.yaml --dump queue-get [{'id': 0, 'ifindex': 1, 'type': 'rx'}, {'id': 0, 'ifindex': 1, 'type': 'tx'}, {'id': 0, 'ifindex': 2, 'napi-id': 513, 'type': 'rx'}, {'id': 1, 'ifindex': 2, 'napi-id': 514, 'type': 'rx'}, ... {'id': 12, 'ifindex': 2, 'io_uring': {}, 'napi-id': 525, 'type': 'rx'}, ... Reviewed-by: Jakub Kicinski Signed-off-by: Pavel Begunkov Signed-off-by: David Wei --- Documentation/netlink/specs/netdev.yaml | 15 +++++++++++++++ include/uapi/linux/netdev.h | 8 ++++++++ tools/include/uapi/linux/netdev.h | 8 ++++++++ 3 files changed, 31 insertions(+) diff --git a/Documentation/netlink/specs/netdev.yaml b/Documentation/netlink/specs/netdev.yaml index cbb544bd6c84..288923e965ae 100644 --- a/Documentation/netlink/specs/netdev.yaml +++ b/Documentation/netlink/specs/netdev.yaml @@ -114,6 +114,9 @@ attribute-sets: doc: Bitmask of enabled AF_XDP features. type: u64 enum: xsk-flags + - + name: io-uring-provider-info + attributes: [] - name: page-pool attributes: @@ -171,6 +174,11 @@ attribute-sets: name: dmabuf doc: ID of the dmabuf this page-pool is attached to. type: u32 + - + name: io-uring + doc: io-uring memory provider information. + type: nest + nested-attributes: io-uring-provider-info - name: page-pool-info subset-of: page-pool @@ -296,6 +304,11 @@ attribute-sets: name: dmabuf doc: ID of the dmabuf attached to this queue, if any. type: u32 + - + name: io-uring + doc: io_uring memory provider information. + type: nest + nested-attributes: io-uring-provider-info - name: qstats @@ -572,6 +585,7 @@ operations: - inflight-mem - detach-time - dmabuf + - io-uring dump: reply: *pp-reply config-cond: page-pool @@ -637,6 +651,7 @@ operations: - napi-id - ifindex - dmabuf + - io-uring dump: request: attributes: diff --git a/include/uapi/linux/netdev.h b/include/uapi/linux/netdev.h index e4be227d3ad6..684090732068 100644 --- a/include/uapi/linux/netdev.h +++ b/include/uapi/linux/netdev.h @@ -86,6 +86,12 @@ enum { NETDEV_A_DEV_MAX = (__NETDEV_A_DEV_MAX - 1) }; +enum { + + __NETDEV_A_IO_URING_PROVIDER_INFO_MAX, + NETDEV_A_IO_URING_PROVIDER_INFO_MAX = (__NETDEV_A_IO_URING_PROVIDER_INFO_MAX - 1) +}; + enum { NETDEV_A_PAGE_POOL_ID = 1, NETDEV_A_PAGE_POOL_IFINDEX, @@ -94,6 +100,7 @@ enum { NETDEV_A_PAGE_POOL_INFLIGHT_MEM, NETDEV_A_PAGE_POOL_DETACH_TIME, NETDEV_A_PAGE_POOL_DMABUF, + NETDEV_A_PAGE_POOL_IO_URING, __NETDEV_A_PAGE_POOL_MAX, NETDEV_A_PAGE_POOL_MAX = (__NETDEV_A_PAGE_POOL_MAX - 1) @@ -136,6 +143,7 @@ enum { NETDEV_A_QUEUE_TYPE, NETDEV_A_QUEUE_NAPI_ID, NETDEV_A_QUEUE_DMABUF, + NETDEV_A_QUEUE_IO_URING, __NETDEV_A_QUEUE_MAX, NETDEV_A_QUEUE_MAX = (__NETDEV_A_QUEUE_MAX - 1) diff --git a/tools/include/uapi/linux/netdev.h b/tools/include/uapi/linux/netdev.h index e4be227d3ad6..684090732068 100644 --- a/tools/include/uapi/linux/netdev.h +++ b/tools/include/uapi/linux/netdev.h @@ -86,6 +86,12 @@ enum { NETDEV_A_DEV_MAX = (__NETDEV_A_DEV_MAX - 1) }; +enum { + + __NETDEV_A_IO_URING_PROVIDER_INFO_MAX, + NETDEV_A_IO_URING_PROVIDER_INFO_MAX = (__NETDEV_A_IO_URING_PROVIDER_INFO_MAX - 1) +}; + enum { NETDEV_A_PAGE_POOL_ID = 1, NETDEV_A_PAGE_POOL_IFINDEX, @@ -94,6 +100,7 @@ enum { NETDEV_A_PAGE_POOL_INFLIGHT_MEM, NETDEV_A_PAGE_POOL_DETACH_TIME, NETDEV_A_PAGE_POOL_DMABUF, + NETDEV_A_PAGE_POOL_IO_URING, __NETDEV_A_PAGE_POOL_MAX, NETDEV_A_PAGE_POOL_MAX = (__NETDEV_A_PAGE_POOL_MAX - 1) @@ -136,6 +143,7 @@ enum { NETDEV_A_QUEUE_TYPE, NETDEV_A_QUEUE_NAPI_ID, NETDEV_A_QUEUE_DMABUF, + NETDEV_A_QUEUE_IO_URING, __NETDEV_A_QUEUE_MAX, NETDEV_A_QUEUE_MAX = (__NETDEV_A_QUEUE_MAX - 1) From patchwork Thu Jan 16 23:16:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wei X-Patchwork-Id: 13942450 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) (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 B1A02243348 for ; Thu, 16 Jan 2025 23:17:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737069438; cv=none; b=GOEPRI3A1v3ABsuGeEgvUpNYqQzyAKDztWXu+S3A1HHXznuKrDvq3e4FAOthmcS4nhOGdPi0uWs6UeH50QlRKzTLO9Uh2DhFtaZDvKi6oU0yfxVsvtkizCbVjKUqSg0ksAr+htpd+xq1tD8ykNT/tCQkA/aak6j7xZ7dCBa3q0U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737069438; c=relaxed/simple; bh=nbNQmvcwm0FGW4HaDmOtxcNekDPwpF6gnNCFwbehIWE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nd/vclVDpygM4s1ZNbRdlyw8cnYnF7555TKjBdGS5H2gj3dqKJJRtNtksg0Gtmfh+KQpGROXkz6tpNg53vAGnFVZvqcM6Q+gtvWwRzhpufpd0lgAaoEQqDKV9CZXAmZ7uNtnTd48b2AJ/yBXwaIqM/JESkquc0zlOytFTRIWORA= 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=pqc0tYwf; arc=none smtp.client-ip=209.85.216.49 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="pqc0tYwf" Received: by mail-pj1-f49.google.com with SMTP id 98e67ed59e1d1-2efb17478adso2638534a91.1 for ; Thu, 16 Jan 2025 15:17:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=davidwei-uk.20230601.gappssmtp.com; s=20230601; t=1737069436; x=1737674236; 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=UXQENGImtt4RlCkb7YV/TGKoODmx+IzagWKK6k97kDE=; b=pqc0tYwfvAHeckLJzMUk6NGRj+YMKnysgDwfm/OrguvI4XULYLxXVmDVFSge9h5R2l Dn01r8U5uQvSa5nRDaDDRqs9PDWGmGxHQ45oB1aEOziRo7ITMm7eNO9EVOpzQK6Ol0hY flAwflhbT97vYYmvmQykvwF5fsCUUHw6uEar7liHWihGI/iSvPBrnce/n2us1tB0b5KJ grKqBL+M7O0E6GmkXNGS6ks4AbdoY0NhwYW3M6A36BQ3wBlCwiYhTFkCSwOy4gDnw99q j/Yw/7oTVRpche2dx5M+1XimRG715XoeEvVquUy6Sho4ORNPDbATux1AMLNXa7Rd41LA 5k/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737069436; x=1737674236; 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=UXQENGImtt4RlCkb7YV/TGKoODmx+IzagWKK6k97kDE=; b=ZwTA3AWXa77EPJe+zhGoCg2Z6E4Sko9pIJ5/7mi2IOmjcnOJLBYqgUfNEvijKvUDKJ Z9Y4ggVdQma4H5tSdlpdkwlxB4OPJWg0dOV+Cmt5sVplqQbfFDkrv90qAoMp/6DXOeaM t1MTvNHVyb2Qdycj4vT7KmggGv31bTqTiBhynccDErjxalNACVckCNCbH+6DPyq5zC2i ZqwtBh0rr2crBcXY3Oh5nnUaLuSdraQf4MSLUVMAhroPoLucRXJewcWDuxta64KIXVYd VfHIEqzwZ9TzoWw2RGD6eCwB0Uf+ziuA/ycoU4PY+C+aI9MN+fV7vvLZsv+hZRz1to+T tT1A== X-Forwarded-Encrypted: i=1; AJvYcCV7bGc29p7yBfj6kAm/lbUgR3k+2+WTkWrgftCUoQU66S6YHm5siya9lUXI3EJM5DUa6hGuNV8=@vger.kernel.org X-Gm-Message-State: AOJu0YwA7jidec0gKHwEF7xmRAEOBpUbg8I0QwvFcFyMNaiXA3eUUT4T aYNQK9BLlY1XfsV/fw5Lq8qBzanSNMZD7WsARnfRO/avVxiKm4UrjJ/1dgXDqUc= X-Gm-Gg: ASbGnct0mDfxbnHtBOwo91DY/5M8DwH/l//IDYTbhPu1iHBh9gp+ZeE8ZvSvRKC0HMl knBXqjc+KtFYnH9TLpAsAaB7X8GKG20oAMvn5OyR8gj0+X58T32sysldSynM2Ut6RUl0VUCySwo i59HIainaY+eQg/Ih7Sk6BgJjbwZpfeYdWXVLUKma/sALJ+RH/Aq3h1PC04EAlZ8s1P8jIhqNnO WwLoDoisFLMhjjICv2YnE9VMZNG8nvgbXD5HMzI1g== X-Google-Smtp-Source: AGHT+IEGFKqSoSekoBRce5bWyn/VrKoW0zkaZl+nl3oqGv69mbBo3HWt5w0Hw0+7kT8xvVhr9Q9yBw== X-Received: by 2002:a17:90b:2703:b0:2ee:d63f:d71 with SMTP id 98e67ed59e1d1-2f782c7252dmr667140a91.14.1737069436010; Thu, 16 Jan 2025 15:17:16 -0800 (PST) Received: from localhost ([2a03:2880:ff:73::]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2f72c14ffaasm3859710a91.4.2025.01.16.15.17.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jan 2025 15:17:15 -0800 (PST) From: David Wei To: io-uring@vger.kernel.org, netdev@vger.kernel.org Cc: Jens Axboe , Pavel Begunkov , Jakub Kicinski , Paolo Abeni , "David S. Miller" , Eric Dumazet , Jesper Dangaard Brouer , David Ahern , Mina Almasry , Stanislav Fomichev , Joe Damato , Pedro Tammela Subject: [PATCH net-next v11 06/21] net: page_pool: add callback for mp info printing Date: Thu, 16 Jan 2025 15:16:48 -0800 Message-ID: <20250116231704.2402455-7-dw@davidwei.uk> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250116231704.2402455-1-dw@davidwei.uk> References: <20250116231704.2402455-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 Add a mandatory callback that prints information about the memory provider to netlink. Reviewed-by: Jakub Kicinski Signed-off-by: Pavel Begunkov Signed-off-by: David Wei --- include/net/page_pool/memory_provider.h | 5 +++++ net/core/devmem.c | 10 ++++++++++ net/core/netdev-genl.c | 11 ++++++----- net/core/page_pool_user.c | 5 ++--- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/include/net/page_pool/memory_provider.h b/include/net/page_pool/memory_provider.h index e49d0a52629d..6d10a0959d00 100644 --- a/include/net/page_pool/memory_provider.h +++ b/include/net/page_pool/memory_provider.h @@ -5,11 +5,16 @@ #include #include +struct netdev_rx_queue; +struct sk_buff; + struct memory_provider_ops { netmem_ref (*alloc_netmems)(struct page_pool *pool, gfp_t gfp); bool (*release_netmem)(struct page_pool *pool, netmem_ref netmem); int (*init)(struct page_pool *pool); void (*destroy)(struct page_pool *pool); + int (*nl_fill)(void *mp_priv, struct sk_buff *rsp, + struct netdev_rx_queue *rxq); }; #endif diff --git a/net/core/devmem.c b/net/core/devmem.c index 48833c1dcbd4..c0bde0869f72 100644 --- a/net/core/devmem.c +++ b/net/core/devmem.c @@ -395,9 +395,19 @@ bool mp_dmabuf_devmem_release_page(struct page_pool *pool, netmem_ref netmem) return false; } +static int mp_dmabuf_devmem_nl_fill(void *mp_priv, struct sk_buff *rsp, + struct netdev_rx_queue *rxq) +{ + const struct net_devmem_dmabuf_binding *binding = mp_priv; + int type = rxq ? NETDEV_A_QUEUE_DMABUF : NETDEV_A_PAGE_POOL_DMABUF; + + return nla_put_u32(rsp, type, binding->id); +} + static const struct memory_provider_ops dmabuf_devmem_ops = { .init = mp_dmabuf_devmem_init, .destroy = mp_dmabuf_devmem_destroy, .alloc_netmems = mp_dmabuf_devmem_alloc_netmems, .release_netmem = mp_dmabuf_devmem_release_page, + .nl_fill = mp_dmabuf_devmem_nl_fill, }; diff --git a/net/core/netdev-genl.c b/net/core/netdev-genl.c index 2d3ae0cd3ad2..4bc05fb27890 100644 --- a/net/core/netdev-genl.c +++ b/net/core/netdev-genl.c @@ -10,6 +10,7 @@ #include #include #include +#include #include "dev.h" #include "devmem.h" @@ -368,7 +369,6 @@ static int netdev_nl_queue_fill_one(struct sk_buff *rsp, struct net_device *netdev, u32 q_idx, u32 q_type, const struct genl_info *info) { - struct net_devmem_dmabuf_binding *binding; struct netdev_rx_queue *rxq; struct netdev_queue *txq; void *hdr; @@ -385,15 +385,16 @@ netdev_nl_queue_fill_one(struct sk_buff *rsp, struct net_device *netdev, switch (q_type) { case NETDEV_QUEUE_TYPE_RX: rxq = __netif_get_rx_queue(netdev, q_idx); + struct pp_memory_provider_params *params; + if (rxq->napi && nla_put_u32(rsp, NETDEV_A_QUEUE_NAPI_ID, rxq->napi->napi_id)) goto nla_put_failure; - binding = rxq->mp_params.mp_priv; - if (binding && - nla_put_u32(rsp, NETDEV_A_QUEUE_DMABUF, binding->id)) + params = &rxq->mp_params; + if (params->mp_ops && + params->mp_ops->nl_fill(params->mp_priv, rsp, rxq)) goto nla_put_failure; - break; case NETDEV_QUEUE_TYPE_TX: txq = netdev_get_tx_queue(netdev, q_idx); diff --git a/net/core/page_pool_user.c b/net/core/page_pool_user.c index 8d31c71bea1a..bd017537fa80 100644 --- a/net/core/page_pool_user.c +++ b/net/core/page_pool_user.c @@ -7,9 +7,9 @@ #include #include #include +#include #include -#include "devmem.h" #include "page_pool_priv.h" #include "netdev-genl-gen.h" @@ -214,7 +214,6 @@ 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; size_t inflight, refsz; void *hdr; @@ -244,7 +243,7 @@ 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)) + if (pool->mp_ops && pool->mp_ops->nl_fill(pool->mp_priv, rsp, NULL)) goto err_cancel; genlmsg_end(rsp, hdr); From patchwork Thu Jan 16 23:16:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wei X-Patchwork-Id: 13942451 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (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 A57F7243863 for ; Thu, 16 Jan 2025 23:17:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737069439; cv=none; b=BhLJlnGrMQfo0bZPNRbCBEbSd/82cUtXf/K/NJdJxPrDzpuT7Db+CilnIzYwa4z+YxafV4SuytwfeNv6f4h4FEIOwvBIo81WPqPByWOhxERr+REGbSUcdylyeT6+RkgYX6CzZNEDgyQ/HXGjSdtnTfZQLkXDzaeEqMu2Lt+USJs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737069439; c=relaxed/simple; bh=3biTJFdUOXAOi6w31VGG1oNYsJz079fKm5kofQxzt+Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MuV2GC8f83XQtiHohPF6ucxyaodXd9fcKa85lK3yXfeoggafms7P8oOTME4A9bmumOESCUWn3in4XtZz1azQ7q1juhPiFRWibQDna34xXtaRCrBzxA1sJ6e6JrNIil5xPIY3SG/HxiM+QttVfrKrBhvEtztSe180oCbYrjq4/uM= 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=ObnjEmLP; arc=none smtp.client-ip=209.85.214.175 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="ObnjEmLP" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-2166022c5caso25446295ad.2 for ; Thu, 16 Jan 2025 15:17:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=davidwei-uk.20230601.gappssmtp.com; s=20230601; t=1737069437; x=1737674237; 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=5HjpNvJntS7mBirVUx5S3IKUa/AMALIP3oGkqWJMCMM=; b=ObnjEmLPm4ke28zV+LBCFYXXF0f78cuQ1qVbVaZuHg9enLI4SHoGkdJIX+v+9KjNXy 0HamaGJHzQNMDARDz1mfJVhcoGG4jLoqzgTL790I76NtU1LpdAuV6U5agRPmRnZNmy8Z OXfSrysnXdK9MyNU3nbY/+FvP0jA+JAp4LAtfo42VnaWT1Hw/qCVFRv8Xz3OPtjHp82V LESNSx3+PW/3pWhRHckkl3B/wLE+xuSxe6AiKhDI2+mZtVy6nC/OiO+NipC2CRg9eeeJ FDuOg4gxfAWoSH/NpB6RzCwKhIX4Uw8knp+57nO0wk7OQjQke6nwfrdCgf2lrlNay6UM b9iQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737069437; x=1737674237; 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=5HjpNvJntS7mBirVUx5S3IKUa/AMALIP3oGkqWJMCMM=; b=aKXi6mRPLdVuG+SSKBbWIoo6TeTtniU5TJyHy+9Zy2FobGZtIVxprnqyB9xE/72+5M F4g2fyRuTBSNLbYxak0llbzXTayaMa1VT2yZ1uKchhnWWCcktHU/MCYtreN5OsWbOuvt JKvBhx9e85UipsGUt68gp5Entz+2w/oSkJWYP2f3kWo5gylHi+/9MUfcJPZBrqrY7YiN gEIgMN+2s3T2S4cQ3S9UNge7DDWjOprCqapqeCnWKgwrjyN+qK3mKo6VOa71DDEdKCOy J1hkNQTi27D6dN9eDUaPJGSj/zT3rSfDpCISwpoO1+Pk6lUZhb41yuBgBpAmjOQoYA/J GDqw== X-Forwarded-Encrypted: i=1; AJvYcCWM7xkxEoNbPkyfXk5eiFPZ0MjpXTIzFGQY46fBDF+A0Gg8+k0OsB5f3zvoKZMlAl8+/xStftc=@vger.kernel.org X-Gm-Message-State: AOJu0Yyxg3SQbbutyoIzmeqCulQJf74pTfe2iWMS/7huqYKiABcPnGJG ToKpXcgqTHPRwlzRlFydesT7LCdcEHbJd1uMGeoMwsQMKj9LblUvtoZzRvqktp4= X-Gm-Gg: ASbGncuhKcnlehWHZKMrGAhO5uKmr1ppxvAb5MAwwGi32F59+iG7qhnulYTxBRHonqz PKyEPDuuUSOLsGNa4hF2KAcRKmN3K6dz60FMiSXr3cvwcfOpqaHfwshrt9cC/cfFDm5Dk3UNw6n eLsvP7vneYWITNTB7X8juDlDGIMN4U7vALQ+CCZABmic44J0mp20ZuZAOGiPIDqSHAGrmfcobNt WA9babBNanYct14OgyWPoSxDmja16meK64gVg6J4g== X-Google-Smtp-Source: AGHT+IHkrl3VnkvScu3B92v7++EOueBneTakU3T0NPFC7aQQKHJ5Vd70/bRIrDYsb9C8jV9/X3+wng== X-Received: by 2002:a17:902:ea03:b0:215:b33b:e26d with SMTP id d9443c01a7336-21c3550c5d3mr8824175ad.21.1737069436984; Thu, 16 Jan 2025 15:17:16 -0800 (PST) Received: from localhost ([2a03:2880:ff:13::]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21c2d402e5esm4889275ad.210.2025.01.16.15.17.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jan 2025 15:17:16 -0800 (PST) From: David Wei To: io-uring@vger.kernel.org, netdev@vger.kernel.org Cc: Jens Axboe , Pavel Begunkov , Jakub Kicinski , Paolo Abeni , "David S. Miller" , Eric Dumazet , Jesper Dangaard Brouer , David Ahern , Mina Almasry , Stanislav Fomichev , Joe Damato , Pedro Tammela Subject: [PATCH net-next v11 07/21] net: page_pool: add a mp hook to unregister_netdevice* Date: Thu, 16 Jan 2025 15:16:49 -0800 Message-ID: <20250116231704.2402455-8-dw@davidwei.uk> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250116231704.2402455-1-dw@davidwei.uk> References: <20250116231704.2402455-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 Devmem TCP needs a hook in unregister_netdevice_many_notify() to upkeep the set tracking queues it's bound to, i.e. ->bound_rxqs. Instead of devmem sticking directly out of the genetic path, add a mp function. Reviewed-by: Jakub Kicinski Reviewed-by: Mina Almasry Signed-off-by: Pavel Begunkov Signed-off-by: David Wei --- include/net/page_pool/memory_provider.h | 1 + net/core/dev.c | 16 ++++++++++- net/core/devmem.c | 36 +++++++++++-------------- net/core/devmem.h | 5 ---- 4 files changed, 32 insertions(+), 26 deletions(-) diff --git a/include/net/page_pool/memory_provider.h b/include/net/page_pool/memory_provider.h index 6d10a0959d00..36469a7e649f 100644 --- a/include/net/page_pool/memory_provider.h +++ b/include/net/page_pool/memory_provider.h @@ -15,6 +15,7 @@ struct memory_provider_ops { void (*destroy)(struct page_pool *pool); int (*nl_fill)(void *mp_priv, struct sk_buff *rsp, struct netdev_rx_queue *rxq); + void (*uninstall)(void *mp_priv, struct netdev_rx_queue *rxq); }; #endif diff --git a/net/core/dev.c b/net/core/dev.c index c7f3dea3e0eb..1d99974e8fba 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -157,6 +157,7 @@ #include #include #include +#include #include #include @@ -11464,6 +11465,19 @@ void unregister_netdevice_queue(struct net_device *dev, struct list_head *head) } EXPORT_SYMBOL(unregister_netdevice_queue); +static void dev_memory_provider_uninstall(struct net_device *dev) +{ + unsigned int i; + + for (i = 0; i < dev->real_num_rx_queues; i++) { + struct netdev_rx_queue *rxq = &dev->_rx[i]; + struct pp_memory_provider_params *p = &rxq->mp_params; + + if (p->mp_ops && p->mp_ops->uninstall) + p->mp_ops->uninstall(rxq->mp_params.mp_priv, rxq); + } +} + void unregister_netdevice_many_notify(struct list_head *head, u32 portid, const struct nlmsghdr *nlh) { @@ -11516,7 +11530,7 @@ void unregister_netdevice_many_notify(struct list_head *head, dev_tcx_uninstall(dev); dev_xdp_uninstall(dev); bpf_dev_bound_netdev_unregister(dev); - dev_dmabuf_uninstall(dev); + dev_memory_provider_uninstall(dev); netdev_offload_xstats_disable_all(dev); diff --git a/net/core/devmem.c b/net/core/devmem.c index c0bde0869f72..6f46286d45a9 100644 --- a/net/core/devmem.c +++ b/net/core/devmem.c @@ -309,26 +309,6 @@ net_devmem_bind_dmabuf(struct net_device *dev, unsigned int dmabuf_fd, return ERR_PTR(err); } -void dev_dmabuf_uninstall(struct net_device *dev) -{ - struct net_devmem_dmabuf_binding *binding; - struct netdev_rx_queue *rxq; - unsigned long xa_idx; - unsigned int i; - - for (i = 0; i < dev->real_num_rx_queues; i++) { - binding = dev->_rx[i].mp_params.mp_priv; - if (!binding) - continue; - - xa_for_each(&binding->bound_rxqs, xa_idx, rxq) - if (rxq == &dev->_rx[i]) { - xa_erase(&binding->bound_rxqs, xa_idx); - break; - } - } -} - /*** "Dmabuf devmem memory provider" ***/ int mp_dmabuf_devmem_init(struct page_pool *pool) @@ -404,10 +384,26 @@ static int mp_dmabuf_devmem_nl_fill(void *mp_priv, struct sk_buff *rsp, return nla_put_u32(rsp, type, binding->id); } +static void mp_dmabuf_devmem_uninstall(void *mp_priv, + struct netdev_rx_queue *rxq) +{ + struct net_devmem_dmabuf_binding *binding = mp_priv; + struct netdev_rx_queue *bound_rxq; + unsigned long xa_idx; + + xa_for_each(&binding->bound_rxqs, xa_idx, bound_rxq) { + if (bound_rxq == rxq) { + xa_erase(&binding->bound_rxqs, xa_idx); + break; + } + } +} + static const struct memory_provider_ops dmabuf_devmem_ops = { .init = mp_dmabuf_devmem_init, .destroy = mp_dmabuf_devmem_destroy, .alloc_netmems = mp_dmabuf_devmem_alloc_netmems, .release_netmem = mp_dmabuf_devmem_release_page, .nl_fill = mp_dmabuf_devmem_nl_fill, + .uninstall = mp_dmabuf_devmem_uninstall, }; diff --git a/net/core/devmem.h b/net/core/devmem.h index a2b9913e9a17..8e999fe2ae67 100644 --- a/net/core/devmem.h +++ b/net/core/devmem.h @@ -68,7 +68,6 @@ void net_devmem_unbind_dmabuf(struct net_devmem_dmabuf_binding *binding); int net_devmem_bind_dmabuf_to_queue(struct net_device *dev, u32 rxq_idx, struct net_devmem_dmabuf_binding *binding, struct netlink_ext_ack *extack); -void dev_dmabuf_uninstall(struct net_device *dev); static inline struct dmabuf_genpool_chunk_owner * net_devmem_iov_to_chunk_owner(const struct net_iov *niov) @@ -145,10 +144,6 @@ net_devmem_bind_dmabuf_to_queue(struct net_device *dev, u32 rxq_idx, return -EOPNOTSUPP; } -static inline void dev_dmabuf_uninstall(struct net_device *dev) -{ -} - static inline struct net_iov * net_devmem_alloc_dmabuf(struct net_devmem_dmabuf_binding *binding) { From patchwork Thu Jan 16 23:16:50 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wei X-Patchwork-Id: 13942452 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (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 28C3C242258 for ; Thu, 16 Jan 2025 23:17:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737069440; cv=none; b=LnB/pT6t62AH2Nwmqbyf2/cbZ2ZOFrElT0q6ldTeWfZYmMsPq8N3aq7nhMIj1Rg69KAUa/jw+QlogpsoRJlMD/73AjpeV5QvQ+cCW+bM5jjlaUt2C4RUjHuecKMxagQosPO3q2JACH5JFRGX/igX+0k9T50Odd3cpXbyGA+b4ZE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737069440; c=relaxed/simple; bh=Bd0rHranX1tldtf5eS5ic1T+HB/zykxgLBff110E+Tw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=njsGn50veCbJQsaqfLdinvsvyBJtmNEzDOKQEdyZDt7k0fwEmKF6ZTKc+FJnOosxirMf6nQWIBEpYY7j3pNfRr37CsSvb42ia235qQyRq3rVQp8y8H5RwgQLzHPqTINJFsETTL8eR2n0BDGY9uRieNu8xysRwSd4acBZLtHzggE= 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=1BvuGejL; arc=none smtp.client-ip=209.85.214.175 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="1BvuGejL" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-216426b0865so26441775ad.0 for ; Thu, 16 Jan 2025 15:17:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=davidwei-uk.20230601.gappssmtp.com; s=20230601; t=1737069438; x=1737674238; 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=/iXcgdxDm1mzjOKK5nUQi77bzCX5UD7reUTrJiMtg6k=; b=1BvuGejLUKIaFsJY01YRJJpxfShA9DDGu98LWb3kXEhtlS4OpKgwwH/gmRC3etK+WD aov8vpvXkLt/Vo0ClzCljk/s1O3FJZ7lYE1oCC73SahqRniljbVsdnrY35BI05AYn22P 6Ou6rzU4AzXAuG11Aw/ei+8eZCgIwugJaJcGSVY4c/4vZLYi8Ymh0rND5t2jatI6j3MV ztFP3neUioXHNwAQxfcZTFLI4FAOC+ZFhl2BgPmO/k2GyXENnLLWgwEFpTHZ8Sv6n13v AMhLJzJFRr66wIGW0U46z2sp7WKrEPuqXqxBI28nSgGHKVakiE534QUqfMR0rCjxCu6z YuXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737069438; x=1737674238; 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=/iXcgdxDm1mzjOKK5nUQi77bzCX5UD7reUTrJiMtg6k=; b=kSqHo1KhPE9MP27RW4Yy6YY9W1nkzmvLFFt4M9EkHFDRbu5vzv9JTg6zSyZhY5FdLK kC4syTLr82Pg2l7YHyhksyffMII4ebMhUis8yiFl0JhWmdYcJSo/QW2B8x3VhHqYSupD 8CD+0oLo62JGktsAU3cQgsRQ0EM87DWYWajFKHM6kWj3qww/tgXR46cv6xKpiszgY8l1 MdW10ZGlznwJjLF8FBMpjdtor90PG4/PLuTsFE66t6O/FDC61rVKZXIn92Nup603zC89 d5rvl3+aIYXIux9/HaLLXybQUryCBUGcgdgNQV0F0gFxeW8tO31j3Awx4ArC83tnbEo4 du3w== X-Forwarded-Encrypted: i=1; AJvYcCV/VEtPz87r4zzds46r/A4e4ozlgHXRx095zlxjP+7JrOPvjqczUhjl3C9V5qHVc+ZBBUpwbkU=@vger.kernel.org X-Gm-Message-State: AOJu0YxVEIt9pjYtVka5abjzhas6Hd4mycDAyYZ4XZHmVHJx1D936Hlu 5ZE0aGKXh1eMIHARGPFWJLbgCibFT+SkQqFmA+oKmYrBjR1AEL/F/PahDNfJ+4w= X-Gm-Gg: ASbGnctLmNQtcZinJbLWggHQ1Axc2aVLPJcdGll+/DBinDKl2Zo0qzLcpV2gRuT29cP +ZI1VWpDzFhicOx1aQo8Bh8siz/jW/LWOJSi9d1QM5K/NtpuQsXRsa4TS+8QU7cv6goJkofKuj/ Uqm1uR8Yt2It66i59+Mborvpha2on1tkUaH8z6jYQHsslA2doaIg2eYVFNCMfK35pYZOMKwX2C8 CKFLYN6h5LlG+xs8vvXapr9abKamq+FDg1QLS6JtC5KqnodWKO9gzs= X-Google-Smtp-Source: AGHT+IEUoQ3cQyeHfrq22BsAqcBQmEnXUFvqOsKhuiuJqY8cqjIMnKVKwPNr5PaVO+MY+927WWp7UQ== X-Received: by 2002:a05:6a00:1f11:b0:71e:2a0:b0b8 with SMTP id d2e1a72fcca58-72daf92ac24mr972238b3a.1.1737069437894; Thu, 16 Jan 2025 15:17:17 -0800 (PST) Received: from localhost ([2a03:2880:ff:72::]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72dab9c8e5asm525688b3a.120.2025.01.16.15.17.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jan 2025 15:17:17 -0800 (PST) From: David Wei To: io-uring@vger.kernel.org, netdev@vger.kernel.org Cc: Jens Axboe , Pavel Begunkov , Jakub Kicinski , Paolo Abeni , "David S. Miller" , Eric Dumazet , Jesper Dangaard Brouer , David Ahern , Mina Almasry , Stanislav Fomichev , Joe Damato , Pedro Tammela Subject: [PATCH net-next v11 08/21] net: prepare for non devmem TCP memory providers Date: Thu, 16 Jan 2025 15:16:50 -0800 Message-ID: <20250116231704.2402455-9-dw@davidwei.uk> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250116231704.2402455-1-dw@davidwei.uk> References: <20250116231704.2402455-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. Reviewed-by: Mina Almasry Reviewed-by: Jakub Kicinski Signed-off-by: Pavel Begunkov Signed-off-by: David Wei --- net/core/devmem.c | 5 +++++ net/core/devmem.h | 7 +++++++ net/ipv4/tcp.c | 5 +++++ 3 files changed, 17 insertions(+) diff --git a/net/core/devmem.c b/net/core/devmem.c index 6f46286d45a9..8fcb0c7b63be 100644 --- a/net/core/devmem.c +++ b/net/core/devmem.c @@ -29,6 +29,11 @@ static DEFINE_XARRAY_FLAGS(net_devmem_dmabuf_bindings, XA_FLAGS_ALLOC1); static const struct memory_provider_ops dmabuf_devmem_ops; +bool net_is_devmem_iov(struct net_iov *niov) +{ + return niov->pp->mp_ops == &dmabuf_devmem_ops; +} + static void net_devmem_dmabuf_free_chunk_owner(struct gen_pool *genpool, struct gen_pool_chunk *chunk, void *not_used) diff --git a/net/core/devmem.h b/net/core/devmem.h index 8e999fe2ae67..7fc158d52729 100644 --- a/net/core/devmem.h +++ b/net/core/devmem.h @@ -115,6 +115,8 @@ struct net_iov * net_devmem_alloc_dmabuf(struct net_devmem_dmabuf_binding *binding); void net_devmem_free_dmabuf(struct net_iov *ppiov); +bool net_is_devmem_iov(struct net_iov *niov); + #else struct net_devmem_dmabuf_binding; @@ -163,6 +165,11 @@ static inline u32 net_devmem_iov_binding_id(const struct net_iov *niov) { return 0; } + +static inline bool net_is_devmem_iov(struct net_iov *niov) +{ + return false; +} #endif #endif /* _NET_DEVMEM_H */ diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index b872de9a8271..7f43d31c9400 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -2476,6 +2476,11 @@ static int tcp_recvmsg_dmabuf(struct sock *sk, const struct sk_buff *skb, } niov = skb_frag_net_iov(frag); + if (!net_is_devmem_iov(niov)) { + err = -ENODEV; + goto out; + } + end = start + skb_frag_size(frag); copy = end - offset; From patchwork Thu Jan 16 23:16:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wei X-Patchwork-Id: 13942453 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (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 8ACD22442E4 for ; Thu, 16 Jan 2025 23:17:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737069441; cv=none; b=qgncBqCU8z2SEBUR1e91KMiWAQXxp0XzzR04N4GnuVcq8rLRgVA0ynFmMrxW7UeIAYD7jPXWd01Jrm3flY1Al/zXD6AOpH8LZuYEQax6WJJwkmPAUdr01NEocXYAu2F3iS6beTetYZuLcjMfw2iJleQzAuuTN6UOMrydYRCtKhY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737069441; c=relaxed/simple; bh=Wu2YRL7RxGBa3+VVAsLlSidmaKFoJfO1MRmnPiP9er0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=n5QTT/Ld+4OFGOZauzJM2BEukbeF6ZhuF+4eMEdX0bbg6y4LcWrsT098bu7kWhH+OYylOGnqw9wccrNYEqrqRpk9BA5d0HPOrSLww3JtlKvVMATWAG3IAIJ7QhWBMxV2TIpusCGzhr8rYnkPD1DpEDGAknLumgQqDidwmmwSLTc= 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=zlOixvM1; arc=none smtp.client-ip=209.85.214.172 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="zlOixvM1" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-21669fd5c7cso26686875ad.3 for ; Thu, 16 Jan 2025 15:17:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=davidwei-uk.20230601.gappssmtp.com; s=20230601; t=1737069439; x=1737674239; 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=7Be6ZuIxyPYoB8SUKHgFZ6AvvdZELR/KF5QFQIGoyyg=; b=zlOixvM1pO1OvomSXVs87T2Y8l4g7F2wxU2ukXBMNgomPNcAoQ2YMW2Zo0oeGC7Yl8 /+NKcXm7BCfVOEF0mrkAzHxmBJkHgvELQqwRNSI+DkyCcPyVYPNdKXJ3M9/trktLBw2r SfqUFxtA2B73EfMi2qUhluiB9kRCyswnb3Kss2sETWxnLoIw7V1i+auY87JYAP2IYEvX a1hcnFwJPtaF1twfjQjhNbXX3yGkyCxd8VwadR8STNmZkVVbd3/euuXZguNpq4BTvqB4 hpyvbObmo+hhRPc+XRXW19VjHndAYZoiskSVKbQWbXHlV6GlKjaND9hYCiBpm8kekgVX mThg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737069439; x=1737674239; 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=7Be6ZuIxyPYoB8SUKHgFZ6AvvdZELR/KF5QFQIGoyyg=; b=pEqAf5FwzoeupCEC675kFzpH7OP1scRrvIeSuMFP3J0W72MXuRwSSBwy4b3cwGVWsF a7vd5Z/7BtELmbxhdmogTUw7BoiREM5xEPK/riwZrRoPuQOciEc/lhuigPK6YdULk5ba JEUUhVqMxNG4quL0ZsoDiSQVY6KOKdLjKcZzaHR1Ragir8TuM7BtOFg8yeG25y4fsfn3 NT1yR6hzVy6oHA+ifJE5hy8KyMPdiRR/73rmK+pKqQS0EkN3HxkNmwuMFHK0r4hRP494 AIiwusgqeigweMy94jbleiTg7VrELDMw2Xm1lWUeAzWPQAWHBat2K4i/iTqu7PopZwDG vEZw== X-Forwarded-Encrypted: i=1; AJvYcCWeDhYTrvRroUh6TkVy/CJqDrq5ogbc/dqoWY73NsItXEkOm7lfdKYvpPE85qZ5YV5a26d2BoU=@vger.kernel.org X-Gm-Message-State: AOJu0YyPl/M8AqzyCDwzUH7aVitraa/hivRetpfrfaYzTz3R07cD0Uw/ aPKe3SA+foePYUy+IrK4X9ThZUMzS3nYLzMvADlUPgtz1xOH8JYqLvx9Hf/KfHg= X-Gm-Gg: ASbGncuShTkXWBFxAh5BGOnqP9pmmhmVzo2OfuDCRN3/Q8yCHbgZ+sLnHrOpPJ+80WC AcVA/TUADSJqUpKIwbzY3a7V8qvFS/d+QFQCFLPzQI/60DLU8HO+BchL7DgQPwa7hy7f8DSs3FL D1c4qM/yfsdqo9ZOE4cMsPxMtMBUtO+jZs8S3iAyHTrqY3EPe/UWDeZyABQk5ryny3HNzdQpb6r IIu5XLoT5ONbAdotugp212fvYSUc+hzPj6w422Y X-Google-Smtp-Source: AGHT+IG4BvB515N3766JxYciwfUXHMvi1fRLt7Mh9m0zlJqgYdA6QEwqcr09WZiN+pXYGb6wkv8pFg== X-Received: by 2002:a17:903:234b:b0:216:7aab:71f0 with SMTP id d9443c01a7336-21c355c0810mr9551615ad.38.1737069438863; Thu, 16 Jan 2025 15:17:18 -0800 (PST) Received: from localhost ([2a03:2880:ff:6::]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21c2ceb76dfsm5199635ad.61.2025.01.16.15.17.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jan 2025 15:17:18 -0800 (PST) From: David Wei To: io-uring@vger.kernel.org, netdev@vger.kernel.org Cc: Jens Axboe , Pavel Begunkov , Jakub Kicinski , Paolo Abeni , "David S. Miller" , Eric Dumazet , Jesper Dangaard Brouer , David Ahern , Mina Almasry , Stanislav Fomichev , Joe Damato , Pedro Tammela Subject: [PATCH net-next v11 09/21] net: page_pool: add memory provider helpers Date: Thu, 16 Jan 2025 15:16:51 -0800 Message-ID: <20250116231704.2402455-10-dw@davidwei.uk> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250116231704.2402455-1-dw@davidwei.uk> References: <20250116231704.2402455-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 Add helpers for memory providers to interact with page pools. net_mp_niov_{set,clear}_page_pool() serve to [dis]associate a net_iov with a page pool. If used, the memory provider is responsible to match "set" calls with "clear" once a net_iov is not going to be used by a page pool anymore, changing a page pool, etc. Signed-off-by: Pavel Begunkov Signed-off-by: David Wei Acked-by: Jakub Kicinski --- include/net/page_pool/memory_provider.h | 19 +++++++++++++++++ net/core/page_pool.c | 28 +++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/include/net/page_pool/memory_provider.h b/include/net/page_pool/memory_provider.h index 36469a7e649f..4f0ffb8f6a0a 100644 --- a/include/net/page_pool/memory_provider.h +++ b/include/net/page_pool/memory_provider.h @@ -18,4 +18,23 @@ struct memory_provider_ops { void (*uninstall)(void *mp_priv, struct netdev_rx_queue *rxq); }; +bool net_mp_niov_set_dma_addr(struct net_iov *niov, dma_addr_t addr); +void net_mp_niov_set_page_pool(struct page_pool *pool, struct net_iov *niov); +void net_mp_niov_clear_page_pool(struct net_iov *niov); + +/** + * net_mp_netmem_place_in_cache() - give a netmem to a page pool + * @pool: the page pool to place the netmem into + * @netmem: netmem to give + * + * Push an accounted netmem into the page pool's allocation cache. The caller + * must ensure that there is space in the cache. It should only be called off + * the mp_ops->alloc_netmems() path. + */ +static inline void net_mp_netmem_place_in_cache(struct page_pool *pool, + netmem_ref netmem) +{ + pool->alloc.cache[pool->alloc.count++] = netmem; +} + #endif diff --git a/net/core/page_pool.c b/net/core/page_pool.c index 24e2e2efb1eb..6a9eb2da5f6d 100644 --- a/net/core/page_pool.c +++ b/net/core/page_pool.c @@ -1196,3 +1196,31 @@ void page_pool_update_nid(struct page_pool *pool, int new_nid) } } EXPORT_SYMBOL(page_pool_update_nid); + +bool net_mp_niov_set_dma_addr(struct net_iov *niov, dma_addr_t addr) +{ + return page_pool_set_dma_addr_netmem(net_iov_to_netmem(niov), addr); +} + +/* Associate a niov with a page pool. Should follow with a matching + * net_mp_niov_clear_page_pool() + */ +void net_mp_niov_set_page_pool(struct page_pool *pool, struct net_iov *niov) +{ + netmem_ref netmem = net_iov_to_netmem(niov); + + page_pool_set_pp_info(pool, netmem); + + pool->pages_state_hold_cnt++; + trace_page_pool_state_hold(pool, netmem, pool->pages_state_hold_cnt); +} + +/* Disassociate a niov from a page pool. Should only be used in the + * ->release_netmem() path. + */ +void net_mp_niov_clear_page_pool(struct net_iov *niov) +{ + netmem_ref netmem = net_iov_to_netmem(niov); + + page_pool_clear_pp_info(netmem); +} From patchwork Thu Jan 16 23:16:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wei X-Patchwork-Id: 13942454 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 8E61D2442FF for ; Thu, 16 Jan 2025 23:17:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737069442; cv=none; b=hQn4+48oS1jkbRlFL5ylLvRKRB9R4gRzTFe5E+z9O4ILnAgm8k8b4RhgDxyO0LmZykt5q81gDl9oY6rooKCqJZ4GS5iLZ2udP8w2cyoHEPXaN+IcFt/gED1WuYaomZI73oImr1vJjuKZffDA60pYnrP9uJel3vqZ7aT8J/8FYm8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737069442; c=relaxed/simple; bh=ni+GBCJpV+6e9Z3Jx+ASe5psY3mF/X+C2+8/GRsJcxU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jNORI+FqyhNWdbb+wYCt1DQX0G/v61E0vA7M3ztYTuOnJb1LCxBLCUPEmcmtFMWBmmicOGdkuFrCZI5ETCU374nA7O++9nvyrg0TBU3sWmi6tBapusqLtQjj60zMd0Z1gX4r3TUkFsCTf86vDjUVNIO4kTDj6E8j3/8UVAhaZws= 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=Rs06UutY; arc=none smtp.client-ip=209.85.214.181 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="Rs06UutY" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-21636268e43so34638025ad.2 for ; Thu, 16 Jan 2025 15:17:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=davidwei-uk.20230601.gappssmtp.com; s=20230601; t=1737069440; x=1737674240; 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=kNe5O6sLZLRlzUpONmh0BhOdwH0c/mpvhiy7fWtyNiI=; b=Rs06UutYlsnhpgzvSNFfgyJIVRU4l0AcgCtBvZi09Wxd+e8cXken7IlHlEjKd60Auu 5onojg0PGDSW3qSjuvrECOqkllCnwjAvEIkgLBmBwrP9U4x9+4neS/lyROHMZjj1uluI FxaHx49+DF5RcPd1LPF/qgMMv+Wa8tonaDUsZFAYdDXFFsCy4yayoJ++4eI0CruRVZ8n cQK3PgdawqfijStdqc2r9spxyzVrBd3eQrmhR6s58EBEvIvh2GeXcYQB/x4OWENB2/wg S8FWR4D54vPaJq2kWlByJDkZxGQfHtlXpaDrIOGZL+4BX4Rx2N3k4GeLWV5DgrG1BdBh VzbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737069440; x=1737674240; 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=kNe5O6sLZLRlzUpONmh0BhOdwH0c/mpvhiy7fWtyNiI=; b=OsZDsNP4YaN3Dsr9BW91zFOct8vkAHEKqaQ4yAQR2yVXWWzmCG2ylgTemfF9GgnTiq XmPpdgi8Mczr8xBHd1lATqoLFqAmMGN/RMlk/nX/zh6jGA9umva+sxF9bGs5Y6VhvGG8 1khI8i5sfcSbMvzt+OXh+RqQRvkLupVGNYGGlP5+2g14u89wzQK5AX/Mxo61j0nKlj/p gT7RHPdGT9+z+ZMivODxyJ/1YbR53/mpNyF1DFhu/Hcn8LNFs2xHwQYkFAw0p+e2kufa CYOHhivE8poEyPS22XPAsMS4Qu4D9rmpa5kixGC4WzWxAeMyholR9j3EyOpQp1qOlspo 0KaA== X-Forwarded-Encrypted: i=1; AJvYcCVvOcRJm4NTQ9XLqh0pJb34Wd8wZkxwJyE6w4wADDhdrp+/l3484PVNJXo6RA07lTtI1OgNlwg=@vger.kernel.org X-Gm-Message-State: AOJu0YyVkvvwdq4cRzjOpdhEuXS1n9Mz8zWi4cz1lS7T2zDS1VVCFEhg wxDU0YHHzlnTP7WyCudVv2RUpRCP4NxXQMoAS2Wk/GmZ7zaIu0yalDqluvHj6QE= X-Gm-Gg: ASbGncvPJWYllznP11Ia55ZUoPTMBPxbhPcN+HGTGQM0k/DzFfk51ffWoGkJQV20Cr1 EdmJvlZTSaQ9fLAJL0FtZZ6v4eiSf9phzsreL0Xol+4XNgZ5MHhW5nfYvPdOwTf7/SSKCBetuO2 Y7r1JYFTcLUtovebZj9J4sAYJRw6+GOWfswzUL1R+S5MJniJnRYE5M3/GEsFaDSQRLram6ThuMs kv5jagmCFKJr6vdLG1MI3sMKwFSEgBAvUwmIXw3f+NlN0M23AU= X-Google-Smtp-Source: AGHT+IFPCVAzi3Y7iLEYB+1MNFlWMBosh0pxQi8qGeMSUjYARBehDaU52qL2+q2dZYAo0YhvuCRF+A== X-Received: by 2002:a05:6a00:330b:b0:724:59e0:5d22 with SMTP id d2e1a72fcca58-72dafba2625mr993459b3a.20.1737069439794; Thu, 16 Jan 2025 15:17:19 -0800 (PST) Received: from localhost ([2a03:2880:ff::]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72dab9c9462sm547474b3a.100.2025.01.16.15.17.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jan 2025 15:17:19 -0800 (PST) From: David Wei To: io-uring@vger.kernel.org, netdev@vger.kernel.org Cc: Jens Axboe , Pavel Begunkov , Jakub Kicinski , Paolo Abeni , "David S. Miller" , Eric Dumazet , Jesper Dangaard Brouer , David Ahern , Mina Almasry , Stanislav Fomichev , Joe Damato , Pedro Tammela Subject: [PATCH net-next v11 10/21] net: add helpers for setting a memory provider on an rx queue Date: Thu, 16 Jan 2025 15:16:52 -0800 Message-ID: <20250116231704.2402455-11-dw@davidwei.uk> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250116231704.2402455-1-dw@davidwei.uk> References: <20250116231704.2402455-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 Add helpers that properly prep or remove a memory provider for an rx queue then restart the queue. Signed-off-by: Pavel Begunkov Signed-off-by: David Wei Reviewed-by: Jakub Kicinski --- include/net/page_pool/memory_provider.h | 5 ++ net/core/netdev_rx_queue.c | 66 +++++++++++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/include/net/page_pool/memory_provider.h b/include/net/page_pool/memory_provider.h index 4f0ffb8f6a0a..b3e665897767 100644 --- a/include/net/page_pool/memory_provider.h +++ b/include/net/page_pool/memory_provider.h @@ -22,6 +22,11 @@ bool net_mp_niov_set_dma_addr(struct net_iov *niov, dma_addr_t addr); void net_mp_niov_set_page_pool(struct page_pool *pool, struct net_iov *niov); void net_mp_niov_clear_page_pool(struct net_iov *niov); +int net_mp_open_rxq(struct net_device *dev, unsigned ifq_idx, + struct pp_memory_provider_params *p); +void net_mp_close_rxq(struct net_device *dev, unsigned ifq_idx, + struct pp_memory_provider_params *old_p); + /** * net_mp_netmem_place_in_cache() - give a netmem to a page pool * @pool: the page pool to place the netmem into diff --git a/net/core/netdev_rx_queue.c b/net/core/netdev_rx_queue.c index e217a5838c87..e934568d4cd9 100644 --- a/net/core/netdev_rx_queue.c +++ b/net/core/netdev_rx_queue.c @@ -3,6 +3,7 @@ #include #include #include +#include #include "page_pool_priv.h" @@ -79,3 +80,68 @@ int netdev_rx_queue_restart(struct net_device *dev, unsigned int rxq_idx) return err; } + +static int __net_mp_open_rxq(struct net_device *dev, unsigned ifq_idx, + struct pp_memory_provider_params *p) +{ + struct netdev_rx_queue *rxq; + int ret; + + if (ifq_idx >= dev->real_num_rx_queues) + return -EINVAL; + ifq_idx = array_index_nospec(ifq_idx, dev->real_num_rx_queues); + + rxq = __netif_get_rx_queue(dev, ifq_idx); + if (rxq->mp_params.mp_ops) + return -EEXIST; + + rxq->mp_params = *p; + ret = netdev_rx_queue_restart(dev, ifq_idx); + if (ret) { + rxq->mp_params.mp_ops = NULL; + rxq->mp_params.mp_priv = NULL; + } + return ret; +} + +int net_mp_open_rxq(struct net_device *dev, unsigned ifq_idx, + struct pp_memory_provider_params *p) +{ + int ret; + + rtnl_lock(); + ret = __net_mp_open_rxq(dev, ifq_idx, p); + rtnl_unlock(); + return ret; +} + +static void __net_mp_close_rxq(struct net_device *dev, unsigned ifq_idx, + struct pp_memory_provider_params *old_p) +{ + struct netdev_rx_queue *rxq; + int ret; + + if (WARN_ON_ONCE(ifq_idx >= dev->real_num_rx_queues)) + return; + + rxq = __netif_get_rx_queue(dev, ifq_idx); + + if (WARN_ON_ONCE(rxq->mp_params.mp_ops != old_p->mp_ops || + rxq->mp_params.mp_priv != old_p->mp_priv)) + return; + + rxq->mp_params.mp_ops = NULL; + rxq->mp_params.mp_priv = NULL; + ret = netdev_rx_queue_restart(dev, ifq_idx); + if (ret) + pr_devel("Could not restart queue %u after removing memory provider.\n", + ifq_idx); +} + +void net_mp_close_rxq(struct net_device *dev, unsigned ifq_idx, + struct pp_memory_provider_params *old_p) +{ + rtnl_lock(); + __net_mp_close_rxq(dev, ifq_idx, old_p); + rtnl_unlock(); +} From patchwork Thu Jan 16 23:16:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wei X-Patchwork-Id: 13942456 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (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 C2B96244F82 for ; Thu, 16 Jan 2025 23:17:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737069444; cv=none; b=JT4v+JYjITTt+cS/XaxDSAsaln/vL9IBvyi1zdkO+LntflGoxojoqOnUtC+J5gT7HyJ2vn738tPxcuvU3+GjvZc7XUUZ8+4ER5uaVIqItVv2LFObd9ClmbwNfNZu4yxZ7Tzk9AtpBCaDSyAwEH7dncI8nX+8gvuZryZKN8i7DVo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737069444; c=relaxed/simple; bh=naGHykPCFniyVspq3/qrf1hb5UiMHZZj43LEdVC/S7s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RaOH1NJSGZzGA+4w8vMPLUBtxrtvoF0ZaX4qx8ox0n4pZPBpI1crGyqs5e+kEPIv2p4WyB7+o29oNocHQ3Si8t3rVJTvOB2BGSFNfEuJZ0rDdd3GgoKl2hxiBny5W8VcstdSrrkREpvrS3CFIvUslnIpURW51kcGQb0aOWzgPmA= 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=LdUMu5i+; arc=none smtp.client-ip=209.85.214.177 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="LdUMu5i+" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-21644aca3a0so34605615ad.3 for ; Thu, 16 Jan 2025 15:17:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=davidwei-uk.20230601.gappssmtp.com; s=20230601; t=1737069442; x=1737674242; 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=QFeVztGJ0Opek7DCa1BcFSjSzFZpJHDDY/O4Y65sHAo=; b=LdUMu5i+2GmcSIykf0Tb8FT4OcQxe/dZmf4VNoQCzYFOEcKk8qONiFHK902rFKbbbH 6y2hoTi/JQ62Zrjsoc1MAiVHcx/QA0sIXjHkjsWMGmuYHcvRcoce49NTJaXyLRiCyDTO MmLGWRbOVQg65rmNSExSNAyuSgAbx1WOpEMj+0Rb7gfucRy7Z98ttPOUP9Q6EKwj8DjO rjaMPOQsGIeX/Ey4/K8vqTIMMDtntuejRq8p+R5LAFMnQqDy0GM2aTGthJdGiOwgIhki /FX+KyxrhHY01KKtCv3E6A+pfkOG4hGJGj51+Du5PPAu/okx+hh6a2fpbQ/5B2To1344 8asg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737069442; x=1737674242; 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=QFeVztGJ0Opek7DCa1BcFSjSzFZpJHDDY/O4Y65sHAo=; b=axTT/uzKlr6aCX5mEtu2OI8uEgRS2kXJa48YtsoSYial5E6qZtUbEToyvNCHPd/ynJ qNc4rpdYgmIMUby85A4w9plWmr3RHeph0g968KCgEFPvSc+r/e1xLyqMTIZXT+uiq4EV KEYMshDtU822gAAWTkvrABh3VjnO97o9T1Wn7PDqlPzUxJKjE4qDZDfeDSjCjo6/pt8n ZbrvobCPb+Kbsi4/N03vHODqSMufZgR3wGDLQyq5MnyiVr6ontY/TgOdqeCbNU3Q51PO h61d3FvWll72xwTA6T+7COkYrO0p3yoofVlBcOUdOyVS76Bz1sNIk3t1cqYReT5AkHPT jezQ== X-Forwarded-Encrypted: i=1; AJvYcCXILHeg1UXijo6ehd7eUNDk8evDKJyXFJfMPkwTBqKtI0bM98GBJlqEKYGTp888o+tTjRaouuo=@vger.kernel.org X-Gm-Message-State: AOJu0YwhFRH1Q1RWjfPVAkHA9Q4UOINVJ6thGTTPIMPMIYK5WLp16EcP KgaTAanQF0OxWh9czPAWOOuF1eGdU8Byq6xrO+dxgrUg0MzeK+avNjV1V4BYG4I= X-Gm-Gg: ASbGncseJyUqmHbAY4xibkvuFI3dlCBuRrGI84rIorKzcLXu6nnHc2O5xOIaKSFH696 3lBsH9MhtZw5Pt4pmHbdJ0txn18tmCbsLsZNDBiFXQJ/oywIsxJox0AinE+sI1sknEqYM9EH1uz aUWLfZCydvBmLhhNAxXzrONjUazkOymhPP+0JAsPHR18CS9Yo7pA+emaVWQwaqPNKfUjwRQPo4H kvS1arauz6U72SSarS06U746dokFO2LoNGN/1bw X-Google-Smtp-Source: AGHT+IFTqbXCJRihMTYyTFfunYDExin9Bg/pP5m61YHb/5wUxXbett+L3lDbrlgtqO4wOr5ij96mHA== X-Received: by 2002:a05:6a00:4293:b0:727:3cd0:122f with SMTP id d2e1a72fcca58-72dafa04710mr852778b3a.9.1737069440639; Thu, 16 Jan 2025 15:17:20 -0800 (PST) Received: from localhost ([2a03:2880:ff:6::]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72dabab64b8sm539563b3a.166.2025.01.16.15.17.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jan 2025 15:17:20 -0800 (PST) From: David Wei To: io-uring@vger.kernel.org, netdev@vger.kernel.org Cc: Jens Axboe , Pavel Begunkov , Jakub Kicinski , Paolo Abeni , "David S. Miller" , Eric Dumazet , Jesper Dangaard Brouer , David Ahern , Mina Almasry , Stanislav Fomichev , Joe Damato , Pedro Tammela Subject: [PATCH net-next v11 11/21] io_uring/zcrx: add interface queue and refill queue Date: Thu, 16 Jan 2025 15:16:53 -0800 Message-ID: <20250116231704.2402455-12-dw@davidwei.uk> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250116231704.2402455-1-dw@davidwei.uk> References: <20250116231704.2402455-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 Add a new object called an interface queue (ifq) that represents a net rx queue that has been configured for zero copy. Each ifq is registered using a new registration opcode IORING_REGISTER_ZCRX_IFQ. The refill queue is allocated by the kernel and mapped by userspace using a new offset IORING_OFF_RQ_RING, in a similar fashion to the main SQ/CQ. It is used by userspace to return buffers that it is done with, which will then be re-used by the netdev again. The main CQ ring is used to notify userspace of received data by using the upper 16 bytes of a big CQE as a new struct io_uring_zcrx_cqe. Each entry contains the offset + len to the data. For now, each io_uring instance only has a single ifq. Reviewed-by: Jens Axboe Signed-off-by: David Wei --- Kconfig | 2 + include/linux/io_uring_types.h | 6 ++ include/uapi/linux/io_uring.h | 43 +++++++++- io_uring/KConfig | 10 +++ io_uring/Makefile | 1 + io_uring/io_uring.c | 7 ++ io_uring/memmap.h | 1 + io_uring/register.c | 7 ++ io_uring/zcrx.c | 149 +++++++++++++++++++++++++++++++++ io_uring/zcrx.h | 35 ++++++++ 10 files changed, 260 insertions(+), 1 deletion(-) create mode 100644 io_uring/KConfig create mode 100644 io_uring/zcrx.c create mode 100644 io_uring/zcrx.h diff --git a/Kconfig b/Kconfig index 745bc773f567..529ea7694ba9 100644 --- a/Kconfig +++ b/Kconfig @@ -30,3 +30,5 @@ source "lib/Kconfig" source "lib/Kconfig.debug" source "Documentation/Kconfig" + +source "io_uring/KConfig" diff --git a/include/linux/io_uring_types.h b/include/linux/io_uring_types.h index 493a8f7fa8e4..f0c6e18d176a 100644 --- a/include/linux/io_uring_types.h +++ b/include/linux/io_uring_types.h @@ -40,6 +40,8 @@ enum io_uring_cmd_flags { IO_URING_F_TASK_DEAD = (1 << 13), }; +struct io_zcrx_ifq; + struct io_wq_work_node { struct io_wq_work_node *next; }; @@ -384,6 +386,8 @@ struct io_ring_ctx { struct wait_queue_head poll_wq; struct io_restriction restrictions; + struct io_zcrx_ifq *ifq; + u32 pers_next; struct xarray personalities; @@ -436,6 +440,8 @@ struct io_ring_ctx { struct io_mapped_region ring_region; /* used for optimised request parameter and wait argument passing */ struct io_mapped_region param_region; + /* just one zcrx per ring for now, will move to io_zcrx_ifq eventually */ + struct io_mapped_region zcrx_region; }; struct io_tw_state { diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h index 38f0d6b10eaf..3af8b7a19824 100644 --- a/include/uapi/linux/io_uring.h +++ b/include/uapi/linux/io_uring.h @@ -638,7 +638,8 @@ enum io_uring_register_op { /* send MSG_RING without having a ring */ IORING_REGISTER_SEND_MSG_RING = 31, - /* 32 reserved for zc rx */ + /* register a netdev hw rx queue for zerocopy */ + IORING_REGISTER_ZCRX_IFQ = 32, /* resize CQ ring */ IORING_REGISTER_RESIZE_RINGS = 33, @@ -955,6 +956,46 @@ enum io_uring_socket_op { SOCKET_URING_OP_SETSOCKOPT, }; +/* Zero copy receive refill queue entry */ +struct io_uring_zcrx_rqe { + __u64 off; + __u32 len; + __u32 __pad; +}; + +struct io_uring_zcrx_cqe { + __u64 off; + __u64 __pad; +}; + +/* The bit from which area id is encoded into offsets */ +#define IORING_ZCRX_AREA_SHIFT 48 +#define IORING_ZCRX_AREA_MASK (~(((__u64)1 << IORING_ZCRX_AREA_SHIFT) - 1)) + +struct io_uring_zcrx_offsets { + __u32 head; + __u32 tail; + __u32 rqes; + __u32 __resv2; + __u64 __resv[2]; +}; + +/* + * Argument for IORING_REGISTER_ZCRX_IFQ + */ +struct io_uring_zcrx_ifq_reg { + __u32 if_idx; + __u32 if_rxq; + __u32 rq_entries; + __u32 flags; + + __u64 area_ptr; /* pointer to struct io_uring_zcrx_area_reg */ + __u64 region_ptr; /* struct io_uring_region_desc * */ + + struct io_uring_zcrx_offsets offsets; + __u64 __resv[4]; +}; + #ifdef __cplusplus } #endif diff --git a/io_uring/KConfig b/io_uring/KConfig new file mode 100644 index 000000000000..9e2a4beba1ef --- /dev/null +++ b/io_uring/KConfig @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# io_uring configuration +# + +config IO_URING_ZCRX + def_bool y + depends on PAGE_POOL + depends on INET + depends on NET_RX_BUSY_POLL diff --git a/io_uring/Makefile b/io_uring/Makefile index 53167bef37d7..a95b0b8229c9 100644 --- a/io_uring/Makefile +++ b/io_uring/Makefile @@ -14,6 +14,7 @@ obj-$(CONFIG_IO_URING) += io_uring.o opdef.o kbuf.o rsrc.o notif.o \ epoll.o statx.o timeout.o fdinfo.o \ cancel.o waitid.o register.o \ truncate.o memmap.o +obj-$(CONFIG_IO_URING_ZCRX) += zcrx.o obj-$(CONFIG_IO_WQ) += io-wq.o obj-$(CONFIG_FUTEX) += futex.o obj-$(CONFIG_NET_RX_BUSY_POLL) += napi.o diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index 5535a72b0ce1..0c02a2e97f01 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -97,6 +97,7 @@ #include "uring_cmd.h" #include "msg_ring.h" #include "memmap.h" +#include "zcrx.h" #include "timeout.h" #include "poll.h" @@ -2686,6 +2687,7 @@ static __cold void io_ring_ctx_free(struct io_ring_ctx *ctx) mutex_lock(&ctx->uring_lock); io_sqe_buffers_unregister(ctx); io_sqe_files_unregister(ctx); + io_unregister_zcrx_ifqs(ctx); io_cqring_overflow_kill(ctx); io_eventfd_unregister(ctx); io_alloc_cache_free(&ctx->apoll_cache, kfree); @@ -2851,6 +2853,11 @@ static __cold void io_ring_exit_work(struct work_struct *work) io_cqring_overflow_kill(ctx); mutex_unlock(&ctx->uring_lock); } + if (ctx->ifq) { + mutex_lock(&ctx->uring_lock); + io_shutdown_zcrx_ifqs(ctx); + mutex_unlock(&ctx->uring_lock); + } if (ctx->flags & IORING_SETUP_DEFER_TASKRUN) io_move_task_work_from_local(ctx); diff --git a/io_uring/memmap.h b/io_uring/memmap.h index c898dcba2b4e..dad0aa5b1b45 100644 --- a/io_uring/memmap.h +++ b/io_uring/memmap.h @@ -2,6 +2,7 @@ #define IO_URING_MEMMAP_H #define IORING_MAP_OFF_PARAM_REGION 0x20000000ULL +#define IORING_MAP_OFF_ZCRX_REGION 0x30000000ULL struct page **io_pin_pages(unsigned long ubuf, unsigned long len, int *npages); diff --git a/io_uring/register.c b/io_uring/register.c index f1698c18c7cb..f9dfdca79a80 100644 --- a/io_uring/register.c +++ b/io_uring/register.c @@ -30,6 +30,7 @@ #include "eventfd.h" #include "msg_ring.h" #include "memmap.h" +#include "zcrx.h" #define IORING_MAX_RESTRICTIONS (IORING_RESTRICTION_LAST + \ IORING_REGISTER_LAST + IORING_OP_LAST) @@ -798,6 +799,12 @@ static int __io_uring_register(struct io_ring_ctx *ctx, unsigned opcode, break; ret = io_register_clone_buffers(ctx, arg); break; + case IORING_REGISTER_ZCRX_IFQ: + ret = -EINVAL; + if (!arg || nr_args != 1) + break; + ret = io_register_zcrx_ifq(ctx, arg); + break; case IORING_REGISTER_RESIZE_RINGS: ret = -EINVAL; if (!arg || nr_args != 1) diff --git a/io_uring/zcrx.c b/io_uring/zcrx.c new file mode 100644 index 000000000000..f3ace7e8264d --- /dev/null +++ b/io_uring/zcrx.c @@ -0,0 +1,149 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include + +#include + +#include "io_uring.h" +#include "kbuf.h" +#include "memmap.h" +#include "zcrx.h" + +#define IO_RQ_MAX_ENTRIES 32768 + +static int io_allocate_rbuf_ring(struct io_zcrx_ifq *ifq, + struct io_uring_zcrx_ifq_reg *reg, + struct io_uring_region_desc *rd) +{ + size_t off, size; + void *ptr; + int ret; + + off = sizeof(struct io_uring); + size = off + sizeof(struct io_uring_zcrx_rqe) * reg->rq_entries; + if (size > rd->size) + return -EINVAL; + + ret = io_create_region_mmap_safe(ifq->ctx, &ifq->ctx->zcrx_region, rd, + IORING_MAP_OFF_ZCRX_REGION); + if (ret < 0) + return ret; + + ptr = io_region_get_ptr(&ifq->ctx->zcrx_region); + ifq->rq_ring = (struct io_uring *)ptr; + ifq->rqes = (struct io_uring_zcrx_rqe *)(ptr + off); + return 0; +} + +static void io_free_rbuf_ring(struct io_zcrx_ifq *ifq) +{ + io_free_region(ifq->ctx, &ifq->ctx->zcrx_region); + ifq->rq_ring = NULL; + ifq->rqes = NULL; +} + +static struct io_zcrx_ifq *io_zcrx_ifq_alloc(struct io_ring_ctx *ctx) +{ + struct io_zcrx_ifq *ifq; + + ifq = kzalloc(sizeof(*ifq), GFP_KERNEL); + if (!ifq) + return NULL; + + ifq->if_rxq = -1; + ifq->ctx = ctx; + return ifq; +} + +static void io_zcrx_ifq_free(struct io_zcrx_ifq *ifq) +{ + io_free_rbuf_ring(ifq); + kfree(ifq); +} + +int io_register_zcrx_ifq(struct io_ring_ctx *ctx, + struct io_uring_zcrx_ifq_reg __user *arg) +{ + struct io_uring_zcrx_ifq_reg reg; + struct io_uring_region_desc rd; + struct io_zcrx_ifq *ifq; + int ret; + + /* + * 1. Interface queue allocation. + * 2. It can observe data destined for sockets of other tasks. + */ + if (!capable(CAP_NET_ADMIN)) + return -EPERM; + + /* mandatory io_uring features for zc rx */ + if (!(ctx->flags & IORING_SETUP_DEFER_TASKRUN && + ctx->flags & IORING_SETUP_CQE32)) + return -EINVAL; + if (ctx->ifq) + return -EBUSY; + if (copy_from_user(®, arg, sizeof(reg))) + return -EFAULT; + if (copy_from_user(&rd, u64_to_user_ptr(reg.region_ptr), sizeof(rd))) + return -EFAULT; + if (memchr_inv(®.__resv, 0, sizeof(reg.__resv))) + return -EINVAL; + if (reg.if_rxq == -1 || !reg.rq_entries || reg.flags) + return -EINVAL; + if (reg.rq_entries > IO_RQ_MAX_ENTRIES) { + if (!(ctx->flags & IORING_SETUP_CLAMP)) + return -EINVAL; + reg.rq_entries = IO_RQ_MAX_ENTRIES; + } + reg.rq_entries = roundup_pow_of_two(reg.rq_entries); + + if (!reg.area_ptr) + return -EFAULT; + + ifq = io_zcrx_ifq_alloc(ctx); + if (!ifq) + return -ENOMEM; + + ret = io_allocate_rbuf_ring(ifq, ®, &rd); + if (ret) + goto err; + + ifq->rq_entries = reg.rq_entries; + ifq->if_rxq = reg.if_rxq; + + reg.offsets.rqes = sizeof(struct io_uring); + reg.offsets.head = offsetof(struct io_uring, head); + reg.offsets.tail = offsetof(struct io_uring, tail); + + if (copy_to_user(arg, ®, sizeof(reg)) || + copy_to_user(u64_to_user_ptr(reg.region_ptr), &rd, sizeof(rd))) { + ret = -EFAULT; + goto err; + } + + ctx->ifq = ifq; + return 0; +err: + io_zcrx_ifq_free(ifq); + return ret; +} + +void io_unregister_zcrx_ifqs(struct io_ring_ctx *ctx) +{ + struct io_zcrx_ifq *ifq = ctx->ifq; + + lockdep_assert_held(&ctx->uring_lock); + + if (!ifq) + return; + + ctx->ifq = NULL; + io_zcrx_ifq_free(ifq); +} + +void io_shutdown_zcrx_ifqs(struct io_ring_ctx *ctx) +{ + lockdep_assert_held(&ctx->uring_lock); +} diff --git a/io_uring/zcrx.h b/io_uring/zcrx.h new file mode 100644 index 000000000000..58e4ab6c6083 --- /dev/null +++ b/io_uring/zcrx.h @@ -0,0 +1,35 @@ +// SPDX-License-Identifier: GPL-2.0 +#ifndef IOU_ZC_RX_H +#define IOU_ZC_RX_H + +#include + +struct io_zcrx_ifq { + struct io_ring_ctx *ctx; + struct io_uring *rq_ring; + struct io_uring_zcrx_rqe *rqes; + u32 rq_entries; + + u32 if_rxq; +}; + +#if defined(CONFIG_IO_URING_ZCRX) +int io_register_zcrx_ifq(struct io_ring_ctx *ctx, + struct io_uring_zcrx_ifq_reg __user *arg); +void io_unregister_zcrx_ifqs(struct io_ring_ctx *ctx); +void io_shutdown_zcrx_ifqs(struct io_ring_ctx *ctx); +#else +static inline int io_register_zcrx_ifq(struct io_ring_ctx *ctx, + struct io_uring_zcrx_ifq_reg __user *arg) +{ + return -EOPNOTSUPP; +} +static inline void io_unregister_zcrx_ifqs(struct io_ring_ctx *ctx) +{ +} +static inline void io_shutdown_zcrx_ifqs(struct io_ring_ctx *ctx) +{ +} +#endif + +#endif From patchwork Thu Jan 16 23:16:54 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wei X-Patchwork-Id: 13942455 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (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 612E8244FAD for ; Thu, 16 Jan 2025 23:17:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737069443; cv=none; b=sbpiZmhxaHsbX41c33XTL861OCaCyUA/pmeEtiM+yvWBGGEaw+Mbm4fyw1hDRjq9n6Q3+AgFWn79sLATXAEaTEKtHUunEJA/7Ekqbh/8WvCah7B5df5ISuQCuPY8Sa8RRd2NztTahicKnr5CvCtT+HR44Cpb4Ba0n85Deov/csg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737069443; c=relaxed/simple; bh=XVYbxLhQjPLjRXvHRi0K/kcnMc22GtAVQg7MWFvQ9yk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nFqGiLmV899K/H7sp0+IqITiAJfQynK45DSHdLZ6MS9NgM81LAQjB9c/pRbb4Dnpg2A0wNUrRtpvFyUxBK6y73mMQ0lFC5CJQwSzhQtFxfKy0G2p6W4qHWXhxaWW6OT0Cpyjd96WAN4o6iiiDi7rG12P5j0xCh5CKxT0c74K6lg= 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=MvZZe1Y1; arc=none smtp.client-ip=209.85.214.178 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="MvZZe1Y1" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-216281bc30fso34762105ad.0 for ; Thu, 16 Jan 2025 15:17:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=davidwei-uk.20230601.gappssmtp.com; s=20230601; t=1737069441; x=1737674241; 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=HANf/wnrk/pvHPDftSyBB7C0ozx5QMtCSP2F71f05Iw=; b=MvZZe1Y1O7rb32DRE+4qjIZeJs2csAUutgPoZ9eHczjgW1AAou+NIxFH0HttnAC6RZ s8H0X9OWmlYCDE2O7xwwU+xfvQB9lx6eQ2VmMxG1ccPCwopDzRm7T7rTcSVsTN//udD7 xtpmqEyLMxYVLowBeaDDD9SKALUqkaCqNPOLPeInLdAYlP8+XAR24Vnpnt8kB3u0IZy/ b4MoOGITknKTrSGIw+/xxqtZcS7YvC3S+Ceksz3YDqIgysUAxCTOuJxiVjLJnqniCfaD 9maJddZoJz4uWPpIp5BCX2Praa79ofJrIccika9SRR0/zhibo01pJPqg0X0MBHCnemRk le2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737069441; x=1737674241; 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=HANf/wnrk/pvHPDftSyBB7C0ozx5QMtCSP2F71f05Iw=; b=DF5EtscQk7bw5jKu6psL9YMda0CBrg8PD2TqFMt1d/7ot3noOAmXy8gEtt+e4EPDC0 7FuOcMhiqnIumS2Ae1ArHeyBFi3UQyY9w7yUmPPjawFDl7GoTjHAPKwUa57f/ioYackk pOEu78fSldVbvrITsOlTWOJdStYNU+eVQIQWsXuSWcnit3IhLQF/EHOTeNgYXKxHssCb d5967t4asTddwbmC2BqKeohw19CneYI//DKqYUNwGkgeJtq95bxCzS2iHZ4ApbqylFXf zT/QVG5jAYrk/qM74iknMJB6glS/hhREj8X+1RgP2a/MaAq9kYF2xF/Ied7d3xeoeBP4 dsWg== X-Forwarded-Encrypted: i=1; AJvYcCUNIyrGKaVctfMhbhHcToCLpadFAGA/iLI7eZ+k02+T9hT0SAMnUGIvxitYxEmDJSH/NOJQ2Q4=@vger.kernel.org X-Gm-Message-State: AOJu0YwIvrO3x83tkW3fiRpaZyooU3iUDaFbFf1k/TVgGTkXTkNLp58Q /dNtcWy15jj1nYXsfYw+JDVgZZ0spLNvD1Uc63tpNmjmcNE5WUjVVqDVmsJCj0Y= X-Gm-Gg: ASbGncujD3D8eGf5l3daNJIXkbYxsHBAosahuaTSSlHKl/tybH7obBCQxziL+7TgOMS bVDwmlY4B68VF5yQWQ3+PDJQAoMA40kAxpCy5IF/f/0QhVJjOH9r5JFU73ETG2qS6yneYiMV8Yc 1jg1dSGRJSDG2bQhHZzq8pN9pf21NClJvk1YmLhAXeLg1l+gs/9WH2EpKlvfMQjRwqiNtZhiJjj qrP3ORcy0ozzn6fNO653ypjKewEOOMhCEJhJWGH X-Google-Smtp-Source: AGHT+IHKmtqGZ3DuT1s5D1Hn2JAQovJAToxkSXCy1ODozv0T3FPBRLo5+NSdTtDZeaNF7dKNCmzj8A== X-Received: by 2002:a17:902:e802:b0:21b:d105:26b8 with SMTP id d9443c01a7336-21c3553b20fmr8203195ad.7.1737069441620; Thu, 16 Jan 2025 15:17:21 -0800 (PST) Received: from localhost ([2a03:2880:ff:9::]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21c2ceb833csm5107095ad.67.2025.01.16.15.17.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jan 2025 15:17:21 -0800 (PST) From: David Wei To: io-uring@vger.kernel.org, netdev@vger.kernel.org Cc: Jens Axboe , Pavel Begunkov , Jakub Kicinski , Paolo Abeni , "David S. Miller" , Eric Dumazet , Jesper Dangaard Brouer , David Ahern , Mina Almasry , Stanislav Fomichev , Joe Damato , Pedro Tammela Subject: [PATCH net-next v11 12/21] io_uring/zcrx: add io_zcrx_area Date: Thu, 16 Jan 2025 15:16:54 -0800 Message-ID: <20250116231704.2402455-13-dw@davidwei.uk> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250116231704.2402455-1-dw@davidwei.uk> References: <20250116231704.2402455-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 Add io_zcrx_area that represents a region of userspace memory that is used for zero copy. During ifq registration, userspace passes in the uaddr and len of userspace memory, which is then pinned by the kernel. Each net_iov is mapped to one of these pages. The freelist is a spinlock protected list that keeps track of all the net_iovs/pages that aren't used. For now, there is only one area per ifq and area registration happens implicitly as part of ifq registration. There is no API for adding/removing areas yet. The struct for area registration is there for future extensibility once we support multiple areas and TCP devmem. Reviewed-by: Jens Axboe Signed-off-by: Pavel Begunkov Signed-off-by: David Wei --- include/uapi/linux/io_uring.h | 9 ++++ io_uring/rsrc.c | 2 +- io_uring/rsrc.h | 1 + io_uring/zcrx.c | 89 ++++++++++++++++++++++++++++++++++- io_uring/zcrx.h | 16 +++++++ 5 files changed, 114 insertions(+), 3 deletions(-) diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h index 3af8b7a19824..e251f28507ce 100644 --- a/include/uapi/linux/io_uring.h +++ b/include/uapi/linux/io_uring.h @@ -980,6 +980,15 @@ struct io_uring_zcrx_offsets { __u64 __resv[2]; }; +struct io_uring_zcrx_area_reg { + __u64 addr; + __u64 len; + __u64 rq_area_token; + __u32 flags; + __u32 __resv1; + __u64 __resv2[2]; +}; + /* * Argument for IORING_REGISTER_ZCRX_IFQ */ diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c index f2ff108485c8..d0f11b5aec0d 100644 --- a/io_uring/rsrc.c +++ b/io_uring/rsrc.c @@ -77,7 +77,7 @@ static int io_account_mem(struct io_ring_ctx *ctx, unsigned long nr_pages) return 0; } -static int io_buffer_validate(struct iovec *iov) +int io_buffer_validate(struct iovec *iov) { unsigned long tmp, acct_len = iov->iov_len + (PAGE_SIZE - 1); diff --git a/io_uring/rsrc.h b/io_uring/rsrc.h index c8b093584461..0ae54ddeb1fd 100644 --- a/io_uring/rsrc.h +++ b/io_uring/rsrc.h @@ -66,6 +66,7 @@ int io_register_rsrc_update(struct io_ring_ctx *ctx, void __user *arg, unsigned size, unsigned type); int io_register_rsrc(struct io_ring_ctx *ctx, void __user *arg, unsigned int size, unsigned int type); +int io_buffer_validate(struct iovec *iov); bool io_check_coalesce_buffer(struct page **page_array, int nr_pages, struct io_imu_folio_data *data); diff --git a/io_uring/zcrx.c b/io_uring/zcrx.c index f3ace7e8264d..04883a3ae80c 100644 --- a/io_uring/zcrx.c +++ b/io_uring/zcrx.c @@ -10,6 +10,7 @@ #include "kbuf.h" #include "memmap.h" #include "zcrx.h" +#include "rsrc.h" #define IO_RQ_MAX_ENTRIES 32768 @@ -44,6 +45,79 @@ static void io_free_rbuf_ring(struct io_zcrx_ifq *ifq) ifq->rqes = NULL; } +static void io_zcrx_free_area(struct io_zcrx_area *area) +{ + kvfree(area->freelist); + kvfree(area->nia.niovs); + if (area->pages) { + unpin_user_pages(area->pages, area->nia.num_niovs); + kvfree(area->pages); + } + kfree(area); +} + +static int io_zcrx_create_area(struct io_zcrx_ifq *ifq, + struct io_zcrx_area **res, + struct io_uring_zcrx_area_reg *area_reg) +{ + struct io_zcrx_area *area; + int i, ret, nr_pages; + struct iovec iov; + + if (area_reg->flags || area_reg->rq_area_token) + return -EINVAL; + if (area_reg->__resv1 || area_reg->__resv2[0] || area_reg->__resv2[1]) + return -EINVAL; + if (area_reg->addr & ~PAGE_MASK || area_reg->len & ~PAGE_MASK) + return -EINVAL; + + iov.iov_base = u64_to_user_ptr(area_reg->addr); + iov.iov_len = area_reg->len; + ret = io_buffer_validate(&iov); + if (ret) + return ret; + + ret = -ENOMEM; + area = kzalloc(sizeof(*area), GFP_KERNEL); + if (!area) + goto err; + + area->pages = io_pin_pages((unsigned long)area_reg->addr, area_reg->len, + &nr_pages); + if (IS_ERR(area->pages)) { + ret = PTR_ERR(area->pages); + area->pages = NULL; + goto err; + } + area->nia.num_niovs = nr_pages; + + area->nia.niovs = kvmalloc_array(nr_pages, sizeof(area->nia.niovs[0]), + GFP_KERNEL | __GFP_ZERO); + if (!area->nia.niovs) + goto err; + + area->freelist = kvmalloc_array(nr_pages, sizeof(area->freelist[0]), + GFP_KERNEL | __GFP_ZERO); + if (!area->freelist) + goto err; + + for (i = 0; i < nr_pages; i++) + area->freelist[i] = i; + + area->free_count = nr_pages; + area->ifq = ifq; + /* we're only supporting one area per ifq for now */ + area->area_id = 0; + area_reg->rq_area_token = (u64)area->area_id << IORING_ZCRX_AREA_SHIFT; + spin_lock_init(&area->freelist_lock); + *res = area; + return 0; +err: + if (area) + io_zcrx_free_area(area); + return ret; +} + static struct io_zcrx_ifq *io_zcrx_ifq_alloc(struct io_ring_ctx *ctx) { struct io_zcrx_ifq *ifq; @@ -59,6 +133,9 @@ static struct io_zcrx_ifq *io_zcrx_ifq_alloc(struct io_ring_ctx *ctx) static void io_zcrx_ifq_free(struct io_zcrx_ifq *ifq) { + if (ifq->area) + io_zcrx_free_area(ifq->area); + io_free_rbuf_ring(ifq); kfree(ifq); } @@ -66,6 +143,7 @@ static void io_zcrx_ifq_free(struct io_zcrx_ifq *ifq) int io_register_zcrx_ifq(struct io_ring_ctx *ctx, struct io_uring_zcrx_ifq_reg __user *arg) { + struct io_uring_zcrx_area_reg area; struct io_uring_zcrx_ifq_reg reg; struct io_uring_region_desc rd; struct io_zcrx_ifq *ifq; @@ -99,7 +177,7 @@ int io_register_zcrx_ifq(struct io_ring_ctx *ctx, } reg.rq_entries = roundup_pow_of_two(reg.rq_entries); - if (!reg.area_ptr) + if (copy_from_user(&area, u64_to_user_ptr(reg.area_ptr), sizeof(area))) return -EFAULT; ifq = io_zcrx_ifq_alloc(ctx); @@ -110,6 +188,10 @@ int io_register_zcrx_ifq(struct io_ring_ctx *ctx, if (ret) goto err; + ret = io_zcrx_create_area(ifq, &ifq->area, &area); + if (ret) + goto err; + ifq->rq_entries = reg.rq_entries; ifq->if_rxq = reg.if_rxq; @@ -122,7 +204,10 @@ int io_register_zcrx_ifq(struct io_ring_ctx *ctx, ret = -EFAULT; goto err; } - + if (copy_to_user(u64_to_user_ptr(reg.area_ptr), &area, sizeof(area))) { + ret = -EFAULT; + goto err; + } ctx->ifq = ifq; return 0; err: diff --git a/io_uring/zcrx.h b/io_uring/zcrx.h index 58e4ab6c6083..53fd94b65b38 100644 --- a/io_uring/zcrx.h +++ b/io_uring/zcrx.h @@ -3,9 +3,25 @@ #define IOU_ZC_RX_H #include +#include + +struct io_zcrx_area { + struct net_iov_area nia; + struct io_zcrx_ifq *ifq; + + u16 area_id; + struct page **pages; + + /* freelist */ + spinlock_t freelist_lock ____cacheline_aligned_in_smp; + u32 free_count; + u32 *freelist; +}; struct io_zcrx_ifq { struct io_ring_ctx *ctx; + struct io_zcrx_area *area; + struct io_uring *rq_ring; struct io_uring_zcrx_rqe *rqes; u32 rq_entries; From patchwork Thu Jan 16 23:16:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wei X-Patchwork-Id: 13942457 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) (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 4AAF5244FA3 for ; Thu, 16 Jan 2025 23:17:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737069444; cv=none; b=Hrs/do1iuBUa9If5asJWnLrVmBeyhOBYpHmmNzNWBK2CMEkm5UBcosbr4gTlmCtbVmlRewMTAvNvEEqe4r2QEEJ+YoxAaUHR+4eGepmsNNcD+MeMFvHRCQYvhNy/cLKodjTqoXFUxk+K7AbAWKEc7GvLRoNxOjmy27AYzh1c2EI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737069444; c=relaxed/simple; bh=moxT/9tlqEGGqkvg89jEl7qnqkLxWddMi6wsJk9KyOo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FbWLDV/WEQUAtMM48HCHOexxhzzKX2wKHgErVU/mFM3cbuPVPPRvmGtQU91eFa0Vddz7KeN5Ce02mNhTibqqQGMgqy1jdLH0e/QosB6FBik+krOSryyU/LKRSEPhJ4JWVbRHO0xoCBcm1ezmVVsW3w23Mq2VbXGzOfhCKGTjlZA= 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=2ABNWw9r; arc=none smtp.client-ip=209.85.216.47 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="2ABNWw9r" Received: by mail-pj1-f47.google.com with SMTP id 98e67ed59e1d1-2ee8e8e29f6so2181679a91.0 for ; Thu, 16 Jan 2025 15:17:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=davidwei-uk.20230601.gappssmtp.com; s=20230601; t=1737069443; x=1737674243; 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=6McXPFUQHYSYEvRYSRp9lVm8DJpoafPAg8IZnzA+YUI=; b=2ABNWw9rdgCycN+Zslx78MFL7Pm8surhUpDO7v+4pGWVRF+Hvz+s9GUBYQVsACOaJ8 CKcwXv4/MEse5qNxtzEdGiagQ/1r9XvhIKlM8FNB4+9RYMarpFTyOauGREvNK7vTO93T i8mg/WVYz27Wyxqq7o7jsLNEQ5FstSVCD+GqJfbo/HLRTZgAW+zAJaPD0UIah0bteK4K qR59JCikTmDS2PVQ0LlgAdvQCkKooTPGHQ5h8ukqEeEPp0TFsUJvDFeCRGmdEihLJKDx GcuE3tXxlym7gceFaBbR8V+M8f/x+UBmKCjexPuDM/bxXNJobu3ThC8fjujPnsrNOHaJ TlMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737069443; x=1737674243; 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=6McXPFUQHYSYEvRYSRp9lVm8DJpoafPAg8IZnzA+YUI=; b=PJ5CanVJ52xb8HxyVsMCFlx1aE/lTQvwZPl0kRiVViUpOE2F+ezPNq7ma+O6w7q8gX wL7u/rRiU6BHe8ar3QKWtdNtEYkhQujC0PBc3Jb+4KPXtoa42qLDsD1FnTVo2apnxCTt 0sce4xp2no2Qmqml8OIdNVMutNaNrbqONyRUsR+kbNGqQLPaqk3DUfR1hTC8gP1ZCytr XKJ+g9U4i6+8cHnoS9Y7YPTHlKl4jZZOz0ocpD4X+9DTxafxeEEL4G/2HvualR+W41Zr /jEI5FGfnHsZuH8ynNQ48ah8h542cOmRguDryG1eEGt7Wb9ETBeyvmV4aZHMlHL4nXvj OICA== X-Forwarded-Encrypted: i=1; AJvYcCVCeaR/3LXPyzzbWrZkQWvVrphBvx/HmwjWQyjBmRKIEb5tojuqYTi7vpfDxdvm703r/0D8kqg=@vger.kernel.org X-Gm-Message-State: AOJu0YxWa7vpoUj2EN/q3P58ZeI9rMnT7lULiQ0BrCKZrudzdQp6Tbrt XDhZjheE6JGaAzRC8HXibKUoxf9DOgODDr2R52Ydvr6+s/m4gn88t6sLwQWADj0= X-Gm-Gg: ASbGnctdeX6KoXeMjuUvhD69PKqsmhEhzPq2/KYMUXhT13ggeegPaJ/uPS2kY+8afZU iHQPul21I2RRa0WVfnGDe4qpQckj6Pg9SxXJ8d11M1bQ7KxLJKiQm6ceH/bohh02jsBFOMwK/hb e/Ju6841mW1GziJuSHS7IyDHc07vdz63VuP3imETlTOkh4cxU/vZRc8rqUuvhPnOo9jsO/deh+k Ax0n8kocA7fdywXp92nYba9h8IL1fxNKbvTjjESVA== X-Google-Smtp-Source: AGHT+IGqq7ZxkRc3/1V0W4uC5/iqUYVT44pqYaPtChWDnrvoE36MzzgrU5K+BZPNWwgUmJqah9EJaw== X-Received: by 2002:a17:90a:c2c7:b0:2ee:693e:ed7c with SMTP id 98e67ed59e1d1-2f782d9ea43mr631647a91.33.1737069442711; Thu, 16 Jan 2025 15:17:22 -0800 (PST) Received: from localhost ([2a03:2880:ff:54::]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2f72c2f31d6sm3840917a91.40.2025.01.16.15.17.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jan 2025 15:17:22 -0800 (PST) From: David Wei To: io-uring@vger.kernel.org, netdev@vger.kernel.org Cc: Jens Axboe , Pavel Begunkov , Jakub Kicinski , Paolo Abeni , "David S. Miller" , Eric Dumazet , Jesper Dangaard Brouer , David Ahern , Mina Almasry , Stanislav Fomichev , Joe Damato , Pedro Tammela Subject: [PATCH net-next v11 13/21] io_uring/zcrx: grab a net device Date: Thu, 16 Jan 2025 15:16:55 -0800 Message-ID: <20250116231704.2402455-14-dw@davidwei.uk> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250116231704.2402455-1-dw@davidwei.uk> References: <20250116231704.2402455-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 Zerocopy receive needs a net device to bind to its rx queue and dma map buffers. As a preparation to following patches, resolve a net device from the if_idx parameter with no functional changes otherwise. Reviewed-by: Jens Axboe Signed-off-by: Pavel Begunkov Signed-off-by: David Wei --- io_uring/zcrx.c | 28 ++++++++++++++++++++++++++++ io_uring/zcrx.h | 5 +++++ 2 files changed, 33 insertions(+) diff --git a/io_uring/zcrx.c b/io_uring/zcrx.c index 04883a3ae80c..435cd634f91c 100644 --- a/io_uring/zcrx.c +++ b/io_uring/zcrx.c @@ -3,6 +3,8 @@ #include #include #include +#include +#include #include @@ -128,13 +130,28 @@ static struct io_zcrx_ifq *io_zcrx_ifq_alloc(struct io_ring_ctx *ctx) ifq->if_rxq = -1; ifq->ctx = ctx; + spin_lock_init(&ifq->lock); return ifq; } +static void io_zcrx_drop_netdev(struct io_zcrx_ifq *ifq) +{ + spin_lock(&ifq->lock); + if (ifq->netdev) { + netdev_put(ifq->netdev, &ifq->netdev_tracker); + ifq->netdev = NULL; + } + spin_unlock(&ifq->lock); +} + static void io_zcrx_ifq_free(struct io_zcrx_ifq *ifq) { + io_zcrx_drop_netdev(ifq); + if (ifq->area) io_zcrx_free_area(ifq->area); + if (ifq->dev) + put_device(ifq->dev); io_free_rbuf_ring(ifq); kfree(ifq); @@ -195,6 +212,17 @@ int io_register_zcrx_ifq(struct io_ring_ctx *ctx, ifq->rq_entries = reg.rq_entries; ifq->if_rxq = reg.if_rxq; + ret = -ENODEV; + ifq->netdev = netdev_get_by_index(current->nsproxy->net_ns, reg.if_idx, + &ifq->netdev_tracker, GFP_KERNEL); + if (!ifq->netdev) + goto err; + + ifq->dev = ifq->netdev->dev.parent; + if (!ifq->dev) + return -EOPNOTSUPP; + get_device(ifq->dev); + reg.offsets.rqes = sizeof(struct io_uring); reg.offsets.head = offsetof(struct io_uring, head); reg.offsets.tail = offsetof(struct io_uring, tail); diff --git a/io_uring/zcrx.h b/io_uring/zcrx.h index 53fd94b65b38..595bca0001d2 100644 --- a/io_uring/zcrx.h +++ b/io_uring/zcrx.h @@ -4,6 +4,7 @@ #include #include +#include struct io_zcrx_area { struct net_iov_area nia; @@ -27,6 +28,10 @@ struct io_zcrx_ifq { u32 rq_entries; u32 if_rxq; + struct device *dev; + struct net_device *netdev; + netdevice_tracker netdev_tracker; + spinlock_t lock; }; #if defined(CONFIG_IO_URING_ZCRX) From patchwork Thu Jan 16 23:16:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wei X-Patchwork-Id: 13942458 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (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 60CAF244FAB for ; Thu, 16 Jan 2025 23:17:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737069446; cv=none; b=AYJeqJoQQN4EUm9b6kEze26F+rbirwI/KKmurVo9W/veqrL1sY0gyCraFhH07v2/50BliAieb/fxzyqgHF3t2+y92qUHLueLSmthLJueisN59OXfoPLXkQmpUhLnaBX36n82pH8eMXYFi8VBMXyrDFysw1evIfX/rKAUwWbibOA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737069446; c=relaxed/simple; bh=M2OzfYpywdq6iTm6K8uQP/OfvoeLl0KtGbk6eyj5Dt8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Tp7rGSHl6fQgsL89zeyTYlicEq7SHdyduyJx+ls0aBMm7bZZuU98xPzhXUavzg8FKSSThZ+MZ/QWnMbqbA2vVeocUh1PJqARIAxquUTBPdEcxrOfcQXl7rSN0Sbpt8v6Lfb8M8NCbIS15H8jyz0ctl1Se0caNJbZrrsP3+Obe+I= 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=uDpyN/8N; arc=none smtp.client-ip=209.85.214.179 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="uDpyN/8N" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-2162c0f6a39so51359775ad.0 for ; Thu, 16 Jan 2025 15:17:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=davidwei-uk.20230601.gappssmtp.com; s=20230601; t=1737069444; x=1737674244; 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=HCbv9zrg2RTuKravn+6cPY6Vx77zCXxosEzAttkO/ZA=; b=uDpyN/8NRREuIckfoJVGA/A9oRP22zFAlOsVWkvmMVehVUCapoOLfSRRiczcTqCsf4 SyExPat6tjX/M6pA6GfWk/YyJPaMB89GhlU+IVte3MqXUeIXmptEfoMDSS3sXpxGVrM8 jZiAmc9yWnoS1KLSeXh9MzsOsWzzlNv/gOGaPPEIYLJguJnwZ684r8I5LaLIZp23okln a1iNJYIHixGNb+EELpaA72ErLSBDtdEELfxq9a9BA7GFDQrZF9ib+Z7ONDCDMwMVGfPN eISZRWiQ8Hu2xIAmeVAAx+sniue1p24vVfRpChUJZl4ankj09ZEg9j5yd9Y9TNECnWDr nZFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737069444; x=1737674244; 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=HCbv9zrg2RTuKravn+6cPY6Vx77zCXxosEzAttkO/ZA=; b=uSQOPLof4Bl0bupHW5/al7B4hafwWH2cOeKPfYTvU18SNIPz1iM4hdR3azxaMkBxvm wjHVymsSqqKFwVl6ChqIEPuoSUa//L4srjNoIyZ1y/YUKdIvny+/+xZb1TtX2F0p0ynk 1ldw9zH248bLubbV7c1nNw9zhkeGkiKDjBcxjJCbaBr1+8KxUzV2ObE59ro1eML51rm6 hpUwZsy3d6Y25RxiVo9v6a8a3zb7ll2XpiZSVk+fdb888zL2yXAcP3fCIx648GtN8nhE hhbA52xY6ml2LRhPreeZl/EulGgT2JyyhzkjAJXm3KTUkT/KzQw4Q4AXuOjVV9RR73HL PxtA== X-Forwarded-Encrypted: i=1; AJvYcCW4H+EnBXQY6/TWfXpBrVW8QRtcYgrGYqhhI0gX3ppdPMVxWo4kcaP0/S8A4/+qlH4KgE/hjl4=@vger.kernel.org X-Gm-Message-State: AOJu0YyEZd9pzbilqt4PEg7jW53Cjm1oW8I4l6thbv3f+z2/K1eAu74r qY5ftmo0lGuyAtAUTAQ6HF6f6URJmnKq66hkKGMt5L94bYGCUx6hdTVqfBELzuU= X-Gm-Gg: ASbGncsRZ6if0nsskORZsfVW3jsP1GZvO4gM6jXKnO4lBDqXmkyaSGv0aofSAVYHF41 YqtV5vYAO7AX4Dt+vhEhy+v07VmApYCDy7G1OEV8pzyP17PWxdo5Vlw6MudgJidCG/Wns9HC0D3 exZ9hxdnkJdm55NmA5kem966GRUs3x/13Q9pt8q1XDxyo/yHlMbzzGA0TT9A7BZGjXryKh8EqsB VlQaXJNtpnfDme2xlAsq8Uc7O2CaPFYR9sREsXUfQ== X-Google-Smtp-Source: AGHT+IFfSVZmR/JD9nKef9R2uiu76LwbOmJT1JQxWRasICwF2GZIFUm1+1GkEz0w46VQ329Xq8juPQ== X-Received: by 2002:a05:6a21:6d9c:b0:1d9:d5e:8297 with SMTP id adf61e73a8af0-1eb216034b9mr722979637.6.1737069443700; Thu, 16 Jan 2025 15:17:23 -0800 (PST) Received: from localhost ([2a03:2880:ff:74::]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72dab848475sm554860b3a.81.2025.01.16.15.17.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jan 2025 15:17:23 -0800 (PST) From: David Wei To: io-uring@vger.kernel.org, netdev@vger.kernel.org Cc: Jens Axboe , Pavel Begunkov , Jakub Kicinski , Paolo Abeni , "David S. Miller" , Eric Dumazet , Jesper Dangaard Brouer , David Ahern , Mina Almasry , Stanislav Fomichev , Joe Damato , Pedro Tammela Subject: [PATCH net-next v11 14/21] io_uring/zcrx: implement zerocopy receive pp memory provider Date: Thu, 16 Jan 2025 15:16:56 -0800 Message-ID: <20250116231704.2402455-15-dw@davidwei.uk> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250116231704.2402455-1-dw@davidwei.uk> References: <20250116231704.2402455-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 Implement a page pool memory provider for io_uring to receieve in a zero copy fashion. For that, the provider allocates user pages wrapped around into struct net_iovs, that are stored in a previously registered struct net_iov_area. Unlike the traditional receive, that frees pages and returns them back to the page pool right after data was copied to the user, e.g. inside recv(2), we extend the lifetime until the user space confirms that it's done processing the data. That's done by taking a net_iov reference. When the user is done with the buffer, it must return it back to the kernel by posting an entry into the refill ring, which is usually polled off the io_uring memory provider callback in the page pool's netmem allocation path. There is also a separate set of per net_iov "user" references accounting whether a buffer is currently given to the user (including possible fragmentation). Reviewed-by: Jens Axboe Signed-off-by: Pavel Begunkov Signed-off-by: David Wei --- io_uring/zcrx.c | 269 ++++++++++++++++++++++++++++++++++++++++++++++++ io_uring/zcrx.h | 3 + 2 files changed, 272 insertions(+) diff --git a/io_uring/zcrx.c b/io_uring/zcrx.c index 435cd634f91c..c007ff80b325 100644 --- a/io_uring/zcrx.c +++ b/io_uring/zcrx.c @@ -2,10 +2,17 @@ #include #include #include +#include #include #include #include +#include +#include +#include + +#include + #include #include "io_uring.h" @@ -16,6 +23,33 @@ #define IO_RQ_MAX_ENTRIES 32768 +__maybe_unused +static const struct memory_provider_ops io_uring_pp_zc_ops; + +static inline struct io_zcrx_area *io_zcrx_iov_to_area(const struct net_iov *niov) +{ + struct net_iov_area *owner = net_iov_owner(niov); + + return container_of(owner, struct io_zcrx_area, nia); +} + +static inline atomic_t *io_get_user_counter(struct net_iov *niov) +{ + struct io_zcrx_area *area = io_zcrx_iov_to_area(niov); + + return &area->user_refs[net_iov_idx(niov)]; +} + +static bool io_zcrx_put_niov_uref(struct net_iov *niov) +{ + atomic_t *uref = io_get_user_counter(niov); + + if (unlikely(!atomic_read(uref))) + return false; + atomic_dec(uref); + return true; +} + static int io_allocate_rbuf_ring(struct io_zcrx_ifq *ifq, struct io_uring_zcrx_ifq_reg *reg, struct io_uring_region_desc *rd) @@ -51,6 +85,7 @@ static void io_zcrx_free_area(struct io_zcrx_area *area) { kvfree(area->freelist); kvfree(area->nia.niovs); + kvfree(area->user_refs); if (area->pages) { unpin_user_pages(area->pages, area->nia.num_niovs); kvfree(area->pages); @@ -106,6 +141,19 @@ static int io_zcrx_create_area(struct io_zcrx_ifq *ifq, for (i = 0; i < nr_pages; i++) area->freelist[i] = i; + area->user_refs = kvmalloc_array(nr_pages, sizeof(area->user_refs[0]), + GFP_KERNEL | __GFP_ZERO); + if (!area->user_refs) + goto err; + + for (i = 0; i < nr_pages; i++) { + struct net_iov *niov = &area->nia.niovs[i]; + + niov->owner = &area->nia; + area->freelist[i] = i; + atomic_set(&area->user_refs[i], 0); + } + area->free_count = nr_pages; area->ifq = ifq; /* we're only supporting one area per ifq for now */ @@ -131,6 +179,7 @@ static struct io_zcrx_ifq *io_zcrx_ifq_alloc(struct io_ring_ctx *ctx) ifq->if_rxq = -1; ifq->ctx = ctx; spin_lock_init(&ifq->lock); + spin_lock_init(&ifq->rq_lock); return ifq; } @@ -256,7 +305,227 @@ void io_unregister_zcrx_ifqs(struct io_ring_ctx *ctx) io_zcrx_ifq_free(ifq); } +static struct net_iov *__io_zcrx_get_free_niov(struct io_zcrx_area *area) +{ + unsigned niov_idx; + + lockdep_assert_held(&area->freelist_lock); + + niov_idx = area->freelist[--area->free_count]; + return &area->nia.niovs[niov_idx]; +} + +static void io_zcrx_return_niov_freelist(struct net_iov *niov) +{ + struct io_zcrx_area *area = io_zcrx_iov_to_area(niov); + + spin_lock_bh(&area->freelist_lock); + area->freelist[area->free_count++] = net_iov_idx(niov); + spin_unlock_bh(&area->freelist_lock); +} + +static void io_zcrx_return_niov(struct net_iov *niov) +{ + netmem_ref netmem = net_iov_to_netmem(niov); + + page_pool_put_unrefed_netmem(niov->pp, netmem, -1, false); +} + +static void io_zcrx_scrub(struct io_zcrx_ifq *ifq) +{ + struct io_zcrx_area *area = ifq->area; + int i; + + if (!area) + return; + + /* Reclaim back all buffers given to the user space. */ + for (i = 0; i < area->nia.num_niovs; i++) { + struct net_iov *niov = &area->nia.niovs[i]; + int nr; + + if (!atomic_read(io_get_user_counter(niov))) + continue; + nr = atomic_xchg(io_get_user_counter(niov), 0); + if (nr && !page_pool_unref_netmem(net_iov_to_netmem(niov), nr)) + io_zcrx_return_niov(niov); + } +} + void io_shutdown_zcrx_ifqs(struct io_ring_ctx *ctx) { lockdep_assert_held(&ctx->uring_lock); + + if (ctx->ifq) + io_zcrx_scrub(ctx->ifq); +} + +static inline u32 io_zcrx_rqring_entries(struct io_zcrx_ifq *ifq) +{ + u32 entries; + + entries = smp_load_acquire(&ifq->rq_ring->tail) - ifq->cached_rq_head; + return min(entries, ifq->rq_entries); } + +static struct io_uring_zcrx_rqe *io_zcrx_get_rqe(struct io_zcrx_ifq *ifq, + unsigned mask) +{ + unsigned int idx = ifq->cached_rq_head++ & mask; + + return &ifq->rqes[idx]; +} + +static void io_zcrx_ring_refill(struct page_pool *pp, + struct io_zcrx_ifq *ifq) +{ + unsigned int mask = ifq->rq_entries - 1; + unsigned int entries; + netmem_ref netmem; + + spin_lock_bh(&ifq->rq_lock); + + entries = io_zcrx_rqring_entries(ifq); + entries = min_t(unsigned, entries, PP_ALLOC_CACHE_REFILL - pp->alloc.count); + if (unlikely(!entries)) { + spin_unlock_bh(&ifq->rq_lock); + return; + } + + do { + struct io_uring_zcrx_rqe *rqe = io_zcrx_get_rqe(ifq, mask); + struct io_zcrx_area *area; + struct net_iov *niov; + unsigned niov_idx, area_idx; + + area_idx = rqe->off >> IORING_ZCRX_AREA_SHIFT; + niov_idx = (rqe->off & ~IORING_ZCRX_AREA_MASK) >> PAGE_SHIFT; + + if (unlikely(rqe->__pad || area_idx)) + continue; + area = ifq->area; + + if (unlikely(niov_idx >= area->nia.num_niovs)) + continue; + niov_idx = array_index_nospec(niov_idx, area->nia.num_niovs); + + niov = &area->nia.niovs[niov_idx]; + if (!io_zcrx_put_niov_uref(niov)) + continue; + + netmem = net_iov_to_netmem(niov); + if (page_pool_unref_netmem(netmem, 1) != 0) + continue; + + if (unlikely(niov->pp != pp)) { + io_zcrx_return_niov(niov); + continue; + } + + net_mp_netmem_place_in_cache(pp, netmem); + } while (--entries); + + smp_store_release(&ifq->rq_ring->head, ifq->cached_rq_head); + spin_unlock_bh(&ifq->rq_lock); +} + +static void io_zcrx_refill_slow(struct page_pool *pp, struct io_zcrx_ifq *ifq) +{ + struct io_zcrx_area *area = ifq->area; + + spin_lock_bh(&area->freelist_lock); + while (area->free_count && pp->alloc.count < PP_ALLOC_CACHE_REFILL) { + struct net_iov *niov = __io_zcrx_get_free_niov(area); + netmem_ref netmem = net_iov_to_netmem(niov); + + net_mp_niov_set_page_pool(pp, niov); + net_mp_netmem_place_in_cache(pp, netmem); + } + spin_unlock_bh(&area->freelist_lock); +} + +static netmem_ref io_pp_zc_alloc_netmems(struct page_pool *pp, gfp_t gfp) +{ + struct io_zcrx_ifq *ifq = pp->mp_priv; + + /* pp should already be ensuring that */ + if (unlikely(pp->alloc.count)) + goto out_return; + + io_zcrx_ring_refill(pp, ifq); + if (likely(pp->alloc.count)) + goto out_return; + + io_zcrx_refill_slow(pp, ifq); + if (!pp->alloc.count) + return 0; +out_return: + return pp->alloc.cache[--pp->alloc.count]; +} + +static bool io_pp_zc_release_netmem(struct page_pool *pp, netmem_ref netmem) +{ + struct net_iov *niov; + + if (WARN_ON_ONCE(!netmem_is_net_iov(netmem))) + return false; + + niov = netmem_to_net_iov(netmem); + net_mp_niov_clear_page_pool(niov); + io_zcrx_return_niov_freelist(niov); + return false; +} + +static int io_pp_zc_init(struct page_pool *pp) +{ + struct io_zcrx_ifq *ifq = pp->mp_priv; + + if (WARN_ON_ONCE(!ifq)) + return -EINVAL; + if (pp->dma_map) + return -EOPNOTSUPP; + if (pp->p.order != 0) + return -EOPNOTSUPP; + + percpu_ref_get(&ifq->ctx->refs); + return 0; +} + +static void io_pp_zc_destroy(struct page_pool *pp) +{ + struct io_zcrx_ifq *ifq = pp->mp_priv; + struct io_zcrx_area *area = ifq->area; + + if (WARN_ON_ONCE(area->free_count != area->nia.num_niovs)) + return; + percpu_ref_put(&ifq->ctx->refs); +} + +static int io_pp_nl_fill(void *mp_priv, struct sk_buff *rsp, + struct netdev_rx_queue *rxq) +{ + struct nlattr *nest; + int type; + + type = rxq ? NETDEV_A_QUEUE_IO_URING : NETDEV_A_PAGE_POOL_IO_URING; + nest = nla_nest_start(rsp, type); + nla_nest_end(rsp, nest); + + return 0; +} + +static void io_pp_uninstall(void *mp_priv, struct netdev_rx_queue *rxq) +{ + struct io_zcrx_ifq *ifq = mp_priv; + + io_zcrx_drop_netdev(ifq); +} + +static const struct memory_provider_ops io_uring_pp_zc_ops = { + .alloc_netmems = io_pp_zc_alloc_netmems, + .release_netmem = io_pp_zc_release_netmem, + .init = io_pp_zc_init, + .destroy = io_pp_zc_destroy, + .nl_fill = io_pp_nl_fill, + .uninstall = io_pp_uninstall, +}; diff --git a/io_uring/zcrx.h b/io_uring/zcrx.h index 595bca0001d2..6c808240ac91 100644 --- a/io_uring/zcrx.h +++ b/io_uring/zcrx.h @@ -9,6 +9,7 @@ struct io_zcrx_area { struct net_iov_area nia; struct io_zcrx_ifq *ifq; + atomic_t *user_refs; u16 area_id; struct page **pages; @@ -26,6 +27,8 @@ struct io_zcrx_ifq { struct io_uring *rq_ring; struct io_uring_zcrx_rqe *rqes; u32 rq_entries; + u32 cached_rq_head; + spinlock_t rq_lock; u32 if_rxq; struct device *dev; From patchwork Thu Jan 16 23:16:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wei X-Patchwork-Id: 13942459 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 63F2B2459C0 for ; Thu, 16 Jan 2025 23:17:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737069447; cv=none; b=oOEAuLfDpxMNbsgsxgvM4ZRgbNnUtzaQnIeomJi13dvRyDDmUvdwVZwRV7xludohzh5u7pp9LNi0cDsjk16Zjnnh/Oq5NymkrY1f5jaFKkn2AkkCBY5qtoArjFsMo0zI74DA2na/TthCY24EZ1x7QzV1nMIfCzyzgxyWQm4UhlU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737069447; c=relaxed/simple; bh=vJpTlHMNIuxJ3ldJNi4xVGXAD0rwjweUR5uvfqKVMO4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hiJ7w0vW33JMfn3OLjcc75pq6FkqX+TXPo+yK1mGoCnNyLH0AjqouvSHrrpmKN7PypVBIH82A6j/afPaAH9st01b6s7hyzkMuhhbofpjHOf3F9zr8JG4/L/2M/4vXKvBvhdVINLpcKd/l/p4jLiHzR1/A5+/uU1V8L43trQvDXA= 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=n1/9xm6J; arc=none smtp.client-ip=209.85.214.181 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="n1/9xm6J" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-2164b1f05caso28310085ad.3 for ; Thu, 16 Jan 2025 15:17:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=davidwei-uk.20230601.gappssmtp.com; s=20230601; t=1737069444; x=1737674244; 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=9hHqgHd4813KMrHlOnuFkhcaf4unu6qC0dc3ADAOeZA=; b=n1/9xm6J891k+RKwfFnY+ru8271XikQq8m5ptDK48KFrHjj5yuaRX62HiEIBFAhSGm IggNArpv2ZcEcKw3zNFnZDGxsmx3BCSolsEw58s/wH3WGUdjgGQV+9DJBKHMOK5dxSdR Yu5czFRrqomZdDzPWMlzyN9/NNWtPsdRwP2dCY/8KRcOn/wEpyys9B39/Aj621Xgh3Gn 35iFAsQEdfJuJKZ+dnETM4O1MvV7tud52jIjCYQ1Rrh4yy4lBaoYVZCtrqqcHkCWHMJb tMZqVtVXCVdPiUBdwI7i5E1RUOexoPr2XmnOzfVZumhGIm6/dxvJt9G0ggZHXDvn9BZO jjlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737069444; x=1737674244; 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=9hHqgHd4813KMrHlOnuFkhcaf4unu6qC0dc3ADAOeZA=; b=MO76XgBexZDWXPvAxym3IKbAN1GE+7O/8RzHQFWX3cir8re+IrbF4yYC8Y0/8VIfzm Yw8FglnR2Iv4wO2/6sAxaiYMCwvpyJ17P8zwkl8VEuQ92xuQk6KcHm8+mEBfKYV63vG1 qY+LGNEdZILhDkF+d+C1Q+9S+rtHT5kJD1Jtuo+cx5TQpM6Ba8onMFCwb/0G1kNOZ5RP KtEzQAz6C/gDjSpPeWGJZ+9efhgYUKnHft/+axNIrGboCWUg5bgdtoboA+4/agJ5DJ27 28Du6nFO6JNCyBcLz610M+bxofNzHecW2XQOFDPoQpMAZ+RPOWYjsu3BJ9AR7M9z69X/ 5lhA== X-Forwarded-Encrypted: i=1; AJvYcCVg/cyxhZQ0FJ6WRS8dlVPFEHYcM2oY2DWljeEgZTkyu3YIOhDhqqp8Pzp/9EsOF10CHljKhEQ=@vger.kernel.org X-Gm-Message-State: AOJu0YxxkCNrJlfpU/IN1qR8KpSTfctUuF1sgZy7xbgiAmTKMUkBorw9 ouNI4rUhJq7TRHoulFQHL1NVce09mSoP274m2drFBkU0iUzJsRJUx0AhKhaDkW0= X-Gm-Gg: ASbGncu0/DDh52r0QnLDobSjpNoUnPYLkDsz37sC+ktLJHx0YY+xy4CPfb8uDoffLKO u7fXQ8pR7mP41L8LbDmaJQNoAx56KfueHnjQiwm4fhpIy8CflqsnXPRFyKbdPqndKwtwWZ2UHyJ fbUILth9469Xlu4GtsM3GxnHdNWtQ0Tcd6J0yt5VbIhq5/LZS2BqbDxIxGZiL17RxQV1cu9zfqq l66JVwYDtplS4Masscul3XB/43RN/zqWUoZQJ8aaA== X-Google-Smtp-Source: AGHT+IGYL9qSwTG5WFtyJZZT72HUZNX7KCOAdE9lPam5LWd1uo68XTkIcze3pOsK0r2tMQkw8mMVwA== X-Received: by 2002:a05:6a21:9990:b0:1e5:f930:c6e8 with SMTP id adf61e73a8af0-1eb2144d51emr752025637.4.1737069444625; Thu, 16 Jan 2025 15:17:24 -0800 (PST) Received: from localhost ([2a03:2880:ff:72::]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-a9bcdcf7c87sm490532a12.43.2025.01.16.15.17.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jan 2025 15:17:24 -0800 (PST) From: David Wei To: io-uring@vger.kernel.org, netdev@vger.kernel.org Cc: Jens Axboe , Pavel Begunkov , Jakub Kicinski , Paolo Abeni , "David S. Miller" , Eric Dumazet , Jesper Dangaard Brouer , David Ahern , Mina Almasry , Stanislav Fomichev , Joe Damato , Pedro Tammela Subject: [PATCH net-next v11 15/21] io_uring/zcrx: dma-map area for the device Date: Thu, 16 Jan 2025 15:16:57 -0800 Message-ID: <20250116231704.2402455-16-dw@davidwei.uk> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250116231704.2402455-1-dw@davidwei.uk> References: <20250116231704.2402455-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 Setup DMA mappings for the area into which we intend to receive data later on. We know the device we want to attach to even before we get a page pool and can pre-map in advance. All net_iov are synchronised for device when allocated, see page_pool_mp_return_in_cache(). Reviewed-by: Jens Axboe Signed-off-by: Pavel Begunkov Signed-off-by: David Wei --- io_uring/zcrx.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++- io_uring/zcrx.h | 1 + 2 files changed, 82 insertions(+), 1 deletion(-) diff --git a/io_uring/zcrx.c b/io_uring/zcrx.c index c007ff80b325..2b668f09b55f 100644 --- a/io_uring/zcrx.c +++ b/io_uring/zcrx.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 #include #include +#include #include #include #include @@ -21,6 +22,73 @@ #include "zcrx.h" #include "rsrc.h" +#define IO_DMA_ATTR (DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_WEAK_ORDERING) + +static void __io_zcrx_unmap_area(struct io_zcrx_ifq *ifq, + struct io_zcrx_area *area, int nr_mapped) +{ + int i; + + for (i = 0; i < nr_mapped; i++) { + struct net_iov *niov = &area->nia.niovs[i]; + dma_addr_t dma; + + dma = page_pool_get_dma_addr_netmem(net_iov_to_netmem(niov)); + dma_unmap_page_attrs(ifq->dev, dma, PAGE_SIZE, + DMA_FROM_DEVICE, IO_DMA_ATTR); + net_mp_niov_set_dma_addr(niov, 0); + } +} + +static void io_zcrx_unmap_area(struct io_zcrx_ifq *ifq, struct io_zcrx_area *area) +{ + if (area->is_mapped) + __io_zcrx_unmap_area(ifq, area, area->nia.num_niovs); +} + +static int io_zcrx_map_area(struct io_zcrx_ifq *ifq, struct io_zcrx_area *area) +{ + int i; + + for (i = 0; i < area->nia.num_niovs; i++) { + struct net_iov *niov = &area->nia.niovs[i]; + dma_addr_t dma; + + dma = dma_map_page_attrs(ifq->dev, area->pages[i], 0, PAGE_SIZE, + DMA_FROM_DEVICE, IO_DMA_ATTR); + if (dma_mapping_error(ifq->dev, dma)) + break; + if (net_mp_niov_set_dma_addr(niov, dma)) { + dma_unmap_page_attrs(ifq->dev, dma, PAGE_SIZE, + DMA_FROM_DEVICE, IO_DMA_ATTR); + break; + } + } + + if (i != area->nia.num_niovs) { + __io_zcrx_unmap_area(ifq, area, i); + return -EINVAL; + } + + area->is_mapped = true; + return 0; +} + +static void io_zcrx_sync_for_device(const struct page_pool *pool, + struct net_iov *niov) +{ +#if defined(CONFIG_HAS_DMA) && defined(CONFIG_DMA_NEED_SYNC) + dma_addr_t dma_addr; + + if (!dma_dev_need_sync(pool->p.dev)) + return; + + dma_addr = page_pool_get_dma_addr_netmem(net_iov_to_netmem(niov)); + __dma_sync_single_for_device(pool->p.dev, dma_addr + pool->p.offset, + PAGE_SIZE, pool->p.dma_dir); +#endif +} + #define IO_RQ_MAX_ENTRIES 32768 __maybe_unused @@ -83,6 +151,8 @@ static void io_free_rbuf_ring(struct io_zcrx_ifq *ifq) static void io_zcrx_free_area(struct io_zcrx_area *area) { + io_zcrx_unmap_area(area->ifq, area); + kvfree(area->freelist); kvfree(area->nia.niovs); kvfree(area->user_refs); @@ -272,6 +342,10 @@ int io_register_zcrx_ifq(struct io_ring_ctx *ctx, return -EOPNOTSUPP; get_device(ifq->dev); + ret = io_zcrx_map_area(ifq, ifq->area); + if (ret) + goto err; + reg.offsets.rqes = sizeof(struct io_uring); reg.offsets.head = offsetof(struct io_uring, head); reg.offsets.tail = offsetof(struct io_uring, tail); @@ -422,6 +496,7 @@ static void io_zcrx_ring_refill(struct page_pool *pp, continue; } + io_zcrx_sync_for_device(pp, niov); net_mp_netmem_place_in_cache(pp, netmem); } while (--entries); @@ -439,6 +514,7 @@ static void io_zcrx_refill_slow(struct page_pool *pp, struct io_zcrx_ifq *ifq) netmem_ref netmem = net_iov_to_netmem(niov); net_mp_niov_set_page_pool(pp, niov); + io_zcrx_sync_for_device(pp, niov); net_mp_netmem_place_in_cache(pp, netmem); } spin_unlock_bh(&area->freelist_lock); @@ -482,10 +558,14 @@ static int io_pp_zc_init(struct page_pool *pp) if (WARN_ON_ONCE(!ifq)) return -EINVAL; - if (pp->dma_map) + if (WARN_ON_ONCE(ifq->dev != pp->p.dev)) + return -EINVAL; + if (WARN_ON_ONCE(!pp->dma_map)) return -EOPNOTSUPP; if (pp->p.order != 0) return -EOPNOTSUPP; + if (pp->p.dma_dir != DMA_FROM_DEVICE) + return -EOPNOTSUPP; percpu_ref_get(&ifq->ctx->refs); return 0; diff --git a/io_uring/zcrx.h b/io_uring/zcrx.h index 6c808240ac91..1b6363591f72 100644 --- a/io_uring/zcrx.h +++ b/io_uring/zcrx.h @@ -11,6 +11,7 @@ struct io_zcrx_area { struct io_zcrx_ifq *ifq; atomic_t *user_refs; + bool is_mapped; u16 area_id; struct page **pages; From patchwork Thu Jan 16 23:16:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wei X-Patchwork-Id: 13942460 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (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 497F42459D1 for ; Thu, 16 Jan 2025 23:17:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737069448; cv=none; b=HwzjF2eV7aO3zH2IY4wrjr4hAxXtrioPqMOfr9zZ53EJY9w0KRJm408XqbtxW+FmhgRFk/ppBDRD/3Umnm6zCkWyHGJ5nVWzLpPYlaYzUwe22babWvGtjXJhG4hw26Xy/PIUnVkgGMtfHZ64rwTXP2sfJJVmKhlkLMHqetx1P9k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737069448; c=relaxed/simple; bh=6wOXe36dEAhL2RQnN4VmQxNUWpWT2z944LHYAt70wBs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BKncVR5CnUADoImbWNfqe3ihcGaovLK2dTEwPLM53P9MG9kpGFZFJyQfJI6cWnSCGx1fVS+AS1g9yfcEAUDxYAco8a/LWBe2urlN2WHjVSOVob4TYIaur1g+O7MZnGEE2jiPH54YqrZsBT3twF6al/U+C0BEcoI+WLWuDd+Zfs4= 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=XaEIVocJ; arc=none smtp.client-ip=209.85.214.176 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="XaEIVocJ" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-2156e078563so19465045ad.2 for ; Thu, 16 Jan 2025 15:17:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=davidwei-uk.20230601.gappssmtp.com; s=20230601; t=1737069445; x=1737674245; 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=lHwcof23gpx++eLSWNm4eRYUbdWak2vfMHQU4MxdNK0=; b=XaEIVocJVWZOFCfDAs8Fj8KQvEZGDDZb0WwvjZEIXTkDVO290WtyTkTv0GheE69fZP wi4N6gA6jw5xB6SWfSGVdOnK/ZwtNBXNvnl077K9Ks3dtauyaK3Jtpko91CGQLOQ1iAr GWf31LSESC/QbvPIMR921eXP24mo+2PYi47jYY5uOQ4og3N9gjEThzwmWSE5XDMr9ii1 1gysFxzgzE8Zvn7T1AhCfQq5t1etxZf8BxOTgJWnmQG8vH4DZrhTquDI4XTBnnDv/8Q3 pzpEsVZcTtViB9fGwE1RaYoywwmc+c4e/uI8YoNMdy6YvHpdtFtMeXL8lApiQQKossiH p8+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737069445; x=1737674245; 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=lHwcof23gpx++eLSWNm4eRYUbdWak2vfMHQU4MxdNK0=; b=DrAPqP3/6OWrkLJgFzOT+adZSvl3mqsq635iJJzBaxfmm7ce3tRxCOkyZGYSNICoap x+F1VUu58ZCU4/cV96fPEDaZhGOghNe6RF9UzU0FxPCx9aedeflumPYA/qmPqXmzSpTP SiUHx44YgZkoliQdW4xcH/cy+hDkgqlrJ8xomzqZ9GxiIH4QVUJRFSmjhl4xQYgC1VhO vhNXNKkpAUT/ah1ANACv16/xvLvBUHhW7ZniprWApTjCvaobg9O1gU42NT5F4kmrUibb KBhUfIhirFTjTtIu6FLcCPIRCwUbbmjLXaohX4vxZ3f4HTxrp6V00zqahwzQfFj3DS+N kPsg== X-Forwarded-Encrypted: i=1; AJvYcCUeZUUoumFTfe3qRkIux9GYdc2qMs+3EuIGmjeOmhzeLlxFscYYAshj8AhdtZcq9UZFoWduSsM=@vger.kernel.org X-Gm-Message-State: AOJu0YygyBYOvf80nwmjFubnZXEfc6dKKQS++SZrOGcEDzrmZxXW9y5c r6IUi62QHLkHD04P/X1t/VgLhDZZ1APfaOwmcyKY5D7gStc7Y63cbLX1TBOOWSw= X-Gm-Gg: ASbGncsLUzrbrDXKO7thr6572Jre6R9kH1FyS3cog4x1zMnnlxbZ4PKbgsT6JAT2ldv 6K8K7++bqjqk6pnNRdVqM13YvcY6zPWtSaZSPjt0zyHuKf+dvC75bwt2BbSa32+rg4ND4PFMkNR LJX7Bg8aPiPK73tk7ZLDGU07/UIm+RHZ/npUy4tMfH0h9uL46EEMaH4mWx2z+Y0uP1kS+mODT6P g7bWGS2dzhyeKGmbWoDQTCD5jpRVFC9jC+asAGuPg== X-Google-Smtp-Source: AGHT+IHiI9MM9kBdQcWQUMPgQQJXI2J7PMShnT58P8wIlW3Wrnx3pnzIG6X46w5c3VVMX7wQOd4xEg== X-Received: by 2002:a17:90a:c888:b0:2f4:f7f8:fc8a with SMTP id 98e67ed59e1d1-2f782d8cd4emr619523a91.33.1737069445575; Thu, 16 Jan 2025 15:17:25 -0800 (PST) Received: from localhost ([2a03:2880:ff:70::]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2f776147806sm683872a91.11.2025.01.16.15.17.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jan 2025 15:17:25 -0800 (PST) From: David Wei To: io-uring@vger.kernel.org, netdev@vger.kernel.org Cc: Jens Axboe , Pavel Begunkov , Jakub Kicinski , Paolo Abeni , "David S. Miller" , Eric Dumazet , Jesper Dangaard Brouer , David Ahern , Mina Almasry , Stanislav Fomichev , Joe Damato , Pedro Tammela Subject: [PATCH net-next v11 16/21] io_uring/zcrx: add io_recvzc request Date: Thu, 16 Jan 2025 15:16:58 -0800 Message-ID: <20250116231704.2402455-17-dw@davidwei.uk> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250116231704.2402455-1-dw@davidwei.uk> References: <20250116231704.2402455-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 Add io_uring opcode OP_RECV_ZC for doing zero copy reads out of a socket. Only the connection should be land on the specific rx queue set up for zero copy, and the socket must be handled by the io_uring instance that the rx queue was registered for zero copy with. That's because neither net_iovs / buffers from our queue can be read by outside applications, nor zero copy is possible if traffic for the zero copy connection goes to another queue. This coordination is outside of the scope of this patch series. Also, any traffic directed to the zero copy enabled queue is immediately visible to the application, which is why CAP_NET_ADMIN is required at the registration step. Of course, no data is actually read out of the socket, it has already been copied by the netdev into userspace memory via DMA. OP_RECV_ZC reads skbs out of the socket and checks that its frags are indeed net_iovs that belong to io_uring. A cqe is queued for each one of these frags. Recall that each cqe is a big cqe, with the top half being an io_uring_zcrx_cqe. The cqe res field contains the len or error. The lower IORING_ZCRX_AREA_SHIFT bits of the struct io_uring_zcrx_cqe::off field contain the offset relative to the start of the zero copy area. The upper part of the off field is trivially zero, and will be used to carry the area id. For now, there is no limit as to how much work each OP_RECV_ZC request does. It will attempt to drain a socket of all available data. This request always operates in multishot mode. Reviewed-by: Jens Axboe Signed-off-by: David Wei --- include/uapi/linux/io_uring.h | 2 + io_uring/io_uring.h | 10 ++ io_uring/net.c | 72 +++++++++++++ io_uring/opdef.c | 16 +++ io_uring/zcrx.c | 190 +++++++++++++++++++++++++++++++++- io_uring/zcrx.h | 13 +++ 6 files changed, 302 insertions(+), 1 deletion(-) diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h index e251f28507ce..b919a541d44f 100644 --- a/include/uapi/linux/io_uring.h +++ b/include/uapi/linux/io_uring.h @@ -87,6 +87,7 @@ struct io_uring_sqe { union { __s32 splice_fd_in; __u32 file_index; + __u32 zcrx_ifq_idx; __u32 optlen; struct { __u16 addr_len; @@ -278,6 +279,7 @@ enum io_uring_op { IORING_OP_FTRUNCATE, IORING_OP_BIND, IORING_OP_LISTEN, + IORING_OP_RECV_ZC, /* this goes last, obviously */ IORING_OP_LAST, diff --git a/io_uring/io_uring.h b/io_uring/io_uring.h index 032758b28d78..2b1ce5539bfe 100644 --- a/io_uring/io_uring.h +++ b/io_uring/io_uring.h @@ -184,6 +184,16 @@ static inline bool io_get_cqe(struct io_ring_ctx *ctx, struct io_uring_cqe **ret return io_get_cqe_overflow(ctx, ret, false); } +static inline bool io_defer_get_uncommited_cqe(struct io_ring_ctx *ctx, + struct io_uring_cqe **cqe_ret) +{ + io_lockdep_assert_cq_locked(ctx); + + ctx->cq_extra++; + ctx->submit_state.cq_flush = true; + return io_get_cqe(ctx, cqe_ret); +} + static __always_inline bool io_fill_cqe_req(struct io_ring_ctx *ctx, struct io_kiocb *req) { diff --git a/io_uring/net.c b/io_uring/net.c index 8457408194e7..5d8b9a016766 100644 --- a/io_uring/net.c +++ b/io_uring/net.c @@ -16,6 +16,7 @@ #include "net.h" #include "notif.h" #include "rsrc.h" +#include "zcrx.h" #if defined(CONFIG_NET) struct io_shutdown { @@ -88,6 +89,13 @@ struct io_sr_msg { */ #define MULTISHOT_MAX_RETRY 32 +struct io_recvzc { + struct file *file; + unsigned msg_flags; + u16 flags; + struct io_zcrx_ifq *ifq; +}; + int io_shutdown_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) { struct io_shutdown *shutdown = io_kiocb_to_cmd(req, struct io_shutdown); @@ -1209,6 +1217,70 @@ int io_recv(struct io_kiocb *req, unsigned int issue_flags) return ret; } +int io_recvzc_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) +{ + struct io_recvzc *zc = io_kiocb_to_cmd(req, struct io_recvzc); + unsigned ifq_idx; + + if (unlikely(sqe->file_index || sqe->addr2 || sqe->addr || + sqe->len || sqe->addr3)) + return -EINVAL; + + ifq_idx = READ_ONCE(sqe->zcrx_ifq_idx); + if (ifq_idx != 0) + return -EINVAL; + zc->ifq = req->ctx->ifq; + if (!zc->ifq) + return -EINVAL; + + zc->flags = READ_ONCE(sqe->ioprio); + zc->msg_flags = READ_ONCE(sqe->msg_flags); + if (zc->msg_flags) + return -EINVAL; + if (zc->flags & ~(IORING_RECVSEND_POLL_FIRST | IORING_RECV_MULTISHOT)) + return -EINVAL; + /* multishot required */ + if (!(zc->flags & IORING_RECV_MULTISHOT)) + return -EINVAL; + /* All data completions are posted as aux CQEs. */ + req->flags |= REQ_F_APOLL_MULTISHOT; + + return 0; +} + +int io_recvzc(struct io_kiocb *req, unsigned int issue_flags) +{ + struct io_recvzc *zc = io_kiocb_to_cmd(req, struct io_recvzc); + struct socket *sock; + int ret; + + if (!(req->flags & REQ_F_POLLED) && + (zc->flags & IORING_RECVSEND_POLL_FIRST)) + return -EAGAIN; + + sock = sock_from_file(req->file); + if (unlikely(!sock)) + return -ENOTSOCK; + + ret = io_zcrx_recv(req, zc->ifq, sock, zc->msg_flags | MSG_DONTWAIT, + issue_flags); + if (unlikely(ret <= 0) && ret != -EAGAIN) { + if (ret == -ERESTARTSYS) + ret = -EINTR; + + req_set_fail(req); + io_req_set_res(req, ret, 0); + + if (issue_flags & IO_URING_F_MULTISHOT) + return IOU_STOP_MULTISHOT; + return IOU_OK; + } + + if (issue_flags & IO_URING_F_MULTISHOT) + return IOU_ISSUE_SKIP_COMPLETE; + return -EAGAIN; +} + void io_send_zc_cleanup(struct io_kiocb *req) { struct io_sr_msg *zc = io_kiocb_to_cmd(req, struct io_sr_msg); diff --git a/io_uring/opdef.c b/io_uring/opdef.c index 3de75eca1c92..6ae00c0af9a8 100644 --- a/io_uring/opdef.c +++ b/io_uring/opdef.c @@ -36,6 +36,7 @@ #include "waitid.h" #include "futex.h" #include "truncate.h" +#include "zcrx.h" static int io_no_issue(struct io_kiocb *req, unsigned int issue_flags) { @@ -513,6 +514,18 @@ const struct io_issue_def io_issue_defs[] = { .async_size = sizeof(struct io_async_msghdr), #else .prep = io_eopnotsupp_prep, +#endif + }, + [IORING_OP_RECV_ZC] = { + .needs_file = 1, + .unbound_nonreg_file = 1, + .pollin = 1, + .ioprio = 1, +#if defined(CONFIG_NET) + .prep = io_recvzc_prep, + .issue = io_recvzc, +#else + .prep = io_eopnotsupp_prep, #endif }, }; @@ -744,6 +757,9 @@ const struct io_cold_def io_cold_defs[] = { [IORING_OP_LISTEN] = { .name = "LISTEN", }, + [IORING_OP_RECV_ZC] = { + .name = "RECV_ZC", + }, }; const char *io_uring_get_opcode(u8 opcode) diff --git a/io_uring/zcrx.c b/io_uring/zcrx.c index 2b668f09b55f..cecfb04a117c 100644 --- a/io_uring/zcrx.c +++ b/io_uring/zcrx.c @@ -13,6 +13,8 @@ #include #include +#include +#include #include @@ -91,7 +93,12 @@ static void io_zcrx_sync_for_device(const struct page_pool *pool, #define IO_RQ_MAX_ENTRIES 32768 -__maybe_unused +struct io_zcrx_args { + struct io_kiocb *req; + struct io_zcrx_ifq *ifq; + struct socket *sock; +}; + static const struct memory_provider_ops io_uring_pp_zc_ops; static inline struct io_zcrx_area *io_zcrx_iov_to_area(const struct net_iov *niov) @@ -118,6 +125,11 @@ static bool io_zcrx_put_niov_uref(struct net_iov *niov) return true; } +static void io_zcrx_get_niov_uref(struct net_iov *niov) +{ + atomic_inc(io_get_user_counter(niov)); +} + static int io_allocate_rbuf_ring(struct io_zcrx_ifq *ifq, struct io_uring_zcrx_ifq_reg *reg, struct io_uring_region_desc *rd) @@ -609,3 +621,179 @@ static const struct memory_provider_ops io_uring_pp_zc_ops = { .nl_fill = io_pp_nl_fill, .uninstall = io_pp_uninstall, }; + +static bool io_zcrx_queue_cqe(struct io_kiocb *req, struct net_iov *niov, + struct io_zcrx_ifq *ifq, int off, int len) +{ + struct io_uring_zcrx_cqe *rcqe; + struct io_zcrx_area *area; + struct io_uring_cqe *cqe; + u64 offset; + + if (!io_defer_get_uncommited_cqe(req->ctx, &cqe)) + return false; + + cqe->user_data = req->cqe.user_data; + cqe->res = len; + cqe->flags = IORING_CQE_F_MORE; + + area = io_zcrx_iov_to_area(niov); + offset = off + (net_iov_idx(niov) << PAGE_SHIFT); + rcqe = (struct io_uring_zcrx_cqe *)(cqe + 1); + rcqe->off = offset + ((u64)area->area_id << IORING_ZCRX_AREA_SHIFT); + rcqe->__pad = 0; + return true; +} + +static int io_zcrx_recv_frag(struct io_kiocb *req, struct io_zcrx_ifq *ifq, + const skb_frag_t *frag, int off, int len) +{ + struct net_iov *niov; + + if (unlikely(!skb_frag_is_net_iov(frag))) + return -EOPNOTSUPP; + + niov = netmem_to_net_iov(frag->netmem); + if (niov->pp->mp_ops != &io_uring_pp_zc_ops || + niov->pp->mp_priv != ifq) + return -EFAULT; + + if (!io_zcrx_queue_cqe(req, niov, ifq, off + skb_frag_off(frag), len)) + return -ENOSPC; + + /* + * Prevent it from being recycled while user is accessing it. + * It has to be done before grabbing a user reference. + */ + page_pool_ref_netmem(net_iov_to_netmem(niov)); + io_zcrx_get_niov_uref(niov); + return len; +} + +static int +io_zcrx_recv_skb(read_descriptor_t *desc, struct sk_buff *skb, + unsigned int offset, size_t len) +{ + struct io_zcrx_args *args = desc->arg.data; + struct io_zcrx_ifq *ifq = args->ifq; + struct io_kiocb *req = args->req; + struct sk_buff *frag_iter; + unsigned start, start_off; + int i, copy, end, off; + int ret = 0; + + start = skb_headlen(skb); + start_off = offset; + + if (offset < start) + return -EOPNOTSUPP; + + for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { + const skb_frag_t *frag; + + if (WARN_ON(start > offset + len)) + return -EFAULT; + + frag = &skb_shinfo(skb)->frags[i]; + end = start + skb_frag_size(frag); + + if (offset < end) { + copy = end - offset; + if (copy > len) + copy = len; + + off = offset - start; + ret = io_zcrx_recv_frag(req, ifq, frag, off, copy); + if (ret < 0) + goto out; + + offset += ret; + len -= ret; + if (len == 0 || ret != copy) + goto out; + } + start = end; + } + + skb_walk_frags(skb, frag_iter) { + if (WARN_ON(start > offset + len)) + return -EFAULT; + + end = start + frag_iter->len; + if (offset < end) { + copy = end - offset; + if (copy > len) + copy = len; + + off = offset - start; + ret = io_zcrx_recv_skb(desc, frag_iter, off, copy); + if (ret < 0) + goto out; + + offset += ret; + len -= ret; + if (len == 0 || ret != copy) + goto out; + } + start = end; + } + +out: + if (offset == start_off) + return ret; + return offset - start_off; +} + +static int io_zcrx_tcp_recvmsg(struct io_kiocb *req, struct io_zcrx_ifq *ifq, + struct sock *sk, int flags, + unsigned issue_flags) +{ + struct io_zcrx_args args = { + .req = req, + .ifq = ifq, + .sock = sk->sk_socket, + }; + read_descriptor_t rd_desc = { + .count = 1, + .arg.data = &args, + }; + int ret; + + lock_sock(sk); + ret = tcp_read_sock(sk, &rd_desc, io_zcrx_recv_skb); + if (ret <= 0) { + if (ret < 0 || sock_flag(sk, SOCK_DONE)) + goto out; + if (sk->sk_err) + ret = sock_error(sk); + else if (sk->sk_shutdown & RCV_SHUTDOWN) + goto out; + else if (sk->sk_state == TCP_CLOSE) + ret = -ENOTCONN; + else + ret = -EAGAIN; + } else if (sock_flag(sk, SOCK_DONE)) { + /* Make it to retry until it finally gets 0. */ + if (issue_flags & IO_URING_F_MULTISHOT) + ret = IOU_REQUEUE; + else + ret = -EAGAIN; + } +out: + release_sock(sk); + return ret; +} + +int io_zcrx_recv(struct io_kiocb *req, struct io_zcrx_ifq *ifq, + struct socket *sock, unsigned int flags, + unsigned issue_flags) +{ + struct sock *sk = sock->sk; + const struct proto *prot = READ_ONCE(sk->sk_prot); + + if (prot->recvmsg != tcp_recvmsg) + return -EPROTONOSUPPORT; + + sock_rps_record_flow(sk); + return io_zcrx_tcp_recvmsg(req, ifq, sk, flags, issue_flags); +} diff --git a/io_uring/zcrx.h b/io_uring/zcrx.h index 1b6363591f72..a16bdd921f03 100644 --- a/io_uring/zcrx.h +++ b/io_uring/zcrx.h @@ -3,6 +3,7 @@ #define IOU_ZC_RX_H #include +#include #include #include @@ -43,6 +44,9 @@ int io_register_zcrx_ifq(struct io_ring_ctx *ctx, struct io_uring_zcrx_ifq_reg __user *arg); void io_unregister_zcrx_ifqs(struct io_ring_ctx *ctx); void io_shutdown_zcrx_ifqs(struct io_ring_ctx *ctx); +int io_zcrx_recv(struct io_kiocb *req, struct io_zcrx_ifq *ifq, + struct socket *sock, unsigned int flags, + unsigned issue_flags); #else static inline int io_register_zcrx_ifq(struct io_ring_ctx *ctx, struct io_uring_zcrx_ifq_reg __user *arg) @@ -55,6 +59,15 @@ static inline void io_unregister_zcrx_ifqs(struct io_ring_ctx *ctx) static inline void io_shutdown_zcrx_ifqs(struct io_ring_ctx *ctx) { } +static inline int io_zcrx_recv(struct io_kiocb *req, struct io_zcrx_ifq *ifq, + struct socket *sock, unsigned int flags, + unsigned issue_flags) +{ + return -EOPNOTSUPP; +} #endif +int io_recvzc(struct io_kiocb *req, unsigned int issue_flags); +int io_recvzc_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe); + #endif From patchwork Thu Jan 16 23:16:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wei X-Patchwork-Id: 13942461 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (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 0CB962459DF for ; Thu, 16 Jan 2025 23:17:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737069448; cv=none; b=Yzq/aBSbqsMn4m9SErtRfbesEvy/b1dVsytiT4BjnP7BpdV2Ed+yHoF06XyPCvtFRWVX3K7i0od50bYSvL0XYJxlfStl8n6pW3l7MkgLx/X9CzK31YlCawojPh4fX0PyX6rtoKKmeesKfl3OmPQdYbXnCsnJVgXPKuVlkPRD028= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737069448; c=relaxed/simple; bh=aaiuE7B0Uw9ab/FPPlzbqlWb3TL6spaAqgcWcyjNhxY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FkIocoK8GHWs2YjvIYo7tX4iUG9v5rgmEeVTpzau6ZfpWpTdbNvPiuElKOVVLiJ6/MBD0ZUsF8w9xRaP+588Gu3DdGGdm0XwcwFvSPscxRkDcrkgX8PLC8jJ5kiMjAUBoyNBTdOw2q6Aiy+RtzKfTAue5LORgHmHkL2TwEnsEpE= 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=nhRfmHda; arc=none smtp.client-ip=209.85.214.177 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="nhRfmHda" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-21a7ed0155cso23470095ad.3 for ; Thu, 16 Jan 2025 15:17:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=davidwei-uk.20230601.gappssmtp.com; s=20230601; t=1737069446; x=1737674246; 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=SwASS/pkxGxpaFbA4C1raSo9vng4y3SjehvEloDLjXY=; b=nhRfmHdadOWuX97rWflDkVYa7gIOxKnECfRyDJ4cwpbfPxBfOBA5Fjlv2HBTKLjizr 9keEYf9U4DSRXaBj7wusydF+6aOAjM+3VQgiBsoU/KmMZxoxlVWNwI+ZqQTYyPxGx8P+ pCiFzwy9I4HiLmI21+OiPApqS+cORsPGOyKSG5sA2vBF857CLcaD6S5c9JGvt2huprgQ fk90NStPmWziTKvjr2bM9rk4Za7NgV3Vl4J4XU27pH/lHpGMGJEjn1eX4C2HyIVXCh7a 6a3Jlz7cf6SkT6RRDGsWj45R1HWqg2xyMFF/Hsd4kWl56eHu/2pmzhiyTlA4W4CN42Px pySA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737069446; x=1737674246; 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=SwASS/pkxGxpaFbA4C1raSo9vng4y3SjehvEloDLjXY=; b=Wk4w/ughK3+ePU62S6LxtZHgzZB0qWJK455eS7g73y/RaTPU2jvof6xAOGkXlwX0kU 4edXQQbK+CCaZ9fSGhRde5JwAXF5Dd4j6ZcdQ6EycYkf/QJm7BOyLf3WiMLG7A9AbMUj 91qLjO8aG2gL5kDLxWzT6R1POo+JW7CR/2abXcEZ0y+aeZEe3dIZBdOgrtAB5D/cUdN+ nDProDpQJdfdqmL0bPejnUO4midsJwZCkblFGR+mnGxCJn1XGCgzoX78x39CPZ+KH9mm j5S7sT9v8DxFGsUSYGzRDjRHTy4ev7YU2DxG6pp0JADsHXLKhHNZi6P4JPXmTaxc4cb5 Ex5Q== X-Forwarded-Encrypted: i=1; AJvYcCUEOlI+v1d0xpW0FZt/0NDIBuQ1r+KnVy+k0ztHaUlzYkR2Tc+LFCTOy//Zm8OxIbmwmsTRL7s=@vger.kernel.org X-Gm-Message-State: AOJu0YxkbyHZRiGSoatunD4of9VIOtjO6ZRWCi8XU9SEGw8Cj+tm4AkJ IHpdxprPfeXdJcONI6eLmSycjOCbQ9HafWvNT3fF3MATWCDJ4ALoCMA8b2T3Pdc= X-Gm-Gg: ASbGncuk+Jej7bcSaWsp82Lvx5iHlJ2O3z9osAvEj+iZ7GWn0vvU4lFH5zXVbQomm43 qM0gFx0bL9Xl7M6mqF5VhbOCq6axb/f2n40alCDgubdu2YZsr/KatiiXHkQ2uYRZwuXr0QRU56S X6sSH69YCY+XsLl/Dkm9xigpQCiyq864mbPDN5HzdGO4YMsptSFtSW1WEpdl1ZqFurPi95sAsTB hmw5kll4JaX4pI3hmoSAGqRoqyMQZOFuZRBppImApM5EC2NSyN1OA== X-Google-Smtp-Source: AGHT+IGWPRJrAGpTE9j1xAdi52aAn8Lrq8yYbBH7KWYEm/w6Up58D7ZFXVzSE2VV3k7HIRyIC29zgQ== X-Received: by 2002:a05:6a00:3c8a:b0:725:f4c6:6b68 with SMTP id d2e1a72fcca58-72daf93116bmr997647b3a.4.1737069446466; Thu, 16 Jan 2025 15:17:26 -0800 (PST) Received: from localhost ([2a03:2880:ff:7::]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72daba4895csm544961b3a.130.2025.01.16.15.17.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jan 2025 15:17:26 -0800 (PST) From: David Wei To: io-uring@vger.kernel.org, netdev@vger.kernel.org Cc: Jens Axboe , Pavel Begunkov , Jakub Kicinski , Paolo Abeni , "David S. Miller" , Eric Dumazet , Jesper Dangaard Brouer , David Ahern , Mina Almasry , Stanislav Fomichev , Joe Damato , Pedro Tammela Subject: [PATCH net-next v11 17/21] io_uring/zcrx: set pp memory provider for an rx queue Date: Thu, 16 Jan 2025 15:16:59 -0800 Message-ID: <20250116231704.2402455-18-dw@davidwei.uk> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250116231704.2402455-1-dw@davidwei.uk> References: <20250116231704.2402455-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 Set the page pool memory provider for the rx queue configured for zero copy to io_uring. Then the rx queue is reset using netdev_rx_queue_restart() and netdev core + page pool will take care of filling the rx queue from the io_uring zero copy memory provider. For now, there is only one ifq so its destruction happens implicitly during io_uring cleanup. Reviewed-by: Jens Axboe Signed-off-by: David Wei --- io_uring/zcrx.c | 47 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/io_uring/zcrx.c b/io_uring/zcrx.c index cecfb04a117c..0cfa8c0ecff8 100644 --- a/io_uring/zcrx.c +++ b/io_uring/zcrx.c @@ -11,11 +11,12 @@ #include #include #include - -#include +#include #include #include +#include + #include #include "io_uring.h" @@ -275,8 +276,32 @@ static void io_zcrx_drop_netdev(struct io_zcrx_ifq *ifq) spin_unlock(&ifq->lock); } +static void io_close_queue(struct io_zcrx_ifq *ifq) +{ + struct net_device *netdev; + netdevice_tracker netdev_tracker; + struct pp_memory_provider_params p = { + .mp_ops = &io_uring_pp_zc_ops, + .mp_priv = ifq, + }; + + if (ifq->if_rxq == -1) + return; + + spin_lock(&ifq->lock); + netdev = ifq->netdev; + netdev_tracker = ifq->netdev_tracker; + ifq->netdev = NULL; + spin_unlock(&ifq->lock); + + if (netdev) + net_mp_close_rxq(netdev, ifq->if_rxq, &p); + ifq->if_rxq = -1; +} + static void io_zcrx_ifq_free(struct io_zcrx_ifq *ifq) { + io_close_queue(ifq); io_zcrx_drop_netdev(ifq); if (ifq->area) @@ -291,6 +316,7 @@ static void io_zcrx_ifq_free(struct io_zcrx_ifq *ifq) int io_register_zcrx_ifq(struct io_ring_ctx *ctx, struct io_uring_zcrx_ifq_reg __user *arg) { + struct pp_memory_provider_params mp_param = {}; struct io_uring_zcrx_area_reg area; struct io_uring_zcrx_ifq_reg reg; struct io_uring_region_desc rd; @@ -341,7 +367,6 @@ int io_register_zcrx_ifq(struct io_ring_ctx *ctx, goto err; ifq->rq_entries = reg.rq_entries; - ifq->if_rxq = reg.if_rxq; ret = -ENODEV; ifq->netdev = netdev_get_by_index(current->nsproxy->net_ns, reg.if_idx, @@ -358,16 +383,20 @@ int io_register_zcrx_ifq(struct io_ring_ctx *ctx, if (ret) goto err; + mp_param.mp_ops = &io_uring_pp_zc_ops; + mp_param.mp_priv = ifq; + ret = net_mp_open_rxq(ifq->netdev, reg.if_rxq, &mp_param); + if (ret) + goto err; + ifq->if_rxq = reg.if_rxq; + reg.offsets.rqes = sizeof(struct io_uring); reg.offsets.head = offsetof(struct io_uring, head); reg.offsets.tail = offsetof(struct io_uring, tail); if (copy_to_user(arg, ®, sizeof(reg)) || - copy_to_user(u64_to_user_ptr(reg.region_ptr), &rd, sizeof(rd))) { - ret = -EFAULT; - goto err; - } - if (copy_to_user(u64_to_user_ptr(reg.area_ptr), &area, sizeof(area))) { + copy_to_user(u64_to_user_ptr(reg.region_ptr), &rd, sizeof(rd)) || + copy_to_user(u64_to_user_ptr(reg.area_ptr), &area, sizeof(area))) { ret = -EFAULT; goto err; } @@ -444,6 +473,8 @@ void io_shutdown_zcrx_ifqs(struct io_ring_ctx *ctx) if (ctx->ifq) io_zcrx_scrub(ctx->ifq); + + io_close_queue(ctx->ifq); } static inline u32 io_zcrx_rqring_entries(struct io_zcrx_ifq *ifq) From patchwork Thu Jan 16 23:17:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wei X-Patchwork-Id: 13942462 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (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 35909246A09 for ; Thu, 16 Jan 2025 23:17:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737069449; cv=none; b=Vo3HYL2qNTU6FIx/cgvqHpwrnmM0YC59vvTbOTxbTmcSm2N7sL8dI4yHE0VkDTwpKGw2QNiS07Vi1ulYxuCyUkmztGKA4eXsnysztKwVPQle+z/3w4j57ArydIDMfU80ahKsijnxD3qno5N6CiZ+lms+OXv+3wKXhaCHYfYHEvE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737069449; c=relaxed/simple; bh=a0yytqucfmG1Nfx2iu7A4JDn1CAOzvKCv+TQ/9N91bk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CUldC7zUfbFMd4l9kRgJGbxLA+OY0E8iVggL0TeSoygJ9BA74cY9iVS2IK40JUWIN19dHH5lNAGGJ5SF7OGwTGrZrgGubExyRuRD0U/p5zSA1iOm/UG+Zpp8zunD2VeKhtWgiUzjAzfNMmvAL52zzJ6wI3RMmhpSTFo3iAoyR3U= 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=O+gLlPkV; arc=none smtp.client-ip=209.85.214.172 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="O+gLlPkV" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-21661be2c2dso28582925ad.1 for ; Thu, 16 Jan 2025 15:17:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=davidwei-uk.20230601.gappssmtp.com; s=20230601; t=1737069447; x=1737674247; 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=SuAE6fDwK//h41IEaYgXJ1RaqDuWb9ybdIHvBrGsuDQ=; b=O+gLlPkV52bHn1XRniav5XFAlgW77hcATQL58hLTv+u9mXVeYbbGONGivIWbhIxK0M WlNEHeU+vjFJ03pglNcqyO6nTRkmYt7/4AEm7yP6bsBrjIa3axP6g0clwItFl3mcTciN Qo2UaOp5FW121vekzW11r5lDbLmxKswD8BhtRFC29jS3WM2V2c296b7UvxqlTTFVJdwv t2ZDn6NTWzZzRw97seYPK0SNVMfUjHXmXzX1a/+7+7ozRlmUxWJ+MjbHF7xtEmkXHr4R oHAGgj9ETbPndG5LDVt5hF2K4Z01kUoDiI8fzUmIVtrWKR0uUO6CuNP/dKmDGqKuF0Vc L4Qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737069447; x=1737674247; 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=SuAE6fDwK//h41IEaYgXJ1RaqDuWb9ybdIHvBrGsuDQ=; b=mVApsHg3z+8ly5iLpzVrynqMm56LP0kIT3fKZkiFuW40yQabBgeqhzCrCOjably7bW JZLgXS9mQb+gqGByf2EMQFKYZ9CO3jQThCgslAmOGfcf8Pn1gusWsOMeH/lcgx2IiTWQ 0y0Q2h14VDlgJmdvuBcHEfIdeJWgUajsLfpomH9Pkjg09+LSqLXUsbgBWcmDLGf8UGn3 LRyJQ84uz7Gsl+ossRy9o4ToQAtcIwK57sbLIEIdoqy2yrztY/TcVg41wtX48EBIidHT yshRP7osbz+RP7eXZ5yuSDN/ARnNHGu3RtB2VLDOAlpCUiU7cZ6ERiNBTn9ZfbGPxMak zpvA== X-Forwarded-Encrypted: i=1; AJvYcCUapOTshnOlvhpizREFgdSc0NRtdwTavK6sStYgS+iw0fgVwp8KIuvGXtF4ehVW3sQyyrZ2G+g=@vger.kernel.org X-Gm-Message-State: AOJu0YyYyL/rYJkVvqpCXj1c9REnRW48jskWNZ9dVKreNVAUmfyqrM70 +QjRjd/qowNn1TFQKshnsCrapjJbTi/+1cYafb1Bco0FQce5HhFTekybXWrtBzI= X-Gm-Gg: ASbGncuB1LIqC9S4fa6XdCgoP0UYVeM3iclwq8RYiVr7JEA282TXD6/+x6j3xq5oxlb +it3u5RiufJdOClf+YRWv9KuJ717W7onuG6Gr9jhyQ/gKTDnOBOzIoZ51BtY8UsHjuG22g6WzbX YTQtYyBfA085JkVWCNssKROidjPXZ5UYWUp+eh+8IVbealeRbvo7mysRY4bUAClsn0kaHuHzF8O wXvkRS5aGUIK6E3ZK6OqqOeWusLWZLPPj1LaxMJeQ== X-Google-Smtp-Source: AGHT+IFqPtYTzhwR/lxML7Vm56sgRoBNvogqzdMHmjzhV3yhmtRlZcd4FMZX5F+JH/qyvtKHo2F0KQ== X-Received: by 2002:a17:903:947:b0:216:5b64:90f6 with SMTP id d9443c01a7336-21c355fa2eamr7843835ad.45.1737069447373; Thu, 16 Jan 2025 15:17:27 -0800 (PST) Received: from localhost ([2a03:2880:ff:14::]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21c2d404755sm4862385ad.243.2025.01.16.15.17.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jan 2025 15:17:27 -0800 (PST) From: David Wei To: io-uring@vger.kernel.org, netdev@vger.kernel.org Cc: Jens Axboe , Pavel Begunkov , Jakub Kicinski , Paolo Abeni , "David S. Miller" , Eric Dumazet , Jesper Dangaard Brouer , David Ahern , Mina Almasry , Stanislav Fomichev , Joe Damato , Pedro Tammela Subject: [PATCH net-next v11 18/21] io_uring/zcrx: throttle receive requests Date: Thu, 16 Jan 2025 15:17:00 -0800 Message-ID: <20250116231704.2402455-19-dw@davidwei.uk> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250116231704.2402455-1-dw@davidwei.uk> References: <20250116231704.2402455-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 io_zc_rx_tcp_recvmsg() continues until it fails or there is nothing to receive. If the other side sends fast enough, we might get stuck in io_zc_rx_tcp_recvmsg() producing more and more CQEs but not letting the user to handle them leading to unbound latencies. Break out of it based on an arbitrarily chosen limit, the upper layer will either return to userspace or requeue the request. Reviewed-by: Jens Axboe Signed-off-by: Pavel Begunkov Signed-off-by: David Wei --- io_uring/net.c | 2 ++ io_uring/zcrx.c | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/io_uring/net.c b/io_uring/net.c index 5d8b9a016766..86eaba37e739 100644 --- a/io_uring/net.c +++ b/io_uring/net.c @@ -1267,6 +1267,8 @@ int io_recvzc(struct io_kiocb *req, unsigned int issue_flags) if (unlikely(ret <= 0) && ret != -EAGAIN) { if (ret == -ERESTARTSYS) ret = -EINTR; + if (ret == IOU_REQUEUE) + return IOU_REQUEUE; req_set_fail(req); io_req_set_res(req, ret, 0); diff --git a/io_uring/zcrx.c b/io_uring/zcrx.c index 0cfa8c0ecff8..6f3fbb9337db 100644 --- a/io_uring/zcrx.c +++ b/io_uring/zcrx.c @@ -94,10 +94,13 @@ static void io_zcrx_sync_for_device(const struct page_pool *pool, #define IO_RQ_MAX_ENTRIES 32768 +#define IO_SKBS_PER_CALL_LIMIT 20 + struct io_zcrx_args { struct io_kiocb *req; struct io_zcrx_ifq *ifq; struct socket *sock; + unsigned nr_skbs; }; static const struct memory_provider_ops io_uring_pp_zc_ops; @@ -713,6 +716,9 @@ io_zcrx_recv_skb(read_descriptor_t *desc, struct sk_buff *skb, int i, copy, end, off; int ret = 0; + if (unlikely(args->nr_skbs++ > IO_SKBS_PER_CALL_LIMIT)) + return -EAGAIN; + start = skb_headlen(skb); start_off = offset; @@ -803,6 +809,9 @@ static int io_zcrx_tcp_recvmsg(struct io_kiocb *req, struct io_zcrx_ifq *ifq, ret = -ENOTCONN; else ret = -EAGAIN; + } else if (unlikely(args.nr_skbs > IO_SKBS_PER_CALL_LIMIT) && + (issue_flags & IO_URING_F_MULTISHOT)) { + ret = IOU_REQUEUE; } else if (sock_flag(sk, SOCK_DONE)) { /* Make it to retry until it finally gets 0. */ if (issue_flags & IO_URING_F_MULTISHOT) From patchwork Thu Jan 16 23:17:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wei X-Patchwork-Id: 13942463 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (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 239DF241A0F for ; Thu, 16 Jan 2025 23:17:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737069450; cv=none; b=EbI4hqGCC5GgLdyUzl/MPSZGPV1Aa3z/1QZcxOX95r41XYq5i/+BrmA3Iym/RU2ZyHFAyIrdkyKztI0pH9nKc8zP8kfoDQcmOqRUDKglmoVuvCQ4qHX4EuddyubgN6ol73Wun12ZOIpY/HZAV+yXLMuC4guHUUX6pOuw27YgVPA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737069450; c=relaxed/simple; bh=Ikwnka17d1DjjYjVgpxxNA51+/AxFdFK0SnuyJspXJg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pZi0+rLukr4vTgpmvZHryE7DEyFYIxqMzRcX/q0BoIcSLSC6yhUIm9ur7wc8XasK9SrGUH407Y/b9iJhX5WUJ95RrS/aGNeHVVFYgmNDpb167H7MOaKOMrkHNi85DJf2TAKOZ+FF6Pb3Uf18yaduBxDUDtdOFtsEngMTpfs9duU= 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=buEXesAO; arc=none smtp.client-ip=209.85.214.173 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="buEXesAO" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-2165cb60719so27715175ad.0 for ; Thu, 16 Jan 2025 15:17:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=davidwei-uk.20230601.gappssmtp.com; s=20230601; t=1737069448; x=1737674248; 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=+ft/js0IlZV2ZfLIlKmpUh4bnB486G6Ky3HP+N18d0g=; b=buEXesAOu4tVvm1zlvvtO+pxWqIT5dzW4Jg1YXqE+hhW4zYFACrlbVIh/hebRkJJyn Jo1vuLejKWfyCzPgQvUuXx3DQPcqcNObwhbekwdo6aGh1/YR8rLVePJvjVxRcgRIWFeB OyFp42dpBXSQVvpP9lTpknmt9cZwVWqH/y5WrsWwfSM/Ez9enAOiOyZzMkbN1RpdL4ba lUavGXcrfAVT0BUPL4xWEPKLWffTTnYSceJQWHeXqFebEmCXqsCiLBpad64dH+beL3l9 SECP7vpxFIS8U5aS/ivPWJCcfW9xPr9DNzDkupbpdSuPm2cHSanIzz3jrxtigNKQvtXw MQBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737069448; x=1737674248; 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=+ft/js0IlZV2ZfLIlKmpUh4bnB486G6Ky3HP+N18d0g=; b=Yh7OEjQYbIcdLjRTApDxYegVyz4NRACP7UrMaLbDjBadW2PNmWwTJemqiDGe+xH+dd g9SAeqW6DD10o3RdlBbUsJloKlB1VF50ciczsTIh+rzkfyW96WxOmxjpav5LiwrhtMrJ mWyNBJTbJujg1gUuF7WDkAP97lTBfNYUfXV4EVGu+zBHJk96nhRsk6aH7OagPHqXdLQZ F8b6b2El0/ncgTiwdxuARTiITvbdeky5yak0iEKuRWGNJq6DTN76ICtl6U3U3/XpAXya 7evhGZtKd1sIup9dROGCfgZBWiDkVt19nv2+GqKckmbR9fK8tmOjQHaleotuR5ny2YF3 vK0g== X-Forwarded-Encrypted: i=1; AJvYcCVTeS+NYg1mZ0Bkd3NlfEQ1+V1wFK2oY89lsGMYToIuA1N0zbfJ6yP3D2pQEN7bVVieSUqzWbY=@vger.kernel.org X-Gm-Message-State: AOJu0YyWjuuHDpEMinq6r5NYJDxDUE4cauDPD/wWaGTmTNXvs+8OKvs1 62uIz80LRsrHvLrLHejGddQs5N/3FnzRL8V8rCF5QwWMhUpmFLkCg0b0ehou02w= X-Gm-Gg: ASbGncvw8FewzSdnGjIkBhK3Y5iIZbf3DT+U5aIrHp/UUvo5MfBydRkazgQnjOYUXSW XcIsSYuFYOc4D5r+P9JyfLnzc4I89w4Oey+4lm1yvm4yDiO6te2e1dC1lfNhsFpX8BlqsJD2wyt 5S4HYRG8/i9yOnOPkuPg4v9o4rsMMyadLSAxGkDSTUPGZQnofXsJLo08QQd0ojniQreYiuih7LG 0VzTTbBaRycvRXnuzJukAxqIiLobbAnID8hOdi/ X-Google-Smtp-Source: AGHT+IHTTM5rf+VxVaR+RyHDAh6qHIQxvNvoWjQ++Qdu8aIT/2rRlbgvQ1M8p95XrUhsCEaDqDuJxg== X-Received: by 2002:a05:6a20:7492:b0:1e1:ae4a:1d42 with SMTP id adf61e73a8af0-1eb2159cc48mr708466637.31.1737069448424; Thu, 16 Jan 2025 15:17:28 -0800 (PST) Received: from localhost ([2a03:2880:ff:d::]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72dababc169sm555577b3a.172.2025.01.16.15.17.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jan 2025 15:17:28 -0800 (PST) From: David Wei To: io-uring@vger.kernel.org, netdev@vger.kernel.org Cc: Jens Axboe , Pavel Begunkov , Jakub Kicinski , Paolo Abeni , "David S. Miller" , Eric Dumazet , Jesper Dangaard Brouer , David Ahern , Mina Almasry , Stanislav Fomichev , Joe Damato , Pedro Tammela Subject: [PATCH net-next v11 19/21] io_uring/zcrx: add copy fallback Date: Thu, 16 Jan 2025 15:17:01 -0800 Message-ID: <20250116231704.2402455-20-dw@davidwei.uk> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250116231704.2402455-1-dw@davidwei.uk> References: <20250116231704.2402455-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 are scenarios in which the zerocopy path can get a kernel buffer instead of a net_iov and needs to copy it to the user, whether it is because of mis-steering or simply getting an skb with the linear part. In this case, grab a net_iov, copy into it and return it to the user as normally. At the moment the user doesn't get any indication whether there was a copy or not, which is left for follow up work. Reviewed-by: Jens Axboe Signed-off-by: Pavel Begunkov Signed-off-by: David Wei --- io_uring/zcrx.c | 120 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 114 insertions(+), 6 deletions(-) diff --git a/io_uring/zcrx.c b/io_uring/zcrx.c index 6f3fbb9337db..3366f25d53bd 100644 --- a/io_uring/zcrx.c +++ b/io_uring/zcrx.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -134,6 +135,13 @@ static void io_zcrx_get_niov_uref(struct net_iov *niov) atomic_inc(io_get_user_counter(niov)); } +static inline struct page *io_zcrx_iov_page(const struct net_iov *niov) +{ + struct io_zcrx_area *area = io_zcrx_iov_to_area(niov); + + return area->pages[net_iov_idx(niov)]; +} + static int io_allocate_rbuf_ring(struct io_zcrx_ifq *ifq, struct io_uring_zcrx_ifq_reg *reg, struct io_uring_region_desc *rd) @@ -446,6 +454,11 @@ static void io_zcrx_return_niov(struct net_iov *niov) { netmem_ref netmem = net_iov_to_netmem(niov); + if (!niov->pp) { + /* copy fallback allocated niovs */ + io_zcrx_return_niov_freelist(niov); + return; + } page_pool_put_unrefed_netmem(niov->pp, netmem, -1, false); } @@ -679,13 +692,93 @@ static bool io_zcrx_queue_cqe(struct io_kiocb *req, struct net_iov *niov, return true; } +static struct net_iov *io_zcrx_alloc_fallback(struct io_zcrx_area *area) +{ + struct net_iov *niov = NULL; + + spin_lock_bh(&area->freelist_lock); + if (area->free_count) + niov = __io_zcrx_get_free_niov(area); + spin_unlock_bh(&area->freelist_lock); + + if (niov) + page_pool_fragment_netmem(net_iov_to_netmem(niov), 1); + return niov; +} + +static ssize_t io_zcrx_copy_chunk(struct io_kiocb *req, struct io_zcrx_ifq *ifq, + void *src_base, struct page *src_page, + unsigned int src_offset, size_t len) +{ + struct io_zcrx_area *area = ifq->area; + size_t copied = 0; + int ret = 0; + + while (len) { + size_t copy_size = min_t(size_t, PAGE_SIZE, len); + const int dst_off = 0; + struct net_iov *niov; + struct page *dst_page; + void *dst_addr; + + niov = io_zcrx_alloc_fallback(area); + if (!niov) { + ret = -ENOMEM; + break; + } + + dst_page = io_zcrx_iov_page(niov); + dst_addr = kmap_local_page(dst_page); + if (src_page) + src_base = kmap_local_page(src_page); + + memcpy(dst_addr, src_base + src_offset, copy_size); + + if (src_page) + kunmap_local(src_base); + kunmap_local(dst_addr); + + if (!io_zcrx_queue_cqe(req, niov, ifq, dst_off, copy_size)) { + io_zcrx_return_niov(niov); + ret = -ENOSPC; + break; + } + + io_zcrx_get_niov_uref(niov); + src_offset += copy_size; + len -= copy_size; + copied += copy_size; + } + + return copied ? copied : ret; +} + +static int io_zcrx_copy_frag(struct io_kiocb *req, struct io_zcrx_ifq *ifq, + const skb_frag_t *frag, int off, int len) +{ + struct page *page = skb_frag_page(frag); + u32 p_off, p_len, t, copied = 0; + int ret = 0; + + off += skb_frag_off(frag); + + skb_frag_foreach_page(frag, off, len, + page, p_off, p_len, t) { + ret = io_zcrx_copy_chunk(req, ifq, NULL, page, p_off, p_len); + if (ret < 0) + return copied ? copied : ret; + copied += ret; + } + return copied; +} + static int io_zcrx_recv_frag(struct io_kiocb *req, struct io_zcrx_ifq *ifq, const skb_frag_t *frag, int off, int len) { struct net_iov *niov; if (unlikely(!skb_frag_is_net_iov(frag))) - return -EOPNOTSUPP; + return io_zcrx_copy_frag(req, ifq, frag, off, len); niov = netmem_to_net_iov(frag->netmem); if (niov->pp->mp_ops != &io_uring_pp_zc_ops || @@ -712,18 +805,33 @@ io_zcrx_recv_skb(read_descriptor_t *desc, struct sk_buff *skb, struct io_zcrx_ifq *ifq = args->ifq; struct io_kiocb *req = args->req; struct sk_buff *frag_iter; - unsigned start, start_off; + unsigned start, start_off = offset; int i, copy, end, off; int ret = 0; if (unlikely(args->nr_skbs++ > IO_SKBS_PER_CALL_LIMIT)) return -EAGAIN; - start = skb_headlen(skb); - start_off = offset; + if (unlikely(offset < skb_headlen(skb))) { + ssize_t copied; + size_t to_copy; - if (offset < start) - return -EOPNOTSUPP; + to_copy = min_t(size_t, skb_headlen(skb) - offset, len); + copied = io_zcrx_copy_chunk(req, ifq, skb->data, NULL, + offset, to_copy); + if (copied < 0) { + ret = copied; + goto out; + } + offset += copied; + len -= copied; + if (!len) + goto out; + if (offset != skb_headlen(skb)) + goto out; + } + + start = skb_headlen(skb); for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { const skb_frag_t *frag; From patchwork Thu Jan 16 23:17:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wei X-Patchwork-Id: 13942464 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 14CE2246A09 for ; Thu, 16 Jan 2025 23:17:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737069452; cv=none; b=TsBaclTa+hZmnfoqLnRWj5EM2HcQNszxY5fkBWUZlDgFVyJkTFSi2QzS3qWqZyNMVpt+p15eDitIbwoqE/C4aHUZ8m5n8rV3M++aDMrTTce+iAiePqpCyUpMICC6eVhDonW7KIdeniAq07wZ/tnUMjwdMdWMFCPLMRah1QODUNo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737069452; c=relaxed/simple; bh=aPsgcI6sv2YIZcrbbnlWPzhKE0O2/vrVZpMxYf0vPWw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UM24+7uEnETKr/UvdhwzthcBXEEe4ggQiXZud0NVX6W2ukEqaPcDcskagucNeswOfDGtKIvWZ5N5ypB9Ra5Q+B1zF1ICAmV3o6IZaQVSG+DLc/ECULKrJTFh+FX3GzfhEzdu+BC0EDgDVfsNRc9IdxRhcn/hBAFe+hcfXsRZYgI= 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=n7rakZHI; arc=none smtp.client-ip=209.85.214.181 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="n7rakZHI" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-216728b1836so25928205ad.0 for ; Thu, 16 Jan 2025 15:17:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=davidwei-uk.20230601.gappssmtp.com; s=20230601; t=1737069449; x=1737674249; 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=EFrx4dtkhpWaD6dvhicsjhhig5cONS03Ll2dOXxfwMI=; b=n7rakZHITxkr4P++NlkiVyKNz8+7y3YrB5WBlOnwjpCE2C6kZIcXdoj+SfRjpCEJu5 33/wuFLBSRfh/vf5snhIdR+wvYK+e+HGrcMTJDbPsWz24xK7GxR6Q1isQoeaHs/FfKjY VYG31SY0EKCDkQn3hPz0V3w2HU6KfEIqvS9qeBjLQx/nCkcx5a12ydSReJuVgy3QEGYF s/524YBGVjsGnVgvabQ/lcjPPeeCjaazPR8fq8C6JVi1m7eUSKvX5PCRNsJ21xa9v43U 0gVGHCVnM/LQ6uls0XLG7sumnL6ytn8pFX8Bb6ThVKdP8Kkzkd7kRw0Uq3A5jhBDQa6F miOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737069449; x=1737674249; 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=EFrx4dtkhpWaD6dvhicsjhhig5cONS03Ll2dOXxfwMI=; b=Bea9IkEFoTNzGvzkl2aSRCyBsBiS5K14pNDDMbaBQdFKClGISedkmzWbE+ix/+Pv9b RdZt0BOVkxrLuTGkj8ltEVEABVieei7iSwYe1XuUE44CsaZ+dz5TpjCQIbDd5l6/ZRgJ BzWW4seXL6jKjApfuZHN2qM3KvneVpsYy6p7wwQnBrPYIpAymjqd/wYYVUt36/Dpomp+ VfdJxAzj/a5EgzeLq8Ur55ilSGgxGlUTg/XRx6W3Eu4wTJqrjfllje65XVmsarkPChdM jivakeStiQr8EM2spIA10rUp0728td+HpZRQZHShulmUBc6nfqnKHxx4fvqxySMtJd3T NGHw== X-Forwarded-Encrypted: i=1; AJvYcCXIJu0o015TVWoE1rFYSBBQKU/N/9gkSs/s0DbInU99KddS2Wjy5+uySzxa99oXfOTJ13Iw9qA=@vger.kernel.org X-Gm-Message-State: AOJu0YzyyULYxgcXq8VY23MLLY3LJXj37Cf/qezNJINbdBStwRfQlWX9 UIj8RwHGivmyPbjBP0jVA0b3utPmGLnJp/BzjYMS8CZesvhANV0x/alWWz3uEGE= X-Gm-Gg: ASbGncsR6AJ+ofchjEhzg/dPW1h2x35fjU7VUW6j8IK+VuU1kClEFPjsgKv/d2dG5ll FQECHmoJa2ITKAYE2cYJeS6g8+C1UM0TY7IcHGRg/ud8nQf17qDrcViiErR52sSlesFHhyHbRR5 tLrYEvGpHFl8NqczObPG+KWCvQ05CgI41WvXnyQhzAXARq9R7aeNPjCtJmwO3Y2BRSx1t0QmutA x9W3NcTyoeLj/6MS6rmV38jWtPVuTwciqVCoPhzKQ== X-Google-Smtp-Source: AGHT+IEJ/gqghOJxd2TDDQDXM4bFQnd4Rz3G5xYAmJzRD5lljlGIKa3GdLohUK0dl0NVpi4ehbGUEA== X-Received: by 2002:a05:6a20:3d89:b0:1e0:c6c0:1e1f with SMTP id adf61e73a8af0-1eb215e1995mr668470637.36.1737069449357; Thu, 16 Jan 2025 15:17:29 -0800 (PST) Received: from localhost ([2a03:2880:ff:1a::]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72dab81754csm565197b3a.63.2025.01.16.15.17.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jan 2025 15:17:29 -0800 (PST) From: David Wei To: io-uring@vger.kernel.org, netdev@vger.kernel.org Cc: Jens Axboe , Pavel Begunkov , Jakub Kicinski , Paolo Abeni , "David S. Miller" , Eric Dumazet , Jesper Dangaard Brouer , David Ahern , Mina Almasry , Stanislav Fomichev , Joe Damato , Pedro Tammela Subject: [PATCH net-next v11 20/21] net: add documentation for io_uring zcrx Date: Thu, 16 Jan 2025 15:17:02 -0800 Message-ID: <20250116231704.2402455-21-dw@davidwei.uk> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250116231704.2402455-1-dw@davidwei.uk> References: <20250116231704.2402455-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 Add documentation for io_uring zero copy Rx that explains requirements and the user API. Signed-off-by: David Wei --- Documentation/networking/index.rst | 1 + Documentation/networking/iou-zcrx.rst | 201 ++++++++++++++++++++++++++ 2 files changed, 202 insertions(+) create mode 100644 Documentation/networking/iou-zcrx.rst diff --git a/Documentation/networking/index.rst b/Documentation/networking/index.rst index 058193ed2eeb..c64133d309bf 100644 --- a/Documentation/networking/index.rst +++ b/Documentation/networking/index.rst @@ -63,6 +63,7 @@ Contents: gtp ila ioam6-sysctl + iou-zcrx ip_dynaddr ipsec ip-sysctl diff --git a/Documentation/networking/iou-zcrx.rst b/Documentation/networking/iou-zcrx.rst new file mode 100644 index 000000000000..7f6b7c072b59 --- /dev/null +++ b/Documentation/networking/iou-zcrx.rst @@ -0,0 +1,201 @@ +.. SPDX-License-Identifier: GPL-2.0 + +===================== +io_uring zero copy Rx +===================== + +Introduction +============ + +io_uring zero copy Rx (ZC Rx) is a feature that removes kernel-to-user copy on +the network receive path, allowing packet data to be received directly into +userspace memory. This feature is different to TCP_ZEROCOPY_RECEIVE in that +there are no strict alignment requirements and no need to mmap()/munmap(). +Compared to kernel bypass solutions such as e.g. DPDK, the packet headers are +processed by the kernel TCP stack as normal. + +NIC HW Requirements +=================== + +Several NIC HW features are required for io_uring ZC Rx to work. For now the +kernel API does not configure the NIC and it must be done by the user. + +Header/data split +----------------- + +Required to split packets at the L4 boundary into a header and a payload. +Headers are received into kernel memory as normal and processed by the TCP +stack as normal. Payloads are received into userspace memory directly. + +Flow steering +------------- + +Specific HW Rx queues are configured for this feature, but modern NICs +typically distribute flows across all HW Rx queues. Flow steering is required +to ensure that only desired flows are directed towards HW queues that are +configured for io_uring ZC Rx. + +RSS +--- + +In addition to flow steering above, RSS is required to steer all other non-zero +copy flows away from queues that are configured for io_uring ZC Rx. + +Usage +===== + +Setup NIC +--------- + +Must be done out of band for now. + +Ensure there are at least two queues:: + + ethtool -L eth0 combined 2 + +Enable header/data split:: + + ethtool -G eth0 tcp-data-split on + +Carve out half of the HW Rx queues for zero copy using RSS:: + + ethtool -X eth0 equal 1 + +Set up flow steering, bearing in mind that queues are 0-indexed:: + + ethtool -N eth0 flow-type tcp6 ... action 1 + +Setup io_uring +-------------- + +This section describes the low level io_uring kernel API. Please refer to +liburing documentation for how to use the higher level API. + +Create an io_uring instance with the following required setup flags:: + + IORING_SETUP_SINGLE_ISSUER + IORING_SETUP_DEFER_TASKRUN + IORING_SETUP_CQE32 + +Create memory area +------------------ + +Allocate userspace memory area for receiving zero copy data:: + + void *area_ptr = mmap(NULL, area_size, + PROT_READ | PROT_WRITE, + MAP_ANONYMOUS | MAP_PRIVATE, + 0, 0); + +Create refill ring +------------------ + +Allocate memory for a shared ringbuf used for returning consumed buffers:: + + void *ring_ptr = mmap(NULL, ring_size, + PROT_READ | PROT_WRITE, + MAP_ANONYMOUS | MAP_PRIVATE, + 0, 0); + +This refill ring consists of some space for the header, followed by an array of +``struct io_uring_zcrx_rqe``:: + + size_t rq_entries = 4096; + size_t ring_size = rq_entries * sizeof(struct io_uring_zcrx_rqe) + PAGE_SIZE; + /* align to page size */ + ring_size = (ring_size + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1); + +Register ZC Rx +-------------- + +Fill in registration structs:: + + struct io_uring_zcrx_area_reg area_reg = { + .addr = (__u64)(unsigned long)area_ptr, + .len = area_size, + .flags = 0, + }; + + struct io_uring_region_desc region_reg = { + .user_addr = (__u64)(unsigned long)ring_ptr, + .size = ring_size, + .flags = IORING_MEM_REGION_TYPE_USER, + }; + + struct io_uring_zcrx_ifq_reg reg = { + .if_idx = if_nametoindex("eth0"), + /* this is the HW queue with desired flow steered into it */ + .if_rxq = 1, + .rq_entries = rq_entries, + .area_ptr = (__u64)(unsigned long)&area_reg, + .region_ptr = (__u64)(unsigned long)®ion_reg, + }; + +Register with kernel:: + + io_uring_register_ifq(ring, ®); + +Map refill ring +--------------- + +The kernel fills in fields for the refill ring in the registration ``struct +io_uring_zcrx_ifq_reg``. Map it into userspace:: + + struct io_uring_zcrx_rq refill_ring; + + refill_ring.khead = (unsigned *)((char *)ring_ptr + reg.offsets.head); + refill_ring.khead = (unsigned *)((char *)ring_ptr + reg.offsets.tail); + refill_ring.rqes = + (struct io_uring_zcrx_rqe *)((char *)ring_ptr + reg.offsets.rqes); + refill_ring.rq_tail = 0; + refill_ring.ring_ptr = ring_ptr; + +Receiving data +-------------- + +Prepare a zero copy recv request:: + + struct io_uring_sqe *sqe; + + sqe = io_uring_get_sqe(ring); + io_uring_prep_rw(IORING_OP_RECV_ZC, sqe, fd, NULL, 0, 0); + sqe->ioprio |= IORING_RECV_MULTISHOT; + +Now, submit and wait:: + + io_uring_submit_and_wait(ring, 1); + +Finally, process completions:: + + struct io_uring_cqe *cqe; + unsigned int count = 0; + unsigned int head; + + io_uring_for_each_cqe(ring, head, cqe) { + struct io_uring_zcrx_cqe *rcqe = (struct io_uring_zcrx_cqe *)(cqe + 1); + + unsigned char *data = area_ptr + (rcqe->off & IORING_ZCRX_AREA_MASK); + /* do something with the data */ + + count++; + } + io_uring_cq_advance(ring, count); + +Recycling buffers +----------------- + +Return buffers back to the kernel to be used again:: + + struct io_uring_zcrx_rqe *rqe; + unsigned mask = refill_ring.ring_entries - 1; + rqe = &refill_ring.rqes[refill_ring.rq_tail & mask]; + + area_offset = rcqe->off & IORING_ZCRX_AREA_MASK; + rqe->off = area_offset | area_reg.rq_area_token; + rqe->len = cqe->res; + IO_URING_WRITE_ONCE(*refill_ring.ktail, ++refill_ring.rq_tail); + +Testing +======= + +See ``tools/testing/selftests/drivers/net/hw/iou-zcrx.c`` From patchwork Thu Jan 16 23:17:03 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wei X-Patchwork-Id: 13942465 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) (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 3904424224B for ; Thu, 16 Jan 2025 23:17:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737069453; cv=none; b=cnkgUHDuiGfbDJr6UCEfID6EM8/IXwkbcfB0tZYUPU5vx5gke4JN5YhIq2ktzNjffrr7+NS6G1fpTwcqdd3Ejbty15haINzj21SdaBQoh0yvUvZ41Rrdxa3t6uvJeSXa9AvRPFDNqwvNAifWs83hzL651CtRRhNcsOM6MBx2OAU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737069453; c=relaxed/simple; bh=i7Cjoz4VNdh3MjU2C4EMCLAhhMhye1Vvv2tRpktseOg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lXPooEjcZu3p1RBcnKm9gF6l02ToVMsU/zDtdG6U1oAZOu8VUGnPToglSHvPluXu44x4Te56K1SXNdT7yyneIK7tXfONh0Ncz143iUhcRsLFD1xrSklwM2HZHBNr8dO8czJNflb0kIL0Lf0LJxtsWq9A/n5xNmXn3MGc8IABq7o= 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=zrqXg5C0; arc=none smtp.client-ip=209.85.216.52 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="zrqXg5C0" Received: by mail-pj1-f52.google.com with SMTP id 98e67ed59e1d1-2ee8aa26415so2616911a91.1 for ; Thu, 16 Jan 2025 15:17:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=davidwei-uk.20230601.gappssmtp.com; s=20230601; t=1737069450; x=1737674250; 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=rcksOgDKGx32nprf9vxJWOghQ71hxo/2GRViGsIWrPo=; b=zrqXg5C0x7jwOJqOcf3YpneW7/mmZdiY8k6tSF3i7+TDzmnG22mWlGFYI6K32DAFtp NXwj/40ACPeCTrmiT/+37qCA/OAD0DnN5szffbzU4S7ySXjubULLTstvJGtVnK860j23 RTpZrxcTgq0ed8kSIZgh5ukilcNGcJtKWXeFyHl2QvrdffNFxGYdsae/W4JInoCW+xjf NAYCF2h+4HEg3in1C5QBEU7OwS0QwYIOhpOexrWM/MQ6v/FqB8yTIHOAXlGJz2wRRcCu KbTcCmBe/Qg+tMj6jqcXjQ7+GV4F9lgFHvfVj0Q/Dw0aj9UyzWTCOa59y0cpgfxLEwKo dddw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737069450; x=1737674250; 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=rcksOgDKGx32nprf9vxJWOghQ71hxo/2GRViGsIWrPo=; b=XpbDELSXpwBo+DfuFJ7ZPTGjvN0T34oVnWr6kZu0dsM/yHDDdAUVp9HaiNcnEyNGvC vfYWC5x9SefqFA3TUsf+JGYOOVeSmYiFfDT8OC2Wcva3ZDsCqBkAuMSB+fDVFKKgEyAz SkfFHtXyDkK8M2s9WQwSt5R0oIezz47Nt/qH9y5mChMEpaig+jkRa5bBrA0JObVGUun4 fakdJOoG7ypjmdoPww/Kl5F33kU+C880Gzzhm0uqkNg2U0StCzUpFNBqz2S1L+uX/UUj wSwqiIeaJ48eeMi0CJyMb7Nnme/LlIJpqmpgBNbDCT2QyVnBRzmcZEjiSlbUfBrxaFqx S46A== X-Forwarded-Encrypted: i=1; AJvYcCXm3P+DlfzoQaf5ZtoCMzuohWFyNa3mWudZ7qkyXwLT4TWj7EZO3G8b3mkOTqsWD+u+e29wmTQ=@vger.kernel.org X-Gm-Message-State: AOJu0YyBey73VoUWHdbXB26XGXWSaASZ39VjSdEbQkh7APL83Yy48Oni +UH2W2cfjkIe7H1EA93O2vZkKAkS9xZA7NRZeRG+K9RMP0QQYn/7gz0GYX4FV80= X-Gm-Gg: ASbGncu4p5XA0IlR9YFDyxVwJiOXYiG5i3cxek58trUn3I9QKaPetA9vWN+M66IBDnv wcAcKFPZKaTxzlk02f8WS++OV7m6F4kCnv0OOTv1HhqIm82dLnOnsQHCcN4fqYbg2GuF2SJv86H bSthSak4Bg1uairLCvikgjhKsvqxWE6MQsgVFGVi+Ni/jrD/torAB0oM1N32IRjIohoMooNVdXy FA2Rb8KCEXxXeQsqnKv9WRWX3kHZClMJgg6d7ptBw== X-Google-Smtp-Source: AGHT+IFluthp7LsBVG1wC3BmGoJsmccQzfwVNJ0sdUfNTRhSctzFg+dEw+quO++miw4qkh5y9dTdoQ== X-Received: by 2002:a17:90b:258b:b0:2ee:48bf:7dc9 with SMTP id 98e67ed59e1d1-2f782cb092dmr663086a91.15.1737069450300; Thu, 16 Jan 2025 15:17:30 -0800 (PST) Received: from localhost ([2a03:2880:ff:4e::]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21c2d4027fcsm4910135ad.214.2025.01.16.15.17.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jan 2025 15:17:30 -0800 (PST) From: David Wei To: io-uring@vger.kernel.org, netdev@vger.kernel.org Cc: Jens Axboe , Pavel Begunkov , Jakub Kicinski , Paolo Abeni , "David S. Miller" , Eric Dumazet , Jesper Dangaard Brouer , David Ahern , Mina Almasry , Stanislav Fomichev , Joe Damato , Pedro Tammela Subject: [PATCH net-next v11 21/21] io_uring/zcrx: add selftest Date: Thu, 16 Jan 2025 15:17:03 -0800 Message-ID: <20250116231704.2402455-22-dw@davidwei.uk> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250116231704.2402455-1-dw@davidwei.uk> References: <20250116231704.2402455-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 Add a selftest for io_uring zero copy Rx. This test cannot run locally and requires a remote host to be configured in net.config. The remote host must have hardware support for zero copy Rx as listed in the documentation page. The test will restore the NIC config back to before the test and is idempotent. liburing is required to compile the test and be installed on the remote host running the test. Signed-off-by: David Wei --- .../selftests/drivers/net/hw/.gitignore | 2 + .../testing/selftests/drivers/net/hw/Makefile | 5 + .../selftests/drivers/net/hw/iou-zcrx.c | 432 ++++++++++++++++++ .../selftests/drivers/net/hw/iou-zcrx.py | 64 +++ 4 files changed, 503 insertions(+) create mode 100644 tools/testing/selftests/drivers/net/hw/iou-zcrx.c create mode 100755 tools/testing/selftests/drivers/net/hw/iou-zcrx.py diff --git a/tools/testing/selftests/drivers/net/hw/.gitignore b/tools/testing/selftests/drivers/net/hw/.gitignore index e9fe6ede681a..6942bf575497 100644 --- a/tools/testing/selftests/drivers/net/hw/.gitignore +++ b/tools/testing/selftests/drivers/net/hw/.gitignore @@ -1 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0-only +iou-zcrx ncdevmem diff --git a/tools/testing/selftests/drivers/net/hw/Makefile b/tools/testing/selftests/drivers/net/hw/Makefile index 21ba64ce1e34..7efc47c89463 100644 --- a/tools/testing/selftests/drivers/net/hw/Makefile +++ b/tools/testing/selftests/drivers/net/hw/Makefile @@ -1,5 +1,7 @@ # SPDX-License-Identifier: GPL-2.0+ OR MIT +TEST_GEN_FILES = iou-zcrx + TEST_PROGS = \ csum.py \ devlink_port_split.py \ @@ -10,6 +12,7 @@ TEST_PROGS = \ ethtool_rmon.sh \ hw_stats_l3.sh \ hw_stats_l3_gre.sh \ + iou-zcrx.py \ loopback.sh \ nic_link_layer.py \ nic_performance.py \ @@ -38,3 +41,5 @@ include ../../../lib.mk # YNL build YNL_GENS := ethtool netdev include ../../../net/ynl.mk + +$(OUTPUT)/iou-zcrx: LDLIBS += -luring diff --git a/tools/testing/selftests/drivers/net/hw/iou-zcrx.c b/tools/testing/selftests/drivers/net/hw/iou-zcrx.c new file mode 100644 index 000000000000..0809db134bba --- /dev/null +++ b/tools/testing/selftests/drivers/net/hw/iou-zcrx.c @@ -0,0 +1,432 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#define PAGE_SIZE (4096) +#define AREA_SIZE (8192 * PAGE_SIZE) +#define SEND_SIZE (512 * 4096) +#define min(a, b) \ + ({ \ + typeof(a) _a = (a); \ + typeof(b) _b = (b); \ + _a < _b ? _a : _b; \ + }) +#define min_t(t, a, b) \ + ({ \ + t _ta = (a); \ + t _tb = (b); \ + min(_ta, _tb); \ + }) + +#define ALIGN_UP(v, align) (((v) + (align) - 1) & ~((align) - 1)) + +static int cfg_family = PF_UNSPEC; +static int cfg_server; +static int cfg_client; +static int cfg_port = 8000; +static int cfg_payload_len; +static const char *cfg_ifname; +static int cfg_queue_id = -1; + +static socklen_t cfg_alen; +static struct sockaddr_storage cfg_addr; + +static char payload[SEND_SIZE] __attribute__((aligned(PAGE_SIZE))); +static void *area_ptr; +static void *ring_ptr; +static size_t ring_size; +static struct io_uring_zcrx_rq rq_ring; +static unsigned long area_token; +static int connfd; +static bool stop; +static size_t received; + +static unsigned long gettimeofday_ms(void) +{ + struct timeval tv; + + gettimeofday(&tv, NULL); + return (tv.tv_sec * 1000) + (tv.tv_usec / 1000); +} + +static inline size_t get_refill_ring_size(unsigned int rq_entries) +{ + size_t size; + + ring_size = rq_entries * sizeof(struct io_uring_zcrx_rqe); + /* add space for the header (head/tail/etc.) */ + ring_size += PAGE_SIZE; + return ALIGN_UP(ring_size, 4096); +} + +static void setup_zcrx(struct io_uring *ring) +{ + unsigned int ifindex; + unsigned int rq_entries = 4096; + int ret; + + ifindex = if_nametoindex(cfg_ifname); + if (!ifindex) + error(1, 0, "bad interface name: %s", cfg_ifname); + + area_ptr = mmap(NULL, + AREA_SIZE, + PROT_READ | PROT_WRITE, + MAP_ANONYMOUS | MAP_PRIVATE, + 0, + 0); + if (area_ptr == MAP_FAILED) + error(1, 0, "mmap(): zero copy area"); + + ring_size = get_refill_ring_size(rq_entries); + ring_ptr = mmap(NULL, + ring_size, + PROT_READ | PROT_WRITE, + MAP_ANONYMOUS | MAP_PRIVATE, + 0, + 0); + + struct io_uring_region_desc region_reg = { + .size = ring_size, + .user_addr = (__u64)(unsigned long)ring_ptr, + .flags = IORING_MEM_REGION_TYPE_USER, + }; + + struct io_uring_zcrx_area_reg area_reg = { + .addr = (__u64)(unsigned long)area_ptr, + .len = AREA_SIZE, + .flags = 0, + }; + + struct io_uring_zcrx_ifq_reg reg = { + .if_idx = ifindex, + .if_rxq = cfg_queue_id, + .rq_entries = rq_entries, + .area_ptr = (__u64)(unsigned long)&area_reg, + .region_ptr = (__u64)(unsigned long)®ion_reg, + }; + + ret = io_uring_register_ifq(ring, ®); + if (ret) + error(1, 0, "io_uring_register_ifq(): %d", ret); + + rq_ring.khead = (unsigned int *)((char *)ring_ptr + reg.offsets.head); + rq_ring.ktail = (unsigned int *)((char *)ring_ptr + reg.offsets.tail); + rq_ring.rqes = (struct io_uring_zcrx_rqe *)((char *)ring_ptr + reg.offsets.rqes); + rq_ring.rq_tail = 0; + rq_ring.ring_entries = reg.rq_entries; + + area_token = area_reg.rq_area_token; +} + +static void add_accept(struct io_uring *ring, int sockfd) +{ + struct io_uring_sqe *sqe; + + sqe = io_uring_get_sqe(ring); + + io_uring_prep_accept(sqe, sockfd, NULL, NULL, 0); + sqe->user_data = 1; +} + +static void add_recvzc(struct io_uring *ring, int sockfd) +{ + struct io_uring_sqe *sqe; + + sqe = io_uring_get_sqe(ring); + + io_uring_prep_rw(IORING_OP_RECV_ZC, sqe, sockfd, NULL, 0, 0); + sqe->ioprio |= IORING_RECV_MULTISHOT; + sqe->user_data = 2; +} + +static void process_accept(struct io_uring *ring, struct io_uring_cqe *cqe) +{ + if (cqe->res < 0) + error(1, 0, "accept()"); + if (connfd) + error(1, 0, "Unexpected second connection"); + + connfd = cqe->res; + add_recvzc(ring, connfd); +} + +static void process_recvzc(struct io_uring *ring, struct io_uring_cqe *cqe) +{ + unsigned rq_mask = rq_ring.ring_entries - 1; + struct io_uring_zcrx_cqe *rcqe; + struct io_uring_zcrx_rqe *rqe; + struct io_uring_sqe *sqe; + uint64_t mask; + char *data; + ssize_t n; + int i; + + if (cqe->res == 0 && cqe->flags == 0) { + stop = true; + return; + } + + if (cqe->res < 0) + error(1, 0, "recvzc(): %d", cqe->res); + + if (!(cqe->flags & IORING_CQE_F_MORE)) + add_recvzc(ring, connfd); + + rcqe = (struct io_uring_zcrx_cqe *)(cqe + 1); + + n = cqe->res; + mask = (1ULL << IORING_ZCRX_AREA_SHIFT) - 1; + data = (char *)area_ptr + (rcqe->off & mask); + + for (i = 0; i < n; i++) { + if (*(data + i) != payload[(received + i)]) + error(1, 0, "payload mismatch"); + } + received += n; + + rqe = &rq_ring.rqes[(rq_ring.rq_tail & rq_mask)]; + rqe->off = (rcqe->off & IORING_ZCRX_AREA_MASK) | area_token; + rqe->len = cqe->res; + io_uring_smp_store_release(rq_ring.ktail, ++rq_ring.rq_tail); +} + +static void server_loop(struct io_uring *ring) +{ + struct io_uring_cqe *cqe; + unsigned int count = 0; + unsigned int head; + int i, ret; + + io_uring_submit_and_wait(ring, 1); + + io_uring_for_each_cqe(ring, head, cqe) { + if (cqe->user_data == 1) + process_accept(ring, cqe); + else if (cqe->user_data == 2) + process_recvzc(ring, cqe); + else + error(1, 0, "unknown cqe"); + count++; + } + io_uring_cq_advance(ring, count); +} + +static void run_server(void) +{ + unsigned int flags = 0; + struct io_uring ring; + int fd, enable, ret; + uint64_t tstop; + + fd = socket(cfg_family, SOCK_STREAM, 0); + if (fd == -1) + error(1, 0, "socket()"); + + enable = 1; + ret = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int)); + if (ret < 0) + error(1, 0, "setsockopt(SO_REUSEADDR)"); + + ret = bind(fd, (const struct sockaddr *)&cfg_addr, sizeof(cfg_addr)); + if (ret < 0) + error(1, 0, "bind()"); + + if (listen(fd, 1024) < 0) + error(1, 0, "listen()"); + + flags |= IORING_SETUP_COOP_TASKRUN; + flags |= IORING_SETUP_SINGLE_ISSUER; + flags |= IORING_SETUP_DEFER_TASKRUN; + flags |= IORING_SETUP_SUBMIT_ALL; + flags |= IORING_SETUP_CQE32; + + io_uring_queue_init(512, &ring, flags); + + setup_zcrx(&ring); + + add_accept(&ring, fd); + + tstop = gettimeofday_ms() + 5000; + while (!stop && gettimeofday_ms() < tstop) + server_loop(&ring); + + if (!stop) + error(1, 0, "test failed\n"); +} + +static void run_client(void) +{ + ssize_t to_send = SEND_SIZE; + ssize_t sent = 0; + ssize_t chunk, res; + int fd; + + fd = socket(cfg_family, SOCK_STREAM, 0); + if (fd == -1) + error(1, 0, "socket()"); + + if (connect(fd, (void *)&cfg_addr, cfg_alen)) + error(1, 0, "connect()"); + + while (to_send) { + void *src = &payload[sent]; + + chunk = min_t(ssize_t, cfg_payload_len, to_send); + res = send(fd, src, chunk, 0); + if (res < 0) + error(1, 0, "send(): %d", sent); + sent += res; + to_send -= res; + } + + close(fd); +} + +static void usage(const char *filepath) +{ + error(1, 0, "Usage: %s (-4|-6) (-s|-c) -h -p " + "-l -i -q", filepath); +} + +static void parse_opts(int argc, char **argv) +{ + const int max_payload_len = sizeof(payload) - + sizeof(struct ipv6hdr) - + sizeof(struct tcphdr) - + 40 /* max tcp options */; + struct sockaddr_in6 *addr6 = (void *) &cfg_addr; + struct sockaddr_in *addr4 = (void *) &cfg_addr; + char *addr = NULL; + int c; + + if (argc <= 1) + usage(argv[0]); + cfg_payload_len = max_payload_len; + + while ((c = getopt(argc, argv, "46sch:p:l:i:q:")) != -1) { + switch (c) { + case '4': + if (cfg_family != PF_UNSPEC) + error(1, 0, "Pass one of -4 or -6"); + cfg_family = PF_INET; + cfg_alen = sizeof(struct sockaddr_in); + break; + case '6': + if (cfg_family != PF_UNSPEC) + error(1, 0, "Pass one of -4 or -6"); + cfg_family = PF_INET6; + cfg_alen = sizeof(struct sockaddr_in6); + break; + case 's': + if (cfg_client) + error(1, 0, "Pass one of -s or -c"); + cfg_server = 1; + break; + case 'c': + if (cfg_server) + error(1, 0, "Pass one of -s or -c"); + cfg_client = 1; + break; + case 'h': + addr = optarg; + break; + case 'p': + cfg_port = strtoul(optarg, NULL, 0); + break; + case 'l': + cfg_payload_len = strtoul(optarg, NULL, 0); + break; + case 'i': + cfg_ifname = optarg; + break; + case 'q': + cfg_queue_id = strtoul(optarg, NULL, 0); + break; + } + } + + if (cfg_server && addr) + error(1, 0, "Receiver cannot have -h specified"); + + switch (cfg_family) { + case PF_INET: + memset(addr4, 0, sizeof(*addr4)); + addr4->sin_family = AF_INET; + addr4->sin_port = htons(cfg_port); + addr4->sin_addr.s_addr = htonl(INADDR_ANY); + + if (addr && + inet_pton(AF_INET, addr, &(addr4->sin_addr)) != 1) + error(1, 0, "ipv4 parse error: %s", addr); + break; + case PF_INET6: + memset(addr6, 0, sizeof(*addr6)); + addr6->sin6_family = AF_INET6; + addr6->sin6_port = htons(cfg_port); + addr6->sin6_addr = in6addr_any; + + if (addr && + inet_pton(AF_INET6, addr, &(addr6->sin6_addr)) != 1) + error(1, 0, "ipv6 parse error: %s", addr); + break; + default: + error(1, 0, "illegal domain"); + } + + if (cfg_payload_len > max_payload_len) + error(1, 0, "-l: payload exceeds max (%d)", max_payload_len); +} + +int main(int argc, char **argv) +{ + const char *cfg_test = argv[argc - 1]; + int i; + + parse_opts(argc, argv); + + for (i = 0; i < SEND_SIZE; i++) + payload[i] = 'a' + (i % 26); + + if (cfg_server) + run_server(); + else if (cfg_client) + run_client(); + + return 0; +} diff --git a/tools/testing/selftests/drivers/net/hw/iou-zcrx.py b/tools/testing/selftests/drivers/net/hw/iou-zcrx.py new file mode 100755 index 000000000000..3998d0ad504f --- /dev/null +++ b/tools/testing/selftests/drivers/net/hw/iou-zcrx.py @@ -0,0 +1,64 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 + +from os import path +from lib.py import ksft_run, ksft_exit +from lib.py import NetDrvEpEnv +from lib.py import bkg, cmd, wait_port_listen + + +def _get_rx_ring_entries(cfg): + eth_cmd = "ethtool -g {} | awk '/RX:/ {{count++}} count == 2 {{print $2; exit}}'" + res = cmd(eth_cmd.format(cfg.ifname), host=cfg.remote) + return int(res.stdout) + + +def _get_combined_channels(cfg): + eth_cmd = "ethtool -l {} | awk '/Combined:/ {{count++}} count == 2 {{print $2; exit}}'" + res = cmd(eth_cmd.format(cfg.ifname), host=cfg.remote) + return int(res.stdout) + + +def _set_flow_rule(cfg, chan): + eth_cmd = "ethtool -N {} flow-type tcp6 dst-port 9999 action {} | awk '{{print $NF}}'" + res = cmd(eth_cmd.format(cfg.ifname, chan), host=cfg.remote) + return int(res.stdout) + + +def test_zcrx(cfg) -> None: + cfg.require_v6() + cfg.require_cmd("awk", remote=True) + + combined_chans = _get_combined_channels(cfg) + if combined_chans < 2: + raise KsftSkipEx('at least 2 combined channels required') + rx_ring = _get_rx_ring_entries(cfg) + + rx_cmd = f"{cfg.bin_remote} -6 -s -p 9999 -i {cfg.ifname} -q {combined_chans - 1}" + tx_cmd = f"{cfg.bin_local} -6 -c -h {cfg.remote_v6} -p 9999 -l 12840" + + try: + cmd(f"ethtool -G {cfg.ifname} rx 64", host=cfg.remote) + cmd(f"ethtool -X {cfg.ifname} equal {combined_chans - 1}", host=cfg.remote) + flow_rule_id = _set_flow_rule(cfg, combined_chans - 1) + + with bkg(rx_cmd, host=cfg.remote, exit_wait=True): + wait_port_listen(9999, proto="tcp", host=cfg.remote) + cmd(tx_cmd) + finally: + cmd(f"ethtool -N {cfg.ifname} delete {flow_rule_id}", host=cfg.remote) + cmd(f"ethtool -X {cfg.ifname} default", host=cfg.remote) + cmd(f"ethtool -G {cfg.ifname} rx {rx_ring}", host=cfg.remote) + + +def main() -> None: + with NetDrvEpEnv(__file__) as cfg: + cfg.bin_local = path.abspath(path.dirname(__file__) + "/../../../drivers/net/hw/iou-zcrx") + cfg.bin_remote = cfg.remote.deploy(cfg.bin_local) + + ksft_run(globs=globals(), case_pfx={"test_"}, args=(cfg, )) + ksft_exit() + + +if __name__ == "__main__": + main()