Skip to content

Commit

Permalink
network: Introduce SOR-IOV
Browse files Browse the repository at this point in the history
SR-IOV provides the ability to partition a single physical PCI
resource into virtual PCI functions which can then be injected in
to a VM. In the case of network VFs, SR-IOV improves north-south n
etwork performance (that is, traffic with endpoints outside the
host machine) by allowing traffic to bypass the host machine’s network stack.
:wq
  • Loading branch information
ssahani committed Jun 22, 2020
1 parent 4ed75c6 commit 36f6723
Show file tree
Hide file tree
Showing 10 changed files with 573 additions and 0 deletions.
66 changes: 66 additions & 0 deletions man/systemd.network.xml
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,72 @@
</variablelist>
</refsect1>

<refsect1>
<title>[SRIOV] Section Options</title>
<para>The <literal>[SRIOV]</literal> section accepts the
following keys. Specify several <literal>[SRIOV]</literal>
sections to configure several SOR-IOVs. SR-IOV provides the ability to partition a single physical PCI resource
into virtual PCI functions which can then be injected into a VM. In the case of network VFs, SR-IOV improves
north-south network performance (that is, traffic with endpoints outside the host machine) by allowing traffic to
bypass the host machine’s network stack.</para>

<variablelist class='network-directives'>
<varlistentry>
<term><varname>VirtualFunction=</varname></term>
<listitem>
<para>Specifies the Virtual Function (VFs), lightweight PCIe functions designed solely to move data
in and out. Takes an unsigned integer ranges 0..4294967294. This is mandatory.</para>
</listitem>
</varlistentry>

<varlistentry>
<term><varname>VLanId=</varname></term>
<listitem>
<para>Specifies Vlan ID of the virtual function. Takes an unsigned integer ranges 1..4095.</para>
</listitem>
</varlistentry>

<varlistentry>
<term><varname>QualityOfService=</varname></term>
<listitem>
<para>Specifies quality of service of the virtual function. Takes an unsigned integer ranges 1..4294967294.</para>
</listitem>
</varlistentry>

<varlistentry>
<term><varname>MACSpoofCheck=</varname></term>
<listitem>
<para>A boolen. Controls the MAC spoof checking. When unset, the kernel's default will be used.</para>
</listitem>
</varlistentry>

<varlistentry>
<term><varname>QueryReceiveSideScaling=</varname></term>
<listitem>
<para>A boolen. Allows to query virtual function's (VF) receive side scaling (RSS) information like
RSS hash key may be considered sensitive on some devices where this information is shared between VF and PF.
When unset, the kernel's default will be used.</para>
</listitem>
</varlistentry>

<varlistentry>
<term><varname>Trust=</varname></term>
<listitem>
<para>A boolen. Allows to set trust mode of virtual function. When unset, the kernel's default will be used.</para>
</listitem>
</varlistentry>

<varlistentry>
<term><varname>LinkState=</varname></term>
<listitem>
<para>Allows to set the link state of vitual function. Takes a boolen or a special value
<literal>auto</literal>. When unset, the kernel's default will be used.</para>
</listitem>
</varlistentry>

</variablelist>
</refsect1>

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

Expand Down
2 changes: 2 additions & 0 deletions src/network/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ sources = files('''
networkd-routing-policy-rule.h
networkd-speed-meter.c
networkd-speed-meter.h
networkd-sriov.c
networkd-sriov.h
networkd-util.c
networkd-util.h
networkd-wifi.c
Expand Down
31 changes: 31 additions & 0 deletions src/network/networkd-link.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <netinet/in.h>
#include <linux/if.h>
#include <linux/if_arp.h>
#include <linux/if_link.h>
#include <unistd.h>

#include "alloc-util.h"
Expand Down Expand Up @@ -31,6 +32,7 @@
#include "networkd-manager.h"
#include "networkd-ndisc.h"
#include "networkd-neighbor.h"
#include "networkd-sriov.h"
#include "networkd-radv.h"
#include "networkd-routing-policy-rule.h"
#include "networkd-wifi.h"
Expand Down Expand Up @@ -1124,6 +1126,9 @@ void link_check_ready(Link *link) {
if (!link->tc_configured)
return;

if (!link->sr_iov_configured)
return;

if (link_has_carrier(link) || !link->network->configure_without_carrier) {

if (link_ipv4ll_enabled(link, ADDRESS_FAMILY_IPV4) && !link->ipv4ll_address)
Expand Down Expand Up @@ -2837,6 +2842,28 @@ static int link_configure_traffic_control(Link *link) {
return 0;
}

static int link_configure_sr_iov(Link *link) {
SRIOV *sr_iov;
Iterator i;
int r;

link->sr_iov_configured = false;
link->sr_iov_messages = 0;

ORDERED_HASHMAP_FOREACH(sr_iov, link->network->sr_iov_by_section, i) {
r = sr_iov_configure(link, sr_iov);
if (r < 0)
return r;
}

if (link->sr_iov_messages == 0)
link->sr_iov_configured = true;
else
log_link_debug(link, "Configuring SR-IOV");

return 0;
}

static int link_configure(Link *link) {
int r;

Expand All @@ -2848,6 +2875,10 @@ static int link_configure(Link *link) {
if (r < 0)
return r;

r = link_configure_sr_iov(link);
if (r < 0)
return r;

if (link->iftype == ARPHRD_CAN)
return link_configure_can(link);

Expand Down
2 changes: 2 additions & 0 deletions src/network/networkd-link.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ typedef struct Link {
unsigned routing_policy_rule_messages;
unsigned routing_policy_rule_remove_messages;
unsigned tc_messages;
unsigned sr_iov_messages;
unsigned enslaving;

Set *addresses;
Expand Down Expand Up @@ -127,6 +128,7 @@ typedef struct Link {
bool static_nexthops_configured:1;
bool routing_policy_rules_configured:1;
bool tc_configured:1;
bool sr_iov_configured:1;
bool setting_mtu:1;
bool setting_genmode:1;
bool ipv6_mtu_set:1;
Expand Down
8 changes: 8 additions & 0 deletions src/network/networkd-network-gperf.gperf
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ _Pragma("GCC diagnostic ignored \"-Wimplicit-fallthrough\"")
#include "networkd-ipv4ll.h"
#include "networkd-ndisc.h"
#include "networkd-network.h"
#include "networkd-sriov.h"
#include "qdisc.h"
#include "tclass.h"
#include "vlan-util.h"
Expand Down Expand Up @@ -54,6 +55,13 @@ Link.AllMulticast, config_parse_tristate,
Link.Unmanaged, config_parse_bool, 0, offsetof(Network, unmanaged)
Link.IPv6LinkLocalAddressGenerationMode, config_parse_link_ipv6_address_gen_mode, 0, offsetof(Network, ipv6_address_gen_mode)
Link.RequiredForOnline, config_parse_required_for_online, 0, 0
SRIOV.VirtualFunction, config_parse_sr_iov_uint32, 0, 0
SRIOV.VLanId, config_parse_sr_iov_uint32, 0, 0
SRIOV.QualityOfService, config_parse_sr_iov_uint32, 0, 0
SRIOV.MACSpoofCheck, config_parse_sr_iov_boolean, 0, 0
SRIOV.QueryReceiveSideScaling, config_parse_sr_iov_boolean, 0, 0
SRIOV.Trust, config_parse_sr_iov_boolean, 0, 0
SRIOV.LinkState, config_parse_sr_iov_link_state, 0, 0
Network.Description, config_parse_string, 0, offsetof(Network, description)
Network.Bridge, config_parse_ifname, 0, offsetof(Network, bridge_name)
Network.Bond, config_parse_ifname, 0, offsetof(Network, bond_name)
Expand Down
9 changes: 9 additions & 0 deletions src/network/networkd-network.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "network-internal.h"
#include "networkd-manager.h"
#include "networkd-network.h"
#include "networkd-sriov.h"
#include "parse-util.h"
#include "path-lookup.h"
#include "set.h"
Expand Down Expand Up @@ -158,6 +159,7 @@ int network_verify(Network *network) {
Route *route, *route_next;
FdbEntry *fdb, *fdb_next;
TrafficControl *tc;
SRIOV *sr_iov;
Iterator i;

assert(network);
Expand Down Expand Up @@ -330,6 +332,11 @@ int network_verify(Network *network) {
if (traffic_control_section_verify(tc, &has_root, &has_clsact) < 0)
traffic_control_free(tc);

ORDERED_HASHMAP_FOREACH(sr_iov, network->sr_iov_by_section, i) {
if (sr_iov_section_verify(sr_iov) < 0)
sr_iov_free(sr_iov);
}

return 0;
}

Expand Down Expand Up @@ -484,6 +491,7 @@ int network_load_one(Manager *manager, OrderedHashmap **networks, const char *fi
filename, NETWORK_DIRS, dropin_dirname,
"Match\0"
"Link\0"
"SRIOV\0"
"Network\0"
"Address\0"
"Neighbor\0"
Expand Down Expand Up @@ -730,6 +738,7 @@ static Network *network_free(Network *network) {
hashmap_free(network->prefixes_by_section);
hashmap_free(network->route_prefixes_by_section);
hashmap_free(network->rules_by_section);
ordered_hashmap_free_with_destructor(network->sr_iov_by_section, sr_iov_free);
ordered_hashmap_free_with_destructor(network->tc_by_section, traffic_control_free);

if (network->manager &&
Expand Down
1 change: 1 addition & 0 deletions src/network/networkd-network.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ struct Network {
Hashmap *route_prefixes_by_section;
Hashmap *rules_by_section;
OrderedHashmap *tc_by_section;
OrderedHashmap *sr_iov_by_section;

/* All kinds of DNS configuration */
struct in_addr_data *dns;
Expand Down

0 comments on commit 36f6723

Please sign in to comment.