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: 108729 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp944823vqr; Thu, 15 Jun 2023 15:14:20 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7uAZh2CphzPYvG4XnYyx3VcG7MJtBVCfJ7nnjRmPYRd7NDUwo+eqpU2yqplS1rEFoDpoqV X-Received: by 2002:aa7:d4d2:0:b0:514:9b60:ea65 with SMTP id t18-20020aa7d4d2000000b005149b60ea65mr102720edr.16.1686867260245; Thu, 15 Jun 2023 15:14:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686867260; cv=none; d=google.com; s=arc-20160816; b=pkmTKzyYDAX/AYoDX8IqOCJ+DQRB9QhLb7L8bqdJKAnq56VGCBItMnApXx6RUw7e5l Yu7S81tARzMPQUzNkYKtW078/Ie4F9BdvH1SnPdpLSE/9M/madBKFosnY0hro1vgCAxz iyyTvlVd6jllrCWK7if+oCMjhAf9sJJ9bsA/7T7qNZW84+R7skupF63LZwe/L7ofQT/N GLUjhf3FkgGN2vXn5CQtO47P+ooKDKgbMdmzbaBXXrP8h6twmY7u8XOluYRBuxWLyEV5 4QIguLCJsas8WUyX5naLHRhVNXqQAvxpI7RbiELDVsucld2WuHedX1HTuBtm8Wq91wh6 bKyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=rj4bV30cPb9K9sKsHExCZ8luQEyBWvqpIuDdC97URtA=; b=VaFqwdZEmx0Vj0dGYeoaqVSsqcCcyLmA+r2vw9W0wR67ZLEt1dwmDci+iqWvpD5TwF 9EVP1GDKywOzgj0DT1w/exZh5+S3wqMowxrSL2HvhuFXHKbQsXwa7hxGH9KHtgJJDSQc kEjzj+uKQENi1tGPYcivnQvX6/UDg3XO/wW/kO0RSIQMQQRIIW5el3+D8HwDifj+vxeX F/D35faoIiyzsqafiAQWChQNCVCHBKBreoWzpbt/lgUyQY8+r8x9dhkMbyi5tugIPQg/ tA1Qgm/ULS1W1nDvm4RPFZYg//M9AUGtR5izb9fJ54ywKuogv9pDNocwIehjRRRx1N90 8DIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=jJRSesBq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i14-20020a056402054e00b00516a29f61acsi10784535edx.649.2023.06.15.15.13.55; Thu, 15 Jun 2023 15:14:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=jJRSesBq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237188AbjFOWBP (ORCPT + 99 others); Thu, 15 Jun 2023 18:01:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232139AbjFOWBG (ORCPT ); Thu, 15 Jun 2023 18:01:06 -0400 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB5F9296C; Thu, 15 Jun 2023 15:01:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1686866464; x=1718402464; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=y9Fdd4CaXjYhM8c/kYRc/ffM8uFuEd3rHTJq5W9ozIE=; b=jJRSesBqLUd0urCv9o194jwNNzu4qMqaGTDmQ4n4qnPNrnMSmuTAR86q BP2sh/aOYCumaxuy+oVXIvRhS0YcejEucDVx7xePs5XnvWQtof6HULkgG jfjVfhj2LzMqtcwWNkdQBD0tEgEdXTLbvZlFuFBmnQ4pEW8CvkDeRnAaq zkxQKhTPjVHlsvDkYeqCynTH3a7/T1ZB3Lv6DOlbs1ZeDlUUlFx/glKyK 6JIM9b26z5NEfqYAfXvxTq2QLvjiI+5GuPS4spQrr0moNG6I/i+IRd+87 vlm6BPXIqfQnGuIZuyYl4EDc/OIixOwP7F4lcTf9xz1p3xbvNLzpwzrnh Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10742"; a="343791130" X-IronPort-AV: E=Sophos;i="6.00,245,1681196400"; d="scan'208";a="343791130" 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768808524316234987?= X-GMAIL-MSGID: =?utf-8?q?1768808524316234987?= 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: 108727 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp940588vqr; Thu, 15 Jun 2023 15:05:48 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6v0LsN0STLWkOmAOIgXuFPLakLbtyfkN/8boUAMpNT9idlStruTCnj+78SdC/MqQC0QgYt X-Received: by 2002:a19:f242:0:b0:4f3:b97c:2d91 with SMTP id d2-20020a19f242000000b004f3b97c2d91mr14322lfk.66.1686866748329; Thu, 15 Jun 2023 15:05:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686866748; cv=none; d=google.com; s=arc-20160816; b=fblkTmiIXfNNsaY4++1H34SQISCdO4L/cW0VBr4Us0cckBj2LQR5/AG08Wws9nZBHP KGsutmrS9MBgDhfiBRwHa3EpuiKqSCOwoiXf9QrHD+9QjHeCVBwFlvl6MXrcmgCMN6IS N9kKObsXpOaoOR1ZPPAbqT7n5d6Ro7K+TBHQauIdIcHi79TlPj2GhRQBZ4ySbJHoDovQ BtOS7MpQwkd/UseEaVpkRMgHjaYgF1cUfh4yHUNtC2+9WmQYMfW9AG6lKGrfsZMvIYIe na6ASaYi3Q4RQK9W8bzBQdIAwTDDr4GQRIeqdfQeElg/6hF0pCjHLTzS4uLRlmQbyihM xXIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=tOhzw+U+EZY622P3OkbIoLu3uYzfsPtlO4bPgBdmAiI=; b=KUMaa/8LHBwC+VxHm5AsOJ75E8gD58O9jtt3GrC+Q8VyoPR5ySCGFMwfZFh/IfTuu1 w6DzRu0LRYtsL/Ft7mpx1NR4exfTao59oar1zMM207b4tTR4PWTkW71K6ArnQ3SQaFBA gdiOhhR+bqWWj2VAbZ8ukIjD1dmbFkE6FKT1gpriNTSXRAW7a0QwGD6udrKOXRs6Whub X9ALjH4o1fzVxrwOvFz2u/Y+YcFA2TeBX4+xbnDqZdiwLeV6gpmX4BKZxicw9ZWRBBrM 01t/7d8vxIC8G90N5g0dKMJk4quP3I8ICnvgHXa7R3RuSGbaRaPuePfWyNsOIB8z/NnW bSuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="JMQf/c3I"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l20-20020a17090612d400b009829077b479si1763673ejb.860.2023.06.15.15.05.23; Thu, 15 Jun 2023 15:05:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="JMQf/c3I"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237874AbjFOWBS (ORCPT + 99 others); Thu, 15 Jun 2023 18:01:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232578AbjFOWBH (ORCPT ); Thu, 15 Jun 2023 18:01:07 -0400 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20C802943; Thu, 15 Jun 2023 15:01:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1686866466; x=1718402466; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=U9rnqtpmVZUt30zvfvx/p0VOOSSlAU3FkBQboHUpz0E=; b=JMQf/c3ItfiQ3GTN3o4+ONX2IbrwQ2xRfZxmw5wEIBbxoarPUjd5rwwG PmsWZApXoDwyC6Wp/ngYFxDdrVeGp2lky0mUdR8GIqNSomMfjpPdKm1Cy FNgHItHOgJ9HTjC4pc5QZX0Ircq0jz8yJVQrdOsktUVLWVHiWUNrWf6AP +onmqCYlRuhCyfkJ+szM3XrVThrQ+9SxWv2k8oP0MmyIyIWHf8hP1gBJe mql6zvVTl0GYTyjWU8NL7LWHefg/62h5cb/F8WmlJGBDMqKBPJP2+2KGY xkfEMrVA2G1TckVe2dV2KfYio6dXJ7CYh3IiXrzSE9LAPmGSIutSTrJe9 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10742"; a="343791146" X-IronPort-AV: E=Sophos;i="6.00,245,1681196400"; d="scan'208";a="343791146" 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768807987058569240?= X-GMAIL-MSGID: =?utf-8?q?1768807987058569240?= 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: 108728 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp943195vqr; Thu, 15 Jun 2023 15:10:46 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ76dWmw2lfzGF/MYVUE6cjaEWGstFqN/yu4MvqbJUw4itDIsaJ5NA8EY5ul5AnqK+pjsRpC X-Received: by 2002:a17:90b:98:b0:25b:cc96:a91a with SMTP id bb24-20020a17090b009800b0025bcc96a91amr135804pjb.39.1686867046268; Thu, 15 Jun 2023 15:10:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686867046; cv=none; d=google.com; s=arc-20160816; b=vei3O778FCjTcAZQvXcQK2T2DKmT0Rjy/PUhczWsS3tO3PA8yse+3y7kunaI9PTddn ptDzfskUuXL6cbI0lc/ioahFw5BYpCmGGLmbUZbAOplmvT29loXo5vSWfbF3zWZq0RWM b/P2ZTDJpqadN3E/uK9i7EJwOYwZPofNJnHk/YAv4Tz89qVYetESuP/nDPhVHvtXmHWR dg+cnJsdRf7dZ47mJfuXrWUNtR/hKJm65TJBTp4nWqh9rrq9ogdP5WC9bFqTr+YvONQL BgOmmtp6H58cxntUuv+SFnEw9GDG6vl1weNhWCmDNdagP2frs5pqB2Lk16WqrZjgTBrO SUFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=2f7MyWiXtVfzfQ7VI1xeIzkghmA9toSBSNHXzVy05kk=; b=pFNuBCTu1iUbZWvoQYkPajgOmIllerVTjEIQ/utGWpPTX7i8rj2jF0oZ1sU6afd4jD jaYhOtETYvQd63bBrmWYoZHD1eNDDhMRe32IiIIlOviazisngKuwT0DVgkU8XrSt5Mop 2TsJkC7iVz7bUZmosG24f+gt2Utu3S+iQ3kbqTeONXoxRSOonoEap2LUz4ThGyvZpYfH GdFxsH8sdGp8Cc/0ri6m/ES0uoCCR8DkWgyaBas5mMuH5AY6cuE6e6+C3IPGtaI8n68s euROaNzNZJAfh3OqhsMwpF0OAIWMvlIpo+VBYTJ7bczXOWY/J318l5GmX8PPEY/wPbb/ m76w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=GTxm7YEr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y11-20020a17090aca8b00b00256d7cc5b67si217645pjt.133.2023.06.15.15.10.33; Thu, 15 Jun 2023 15:10:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=GTxm7YEr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237928AbjFOWBW (ORCPT + 99 others); Thu, 15 Jun 2023 18:01:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234203AbjFOWBI (ORCPT ); Thu, 15 Jun 2023 18:01:08 -0400 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C3EF2971; Thu, 15 Jun 2023 15:01:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1686866466; x=1718402466; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=LdChvoFmNnlAlHfrYI7/8PGxZ7XvW/yi15/tTemhtfg=; b=GTxm7YErEpKjoyHoB3oScxINCTusKrDxfcI93Cax0r0Vmi7TQPIJ1oNH iTQsKC/O1TwPrlMTZrARA3rvOE7Lk8nReUzjpB6OV+K6xCl/G/ae2h3jX DFS24IE92Xpr0uh5263kZOM/yx+ybqM5VDLan01z6PuuuN+9WqXlCXCjJ mWA71fWDjlp8OGnRoyD/Y75qSf/r0R0hnAh7262Y6V2Q1/ql/lo7A1JVR aHB9r/Rd5WGZyyfz0ihr+DC6Y9SdsA96Dy57V9pq9aAFYIc7VVsXUIF1W dUYAgtCQsdtzZtE9p3eNA3qgPcNsI3oPzUp06RbyckEHRLD0igO7NFVhW g==; X-IronPort-AV: E=McAfee;i="6600,9927,10742"; a="343791154" X-IronPort-AV: E=Sophos;i="6.00,245,1681196400"; d="scan'208";a="343791154" 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768808300011282014?= X-GMAIL-MSGID: =?utf-8?q?1768808300011282014?= 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++; }