Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3881920imu; Mon, 12 Nov 2018 02:00:50 -0800 (PST) X-Google-Smtp-Source: AJdET5fCrI4bcz4ZUgzStBecISh6suZBdhq8ouhLCxGUgWHpGKOfbgbSnwS42MPSSdI4yVnXjMvT X-Received: by 2002:a63:cf08:: with SMTP id j8mr255641pgg.113.1542016850487; Mon, 12 Nov 2018 02:00:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542016850; cv=none; d=google.com; s=arc-20160816; b=JE49NDUKxFCsx8qUN7J72d50utpDCP+u/ymDt+PQSLGlF9FaZw9SwvRoN5VDhXZMLF 1a3yO1IehJZfkMC7nYVh736n6VEUr1lkKHS4adkHgUo0jYPQq0G4idq4eh3lNPqpNLFl P6iP6u2RwfhFKSxT80JjCzdrrdEtIPR+Qs7W5Uh5Q9+3oPzh7w5pP9jYMPOk0wN8w+IF aqusosVqBA9Y9EP61/gYm0DHvAbTswetuVI+vP09riH8So2MJRUx1141+/CSiDQKFEEK Cw5vac9VsJ/Lx/rygBgKCqeL/tg9XREUopSfPRFCBEwNWw9NJiPm1nCy7jimPzTfsriY qc2g== 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; bh=F3L9+SfIlcMVfSlLHkfsW+oyEl+3/AzUXgq4+r9SpSI=; b=jcc8AeMfV+Vrwbf85n8aY2vjP+BmpDBQOXf04CCmxTvGnH8X02sFmPqBBEVloSJ7Bw tLPwkKfW93FLLEeKF73eL4GIy0hsSuAhNxi+UiHg0/16ds6YfS1Mqv7G0BikQnlG4lxG +zc7peIOCJRhveZRqno+tbkDWrHeE2wESvErTqx+tBfRdQQ/0PGD94d/hE6Q4CrxvZtM LFSYz4sTefpbkAX+8DdMhXkSsHsiW/RlZ8cJ3ifKJ2qjRUJKpTeSTbUQkWkhRSNBAOfJ lMTrj7sMQn+Q311vrNfjKmecaFyywS5olf4zvFxwbWN/yKJbE668ymXniQH9vAsdpx/t m6UA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bc11-v6si17010700plb.120.2018.11.12.02.00.35; Mon, 12 Nov 2018 02:00:50 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729447AbeKLTuy (ORCPT + 99 others); Mon, 12 Nov 2018 14:50:54 -0500 Received: from relay.sw.ru ([185.231.240.75]:38806 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727247AbeKLTuy (ORCPT ); Mon, 12 Nov 2018 14:50:54 -0500 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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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); -- 2.17.1