Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp280985lqm; Tue, 30 Apr 2024 23:13:24 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU2sduEJKMVyMOXyqstVTR1iJiapWCWDHa9N8Zn9xXLciXPyDo9HXOkEKHjvPuurssXNFJnNPdAp3YUQfff3yEKox9brUjdSuphTpPeFQ== X-Google-Smtp-Source: AGHT+IFUrqVra71bzXnAo93GvEDw3LEh6vVr7Y/T4dqWZJXdt2MkiSSdDQtYNPWLtq1hZbyDpB/e X-Received: by 2002:a05:6a20:394b:b0:1a3:df1d:deba with SMTP id r11-20020a056a20394b00b001a3df1ddebamr1455276pzg.31.1714544004119; Tue, 30 Apr 2024 23:13:24 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714544004; cv=pass; d=google.com; s=arc-20160816; b=zj21BcdqAyR792fHLk30eMItyPRoUL7UR+kCc19Cqw+hmyGu5pXvdQnkI5zEqGreXh /AauyzApmdfTBzIIZJY7aLn/a5v0vYGtVuCXLnb28BFpjX5Z+5Hoa7Hy7nZZoz09fG1g AcLzshF8c4oa491Cm60J6b93jo30IodQTH1Drbbrv35WF/9tHSdvWswQZngSj/UoDBmg HwtFftad1OOVDAqnjsKU+bjkHynmUi1oZAynOZT+2shzyJRO77C1zk8Eh9IJKQQsBZbp WwNof/CxAF88wEWOF51J7oEPsDFAXpfKYEP9JGIESgi8JWRkhFl/BICvvUQVVOM5e8mf /EWg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=gwS+r/rdI4rV0rumRC/q7YG2Q+QFhBrZIl/mXrqt2Ss=; fh=udrSz9pWHKjFaK1ue0NQ/AReaCOROzs4rslcLE8Fy4w=; b=IDasjFwaD/um6YtQEFkZb9mXKqjKc4RIUQ0MyTtzXT67Xu70VW9qjNb5DAKvIDQozJ NP+D2te5khvtuxt1sH6V52cS6/LzyHrD4kdRM9Gcimwbc73XA+SOm9H4gPKSjF8TbVmm /joOMudaWOo2XwBA2e/Nz6yJXU/14xn8nIxIQa8rFD9CLKGyi8rc6b3Z8iGqmIistB3x vh5TgFvEhfaRrTKC8DvgmUuygrNnedrQBxIcrRGGgQJNuA/32GA30tUHUT2bG4GBeLOz 02dXTYTvq3fU4Gurh+0NHB+kmjA0C7n1UVABsPVXi/wxUd8SpUd2BUBawICv0r4A5fz8 hsPg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-164963-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-164963-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id j7-20020a170902758700b001e236f58ea1si22255866pll.204.2024.04.30.23.13.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 23:13:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-164963-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-164963-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-164963-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 1799DB21895 for ; Wed, 1 May 2024 06:13:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 11F1C4CB4E; Wed, 1 May 2024 06:13:11 +0000 (UTC) Received: from mail-pg1-f195.google.com (mail-pg1-f195.google.com [209.85.215.195]) (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 EAAFA4AEEA; Wed, 1 May 2024 06:13:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.195 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714543990; cv=none; b=tNbftATrAR+NZykznyCMbfcj0559Veb16MMRCHJTLp94pN0NwmkX1sn0skCQU++neavODiQIo+CiSycl9vVnMoWSm8cGGFW8XephJzg1ElOoYSy4sqIO5OBI9HMIncRcteDmfpPzfdcR++1qtHBdHYFs5BV1HPBAb0regFzZDcA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714543990; c=relaxed/simple; bh=/e9sY+SaMEqXblc2/CW6yINkIpZNGhoFfR3QI6K1TH0=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=GOId4Sr72ABMl28UnVPaz01DhChWPsQzNPo0m/Mo4Pkf4/2MaO+qaipbL/HvbDtyyo5YHg9bjOxRf8U+H2AUmhwkwuBetQvEMdK1A5MQw55tgF3d9g7jPQ44NVC0XSV7OzGntD7hyKNIXL/hZnlctFk1RgyrJuGwx9s33KBx06w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.215.195 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=gmail.com Received: by mail-pg1-f195.google.com with SMTP id 41be03b00d2f7-5cdbc4334edso3657519a12.3; Tue, 30 Apr 2024 23:13:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714543985; x=1715148785; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=gwS+r/rdI4rV0rumRC/q7YG2Q+QFhBrZIl/mXrqt2Ss=; b=H8nkA85Obcbr9wRBb/PX/C5dNE8YwX9HYL1zSFBmMKw+pVile3I1ohEPd2VHOTIukv Qn2rwltHKzI1LLOJMgxtw9giyVJZcYnu3F0SyhzDt3aYUuqRLfxDtT1XR/GEDQuUrBf9 ig5E8ePGIsQf2i8xA/rB8pqrX/ghpDTvrVjUPG42I9IX7aWgDElF1kwyUQHZFfFOhUGD xvzckmhykaLpRr7r1I9njt/uXPgurIzL3Iv+dMvOeQn9ywgBgvZDlzoIrzgxXfjvYDEF S6CD4k+ceagUYIqTXbx3q6FBWlB1TMsYT42zK7+30TItuqgDSf5ostYWblUG+w7roI85 Zp/Q== X-Forwarded-Encrypted: i=1; AJvYcCU+cxOvqf9YW0UgVACBT1N7bCU6aX3JsvPw/bglR/fOT66D3OhqPwL4Kq8tTrdBsAkMRphHT7cUU8WNGHxUyyefuZIpgARdZb7EA5WM X-Gm-Message-State: AOJu0Yxsf1FnKxvvxHlSi5R5hImODQsv4nGL/LZCRnO67ETllEGwPuIb gQMvUetFQ10W62Eb/48X1RcS2Ok1EtXE2I71BmQpa4Taj3Ttg3oL X-Received: by 2002:a05:6a20:2587:b0:1a7:919f:2b60 with SMTP id k7-20020a056a20258700b001a7919f2b60mr1632139pzd.37.1714543985092; Tue, 30 Apr 2024 23:13:05 -0700 (PDT) Received: from localhost.localdomain ([111.48.58.10]) by smtp.gmail.com with ESMTPSA id w17-20020a1709029a9100b001e2a4663179sm23448382plp.258.2024.04.30.23.13.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 23:13:04 -0700 (PDT) From: Xueqin Luo To: rafael@kernel.org, pavel@ucw.cz, len.brown@intel.com Cc: linux-pm@vger.kernel.org, xiongxin@kylinos.cn, linux-kernel@vger.kernel.org, Xueqin Luo Subject: [PATCH -next] PM: hibernate: add retry mechanism for S4 image loading failures Date: Wed, 1 May 2024 14:12:58 +0800 Message-Id: <20240501061258.2874092-1-luoxueqin@kylinos.cn> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit During the S4 resume process, there's a rare chance of image loading failure. We provide three retries to load it successfully. If the recovery fails after these attempts, print out the handle CRC32 value. When the CRC32 value obtained on each retry are inconsistent, there may be a memory anomaly. When the values are consistent, it might indicate corrupted swapped memory data. Signed-off-by: Xueqin Luo --- kernel/power/hibernate.c | 8 ++++++++ kernel/power/swap.c | 14 ++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c index 43b1a82e800c..d9bcf38221ef 100644 --- a/kernel/power/hibernate.c +++ b/kernel/power/hibernate.c @@ -703,6 +703,7 @@ static int load_image_and_restore(void) { int error; unsigned int flags; + int cnt = 0; pm_pr_dbg("Loading hibernation image.\n"); @@ -713,7 +714,14 @@ static int load_image_and_restore(void) goto Unlock; } +retry: error = swsusp_read(&flags); + if (error && (cnt++ < 3)) { + pr_err("Failed to load hibernation image, trying to load again...\n"); + swsusp_free(); + goto retry; + } + swsusp_close(); if (!error) error = hibernation_restore(flags & SF_PLATFORM_MODE); diff --git a/kernel/power/swap.c b/kernel/power/swap.c index 5bc04bfe2db1..4b866c645cd7 100644 --- a/kernel/power/swap.c +++ b/kernel/power/swap.c @@ -1489,15 +1489,17 @@ static int load_compressed_image(struct swap_map_handle *handle, ret = snapshot_write_finalize(snapshot); if (!ret && !snapshot_image_loaded(snapshot)) ret = -ENODATA; - if (!ret) { - if (swsusp_header->flags & SF_CRC32_MODE) { - if(handle->crc32 != swsusp_header->crc32) { - pr_err("Invalid image CRC32!\n"); - ret = -ENODATA; - } + } + if (!ret) { + if (swsusp_header->flags & SF_CRC32_MODE) { + if (handle->crc32 != swsusp_header->crc32) { + pr_err("Invalid image CRC32, swsusp header CRC32: %u, handle CRC32: %u\n", + swsusp_header->crc32, handle->crc32); + ret = -ENODATA; } } } + swsusp_show_speed(start, stop, nr_to_read, "Read"); out_clean: hib_finish_batch(&hb); -- 2.25.1