From mboxrd@z Thu Jan 1 00:00:00 1970 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 AA8C9C021BE for ; Wed, 26 Feb 2025 02:08:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C6D356B0095; Tue, 25 Feb 2025 21:08:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C1D306B0096; Tue, 25 Feb 2025 21:08:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AE48D280001; Tue, 25 Feb 2025 21:08:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 8B74F6B0095 for ; Tue, 25 Feb 2025 21:08:24 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 281B21A074B for ; Wed, 26 Feb 2025 02:08:24 +0000 (UTC) X-FDA: 83160461328.09.CD6F0AE Received: from out-174.mta1.migadu.com (out-174.mta1.migadu.com [95.215.58.174]) by imf24.hostedemail.com (Postfix) with ESMTP id 37C4A180005 for ; Wed, 26 Feb 2025 02:08:22 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=bW7DTZ3J; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf24.hostedemail.com: domain of yosry.ahmed@linux.dev designates 95.215.58.174 as permitted sender) smtp.mailfrom=yosry.ahmed@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1740535702; a=rsa-sha256; cv=none; b=G+1BkWD9ZrpWMlCdGPe2Cv8oKA+LNW/QUh568Ll0QQ1ZKUAIztMjYmiphQC6hLznUJ8YON vOZBkMMiqvpiqgLUEUCAw/1v9gAu2jrxmI9ZqZHik9tWiJExz6MfP4MVkTcVE22VuJr0dK uxUc7mPevSOowxqT3ni4LB2ynFmtm64= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=bW7DTZ3J; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf24.hostedemail.com: domain of yosry.ahmed@linux.dev designates 95.215.58.174 as permitted sender) smtp.mailfrom=yosry.ahmed@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1740535702; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=6OT2cF/ZPcycQso9hH5apzsVw/Q9q7yBIY5IL7+Yorg=; b=uvesPVZvZ3DyPtnlElVrRxowQJ+gSj8xbok6HshxqRQMAFwluMu6V7E5zwxxY00CMk621/ HmQ0haPAldZDpQTDCPVhMFV1Nq6qG4d4ltsedYYDpUyYHSaZKE2eIR/32DUSO+MHNEV9W0 TzVhh+AGIb/Z9M6Tg8Vz9EEfru6+LxA= Date: Wed, 26 Feb 2025 02:08:14 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1740535700; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=6OT2cF/ZPcycQso9hH5apzsVw/Q9q7yBIY5IL7+Yorg=; b=bW7DTZ3JfPodHoYu+uOpvnoXAigpeYV7HdjDSDy5E8J55jVfS+Q8dP41VEvwgSyrbA+FQD fgr0fGAlfoGD+EkvNbSCuZ7+eKN+qrPqN09/d/kKyzHq0vSM58Oa5Gb16L9hDafWpMWxMr GieMLLR3MTMg8SoX/OgqhLwGNCXlLEU= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Yosry Ahmed To: Herbert Xu Cc: syzbot , davem@davemloft.net, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com, Andrew Morton , linux-mm@kvack.org Subject: Re: mm: zswap: fix crypto_free_acomp deadlock in zswap_cpu_comp_dead Message-ID: References: <67bcea51.050a0220.bbfd1.0096.GAE@google.com> <3482501981b13aedda3c1c6b54d83d496bd05922@linux.dev> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 37C4A180005 X-Stat-Signature: cj8r6z94my8t68h3z8sk7mdjkku6uuq5 X-Rspam-User: X-HE-Tag: 1740535702-199342 X-HE-Meta: U2FsdGVkX1/LcCqIIlimvziJJRWqdvyBaN/DwipPC2xbRLSCfHfER8hTdu0Cj5lSVImTEhJaY2F+DapgkTJYUp5iqRzHYy3yVD9Ur+4QVf68SQnGvMcmIlhTAlpOvSio0Nq/L1xcisTKDMsZ40KcFX+V8ImRocr4Xd8+LNLlze61l9nOjax8FaNmRszu+yvH+Cqdsi0yVLgYKhYQIRTFTU1IEBbMdLDJvurjIYgEIjltcEZLfnSTKTPEXruai+ciJCS3Hg509FtAt8vXMZjBPjAja8Ac5N4LxgYehIGTYAFLJi1AnM6BxWfMLjzR/1xGH0aXyRV9ylV5pNEzQkEo7vl/4Idi9NxYEsM3Twar7lXyv1baehaKpg3A6ucW5LKijtprH8orEcM0pn9cvcD5AQTzeE3U9Rw9eZPBEUli8eHddkKPOpraEPGf/MgUs6Q165N8Zudh5wcuA9H99L/2+8YGykoWOoMNKNuK6Fr56SP6Bgj4dfl4F/BsgljvmaFC0JeE5Xx2+hx12ouCwHQg2C7my1caa86KwMmirH8apIvkgcqjg3jnqrMDYax0r/x3vr9wkSFGVGHGf98+znpuuLY++wCfuTh8qViz+/STt3P1Ii4QjarOkqykmAcnsxrNnCfXUIR8RT1rej3t4YjXJ6pvaZFE2m1Ewdy2zra4niuh6V1cT/i9cTLDYFKWSSFNlLwpAZU6dB+E9KUysULHpCbIqmR+klYm/m/9Y1KobQ7hP6G7wpjEKQKi/LWJeHZ22P/nPj97nxG7HNBeWlv5c5hpnJXCi0NNaqYuDVpSCH7bjShlVoKknvwlOHk0Qz0uAaQVLmbrYyDwQKmW3gp36rWNcC8/7ZpvPNOjuUd5CpVIyvSfYvegQZhiKU4SuSJzqJCyB9525x/QED9H8DgFHSi3Kf4QKILqEL73L37Hp12FSlN7PQCeD1KAWFub+cF94NfAvULBTpwO8YLSqHa oBD2rq4Y PClBA8xx+7wZjWwOerD8WTjUUo3f59ktBmiLrRcLiZbs4m7y/fWJq0eU/ShX65Y7AHiJnXAbqzDB8V0D8/qmkGqCtN5YKgHk6U+zWuDg6dlmtYvFKveL3EZx+MNPIKBHXbrLwwWfFPNQyHFMjK3zzkWB5tA/H391+hEWTHIR9SVsAk0izCXvx56v1ec2eqIdedP2iPuQbapq+NXPATsFIQds3JLwzJmjvXL35F7viBlexx4fOTY1CsoqO5UtMG10hZM6s4ktTMSQ/9HSBZLMl1Gt1zHMgxukNHWg28nXhOfn7W6aPBRb9OPxxiFzYDl+mgMZzHrYtqbz56FGTVCiEf8hgMe43WKbMAIY/RlmkBML/ThEvTm8DKHDmUkWM0nFpVs3hIVA3yscL7P/Wxf8060RIQSMSFWGWN+hT 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: On Wed, Feb 26, 2025 at 09:25:23AM +0800, Herbert Xu wrote: > On Tue, Feb 25, 2025 at 01:43:41PM +0000, Yosry Ahmed wrote: > > > > Interesting, it's weird that crypto_free_acomp() allocates memory. Do you have the specific call path? > > crypto_free_acomp does not allocate memory. However, it takes > the same mutex that is also taken on the allocation path. > > The specific call path can be seen in the original report: > > https://syzkaller.appspot.com/bug?extid=1a517ccfcbc6a7ab0f82 After staring at this for a while I think the following situation could be the problem: Task A running on CPU #1: crypto_alloc_acomp_node() Holds scomp_lock Enters reclaim Reads per_cpu_ptr(pool->acomp_ctx, cpu) Task A is descheduled zswap_cpu_comp_dead(CPU #1) // CPU #1 going offline Holds per_cpu_ptr(pool->acomp_ctx, cpu)) Calls crypto_free_acomp() Waits for scomp_lock Task A running on CPU #2: Waits for per_cpu_ptr(pool->acomp_ctx, cpu) DEADLOCK In this case I think the fix is correct, thanks for looking into it. Could you please: (1) Explain the exact scenario in the commit log, I did not understand it at first, only after looking at the syzbot dashboard for a while (and I am not sure how long this persists). (2) Move all the freeing operations outside the mutex? Right now crypto_free_acomp() was the problematic call but it could be acomp_request_free() next. Something like: static int zswap_cpu_comp_dead(unsigned int cpu, struct hlist_node *node) { 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 struct acomp_req *req; struct crypto_acomp *acomp; u8 *buffer; if (IS_ERR_OR_NULL(acomp_ctx)) return 0; mutex_lock(&acomp_ctx->mutex); req = acomp_ctx->req; acomp_ctx->req = NULL; acomp = acomp_ctx->acomp; acomp_ctx->acomp = NULL; buffer = acomp_ctx->buffer; acomp_ctx->buffer = NULL; mutex_unlock(&acomp_ctx->mutex); /* * Do the actual freeing after releasing the mutex to avoid subtle * locking dependencies causing deadlocks */ if (!IS_ERR_OR_NULL(req)) acomp_request_free(req); if (!IS_ERR_OR_NULL(acomp)) crypto_free_acomp(acomp); kfree(acomp_ctx->buffer); return 0; }