Received: by 2002:ab2:3c46:0:b0:1f5:f2ab:c469 with SMTP id x6csp193983lqf; Fri, 26 Apr 2024 04:10:31 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWtP9abTiqEZZd5FdFK8ON2Q64lBzuylQqgHerCuJCqx6jPBZNkC88o9HMheL1KZjKBvkxu32e2augabamiqL3IyKnc+BoxR9dM0OfEDw== X-Google-Smtp-Source: AGHT+IHjT3rHqcz7ri0wpyxs6N93wVNOWTgKIXUSj5ehQNWQ3WTatLlfrF3KvIxIdWduvhr9zWNF X-Received: by 2002:a17:90b:1e0f:b0:2a4:e9d:9888 with SMTP id pg15-20020a17090b1e0f00b002a40e9d9888mr2208315pjb.16.1714129831505; Fri, 26 Apr 2024 04:10:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714129831; cv=pass; d=google.com; s=arc-20160816; b=ClGTpWlnOPu7aaP6F1EIwnsTdKeQzkKykna2jeTxXUXL7G83z05JXk1Wnghf0XLVS8 eDzki3Ey3DJgWzd4RcneCSWeyjLHtsTkrT7d/tlQmLe85nAe93qzXcFPTiLrRBVVhYm7 MpuIpp3N8VnNWSQ+VkioZ913OuAyE9BZqHlnNTev8JF/BwdXGMYReumctI/oJ7vAmzS2 LTsyWLI9bqSzz5UKkOQCbMtINOMXoE2wlTTngstJ7UNZG3ntu3gnHCTtqhb7NTXED+tS uAnQ/kqZcHRVs+awQ5eccmhN8L1o53PiCiOkpXoS9LE8707EMaW44PajrITLEXjlIO5c LOVw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:organization:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=SXqAMI5ty4tAQTxGJoPG7QW8TvoXcUXVlKqJBF75cTw=; fh=eE9ID1VSvblbjLwHaUggvxi1lShWgRu3iz6ofcuQTes=; b=C16FeK9hMLCxSjS8k5dJD5L5sVVFrzLU5A7dB/+KPXYuLSVXes2T1m71LR+GW88GvH BnmtwU46LOVtAsy56LIwP36NQxk+7dupOwWn158I1/15BCxzY+udXpvoLBd5nxakZCx2 sYencatFoF6QVXjh6igsMm6+JSCADOcY7aErlmg7mm2mvcpf/IFyJ8CwqXIJ9pRpIXQC 8n1afr9jRE0WRSWuuI3Gbd8mFOUSTRC0wbxasPw8H1uwebrr/joU4B19LdhM3MJzbdrB OY07wtFleeXwCBv3G1PFGp9+oePMdZEPa0vYkMLlutUYEAndZKN+n8ZZ1Nj0A887Poe/ hqNw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="RTLRs/l+"; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-crypto+bounces-3882-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-crypto+bounces-3882-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id br11-20020a17090b0f0b00b002ad02baafb6si10999535pjb.103.2024.04.26.04.10.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Apr 2024 04:10:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto+bounces-3882-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="RTLRs/l+"; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-crypto+bounces-3882-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-crypto+bounces-3882-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id E5BE928455B for ; Fri, 26 Apr 2024 11:10:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C7A60145341; Fri, 26 Apr 2024 11:10:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="RTLRs/l+" X-Original-To: linux-crypto@vger.kernel.org Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 87B7A14532D; Fri, 26 Apr 2024 11:10:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.11 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714129810; cv=none; b=aJb+U4VRYDOx8q3O945UoccSJm33MfjeQ3zh3axddiIgO4MuORiPbooKeZqMYYOAGn1DkuMHZyi/h9odokCQyNMkfy435OOKQZ9eNBqWJOFHS8cLGj+u72z9NX+UqyC9M6Q54MvtG5Y3Abu/0Vw0nywcuXCOqRvQ2hMS+eECsCo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714129810; c=relaxed/simple; bh=JQTIe8JMxkNxe5JfmeBIbVWz9NGiNeER2iB56mvI2JA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=opw2G6/Z+UF4801N9w99cw2SgmR3KHiea4w8QgC4Oj/nO74/Hb835FDTF1jeVTKVibl5iL/jgptlW7htnqzLs/X9u9nVHycmux+qHM2SAPhm2EplonSDvIjW3uOA+mL5gvJbiG3/zhtYOJHVm1+lIgF1I/0bDq/vOiBFUsCxn54= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=RTLRs/l+; arc=none smtp.client-ip=192.198.163.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1714129809; x=1745665809; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=JQTIe8JMxkNxe5JfmeBIbVWz9NGiNeER2iB56mvI2JA=; b=RTLRs/l+llQEEVP7LHg3394BRU+g7KPkJtpuWPQ7O7KyifOLzNhlPru7 Gj0MTjyKmIY+aB/7ayUD94meKWO/c6Ce2Kv34MvUsmcQfPQ0gNVZGsMZ1 5szTkxH5A/FkyftSmoQU3oThx/2s0zpo78OAhUTMXV0xI19tQzktDtLym 6dh/T3qL6bj2nm2Ryp/tJNTvw1BMPrtuUJdtkXwYN7E4y8DxRqb66DKkJ hWJ32k1DVuSvukq4WbTl5OqfR6PkN3ayoOgjj/8EgcpFnNN/9ZEGJ94F3 02lJRWXIOuWZTxwqAnY9It4gqTDvwh5/49Dshh6z4H5FZIbFaEHeoMng6 Q==; X-CSE-ConnectionGUID: NyKx0v9vSemB51EDXFg4FA== X-CSE-MsgGUID: q8fXYOY2SDaxUlACQYtLbA== X-IronPort-AV: E=McAfee;i="6600,9927,11055"; a="20474068" X-IronPort-AV: E=Sophos;i="6.07,232,1708416000"; d="scan'208";a="20474068" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Apr 2024 04:10:08 -0700 X-CSE-ConnectionGUID: dNgowoCqTdqrrUIRnOLusw== X-CSE-MsgGUID: fhK8fq9ASAyJ8H6m2n3snA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,232,1708416000"; d="scan'208";a="30030901" Received: from unknown (HELO silpixa00400314.ger.corp.intel.com) ([10.237.222.216]) by fmviesa004.fm.intel.com with ESMTP; 26 Apr 2024 04:10:04 -0700 From: Giovanni Cabiddu To: clm@fb.com, josef@toxicpanda.com, dsterba@suse.com, herbert@gondor.apana.org.au Cc: linux-btrfs@vger.kernel.org, linux-crypto@vger.kernel.org, qat-linux@intel.com, embg@meta.com, cyan@meta.com, brian.will@intel.com, weigang.li@intel.com, Giovanni Cabiddu Subject: [RFC PATCH 2/6] Revert "crypto: deflate - Remove zlib-deflate" Date: Fri, 26 Apr 2024 11:54:25 +0100 Message-ID: <20240426110941.5456-3-giovanni.cabiddu@intel.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240426110941.5456-1-giovanni.cabiddu@intel.com> References: <20240426110941.5456-1-giovanni.cabiddu@intel.com> Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Organization: Intel Research and Development Ireland Ltd - Co. Reg. #308263 - Collinstown Industrial Park, Leixlip, County Kildare - Ireland Content-Transfer-Encoding: 8bit This reverts commit 62a465c25e99b9a98259a6b7f5bb759f5296d501. --- crypto/deflate.c | 61 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 17 deletions(-) diff --git a/crypto/deflate.c b/crypto/deflate.c index 6e31e0db0e86..b2a46f6dc961 100644 --- a/crypto/deflate.c +++ b/crypto/deflate.c @@ -39,20 +39,24 @@ struct deflate_ctx { struct z_stream_s decomp_stream; }; -static int deflate_comp_init(struct deflate_ctx *ctx) +static int deflate_comp_init(struct deflate_ctx *ctx, int format) { int ret = 0; struct z_stream_s *stream = &ctx->comp_stream; stream->workspace = vzalloc(zlib_deflate_workspacesize( - -DEFLATE_DEF_WINBITS, MAX_MEM_LEVEL)); + MAX_WBITS, MAX_MEM_LEVEL)); if (!stream->workspace) { ret = -ENOMEM; goto out; } - ret = zlib_deflateInit2(stream, DEFLATE_DEF_LEVEL, Z_DEFLATED, - -DEFLATE_DEF_WINBITS, DEFLATE_DEF_MEMLEVEL, - Z_DEFAULT_STRATEGY); + if (format) + ret = zlib_deflateInit(stream, 3); + else + ret = zlib_deflateInit2(stream, DEFLATE_DEF_LEVEL, Z_DEFLATED, + -DEFLATE_DEF_WINBITS, + DEFLATE_DEF_MEMLEVEL, + Z_DEFAULT_STRATEGY); if (ret != Z_OK) { ret = -EINVAL; goto out_free; @@ -64,7 +68,7 @@ static int deflate_comp_init(struct deflate_ctx *ctx) goto out; } -static int deflate_decomp_init(struct deflate_ctx *ctx) +static int deflate_decomp_init(struct deflate_ctx *ctx, int format) { int ret = 0; struct z_stream_s *stream = &ctx->decomp_stream; @@ -74,7 +78,10 @@ static int deflate_decomp_init(struct deflate_ctx *ctx) ret = -ENOMEM; goto out; } - ret = zlib_inflateInit2(stream, -DEFLATE_DEF_WINBITS); + if (format) + ret = zlib_inflateInit(stream); + else + ret = zlib_inflateInit2(stream, -DEFLATE_DEF_WINBITS); if (ret != Z_OK) { ret = -EINVAL; goto out_free; @@ -98,21 +105,21 @@ static void deflate_decomp_exit(struct deflate_ctx *ctx) vfree(ctx->decomp_stream.workspace); } -static int __deflate_init(void *ctx) +static int __deflate_init(void *ctx, int format) { int ret; - ret = deflate_comp_init(ctx); + ret = deflate_comp_init(ctx, format); if (ret) goto out; - ret = deflate_decomp_init(ctx); + ret = deflate_decomp_init(ctx, format); if (ret) deflate_comp_exit(ctx); out: return ret; } -static void *deflate_alloc_ctx(struct crypto_scomp *tfm) +static void *gen_deflate_alloc_ctx(struct crypto_scomp *tfm, int format) { struct deflate_ctx *ctx; int ret; @@ -121,7 +128,7 @@ static void *deflate_alloc_ctx(struct crypto_scomp *tfm) if (!ctx) return ERR_PTR(-ENOMEM); - ret = __deflate_init(ctx); + ret = __deflate_init(ctx, format); if (ret) { kfree(ctx); return ERR_PTR(ret); @@ -130,11 +137,21 @@ static void *deflate_alloc_ctx(struct crypto_scomp *tfm) return ctx; } +static void *deflate_alloc_ctx(struct crypto_scomp *tfm) +{ + return gen_deflate_alloc_ctx(tfm, 0); +} + +static void *zlib_deflate_alloc_ctx(struct crypto_scomp *tfm) +{ + return gen_deflate_alloc_ctx(tfm, 1); +} + static int deflate_init(struct crypto_tfm *tfm) { struct deflate_ctx *ctx = crypto_tfm_ctx(tfm); - return __deflate_init(ctx); + return __deflate_init(ctx, 0); } static void __deflate_exit(void *ctx) @@ -269,7 +286,7 @@ static struct crypto_alg alg = { .coa_decompress = deflate_decompress } } }; -static struct scomp_alg scomp = { +static struct scomp_alg scomp[] = { { .alloc_ctx = deflate_alloc_ctx, .free_ctx = deflate_free_ctx, .compress = deflate_scompress, @@ -279,7 +296,17 @@ static struct scomp_alg scomp = { .cra_driver_name = "deflate-scomp", .cra_module = THIS_MODULE, } -}; +}, { + .alloc_ctx = zlib_deflate_alloc_ctx, + .free_ctx = deflate_free_ctx, + .compress = deflate_scompress, + .decompress = deflate_sdecompress, + .base = { + .cra_name = "zlib-deflate", + .cra_driver_name = "zlib-deflate-scomp", + .cra_module = THIS_MODULE, + } +} }; static int __init deflate_mod_init(void) { @@ -289,7 +316,7 @@ static int __init deflate_mod_init(void) if (ret) return ret; - ret = crypto_register_scomp(&scomp); + ret = crypto_register_scomps(scomp, ARRAY_SIZE(scomp)); if (ret) { crypto_unregister_alg(&alg); return ret; @@ -301,7 +328,7 @@ static int __init deflate_mod_init(void) static void __exit deflate_mod_fini(void) { crypto_unregister_alg(&alg); - crypto_unregister_scomp(&scomp); + crypto_unregister_scomps(scomp, ARRAY_SIZE(scomp)); } subsys_initcall(deflate_mod_init); -- 2.44.0