From patchwork Fri Jun 30 21:19:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13298783 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 67C8AEB64DC for ; Fri, 30 Jun 2023 21:20:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DE15B8E004C; Fri, 30 Jun 2023 17:20:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D91548E000F; Fri, 30 Jun 2023 17:20:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C80958E004C; Fri, 30 Jun 2023 17:20:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id BA6C28E000F for ; Fri, 30 Jun 2023 17:20:06 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 68C3F80E56 for ; Fri, 30 Jun 2023 21:20:06 +0000 (UTC) X-FDA: 80960682012.12.BBDCB13 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf09.hostedemail.com (Postfix) with ESMTP id 9DDF114000F for ; Fri, 30 Jun 2023 21:20:04 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=gj3Eoj1y; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf09.hostedemail.com: domain of 3A0efZAYKCDooqnajXckkcha.Ykihejqt-iigrWYg.knc@flex--surenb.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3A0efZAYKCDooqnajXckkcha.Ykihejqt-iigrWYg.knc@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1688160004; 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:in-reply-to:references:references:dkim-signature; bh=T+U3NPNy+xyAlbM+feS8QAyMObapdpoy5/9PcF9TKLI=; b=UQ0wn+YPy2zVi0MioStiKOwbbT2xzYVkxWHtzmfBneqrYq182Bmu+Fcp5TdcSrfE+TPfhb I6PagJeeh93MzI1VBAqNvNhuyMSepEeR9tu2yeLmlDvbU1n/QaVA1y4NWXpWZBBki1H9x8 2qCoSa9vmFFtGi9bIw0ljbm95PnMUKU= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=gj3Eoj1y; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf09.hostedemail.com: domain of 3A0efZAYKCDooqnajXckkcha.Ykihejqt-iigrWYg.knc@flex--surenb.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3A0efZAYKCDooqnajXckkcha.Ykihejqt-iigrWYg.knc@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1688160004; a=rsa-sha256; cv=none; b=49kuLc1lag1kiXjmwwl6OUnzOmhYjyhR2PakZX2To41IJRjBtn8nw87UYCNAnZfYgZugxd 3LTdf2dpJ2Q7Cm0HnmkvcdXbt/suaIrnDczEvgSLDCgtus8EbwvrnSEUDU+0fwXWA9i4qb p9MUfula1A2UuEL9tcRmtGrRsUEA6Q4= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-573d70da2dcso22630137b3.1 for ; Fri, 30 Jun 2023 14:20:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1688160004; x=1690752004; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=T+U3NPNy+xyAlbM+feS8QAyMObapdpoy5/9PcF9TKLI=; b=gj3Eoj1ySBPw7PRJkS7EMLlo2pHw7Fy4fqTaMfYLzfs8i//BzYVVgxavozWht9eYa3 9QAis0pBfrH9H8O+BTK2P79HmbSy+ccpBICKn8dunthp5sDi7iBpTMHFffkiZCrb/4pR En+6nDy6jwP37RQrIPo3q7g/52V2l2w5AufZPHDuq4ZHdGhSDNnMavuXRPZVKntKOTDi uiJ3U638bAeT24PExrpL+ltCWuRdoPULemr1kCD8+I4EoR2xOlnV2Nf8827lutjv9zcq lKwsFdM6xI6ZVtuw93zeDjoRoNdTpjbnxRcchetindVZNkpIckBFK5QbU6hmmDd25SjA DVkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688160004; x=1690752004; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=T+U3NPNy+xyAlbM+feS8QAyMObapdpoy5/9PcF9TKLI=; b=feMwKObbL7Bq5hZAudOUptzE7jqQ5+KxUi7NklIEsXnZbmEL0T17zxDww+XdNs5aoH ZTTmOfDwYQhNQ5CCiSUXel95WOYsfGDggtvSfnnj803lPXE5RCE2PUQjmUeFLy9HxiFV 7U+jUMATp2RMrL7YuTLVwwyOZeq1nQhydHCpOFizglsjDUToN8lEBR+01zIZBmtUAxyJ cCwgV2VsCDc4TSJ1aNFU7P1hIMUCcfUIYsT4G7PdfaW1kQSwbp7r/NWYp8gXh/1owI3X +0TM9HCNP21GJzVDkMzZHMEQzAG8fOzQkJdMBP9CIG52il9ydnWVA91KKEQWPao0Tofb Bk5A== X-Gm-Message-State: ABy/qLY8DuNHmnuWHLG/BtpR9zIfLf0uHWkHjtiGuD8QB8xPye5eOKVR j2OR25j0YbwNh03UfmriVUCIeQF6wrY= X-Google-Smtp-Source: APBJJlHm1PS8GELal/xG6N1RB/HDwu0xhxZBZ/b8TRPUqLWRpiaRfbIuTnZTA+ooMa+BPx0Ft/eRiuXr8FU= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:b54c:4d64:f00a:1b67]) (user=surenb job=sendgmr) by 2002:a25:2cb:0:b0:c43:b4b6:dde8 with SMTP id 194-20020a2502cb000000b00c43b4b6dde8mr17502ybc.8.1688160003659; Fri, 30 Jun 2023 14:20:03 -0700 (PDT) Date: Fri, 30 Jun 2023 14:19:52 -0700 In-Reply-To: <20230630211957.1341547-1-surenb@google.com> Mime-Version: 1.0 References: <20230630211957.1341547-1-surenb@google.com> X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog Message-ID: <20230630211957.1341547-2-surenb@google.com> Subject: [PATCH v7 1/6] swap: remove remnants of polling from read_swap_cache_async 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, Christoph Hellwig X-Rspamd-Queue-Id: 9DDF114000F X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: mijc67pnwpmojcnbhkcz1skcarmdq1hh X-HE-Tag: 1688160004-478021 X-HE-Meta: U2FsdGVkX18qMQOkZ7pU/RnGcyDLHkhJHhQVeQhp9gbxGk+ATB4CvcmcLjOc6FGDoQkHFHVG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SPZyFtjmOwpjxb6MG/5g0squNBTn8R5mdtWnxtYp59+PPh2ceBFbG0hHX1WisH6IJuHJc2spWgQ/00hy5V6ve72uFva4dMvnmUgk46NJkm26T4JzIUknD9foIOCcEj9/BUkcIsFIOxMhL7onmCqkg4jz2LTOitDrTxSUiY0c3GTrgbvuEBoOW7NpBG0lIqJDy2ud5nNjTmTyHR/r2jqGJsPf+BL495ZgI4hP1dzVXUDF8cPLCL/QcNdAWHOIJtXwEg/x93PRsXtmBhZyQoFYO4Lt0M8WUb0COtShvus3JWgvi9N0PAquo4No8Ju0O/ZoTw1dvtk3VqKC//bGKAYksqdpRwwA65JCJnoUnDz0H6eYVTg15pNPzvf0Oel76T2MqoUT+Nu1uzMoXY7AhEG3qEMrXU/aL1Qw6qChuidFnqXFj/jgLWabEeTamzyXTEoHN+LVs26P+QOOExLhSXYH/z8BKSrJ2nUFifGEW73tharzZBxX3SbMAn6h1uKE9P2AvLaQuTiAWiJDPqFpFZor+cR1u8g== 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: Commit [1] introduced IO polling support duding swapin to reduce swap read latency for block devices that can be polled. However later commit [2] removed polling support. Therefore it seems safe to remove do_poll parameter in read_swap_cache_async and always call swap_readpage with synchronous=false waiting for IO completion in folio_lock_or_retry. [1] commit 23955622ff8d ("swap: add block io poll in swapin path") [2] commit 9650b453a3d4 ("block: ignore RWF_HIPRI hint for sync dio") Suggested-by: "Huang, Ying" Signed-off-by: Suren Baghdasaryan Reviewed-by: "Huang, Ying" Reviewed-by: Christoph Hellwig --- mm/madvise.c | 4 ++-- mm/swap.h | 1 - mm/swap_state.c | 12 +++++------- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/mm/madvise.c b/mm/madvise.c index 886f06066622..ac6d92f74f6d 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -218,7 +218,7 @@ static int swapin_walk_pmd_entry(pmd_t *pmd, unsigned long start, ptep = NULL; page = read_swap_cache_async(entry, GFP_HIGHUSER_MOVABLE, - vma, addr, false, &splug); + vma, addr, &splug); if (page) put_page(page); } @@ -262,7 +262,7 @@ static void shmem_swapin_range(struct vm_area_struct *vma, rcu_read_unlock(); page = read_swap_cache_async(entry, mapping_gfp_mask(mapping), - vma, addr, false, &splug); + vma, addr, &splug); if (page) put_page(page); diff --git a/mm/swap.h b/mm/swap.h index 7c033d793f15..8a3c7a0ace4f 100644 --- a/mm/swap.h +++ b/mm/swap.h @@ -46,7 +46,6 @@ struct folio *filemap_get_incore_folio(struct address_space *mapping, struct page *read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask, struct vm_area_struct *vma, unsigned long addr, - bool do_poll, struct swap_iocb **plug); struct page *__read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask, struct vm_area_struct *vma, diff --git a/mm/swap_state.c b/mm/swap_state.c index f8ea7015bad4..5a690c79cc13 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -527,15 +527,14 @@ struct page *__read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask, */ struct page *read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask, struct vm_area_struct *vma, - unsigned long addr, bool do_poll, - struct swap_iocb **plug) + unsigned long addr, struct swap_iocb **plug) { bool page_was_allocated; struct page *retpage = __read_swap_cache_async(entry, gfp_mask, vma, addr, &page_was_allocated); if (page_was_allocated) - swap_readpage(retpage, do_poll, plug); + swap_readpage(retpage, false, plug); return retpage; } @@ -630,7 +629,7 @@ struct page *swap_cluster_readahead(swp_entry_t entry, gfp_t gfp_mask, struct swap_info_struct *si = swp_swap_info(entry); struct blk_plug plug; struct swap_iocb *splug = NULL; - bool do_poll = true, page_allocated; + bool page_allocated; struct vm_area_struct *vma = vmf->vma; unsigned long addr = vmf->address; @@ -638,7 +637,6 @@ struct page *swap_cluster_readahead(swp_entry_t entry, gfp_t gfp_mask, if (!mask) goto skip; - do_poll = false; /* Read a page_cluster sized and aligned cluster around offset. */ start_offset = offset & ~mask; end_offset = offset | mask; @@ -670,7 +668,7 @@ struct page *swap_cluster_readahead(swp_entry_t entry, gfp_t gfp_mask, lru_add_drain(); /* Push any new pages onto the LRU now */ skip: /* The page was likely read above, so no need for plugging here */ - return read_swap_cache_async(entry, gfp_mask, vma, addr, do_poll, NULL); + return read_swap_cache_async(entry, gfp_mask, vma, addr, NULL); } int init_swap_address_space(unsigned int type, unsigned long nr_pages) @@ -838,7 +836,7 @@ static struct page *swap_vma_readahead(swp_entry_t fentry, gfp_t gfp_mask, skip: /* The page was likely read above, so no need for plugging here */ return read_swap_cache_async(fentry, gfp_mask, vma, vmf->address, - ra_info.win == 1, NULL); + NULL); } /** From patchwork Fri Jun 30 21:19:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13298784 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 6E2BAEB64DA for ; Fri, 30 Jun 2023 21:20:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E58778E004D; Fri, 30 Jun 2023 17:20:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D27958E000F; Fri, 30 Jun 2023 17:20:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BC22B8E004D; Fri, 30 Jun 2023 17:20:08 -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 AE08C8E000F for ; Fri, 30 Jun 2023 17:20:08 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 8130740DED for ; Fri, 30 Jun 2023 21:20:08 +0000 (UTC) X-FDA: 80960682096.24.A0B5016 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf30.hostedemail.com (Postfix) with ESMTP id AF34A8000A for ; Fri, 30 Jun 2023 21:20:06 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=CmiBSAVO; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf30.hostedemail.com: domain of 3BUefZAYKCDwqspclZemmejc.amkjglsv-kkitYai.mpe@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3BUefZAYKCDwqspclZemmejc.amkjglsv-kkitYai.mpe@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1688160006; a=rsa-sha256; cv=none; b=D3/zGR5FZfFcWkro38orGuotMIKgVH9hLI3rRPTFSu5cGqg0izDcjGyFhJ8h1nOuRxQFMj X7nN46gMP14bbTbZKIWnpTf3rubUG2rGWdt2VX6LqcT0fqcEeCtGckdt2FT8anVoCXwo/L wHXhqsfuTJi0dIjHjx6TMSHMGzEXxeY= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=CmiBSAVO; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf30.hostedemail.com: domain of 3BUefZAYKCDwqspclZemmejc.amkjglsv-kkitYai.mpe@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3BUefZAYKCDwqspclZemmejc.amkjglsv-kkitYai.mpe@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1688160006; 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:in-reply-to:references:references:dkim-signature; bh=wxpT0wtXiDyXAkq9m4Ft7pVFAXex2TsyXSa3a6xpvEY=; b=k2C1warLPIejf53iOoDC3zWQJLcRs8BTYBOqADLM1+Gl1HGObhdsyBQzOzYyyX+R3HEAKV OkAVZK8uGQuEB7QNKX74zMpTv6+BwifIMFvq4u3UBzaYFKbCjFLwysxoBaqokvd+a/cRPV plLEFJJS1v28J0l9b09Rb9hzIDkOYIM= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-56942442eb0so23260757b3.1 for ; Fri, 30 Jun 2023 14:20:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1688160005; x=1690752005; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=wxpT0wtXiDyXAkq9m4Ft7pVFAXex2TsyXSa3a6xpvEY=; b=CmiBSAVOd2SJ9KkajKb82g1sbktJiFYJzW5mhwIbhohJMYg+6NliTNYNRvGr7qH9J3 DZo+DChiKr23yUB7iM6WjoSuQzJ60wZzKLuuQC3mPPiMY/9zG+OpIZguJ/pnwtM1HRR0 jBN8ksj8AloU+LK/FwdRLkImKs42oA6n1CCvxR0nsaaBTrAKU+TX0aGyoCQJSV1nSteg QfJaV+ROJPuT8NGWeSCLb3CVxDPCwNixwjO7DkBpmWVUjULNQteVd1/J2ReFt69J8GlU 8FBGmlqRK/+OBL1joScBwgOrtRwZ7y3x0w5Ya6f3GZ8X35wlWUNahWE+vUb7f9HVQmrH GL/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688160005; x=1690752005; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=wxpT0wtXiDyXAkq9m4Ft7pVFAXex2TsyXSa3a6xpvEY=; b=JKNMYkxoBgsmJaU8wn0AA61gh1LJ0S+R75AnD2erXiYw+5iA+/sE72SdjVyEG6EORE DQ54Mwqis/hoU6ZPcr54ApK25rvFJ83X7rxYyOBUCwzqSQgMEG9BVr4ghPw6JefwtXLY TRHPuinBDSmN3NlCq6Fg2KQ1dILiMgRnvgjKGQCgNuP3Ugs14kMVRfaHmFd6Nsw5oL8U /SzNzjBk5aIPlFKsIScBDJ6Nh71SJHU+EAzbmAB4nILtN3eKKixs++WkYay1OhG1Y+xh fVSR5kgVPHO39RodddMp6BQ2HtQlNH2Hb0F/F1RSfKogA7+O/5xNGUByskwc+R16xdFl rAFw== X-Gm-Message-State: ABy/qLaS8fUrSRDQNHDwSRx3pZ3oOK7vPP5M6MW0llAB4RAhd58i4wCC jvb/9+2h4AFnHJansunD9XbbbPq+Ybs= X-Google-Smtp-Source: APBJJlF5ztBBwyWteO2XW01iQph/9sOhVVQ5xerSWUbLHw3eJriy3uuhavoxZfleLDq4B516ZDfLMavujZQ= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:b54c:4d64:f00a:1b67]) (user=surenb job=sendgmr) by 2002:a0d:d890:0:b0:565:9bf1:f6b with SMTP id a138-20020a0dd890000000b005659bf10f6bmr29618ywe.8.1688160005788; Fri, 30 Jun 2023 14:20:05 -0700 (PDT) Date: Fri, 30 Jun 2023 14:19:53 -0700 In-Reply-To: <20230630211957.1341547-1-surenb@google.com> Mime-Version: 1.0 References: <20230630211957.1341547-1-surenb@google.com> X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog Message-ID: <20230630211957.1341547-3-surenb@google.com> Subject: [PATCH v7 2/6] mm: add missing VM_FAULT_RESULT_TRACE name for VM_FAULT_COMPLETED 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-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: AF34A8000A X-Stat-Signature: ajtordiwibz9d41i9ttkn7bs6j18tnnd X-HE-Tag: 1688160006-422176 X-HE-Meta: U2FsdGVkX1+q4+mViy02kTuFwj18g8airp2ZTrOoSsx6u4n9wmwtdJjuq/UndyiScNewQHXWuxfOgOMnWeoUyTn2ndK9/3UIh8wSJsi28N9Jo16i5cECn0Xq4LT/PLTvn1AQfoonqExVJG0Vl/QxkNe5ZFjKj7O+FA26T5h+HsAJT7rfpzc6e7ycRV3LDWNyZPLpsv6DM5HcQMuGnFJpZPcae7O2NYi9RSMLvJJvrxSxH7mO3FWOCuPOsxyn4My+n+GQ1BjU65+oTfxxSBEZi0VZZTcwMitLcQNMH3dcsgvfYOhoycCmxIlofOBvvtpXF913EGLG2VEBDxMAT5DSS3W5WjBUp6KlACmJhdqshnSHzldzhjEAi1qwzI2nd38z4x8NPUxvM1FU6RXBos2snTc1Jv/clyJb0RuDgA4pWpLkrClnyaCaYiUSn2cZwWp2rRa7umLu8YBjLxr5Qk+MjKs0f3v0uwTEUEogrx6/T0e2E82Cs051tDThyOLiq+X0aHn4iZ5wwVwDIpMVRFUc+RcVmdeXv8+OUyqEV79WNvwLrxax503/l5Mh6x/rOS2Tn/2co3M2pK1VQlL/Nbe8Q0QVgwlvvsPxOum50qtXOeHkGsQuCHiFWAlspnxnh5wyaEo3yktVxStBV55AG50xzTPsCBo26f/vxFAMSU121G7gxgf+XNZLpRZleh6mY8KfYCwJottk+KWuuRW4ES4xQwNAy768TxCKZhkPVEJe3m628o1oV7NkkeD2tlhIXE82WAjViI0UjoNDj4iPJjhmaOrfh2GPALTfTkwl8In1t45RKWJKOU7+wgb7OvMMgsrtLio8mP8uiliye8CRC7Rk3Y1GWg29SPPvCKoBO9asjoKQUs0tAwUkF8SgL+i8XFYV5cbneJduCMFxtd5rNJ5nh0APmPyYZIrKrZVQ2+z7ZL38XsOUHb6/ew+c8Bcaf+tOo5u0abIwg9W7BDo/JfL FaYoqqMH /53syVLPXFKRKbnR9VWkcbAMGrn9RM336hcn6L6scZpqiaROyI+lq8VodkT49zcZnJaRekm81H/8/G1jt2tMHxBIqdAreV66PemhPPCGqvmJiP5rChL9doa7fOoWnMVhhJLLiTAMYtMV7E/MmVxkS6MWj7G8bAbBCi/Z2XLFXb68rXSyeL1aJyO/oA2S61sjxg8Zwk6tVBjUZDG5H2XoaS2YgGBFC0B0p9wLtjvJGO3mJJ8BPBe7GGAq6++lVe2ETIb4dvFlQ1fBaDwofHdsCQCHmCGQy/ZbuZF22UozS9Sj8w6BXqkWHjv0GFXSiBk7bMohnOtjtV5Rlaa82SUBtGvSHkkRbnYVK3nFjt44mhXErhQjjb0RdHEkb8rBQE1QlxrmcJTCJ/Fo41ZC+d5c8u2txFrQ3FCDirkASwAk5l3L/Rwrhdr3ZRjvJwmOXw/7iBPtx36X+oPIuwJjq6Anv+QdfDq7yJ35cioDOuOcESqstuzka1X22o1WjhMaWws0U0LdMvLTj0hrFyNu0mharcMCOm3uizeK7pcjz3V/n6f6MEnqB3oCHh0TEnKrFjhmEe0hsymuxEa8oKAOot7dtoEUH6z41tTS5NEnUpwKrZRc1GuTUxR72p+AVPjRNFCaiF2B/8xevcXcZlJuxraSIfn+gLa10HLdldcSbGlUc3Akimr2SCfTgUn+fWHzwd+pPmz7iAIu4ed8GEHluXL+PBxabq4HDKhnin9gBZvNUT4d9dHE+eIsOZNXHDQx+Oc4A99wE 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: VM_FAULT_RESULT_TRACE should contain an element for every vm_fault_reason to be used as flag_array inside trace_print_flags_seq(). The element for VM_FAULT_COMPLETED is missing, add it. Signed-off-by: Suren Baghdasaryan Reviewed-by: Peter Xu --- include/linux/mm_types.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index de10fc797c8e..39cd34b4dbaa 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -1077,7 +1077,8 @@ enum vm_fault_reason { { VM_FAULT_RETRY, "RETRY" }, \ { VM_FAULT_FALLBACK, "FALLBACK" }, \ { VM_FAULT_DONE_COW, "DONE_COW" }, \ - { VM_FAULT_NEEDDSYNC, "NEEDDSYNC" } + { VM_FAULT_NEEDDSYNC, "NEEDDSYNC" }, \ + { VM_FAULT_COMPLETED, "COMPLETED" } struct vm_special_mapping { const char *name; /* The name, e.g. "[vdso]". */ From patchwork Fri Jun 30 21:19:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13298785 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 B051CEB64DC for ; Fri, 30 Jun 2023 21:20:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4B9948E004E; Fri, 30 Jun 2023 17:20:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4699D8E000F; Fri, 30 Jun 2023 17:20:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2BDDD8E004E; Fri, 30 Jun 2023 17:20:11 -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 1B27B8E000F for ; Fri, 30 Jun 2023 17:20:11 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id E94D380DC3 for ; Fri, 30 Jun 2023 21:20:10 +0000 (UTC) X-FDA: 80960682180.05.A24A0A9 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf19.hostedemail.com (Postfix) with ESMTP id 2063D1A0006 for ; Fri, 30 Jun 2023 21:20:08 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=3h3MWve0; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf19.hostedemail.com: domain of 3CEefZAYKCD8tvsfochpphmf.dpnmjovy-nnlwbdl.psh@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3CEefZAYKCD8tvsfochpphmf.dpnmjovy-nnlwbdl.psh@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1688160009; a=rsa-sha256; cv=none; b=yES2vV9fB/oA+ePWxkD71KcGubRvj/DkDnJPga8ycjSFadwtgutkh72DFYTG2oA2qmkQv3 26JQeXCFf2zkTg9/2y4f+Z/YrmNWsAQIdPjtR0X0Bt2mgiCzgaNJR0PSd79l8C1BN9yHFd TrTyt/nFGf92Tx8Cp9rZYU5Q2BbLf+k= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=3h3MWve0; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf19.hostedemail.com: domain of 3CEefZAYKCD8tvsfochpphmf.dpnmjovy-nnlwbdl.psh@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3CEefZAYKCD8tvsfochpphmf.dpnmjovy-nnlwbdl.psh@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1688160009; 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:in-reply-to:references:references:dkim-signature; bh=V7p+xkeFpHpY+8imX6dpZwoTYVp943eibQ5qK+rLf3c=; b=GwSiS8cAbsPajlv6gvB+Ng/ixOUKOyxhJduk7itjtiCFZeQ4BCkLFQ4ItTPjIYobI06qvH H8AKnkuudLTH+HB/4BrumnlrlCieeY+zHlvdKx/+UaNnaZFdxBg8tYXoRPnxqB99/GIigG KMv2wWPqiZgXJJV40aW3nd7f9RD9CN8= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-56ff7b4feefso23053667b3.0 for ; Fri, 30 Jun 2023 14:20:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1688160008; x=1690752008; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=V7p+xkeFpHpY+8imX6dpZwoTYVp943eibQ5qK+rLf3c=; b=3h3MWve0jx96zUgQCtdmEwl/487FE7hiM4XAWV/a03FX+hNKPzjfhxBp2xnBvYegT/ C6qnQUGRlOp0ILLqmsHhYWmc/p6bWF9Xsy4JDf6vX8OB4sEkRCVKltes2JnR6jJHHPWk WM+978jF+PQrbMOpb67gRRryqGNgIoDfI+qbh7M90nHodbn3+x4ZbPjl/WLgJ+x4EqcG oKqwNpwQNdEusOK0uqAcFe7yKhS7MKhu1T3R1hnxNBiexJX6j6d8zQpeZIzKYKffocD6 VaUxkh4bivx+CK9wy3r/jwRiyZnbwkGB7nTRtGadYqOebn4I5AJmIEWkucS1Ejv0gjej 48/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688160008; x=1690752008; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=V7p+xkeFpHpY+8imX6dpZwoTYVp943eibQ5qK+rLf3c=; b=DoIqrqrZ2sIoJ/+SdzQ1K/Gg8CHPmEKfQjXeCsNdyHS65EtilhP/1Jx+xT31yyeR6/ dQq3hoZbJKXgnMGwsrTTDgAVltyQsbtKIFX9o+Cwgt2Q2nUoa6YcqoMAXYgup/ZPwIrH EZ5cCiD8xWQbtbuzej1WQORX8ZPj7zX3qvkC5m0cN6Be2DhuUWtC6WVW9H064JPuttrZ Ns5hAzAFxlbNqhSjg7oOpYD5oSVeJZVyPrmTzbP2QZazgfJ5G4g/u+/GKgIs/4+CjEUU 11aSNqnDxY/8bEc/XTMjflhsmfwKaW638uhW2BV+CDmF4jdZcAFH0ngYDWoF9SJBUDkB LKtA== X-Gm-Message-State: ABy/qLYDdKV8ftRYzXEmgc7oFL4Vnyqq+y46EL8R0T/VaOVOSZOjDIb3 O+wXhiC4ygiTF5W0I5n8Qyi1W0J3UEc= X-Google-Smtp-Source: APBJJlE6epfASRhUr+pvRHp+fS5E4dLCsuAbw47YMK/KkE1Font5yAC9IWg5l/JB5jBUsD/jiPVeVxN9Sfk= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:b54c:4d64:f00a:1b67]) (user=surenb job=sendgmr) by 2002:a0d:d586:0:b0:569:e04a:238f with SMTP id x128-20020a0dd586000000b00569e04a238fmr29616ywd.4.1688160008047; Fri, 30 Jun 2023 14:20:08 -0700 (PDT) Date: Fri, 30 Jun 2023 14:19:54 -0700 In-Reply-To: <20230630211957.1341547-1-surenb@google.com> Mime-Version: 1.0 References: <20230630211957.1341547-1-surenb@google.com> X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog Message-ID: <20230630211957.1341547-4-surenb@google.com> Subject: [PATCH v7 3/6] mm: drop per-VMA lock when returning VM_FAULT_RETRY or VM_FAULT_COMPLETED 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-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 2063D1A0006 X-Stat-Signature: wydecc8zmuaxdmgc919i9bsuwwnw56sd X-HE-Tag: 1688160008-609654 X-HE-Meta: U2FsdGVkX1/1QUEon0KEAI/Hc5VrERspwunqMRlZgXC058BR/DTYosYR0V/HaWgW5dF5ouPBKaATl3qzAdBrVJro6hA3Zeiep7xX7s3CbTM0jrkxk8EAl1ioZn9bMI/9c34JL3Eet1crMWBaiFePYvAkKkGmXfXdPevLfmr7s1RbRvKKK6AZpdH8e74vNh087BpFho/d2gzOo/x1n0G78rE4j1wJCtRFHRQnbboOY4Fv0mrSedTNeqgUm/VBJkzrcQYcnGN0J/bye48PIh7Zzjp4FTlHgvk7EnWH8gVuxra77XQ0RVce9SdmDM/CfHPIvXJ8X9R0VWlghFLR1Op3LNHyN5SuZDReLGvu8BJ1sXnWbynW8r36pkmuLlD0g+XMFAGXnEr/HdL15lUpN8WBUz73EqOFRNa9TQEirF3IfdoadRkK+/x+yDpZccMn2kbv1f942d8VUSYITsYZZW4SNa0ikRqUPgzaPQT8D3gO4HxfKfx6I/5FNUBStnUvNnfNgvPe5o8cX7rwrpjAYNpnVg1wIuSndTRwQBqXq+02kU7Ug1kCm9ftOHYOfdEm3QjilyFykua5RzJOr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GFuuMiC5d+ExtO0OafnDZ02g== 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: handle_mm_fault returning VM_FAULT_RETRY or VM_FAULT_COMPLETED means mmap_lock has been released. However with per-VMA locks behavior is different and the caller should still release it. To make the rules consistent for the caller, drop the per-VMA lock when returning VM_FAULT_RETRY or VM_FAULT_COMPLETED. Currently the only path returning VM_FAULT_RETRY under per-VMA locks is do_swap_page and no path returns VM_FAULT_COMPLETED for now. Signed-off-by: Suren Baghdasaryan Acked-by: Peter Xu --- arch/arm64/mm/fault.c | 3 ++- arch/powerpc/mm/fault.c | 3 ++- arch/s390/mm/fault.c | 3 ++- arch/x86/mm/fault.c | 3 ++- mm/memory.c | 12 ++++++++++++ 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c index 935f0a8911f9..9d78ff78b0e3 100644 --- a/arch/arm64/mm/fault.c +++ b/arch/arm64/mm/fault.c @@ -602,7 +602,8 @@ static int __kprobes do_page_fault(unsigned long far, unsigned long esr, goto lock_mmap; } fault = handle_mm_fault(vma, addr, mm_flags | FAULT_FLAG_VMA_LOCK, regs); - vma_end_read(vma); + if (!(fault & (VM_FAULT_RETRY | VM_FAULT_COMPLETED))) + vma_end_read(vma); if (!(fault & VM_FAULT_RETRY)) { count_vm_vma_lock_event(VMA_LOCK_SUCCESS); diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c index 5bfdf6ecfa96..82954d0e6906 100644 --- a/arch/powerpc/mm/fault.c +++ b/arch/powerpc/mm/fault.c @@ -489,7 +489,8 @@ static int ___do_page_fault(struct pt_regs *regs, unsigned long address, } fault = handle_mm_fault(vma, address, flags | FAULT_FLAG_VMA_LOCK, regs); - vma_end_read(vma); + if (!(fault & (VM_FAULT_RETRY | VM_FAULT_COMPLETED))) + vma_end_read(vma); if (!(fault & VM_FAULT_RETRY)) { count_vm_vma_lock_event(VMA_LOCK_SUCCESS); diff --git a/arch/s390/mm/fault.c b/arch/s390/mm/fault.c index dbe8394234e2..40a71063949b 100644 --- a/arch/s390/mm/fault.c +++ b/arch/s390/mm/fault.c @@ -418,7 +418,8 @@ static inline vm_fault_t do_exception(struct pt_regs *regs, int access) goto lock_mmap; } fault = handle_mm_fault(vma, address, flags | FAULT_FLAG_VMA_LOCK, regs); - vma_end_read(vma); + if (!(fault & (VM_FAULT_RETRY | VM_FAULT_COMPLETED))) + vma_end_read(vma); if (!(fault & VM_FAULT_RETRY)) { count_vm_vma_lock_event(VMA_LOCK_SUCCESS); goto out; diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c index e8711b2cafaf..56b4f9faf8c4 100644 --- a/arch/x86/mm/fault.c +++ b/arch/x86/mm/fault.c @@ -1341,7 +1341,8 @@ void do_user_addr_fault(struct pt_regs *regs, goto lock_mmap; } fault = handle_mm_fault(vma, address, flags | FAULT_FLAG_VMA_LOCK, regs); - vma_end_read(vma); + if (!(fault & (VM_FAULT_RETRY | VM_FAULT_COMPLETED))) + vma_end_read(vma); if (!(fault & VM_FAULT_RETRY)) { count_vm_vma_lock_event(VMA_LOCK_SUCCESS); diff --git a/mm/memory.c b/mm/memory.c index 0ae594703021..5f26c56ce979 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3730,6 +3730,7 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) if (vmf->flags & FAULT_FLAG_VMA_LOCK) { ret = VM_FAULT_RETRY; + vma_end_read(vma); goto out; } @@ -5182,6 +5183,17 @@ static vm_fault_t sanitize_fault_flags(struct vm_area_struct *vma, !is_cow_mapping(vma->vm_flags))) return VM_FAULT_SIGSEGV; } +#ifdef CONFIG_PER_VMA_LOCK + /* + * Per-VMA locks can't be used with FAULT_FLAG_RETRY_NOWAIT because of + * the assumption that lock is dropped on VM_FAULT_RETRY. + */ + if (WARN_ON_ONCE((*flags & + (FAULT_FLAG_VMA_LOCK | FAULT_FLAG_RETRY_NOWAIT)) == + (FAULT_FLAG_VMA_LOCK | FAULT_FLAG_RETRY_NOWAIT))) + return VM_FAULT_SIGSEGV; +#endif + return 0; } From patchwork Fri Jun 30 21:19:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13298786 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 BBFC6EB64DD for ; Fri, 30 Jun 2023 21:20:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4E33E8E004F; Fri, 30 Jun 2023 17:20:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 41C218E000F; Fri, 30 Jun 2023 17:20:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 295DD8E004F; Fri, 30 Jun 2023 17:20:13 -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 1C2AE8E000F for ; Fri, 30 Jun 2023 17:20:13 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id E9DC4C02FC for ; Fri, 30 Jun 2023 21:20:12 +0000 (UTC) X-FDA: 80960682264.15.E648241 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf24.hostedemail.com (Postfix) with ESMTP id 31753180013 for ; Fri, 30 Jun 2023 21:20:11 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=lpQ0audC; spf=pass (imf24.hostedemail.com: domain of 3CkefZAYKCEEvxuhqejrrjoh.frpolqx0-ppnydfn.ruj@flex--surenb.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3CkefZAYKCEEvxuhqejrrjoh.frpolqx0-ppnydfn.ruj@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1688160011; a=rsa-sha256; cv=none; b=mxLF7UANvZPorvptXRsfDRdJGTpi1I0DdlEJC1I1WiJ2QDreLG/aLIiXlUFtQ7Knm8p17j G7unGn5Z96yQEZD0+PDpJigh5n2EW1REa4a5XYHEWvT+3yfJ0AiedEh1rrEFvt+hnd6P9i 6oeAOcfXh7QcfPkYEq2ISndJVhOkR58= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=lpQ0audC; spf=pass (imf24.hostedemail.com: domain of 3CkefZAYKCEEvxuhqejrrjoh.frpolqx0-ppnydfn.ruj@flex--surenb.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3CkefZAYKCEEvxuhqejrrjoh.frpolqx0-ppnydfn.ruj@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=1688160011; 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:in-reply-to:references:references:dkim-signature; bh=V48GaAIPa0cNnuKmjtn5vErs8F0GYQkIF6/xAME4ub8=; b=s89YZ/0siBEFXIi+EMQ7T16LIUKYrV7giGWZOIzzE+0D+9RxHWO4ubqe2OiLIbxgmzvwF9 7oY7offWQcl3Vu1CI/FIqK09n2XR3e8arU+NdeUwtf7sGgSaiEgwSxxhfQrlX7j1foZpaa M+HWVYOIpvwBZ91NHMgPHaB5kI1RqcU= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-5704995f964so23257547b3.2 for ; Fri, 30 Jun 2023 14:20:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1688160010; x=1690752010; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=V48GaAIPa0cNnuKmjtn5vErs8F0GYQkIF6/xAME4ub8=; b=lpQ0audC6wsRuzHnyRK+4z8E2+3FbVewuOe/E8fGl0CME/gVGP/LwtfwHeXZbkhDvB KMew6UgHQL4Hs7KuwRdK9MYyuFU0dsYVjWwGkfCXYFTo5Xs//Nxyhd+SmNnxyMNtaH6n IZ6bWkw6zolCt4THSRJw09sKyzxPh4Y1FKecn5UyWQK1gOJTMKrbgqjoyIEKWtsMVMNQ Jz3gB4ynV2sWz1sBqH2aUoCl+fRile8jnRuhnjAZbmOkvcfXYsNAYgMuiJ5VMp3R4wKn /ZDhevNPwR502yvk+OovCCRm9sub1Yr6ptFlEfcHZ7b0/NzgizbQm70kFi9gVlAZRkH1 D83A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688160010; x=1690752010; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=V48GaAIPa0cNnuKmjtn5vErs8F0GYQkIF6/xAME4ub8=; b=N7UsYxjNJDOUc2BwuXTZ7WFunrWlIz+DV14J+ySAvxDEuAbH+dP0fYdmxJRqLoB9gk e03HzSD9YWe6yRvPUOzRF+BWC/IP5DxsCPnrHMdcCtna5kH0+2MyUHflxuZsZDy3W3np fnVgs0x0WgYa3EgXLMM7cgAyNE9SagCOm/6PFNZiqYvRrJbszEDf+hR31mb0voA5UkH2 TvvhcRSWvQ5g+mVCH0rjU+MDNZaFMdLX9oApqToKq/2JUt0Ohqbjyw4hIw0nRRK87T6M m9fQfkfpxja86Mz0RYZfslyCFnZRQNZnWYMPP3zQBwBF+Zc9lEaz4te/7maXhLLG+yYY OjjQ== X-Gm-Message-State: ABy/qLZHu1wuGljiGWv3TFjNk9FwTjhJIgM4976jKFyLpnsAPgunaYz4 0kfhhkRVuqrBJZOebyWnCbNfrNPQTKQ= X-Google-Smtp-Source: APBJJlFgzJeFB/N0Q7kM4hg4P3gJ476zCnS8Qd4r8uqOH2goCCLdS+i6OHQO2ZNJoVkai7oWS9rXpJLTShc= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:b54c:4d64:f00a:1b67]) (user=surenb job=sendgmr) by 2002:a81:414c:0:b0:576:d9ea:1331 with SMTP id f12-20020a81414c000000b00576d9ea1331mr27652ywk.4.1688160010392; Fri, 30 Jun 2023 14:20:10 -0700 (PDT) Date: Fri, 30 Jun 2023 14:19:55 -0700 In-Reply-To: <20230630211957.1341547-1-surenb@google.com> Mime-Version: 1.0 References: <20230630211957.1341547-1-surenb@google.com> X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog Message-ID: <20230630211957.1341547-5-surenb@google.com> Subject: [PATCH v7 4/6] mm: change folio_lock_or_retry to use vm_fault directly 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-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 31753180013 X-Stat-Signature: 1as9a8zsmfqoq3z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RqNTIkRzcsszJc654AA5TT7e5YHRwh8gE+3kCuX3fTKmSm6Fr4tcMIw9B5P1XUKl2dfk0n+McYEUrOhCjxcZ9zmBti2JPNT5d6HzWEVPsIYbLskrJjTOCzYKEec938vRuhgPO5nhimFoe+IkPu26h7Fzv+5ryvTl//CMt3dqKVAHLeZOgk3pbW194vHT8+wUTPCJhkdqUbSzCg01NrN+EE/UcPFNEE3CjT4By5tbo9MslgEkBPQ74Y6w1SYfL2/fU3UwLMzBkujr5KXUWASwaE9AR99S4YnQAYrOP49We9T5hqA8RFnclEF4vGuq4FwiGQ5gHJVUunO4r5TCIiw3cKTnwPIMXQSNizazbeyluZWDXFVcnjdfBY5JHkqYOCvjWpk4sWY39i0IML7DygExFsEzCb0ZvHU67VejL4TyANnDQHYIN1lydHqwvNOHkwZW0RpXpZmHvw1VCzmdVMNZlxLfeeJ5T36ik5fbGZIWqBDPQ5DITokvdDm7BVCzTGWOMoteGqbAR+t3T7NoiRSzWz6mFTL65GwDUdpQ7kWWIgOU2pjCoaP1gfHJMNiT9p5PurPrs3b3VaUJk77r3Yygf1GFFirhCy/b8R0J87nd+V+JNQGjlVr1vWNVHPZJGyGaPQ479EomP64AeJSR49pnuz1oI0+ljDNN3dVou54UmiGQbNitudSgbDZmzRsfQpQgQxrrtsW6oG8= 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: Change folio_lock_or_retry to accept vm_fault struct and return the vm_fault_t directly. Suggested-by: Matthew Wilcox Signed-off-by: Suren Baghdasaryan Acked-by: Peter Xu --- include/linux/pagemap.h | 11 ++++++----- mm/filemap.c | 22 ++++++++++++---------- mm/memory.c | 14 ++++++-------- 3 files changed, 24 insertions(+), 23 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 716953ee1ebd..de16f740b755 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -900,8 +900,7 @@ static inline bool wake_page_match(struct wait_page_queue *wait_page, void __folio_lock(struct folio *folio); int __folio_lock_killable(struct folio *folio); -bool __folio_lock_or_retry(struct folio *folio, struct mm_struct *mm, - unsigned int flags); +vm_fault_t __folio_lock_or_retry(struct folio *folio, struct vm_fault *vmf); void unlock_page(struct page *page); void folio_unlock(struct folio *folio); @@ -1005,11 +1004,13 @@ static inline int folio_lock_killable(struct folio *folio) * Return value and mmap_lock implications depend on flags; see * __folio_lock_or_retry(). */ -static inline bool folio_lock_or_retry(struct folio *folio, - struct mm_struct *mm, unsigned int flags) +static inline vm_fault_t folio_lock_or_retry(struct folio *folio, + struct vm_fault *vmf) { might_sleep(); - return folio_trylock(folio) || __folio_lock_or_retry(folio, mm, flags); + if (!folio_trylock(folio)) + return __folio_lock_or_retry(folio, vmf); + return 0; } /* diff --git a/mm/filemap.c b/mm/filemap.c index 9e44a49bbd74..5da5ad6f7f4c 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1669,32 +1669,34 @@ static int __folio_lock_async(struct folio *folio, struct wait_page_queue *wait) /* * Return values: - * true - folio is locked; mmap_lock is still held. - * false - folio is not locked. + * 0 - folio is locked. + * non-zero - folio is not locked. * mmap_lock has been released (mmap_read_unlock(), unless flags had both * FAULT_FLAG_ALLOW_RETRY and FAULT_FLAG_RETRY_NOWAIT set, in * which case mmap_lock is still held. * - * If neither ALLOW_RETRY nor KILLABLE are set, will always return true + * If neither ALLOW_RETRY nor KILLABLE are set, will always return 0 * with the folio locked and the mmap_lock unperturbed. */ -bool __folio_lock_or_retry(struct folio *folio, struct mm_struct *mm, - unsigned int flags) +vm_fault_t __folio_lock_or_retry(struct folio *folio, struct vm_fault *vmf) { + struct mm_struct *mm = vmf->vma->vm_mm; + unsigned int flags = vmf->flags; + if (fault_flag_allow_retry_first(flags)) { /* * CAUTION! In this case, mmap_lock is not released - * even though return 0. + * even though return VM_FAULT_RETRY. */ if (flags & FAULT_FLAG_RETRY_NOWAIT) - return false; + return VM_FAULT_RETRY; mmap_read_unlock(mm); if (flags & FAULT_FLAG_KILLABLE) folio_wait_locked_killable(folio); else folio_wait_locked(folio); - return false; + return VM_FAULT_RETRY; } if (flags & FAULT_FLAG_KILLABLE) { bool ret; @@ -1702,13 +1704,13 @@ bool __folio_lock_or_retry(struct folio *folio, struct mm_struct *mm, ret = __folio_lock_killable(folio); if (ret) { mmap_read_unlock(mm); - return false; + return VM_FAULT_RETRY; } } else { __folio_lock(folio); } - return true; + return 0; } /** diff --git a/mm/memory.c b/mm/memory.c index 5f26c56ce979..4ae3f046f593 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3582,6 +3582,7 @@ static vm_fault_t remove_device_exclusive_entry(struct vm_fault *vmf) struct folio *folio = page_folio(vmf->page); struct vm_area_struct *vma = vmf->vma; struct mmu_notifier_range range; + vm_fault_t ret; /* * We need a reference to lock the folio because we don't hold @@ -3594,9 +3595,10 @@ static vm_fault_t remove_device_exclusive_entry(struct vm_fault *vmf) if (!folio_try_get(folio)) return 0; - if (!folio_lock_or_retry(folio, vma->vm_mm, vmf->flags)) { + ret = folio_lock_or_retry(folio, vmf); + if (ret) { folio_put(folio); - return VM_FAULT_RETRY; + return ret; } mmu_notifier_range_init_owner(&range, MMU_NOTIFY_EXCLUSIVE, 0, vma->vm_mm, vmf->address & PAGE_MASK, @@ -3721,7 +3723,6 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) bool exclusive = false; swp_entry_t entry; pte_t pte; - int locked; vm_fault_t ret = 0; void *shadow = NULL; @@ -3844,12 +3845,9 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) goto out_release; } - locked = folio_lock_or_retry(folio, vma->vm_mm, vmf->flags); - - if (!locked) { - ret |= VM_FAULT_RETRY; + ret |= folio_lock_or_retry(folio, vmf); + if (ret & VM_FAULT_RETRY) goto out_release; - } if (swapcache) { /* From patchwork Fri Jun 30 21:19:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13298787 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 51D66C001B1 for ; Fri, 30 Jun 2023 21:20:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D93D88E0050; Fri, 30 Jun 2023 17:20:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CF5938E000F; Fri, 30 Jun 2023 17:20:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BBD668E0050; Fri, 30 Jun 2023 17:20:15 -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 ACC008E000F for ; Fri, 30 Jun 2023 17:20:15 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 8A68BC0E08 for ; Fri, 30 Jun 2023 21:20:15 +0000 (UTC) X-FDA: 80960682390.26.BE09388 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf16.hostedemail.com (Postfix) with ESMTP id A90D718000D for ; Fri, 30 Jun 2023 21:20:13 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=ZT6ktHZW; spf=pass (imf16.hostedemail.com: domain of 3DEefZAYKCEMxzwjsglttlqj.htrqnsz2-rrp0fhp.twl@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3DEefZAYKCEMxzwjsglttlqj.htrqnsz2-rrp0fhp.twl@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=1688160013; 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:in-reply-to:references:references:dkim-signature; bh=ZLYKxrZ5h1fbhcFAmYXsTYfJQa/73KPAk4mDWkHP+2U=; b=eB1qV1Diz7/HYyLTa3PIvp7tVIPhcDhS68Nc8HHk3gsSI80LKYNCrQ/29jjvwKu5KqljnP YiIJfAaXiCbvjzllkY59zOQ0vYGedFNn5E10G2yZEgR0NeL97cI5xE8Giv4JmJNU/+GTdx c7C9QVlQsJfoPTvAd/7jeo23IOhRyuM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1688160013; a=rsa-sha256; cv=none; b=4LMf56iyr+WBLmdZvXQer3SQlcc39X+PyP3Gr1sDGq013chO8LVmK+km5pEIwXXT2xfPGt krT2UIlMgmJ2D6u4Xe0uNiwTz2yLO9sLjE6m37AF0/AXBagyDaVepCbLsbywchjNYegdn2 QDJtaDofT5mjzsQkxazHrYOAbbysP0E= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=ZT6ktHZW; spf=pass (imf16.hostedemail.com: domain of 3DEefZAYKCEMxzwjsglttlqj.htrqnsz2-rrp0fhp.twl@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3DEefZAYKCEMxzwjsglttlqj.htrqnsz2-rrp0fhp.twl@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-573d70da2dcso22631157b3.1 for ; Fri, 30 Jun 2023 14:20:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1688160012; x=1690752012; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ZLYKxrZ5h1fbhcFAmYXsTYfJQa/73KPAk4mDWkHP+2U=; b=ZT6ktHZWBfakPwTdWQL11GJylklZdUt0REmIhnELtq8vuBuVaxQgco9JCoPnC+OuuU vZw6PSnrGelo0lEcCeDnFYN+4tflSM08EdhmftkX19M9KyJrNLTeDVawm7norgcsHG5C dYVgLU28UQIhivrIil0nxAl475ziO73D9fN2kmu9LIUFW9ZFSiP3g0UxtSZe73VE2twZ nBPnZdmF3VizjltBsqXwY6xVQPcd/rehkQvW2VeGImIgps3clPONivcBrZwnBiRTeozA de88VNzV4x+EJnMxv8ucE3UsQ49l0jwnRRd+gl+RiItO69e1VdmSX+9wfmOXimiSZbMc iK4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688160012; x=1690752012; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ZLYKxrZ5h1fbhcFAmYXsTYfJQa/73KPAk4mDWkHP+2U=; b=kvqP6vlmiDruZhmySS7WjXZmUei4N+UNPO/Uz7Ip5F8HM4wRwVninSi0jjZWgHH0UH Lv537xmgkkn+YqzyTK5rBEvZHwnfdt4RNEzd7IGAN87ze2kWeK4hdTpFtmmPBjN1IZuO +eE5QMvQVJa5cBA8OanqjUg45vfYaeCITy9vjgY+1vWEuWzPOa7NBDcjjo5kt+H0Rfh5 OuNc7+5KqYVR13abDURUNIGfQx0Bwn/vXmzuAerEE9Rzrw7kL6vav5U0J0jdbWR0jv1Y X95Zxh1tHMcxCAmlJoGCC17ObnnF1LLGL/DNpAdUl86gusoxBhjL5aZ3UD0o558YOjq4 ykCQ== X-Gm-Message-State: ABy/qLbklM+9Mwr93/fVnzYne6UK15J6agZKlBOQFf4JJs+3lgyUoKx0 fTeT0u+VojpWLIHk3Yn43+Kgcb54eo0= X-Google-Smtp-Source: APBJJlEfJxRiiLohpASuK48k4/aLdsiMH6cDocekn+hydllmXb7XugZwuZXe3kkmsJwh5wjvqPkBFJmtPmQ= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:b54c:4d64:f00a:1b67]) (user=surenb job=sendgmr) by 2002:a81:cb0c:0:b0:56c:e6fa:6ce9 with SMTP id q12-20020a81cb0c000000b0056ce6fa6ce9mr29913ywi.8.1688160012625; Fri, 30 Jun 2023 14:20:12 -0700 (PDT) Date: Fri, 30 Jun 2023 14:19:56 -0700 In-Reply-To: <20230630211957.1341547-1-surenb@google.com> Mime-Version: 1.0 References: <20230630211957.1341547-1-surenb@google.com> X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog Message-ID: <20230630211957.1341547-6-surenb@google.com> Subject: [PATCH v7 5/6] mm: handle swap page faults under per-VMA lock 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: fzm8zts3ptgw9ocukr7dpmdnh6mbh4bh X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: A90D718000D X-Rspam-User: X-HE-Tag: 1688160013-608357 X-HE-Meta: U2FsdGVkX1+A8CoHjPhEC7jT7cNxt3TtVxMhi2o/vF/71h30GTIwZfxt3h+WtraPy+t83vA+NDwPKJfchsBW+4v0QdV8FjCim40mjnZ2804Sj+etx1PgztJpImN7GWrEUplIlIkEpMD2NqJI7SURXCwpXU5Z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TStoisONsSeMztdyPKGjAxkWvfbszvE+wHjsM/bF/Qq6wo0p3rhalrC4EIiEw2gt0cAQSn+O//4yaIWQGiug5JH2UoA08aNYuftHZ/HWQwNVyoduiZzrCJTwD5YfRmzStFytIA81rN/SzbwobZYw+qv1M7TP5hBvdcMtPAWWxOCyrZKLPPVmitAn2StbV79rdUH2b4m0YAoKmSE6gaX9YLpuAqGBR7N3HNhjKjUmySmTfragAYuSqsYOHRCpcHGVVzFtLvkiQTeaq6rbqfWEIzyjvOx9Ja7C+kGQ8n0AACGnSyN3Wtx8Hfq8U1RV3FK3gFoVxKYXAu9ukWu0gJqwSw7fS/QQzgCKICf1wvGTm63pcxskS1qSs+AutXhPQXJvvnWGQMHb0sJTMM+mkt2w== 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: When page fault is handled under per-VMA lock protection, all swap page faults are retried with mmap_lock because folio_lock_or_retry has to drop and reacquire mmap_lock if folio could not be immediately locked. Follow the same pattern as mmap_lock to drop per-VMA lock when waiting for folio and retrying once folio is available. With this obstacle removed, enable do_swap_page to operate under per-VMA lock protection. Drivers implementing ops->migrate_to_ram might still rely on mmap_lock, therefore we have to fall back to mmap_lock in that particular case. Note that the only time do_swap_page calls synchronous swap_readpage is when SWP_SYNCHRONOUS_IO is set, which is only set for QUEUE_FLAG_SYNCHRONOUS devices: brd, zram and nvdimms (both btt and pmem). Therefore we don't sleep in this path, and there's no need to drop the mmap or per-VMA lock. Signed-off-by: Suren Baghdasaryan Tested-by: Alistair Popple Reviewed-by: Alistair Popple Acked-by: Peter Xu --- include/linux/mm.h | 13 +++++++++++++ mm/filemap.c | 17 ++++++++--------- mm/memory.c | 16 ++++++++++------ 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 39aa409e84d5..54ab11214f4f 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -720,6 +720,14 @@ static inline void vma_mark_detached(struct vm_area_struct *vma, bool detached) vma->detached = detached; } +static inline void release_fault_lock(struct vm_fault *vmf) +{ + if (vmf->flags & FAULT_FLAG_VMA_LOCK) + vma_end_read(vmf->vma); + else + mmap_read_unlock(vmf->vma->vm_mm); +} + struct vm_area_struct *lock_vma_under_rcu(struct mm_struct *mm, unsigned long address); @@ -735,6 +743,11 @@ static inline void vma_assert_write_locked(struct vm_area_struct *vma) {} static inline void vma_mark_detached(struct vm_area_struct *vma, bool detached) {} +static inline void release_fault_lock(struct vm_fault *vmf) +{ + mmap_read_unlock(vmf->vma->vm_mm); +} + #endif /* CONFIG_PER_VMA_LOCK */ /* diff --git a/mm/filemap.c b/mm/filemap.c index 5da5ad6f7f4c..5ac1b7beea2a 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1671,27 +1671,26 @@ static int __folio_lock_async(struct folio *folio, struct wait_page_queue *wait) * Return values: * 0 - folio is locked. * non-zero - folio is not locked. - * mmap_lock has been released (mmap_read_unlock(), unless flags had both - * FAULT_FLAG_ALLOW_RETRY and FAULT_FLAG_RETRY_NOWAIT set, in - * which case mmap_lock is still held. + * mmap_lock or per-VMA lock has been released (mmap_read_unlock() or + * vma_end_read()), unless flags had both FAULT_FLAG_ALLOW_RETRY and + * FAULT_FLAG_RETRY_NOWAIT set, in which case the lock is still held. * * If neither ALLOW_RETRY nor KILLABLE are set, will always return 0 - * with the folio locked and the mmap_lock unperturbed. + * with the folio locked and the mmap_lock/per-VMA lock is left unperturbed. */ vm_fault_t __folio_lock_or_retry(struct folio *folio, struct vm_fault *vmf) { - struct mm_struct *mm = vmf->vma->vm_mm; unsigned int flags = vmf->flags; if (fault_flag_allow_retry_first(flags)) { /* - * CAUTION! In this case, mmap_lock is not released - * even though return VM_FAULT_RETRY. + * CAUTION! In this case, mmap_lock/per-VMA lock is not + * released even though returning VM_FAULT_RETRY. */ if (flags & FAULT_FLAG_RETRY_NOWAIT) return VM_FAULT_RETRY; - mmap_read_unlock(mm); + release_fault_lock(vmf); if (flags & FAULT_FLAG_KILLABLE) folio_wait_locked_killable(folio); else @@ -1703,7 +1702,7 @@ vm_fault_t __folio_lock_or_retry(struct folio *folio, struct vm_fault *vmf) ret = __folio_lock_killable(folio); if (ret) { - mmap_read_unlock(mm); + release_fault_lock(vmf); return VM_FAULT_RETRY; } } else { diff --git a/mm/memory.c b/mm/memory.c index 4ae3f046f593..bb0f68a73b0c 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3729,12 +3729,6 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) if (!pte_unmap_same(vmf)) goto out; - if (vmf->flags & FAULT_FLAG_VMA_LOCK) { - ret = VM_FAULT_RETRY; - vma_end_read(vma); - goto out; - } - entry = pte_to_swp_entry(vmf->orig_pte); if (unlikely(non_swap_entry(entry))) { if (is_migration_entry(entry)) { @@ -3744,6 +3738,16 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) vmf->page = pfn_swap_entry_to_page(entry); ret = remove_device_exclusive_entry(vmf); } else if (is_device_private_entry(entry)) { + if (vmf->flags & FAULT_FLAG_VMA_LOCK) { + /* + * migrate_to_ram is not yet ready to operate + * under VMA lock. + */ + vma_end_read(vma); + ret = VM_FAULT_RETRY; + goto out; + } + vmf->page = pfn_swap_entry_to_page(entry); vmf->pte = pte_offset_map_lock(vma->vm_mm, vmf->pmd, vmf->address, &vmf->ptl); From patchwork Fri Jun 30 21:19:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13298788 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 D887EC001B0 for ; Fri, 30 Jun 2023 21:20:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7EE078E0051; Fri, 30 Jun 2023 17:20:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 79E218E000F; Fri, 30 Jun 2023 17:20:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 61ACD8E0051; Fri, 30 Jun 2023 17:20:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 548A68E000F for ; Fri, 30 Jun 2023 17:20:18 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 32EB41604AD for ; Fri, 30 Jun 2023 21:20:18 +0000 (UTC) X-FDA: 80960682516.30.3B9A065 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf25.hostedemail.com (Postfix) with ESMTP id 6B18AA0016 for ; Fri, 30 Jun 2023 21:20:16 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=VRHbgEe+; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf25.hostedemail.com: domain of 3D0efZAYKCEY02zmvjowwotm.kwutqv25-uus3iks.wzo@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3D0efZAYKCEY02zmvjowwotm.kwutqv25-uus3iks.wzo@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1688160016; 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:in-reply-to:references:references:dkim-signature; bh=CYZzVVGdFW3BZ7BX39EfN49IRv4dv2Sl4PMSdQqxDi4=; b=hAkFT732UGFme2namF7bxzlLVrP7/bSG55xDIksldU3Ln8EGXCYcnIrJlzjLNvvTNnr2UK PfD84vrwkMU/E05vYzCfuEFGaNf3KqoTAG+KFhm1qMKUTPfD5nBagEAl8zfE5F+aYyEmXB vuc3poZvU+CpIjSujorhmWB/kqimNqI= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=VRHbgEe+; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf25.hostedemail.com: domain of 3D0efZAYKCEY02zmvjowwotm.kwutqv25-uus3iks.wzo@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3D0efZAYKCEY02zmvjowwotm.kwutqv25-uus3iks.wzo@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1688160016; a=rsa-sha256; cv=none; b=KYHYmmNT833HcHHjaFqXz5EzSiZ3yfHgbVE/ih4aZ6KNs8waxE1vStW33FNUMd9+AOFTfW p9jwYlILpoORSm/ypdxkzo7hzEb6O6SOTvLLr6iwTvsuB74mCHsB1sKDDHvuDgLBqGLhep MQ6fVPPo4ckwT2wIA2iOOia3tZSaSFk= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-5707177ff8aso22546807b3.2 for ; Fri, 30 Jun 2023 14:20:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1688160015; x=1690752015; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=CYZzVVGdFW3BZ7BX39EfN49IRv4dv2Sl4PMSdQqxDi4=; b=VRHbgEe+4tmyXojwe94SagE/3BdWRl9HljjtCM10oZH/2lirmShVuqPWYhXZZyEPVa PHSvriOmhmIWRrb97shs8wqeA/tP9lhy9ofKmbZu25SK7Md122TbXLrK9ljgsXGJnI7k 2Mai/hmZVv0XaioP1GuSs9ziPWNt6fGSHdy1nJYlIY/ldiZVysVd4eUGJdPsUGTJU1jG HkPIOLGsrmKHdMyj/vDsrtFzgjcyUb0RruqV5uD7mMn2bM5ITwFRVeLw4+orENuWMhoI SxIeBb8YpgDHnftP3wphxALr9hOaqHUGaMOTSEgl5omQxW0Qu6paJ/+V+fHiSgMem/mA FuTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688160015; x=1690752015; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=CYZzVVGdFW3BZ7BX39EfN49IRv4dv2Sl4PMSdQqxDi4=; b=gIbOsV9fdpJKEyYY40XCpG5H1Dlrwp4OdEi3BwqY7Cw6mho+roD52fw0ab4GowUz1e 0+xjvNEza6W98MXe/aNZDrFJtwQwyCCyRDJMLIG3PwV1VEjqPQ7JeytvBSGZBahasTb0 Ika7lkDFPNF6gFirMWI2TDgIliXpjwzH86qvNApzTo39aPp2K7g5M+ss4j7wo+f5Ht5J c1/T4Kn9g1oo6sgpNyJbw4VzT5DkeRfv0ziQ+tNzjcTFaE0GL9qYz/Ao9RCdtjHmkuIv OvJqMw0wT8aaulqsy3Nm5vikPMIxxWAUZ1IubuLXt1oVRVb+XTkchN6nAZn7O1SacKXj zdvg== X-Gm-Message-State: ABy/qLYPY7tHIdR3s4zvU6N+FvwKw15UTpnYynZaSkgZGP7Aaz9BlOTi gWsQq4/EHsanHvw7IuunIfsGrNVsJ1E= X-Google-Smtp-Source: APBJJlGXAJjNagMRUpJSstior0oEerrgAMTnrbJJ1mJiBLKiXUVNW+JBvG48qVTyNdlMCtXmqetsT5NLqOQ= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:b54c:4d64:f00a:1b67]) (user=surenb job=sendgmr) by 2002:a81:414c:0:b0:56d:21a1:16a1 with SMTP id f12-20020a81414c000000b0056d21a116a1mr30032ywk.5.1688160015604; Fri, 30 Jun 2023 14:20:15 -0700 (PDT) Date: Fri, 30 Jun 2023 14:19:57 -0700 In-Reply-To: <20230630211957.1341547-1-surenb@google.com> Mime-Version: 1.0 References: <20230630211957.1341547-1-surenb@google.com> X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog Message-ID: <20230630211957.1341547-7-surenb@google.com> Subject: [PATCH v7 6/6] mm: handle userfaults under VMA lock 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-Rspamd-Queue-Id: 6B18AA0016 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: f1zggo5nfar13ejmeq3dgcnqa8bw4k6d X-HE-Tag: 1688160016-183873 X-HE-Meta: U2FsdGVkX1/dXuQPLJunmKiEtJtsgeq3kWhvsZVgXMBONyW8Ckf6ZpEMUWwMUH1yuMNogEOBvxP2Odm3W6hpA9PyydwUS8nQqNF/VCAsg4s6hB045/agrRmm2yZh/0cxdVsoVn8cPAxxjCwPo0WVdxlKrPnKSZeT/SEMGSurenTbH2IdyaWqB0c010ihb+rguJwqKylDF9vfFtpuoY9Un53LshVU4lotUnFJEgLcKcR34P5eipajyB6k0HBUGtetWQc8pFsyA3E/AL3TFjQSAuZWjJb7I+QULQ4KxAM8W4YcP7r1JQXTWENIAMzQwGXg49QVmKx/vZv/f/qZBrW6s1/kgGief4PcDBR45UYRcKREyxkS1Ppwqguosvv2/kmzvTcOKgWMT+G3YZOqrB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lDooso7FSXbKpwK2jOu436X7Pgvw3AJCXFvPkogKZzSgstnM21oKzKG5F7O1nuBd82uikaL82H4oK5JnIDfw+bONxA5+zs8N9LnyHTeKLImSmlRVIA/3nYEkH3QR0OrJCY2a6e6UYdSfZap+CthnJqyc 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: Enable handle_userfault to operate under VMA lock by releasing VMA lock instead of mmap_lock and retrying. Note that FAULT_FLAG_RETRY_NOWAIT should never be used when handling faults under per-VMA lock protection because that would break the assumption that lock is dropped on retry. Signed-off-by: Suren Baghdasaryan Acked-by: Peter Xu --- fs/userfaultfd.c | 34 ++++++++++++++-------------------- include/linux/mm.h | 24 ++++++++++++++++++++++++ mm/memory.c | 9 --------- 3 files changed, 38 insertions(+), 29 deletions(-) diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c index 7cecd49e078b..21a546eaf9f7 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -277,17 +277,16 @@ static inline struct uffd_msg userfault_msg(unsigned long address, * hugepmd ranges. */ static inline bool userfaultfd_huge_must_wait(struct userfaultfd_ctx *ctx, - struct vm_area_struct *vma, - unsigned long address, - unsigned long flags, - unsigned long reason) + struct vm_fault *vmf, + unsigned long reason) { + struct vm_area_struct *vma = vmf->vma; pte_t *ptep, pte; bool ret = true; - mmap_assert_locked(ctx->mm); + assert_fault_locked(vmf); - ptep = hugetlb_walk(vma, address, vma_mmu_pagesize(vma)); + ptep = hugetlb_walk(vma, vmf->address, vma_mmu_pagesize(vma)); if (!ptep) goto out; @@ -308,10 +307,8 @@ static inline bool userfaultfd_huge_must_wait(struct userfaultfd_ctx *ctx, } #else static inline bool userfaultfd_huge_must_wait(struct userfaultfd_ctx *ctx, - struct vm_area_struct *vma, - unsigned long address, - unsigned long flags, - unsigned long reason) + struct vm_fault *vmf, + unsigned long reason) { return false; /* should never get here */ } @@ -325,11 +322,11 @@ static inline bool userfaultfd_huge_must_wait(struct userfaultfd_ctx *ctx, * threads. */ static inline bool userfaultfd_must_wait(struct userfaultfd_ctx *ctx, - unsigned long address, - unsigned long flags, + struct vm_fault *vmf, unsigned long reason) { struct mm_struct *mm = ctx->mm; + unsigned long address = vmf->address; pgd_t *pgd; p4d_t *p4d; pud_t *pud; @@ -338,7 +335,7 @@ static inline bool userfaultfd_must_wait(struct userfaultfd_ctx *ctx, pte_t ptent; bool ret = true; - mmap_assert_locked(mm); + assert_fault_locked(vmf); pgd = pgd_offset(mm, address); if (!pgd_present(*pgd)) @@ -440,7 +437,7 @@ vm_fault_t handle_userfault(struct vm_fault *vmf, unsigned long reason) * Coredumping runs without mmap_lock so we can only check that * the mmap_lock is held, if PF_DUMPCORE was not set. */ - mmap_assert_locked(mm); + assert_fault_locked(vmf); ctx = vma->vm_userfaultfd_ctx.ctx; if (!ctx) @@ -556,15 +553,12 @@ vm_fault_t handle_userfault(struct vm_fault *vmf, unsigned long reason) spin_unlock_irq(&ctx->fault_pending_wqh.lock); if (!is_vm_hugetlb_page(vma)) - must_wait = userfaultfd_must_wait(ctx, vmf->address, vmf->flags, - reason); + must_wait = userfaultfd_must_wait(ctx, vmf, reason); else - must_wait = userfaultfd_huge_must_wait(ctx, vma, - vmf->address, - vmf->flags, reason); + must_wait = userfaultfd_huge_must_wait(ctx, vmf, reason); if (is_vm_hugetlb_page(vma)) hugetlb_vma_unlock_read(vma); - mmap_read_unlock(mm); + release_fault_lock(vmf); if (likely(must_wait && !READ_ONCE(ctx->released))) { wake_up_poll(&ctx->fd_wqh, EPOLLIN); diff --git a/include/linux/mm.h b/include/linux/mm.h index 54ab11214f4f..2794225b2d42 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -705,6 +705,17 @@ static inline bool vma_try_start_write(struct vm_area_struct *vma) return true; } +static inline void vma_assert_locked(struct vm_area_struct *vma) +{ + int mm_lock_seq; + + if (__is_vma_write_locked(vma, &mm_lock_seq)) + return; + + lockdep_assert_held(&vma->vm_lock->lock); + VM_BUG_ON_VMA(!rwsem_is_locked(&vma->vm_lock->lock), vma); +} + static inline void vma_assert_write_locked(struct vm_area_struct *vma) { int mm_lock_seq; @@ -728,6 +739,14 @@ static inline void release_fault_lock(struct vm_fault *vmf) mmap_read_unlock(vmf->vma->vm_mm); } +static inline void assert_fault_locked(struct vm_fault *vmf) +{ + if (vmf->flags & FAULT_FLAG_VMA_LOCK) + vma_assert_locked(vmf->vma); + else + mmap_assert_locked(vmf->vma->vm_mm); +} + struct vm_area_struct *lock_vma_under_rcu(struct mm_struct *mm, unsigned long address); @@ -748,6 +767,11 @@ static inline void release_fault_lock(struct vm_fault *vmf) mmap_read_unlock(vmf->vma->vm_mm); } +static inline void assert_fault_locked(struct vm_fault *vmf) +{ + mmap_assert_locked(vmf->vma->vm_mm); +} + #endif /* CONFIG_PER_VMA_LOCK */ /* diff --git a/mm/memory.c b/mm/memory.c index bb0f68a73b0c..d9f36f9392a9 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5407,15 +5407,6 @@ struct vm_area_struct *lock_vma_under_rcu(struct mm_struct *mm, if (!vma_start_read(vma)) goto inval; - /* - * Due to the possibility of userfault handler dropping mmap_lock, avoid - * it for now and fall back to page fault handling under mmap_lock. - */ - if (userfaultfd_armed(vma)) { - vma_end_read(vma); - goto inval; - } - /* Check since vm_start/vm_end might change before we lock the VMA */ if (unlikely(address < vma->vm_start || address >= vma->vm_end)) { vma_end_read(vma);