From patchwork Fri Oct 18 06:40:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sridhar, Kanchana P" X-Patchwork-Id: 13841229 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D3A64D3C551 for ; Fri, 18 Oct 2024 06:41:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B1C7D6B0088; Fri, 18 Oct 2024 02:41:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id ACD296B0089; Fri, 18 Oct 2024 02:41:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8F8176B008A; Fri, 18 Oct 2024 02:41:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 6C27E6B0088 for ; Fri, 18 Oct 2024 02:41:08 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id BFB83811E5 for ; Fri, 18 Oct 2024 06:40:57 +0000 (UTC) X-FDA: 82685775480.30.59D2584 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.15]) by imf19.hostedemail.com (Postfix) with ESMTP id 66D741A000C for ; Fri, 18 Oct 2024 06:40:52 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=EuiHOFsh; spf=pass (imf19.hostedemail.com: domain of kanchana.p.sridhar@intel.com designates 192.198.163.15 as permitted sender) smtp.mailfrom=kanchana.p.sridhar@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729233519; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=3n7vBZ2YHqBQ19A05vmbe5pZrtJfejWOVervqy3sijA=; b=e22UtLizRz63bJisWRCoBG65mDdMkPtOlLqav922DVvhxvBE0SjrL9kSUszw8yWHiU9Mni 0yoZVRwljlB5nMS3Goy4QiMu48nK9LCx483imvE1osTb1h3XMpxBfGzUP+RMziZJfyv5dC cJmH6z1pCpCyK0DqM18qVdtoRvHN05o= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729233519; a=rsa-sha256; cv=none; b=sTaNjVCq9Ivi8FdhoWG1vGcdD+O7s+jZy3a0Abla/yxlNT9Q00+sbivtK4blyzKS8tHUb6 OZ+27OnMIOSIBHL8i0g5Cw3SXq+2Y3Jo1zNhuzqCpzsCs5NTyLVMfR33fC8vvzXXLa8q91 wDOssq9Og6PgoPW09QFJ9yxpPyp/Dgw= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=EuiHOFsh; spf=pass (imf19.hostedemail.com: domain of kanchana.p.sridhar@intel.com designates 192.198.163.15 as permitted sender) smtp.mailfrom=kanchana.p.sridhar@intel.com; dmarc=pass (policy=none) header.from=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729233666; x=1760769666; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LlOfKWFmMimgOZRHZFBWIeDtQDuVJjBoFm4a8ckUAcs=; b=EuiHOFsh64wnXr4Fcl2k9knPJAsdnOkM7ux1x8C9guvaOyOFC2yc8RpQ utxgSJb1fRKit2yE2CT9HuSU0QDvU3FBl3kwG9C7AI79H+nxFpseFao6H QHZ9SmXJ05r9PzqXCLW+LiVM9ba1Ovy5bAe5US19Mx1sd9niS+M0M1X/6 R5M+HZLTorNuk9gVMe/ljBODFyGtZ8R7q1tGvsv8YeIcJ6JTeKsFsuhMq UO7+sF+vqGmgn6Q9V8HCj4b04osZXQGyOeJ0G7uodVzBCc1Hyu4lMbszZ a+Qej7/g9+JvEiMmZn1AMGCaZFk54m5Krso915G2mWk3fLaEkt3EeHsKN Q==; X-CSE-ConnectionGUID: h5tFPtTaTce/fp0AUi1Xhw== X-CSE-MsgGUID: 8a6D1H2FS8qyhpp3dD48Tg== X-IronPort-AV: E=McAfee;i="6700,10204,11228"; a="28884798" X-IronPort-AV: E=Sophos;i="6.11,212,1725346800"; d="scan'208";a="28884798" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by fmvoesa109.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2024 23:41:02 -0700 X-CSE-ConnectionGUID: gJKulEXVTRCuP5PYxKnngw== X-CSE-MsgGUID: S19yrmp8R/uCrtwKGYX3Rw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="83607493" Received: from jf5300-b11a338t.jf.intel.com ([10.242.51.6]) by orviesa003.jf.intel.com with ESMTP; 17 Oct 2024 23:41:02 -0700 From: Kanchana P Sridhar To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, hannes@cmpxchg.org, yosryahmed@google.com, nphamcs@gmail.com, chengming.zhou@linux.dev, usamaarif642@gmail.com, ryan.roberts@arm.com, ying.huang@intel.com, 21cnbao@gmail.com, akpm@linux-foundation.org, linux-crypto@vger.kernel.org, herbert@gondor.apana.org.au, davem@davemloft.net, clabbe@baylibre.com, ardb@kernel.org, ebiggers@google.com, surenb@google.com, kristen.c.accardi@intel.com, zanussi@kernel.org, viro@zeniv.linux.org.uk, brauner@kernel.org, jack@suse.cz, mcgrof@kernel.org, kees@kernel.org, joel.granados@kernel.org, bfoster@redhat.com, willy@infradead.org, linux-fsdevel@vger.kernel.org Cc: wajdi.k.feghali@intel.com, vinodh.gopal@intel.com, kanchana.p.sridhar@intel.com Subject: [RFC PATCH v1 02/13] crypto: iaa - Add support for irq-less crypto async interface Date: Thu, 17 Oct 2024 23:40:50 -0700 Message-Id: <20241018064101.336232-3-kanchana.p.sridhar@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20241018064101.336232-1-kanchana.p.sridhar@intel.com> References: <20241018064101.336232-1-kanchana.p.sridhar@intel.com> MIME-Version: 1.0 X-Stat-Signature: 7af3fx6wkq1ndbc9n47tr6w3efumkqce X-Rspamd-Queue-Id: 66D741A000C X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1729233652-759413 X-HE-Meta: U2FsdGVkX19WFfbzgJdPWjDs4nHTOoqONcZJPheQlCQ9Je6qwRy9+DbiDPaY0LMNhaSSujT5Q338KWpoPgQPvetarutZpExjXov6R0Oud2S3UocrZvvUEjqVh6zG2lkop8Ng7B0+6y0OhvBeqKRzTqYAkf9HeBRPjcLfwbGUstMww+i8WFFlCIFfNclZG5rkSq0+u8tPMvg3+RjuEhblEPC8q1rTZ8/LlJj0NDeWUcd0HOoNsYNoqdHV85fvoRMkHsXv6nQ9tTEZjgZ4qD5ogx4NS1k2guipl5tvCQQ63B0//1w11fE6XaQPkP0WNWlxC8jhejQZnd0PcCfnV4b4T+Stw8tVpuh00gDS0qOMkyX9cOJ5Q5dOVnEldNQP28KGTJI3Z8KE6Bz3wuUfYmPYBRhMK/T8rS6NyF1agk80scu+hEaROzwpEkydt+zCwt/I1s0TfPXTGEgwL4JeSOPTZ9c2S7OITKJRHoImTxUB0zjcH33YnAGmMf/rP5XSs4g+1kV3fmWUXovkuMC259y98V8VZoDXB8399yK3T0EsrrUkHb5hLsLJVyMeUdfjNxljvxfJ1ZWZShspEgEoISDvQk9iskg4H+7uany2KhfrXhVVwupGvlwQXpdcgVin8ejM1+HQZXM6CE8bdMkxkjgIw/54xPUJPrK8T8crwUjwPkirxtQH7F9mqcJyFT6rgvoM7bvE+zmWYOU7FVAgbzKQWGOgTGNtBWOYYLEc87o/fABu9kKFubUn6JkHUL7q6R0RBlS3l5P20EhsghNuZWrvkjFNHWc3h3c7zvJyTcaYOyB8t+7PNljrCs2ysc+UW5J0FpCMt2uKDHHddo8giehztt/kwgHUoyER+fpb2sFuvl9iHMssFHSFAHy1dLDUA3rQOBuOc4W0xhJ8PHHsi5ENkD8kY4MUi3LiKE1594/o7Gaj/+/14eE0mFQQdYJwUOooi8NSR7NxkFCoh7jSYS5 CSJzcx5R nf1ADfE5uSQAjEIe9Unfk48LF9vS+XA7cfyDCyRQJsE3RdMpmcCfXgUpBa8Elh7uCyC/WiLKWMCsJKi2Nq7qRWPU3qifCZNGiVBhLXAK8CKffmhdI7Gqi82VKm6mlM8/Oc8sNsAApL7II2JX3Jb7v/4ibQdLMYOfUTyV5JMPIKqFGt7TYrqSE4jLQbA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Add a crypto acomp poll() implementation so that callers can use true async iaa compress/decompress without interrupts. To use this mode with zswap, select the 'async' iaa_crypto driver_sync_mode: echo async > /sys/bus/dsa/drivers/crypto/sync_mode This will cause the iaa_crypto driver to register its acomp_alg implementation using a non-NULL poll() member, which callers such as zswap can check for the presence of and use true async mode if found. Signed-off-by: Tom Zanussi Signed-off-by: Kanchana P Sridhar --- drivers/crypto/intel/iaa/iaa_crypto_main.c | 74 ++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/drivers/crypto/intel/iaa/iaa_crypto_main.c b/drivers/crypto/intel/iaa/iaa_crypto_main.c index 237f87000070..6a8577ac1330 100644 --- a/drivers/crypto/intel/iaa/iaa_crypto_main.c +++ b/drivers/crypto/intel/iaa/iaa_crypto_main.c @@ -1788,6 +1788,74 @@ static void compression_ctx_init(struct iaa_compression_ctx *ctx) ctx->use_irq = use_irq; } +static int iaa_comp_poll(struct acomp_req *req) +{ + struct idxd_desc *idxd_desc; + struct idxd_device *idxd; + struct iaa_wq *iaa_wq; + struct pci_dev *pdev; + struct device *dev; + struct idxd_wq *wq; + bool compress_op; + int ret; + + idxd_desc = req->base.data; + if (!idxd_desc) + return -EAGAIN; + + compress_op = (idxd_desc->iax_hw->opcode == IAX_OPCODE_COMPRESS); + wq = idxd_desc->wq; + iaa_wq = idxd_wq_get_private(wq); + idxd = iaa_wq->iaa_device->idxd; + pdev = idxd->pdev; + dev = &pdev->dev; + + ret = check_completion(dev, idxd_desc->iax_completion, true, true); + if (ret == -EAGAIN) + return ret; + if (ret) + goto out; + + req->dlen = idxd_desc->iax_completion->output_size; + + /* Update stats */ + if (compress_op) { + update_total_comp_bytes_out(req->dlen); + update_wq_comp_bytes(wq, req->dlen); + } else { + update_total_decomp_bytes_in(req->slen); + update_wq_decomp_bytes(wq, req->slen); + } + + if (iaa_verify_compress && (idxd_desc->iax_hw->opcode == IAX_OPCODE_COMPRESS)) { + struct crypto_tfm *tfm = req->base.tfm; + dma_addr_t src_addr, dst_addr; + u32 compression_crc; + + compression_crc = idxd_desc->iax_completion->crc; + + dma_sync_sg_for_device(dev, req->dst, 1, DMA_FROM_DEVICE); + dma_sync_sg_for_device(dev, req->src, 1, DMA_TO_DEVICE); + + src_addr = sg_dma_address(req->src); + dst_addr = sg_dma_address(req->dst); + + ret = iaa_compress_verify(tfm, req, wq, src_addr, req->slen, + dst_addr, &req->dlen, compression_crc); + } +out: + /* caller doesn't call crypto_wait_req, so no acomp_request_complete() */ + + dma_unmap_sg(dev, req->dst, sg_nents(req->dst), DMA_FROM_DEVICE); + dma_unmap_sg(dev, req->src, sg_nents(req->src), DMA_TO_DEVICE); + + idxd_free_desc(idxd_desc->wq, idxd_desc); + + dev_dbg(dev, "%s: returning ret=%d\n", __func__, ret); + + return ret; +} + static int iaa_comp_init_fixed(struct crypto_acomp *acomp_tfm) { struct crypto_tfm *tfm = crypto_acomp_tfm(acomp_tfm); @@ -1813,6 +1881,7 @@ static struct acomp_alg iaa_acomp_fixed_deflate = { .compress = iaa_comp_acompress, .decompress = iaa_comp_adecompress, .dst_free = dst_free, + .poll = iaa_comp_poll, .base = { .cra_name = "deflate", .cra_driver_name = "deflate-iaa", @@ -1827,6 +1896,11 @@ static int iaa_register_compression_device(void) { int ret; + if (async_mode && !use_irq) + iaa_acomp_fixed_deflate.poll = iaa_comp_poll; + else + iaa_acomp_fixed_deflate.poll = NULL; + ret = crypto_register_acomp(&iaa_acomp_fixed_deflate); if (ret) { pr_err("deflate algorithm acomp fixed registration failed (%d)\n", ret);