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 80026ECAAD1 for ; Thu, 1 Sep 2022 15:16:20 +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=rrX4qHqZ9C7Du5jqZYAe2WAVjZJyadUQo4W5nidT0Pw=; b=mig4s/Dk6X9Mkf o7meJ9Kv8wBt0w/tHUI9RvWmsn7eL2YD0dUNDDQYoVsjY29V/9YR3bZzcIDJaGLTsp1jmIT8euudi ECuaLPkBefsB8WdzBAR1uCZMlYXca/vRus7gsvIuCu3dyQg5tX5uJs+Fc0gZsDNtgKhAH/B2rwsI3 lBjHiuozlEQN5cT15Adz2vGuuzxFLQRjRI4k7yylfc/QqmviM9JHYYnN6K7fqj938KrGzhrwjtorn JwvM8qT15MA+4HK7A6bb7yhm6xbEPNEXgXWHpDNnO5vZxH7BDvfa3dbUWWdvCHLnwMuQdWqr4Ep19 9dYYK2s8UjjVffLLR9aA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oTluT-00CkGh-Ex; Thu, 01 Sep 2022 15:15:13 +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 1oTltY-00CjkY-IK for linux-arm-kernel@lists.infradead.org; Thu, 01 Sep 2022 15:14:20 +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 D288DD6E; Thu, 1 Sep 2022 08:14:14 -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 8EB8D3F766; Thu, 1 Sep 2022 08:14:07 -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 0/9] arm64: alternatives: improvements Date: Thu, 1 Sep 2022 16:13:54 +0100 Message-Id: <20220901151403.1735836-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-20220901_081416_741019_7D314CA0 X-CRM114-Status: GOOD ( 15.59 ) 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 As identified in the trailing "HACK" patch, there are further changes that could be made in future. 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. Mark. Mark Rutland (9): 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 HACK: arm64: alternatives: dump summary of alternatives 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 | 135 +++++++++++++++----- 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, 204 insertions(+), 95 deletions(-) -- 2.30.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel