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 AC0ACEB64D8 for ; Wed, 21 Jun 2023 09:06:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2353F8D0002; Wed, 21 Jun 2023 05:06:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1E50B8D0001; Wed, 21 Jun 2023 05:06:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0ADD28D0002; Wed, 21 Jun 2023 05:06:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id ECEDC8D0001 for ; Wed, 21 Jun 2023 05:06:58 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id A2A9416084D for ; Wed, 21 Jun 2023 09:06:58 +0000 (UTC) X-FDA: 80926175316.07.3AF8E67 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by imf17.hostedemail.com (Postfix) with ESMTP id 9A8B14001F for ; Wed, 21 Jun 2023 09:06:56 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=cooEGTq0; spf=pass (imf17.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.214.175 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1687338416; 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=K8HTIhkv++1Fsa2NTQSKbuaibYlj+ipl+Ced2oh/4BE=; b=nLUVrmFBFJlzm6Ag95EGZvXF9G9IhYzmm+ytBUGrJRzB/Q/jCWzfhaKUf+y+J8HqDNWY7z Cv6Z6x1uQLqalpek68SXpixWul2buFAY9nGqyFdrWqbmTVH10ihry+Xn38Sc++HB1K59p0 5lNK6qsa+0V4pqREHZXkEGjWZYX7sRw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687338416; a=rsa-sha256; cv=none; b=UjjzJw0s99tKF9DYPl+LqDRGQN2ekjv9er52ahIhNmumKw2+R69Oq+71jKpuveOsy7JEmf 7BQ5QdSXE74IVbxha1k6uKkGA/F57C58Op9ehZKy8/8+knexRcx+bdl1zGTz0n6neVk3Zx ZtqfTBAEWrUMNbXeTeCiZdyk+j1IqRo= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=cooEGTq0; spf=pass (imf17.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.214.175 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1b55fc3a71cso18579155ad.2 for ; Wed, 21 Jun 2023 02:06:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687338415; x=1689930415; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=K8HTIhkv++1Fsa2NTQSKbuaibYlj+ipl+Ced2oh/4BE=; b=cooEGTq01eez/kjEDOJuayOLBQZWnKWTa/EhoHmXV8T8lPgNAemspEULxzi9lxLzxo 1RBL/tsTpGGO7+A/qTPx9P7tEbp/6VX2sllhLMSgf6RqlERi1lcZlN3CgEefMMloyLlE n4UVA9D/z6NAaIVWN8S0MSVuYnpBUhOnMdPqq3O5z9qI0OgKpL+bxbsNDOspnCeYy8Pz t8DXgHvUO3IlGat8t+T6JiEcDgSyhfcLjKMgQtfpg+e47U0hCokU8jmDDAuYb0nWKd1Z lcRfp/aKkJnB0b+R+acCjOnu7GvBBqiU5T3wDNuyf2Vojzs0JV/cIfCxXAYLcXokuL3r K2Xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687338415; x=1689930415; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=K8HTIhkv++1Fsa2NTQSKbuaibYlj+ipl+Ced2oh/4BE=; b=QZN/pVvXE2/vq24+QnTMwAqnFubKU4tYzFMxSr/1l3616xhLbYT45Vz2d8RmGGPNV5 vSJ96QflTIh+1m3ReKZ2aWjm81VtMoaDMyzxHXujcBFa7RWICAgMLZPD2V7HpLcoJp3b slhry8QWULAm7RfB2vCGrSYvAZ4xUM0TVSU9tr+b8cF+2qjmz/vLCJaIxuMHms2YL7x8 JleytF8rywUC7qtcJZuNHl56gvC0x1P23ENNpDTQYPDaDQBIU/xbvGEhiXdtNQ3p31hS 9lNqUleZSjE8zUnYxpjuCOag6G70My18HcdnXMN0tY+/lEEyr8+f2cPdmiB7z+/W0L32 YbMA== X-Gm-Message-State: AC+VfDxLwjCGlbF12HfdJAqxmRjQAqSQAMLV+M6iviHkcS9m9Jnv29Sz IGLOumEaHfKdtXGRi52b4AQ= X-Google-Smtp-Source: ACHHUZ4JpE0R9/+Dh6vTgNfs0KqO4uOSmg4xuknZOptg40nCdU67XSngubYLl72PO+RACezyJvBriA== X-Received: by 2002:a17:902:e847:b0:1af:a2a4:837f with SMTP id t7-20020a170902e84700b001afa2a4837fmr14444319plg.26.1687338415193; Wed, 21 Jun 2023 02:06:55 -0700 (PDT) Received: from fedora ([1.245.179.104]) by smtp.gmail.com with ESMTPSA id iy14-20020a170903130e00b001b6771ad27bsm2952449plb.265.2023.06.21.02.06.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jun 2023 02:06:54 -0700 (PDT) Date: Wed, 21 Jun 2023 18:06:48 +0900 From: Hyeonggon Yoo <42.hyeyoo@gmail.com> To: Yosry Ahmed Cc: Andrew Morton , Konrad Rzeszutek Wilk , Seth Jennings , Dan Streetman , Vitaly Wool , Johannes Weiner , Nhat Pham , Domenico Cerasuolo , Yu Zhao , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [BUG mm-unstable] "kernel BUG at mm/swap.c:393!" on commit b9c91c43412f2e Message-ID: References: <20230607195143.1473802-1-yosryahmed@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Rspamd-Queue-Id: 9A8B14001F X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: 7k1q44t4tfuwymffap9ra5ssgyaer4jx X-HE-Tag: 1687338416-891947 X-HE-Meta: U2FsdGVkX191MsC4siH4SsXzs88Yu61hDjHZY1Hli37+sofNtRcGa9drxJ5s03e43FSmIW12Svh5wF8oC2mvONv6wnKZ/ExbdTeyC506P//o0eXcmgZWXFQNAUqb0jyLSiKFUgmsAQ6urIxRyIiSo8GJVDzzkGL/u8jCfQzZUu4OzvSwt/CQVeEb/4hp80rRppFES7p8ShExTOjLx83sRjggTuIBtQm16A/ldv+/Wpyjn/caALJcaoan2M0KuKyl0f0ypqljxmA2AAQ6RCbHpX7LyWFmPNqHzJcl6xy3/UCO083Zz1xIMP+bM5rqLqP9Nq4DEmGhZidX4kSAX/VBOdfi9HT7qviDN3TYNJzDL11FLERHXkCJ/EqxgIXSDEKJEfUql5ynxKku0TNlr07nlc6AbbtFzpwOQOaQRyj8cgJstPO2Z3Hvp7LBO25nrIM36nrGahvg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3/jdAwpo5TeElKspfpvfH5QSAyHIARazH7il5jRJPsUqUUYNydUgCoFBptDKuEiKHvwjvPFobOEB+dYPdBYBtMAkS0= 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: On Wed, Jun 21, 2023 at 01:05:56AM -0700, Yosry Ahmed wrote: > On Wed, Jun 21, 2023 at 12:01 AM Hyeonggon Yoo <42.hyeyoo@gmail.com> wrote: > > Hi Yosry, I was testing the latest mm-unstable and encountered a bug. > > It was bisectable and this is the first bad commit. > > > > > > Attached config file and bisect log. > > The oops message is available at: > > > > https://social.kernel.org/media/eace06d71655b3cc76411366573e4a8ce240ad65b8fd20977d7c73eec9dc2253.jpg > > > > (the head commit is b9c91c43412f2e07 "mm: zswap: support exclusive loads") > > (it's an image because I tested it on real machine) > > > > > > This is what I have as swap space: > > > > $ cat /proc/swaps > > Filename Type Size Used Priority > > /var/swap file 134217724 0 -2 > > /dev/zram0 partition 8388604 0 100 > > > Hi Hyeonggon, > > Thanks for reporting this! I think I know what went wrong. Could you > please verify if the below fix works if possible? > Works fine and I was not able to reproduce the bug with the patch applied. Not sure Andrew would prefer squashing it into original one or applying it as separate patch, though (I'm totally fine with both way). Anyway: Tested-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> > Domenico, I believe the below fix would also fix a problem with the > recent writeback series. If the entry is invalidated before we grab the > lock to put the local ref in zswap_frontswap_load(), then the entry > will be freed once we call zswap_entry_put(), and the movement to the > beginning LRU will be operating on a freed entry. It also modifies > your recently added commit 418fd29d9de5 ("mm: zswap: invaldiate entry > after writeback"). I would appreciate it if you also take a look. > > If this works as intended, I can send a formal patch (applies on top > of fd247f029cd0 ("mm/gup: do not return 0 from pin_user_pages_fast() > for bad args")): > > From 4b7f949b3ffb42d969d525d5b576fad474f55276 Mon Sep 17 00:00:00 2001 > From: Yosry Ahmed > Date: Wed, 21 Jun 2023 07:43:51 +0000 > Subject: [PATCH] mm: zswap: fix double invalidate with exclusive loads > > If exclusive loads are enabled for zswap, we invalidate the entry before > returning from zswap_frontswap_load(), after dropping the local > reference. However, the tree lock is dropped during decompression after > the local reference is acquired, so the entry could be invalidated > before we drop the local ref. If this happens, the entry is freed once > we drop the local ref, and zswap_invalidate_entry() tries to invalidate > an already freed entry. > > Fix this by: > (a) Making sure zswap_invalidate_entry() is always called with a local > ref held, to avoid being called on a freed entry. > (b) Making sure zswap_invalidate_entry() only drops the ref if the entry > was actually on the rbtree. Otherwise, another invalidation could > have already happened, and the initial ref is already dropped. > > With these changes, there is no need to check that there is no need to > make sure the entry still exists in the tree in zswap_reclaim_entry() > before invalidating it, as zswap_reclaim_entry() will make this check > internally. > > Fixes: b9c91c43412f ("mm: zswap: support exclusive loads") > Reported-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> > Signed-off-by: Yosry Ahmed <...snip...> -- Hyeonggon Yoo Undergraduate | Chungnam National University