Skip to content

Commit

Permalink
net/bonding: Implement TLS TX device offload
Browse files Browse the repository at this point in the history
Implement TLS TX device offload for bonding interfaces.
This allows kTLS sockets running on a bond to benefit from the
device offload on capable lower devices.

To allow a simple and fast maintenance of the TLS context in SW and
lower devices, we bind the TLS socket to a specific lower dev.
To achieve a behavior similar to SW kTLS, we support only balance-xor
and 802.3ad modes, with xmit_hash_policy=layer3+4. This is enforced
in bond_sk_check(), done in a previous patch.

For the above configuration, the SW implementation keeps picking the
same exact lower dev for all the socket's SKBs. The device offload
behaves similarly, making the decision once at the connection creation.

Per socket, the TLS module should work directly with the lowest netdev
in chain, to call the tls_dev_ops operations.

As the bond interface is being bypassed by the TLS module, interacting
directly against the lower devs, there is no way for the bond interface
to disable its device offload capabilities, as long as the mode/policy
config allows it.
Hence, the feature flag is not directly controllable, but just reflects
the current offload status based on the logic under bond_sk_check().

Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
Reviewed-by: Boris Pismenny <borisp@nvidia.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Tariq Toukan authored and kuba-moo committed Jan 19, 2021
1 parent f45583d commit 89df6a8
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
29 changes: 29 additions & 0 deletions drivers/net/bonding/bond_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@
#include <net/bonding.h>
#include <net/bond_3ad.h>
#include <net/bond_alb.h>
#if IS_ENABLED(CONFIG_TLS_DEVICE)
#include <net/tls.h>
#endif

#include "bonding_priv.h"

Expand Down Expand Up @@ -1225,6 +1228,13 @@ static netdev_features_t bond_fix_features(struct net_device *dev,
netdev_features_t mask;
struct slave *slave;

#if IS_ENABLED(CONFIG_TLS_DEVICE)
if (bond_sk_check(bond))
features |= BOND_TLS_FEATURES;
else
features &= ~BOND_TLS_FEATURES;
#endif

mask = features;

features &= ~NETIF_F_ONE_FOR_ALL;
Expand Down Expand Up @@ -4647,6 +4657,16 @@ static struct net_device *bond_sk_get_lower_dev(struct net_device *dev,
return lower;
}

#if IS_ENABLED(CONFIG_TLS_DEVICE)
static netdev_tx_t bond_tls_device_xmit(struct bonding *bond, struct sk_buff *skb,
struct net_device *dev)
{
if (likely(bond_get_slave_by_dev(bond, tls_get_ctx(skb->sk)->netdev)))
return bond_dev_queue_xmit(bond, skb, tls_get_ctx(skb->sk)->netdev);
return bond_tx_drop(dev, skb);
}
#endif

static netdev_tx_t __bond_start_xmit(struct sk_buff *skb, struct net_device *dev)
{
struct bonding *bond = netdev_priv(dev);
Expand All @@ -4655,6 +4675,11 @@ static netdev_tx_t __bond_start_xmit(struct sk_buff *skb, struct net_device *dev
!bond_slave_override(bond, skb))
return NETDEV_TX_OK;

#if IS_ENABLED(CONFIG_TLS_DEVICE)
if (skb->sk && tls_is_sk_tx_device_offloaded(skb->sk))
return bond_tls_device_xmit(bond, skb, dev);
#endif

switch (BOND_MODE(bond)) {
case BOND_MODE_ROUNDROBIN:
return bond_xmit_roundrobin(skb, dev);
Expand Down Expand Up @@ -4855,6 +4880,10 @@ void bond_setup(struct net_device *bond_dev)
if (BOND_MODE(bond) == BOND_MODE_ACTIVEBACKUP)
bond_dev->features |= BOND_XFRM_FEATURES;
#endif /* CONFIG_XFRM_OFFLOAD */
#if IS_ENABLED(CONFIG_TLS_DEVICE)
if (bond_sk_check(bond))
bond_dev->features |= BOND_TLS_FEATURES;
#endif
}

/* Destroy a bonding device.
Expand Down
27 changes: 25 additions & 2 deletions drivers/net/bonding/bond_options.c
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,19 @@ static bool bond_set_xfrm_features(struct bonding *bond)
return true;
}

static bool bond_set_tls_features(struct bonding *bond)
{
if (!IS_ENABLED(CONFIG_TLS_DEVICE))
return false;

if (bond_sk_check(bond))
bond->dev->wanted_features |= BOND_TLS_FEATURES;
else
bond->dev->wanted_features &= ~BOND_TLS_FEATURES;

return true;
}

static int bond_option_mode_set(struct bonding *bond,
const struct bond_opt_value *newval)
{
Expand All @@ -784,9 +797,15 @@ static int bond_option_mode_set(struct bonding *bond,
bond->params.arp_validate = BOND_ARP_VALIDATE_NONE;
bond->params.mode = newval->value;

if (bond->dev->reg_state == NETREG_REGISTERED)
if (bond_set_xfrm_features(bond))
if (bond->dev->reg_state == NETREG_REGISTERED) {
bool update = false;

update |= bond_set_xfrm_features(bond);
update |= bond_set_tls_features(bond);

if (update)
netdev_update_features(bond->dev);
}

return 0;
}
Expand Down Expand Up @@ -1220,6 +1239,10 @@ static int bond_option_xmit_hash_policy_set(struct bonding *bond,
newval->string, newval->value);
bond->params.xmit_policy = newval->value;

if (bond->dev->reg_state == NETREG_REGISTERED)
if (bond_set_tls_features(bond))
netdev_update_features(bond->dev);

return 0;
}

Expand Down
2 changes: 2 additions & 0 deletions include/net/bonding.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@
#define BOND_XFRM_FEATURES (NETIF_F_HW_ESP | NETIF_F_HW_ESP_TX_CSUM | \
NETIF_F_GSO_ESP)

#define BOND_TLS_FEATURES (NETIF_F_HW_TLS_TX)

#ifdef CONFIG_NET_POLL_CONTROLLER
extern atomic_t netpoll_block_tx;

Expand Down

0 comments on commit 89df6a8

Please sign in to comment.