• Wen Yang's avatar
    pvcalls-front: Avoid get_free_pages(GFP_KERNEL) under spinlock · 06b919a5
    Wen Yang authored
    [ Upstream commit 9f51c05d ]
    
    The problem is that we call this with a spin lock held.
    The call tree is:
    pvcalls_front_accept() holds bedata->socket_lock.
        -> create_active()
            -> __get_free_pages() uses GFP_KERNEL
    
    The create_active() function is only called from pvcalls_front_accept()
    with a spin_lock held, The allocation is not allowed to sleep and
    GFP_KERNEL is not sufficient.
    
    This issue was detected by using the Coccinelle software.
    
    v2: Add a function doing the allocations which is called
        outside the lock and passing the allocated data to
        create_active().
    
    v3: Use the matching deallocators i.e., free_page()
        and free_pages(), respectively.
    
    v4: It would be better to pre-populate map (struct sock_mapping),
        rather than introducing one more new struct.
    
    v5: Since allocating the data outside of this call it should also
        be freed outside, when create_active() fails.
        Move kzalloc(sizeof(*map2), GFP_ATOMIC) outside spinlock and
        use GFP_KERNEL instead.
    
    v6: Drop the superfluous calls.
    Suggested-by: default avatarJuergen Gross <jgross@suse.com>
    Suggested-by: default avatarBoris Ostrovsky <boris.ostrovsky@oracle.com>
    Suggested-by: default avatarStefano Stabellini <sstabellini@kernel.org>
    Signed-off-by: default avatarWen Yang <wen.yang99@zte.com.cn>
    Acked-by: default avatarStefano Stabellini <sstabellini@kernel.org>
    CC: Julia Lawall <julia.lawall@lip6.fr>
    CC: Boris Ostrovsky <boris.ostrovsky@oracle.com>
    CC: Juergen Gross <jgross@suse.com>
    CC: Stefano Stabellini <sstabellini@kernel.org>
    CC: xen-devel@lists.xenproject.org
    CC: linux-kernel@vger.kernel.org
    Signed-off-by: default avatarBoris Ostrovsky <boris.ostrovsky@oracle.com>
    Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
    06b919a5
pvcalls-front.c 32.4 KB