From patchwork Sat Feb 17 04:51:00 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: 13561231 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 3174EC48BC3 for ; Sat, 17 Feb 2024 04:51:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 87B856B00A5; Fri, 16 Feb 2024 23:51:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 82B626B00A6; Fri, 16 Feb 2024 23:51:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6CADA6B00A7; Fri, 16 Feb 2024 23:51:31 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 565D76B00A5 for ; Fri, 16 Feb 2024 23:51:31 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 06188160135 for ; Sat, 17 Feb 2024 04:51:31 +0000 (UTC) X-FDA: 81800072382.09.D83AEF1 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by imf14.hostedemail.com (Postfix) with ESMTP id 3F1EF100008 for ; Sat, 17 Feb 2024 04:51:29 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=etMCtw4G; spf=pass (imf14.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.210.170 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708145489; a=rsa-sha256; cv=none; b=dSU3dHUsD37PBtEWwiK3TyX3te//Z2N1ly0JoXwppWLH1wsXHMELTXZRwmnfWIOzc4Km/t gDCw1vA4sRDeMpYUOKggOR6is7jXvarsJctgp4CSuWyzKEbf84uwz87G4H7t4Ca3N1tqhB S2wkbmybfTKRYrlZo33ZJhzYb9Cd1Ro= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=etMCtw4G; spf=pass (imf14.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.210.170 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=1708145489; 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=lBwGphqaBGgnqVopSLPzNP3HsID/sdo6yu3ftKGqOG4=; b=SexYvN1Ft699YrPJSfRccwIkRvp2NVYinwxD9wtePUlnXVAkxYQcldsJIl+XL+isKgKH9P lzJWoBzCszC823/BMBucRC9nUKvGJCL8mN2lQcyF8Tiv/FlfhKQ0jTc559UkWa3Fel7Gw4 fWF8xu9ibVv+03AeKjn4D+/kiVcpP4U= Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-6e1126f57f1so1578128b3a.2 for ; Fri, 16 Feb 2024 20:51:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708145488; x=1708750288; 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=lBwGphqaBGgnqVopSLPzNP3HsID/sdo6yu3ftKGqOG4=; b=etMCtw4GEiypS8v68q43QuMtWFJCttI5gP/MeaB/zTRhmL5B9ygFmeCYt2caB3nRlk 3PvFnAArBoToRTiA9hpYM6eepSqhEOqtomL3CYo6FkSyEpObdgqyu8SiEZuc6TLFqfNC 9wQbejhH++vlabhENYI+qacsbn8GX0HeLxtOcr4qYFPRsoOM8HR1qEykIED0uCf75prH g3DvpEAhprYKbGP/VrCSVm625B8vJNGOl/lOvKswgFRqFtUQPf70wRTtufkxlS0g1R7H TVRJPEdEXPcyfwykoE28Zr2UXLzFI5JsFSA9OWh0C1V+Ayah0l+hZxIiI94yjOTRRQEf ZDbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708145488; x=1708750288; 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=lBwGphqaBGgnqVopSLPzNP3HsID/sdo6yu3ftKGqOG4=; b=aaaR/ewrouogviZbxroknzrKQDbPxyw0CYLsewkxjRY280z9Pvbd7RVZMDkjxwyyh5 JCfEXCeSvAJvhMYw8YTGMqhfWQkDvatkPG7GksKn6Cg6HMETqgucW54ScehgZids5oCw IcmLlX1cEvbp9xmdjnu64W46F+C3CNDISoLvICD6NxwSVnQq1ONcbZcpZQVcWM4iyeyf evbKk3MnLxdnXAkJOrlYR2aJyeaXqQXBMqdBhNITrSEEP3tK76pHQWmSCN/WaNMfJY7w mfYUeRvgaB0DODn6cUTXs4b7JV548fMTLjxsK0Q2sO5ITTxqBl33AvYyb5m3X9+rHUNJ 5Nbg== X-Forwarded-Encrypted: i=1; AJvYcCXrUQ+DdGyYuuQRi+fIpiFwmoebSjm5focj2HHFjj5owZ5z0Hlse3bIOsAeCQHeqhLxAxUmTnzjOu/8nb95T6h0tt4= X-Gm-Message-State: AOJu0Yylgjmcuq+NLYrYM/WhwfA8joPEAfK+bdI0Fl+F9hoEzXC0If2l oRLMPMeefV/IxYqAo8tb7It4IWX8AKHPQ9XJaPhJD/Ya+xdgHlwB X-Google-Smtp-Source: AGHT+IHDHukVZC3Tl6VbSP7cvk6J3RQAkpvZafO4xOt+DersUqDTPAn7tJNGZjo9EuDadh2/3wlOaA== X-Received: by 2002:a05:6a00:80b:b0:6e0:71bd:3322 with SMTP id m11-20020a056a00080b00b006e071bd3322mr9708070pfk.10.1708145487782; Fri, 16 Feb 2024 20:51:27 -0800 (PST) Received: from barry-desktop.hub ([2407:7000:8942:5500:e82e:22f2:1bdb:989f]) by smtp.gmail.com with ESMTPSA id n14-20020a635c4e000000b005dc2ca5b667sm610703pgm.10.2024.02.16.20.51.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 20:51:27 -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 Subject: [PATCH v3 1/3] crypto: introduce acomp_is_sleepable to expose if comp drivers might sleep Date: Sat, 17 Feb 2024 17:51:00 +1300 Message-Id: <20240217045102.55339-2-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240217045102.55339-1-21cnbao@gmail.com> References: <20240217045102.55339-1-21cnbao@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 3F1EF100008 X-Stat-Signature: zej7pq8dko1ryranptfcdy76tfy9tdmx X-Rspam-User: X-HE-Tag: 1708145489-735161 X-HE-Meta: U2FsdGVkX19jOiG4rUav6sJ0cL2DxFD1mIeq1IqGsfh6u2qzGqqHCLNaZQdZj5xTKI4woumYrmtiYN5O0GZ5N+eASRoX1nsWC1rkkDlMNfRt7CV5GJWa//XvFwNtnAy4wHnuh0O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ko79+K+eF8CgwrPNZx3T8qA/ZOqe15+01edeDpHFRhpPaBr3w9osMapTyi4JFl3F88TMWdRQOaJD8g901/TVNuxuwhqStf9IVk7DBjgB3zDwc3IeVKjnqjGnUYhToazyLc24vFfiEPgamvm6eapMVa6VEg75KtoovmlP+K1IBGMe3mbIfKXe7rcgX+hqf+vrt1X5UYcTwmmhGZFbyefnEDbZQxAqHKUguvQYVWq2pLVq9rmOluRhHMSmMG9eGqQ80amdDjU9kNUB/doT/o7kuqatVeNvf8iGQswCcu1JNJq4qTPaqsQnydTbDrba9ToEeCm1590pMNl9k8i/05QfjEe/7pbhl6IugpA9x/9RjzRB8RsEcm63+fuUtfZnFnxTFHKhek9KZqVZ54RBTAJoVqZD8+FAl46tWnED 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 Almost all CPU-based compressors/decompressors are actually synchronous though they support acomp APIs. While some hardware has hardware-based accelerators to offload CPU's work such as hisilicon and intel/qat/, their drivers are working in async mode. Letting acomp's users know exactly if the acomp is really async will help users know if the compression and decompression procedure can sleep. Generally speaking, async and sleepable are semantically similar but not equal. But for compress drivers, they are actually equal at least due to the below facts. Firstly, scompress drivers - crypto/deflate.c, lz4.c, zstd.c, lzo.c etc have no sleep. Secondly, zRAM has been using these scompress drivers for years in atomic contexts, and never worried those drivers going to sleep. Signed-off-by: Barry Song Tested-by: Chengming Zhou --- crypto/acompress.c | 8 ++++++++ include/crypto/acompress.h | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/crypto/acompress.c b/crypto/acompress.c index 1c682810a484..fa15df394a4c 100644 --- a/crypto/acompress.c +++ b/crypto/acompress.c @@ -152,6 +152,14 @@ struct crypto_acomp *crypto_alloc_acomp_node(const char *alg_name, u32 type, } EXPORT_SYMBOL_GPL(crypto_alloc_acomp_node); +bool acomp_is_sleepable(struct crypto_acomp *acomp) +{ + struct crypto_tfm *tfm = crypto_acomp_tfm(acomp); + + return tfm->__crt_alg->cra_type == &crypto_acomp_type; +} +EXPORT_SYMBOL_GPL(acomp_is_sleepable); + struct acomp_req *acomp_request_alloc(struct crypto_acomp *acomp) { struct crypto_tfm *tfm = crypto_acomp_tfm(acomp); diff --git a/include/crypto/acompress.h b/include/crypto/acompress.h index 574cffc90730..88ca33532313 100644 --- a/include/crypto/acompress.h +++ b/include/crypto/acompress.h @@ -204,6 +204,15 @@ struct acomp_req *acomp_request_alloc(struct crypto_acomp *tfm); */ void acomp_request_free(struct acomp_req *req); +/** + * acomp_is_sleepable() -- check if an acomp is sleepable + * + * @tfm: ACOMPRESS tfm handle allocated with crypto_alloc_acomp() + * + * Return: true if the acomp is sleepable, otherwise, false + */ +bool acomp_is_sleepable(struct crypto_acomp *tfm); + /** * acomp_request_set_callback() -- Sets an asynchronous callback *