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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 3049FC43458 for ; Fri, 10 Jul 2026 03:41:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:In-Reply-To:From:References:CC:To:Subject:MIME-Version:Date: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=iTljOFKYJBI33ZEI0JX671u45JXFShPIM4aeNDpDwv0=; b=ImtV864qjenTQPrrLpB2biOST7 aLLtyZsu+U8HDbTqRe/ci9ZKtthbSJ3Ltxb5rgXczQwLxqxTUGdM2OGDYrn6WsxP3vaIovc9ZTMSQ fgcHnU3DeGPAuGvPzTs6n2qFw0O+tQuU6C4aC7nLv2OteH4bn5RTpbXgqY2Xn5TzkXXO7G+Kn4K3c s5bBpIRNfqbMl7F8YujoB04ivCMob5Kg/FGe9wSWj3Mt3GPHynZFVtdmjJynO7No0EGuHejjnI/o/ BlAIJVwDGCCR1mZBQvsXwX8IyTa/82/pL41kW6ljEwZURjz1mK/yroceLYd0nmokej7qXSFRR8OeU O5V5CbYg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wi26q-000000043FX-2aer; Fri, 10 Jul 2026 03:41:04 +0000 Received: from canpmsgout04.his.huawei.com ([113.46.200.219]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wi26m-000000043El-2BFv for linux-arm-kernel@lists.infradead.org; Fri, 10 Jul 2026 03:41:03 +0000 dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=iTljOFKYJBI33ZEI0JX671u45JXFShPIM4aeNDpDwv0=; b=glSw8Dx9Mzy1CL32Fk+FBH40Il6zPAuD1Q137P883L3KsqBedtUB5HPKpNDKcuua5jfShM1jF Ncgz0lq6wkOMr2Ez7I/Mgtx0Q6ZrVMvw47Hh/GkzSvfcmTHTHMM+wW2xeKuBzUrO/8lBvYVhEkX BvFMKYabhqI25nUDMEp6TI4= Received: from mail.maildlp.com (unknown [172.19.163.0]) by canpmsgout04.his.huawei.com (SkyGuard) with ESMTPS id 4gxHRx09Gpz1prKZ; Fri, 10 Jul 2026 11:31:25 +0800 (CST) Received: from dggemv705-chm.china.huawei.com (unknown [10.3.19.32]) by mail.maildlp.com (Postfix) with ESMTPS id 2532340537; Fri, 10 Jul 2026 11:40:42 +0800 (CST) Received: from kwepemq200011.china.huawei.com (7.202.195.155) by dggemv705-chm.china.huawei.com (10.3.19.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 10 Jul 2026 11:40:41 +0800 Received: from [10.67.110.108] (10.67.110.108) by kwepemq200011.china.huawei.com (7.202.195.155) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 10 Jul 2026 11:40:41 +0800 Message-ID: <2410686c-bc58-44a0-9f71-ec79791daaa6@huawei.com> Date: Fri, 10 Jul 2026 11:40:40 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH 03/36] arm64: hibernate: mask DAIF before restoring hibernated kernel To: Vladimir Murzin , CC: , , , , , References: <20260709121333.23507-1-vladimir.murzin@arm.com> <20260709121333.23507-4-vladimir.murzin@arm.com> From: "Liao, Chang" In-Reply-To: <20260709121333.23507-4-vladimir.murzin@arm.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.67.110.108] X-ClientProxiedBy: kwepems500001.china.huawei.com (7.221.188.70) To kwepemq200011.china.huawei.com (7.202.195.155) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260709_204101_172397_41369C23 X-CRM114-Status: GOOD ( 24.04 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 在 2026/7/9 20:13, Vladimir Murzin 写道: > From: Ada Couprie Diaz > > The arm64 hibernate code manages the exception masking in an unsound > way, leading to potential crashes and/or warnings during resume. > > When a hibernation image is saved in `swsusp_arch_suspend()`, all DAIF > exceptions are masked (by virtue of `local_daif_save()`), and the > suspended image is saved assuming that all DAIF exceptions will remain > masked when the image is restored. > > When a hibernation image is resumed by `swsusp_arch_resume()`, only > interrupts are masked (by virtue of `local_irq_save()` in > `resume_target_kernel()`). When pseudo-NMI is enabled the DAIF.IF bits > will be clear, and regardless of pseudo-NMI the DAIF.DA bits will be > clear. > > This means that there are two problems: > > (1) It is possible to take Debug, SError, or pseudo-NMI exceptions > during the resume process. This is unsafe, as during the resume > process both the old ane new kernels will tranisently be in an > inconsistent state, and swsusp_arch_suspend_exit() won't retain > an executable mapping of any exception vectors. > > Any exception taken here will be fatal and silent. > > (2) When re-entering the resumed kernel, some DAIF bits will be clear > unexpectedly. This permits Debug, SError, or pseudo-NMI exceptions > to be taken for a short period while the resumed kernel is not yet > in a consistent state. > > This is detected by CONFIG_ARM64_DEBUG_PRIORITY_MASKING. > > Avoid these issues by masking all DAIF exceptions during resume. > > Cc: stable@vger.kernel.org > Signed-off-by: Ada Couprie Diaz > Signed-off-by: Vladimir Murzin > --- > arch/arm64/kernel/hibernate.c | 13 +++++++++++++ > 1 file changed, 13 insertions(+) > > diff --git a/arch/arm64/kernel/hibernate.c b/arch/arm64/kernel/hibernate.c > index 9717568518ba..d0d9bd91e639 100644 > --- a/arch/arm64/kernel/hibernate.c > +++ b/arch/arm64/kernel/hibernate.c > @@ -405,6 +405,7 @@ int swsusp_arch_suspend(void) > int __nocfi swsusp_arch_resume(void) > { > int rc; > + unsigned long flags; > void *zero_page; > size_t exit_size; > pgd_t *tmp_pg_dir; > @@ -465,9 +466,21 @@ int __nocfi swsusp_arch_resume(void) > if (el2_reset_needed()) > __hyp_set_vectors(el2_vectors); > > + /* > + * It is necessary to mask all DAIF exceptions here as: > + * > + * - The copy of swsusp_arch_suspend_exit() in the hibernation > + * text cannot handle taking any exceptions. > + * > + * - The suspended kernel masked all DAIF exceptions in > + * swsusp_arch_resume(), and expects to be re-entered in the > + * same state : with all DAIF exceptions masked. > + */ > + flags = local_daif_save(); > hibernate_exit(virt_to_phys(tmp_pg_dir), resume_hdr.ttbr1_el1, > resume_hdr.reenter_kernel, restore_pblist, > resume_hdr.__hyp_stub_vectors, virt_to_phys(zero_page)); > + local_daif_restore(flags); As Jinjie said, the resumed kernel never return from hibernate_exit(). If that's the case, it seems better to place unreachable() rather than local_daif_restore(), would you agree? > > return 0; > } -- BR Liao, Chang