From mboxrd@z Thu Jan 1 00:00:00 1970 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 lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 30885EB595E for ; Wed, 11 Feb 2026 03:40:54 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4f9kjc5wNfz2xlj; Wed, 11 Feb 2026 14:40:52 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip="2607:f8b0:4864:20::636" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1770781252; cv=none; b=Zwc4cWwhxx/LJGCkpAsDLZA98cAJsyuGz81V9tMySbBY7H4LD3mBZ8dTazYBCBYixz0jWvWoHD8tUYF0QGeNqqWis7pG7t2e5OC5xVZtkMY3BQO8VxFD2zdTCPyqNeylRSvBVe99GdhRfJm4Aeu/jUYmxFwpdanxZ9xJ7ANLKKHuGWIQPIVAVrxsMKuoF0XP4Rq37C5NMnvzmOnTvsERNOVJzHhJHzYfyiyTxfRayH8etgmcMlXdEB8Pew8nrJkRKCwOa8We6wiWqgsiSZ97rhcTjZft0OJe8Ks5/pLm//4BX2Ph46FC5UEBG+YRpn8+8wefmTwH0HgD7XnSFaVTBw== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1770781252; c=relaxed/relaxed; bh=B7DOpjMHcDmq5D3vVdYPupJ9INvt1gOBUArAP89WU/Y=; h=From:To:Cc:Subject:In-Reply-To:Date:Message-ID:References; b=Uah2F2EjNa1mroHolWKKjnOYVQNcxxkXziJINpdJtlO/acWUR+H5+L34r8GFZbHewfdSFNl4634gJL7K989bCpyselVoR1Hp6sNXgnjpnGyUjexUiLIXuJeQLoz6tQTvrWoO/+x6bTYDCEVpvszg2L/emcp5oBGqDSgIYKn90TO9U7KWp0/nlHqHzGkaXf2eLaEQH1kTCM1/gDhMFpFWSWEpv74hevHB0ZmQvpPyMPEA0FDhSP6nBBmPxtg6XqLXZyZMRvdTpPkCmSTLMdD6eduvJ6yD24+UzR38KfHe3Dq2wU6b2Fqc+TOO3i0EomoOo6+cOdScjX0rZLFUfKkzgQ== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=m91kbfvq; dkim-atps=neutral; spf=pass (client-ip=2607:f8b0:4864:20::636; helo=mail-pl1-x636.google.com; envelope-from=ritesh.list@gmail.com; receiver=lists.ozlabs.org) smtp.mailfrom=gmail.com Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=m91kbfvq; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::636; helo=mail-pl1-x636.google.com; envelope-from=ritesh.list@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4f9kjb2mHmz2xd6 for ; Wed, 11 Feb 2026 14:40:50 +1100 (AEDT) Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-2aaf91bbcd9so18362395ad.0 for ; Tue, 10 Feb 2026 19:40:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770781248; x=1771386048; darn=lists.ozlabs.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=m91kbfvqL9s9RhUbh84tXdqG4twJQa7MVIIEMdYwx28t0cfFwgoD3f/o3to+GCsf2S NsH1KKBHHzhviF0SawyjYSqMsEIG2SQBUvjRFk7izyz5Uy/LnOf1M8wIBnsKnXyatgeB 8ghoIbP2oytci800xPjUExg7JaMExQPGxXDdf2v18D7Ha0FK9me5vX8x2Ao2UIZMViVj diq35DLrjdbh9M3gCNC+jRS2E8+XS7tz1gcw5Svl86AWe64gf6pAVUlwLtgCKNeC5jX4 W5EaLArOt7kysxDb0mVM4AxBHP33WbiCQJmszFJQJNP/m6/lHxxAy/yPdxcUUGXhenGB pXsw== 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=FT5/blqKzMHMGStTxcxXNhW0Vx9h6ZYOnOQ47oyUuYcmXmXVSivMGWz2Hq1E80Vlsr OdMpcnzPp7Kkgjnkdqc8uzgntGCt5MmR6gw5lqKmVpKLEFm2++KHpbUtTGSOEZjE9foB OJhIgIKT31wUXz70pVSE8ILOnQlz9EZ8ElsCRi31FxRcrO8MigO0rXjUQGebN2fCJ5tZ BPkLkJkwrbNHidWYfraG1wWNWCQ/V4QlesNv1IaNQp1kILLG2Q8XTkPC98WG1p4LX/GB 0L1Z4vL+XHsKAqG2elOv0jpllQEUIp2YfXu1FzxQYUyW5QM7J6ppUIhuGq6WZUjxq8GE YZYA== X-Forwarded-Encrypted: i=1; AJvYcCW9ZgCX13di/hMCxXPhnuO/LwczHf0pjTIVjjE11Kmn7fgu2y33qnKKAQ8fLShr9icFw/ncndg5tsE3R6E=@lists.ozlabs.org X-Gm-Message-State: AOJu0YzxVvz+/3Udi6xZlyoqYvvcFqPiqx2NIGZr5gngvcVL3mJRMoka mCjVm3fXyOslXZxGa8MlydJvDVdg9qxg0SYQIRKCrImLsEC4oqb/05fB X-Gm-Gg: AZuq6aJ9DlX3pARVpkERlOXRBsHLRQvS25nNq3Fv4Cxl+aggxpyFW/4sY1bM1NsdMH9 C8otR0e9GW03Msjbp+2MDcawSeNt8e+TCiGDF4yLy0RHsg9pVzGHFpUTiVoH6XLAzMxp+L7Em3P iP3NxpUeuAHXxVd3dydI27L2Hw++6kLr6UhPEB5N55P0owxzZiz44iKGndYhNy9NBsPbFWrmeF8 DWt8C1SkfCPZPXidYtqXVRgUvyezkBMNzgIWojym7CQwpefDuvnVDdXsJ5RLKKAhZJOrqUBHMsu H5hgE7aT+6KwoB6ywFTAYPMsVeFqWa52tikJrzyrHB/OWx0DUbSdME+YJSn9haHe5JHzeku9NAb BwOd9+du+CD27IC5FLILohRQbqUSxfhU/344mQWeLdKJtdn9Wz3CyxUoToCzGymWq1FaoD/bR6V kcrw9En5JE2iPBMWA2x4tLdctEjn4= 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> X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Owner: List-Post: List-Archive: , List-Subscribe: , , List-Unsubscribe: Precedence: list 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