Skip to content

Commit 5bb4c45

Browse files
jsitnickidavem330
authored andcommitted
net/tls: Read sk_prot once when building tls proto ops
Apart from being a "tremendous" win when it comes to generated machine code (see bloat-o-meter output for x86-64 below) this mainly prepares ground for annotating access to sk_prot with READ_ONCE, so that we don't pepper the code with access annotations and needlessly repeat loads. add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-46 (-46) Function old new delta tls_init 851 805 -46 Total: Before=21063, After=21017, chg -0.22% Signed-off-by: Jakub Sitnicki <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent f13fe3e commit 5bb4c45

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

net/tls/tls_main.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -628,24 +628,25 @@ struct tls_context *tls_ctx_create(struct sock *sk)
628628
static void tls_build_proto(struct sock *sk)
629629
{
630630
int ip_ver = sk->sk_family == AF_INET6 ? TLSV6 : TLSV4;
631+
const struct proto *prot = sk->sk_prot;
631632

632633
/* Build IPv6 TLS whenever the address of tcpv6 _prot changes */
633634
if (ip_ver == TLSV6 &&
634-
unlikely(sk->sk_prot != smp_load_acquire(&saved_tcpv6_prot))) {
635+
unlikely(prot != smp_load_acquire(&saved_tcpv6_prot))) {
635636
mutex_lock(&tcpv6_prot_mutex);
636-
if (likely(sk->sk_prot != saved_tcpv6_prot)) {
637-
build_protos(tls_prots[TLSV6], sk->sk_prot);
638-
smp_store_release(&saved_tcpv6_prot, sk->sk_prot);
637+
if (likely(prot != saved_tcpv6_prot)) {
638+
build_protos(tls_prots[TLSV6], prot);
639+
smp_store_release(&saved_tcpv6_prot, prot);
639640
}
640641
mutex_unlock(&tcpv6_prot_mutex);
641642
}
642643

643644
if (ip_ver == TLSV4 &&
644-
unlikely(sk->sk_prot != smp_load_acquire(&saved_tcpv4_prot))) {
645+
unlikely(prot != smp_load_acquire(&saved_tcpv4_prot))) {
645646
mutex_lock(&tcpv4_prot_mutex);
646-
if (likely(sk->sk_prot != saved_tcpv4_prot)) {
647-
build_protos(tls_prots[TLSV4], sk->sk_prot);
648-
smp_store_release(&saved_tcpv4_prot, sk->sk_prot);
647+
if (likely(prot != saved_tcpv4_prot)) {
648+
build_protos(tls_prots[TLSV4], prot);
649+
smp_store_release(&saved_tcpv4_prot, prot);
649650
}
650651
mutex_unlock(&tcpv4_prot_mutex);
651652
}

0 commit comments

Comments
 (0)