Skip to content

Commit bd29dfe

Browse files
committed
udev/net: also support [SR-IOV] section in .link files
The same section is already supported by .network files. But such low-level inteerface setting should be done by udevd, instead of networkd. Let's also support the same semantics by .link files. Prompted by systemd#20474 (comment).
1 parent b4fd34d commit bd29dfe

File tree

6 files changed

+174
-89
lines changed

6 files changed

+174
-89
lines changed

man/systemd.link.xml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,95 @@
949949
</variablelist>
950950
</refsect1>
951951

952+
<refsect1 id='sr-iov'>
953+
<title>[SR-IOV] Section Options</title>
954+
<para>The [SR-IOV] section accepts the following keys. Specify several [SR-IOV] sections to
955+
configure several SR-IOVs. SR-IOV provides the ability to partition a single physical PCI resource
956+
into virtual PCI functions which can then be injected into a VM. In the case of network VFs, SR-IOV
957+
improves north-south network performance (that is, traffic with endpoints outside the host machine)
958+
by allowing traffic to bypass the host machine’s network stack.</para>
959+
960+
<variablelist class='network-directives'>
961+
<varlistentry>
962+
<term><varname>VirtualFunction=</varname></term>
963+
<listitem>
964+
<para>Specifies a Virtual Function (VF), lightweight PCIe function designed solely to move
965+
data in and out. Takes an integer in the range 0…2147483646. This option is compulsory.
966+
</para>
967+
</listitem>
968+
</varlistentry>
969+
970+
<varlistentry>
971+
<term><varname>VLANId=</varname></term>
972+
<listitem>
973+
<para>Specifies VLAN ID of the virtual function. Takes an integer in the range 1…4095.</para>
974+
</listitem>
975+
</varlistentry>
976+
977+
<varlistentry>
978+
<term><varname>QualityOfService=</varname></term>
979+
<listitem>
980+
<para>Specifies quality of service of the virtual function. Takes an integer in the range
981+
1…4294967294.</para>
982+
</listitem>
983+
</varlistentry>
984+
985+
<varlistentry>
986+
<term><varname>VLANProtocol=</varname></term>
987+
<listitem>
988+
<para>Specifies VLAN protocol of the virtual function. Takes <literal>802.1Q</literal> or
989+
<literal>802.1ad</literal>.</para>
990+
</listitem>
991+
</varlistentry>
992+
993+
<varlistentry>
994+
<term><varname>MACSpoofCheck=</varname></term>
995+
<listitem>
996+
<para>Takes a boolean. Controls the MAC spoof checking. When unset, the kernel's default will
997+
be used.</para>
998+
</listitem>
999+
</varlistentry>
1000+
1001+
<varlistentry>
1002+
<term><varname>QueryReceiveSideScaling=</varname></term>
1003+
<listitem>
1004+
<para>Takes a boolean. Toggle the ability of querying the receive side scaling (RSS)
1005+
configuration of the virtual function (VF). The VF RSS information like RSS hash key may be
1006+
considered sensitive on some devices where this information is shared between VF and the
1007+
physical function (PF). When unset, the kernel's default will be used.</para>
1008+
</listitem>
1009+
</varlistentry>
1010+
1011+
<varlistentry>
1012+
<term><varname>Trust=</varname></term>
1013+
<listitem>
1014+
<para>Takes a boolean. Allows one to set trust mode of the virtual function (VF). When set,
1015+
VF users can set a specific feature which may impact security and/or performance. When unset,
1016+
the kernel's default will be used.</para>
1017+
</listitem>
1018+
</varlistentry>
1019+
1020+
<varlistentry>
1021+
<term><varname>LinkState=</varname></term>
1022+
<listitem>
1023+
<para>Allows one to set the link state of the virtual function (VF). Takes a boolean or a
1024+
special value <literal>auto</literal>. Setting to <literal>auto</literal> means a
1025+
reflection of the physical function (PF) link state, <literal>yes</literal> lets the VF to
1026+
communicate with other VFs on this host even if the PF link state is down,
1027+
<literal>no</literal> causes the hardware to drop any packets sent by the VF. When unset,
1028+
the kernel's default will be used.</para>
1029+
</listitem>
1030+
</varlistentry>
1031+
1032+
<varlistentry>
1033+
<term><varname>MACAddress=</varname></term>
1034+
<listitem>
1035+
<para>Specifies the MAC address for the virtual function.</para>
1036+
</listitem>
1037+
</varlistentry>
1038+
</variablelist>
1039+
</refsect1>
1040+
9521041
<refsect1>
9531042
<title>Examples</title>
9541043

man/systemd.network.xml

Lines changed: 1 addition & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -300,94 +300,7 @@
300300
</variablelist>
301301
</refsect1>
302302

303-
<refsect1>
304-
<title>[SR-IOV] Section Options</title>
305-
<para>The [SR-IOV] section accepts the following keys. Specify several [SR-IOV] sections to
306-
configure several SR-IOVs. SR-IOV provides the ability to partition a single physical PCI resource
307-
into virtual PCI functions which can then be injected into a VM. In the case of network VFs, SR-IOV
308-
improves north-south network performance (that is, traffic with endpoints outside the host machine)
309-
by allowing traffic to bypass the host machine’s network stack.</para>
310-
311-
<variablelist class='network-directives'>
312-
<varlistentry>
313-
<term><varname>VirtualFunction=</varname></term>
314-
<listitem>
315-
<para>Specifies a Virtual Function (VF), lightweight PCIe function designed solely to move
316-
data in and out. Takes an integer in the range 0…2147483646. This option is compulsory.
317-
</para>
318-
</listitem>
319-
</varlistentry>
320-
321-
<varlistentry>
322-
<term><varname>VLANId=</varname></term>
323-
<listitem>
324-
<para>Specifies VLAN ID of the virtual function. Takes an integer in the range 1…4095.</para>
325-
</listitem>
326-
</varlistentry>
327-
328-
<varlistentry>
329-
<term><varname>QualityOfService=</varname></term>
330-
<listitem>
331-
<para>Specifies quality of service of the virtual function. Takes an integer in the range
332-
1…4294967294.</para>
333-
</listitem>
334-
</varlistentry>
335-
336-
<varlistentry>
337-
<term><varname>VLANProtocol=</varname></term>
338-
<listitem>
339-
<para>Specifies VLAN protocol of the virtual function. Takes <literal>802.1Q</literal> or
340-
<literal>802.1ad</literal>.</para>
341-
</listitem>
342-
</varlistentry>
343-
344-
<varlistentry>
345-
<term><varname>MACSpoofCheck=</varname></term>
346-
<listitem>
347-
<para>Takes a boolean. Controls the MAC spoof checking. When unset, the kernel's default will
348-
be used.</para>
349-
</listitem>
350-
</varlistentry>
351-
352-
<varlistentry>
353-
<term><varname>QueryReceiveSideScaling=</varname></term>
354-
<listitem>
355-
<para>Takes a boolean. Toggle the ability of querying the receive side scaling (RSS)
356-
configuration of the virtual function (VF). The VF RSS information like RSS hash key may be
357-
considered sensitive on some devices where this information is shared between VF and the
358-
physical function (PF). When unset, the kernel's default will be used.</para>
359-
</listitem>
360-
</varlistentry>
361-
362-
<varlistentry>
363-
<term><varname>Trust=</varname></term>
364-
<listitem>
365-
<para>Takes a boolean. Allows one to set trust mode of the virtual function (VF). When set, VF
366-
users can set a specific feature which may impact security and/or performance. When unset,
367-
the kernel's default will be used.</para>
368-
</listitem>
369-
</varlistentry>
370-
371-
<varlistentry>
372-
<term><varname>LinkState=</varname></term>
373-
<listitem>
374-
<para>Allows one to set the link state of the virtual function (VF). Takes a boolean or a
375-
special value <literal>auto</literal>. Setting to <literal>auto</literal> means a
376-
reflection of the physical function (PF) link state, <literal>yes</literal> lets the VF to
377-
communicate with other VFs on this host even if the PF link state is down,
378-
<literal>no</literal> causes the hardware to drop any packets sent by the VF. When unset,
379-
the kernel's default will be used.</para>
380-
</listitem>
381-
</varlistentry>
382-
383-
<varlistentry>
384-
<term><varname>MACAddress=</varname></term>
385-
<listitem>
386-
<para>Specifies the MAC address for the virtual function.</para>
387-
</listitem>
388-
</varlistentry>
389-
</variablelist>
390-
</refsect1>
303+
<xi:include href="systemd.link.xml" xpointer="sr-iov" />
391304

392305
<refsect1>
393306
<title>[Network] Section Options</title>

src/udev/net/link-config-gperf.gperf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _Pragma("GCC diagnostic ignored \"-Wimplicit-fallthrough\"")
88
#include "ethtool-util.h"
99
#include "link-config.h"
1010
#include "net-condition.h"
11+
#include "netif-sriov.h"
1112
#include "socket-util.h"
1213
%}
1314
struct ConfigPerfItem;
@@ -101,3 +102,12 @@ Link.RxMaxCoalescedHighFrames, config_parse_coalesce_u32,
101102
Link.TxCoalesceHighSec, config_parse_coalesce_sec, 0, offsetof(LinkConfig, coalesce.tx_coalesce_usecs_high)
102103
Link.TxMaxCoalescedHighFrames, config_parse_coalesce_u32, 0, offsetof(LinkConfig, coalesce.tx_max_coalesced_frames_high)
103104
Link.CoalescePacketRateSampleIntervalSec, config_parse_coalesce_sec, 0, offsetof(LinkConfig, coalesce.rate_sample_interval)
105+
SR-IOV.VirtualFunction, config_parse_sr_iov_uint32, 0, offsetof(LinkConfig, sr_iov_by_section)
106+
SR-IOV.VLANId, config_parse_sr_iov_uint32, 0, offsetof(LinkConfig, sr_iov_by_section)
107+
SR-IOV.QualityOfService, config_parse_sr_iov_uint32, 0, offsetof(LinkConfig, sr_iov_by_section)
108+
SR-IOV.VLANProtocol, config_parse_sr_iov_vlan_proto, 0, offsetof(LinkConfig, sr_iov_by_section)
109+
SR-IOV.MACSpoofCheck, config_parse_sr_iov_boolean, 0, offsetof(LinkConfig, sr_iov_by_section)
110+
SR-IOV.QueryReceiveSideScaling, config_parse_sr_iov_boolean, 0, offsetof(LinkConfig, sr_iov_by_section)
111+
SR-IOV.Trust, config_parse_sr_iov_boolean, 0, offsetof(LinkConfig, sr_iov_by_section)
112+
SR-IOV.LinkState, config_parse_sr_iov_link_state, 0, offsetof(LinkConfig, sr_iov_by_section)
113+
SR-IOV.MACAddress, config_parse_sr_iov_mac, 0, offsetof(LinkConfig, sr_iov_by_section)

src/udev/net/link-config.c

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "log-link.h"
2323
#include "memory-util.h"
2424
#include "net-condition.h"
25+
#include "netif-sriov.h"
2526
#include "netif-util.h"
2627
#include "netlink-util.h"
2728
#include "parse-util.h"
@@ -60,6 +61,8 @@ static LinkConfig* link_config_free(LinkConfig *config) {
6061
free(config->wol_password_file);
6162
erase_and_free(config->wol_password);
6263

64+
ordered_hashmap_free_with_destructor(config->sr_iov_by_section, sr_iov_free);
65+
6366
return mfree(config);
6467
}
6568

@@ -257,7 +260,9 @@ int link_load_one(LinkConfigContext *ctx, const char *filename) {
257260
STRV_MAKE_CONST(filename),
258261
(const char* const*) CONF_PATHS_STRV("systemd/network"),
259262
dropin_dirname,
260-
"Match\0Link\0",
263+
"Match\0"
264+
"Link\0"
265+
"SR-IOV\0",
261266
config_item_perf_lookup, link_config_gperf_lookup,
262267
CONFIG_PARSE_WARN, config, NULL);
263268
if (r < 0)
@@ -285,6 +290,10 @@ int link_load_one(LinkConfigContext *ctx, const char *filename) {
285290
if (r < 0)
286291
return r;
287292

293+
r = sr_iov_drop_invalid_sections(config->sr_iov_by_section);
294+
if (r < 0)
295+
return r;
296+
288297
log_debug("Parsed configuration file %s", filename);
289298

290299
LIST_PREPEND(configs, ctx->configs, TAKE_PTR(config));
@@ -830,6 +839,53 @@ static int link_apply_alternative_names(Link *link, sd_netlink **rtnl) {
830839
return 0;
831840
}
832841

842+
static int sr_iov_configure(Link *link, sd_netlink **rtnl, SRIOV *sr_iov) {
843+
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL;
844+
int r;
845+
846+
assert(link);
847+
assert(rtnl);
848+
assert(link->ifindex > 0);
849+
850+
if (!*rtnl) {
851+
r = sd_netlink_open(rtnl);
852+
if (r < 0)
853+
return r;
854+
}
855+
856+
r = sd_rtnl_message_new_link(*rtnl, &req, RTM_SETLINK, link->ifindex);
857+
if (r < 0)
858+
return r;
859+
860+
r = sr_iov_set_netlink_message(sr_iov, req);
861+
if (r < 0)
862+
return r;
863+
864+
r = sd_netlink_call(*rtnl, req, 0, NULL);
865+
if (r < 0)
866+
return r;
867+
868+
return 0;
869+
}
870+
871+
static int link_apply_sr_iov_config(Link *link, sd_netlink **rtnl) {
872+
SRIOV *sr_iov;
873+
int r;
874+
875+
assert(link);
876+
assert(link->config);
877+
878+
ORDERED_HASHMAP_FOREACH(sr_iov, link->config->sr_iov_by_section) {
879+
r = sr_iov_configure(link, rtnl, sr_iov);
880+
if (r < 0)
881+
log_link_warning_errno(link, r,
882+
"Failed to configure SR-IOV virtual function %"PRIu32", ignoring: %m",
883+
sr_iov->vf);
884+
}
885+
886+
return 0;
887+
}
888+
833889
int link_apply_config(LinkConfigContext *ctx, sd_netlink **rtnl, Link *link) {
834890
int r;
835891

@@ -861,6 +917,10 @@ int link_apply_config(LinkConfigContext *ctx, sd_netlink **rtnl, Link *link) {
861917
if (r < 0)
862918
return r;
863919

920+
r = link_apply_sr_iov_config(link, rtnl);
921+
if (r < 0)
922+
return r;
923+
864924
return 0;
865925
}
866926

src/udev/net/link-config.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "condition.h"
88
#include "conf-parser.h"
99
#include "ethtool-util.h"
10+
#include "hashmap.h"
1011
#include "list.h"
1112
#include "net-condition.h"
1213
#include "netif-naming-scheme.h"
@@ -76,6 +77,8 @@ struct LinkConfig {
7677
int autoneg_flow_control;
7778
netdev_coalesce_param coalesce;
7879

80+
OrderedHashmap *sr_iov_by_section;
81+
7982
LIST_FIELDS(LinkConfig, configs);
8083
};
8184

test/fuzz/fuzz-link-parser/directives.link

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,13 @@ RxMaxCoalescedHighFrames=
8080
TxCoalesceHighSec=
8181
TxMaxCoalescedHighFrames=
8282
CoalescePacketRateSampleIntervalSec=
83+
[SR-IOV]
84+
VirtualFunction=
85+
MACSpoofCheck=
86+
VLANId=
87+
VLANProtocol=
88+
QualityOfService=
89+
QueryReceiveSideScaling=
90+
Trust=
91+
LinkState=
92+
MACAddress=

0 commit comments

Comments
 (0)