From patchwork Sun Dec 6 06:14:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 11953659 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3C427C433FE for ; Sun, 6 Dec 2020 06:14:59 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E465C230FA for ; Sun, 6 Dec 2020 06:14:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E465C230FA Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 83F9A6B0072; Sun, 6 Dec 2020 01:14:58 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7C7D96B0073; Sun, 6 Dec 2020 01:14:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 68F9C6B0074; Sun, 6 Dec 2020 01:14:58 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0111.hostedemail.com [216.40.44.111]) by kanga.kvack.org (Postfix) with ESMTP id 5278D6B0072 for ; Sun, 6 Dec 2020 01:14:58 -0500 (EST) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 0E7A31EE6 for ; Sun, 6 Dec 2020 06:14:58 +0000 (UTC) X-FDA: 77561844276.08.smile74_100bc64273d3 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin08.hostedemail.com (Postfix) with ESMTP id EBF701819E793 for ; Sun, 6 Dec 2020 06:14:57 +0000 (UTC) X-HE-Tag: smile74_100bc64273d3 X-Filterd-Recvd-Size: 2555 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf42.hostedemail.com (Postfix) with ESMTP for ; Sun, 6 Dec 2020 06:14:57 +0000 (UTC) Date: Sat, 05 Dec 2020 22:14:55 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1607235296; bh=yQHF9wy/rEDp1jEnZIQgWe+affdUfYqCvb72tCH1FP0=; h=From:To:Subject:In-Reply-To:From; b=XThZZkI8OIP4QZjWIZNoEBx2nuAn7+HlDDpPEgArXBEZHdkYqhaqDfHTpq5sDjhbp JRsgXNKSTTiNASvB7U4QnrkUm/Zfy+OYpK5OAdSmzdKC+B6VdTh5JOT7/ik2i3TWXJ /TWylwhzx5X69m6/nW5FQ1jaB1GrveFKFCJsL0SE= From: Andrew Morton To: akpm@linux-foundation.org, hughd@google.com, linux-mm@kvack.org, mm-commits@vger.kernel.org, qcai@redhat.com, stable@vger.kernel.org, torvalds@linux-foundation.org Subject: [patch 06/12] mm/swapfile: do not sleep with a spin lock held Message-ID: <20201206061455.fGLHX_jlo%akpm@linux-foundation.org> In-Reply-To: <20201205221412.67f14b9b3a5ef531c76dd452@linux-foundation.org> User-Agent: s-nail v14.8.16 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Qian Cai Subject: mm/swapfile: do not sleep with a spin lock held We can't call kvfree() with a spin lock held, so defer it. Fixes a might_sleep() runtime warning. Link: https://lkml.kernel.org/r/20201202151549.10350-1-qcai@redhat.com Fixes: 873d7bcfd066 ("mm/swapfile.c: use kvzalloc for swap_info_struct allocation") Signed-off-by: Qian Cai Reviewed-by: Andrew Morton Cc: Hugh Dickins Cc: Signed-off-by: Andrew Morton --- mm/swapfile.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/mm/swapfile.c~mm-swapfile-do-not-sleep-with-a-spin-lock-held +++ a/mm/swapfile.c @@ -2867,6 +2867,7 @@ late_initcall(max_swapfiles_check); static struct swap_info_struct *alloc_swap_info(void) { struct swap_info_struct *p; + struct swap_info_struct *defer = NULL; unsigned int type; int i; @@ -2895,7 +2896,7 @@ static struct swap_info_struct *alloc_sw smp_wmb(); WRITE_ONCE(nr_swapfiles, nr_swapfiles + 1); } else { - kvfree(p); + defer = p; p = swap_info[type]; /* * Do not memset this entry: a racing procfs swap_next() @@ -2908,6 +2909,7 @@ static struct swap_info_struct *alloc_sw plist_node_init(&p->avail_lists[i], 0); p->flags = SWP_USED; spin_unlock(&swap_lock); + kvfree(defer); spin_lock_init(&p->lock); spin_lock_init(&p->cont_lock);