From a0cd931bef3dc6ed8fdb2befb384a828bb8d66ef Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Wed, 5 Oct 2022 10:47:25 +0200 Subject: [PATCH] platform: set custom netlink buffer size when adding SR-IOV VFs When there are many VFs the default buffer size of 1 memory page is not enough. Each VF can take up to ~120 bytes and so when the page size is 4KiB at most ~34 VFs can be added. Specify the buffer size when allocating the message. (cherry picked from commit f7ac887502d06e430aceeb1ec0c2282b702b93de) --- src/libnm-platform/nm-linux-platform.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/libnm-platform/nm-linux-platform.c b/src/libnm-platform/nm-linux-platform.c index c36695816a..eb7c671b7a 100644 --- a/src/libnm-platform/nm-linux-platform.c +++ b/src/libnm-platform/nm-linux-platform.c @@ -8405,16 +8405,23 @@ link_set_sriov_vfs(NMPlatform *platform, int ifindex, const NMPlatformVF *const { nm_auto_nlmsg struct nl_msg *nlmsg = NULL; struct nlattr *list, *info, *vlan_list; - guint i; + guint i = 0; + guint num = 0; + size_t buflen = 0; - nlmsg = _nl_msg_new_link(RTM_NEWLINK, 0, ifindex, NULL); + while (vfs[num]) + num++; + + /* A single IFLA_VF_INFO shouldn't take more than 200 bytes. */ + buflen = (num + 1) * 200; + nlmsg = _nl_msg_new_link_full(RTM_NEWLINK, 0, ifindex, NULL, AF_UNSPEC, 0, 0, buflen); if (!nlmsg) g_return_val_if_reached(-NME_BUG); if (!(list = nla_nest_start(nlmsg, IFLA_VFINFO_LIST))) goto nla_put_failure; - for (i = 0; vfs[i]; i++) { + for (; vfs[i]; i++) { const NMPlatformVF *vf = vfs[i]; if (!(info = nla_nest_start(nlmsg, IFLA_VF_INFO))) @@ -8487,6 +8494,11 @@ link_set_sriov_vfs(NMPlatform *platform, int ifindex, const NMPlatformVF *const return (do_change_link(platform, CHANGE_LINK_TYPE_UNSPEC, ifindex, nlmsg, NULL) >= 0); nla_put_failure: + _LOGE("error building SR-IOV VFs netlink message: used %u/%zu bytes for %u/%u VFs", + nlmsg_hdr(nlmsg)->nlmsg_len, + buflen, + i, + num); g_return_val_if_reached(FALSE); }