Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp7794342rwd; Tue, 20 Jun 2023 06:24:13 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6g7MVGGss0ZCBEjVzDwi3VQKOYSvM0CI/6trhH00k2f0Z28PeicOn0xxSe/cA4T+TZmgpN X-Received: by 2002:a05:6a20:8e05:b0:ff:ed6b:4c9e with SMTP id y5-20020a056a208e0500b000ffed6b4c9emr18196897pzj.36.1687267453142; Tue, 20 Jun 2023 06:24:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687267453; cv=none; d=google.com; s=arc-20160816; b=pTbwHYBhiJY4CDFK/IvkMvSFUf+s5r83AKRWa6JEEAkrOYOcf1jil/lJQOuf9NK1o2 DclNhRViSlrMH28hFOoGYuB/t6SdCopSfFYYYx4aaE0KyjEKEoNuWz1RtOrPodo+v07o yNxMxO53QtPIFtN5D2ClW+WUtle/iiGe2LDuZ92ioipevbspg9IHt6/IGNmD0nDv0nOa 7l6hN7nzvDg9t05fErFChcJ6wUjwq7yZ2pMg9HMMqQXpUljszPvZ+zbXJmtKwR9xjOIh 70ebhjaBeyq2oUg2hOvlxbS4MBjMAmJAeJ1B+vyMRT7GdcmjDCc5wPsTalzmuRBNlQR8 uJQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=H3BTlpVBypn/HUSJmwRVHEmC2PE6s+8bLrqyH4SKjio=; b=RDS+xNyDdAUYb/8sJi39OY9ZJREUFoK1sD+eOEtK5syaaCptkPDGvlOaClALpTJeBD Yyw2PkUvxp7bTMydoEKRsRztc11csC5Fjz5trSKXW5KHOkNxbcG4E/FBynkOuWpYRgxQ s92mGWRwphkppeH874D5lNZ0I+4u+fWZzHWqkOM4euCtKKsNiUGYNoCIc/8Gzaj8DrNA dJpTfEoxL56DVma5MdbRVHcdR9GNXy9J/Kg9C+LpfLlPKfr1P6xBjaUnS4VL5fVZuhQW basnz0KkLQA+q6kXaNieQ8nSXwMk5dGCVs8rtvqiOwJBOMB3CCHLzXAhCmIfCfMMhpUP TXlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b="rykL9/vr"; 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=REJECT sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c29-20020a056a00009d00b00662186eb4eesi1656997pfj.273.2023.06.20.06.23.58; Tue, 20 Jun 2023 06:24:13 -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=@ibm.com header.s=pp1 header.b="rykL9/vr"; 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=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232134AbjFTNP1 (ORCPT + 99 others); Tue, 20 Jun 2023 09:15:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230295AbjFTNPZ (ORCPT ); Tue, 20 Jun 2023 09:15:25 -0400 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2EC01716; Tue, 20 Jun 2023 06:15:24 -0700 (PDT) Received: from pps.filterd (m0353724.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35KD94PA016292; Tue, 20 Jun 2023 13:14:52 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : in-reply-to : references : date : message-id : mime-version : content-type; s=pp1; bh=H3BTlpVBypn/HUSJmwRVHEmC2PE6s+8bLrqyH4SKjio=; b=rykL9/vrDus2UGuiv2B8ecixd3wfY+XxpMSZ6LrzBTuN7m+sKbwfiLTU7tu2keZhZLj3 hRavxxIt0FeMvmHP65mj2U2F6pz9DzEqXXaesH4JzTtnFK3kh+sxfZ16XXdInAFaiVfF pT/miH0IXMZUlQsWVtusjm1e4YmBgutEEHYs4qvGORiJ0r38cnkNRmOsCRDMoJnfc88J 6uTFOAK1OG5Sbuv+TKlqmUcCVWyjWxY/CVg2OqmSKs9ecvJRjZ60U1Y8Ar02InAS4FFa ZO7N7E46cB8FPWCbCZ70deKDJxt/Wg/9dy7cHf//dA96N+VWJ2lIkPvfStDi1IMlfVPP xA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rbcg88jqe-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 20 Jun 2023 13:14:51 +0000 Received: from m0353724.ppops.net (m0353724.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 35KDBWBl000800; Tue, 20 Jun 2023 13:14:51 GMT Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rbcg88jpj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 20 Jun 2023 13:14:50 +0000 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 35K2uqrY021786; Tue, 20 Jun 2023 13:14:48 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma03ams.nl.ibm.com (PPS) with ESMTPS id 3r94f52309-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 20 Jun 2023 13:14:48 +0000 Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 35KDEkL642337012 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 20 Jun 2023 13:14:46 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2135720040; Tue, 20 Jun 2023 13:14:46 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 53CFC20043; Tue, 20 Jun 2023 13:14:42 +0000 (GMT) Received: from tarunpc (unknown [9.199.157.25]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTPS; Tue, 20 Jun 2023 13:14:42 +0000 (GMT) From: Tarun Sahu To: Vishal Verma , "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 , aneesh.kumar@linux.ibm.com Subject: Re: [PATCH 3/3] dax/kmem: Always enroll hotplugged memory for memmap_on_memory In-Reply-To: <20230613-vv-kmem_memmap-v1-3-f6de9c6af2c6@intel.com> References: <20230613-vv-kmem_memmap-v1-0-f6de9c6af2c6@intel.com> <20230613-vv-kmem_memmap-v1-3-f6de9c6af2c6@intel.com> Date: Tue, 20 Jun 2023 18:44:40 +0530 Message-ID: <87zg4uwa0v.fsf@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: k445iHDRACRzPCIxEzPCR5_a3eK4s88q X-Proofpoint-GUID: uz0hnxRkr9FUlWfHMTCrnrTx7dGX1Mqi X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-06-20_09,2023-06-16_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 adultscore=0 mlxscore=0 suspectscore=0 lowpriorityscore=0 impostorscore=0 mlxlogscore=999 phishscore=0 malwarescore=0 bulkscore=0 clxscore=1011 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306200117 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS,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 Hi Vishal, Vishal Verma writes: > 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. > Some architectures doesn't have support for MEMMAP_ON_MEMORY, bypassing the check mhp_memmap_on_memory() might cause problems on such architectures (for e.g PPC64). > 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++; > } > > -- > 2.40.1