From patchwork Fri Jul 6 08:29:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Aneesh Kumar K.V" X-Patchwork-Id: 10511031 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 05D4F600CA for ; Fri, 6 Jul 2018 08:29:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EAA3F28462 for ; Fri, 6 Jul 2018 08:29:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DF35028474; Fri, 6 Jul 2018 08:29:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4B7E928462 for ; Fri, 6 Jul 2018 08:29:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7A7FF6B0274; Fri, 6 Jul 2018 04:29:31 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 6BDD66B0275; Fri, 6 Jul 2018 04:29:31 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 46EEB6B0276; Fri, 6 Jul 2018 04:29:31 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by kanga.kvack.org (Postfix) with ESMTP id DCC7F6B0274 for ; Fri, 6 Jul 2018 04:29:30 -0400 (EDT) Received: by mail-ed1-f72.google.com with SMTP id n2-v6so4349146edr.5 for ; Fri, 06 Jul 2018 01:29:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:in-reply-to:references:message-id; bh=2dFafBtElC09D3AMdAdCO/4+xiuHhUycE9LD+Aujalw=; b=sC5dtWPrQbNr4R9cr1yASdoHANV7gfAUOIYSdstfMNKH+0xcywdHG6ji0yvcaY/dlN GLZrrYQm9EwSqwBDFrX5Qd2/P21/HCeOPxPsoRY2nP7wiaGTDi6Vc2DQEsUElS2Qc0cj JFeuZFYD7RT0q2bFfZwLMMYdfn1wUuH63c0IjSzo4nZfHfrAtw+zRd4PB32L0sJWF1Fd +jL4DyBZK+h/JYspdhf1fOTZtLwSfcFavnldz+mNk+0EKv6YvB5Is8tFnMmAn3PCcckt bgA2+NKep6OCG8uD1kD8sXz8Y+ypqL1d2zRs/yMX77K0f8MXSiUXHhbIaQp+O9pTeyPK ovvQ== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.158.5 as permitted sender) smtp.mailfrom=aneesh.kumar@linux.ibm.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com X-Gm-Message-State: APt69E1zNApj3ZSdVWlJqvBqKRA7qIIBbyoevAWKhuqEODsBi/6Ghcci RKq9XNqYs6fIRbvNjypGOf5clKVVshG5hmK30KbBQKcERw4RYxNbHXfOW9Y2R+oFTskmP51A+xU jjR4DUYC7Q/HrHvnXT5CNVmhLqUxfilPTk4aVkVZ+N/IxaTV7LEny7GHP/XhGie2cEQ== X-Received: by 2002:a50:9f8a:: with SMTP id c10-v6mr10025307edf.17.1530865770447; Fri, 06 Jul 2018 01:29:30 -0700 (PDT) X-Google-Smtp-Source: AAOMgpec85HON0Pme+Qwen8hR1h57Rhk/iwRjZyNaVHr2LLjI5Du1vi3KKBuDv4ZYqUUTCLiwWiE X-Received: by 2002:a50:9f8a:: with SMTP id c10-v6mr10025250edf.17.1530865769530; Fri, 06 Jul 2018 01:29:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530865769; cv=none; d=google.com; s=arc-20160816; b=dEW7yV6+dOVxqrGuv7zpKZuD61p6J58eIDDFzwM79wuVZVSl3ni46tNRiPJZfL/VoO VEioXy+ZKtRa/FR0LJ83y1Pi9JwqzmrhdsYuCA58nnAvp9HlDsmmUREM473C/9Uu1y6W idhkZpb4RfbaZme6KGSUZedd6zSmMFDwOdXYtLCGjiolcC54qdlOQ3iAdR/KBP+M4z3h aEFUu4+87LkUgRZ0SBy6/Omi6x4lsww73Bab3o1EM78J56SaS/CFUZK7MNh5u23y3TaV dwWPI+rpaoxY8l3p4MKZY0EUtI3nzpyZgtfvJ+u460ccJgCgKUCdjvuCyDm4Bt6EH6JY 6Pqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:references:in-reply-to:date:subject:cc:to:from :arc-authentication-results; bh=2dFafBtElC09D3AMdAdCO/4+xiuHhUycE9LD+Aujalw=; b=a636UGhHsBZQb/B6fFXPnSluDmG/ArbEW4a+fO+pvqvuI1JiPOywIY/VgGbtm6F50g +Uj43+zZkImhOLwxFo29RwtiXDay++Y7rNXInfsGVj4x9wFpZASlrH3gKVASdWqHeU9y RDBrNF2rABCZRDx+NubVjiTvOmVQEDhvjUyLfYLNTV1vPDPPaoIHbBzTHbjJjdDi6GNj pI1nCyVaB4GEfsDbhET+C+dapslGxywfB3iuNbz/JF/skEkXQZG8Q7FXwGU5sEByPQDU XmFdKPqVvLwZyXw0Pram8Wb4WEK3mfmnT1mjRJANaqHFSqjbZH0VzmF8MTHYX7evjt0L QjLQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.158.5 as permitted sender) smtp.mailfrom=aneesh.kumar@linux.ibm.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com. [148.163.158.5]) by mx.google.com with ESMTPS id r16-v6si6857195eds.213.2018.07.06.01.29.29 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 06 Jul 2018 01:29:29 -0700 (PDT) Received-SPF: pass (google.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.158.5 as permitted sender) client-ip=148.163.158.5; Authentication-Results: mx.google.com; spf=pass (google.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.158.5 as permitted sender) smtp.mailfrom=aneesh.kumar@linux.ibm.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: from pps.filterd (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w668SvgI106880 for ; Fri, 6 Jul 2018 04:29:28 -0400 Received: from e17.ny.us.ibm.com (e17.ny.us.ibm.com [129.33.205.207]) by mx0b-001b2d01.pphosted.com with ESMTP id 2k24m58vyc-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 06 Jul 2018 04:29:27 -0400 Received: from localhost by e17.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 6 Jul 2018 04:29:27 -0400 Received: from b01cxnp22035.gho.pok.ibm.com (9.57.198.25) by e17.ny.us.ibm.com (146.89.104.204) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Fri, 6 Jul 2018 04:29:25 -0400 Received: from b01ledav004.gho.pok.ibm.com (b01ledav004.gho.pok.ibm.com [9.57.199.109]) by b01cxnp22035.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w668TOaD6292158 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 6 Jul 2018 08:29:24 GMT Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6DFBF112063; Fri, 6 Jul 2018 04:29:16 -0400 (EDT) Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A227C112061; Fri, 6 Jul 2018 04:29:14 -0400 (EDT) Received: from skywalker.in.ibm.com (unknown [9.124.31.51]) by b01ledav004.gho.pok.ibm.com (Postfix) with ESMTP; Fri, 6 Jul 2018 04:29:14 -0400 (EDT) From: "Aneesh Kumar K.V" To: akpm@linux-foundation.org, Dan Williams , Oliver Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Aneesh Kumar K.V" Subject: [RFC PATCH 2/2] mm/pmem: Add memblock based e820 platform driver Date: Fri, 6 Jul 2018 13:59:11 +0530 X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180706082911.13405-1-aneesh.kumar@linux.ibm.com> References: <20180706082911.13405-1-aneesh.kumar@linux.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18070608-0040-0000-0000-0000044AECCC X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00009318; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000266; SDB=6.01057295; UDB=6.00542444; IPR=6.00835216; MB=3.00022021; MTD=3.00000008; XFM=3.00000015; UTC=2018-07-06 08:29:27 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18070608-0041-0000-0000-000008510C4E Message-Id: <20180706082911.13405-2-aneesh.kumar@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-07-06_02:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1806210000 definitions=main-1807060094 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: X-Virus-Scanned: ClamAV using ClamSMTP This patch steal system RAM and use that to emulate pmem device using the e820 platform driver. This adds a new kernel command line 'pmemmap' which takes the format to allocate memory early in the boot. This memory is later registered as persistent memory range. Based on original patch from Oliver OHalloran Not-Signed-off-by: Aneesh Kumar K.V --- drivers/nvdimm/Kconfig | 13 ++++ drivers/nvdimm/Makefile | 1 + drivers/nvdimm/memblockpmem.c | 115 ++++++++++++++++++++++++++++++++++ 3 files changed, 129 insertions(+) create mode 100644 drivers/nvdimm/memblockpmem.c diff --git a/drivers/nvdimm/Kconfig b/drivers/nvdimm/Kconfig index 50d2a33de441..cbbbcbd4506b 100644 --- a/drivers/nvdimm/Kconfig +++ b/drivers/nvdimm/Kconfig @@ -115,4 +115,17 @@ config OF_PMEM config PMEM_PLATFORM_DEVICE bool +config MEMBLOCK_PMEM + bool "pmemmap= parameter support" + default y + depends on HAVE_MEMBLOCK + select PMEM_PLATFORM_DEVICE + help + Add support for the pmemmap= kernel command line parameter. This is similar + to the memmap= parameter available on ACPI platforms, but it uses generic + kernel facilities (the memblock allocator) to reserve memory rather than adding + to the e820 table. + + Select Y if unsure. + endif diff --git a/drivers/nvdimm/Makefile b/drivers/nvdimm/Makefile index 94f7f29146ce..0215ce0182e9 100644 --- a/drivers/nvdimm/Makefile +++ b/drivers/nvdimm/Makefile @@ -5,6 +5,7 @@ obj-$(CONFIG_ND_BTT) += nd_btt.o obj-$(CONFIG_ND_BLK) += nd_blk.o obj-$(CONFIG_PMEM_PLATFORM_DEVICE) += nd_e820.o obj-$(CONFIG_OF_PMEM) += of_pmem.o +obj-$(CONFIG_MEMBLOCK_PMEM) += memblockpmem.o nd_pmem-y := pmem.o diff --git a/drivers/nvdimm/memblockpmem.c b/drivers/nvdimm/memblockpmem.c new file mode 100644 index 000000000000..d39772b75fcd --- /dev/null +++ b/drivers/nvdimm/memblockpmem.c @@ -0,0 +1,115 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2018 IBM Corporation + */ + +#define pr_fmt(fmt) "memblock pmem: " fmt + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * Align pmem reservations to the section size so we don't have issues with + * memory hotplug + */ +#ifdef CONFIG_SPARSEMEM +#define BOOTPMEM_ALIGN (1UL << SECTION_SIZE_BITS) +#else +#define BOOTPMEM_ALIGN PFN_DEFAULT_ALIGNMENT +#endif + +static __initdata u64 pmem_size; +static __initdata phys_addr_t pmem_stolen_memory; + +static void alloc_pmem_from_memblock(void) +{ + + pmem_stolen_memory = memblock_alloc_base(pmem_size, + BOOTPMEM_ALIGN, + MEMBLOCK_ALLOC_ACCESSIBLE); + if (!pmem_stolen_memory) { + pr_err("Failed to allocate memory for PMEM from memblock\n"); + return; + } + + /* + * Remove from the memblock reserved range + */ + memblock_free(pmem_stolen_memory, pmem_size); + + /* + * Remove from the memblock memory range. + */ + memblock_remove(pmem_stolen_memory, pmem_size); + pr_info("Allocated %ld memory at 0x%lx\n", (unsigned long)pmem_size, + (unsigned long)pmem_stolen_memory); + return; +} + +/* + * pmemmap=ss[KMG] + * + * This is similar to the memremap=offset[KMG]!size[KMG] paramater + * for adding a legacy pmem range to the e820 map on x86, but it's + * platform agnostic. + * + * e.g. pmemmap=16G allocates 16G pmem region + */ +static int __init parse_pmemmap(char *p) +{ + char *old_p = p; + + if (!p) + return -EINVAL; + + pmem_size = memparse(p, &p); + if (p == old_p) + return -EINVAL; + + alloc_pmem_from_memblock(); + return 0; +} +early_param("pmemmap", parse_pmemmap); + +static __init int register_e820_pmem(void) +{ + struct resource *res, *conflict; + struct platform_device *pdev; + + if (!pmem_stolen_memory) + return 0; + + res = kzalloc(sizeof(*res), GFP_KERNEL); + if (!res) + return -1; + + memset(res, 0, sizeof(*res)); + res->start = pmem_stolen_memory; + res->end = pmem_stolen_memory + pmem_size - 1; + res->name = "Persistent Memory (legacy)"; + res->desc = IORES_DESC_PERSISTENT_MEMORY_LEGACY; + res->flags = IORESOURCE_MEM; + + conflict = insert_resource_conflict(&iomem_resource, res); + if (conflict) { + pr_err("%pR conflicts, try insert below %pR\n", res, conflict); + kfree(res); + return -1; + } + /* + * See drivers/nvdimm/e820.c for the implementation, this is + * simply here to trigger the module to load on demand. + */ + pdev = platform_device_alloc("e820_pmem", -1); + + return platform_device_add(pdev); +} +device_initcall(register_e820_pmem);