From patchwork Mon Nov 12 12:00:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Tikhomirov X-Patchwork-Id: 10678541 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 0FFFE14BD for ; Mon, 12 Nov 2018 12:00:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EE27D29D5B for ; Mon, 12 Nov 2018 12:00:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E1B2A29E9B; Mon, 12 Nov 2018 12:00:16 +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 5CD7229D5B for ; Mon, 12 Nov 2018 12:00:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 592B16B027E; Mon, 12 Nov 2018 07:00:14 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 517B16B027F; Mon, 12 Nov 2018 07:00:14 -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 4070C6B0280; Mon, 12 Nov 2018 07:00:14 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-lj1-f197.google.com (mail-lj1-f197.google.com [209.85.208.197]) by kanga.kvack.org (Postfix) with ESMTP id C7B396B027E for ; Mon, 12 Nov 2018 07:00:13 -0500 (EST) Received: by mail-lj1-f197.google.com with SMTP id e8-v6so2646870ljg.22 for ; Mon, 12 Nov 2018 04:00:13 -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:in-reply-to:references; bh=lPgQrY/hEr6EnH4YxP1qV6ve7x1RyTlRzCugdoO0NYY=; b=JzGuQq1QXGYBJfnowI8rAr3wqc2hLExFxIeXdxo8yLa6l+CSCuXPf7wmpI7Li+w0F4 dlIIG8xOIlttAD5pFUOg2XcyInhp6300HSvhyJGO2vwutDn1NbVQhh5l0hP1zlu908JG HT3vbthJAAZoUNJdT+M5imWmQCfUrrTV7b05QdumdAL5JD6OuLePm7gAcBzOkkkcjOEY 1HPsgyljr0obEyYwd5+dbqXpvh/Wx9eoPWeR3dWL4v45B9/sHNEBMTsstThBW7uZ9y5W iXFdliYQcrKfQPr2USwEmDq4vvAy6zwAg+HE/BsQPFUNFpcYpGy6nWmjV37D/BRzhLyB YHfw== 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: AGRZ1gJb/EUcVoKoyCsCj848IczFG5pA8hwveh1TdlvxI7S513oMJ3Kw NqP56b2ngatOyUb4RboRWxaCXH9/l8PlX/V+6kv3tHXKeh7BatfiPL1YDlmj2dkqImDnKDXKU5o PWmQIDBPk9sB1K4GoIGgxy88I5i5I2UGWKRrszFne+wYCwDauLEIKpNYyUZtXIXkfQA== X-Received: by 2002:a2e:1603:: with SMTP id w3-v6mr485171ljd.33.1542024013209; Mon, 12 Nov 2018 04:00:13 -0800 (PST) X-Google-Smtp-Source: AJdET5drVaM5X/N/jKrb1JGytnAcKDKosx1UQtgvH2DMhwLaXy6FPttUWOcO32r3u4/OtCMLDhYx X-Received: by 2002:a2e:1603:: with SMTP id w3-v6mr485127ljd.33.1542024012231; Mon, 12 Nov 2018 04:00:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542024012; cv=none; d=google.com; s=arc-20160816; b=q3F976dj/ePUk0TeMHPI+X0KqGa7E499pCSwAjVW3iTciyYJEdN3569S+iZN08rq5L qQ6SpJzCa/USwnBBueYTCeheb81yJdSKt4GStYFwZmL174Gchbf15qdp8kjwbXsuwlmI 8/UAffA4iKhzRMcwKTA5n3hF0E1fzUa/G0KxYZ6Z8lGDoWo7dnFRAr+v/Mp3erSxVacj g+Tyo+v0NP8dZkAQhUHSzuK5vdL1XZ0Q4Z/rdebXtpkpnVdUIyESW6Hea8JUXZ4Jw18s 9gLeIV92RY+vNHXNoZ3SB8Uf4JevWKHoxUdsFF1OQkRRpE8tyOCeIuc1xLpmv5tLzjll e8wg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=lPgQrY/hEr6EnH4YxP1qV6ve7x1RyTlRzCugdoO0NYY=; b=rbb3j4UOAqidR4tf3/P/aJhrVWyE4Wz5Y2cmMh94DgHLMCk8H1d0dc1mwnWoUF5Sho MlVzvYC+z0ofQz9cIby0+2d4Y2EsP8jcrLykK2Kw7Ru373IWdernYRqWaKxCNztvbfmp /ycOQakE4ch/vN37GpRkx9Wroq0q5f7SRwdOOF3kWrlz5iwjojGVaJ99PS0qnMIbPyFp LVDBbAxFVEjKx+8DDmJEMr2pqmwwSemUZD4Tchss/YYh/leFnosjnPQMyJv6VqxP0LsY 5SJfJ3x8ZIpZUb2nacRJU15pvJTYKZp4Ld0wNVpMJUKiMWqB+IW5ITjmr3CeZsPDUs9T mjgw== 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 q5-v6si16548373lji.207.2018.11.12.04.00.11 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Nov 2018 04:00:12 -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 1gMAsv-0006JV-RC; Mon, 12 Nov 2018 15:00:05 +0300 From: Pavel Tikhomirov To: Jan Kara Cc: Vasily Averin , Andrey Ryabinin , Konstantin Khorenko , Pavel Tikhomirov , Johannes Weiner , Mel Gorman , Matthew Wilcox , Andi Kleen , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] mm: cleancache: fix corruption on missed inode invalidation Date: Mon, 12 Nov 2018 15:00:03 +0300 Message-Id: <20181112120003.23245-1-ptikhomirov@virtuozzo.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181112113153.GC7175@quack2.suse.cz> References: <20181112113153.GC7175@quack2.suse.cz> 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. v2: add comment 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 Reviewed-by: Jan Kara Signed-off-by: Pavel Tikhomirov --- mm/truncate.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mm/truncate.c b/mm/truncate.c index 45d68e90b703..2c5285767ce5 100644 --- a/mm/truncate.c +++ b/mm/truncate.c @@ -517,9 +517,14 @@ 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); } + + /* + * Cleancache needs notification even if there are no pages or shadow + * entries, else we will leave leftover pages in the cleancache for + * a deleted inode. + */ + truncate_inode_pages(mapping, 0); } EXPORT_SYMBOL(truncate_inode_pages_final);