Skip to contentSkip to conversation

uapi: update kernel headers from upstream

PATCH New Edwin Peer 1 participant 4 messages Jan 23, 2021

Subsystems (3)
lore
Share & tools
lore

Edwin Peer

author
#0 lore raw

PATCH 1/4 uapi: update kernel headers from upstream

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.

---
 include/uapi/linux/if_link.h   | 2 ++
 include/uapi/linux/netlink.h   | 1 +
 include/uapi/linux/rtnetlink.h | 1 +
 3 files changed, 4 insertions(+)
include/uapi/linux/if_link.h +2 -0
index 97a95cf7e4f9..2889897bc2bb 100644
@@ -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)
include/uapi/linux/netlink.h +1 -0
index 5024c5435749..1cab84506eaf 100644
@@ -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	*/
include/uapi/linux/rtnetlink.h +1 -0
index c66fd247d90a..b31afc8f70a4 100644
@@ -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 */
 
Signature · 1 line
2.30.0
author
#1 lore raw

PATCH 2/4 lib: iplink: print warnings for missing data

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.

---
 ip/ipaddress.c   |  9 ++++++++-
 lib/libnetlink.c | 12 ++++++++++++
 2 files changed, 20 insertions(+), 1 deletion(-)
ip/ipaddress.c +8 -1
index 571346b15cc3..0bbcee2b3bb2 100644
@@ -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;
 }
 
lib/libnetlink.c +12 -0
index c958aa57d0cd..b1f07d4570cf 100644
@@ -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)) {
Signature · 1 line
2.30.0
author
#2 lore raw

PATCH 3/4 iplink: filter stats using RTEXT_FILTER_SKIP_STATS

In reply to Edwin Peer

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.

---
 ip/ipaddress.c | 6 +++++-
 ip/iplink.c    | 3 +++
 2 files changed, 8 insertions(+), 1 deletion(-)
ip/ipaddress.c +5 -1
index 0bbcee2b3bb2..75511881050d 100644
@@ -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;
 
ip/iplink.c +3 -0
index 27c9be442a7a..6a973213dc11 100644
@@ -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)
Signature · 1 line
2.30.0
author
#3 lore raw

PATCH 4/4 iplink: render IFLA_VF_STATS from IFLA_VFSTATS_LIST

In reply to Edwin Peer

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.

---
 ip/ipaddress.c   | 14 +++++++++++---
 ip/iplink.c      |  1 +
 lib/libnetlink.c |  3 ++-
 3 files changed, 14 insertions(+), 4 deletions(-)
ip/ipaddress.c +11 -3
index 75511881050d..a048b3db601c 100644
@@ -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)
ip/iplink.c +1 -0
index 6a973213dc11..3cce8aa2a0b7 100644
@@ -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);
lib/libnetlink.c +2 -1
index b1f07d4570cf..b4aa9d16b446 100644
@@ -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);
 }
Signature · 1 line
2.30.0