From patchwork Thu Sep 26 06:46:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13812856 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 1D9BECCFA07 for ; Thu, 26 Sep 2024 06:46:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8CE7F6B0098; Thu, 26 Sep 2024 02:46:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 87DBD6B0099; Thu, 26 Sep 2024 02:46:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7456B6B009A; Thu, 26 Sep 2024 02:46:53 -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 555546B0098 for ; Thu, 26 Sep 2024 02:46:53 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id B9271ACD32 for ; Thu, 26 Sep 2024 06:46:52 +0000 (UTC) X-FDA: 82605956664.27.7258A03 Received: from mail-qt1-f181.google.com (mail-qt1-f181.google.com [209.85.160.181]) by imf04.hostedemail.com (Postfix) with ESMTP id 557704000D for ; Thu, 26 Sep 2024 06:46:49 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=BwXvl2EB; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf04.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.160.181 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727333122; a=rsa-sha256; cv=none; b=aU1HSEYJByOXZD4BMKsi+k2cnpwE8rrtkurWrtjwOc5wGabDBVGU5+YTNVLDQKlakfDmkr NuJypBBROaIL7e7Ne6NgT5S8j8somaUaVZnM3LK85akilCkGxzoJvcLPt/9/9NSzQR7QFj FrFuGJUApIDgdfIi/jhRJSH2SjzOdug= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=BwXvl2EB; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf04.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.160.181 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727333122; 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=psD5QBE2/gRnBoEm6qk1NsXq2zG3EMB2GGe+WDIIiWM=; b=FbU0DQYBGdqg3uy5msd++qZaXktmOCSf7t9ztmiCabeiZEcj/3zVKGLDgacuTuqFjB8wn3 wBPxZBm3i9ahc5ojhxLVbWJR2pEpPitthLP0Cl6crvrdANQKKPD/tNTbFwy3vSb8kH18vB kPtoJbl5gogNW6RvTYgWQKYN5l8ajlc= Received: by mail-qt1-f181.google.com with SMTP id d75a77b69052e-456757d8871so3875131cf.0 for ; Wed, 25 Sep 2024 23:46:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1727333208; x=1727938008; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=psD5QBE2/gRnBoEm6qk1NsXq2zG3EMB2GGe+WDIIiWM=; b=BwXvl2EBb7awxbz5Y9ImovgjcSaGNDpNvwGUgihPM1gCTSlJlPp/2TdoQiYTLA5XSs 7B+r2HG5rFKE4KRXlHnApwfFEHmRHw8bMma9QlgK7OnNIiiKYZGfQn6rdSjnHuQ4/oBO aWdZFRkuhmU/PQrSG/eB7V4McSXXgX08YkqHquy3vrinGvdNz6Qn/gJ1FQhw4kmxsbZW j24yH+ckoIZhwgojOAamG4dn10V6st3TtQEF7XoijsLhfa/wVOFMqR9RezgVt+4jDYcY fQUxHo98FJvif3hMYifXj/vxfnrj8mDeZXwO2psPwObPIXCXB0xICJrkY1Ry88+f5MYr XY9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727333208; x=1727938008; 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=psD5QBE2/gRnBoEm6qk1NsXq2zG3EMB2GGe+WDIIiWM=; b=if/RjZY/YN5wL7zd0puZu5gHXih/zG+0Af15F+KAMh1Vz2+ZVzZmUNp9dbALDGFt// MpHlPx+ZaHwhLpJci1nmYcAy0z56BT6CGTkHXCj3LwrLaemHAzTzI6ErUBXorBzNAk4M YldTpHKnT9hlWyLR1cOOyw/4rYCbz+rsPHlSKpmS4HjHpmXZgLuLOLSARPJOSze5ZFjM JaAd9sdgCF3BlcuayBO2z5AlNBq7wcCcr9TQGSQviBls1IiPKb4sl5CMpTmtL8mKrQRw 4pTvY++kTKcGAikW3CJagIGeZ5tzOrH2oxPpcqp+wPzqM3v2UTPQF8gO4HNXrXZxo0cL NmKQ== X-Forwarded-Encrypted: i=1; AJvYcCX18nhlt62h7JR6T5A8D609RaHpoFwNp4pt4wNNSBvPAcNhf0bMGeu41gKyAzMZXRo+kGZMQpzDnw==@kvack.org X-Gm-Message-State: AOJu0Yyrn/YLECYlW8vTIXxG6IbcnpeirxsKSkTO3dqegWRhyhP48pZh e2WVCY/Y2Rg37kku6L5HJQtWpbfnboCMZA/vRy9A62WN4fNrEjomjqil4Laod7M= X-Google-Smtp-Source: AGHT+IESrskC0O60xJo9CKcSFqAz070fd6XCEqJPS1rPBwM9ByQ3Zw6qYsXl3/Ca/QhHASyX7ikg5w== X-Received: by 2002:a05:622a:1311:b0:458:34ee:3a4b with SMTP id d75a77b69052e-45b5dec78afmr74252701cf.6.1727333208088; Wed, 25 Sep 2024 23:46:48 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.150]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-45b5257ff1esm23024611cf.38.2024.09.25.23.46.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Sep 2024 23:46:47 -0700 (PDT) From: Qi Zheng To: david@redhat.com, hughd@google.com, willy@infradead.org, muchun.song@linux.dev, vbabka@kernel.org, akpm@linux-foundation.org, rppt@kernel.org, vishal.moola@gmail.com, peterx@redhat.com, ryan.roberts@arm.com, christophe.leroy2@cs-soprasteria.com Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, Qi Zheng Subject: [PATCH v5 00/13] introduce pte_offset_map_{ro|rw}_nolock() Date: Thu, 26 Sep 2024 14:46:13 +0800 Message-Id: X-Mailer: git-send-email 2.24.3 (Apple Git-128) MIME-Version: 1.0 X-Rspamd-Queue-Id: 557704000D X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: c8dun4g7y1ujoasadjw49pdkj8391ui1 X-HE-Tag: 1727333209-605911 X-HE-Meta: U2FsdGVkX19YmTodXAj1dTWLglRoBRmA4l3wGU+AwzCQNwnn8mJgMCPIJ3WGh9XY5J/8koais/9oOwXRWq72ynOqK5t1IOa/gupQGVhkJh3Odh8G7l3VDyucGfSa7tB8vgFKa2QXS/qbOtPSwlSDAjjm1cZFqNFGzxuHD34iTUvaAH/7IRCW/kuHUwg7qGfLSfPPTU43Z55h5JBWpPfm6yyrdUFO+1x9aR4r5ROFwBqTzKKqj4cDlsPPdnnWfo7TROcH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Mb7rf2Wl9bmmwxZE4sOLqUDj9Usil/ngiyUrMXaAsprMlmaoDYYQPoZ5fREj9uG/St1WkB7jOA== 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: List-Subscribe: List-Unsubscribe: Changes in v5: - directly pass pmdvalp to __pte_offset_map() in pte_offset_map_rw_nolock() (Muchun Song) - fix the problem of the reference of folio and the mm counter in [PATCH v4 07/13] (Muchun Song) - directly pass pmdvalp to pte_offset_map_rw_nolock() in map_pte() (Muchun Song) - collect the Acked-bys and Reviewed-bys - rebase onto the next-20240926 Changes in v4: - arm: adjust_pte() use pte_offset_map_rw_nolock() (use ptl != vmf->ptl to check if we are using split PTE locks) mm: khugepaged: collapse_pte_mapped_thp() use pte_offset_map_rw_nolock() (move the pte_unmap() backward) mm: copy_pte_range() use pte_offset_map_rw_nolock() (remove pmd_same() check) mm: mremap: move_ptes() use pte_offset_map_rw_nolock() (remove pmd_same() check) mm: page_vma_mapped_walk: map_pte() use pte_offset_map_rw_nolock() (move the assignment to pvmw->ptl backward) - remove [PATCH v3 14/14] (will be sent as a separate patch) - reorder patches - collect the Reviewed-bys - rebase onto the next-20240923 Changes in v3: - change to use VM_WARN_ON_ONCE() instead of BUG_ON() in pte_offset_map_rw_nolock() (David Hildenbrand) - modify the comment above the pte_offset_map_lock() in [PATCH v2 01/14] (David Hildenbrand and Muchun Song) - modify the comment above the pte_offset_map_rw_nolock() in [PATCH v2 06/14] (David Hildenbrand and Muchun Song) - also perform a pmd_same() check in [PATCH v2 08/14] and [PATCH v2 09/14] (since we may free the PTE page in retract_page_tables() without holding the read lock of mmap_lock) - collect the Acked-bys and Reviewed-bys - rebase onto the next-20240904 Changes in v2: - rename pte_offset_map_{readonly|maywrite}_nolock() to pte_offset_map_{ro|rw}_nolock() (LEROY Christophe) - make pte_offset_map_rw_nolock() not accept NULL parameters (David Hildenbrand) - rebase onto the next-20240822 Hi all, As proposed by David Hildenbrand [1], this series introduces the following two new helper functions to replace pte_offset_map_nolock(). 1. pte_offset_map_ro_nolock() 2. pte_offset_map_rw_nolock() As the name suggests, pte_offset_map_ro_nolock() is used for read-only case. In this case, only read-only operations will be performed on PTE page after the PTL is held. The RCU lock in pte_offset_map_nolock() will ensure that the PTE page will not be freed, and there is no need to worry about whether the pmd entry is modified. Therefore pte_offset_map_ro_nolock() is just a renamed version of pte_offset_map_nolock(). pte_offset_map_rw_nolock() is used for may-write case. In this case, the pte or pmd entry may be modified after the PTL is held, so we need to ensure that the pmd entry has not been modified concurrently. So in addition to the name change, it also outputs the pmdval when successful. The users should make sure the page table is stable like checking pte_same() or checking pmd_same() by using the output pmdval before performing the write operations. This series will convert all pte_offset_map_nolock() into the above two helper functions one by one, and finally completely delete it. This also a preparation for reclaiming the empty user PTE page table pages. This series is based on the next-20240926. Comments and suggestions are welcome! Thanks, Qi Qi Zheng (13): mm: pgtable: introduce pte_offset_map_{ro|rw}_nolock() powerpc: assert_pte_locked() use pte_offset_map_ro_nolock() mm: filemap: filemap_fault_recheck_pte_none() use pte_offset_map_ro_nolock() mm: khugepaged: __collapse_huge_page_swapin() use pte_offset_map_ro_nolock() arm: adjust_pte() use pte_offset_map_rw_nolock() mm: handle_pte_fault() use pte_offset_map_rw_nolock() mm: khugepaged: collapse_pte_mapped_thp() use pte_offset_map_rw_nolock() mm: copy_pte_range() use pte_offset_map_rw_nolock() mm: mremap: move_ptes() use pte_offset_map_rw_nolock() mm: page_vma_mapped_walk: map_pte() use pte_offset_map_rw_nolock() mm: userfaultfd: move_pages_pte() use pte_offset_map_rw_nolock() mm: multi-gen LRU: walk_pte_range() use pte_offset_map_rw_nolock() mm: pgtable: remove pte_offset_map_nolock() Documentation/mm/split_page_table_lock.rst | 6 ++- arch/arm/mm/fault-armv.c | 53 +++++++++------------- arch/powerpc/mm/pgtable.c | 2 +- include/linux/mm.h | 7 ++- mm/filemap.c | 4 +- mm/khugepaged.c | 24 +++++++--- mm/memory.c | 25 ++++++++-- mm/mremap.c | 11 ++++- mm/page_vma_mapped.c | 24 +++++++--- mm/pgtable-generic.c | 41 ++++++++++++++--- mm/userfaultfd.c | 15 ++++-- mm/vmscan.c | 9 +++- 12 files changed, 157 insertions(+), 64 deletions(-)