From patchwork Mon May 22 05:20:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 13249785 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 B5BB7C7EE23 for ; Mon, 22 May 2023 05:20:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5136F6B0075; Mon, 22 May 2023 01:20:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 49DEF6B0078; Mon, 22 May 2023 01:20:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3172E900002; Mon, 22 May 2023 01:20:59 -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 1EFEB6B0075 for ; Mon, 22 May 2023 01:20:59 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id D70CAC0633 for ; Mon, 22 May 2023 05:20:58 +0000 (UTC) X-FDA: 80816741796.16.10774E9 Received: from mail-yb1-f180.google.com (mail-yb1-f180.google.com [209.85.219.180]) by imf23.hostedemail.com (Postfix) with ESMTP id 1165D140009 for ; Mon, 22 May 2023 05:20:56 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=YFRKfsKF; spf=pass (imf23.hostedemail.com: domain of hughd@google.com designates 209.85.219.180 as permitted sender) smtp.mailfrom=hughd@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=1684732857; 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=j6etDg/swU7AOCalaMxD05iIweXIhmZHtm6GGNoHnzQ=; b=C6jLFACHO54mBdO/H0fwMOLE6diQ5QOOns2HzuTILCUjDCvJOPKqiegjJ3OKOz0nFeKaRX 7oO3PF2jc1IiRVKKisM7Na1nKG26Puvt+z1TTU46aaBzKLXXkZRDJujHzcBeYV0lBvW2Tc 0iDmFlffCa4lYXAzW7XLh+XIVbVE22Y= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684732857; a=rsa-sha256; cv=none; b=D7elWljm1Ld1/HjW8cDopzs7J7VIBLsGLgn+EOfV9smPFDWHBU28EcnyVV7mRGbD4gsfKs Zht+VA8YwFrsH9azjFNyLaDJEOLJtAQyrhE8DpuQHHYzBPGDR9g17s9SKep1eA6sYBcu8N kyAeEWs/avSUk3G6eTT0OYRssZAwxaI= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=YFRKfsKF; spf=pass (imf23.hostedemail.com: domain of hughd@google.com designates 209.85.219.180 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-yb1-f180.google.com with SMTP id 3f1490d57ef6-ba8afcc82c0so8176110276.2 for ; Sun, 21 May 2023 22:20:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684732856; x=1687324856; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to; bh=j6etDg/swU7AOCalaMxD05iIweXIhmZHtm6GGNoHnzQ=; b=YFRKfsKFJp2z/omMF9kAApd0S0vxQuFTDhSSSfTCRKzoqcrub4PhM+O1boooV8+h+7 EnjnOkymlppoTkDw4nRAPps7rFoXTdCM2fk5vgu0nhCdGNkuTC3Ywg1Tg0z3smilw57a AYhYR543c86roHNURCr25oJ9c1fQFj3ujvNOV5N67eBFAEXegF1f2oEskky6yYw53RB6 1LMrFi8toFy6m/MnfxFA7DcCZIfsKlCmP01wxE3ks9bt8Xfi1FEm4Lsd/b5mwwUQxQvr vvJIRG6Xgs+dtaUMASMBUyR0SSOfetdWJ8Iw1sW/hI3XPXcU9B/tW4Jbs4RLezTnbIt4 iIvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684732856; x=1687324856; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=j6etDg/swU7AOCalaMxD05iIweXIhmZHtm6GGNoHnzQ=; b=Wz1CLYdhGy8UKs6kLbgPAEBVbOvebKUTpof9PTcjf3rluHuSEImVt0dPHKHr6JzlO9 xPzUP6rLzHkPmp6oTfX/Fl+jy3cmBl80TwCXXp/rqfK4ALDiK3gl/eVewORaehgcHDqF wYY3p0kxl6imitlSG5FHSFkpGdD/UaTrajd8EKEokIcb2t2DmHTqRcu1+AFhBoLAN7Ye +69e6UM9Fu5CSj+VWHRUE9dZTILTftD2FzGD33jW/n6u57YkkAbUu1qRFsn4Cer+QwOu uKzJfePZ19afNUeJRK6leVnM4aGXe5EDZjs2yU8c4pZ7ga3RRYshBvsKs3tpltAbLGH7 gu0A== X-Gm-Message-State: AC+VfDypWwNzAE9de9mlj0NJpxCxqU3bCQA50plXB3dYKyusYEzk/qjv hqHG5LEo8qDQOCNlNmg/MUccZg== X-Google-Smtp-Source: ACHHUZ4unls6ogV9SvyZExwOGgG/jyFNvH+bFxzEVTKzBIPGmZGTzZNTpUXsl12MimVOmHUoz8BiUw== X-Received: by 2002:a0d:ea93:0:b0:559:f0ef:aac0 with SMTP id t141-20020a0dea93000000b00559f0efaac0mr10004964ywe.30.1684732856030; Sun, 21 May 2023 22:20:56 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id i16-20020a0ddf10000000b0054f80928ea4sm1795763ywe.140.2023.05.21.22.20.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 May 2023 22:20:55 -0700 (PDT) Date: Sun, 21 May 2023 22:20:52 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.attlocal.net To: Andrew Morton cc: Mike Kravetz , Mike Rapoport , "Kirill A. Shutemov" , Matthew Wilcox , David Hildenbrand , Suren Baghdasaryan , Qi Zheng , Yang Shi , Mel Gorman , Peter Xu , Peter Zijlstra , Will Deacon , Yu Zhao , Alistair Popple , Ralph Campbell , Ira Weiny , Steven Price , SeongJae Park , Naoya Horiguchi , Christophe Leroy , Zack Rusin , Jason Gunthorpe , Axel Rasmussen , Anshuman Khandual , Pasha Tatashin , Miaohe Lin , Minchan Kim , Christoph Hellwig , Song Liu , Thomas Hellstrom , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 24/31] mm/migrate_device: allow pte_offset_map_lock() to fail In-Reply-To: <68a97fbe-5c1e-7ac6-72c-7b9c6290b370@google.com> Message-ID: References: <68a97fbe-5c1e-7ac6-72c-7b9c6290b370@google.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 1165D140009 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: 1zx11hzg5t6omxhyygfxjg48nwii8k7u X-HE-Tag: 1684732856-928958 X-HE-Meta: U2FsdGVkX1/J9Cr5q9uPj5PpPKvml8HpV/ML7WSd8z7LsdaxSkC+BxP5eNIGvJ2J4+XVrbeKOQeNs2ftc8+0qTTcThhu7Bz7ajTTNPtkuQS5SiQfzP2pOdlK4SS1Yp2JeoY8x7oNYCJVNNCk53WxL3sWZx0INpsugFPoxpj/g5Jz7ELte6PhyHuEkfacYxKZBr9nnjWZFzenbtdrWZ/SxcC22y60+0ovcohsXBlCTEP+iShAnmP0w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GYqIZNH8qUTF/At7VJYlSJYg9CvDYAVdgWxRU04cxPxvNWkwBgbb2owjqiv783b+xUV3LvudKzL+8rVZYxIbTBVuPDc+6Lgqx7QxoaA== 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: migrate_vma_collect_pmd(): remove the pmd_trans_unstable() handling after splitting huge zero pmd, and the pmd_none() handling after successfully splitting huge page: those are now managed inside pte_offset_map_lock(), and by "goto again" when it fails. But the skip after unsuccessful split_huge_page() must stay: it avoids an endless loop. The skip when pmd_bad()? Remove that: it will be treated as a hole rather than a skip once cleared by pte_offset_map_lock(), but with different timing that would be so anyway; and it's arguably best to leave the pmd_bad() handling centralized there. migrate_vma_insert_page(): remove comment on the old pte_offset_map() and old locking limitations; remove the pmd_trans_unstable() check and just proceed to pte_offset_map_lock(), aborting when it fails (page has now been charged to memcg, but that's so in other cases, and presumably uncharged later). Signed-off-by: Hugh Dickins Reviewed-by: Alistair Popple --- mm/migrate_device.c | 31 ++++--------------------------- 1 file changed, 4 insertions(+), 27 deletions(-) diff --git a/mm/migrate_device.c b/mm/migrate_device.c index d30c9de60b0d..a14af6b12b04 100644 --- a/mm/migrate_device.c +++ b/mm/migrate_device.c @@ -83,9 +83,6 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp, if (is_huge_zero_page(page)) { spin_unlock(ptl); split_huge_pmd(vma, pmdp, addr); - if (pmd_trans_unstable(pmdp)) - return migrate_vma_collect_skip(start, end, - walk); } else { int ret; @@ -100,16 +97,12 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp, if (ret) return migrate_vma_collect_skip(start, end, walk); - if (pmd_none(*pmdp)) - return migrate_vma_collect_hole(start, end, -1, - walk); } } - if (unlikely(pmd_bad(*pmdp))) - return migrate_vma_collect_skip(start, end, walk); - ptep = pte_offset_map_lock(mm, pmdp, addr, &ptl); + if (!ptep) + goto again; arch_enter_lazy_mmu_mode(); for (; addr < end; addr += PAGE_SIZE, ptep++) { @@ -595,27 +588,10 @@ static void migrate_vma_insert_page(struct migrate_vma *migrate, pmdp = pmd_alloc(mm, pudp, addr); if (!pmdp) goto abort; - if (pmd_trans_huge(*pmdp) || pmd_devmap(*pmdp)) goto abort; - - /* - * Use pte_alloc() instead of pte_alloc_map(). We can't run - * pte_offset_map() on pmds where a huge pmd might be created - * from a different thread. - * - * pte_alloc_map() is safe to use under mmap_write_lock(mm) or when - * parallel threads are excluded by other means. - * - * Here we only have mmap_read_lock(mm). - */ if (pte_alloc(mm, pmdp)) goto abort; - - /* See the comment in pte_alloc_one_map() */ - if (unlikely(pmd_trans_unstable(pmdp))) - goto abort; - if (unlikely(anon_vma_prepare(vma))) goto abort; if (mem_cgroup_charge(page_folio(page), vma->vm_mm, GFP_KERNEL)) @@ -650,7 +626,8 @@ static void migrate_vma_insert_page(struct migrate_vma *migrate, } ptep = pte_offset_map_lock(mm, pmdp, addr, &ptl); - + if (!ptep) + goto abort; if (check_stable_address_space(mm)) goto unlock_abort;