Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2574785imm; Mon, 16 Jul 2018 10:13:15 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcq8nVJIpxxyXH7oNs20k3wLQDWHMN5jjnV52efVa5h4VjPt//WP1Uwj5Oz8uEaljo3njym X-Received: by 2002:a63:d10c:: with SMTP id k12-v6mr16544063pgg.49.1531761195680; Mon, 16 Jul 2018 10:13:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531761195; cv=none; d=google.com; s=arc-20160816; b=yN3nyum3jUpzIz4FWjKa74Bf+C2M3bUhKJIZitGcLZMCkIXXmXL0iNSQJeo1bpDi4d 9uUUiZVla5REVT16iddGyAwM/8FOrahn6StqP5qRLPE4n9JteTKrkL2EEkaoTwD4U43m Ii9/O82R/xur8bxKc7EZtu5jg6k6lOZJl9qHTBb5XxJvDKitx2JwJ4yCyDVh5LPTespJ p3MH2qOGlm9N1ngVzqiosj6u4xHDG4stbqdF/qu/M78gpBBhb14JJiwD1bhODixRG0z9 e49xQxKTf8Cs/I1kVmz7CBuSzrSD5KWgt4j+W0nbCv8fb6VgXPlYTx4SrzDVz1XM7KCX 5i0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:arc-authentication-results; bh=zXjZdsI+rGRMd290/1MRn8K51F4sLlAegV0MP8DbO0s=; b=FfzzQMDs3fnYSCLv2u9pTATDaEwCgKObH+12pLDliLbvfUiYu7TjIJsoC+qAKgCmbx Pcu4qzQ08Shjb1NmygQAso9ppzcwFmnikJORlKi5nz5+3WUnl6ABihtqY0Q9w7jQF79B sZrTSa38l2od8EsqUZvGRUKpn+b10qlO+qW3/4aCGFqRDggl/FOPZdnBXKvK8qKTg316 E/tRbWcY9C5JqrdQcoZMHmV3Yf7103C8w8SqfzyccAbAvtFC4lhMxUtrrAgsBzro3mdn 4/CmQGxRzp09WFN39z+J2+TbbWOGbFUrXHS8iSj+rVHvXAcycOTJL5Zr8ZNMu7FGS7I9 MB0g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q23-v6si30242091pgl.275.2018.07.16.10.13.00; Mon, 16 Jul 2018 10:13:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730598AbeGPRjh (ORCPT + 99 others); Mon, 16 Jul 2018 13:39:37 -0400 Received: from mga07.intel.com ([134.134.136.100]:7574 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727970AbeGPRjh (ORCPT ); Mon, 16 Jul 2018 13:39:37 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Jul 2018 10:11:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,362,1526367600"; d="scan'208";a="65094363" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by FMSMGA003.fm.intel.com with ESMTP; 16 Jul 2018 10:11:18 -0700 Subject: [PATCH v2 11/14] filesystem-dax: Make mount time pfn validation a debug check From: Dan Williams To: akpm@linux-foundation.org Cc: Jan Kara , Christoph Hellwig , Ross Zwisler , vishal.l.verma@intel.com, linux-mm@kvack.org, jack@suse.cz, linux-nvdimm@lists.01.org, linux-kernel@vger.kernel.org Date: Mon, 16 Jul 2018 10:01:19 -0700 Message-ID: <153176047958.12695.16209413909835344164.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <153176041838.12695.3365448145295112857.stgit@dwillia2-desk3.amr.corp.intel.com> References: <153176041838.12695.3365448145295112857.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-2-gc94f MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Do not ask for dax_direct_access() to retrieve a pfn in the DAX_DRIVER_DEBUG=n case. This avoids an early call to memmap_sync() in the driver. Now that QUEUE_FLAG_DAX usage has been fixed the validation of the pfn is only useful for dax driver developers. It is safe to assume that pmem, dcssblk, and device-mapper-dax are correct with respect to dax operation, so only retrieve the pfn for debug builds when qualifying a new dax driver, if one ever arrives. The moves the first consumption of a pfn from ->direct_access() to the first dax mapping fault, rather than initial filesystem mount. I.e. more time for memmap init to run in the background. Cc: Jan Kara Cc: Christoph Hellwig Cc: Ross Zwisler Signed-off-by: Dan Williams --- drivers/dax/Kconfig | 10 ++++++++ drivers/dax/super.c | 64 ++++++++++++++++++++++++++++++++------------------- 2 files changed, 50 insertions(+), 24 deletions(-) diff --git a/drivers/dax/Kconfig b/drivers/dax/Kconfig index e0700bf4893a..b32f8827b983 100644 --- a/drivers/dax/Kconfig +++ b/drivers/dax/Kconfig @@ -9,6 +9,16 @@ menuconfig DAX if DAX +config DAX_DRIVER_DEBUG + bool "DAX: driver debug" + help + Enable validation of the page frame objects returned from a + driver's 'direct_access' operation. This validation is + performed relative to the requirements of the FS_DAX and + FS_DAX_LIMITED configuration options. If you are validating + the implementation of a dax device driver say Y otherwise + say N. + config DEV_DAX tristate "Device DAX: direct access mapping device" depends on TRANSPARENT_HUGEPAGE diff --git a/drivers/dax/super.c b/drivers/dax/super.c index 903d9c473749..65851919e59a 100644 --- a/drivers/dax/super.c +++ b/drivers/dax/super.c @@ -72,6 +72,41 @@ struct dax_device *fs_dax_get_by_bdev(struct block_device *bdev) EXPORT_SYMBOL_GPL(fs_dax_get_by_bdev); #endif +static bool validate_dax_pfn(pfn_t *pfn) +{ + bool dax_enabled = false; + + /* + * Unless debugging a new dax driver, or new dax architecture + * support there is no need to check the pfn. Delay the kernel's + * first need for a dax pfn until first userspace dax fault. + */ + if (!pfn) + return true; + + if (IS_ENABLED(CONFIG_FS_DAX_LIMITED) && pfn_t_special(*pfn)) { + /* + * An arch that has enabled the pmem api should also + * have its drivers support pfn_t_devmap() + * + * This is a developer warning and should not trigger in + * production. dax_flush() will crash since it depends + * on being able to do (page_address(pfn_to_page())). + */ + WARN_ON(IS_ENABLED(CONFIG_ARCH_HAS_PMEM_API)); + dax_enabled = true; + } else if (pfn_t_devmap(*pfn)) { + struct dev_pagemap *pgmap; + + pgmap = get_dev_pagemap(pfn_t_to_pfn(*pfn), NULL); + if (pgmap && pgmap->type == MEMORY_DEVICE_FS_DAX) + dax_enabled = true; + put_dev_pagemap(pgmap); + } + + return dax_enabled; +} + /** * __bdev_dax_supported() - Check if the device supports dax for filesystem * @bdev: block device to check @@ -85,11 +120,10 @@ EXPORT_SYMBOL_GPL(fs_dax_get_by_bdev); bool __bdev_dax_supported(struct block_device *bdev, int blocksize) { struct dax_device *dax_dev; - bool dax_enabled = false; + pfn_t _pfn, *pfn; pgoff_t pgoff; int err, id; void *kaddr; - pfn_t pfn; long len; char buf[BDEVNAME_SIZE]; @@ -113,8 +147,10 @@ bool __bdev_dax_supported(struct block_device *bdev, int blocksize) return false; } + pfn = IS_ENABLED(CONFIG_DAX_DRIVER_DEBUG) ? &_pfn : NULL; + id = dax_read_lock(); - len = dax_direct_access(dax_dev, pgoff, 1, &kaddr, &pfn); + len = dax_direct_access(dax_dev, pgoff, 1, &kaddr, pfn); dax_read_unlock(id); put_dax(dax_dev); @@ -125,27 +161,7 @@ bool __bdev_dax_supported(struct block_device *bdev, int blocksize) return false; } - if (IS_ENABLED(CONFIG_FS_DAX_LIMITED) && pfn_t_special(pfn)) { - /* - * An arch that has enabled the pmem api should also - * have its drivers support pfn_t_devmap() - * - * This is a developer warning and should not trigger in - * production. dax_flush() will crash since it depends - * on being able to do (page_address(pfn_to_page())). - */ - WARN_ON(IS_ENABLED(CONFIG_ARCH_HAS_PMEM_API)); - dax_enabled = true; - } else if (pfn_t_devmap(pfn)) { - struct dev_pagemap *pgmap; - - pgmap = get_dev_pagemap(pfn_t_to_pfn(pfn), NULL); - if (pgmap && pgmap->type == MEMORY_DEVICE_FS_DAX) - dax_enabled = true; - put_dev_pagemap(pgmap); - } - - if (!dax_enabled) { + if (!validate_dax_pfn(pfn)) { pr_debug("%s: error: dax support not enabled\n", bdevname(bdev, buf)); return false;