Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 8CBEB46A5E7; Tue, 21 Jul 2026 17:32:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784655136; cv=none; b=R0jgNGiEqTNd0a+oz01ejjlH5B21NPRzuhajDcFax8yutJbiVwbv68eEOik/0zUCOzWeg/Vh+CGVrsg/qBVOuy39ZkF+8+LpAtvlWIQycq4lUepz+HvS4plBCk0Fu4+15bwKexvBjdna0uCNXlFPpczdzPTBhDUYBXNXn8R8R4w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784655136; c=relaxed/simple; bh=uehivxClBHHIra7IviMgiCUGUIUs6A1qVt31RbJXwWQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nXDF9AphItIFgiN64AhtD0QRP4JF7Dsax0TIyecAuKuJG2+6rFV7K9uOlT+SautGTEzkqhkk+9yxkMg49Qp0CVWPH94QaX2JkQ25sqH5JJnDcrQrGAXnRjOF6EmCaGvRlLXITw89z9rWksK1tCZmAEfwgOr26hh5G/B5bIANVWQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=HupFwBDZ; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="HupFwBDZ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 890051F000E9; Tue, 21 Jul 2026 17:32:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784655135; bh=e4YXe2CpchS8nHh3oF6rarQYHZZPKePz2oJ1lMb0txc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=HupFwBDZdF3Ni27P/P9SwkbWFv5NV+y9bpxm+O8EEGLfP4ASfzkP3P1GiUvfJ2Ad6 cb+9OqQmfc1GeGHszwkTutkfilhfJHBmTmy0KXG4yKgBWQVhTqI2TaedHfzZu8tu0F rNUaDSAlJVMyIaSlc/G4fmgR5ivRJzKe++U99fII= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Zi Yan , "Vlastimil Babka (SUSE)" , Johannes Weiner , Baolin Wang , Lance Yang , Brendan Jackman , Jiaqi Yan , Michal Hocko , Suren Baghdasaryan , Andrew Morton Subject: [PATCH 7.1 1968/2077] mm/compaction: handle free_pages_prepare() properly in compaction_free() Date: Tue, 21 Jul 2026 17:27:21 +0200 Message-ID: <20260721152639.123758227@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260721152552.646164743@linuxfoundation.org> References: <20260721152552.646164743@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Zi Yan commit 7da7d599b8a83271c464adfd5ef160202b470570 upstream. free_pages_prepare() can fail but compaction_free() does not handle the failure case. Failed pages should not be added back to cc->freepages for future use, since they can be either PageHWPoison or free_page_is_bad() and might cause data corruption. Link: https://lore.kernel.org/20260622-handle_free_pages_prepare_in_compaction_free-v1-1-fcf3b14abcf7@nvidia.com Fixes: 733aea0b3a7b ("mm/compaction: add support for >0 order folio memory compaction.") Signed-off-by: Zi Yan Reviewed-by: Vlastimil Babka (SUSE) Acked-by: Johannes Weiner Reviewed-by: Baolin Wang Reviewed-by: Lance Yang Cc: Brendan Jackman Cc: Jiaqi Yan Cc: Michal Hocko Cc: Suren Baghdasaryan Cc: Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- mm/compaction.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) --- a/mm/compaction.c +++ b/mm/compaction.c @@ -1875,15 +1875,14 @@ static void compaction_free(struct folio int order = folio_order(dst); struct page *page = &dst->page; - if (folio_put_testzero(dst)) { - free_pages_prepare(page, order); + if (folio_put_testzero(dst) && free_pages_prepare(page, order)) { list_add(&dst->lru, &cc->freepages[order]); cc->nr_freepages += 1 << order; } cc->nr_migratepages += 1 << order; /* - * someone else has referenced the page, we cannot take it back to our - * free list. + * someone else has referenced the page or free_pages_prepare() fails, + * we cannot take it back to our free list. */ }