From patchwork Wed Oct 16 19:26:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13838797 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 03C0CD2A541 for ; Wed, 16 Oct 2024 19:29:53 +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=sdyYwjyFS7cKng3xrhrvuZYheW62euvO0qiJZmOhRNg=; b=q4flCO00qyiE30nMIVWYxQ5P/e v9r4jQ2oSvwPG5KkNHAIS6H/Y2uJDWTeIQBtCnlIFZynTXyU7i2pC4stkNv3aZ886Ud+VaA4TTDyE uuQl4rxbqb1XWNO1WVzYnOs9ojBHa7GJMwu70JWAfMHa/+56zd2qZEtfIqu3dV7J1mY/IJbhHLuTq 8Rghd7IHnLctPKFC8aoiWZoforKXXjiRd3XnvDQA7psNtNAiAyJ0nt+SGnmWB5xct4QVteDMPUFQg Dz1Lz3krpb/ekwFI7cV0PRXrhobCEXiSTxCQdGE331ELR8ifEgSuohn1qgKlJw17g3B4B9ejUlSTp J4ZuUXlg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t19iJ-0000000Co2f-4AzF; Wed, 16 Oct 2024 19:29:44 +0000 Received: from mail-wm1-x349.google.com ([2a00:1450:4864:20::349]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t19fX-0000000CnaQ-1NlN for linux-arm-kernel@lists.infradead.org; Wed, 16 Oct 2024 19:26:52 +0000 Received: by mail-wm1-x349.google.com with SMTP id 5b1f17b1804b1-43117b2a901so1917555e9.1 for ; Wed, 16 Oct 2024 12:26:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729106809; x=1729711609; 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=sdyYwjyFS7cKng3xrhrvuZYheW62euvO0qiJZmOhRNg=; b=zcyT8zCr0SQByYsNnhbZ9itPgWkP/elYFH6bnFW8tWfBuzvhg4A1pNTBJY+fTrUABY JEsdu44KHNOYJV1QtPol02i6RBYXrWrEnpO0vR8qv8ypCe5E8yYIddBBjo6G3iSirUnJ szrnaPH8TUUoPAhvnB5jiDQ0qfItxj4zuZT+tHJppK5lqPjEJH6cLcK/uTo/Z4R5gENw Hv0yCaFdwQBW0oUZmvo+vKowwz6ggdNZqXTEGPKp5Bn4nShpdQOXvTbqU86oExxckM3d xzAX7MIYVqIFwK7wOtA6eaNTDN10PK4tklMa0KV2PtFTOrmLGMRaJprvZ5SQnyAUlLWd 1A5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729106809; x=1729711609; 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=sdyYwjyFS7cKng3xrhrvuZYheW62euvO0qiJZmOhRNg=; b=OfJi581MKmMuMqFZyDAxt0KQGiElcUMDsdGXLBbJYrHmPLeGQt6jowF6/BrpZnVK1q pkfqZKcBrm678S+8rR3yxoX5DJ696QfjxkCfTYAwVLnagviCo0/SJ2yok7Tf/+S4fp2S IakczFxmmTdObGyCI1k6Bg6zI4gVRjod4c0qxS5Sg0HKI6kN5smfCfNDPWLLdokoQrHg hLx2DlTlT3pPXrlR9Hu8Rd9tYkpn9fKY6VjPdgC7D4uPN80p5MLNb5EpNB+HkgU9jnkY ETUhNPODKuK3oRAsO0VMpZfGaRgxO1CT28ePDSmEDf+CGQ20CFpuSrmJfb1HCpOlcV4E t/tQ== X-Gm-Message-State: AOJu0YxNJy6VV1FfnWZvabh+b1+fX6OEjYqsxULzNkVkPOFWEf3Vwx6j ePCxB9B3wXXuFIm8VxYm3SIPxfLwuuDCIu2vKHfRaOdM8aZayd7pvQrluzByP7lVaQcoxF5T8Ws oj5X8BK3nbwaUuaJsxxR8SdL7LkfWU935YW6RVOw8DayuD3RsNK+JCZ6R0RLHrz2N68du2ygBwi vvw3RUtDEFsZ6O5jP3GWU+WuCzJxrfG8Qe5dtzVqi5 X-Google-Smtp-Source: AGHT+IFNPVTQq4FU+tjLci7Y7yj+a7X37dCzskRm3spU5YpifCPnZ7HlXxkkLmtwz8D5/uebxM7mm2Tn X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:7b:198d:ac11:8138]) (user=ardb job=sendgmr) by 2002:a05:600c:26c4:b0:430:4e1e:9b93 with SMTP id 5b1f17b1804b1-4314a28b66cmr30515e9.1.1729106808491; Wed, 16 Oct 2024 12:26:48 -0700 (PDT) Date: Wed, 16 Oct 2024 21:26:42 +0200 In-Reply-To: <20241016192640.406255-4-ardb+git@google.com> Mime-Version: 1.0 References: <20241016192640.406255-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=3064; i=ardb@kernel.org; h=from:subject; bh=t1qGgmVoGyL6ETZIh2nQx2YqAZcU/0d9D3ED8tzRuT0=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIV1AuMiwY47kzKTnOvHTz5cHyx+V3/hUy0hdUl9PnOFb6 8rdL1d0lLIwiHEwyIopsgjM/vtu5+mJUrXOs2Rh5rAygQxh4OIUgIk0PGZk+KujsWGZZ170Z2++ nBPTvL8z1itsrk/N4YsOvri0PiR9CiNDg6Tb4YwWkdx+wVleHHJdOa1u1cUTDGdO350W33rAcSE bAA== X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Message-ID: <20241016192640.406255-5-ardb+git@google.com> Subject: [PATCH v2 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241016_122651_375782_4F2C8B58 X-CRM114-Status: GOOD ( 14.03 ) 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. Signed-off-by: Ard Biesheuvel Reviewed-by: Eric Biggers --- arch/arm64/lib/Makefile | 2 +- arch/arm64/lib/crc32-glue.c | 34 ++++++++++++++++++++ arch/arm64/lib/crc32.S | 21 ++++-------- 3 files changed, 41 insertions(+), 16 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..5dac63da4247 100644 --- a/arch/arm64/lib/crc32.S +++ b/arch/arm64/lib/crc32.S @@ -136,25 +136,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)