From patchwork Wed Jun 28 07:17: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: 13295271 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 85867EB64D7 for ; Wed, 28 Jun 2023 07:18:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E99A18D0005; Wed, 28 Jun 2023 03:18:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E49158D0001; Wed, 28 Jun 2023 03:18:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D10868D0005; Wed, 28 Jun 2023 03:18:11 -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 C42128D0001 for ; Wed, 28 Jun 2023 03:18:11 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 847621A0B56 for ; Wed, 28 Jun 2023 07:18:11 +0000 (UTC) X-FDA: 80951302782.24.8F44109 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf24.hostedemail.com (Postfix) with ESMTP id 357CF180009 for ; Wed, 28 Jun 2023 07:18:08 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b="0ku/s7JO"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf24.hostedemail.com: domain of 3r96bZAYKCAg02zmvjowwotm.kwutqv25-uus3iks.wzo@flex--surenb.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3r96bZAYKCAg02zmvjowwotm.kwutqv25-uus3iks.wzo@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1687936688; 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=KMxqHAnxOZxMzgoGe7kH228DI7ZaEMF5Tfki0D7IS+4=; b=c3YjkoobkWkR8rm0pdnrV8JePeWlatO9XBIG1Tejyn2nP3hcLBe8R1vDRnpFHBGbtvQDEL oNKQsoCjYcTMur/jrbNDA00ITh9DHDeFOhc3HJWbsNlkycCB2xgVS3hdVLLiUH821t9gFp axPmD7kFi+73q8hDclTNMsTagWPQ2Zk= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b="0ku/s7JO"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf24.hostedemail.com: domain of 3r96bZAYKCAg02zmvjowwotm.kwutqv25-uus3iks.wzo@flex--surenb.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3r96bZAYKCAg02zmvjowwotm.kwutqv25-uus3iks.wzo@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687936688; a=rsa-sha256; cv=none; b=ZrZo8yGFw4RNV2zO0DPqz8rfQneD528CFaO5XwKyITAEj4KezCHKiZFbAIqfjDBS30lGwS EBc4MFL/gsL5GBJ99rPIFRBNfuTrSYe17Fr9m+Lx89u6vMtUQulpke7t/0K74ZMN7DWOTG lhS4YL0GtXoQK/1rmhmMpDIME8DRBMo= Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-bb2202e0108so7006721276.1 for ; Wed, 28 Jun 2023 00:18:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1687936687; x=1690528687; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=KMxqHAnxOZxMzgoGe7kH228DI7ZaEMF5Tfki0D7IS+4=; b=0ku/s7JOYS25Ssb/TK9mxmOCJZLqRDj28TLTN+62uIW3T4PAT40AConihZeYPJTuOq pBmwei8rFDKCDPJYQM/skpek57YiLQZ/I9oDiT8X2vG/yxx4Dm3IMC0Fyd5cTCXMjOid Hvts2kbEwT9xvJP59WbeiRbQhvsolauFOVtF5WAyU9YXglPphuRZ4vp5aNLZXnXNqulh Y8IrfvL6jaaFFk//+Cx/JuQEsx0g+IpMojHToC/AwAtitwx/DGOeNqxGL9NZxDh1HgHf YE4xBByujQnhsw5d6CLOwIuIStkTt0ijsqcyJU3qmVpzuvpNJRGhd9YpjjxbDugjGePG Qu2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687936687; x=1690528687; 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=KMxqHAnxOZxMzgoGe7kH228DI7ZaEMF5Tfki0D7IS+4=; b=KLcLiugxrTenbs+C/3nU4m8BhWRTP1+y/D5/6lh528dHmQdIIFRSNR3OJQ/Z4TadVT iJAhCXd6vGt4oTQzaQEI3pDVF49BdM4H+7y6eAU1+mjBw9nmalCNx+k0SbO11aeSfMXu Zi+q63XpuSSUcUp/tFNqWQqpRA/WyDkHmKL/ZK52dyO3Ozm+7FvCYWzwsa7VSX7LH6Lb fTBeXuv+dhvq15aIwpu00CV7AiYB1vDRGJAHUGNbjT5X4jojaIAzxKaK/z2U0FogRqgu DiXXUjr35g/gDVELrp0FBQ0mpFFye7O8u8y/JC4MaOG0LEXaStTDTOXhIGzS+cWakk10 dsCw== X-Gm-Message-State: AC+VfDxVoI7HMVxT4mSpEl7XKNomN0uscxKIWUvPSU6PC7CbB3JrUWT1 1dQDdysSvg1ih1Bkvyv0XVys9IySB4Q= X-Google-Smtp-Source: ACHHUZ7N2+Vdz5wzVt4qo3ORJk1cvXaFXFgrNn/dwhdlBeAqH0Ef2MJ/aZaUm1mJL36im1QJNi0z39SWTj8= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:6664:8bd3:57fd:c83a]) (user=surenb job=sendgmr) by 2002:a25:ab82:0:b0:bb0:f056:cf43 with SMTP id v2-20020a25ab82000000b00bb0f056cf43mr7882151ybi.1.1687936687271; Wed, 28 Jun 2023 00:18:07 -0700 (PDT) Date: Wed, 28 Jun 2023 00:17:55 -0700 In-Reply-To: <20230628071800.544800-1-surenb@google.com> Mime-Version: 1.0 References: <20230628071800.544800-1-surenb@google.com> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog Message-ID: <20230628071800.544800-2-surenb@google.com> Subject: [PATCH v4 1/6] swap: remove remnants of polling from read_swap_cache_async From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: willy@infradead.org, hannes@cmpxchg.org, mhocko@suse.com, josef@toxicpanda.com, jack@suse.cz, ldufour@linux.ibm.com, laurent.dufour@fr.ibm.com, michel@lespinasse.org, liam.howlett@oracle.com, jglisse@google.com, vbabka@suse.cz, minchan@google.com, dave@stgolabs.net, punit.agrawal@bytedance.com, lstoakes@gmail.com, hdanton@sina.com, apopple@nvidia.com, peterx@redhat.com, ying.huang@intel.com, david@redhat.com, yuzhao@google.com, dhowells@redhat.com, hughd@google.com, viro@zeniv.linux.org.uk, brauner@kernel.org, pasha.tatashin@soleen.com, surenb@google.com, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@android.com, Christoph Hellwig X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 357CF180009 X-Stat-Signature: fdeekhnow3jtry8jjphj4m9u3qom1x4y X-Rspam-User: X-HE-Tag: 1687936688-84787 X-HE-Meta: U2FsdGVkX1+3PY2NSw+CqPL8yVJpjrYM6T3Q5oi1QNE1V9d4MDL96fSfF7U8KqSN5rBk8t7Cn31qFdCivQs1q9MAmYqWaCp04hhjkxQk6QAuoZEK6F5LifmxrqCz/KjrpnXuAtTuFVnaeaC2TLvAHhC/Z6ddma0z8md1bN/MYTPZZ46YyQoTHqJsBsaHAfcRzQNxWyB68hDQwMJ3p36whd5a47yi9iIoPeu/zHOXA/0hcmMel+V/lIbImKy4ELvksGStL9tS0gJaEC1GLst9GUxXD5pYopnxc5Bc7UQkD2DddgZ1VVnv2l2tB582wf5orAsEr1tikuiniywaXQELnZu2v8r8uZO7AwKFVdSP3a4Usma9X7LICvnldqvq2Uz/AjdXmg87homb9VstH2jBdIqFETga+ywhkrr6SFO0k/6jxLxhVCPUsHSUGBSoyFvUrqN/g8rfYrbg0+xOwYwmJ1ZIn9Ktc4plrIyP+MoBgAZ0Q/+KamNpeTn3sqWTcAMsxGdJx3UGWIjUD7ThHn50DwVcmY6nGyTONJ95QxKp9mNi5EFeYpEYajVf+4yTKd2M4lipLx6Wh1YGSnITfCyFgqw7VkWtArpyF0TY76O9mbFV3mahUzU9CKWavR9FOwxN0lySF7c6/fyJHX9x15o9tkZ8uJJkYzXXdr33ylZ6oT8pTfUIjomt+58lXjwaNBlVVxx6NSGIiHbVHa4J3uS2qy7+XByjD3V3FfyVDGMVINmLSZ8PABVSyLtZNaXh47QOAkM3RhK3ZBo04Z4yUntpGKSSWuY2Qlq/yHPbRRvzOS/Ut11lXmRKfLAT901nUk9hTppHhiKCGmY/U57+O/S/zQ6J6CnAwdw/vPhCvKvzK39LNoE/mJ+VMW36giujnDt4S4TH3lb1skRSLgwlGSpZflEx1zmCPw1KQmcEP9xIgSozuNnNzLgw+oF/yC7PeLaLASJiqyyZiSyLx1AIZLQ 2rKIWZja ybi34NBuuPlk3N/PGK1gPQkz7CR93W3thpQwj/aK45qE2i8/CLR9/Qcc9VL1bPYPB9fFjjTMVDffKW/E9mKi+PokTMQ2AcPah9eYk8ElL04t3CwrDM3skT9CrtUFbe6LiTlPA80vzcRqjqPRTn3yM70r6OL5HnF7KTVcj2uHKsw/ew5h8ROOTShcz8vp7wqtY9x26LSTmukWjv1ZdW1AWzSRcwvtAdm/0bUUJc2Af7jpmNPker4kjXE/2B6kCmU8I/lK5borSNgZvkYJr+D/FQvxMzvkLHB/Hzv4MN5Xj37pW+kftXBJrBN2c4ZlaRruazDWT2nHm/nKTkEo2Xdxnis0s2XnpPQElU/gAphArSxocLy7Q0lDq/UQd9A1rJDknrPj2zfjibD/BwLlYRhJsmXxRfDb+mS+LzNFspmbvrqHHGgT62cdPM0BmRRodJKWf/gUClERc1ALizKs5PeFaiSzLkNOttNbHTfUV6Z7LguzUZy2Pi1/PoY37NarzjnYTGL37AfTqlcGQBI6Zn5y/o8Pd3Q7Q/uUKRTAoerQ0YgUntwoUz8pOBYYI6R99uPVh91YwHg65UhdB958adFcIPT8XVkAyioakDDDzHNI2q8Yw4jJFzP1bYPpyGXT3Eb0sKGwDzop0O/ehLTmt9y7U3CzijcdtmiGsWbPezBMiTXbGxaVZXCQZZgVAXQ== 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 Wed Jun 28 07:17: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: 13295272 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 96735EB64DC for ; Wed, 28 Jun 2023 07:18:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C52AE8D0006; Wed, 28 Jun 2023 03:18:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BD8EF8D0001; Wed, 28 Jun 2023 03:18:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AA1898D0006; Wed, 28 Jun 2023 03:18:12 -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 9C9C08D0001 for ; Wed, 28 Jun 2023 03:18:12 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 6530540BD2 for ; Wed, 28 Jun 2023 07:18:12 +0000 (UTC) X-FDA: 80951302824.16.0A5C4FB Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf26.hostedemail.com (Postfix) with ESMTP id 94E4D14001D for ; Wed, 28 Jun 2023 07:18:10 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=A1ANSxFM; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf26.hostedemail.com: domain of 3sd6bZAYKCAo241oxlqyyqvo.mywvsx47-wwu5kmu.y1q@flex--surenb.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3sd6bZAYKCAo241oxlqyyqvo.mywvsx47-wwu5kmu.y1q@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1687936690; 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=83rYaWFW6QNQhfB0rTt9RkG69OVxHHwKFqolT0xWQu0=; b=OIv14CYx7dQiLBU85ZI1ErbqcUZWzPtIeJpPGKid3+6lec50fuf9yiatTMutaoghy7Ty9K 6AGbvFrYxOb9n3Acl3B8lumJXlkQllh6Ldk1jDHwgRhf22cl8XqdQqwSUu4euTOdotBqJf mcWluD3xJagaafjQFS/XCaNYiJPifU4= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=A1ANSxFM; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf26.hostedemail.com: domain of 3sd6bZAYKCAo241oxlqyyqvo.mywvsx47-wwu5kmu.y1q@flex--surenb.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3sd6bZAYKCAo241oxlqyyqvo.mywvsx47-wwu5kmu.y1q@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687936690; a=rsa-sha256; cv=none; b=WGfGbMRrbzto6DS7/bmr0cmmnVP9CblFkhdZI1Iu/flN1TaNFrO1T1QdrsE4tIYeqehKDR J4udXRVoH1kaLsLY+OERymaOtPKUJ/iOEE7BVi5+RQj/MCOBDfAEow5YOKw46TOACPfXcN X5Be0p8o4KpMRSNJ/zUXEQ2+effMCIk= Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-c18ebcb4358so1335793276.1 for ; Wed, 28 Jun 2023 00:18:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1687936689; x=1690528689; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=83rYaWFW6QNQhfB0rTt9RkG69OVxHHwKFqolT0xWQu0=; b=A1ANSxFMJwxMrIdRAByxDyQ167BBa5j6JMYlqmL9Ri6TbTlIO6j3CzCcAuSQpmTi14 1U85kDYreNDOE3qU8Lm5XOQzw2+xn9p8MTkRPGy6zp/20ZnCwvQMGgcl7AFr9VjonIYi aL2HAmXpIldY/RoXFqH5QWrwSVYAWNdSsvD2WcSyV3A5Re0CZz8OjnuDS+OzHDXYco09 V7FtT4AcXnTMoBc4Mt/svTeWMVk8jd8vgQHgKD8QUGoDHMzxdX3udCfBfnhl0hjp+egc 9atjzOSMiENEWHQvYiixzgDQYjxgPaY0+QJDtmqUfojAd0AvoDfAwGWE/vbhYI6l0i14 FvTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687936689; x=1690528689; 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=83rYaWFW6QNQhfB0rTt9RkG69OVxHHwKFqolT0xWQu0=; b=Le3BYh+CWXcrmlYU03dVJ1+eHaG3KV6WzJbsOLz7whgXAMq3C/XqzLKi+Nc+G3p9sr 36Mzid492ExM+8pnsjRNC/NVjFwH9b7ZYVT50PLLiCbd44Z733e9FBOqrxLZdX4S6Pza 6YaeEVNta/RbICkR2cJ3CUdD1ArhtFbgDEplCuZvEYXBT3tHWtFuNTwjgSCyW5vkucDA UCpru/3u1V4oaFPSdkVNOdKgVpBXZ5YYc8bIrCLWbVyNXQwscO1+5OCJUb0FWrKPbDRi IgOlzZAjlMm7Kv0J9ND8KdqvkyxvZUCst4rI8mxgJRvoNhy6tArp8Ud5hX6XVWTU9aqI dh4Q== X-Gm-Message-State: ABy/qLbSA36zCT6jMGbWiE1aIA1Ik4Bb9NSebyZVWjkiPQffcWq8QinW cMF11pQtBq7Z4M+KoTcEvLRxkncnjcc= X-Google-Smtp-Source: APBJJlEw1+A/dz6nNLU/xIoq936J+gnmtGHgb4WKOZkDIT7PH8urmhAvh0DMqKPzkAG85bCaYotcRGxUtQE= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:6664:8bd3:57fd:c83a]) (user=surenb job=sendgmr) by 2002:a5b:512:0:b0:c38:993b:3be5 with SMTP id o18-20020a5b0512000000b00c38993b3be5mr245ybp.0.1687936689805; Wed, 28 Jun 2023 00:18:09 -0700 (PDT) Date: Wed, 28 Jun 2023 00:17:56 -0700 In-Reply-To: <20230628071800.544800-1-surenb@google.com> Mime-Version: 1.0 References: <20230628071800.544800-1-surenb@google.com> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog Message-ID: <20230628071800.544800-3-surenb@google.com> Subject: [PATCH v4 2/6] mm: add missing VM_FAULT_RESULT_TRACE name for VM_FAULT_COMPLETED From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: willy@infradead.org, hannes@cmpxchg.org, mhocko@suse.com, josef@toxicpanda.com, jack@suse.cz, ldufour@linux.ibm.com, laurent.dufour@fr.ibm.com, michel@lespinasse.org, liam.howlett@oracle.com, jglisse@google.com, vbabka@suse.cz, minchan@google.com, dave@stgolabs.net, punit.agrawal@bytedance.com, lstoakes@gmail.com, hdanton@sina.com, apopple@nvidia.com, peterx@redhat.com, ying.huang@intel.com, david@redhat.com, yuzhao@google.com, dhowells@redhat.com, hughd@google.com, viro@zeniv.linux.org.uk, brauner@kernel.org, pasha.tatashin@soleen.com, surenb@google.com, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@android.com X-Rspamd-Queue-Id: 94E4D14001D X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: ps9a4a1884wecizmrni3e3myr56f7uqf X-HE-Tag: 1687936690-327882 X-HE-Meta: U2FsdGVkX1+JlrqKEK77Hyr8wDorS4/DiQzuLeJwpqw0G80vjJz8w8fXy13RQDk3MVqilLyrmAPZwKwjZCqa/hNytEp2QWX2eA6w3vbQzPFKwBO8O1H7Z7dZ6EDdJ/SJ2AMQSTashnHEjx7g0oHtYAKxkbyit/9WajpoIA2+JFPvfSJ8VUrktK5wBNNqhld2oboEXZR2tMjGAMrZVbRdWfYrcIpDX6opcX1VvxrKqBla0Jkc3jHbEtGHHmnZnpQs0VIDSpkgVzJLsgytyXtG0YbvenHlkXqsfzZKVzz/SX3Ufi/EPcy8Svu9Xio2MUgKS9bc+75i+tgSsf4cAb0vUvuqU+bOWc/uL8hmvspMpABRbmsGA1w9By7cPG/ED3YXvDC12QfSlok4FHVsreBsETG5ackwRzgXvjbcj4n9UKrVJU8PzDxZeNdJv5wYIZFjWD9wA7uM6WdBtEj9oEMzu8d9LttBWkbdfgnve42V6509zjTPTKGraQpAI07c5i34OZ+wLp8EHqSYVtZMaa59PANPdQzVFwQbtNNt/GR+u/SHFMAGb4WRq0b1vYxL0EDs/HTzkM0fR7SyQy2H5KbSBESso5wj3oIxXR9DYGIJ32cLDgNuuraMG4VkCn4w7yYFwDA0VlJuQVj/iNKGDVB3RctpVEXdoEThnUVpTSsPJe4tjyzkbAqHn4Wpj+0iwS9ILBKcfftcDNNbhLvSbq4CnNQeB0L7W9iIU6Jbx+fNkNZbDi2dWNfFX8ezOnRjeCOLji6JgTJcoAnn/ZvbzDtTOZt3RLfJiV8zttTgae6eCess9foATXH/dJM3Uihsrk/dGLTss//r5MXXUuQ2QZ9T+PMNV7t1mJ8rQUgSa9D6s7KV/eKjr41+eDL8LLG+PbAqGdlKEleVEq+OfHw/P1P2SsK09KULOGPM870zuUFNWu7levGX9tN7xOPsBBx5m7Gx/DgVOE9noFhsuCQzSWs M/vBV311 CV9UJLecfHLIqNlFDP6J/FPfn5AE9BQ+pWpyKGS0UkVhb/dF2nPuGw+ZtkWq49NfHUCuLxWq05N4yGa+IAvhS7ObL+Obafs1UBRSdHOY7B/arKTSndoJ8AQ6Qnv+jMSeXCpIVQx44Jz0kSq6OMatr+XvCftd81ACOMfZ4cBJH0QC7IhJ/JlV02mc0sbG7Rdx3vOeGoqa4wkJdlm0ccYOMbMThWggmk3TtVDYJ+n9ZvTjVGuFZ4gcF6sNYePGj+wx6b/zNXmRfUod8QffU4nnrajCQ4rkexZ1trxaaseAgHc47M4WiwTfu2e3IcQsV6PSqmbO9bIy4Jnnw7Y0YCajfwqThXBWjUMf3swwKm1mqsFLh/US1acJAwQEyu0J/beEQXIzZpbbhj7MOV8hECTQ1NItAMsbcGpkGbl+E35iWfh980xSq+6MjTqYiY2T+MBjstyUSMqhNU+4JfkPMEatw+y+H6ZCmTyNzZjDY4QDuoR3jtVW8TZZolFFMaVeJJAIpnrNulxUwztxDpCWfYA1ytX6Lo1vjbG1U+MgOiwajweS6O3zdcU3VKLxqpdUiFaSs5jqkvVWFF4CKpGmdvgdEZaB0okk6569vAcsCvYp+ZBbt+U3NKICFBw4docC+4rajlqVGkzOKsCsPYvVLZ9PG50YxCnCOgxXHfsWooAWZSwGo8lYgnMAtf3WxOA== 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 Wed Jun 28 07:17: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: 13295273 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 7BBE2EB64D7 for ; Wed, 28 Jun 2023 07:18:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BDA228D0007; Wed, 28 Jun 2023 03:18:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B62E18D0001; Wed, 28 Jun 2023 03:18:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9DC6F8D0007; Wed, 28 Jun 2023 03:18:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 906ED8D0001 for ; Wed, 28 Jun 2023 03:18:14 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 4A35EAF87E for ; Wed, 28 Jun 2023 07:18:14 +0000 (UTC) X-FDA: 80951302908.26.1011289 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf14.hostedemail.com (Postfix) with ESMTP id 7F7C8100003 for ; Wed, 28 Jun 2023 07:18:12 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=SLs76mkj; spf=pass (imf14.hostedemail.com: domain of 3s96bZAYKCAw463qzns00sxq.o0yxuz69-yyw7mow.03s@flex--surenb.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3s96bZAYKCAw463qzns00sxq.o0yxuz69-yyw7mow.03s@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687936692; a=rsa-sha256; cv=none; b=tVOwZqcGMNN2rHdayTVgF5eMEbC+JHqs3b1sjGwzUBckSKyp28MvAhig60Bha6ZkVkG0Zz ENhN1GZ809THQE75rRlAGScwXzkEuF+geK/DYJSHPR1XFRuYdZQi6hiqh8KZeI3nnWKb0V giCcbyQP9aKXOOBpX/vqDltOBWUE4Ww= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=SLs76mkj; spf=pass (imf14.hostedemail.com: domain of 3s96bZAYKCAw463qzns00sxq.o0yxuz69-yyw7mow.03s@flex--surenb.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3s96bZAYKCAw463qzns00sxq.o0yxuz69-yyw7mow.03s@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=1687936692; 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=vpZ4UoIowr79k29KU4+AhJbPBUsrrQbVzV/sKUpKyik=; b=N+1aaB68G4RpoPsE8kYvtE7PvWgnaIujgmO3joolgL5ADukmoDneJLGpcvcOA6lI3Zp5DC 73j3sWVwks98fvuRBuwRGPh93x01Pf6I4aobA5dnyDCIM9XCce7vm4QtDcwHgbmixn7wZB WN3abvNKxsWU9KqcY0NL+CnVfYEMQ6g= Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-c18ebcb4358so1335830276.1 for ; Wed, 28 Jun 2023 00:18:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1687936691; x=1690528691; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=vpZ4UoIowr79k29KU4+AhJbPBUsrrQbVzV/sKUpKyik=; b=SLs76mkjZS/IPWUFDrWe+WabTw/6PoyKoxnKx5c2+HkFLi1gsV2ZJRy/kBPEq4QB87 XXCvupAyakoRvJUqAGoahV38l60daziRCxaQH0YkZQJeum0l7cxZ9swxwKvx8AmgY0tI cjEEnGBFaiCx1/bU/pacXNB3McOE+Jk0Hg+xOlefDx0TtzXaRptU/gJksUoFQPPsoJXj izcVNfG+LPXBLJiFXsBGAKDDPYYmNba9jLKhu2cVp2Dpd1Gvc5i43PJyyrItFsO+BVJP czQYZMZ9+UVoJRF+70p5nESx05q4a/7PZSGqtMaNV3Jb+jUrhGMXtqVQ/GrAP+Eu7+7/ 6nSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687936691; x=1690528691; 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=vpZ4UoIowr79k29KU4+AhJbPBUsrrQbVzV/sKUpKyik=; b=OfKq88lvPHfdmX0+Cjqlwnpd5xOdQ38RYNTe/MFxMJoeFmcG9cOl0dQfRr3kUZGSok UGLGMFDcsB8gIVG9m4suo/Zw66NV+VVgEQzEGM+11zYirO3Hl/x+2lcAxSz7S8ZpZf9N E6PmDYzPeJN80xXz/LW3va14zVkVnHnxHDj5LGbKERW/Q3OFLlO+6rE1WVTQtKMzJyJr fTJiM2SsmpImCP5N5va/ut8tbQn9zzWwh1owAYM4wqXL4TPMQ8pT11XdNhylLI0w3SDe pV/cVh7jgTPWTly0yqgv1/U6nqjCwShFQ2fhKhOZn/irVZB8FCqhkUnQFby01ht/Br+o GeIQ== X-Gm-Message-State: ABy/qLY0xofliEMUM12Gs0gN/mbYze03nZMPRWRMFaQfysbbctc0iVSX ArIvUhwj6hZpdSZnOUJjrT+nWCbKIWw= X-Google-Smtp-Source: APBJJlFgJ2jRK81tWxhk4XDKf3t6TTIa6oT5N32m+JJJWdx/Y3G1ED6lRjtvxsVjVQo+TveZPkRF5dvhPUU= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:6664:8bd3:57fd:c83a]) (user=surenb job=sendgmr) by 2002:a05:6902:1105:b0:bc3:cdb7:4ec8 with SMTP id o5-20020a056902110500b00bc3cdb74ec8mr7690ybu.6.1687936691637; Wed, 28 Jun 2023 00:18:11 -0700 (PDT) Date: Wed, 28 Jun 2023 00:17:57 -0700 In-Reply-To: <20230628071800.544800-1-surenb@google.com> Mime-Version: 1.0 References: <20230628071800.544800-1-surenb@google.com> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog Message-ID: <20230628071800.544800-4-surenb@google.com> Subject: [PATCH v4 3/6] mm: drop per-VMA lock when returning VM_FAULT_RETRY or VM_FAULT_COMPLETED From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: willy@infradead.org, hannes@cmpxchg.org, mhocko@suse.com, josef@toxicpanda.com, jack@suse.cz, ldufour@linux.ibm.com, laurent.dufour@fr.ibm.com, michel@lespinasse.org, liam.howlett@oracle.com, jglisse@google.com, vbabka@suse.cz, minchan@google.com, dave@stgolabs.net, punit.agrawal@bytedance.com, lstoakes@gmail.com, hdanton@sina.com, apopple@nvidia.com, peterx@redhat.com, ying.huang@intel.com, david@redhat.com, yuzhao@google.com, dhowells@redhat.com, hughd@google.com, viro@zeniv.linux.org.uk, brauner@kernel.org, pasha.tatashin@soleen.com, surenb@google.com, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@android.com X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 7F7C8100003 X-Stat-Signature: wxm7c3zr3sf1mnijtb5uncbj5h5aoj9x X-Rspam-User: X-HE-Tag: 1687936692-578327 X-HE-Meta: U2FsdGVkX1+U4D21o+cJkpAS02oqZIJ9i03bMyJeQGTpKQFajQU5ALrpIIl/xukQ7ff0nJAA1tY9BU3lN9b6k6kzHAbfI4MWvQ7caNl7B/Hk6Yb2ogcJZZlokmYUH44tUYxcJW2bHCeWFJeC/6wDPDcbcAiPM/Dv9w0dcXPywnIDECrGhLgPo7z+i/+DwEBLsBFtNhoiP3UsBiWhEBebYB24kJp/2R4deMl2bRfKVikiw4MGl9AynrtNXEf3Un6aOs9Prel2+NcIgt66T2/eSxPrEwg5dDLS/S9HTyXIwP0x21+G+TlwQ2BlzbodiovjS88mRFW64Npzho1CnvnC9eeZR5hmqnJE9CR5FeFA0nBEk+QJi0CSn+W15fP1CS7Wv1EJMwr8JF8YlURU2jzDg4q6Oxzjx06pHvETD8HmH5N+bUvgoDljHuYJlkwzdP5Oo34w+f/TinprVtoZS7UOfehaqknlzFSTfaAlNjOaE6pwPl3bufo8pc+BqsM66xhYt8ZM30E3bXQQ2RoHK/d2NvBBCvrxPemviRn/Zk3WsZxgXnOiLjOwMAHcg/Af+iSwYSYiyKzzj3ioVjag/ktBKiamliN+8OfmMPZwQbR9VSoCAsQrAG12WLniDaWtGa5Fz6znj5Tl85T8HEd0Eu50O2JbkaEPWd4qkifcIjebds3/VfUXKyQ9lHcdOQ9pvo846JZbEbCFND6Yia6d6wig2bpBfDOWIpxXFAsCmbi8G6meJPdKqRwq+qyFh702g7YyhEDle7rKtIMBVnRHhlAqaYqhJLJ1UDw5TQsMkl6MOfjEPGZ+jJdOA+ejMZ5jHCErhghWdSkIxpuIrkgf+T94tcJVM48M20agLvPfSMbkasd4544rsNo+G0K47T9BhZNXIdYgBKVKW3GgRRH8vIxtPL+D/9YoSrdqr873DrqXrgAvJ17cmdcDLCEah343BbgHpdd04GF8M66RPpAdYGu z9FmmpFe kVIXhzY9Ukohbd0GLQ8mIDdf9DU3mKQH+LWucJP1A590LBK+wqAV9jb+e8+/uMXIeh9FnRB3beRhr/nqGvxrpsM+rjK6a7/9L/IG97DypwVOPF/xkmJvfHf3R/Jzxxngjavv49jY5GGMrxpXAVgUQP3iRc9NC8GJZCTwVZCIrLZffCsq9khx3+eKAUbRV3ucXL24lDoPQ/lkDGw+/XjNmWDJiI1ozxy3mpvjz0XAqd7iabnxS0tQXJWlUup+LKAgB3oHKVTNe1KnS+tfxE4HtA5r7F3DMk6TFR+zwJc+1Nwr+A7Gwn2yoybbdcqs+p/WpgUrRkBadVbaebLeokH7d3inMhN43TAPGqvV8TFuhYsPOgw4V2AzYQNQixME/99qyiQjUGucBuPjRmq2X9ae13CQWwGk0FzDMD1MVFy3/01GbgNqYQWB7KbCZsKEyrCcnxiDCFJX6IgQ3c2vx1B4L0Lvs6hkvosCT3NG7v7pxRg5w40mLL7wxbGWQsbQotJxvGsJM52Cyn1XzVoRm5jcBH3pdUvQOc2lCXUqg0MnQSJ9c3lBmzUfmlNRRlOXuwHeuyvrz7ADL1BxCUCsdAtUBXw4+VmsdyHVDlb9+F7urNMp4yY4JPeYF/J+It6y7QxhCqHnYlaV49ak84wqbkq8hRvpGEA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: handle_mm_fault returning VM_FAULT_RETRY or VM_FAULT_COMPLETED means mmap_lock has been released. However with per-VMA locks behavior is different and the caller should still release it. To make the rules consistent for the caller, drop the per-VMA lock when returning VM_FAULT_RETRY or VM_FAULT_COMPLETED. Currently the only path returning VM_FAULT_RETRY under per-VMA locks is do_swap_page and no path returns VM_FAULT_COMPLETED for now. Signed-off-by: Suren Baghdasaryan Acked-by: Peter Xu --- arch/arm64/mm/fault.c | 3 ++- arch/powerpc/mm/fault.c | 3 ++- arch/s390/mm/fault.c | 3 ++- arch/x86/mm/fault.c | 3 ++- mm/memory.c | 1 + 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c index c85b6d70b222..9c06c53a9ff3 100644 --- a/arch/arm64/mm/fault.c +++ b/arch/arm64/mm/fault.c @@ -612,7 +612,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..f14d45957b83 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3713,6 +3713,7 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) if (vmf->flags & FAULT_FLAG_VMA_LOCK) { ret = VM_FAULT_RETRY; + vma_end_read(vma); goto out; } From patchwork Wed Jun 28 07:17: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: 13295274 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 8A9F7EB64DC for ; Wed, 28 Jun 2023 07:18:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E9A278D0008; Wed, 28 Jun 2023 03:18:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E4A738D0001; Wed, 28 Jun 2023 03:18:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CC44C8D0008; Wed, 28 Jun 2023 03:18:16 -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 B4BDD8D0001 for ; Wed, 28 Jun 2023 03:18:16 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 6A86B120C7D for ; Wed, 28 Jun 2023 07:18:16 +0000 (UTC) X-FDA: 80951302992.10.5BD1C1E Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf10.hostedemail.com (Postfix) with ESMTP id ADBB9C0009 for ; Wed, 28 Jun 2023 07:18:14 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=2j6rC6JP; spf=pass (imf10.hostedemail.com: domain of 3td6bZAYKCA4685s1pu22uzs.q20zw18B-00y9oqy.25u@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3td6bZAYKCA4685s1pu22uzs.q20zw18B-00y9oqy.25u@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687936694; a=rsa-sha256; cv=none; b=VK2Wo68uoeN6mmnJ9HLY/HmHXr1jTazTWZEz2dayEP1p283MqM/rs9NRZzzBf4ldrUztES r1rS80PXJRABuQfvXK2NEDVfCaeDMepeGmWSwrPFcieyjMunpZxlkTuLEpWg7nrtF0tS9q mr3JTTzaMIpLA3wYqENms5vMTtzWiLs= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=2j6rC6JP; spf=pass (imf10.hostedemail.com: domain of 3td6bZAYKCA4685s1pu22uzs.q20zw18B-00y9oqy.25u@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3td6bZAYKCA4685s1pu22uzs.q20zw18B-00y9oqy.25u@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=1687936694; 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=70kkRXsfLM/8BYxAf0BjvmYkgZM27G9ch/j23+KotKk=; b=t3irNISBc2MPlvJhrHROs0flWPl2PuSoii+gBZ9rZbZ0Je57Fi3mU9Z0NNgBPGFJXr4xui ZebAlRf9TM4NXXR8S/Bu+K9iAUjxdLoeW1eytG01mHFa5Le2S8+QHmRVns/Ktu+DAVD8xE e0au8COasHOJHtYu1P675gr0VQe5ThQ= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-564fb1018bcso75968167b3.0 for ; Wed, 28 Jun 2023 00:18:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1687936694; x=1690528694; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=70kkRXsfLM/8BYxAf0BjvmYkgZM27G9ch/j23+KotKk=; b=2j6rC6JPL2YZjVDNjSuz3XfLikJeKjCdOIy/hDMUWQUPhsVDGLQM+MPzx5VEdlFP0u tw9yulb3bHX/HNYybGu6MWDWSnlAve77hIC5hqvxjrYRhbozZ17KLrLgvT89FAn2r6EG 0JB59bf3q6b+kSXpcJHknOiZXeTuNJBA8QnapuoeA+oj8SEfuNgdIAiLdLl3GIuWcoXx V8EoIxH9py5ZVGwJQIZunXZLjOEfmySzy5MMfjsKPtv4ngFUclZxJpqeFEAbLEDJmHXy NK+CZUORLtGlSzG2HegFkG9DxXO3P7tbtF1tXW6/UhlOixp+bzIpA9nES6tPKWvBi/jD bXsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687936694; x=1690528694; 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=70kkRXsfLM/8BYxAf0BjvmYkgZM27G9ch/j23+KotKk=; b=VwejDwGv9YgS10VIroVFzye/r0jvBQc9Fv/A6dXKFz99ZjgEBkZLiTZJ4BIUkF1qvu UqnTdvTV8oQp8TMwTVZoUVx7BIFJ0ZVJ8TjpoDJ+0ZtDVRy51PUaJTyKRXB+zuC0WXZL jbMlV7lRq3p+SHyLpz6QT7tjVSTw1864LOZtm2Y6lYDPVzmvqQ8E6RlRHuHCoqmfqGUa S4K+yKMQpEI9wv60ddngaXmOdbjKZiBbLVm5HVXFLMb9xsES1kjLFrnUNxuANgaHv2lk QnIv3AbXZai1fhi+/fVfsV3pkz9s0CyTFX97kJLZJCHSY8Z1NX6qldOSayk6v9YF+8IA 4SBw== X-Gm-Message-State: AC+VfDx/6xpZno4Tk+5MjE9Xbgd6zoHWNQoi6ce2AkL1Re3tPVkulPFu BdkMBOgpy0mwmlc7wiKRizUIfRQhPd0= X-Google-Smtp-Source: ACHHUZ6OQi+GrrsFt6L2aYE+Bh/8JjB2CJChJJQK4V9w8+uL61Sq3ukd625ySw4N4Q1XugZY6mxhmwtxYNQ= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:6664:8bd3:57fd:c83a]) (user=surenb job=sendgmr) by 2002:a25:11c4:0:b0:c2a:b486:1085 with SMTP id 187-20020a2511c4000000b00c2ab4861085mr2504239ybr.10.1687936693767; Wed, 28 Jun 2023 00:18:13 -0700 (PDT) Date: Wed, 28 Jun 2023 00:17:58 -0700 In-Reply-To: <20230628071800.544800-1-surenb@google.com> Mime-Version: 1.0 References: <20230628071800.544800-1-surenb@google.com> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog Message-ID: <20230628071800.544800-5-surenb@google.com> Subject: [PATCH v4 4/6] mm: change folio_lock_or_retry to use vm_fault directly From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: willy@infradead.org, hannes@cmpxchg.org, mhocko@suse.com, josef@toxicpanda.com, jack@suse.cz, ldufour@linux.ibm.com, laurent.dufour@fr.ibm.com, michel@lespinasse.org, liam.howlett@oracle.com, jglisse@google.com, vbabka@suse.cz, minchan@google.com, dave@stgolabs.net, punit.agrawal@bytedance.com, lstoakes@gmail.com, hdanton@sina.com, apopple@nvidia.com, peterx@redhat.com, ying.huang@intel.com, david@redhat.com, yuzhao@google.com, dhowells@redhat.com, hughd@google.com, viro@zeniv.linux.org.uk, brauner@kernel.org, pasha.tatashin@soleen.com, surenb@google.com, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@android.com X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: ADBB9C0009 X-Stat-Signature: 6g7mi64qjgud3dxp3g4y74dadbqz6bjy X-Rspam-User: X-HE-Tag: 1687936694-877964 X-HE-Meta: U2FsdGVkX19IzJDtltBOrGPtA/qBA5QH8zBZqqBsNYY18t5/vld/Q8rdo+GRgYvpbRF7LiQH2wX09vSvzZtx2I7zVxsR5eQp1GagQauMN/c99nLs2ZnUSY8/7sNCvCRyy43YmsDhpv47UA6dA/w6gOP7owU8GJ/khvIhAinsH0A2UkPAC3VlHmjJP3aOLEnxUs928SSnDB3AGOkkz+ZB4bTtuMuV2Gt6ZvS/j7Nt4m1orsT5b5+Iq+ojojz72ZQzIDSon3W5WYYpxlyDp4JmvnqRfzchdF3w5ehgsJeUjEGAyAk/oDptCqsIIZryOoXS7v70IP8d7WPVsELwHfEheh9lJkOq7nwzykPkGPLGbpsLUCq6XM/DrbRnzfDs8fm5EB7XYgizJcvhp5CecB+nEaCl61CSdLUz3/yjhACxRogyhyaEHWqPHos9TdnEseO9pX9Y5bgLgv5FPnxKd3sJdmxLzjN/Vt7sK6bw3AXGitxZ9vyE5J8006zcqhr/nUDk4cgjMBZ+nRtYJjRbXGAH1kI6yDwR+JlXTd7PyTVrqyyYghuipuKnXMGPcKKYaSP4LQnKQzs+cAD1190iQkH/ho5amhQA//q9PBXz4sqCih0awcvO+lviwZUXeim2JOR5Hg2uIepHNmEnpT6KI3tkn8g5lkNzLIRnOh3PHDVuTahZ7h77ELPLUVcjG6iRJ4xF06lWJcweVLQvcV17omnS6GLCx7FPdg+RefI1WEP1ZxW3eIG9CN3X+hmAFhlG4dQJ8Lrul0yK7tk9384oQUGQbcdKcATmttuJ7uuhZ88rNqcjxoJ1lJYsHmxUo0Uk+OGuDjUQ4eYQsISAfU1Abxl/mBiFTcL/UFB35q33L3cgfpTTysQAeVPW/BGsMKl2Zldys5SiTUepXpdwWZX85BZmkBjC2HGNO2SvAF61tYJ8Bj4jbZsxNNLPOFHHZGPkArc24ytxDA758p7itUK6Fx4 ykcK29kA Gt9G2pE29mhvMuwICOsSc3sOpIw85lGK0XcuRC4mfADUA/Ku1ALohx0vfBIo+9WWU/+wDCbC5e9bq6SaFxfWfpFhrUDy18thcgDSnK1tegsCWr1sMEJDrdSAmRTkmTLy9oNueVglYMoAeuioriobh76Cmr750oYTBWZ9Q0KgPrWPwVZniwou5qZvcAvDAyUAyC6PKjL7hwK4sUj6X8LrIG3co4vHxzexhGvDPNW/w+aNKndkdOzp+LStJ54ERHuBM8HVzhfeMqE1992LrkeaACqANvTDBNfn/fTSj9WumdRFsb6un88sT4Ix3JfrPfqml5wpmHvnTGuyhPTw4AQFfbn7DtlfpblDugzyydQC6ZRnYKwlRA0SId3uks/Nhq98g0mZY0h82Di+yOv0jY0N0OLYWMbcYjSFBWyGAr5uNfaO1lnm4MnZyK3hEsDrQOYRrRMHFheImy824aozhOedS+mgWDW2cPLo0y5zft7IOvnSBRBeLo6ag1diIFnlWU2KK+f5byzJoS6sQzC3lkbfFqUco0y46k0FKyK9JBa3hxzkgRrrdZj3IMnhu82zPoQc5qNovQbGQpoTr+slvqyB8Wpip3l4qYMu6aKbPk1PlYeQPBHKp9xiqIyTCd6eF2HMO+IyDPscyqT2xYrnu0fiTWbKLIjdMNXUoz+rxlfN8aggrym06sKSJMNIaBMH5shPTPm0UcxSGBD9qpVz9SWB8Laxm4w== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Change folio_lock_or_retry to accept vm_fault struct and return the vm_fault_t directly. Suggested-by: Matthew Wilcox Signed-off-by: Suren Baghdasaryan Acked-by: Peter Xu --- include/linux/pagemap.h | 9 ++++----- mm/filemap.c | 22 ++++++++++++---------- mm/memory.c | 14 ++++++-------- 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index a56308a9d1a4..59d070c55c97 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_or_retry(struct folio *folio, struct vm_fault *vmf); void unlock_page(struct page *page); void folio_unlock(struct folio *folio); @@ -1001,11 +1000,11 @@ static inline int folio_lock_killable(struct folio *folio) * Return value and mmap_lock implications depend on flags; see * __folio_lock_or_retry(). */ -static inline bool folio_lock_or_retry(struct folio *folio, - struct mm_struct *mm, unsigned int flags) +static inline vm_fault_t folio_lock_or_retry(struct folio *folio, + struct vm_fault *vmf) { might_sleep(); - return folio_trylock(folio) || __folio_lock_or_retry(folio, mm, flags); + return folio_trylock(folio) ? 0 : __folio_lock_or_retry(folio, vmf); } /* diff --git a/mm/filemap.c b/mm/filemap.c index 00f01d8ead47..52bcf12dcdbf 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1701,32 +1701,34 @@ static int __folio_lock_async(struct folio *folio, struct wait_page_queue *wait) /* * Return values: - * true - folio is locked; mmap_lock is still held. - * false - folio is not locked. + * 0 - folio is locked. + * 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_or_retry(struct folio *folio, struct vm_fault *vmf) { + struct mm_struct *mm = vmf->vma->vm_mm; + unsigned int flags = vmf->flags; + if (fault_flag_allow_retry_first(flags)) { /* * CAUTION! In this case, mmap_lock is not released - * even though return 0. + * even though return VM_FAULT_RETRY. */ if (flags & FAULT_FLAG_RETRY_NOWAIT) - return false; + return VM_FAULT_RETRY; mmap_read_unlock(mm); if (flags & FAULT_FLAG_KILLABLE) folio_wait_locked_killable(folio); else folio_wait_locked(folio); - return false; + return VM_FAULT_RETRY; } if (flags & FAULT_FLAG_KILLABLE) { bool ret; @@ -1734,13 +1736,13 @@ bool __folio_lock_or_retry(struct folio *folio, struct mm_struct *mm, ret = __folio_lock_killable(folio); if (ret) { mmap_read_unlock(mm); - return false; + return VM_FAULT_RETRY; } } else { __folio_lock(folio); } - return true; + return 0; } /** diff --git a/mm/memory.c b/mm/memory.c index f14d45957b83..345080052003 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_or_retry(folio, vmf); + if (ret) { folio_put(folio); - return VM_FAULT_RETRY; + return ret; } mmu_notifier_range_init_owner(&range, MMU_NOTIFY_EXCLUSIVE, 0, vma->vm_mm, vmf->address & PAGE_MASK, @@ -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; @@ -3826,12 +3827,9 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) goto out_release; } - locked = folio_lock_or_retry(folio, vma->vm_mm, vmf->flags); - - if (!locked) { - ret |= VM_FAULT_RETRY; + ret |= folio_lock_or_retry(folio, vmf); + if (ret & VM_FAULT_RETRY) goto out_release; - } if (swapcache) { /* From patchwork Wed Jun 28 07:17:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13295275 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 1EF07EB64D7 for ; Wed, 28 Jun 2023 07:18:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 067ED8D0009; Wed, 28 Jun 2023 03:18:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0187E8D0001; Wed, 28 Jun 2023 03:18:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E224A8D0009; Wed, 28 Jun 2023 03:18:18 -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 D445C8D0001 for ; Wed, 28 Jun 2023 03:18:18 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id A5C8980CA3 for ; Wed, 28 Jun 2023 07:18:18 +0000 (UTC) X-FDA: 80951303076.21.F74BA44 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf04.hostedemail.com (Postfix) with ESMTP id D676D40005 for ; Wed, 28 Jun 2023 07:18:16 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=g48V+MJr; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf04.hostedemail.com: domain of 3uN6bZAYKCBE9B8v4sx55x2v.t532z4BE-331Crt1.58x@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3uN6bZAYKCBE9B8v4sx55x2v.t532z4BE-331Crt1.58x@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1687936696; 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=b7MqQHJHdH35CYJ6Jb1zpJ4/eRYK1pcerh43dShkH+M=; b=ZY4+9Rn23YwY7j1mAnEPLodxNFkkA9J6tJfvaE86xbqUKia2z9QxM1l5rZc2+jZkd/v+Cn hndGmMlcBGmc64GjQl6CIMijUWp7hw5f0mDfoBOqcxXcuZMDiEE/Bs5S3ji74W5X7Ogplw FIe1EaVW042jrVP6sLkp6v/0jPF68MI= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=g48V+MJr; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf04.hostedemail.com: domain of 3uN6bZAYKCBE9B8v4sx55x2v.t532z4BE-331Crt1.58x@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3uN6bZAYKCBE9B8v4sx55x2v.t532z4BE-331Crt1.58x@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687936696; a=rsa-sha256; cv=none; b=BSrtSpgeTO5GjTAv2EF9A8D5mvb7PRCV81k4Ro85cQeExkxI0Yw/E1+0tS1JOH6AHbM0hO DIfOLV0gN/XxDaunvSiNfJ8Mi7v6BXyEZSEbF8d3Idn8RQFGwEdgYBoQcdDxrytFxuXCpR C3zdBvGc5w4wT/+ufwZurQB4lQIBuFU= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-565ba5667d5so70500357b3.0 for ; Wed, 28 Jun 2023 00:18:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1687936696; x=1690528696; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=b7MqQHJHdH35CYJ6Jb1zpJ4/eRYK1pcerh43dShkH+M=; b=g48V+MJrxb5eSEjyL2iKtN/pPbN1MfYIjbyI7k+Ph5zLX9pOqSy0bI/iSTq8ynaAv2 +dtLaVTZuWBoHtPx+WE9swOOvjc4HEP18ck+X8gyP2hZHEeVhI81gYueHcbww6LxgOMa LsmCB7piWMCI+TEtSFI05OjRmaVr3SNelE0yHo6RvME1z+zbGm3FkxipazXo3FSyR9JG F5ws6BPFBksuHcM0OPJSKH8sgS6VK7KCMdA8CAmdPZUa5sb3DGy1kMimg4nYKRndAJKf p27MRa3E8cwerZeCNy05DHZ/fnLi71GnBj1QTCT1/0e7Mj+wH/0ewNx30+M4kNpzSe4W 4LTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687936696; x=1690528696; 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=b7MqQHJHdH35CYJ6Jb1zpJ4/eRYK1pcerh43dShkH+M=; b=cTvKZyybFlcR+ZdP5HKlHsk0Upt/6unmn6tejxRHrmQXsGhtwznhSxzSAyp235rV9R 8GekFgf60Qg64uB8brwdLUQX2rdY9ZxFyFOgEidMRzqQojaVQX8Vwt1FJ6wjg4XnzFj+ S3wuAHS+g8tLmI2m7XqxL9y1OzK/e+lZEvvmPTPUQly9UyN09Aix68ae52ydEWw8a17n IAEZiKYNqYQWRcoeVjCoJCtlntX/5bL7qyki3PvkdyxhUl1Pe4yL2iuTWQCdYhkNaqBd ypc4DuGovBuRKOrZSyKoaRAn81SjzoRUUnAprJhNNGBVEsT06L9DN7++9jZH+wYWL6QU c0sg== X-Gm-Message-State: AC+VfDyWWjfK+gtAuYjrIoKperwAmITRemZu3u31/GnZAkzcduaGt3Cz 4NQAkbJZTjURf6RWsa8SnoVgqhUizeU= X-Google-Smtp-Source: ACHHUZ5p7K5vwu3GLTcOloeUXHu3uFg6BFvaVURIKfx6u7AbyQoKOvh6cJprBsCrY0QmdnAunXGn4WazRWI= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:6664:8bd3:57fd:c83a]) (user=surenb job=sendgmr) by 2002:a81:af22:0:b0:559:c032:eb5e with SMTP id n34-20020a81af22000000b00559c032eb5emr14112427ywh.1.1687936696048; Wed, 28 Jun 2023 00:18:16 -0700 (PDT) Date: Wed, 28 Jun 2023 00:17:59 -0700 In-Reply-To: <20230628071800.544800-1-surenb@google.com> Mime-Version: 1.0 References: <20230628071800.544800-1-surenb@google.com> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog Message-ID: <20230628071800.544800-6-surenb@google.com> Subject: [PATCH v4 5/6] mm: handle swap page faults under per-VMA lock From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: willy@infradead.org, hannes@cmpxchg.org, mhocko@suse.com, josef@toxicpanda.com, jack@suse.cz, ldufour@linux.ibm.com, laurent.dufour@fr.ibm.com, michel@lespinasse.org, liam.howlett@oracle.com, jglisse@google.com, vbabka@suse.cz, minchan@google.com, dave@stgolabs.net, punit.agrawal@bytedance.com, lstoakes@gmail.com, hdanton@sina.com, apopple@nvidia.com, peterx@redhat.com, ying.huang@intel.com, david@redhat.com, yuzhao@google.com, dhowells@redhat.com, hughd@google.com, viro@zeniv.linux.org.uk, brauner@kernel.org, pasha.tatashin@soleen.com, surenb@google.com, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@android.com X-Rspam-User: X-Stat-Signature: r9kdsahzzsdo3rme7hnt9u9h5y5bdq9p X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: D676D40005 X-HE-Tag: 1687936696-382391 X-HE-Meta: U2FsdGVkX1+RBFOcoh94kQ8Ps139um++UYy+0Tmwgitoule5FiPm4utAWSbr7O2PwzfpavQHJwLNaaabq4EgqeJk5NgrSsPkvK7y+wREBJcEm4JlxdF351ho6OLWng+LCN2Bvwt6AekbgSaJ0QhAo4HM+rbc9tDtz51vxOFwU5D7selD3/9mkzGD/jDqRKU0Nvqpc7LHla8F+SHiJoTRXJpSDwuRW2fo1r8W6LL9nuFwQ52/QI2EJgrsUayVc32SCf6Op2x3g1KR4VHb4oWzZF5xm6uP5951XtoyoRtfU7tpo1buih+AlZdvoSJXdLK9vjolQrIZjeIeHHzqeAZjBuoz8aui3cgM7dUFAieAeBXmsaT7zEnduBQI+AKB+CRGzj7KPCUs4UaU/d95o5Z8I0I+pLtoAIiyggV11SuQV9s3FivRAr9oeL2oDJokIJkL1rBZK7fxgPSzRVtsjZZ6Aszf9vCUdi4ShDd0Ds5P+NU+P/r4xKUkn7WUxqRpIqsW+al7JzatJeeQy7KNNOQ5EKfa5TEvpTXVi3tkDXB5OTpYqctaHJymKWfrMW+TREUWo33TjhTH4Yg7IarcNxup9g6yZjzzqjIkkiAZumJIcMPUQz7gmNiIQSWZkTFRRh1EYoVp96tmvHNn7ce0g1N5mCT1pwT8vhT6jnomuBolU7syD9DjSK8yrn3IgxuqK70SrGyaHvs5sAkm8MKFvlyUcDhxdG2PMfLqZeUEjamWhmRySv+EMsGd/FvbIokS2uiCy0sWI6Ut+E0cJ9wMfBA3ST3cJhjVQRRVsbKIgLEV/kronOpB/1LmJkanXt0cL6uCiLWZ9wDIXtbtmncbS8Kmdk/B6SLnTPAo3bjdUrxQZqJ41GFQaRo3uV5PQ2ksb01ZG5SJ8KTvnBDFVqnFoVDnBSkFWtyiprRM7U4QxxNIyL45mzKJRh57dZsgT+Yn80glB+SJLk71gNVQA1o2ztS N1jerky8 F/W72lq6xSJ2Obi+35nzAi1WJCxhh0bV719or+JiY4JmrLBV08oTHPzJ93p/6mFeF6gpVNCcjfeXLar7aUW0CZLPFLjhpvWZYk63hwajey45/65xlChtIplYl8z/CVTRFHj2YfwTyUgSnW8jB/nFec9NCa4TLnEuE8v6E23ESl4O194Vhb1hZvcSnH+2zotA4deim/O6OpB5bdRo444UxbNf+P3kSidNtsXmktpXcNPJiGm4JYv1roPdtmNJJCP5tbiV5nbBwJyMjif0ySYe7cLzQ0zhE9+IL8kp3wuig1G8pXbhGCnT3HgfG5VaEAT5xoYI3f/YG6DcWDU7+sbNuCd0D7YqlgEvP72Lrd0hhItEJd0Wrf4R9nZDOVm+IEmYXK7KWBvADhzzEou3qsTY7pI3dYMevd+HPTNlgp5mpJ+61pSnRHQip6QnA7f5mR8M4uTwABr1TPSWG/7eXORl3YRvXVAS0oiwgOJ0jxzFzP67aSwaXGCRqjx9RZVOO3F2hAEmIklhsjiinD5s6ElURDdVVNDsTDnH+N6J7ufNk386iLNaNX2XR1ZSO+FAV2k6XiX9sCamrVRmcPOHiCLrZulN6HhJcmY6Y84e02ys5xvWYRUc= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: When page fault is handled under per-VMA lock protection, all swap page faults are retried with mmap_lock because folio_lock_or_retry has to drop and reacquire mmap_lock if folio could not be immediately locked. Follow the same pattern as mmap_lock to drop per-VMA lock when waiting for folio and retrying once folio is available. With this obstacle removed, enable do_swap_page to operate under per-VMA lock protection. Drivers implementing ops->migrate_to_ram might still rely on mmap_lock, therefore we have to fall back to mmap_lock in that particular case. Note that the only time do_swap_page calls synchronous swap_readpage is when SWP_SYNCHRONOUS_IO is set, which is only set for QUEUE_FLAG_SYNCHRONOUS devices: brd, zram and nvdimms (both btt and pmem). Therefore we don't sleep in this path, and there's no need to drop the mmap or per-VMA lock. Signed-off-by: Suren Baghdasaryan Acked-by: Peter Xu --- mm/filemap.c | 25 ++++++++++++++++--------- mm/memory.c | 16 ++++++++++------ 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index 52bcf12dcdbf..7ee078e1a0d2 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1699,31 +1699,38 @@ static int __folio_lock_async(struct folio *folio, struct wait_page_queue *wait) return ret; } +static void release_fault_lock(struct vm_fault *vmf) +{ + if (vmf->flags & FAULT_FLAG_VMA_LOCK) + vma_end_read(vmf->vma); + else + mmap_read_unlock(vmf->vma->vm_mm); +} + /* * 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. + * mmap_lock or per-VMA lock has been released (mmap_read_unlock() or + * vma_end_read()), unless flags had both FAULT_FLAG_ALLOW_RETRY and + * FAULT_FLAG_RETRY_NOWAIT set, in which case the lock is still held. * * If neither ALLOW_RETRY nor KILLABLE are set, will always return 0 - * with the folio locked and the mmap_lock unperturbed. + * with the folio locked and the mmap_lock/per-VMA lock is left unperturbed. */ vm_fault_t __folio_lock_or_retry(struct folio *folio, struct vm_fault *vmf) { - struct mm_struct *mm = vmf->vma->vm_mm; unsigned int flags = vmf->flags; if (fault_flag_allow_retry_first(flags)) { /* - * CAUTION! In this case, mmap_lock is not released - * even though return VM_FAULT_RETRY. + * CAUTION! In this case, mmap_lock/per-VMA lock is not + * released even though returning VM_FAULT_RETRY. */ if (flags & FAULT_FLAG_RETRY_NOWAIT) return VM_FAULT_RETRY; - mmap_read_unlock(mm); + release_fault_lock(vmf); if (flags & FAULT_FLAG_KILLABLE) folio_wait_locked_killable(folio); else @@ -1735,7 +1742,7 @@ vm_fault_t __folio_lock_or_retry(struct folio *folio, struct vm_fault *vmf) ret = __folio_lock_killable(folio); if (ret) { - mmap_read_unlock(mm); + release_fault_lock(vmf); return VM_FAULT_RETRY; } } else { diff --git a/mm/memory.c b/mm/memory.c index 345080052003..76c7907e7286 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3712,12 +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; - vma_end_read(vma); - goto out; - } - entry = pte_to_swp_entry(vmf->orig_pte); if (unlikely(non_swap_entry(entry))) { if (is_migration_entry(entry)) { @@ -3727,6 +3721,16 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) vmf->page = pfn_swap_entry_to_page(entry); ret = remove_device_exclusive_entry(vmf); } else if (is_device_private_entry(entry)) { + if (vmf->flags & FAULT_FLAG_VMA_LOCK) { + /* + * migrate_to_ram is not yet ready to operate + * under VMA lock. + */ + vma_end_read(vma); + ret |= VM_FAULT_RETRY; + goto out; + } + vmf->page = pfn_swap_entry_to_page(entry); vmf->pte = pte_offset_map_lock(vma->vm_mm, vmf->pmd, vmf->address, &vmf->ptl); From patchwork Wed Jun 28 07:18:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13295276 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 9A5CEEB64DC for ; Wed, 28 Jun 2023 07:18:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8F6F98D000A; Wed, 28 Jun 2023 03:18:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8A4BE8D0001; Wed, 28 Jun 2023 03:18:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 76B1F8D000A; Wed, 28 Jun 2023 03:18:21 -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 695C18D0001 for ; Wed, 28 Jun 2023 03:18:21 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 37A52A0B9C for ; Wed, 28 Jun 2023 07:18:21 +0000 (UTC) X-FDA: 80951303202.04.6FB81F7 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf08.hostedemail.com (Postfix) with ESMTP id 5F72E160004 for ; Wed, 28 Jun 2023 07:18:19 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=o3mfftQB; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf08.hostedemail.com: domain of 3ut6bZAYKCBMBDAx6uz77z4x.v75416DG-553Etv3.7Az@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3ut6bZAYKCBMBDAx6uz77z4x.v75416DG-553Etv3.7Az@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1687936699; 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=P/PrTNNebDD3ET79IWIr+QJG2wgn5QmJDayPL9+A73A=; b=LzUI1QMmBp97PC8fQNKjU5DspWWqe/8+3a6OqciZrdI1/UTNK/EwXIwdXvAU0dQkmzDXYX rIC58i4y3ZxGs5BX0OTorXW7eCwFKrumdNuzCU72/cUO5xj/ZHzgbRojBEbRkHKQwmB6o3 LP5ybAoBntGK26nAeQJ5tsDGzwOAh4Q= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=o3mfftQB; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf08.hostedemail.com: domain of 3ut6bZAYKCBMBDAx6uz77z4x.v75416DG-553Etv3.7Az@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3ut6bZAYKCBMBDAx6uz77z4x.v75416DG-553Etv3.7Az@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687936699; a=rsa-sha256; cv=none; b=2tjKbOfdHLGnKNplUKGJhwfEQEbIJV+WGNdksVgUfhbCr1TCxWGN3FFvLDfnJtx8i5lv0y udWAVSuPr4FgeQw0Rw9w7BEYMQzbR7mzbJCzbDXgbdwudPxCRdAZwuDwNyzSPwDzhWGBuT 3phDMrCQlo9lNMPuAt5W387ceguoBCQ= Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-c0bf91d259fso7051792276.1 for ; Wed, 28 Jun 2023 00:18:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1687936698; x=1690528698; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=P/PrTNNebDD3ET79IWIr+QJG2wgn5QmJDayPL9+A73A=; b=o3mfftQBKPovM43cmYPS1YI36P+25p9oi35azvDNp9/mWCSYYAuvVBAWUYYmoXyzUA x/e8gf9ND7SV7V3zc7QbZAws5RL7tAdiha0DVCNmZRWDR75EqFlIhl7cXCg9RD7ppR5f ZMYZ9pjQf6pbnGAlmvWnJ7UiobNEhohi3gR6ZdcClKWvLMGCIW4xhO86oDFUJQg5JjTN XH8VdAUjzRbB1pS0ZvIrJ5jhGjOMHm38u+/bFSpNbcC/hxemHs3VY6GANvjSSqYO34v5 ho0Jluar0wb1rCI/oPm0WsPDZxydzMECfzXTyVqqLKPeb8qHq0yJG0KWfbtt+rgElRyI c/9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687936698; x=1690528698; 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=P/PrTNNebDD3ET79IWIr+QJG2wgn5QmJDayPL9+A73A=; b=FkaQ6Z+paSaqRbViHcQCy67wRhajpxrNjAS0Xtmm2zjr5Q8aplROiCceJyt6DoHYSx PSBxDaGktRQzYDlFf6E8bvWd/ip80XRsMzlpHGuElg1MtmaWNDj8GUjSWlJ23zhdUVN+ p0eVjlb898JzBnovBadspZ7gAxzTQkEthuleKMK5PGlzsiyFibA5HxLCVk/VFOqqFT27 N9hX7qVS14dMBCZyvgHIYIDi3QlQxtXiXjs0LY+bbukn+AAs1ARxlDD2KrtKpHF/Nx0F 18k8LwnNdNYwBeSHhiJEcHkgL91Y88mn4HJ05bqL9gj5BK6WyrkGdLNe2iZc7jsfS4C+ /Teg== X-Gm-Message-State: AC+VfDzAIC1ykZ1dGZ3b9knr4Yw6t2j4WvtAqflXOd4lZX+NUoIdwM4j 5bE25FqQQ5pZa/MCWIWUEIRHV+SPJOE= X-Google-Smtp-Source: ACHHUZ7aI7icl9yP+XTVAxjb/B56LWhJlYyY/bkxia+e7VEwFYxsmG4eFO4RUCr5qbQXOHl5LdpkQKpzOJA= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:6664:8bd3:57fd:c83a]) (user=surenb job=sendgmr) by 2002:a25:198a:0:b0:c00:a33:7 with SMTP id 132-20020a25198a000000b00c000a330007mr9718444ybz.8.1687936698504; Wed, 28 Jun 2023 00:18:18 -0700 (PDT) Date: Wed, 28 Jun 2023 00:18:00 -0700 In-Reply-To: <20230628071800.544800-1-surenb@google.com> Mime-Version: 1.0 References: <20230628071800.544800-1-surenb@google.com> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog Message-ID: <20230628071800.544800-7-surenb@google.com> Subject: [PATCH v4 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-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 5F72E160004 X-Stat-Signature: xzcd4edush9dcc81fm3were7753eygto X-HE-Tag: 1687936699-671940 X-HE-Meta: U2FsdGVkX18oMb0AeY5pIHCUKNLRbvEk+PaxLAH4UYpcJn1f+/x8470kITqjf3KaFXVyqvq2TdV5vE68cwVL118S9pIFpdDIPR3KjQeByyy570Hb5LNQFIxv9Gfced47D+uIpM95oM8nM5o7xQFdOkh97WnmUvX1yLXhI6sTUZVJblhDR6dhhbLMSupesqCUd/DYkITalteYOnQWdv5zWWqA92LkzeHS58nnIqNF7kP/ZYxCU5XzTVhfUip2/sGLXQiY1RVYSH0z+rT14fK44/A5u1wWOPDH7OnMC/Svi280hS0nHRhMozTNKkWuLcaTqjB+I0nIE1/Nby8AUzQ+fG8errZabGxOQSxO0UbtjybtFs7qn9TFkbZlnciOf9l344iZBzq62IyNjZ6sTn9s5Nw8szFD4sIqM8Ro44M4g6P5F2elEUQE+6KYu1ZxA7lM3s7hBeaiv7btOhUeaEIQyZQ7wDLyYdR3uJI0bhIyvDG9+demGYG7abZ215KRv+7qlehMZ8SoPsiAYMEEpT7GE178Gzixvu62kXSmbvJH45xCU1jOubzLkdpetKJBdnyiNPAupypxhgq7MzzJKfHVBeCQDth4Yy/7MSNc2rAPbcLXDtfI9TFBsI8b7v1m164BQsjMNI978FgcebTluQSMSshRyuiECDyjss8Mzny2c3JRudtK+cE+iKX4fbJA353Tqab3xBdTuf/mfIWlRpGhL7jGXX2aJysP7MZ2Nted5csQqRO+NIX2jpuyvae5bHkjXWGXODINJnOGxjAIg1wMjcBhqDcSpyg9hI9XOOa4dVBZdXAJ53gg79kYJw5Qd1jppM6xc4x9t61xqZfkChbFxLSl2l8so5AlucYk2XRwGzn3HWicJOjhY7ymEi5PCiyABcmCIC86lYEkfAlmb6yYDnz0kFe72e0k3+A98p7SB0T6RJSaz3/yg41xLOLOg4JGQNJNPemgnccL6KgDvuc 1aUwXFAs Xzp2viqFWgCW/SHqU5y5v3rzKDmHOZ6PN4SWigouq/V1R/lo3cJmLAUoScHvNGqfvnZvHcuXMFfhWFW9eBmXaVtNM/QEhyPlcqBGAmAnpQxZyipFmznQGx2K7K6CsmDSItO2wLX05BzF3/YafmFSSpLbUdL/TOQCaFPKF5W9pIM6LlqnMu5ngSU207frOL0JObwchNm1qGtrW4iHTX2Im0QbJv/UdvGnZKkYAz+GsPJ6vVK436Fnqwng3eqzyCt3mpbUN/dSAUXqojm+4K2OsMc/yAFQSgmBxTn0HmfKvRqxcMgJHmpu0iU+gLrI0QruSzEjLaLg7h6gs2FuaK9J5hun0OMCj8inpdgoTWAfoqjhiKcdoyk0Y9/w8daocAv3t0WfaqJ01FhmV+xe6LPoIxfQzJxHCroPtvZC3bziQ/dPWyXV/bBB1mGFUAppJCRwxyrbDZt55doO51HZrlv4WiF/79VZrf3llJCLI7r36xwQwVCSLzpqOkjq3bpmCsymJxt0lfk4/6RdCvYywpmoVdl9v29Ymy6pyHWi1j7NJeeidnQhI5JYfdKQ7TnvcfJ4/MzL7nv6fQkbbaT1JhqXDtDVvbp96Wfs80BZPJXyCvrc7Ge4= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Enable handle_userfault to operate under VMA lock by releasing VMA lock instead of mmap_lock and retrying. Note that FAULT_FLAG_RETRY_NOWAIT should never be used when handling faults under per-VMA lock protection because that would break the assumption that lock is dropped on retry. Signed-off-by: Suren Baghdasaryan --- fs/userfaultfd.c | 39 ++++++++++++++++++--------------------- include/linux/mm.h | 39 +++++++++++++++++++++++++++++++++++++++ mm/filemap.c | 8 -------- mm/memory.c | 9 --------- 4 files changed, 57 insertions(+), 38 deletions(-) diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c index 4e800bb7d2ab..d019e7df6f15 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -277,17 +277,16 @@ static inline struct uffd_msg userfault_msg(unsigned long address, * hugepmd ranges. */ static inline bool userfaultfd_huge_must_wait(struct userfaultfd_ctx *ctx, - struct vm_area_struct *vma, - unsigned long address, - unsigned long flags, - unsigned long reason) + struct vm_fault *vmf, + unsigned long reason) { + struct vm_area_struct *vma = vmf->vma; pte_t *ptep, pte; bool ret = true; - mmap_assert_locked(ctx->mm); + assert_fault_locked(ctx->mm, vmf); - ptep = hugetlb_walk(vma, address, vma_mmu_pagesize(vma)); + ptep = hugetlb_walk(vma, vmf->address, vma_mmu_pagesize(vma)); if (!ptep) goto out; @@ -308,10 +307,8 @@ static inline bool userfaultfd_huge_must_wait(struct userfaultfd_ctx *ctx, } #else static inline bool userfaultfd_huge_must_wait(struct userfaultfd_ctx *ctx, - struct vm_area_struct *vma, - unsigned long address, - unsigned long flags, - unsigned long reason) + struct vm_fault *vmf, + unsigned long reason) { return false; /* should never get here */ } @@ -325,11 +322,11 @@ static inline bool userfaultfd_huge_must_wait(struct userfaultfd_ctx *ctx, * threads. */ static inline bool userfaultfd_must_wait(struct userfaultfd_ctx *ctx, - unsigned long address, - unsigned long flags, + struct vm_fault *vmf, unsigned long reason) { struct mm_struct *mm = ctx->mm; + unsigned long address = vmf->address; pgd_t *pgd; p4d_t *p4d; pud_t *pud; @@ -337,7 +334,7 @@ static inline bool userfaultfd_must_wait(struct userfaultfd_ctx *ctx, pte_t *pte; bool ret = true; - mmap_assert_locked(mm); + assert_fault_locked(mm, vmf); pgd = pgd_offset(mm, address); if (!pgd_present(*pgd)) @@ -445,7 +442,7 @@ vm_fault_t handle_userfault(struct vm_fault *vmf, unsigned long reason) * Coredumping runs without mmap_lock so we can only check that * the mmap_lock is held, if PF_DUMPCORE was not set. */ - mmap_assert_locked(mm); + assert_fault_locked(mm, vmf); ctx = vma->vm_userfaultfd_ctx.ctx; if (!ctx) @@ -522,8 +519,11 @@ vm_fault_t handle_userfault(struct vm_fault *vmf, unsigned long reason) * and wait. */ ret = VM_FAULT_RETRY; - if (vmf->flags & FAULT_FLAG_RETRY_NOWAIT) + if (vmf->flags & FAULT_FLAG_RETRY_NOWAIT) { + /* Per-VMA lock is expected to be dropped on VM_FAULT_RETRY */ + BUG_ON(vmf->flags & FAULT_FLAG_RETRY_NOWAIT); goto out; + } /* take the reference before dropping the mmap_lock */ userfaultfd_ctx_get(ctx); @@ -561,15 +561,12 @@ vm_fault_t handle_userfault(struct vm_fault *vmf, unsigned long reason) spin_unlock_irq(&ctx->fault_pending_wqh.lock); if (!is_vm_hugetlb_page(vma)) - must_wait = userfaultfd_must_wait(ctx, vmf->address, vmf->flags, - reason); + must_wait = userfaultfd_must_wait(ctx, vmf, reason); else - must_wait = userfaultfd_huge_must_wait(ctx, vma, - vmf->address, - vmf->flags, reason); + must_wait = userfaultfd_huge_must_wait(ctx, vmf, reason); if (is_vm_hugetlb_page(vma)) hugetlb_vma_unlock_read(vma); - mmap_read_unlock(mm); + release_fault_lock(vmf); if (likely(must_wait && !READ_ONCE(ctx->released))) { wake_up_poll(&ctx->fd_wqh, EPOLLIN); diff --git a/include/linux/mm.h b/include/linux/mm.h index fec149585985..70bb2f923e33 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -705,6 +705,17 @@ static inline bool vma_try_start_write(struct vm_area_struct *vma) return true; } +static inline void vma_assert_locked(struct vm_area_struct *vma) +{ + int mm_lock_seq; + + if (__is_vma_write_locked(vma, &mm_lock_seq)) + return; + + lockdep_assert_held(&vma->vm_lock->lock); + VM_BUG_ON_VMA(!rwsem_is_locked(&vma->vm_lock->lock), vma); +} + static inline void vma_assert_write_locked(struct vm_area_struct *vma) { int mm_lock_seq; @@ -723,6 +734,23 @@ static inline void vma_mark_detached(struct vm_area_struct *vma, bool detached) struct vm_area_struct *lock_vma_under_rcu(struct mm_struct *mm, unsigned long address); +static inline +void assert_fault_locked(struct mm_struct *mm, struct vm_fault *vmf) +{ + if (vmf->flags & FAULT_FLAG_VMA_LOCK) + vma_assert_locked(vmf->vma); + else + mmap_assert_locked(mm); +} + +static inline void release_fault_lock(struct vm_fault *vmf) +{ + if (vmf->flags & FAULT_FLAG_VMA_LOCK) + vma_end_read(vmf->vma); + else + mmap_read_unlock(vmf->vma->vm_mm); +} + #else /* CONFIG_PER_VMA_LOCK */ static inline void vma_init_lock(struct vm_area_struct *vma) {} @@ -736,6 +764,17 @@ static inline void vma_assert_write_locked(struct vm_area_struct *vma) {} static inline void vma_mark_detached(struct vm_area_struct *vma, bool detached) {} +static inline +void assert_fault_locked(struct mm_struct *mm, struct vm_fault *vmf) +{ + mmap_assert_locked(mm); +} + +static inline void release_fault_lock(struct vm_fault *vmf) +{ + mmap_read_unlock(vmf->vma->vm_mm); +} + #endif /* CONFIG_PER_VMA_LOCK */ /* diff --git a/mm/filemap.c b/mm/filemap.c index 7ee078e1a0d2..d4d8f474e0c5 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1699,14 +1699,6 @@ static int __folio_lock_async(struct folio *folio, struct wait_page_queue *wait) return ret; } -static void release_fault_lock(struct vm_fault *vmf) -{ - if (vmf->flags & FAULT_FLAG_VMA_LOCK) - vma_end_read(vmf->vma); - else - mmap_read_unlock(vmf->vma->vm_mm); -} - /* * Return values: * 0 - folio is locked. diff --git a/mm/memory.c b/mm/memory.c index 76c7907e7286..c6c759922f39 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5294,15 +5294,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);