From patchwork Thu Aug 22 07:13:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13772818 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 A7294C3DA4A for ; Thu, 22 Aug 2024 07:13:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 377E36B0105; Thu, 22 Aug 2024 03:13:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 262CF6B0111; Thu, 22 Aug 2024 03:13:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0DDAC6B010B; Thu, 22 Aug 2024 03:13:55 -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 E4FC26B02A7 for ; Thu, 22 Aug 2024 03:13:54 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 999C61604D9 for ; Thu, 22 Aug 2024 07:13:54 +0000 (UTC) X-FDA: 82479016788.14.0A283C1 Received: from mail-ot1-f48.google.com (mail-ot1-f48.google.com [209.85.210.48]) by imf19.hostedemail.com (Postfix) with ESMTP id 3F8C81A0005 for ; Thu, 22 Aug 2024 07:13:50 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=MYc8M5gK; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf19.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.48 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724310773; a=rsa-sha256; cv=none; b=sN2rXx0l9gQVkKAm29B35r/JLIefIDtM0Ry3XnCAR5d7VQ7ISDcd7YOcF26m9DfaZbtXbI ojVUbASUqTg88raFjLReZ8gnYzU9GqG2ilzkWSGexSF8YUQ4QgRUdf7QT5kuoez/Q9J2qt vUXm5RLj3K3quyLCRexLvd023z1o63Y= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=MYc8M5gK; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf19.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.48 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=1724310773; 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=CFMLU37SF14i0z7/xzd4z7SOLQqMigYLuSMvL0jdhU0=; b=jU3ic7h4BJ5C0Yeicg0LMQAnXVCh0GNjmKYRA+jVnniG+xBo3IUskjB8c590o/6yzbmLIN vjHW99fnTRhSkK/Sghx5CcfAw+1IzvRXSfNjw6nBF09Kz7FG3Fap+fNApQoN6/blVhSMn+ MqGn3VoH7t0LUo3AH1Tie01L1rHSbzs= Received: by mail-ot1-f48.google.com with SMTP id 46e09a7af769-709346604a7so282914a34.1 for ; Thu, 22 Aug 2024 00:13:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1724310829; x=1724915629; 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=CFMLU37SF14i0z7/xzd4z7SOLQqMigYLuSMvL0jdhU0=; b=MYc8M5gKGvmPWLDeJMLBgOmLMXJE09trj54f+sW3ZUX9Ioobhw45ueMrjRTt9+PQC+ xwD33RSTUoOIwKQrO/Jxw0LzGU7zUIF2ui0NKuU5Qe/MnP8h4buh4hw6FzeAeG1gSgmU S05ZkGEylgTAlDMZM7CSdoD93FMGxYY7Q6kzNjQ4Ac3/kyU2Pr8Fj3iWFfc49wr7LbZz 8rphp2kagOAIrDVMvVjrk6+FBnzzccXN1cKMB4uKKxfpSwgdH1UsAdR6+eTGtl6QwuYS WV16Lm5AzSvAC7XxMxN/HMbIzxRqS8q0mOxXbFYv8rB50xLjA2Wqk6MJKf8y9Nw0KDlw 3ljQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724310829; x=1724915629; 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=CFMLU37SF14i0z7/xzd4z7SOLQqMigYLuSMvL0jdhU0=; b=O5gk4os+jNdeIwxg8nJPMBmKdEyYYomlGZIqx5dlt3L3D0muObrS9PUMRFvkOjMu9H NoLxqv29RLBYRmOAlVCITpiXeEmVDRvzQE+mJwNjBsXaIUEBPQu6xbXPi+9WMcxaGC3W jZjvM2AnnyUyYXMY5aoEiF4QCvF/+LFki+WsbnYmLIJTVF1nPk49HlP2iWktdyOLsMYM dBcg3fH2f558S+bTpKophbGHwZQoqQU56iGhkGhLu8ApClKd1dz8QKjv/PJdieQh1AR+ d5RGWmbEm93P+mBhTQ75Wht3aeTzYXB9oH7gNpGcWlFF03fS6FtcD8Tk8C3IZ1uBZRzo +FAQ== X-Forwarded-Encrypted: i=1; AJvYcCX340/C8oBfNCjFGSDcz7upUnams3idH+aoUPnEiygPadzE04VXLzs8hCoKoLkPONleerM/PUJYNQ==@kvack.org X-Gm-Message-State: AOJu0YzfjqUfr3v7c/B6C+e0Jtwfs6FRY9W1K9xmpCaQYKnre1FwZNMd zHBBZKViFYVTA8nrjP20STMeUe6xcF2ghjE4oqOQq9bX3OYJIHWqFVpHde58jCc= X-Google-Smtp-Source: AGHT+IHFVt0p20Eao8jGQp/M4A8gGxgTtYUk7Hnj/FFBLeb56GgWurcM0rgpuj3RCCjsswwc/siqyg== X-Received: by 2002:a05:6830:4386:b0:702:5a0:2f82 with SMTP id 46e09a7af769-70e043561e4mr1361943a34.0.1724310828958; Thu, 22 Aug 2024 00:13:48 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([240e:473:c90:f96:d029:ea8a:4e6d:d272]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7cd9ac994a3sm695095a12.16.2024.08.22.00.13.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Aug 2024 00:13:48 -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 v2 00/14] introduce pte_offset_map_{ro|rw}_nolock() Date: Thu, 22 Aug 2024 15:13:15 +0800 Message-Id: X-Mailer: git-send-email 2.24.3 (Apple Git-128) MIME-Version: 1.0 X-Rspamd-Queue-Id: 3F8C81A0005 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 59askmxqfe1e9feo5apb5zp9qkt8okyd X-HE-Tag: 1724310830-397031 X-HE-Meta: U2FsdGVkX19iDk9niwRxMj7OxDyRe4bHfdDhNPS0COKcVwZJkoaCVu+NWiQcLXdRn7wgsNXIjf2dbjODIFAkPNul+/D5FtBGckUrGjupurzk4QLOE/bsKvh/c6G+Pqb146dSzsH5dP75Ltw0qxyWD8BNXXrtH6DXAyFcR12eBzXRvwwuWC5TfGtuRw0aM2n5nDldS9WHCwl+XZZbSfJTsSTtDf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qx8K0UaUM+ARPBHY5eeqAh/jA48fEvYtxxTwNFi36kPnn7XCs7jv/69sbjKpMRGe8VU+Oe+yNOWPPLud9+ENUl6m4d4Asgx3iCwK2l0s/8U2aOVOdkouq9X6URDSjw270US4NGZDb6/yVUIXx1YeTC3ZVSkvqnZTmrCHqycn0qR86v2MdiAnBPt5rrR5Bc56z9xa+zWz4ta5ofiFtLAkcGI7x06nWo5IE 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 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. This can help the caller recheck *pmd once the PTL is taken. In some cases, that is, either the mmap_lock for write, or pte_same() check on contents, is also enough to ensure that the pmd entry is stable. But in order to prevent the interface from being abused, we choose to pass in a dummy local variable instead of NULL. 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-20240822. Comments and suggestions are welcome! Thanks, Qi [1]. https://lore.kernel.org/lkml/f79bbfc9-bb4c-4da4-9902-2e73817dd135@redhat.com/ Qi Zheng (14): mm: pgtable: introduce pte_offset_map_{ro|rw}_nolock() arm: adjust_pte() use pte_offset_map_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() 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() mm: khugepaged: retract_page_tables() use pte_offset_map_rw_nolock() Documentation/mm/split_page_table_lock.rst | 6 +++- arch/arm/mm/fault-armv.c | 9 ++++- arch/powerpc/mm/pgtable.c | 2 +- include/linux/mm.h | 7 ++-- mm/filemap.c | 4 +-- mm/khugepaged.c | 39 ++++++++++++++++++-- mm/memory.c | 23 ++++++++++-- mm/mremap.c | 9 ++++- mm/page_vma_mapped.c | 24 ++++++++++--- mm/pgtable-generic.c | 42 ++++++++++++++++------ mm/userfaultfd.c | 15 ++++++-- mm/vmscan.c | 9 ++++- 12 files changed, 157 insertions(+), 32 deletions(-)