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 6EFB4EB64D7 for ; Wed, 21 Jun 2023 09:09:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E1BCE8D0002; Wed, 21 Jun 2023 05:09:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DA3C08D0001; Wed, 21 Jun 2023 05:09:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C1CF78D0002; Wed, 21 Jun 2023 05:09:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id ACCB88D0001 for ; Wed, 21 Jun 2023 05:09:52 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 68BBE1406C3 for ; Wed, 21 Jun 2023 09:09:52 +0000 (UTC) X-FDA: 80926182624.13.DF4F792 Received: from mail-ed1-f52.google.com (mail-ed1-f52.google.com [209.85.208.52]) by imf21.hostedemail.com (Postfix) with ESMTP id 89C5F1C0011 for ; Wed, 21 Jun 2023 09:09:50 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=4pYZ8rFu; spf=pass (imf21.hostedemail.com: domain of yosryahmed@google.com designates 209.85.208.52 as permitted sender) smtp.mailfrom=yosryahmed@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1687338590; 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=lG2lXvo8ynTJGJsMqdSPccmtpLBchNBmTKGe+x6AzlI=; b=AidrQ6n6oAzxfr2uuZNZpKd26Cn0CS7xk9nrlFJYC5LPqOFNGpPdZltA9uuKB8PNg2rY1u X+5BmLc9r3TVjc1HmnTvnszBo1T8+BBqPh9OkYG+sNMeal/lu/xJj4hOFdHDRa8fkcXiIU LLCwLQ4RQzlzSL1SJZ1F/ZQNCcVm3aM= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=4pYZ8rFu; spf=pass (imf21.hostedemail.com: domain of yosryahmed@google.com designates 209.85.208.52 as permitted sender) smtp.mailfrom=yosryahmed@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687338590; a=rsa-sha256; cv=none; b=wK0fFQ9eBcQ09a4NqnN3WZuQNhfFFjWjaRpavpdfl61mQ1ufp7FWFKD4Sc+WIkQqBun/cd +ntwqm7k116U59+KQgFk6sGVzDcqdfjUX4ekMuZBMlfV9a6zxidHuanGU5H6PNkLuNKeNP nL1HpKuQZv+yexZ4zf5ThHu9jOx/qto= Received: by mail-ed1-f52.google.com with SMTP id 4fb4d7f45d1cf-519c0ad1223so7008353a12.0 for ; Wed, 21 Jun 2023 02:09:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1687338589; x=1689930589; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=lG2lXvo8ynTJGJsMqdSPccmtpLBchNBmTKGe+x6AzlI=; b=4pYZ8rFuPEyRoNobu2LBG9p/5grmUYsqYKPqSkG222JoaFLInGkFhnbovFTNI1ZkK5 ULGHVhoPm6qlwrywBHQI83CZ4w9SVwijcvHtv6Q2cusD3LF74BjGXb/W4Tg6Ti2oTihV wVq86yhFI08DfeEVzQl4JguCYqt42HMQG01R97ZcP/5MfxP4jlcYaNzlhEZEW3GJvxWQ mgT6bWL0+KlL8hbddIlfv9HUZncuR4XtAMEBG7H8ikQ/fKjncDLWcddeDD/mqa6xVf3J XMpl24bhckc68YxhTqMd5ltB9GK72RxQmqOgwP+Ru+8bWVHhtU3K6L87iObfeabLLzMQ GwKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687338589; x=1689930589; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lG2lXvo8ynTJGJsMqdSPccmtpLBchNBmTKGe+x6AzlI=; b=fE9iTzuIrU4qvgCSxXp4h1uWNMy4SjTRTxejqrWQ8GGpJzhG33hS4C89q/N4p0JVs+ vuype656OdgiOI4xd4Dis2nOONzQKCZJUU1EtDfRLpMe/o27UoNsh3PkN8aG1+cTgotV ItpyKPbOjF4A4j5g2+P8BJcxmxOjIdGAhpFadvVDenhLn2lN8F1TINnbB2qUXGZjH2WG ZHifKecujWpp/KbQ43CkpRiNpo6PNcW9EowN1GTaWsyHn7oNLFAlDpH+rUotWUxSz2f7 4QpqjLJn/3hlvQ0nHS2WJg4bOWoVQWN/fHuF+dpaA6Qka5wywgq0JfaACPBjJrXzYxMT 9qZg== X-Gm-Message-State: AC+VfDytO2C7XQWM2ThhOUShJxg8qV4iQULrntV/zHejeLd4peDc82XT PdQ7QwqP/mw4j4TzbJpVsW4+lsLeixTSHlT2Rml/WA== X-Google-Smtp-Source: ACHHUZ5Dk4MwHGdfv8f7OujyhRJV0h+jcKKQ3o7MDM0xd+Nx3KhlNRz83dOPSZ5H9svd9wp5rUg+yLi90cg4Pk25eQk= X-Received: by 2002:a17:906:eecc:b0:974:62d1:e942 with SMTP id wu12-20020a170906eecc00b0097462d1e942mr13014405ejb.21.1687338588733; Wed, 21 Jun 2023 02:09:48 -0700 (PDT) MIME-Version: 1.0 References: <20230607195143.1473802-1-yosryahmed@google.com> In-Reply-To: From: Yosry Ahmed Date: Wed, 21 Jun 2023 02:09:11 -0700 Message-ID: Subject: Re: [BUG mm-unstable] "kernel BUG at mm/swap.c:393!" on commit b9c91c43412f2e To: Hyeonggon Yoo <42.hyeyoo@gmail.com> 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 89C5F1C0011 X-Rspam-User: X-Stat-Signature: o8j7sc988w9c6ghemctug9i16xuhdb4z X-Rspamd-Server: rspam01 X-HE-Tag: 1687338590-493369 X-HE-Meta: U2FsdGVkX1+DATOcwvJk8sW0ZkQdeWpfV9+FmvVGe0FHP6iNkBOohsInXesfpW+IHqomPQiA42l/obhckhda3N/pIsJ34lNL2DYrhoRHfxjk/40RCAX1j1Kh99D204WTPhHE+4VgAslzBrAIruFHmx0WvY/EpUXqqL0CZ2nq/IDBO2/9r1mJAStxt2ipEHiEteyyjHYUuJu9KRaU8IF+g57MwtHrHcujnxBn9SSkbZQCAbvTuLOxpjhRmS8I65xJBJq1QRsiEMOABVOYS+YvnBOPOeCZm1PwhyB7gbfm0jv3EodwQ3ZgKk5BYJJOaK/2CLNlGpiY8mo+47lLGmtGw+WwBm0ipTxL2HZHY6khcyZXk3IwSSCSQfvrux1UxlX3WQisAx9TkE75aIbENOD8M+epFcJbW+mtEHVBzIgXpgEXAr3fNBKRJApKMDcmcTfebQWrATWkM1fl2heM2Ycg4wOyiv0n+q5guXN5+TwqTE6/nSCKqLwcS5l6QG4vwVFUM0QsXZkpP+Jbon99Z6INqxlREbDttODuTmVYdz0i89+WYbfHdjBlwaW55rd44BIIEJcK1YltNdC4bzbUpZ2YvmX/bwX8uzLown8t8//DJ8EDs2UfksO3xXO7Yl8gm48GpI3aTKHXiCEhoVgiTSHvkitg7Vbq79TB80IuCHvYENkAcD3t08TvAqy+m41CCGpzhwaLmhs7fn19Jd2XB5ODQ2PS7SWvpHTbwccj8ErvEVK7qO9GkrRXnXfWxviblkokIWDN8cRhzFOtxs+QHceX4yabkWhnjJyXieZSWjo5RpfbQNKbhXLQSFj7/uU1xVidTmQAt4B7N8AgTWn4L0hPcd1NhVtQ7AXNBVxImC7FGjEgl36Epy2NPwTDkP1cGkpvriv8Ltu360KsVY5gcYik2fUNcp5PknmkKJ1mkGK6shUCOmGCrz2ak5LZYtaj6BViSf4JBSC6wxWcMO0IfyU lFVBfEnW c2gFYx3nVzHZmQxAXv/tmWszlrEQUDpel1jSsN/SKoeVIjL/2eM55ZFmwrx5vU1Ll9U+SE6DTuAfnz+GREAVyGeYkVLsiHFDLIeOPjGbdwlipKEuwR5NmEZRHORy8lXxdKvqwX1orssOcgPS8uVm8xsPyv3VWBMz+k6etGSXkNlO/6hhD8gW2khoKtBVv9fWGY/06THw0xaRebMYjnb6AHbFpEbigkDukFy4Buo/0i2nWzgYqD/wJN+BwdobaJJq7w1R1WjewSVQcbBEW1tQhbYaRXVquHYRakRhH/o3w2xyYV7l+wkSdx3jR40GFef6/zYsJhv9/Jz5DRRnyqRAU0zm4fHFk8zEDSUvxaALmHUoutR0wlhc0hU1GsCvZjx20QVGjhNSRgDT1mouc+HBmYGLG8F4nogsPERdGvJSwQp0VRiiGacMpV6YIfkcsufvt8MRM 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 2:06=E2=80=AFAM Hyeonggon Yoo <42.hyeyoo@gmail.com>= wrote: > > On Wed, Jun 21, 2023 at 01:05:56AM -0700, Yosry Ahmed wrote: > > On Wed, Jun 21, 2023 at 12:01=E2=80=AFAM 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/eace06d71655b3cc76411366573e4a8ce240a= d65b8fd20977d7c73eec9dc2253.jpg > > > > > > (the head commit is b9c91c43412f2e07 "mm: zswap: support exclusive lo= ads") > > > (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 i= t > as separate patch, though (I'm totally fine with both way). I think it already landed in mm-stable so it cannot be squashed at this poi= nt. > > Anyway: > > Tested-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> Thanks a lot for reporting and testing this! I will wait for Domenico to also respond then send the fix to Andrew. Hopefully it's not too late for this rc. > > > 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 befor= e > > 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 entr= y > > 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