From patchwork Fri Jun 9 00:51: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: 13273052 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 15BAFC83003 for ; Fri, 9 Jun 2023 00:52:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 902E78E0003; Thu, 8 Jun 2023 20:52:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8B2BA8E0001; Thu, 8 Jun 2023 20:52:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 72C0A8E0003; Thu, 8 Jun 2023 20:52:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 638768E0001 for ; Thu, 8 Jun 2023 20:52:08 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 38C791401AA for ; Fri, 9 Jun 2023 00:52:08 +0000 (UTC) X-FDA: 80881382736.27.0FC5C5D Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf11.hostedemail.com (Postfix) with ESMTP id 6A99240003 for ; Fri, 9 Jun 2023 00:52:06 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=IyAXoXjV; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf11.hostedemail.com: domain of 3tXeCZAYKCNgMOL8H5AIIAF8.6IGFCHOR-GGEP46E.ILA@flex--surenb.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3tXeCZAYKCNgMOL8H5AIIAF8.6IGFCHOR-GGEP46E.ILA@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1686271926; 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=yuiOMQ0aSy0KwUuwsgymDjnxP8/lpeb7/V1M3j1Xb1E=; b=5C74Zm+tr7VgkXv/+FUZnyqdI6TCzRV+pwXTx1fQm7a+MVfQj05g+ALUE0JXhkr2riA+zZ ETUB9o9SGE1hQUC7OO4ODu2W1BQT1bHW4ncwxiVCwe9N3T4SubSKNNHlm7EmQLKVpOFhCK cOG+u7MLDShkQcbFMkUdARLfMSdJmbo= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=IyAXoXjV; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf11.hostedemail.com: domain of 3tXeCZAYKCNgMOL8H5AIIAF8.6IGFCHOR-GGEP46E.ILA@flex--surenb.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3tXeCZAYKCNgMOL8H5AIIAF8.6IGFCHOR-GGEP46E.ILA@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1686271926; a=rsa-sha256; cv=none; b=sNGOr1AUW4NNlDxn/7Xohar8F57raIj3SNBT06YYlGzROjDXhJudiK3TYfNcduvs/weDtu q2Rs8JcyUun9j7oHYOo6YUJqYhLHhQhRK+XPT3h2TdzhximpqEtgxJDLhpvBDRd50pdKih 58YowXGgH53V/pOnaEy+HfFOs8MGoKM= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-5651d8acfe2so16859347b3.2 for ; Thu, 08 Jun 2023 17:52:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1686271925; x=1688863925; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=yuiOMQ0aSy0KwUuwsgymDjnxP8/lpeb7/V1M3j1Xb1E=; b=IyAXoXjV7xCg1A6CTIB0VVGoVOFSNHNynjRms7ZT4ZJuasxkgD/xINqmOy3R2QWmj6 LweWil7YBo9DB23KcYDwjIFg2tzhu/sNAVap1M78azP9/yh5rbc8NVuFliEYHm7NBXMo soQpcPklJ87/HIwm9iXTXt6sGz2j9ugeHoaBCIPXu786yDSkXPG2N+lpjRD03pJqKf4U ynS64LhxDlPhl3xfkAFkbEO/hQz6xagu8ZpHoJtj8fgQugYSIR8+59/FTuzy8cFImM2J 9Fgql8U7ice3Cs5matPGhf41n4PEh7vFyVlNzgNeB1JUE14tptvSHOdWg+sF+J8fGOVy muaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686271925; x=1688863925; 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=yuiOMQ0aSy0KwUuwsgymDjnxP8/lpeb7/V1M3j1Xb1E=; b=b2AmLS2ewX4oW15EAugCmKEqos2uFMOPjFdefKE2bQOQh80hqkSflzk5npEZGAYbWX oFHR4Lo3Cx9op9csp3cJg9RKD6C3Dv017O8BV+zPj6DvFttcfHibdy/z8GIS1wWvMR3L Pae5frGVAd3Mry53+Yxy2cDQZp/hJTeWcM2gsh9Jmv4jGmMuhbJeAt0VlgHNm87as9UG HyULNkfcT4L/Sf+3BVLxuca3YrGWSj5yJoeiyWUttkTOlQYUsKFAx77zyL/FWEkHMUaU mo4LQlkcwOSYpxgGkMBLghDFrh8Pm4AyaoWXWVUu/Qviw7L5jAjR0ZJYwQZciYY4iZuV 59bg== X-Gm-Message-State: AC+VfDzyI6LA5G63GkrzEtm8imPWnECfe8Dm3a6VxKqTMMDWpUccpsLI PxW7CiVa+Koma2loKf59fvOrVQ8w98s= X-Google-Smtp-Source: ACHHUZ7vpO/mcmJj2VKORN5it7Uqz0TT+6LPQeqOxr4F1AyBIL+6jgbr7cmENYkI/PhrqFOCmtLfaWiUoNY= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:c03e:d3b7:767a:9467]) (user=surenb job=sendgmr) by 2002:a81:b2c9:0:b0:55d:8472:4597 with SMTP id q192-20020a81b2c9000000b0055d84724597mr729567ywh.10.1686271925574; Thu, 08 Jun 2023 17:52:05 -0700 (PDT) Date: Thu, 8 Jun 2023 17:51:53 -0700 In-Reply-To: <20230609005158.2421285-1-surenb@google.com> Mime-Version: 1.0 References: <20230609005158.2421285-1-surenb@google.com> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog Message-ID: <20230609005158.2421285-2-surenb@google.com> Subject: [PATCH v2 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 X-Rspamd-Queue-Id: 6A99240003 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 6saszfihfgratb1yx3ixgacy93dnexrz X-HE-Tag: 1686271926-21643 X-HE-Meta: U2FsdGVkX1/M1wdcsxsxhZ6CVXVVFZtF4p/eGJkExhxfeTKP+CcpOBEnur048vxbnwKWH7mJkMoLPS0soeSN1hq0kODPXZRrYzTe1G/Rw6Zh7AgNMeDwcZJZ7TiE9sg/7ArxQyTuekWO4UPExZaFhDWhCpflxGLqJ43nVYqcCmicuy4h9VGP9MNfunjxh1VuK88JimD+c4JAx7vPDcLkw5IdLw2zm9qpB86uXbLehNRcVWyCKW/5BBd2UFVFtxTyViMyUWCk4ypG9BSWvIGwJ8DUy8wmUeVjSCUwbeBPho5jiO+XLyXNwXz/nm/AZw2+pVJmCaxZWkVrLa747h2WjNN8aGqigWTnp+yAH/7HFwhphfuXhjAXFZzgWH0wuWhlEY/8XE6oD1DfVwzYmB2vSUEPlNVVBFDf+7QwOXytpj4u3tMSzM4QmH0tvwu2YF7rWsV2JD0vBo2mYRH2jkuXRCsBcp+5aldcpJQfxNWyn+LSjk2haBxWajDwg8kqAq/94R8Zs2lDihWSL1O+/KZtpM+dX75ggsbXzNXG5rqpctDSJc5A0fGP5o91Zj7OW3veaHi4htJ8GoV41/6XByNzYC2WNt0ZA0Y1WuxBBsNPb/h6JH+Eup0Q04cRKlqP9es+GBOdhPzjdzuyJWYHFOrwPwJqi6MFhndxDarQqiSknKdpmHipga8ytZ167dnUQbZi9PT7n9SiB7+tT/+IXpe4NONHPSrShrDEtMpZ+vHLNbtQi1OJCHD/rtjRBO4/erfi7TRxFCxQFNLwVqZytie+MNXCYNWwrjPmOKKx2vnTCrc2Bx1v6FttqH7NLF0P+Hs/DqSQYc1IaLv8enrxLEcRBptJlXu2v4NQiZSrjqCGJN7cNAX+5sE7zr1XaHURM7Qn0fj9e1ahTloknmNsI+iPy9IIfVYGMo/FVNb/zo9TkGImsiIwXC4aGhDOvIfJ6o3NPLmQYJvM05m/yKOH71a EjbAk0Bf zpaWAmibDZmh2ijha5k6RBsxMzROiwO8F6gQRSUSxo8vqM33xnPuitKNGFvKJDhdECehkKxZ72fFRPU1JOqp4lagI0WCjhrn0RYXKgDQ1qnZKzfaTTGGQB1Bszo5aqFrllAHWqjorBvy+hB/O7Z9aJOVu+ynxazNbtVC1rpOYjBamo+oauZjaDYVtQb8VzxMsQGpgXmG0+4Hjkrawa2Ac7S+7rU0kQqCIGW6/8IAN2XWoPKt373FGdwlrZk0CT0ge6+8yzt/hWQprNSiawZPCKZh6+ztFU12QCL8F8vMdfQpexMt7PVfSIp9D7oqpaO8IDutLsKzI/wl1QGIsjBtj0qC7mrsK5z3yPqJVxPmKZTrMxg41JTQyHQ/7EFmJGcACL330/etY4Nm5x+p9GOmQeGMIJvOVj4EGdTYusvEnnFlTMvFxw9amXp3d1fM9sElCA3nulJTO4dQaJpvr1JoHaMJE/ZFTukeP1Oox3jYXa9LVmkIeiVBZXA5YZbkD5YOWm89PyXwCnyixqWGsE93qR8dJur863RzcHbKnJFophBPu6arQ+jREOZVeeTaT1xGiYQ+9x7qv0M+U22kk/gcRlfuQMkEX+oDQCaKoOp5issunesVVWujL8ySW84b8XR8rD6ai6R5I1vMaWtUCi+R+ss5TM981ChGx+a2gyizKdbWOorlLHoyhuadZpw== 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 during 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 b5ffbaf616f5..b1e8adf1234e 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -215,7 +215,7 @@ static int swapin_walk_pmd_entry(pmd_t *pmd, unsigned long start, continue; page = read_swap_cache_async(entry, GFP_HIGHUSER_MOVABLE, - vma, index, false, &splug); + vma, index, &splug); if (page) put_page(page); } @@ -252,7 +252,7 @@ static void force_shm_swapin_readahead(struct vm_area_struct *vma, rcu_read_unlock(); page = read_swap_cache_async(swap, GFP_HIGHUSER_MOVABLE, - NULL, 0, false, &splug); + NULL, 0, &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 b76a65ac28b3..a3839de71f3f 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -517,15 +517,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; } @@ -620,7 +619,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; @@ -628,7 +627,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; @@ -660,7 +658,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) @@ -825,7 +823,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 9 00:51: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: 13273053 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 9505EC7EE29 for ; Fri, 9 Jun 2023 00:52:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2C2DC8E0005; Thu, 8 Jun 2023 20:52:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1D57C8E0001; Thu, 8 Jun 2023 20:52:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 09D2B8E0005; Thu, 8 Jun 2023 20:52:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id F07978E0001 for ; Thu, 8 Jun 2023 20:52:10 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id AE4351A0397 for ; Fri, 9 Jun 2023 00:52:10 +0000 (UTC) X-FDA: 80881382820.06.A6C64E0 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf26.hostedemail.com (Postfix) with ESMTP id E210A140008 for ; Fri, 9 Jun 2023 00:52:08 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b="gXDUez/e"; spf=pass (imf26.hostedemail.com: domain of 3t3eCZAYKCNoOQNAJ7CKKCHA.8KIHEJQT-IIGR68G.KNC@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3t3eCZAYKCNoOQNAJ7CKKCHA.8KIHEJQT-IIGR68G.KNC@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1686271928; a=rsa-sha256; cv=none; b=do7rDF/17vHJOBvpwocPm2Ya+sHQAfRyuCkXBExCl+kGiooAK3rZl/6hLi+dR3Jsjp8HPf ux3vAgvzr0bh8UZLpjNBw08mfGvXp179CtGbmrptT0tU5wdQz3Ly9yGB6TfAx1GPmh1bvH LH8dEfsnKqIFnMDvOrZl4iSzQDKeH0k= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b="gXDUez/e"; spf=pass (imf26.hostedemail.com: domain of 3t3eCZAYKCNoOQNAJ7CKKCHA.8KIHEJQT-IIGR68G.KNC@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3t3eCZAYKCNoOQNAJ7CKKCHA.8KIHEJQT-IIGR68G.KNC@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=1686271928; 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=PkmNN9bDB8D6ky9B1T3x3QkjIj3UMnGVw+OccLVTcQI=; b=pF9Pblb6pmU9aIfpiCrHnfqgTZXv2Ve8r9GsA4/NGiDTOky+yuMT9U3dQLrrjtX/7/0XAs PIo0/e1Yl+5E9ieQjVYjUrCwl27fCXsV2YRkn166KyQZsQexeM3M+r/3Ko33G9zGJybW9m OLTQ4Brzesxpec/jKimDRs7MDvEH1ho= Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-babb79a17b8so1742711276.0 for ; Thu, 08 Jun 2023 17:52:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1686271928; x=1688863928; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=PkmNN9bDB8D6ky9B1T3x3QkjIj3UMnGVw+OccLVTcQI=; b=gXDUez/eWeoXfvtzBxoMFqX6yzChXfTjDT+EJvNOmhXnnvN012eKsotIpflrgQF8Lp 2fyTd8do5aQagZSZ9UACoo1VzNRvUvy51OShxvvsm8sbDywK/VrQvSv+sRssJTGwZVIC O3ehpAZc1poO5bYiy+cj10MKTJW6cZFiOgpPC3NY9qfT+DR6GY8WwwiHc1OHk8IdiUQQ 0ZsriYgMP54GSTwssMvXRD/MDAyF/nV4E+VqHs3oPq/UGb1xuVtyNqZYuiLhpsjiEGIs wnGJGf8nQGo+PvFSaShaFDV7MeHfsOJeL0uf+hxmZhAZVLSptRntOtdojyaNM4xUuxW5 WCcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686271928; x=1688863928; 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=PkmNN9bDB8D6ky9B1T3x3QkjIj3UMnGVw+OccLVTcQI=; b=HvEohrHLx9JyynucQlYyo1VXfSV2UnjdvTpVj6Eo8CzLGE0zGzCU7qJzxZBoOsiRL3 2IcBjjeQ5X7xVPrPWYSne9WGT3lCM1htR/Uxt+8jgGIJ/e4ucmkKiT/QTPKcyrg7gGuQ j+4NHjYf3eFeBL7PX9viqYhUxIsBKzpkPgGwEmR6U5+kUgKT1SAkmdoevfCzMJ/qCIf0 l5FA6vEvonbkw06lkspNg+K1bBK85MSHmRWAnvFb4z8mr0f8Bvwp5PyyRvcz7y5bOZQ9 t4ov8Pc0HGNe3zE7XRsCNk286mdP5pHJ1SY2q6pYvjwvJFgnZDeULavWIRnn0xvwG66d BLXA== X-Gm-Message-State: AC+VfDwVyUOZLLxoa1Z484DT86+F8NAedNCjwJ2AZy4Fci53TBmZ4G5d Xzl3rMO78wt0rvwNn9qXKm/b/GBI5KI= X-Google-Smtp-Source: ACHHUZ5ErqzNYue3IsR81EKLpgdV2ofXzmHeKkote+bFDE5P/CfrHNwNpRNHxN6f/RnaMXvb7Ljn6yc+ads= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:c03e:d3b7:767a:9467]) (user=surenb job=sendgmr) by 2002:a05:6902:691:b0:ba8:1f20:ff4f with SMTP id i17-20020a056902069100b00ba81f20ff4fmr691767ybt.12.1686271927895; Thu, 08 Jun 2023 17:52:07 -0700 (PDT) Date: Thu, 8 Jun 2023 17:51:54 -0700 In-Reply-To: <20230609005158.2421285-1-surenb@google.com> Mime-Version: 1.0 References: <20230609005158.2421285-1-surenb@google.com> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog Message-ID: <20230609005158.2421285-3-surenb@google.com> Subject: [PATCH v2 2/6] mm: handle swap page faults under VMA lock if page is uncontended 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: E210A140008 X-Stat-Signature: 8ieeyno5xnwy38xheafgw87fii1bdc6g X-Rspam-User: X-HE-Tag: 1686271928-353998 X-HE-Meta: U2FsdGVkX19JHult2fvo25IkKHxEHIrgTCxSSaxwTDk1DQH/Ahv4sFfxBMryJevRrtfwO+V9AQzUM7coUGTqLGS0PWAHY8CqNyZSpGGccEct7ZME5hhH47ztEvlSipbyzc3YEfl4EWUoCixO2EsGlj13VBBXIZ/o+4i1IjyuCVhM2mHj6tJyfpspizuKbSIyNJZ5G3l2KrqhvJ4y6sKDBVaA4q2kiSco1ujdqb0Vu0ZErZLm7pFiPN0PQAPlTIpUPJE40O9zQInL9WwAVxtqalh3RzaKhuWBoa0YA7GuW6IkE6qgA5MBVk+jp6nRBaGz4bVmz2f7S2aIwFiS1R24Lv/JNweo+qoewAM+nd+PxLD+7eatS8ngpDddaVvkZ+8FMK2X85lzcFDpe6/vM1CT1NBXE1QjvUvFVb86+HuOI9ifTVdwY87HqMXH4G4Ftu+02VfifKW1veXrjocfSTuG8aZ4TzSc33Av5S2KWGaZ2Kz3/+UeoS+HxIT6YTDBdvn3L3iROI58svVx8JLcwBzc17qIo8Izm5R+fZKoHQPb3YJm0lshxCHc8wgrk4heFOsK0duKMhFFRJmp8wwRQeeFQmkYS/0wXdQCcuWIYJFpoYmqy9ydzu+yaKpjfLzXMme07NiUOxnMANinBczkfUoGPisnLfgexvGI/ouGRBhEkj4/BF86rpDtHszDll0vkoWyGjRT/vXhq12iPocEOL5azAFFMh/jLqrBqLemdcCfzQvFoPTw4jhB/wZpTJRvUC99krYRqRIMYLZajOfJrHhlG/ikxe/8k+qcroKGP8m/Z8yt0VH/M4Sp3zrARwdjRip/r9T9n+FvO/UfYnjxqQY51Yj33NB7ERjUenYtq09BwQ07E1bF8KApfnRE1msFOjK6jdWW9N5bweM7c86vjUBt6zZCo1zXgqKZ+2B/TPoNEhDTlVGM71HXaT6/ts/ZHyJEr2I83I/LGs7XUbGFWiA /SVdvr2F 7BhFylClz8GYBc73iiUrR/mw43lERrpa4EiCXkkTDGuzdYVSZ/WfT7Qtz0oQYpmUd4ofPKvPR5b1pUBUZ/nHYAbeSizDXAw0eUyfbvkM9TgYc8Xj3yc8XSf6ePlNKjjjeZIRvkBH6lJsk4k/FRNrmfMZdXmKxbQQI6piFlDPSAoRziHBcl3p2fFaN38Jf+HpbijjHJdpJ1KQuoXCeey4EU1t/ej6I1kt5pTkmlkVmJeCvbcwxRo0ow8bAFrZXJi9IF39lpDsP14ADhRecDK/z3fqLKIywgISSA0Q8/y5VHDykWuS6gkEJ9S6Vj9EZGw5yL7UTC7vmvjgFA7oCFR2lYWwBOo29c37COqfwCeQizX5D7HZphG78DqIBkt5J223F/ZGKV8DeH21HYDkxVdl5IWdnRQn8F5/d06G7bn54DkRgZxoNKQ1QtdJSpCvyoNFTXOYtLcVFTz5+hMSvTsbP5cnrvFXjcs8wgXdaIvDZ9D44eRdbWbwl5gtHoivPuRILQ7KtzhxlJigk/vsDgVglLoSPJjGw4wKA2sKS/5+oplcsTm9PBsklSDL5asGTUk5TjiQ6Fj4OkxglVnmzryZU+w6dpUq9pQFFKf0pLTV2AAp8k+w= 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 VMA lock protection, all swap page faults are retried with mmap_lock because folio_lock_or_retry implementation has to drop and reacquire mmap_lock if folio could not be immediately locked. Instead of retrying all swapped page faults, retry only when folio locking fails. 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. Drivers implementing ops->migrate_to_ram might still rely on mmap_lock, therefore fall back to mmap_lock in this case. Signed-off-by: Suren Baghdasaryan --- mm/filemap.c | 6 ++++++ mm/memory.c | 14 +++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index b4c9bd368b7e..7cb0a3776a07 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1706,6 +1706,8 @@ static int __folio_lock_async(struct folio *folio, struct wait_page_queue *wait) * 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 flags had FAULT_FLAG_VMA_LOCK set, meaning the operation is performed + * with VMA lock only, the VMA lock is still held. * * If neither ALLOW_RETRY nor KILLABLE are set, will always return true * with the folio locked and the mmap_lock unperturbed. @@ -1713,6 +1715,10 @@ static int __folio_lock_async(struct folio *folio, struct wait_page_queue *wait) bool __folio_lock_or_retry(struct folio *folio, struct mm_struct *mm, unsigned int flags) { + /* Can't do this if not holding mmap_lock */ + if (flags & FAULT_FLAG_VMA_LOCK) + return false; + if (fault_flag_allow_retry_first(flags)) { /* * CAUTION! In this case, mmap_lock is not released diff --git a/mm/memory.c b/mm/memory.c index f69fbc251198..41f45819a923 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3711,11 +3711,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; - goto out; - } - entry = pte_to_swp_entry(vmf->orig_pte); if (unlikely(non_swap_entry(entry))) { if (is_migration_entry(entry)) { @@ -3725,6 +3720,15 @@ 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. + */ + 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 9 00:51: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: 13273054 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 4420DC7EE37 for ; Fri, 9 Jun 2023 00:52:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CD4238E0006; Thu, 8 Jun 2023 20:52:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C5CC08E0001; Thu, 8 Jun 2023 20:52:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AFE208E0006; Thu, 8 Jun 2023 20:52:12 -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 9E80B8E0001 for ; Thu, 8 Jun 2023 20:52:12 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 6DF791A039C for ; Fri, 9 Jun 2023 00:52:12 +0000 (UTC) X-FDA: 80881382904.24.D0672DC Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf11.hostedemail.com (Postfix) with ESMTP id ABB3140006 for ; Fri, 9 Jun 2023 00:52:10 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b="zXF0/SOz"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf11.hostedemail.com: domain of 3uXeCZAYKCNwQSPCL9EMMEJC.AMKJGLSV-KKIT8AI.MPE@flex--surenb.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3uXeCZAYKCNwQSPCL9EMMEJC.AMKJGLSV-KKIT8AI.MPE@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1686271930; 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=JqcDdPqSbAUSGbTjmvLRcpjiA0c+o9DbrViIiTIy+Ug=; b=X0WTjEWZfotkC4LeI2UVij6/bdUqj9QZapEXYjK1g9aBG9M4Zn0TSC5YEEsJBAPrWsKtf+ mDu5wTYznvT5R0gSJCjYEWg9zMR1ibvKhEGPPTlLqm27saPrKga3tZlsALlNf/Ms8T08Ia jWpJgsdO/EZsAUEL7jFrIVjl89HrLLA= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b="zXF0/SOz"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf11.hostedemail.com: domain of 3uXeCZAYKCNwQSPCL9EMMEJC.AMKJGLSV-KKIT8AI.MPE@flex--surenb.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3uXeCZAYKCNwQSPCL9EMMEJC.AMKJGLSV-KKIT8AI.MPE@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1686271930; a=rsa-sha256; cv=none; b=Om+fDMwINPEZFHghE4LpAqE+EAmEZa5k8+baKUecDAOX3upNs1gNEfVbv4HI5um168ridA qwHc33vTOnZViLCPqyVM+e6Lfi/vuoUzKojZlVzceVBFrYN1hiiTMENuQ4rfZ1psoicv66 CHnfZhdDfhPseoUAYS4kHR0kMG2WqC8= Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-ba8338f20bdso1718291276.0 for ; Thu, 08 Jun 2023 17:52:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1686271930; x=1688863930; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=JqcDdPqSbAUSGbTjmvLRcpjiA0c+o9DbrViIiTIy+Ug=; b=zXF0/SOz02AqM5BWf2P/zwcWEHhQEqJOZyXi3UZpbx8VPRWxCUcaRMvo1gco/xsra2 1KRka8Fv7Cz5TdkzcXaQgC6O85k85tL3gyx/iy3cDrh6mP1AOUruXIGz0ftmdJxZ1KRm ZZx2kRtlsPb6qeLOZNriXbpH5lr8UltQBDA01BaTWp8gpunXX21xn4/zrUa5rAnUvMfl mCkY25J/3lnSqtjOJla8DOtGiyoeA+L2vJd0IiqnWI7c7ZShrlyswyCHOWMMkPwl9HjW QFj7gjWymWSTqWnDk2iKhq+C7yb+32Ze1ontuD7AeEZ5CFFfLh23UfHmunZhj1vbgoCU wHiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686271930; x=1688863930; 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=JqcDdPqSbAUSGbTjmvLRcpjiA0c+o9DbrViIiTIy+Ug=; b=aY0Ax0Hs6Hzt9nOhrTMh/nYKtKIntroeP+Y4Tgf3R+/oXlrAedlQCT3zqmdZurtwRn y1hqbC5eRi0oty5eAq6bKYf/JwsqO2J2VosQQnBSqkOKrr87YP3ZEt94F1L+JlfxPdcY wR41qCMGq1NpW87Fc/rAJIAtxp5Qoxcx2zFsntFO2MJ9UIAP2t+6ywlBsuTwazWVmQKT vLbZ6SU38kaapQHFVdlyISV1XhRhttG5aU0CTUFB/A4UZBEIFCPzPV072Qlg2UlvXhqA R5kdSAmnnB+7FiXUfwC3e3w7jCO2XwAWViwnfWf+jHkjAlHkYcVPkDzZyLy50+d2qS/a UJrA== X-Gm-Message-State: AC+VfDymqHrfMZUfeOu5O16NXyTMKiKGXdwjt3rI3T0S6YDMrK7gGoF0 rhJj4pBN7FldSOowDiDq3Su/jnnMmUQ= X-Google-Smtp-Source: ACHHUZ5YbGKMEwsx1wWALVdFMCpP8nhO2N5qAulNG9AhZTP2wq6KaJAphozg0TQUY00Q3mKklpdD+wtUbrM= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:c03e:d3b7:767a:9467]) (user=surenb job=sendgmr) by 2002:a25:db09:0:b0:bb1:5962:6fde with SMTP id g9-20020a25db09000000b00bb159626fdemr677035ybf.13.1686271929776; Thu, 08 Jun 2023 17:52:09 -0700 (PDT) Date: Thu, 8 Jun 2023 17:51:55 -0700 In-Reply-To: <20230609005158.2421285-1-surenb@google.com> Mime-Version: 1.0 References: <20230609005158.2421285-1-surenb@google.com> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog Message-ID: <20230609005158.2421285-4-surenb@google.com> Subject: [PATCH v2 3/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-Rspamd-Queue-Id: ABB3140006 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: cnheaxt8o4j3h89gu4n75ihq6r5egoyk X-HE-Tag: 1686271930-845897 X-HE-Meta: U2FsdGVkX1/UHzUrLi1xHxvn5uiv0LQknoGkgOLoey5eUEdA3B58Ojm90f++J4pjvfr9mMed494Qc0oAubBa/jcINFtZewg14UIfYOdJMpcBTe/CDnf3JDnf/JwHbUhnB3vDqeiF63t20tuvn91pReDArkavo9oxqlAs8U2HZy88ZnUoGINT68C6xEQVQ3zZA9tHhwIsaIQGLbfAqWXkz83WCMpN4pjM5jes2UbYCvmg56uKBdzJnFWGmxjh3Y0XOjtxhi82CSab9i67G/jdRZXcxsqPx4MaqnH57LyXwpimJqQlGr3lhRvpzm/QuaVPPcse9+V1zA2RoXykNn53pM1huO1NDSUFFOiC7m6qeb+Bmap0odGLMNlWRRUMzLf723jJC7TPgzoWRCR1hIihh+kOowyaeDBXSSw4sxMvvf1ATc2gt9Rf9gUzcLEorY7+OEI6nvhkFmRKb/vPG0zqtxy02F+2GjId3SOCqaZafTANZUvIW5kNIniMtsi+seMCMKNjxX+jkyN0RYU8ys7wC+srhWbJlDRlOqE2pwPyu4ImlgU0FzXZBARKXKx+AcvoxILbMfhWturUPzmsHmpw7ET7bR7ADNBAJ6fifaFpShPNDG88ADzva856B3G8RiT8mDu/XpjO8TTTbNjphO3Qmlanl8LgpTovA9/lr+zEbV7GAMRVi+G8HbmbkqsirqksTyklkjTm9BXujI35IFcw0cm9ehU3sd13W5WKqE9GovkdwMVocSNozT3hegrjv91sB3EDf56f4DYe7KZzEYE/KMNfb3Yfq2KEV4VeieCh0j/WDpyym90+9giwd6xv+tZE16dB2RO+HjxlSKoz75S7N0s8wpd+8lQL/MNlbXqNFVbDor5GA75nnT1aSo/s5lYaIAiyiS09IimY/8WZdcpRE6fNSDvADtPDijfvXtJRBaEQ2fj0KbPS4VRn9zrE5J/mRj/296QVIMLEt/WtHVR DcL/12Ff hJ2eDSM1R6WNUbBuBFhlxK0ZzTn84t2JcvCWm31knNt//mOqWVWtDY3qZmsLwsQmRsQsg7IoJ/TiHOPWc0K/dMcrLZfi9bflETqBnHGYO5uwxTNcMtwJfHIJmc2o+C00nBtxnEyR2Nt5FT3/Mdx541WmQ2bFnPJxhjbvhlJQPTv8euY96MP8Bf/fnLpKhD1gs/Bv7gP13MC19P4uf2w30u4H4h2XnnqUZlpAx8zmVOx6d2YrCbu2rA0KLpVVMMuLxrC5fkm6AJmaHd2BoGSS49630dDf6ztdAYRN2ATdIijuwEl0MZU0nMQ8ktQKoLA8pEqZXy6CMj+STWkP2t9jWYEof7R/EfnskvPjHRCf+7BywTLEeE5m7hYtLCPu12aRqzYwq50QpFpfES6PA7mHdSoas1wor2GqAxuq/6mWdSR25T1giHgwtGp++ejGsnC3LgJY1srs5sSCtBDxGa1YdK6bbwS8MtHSa6XOhHlzMsFEiK3QAbHwdipwIFmx4f/JhHRFOtnEfeE6YvTf5bS7pizXXssnHiVH2tfdmZAqxsBSZe8fApi/y8qy6NM98g2kkFahvzMkGSw2Jz2ciR7pC2HVJsudrol7athoWj/upghHTLvTEKMtyhnuU8Aov52PeXWMORrsjDXZxpa7RWAmIxTdvbw== 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 306a3d1a0fa6..79765e3dd8f3 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -1070,7 +1070,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 9 00:51: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: 13273055 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 1FD78C87FE2 for ; Fri, 9 Jun 2023 00:52:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AFE6E8E0007; Thu, 8 Jun 2023 20:52:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AD5AD8E0001; Thu, 8 Jun 2023 20:52:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9768C8E0007; Thu, 8 Jun 2023 20:52:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 89B1D8E0001 for ; Thu, 8 Jun 2023 20:52:15 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 4BB011402F6 for ; Fri, 9 Jun 2023 00:52:15 +0000 (UTC) X-FDA: 80881383030.07.7F5101A Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) by imf14.hostedemail.com (Postfix) with ESMTP id 81FE6100011 for ; Fri, 9 Jun 2023 00:52:13 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=aoHc7JPC; spf=pass (imf14.hostedemail.com: domain of 3vHeCZAYKCN8TVSFOCHPPHMF.DPNMJOVY-NNLWBDL.PSH@flex--surenb.bounces.google.com designates 209.85.215.202 as permitted sender) smtp.mailfrom=3vHeCZAYKCN8TVSFOCHPPHMF.DPNMJOVY-NNLWBDL.PSH@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1686271933; a=rsa-sha256; cv=none; b=blGjjgLtRUq+YOxfxWL4mSdTfN2o89cYJp2b7fCH8ozqIkucYzlonqO6wo9nIXKSKIM2K1 28tXS7GSrLuwV5CWKj7DqgqBGxT9RcPHdr5SVdiH0JXq1ZX8FwMRos3wVTOOEA+s+Vxo07 1OVmcnPo/iotM+omuf8ieqoI+qIW+4U= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=aoHc7JPC; spf=pass (imf14.hostedemail.com: domain of 3vHeCZAYKCN8TVSFOCHPPHMF.DPNMJOVY-NNLWBDL.PSH@flex--surenb.bounces.google.com designates 209.85.215.202 as permitted sender) smtp.mailfrom=3vHeCZAYKCN8TVSFOCHPPHMF.DPNMJOVY-NNLWBDL.PSH@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=1686271933; 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=uuo3Il/2NbgOWAM0rjqTihVZSZhUnoZMQ/ESG1PbGOc=; b=fTrTpdOIAUz5eQOI26khEJ964Cevzie5ge847SwH1I/Ka5F/yDjnC9OPONrkaxWlBio+ib yUNcKFnAHw1D/LaESg8X2ceyV27s9VDGSP/V/C5ekSp1MEiptLSEwJe2mcfTd2TkXFwdsC H5pCxAWNqG99xOeVT3qhFiuTZ4ss64k= Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-53f44c25595so208624a12.2 for ; Thu, 08 Jun 2023 17:52:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1686271932; x=1688863932; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=uuo3Il/2NbgOWAM0rjqTihVZSZhUnoZMQ/ESG1PbGOc=; b=aoHc7JPCZ32CAYt9q46WDYGEOxxS+8Zg8n+MkQ8tBFVy2AxaNM8+3Gds918auhPTHa q1i93JJIOBjYqWdat77Bw43ovYfILELgsQ3A15M4ncn74YtVwsuP81alu9yqHz/6QEf4 0ZCIwnE+WqrId9F8Np2B9UzySwNVPcW9qaPUxrGBEsK8nkCGUUE7v/JS22HdzPoOb4MB Chi4Dc24/vK44G+H3O7mb/dNtV3gVAS4dKZye3QS8d/JCKeQ8FR8f6Rt4chkxNrZVvil NBHO4/LslE98QkZt8lZcAJ+QXDZaDtGSI1vY2Loous6hPUzUbnAktXCDF6R5gPFfIwoD hcMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686271932; x=1688863932; 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=uuo3Il/2NbgOWAM0rjqTihVZSZhUnoZMQ/ESG1PbGOc=; b=lKckqhEHfGuUY4MbWFmsQ9EQzMcjl1omknWL2nMgQeTXWIde0bzaa9rkfsHJHL+pZu ARhF5JAEmhU2dwm76L7aeQJTME/0zuFayq9PB27XH7gYsGydPyTcgOwvuX/Ir4a/epd8 utCMUCR0Yb5m/APm7LrYERZTnHdkL7B1yhOluCiRzI8+28KEgY6eDNHxg+6+IrGvxIpi W24pY9wNU7wzJ5krTTFImDAP5Ngwm9KjPWiIfwfxT4MkedNOfIAGDUTF7R3wi0oRw2bC qWi+7uUyEitCxkbhQNUvNvMzWcdTSODtJKr1qW6iCIXxGdPl4FghRlAb0zfFm9TZToGu 5RYg== X-Gm-Message-State: AC+VfDylJubj8XEPayzAzGPXxmURbfXuZdnrgpImsDR9hWdZLO6aA1jy R+00ploASQppkzAqEQ5c1YiZ6HOafcU= X-Google-Smtp-Source: ACHHUZ6b1B6MYsfuF9F0w1PhABF3eJ3XJNF2fY5wRRyw5gd4GldbBtWiJ9mZhA7X4yciara2bOj4oc1yZEs= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:c03e:d3b7:767a:9467]) (user=surenb job=sendgmr) by 2002:a63:d44:0:b0:503:77c9:45aa with SMTP id 4-20020a630d44000000b0050377c945aamr225410pgn.9.1686271932107; Thu, 08 Jun 2023 17:52:12 -0700 (PDT) Date: Thu, 8 Jun 2023 17:51:56 -0700 In-Reply-To: <20230609005158.2421285-1-surenb@google.com> Mime-Version: 1.0 References: <20230609005158.2421285-1-surenb@google.com> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog Message-ID: <20230609005158.2421285-5-surenb@google.com> Subject: [PATCH v2 4/6] mm: drop VMA lock before waiting for migration 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: 81FE6100011 X-Stat-Signature: edkwpjobrz56g66f9k9q93t3snzijewm X-Rspam-User: X-HE-Tag: 1686271933-903926 X-HE-Meta: U2FsdGVkX18zK3gH07r4M7AlqWjFj2Xxudea7BEnjv3FFWnbqhBojtugxuU/AyCQHtS30qshnG7V1Ap9mH+LDPJKZ1EHRkGS+W9jVmGahGvAACpNkRvYcMYa0iiYqlimgvjXPytPitIvZj5DD6PUvblwTjEiusyli8U2jfy3b/H5N10fg62/a18e7Sft9RP08GwJQCbEz7oe8Wc4QpDDVfPi83JJHEtyQWbWB9EnORIqEKHvCwIGDD7e7tUEfDNqbRep3amIqwl8gvg9BWUIYtfa+k/kgxSOp7HXwK8Khp+5K6/JXShSCslRlkV9TPhm9stCi1jb+VHiuZLLOzThooeln2ZMeurEQ0UN0MsFS7oen7oeAy97gd0uwh6dRd8oM5zeMj5cmdEQVZ59HchSu7jzDKSZMp8r78uUayWto4FUXYERWCmtUon0R5EGlowg2mtShWV7+/1qfiVB6+Hg1Slnj9AngFG2iTYA8eKri0FYs6BD0rMaKx4B43m9k/h1nud5VjYeFn/dtxC5bn5V+CoTU2Fyzv+5oACp/ATo1nOBpjDkWrD9pfn+uMhd4NqmlyxiUL+HUsuBjPi/sst1sSZH5oklNb1ebSa/12aVEXkSWr7BlWq167FkYs580IdFMQ+7yhEvzjfFdNPd33VZrWYJPFah9N+KYlMG9u/gu7MVPILMz9YXDSPqVYW4bsW3tiTSWcX+ODDCTKl6kg8E0do4S9cp5M/JG5yaD8tsu9Xhoco5xCGlUrhPtWGJYyStf4p2dsse7oonAWFVM5643Omkt3IasGQ/3OByJL/PoAKF8Pifj6bVCerXZxuEJiOvsHewF5KNtGHS5+Ciav7Ml/DDxDdnPdlGUXwf9iZxLrmnV5ZhONgrD9Vsb5YZYVnmhHyqFcWU7CfVKwWq9tTPqvL7AyIdw66L/BiB1RUeky9kBD4HTWbHT5gyDvm+Q6qMUWupwrAyQ/XEcFsdIiy ce8cJMR7 75kaD5fnuMf4UFZqSmZzP98StI3BOYB10fDrDbpimTocND9hah1DxgwRu5LarwrE6l0CptWDloc69eJjMcV1dPTDa1KrL7Aw8FWxNF2RvB3NjA0OSI1ykGKE2GMy1iyvYBMQBpMSEpnGpQMDrOpWfsopCBXUQrXz082c0oqn7JTzQ4cvHEE+gCp+DS4yibRAPg5xucdeqvigtE/Qz8Pb9bg0lWeHq/fokB5PCB2mrxx8k6cy268OVLnbvUrceKfFBF6m/moLyQwlD4kKDgSRM37ysT+cwriWuR98ogwaoLAPSKAA1LXDKy3M8UG2tyXZr82oIl94lwMAq9WHCihoJf5cRH4PcGF+Ire5pwiaFlxGjzHqqPFmeaNjDMlHgck2maGNFwPLIGmXh+4jeXvNXDlgyc5wb79nL62F/RgngS3aRqSsszNLldYKY67SXKBY9MJggjKpN6vE8dMNQyZgbEEG4iYprdSI8uDqpGB7okWFS8j307UJSzfGq6WaEvj74RBRc0XVaxIXUtbPZ/vX7ud3It9tVmjKCQ1VZaG2Af8khVngWtHM1c68teP3TtaMv+snxeQIvvbDkj1wW4lHZLzlrO2wO+XoOro2iu13h67WOAsk= 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: migration_entry_wait does not need VMA lock, therefore it can be dropped before waiting. Introduce VM_FAULT_VMA_UNLOCKED to indicate that VMA lock was dropped while in handle_mm_fault(). Note that once VMA lock is dropped, the VMA reference can't be used as there are no guarantees it was not freed. Signed-off-by: Suren Baghdasaryan --- arch/arm64/mm/fault.c | 3 ++- arch/powerpc/mm/fault.c | 3 ++- arch/s390/mm/fault.c | 3 ++- arch/x86/mm/fault.c | 3 ++- include/linux/mm_types.h | 6 +++++- mm/memory.c | 12 ++++++++++-- 6 files changed, 23 insertions(+), 7 deletions(-) diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c index 6045a5117ac1..8f59badbffb5 100644 --- a/arch/arm64/mm/fault.c +++ b/arch/arm64/mm/fault.c @@ -601,7 +601,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_VMA_UNLOCKED)) + 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 531177a4ee08..b27730f07141 100644 --- a/arch/powerpc/mm/fault.c +++ b/arch/powerpc/mm/fault.c @@ -494,7 +494,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_VMA_UNLOCKED)) + 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 b65144c392b0..cc923dbb0821 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_VMA_UNLOCKED)) + 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 e4399983c50c..ef62ab2fd211 100644 --- a/arch/x86/mm/fault.c +++ b/arch/x86/mm/fault.c @@ -1347,7 +1347,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_VMA_UNLOCKED)) + vma_end_read(vma); if (!(fault & VM_FAULT_RETRY)) { count_vm_vma_lock_event(VMA_LOCK_SUCCESS); diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 79765e3dd8f3..bd6b95c82f7a 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -1030,6 +1030,8 @@ typedef __bitwise unsigned int vm_fault_t; * fsync() to complete (for synchronous page faults * in DAX) * @VM_FAULT_COMPLETED: ->fault completed, meanwhile mmap lock released + * @VM_FAULT_VMA_UNLOCKED: VMA lock was released, vmf->vma should no longer + * be accessed * @VM_FAULT_HINDEX_MASK: mask HINDEX value * */ @@ -1047,6 +1049,7 @@ enum vm_fault_reason { VM_FAULT_DONE_COW = (__force vm_fault_t)0x001000, VM_FAULT_NEEDDSYNC = (__force vm_fault_t)0x002000, VM_FAULT_COMPLETED = (__force vm_fault_t)0x004000, + VM_FAULT_VMA_UNLOCKED = (__force vm_fault_t)0x008000, VM_FAULT_HINDEX_MASK = (__force vm_fault_t)0x0f0000, }; @@ -1071,7 +1074,8 @@ enum vm_fault_reason { { VM_FAULT_FALLBACK, "FALLBACK" }, \ { VM_FAULT_DONE_COW, "DONE_COW" }, \ { VM_FAULT_NEEDDSYNC, "NEEDDSYNC" }, \ - { VM_FAULT_COMPLETED, "COMPLETED" } + { VM_FAULT_COMPLETED, "COMPLETED" }, \ + { VM_FAULT_VMA_UNLOCKED, "VMA_UNLOCKED" } struct vm_special_mapping { const char *name; /* The name, e.g. "[vdso]". */ diff --git a/mm/memory.c b/mm/memory.c index 41f45819a923..c234f8085f1e 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3714,8 +3714,16 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) entry = pte_to_swp_entry(vmf->orig_pte); if (unlikely(non_swap_entry(entry))) { if (is_migration_entry(entry)) { - migration_entry_wait(vma->vm_mm, vmf->pmd, - vmf->address); + /* Save mm in case VMA lock is dropped */ + struct mm_struct *mm = vma->vm_mm; + + if (vmf->flags & FAULT_FLAG_VMA_LOCK) { + /* No need to hold VMA lock for migration */ + vma_end_read(vma); + /* WARNING: VMA can't be used after this */ + ret |= VM_FAULT_VMA_UNLOCKED; + } + migration_entry_wait(mm, vmf->pmd, vmf->address); } else if (is_device_exclusive_entry(entry)) { vmf->page = pfn_swap_entry_to_page(entry); ret = remove_device_exclusive_entry(vmf); From patchwork Fri Jun 9 00:51: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: 13273056 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 E34A1C83003 for ; Fri, 9 Jun 2023 00:52:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 692C48E0008; Thu, 8 Jun 2023 20:52:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 61B228E0001; Thu, 8 Jun 2023 20:52:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 446E58E0008; Thu, 8 Jun 2023 20:52:17 -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 31C168E0001 for ; Thu, 8 Jun 2023 20:52:17 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 0660812028D for ; Fri, 9 Jun 2023 00:52:17 +0000 (UTC) X-FDA: 80881383114.30.C090F0C Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf05.hostedemail.com (Postfix) with ESMTP id 4CB0D100005 for ; Fri, 9 Jun 2023 00:52:15 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=oVug16yE; spf=pass (imf05.hostedemail.com: domain of 3vneCZAYKCOEVXUHQEJRRJOH.FRPOLQXa-PPNYDFN.RUJ@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3vneCZAYKCOEVXUHQEJRRJOH.FRPOLQXa-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=1686271935; 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=yDKE+Wkkd9TQZuY1u1+D5VbBuChdz1DMs8UdXXj0e2g=; b=j2CLl1izsm5OxepBPW1b9Q+KsuCpsdybshP4JP29wZi9Jp2vqaFbnDYfYHHlCgPtx6b+Gf /pKLcrYriBRybhKnwVihRhTRV0GvGmBYM6mhrq3KOhef8/HVP9CFmOpV/fVW7VtF6Ef4YY Z05ZEE4kiE8rdWeWDvrCs2w6tzjJpnQ= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=oVug16yE; spf=pass (imf05.hostedemail.com: domain of 3vneCZAYKCOEVXUHQEJRRJOH.FRPOLQXa-PPNYDFN.RUJ@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3vneCZAYKCOEVXUHQEJRRJOH.FRPOLQXa-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=1686271935; a=rsa-sha256; cv=none; b=hGHmRJ1EnSrSGchXLafaVIbkgG87HcCJ57RmZ1vUMq060hephndX4MvE8dC7npWWgOSNLv 8Wj+qvTsz+o6BHk9PToS5DcoAP2THIrZnl+IXmAZpQ8yecc43e4RQ9oPuF+uIk0yn29PS4 MyGjP/E5q54IWYAsgzGNQvY10AbaagM= Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-bb3855c34deso1716323276.2 for ; Thu, 08 Jun 2023 17:52:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1686271934; x=1688863934; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=yDKE+Wkkd9TQZuY1u1+D5VbBuChdz1DMs8UdXXj0e2g=; b=oVug16yEjdlnNEpZ7pnd5qNolPTgsrM9t75qLEfhGOZfvwQQTTtBUSAfR3QIEEr+oC v/fzE6FqQXocpbRK9V3XWMbF2lwE13bpKfYmrqjm6uNGGYsi/lgDYeC/9YEof7hp5FqS 5A0uKzNV8LOj4fKrnAEEjVJwZBkiAOghnhCcJkEwlpwZR4xAR7bH/08Zl/fuOCMap4kM hmRM8jBS/+AwHvOnOyZBcktaKtQpOMW1qGAdckEP5f61vXaEekTcAIlIX8pWgUawmGin 2woY8gWii5fyujAxxvv+l/JMuwNA3M044wzqA3CPsKBvTCAFqHIUtCTz2+/Qo24VtWBB JIiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686271934; x=1688863934; 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=yDKE+Wkkd9TQZuY1u1+D5VbBuChdz1DMs8UdXXj0e2g=; b=CqVCuRBKZ5DR1hhpJfQKxaLNUrnxdbQGqsJqSw6t/4RsckjvN4cSGUZhFN24GQtilf 2G2ifWOrIEomb+nyr9jBU5X9p7XtoGbwGJGmZBeEuhF02BwQ1kDdfQW/QWPqqkeHXLvY 8PAhbakMxVdvpZu8gnHa1ZEJqDVeWwjMeCqVqZ7rfBpzTFOiMcibhKHn7pp8rHn4xaIy nO7mPY3Ls96KeLNULHMsY87/VC4u3eEhqpV4Q7u6U9Hu1Cj9mdiMjQt6e30nQai96u6r fDCVlBGLZ8ZoKbUiblF6L9dyboF4Dh3DgfewtlFVC1V/9NNNu0SloG3XHmdYij/8P47Y sl7w== X-Gm-Message-State: AC+VfDxyEwQFLxHIQG+3Oqd57GP5qlPWvTLQDQGcb8bpM6YrtcR0Icj8 TCOTrQgxWClE4IXSc5RWEgS5mTuMoxI= X-Google-Smtp-Source: ACHHUZ6qGzpVQ3JwgFBzFsFEN7W5Nqjbd5tmkwDtF5dFLLF9fdY1OW4nuRJzWHLumkRKhGTOuLgN6g2TsCw= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:c03e:d3b7:767a:9467]) (user=surenb job=sendgmr) by 2002:a25:3216:0:b0:bb3:ac6a:6d61 with SMTP id y22-20020a253216000000b00bb3ac6a6d61mr657350yby.3.1686271934456; Thu, 08 Jun 2023 17:52:14 -0700 (PDT) Date: Thu, 8 Jun 2023 17:51:57 -0700 In-Reply-To: <20230609005158.2421285-1-surenb@google.com> Mime-Version: 1.0 References: <20230609005158.2421285-1-surenb@google.com> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog Message-ID: <20230609005158.2421285-6-surenb@google.com> Subject: [PATCH v2 5/6] mm: implement folio wait 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: 4CB0D100005 X-Rspam-User: X-Stat-Signature: uu4r514e7axru39zmtsoki9rxyzbckfn X-Rspamd-Server: rspam01 X-HE-Tag: 1686271935-446808 X-HE-Meta: U2FsdGVkX19ntqLCk2rBm2+qvvhKayAuULTQr70IO6nNo2+e15o1VK0IugjEGQ8UNYcY8MrAHU+5GwFy9C889wjwtBRZ3L6Oz0XcqGbqMROrHCRs+0162SskNfKsB24FYoBmif/K0AsXKpgvNhQ4bRzOyhO0LOGLcavKtj2HYdCzq27E2JKQjUCF5iwJWVaYIWcNj3T/+3j8G8H+cXg9SRxkJAbpzU1l6j5Y7bcJjT5/+PAZP1u2GhCHY+NB/Gt49M1bOzDlaRJ9WEoFo4b/m0498ZeROUo6HRZum+t5mmX6vx4sf4NWcz7wByi/YVCJBURhDb0EzndasssXpbcw1RTcfS1NdRit+ZlYskkO17+q8xodm2a4zkOoJn1duP66kgB/l9nGMDovYRb8BaZbXvteC+2NLEWYVkZy93hirf7WGQaPeFmrK7YsB2++1dqqpm0esbIRjOC1bbA9hZoPX61izq63QPlG6yxUmX7Kkurq9GTpSWzeypWRP5Ygmmmy6hg1VA/2BbKLRJ/jrQmeBe1Mhog6URuWowBaWd/b5Xh6ZosBNewv5rkq4MTpe2r6TuQmpN03cbUQ5ATkv6+vcwD4XBqrJdUFJIXauZzbbGZXPZbJikTw7VOaM7/5ZUpikBWmEd9n2+Ln0HEa+JydYMAWvu+kNxS1HO9dg/wYTVi3wcOiLZLgBbgqWVujiMq7agSwcifFG5G1Qx+L0l08kQIZA+g3S53mDTALGS/EaM8783G6zZP2MJdvx3vODeShM5OE7UifaN4lQp8e67Ku5g+VFIYysyX2ARetCgufVRZrUGZHKqL+CXGNH7a+RH2MGX7iojl7MJqZ6dcmTf/WVDw/3B1pxglDVHzyAHjauzrw1m9bmci9oSzhsvz1Zg/ifwPrqXIAm5xYFZpXjTIk1chcbXhOTdc4qTKOX9Ngy5TvSf6JK2zYs1BEZPJd8ONRlEznqTIhDMY9Z9/zeIA u0SMrmGp G8WkXbz024vphOMpsavTgIUjMQaxge9R27dyvGcQdsjZ/ojf9Po0TbMapB6AYwK3pdp9buhzZPVPlfuZawR16R/V0S/aQG8k4/8dgbByg2aB84gxJfDNKIfxVDO9SzHuNhf71Fb2CRw7sPT0HfGMG6j1u18bBjcuRiL8hKy6L84XOEukgbmjL1dzOngFbQo9powGgy7R1kqOCnU3XsnUCwhWB5jZdZNm4LyK5SzVZLcjZYIOj2vYxsVUTeG22pMOnNUfehus98Ee3dGhIyvO3FfkmqZ+SoA6vxmehf+Jeo23KPUOFHwAXHos4lzOz4BGNFE1P6nTBh5LJufc81hW+Dc4S1TuN3iuI+USGY28Mf7tVxH6EoEjhwqigljOh7T697J/8wwbHjNTw+cyhzHSMyWejWL4qhyW42v001v5c4WsolAmBNy0wAYMqbGvgTEtloQ9hzvPIHl1lylvSX2WvTkEziuqGBou+AQdxzUvHxCEadexJSAWUW1c/S+l1oz/npa8Lo2q5pLa1OBVVaKeTRVgROdF6hSE1EyG7mYr+2r0CF5BHpvsnT8NxY0T6sA8ovLGpo/FQytW+fJ1fDrgXb6J/CRMAVRwpZC5SpwdSH0f/QEs= 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: Follow the same pattern as mmap_lock when waiting for folio by dropping VMA lock before the wait and retrying once folio is available. Signed-off-by: Suren Baghdasaryan --- include/linux/pagemap.h | 14 ++++++++++---- mm/filemap.c | 43 ++++++++++++++++++++++------------------- mm/memory.c | 13 ++++++++----- 3 files changed, 41 insertions(+), 29 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index a56308a9d1a4..6c9493314c21 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -896,8 +896,8 @@ 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); +bool __folio_lock_or_retry(struct folio *folio, struct vm_area_struct *vma, + unsigned int flags, bool *lock_dropped); void unlock_page(struct page *page); void folio_unlock(struct folio *folio); @@ -1002,10 +1002,16 @@ static inline int folio_lock_killable(struct folio *folio) * __folio_lock_or_retry(). */ static inline bool folio_lock_or_retry(struct folio *folio, - struct mm_struct *mm, unsigned int flags) + struct vm_area_struct *vma, unsigned int flags, + bool *lock_dropped) { might_sleep(); - return folio_trylock(folio) || __folio_lock_or_retry(folio, mm, flags); + if (folio_trylock(folio)) { + *lock_dropped = false; + return true; + } + + return __folio_lock_or_retry(folio, vma, flags, lock_dropped); } /* diff --git a/mm/filemap.c b/mm/filemap.c index 7cb0a3776a07..838955635fbc 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1701,37 +1701,35 @@ static int __folio_lock_async(struct folio *folio, struct wait_page_queue *wait) /* * Return values: - * true - folio is locked; mmap_lock is still held. + * true - folio is locked. * false - 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 flags had FAULT_FLAG_VMA_LOCK set, meaning the operation is performed - * with VMA lock only, the VMA lock is still held. + * + * lock_dropped indicates whether mmap_lock/VMA lock got dropped. + * mmap_lock/VMA lock is dropped when function fails to lock the folio, + * unless flags had both FAULT_FLAG_ALLOW_RETRY and FAULT_FLAG_RETRY_NOWAIT + * set, in which case mmap_lock/VMA lock is still held. * * If neither ALLOW_RETRY nor KILLABLE are set, will always return true - * with the folio locked and the mmap_lock unperturbed. + * with the folio locked and the mmap_lock/VMA lock unperturbed. */ -bool __folio_lock_or_retry(struct folio *folio, struct mm_struct *mm, - unsigned int flags) +bool __folio_lock_or_retry(struct folio *folio, struct vm_area_struct *vma, + unsigned int flags, bool *lock_dropped) { - /* Can't do this if not holding mmap_lock */ - if (flags & FAULT_FLAG_VMA_LOCK) - return false; - if (fault_flag_allow_retry_first(flags)) { - /* - * CAUTION! In this case, mmap_lock is not released - * even though return 0. - */ - if (flags & FAULT_FLAG_RETRY_NOWAIT) + if (flags & FAULT_FLAG_RETRY_NOWAIT) { + *lock_dropped = false; return false; + } - mmap_read_unlock(mm); + if (flags & FAULT_FLAG_VMA_LOCK) + vma_end_read(vma); + else + mmap_read_unlock(vma->vm_mm); if (flags & FAULT_FLAG_KILLABLE) folio_wait_locked_killable(folio); else folio_wait_locked(folio); + *lock_dropped = true; return false; } if (flags & FAULT_FLAG_KILLABLE) { @@ -1739,13 +1737,18 @@ bool __folio_lock_or_retry(struct folio *folio, struct mm_struct *mm, ret = __folio_lock_killable(folio); if (ret) { - mmap_read_unlock(mm); + if (flags & FAULT_FLAG_VMA_LOCK) + vma_end_read(vma); + else + mmap_read_unlock(vma->vm_mm); + *lock_dropped = true; return false; } } else { __folio_lock(folio); } + *lock_dropped = false; return true; } diff --git a/mm/memory.c b/mm/memory.c index c234f8085f1e..acb09a3aad53 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3568,6 +3568,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; + bool lock_dropped; /* * We need a reference to lock the folio because we don't hold @@ -3580,8 +3581,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)) { + if (!folio_lock_or_retry(folio, vma, vmf->flags, &lock_dropped)) { folio_put(folio); + if (lock_dropped && vmf->flags & FAULT_FLAG_VMA_LOCK) + return VM_FAULT_VMA_UNLOCKED | VM_FAULT_RETRY; return VM_FAULT_RETRY; } mmu_notifier_range_init_owner(&range, MMU_NOTIFY_EXCLUSIVE, 0, @@ -3704,7 +3707,7 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) bool exclusive = false; swp_entry_t entry; pte_t pte; - int locked; + bool lock_dropped; vm_fault_t ret = 0; void *shadow = NULL; @@ -3837,9 +3840,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) { + if (!folio_lock_or_retry(folio, vma, vmf->flags, &lock_dropped)) { + if (lock_dropped && vmf->flags & FAULT_FLAG_VMA_LOCK) + ret |= VM_FAULT_VMA_UNLOCKED; ret |= VM_FAULT_RETRY; goto out_release; } From patchwork Fri Jun 9 00:51:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13273057 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 96244C7EE29 for ; Fri, 9 Jun 2023 00:52:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 051BF8E0009; Thu, 8 Jun 2023 20:52:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F1BE28E0001; Thu, 8 Jun 2023 20:52:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D47638E0009; Thu, 8 Jun 2023 20:52:19 -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 C0DB78E0001 for ; Thu, 8 Jun 2023 20:52:19 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 8DEA81C7863 for ; Fri, 9 Jun 2023 00:52:19 +0000 (UTC) X-FDA: 80881383198.17.EF9BCA5 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf13.hostedemail.com (Postfix) with ESMTP id D5D2120011 for ; Fri, 9 Jun 2023 00:52:17 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=4hO9nbpC; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf13.hostedemail.com: domain of 3wHeCZAYKCOMXZWJSGLTTLQJ.HTRQNSZc-RRPaFHP.TWL@flex--surenb.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3wHeCZAYKCOMXZWJSGLTTLQJ.HTRQNSZc-RRPaFHP.TWL@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1686271937; 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=R1WyFySTZ0XkKYIf3B7+wOl2DNVNhKC+z/byy1yFxnw=; b=6QcpH+0XMrN2epEIHQxOtLW3+j+Pv2KcziP0UouRt8pWx7rMlzSJBd+rK0yk8CUpOF72Wf yIvroIGXu8MuJT6RhcQOhGkFz7AKP/urOdaoIvgeSWJjTPCISgLZIOHKslvNi9dYQRpTAe QkS5vuDlR7RgLqyktGxuZoGXZ513GBA= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=4hO9nbpC; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf13.hostedemail.com: domain of 3wHeCZAYKCOMXZWJSGLTTLQJ.HTRQNSZc-RRPaFHP.TWL@flex--surenb.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3wHeCZAYKCOMXZWJSGLTTLQJ.HTRQNSZc-RRPaFHP.TWL@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1686271937; a=rsa-sha256; cv=none; b=7OfDq5pQbgkuzKmiveZIqm02JWlg+gjbYmwvVRi4oDCZqh6mELlUuol3Hm8oqjBX1AcbxF MYWMJuRqBcvST7z8UK2qyn90WmwgMPEDpEVrB5ed+t+c/vgF28fdTgslau5zSf8mPHuLxb EGp1+/LNEjfrnN5olUt4PunODsvQTFw= Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-bb39aebdd87so2696854276.0 for ; Thu, 08 Jun 2023 17:52:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1686271937; x=1688863937; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=R1WyFySTZ0XkKYIf3B7+wOl2DNVNhKC+z/byy1yFxnw=; b=4hO9nbpC9/B59lz7lu7ipLmvPx0TPiRR1YFcnoIIsLsACw+RsmBoY1hg9fpZtuMvoW AsVsIpTf8LfYB4lwQ5sT6jbE8vVaylpAww88SyjrA1LKqGMRXyWLDVtjUMHa3DShm/3L oCZtGpYklKgkoDTmolhi1ndUET6n652IDLkTIObECyb0yackpoS0TrORfZJOHg5/tfhJ JNKbEXfUKTJj0MNVLKCwTOpswbGOlStCgQHRqPjpQAo80ZcJR3KseQgmY2Wv1ZWl+SgC d+U9Bx2apmjK27kmJGDzWSJpSU7aLQV3FnJPhxOI/r8/brluCy0xQxyPUn6xCpotTzHq ehCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686271937; x=1688863937; 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=R1WyFySTZ0XkKYIf3B7+wOl2DNVNhKC+z/byy1yFxnw=; b=KnUegYLKTqaUTIbpy79eo2sbOVzM9+7H8sQMbw52XQpa5DdO8uE8RaTjKYrHEp9vpW lf+jmluDq2PNM4QpbCjzJeduAwpZz3UhI6r8OyVqvZQ46Zc3ddD6YPAOQeU3Vz/5B4Th IpIZ6RsyZo6VDPdfEEyrTp+RZZTVappIPp8H2ix+4G9agxOH+K9fIZ+eS/0TGlgR8DoE skafsaEhTu9qvsuzNVjOlEBg3hgTRy5TNsYn+UQP3v1IEJxA6cTtMG/2P2gvcMBzGroy Ha63v7Da9Hn54xv41KNnqalbK+18/miQzX5Gt0a9zWqBCpaOX6QKK/q5aTIaPrZgKC/l Xlpw== X-Gm-Message-State: AC+VfDxknKOhVL4KQ5IdqwIYl6sCpzwucxD3okPpEeTXI/6qmiASOBRQ fpm4MStA5mlu9Fk+Eke8u382gL7ltlo= X-Google-Smtp-Source: ACHHUZ4bWROsb838DrUUPzvA00RwKpJHV0L0dTRYqvNM1IO6yvKJkT1erTMTIADmBKvxMqLYZ9xOLKXYFnE= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:c03e:d3b7:767a:9467]) (user=surenb job=sendgmr) by 2002:a05:6902:211:b0:bb1:569c:f381 with SMTP id j17-20020a056902021100b00bb1569cf381mr138781ybs.1.1686271936956; Thu, 08 Jun 2023 17:52:16 -0700 (PDT) Date: Thu, 8 Jun 2023 17:51:58 -0700 In-Reply-To: <20230609005158.2421285-1-surenb@google.com> Mime-Version: 1.0 References: <20230609005158.2421285-1-surenb@google.com> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog Message-ID: <20230609005158.2421285-7-surenb@google.com> Subject: [PATCH v2 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: D5D2120011 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: tfz63iskkjd5fnq7xn484m3wxtndqbdu X-HE-Tag: 1686271937-240694 X-HE-Meta: U2FsdGVkX19OphwCBjAQ9bi4ukGFTdR6c4M9Jd1arDzItZVvCxMlkGruX7AyDD4Pqfak9GuHKfdCErADbSqtCV14y6psifyOhKVs519XkXwNmSGt8hnL/zCSsEqFjF3PlSgIbypLEDlEBDwAFHedj0+D6jD+WlrlCZoM0xJG1TLjTOtt3IZ6lTL97vu7zbzGwPUogRvf97AgcWlarYQewQWccJvZGU/IccYaJDTGLZhlHubhsVVpF+dysWnl1lJhnUmEDrsdaescdrt38C8e5GMouHzhwOqyjRKj99hfa07xuJShp8dM0k37oHvus1w3NKXY2WsBKSc/LQKmkCEk7POhssp5wIItAyyXwBv2peaRoGzqwbseSkgEu9mISNkVm8sXu0R4yEzcaEKrx+6YjmdAlnysWuffm3k9Chohn9U9A8/gL7OyS+0zMCUhP6dMfgNr27M5/juu7FzTaOODP7B0RzLZVNDXiRLAr6W6rytSO9lG1zFwAWX8OA270LE+uB47B5egABHgM+xlxjvwUDTzjtslosTy4URlw8GYPiavGCnpCez1Zd0ZKRNCazZmKiVVUr4iBJRN6/wuhbQc2IeXUffvdJmt1WEIUfrK0trgBspxY77grvVj3gy+LQEZBjs//gENHxQcj8tsR1EF71dmuyTvN8mldnFfZuY76EwIrv1+i7Q0QXmDBD/mmeDw8NH5T4PsD7sp07H3cBaGkPakRPmPlRyIKNhKvzp7WbHSchACRfmK2Fku2vQG4w/sumMX5cGxI/eelvAdFDHtVbmfUWICba1ytvQWuo3Zm3kX18IulPSft1LVWUb+TkYeUb436sOcpgHacrSULpchJ70CrXE+4TAMIeEpXatoErf7cne+4RLqvddCZULhZM5xOKw+PYbSvB5zHQtMwVO0U9hJX//biipY0mTpsHRuBnDk1NDPkhsOj6P7zvQ5UwCZU21IEyExsSaoamFHIWW UyehmrCa kwK8rygwDk2SXr1lY61jB/L2b7uDestaSKLbeDA2JVXPDTz+KfmG6WC3EY0L5ZLFCYJ65ccNZeoud2KlwKhRUi/nONON/PNrOmDrA5je49allfbxZzhO0CEPnE83s3Cm5W7iTGJ/FMPBLxjCIXeADgelG6F+POe6KwIS53NVYnrFFml+4RFfa3VVMrYEq4hi6WVAf7xqRX9HgT5qDMMBkPCON9XeCG3ZY050F2MC5+dhoRR3G03XwKwBSmGZSawOJLg3CEwhhrNrDzi/RrnmqsqljZMSWKfIWFKCT9DcQWPMWsE6X+8Km7V30yF+n2XOPbXjSHyWWSApZzu7QRrEwfOnTA+DWN6FCskMUwROje08d56TCjyZwYDEyD4Po0r29jMdhX6XdNsdmxDWid5mUjqAfOYOZlVgjjfPaERhr+9+qcg9q3nomE65NnsqVMs58XRLDZZWCm3vWHSPdw4bNpnn1YFgm23HX80dSFguBOcxMHfDeJUfTUkK24EkYj0+19IRWZWDRXtqZd3h79ONtbx+rqSYhTBCYYulnZMq3VFlCHx/4mkV5ItIBAUSjGE9ISa2mMvTi/Hp9kjJqt5JVBz79BX8FKtTqG6XrMTEwUPE91xA= 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 with VM_FAULT_VMA_UNLOCKED set. Signed-off-by: Suren Baghdasaryan --- fs/userfaultfd.c | 42 ++++++++++++++++++++++-------------------- mm/memory.c | 9 --------- 2 files changed, 22 insertions(+), 29 deletions(-) diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c index 0fd96d6e39ce..23c3a4ce45d9 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -277,17 +277,17 @@ 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); + if (!(vmf->flags & FAULT_FLAG_VMA_LOCK)) + mmap_assert_locked(ctx->mm); - 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 +308,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 +323,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; @@ -337,7 +335,8 @@ static inline bool userfaultfd_must_wait(struct userfaultfd_ctx *ctx, pte_t *pte; bool ret = true; - mmap_assert_locked(mm); + if (!(vmf->flags & FAULT_FLAG_VMA_LOCK)) + mmap_assert_locked(mm); pgd = pgd_offset(mm, address); if (!pgd_present(*pgd)) @@ -445,7 +444,8 @@ 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); + if (!(vmf->flags & FAULT_FLAG_VMA_LOCK)) + mmap_assert_locked(mm); ctx = vma->vm_userfaultfd_ctx.ctx; if (!ctx) @@ -561,15 +561,17 @@ 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); + if (vmf->flags & FAULT_FLAG_VMA_LOCK) { + vma_end_read(vma); + /* WARNING: VMA can't be used after this */ + ret |= VM_FAULT_VMA_UNLOCKED; + } else + mmap_read_unlock(mm); if (likely(must_wait && !READ_ONCE(ctx->released))) { wake_up_poll(&ctx->fd_wqh, EPOLLIN); diff --git a/mm/memory.c b/mm/memory.c index acb09a3aad53..b2ea015dcb87 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5306,15 +5306,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);