aboutsummaryrefslogtreecommitdiffstats
path: root/net/tls/tls_main.c
diff options
context:
space:
mode:
authorBoris Pismenny <borisp@mellanox.com>2018-07-13 07:33:43 -0400
committerDavid S. Miller <davem@davemloft.net>2018-07-16 03:13:11 -0400
commit4799ac81e52a72a6404827bf2738337bb581a174 (patch)
tree0d75fbecd761c35507d05122d9d26855c7e6c4de /net/tls/tls_main.c
parentb190a587c634a8559e4ceabeb0468e93db49789a (diff)
tls: Add rx inline crypto offload
This patch completes the generic infrastructure to offload TLS crypto to a network device. It enables the kernel to skip decryption and authentication of some skbs marked as decrypted by the NIC. In the fast path, all packets received are decrypted by the NIC and the performance is comparable to plain TCP. This infrastructure doesn't require a TCP offload engine. Instead, the NIC only decrypts packets that contain the expected TCP sequence number. Out-Of-Order TCP packets are provided unmodified. As a result, at the worst case a received TLS record consists of both plaintext and ciphertext packets. These partially decrypted records must be reencrypted, only to be decrypted. The notable differences between SW KTLS Rx and this offload are as follows: 1. Partial decryption - Software must handle the case of a TLS record that was only partially decrypted by HW. This can happen due to packet reordering. 2. Resynchronization - tls_read_size calls the device driver to resynchronize HW after HW lost track of TLS record framing in the TCP stream. Signed-off-by: Boris Pismenny <borisp@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/tls/tls_main.c')
-rw-r--r--net/tls/tls_main.c32
1 files changed, 20 insertions, 12 deletions
diff --git a/net/tls/tls_main.c b/net/tls/tls_main.c
index 301f22430469..b09867c8b817 100644
--- a/net/tls/tls_main.c
+++ b/net/tls/tls_main.c
@@ -51,15 +51,6 @@ enum {
51 TLSV6, 51 TLSV6,
52 TLS_NUM_PROTS, 52 TLS_NUM_PROTS,
53}; 53};
54enum {
55 TLS_BASE,
56 TLS_SW,
57#ifdef CONFIG_TLS_DEVICE
58 TLS_HW,
59#endif
60 TLS_HW_RECORD,
61 TLS_NUM_CONFIG,
62};
63 54
64static struct proto *saved_tcpv6_prot; 55static struct proto *saved_tcpv6_prot;
65static DEFINE_MUTEX(tcpv6_prot_mutex); 56static DEFINE_MUTEX(tcpv6_prot_mutex);
@@ -290,7 +281,10 @@ static void tls_sk_proto_close(struct sock *sk, long timeout)
290 } 281 }
291 282
292#ifdef CONFIG_TLS_DEVICE 283#ifdef CONFIG_TLS_DEVICE
293 if (ctx->tx_conf != TLS_HW) { 284 if (ctx->rx_conf == TLS_HW)
285 tls_device_offload_cleanup_rx(sk);
286
287 if (ctx->tx_conf != TLS_HW && ctx->rx_conf != TLS_HW) {
294#else 288#else
295 { 289 {
296#endif 290#endif
@@ -470,8 +464,16 @@ static int do_tls_setsockopt_conf(struct sock *sk, char __user *optval,
470 conf = TLS_SW; 464 conf = TLS_SW;
471 } 465 }
472 } else { 466 } else {
473 rc = tls_set_sw_offload(sk, ctx, 0); 467#ifdef CONFIG_TLS_DEVICE
474 conf = TLS_SW; 468 rc = tls_set_device_offload_rx(sk, ctx);
469 conf = TLS_HW;
470 if (rc) {
471#else
472 {
473#endif
474 rc = tls_set_sw_offload(sk, ctx, 0);
475 conf = TLS_SW;
476 }
475 } 477 }
476 478
477 if (rc) 479 if (rc)
@@ -629,6 +631,12 @@ static void build_protos(struct proto prot[TLS_NUM_CONFIG][TLS_NUM_CONFIG],
629 prot[TLS_HW][TLS_SW] = prot[TLS_BASE][TLS_SW]; 631 prot[TLS_HW][TLS_SW] = prot[TLS_BASE][TLS_SW];
630 prot[TLS_HW][TLS_SW].sendmsg = tls_device_sendmsg; 632 prot[TLS_HW][TLS_SW].sendmsg = tls_device_sendmsg;
631 prot[TLS_HW][TLS_SW].sendpage = tls_device_sendpage; 633 prot[TLS_HW][TLS_SW].sendpage = tls_device_sendpage;
634
635 prot[TLS_BASE][TLS_HW] = prot[TLS_BASE][TLS_SW];
636
637 prot[TLS_SW][TLS_HW] = prot[TLS_SW][TLS_SW];
638
639 prot[TLS_HW][TLS_HW] = prot[TLS_HW][TLS_SW];
632#endif 640#endif
633 641
634 prot[TLS_HW_RECORD][TLS_HW_RECORD] = *base; 642 prot[TLS_HW_RECORD][TLS_HW_RECORD] = *base;