From patchwork Thu Apr 8 13:08:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 12191033 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=-11.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT 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 59018C433B4 for ; Thu, 8 Apr 2021 13:09:25 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B564061074 for ; Thu, 8 Apr 2021 13:09:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B564061074 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 41BAC6B0072; Thu, 8 Apr 2021 09:09:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 229D16B0082; Thu, 8 Apr 2021 09:09:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 055C16B0081; Thu, 8 Apr 2021 09:09:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0004.hostedemail.com [216.40.44.4]) by kanga.kvack.org (Postfix) with ESMTP id DAF986B0078 for ; Thu, 8 Apr 2021 09:09:22 -0400 (EDT) Received: from smtpin40.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 9FC251805BDB9 for ; Thu, 8 Apr 2021 13:09:22 +0000 (UTC) X-FDA: 78009230964.40.699F40E Received: from szxga06-in.huawei.com (szxga06-in.huawei.com [45.249.212.32]) by imf21.hostedemail.com (Postfix) with ESMTP id D4059E000110 for ; Thu, 8 Apr 2021 13:09:20 +0000 (UTC) Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4FGM4L0Jypzkjg5; Thu, 8 Apr 2021 21:07:30 +0800 (CST) Received: from huawei.com (10.175.104.175) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.498.0; Thu, 8 Apr 2021 21:09:07 +0800 From: Miaohe Lin To: CC: , , , , , , , , , , , , , Subject: [PATCH 0/5] close various race windows for swap Date: Thu, 8 Apr 2021 09:08:15 -0400 Message-ID: <20210408130820.48233-1-linmiaohe@huawei.com> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 X-Originating-IP: [10.175.104.175] X-CFilter-Loop: Reflected X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: D4059E000110 X-Stat-Signature: k68d5y3uzwjmceyrpcswoe4hgcwh4d3w Received-SPF: none (huawei.com>: No applicable sender policy available) receiver=imf21; identity=mailfrom; envelope-from=""; helo=szxga06-in.huawei.com; client-ip=45.249.212.32 X-HE-DKIM-Result: none/none X-HE-Tag: 1617887360-141582 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: Hi all, When I was investigating the swap code, I found some possible race windows. This series aims to fix all these races. But using current get/put_swap_device() to guard against concurrent swapoff for swap_readpage() looks terrible because swap_readpage() may take really long time. And to reduce the performance overhead on the hot-path as much as possible, it appears we can use the percpu_ref to close this race window(as suggested by Huang, Ying). The patch 1 adds percpu_ref support for swap and the rest of the patches use this to close various race windows. More details can be found in the respective changelogs. Thanks! Miaohe Lin (5): mm/swapfile: add percpu_ref support for swap swap: fix do_swap_page() race with swapoff mm/swap_state: fix get_shadow_from_swap_cache() race with swapoff mm/swap_state: fix potential faulted in race in swap_ra_info() mm/swap_state: fix swap_cluster_readahead() race with swapoff include/linux/swap.h | 4 +++- mm/memory.c | 10 +++++++++ mm/swap_state.c | 33 +++++++++++++++++++++-------- mm/swapfile.c | 50 +++++++++++++++++++++++++++----------------- 4 files changed, 68 insertions(+), 29 deletions(-)