Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp7546109yba; Thu, 2 May 2019 11:46:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqzecE+fHSKEgllCuWTseFr9QoctJmQj5mzuiWUUkINWqLC9T/W3S/kO8APYy4kWsZfV2Jgm X-Received: by 2002:a63:5057:: with SMTP id q23mr5641545pgl.30.1556822783342; Thu, 02 May 2019 11:46:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556822783; cv=none; d=google.com; s=arc-20160816; b=Ca+hgtfFVhiNpwySjUtK4Sv3BiUsmDHMSNaeYpForFRV6Jp4omKUrZdLJS5nIJKzGf Kvk1FuQuxjcj3WlFTjLRQTq8e5LD8J3Jd8J+F+rU8MQ4sYnX2nLqFVq0R31Iy3VHy0Jq JxwrzvY7grLrrLBWwGbvUrywePhSK9NvJg/7Prhmfur7hk6MWcLd0KQ95Vlh6U3v/GFI A0hYihp50fYl7/DDWiZEJGvxaYEWYjN/SezKJ8hyyVP++Ua39gYD98+MorUhbmicgQrl vY05mLhUpIfTZQVMxX/jMy/+A2GtQ9QICqNtYzzhkoNzuBrq5r47eDbEVjRCsEnLU1vq PGrQ== 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 :references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=8p3wsS4SMTLuQgzuXCRhTKHP61mCg8wFpFeHB9x4QIQ=; b=sZMdlJf94ae7oNkhgusxFaM1CELDHm8f4m4/TWPFdzgb+k82DA75hyCp4jQRtpx2Vm 97JvQVgzzFMhXVsrga93QW3kOxbpxzEaPmPzA3uvA43Ls+B7l1/1G9MfoGqBAla7wE8W JiluFk5DTz60yy99jxnlT6uTM+DwU57gSbJ+Q/lF8FSnGXAfJfbfuMhf3vGjICaBvWl3 d3SZN9TC1bm437PUkN1p53vDvyW0KvRA8YSVQwXmkic8bqoM319D/Pf/KTca9p7eXnzJ oODViYfL/3dQIbuNCNcaVpWBTgTCx20Pr1cIVv98XSW83mwglJo4XCIYKnSCME4qSPD0 8aeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@soleen.com header.s=google header.b=Kz0i1rO4; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m86si45387945pfi.235.2019.05.02.11.46.08; Thu, 02 May 2019 11:46:23 -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; dkim=pass header.i=@soleen.com header.s=google header.b=Kz0i1rO4; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726418AbfEBSnv (ORCPT + 99 others); Thu, 2 May 2019 14:43:51 -0400 Received: from mail-qk1-f194.google.com ([209.85.222.194]:42294 "EHLO mail-qk1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726369AbfEBSnr (ORCPT ); Thu, 2 May 2019 14:43:47 -0400 Received: by mail-qk1-f194.google.com with SMTP id x19so2116170qki.9 for ; Thu, 02 May 2019 11:43:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=8p3wsS4SMTLuQgzuXCRhTKHP61mCg8wFpFeHB9x4QIQ=; b=Kz0i1rO4XLenBHe0eXayRavWGw7pvnIFj5qwbjyLHk/JTkjzzMAusXSgeGztfw2jXT AzH2pV256L4jup5CB6VA42JG9lRPJYVWLrtDJCQDUK4EQXR2yj8Q80TY24L817JHSxmh spuIx6Z5shY9RIx1zMZAOkq55ZwXnBzneYb/OA0UTekFNXQmtBsUfMzl9t9YQELg8HsA BLChCaBKaoUuHkqkKNUfkT6HH30xNnSWRNZ6LbGEPBplAiDSCMZ4JS7ykdoiUMoi5e/r DseTc2Ralec84SLyABLLfoTQtUvda4DOocw5xSVDm+Kl2UHGf8zyXwN93fFAbcyycuLE MRaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8p3wsS4SMTLuQgzuXCRhTKHP61mCg8wFpFeHB9x4QIQ=; b=MiZji+umQflqiE6KVlDrk+8NxlvH+a0MVrCooEGZKoTXGkKJpzyV77i33ZF2xZJw6G kNhEjd8i8WOgo8eql9jDcBcxgi8ZJgrQs9nujTx2jVgCaFSv74tXYWwedHcGHQx5K1zY PeUU3MjlRI18aqn8SRgJZDFFfey9jkSGbjai3KtdBbujnhApRqDSPNavSVXHsyYzrE1I G67cVMH4pOceCDshQ56YmvZ59GNG4AsCqPyIe4C1GnDSLK6sUPtpAcnFdXLlxEaKui52 39UFGUcvHrvyPbJhNYkPSNLsFu2kpMDMhxwviPj9FJ10S9DHXCCV0SXKy/frYgEmA+G7 MKbQ== X-Gm-Message-State: APjAAAXue3vyk7lhr7GN8WRcfIEWTKSIOCF6/ojIAitTAz6rmErfVHD1 WFlnfNP66cF3dN7181JjkMX4DQ== X-Received: by 2002:a37:6087:: with SMTP id u129mr4356847qkb.300.1556822626323; Thu, 02 May 2019 11:43:46 -0700 (PDT) Received: from localhost.localdomain (c-73-69-118-222.hsd1.nh.comcast.net. [73.69.118.222]) by smtp.gmail.com with ESMTPSA id 8sm25355751qtr.32.2019.05.02.11.43.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 May 2019 11:43:45 -0700 (PDT) From: Pavel Tatashin To: pasha.tatashin@soleen.com, jmorris@namei.org, sashal@kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-nvdimm@lists.01.org, akpm@linux-foundation.org, mhocko@suse.com, dave.hansen@linux.intel.com, dan.j.williams@intel.com, keith.busch@intel.com, vishal.l.verma@intel.com, dave.jiang@intel.com, zwisler@kernel.org, thomas.lendacky@amd.com, ying.huang@intel.com, fengguang.wu@intel.com, bp@suse.de, bhelgaas@google.com, baiyaowei@cmss.chinamobile.com, tiwai@suse.de, jglisse@redhat.com, david@redhat.com Subject: [v5 3/3] device-dax: "Hotremove" persistent memory that is used like normal RAM Date: Thu, 2 May 2019 14:43:37 -0400 Message-Id: <20190502184337.20538-4-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190502184337.20538-1-pasha.tatashin@soleen.com> References: <20190502184337.20538-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It is now allowed to use persistent memory like a regular RAM, but currently there is no way to remove this memory until machine is rebooted. This work expands the functionality to also allows hotremoving previously hotplugged persistent memory, and recover the device for use for other purposes. To hotremove persistent memory, the management software must first offline all memory blocks of dax region, and than unbind it from device-dax/kmem driver. So, operations should look like this: echo offline > /sys/devices/system/memory/memoryN/state ... echo dax0.0 > /sys/bus/dax/drivers/kmem/unbind Note: if unbind is done without offlining memory beforehand, it won't be possible to do dax0.0 hotremove, and dax's memory is going to be part of System RAM until reboot. Signed-off-by: Pavel Tatashin Reviewed-by: David Hildenbrand --- drivers/dax/dax-private.h | 2 ++ drivers/dax/kmem.c | 41 +++++++++++++++++++++++++++++++++++---- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/drivers/dax/dax-private.h b/drivers/dax/dax-private.h index a45612148ca0..999aaf3a29b3 100644 --- a/drivers/dax/dax-private.h +++ b/drivers/dax/dax-private.h @@ -53,6 +53,7 @@ struct dax_region { * @pgmap - pgmap for memmap setup / lifetime (driver owned) * @ref: pgmap reference count (driver owned) * @cmp: @ref final put completion (driver owned) + * @dax_mem_res: physical address range of hotadded DAX memory */ struct dev_dax { struct dax_region *region; @@ -62,6 +63,7 @@ struct dev_dax { struct dev_pagemap pgmap; struct percpu_ref ref; struct completion cmp; + struct resource *dax_kmem_res; }; static inline struct dev_dax *to_dev_dax(struct device *dev) diff --git a/drivers/dax/kmem.c b/drivers/dax/kmem.c index 4c0131857133..3d0a7e702c94 100644 --- a/drivers/dax/kmem.c +++ b/drivers/dax/kmem.c @@ -71,21 +71,54 @@ int dev_dax_kmem_probe(struct device *dev) kfree(new_res); return rc; } + dev_dax->dax_kmem_res = new_res; return 0; } +#ifdef CONFIG_MEMORY_HOTREMOVE +static int dev_dax_kmem_remove(struct device *dev) +{ + struct dev_dax *dev_dax = to_dev_dax(dev); + struct resource *res = dev_dax->dax_kmem_res; + resource_size_t kmem_start = res->start; + resource_size_t kmem_size = resource_size(res); + int rc; + + /* + * We have one shot for removing memory, if some memory blocks were not + * offline prior to calling this function remove_memory() will fail, and + * there is no way to hotremove this memory until reboot because device + * unbind will succeed even if we return failure. + */ + rc = remove_memory(dev_dax->target_node, kmem_start, kmem_size); + if (rc) { + dev_err(dev, + "DAX region %pR cannot be hotremoved until the next reboot\n", + res); + return rc; + } + + /* Release and free dax resources */ + release_resource(res); + kfree(res); + dev_dax->dax_kmem_res = NULL; + + return 0; +} +#else static int dev_dax_kmem_remove(struct device *dev) { /* - * Purposely leak the request_mem_region() for the device-dax - * range and return '0' to ->remove() attempts. The removal of - * the device from the driver always succeeds, but the region - * is permanently pinned as reserved by the unreleased + * Without hotremove purposely leak the request_mem_region() for the + * device-dax range and return '0' to ->remove() attempts. The removal + * of the device from the driver always succeeds, but the region is + * permanently pinned as reserved by the unreleased * request_mem_region(). */ return 0; } +#endif /* CONFIG_MEMORY_HOTREMOVE */ static struct dax_device_driver device_dax_kmem_driver = { .drv = { -- 2.21.0