From nobody Tue Feb 10 08:27:39 2026 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5EE2729DB61; Thu, 18 Dec 2025 03:49:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=114.242.206.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766029766; cv=none; b=KEkipo66G+qIsclblMvCc9BYz+XkTmuya3oxhHwNiDtRzAfZqTTA32CmeaxsKokyHlXfzUQE/YBHGHbLqLTOLjSN8JxO2sAUSE693qUA/YpPxgmieGbMoXhQ+vE0z+ibESeb73QZ4lrP557VtwTPrRlgB1hRrJqbmtfaeBy+ieA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766029766; c=relaxed/simple; bh=JWwaJBFy5oIvmdtqhh5mZ0Gbwalk+2T00rI/ggDjVuU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=n94cHaGy9JUC/fUHC8MBUfQkfoWJVy4DhyOWc0SjEyRJXp/anPHMkOIC1p+3YJTEA7JVrXR/N5hx5NxcbqV6mLn+IW02fjpmcHsY7Bcr91oQc0FLWnuz7haZaV6KqdTZerl3sL+MEMnnC4fveevxo7eq+ZCEhDX4iKMh3HeRf5M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn; spf=pass smtp.mailfrom=loongson.cn; arc=none smtp.client-ip=114.242.206.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=loongson.cn Received: from loongson.cn (unknown [10.2.5.213]) by gateway (Coremail) with SMTP id _____8BxcfCreUNph1wAAA--.1729S3; Thu, 18 Dec 2025 11:48:59 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.213]) by front1 (Coremail) with SMTP id qMiowJAxXcKpeUNpwS4BAA--.2172S2; Thu, 18 Dec 2025 11:48:57 +0800 (CST) From: Bibo Mao To: Gonglei , "Michael S . Tsirkin" , Jason Wang , Eric Biggers , Xuan Zhuo , =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Herbert Xu , "David S. Miller" Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-crypto@vger.kernel.org, virtualization@lists.linux.dev Subject: [PATCH v4 4/9] crypto: virtio: Add algo pointer in virtio_crypto_skcipher_ctx Date: Thu, 18 Dec 2025 11:48:41 +0800 Message-Id: <20251218034846.948860-5-maobibo@loongson.cn> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20251218034846.948860-1-maobibo@loongson.cn> References: <20251218034846.948860-1-maobibo@loongson.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: qMiowJAxXcKpeUNpwS4BAA--.2172S2 X-CM-SenderInfo: xpdruxter6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Content-Type: text/plain; charset="utf-8" Structure virtio_crypto_skcipher_ctx is allocated together with crypto_skcipher, and skcipher_alg is set in strucutre crypto_skcipher when it is created. Here add virtio_crypto_algo pointer in virtio_crypto_skcipher_ctx and set it in function virtio_crypto_skcipher_init(). So crypto service and algo can be acquired from virtio_crypto_algo pointer. Signed-off-by: Bibo Mao --- .../virtio/virtio_crypto_skcipher_algs.c | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/drivers/crypto/virtio/virtio_crypto_skcipher_algs.c b/drivers/= crypto/virtio/virtio_crypto_skcipher_algs.c index 11053d1786d4..8a139de3d064 100644 --- a/drivers/crypto/virtio/virtio_crypto_skcipher_algs.c +++ b/drivers/crypto/virtio/virtio_crypto_skcipher_algs.c @@ -15,9 +15,11 @@ #include "virtio_crypto_common.h" =20 =20 +struct virtio_crypto_algo; struct virtio_crypto_skcipher_ctx { struct virtio_crypto *vcrypto; =20 + struct virtio_crypto_algo *alg; struct virtio_crypto_sym_session_info enc_sess_info; struct virtio_crypto_sym_session_info dec_sess_info; }; @@ -108,9 +110,7 @@ virtio_crypto_alg_validate_key(int key_len, uint32_t *a= lg) =20 static int virtio_crypto_alg_skcipher_init_session( struct virtio_crypto_skcipher_ctx *ctx, - uint32_t alg, const uint8_t *key, - unsigned int keylen, - int encrypt) + const uint8_t *key, unsigned int keylen, int encrypt) { struct scatterlist outhdr, key_sg, inhdr, *sgs[3]; struct virtio_crypto *vcrypto =3D ctx->vcrypto; @@ -140,7 +140,7 @@ static int virtio_crypto_alg_skcipher_init_session( /* Pad ctrl header */ ctrl =3D &vc_ctrl_req->ctrl; ctrl->header.opcode =3D cpu_to_le32(VIRTIO_CRYPTO_CIPHER_CREATE_SESSION); - ctrl->header.algo =3D cpu_to_le32(alg); + ctrl->header.algo =3D cpu_to_le32(ctx->alg->algonum); /* Set the default dataqueue id to 0 */ ctrl->header.queue_id =3D 0; =20 @@ -261,13 +261,11 @@ static int virtio_crypto_alg_skcipher_init_sessions( return -EINVAL; =20 /* Create encryption session */ - ret =3D virtio_crypto_alg_skcipher_init_session(ctx, - alg, key, keylen, 1); + ret =3D virtio_crypto_alg_skcipher_init_session(ctx, key, keylen, 1); if (ret) return ret; /* Create decryption session */ - ret =3D virtio_crypto_alg_skcipher_init_session(ctx, - alg, key, keylen, 0); + ret =3D virtio_crypto_alg_skcipher_init_session(ctx, key, keylen, 0); if (ret) { virtio_crypto_alg_skcipher_close_session(ctx, 1); return ret; @@ -293,7 +291,7 @@ static int virtio_crypto_skcipher_setkey(struct crypto_= skcipher *tfm, int node =3D virtio_crypto_get_current_node(); struct virtio_crypto *vcrypto =3D virtcrypto_get_dev_node(node, - VIRTIO_CRYPTO_SERVICE_CIPHER, alg); + ctx->alg->service, ctx->alg->algonum); if (!vcrypto) { pr_err("virtio_crypto: Could not find a virtio device in the system or = unsupported algo\n"); return -ENODEV; @@ -509,7 +507,11 @@ static int virtio_crypto_skcipher_decrypt(struct skcip= her_request *req) =20 static int virtio_crypto_skcipher_init(struct crypto_skcipher *tfm) { + struct virtio_crypto_skcipher_ctx *ctx =3D crypto_skcipher_ctx(tfm); + struct skcipher_alg *alg =3D crypto_skcipher_alg(tfm); + crypto_skcipher_set_reqsize(tfm, sizeof(struct virtio_crypto_sym_request)= ); + ctx->alg =3D container_of(alg, struct virtio_crypto_algo, algo.base); =20 return 0; } --=20 2.39.3