Skip to content

Commit

Permalink
net: openvswitch: add support for l4 symmetric hashing
Browse files Browse the repository at this point in the history
Since its introduction, the ovs module execute_hash action allowed
hash algorithms other than the skb->l4_hash to be used.  However,
additional hash algorithms were not implemented.  This means flows
requiring different hash distributions weren't able to use the
kernel datapath.

Now, introduce support for symmetric hashing algorithm as an
alternative hash supported by the ovs module using the flow
dissector.

Output of flow using l4_sym hash:

    recirc_id(0),in_port(3),eth(),eth_type(0x0800),
    ipv4(dst=64.0.0.0/192.0.0.0,proto=6,frag=no), packets:30473425,
    bytes:45902883702, used:0.000s, flags:SP.,
    actions:hash(sym_l4(0)),recirc(0xd)

Some performance testing with no GRO/GSO, two veths, single flow:

    hash(l4(0)):      4.35 GBits/s
    hash(l4_sym(0)):  4.24 GBits/s

Signed-off-by: Aaron Conole <aconole@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Aaron Conole authored and David S. Miller committed Jun 12, 2023
1 parent 6513787 commit e069ba0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions include/uapi/linux/openvswitch.h
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,7 @@ struct ovs_action_push_vlan {
*/
enum ovs_hash_alg {
OVS_HASH_ALG_L4,
OVS_HASH_ALG_SYM_L4,
};

/*
Expand Down
12 changes: 10 additions & 2 deletions net/openvswitch/actions.c
Original file line number Diff line number Diff line change
Expand Up @@ -1073,8 +1073,16 @@ static void execute_hash(struct sk_buff *skb, struct sw_flow_key *key,
struct ovs_action_hash *hash_act = nla_data(attr);
u32 hash = 0;

/* OVS_HASH_ALG_L4 is the only possible hash algorithm. */
hash = skb_get_hash(skb);
if (hash_act->hash_alg == OVS_HASH_ALG_L4) {
/* OVS_HASH_ALG_L4 hasing type. */
hash = skb_get_hash(skb);
} else if (hash_act->hash_alg == OVS_HASH_ALG_SYM_L4) {
/* OVS_HASH_ALG_SYM_L4 hashing type. NOTE: this doesn't
* extend past an encapsulated header.
*/
hash = __skb_get_hash_symmetric(skb);
}

hash = jhash_1word(hash, hash_act->hash_basis);
if (!hash)
hash = 0x1;
Expand Down
2 changes: 2 additions & 0 deletions net/openvswitch/flow_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -3221,6 +3221,8 @@ static int __ovs_nla_copy_actions(struct net *net, const struct nlattr *attr,

switch (act_hash->hash_alg) {
case OVS_HASH_ALG_L4:
fallthrough;
case OVS_HASH_ALG_SYM_L4:
break;
default:
return -EINVAL;
Expand Down

0 comments on commit e069ba0

Please sign in to comment.