netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next v1 00/3] Introduce MACsec offload SKB extension
@ 2022-05-08  9:09 Lior Nahmanson
  2022-05-08  9:09 ` [PATCH net-next v1 01/03] net/macsec: Add MACsec skb extension Tx Data path support Lior Nahmanson
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Lior Nahmanson @ 2022-05-08  9:09 UTC (permalink / raw)
  To: edumazet, kuba, pabeni; +Cc: davem, netdev, Lior Nahmanson

This patchset introduces MACsec SKB extension to lay the ground
for MACsec HW offload.

MACsec is an IEEE standard (IEEE 802.1AE) for MAC security.
It defines a way to establish a protocol independent connection
between two hosts with data confidentiality, authenticity and/or
integrity, using GCM-AES. MACsec operates on the Ethernet layer and
as such is a layer 2 protocol, which means it’s designed to secure
traffic within a layer 2 network, including DHCP or ARP requests.

Linux has a software implementation of the MACsec standard and
HW offloading support.
The offloading is re-using the logic, netlink API and data
structures of the existing MACsec software implementation.

For Tx:
In the current MACsec offload implementation, MACsec interfaces are
sharing the same MAC address of their parent interface by default.
Therefore, HW can't distinguish if a packet was sent from MACsec
interface and need to be offloaded or not.
Also, it can't distinguish from which MACsec interface it was sent in
case there are multiple MACsec interface with the same MAC address.

Used SKB extension, so SW can mark if a packet is needed to be offloaded
and use the SCI, which is unique value for each MACsec interface,
to notify the HW from which MACsec interface the packet is sent.

For Rx:
Like in the Tx changes, packet that don't have SecTAG
header aren't necessary been offloaded by the HW.
Therefore, the MACsec driver needs to distinguish if the packet
was offloaded or not and handle accordingly.
Moreover, if there are more than one MACsec device with the same MAC
address as in the packet's destination MAC, the packet will forward only
to this device and only to the desired one.

Used SKB extension and marking it by the HW if the packet was offloaded
and to which MACsec offload device it belongs according to the packet's
SCI.

1) patch 0001-0002, Add support to SKB extension in MACsec code:
net/macsec: Add MACsec skb extension Tx Data path support
net/macsec: Add MACsec skb extension Rx Data path support

2) patch 0003, Move some MACsec driver code for sharing with various
drivers that implements offload:
net/macsec: Move some code for sharing with various drivers that
implements offload

Follow-up patchset for Nvidia MACsec HW offload will be submitted
later on.

-- 
2.25.4


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH net-next v1 01/03] net/macsec: Add MACsec skb extension Tx Data path support
  2022-05-08  9:09 [PATCH net-next v1 00/3] Introduce MACsec offload SKB extension Lior Nahmanson
@ 2022-05-08  9:09 ` Lior Nahmanson
  2022-05-10  9:23   ` Paolo Abeni
  2022-05-08  9:09 ` [PATCH net-next v1 02/03] net/macsec: Add MACsec skb extension Rx " Lior Nahmanson
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Lior Nahmanson @ 2022-05-08  9:09 UTC (permalink / raw)
  To: edumazet, kuba, pabeni
  Cc: davem, netdev, Lior Nahmanson, Raed Salem, Jiri Pirko, Ben Ben-Ishay

In the current MACsec offload implementation, MACsec interfaces are
sharing the same MAC address of their parent interface by default.
Therefore, HW can't distinguish if a packet was sent from MACsec
interface and need to be offloaded or not.
Also, it can't distinguish from which MACsec interface it was sent in
case there are multiple MACsec interface with the same MAC address.

Used SKB extension, so SW can mark if a packet is needed to be offloaded
and use the SCI, which is unique value for each MACsec interface,
to notify the HW from which MACsec interface the packet is sent.

Signed-off-by: Lior Nahmanson <liorna@nvidia.com>
Reviewed-by: Raed Salem <raeds@nvidia.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Reviewed-by: Ben Ben-Ishay <benishay@nvidia.com>
---
 drivers/net/Kconfig    | 1 +
 drivers/net/macsec.c   | 5 +++++
 include/linux/skbuff.h | 3 +++
 include/net/macsec.h   | 6 ++++++
 net/core/skbuff.c      | 7 +++++++
 5 files changed, 22 insertions(+)

diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index b2a4f998c180..6c9a950b7010 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -313,6 +313,7 @@ config MACSEC
 	select CRYPTO_AES
 	select CRYPTO_GCM
 	select GRO_CELLS
+	select SKB_EXTENSIONS
 	help
 	   MACsec is an encryption standard for Ethernet.
 
diff --git a/drivers/net/macsec.c b/drivers/net/macsec.c
index 832f09ac075e..0960339e2442 100644
--- a/drivers/net/macsec.c
+++ b/drivers/net/macsec.c
@@ -3377,6 +3377,11 @@ static netdev_tx_t macsec_start_xmit(struct sk_buff *skb,
 	int ret, len;
 
 	if (macsec_is_offloaded(netdev_priv(dev))) {
+		struct macsec_ext *secext = skb_ext_add(skb, SKB_EXT_MACSEC);
+
+		secext->sci = secy->sci;
+		secext->offloaded = true;
+
 		skb->dev = macsec->real_dev;
 		return dev_queue_xmit(skb);
 	}
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 84d78df60453..4ee71c7848bf 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -4552,6 +4552,9 @@ enum skb_ext_id {
 #endif
 #if IS_ENABLED(CONFIG_MCTP_FLOWS)
 	SKB_EXT_MCTP,
+#endif
+#if IS_ENABLED(CONFIG_MACSEC)
+	SKB_EXT_MACSEC,
 #endif
 	SKB_EXT_NUM, /* must be last */
 };
diff --git a/include/net/macsec.h b/include/net/macsec.h
index d6fa6b97f6ef..fcbca963c04d 100644
--- a/include/net/macsec.h
+++ b/include/net/macsec.h
@@ -20,6 +20,12 @@
 typedef u64 __bitwise sci_t;
 typedef u32 __bitwise ssci_t;
 
+/* MACsec sk_buff extension data */
+struct macsec_ext {
+	sci_t sci;
+	bool offloaded;
+};
+
 typedef union salt {
 	struct {
 		u32 ssci;
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 30b523fa4ad2..7483f45a6a83 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -72,6 +72,7 @@
 #include <net/mptcp.h>
 #include <net/mctp.h>
 #include <net/page_pool.h>
+#include <net/macsec.h>
 
 #include <linux/uaccess.h>
 #include <trace/events/skb.h>
@@ -4345,6 +4346,9 @@ static const u8 skb_ext_type_len[] = {
 #if IS_ENABLED(CONFIG_MCTP_FLOWS)
 	[SKB_EXT_MCTP] = SKB_EXT_CHUNKSIZEOF(struct mctp_flow),
 #endif
+#if IS_ENABLED(CONFIG_MACSEC)
+	[SKB_EXT_MACSEC] = SKB_EXT_CHUNKSIZEOF(struct macsec_ext),
+#endif
 };
 
 static __always_inline unsigned int skb_ext_total_length(void)
@@ -4364,6 +4368,9 @@ static __always_inline unsigned int skb_ext_total_length(void)
 #endif
 #if IS_ENABLED(CONFIG_MCTP_FLOWS)
 		skb_ext_type_len[SKB_EXT_MCTP] +
+#endif
+#if IS_ENABLED(CONFIG_MACSEC)
+		skb_ext_type_len[SKB_EXT_MACSEC] +
 #endif
 		0;
 }
-- 
2.25.4


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH net-next v1 02/03] net/macsec: Add MACsec skb extension Rx Data path support
  2022-05-08  9:09 [PATCH net-next v1 00/3] Introduce MACsec offload SKB extension Lior Nahmanson
  2022-05-08  9:09 ` [PATCH net-next v1 01/03] net/macsec: Add MACsec skb extension Tx Data path support Lior Nahmanson
@ 2022-05-08  9:09 ` Lior Nahmanson
  2022-05-08  9:09 ` [PATCH net-next v1 03/03] net/macsec: Move some code for sharing with various drivers that implements offload Lior Nahmanson
  2022-05-08 15:40 ` [PATCH net-next v1 00/3] Introduce MACsec offload SKB extension Leon Romanovsky
  3 siblings, 0 replies; 8+ messages in thread
From: Lior Nahmanson @ 2022-05-08  9:09 UTC (permalink / raw)
  To: edumazet, kuba, pabeni
  Cc: davem, netdev, Lior Nahmanson, Raed Salem, Jiri Pirko, Ben Ben-Ishay

Like in the Tx changes, packet that don't have SecTAG
header aren't necessary been offloaded by the HW.
Therefore, the MACsec driver needs to distinguish if the packet
was offloaded or not and handle accordingly.
Moreover, if there are more than one MACsec device with the same MAC
address as in the packet's destination MAC, the packet will forward only
to this device and only to the desired one.

Used SKB extension and marking it by the HW if the packet was offloaded
and to which MACsec offload device it belongs according to the packet's
SCI.

Signed-off-by: Lior Nahmanson <liorna@nvidia.com>
Reviewed-by: Raed Salem <raeds@nvidia.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Reviewed-by: Ben Ben-Ishay <benishay@nvidia.com>
---
 drivers/net/macsec.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/net/macsec.c b/drivers/net/macsec.c
index 0960339e2442..ee83d6a6e818 100644
--- a/drivers/net/macsec.c
+++ b/drivers/net/macsec.c
@@ -997,11 +997,13 @@ static enum rx_handler_result handle_not_macsec(struct sk_buff *skb)
 	/* Deliver to the uncontrolled port by default */
 	enum rx_handler_result ret = RX_HANDLER_PASS;
 	struct ethhdr *hdr = eth_hdr(skb);
+	struct macsec_ext *macsec_ext;
 	struct macsec_rxh_data *rxd;
 	struct macsec_dev *macsec;
 
 	rcu_read_lock();
 	rxd = macsec_data_rcu(skb->dev);
+	macsec_ext = skb_ext_find(skb, SKB_EXT_MACSEC);
 
 	list_for_each_entry_rcu(macsec, &rxd->secys, secys) {
 		struct sk_buff *nskb;
@@ -1011,7 +1013,11 @@ static enum rx_handler_result handle_not_macsec(struct sk_buff *skb)
 		/* If h/w offloading is enabled, HW decodes frames and strips
 		 * the SecTAG, so we have to deduce which port to deliver to.
 		 */
-		if (macsec_is_offloaded(macsec) && netif_running(ndev)) {
+		if (macsec_is_offloaded(macsec) && netif_running(ndev) &&
+		    (!macsec_ext || macsec_ext->offloaded)) {
+			if ((macsec_ext) && (!find_rx_sc(&macsec->secy, macsec_ext->sci)))
+				continue;
+
 			if (ether_addr_equal_64bits(hdr->h_dest,
 						    ndev->dev_addr)) {
 				/* exact match, divert skb to this port */
-- 
2.25.4


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH net-next v1 03/03] net/macsec: Move some code for sharing with various drivers that implements offload
  2022-05-08  9:09 [PATCH net-next v1 00/3] Introduce MACsec offload SKB extension Lior Nahmanson
  2022-05-08  9:09 ` [PATCH net-next v1 01/03] net/macsec: Add MACsec skb extension Tx Data path support Lior Nahmanson
  2022-05-08  9:09 ` [PATCH net-next v1 02/03] net/macsec: Add MACsec skb extension Rx " Lior Nahmanson
@ 2022-05-08  9:09 ` Lior Nahmanson
  2022-05-08 15:40 ` [PATCH net-next v1 00/3] Introduce MACsec offload SKB extension Leon Romanovsky
  3 siblings, 0 replies; 8+ messages in thread
From: Lior Nahmanson @ 2022-05-08  9:09 UTC (permalink / raw)
  To: edumazet, kuba, pabeni
  Cc: davem, netdev, Lior Nahmanson, Raed Salem, Jiri Pirko, Ben Ben-Ishay

Some MACsec infrastructure like defines and functions,
which may be useful for other drivers who implemented MACsec offload,
aren't accessible since they aren't located in any header file.

Moved those values to MACsec header file will allow those drivers
to use them and avoid code duplication.

Signed-off-by: Lior Nahmanson <liorna@nvidia.com>
Reviewed-by: Raed Salem <raeds@nvidia.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Reviewed-by: Ben Ben-Ishay <benishay@nvidia.com>
---
 drivers/net/macsec.c | 32 ++++++--------------------------
 include/net/macsec.h | 20 ++++++++++++++++++++
 2 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/drivers/net/macsec.c b/drivers/net/macsec.c
index ee83d6a6e818..b214abc0fb94 100644
--- a/drivers/net/macsec.c
+++ b/drivers/net/macsec.c
@@ -24,8 +24,6 @@
 
 #include <uapi/linux/if_macsec.h>
 
-#define MACSEC_SCI_LEN 8
-
 /* SecTAG length = macsec_eth_header without the optional SCI */
 #define MACSEC_TAG_LEN 6
 
@@ -46,20 +44,10 @@ struct macsec_eth_header {
 	u8 secure_channel_id[8]; /* optional */
 } __packed;
 
-#define MACSEC_TCI_VERSION 0x80
-#define MACSEC_TCI_ES      0x40 /* end station */
-#define MACSEC_TCI_SC      0x20 /* SCI present */
-#define MACSEC_TCI_SCB     0x10 /* epon */
-#define MACSEC_TCI_E       0x08 /* encryption */
-#define MACSEC_TCI_C       0x04 /* changed text */
-#define MACSEC_AN_MASK     0x03 /* association number */
-#define MACSEC_TCI_CONFID  (MACSEC_TCI_E | MACSEC_TCI_C)
-
 /* minimum secure data length deemed "not short", see IEEE 802.1AE-2006 9.7 */
 #define MIN_NON_SHORT_LEN 48
 
 #define GCM_AES_IV_LEN 12
-#define DEFAULT_ICV_LEN 16
 
 #define for_each_rxsc(secy, sc)				\
 	for (sc = rcu_dereference_bh(secy->rx_sc);	\
@@ -242,14 +230,6 @@ static struct macsec_cb *macsec_skb_cb(struct sk_buff *skb)
 #define DEFAULT_ENCRYPT false
 #define DEFAULT_ENCODING_SA 0
 
-static bool send_sci(const struct macsec_secy *secy)
-{
-	const struct macsec_tx_sc *tx_sc = &secy->tx_sc;
-
-	return tx_sc->send_sci ||
-		(secy->n_rx_sc > 1 && !tx_sc->end_station && !tx_sc->scb);
-}
-
 static sci_t make_sci(const u8 *addr, __be16 port)
 {
 	sci_t sci;
@@ -314,7 +294,7 @@ static void macsec_fill_sectag(struct macsec_eth_header *h,
 	/* with GCM, C/E clear for !encrypt, both set for encrypt */
 	if (tx_sc->encrypt)
 		h->tci_an |= MACSEC_TCI_CONFID;
-	else if (secy->icv_len != DEFAULT_ICV_LEN)
+	else if (secy->icv_len != MACSEC_DEFAULT_ICV_LEN)
 		h->tci_an |= MACSEC_TCI_C;
 
 	h->tci_an |= tx_sc->encoding_sa;
@@ -632,7 +612,7 @@ static struct sk_buff *macsec_encrypt(struct sk_buff *skb,
 
 	unprotected_len = skb->len;
 	eth = eth_hdr(skb);
-	sci_present = send_sci(secy);
+	sci_present = macsec_send_sci(secy);
 	hh = skb_push(skb, macsec_extra_len(sci_present));
 	memmove(hh, eth, 2 * ETH_ALEN);
 
@@ -1266,7 +1246,7 @@ static rx_handler_result_t macsec_handle_frame(struct sk_buff **pskb)
 	/* 10.6.1 if the SC is not found */
 	cbit = !!(hdr->tci_an & MACSEC_TCI_C);
 	if (!cbit)
-		macsec_finalize_skb(skb, DEFAULT_ICV_LEN,
+		macsec_finalize_skb(skb, MACSEC_DEFAULT_ICV_LEN,
 				    macsec_extra_len(macsec_skb_cb(skb)->has_sci));
 
 	list_for_each_entry_rcu(macsec, &rxd->secys, secys) {
@@ -4001,7 +3981,7 @@ static int macsec_newlink(struct net *net, struct net_device *dev,
 {
 	struct macsec_dev *macsec = macsec_priv(dev);
 	rx_handler_func_t *rx_handler;
-	u8 icv_len = DEFAULT_ICV_LEN;
+	u8 icv_len = MACSEC_DEFAULT_ICV_LEN;
 	struct net_device *real_dev;
 	int err, mtu;
 	sci_t sci;
@@ -4125,7 +4105,7 @@ static int macsec_validate_attr(struct nlattr *tb[], struct nlattr *data[],
 				struct netlink_ext_ack *extack)
 {
 	u64 csid = MACSEC_DEFAULT_CIPHER_ID;
-	u8 icv_len = DEFAULT_ICV_LEN;
+	u8 icv_len = MACSEC_DEFAULT_ICV_LEN;
 	int flag;
 	bool es, scb, sci;
 
@@ -4137,7 +4117,7 @@ static int macsec_validate_attr(struct nlattr *tb[], struct nlattr *data[],
 
 	if (data[IFLA_MACSEC_ICV_LEN]) {
 		icv_len = nla_get_u8(data[IFLA_MACSEC_ICV_LEN]);
-		if (icv_len != DEFAULT_ICV_LEN) {
+		if (icv_len != MACSEC_DEFAULT_ICV_LEN) {
 			char dummy_key[DEFAULT_SAK_LEN] = { 0 };
 			struct crypto_aead *dummy_tfm;
 
diff --git a/include/net/macsec.h b/include/net/macsec.h
index fcbca963c04d..c5a18e7b386a 100644
--- a/include/net/macsec.h
+++ b/include/net/macsec.h
@@ -17,6 +17,19 @@
 #define MACSEC_SALT_LEN 12
 #define MACSEC_NUM_AN 4 /* 2 bits for the association number */
 
+#define MACSEC_SCI_LEN 8
+
+#define MACSEC_TCI_VERSION 0x80
+#define MACSEC_TCI_ES      0x40 /* end station */
+#define MACSEC_TCI_SC      0x20 /* SCI present */
+#define MACSEC_TCI_SCB     0x10 /* epon */
+#define MACSEC_TCI_E       0x08 /* encryption */
+#define MACSEC_TCI_C       0x04 /* changed text */
+#define MACSEC_AN_MASK     0x03 /* association number */
+#define MACSEC_TCI_CONFID  (MACSEC_TCI_E | MACSEC_TCI_C)
+
+#define MACSEC_DEFAULT_ICV_LEN 16
+
 typedef u64 __bitwise sci_t;
 typedef u32 __bitwise ssci_t;
 
@@ -295,5 +308,12 @@ struct macsec_ops {
 };
 
 void macsec_pn_wrapped(struct macsec_secy *secy, struct macsec_tx_sa *tx_sa);
+static inline bool macsec_send_sci(const struct macsec_secy *secy)
+{
+	const struct macsec_tx_sc *tx_sc = &secy->tx_sc;
+
+	return tx_sc->send_sci ||
+		(secy->n_rx_sc > 1 && !tx_sc->end_station && !tx_sc->scb);
+}
 
 #endif /* _NET_MACSEC_H_ */
-- 
2.25.4


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH net-next v1 00/3] Introduce MACsec offload SKB extension
  2022-05-08  9:09 [PATCH net-next v1 00/3] Introduce MACsec offload SKB extension Lior Nahmanson
                   ` (2 preceding siblings ...)
  2022-05-08  9:09 ` [PATCH net-next v1 03/03] net/macsec: Move some code for sharing with various drivers that implements offload Lior Nahmanson
@ 2022-05-08 15:40 ` Leon Romanovsky
  2022-05-09  6:41   ` Lior Nahmanson
  3 siblings, 1 reply; 8+ messages in thread
From: Leon Romanovsky @ 2022-05-08 15:40 UTC (permalink / raw)
  To: Lior Nahmanson; +Cc: edumazet, kuba, pabeni, davem, netdev

On Sun, May 08, 2022 at 12:09:51PM +0300, Lior Nahmanson wrote:
> This patchset introduces MACsec SKB extension to lay the ground
> for MACsec HW offload.
> 
> MACsec is an IEEE standard (IEEE 802.1AE) for MAC security.
> It defines a way to establish a protocol independent connection
> between two hosts with data confidentiality, authenticity and/or
> integrity, using GCM-AES. MACsec operates on the Ethernet layer and
> as such is a layer 2 protocol, which means it’s designed to secure
> traffic within a layer 2 network, including DHCP or ARP requests.
> 
> Linux has a software implementation of the MACsec standard and
> HW offloading support.
> The offloading is re-using the logic, netlink API and data
> structures of the existing MACsec software implementation.
> 
> For Tx:
> In the current MACsec offload implementation, MACsec interfaces are
> sharing the same MAC address of their parent interface by default.
> Therefore, HW can't distinguish if a packet was sent from MACsec
> interface and need to be offloaded or not.
> Also, it can't distinguish from which MACsec interface it was sent in
> case there are multiple MACsec interface with the same MAC address.
> 
> Used SKB extension, so SW can mark if a packet is needed to be offloaded
> and use the SCI, which is unique value for each MACsec interface,
> to notify the HW from which MACsec interface the packet is sent.
> 
> For Rx:
> Like in the Tx changes, packet that don't have SecTAG
> header aren't necessary been offloaded by the HW.
> Therefore, the MACsec driver needs to distinguish if the packet
> was offloaded or not and handle accordingly.
> Moreover, if there are more than one MACsec device with the same MAC
> address as in the packet's destination MAC, the packet will forward only
> to this device and only to the desired one.
> 
> Used SKB extension and marking it by the HW if the packet was offloaded
> and to which MACsec offload device it belongs according to the packet's
> SCI.
> 
> 1) patch 0001-0002, Add support to SKB extension in MACsec code:
> net/macsec: Add MACsec skb extension Tx Data path support
> net/macsec: Add MACsec skb extension Rx Data path support
> 
> 2) patch 0003, Move some MACsec driver code for sharing with various
> drivers that implements offload:
> net/macsec: Move some code for sharing with various drivers that
> implements offload

Can you please post diffstat and patch list of the series?
As a reply to this cover letter.

As an example:
https://lore.kernel.org/netdev/20220508153049.427227-1-andrew@lunn.ch/T/#m3c6fbfaa6c4e8c841e8bbb7e8953daefd2a53cd9

Thanks

^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: [PATCH net-next v1 00/3] Introduce MACsec offload SKB extension
  2022-05-08 15:40 ` [PATCH net-next v1 00/3] Introduce MACsec offload SKB extension Leon Romanovsky
@ 2022-05-09  6:41   ` Lior Nahmanson
  0 siblings, 0 replies; 8+ messages in thread
From: Lior Nahmanson @ 2022-05-09  6:41 UTC (permalink / raw)
  To: Leon Romanovsky; +Cc: edumazet, kuba, pabeni, davem, netdev

 > On Sun, May 08, 2022 at 12:09:51PM +0300, Lior Nahmanson wrote:
> > This patchset introduces MACsec SKB extension to lay the ground for
> > MACsec HW offload.
> >
> > MACsec is an IEEE standard (IEEE 802.1AE) for MAC security.
> > It defines a way to establish a protocol independent connection
> > between two hosts with data confidentiality, authenticity and/or
> > integrity, using GCM-AES. MACsec operates on the Ethernet layer and as
> > such is a layer 2 protocol, which means it’s designed to secure
> > traffic within a layer 2 network, including DHCP or ARP requests.
> >
> > Linux has a software implementation of the MACsec standard and HW
> > offloading support.
> > The offloading is re-using the logic, netlink API and data structures
> > of the existing MACsec software implementation.
> >
> > For Tx:
> > In the current MACsec offload implementation, MACsec interfaces are
> > sharing the same MAC address of their parent interface by default.
> > Therefore, HW can't distinguish if a packet was sent from MACsec
> > interface and need to be offloaded or not.
> > Also, it can't distinguish from which MACsec interface it was sent in
> > case there are multiple MACsec interface with the same MAC address.
> >
> > Used SKB extension, so SW can mark if a packet is needed to be
> > offloaded and use the SCI, which is unique value for each MACsec
> > interface, to notify the HW from which MACsec interface the packet is
> sent.
> >
> > For Rx:
> > Like in the Tx changes, packet that don't have SecTAG header aren't
> > necessary been offloaded by the HW.
> > Therefore, the MACsec driver needs to distinguish if the packet was
> > offloaded or not and handle accordingly.
> > Moreover, if there are more than one MACsec device with the same MAC
> > address as in the packet's destination MAC, the packet will forward
> > only to this device and only to the desired one.
> >
> > Used SKB extension and marking it by the HW if the packet was
> > offloaded and to which MACsec offload device it belongs according to
> > the packet's SCI.
> >
> > 1) patch 0001-0002, Add support to SKB extension in MACsec code:
> > net/macsec: Add MACsec skb extension Tx Data path support
> > net/macsec: Add MACsec skb extension Rx Data path support
> >
> > 2) patch 0003, Move some MACsec driver code for sharing with various
> > drivers that implements offload:
> > net/macsec: Move some code for sharing with various drivers that
> > implements offload
> 
> Can you please post diffstat and patch list of the series?
> As a reply to this cover letter.
> 
> As an example:
> https://lore.kernel.org/netdev/20220508153049.427227-1-
> andrew@lunn.ch/T/#m3c6fbfaa6c4e8c841e8bbb7e8953daefd2a53cd9
> 
> Thanks

   Lior Nahmanson (3):
    net/macsec: Add MACsec skb extension Tx Data path support
    net/macsec: Add MACsec skb extension Rx Data path support
    net/macsec: Move some code for sharing with various drivers that
      implements offload
  
   drivers/net/Kconfig    |  1 +
   drivers/net/macsec.c   | 45 +++++++++++++++++-------------------------
   include/linux/skbuff.h |  3 +++
   include/net/macsec.h   | 26 ++++++++++++++++++++++++
   net/core/skbuff.c      |  7 +++++++
   5 files changed, 55 insertions(+), 27 deletions(-)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH net-next v1 01/03] net/macsec: Add MACsec skb extension Tx Data path support
  2022-05-08  9:09 ` [PATCH net-next v1 01/03] net/macsec: Add MACsec skb extension Tx Data path support Lior Nahmanson
@ 2022-05-10  9:23   ` Paolo Abeni
  2022-05-19  6:26     ` Lior Nahmanson
  0 siblings, 1 reply; 8+ messages in thread
From: Paolo Abeni @ 2022-05-10  9:23 UTC (permalink / raw)
  To: Lior Nahmanson, edumazet, kuba
  Cc: davem, netdev, Raed Salem, Jiri Pirko, Ben Ben-Ishay

On Sun, 2022-05-08 at 12:09 +0300, Lior Nahmanson wrote:
> In the current MACsec offload implementation, MACsec interfaces are
> sharing the same MAC address of their parent interface by default.
> Therefore, HW can't distinguish if a packet was sent from MACsec
> interface and need to be offloaded or not.
> Also, it can't distinguish from which MACsec interface it was sent in
> case there are multiple MACsec interface with the same MAC address.
> 
> Used SKB extension, so SW can mark if a packet is needed to be offloaded
> and use the SCI, which is unique value for each MACsec interface,
> to notify the HW from which MACsec interface the packet is sent.
> 
> Signed-off-by: Lior Nahmanson <liorna@nvidia.com>
> Reviewed-by: Raed Salem <raeds@nvidia.com>
> Reviewed-by: Jiri Pirko <jiri@nvidia.com>
> Reviewed-by: Ben Ben-Ishay <benishay@nvidia.com>
> ---
>  drivers/net/Kconfig    | 1 +
>  drivers/net/macsec.c   | 5 +++++
>  include/linux/skbuff.h | 3 +++
>  include/net/macsec.h   | 6 ++++++
>  net/core/skbuff.c      | 7 +++++++
>  5 files changed, 22 insertions(+)
> 
> diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
> index b2a4f998c180..6c9a950b7010 100644
> --- a/drivers/net/Kconfig
> +++ b/drivers/net/Kconfig
> @@ -313,6 +313,7 @@ config MACSEC
>  	select CRYPTO_AES
>  	select CRYPTO_GCM
>  	select GRO_CELLS
> +	select SKB_EXTENSIONS
>  	help
>  	   MACsec is an encryption standard for Ethernet.
>  
> diff --git a/drivers/net/macsec.c b/drivers/net/macsec.c
> index 832f09ac075e..0960339e2442 100644
> --- a/drivers/net/macsec.c
> +++ b/drivers/net/macsec.c
> @@ -3377,6 +3377,11 @@ static netdev_tx_t macsec_start_xmit(struct sk_buff *skb,
>  	int ret, len;
>  
>  	if (macsec_is_offloaded(netdev_priv(dev))) {
> +		struct macsec_ext *secext = skb_ext_add(skb, SKB_EXT_MACSEC);
> +
> +		secext->sci = secy->sci;
> +		secext->offloaded = true;
> +
>  		skb->dev = macsec->real_dev;
>  		return dev_queue_xmit(skb);
>  	}
> diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
> index 84d78df60453..4ee71c7848bf 100644
> --- a/include/linux/skbuff.h
> +++ b/include/linux/skbuff.h
> @@ -4552,6 +4552,9 @@ enum skb_ext_id {
>  #endif
>  #if IS_ENABLED(CONFIG_MCTP_FLOWS)
>  	SKB_EXT_MCTP,
> +#endif
> +#if IS_ENABLED(CONFIG_MACSEC)
> +	SKB_EXT_MACSEC,
>  #endif
>  	SKB_EXT_NUM, /* must be last */
>  };
> diff --git a/include/net/macsec.h b/include/net/macsec.h
> index d6fa6b97f6ef..fcbca963c04d 100644
> --- a/include/net/macsec.h
> +++ b/include/net/macsec.h
> @@ -20,6 +20,12 @@
>  typedef u64 __bitwise sci_t;
>  typedef u32 __bitwise ssci_t;
>  
> +/* MACsec sk_buff extension data */
> +struct macsec_ext {
> +	sci_t sci;
> +	bool offloaded;

It looks like the bool is not used/it's always true when the extension
is attached? If so it's better to drop it and use the extension
presence as the flag.

BTW have you considered other options other then the skb extensions?
e.g. could you use skb_metadata() here?

Otherwise I think you need explicitly to take care of this extension at
the GRO layer, see commit 8550ff8d8c75

Thanks!

Paolo


^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: [PATCH net-next v1 01/03] net/macsec: Add MACsec skb extension Tx Data path support
  2022-05-10  9:23   ` Paolo Abeni
@ 2022-05-19  6:26     ` Lior Nahmanson
  0 siblings, 0 replies; 8+ messages in thread
From: Lior Nahmanson @ 2022-05-19  6:26 UTC (permalink / raw)
  To: Paolo Abeni, edumazet, kuba
  Cc: davem, netdev, Raed Salem, Jiri Pirko, Ben Ben Ishay

> -----Original Message-----
> From: Paolo Abeni <pabeni@redhat.com>
> Sent: Tuesday, May 10, 2022 12:23 PM
> To: Lior Nahmanson <liorna@nvidia.com>; edumazet@google.com;
> kuba@kernel.org
> Cc: davem@davemloft.net; netdev@vger.kernel.org; Raed Salem
> <raeds@nvidia.com>; Jiri Pirko <jiri@nvidia.com>; Ben Ben Ishay
> <benishay@nvidia.com>
> Subject: Re: [PATCH net-next v1 01/03] net/macsec: Add MACsec skb
> extension Tx Data path support
> 
> External email: Use caution opening links or attachments
> 
> 
> On Sun, 2022-05-08 at 12:09 +0300, Lior Nahmanson wrote:
> > In the current MACsec offload implementation, MACsec interfaces are
> > sharing the same MAC address of their parent interface by default.
> > Therefore, HW can't distinguish if a packet was sent from MACsec
> > interface and need to be offloaded or not.
> > Also, it can't distinguish from which MACsec interface it was sent in
> > case there are multiple MACsec interface with the same MAC address.
> >
> > Used SKB extension, so SW can mark if a packet is needed to be
> > offloaded and use the SCI, which is unique value for each MACsec
> > interface, to notify the HW from which MACsec interface the packet is
> sent.
> >
> > Signed-off-by: Lior Nahmanson <liorna@nvidia.com>
> > Reviewed-by: Raed Salem <raeds@nvidia.com>
> > Reviewed-by: Jiri Pirko <jiri@nvidia.com>
> > Reviewed-by: Ben Ben-Ishay <benishay@nvidia.com>
> > ---
> >  drivers/net/Kconfig    | 1 +
> >  drivers/net/macsec.c   | 5 +++++
> >  include/linux/skbuff.h | 3 +++
> >  include/net/macsec.h   | 6 ++++++
> >  net/core/skbuff.c      | 7 +++++++
> >  5 files changed, 22 insertions(+)
> >
> > diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig index
> > b2a4f998c180..6c9a950b7010 100644
> > --- a/drivers/net/Kconfig
> > +++ b/drivers/net/Kconfig
> > @@ -313,6 +313,7 @@ config MACSEC
> >       select CRYPTO_AES
> >       select CRYPTO_GCM
> >       select GRO_CELLS
> > +     select SKB_EXTENSIONS
> >       help
> >          MACsec is an encryption standard for Ethernet.
> >
> > diff --git a/drivers/net/macsec.c b/drivers/net/macsec.c index
> > 832f09ac075e..0960339e2442 100644
> > --- a/drivers/net/macsec.c
> > +++ b/drivers/net/macsec.c
> > @@ -3377,6 +3377,11 @@ static netdev_tx_t macsec_start_xmit(struct
> sk_buff *skb,
> >       int ret, len;
> >
> >       if (macsec_is_offloaded(netdev_priv(dev))) {
> > +             struct macsec_ext *secext = skb_ext_add(skb,
> > + SKB_EXT_MACSEC);
> > +
> > +             secext->sci = secy->sci;
> > +             secext->offloaded = true;
> > +
> >               skb->dev = macsec->real_dev;
> >               return dev_queue_xmit(skb);
> >       }
> > diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index
> > 84d78df60453..4ee71c7848bf 100644
> > --- a/include/linux/skbuff.h
> > +++ b/include/linux/skbuff.h
> > @@ -4552,6 +4552,9 @@ enum skb_ext_id {  #endif  #if
> > IS_ENABLED(CONFIG_MCTP_FLOWS)
> >       SKB_EXT_MCTP,
> > +#endif
> > +#if IS_ENABLED(CONFIG_MACSEC)
> > +     SKB_EXT_MACSEC,
> >  #endif
> >       SKB_EXT_NUM, /* must be last */
> >  };
> > diff --git a/include/net/macsec.h b/include/net/macsec.h index
> > d6fa6b97f6ef..fcbca963c04d 100644
> > --- a/include/net/macsec.h
> > +++ b/include/net/macsec.h
> > @@ -20,6 +20,12 @@
> >  typedef u64 __bitwise sci_t;
> >  typedef u32 __bitwise ssci_t;
> >
> > +/* MACsec sk_buff extension data */
> > +struct macsec_ext {
> > +     sci_t sci;
> > +     bool offloaded;
> 
> It looks like the bool is not used/it's always true when the extension is
> attached? If so it's better to drop it and use the extension presence as the
> flag.

It's true for Tx but not for Rx.
The bool of the extension is false for any un-MACsec packet that is received by the NIC when the MACsec offload is on,
the MACsec layer should use this data and ignore those packets by forwarding them to the parent device.

> 
> BTW have you considered other options other then the skb extensions?
> e.g. could you use skb_metadata() here?

Other security offload like IPsec offload implemented in the same way,
so it looks like using SKB extension is the preferable approach for such use-cases.

> 
> Otherwise I think you need explicitly to take care of this extension at the
> GRO layer, see commit 8550ff8d8c75

Ack, will add it.

> 
> Thanks!
> 
> Paolo

thanks for the review.
apologize for the late respond.


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-05-19  6:27 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-08  9:09 [PATCH net-next v1 00/3] Introduce MACsec offload SKB extension Lior Nahmanson
2022-05-08  9:09 ` [PATCH net-next v1 01/03] net/macsec: Add MACsec skb extension Tx Data path support Lior Nahmanson
2022-05-10  9:23   ` Paolo Abeni
2022-05-19  6:26     ` Lior Nahmanson
2022-05-08  9:09 ` [PATCH net-next v1 02/03] net/macsec: Add MACsec skb extension Rx " Lior Nahmanson
2022-05-08  9:09 ` [PATCH net-next v1 03/03] net/macsec: Move some code for sharing with various drivers that implements offload Lior Nahmanson
2022-05-08 15:40 ` [PATCH net-next v1 00/3] Introduce MACsec offload SKB extension Leon Romanovsky
2022-05-09  6:41   ` Lior Nahmanson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).