From patchwork Tue Sep 22 17:46:19 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ross Zwisler X-Patchwork-Id: 7241941 Return-Path: X-Original-To: patchwork-linux-nvdimm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 5FAFE9F32B for ; Tue, 22 Sep 2015 17:47:22 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8158220A2A for ; Tue, 22 Sep 2015 17:47:21 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 98F0F20A29 for ; Tue, 22 Sep 2015 17:47:20 +0000 (UTC) Received: from ml01.vlan14.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 6C75261507; Tue, 22 Sep 2015 10:47:20 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by ml01.01.org (Postfix) with ESMTP id 64FC861505 for ; Tue, 22 Sep 2015 10:47:19 -0700 (PDT) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga103.fm.intel.com with ESMTP; 22 Sep 2015 10:46:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.17,574,1437462000"; d="scan'208";a="566395545" Received: from theros.lm.intel.com ([10.232.112.60]) by FMSMGA003.fm.intel.com with ESMTP; 22 Sep 2015 10:46:48 -0700 From: Ross Zwisler To: linux-kernel@vger.kernel.org Subject: [PATCH] dax: fix NULL pointer in __dax_pmd_fault() Date: Tue, 22 Sep 2015 11:46:19 -0600 Message-Id: <1442943979-1931-1-git-send-email-ross.zwisler@linux.intel.com> X-Mailer: git-send-email 2.1.0 Cc: linux-nvdimm@lists.01.org, Dave Chinner , Alexander Viro , linux-fsdevel@vger.kernel.org, "Kirill A. Shutemov" X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, 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 The following commit: commit 46c043ede471 ("mm: take i_mmap_lock in unmap_mapping_range() for DAX") moved some code in __dax_pmd_fault() that was responsible for zeroing newly allocated PMD pages. The new location didn't properly set up 'kaddr', though, so when run this code resulted in a NULL pointer BUG. Fix this by getting the correct 'kaddr' via bdev_direct_access(), and only make the second call to bdev_direct_access() if we don't already have a PFN from the first call. Signed-off-by: Ross Zwisler Reported-by: Dan Williams --- fs/dax.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/fs/dax.c b/fs/dax.c index 7ae6df7..08ac2bd 100644 --- a/fs/dax.c +++ b/fs/dax.c @@ -532,7 +532,7 @@ int __dax_pmd_fault(struct vm_area_struct *vma, unsigned long address, void __pmem *kaddr; pgoff_t size, pgoff; sector_t block, sector; - unsigned long pfn; + unsigned long pfn = 0; int result = 0; /* Fall back to PTEs if we're going to COW */ @@ -569,8 +569,20 @@ int __dax_pmd_fault(struct vm_area_struct *vma, unsigned long address, if (!buffer_size_valid(&bh) || bh.b_size < PMD_SIZE) goto fallback; + sector = bh.b_blocknr << (blkbits - 9); + if (buffer_unwritten(&bh) || buffer_new(&bh)) { int i; + + length = bdev_direct_access(bh.b_bdev, sector, &kaddr, &pfn, + bh.b_size); + if (length < 0) { + result = VM_FAULT_SIGBUS; + goto out; + } + if ((length < PMD_SIZE) || (pfn & PG_PMD_COLOUR)) + goto fallback; + for (i = 0; i < PTRS_PER_PMD; i++) clear_pmem(kaddr + i * PAGE_SIZE, PAGE_SIZE); wmb_pmem(); @@ -623,15 +635,16 @@ int __dax_pmd_fault(struct vm_area_struct *vma, unsigned long address, result = VM_FAULT_NOPAGE; spin_unlock(ptl); } else { - sector = bh.b_blocknr << (blkbits - 9); - length = bdev_direct_access(bh.b_bdev, sector, &kaddr, &pfn, - bh.b_size); - if (length < 0) { - result = VM_FAULT_SIGBUS; - goto out; + if (pfn == 0) { + length = bdev_direct_access(bh.b_bdev, sector, &kaddr, + &pfn, bh.b_size); + if (length < 0) { + result = VM_FAULT_SIGBUS; + goto out; + } + if ((length < PMD_SIZE) || (pfn & PG_PMD_COLOUR)) + goto fallback; } - if ((length < PMD_SIZE) || (pfn & PG_PMD_COLOUR)) - goto fallback; result |= vmf_insert_pfn_pmd(vma, address, pmd, pfn, write); }