Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp2044322rdb; Sun, 19 Nov 2023 23:24:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IEsAKEj7k65ai1vL6AZrphgFlGOMuaJHtFMmrzUK7sDQDRo+rtS82Jly4yNOd0+/er56c30 X-Received: by 2002:aca:1005:0:b0:3b5:6467:8cf5 with SMTP id 5-20020aca1005000000b003b564678cf5mr8701351oiq.54.1700465079377; Sun, 19 Nov 2023 23:24:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700465079; cv=none; d=google.com; s=arc-20160816; b=NrFDvYlh1sW0x82mcRYFJ+vuqkLDSShVcKaR2nY6MNcTaMSQbXCbmhSDYEsHQpfjBb 2OdBM8F85XJC5nKqC/TweLH+6C+yotYlDdsa5P3zAil6o5J4HO77ytcG06O9HXiuOamF PN50PET6864E9zr0zMKVf9ByWYRKT1EfL890xGPHWwO9GiCeY0o7GTTu0YgPr20A6N92 +2BviK61k+QMlWIcQsTdKv2vAP1ApgT4OxwLKTzyrsg/lqrH1Xwa5qidI9IAcJlJb6pW b2G4luXftlk4ziaJqzUUJSOXuk/C2b+O60Wja10ntD1uMx4DVMqQkO4HDIgLCwXBWI7C APrA== 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=BwjqaOg3dzwZ6bAKcYCLKvjoYag2ay5CRFizDGiN3hA=; fh=16z9eSgr+T6wkiFTMo20mXPHGWzPIsCuS8kXeZ8Bzu4=; b=js06uKh2ioDVCHuQ2RmcYL1YwxSBDGRaUbz0/9yLEa9FhrEC53agMZvofA7q1ZgB4u iUtAcCgbSJ1kURagzn+9F6k36WHvNXW4fMwi5m8JIZ9Pb96Vd8rBWFX5y6agZw6/aCHA dG9TIidBYGx3OIzlAFgoqAv8aUCmicLgqt2vK2ghwCwEqxtr1TzdVJpYJgIWQ9d05s9t bodVxwhwB2FoAqG8nKTts5WtuD/U/MIOvQiTRF1vBgopuKqry5JsH/Lt+UrjzsHc2vHD o0hDPVWL3WIXBMhZppFHOg5Gr6cjSVYIx2tlRNdYW0csYkMIZ2rpvRSTN82Eczt7yw7Z Obsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=kF1+pCmP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id r142-20020a632b94000000b005c2188ae874si5655009pgr.576.2023.11.19.23.24.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Nov 2023 23:24:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=kF1+pCmP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id C8EF480A30DA; Sun, 19 Nov 2023 23:23:58 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232054AbjKTHXq (ORCPT + 99 others); Mon, 20 Nov 2023 02:23:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229562AbjKTHXp (ORCPT ); Mon, 20 Nov 2023 02:23:45 -0500 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C810AF; Sun, 19 Nov 2023 23:23:41 -0800 (PST) Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3AK5gOLv027826; Mon, 20 Nov 2023 07:23:31 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=BwjqaOg3dzwZ6bAKcYCLKvjoYag2ay5CRFizDGiN3hA=; b=kF1+pCmPaClbQLuxSRDULLXpJZO9ItqZjz0B15kaOcXODbXqN4xga7zAj5VWnKoEDmaU DeUiU6iVJGJy4uuAHaFZIfXo3GQf0aPXUKcyI4jHiZfTCnN9lrvL/oTFvN2xpZdqzbsh qQpaLU8wOW+GyXNvc0YFTA6D0kHuQ502Y6MfLB/nqpJJyqpD1/4Zqj3Z5Oj2RZoHfwTA O6FoBSofX6dn/OZW+g7JORUEPfp37K8FbajuCli2nOgILvN1ZEVFNvmsJxQhzSHTTQSa 1nt/McVZ/m9lhUF+Fed9UVxJsLsU12YEE/05WO2ZSh22lvRp2QXU7/h4SxCvgbh9PSXx Fg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3ufuws05pv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Nov 2023 07:23:30 +0000 Received: from m0356516.ppops.net (m0356516.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 3AK7GIkh018207; Mon, 20 Nov 2023 07:23:30 GMT Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3ufuws05pj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Nov 2023 07:23:30 +0000 Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 3AK7KRBM008955; Mon, 20 Nov 2023 07:23:29 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3uf7yy7rxr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Nov 2023 07:23:29 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 3AK7NQWs42074552 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 20 Nov 2023 07:23:26 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2F34F20040; Mon, 20 Nov 2023 07:23:26 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D47E22004B; Mon, 20 Nov 2023 07:23:25 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 20 Nov 2023 07:23:25 +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 , Alexander Gordeev , Heiko Carstens , Vasily Gorbik , linux-s390 , LKML Subject: [PATCH 2/3] mm/memory_hotplug: fix error handling in add_memory_resource() Date: Mon, 20 Nov 2023 08:23:16 +0100 Message-Id: <20231120072317.3169630-3-sumanthk@linux.ibm.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231120072317.3169630-1-sumanthk@linux.ibm.com> References: <20231120072317.3169630-1-sumanthk@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 3d9mbPpTPABzcun9Q-w9vYzYUwpx0Bcp X-Proofpoint-GUID: 0DiWSAupzY9cHbCzU3NqtR37jHtZ8Ly8 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-20_04,2023-11-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 phishscore=0 adultscore=0 priorityscore=1501 lowpriorityscore=0 mlxlogscore=570 spamscore=0 clxscore=1015 suspectscore=0 mlxscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2311200046 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sun, 19 Nov 2023 23:23:58 -0800 (PST) In add_memory_resource(), creation of memory block devices occurs after successful call to arch_add_memory(). However, creation of memory block devices could fail. In that case, arch_remove_memory() is called to perform necessary cleanup. Currently with or without altmap support, arch_remove_memory() is always passed with altmap set to NULL during error handling. This leads to freeing of struct pages using free_pages(), eventhough the allocation might have been performed with altmap support via altmap_alloc_block_buf(). Fix the error handling by passing altmap in arch_remove_memory(). This ensures the following: * When altmap is disabled, deallocation of the struct pages array occurs via free_pages(). * When altmap is enabled, deallocation occurs via vmem_altmap_free(). Fixes: a08a2ae34613 ("mm,memory_hotplug: allocate memmap from the added memory range") Reviewed-by: Gerald Schaefer Signed-off-by: Sumanth Korikkar --- mm/memory_hotplug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index c8238fc5edcb..4f476a970e84 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1458,7 +1458,7 @@ int __ref add_memory_resource(int nid, struct resource *res, mhp_t mhp_flags) /* create memory block devices after memory was added */ ret = create_memory_block_devices(start, size, params.altmap, group); if (ret) { - arch_remove_memory(start, size, NULL); + arch_remove_memory(start, size, params.altmap); goto error_free; } -- 2.41.0