From nobody Sun Feb 8 05:29:31 2026 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 09B011F9EB6; Mon, 2 Dec 2024 08:28:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733128088; cv=none; b=YafoikxsV4btBOWt+BmYaZuP9sXzgGuU9h0CbJ/WtlmFSiJLSvH8iMnoc3R67Y1FBj2uOHXrx8p2zOXyK4+6kmv8cdqFLkoEfZhupaa+lstU+JZh0Mz1/R8NpzqSQU8YXaUY0wm30zvHkUZtWC3MNIgk2aY7z3gU+Bu1nsTNKn8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733128088; c=relaxed/simple; bh=omh02Qqp5XKw7wm7hUqTKB2lA0p66F9/vlR7aGGFk3g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hAyFqhH7FgELQV5BpF88qtJxx+AlP2vRKGEia+Iv8saRT6E553BKjzX2bPyogUb54ZAfGMrsmsHRMksBq9I0iQBK5sWcZgNc1rCWPOyOkqZEB1YYNmZpZrsJm/psGg17BC7t4N7dsfkg36VLEOFi4SSTjgc0dGtjKxzidtOkQrU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=oL60V92d; arc=none smtp.client-ip=148.163.158.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="oL60V92d" Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4B1Ij4rp022972; Mon, 2 Dec 2024 08:28:00 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=FckEokSgRioUHQRcH ayHqWILEETFnWG+x7hLq5rxsJM=; b=oL60V92dQozFG2No7T4TVJsetS9MWzWMA B6z7rIUjXXlwW4Qf/Qt3f/dv0mYRFpycgzw7Yxor//QlejQFgARLhoExIWAOqH1T hpJmz3axibcIQqYZlXzHJANaqshE9HoUMy4oLYgo0bAi+1Nhz/l42WIuLVEag57F 8fUbnsBuiKXoAHJBMewEsUEHsRIsYDh3kyEamhMJvm/4jSVZMoh32WOM4xkCXCrm JCVgGxiQaPR7kb5/igIsjA8p2MW27OxK+ZciYHrzRbC27iqk7hSQ/GPCr6VDjU7w tIOrkOBFVmoaZp33DH7GQ+gExiaOsIIG2pUK+KtLwRkJtBiXa8Qyw== Received: from ppma13.dal12v.mail.ibm.com (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 437r4p7pwc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 02 Dec 2024 08:28:00 +0000 (GMT) Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 4B27JolW007467; Mon, 2 Dec 2024 08:27:59 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 438f8j9wn6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 02 Dec 2024 08:27:59 +0000 Received: from smtpav07.fra02v.mail.ibm.com (smtpav07.fra02v.mail.ibm.com [10.20.54.106]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 4B28RuWD14287148 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 2 Dec 2024 08:27:56 GMT Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DECAB2004E; Mon, 2 Dec 2024 08:27:55 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A776B20040; Mon, 2 Dec 2024 08:27:55 +0000 (GMT) Received: from tuxmaker.lnxne.boe (unknown [9.152.85.9]) by smtpav07.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 2 Dec 2024 08:27:55 +0000 (GMT) From: Sumanth Korikkar To: David Hildenbrand , linux-mm Cc: Andrew Morton , Oscar Salvador , Gerald Schaefer , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , linux-s390 , LKML , Sumanth Korikkar Subject: [RFC PATCH 1/4] mm/memory_hotplug: Add interface for runtime (de)configuration of memory Date: Mon, 2 Dec 2024 09:27:29 +0100 Message-ID: <20241202082732.3959803-2-sumanthk@linux.ibm.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241202082732.3959803-1-sumanthk@linux.ibm.com> References: <20241202082732.3959803-1-sumanthk@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: p1XxvKuTo3rCWRRzBvjFXhl2SyYkMdyS X-Proofpoint-ORIG-GUID: p1XxvKuTo3rCWRRzBvjFXhl2SyYkMdyS X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-15_01,2024-10-11_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 priorityscore=1501 clxscore=1015 phishscore=0 malwarescore=0 suspectscore=0 mlxscore=0 bulkscore=0 mlxlogscore=999 adultscore=0 lowpriorityscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2411120000 definitions=main-2412020070 Content-Type: text/plain; charset="utf-8" Provide a new interface for dynamic configuration and deconfiguration of hotplug memory, allowing for mixed altmap and non-altmap support. It is a follow-up on the discussion with David: https://lore.kernel.org/all/ee492da8-74b4-4a97-8b24-73e07257f01d@redhat.com/ As mentioned in the discussion, advantages of the new interface are: * Users can dynamically specify which memory ranges should have altmap support, rather than having it statically enabled or disabled for all hot-plugged memory. * In the long term, user could specify a memory range, including multiple blocks, and whether user wants altmap support for that range. This could allow for the altmap block grouping, or even variable-sized blocks, in the future. i.e. "grouping" memory blocks that share a same altmap located on the first memory blocks in the group and reduce fragementation due to altmap. To leverage these advantages: Create a sysfs interface /sys/bus/memory/devices/configure_memory, which performs runtime (de)configuration of memory with altmap or non-altmap support. The interface validates the memory ranges against architecture specific memory configuration and performs add_memory()/remove_memory(). Dynamic (de)configuration of memory is made configurable via config CONFIG_RUNTIME_MEMORY_CONFIGURATION. Usage format for the new interface: echo config_mode,memoryrange,altmap_mode > /sys/bus/memory/devices/configure_memory E.g. to configure a range with altmap: echo 1,0x200000000-0x20fffffff,1 > /sys/bus/memory/devices/configure_memory This interface could not only help to make s390 more flexible and similar to others (wrt adding hotplug memory in advance). It might also be possible to provide the dynamically configured altmap support for others. E.g. instead of directly doing an add_memory() in the ACPI handler, with the static altmap setting, one could instead defer that to the new interface which allows dynamic altmap configuration. Reviewed-by: Gerald Schaefer Signed-off-by: Sumanth Korikkar --- drivers/base/memory.c | 124 +++++++++++++++++++++++++++++++++++++++++ include/linux/memory.h | 6 ++ mm/Kconfig | 16 ++++++ 3 files changed, 146 insertions(+) diff --git a/drivers/base/memory.c b/drivers/base/memory.c index 67858eeb92ed..f024444b3301 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -631,6 +631,127 @@ int __weak arch_get_memory_phys_device(unsigned long = start_pfn) return 0; } =20 +#ifdef CONFIG_RUNTIME_MEMORY_CONFIGURATION +enum { + REMOVE_MEMORY =3D 0, + ADD_MEMORY, + MAX_CONFIGURE_MODE +}; + +enum { + NOALTMAP =3D 0, + ALTMAP, + MAX_ALTMAP_MODE +}; + +/* + * Return true when the memory range is valid. + * + * Architecture specific code can override the below function and validate= the + * memory range against its possible memory configurations. + */ +bool __weak arch_validate_memory_range(unsigned long long start, + unsigned long long end) +{ + return false; +} + +/* + * Format: + * echo config_mode,memoryrange,altmap_mode > + * /sys/bus/memory/devices/configure_memory + * + * config_mode: + * value: 1 - add_memory, 0 - remove_memory + * + * range: + * 0x-0x + * Where start address is aligned to memory block size and end address + * represents last byte in the range. + * example: 0x200000000-0x20fffffff + * + * altmap_mode: + * value: 1 - altmap support, 0 - no altmap support + */ +static ssize_t configure_memory_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + s64 start, end, block_size, range; + u32 config_mode, altmap_mode; + int num, nid, ret =3D -EINVAL; + struct memory_block *mem; + + num =3D sscanf(buf, "%u,0x%llx-0x%llx,%u", &config_mode, &start, &end, &a= ltmap_mode); + if (num !=3D 4) + goto out; + + if (config_mode >=3D MAX_CONFIGURE_MODE || altmap_mode >=3D MAX_ALTMAP_MO= DE) + goto out; + + altmap_mode =3D altmap_mode ? MHP_MEMMAP_ON_MEMORY | + MHP_OFFLINE_INACCESSIBLE : MHP_NONE; + + block_size =3D memory_block_size_bytes(); + + if (!IS_ALIGNED(start, block_size) || !IS_ALIGNED(end + 1, block_size)) + goto out; + + if (start < 0 || end < 0 || start >=3D end) + goto out; + + if (!arch_validate_memory_range(start, end)) + goto out; + + ret =3D lock_device_hotplug_sysfs(); + if (ret) + goto out; + + if (config_mode =3D=3D ADD_MEMORY) { + for (range =3D start; range < end + 1; range +=3D block_size) { + mem =3D find_memory_block(pfn_to_section_nr(PFN_DOWN(range))); + if (mem) { + pr_info("Memory already configured - (start:0x%llx)\n", range); + ret =3D -EEXIST; + put_device(&mem->dev); + goto out_unlock; + } + nid =3D memory_add_physaddr_to_nid(range); + ret =3D __add_memory(nid, range, block_size, altmap_mode); + if (ret) { + pr_info("Memory addition failed - (start:0x%llx)\n", range); + goto out_unlock; + } + } + } else if (config_mode =3D=3D REMOVE_MEMORY) { + for (range =3D start; range < end + 1; range +=3D block_size) { + mem =3D find_memory_block(pfn_to_section_nr(PFN_DOWN(range))); + if (!mem) { + pr_info("Memory not configured - (start:0x%llx)\n", range); + ret =3D -EINVAL; + goto out_unlock; + } + if (mem->state !=3D MEM_OFFLINE) { + pr_info("Memory removal failed - (start:0x%llx) not offline\n", + range); + put_device(&mem->dev); + ret =3D -EBUSY; + goto out_unlock; + } else { + /* drop the ref just got via find_memory_block() */ + put_device(&mem->dev); + } + __remove_memory(range, block_size); + } + } +out_unlock: + unlock_device_hotplug(); +out: + return ret ? ret : count; +} +static DEVICE_ATTR_WO(configure_memory); +#endif /* CONFIG_RUNTIME_MEMORY_CONFIGURATION */ + /* * A reference for the returned memory block device is acquired. * @@ -941,6 +1062,9 @@ static struct attribute *memory_root_attrs[] =3D { &dev_attr_auto_online_blocks.attr, #ifdef CONFIG_CRASH_HOTPLUG &dev_attr_crash_hotplug.attr, +#endif +#ifdef CONFIG_RUNTIME_MEMORY_CONFIGURATION + &dev_attr_configure_memory.attr, #endif NULL }; diff --git a/include/linux/memory.h b/include/linux/memory.h index c0afee5d126e..88b2b374bc44 100644 --- a/include/linux/memory.h +++ b/include/linux/memory.h @@ -85,6 +85,12 @@ struct memory_block { #endif }; =20 +#ifdef CONFIG_RUNTIME_MEMORY_CONFIGURATION +bool arch_validate_memory_range(unsigned long long start, unsigned long lo= ng end); +ssize_t arch_get_memory_max_configurable(void); +int memory_create_sysfs_max_configurable(void); +#endif /* CONFIG_RUNTIME_MEMORY_CONFIGURATION */ + int arch_get_memory_phys_device(unsigned long start_pfn); unsigned long memory_block_size_bytes(void); int set_memory_block_size_order(unsigned int order); diff --git a/mm/Kconfig b/mm/Kconfig index 84000b016808..2aec2fc3fb25 100644 --- a/mm/Kconfig +++ b/mm/Kconfig @@ -576,6 +576,22 @@ config MHP_MEMMAP_ON_MEMORY depends on MEMORY_HOTPLUG && SPARSEMEM_VMEMMAP depends on ARCH_MHP_MEMMAP_ON_MEMORY_ENABLE =20 +config RUNTIME_MEMORY_CONFIGURATION + bool "Dynamic configuration and deconfiguration of memory" + def_bool n + depends on MEMORY_HOTPLUG && SPARSEMEM_VMEMMAP + help + This option provides support to perform dynamic configuration and + deconfiguration of memory with altmap or non-altmap support + (/sys/bus/memory/devices/configure_memory). The interface validates + the configuration and deconfiguration of memory ranges against + architecture specific configuration and performs add_memory() with + altmap or non-altmap support and remove_memory() respectively. + + Say Y here if the architecture supports validating dynamically + (de)configured memory against architecture specific memory + configurations. + endif # MEMORY_HOTPLUG =20 config ARCH_MHP_MEMMAP_ON_MEMORY_ENABLE --=20 2.45.2 From nobody Sun Feb 8 05:29:31 2026 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B54C71FA14E; Mon, 2 Dec 2024 08:28:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733128093; cv=none; b=Yy1AGpmSa6SsUovNV414zJLArEtpR9owBkLKr1gz1FAq6fGYQlhfr9mVH8CvkgnvKQvjorFkKrtC2L64DaohxIPzTjNFZTFqIe2wRiXaptz/fMSU+NxWq0Ro2Kk+8IRKMApc4Ioa+OGQrg1KBy+3zUjBBd5dKOb09LrtXJIOS9o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733128093; c=relaxed/simple; bh=rVxXH9sWDoht1KxMmKbfnALGLfi1rfOi6esHorldA/8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gpA1RxuCgjbFBVMLgI9mcQwjbvAwEX+zxiOZ5D3wuMp91zN5M6oqmEhvGIBovX5Zt3gsKt6qFwMlNv4SeIXHDb5g6eTIHPgy691O/J5afAOVB1vGHlsU81UV4wmRGIKHLBGBf5pFXLeNDBbgM4n0vCd6tN64r9XTqQDqkfydH/k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=BD7l8Og9; arc=none smtp.client-ip=148.163.158.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="BD7l8Og9" Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4B1EFbRC026106; Mon, 2 Dec 2024 08:28:05 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=ttEIqKp1gqeMV+LBQ OU9I5MsmYSVPQfGPglAO21iWo8=; b=BD7l8Og9Y6eW5WSxBtuWl651pEWyQg5HX Oc3yuVmGg+fgBQck88JbJ/pi5ZFhK1ElbTvlsfPZe69pAga2FTS8iLZEceKrPKS6 RPsKx8QlIAP8iH5vbuFjH6FUA3BoKRcVFoXnITLN7oo+gfuub1jktFpn6O1V+OE4 xO3Uqgu+ILPAfOj1p0Jm5GqVr0R4EAITC/oOpNOpx7oXxmGkZ7W3SnNfA/JdTA/U pdGQ+RRcrvqU54IxN4Ui6Fqg/lq7bTvGmlqyBbwoSY+gckiAgKMSjzDaHxcax3SU dUypS7RWO9u4+QIzNIdhaNG84Dw0kc/3e1CrKHPfjm0nVDdchY2wA== Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 437tbx7c12-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 02 Dec 2024 08:28:04 +0000 (GMT) Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 4B1J5ZZv017943; Mon, 2 Dec 2024 08:28:04 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 438d1s22jt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 02 Dec 2024 08:28:03 +0000 Received: from smtpav07.fra02v.mail.ibm.com (smtpav07.fra02v.mail.ibm.com [10.20.54.106]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 4B28S0We60424552 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 2 Dec 2024 08:28:00 GMT Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8C83D20043; Mon, 2 Dec 2024 08:28:00 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5EFED20040; Mon, 2 Dec 2024 08:28:00 +0000 (GMT) Received: from tuxmaker.lnxne.boe (unknown [9.152.85.9]) by smtpav07.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 2 Dec 2024 08:28:00 +0000 (GMT) From: Sumanth Korikkar To: David Hildenbrand , linux-mm Cc: Andrew Morton , Oscar Salvador , Gerald Schaefer , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , linux-s390 , LKML , Sumanth Korikkar Subject: [RFC PATCH 2/4] mm/memory_hotplug: Add memory block altmap sysfs attribute Date: Mon, 2 Dec 2024 09:27:30 +0100 Message-ID: <20241202082732.3959803-3-sumanthk@linux.ibm.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241202082732.3959803-1-sumanthk@linux.ibm.com> References: <20241202082732.3959803-1-sumanthk@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: ROhRVQNbGn0edF93JjKxvQRIWzG9HKXD X-Proofpoint-GUID: ROhRVQNbGn0edF93JjKxvQRIWzG9HKXD X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-15_01,2024-10-11_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1011 impostorscore=0 mlxscore=0 suspectscore=0 mlxlogscore=761 priorityscore=1501 bulkscore=0 phishscore=0 adultscore=0 malwarescore=0 spamscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2411120000 definitions=main-2412020070 Content-Type: text/plain; charset="utf-8" Currently memmap_on_memory sysfs attribute can determine if the altmap is supported in the entire system. However, with CONFIG_RUNTIME_MEMORY_CONFIGURATION, user can dynamically add or remove individual memory blocks with/without altmap support. Hence, it is more beneficial to the user, if the altmap support can also be represented per memory block. lsmem output could look like the following: RANGE SIZE STATE BLOCK ALTMAP 0x0000000000000000-0x000000007fffffff 2G online 0-7 0 0x0000000080000000-0x00000001ffffffff 6G online 8-31 0 0x0000000200000000-0x00000002ffffffff 4G offline 32-47 1 Reviewed-by: Gerald Schaefer Signed-off-by: Sumanth Korikkar --- drivers/base/memory.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/base/memory.c b/drivers/base/memory.c index f024444b3301..469adc7212fc 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -431,6 +431,14 @@ static ssize_t phys_device_show(struct device *dev, arch_get_memory_phys_device(start_pfn)); } =20 +static ssize_t altmap_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct memory_block *mem =3D to_memory_block(dev); + + return sysfs_emit(buf, "%u\n", mem->altmap ? 1 : 0); +} + #ifdef CONFIG_MEMORY_HOTREMOVE static int print_allowed_zone(char *buf, int len, int nid, struct memory_group *group, @@ -492,6 +500,7 @@ static DEVICE_ATTR_RO(phys_index); static DEVICE_ATTR_RW(state); static DEVICE_ATTR_RO(phys_device); static DEVICE_ATTR_RO(removable); +static DEVICE_ATTR_RO(altmap); =20 /* * Show the memory block size (shared by all memory blocks). @@ -785,6 +794,7 @@ static struct attribute *memory_memblk_attrs[] =3D { #ifdef CONFIG_MEMORY_HOTREMOVE &dev_attr_valid_zones.attr, #endif + &dev_attr_altmap.attr, NULL }; =20 --=20 2.45.2 From nobody Sun Feb 8 05:29:31 2026 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0567F1FA14E; Mon, 2 Dec 2024 08:28:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.156.1 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733128098; cv=none; b=cwV/6s+ORHCry1ibL0BnzelMu9PMVpuXCJEOclfFTthBA1NTJY/C0ww7jUkXT4Gv9SfAzzQo+hII7kyOCQwX/pywbd+zHBBSmNqIeJMpaAlA9X2Yu4tc4B0uVEy6Ys20LfKSk3N57NUYlsFAuGxPmIRF1Z0ZYos+VKJtsNHe+Qo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733128098; c=relaxed/simple; bh=b2fwXB79lh648hWRmdzkCNo+wueq7FSM4rU53P45Fpk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ms413jj4OXhcBM1z7ciM9u0myE3N6Zi1gucJ/fwtDfV0JwVgmVAYvTtBF9znRWPfqwmSJa5KNz/7dv0grDahuoDMFZwADtAOFEXV+EIrzOXhZ2ulmjkDp9SlkIzBtLR5ZDbLC/2puorndZSa1G10Ou2VG8QoDkmieUcz98MkrNY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=Z/qNdeW1; arc=none smtp.client-ip=148.163.156.1 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="Z/qNdeW1" Received: from pps.filterd (m0360083.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4B1Eb8e8018708; Mon, 2 Dec 2024 08:28:08 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=fxEOWl+pF9H+TPIB1 u0RcA7fohWLpjI43sHvTpb8qt4=; b=Z/qNdeW1gofwxI6550nITDLPJ574ZtZTI vb8pNpjuB0O9C+VyT4vska+5ZeGtWtAhzwh/U8KkRs7zQBA31Yd00QATdNDfwNOI 6jVLqWH7ETWt75IfQiZUhEprKXC+dlHtejp2gQXpfrLF5FLFAo13zlZ8W0cbcKC9 9JJRH5sOFj3zLWmfhM7AQNd5MUmxWe3E1d9SDM29mM992+sTdBZD0dez63AtIuRb ppsvMWDJCGSYHvrtQvFCDFI8zr9fW1Ug/uWEjc7+PLmi01xq3zHL2XJAXGlz+gf2 ZjoNaEWFjYjvZarxPo/yJ1pmU2Na6r+VzCDpoKQiTr6ARigK9202g== Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 438kfgc0gb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 02 Dec 2024 08:28:08 +0000 (GMT) Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 4B28S3Qb005278; Mon, 2 Dec 2024 08:28:07 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 438fr19v96-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 02 Dec 2024 08:28:07 +0000 Received: from smtpav07.fra02v.mail.ibm.com (smtpav07.fra02v.mail.ibm.com [10.20.54.106]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 4B28S3Ct33096240 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 2 Dec 2024 08:28:03 GMT Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B840B20043; Mon, 2 Dec 2024 08:28:03 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8A6B920040; Mon, 2 Dec 2024 08:28:03 +0000 (GMT) Received: from tuxmaker.lnxne.boe (unknown [9.152.85.9]) by smtpav07.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 2 Dec 2024 08:28:03 +0000 (GMT) From: Sumanth Korikkar To: David Hildenbrand , linux-mm Cc: Andrew Morton , Oscar Salvador , Gerald Schaefer , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , linux-s390 , LKML , Sumanth Korikkar Subject: [RFC PATCH 3/4] mm/memory_hotplug: Add max_configurable sysfs read attribute Date: Mon, 2 Dec 2024 09:27:31 +0100 Message-ID: <20241202082732.3959803-4-sumanthk@linux.ibm.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241202082732.3959803-1-sumanthk@linux.ibm.com> References: <20241202082732.3959803-1-sumanthk@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: H14ztYqrnCyIw3sYL5zYSqhlBBOCiSmm X-Proofpoint-GUID: H14ztYqrnCyIw3sYL5zYSqhlBBOCiSmm X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-15_01,2024-10-11_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 spamscore=0 clxscore=1011 malwarescore=0 bulkscore=0 adultscore=0 priorityscore=1501 mlxlogscore=999 impostorscore=0 phishscore=0 mlxscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2411120000 definitions=main-2412020070 Content-Type: text/plain; charset="utf-8" Introduce /sys/devices/system/memory/max_configurable sysfs interface to list maximum number of configurable memory blocks by the architecture. Using this information, lsmem tool could possibly read memory blocks /sys/devices/system/memory/memory[0-9]+ as configured and list rest of the max_configurable count as deconfigured. Arch can define max_configurable by overriding arch_get_memory_max_configurable(). s390 usecase: /sys/devices/system/memory/max_configurable would be online + standby memory blocks count. The max_configurable attribute for s390 is configured in the next patch. x86 possible usecase: max_configurable could be initially set to count of all online memory blocks. Later, max_configurable can be updated whenever there is an acpi event generation for hotplugged memory. Userspace application like lsmem could possibly read memory blocks /sys/devices/system/memory/memory[0-9]+ as configured and rest of the max_configurable count as deconfigured. Reviewed-by: Gerald Schaefer Signed-off-by: Sumanth Korikkar --- drivers/base/memory.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/drivers/base/memory.c b/drivers/base/memory.c index 469adc7212fc..3da83345b570 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -665,6 +665,15 @@ bool __weak arch_validate_memory_range(unsigned long l= ong start, return false; } =20 +/* + * Arch can override the function and return the number of maximum configu= rable + * memory. + */ +ssize_t __weak arch_get_memory_max_configurable(void) +{ + return 0; +} + /* * Format: * echo config_mode,memoryrange,altmap_mode > @@ -759,6 +768,15 @@ static ssize_t configure_memory_store(struct device *d= ev, return ret ? ret : count; } static DEVICE_ATTR_WO(configure_memory); + +/* + * Show the maximum number of configurable memory. + */ +static ssize_t max_configurable_show(struct device *dev, struct device_att= ribute *attr, char *buf) +{ + return sysfs_emit(buf, "%lu\n", arch_get_memory_max_configurable()); +} +static DEVICE_ATTR_RO(max_configurable); #endif /* CONFIG_RUNTIME_MEMORY_CONFIGURATION */ =20 /* @@ -1075,6 +1093,7 @@ static struct attribute *memory_root_attrs[] =3D { #endif #ifdef CONFIG_RUNTIME_MEMORY_CONFIGURATION &dev_attr_configure_memory.attr, + &dev_attr_max_configurable.attr, #endif NULL }; --=20 2.45.2 From nobody Sun Feb 8 05:29:31 2026 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5785E1FA16C; Mon, 2 Dec 2024 08:28:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733128101; cv=none; b=lxKicUv9fAM3I54jsqE1okHGv02fsFsihANsxFyhFMP5RcUeVQb25qPuBWBXihKzWrkV43gyPjgn+PX0QHbVwdljjtexSGu52k7Y63zgsfmA5NhNoEofxR3Cp1erSO+fdhhvGguJl7x0f8K0Udtr8Ujsh+g8tbHTQOteRAyd8DA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733128101; c=relaxed/simple; bh=Rf0ZjoDnR00pyvPccIKgbQEOUbeadoDktB9N2WQxguM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Xcgk43shPbxcJ4Quq62r6Gy3cIfKiJaoYq8bbQqdvjeNw1Md7rb2eqyeVDFlZroipQjTzoBVzHn0dfiKHduI1ooZFXPSscCVetSx/Xx10OqZGKC9caKR9qMwsQyXvXvNwYOGoxnM7/vI0ryxkwx92CshaGLCZVe1xoLhXPSEYfw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=LQWuR01L; arc=none smtp.client-ip=148.163.158.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="LQWuR01L" Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4B1Ka1ou025537; Mon, 2 Dec 2024 08:28:12 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=PzEKgDn/rKSXqmNTX o3NBRYIUx3uyjVObkesFz0KD9k=; b=LQWuR01LmwBcb2be3LiGD17FjALpnnjDa 5wehK/kPfLFi/ZURE+FSJ6y0CacVSOOBxwJ8jRpHoQ4l4VtrQSK9yx2L7d5bREx8 OEM2z+/zpnVCJaHSDprEHW9zbEO+0iD06sY//q429GNmOUtXKhyZVsYMkHLYRL5D Mx3cVcIMTorNzmzhMC6kZgolb/hHl1gIWMxYCpbh1JHDdQU4eegapuZzHhC2d4Ht NRHtS/cvTirr4skFdYENNoOf6CcjUvZaVrRDf4XlS6kMY/K4crEFziIrxdVsZzno T1e83YOSpoPJzDvDCSPvb7VG13ioqOGcdHeFtwoRcU4/eniOnVVfw== Received: from ppma13.dal12v.mail.ibm.com (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 437tbx7c1f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 02 Dec 2024 08:28:12 +0000 (GMT) Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 4B27WoQ0008576; Mon, 2 Dec 2024 08:28:11 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 438f8j9wng-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 02 Dec 2024 08:28:11 +0000 Received: from smtpav07.fra02v.mail.ibm.com (smtpav07.fra02v.mail.ibm.com [10.20.54.106]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 4B28S8PU48693674 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 2 Dec 2024 08:28:08 GMT Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 22D5F20043; Mon, 2 Dec 2024 08:28:08 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EA9D120040; Mon, 2 Dec 2024 08:28:07 +0000 (GMT) Received: from tuxmaker.lnxne.boe (unknown [9.152.85.9]) by smtpav07.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 2 Dec 2024 08:28:07 +0000 (GMT) From: Sumanth Korikkar To: David Hildenbrand , linux-mm Cc: Andrew Morton , Oscar Salvador , Gerald Schaefer , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , linux-s390 , LKML , Sumanth Korikkar Subject: [RFC PATCH 4/4] s390/sclp: Add support for dynamic (de)configuration of memory Date: Mon, 2 Dec 2024 09:27:32 +0100 Message-ID: <20241202082732.3959803-5-sumanthk@linux.ibm.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241202082732.3959803-1-sumanthk@linux.ibm.com> References: <20241202082732.3959803-1-sumanthk@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: mNVRnZon9w0MjKg3c6OTZ7IdQtD_qvjb X-Proofpoint-GUID: mNVRnZon9w0MjKg3c6OTZ7IdQtD_qvjb X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-15_01,2024-10-11_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1011 impostorscore=0 mlxscore=0 suspectscore=0 mlxlogscore=999 priorityscore=1501 bulkscore=0 phishscore=0 adultscore=0 malwarescore=0 spamscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2411120000 definitions=main-2412020070 Content-Type: text/plain; charset="utf-8" CONFIG_RUNTIME_MEMORY_CONFIGURATION introduced dynamic configuration and deconfiguration of hotpluggable memory with altmap/non-altmap support during runtime. Add support for dynamic (de)configuration of standby memory on s390 by providing validation of s390 memory configuration against user inputs by overriding arch_validate_memory_range(). Design: 1. If CONFIG_RUNTIME_MEMORY_CONFIGURATION is enabled, then support runtime (de)configuration of standby memory. If CONFIG_RUNTIME_MEMORY_CONFIGURATION is disabled, then provide backward compatibility and standby memory addition is performed during boottime. 2. If CONFIG_RUNTIME_MEMORY_CONFIGURATION is enabled, /sys/devices/system/memory/configure_memory sysfs interface exists. Perform memory block range validation against user inputs. Also, measures are taken to ensure that add_memory() / remove_memory() is performed on only standby memory ranges. 3. If CONFIG_RUNTIME_MEMORY_CONFIGURATION is enabled, provide the maximum number of configurable memory blocks on s390 via /sys/devices/system/memory/max_configurable. NOTE: When there is no hotpluggable standby memory and when CONFIG_RUNTIME_MEMORY_CONFIGURATION is enabled, /sys/devices/system/memory/max_configurable will return 0. Reviewed-by: Gerald Schaefer Signed-off-by: Sumanth Korikkar --- drivers/s390/char/sclp_cmd.c | 80 ++++++++++++++++++++++++++++++++---- 1 file changed, 71 insertions(+), 9 deletions(-) diff --git a/drivers/s390/char/sclp_cmd.c b/drivers/s390/char/sclp_cmd.c index f905a6643a0f..8c02097960b0 100644 --- a/drivers/s390/char/sclp_cmd.c +++ b/drivers/s390/char/sclp_cmd.c @@ -171,11 +171,15 @@ static DEFINE_MUTEX(sclp_mem_mutex); static LIST_HEAD(sclp_mem_list); static u8 sclp_max_storage_id; static DECLARE_BITMAP(sclp_storage_ids, 256); +static bool runtime_memory_config =3D IS_ENABLED(CONFIG_RUNTIME_MEMORY_CON= FIGURATION); +static unsigned long long max_standby, max_online; +static ssize_t max_configurable; =20 struct memory_increment { struct list_head list; u16 rn; int standby; + int boot_standby; }; =20 struct assign_storage_sccb { @@ -390,24 +394,29 @@ static struct notifier_block sclp_mem_nb =3D { .notifier_call =3D sclp_mem_notifier, }; =20 -static void __init align_to_block_size(unsigned long long *start, - unsigned long long *size, - unsigned long long alignment) +static void align_to_block_size(unsigned long long *start, + unsigned long long *size, + unsigned long long alignment) { - unsigned long long start_align, size_align; + unsigned long long start_align; =20 start_align =3D roundup(*start, alignment); - size_align =3D rounddown(*start + *size, alignment) - start_align; - - pr_info("Standby memory at 0x%llx (%lluM of %lluM usable)\n", - *start, size_align >> 20, *size >> 20); + *size =3D rounddown(*start + *size, alignment) - start_align; *start =3D start_align; - *size =3D size_align; +} + +static void __init set_max_memory_configuration(void) +{ + unsigned long long blocksz =3D memory_block_size_bytes(); + + max_online =3D roundup(max_online, blocksz); + max_configurable =3D (max_online + max_standby) / blocksz; } =20 static void __init add_memory_merged(u16 rn) { unsigned long long start, size, addr, block_size; + unsigned long long basesize, basestart; static u16 first_rn, num; =20 if (rn && first_rn && (first_rn + num =3D=3D rn)) { @@ -423,9 +432,17 @@ static void __init add_memory_merged(u16 rn) if (start + size > ident_map_size) size =3D ident_map_size - start; block_size =3D memory_block_size_bytes(); + basestart =3D start; + basesize =3D size; align_to_block_size(&start, &size, block_size); + pr_info("Standby memory at 0x%llx (%lluM of %lluM usable)\n", + basestart, size >> 20, basesize >> 20); if (!size) goto skip_add; + if (runtime_memory_config) { + max_standby +=3D size; + goto skip_add; + } for (addr =3D start; addr < start + size; addr +=3D block_size) add_memory(0, addr, block_size, MACHINE_HAS_EDAT1 ? @@ -435,6 +452,48 @@ static void __init add_memory_merged(u16 rn) num =3D 1; } =20 +#ifdef CONFIG_RUNTIME_MEMORY_CONFIGURATION +bool arch_validate_memory_range(unsigned long long start, unsigned long lo= ng end) +{ + unsigned long long incr_start, incr_end, curr =3D start; + struct memory_increment *incr; + bool rangefound =3D false; + + if (start >=3D ident_map_size || end + 1 > ident_map_size) { + pr_info("Memory range (start:0x%llx,end:0x%llx) exceeds max physical mem= ory (0x%lx)\n", + start, end, ident_map_size); + goto out; + } + + list_for_each_entry(incr, &sclp_mem_list, list) { + incr_start =3D rn2addr(incr->rn); + incr_end =3D incr_start + sclp.rzm - 1; + + if (curr !=3D incr_start) + continue; + /* + * Allow runtime configuration/deconfiguration for only + * standby memory + */ + if (!incr->boot_standby) + goto out; + if (incr_end =3D=3D end) { + rangefound =3D true; + goto out; + } else { + curr =3D incr_end + 1; + } + } +out: + return rangefound; +} + +ssize_t arch_get_memory_max_configurable(void) +{ + return max_configurable; +} +#endif + static void __init sclp_add_standby_memory(void) { struct memory_increment *incr; @@ -456,6 +515,7 @@ static void __init insert_increment(u16 rn, int standby= , int assigned) return; new_incr->rn =3D rn; new_incr->standby =3D standby; + new_incr->boot_standby =3D standby; last_rn =3D 0; prev =3D &sclp_mem_list; list_for_each_entry(incr, &sclp_mem_list, list) { @@ -502,6 +562,7 @@ static int __init sclp_detect_standby_memory(void) if (!sccb->entries[i]) continue; assigned++; + max_online +=3D sclp.rzm; insert_increment(sccb->entries[i] >> 16, 0, 1); } break; @@ -530,6 +591,7 @@ static int __init sclp_detect_standby_memory(void) if (rc) goto out; sclp_add_standby_memory(); + set_max_memory_configuration(); out: free_page((unsigned long) sccb); return rc; --=20 2.45.2