Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp92950pxu; Thu, 10 Dec 2020 19:30:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJxMjqjOQzmkmDnpFjXSR61HG+ljtT+75s8upsjRxkrdUpAh09/Icpaebg7lXsuTbFagtgxj X-Received: by 2002:aa7:c886:: with SMTP id p6mr9958146eds.207.1607657423051; Thu, 10 Dec 2020 19:30:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607657423; cv=none; d=google.com; s=arc-20160816; b=R7b8skpge9+Z+6LiWbzei5im3Kal/BApyJv8Tdw8g9I2uIh8Z/pE6sJPmnYxGF/JJt QG3zeXq6Cg4IO91XSU2z4ZW1OAMEITot/Gn0d55b2k/gfZNxl6xiJEbCsqD9kmUgktVA UDNYgnnsRm9KHSkUo+2xjn7H7S0mHsTyNij9NB/EaSj7ZYAiFmXTOPUfaZM3pPvknexT sTDSPVTQzzAtZ4r2GBlXM1AYkp7F4QhhK6rFFy33w4iltAvLvR6qRN3f0BOeNk5/X1Cd 2yN1iGbuxBadCQrBsGSDC/3+mHjmepj8UAfQ4Yq6u69sBsI4qMWXKbhTQsAus8QXpJN2 LHvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from; bh=wBJ4GBUTxdDhBc3PocLREHvkfyxKysTEhtEH8HXuj/Q=; b=Byhi2KZKMCX4JbPlUPmNT0nuxnSXlZRikeviv+CSG5JZM+AI7Fyv586yfHmXOfkNLM FP3IrpR4uE3+/OvRiLxOg7J1TBvn+sStxDHljOWKy30iqrVUwStthDe7czRm9Y9XCqvw 2NyQdI8vDAviIDx4/Z8K1IzOJTvoV823WzwDxflsi8hx1wwlo8icKnL5C4auYRiiyywR a0TJtP5dhNkNleYHPgST1V1tgmFYMsdl/c6hhu4VsButjCr1axj+uZz1WGCfggIPq+vj YXfo4VeUdjoFuBznIp7yxxzjA56Y/WaD1YVgd1EPBiK/EXS8D7UaNorVkWVOr9/UXn8q 0BDA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v7si3760805ejr.236.2020.12.10.19.29.59; Thu, 10 Dec 2020 19:30:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390626AbgLJOcv (ORCPT + 99 others); Thu, 10 Dec 2020 09:32:51 -0500 Received: from mail.kernel.org ([198.145.29.99]:38684 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390478AbgLJObW (ORCPT ); Thu, 10 Dec 2020 09:31:22 -0500 From: Greg Kroah-Hartman Authentication-Results: mail.kernel.org; dkim=permerror (bad message/signature format) To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Qian Cai , Andrew Morton , Hugh Dickins , Linus Torvalds Subject: [PATCH 4.14 18/31] mm/swapfile: do not sleep with a spin lock held Date: Thu, 10 Dec 2020 15:26:55 +0100 Message-Id: <20201210142603.001031407@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201210142602.099683598@linuxfoundation.org> References: <20201210142602.099683598@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Qian Cai commit b11a76b37a5aa7b07c3e3eeeaae20b25475bddd3 upstream. We can't call kvfree() with a spin lock held, so defer it. Fixes a might_sleep() runtime warning. Fixes: 873d7bcfd066 ("mm/swapfile.c: use kvzalloc for swap_info_struct allocation") Signed-off-by: Qian Cai Signed-off-by: Andrew Morton Reviewed-by: Andrew Morton Cc: Hugh Dickins Cc: Link: https://lkml.kernel.org/r/20201202151549.10350-1-qcai@redhat.com Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/swapfile.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -2828,6 +2828,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; int size = sizeof(*p) + nr_node_ids * sizeof(struct plist_node); @@ -2857,7 +2858,7 @@ static struct swap_info_struct *alloc_sw smp_wmb(); nr_swapfiles++; } else { - kvfree(p); + defer = p; p = swap_info[type]; /* * Do not memset this entry: a racing procfs swap_next() @@ -2870,6 +2871,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);