Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp1071357rwb; Sat, 13 Aug 2022 16:07:35 -0700 (PDT) X-Google-Smtp-Source: AA6agR43I1iwwwW0TthGkDrCf1TjJ/YcB+NtLHjhpkRJBiwZnMDtrucszC1jSUJiZlIhSYO+CAaJ X-Received: by 2002:a05:6402:354e:b0:440:5398:cd65 with SMTP id f14-20020a056402354e00b004405398cd65mr8772886edd.43.1660432055309; Sat, 13 Aug 2022 16:07:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660432055; cv=none; d=google.com; s=arc-20160816; b=VBXZ8k/bhDo7MHxCCl3o1jU1RF2syrqZP5/Oppv3w8rIVXhU9CCnXFGz39UwX7Gbro r+RrM15XwPWVy0zbDICrz9BmhbHOrHK4J1xXEyN3DPgOqhS8EvflnwdYF3z0kkAAwwI5 KPdvQN7wcRDV/3SodzhGDawZzQCSQyOQBsBy8X4tzmyenjfmwHVqIS5uNYI77W7dGJrd bo8PZQcA2v3Q47Ij31e0F4Dxr6V9RitYEB3XOZavlqqBTrzIlNXHmIw0ieVDhBXQhTdh 1FsWJfV5QXI1hkTf7ZjDpUKjAXvTCrrxBsuutXc5kEG4AjtLpfAA8lJ+3KtIwfKLmkGa YHaQ== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=2y/+QjsbwZnDSI3U6kv+3YmFpybKucr3hBm4+M8u7aw=; b=E4k/iRdZ+PxgcBmOPIjEvTt8cinsygxFDTUkYeGwZMm0VL9spb3UATYMFxMJNQE3GJ 0YKuxVYo/+m5CtvXvGfCT7ZiknMGO2rJn5GvE7S+U4uiZOm9hqHZLvP5cY5nasbWTuNm eech6T3Uf27N+i5Z2rg8wYbRNAl/JdJ9ekfBR4M1wbrvOt+oDBF2+b0KNzkAjvCWSpuz ENaXDDuJXKKFYA4buIx0bpvqM4xvbuEcZQQzFc5d5porR2f9KjTKBz3sLsDVlYCr4vFm 4hB8EiFTgsImH4+XAyI7S51XWd08uCpCT8n0JCPGNT45+Wn9OpllpNIP0WMdRruW+jbj 5CWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@hpe.com header.s=pps0720 header.b=Na+K7Oq7; 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=hpe.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hc12-20020a170907168c00b007316cc27ab0si5438257ejc.980.2022.08.13.16.06.55; Sat, 13 Aug 2022 16:07:35 -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=@hpe.com header.s=pps0720 header.b=Na+K7Oq7; 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=hpe.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239646AbiHMXGv (ORCPT + 99 others); Sat, 13 Aug 2022 19:06:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238439AbiHMXGu (ORCPT ); Sat, 13 Aug 2022 19:06:50 -0400 Received: from mx0a-002e3701.pphosted.com (mx0a-002e3701.pphosted.com [148.163.147.86]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 407A78284F for ; Sat, 13 Aug 2022 16:06:49 -0700 (PDT) Received: from pps.filterd (m0134421.ppops.net [127.0.0.1]) by mx0b-002e3701.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 27DMvvbM014112; Sat, 13 Aug 2022 23:05:20 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hpe.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding; s=pps0720; bh=2y/+QjsbwZnDSI3U6kv+3YmFpybKucr3hBm4+M8u7aw=; b=Na+K7Oq7hJ5zGFVg8xzw33lbYZZVXcnKf69/q8Y3KcxwlZsKdFd3zMljfJA3nCLuXfZy KfvAI35VZgkXn4oal2yug3zwPO/XX96oMhu5510VxeLv8W0y68/jqlKlejI4g3fKcou9 NaMiJW9S3IgdSu0YahGrorvj2QK6NHU0FIAFB8bdmQ/6aY4WapqdW2Xgtb4Yx0IoUhcp 9a5zhPjsnIpBFyRwwXTcdAH6Yn5vZ/kD2QFEvHm9Dbk6jzFJ0JUiS+UB1oBNRqiDqG7X BKyZR7pjStkTup0uG3lHgqeTLjuDd0tWSSXnRSIYXnnXCARnXIewLH5uKTGBv/DlC1lI /w== Received: from p1lg14879.it.hpe.com (p1lg14879.it.hpe.com [16.230.97.200]) by mx0b-002e3701.pphosted.com (PPS) with ESMTPS id 3hx3vfmd9k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 13 Aug 2022 23:05:20 +0000 Received: from p1lg14885.dc01.its.hpecorp.net (unknown [10.119.18.236]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by p1lg14879.it.hpe.com (Postfix) with ESMTPS id D31C9132DE; Sat, 13 Aug 2022 23:05:19 +0000 (UTC) Received: from adevxp033-sys.us.rdlabs.hpecorp.net (unknown [16.231.227.36]) by p1lg14885.dc01.its.hpecorp.net (Postfix) with ESMTP id 1D6C38041D1; Sat, 13 Aug 2022 23:05:17 +0000 (UTC) From: Robert Elliott To: tim.c.chen@linux.intel.com, herbert@gondor.apana.org.au, davem@davemloft.net, linux-crypto@vger.kernel.org, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, toshi.kani@hpe.com, rwright@hpe.com Cc: Robert Elliott Subject: [PATCH] crypto: x86/sha512 - load based on CPU features Date: Sat, 13 Aug 2022 18:04:31 -0500 Message-Id: <20220813230431.2666-1-elliott@hpe.com> X-Mailer: git-send-email 2.37.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Proofpoint-GUID: phYctUuUBvkym5Ne6LbuRZoJbIH4t842 X-Proofpoint-ORIG-GUID: phYctUuUBvkym5Ne6LbuRZoJbIH4t842 X-HPE-SCL: -1 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-08-13_11,2022-08-11_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 impostorscore=0 lowpriorityscore=0 priorityscore=1501 suspectscore=0 mlxlogscore=999 spamscore=0 clxscore=1011 malwarescore=0 mlxscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2208130095 X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE,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-crypto@vger.kernel.org x86 optimized crypto modules built as modules rather than built-in to the kernel end up as .ko files in the filesystem, e.g., in /usr/lib/modules. If the filesystem itself is a module, these might not be available when the crypto API is initialized, resulting in the generic implementation being used (e.g., sha512_transform rather than sha512_transform_avx2). In one test case, CPU utilization in the sha512 function dropped from 15.34% to 7.18% after forcing loading of the optimized module. Add module aliases for this x86 optimized crypto module based on CPU feature bits so udev gets a chance to load them later in the boot process when the filesystems are all running. Signed-off-by: Robert Elliott --- arch/x86/crypto/sha512_ssse3_glue.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arch/x86/crypto/sha512_ssse3_glue.c b/arch/x86/crypto/sha512_ssse3_glue.c index 30e70f4fe2f7..6d3b85e53d0e 100644 --- a/arch/x86/crypto/sha512_ssse3_glue.c +++ b/arch/x86/crypto/sha512_ssse3_glue.c @@ -36,6 +36,7 @@ #include #include #include +#include #include asmlinkage void sha512_transform_ssse3(struct sha512_state *state, @@ -284,6 +285,13 @@ static int register_sha512_avx2(void) ARRAY_SIZE(sha512_avx2_algs)); return 0; } +static const struct x86_cpu_id module_cpu_ids[] = { + X86_MATCH_FEATURE(X86_FEATURE_AVX2, NULL), + X86_MATCH_FEATURE(X86_FEATURE_AVX, NULL), + X86_MATCH_FEATURE(X86_FEATURE_SSSE3, NULL), + {} +}; +MODULE_DEVICE_TABLE(x86cpu, module_cpu_ids); static void unregister_sha512_avx2(void) { @@ -294,6 +302,8 @@ static void unregister_sha512_avx2(void) static int __init sha512_ssse3_mod_init(void) { + if (!x86_match_cpu(module_cpu_ids)) + return -ENODEV; if (register_sha512_ssse3()) goto fail; -- 2.37.1