From patchwork Thu Jul 1 01:52:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 12353271 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,URIBL_RED autolearn=unavailable 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 86429C11F68 for ; Thu, 1 Jul 2021 01:52:58 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3E78361468 for ; Thu, 1 Jul 2021 01:52:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3E78361468 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 BE3748D023E; Wed, 30 Jun 2021 21:52:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BBA238D0236; Wed, 30 Jun 2021 21:52:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A82E28D023E; Wed, 30 Jun 2021 21:52:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0180.hostedemail.com [216.40.44.180]) by kanga.kvack.org (Postfix) with ESMTP id 84EDC8D0236 for ; Wed, 30 Jun 2021 21:52:57 -0400 (EDT) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 59C2282D35F4 for ; Thu, 1 Jul 2021 01:52:57 +0000 (UTC) X-FDA: 78312345594.30.6D998A2 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf22.hostedemail.com (Postfix) with ESMTP id 0A1561982 for ; Thu, 1 Jul 2021 01:52:56 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id DF4186105A; Thu, 1 Jul 2021 01:52:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1625104376; bh=6MWdX56fY3D94DuzhXP11oAIC2y/aPv8BRRKi5jD3bA=; h=Date:From:To:Subject:In-Reply-To:From; b=kQRCOUQ5EWJ7OZjQPf4cCk1xaALDzsKIr5GQTW5tIWdPTyzUhTUiRdpjEISKzzKBn Okm9eHf9aDgqpqVjgQ0wHkB6+jd28tA4E5pzCEYULp+ZvRalTWuLCTqB2PzklkhCF8 70Jllkk5+JduW7BgWFWVJJW7V5WHGx7gAgnFrNj4= Date: Wed, 30 Jun 2021 18:52:55 -0700 From: Andrew Morton To: akpm@linux-foundation.org, bigeasy@linutronix.de, colin.king@canonical.com, ddstreet@ieee.org, linmiaohe@huawei.com, linux-mm@kvack.org, mm-commits@vger.kernel.org, nathan@kernel.org, sjenning@redhat.com, tiantao6@hisilicon.com, torvalds@linux-foundation.org, vitaly.wool@konsulko.com Subject: [patch 107/192] mm/zswap.c: fix two bugs in zswap_writeback_entry() Message-ID: <20210701015255.wWKmg3P-p%akpm@linux-foundation.org> In-Reply-To: <20210630184624.9ca1937310b0dd5ce66b30e7@linux-foundation.org> User-Agent: s-nail v14.8.16 Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=kQRCOUQ5; dmarc=none; spf=pass (imf22.hostedemail.com: domain of akpm@linux-foundation.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org X-Stat-Signature: zcyzwn51a6t8m1t99dwub3kegcjt6hdc X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 0A1561982 X-HE-Tag: 1625104376-100220 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: Miaohe Lin Subject: mm/zswap.c: fix two bugs in zswap_writeback_entry() In the ZSWAP_SWAPCACHE_FAIL and ZSWAP_SWAPCACHE_EXIST case, we forgot to call zpool_unmap_handle() when zpool can't sleep. And we might sleep in zswap_get_swap_cache_page() while zpool can't sleep. To fix all of these, zpool_unmap_handle() should be done before zswap_get_swap_cache_page() when zpool can't sleep. Link: https://lkml.kernel.org/r/20210522092242.3233191-4-linmiaohe@huawei.com Fixes: fc6697a89f56 ("mm/zswap: add the flag can_sleep_mapped") Signed-off-by: Miaohe Lin Cc: Colin Ian King Cc: Dan Streetman Cc: Nathan Chancellor Cc: Sebastian Andrzej Siewior Cc: Seth Jennings Cc: Tian Tao Cc: Vitaly Wool Signed-off-by: Andrew Morton --- mm/zswap.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) --- a/mm/zswap.c~mm-zswapc-fix-two-bugs-in-zswap_writeback_entry +++ a/mm/zswap.c @@ -967,6 +967,13 @@ static int zswap_writeback_entry(struct spin_unlock(&tree->lock); BUG_ON(offset != entry->offset); + src = (u8 *)zhdr + sizeof(struct zswap_header); + if (!zpool_can_sleep_mapped(pool)) { + memcpy(tmp, src, entry->length); + src = tmp; + zpool_unmap_handle(pool, handle); + } + /* try to allocate swap cache page */ switch (zswap_get_swap_cache_page(swpentry, &page)) { case ZSWAP_SWAPCACHE_FAIL: /* no memory or invalidate happened */ @@ -982,17 +989,7 @@ static int zswap_writeback_entry(struct case ZSWAP_SWAPCACHE_NEW: /* page is locked */ /* decompress */ acomp_ctx = raw_cpu_ptr(entry->pool->acomp_ctx); - dlen = PAGE_SIZE; - src = (u8 *)zhdr + sizeof(struct zswap_header); - - if (!zpool_can_sleep_mapped(pool)) { - - memcpy(tmp, src, entry->length); - src = tmp; - - zpool_unmap_handle(pool, handle); - } mutex_lock(acomp_ctx->mutex); sg_init_one(&input, src, entry->length);