From patchwork Fri Oct 14 23:58:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 13007529 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 922D1C4332F for ; Fri, 14 Oct 2022 23:58:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2FADF6B0075; Fri, 14 Oct 2022 19:58:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2AA896B007D; Fri, 14 Oct 2022 19:58:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 172196B007E; Fri, 14 Oct 2022 19:58:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 04DCD6B0075 for ; Fri, 14 Oct 2022 19:58:29 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id CA0411206F8 for ; Fri, 14 Oct 2022 23:58:28 +0000 (UTC) X-FDA: 80021221896.17.47E233A Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by imf23.hostedemail.com (Postfix) with ESMTP id 57BC0140032 for ; Fri, 14 Oct 2022 23:58:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1665791908; x=1697327908; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=C/qZLnXcKAFdw6v16/JSbSW5MEboRqnBqKQbL8OhQjQ=; b=Pcok9azHciWzoDwk5sKElNCiUZYxFoHLS58m6ztL6WJuX3tRiDQU6V7W BZIEl9z/kmYzMBN2XyAEkD2kTRN5LJpM1y4gtkiuZ+/nQFdPfRaw2za/Y 5nCC4FJRaeNWm82p3f2TX1JrYWUWoskZqRZXOOhW0ld0Im/wwVTWtfq2c Fyqy77W/clyE8/ZPfLJ2UBmEIfzAsSSnEWG1PRWTCEzT5n8a1kNoaX3Xh ZWNqjMdwCHYhTK7fz54NiYEiYTKcMBkW0EZ+XCGoKbzVI01PlXmaoK/h8 WrvZl/kACqG7BfBJcofNzrdII0RColqb4GoeARDSWmuLRfDYh5Zs4z2zN w==; X-IronPort-AV: E=McAfee;i="6500,9779,10500"; a="367523236" X-IronPort-AV: E=Sophos;i="5.95,185,1661842800"; d="scan'208";a="367523236" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Oct 2022 16:58:27 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10500"; a="630113510" X-IronPort-AV: E=Sophos;i="5.95,185,1661842800"; d="scan'208";a="630113510" Received: from uyoon-mobl.amr.corp.intel.com (HELO dwillia2-xfh.jf.intel.com) ([10.209.90.112]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Oct 2022 16:58:26 -0700 Subject: [PATCH v3 15/25] libnvdimm/pmem: Support pmem block devices without dax From: Dan Williams To: linux-mm@kvack.org Cc: david@fromorbit.com, hch@lst.de, nvdimm@lists.linux.dev, akpm@linux-foundation.org, linux-fsdevel@vger.kernel.org Date: Fri, 14 Oct 2022 16:58:26 -0700 Message-ID: <166579190607.2236710.1230996282258115812.stgit@dwillia2-xfh.jf.intel.com> In-Reply-To: <166579181584.2236710.17813547487183983273.stgit@dwillia2-xfh.jf.intel.com> References: <166579181584.2236710.17813547487183983273.stgit@dwillia2-xfh.jf.intel.com> User-Agent: StGit/0.18-3-g996c MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=Pcok9azH; spf=pass (imf23.hostedemail.com: domain of dan.j.williams@intel.com designates 134.134.136.31 as permitted sender) smtp.mailfrom=dan.j.williams@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1665791908; a=rsa-sha256; cv=none; b=cuZ9NduH/iW34+NLmteylpsZfaBaL1bIsknveAiqYKOHnf5h4Sgio+PvkC8NgKoX/QiIoD o56VSNubReB4zBvRXtDk3E5VVDuXmQ6x08qiYfD3vUhPh15XwUFh/ucyiseT+EsMjYs+Tj 2Sso1hZEb2SOFVAkEey/eijTPsUtIs8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1665791908; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=a9trwZBc+KeRM7FLcSeop9grDbZqq5tr+AizBEGe0mI=; b=y+q5DO2wVKHioyETRd0BTYDeY6OPVF5ytpYFUOmaZ+678Yco+WeZPipxql3qXetaHj8K7U Uu+Gyvgu79S1SI9by8NwhdUBJFfGBO6JFPlPoLByxCSri8r2uPiGF+Qm00OuOf+lIlRYNI 67xdqRbpVW4CLAffn2PeIodIhkSrKZU= X-Rspamd-Server: rspam05 X-Rspam-User: Authentication-Results: imf23.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=Pcok9azH; spf=pass (imf23.hostedemail.com: domain of dan.j.williams@intel.com designates 134.134.136.31 as permitted sender) smtp.mailfrom=dan.j.williams@intel.com; dmarc=pass (policy=none) header.from=intel.com X-Stat-Signature: uqb6t189waxtgn8fxi5q6mw9x11ps4yd X-Rspamd-Queue-Id: 57BC0140032 X-HE-Tag: 1665791908-62937 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: In preparation for CONFIG_DAX growing a CONFIG_MMU dependency add support for pmem to skip dax-device registration in the CONFIG_DAX=n case. alloc_dax() returns NULL in the CONFIG_DAX=n case, ERR_PTR() in the failure case, and a dax-device in the success case. dax_remove_host(), kill_dax() and put_dax() are safe to call if setup_dax() returns 0 because it suceeded, or 0 because CONFIG_DAX=n. Signed-off-by: Dan Williams --- drivers/nvdimm/Kconfig | 2 +- drivers/nvdimm/pmem.c | 47 ++++++++++++++++++++++++++++++----------------- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/drivers/nvdimm/Kconfig b/drivers/nvdimm/Kconfig index 5a29046e3319..027acca1bac4 100644 --- a/drivers/nvdimm/Kconfig +++ b/drivers/nvdimm/Kconfig @@ -19,7 +19,7 @@ if LIBNVDIMM config BLK_DEV_PMEM tristate "PMEM: Persistent memory block device support" default LIBNVDIMM - select DAX + select DAX if MMU select ND_BTT if BTT select ND_PFN if NVDIMM_PFN help diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c index 7e88cd242380..068183ee9bf6 100644 --- a/drivers/nvdimm/pmem.c +++ b/drivers/nvdimm/pmem.c @@ -468,6 +468,32 @@ static const struct dev_pagemap_ops fsdax_pagemap_ops = { .memory_failure = pmem_pagemap_memory_failure, }; +static int setup_dax(struct pmem_device *pmem, struct gendisk *disk, + struct nd_region *nd_region) +{ + struct dax_device *dax_dev; + int rc; + + dax_dev = alloc_dax(pmem, &pmem_dax_ops); + if (IS_ERR(dax_dev)) + return PTR_ERR(dax_dev); + if (!dax_dev) + return 0; + set_dax_nocache(dax_dev); + set_dax_nomc(dax_dev); + if (is_nvdimm_sync(nd_region)) + set_dax_synchronous(dax_dev); + rc = dax_add_host(dax_dev, disk); + if (rc) { + kill_dax(dax_dev); + put_dax(dax_dev); + return rc; + } + dax_write_cache(dax_dev, nvdimm_has_cache(nd_region)); + pmem->dax_dev = dax_dev; + return 0; +} + static int pmem_attach_disk(struct device *dev, struct nd_namespace_common *ndns) { @@ -477,7 +503,6 @@ static int pmem_attach_disk(struct device *dev, struct resource *res = &nsio->res; struct range bb_range; struct nd_pfn *nd_pfn = NULL; - struct dax_device *dax_dev; struct nd_pfn_sb *pfn_sb; struct pmem_device *pmem; struct request_queue *q; @@ -578,24 +603,13 @@ static int pmem_attach_disk(struct device *dev, nvdimm_badblocks_populate(nd_region, &pmem->bb, &bb_range); disk->bb = &pmem->bb; - dax_dev = alloc_dax(pmem, &pmem_dax_ops); - if (IS_ERR(dax_dev)) { - rc = PTR_ERR(dax_dev); - goto out; - } - set_dax_nocache(dax_dev); - set_dax_nomc(dax_dev); - if (is_nvdimm_sync(nd_region)) - set_dax_synchronous(dax_dev); - rc = dax_add_host(dax_dev, disk); + rc = setup_dax(pmem, disk, nd_region); if (rc) - goto out_cleanup_dax; - dax_write_cache(dax_dev, nvdimm_has_cache(nd_region)); - pmem->dax_dev = dax_dev; + goto out; rc = device_add_disk(dev, disk, pmem_attribute_groups); if (rc) - goto out_remove_host; + goto out_dax; if (devm_add_action_or_reset(dev, pmem_release_disk, pmem)) return -ENOMEM; @@ -607,9 +621,8 @@ static int pmem_attach_disk(struct device *dev, dev_warn(dev, "'badblocks' notification disabled\n"); return 0; -out_remove_host: +out_dax: dax_remove_host(pmem->disk); -out_cleanup_dax: kill_dax(pmem->dax_dev); put_dax(pmem->dax_dev); out: