Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp5236199ybl; Tue, 27 Aug 2019 01:17:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqzMrUjGIxdBy9In6XeunDU0yIwU3AJhVIljaGQvg5AdFmAYpr6T0odVqrJVkrA0ZW6v4k1c X-Received: by 2002:aa7:984a:: with SMTP id n10mr11885840pfq.3.1566893878614; Tue, 27 Aug 2019 01:17:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566893878; cv=none; d=google.com; s=arc-20160816; b=qMTuJ57GNAuPRWd6R+RCb4LKuujxeOqFjSa7dRD3EbuXDeEfmmGSASse4FPBpGeq9A SNZYCEV2xPVFXcj5FMxN53/jzOz2CesT0YSbywYF1yxPpWLGIREBI6QcS+iW6GG7yQzV 6gup393S9hGQf6+bJVK/Q5cIOS6hxL7XmhCOx3cg1LbbQYGr4cP4EYHoZBy+EFBSKgfk 2rl6K/dLNkrfFzgSe1ncwRi90QOwzwaux7FxkZ97euKyu3tFBFxrXzMTj4jDeSiQKMwp Gu+oqkD3TTxwsShSquPNBXAVgpTXg2+i8pwQ32SLct0dSbyaFt4Og89MMPAsXwaWDQ6r mNew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ScYnMNFB05wU5QYml7R7K9VB8fwbi5YVDnunfKbcJtM=; b=To4zUBKCeCbZ3iuqodXrWgUq9zP8F+Rx2zE/m1kvNzQeWsjtvcU3zzVc9sh+zF+slz J3/qvKLu8g9OxtgPH4fVTwBQtx+PDQ3HcSdEJVG+PrrLCk+ehY3dgccmgd8ZtqBe0Zhw HIX0UHclEglgcL+nYuqpi3IJG8FR3lNQThg7jgIL+2ViZoU1AMkHJ1K1Iz+5Mv1KK4ia XGiCovPLhKqg7gaXoX+6zazNMuQG3rFpIoFLeyprqOGMeaAD6UEUCFds35BCKapD8THm EQLMjcMyklP6DvQYGuY7pr2jOwUjlqxmR5yVLpf4ikCUnTBgUrK0XCDhO60G839+J41D sRJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=CVyCpgGQ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bo13si1009192pjb.89.2019.08.27.01.17.43; Tue, 27 Aug 2019 01:17:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=CVyCpgGQ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730087AbfH0Hyg (ORCPT + 99 others); Tue, 27 Aug 2019 03:54:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:46116 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729576AbfH0Hya (ORCPT ); Tue, 27 Aug 2019 03:54:30 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E47112186A; Tue, 27 Aug 2019 07:54:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566892469; bh=vbhXG0rORz1IcehPNBtQZMb7EgXEG9oBiCYmrZJYbpY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CVyCpgGQMTgKLOjjIChD+2WyEez3zArthdwX6VDJy3svTYkYu/nefWjghyvVgx3U6 QvrntyzBpR9srSZulXm1OANmLlV8eGTYAtJoAkuHLrD3kAMbNChatpUY73GVFWMdeQ 0LOtyzSdyAJbleN9lMwWlN8yrMVIoUc7KXovYGas= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Henry Burns , Sergey Senozhatsky , Henry Burns , Minchan Kim , Shakeel Butt , Jonathan Adams , Andrew Morton , Linus Torvalds Subject: [PATCH 4.14 58/62] mm/zsmalloc.c: migration can leave pages in ZS_EMPTY indefinitely Date: Tue, 27 Aug 2019 09:51:03 +0200 Message-Id: <20190827072703.836244944@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190827072659.803647352@linuxfoundation.org> References: <20190827072659.803647352@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Henry Burns commit 1a87aa03597efa9641e92875b883c94c7f872ccb upstream. In zs_page_migrate() we call putback_zspage() after we have finished migrating all pages in this zspage. However, the return value is ignored. If a zs_free() races in between zs_page_isolate() and zs_page_migrate(), freeing the last object in the zspage, putback_zspage() will leave the page in ZS_EMPTY for potentially an unbounded amount of time. To fix this, we need to do the same thing as zs_page_putback() does: schedule free_work to occur. To avoid duplicated code, move the sequence to a new putback_zspage_deferred() function which both zs_page_migrate() and zs_page_putback() call. Link: http://lkml.kernel.org/r/20190809181751.219326-1-henryburns@google.com Fixes: 48b4800a1c6a ("zsmalloc: page migration support") Signed-off-by: Henry Burns Reviewed-by: Sergey Senozhatsky Cc: Henry Burns Cc: Minchan Kim Cc: Shakeel Butt Cc: Jonathan Adams Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/zsmalloc.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -1878,6 +1878,18 @@ static void dec_zspage_isolation(struct zspage->isolated--; } +static void putback_zspage_deferred(struct zs_pool *pool, + struct size_class *class, + struct zspage *zspage) +{ + enum fullness_group fg; + + fg = putback_zspage(class, zspage); + if (fg == ZS_EMPTY) + schedule_work(&pool->free_work); + +} + static void replace_sub_page(struct size_class *class, struct zspage *zspage, struct page *newpage, struct page *oldpage) { @@ -2047,7 +2059,7 @@ int zs_page_migrate(struct address_space * the list if @page is final isolated subpage in the zspage. */ if (!is_zspage_isolated(zspage)) - putback_zspage(class, zspage); + putback_zspage_deferred(pool, class, zspage); reset_page(page); put_page(page); @@ -2093,14 +2105,13 @@ void zs_page_putback(struct page *page) spin_lock(&class->lock); dec_zspage_isolation(zspage); if (!is_zspage_isolated(zspage)) { - fg = putback_zspage(class, zspage); /* * Due to page_lock, we cannot free zspage immediately * so let's defer. */ - if (fg == ZS_EMPTY) - schedule_work(&pool->free_work); + putback_zspage_deferred(pool, class, zspage); } + spin_unlock(&class->lock); }