From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 00FA13446B2 for ; Wed, 11 Feb 2026 03:40:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770781251; cv=none; b=JGPspwE1QPtFszZks8BtxAhSjkOBvN/DvKYg7HC3EIhUbGWBQAE0n4P69p70iQKGsrZb0J7XOR5niLQJoCqbNpOajbJTY7kAwhjxZwliC8Q6KHsIA4y8sSw6cEfGdLUKOcvaUb838jFyWx9W6CEXdzKrYOCVvgZhoRhR6i3ZT7M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770781251; c=relaxed/simple; bh=oLVFs8UeTt1U989HxV+yHjJeDlE5/GWso0ukeJWwDII=; h=From:To:Cc:Subject:In-Reply-To:Date:Message-ID:References; b=aQDD0pgHVq7e4KjrFyXbfCLUpMScOqnP0e4uArysp/ZTTgNzfQKKupmKpuzJKW5WHToGWmV7RPlYWA6IIogCoyIn/qSv4sEaL7Hmwee2cT6MwejFmJFgwJFx1FKPvdaGY54QjQJp2WSwZlHa7Qm5xJNFlXNSuHbufPBhy5JjPpA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=buu3Aqy5; arc=none smtp.client-ip=209.85.214.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="buu3Aqy5" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-2aad1dc8856so24031615ad.1 for ; Tue, 10 Feb 2026 19:40:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770781248; x=1771386048; darn=vger.kernel.org; h=references:message-id:date:in-reply-to:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=B7DOpjMHcDmq5D3vVdYPupJ9INvt1gOBUArAP89WU/Y=; b=buu3Aqy5XEWo7zyqp3COl30WMd+Waq31LefJE8Os3kof6RkSh3e8CErXlGcY6TDLdm JODqaEOlafBpuiXQEvA5kABWSdHGYmMDa/GiMdjqzG2uhDwVIG11gpgzoKaoYwj2vGA5 7W6sdqjlWf3bPvBBjptOCa+E1aWTZxySPI3i4Q8Yez+3HTkifiodoabmf0axOtSzKYO4 bKb/aAhqhU1jnzqvHlkQDH0IKzsz0aovPqT6XeZA/v2RE1pkwVbJwK7coaTndv2KBnhv nzZwXN41HV1PR2Y3Eqzc0HkAo0aFK/yWytHuUzE1SubZ7auhS1zuTQR3SN+Hh23JobDm SR1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770781248; x=1771386048; h=references:message-id:date:in-reply-to:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=B7DOpjMHcDmq5D3vVdYPupJ9INvt1gOBUArAP89WU/Y=; b=D8I/ru4RSVp1oDmXLIU/13NSMip6lLRPWYZclnJYZNTMoaXVa7ikb7n3UVx2ivqWq1 f4Zb/iFVIqkw/e/5dFeHdDs8F2ou+IRF87Cjr1E3oDcnY3mRDJoT7h6wx4SOQWJRPVHt YVCh9d1LgkYXIvpx7ZomTVpOVAQawhahxHCdy0XQ5mS+7uLIEPecgrm/4cHT5d8x0qky N9Y7JSvGbVNa0azOuk1lrd8t2S5ATvAcfuH1GTAWBTKwvrWNbeF42aso6ZAmNkduYtRE Hr/Wq9dHMeVXfKBilazfgJhatFP5mnjdFyBghbYJ0dpBqqjSrf2B/Mfn+JhOIluwR7zF Nf+A== X-Forwarded-Encrypted: i=1; AJvYcCXpp40FnECBnaLzEhOQySRwhCBsFcHpS3tJapknh6KgQR9qqrTJNKbTyheIYfcYGpQzRJeBcUp4Z+Etoj0=@vger.kernel.org X-Gm-Message-State: AOJu0YwFC/fpKxNm6EeDykngV9BgKZ7Mfp0kOq7Mhe7nuaVKK9bOH4Df xBA52/5l9eDhCaGTF5SOk1QVaZMIp4AEkr7ATcN2beD0SmIkXyaMJxqOEI3bhuQ2 X-Gm-Gg: AZuq6aI7Rdx2ZPz6QxZ9/QKDQx4pnzH+CaElvemJaEiGXTrkUx1S3Tob7OPdNtHPrdh BBJgjN5Vwa8NFD7UQ1Jl65JkvZmHu26bQRla2JJjgo4/ZPSrdkDN3oB0Ynl09Ine55wR9fOz7Dc xIBHXAYICStOqzUDWTztZqUUO3KqqLydCUkV4u2hbrQn3epyyWiD3O/jDs74kNQYLZNpgiDuh/c 7JYscU1YDFJz+LQ2xebZ1nIMbZ9yBPTUrm0jmhzFf1QTW61DjcwKJ3ouokHB4lAt3Ea8CtV2QcO vpuJj46N1GmMdvsWVv9/PW09zLt8XRIONn9n9e8M6BdMYKMe18X0wCMLBMYUb2AiaB2legmXXI8 WkTRKwDjUDfmxTpyJ8xO2ZcOOhRe3pm3vEDSVp9neWe1SpEPQc1GpYV2mRiswaCajJVqVxkJSbe 9QHTVmcQIntR4AnTkLl8PBOvPAAWY= X-Received: by 2002:a17:903:298e:b0:2aa:e7f3:faf9 with SMTP id d9443c01a7336-2ab27f37d22mr13647925ad.31.1770781248440; Tue, 10 Feb 2026 19:40:48 -0800 (PST) Received: from dw-tp ([49.205.216.49]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8249e3bd3b2sm507040b3a.22.2026.02.10.19.40.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Feb 2026 19:40:47 -0800 (PST) From: Ritesh Harjani (IBM) To: Sourabh Jain , linuxppc-dev@lists.ozlabs.org Cc: Sourabh Jain , Andrew Morton , Baoquan he , Jinjie Ruan , Hari Bathini , Madhavan Srinivasan , Mahesh Salgaonkar , Michael Ellerman , Shivang Upadhyay , linux-kernel@vger.kernel.org Subject: Re: [PATCH] powerpc/crash: sort crash memory ranges before preparing elfcorehdr In-Reply-To: <20260210120803.433978-1-sourabhjain@linux.ibm.com> Date: Wed, 11 Feb 2026 09:05:20 +0530 Message-ID: <875x840x6v.ritesh.list@gmail.com> References: <20260210120803.433978-1-sourabhjain@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Sourabh Jain writes: > During a memory hot-remove event, the elfcorehdr is rebuilt to exclude > the removed memory. While updating the crash memory ranges for this > operation, the crash memory ranges array can become unsorted. This > happens because remove_mem_range() may split a memory range into two > parts and append the higher-address part as a separate range at the end > of the array. > > So far, no issues have been observed due to the unsorted crash memory > ranges. However, this could lead to problems once crash memory range > removal is handled by generic code, as introduced in the upcoming > patches in this series. Do you have the link of the discussion, to where you have pointed about, what sort of problems this unsorted memory ranges might bring up with the new patch series? > > Currently, powerpc uses a platform-specific function, > remove_mem_range(), to exclude hot-removed memory from the crash memory > ranges. This function performs the same task as the generic > crash_exclude_mem_range() in crash_core.c. The generic helper also > ensures that the crash memory ranges remain sorted. So remove the > redundant powerpc-specific implementation and instead call > crash_exclude_mem_range_guarded() (which internally calls > crash_exclude_mem_range()) to exclude the hot-removed memory ranges. > > Cc: Andrew Morton > Cc: Baoquan he > Cc: Jinjie Ruan > Cc: Hari Bathini > Cc: Madhavan Srinivasan > Cc: Mahesh Salgaonkar > Cc: Michael Ellerman > Cc: Ritesh Harjani (IBM) > Cc: Shivang Upadhyay > Cc: linux-kernel@vger.kernel.org > Signed-off-by: Sourabh Jain > --- > > Requesting this patch to part of the below patch series. > https://lore.kernel.org/all/20260209095931.2813152-1-ruanjinjie@huawei.com/ > > --- > arch/powerpc/include/asm/kexec_ranges.h | 4 +- > arch/powerpc/kexec/crash.c | 5 +- > arch/powerpc/kexec/ranges.c | 87 +------------------------ > 3 files changed, 7 insertions(+), 89 deletions(-) > > diff --git a/arch/powerpc/include/asm/kexec_ranges.h b/arch/powerpc/include/asm/kexec_ranges.h > index 14055896cbcb..ad95e3792d10 100644 > --- a/arch/powerpc/include/asm/kexec_ranges.h > +++ b/arch/powerpc/include/asm/kexec_ranges.h > @@ -7,7 +7,9 @@ > void sort_memory_ranges(struct crash_mem *mrngs, bool merge); > struct crash_mem *realloc_mem_ranges(struct crash_mem **mem_ranges); > int add_mem_range(struct crash_mem **mem_ranges, u64 base, u64 size); > -int remove_mem_range(struct crash_mem **mem_ranges, u64 base, u64 size); > +int crash_exclude_mem_range_guarded(struct crash_mem **mem_ranges, > + unsigned long long mstart, > + unsigned long long mend); > int get_exclude_memory_ranges(struct crash_mem **mem_ranges); > int get_reserved_memory_ranges(struct crash_mem **mem_ranges); > int get_crash_memory_ranges(struct crash_mem **mem_ranges); > diff --git a/arch/powerpc/kexec/crash.c b/arch/powerpc/kexec/crash.c > index a325c1c02f96..31462e8415ff 100644 > --- a/arch/powerpc/kexec/crash.c > +++ b/arch/powerpc/kexec/crash.c > @@ -431,7 +431,7 @@ static void update_crash_elfcorehdr(struct kimage *image, struct memory_notify * > struct crash_mem *cmem = NULL; > struct kexec_segment *ksegment; > void *ptr, *mem, *elfbuf = NULL; > - unsigned long elfsz, memsz, base_addr, size; > + unsigned long elfsz, memsz, base_addr, size, end; > > ksegment = &image->segment[image->elfcorehdr_index]; > mem = (void *) ksegment->mem; > @@ -450,7 +450,8 @@ static void update_crash_elfcorehdr(struct kimage *image, struct memory_notify * > if (image->hp_action == KEXEC_CRASH_HP_REMOVE_MEMORY) { > base_addr = PFN_PHYS(mn->start_pfn); > size = mn->nr_pages * PAGE_SIZE; > - ret = remove_mem_range(&cmem, base_addr, size); > + end = base_addr - size - 1; end should be "base_addr + size - 1", isn't it? > + ret = crash_exclude_mem_range_guarded(&cmem, base_addr, end); > if (ret) { > pr_err("Failed to remove hot-unplugged memory from crash memory ranges\n"); > goto out; -ritesh