Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1779851pxp; Mon, 21 Mar 2022 05:05:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwtwaxRs0MAENlBbFv738VT2klb8O9XCKO0IQlLpDclfP/rB45ZAmmEzOC2A4psjZtwkiix X-Received: by 2002:a17:90a:e7c6:b0:1c7:443:3fdf with SMTP id kb6-20020a17090ae7c600b001c704433fdfmr6868979pjb.3.1647864322395; Mon, 21 Mar 2022 05:05:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647864322; cv=none; d=google.com; s=arc-20160816; b=KtDQzf+/HfDE7UFKLaiGcCH9G7nBCIBBjQK1BFLB9mAuth07vAD63jX5PyCRs8l0bD Qk93A0DgEmH2mC9zd0NPaWAcDm9F++zY00GlRvW4r+Jqlt8NfCfbXPhrVeTZjg7g86S8 PKi61ofrMBy/HKgTxrDUZeR273VPjHdBmh/CsPUW+RrS465DGPn6UbDFhvn3N5qTvr7M T+WLT3YFcecuQtom5cCg3Op1EMY4vgQLxUqAEBwauW9fe7SkTg7TMvghVNCwEJRo08Sl 6dW9qhyrRb6MVpGq7s1EmwHMNtKMNn91KoPdG5KNdyo99Tih6k+UAHKch4njTw1dNMye WNqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=UErwGd6I/hBcA1Kre4A83puzA4o3RWqNj7NAXAbfm30=; b=I3yPCHErjmZaDZfmM0DpjhVofZYdVpJTqnFTJtnW6mO/r7ThyGqdDIS++L/suMgs1n RIX8fMSKu4KGWLcgp6PCEWQasW6TePqi86U9D3qTuyoPfE1DP9Sp9B9tYJdwSiBqxn9V TrlH05xgt0dCUVayyxTTP6NwwXyldVMLrcoAlTQpSoErUflFdpcDsbaPE2wY6GqyGg8d Up8Q52u7/RaFMrbPE/5RxERATBIDBz7oD9RSTAKTMQn9IKbBKwW9GngVAgvafKQKkfo+ oJiCTihjVo+DpTzPClqFIzGnb69T/ZkCvPxrVYzdBmyA4spiwYwki4WifAJ4i4HE0Av7 +Apg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 22-20020a631456000000b003816043eef5si13598156pgu.234.2022.03.21.05.05.08; Mon, 21 Mar 2022 05:05:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239826AbiCRRvJ (ORCPT + 99 others); Fri, 18 Mar 2022 13:51:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239809AbiCRRu5 (ORCPT ); Fri, 18 Mar 2022 13:50:57 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 08E6415DABC; Fri, 18 Mar 2022 10:49:39 -0700 (PDT) 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 C3C221515; Fri, 18 Mar 2022 10:49:38 -0700 (PDT) Received: from eglon.cambridge.arm.com (eglon.cambridge.arm.com [10.1.196.218]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 2401B3F7B4; Fri, 18 Mar 2022 10:49:38 -0700 (PDT) From: James Morse To: stable@vger.kernel.org Cc: linux-kernel@vger.kernel.org, james.morse@arm.com, catalin.marinas@arm.com Subject: [stable:PATCH v4.19.235 06/22] arm64: entry: Free up another register on kpti's tramp_exit path Date: Fri, 18 Mar 2022 17:48:26 +0000 Message-Id: <20220318174842.2321061-7-james.morse@arm.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220318174842.2321061-1-james.morse@arm.com> References: <20220318174842.2321061-1-james.morse@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org commit 03aff3a77a58b5b52a77e00537a42090ad57b80b upstream. Kpti stashes x30 in far_el1 while it uses x30 for all its work. Making the vectors a per-cpu data structure will require a second register. Allow tramp_exit two registers before it unmaps the kernel, by leaving x30 on the stack, and stashing x29 in far_el1. Reviewed-by: Russell King (Oracle) Reviewed-by: Catalin Marinas Signed-off-by: James Morse --- arch/arm64/kernel/entry.S | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S index 96a0dda176c5..16988a9d1d19 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -348,18 +348,20 @@ alternative_else_nop_endif ldp x24, x25, [sp, #16 * 12] ldp x26, x27, [sp, #16 * 13] ldp x28, x29, [sp, #16 * 14] - ldr lr, [sp, #S_LR] - add sp, sp, #S_FRAME_SIZE // restore sp /* * ARCH_HAS_MEMBARRIER_SYNC_CORE rely on eret context synchronization * when returning from IPI handler, and when returning to user-space. */ .if \el == 0 -alternative_insn eret, nop, ARM64_UNMAP_KERNEL_AT_EL0 +alternative_if_not ARM64_UNMAP_KERNEL_AT_EL0 + ldr lr, [sp, #S_LR] + add sp, sp, #S_FRAME_SIZE // restore sp + eret +alternative_else_nop_endif #ifdef CONFIG_UNMAP_KERNEL_AT_EL0 bne 4f - msr far_el1, x30 + msr far_el1, x29 tramp_alias x30, tramp_exit_native br x30 4: @@ -367,6 +369,8 @@ alternative_insn eret, nop, ARM64_UNMAP_KERNEL_AT_EL0 br x30 #endif .else + ldr lr, [sp, #S_LR] + add sp, sp, #S_FRAME_SIZE // restore sp eret .endif .endm @@ -996,10 +1000,12 @@ alternative_insn isb, nop, ARM64_WORKAROUND_QCOM_FALKOR_E1003 .macro tramp_exit, regsize = 64 adr x30, tramp_vectors msr vbar_el1, x30 - tramp_unmap_kernel x30 + ldr lr, [sp, #S_LR] + tramp_unmap_kernel x29 .if \regsize == 64 - mrs x30, far_el1 + mrs x29, far_el1 .endif + add sp, sp, #S_FRAME_SIZE // restore sp eret .endm -- 2.30.2