From patchwork Sun Apr 23 04:47:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 13221218 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 1E6A9C77B76 for ; Sun, 23 Apr 2023 04:47:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 14D8B6B0072; Sun, 23 Apr 2023 00:47:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0FE776B0074; Sun, 23 Apr 2023 00:47:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F2E726B0075; Sun, 23 Apr 2023 00:47:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id E40D96B0072 for ; Sun, 23 Apr 2023 00:47:32 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id AC2111C6380 for ; Sun, 23 Apr 2023 04:47:32 +0000 (UTC) X-FDA: 80711422344.15.2535150 Received: from mail-yb1-f179.google.com (mail-yb1-f179.google.com [209.85.219.179]) by imf17.hostedemail.com (Postfix) with ESMTP id 048F140010 for ; Sun, 23 Apr 2023 04:47:30 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=OsvSozEg; spf=pass (imf17.hostedemail.com: domain of hughd@google.com designates 209.85.219.179 as permitted sender) smtp.mailfrom=hughd@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=1682225251; 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: references:dkim-signature; bh=5D3feF4PSSkQcO2AaQ2Qdwn6n+8ejKfwGR371I/nVE8=; b=iyeNStVCDLpgWl3/D6+O1nS7iWIFmtXghuyiJ2I4QrLCEtO7gT5UDbiUvdaxtF6SeTqqIU VcT95miJPvFoiTsMeCv590J6VhZ6PQuE7G/8p442G3LdsauX45py5VLPSjFLs9ufkJ4nQG kqMoz2IaOuOk3HLzttGttoD3C0Ctdb0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1682225251; a=rsa-sha256; cv=none; b=VMnyZ2Vn2MYzCOPXXI9/VijCosCRTfFK4k2xTeNt7u2gGB5AU3BGql5oMLLeh9CeJodbbJ 46EeO+5n+zqGycyrm77G+yEuDFSDB0/yevtEoCtcIsujMwMRq2hINlDKggXA3KPKcq+lkR 0JlRQxcgZvQ+tXy13UUhMCkkBuon0wA= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=OsvSozEg; spf=pass (imf17.hostedemail.com: domain of hughd@google.com designates 209.85.219.179 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-yb1-f179.google.com with SMTP id 3f1490d57ef6-b992ed878ebso7900496276.0 for ; Sat, 22 Apr 2023 21:47:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1682225250; x=1684817250; h=mime-version:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to; bh=5D3feF4PSSkQcO2AaQ2Qdwn6n+8ejKfwGR371I/nVE8=; b=OsvSozEgu2GbNBizVFQdIkrStd8lwIkOI6yM11vnuZorInZvUG3O+O48DbL0qku65S WirI+g6wL1j+Fwjaq2xBqp5EbEQ7IZWpNAKU3urgZxxhXFposElUjSIEGNyd9JdN2AtE hRpEMOw27q5OjX8kf4YPwHI41urHDD0x2cxmxn9S1hhScpx4yYGVAYIRC50JWXmvxUnZ RVA3EW3Oq7Nn5L6lZ4gy/4Ygglq0T6PMYZieudrfY/OjAVNpD1s5bkWF8LVN3Olx1BeR 8MjZQIj7cJ622HgnFNqTww1I35wNp3S9vGHw5wsptIF/uN8kjL4YztG/hCIMUopAccD9 3xMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682225250; x=1684817250; h=mime-version:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=5D3feF4PSSkQcO2AaQ2Qdwn6n+8ejKfwGR371I/nVE8=; b=HN3NXPcbmLzpGhv7GG4f8uVglTfpKvlhkxYYWOdsKNczYeZmroKrxlbtX61dElmJ5s 6klmKWGf0Ju9gCgbQQ6gEsc+629UK5oZxtvxACwUPAzfAjkDvRKDJTWiEVvDCNrPlpo/ v2I180zwHzVy9M1jMZZLBoSOB9LPiP7ZiP0yK7ZtRcooHn4xCNEJrE+5B7a9rgR2uQha fRGl+qDc5NrM/TPh6OBZ2JxkrNr9ezemLdkQdbxzPdvMgQIzSif++dTytocK+cjVhNxF sHpuPVnQMni5N8MiyUZKZj1CUwQJ4Jtxn49jeyxiRrlNJGg0GKdzh+J8becu7Gl+qESr JT3Q== X-Gm-Message-State: AAQBX9dFtfumcQ4AaWkCXdaAVLrUq+298dPXINLFkL3j+87AaQn/s1GF Dni9liLcLICVVZ8FtLLN1+RM0Q== X-Google-Smtp-Source: AKy350bD+eVu16bIy5Bp7eNcb9NeaVxoOCKJu7qHcQIXSMztOqAWfAd0g2KxnRTKfQBinxo8RRCy5Q== X-Received: by 2002:a81:8301:0:b0:552:c30d:2243 with SMTP id t1-20020a818301000000b00552c30d2243mr6717824ywf.11.1682225249939; Sat, 22 Apr 2023 21:47:29 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id u185-20020a8184c2000000b0054640a352f2sm2056704ywf.20.2023.04.22.21.47.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 22 Apr 2023 21:47:29 -0700 (PDT) Date: Sat, 22 Apr 2023 21:47:20 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.attlocal.net To: Andrew Morton cc: Ivan Orlov , Jiaqi Yan , David Stevens , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH next] mm/khugepaged: fix conflicting mods to collapse_file() Message-ID: MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 048F140010 X-Rspamd-Server: rspam09 X-Stat-Signature: td5m18mgycpzakcucny37rx9w4xjwx3m X-HE-Tag: 1682225250-583460 X-HE-Meta: U2FsdGVkX1/eoHYAJVHj7Wxh2fRlkqTjzusINHRe/82DE5iqRy3K+XTULGsVa+HmCpNk6LujOvlr28ojLi8fVgWCLj8uaWxlkv7QKhlTxdYUU2axXAtHyLkcXF1vrKLqzsGJlHI7gnkrwHEErS91ZvaOh4YUbtKYYY8zZ9Xhj91AMaPw2VjwWz3aSttBZFDL4NLAdHLv0VwsozuHbPoo3P9tFEFhaVQoAE10lvDdkLuR0FX9X0g5HYerkuAszYI+zz9e4qUdsXSKEZuMajpdXLudEN//U6wbsabcUoQwiPzvH4YxSb2Pfr1wp4xSPfEOT81XmpoE4txPfvkIEdQvxbOt3elYUrDYtlQBd+20IDzjJmhTkY5/HxWgmO34othf4sIuzPnR9DjXxHWAUpVV68y11qzYjo+ntaa5/LD1paXvfDLM85NV4OzBcBSNMHFzEpaoya7wbITVu8zvhDqSm1qaXPTIOzcMv0xkv2PPndjnBREWR22zJfqGUpB3qxKw/zc0OVBCMJRNjDFTIdB2D3c/g1KJD9vtDlcRUp0L793HJIIey62mlIUmppXgHXkNz2AgcgKajg1a2zOxvrAFWTy8PFqJsQHY1aqpcRH82bmuQhHlADHfIGmc7QNoqI82D5kiHPzP7fItQHptNWfevFVKUeYy0xDt9ZKzuIgi5aZOJ8mp7f8yCz2YWk3qb3g+NtWJe0/WKkGovkYoHu8fcN7CDqZNHWWVFfUmlQVRxhQyhTinKULdi1aOcy2/c3fMHTldKRIHYd9WzxlCehCwBaTPHLWKfedLPDCYyNFudkCzmVd1TpfqKWS0O30roWfCRVtvXxFsA5PlaHLTb+/R+2xuMqrlhIuEb+1C+7Rm2hyniCdA/ZV+4roOT9MMEVdzeWm9ubsYX/PamaCOk6gsGpHFbcozdzQvSjVSNxqXhxuE9bVoQedhnU/NV5r2LCcQ4Bkcv1PH+l8OsEPm+27 VfKxK9dF /Pi5KdDQhxJm/MvdkDedaBS3K4e/gODj5Lu/RmJSYoLLbSzJ76p7CLQZukCyujvk8zA+KuUGaJEe8ZU/r+tFFQKYY/z3DNTxbFqf0OgKigwWpmB7+GAjbbbeISG9POl0DB8YZ0vF41huEG0w4QIRGPT/SwBNIjVNkUivJojs9SI6F4HSgTViPO4XDUGplBIYByz7h/O/dIe5SHbGgmDZDKtiqOmhpjJL8fQBhTRihetK3k7fCxNYPXTrZmjQ5ypavVt3cs8deRG5O+/2KIdJloNG513FOS57OzsIACmctlVLEkaeY8QnbD74NtC+DYQlAVvaEZFijs3fJDfxpVbuPuwrozp0nTXTVarwNfzGbsfZIRp/pn3eK8f6sQwK7lhQX8V642ar5eqQ2esIP6WvcBdV8dnv4oz3VpsA4B8DKlqxU0lqldhCJwtwdSucdG0DXbWWUohg+aC+w62YkY6g/WjAQRQKQHlDqv7zi0niu5galG0g+fW7gw0NKHA== 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: Inserting Ivan Orlov's syzbot fix commit 2ce0bdfebc74 ("mm: khugepaged: fix kernel BUG in hpage_collapse_scan_file()") ahead of Jiaqi Yan's and David Stevens's commits 12904d953364 ("mm/khugepaged: recover from poisoned file-backed memory") cae106dd67b9 ("mm/khugepaged: refactor collapse_file control flow") ac492b9c70ca ("mm/khugepaged: skip shmem with userfaultfd") (all of which restructure collapse_file()) did not work out well. xfstests generic/086 on huge tmpfs (with accelerated khugepaged) freezes (if not on the first attempt, then the 2nd or 3rd) in find_lock_entries() while doing drop_caches: the file's xarray seems to have been corrupted, with find_get_entry() returning nonsense which makes no progress. Bisection led to ac492b9c70ca; and diff against earlier working linux-next suggested that it's probably down to an errant xas_store(), which does not belong with the later changes (and nor does the positioning of warnings). The later changes look as if they fix the syzbot issue independently. Remove most of what's left of 2ce0bdfebc74: just leave one WARN_ON_ONCE (xas_error) after the final xas_store() of the multi-index entry. Signed-off-by: Hugh Dickins --- mm/khugepaged.c | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -1941,16 +1941,6 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr, result = SCAN_FAIL; goto xa_locked; } - xas_store(&xas, hpage); - if (xas_error(&xas)) { - /* revert shmem_charge performed - * in the previous condition - */ - mapping->nrpages--; - shmem_uncharge(mapping->host, 1); - result = SCAN_STORE_FAILED; - goto xa_locked; - } nr_none++; continue; } @@ -2105,13 +2095,6 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr, * Accumulate the pages that are being collapsed. */ list_add_tail(&page->lru, &pagelist); - - /* - * We can't get an ENOMEM here (because the allocation happened - * before) but let's check for errors (XArray implementation - * can be changed in the future) - */ - WARN_ON_ONCE(xas_error(&xas)); continue; out_unlock: unlock_page(page); @@ -2134,11 +2117,6 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr, } } - /* Here we can't get an ENOMEM (because entries were - * previously allocated) But let's check for errors - * (XArray implementation can be changed in the future) - */ - WARN_ON_ONCE(xas_error(&xas)); xa_locked: xas_unlock_irq(&xas); xa_unlocked: @@ -2259,6 +2237,7 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr, /* Join all the small entries into a single multi-index entry. */ xas_set_order(&xas, start, HPAGE_PMD_ORDER); xas_store(&xas, hpage); + WARN_ON_ONCE(xas_error(&xas)); xas_unlock_irq(&xas); /*