<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel/linux.git/drivers/crypto/virtio, branch v6.1.87</title>
<subtitle>Linux kernel stable tree (mirror)</subtitle>
<id>https://git.radix-linux.su/kernel/linux.git/atom?h=v6.1.87</id>
<link rel='self' href='https://git.radix-linux.su/kernel/linux.git/atom?h=v6.1.87'/>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/'/>
<updated>2024-03-01T12:26:32+00:00</updated>
<entry>
<title>crypto: virtio/akcipher - Fix stack overflow on memcpy</title>
<updated>2024-03-01T12:26:32+00:00</updated>
<author>
<name>zhenwei pi</name>
<email>pizhenwei@bytedance.com</email>
</author>
<published>2024-01-30T11:27:40+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=62f361bfea60c6afc3df09c1ad4152e6507f6f47'/>
<id>urn:sha1:62f361bfea60c6afc3df09c1ad4152e6507f6f47</id>
<content type='text'>
commit c0ec2a712daf133d9996a8a1b7ee2d4996080363 upstream.

sizeof(struct virtio_crypto_akcipher_session_para) is less than
sizeof(struct virtio_crypto_op_ctrl_req::u), copying more bytes from
stack variable leads stack overflow. Clang reports this issue by
commands:
make -j CC=clang-14 mrproper &gt;/dev/null 2&gt;&amp;1
make -j O=/tmp/crypto-build CC=clang-14 allmodconfig &gt;/dev/null 2&gt;&amp;1
make -j O=/tmp/crypto-build W=1 CC=clang-14 drivers/crypto/virtio/
  virtio_crypto_akcipher_algs.o

Fixes: 59ca6c93387d ("virtio-crypto: implement RSA algorithm")
Link: https://lore.kernel.org/all/0a194a79-e3a3-45e7-be98-83abd3e1cb7e@roeck-us.net/
Cc: &lt;stable@vger.kernel.org&gt;
Signed-off-by: zhenwei pi &lt;pizhenwei@bytedance.com&gt;
Tested-by: Nathan Chancellor &lt;nathan@kernel.org&gt; # build
Acked-by: Michael S. Tsirkin &lt;mst@redhat.com&gt;
Acked-by: Jason Wang &lt;jasowang@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 - Wait for tasklet to complete on device remove</title>
<updated>2024-01-25T23:27:22+00:00</updated>
<author>
<name>wangyangxin</name>
<email>wangyangxin1@huawei.com</email>
</author>
<published>2023-12-11T11:42:15+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=635308e6042f8972d9c77dae6eef3bbac8808d79'/>
<id>urn:sha1:635308e6042f8972d9c77dae6eef3bbac8808d79</id>
<content type='text'>
[ Upstream commit 67cc511e8d436456cc98033e6d4ba83ebfc8e672 ]

The scheduled tasklet needs to be executed on device remove.

Fixes: fed93fb62e05 ("crypto: virtio - Handle dataq logic with tasklet")
Signed-off-by: wangyangxin &lt;wangyangxin1@huawei.com&gt;
Signed-off-by: Gonglei &lt;arei.gonglei@huawei.com&gt;
Signed-off-by: Herbert Xu &lt;herbert@gondor.apana.org.au&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>crypto: virtio - Handle dataq logic with tasklet</title>
<updated>2024-01-25T23:27:21+00:00</updated>
<author>
<name>Gonglei (Arei)</name>
<email>arei.gonglei@huawei.com</email>
</author>
<published>2023-11-20T11:49:45+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=ae4747dab2eab95a68bb2f6c7e904bff0424e1b1'/>
<id>urn:sha1:ae4747dab2eab95a68bb2f6c7e904bff0424e1b1</id>
<content type='text'>
[ Upstream commit fed93fb62e05c38152b0fc1dc9609639e63eed76 ]

Doing ipsec produces a spinlock recursion warning.
This is due to crypto_finalize_request() being called in the upper half.
Move virtual data queue processing of virtio-crypto driver to tasklet.

Fixes: dbaf0624ffa57 ("crypto: add virtio-crypto driver")
Reported-by: Halil Pasic &lt;pasic@linux.ibm.com&gt;
Signed-off-by: wangyangxin &lt;wangyangxin1@huawei.com&gt;
Signed-off-by: Gonglei &lt;arei.gonglei@huawei.com&gt;
Signed-off-by: Herbert Xu &lt;herbert@gondor.apana.org.au&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>virtio-crypto: handle config changed by work queue</title>
<updated>2023-11-02T08:35:23+00:00</updated>
<author>
<name>zhenwei pi</name>
<email>pizhenwei@bytedance.com</email>
</author>
<published>2023-10-07T06:43:09+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=86f467d3582e0300d4574aec1cf6fb1d86dfd361'/>
<id>urn:sha1:86f467d3582e0300d4574aec1cf6fb1d86dfd361</id>
<content type='text'>
commit fa2e6947aa8844f25f5bad0d8cd1a541d9bc83eb upstream.

MST pointed out: config change callback is also handled incorrectly
in this driver, it takes a mutex from interrupt context.

Handle config changed by work queue instead.

Cc: stable@vger.kernel.org
Cc: Gonglei (Arei) &lt;arei.gonglei@huawei.com&gt;
Cc: Halil Pasic &lt;pasic@linux.ibm.com&gt;
Cc: Michael S. Tsirkin &lt;mst@redhat.com&gt;
Signed-off-by: zhenwei pi &lt;pizhenwei@bytedance.com&gt;
Message-Id: &lt;20231007064309.844889-1-pizhenwei@bytedance.com&gt;
Signed-off-by: Michael S. Tsirkin &lt;mst@redhat.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>virtio-crypto: fix memory leak in virtio_crypto_alg_skcipher_close_session()</title>
<updated>2023-01-12T11:02:08+00:00</updated>
<author>
<name>Wei Yongjun</name>
<email>weiyongjun1@huawei.com</email>
</author>
<published>2022-11-14T11:07:40+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=0871df190fe6723464efe0f493d476411616f553'/>
<id>urn:sha1:0871df190fe6723464efe0f493d476411616f553</id>
<content type='text'>
[ Upstream commit b1d65f717cd6305a396a8738e022c6f7c65cfbe8 ]

'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;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>virtio-crypto: fix memory-leak</title>
<updated>2022-09-27T22:30:48+00:00</updated>
<author>
<name>lei he</name>
<email>helei.sig11@bytedance.com</email>
</author>
<published>2022-09-19T07:51:58+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=1bedcf22c081a6e9943f09937b2da8d3ef52d20d'/>
<id>urn:sha1:1bedcf22c081a6e9943f09937b2da8d3ef52d20d</id>
<content type='text'>
Fix memory-leak for virtio-crypto akcipher request, this problem is
introduced by 59ca6c93387d3(virtio-crypto: implement RSA algorithm).
The leak can be reproduced and tested with the following script
inside virtual machine:

#!/bin/bash

LOOP_TIMES=10000

# required module: pkcs8_key_parser, virtio_crypto
modprobe pkcs8_key_parser # if CONFIG_PKCS8_PRIVATE_KEY_PARSER=m
modprobe virtio_crypto # if CONFIG_CRYPTO_DEV_VIRTIO=m
rm -rf /tmp/data
dd if=/dev/random of=/tmp/data count=1 bs=230

# generate private key and self-signed cert
openssl req -nodes -x509 -newkey rsa:2048 -keyout key.pem \
		-outform der -out cert.der  \
		-subj "/C=CN/ST=GD/L=SZ/O=vihoo/OU=dev/CN=always.com/emailAddress=yy@always.com"
# convert private key from pem to der
openssl pkcs8 -in key.pem -topk8 -nocrypt -outform DER -out key.der

# add key
PRIV_KEY_ID=`cat key.der | keyctl padd asymmetric test_priv_key @s`
echo "priv key id = "$PRIV_KEY_ID
PUB_KEY_ID=`cat cert.der | keyctl padd asymmetric test_pub_key @s`
echo "pub key id = "$PUB_KEY_ID

# query key
keyctl pkey_query $PRIV_KEY_ID 0
keyctl pkey_query $PUB_KEY_ID 0

# here we only run pkey_encrypt becasuse it is the fastest interface
function bench_pub() {
	keyctl pkey_encrypt $PUB_KEY_ID 0 /tmp/data enc=pkcs1 &gt;/tmp/enc.pub
}

# do bench_pub in loop to obtain the memory leak
for (( i = 0; i &lt; ${LOOP_TIMES}; ++i )); do
	bench_pub
done

Signed-off-by: lei he &lt;helei.sig11@bytedance.com&gt;
Acked-by: Michael S. Tsirkin &lt;mst@redhat.com&gt;
Reviewed-by: Gonglei &lt;arei.gonglei@huawei.com&gt;
Message-Id: &lt;20220919075158.3625-1-helei.sig11@bytedance.com&gt;
Signed-off-by: Michael S. Tsirkin &lt;mst@redhat.com&gt;
</content>
</entry>
<entry>
<title>virtio-crypto: enable retry for virtio-crypto-dev</title>
<updated>2022-05-31T16:45:09+00:00</updated>
<author>
<name>lei he</name>
<email>helei.sig11@bytedance.com</email>
</author>
<published>2022-05-06T13:16:27+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=4e0d352af04cf4e019d3e45229eaaff9e8ffb33d'/>
<id>urn:sha1:4e0d352af04cf4e019d3e45229eaaff9e8ffb33d</id>
<content type='text'>
Enable retry for virtio-crypto-dev, so that crypto-engine
can process cipher-requests parallelly.

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: lei he &lt;helei.sig11@bytedance.com&gt;
Signed-off-by: zhenwei pi &lt;pizhenwei@bytedance.com&gt;
Message-Id: &lt;20220506131627.180784-6-pizhenwei@bytedance.com&gt;
Signed-off-by: Michael S. Tsirkin &lt;mst@redhat.com&gt;
</content>
</entry>
<entry>
<title>virtio-crypto: adjust dst_len at ops callback</title>
<updated>2022-05-31T16:45:09+00:00</updated>
<author>
<name>lei he</name>
<email>helei.sig11@bytedance.com</email>
</author>
<published>2022-05-06T13:16:26+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=a36bd0ad9fbf69d0d711b1c105954ce8d6cc144a'/>
<id>urn:sha1:a36bd0ad9fbf69d0d711b1c105954ce8d6cc144a</id>
<content type='text'>
For some akcipher operations(eg, decryption of pkcs1pad(rsa)),
the length of returned result maybe less than akcipher_req-&gt;dst_len,
we need to recalculate the actual dst_len through the virt-queue
protocol.

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: lei he &lt;helei.sig11@bytedance.com&gt;
Signed-off-by: zhenwei pi &lt;pizhenwei@bytedance.com&gt;
Message-Id: &lt;20220506131627.180784-5-pizhenwei@bytedance.com&gt;
Signed-off-by: Michael S. Tsirkin &lt;mst@redhat.com&gt;
</content>
</entry>
<entry>
<title>virtio-crypto: wait ctrl queue instead of busy polling</title>
<updated>2022-05-31T16:45:09+00:00</updated>
<author>
<name>zhenwei pi</name>
<email>pizhenwei@bytedance.com</email>
</author>
<published>2022-05-06T13:16:25+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/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:09+00:00</updated>
<author>
<name>zhenwei pi</name>
<email>pizhenwei@bytedance.com</email>
</author>
<published>2022-05-06T13:16:24+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/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>
</feed>
