Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1467693rwd; Thu, 8 Jun 2023 19:23:26 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5zqJydxrvWftC/UhXuHYY8uuN0YdePWlkMbt9OFiggQ89hsA0KVjsXgodKPtqQ4ZVVt8gR X-Received: by 2002:a05:6359:2a1:b0:127:afd3:b78f with SMTP id ek33-20020a05635902a100b00127afd3b78fmr128480rwb.19.1686277405911; Thu, 08 Jun 2023 19:23:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686277405; cv=none; d=google.com; s=arc-20160816; b=hNU1fa4mNjA6xenT9ejmMYDg8ouAQFEm5edeugRormN7Lt/zRcdvf1qgZScTy2/jVj wqRI5nirrx/fqJA6B3UxrDesbIvJ6pWfEFYWLs268o4uN+7uUCnIKO8zLz/tOaQPC9jb lcVC4qCj0hEPiZbVUdtALsCsMkFdosLgprC1RoXje4s52boIIUcU5mDo61uY9p0ealoC N7MUhShpEwDWK4U+fa4y988U5pbY04JAG4LKBdgtmD42++2XGnS9gSNBLNygkM7LZ+Hw Rv5m3aUC+nDQP0Y6lmow28u4NnweMITFraZUtosHMO7fBsq7W/E9JyNAHH0g6LGAC4yc mvaw== 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=9rqctUCF3S3JfLMZMEb80lefSOXfBunLGXTWgvpiAkU=; b=c8ExpCoomurjhtsLVb3ojNt9ol0YSEampg7Gp2alh1fylRt5AJVW9nJ18L3YBTyano SjTC8BsVBpoYV9V3N6en52vs41jRg43btTQZNWNRjdhYAbbZSUPecrtVSKQfpGEe4dXo MeThxb0ixvcKF9g2maD47bHW1M+ZO8dXCmxCCzlUP9dpDiPWRQKmAiQj41ezzTdQCqqy cwAUH0zA+jIFhvp1N0zb79ajyv86i4HmUsHBGLIEfW+Vgorp2kclnQwZrZzlLjSyBOKZ y8ZPwzLWcd4/OZMgzCV8cnGl1DtndVSigFbVbyu2HCVYD7FT0+af/hjOF7yHeKChUJvF VfQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=ZUnTRtdJ; 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 v135-20020a63618d000000b0053415b1caa8si1907965pgb.157.2023.06.08.19.23.12; Thu, 08 Jun 2023 19:23:25 -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=ZUnTRtdJ; 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 S237872AbjFIBlk (ORCPT + 99 others); Thu, 8 Jun 2023 21:41:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237849AbjFIBli (ORCPT ); Thu, 8 Jun 2023 21:41:38 -0400 Received: from mail-yw1-x112f.google.com (mail-yw1-x112f.google.com [IPv6:2607:f8b0:4864:20::112f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43BC118C for ; Thu, 8 Jun 2023 18:41:37 -0700 (PDT) Received: by mail-yw1-x112f.google.com with SMTP id 00721157ae682-565ba6aee5fso11407947b3.1 for ; Thu, 08 Jun 2023 18:41:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1686274896; x=1688866896; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to; bh=9rqctUCF3S3JfLMZMEb80lefSOXfBunLGXTWgvpiAkU=; b=ZUnTRtdJaKuP8HpCFk7QtfKJXS4h7TMBZvOJMvdH3Kb9GiIDkKt+HetF/u5hNY0iBZ C1Kvof77sPcx1H7YMQXI4g7GvGYj+dOG69GUGVHoheyoLtvIX7JK20pKUCPc88Hz5F7K 1vDSIi4a6aoe2Zceom9Svwsk2YImxUMqdpYy3MpT8APM++H9OeEHUgaErR5PTJoWvDnG Ooj+D4UNVVjEzEkwYMDebnqNIzPrU3Z0+Y3Vz1q/c+oe13fguEZcDxrw/xPw7f0EQgh9 2MxgqZ31UDTio0TPV7BeKiTntn6xKzAMDwB1lip/A72zUIdR7jZaKNlHZ1NNT8xv0XOp wchQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686274896; x=1688866896; 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=9rqctUCF3S3JfLMZMEb80lefSOXfBunLGXTWgvpiAkU=; b=RROmMbfz1k8qf8gEMcbUyn8M/bRnEckjvMw4Ma1pJkd27czc0XA93mzHL9LQK82Mq8 KSVXtKAxUjCQ+O3UlaktpHt6LZoBx+tIgddsv4Yr7Jt7WaaVwUaxbEoyoyBEE7SIoH/j RHzASwBaQhQiTJQlCRx1NXu1fTt9U/4QCPMcSHJo80t7EZjNOwwFVoS5Ni9yNGVv2RYK PD/X8+SrFEMJe3ctFewYAXWTD+Ieuf9JGTGfOA8DMKhpjYdHlIayAV4V3H4hZKmNbqs4 I2b9MvypKd9912Qoy4jKyEwolf/1TQSYMfyNW4qGlOpdZNrL2kpu2BW4+Yc2kN882xtU EtQQ== X-Gm-Message-State: AC+VfDzMkKux4Z4ZQON/GUU78BcMaRsleyZLm8NG31Q6T3L3HL6IXRtl drXgZbJCCmpgr/ZsxottIy0jkA== X-Received: by 2002:a81:6d04:0:b0:565:d3f9:209e with SMTP id i4-20020a816d04000000b00565d3f9209emr1374109ywc.34.1686274896335; Thu, 08 Jun 2023 18:41:36 -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 r205-20020a0de8d6000000b00559d9989490sm304902ywe.41.2023.06.08.18.41.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Jun 2023 18:41:34 -0700 (PDT) Date: Thu, 8 Jun 2023 18:41:31 -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 26/32] mm/huge_memory: split huge pmd under one pte_offset_map() In-Reply-To: Message-ID: <90cbed7f-90d9-b779-4a46-d2485baf9595@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 __split_huge_zero_page_pmd() use a single pte_offset_map() to sweep the extent: it's already under pmd_lock(), so this is no worse for latency; and since it's supposed to have full control of the just-withdrawn page table, here choose to VM_BUG_ON if it were to fail. And please don't increment haddr by PAGE_SIZE, that should remain huge aligned: declare a separate addr (not a bugfix, but it was deceptive). __split_huge_pmd_locked() likewise (but it had declared a separate addr); and change its BUG_ON(!pte_none) to VM_BUG_ON, for consistency with zero (those deposited page tables are sometimes victims of random corruption). Signed-off-by: Hugh Dickins Reviewed-by: Yang Shi --- mm/huge_memory.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index d4bd5fa7c823..839c13fa0bbe 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2037,6 +2037,8 @@ static void __split_huge_zero_page_pmd(struct vm_area_struct *vma, struct mm_struct *mm = vma->vm_mm; pgtable_t pgtable; pmd_t _pmd, old_pmd; + unsigned long addr; + pte_t *pte; int i; /* @@ -2052,17 +2054,20 @@ static void __split_huge_zero_page_pmd(struct vm_area_struct *vma, pgtable = pgtable_trans_huge_withdraw(mm, pmd); pmd_populate(mm, &_pmd, pgtable); - for (i = 0; i < HPAGE_PMD_NR; i++, haddr += PAGE_SIZE) { - pte_t *pte, entry; - entry = pfn_pte(my_zero_pfn(haddr), vma->vm_page_prot); + pte = pte_offset_map(&_pmd, haddr); + VM_BUG_ON(!pte); + for (i = 0, addr = haddr; i < HPAGE_PMD_NR; i++, addr += PAGE_SIZE) { + pte_t entry; + + entry = pfn_pte(my_zero_pfn(addr), vma->vm_page_prot); entry = pte_mkspecial(entry); if (pmd_uffd_wp(old_pmd)) entry = pte_mkuffd_wp(entry); - pte = pte_offset_map(&_pmd, haddr); VM_BUG_ON(!pte_none(*pte)); - set_pte_at(mm, haddr, pte, entry); - pte_unmap(pte); + set_pte_at(mm, addr, pte, entry); + pte++; } + pte_unmap(pte - 1); smp_wmb(); /* make pte visible before pmd */ pmd_populate(mm, pmd, pgtable); } @@ -2077,6 +2082,7 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd, bool young, write, soft_dirty, pmd_migration = false, uffd_wp = false; bool anon_exclusive = false, dirty = false; unsigned long addr; + pte_t *pte; int i; VM_BUG_ON(haddr & ~HPAGE_PMD_MASK); @@ -2205,8 +2211,10 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd, pgtable = pgtable_trans_huge_withdraw(mm, pmd); pmd_populate(mm, &_pmd, pgtable); + pte = pte_offset_map(&_pmd, haddr); + VM_BUG_ON(!pte); for (i = 0, addr = haddr; i < HPAGE_PMD_NR; i++, addr += PAGE_SIZE) { - pte_t entry, *pte; + pte_t entry; /* * Note that NUMA hinting access restrictions are not * transferred to avoid any possibility of altering @@ -2249,11 +2257,11 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd, entry = pte_mkuffd_wp(entry); page_add_anon_rmap(page + i, vma, addr, false); } - pte = pte_offset_map(&_pmd, addr); - BUG_ON(!pte_none(*pte)); + VM_BUG_ON(!pte_none(*pte)); set_pte_at(mm, addr, pte, entry); - pte_unmap(pte); + pte++; } + pte_unmap(pte - 1); if (!pmd_migration) page_remove_rmap(page, vma, true); -- 2.35.3