<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel/drivers/crypto/virtio/virtio_crypto_skcipher_algs.c, branch linux-rolling-stable</title>
<subtitle>Hosts the 0x221E linux distro kernel.</subtitle>
<id>https://universe.0xinfinity.dev/distro/kernel/atom?h=linux-rolling-stable</id>
<link rel='self' href='https://universe.0xinfinity.dev/distro/kernel/atom?h=linux-rolling-stable'/>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/'/>
<updated>2026-02-16T09:19:44Z</updated>
<entry>
<title>crypto: virtio - Remove duplicated virtqueue_kick in virtio_crypto_skcipher_crypt_req</title>
<updated>2026-02-16T09:19:44Z</updated>
<author>
<name>Bibo Mao</name>
<email>maobibo@loongson.cn</email>
</author>
<published>2026-01-13T03:05:55Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=52505d7f713bff9b3e2e04a63adcacf1ded62a45'/>
<id>urn:sha1:52505d7f713bff9b3e2e04a63adcacf1ded62a45</id>
<content type='text'>
commit 14f86a1155cca1176abf55987b2fce7f7fcb2455 upstream.

With function virtio_crypto_skcipher_crypt_req(), there is already
virtqueue_kick() call with spinlock held in function
__virtio_crypto_skcipher_do_req(). Remove duplicated virtqueue_kick()
function call here.

Fixes: d79b5d0bbf2e ("crypto: virtio - support crypto engine framework")
Cc: stable@vger.kernel.org
Signed-off-by: Bibo Mao &lt;maobibo@loongson.cn&gt;
Acked-by: Jason Wang &lt;jasowang@redhat.com&gt;
Acked-by: Michael S. Tsirkin &lt;mst@redhat.com&gt;
Signed-off-by: Herbert Xu &lt;herbert@gondor.apana.org.au&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>crypto: virtio - Drop superfluous [as]kcipher_req pointer</title>
<updated>2025-02-22T07:56:02Z</updated>
<author>
<name>Lukas Wunner</name>
<email>lukas@wunner.de</email>
</author>
<published>2025-02-03T13:37:05Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=62d027fb49c76475c5256ab69059752f42c3730f'/>
<id>urn:sha1:62d027fb49c76475c5256ab69059752f42c3730f</id>
<content type='text'>
The request context virtio_crypto_{akcipher,sym}_request contains a
pointer to the [as]kcipher_request itself.

The pointer is superfluous as it can be calculated with container_of().

Drop the superfluous pointer.

Signed-off-by: Lukas Wunner &lt;lukas@wunner.de&gt;
Signed-off-by: Herbert Xu &lt;herbert@gondor.apana.org.au&gt;
</content>
</entry>
<entry>
<title>crypto: virtio - Drop superfluous [as]kcipher_ctx pointer</title>
<updated>2025-02-22T07:56:02Z</updated>
<author>
<name>Lukas Wunner</name>
<email>lukas@wunner.de</email>
</author>
<published>2025-02-03T13:37:04Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=dc91d858fb9251b25828ab63ac7220145cef282c'/>
<id>urn:sha1:dc91d858fb9251b25828ab63ac7220145cef282c</id>
<content type='text'>
The request context virtio_crypto_{akcipher,sym}_request contains a
pointer to the transform context virtio_crypto_[as]kcipher_ctx.

The pointer is superfluous as it can be calculated with the cheap
crypto_akcipher_reqtfm() + akcipher_tfm_ctx() and
crypto_skcipher_reqtfm() + crypto_skcipher_ctx() combos.

Drop the superfluous pointer.

Signed-off-by: Lukas Wunner &lt;lukas@wunner.de&gt;
Signed-off-by: Herbert Xu &lt;herbert@gondor.apana.org.au&gt;
</content>
</entry>
<entry>
<title>crypto: virtio - Drop superfluous ctx-&gt;tfm backpointer</title>
<updated>2025-02-22T07:56:02Z</updated>
<author>
<name>Lukas Wunner</name>
<email>lukas@wunner.de</email>
</author>
<published>2025-02-03T13:37:03Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=aefeca1188962da52e3ed35ddb865d37a216dd53'/>
<id>urn:sha1:aefeca1188962da52e3ed35ddb865d37a216dd53</id>
<content type='text'>
struct virtio_crypto_[as]kcipher_ctx contains a backpointer to struct
crypto_[as]kcipher which is superfluous in two ways:

First, it's not used anywhere.  Second, the context is embedded into
struct crypto_tfm, so one could just use container_of() to get from the
context to crypto_tfm and from there to crypto_[as]kcipher.

Drop the superfluous backpointer.

Signed-off-by: Lukas Wunner &lt;lukas@wunner.de&gt;
Signed-off-by: Herbert Xu &lt;herbert@gondor.apana.org.au&gt;
</content>
</entry>
<entry>
<title>crypto: virtio - Use new crypto_engine_op interface</title>
<updated>2023-08-18T09:01:11Z</updated>
<author>
<name>Herbert Xu</name>
<email>herbert@gondor.apana.org.au</email>
</author>
<published>2023-08-13T06:55:16Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=7a2673d70ca69bb890dc0fec590297f5aa7da739'/>
<id>urn:sha1:7a2673d70ca69bb890dc0fec590297f5aa7da739</id>
<content type='text'>
Use the new crypto_engine_op interface where the callback is stored
in the algorithm object.

Signed-off-by: Herbert Xu &lt;herbert@gondor.apana.org.au&gt;
</content>
</entry>
<entry>
<title>crypto: virtio - Remove prepare/unprepare request</title>
<updated>2023-08-18T09:01:10Z</updated>
<author>
<name>Herbert Xu</name>
<email>herbert@gondor.apana.org.au</email>
</author>
<published>2023-08-13T06:54:28Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=fc0bdcb8303b70bc0c1b5fbf236a4882f254cf94'/>
<id>urn:sha1:fc0bdcb8303b70bc0c1b5fbf236a4882f254cf94</id>
<content type='text'>
The callbacks for prepare and unprepare request in crypto_engine
is superfluous.  They can be done directly from do_one_request.

Move the code into do_one_request and remove the unused callbacks.

Signed-off-by: Herbert Xu &lt;herbert@gondor.apana.org.au&gt;
</content>
</entry>
<entry>
<title>virtio-crypto: fix memory leak in virtio_crypto_alg_skcipher_close_session()</title>
<updated>2022-12-28T10:28:10Z</updated>
<author>
<name>Wei Yongjun</name>
<email>weiyongjun1@huawei.com</email>
</author>
<published>2022-11-14T11:07:40Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=b1d65f717cd6305a396a8738e022c6f7c65cfbe8'/>
<id>urn:sha1:b1d65f717cd6305a396a8738e022c6f7c65cfbe8</id>
<content type='text'>
'vc_ctrl_req' is alloced in virtio_crypto_alg_skcipher_close_session(),
and should be freed in the invalid ctrl_status-&gt;status error handling
case. Otherwise there is a memory leak.

Fixes: 0756ad15b1fe ("virtio-crypto: use private buffer for control request")
Signed-off-by: Wei Yongjun &lt;weiyongjun1@huawei.com&gt;
Message-Id: &lt;20221114110740.537276-1-weiyongjun@huaweicloud.com&gt;
Signed-off-by: Michael S. Tsirkin &lt;mst@redhat.com&gt;
Reviewed-by: Gonglei &lt;arei.gonglei@huawei.com&gt;
Acked-by: zhenwei pi&lt;pizhenwei@bytedance.com&gt;
Acked-by: Jason Wang &lt;jasowang@redhat.com&gt;
</content>
</entry>
<entry>
<title>virtio-crypto: wait ctrl queue instead of busy polling</title>
<updated>2022-05-31T16:45:09Z</updated>
<author>
<name>zhenwei pi</name>
<email>pizhenwei@bytedance.com</email>
</author>
<published>2022-05-06T13:16:25Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=977231e8d45657871a86fe3c7bed94921d04e447'/>
<id>urn:sha1:977231e8d45657871a86fe3c7bed94921d04e447</id>
<content type='text'>
Originally, after submitting request into virtio crypto control
queue, the guest side polls the result from the virt queue. This
works like following:
    CPU0   CPU1               ...             CPUx  CPUy
     |      |                                  |     |
     \      \                                  /     /
      \--------spin_lock(&amp;vcrypto-&gt;ctrl_lock)-------/
                           |
                 virtqueue add &amp; kick
                           |
                  busy poll virtqueue
                           |
              spin_unlock(&amp;vcrypto-&gt;ctrl_lock)
                          ...

There are two problems:
1, The queue depth is always 1, the performance of a virtio crypto
   device gets limited. Multi user processes share a single control
   queue, and hit spin lock race from control queue. Test on Intel
   Platinum 8260, a single worker gets ~35K/s create/close session
   operations, and 8 workers get ~40K/s operations with 800% CPU
   utilization.
2, The control request is supposed to get handled immediately, but
   in the current implementation of QEMU(v6.2), the vCPU thread kicks
   another thread to do this work, the latency also gets unstable.
   Tracking latency of virtio_crypto_alg_akcipher_close_session in 5s:
        usecs               : count     distribution
         0 -&gt; 1          : 0        |                        |
         2 -&gt; 3          : 7        |                        |
         4 -&gt; 7          : 72       |                        |
         8 -&gt; 15         : 186485   |************************|
        16 -&gt; 31         : 687      |                        |
        32 -&gt; 63         : 5        |                        |
        64 -&gt; 127        : 3        |                        |
       128 -&gt; 255        : 1        |                        |
       256 -&gt; 511        : 0        |                        |
       512 -&gt; 1023       : 0        |                        |
      1024 -&gt; 2047       : 0        |                        |
      2048 -&gt; 4095       : 0        |                        |
      4096 -&gt; 8191       : 0        |                        |
      8192 -&gt; 16383      : 2        |                        |
This means that a CPU may hold vcrypto-&gt;ctrl_lock as long as 8192~16383us.

To improve the performance of control queue, a request on control queue
waits completion instead of busy polling to reduce lock racing, and gets
completed by control queue callback.
    CPU0   CPU1               ...             CPUx  CPUy
     |      |                                  |     |
     \      \                                  /     /
      \--------spin_lock(&amp;vcrypto-&gt;ctrl_lock)-------/
                           |
                 virtqueue add &amp; kick
                           |
      ---------spin_unlock(&amp;vcrypto-&gt;ctrl_lock)------
     /      /                                  \     \
     |      |                                  |     |
    wait   wait                               wait  wait

Test this patch, the guest side get ~200K/s operations with 300% CPU
utilization.

Cc: Michael S. Tsirkin &lt;mst@redhat.com&gt;
Cc: Jason Wang &lt;jasowang@redhat.com&gt;
Cc: Gonglei &lt;arei.gonglei@huawei.com&gt;
Reviewed-by: Gonglei &lt;arei.gonglei@huawei.com&gt;
Signed-off-by: zhenwei pi &lt;pizhenwei@bytedance.com&gt;
Message-Id: &lt;20220506131627.180784-4-pizhenwei@bytedance.com&gt;
Signed-off-by: Michael S. Tsirkin &lt;mst@redhat.com&gt;
</content>
</entry>
<entry>
<title>virtio-crypto: use private buffer for control request</title>
<updated>2022-05-31T16:45:09Z</updated>
<author>
<name>zhenwei pi</name>
<email>pizhenwei@bytedance.com</email>
</author>
<published>2022-05-06T13:16:24Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=0756ad15b1fef287d4d8fa11bc36ea77a5c42e4a'/>
<id>urn:sha1:0756ad15b1fef287d4d8fa11bc36ea77a5c42e4a</id>
<content type='text'>
Originally, all of the control requests share a single buffer(
ctrl &amp; input &amp; ctrl_status fields in struct virtio_crypto), this
allows queue depth 1 only, the performance of control queue gets
limited by this design.

In this patch, each request allocates request buffer dynamically, and
free buffer after request, so the scope protected by ctrl_lock also
get optimized here.
It's possible to optimize control queue depth in the next step.

A necessary comment is already in code, still describe it again:
/*
 * Note: there are padding fields in request, clear them to zero before
 * sending to host to avoid to divulge any information.
 * Ex, virtio_crypto_ctrl_request::ctrl::u::destroy_session::padding[48]
 */
So use kzalloc to allocate buffer of struct virtio_crypto_ctrl_request.

Potentially dereferencing uninitialized variables:
Reported-by: kernel test robot &lt;lkp@intel.com&gt;
Reported-by: Dan Carpenter &lt;dan.carpenter@oracle.com&gt;

Cc: Michael S. Tsirkin &lt;mst@redhat.com&gt;
Cc: Jason Wang &lt;jasowang@redhat.com&gt;
Cc: Gonglei &lt;arei.gonglei@huawei.com&gt;
Reviewed-by: Gonglei &lt;arei.gonglei@huawei.com&gt;
Signed-off-by: zhenwei pi &lt;pizhenwei@bytedance.com&gt;
Message-Id: &lt;20220506131627.180784-3-pizhenwei@bytedance.com&gt;
Signed-off-by: Michael S. Tsirkin &lt;mst@redhat.com&gt;
</content>
</entry>
<entry>
<title>virtio-crypto: change code style</title>
<updated>2022-05-31T16:45:08Z</updated>
<author>
<name>zhenwei pi</name>
<email>pizhenwei@bytedance.com</email>
</author>
<published>2022-05-06T13:16:23Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=6fd763d155860eb7ea3a93c8b3bf926940ffa3fb'/>
<id>urn:sha1:6fd763d155860eb7ea3a93c8b3bf926940ffa3fb</id>
<content type='text'>
Use temporary variable to make code easy to read and maintain.
	/* Pad cipher's parameters */
        vcrypto-&gt;ctrl.u.sym_create_session.op_type =
                cpu_to_le32(VIRTIO_CRYPTO_SYM_OP_CIPHER);
        vcrypto-&gt;ctrl.u.sym_create_session.u.cipher.para.algo =
                vcrypto-&gt;ctrl.header.algo;
        vcrypto-&gt;ctrl.u.sym_create_session.u.cipher.para.keylen =
                cpu_to_le32(keylen);
        vcrypto-&gt;ctrl.u.sym_create_session.u.cipher.para.op =
                cpu_to_le32(op);
--&gt;
	sym_create_session = &amp;ctrl-&gt;u.sym_create_session;
	sym_create_session-&gt;op_type = cpu_to_le32(VIRTIO_CRYPTO_SYM_OP_CIPHER);
	sym_create_session-&gt;u.cipher.para.algo = ctrl-&gt;header.algo;
	sym_create_session-&gt;u.cipher.para.keylen = cpu_to_le32(keylen);
	sym_create_session-&gt;u.cipher.para.op = cpu_to_le32(op);

The new style shows more obviously:
- the variable we want to operate.
- an assignment statement in a single line.

Cc: Michael S. Tsirkin &lt;mst@redhat.com&gt;
Cc: Jason Wang &lt;jasowang@redhat.com&gt;
Cc: Gonglei &lt;arei.gonglei@huawei.com&gt;
Reviewed-by: Gonglei &lt;arei.gonglei@huawei.com&gt;
Signed-off-by: zhenwei pi &lt;pizhenwei@bytedance.com&gt;
Message-Id: &lt;20220506131627.180784-2-pizhenwei@bytedance.com&gt;
Signed-off-by: Michael S. Tsirkin &lt;mst@redhat.com&gt;
</content>
</entry>
</feed>
