Skip to content
  • Paolo Abeni's avatar
    pktgen: do not sleep with the thread lock held. · b23be64f
    Paolo Abeni authored
    [ Upstream commit 720f1de4 ]
    
    Currently, the process issuing a "start" command on the pktgen procfs
    interface, acquires the pktgen thread lock and never release it, until
    all pktgen threads are completed. The above can blocks indefinitely any
    other pktgen command and any (even unrelated) netdevice removal - as
    the pktgen netdev notifier acquires the same lock.
    
    The issue is demonstrated by the following script, reported by Matteo:
    
    ip -b - <<'EOF'
    	link add type dummy
    	link add type veth
    	link set dummy0 up
    EOF
    modprobe pktgen
    echo reset >/proc/net/pktgen/pgctrl
    {
    	echo rem_device_all
    	echo add_device dummy0
    } >/proc/net/pktgen/kpktgend_0
    echo count 0 >/proc/net/pktgen/dummy0
    echo start >/proc/net/pktgen/pgctrl &
    sleep 1
    rmmod veth
    
    Fix the above releasing the thread lock around the sleep call.
    
    Additionally we must prevent racing with forcefull rmmod - as the
    thread lock no more protects from them. Instead, acquire a self-reference
    before waiting for any thread. As a side effect, running
    
    rmmod pktgen
    
    while some thread is running now fails with "module in use" error,
    before this patch such command hanged indefinitely.
    
    Note: the issue predates the commit reported in the fixes tag, but
    this fix can't be applied before the mentioned commit.
    
    v1 -> v2:
     - no need to check for thread existence after flipping the lock,
       pktgen threads are freed only at net exit time
     -
    
    Fixes: 6146e6a4
    
     ("[PKTGEN]: Removes thread_{un,}lock() macros.")
    Reported-and-tested-by: default avatarMatteo Croce <mcroce@redhat.com>
    Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
    Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
    Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    b23be64f