Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1344680pxa; Thu, 20 Aug 2020 08:55:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwmQ3ZVo6LUyEn2WU6b37l7ER6uZ2GUeDFQexc2A0p5HDpDn9CTOj1gfWuIzOSymSxOf7hu X-Received: by 2002:a17:906:7752:: with SMTP id o18mr3795466ejn.150.1597938902026; Thu, 20 Aug 2020 08:55:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597938902; cv=none; d=google.com; s=arc-20160816; b=Lgk3iL8rIyEy9Z83d3oa0uvKbWVPK02xzLu3UkVO1wvuDm3l9fw8QizGaXlBKuR107 oAo6KQC1n8unVn5ZY+I25ABjSDjk0/NG88OOeNfxZRb7tdLXlQuKzQcJQXg+L7138YGi PNom3GieRYEWOThTUBR+BNJJx9I4yMPmTvJBWnaB/Nz/3hPBPcuEFsQ5piJfqz7W/Xxs vNa3Vec/Wf6U5BDJag+DkhF399IMQBt5yh7Il+HxUoRaubGv6VUDig2CCa+QxhTY3Vti kb0bHZeT80h47dkEzd5GnCOiLHdjncfL2RzZdCsY1jgNu5P1F99MuMVB3WJgsOQtY6+e SdDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=R6ghZf9v2o9kk/8rogKtOdOOtqVr3hm3Y5dvwh2/Dy0=; b=GGhqVy4g2bcWM/OSphsXAymikVBtEmi0VCp6btGU3jab9ySZDxEa0XTbpb8PACTMgr lGc7lFjoqqTGh4U/5OXIoxuNwXjgivg+mYqszPUmxk80optJ7GINE5FrKnBtoMZm4CBC 83U7Drkpbl7Fn/xUlLDABh3Rg9vLCHtNpfydrXf7Dte5H/jdfzU82OvtWiHHNJvP/xsw QrP7KxI4Pgiz2agTMJt7qLRXXz7bze5T/NYbQvc/BpTqmLUhrBThBWY7Xxl1FHCCxs0f fHs0NE2MDEVMsM7+RrVP1NVppFCIntrU7R0/dccEzM9LgCyrJOEZdZ8ihWhilZZHJ+f+ qwFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=g2Ohspes; 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 v19si1458519ejf.83.2020.08.20.08.54.37; Thu, 20 Aug 2020 08:55:02 -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=g2Ohspes; 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 S1729289AbgHTPvp (ORCPT + 99 others); Thu, 20 Aug 2020 11:51:45 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:43123 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728209AbgHTPvl (ORCPT ); Thu, 20 Aug 2020 11:51:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597938699; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=R6ghZf9v2o9kk/8rogKtOdOOtqVr3hm3Y5dvwh2/Dy0=; b=g2Ohspesn9N6QBM2rCCWapOMELf6QJeDDGE/+h4SCmV9gtrJwFk8HsP6tcYK50tjeS6wJN LQ9ZdLCcfg/rvZofEN1P8Jln5gui54Y61l+uj+QojFe9fn1vJsTb/6TanAe3Svp8Jwh9jl NTEU0jbjlM5kZbuYuLyfmEVsuXbY/vE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-265-lMVDHeFMMuKcctS_nkLwSg-1; Thu, 20 Aug 2020 11:51:37 -0400 X-MC-Unique: lMVDHeFMMuKcctS_nkLwSg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 24DE08030B1; Thu, 20 Aug 2020 15:51:36 +0000 (UTC) Received: from optiplex-lnx (unknown [10.3.128.5]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EBDDD19C66; Thu, 20 Aug 2020 15:51:27 +0000 (UTC) Date: Thu, 20 Aug 2020 11:51:25 -0400 From: Rafael Aquini To: Gao Xiang Cc: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Carlos Maiolino , Eric Sandeen , "Huang, Ying" , Yang Shi , Dave Chinner , stable Subject: Re: [PATCH v2] mm, THP, swap: fix allocating cluster for swapfile by mistake Message-ID: <20200820155125.GB3071325@optiplex-lnx> References: <20200820045323.7809-1-hsiangkao@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200820045323.7809-1-hsiangkao@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 20, 2020 at 12:53:23PM +0800, Gao Xiang wrote: > SWP_FS is used to make swap_{read,write}page() go through > the filesystem, and it's only used for swap files over > NFS. So, !SWP_FS means non NFS for now, it could be either > file backed or device backed. Something similar goes with > legacy SWP_FILE. > > 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. > > 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 > > 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: Yang Shi > Cc: Rafael Aquini > Cc: Dave Chinner > Cc: stable > Signed-off-by: Gao Xiang > --- > v1: https://lore.kernel.org/r/20200819195613.24269-1-hsiangkao@redhat.com > > changes since v1: > - improve commit message description > > Hi Andrew, > Kindly consider this one instead if no other concerns... > > Thanks, > Gao Xiang > > 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 > Acked-by: Rafael Aquini