From nobody Thu Dec 18 20:23:52 2025 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 D0D61245B1A for ; Thu, 13 Feb 2025 19:23:47 +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=1739474630; cv=none; b=SeNanEPcXjDkDvA9dgGCffW/4lWc1XTCiHo4mZkDuonhQALqHHvgRVS8M7BjV0rWG3LM5enK1z4ZBD5aPs1bRm1WBBRkTyhTeB4XDVxK5svHkbkXvO7V4wBES/Yqff+dkwVA4A8CrX/thoyz4E/KBNAfmpgm6G361ldnRP42P/4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739474630; c=relaxed/simple; bh=O19yHCpkqJTXpsHZkKuIx0bHDAhaiab89LoRBXElqsY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PLtz9ketuUXziLhy2wOj3IDhfENzTF0+W43BSR5PLUoqiRGdIrXMtC+isO+CSJqb2kMQoCBF6t2bCu5J3sMLURf2sVbhrwn879OhSlSdFfTqkX6sbQHSDYdR53fbq0sSFPsYc990rSXqDd/fo/3f+FYzCEZxek3BLgODInFHCVE= 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.179 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-f179.google.com with SMTP id d9443c01a7336-220bfdfb3f4so26056035ad.2 for ; Thu, 13 Feb 2025 11:23:47 -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=wCzDul6wy5XED63pN7wvHLCHIDT2mh86qvTk1HYGx5N4tndBDSLyOJBBZJlcAnMSS8 1P/P/8b6NhKTcgYZx74ZV2JKL6KDm/TIH/p87wj0tcHafyVkNmQDF42TR3+YVgVixVdF Uhys46llN+sOwJKEjx0SlVYbUZBfbHj/6KBnYUf7/3icOBAQy1o5f/ADNMdbOmYnYye3 Mzbgpg+hWIbla+9KQgHsGunIcC2rm1GbFTT57ABKfcZ1yAChZAEJZeC+cfxaUdMDYO3p u2TXP291qX0iYkqxxWtKVjHyzAnZQRpIywRieNsOAoXeIOSMjUvet2njsR4lOZtVxz3p giDw== X-Forwarded-Encrypted: i=1; AJvYcCWj3nbP0PT11cGXKqDpxSIlOW5SnHuKIR5Bve/QP2IEjvQLavidmzoFr0J/jQujuMqsnXV9nfAqCOqXxB8=@vger.kernel.org X-Gm-Message-State: AOJu0YzWSnvUsDkl07L/FF+ETAgS8efINeoFwenCl2V4YLGAr5m37bMW haUxoRN7f+JT2oadUKjx1CeASIrYdAKVrk02nsNoU3FjfNOA2HnTD4skGUmi0BI= X-Gm-Gg: ASbGncvobCq0ldB3dumF45O9TSkCXVyjdHUe30lqwU91vLvyxpnLdDJLCfcCiXGWrOc 6RFcTpqZczRvHv4/AeOJTcoQkZ2S8gTP5BxNRxIuQDt5Gt/X78SMECu/n7MQvO4IfSIDb3faPS/ b537A+BlJ73njRpXABBe5kUeVlOlaCWf14VQAWyEDEkYFeccD9OHpinzmcnfKyTwoGtpkAeT2hs 5AjUERg9plJ6wiqeyGuNtxVleqMQkSd7/mwhHDYmrDuydC4t7Pw6nI/qHdeYQp54CRPmFfUPGvj NMAoh0Sclz/7ch2Ql0bbNek= 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: 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 --- 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:23:52 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 911C9245B0A for ; Thu, 13 Feb 2025 19:23:55 +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=1739474637; cv=none; b=N3mSrH2sGdH0wq5Ge8OymYElwUCy50lcKyTXeb7bntCxB62UMqHpIpgdoWQGfKU+mwfWsVru4GGP70ePqwaCCbOinQjHOOxwXN7u55Ur2mHodCacxn1PSXQJoYlKOsCpUVi5H79uUHNClzwmq+H8jLsZ5SPQ/aejRCaLukv24n4= 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.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="hla3EaoG" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-21f6d2642faso32625375ad.1 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=KnER8wZ1HcpSH2WxBVRwRTV5dPRMtE9+IYIWk4kYosdHjUiEIELngaK5UwU+oW1LHH 8VqxuyesyTs+xLZHyAeJTZYSLMFyaHEQEk5vX3WkT4mms7l8ZAwxjWzTCFVjkUCQe7Nd j49sI37SKRKAyc2VpXN6GVZ6QmAWFL2kklo4TSLPpxq06pcPxiUEy9x0IkqrALRAQGsF XydZj/GBOgVIyGoY/grQ7ljRlFjUjndw8wfPUgyKeO9uMF65lNrLwj0Yj+XgdkzOA+OJ ootDJD3J3YAOgM1HhsIeZC9ruF+77ldS3Co+MdIoAF8K/uPhml/brEkyeUO/r7O4b5yb 98Uw== X-Forwarded-Encrypted: i=1; AJvYcCVua/vNTEiuVDrxWhDUZah10nvPh91IPVN2q7hSe29Y51+SDP38UEctOzIEaUSTLH0WbJyqpOKQx00hF+w=@vger.kernel.org X-Gm-Message-State: AOJu0YzLiIkeVfVVIBmy8kz1nre/JNVbm3uUOd7C2B8IjB5sjXNSH1hN IwnVblmpeWA0XRXNVZpZ7T1rKK2JmTBrpb0HC0Xmk08UW2U04EPBlbUesQ5Gh6A= X-Gm-Gg: ASbGncubJk99QBuD81rH5oCAL6QT6Iw4l0z6SL8w9yZOK51Y05h3YDsR8oygmyyrW8R sDsSRKKN6cS14e29UHG8m0zl3yXVP3unspdHf31s3uOtr/bDk1gFx3Mw6dDOpyy0NQUz801kXrc 5x1if+u3EBFGeoIYTCQne1PfOScDb/BOJHpSy1J9aUY8IF1ukYe1X8KsG2kH6aadxsa/3IwMe3x KFAPr6BgPcVRmtkC2hJtpaHGKqkz7SjebnRJIkroouRgzrNcovMyKuFL8u9HTmH/ZTYHYdoKVde DKE+q/eUHwVQuhGT0Z4pdPo= 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: 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 --- 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:23:52 2025 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 4E74A266184 for ; Thu, 13 Feb 2025 19:23:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739474641; cv=none; b=nyk/RPfFRjCqYMK9ved0IXhuVZmoNWnibOA5b52/DyTwx8epAZw1Ap8AKJo/hv4Ka5LGLlWzFTuL6DzdodPPc0UGamJMR4lK8jaXGmeeVAb1TdjCyA602UPTfNADvP6ONKdBFUKl03eVW5eMYhPnu/eaMkcy3yHjpkQjy+upuRk= 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.180 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-f180.google.com with SMTP id d9443c01a7336-21f92258aa6so32958925ad.3 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=NCscufP83LSbVkOSvjDixJBxF4VONMaHdRxsSYuG2or/gkRVOtx/uozYxDlO2h+mWY nFA+JHPOrZtqjb6vsZgPTqk/4c9I9pmze2cO1sNrWNuSUr5tGwNtShWeDbzxno0kpLRj dz974A92Okxn+fEj2lFqL43Zkiui9aUKO2ojLI3RBu9jqHZx2r4C015CdUSR4jC0LAII t2/hsq3yR5WbvE9D99aq5COIoNzDVP6oQqCK8bNfQL2SdjVD5v9xPn5z3CBNhZGBB9KP nTwn36olAQJnfkkm9TXfpEzd4mpRdmWw764d1NKxbZ0PstjlUmA0TQISrral8TYNT4Mm EAbw== X-Forwarded-Encrypted: i=1; AJvYcCXb2lkT/wf/anMmirLO4LyUG4Gw4xwcWj9PEF3u5HiTdQVjY1MF19p8zqfpzcoaKadlkWix5kLarTfx/vU=@vger.kernel.org X-Gm-Message-State: AOJu0YyzV0DHwfUspOTQ6/ZyxuQXrPSmtQlPd1WAHDkf/XAlk43BYs1j 4+89l20NXVKEaGUxvky/2oTIZPm2biLrJmcn3B7mvQEDqX8rMPeTddKm6kXNQHo= X-Gm-Gg: ASbGncuk9vkPYj7g8NN9Bau/m4xjAIGqoMV44DNurg405ZTued1gVMWGp9CFTQ6Hl40 s8sUH7Tg08iypOLHYS+SgLIcMUHLiQ7OnbA1UhlW9wldbWxKK3HDEjVGgwGjpOr2nFQ3C2PwL9j 7v+/7wPq3jgehCQr8uBRCGx/Vt4fI9mVbx2M28INZ6XGungR69svK86WpYMGJBr77/yoUsIks5/ bCncIgW+7vxxHCAbhUxtHD4p/H1122JaJOfa6UzYMJGacdBkk2RDca6lEXW6MeTl78HLsCkeooK 7vJWeMrfID0gicWebs1RxRY= 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: 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 --- .../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..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 +=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/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..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 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 doesnt 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