From patchwork Mon May 25 22:08:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Simmons X-Patchwork-Id: 11569593 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 08D9890 for ; Mon, 25 May 2020 22:10:40 +0000 (UTC) Received: from pdx1-mailman02.dreamhost.com (pdx1-mailman02.dreamhost.com [64.90.62.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E60262071A for ; Mon, 25 May 2020 22:10:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E60262071A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lustre-devel-bounces@lists.lustre.org Received: from pdx1-mailman02.dreamhost.com (localhost [IPv6:::1]) by pdx1-mailman02.dreamhost.com (Postfix) with ESMTP id 22A1524757A; Mon, 25 May 2020 15:09:54 -0700 (PDT) X-Original-To: lustre-devel@lists.lustre.org Delivered-To: lustre-devel-lustre.org@pdx1-mailman02.dreamhost.com Received: from smtp4.ccs.ornl.gov (smtp4.ccs.ornl.gov [160.91.203.40]) by pdx1-mailman02.dreamhost.com (Postfix) with ESMTP id ABFE5248326 for ; Mon, 25 May 2020 15:08:43 -0700 (PDT) Received: from star.ccs.ornl.gov (star.ccs.ornl.gov [160.91.202.134]) by smtp4.ccs.ornl.gov (Postfix) with ESMTP id 77F4B1006247; Mon, 25 May 2020 18:08:27 -0400 (EDT) Received: by star.ccs.ornl.gov (Postfix, from userid 2004) id 773F1499; Mon, 25 May 2020 18:08:27 -0400 (EDT) From: James Simmons To: Andreas Dilger , Oleg Drokin , NeilBrown Date: Mon, 25 May 2020 18:08:20 -0400 Message-Id: <1590444502-20533-44-git-send-email-jsimmons@infradead.org> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1590444502-20533-1-git-send-email-jsimmons@infradead.org> References: <1590444502-20533-1-git-send-email-jsimmons@infradead.org> Subject: [lustre-devel] [PATCH 43/45] lustre: llite: check if page truncated in ll_write_begin() X-BeenThere: lustre-devel@lists.lustre.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "For discussing Lustre software development." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Wang Shilong , Lustre Development List MIME-Version: 1.0 Errors-To: lustre-devel-bounces@lists.lustre.org Sender: "lustre-devel" From: Wang Shilong See following function flows: CPU0 CPU1: |->grab_cache_page_nowait |->find_get_page |->__find_get_page (page unlocked) |->truncate page |->trylock_page -->page might has been truncated after So it is possible that page might has been truncated after grab_cache_page_nowait() return even page lock is held. We need check wheather vmpage->mapping change in ll_write_begin() otherwise, we will have truncated page with NULL mapping, which will trigger assertions in vvp_set_pagevec_dirty(). This patch also fix assertion string doesn't end in newline. WC-bug-id: https://jira.whamcloud.com/browse/LU-13493 Lustre-commit: 985de582849df ("LU-13493 llite: check if page truncated in ll_write_begin()") Signed-off-by: Wang Shilong Reviewed-on: https://review.whamcloud.com/38425 Reviewed-by: Andreas Dilger Reviewed-by: Bobi Jam Reviewed-by: Oleg Drokin Signed-off-by: James Simmons --- fs/lustre/llite/rw26.c | 16 +++++++++++++--- fs/lustre/llite/vvp_io.c | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/fs/lustre/llite/rw26.c b/fs/lustre/llite/rw26.c index dd388b9..7abf3fc 100644 --- a/fs/lustre/llite/rw26.c +++ b/fs/lustre/llite/rw26.c @@ -453,11 +453,12 @@ static int ll_prepare_partial_page(const struct lu_env *env, struct cl_io *io, return result; } -static int ll_tiny_write_begin(struct page *vmpage) +static int ll_tiny_write_begin(struct page *vmpage, + struct address_space *mapping) { /* Page must be present, up to date, dirty, and not in writeback. */ if (!vmpage || !PageUptodate(vmpage) || !PageDirty(vmpage) || - PageWriteback(vmpage)) + PageWriteback(vmpage) || vmpage->mapping != mapping) return -ENODATA; return 0; @@ -483,7 +484,7 @@ static int ll_write_begin(struct file *file, struct address_space *mapping, lcc = ll_cl_find(file); if (!lcc) { vmpage = grab_cache_page_nowait(mapping, index); - result = ll_tiny_write_begin(vmpage); + result = ll_tiny_write_begin(vmpage, mapping); goto out; } @@ -547,6 +548,15 @@ static int ll_write_begin(struct file *file, struct address_space *mapping, } } + /* page was truncated */ + if (mapping != vmpage->mapping) { + CDEBUG(D_VFSTRACE, "page: %lu was truncated\n", index); + unlock_page(vmpage); + put_page(vmpage); + vmpage = NULL; + goto again; + } + page = cl_page_find(env, clob, vmpage->index, vmpage, CPT_CACHEABLE); if (IS_ERR(page)) { result = PTR_ERR(page); diff --git a/fs/lustre/llite/vvp_io.c b/fs/lustre/llite/vvp_io.c index d755551..371d988 100644 --- a/fs/lustre/llite/vvp_io.c +++ b/fs/lustre/llite/vvp_io.c @@ -899,7 +899,7 @@ void vvp_set_pagevec_dirty(struct pagevec *pvec) ClearPageReclaim(pvec->pages[i]); LASSERTF(page->mapping, - "mapping must be set. page %p, page->private (cl_page) %p", + "mapping must be set. page %p, page->private (cl_page) %p\n", page, (void *) page->private); /* Rest of code derived from __set_page_dirty_nobuffers */