Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp916850rdb; Wed, 6 Dec 2023 03:54:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IHlUE8PXcvJEZ0MxoRLG9JUbAW15cVogUeT4/LJGDG9V0KrMy2RUtYyLokUdcyibp04Ef6x X-Received: by 2002:a05:6a20:1583:b0:18f:97c:8a4b with SMTP id h3-20020a056a20158300b0018f097c8a4bmr773356pzj.118.1701863668299; Wed, 06 Dec 2023 03:54:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701863668; cv=none; d=google.com; s=arc-20160816; b=nsHOaDkEfpF+VyJx+6l9Xz/bFZSVcs0TYJAeMP/j7bKp6YyvcDFIZmlylPkWVb+kva uZqv6aydYa4+nKuT51Yagks8AFJjz+PcmtKMPQsimIkT+SDpzBk99ccOnVGTPBLlOtcu rHdckdk7dcy4o+gQW7yVCQagDtG8Gp0X0Cabm99EvEkxCz6SGLwjo6Adt+lfrVxsu2sY 9HLRcEqN8qGJYq3PUhDMCBwvJLz6Sma/FhFfP0YDT4xuiCaAHzX/SRe3TzF5/MUlAeI4 Ql21SaxZrUtnZM5tVYo00xbxp/ZPQcg1dADcR0yWz3/jP/h/sbZJ4chJDlXQDxBPD+Ll YFAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :content-language:accept-language:message-id:date:thread-index :thread-topic:subject:cc:to:from; bh=TgARovU9O3zc6LWIlwqRoj2Ur6eoWQPBXaMUpsT7mE4=; fh=b4NfOIYdTVp8GcobU8MPuQC3KFyV9uno3Pnb+8jI77A=; b=LBwT0WFfyfv5SylUXwGA0n+wTfxVeXdNpMkuOnG/75Qp4NxYiYl8SQt5s/C8ZKeSW5 6Fb2B+Qv4n9UgQ+O3+pbgBaWYbYEjurS4Kd1jxy+Yu1iTsT8vaSzhzz2l6DApdDY5pKA l8lK04gCh69eUL/7qM4h5tq+eCbQnvnnXcsKQhahFhbPFYE6/HLFKn300ycfQUO73zDI Gt7hxHEJCtyi/pbQVub4VvXazq6C1ObfUIQZI2rrlXpQ8wk9euG77Ic0zc2L6WGlC/U6 xkkoI1f6FUnls5lvylG8Fzvxsd0DB9YOldZslGA46PCQHVw2QsisxkZebFaBdyfVxanG BamQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id dn3-20020a056a00498300b006ce420e612bsi6128503pfb.127.2023.12.06.03.54.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 03:54:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 4CD40809AF8A; Wed, 6 Dec 2023 03:54:18 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377858AbjLFLxq convert rfc822-to-8bit (ORCPT + 99 others); Wed, 6 Dec 2023 06:53:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378071AbjLFLx3 (ORCPT ); Wed, 6 Dec 2023 06:53:29 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60A49172A; Wed, 6 Dec 2023 03:52:53 -0800 (PST) Received: from dggpemm500008.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4SlbNX5kmdzWj91; Wed, 6 Dec 2023 19:51:56 +0800 (CST) Received: from dggpemm500006.china.huawei.com (7.185.36.236) by dggpemm500008.china.huawei.com (7.185.36.136) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Wed, 6 Dec 2023 19:52:51 +0800 Received: from dggpemm500006.china.huawei.com ([7.185.36.236]) by dggpemm500006.china.huawei.com ([7.185.36.236]) with mapi id 15.01.2507.035; Wed, 6 Dec 2023 19:52:51 +0800 From: "Gonglei (Arei)" To: Herbert Xu , "linux-crypto@vger.kernel.org" CC: "Michael S. Tsirkin" , Jason Wang , "virtualization@lists.linux-foundation.org" , "linux-kernel@vger.kernel.org" , wangyangxin , "Gonglei (Arei)" , Halil Pasic Subject: [PATCH v2] crypto: virtio-crypto: Handle dataq logic with tasklet Thread-Topic: [PATCH v2] crypto: virtio-crypto: Handle dataq logic with tasklet Thread-Index: AdooOneOWI65hKIST2yjTeZdqptiyQ== Date: Wed, 6 Dec 2023 11:52:51 +0000 Message-ID: Accept-Language: zh-CN, en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.174.149.11] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-CFilter-Loop: Reflected X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Wed, 06 Dec 2023 03:54:18 -0800 (PST) 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: dbaf0624ffa5 ("crypto: add virtio-crypto driver") Reported-by: Halil Pasic Signed-off-by: wangyangxin Signed-off-by: Gonglei --- v2: calling tasklet_kill() in virtcrypto_remove(), thanks for MST. drivers/crypto/virtio/virtio_crypto_common.h | 2 ++ drivers/crypto/virtio/virtio_crypto_core.c | 26 ++++++++++++++++---------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/drivers/crypto/virtio/virtio_crypto_common.h b/drivers/crypto/virtio/virtio_crypto_common.h index 154590e..7059bbe 100644 --- a/drivers/crypto/virtio/virtio_crypto_common.h +++ b/drivers/crypto/virtio/virtio_crypto_common.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -28,6 +29,7 @@ struct data_queue { char name[32]; struct crypto_engine *engine; + struct tasklet_struct done_task; }; struct virtio_crypto { diff --git a/drivers/crypto/virtio/virtio_crypto_core.c b/drivers/crypto/virtio/virtio_crypto_core.c index 43a0838..b909c6a 100644 --- a/drivers/crypto/virtio/virtio_crypto_core.c +++ b/drivers/crypto/virtio/virtio_crypto_core.c @@ -72,27 +72,28 @@ int virtio_crypto_ctrl_vq_request(struct virtio_crypto *vcrypto, struct scatterl return 0; } -static void virtcrypto_dataq_callback(struct virtqueue *vq) +static void virtcrypto_done_task(unsigned long data) { - struct virtio_crypto *vcrypto = vq->vdev->priv; + struct data_queue *data_vq = (struct data_queue *)data; + struct virtqueue *vq = data_vq->vq; struct virtio_crypto_request *vc_req; - unsigned long flags; unsigned int len; - unsigned int qid = vq->index; - spin_lock_irqsave(&vcrypto->data_vq[qid].lock, flags); do { virtqueue_disable_cb(vq); while ((vc_req = virtqueue_get_buf(vq, &len)) != NULL) { - spin_unlock_irqrestore( - &vcrypto->data_vq[qid].lock, flags); if (vc_req->alg_cb) vc_req->alg_cb(vc_req, len); - spin_lock_irqsave( - &vcrypto->data_vq[qid].lock, flags); } } while (!virtqueue_enable_cb(vq)); - spin_unlock_irqrestore(&vcrypto->data_vq[qid].lock, flags); +} + +static void virtcrypto_dataq_callback(struct virtqueue *vq) +{ + struct virtio_crypto *vcrypto = vq->vdev->priv; + struct data_queue *dq = &vcrypto->data_vq[vq->index]; + + tasklet_schedule(&dq->done_task); } static int virtcrypto_find_vqs(struct virtio_crypto *vi) @@ -150,6 +151,8 @@ static int virtcrypto_find_vqs(struct virtio_crypto *vi) ret = -ENOMEM; goto err_engine; } + tasklet_init(&vi->data_vq[i].done_task, virtcrypto_done_task, + (unsigned long)&vi->data_vq[i]); } kfree(names); @@ -497,12 +500,15 @@ static void virtcrypto_free_unused_reqs(struct virtio_crypto *vcrypto) static void virtcrypto_remove(struct virtio_device *vdev) { struct virtio_crypto *vcrypto = vdev->priv; + int i; dev_info(&vdev->dev, "Start virtcrypto_remove.\n"); flush_work(&vcrypto->config_work); if (virtcrypto_dev_started(vcrypto)) virtcrypto_dev_stop(vcrypto); + for (i = 0; i < vcrypto->max_data_queues; i++) + tasklet_kill(&vcrypto->data_vq[i].done_task); virtio_reset_device(vdev); virtcrypto_free_unused_reqs(vcrypto); virtcrypto_clear_crypto_engines(vcrypto); -- 1.8.3.1