Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp774033rwl; Wed, 12 Apr 2023 04:04:42 -0700 (PDT) X-Google-Smtp-Source: AKy350YzdvafurpVnLCpBXXzDUeILJ/xHsF5EhgMn8sS1ZFXZ7OkJt/C0BQFz+X2doWngwsmZ6K3 X-Received: by 2002:a17:907:1003:b0:931:4285:ea1d with SMTP id ox3-20020a170907100300b009314285ea1dmr1550946ejb.5.1681297482210; Wed, 12 Apr 2023 04:04:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681297482; cv=none; d=google.com; s=arc-20160816; b=PH4zsIxmys2Uo9V8eSutw8Dhk0+ddt5cxhqR8P2x56j0AKI7t5cqP3pbWycISQCprv 3GPU54Jr2kTXk4+N0HjgHAqockJcB8Hs3awGpvnribUZqinqJcvGcCD0w4EjKRgIsLgR /ntEeqtLfAv44VocOrQqgrerhv7V+YXNwOp/s76QDSnwnj8bScToxyjTL5m2kcn1EO8a t3t5E8Bb/MpG89mCPBM94dNAXz4b5Elp7KnU9ihScPc2qUTzUsrPFyg1kYk7Iuv6g4k8 bnnX1HWzd3A349GJbT7+v88N7fy5o+UO3WOorzjCfJAFyp34Uyn6YGaUIZgeXKjHbwQJ Sv+w== 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 :dkim-signature; bh=wXS39t1ilEJNep1FYH+GssDLaRidnrOR1lf5OWwh48U=; b=qvWFzb4ckftfd67/EUnfCciK12ceG/HNBBsE/xdNyfbTeNOUhaBd7NslSJE+Bw1Vjf EZ/Q0qXP+Z/458piMrADfZSSWLqswyk+HzOzzvZInHMuQQQxZAPaX0BosNarxP1VxW3L KzZO7XkPA7umj9jQF72w0Y3O/dRDU8pVtI+hzbP/FEW6s1UXTpIRAjZoFSAeKjpkGL4D eXSkmtway49TEw0DGDXQajtsQJkHXYh/m0loxgQy84xSaqfG0AvCKCGBxA4U0OtaioO0 YeODqHDjetzIB2tBpTbJV/nQ1I+j7vF0ZMRSJWKX5MskNZXALpOJSriOPRgYPyOZQ6s0 ouNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=pyVYsqkD; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dm21-20020a170907949500b0092a7c28c360si7537608ejc.5.2023.04.12.04.04.16; Wed, 12 Apr 2023 04:04:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=pyVYsqkD; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229647AbjDLLBA (ORCPT + 99 others); Wed, 12 Apr 2023 07:01:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229671AbjDLLA6 (ORCPT ); Wed, 12 Apr 2023 07:00:58 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99AD965B0 for ; Wed, 12 Apr 2023 04:00:57 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3415163256 for ; Wed, 12 Apr 2023 11:00:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 779E3C433D2; Wed, 12 Apr 2023 11:00:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681297256; bh=qEHykw/e7t8o+96tpVB/xNNOYi4X5fvmoTrv8XRvmCs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pyVYsqkDehjfnkV3ZwaaBytDALEmhWSq23F9wtMj/RhVBGk4YhIDtZYNET+XXmUsW Ho5c+fp3OypMTnuSxL+9OPANkeX+uFpnN3RfyJMm33GOepWu07oAyKj3hpcroqAShA QOilVAlF5EqyfiH6TMP15GRNlEYs+DoofXymLPpPgu3nroZkVVDO2JX+ZB3nyf7rkI hnDcrm9eb6X+8TDp5u8pzUmg3XFEv3tBDkddVDPG2GF9BL1uINzdkpYIMosoI/Rc4y K4LLpU37Iz982rYpHqLJrqrUh6zpvduwYzg7iuunnNd2XTqS0w3q3ZqbhI9y4WTlL3 CXDMbdlKs/JpQ== From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: Ard Biesheuvel , Herbert Xu , Eric Biggers , Kees Cook Subject: [PATCH v2 06/13] crypto: x86/cast6 - Use RIP-relative addressing Date: Wed, 12 Apr 2023 13:00:28 +0200 Message-Id: <20230412110035.361447-7-ardb@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230412110035.361447-1-ardb@kernel.org> References: <20230412110035.361447-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3224; i=ardb@kernel.org; h=from:subject; bh=qEHykw/e7t8o+96tpVB/xNNOYi4X5fvmoTrv8XRvmCs=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIcWs37MnQOXLh36nBbe63uUsZL7+LOfru9C/dWLz6lbri bP0/qvsKGVhEONgkBVTZBGY/ffdztMTpWqdZ8nCzGFlAhnCwMUpABNZvZOR4Q9/UfWKXY46Qj2W KZV1rr/NeKZKBeZoJp29HqPXZmGTzvDfTUOC8/mytesMH989w3Le2zCjPcHQ1Erh2XLuIp/NWhP ZAA== X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS 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-crypto@vger.kernel.org Prefer RIP-relative addressing where possible, which removes the need for boot time relocation fixups. Co-developed-by: Thomas Garnier Signed-off-by: Thomas Garnier Signed-off-by: Ard Biesheuvel --- arch/x86/crypto/cast6-avx-x86_64-asm_64.S | 32 +++++++++++--------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S index 82b716fd5dbac65a..9e86d460b4092826 100644 --- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S +++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S @@ -84,15 +84,19 @@ #define lookup_32bit(src, dst, op1, op2, op3, interleave_op, il_reg) \ movzbl src ## bh, RID1d; \ + leaq s1(%rip), RID2; \ + movl (RID2,RID1,4), dst ## d; \ movzbl src ## bl, RID2d; \ + leaq s2(%rip), RID1; \ + op1 (RID1,RID2,4), dst ## d; \ shrq $16, src; \ - movl s1(, RID1, 4), dst ## d; \ - op1 s2(, RID2, 4), dst ## d; \ movzbl src ## bh, RID1d; \ + leaq s3(%rip), RID2; \ + op2 (RID2,RID1,4), dst ## d; \ movzbl src ## bl, RID2d; \ interleave_op(il_reg); \ - op2 s3(, RID1, 4), dst ## d; \ - op3 s4(, RID2, 4), dst ## d; + leaq s4(%rip), RID1; \ + op3 (RID1,RID2,4), dst ## d; #define dummy(d) /* do nothing */ @@ -175,10 +179,10 @@ qop(RD, RC, 1); #define shuffle(mask) \ - vpshufb mask, RKR, RKR; + vpshufb mask(%rip), RKR, RKR; #define preload_rkr(n, do_mask, mask) \ - vbroadcastss .L16_mask, RKR; \ + vbroadcastss .L16_mask(%rip), RKR; \ /* add 16-bit rotation to key rotations (mod 32) */ \ vpxor (kr+n*16)(CTX), RKR, RKR; \ do_mask(mask); @@ -258,9 +262,9 @@ SYM_FUNC_START_LOCAL(__cast6_enc_blk8) movq %rdi, CTX; - vmovdqa .Lbswap_mask, RKM; - vmovd .Lfirst_mask, R1ST; - vmovd .L32_mask, R32; + vmovdqa .Lbswap_mask(%rip), RKM; + vmovd .Lfirst_mask(%rip), R1ST; + vmovd .L32_mask(%rip), R32; inpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM); inpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM); @@ -284,7 +288,7 @@ SYM_FUNC_START_LOCAL(__cast6_enc_blk8) popq %rbx; popq %r15; - vmovdqa .Lbswap_mask, RKM; + vmovdqa .Lbswap_mask(%rip), RKM; outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM); outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM); @@ -306,9 +310,9 @@ SYM_FUNC_START_LOCAL(__cast6_dec_blk8) movq %rdi, CTX; - vmovdqa .Lbswap_mask, RKM; - vmovd .Lfirst_mask, R1ST; - vmovd .L32_mask, R32; + vmovdqa .Lbswap_mask(%rip), RKM; + vmovd .Lfirst_mask(%rip), R1ST; + vmovd .L32_mask(%rip), R32; inpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM); inpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM); @@ -332,7 +336,7 @@ SYM_FUNC_START_LOCAL(__cast6_dec_blk8) popq %rbx; popq %r15; - vmovdqa .Lbswap_mask, RKM; + vmovdqa .Lbswap_mask(%rip), RKM; outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM); outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM); -- 2.39.2