From nobody Thu Dec 18 20:24:03 2025 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 B66721DA31F for ; Fri, 14 Feb 2025 21:13:10 +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=1739567593; cv=none; b=UUnInq8H9BR51lM6m8WWkHKHbBehkdj6xDAdHwQXRtaocdPct0C+Q3854FM6YLnGO7DbD73PSJEzWIqHBKc3meAQHWmmJiYGvswM9egJvNui+URntd+fyQyGIyym31ln79i3STrpQG6etjeEMo3qcHMLZiybPE8Kd79FqmB2Ox4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739567593; c=relaxed/simple; bh=fgaREE9e6jz5S5ZRiFkiZ2u/DNlIlA4sG+vDOPb2x/w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PHnxZsfSQIWtsSFBr0tRCnIDNwlFld2q0JWu0RUGr1s5Qd/UR0oN3L88dYbmx8EhYFMBuwpkoZ/vlVs2fCMYqcKT23XboC9FUYVPDjrXe8vbeshHpuWO2SseMA4U0xUXm5XVeWZzSMVXYsLDDEGs6sIyuOqdqZqYdZmIHQkya/I= 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=LkNu7q6E; arc=none smtp.client-ip=209.85.214.182 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="LkNu7q6E" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-21f6d2642faso67860085ad.1 for ; Fri, 14 Feb 2025 13:13:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastly.com; s=google; t=1739567590; x=1740172390; 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=h50Y3zF4tCkc/2EOdw4zLXgmcTIrGB/eNO65/LtZobs=; b=LkNu7q6E66cr1tsNbLyRLwWYxV7/5nUoETzU/U9bqY2BqJ8gFMl7zKSImgeEpRlxNw 9AngJX2+nQmE+uxaIUxKMOZJn0KsURDC5QSeTcNrrtDozt8eBKFfhQx1ImNxSgRwJxGf ulsElxXqRVCOx86g6cshIESAXbP8W+mdINOSM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739567590; x=1740172390; 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=h50Y3zF4tCkc/2EOdw4zLXgmcTIrGB/eNO65/LtZobs=; b=TrvtLv98v1qoV0aOf6C/jzM6Zl4u3+kIhZi1lJVeD/hasPjrNYoVqHwRtvaNmi1nD7 piPqYp4VPqKEnrXVINj2/+/Bi+/xtHgIqDUWcJ0dLXsYlxfEBIAPaeSXdHqq7+i74hoV GlWjkaUp7TClb+JVtboTZ5KqoNSNiyk0jiutbak/SYuXQbJGMu12cW19WHR+0UB/E6WT WOUevJWZr6XPhXKM8NeXg1enaTovmtaigZrsP8+HV0HNglaimoW4pEVHdMlw2WrWxgt0 /dYyILzlc3FMi+bwJQPYCS84yRCvRfGmvNl8qZA6V4xe0EQ85QnRXlvveel1IzrjYjnN +qgQ== X-Forwarded-Encrypted: i=1; AJvYcCUdPR6UMwmD6YJ2As89+91NinoAs1dDJYXiAWTJpgRtDlxo83WE+iN0ENK4g3ySPOAC85tlSOgyZC7M5n0=@vger.kernel.org X-Gm-Message-State: AOJu0YzHSt7Fo3ZJ49AvjKxBnaydquRkmnkY+H+yMde3l3Lfad9vfT7Z nqx4YDG/jGznDxbUr1leuWkkN+vZqJODMBl3Npz3LXEusyfzWNDiChcDOZFUiJ8= X-Gm-Gg: ASbGnctvVyLI+g7EWMI5pM/JnSj+FIwCMNmpjo/ezaTFpwfMFGDGfMgGZofrfEUA7GH /FEzH+VCZJKs7RbnmZawNpb0sOlYaaSij4DiE+ULs+M61kr4EINMwpC5NDO/FuVykLjSCO910LR f3i9LQcNTZn4o0tkAFpZXA+XOcH80K5fSW13gxyk95RE5zRzbNlX8yeCPe8X/j9SQ2TGuRzPe62 g31hG+uA1PIJG9H88MEY2o1munvP4TEVHdLwJxnwPKr0fnMxRSXXtmR1hbGGb69SDXAIjw/CcMy WN1M4HTU8q+Wu0O2R1Ekc90= X-Google-Smtp-Source: AGHT+IHLzbQ5GQfrunSH/5MZfcXL0ig2ibFP6/HEsx6LkPpxC/41PemipAIBEq3dtSX+KfEf55fVPQ== X-Received: by 2002:a17:902:d542:b0:215:f1c2:fcc4 with SMTP id d9443c01a7336-221040bc31bmr12353955ad.41.1739567589935; Fri, 14 Feb 2025 13:13:09 -0800 (PST) Received: from localhost.localdomain ([2620:11a:c019:0:65e:3115:2f58:c5fd]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d55908a7sm33285265ad.240.2025.02.14.13.13.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Feb 2025 13:13:09 -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 v8 1/3] netlink: Add nla_put_empty_nest helper Date: Fri, 14 Feb 2025 21:12:29 +0000 Message-ID: <20250214211255.14194-2-jdamato@fastly.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250214211255.14194-1-jdamato@fastly.com> References: <20250214211255.14194-1-jdamato@fastly.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- v4: - new in v4 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 *s= kb, struct nlattr *start) nlmsg_trim(skb, start); } =20 +/** + * 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 --=20 2.43.0 From nobody Thu Dec 18 20:24:03 2025 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 32B181D9A79 for ; Fri, 14 Feb 2025 21:13:16 +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=1739567599; cv=none; b=HShqOkXTBPP1+gDD47blT8WnYmMM9zbT40Ah3AfkyXWIKrhgOZGHoz6IlRdp3whBTwFp2X2OBPq1wb4b7O3m0QOKF0p7cTi1a6Q7WLBqBXrcGkVUsiST5/NYPBVsbk558tHoIR+noIU9qgF55BJM4VosTjbPIYUp6lTsOYbhKXY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739567599; c=relaxed/simple; bh=mPuhF130ax/7GB13RCt7Li/n+rP3TtOcYvGXiH7f4No=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BvUNha2IeD6A5YYt636muFBrZ+nZFw7qZ8dTjeXaQq3taHw8vqR0x3JZVOSSl58qN/XwiA9SulpEOVNhj5aUC4lgtDWEKwqOyDxAm0Xc+3g5Crju/T+h6uIA4cDXVwsQSs7vuRONftpsndDwLkOQC8j+8qlyUZhj90hqpojWR20= 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=RSd7CIWH; arc=none smtp.client-ip=209.85.214.176 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="RSd7CIWH" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-22100006bc8so10530495ad.0 for ; Fri, 14 Feb 2025 13:13:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastly.com; s=google; t=1739567596; x=1740172396; 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=f/SwDJv69vExAVSJvdtCIxYScbgvivss7r+DNLYoyxA=; b=RSd7CIWHalzilPJwWPpOpTMGw9ix2wbm6X8vrf7kzD8S1tKly3hKS7ahkdaGUCC3Z8 tbftzr1NUG/1ZyAkgq0u/WR2wZMyv+fjK1uTubTeSWiNqZn/oFcNI7vM/Uhxyk4XJGOa dOIdzr/8J1kl7h3go7kWkJb8gn3WmDPimeE8Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739567596; x=1740172396; 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=f/SwDJv69vExAVSJvdtCIxYScbgvivss7r+DNLYoyxA=; b=Wrl0FBjMOJ28CPqieTblnk9IU0M55wns9Xp3uTW9Wgjcy9kDfIDJGK5igIfOF944ra L1QD5sIwh8ZdKPy4MC9lY0SERxIK86Wl6Tur6a4s2XODXZrX7w9k1Ex1NIM2jZseN2Pt FB00l+f8d0UW53Exf1toTkzfokUVdO13wlPoCySGVBpucy2KVOkj7n0vUpFxidK2gWd7 wxoM+DzZMrReoxgcbCFx/0rcMFoV9r51mks+lFSB9AaeJbt3uaDcFxCIpu+xUihrUucY 7O4bVSv7eiBcz8nKDl7VUeSg2JNVDacFKEsR+giRL3xCwOOBE8i3AU56V/0r+cBFAzkh +LfQ== X-Forwarded-Encrypted: i=1; AJvYcCULiUw/I3iQDUHzwBtrWGeU7+WIZdo3JWDSxtMyNmWH4WZFPZEPC9d0q+QzCvH5Ao68n08dxAZX8z3fbl8=@vger.kernel.org X-Gm-Message-State: AOJu0YzLej72nZI+/xABmaA2nE3BeH48MEs76oAzAwSYWgyj3YNCEJLH Mk6H7YnbCiJ2Thv92S/jfmpebHPTfdFAdumMa0N+Llv+QSdt6RDVxMCOfKP7fBc= X-Gm-Gg: ASbGncuSXe/RgndVL3GICjVixeZ6PLywsFZHIG26nuChj24ETgVXsyTZ5HFRuiNVNly jAvA1+EixfL7CWrB2LrewkOioJrzF+sb1grwMVH+HM8I70gJBe34v5A9yQYPcQrnGN7yFRUO+C4 eqTrjNjhAexhfZJxg2KkPIuhEsWF9lObcnAaFLovJ5+A6i3iGjpZ3vqvp6L/SzL63e086EGn6gf qlc3s1DiEW4FBCNVcgzVUJhABpCFZBYwtvG7puAySyv6IDgZbxZFzo5UzXqAMmGsC3tEe4qYZ+T UrBRnxmAUpwEo0SbEOjWyCs= X-Google-Smtp-Source: AGHT+IEW74IZ924sIDJL2hMkAeBC+xS5FAhDGZrCYUaEeaFkkBcD4GGittPhCyL0tVhl3nEXmJRZ6Q== X-Received: by 2002:a17:902:ef49:b0:216:6769:9ed7 with SMTP id d9443c01a7336-221040b131dmr13212605ad.40.1739567596408; Fri, 14 Feb 2025 13:13:16 -0800 (PST) Received: from localhost.localdomain ([2620:11a:c019:0:65e:3115:2f58:c5fd]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d55908a7sm33285265ad.240.2025.02.14.13.13.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Feb 2025 13:13:16 -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 , Donald Hunter , Andrew Lunn , Xuan Zhuo , Mina Almasry , David Wei , Martin Karsten , Amritha Nambiar , Stanislav Fomichev , linux-kernel@vger.kernel.org (open list) Subject: [PATCH net-next v8 2/3] netdev-genl: Add an XSK attribute to queues Date: Fri, 14 Feb 2025 21:12:30 +0000 Message-ID: <20250214211255.14194-3-jdamato@fastly.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250214211255.14194-1-jdamato@fastly.com> References: <20250214211255.14194-1-jdamato@fastly.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- v6: - Added ifdefs to netdev_nl_queue_fill_one for CONFIG_XDP_SOCKETS. v5: - Removed unused variable, ret, from netdev_nl_queue_fill_one. v4: - Updated netdev_nl_queue_fill_one to use the empty nest helper added in patch 1. v2: - Patch adjusted to include an attribute, xsk, which is an empty nest and exposed for queues which have a pool. 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/netlin= k/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 s= pace. + 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 =3D (__NETDEV_A_NAPI_MAX - 1) }; =20 +enum { + __NETDEV_A_XSK_INFO_MAX, + NETDEV_A_XSK_INFO_MAX =3D (__NETDEV_A_XSK_INFO_MAX - 1) +}; + enum { NETDEV_A_QUEUE_ID =3D 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, =20 __NETDEV_A_QUEUE_MAX, NETDEV_A_QUEUE_MAX =3D (__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 =3D 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; } =20 genlmsg_end(rsp, hdr); diff --git a/tools/include/uapi/linux/netdev.h b/tools/include/uapi/linux/n= etdev.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 =3D (__NETDEV_A_NAPI_MAX - 1) }; =20 +enum { + __NETDEV_A_XSK_INFO_MAX, + NETDEV_A_XSK_INFO_MAX =3D (__NETDEV_A_XSK_INFO_MAX - 1) +}; + enum { NETDEV_A_QUEUE_ID =3D 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, =20 __NETDEV_A_QUEUE_MAX, NETDEV_A_QUEUE_MAX =3D (__NETDEV_A_QUEUE_MAX - 1) --=20 2.43.0 From nobody Thu Dec 18 20:24:03 2025 Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) (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 E869D1DA617 for ; Fri, 14 Feb 2025 21:13:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739567602; cv=none; b=QAvIb0R8zsObAyh7gPl/0jP1uUAkjii4hlU9ARjF0ftmp2FCmWv9d+0XO7rJnptcLob2+mqbr4FqKCCx74YYASJyDryBzvbUMmwlixW7vq6EiUk6m7q95GD2AvuHp6N01GGpG1Ab/9nu5VMBF+kt+DsWd2zPxZA+dLOJ3CVb38c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739567602; c=relaxed/simple; bh=rlrXc4hroYFAQc+w/Ml5h4jot5Mubo3164+XNtZ2tik=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bY/Nq6owwN/6HorYIcZyqmxtG9P1LToQs3+91BHte3lVjZBY1TxuKxXqm/sHYLcqq1xyeog/tBLG64yqHOi1C4h9xu0xDXuTLskWy9ytarWxhyzDT5AqoaUnluYsXFM0CARwBnQeZ+AVtf7//sWBNhnx+jmrFi2rOMG9OfugV4o= 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=Ja0+x4ai; arc=none smtp.client-ip=209.85.216.43 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="Ja0+x4ai" Received: by mail-pj1-f43.google.com with SMTP id 98e67ed59e1d1-2f441791e40so3708372a91.3 for ; Fri, 14 Feb 2025 13:13:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastly.com; s=google; t=1739567600; x=1740172400; 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=dQVAlNj3QbWNBbK5rOU0fAHCX0qfBnwQBa4usEGobZQ=; b=Ja0+x4aisuqZX6j7K6q0RT6PIGWxYXy2CmHnhtzzzpw3Muex46I2n4e1oLXPvuXHZW 0Jjptcz42G/ONltGNOd7eDRIqb1hoy98vClaT6yMDQSCHMRMjT7AXOMQv86vN+cyXxqX Bk2Q4QGbGlw/fUM+VEwNj6NsP9xBzzR8EGDWg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739567600; x=1740172400; 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=dQVAlNj3QbWNBbK5rOU0fAHCX0qfBnwQBa4usEGobZQ=; b=N6OjqWfrVf5C4o8ARPnaHaM/JylCM++7I49g77l+zSFsI2ZLaI3j5xiEZw18KgHFh3 MPIJ7eLWp72cqvl6xnQ4gBWxSkO39+f8G9+qPus2JMjxxpUW8B+a+6eL7Q20uznhT9J6 5c4dhBoemIYBxkcV+pGy82ohGIIko1DVA3fgb6eoL5EYwnJcTzXOJUXD8OuIyrN7gGXD 2DfWj2zBbG5Ok2q2GLRn9WunigtgLJLd78cjfSj0QQr1NuCGX58tsg9uXfOzI6dqGgAH knlZi8GjTqsQwkwQ09nqwspdTD6LwE4ljlbs/LIsrh/emWd1lzIUvdC1sqmbjm/f0mDf M5fg== X-Forwarded-Encrypted: i=1; AJvYcCVCkQchz0ms568H55qo2BCvazbQEatQsqA4UiSS0IA/2f4YEiSyPlHUcFEyWgOvYcZDeL7GzmHjbEjyTsU=@vger.kernel.org X-Gm-Message-State: AOJu0Yz6Mjy52ol4DXha5THsEDLWsF7oe4BWSUUFhsCFzzGmUKt3TYJi OH6LqRP4MyNk7CmHgrnpnt2n5UddMuZuZ5T86lRC6ITikStL5KpxGf5jw2weiNE= X-Gm-Gg: ASbGncuWPAVgtxIBm1wjD0bAMf01ZeVXX48tGumTZRVor61C4fhTwcj/VnNTiTZUL0r Lm7d9oSpaA0y0hXxTIuJ3KEbCMYks9lD/FPbwALQUZ6TLRu0SUvSz7y0Yc/oXznkdYtXKbm8ddl /gcuVfGO9flo4midqCL565fWw/uFvp/5XXf6umoLkuL0pa55Z6DIFx0tseIXIBO+TDIApsw9ikK KW5sMfQ1oxPnKsTx6KM7ebihZjOoxdkup2vJZZf/rNnf4WXfnH5zZ2ZTal4SxHxU2bOraUjol0q KUCsxzUbqJDY8Mr1eUeDgaI= X-Google-Smtp-Source: AGHT+IG25rthdsrePVBbc4s0lfFZSqx3GHujdDrq1qGR930P5reQFwnTWK+/n+GUAgL9O+BCHUIXBg== X-Received: by 2002:a17:90b:1b0d:b0:2ee:c9b6:4c42 with SMTP id 98e67ed59e1d1-2fc40f22cbamr1022240a91.16.1739567600010; Fri, 14 Feb 2025 13:13:20 -0800 (PST) Received: from localhost.localdomain ([2620:11a:c019:0:65e:3115:2f58:c5fd]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d55908a7sm33285265ad.240.2025.02.14.13.13.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Feb 2025 13:13:19 -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 v8 3/3] selftests: drv-net: Test queue xsk attribute Date: Fri, 14 Feb 2025 21:12:31 +0000 Message-ID: <20250214211255.14194-4-jdamato@fastly.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250214211255.14194-1-jdamato@fastly.com> References: <20250214211255.14194-1-jdamato@fastly.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- v8: - Switch from TEST_GET_PROGS to TEST_GEN_FILES in the Makefile. - Fix codespell spelling issue in xdp_helper.c v7: - Added CONFIG_XDP_SOCKETS=3Dy to selftests/drivers/net/config. - Updated xdp_helper to return -1 on AF_XDP non-existence, 1 for other failures. - Updated queues.py to skip if AF_XDP does not not exist, fail otherwise. v3: - Change comment style of helper C program to avoid kdoc warnings as suggested by Jakub. No other changes. v2: - Updated the Python test after changes to patch 1 which expose an empty nest - Updated Python test with general Python coding feedback .../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/s= elftests/drivers/net/Makefile index 28b6d47f812d..0c95bd944d56 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 +=3D $(KHDR_INCLUDES) =20 TEST_INCLUDES :=3D $(wildcard lib/py/*.py) \ $(wildcard lib/sh/*.sh) \ ../../net/net_helper.sh \ ../../net/lib.sh \ =20 +TEST_GEN_FILES :=3D xdp_helper + TEST_PROGS :=3D \ netcons_basic.sh \ netcons_fragmented_msg.sh \ diff --git a/tools/testing/selftests/drivers/net/config b/tools/testing/sel= ftests/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=3Dy CONFIG_NETCONSOLE=3Dm CONFIG_NETCONSOLE_DYNAMIC=3Dy CONFIG_NETCONSOLE_EXTENDED_LOG=3Dy +CONFIG_XDP_SOCKETS=3Dy 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 =20 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 =20 def sys_get_queues(ifname, qtype=3D'rx') -> int: folders =3D glob.glob(f'/sys/class/net/{ifname}/queues/{qtype}-*') @@ -21,6 +24,39 @@ def nl_get_queues(cfg, nl, qtype=3D'rx'): return len([q for q in queues if q['type'] =3D=3D qtype]) return None =20 +def check_xdp(cfg, nl, xdp_queue_id=3D0) -> None: + test_dir =3D os.path.dirname(os.path.realpath(__file__)) + xdp =3D subprocess.Popen([f"{test_dir}/xdp_helper", f"{cfg.ifindex}", = f"{xdp_queue_id}"], + stdin=3Dsubprocess.PIPE, stdout=3Dsubprocess.PI= PE, bufsize=3D1, + text=3DTrue) + defer(xdp.kill) + + stdout, stderr =3D xdp.communicate(timeout=3D10) + rx =3D tx =3D False + + if xdp.returncode =3D=3D 255: + raise KsftSkipEx('AF_XDP unsupported') + elif xdp.returncode > 0: + raise KsftFailEx('unable to create AF_XDP socket') + + queues =3D nl.queue_get({'ifindex': cfg.ifindex}, dump=3DTrue) + if not queues: + raise KsftSkipEx("Netlink reports no queues") + + for q in queues: + if q['id'] =3D=3D 0: + if q['type'] =3D=3D 'rx': + rx =3D True + if q['type'] =3D=3D 'tx': + tx =3D True + + ksft_eq(q['xsk'], {}) + else: + if 'xsk' in q: + _fail("Check failed: xsk attribute set.") + + ksft_eq(rx, True) + ksft_eq(tx, True) =20 def get_queues(cfg, nl) -> None: snl =3D NetdevFamily(recv_size=3D4096) @@ -81,7 +117,7 @@ def check_down(cfg, nl) -> None: =20 def main() -> None: with NetDrvEnv(__file__, queue_count=3D100) as cfg: - ksft_run([get_queues, addremove_queues, check_down], args=3D(cfg, = NetdevFamily())) + ksft_run([get_queues, addremove_queues, check_down, check_xdp], ar= gs=3D(cfg, NetdevFamily())) ksft_exit() =20 =20 diff --git a/tools/testing/selftests/drivers/net/xdp_helper.c b/tools/testi= ng/selftests/drivers/net/xdp_helper.c new file mode 100644 index 000000000000..cf06a88b830b --- /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 coul= d 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 =3D { 0 }; + struct sockaddr_xdp sxdp =3D { 0 }; + int num_desc =3D NUM_DESC; + void *umem_area; + int ifindex; + int sock_fd; + int queue; + char byte; + + if (argc !=3D 3) { + fprintf(stderr, "Usage: %s ifindex queue_id", argv[0]); + return 1; + } + + sock_fd =3D socket(AF_XDP, SOCK_RAW, 0); + if (sock_fd < 0) { + perror("socket creation failed"); + /* if the kernel doesn't support AF_XDP, let the test program + * know with -1. All other error paths return 1. + */ + if (errno =3D=3D EAFNOSUPPORT) + return -1; + return 1; + } + + ifindex =3D atoi(argv[1]); + queue =3D atoi(argv[2]); + + umem_area =3D mmap(NULL, UMEM_SZ, PROT_READ | PROT_WRITE, MAP_PRIVATE | + MAP_ANONYMOUS, -1, 0); + if (umem_area =3D=3D MAP_FAILED) { + perror("mmap failed"); + return 1; + } + + umem_reg.addr =3D (uintptr_t)umem_area; + umem_reg.len =3D UMEM_SZ; + umem_reg.chunk_size =3D 2048; + umem_reg.headroom =3D 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 =3D AF_XDP; + sxdp.sxdp_ifindex =3D ifindex; + sxdp.sxdp_queue_id =3D queue; + sxdp.sxdp_flags =3D 0; + + if (bind(sock_fd, (struct sockaddr *)&sxdp, sizeof(sxdp)) !=3D 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; +} --=20 2.43.0