From patchwork Tue Feb 20 02:55:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Barry Song <21cnbao@gmail.com> X-Patchwork-Id: 13563285 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 7B664C48BF8 for ; Tue, 20 Feb 2024 02:56:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0FFF76B0083; Mon, 19 Feb 2024 21:56:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0B0D26B0087; Mon, 19 Feb 2024 21:56:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E93906B0088; Mon, 19 Feb 2024 21:56:14 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id DA1536B0083 for ; Mon, 19 Feb 2024 21:56:14 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id A6184A0508 for ; Tue, 20 Feb 2024 02:56:14 +0000 (UTC) X-FDA: 81810668268.30.4239A1E Received: from mail-oi1-f181.google.com (mail-oi1-f181.google.com [209.85.167.181]) by imf10.hostedemail.com (Postfix) with ESMTP id C3C78C001C for ; Tue, 20 Feb 2024 02:56:12 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=mDB3dWtB; spf=pass (imf10.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.167.181 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708397772; 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=tiMCpE6cizjhU1RT67E8V4r+8Ln0KAuPCSDlqhlksl4=; b=M04oh9DIL4in2Xjm8AlYLSFIf4yaKqlpKRmNhaMEjE0eluyDHv8lTnAURfvcFnj9m025CS 61hfaqSBQB+EAysSKDRpi1P1vJqlsTzD06my0/Tk2EGsnFK1Vz9yVlg3o3nl1Q586kQPvY Q2uZeHCn8FWvk3/OUr/19e4Yn7oPavc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708397772; a=rsa-sha256; cv=none; b=ReJnE2ofLiZnXtPmcWCgk0s7ZMIE1NHM3/fQJAqQop3v1B1FoTOjjjYZTdpGtriRDmEM1d 0vGF1/04KMNSZyEsFp+VsBL64OHeuEbBGbS0n6YwIxOunVjMWm1uuWJFB2fCTKJKoW1QWU 1KZYGOmXmc+mcJCjHHuC5Gn5A+Cxszw= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=mDB3dWtB; spf=pass (imf10.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.167.181 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-oi1-f181.google.com with SMTP id 5614622812f47-3c049ccb623so2848584b6e.1 for ; Mon, 19 Feb 2024 18:56:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708397772; x=1709002572; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tiMCpE6cizjhU1RT67E8V4r+8Ln0KAuPCSDlqhlksl4=; b=mDB3dWtB5iKtrJRF7jL5c6/GCFhhTjNsnKjW5d9m7YnUJ54FA+hEJag26EN7qOOM9W jtSaF5t9KMOIhEuqrWb30csRROj06VGgurvVR0Ig5WfmmWLX4uaJ9Dp/3ZwzAjk7jobF wM7T/9vZPzrjEN6q4RFaHpupJU2LO0HO0T8t/C//voJPnggZwILaG3Kw0CGcLC39Rm2E ldgQfpsfkLOJV5EUkkbIU7BZx0R2KWQ8uUSRh2IKQnXzOMqRhKGaXMbKkEr+zLAfxZi/ cwwzUbgsTDVMK2Gf8jYRCfS7qJaZAE+jV/2VafqpVXYuH3nllAwDX9dsfxRVMDNb1DMO tIlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708397772; x=1709002572; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tiMCpE6cizjhU1RT67E8V4r+8Ln0KAuPCSDlqhlksl4=; b=V4xpomtAvbhiBZSfr5fB6ei/5NTDjQ0tXT8aLzbjVz+9JHuz+nBkQJH8bm9r1ygonT w2meg3pIBEsDUAl7CEn4UK/lAb/xeAwT6il/rrdAzTGX7HSQX+jsC83we9+6Aanh8btj eqnYvyypagGSxDHbj/9mWQMbosOPCgcj7oZ/Uwj6E3CQ591mU+AOsVHz2me2yBi9zBwt Os6ZOvJEYyfKAGEtnvlqTUTHrzfJP80iFuuVWtU1lZ1xV4XmGhQLeaj3YusAZZHrOxy2 qyKwM9O9HkIvB/0L+sQMoXjvNi5IBfE4WyyT5b0y5XoZGYctzRQ2J6Qy+soWXdvFfGh7 7EGw== X-Forwarded-Encrypted: i=1; AJvYcCW3GrLk59aExAGhzlcghd3hb0qpch1KPllcFFzLNNFcLPZJCkPWI3MpR6pNGkYsgVJJlePKbIEwKH9GR+xgkevuR3w= X-Gm-Message-State: AOJu0YzjOKgaw5xuSg1JSS7wSz8tm6VKE81eIA0ANednVN4ZEdtxaijP ZE0E04qaxxjFbTadd4cj7EGzvKCqE6x9LG8aY4n+PishobD11lkk X-Google-Smtp-Source: AGHT+IGt+eY+tIvCG4LwXzbVuI0ZKfC6ws0uDOdftQOJVvSjsz5UFEJGJlJE5E0UOzF0YnLQ2I4PrA== X-Received: by 2002:a05:6358:7f0e:b0:176:92d1:568f with SMTP id p14-20020a0563587f0e00b0017692d1568fmr13688884rwn.18.1708397771772; Mon, 19 Feb 2024 18:56:11 -0800 (PST) Received: from barry-desktop.hub ([2407:7000:8942:5500:a5bd:9c11:af2b:aecf]) by smtp.gmail.com with ESMTPSA id j34-20020a63fc22000000b005dc1edf7371sm5500047pgi.9.2024.02.19.18.56.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 18:56:11 -0800 (PST) From: Barry Song <21cnbao@gmail.com> To: akpm@linux-foundation.org, davem@davemloft.net, hannes@cmpxchg.org, herbert@gondor.apana.org.au, linux-crypto@vger.kernel.org, linux-mm@kvack.org, nphamcs@gmail.com, yosryahmed@google.com, zhouchengming@bytedance.com Cc: chriscli@google.com, chrisl@kernel.org, ddstreet@ieee.org, linux-kernel@vger.kernel.org, sjenning@redhat.com, vitaly.wool@konsulko.com, Barry Song , Yang Shen , Zhou Wang , Tom Zanussi Subject: [PATCH v4 1/3] crypto: introduce crypto_acomp_get_alg_flags to expose algorithm flags Date: Tue, 20 Feb 2024 15:55:43 +1300 Message-Id: <20240220025545.194886-2-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240220025545.194886-1-21cnbao@gmail.com> References: <20240220025545.194886-1-21cnbao@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: C3C78C001C X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: f9njxfpruest3irbo1wdc4omzz8jq98y X-HE-Tag: 1708397772-948378 X-HE-Meta: U2FsdGVkX1/voBrcWN72Y96BqG/SJBo+ELxa2ExDiy3bIYJnicxg/zcYtX0TVQ0QHEtQVYglMtvFkmkKjv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1Wpyl2l6TAgUjhanpbTeng/YjbH23Z01BwuebdQlQBo4xmPt6C3V8WZcc6sDs1wb/BGe5QaP2pf1srCG0nDnBxXF7XO3hLHrieqSKtb+gbu2LxfHYqGPnI9bU2K+EqORaWTgp2n8NMS0+xfI69OEP9IpLYuGiwiP0qGd7EF8w6E7+SLJYY7TNcU+TsW6130PInlu2TqGpDomqXlxfsjhiJbeVCG4PKSU8hA8z9UrO2MH8g0UQglx8c7PAh70TEaFWiaa3BrFgMZCwvJK+6qbW5zAq6qojqcKTOXBuolb+iOdurDUWiNlRPkKJWEfo4wRlP3nLpGBZjSp8u7SfY0rKxFO4Hpx8CQMKTJWHxAnyh8MyDwdZMyXs4kzJQN1cBFri1enEDml5BRb4wvNupdUrVA64qBv8NpbexhEiowFZr/fOeJkkyXzzfcrc+UHNHoSAss680usJqznXnlxVGpOMJBJVjenMNBIwrDeYzYmeXw= 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: From: Barry Song acomp's users might want to know algorithm flags to optimize themselves. One typical user which can benefit from exposed alg flags is zswap. In zswap, zsmalloc is the most commonly used allocator for (and perhaps the only one). For zsmalloc, we cannot sleep while we map the compressed memory, so we copy it to a temporary buffer. By knowing the alg won't sleep can help zswap to avoid the need for a buffer. This shows noticeable improvement in load/store latency of zswap. This patch also fixes the missing ASYNC cra_flags in Intel iaa and Hisilicon zip drivers. Cc: Yang Shen Cc: Zhou Wang Cc: Tom Zanussi Signed-off-by: Barry Song --- drivers/crypto/hisilicon/zip/zip_crypto.c | 1 + drivers/crypto/intel/iaa/iaa_crypto_main.c | 1 + include/crypto/acompress.h | 5 +++++ include/linux/crypto.h | 5 +++++ 4 files changed, 12 insertions(+) diff --git a/drivers/crypto/hisilicon/zip/zip_crypto.c b/drivers/crypto/hisilicon/zip/zip_crypto.c index c650c741a18d..94e2d66b04b6 100644 --- a/drivers/crypto/hisilicon/zip/zip_crypto.c +++ b/drivers/crypto/hisilicon/zip/zip_crypto.c @@ -591,6 +591,7 @@ static struct acomp_alg hisi_zip_acomp_deflate = { .base = { .cra_name = "deflate", .cra_driver_name = "hisi-deflate-acomp", + .cra_flags = CRYPTO_ALG_ASYNC, .cra_module = THIS_MODULE, .cra_priority = HZIP_ALG_PRIORITY, .cra_ctxsize = sizeof(struct hisi_zip_ctx), diff --git a/drivers/crypto/intel/iaa/iaa_crypto_main.c b/drivers/crypto/intel/iaa/iaa_crypto_main.c index dfd3baf0a8d8..91adf9d76a2e 100644 --- a/drivers/crypto/intel/iaa/iaa_crypto_main.c +++ b/drivers/crypto/intel/iaa/iaa_crypto_main.c @@ -1916,6 +1916,7 @@ static struct acomp_alg iaa_acomp_fixed_deflate = { .base = { .cra_name = "deflate", .cra_driver_name = "deflate-iaa", + .cra_flags = CRYPTO_ALG_ASYNC, .cra_ctxsize = sizeof(struct iaa_compression_ctx), .cra_module = THIS_MODULE, .cra_priority = IAA_ALG_PRIORITY, diff --git a/include/crypto/acompress.h b/include/crypto/acompress.h index 574cffc90730..07bd8f6bc79a 100644 --- a/include/crypto/acompress.h +++ b/include/crypto/acompress.h @@ -160,6 +160,11 @@ static inline void acomp_request_set_tfm(struct acomp_req *req, req->base.tfm = crypto_acomp_tfm(tfm); } +static inline u32 crypto_acomp_get_alg_flags(struct crypto_acomp *tfm) +{ + return crypto_tfm_alg_flags(crypto_acomp_tfm(tfm)); +} + static inline struct crypto_acomp *crypto_acomp_reqtfm(struct acomp_req *req) { return __crypto_acomp_tfm(req->base.tfm); diff --git a/include/linux/crypto.h b/include/linux/crypto.h index b164da5e129e..811bfaf8b6f8 100644 --- a/include/linux/crypto.h +++ b/include/linux/crypto.h @@ -467,6 +467,11 @@ static inline unsigned int crypto_tfm_alg_blocksize(struct crypto_tfm *tfm) return tfm->__crt_alg->cra_blocksize; } +static inline unsigned int crypto_tfm_alg_flags(struct crypto_tfm *tfm) +{ + return tfm->__crt_alg->cra_flags; +} + static inline unsigned int crypto_tfm_alg_alignmask(struct crypto_tfm *tfm) { return tfm->__crt_alg->cra_alignmask;