From mboxrd@z Thu Jan 1 00:00:00 1970 From: Hannes Frederic Sowa Subject: Re: [PATCH net] Revert "tcp: switch tcp_fastopen key generation to net_get_random_once" Date: Thu, 18 Jun 2015 11:32:33 +0200 Message-ID: <1434619953.7926.10.camel@stressinduktion.org> References: <1434587299-60271-1-git-send-email-cpaasch@apple.com> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Cc: David Miller To: Christoph Paasch , netdev@vger.kernel.org Return-path: Received: from out5-smtp.messagingengine.com ([66.111.4.29]:39636 "EHLO out5-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753002AbbFRJch (ORCPT ); Thu, 18 Jun 2015 05:32:37 -0400 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id DDEBA20BB8 for ; Thu, 18 Jun 2015 05:32:36 -0400 (EDT) In-Reply-To: <1434587299-60271-1-git-send-email-cpaasch@apple.com> Sender: netdev-owner@vger.kernel.org List-ID: Hello Christoph, On Wed, 2015-06-17 at 17:28 -0700, Christoph Paasch wrote: > This reverts commit 222e83d2e0aecb6a5e8d42b1a8d51332a1eba960. > > tcp_fastopen_reset_cipher really cannot be called from interrupt > context. It allocates the tcp_fastopen_context with GFP_KERNEL and > calls crypto_alloc_cipher, which allocates all kind of stuff with > GFP_KERNEL. > > Thus, we might sleep when the key-generation is triggered by an > incoming TFO cookie-request which would then happen in interrupt- > context, as shown by enabling CONFIG_DEBUG_ATOMIC_SLEEP: > > [ 36.001813] BUG: sleeping function called from invalid context at > mm/slub.c:1266 > [ 36.003624] in_atomic(): 1, irqs_disabled(): 0, pid: 1016, name: > packetdrill > [ 36.004859] CPU: 1 PID: 1016 Comm: packetdrill Not tainted 4.1.0-rc7 #14 > [ 36.006085] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel > -1.7.5-0-ge51488c-20140602_164612-nilsson.home.kraxel.org 04/01/2014 > [ 36.008250] 00000000000004f2 ffff88007f8838a8 ffffffff8171d53a > ffff880075a084a8 > [ 36.009630] ffff880075a08000 ffff88007f8838c8 ffffffff810967d3 > ffff88007f883928 > [ 36.011076] 0000000000000000 ffff88007f8838f8 ffffffff81096892 > ffff88007f89be00 > [ 36.012494] Call Trace: > [ 36.012953] [] dump_stack+0x4f/0x6d > [ 36.014085] [] ___might_sleep+0x103/0x170 > [ 36.015117] [] __might_sleep+0x52/0x90 > [ 36.016117] [] kmem_cache_alloc_trace+0x47/0x190 > [ 36.017266] [] ? tcp_fastopen_reset_cipher+0x42/0x130 > [ 36.018485] [] tcp_fastopen_reset_cipher+0x42/0x130 > [ 36.019679] [] tcp_fastopen_init_key_once+0x61/0x70 > [ 36.020884] [] __tcp_fastopen_cookie_gen+0x1c/0x60 > [ 36.022058] [] tcp_try_fastopen+0x58f/0x730 > [ 36.023118] [] tcp_conn_request+0x3e8/0x7b0 > [ 36.024185] [] ? __module_text_address+0x12/0x60 > [ 36.025327] [] tcp_v4_conn_request+0x51/0x60 > [ 36.026410] [] tcp_rcv_state_process+0x190/0xda0 > [ 36.027556] [] ? __inet_lookup_established+0x47/0x170 > [ 36.028784] [] tcp_v4_do_rcv+0x16d/0x3d0 > [ 36.029832] [] ? security_sock_rcv_skb+0x16/0x20 > [ 36.030936] [] tcp_v4_rcv+0x77a/0x7b0 > [ 36.031875] [] ? iptable_filter_hook+0x33/0x70 > [ 36.032953] [] ip_local_deliver_finish+0x92/0x1f0 > [ 36.034065] [] ip_local_deliver+0x9a/0xb0 > [ 36.035069] [] ? ip_rcv+0x3d0/0x3d0 > [ 36.035963] [] ip_rcv_finish+0x119/0x330 > [ 36.036950] [] ip_rcv+0x2e7/0x3d0 > [ 36.037847] [] __netif_receive_skb_core+0x552/0x930 > [ 36.038994] [] __netif_receive_skb+0x27/0x70 > [ 36.040033] [] process_backlog+0xd2/0x1f0 > [ 36.041025] [] net_rx_action+0x122/0x310 > [ 36.042007] [] __do_softirq+0x103/0x2f0 > [ 36.042978] [] do_softirq_own_stack+0x1c/0x30 > > There does not seem to be a better way to handle this. We could try > to make the call to kmalloc and crypto_alloc_cipher during bootup, and > then generate the random value only on-the-fly (when the first TFO-SYN > comes in) with net_get_random_once in order to have the better entropy > that comes with doing the late initialisation of the random value. But > that's probably net-next material. can't we simply move the net_get_random_once to the TCP_FASTOPEN setsockopt and sendmsg(MSG_FASTOPEN) path, so those allocations still happen in process context but we still defer the extraction of entropy as long as posible? Thanks, Hannes