From patchwork Wed Apr 16 04:03:36 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: NeilBrown X-Patchwork-Id: 3997581 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 94FB8BFF02 for ; Wed, 16 Apr 2014 04:24:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CBDEB20200 for ; Wed, 16 Apr 2014 04:24:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DE67E2013D for ; Wed, 16 Apr 2014 04:24:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751496AbaDPESt (ORCPT ); Wed, 16 Apr 2014 00:18:49 -0400 Received: from cantor2.suse.de ([195.135.220.15]:38816 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751554AbaDPESr (ORCPT ); Wed, 16 Apr 2014 00:18:47 -0400 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id AAB50AC2B; Wed, 16 Apr 2014 04:18:46 +0000 (UTC) From: NeilBrown To: linux-mm@kvack.org, linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org Date: Wed, 16 Apr 2014 14:03:36 +1000 Subject: [PATCH 08/19] Set PF_FSTRANS while write_cache_pages calls ->writepage Cc: xfs@oss.sgi.com Message-ID: <20140416040336.10604.34673.stgit@notabene.brown> In-Reply-To: <20140416033623.10604.69237.stgit@notabene.brown> References: <20140416033623.10604.69237.stgit@notabene.brown> User-Agent: StGit/0.16 MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP It is normally safe for direct reclaim to enter filesystems even when a page is locked - as can happen if ->writepage allocates memory with GFP_KERNEL (which xfs does). However if a localhost NFS mount is present, then a flush-* thread might hold a page locked and then in direct reclaim, ask nfs to commit an inode (nfs_release_page). When nfsd performs the fsync it might try to lock the same page, which leads to a deadlock. A ->writepage should not allocate much memory, or do so very often, so it is safe to set PF_FSTRANS, and this removes the possible deadlock. This was not detected by lockdep as it doesn't monitor the page lock. It was found as a real deadlock in testing. Signed-off-by: NeilBrown --- mm/page-writeback.c | 3 +++ 1 file changed, 3 insertions(+) -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 7106cb1aca8e..572e70b9a3f7 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -1909,6 +1909,7 @@ retry: for (i = 0; i < nr_pages; i++) { struct page *page = pvec.pages[i]; + unsigned int pflags; /* * At this point, the page may be truncated or @@ -1960,8 +1961,10 @@ continue_unlock: if (!clear_page_dirty_for_io(page)) goto continue_unlock; + current_set_flags_nested(&pflags, PF_FSTRANS); trace_wbc_writepage(wbc, mapping->backing_dev_info); ret = (*writepage)(page, wbc, data); + current_restore_flags_nested(&pflags, PF_FSTRANS); if (unlikely(ret)) { if (ret == AOP_WRITEPAGE_ACTIVATE) { unlock_page(page);