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 9C7EAC021B8 for ; Wed, 26 Feb 2025 21:16:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2BA216B0085; Wed, 26 Feb 2025 16:16:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 269F8280001; Wed, 26 Feb 2025 16:16:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 131516B008A; Wed, 26 Feb 2025 16:16:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id E9E8C6B0085 for ; Wed, 26 Feb 2025 16:16:33 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 8A205B230E for ; Wed, 26 Feb 2025 21:16:33 +0000 (UTC) X-FDA: 83163354666.24.778E04B Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf26.hostedemail.com (Postfix) with ESMTP id CE40014000D for ; Wed, 26 Feb 2025 21:16:31 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=PjJlQYC6; spf=pass (imf26.hostedemail.com: domain of ebiggers@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=ebiggers@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1740604591; 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=e0u8TroBMf8eBGT2qzKox87PjSANGqgK59Q1tWsfFZ8=; b=xLH7c9huN8/BB64EwJg5NcWrixs89Mm7rcKSmgBRSkbkqZ0F7Cesa0qnP5IicEvdIy6FCk DOyzCEYtxoHr79LHCmlM8fWc9EsHkmuGNBiK9et/nViEMNMaiHDsVWOzkCzQA7tGOZsk/s RpsB6aUJ5kS6LH8W2BIGmhBGL7LDj8Q= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=PjJlQYC6; spf=pass (imf26.hostedemail.com: domain of ebiggers@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=ebiggers@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1740604592; a=rsa-sha256; cv=none; b=JNa4hI/lDm8WpJm5Xv95kQ5AqwcxU/V6VrBasmQk8j2s8NA8G2I0mH3qPeNfVlNigEb3uy xB/fPNAF/D5ortni1/q1YWL/Xz4l2NsMFqhmE8IY3NsyrT48QgxXAhfO/hDPLrzcp9QFPH dabhAgOpnk4zjNuOR7UsIxeOWes7WNs= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id D6A4C5C3A6E; Wed, 26 Feb 2025 21:15:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EAEAAC4CEE7; Wed, 26 Feb 2025 21:16:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740604590; bh=BlXrr5d0eV/LhE0K1ldO09vh9dZWhnRmDBzqcBJ+MDc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=PjJlQYC6X0Ysyd0rN4GOVuwn8p1vTM0P/RTtiVegzerz7GdF/X8yBE1ul9r8dIvme v4pmKoPifGMG7esQKPU2DDle9YL8BV9r9Ifm31rUYkQEcthrbkqOCXf5+aiL3tIrna OC+bYnJxK8E4N9G86mVOs7hBOCP1d8R4B9Fz/cX7ZqgjPqfa7dFgjZK6UckAtvaU63 FnTr+OXy399bfR/1hbmvQwKEbitnTw0w8Rd93GjUDUjtC47AwS5/tqB1JrMMuxHNDN KtIvu/UEGFElCZECX5tsqoBx1znqsJZVRuwd2q+fOYeLHY03n9m/fMXIkq1/2nkVFe cobiK/OYjJdWw== Date: Wed, 26 Feb 2025 21:16:28 +0000 From: Eric Biggers To: Yosry Ahmed 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: <20250226211628.GD3949421@google.com> 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: X-Rspam-User: X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: CE40014000D X-Stat-Signature: 7kady1wcirtpqsmn9kqoc7wob74mpibg X-HE-Tag: 1740604591-508312 X-HE-Meta: U2FsdGVkX18g9QpIX0ES789Ze9AXS2RUyDxP60UgkLHkG73BXM4mhcpquorUDvkrR4p8Wt1I4lkHcrgEsJAQ/uCjk8Noe3GIIH83rl703RJe7illqWdP4QqNbrvDcZjaI7AXsYmA+3ndpBJQSVYrqF4V73s1HgFAXDXSxPv+ZkyJ1CuENZtM7+7WWWKlMQA3qvDXbkPgur3JkmW7N7Ys9P45TdbCG+n8yuAr3c9cQhKyBuCfstiLb8xurku8NWImmyh5BwI7FAzdqyai260gzf4fM8U6siyJLxTbri35mz9PX+7EAB7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WaLdJWmW1Cr6pSk0S8EI4gYRv7BF/k4sMbyRf0Ro3F/ARBJoYs8zxq4LPzEPEZPaI8G27m7kg7cSO7YTY9ZVqRzv1 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: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. > > 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. - Eric