From nobody Sun Feb 8 04:34:45 2026 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 85A9916C850 for ; Sat, 8 Feb 2025 04:14:32 +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=1738988074; cv=none; b=DlTNC8rf9JbzL7TDXOqAYuePRpL4viK9m92xrAyaiz0lUkK0SOPFNsoS0qFsX7i54L9vo6g/v3/OEkLbs/8IqhGZarZ021FsTC90VclJgLDXiPbaFFEk7bRYsazm8bfxsb6bIxYl4O99ntKyNIsHwfxsJTduW2QejObmu4tjfdg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738988074; c=relaxed/simple; bh=fgaREE9e6jz5S5ZRiFkiZ2u/DNlIlA4sG+vDOPb2x/w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZLGuyIvJunIYEKk2X/SzAguQiEtz3Z3ZnjevKqrQZjLA4uxXe22cQgA08MvMJzf+Ob8eivyG4E8jdE3g0ztjL9jutfQnsMkPz6rMP6NBP+zOVIf3lqWuY5sh73CgvMBvs1rS3Mlncp5/ES5a/lDDujvSULFF5vlrTfxSiCDWrNE= 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=FA1apH12; 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="FA1apH12" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-21f5660c2fdso24451085ad.2 for ; Fri, 07 Feb 2025 20:14:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastly.com; s=google; t=1738988072; x=1739592872; 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=FA1apH12R37ESE1KN4zVVlpFFt82VLgU7O/JZqnzAet/W+UmpDj2MZ3aEYtaNYaf1h euPLeo0uoXbubqP4IYbSauBCz1r90fQIFDlDre7Ul/7gG90pD6C+uRTtGJFdb1/zsINk M8hPVxquLjUEsWk3FRQZ/rA0aaiR/RCgIBCiI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738988072; x=1739592872; 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=daIEOEf94FoEVKKIk010KToj4lZo0wEyy+tvK6Eq2PumzrdD3x7HSHrdmJurvYu7D4 58LNVKHtLF1UvnuSkDv6Kq5Kmv+FJNPPajITrchMaGbFRnJZuQ6zwzSRu79DfOG7geg0 HNiSsdWabifiZyRjBtnCRZV7YxDoDBnv5HaNwHonXChL7TJF3W/qftSVfq17QuOa0RqS wiJEe+7BTq/65Ycy8kOjsAhP2AQUBZBXCe8yRm8No3gx9u0TbiB8rSdtFCym0Ds5ZYEV iQ71y6kLZaM28PN+xjpk28eoXnJXUFsxu/ZsGmkw0TN5vQjLLs+Natw/lorLltf0YA0l WTgA== X-Forwarded-Encrypted: i=1; AJvYcCVrXmy0GMWcJKcMmQiQ5xZm0fDyYwRx0DQtmtvkR5WHLO8ZeuRRt4Wk7lQ3MA/oUcEY5+uCayM6OwBLU9o=@vger.kernel.org X-Gm-Message-State: AOJu0Yy7jSHiuQiCrF092BPAkzO0jFeV3IqveB5NbywUOolDhEtzo4Mt BRfRSor5ileye7Xi5dp47tEQQqNISGa4KAdB/0Qkerp/C2UWFheiIsQNHi1pUVk= X-Gm-Gg: ASbGncvOKTBrKt8AweRjoe5DfEUsbeHgosD/2K6fttO6LWE9xrnHGv6jylp1Lq7B64M C3EkjPeSq3kPGwJ4FXQsfYfOhje40aOmQYvuP7Yfs0JtVP3pgIC+5bMDqwpQiVTj9he9TlPsGE+ xpk+oN3zh3R1cB0xLQnfR5DIodyNP2DcoqEyhGg0ktBRF/EanrZutdQu7vMbxwhssPJlWjKH2l7 gzEaVGrztgrFaJNRTNZDONz5BbMObP/Gntf0yAf9Fru2+2WCdyZjw2FbyOZ9inK1RPup3FCrsOF xcZFIsgp7meivENjK487Ah0= X-Google-Smtp-Source: AGHT+IFibipGLR5Jyf9zTmTf+G8WqPE/WDRNuZpNVsIuJ6CUOWboJI4UQgEjzXJ5C+bf4G/4+P5jHw== X-Received: by 2002:a17:902:e88e:b0:21f:55e:ed71 with SMTP id d9443c01a7336-21f4e6a0100mr87242125ad.5.1738988071853; Fri, 07 Feb 2025 20:14:31 -0800 (PST) Received: from localhost.localdomain ([2620:11a:c019:0:65e:3115:2f58:c5fd]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21f3650ce0bsm38567715ad.21.2025.02.07.20.14.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Feb 2025 20:14:31 -0800 (PST) From: Joe Damato To: netdev@vger.kernel.org Cc: 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 v5 1/3] netlink: Add nla_put_empty_nest helper Date: Sat, 8 Feb 2025 04:12:23 +0000 Message-ID: <20250208041248.111118-2-jdamato@fastly.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250208041248.111118-1-jdamato@fastly.com> References: <20250208041248.111118-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 Sun Feb 8 04:34:45 2026 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 1C2DC189F45 for ; Sat, 8 Feb 2025 04:14:38 +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=1738988080; cv=none; b=odAr0LzFvLFWoZAAza/4mRNHuAhOhwxxKiYwli0A+H09LCaDvh5c0owSjmzkU3sbsfjm7X932XCrGCeS11qyJaW4dm3SWS7rSCoqCDv3Xsn/dkviwZ4AMy8GAxAOKDXfP257GlQJ5TdxPx7xe2/mP+uOuf/TFs4A9LKqaCOjCzE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738988080; c=relaxed/simple; bh=qMU/SSD+GnDstgplnPhUezCKkpRh9MkYWQpob4UhFaw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=emkaS7Q+fLnm7YvkIGEVUV6ErCKi+ex62QQe3Pt7gHvtDj6QQ1+QL0M233N+4tjqNJL3MUgUpkUE9K5LIm91k2EPNIhlF22e6MVD9k66F4AHry9JNeY/w3AMW/rWVKApoxkvCwt/mV67E3ihgDuIrtNKSEsYX68O1f+fNzCmdrY= 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=pxdGGLII; arc=none smtp.client-ip=209.85.214.181 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="pxdGGLII" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-21f6d2642faso4400695ad.1 for ; Fri, 07 Feb 2025 20:14:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastly.com; s=google; t=1738988078; x=1739592878; 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=P4DJzSaiR41L4hlteYq1D8hTA0O9UNuuENwILLXuiso=; b=pxdGGLII/xKi1lFhN8O+lLmzjTr0dbr6fo3JQmUS+Gyf95jSWX0BBxxGAVL9qODOef ykMxu4tUqeNjmLkOlhabSvKziab5u7ybG/cFoGa5RmozYQDhjnEjTM2P7Dn0bBZJ+0gf BLt89WSVTPMAEsEVitDUwPopWuipnUiQovh3s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738988078; x=1739592878; 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=P4DJzSaiR41L4hlteYq1D8hTA0O9UNuuENwILLXuiso=; b=NUDCR1McZb2MOU+avqRnBF6h/SC31m4JD5Xqbu4k4FN9yNVaEH1FtVC7M5N8J/pQtA U4TJXRBAChJ25bK/74E+g6uPPTxtgAINba8iFtmnsk42X4Cz1Km0cuuaSAQwDFsizh+v zQF967RBMntFu1ivyM6GE4irs8BWH40GyRWNWeSN20a2QDl1HncbWF2IfViftQKtdi8R 5hwNL2gxB+ivovknziutOr3AJ5SKb51dnrd5Y1yBV3tQvVcI2C6Ap7oEpQlOW8iNEAUZ aLgDikeQ3WmUA/72crJKBJV5SVcbLFeuEA76GGZIMxh6i1aYfpk6czsmwLU/5N9eq5/P gBYw== X-Forwarded-Encrypted: i=1; AJvYcCVYv6WW6M5ZqjaHYOvzOw3OuJYwX8YruOGVVemdTkzD1ijSm32bfJm+/HW9OMipDNw0it9tvAqzIu1SoqQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yzu5dWYGMw/Xlu3tstwZr0C2/VUN+lU6pM1LV33OZKUqajrT+xX w9VSZkv2+RL6ht6bXqt3xepPxV4OEIePpHDH9tQklAxS7PAtLSDME194Rs3O6dE= X-Gm-Gg: ASbGncubeDnRkc7BKNXLUfO/ETHN6Jb9JNS7Eyb2muvx8WT/ndYwpkFHmCRj7zj0/Z7 NNX9gXKVR0Y6nahJGMg2a8umuZttedF7g2KsEGe+kFaEyWdBCMwnfjijTBSkhRal8UbHJ1u70oZ TOYJ4V5W5TrX5uBHUwcf64nVKLoD3BRk8danPNboxDZg8obflH2Au3IhwTSBRPnqkBLvhxgeaHQ BtGJuPXbDc0ArNYO4vBTocV+dRTJcLdEKud3JOCC4pTU+9QIjBXQTEFpOu5FkhtyAUtsdMIdvJR KKpztshbenWpsLHsBjF6GJQ= X-Google-Smtp-Source: AGHT+IFZ59NGSqTUMa/FLxvgaYbBKt8+YckD6RRdPZKX9/d1HXQ/rQ9E90HNh7Azr36Zxf8jvckMTA== X-Received: by 2002:a17:903:1c4:b0:216:4169:f9d7 with SMTP id d9443c01a7336-21f4e6a00f4mr104632155ad.2.1738988078328; Fri, 07 Feb 2025 20:14:38 -0800 (PST) Received: from localhost.localdomain ([2620:11a:c019:0:65e:3115:2f58:c5fd]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21f3650ce0bsm38567715ad.21.2025.02.07.20.14.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Feb 2025 20:14:37 -0800 (PST) From: Joe Damato To: netdev@vger.kernel.org Cc: horms@kernel.org, kuba@kernel.org, Joe Damato , "David S. Miller" , Eric Dumazet , Paolo Abeni , Donald Hunter , Andrew Lunn , Xuan Zhuo , Stanislav Fomichev , Mina Almasry , Martin Karsten , Sridhar Samudrala , David Wei , linux-kernel@vger.kernel.org (open list) Subject: [PATCH net-next v5 2/3] netdev-genl: Add an XSK attribute to queues Date: Sat, 8 Feb 2025 04:12:24 +0000 Message-ID: <20250208041248.111118-3-jdamato@fastly.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250208041248.111118-1-jdamato@fastly.com> References: <20250208041248.111118-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 --- 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 | 11 +++++++++++ tools/include/uapi/linux/netdev.h | 6 ++++++ 4 files changed, 35 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 0dcd4faefd8d..b5a93a449af9 100644 --- a/net/core/netdev-genl.c +++ b/net/core/netdev-genl.c @@ -400,11 +400,22 @@ 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; + + if (rxq->pool) + if (nla_put_empty_nest(rsp, NETDEV_A_QUEUE_XSK)) + goto nla_put_failure; + 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; + + if (txq->pool) + if (nla_put_empty_nest(rsp, NETDEV_A_QUEUE_XSK)) + goto nla_put_failure; + + 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 Sun Feb 8 04:34:45 2026 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 A0C7818FC65 for ; Sat, 8 Feb 2025 04:14:42 +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=1738988084; cv=none; b=li6bXKcoYblix7EA3V0S8FOXyk7qVOAeNvRe2JUMEM30Qfu88/ZmXOBtMaeWxBEZcqNNJEaFCwifxmCabx1W5O9ONDQAmAD/64cQd2Uu3wU+hoasz4gHsa6p1sTMeDIxslFAVHdT1gQQeQ7h1dp5yeYqDatTIQ4kK8Dhjyg6FQo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738988084; c=relaxed/simple; bh=TmFrieKafs0y9qgWW4DLzVPuAlNlJxW158B1qIqoulU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bIPRdTfybDZp8JoCDyESqLl4btnsp3Z9VmilzPc7WT1VaHWwCNxdnhtETBdadbUnCbhEbAhSgrRybwzZeNYYTEcAhJT7h9bVKBC0QXYI7lmyq2VvT5trEEl62H0g1QQe0qRupICXMvke5WRsT+SoTRSw9RyXy4B+XLUW481qGas= 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=vXTumveD; arc=none smtp.client-ip=209.85.214.177 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="vXTumveD" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-21f6f18b474so1386125ad.1 for ; Fri, 07 Feb 2025 20:14:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastly.com; s=google; t=1738988082; x=1739592882; 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=r7RUZIqHwLPt1JPkc0hYqOZYvl0G8thAspfJu2yEGWI=; b=vXTumveDPV5D/h+W7pYAN4DirQaTAJqKXexuJu0+2+bNKw52aeL5aPrZSHgHnVaBBa n1XPnJNl1/jDz7gkji+zYZA08NA6k8vBVs+fJY/+0Us2fjF5b1NDRE49lhI/saHxzl/0 6cix2VhcDW6fY2mfFaTQEMxDt/ATstN3EJIYo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738988082; x=1739592882; 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=r7RUZIqHwLPt1JPkc0hYqOZYvl0G8thAspfJu2yEGWI=; b=UFANhtgCuPhYwDVjdxA9sDVNFswCNMkC5q7q2tKBFs0yUBSOAWebA9OO+6Y0mo0jOu WwMbSojs7Krq0cpnEcC4vugynTeqr9um2BNzADVF9l+5ki5nPyv6XhB+FcoeltOdX1Nv Eq07Ip838RhEi7n5vskiqISmLSSXyZGpFQXeOp60hflS3YoHDZd8L3iXyoiyId4qTC4K siR0bMKxgKM/0cp1oXlXuwPQRoXmAwHOMG57bYYcAvqmXnO/25v4c9QuYd1O8MjUmzgS vbE/X7Rs5IQs+u8FxmgxABlsDG4lO1wis12RwgMsapIWdXkX0xfGLT0aKdbaDKN2utH9 kWhA== X-Forwarded-Encrypted: i=1; AJvYcCVRXfRSrNqjgDHBndZTQscFHz0OpJI+AHW5bTXWLIYpuOSVws6hECEoCMFdknm+ZNgwydMAXrOUXZHjyxM=@vger.kernel.org X-Gm-Message-State: AOJu0YxkqUS/0sgSYQ90gybKC9sw7Rm28RD4gLOpzhv2wyMQVRXtPbX1 UEYcjvMSOd5H+OXSnv8PH8PhXIgZ+iAysmRwJwh+wcpUlJzaCEHgJ2kRCu8DTG4= X-Gm-Gg: ASbGncsWnPmGygQGlZs2Xs5UBKK14VjMQGJrv0f2pcN3EnXCOwI+SG21Unh+ZvER66U 3nMYkPdjIMwhFvvzfyKbYSDbSAF5joawXxVapOWqpeUsqFpEMOv09SptmqpqCOA71Gdx+leQYe6 G5k/2mty8+nx2XjRFOJ+3I65L8+4GtQ5T6CjxwwwOXqSIrGm/3M5NqJAXsx7UxhW1FaGIYhTzy7 gSkHTtiau15IXpC3WaguJ0vTjJ9EyPxBAuMgK0NWGGSTvIYjalyCB4OBToqwdcU1Kz8gAinEIAq o1wB4uoLDfP+wcNKspaCzJo= X-Google-Smtp-Source: AGHT+IEv7CcUWtUY/vHth+Pzo08OssxlhLb3z6WAsk4ULdVgEgbzIik2NIG6kbk+BkSy6XxFiRHClA== X-Received: by 2002:a17:903:186:b0:21f:75f:295 with SMTP id d9443c01a7336-21f4e716a17mr85874165ad.31.1738988081807; Fri, 07 Feb 2025 20:14:41 -0800 (PST) Received: from localhost.localdomain ([2620:11a:c019:0:65e:3115:2f58:c5fd]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21f3650ce0bsm38567715ad.21.2025.02.07.20.14.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Feb 2025 20:14:41 -0800 (PST) From: Joe Damato To: netdev@vger.kernel.org Cc: 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 v5 3/3] selftests: drv-net: Test queue xsk attribute Date: Sat, 8 Feb 2025 04:12:25 +0000 Message-ID: <20250208041248.111118-4-jdamato@fastly.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250208041248.111118-1-jdamato@fastly.com> References: <20250208041248.111118-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. Signed-off-by: Joe Damato Suggested-by: Jakub Kicinski --- 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/queues.py | 35 +++++++- .../selftests/drivers/net/xdp_helper.c | 89 +++++++++++++++++++ 4 files changed, 127 insertions(+), 2 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 c7f1c443f2af..81961c6e059d 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_PROGS :=3D xdp_helper + TEST_PROGS :=3D \ netcons_basic.sh \ netcons_fragmented_msg.sh \ diff --git a/tools/testing/selftests/drivers/net/queues.py b/tools/testing/= selftests/drivers/net/queues.py index 38303da957ee..55c2b296ad3c 100755 --- a/tools/testing/selftests/drivers/net/queues.py +++ b/tools/testing/selftests/drivers/net/queues.py @@ -8,7 +8,10 @@ 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,34 @@ 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 + + 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 +112,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..b04d4e0ea30a --- /dev/null +++ b/tools/testing/selftests/drivers/net/xdp_helper.c @@ -0,0 +1,89 @@ +// SPDX-License-Identifier: GPL-2.0 +#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"); + 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) + 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) { + 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