From patchwork Thu Jun 15 22:00:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Verma, Vishal L" X-Patchwork-Id: 13281777 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 1C5AFEB64DB for ; Thu, 15 Jun 2023 22:01:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E779F8E0005; Thu, 15 Jun 2023 18:01:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E29348E0002; Thu, 15 Jun 2023 18:01:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C53A58E0005; Thu, 15 Jun 2023 18:01:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id AF6298E0002 for ; Thu, 15 Jun 2023 18:01:12 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 46B4A1A0B4D for ; Thu, 15 Jun 2023 22:01:12 +0000 (UTC) X-FDA: 80906353584.09.D05B6A6 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by imf22.hostedemail.com (Postfix) with ESMTP id C8508C002B for ; Thu, 15 Jun 2023 22:01:08 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=SAks360s; spf=pass (imf22.hostedemail.com: domain of vishal.l.verma@intel.com designates 134.134.136.126 as permitted sender) smtp.mailfrom=vishal.l.verma@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1686866469; 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=2f7MyWiXtVfzfQ7VI1xeIzkghmA9toSBSNHXzVy05kk=; b=EX9IbsZyom72At6pCe1x+6/67rdB7U+KPSce7kRFjidA9EJwyzCWI3rw+vuqrnoy9lwYq1 LBr2MN+3hDDHNVpajcK3rtJTysa0hUnLzRrkURg2AVYQKclXwMU0sd64i/nEbhvbYTJbG/ TQ/5BlaNedXeMv9kYSX8WUh4t0WAluE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1686866469; a=rsa-sha256; cv=none; b=sMg0g1Y0cyYTmVsG50NdQ9bgqU5rb0zSTq1oNyDR3jjJJUfCPVeyIt1oKzGCY1LnptAjjd LAfNftewTV5t3KiLESc2aDa+6fzzSzZwJK5UnGRq4LnCpJ7HfnNqyFWiQ6Tcn4bgtKM/o+ u/5PgpyajxZeJCz5jmMhdxtMxMCNKoQ= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=SAks360s; spf=pass (imf22.hostedemail.com: domain of vishal.l.verma@intel.com designates 134.134.136.126 as permitted sender) smtp.mailfrom=vishal.l.verma@intel.com; dmarc=pass (policy=none) header.from=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1686866468; x=1718402468; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=LdChvoFmNnlAlHfrYI7/8PGxZ7XvW/yi15/tTemhtfg=; b=SAks360sq1JFjWM6de5Za2sFd3goHYBCANYi7Cl4a+bzcbheUJ9p4m2/ 2Wrz7T//DOuu1kCzug8crXWte6+ueHBe5A3IXC8fy4Ohemq4pbcp23Nd8 Syt+HEOA3jeqv7CC8lkpkQD3YK+8SRmEspTrzWsqrUtuaGxObY1bm/jc0 cadJQE52k0X5U5Fm4f8XzULDi5zlWfS75O+5UzzfsTR69A0Dd8xz50Zpk j/XE+HID0JslcaNOesKZQqFfVYymyXBo5PoeMVBX3dUn8skYv4vAK1Pwy X921+gVFibjedY4f+rFeqWh6jTRNw3sQGlF38YG+uwViVpdQuLLAWHLmr w==; X-IronPort-AV: E=McAfee;i="6600,9927,10742"; a="343791152" X-IronPort-AV: E=Sophos;i="6.00,245,1681196400"; d="scan'208";a="343791152" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Jun 2023 15:01:04 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10742"; a="715770103" X-IronPort-AV: E=Sophos;i="6.00,245,1681196400"; d="scan'208";a="715770103" Received: from smaurice-mobl.amr.corp.intel.com (HELO [192.168.1.200]) ([10.212.120.175]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Jun 2023 15:01:02 -0700 From: Vishal Verma Date: Thu, 15 Jun 2023 16:00:25 -0600 Subject: [PATCH 3/3] dax/kmem: Always enroll hotplugged memory for memmap_on_memory MIME-Version: 1.0 Message-Id: <20230613-vv-kmem_memmap-v1-3-f6de9c6af2c6@intel.com> References: <20230613-vv-kmem_memmap-v1-0-f6de9c6af2c6@intel.com> In-Reply-To: <20230613-vv-kmem_memmap-v1-0-f6de9c6af2c6@intel.com> To: "Rafael J. Wysocki" , Len Brown , Andrew Morton , David Hildenbrand , Oscar Salvador , Dan Williams , Dave Jiang Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org, Huang Ying , Dave Hansen , Vishal Verma X-Mailer: b4 0.13-dev-02a79 X-Developer-Signature: v=1; a=openpgp-sha256; l=3515; i=vishal.l.verma@intel.com; h=from:subject:message-id; bh=LdChvoFmNnlAlHfrYI7/8PGxZ7XvW/yi15/tTemhtfg=; b=owGbwMvMwCXGf25diOft7jLG02pJDCndXTIrHz/Xtq+wu3jBMy+xfr7Z2f+L9vlN3p4Y4pMm5 Fuz/uL9jlIWBjEuBlkxRZa/ez4yHpPbns8TmOAIM4eVCWQIAxenAEzEoZ2R4Z39gVmZulYpD7hq 8jebSH29eWRVeLbZhgq57OPHdj2TtWL4p9A1+afr1TyLVbl3Vb3rfussnLe0fDf3Zh3pBRbef1J 3cAIA X-Developer-Key: i=vishal.l.verma@intel.com; a=openpgp; fpr=F8682BE134C67A12332A2ED07AFA61BEA3B84DFF X-Rspamd-Queue-Id: C8508C002B X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: pyosmftx4rocu13zm7zq935t499z4mt4 X-HE-Tag: 1686866468-7934 X-HE-Meta: U2FsdGVkX1/ExRrdp/AcSTGz5gxq86wnTOcmRFy3eLkrbyyUJ1d2UAceBhWrAJKsEYQQOSqXuU+mGToDTYxwUsmWWNVzM4S9aoL5D+ysCStDsrRDbQRYdouEO3iGKOGe2MrJg1orzMvpnUEC+qsm+OIV3NOhZgFGe85tLIGfYZdub++sb+5nQ17P+fOrAoNWTOzM0tQqzZH0sJlODhd4IFOCU3ugkyCxWy+BhPgrlv9ZHQmCO1qajQVV6ViXAMpWkj1kh71fiV59a8J+4LiLsBl+gSj9K1fxPAMCeVPl8bxgKJQwt9KShHvAcbOM3e6f3hJSpcwkAwK4NnlH/rbqQYGufesv+IZvVg3AVDaorOUtTkNGWWNeVdisj7IkZSLwI+eMkiXLngZs6Hm1SuwE55BlAu9psoGHEItSuWH1ybfKBI/06jqiEaloh8ep9nrZAGUEA1IP+It5TmvmefM00t63bHrGWqsA9ge5MxhHDgMu49NnvXxt5BYYvwEHy25FuT+ppwpj6oBOY5xoOwhSL95PVqqbgdXG8lPUbvG7kVbOlVYaJrPhl5xvY2+J4AWfB0owCumXzeAHrA2j7i+lnhqdSLsQ+RzV7VLdeEd8zZYGI+J9eQpN9OHhjB3S6qorIO7tPiYOPIrpvbcdAwcmsr44xsXzscCAw+6ZyHdkstc9XYNwr4369S3EpEqFGPn3X2cDWirpKn4VRVUTjWVaQInJzg8aaiE5khRG9MGHiDIap/U+9VsAY5zbJ9jcWXkIZ4AHSdoxlLPojjB1kEJcXeoZhmXGWgYehPQTfRA98CGiax5j2euvhQIci3NtPiPFZlv985tLR/GWlm/s3Ux9DnpcLfcBdfUU7P9iNiyf08SI1JOCtN4voc8IsS1m2CT9JPUPIOBdpxjFW9DWp/121WmYVdQHb6UkjfBg5+/yUhwiUwkv5blrrGoTxAr7P8je2eAEUcycj6KidVkKvZf qx4nMU79 94ywWda5w23qmiEbJwJYvzAzVXGNLHCqxHM+hV/VbeuAIuE1p2VzviYgs6N59ZH3prgJwKcFPH1QbGpN5j+W8qzlbePnwe/uEgumemHPVXW6jZRdB3zS4N6WP4eJsI4F141dyBSVGRiUzWlX4Od3YiAbHXA3ozsQBvIsLdm1mbsQFy0+yGTrVJRtOYFK9BYVUMFHSaUyv3/XorcKWhTX+9f7MSRUVtAJ+vkDR1ukHbxJ9ALf8erNXLqXbQ0X+2g9Le0w9HCvnZu861dBXfIKUy0OhMgXLsCf2kZvmep1Gb/mSJV3O5uP/yCG+7x3Ewpy6hoRtGMVVOWxGIVcNcmQ7lmkEyZCiu7DEqsA5Wgp5Jn9XzPU= 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: With DAX memory regions originating from CXL memory expanders or NVDIMMs, the kmem driver may be hot-adding huge amounts of system memory on a system without enough 'regular' main memory to support the memmap for it. To avoid this, ensure that all kmem managed hotplugged memory is added with the MHP_MEMMAP_ON_MEMORY flag to place the memmap on the new memory region being hot added. To do this, call add_memory() in chunks of memory_block_size_bytes() as that is a requirement for memmap_on_memory. Additionally, Use the mhp_flag to force the memmap_on_memory checks regardless of the respective module parameter setting. Cc: "Rafael J. Wysocki" Cc: Len Brown Cc: Andrew Morton Cc: David Hildenbrand Cc: Oscar Salvador Cc: Dan Williams Cc: Dave Jiang Cc: Dave Hansen Cc: Huang Ying Signed-off-by: Vishal Verma --- drivers/dax/kmem.c | 49 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/drivers/dax/kmem.c b/drivers/dax/kmem.c index 7b36db6f1cbd..0751346193ef 100644 --- a/drivers/dax/kmem.c +++ b/drivers/dax/kmem.c @@ -12,6 +12,7 @@ #include #include #include +#include #include "dax-private.h" #include "bus.h" @@ -105,6 +106,7 @@ static int dev_dax_kmem_probe(struct dev_dax *dev_dax) data->mgid = rc; for (i = 0; i < dev_dax->nr_range; i++) { + u64 cur_start, cur_len, remaining; struct resource *res; struct range range; @@ -137,21 +139,42 @@ static int dev_dax_kmem_probe(struct dev_dax *dev_dax) res->flags = IORESOURCE_SYSTEM_RAM; /* - * Ensure that future kexec'd kernels will not treat - * this as RAM automatically. + * Add memory in chunks of memory_block_size_bytes() so that + * it is considered for MHP_MEMMAP_ON_MEMORY + * @range has already been aligned to memory_block_size_bytes(), + * so the following loop will always break it down cleanly. */ - rc = add_memory_driver_managed(data->mgid, range.start, - range_len(&range), kmem_name, MHP_NID_IS_MGID); + cur_start = range.start; + cur_len = memory_block_size_bytes(); + remaining = range_len(&range); + while (remaining) { + mhp_t mhp_flags = MHP_NID_IS_MGID; - if (rc) { - dev_warn(dev, "mapping%d: %#llx-%#llx memory add failed\n", - i, range.start, range.end); - remove_resource(res); - kfree(res); - data->res[i] = NULL; - if (mapped) - continue; - goto err_request_mem; + if (mhp_supports_memmap_on_memory(cur_len, + MHP_MEMMAP_ON_MEMORY)) + mhp_flags |= MHP_MEMMAP_ON_MEMORY; + /* + * Ensure that future kexec'd kernels will not treat + * this as RAM automatically. + */ + rc = add_memory_driver_managed(data->mgid, cur_start, + cur_len, kmem_name, + mhp_flags); + + if (rc) { + dev_warn(dev, + "mapping%d: %#llx-%#llx memory add failed\n", + i, cur_start, cur_start + cur_len - 1); + remove_resource(res); + kfree(res); + data->res[i] = NULL; + if (mapped) + continue; + goto err_request_mem; + } + + cur_start += cur_len; + remaining -= cur_len; } mapped++; }