From patchwork Mon May 22 05:23:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 13249787 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 8AA60C7EE23 for ; Mon, 22 May 2023 05:23:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2F0F26B0075; Mon, 22 May 2023 01:23:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2C7646B0078; Mon, 22 May 2023 01:23:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 18F2C900002; Mon, 22 May 2023 01:23:32 -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 057B76B0075 for ; Mon, 22 May 2023 01:23:32 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id D24BEA0576 for ; Mon, 22 May 2023 05:23:31 +0000 (UTC) X-FDA: 80816748222.03.9DCF290 Received: from mail-yb1-f176.google.com (mail-yb1-f176.google.com [209.85.219.176]) by imf10.hostedemail.com (Postfix) with ESMTP id 0F7CCC0010 for ; Mon, 22 May 2023 05:23:29 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=OqBANCRQ; spf=pass (imf10.hostedemail.com: domain of hughd@google.com designates 209.85.219.176 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=1684733010; 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=lzQPoLjWXuP3+Ka40j/FX+cgzbLo3MyR/78LE/Otflc=; b=8CAJz4mw80FWprNm1bNlakEzeEDqNVNv8J1pThmURmVBy/wHBzRHfYla+wmns5K9KDbJbi tc9CQi6yZziTj8lfnh2+TnkKK+ivwShc/Ji5HhUwvFi1jsuiKxWwIVosKtzLdeIK1X50T8 w9oZeyKM1khqVm5BQmSOlcF6mqOcwAY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684733010; a=rsa-sha256; cv=none; b=M3AAG64VYeB3gtTcmCw93fdupxGI9PXsFRFD5gWcWCsTbSDwfWskO3o9CqW67irV4ybLpo uYjnYlQENwKt7bQM5pD4bLyeC5W+PSqtU7mSAqx2kSu+WuEUgPCXNY1R/oYpyVjTrv+NfY A0Fx3SPzYhFGK1LgKj7tX0gS5O1Fgjs= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=OqBANCRQ; spf=pass (imf10.hostedemail.com: domain of hughd@google.com designates 209.85.219.176 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-yb1-f176.google.com with SMTP id 3f1490d57ef6-b9daef8681fso4793342276.1 for ; Sun, 21 May 2023 22:23:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684733009; x=1687325009; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to; bh=lzQPoLjWXuP3+Ka40j/FX+cgzbLo3MyR/78LE/Otflc=; b=OqBANCRQzvanaas2fLT/vDBYw2XZ+pto0Z3I0g1aU/R1OYHuij2QrMo2xy+Rr6C35x l86kCF5UL52/GbeJlQ6bHEBRSpOVELHuSaKXNybOZhqbs+opPxUSDPmtJNEm+jrMaklN ft3L6EaR3I8ziuMCU5sNY2OaZ+zGmtKvbNZ9Tsv9F9B6wECrNMIjTpzlO5d+Z255LDVp yEk+S1bLKTQfkqEB9/oNMA15Vbb0/7X2Ek3v5V8dnbfTlUQxMGQNWKaElfOhfI5B5peu qIbnRaHYRIRCfQSqqRnyf0yf2fu8VPlbHJkeNdMJAA3hkVwFBfoZ10oZW3ZVmkHCSkfx eCng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684733009; x=1687325009; 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=lzQPoLjWXuP3+Ka40j/FX+cgzbLo3MyR/78LE/Otflc=; b=U8Psbvja4Mskh+xk/fLIO2neGkq9dfuSwqPEWurI4GzlMEMzo89yuGDjSkNrnLEY4k wvQ0qeAnEMlPWukjmMGoSNGQZ08J+lSRa69PNAL8jsXPgKVvigeY5IX6EJ5Wv2ZZ5l9o +1c2QdkDYZ9Zt9AM0G0r40cxQHr3qb5f85IEgO95g/G3t9WKnWAIbqGUxwELrC2s2VyZ Aop28p8m2ZOw3HUxH8Wfk1pB1xkW/KFwai9yIjSVECwrk3Pj5AI1g67W8pGs2LLF28fk n57/KRcAd5aziEbqdZt5d7+bm5y3Fss1mH2/us0oXlOMPVf4484cbGE6D9YRqEwpuQbg nJYA== X-Gm-Message-State: AC+VfDwQTm+73c7hZP/b/kRJTGhnb0PPB5KlJU5ARKGi/u6GRT8mro+f f6o3r6Jwnp4ZQOwp4F1hd1RHSQ== X-Google-Smtp-Source: ACHHUZ7qqz3U4uOnP6Ec8LA+Qz8AEibK4IaZAP5jwPoGGf6Fy3SqZkPf36XnHstJeJW2gmcrXMZvlw== X-Received: by 2002:a25:d2c5:0:b0:ba7:20a:3967 with SMTP id j188-20020a25d2c5000000b00ba7020a3967mr11645090ybg.43.1684733009011; Sun, 21 May 2023 22:23:29 -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 g10-20020a056902134a00b00b9db62abff3sm1277036ybu.58.2023.05.21.22.23.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 May 2023 22:23:28 -0700 (PDT) Date: Sun, 21 May 2023 22:23:25 -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 26/31] mm/huge_memory: split huge pmd under one pte_offset_map() In-Reply-To: <68a97fbe-5c1e-7ac6-72c-7b9c6290b370@google.com> Message-ID: <3f442a9c-af6d-573d-1ad1-f6f413b1abc9@google.com> References: <68a97fbe-5c1e-7ac6-72c-7b9c6290b370@google.com> MIME-Version: 1.0 X-Stat-Signature: n8tgmy887coshsenjisup9dwjnm4qme9 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 0F7CCC0010 X-Rspam-User: X-HE-Tag: 1684733009-920569 X-HE-Meta: U2FsdGVkX1//5JgjsBJLSPkXPmObNbiO++3UbRwyCrlFC1BEf3X4D8LM4iKdiN5R/htPFuPZzBBcqBOu5PcuqvsWMolt7GGh9agbHWWiSU1fU9meoXSfJUQbfXMLCdNNZ/5MSBcpUFf+1kdHHJciADJ+ceO+uuca0TpT5K64HyuZzW7upqh+Qk4lS6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a9LadzdeQQgZm0CpdhiQoB34VgdHlABJDL9ars74VGBKLeLrr5oaII4kKoKaPyOOYrQ7qjpBE2r4qX0CExEynFvtYEg13NLSt6zhUWx+3piagxPsdjN0XikawcwcLAVWiWVKkdx+m4DrMuxcQy//HUK3cMXfllWmB4lFIMDDZbuMWeJ0Fg3Q== 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: __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);