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 0CD08C07CB1 for ; Mon, 27 Nov 2023 16:31:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=fpeewjUMWZvWUhct7TsizZ+o90TJKq5pf5mRB3g+8aE=; b=WcDXYzwwd85zxZ VR62GmhJ1AaqZAqRLKO4V1EIFXZ8pV+ZvhcUEScm1NvbvnfAmLWt7BJX4IJEezMiTM9UIt/Gjka8G +YFlyruaLWNn2VAFf9k/N+sZAXI+na+JtvzH3KMNMD8RRidKY5jVwqRfOqXYPs9EhYE+euTQydaIl KgZwjqTgUZ6f9chmogKQZRE35OlOkyUBTAdVt0odiBNFIXiRfoQSI1cv8nfbBN0msaIqWgts+dS5I E6hM+d4oUsi8nGyoy0D/OoRnUuavk7pitCtwXDaZn1qh0t7VI+LH6drqWWN9l1xG+Me9AidrUVTlw /vs3wneMpbGzLkDo/hTA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r7eVu-002zgb-2f; Mon, 27 Nov 2023 16:31:14 +0000 Received: from sin.source.kernel.org ([145.40.73.55]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r7eVr-002zey-1F for linux-arm-kernel@lists.infradead.org; Mon, 27 Nov 2023 16:31:12 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 206CECE1396; Mon, 27 Nov 2023 16:31:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 224F2C433C8; Mon, 27 Nov 2023 16:31:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701102668; bh=jHbeOHocL//8r8fWrHPjwucrHi2T7RJCHEHgQFGs5z4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=AMV7QbmkfLKtCVI9cAW5z7OJgR/O1Io+HcxGkt9R17hT9q03MepA48/c5fzO+EssT sIyo73KF64DsroMofTvinD2CBA+MKmEH7MlqJdQBn3ROPBmeC9bUHp1uFp0hoqySxY EA/5DKLhb4/P2GvE/UCo6T1608wjT8VZB63yKhPaJ/rA2oVQgThb/gc11nzwpeYPgY ie5YuUZpamuEQe0LdbD1AixU+JHPFCKV7VY4q7vYq48W5Bo2PLF/eAfGDVt31n3Xom qXqRLV3ElmhdJnixSlb++wW0H7eD+vNL5wgfCUweQP+9fzLbZIMbmjEhSHJgcooxkX YFEC39Zr+FXcQ== Date: Mon, 27 Nov 2023 16:31:03 +0000 From: Will Deacon To: Ard Biesheuvel Cc: Ard Biesheuvel , linux-arm-kernel@lists.infradead.org, Catalin Marinas , Marc Zyngier , Mark Rutland Subject: Re: [PATCH v2 1/3] arm64: Avoid enabling KPTI unnecessarily Message-ID: <20231127163103.GA8627@willie-the-truck> References: <20231127120049.2258650-5-ardb@google.com> <20231127120049.2258650-6-ardb@google.com> <20231127154818.GA8453@willie-the-truck> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231127_083111_649075_9AC57A74 X-CRM114-Status: GOOD ( 26.42 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, Nov 27, 2023 at 04:52:11PM +0100, Ard Biesheuvel wrote: > On Mon, 27 Nov 2023 at 16:48, Will Deacon wrote: > > > > On Mon, Nov 27, 2023 at 01:00:51PM +0100, Ard Biesheuvel wrote: > > > From: Ard Biesheuvel > > > > > > Commit 42c5a3b04bf6 refactored the KPTI init code in a way that results > > > in the use of non-global kernel mappings even on systems that have no > > > need for it, and even when KPTI has been disabled explicitly via the > > > command line. > > > > > > Ensure that this only happens when we have decided (based on the > > > detected system-wide CPU features) that KPTI should be enabled. > > > > > > Fixes: 42c5a3b04bf6 ("arm64: Split kpti_install_ng_mappings()") > > > Signed-off-by: Ard Biesheuvel > > > --- > > > arch/arm64/kernel/cpufeature.c | 4 ++++ > > > 1 file changed, 4 insertions(+) > > > > > > diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c > > > index 646591c67e7a..91d2d6714969 100644 > > > --- a/arch/arm64/kernel/cpufeature.c > > > +++ b/arch/arm64/kernel/cpufeature.c > > > @@ -1839,6 +1839,10 @@ static int __init __kpti_install_ng_mappings(void *__unused) > > > > > > static void __init kpti_install_ng_mappings(void) > > > { > > > + /* Check whether KPTI is going to be used */ > > > + if (!cpus_have_cap(ARM64_UNMAP_KERNEL_AT_EL0)) > > > + return; > > > > Why can't you use arm64_kernel_unmapped_at_el0() here? > > > > Because it relies on alternatives patching, which hasn't occurred yet > at this point. Hmm. Keeping the determination of the capabilities separate from the alternatives patching feels like it's asking for trouble given how many of the boolean system_*() helpers in asm/cpufeature.h are using the alternative_has_cap*() code. Could we move the call to apply_alternatives_all() into setup_system_features() and then you could do the kpti stuff after that? I think sve_setup() and sme_setup() are ok, but I'd be more comfortable moving those later too, given how things like system_supports_sve() rely on the alternatives as well. Will _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel