Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp3677198pxm; Tue, 1 Mar 2022 03:17:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJzmNgPCzTuD48Yp0C60jGwEMBk+pc5zo4a5qQqOF1rZIlGdmOEfzazHROc16ftcmc2Clip8 X-Received: by 2002:a17:90a:604f:b0:1be:e84e:692 with SMTP id h15-20020a17090a604f00b001bee84e0692mr783655pjm.61.1646133453476; Tue, 01 Mar 2022 03:17:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646133453; cv=none; d=google.com; s=arc-20160816; b=c7txuntDOuvHNqT6CBU8NTSMxjGzqXO2+K2p4FCMorRxUtypWO1ziEd7MKImMAfwo+ t3DlLls4anfYhvmhZ1xOCtXCAIdZ0VB7HKcBqPsTGuKbWZUX7g8D31l0IssF1WBtR1vB QwIN5UZKT2PCeiPpxRhFVPZhpVfWXAVibvGnKH7JpiD4aKsRsokVX6Lq/x/BtTnfT4Rz 13AHb3JgCVG9qK53mSifyHqeCOP4T7uWX9mEtBeVE/aBuRAW9pXxzitiQV+r2Gz7nuQg vPqduR58CMZVsK1xVc+2B6Dy3eBnHPvENNrG4rpVllXWWR6CvoWfLSOShyD3pcC0EcCK BPxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:references:cc :to:from:subject:dkim-signature; bh=OnrvTGkeFdz9SdbU5YzUcBSW1gSC4dxIsoPtl5S/0ts=; b=wSnTGtDHNh6oN1Buym+HqJe7wOu9oJG2KMJg4E1It9ieCQeHzeV2oPeKKk26wGRFX3 LF6+wykdZrPidTks/JUiqzVMszSZAI1+RQyS4qTLx0CdbtSPimkANgm6L6LJEaPF2Yau Z38UCSzMA1M4SouLMXVq3rsi1KGaIES6GDvi40fCkxBZ4Oo6PTdC6P9HBv7sv0ZampdD wUzn7JxyribsJZLs8eY4untX+clFujpsT8Qaeav3q7kKRoaqsduQs6uCMBVM/VXzHpV5 a7QA+qMg9wjT8SR3UZ5jA8OXyc7/w9GU2jvO3qyVSP6L3dID0keeJ9q8M8glzuJTv3JV 2DiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=lMlykeCo; 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=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z12-20020a65610c000000b0037572b4b9fbsi13179686pgu.240.2022.03.01.03.17.17; Tue, 01 Mar 2022 03:17:33 -0800 (PST) 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=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=lMlykeCo; 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=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234098AbiCAK3N (ORCPT + 99 others); Tue, 1 Mar 2022 05:29:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234094AbiCAK3M (ORCPT ); Tue, 1 Mar 2022 05:29:12 -0500 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9846756C32 for ; Tue, 1 Mar 2022 02:28:30 -0800 (PST) Received: by mail-pj1-x1032.google.com with SMTP id m22so13734709pja.0 for ; Tue, 01 Mar 2022 02:28:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=OnrvTGkeFdz9SdbU5YzUcBSW1gSC4dxIsoPtl5S/0ts=; b=lMlykeCoeBj9pbm8Ib7uSMq9dStt/53mqUfx2z5VFG6jvOn36rzyKO/bfGleQvEiXE FzasQdln3ka7j+JaThLPFGyV6U/ACZts500Rvo7q6u6i20CssPsw9nnuZwPNED0r70UU 5SK3n9+/DGKFtTmR8ghteojViVhQui3Cqzdce3A358Y6XD0PPkAOFXP9zod+bwchXybO YBdv506L4f553PXcFwYQ7ywQg7js5X7r/PcC4E6iId7+DfqWvRvwOzc7LFxQ/zWtRVVU /Dp8PKzt37KMYZUWpmtsV6CiTl2Rtryy1BoegmoOY86Al9w3GbFbtgOFWwfN85Qey9Ys ndtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:from:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=OnrvTGkeFdz9SdbU5YzUcBSW1gSC4dxIsoPtl5S/0ts=; b=eSpMdMtjSQHnDf/FVmOFGIZcNYdZMfi/YqhYacGWXH/KwDesrtSEjusLlBb2tEZLMk nzFY61tsgeWpqBysdc0wE8DvSOs4rwQqKrxngdLGCRTehwEvy1zeNphXob8zUIIsx0yj egW96Se5G8Bp2EXU33EocQd36UFmH8UFASGxHdWFan48klhUfAE44izbZkvBOLECA4T7 s/MJExzfqJOt4tn5klKkskM1kLGFaSxw6LLgfI/+h4sOHECze7q/DZ5z7slKOTVqRBP1 BYhMKPwGyLIGlZwLel3Jn7g6Gn4eJbeYcL+8s1jNNdhu1Tlid2Y/zBjUTy8xPlxVv6Ql g1MQ== X-Gm-Message-State: AOAM532AlTD4ppMw7mMqB7nWfETrJ3PuJsYd9Qouab7GFqgtswxkiRg/ 1v2RQMRFVF/PJn0m9TqVFYXlvw== X-Received: by 2002:a17:902:7204:b0:14f:b325:7658 with SMTP id ba4-20020a170902720400b0014fb3257658mr24704466plb.110.1646130510135; Tue, 01 Mar 2022 02:28:30 -0800 (PST) Received: from [10.76.15.169] ([61.120.150.76]) by smtp.gmail.com with ESMTPSA id r12-20020a63a54c000000b00376047bf784sm12271772pgu.23.2022.03.01.02.28.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 01 Mar 2022 02:28:29 -0800 (PST) Subject: PING: [PATCH v2 3/3] virtio-crypto: implement RSA algorithm From: zhenwei pi To: "Gonglei (Arei)" Cc: "jasowang@redhat.com" , "mst@redhat.com" , "virtualization@lists.linux-foundation.org" , "linux-crypto@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "helei.sig11@bytedance.com" , "herbert@gondor.apana.org.au" , kernel test robot References: <20220211084108.1254218-1-pizhenwei@bytedance.com> <20220211084108.1254218-4-pizhenwei@bytedance.com> <8ef2f660-bd84-de70-1539-402c73795dfe@bytedance.com> Message-ID: <0c148ada-9f32-3272-8a89-591299ab098d@bytedance.com> Date: Tue, 1 Mar 2022 18:25:36 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 PING! Hi, Lei I also take a look at other crypto drivers qat/ccp/hisilicon, they separate akcipher/skcipher algo. If you consider that reusing virtio_crypto_algs_register/unregister seems better, I will try to merge them into a single function. On 2/23/22 6:17 PM, zhenwei pi wrote: > > On 2/18/22 11:12 AM, zhenwei pi wrote: >>>> +void virtio_crypto_akcipher_algs_unregister(struct virtio_crypto >>>> +*vcrypto) { >>>> +    int i = 0; >>>> + >>>> +    mutex_lock(&algs_lock); >>>> + >>>> +    for (i = 0; i < ARRAY_SIZE(virtio_crypto_akcipher_algs); i++) { >>>> +        uint32_t service = virtio_crypto_akcipher_algs[i].service; >>>> +        uint32_t algonum = virtio_crypto_akcipher_algs[i].algonum; >>>> + >>>> +        if (virtio_crypto_akcipher_algs[i].active_devs == 0 || >>>> +            !virtcrypto_algo_is_supported(vcrypto, service, algonum)) >>>> +            continue; >>>> + >>>> +        if (virtio_crypto_akcipher_algs[i].active_devs == 1) >>>> + >>>>     crypto_unregister_akcipher(&virtio_crypto_akcipher_algs[i].algo); >>>> + >>>> +        virtio_crypto_akcipher_algs[i].active_devs--; >>>> +    } >>>> + >>>> +    mutex_unlock(&algs_lock); >>>> +} >>> >>> Why don't you reuse the virtio_crypto_algs_register/unregister >>> functions? >>> The current code is too repetitive. Maybe we don't need create the >>> new file virtio_crypto_akcipher_algo.c >>> because we had virtio_crypto_algs.c which includes all algorithms. >>> >> >> Yes, this looks similar to virtio_crypto_algs_register/unregister. >> >> Let's look at the difference: >> struct virtio_crypto_akcipher_algo { >>          uint32_t algonum; >>          uint32_t service; >>          unsigned int active_devs; >>          struct akcipher_alg algo; >> }; >> >> struct virtio_crypto_algo { >>          uint32_t algonum; >>          uint32_t service; >>          unsigned int active_devs; >>          struct skcipher_alg algo; /* akcipher_alg VS skcipher_alg */ >> }; >> >> If reusing virtio_crypto_algs_register/unregister, we need to modify >> the data structure like this: >> struct virtio_crypto_akcipher_algo { >>          uint32_t algonum; >>          uint32_t service;    /* use service to distinguish >> akcipher/skcipher */ >>          unsigned int active_devs; >>      union { >>          struct skcipher_alg skcipher; >>              struct akcipher_alg akcipher; >>      } alg; >> }; >> >> int virtio_crypto_akcipher_algs_register(struct virtio_crypto *vcrypto) >> { >>      ... >>          for (i = 0; i < ARRAY_SIZE(virtio_crypto_akcipher_algs); i++) { >>                  uint32_t service = >> virtio_crypto_akcipher_algs[i].service; >>          ... >>          /* test service type then call >> crypto_register_akcipher/crypto_register_skcipher */ >>                  if (service == VIRTIO_CRYPTO_SERVICE_AKCIPHER) >> crypto_register_akcipher(&virtio_crypto_akcipher_algs[i].algo.akcipher); >>          else >> crypto_register_skcipher(&virtio_crypto_skcipher_algs[i].algo.skcipher); >>          ... >>          } >>      ... >> } >> >> Also test service type and call >> crypto_unregister_skcipher/crypto_unregister_akcipher. >> >> This gets unclear from current v2 version. >> >> On the other hand, the kernel side prefers to separate skcipher and >> akcipher(separated header files and implementations). >> > -- zhenwei pi