From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: stable@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
patches@lists.linux.dev, Yosry Ahmed <yosryahmed@google.com>,
Chengming Zhou <chengming.zhou@linux.dev>,
Johannes Weiner <hannes@cmpxchg.org>,
Nhat Pham <nphamcs@gmail.com>,
Andrew Morton <akpm@linux-foundation.org>
Subject: [PATCH 6.12 16/40] mm: zswap: move allocations during CPU init outside the lock
Date: Thu, 30 Jan 2025 14:59:16 +0100 [thread overview]
Message-ID: <20250130133500.361454546@linuxfoundation.org> (raw)
In-Reply-To: <20250130133459.700273275@linuxfoundation.org>
6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yosry Ahmed <yosryahmed@google.com>
commit 779b9955f64327c339a16f68055af98252fd3315 upstream.
In zswap_cpu_comp_prepare(), allocations are made and assigned to various
members of acomp_ctx under acomp_ctx->mutex. However, allocations may
recurse into zswap through reclaim, trying to acquire the same mutex and
deadlocking.
Move the allocations before the mutex critical section. Only the
initialization of acomp_ctx needs to be done with the mutex held.
Link: https://lkml.kernel.org/r/20250113214458.2123410-1-yosryahmed@google.com
Fixes: 12dcb0ef5406 ("mm: zswap: properly synchronize freeing resources during CPU hotunplug")
Signed-off-by: Yosry Ahmed <yosryahmed@google.com>
Reviewed-by: Chengming Zhou <chengming.zhou@linux.dev>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Nhat Pham <nphamcs@gmail.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
mm/zswap.c | 42 ++++++++++++++++++++++++------------------
1 file changed, 24 insertions(+), 18 deletions(-)
--- a/mm/zswap.c
+++ b/mm/zswap.c
@@ -815,15 +815,15 @@ static int zswap_cpu_comp_prepare(unsign
{
struct zswap_pool *pool = hlist_entry(node, struct zswap_pool, node);
struct crypto_acomp_ctx *acomp_ctx = per_cpu_ptr(pool->acomp_ctx, cpu);
- struct crypto_acomp *acomp;
- struct acomp_req *req;
+ struct crypto_acomp *acomp = NULL;
+ struct acomp_req *req = NULL;
+ u8 *buffer = NULL;
int ret;
- mutex_lock(&acomp_ctx->mutex);
- acomp_ctx->buffer = kmalloc_node(PAGE_SIZE * 2, GFP_KERNEL, cpu_to_node(cpu));
- if (!acomp_ctx->buffer) {
+ buffer = kmalloc_node(PAGE_SIZE * 2, GFP_KERNEL, cpu_to_node(cpu));
+ if (!buffer) {
ret = -ENOMEM;
- goto buffer_fail;
+ goto fail;
}
acomp = crypto_alloc_acomp_node(pool->tfm_name, 0, 0, cpu_to_node(cpu));
@@ -831,21 +831,25 @@ static int zswap_cpu_comp_prepare(unsign
pr_err("could not alloc crypto acomp %s : %ld\n",
pool->tfm_name, PTR_ERR(acomp));
ret = PTR_ERR(acomp);
- goto acomp_fail;
+ goto fail;
}
- acomp_ctx->acomp = acomp;
- acomp_ctx->is_sleepable = acomp_is_async(acomp);
- req = acomp_request_alloc(acomp_ctx->acomp);
+ req = acomp_request_alloc(acomp);
if (!req) {
pr_err("could not alloc crypto acomp_request %s\n",
pool->tfm_name);
ret = -ENOMEM;
- goto req_fail;
+ goto fail;
}
- acomp_ctx->req = req;
+ /*
+ * Only hold the mutex after completing allocations, otherwise we may
+ * recurse into zswap through reclaim and attempt to hold the mutex
+ * again resulting in a deadlock.
+ */
+ mutex_lock(&acomp_ctx->mutex);
crypto_init_wait(&acomp_ctx->wait);
+
/*
* if the backend of acomp is async zip, crypto_req_done() will wakeup
* crypto_wait_req(); if the backend of acomp is scomp, the callback
@@ -854,15 +858,17 @@ static int zswap_cpu_comp_prepare(unsign
acomp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
crypto_req_done, &acomp_ctx->wait);
+ acomp_ctx->buffer = buffer;
+ acomp_ctx->acomp = acomp;
+ acomp_ctx->is_sleepable = acomp_is_async(acomp);
+ acomp_ctx->req = req;
mutex_unlock(&acomp_ctx->mutex);
return 0;
-req_fail:
- crypto_free_acomp(acomp_ctx->acomp);
-acomp_fail:
- kfree(acomp_ctx->buffer);
-buffer_fail:
- mutex_unlock(&acomp_ctx->mutex);
+fail:
+ if (acomp)
+ crypto_free_acomp(acomp);
+ kfree(buffer);
return ret;
}
next prev parent reply other threads:[~2025-01-30 14:00 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-30 13:59 [PATCH 6.12 00/40] 6.12.12-rc1 review Greg Kroah-Hartman
2025-01-30 13:59 ` [PATCH 6.12 01/40] ASoC: wm8994: Add depends on MFD core Greg Kroah-Hartman
2025-01-30 13:59 ` [PATCH 6.12 02/40] ASoC: codecs: es8316: Fix HW rate calculation for 48Mhz MCLK Greg Kroah-Hartman
2025-01-30 13:59 ` [PATCH 6.12 03/40] ASoC: samsung: Add missing selects for MFD_WM8994 Greg Kroah-Hartman
2025-01-30 13:59 ` [PATCH 6.12 04/40] seccomp: Stub for !CONFIG_SECCOMP Greg Kroah-Hartman
2025-01-30 13:59 ` [PATCH 6.12 05/40] ASoC: cs42l43: Add codec force suspend/resume ops Greg Kroah-Hartman
2025-01-30 13:59 ` [PATCH 6.12 06/40] scsi: iscsi: Fix redundant response for ISCSI_UEVENT_GET_HOST_STATS request Greg Kroah-Hartman
2025-01-30 13:59 ` [PATCH 6.12 07/40] drm/amd/display: Use HW lock mgr for PSR1 Greg Kroah-Hartman
2025-01-30 13:59 ` [PATCH 6.12 08/40] drm/amd/display: Initialize denominator defaults to 1 Greg Kroah-Hartman
2025-01-30 13:59 ` [PATCH 6.12 09/40] of/unittest: Add test that of_address_to_resource() fails on non-translatable address Greg Kroah-Hartman
2025-01-30 13:59 ` [PATCH 6.12 10/40] ALSA: hda/realtek: Fix volume adjustment issue on Lenovo ThinkBook 16P Gen5 Greg Kroah-Hartman
2025-01-30 13:59 ` [PATCH 6.12 11/40] drm/connector: hdmi: Validate supported_formats matches ycbcr_420_allowed Greg Kroah-Hartman
2025-01-30 13:59 ` [PATCH 6.12 12/40] irqchip/sunxi-nmi: Add missing SKIP_WAKE flag Greg Kroah-Hartman
2025-01-30 13:59 ` [PATCH 6.12 13/40] hwmon: (drivetemp) Set scsi command timeout to 10s Greg Kroah-Hartman
2025-01-30 13:59 ` [PATCH 6.12 14/40] ASoC: samsung: Add missing depends on I2C Greg Kroah-Hartman
2025-01-30 13:59 ` [PATCH 6.12 15/40] mm: zswap: properly synchronize freeing resources during CPU hotunplug Greg Kroah-Hartman
2025-01-30 13:59 ` Greg Kroah-Hartman [this message]
2025-01-30 13:59 ` [PATCH 6.12 17/40] gfs2: Truncate address space when flipping GFS2_DIF_JDATA flag Greg Kroah-Hartman
2025-01-30 13:59 ` [PATCH 6.12 18/40] libfs: Return ENOSPC when the directory offset range is exhausted Greg Kroah-Hartman
2025-01-30 13:59 ` [PATCH 6.12 19/40] Revert "libfs: Add simple_offset_empty()" Greg Kroah-Hartman
2025-01-30 13:59 ` [PATCH 6.12 20/40] Revert "libfs: fix infinite directory reads for offset dir" Greg Kroah-Hartman
2025-01-30 13:59 ` [PATCH 6.12 21/40] libfs: Replace simple_offset end-of-directory detection Greg Kroah-Hartman
2025-01-30 13:59 ` [PATCH 6.12 22/40] libfs: Use d_children list to iterate simple_offset directories Greg Kroah-Hartman
2025-01-30 13:59 ` [PATCH 6.12 23/40] smb: client: handle lack of EA support in smb2_query_path_info() Greg Kroah-Hartman
2025-01-30 13:59 ` [PATCH 6.12 24/40] net: sched: fix ets qdisc OOB Indexing Greg Kroah-Hartman
2025-01-30 13:59 ` [PATCH 6.12 25/40] Revert "HID: multitouch: Add support for lenovo Y9000P Touchpad" Greg Kroah-Hartman
2025-01-30 13:59 ` [PATCH 6.12 26/40] cachestat: fix page cache statistics permission checking Greg Kroah-Hartman
2025-01-30 13:59 ` [PATCH 6.12 27/40] vfio/platform: check the bounds of read/write syscalls Greg Kroah-Hartman
2025-01-30 13:59 ` [PATCH 6.12 28/40] scsi: storvsc: Ratelimit warning logs to prevent VM denial of service Greg Kroah-Hartman
2025-01-30 13:59 ` [PATCH 6.12 29/40] USB: serial: quatech2: fix null-ptr-deref in qt2_process_read_urb() Greg Kroah-Hartman
2025-01-30 13:59 ` [PATCH 6.12 30/40] Revert "usb: gadget: u_serial: Disable ep before setting port to null to fix the crash caused by port being null" Greg Kroah-Hartman
2025-01-30 13:59 ` [PATCH 6.12 31/40] ALSA: usb-audio: Add delay quirk for USB Audio Device Greg Kroah-Hartman
2025-01-30 13:59 ` [PATCH 6.12 32/40] wifi: rtl8xxxu: add more missing rtl8192cu USB IDs Greg Kroah-Hartman
2025-01-30 13:59 ` [PATCH 6.12 33/40] HID: wacom: Initialize brightness of LED trigger Greg Kroah-Hartman
2025-01-30 13:59 ` [PATCH 6.12 34/40] Input: xpad - add support for Nacon Pro Compact Greg Kroah-Hartman
2025-01-30 13:59 ` [PATCH 6.12 35/40] Input: atkbd - map F23 key to support default copilot shortcut Greg Kroah-Hartman
2025-01-30 13:59 ` [PATCH 6.12 36/40] Input: xpad - add unofficial Xbox 360 wireless receiver clone Greg Kroah-Hartman
2025-01-30 13:59 ` [PATCH 6.12 37/40] Input: xpad - add QH Electronics VID/PID Greg Kroah-Hartman
2025-01-30 13:59 ` [PATCH 6.12 38/40] Input: xpad - improve name of 8BitDo controller 2dc8:3106 Greg Kroah-Hartman
2025-01-30 13:59 ` [PATCH 6.12 39/40] Input: xpad - add support for Nacon Evol-X Xbox One Controller Greg Kroah-Hartman
2025-01-30 13:59 ` [PATCH 6.12 40/40] Input: xpad - add support for wooting two he (arm) Greg Kroah-Hartman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250130133500.361454546@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=akpm@linux-foundation.org \
--cc=chengming.zhou@linux.dev \
--cc=hannes@cmpxchg.org \
--cc=nphamcs@gmail.com \
--cc=patches@lists.linux.dev \
--cc=stable@vger.kernel.org \
--cc=yosryahmed@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.