Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp419613pxm; Wed, 23 Feb 2022 03:24:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJz7bcX5gkKkn+JNe/nFB8Ts6BUw6E7ez/iRoDFW5/znH7sc3MV3xwonYv8Z5mR4rLmvH4NL X-Received: by 2002:a17:902:7b81:b0:14f:1b7e:c83c with SMTP id w1-20020a1709027b8100b0014f1b7ec83cmr27362891pll.119.1645615464506; Wed, 23 Feb 2022 03:24:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645615464; cv=none; d=google.com; s=arc-20160816; b=sDg04P57jWuf7v3D6L4W82GYOM5F5Ao2QYH3nfkaqG+Brow1vdN40CgE5yWATC6GZ5 lxA2FgsPPAdS/NWsS5vopZhpo7LmXMXuHJXPD5nc6YjVY3J/zPWOk8mima1+Uq2ReU+3 QzndYrJ+ZntJ4xIniKRixUW5qn8/bN+JvfdnIm03eSFyQK7+fekARtLT5Yj8RFW5zrpF hesGredXk/0hgEuAii42EKAcHcAzu0Ccc51c6Jqpa2RVSAQlBtEBExBp8lVSqIhpX8Jd EabOLYNP+zGOiDFvrnXf/P5OvB61unvK+cKLJeLyQ8fvPYfIdndr7radLB0los9W9Xqn +RWg== 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=DQX7V52CBiJ7FddDejeLAMem+iUAD4nV8smE6+HMiCk=; b=ZHz/bcFqRQnK1GbWj7s8AqeYZsp0FD4ES/XuXyZiIQDFevAQlmCxPyCOZ0F2u5WCSX 2B71zRliQ74dask77DjTm5EvyCa5HNkRo9WhQY0OMSvZPs8q96I35ow6zqfrkkJZwqfe /+Qv9pco9y39DB75kBd57Kt2Eh7kLzztPn75D33mo9bj8L6ezq5EJEnrxcwkjnXj8opG +UC0PXpuJm5zF7oLvUU755CAFiaoriNLEukUAJ8axGdUNXGrF8HA6tq4JxPihQrKKhca X+LWKJbq1QmRTJez3gPnTP9w7ahXcHR9np/NMiiWGfRudHnghPU0P7jCAEyCGm1/CnUI J99Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=nN41YCVI; 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 u2si14744695pfg.207.2022.02.23.03.23.48; Wed, 23 Feb 2022 03:24:24 -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=nN41YCVI; 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 S239577AbiBWKUm (ORCPT + 99 others); Wed, 23 Feb 2022 05:20:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236653AbiBWKUm (ORCPT ); Wed, 23 Feb 2022 05:20:42 -0500 Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A40F58BF67 for ; Wed, 23 Feb 2022 02:20:14 -0800 (PST) Received: by mail-pg1-x52d.google.com with SMTP id f8so19481599pgc.8 for ; Wed, 23 Feb 2022 02:20:14 -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=DQX7V52CBiJ7FddDejeLAMem+iUAD4nV8smE6+HMiCk=; b=nN41YCVInSLt/JhZi7jK4UIpYreHneBcjM9jaq1ZZoxJ1/HvTSNw/17hZcv+kDyYd6 +REnkeyTUgx0AmMKdy+VTVlBINeBfEKvrtvRYmlTs9AgmnLtJF9qZixJ3s5pQNss0vs6 zVZe/dXo1+NnSdrdMA9wcfg6nXb7vGWJxV6I5T0J6PkmWpN0YNnb6zjvCoCr935RSum7 Y2LQBdU3OuNnflCdHskASMBzdNDYIplLTdH793XbTrZvH4nak4d7jYpjPCz/3Z2V+Mar 9jB/QwBi/DjewJnn924OyllWj+1kAstpa7J+h5ZalOgqI27LkUHizcD3M1ll6ekNuD3h WfoQ== 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=DQX7V52CBiJ7FddDejeLAMem+iUAD4nV8smE6+HMiCk=; b=oAyznhl7Rc0zjzQXMxdDrVwlTtMrzEyL9trJfvJKFJGCOOyeSlE0MpamBLIKR/sT8a 5OjTOLEspSzgqhgtw3NTOaB3boFsOu4u6+Ht2M0KcrLryXKirhQ5aEItthwrDNtkAeFS q6JYpAg1p7eXUiWjWMenoZrOcOa5BApmyiXznoLRQlvn0Qct2owG/prIse5dXu0Z2pS0 sE26HCeZv+RX4C9Gs+CaPXnEoOW+SMDEaTPbEuk2Tw9mA67/FEroxVE78yZJJJL+dSc0 VE61A332GGeVlMC5QIDKuaEQVBpOtmFebaWCR1qJTPS6EwpVyKg9PxcZDSzn4IQqTl22 Lt9w== X-Gm-Message-State: AOAM533kpV9vu6p3SC7xDI7YbDn65+KBqKjGqHfMHiqRA0jt+qjVMULH lpu+d8RZP/6Ro52SdF7eT38Q1g== X-Received: by 2002:a63:af4b:0:b0:373:a2a1:bf9a with SMTP id s11-20020a63af4b000000b00373a2a1bf9amr23123430pgo.369.1645611614111; Wed, 23 Feb 2022 02:20:14 -0800 (PST) Received: from [10.76.15.169] ([61.120.150.76]) by smtp.gmail.com with ESMTPSA id x64-20020a17090a6c4600b001bc6d235a0esm2496931pjj.1.2022.02.23.02.20.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 23 Feb 2022 02:20:13 -0800 (PST) Subject: Re: [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: Date: Wed, 23 Feb 2022 18:17:21 +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: <8ef2f660-bd84-de70-1539-402c73795dfe@bytedance.com> 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,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,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 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). > Hi, Lei I also take a look at other crypto drivers at 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. -- zhenwei pi