From patchwork Mon Mar 3 08:47:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sridhar, Kanchana P" X-Patchwork-Id: 13998357 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 4D4BAC282C5 for ; Mon, 3 Mar 2025 08:48:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1BFA128001C; Mon, 3 Mar 2025 03:47:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1479428001B; Mon, 3 Mar 2025 03:47:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CE15528001C; Mon, 3 Mar 2025 03:47:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 79FB828000B for ; Mon, 3 Mar 2025 03:47:45 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 03FFE12047E for ; Mon, 3 Mar 2025 08:47:44 +0000 (UTC) X-FDA: 83179611690.15.036E636 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) by imf18.hostedemail.com (Postfix) with ESMTP id D21771C000B for ; Mon, 3 Mar 2025 08:47:42 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=TMfb7IJi; spf=pass (imf18.hostedemail.com: domain of kanchana.p.sridhar@intel.com designates 192.198.163.14 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=1740991663; 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=RSUdPHzQM/668ueiIbP4yqJngLMhWytO1m39iTdoK4A=; b=eRRx/0e8fYMOpQs67z+S7uNPZmJRzR8zFZOfPZBVb5+VgNJO345+jN0Pol3Axe+6lIybQ3 vlZ6Gvx3r9kgTHEgTNGb0IMxMwv8Ytp4vgTSEddw15yDJDFTJgQKivJjtPAsHcyRvIakrc d6qoJEMNaxiaVaoymXIlXs+z9fAxS6E= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1740991663; a=rsa-sha256; cv=none; b=IUjdZvLraZQ/AkPm3kdopiDhZkMpO3TfuBwgspnwQDVCM0SHE8obHxvd+lwCxTSg+pA3de Ontlpka2f3XYI4KIA665c+jnGtT5jir2ooXBwrcOaD3b0YzN/RL1d7l7ip4WSXRyqCE1MB jgVTvAW+ruC/DtKJM1+gmVV5pyH/TAk= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=TMfb7IJi; spf=pass (imf18.hostedemail.com: domain of kanchana.p.sridhar@intel.com designates 192.198.163.14 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=1740991663; x=1772527663; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xzJxxiFYwAjT5Xrqds5C/407QeaiWfMMqcMGCN4vRiA=; b=TMfb7IJifv9AX0FT7W6KV8cDMGTwS3c1ckMbtdSl2Q5KIrdrSIIscD/l OVMMKIkEXHwvjaxFlMM5QBi0s4m3pbX38nHBJ0DefIkwVsJGOCFsTluuc bxACW9+SIyEOqxRTGeWay0LuL96vpxJtVmYfR+LXj76+3c1T9PJ3gJQ7i Hr/4OlHWWO8UGaBlubJ6mFbF0bFqGE2byCfvSA8kEz4oVFbij8WQFx2yK lh9Qnd+Aw9J3EexNUWNV0Odqx/p0EYDch8AjPpiEKD4OSgLAJ2ZooMCn6 zjvd2x0GjP0daHKpkyjdIc/hsQEpQwQJOL3TUulPqUO3m+wb/RBORVNmg A==; X-CSE-ConnectionGUID: e2edGUN4THqrOsu4bEW46g== X-CSE-MsgGUID: YDZm0hD2Q2eY5noYMOHyVA== X-IronPort-AV: E=McAfee;i="6700,10204,11361"; a="42111981" X-IronPort-AV: E=Sophos;i="6.13,329,1732608000"; d="scan'208";a="42111981" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Mar 2025 00:47:36 -0800 X-CSE-ConnectionGUID: dO2fnQJ4QGuFYHAJhUYFvA== X-CSE-MsgGUID: I08r1il/SqebEfhy5Kjt9Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.13,329,1732608000"; d="scan'208";a="118426818" Received: from jf5300-b11a338t.jf.intel.com ([10.242.51.115]) by fmviesa010.fm.intel.com with ESMTP; 03 Mar 2025 00:47:35 -0800 From: Kanchana P Sridhar To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, hannes@cmpxchg.org, yosry.ahmed@linux.dev, nphamcs@gmail.com, chengming.zhou@linux.dev, usamaarif642@gmail.com, ryan.roberts@arm.com, 21cnbao@gmail.com, ying.huang@linux.alibaba.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 Cc: wajdi.k.feghali@intel.com, vinodh.gopal@intel.com, kanchana.p.sridhar@intel.com Subject: [PATCH v8 10/14] crypto: iaa - Descriptor allocation timeouts with mitigations in iaa_crypto. Date: Mon, 3 Mar 2025 00:47:20 -0800 Message-Id: <20250303084724.6490-11-kanchana.p.sridhar@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20250303084724.6490-1-kanchana.p.sridhar@intel.com> References: <20250303084724.6490-1-kanchana.p.sridhar@intel.com> MIME-Version: 1.0 X-Stat-Signature: ekj1hb11qhxn4ur9iyd9unidnhbpo8jj X-Rspamd-Queue-Id: D21771C000B X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1740991662-4491 X-HE-Meta: U2FsdGVkX1/clbFuEjuWqTYubeOQnBKfQPWfNxhONzXIvOAjWSS/x84AlC7DAc0njFpRcOQZBlB/lJSbj+p0Qc9u4Wzykxc+Bccu9NlgvQwHZtIkJRJTLXahaT/GWn/xuB2MTxLwjlBO148Fl1BG3ckV8UJ7FtwSVtMYon2hu8FP+kDPHgBvvS9CD4/u55Z/RzcHiWtgIzm3zGXbbYNnNXbX+hiDW1Y0TOSbaz3Zy+1QtjzEqlI+oewFGQGtI/hu2qYZ6H1CcqtA0/q10eqNUkOerWiK2zGnuY7C9NU/ShOLXWUoiwR4w/c+jitbz8JDhp9IPzcgokcTLvM2GWoxlQYmO3Ti/0ABsZWjbiKle3acH4gVcMS2AdvzCIR/aBlaHq0PztC5U4jesfpIPmUa6i96qo3Y5D5GbY+smxoJNRWXA5gD0B93cHEXzHEnPdkJBli15SeL3nHn+L3/g6hmDM8zExU/YuT8mE2WwhsNrypKVpDljnmMfGGXGje9zEpy2jEch6pyQd3hFX8nftextJb4eoJt3gxgnGCORdGle60A7UqUI+gckI2Ef3VbAYcKqRQ6pBVQkKyHdvEQKB27Ue7agcci/SvBoy4rMgvldMCPhIv9hpcfFCJXI6OWBZ/2yOhzqMPu7ZxsAnePCtL1QJw9xKRCK8FXjkgOw+qOH7UmTLpBK1KX5Ksd6sMhXDH87V0b3VhVGgW6PgKDgN84L1VnFbcENG6aF/2RtpTik3SsQZGRaQPoPB5HCIrmBq2rRs+SFUUenLTqXa0vT84DWHMgiKP+RxUJujmxSLqu33Lnymd1AoHcPoOzoimtQblaO4mby46rM3SIgQ+tFfRI515mCY6/Z0PcQf86VBNkg5Ch7omj2N5FkI3u58mWxb+FJekRUVJ8E9rcwn7ZyK4E3D2ofiW33bdbO7/JNS/tGS8vOOcNl5jZ3tfPAmOpGMWg2j9zauQ32Uyhpa7YkvI EPUE50O0 vOAmh5UyzIOGNDFsdTwDAnIKU8LRVZIiVXybOn0hHjcHA81xTRJ5u0aSHSnhtpkvUb4y9SUVbj68lQGO+Q8aaBUeily8ohS4nNBXJM94ibtWsJ8KQEe7Z5dJYfR6fs3fGcjxe/W4//zeVli7+HSqDd62t97q2nVZa9Rv33AvPBjYNi+3WC4CjG7vUp5B1jHA9RqdnEpV5L6N0izV+o2KbQAEWGvxyiUpChFbdlUpJY5ksFj0= 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: This patch modifies the descriptor allocation from blocking to non-blocking with bounded retries or "timeouts". This is necessary to prevent task blocked errors in high contention scenarios, for instance, when the platform has only 1 IAA device enabled. With 1 IAA device enabled per package on a dual-package SPR with 56 cores/package, there are 112 logical cores mapped to this single IAA device. In this scenario, the task blocked errors can occur because idxd_alloc_desc() is called with IDXD_OP_BLOCK. Any process that is able to obtain IAA_CRYPTO_MAX_BATCH_SIZE (8U) descriptors, will cause contention for allocating descriptors for all other processes. Under IDXD_OP_BLOCK, this can cause compress/decompress jobs to stall in stress test scenarios (e.g. zswap_store() of 2M folios). In order to make the iaa_crypto driver be more fail-safe, this commit implements the following: 1) Change compress/decompress descriptor allocations to be non-blocking with retries ("timeouts"). 2) Return compress error to zswap if descriptor allocation with timeouts fails during compress ops. zswap_store() will return an error and the folio gets stored in the backing swap device. 3) Fallback to software decompress if descriptor allocation with timeouts fails during decompress ops. 4) Bug fixes for freeing the descriptor consistently in all error cases. With these fixes, there are no task blocked errors seen under stress testing conditions, and no performance degradation observed. Signed-off-by: Kanchana P Sridhar --- drivers/crypto/intel/iaa/iaa_crypto.h | 3 + drivers/crypto/intel/iaa/iaa_crypto_main.c | 74 ++++++++++++---------- 2 files changed, 45 insertions(+), 32 deletions(-) diff --git a/drivers/crypto/intel/iaa/iaa_crypto.h b/drivers/crypto/intel/iaa/iaa_crypto.h index 5f38f530c33d..de14e5e2a017 100644 --- a/drivers/crypto/intel/iaa/iaa_crypto.h +++ b/drivers/crypto/intel/iaa/iaa_crypto.h @@ -21,6 +21,9 @@ #define IAA_COMPLETION_TIMEOUT 1000000 +#define IAA_ALLOC_DESC_COMP_TIMEOUT 1000 +#define IAA_ALLOC_DESC_DECOMP_TIMEOUT 500 + #define IAA_ANALYTICS_ERROR 0x0a #define IAA_ERROR_DECOMP_BUF_OVERFLOW 0x0b #define IAA_ERROR_COMP_BUF_OVERFLOW 0x19 diff --git a/drivers/crypto/intel/iaa/iaa_crypto_main.c b/drivers/crypto/intel/iaa/iaa_crypto_main.c index cb96897e7fed..7503fafca279 100644 --- a/drivers/crypto/intel/iaa/iaa_crypto_main.c +++ b/drivers/crypto/intel/iaa/iaa_crypto_main.c @@ -1406,6 +1406,7 @@ static int deflate_generic_decompress(struct acomp_req *req) void *src, *dst; int ret; + req->dlen = PAGE_SIZE; src = kmap_local_page(sg_page(req->src)) + req->src->offset; dst = kmap_local_page(sg_page(req->dst)) + req->dst->offset; @@ -1469,7 +1470,8 @@ static int iaa_compress_verify(struct crypto_tfm *tfm, struct acomp_req *req, struct iaa_device_compression_mode *active_compression_mode; struct iaa_compression_ctx *ctx = crypto_tfm_ctx(tfm); struct iaa_device *iaa_device; - struct idxd_desc *idxd_desc; + struct idxd_desc *idxd_desc = ERR_PTR(-EAGAIN); + int alloc_desc_retries = 0; struct iax_hw_desc *desc; struct idxd_device *idxd; struct iaa_wq *iaa_wq; @@ -1485,7 +1487,11 @@ static int iaa_compress_verify(struct crypto_tfm *tfm, struct acomp_req *req, active_compression_mode = get_iaa_device_compression_mode(iaa_device, ctx->mode); - idxd_desc = idxd_alloc_desc(wq, IDXD_OP_BLOCK); + while ((idxd_desc == ERR_PTR(-EAGAIN)) && (alloc_desc_retries++ < IAA_ALLOC_DESC_DECOMP_TIMEOUT)) { + idxd_desc = idxd_alloc_desc(wq, IDXD_OP_NONBLOCK); + cpu_relax(); + } + if (IS_ERR(idxd_desc)) { dev_dbg(dev, "idxd descriptor allocation failed\n"); dev_dbg(dev, "iaa compress failed: ret=%ld\n", @@ -1661,7 +1667,8 @@ static int iaa_compress(struct crypto_tfm *tfm, struct acomp_req *req, struct iaa_device_compression_mode *active_compression_mode; struct iaa_compression_ctx *ctx = crypto_tfm_ctx(tfm); struct iaa_device *iaa_device; - struct idxd_desc *idxd_desc; + struct idxd_desc *idxd_desc = ERR_PTR(-EAGAIN); + int alloc_desc_retries = 0; struct iax_hw_desc *desc; struct idxd_device *idxd; struct iaa_wq *iaa_wq; @@ -1677,7 +1684,11 @@ static int iaa_compress(struct crypto_tfm *tfm, struct acomp_req *req, active_compression_mode = get_iaa_device_compression_mode(iaa_device, ctx->mode); - idxd_desc = idxd_alloc_desc(wq, IDXD_OP_BLOCK); + while ((idxd_desc == ERR_PTR(-EAGAIN)) && (alloc_desc_retries++ < IAA_ALLOC_DESC_COMP_TIMEOUT)) { + idxd_desc = idxd_alloc_desc(wq, IDXD_OP_NONBLOCK); + cpu_relax(); + } + if (IS_ERR(idxd_desc)) { dev_dbg(dev, "idxd descriptor allocation failed\n"); dev_dbg(dev, "iaa compress failed: ret=%ld\n", PTR_ERR(idxd_desc)); @@ -1753,15 +1764,10 @@ static int iaa_compress(struct crypto_tfm *tfm, struct acomp_req *req, *compression_crc = idxd_desc->iax_completion->crc; - if (!ctx->async_mode || disable_async) - idxd_free_desc(wq, idxd_desc); -out: - return ret; err: idxd_free_desc(wq, idxd_desc); - dev_dbg(dev, "iaa compress failed: ret=%d\n", ret); - - goto out; +out: + return ret; } static int iaa_decompress(struct crypto_tfm *tfm, struct acomp_req *req, @@ -1773,7 +1779,8 @@ static int iaa_decompress(struct crypto_tfm *tfm, struct acomp_req *req, struct iaa_device_compression_mode *active_compression_mode; struct iaa_compression_ctx *ctx = crypto_tfm_ctx(tfm); struct iaa_device *iaa_device; - struct idxd_desc *idxd_desc; + struct idxd_desc *idxd_desc = ERR_PTR(-EAGAIN); + int alloc_desc_retries = 0; struct iax_hw_desc *desc; struct idxd_device *idxd; struct iaa_wq *iaa_wq; @@ -1789,12 +1796,18 @@ static int iaa_decompress(struct crypto_tfm *tfm, struct acomp_req *req, active_compression_mode = get_iaa_device_compression_mode(iaa_device, ctx->mode); - idxd_desc = idxd_alloc_desc(wq, IDXD_OP_BLOCK); + while ((idxd_desc == ERR_PTR(-EAGAIN)) && (alloc_desc_retries++ < IAA_ALLOC_DESC_DECOMP_TIMEOUT)) { + idxd_desc = idxd_alloc_desc(wq, IDXD_OP_NONBLOCK); + cpu_relax(); + } + if (IS_ERR(idxd_desc)) { dev_dbg(dev, "idxd descriptor allocation failed\n"); dev_dbg(dev, "iaa decompress failed: ret=%ld\n", PTR_ERR(idxd_desc)); - return PTR_ERR(idxd_desc); + ret = PTR_ERR(idxd_desc); + idxd_desc = NULL; + goto fallback_software_decomp; } desc = idxd_desc->iax_hw; @@ -1837,7 +1850,7 @@ static int iaa_decompress(struct crypto_tfm *tfm, struct acomp_req *req, ret = idxd_submit_desc(wq, idxd_desc); if (ret) { dev_dbg(dev, "submit_desc failed ret=%d\n", ret); - goto err; + goto fallback_software_decomp; } /* Update stats */ @@ -1851,19 +1864,20 @@ static int iaa_decompress(struct crypto_tfm *tfm, struct acomp_req *req, } ret = check_completion(dev, idxd_desc->iax_completion, false, false); + +fallback_software_decomp: if (ret) { - dev_dbg(dev, "%s: check_completion failed ret=%d\n", __func__, ret); - if (idxd_desc->iax_completion->status == IAA_ANALYTICS_ERROR) { + dev_dbg(dev, "%s: desc allocation/submission/check_completion failed ret=%d\n", __func__, ret); + if (idxd_desc && idxd_desc->iax_completion->status == IAA_ANALYTICS_ERROR) { pr_warn("%s: falling back to deflate-generic decompress, " "analytics error code %x\n", __func__, idxd_desc->iax_completion->error_code); - ret = deflate_generic_decompress(req); - if (ret) { - dev_dbg(dev, "%s: deflate-generic failed ret=%d\n", - __func__, ret); - goto err; - } - } else { + } + + ret = deflate_generic_decompress(req); + + if (ret) { + pr_err("%s: iaa decompress failed: fallback to deflate-generic software decompress error ret=%d\n", __func__, ret); goto err; } } else { @@ -1872,19 +1886,15 @@ static int iaa_decompress(struct crypto_tfm *tfm, struct acomp_req *req, *dlen = req->dlen; - if (!ctx->async_mode || disable_async) - idxd_free_desc(wq, idxd_desc); - /* Update stats */ update_total_decomp_bytes_in(slen); update_wq_decomp_bytes(wq, slen); + +err: + if (idxd_desc) + idxd_free_desc(wq, idxd_desc); out: return ret; -err: - idxd_free_desc(wq, idxd_desc); - dev_dbg(dev, "iaa decompress failed: ret=%d\n", ret); - - goto out; } static int iaa_comp_acompress(struct acomp_req *req)