From patchwork Mon Nov 12 09:57:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Tikhomirov X-Patchwork-Id: 10678417 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A8E0814BA for ; Mon, 12 Nov 2018 09:58:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 97A9829F60 for ; Mon, 12 Nov 2018 09:58:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8BAAC29F62; Mon, 12 Nov 2018 09:58:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9DD7729F60 for ; Mon, 12 Nov 2018 09:58:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 998C96B0266; Mon, 12 Nov 2018 04:58:26 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 91E476B0269; Mon, 12 Nov 2018 04:58:26 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 799366B026A; Mon, 12 Nov 2018 04:58:26 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-lj1-f199.google.com (mail-lj1-f199.google.com [209.85.208.199]) by kanga.kvack.org (Postfix) with ESMTP id 048C56B0266 for ; Mon, 12 Nov 2018 04:58:26 -0500 (EST) Received: by mail-lj1-f199.google.com with SMTP id h10-v6so2530870ljk.18 for ; Mon, 12 Nov 2018 01:58:25 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id; bh=F3L9+SfIlcMVfSlLHkfsW+oyEl+3/AzUXgq4+r9SpSI=; b=eCAHYJAjLkWX+MkMWrq60cexzYDAVuFa3apv4xxwZ2/FZaPd5ArkzaVYPcQSS32Dut 8xztgBQrCw1ZOA9O528ySBh32B5RtjR6XcZyjCzBRjD6SADYs4WovyPp4icVVNkvZOKK cA6VCFM4y9QRhWJWFvWQOP/XF75fD2mczM3NthDEpdDjO/5LTLpmRQLzYbS6/M3Cjkzi OguYeNgUtfx9NmTm/awZom2+Mmng6eVyZ7LAPV/vcP1rhRgJ6nAovIfS51r43He5aNHk +APfmeMa8gOpZ5BYdPq6UFArTrnoH3y1Qx+ym8U6bqYwGsHL+WdL5kQKgLzXBc8/nEks aVgg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of ptikhomirov@virtuozzo.com designates 185.231.240.75 as permitted sender) smtp.mailfrom=ptikhomirov@virtuozzo.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com X-Gm-Message-State: AGRZ1gJiUtf/QbG3PABrHDpmffJ3A6Utl6w9FjuamLyyPX7Vr6AYwwvi T1vap5aoGPhNe5yt4qq1BSYCISCc+DxsQDg+yYVLmFqmyEnT7LerHvElCe5yBWMcazvkz1MoG7s vdWPioNVYaBWi5K4B0PKD2FqG+/QVjobqXvnRaZ31ok6gZa2nUjpVyaDvqlNTq8jw7g== X-Received: by 2002:a2e:1241:: with SMTP id t62-v6mr181588lje.171.1542016705153; Mon, 12 Nov 2018 01:58:25 -0800 (PST) X-Google-Smtp-Source: AJdET5ccvs2qACePQZBCJZRpATpILURBBuB3HFwW1Xz5ZlMh63iwdz7o4gD3V1iqR06WGRarWnTT X-Received: by 2002:a2e:1241:: with SMTP id t62-v6mr181548lje.171.1542016703820; Mon, 12 Nov 2018 01:58:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542016703; cv=none; d=google.com; s=arc-20160816; b=xt9oRpwK4/ck48juHXNkYEDX4yoSFIpxv49bLxuVfiJkjkwUXcJTcjolDfWaWQzG47 m4C+TT5Tlea+HT3XMESYADVwa4v1FUdMnfrNCo8N8eeV2r7B23+C+6SeoCMaEhfso3ym E1ORLndHjZVEknBxzHyMIXiWKYm0dM85pGygOSwTruaa3+RAXK6dJt9dOjmHrfpx0lqy GsuBUxm4Hkc9DNlslVMHsAQGovEpXvjn6Fzr1dt9dQ0NgPVdT0b6GfL8gpKr2hpTsO/K uxjDNfHya6LopY5OsxSr2zE9TotaM9FvNA/ly8TszZ3zhrqsD/oy2RNJIb2mwrnb/ypl qH4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from; bh=F3L9+SfIlcMVfSlLHkfsW+oyEl+3/AzUXgq4+r9SpSI=; b=MweJh1FGvqviHcHbAyqwWnXHY+TNLvt/pFUuRaBXcLr+foRXbhcXDejzFNiQf7SzYq texNQLg7rqfaNAsPNC+ehnpOpkAebGSa8iNbxZd8sWI8ZXXagJw0RmMECbqJbe/rvMtX mFAQQSUVvk3+XVXkOa4gnw2Qw9pTSJp+ifh0y6OjKzRYIU/+qoIe9CwhLyQOl6rMiWJH 2Ibp40qogNCwav7n+cefs7tAc7npCiVQM4OvT8hW5yfAg88LfqvWv/pGHUJjCD6XddRi +P7fQVqr4dajk3+Dy1DfQoF7XI54qSHHNyg85WWkTpFwbTtnWxtzex324JtKrocJXKVa +Dtw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ptikhomirov@virtuozzo.com designates 185.231.240.75 as permitted sender) smtp.mailfrom=ptikhomirov@virtuozzo.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Received: from relay.sw.ru (relay.sw.ru. [185.231.240.75]) by mx.google.com with ESMTPS id d6-v6si14639686ljg.177.2018.11.12.01.58.23 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Nov 2018 01:58:23 -0800 (PST) Received-SPF: pass (google.com: domain of ptikhomirov@virtuozzo.com designates 185.231.240.75 as permitted sender) client-ip=185.231.240.75; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ptikhomirov@virtuozzo.com designates 185.231.240.75 as permitted sender) smtp.mailfrom=ptikhomirov@virtuozzo.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Received: from [172.16.24.163] (helo=snorch.sw.ru) by relay.sw.ru with esmtp (Exim 4.90_1) (envelope-from ) id 1gM8yk-0005ft-As; Mon, 12 Nov 2018 12:57:58 +0300 From: Pavel Tikhomirov To: Andrew Morton Cc: Vasily Averin , Andrey Ryabinin , Konstantin Khorenko , Pavel Tikhomirov , Johannes Weiner , Mel Gorman , Jan Kara , Matthew Wilcox , Andi Kleen , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH] mm: cleancache: fix corruption on missed inode invalidation Date: Mon, 12 Nov 2018 12:57:34 +0300 Message-Id: <20181112095734.17979-1-ptikhomirov@virtuozzo.com> X-Mailer: git-send-email 2.17.1 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: X-Virus-Scanned: ClamAV using ClamSMTP If all pages are deleted from the mapping by memory reclaim and also moved to the cleancache: __delete_from_page_cache (no shadow case) unaccount_page_cache_page cleancache_put_page page_cache_delete mapping->nrpages -= nr (nrpages becomes 0) We don't clean the cleancache for an inode after final file truncation (removal). truncate_inode_pages_final check (nrpages || nrexceptional) is false no truncate_inode_pages no cleancache_invalidate_inode(mapping) These way when reading the new file created with same inode we may get these trash leftover pages from cleancache and see wrong data instead of the contents of the new file. Fix it by always doing truncate_inode_pages which is already ready for nrpages == 0 && nrexceptional == 0 case and just invalidates inode. Fixes: commit 91b0abe36a7b ("mm + fs: store shadow entries in page cache") To: Andrew Morton Cc: Johannes Weiner Cc: Mel Gorman Cc: Jan Kara Cc: Matthew Wilcox Cc: Andi Kleen Cc: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org Reviewed-by: Vasily Averin Reviewed-by: Andrey Ryabinin Signed-off-by: Pavel Tikhomirov Reviewed-by: Jan Kara --- mm/truncate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/truncate.c b/mm/truncate.c index 45d68e90b703..4c56c19e76eb 100644 --- a/mm/truncate.c +++ b/mm/truncate.c @@ -517,9 +517,9 @@ void truncate_inode_pages_final(struct address_space *mapping) */ xa_lock_irq(&mapping->i_pages); xa_unlock_irq(&mapping->i_pages); - - truncate_inode_pages(mapping, 0); } + + truncate_inode_pages(mapping, 0); } EXPORT_SYMBOL(truncate_inode_pages_final);