Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp17121664rwd; Mon, 26 Jun 2023 21:25:15 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6GxjZgdCEfr+dH78ZCVshftkZAz4KJtDH914hr/ZfztlOr2hZU2sp+LO5GPoSr172SAzXk X-Received: by 2002:a17:902:d490:b0:1b6:88ba:db75 with SMTP id c16-20020a170902d49000b001b688badb75mr11960850plg.22.1687839915430; Mon, 26 Jun 2023 21:25:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687839915; cv=none; d=google.com; s=arc-20160816; b=N57l6SS1+oRhY31ZSLUNU3hd7Xw5wb/YbbAg6Snrr/HabxK84Dla/XxmjJwmbnX6Wz mU2ha9ckHCHEjuNJWNkX6QqxO+QBSRlGl5Fqg1b0fLJiu6KZBiLZvjWa1+vOUCZo4q1y VsfzdjeEscD4HBqdl6RNuYApFF7AbGxMWsED9bB6vKO2t+2QVZtGtdvJ9KQEj+glMqLT fS3Nd4Kt/bIc3IpaaLp8rnC1ll+kVOG4ZP7f8XVtCs1LY0T+epzFTOp+GrICoEgpsNji UE4NOidrnwEs30lemqssRu/etopOpRfdh6D8g6HfFOWAdQcnkQD3csKk6xtvoblUL5HR NADw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=JWV/DPfsr/X1EdWkyMfUvUzcNXJIr36UfbN56sh3Nho=; fh=RMSYO7NH5mgRq+Q9Sd8uvtKjjFjspH3ZqZT6M3GUwas=; b=j0Mq2qrxNWd4lErp70vpx7vPF7fGF+/rMjP6EOiClmVcWUgBg3dmZv6SiDBSA3IU+l 9R7t7/VTA+awuK5G8+80Omr0V5EnbJO0ksT5Ck6pLmzrEEa+mpmM3n03QxyCH6uDgR+b JrsnZkatp9+A1h9Rg73RxcqIWC366jGcr4oqel8hDSYT0t45tMjwoFXiceVBCwzDh0XR NBkqHjpgnNjhD4aBLrayNf2ZlldjIUNHNC6XIMVNbiAF1R9Fk3FPF/40PBVPDjU1gjvJ TGBoI5Jc6q5pykdfXtB0FAX1lDjvPSYAj7zVAiPAGWm03ca66LT9PcbqupXtksu2kF1F 7LnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=x2iMPg4X; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d7-20020a170902cec700b001b392bf919bsi6661832plg.407.2023.06.26.21.25.02; Mon, 26 Jun 2023 21:25:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=x2iMPg4X; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230075AbjF0EX3 (ORCPT + 99 others); Tue, 27 Jun 2023 00:23:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229738AbjF0EX1 (ORCPT ); Tue, 27 Jun 2023 00:23:27 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8EDD610FE for ; Mon, 26 Jun 2023 21:23:25 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-bfee66a6398so4140730276.3 for ; Mon, 26 Jun 2023 21:23:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1687839805; x=1690431805; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=JWV/DPfsr/X1EdWkyMfUvUzcNXJIr36UfbN56sh3Nho=; b=x2iMPg4XRNf8vHFsb9oj4O2ZELGqekijMqu5JGOH1XL1vViWwwWC9MBkqH9HHe4btJ c19XM2XqaHIdWyVgEShFN+FKhTNvVvVMcM9KPGdA2PpIKlKOFfjWIxX/FTRQ+Egzz2Xk iDOHnC+luY1cdNvUBatfG4vVVioTEVkMxkAuGqGmuEGGYxJfP+4hqSMSdMsuJhdGFwBo ha0yY/DE1KDekc0YbbEhrbK/ZfuDdaU+y21gTEGJNm3OiwsK0/m5w1uhZ73NmyB1jFRp VEn2awGEL5+iVwgxI+McDtpysZ6sRcaia6mf8ZdScFiYwaVc51h/mR4Ayui/LnJG+dff b0iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687839805; x=1690431805; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=JWV/DPfsr/X1EdWkyMfUvUzcNXJIr36UfbN56sh3Nho=; b=lpKQ8l6Sf7uZw+we1j1f4navqk4JJ43Sgbifj00mbqo6IpQvetkrhM1ER+L6im6lAF ajl0BhhoZhG9uk0Zp/szmU+PmpiBncMGxoQTiq6DzKP5x1XQ/sT+N9cT4iCj74P0bCMB B/gnezjjTLrt2ha/tn2JZdTENQvZxUtPDnf2OWF4+nsdCtBh20+tjEdvBKchLqE1dF+r zBmPSxcuXLD0yW1C++S0eCVsEKLtYiGYcQfxSUzYqePrXjJlGkh9XOiWmRQOxC5JB65S 461B//+LGdpCxXmCMANSOat0l+4IapdqgcC5JRq6+haeSPfxEPqi4cPADj1PdCMjjdEl X3Rw== X-Gm-Message-State: AC+VfDyGM9W5c4xGObAptK9xljMBUFwIEz2RLELPHhnmnt5UDGs971DT 6wBg0w6TPMf91cGrNUNYgsk5hCA38WI= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:5075:f38d:ce2f:eb1b]) (user=surenb job=sendgmr) by 2002:a5b:ccd:0:b0:bd1:7934:b4fe with SMTP id e13-20020a5b0ccd000000b00bd17934b4femr13504050ybr.13.1687839804822; Mon, 26 Jun 2023 21:23:24 -0700 (PDT) Date: Mon, 26 Jun 2023 21:23:13 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog Message-ID: <20230627042321.1763765-1-surenb@google.com> Subject: [PATCH v3 0/8] Per-VMA lock support for swap and userfaults From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: willy@infradead.org, hannes@cmpxchg.org, mhocko@suse.com, josef@toxicpanda.com, jack@suse.cz, ldufour@linux.ibm.com, laurent.dufour@fr.ibm.com, michel@lespinasse.org, liam.howlett@oracle.com, jglisse@google.com, vbabka@suse.cz, minchan@google.com, dave@stgolabs.net, punit.agrawal@bytedance.com, lstoakes@gmail.com, hdanton@sina.com, apopple@nvidia.com, peterx@redhat.com, ying.huang@intel.com, david@redhat.com, yuzhao@google.com, dhowells@redhat.com, hughd@google.com, viro@zeniv.linux.org.uk, brauner@kernel.org, pasha.tatashin@soleen.com, surenb@google.com, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@android.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When per-VMA locks were introduced in [1] several types of page faults would still fall back to mmap_lock to keep the patchset simple. Among them are swap and userfault pages. The main reason for skipping those cases was the fact that mmap_lock could be dropped while handling these faults and that required additional logic to be implemented. Implement the mechanism to allow per-VMA locks to be dropped for these cases. First, change handle_mm_fault to drop per-VMA locks when returning VM_FAULT_RETRY or VM_FAULT_COMPLETED to be consistent with the way mmap_lock is handled. Then change folio_lock_or_retry (and rename it to folio_lock_fault) to accept vm_fault, which will be used to indicate mmap_lock/per-VMA lock's state upon exit. Finally allow swap and uffd page faults to be handled under per-VMA locks by dropping per-VMA locks when waiting for a folio, the same way it's done under mmap_lock. Naturally, once VMA lock is dropped that VMA should be assumed unstable and can't be used. Changes since v2 posted at [2] - Moved prerequisite patches to the beginning (first 2 patches) - Added a new patch 3/8 to make per-VMA locks consistent with mmap_locks by dropping it on VM_FAULT_RETRY or VM_FAULT_COMPLETED. - Implemented folio_lock_fault in 4/8, per Matthew Wilcox - Replaced VM_FAULT_VMA_UNLOCKED with FAULT_FLAG_LOCK_DROPPED vmf_flag in 5/8. - Merged swap page fault handling patch with the one implementing wait for a folio into 6/8, per Peter Xu Note: patch 3/8 will cause a trivial merge conflict in arch/arm64/mm/fault.c when applied over mm-unstable branch due to a patch from ARM64 tree [3] which is missing in mm-unstable. [1] https://lore.kernel.org/all/20230227173632.3292573-1-surenb@google.com/ [2] https://lore.kernel.org/all/20230609005158.2421285-1-surenb@google.com/ [3] https://lore.kernel.org/all/20230524131305.2808-1-jszhang@kernel.org/ Suren Baghdasaryan (8): swap: remove remnants of polling from read_swap_cache_async mm: add missing VM_FAULT_RESULT_TRACE name for VM_FAULT_COMPLETED mm: drop per-VMA lock in handle_mm_fault if retrying or when finished mm: replace folio_lock_or_retry with folio_lock_fault mm: make folio_lock_fault indicate the state of mmap_lock upon return mm: handle swap page faults under per-VMA lock mm: drop VMA lock before waiting for migration mm: handle userfaults under VMA lock arch/arm64/mm/fault.c | 3 +- arch/powerpc/mm/fault.c | 3 +- arch/s390/mm/fault.c | 3 +- arch/x86/mm/fault.c | 3 +- fs/userfaultfd.c | 42 +++++++++++++------------ include/linux/mm_types.h | 4 ++- include/linux/pagemap.h | 13 ++++---- mm/filemap.c | 55 +++++++++++++++++++-------------- mm/madvise.c | 4 +-- mm/memory.c | 66 +++++++++++++++++++++++++--------------- mm/swap.h | 1 - mm/swap_state.c | 12 +++----- 12 files changed, 120 insertions(+), 89 deletions(-) -- 2.41.0.178.g377b9f9a00-goog