Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1453097rwd; Thu, 8 Jun 2023 19:04:15 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ48PxVHYI8x1u8iCVK8u7nnRtGFF1pE1ippKP1+H5vLhzNp9dqWax5Jxkvweee+Gpiw3Zmj X-Received: by 2002:a17:903:2584:b0:1ad:cb4b:1d50 with SMTP id jb4-20020a170903258400b001adcb4b1d50mr89686plb.43.1686276254929; Thu, 08 Jun 2023 19:04:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686276254; cv=none; d=google.com; s=arc-20160816; b=AFcqXTVp8F2NEqXxaXDnG3JJkLcGKtGfm+CyTrzxBGZ8UOLmlnuiZOvgDrXFld5Bb2 ATPs2jwKO9YUenYXIcn6+LULtbt5oUqtK/2eq8XFPp9KUw2fyM3NN9bEw9rkAlrlqVjx YE+g8gl6ZmV0rkFTtiStguSnEOvZqq71NDf0sWA8dr94GvWo4N2nbGc3MQlOWN1TntbI 8CSNddorMqjqvORWfUCQD/FrOHuL2VFuYMmaxBNFbFp46JpbhGSE2jPwwTQhQg+N3ekR iSK8wbxomVPTW1Nfw2bW+fOewBjeXY2zkNgiYt14qZzZ/i3njdtK2d5Uknri2LzyAc7s T1iw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:message-id:in-reply-to :subject:cc:to:from:date:dkim-signature; bh=AiDluOv2NKQXWITQOVsUWe3sj/TRHmtPFYOGjZ2ttyw=; b=bFjgiS6vne6l++uSgG4YdbPH6GXu93m0MnpL6zkYlSdtV7sqruoHbcvKUJ/vXOh7qb WUPfcXGgLTOHN+ZR50kAbsIq+2ppT9ft6NmdQjdrmMivqGhG4etS+kNND4+kPt7/I/tY EfFBIk4YH0nC9fVPi/EPd6u/SXEniB0VtswvUfS/E2D5LXuwA0lNuoegnyl+98aWkvtN ruKNIaqPMELzT12RnjVuxRwlE9xCUjuxeP2goWXGGyaCJfk4Bp38XtqdAuCFj+g2Mv3O fmXZP1tthXHFPyKBrfvLuhYwi/zR1RXlyVG9Kx+PtMmAKkdUuqrZTAGyy7yreDcbBf3t HiOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=T0Kllypm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kz6-20020a170902f9c600b0019cec50618csi1855389plb.159.2023.06.08.19.04.00; Thu, 08 Jun 2023 19:04:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=T0Kllypm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237771AbjFIBi0 (ORCPT + 99 others); Thu, 8 Jun 2023 21:38:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229923AbjFIBiZ (ORCPT ); Thu, 8 Jun 2023 21:38:25 -0400 Received: from mail-ot1-x32e.google.com (mail-ot1-x32e.google.com [IPv6:2607:f8b0:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DDF918C for ; Thu, 8 Jun 2023 18:38:23 -0700 (PDT) Received: by mail-ot1-x32e.google.com with SMTP id 46e09a7af769-6b2993c9652so261143a34.1 for ; Thu, 08 Jun 2023 18:38:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1686274702; x=1688866702; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to; bh=AiDluOv2NKQXWITQOVsUWe3sj/TRHmtPFYOGjZ2ttyw=; b=T0KllypmaI6dTB7DB6gV+sXkQkzh1ghuQsJWEK3jBazIFUwKZcsQ3r5kr988Onz36X Dex8mQRK1D2tkuguCbuqQKOnDZrak1tNbdPv9EQlJylAGS/JOPCnfCNAKd3nfZKgjEDX NyjKhyt6lzb+I77gA/PrGWpgqss/Ipf03liz3QsE5ZInJrgAzICnzUTYMrBYboMu8+Ko Te1BCCl46W+vNegr6tum9ZNWdColvrZcB8P0b/1QpqOrN9yiBM3NUya9DmMuMuxFqXqJ gRuJjfPoEiaWO0bbttWGNF01oOM4LC9iGoxIWBtycc73x4aBvX+fDbj/NGV2UJ/71lCf Nnag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686274702; x=1688866702; 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=AiDluOv2NKQXWITQOVsUWe3sj/TRHmtPFYOGjZ2ttyw=; b=d8ZvJRiEINg5LtWCaKk1ndGwufvihXUWXmJyI14yAy8mzulU4+PO2F4Fo+E62dYYAF vsZGnqMgFeDvfC+jXwMen858VHC8tQ3AW1QhYkrn32P6QfNJKwyYfmhQ2MhD458GMhz3 S/ZdnTljEou88FbVrAUOnkNGzmAHi5B+giz0XmXhvlgSJXWnshuVAxSO+I8UP/b2PJkQ mD34YafQqbH3vAP/ZMOOP8dN7NIkI2vBzrVHqQIkGzzcMUl9yk9k6s8a5MLyFVouE/9G BUHzY7uxww8BCf0rWMZmT/kRatZVMR6MZrJJqTeo7t8ES7fWlsEnaKOphFQuB4oDGICS AXMw== X-Gm-Message-State: AC+VfDyG6+7/obxGJUuvdGneQX/SY2C93wk4q6m8n3ZL2JqWavQuxdyX lxpHFTabjCF9P1KfLhh5Ir9OHw== X-Received: by 2002:a05:6830:cb:b0:6b1:570c:de5 with SMTP id x11-20020a05683000cb00b006b1570c0de5mr88477oto.17.1686274701910; Thu, 08 Jun 2023 18:38:21 -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 y7-20020a056902052700b00b8f13ff2a8esm586262ybs.61.2023.06.08.18.38.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Jun 2023 18:38:21 -0700 (PDT) Date: Thu, 8 Jun 2023 18:38:17 -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 , Lorenzo Stoakes , Huang Ying , Naoya Horiguchi , Christophe Leroy , Zack Rusin , Jason Gunthorpe , Axel Rasmussen , Anshuman Khandual , Pasha Tatashin , Miaohe Lin , Minchan Kim , Christoph Hellwig , Song Liu , Thomas Hellstrom , Ryan Roberts , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v2 24/32] mm/migrate_device: allow pte_offset_map_lock() to fail In-Reply-To: Message-ID: <1131be62-2e84-da2f-8f45-807b2cbeeec5@google.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 been charged to memcg, but as in other cases, it's uncharged when freed). 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; -- 2.35.3