All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH iproute2-next 1/4] uapi: update kernel headers from upstream
@ 2021-01-23  4:53 Edwin Peer
  2021-01-23  4:53 ` [PATCH iproute2-next 2/4] lib: iplink: print warnings for missing data Edwin Peer
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Edwin Peer @ 2021-01-23  4:53 UTC (permalink / raw
  To: netdev
  Cc: Edwin Peer, Jakub Kicinski, Andrew Gospodarek, Michael Chan,
	Stephen Hemminger, Michal Kubecek, David Ahern

[-- Attachment #1: Type: text/plain, Size: 2009 bytes --]

This primarily pulls in the ABI changes needed to detect truncated
lists of netlink attributes as well as the bits necessary to elevate
IFLA_VF_INFO stats out of IFLA_VFINFO_LIST. Unrelated changes in the
affected files were also synced.

Signed-off-by: Edwin Peer <edwin.peer@broadcom.com>
---
 include/uapi/linux/if_link.h   | 2 ++
 include/uapi/linux/netlink.h   | 1 +
 include/uapi/linux/rtnetlink.h | 1 +
 3 files changed, 4 insertions(+)

diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h
index 97a95cf7e4f9..2889897bc2bb 100644
--- a/include/uapi/linux/if_link.h
+++ b/include/uapi/linux/if_link.h
@@ -341,6 +341,7 @@ enum {
 	IFLA_ALT_IFNAME, /* Alternative ifname */
 	IFLA_PERM_ADDRESS,
 	IFLA_PROTO_DOWN_REASON,
+	IFLA_VFSTATS_LIST,
 	__IFLA_MAX
 };
 
@@ -807,6 +808,7 @@ enum {
 	IFLA_GTP_FD1,
 	IFLA_GTP_PDP_HASHSIZE,
 	IFLA_GTP_ROLE,
+	IFLA_GTP_COLLECT_METADATA,
 	__IFLA_GTP_MAX,
 };
 #define IFLA_GTP_MAX (__IFLA_GTP_MAX - 1)
diff --git a/include/uapi/linux/netlink.h b/include/uapi/linux/netlink.h
index 5024c5435749..1cab84506eaf 100644
--- a/include/uapi/linux/netlink.h
+++ b/include/uapi/linux/netlink.h
@@ -57,6 +57,7 @@ struct nlmsghdr {
 #define NLM_F_ECHO		0x08	/* Echo this request 		*/
 #define NLM_F_DUMP_INTR		0x10	/* Dump was inconsistent due to sequence change */
 #define NLM_F_DUMP_FILTERED	0x20	/* Dump was filtered as requested */
+#define NLM_F_NEST_TRUNCATED	0x40	/* Message contains truncated nested attribute */
 
 /* Modifiers to GET request */
 #define NLM_F_ROOT	0x100	/* specify tree	root	*/
diff --git a/include/uapi/linux/rtnetlink.h b/include/uapi/linux/rtnetlink.h
index c66fd247d90a..b31afc8f70a4 100644
--- a/include/uapi/linux/rtnetlink.h
+++ b/include/uapi/linux/rtnetlink.h
@@ -787,6 +787,7 @@ enum {
 #define RTEXT_FILTER_MRP	(1 << 4)
 #define RTEXT_FILTER_CFM_CONFIG	(1 << 5)
 #define RTEXT_FILTER_CFM_STATUS	(1 << 6)
+#define RTEXT_FILTER_VF_SEPARATE_STATS (1 << 7)
 
 /* End of information exported to user level */
 
-- 
2.30.0


[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4160 bytes --]

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH iproute2-next 2/4] lib: iplink: print warnings for missing data
  2021-01-23  4:53 [PATCH iproute2-next 1/4] uapi: update kernel headers from upstream Edwin Peer
@ 2021-01-23  4:53 ` Edwin Peer
  2021-01-23  4:53 ` [PATCH iproute2-next 3/4] iplink: filter stats using RTEXT_FILTER_SKIP_STATS Edwin Peer
  2021-01-23  4:53 ` [PATCH iproute2-next 4/4] iplink: render IFLA_VF_STATS from IFLA_VFSTATS_LIST Edwin Peer
  2 siblings, 0 replies; 4+ messages in thread
From: Edwin Peer @ 2021-01-23  4:53 UTC (permalink / raw
  To: netdev
  Cc: Edwin Peer, Jakub Kicinski, Andrew Gospodarek, Michael Chan,
	Stephen Hemminger, Michal Kubecek, David Ahern

[-- Attachment #1: Type: text/plain, Size: 3227 bytes --]

The kernel might truncate VF info in IFLA_VFINFO_LIST. Sufficiently new
kernels will provide NLM_F_NEST_TRUNCATED in these cases, but this flag
has limited resolution, as it pertains to the entire netlink message. A
better approach is to compare the expected number of VFs in IFLA_NUM_VF
to how many were found in the list and warn accordingly.

Signed-off-by: Edwin Peer <edwin.peer@broadcom.com>
---
 ip/ipaddress.c   |  9 ++++++++-
 lib/libnetlink.c | 12 ++++++++++++
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/ip/ipaddress.c b/ip/ipaddress.c
index 571346b15cc3..0bbcee2b3bb2 100644
--- a/ip/ipaddress.c
+++ b/ip/ipaddress.c
@@ -922,6 +922,7 @@ int print_linkinfo(struct nlmsghdr *n, void *arg)
 	const char *name;
 	unsigned int m_flag = 0;
 	SPRINT_BUF(b1);
+	bool truncated_vfs = false;
 
 	if (n->nlmsg_type != RTM_NEWLINK && n->nlmsg_type != RTM_DELLINK)
 		return 0;
@@ -1199,15 +1200,18 @@ int print_linkinfo(struct nlmsghdr *n, void *arg)
 
 	if ((do_link || show_details) && tb[IFLA_VFINFO_LIST] && tb[IFLA_NUM_VF]) {
 		struct rtattr *i, *vflist = tb[IFLA_VFINFO_LIST];
-		int rem = RTA_PAYLOAD(vflist);
+		int rem = RTA_PAYLOAD(vflist), count = 0;
 
 		open_json_array(PRINT_JSON, "vfinfo_list");
 		for (i = RTA_DATA(vflist); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) {
 			open_json_object(NULL);
 			print_vfinfo(fp, ifi, i);
 			close_json_object();
+			count++;
 		}
 		close_json_array(PRINT_JSON, NULL);
+		if (count != rta_getattr_u32(tb[IFLA_NUM_VF]))
+			truncated_vfs = true;
 	}
 
 	if (tb[IFLA_PROP_LIST]) {
@@ -1228,6 +1232,9 @@ int print_linkinfo(struct nlmsghdr *n, void *arg)
 
 	print_string(PRINT_FP, NULL, "%s", "\n");
 	fflush(fp);
+	/* prettier here if stderr and stdout go to the same place */
+	if (truncated_vfs)
+		fprintf(stderr, "Truncated VF list: %s\n", name);
 	return 1;
 }
 
diff --git a/lib/libnetlink.c b/lib/libnetlink.c
index c958aa57d0cd..b1f07d4570cf 100644
--- a/lib/libnetlink.c
+++ b/lib/libnetlink.c
@@ -833,6 +833,9 @@ static int rtnl_dump_filter_l(struct rtnl_handle *rth,
 				if (h->nlmsg_flags & NLM_F_DUMP_INTR)
 					dump_intr = 1;
 
+				if (h->nlmsg_flags & NLM_F_NEST_TRUNCATED)
+					fprintf(stderr, "Incomplete data: truncated attribute list\n");
+
 				if (h->nlmsg_type == NLMSG_DONE) {
 					err = rtnl_dump_done(h);
 					if (err < 0) {
@@ -978,6 +981,9 @@ next:
 				continue;
 			}
 
+			if (h->nlmsg_flags & NLM_F_NEST_TRUNCATED)
+				fprintf(stderr, "Incomplete data: truncated attribute list\n");
+
 			if (h->nlmsg_type == NLMSG_ERROR) {
 				struct nlmsgerr *err = (struct nlmsgerr *)NLMSG_DATA(h);
 				int error = err->error;
@@ -1156,6 +1162,9 @@ int rtnl_listen(struct rtnl_handle *rtnl,
 				exit(1);
 			}
 
+			if (h->nlmsg_flags & NLM_F_NEST_TRUNCATED)
+				fprintf(stderr, "Incomplete data: truncated attribute list\n");
+
 			err = handler(&ctrl, h, jarg);
 			if (err < 0)
 				return err;
@@ -1206,6 +1215,9 @@ int rtnl_from_file(FILE *rtnl, rtnl_listen_filter_t handler,
 			return -1;
 		}
 
+		if (h->nlmsg_flags & NLM_F_NEST_TRUNCATED)
+			fprintf(stderr, "Incomplete data: truncated attribute list\n");
+
 		status = fread(NLMSG_DATA(h), 1, NLMSG_ALIGN(l), rtnl);
 
 		if (status != NLMSG_ALIGN(l)) {
-- 
2.30.0


[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4160 bytes --]

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH iproute2-next 3/4] iplink: filter stats using RTEXT_FILTER_SKIP_STATS
  2021-01-23  4:53 [PATCH iproute2-next 1/4] uapi: update kernel headers from upstream Edwin Peer
  2021-01-23  4:53 ` [PATCH iproute2-next 2/4] lib: iplink: print warnings for missing data Edwin Peer
@ 2021-01-23  4:53 ` Edwin Peer
  2021-01-23  4:53 ` [PATCH iproute2-next 4/4] iplink: render IFLA_VF_STATS from IFLA_VFSTATS_LIST Edwin Peer
  2 siblings, 0 replies; 4+ messages in thread
From: Edwin Peer @ 2021-01-23  4:53 UTC (permalink / raw
  To: netdev
  Cc: Edwin Peer, Jakub Kicinski, Andrew Gospodarek, Michael Chan,
	Stephen Hemminger, Michal Kubecek, David Ahern

[-- Attachment #1: Type: text/plain, Size: 1318 bytes --]

Don't request statistics we do not intend to render. This is a step
towards avoiding a truncated IFLA_VFINFO_LIST. It also avoids fetching
unnecessary data, reducing netlink traffic.

Signed-off-by: Edwin Peer <edwin.peer@broadcom.com>
---
 ip/ipaddress.c | 6 +++++-
 ip/iplink.c    | 3 +++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/ip/ipaddress.c b/ip/ipaddress.c
index 0bbcee2b3bb2..75511881050d 100644
--- a/ip/ipaddress.c
+++ b/ip/ipaddress.c
@@ -1882,9 +1882,13 @@ static int ipaddr_flush(void)
 
 static int iplink_filter_req(struct nlmsghdr *nlh, int reqlen)
 {
+	__u32 filt_mask;
 	int err;
 
-	err = addattr32(nlh, reqlen, IFLA_EXT_MASK, RTEXT_FILTER_VF);
+	filt_mask = RTEXT_FILTER_VF;
+	if (!show_stats)
+		filt_mask |= RTEXT_FILTER_SKIP_STATS;
+	err = addattr32(nlh, reqlen, IFLA_EXT_MASK, filt_mask);
 	if (err)
 		return err;
 
diff --git a/ip/iplink.c b/ip/iplink.c
index 27c9be442a7a..6a973213dc11 100644
--- a/ip/iplink.c
+++ b/ip/iplink.c
@@ -1116,6 +1116,9 @@ int iplink_get(char *name, __u32 filt_mask)
 			  !check_ifname(name) ? IFLA_IFNAME : IFLA_ALT_IFNAME,
 			  name, strlen(name) + 1);
 	}
+
+	if (!show_stats)
+		filt_mask |= RTEXT_FILTER_SKIP_STATS;
 	addattr32(&req.n, sizeof(req), IFLA_EXT_MASK, filt_mask);
 
 	if (rtnl_talk(&rth, &req.n, &answer) < 0)
-- 
2.30.0


[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4160 bytes --]

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH iproute2-next 4/4] iplink: render IFLA_VF_STATS from IFLA_VFSTATS_LIST
  2021-01-23  4:53 [PATCH iproute2-next 1/4] uapi: update kernel headers from upstream Edwin Peer
  2021-01-23  4:53 ` [PATCH iproute2-next 2/4] lib: iplink: print warnings for missing data Edwin Peer
  2021-01-23  4:53 ` [PATCH iproute2-next 3/4] iplink: filter stats using RTEXT_FILTER_SKIP_STATS Edwin Peer
@ 2021-01-23  4:53 ` Edwin Peer
  2 siblings, 0 replies; 4+ messages in thread
From: Edwin Peer @ 2021-01-23  4:53 UTC (permalink / raw
  To: netdev
  Cc: Edwin Peer, Jakub Kicinski, Andrew Gospodarek, Michael Chan,
	Stephen Hemminger, Michal Kubecek, David Ahern

[-- Attachment #1: Type: text/plain, Size: 3264 bytes --]

The maximum possible length of a netlink attribute is 64KB, but the
IFLA_VFINFO_LIST exceeds this when stats are included and more than
about 220 VFs are present (each VF consumes approximately 300 bytes,
depending on alignment and optional fields). Exceeding the limit will
cause the list to be truncated by the kernel's nla_nest_end().

A recent ABI fix moves the VF stats into an independent list when
requested, thus avoiding the problem. Send requests using the new
RTEXT_FILTER_VF_SEPARATE_STATS filter and render the stats from
the alternate list instead.

Signed-off-by: Edwin Peer <edwin.peer@broadcom.com>
---
 ip/ipaddress.c   | 14 +++++++++++---
 ip/iplink.c      |  1 +
 lib/libnetlink.c |  3 ++-
 3 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/ip/ipaddress.c b/ip/ipaddress.c
index 75511881050d..a048b3db601c 100644
--- a/ip/ipaddress.c
+++ b/ip/ipaddress.c
@@ -1200,12 +1200,20 @@ int print_linkinfo(struct nlmsghdr *n, void *arg)
 
 	if ((do_link || show_details) && tb[IFLA_VFINFO_LIST] && tb[IFLA_NUM_VF]) {
 		struct rtattr *i, *vflist = tb[IFLA_VFINFO_LIST];
-		int rem = RTA_PAYLOAD(vflist), count = 0;
+		struct rtattr *j, *vfstats = tb[IFLA_VFSTATS_LIST];
+		int rem_stats, rem = RTA_PAYLOAD(vflist), count = 0;
 
+		j = vfstats ? RTA_DATA(vfstats) : NULL;
+		rem_stats = vfstats ? RTA_PAYLOAD(vfstats) : 0;
 		open_json_array(PRINT_JSON, "vfinfo_list");
 		for (i = RTA_DATA(vflist); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) {
 			open_json_object(NULL);
 			print_vfinfo(fp, ifi, i);
+			if (show_stats && j) {
+				print_vf_stats64(fp, j);
+				j = RTA_OK(j, rem_stats) ?
+					RTA_NEXT(j, rem_stats) : NULL;
+			}
 			close_json_object();
 			count++;
 		}
@@ -1885,7 +1893,7 @@ static int iplink_filter_req(struct nlmsghdr *nlh, int reqlen)
 	__u32 filt_mask;
 	int err;
 
-	filt_mask = RTEXT_FILTER_VF;
+	filt_mask = RTEXT_FILTER_VF | RTEXT_FILTER_VF_SEPARATE_STATS;
 	if (!show_stats)
 		filt_mask |= RTEXT_FILTER_SKIP_STATS;
 	err = addattr32(nlh, reqlen, IFLA_EXT_MASK, filt_mask);
@@ -1923,7 +1931,7 @@ static int ipaddr_link_get(int index, struct nlmsg_chain *linfo)
 		.i.ifi_family = filter.family,
 		.i.ifi_index = index,
 	};
-	__u32 filt_mask = RTEXT_FILTER_VF;
+	__u32 filt_mask = RTEXT_FILTER_VF | RTEXT_FILTER_VF_SEPARATE_STATS;
 	struct nlmsghdr *answer;
 
 	if (!show_stats)
diff --git a/ip/iplink.c b/ip/iplink.c
index 6a973213dc11..3cce8aa2a0b7 100644
--- a/ip/iplink.c
+++ b/ip/iplink.c
@@ -1117,6 +1117,7 @@ int iplink_get(char *name, __u32 filt_mask)
 			  name, strlen(name) + 1);
 	}
 
+	filt_mask |= RTEXT_FILTER_VF_SEPARATE_STATS;
 	if (!show_stats)
 		filt_mask |= RTEXT_FILTER_SKIP_STATS;
 	addattr32(&req.n, sizeof(req), IFLA_EXT_MASK, filt_mask);
diff --git a/lib/libnetlink.c b/lib/libnetlink.c
index b1f07d4570cf..b4aa9d16b446 100644
--- a/lib/libnetlink.c
+++ b/lib/libnetlink.c
@@ -486,7 +486,8 @@ static int __rtnl_linkdump_req(struct rtnl_handle *rth, int family)
 int rtnl_linkdump_req(struct rtnl_handle *rth, int family)
 {
 	if (family == AF_UNSPEC)
-		return rtnl_linkdump_req_filter(rth, family, RTEXT_FILTER_VF);
+		return rtnl_linkdump_req_filter(rth, family, RTEXT_FILTER_VF |
+						RTEXT_FILTER_VF_SEPARATE_STATS);
 
 	return __rtnl_linkdump_req(rth, family);
 }
-- 
2.30.0


[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4160 bytes --]

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-01-23  4:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-01-23  4:53 [PATCH iproute2-next 1/4] uapi: update kernel headers from upstream Edwin Peer
2021-01-23  4:53 ` [PATCH iproute2-next 2/4] lib: iplink: print warnings for missing data Edwin Peer
2021-01-23  4:53 ` [PATCH iproute2-next 3/4] iplink: filter stats using RTEXT_FILTER_SKIP_STATS Edwin Peer
2021-01-23  4:53 ` [PATCH iproute2-next 4/4] iplink: render IFLA_VF_STATS from IFLA_VFSTATS_LIST Edwin Peer

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.