From patchwork Sun Nov 8 14:11:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 11889613 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E1EAA139F for ; Sun, 8 Nov 2020 14:13:04 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id AA02A208B6 for ; Sun, 8 Nov 2020 14:13:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=bytedance-com.20150623.gappssmtp.com header.i=@bytedance-com.20150623.gappssmtp.com header.b="NVXNzHd6" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AA02A208B6 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id E082B6B005D; Sun, 8 Nov 2020 09:13:03 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id DB57C6B0072; Sun, 8 Nov 2020 09:13:03 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C56586B0073; Sun, 8 Nov 2020 09:13:03 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0059.hostedemail.com [216.40.44.59]) by kanga.kvack.org (Postfix) with ESMTP id 981796B005D for ; Sun, 8 Nov 2020 09:13:03 -0500 (EST) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 45A2F180AD802 for ; Sun, 8 Nov 2020 14:13:03 +0000 (UTC) X-FDA: 77461442646.22.money74_1f155dc272e4 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin22.hostedemail.com (Postfix) with ESMTP id 1E84518038E67 for ; Sun, 8 Nov 2020 14:13:03 +0000 (UTC) X-Spam-Summary: 1,0,0,cfff28adcdfa6a7e,d41d8cd98f00b204,songmuchun@bytedance.com,,RULES_HIT:41:355:379:541:800:960:966:973:988:989:1260:1311:1314:1345:1359:1437:1515:1535:1543:1711:1730:1747:1777:1792:2196:2199:2393:2559:2562:2693:3138:3139:3140:3141:3142:3355:3865:3866:3867:3868:3870:3871:3872:4118:4321:4385:5007:6119:6261:6653:6737:6738:7903:10004:11026:11473:11658:11914:12043:12048:12291:12296:12297:12438:12517:12519:12555:12683:12895:13161:13229:13894:13972:14096:14181:14394:14721:21080:21222:21444:21451:21611:21627:21990:30012:30054,0,RBL:209.85.215.194:@bytedance.com:.lbl8.mailshell.net-62.2.0.100 66.100.201.201;04yf8f81tgshtt1o3qeuwh8beix6gyc7xshcgd6fpgxssno7c8zupa3yiu1j1qs.ieapzjjpoopb9d1sbkywxmtc644oogfqkz9ra9mdbmm437n83sxbtmmr4t5rtyc.s-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:68,LUA_SUMMARY:none X-HE-Tag: money74_1f155dc272e4 X-Filterd-Recvd-Size: 7246 Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.194]) by imf02.hostedemail.com (Postfix) with ESMTP for ; Sun, 8 Nov 2020 14:13:02 +0000 (UTC) Received: by mail-pg1-f194.google.com with SMTP id f27so1219978pgl.1 for ; Sun, 08 Nov 2020 06:13:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gJvwt6IYpSrNpCnp/nDtM/yb/962d0wM2I3fDXrMctE=; b=NVXNzHd63ZTvB8FSYDnHadOs+KBue+oFdqo7vfMUXTqNE8PQnK5L9eUWqwLW/e55sJ ZcnzJpzUGn1xd5HuBD2MyemUrRCo+xFzWgTVcv+sK05Bg/9w6yYMOQyt0SjgkAiRq9dh GpUmasIs9Us+iBPjlDX4YUMBylwVI1EYVgEdYE4NrrTjD0ay5aAmYrAv1tIq81NMSYqC bhJgDF8y5kWDpTmbOY/V2QwIGAwVS0PHHEWV1dTByf0tpvqn/k9NfkoEH2ZnAA6Bbk2y t9LGrhY4z1x2ghjn3oNu+bo/+k5lyhy7Did+wyTeR71fnpEUthynykNZnFNCNtW70Iuo FRuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gJvwt6IYpSrNpCnp/nDtM/yb/962d0wM2I3fDXrMctE=; b=p3UPDDZRnkHFty6RtwzWKgP5bffAQz4J3unmOj9EptXFPIqjDOX2gs1+ohxSgNgfOO m/E8Sn6LQfL+WIPxMsL2/hOv9d/IzAEI7X6Cj3GnAUJ6EvYvXINGl1PT0ohLGmBrLR8L 2BOJFXX4t+2vUAB+Avg9yUcucwUvEbv/HbELyjVtkKMNCn5ij6FgfVcYEy5Mn6w4D2QE wvKSzFNygjsE0qKIJ9m2RYWoJfYSIPZ3S7vZ7TweljPBhmTXS4JUOWIEpiRbJpkQ6SXk 49X87nco01GYxMTyPYZi4nxmhJsx1ve9XdQX6ZAqQ6iq5C2u3kdEnDOApBM0VU8gfKUq 6QUg== X-Gm-Message-State: AOAM533CLNpbIeydJdFsISj72EGiSnRZ0N2DAomVSpeMTQEH4lvkn59e kV8Juj3nxaM9NT5T9izoJixQwg== X-Google-Smtp-Source: ABdhPJyQqWPpgmRvgnD972Khgu3G9Ptsqvw1zov+M+MkcF3Btc4R4kANj2R843j2oHElxn5CHv31+Q== X-Received: by 2002:a62:194:0:b029:18b:b0f6:1e1b with SMTP id 142-20020a6201940000b029018bb0f61e1bmr9820395pfb.71.1604844781837; Sun, 08 Nov 2020 06:13:01 -0800 (PST) Received: from localhost.localdomain ([103.136.220.94]) by smtp.gmail.com with ESMTPSA id z11sm8754047pfk.52.2020.11.08.06.12.52 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 08 Nov 2020 06:13:01 -0800 (PST) From: Muchun Song To: corbet@lwn.net, mike.kravetz@oracle.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, x86@kernel.org, hpa@zytor.com, dave.hansen@linux.intel.com, luto@kernel.org, peterz@infradead.org, viro@zeniv.linux.org.uk, akpm@linux-foundation.org, paulmck@kernel.org, mchehab+huawei@kernel.org, pawan.kumar.gupta@linux.intel.com, rdunlap@infradead.org, oneukum@suse.com, anshuman.khandual@arm.com, jroedel@suse.de, almasrymina@google.com, rientjes@google.com, willy@infradead.org, osalvador@suse.de, mhocko@suse.com Cc: duanxiongchun@bytedance.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, Muchun Song Subject: [PATCH v3 08/21] mm/vmemmap: Initialize page table lock for vmemmap Date: Sun, 8 Nov 2020 22:11:00 +0800 Message-Id: <20201108141113.65450-9-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20201108141113.65450-1-songmuchun@bytedance.com> References: <20201108141113.65450-1-songmuchun@bytedance.com> MIME-Version: 1.0 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: In the register_page_bootmem_memmap, the slab allocator is not ready yet. So when ALLOC_SPLIT_PTLOCKS, we use init_mm.page_table_lock. otherwise we use per page table lock(page->ptl). In the later patch, we will use the vmemmap page table lock to guard the splitting of the vmemmap huge PMD. Signed-off-by: Muchun Song --- arch/x86/mm/init_64.c | 2 ++ include/linux/mm.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c index 0435bee2e172..a010101bbe24 100644 --- a/arch/x86/mm/init_64.c +++ b/arch/x86/mm/init_64.c @@ -1610,6 +1610,8 @@ void register_page_bootmem_memmap(unsigned long section_nr, } get_page_bootmem(section_nr, pud_page(*pud), MIX_SECTION_INFO); + vmemmap_ptlock_init(pud_page(*pud)); + if (!boot_cpu_has(X86_FEATURE_PSE)) { next = (addr + PAGE_SIZE) & PAGE_MASK; pmd = pmd_offset(pud, addr); diff --git a/include/linux/mm.h b/include/linux/mm.h index a12354e63e49..ce429614d1ab 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2169,6 +2169,26 @@ static inline bool ptlock_init(struct page *page) return true; } +#if ALLOC_SPLIT_PTLOCKS +static inline void vmemmap_ptlock_init(struct page *page) +{ +} +#else +static inline void vmemmap_ptlock_init(struct page *page) +{ + /* + * prep_new_page() initialize page->private (and therefore page->ptl) + * with 0. Make sure nobody took it in use in between. + * + * It can happen if arch try to use slab for page table allocation: + * slab code uses page->{s_mem, counters}, which share storage with + * page->ptl. + */ + VM_BUG_ON_PAGE(*(unsigned long *)&page->ptl, page); + spin_lock_init(ptlock_ptr(page)); +} +#endif + #else /* !USE_SPLIT_PTE_PTLOCKS */ /* * We use mm->page_table_lock to guard all pagetable pages of the mm. @@ -2180,6 +2200,7 @@ static inline spinlock_t *pte_lockptr(struct mm_struct *mm, pmd_t *pmd) static inline void ptlock_cache_init(void) {} static inline bool ptlock_init(struct page *page) { return true; } static inline void ptlock_free(struct page *page) {} +static inline void vmemmap_ptlock_init(struct page *page) {} #endif /* USE_SPLIT_PTE_PTLOCKS */ static inline void pgtable_init(void) @@ -2244,6 +2265,18 @@ static inline spinlock_t *pmd_lockptr(struct mm_struct *mm, pmd_t *pmd) return ptlock_ptr(pmd_to_page(pmd)); } +#if ALLOC_SPLIT_PTLOCKS +static inline spinlock_t *vmemmap_pmd_lockptr(pmd_t *pmd) +{ + return &init_mm.page_table_lock; +} +#else +static inline spinlock_t *vmemmap_pmd_lockptr(pmd_t *pmd) +{ + return ptlock_ptr(pmd_to_page(pmd)); +} +#endif + static inline bool pmd_ptlock_init(struct page *page) { #ifdef CONFIG_TRANSPARENT_HUGEPAGE @@ -2269,6 +2302,11 @@ static inline spinlock_t *pmd_lockptr(struct mm_struct *mm, pmd_t *pmd) return &mm->page_table_lock; } +static inline spinlock_t *vmemmap_pmd_lockptr(pmd_t *pmd) +{ + return &init_mm.page_table_lock; +} + static inline bool pmd_ptlock_init(struct page *page) { return true; } static inline void pmd_ptlock_free(struct page *page) {} @@ -2283,6 +2321,13 @@ static inline spinlock_t *pmd_lock(struct mm_struct *mm, pmd_t *pmd) return ptl; } +static inline spinlock_t *vmemmap_pmd_lock(pmd_t *pmd) +{ + spinlock_t *ptl = vmemmap_pmd_lockptr(pmd); + spin_lock(ptl); + return ptl; +} + static inline bool pgtable_pmd_page_ctor(struct page *page) { if (!pmd_ptlock_init(page))