From patchwork Thu Jul 4 04:30:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13723187 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 E4969C30653 for ; Thu, 4 Jul 2024 04:32:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1570C6B009C; Thu, 4 Jul 2024 00:32:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0DF096B009D; Thu, 4 Jul 2024 00:32:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DFDE86B009E; Thu, 4 Jul 2024 00:32:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id B597C6B009C for ; Thu, 4 Jul 2024 00:32:04 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 485ACA0FBD for ; Thu, 4 Jul 2024 04:32:04 +0000 (UTC) X-FDA: 82300797768.20.BECD8B8 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf26.hostedemail.com (Postfix) with ESMTP id 288CF140010 for ; Thu, 4 Jul 2024 04:32:01 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=mvxA8c0w; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=gtiiSyL8; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=mvxA8c0w; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=gtiiSyL8; spf=pass (imf26.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.131 as permitted sender) smtp.mailfrom=osalvador@suse.de; dmarc=pass (policy=none) header.from=suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1720067498; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=759iJlxKnytdAlee8rRqvYsRUqK1GzIE0jiP12kfaog=; b=cl7GkMa0IimPtFB1v4U6nO5GSN+R0dn39tTHfxKr/S+9e3paPcTbHscYfp7tJatjBZYR+D gJ2G4Tz62eVXb/vHkuwacXvN+asX24/gvpkl538veGk5KUXlob/OPbAX6wRbQ+1ZK4DMAz zzV+3gGBXxdaK1/ZwUiSe7shkQvLsHs= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720067498; a=rsa-sha256; cv=none; b=GIhc3Sau63rocnlDFUtN36CVN67QR1tUk4DveN24hiJ7UZRygGJcvNI7ub52l4EGkf95Gi tUux2OYtWTJ2dRRbvFSNtj1BHRR6WKmbsYAJAm5smcXoQ2Dhve/TpP0MpNWC0BwhggxTu7 wBGUk30JW51vpN4hoqqgosCThoQGAIg= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=mvxA8c0w; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=gtiiSyL8; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=mvxA8c0w; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=gtiiSyL8; spf=pass (imf26.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.131 as permitted sender) smtp.mailfrom=osalvador@suse.de; dmarc=pass (policy=none) header.from=suse.de Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id D4A8C1FCF8; Thu, 4 Jul 2024 04:32:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1720067520; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=759iJlxKnytdAlee8rRqvYsRUqK1GzIE0jiP12kfaog=; b=mvxA8c0wNNkkavEyFQzOp2mf8378ze4FIH4m4ZfgOZRJ7zpzcoSPW950dQZsa3S/CK+ttv iZlMjg840j6JYRueSYvhI7YBduf5ZmQglN6zSGHvYGjJBa7Jy2q7URNYkz9x4o2JnliPCw zchyR+/MljAZfrr+nxrpTvg2ZDweQk4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1720067520; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=759iJlxKnytdAlee8rRqvYsRUqK1GzIE0jiP12kfaog=; b=gtiiSyL8IoxKC27iK+u4Mo4MByRQvcwll4qDeKH5vMoKVQYazRAVgxQtYJlScwNErbS0UE MtZSHFG7y/+A7DCQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1720067520; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=759iJlxKnytdAlee8rRqvYsRUqK1GzIE0jiP12kfaog=; b=mvxA8c0wNNkkavEyFQzOp2mf8378ze4FIH4m4ZfgOZRJ7zpzcoSPW950dQZsa3S/CK+ttv iZlMjg840j6JYRueSYvhI7YBduf5ZmQglN6zSGHvYGjJBa7Jy2q7URNYkz9x4o2JnliPCw zchyR+/MljAZfrr+nxrpTvg2ZDweQk4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1720067520; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=759iJlxKnytdAlee8rRqvYsRUqK1GzIE0jiP12kfaog=; b=gtiiSyL8IoxKC27iK+u4Mo4MByRQvcwll4qDeKH5vMoKVQYazRAVgxQtYJlScwNErbS0UE MtZSHFG7y/+A7DCQ== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id A5A4213889; Thu, 4 Jul 2024 04:31:59 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id uIG7I78lhmbnDAAAD6G6ig (envelope-from ); Thu, 04 Jul 2024 04:31:59 +0000 From: Oscar Salvador To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Peter Xu , Muchun Song , David Hildenbrand , SeongJae Park , Miaohe Lin , Michal Hocko , Matthew Wilcox , Christophe Leroy , Oscar Salvador Subject: [PATCH 09/45] mm: Implement pud-version functions for swap and vm_normal_page_pud Date: Thu, 4 Jul 2024 06:30:56 +0200 Message-ID: <20240704043132.28501-10-osalvador@suse.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240704043132.28501-1-osalvador@suse.de> References: <20240704043132.28501-1-osalvador@suse.de> MIME-Version: 1.0 X-Rspamd-Queue-Id: 288CF140010 X-Stat-Signature: diwuh6hz1711hdktud5q1kn77gp1fays X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1720067521-97985 X-HE-Meta: U2F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jD/2FFutnLgSED0ufjXV7LrUHTbD2XxDhMr+kVAzjVrqTFuwMBLf3rGQrOjj8hC28AkoaDGo0IxijHYn+jEg4SUOfrC62ajL++WDlQBohhxXbDJyLphIGs+BB++LqQ7CRIBDD8Y/Oxa+a60osCwwoOZ8FxMPSS8yAyXRRPwaD/WXumvHFR8Ic2a 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: List-Subscribe: List-Unsubscribe: HugeTLB pages will be handled on pud level as well, so we need to implement pud-version of vm_normal_page_pud and swp-pud functions. Signed-off-by: Oscar Salvador --- arch/powerpc/include/asm/book3s/64/pgtable.h | 1 + include/linux/mm.h | 4 ++ include/linux/pgtable.h | 6 +++ include/linux/swapops.h | 15 ++++++ mm/memory.c | 51 ++++++++++++++++++++ 5 files changed, 77 insertions(+) diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h b/arch/powerpc/include/asm/book3s/64/pgtable.h index 519b1743a0f4..fa4bb8d6356f 100644 --- a/arch/powerpc/include/asm/book3s/64/pgtable.h +++ b/arch/powerpc/include/asm/book3s/64/pgtable.h @@ -687,6 +687,7 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t newprot) #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val((pte)) & ~_PAGE_PTE }) #define __swp_entry_to_pte(x) __pte((x).val | _PAGE_PTE) #define __pmd_to_swp_entry(pmd) (__pte_to_swp_entry(pmd_pte(pmd))) +#define __pud_to_swp_entry(pud) (__pte_to_swp_entry(pud_pte(pud))) #define __swp_entry_to_pmd(x) (pte_pmd(__swp_entry_to_pte(x))) #ifdef CONFIG_MEM_SOFT_DIRTY diff --git a/include/linux/mm.h b/include/linux/mm.h index 5f1075d19600..baade06b159b 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2371,6 +2371,10 @@ struct folio *vm_normal_folio_pmd(struct vm_area_struct *vma, unsigned long addr, pmd_t pmd); struct page *vm_normal_page_pmd(struct vm_area_struct *vma, unsigned long addr, pmd_t pmd); +struct folio *vm_normal_folio_pud(struct vm_area_struct *vma, + unsigned long addr, pud_t pud); +struct page *vm_normal_page_pud(struct vm_area_struct *vma, unsigned long addr, + pud_t pud); void zap_vma_ptes(struct vm_area_struct *vma, unsigned long address, unsigned long size); diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h index 3a7b8751747e..a9edeb86b7fe 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -1990,4 +1990,10 @@ pgprot_t vm_get_page_prot(unsigned long vm_flags) \ } \ EXPORT_SYMBOL(vm_get_page_prot); +#ifdef CONFIG_HUGETLB_PAGE +#ifndef __pud_to_swp_entry +#define __pud_to_swp_entry(pud) ((swp_entry_t) { pud_val(pud) }) +#endif +#endif + #endif /* _LINUX_PGTABLE_H */ diff --git a/include/linux/swapops.h b/include/linux/swapops.h index cb468e418ea1..182957f0d013 100644 --- a/include/linux/swapops.h +++ b/include/linux/swapops.h @@ -126,6 +126,21 @@ static inline int is_swap_pte(pte_t pte) return !pte_none(pte) && !pte_present(pte); } +#ifdef CONFIG_HUGETLB_PAGE +static inline int is_swap_pud(pud_t pud) +{ + return !pud_none(pud) && !pud_present(pud); +} + +static inline swp_entry_t pud_to_swp_entry(pud_t pud) +{ + swp_entry_t arch_entry; + + arch_entry = __pud_to_swp_entry(pud); + return swp_entry(__swp_type(arch_entry), __swp_offset(arch_entry)); +} +#endif + /* * Convert the arch-dependent pte representation of a swp_entry_t into an * arch-independent swp_entry_t. diff --git a/mm/memory.c b/mm/memory.c index 0a769f34bbb2..90c5dfac35c6 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -718,6 +718,57 @@ struct folio *vm_normal_folio_pmd(struct vm_area_struct *vma, } #endif +#ifdef CONFIG_HUGETLB_PAGE +struct page *vm_normal_page_pud(struct vm_area_struct *vma, unsigned long addr, + pud_t pud) +{ + unsigned long pfn = pud_pfn(pud); + + /* + * There is no pmd_special() but there may be special pmds, e.g. + * in a direct-access (dax) mapping, so let's just replicate the + * !CONFIG_ARCH_HAS_PTE_SPECIAL case from vm_normal_page() here. + */ + if (unlikely(vma->vm_flags & (VM_PFNMAP|VM_MIXEDMAP))) { + if (vma->vm_flags & VM_MIXEDMAP) { + if (!pfn_valid(pfn)) + return NULL; + goto out; + } else { + unsigned long off; + + off = (addr - vma->vm_start) >> PAGE_SHIFT; + if (pfn == vma->vm_pgoff + off) + return NULL; + if (!is_cow_mapping(vma->vm_flags)) + return NULL; + } + } + + if (pud_devmap(pud)) + return NULL; + if (unlikely(pfn > highest_memmap_pfn)) + return NULL; + + /* + * NOTE! We still have PageReserved() pages in the page tables. + * eg. VDSO mappings can cause them to exist. + */ +out: + return pfn_to_page(pfn); +} + +struct folio *vm_normal_folio_pud(struct vm_area_struct *vma, + unsigned long addr, pud_t pud) +{ + struct page *page = vm_normal_page_pud(vma, addr, pud); + + if (page) + return page_folio(page); + return NULL; +} +#endif + static void restore_exclusive_pte(struct vm_area_struct *vma, struct page *page, unsigned long address, pte_t *ptep)