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 B3052ECAAD5 for ; Mon, 12 Sep 2022 16:24:08 +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:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=8UjSSXbr/Eon2OPS0eE//v24aDIlpCAhdvqgbcfILFA=; b=wMCNe6BjAOj/X9 q9tOOZayDChNy4x0k/uRnXs7nMoxUYZ1A3vD0OEU1C2LSCsHguCS51ZCCqdW3/Y1dh5Ug69Rl8NhG u86UwdZQQa/xD6TREVa3K5boRIgAC6NV7fKFX61rBgUOeC4BnFKXGsKiNKYTHA01c47xGORDelVeD Zr7Aiu3MyliuCF7BjApqf4gUJjeQjCXSrIMBYhQDRziA47ZW8SQo+1FOWAYU/rTu6tDIIEBDk6c1u vPMIOaEW1HZ1NOUwtJkNeiCLymbKItw5adAQOKKISIutw3ZRkNV3pRWc6czH0juOe2V4JJZclJwrC sr+Qurbe1j/IEiDyWkbw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oXmCv-00BYXC-RF; Mon, 12 Sep 2022 16:22:49 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oXmCV-00BYDk-41 for linux-arm-kernel@lists.infradead.org; Mon, 12 Sep 2022 16:22:25 +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 C8FB3106F; Mon, 12 Sep 2022 09:22:25 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 541993F73D; Mon, 12 Sep 2022 09:22:18 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, Catalin Marinas Cc: ardb@kernel.org, james.morse@arm.com, joey.gouly@arm.com, mark.rutland@arm.com, maz@kernel.org, will@kernel.org Subject: [PATCH v2 0/8] arm64: alternatives: improvements Date: Mon, 12 Sep 2022 17:22:02 +0100 Message-Id: <20220912162210.3626215-1-mark.rutland@arm.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220912_092223_345401_053CC378 X-CRM114-Status: GOOD ( 15.21 ) 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 This series reworks the arm64 alternatives code. The major aim is to make the patching code more consistent and robust, and as a benefit we can also make the kernel Image smaller. Largely, the series makes two structural changes: 1) Replacing cpucap static branches with equivalent alternatives. This helps with a number of existing pain points: * Each static branch has metadata in the __jump_table section, which is not discarded after features are finalized. This wastes some space, and slows down the patching of other static branches. * The static branches are patched at a different point in time from the alternatives, so changes are not atomic. This leaves a transient period where there could be a mismatch between the behaviour of alternatives and static branches, which could be problematic for some features (e.g. pseudo-NMI). * More (instrumentable) kernel code is executed to patch each static branch, which can be risky when patching certain features (e.g. irqflags management for pseudo-NMI). * When CONFIG_JUMP_LABEL=n, static branches are turned into a load of a flag and a conditional branch. This means it isn't safe to use such static branches in an alternative address space (e.g. the NVHE/PKVM hyp code), where the generated address isn't safe to acccess. Note that all supported toolchains have asm goto support, and since commit: a0a12c3ed057af57 ("asm goto: eradicate CC_HAS_ASM_GOTO)" ... the CC_HAS_ASM_GOTO Kconfig symbol has been removed, so no feature check is necessary, and we can always make use of asm goto. 2) Associating callback alternatives with a cpucap. This removes the need to special-case alternatives with callbacks, making it clearer when the callbacks will be invoked, and making it possible to add boot-time callbacks in future. This also makes it possible to add shared callbacks for common operations (e.g. where the replacement consists purely of NOPs), saving space. With this series applied, the resulting vmlinux is ~364KiB smaller, and the resulting Image is 64KiB smaller (due to padding and alignment): | % ls -al vmlinux-* | -rwxr-xr-x 1 mark mark 134644592 Sep 1 15:25 vmlinux-after | -rwxr-xr-x 1 mark mark 135018072 Sep 1 15:23 vmlinux-v6.0-rc3 | % ls -al Image-* | -rw-r--r-- 1 mark mark 37108224 Sep 1 15:25 Image-after | -rw-r--r-- 1 mark mark 37173760 Sep 1 15:23 Image-v6.0-rc3 Note: this patch does *NOT* address latent issues with noinstr safety in the existing alternatives callbacks, which will be addressed in a separate patch series. Since v1 [1]: * Expand commit message for making alt_region const * Remove unused macro * Fix typos and phrasing * Add R-b from Joey [1] https://lore.kernel.org/r/20220901151403.1735836-1-mark.rutland@arm.com Mark. Mark Rutland (8): arm64: cpufeature: make cpus_have_cap() noinstr-safe arm64: alternatives: kvm: prepare for cap changes arm64: alternatives: proton-pack: prepare for cap changes arm64: alternatives: hoist print out of __apply_alternatives() arm64: alternatives: make alt_region const arm64: alternatives: have callbacks take a cap arm64: alternatives: add alternative_has_feature_*() arm64: alternatives: add shared NOP callback arch/arm64/include/asm/alternative-macros.h | 59 ++++++++++++++++-- arch/arm64/include/asm/assembler.h | 10 ++-- arch/arm64/include/asm/cpufeature.h | 15 ++--- arch/arm64/include/asm/kvm_mmu.h | 5 +- arch/arm64/include/asm/lse.h | 5 +- arch/arm64/kernel/alternative.c | 66 ++++++++++++--------- arch/arm64/kernel/cpufeature.c | 44 ++++++-------- arch/arm64/kernel/entry.S | 8 +-- arch/arm64/kernel/image-vars.h | 5 +- arch/arm64/kernel/proton-pack.c | 2 +- arch/arm64/kvm/hyp/hyp-entry.S | 4 +- arch/arm64/kvm/va_layout.c | 5 +- arch/arm64/tools/cpucaps | 2 + 13 files changed, 137 insertions(+), 93 deletions(-) -- 2.30.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel