From patchwork Tue Apr 18 06:19:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Stevens X-Patchwork-Id: 13215068 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 D7283C77B71 for ; Tue, 18 Apr 2023 06:22:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7203D900002; Tue, 18 Apr 2023 02:22:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6D07C8E0002; Tue, 18 Apr 2023 02:22:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5BFBA900002; Tue, 18 Apr 2023 02:22:13 -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 4DA8B8E0002 for ; Tue, 18 Apr 2023 02:22:13 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 23BDCC0144 for ; Tue, 18 Apr 2023 06:22:13 +0000 (UTC) X-FDA: 80693516946.09.2E713B9 Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) by imf11.hostedemail.com (Postfix) with ESMTP id 5207740008 for ; Tue, 18 Apr 2023 06:22:11 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=YG8GY9X0; spf=pass (imf11.hostedemail.com: domain of stevensd@chromium.org designates 209.85.210.180 as permitted sender) smtp.mailfrom=stevensd@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681798931; a=rsa-sha256; cv=none; b=4X15rQKjzxDpi01/B0EJPIVO3ICdRMpRL1pApSiD2Ks0pAgzElRgd5C4PleAcTbmTnhGNE Zmy+yl1OTP1u/Ud/Inp1iAuvdxN7fKFIHoqzDwpZuF/UZlDOSVgf6KDhI7XAD5np6VcQLB a4y8/gdy9teAOplC4D1yfvIV9FSZ784= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=YG8GY9X0; spf=pass (imf11.hostedemail.com: domain of stevensd@chromium.org designates 209.85.210.180 as permitted sender) smtp.mailfrom=stevensd@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1681798931; 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=TzsJOek1xUBUP3YBf2eRQeEhD3Svo6XZElWtbVkMay8=; b=O2dTpi1DEgP2tWJN8iDrKm9veyjMcbSNFpvvNybdzEVqha3PGmMASbscvMcpcO3W58SFsI BU5upWq86u/XboOGyeFLytyrB892zlRceW8+/7z5E3hSGm3NTkJE3XCLAlUlPfZzae16v3 1bHzmpzAbPGkfzqKKpPdqUBK6WNhC2A= Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-63b73203e0aso6229639b3a.1 for ; Mon, 17 Apr 2023 23:22:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1681798929; x=1684390929; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=TzsJOek1xUBUP3YBf2eRQeEhD3Svo6XZElWtbVkMay8=; b=YG8GY9X07EnaHeXxr8wLKzOvzsN5/4sI2DjM+Hs7zCu0UrsPJpTXrkguwMwOodWMhj YuWGFpmoa/JBZbBQUPXduM796ikNDuaA5AqxnGk4Gxr6LOwHK4xb9zKQkU5j2KjSvTwq G/oom33AwqUG8m+kYYxiVYv7qucS+Xzh21xCQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681798929; x=1684390929; 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=TzsJOek1xUBUP3YBf2eRQeEhD3Svo6XZElWtbVkMay8=; b=iIvl04IUrbeGCSzsa2LrzUfuTBOJ/Cpudy8AXb2T5vxe0IGY6JY6rjKcvUjprvjsiU bqZq+5vEyh4/A3P1k7/FYFJq8OK+WaHKNe8SEo7jj/mQWrGbFq3cDtuW98iAszOpbzVS 4tsXjkcNNjCqewsF+V+5s8NMaWtLGUniPX0NpIunpmPAkOszaVFCynB8yugY+ID1Hh/M j1hIrpcRZCQUB68+dTX3bby1Xy5NgsaMfJa5tqzfIxImwDZRO6v+/JvWiDmYTTeOlVzU FJwb2rSgLGaZUDLqAIznONdgS2Hqahe1pLJrA/ITKg1/KbXaUanoGMDXj7j6FTN2Emp4 evxA== X-Gm-Message-State: AAQBX9c75mhuw6U1eoaZJYD2KIgDZCaYb3+0hvt5zhqBYrOYex2WZlyw kdZXbSu+thVvDjNYuJDDS5Lw3Y67viklUmvSwXk= X-Google-Smtp-Source: AKy350YC4kATbrbaiGVRNclTWx4ZyFk0H3RATKfFe3sPz1aERFzAxQSeiybCsl58pGi4Nscbz6cMzg== X-Received: by 2002:a17:902:ec8f:b0:1a6:9762:6eed with SMTP id x15-20020a170902ec8f00b001a697626eedmr1274445plg.22.1681798929447; Mon, 17 Apr 2023 23:22:09 -0700 (PDT) Received: from localhost ([2401:fa00:8f:203:7254:8270:74ed:755b]) by smtp.gmail.com with UTF8SMTPSA id v1-20020a170902b7c100b0019d1f42b00csm8717437plz.17.2023.04.17.23.22.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 17 Apr 2023 23:22:09 -0700 (PDT) From: David Stevens X-Google-Original-From: David Stevens To: linux-mm@kvack.org Cc: Andrew Morton , "Matthew Wilcox (Oracle)" , Suleiman Souhlal , linux-kernel@vger.kernel.org, David Stevens , stable@vger.kernel.org Subject: [PATCH] mm/shmem: Fix race in shmem_undo_range w/THP Date: Tue, 18 Apr 2023 15:19:33 +0900 Message-ID: <20230418061933.3282785-1-stevensd@google.com> X-Mailer: git-send-email 2.40.0.634.g4ca3ef3211-goog MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 5207740008 X-Rspamd-Server: rspam01 X-Stat-Signature: 5mddiaregkfimihdwdqmkdnrjxh153oc X-HE-Tag: 1681798931-37318 X-HE-Meta: U2FsdGVkX196651xUjk7Y9gHYTMJSOmbLHwEKdBbNJeT6RzX1pmXyM5+HqdVgvHMGjc3ag5pti+gDpLl9Nda+Ofyaw112RUtmWzf3F0MZcmx5QaNqcL/ZkEzaVtxUfPKumhg5+WghAIGx4pBxCptWHuiYQAgUDSw0t0vpDM8tyqm8u6WlAJF8/weZ0mOU/ubft+qu1EmqKk/xwHTmy/kvRopeRrbRqkwS+4utyo61zNtdhr1B/ExXNxjIsmdNh3VaRLEMtBj8bDOuazcQq2fFqILidHtqU348/gxJOeALlp+YYKuJ3XpBjamTg2HJUYHdsppfvT7DCc4FOUhwVBGzvwduDZIj4ZC1AY1SNhKLOeHIZpSPa40quwf0MDOLhWHOawWS06bmdCP93xumDo9pprvMw5rpQSHk4RlokRWofV7BQQ20rd9oTDj6nYj3B2W0ZrL1xMsXPODfXVejMG3QtFM+QPy4BfrvB3xxP/kvZvlqnFzVmrbjkdRRnot74V7elnlXOBS6QXTP2fB3GBxRWv60UENE9aqeSkgWY9vyPqDgmQqfUa+QtHXRRfthURdl6kuncC2Qm7nt3VlvpOZGhU3fueS47wWLPzyLOfNsQ88xNNZrVzNvf6UHgAyAIMUYY+dn8bD/xp3U5pR2IrlwAVSsOXNwnNpBkFCp7A3yR7o9Gy7nmKJhoSrREI7aB6aN2oVc1QoWYnpJuTjzcXuebFYx9D79YMS9MuBhrTqxQdWncAQT/kaoTFNILFW+W51ss9CQrX/EB/XfW35KImLQkrhU8vR7aFHjb8NjPjuwz0/C9ukVPtGGUTpTquVAUJ+xPAC6kea1CKCFv7bmCZwn+X6Y7l2NPxXh91dE6d9iLbm/R6l3pCWiAuCatoPxsDO0f74sdY7JaWrun4UCI+x4QlUh17W6mH+z+vZ5zKyrcIvuSUlstZjeFaF5umWSMwdFDraWZ5uCwziftRvnUc 4hCBjgQ8 Hg3Dhni+3S8j2Krzmesyw+j7L7MBD4RXLYXr60WQv29h69vuFXzxNl7LZ4JVrtOppY5kftnrllca43ud/RhpQtHLWoUU7AEpQihRcH+en4MqJiFZTN0qf4zBhnApQ+8sZPLVqCagtSlSdN6x7/KSSaZ4rwS53t9Bb0Kr1HViggI3LEfg0povDQ7tcQWCpexYyDL+hxeWI9rKtQlFf9H3GfsSzmKpYkq5Jzt78hU9ZKZltatjSZSss8kBYsadT7t7V9RbvntET9PY0/CxKAR0SAR4gdJ37kz/kk9c44Vy81F3YuffL9+QxVptdgbG46Nq8Itgb+iDDxm7ONPa3g0XKjEV9+RNR8q59QEcYDX2K1rQWNuzDv02hxXq7EvtIOKRHN/nDsRuDGZl1mpz6zSw6GwTKjb1Hs4vIXQhZTNhSeE441qqFgyKaH0jHPG3tfeK1Zuf35gCROeN/zdU= 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 Split folios during the second loop of shmem_undo_range. It's not sufficient to only split folios when dealing with partial pages, since it's possible for a THP to be faulted in after that point. Calling truncate_inode_folio in that situation can result in throwing away data outside of the range being targeted. Fixes: b9a8a4195c7d ("truncate,shmem: Handle truncates that split large folios") Cc: stable@vger.kernel.org Signed-off-by: David Stevens --- mm/shmem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/shmem.c b/mm/shmem.c index 9218c955f482..317cbeb0fb6b 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1033,7 +1033,7 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend, } VM_BUG_ON_FOLIO(folio_test_writeback(folio), folio); - truncate_inode_folio(mapping, folio); + truncate_inode_partial_folio(folio, lstart, lend); } folio_unlock(folio); }