Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp944010pxb; Thu, 17 Feb 2022 19:16:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJx7xJWYDiXKAtp6VRXMLM12j6vkpxjK6VZFtcb3PiHxeBqjvhErDUZ36vh0RKOeXvsT7Gg0 X-Received: by 2002:a17:90b:4b12:b0:1b9:8932:d47c with SMTP id lx18-20020a17090b4b1200b001b98932d47cmr10695291pjb.50.1645154180767; Thu, 17 Feb 2022 19:16:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645154180; cv=none; d=google.com; s=arc-20160816; b=Ucq3Q8nva+OeHXnUtSaEdYfOKiksQxBFEFI4yCXxs9TMuF05CX0iZwnQFNO0vBqGZS k6bPfe/sTHUKPINDtlNa1UvzTzV0BpyGBu8wT39n/sWdH+l4pjRGht/N/6iXpQWplk3I tnBoLJLPb05vCGC/UgEa6pRHWM8CY3KBl+b+VNEL0buGG5ofZIz1cenzNdx19FS6cSfJ mnt9m+0MuW54ecAL9plmqVTYaaLP4yfxLxrDY0EkEBxoRSz9HabmEJw2gOKSRCcmOtB7 Fs8u2fImj7BuLXB/AaQu7DcpQD727xZxGJ9vFKSvfWkdTH/R9CH4N2/6fK2OQ7bHVOY6 1UVQ== 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:from:references :cc:to:subject:dkim-signature; bh=Cvti9DbyWYs8dMjlWXIsVfLl8mOEd5qxZxKU5ZS8qhM=; b=jlN2cZKJTTXCzUbHbieS47vY/C4EiAlHgqdXSug70maNRNNLLBm2M5d9bew3WaCeJ9 4PYl8Jpx+c/4E99j4x9NrwFeOI8tUIQP4WE3/jTH8GoPSqoGl22lil3cZxEVMfhFYJtq ONjst7cz2zXUQFBwlJJTcud8NhD47H0ePpu7VcR4zIfpXQC2CP3Lm9JUErMDN0x5sgVT HB7zsWr2H8dlJehsWlZc1sM7A4PIrZ5xjmk5T0gOayuWrDJVW8bJtINkwKDluNTV/IZL igkL/IoyOgbOypQrscOwMmY2dQ23KUrZ2pCh0eNlb1/EYfPxT2VvaE3TJyL1zeUtRl+B cFRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b="EnqUrDW/"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id ml1si2373993pjb.86.2022.02.17.19.16.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Feb 2022 19:16:20 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b="EnqUrDW/"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 158C11C00CE; Thu, 17 Feb 2022 19:15:57 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232003AbiBRDQJ (ORCPT + 99 others); Thu, 17 Feb 2022 22:16:09 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:59780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231932AbiBRDP6 (ORCPT ); Thu, 17 Feb 2022 22:15:58 -0500 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE72F1BBF61 for ; Thu, 17 Feb 2022 19:15:42 -0800 (PST) Received: by mail-pf1-x435.google.com with SMTP id y11so1281078pfa.6 for ; Thu, 17 Feb 2022 19:15:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=Cvti9DbyWYs8dMjlWXIsVfLl8mOEd5qxZxKU5ZS8qhM=; b=EnqUrDW/nfup+NhWajLnkDWhSOvmFoQK+dIo4ycSZlbsaVZJQ3toa0sV/8PDtLpVtc Ua0hdYljmfKvlJdq+WpMj2cGgilXh8rXHSlRESdUebGxMXfw/A205qgyBOIEVWv+4brN NG9GiLi0ZFqeHR/zxleMZYNtBDRe15bxJfg3g6yujkyJ6YLRflwF2dEv+AXmhyQvEDPx iaqI9kaMr1J66C769SPr6XBkLO0cER66YfEcxLJ/YbkQLScKp1HiLAfpbDFm2hc6/00x Iij4aCq5PBkd0bXF/fU869XzGKcQR0BoA78b38hn4VifEuBUufctF3qushtC1R+qGyZk 9N+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=Cvti9DbyWYs8dMjlWXIsVfLl8mOEd5qxZxKU5ZS8qhM=; b=b+8gP2JEMImwyrVnpojMIUKHpC9yi9z4XilgQYiVB7J0PVAHIMr9TUavKPZ3mSFGq3 vi6EM0mEwUPdBtJz1wQlHWUYAeU77Cf13Kuqq7gMhXqPVehjTc9hyNDfAPUujDG91HsN jvLCWzJHoGsYCQJhqdOM5pzt9BF94UlJewYkkbh0EoS1mfxvhfAxDYkyq1aARCEZWd5E HKLOcV8QTLfKKWJlRsnzplWgyZu9ugJnu9ieO85W6sEc9pigtHj7dvzj5srO33P9CTNo EylMVps/HxIDacRVpoOC0yY+IH9N2q8XHsRg6mAfl8lUczOHkiZJTh0iEHgbzYWiBdH/ Q9Zg== X-Gm-Message-State: AOAM5324CNrVKdAkC3tju67nOplse3UeYTcw+W4VmKbQfGMQI57CDp2O AtmtSTH8gjzcyXZzeDr5cyo84g== X-Received: by 2002:a63:f90e:0:b0:373:da89:c0bd with SMTP id h14-20020a63f90e000000b00373da89c0bdmr462001pgi.135.1645154142317; Thu, 17 Feb 2022 19:15:42 -0800 (PST) Received: from [10.76.15.169] ([61.120.150.76]) by smtp.gmail.com with ESMTPSA id m19sm929643pfk.215.2022.02.17.19.15.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 17 Feb 2022 19:15:41 -0800 (PST) Subject: Re: RE: [PATCH v2 3/3] virtio-crypto: implement RSA algorithm 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> From: zhenwei pi Message-ID: <8ef2f660-bd84-de70-1539-402c73795dfe@bytedance.com> Date: Fri, 18 Feb 2022 11:12:51 +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: 7bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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-kernel@vger.kernel.org >> +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