Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1299613imu; Wed, 16 Jan 2019 16:42:36 -0800 (PST) X-Google-Smtp-Source: ALg8bN70u2ML3xNRUSF3LVwvB0cM6aJy/VVzQJW/fk8oWmIYgsb6axQsiSLf9Na27wkZZKTL1K3y X-Received: by 2002:a63:fe0a:: with SMTP id p10mr11378279pgh.265.1547685756592; Wed, 16 Jan 2019 16:42:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547685756; cv=none; d=google.com; s=arc-20160816; b=eAUE7o2Y9edcayW4IWW+4PzgfhrCmuHvWjomLP9WSs+nQF1KnFYVyNzogDpRjl7L4d 1kHUC96rOwzDO/6beGVj5giki849lVbKBVxoqCw3DxXSjfGvQqzZcfEHmKsO0FsNHmj5 4f15cN998nzmRDt0NuktkAH4k8VmNpwU/mUvKrZ85/lXL56Ur2VTI7Ijam4mFTx/td2L UTsFJYyJnyHNCmYi6SSmihtGJibFncPotPm0ksVddBydOaVxB1F5dB+s8aDvfrjPjxBS +7iOssgtknP+LAYUxP22Ru5vrRI9jbhMUoP4o6eILDlVj81jrv8JFWzBe6SOaNywYJQV DHyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=E7r27cPH6QvmhGZvdPLqpBm2gsIRGHNSXibTSYkggwM=; b=VU33af8XQibSJXg14vnBob/JtbqKY+kJWza9Oqu3p7AUA0vq7MbOmiF52J0juhDye/ fXeclInEaDsGFiuMK/aFL5orOccF/QIaW5S43H8peQiYOvOBv4NaQktjMIPnlFSFXeBl ilznJCObcyU1TUSuQ/FDtNf59FojKcu3up0imPCBZPFq0+QBNtypgCAMeIXy8TAIuUhI dkhASObZ/qm1t/lOigpj6la6Hld5p60keTlxYv0YPMCYUOcWrH7hR5h1ZyD+QDtKDf87 ldD8nqMAv9netjDvH1UEGzTDdnne7q90qFmYZjUOxYcBuDdSetdcZmpLfgDJWFyQZR5I YIKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel-com.20150623.gappssmtp.com header.s=20150623 header.b=Uq5oYQI3; 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 c31si7620571pgc.465.2019.01.16.16.42.21; Wed, 16 Jan 2019 16:42:36 -0800 (PST) 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=@intel-com.20150623.gappssmtp.com header.s=20150623 header.b=Uq5oYQI3; 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 S1732886AbfAPWGc (ORCPT + 99 others); Wed, 16 Jan 2019 17:06:32 -0500 Received: from mail-oi1-f193.google.com ([209.85.167.193]:46309 "EHLO mail-oi1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730742AbfAPWGc (ORCPT ); Wed, 16 Jan 2019 17:06:32 -0500 Received: by mail-oi1-f193.google.com with SMTP id x202so4489540oif.13 for ; Wed, 16 Jan 2019 14:06:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=E7r27cPH6QvmhGZvdPLqpBm2gsIRGHNSXibTSYkggwM=; b=Uq5oYQI3BBApJMKZCnuG5WBTN3n6G2h4ZRMgKM8BG+h7RoRAUOM6LgGgQGS377aiuc BisgBraGLnlxoJmRgqvX/OtHDk3+XpwfDXkzIN+PxyTupd7CHtw9khCI3KqtnZNJdP4D bzr1mJZ+2qlCVY3bLXhbGmWwFMjaB7PYvVwQhBZQXDFczi63Hswr9sokChIJ6S4JeVHV Pe1edn89lbK0QU++lnot2oGVNJNodAeqMwsDZH91kQG6Uw1mthtFlAQ0GCsD88zIGBLB 9YqSNWZvmVI2WwRUn+Y0meelrrKDcjt7Dxw1gwKEyICxs05IwPrtlRUnLahDx/oeFxmV ix5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=E7r27cPH6QvmhGZvdPLqpBm2gsIRGHNSXibTSYkggwM=; b=jEVPfNIIuJwBYD4zz1mRvTfIiSBvl/mS6qyWcLF6SZ/AF1jkTUCR0DmrLmPWy/A6Ns //V2TfTzkSBveaQk6pXpxjMjcABFnwl1YVIZz5xzLIba/+IpiNAtTotC06WcwAypKiqJ X4tFrODc+3Gr8UTT/YB+0FqDJU7Cl03RGxFVFt52lYNRwP0pc98DYJZ+z9NuT21fC9OC yX9QMH/DrGuZ0YSefSYMk9Ed8jH1wc1Z/ZGu7hGSNgPt7zBfgAEQiRBvKznjNJJ3tt7c 0QbnEiZJBO7eEFAmdA3FcPLf+WI2nI8zJHMx/vmLnlR4M4qOOKSPRKd1Y+SUWeah2goX oEkg== X-Gm-Message-State: AJcUukcyuJOEB+3Z0EByHRXS7exS887Dy235TRFdga/c3FIlgv3jIk0O 5o8nQ9jAn+KsZSqffpUC8d62aycnPRZc8Z7y4jz1hQ== X-Received: by 2002:aca:d905:: with SMTP id q5mr3147783oig.0.1547676391437; Wed, 16 Jan 2019 14:06:31 -0800 (PST) MIME-Version: 1.0 References: <20190116181859.D1504459@viggo.jf.intel.com> <20190116181905.12E102B4@viggo.jf.intel.com> <98ab9bc8-8a17-297c-da7c-2e6b5a03ef24@intel.com> In-Reply-To: <98ab9bc8-8a17-297c-da7c-2e6b5a03ef24@intel.com> From: Dan Williams Date: Wed, 16 Jan 2019 14:06:20 -0800 Message-ID: Subject: Re: [PATCH 4/4] dax: "Hotplug" persistent memory for use like normal RAM To: Dave Hansen Cc: Bjorn Helgaas , Dave Hansen , Dave Hansen , Dave Jiang , Ross Zwisler , Vishal L Verma , Tom Lendacky , Andrew Morton , Michal Hocko , linux-nvdimm , Linux Kernel Mailing List , Linux MM , Huang Ying , Wu Fengguang , Borislav Petkov , Yaowei Bai , Takashi Iwai Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 16, 2019 at 1:40 PM Dave Hansen wrote: > > On 1/16/19 1:16 PM, Bjorn Helgaas wrote: > > On Wed, Jan 16, 2019 at 12:25 PM Dave Hansen > > wrote: > >> From: Dave Hansen > >> Currently, a persistent memory region is "owned" by a device driver, > >> either the "Direct DAX" or "Filesystem DAX" drivers. These drivers > >> allow applications to explicitly use persistent memory, generally > >> by being modified to use special, new libraries. > > > > Is there any documentation about exactly what persistent memory is? > > In Documentation/, I see references to pstore and pmem, which sound > > sort of similar, but maybe not quite the same? > > One instance of persistent memory is nonvolatile DIMMS. They're > described in great detail here: Documentation/nvdimm/nvdimm.txt > > >> +config DEV_DAX_KMEM > >> + def_bool y > > > > Is "y" the right default here? I periodically see Linus complain > > about new things defaulting to "on", but I admit I haven't paid enough > > attention to know whether that would apply here. > > > >> + depends on DEV_DAX_PMEM # Needs DEV_DAX_PMEM infrastructure > >> + depends on MEMORY_HOTPLUG # for add_memory() and friends > > Well, it doesn't default to "on for everyone". It inherits the state of > DEV_DAX_PMEM so it's only foisted on folks who have already opted in to > generic pmem support. > > >> +int dev_dax_kmem_probe(struct device *dev) > >> +{ > >> + struct dev_dax *dev_dax = to_dev_dax(dev); > >> + struct resource *res = &dev_dax->region->res; > >> + resource_size_t kmem_start; > >> + resource_size_t kmem_size; > >> + struct resource *new_res; > >> + int numa_node; > >> + int rc; > >> + > >> + /* Hotplug starting at the beginning of the next block: */ > >> + kmem_start = ALIGN(res->start, memory_block_size_bytes()); > >> + > >> + kmem_size = resource_size(res); > >> + /* Adjust the size down to compensate for moving up kmem_start: */ > >> + kmem_size -= kmem_start - res->start; > >> + /* Align the size down to cover only complete blocks: */ > >> + kmem_size &= ~(memory_block_size_bytes() - 1); > >> + > >> + new_res = devm_request_mem_region(dev, kmem_start, kmem_size, > >> + dev_name(dev)); > >> + > >> + if (!new_res) { > >> + printk("could not reserve region %016llx -> %016llx\n", > >> + kmem_start, kmem_start+kmem_size); > > > > 1) It'd be nice to have some sort of module tag in the output that > > ties it to this driver. > > Good point. That should probably be a dev_printk(). > > > 2) It might be nice to print the range in the same format as %pR, > > i.e., "[mem %#010x-%#010x]" with the end included (start + size -1 ). > > Sure, that sounds like a sane thing to do as well. Does %pR protect physical address disclosure to non-root by default? At least the pmem driver is using %pR rather than manually printing raw physical address values, but you would need to create a local modified version of the passed in resource. > >> + return -EBUSY; > >> + } > >> + > >> + /* > >> + * Set flags appropriate for System RAM. Leave ..._BUSY clear > >> + * so that add_memory() can add a child resource. > >> + */ > >> + new_res->flags = IORESOURCE_SYSTEM_RAM; > > > > IIUC, new_res->flags was set to "IORESOURCE_MEM | ..." in the > > devm_request_mem_region() path. I think you should keep at least > > IORESOURCE_MEM so the iomem_resource tree stays consistent. > > > >> + new_res->name = dev_name(dev); > >> + > >> + numa_node = dev_dax->target_node; > >> + if (numa_node < 0) { > >> + pr_warn_once("bad numa_node: %d, forcing to 0\n", numa_node); > > > > It'd be nice to again have a module tag and an indication of what > > range is affected, e.g., %pR of new_res. > > > > You don't save the new_res pointer anywhere, which I guess you intend > > for now since there's no remove or anything else to do with this > > resource? I thought maybe devm_request_mem_region() would implicitly > > save it, but it doesn't; it only saves the parent (iomem_resource, the > > start (kmem_start), and the size (kmem_size)). > > Yeah, that's the intention: removal is currently not supported. I'll > add a comment to clarify. I would clarify that *driver* removal is supported because there's no Linux facility for drivers to fail removal (nothing checks the return code from ->remove()). Instead the protection is that the resource must remain pinned forever. In that case devm_request_mem_region() is the wrong function to use. You want to explicitly use the non-devm request_mem_region() and purposely leak it to keep the memory reserved indefinitely.