Skip to content

Commit f4e405f

Browse files
committed
Merge branch 'macsec-offload-fixes'
Sabrina Dubroca says: ==================== macsec: offload-related fixes I'm working on a dummy offload for macsec on netdevsim. It just has a small SecY and RXSC table so I can trigger failures easily on the ndo_* side. It has exposed a couple of issues. The first patch is a revert of commit c850240 ("net: macsec: report real_dev features when HW offloading is enabled"). That commit tried to improve the performance of macsec offload by taking advantage of some of the NIC's features, but in doing so, broke macsec offload when the lower device supports both macsec and ipsec offload, as the ipsec offload feature flags were copied from the real device. Since the macsec device doesn't provide xdo_* ops, the XFRM core rejects the registration of the new macsec device in xfrm_api_check. I'm working on re-adding those feature flags when offload is available, but I haven't fully solved that yet. I think it would be safer to do that second part in net-next considering how complex feature interactions tend to be. v2: - better describe the issue introduced by commit c850240 (Leon Romanovsky) - patch #3: drop unnecessary !! (Leon Romanovsky) v3: - patch #3: drop extra newline (Jakub Kicinski) ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents cdb525c + aaab73f commit f4e405f

File tree

1 file changed

+17
-33
lines changed

1 file changed

+17
-33
lines changed

drivers/net/macsec.c

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,7 +1413,8 @@ static struct macsec_rx_sc *del_rx_sc(struct macsec_secy *secy, sci_t sci)
14131413
return NULL;
14141414
}
14151415

1416-
static struct macsec_rx_sc *create_rx_sc(struct net_device *dev, sci_t sci)
1416+
static struct macsec_rx_sc *create_rx_sc(struct net_device *dev, sci_t sci,
1417+
bool active)
14171418
{
14181419
struct macsec_rx_sc *rx_sc;
14191420
struct macsec_dev *macsec;
@@ -1437,7 +1438,7 @@ static struct macsec_rx_sc *create_rx_sc(struct net_device *dev, sci_t sci)
14371438
}
14381439

14391440
rx_sc->sci = sci;
1440-
rx_sc->active = true;
1441+
rx_sc->active = active;
14411442
refcount_set(&rx_sc->refcnt, 1);
14421443

14431444
secy = &macsec_priv(dev)->secy;
@@ -1838,6 +1839,7 @@ static int macsec_add_rxsa(struct sk_buff *skb, struct genl_info *info)
18381839
secy->key_len);
18391840

18401841
err = macsec_offload(ops->mdo_add_rxsa, &ctx);
1842+
memzero_explicit(ctx.sa.key, secy->key_len);
18411843
if (err)
18421844
goto cleanup;
18431845
}
@@ -1876,7 +1878,7 @@ static int macsec_add_rxsc(struct sk_buff *skb, struct genl_info *info)
18761878
struct macsec_rx_sc *rx_sc;
18771879
struct nlattr *tb_rxsc[MACSEC_RXSC_ATTR_MAX + 1];
18781880
struct macsec_secy *secy;
1879-
bool was_active;
1881+
bool active = true;
18801882
int ret;
18811883

18821884
if (!attrs[MACSEC_ATTR_IFINDEX])
@@ -1898,16 +1900,15 @@ static int macsec_add_rxsc(struct sk_buff *skb, struct genl_info *info)
18981900
secy = &macsec_priv(dev)->secy;
18991901
sci = nla_get_sci(tb_rxsc[MACSEC_RXSC_ATTR_SCI]);
19001902

1901-
rx_sc = create_rx_sc(dev, sci);
1903+
if (tb_rxsc[MACSEC_RXSC_ATTR_ACTIVE])
1904+
active = nla_get_u8(tb_rxsc[MACSEC_RXSC_ATTR_ACTIVE]);
1905+
1906+
rx_sc = create_rx_sc(dev, sci, active);
19021907
if (IS_ERR(rx_sc)) {
19031908
rtnl_unlock();
19041909
return PTR_ERR(rx_sc);
19051910
}
19061911

1907-
was_active = rx_sc->active;
1908-
if (tb_rxsc[MACSEC_RXSC_ATTR_ACTIVE])
1909-
rx_sc->active = !!nla_get_u8(tb_rxsc[MACSEC_RXSC_ATTR_ACTIVE]);
1910-
19111912
if (macsec_is_offloaded(netdev_priv(dev))) {
19121913
const struct macsec_ops *ops;
19131914
struct macsec_context ctx;
@@ -1931,7 +1932,8 @@ static int macsec_add_rxsc(struct sk_buff *skb, struct genl_info *info)
19311932
return 0;
19321933

19331934
cleanup:
1934-
rx_sc->active = was_active;
1935+
del_rx_sc(secy, sci);
1936+
free_rx_sc(rx_sc);
19351937
rtnl_unlock();
19361938
return ret;
19371939
}
@@ -2080,6 +2082,7 @@ static int macsec_add_txsa(struct sk_buff *skb, struct genl_info *info)
20802082
secy->key_len);
20812083

20822084
err = macsec_offload(ops->mdo_add_txsa, &ctx);
2085+
memzero_explicit(ctx.sa.key, secy->key_len);
20832086
if (err)
20842087
goto cleanup;
20852088
}
@@ -2570,7 +2573,7 @@ static bool macsec_is_configured(struct macsec_dev *macsec)
25702573
struct macsec_tx_sc *tx_sc = &secy->tx_sc;
25712574
int i;
25722575

2573-
if (secy->n_rx_sc > 0)
2576+
if (secy->rx_sc)
25742577
return true;
25752578

25762579
for (i = 0; i < MACSEC_NUM_AN; i++)
@@ -2654,11 +2657,6 @@ static int macsec_upd_offload(struct sk_buff *skb, struct genl_info *info)
26542657
if (ret)
26552658
goto rollback;
26562659

2657-
/* Force features update, since they are different for SW MACSec and
2658-
* HW offloading cases.
2659-
*/
2660-
netdev_update_features(dev);
2661-
26622660
rtnl_unlock();
26632661
return 0;
26642662

@@ -3432,16 +3430,9 @@ static netdev_tx_t macsec_start_xmit(struct sk_buff *skb,
34323430
return ret;
34333431
}
34343432

3435-
#define SW_MACSEC_FEATURES \
3433+
#define MACSEC_FEATURES \
34363434
(NETIF_F_SG | NETIF_F_HIGHDMA | NETIF_F_FRAGLIST)
34373435

3438-
/* If h/w offloading is enabled, use real device features save for
3439-
* VLAN_FEATURES - they require additional ops
3440-
* HW_MACSEC - no reason to report it
3441-
*/
3442-
#define REAL_DEV_FEATURES(dev) \
3443-
((dev)->features & ~(NETIF_F_VLAN_FEATURES | NETIF_F_HW_MACSEC))
3444-
34453436
static int macsec_dev_init(struct net_device *dev)
34463437
{
34473438
struct macsec_dev *macsec = macsec_priv(dev);
@@ -3458,12 +3449,8 @@ static int macsec_dev_init(struct net_device *dev)
34583449
return err;
34593450
}
34603451

3461-
if (macsec_is_offloaded(macsec)) {
3462-
dev->features = REAL_DEV_FEATURES(real_dev);
3463-
} else {
3464-
dev->features = real_dev->features & SW_MACSEC_FEATURES;
3465-
dev->features |= NETIF_F_LLTX | NETIF_F_GSO_SOFTWARE;
3466-
}
3452+
dev->features = real_dev->features & MACSEC_FEATURES;
3453+
dev->features |= NETIF_F_LLTX | NETIF_F_GSO_SOFTWARE;
34673454

34683455
dev->needed_headroom = real_dev->needed_headroom +
34693456
MACSEC_NEEDED_HEADROOM;
@@ -3495,10 +3482,7 @@ static netdev_features_t macsec_fix_features(struct net_device *dev,
34953482
struct macsec_dev *macsec = macsec_priv(dev);
34963483
struct net_device *real_dev = macsec->real_dev;
34973484

3498-
if (macsec_is_offloaded(macsec))
3499-
return REAL_DEV_FEATURES(real_dev);
3500-
3501-
features &= (real_dev->features & SW_MACSEC_FEATURES) |
3485+
features &= (real_dev->features & MACSEC_FEATURES) |
35023486
NETIF_F_GSO_SOFTWARE | NETIF_F_SOFT_FEATURES;
35033487
features |= NETIF_F_LLTX;
35043488

0 commit comments

Comments
 (0)