From nobody Wed Sep 30 13:56:24 2026 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6ED0D463B7B for ; Fri, 7 Aug 2026 07:51:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786089110; cv=none; b=DTMZwmB200x0RjKxM/6GQdTxtJygTjzXq5ahlxml+QTban63brAROXGUP8rYYcQPbXUQ3LPPpCpZ9Wa+T6OSmUruavcTZ3qoJ+vWBSkxHxzKSPQ/NPJslapHbSIZPLHHpGEwlCc0lQwtDCtaIutYNFwHLP+aFMKxrVPjHnGiCao= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786089110; c=relaxed/simple; bh=N41xzeo4mhNZ2GwIRLZOEY2DVKynFNPGr8wVO0bOQpg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=tpsfDg8cJrppMTGFjDSlWsOtFpJ6N90lYA1LcfdUX1djQGnB9rwQODhFyn9kS7MbnFZMb7PTKvLxbd74d9Zekzvo9Br8HsRLPCPhyRIEwDyBBr0Vo20epraef4O1tizVMm1dz3rtJTqz6ACy6x1yPVbiljPp/jhU2yRS0Jt1DmY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: d0243634923411f1aa26b74ffac11d73-20260807 X-CTIC-Tags: HR_CC_COUNT, HR_CC_DOMAIN_COUNT, HR_CC_NO_NAME, HR_CTE_8B, HR_CTT_MISS HR_DATE_H, HR_DATE_WKD, HR_DATE_ZONE, HR_FROM_NAME, HR_SJ_DIGIT_LEN HR_SJ_LANG, HR_SJ_LEN, HR_SJ_LETTER, HR_SJ_NOR_SYM, HR_SJ_PHRASE HR_SJ_PHRASE_LEN, HR_SJ_WS, HR_TO_COUNT, HR_TO_DOMAIN_COUNT, HR_TO_NO_NAME IP_UNTRUSTED, SRC_UNTRUSTED, IP_UNFAMILIAR, SRC_UNFAMILIAR, DN_TRUSTED SRC_TRUSTED, SA_TRUSTED, SA_EXISTED, SN_EXISTED, SPF_NOPASS DKIM_NOPASS, DMARC_NOPASS, CIE_BAD, CIE_GOOD, CIE_GOOD_SPF GTI_FG_BS, GTI_RG_INFO, GTI_C_BU, AMN_GOOD, ABX_MISS_RDNS X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.12,REQID:9248a66f-0245-4dce-a9c1-9cc137809a2c,IP:10, URL:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION :release,TS:10 X-CID-INFO: VERSION:1.3.12,REQID:9248a66f-0245-4dce-a9c1-9cc137809a2c,IP:10,UR L:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION:r elease,TS:10 X-CID-META: VersionHash:e7bac3a,CLOUDID:796fb985dc2c6de23780a711ccd274f9,BulkI D:2608071551394GP681FK,BulkQuantity:0,Recheck:0,SF:10|38|66|78|81|82|102|1 27|850|865|898,TC:nil,Content:0|15|50,EDM:-3,IP:-2,URL:0,File:nil,RT:nil,B ulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR :0,BRE:0,ARC:0 X-CID-BVR: 2,SSN|SDN X-CID-BAS: 2,SSN|SDN,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-CID-RHF: D41D8CD98F00B204E9800998ECF8427E X-UUID: d0243634923411f1aa26b74ffac11d73-20260807 X-User: duanchenghao@kylinos.cn Received: from localhost.localdomain [(223.104.44.99)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA) with ESMTP id 1127736449; Fri, 07 Aug 2026 15:51:35 +0800 From: Chenghao Duan To: pasha.tatashin@soleen.com, rppt@kernel.org, pratyush@kernel.org, graf@amazon.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, kexec@lists.infradead.org Cc: jianghaoran@kylinos.cn, duanchenghao@kylinos.cn Subject: [PATCH v1 1/2] kho: remove useless phys increment in inner loop Date: Fri, 7 Aug 2026 15:51:27 +0800 Message-Id: <20260807075128.542806-2-duanchenghao@kylinos.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20260807075128.542806-1-duanchenghao@kylinos.cn> References: <20260807075128.542806-1-duanchenghao@kylinos.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The statement phys +=3D contig_pages * PAGE_SIZE at the end of the inner for-loop in kho_restore_vmalloc() is redundant code. The variable 'phys' is local to each loop iteration (re-assigned from chunk->phys[i] on every iteration) and is never referenced after this increment, so the statement has no functional impact. Remove it to avoid confusion during code review. Signed-off-by: Chenghao Duan Reviewed-by: Pratyush Yadav --- kernel/liveupdate/kexec_handover.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_h= andover.c index 175c08a6e41e..ba03ff5baa9e 100644 --- a/kernel/liveupdate/kexec_handover.c +++ b/kernel/liveupdate/kexec_handover.c @@ -1191,8 +1191,6 @@ void *kho_restore_vmalloc(const struct kho_vmalloc *p= reservation) =20 for (int j =3D 0; j < contig_pages; j++) pages[idx++] =3D page + j; - - phys +=3D contig_pages * PAGE_SIZE; } =20 page =3D kho_restore_pages(virt_to_phys(chunk), 1); --=20 2.25.1 From nobody Wed Sep 30 13:56:24 2026 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9E7A0332EC8 for ; Fri, 7 Aug 2026 07:51:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786089107; cv=none; b=DiT1LXVfDzShFG07h+bFURIdmlQoCxMc+c2LVmJiT2UDr3uhPc2mHKjriyK8Jcrv9na27sTb1TAzmrwVloxrN5OWeew1U1VBRQb+fK1v9SSt1d+NSbPT2GpFjWL89tkieTmFMAoNeBfKwYLVXa5wretZQOfRq/1muiRBusWfnjc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786089107; c=relaxed/simple; bh=CWsB4h38FaKPREDee1EPOLXJ86ity2SyI/cQbqCED5I=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=htLMEJAh5sJ/PSpXcpQUppi9/JWLB4foM1QWQAnstmpbdKzTmfzoLBOyOXvkc0XGbLuKo2ksC4luj5hqJ5LkKRBLlnXY5GJ4XJdK6Yf5aOD++W5RUB0VfyczMQD0EPpyFYoGo42BbrmqkP2affQm3s91Gp9eAw/WdabajXt/BkQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: d0fce1aa923411f1aa26b74ffac11d73-20260807 X-CTIC-Tags: HR_CC_COUNT, HR_CC_DOMAIN_COUNT, HR_CC_NO_NAME, HR_CTE_8B, HR_CTT_MISS HR_DATE_H, HR_DATE_WKD, HR_DATE_ZONE, HR_FROM_NAME, HR_SJ_DIGIT_LEN HR_SJ_LANG, HR_SJ_LEN, HR_SJ_LETTER, HR_SJ_NOR_SYM, HR_SJ_PHRASE HR_SJ_PHRASE_LEN, HR_SJ_WS, HR_TO_COUNT, HR_TO_DOMAIN_COUNT, HR_TO_NO_NAME IP_UNTRUSTED, SRC_UNTRUSTED, IP_UNFAMILIAR, SRC_UNFAMILIAR, DN_TRUSTED SRC_TRUSTED, SA_TRUSTED, SA_EXISTED, SN_EXISTED, SPF_NOPASS DKIM_NOPASS, DMARC_NOPASS, CIE_BAD, CIE_GOOD, CIE_GOOD_SPF GTI_FG_BS, GTI_RG_INFO, GTI_C_BU, AMN_GOOD, ABX_MISS_RDNS X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.12,REQID:9cbef195-252b-4aa5-8b05-af006c4c3798,IP:10, URL:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION :release,TS:10 X-CID-INFO: VERSION:1.3.12,REQID:9cbef195-252b-4aa5-8b05-af006c4c3798,IP:10,UR L:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION:r elease,TS:10 X-CID-META: VersionHash:e7bac3a,CLOUDID:c8296ac799a20adaa64dd19fac0165fc,BulkI D:260807155139A72UEW7B,BulkQuantity:0,Recheck:0,SF:10|38|66|78|81|82|102|1 27|136|850|865|898,TC:nil,Content:0|15|50,EDM:-3|-100,IP:-2,URL:0,File:nil ,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0, DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 2,SSN|SDN X-CID-BAS: 2,SSN|SDN,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-CID-RHF: D41D8CD98F00B204E9800998ECF8427E X-UUID: d0fce1aa923411f1aa26b74ffac11d73-20260807 X-User: duanchenghao@kylinos.cn Received: from localhost.localdomain [(223.104.44.99)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA) with ESMTP id 303652395; Fri, 07 Aug 2026 15:51:36 +0800 From: Chenghao Duan To: pasha.tatashin@soleen.com, rppt@kernel.org, pratyush@kernel.org, graf@amazon.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, kexec@lists.infradead.org Cc: jianghaoran@kylinos.cn, duanchenghao@kylinos.cn Subject: [PATCH v1 2/2] kho: unwind restored pages on kho_restore_vmalloc error Date: Fri, 7 Aug 2026 15:51:28 +0800 Message-Id: <20260807075128.542806-3-duanchenghao@kylinos.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20260807075128.542806-1-duanchenghao@kylinos.cn> References: <20260807075128.542806-1-duanchenghao@kylinos.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In kho_restore_vmalloc(), when kho_restore_pages() succeeds, the recovered pages are handed to the buddy allocator (via adjust_managed_page_count()). If any later step (e.g. __get_vm_area_node() or vmap_pages_range()) fails, the original error path only called kvfree(pages), leaking those folio pages. Fix by tracking how many folio groups have been restored with restored_idx. On any failure, use err_unwind_restored to walk restored_idx backwards and return each folio group to the buddy via __free_pages() before freeing the pages array. Signed-off-by: Chenghao Duan --- kernel/liveupdate/kexec_handover.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_h= andover.c index ba03ff5baa9e..ed35405f59ab 100644 --- a/kernel/liveupdate/kexec_handover.c +++ b/kernel/liveupdate/kexec_handover.c @@ -1161,6 +1161,7 @@ void *kho_restore_vmalloc(const struct kho_vmalloc *p= reservation) struct vm_struct *area; struct page **pages; unsigned int idx =3D 0; + unsigned int restored_idx =3D 0; int err; =20 vm_flags =3D kho_flags_to_vmalloc(preservation->flags); @@ -1183,11 +1184,11 @@ void *kho_restore_vmalloc(const struct kho_vmalloc = *preservation) phys_addr_t phys =3D chunk->phys[i]; =20 if (idx + contig_pages > total_pages) - goto err_free_pages_array; + goto err_unwind_restored; =20 page =3D kho_restore_pages(phys, contig_pages); if (!page) - goto err_free_pages_array; + goto err_unwind_restored; =20 for (int j =3D 0; j < contig_pages; j++) pages[idx++] =3D page + j; @@ -1195,13 +1196,14 @@ void *kho_restore_vmalloc(const struct kho_vmalloc = *preservation) =20 page =3D kho_restore_pages(virt_to_phys(chunk), 1); if (!page) - goto err_free_pages_array; + goto err_unwind_restored; + restored_idx =3D idx; chunk =3D KHOSER_LOAD_PTR(chunk->hdr.next); __free_page(page); } =20 if (idx !=3D total_pages) - goto err_free_pages_array; + goto err_unwind_restored; =20 area =3D __get_vm_area_node(total_pages * PAGE_SIZE, align, shift, vm_flags | VM_UNINITIALIZED, @@ -1209,7 +1211,7 @@ void *kho_restore_vmalloc(const struct kho_vmalloc *p= reservation) NUMA_NO_NODE, GFP_KERNEL, __builtin_return_address(0)); if (!area) - goto err_free_pages_array; + goto err_unwind_restored; =20 addr =3D (unsigned long)area->addr; size =3D get_vm_area_size(area); @@ -1231,7 +1233,16 @@ void *kho_restore_vmalloc(const struct kho_vmalloc *= preservation) =20 err_free_vm_area: free_vm_area(area); -err_free_pages_array: +err_unwind_restored: + /* + * Pages already restored via kho_restore_pages() have been given to + * the buddy allocator (via adjust_managed_page_count()). Return them + * to the buddy so that failure leaves the system in a clean state. + */ + while (restored_idx > 0) { + restored_idx -=3D contig_pages; + __free_pages(pages[restored_idx], order); + } kvfree(pages); return NULL; } --=20 2.25.1