Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp5228432ybl; Tue, 27 Aug 2019 01:09:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqxqsu/ZOdNvm0Gei/9i+M6gNvgrQn8aix1XE3tiNo0LXtrRiHZ6+94NDQBSY20/GX30gRu0 X-Received: by 2002:a63:6146:: with SMTP id v67mr21020180pgb.271.1566893373540; Tue, 27 Aug 2019 01:09:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566893373; cv=none; d=google.com; s=arc-20160816; b=cBOIFBzGbMw42H7bty5kY5DxLj93C6G/1c1ZcML/sVXUUl4o1XOLMJsCaXdlGWEuFc PXW5YoixDzlYGzfU+VGeFhiYb0hEMcJTVLLtEfcZLpWtiaK2Ljn+OGSLoFFdHmk2M8SH /Qc5yJKDLqTpaHmFddB0Av6lMOpkZTFATqzVHhhapNNi9/AON3IWfcKHP/HP31PHBiFu fKDUwlV5IhfyKJ1BpMbgo1/Ilw4KOrBcpRwITs4OueaJ1OerJY08Fe2ScN58uKvtcRaw gyGAI9VrXa3tuLvtDexr3ZAnCnLe0abp4S2AvqF0loUbT+Kgfj3ZpRtOQ5fNWgm1u8na rW0A== 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=TqxWKrlzHPoL7fm36Z2PO3Jf9D997ZqP1ak876wik7k=; b=NehZLn3uiEPj33B5sYD3UFOMDLxRKyLlcJnY+DVIhbSQF7puFKvHS5yyKqCL4JUuzU CTbkzJi779golUat/aaN36NvDU+pREIc02jbgJgo1RX1gFjg3akIO6V+F5CSYhbyFTsb qWAtTE/eVKkz2q/OD3RcMcs/EVvKK9msI+hM/cBZfBn+RvCTEKivBB+OG+FvPedtHQb4 4maS3our/kVoP071D4xbyWySGa5r8+3y9Y9d8qtVTHn/HjLZJZWM27IJ6V1E5zhqlelq GNvV1y+cWgI/vcA5/WjWUEUJm/9gzM+22G6xIDztya8+qIC6pY0GOtQw8Vn6MR4ZWjmC BC/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2QP0nT7F; 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 143si11196109pgc.479.2019.08.27.01.09.18; Tue, 27 Aug 2019 01:09:33 -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=2QP0nT7F; 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 S1733132AbfH0IHJ (ORCPT + 99 others); Tue, 27 Aug 2019 04:07:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:37104 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732787AbfH0IHF (ORCPT ); Tue, 27 Aug 2019 04:07:05 -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 5DD5C206BA; Tue, 27 Aug 2019 08:07:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566893223; bh=98BKHUssZiAvVoIeeamna4LlHN+bPH8+OD69xuUHJas=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2QP0nT7FvUtd6Wr7HAjiT4GotardjNx4gV6iGH6HKxA5ZO9LWWCAcBEqZUOHuvaKV gkOstcWffDcKeTVBVTSMuoUqA8ZfGxgExIi4zjmKgwLXpcKiZL/SPMu2aRa5XB7eNi cnmUJ+d9xpUAw5UMZ+jzz78JQtgOxEjXcdspuC1s= 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 5.2 151/162] mm/zsmalloc.c: migration can leave pages in ZS_EMPTY indefinitely Date: Tue, 27 Aug 2019 09:51:19 +0200 Message-Id: <20190827072744.020727711@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190827072738.093683223@linuxfoundation.org> References: <20190827072738.093683223@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 @@ -1882,6 +1882,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) { @@ -2051,7 +2063,7 @@ static int zs_page_migrate(struct addres * 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); @@ -2097,14 +2109,13 @@ static void zs_page_putback(struct 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); }