From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail.mainlining.org (mail.mainlining.org [5.75.144.95]) (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 8F42D3D8125 for ; Tue, 25 Aug 2026 20:58:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=5.75.144.95 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787691538; cv=none; b=N9o65JzeGnWc/WMM2+bLPYtwmYxpdwEMvN3wvsH1jKKuxgGdpWbhBXDSPL5Aoj+S1KsSG3csNVUmEDx5FnjJudMc/jdQJIZUHSZF3lu4xe98y7wojt0Vrd53bYr1nej1JvYlPme035wlBQt7DfdrRIi68BDJveUSSWSq2tcGd7I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787691538; c=relaxed/simple; bh=sX+K8VoUPQkmHeS97h8G6+QD9wmkzWqtLleWRh222vU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rpry7g2s7WhlU+/cAZlGybH0FMShyRYIDsQ+kRZaNG8rPf2zQdSxSyBgaalcv78PiU2CC0G4lv64VxHMeQp1Pfbd5gnMtRbT8GTIJlIIRuMfZS2B92e4NzJlrPN3i/gamY6uGyd8W60SfaZSI5o2YElffHzzBls0izGmopysoz8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=mainlining.org; spf=pass smtp.mailfrom=mainlining.org; dkim=pass (2048-bit key) header.d=mainlining.org header.i=@mainlining.org header.b=CcCNa3x5; dkim=permerror (0-bit key) header.d=mainlining.org header.i=@mainlining.org header.b=XCXO5TuF; arc=none smtp.client-ip=5.75.144.95 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=mainlining.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mainlining.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=mainlining.org header.i=@mainlining.org header.b="CcCNa3x5"; dkim=permerror (0-bit key) header.d=mainlining.org header.i=@mainlining.org header.b="XCXO5TuF" DKIM-Signature: v=1; a=rsa-sha256; s=202507r; d=mainlining.org; c=relaxed/relaxed; h=Message-ID:Date:Subject:To:From; t=1787691521; bh=tcjQYxJSDuzLIJWxbldwZuY iOSwnH8+4AZ5XCME/3vg=; b=CcCNa3x52RoI0/e0OH+7hcs4HFDJkoOwd9ESWola0c+lSe7Lf6 CnSwRptOswVUyIHK/C7TPc0qWfS8/iPkLDG8qnWZXY+x/QDHRrsZoziS53t1yQB6eFHjoHhntzf cmw1HIs9e/0h1g0o2hjQafUQiVvmkxNxkOJI/RSiw9nlf6wINziuKyr1EFj9F5XISYgZ3pjaVAr LPQR++QwnEVzKTrQmxYaUtgDnO8f8WBaiQ5TXt6JL/5VwvQtx85/RTeXzt/o2hagYsTAhh3J9Jn pygMXMcjCj8otGaOMGK3d7rhA62iUL+MtF1ucGdI+UchHyfFWP/mvY/vVGy7JaMtYVA==; DKIM-Signature: v=1; a=ed25519-sha256; s=202507e; d=mainlining.org; c=relaxed/relaxed; h=Message-ID:Date:Subject:To:From; t=1787691521; bh=tcjQYxJSDuzLIJWxbldwZuY iOSwnH8+4AZ5XCME/3vg=; b=XCXO5TuFHBpaNStAIMteueMkdMR+xerG/ycXx00bgQY8i7qniq ngEH7n9BEoM+tyPSwc3hPVM/CJqGVOEIflBQ==; From: Bradley Morgan To: Will Deacon Cc: Catalin Marinas , Mark Rutland , James Morse , Marc Zyngier , Ard Biesheuvel , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, brads@mainlining.org Subject: [PATCH 3/7] arm64: hibernate: free MTE tag pages after saving Date: Tue, 25 Aug 2026 20:58:35 +0000 Message-ID: <20260825205839.14571-4-brads@mainlining.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260825205839.14571-1-brads@mainlining.org> References: <20260825205839.14571-1-brads@mainlining.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit swsusp_arch_suspend() calls swsusp_mte_save_tags() to stash the userspace MTE tags, but we only free them on a successful resume in swsusp_mte_restore_tags(). If hibernation fails partway, the tags stay allocated, and the next time we try to hibernate, swsusp_mte_save_tags() warns about duplicate entries in the mte_pages xarray. Reproducing it is easy, just make a hibernate fail twice in a row. | # echo test_resume > /sys/power/disk | # echo disk > /sys/power/state ... | PM: Cannot find swap device, try swapon -a | PM: Cannot get swap writer ... | # echo disk > /sys/power/state ... | ------------[ cut here ]------------ | swsusp: save_tags: Duplicate entry | WARNING: CPU: 0 PID: 123 at arch/arm64/kernel/hibernate.c:234 \ | swsusp_arch_suspend+0x3f0/0x5b0 ... Free the tag storage right after swsusp_save() has copied it into the hibernation image. Where hibernation succeeds, the tags come back from the image and get consumed by swsusp_mte_restore_tags() as before. Fixes: ee11f332af96 ("arm64: mte: Save tags when hibernating") Signed-off-by: Bradley Morgan --- arch/arm64/kernel/hibernate.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arch/arm64/kernel/hibernate.c b/arch/arm64/kernel/hibernate.c index 7bf117427777..8ac29058a839 100644 --- a/arch/arm64/kernel/hibernate.c +++ b/arch/arm64/kernel/hibernate.c @@ -241,14 +241,18 @@ static int save_tags(struct page *page, unsigned long pfn) static void swsusp_mte_free_storage(void) { XA_STATE(xa_state, &mte_pages, 0); + int n = 0; void *tags; xa_lock(&mte_pages); xas_for_each(&xa_state, tags, ULONG_MAX) { mte_free_tag_storage(tags); + n++; } xa_unlock(&mte_pages); + pr_info("Freed %d MTE pages\n", n); + xa_destroy(&mte_pages); } @@ -355,6 +359,12 @@ int swsusp_arch_suspend(void) sleep_cpu = smp_processor_id(); ret = swsusp_save(); + + /* + * Hibernation can still fail from here, so free the tags now, + * a second attempt would warn on duplicate entries otherwise. + */ + swsusp_mte_free_storage(); } else { /* Clean kernel core startup/idle code to PoC*/ dcache_clean_inval_poc((unsigned long)__mmuoff_data_start, -- 2.47.3