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 D1DF6C021B8 for ; Wed, 26 Feb 2025 20:32:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6DCE6280005; Wed, 26 Feb 2025 15:32:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 68D76280002; Wed, 26 Feb 2025 15:32:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5547D280005; Wed, 26 Feb 2025 15:32:34 -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 35074280002 for ; Wed, 26 Feb 2025 15:32:34 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id DC8D54E885 for ; Wed, 26 Feb 2025 20:32:33 +0000 (UTC) X-FDA: 83163243786.27.5E1F341 Received: from out-185.mta1.migadu.com (out-185.mta1.migadu.com [95.215.58.185]) by imf20.hostedemail.com (Postfix) with ESMTP id 054791C001D for ; Wed, 26 Feb 2025 20:32:31 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=pizpSgxd; spf=pass (imf20.hostedemail.com: domain of yosry.ahmed@linux.dev designates 95.215.58.185 as permitted sender) smtp.mailfrom=yosry.ahmed@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1740601952; 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=YwKQQagVy4d7sPBKa/BO0IpJPH7lXzoPFfwUhxzxnZE=; b=wPiOFMg6KB0uHnLEB7s3e+wMHUXtAm2bBFFUQtpFWtAnYc+dcPnC6QeCCqnSTERrIE8xu4 XQj9z1FU3ia+Fnppt0UCs4UOly6hoQyW7o6ea3Y29IfR1cBzBqMcks5zrgAArldFXAId2P 91SQpdIs1vo2BV0EN2UR4waX2VvK6Ok= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=pizpSgxd; spf=pass (imf20.hostedemail.com: domain of yosry.ahmed@linux.dev designates 95.215.58.185 as permitted sender) smtp.mailfrom=yosry.ahmed@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1740601952; a=rsa-sha256; cv=none; b=nOjPi/kCTd5Grmyycutkt76v11VNEAmy957hL9Aku0sXFuTvA3ToqUbA/Lmg83+lDZAvv1 q1aitd99ur9u1dPvCph69fjdT9I22WDhotIo1IWNLmIWRhIl/qlUav9G1MzFT7+4ueg6DT bEbnYjzaloJqaF45umwilHJAdIRPbKY= Date: Wed, 26 Feb 2025 20:32:22 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1740601949; 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=YwKQQagVy4d7sPBKa/BO0IpJPH7lXzoPFfwUhxzxnZE=; b=pizpSgxdCb0Mj6HEOWUuTJ1W8pbQ7bCrYI18B58ul1/EvUVVxfUCQX6c0w/se9Jq/6XLMe ULVoKZB2bQEEENYOdwkXknnhu5X6QR35mSZcsFswdHTsltbulwuT0RLHzFKyJIAgyxmURH PC0bPCNoqGnxk7pEjgH90quatMZ4m7c= 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20250226200016.GB3949421@google.com> X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: 054791C001D X-Stat-Signature: cbmd1mn81d7tntx3x31itf8t8sq5ciza X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1740601951-779894 X-HE-Meta: U2FsdGVkX1+XWRXAYzXveAaFy2mmUZ+mFhEWwIvxWA/8evs8MCFnXrU34Yr7mG9H4TW+gYIVWqXXKaACAREs09Q9BCVgJ1iA7LHjEruw8n8cmCTypa058YJuPgfyCjIEW3+auOqQoPGnozvJoRPUOnWhc5urnb0J5g2mF33HaQC8fecc6OZyRCIGwuylnwkR/9vgNkrnRVAaxEexR8gnE8I/IwcjYq43ACFmUAzvvEu5xs0AhJqZs4AutbfJmHu30zvv/6U94c3/EtmzlRAIJGkx10DkhlLZxakjBUYTwl5RGJtNC8raKzV5Eoo/FKrW/TGUCZRP8neXuq1okBJ1UHERcBEz6tbVSbWxqH0ykEigo9LooChrZ+DVN+JaTWRVhdmPFKQTP1g5i6lDmkfP6z9kHDOjnhtWrYVUdnLbqD77SexJhBtXz1pu7vAqOphP1du/kpvrTe1BdSW826lOqUxWJ3o/r2td8+5lYKU+FBnUvDE1h1vIUJtB2GYjEp6vLdlmX5DHHV0T9HkzTKsBUEDCLpfPjIOZqA9NWARBM88Y1NCIEmQU7LQV51Y2PFeuZHTNUvEKyB2EykUVyuNRtx9cjSrLc6w9QFrdDKxvYz1G0J35qKd/qewwkuuSEjuo68CVpnoltiVdmBG5zDIrIipaBnQ9db/mlacUpeplAZZo7c4qua/b5uXVPgf229THMltOQgXvO5bmCObvfvynypmBTkFTOSJQ/JIfJiZaVBJCPpoeuWvrcZzNojWf4jCqacMvvbYTuMkHaJuwuf2VAd33XcEVhOyjfUzdi5O6kpP/CZBnnfzLlyBKEQiGm5S4UOgmdY+OyoC95o/Xz8Fh4J96iqtVngz1canryUYMXpDvuEMxfjI3N4pKLtcSA97H3ecHSzl9KF1iRa9ZVE+wyvPNxZoleCLls3J1iK5jfPsrM5C8aA1gqb7Q5qju4mJADa4hc1hGm6E3Ag1KiJt MyofVAIv s2NyfyaUuNkuWD7KVCvLwgCaE4fMceubKwQJ0dnwQpRBIECQDkLqM0AJi6TFlIWn6SwgZyzFkRPgnDL/Krn5ZfDaxuIyHGx6B3dr82kRbGVq8TfPgHtPCnuOgJy6Ihmp0PtCMBSfPkvYSqyszWZAPGJKrRdf5GqDBh/NqMB59eAEdJqphVkkzy0dd4gfhcjo4cc66YZAtJZ+dFqGerCz5GSryjNHaM51yKS/ICXnWUXxWMWmJ8AfYvXMCbavii/YSQOXEZjuctfF5FS2d/EiqeZwBG/W3MaRVs+Mq4XQoFpzHMzLB7UQCKCuy7Gm67Fx6JYru3jhiglRpHfZ18mzSi/GPGOrV9fdUUmceItVmWkAyKpQ= 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 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? > > 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. 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.