From patchwork Tue Jun 27 04:23:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13293980 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 CE567EB64D9 for ; Tue, 27 Jun 2023 04:23:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5D35D8D0005; Tue, 27 Jun 2023 00:23:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 55CF98D0001; Tue, 27 Jun 2023 00:23:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3FD588D0005; Tue, 27 Jun 2023 00:23:31 -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 2F37E8D0001 for ; Tue, 27 Jun 2023 00:23:31 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id EA2911206CD for ; Tue, 27 Jun 2023 04:23:30 +0000 (UTC) X-FDA: 80947233780.11.C2AF947 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf02.hostedemail.com (Postfix) with ESMTP id 15D9B80020 for ; Tue, 27 Jun 2023 04:23:27 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=dHheU6IC; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf02.hostedemail.com: domain of 3P2SaZAYKCJwOQNAJ7CKKCHA.8KIHEJQT-IIGR68G.KNC@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3P2SaZAYKCJwOQNAJ7CKKCHA.8KIHEJQT-IIGR68G.KNC@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687839808; a=rsa-sha256; cv=none; b=rzjexIYNA+UX5iwCby9I7tdYRUam6aP7ni3akgXVfKMApxXkBqFUzAdeAgh1d3SFcdBgmq 8Q4mnMoR6DROU70hZXoipuqgK1rwAOvlgbEXzNuzhklyuHTuAKIzLkR2WwEzCQDtWBekKB pS1ezfWtpm4+txy8/fI5MEjfcK64fDo= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=dHheU6IC; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf02.hostedemail.com: domain of 3P2SaZAYKCJwOQNAJ7CKKCHA.8KIHEJQT-IIGR68G.KNC@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3P2SaZAYKCJwOQNAJ7CKKCHA.8KIHEJQT-IIGR68G.KNC@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1687839808; 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=o3AoGbebO2/sjyjLq3ryUCG8xyOW9r1weM+cOFZBuLE=; b=F73hsRKLnQcqAyaiBGDKNYj3q5AHDILbxaIuGav4QZgnXdzfPcqYoxSrRCCpSovBPMFzff kjxOersNt78nyGxPHzt6hnwWq1B24jMKKOAnsKeucSMZyDQ2NRHbxGY06nPu1hBqc6SWRp 02wZEHWizxXUnCognFfBh3uZAb4qf0M= Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-c1039cbba72so6116245276.0 for ; Mon, 26 Jun 2023 21:23:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1687839807; x=1690431807; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=o3AoGbebO2/sjyjLq3ryUCG8xyOW9r1weM+cOFZBuLE=; b=dHheU6IC1gE4LjWZbQ/IniaV5DkcPhnNF8syM8uOEowX24NwDyxL2jv7tc6FMBV27G 4Rxqr6ibWCntKsVRDQuwZtzhYYD6gJJ2gf36p8H6RGHXmOM8wDs4xTT/AlcWoevHEkxS v11okL1qKsR1gEcM8TCR0a/PdkjPb5Pq5EFqxbA0tdJVQ5Xuw5GeD2Ni9wv4/5tL70nq RQBUnOCAF8gaCTtKz4Rjw+9hMKvCgHNAWYRPVUKlT6kt/uP3e/quWkiQpWjZf2l4itqS 1KtiecTwEsABkWVxwh5d4fxy32LDKhCX/GgNJwBCk69VtHXh+xGpl12LuLk4+qxVZJeO Od9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687839807; x=1690431807; 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=o3AoGbebO2/sjyjLq3ryUCG8xyOW9r1weM+cOFZBuLE=; b=VbExdxnNhbs5drm/gMo8S/TQMbplQNzsnNRW4JJr39j062odM45Ypiro7YDjR8zKkm /hdKUaAXlM/ATNwkaaiZv34XarsSfGIS+qLeH1wywRhlojSGQ863Ch1wsiKP+/jXb6Ga sLKaQ69ceGXXBjW/3euktrqO8616xliztBwE/RDI6k1J67NfPxtd5t4nn8BskHbFhp1y nISYkF74s2Dw3AU6I4OH/ewh1UU+/jv2SUEdSv41e6a3gkH48j+gQM8/PJFLw0gGnIJD XTvkey0tctteWyd3cEjK27vCnJWoBshGve3sx11HPBK2lRVSQU4vS9pCZdeCD/NJyddJ +FXQ== X-Gm-Message-State: AC+VfDwMZNchKH7VcpJX/YZvTI/CXKBYqd8WSRdKErAuvKaOEQQ0kilm KcIee0TIpUFLZa8yARr4xOWW/7OsobI= X-Google-Smtp-Source: ACHHUZ5z6WN5yIbltZSphoAhRLFW8PERhElNtWSsbrV8xNDcki//Fjq1aVBOXHRZFF3wnIZEH2iDfzPMLKI= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:5075:f38d:ce2f:eb1b]) (user=surenb job=sendgmr) by 2002:a05:6902:92:b0:bc4:a660:528f with SMTP id h18-20020a056902009200b00bc4a660528fmr10901839ybs.5.1687839807170; Mon, 26 Jun 2023 21:23:27 -0700 (PDT) Date: Mon, 26 Jun 2023 21:23:14 -0700 In-Reply-To: <20230627042321.1763765-1-surenb@google.com> Mime-Version: 1.0 References: <20230627042321.1763765-1-surenb@google.com> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog Message-ID: <20230627042321.1763765-2-surenb@google.com> Subject: [PATCH v3 1/8] 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-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 15D9B80020 X-Stat-Signature: rdi7dbhjmk14ox7a7jydfnr1763omhzn X-HE-Tag: 1687839807-660066 X-HE-Meta: U2FsdGVkX19DIF/Y7pjMYN58k853gVdAjbLw8QnKm24XrvQju7YS47PxCI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0AzVSSxXZOJRvDGQmM1DkYZVRGX6568/JLv1K20fdllcsrp+U8+uq3OadeWy+LdT74Yknx9tlvtbsFNREpwW/KZ/xqJBAGk8louJYpwA8YvNQgsZb4SGhvdgO2Kdg3pGpivfw9JO88E1PUJAd3/2gheGoZ+qBCBz8CevwNUdo4yl/mLpoB8IT5PWnn0+PN7tbIDBYRuph3b9kjPCyF+nrz+s4FRZnFZsUmZqVWOqJxp90EXS32l8M+c6Y6SGYyzEHOSAiOfkly1QzN4OWNoEcPti9+RSH5mPAM8natHZSgZzPUsWNBFRPyT38dqyn5y+dozgmYP32lW1whSdnX8cT36tQsL4UdT/mCkP2giD9o2bpvSFgUzeFuzcPbCFkvH/425FavizWfxZHmJ2FdjCi+lzQqNjPv7Ml+0q1qlacjP2hTtXJoVqmiEFfYrnZWxrSpLTYyGoOt/aQ4vu0buf+Yz1tphe/Xq6qa6+ev7V4zG8Ve/zViw92i3vMWr99+Rl5IEl/lMOM5x/YkgAG64opcwPHooVRWlPUug== 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 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 Tue Jun 27 04:23:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13293981 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 D32BCEB64DD for ; Tue, 27 Jun 2023 04:23:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6BF4E8D0006; Tue, 27 Jun 2023 00:23:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 648548D0001; Tue, 27 Jun 2023 00:23:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4E76A8D0006; Tue, 27 Jun 2023 00:23:33 -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 3ADE18D0001 for ; Tue, 27 Jun 2023 00:23:33 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 0F86B808F8 for ; Tue, 27 Jun 2023 04:23:33 +0000 (UTC) X-FDA: 80947233906.07.9EEF399 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf05.hostedemail.com (Postfix) with ESMTP id 51A1B100009 for ; Tue, 27 Jun 2023 04:23:30 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=xItssmSv; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf05.hostedemail.com: domain of 3QWSaZAYKCJ4QSPCL9EMMEJC.AMKJGLSV-KKIT8AI.MPE@flex--surenb.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3QWSaZAYKCJ4QSPCL9EMMEJC.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=1687839810; 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=avzs4/2teeLyiygOd/b1Z8yOJdjymCMBXiqSvPvjnU8=; b=z/C0iivoZPDW6Era4Vl+R0Uq4RC6IJWDnDTf1AGMlGZsErWTSnRrjJ/QhTMigdH3RLdCws wJBfCsNduWjm3x4xepjXRfTDCXn/y0WjOXMsf6kBkXek85FFtq88mhu7mHqCDM6Q3A0HZu SHgZ6GiW/pd1BMjY88MbPUY+jJsEYZQ= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=xItssmSv; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf05.hostedemail.com: domain of 3QWSaZAYKCJ4QSPCL9EMMEJC.AMKJGLSV-KKIT8AI.MPE@flex--surenb.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3QWSaZAYKCJ4QSPCL9EMMEJC.AMKJGLSV-KKIT8AI.MPE@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687839810; a=rsa-sha256; cv=none; b=1jPk6gaUsYwl9XqbV/3i3R32fQ1AiePz3JdUiOcwlMSTDdmTG8ZTkm6cC4iyEhjmqbDJOv 0erL1WMriq72YVkL4xI1G6doVqR+CCZJIVajGXDw9hIeJNpD+V2lT1jwgLlANIDilM9ctF gIvyhplwyPXGZwYHf/Q//6fqdBamAUQ= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-5704e551e8bso54509717b3.3 for ; Mon, 26 Jun 2023 21:23:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1687839809; x=1690431809; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=avzs4/2teeLyiygOd/b1Z8yOJdjymCMBXiqSvPvjnU8=; b=xItssmSvERMw9dsz1Nh5mK37qPbVAP5IEkuWu1uDTGcdg9Vwz2ARZEnjyozZOEqUuG e8uckzXLnLK7yP5FRM7n4SZnRy9wztCXumxHxgkSmrrAMof/XLBanlvGazRLnO/sRoJN UCIl1KpUKDC8OR2vK1T4hTMRgAefTBd7NM+Dx6ZXICvZBrXfyNX3TUTCKVgYWm2hUS2l gOq88g1izAtjxSu5tZWmDb9LNBvXrPbf9h1PhZMWTUxNWgeVfGL1S4kF5FPib76mtzVI DLL3RiWHlMy/zCm8bB7icB7scjmZmtSqhqRFvK87ijBCTPJOJVmbS5n00YK5TtuwF9oT e7Lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687839809; x=1690431809; 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=avzs4/2teeLyiygOd/b1Z8yOJdjymCMBXiqSvPvjnU8=; b=gQ7PZ1gnX3BJqf+Wm5ashPAK3UEkOd6UOjh21PUrBdBGvl1iEYy9zIyho/ZKAfXB9h PSuiTRzp5JSJGctl5Oj6/zN4dfSuFeAj8AUcC0K1Ze0c7vp+psvOiF8wtR75D2jcYUEC q8a/oFXGR3c2lhERhf0upz10VwHthvccF/wJIZggmKRLwrZi19dxknVO8PqnuigzxIYO 7K76qLlU3X0+qhdcAL3X4HEyKisR+6vJDStddtb1EZtYNPIEOR7WJ9fOEAKZFGZ4y67z KFCOYwnZZ9dXYzLw0emjwtoB0GO+9JC9jZ4Wi2FBSvFNI84IlpAeXMR19+x3WAsQ45fN G+bg== X-Gm-Message-State: AC+VfDyliL5PBx6EH4p5+J5iSGsoUWPKTvsUltxLAp3ItX2LnfMDz9+z vI2d8zFL6smAoeVloXPV5m5hp/Y6tPU= X-Google-Smtp-Source: ACHHUZ5AuZJxZCfveJ0bV7TxtQYd9lNOfSSAPqhvcXC32iXyNPsD+vrMDeCVzVPvKZJ/jqjM2C5sDhTgrX4= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:5075:f38d:ce2f:eb1b]) (user=surenb job=sendgmr) by 2002:a25:a28f:0:b0:c15:cbd1:60da with SMTP id c15-20020a25a28f000000b00c15cbd160damr2662160ybi.6.1687839809398; Mon, 26 Jun 2023 21:23:29 -0700 (PDT) Date: Mon, 26 Jun 2023 21:23:15 -0700 In-Reply-To: <20230627042321.1763765-1-surenb@google.com> Mime-Version: 1.0 References: <20230627042321.1763765-1-surenb@google.com> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog Message-ID: <20230627042321.1763765-3-surenb@google.com> Subject: [PATCH v3 2/8] 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: 51A1B100009 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: irr1oz6kkmpbeqpjthw4sptm684ot4ag X-HE-Tag: 1687839810-363147 X-HE-Meta: U2FsdGVkX1+n0Et4B1C6+xK6emtHnjPX0Y10YeWW3ilnkpvoF5I+/QgmixQClox+G+mbxM5gdrslbbvlc7pHNjJUJbHrp/JMJvOYMYLRY960x1zqhyol5NhZDuf7uHDd7KFJgZeEiQexltO9lwGIpLCgGjuPEg4ZqEWTNeuF9bbtujU6dTMKsbMN1Dsv3hGniJzoHUtZdgkvF8nhgAbr1cBTAOos3Ei6nXhQWPRtXzHpeTHGEQBDHQFeON3jlNQPXTjqtOo//2DAT8w/LrVmu7mtt0kPvZhA56baxhglZLPvu4ZaGj0Ac/kXAKYIt/DWc+QcSc5eFmLgS+U8luLlM6Y5vmHUysSrB49iAzXV6FAheQJI0VDtzeHxV8Yu+fnGBi1+9kyzbehagJxbgehDaymolkXPLloOW0JsBvBJq0vCZi3AvHoIkEBKC9ujm8KgMsHAlXR+N7R6eb6vLrzdmSu5G6x7AsI2C2Nn05DnRampgw/ZxvPdt/2jviYnnPpubyuiK1tHMF8dJr0yqPyGTlHVLviRN5EzxOYhhJPruZPGtCaFn6RRcPWIDU0Foq8zlMqNZbc+LTSkygGcyqPH3BbDGTttfJnEDNXddiDPQVJ9U57BcTIkcHHQ9CTSNoswciQL3VvPnQY9WYU8DOQbiKcCXuxIFsDdK8rRlQv+V5AcG86sSxOB+D0Eg9acUjilNPmg1OINyiQOjz8D3aVgr4256T1QXtCpH2BqwLCgg+vHaxhJB9VpssUIr75OczY81jehVpMrm/afpbQMUHKTwht1sF4PR/GGCPyK8nlZSUoAAYXvQJBp8lbuljXsOr0pOAPoOyggUa4OSXwYv90AB/zpLxfLymRpIvJDlMOJFMaC89UEaqQJ2nVF4U4CCJFvmJ6xpNt6vr4+M5i7VCK105upFISl/WO5JjfVS/4Ryu1iCKR5mOsr504iCxqkf6OqYGQdb0iVJtYUzB5RV4h 6hlI3ihy 6KtQBheNcoBf0nxWy2ljQjORGFNq4x5zuvp4ERroiQE+Y3msBXTbk3xFsMn6bP7JzibrmJ7kQvAoSYxgVSWW1l2mZYsCkbk4b0rL5IUqaZdsIrOTIzcucSoCb6VUfkByOnw/+mx6pzIWswNJ9m0miBqs799ksizT7OD+s64u5Cld4tRs6yzBhIIS9DO1XFEHDeZi4DfbqzhTKxSJ23YcZtpu4CIzhkKwYY59cnQ3KJJ0IKniMvRAy7LKnf2rMi2tB7eReBrBsQoelP80xnNp11XZMUr57FCR0R2AfLeKi58Dv4MD/sAsPN6tog5rnK/Pt1wODIEeZZ2deRe1vMXKmjhslwBWQ55THiCuPweCJ636Uuglu2GQZeQdNNjVgaGYL7/K6v0Xo129RIkA8MXG1+K8HToXXTP/RmhuIxHQAsx30iRx5b4mzr/SObvZHcpy2muy3zizC84OPJwKqDinB8xiw6Sw1Zeqq3QqmId4BzN1xiKBere+PLPSpKNypDjFhE+3vX63VbaHPIiz+l16H6cIX0MIiLZSSI9yWtikJ//2SlL5uNvKQybWQ/XDid84u0EmHaOevWFpQGrr4Qs7xdZDHeS/BG6swgRt1V7vPGD7yNlq0kx0PKv3Ieoy8cnhNX5qrWvBi9/musX8bpfPEC+iVLjLU098LhSNg9bVURrKKY/yZXiFTWW5H9g== 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 Tue Jun 27 04:23:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13293982 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 18EA4EB64D9 for ; Tue, 27 Jun 2023 04:23:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7CFB48D0007; Tue, 27 Jun 2023 00:23:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 759CF8D0001; Tue, 27 Jun 2023 00:23:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 55DA68D0007; Tue, 27 Jun 2023 00:23:34 -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 473288D0001 for ; Tue, 27 Jun 2023 00:23:34 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 19C691405BA for ; Tue, 27 Jun 2023 04:23:34 +0000 (UTC) X-FDA: 80947233948.01.52ED914 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf11.hostedemail.com (Postfix) with ESMTP id 4A0BF40008 for ; Tue, 27 Jun 2023 04:23:32 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=ugW+SG7Y; spf=pass (imf11.hostedemail.com: domain of 3Q2SaZAYKCKASURENBGOOGLE.COMLINUX-MMKVACK.ORG@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3Q2SaZAYKCKASURENBGOOGLE.COMLINUX-MMKVACK.ORG@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=1687839812; 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=kbyeBW7WIJNXjK7iu35fAbN/5yTuDJs52xpJl7xU1IY=; b=vD8kem979exbJomXU6LoFhWkW8Uz9XjEIRWqEjjNjgFiWBLAZ4w0+PcvnaByqD6fY/f/7B ehNAKY5mhTh56YZvqgVlziusVCyaznP0qE89YtUwnuk6a7wH6nRcnpeMcgOzz2nFXuaPpA RLuI5Rja1BOY1ofSocEanAcwsw95ivM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687839812; a=rsa-sha256; cv=none; b=ta9i4o7Lnnxs8w/+ZnLfbVKxUE/XLym53t5GQAtHr/tngjx2IcZrZ+eew91dCV0Mjj21rP JUGo2dUQ0/PgDjanOFDhSAa1Ux3lFxwrLqo1MwUtPZDcbAdbrAwr0h87i/YvnHlhdg7cXO byxF+ctAgKDHERiVuTD4MUF7RgPZKE0= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=ugW+SG7Y; spf=pass (imf11.hostedemail.com: domain of 3Q2SaZAYKCKASURENBGOOGLE.COMLINUX-MMKVACK.ORG@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3Q2SaZAYKCKASURENBGOOGLE.COMLINUX-MMKVACK.ORG@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-57003dac4a8so105903097b3.1 for ; Mon, 26 Jun 2023 21:23:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1687839811; x=1690431811; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=kbyeBW7WIJNXjK7iu35fAbN/5yTuDJs52xpJl7xU1IY=; b=ugW+SG7YngNovW466Ob1qbMUa7QCgvQN2HYZdw69vEb2gnilYAyfBBDC9eIv0kJn5R K+Nth6CovXEzufoeufA2bBetWvrGzXQiUD8VhdoqNnFL16vRdxwfeZTWoLlNANAXPsaE 4it7n5SCFHwAzJ+itDODzIf22wtA7wDa/2u16CAUMCgAj1Ez2yBmApbjIHS34bZr0QAs 6CcMERtjjQw5qzSYxGAWzCQbLbu0UfN+0PYZKiPIpB8IIqWC1ndKoEhlLxsLL9cLvsPv v4BzBjfVXuH+PyuaE6GmW6rTE2x5EJClKScB3InhL/RUrH4gPNiYW0KVLBDn77KNMcAS 0haQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687839811; x=1690431811; 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=kbyeBW7WIJNXjK7iu35fAbN/5yTuDJs52xpJl7xU1IY=; b=d6qnswB9FiwybZRW3WbOeYsR1ADyRR/WppbgxCEXtD61oQxvU9OtTOnyiEf8YvMzVC g+HQeWp1nQtYa8v0gVw2jTV0e4APeany6dSwvNBpENdJs8+1yRFRNWOPI17k2ek16UO+ qbiggJiDm2b7VpZCivAxg5cnnFJiJa/8yfYaVQGsXNU828IqyfDqOUon0WZNIExU3Q7I yD674te9FDIR387uQdDlNSWs0l2MsI5g4nUr191fcDGfjLeU3vFzSm+HP6J6Znc47r48 e+kYuUu8tmjlCaO4xBronea1Y5hcsYJI5WT8S4MHRgefCPGuEIdZ1mGwX3/Dp5m/qPBs 3geQ== X-Gm-Message-State: AC+VfDyMm5qDagDrCCyVF/D+p5QEvSzIGWHdiYSvfKoPhAwBvo87dsqJ GvOz0/LrMusrR0j8+b74ENOPy3Vu6kA= X-Google-Smtp-Source: ACHHUZ5PHgbnMPnEsTLa+W0vChTT29tB4jfEbEI5BqOjiRDx9zMqo94H5raeRb2+zfsUTcjeQvPxANoMY/M= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:5075:f38d:ce2f:eb1b]) (user=surenb job=sendgmr) by 2002:a25:ac92:0:b0:bc4:78ac:920f with SMTP id x18-20020a25ac92000000b00bc478ac920fmr13716099ybi.0.1687839811426; Mon, 26 Jun 2023 21:23:31 -0700 (PDT) Date: Mon, 26 Jun 2023 21:23:16 -0700 In-Reply-To: <20230627042321.1763765-1-surenb@google.com> Mime-Version: 1.0 References: <20230627042321.1763765-1-surenb@google.com> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog Message-ID: <20230627042321.1763765-4-surenb@google.com> Subject: [PATCH v3 3/8] mm: drop per-VMA lock in handle_mm_fault if retrying or when finished 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: 4A0BF40008 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: osuopdwzysdy4goutndhiizhxtagauhe X-HE-Tag: 1687839812-754379 X-HE-Meta: U2FsdGVkX19pIl7EHWojHtfustl3QnUgrqX28PuAyzBx4L+QQy5xBRP83qtd7AqikPubGYcqyjMROWfMYc+CN7QPqxntKd4UP9NhNOn5MYGH+Xt0AGD6OgJTBFJ4DzxtueCr1KsVstYhfXKchSrwEx7oexT5xVynjJ347IpeC3H6LMjusRloL7yjhCR4RyDZfY01KhdTYzPxUCTmH8t2lBU1nKDpvLA6+QBaGWZIYP69OBil91JTnLGPWxCqXVwWMaDfXoQJxMxPO32/epbKHPhlx/WY3veA40jO2VpKZz8t54K2HZrbYx2GekzdJv02LO9qGhFblvHiq84/V9n/LVMP70FJWus/mQivxrQEsmUQPwtrXxi8zkHp+9zVcdsBhVLYrCctZ3GcHnnDDFmxYPw03qLx5HazXWF478eA8lk6kN63sQiWKMl6h4lGU39nvUXbOhc/E2Mtc0TVQnM9+A+IRL3uojK6Dzf0JZOb1ub9IkPR+Qx7rAg9LZTJw0SfJWC8sGkPibAvSHsK3BF/t8i3Zqtff+aRHlIJIHPp6EQrFCHmfcjoXZgD8yJGFpTy9sy92vRF42Hi4SdtoY/1cx4VyxFMNWwcc5b+b7szTAJQoTY/kGRr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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 before returning from handle_mm_fault when page fault should be retried or is completed. 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 ++- mm/memory.c | 12 +++++++++++- 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c index 6045a5117ac1..89f84e9ea1ff 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_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 531177a4ee08..4697c5dca31c 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_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 b65144c392b0..cccefe41038b 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 e4399983c50c..d69c85c1c04e 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_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 f69fbc251198..9011ad63c41b 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5086,7 +5086,17 @@ static vm_fault_t __handle_mm_fault(struct vm_area_struct *vma, } } - return handle_pte_fault(&vmf); + ret = handle_pte_fault(&vmf); + if (ret & (VM_FAULT_RETRY | VM_FAULT_COMPLETED)) { + /* + * In case of VM_FAULT_RETRY or VM_FAULT_COMPLETED we might + * be still holding per-VMA lock to keep the vma stable as long + * as possible. Drop it before returning. + */ + if (vmf.flags & FAULT_FLAG_VMA_LOCK) + vma_end_read(vma); + } + return ret; } /** From patchwork Tue Jun 27 04:23:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13293983 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 E4ECEC0015E for ; Tue, 27 Jun 2023 04:23:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 75AFD8D0008; Tue, 27 Jun 2023 00:23:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6E4428D0001; Tue, 27 Jun 2023 00:23:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4C1258D0008; Tue, 27 Jun 2023 00:23:36 -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 3AA4E8D0001 for ; Tue, 27 Jun 2023 00:23:36 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 18BEF1405BA for ; Tue, 27 Jun 2023 04:23:36 +0000 (UTC) X-FDA: 80947234032.14.69BB8B1 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf06.hostedemail.com (Postfix) with ESMTP id 60C6A180003 for ; Tue, 27 Jun 2023 04:23:34 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=0LWS1fUj; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf06.hostedemail.com: domain of 3RWSaZAYKCKIUWTGPDIQQING.EQONKPWZ-OOMXCEM.QTI@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3RWSaZAYKCKIUWTGPDIQQING.EQONKPWZ-OOMXCEM.QTI@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1687839814; 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=WF0nP76m0uCKG0VaTNWwLBGINdJ/4Fr3BCgpH937Cjs=; b=erWSYabXKvkwv4+NGqTbiQ8oCR80Xln9i4QnHj4wJTemOzTPB/RBh9nIxNke3Vx7FTiHlH F/wlCEd6f5dh8sqbmcCqjxsGG6RwydcZzqjGCmBpuynm4O6ALgyy4NqlbQk6WpvfjIUQDD s/7yLUMElkzSkuRROeRNJ1YGUq2yFhg= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=0LWS1fUj; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf06.hostedemail.com: domain of 3RWSaZAYKCKIUWTGPDIQQING.EQONKPWZ-OOMXCEM.QTI@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3RWSaZAYKCKIUWTGPDIQQING.EQONKPWZ-OOMXCEM.QTI@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687839814; a=rsa-sha256; cv=none; b=cUDcXR5N3SqO0ybgbu2rJob2wg0+sz0fu6JetjtFWu/q4cyc3BI6WUS8MJE9/gfFX3rdKO GNo9YA8hNeYkDtCB+9UdOf6lKObBEhkTySZW2T09WM9kd5DF4xzHjbfBQSTPMY7MZbsr+Z lXHJWl3arFD1MV9cSvh9/QT4qrNkos4= Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-bfebb1beeccso5399939276.2 for ; Mon, 26 Jun 2023 21:23:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1687839813; x=1690431813; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=WF0nP76m0uCKG0VaTNWwLBGINdJ/4Fr3BCgpH937Cjs=; b=0LWS1fUj8fHv91oTajKg0vJcBVpdqwwSqjUtzC56pWGWU3fl8K9dA6f0idnSLMfjRp fokb+1l28uCZoInOB6UO18g1SRkEK1ukcbhhi0rTdehONv4x9IMeidIzzGOWyKexc0OG jtPnV6XHIsb+Kk87Cid51Sqhcr8uIw/ufmfTLfVhd2MQ4RpVy1HWiF8B3Sb3sDy9uguB pjICzCL8grLgH0l9QV0PKaK54nmIU8F7wcbUEL44gNrVf8lCe7QlzZUd/Ktb4nhV/XHr Yfq48KIvtTGqDvC3g4QyYJOr3Z8pcOMXFmK7g5sWgh7pvY3BZaDvj7vYqGrfnd6T5ld/ zR/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687839813; x=1690431813; 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=WF0nP76m0uCKG0VaTNWwLBGINdJ/4Fr3BCgpH937Cjs=; b=G6fMgE3t8TR9n7pl8RKzWYRCL8byDMSciXeQX6EM13l+LNrtR2IvT0xl05BoOrV7Nj tXj2sO2v4cXbxS5gk8pPHsRGTZs5P0ODLuVyit0bKyPa45Ny5eGXTZI6jY88qSfubCMp XiNwlp3sVRC3rgLnr6UUmm9S871gWfToUahJS30FJdW9a0Av17MCtXaJ+2HnD8ytYr1M rHSHKPxhiAR4yuv6DAS9pM4hK8F+6klm06uEzHaRtu7Ff2iQ0q92oz034Ti+fyV5tMyR ux6HYiBxOIYOzuOeUsM+y1F0tr8xzhHLgX4ByCecQ/hLBkTPym0dnoygHpEyfpzWn7jR GRMQ== X-Gm-Message-State: AC+VfDxqUFvuUOEBc6SI+Utr1ZmPLL882rLxTrwF+FicQk5Pqk7cqX6W wpYzPQYCgc3dDGyDscKlAixfzicN+5U= X-Google-Smtp-Source: ACHHUZ56AMLtfxTBdGwHX0CowYNHyrKCFB2CGbJH8wbYjNIC5f8CBX5MSU7xISg3RwE4lnvBrqwh6dvbi6E= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:5075:f38d:ce2f:eb1b]) (user=surenb job=sendgmr) by 2002:a25:ac1:0:b0:c1d:4fce:466 with SMTP id 184-20020a250ac1000000b00c1d4fce0466mr2214106ybk.4.1687839813544; Mon, 26 Jun 2023 21:23:33 -0700 (PDT) Date: Mon, 26 Jun 2023 21:23:17 -0700 In-Reply-To: <20230627042321.1763765-1-surenb@google.com> Mime-Version: 1.0 References: <20230627042321.1763765-1-surenb@google.com> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog Message-ID: <20230627042321.1763765-5-surenb@google.com> Subject: [PATCH v3 4/8] mm: replace folio_lock_or_retry with folio_lock_fault 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: rspam09 X-Rspamd-Queue-Id: 60C6A180003 X-Stat-Signature: ut53e73tsmqxwcapemod5wykd8aym7ap X-Rspam-User: X-HE-Tag: 1687839814-634841 X-HE-Meta: U2FsdGVkX19my55E9OZCiBHFIu9rWBfoR/30DZDat3tlWU+gmIfwOMSFJ+rMnvioqWVM6Iv/hPTTpygxrivuaLgc+JPaTVfT2kdI8AZILukjAhhv1J7OwQhljY73C0eA/2iUaSW5kzZXIwJ+sPaO90WZvM7VIxWo8MpkF6jglzOoUl1UnqpHIUIyu8OtvZzJ8CV/OiTDS3TRJBjFNiDWGLA+WVuLpVSuKdffmb+g0/lclreed6SnQkBDGxu1pVOYGWPrnjr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cHq0RyOIYYcYfZW2N8zmg5UdF/xwmlJcflQQtrUwLHha0pR27NTlA4/YQVqxbPd174Rr5Mf8olQYPbBdXplD7W6y5hywtbBbJJPDrnfAItqOk3+2dWnzRVG0IEfqLRqcksEHtkN/PcK9XQyf/0sJhIcjDfb+c2HnT1BhSyDkMl1O+7svm6MfsTRGZ9oQY8rWEOulmLpBS8U/OUN046Y1T3hcDBowHoDC6w6n5fFeMuTbRvKiKKlL71rEBOd3J5gNkFAQb4M2K5AZptOnkPGBtj0TZIJhOhjU7sVWLwOhCILLKpsxgxwQ4dtejb1iczxsMMTpwLkwPuSIlb6czwMPu4oL/ba5SRwnT7uhQCLV9bqg4gldiI9AF9+nhXy7pxIPBEQZPwbKUYNrphrGA== 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. This will be used later to return additional information about the state of the mmap_lock upon return from this function. Suggested-by: Matthew Wilcox Signed-off-by: Suren Baghdasaryan --- include/linux/pagemap.h | 13 ++++++------- mm/filemap.c | 29 +++++++++++++++-------------- mm/memory.c | 14 ++++++-------- 3 files changed, 27 insertions(+), 29 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index a56308a9d1a4..0bc206c6f62c 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -896,8 +896,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_fault(struct folio *folio, struct vm_fault *vmf); void unlock_page(struct page *page); void folio_unlock(struct folio *folio); @@ -995,17 +994,17 @@ static inline int folio_lock_killable(struct folio *folio) } /* - * folio_lock_or_retry - Lock the folio, unless this would block and the + * folio_lock_fault - Lock the folio, unless this would block and the * caller indicated that it can handle a retry. * * Return value and mmap_lock implications depend on flags; see - * __folio_lock_or_retry(). + * __folio_lock_fault(). */ -static inline bool folio_lock_or_retry(struct folio *folio, - struct mm_struct *mm, unsigned int flags) +static inline vm_fault_t folio_lock_fault(struct folio *folio, + struct vm_fault *vmf) { might_sleep(); - return folio_trylock(folio) || __folio_lock_or_retry(folio, mm, flags); + return folio_trylock(folio) ? 0 : __folio_lock_fault(folio, vmf); } /* diff --git a/mm/filemap.c b/mm/filemap.c index 00f01d8ead47..87b335a93530 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1701,46 +1701,47 @@ 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. + * VM_FAULT_RETRY - 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_fault(struct folio *folio, struct vm_fault *vmf) { - if (fault_flag_allow_retry_first(flags)) { + struct mm_struct *mm = vmf->vma->vm_mm; + + if (fault_flag_allow_retry_first(vmf->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; + if (vmf->flags & FAULT_FLAG_RETRY_NOWAIT) + return VM_FAULT_RETRY; mmap_read_unlock(mm); - if (flags & FAULT_FLAG_KILLABLE) + if (vmf->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) { + if (vmf->flags & FAULT_FLAG_KILLABLE) { bool ret; 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 9011ad63c41b..3c2acafcd7b6 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; + vm_fault_t ret; /* * We need a reference to lock the folio because we don't hold @@ -3580,9 +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)) { + ret = folio_lock_fault(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, @@ -3704,7 +3706,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; @@ -3825,12 +3826,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_fault(folio, vmf); + if (ret & VM_FAULT_RETRY) goto out_release; - } if (swapcache) { /* From patchwork Tue Jun 27 04:23:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13293984 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 36414EB64DC for ; Tue, 27 Jun 2023 04:23:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C3CE48D0009; Tue, 27 Jun 2023 00:23:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BA1EC8D0001; Tue, 27 Jun 2023 00:23:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9F09E8D0009; Tue, 27 Jun 2023 00:23:38 -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 8ED8B8D0001 for ; Tue, 27 Jun 2023 00:23:38 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 59D9D807EA for ; Tue, 27 Jun 2023 04:23:38 +0000 (UTC) X-FDA: 80947234116.28.C7145EF Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf27.hostedemail.com (Postfix) with ESMTP id 99C4640004 for ; Tue, 27 Jun 2023 04:23:36 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=OvvulEsW; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf27.hostedemail.com: domain of 3R2SaZAYKCKQWYVIRFKSSKPI.GSQPMRYb-QQOZEGO.SVK@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3R2SaZAYKCKQWYVIRFKSSKPI.GSQPMRYb-QQOZEGO.SVK@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1687839816; 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=/bqEyfDb2JHBciJ5X1JfWPHzjf7SmvaClBSwV4xMi6U=; b=nk/uMfCczS8DLNE3LJBsz49lQXzav+ffr9uyNDYL7oSSN4ObPPPUuyolHJEC6bqPMoKjJS eINYRTRVuFyg+Q+kMTOMAw9SwEtQBJepgJBibOSXMBnVem/GD+hp2BZhW4jfHPkYD7xMPa vRJqw6NeWpAKTGE3Pdu7ai0Jw4ShsPo= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=OvvulEsW; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf27.hostedemail.com: domain of 3R2SaZAYKCKQWYVIRFKSSKPI.GSQPMRYb-QQOZEGO.SVK@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3R2SaZAYKCKQWYVIRFKSSKPI.GSQPMRYb-QQOZEGO.SVK@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687839816; a=rsa-sha256; cv=none; b=37Bn/rQTgx1QwE5/9fECtEn3XU9oQtwdYSCIhinZGF0s3XW3pK3leIk6S+cgm6SCXsgwP6 WONSSUEuVWEFgM7Moo29U/E7jaW7qReaDNQ8eHzncbFtgaTb6w6mqv4mn4cvLXRpsKZbhv IwgcuYAWTwWzRsNQdFbRdZ70Y9AiQ9s= Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-c17812e30b4so3259208276.1 for ; Mon, 26 Jun 2023 21:23:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1687839816; x=1690431816; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=/bqEyfDb2JHBciJ5X1JfWPHzjf7SmvaClBSwV4xMi6U=; b=OvvulEsWmawhmtqOLDyG7NX+8MMLCKyrPheIcVIJBGuloUk350HzepAZTTg9GSNFTq Zxyei2vg/f2B5jkrZYoGKPbRxvuLjH35sLV4l1wOBTJafVD0HTbDUzbP6jPQfOdU+KaG 3gIkRMxtJ9DgS5SW0Kt3bWfeu+sXaplrrhq1B7dNLrmsE2meL4KQdekBOG7sWz0zAe0N lkYsG+/en/JT0DT8eW/ip3lW+AyM8tArkN2trbjAuP+aG5gijB434ikFW3ucpom8cFWS 1HC6TfIWomgbHMNnYthALNU+Ilov/TeO7Y284bIljOOAHiqgvbBCXiM9wMHeW6Wjn6nD V8ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687839816; x=1690431816; 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=/bqEyfDb2JHBciJ5X1JfWPHzjf7SmvaClBSwV4xMi6U=; b=F7hyCMknr6FZKgBIg6CD/2atShCKbut7hTJdg4KRgSECOHCBqa/kNC3re3v5JRldd0 36fk7Et5RIMfNexVn3IGnJnjwLlZaTtC8iJRtQk8CJmMxRuLrhy6pcQXYa4LP+tX0ZcM mm/kzO9PEul7vY2Bx7EAK7NvBbffMLN9VrJTFO6K4sO7RQOaDDwXx2eUIn+acUYbgWXw KQqVKVk5DSpID41iZ/1LaEeVPPvUv6JfAjH4SjsLx81Z8cqDXKyh++NU/9ag3CtQH0rj 7vVtAM/aMKknyg73gSjTaUGFYo3gEDTE0IARj/5w6eeh2Mb1DiE5aNP/sIt+KnxdlYAW js7w== X-Gm-Message-State: AC+VfDzzUbIgWDkKb6jwqagKifx2gQQicKFzti6rJJzOF/vK/EeFV9NI lbo7S2OITqUbKtak3v2jqu7YIYd/oOY= X-Google-Smtp-Source: ACHHUZ6bk8wsxPi2CO6Ry//dDv3J6w7VSpDN0W+ynAgt0XYXbCETpv309cOV7KiQRlvOMURiMuow8VTWjRU= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:5075:f38d:ce2f:eb1b]) (user=surenb job=sendgmr) by 2002:a25:d3c8:0:b0:bac:adb8:a605 with SMTP id e191-20020a25d3c8000000b00bacadb8a605mr6458407ybf.2.1687839815785; Mon, 26 Jun 2023 21:23:35 -0700 (PDT) Date: Mon, 26 Jun 2023 21:23:18 -0700 In-Reply-To: <20230627042321.1763765-1-surenb@google.com> Mime-Version: 1.0 References: <20230627042321.1763765-1-surenb@google.com> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog Message-ID: <20230627042321.1763765-6-surenb@google.com> Subject: [PATCH v3 5/8] mm: make folio_lock_fault indicate the state of mmap_lock upon return 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: 99C4640004 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 39fnsebufd4e16xmctx3jrz9b84cikaz X-HE-Tag: 1687839816-279737 X-HE-Meta: U2FsdGVkX1/oabjFS0SdRzNfTw7oyicjov/8Xc8/2IGXiFcpBLPMZc5P9y+96YC134gCOzlhG9vXvk9oi0KAhWkKeS3ORTUt5ADYnpAi5Y6WQ+U/doQdHryHKa4MRR8J+pfyaczii+q569qZtVvpHd6KiPpk0BuWWpGly0/GkyFas4orfeNwWAIxWnElzNBI4Ut/Pqb4e4rpgMjgWzKiD+IOVqBc8ChEHV0goBXM2Gdpr/48U7vTdoRmA3LtNuJ7g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AuexIx2kG7EEkMx8Of7NmQUd+rVLzbsiLNyCTzUwOkJdn1frZmXLu4pG10ylPVEOkesAVkdDbPmidAnvdbo11b6q3nZuIcqo7G5dHXBTW3aXdpE9Al6z3p1bpwV8tQ6ExyndGu1Coa69tw7MdtIDmG81mifq9EEvMOzxBIEd3Hag6fWbgX1CnTDcvrOQyTyds4K2uOyWjbjdZMepTCDZzSwB3HUQ0TPFcRRdZ8AxWJsz8BDeWpsAkYRKC4XtCSmbZ6iNpz0w+QR7M8SxKwqVHQbCGBTnVzNPnz1ExKigAWbu1xuQXQ1jV7uGxpcZ5NzXtLQ4SA== 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: folio_lock_fault might drop mmap_lock before returning and to extend it to work with per-VMA locks, the callers will need to know whether the lock was dropped or is still held. Introduce new fault_flag to indicate whether the lock got dropped and store it inside vm_fault flags. Signed-off-by: Suren Baghdasaryan --- include/linux/mm_types.h | 1 + mm/filemap.c | 2 ++ 2 files changed, 3 insertions(+) diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 79765e3dd8f3..6f0dbef7aa1f 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -1169,6 +1169,7 @@ enum fault_flag { FAULT_FLAG_UNSHARE = 1 << 10, FAULT_FLAG_ORIG_PTE_VALID = 1 << 11, FAULT_FLAG_VMA_LOCK = 1 << 12, + FAULT_FLAG_LOCK_DROPPED = 1 << 13, }; typedef unsigned int __bitwise zap_flags_t; diff --git a/mm/filemap.c b/mm/filemap.c index 87b335a93530..8ad06d69895b 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1723,6 +1723,7 @@ vm_fault_t __folio_lock_fault(struct folio *folio, struct vm_fault *vmf) return VM_FAULT_RETRY; mmap_read_unlock(mm); + vmf->flags |= FAULT_FLAG_LOCK_DROPPED; if (vmf->flags & FAULT_FLAG_KILLABLE) folio_wait_locked_killable(folio); else @@ -1735,6 +1736,7 @@ vm_fault_t __folio_lock_fault(struct folio *folio, struct vm_fault *vmf) ret = __folio_lock_killable(folio); if (ret) { mmap_read_unlock(mm); + vmf->flags |= FAULT_FLAG_LOCK_DROPPED; return VM_FAULT_RETRY; } } else { From patchwork Tue Jun 27 04:23:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13293985 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 887A3EB64DD for ; Tue, 27 Jun 2023 04:23:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1B6188D000A; Tue, 27 Jun 2023 00:23:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0F09C8D0001; Tue, 27 Jun 2023 00:23:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E0F1F8D000A; Tue, 27 Jun 2023 00:23:40 -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 C66CC8D0001 for ; Tue, 27 Jun 2023 00:23:40 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 92917808F8 for ; Tue, 27 Jun 2023 04:23:40 +0000 (UTC) X-FDA: 80947234200.11.4D567B9 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf26.hostedemail.com (Postfix) with ESMTP id C2B25140002 for ; Tue, 27 Jun 2023 04:23:38 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=SPsLrhIf; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf26.hostedemail.com: domain of 3SWSaZAYKCKYYaXKTHMUUMRK.IUSROTad-SSQbGIQ.UXM@flex--surenb.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3SWSaZAYKCKYYaXKTHMUUMRK.IUSROTad-SSQbGIQ.UXM@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1687839818; 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=L/K5IT4x+bKsumOYQJ+yi2cT1e5z+UZoZveNoih+cDc=; b=6Q9MYenv/Hz+pf/kTR1btk6Pe3e/CM2zosDQCfwLk8D8guiBNtxntp93C0vGTkaNYxFxfw ugDnEJ8+NlUjoAee/icG7xCwS9qKAqxpnLwSYO+eJT305HmcuftxgoZ5iVlxan7dAM4bES fstWEyyVkYwlJ48YsCkOMR2sYueGK44= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=SPsLrhIf; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf26.hostedemail.com: domain of 3SWSaZAYKCKYYaXKTHMUUMRK.IUSROTad-SSQbGIQ.UXM@flex--surenb.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3SWSaZAYKCKYYaXKTHMUUMRK.IUSROTad-SSQbGIQ.UXM@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687839818; a=rsa-sha256; cv=none; b=yAMuP57JzkffNpD1SmCxKytFbEVHjBG1Gf8WH9JH8a54g/5kXfpMYgRXKNkOdwQMTgLEkV Hq7L9Mf0NXw5uh9c9z9gyJAmIDYtWe1i/BRyiVxDNG0Z63HxLFhACl2791UpiNlrPv0LpZ HSi3BARCjEUKD99t4BfOq0IMBY5SzdM= Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-bb2a7308f21so5531831276.2 for ; Mon, 26 Jun 2023 21:23:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1687839818; x=1690431818; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=L/K5IT4x+bKsumOYQJ+yi2cT1e5z+UZoZveNoih+cDc=; b=SPsLrhIf+/FviYu5sa3cDiqhSS9nUO2CjK/9TugBc73fpzLKK7PAw7c+quZSTddlaF vZFybm/r8dGNnIepLjzU4IjRPPNo5Dyn4qcIKvLx1Ra7pU8Cv/EXd8r7DspbiwGRfqHi MU+3kIKCrT0+6JdwkeK19scpvS+xkXgrwyrrwzTvdmNJYgNZXtE3QZuG/vo4kg5AeGI2 bmnmp+IfBgDLtPSxL3LPcMXJgEk0vn02BtNF9KdqeRATk3kahh1G/AEseDofSFqqS0cB IngFLnBfekjj25euZhbjVOsR2M+c4gYV9YLPJZnMZCSFvyWp7HxKSX62DnyRwsvBkXkx 8M7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687839818; x=1690431818; 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=L/K5IT4x+bKsumOYQJ+yi2cT1e5z+UZoZveNoih+cDc=; b=ZMUkXTqvOFF6jMLKmrRBLFm4GfrQue5HE/CwK4YZHPDaokdrhBLYJ+HAYUto2taWWm ZsbnogILHP6EQIUJbZilai6c9KUFBf9K8L3DdZJVG9nRtXQulRtLHIFlb214X7/m7LVB RjL79BraacvT8N9+Jk4si/kvOlGK9FNZ1n8kIzeCuiIUC2OcF6ekuZDPGd5TXlvqbkrT 87MJtXVMTDz3h3iaVd0G/fyWXJ07AuR5P6kN4G4PbXaQ8OOUyV0l49QEUiZ+23TewbES Jw+m2Pro/1qU/CRw7NM3JiyDF62UIoPTANYe7/N71pjHrP4ZEflTVX1E6Yxx7Vrc535e A2mQ== X-Gm-Message-State: AC+VfDw5IReczChjPuJE5UIg81zaWt0ppvGLZXooGSRxQAuhwna858Pe 4Cu9ocxYbfXzaSRoWgCqXbz8UVfG414= X-Google-Smtp-Source: ACHHUZ5LhiNy4/UmnJHGuxwqmDS8M96KwdM5oYuqNif7TJ8z9OhcGrThYwi/uY+L/KRajOJ6sRKDPRQ1ACQ= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:5075:f38d:ce2f:eb1b]) (user=surenb job=sendgmr) by 2002:a25:e7c2:0:b0:c1d:4fce:452 with SMTP id e185-20020a25e7c2000000b00c1d4fce0452mr3205627ybh.1.1687839817945; Mon, 26 Jun 2023 21:23:37 -0700 (PDT) Date: Mon, 26 Jun 2023 21:23:19 -0700 In-Reply-To: <20230627042321.1763765-1-surenb@google.com> Mime-Version: 1.0 References: <20230627042321.1763765-1-surenb@google.com> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog Message-ID: <20230627042321.1763765-7-surenb@google.com> Subject: [PATCH v3 6/8] 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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Pv6XDh5THBpXP/92Yt6M1hJNGu5 wbLwaX/x tM5M2tA7ODQnFs2DrBZZ5kwJn3lHw8o3l935vjPlvhdsPzTo6gxvH/r6NKQ6+Qja93/jiC1AJOWQAuBQFe405l0xZIPs6PSuMZfJmUqT2rGyNE0L4+mHPVgpSsRxLWLZRlvstq7i0rPMHXFRQnDWFCT8pAbbkaPIeZWnzhu3/ENZKtp2jou4muSWgAw4tupebCYW+OitaQOvUZsui3iMQQiNjLjswxbNnz8ISLzXf6JHmz/6NNPJQ9d90uK93nr7Zj2SI4Wq0quI8PXQemkca5tAGNQA3K/e5gok8qhgebuMkdFOJmoZEeIBN+gR3m5UuH1BAIZKjOkQ3WtdRWh16OfIwu+4f7kPA0x9FOp0XwnuokMBa1kWiQ/tfP7yb/CtAv2oTt1Zk4RBmUrG9HKg1tEeTRvTXUdtj1tAMn/BfomA7E3KLuCneYXY1lwacEZI7/doMQQzxnjGfplVFv1333IcsgLrun4TE47H+iwfa7txGHda/oKU3a9R8qM7bVtpJ7P+CQeULEsrsYecDQRouK31eWY1HzDpE5NJrf2oNe1pdYGkCZTlABV3HEOYzreTl6rmYrMHfCpgCPzH5i5Dz5Q9FkzPNIwiYVaAyC6LudGAwS50= 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_fault (formerly known as folio_lock_or_retry) had 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 in folio_lock_fault 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 --- mm/filemap.c | 24 ++++++++++++++++-------- mm/memory.c | 21 ++++++++++++++------- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index 8ad06d69895b..683f11f244cd 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1703,12 +1703,14 @@ static int __folio_lock_async(struct folio *folio, struct wait_page_queue *wait) * Return values: * 0 - folio is locked. * VM_FAULT_RETRY - 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. + * FAULT_FLAG_LOCK_DROPPED bit in vmf flags will be set if mmap_lock or + * per-VMA lock got dropped. mmap_lock/per-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 + * 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 unperturbed. */ vm_fault_t __folio_lock_fault(struct folio *folio, struct vm_fault *vmf) { @@ -1716,13 +1718,16 @@ vm_fault_t __folio_lock_fault(struct folio *folio, struct vm_fault *vmf) if (fault_flag_allow_retry_first(vmf->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 (vmf->flags & FAULT_FLAG_RETRY_NOWAIT) return VM_FAULT_RETRY; - mmap_read_unlock(mm); + if (vmf->flags & FAULT_FLAG_VMA_LOCK) + vma_end_read(vmf->vma); + else + mmap_read_unlock(mm); vmf->flags |= FAULT_FLAG_LOCK_DROPPED; if (vmf->flags & FAULT_FLAG_KILLABLE) folio_wait_locked_killable(folio); @@ -1735,7 +1740,10 @@ vm_fault_t __folio_lock_fault(struct folio *folio, struct vm_fault *vmf) ret = __folio_lock_killable(folio); if (ret) { - mmap_read_unlock(mm); + if (vmf->flags & FAULT_FLAG_VMA_LOCK) + vma_end_read(vmf->vma); + else + mmap_read_unlock(mm); vmf->flags |= FAULT_FLAG_LOCK_DROPPED; return VM_FAULT_RETRY; } diff --git a/mm/memory.c b/mm/memory.c index 3c2acafcd7b6..5caaa4c66ea2 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3712,11 +3712,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)) { @@ -3726,6 +3721,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); @@ -5089,9 +5093,12 @@ static vm_fault_t __handle_mm_fault(struct vm_area_struct *vma, /* * In case of VM_FAULT_RETRY or VM_FAULT_COMPLETED we might * be still holding per-VMA lock to keep the vma stable as long - * as possible. Drop it before returning. + * as possible. In this situation vmf.flags has + * FAULT_FLAG_VMA_LOCK set and FAULT_FLAG_LOCK_DROPPED unset. + * Drop the lock before returning when this happens. */ - if (vmf.flags & FAULT_FLAG_VMA_LOCK) + if ((vmf.flags & (FAULT_FLAG_VMA_LOCK | FAULT_FLAG_LOCK_DROPPED)) == + FAULT_FLAG_VMA_LOCK) vma_end_read(vma); } return ret; From patchwork Tue Jun 27 04:23:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13293986 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 70DC3EB64DC for ; Tue, 27 Jun 2023 04:23:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 07D9D8D000B; Tue, 27 Jun 2023 00:23:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F21C18D0001; Tue, 27 Jun 2023 00:23:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D99D58D000B; Tue, 27 Jun 2023 00:23:42 -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 C74508D0001 for ; Tue, 27 Jun 2023 00:23:42 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 96BA01A0841 for ; Tue, 27 Jun 2023 04:23:42 +0000 (UTC) X-FDA: 80947234284.08.424D0C8 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf04.hostedemail.com (Postfix) with ESMTP id D64344000D for ; Tue, 27 Jun 2023 04:23:40 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=uyhBbu35; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf04.hostedemail.com: domain of 3TGSaZAYKCKkbdaNWKPXXPUN.LXVURWdg-VVTeJLT.XaP@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3TGSaZAYKCKkbdaNWKPXXPUN.LXVURWdg-VVTeJLT.XaP@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1687839820; 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=S48dBfG0SWV0QU4tyl9ann+yNi8sxz8gZYLMNRkbGeY=; b=ID11nKKiljNhQM0s1xcloQ0BaaXSpr/+GEuSeCUXqFuev1dA5JuxNFQ0aAA95c69in/CBu sb1tnykmsIIfZGe3ZY4Ze5/PW4XFyXFaj60VXcnrmywWn9BELTs5ggYYdvLYHujMpCh2Ef cwlFP+xE06tn3zndqcQ878ZqALb6TD4= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=uyhBbu35; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf04.hostedemail.com: domain of 3TGSaZAYKCKkbdaNWKPXXPUN.LXVURWdg-VVTeJLT.XaP@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3TGSaZAYKCKkbdaNWKPXXPUN.LXVURWdg-VVTeJLT.XaP@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687839820; a=rsa-sha256; cv=none; b=JrmL4drl8NdGd+s/ZtImQJKoC1ct/peC56ZucOxBoiKX07Hlg40uo5oNXZUZPdJ+lyuoUT g7Os/NXR0CDqSQMm2U17qklijP0bCabkFWzdczqrSEWplzfng5x84aBAQ2z0VEaCEBhImX ovYss2gV9VxQ8VxlyHW9UHHgTXHLSrk= Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-bb2fae9b286so5206590276.3 for ; Mon, 26 Jun 2023 21:23:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1687839820; x=1690431820; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=S48dBfG0SWV0QU4tyl9ann+yNi8sxz8gZYLMNRkbGeY=; b=uyhBbu35AtD8uFc7lNVRhrhL9FZssNEc1U3YlNjnS6/vWb6a5ERBcwBMaYSPxjJ/Mk Qe5HTpNa5XqvLjiojjNbFmZN0xmWKkvRVR4N08jGcpfsLakGmZkxol+hWOUA2MEdPtG3 CCWMkRdx3oFd6/Dcq2ziTDhiHH5hTD+8UeRRw0fdTOeqAixqf3jfdQ7B3ZgYpw+aT0x0 7n1tbaJiroElOh+0zEGZhbUInAo3kZrsUt6r5yZG0ZhF8kLRGvyK6fttt1xmJKJlC+bc 8aGAiRC7PO3v1V82sW0UO8XGuG6YrM7whEZUcc8FMaVdHAxabZ1AEzNvmsHlLQ8otu9G mugQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687839820; x=1690431820; 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=S48dBfG0SWV0QU4tyl9ann+yNi8sxz8gZYLMNRkbGeY=; b=gCFbbi05HUl9fr9Ep9jofLodsJzhB0Yk27+eEvT46a+nRp1+Mn1UcbomCBJS3EgwZF HlCKOlY4f0yYMb6ghhcvVF8FBUctRO/aN8kNqOYmziiq9AfvaAVeYmTDrh7wn184USCR arF//pqFyUqba8ohclH+AaKMTlRIB0FR4o81OY3X8W3Pek7OxqH17EpwZGHGnOrvE+A9 1JkEsp4X3iUvdDiKYYWmLg075tw1XzljN7VFOuScgBuiQO8rvirW5wQOr1MYOAY0UAVd kqz1VOVg/Dnyouw5tJLko/f9th2FadxfQG7YUeOn0ry49Lj1ounpbb3+6HNcShmdj1Kt 4h3A== X-Gm-Message-State: AC+VfDyx7bjq4KIpK7oZubSKDNLjtgSkggZ+8V4MMB6yo6ttK1wb0gQG Wkdm1BbPQgKWWezpD76Biu5H3WVkkI8= X-Google-Smtp-Source: ACHHUZ7TRsCUwE2ZwvAugNjG47XxvELjQ1x8vS3tmisicM0hRabZmbuVIm5qRhxSsRS9QjFAyyEcLENdUAY= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:5075:f38d:ce2f:eb1b]) (user=surenb job=sendgmr) by 2002:a25:e78a:0:b0:bc4:ef98:681c with SMTP id e132-20020a25e78a000000b00bc4ef98681cmr6584157ybh.13.1687839820015; Mon, 26 Jun 2023 21:23:40 -0700 (PDT) Date: Mon, 26 Jun 2023 21:23:20 -0700 In-Reply-To: <20230627042321.1763765-1-surenb@google.com> Mime-Version: 1.0 References: <20230627042321.1763765-1-surenb@google.com> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog Message-ID: <20230627042321.1763765-8-surenb@google.com> Subject: [PATCH v3 7/8] 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-Queue-Id: D64344000D X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: ct3nw4m4n79sro8n984fht6gc4ch33di X-HE-Tag: 1687839820-32337 X-HE-Meta: U2FsdGVkX1/+0jar+Swu/BS+UNxjw194n/EoQiiIWsutLAiqdV4/EDj1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WsB+CFyMbP3yYJYQc+wletXFgXheCZ1amVHYF47/lMQkrRnvbM2VvyM3SdCk2G1973zM3HbYdozdBsphCOPWa/j2WtzGxe08e6nLhXeHDZNsIsJkNSCmuXpqRZKRB1VH2FRt8BmJTycfqj7or6QM9lbroJoTW7TG50vjA8LQ4zUZYzItBQURWOWTvmEuXfzTDl/girG+tVcr3PqHkJjU6LReCiT+9vGQ7NOKLinQo0W0ZXAcRvCWXujmczSk9bPyBWtUNZ/1/27Uv1G36HJLs3568ZVTcshxs2/pfod0HwqY/D8tBlRq6wRbsDXH8Wz3iANh5z5mZ1PVeRTnp98YlfbqxtDYQuMQ0IiVQ3a95rxFMfiYvJyjsvv6NRy5nImjFTDS2fZoEvAFquqbkJmvszcSe0HOG3mqgf9pstoQeFCqMDYoWd9HaVB/2zk/US/GNFxkJwXQlPJAXxs/8Po4= 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. Signed-off-by: Suren Baghdasaryan --- mm/memory.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 5caaa4c66ea2..bdf46fdc58d6 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3715,8 +3715,18 @@ 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. + * WARNING: vma can't be used after this! + */ + vma_end_read(vma); + ret |= VM_FAULT_COMPLETED; + } + 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 Tue Jun 27 04:23:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13293987 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 7B7B6EB64D9 for ; Tue, 27 Jun 2023 04:23:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 166F08D000C; Tue, 27 Jun 2023 00:23:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0A1B78D0001; Tue, 27 Jun 2023 00:23:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E0F448D000C; Tue, 27 Jun 2023 00:23:44 -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 CF6638D0001 for ; Tue, 27 Jun 2023 00:23:44 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 985F41A03F7 for ; Tue, 27 Jun 2023 04:23:44 +0000 (UTC) X-FDA: 80947234368.24.065E7BA Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf23.hostedemail.com (Postfix) with ESMTP id C18F214000A for ; Tue, 27 Jun 2023 04:23:42 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=HRPWGd1f; spf=pass (imf23.hostedemail.com: domain of 3TWSaZAYKCKocebOXLQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3TWSaZAYKCKocebOXLQYYQVO.MYWVSXeh-WWUfKMU.YbQ@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=1687839822; 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=Lr5SfBQGAifcALE2slHdUCY8qB9p3T7NgiAWq42Xuxc=; b=oyBW/3loY0CV/0rrqBZVM4MIw4CSG7ugUnxPnxi8UMfkFcWBZABzT4sMKUoRwzfL8lrNFT EEyFygd17oYCOlDKdour9iuv75dZlXCkV8srkdnvcsYhajMY4PFWWSgFDylggA+MN1CudR T+GN6+UpBIyWp8Lqt7N/uei3YE+gnfw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687839822; a=rsa-sha256; cv=none; b=diOaFaUdnareZtC3gBK1bVpXT0TJ80UIOHMryPAWSawJfg8pg+jqbl377QBn5RsUGvQLJI hHkGRUCg28LaUGkH0bUz/i8/eV1WK7YwCWB8b4gIc3tkHRR7IgCXW1glp1t1FSeG44W3wa akDZsko3oncwcp5MRR781WYevOugqlA= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=HRPWGd1f; spf=pass (imf23.hostedemail.com: domain of 3TWSaZAYKCKocebOXLQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3TWSaZAYKCKocebOXLQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-bd5f9d084c9so4381389276.3 for ; Mon, 26 Jun 2023 21:23:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1687839822; x=1690431822; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Lr5SfBQGAifcALE2slHdUCY8qB9p3T7NgiAWq42Xuxc=; b=HRPWGd1foVC0TIQog8by8o2V8v8sJUL0qEpF8wD/s++kmHcbLnW9YsASla9n/li/yn jAVoOJuXYj+89+BkDU6C7DR87/c5I2Xe7AUt5OkB4Vx+il4OJL1UCe8wo1BahbtfS+tM +TIjU6wTLeLvtbx3yRAqe+pxoXluESKq2T+f/WXJ7whSwwQzfC1S58nYgZEbfoxC42G2 cOxhlNeMNxCCBL8LKTRY8Gro4C7H4cVDDp7MvXisijQEL+ExlO4Z3Tomv0kO3XT8qUaT oJlcEThRU2WvKg9M91CG55+zV88WNMwVprV9PiZ+i5YWzMxoB7iBW977umhZZsFn9Nyn UwSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687839822; x=1690431822; 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=Lr5SfBQGAifcALE2slHdUCY8qB9p3T7NgiAWq42Xuxc=; b=g+kx38jiUpM/od4ie1++vQZT4KPGCfzeZLwR1mi3Keqi7eZG5ROsnQN2URAU6irl2R up/zAmkql5s8HgRAfoFA7t2TuR+KL/q9T4v0QAuD84kKsZVv2oCqeAihHmmoe55v/Ako ilxDsREg1n5uKXYHvTVuJgryzizbKy8umHTAObyUrhw/auW7dkJ1lYhmEXVzTQZsVAvZ ZcWSJECw4TwK7zrOnLh0tZejDRCjrQqIulcsgSufzLRU1+ahrO8tOXrpwjh6gJ6A6Gl2 TT/ePc7yKa6fa8fH/QiGlKuHGM2vfwDum5f7Gr4PCDQM+Un53mBAtG/BTPvAJI35FSPi 2n5A== X-Gm-Message-State: AC+VfDxnwgPHWVqxtbPyQIM1C0oCpH9g7lX5LLcK1JZ7/Qq0DTksg62o bK/xaP9K22MagScMXhQv0idNaLmlZNE= X-Google-Smtp-Source: ACHHUZ7ZrkP2eGvIORpom8C2PklGU9Puo2bqG/qIQ+eaEnnHLQXFfj/ZvexRg0ciCojV4a3OpKeuYZMwT6k= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:5075:f38d:ce2f:eb1b]) (user=surenb job=sendgmr) by 2002:a25:d658:0:b0:bbb:8c13:ce26 with SMTP id n85-20020a25d658000000b00bbb8c13ce26mr14013293ybg.11.1687839821918; Mon, 26 Jun 2023 21:23:41 -0700 (PDT) Date: Mon, 26 Jun 2023 21:23:21 -0700 In-Reply-To: <20230627042321.1763765-1-surenb@google.com> Mime-Version: 1.0 References: <20230627042321.1763765-1-surenb@google.com> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog Message-ID: <20230627042321.1763765-9-surenb@google.com> Subject: [PATCH v3 8/8] 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-Stat-Signature: 3fmd13opckxut6kf9p44misgpc17skhi X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: C18F214000A X-Rspam-User: X-HE-Tag: 1687839822-332589 X-HE-Meta: U2FsdGVkX184lTr/11XwwY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RQ80FUdIwzO3OfwaBs0UHGhLwnW+fEFI5jzgKlzTYshqSmi9zI41043yqjDyCzBjXbnO3acW8bNorO43KXgx3zrTGLrRTUmWMZlf/BdjWB1SIve6Npvm8j26tl9PifYXfu+TJaW3BKCesMgND/9GhpfGNShS0T7qwOcq90OTjdjpjMJWww9RAOWrTTv8LolbU5JSzRrtMEpDAjqXelEI35dv/5ogTbExWIjaoTQWmcvgUePWa10x/f4+OGMbadgFl3x9hwz2Sdjd65CwBIhcttgxTYrrNiWyxQ0avMQcXoWusHHdxnoez68zI9cw/f/Tu68fmZY8h7f7/NTxIW5ouDCnH+n1uZJdwDAe33PrFzr82+pTr/Lfui65Qkvh5X+4/v4D17aHVZlQZxslDBcWq8KlpzXm6hGpXUzRF/m2EuvTracH7DsxeM20vLoiRzZEF8+LsSheOiuz7DQUImJga00BXnUipWQUBvicAK8fbLwbvDjeBEppoxGcxoAjE0= 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. 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 4e800bb7d2ab..b88632c404b6 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) { + /* WARNING: VMA can't be used after this */ + vma_end_read(vma); + } else + mmap_read_unlock(mm); + vmf->flags |= FAULT_FLAG_LOCK_DROPPED; 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 bdf46fdc58d6..923c1576bd14 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5316,15 +5316,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);