From patchwork Fri Feb 17 08:54:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Stevens X-Patchwork-Id: 13144436 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 A9096C636D4 for ; Fri, 17 Feb 2023 08:55:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 393F66B0074; Fri, 17 Feb 2023 03:55:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 344586B0075; Fri, 17 Feb 2023 03:55:05 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 20DFB6B0078; Fri, 17 Feb 2023 03:55:05 -0500 (EST) 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 13D026B0074 for ; Fri, 17 Feb 2023 03:55:05 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id ACFEEABD51 for ; Fri, 17 Feb 2023 08:55:04 +0000 (UTC) X-FDA: 80476174128.28.17DF30C Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) by imf03.hostedemail.com (Postfix) with ESMTP id DE76920029 for ; Fri, 17 Feb 2023 08:55:02 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=AxKWq247; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf03.hostedemail.com: domain of stevensd@chromium.org designates 209.85.210.173 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=1676624103; 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=jW7jj7f6MP9PxLSksLkqYvzlSatAtLM3QwqY5I2bMTs=; b=Z0eGhGduEp56wUz+pjkK1EMCPliTghNH87mYOXJu9piut5KmL2dM8ReTr4JfzySOqgPO2I i5dSnKtD7Y9B6pXlg+spu77AyRh/c/21mcBgRUkoY9qOhGKZbUqbNg9N0Eb8HTok5AT8Qb DPZNVEzmH40xno1RQIxSC+ZcNm/JAAU= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=AxKWq247; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf03.hostedemail.com: domain of stevensd@chromium.org designates 209.85.210.173 as permitted sender) smtp.mailfrom=stevensd@chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676624103; a=rsa-sha256; cv=none; b=vg1FcU4xYTh4/29OdBo/YHMP1gvr8Ps4aouQOYzoZeU1H2Q3HcCuK+02T2eQrz7rDz9huu hnmLCyTyMSeOox+w7q+1CnNSrBdy/X8LOfbtejs1eLZLxXfD+hlhO+roJmlhJ8L9auxbMl JUNS2FR7frAHFm+9k2RK9a0Y5YzeJQM= Received: by mail-pf1-f173.google.com with SMTP id p33so222793pfh.2 for ; Fri, 17 Feb 2023 00:55:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=jW7jj7f6MP9PxLSksLkqYvzlSatAtLM3QwqY5I2bMTs=; b=AxKWq247OiMsgwdjeZG4onLqOOczVeFhigzgMW36NqP3PnTtr07pQcIC1NkUqoUybP Z2DyZ6zDOWze0riOIPhsGIdG+A+wTKsQIqeazKwMz6LJz9bLLXgFxCOY0AU84qR4RDZL xNohVtblk/uKWsKH9xK3lezjLER2Of2GPjl8M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=jW7jj7f6MP9PxLSksLkqYvzlSatAtLM3QwqY5I2bMTs=; b=YX//8qMVZ4HtR2scvAUx5K2tVLDcqEWqi+Bceb6OlQGK4qp0EmZFVpDzMm42w+vLeP 4gFrAjyIbfsC72K6+nCJ4JqX8mvaYUwuBm5+XrC29CJ0m0PFQicnDGhLxYB7P/6BBawi 9bn/StQyPOTFEGZlUG7UbhdJft8Nu5bocrLSgE9kKJBf+3U90QaO6OIcewIV/fK3DmzX MSy8YKTCrbGivrkRqQj13xh0z4q1JGWsYYvY9VaOVOSZIFWKmU7kKNgVtspUezZ64/LM h6E5Xjzm9gZO58l3HHCmHbOBmx5ct4qNgID8XwFtxX9ST+yhSELlkecqBrLluYuCPyGj g3RQ== X-Gm-Message-State: AO0yUKXxquep308kxBNyTu68zLCopq2rlG2GpCPiudYnem28s7Tbph3P mWV7iDvrS1So/lgYgThtgmOZdbyCU0OWRd3p X-Google-Smtp-Source: AK7set8sxc3XjPtlUCSHKtLA+vXLcsVBezbuhd1RvxMP54fMig5RoihUdtXrlUEJbwQu1Tm3esJyyw== X-Received: by 2002:aa7:96ae:0:b0:5a8:31a1:2f05 with SMTP id g14-20020aa796ae000000b005a831a12f05mr211084pfk.5.1676624101229; Fri, 17 Feb 2023 00:55:01 -0800 (PST) Received: from localhost ([2401:fa00:8f:203:b7bc:8cb9:1364:30fb]) by smtp.gmail.com with UTF8SMTPSA id s8-20020aa78288000000b005a83129caeasm2576589pfm.185.2023.02.17.00.54.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 17 Feb 2023 00:55:00 -0800 (PST) From: David Stevens X-Google-Original-From: David Stevens To: linux-mm@kvack.org, Peter Xu , Matthew Wilcox Cc: Andrew Morton , "Kirill A . Shutemov" , Yang Shi , David Hildenbrand , Hugh Dickins , linux-kernel@vger.kernel.org, David Stevens Subject: [PATCH v4 0/3] mm/khugepaged: fix khugepaged+shmem races Date: Fri, 17 Feb 2023 17:54:36 +0900 Message-Id: <20230217085439.2826375-1-stevensd@google.com> X-Mailer: git-send-email 2.39.2.637.g21b0678d19-goog MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: DE76920029 X-Stat-Signature: 6rtzq86ukbx75cnadnyu1wyd87ptujmk X-HE-Tag: 1676624102-229053 X-HE-Meta: U2FsdGVkX19K54VLRYpf7PXkEEFtMXH9uAK8RCzDrjVRzpujfe3KCHiPdn8dnT+IxBGxKXheLJl1kuSFQEfTvQmB7wX26XzF6iuCa9Sy5FJoDZoLSdIayRJoSM400ZY+9nl/9yDhZgxB74B99fIyo/JhYOGRXFol1kDEK3q9UiZucPwcMmaEBCdppW43x/OCpg2wMNYj5D2JmC/f3FtwxqXFnOrAdKTFCWS7wFfwgcaZhq07NFXTyNUEAcRC/0xAN9fJjwt8cZXYRh145tUNdYwN7sPCeztE84+gaMyS7lCw3IweMRvDeVtnTWmw0UQB4xc1SfUJoHC4QQYIjuCK4RoxGAjVGBQZ/SByNcMO65uctZdyB2TGqQ4ORm/vhE4pm83Tpn92VyHabs8puVRC/ZWdrAa5em1qbm6g8FUE8Q4JqRuu/pDWxBxhLS7ZDZQ2hsrqJP57eK9ITLVBiC/YZnqF0t85SGHMDoGThrXPqDZCKcbm2BQ+YnPm1eIZi3p3R/9Z0RQ9RHMtEPYRAZ2YlYp0BGMGoS6vrAlVonj4jkH+5xbQrMNbVR5yG49udYoL6jm2UwKuCJHXcF40GEvyw0DvgEvOh9GjFlvDal3PO8d3gTQGGS7qnnQZlvOvUdWQVxYNkmvU36fNlIxQ7cU3Ni9qz9jJVqxSDxkQXwQOvBAcpqPWUC0S5kxmLeGqO6EFVvxy7SnGzqWDFZ+mw7ha+1LimzzmaYBq453lh9NDaX6yB3zt2QMJj71uzc3a7zjjK2Zbpa0wrnUuAlNghZ343egq/21bxg+pmnfQD8uKwwYKFWIcVEXjJvqMnEyKPzU7GX6waNJlDN+s7lxU3qZbN+7/2MXZDi0HXOwmFupxdsIKO72e5vq4pwpAMgaLC+vndfBRt7EDcD683MLveWtrmZF2Q2GH9hnzTM627WbJA99w9K1WkNmjMBc9KgzUrMUpQtz5DnKwVtNRHM5+9bt qL6myx4c AbdfZjTJo9JkQJFprZKCi9NXLMc8FaxAgyzRF8XRxVEgiOVhZ3NuglFgm+mU+tfBWHaQW0LwxlCcEAf54dNMe9inkuw2Trbw7vl8AS4c9JPP6WieeLgNvoJnixiW67r11E4Kw29Jx4wLiJbj9AQk73fhqQnpVTucFUwS+g0L/Nb/DLq/nOuKM2rXyBM8dzso2QPlILIKBXYYdLi3CRCSzNbEHdtrlqDy7QEiALjJBnc5+S8npo0BjlBrG8sNifvgze7dxe0ZxeszvLANhovesj7c2FMoRev5mJGNDezwowlV8cdhiCH7ZGC4OMSWppv2jy/N3 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 Fix two races in khugepaged+shmem that cause issues with userfaultfd and lseek, respectively. v3 -> v4: - Base changes on mm-everything (fba720cb4dc0) - Add patch to refactor error handling control flow in collapse_file - Rebase userfaultfd patch with no significant logic changes - Different approach for fixing lseek race v2 -> v3: - Use XA_RETRY_ENTRY to synchronize with reads from the page cache under the RCU read lock in userfaultfd fix - Add patch to fix lseek race v1 -> v2: - Different approach for userfaultfd fix David Stevens (3): mm/khugepaged: refactor collapse_file control flow mm/khugepaged: skip shmem with userfaultfd mm/khugepaged: maintain page cache uptodate flag include/trace/events/huge_memory.h | 3 +- mm/khugepaged.c | 263 ++++++++++++++++------------- 2 files changed, 144 insertions(+), 122 deletions(-)