From patchwork Fri Apr 26 10:54:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Cabiddu, Giovanni" X-Patchwork-Id: 792450 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 262BB1448DF; Fri, 26 Apr 2024 11:10:04 +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=1714129805; cv=none; b=ooQk12jF6mrG0jF/2PuOKMyE3zs/lQzEvVnDFvCGoIeRUIN+T+SG81qmAcD2lZb30s7Jmegkl0meyOVlSgxZs6urpCVAT4NVH/Jlafe1qzdlokW9xRa89Co9Y+wLrlNkmOk7IG4A+mBDcekaQlxcayKdPi/kdKFlDLpF7CK65M8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714129805; c=relaxed/simple; bh=C6zwMGNw1Pfmrr7no50l7uH5Ymdi1QlJcQQQ87iPgkw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WZTHCHPm042rFdU1Y0fbrpbXHGwy86HYmWCiFEvfEkFAZWxo//6pyET4xWaMeYlbDsrXbo8sJ7GtI8vj7kFHh3fafND5CjTOlmC4g0xQq5ApUofYxCGTNkPeFcJBsAfZeIYcl1AXeN1g0HHt+MHtPlgoDzyoBLoUzj3dL90EGak= 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=TMIc2Elf; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="TMIc2Elf" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1714129804; x=1745665804; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=C6zwMGNw1Pfmrr7no50l7uH5Ymdi1QlJcQQQ87iPgkw=; b=TMIc2ElfWFv0IN7bPzdTlLYDQIxaQAkNqO84p3s7e5znxV2QiKMqXdI7 qtUEBL3JyFCvva88Ov2qeOUPAedKtNLX5WwB5XleVg4UXpsjaZTjpiwG/ igyHbq1puJR/fu6SiQdv/L7Ob0JoxxfNiQRY6v3d7nkFN85US8HR3bVNo Kc9Be4gXj1BG8TJuITYzs/vBZ/ln34Pjtfwm2EgELZ0kr2AmK7K4d7/FA iHw6Cxvil+ab1g9Ga/fk5w2+Q9cF3TSwx+4y8WFgrXoBTG8IZcWKtFx51 oQGIOOIeKvRcHtJb+3H8yP+zbxxMt/14SZcVmp8H8UDwEnmzjM7tfW6Mg Q==; X-CSE-ConnectionGUID: vX6aZOF3TLePOf5BbcEaUg== X-CSE-MsgGUID: qbd+KKHxQ361gO52+dbojg== X-IronPort-AV: E=McAfee;i="6600,9927,11055"; a="20474059" X-IronPort-AV: E=Sophos;i="6.07,232,1708416000"; d="scan'208";a="20474059" 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:04 -0700 X-CSE-ConnectionGUID: F79QqFACRQKhnxQq7r9pUw== X-CSE-MsgGUID: 7968Phl+SruEgmQlfrBD9A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,232,1708416000"; d="scan'208";a="30030866" 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:00 -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 1/6] Revert "crypto: testmgr - Remove zlib-deflate" Date: Fri, 26 Apr 2024 11:54:24 +0100 Message-ID: <20240426110941.5456-2-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 This reverts commit 30febae71c6182e0762dc7744737012b4f8e6a6d. --- crypto/testmgr.c | 10 +++++++ crypto/testmgr.h | 75 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) diff --git a/crypto/testmgr.c b/crypto/testmgr.c index 00f5a6cf341a..ab904ab74bee 100644 --- a/crypto/testmgr.c +++ b/crypto/testmgr.c @@ -5733,6 +5733,16 @@ static const struct alg_test_desc alg_test_descs[] = { .suite = { .hash = __VECS(xxhash64_tv_template) } + }, { + .alg = "zlib-deflate", + .test = alg_test_comp, + .fips_allowed = 1, + .suite = { + .comp = { + .comp = __VECS(zlib_deflate_comp_tv_template), + .decomp = __VECS(zlib_deflate_decomp_tv_template) + } + } }, { .alg = "zstd", .test = alg_test_comp, diff --git a/crypto/testmgr.h b/crypto/testmgr.h index 5350cfd9d325..71d87a2fd842 100644 --- a/crypto/testmgr.h +++ b/crypto/testmgr.h @@ -34752,6 +34752,81 @@ static const struct comp_testvec deflate_decomp_tv_template[] = { }, }; +static const struct comp_testvec zlib_deflate_comp_tv_template[] = { + { + .inlen = 70, + .outlen = 44, + .input = "Join us now and share the software " + "Join us now and share the software ", + .output = "\x78\x5e\xf3\xca\xcf\xcc\x53\x28" + "\x2d\x56\xc8\xcb\x2f\x57\x48\xcc" + "\x4b\x51\x28\xce\x48\x2c\x4a\x55" + "\x28\xc9\x48\x55\x28\xce\x4f\x2b" + "\x29\x07\x71\xbc\x08\x2b\x01\x00" + "\x7c\x65\x19\x3d", + }, { + .inlen = 191, + .outlen = 129, + .input = "This document describes a compression method based on the DEFLATE" + "compression algorithm. This document defines the application of " + "the DEFLATE algorithm to the IP Payload Compression Protocol.", + .output = "\x78\x5e\x5d\xce\x41\x0a\xc3\x30" + "\x0c\x04\xc0\xaf\xec\x0b\xf2\x87" + "\xd2\xa6\x50\xe8\xc1\x07\x7f\x40" + "\xb1\x95\x5a\x60\x5b\xc6\x56\x0f" + "\xfd\x7d\x93\x1e\x42\xe8\x51\xec" + "\xee\x20\x9f\x64\x20\x6a\x78\x17" + "\xae\x86\xc8\x23\x74\x59\x78\x80" + "\x10\xb4\xb4\xce\x63\x88\x56\x14" + "\xb6\xa4\x11\x0b\x0d\x8e\xd8\x6e" + "\x4b\x8c\xdb\x7c\x7f\x5e\xfc\x7c" + "\xae\x51\x7e\x69\x17\x4b\x65\x02" + "\xfc\x1f\xbc\x4a\xdd\xd8\x7d\x48" + "\xad\x65\x09\x64\x3b\xac\xeb\xd9" + "\xc2\x01\xc0\xf4\x17\x3c\x1c\x1c" + "\x7d\xb2\x52\xc4\xf5\xf4\x8f\xeb" + "\x6a\x1a\x34\x4f\x5f\x2e\x32\x45" + "\x4e", + }, +}; + +static const struct comp_testvec zlib_deflate_decomp_tv_template[] = { + { + .inlen = 128, + .outlen = 191, + .input = "\x78\x9c\x5d\x8d\x31\x0e\xc2\x30" + "\x10\x04\xbf\xb2\x2f\xc8\x1f\x10" + "\x04\x09\x89\xc2\x85\x3f\x70\xb1" + "\x2f\xf8\x24\xdb\x67\xd9\x47\xc1" + "\xef\x49\x68\x12\x51\xae\x76\x67" + "\xd6\x27\x19\x88\x1a\xde\x85\xab" + "\x21\xf2\x08\x5d\x16\x1e\x20\x04" + "\x2d\xad\xf3\x18\xa2\x15\x85\x2d" + "\x69\xc4\x42\x83\x23\xb6\x6c\x89" + "\x71\x9b\xef\xcf\x8b\x9f\xcf\x33" + "\xca\x2f\xed\x62\xa9\x4c\x80\xff" + "\x13\xaf\x52\x37\xed\x0e\x52\x6b" + "\x59\x02\xd9\x4e\xe8\x7a\x76\x1d" + "\x02\x98\xfe\x8a\x87\x83\xa3\x4f" + "\x56\x8a\xb8\x9e\x8e\x5c\x57\xd3" + "\xa0\x79\xfa\x02\x2e\x32\x45\x4e", + .output = "This document describes a compression method based on the DEFLATE" + "compression algorithm. This document defines the application of " + "the DEFLATE algorithm to the IP Payload Compression Protocol.", + }, { + .inlen = 44, + .outlen = 70, + .input = "\x78\x9c\xf3\xca\xcf\xcc\x53\x28" + "\x2d\x56\xc8\xcb\x2f\x57\x48\xcc" + "\x4b\x51\x28\xce\x48\x2c\x4a\x55" + "\x28\xc9\x48\x55\x28\xce\x4f\x2b" + "\x29\x07\x71\xbc\x08\x2b\x01\x00" + "\x7c\x65\x19\x3d", + .output = "Join us now and share the software " + "Join us now and share the software ", + }, +}; + /* * LZO test vectors (null-terminated strings). */ From patchwork Fri Apr 26 10:54:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Cabiddu, Giovanni" X-Patchwork-Id: 793851 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="RTLRs/l+" 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 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); From patchwork Fri Apr 26 10:54:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Cabiddu, Giovanni" X-Patchwork-Id: 792449 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 DE95714532D; Fri, 26 Apr 2024 11:10:11 +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=1714129813; cv=none; b=W+sCvAlRZoVmg/fbeya7ne1wni7cZjg8o7Tuj4SNI3jvIiwIIMjKE1bRnMbILRkJp83gr/50G9Wk8OwSwdzIkBjHt+dLICrnlbffVonQM8Kj439URjevnpkVtLL7oTJ+dKH5QUciUzTROQB8Rkxa6K/z61sg6gBBN+oRplu1Owg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714129813; c=relaxed/simple; bh=uC7DwOk0O0Wkj3or1UnUhWcE9A9EC56hI7kWvDqjUX4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=niooT3Y09G6pKlkQy0KqcpUbmShDLRuDxEUeOZtqL4SubS6Rmc1oHMFFX6+YUCHWK5Jbu8KqfUO63X96n+cKC7WLibo5m6dYXvhgaBUThqXFhTz3oqJHrJ2KvZVeD9rhK5H3liXTZ+PnTDVHWLkQ4z3QVC2X6Rdl9ciRAdDnu2w= 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=gmU3sH+F; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="gmU3sH+F" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1714129812; x=1745665812; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uC7DwOk0O0Wkj3or1UnUhWcE9A9EC56hI7kWvDqjUX4=; b=gmU3sH+Fjca3CTt9nTEQR4jZRIauezYqvjtj0l+NrTg6s2ercjzyM3g6 b9f1wF9pOt4Qw2G8gKuwy/pf+MpNMLHtZmEEcD+Rd7GHyTtF2chy3IxaQ W2CWt8oEX9G1qU2+NkTmZ1q5Y5MDeyNZORpbsrPP7WRMt1hjrUltYaE/5 8J7Ha36oqeTULeGAPtUXbcG+y1mNZ91SbzzVqwUMPKPDYyVTCbEB145eU AWCgTJPgKdJkUBjePw/78j6kQPs3Vg03MvZyz4q18Wvt5uHdRZQTHSXZK 870KwHn+fWLO3LX+l1zmvk1ZKFLjnaiNgMAHW5aL7A+Q+mn1TgQ9+bAVc A==; X-CSE-ConnectionGUID: XyMB650WSkeqTcLz02Dc0A== X-CSE-MsgGUID: H4uoVPscRqmYBjfpWXII6g== X-IronPort-AV: E=McAfee;i="6600,9927,11055"; a="20474079" X-IronPort-AV: E=Sophos;i="6.07,232,1708416000"; d="scan'208";a="20474079" 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:12 -0700 X-CSE-ConnectionGUID: GCNkBu6hST2zJcj3NidSfQ== X-CSE-MsgGUID: eOtKe1wYQ8qntGRdaGXlLw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,232,1708416000"; d="scan'208";a="30030918" 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:08 -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 3/6] Revert "crypto: qat - Remove zlib-deflate" Date: Fri, 26 Apr 2024 11:54:26 +0100 Message-ID: <20240426110941.5456-4-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 This reverts commit e9dd20e0e5f62d01d9404db2cf9824d1faebcf71. --- .../intel/qat/qat_common/qat_comp_algs.c | 129 +++++++++++++++++- 1 file changed, 128 insertions(+), 1 deletion(-) diff --git a/drivers/crypto/intel/qat/qat_common/qat_comp_algs.c b/drivers/crypto/intel/qat/qat_common/qat_comp_algs.c index 2ba4aa22e092..79de04cfa012 100644 --- a/drivers/crypto/intel/qat/qat_common/qat_comp_algs.c +++ b/drivers/crypto/intel/qat/qat_common/qat_comp_algs.c @@ -100,6 +100,69 @@ static void qat_comp_resubmit(struct work_struct *work) acomp_request_complete(areq, ret); } +static int parse_zlib_header(u16 zlib_h) +{ + int ret = -EINVAL; + __be16 header; + u8 *header_p; + u8 cmf, flg; + + header = cpu_to_be16(zlib_h); + header_p = (u8 *)&header; + + flg = header_p[0]; + cmf = header_p[1]; + + if (cmf >> QAT_RFC_1950_CM_OFFSET > QAT_RFC_1950_CM_DEFLATE_CINFO_32K) + return ret; + + if ((cmf & QAT_RFC_1950_CM_MASK) != QAT_RFC_1950_CM_DEFLATE) + return ret; + + if (flg & QAT_RFC_1950_DICT_MASK) + return ret; + + return 0; +} + +static int qat_comp_rfc1950_callback(struct qat_compression_req *qat_req, + void *resp) +{ + struct acomp_req *areq = qat_req->acompress_req; + enum direction dir = qat_req->dir; + __be32 qat_produced_adler; + + qat_produced_adler = cpu_to_be32(qat_comp_get_produced_adler32(resp)); + + if (dir == COMPRESSION) { + __be16 zlib_header; + + zlib_header = cpu_to_be16(QAT_RFC_1950_COMP_HDR); + scatterwalk_map_and_copy(&zlib_header, areq->dst, 0, QAT_RFC_1950_HDR_SIZE, 1); + areq->dlen += QAT_RFC_1950_HDR_SIZE; + + scatterwalk_map_and_copy(&qat_produced_adler, areq->dst, areq->dlen, + QAT_RFC_1950_FOOTER_SIZE, 1); + areq->dlen += QAT_RFC_1950_FOOTER_SIZE; + } else { + __be32 decomp_adler; + int footer_offset; + int consumed; + + consumed = qat_comp_get_consumed_ctr(resp); + footer_offset = consumed + QAT_RFC_1950_HDR_SIZE; + if (footer_offset + QAT_RFC_1950_FOOTER_SIZE > areq->slen) + return -EBADMSG; + + scatterwalk_map_and_copy(&decomp_adler, areq->src, footer_offset, + QAT_RFC_1950_FOOTER_SIZE, 0); + + if (qat_produced_adler != decomp_adler) + return -EBADMSG; + } + return 0; +} + static void qat_comp_generic_callback(struct qat_compression_req *qat_req, void *resp) { @@ -221,6 +284,18 @@ static void qat_comp_alg_exit_tfm(struct crypto_acomp *acomp_tfm) memset(ctx, 0, sizeof(*ctx)); } +static int qat_comp_alg_rfc1950_init_tfm(struct crypto_acomp *acomp_tfm) +{ + struct crypto_tfm *tfm = crypto_acomp_tfm(acomp_tfm); + struct qat_compression_ctx *ctx = crypto_tfm_ctx(tfm); + int ret; + + ret = qat_comp_alg_init_tfm(acomp_tfm); + ctx->qat_comp_callback = &qat_comp_rfc1950_callback; + + return ret; +} + static int qat_comp_alg_compress_decompress(struct acomp_req *areq, enum direction dir, unsigned int shdr, unsigned int sftr, unsigned int dhdr, unsigned int dftr) @@ -316,6 +391,43 @@ static int qat_comp_alg_decompress(struct acomp_req *req) return qat_comp_alg_compress_decompress(req, DECOMPRESSION, 0, 0, 0, 0); } +static int qat_comp_alg_rfc1950_compress(struct acomp_req *req) +{ + if (!req->dst && req->dlen != 0) + return -EINVAL; + + if (req->dst && req->dlen <= QAT_RFC_1950_HDR_SIZE + QAT_RFC_1950_FOOTER_SIZE) + return -EINVAL; + + return qat_comp_alg_compress_decompress(req, COMPRESSION, 0, 0, + QAT_RFC_1950_HDR_SIZE, + QAT_RFC_1950_FOOTER_SIZE); +} + +static int qat_comp_alg_rfc1950_decompress(struct acomp_req *req) +{ + struct crypto_acomp *acomp_tfm = crypto_acomp_reqtfm(req); + struct crypto_tfm *tfm = crypto_acomp_tfm(acomp_tfm); + struct qat_compression_ctx *ctx = crypto_tfm_ctx(tfm); + struct adf_accel_dev *accel_dev = ctx->inst->accel_dev; + u16 zlib_header; + int ret; + + if (req->slen <= QAT_RFC_1950_HDR_SIZE + QAT_RFC_1950_FOOTER_SIZE) + return -EBADMSG; + + scatterwalk_map_and_copy(&zlib_header, req->src, 0, QAT_RFC_1950_HDR_SIZE, 0); + + ret = parse_zlib_header(zlib_header); + if (ret) { + dev_dbg(&GET_DEV(accel_dev), "Error parsing zlib header\n"); + return ret; + } + + return qat_comp_alg_compress_decompress(req, DECOMPRESSION, QAT_RFC_1950_HDR_SIZE, + QAT_RFC_1950_FOOTER_SIZE, 0, 0); +} + static struct acomp_alg qat_acomp[] = { { .base = { .cra_name = "deflate", @@ -331,7 +443,22 @@ static struct acomp_alg qat_acomp[] = { { .decompress = qat_comp_alg_decompress, .dst_free = sgl_free, .reqsize = sizeof(struct qat_compression_req), -}}; +}, { + .base = { + .cra_name = "zlib-deflate", + .cra_driver_name = "qat_zlib_deflate", + .cra_priority = 4001, + .cra_flags = CRYPTO_ALG_ASYNC, + .cra_ctxsize = sizeof(struct qat_compression_ctx), + .cra_module = THIS_MODULE, + }, + .init = qat_comp_alg_rfc1950_init_tfm, + .exit = qat_comp_alg_exit_tfm, + .compress = qat_comp_alg_rfc1950_compress, + .decompress = qat_comp_alg_rfc1950_decompress, + .dst_free = sgl_free, + .reqsize = sizeof(struct qat_compression_req), +} }; int qat_comp_algs_register(void) { From patchwork Fri Apr 26 10:54:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Cabiddu, Giovanni" X-Patchwork-Id: 793850 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 40EE9144D2E; Fri, 26 Apr 2024 11:10:15 +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=1714129816; cv=none; b=CyI/88PM5KBcR5hZWq/hLuOqKsUfdPvnqzQo5cKxevNgcPm+LuLTTzjI2YF+QQJ5Mv2bLkSK8jzGfimzLATZ5fwtPlg4WpfBbASDzhuwiIaRIEqNUnpd2z3gwhrG69a7On4qhL9FMq3fPbJz2+ipyP+hNCSbGhwFISz/FCfu/hQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714129816; c=relaxed/simple; bh=E3lsNuPY2s3Q+h3/lR91Vlx3BxKcj68xT1Zz7FHBTtU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mQ0wag+rQ4vWazg0KIpb2RaIkTkJlZ0cFqGC4rRkmue+2JKzWEvKvRP1DTyU4cgpzJafD2Z29lwcNWlNTd/D+x6oiqwKS0sF+eAFCg03wqIHs+hZHUNbBGIFcg8vAwEP9Sc8J9H/wsu1hIHClI0nsRPxcpkHNODys4d3z37Ruqc= 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=a8Zk3wO5; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="a8Zk3wO5" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1714129815; x=1745665815; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=E3lsNuPY2s3Q+h3/lR91Vlx3BxKcj68xT1Zz7FHBTtU=; b=a8Zk3wO5B/VXm5RQgqOyffddDfFv2kUZdwPDoK71wtz9UcvQaYGug5Bf 4UYF5n2SxbB8V3UtGWYpJsuUpeYlPyASK//GD28EsfS/zHI0HUz0cDyXO brtQGonU9mHctC5MIxyNEAfjm+QX7Hy8+MXB9hz74yjc40BqDtz4vPRq/ 6dL/XHonotCZr7P+a5BEwcY+11qTbPvd6w9B6af1V3ZQKzILyAjw+A9cc WH0ONwhmp9RzfjTPto8yxTYObQLeRpryChPnO5OPxf5GzGz/bRwK2fEco irsiwGrRz7OFuX2f6xyAMIm8FcfUhihvP1rKe7RK1JVTeH5I3suNVDlN1 Q==; X-CSE-ConnectionGUID: tXmwf2fERiyCjh/kAEyv8g== X-CSE-MsgGUID: 6757YmJURFmYXMF5juMurQ== X-IronPort-AV: E=McAfee;i="6600,9927,11055"; a="20474090" X-IronPort-AV: E=Sophos;i="6.07,232,1708416000"; d="scan'208";a="20474090" 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:15 -0700 X-CSE-ConnectionGUID: sdKP7++bTUSW5ohpdhqj2Q== X-CSE-MsgGUID: lK7pFLwlSvyr4TJS5CEU1A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,232,1708416000"; d="scan'208";a="30030940" 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:12 -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 4/6] Revert "crypto: qat - remove unused macros in qat_comp_alg.c" Date: Fri, 26 Apr 2024 11:54:27 +0100 Message-ID: <20240426110941.5456-5-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 This reverts commit b4bf8295892924fca60d0704ac7cbc3b5897d233. --- drivers/crypto/intel/qat/qat_common/qat_comp_algs.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/crypto/intel/qat/qat_common/qat_comp_algs.c b/drivers/crypto/intel/qat/qat_common/qat_comp_algs.c index 79de04cfa012..b533984906ec 100644 --- a/drivers/crypto/intel/qat/qat_common/qat_comp_algs.c +++ b/drivers/crypto/intel/qat/qat_common/qat_comp_algs.c @@ -13,6 +13,15 @@ #include "qat_compression.h" #include "qat_algs_send.h" +#define QAT_RFC_1950_HDR_SIZE 2 +#define QAT_RFC_1950_FOOTER_SIZE 4 +#define QAT_RFC_1950_CM_DEFLATE 8 +#define QAT_RFC_1950_CM_DEFLATE_CINFO_32K 7 +#define QAT_RFC_1950_CM_MASK 0x0f +#define QAT_RFC_1950_CM_OFFSET 4 +#define QAT_RFC_1950_DICT_MASK 0x20 +#define QAT_RFC_1950_COMP_HDR 0x785e + static DEFINE_MUTEX(algs_lock); static unsigned int active_devs; From patchwork Fri Apr 26 10:54:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Cabiddu, Giovanni" X-Patchwork-Id: 792448 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 858C8145321; Fri, 26 Apr 2024 11:10:19 +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=1714129821; cv=none; b=YHv1KXK46KKUHUluFWgNwK2/8AA2bL+2j7hA3SmT1kcmDitqNUa8Fv0LFhoMDssHSLdXQCcRrvOi5KcG5cvgipbkSVynu3v7cyHW8SgAikej0BDIluIF5zoJ/iec0m0/cGGjPllp+TuYjLicSELMGZTLxS4z9YIIRy/l5VxuYKk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714129821; c=relaxed/simple; bh=Tqra8/1ha5Kv33pjuHHw6inu+5h3ytJKKpKbhL4wab0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=q1zAjAtzdD4HPEE63AmnSI+7iEMYW6Wp/d1WGOtHZB0PsTC7DIVWyama61K/GjFTJfJzIGOEr5DKjAXGQXv4B68EyLWXEaPLYeONRM3mGPTyQ6DDvRuaQOtt3u3KzWrx/jLLNNXHZVgnebG95We825xcaYFGk63ECbz8ZpymggU= 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=Mv3Z/e9W; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Mv3Z/e9W" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1714129820; x=1745665820; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Tqra8/1ha5Kv33pjuHHw6inu+5h3ytJKKpKbhL4wab0=; b=Mv3Z/e9WXVYRjq20ernWPpUF83sRR0Lz6w9icKVycHhqvDCi3IDxnOBG KcAV+zFgfSQlFYGhz04+jdoqwFeawImjnrmfDFYGlPIR4D6tdQVVFLPBB F96W6uaiXboxO7tFL3Kh8lnZKMODFEFVKr73KiJ7mP93FKUOP4FBhULLp l3kftlMvbEXmcTOhiyPCdA04Gm/Ko1kdl9SIqoy1eZMfqPp7IT7c29pU0 ldmwukD2f8twmx+YtfgHO2vfdj6UK0hrAFkS+eqtATpLpX4cqGt83WgIU TIWq9tOa00uROlPvx6Kd3S6gue3dOfQK3T68faTPsoHS5K0vRBQGdaH6s g==; X-CSE-ConnectionGUID: v3eN1JPuQ7aVbb3RH8lscg== X-CSE-MsgGUID: kvmD0tO6TTe6R7VmlWr1+w== X-IronPort-AV: E=McAfee;i="6600,9927,11055"; a="20474097" X-IronPort-AV: E=Sophos;i="6.07,232,1708416000"; d="scan'208";a="20474097" 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:19 -0700 X-CSE-ConnectionGUID: mSzro9B9Tk+ws7rfLtpUng== X-CSE-MsgGUID: swgjxfjcSImSwmOo8mjnYA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,232,1708416000"; d="scan'208";a="30030955" 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:15 -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 5/6] crypto: qat - change compressor settings for QAT GEN4 Date: Fri, 26 Apr 2024 11:54:28 +0100 Message-ID: <20240426110941.5456-6-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 Enable dynamic compression by default for QAT GEN4 and change compression level to 9. Signed-off-by: Giovanni Cabiddu --- drivers/crypto/intel/qat/qat_common/adf_gen4_dc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/crypto/intel/qat/qat_common/adf_gen4_dc.c b/drivers/crypto/intel/qat/qat_common/adf_gen4_dc.c index 5859238e37de..34f418b88738 100644 --- a/drivers/crypto/intel/qat/qat_common/adf_gen4_dc.c +++ b/drivers/crypto/intel/qat/qat_common/adf_gen4_dc.c @@ -22,7 +22,7 @@ static void qat_comp_build_deflate(void *ctx) header->hdr_flags = ICP_QAT_FW_COMN_HDR_FLAGS_BUILD(ICP_QAT_FW_COMN_REQ_FLAG_SET); header->service_type = ICP_QAT_FW_COMN_REQ_CPM_FW_COMP; - header->service_cmd_id = ICP_QAT_FW_COMP_CMD_STATIC; + header->service_cmd_id = ICP_QAT_FW_COMP_CMD_DYNAMIC; header->comn_req_flags = ICP_QAT_FW_COMN_FLAGS_BUILD(QAT_COMN_CD_FLD_TYPE_16BYTE_DATA, QAT_COMN_PTR_TYPE_SGL); @@ -35,7 +35,7 @@ static void qat_comp_build_deflate(void *ctx) hw_comp_lower_csr.skip_ctrl = ICP_QAT_HW_COMP_20_BYTE_SKIP_3BYTE_LITERAL; hw_comp_lower_csr.algo = ICP_QAT_HW_COMP_20_HW_COMP_FORMAT_ILZ77; hw_comp_lower_csr.lllbd = ICP_QAT_HW_COMP_20_LLLBD_CTRL_LLLBD_ENABLED; - hw_comp_lower_csr.sd = ICP_QAT_HW_COMP_20_SEARCH_DEPTH_LEVEL_1; + hw_comp_lower_csr.sd = ICP_QAT_HW_COMP_20_SEARCH_DEPTH_LEVEL_9; hw_comp_lower_csr.hash_update = ICP_QAT_HW_COMP_20_SKIP_HASH_UPDATE_DONT_ALLOW; hw_comp_lower_csr.edmm = ICP_QAT_HW_COMP_20_EXTENDED_DELAY_MATCH_MODE_EDMM_ENABLED; hw_comp_upper_csr.nice = ICP_QAT_HW_COMP_20_CONFIG_CSR_NICE_PARAM_DEFAULT_VAL; From patchwork Fri Apr 26 10:54:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Cabiddu, Giovanni" X-Patchwork-Id: 793849 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 51AEC14532C; Fri, 26 Apr 2024 11:10:23 +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=1714129826; cv=none; b=m7FaFkp8WI4/P8xFNBWeCasLFQjZHmt0KcR3HeVSC2Ug5YDeqs1dbg4EeA8QUmJWcj5EGEffHP9RlqKRykrd3AGAsynfIrtdEMFCPfFrWyNQkUvMRRLBPz7GT1CK0OK9tHGsHuro12U20agOUesiy/pbrW4JJ/AdGsrlSdqPrAI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714129826; c=relaxed/simple; bh=obllucfMKr7nP8Fd7tINm6E+qy6THCOcZXqtxMe2J5I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IjuN8a25M9G+vJYlJYkmfDev8gi5+hcPGtq1pJw5t/8o2twxRYut58mHo2Om/FE3/f4z2GM64MuOXStKLhmYtgfXYc9OThAH3YpQ9wzWERIfe0ISW2ktYppdeq+71sM1i25y8oGUb6UAubU1RnqTDxD8geV5ushiT1ZY57urS9I= 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=jcahVx8/; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="jcahVx8/" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1714129823; x=1745665823; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=obllucfMKr7nP8Fd7tINm6E+qy6THCOcZXqtxMe2J5I=; b=jcahVx8/hktfITFWa6/bF2NoCNNwCDAr6O1i36/lfhf8drk+jXxSWEGW gl011mUmBtNkfhb1ckt26RipCNCOSqfy8wCHDJ02J0tZl0+Ttnniuzo2Q G2xMtdTPYgl5K/3b+GReUj1CTB+u2OD2sCSvTQ3vP2hDFPw/TeQGF2+J4 DQRxU1ETa6mMDxm9qlxcv3hD9AFwZIhzE5WIT0AUmf8LCO+4bPuPRcEmj /lYPrMDeR/ngv3BHW+y82iLFLY/UoMa9enFzLTODMPZT74uDiMRDc3Zkn YI2aDdY6nCbq6WxTY1WkZChd2uruCOFfwtpdyHrpNwVaLNvXx13bg9G26 A==; X-CSE-ConnectionGUID: hWiw4rQlTS2LFIAEkyyaHw== X-CSE-MsgGUID: ekqB5eVoQ8mVdvhI18ggkg== X-IronPort-AV: E=McAfee;i="6600,9927,11055"; a="20474105" X-IronPort-AV: E=Sophos;i="6.07,232,1708416000"; d="scan'208";a="20474105" 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:23 -0700 X-CSE-ConnectionGUID: 2PZwnv6LTKWjyfCBCT0sNA== X-CSE-MsgGUID: Ey0Zd8xXSn64+/eWW6R/uw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,232,1708416000"; d="scan'208";a="30030970" 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:20 -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 Subject: [RFC PATCH 6/6] btrfs: zlib: add support for zlib-deflate through acomp Date: Fri, 26 Apr 2024 11:54:29 +0100 Message-ID: <20240426110941.5456-7-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 From: Weigang Li Add support for zlib compression and decompression through the acomp APIs. Input pages are added to an sg-list and sent to acomp in one request. Since acomp is asynchronous, the thread is put to sleep and then the CPU is freed up. Once compression is done, the acomp callback is triggered and the thread is woke up. This patch doesn't change the BTRFS disk format, this means that files compressed by hardware engines can be de-compressed by the zlib software library, and vice versa. Limitations: * The implementation tries always to use an acomp even if only zlib-deflate-scomp is present * Acomp does not provide a way to support compression levels * Acomp is an asynchronous API but used here synchronously Signed-off-by: Weigang Li --- fs/btrfs/zlib.c | 216 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 216 insertions(+) diff --git a/fs/btrfs/zlib.c b/fs/btrfs/zlib.c index e5b3f2003896..b5bbb8c97244 100644 --- a/fs/btrfs/zlib.c +++ b/fs/btrfs/zlib.c @@ -18,6 +18,8 @@ #include #include #include +#include +#include #include "compression.h" /* workspace buffer size for s390 zlib hardware support */ @@ -33,6 +35,201 @@ struct workspace { static struct workspace_manager wsm; +static int acomp_comp_pages(struct address_space *mapping, u64 start, + unsigned long len, struct page **pages, + unsigned long *out_pages, + unsigned long *total_in, + unsigned long *total_out) +{ + unsigned int nr_src_pages = 0, nr_dst_pages = 0, nr_pages = 0; + struct sg_table in_sg = { 0 }, out_sg = { 0 }; + struct page *in_page, *out_page, **in_pages; + struct crypto_acomp *tfm = NULL; + struct acomp_req *req = NULL; + struct crypto_wait wait; + int ret, i; + + nr_src_pages = (len + PAGE_SIZE - 1) >> PAGE_SHIFT; + in_pages = kcalloc(nr_src_pages, sizeof(struct page *), GFP_KERNEL); + if (!in_pages) { + ret = -ENOMEM; + goto out; + } + + for (i = 0; i < nr_src_pages; i++) { + in_page = find_get_page(mapping, start >> PAGE_SHIFT); + out_page = alloc_page(GFP_NOFS | __GFP_HIGHMEM); + if (!in_page || !out_page) { + ret = -ENOMEM; + goto out; + } + in_pages[i] = in_page; + pages[i] = out_page; + nr_dst_pages += 1; + start += PAGE_SIZE; + } + + ret = sg_alloc_table_from_pages(&in_sg, in_pages, nr_src_pages, 0, + nr_src_pages << PAGE_SHIFT, GFP_KERNEL); + if (ret) + goto out; + + ret = sg_alloc_table_from_pages(&out_sg, pages, nr_dst_pages, 0, + nr_dst_pages << PAGE_SHIFT, GFP_KERNEL); + if (ret) + goto out; + + crypto_init_wait(&wait); + tfm = crypto_alloc_acomp("zlib-deflate", 0, 0); + if (IS_ERR(tfm)) { + ret = PTR_ERR(tfm); + goto out; + } + + req = acomp_request_alloc(tfm); + if (!req) { + ret = -ENOMEM; + goto out; + } + + acomp_request_set_params(req, in_sg.sgl, out_sg.sgl, len, + nr_dst_pages << PAGE_SHIFT); + acomp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, + crypto_req_done, &wait); + + ret = crypto_wait_req(crypto_acomp_compress(req), &wait); + if (ret) + goto out; + + *total_in = len; + *total_out = req->dlen; + nr_pages = (*total_out + PAGE_SIZE - 1) >> PAGE_SHIFT; + +out: + sg_free_table(&in_sg); + sg_free_table(&out_sg); + + if (in_pages) { + for (i = 0; i < nr_src_pages; i++) + put_page(in_pages[i]); + kfree(in_pages); + } + + /* free un-used out pages */ + for (i = nr_pages; i < nr_dst_pages; i++) + put_page(pages[i]); + + if (req) + acomp_request_free(req); + + if (tfm) + crypto_free_acomp(tfm); + + *out_pages = nr_pages; + + return ret; +} + +static int acomp_zlib_decomp_bio(struct page **in_pages, + struct compressed_bio *cb, size_t srclen, + unsigned long total_pages_in) +{ + unsigned int nr_dst_pages = BTRFS_MAX_COMPRESSED_PAGES; + struct sg_table in_sg = { 0 }, out_sg = { 0 }; + struct bio *orig_bio = &cb->orig_bbio->bio; + char *data_out = NULL, *bv_buf = NULL; + int copy_len = 0, bytes_left = 0; + struct crypto_acomp *tfm = NULL; + struct page **out_pages = NULL; + struct acomp_req *req = NULL; + struct crypto_wait wait; + struct bio_vec bvec; + int ret, i = 0; + + ret = sg_alloc_table_from_pages(&in_sg, in_pages, total_pages_in, + 0, srclen, GFP_KERNEL); + if (ret) + goto out; + + out_pages = kcalloc(nr_dst_pages, sizeof(struct page *), GFP_KERNEL); + if (!out_pages) { + ret = -ENOMEM; + goto out; + } + + for (i = 0; i < nr_dst_pages; i++) { + out_pages[i] = alloc_page(GFP_NOFS | __GFP_HIGHMEM); + if (!out_pages[i]) { + ret = -ENOMEM; + goto out; + } + } + + ret = sg_alloc_table_from_pages(&out_sg, out_pages, nr_dst_pages, 0, + nr_dst_pages << PAGE_SHIFT, GFP_KERNEL); + if (ret) + goto out; + + crypto_init_wait(&wait); + tfm = crypto_alloc_acomp("zlib-deflate", 0, 0); + if (IS_ERR(tfm)) { + ret = PTR_ERR(tfm); + goto out; + } + + req = acomp_request_alloc(tfm); + if (!req) { + ret = -ENOMEM; + goto out; + } + + acomp_request_set_params(req, in_sg.sgl, out_sg.sgl, srclen, + nr_dst_pages << PAGE_SHIFT); + acomp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, + crypto_req_done, &wait); + + ret = crypto_wait_req(crypto_acomp_decompress(req), &wait); + if (ret) + goto out; + + /* Copy decompressed buffer to bio pages */ + bytes_left = req->dlen; + for (i = 0; i < nr_dst_pages; i++) { + copy_len = bytes_left > PAGE_SIZE ? PAGE_SIZE : bytes_left; + data_out = kmap_local_page(out_pages[i]); + + bvec = bio_iter_iovec(orig_bio, orig_bio->bi_iter); + bv_buf = kmap_local_page(bvec.bv_page); + memcpy(bv_buf, data_out, copy_len); + kunmap_local(bv_buf); + + bio_advance(orig_bio, copy_len); + if (!orig_bio->bi_iter.bi_size) + break; + bytes_left -= copy_len; + if (bytes_left <= 0) + break; + } +out: + sg_free_table(&in_sg); + sg_free_table(&out_sg); + + if (out_pages) { + for (i = 0; i < nr_dst_pages; i++) { + if (out_pages[i]) + put_page(out_pages[i]); + } + kfree(out_pages); + } + + if (req) + acomp_request_free(req); + if (tfm) + crypto_free_acomp(tfm); + + return ret; +} + struct list_head *zlib_get_workspace(unsigned int level) { struct list_head *ws = btrfs_get_workspace(BTRFS_COMPRESS_ZLIB, level); @@ -108,6 +305,15 @@ int zlib_compress_pages(struct list_head *ws, struct address_space *mapping, unsigned long nr_dest_pages = *out_pages; const unsigned long max_out = nr_dest_pages * PAGE_SIZE; + if (crypto_has_acomp("zlib-deflate", 0, 0)) { + ret = acomp_comp_pages(mapping, start, len, pages, out_pages, + total_in, total_out); + if (!ret) + return ret; + + pr_warn("BTRFS: acomp compression failed: ret = %d\n", ret); + /* Fallback to SW implementation if HW compression failed */ + } *out_pages = 0; *total_out = 0; *total_in = 0; @@ -281,6 +487,16 @@ int zlib_decompress_bio(struct list_head *ws, struct compressed_bio *cb) unsigned long buf_start; struct page **pages_in = cb->compressed_pages; + if (crypto_has_acomp("zlib-deflate", 0, 0)) { + ret = acomp_zlib_decomp_bio(pages_in, cb, srclen, + total_pages_in); + if (!ret) + return ret; + + pr_warn("BTRFS: acomp decompression failed, ret=%d\n", ret); + /* Fallback to SW implementation if HW decompression failed */ + } + data_in = kmap_local_page(pages_in[page_in_index]); workspace->strm.next_in = data_in; workspace->strm.avail_in = min_t(size_t, srclen, PAGE_SIZE);