From patchwork Tue Dec 7 09:34:56 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Zhong X-Patchwork-Id: 382162 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id oB79Z8WQ005479 for ; Tue, 7 Dec 2010 09:35:08 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755146Ab0LGJfD (ORCPT ); Tue, 7 Dec 2010 04:35:03 -0500 Received: from mga01.intel.com ([192.55.52.88]:62630 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755137Ab0LGJfB convert rfc822-to-8bit (ORCPT ); Tue, 7 Dec 2010 04:35:01 -0500 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP; 07 Dec 2010 01:35:00 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.59,310,1288594800"; d="scan'208";a="633878438" Received: from pgsmsx603.gar.corp.intel.com ([10.221.43.87]) by fmsmga002.fm.intel.com with ESMTP; 07 Dec 2010 01:34:59 -0800 Received: from pgsmsx509.gar.corp.intel.com (172.30.13.17) by pgsmsx603.gar.corp.intel.com (10.221.43.87) with Microsoft SMTP Server (TLS) id 8.2.254.0; Tue, 7 Dec 2010 17:34:58 +0800 Received: from shsmsx601.ccr.corp.intel.com (10.239.4.112) by PGSMSX509.gar.corp.intel.com (172.30.13.17) with Microsoft SMTP Server (TLS) id 8.2.254.0; Tue, 7 Dec 2010 17:34:58 +0800 Received: from shsmsx502.ccr.corp.intel.com ([10.239.4.96]) by shsmsx601.ccr.corp.intel.com ([10.239.4.112]) with mapi; Tue, 7 Dec 2010 17:34:57 +0800 From: "Zhong, Xin" To: "Zhong, Xin" , "linux-btrfs@vger.kernel.org" Date: Tue, 7 Dec 2010 17:34:56 +0800 Subject: RE: [PATCH] Btrfs: pwrite blocked when writing from the mmaped buffer of the same page Thread-Topic: [PATCH] Btrfs: pwrite blocked when writing from the mmaped buffer of the same page Thread-Index: AcuV8KY96V0eDWZEQhCVLrx82WzWdgAAVO/w Message-ID: <1865303E0DED764181A9D882DEF65FB682F3F80FDF@shsmsx502.ccr.corp.intel.com> References: <1291713902-5149-1-git-send-email-xin.zhong@intel.com> In-Reply-To: <1291713902-5149-1-git-send-email-xin.zhong@intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: en-US MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Tue, 07 Dec 2010 09:35:08 +0000 (UTC) diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index c1faded..805f2ee 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -57,11 +57,15 @@ static noinline int btrfs_copy_from_user(loff_t pos, int num_pages, PAGE_CACHE_SIZE - offset, write_bytes); struct page *page = prepared_pages[pg]; again: - if (unlikely(iov_iter_fault_in_readable(i, count))) - return -EFAULT; - - /* Copy data from userspace to the current page */ - copied = iov_iter_copy_from_user(page, i, offset, count); + /* + * Copy data from userspace to the current page + * + * Disable pagefault to avoid recursive lock since + * the pages are already locked + */ + pagefault_disable(); + copied = iov_iter_copy_from_user_atomic(page, i, offset, count); + pagefault_enable(); /* Flush processor's dcache for this page */ flush_dcache_page(page); @@ -974,6 +978,15 @@ static ssize_t btrfs_file_aio_write(struct kiocb *iocb, if (ret) goto out; + /* + * fault pages before locking them in prepare_pages + * to avoid recursive lock + */ + if (unlikely(iov_iter_fault_in_readable(&i, write_bytes))) { + ret = -EFAULT; + goto out; + } + ret = prepare_pages(root, file, pages, num_pages, pos, first_index, last_index, write_bytes);