Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp3595073pxy; Mon, 26 Apr 2021 05:34:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz8Ev8wZzH96LYQEZ5nQt2SyDgmypS84UFVA3RAxHsy/4phv7lyPCFUy7kvqK79ngGs5MHc X-Received: by 2002:a17:90a:d681:: with SMTP id x1mr21361586pju.82.1619440479564; Mon, 26 Apr 2021 05:34:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619440479; cv=none; d=google.com; s=arc-20160816; b=IfZWFt0Rho7I5rw/cS2X3qSIdCrrgxJPm3f3n0AHO45v5rgEsc6Eh/WC+UACpA57qA VL3yPceRiUeDNcpoOl2mmUJdj87a5DtV7v3ELE0MHUfXNJEq6F9HHLNGmhBF2P28HXs+ GSCjX8Sh0jcLbNzRrUOYRS3Xk/Kyu8W2J6o0LpCSd6yz3u+OS4JOpRVgsKXezS2Gx9SL O3M2hrATlo6slSWqFLVxDh8Yr3bwRkqJLiKS787nANlarF3cd99MGB5WU+xS0WvCkz/y SAW+PlSuDWI+nlVV0hLhTZ88BgmMcDvcXxZGFw9kd3cbRGBME4FXmAcZsDeOi5XyZ6Lq RHBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=FcSbujDjNdOYMDc1/N6lpy3Rfzd9XN6O//y7efeCwQo=; b=BV0ibdkDrT3JuJ3NuyscFTUiKxrgocYm6q3IuGK0tU9huaQKEf25NJ+ZWw+YJlX90y LsBD0vjqS7E/Gory7qrO/VsOSVN95P0r/JeHR0jNCw9AdCKv1N7fQzXZaC8xQnPu5Yj/ IvYu9Hl95ZE4Mqh8kmSuh2Ms/WF2LOJk4NgTVigdEvQvS84MQ0zRAR2Ca/i+V7lO2V+S BrgUSkXnChurLX6Q+fKE+5qPyOVbm6O/N4zsCT9XLKXGChXrVnfyonREY2l8Z8KLeWBM ovbY4rHsAmmF8nWD9q0H52zcYrXPuvNvIAvQy8GMlb9PG6GAFsIq66SA+RctzY8b0MNm Nv9A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j9si19674866pgq.51.2021.04.26.05.34.26; Mon, 26 Apr 2021 05:34:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233403AbhDZMed (ORCPT + 99 others); Mon, 26 Apr 2021 08:34:33 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:16156 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233385AbhDZMeb (ORCPT ); Mon, 26 Apr 2021 08:34:31 -0400 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4FTPPZ4FdqzmdT8; Mon, 26 Apr 2021 20:30:42 +0800 (CST) Received: from huawei.com (10.175.104.170) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.498.0; Mon, 26 Apr 2021 20:33:41 +0800 From: Miaohe Lin To: CC: , , , , , , , , , , , , , , , , Subject: [PATCH v6 0/4] close various race windows for swap Date: Mon, 26 Apr 2021 20:33:12 +0800 Message-ID: <20210426123316.806267-1-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.104.170] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 most of the remaining patches try to use this to close various race windows. More details can be found in the respective changelogs. Thanks! v5->v6: collect Reviewed-by tag fix page uninitialized in failed case per Yu Zhao v4->v5: collect Reviewed-by tag do put_swap_device() before returning from the function per Huang, Ying v3->v4: some commit log and comment enhance per Huang, Ying put get/put_swap_device() in shmem_swapin_page() per Huang, Ying collect Reviewed-by tag v2->v3: some commit log and comment enhance per Huang, Ying remove ref_initialized field squash PATCH 1-2 v1->v2: reorganize the patch-2/5 various enhance and fixup per Huang, Ying Many thanks for the comments of Huang, Ying, Dennis Zhou and Tim Chen. Miaohe Lin (4): mm/swapfile: use percpu_ref to serialize against concurrent swapoff swap: fix do_swap_page() race with swapoff mm/swap: remove confusing checking for non_swap_entry() in swap_ra_info() mm/shmem: fix shmem_swapin() race with swapoff include/linux/swap.h | 14 ++++++-- mm/memory.c | 11 ++++-- mm/shmem.c | 14 +++++++- mm/swap_state.c | 6 ---- mm/swapfile.c | 79 +++++++++++++++++++++++++++----------------- 5 files changed, 83 insertions(+), 41 deletions(-) -- 2.23.0