Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp207416rdh; Thu, 23 Nov 2023 01:24:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IGq5KlomOIhoC2KfBIUQC2ts6CJwCGTxFi1HbvQE1fP86jI3vFI6MDjwqil9JaKQe2JMIdR X-Received: by 2002:a05:6a00:2d94:b0:6cb:db40:4568 with SMTP id fb20-20020a056a002d9400b006cbdb404568mr3114193pfb.17.1700731496711; Thu, 23 Nov 2023 01:24:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700731496; cv=none; d=google.com; s=arc-20160816; b=siDCfRDzFSY/cGDTB6nhpBaqlf3KKJm1Hpk7PgoqcC71MYO3icHoIDSrw+TcqHfhYw dxCLtfpcdnh8TP9wiOZSUpXhGO6PMCePt+rPc2zsFDWXls9mT7vODt6Z2e6gWP2XBi+b dZUXvGwanRJh2Ib3uQ/PjiKOMvZWNpLsTzUUEHoaXieuccPixspOSYx6uLAeUiftI7Sq 0yPZc+YQPqZ0iYggSbwci215XsVL5vbhY9kyICpbfkMZluc/uiBTFzQf/JRDbPLwmaOT TVrTxsey70bQWRsO9KFrvPUBcvZD7qgygbmBgPWk9p2TI57+v9ccMG+n5wMOIbZ3cTv2 LAhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=HwbCfMd9FDVn6PpCGOGhbJh/24QSajgcDKz+c2O+fJc=; fh=gDYt9MY/1X/h5fcLsrPXNJSbxtFOUO5bXnC2IdpKvq4=; b=bSjqGBQvRSo/gYpeG/eLiRaFqrS+8Oz8qw6ED1WtNKyQi9jLSiotTh3WCXHFwUFHB6 QLdfORvP/rRco5Iu96Umt7ppgs63tdqlX72RIeI4Yim0K6jDfUlgS1cLCPpy42IwbnMJ dW1twvxtrQ7H7dweE223T7aE5uK44ORZ1LlIyMM7f8t2dzMELxQn4J1HOJHOw9PG3P10 gEM3kmJ2F30G456KYpRPVn3Yd1Ezmp/bDGy2eL+0qdR5Xa3PpgcAml9m8B9jg0N0LUO3 5lcrWiu/2gdjLg4jelm7zP22aY82st1qGlayci3Xn/g1YvpRwxiKPSKTsHfHH74MerDz BnIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=DTKWH7wJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id f12-20020a631f0c000000b005898b0b851asi938132pgf.530.2023.11.23.01.24.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Nov 2023 01:24:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=DTKWH7wJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 61F638083AD5; Thu, 23 Nov 2023 01:24:52 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232645AbjKWJYR (ORCPT + 99 others); Thu, 23 Nov 2023 04:24:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231656AbjKWJYF (ORCPT ); Thu, 23 Nov 2023 04:24:05 -0500 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9AF5D41; Thu, 23 Nov 2023 01:24:11 -0800 (PST) Received: from pps.filterd (m0353727.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3AN9MJew015055; Thu, 23 Nov 2023 09:24:01 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=HwbCfMd9FDVn6PpCGOGhbJh/24QSajgcDKz+c2O+fJc=; b=DTKWH7wJ+GKrW6nB2PoOXQvtPeUg8dEfEpNuODKRz5a5fJqMzfj/Iz5aZsuyadd6TfZg z4M8xjYHa+Wbm7VriuZgLgkskdJqvJKQxnbpnEzYFctTRKMit24KMFRIGV2JExslsySd sCLbfORP7jslfw2sFInRbxAxEIptrtTdV+sLZcdIOUbJX8R0r9y2BB4pE2mHCkWjaqlf n3c2vZV08K+k97D4alFSjAtvaqYNTUPDpUE44c7cn/axC4AZhGdjoh8ku4wmL+KcXs1E ZD/KIJslqPBZEV9VNlmN31RgmtnQ9487YMMY0KsC0XvyE3qpR4X2FJyrvMfeKdZCm5wd kg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3uj41vr1b4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 23 Nov 2023 09:24:00 +0000 Received: from m0353727.ppops.net (m0353727.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 3AN9N0Bm017396; Thu, 23 Nov 2023 09:24:00 GMT 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 3uj41vr1ad-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 23 Nov 2023 09:23:59 +0000 Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 3AN8nEja023488; Thu, 23 Nov 2023 09:23:59 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 3uf9tknumx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 23 Nov 2023 09:23:58 +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 3AN9NuvC29229736 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 23 Nov 2023 09:23:56 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EF6F120040; Thu, 23 Nov 2023 09:23:55 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C09F32004B; Thu, 23 Nov 2023 09:23:55 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 23 Nov 2023 09:23:55 +0000 (GMT) From: Sumanth Korikkar To: linux-mm , Andrew Morton , David Hildenbrand Cc: Oscar Salvador , Michal Hocko , "Aneesh Kumar K.V" , Anshuman Khandual , Gerald Schaefer , Sumanth Korikkar , Alexander Gordeev , Heiko Carstens , Vasily Gorbik , linux-s390 , LKML Subject: [PATCH v2 1/7] mm/memory_hotplug: introduce mhp_flag MHP_OFFLINE_INACCESSIBLE Date: Thu, 23 Nov 2023 10:23:37 +0100 Message-Id: <20231123092343.1703707-2-sumanthk@linux.ibm.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231123092343.1703707-1-sumanthk@linux.ibm.com> References: <20231123092343.1703707-1-sumanthk@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 1LOAtid-uln_WgoAXOcTLt5CJX2DCdKE X-Proofpoint-GUID: 43IddKH6wX7PlbvKGysk-2j4SFo5RpMm X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.987,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-23_07,2023-11-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 lowpriorityscore=0 mlxscore=0 phishscore=0 mlxlogscore=447 clxscore=1015 bulkscore=0 adultscore=0 priorityscore=1501 suspectscore=0 impostorscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2311230067 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Thu, 23 Nov 2023 01:24:52 -0800 (PST) Introduce MHP_OFFLINE_INACCESSIBLE mhp_flag to mark the hotplugged memory block as inaccessible during the memory hotplug addition phase. With support for "memmap on memory", the altmap is prepared at this stage. Architectures like s390 anticipate that memmap should not be accessed until memory is physically accessible and is accessible only when it enters the memory hotplug onlining phase using the memory notifier. Introduce the flag to inform the memory hotplug infrastructure that the memory remains inaccessible until the memory hotplug onlining phase begins. Implementation considerations: mhp inaccessible flag is initially set in altmap. This is useful in arch_add_memory(). When the memory block device is added, the mhp inaccessible information is passed to memory_block. The flag is used in subsequent patch to avoid accessing memmap during memory hotplug addition phase. Signed-off-by: Sumanth Korikkar --- drivers/base/memory.c | 2 ++ include/linux/memory.h | 1 + include/linux/memory_hotplug.h | 10 ++++++++++ include/linux/memremap.h | 1 + mm/memory_hotplug.c | 3 ++- 5 files changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/base/memory.c b/drivers/base/memory.c index 8a13babd826c..51915d5c3f88 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -774,6 +774,8 @@ static int add_memory_block(unsigned long block_id, unsigned long state, mem->state = state; mem->nid = NUMA_NO_NODE; mem->altmap = altmap; + if (altmap) + mem->inaccessible = altmap->inaccessible; INIT_LIST_HEAD(&mem->group_next); #ifndef CONFIG_NUMA diff --git a/include/linux/memory.h b/include/linux/memory.h index f53cfdaaaa41..655714d4e65a 100644 --- a/include/linux/memory.h +++ b/include/linux/memory.h @@ -67,6 +67,7 @@ struct memory_group { struct memory_block { unsigned long start_section_nr; unsigned long state; /* serialized by the dev->lock */ + bool inaccessible; /* during memory addition phase */ int online_type; /* for passing data to online routine */ int nid; /* NID for this memory block */ /* diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h index 7d2076583494..8988cd5ad55d 100644 --- a/include/linux/memory_hotplug.h +++ b/include/linux/memory_hotplug.h @@ -106,6 +106,16 @@ typedef int __bitwise mhp_t; * implies the node id (nid). */ #define MHP_NID_IS_MGID ((__force mhp_t)BIT(2)) +/* + * Mark the hotplugged memory block as inaccessible during the memory hotplug + * addition phase. With support for "memmap on memory," the altmap is prepared + * at this stage. Architectures like s390 anticipate that memmap should not be + * accessed until memory is physically accessible and is accessible only when + * it enters the memory hotplug onlining phase using the memory notifier. + * Utilize this flag to inform the memory hotplug infrastructure that the + * memory remains inaccessible until the memory hotplug onlining phase begins. + */ +#define MHP_OFFLINE_INACCESSIBLE ((__force mhp_t)BIT(3)) /* * Extended parameters for memory hotplug: diff --git a/include/linux/memremap.h b/include/linux/memremap.h index 744c830f4b13..9837f3e6fb95 100644 --- a/include/linux/memremap.h +++ b/include/linux/memremap.h @@ -25,6 +25,7 @@ struct vmem_altmap { unsigned long free; unsigned long align; unsigned long alloc; + bool inaccessible; }; /* diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 7a5fc89a8652..1e02eba166b0 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1092,7 +1092,6 @@ int mhp_init_memmap_on_memory(unsigned long pfn, unsigned long nr_pages, ret = kasan_add_zero_shadow(__va(PFN_PHYS(pfn)), PFN_PHYS(nr_pages)); if (ret) return ret; - move_pfn_range_to_zone(zone, pfn, nr_pages, NULL, MIGRATE_UNMOVABLE); for (i = 0; i < nr_pages; i++) @@ -1439,6 +1438,8 @@ int __ref add_memory_resource(int nid, struct resource *res, mhp_t mhp_flags) if (mhp_flags & MHP_MEMMAP_ON_MEMORY) { if (mhp_supports_memmap_on_memory(size)) { mhp_altmap.free = memory_block_memmap_on_memory_pages(); + if (mhp_flags & MHP_OFFLINE_INACCESSIBLE) + mhp_altmap.inaccessible = true; params.altmap = kmalloc(sizeof(struct vmem_altmap), GFP_KERNEL); if (!params.altmap) { ret = -ENOMEM; -- 2.39.2