aboutsummaryrefslogtreecommitdiffstats
path: root/net/tls
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2018-12-20 13:53:28 -0500
committerDavid S. Miller <davem@davemloft.net>2018-12-20 14:53:36 -0500
commit2be09de7d6a06f58e768de1255a687c9aaa66606 (patch)
tree298f9e04caf105873d987e807eccba27710a49cc /net/tls
parent44a7b3b6e3a458f9549c2cc28e74ecdc470e42f1 (diff)
parent1d51b4b1d3f2db0d6d144175e31a84e472fbd99a (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net
Lots of conflicts, by happily all cases of overlapping changes, parallel adds, things of that nature. Thanks to Stephen Rothwell, Saeed Mahameed, and others for their guidance in these resolutions. Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/tls')
-rw-r--r--net/tls/tls_main.c44
1 files changed, 27 insertions, 17 deletions
diff --git a/net/tls/tls_main.c b/net/tls/tls_main.c
index 311cec8e533d..28887cf628b8 100644
--- a/net/tls/tls_main.c
+++ b/net/tls/tls_main.c
@@ -56,7 +56,7 @@ enum {
56static struct proto *saved_tcpv6_prot; 56static struct proto *saved_tcpv6_prot;
57static DEFINE_MUTEX(tcpv6_prot_mutex); 57static DEFINE_MUTEX(tcpv6_prot_mutex);
58static LIST_HEAD(device_list); 58static LIST_HEAD(device_list);
59static DEFINE_MUTEX(device_mutex); 59static DEFINE_SPINLOCK(device_spinlock);
60static struct proto tls_prots[TLS_NUM_PROTS][TLS_NUM_CONFIG][TLS_NUM_CONFIG]; 60static struct proto tls_prots[TLS_NUM_PROTS][TLS_NUM_CONFIG][TLS_NUM_CONFIG];
61static struct proto_ops tls_sw_proto_ops; 61static struct proto_ops tls_sw_proto_ops;
62 62
@@ -538,11 +538,14 @@ static struct tls_context *create_ctx(struct sock *sk)
538 struct inet_connection_sock *icsk = inet_csk(sk); 538 struct inet_connection_sock *icsk = inet_csk(sk);
539 struct tls_context *ctx; 539 struct tls_context *ctx;
540 540
541 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); 541 ctx = kzalloc(sizeof(*ctx), GFP_ATOMIC);
542 if (!ctx) 542 if (!ctx)
543 return NULL; 543 return NULL;
544 544
545 icsk->icsk_ulp_data = ctx; 545 icsk->icsk_ulp_data = ctx;
546 ctx->setsockopt = sk->sk_prot->setsockopt;
547 ctx->getsockopt = sk->sk_prot->getsockopt;
548 ctx->sk_proto_close = sk->sk_prot->close;
546 return ctx; 549 return ctx;
547} 550}
548 551
@@ -552,7 +555,7 @@ static int tls_hw_prot(struct sock *sk)
552 struct tls_device *dev; 555 struct tls_device *dev;
553 int rc = 0; 556 int rc = 0;
554 557
555 mutex_lock(&device_mutex); 558 spin_lock_bh(&device_spinlock);
556 list_for_each_entry(dev, &device_list, dev_list) { 559 list_for_each_entry(dev, &device_list, dev_list) {
557 if (dev->feature && dev->feature(dev)) { 560 if (dev->feature && dev->feature(dev)) {
558 ctx = create_ctx(sk); 561 ctx = create_ctx(sk);
@@ -570,7 +573,7 @@ static int tls_hw_prot(struct sock *sk)
570 } 573 }
571 } 574 }
572out: 575out:
573 mutex_unlock(&device_mutex); 576 spin_unlock_bh(&device_spinlock);
574 return rc; 577 return rc;
575} 578}
576 579
@@ -579,12 +582,17 @@ static void tls_hw_unhash(struct sock *sk)
579 struct tls_context *ctx = tls_get_ctx(sk); 582 struct tls_context *ctx = tls_get_ctx(sk);
580 struct tls_device *dev; 583 struct tls_device *dev;
581 584
582 mutex_lock(&device_mutex); 585 spin_lock_bh(&device_spinlock);
583 list_for_each_entry(dev, &device_list, dev_list) { 586 list_for_each_entry(dev, &device_list, dev_list) {
584 if (dev->unhash) 587 if (dev->unhash) {
588 kref_get(&dev->kref);
589 spin_unlock_bh(&device_spinlock);
585 dev->unhash(dev, sk); 590 dev->unhash(dev, sk);
591 kref_put(&dev->kref, dev->release);
592 spin_lock_bh(&device_spinlock);
593 }
586 } 594 }
587 mutex_unlock(&device_mutex); 595 spin_unlock_bh(&device_spinlock);
588 ctx->unhash(sk); 596 ctx->unhash(sk);
589} 597}
590 598
@@ -595,12 +603,17 @@ static int tls_hw_hash(struct sock *sk)
595 int err; 603 int err;
596 604
597 err = ctx->hash(sk); 605 err = ctx->hash(sk);
598 mutex_lock(&device_mutex); 606 spin_lock_bh(&device_spinlock);
599 list_for_each_entry(dev, &device_list, dev_list) { 607 list_for_each_entry(dev, &device_list, dev_list) {
600 if (dev->hash) 608 if (dev->hash) {
609 kref_get(&dev->kref);
610 spin_unlock_bh(&device_spinlock);
601 err |= dev->hash(dev, sk); 611 err |= dev->hash(dev, sk);
612 kref_put(&dev->kref, dev->release);
613 spin_lock_bh(&device_spinlock);
614 }
602 } 615 }
603 mutex_unlock(&device_mutex); 616 spin_unlock_bh(&device_spinlock);
604 617
605 if (err) 618 if (err)
606 tls_hw_unhash(sk); 619 tls_hw_unhash(sk);
@@ -675,9 +688,6 @@ static int tls_init(struct sock *sk)
675 rc = -ENOMEM; 688 rc = -ENOMEM;
676 goto out; 689 goto out;
677 } 690 }
678 ctx->setsockopt = sk->sk_prot->setsockopt;
679 ctx->getsockopt = sk->sk_prot->getsockopt;
680 ctx->sk_proto_close = sk->sk_prot->close;
681 691
682 /* Build IPv6 TLS whenever the address of tcpv6 _prot changes */ 692 /* Build IPv6 TLS whenever the address of tcpv6 _prot changes */
683 if (ip_ver == TLSV6 && 693 if (ip_ver == TLSV6 &&
@@ -699,17 +709,17 @@ out:
699 709
700void tls_register_device(struct tls_device *device) 710void tls_register_device(struct tls_device *device)
701{ 711{
702 mutex_lock(&device_mutex); 712 spin_lock_bh(&device_spinlock);
703 list_add_tail(&device->dev_list, &device_list); 713 list_add_tail(&device->dev_list, &device_list);
704 mutex_unlock(&device_mutex); 714 spin_unlock_bh(&device_spinlock);
705} 715}
706EXPORT_SYMBOL(tls_register_device); 716EXPORT_SYMBOL(tls_register_device);
707 717
708void tls_unregister_device(struct tls_device *device) 718void tls_unregister_device(struct tls_device *device)
709{ 719{
710 mutex_lock(&device_mutex); 720 spin_lock_bh(&device_spinlock);
711 list_del(&device->dev_list); 721 list_del(&device->dev_list);
712 mutex_unlock(&device_mutex); 722 spin_unlock_bh(&device_spinlock);
713} 723}
714EXPORT_SYMBOL(tls_unregister_device); 724EXPORT_SYMBOL(tls_unregister_device);
715 725