From patchwork Wed Jul 15 20:44:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Simmons X-Patchwork-Id: 11666239 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 58609618 for ; Wed, 15 Jul 2020 20:46:21 +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 4231920672 for ; Wed, 15 Jul 2020 20:46:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4231920672 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 1C5ED21F80D; Wed, 15 Jul 2020 13:45:57 -0700 (PDT) X-Original-To: lustre-devel@lists.lustre.org Delivered-To: lustre-devel-lustre.org@pdx1-mailman02.dreamhost.com Received: from smtp3.ccs.ornl.gov (smtp3.ccs.ornl.gov [160.91.203.39]) by pdx1-mailman02.dreamhost.com (Postfix) with ESMTP id B02F421F7FB for ; Wed, 15 Jul 2020 13:45:28 -0700 (PDT) Received: from star.ccs.ornl.gov (star.ccs.ornl.gov [160.91.202.134]) by smtp3.ccs.ornl.gov (Postfix) with ESMTP id 9A15649B; Wed, 15 Jul 2020 16:45:20 -0400 (EDT) Received: by star.ccs.ornl.gov (Postfix, from userid 2004) id 981498D; Wed, 15 Jul 2020 16:45:20 -0400 (EDT) From: James Simmons To: Andreas Dilger , Oleg Drokin , NeilBrown Date: Wed, 15 Jul 2020 16:44:59 -0400 Message-Id: <1594845918-29027-19-git-send-email-jsimmons@infradead.org> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1594845918-29027-1-git-send-email-jsimmons@infradead.org> References: <1594845918-29027-1-git-send-email-jsimmons@infradead.org> Subject: [lustre-devel] [PATCH 18/37] lustre: llite: Fix lock ordering in pagevec_dirty 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: Shaun Tancheff , Lustre Development List MIME-Version: 1.0 Errors-To: lustre-devel-bounces@lists.lustre.org Sender: "lustre-devel" From: Shaun Tancheff In vvp_set_pagevec_dirty lock order between i_pages and lock_page_memcg was inverted with the expectation that no other users would conflict. However in vvp_page_completion_write the call to test_clear_page_writeback does expect to be able to lock_page_memcg then lock i_pages which appears to conflict with the original analysis. The reported case shows as RCU stalls with vvp_set_pagevec_dirty blocked attempting to lock i_pages. Fixes: f8a5fb036ae ("lustre: vvp: dirty pages with pagevec") HPE-bug-id: LUS-8798 WC-bug-id: https://jira.whamcloud.com/browse/LU-13746 Lustre-commit: c4ed9b0fb1013 ("LU-13476 llite: Fix lock ordering in pagevec_dirty") Signed-off-by: Shaun Tancheff Reviewed-on: https://review.whamcloud.com/38317 Reviewed-by: Wang Shilong Reviewed-by: Patrick Farrell Reviewed-by: Oleg Drokin Signed-off-by: James Simmons --- fs/lustre/llite/vvp_io.c | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/fs/lustre/llite/vvp_io.c b/fs/lustre/llite/vvp_io.c index 8edd3c1..7627431 100644 --- a/fs/lustre/llite/vvp_io.c +++ b/fs/lustre/llite/vvp_io.c @@ -897,19 +897,31 @@ void vvp_set_pagevec_dirty(struct pagevec *pvec) struct page *page = pvec->pages[0]; struct address_space *mapping = page->mapping; unsigned long flags; + unsigned long skip_pages = 0; int count = pagevec_count(pvec); int dirtied = 0; - int i = 0; - - /* From set_page_dirty */ - for (i = 0; i < count; i++) - ClearPageReclaim(pvec->pages[i]); + int i; + BUILD_BUG_ON(PAGEVEC_SIZE > BITS_PER_LONG); LASSERTF(page->mapping, "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 */ + for (i = 0; i < count; i++) { + page = pvec->pages[i]; + + ClearPageReclaim(page); + + lock_page_memcg(page); + if (TestSetPageDirty(page)) { + /* page is already dirty .. no extra work needed + * set a flag for the i'th page to be skipped + */ + unlock_page_memcg(page); + skip_pages |= (1 << i); + } + } + xa_lock_irqsave(&mapping->i_pages, flags); /* Notes on differences with __set_page_dirty_nobuffers: @@ -920,17 +932,13 @@ void vvp_set_pagevec_dirty(struct pagevec *pvec) * 3. No mapping is impossible. (Race w/truncate mentioned in * dirty_nobuffers should be impossible because we hold the page lock.) * 4. All mappings are the same because i/o is only to one file. - * 5. We invert the lock order on lock_page_memcg(page) and the mapping - * xa_lock, but this is the only function that should use that pair of - * locks and it can't race because Lustre locks pages throughout i/o. */ for (i = 0; i < count; i++) { page = pvec->pages[i]; - lock_page_memcg(page); - if (TestSetPageDirty(page)) { - unlock_page_memcg(page); + /* if the i'th page was unlocked above, skip it here */ + if ((skip_pages >> i) & 1) continue; - } + LASSERTF(page->mapping == mapping, "all pages must have the same mapping. page %p, mapping %p, first mapping %p\n", page, page->mapping, mapping);