From patchwork Thu Oct 17 09:41:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13839770 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 6C285D2126D for ; Thu, 17 Oct 2024 10:01:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=kezPyuM4InCRolJl6LAlFN5HCzOB9cU6j7/gSS+7X54=; b=w0WdH9KMJFXMWuD9jlfsda+EpO lBWdRaf7Fr67Gvk7FNsxWjySavKFChLj8DcWImZTXrG/xUpIdV+MHcrS/qUgLMz57lBRghviVUY0l Ed3U+oMM3uBp7gQomQTpwy5RvItEANjcfZwaDaM4MjMtb19aONXoAfbu8rk5dkKiA5xvfMGUONki+ LGLccvyzKrEneTZhyZxZ5ptE9i7PnNVHZGGmIUI0kCapNXz/p4Kjk8ZWpjP7WKi9aZAV9JhqeOhil /rpCzrZArdB87cf3gpn7qw9M0n0m754sSc5hWugPzPbFmtCeU45Hn9+SsGkKF1a6YTfl49IRa5isy MfeFj1Hw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t1NJh-0000000ESAQ-2ax2; Thu, 17 Oct 2024 10:01:13 +0000 Received: from mail-wr1-x44a.google.com ([2a00:1450:4864:20::44a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t1N0q-0000000ENN6-0zZT for linux-arm-kernel@lists.infradead.org; Thu, 17 Oct 2024 09:41:45 +0000 Received: by mail-wr1-x44a.google.com with SMTP id ffacd0b85a97d-37d533a484aso872949f8f.0 for ; Thu, 17 Oct 2024 02:41:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729158101; x=1729762901; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=kezPyuM4InCRolJl6LAlFN5HCzOB9cU6j7/gSS+7X54=; b=jtG7sai9wjvdQT5Wcykly9gHWGgvnKy8ro3u6kreTV1alFsarShq0pM2vU4TM77naw Xn4WSuiya4bUgLJsrQEg+ef2vgA1kYH2nD8UTzCu0t+2JYIdBXRIeHqGP37W3xXeviKN bLD/q8UOHBV2KfjpgfcdAJZEleNTXejC4dcVpTcigohpDNhmS19W6pNqs1IupCuDlTWK XRL8o5S0BWPeIJLiA+1k+ed4AbvV3jjNS1V6FTH8RUSr5xOsZj9xf/GFmrUs4Vxc1XVM hsIfbEAH7NHrrmGBwgok9Mei+GIv/VBLSDr8GDOExYg6iXnb2C+OV4nkObz1DZNR9/Af I/XA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729158101; x=1729762901; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=kezPyuM4InCRolJl6LAlFN5HCzOB9cU6j7/gSS+7X54=; b=bzYr8k2xIC5SR9UHdW5z3Kh8sAvRG8g1+teEVSGP/0JSE1vG2iPsock/RV1pSDjwyH Js3hue2NUNQRkGj3a0i1GWwR9xZGMRinHs/vwzfj5/bORZcJP/yjBgV2qLzVk3I2Pb1J E9Z6m24H9VAyyNb8IRvAYbwd/KDLHD502tirYUKq0AAzErUmPAiQSMpG2UmdFuW+jJEX 38ttZFUmsDlQYEFCbef7lg9/zAt+naJVfHH6wJ10EKiclwwX49GHqrAlZTfacIf+NSSp g2EZlbUauIm+83JwAT81EhS4eeQHbMF0dc1Bynl6/oPyku6ITSZJcKG5aCvDyl5fmrIB M9fg== X-Gm-Message-State: AOJu0Yx23FYXcUPku24WE+33m77/336SIGOM+LkHWi4lv4YsjWff/k21 J6gILJQlp7AwZ1gsPLDiTwcjHNdcsSgu23ZFDLl3W8AJqy573VlsC17FrAqSk7EufLX1BfzR1x9 CYd8yo7J8GkC/EW11E/sUlK9N+iirPRrmgRGeyQbkxHHdwOAUrzyx+yqSdfgFdNwO3av5isU62m B7/vDWQf5jDzgyF4x9d5DMmCrA07kbLKn/UfyYDcQD X-Google-Smtp-Source: AGHT+IFtrefZwulQCp/DMukJY8gdjmqiJAlfQp80ffHtAb5a7zr+SDM3yt7r1lb8TZ0V24OYrICWPe6U X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:7b:198d:ac11:8138]) (user=ardb job=sendgmr) by 2002:adf:a349:0:b0:37d:32f2:eb27 with SMTP id ffacd0b85a97d-37d93e1ba24mr1702f8f.4.1729158100933; Thu, 17 Oct 2024 02:41:40 -0700 (PDT) Date: Thu, 17 Oct 2024 11:41:34 +0200 In-Reply-To: <20241017094132.2482168-4-ardb+git@google.com> Mime-Version: 1.0 References: <20241017094132.2482168-4-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=3254; i=ardb@kernel.org; h=from:subject; bh=BrBF0xPC0fiK7oW+r+6zBvbfuoNaGmKqDl154e11vl8=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIV3g9rlY/pZJO9Q23nRh4V6gbpDwge/T3+l14aIKenfXe Mzf6r+8o5SFQYyDQVZMkUVg9t93O09PlKp1niULM4eVCWQIAxenAEwk0JThv++e5d/EtlQuSmB7 yvHvch2D+pv59tyH6hfz1oUExM3P4mf4K7FFWzx59/uJvYe+7jo9PYbJ/pEyV4Oe7PE5siuVfxz nZwUA X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Message-ID: <20241017094132.2482168-5-ardb+git@google.com> Subject: [PATCH v3 1/2] arm64/lib: Handle CRC-32 alternative in C code From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, herbert@gondor.apana.org.au, will@kernel.org, catalin.marinas@arm.com, Ard Biesheuvel , Eric Biggers , Kees Cook , Eric Biggers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241017_024144_311355_E2CA4B32 X-CRM114-Status: GOOD ( 13.66 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Ard Biesheuvel In preparation for adding another code path for performing CRC-32, move the alternative patching for ARM64_HAS_CRC32 into C code. The logic for deciding whether to use this new code path will be implemented in C too. Reviewed-by: Eric Biggers Signed-off-by: Ard Biesheuvel --- arch/arm64/lib/Makefile | 2 +- arch/arm64/lib/crc32-glue.c | 34 ++++++++++++++++++++ arch/arm64/lib/crc32.S | 22 ++++--------- 3 files changed, 41 insertions(+), 17 deletions(-) diff --git a/arch/arm64/lib/Makefile b/arch/arm64/lib/Makefile index 13e6a2829116..8e882f479d98 100644 --- a/arch/arm64/lib/Makefile +++ b/arch/arm64/lib/Makefile @@ -13,7 +13,7 @@ endif lib-$(CONFIG_ARCH_HAS_UACCESS_FLUSHCACHE) += uaccess_flushcache.o -obj-$(CONFIG_CRC32) += crc32.o +obj-$(CONFIG_CRC32) += crc32.o crc32-glue.o obj-$(CONFIG_FUNCTION_ERROR_INJECTION) += error-inject.o diff --git a/arch/arm64/lib/crc32-glue.c b/arch/arm64/lib/crc32-glue.c new file mode 100644 index 000000000000..0b51761d4b75 --- /dev/null +++ b/arch/arm64/lib/crc32-glue.c @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include +#include + +#include + +asmlinkage u32 crc32_le_arm64(u32 crc, unsigned char const *p, size_t len); +asmlinkage u32 crc32c_le_arm64(u32 crc, unsigned char const *p, size_t len); +asmlinkage u32 crc32_be_arm64(u32 crc, unsigned char const *p, size_t len); + +u32 __pure crc32_le(u32 crc, unsigned char const *p, size_t len) +{ + if (!alternative_has_cap_likely(ARM64_HAS_CRC32)) + return crc32_le_base(crc, p, len); + + return crc32_le_arm64(crc, p, len); +} + +u32 __pure __crc32c_le(u32 crc, unsigned char const *p, size_t len) +{ + if (!alternative_has_cap_likely(ARM64_HAS_CRC32)) + return __crc32c_le_base(crc, p, len); + + return crc32c_le_arm64(crc, p, len); +} + +u32 __pure crc32_be(u32 crc, unsigned char const *p, size_t len) +{ + if (!alternative_has_cap_likely(ARM64_HAS_CRC32)) + return crc32_be_base(crc, p, len); + + return crc32_be_arm64(crc, p, len); +} diff --git a/arch/arm64/lib/crc32.S b/arch/arm64/lib/crc32.S index 8340dccff46f..22139691c7ae 100644 --- a/arch/arm64/lib/crc32.S +++ b/arch/arm64/lib/crc32.S @@ -6,7 +6,6 @@ */ #include -#include #include .arch armv8-a+crc @@ -136,25 +135,16 @@ CPU_BE( rev16 \reg, \reg ) .endm .align 5 -SYM_FUNC_START(crc32_le) -alternative_if_not ARM64_HAS_CRC32 - b crc32_le_base -alternative_else_nop_endif +SYM_FUNC_START(crc32_le_arm64) __crc32 -SYM_FUNC_END(crc32_le) +SYM_FUNC_END(crc32_le_arm64) .align 5 -SYM_FUNC_START(__crc32c_le) -alternative_if_not ARM64_HAS_CRC32 - b __crc32c_le_base -alternative_else_nop_endif +SYM_FUNC_START(crc32c_le_arm64) __crc32 c -SYM_FUNC_END(__crc32c_le) +SYM_FUNC_END(crc32c_le_arm64) .align 5 -SYM_FUNC_START(crc32_be) -alternative_if_not ARM64_HAS_CRC32 - b crc32_be_base -alternative_else_nop_endif +SYM_FUNC_START(crc32_be_arm64) __crc32 be=1 -SYM_FUNC_END(crc32_be) +SYM_FUNC_END(crc32_be_arm64)