From patchwork Wed Jun 7 05:31:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Stevens X-Patchwork-Id: 13270002 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 92E2EC77B7A for ; Wed, 7 Jun 2023 05:31:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CF8FE8E0001; Wed, 7 Jun 2023 01:31:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CA8906B0072; Wed, 7 Jun 2023 01:31:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B6FD68E0001; Wed, 7 Jun 2023 01:31:58 -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 A4C856B0071 for ; Wed, 7 Jun 2023 01:31:58 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 63C8780109 for ; Wed, 7 Jun 2023 05:31:58 +0000 (UTC) X-FDA: 80874830316.17.10ADCC9 Received: from mail-ot1-f53.google.com (mail-ot1-f53.google.com [209.85.210.53]) by imf05.hostedemail.com (Postfix) with ESMTP id 8031B10000C for ; Wed, 7 Jun 2023 05:31:56 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=HHf4ZsFD; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf05.hostedemail.com: domain of stevensd@chromium.org designates 209.85.210.53 as permitted sender) smtp.mailfrom=stevensd@chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1686115916; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=os/aeqRhsyR2udmNtFJcHkFZKaZyNQcEib6HfkQ0L18=; b=ICAMwGoe96RudGs+uTAqwp90NhB1+ddNuQ2dE5kqhb8aOhVR6vRFfrMS2h7aEcQz5sGaLL r1egwDb6AxTFVt9cc2LGeiiP2+QOIIgoN9eFj3qSP5IhEXiAmgbSDl8kR6rd8YJQB4X0Ug UUJjUa0Fg1Qh7tMP6lwOo+1KU58OWX8= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=HHf4ZsFD; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf05.hostedemail.com: domain of stevensd@chromium.org designates 209.85.210.53 as permitted sender) smtp.mailfrom=stevensd@chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1686115916; a=rsa-sha256; cv=none; b=FkX5agz2AFw2NDE6RjT+WDgvrJ7MQxp8nQfCvjFB1xjVKx8FtqR9+h8u+PM8d6ZzVB40cw fn2JrUUD5dwKwOZYYZ5D14Me7hDPji4H5GSjDisDrovLQ1PYAWZGlIJVsHj4T557PWnAIK vR9L1QBVK/qdmW+ZZsol4WB4eZKpG7E= Received: by mail-ot1-f53.google.com with SMTP id 46e09a7af769-6b291d55f52so1222470a34.2 for ; Tue, 06 Jun 2023 22:31:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1686115915; x=1688707915; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=os/aeqRhsyR2udmNtFJcHkFZKaZyNQcEib6HfkQ0L18=; b=HHf4ZsFDOATneFcjMagAeFdAmQa0S3zkFPR6Kl71dO6kSzG4yeJDphbAmWiXLpVWnk LibMuVLNT0qp7vStwD2E6gBmTwULqAq+v6LJKNY8Z6B4wfnKBJ59oYvBvOQoFET93b+d 1XWVy5sGRtsP4Q2A/XHEaaMj446yXhLNHvTxg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686115915; x=1688707915; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=os/aeqRhsyR2udmNtFJcHkFZKaZyNQcEib6HfkQ0L18=; b=daNAUganBkUTs2nAZHGtN5aaD03dcHXgGh4RUly/UFH5+57s8Fkm5XjisgIni/smWA ufbHkPZhdrT2j0Xv+fIf9iQeV5HetvgTnTqMEfRMIrTbuXgK8WPzGEUDce0guoA1ylnd KtxlNpfgny2ZL5luziJMEdog5fMS9cVaB5DLwPeFpHD5vwZNWfI0JTYyNwYYr63c3crS OQpWd1CZw8S82jSy6vBVZSLjs/+WuX83wGB4WEHZbAqg96rDaFuSyuSemzK8d1BazMz6 Wm94pY/3cnuvzEPq3SPpgIgddcf7goKZ5mnrIxACwA0NSJHiIn5VeavoX71a8GLPAQvB kapQ== X-Gm-Message-State: AC+VfDytYVuf4XsDC4oFN4B73EFNLkWjKYfXMyarmHp+7FB8YhvZVmwt WkJ8vHrWGwTC2zr0blPiBRDlHyC3cPBMxleB3oM= X-Google-Smtp-Source: ACHHUZ5lMJIND9Kzi4ibR4p+GOc+LHJey4+fB1q0UaEPsfdK6Vz/9m2eHCXPfGlL9pY/laVGtRBz3Q== X-Received: by 2002:a05:6358:1a9c:b0:129:c89e:46cb with SMTP id gm28-20020a0563581a9c00b00129c89e46cbmr951145rwb.15.1686115915057; Tue, 06 Jun 2023 22:31:55 -0700 (PDT) Received: from localhost ([2401:fa00:8f:203:a706:dc8b:addd:1237]) by smtp.gmail.com with UTF8SMTPSA id b10-20020a63cf4a000000b0050a0227a4bcsm8336856pgj.57.2023.06.06.22.31.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 06 Jun 2023 22:31:54 -0700 (PDT) From: David Stevens X-Google-Original-From: David Stevens To: linux-mm@kvack.org, Andrew Morton Cc: Peter Xu , Matthew Wilcox , "Kirill A . Shutemov" , Yang Shi , David Hildenbrand , Hugh Dickins , Jiaqi Yan , linux-kernel@vger.kernel.org, David Stevens Subject: [PATCH] mm/khugepaged: fix iteration in collapse_file Date: Wed, 7 Jun 2023 14:31:35 +0900 Message-ID: <20230607053135.2087354-1-stevensd@google.com> X-Mailer: git-send-email 2.41.0.rc2.161.g9c6817b8e7-goog MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 8031B10000C X-Stat-Signature: 9bohi6skx3ernkgifzbkgugiirybf388 X-HE-Tag: 1686115916-423325 X-HE-Meta: U2FsdGVkX1+QgkaJWWbnlK9V3W4pdQm0sB1OTDrzgCphjWiG1yg4AS/2akhJePbmVRlmGX+wel092KoKbmkZbQJZLP0Q2E1ScHx3p7VdaKIaMevpVdOHPOxu1xF1PQkLvVv63rxb76qz46iR9vzQtUZ06Rtbu8nSqaNwP1MAHaZbNkVe+6vIkdPqnaqlAoHNMS/+UT5nCHb72IKdGmSSxlg30xlygJo9DtBzEym+D9HcOew9gFB3f8ah00KCEpUeEsGnKdpdvmAMD43j5/iqsMbsyI3gtbEp8PsHFfyaUL4EJx19bsZyaluvO7iK3KUqQ7fQzdi7yp41SfLotEjONf0l4J8ZCV6OAm+gweF5satMdQfOoiHOBOxzrzlo52XD0Iw4tfui+DEqVDkBKRfhPDW7ENhNnHX03SBsIrJ320+GjTaDlH5nD8LjsRZ7Y/sh6pfEnqnC60vgPYMJZULt2ePPtkUCF7VqDrmp4VBoc0vWx6gy26fBs8jObM4AQiyoO/Ozgcm3Jwxq7DsNCe5QqW+Ydm5YfTPYQwSqS+X6SOZYApOWxC8rL6kI15I1g7BGSHv2XDvpQSKzrOaW5FSwQuBbi8D7BYfgllYh7yKBHNu+AtsxqbktItDLKtaO5JkRKUaD9IVt9uHYeiF8DbcnNYpIvGO+WQNOGYS7jjRNepcCp4UCkKiWXJOn90e3nGLuJGP6igxbs47W2pDTRovkbVAL5B2eM4bI5mzZFNen41hRxNmmWq0yjn5P1NN94CMFTAS4vaf6LRLUxWWPlIVQ8YIKWkM4ILeLPn9JQPXGXrjwwxU+uYEMhkRZOPoM4KY0DtLIYvOeZ40UYCXFfVPiBSlQQnUZo4trdhDEO7n7qBP1aZACHsgzSYjcCrH21VeToeL3Muvj/bwAUc4eghtdRUg3zAACwsaIkKf+dUu0fYd1oZHgc/28XjnyXdffRbbX3mpOKiJindVHwFAdf/K F+IpJXBl gEsBDGyvqcaHmmnCb/jtD5z01oCTCnCl0Jsirr2XgW7Z88kbeM1zN8UREPVbRVJRrrTHJpjYEKFkIuERQ8ndJh8qaNq59g2eN3sPSSWGTUGDQ6N/+NGdWtqefYwtb8Rxhc4B80pyDj3u+Ahtj3dnx//NZ3D+/fKHhFUPbfPX6FSsXwXyNyX9nsstp8CEZLxJjTQBHqt8lBu9r4aO0nTzRku271TiCkasSNyBlTf6DeXLLLpWeOrkvWLm4SSF2/nON+wmyEDaShDfm3QygvDVaTDZNzN0lhVEl8b9w4AbdqQrIw+37PN7DHh0F8tM5e73ndqZpYZ8RWtIf9T/JGWe/BwcV3NV4l3vm4Vw70/q1r0itc0PzjOPZHkFeMw== 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: From: David Stevens Remove an unnecessary call to xas_set(index) when iterating over the target range in collapse_file. The extra call to xas_set reset the xas cursor to the top of the tree, causing the xas_next call on the next iteration to walk the tree to index instead of advancing to index+1. This returned the same page again, which would cause collapse_file to fail because the page is already locked. This bug was hidden when CONFIG_DEBUG_VM was set. When that config was used, the xas_load in a subsequent VM_BUG_ON assert would walk xas from the top of the tree to index, causing the xas_next call on the next loop iteration to advance the cursor as expected. Fixes: a2e17cc2efc7 ("mm/khugepaged: maintain page cache uptodate flag") Signed-off-by: David Stevens Reviewed-by: Peter Xu --- mm/khugepaged.c | 1 - 1 file changed, 1 deletion(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 6b9d39d65b73..2d0d58fb4e7f 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -2070,7 +2070,6 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr, TTU_IGNORE_MLOCK | TTU_BATCH_FLUSH); xas_lock_irq(&xas); - xas_set(&xas, index); VM_BUG_ON_PAGE(page != xas_load(&xas), page);