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++; }