From patchwork Sat Mar 10 15:21:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 10273655 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D3C30602BD for ; Sat, 10 Mar 2018 15:26:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C0FC529563 for ; Sat, 10 Mar 2018 15:26:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B5B2429765; Sat, 10 Mar 2018 15:26:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4B7A029563 for ; Sat, 10 Mar 2018 15:26:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=0h6XIHmLjqVOvI6JocZ834afg4S+TNnoaO+o0STwXCk=; b=pQ8rYete1Av9EuIxLQc1wBt7e3 RAL3tR+KAaDA6kz5sb1UDp/ruBjykFS9FrrLP5OdJsbKcHJjH6yqmS6y2+wVJ3HAq/uOtmGDgk9fk dCKU7/k9cPV0lAgOFoaOL6A14oThxDLdkbNPvNLtn1eq1YW8oXwG5cbuFT/3zYbEwgv9kmVgdVSvZ rfZerqIDpUgC8o6k6M9kdsrkQDX2SdZHc9pchPLYSGaHGunq7ucJO9JQS4O67vlfJQE7fw3aNubmb YBO0li/n8EXxf5Pkkfk/lBZsiEVSq4m1gmo3RRnPBYdT7JVeDWbwVHaoQMA5SA97A6CELSGwPXzXd l8DC7zew==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1eugOH-0002qM-Mm; Sat, 10 Mar 2018 15:26:33 +0000 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eugKv-00089t-OZ for linux-arm-kernel@lists.infradead.org; Sat, 10 Mar 2018 15:23:17 +0000 Received: by mail-wm0-x244.google.com with SMTP id q83so8910527wme.5 for ; Sat, 10 Mar 2018 07:22:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ghtE/+HMhJ7+BEn8JVj07Uf/eaORWShrkPULyd1WCu8=; b=VMf6V7QQDK1FdmxfpKtNnLbFsdW5ywaElZ+MUDBevO5/6hGLvC2p+mpzayQBOluVa4 DVZ4pLMe3/1JAHYXiLF829Or0FglWvOUFrOEQH3+2oY54mis9Np5hyaUs/shwLn6yEpz s7rQGiyK9CbdbJoA/C5VfHJwEycb5VH3TTEbM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ghtE/+HMhJ7+BEn8JVj07Uf/eaORWShrkPULyd1WCu8=; b=FvRovgLc9wvTCxAUlnWxE7w/9j674s4oZ0foj7ZuVbBYIp+sqqraFF1jTwsY8e3pe2 RnRWJ7lqMBkPCoN2d600esQHWvAlxcYrNvHqL9DwF/tbcTbYbm00A2kgYPZwNJ3LPyKF qyC7pdED9vygREgRmiAXoJjU9zPUAGlmGjnc9S76qm9uXEfksbOEJFtMGotGgIikV5SC PoJFsQ0QWkFrPgEx0Zo5GAM0yR0Ipdp4mJih7tF+YvIoBT5Yw9ZuW4kBzax6cTb/cLI+ rG6HFKzzm1gMX15Q+OmFwvng0txlLxjhw8xD7jp77T9dCGhV4zZgmUbBiEp/Z8TOq7Ud 7b2w== X-Gm-Message-State: AElRT7E5oQW9yos6G6Fbp4aHzpe3eS04iohYYBjxvxu8jS1656TFo4Sj Ie5Zuuj1CXPpBSMEB7tmEbay/Q== X-Google-Smtp-Source: AG47ELuTWUWZ3uG2ELC6HEbfjU+hSHvsDQcfDU/2ddyLmZFMISdzf/ggSZM/pgzygB0nfrGb1q5Iyg== X-Received: by 10.28.1.14 with SMTP id 14mr1318939wmb.40.1520695378429; Sat, 10 Mar 2018 07:22:58 -0800 (PST) Received: from localhost.localdomain ([105.148.128.186]) by smtp.gmail.com with ESMTPSA id m9sm7027531wrf.13.2018.03.10.07.22.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 10 Mar 2018 07:22:57 -0800 (PST) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Subject: [PATCH v5 10/23] arm64: assembler: add utility macros to push/pop stack frames Date: Sat, 10 Mar 2018 15:21:55 +0000 Message-Id: <20180310152208.10369-11-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180310152208.10369-1-ard.biesheuvel@linaro.org> References: <20180310152208.10369-1-ard.biesheuvel@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180310_072306_738804_5A075D47 X-CRM114-Status: GOOD ( 18.49 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , herbert@gondor.apana.org.au, Ard Biesheuvel , Peter Zijlstra , Catalin Marinas , Sebastian Andrzej Siewior , Will Deacon , Russell King - ARM Linux , Steven Rostedt , Thomas Gleixner , Dave Martin , linux-arm-kernel@lists.infradead.org, linux-rt-users@vger.kernel.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP We are going to add code to all the NEON crypto routines that will turn them into non-leaf functions, so we need to manage the stack frames. To make this less tedious and error prone, add some macros that take the number of callee saved registers to preserve and the extra size to allocate in the stack frame (for locals) and emit the ldp/stp sequences. Signed-off-by: Ard Biesheuvel --- arch/arm64/include/asm/assembler.h | 70 ++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/arch/arm64/include/asm/assembler.h b/arch/arm64/include/asm/assembler.h index 053d83e8db6f..eef1fd2c1c0b 100644 --- a/arch/arm64/include/asm/assembler.h +++ b/arch/arm64/include/asm/assembler.h @@ -555,6 +555,19 @@ USER(\label, ic ivau, \tmp2) // invalidate I line PoU #endif .endm +/* + * Errata workaround post TTBR0_EL1 update. + */ + .macro post_ttbr0_update_workaround +#ifdef CONFIG_CAVIUM_ERRATUM_27456 +alternative_if ARM64_WORKAROUND_CAVIUM_27456 + ic iallu + dsb nsh + isb +alternative_else_nop_endif +#endif + .endm + /** * Errata workaround prior to disable MMU. Insert an ISB immediately prior * to executing the MSR that will change SCTLR_ELn[M] from a value of 1 to 0. @@ -565,4 +578,61 @@ USER(\label, ic ivau, \tmp2) // invalidate I line PoU #endif .endm + /* + * frame_push - Push @regcount callee saved registers to the stack, + * starting at x19, as well as x29/x30, and set x29 to + * the new value of sp. Add @extra bytes of stack space + * for locals. + */ + .macro frame_push, regcount:req, extra + __frame st, \regcount, \extra + .endm + + /* + * frame_pop - Pop the callee saved registers from the stack that were + * pushed in the most recent call to frame_push, as well + * as x29/x30 and any extra stack space that may have been + * allocated. + */ + .macro frame_pop + __frame ld + .endm + + .macro __frame_regs, reg1, reg2, op, num + .if .Lframe_regcount == \num + \op\()r \reg1, [sp, #(\num + 1) * 8] + .elseif .Lframe_regcount > \num + \op\()p \reg1, \reg2, [sp, #(\num + 1) * 8] + .endif + .endm + + .macro __frame, op, regcount, extra=0 + .ifc \op, st + .if (\regcount) < 0 || (\regcount) > 10 + .error "regcount should be in the range [0 ... 10]" + .endif + .if ((\extra) % 16) != 0 + .error "extra should be a multiple of 16 bytes" + .endif + .set .Lframe_regcount, \regcount + .set .Lframe_extra, \extra + .set .Lframe_local_offset, ((\regcount + 3) / 2) * 16 + stp x29, x30, [sp, #-.Lframe_local_offset - .Lframe_extra]! + mov x29, sp + .elseif .Lframe_regcount == -1 // && op == 'ld' + .error "frame_push/frame_pop may not be nested" + .endif + + __frame_regs x19, x20, \op, 1 + __frame_regs x21, x22, \op, 3 + __frame_regs x23, x24, \op, 5 + __frame_regs x25, x26, \op, 7 + __frame_regs x27, x28, \op, 9 + + .ifc \op, ld + ldp x29, x30, [sp], #.Lframe_local_offset + .Lframe_extra + .set .Lframe_regcount, -1 + .endif + .endm + #endif /* __ASM_ASSEMBLER_H */