[PATCH v3 0/6] Support akcipher for virtio-crypto

zhenwei pi posted 6 patches 2 years, 1 month ago
Test checkpatch passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20220323024912.249789-1-pizhenwei@bytedance.com
Maintainers: "Gonglei (Arei)" <arei.gonglei@huawei.com>, "Daniel P. Berrangé" <berrange@redhat.com>, "Michael S. Tsirkin" <mst@redhat.com>, Eric Blake <eblake@redhat.com>, Markus Armbruster <armbru@redhat.com>
backends/cryptodev-builtin.c                  | 319 +++++++-
backends/cryptodev-vhost-user.c               |  34 +-
backends/cryptodev.c                          |  32 +-
crypto/akcipher-nettle.c                      | 523 +++++++++++++
crypto/akcipher.c                             |  81 ++
crypto/asn1_decoder.c                         | 185 +++++
crypto/asn1_decoder.h                         |  42 +
crypto/meson.build                            |   4 +
hw/virtio/virtio-crypto.c                     | 326 ++++++--
include/crypto/akcipher.h                     | 155 ++++
include/hw/virtio/virtio-crypto.h             |   5 +-
.../standard-headers/linux/virtio_crypto.h    |  82 +-
include/sysemu/cryptodev.h                    |  88 ++-
meson.build                                   |  11 +
qapi/crypto.json                              |  86 +++
tests/bench/benchmark-crypto-akcipher.c       | 163 ++++
tests/bench/meson.build                       |   6 +
tests/bench/test_akcipher_keys.inc            | 277 +++++++
tests/unit/meson.build                        |   1 +
tests/unit/test-crypto-akcipher.c             | 715 ++++++++++++++++++
20 files changed, 2990 insertions(+), 145 deletions(-)
create mode 100644 crypto/akcipher-nettle.c
create mode 100644 crypto/akcipher.c
create mode 100644 crypto/asn1_decoder.c
create mode 100644 crypto/asn1_decoder.h
create mode 100644 include/crypto/akcipher.h
create mode 100644 tests/bench/benchmark-crypto-akcipher.c
create mode 100644 tests/bench/test_akcipher_keys.inc
create mode 100644 tests/unit/test-crypto-akcipher.c
[PATCH v3 0/6] Support akcipher for virtio-crypto
Posted by zhenwei pi 2 years, 1 month ago
v2 -> v3:
- Introduce akcipher types to qapi
- Add test/benchmark suite for akcipher class
- Seperate 'virtio_crypto: Support virtio crypto asym operation' into:
  - crypto: Introduce akcipher crypto class
  - virtio-crypto: Introduce RSA algorithm

v1 -> v2:
- Update virtio_crypto.h from v2 version of related kernel patch.

v1:
- Support akcipher for virtio-crypto.
- Introduce akcipher class.
- Introduce ASN1 decoder into QEMU.
- Implement RSA backend by nettle/hogweed.

Lei He (3):
  crypto-akcipher: Introduce akcipher types to qapi
  crypto: Implement RSA algorithm by hogweed
  tests/crypto: Add test suite for crypto akcipher

Zhenwei Pi (3):
  virtio-crypto: header update
  crypto: Introduce akcipher crypto class
  virtio-crypto: Introduce RSA algorithm

 backends/cryptodev-builtin.c                  | 319 +++++++-
 backends/cryptodev-vhost-user.c               |  34 +-
 backends/cryptodev.c                          |  32 +-
 crypto/akcipher-nettle.c                      | 523 +++++++++++++
 crypto/akcipher.c                             |  81 ++
 crypto/asn1_decoder.c                         | 185 +++++
 crypto/asn1_decoder.h                         |  42 +
 crypto/meson.build                            |   4 +
 hw/virtio/virtio-crypto.c                     | 326 ++++++--
 include/crypto/akcipher.h                     | 155 ++++
 include/hw/virtio/virtio-crypto.h             |   5 +-
 .../standard-headers/linux/virtio_crypto.h    |  82 +-
 include/sysemu/cryptodev.h                    |  88 ++-
 meson.build                                   |  11 +
 qapi/crypto.json                              |  86 +++
 tests/bench/benchmark-crypto-akcipher.c       | 163 ++++
 tests/bench/meson.build                       |   6 +
 tests/bench/test_akcipher_keys.inc            | 277 +++++++
 tests/unit/meson.build                        |   1 +
 tests/unit/test-crypto-akcipher.c             | 715 ++++++++++++++++++
 20 files changed, 2990 insertions(+), 145 deletions(-)
 create mode 100644 crypto/akcipher-nettle.c
 create mode 100644 crypto/akcipher.c
 create mode 100644 crypto/asn1_decoder.c
 create mode 100644 crypto/asn1_decoder.h
 create mode 100644 include/crypto/akcipher.h
 create mode 100644 tests/bench/benchmark-crypto-akcipher.c
 create mode 100644 tests/bench/test_akcipher_keys.inc
 create mode 100644 tests/unit/test-crypto-akcipher.c

-- 
2.25.1
Re: [PATCH v3 0/6] Support akcipher for virtio-crypto
Posted by Philippe Mathieu-Daudé 2 years, 1 month ago
Cc'ing Daniel & Laurent.

On 23/3/22 03:49, zhenwei pi wrote:
> v2 -> v3:
> - Introduce akcipher types to qapi
> - Add test/benchmark suite for akcipher class
> - Seperate 'virtio_crypto: Support virtio crypto asym operation' into:
>    - crypto: Introduce akcipher crypto class
>    - virtio-crypto: Introduce RSA algorithm
> 
> v1 -> v2:
> - Update virtio_crypto.h from v2 version of related kernel patch.
> 
> v1:
> - Support akcipher for virtio-crypto.
> - Introduce akcipher class.
> - Introduce ASN1 decoder into QEMU.
> - Implement RSA backend by nettle/hogweed.
> 
> Lei He (3):
>    crypto-akcipher: Introduce akcipher types to qapi
>    crypto: Implement RSA algorithm by hogweed
>    tests/crypto: Add test suite for crypto akcipher
> 
> Zhenwei Pi (3):
>    virtio-crypto: header update
>    crypto: Introduce akcipher crypto class
>    virtio-crypto: Introduce RSA algorithm
> 
>   backends/cryptodev-builtin.c                  | 319 +++++++-
>   backends/cryptodev-vhost-user.c               |  34 +-
>   backends/cryptodev.c                          |  32 +-
>   crypto/akcipher-nettle.c                      | 523 +++++++++++++
>   crypto/akcipher.c                             |  81 ++
>   crypto/asn1_decoder.c                         | 185 +++++
>   crypto/asn1_decoder.h                         |  42 +
>   crypto/meson.build                            |   4 +
>   hw/virtio/virtio-crypto.c                     | 326 ++++++--
>   include/crypto/akcipher.h                     | 155 ++++
>   include/hw/virtio/virtio-crypto.h             |   5 +-
>   .../standard-headers/linux/virtio_crypto.h    |  82 +-
>   include/sysemu/cryptodev.h                    |  88 ++-
>   meson.build                                   |  11 +
>   qapi/crypto.json                              |  86 +++
>   tests/bench/benchmark-crypto-akcipher.c       | 163 ++++
>   tests/bench/meson.build                       |   6 +
>   tests/bench/test_akcipher_keys.inc            | 277 +++++++
>   tests/unit/meson.build                        |   1 +
>   tests/unit/test-crypto-akcipher.c             | 715 ++++++++++++++++++
>   20 files changed, 2990 insertions(+), 145 deletions(-)
>   create mode 100644 crypto/akcipher-nettle.c
>   create mode 100644 crypto/akcipher.c
>   create mode 100644 crypto/asn1_decoder.c
>   create mode 100644 crypto/asn1_decoder.h
>   create mode 100644 include/crypto/akcipher.h
>   create mode 100644 tests/bench/benchmark-crypto-akcipher.c
>   create mode 100644 tests/bench/test_akcipher_keys.inc
>   create mode 100644 tests/unit/test-crypto-akcipher.c
>
Re: [PATCH v3 0/6] Support akcipher for virtio-crypto
Posted by Eric Biggers 2 years, 1 month ago
On Wed, Mar 23, 2022 at 10:49:06AM +0800, zhenwei pi wrote:
> v2 -> v3:
> - Introduce akcipher types to qapi
> - Add test/benchmark suite for akcipher class
> - Seperate 'virtio_crypto: Support virtio crypto asym operation' into:
>   - crypto: Introduce akcipher crypto class
>   - virtio-crypto: Introduce RSA algorithm
> 
> v1 -> v2:
> - Update virtio_crypto.h from v2 version of related kernel patch.
> 
> v1:
> - Support akcipher for virtio-crypto.
> - Introduce akcipher class.
> - Introduce ASN1 decoder into QEMU.
> - Implement RSA backend by nettle/hogweed.
> 
> Lei He (3):
>   crypto-akcipher: Introduce akcipher types to qapi
>   crypto: Implement RSA algorithm by hogweed
>   tests/crypto: Add test suite for crypto akcipher
> 
> Zhenwei Pi (3):
>   virtio-crypto: header update
>   crypto: Introduce akcipher crypto class
>   virtio-crypto: Introduce RSA algorithm

You forgot to describe the point of this patchset and what its use case is.
Like any other Linux kernel patchset, that needs to be in the cover letter.

- Eric
Re: Re: [PATCH v3 0/6] Support akcipher for virtio-crypto
Posted by zhenwei pi 2 years, 1 month ago
On 3/23/22 13:17, Eric Biggers wrote:
> On Wed, Mar 23, 2022 at 10:49:06AM +0800, zhenwei pi wrote:
>> v2 -> v3:
>> - Introduce akcipher types to qapi
>> - Add test/benchmark suite for akcipher class
>> - Seperate 'virtio_crypto: Support virtio crypto asym operation' into:
>>    - crypto: Introduce akcipher crypto class
>>    - virtio-crypto: Introduce RSA algorithm
>>
>> v1 -> v2:
>> - Update virtio_crypto.h from v2 version of related kernel patch.
>>
>> v1:
>> - Support akcipher for virtio-crypto.
>> - Introduce akcipher class.
>> - Introduce ASN1 decoder into QEMU.
>> - Implement RSA backend by nettle/hogweed.
>>
>> Lei He (3):
>>    crypto-akcipher: Introduce akcipher types to qapi
>>    crypto: Implement RSA algorithm by hogweed
>>    tests/crypto: Add test suite for crypto akcipher
>>
>> Zhenwei Pi (3):
>>    virtio-crypto: header update
>>    crypto: Introduce akcipher crypto class
>>    virtio-crypto: Introduce RSA algorithm
> 
> You forgot to describe the point of this patchset and what its use case is.
> Like any other Linux kernel patchset, that needs to be in the cover letter.
> 
> - Eric
Thanks Eric for pointing this missing part.

This feature provides akcipher service offloading capability. QEMU side 
handles asymmetric requests via virtio-crypto devices from guest side, 
do encrypt/decrypt/sign/verify operations on host side, and return the 
result to guest.

This patchset implements a RSA backend by hogweed from nettle, it works 
together with guest patch:
https://lkml.org/lkml/2022/3/1/1425

-- 
zhenwei pi
Re: Re: [PATCH v3 0/6] Support akcipher for virtio-crypto
Posted by Eric Biggers 2 years, 1 month ago
On Wed, Mar 23, 2022 at 03:32:37PM +0800, zhenwei pi wrote:
> 
> On 3/23/22 13:17, Eric Biggers wrote:
> > On Wed, Mar 23, 2022 at 10:49:06AM +0800, zhenwei pi wrote:
> > > v2 -> v3:
> > > - Introduce akcipher types to qapi
> > > - Add test/benchmark suite for akcipher class
> > > - Seperate 'virtio_crypto: Support virtio crypto asym operation' into:
> > >    - crypto: Introduce akcipher crypto class
> > >    - virtio-crypto: Introduce RSA algorithm
> > > 
> > > v1 -> v2:
> > > - Update virtio_crypto.h from v2 version of related kernel patch.
> > > 
> > > v1:
> > > - Support akcipher for virtio-crypto.
> > > - Introduce akcipher class.
> > > - Introduce ASN1 decoder into QEMU.
> > > - Implement RSA backend by nettle/hogweed.
> > > 
> > > Lei He (3):
> > >    crypto-akcipher: Introduce akcipher types to qapi
> > >    crypto: Implement RSA algorithm by hogweed
> > >    tests/crypto: Add test suite for crypto akcipher
> > > 
> > > Zhenwei Pi (3):
> > >    virtio-crypto: header update
> > >    crypto: Introduce akcipher crypto class
> > >    virtio-crypto: Introduce RSA algorithm
> > 
> > You forgot to describe the point of this patchset and what its use case is.
> > Like any other Linux kernel patchset, that needs to be in the cover letter.
> > 
> > - Eric
> Thanks Eric for pointing this missing part.
> 
> This feature provides akcipher service offloading capability. QEMU side
> handles asymmetric requests via virtio-crypto devices from guest side, do
> encrypt/decrypt/sign/verify operations on host side, and return the result
> to guest.
> 
> This patchset implements a RSA backend by hogweed from nettle, it works
> together with guest patch:
> https://lkml.org/lkml/2022/3/1/1425

So what is the use case?

- Eric
Re: Re: Re: [PATCH v3 0/6] Support akcipher for virtio-crypto
Posted by zhenwei pi 2 years, 1 month ago
On 3/24/22 02:03, Eric Biggers wrote:
> On Wed, Mar 23, 2022 at 03:32:37PM +0800, zhenwei pi wrote:
>>
>> On 3/23/22 13:17, Eric Biggers wrote:
>>> On Wed, Mar 23, 2022 at 10:49:06AM +0800, zhenwei pi wrote:
>>>> v2 -> v3:
>>>> - Introduce akcipher types to qapi
>>>> - Add test/benchmark suite for akcipher class
>>>> - Seperate 'virtio_crypto: Support virtio crypto asym operation' into:
>>>>     - crypto: Introduce akcipher crypto class
>>>>     - virtio-crypto: Introduce RSA algorithm
>>>>
>>>> v1 -> v2:
>>>> - Update virtio_crypto.h from v2 version of related kernel patch.
>>>>
>>>> v1:
>>>> - Support akcipher for virtio-crypto.
>>>> - Introduce akcipher class.
>>>> - Introduce ASN1 decoder into QEMU.
>>>> - Implement RSA backend by nettle/hogweed.
>>>>
>>>> Lei He (3):
>>>>     crypto-akcipher: Introduce akcipher types to qapi
>>>>     crypto: Implement RSA algorithm by hogweed
>>>>     tests/crypto: Add test suite for crypto akcipher
>>>>
>>>> Zhenwei Pi (3):
>>>>     virtio-crypto: header update
>>>>     crypto: Introduce akcipher crypto class
>>>>     virtio-crypto: Introduce RSA algorithm
>>>
>>> You forgot to describe the point of this patchset and what its use case is.
>>> Like any other Linux kernel patchset, that needs to be in the cover letter.
>>>
>>> - Eric
>> Thanks Eric for pointing this missing part.
>>
>> This feature provides akcipher service offloading capability. QEMU side
>> handles asymmetric requests via virtio-crypto devices from guest side, do
>> encrypt/decrypt/sign/verify operations on host side, and return the result
>> to guest.
>>
>> This patchset implements a RSA backend by hogweed from nettle, it works
>> together with guest patch:
>> https://lkml.org/lkml/2022/3/1/1425
> 
> So what is the use case?
> 
> - Eric
Hi,

In our plan, the feature is designed for HTTPS offloading case and other 
applications which use kernel RSA/ecdsa by keyctl syscall. The full 
picture shows bellow:


                   Nginx/openssl[1] ... Apps
Guest   -----------------------------------------
                    virtio-crypto driver[2]
-------------------------------------------------
                    virtio-crypto backend[3]
Host    -----------------------------------------
                   /          |          \
               builtin[4]   vhost     keyctl[5] ...


[1] User applications can offload RSA calculation to kernel by keyctl 
syscall. There is no keyctl engine in openssl currently, we developed a 
engine and tried to contribute it to openssl upstream, but openssl 1.x 
does not accept new feature. Link:
	https://github.com/openssl/openssl/pull/16689

This branch is available and maintained by Lei <helei.sig11@bytedance.com>
	https://github.com/TousakaRin/openssl/tree/OpenSSL_1_1_1-kctl_engine

We tested nginx(change config file only) with openssl keyctl engine, it 
works fine.

[2] virtio-crypto driver is used to communicate with host side, send 
requests to host side to do asymmetric calculation.
	https://lkml.org/lkml/2022/3/1/1425

[3] virtio-crypto backend handles requests from guest side, and forwards 
request to crypto backend driver of QEMU.

[4] Currently RSA is supported only in builtin driver. This driver is 
supposed to test the full feature without other software(Ex vhost 
process) and hardware dependence. ecdsa is introduced into qapi type 
without implementation, this may be implemented in Q3-2022 or later. If 
ecdsa type definition should be added with the implementation together, 
I'll remove this in next version.

[5] keyctl backend is in development, we will post this feature in 
Q2-2022. keyctl backend can use hardware acceleration(Ex, Intel QAT).

Setup the full environment, tested with Intel QAT on host side, the QPS 
of HTTPS increase to ~200% in a guest.

VS PCI passthrough: the most important benefit of this solution makes 
the VM migratable.

-- 
zhenwei pi
Re: [PATCH v3 0/6] Support akcipher for virtio-crypto
Posted by Michael S. Tsirkin 2 years, 1 month ago
On Wed, Mar 23, 2022 at 10:49:06AM +0800, zhenwei pi wrote:
> v2 -> v3:
> - Introduce akcipher types to qapi
> - Add test/benchmark suite for akcipher class
> - Seperate 'virtio_crypto: Support virtio crypto asym operation' into:
>   - crypto: Introduce akcipher crypto class
>   - virtio-crypto: Introduce RSA algorithm

Thanks!
I tagged this but qemu is in freeze. If possible pls ping or
repost after the release to help make sure I don't lose it.

> v1 -> v2:
> - Update virtio_crypto.h from v2 version of related kernel patch.
> 
> v1:
> - Support akcipher for virtio-crypto.
> - Introduce akcipher class.
> - Introduce ASN1 decoder into QEMU.
> - Implement RSA backend by nettle/hogweed.
> 
> Lei He (3):
>   crypto-akcipher: Introduce akcipher types to qapi
>   crypto: Implement RSA algorithm by hogweed
>   tests/crypto: Add test suite for crypto akcipher
> 
> Zhenwei Pi (3):
>   virtio-crypto: header update
>   crypto: Introduce akcipher crypto class
>   virtio-crypto: Introduce RSA algorithm
> 
>  backends/cryptodev-builtin.c                  | 319 +++++++-
>  backends/cryptodev-vhost-user.c               |  34 +-
>  backends/cryptodev.c                          |  32 +-
>  crypto/akcipher-nettle.c                      | 523 +++++++++++++
>  crypto/akcipher.c                             |  81 ++
>  crypto/asn1_decoder.c                         | 185 +++++
>  crypto/asn1_decoder.h                         |  42 +
>  crypto/meson.build                            |   4 +
>  hw/virtio/virtio-crypto.c                     | 326 ++++++--
>  include/crypto/akcipher.h                     | 155 ++++
>  include/hw/virtio/virtio-crypto.h             |   5 +-
>  .../standard-headers/linux/virtio_crypto.h    |  82 +-
>  include/sysemu/cryptodev.h                    |  88 ++-
>  meson.build                                   |  11 +
>  qapi/crypto.json                              |  86 +++
>  tests/bench/benchmark-crypto-akcipher.c       | 163 ++++
>  tests/bench/meson.build                       |   6 +
>  tests/bench/test_akcipher_keys.inc            | 277 +++++++
>  tests/unit/meson.build                        |   1 +
>  tests/unit/test-crypto-akcipher.c             | 715 ++++++++++++++++++
>  20 files changed, 2990 insertions(+), 145 deletions(-)
>  create mode 100644 crypto/akcipher-nettle.c
>  create mode 100644 crypto/akcipher.c
>  create mode 100644 crypto/asn1_decoder.c
>  create mode 100644 crypto/asn1_decoder.h
>  create mode 100644 include/crypto/akcipher.h
>  create mode 100644 tests/bench/benchmark-crypto-akcipher.c
>  create mode 100644 tests/bench/test_akcipher_keys.inc
>  create mode 100644 tests/unit/test-crypto-akcipher.c
> 
> -- 
> 2.25.1
Re: Re: [PATCH v3 0/6] Support akcipher for virtio-crypto
Posted by zhenwei pi 2 years, 1 month ago
On 3/23/22 20:36, Michael S. Tsirkin wrote:
> On Wed, Mar 23, 2022 at 10:49:06AM +0800, zhenwei pi wrote:
>> v2 -> v3:
>> - Introduce akcipher types to qapi
>> - Add test/benchmark suite for akcipher class
>> - Seperate 'virtio_crypto: Support virtio crypto asym operation' into:
>>    - crypto: Introduce akcipher crypto class
>>    - virtio-crypto: Introduce RSA algorithm
> 
> Thanks!
> I tagged this but qemu is in freeze. If possible pls ping or
> repost after the release to help make sure I don't lose it.
> 
Hi,

Daniel has started to review this patchset, according to Daniel's 
important suggestion, I'll rework this feature and post the next version 
later.

Thanks a lot!

-- 
zhenwei pi