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 74EC6C282D1 for ; Fri, 7 Mar 2025 03:06:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 79C3F280002; Thu, 6 Mar 2025 22:06:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 74A17280001; Thu, 6 Mar 2025 22:06:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 63AA1280002; Thu, 6 Mar 2025 22:06:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 44EA7280001 for ; Thu, 6 Mar 2025 22:06:35 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 715E380446 for ; Fri, 7 Mar 2025 03:06:36 +0000 (UTC) X-FDA: 83193267192.18.EB8AEB1 Received: from out-180.mta0.migadu.com (out-180.mta0.migadu.com [91.218.175.180]) by imf09.hostedemail.com (Postfix) with ESMTP id 69CAF14000B for ; Fri, 7 Mar 2025 03:06:34 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=FVhC0c9s; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf09.hostedemail.com: domain of chengming.zhou@linux.dev designates 91.218.175.180 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1741316794; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=IzbprMV/OZKTdRrqS+bnLZbpGK4ksEtI/ebz1jE8B40=; b=fBE4sEF6hhEc0XO48JnPAnuKxTfh0m9MGAx6pjV6Nxv3DTUcY5HrJs63ge1d9J9gGjwuEv 0rtKEyR0yEf3RjEgbtI/4YHuwlfOSAD45xsffgabNQDomqnm+qmQPcceWozy5FsIDZceRQ 2cYmnzrLjTnWEA5i/1r8KFG32Jk6OXw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1741316794; a=rsa-sha256; cv=none; b=MkBO4RcVf1MU7aCfHcmXN7sXFru4P9rFEhFcTdDLBPhgX1mMF1T51AkmOdXLLqNixaNItt RiSWSHkvjjSWcVRzINkWBdofyqDKSGFEWNPOXJs2wXbgOkweT++LvrnNNA0Qxa92caTtrS bgg/NimMG+SE1IUQ+BIHcouukZ+aCvo= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=FVhC0c9s; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf09.hostedemail.com: domain of chengming.zhou@linux.dev designates 91.218.175.180 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev Message-ID: <6a7c9ef6-2511-404e-b9c2-117765c90d95@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1741316792; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IzbprMV/OZKTdRrqS+bnLZbpGK4ksEtI/ebz1jE8B40=; b=FVhC0c9sGprYOiv6EJpEGTtXi1vYAz/wO3ugz6oEyGzzKmUKFTX9zJtXxjRK5k2qkMgzwi +Ch/+3BPiMaSYrSl3SKbLHDSKljc6M6Cc7gpwROMd6Z3a9CHaTWNNJXTbGXBBIRL9vVFdN hK/MxephVOltyad+DQxgRMbxCicUY2c= Date: Fri, 7 Mar 2025 11:06:23 +0800 MIME-Version: 1.0 Subject: Re: [PATCH v4] page_io: zswap: do not crash the kernel on decompression failure To: Nhat Pham , akpm@linux-foundation.org Cc: hannes@cmpxchg.org, yosryahmed@google.com, yosry.ahmed@linux.dev, linux-mm@kvack.org, kernel-team@meta.com, linux-kernel@vger.kernel.org References: <20250306205011.784787-1-nphamcs@gmail.com> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Chengming Zhou In-Reply-To: <20250306205011.784787-1-nphamcs@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 69CAF14000B X-Stat-Signature: m361sijdmjo6exusip8ei7jwge7x5uzc X-HE-Tag: 1741316794-367059 X-HE-Meta: U2FsdGVkX18XQhV263au55SHqorqeO859BpJRxbDd7mquJxGYvVxCHR806Us6paL+m57oSNid3hpCpxUety7/q3sGceKVOxUbL5359fBy3x3SfTghkiIk57jH2WWcSUz7/WM9ARy3JnzCswkxflbJ6676GeXsrbsN2sCgQzxQCUUXoG28hs6PKxL4w0LNqWCEtpsxieSlWhS8zL9Q6Y4+sfNenHMRv9nGA3pe/4g1uEwl7b5JbxugYRjpQCjMCNfDf9JIiV+FIYxxbUfuUBF94B04XsaVXFR8KDmgmgRX7cHKnXc4afHQOogKYJlNGabDd3m/vnMzlDjzv1WkQCQhRlt5oWfquUKBf3UTB5fPM5hdYGO9DS/0q295MxV9wD+sNn+u9Tcypn/AaOzAF1MYis7F63TJt3+K7G81LX7hp8tOeLcr35jJHrV/XjYJhRi1Nw8XqzBawf0eOnAKgEib5kfBvHcFTfJw6YautewBvJn641kgBZYEmAxM4mc6mGsDlY5yo2KK1BdOJDxd1KVndzNQLO7UIxGjB5l0Mg0lEAN5D6B5dEbA2AUyN6qUxTSlxQ966XeOVDIGE0e2syly8ZO62AkmAv7ySfGXaUAinN9pQZWK1gus68rqAuYb7uAyAZFMfpW3ry+IlNDV9W00+kumoxDM+au/TJdNbpqaSpZftE4rXc3aSi+9LDyMTBQl7Hy33jEnEeMyV0gFY22T4Q5mUWitOgR8UBPpuIoxdG8Wo/tVmH6aQ5zCjz5bFcFTN4qyB1oZWHUEOgziOAxtJ2r6xlH1zh5o4Qu1p/wDiWZqJLcncWxIRK8Mbk4I7MIWncKaKZX8qj8XY8rYSI1/suBTutRCi6+YyOWySpo6xMcTqJCczadtf42YUoumhqvNYzUrM5Tm993iJDvSQjlEqxK3Gah5rCQUTZLlIGBWSjU70YH/ghggOSEhQa1lV/jvqZZIQ7f0q0/ZAQqVWg g5MnbOxM nUPUZK9nhlyw0LVY5NdYsbssOYiqqH8vYiCtF7xeOCpBRsYxDfsCqD52A5NkJEcsaAO9ca2pfn2vv+fBDoadje4AB8hk5xfV/iDMk3XkBQhz1w/K6Vk5XQlZkyyOC3T/m0B2CIkjr5MKeH1UvZ4PFIN1+AamVR+goyS2Yjy2JXYMd+rKl28t/t737/XXtPpPdU6uZQh6ywUExfagoLOVaGfJQaoCBcOmjej0INUFFEbycJi0RQnJOWGqU37vm1gNBGfL50rmYiZh7hQ7HQJ+2tOoijBcWYNNDakOM4U3tmhd5KbXfSWfHh+HlW1atdTxCe4kMQ0DUYLwNXk9nZdJWI+UKqyAuNd4GJ/br4KN46Ug1HT4xklqbBPmnhxj1d/20fsXE1JTRtZXSf8o= 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 2025/3/7 04:50, Nhat Pham wrote: > Currently, we crash the kernel when a decompression failure occurs in > zswap (either because of memory corruption, or a bug in the compression > algorithm). This is overkill. We should only SIGBUS the unfortunate > process asking for the zswap entry on zswap load, and skip the corrupted > entry in zswap writeback. > > See [1] for a recent upstream discussion about this. > > The zswap writeback case is relatively straightforward to fix. For the > zswap_load() case, we change the return behavior: > > * Return 0 on success. > * Return -ENOENT (with the folio locked) if zswap does not own the > swapped out content. > * Return -EIO if zswap owns the swapped out content, but encounters a > decompression failure for some reasons. The folio will be unlocked, > but not be marked up-to-date, which will eventually cause the process > requesting the page to SIGBUS (see the handling of not-up-to-date > folio in do_swap_page() in mm/memory.c), without crashing the kernel. > * Return -EINVAL if we encounter a large folio, as large folio should > not be swapped in while zswap is being used. Similar to the -EIO case, > we also unlock the folio but do not mark it as up-to-date to SIGBUS > the faulting process. > > As a side effect, we require one extra zswap tree traversal in the load > and writeback paths. Quick benchmarking on a kernel build test shows no > performance difference: > > With the new scheme: > real: mean: 125.1s, stdev: 0.12s > user: mean: 3265.23s, stdev: 9.62s > sys: mean: 2156.41s, stdev: 13.98s > > The old scheme: > real: mean: 125.78s, stdev: 0.45s > user: mean: 3287.18s, stdev: 5.95s > sys: mean: 2177.08s, stdev: 26.52s > > [1]: https://lore.kernel.org/all/ZsiLElTykamcYZ6J@casper.infradead.org/ > > Suggested-by: Matthew Wilcox > Suggested-by: Yosry Ahmed > Suggested-by: Johannes Weiner > Signed-off-by: Nhat Pham Reviewed-by: Chengming Zhou Thanks!