Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp720844pxa; Wed, 19 Aug 2020 13:00:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJysLpVAEYVET7EP+Wg3jNnj2nfjquHOT6Gr4maRsmE2Dx/Va9j2nyGG3xJ/OC9h+c0JEqMs X-Received: by 2002:a17:906:7d6:: with SMTP id m22mr25777807ejc.229.1597867218697; Wed, 19 Aug 2020 13:00:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597867218; cv=none; d=google.com; s=arc-20160816; b=quBxuK3W1H4Kk85lx+g0WcKkC1o58C3EL4+K7dDM5+YNqc2HQFEnKLgu86eQCc27RM u0Bs9iapyO9aQtwH0/xM1TN5t4dLAb9hxOsSNtwePCgc0dRKxXnKIS2uis9CJZrvHrfp 5105oCTRfOzN43pFFWZdQC8ipXkK8KASXb0v6jon5Z/vN09AHOrVCtgh4cYnM+l9WvNh rCJzzwD7KxAvm3n8Txm+lXNPBJH2mXURdq7oSI6+HsvSdkBd+de6MoMhelKtmoFlP4XT qaSaG6rzJJS6x04WPrlNLQpKDE7Ofa00IeSfsXXhwfCITT8NeUdFSmgLBGEjIq4p6e8I hc5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=JDGvX0s3CfGuroZ3WjQYFXy/cRxyJCVnz+Pf0p7uSV8=; b=JMBCHo+sxGEzO8yjwpSvLze2pLVUzuCoZ2Kvu7HtFGfkqDf8ozqPBnTr/420U1Jsl8 bI9yMDsxB8cJCrBjiJTD62HAp5b2k4OUAc9zHHNTuWN2DJARabKX8Ohwhutl6v3neHgv 3r1gHINPH4TeDBXCtH+M/5x4pRxwgi+vgjs+Kan//Pt8BW9vQX+b91rbeSkYmx2xt/C6 tFwUx0OsfcEOR4CriD4ehDppFEuScEdb6xcYR4RdIg39ge3VBVebKuHGOtbDwnSpGAB9 vk55gUclsolOfOt8RjntnpZkKVbejgHhAuN7A65eWk2ZigZQu1uBDPxvAF0ENTF0QL5v s3vg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=chpaM9fl; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w2si13295164ejz.34.2020.08.19.12.59.52; Wed, 19 Aug 2020 13:00:18 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=chpaM9fl; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726837AbgHST5C (ORCPT + 99 others); Wed, 19 Aug 2020 15:57:02 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:58487 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726585AbgHST5B (ORCPT ); Wed, 19 Aug 2020 15:57:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597867020; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc; bh=JDGvX0s3CfGuroZ3WjQYFXy/cRxyJCVnz+Pf0p7uSV8=; b=chpaM9flQOJ2t8U0f7PgxsUJpwOVdAgZVjVb8ulrpKW6wUXx0OqUcv/pECiZujPXhhGkwy BLyLiS9RTN8CEGyygear3/L1kmUxhCN4h7Itt0A/53JMtTV6VAbLWJ/uG9j1RE5otKz9ol 02U6NVyMzHUHCBOtO+gJpnE8ySViY24= Received: from mail-pj1-f70.google.com (mail-pj1-f70.google.com [209.85.216.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-83-OVFynVMkPaObxO7E2QQ77Q-1; Wed, 19 Aug 2020 15:56:58 -0400 X-MC-Unique: OVFynVMkPaObxO7E2QQ77Q-1 Received: by mail-pj1-f70.google.com with SMTP id c3so281297pjr.2 for ; Wed, 19 Aug 2020 12:56:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=JDGvX0s3CfGuroZ3WjQYFXy/cRxyJCVnz+Pf0p7uSV8=; b=PsNovsUA5I+og+bw0/ZPsd2ZW9nMFEAzDw6hdojmsUnYE+s5Fw07WhnUrJdbj+XxpA sQKrzLdLfkTxeV2c51u1DECsKLAp4h3J/saOhDEKW3P0YW+k/KECbQrGITjNvCK9xdvm h1+5unkXbDmk+ASbAemMmNvtEGjBtlQ1a2XregPjsGWNlJMRNgi+lxKTHPIGyqMGvtbS MI7dRybqmlh78zrY8153igBAnmssRsFRU4J9XWfRAelR6sJuaBXyy7wdnXPXvocq+XzZ GTOvLMoX6iiu/OW6bRWGQfoIFunlddNK+1LVstFuVtZdWqbMnRAn9BU5Ym9KGjriC+Ea HUfw== X-Gm-Message-State: AOAM531g7PXBneeGMkb/CUGBpm/97Uz3MAaIWNCfhGUIOh4hzkWiDWDb KM7vhf0wvwV22A6s8nOTTRJH7J6TuHfGjduaB8uiTp/meCqQw0dOOV/NYpCAYwaxHJAnEa0vXhn dbTOrJRmhYuUN5fwc0conwfpl X-Received: by 2002:a63:7d3:: with SMTP id 202mr32005pgh.230.1597867017031; Wed, 19 Aug 2020 12:56:57 -0700 (PDT) X-Received: by 2002:a63:7d3:: with SMTP id 202mr31995pgh.230.1597867016665; Wed, 19 Aug 2020 12:56:56 -0700 (PDT) Received: from xiangao.remote.csb ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id i39sm3906880pje.8.2020.08.19.12.56.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Aug 2020 12:56:56 -0700 (PDT) From: Gao Xiang To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Rafael Aquini , Carlos Maiolino , Eric Sandeen , Gao Xiang , "Huang, Ying" , stable Subject: [PATCH] mm, THP, swap: fix allocating cluster for swapfile by mistake Date: Thu, 20 Aug 2020 03:56:13 +0800 Message-Id: <20200819195613.24269-1-hsiangkao@redhat.com> X-Mailer: git-send-email 2.18.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org SWP_FS doesn't mean the device is file-backed swap device, which just means each writeback request should go through fs by DIO. Or it'll just use extents added by .swap_activate(), but it also works as file-backed swap device. So in order to achieve the goal of the original patch, SWP_BLKDEV should be used instead. FS corruption can be observed with SSD device + XFS + fragmented swapfile due to CONFIG_THP_SWAP=y. Fixes: f0eea189e8e9 ("mm, THP, swap: Don't allocate huge cluster for file backed swap device") Fixes: 38d8b4e6bdc8 ("mm, THP, swap: delay splitting THP during swap out") Cc: "Huang, Ying" Cc: stable Signed-off-by: Gao Xiang --- I reproduced the issue with the following details: Environment: QEMU + upstream kernel + buildroot + NVMe (2 GB) Kernel config: CONFIG_BLK_DEV_NVME=y CONFIG_THP_SWAP=y Some reproducable steps: mkfs.xfs -f /dev/nvme0n1 mkdir /tmp/mnt mount /dev/nvme0n1 /tmp/mnt bs="32k" sz="1024m" # doesn't matter too much, I also tried 16m xfs_io -f -c "pwrite -R -b $bs 0 $sz" -c "fdatasync" /tmp/mnt/sw xfs_io -f -c "pwrite -R -b $bs 0 $sz" -c "fdatasync" /tmp/mnt/sw xfs_io -f -c "pwrite -R -b $bs 0 $sz" -c "fdatasync" /tmp/mnt/sw xfs_io -f -c "pwrite -F -S 0 -b $bs 0 $sz" -c "fdatasync" /tmp/mnt/sw xfs_io -f -c "pwrite -R -b $bs 0 $sz" -c "fsync" /tmp/mnt/sw mkswap /tmp/mnt/sw swapon /tmp/mnt/sw stress --vm 2 --vm-bytes 600M # doesn't matter too much as well Symptoms: - FS corruption (e.g. checksum failure) - memory corruption at: 0xd2808010 - segfault ... mm/swapfile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index 6c26916e95fd..2937daf3ca02 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1074,7 +1074,7 @@ int get_swap_pages(int n_goal, swp_entry_t swp_entries[], int entry_size) goto nextsi; } if (size == SWAPFILE_CLUSTER) { - if (!(si->flags & SWP_FS)) + if (si->flags & SWP_BLKDEV) n_ret = swap_alloc_cluster(si, swp_entries); } else n_ret = scan_swap_map_slots(si, SWAP_HAS_CACHE, -- 2.18.1