From patchwork Thu Jun 15 22:00:23 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: 13281776 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 2F754C0015E for ; Thu, 15 Jun 2023 22:01:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EA1158E0003; Thu, 15 Jun 2023 18:01:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DB3E48E0002; Thu, 15 Jun 2023 18:01:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C2C2C8E0003; Thu, 15 Jun 2023 18:01:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id B0C068E0002 for ; Thu, 15 Jun 2023 18:01:11 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 7051B140AAC for ; Thu, 15 Jun 2023 22:01:11 +0000 (UTC) X-FDA: 80906353542.25.4EB488E Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by imf26.hostedemail.com (Postfix) with ESMTP id 8C9CE140028 for ; Thu, 15 Jun 2023 22:01:08 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=AvLS2wCX; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf26.hostedemail.com: domain of vishal.l.verma@intel.com designates 134.134.136.126 as permitted sender) smtp.mailfrom=vishal.l.verma@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1686866468; 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=rj4bV30cPb9K9sKsHExCZ8luQEyBWvqpIuDdC97URtA=; b=5M4q9czgs5NFY7OKClMOFwe5Xa09vSJgqAlAVeasR3+2Ql46n17PuoaGMAiKW1VIMTWPR+ Ggm8EDyAbO3tY+wwBVzZorwjRGxyYGyFTeITLNZJTlnt+lrvguNzXlLy68KVMN4VIwWrLb ne/WidsfbKGfG3W58z+jJOSLrHH8en0= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=AvLS2wCX; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf26.hostedemail.com: domain of vishal.l.verma@intel.com designates 134.134.136.126 as permitted sender) smtp.mailfrom=vishal.l.verma@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1686866468; a=rsa-sha256; cv=none; b=nBxCOwSywjJdB/HKm0nS1Qed+tKMACxBipGZb81H4t8F15dmN3bBTuWS/Mgiv52L+MsBqB EeeEMiDfnOoYxfGfATq0ZaO7HSVadbVO5uJemTV5wn8lrZ2pSaSWUuedyUeOB7Dn9R0tDp OFe6hbBwXA2NQ6sExfCx3ZT7uZMdwsY= 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=y9Fdd4CaXjYhM8c/kYRc/ffM8uFuEd3rHTJq5W9ozIE=; b=AvLS2wCXUvm3RMxSCpojLhm6Ty+tjsV4BqRFwsVSgZGevO2uU9H4LfcT gFf1lHqnpAA+2cALnHyHQ+CNwWh94SDZV2cip0VYhZaPVMne4cZCkSrjI aD2D1ZDjofqy807bEGc+aMuqFV9M9BvmDgiadt+JnL5EoAPrjgYE1VLVn 8jDzAfnvRbgelRx868KIuB7DzUx9MjQcvNM/+IuJJUrb5QYDXzZAF6P7v DT8XXhkE8NQ52qHiA9DYD8GCPZGMmSISt3ase2wFwidN+zTeW/NZJ18DK 9fDW3eHMcVNv+5wBuCHUIcTvrNBGQMoPy0hbqanXqzd9Eftgd3wFvzGYY g==; X-IronPort-AV: E=McAfee;i="6600,9927,10742"; a="343791134" X-IronPort-AV: E=Sophos;i="6.00,245,1681196400"; d="scan'208";a="343791134" 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:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10742"; a="715770091" X-IronPort-AV: E=Sophos;i="6.00,245,1681196400"; d="scan'208";a="715770091" 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:00 -0700 From: Vishal Verma Date: Thu, 15 Jun 2023 16:00:23 -0600 Subject: [PATCH 1/3] mm/memory_hotplug: Allow an override for the memmap_on_memory param MIME-Version: 1.0 Message-Id: <20230613-vv-kmem_memmap-v1-1-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=5348; i=vishal.l.verma@intel.com; h=from:subject:message-id; bh=y9Fdd4CaXjYhM8c/kYRc/ffM8uFuEd3rHTJq5W9ozIE=; b=owGbwMvMwCXGf25diOft7jLG02pJDCndXdJbnAJ++yhZVS3cvOTdxff5fUeOOrvs/W7jtJclP WTj/uU/OkpZGMS4GGTFFFn+7vnIeExuez5PYIIjzBxWJpAhDFycAjARjZWMDOcv2YmZnLWzVvS7 ZmDA/pxvkXo8w7k/p3WUixhuPrsgsYuR4cuznZa5advZfkrwz5A/cUmgei/3H+NlJ99c6hPf5ON 4lxcA X-Developer-Key: i=vishal.l.verma@intel.com; a=openpgp; fpr=F8682BE134C67A12332A2ED07AFA61BEA3B84DFF X-Rspamd-Queue-Id: 8C9CE140028 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: jtmtnnkhpnp44t7ki9ynqfhxca6wujyc X-HE-Tag: 1686866468-115961 X-HE-Meta: U2FsdGVkX1/1w/1Qtv26FoZWH35qTchQFUZDyKt5+abdnojzU3kOtSzzcb7/3cJvuuRhlqDSZ+qHwzGodmxhjaVsCru/FqICW305zcPSoU80lwufR18I8XBNCpKiMc4FWAWpeHnksqC+FA0vI1NAnembePGo3FdPE+s63gMCq8T1/g0Q80fLGQvKRGwaWA3JYa+vDIsODrhYaLsyB1GSdTqCgHFb0QIVzCSGaUhjzbNdha2haRHR+eoPtdRXX0VR5HQ3oDla+vvNYs5Z0yo+wt5tGsbd5FRuGqRV0SQ5/USPUFnRMPwa40P8iHt4mpreEJ3DuqVeOwOJI28MZKCicJaqmQBNrd3hGr8IZxWQAVIH3EDpsZiF5teyah3Pqrb4+c1lrFW1Kktz1rOj2cEfFQu1pjw89x5t1fIWKO9LhwtzNfXwUWxdw+nXfm9ZHJuB31aNmYGlDL4SJuvzw4VnLUGAMlnr1by1kDGS61AUtfc5lTPofVMJz+vWnZEtv+WtHGjlnpajeFw/1N/09+8aMEkrntzS8IEXMznMXYvt2rcc8RgYV30axg6ziOLCSgUNa++uUGJYQdLZKJVz8DIdb1ZvfLXYgp1XsfbMrWu5RK6gKZClMKPmSyK3uzv39QeAXY9xZu+A3x3O8qCuFNfg/COwrVn5omBIzsNIDnjWpf6BtSwABkkba5OYEz/PdZLuHm2ns5WmqHqAs2DkdujAJ6FyKbK+bxBCAkp3Ku3eA95tmD19YViD1y8xxY5d+N4jL6KZUrK4p1b/t2lRxio/J9fvizj7rjKyfRLbRCnDt5JGTtb8YlRBWttspqGt5Go5L7w6NGh+U3mClRYrg2Ie3QnXC8bz5G+jM7tPldvca4vGzvo+NqVPbMfHWlgEcZbPTsoFaDHBQHa39sj6EVJbwGnn7yBXCWRrneG8PgGzUGy5tUtCY4B1f8IK6uP105c2s6NsZD+KPC9ERjuWDxN UalWFadT stqaS7CYiqDt1C5mkVlcVDtTFuWsgiIU/o4Hw5Te8MOpt/npKxQTrNCr/3J0Kb0nukMctve1ooiDvM9I1tNPAbE5Z6iqu4Shvz+801/YHUt2NRR7/nFgMyjYkh4xfoOF/d7Utqm153GWoCBiHJLiWwXpushQgc2mrOAts1g5mIdodmCM56Gr+YCD1M+SZZ9Vc+ZF89J5GiqGQhMNwU+7OyQr9FVKOKGm4NGbpT11nfqtep1D1WL2SSB00R+DJlGPCgbf9a4iG5ZdIDjB7dHurnJgryoXJRFEbFGknInTrGsyEsjHrlQBmjOaVQ4OeshZQKlU7AAeIo4qcr+OnYTU+HwIM5ZI4Qpjyw6jxxNWuWwHBpJs= 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: For memory hotplug to consider MHP_MEMMAP_ON_MEMORY behavior, the 'memmap_on_memory' module parameter was a hard requirement. In preparation for the dax/kmem driver to use memmap_on_memory semantics, arrange for the module parameter check to be bypassed via the appropriate mhp_flag. Recall that the kmem driver could contribute huge amounts of hotplugged memory originating from special purposes devices such as CXL memory expanders. In some cases memmap_on_memory may be the /only/ way this new memory can be hotplugged. Hence it makes sense for kmem to have a way to force memmap_on_memory without depending on a module param, if all the other conditions for it are met. The only other user of this interface is acpi/acpi_memoryhotplug.c, which only enables the mhp_flag if an initial mhp_supports_memmap_on_memory() test passes. Maintain the existing behavior and semantics for this by performing the initial check from acpi without the MHP_MEMMAP_ON_MEMORY flag, so its decision falls back to the module parameter. 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 --- include/linux/memory_hotplug.h | 2 +- drivers/acpi/acpi_memhotplug.c | 2 +- mm/memory_hotplug.c | 24 ++++++++++++++++-------- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h index 9fcbf5706595..c9ddcd3cad70 100644 --- a/include/linux/memory_hotplug.h +++ b/include/linux/memory_hotplug.h @@ -358,7 +358,7 @@ extern struct zone *zone_for_pfn_range(int online_type, int nid, extern int arch_create_linear_mapping(int nid, u64 start, u64 size, struct mhp_params *params); void arch_remove_linear_mapping(u64 start, u64 size); -extern bool mhp_supports_memmap_on_memory(unsigned long size); +extern bool mhp_supports_memmap_on_memory(unsigned long size, mhp_t mhp_flags); #endif /* CONFIG_MEMORY_HOTPLUG */ #endif /* __LINUX_MEMORY_HOTPLUG_H */ diff --git a/drivers/acpi/acpi_memhotplug.c b/drivers/acpi/acpi_memhotplug.c index 24f662d8bd39..119d3bb49753 100644 --- a/drivers/acpi/acpi_memhotplug.c +++ b/drivers/acpi/acpi_memhotplug.c @@ -211,7 +211,7 @@ static int acpi_memory_enable_device(struct acpi_memory_device *mem_device) if (!info->length) continue; - if (mhp_supports_memmap_on_memory(info->length)) + if (mhp_supports_memmap_on_memory(info->length, 0)) mhp_flags |= MHP_MEMMAP_ON_MEMORY; result = __add_memory(mgid, info->start_addr, info->length, mhp_flags); diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 8e0fa209d533..bb3845830922 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1283,15 +1283,21 @@ static int online_memory_block(struct memory_block *mem, void *arg) return device_online(&mem->dev); } -bool mhp_supports_memmap_on_memory(unsigned long size) +bool mhp_supports_memmap_on_memory(unsigned long size, mhp_t mhp_flags) { unsigned long nr_vmemmap_pages = size / PAGE_SIZE; unsigned long vmemmap_size = nr_vmemmap_pages * sizeof(struct page); unsigned long remaining_size = size - vmemmap_size; /* - * Besides having arch support and the feature enabled at runtime, we - * need a few more assumptions to hold true: + * The MHP_MEMMAP_ON_MEMORY flag indicates a caller that wants to force + * memmap_on_memory (if other conditions are met), regardless of the + * module parameter. drivers/dax/kmem.c is an example, where large + * amounts of hotplug memory may come from, and the only option to + * successfully online all of it is to place the memmap on this memory. + * + * Besides having arch support and the feature enabled at runtime or + * via the mhp_flag, we need a few more assumptions to hold true: * * a) We span a single memory block: memory onlining/offlinin;g happens * in memory block granularity. We don't want the vmemmap of online @@ -1315,10 +1321,12 @@ bool mhp_supports_memmap_on_memory(unsigned long size) * altmap as an alternative source of memory, and we do not exactly * populate a single PMD. */ - return mhp_memmap_on_memory() && - size == memory_block_size_bytes() && - IS_ALIGNED(vmemmap_size, PMD_SIZE) && - IS_ALIGNED(remaining_size, (pageblock_nr_pages << PAGE_SHIFT)); + + if ((mhp_flags & MHP_MEMMAP_ON_MEMORY) || mhp_memmap_on_memory()) + return size == memory_block_size_bytes() && + IS_ALIGNED(vmemmap_size, PMD_SIZE) && + IS_ALIGNED(remaining_size, (pageblock_nr_pages << PAGE_SHIFT)); + return false; } /* @@ -1375,7 +1383,7 @@ int __ref add_memory_resource(int nid, struct resource *res, mhp_t mhp_flags) * Self hosted memmap array */ if (mhp_flags & MHP_MEMMAP_ON_MEMORY) { - if (!mhp_supports_memmap_on_memory(size)) { + if (!mhp_supports_memmap_on_memory(size, mhp_flags)) { ret = -EINVAL; goto error; } From patchwork Thu Jun 15 22:00:24 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: 13281775 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 2A5F1EB64DD for ; Thu, 15 Jun 2023 22:01:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AA6F66B0074; Thu, 15 Jun 2023 18:01:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A57BC8E0002; Thu, 15 Jun 2023 18:01:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 945C36B0075; Thu, 15 Jun 2023 18:01:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 7DAC58E0002 for ; Thu, 15 Jun 2023 18:01:09 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 3AAA340A6F for ; Thu, 15 Jun 2023 22:01:09 +0000 (UTC) X-FDA: 80906353458.06.D2DBCC2 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by imf22.hostedemail.com (Postfix) with ESMTP id 7E88EC0028 for ; Thu, 15 Jun 2023 22:01:05 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=NpiiJP8H; 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=1686866466; 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=tOhzw+U+EZY622P3OkbIoLu3uYzfsPtlO4bPgBdmAiI=; b=c06jCJabHoSixfckYmNT65xgdyWuqeJloEoSFVmuZ+vMsx4zejySPItjBu10+NWyWSPcZa Klxk7VuBvfVk32UQRkcuTln/+ffgiTFDir+pwUKBnphKW+H8APuZwRHmjXsC54RXSMC0QN cDCA32EkFUxWOgxAuSdxem7QhikQyBs= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1686866466; a=rsa-sha256; cv=none; b=zF9G+CZUwE/Gx5SZk/pijwzwnEhOst/ggBwST8eICbGWDKn4zBr5zUC6K45d4KZajtmT23 MhR97RFIL4whHpeaIRxasxDN/9FOUkK4TrrKtDExcCi8IGnA7MQ51uHzxdNKUgzhuukeIa qXE2kj09ZD5AISqVdJNc4/3VF6EBLa0= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=NpiiJP8H; 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=1686866465; x=1718402465; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=U9rnqtpmVZUt30zvfvx/p0VOOSSlAU3FkBQboHUpz0E=; b=NpiiJP8H3KMuqGIC9ccjeHAPUbuuOFMMS98t1b8+7F+rr/3Rqse/iVe0 3Y1gS1h9wwTrZyMmPd7a5YF1KLpOoXsNBuf+5jwgSjHxlnjhh0JrotDX4 vxteu/YK5eut6MBDWb9o7PH9jQBt1RK2hJuPPqp6YZv+gcMXMMDncIwHG bT4ZltmFGtRpNb6XQ8f4uwljQPSTqWieX6YSUlZPLjUNH7yy3Jez1AhKf 1H9LZ13IxNPIpEvr2AifyHognm+r4ymIcnOF/6Nu9Jq8EkK5GNed60BMq 1aV2ZUK6+C4VeRWupLgG1uS6TdjaH6RD29VlyW8xTZmncxBhn3+K7yTkH Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10742"; a="343791143" X-IronPort-AV: E=Sophos;i="6.00,245,1681196400"; d="scan'208";a="343791143" 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:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10742"; a="715770100" X-IronPort-AV: E=Sophos;i="6.00,245,1681196400"; d="scan'208";a="715770100" 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:01 -0700 From: Vishal Verma Date: Thu, 15 Jun 2023 16:00:24 -0600 Subject: [PATCH 2/3] mm/memory_hotplug: Export symbol mhp_supports_memmap_on_memory() MIME-Version: 1.0 Message-Id: <20230613-vv-kmem_memmap-v1-2-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=1128; i=vishal.l.verma@intel.com; h=from:subject:message-id; bh=U9rnqtpmVZUt30zvfvx/p0VOOSSlAU3FkBQboHUpz0E=; b=owGbwMvMwCXGf25diOft7jLG02pJDCndXdJPCib2Sa5SyA1aNe/Q/VXJhzimiG36Itn24UN9e H7A1vBbHaUsDGJcDLJiiix/93xkPCa3PZ8nMMERZg4rE8gQBi5OAZiIryzD/3jW5j0urffjip8t rp3lFbThsIdtc7BdjespQffltSv0mBj+ir6LTXEoMz7Re1bMx3xRREVS1t8keY4Wzldm89w9ctL 5AQ== X-Developer-Key: i=vishal.l.verma@intel.com; a=openpgp; fpr=F8682BE134C67A12332A2ED07AFA61BEA3B84DFF X-Rspamd-Queue-Id: 7E88EC0028 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: zadodj9xxhbba3kf363mp571c4kycj8x X-HE-Tag: 1686866465-75242 X-HE-Meta: U2FsdGVkX18lPoJFclbNNJ5O2c36yNd2CNUrYOL821mLQmgIrSHCGNqghPlyT8aNxDfvWcva6CN6xTJ2+D12n4U/R0ofzbpmBxYMWjAwDO6aNfWO7uAufUdiSVTV5q7NwIIYG5c/mxg/6mKJm8OoC8dPO3GRz3LKHmHkuzK4KZyEMlhu77vxyb6bPcSvN/RC/DEcZ2oauNnEvJHgjclWEhwFoPFNpARkCF3Yqrhzh57uVAjEVeMP/uIuomO5xdYt3tEjuZYk5yqglcP4ZB5lANNEkY26qJ2gWB7SdgfTtb9DdbD7pqZCVeGTqQUQ+7e8yS9wf//GXuVTisakuwrfRRNH1LYJc5YBevuRrA+a4lYZryu8WYMUrfl+Q9MQeYdmdj+W6NqL03YBCsW6fS/7AkO2n4AHJssZ5I/M/gi5TmZwFV6pA1s3uuJkfm0oNPAOjbPNJzA42aELZlShrl4yYKNvkJVy+HlX8SpopupHFZl1gR+XnsNpmhVHDeb5Zp89AJ1Ri5apFEGY1BpYsRaxvYjzD4ExSVA4kKodsjaAnH4X5gCkY3Z2A2TTxCGUPcWL/Ak/zBWat8L+Tz89Olyr5HDnlsyR4IISWWkgPCbfOq8UOGJI1+XEGzIaHFPF8ASSaxdtFAp94wlsLoAubLm1K76XMHEJwn1EXIL1BhyQQCFC0YNI35oKQPjI4WdM57JKLgG6QxR3+SSfcX3Kf5ZfJuhQvAk34NLpaBa0PowxST1QaDIWfmkYnVPaLgc6+vkOPsVI/rxnXK2tNEUDG4acvYZIrXitJhrHRtRhEEHWnnd7OktR+SMnxuz7DRyz8C0wiEI7JuT79tgZRAZGUudEJS1xW/bJZcoSJ4sXzGzX3iNsjIANE0VgY2lNKK5As0cYjWJwZmQHYK6pFhQTIJ1J2XMJgWQJvQfLPSZGoZlYiHh84dvT8kGro5cLdIrTmRi1ZWJVamIKU2T/LYtJM8i t857NePu cPz3Q3ZMV3icFFxV52iInpkdODD4vIMxnkM3StAcYzXrjzOOCS9ulO8Y35k2mC/H14KaWUCWXoaWdZCBpUSb+C3HifC9QmI8T1/jh1OL2oSQA7femoTdIikhjuFQpt54K0j2KFyJRgbXdBFBfjxSDtzmKBnSzUvLr5RxcVSrw5Sno4UQSlYBMHD10i/lDE1u8j5UHOTXGYstSbImuBPkZp2UpxQWTLsTuUv5890SdvGAql1g6yC+tVrOjE+/uziRz5fxldott94Op6UoaQuaekMAMeSZss6pd9jwslP77gZmpOpS93+PA2TvTtxf9GFwkJiAqsnJv0Oi+jCwa70/+iY7QmvxSJNkQG+zcNIc8xGLP2x8= 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 the dax/kmem driver, which can be built as a module, to use this interface, export it with EXPORT_SYMBOL_GPL(). 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 Reviewed-by: David Hildenbrand --- mm/memory_hotplug.c | 1 + 1 file changed, 1 insertion(+) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index bb3845830922..92922080d3fa 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1328,6 +1328,7 @@ bool mhp_supports_memmap_on_memory(unsigned long size, mhp_t mhp_flags) IS_ALIGNED(remaining_size, (pageblock_nr_pages << PAGE_SHIFT)); return false; } +EXPORT_SYMBOL_GPL(mhp_supports_memmap_on_memory); /* * NOTE: The caller must call lock_device_hotplug() to serialize hotplug 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++; }