From patchwork Fri Jun 30 21:19:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13298782 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 3F835EB64DA for ; Fri, 30 Jun 2023 21:20:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 52EA68E004B; Fri, 30 Jun 2023 17:20:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4DED58E000F; Fri, 30 Jun 2023 17:20:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3A6478E004B; Fri, 30 Jun 2023 17:20:04 -0400 (EDT) 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 278858E000F for ; Fri, 30 Jun 2023 17:20:04 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id EB9BDC0A08 for ; Fri, 30 Jun 2023 21:20:03 +0000 (UTC) X-FDA: 80960681886.30.18ADAEB Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf10.hostedemail.com (Postfix) with ESMTP id 3682BC0019 for ; Fri, 30 Jun 2023 21:20:01 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=oNIgkcP+; spf=pass (imf10.hostedemail.com: domain of 3AUefZAYKCDgmolYhVaiiafY.Wigfchor-ggepUWe.ila@flex--surenb.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3AUefZAYKCDgmolYhVaiiafY.Wigfchor-ggepUWe.ila@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1688160002; 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-type:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=H9gcN3gNFu1WTtBUtpC0M4aYh2b9oslK18bWcyLDHdo=; b=vUTvacZHZe42f5kdsplGDTOLTfstBJaGWT37NpA+gl7dhaa3fIBAa668vINihob6d7UkNP 7T+6Kl6oHyo4OhH2JVTpcrS884XKv4xHWV6r1rHXNMugIbwIbp+dpNs6DFKfp8+GKyqA2b 7UYDWLArVNu0crHbobzUpKngRhd1Hh4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1688160002; a=rsa-sha256; cv=none; b=e5SSDqyWupv+PANyF9aSy3BHJZKb2rsjOLCp+a7fuS5VOSqWS+T+LUVa4I32r9ejhavbLc VSgTYw18UyD2LUtdItN/QOrIJKHlJqkbalMhniPdoIjZR48isYM80TJ8VgmciRz1QGG6bd Czzi5l2EP7Ec9priHA1AghTrYQkjkR8= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=oNIgkcP+; spf=pass (imf10.hostedemail.com: domain of 3AUefZAYKCDgmolYhVaiiafY.Wigfchor-ggepUWe.ila@flex--surenb.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3AUefZAYKCDgmolYhVaiiafY.Wigfchor-ggepUWe.ila@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-56ff7b4feefso23052877b3.0 for ; Fri, 30 Jun 2023 14:20:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1688160001; x=1690752001; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=H9gcN3gNFu1WTtBUtpC0M4aYh2b9oslK18bWcyLDHdo=; b=oNIgkcP+Rm1zkUVn4t5u68ESvpgQIXbrcYw29/gRzdkE5UaATbVPes4z0XxKc6K6/p Jw15ZeO2phUHjjdXkz/Fm6vKj6Kxg45Foww+zGK4uOAGQqqs1BrsHBYIMr41Xjj7veyP /7nxOF0o6KW7tDm6OUT6bmkpjra0/KYvwtRBjY/lE/5NTj9I0EuMyZRtDufv8j+YeJo4 BurycZxKQ3Kva49nwAun+2C6w+cBong6Laauu/NCOZuov5J3VnHB+mmdeOgOOJr4/dpD PbfVskXqe6CffLh9wmpPLX7R5GUurnXto1SNVVdCYTODhlgKHpIMPgLptoHhfPs82CSh M/NQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688160001; x=1690752001; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=H9gcN3gNFu1WTtBUtpC0M4aYh2b9oslK18bWcyLDHdo=; b=VuT5ka/nvfkiLKLBVyJh8gwznuhSDBO7rNzyyzv+Y30O0EnJfjO1C6yRx2bq9RzA26 KeQtuyzB8FuEOfdEAVwj3O9XnvquwyR5JE1FTH1O6L42ihKJ70cGXcbOBku2NEubECAo 5EloL32HtP499XrzQodcn+vLoXWlr/uIrfX7L0W0GguaziycTy4jfUXwwk0neYFdKDXS ZxKDz4aMeynDJXw6JXaSjQcX0k02lewr8gsnsJn/XLmY+53qcV/dKbVesuQ/TfZFoEKt +bylbLfsM6F5CEy1a4o+PNTB5aw52VedBBM7x6I1YCPaPM0EqIii9ZgGESw6UlMPMlmO tcxQ== X-Gm-Message-State: ABy/qLbM9TVduNpx1lI1j3DJp0PmtYW0LN+gEWNhdnjjeAgvNrK0yk0B gNoQ1CPe5J03kqlhaGXE1sidMCgB1DI= X-Google-Smtp-Source: APBJJlFxz+5qjMtbjV4jvSAgVZ7fFk8uY3skGFQMChHy9vo8oYp4UdiT1As/B8NsDi05V0mv39s2UQ7kX1g= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:b54c:4d64:f00a:1b67]) (user=surenb job=sendgmr) by 2002:a81:bd01:0:b0:56c:e585:8b17 with SMTP id b1-20020a81bd01000000b0056ce5858b17mr27432ywi.5.1688160001126; Fri, 30 Jun 2023 14:20:01 -0700 (PDT) Date: Fri, 30 Jun 2023 14:19:51 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog Message-ID: <20230630211957.1341547-1-surenb@google.com> Subject: [PATCH v7 0/6] 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 X-Stat-Signature: raof36mdipbbdy1jr19318yixhtad44g X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 3682BC0019 X-Rspam-User: X-HE-Tag: 1688160001-604287 X-HE-Meta: U2FsdGVkX19C/QD/CeZmMWm1P2ITawYzMIqCSWiQ3QUk8mm0GaUxpVmmhH08An6AiQX64TuZJDt/TyEe7kKYVPo77ieTf1mkwSIfEmj8M06K5tKlKSEtXw07o9jULK28sbsNjhfd0+T0dz2IfZaENSMnxQ9tZfdqMJNIlKRH+Mjj6OloezhSv5RPn8C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i0G5yUfu/w6gw198+ueq6yrftr+NiHJpMJxUkFu681idJh94MQZ+2dQUKrXsZgIdigT5EfNUe5i90gIFIC+LJjFrW77H0iFIpmMynGcIZlhWMzJwzmvyX2Wt6jczNMBZFO34cpGMfZGOir0brzpD4OAQ/Cs7KDHSw62ihzq5M3Izd0HXKuG6NTVXqbHy5WSGaWEFWkpulKBp+7/gPVcqILGiNhjF4sR1galuvbXXSz2ObylBqBLuDXVb/cgMXO/1kXsDrGrAccy83Ann74MRdmtwtQzmgpN80WH8FU+OYJK77H687C++3zxft73J1WEpbBabUPTfcuAZXBPI6jyq64A/hU10YxEt30zURQOigtK5Y39HuxkRBjVCuVaFCiA X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 to accept vm_fault and return vm_fault_t which simplifies later patches. Finally allow swap and uffd page faults to be handled under per-VMA locks by dropping per-VMA and retrying, 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 v6 posted at [2] - 4/6 replaced the ternary operation in folio_lock_or_retry, per Matthew Wilcox - 4/6 changed return code description for __folio_lock_or_retry per Matthew Wilcox Note: patch 3/6 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/20230630020436.1066016-1-surenb@google.com/ [3] https://lore.kernel.org/all/20230524131305.2808-1-jszhang@kernel.org/ Suren Baghdasaryan (6): 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 when returning VM_FAULT_RETRY or VM_FAULT_COMPLETED mm: change folio_lock_or_retry to use vm_fault directly mm: handle swap page faults under per-VMA lock 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 | 34 ++++++++++++---------------- include/linux/mm.h | 37 ++++++++++++++++++++++++++++++ include/linux/mm_types.h | 3 ++- include/linux/pagemap.h | 11 +++++---- mm/filemap.c | 37 +++++++++++++++--------------- mm/madvise.c | 4 ++-- mm/memory.c | 49 ++++++++++++++++++++++------------------ mm/swap.h | 1 - mm/swap_state.c | 12 ++++------ 13 files changed, 120 insertions(+), 80 deletions(-)