From patchwork Wed Dec 2 15:15:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qian Cai X-Patchwork-Id: 11946337 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=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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 D7C26C83012 for ; Wed, 2 Dec 2020 15:16:16 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4D78320656 for ; Wed, 2 Dec 2020 15:16:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4D78320656 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 4EE326B005C; Wed, 2 Dec 2020 10:16:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4C4A36B005D; Wed, 2 Dec 2020 10:16:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 401F38D0001; Wed, 2 Dec 2020 10:16:15 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0090.hostedemail.com [216.40.44.90]) by kanga.kvack.org (Postfix) with ESMTP id 2A9856B005C for ; Wed, 2 Dec 2020 10:16:15 -0500 (EST) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id C822534A3 for ; Wed, 2 Dec 2020 15:16:14 +0000 (UTC) X-FDA: 77548693068.22.map41_2a0d376273b4 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin22.hostedemail.com (Postfix) with ESMTP id 7A26218038E74 for ; Wed, 2 Dec 2020 15:16:14 +0000 (UTC) X-HE-Tag: map41_2a0d376273b4 X-Filterd-Recvd-Size: 2951 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by imf31.hostedemail.com (Postfix) with ESMTP for ; Wed, 2 Dec 2020 15:16:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606922173; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=zqfbDEdmB+K+wrCtKWPCvHaKiRXjTInLALFT1GWF9Wg=; b=OE1sMp29kutrm+ldkQZ7g7ZAdRatlwxIxGW5UjLX4JzFTmX20omPoaxtlASQyioeE+2krP KTLg3oTfzIzHjd1DckR1VfUQkbKsqFvih9K+nnaFxi9zAZFuoCaG/r9VzA4PtMYW4SBGAs Zud/uSWvdDU8shM7slNSf8A0AjxQstU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-420-MmbhUDL8NkyixFkKyy_BOg-1; Wed, 02 Dec 2020 10:16:11 -0500 X-MC-Unique: MmbhUDL8NkyixFkKyy_BOg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6383B190A7B4; Wed, 2 Dec 2020 15:16:10 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.10.67.132]) by smtp.corp.redhat.com (Postfix) with ESMTP id C8DC95C1BD; Wed, 2 Dec 2020 15:16:09 +0000 (UTC) From: Qian Cai To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Qian Cai Subject: [PATCH] mm/swapfile: Do not sleep with a spin lock held Date: Wed, 2 Dec 2020 10:15:49 -0500 Message-Id: <20201202151549.10350-1-qcai@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.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: We can't call kvfree() with a spin lock held, so defer it. Signed-off-by: Qian Cai --- mm/swapfile.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index c4a613688a17..d58361109066 100644 --- a/mm/swapfile.c +++ b/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_swap_info(void) 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_swap_info(void) 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);