Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp429210pxf; Thu, 8 Apr 2021 06:10:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxwy/PBr5zVdfLJI4Qz+0eOoVCxjJosm7Czhj1Ujq/mSOn7pMcDvomzpG/XLhA2QPeW6AGt X-Received: by 2002:a50:c004:: with SMTP id r4mr10986453edb.192.1617887436893; Thu, 08 Apr 2021 06:10:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617887436; cv=none; d=google.com; s=arc-20160816; b=iTEsjsf++HB/ckoie7dlcXn3m4AO0/bmBI2+9PuLOkyAhzk9jSX7TTene2Q8NhmNAt IdrvjB7HhFy8SlaJWUgHg9uixyT2mmmUpFt0L9HZ3QZ3NWiLmCY9Hg+m6K5SgS3o7euX aC7eqAQMSeY4LE9kk993BrF2HVI8pLPF0xgEP6CiaDNbWUpHf6AEMqgPXumX9UWsEg41 Mi3Xn9ha/xcEfgp0jQpOO80X5kOSVj+5tln6drnnC2EtTw241zpWgyZl++Y/7Xwj6ilE XdU1ZUVhpy37VGiovN5Lfjh5vxYgnMv0z2NPrHv1ayx1b23/buXmwFP60Sx4qgzctWFf y3Dw== 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=zBx0/nlVI1lxc37oQo7lbuBVwnuMf1HkiMJyFos+d2g=; b=IdmJbIJ+nlMd74cbwmqRS19ZzQF5dLO43DJzyncUTaBgTZhz1MCbfRwoiiW6WPdEpD fPhkuanw+BAt/5zjAJyEOg5Dyyl+aBPZdh/TJ/3CKyPD3iqTubLBVK6GAMUhDbxHCx25 gwuDaDNW4az/LFjxRc3pgmkFzRCEx+/GJzlGewdf1kAE75JrDxr83f4Vzkp3++UFgpws Wo38svB+Hj1+LcHgr2MU5z2Yh77GEAW2QvsQTnnXpuin9Fzg1ge+G2Ih51K+u7crQTeM NHKAKjexYR59HGu8WwzJ94Avq9HGcWx8S5VfKmIgfsqUkp4ZE/skKcK7PFZDzxjMk30o 8HJQ== 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 a5si6791039ejt.533.2021.04.08.06.10.10; Thu, 08 Apr 2021 06:10:36 -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 S231591AbhDHNJa (ORCPT + 99 others); Thu, 8 Apr 2021 09:09:30 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:16413 "EHLO szxga06-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229741AbhDHNJa (ORCPT ); Thu, 8 Apr 2021 09:09:30 -0400 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 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.104.175] 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 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(-) -- 2.19.1