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 56B69C021B8 for ; Wed, 26 Feb 2025 21:24:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DBD21280003; Wed, 26 Feb 2025 16:24:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D6BE7280001; Wed, 26 Feb 2025 16:24:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C33A8280003; Wed, 26 Feb 2025 16:24:02 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id A5A6D280001 for ; Wed, 26 Feb 2025 16:24:02 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 44CAA120C79 for ; Wed, 26 Feb 2025 21:24:02 +0000 (UTC) X-FDA: 83163373524.28.8E00A74 Received: from out-182.mta0.migadu.com (out-182.mta0.migadu.com [91.218.175.182]) by imf27.hostedemail.com (Postfix) with ESMTP id 761B04000A for ; Wed, 26 Feb 2025 21:24:00 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=LyPPWAxE; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf27.hostedemail.com: domain of yosry.ahmed@linux.dev designates 91.218.175.182 as permitted sender) smtp.mailfrom=yosry.ahmed@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1740605040; a=rsa-sha256; cv=none; b=8ahU9zyTtnW/S7p0CK89ApvxekWNRSccHEdmn3LlwQlLTdmCEwDb6AEnocCTbkYOVxy0Em bgaDCvBBWtDXu+Qhwj2Ujwe1kvKT9opsdZdu9BdOKGZlJFY5ih+uO4J/qK52DzzwNumW5W dpcdRmG89elN4XIk9BT/6u5F+VauWAA= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=LyPPWAxE; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf27.hostedemail.com: domain of yosry.ahmed@linux.dev designates 91.218.175.182 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=1740605040; 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=uJQGr+aTHnne3w5uc9X4/jJeY03gqZ4f7+KcAq7dW68=; b=j6ZR6EbivOmdLd7jZTw7HBUeVQ5Dczc9thTrQ4z7sRHcFRJmiAl60pD9Cjv+RqxUxGFwni qS0qHGOpksLhNrHYmqqB4WRIHGkNcaWmnQuQdlAgnk2R2k051w5i//baOW9T4h9bD7rBUX 1OfnC0hcuk08IhTKLg67xOaSYYwXhWo= Date: Wed, 26 Feb 2025 21:23:53 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1740605038; 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=uJQGr+aTHnne3w5uc9X4/jJeY03gqZ4f7+KcAq7dW68=; b=LyPPWAxEWmkvlpAaeOkB0LyTb0NOTyoQALIAYITZFvXbCw88dvPQBXQB/eTmb24p3dHat1 ocBilEY5UdJy0v873ihFR79MORCfmEvIN5z4HrsdJV2uGgJQx7HxGbvOWYODYX1sN8JIF/ v0rGNQ/GP1Apni1yTp6ebXEYPZKHj2c= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Yosry Ahmed To: Eric Biggers Cc: Andrew Morton , Johannes Weiner , Nhat Pham , Chengming Zhou , "David S. Miller" , Herbert Xu , linux-mm@kvack.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com, syzbot+1a517ccfcbc6a7ab0f82@syzkaller.appspotmail.com, stable@vger.kernel.org Subject: Re: [PATCH v2] mm: zswap: fix crypto_free_acomp() deadlock in zswap_cpu_comp_dead() Message-ID: References: <20250226185625.2672936-1-yosry.ahmed@linux.dev> <20250226200016.GB3949421@google.com> <20250226211628.GD3949421@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20250226211628.GD3949421@google.com> X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Queue-Id: 761B04000A X-Rspamd-Server: rspam12 X-Stat-Signature: 4gisyfkn6huyihnhz8zg3bocg1stx8a7 X-HE-Tag: 1740605040-315367 X-HE-Meta: U2FsdGVkX18HkqDv2shTK4yEvGdd9zVX+YTzQGQ1x5fVpZGCdtqpxYQYJ9PY7Vgt8JQyiFV2DO0cx7BfwkoVrH+1LEYOB/K+dMGXaipLRoQIJK3f3+ZFTtOqyQDmBagNskQyq4BgptsFebm25pqkIWv7VGxdLDKrDe45cu8PERENOvNmD61xcqXXKOqKBQ5V740bC8BUVmvNAndmOgM/DTF62PnXNWQ2uhHQleYR6dVxpp73Ha+pYSnv5QrkMcr2MAVtjDez1ud3JYv4Ec48Wu7jDqSzCoc+ltfVoBg24fsurUvQZD7P4+HLJFsBJu7x/vnV3v8I+caIo2ApQjYyd25pQVMEN2MgjL6nNFEpFZRN4cEkV29kIOO4NdaAQZOFy0YzIpo2WjyhgfZ9gvGgSGQ4Fn072meLv0l327VtQfkBBuxr2831ZxMD4SRL/7Dg5dnQA7yDXaJXYzh2YaBFUMDzHn2GNx3Uu5LCnscJAlSwe7xny+IA5Y5m76/UVMlQQAETrAuFxEZGCUS22ZRzK2UFreSBSAEPf6UpxO5jlqQ65thcVfhkpXHedmHtV6RuLrWIHDD9pEDB7Vf97cBzcjmwePr7o7CegXw9eh7jAflFNTWOLXfob2vx43rFB8nBnbtjl3tM9cJUY0mODzUiTr+UhURdEPVLQewiKLOCsCQAVXeD0WBuDlNWQLvERRtZwI6Vsjgc4roGFdZGUeF4GzcnT1gbFlSayONkd2PWU/CAEFApHkf+7s8/CsB944hePre+kMRJGDfzsJFBg9pdU2uEEc43tUXyg8YIT2ko6CY6gxeVOGQRO685uBsnX4CJkPzYdYAUczD2tszzvT58TddozGE2zrFWk/yHEU6KDzuzhm8t4SsBuL4YsXRZqAyiX6O4K8ShSo6QXq8pu8O7bbZ0UNmnMF5embieAzXWlvlQuqz28TD8H6W0mRSmWLXevxrIHjmkIKknTKtt3yp Ei7Bjp8Y d5loPpI70QoXBDZF4c+IGqQ0+qroo9thFGPX5ya40tIK8wXQ7qBuwkgNMYrPQaClXqMJIR0G0UZc5Ffh47yZQ2TcmWw3AgHyNQzLlLVzHpqCX6K54VkzYJvRa9M6uHkeSI4fWbqFQHIbBn34LdNcs40kjGVoJkGYT62DNu6AYDq4+gXFiUsLWVavgH2yNc4/4AO7zkPtiNLo1I5e8K3j4p8fQ5/U/HtxD9iR+dM9SmLosGnQAGvNwU1cm5sL3mwdcubAu+arr3o+o+G+Mn0WM73ne/cgfHMFse97pDtyyhhIxEWMpsJ9fOuRxryS60GbsijHgQf4RgZ7MJSsjy3KVcq+ncvus/s1FKg1sLw/DD2Blf7Bk4bM3GurttwtB4y44L4EuCMTRgMVmSLH/8n5QjfBkGhkJwUwKxuaqsz1CiwBzuEudWlRdTTVMZxHPMuS/lE09 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:16:28PM +0000, Eric Biggers wrote: > On Wed, Feb 26, 2025 at 08:32:22PM +0000, Yosry Ahmed wrote: > > On Wed, Feb 26, 2025 at 08:00:16PM +0000, Eric Biggers wrote: > > > On Wed, Feb 26, 2025 at 06:56:25PM +0000, Yosry Ahmed wrote: > > > > Currently, zswap_cpu_comp_dead() calls crypto_free_acomp() while holding > > > > the per-CPU acomp_ctx mutex. crypto_free_acomp() then holds scomp_lock > > > > (through crypto_exit_scomp_ops_async()). > > > > > > > > On the other hand, crypto_alloc_acomp_node() holds the scomp_lock > > > > (through crypto_scomp_init_tfm()), and then allocates memory. > > > > If the allocation results in reclaim, we may attempt to hold the per-CPU > > > > acomp_ctx mutex. > > > > > > The bug is in acomp. crypto_free_acomp() should never have to wait for a memory > > > allocation. That is what needs to be fixed. > > > > crypto_free_acomp() does not explicitly wait for an allocation, but it > > waits for scomp_lock (in crypto_exit_scomp_ops_async()), which may be > > held while allocating memory from crypto_scomp_init_tfm(). > > > > Are you suggesting that crypto_exit_scomp_ops_async() should not be > > holding scomp_lock? > > I think the solution while keeping the bounce buffer in place would be to do > what the patch > https://lore.kernel.org/linux-crypto/Z6w7Pz8jBeqhijut@gondor.apana.org.au/ does, > i.e. make the actual allocation and free happen outside the lock. I am fine with a solution like that if Herbert is fine with it. Although as I mentioned, I think this patch is nice to have anyway. > > > > But really the bounce buffering in acomp (which is what is causing this problem) > > > should not exist at all. There is really no practical use case for it; it's > > > just there because of the Crypto API's insistence on shoehorning everything into > > > scatterlists for no reason... > > > > I am assuming this about scomp_scratch logic, which is what we need to > > hold the scomp_lock for, resulting in this problem. > > Yes. > > > If this is something that can be done right away I am fine with dropping > > this patch for an alternative fix, although it may be nice to reduce the > > lock critical section in zswap_cpu_comp_dead() to the bare minimum > > anyway. > > Well, unfortunately the whole Crypto API philosophy of having a single interface > for software and for hardware offload doesn't really work. This is just yet > another example of that; it's a problem caused by shoehorning software > compression into an interface designed for hardware offload. zcomp really > should just use the compression libs directly (like most users of compression in > the kernel already do), and have an alternate code path specifically for > hardware offload (using acomp) for the few people who really want that. zcomp is for zram, zswap does not use it. If zswap is not going to use the crypto API we'll want something like zcomp or maybe reuse zcomp itself. That's a problem for another day :)