From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2AB96606A335 for ; Mon, 30 Nov 2026 15:56:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=S7ldZUXQ; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=foss header.b=vTThuuW+ 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: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=2bRjjE9tj5dEBWghh0hdNJrNaohSkE9UaltxR++FLcI=; b=S7ldZUXQKonRyV x0JQrlE33StHqOrR3ciLCmw6ZjByMAAayn3fTTvvmL32kh54VzxVqQjQ+Qpux9ftM7wbYePAgoTlJ AezEDpyvzPNU2DBPuNgcE5L2bluDRji0OINZImluq0h1KIngzKjW60QU80EyUVHbrD8ETwdHtdA0Z 47MfXZpuM6z8k4sSziwz1q7q+BTo6g80WwwJbdC8HJHiXK5guleXQxh5wdz2cR4HaegcopvyWsylt zj9q3PUOWornUQIfY6DQhz7AZ1zcMZOU6B1YHJqiRdMy4UnOZ2h6YLcMkmeOEXC3z3Cf/db/z4c2d 9mu9BoOPX7euDjF73Lqw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xY3jQ-0000000563s-1OJq; Mon, 30 Nov 2026 15:55:56 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xY3jH-0000000561C-3K7s for linux-arm-kernel@lists.infradead.org; Mon, 30 Nov 2026 15:55:48 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 224F2169C; Mon, 30 Nov 2026 07:55:44 -0800 (PST) Received: from login2.euhpc2.arm.com (login2.euhpc2.arm.com [10.58.100.22]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 6BA823F86F; Mon, 30 Nov 2026 07:55:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1796054146; bh=Fql2t5vk0IyM8DAibVJrG8H+bSxBMjidPf+cBllKw8E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vTThuuW+S2y+x8ahv7wwZ+OM/whsICCeFg/6/VZxBgCV+PqZNvikD3Rz3NZEcz5Lu Tz2A8U3BPUYUEZw1ATADrec7UorOqC0V1mHTzkft7eaMtgaC5gIYgLXXNNCQfiGc6Y 2EfFtiLO6a6sCg0Hw6+GW7wJL8Cp14n3mgqV4iek= From: Vladimir Murzin To: linux-arm-kernel@lists.infradead.org Cc: catalin.marinas@arm.com, will@kernel.org, mark.rutland@arm.com, lpieralisi@kernel.org, ruanjinjie@huawei.com, liaochang1@huawei.com, ashok.raj@oss.qualcomm.com, maz@kernel.org, kas@kernel.org Subject: [PATCH v3 03/44] arm64: Clarify initial unmasking of DAIF bits Date: Mon, 30 Nov 2026 15:54:25 +0000 Message-Id: <20261130155506.118408-4-vladimir.murzin@arm.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20261130155506.118408-1-vladimir.murzin@arm.com> References: <20261130155506.118408-1-vladimir.murzin@arm.com> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261130_075547_879244_EBEC2201 X-CRM114-Status: GOOD ( 14.20 ) X-Spam-Score: -4.4 (----) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-18.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 The exception masking state is built differently for the boot and secondary CPUs. For the boot CPU, the exception masking state is built step by step: * Start with DAIF masked * Unmask DA in setup_arch() * Later, in smp_prepare_boot_cpu(), once the relevant boot CPU features are discovered, update PMR if pseudo-NMI is supported * Finally, in init_IRQ(), re-synchronize the state, allowing pseudo-NMIs (again, if supported) For secondary CPUs: * Start with DAIF masked * secondary_start_kernel() updates PMR if supported and unmasks DAIF Both flows use the same local_daif_restore() helper to manipulate the exception masking state. However, although there is no functional issue, local_daif_restore() behaves differently depending on the context in which it is invoked: part of its functionality depends on CPU feature discovery. On the boot CPU, the relevant CPU features are discovered in smp_prepare_boot_cpu() at the earliest, which means that a call to local_daif_restore() prior to that, say in setup_arch(), cannot do anything other than update DAIF. Although we end up with the desired effect, this can still be confusing. Clarify the initial unmasking of DAIF bits by: * Replacing local_daif_restore() with a direct write to DAIF * Updating the accompanying comment to explain that the exception masking state is built step by step for the boot CPU Signed-off-by: Vladimir Murzin --- arch/arm64/kernel/setup.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c index a707deba6ae7..56c40575b39b 100644 --- a/arch/arm64/kernel/setup.c +++ b/arch/arm64/kernel/setup.c @@ -308,10 +308,14 @@ void __init __no_sanitize_address setup_arch(char **cmdline_p) * threads, and we want to unmask SError as soon as possible after * initializing earlycon so that we can report any SErrors immediately. * - * IRQ and FIQ will be unmasked after the root irqchip has been - * detected and initialized. + * Note, that exception state can depend on supported CPU features, yet + * those are discovered later on during primary CPU boot. + * + * IRQ and FIQ (and any form of supported NMI) will be unmasked after + * the root irqchip has been detected and initialized. */ - local_daif_restore(DAIF_PROCCTX_NOIRQ); + write_sysreg(DAIF_PROCCTX_NOIRQ, daif); + trace_hardirqs_off(); /* * TTBR0 is only used for the identity mapping at this stage. Make it -- 2.34.1