From patchwork Thu Feb 13 19:23:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Damato X-Patchwork-Id: 13973951 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 60F6324A056 for ; Thu, 13 Feb 2025 19:23:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739474629; cv=none; b=MK9MBDIO8pNXrd8hBc7fupvx29xgc/f/L2vhIxaImhc1Zf+jRM4flJmWEvs6yePtiX11RV+RC5HvKAydEleWPA5WuOzy80qkJcvI3CoCdT1woOFxHyYmu52Zzr/Dl2G1eB/95QnRWYo3eYHQGYd+D8snPNGeLq0dP3lNsR7o0vE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739474629; c=relaxed/simple; bh=O19yHCpkqJTXpsHZkKuIx0bHDAhaiab89LoRBXElqsY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Pf1J/zClI0sYjLddjcymSXAaYSjI4IbPkQlqjK79sO1vewMb0mS3p2fRVM+8lUXDqncCWo5NzsN8L5vhj52A9eVIfXYJMfWEGARnwXa/ih+OlR8lWdYbMH0S8q0ROJhKznlmkP9u/SUlY1xK87iv/RHrmkw0cRc9w6ArnL5aH7c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fastly.com; spf=pass smtp.mailfrom=fastly.com; dkim=pass (1024-bit key) header.d=fastly.com header.i=@fastly.com header.b=k8JUe/Xh; arc=none smtp.client-ip=209.85.214.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fastly.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fastly.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=fastly.com header.i=@fastly.com header.b="k8JUe/Xh" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-21f6d2642faso32621525ad.1 for ; Thu, 13 Feb 2025 11:23:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastly.com; s=google; t=1739474627; x=1740079427; 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=icDgF0dhXJ+X9NyKJop8wxjdfDNUacr6ErfUqD8p/9E=; b=k8JUe/XhdiQz15gtIIzsurszeZsdaHQhCPns5OybRpK9ZmL3HLIDEHmyTIxS0oOG2g 8YB9s2ehxkJ9Nq0kq1v2TdNtMj/SrmuCzDfOyDMkLPFWnMHfZexY+BsS3UQ8jj+3m9e7 Vk3iQzDJ5LpuH+enTI9wCYkZ5mp0Xq5vCbzKQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739474627; x=1740079427; 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=icDgF0dhXJ+X9NyKJop8wxjdfDNUacr6ErfUqD8p/9E=; b=Y5XD3RaBY2Mt8yrHXyXWiDN8WuerZwvCwnrJBkexaUC3aXhiDLBRO7rU920qml4Kxi SolWVapxC5269YbeLUn1nwd80H4tejRiAwUpVUA1QtDeZ0Sgui3YoKuo+vtVyQ3A3FPw 7uuWiYrWSKzrBq0XL4dHCdXceg27Yzs6Szlhq5/xNtUrJHLlL+Y+T/RwVbZLGYGoIrHD rC/NFpVI5QM0ejjWv8rh1zhZqoxvzXOQndQ6hZQxxxAAMfQPXrS2lxhHPnj6Rx0nu5MK Zi8ZhHxWTlU1ft85hhsj/91kPsB/GHqLr4pZgOC0d3NLFpOQqoqLrD1OMIRTURQe3Ax8 4V+Q== X-Gm-Message-State: AOJu0YzYDWJi800GQ2UnggsoiKLmm03BT5nXF0v1v69g/oVQkO1NieDG fucoYAv2LdfTRS517MyO7OaQKlMQtfuM3el+6sR53bR6Lpvj+meWIMFlyysp1oUk1CyG3f6xtiH NeBWq8AK5hyZejJeqg/oB5rHc+ZpcmMNOS5zmfIv8Gtl7Yo559g72ipKuP/1s3ZHHyOUB4IQ5OX NF4lmz7Dme3ifx+ULeb4v67CBYThk9DIZj78ZJXQ== X-Gm-Gg: ASbGncvieVUzozESCJj+dx/uzF+NTbzy4BE7haE9xi3Xdignq+0wazAajBNDgSmMu0e JgvzpBu5ZtZjcpoT3TmHNxrM549SNWMdEZDbs7UAZ79Vkx4uiuzUS7hTe2X0fihEytdeBr9Vo75 O7R+d7/FOtNdioPUXeRz9wSV1l0XhdeZyo9vKJnLMEtaBQo3H/+IE3KA16qhHhlSucvXIt3rjvD 0K9qN5haRX0eRG2km0/esEieOVQBYPS5j35+GZA+X/Lzgl9p+B4u6RMAqht95zGRHA3Exg9mXp7 it7g4wo5dB8pCcC9KmritiU= X-Google-Smtp-Source: AGHT+IGWSm8u83uqTS8PspXgmBAMPe2ctcctOKcrElV+Kvu4yuGLuATPkegQA2jTuHjMlGiwUOVI3w== X-Received: by 2002:a05:6a00:3e0b:b0:730:9946:5972 with SMTP id d2e1a72fcca58-7322c374050mr12054627b3a.1.1739474627147; Thu, 13 Feb 2025 11:23:47 -0800 (PST) Received: from localhost.localdomain ([2620:11a:c019:0:65e:3115:2f58:c5fd]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-73242568a9esm1633458b3a.45.2025.02.13.11.23.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Feb 2025 11:23:45 -0800 (PST) From: Joe Damato To: netdev@vger.kernel.org Cc: stfomichev@gmail.com, horms@kernel.org, kuba@kernel.org, Joe Damato , "David S. Miller" , Eric Dumazet , Paolo Abeni , linux-kernel@vger.kernel.org (open list) Subject: [PATCH net-next RESEND v7 1/3] netlink: Add nla_put_empty_nest helper Date: Thu, 13 Feb 2025 19:23:11 +0000 Message-ID: <20250213192336.42156-2-jdamato@fastly.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250213192336.42156-1-jdamato@fastly.com> References: <20250213192336.42156-1-jdamato@fastly.com> 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 Creating empty nests is helpful when the exact attributes to be exposed in the future are not known. Encapsulate the logic in a helper. Signed-off-by: Joe Damato Suggested-by: Jakub Kicinski --- include/net/netlink.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/include/net/netlink.h b/include/net/netlink.h index e015ffbed819..29e0db940382 100644 --- a/include/net/netlink.h +++ b/include/net/netlink.h @@ -118,6 +118,7 @@ * nla_nest_start(skb, type) start a nested attribute * nla_nest_end(skb, nla) finalize a nested attribute * nla_nest_cancel(skb, nla) cancel nested attribute construction + * nla_put_empty_nest(skb, type) create an empty nest * * Attribute Length Calculations: * nla_attr_size(payload) length of attribute w/o padding @@ -2240,6 +2241,20 @@ static inline void nla_nest_cancel(struct sk_buff *skb, struct nlattr *start) nlmsg_trim(skb, start); } +/** + * nla_put_empty_nest - Create an empty nest + * @skb: socket buffer the message is stored in + * @attrtype: attribute type of the container + * + * This function is a helper for creating empty nests. + * + * Returns: 0 when successful or -EMSGSIZE on failure. + */ +static inline int nla_put_empty_nest(struct sk_buff *skb, int attrtype) +{ + return nla_nest_start(skb, attrtype) ? 0 : -EMSGSIZE; +} + /** * __nla_validate_nested - Validate a stream of nested attributes * @start: container attribute From patchwork Thu Feb 13 19:23:12 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Damato X-Patchwork-Id: 13973952 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (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 F349E245B0C for ; Thu, 13 Feb 2025 19:23:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739474637; cv=none; b=bPJuGXyrAX4t8JsEHAOQRb6olSgjGj5YfBjbqEv17U0Rr461V38xi1q2mkBC/U2ELkxCaFwPD+rlDw6Be/BeVbtGc+dZ4pNMlXxVa1NXlkk+q2+3IyAa2whhpvHH6AMKxn84AwgyqnQdnGwra7dWm327Oh68ifvKuWaSuc3+dbU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739474637; c=relaxed/simple; bh=JmmEchmG/T2KTFE40ANXceRTnPYqC6cBJs+eCktZTEc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BjjoQImboQ95PLFW/fK8GD9VDkCghwSMcBHZ2iGJdHk34DMnZve4JPgNrwMWNlaRx1oU1NifE61Znmm0YSQfyWSCnrjzywbishdiZYF0O5qTpCvZvPu2p5jT+L+xaAu48oXJN3vURemfgEtfnmdTd8/x5irPGOzcEFkBn8w8O8E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fastly.com; spf=pass smtp.mailfrom=fastly.com; dkim=pass (1024-bit key) header.d=fastly.com header.i=@fastly.com header.b=hla3EaoG; arc=none smtp.client-ip=209.85.214.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fastly.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fastly.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=fastly.com header.i=@fastly.com header.b="hla3EaoG" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-21f92258aa6so32957395ad.3 for ; Thu, 13 Feb 2025 11:23:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastly.com; s=google; t=1739474635; x=1740079435; 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=JFmTLGonL9CPxuqbAvj4+M2PsmUtQYzlnrZXTFj7G1o=; b=hla3EaoGeiuwikkVALHwiCnDgXvcJhH3hZ8OPOQ1d5zmcm7oARpxdzPEvfL1VtsvLT 73MWEg/TpcvWp2yhm4qIIOpTvYtgx55sHfmlxfGPjkfwH939RKa1st7qkR8g1ZDuQK/7 HIJtOxGgPU90VEiYkrH0EniZa+nVBzF6eNVrU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739474635; x=1740079435; 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=JFmTLGonL9CPxuqbAvj4+M2PsmUtQYzlnrZXTFj7G1o=; b=R6lh+Q3MEh0e20HM52OcocPAeZbPW+vt478ydl49NCFKaC0bRVXp1QTkGc4ApcgZk9 iNhq8ZmdMzKBFIgNgtMyLvXVTMpchymdXt38smwZaKssIRxwOTLNkhMO0FxRgZMqAql/ yhNftuePmIdC6p0Ij4xpfTSdywFG62pSekSWJGAcrfqDwscjxmCum4DOsx4egQ6ZyrLr gfXDIF8wWNpEUUj6D7HvV81eFRUTfXazBh99r3TX+jDKSUN9E1zIFH++LWNRR3s3YP8m aK2OPffXNOZrbxJCjIA/OQlnDD4tH2xEWmIArm955/UL0/6iUGzqMUiHhjrznOYOrXGY K9zg== X-Gm-Message-State: AOJu0YzBCbHLBQAcjIG4vVlOzulF+vgM/DhIoMLPycuF1cTngY8xUe5j hLPa+RVxTRJlwrk0zEbV/rtl3aX1ayI5CvkDvvCaUV+Wxr5eOuB0+WcGn2bW8ROV2yt4mcUA+5K OBgajunM5gxFcB1kLl3jKXJ8SFnNM5Ayj7pgoXCCdGIsdCe+0zQIAL1whadfuHHLHANEkLlT5kr P/DCggS1TurLBJp5quTNMqHncPeTbDMjXOIVzutg== X-Gm-Gg: ASbGncuoLJvHHJ3vStT7D5vNdnioD6u7xGxgyLgtGPirBSiyVMVqmh9GwU/VPTxuJDL 4tYlU9QNnGNYrT5M8C7HsY4EepHjlEgJPCvnwVAgQOkt1gSKpHucudLNRk8gNNU1FJHXr7BJhxo ueSRprD258c3fDVGesx7qSItNwr07t6rX4MHPRv5LL3BErnfKI1qMdOCi7r3w1dD6nUMTPYLYBY V9cC6hjnRqRIbDOqXzJs/ufi1VSbUMWy3rCdBuRAoZbVtLwJQxzMr8XE0q/cydOLSVnYFwOeq7d zKYit0SSXKUwxt3JJtZKMxU= X-Google-Smtp-Source: AGHT+IFMQ8my9cYQBxHI0GOl+/Lvp33Cz51AIR5j+cNuRCPKxqLDZLIFO+x8S8OnRWe8Ul/XBnnUvA== X-Received: by 2002:a05:6a20:3d88:b0:1ee:7c01:d16 with SMTP id adf61e73a8af0-1ee7c0112abmr2336436637.30.1739474634856; Thu, 13 Feb 2025 11:23:54 -0800 (PST) Received: from localhost.localdomain ([2620:11a:c019:0:65e:3115:2f58:c5fd]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-73242568a9esm1633458b3a.45.2025.02.13.11.23.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Feb 2025 11:23:54 -0800 (PST) From: Joe Damato To: netdev@vger.kernel.org Cc: stfomichev@gmail.com, horms@kernel.org, kuba@kernel.org, Joe Damato , Donald Hunter , "David S. Miller" , Eric Dumazet , Paolo Abeni , Andrew Lunn , Stanislav Fomichev , Xuan Zhuo , Mina Almasry , Daniel Jurgens , Martin Karsten , Sridhar Samudrala , David Wei , linux-kernel@vger.kernel.org (open list) Subject: [PATCH net-next RESEND v7 2/3] netdev-genl: Add an XSK attribute to queues Date: Thu, 13 Feb 2025 19:23:12 +0000 Message-ID: <20250213192336.42156-3-jdamato@fastly.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250213192336.42156-1-jdamato@fastly.com> References: <20250213192336.42156-1-jdamato@fastly.com> 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 Expose a new per-queue nest attribute, xsk, which will be present for queues that are being used for AF_XDP. If the queue is not being used for AF_XDP, the nest will not be present. In the future, this attribute can be extended to include more data about XSK as it is needed. Signed-off-by: Joe Damato Suggested-by: Jakub Kicinski --- Documentation/netlink/specs/netdev.yaml | 13 ++++++++++++- include/uapi/linux/netdev.h | 6 ++++++ net/core/netdev-genl.c | 12 ++++++++++++ tools/include/uapi/linux/netdev.h | 6 ++++++ 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/Documentation/netlink/specs/netdev.yaml b/Documentation/netlink/specs/netdev.yaml index 288923e965ae..85402a2e289c 100644 --- a/Documentation/netlink/specs/netdev.yaml +++ b/Documentation/netlink/specs/netdev.yaml @@ -276,6 +276,9 @@ attribute-sets: doc: The timeout, in nanoseconds, of how long to suspend irq processing, if event polling finds events type: uint + - + name: xsk-info + attributes: [] - name: queue attributes: @@ -294,6 +297,9 @@ attribute-sets: - name: type doc: Queue type as rx, tx. Each queue type defines a separate ID space. + XDP TX queues allocated in the kernel are not linked to NAPIs and + thus not listed. AF_XDP queues will have more information set in + the xsk attribute. type: u32 enum: queue-type - @@ -309,7 +315,11 @@ attribute-sets: doc: io_uring memory provider information. type: nest nested-attributes: io-uring-provider-info - + - + name: xsk + doc: XSK information for this queue, if any. + type: nest + nested-attributes: xsk-info - name: qstats doc: | @@ -652,6 +662,7 @@ operations: - ifindex - dmabuf - io-uring + - xsk dump: request: attributes: diff --git a/include/uapi/linux/netdev.h b/include/uapi/linux/netdev.h index 6c6ee183802d..4e82f3871473 100644 --- a/include/uapi/linux/netdev.h +++ b/include/uapi/linux/netdev.h @@ -136,6 +136,11 @@ enum { NETDEV_A_NAPI_MAX = (__NETDEV_A_NAPI_MAX - 1) }; +enum { + __NETDEV_A_XSK_INFO_MAX, + NETDEV_A_XSK_INFO_MAX = (__NETDEV_A_XSK_INFO_MAX - 1) +}; + enum { NETDEV_A_QUEUE_ID = 1, NETDEV_A_QUEUE_IFINDEX, @@ -143,6 +148,7 @@ enum { NETDEV_A_QUEUE_NAPI_ID, NETDEV_A_QUEUE_DMABUF, NETDEV_A_QUEUE_IO_URING, + NETDEV_A_QUEUE_XSK, __NETDEV_A_QUEUE_MAX, NETDEV_A_QUEUE_MAX = (__NETDEV_A_QUEUE_MAX - 1) diff --git a/net/core/netdev-genl.c b/net/core/netdev-genl.c index c18bb53d13fd..2a0b6a452356 100644 --- a/net/core/netdev-genl.c +++ b/net/core/netdev-genl.c @@ -400,11 +400,23 @@ netdev_nl_queue_fill_one(struct sk_buff *rsp, struct net_device *netdev, if (params->mp_ops && params->mp_ops->nl_fill(params->mp_priv, rsp, rxq)) goto nla_put_failure; +#ifdef CONFIG_XDP_SOCKETS + if (rxq->pool) + if (nla_put_empty_nest(rsp, NETDEV_A_QUEUE_XSK)) + goto nla_put_failure; +#endif + break; case NETDEV_QUEUE_TYPE_TX: txq = netdev_get_tx_queue(netdev, q_idx); if (nla_put_napi_id(rsp, txq->napi)) goto nla_put_failure; +#ifdef CONFIG_XDP_SOCKETS + if (txq->pool) + if (nla_put_empty_nest(rsp, NETDEV_A_QUEUE_XSK)) + goto nla_put_failure; +#endif + break; } genlmsg_end(rsp, hdr); diff --git a/tools/include/uapi/linux/netdev.h b/tools/include/uapi/linux/netdev.h index 6c6ee183802d..4e82f3871473 100644 --- a/tools/include/uapi/linux/netdev.h +++ b/tools/include/uapi/linux/netdev.h @@ -136,6 +136,11 @@ enum { NETDEV_A_NAPI_MAX = (__NETDEV_A_NAPI_MAX - 1) }; +enum { + __NETDEV_A_XSK_INFO_MAX, + NETDEV_A_XSK_INFO_MAX = (__NETDEV_A_XSK_INFO_MAX - 1) +}; + enum { NETDEV_A_QUEUE_ID = 1, NETDEV_A_QUEUE_IFINDEX, @@ -143,6 +148,7 @@ enum { NETDEV_A_QUEUE_NAPI_ID, NETDEV_A_QUEUE_DMABUF, NETDEV_A_QUEUE_IO_URING, + NETDEV_A_QUEUE_XSK, __NETDEV_A_QUEUE_MAX, NETDEV_A_QUEUE_MAX = (__NETDEV_A_QUEUE_MAX - 1) From patchwork Thu Feb 13 19:23:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Damato X-Patchwork-Id: 13973950 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (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 4D808266182 for ; Thu, 13 Feb 2025 19:23:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739474641; cv=none; b=CBfPUmbRiJoxvyUIOL0QwsMWUwi+mUTbL8p4GpeustaY9+hHsdu4cEK1epTenDE9d77YtHXFpVwiNDJwyBl6JZtNiF/BaKz/aKs9i36YrUiglCnPwtzfkE7kSSqapjN6KenpX4LS9TpO3y32BhmTVDsTbjfIkfqaTDj8AnYte4w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739474641; c=relaxed/simple; bh=CJWBPXmsxgPHyVpk2lWHbQwaPlDzlBXsV4FmAq+lo+c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iWCBSqqXYShNTxjJVPd5Sp/wXil1oaKgx3RsxIUXpVOFHPKtbiPbiiqGjCS36j89UFRhDl6dXKszlVX0T1IFlZ4f2t25LsLXG7XeZewJYP5ikuxTNW3hKcCcap78WepDJ60KtlSf1MfEWX+D2zDonndlYiPi7xmM0IIAZzcyxmk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fastly.com; spf=pass smtp.mailfrom=fastly.com; dkim=pass (1024-bit key) header.d=fastly.com header.i=@fastly.com header.b=nfGM5Xt6; arc=none smtp.client-ip=209.85.214.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fastly.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fastly.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=fastly.com header.i=@fastly.com header.b="nfGM5Xt6" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-21f6d2642faso32627235ad.1 for ; Thu, 13 Feb 2025 11:23:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastly.com; s=google; t=1739474638; x=1740079438; 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=cwadMtANA8OqSE9WI8RE1a22pM7OUgQJRvEwfN3e/Eo=; b=nfGM5Xt64V0IJ7PdjXLw60O4kBG7IfrFO4dNnZw0FTTGYk1Z4bul4zUp0NvDBLVm/A h5gn77/6flk+QNUUJ+7LU0DplXmtw1QtYj3ZuiFgiwQYzfGtABZ2t1+HC3pQcDoP5ne2 NhhAUv3Qzeqbs1fw/WMfInIAopZBgLHiu41So= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739474638; x=1740079438; 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=cwadMtANA8OqSE9WI8RE1a22pM7OUgQJRvEwfN3e/Eo=; b=uns4SlVw7ZelFUZEM1ZbAGT60zx5RfCyug8P9fbC/fKiR/Fb4Isqe/sP3Li+IqvBUa CT26V8YXcvJ4eZFC7AUL+UmCUoxbVjzmFnvayrhPjEZAi/Bu559tQBbDr1OBtPwppJM1 nAwsXDAYFdw5reJ/m2//bSRP6Yxn0NGTC0exsaOuKAzatXL6beobLHnWGttC5bGnFsYP Z9n50mp2A/AKEbNqxziOcTc5lgjEz2375KXYNl1HoN+UkOoKdwvWAyLzlCwb1Wny+5jr E7EPquvlSBPzWVUSmUxaTXGUT+hd2uoULCF2Mv7S+XB0P3T4fU/BAKSLdvo1O9kC0d6M Vjxg== X-Forwarded-Encrypted: i=1; AJvYcCV7URAXctTnZjsTJgwmedVDQwt8CAKrdKUosQ8F0dmxiexnTI/+fJhuOjt++bVRIdiTo0A=@vger.kernel.org X-Gm-Message-State: AOJu0YwL9Vwtjr31oSs1/qm3GhvtRDgTgqHOwjvKm389Q6B7ycT2OZGo rC4ivZiaZ0hkNUT2AhDE6X4TCiEibNV48NnroUlYQf9cPaEvA1mxrM2/+Bbvc7M= X-Gm-Gg: ASbGncvDm5LwwNGQEkTy+wT+S+cAFB1JZMisfGWNFKrEb5i6RWjxA0LrqGQDlbLTbMI Wsnn1f9PlL1ZlmeHyE7sArGi0imC+G1CE90jJXu3iMcOaDv70V3v4OZRtsKmjOIQYc91YjAuggT 0CtheAMrThsUHISra5r/7UMw/zijbJaAljkdxrMeTw49wVGhgtYX99VzrYb1/TOSyi2+Vd9KWDw c+KnsCcnhAMrILAucYl90JGtao+qBVFD0KL+0rxUH72ehOQNu5IaUl1VQERVIOxDVoRLOp6jenq mwH/AlwjnXVJXLd6nPeQUYU= X-Google-Smtp-Source: AGHT+IFB59MypCe1M67/gpnz3aEE1mKoo0YL/Ohl2o58HL0YFhqCLmbe4dCReCYupJtHWcKppaZayw== X-Received: by 2002:a05:6a00:2e84:b0:730:95a6:3761 with SMTP id d2e1a72fcca58-7322c373ebamr15784837b3a.3.1739474638497; Thu, 13 Feb 2025 11:23:58 -0800 (PST) Received: from localhost.localdomain ([2620:11a:c019:0:65e:3115:2f58:c5fd]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-73242568a9esm1633458b3a.45.2025.02.13.11.23.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Feb 2025 11:23:58 -0800 (PST) From: Joe Damato To: netdev@vger.kernel.org Cc: stfomichev@gmail.com, horms@kernel.org, kuba@kernel.org, Joe Damato , Andrew Lunn , "David S. Miller" , Eric Dumazet , Paolo Abeni , Shuah Khan , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , linux-kernel@vger.kernel.org (open list), linux-kselftest@vger.kernel.org (open list:KERNEL SELFTEST FRAMEWORK), bpf@vger.kernel.org (open list:XDP (eXpress Data Path):Keyword:(?:\b|_)xdp(?:\b|_)) Subject: [PATCH net-next RESEND v7 3/3] selftests: drv-net: Test queue xsk attribute Date: Thu, 13 Feb 2025 19:23:13 +0000 Message-ID: <20250213192336.42156-4-jdamato@fastly.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250213192336.42156-1-jdamato@fastly.com> References: <20250213192336.42156-1-jdamato@fastly.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Test that queues which are used for AF_XDP have the xsk nest attribute. The attribute is currently empty, but its existence means the AF_XDP is being used for the queue. Enable CONFIG_XDP_SOCKETS for selftests/drivers/net tests, as well. Signed-off-by: Joe Damato Suggested-by: Jakub Kicinski --- .../testing/selftests/drivers/net/.gitignore | 2 + tools/testing/selftests/drivers/net/Makefile | 3 + tools/testing/selftests/drivers/net/config | 1 + tools/testing/selftests/drivers/net/queues.py | 42 +++++++- .../selftests/drivers/net/xdp_helper.c | 98 +++++++++++++++++++ 5 files changed, 143 insertions(+), 3 deletions(-) create mode 100644 tools/testing/selftests/drivers/net/.gitignore create mode 100644 tools/testing/selftests/drivers/net/xdp_helper.c diff --git a/tools/testing/selftests/drivers/net/.gitignore b/tools/testing/selftests/drivers/net/.gitignore new file mode 100644 index 000000000000..ec746f374e85 --- /dev/null +++ b/tools/testing/selftests/drivers/net/.gitignore @@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0-only +xdp_helper diff --git a/tools/testing/selftests/drivers/net/Makefile b/tools/testing/selftests/drivers/net/Makefile index 28b6d47f812d..68127c449c24 100644 --- a/tools/testing/selftests/drivers/net/Makefile +++ b/tools/testing/selftests/drivers/net/Makefile @@ -1,10 +1,13 @@ # SPDX-License-Identifier: GPL-2.0 +CFLAGS += $(KHDR_INCLUDES) TEST_INCLUDES := $(wildcard lib/py/*.py) \ $(wildcard lib/sh/*.sh) \ ../../net/net_helper.sh \ ../../net/lib.sh \ +TEST_GEN_PROGS := xdp_helper + TEST_PROGS := \ netcons_basic.sh \ netcons_fragmented_msg.sh \ diff --git a/tools/testing/selftests/drivers/net/config b/tools/testing/selftests/drivers/net/config index a2d8af60876d..f27172ddee0a 100644 --- a/tools/testing/selftests/drivers/net/config +++ b/tools/testing/selftests/drivers/net/config @@ -4,3 +4,4 @@ CONFIG_CONFIGFS_FS=y CONFIG_NETCONSOLE=m CONFIG_NETCONSOLE_DYNAMIC=y CONFIG_NETCONSOLE_EXTENDED_LOG=y +CONFIG_XDP_SOCKETS=y diff --git a/tools/testing/selftests/drivers/net/queues.py b/tools/testing/selftests/drivers/net/queues.py index 38303da957ee..5fdfebc6415f 100755 --- a/tools/testing/selftests/drivers/net/queues.py +++ b/tools/testing/selftests/drivers/net/queues.py @@ -2,13 +2,16 @@ # SPDX-License-Identifier: GPL-2.0 from lib.py import ksft_disruptive, ksft_exit, ksft_run -from lib.py import ksft_eq, ksft_raises, KsftSkipEx +from lib.py import ksft_eq, ksft_raises, KsftSkipEx, KsftFailEx from lib.py import EthtoolFamily, NetdevFamily, NlError from lib.py import NetDrvEnv from lib.py import cmd, defer, ip import errno import glob - +import os +import socket +import struct +import subprocess def sys_get_queues(ifname, qtype='rx') -> int: folders = glob.glob(f'/sys/class/net/{ifname}/queues/{qtype}-*') @@ -21,6 +24,39 @@ def nl_get_queues(cfg, nl, qtype='rx'): return len([q for q in queues if q['type'] == qtype]) return None +def check_xdp(cfg, nl, xdp_queue_id=0) -> None: + test_dir = os.path.dirname(os.path.realpath(__file__)) + xdp = subprocess.Popen([f"{test_dir}/xdp_helper", f"{cfg.ifindex}", f"{xdp_queue_id}"], + stdin=subprocess.PIPE, stdout=subprocess.PIPE, bufsize=1, + text=True) + defer(xdp.kill) + + stdout, stderr = xdp.communicate(timeout=10) + rx = tx = False + + if xdp.returncode == 255: + raise KsftSkipEx('AF_XDP unsupported') + elif xdp.returncode > 0: + raise KsftFailEx('unable to create AF_XDP socket') + + queues = nl.queue_get({'ifindex': cfg.ifindex}, dump=True) + if not queues: + raise KsftSkipEx("Netlink reports no queues") + + for q in queues: + if q['id'] == 0: + if q['type'] == 'rx': + rx = True + if q['type'] == 'tx': + tx = True + + ksft_eq(q['xsk'], {}) + else: + if 'xsk' in q: + _fail("Check failed: xsk attribute set.") + + ksft_eq(rx, True) + ksft_eq(tx, True) def get_queues(cfg, nl) -> None: snl = NetdevFamily(recv_size=4096) @@ -81,7 +117,7 @@ def check_down(cfg, nl) -> None: def main() -> None: with NetDrvEnv(__file__, queue_count=100) as cfg: - ksft_run([get_queues, addremove_queues, check_down], args=(cfg, NetdevFamily())) + ksft_run([get_queues, addremove_queues, check_down, check_xdp], args=(cfg, NetdevFamily())) ksft_exit() diff --git a/tools/testing/selftests/drivers/net/xdp_helper.c b/tools/testing/selftests/drivers/net/xdp_helper.c new file mode 100644 index 000000000000..2a40cc35d800 --- /dev/null +++ b/tools/testing/selftests/drivers/net/xdp_helper.c @@ -0,0 +1,98 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define UMEM_SZ (1U << 16) +#define NUM_DESC (UMEM_SZ / 2048) + +/* this is a simple helper program that creates an XDP socket and does the + * minimum necessary to get bind() to succeed. + * + * this test program is not intended to actually process packets, but could be + * extended in the future if that is actually needed. + * + * it is used by queues.py to ensure the xsk netlinux attribute is set + * correctly. + */ +int main(int argc, char **argv) +{ + struct xdp_umem_reg umem_reg = { 0 }; + struct sockaddr_xdp sxdp = { 0 }; + int num_desc = NUM_DESC; + void *umem_area; + int ifindex; + int sock_fd; + int queue; + char byte; + + if (argc != 3) { + fprintf(stderr, "Usage: %s ifindex queue_id", argv[0]); + return 1; + } + + sock_fd = socket(AF_XDP, SOCK_RAW, 0); + if (sock_fd < 0) { + perror("socket creation failed"); + /* if the kernel doesnt support AF_XDP, let the test program + * know with -1. All other error paths return 1. + */ + if (errno == EAFNOSUPPORT) + return -1; + return 1; + } + + ifindex = atoi(argv[1]); + queue = atoi(argv[2]); + + umem_area = mmap(NULL, UMEM_SZ, PROT_READ | PROT_WRITE, MAP_PRIVATE | + MAP_ANONYMOUS, -1, 0); + if (umem_area == MAP_FAILED) { + perror("mmap failed"); + return 1; + } + + umem_reg.addr = (uintptr_t)umem_area; + umem_reg.len = UMEM_SZ; + umem_reg.chunk_size = 2048; + umem_reg.headroom = 0; + + setsockopt(sock_fd, SOL_XDP, XDP_UMEM_REG, &umem_reg, + sizeof(umem_reg)); + setsockopt(sock_fd, SOL_XDP, XDP_UMEM_FILL_RING, &num_desc, + sizeof(num_desc)); + setsockopt(sock_fd, SOL_XDP, XDP_UMEM_COMPLETION_RING, &num_desc, + sizeof(num_desc)); + setsockopt(sock_fd, SOL_XDP, XDP_RX_RING, &num_desc, sizeof(num_desc)); + + sxdp.sxdp_family = AF_XDP; + sxdp.sxdp_ifindex = ifindex; + sxdp.sxdp_queue_id = queue; + sxdp.sxdp_flags = 0; + + if (bind(sock_fd, (struct sockaddr *)&sxdp, sizeof(sxdp)) != 0) { + munmap(umem_area, UMEM_SZ); + perror("bind failed"); + close(sock_fd); + return 1; + } + + /* give the parent program some data when the socket is ready*/ + fprintf(stdout, "%d\n", sock_fd); + + /* parent program will write a byte to stdin when its ready for this + * helper to exit + */ + read(STDIN_FILENO, &byte, 1); + + close(sock_fd); + return 0; +}