From patchwork Mon Dec 2 08:27:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumanth Korikkar X-Patchwork-Id: 13895581 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 E8599E77170 for ; Thu, 5 Dec 2024 15:31:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BC97A6B011C; Thu, 5 Dec 2024 10:19:28 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 889786B00C8; Thu, 5 Dec 2024 10:19:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ACD2B6B0127; Thu, 5 Dec 2024 10:19:14 -0500 (EST) 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 D1FFA6B0088 for ; Mon, 2 Dec 2024 03:28:03 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 5980E1611F8 for ; Mon, 2 Dec 2024 08:28:03 +0000 (UTC) X-FDA: 82849340994.16.C21B495 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by imf16.hostedemail.com (Postfix) with ESMTP id 5BD7B180013 for ; Mon, 2 Dec 2024 08:27:49 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=oL60V92d; spf=pass (imf16.hostedemail.com: domain of sumanthk@linux.ibm.com designates 148.163.158.5 as permitted sender) smtp.mailfrom=sumanthk@linux.ibm.com; dmarc=pass (policy=none) header.from=ibm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733128073; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=FckEokSgRioUHQRcHayHqWILEETFnWG+x7hLq5rxsJM=; b=QqgrFbR3JJxWARhHM7FxfncOzB1JVaxLNzYXYWllVLLYyBqlQ2wODlmqrkV63gS4LqkrZ3 orSKTm+026UuELc3ERU1ziLSma66jaUCvMoE9jwXqN0pFAzvKwk2IJuJIyy680Uiy0gQqF p9pQJj/HfvyxPrpnXW6WJF+UGqqTSB0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733128073; a=rsa-sha256; cv=none; b=diDXwXY3TZ1jEs16ldHA9sGijmctGPa0+F64UO+y5/ltl4Ni3c9c+E5+JyG/0nDmoyUMnF akSS+6J1QBMKBgObZVnN46Yq3EpwYIV9x1YdQIJT2gvfZ0f9+sSanATDJzdgz+ldoKYIh2 HnJZwpiQgFlVcwcH6gbNbyvxKKFRAys= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=oL60V92d; spf=pass (imf16.hostedemail.com: domain of sumanthk@linux.ibm.com designates 148.163.158.5 as permitted sender) smtp.mailfrom=sumanthk@linux.ibm.com; dmarc=pass (policy=none) header.from=ibm.com 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> MIME-Version: 1.0 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 X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 5BD7B180013 X-Stat-Signature: u85d48qm9qo49jbnbhgb539mazyo6mcg X-Rspam-User: X-HE-Tag: 1733128069-70499 X-HE-Meta: U2FsdGVkX1/BB47BQZ4OW/bKkQU6pCQa7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d/lPN68ayRO9jGIJaxg2eWyb+zEdSbK3HMNOeH/96D5VKF0HJPVjqDqdWSgSxB/hbQ0tG3oVShUY7OrnMMOD/MTC4xZy4m141jj2E2LEbSJt9SoUU5XpIvlhJ1x3Jyzu8DVwgMlHZx/TAWroJv7cWJKCyZIvq5Vr1SAKbMFrsc4gqYB7+QcLodH8b4vXTsUlLbKgmk9u5L6vmzUUZ1JL3RH7r7thVxXlWgQ5Pv6x8zO0a8Q2/NdPbU4hH5IaBOhRJBAt2rtBrmiL2dYvumv4bfLe7Lc4NCf2K3fv1Jr3Lc+FW8nSojzjgVUtj5 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: List-Subscribe: List-Unsubscribe: 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; } +#ifdef CONFIG_RUNTIME_MEMORY_CONFIGURATION +enum { + REMOVE_MEMORY = 0, + ADD_MEMORY, + MAX_CONFIGURE_MODE +}; + +enum { + NOALTMAP = 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 = -EINVAL; + struct memory_block *mem; + + num = sscanf(buf, "%u,0x%llx-0x%llx,%u", &config_mode, &start, &end, &altmap_mode); + if (num != 4) + goto out; + + if (config_mode >= MAX_CONFIGURE_MODE || altmap_mode >= MAX_ALTMAP_MODE) + goto out; + + altmap_mode = altmap_mode ? MHP_MEMMAP_ON_MEMORY | + MHP_OFFLINE_INACCESSIBLE : MHP_NONE; + + block_size = memory_block_size_bytes(); + + if (!IS_ALIGNED(start, block_size) || !IS_ALIGNED(end + 1, block_size)) + goto out; + + if (start < 0 || end < 0 || start >= end) + goto out; + + if (!arch_validate_memory_range(start, end)) + goto out; + + ret = lock_device_hotplug_sysfs(); + if (ret) + goto out; + + if (config_mode == ADD_MEMORY) { + for (range = start; range < end + 1; range += block_size) { + mem = find_memory_block(pfn_to_section_nr(PFN_DOWN(range))); + if (mem) { + pr_info("Memory already configured - (start:0x%llx)\n", range); + ret = -EEXIST; + put_device(&mem->dev); + goto out_unlock; + } + nid = memory_add_physaddr_to_nid(range); + ret = __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 == REMOVE_MEMORY) { + for (range = start; range < end + 1; range += block_size) { + mem = find_memory_block(pfn_to_section_nr(PFN_DOWN(range))); + if (!mem) { + pr_info("Memory not configured - (start:0x%llx)\n", range); + ret = -EINVAL; + goto out_unlock; + } + if (mem->state != MEM_OFFLINE) { + pr_info("Memory removal failed - (start:0x%llx) not offline\n", + range); + put_device(&mem->dev); + ret = -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[] = { &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 }; +#ifdef CONFIG_RUNTIME_MEMORY_CONFIGURATION +bool arch_validate_memory_range(unsigned long long start, unsigned long long 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 +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 config ARCH_MHP_MEMMAP_ON_MEMORY_ENABLE From patchwork Mon Dec 2 08:27:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumanth Korikkar X-Patchwork-Id: 13895599 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 AF6E7E77176 for ; Thu, 5 Dec 2024 15:35:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9D2DC6B013F; Thu, 5 Dec 2024 10:19:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2717D6B0137; Thu, 5 Dec 2024 10:19:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D6C376B012C; Thu, 5 Dec 2024 10:19:15 -0500 (EST) 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 62CCF6B0088 for ; Mon, 2 Dec 2024 03:28:08 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id DB4918147B for ; Mon, 2 Dec 2024 08:28:07 +0000 (UTC) X-FDA: 82849340868.01.58AB3BE Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by imf01.hostedemail.com (Postfix) with ESMTP id D983C4000C for ; Mon, 2 Dec 2024 08:27:56 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=BD7l8Og9; dmarc=pass (policy=none) header.from=ibm.com; spf=pass (imf01.hostedemail.com: domain of sumanthk@linux.ibm.com designates 148.163.158.5 as permitted sender) smtp.mailfrom=sumanthk@linux.ibm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733128074; a=rsa-sha256; cv=none; b=q7/7qYOCFdTA3qhnWU4wWo29KS2UrZfdf907S4KXno0akJl/zLbtO8L8Yswp4wxM6opSqy co9Q6Ab9YOV6WyYnUa+2NYp42k44u8ap1LJPUDSSiTMl+i7W7znm3CFOrt3TBNONKzQ2TH W3PVZp4aW3ytYfzVrU3YMVTWLzbhzQA= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=BD7l8Og9; dmarc=pass (policy=none) header.from=ibm.com; spf=pass (imf01.hostedemail.com: domain of sumanthk@linux.ibm.com designates 148.163.158.5 as permitted sender) smtp.mailfrom=sumanthk@linux.ibm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733128074; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ttEIqKp1gqeMV+LBQOU9I5MsmYSVPQfGPglAO21iWo8=; b=dSoLZtHCiG4tQlGmNSzosBlJsy9nkUbLNI4ndmXJQ2+OFCsX4bSZfpO5ux4LsflRUejfoi gTf31YyEHn2pdhXnlxr8Xd5vWMxxMbEKzHECXUQKc+E98kMvV4qYmSvo9K0yz6E7xFF7gr 9MTHc1SfwfUloo2fRNGb0vGoFX4aHJ0= 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> MIME-Version: 1.0 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 X-Stat-Signature: sf1gxc9iex5asuwuhru3yw5zh7p1gt34 X-Rspam-User: X-Rspamd-Queue-Id: D983C4000C X-Rspamd-Server: rspam08 X-HE-Tag: 1733128076-223112 X-HE-Meta: U2FsdGVkX18p3f1gKaOjDuILDq6yeI3Ji+sME6xwow26sfvX+8dndeRNUrM+7nLPGbva4qsnQsUZ8i2037jrLRB3YCvPyuCTItBiinLa4xxaBjA47gZSRZVP3OqmzuztB4En2AcxdWFL8yfCCWO4ZYQjQgW12eML4K/heglqZ8T8VVpZbB+xO67nk18ZVEhHokt3PyfG9rASMolsGUM8WRQS1orgNeA/UKJ1Qy3XWN3peY/MqO0/fgzoL+5QWjkgo6wz/v9pQkkcLdDyMo7EGW4tDacAKDCyD5XuHjfM8KxzFc7DgfZ59genn1kffutU6ctWXs1QKWdNWXSIhM7qTra4cUk4Duhi5YQ9h7YIqmXApY0egNIL1YB5Oap/JzlUp/oNGo8TuS8azYCIwO7pjcIj1urwXZIdq/AygcIBnps2wTaxfamXRjOI1xuTaRT6vdhUk2q/hWbUrJgoRbEWW1/q5A5fFJDORCcMcHeKyFKx27rPkxnck1N1Tjfvh7s8h9mhlBOmlI10H4Lhx5iTKermqBxDuZi9uDO171NfkwBr93VNqFOHD1321K+QCJMOFTWZ4xcGruFWSLiaYp4B2kZnM4bh00sTszWRDkGkjZ/QuwpqHE/4jzxTkD4HyiwmkkT4bSoS+CnO1x0OeiovcqbHE7Fsk054+fKhdfOhUH4Vc4rrTyMkMQCVx3o+/42u5vTjVn/pq6KRSRv7poOQFJvxcuGJu5Qb8O2bRgngXxhAmHNdKr+2UCC05WsXUI7OCGMPiunQ6DWPdHK0/uhOKfNtup3+iBRgPMl5NYVDzuw8ZkyHhveLOjzdIRv2x82swFqCLTpX33tGITH5BJOjsEN4o8THc40fq8eOmJuvCQTOSdGrER2k1cj+1sCFUw/1dvAy2Ks6D9EqBMzjILLq3jS+NLPKisLm0f1kuvQwRnRxIyrJECKatZdLzK4nyZkWraySulETW7U91r7QEdP rrJ8UqsP XEApzSkKEQnxTXI2t9mVS1o9xpVLoOqsxe2QH4WsGz2K06k6Uhy8proHqn7Mue/hxn4ZNVGHhTG/4z1IqyxKG5s5MqGAYtWwbMKaAsF+muhTuzQ9KG0NedU5JDuwp0Knd3KmtgFEt7yxwdpag4onhEkDaklTCvLVpMT2zRG3fpkaVOdniU4ZSFSDdZhjtLOcvlMhW/eerWCPLq/ziwictrcp4Go60/v2zYwmpsAZ7pXUD2X5KJIT6s1gHNbwdajrGapEchJOKzLKwwysTzBz7T1UNnqqlQhSCGzMyse9pSPPlZGYjgZ+PN65fLPonia8SWXIcmMDx8H/KvQLbXsR1Ut43iWCNXNwtBj8WzD4ZkdXPn/xvHKVfQLg6UQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000009, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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)); } +static ssize_t altmap_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct memory_block *mem = 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); /* * Show the memory block size (shared by all memory blocks). @@ -785,6 +794,7 @@ static struct attribute *memory_memblk_attrs[] = { #ifdef CONFIG_MEMORY_HOTREMOVE &dev_attr_valid_zones.attr, #endif + &dev_attr_altmap.attr, NULL }; From patchwork Mon Dec 2 08:27:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumanth Korikkar X-Patchwork-Id: 13895593 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 CE631E7716D for ; Thu, 5 Dec 2024 15:34:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B7D106B00D7; Thu, 5 Dec 2024 10:19:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1B1B26B0129; Thu, 5 Dec 2024 10:19:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D864C6B00C4; Thu, 5 Dec 2024 10:19:15 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 3BEA36B0088 for ; Mon, 2 Dec 2024 03:28:12 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id EC9E7121285 for ; Mon, 2 Dec 2024 08:28:11 +0000 (UTC) X-FDA: 82849341246.10.8D9E79B Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by imf28.hostedemail.com (Postfix) with ESMTP id D72D8C0007 for ; Mon, 2 Dec 2024 08:27:54 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b="Z/qNdeW1"; dmarc=pass (policy=none) header.from=ibm.com; spf=pass (imf28.hostedemail.com: domain of sumanthk@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=sumanthk@linux.ibm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733128078; a=rsa-sha256; cv=none; b=n76jnaLXBEQ6ARFoi+Lu/WgyVZQ6/B52fTngdp8quhDi0JSyJzraAN7R3TZKBxuAMiVABW MnGR34b/Q7nPr+6YmMQNKf1s1MxU29/HSC0ikP/qUBtihnF8IUlc1PuPE0KglG1q7jsrhN nqfCOb0hB7r17ROwupDM7gpB+WWPTDQ= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b="Z/qNdeW1"; dmarc=pass (policy=none) header.from=ibm.com; spf=pass (imf28.hostedemail.com: domain of sumanthk@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=sumanthk@linux.ibm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733128078; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=fxEOWl+pF9H+TPIB1u0RcA7fohWLpjI43sHvTpb8qt4=; b=SeV48I/QbBGTzfWrEzyiXodf+UUNTnN0P5jlWaZlP2xpa/v2oQ3Y9VVpe8Mldd5JvlyZRU 9FCQS/7rWNHpKsq4gVz8oRDNZvS7J4jGxdS0Hfkk61uCXrGzj1fzPwqR0qakD/WWHQeNlM Mr0T3fhEYUWmnAOUN+xkHYno1ORVxJE= 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> MIME-Version: 1.0 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 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: D72D8C0007 X-Stat-Signature: d917h18doa3fe65y6faqoiohwrukr8jy X-Rspam-User: X-HE-Tag: 1733128074-851036 X-HE-Meta: U2FsdGVkX19InPYFVJSZfiLxNwJnNbrZZHOYyrP7FwlTUxcMujFdP6+L5iLSgw0AWd6NwWkD+Qzf3m5XYYDxJn3VyutPWHJ2jhRI1GmBogxDU/n8cWGDaz31jsHycIkgN1mlQ+DdpqH+Zp2FWwKUxWpeN6bUCLMSMbGO7sE8L/9EQcuqzf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4jkR/WQjoEIj5qKUa69jKMHff0dGjeNN3rTmpFZ44TtUFbo49mstWuCTDZZnzuhXPemUIEgqT5SDyv8MIhskBBX7QQ0QOsU1x0gMrQ== 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: List-Subscribe: List-Unsubscribe: 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 long start, return false; } +/* + * Arch can override the function and return the number of maximum configurable + * 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 *dev, 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_attribute *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 */ /* @@ -1075,6 +1093,7 @@ static struct attribute *memory_root_attrs[] = { #endif #ifdef CONFIG_RUNTIME_MEMORY_CONFIGURATION &dev_attr_configure_memory.attr, + &dev_attr_max_configurable.attr, #endif NULL }; From patchwork Mon Dec 2 08:27:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumanth Korikkar X-Patchwork-Id: 13890112 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 631ADD10DBD for ; Mon, 2 Dec 2024 08:28:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F20936B0088; Mon, 2 Dec 2024 03:28:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id ECFC86B0089; Mon, 2 Dec 2024 03:28:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DBEE66B008A; Mon, 2 Dec 2024 03:28:15 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id C00356B0088 for ; Mon, 2 Dec 2024 03:28:15 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 796DE141395 for ; Mon, 2 Dec 2024 08:28:15 +0000 (UTC) X-FDA: 82849341204.08.4A8A42A Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by imf27.hostedemail.com (Postfix) with ESMTP id 9170240019 for ; Mon, 2 Dec 2024 08:27:58 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=LQWuR01L; dmarc=pass (policy=none) header.from=ibm.com; spf=pass (imf27.hostedemail.com: domain of sumanthk@linux.ibm.com designates 148.163.158.5 as permitted sender) smtp.mailfrom=sumanthk@linux.ibm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733128082; a=rsa-sha256; cv=none; b=V+HvOmGdWSg/UfPacwTYuhBHcEAj0UhAjneDn8ZJ+o8cLNThWCL+rvukHA6ISeJdRmAOw5 +sv3mleAPbjRdftpEJvBAcbiWkRKIwOu4gR1SCyrp9hsBiGVswadr8o9+LdT/Lq2WaZz9x XxuFM/kwHcmKI4FSOaPRysvta6yw9IY= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=LQWuR01L; dmarc=pass (policy=none) header.from=ibm.com; spf=pass (imf27.hostedemail.com: domain of sumanthk@linux.ibm.com designates 148.163.158.5 as permitted sender) smtp.mailfrom=sumanthk@linux.ibm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733128082; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=PzEKgDn/rKSXqmNTXo3NBRYIUx3uyjVObkesFz0KD9k=; b=q1SGd/Cm/bVLh/LS+7zuKesQUnHbXxj9IebLU5ZbND3mqyW+qyNUABUVZjur6sDRZNeuND p1ayUjeFSiQc5QvzzpQAU4+/qn+zjzxN+4GZLLqqhdgkrVLQ5fOorGBh0HkGl+MK3jrn4f 6R0kJBwY2Fupa4ksr2nZ3npd3y/SR5o= 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> MIME-Version: 1.0 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-2412020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z1OynGlUqxARDmKc6qSTnwGOTC+cf ludRB/Fk SrCNCmEBGwAmr6th+1hhIr/aySp9+NkAfH7jHd4BQYJhQ429MRWyEsVYAhn4fWb7kjO7FIQwq2y4ZA0mjvfQeQ1watNF2HLx+8KNJqXmNYBmVDGu4pAku81gZbQ666pP85hkkAvZZGqcPTcEqfkarihpe8kZXYb4qrdAvJj+NlDyOsu7WTP8AoBdXADdXYj2IBuUEkxzvyv9Sy3ro1le05c6eFxXwYMCVRZL2jvTijzqGbLjblRj7kbWHr0xJ7NbEkTp/OxqpiWs7PP7118KB/Q01llVOQQcm8v57 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: List-Subscribe: List-Unsubscribe: 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 = IS_ENABLED(CONFIG_RUNTIME_MEMORY_CONFIGURATION); +static unsigned long long max_standby, max_online; +static ssize_t max_configurable; struct memory_increment { struct list_head list; u16 rn; int standby; + int boot_standby; }; struct assign_storage_sccb { @@ -390,24 +394,29 @@ static struct notifier_block sclp_mem_nb = { .notifier_call = sclp_mem_notifier, }; -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; start_align = roundup(*start, alignment); - size_align = 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 = rounddown(*start + *size, alignment) - start_align; *start = start_align; - *size = size_align; +} + +static void __init set_max_memory_configuration(void) +{ + unsigned long long blocksz = memory_block_size_bytes(); + + max_online = roundup(max_online, blocksz); + max_configurable = (max_online + max_standby) / blocksz; } 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; if (rn && first_rn && (first_rn + num == rn)) { @@ -423,9 +432,17 @@ static void __init add_memory_merged(u16 rn) if (start + size > ident_map_size) size = ident_map_size - start; block_size = memory_block_size_bytes(); + basestart = start; + basesize = 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 += size; + goto skip_add; + } for (addr = start; addr < start + size; addr += block_size) add_memory(0, addr, block_size, MACHINE_HAS_EDAT1 ? @@ -435,6 +452,48 @@ static void __init add_memory_merged(u16 rn) num = 1; } +#ifdef CONFIG_RUNTIME_MEMORY_CONFIGURATION +bool arch_validate_memory_range(unsigned long long start, unsigned long long end) +{ + unsigned long long incr_start, incr_end, curr = start; + struct memory_increment *incr; + bool rangefound = false; + + if (start >= ident_map_size || end + 1 > ident_map_size) { + pr_info("Memory range (start:0x%llx,end:0x%llx) exceeds max physical memory (0x%lx)\n", + start, end, ident_map_size); + goto out; + } + + list_for_each_entry(incr, &sclp_mem_list, list) { + incr_start = rn2addr(incr->rn); + incr_end = incr_start + sclp.rzm - 1; + + if (curr != incr_start) + continue; + /* + * Allow runtime configuration/deconfiguration for only + * standby memory + */ + if (!incr->boot_standby) + goto out; + if (incr_end == end) { + rangefound = true; + goto out; + } else { + curr = 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 = rn; new_incr->standby = standby; + new_incr->boot_standby = standby; last_rn = 0; prev = &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 += 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;