Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp2469954pxb; Thu, 3 Feb 2022 07:20:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJwu+Flc1MGCjlLshLlPuHXAix2uVQFm//QwI9AZGGGsguFZi2fl9rIbkd/0txC7RzUXjFOQ X-Received: by 2002:a17:90a:a385:: with SMTP id x5mr14438409pjp.129.1643901625398; Thu, 03 Feb 2022 07:20:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643901625; cv=none; d=google.com; s=arc-20160816; b=yIkuiVvNx4VSxl1ZUylvKQxvkmRCjatXDcAe8KR8WheOu5RE2xDAnypIgSnE5QtI86 xi6UEN0lHfAvqqN7ciuieLNMGkRuBEH4NLjeaNIBaFW7tSjXlztUY0st1NuKc046aJnL LN/xXbmEGaa//FJ/z2jInZOs4v0K07drcc07eiun8e7mddMsfeViPejoU10bJSDkZZSo 40Xw3D4NGOk3IKIYFhIz6Hb6YbxhMkq3XfCfEAC3LESA61JVrRI5bi2dWruoSylRviui OqjmgSMW3xJCkvN3IJ0R6/+93OmgaI4lwvTCd50SIBEoCeWNfx2h5tNV937dszmnW4Sk 9iSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=Q/9gAylFN9T7rNKYZGVZsTD41vtsc3/Xr6IAF55sKss=; b=nbWjJP3DuF2wCyILpNX2JF68lWrlhx4ARx9bcjcdvlpYlA1DmJQ5tLlWqq2Sjds9zO /O22VrezMerQSGaeBA86qCz/mceiWzSKSfDnZoGWpIQxeLFZRNtnU9abJjZK5jC/2/EY sFHU9XYdPDW9gDhN38zgRQAua/3HBFFadWWZL6mvi6rGhH98GPFfW+86U16+OwCh5hbJ m/Y+PEoB1jA3RMNHsARpTeOL8QUv0s6EwzhqKLHn3+lo27Cncwh5TIlPMIzr96xrMpNH wvn151xqwsSvFoOClNUj9M0SujkF9gU+Qb9kzXU1k8VG76BljOdLOeucYf8miTpZBXi1 tUiQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y10si21209652pfl.314.2022.02.03.07.20.12; Thu, 03 Feb 2022 07:20:25 -0800 (PST) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349264AbiBCD6E (ORCPT + 99 others); Wed, 2 Feb 2022 22:58:04 -0500 Received: from foss.arm.com ([217.140.110.172]:46550 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349259AbiBCD6D (ORCPT ); Wed, 2 Feb 2022 22:58:03 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 303381FB; Wed, 2 Feb 2022 19:58:03 -0800 (PST) Received: from p8cg001049571a15.arm.com (unknown [10.163.44.35]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 375473F774; Wed, 2 Feb 2022 19:57:58 -0800 (PST) From: Anshuman Khandual To: linux-mm@kvack.org Cc: christophe.leroy@csgroup.eu, Anshuman Khandual , Catalin Marinas , Will Deacon , Michael Ellerman , Paul Mackerras , "David S. Miller" , Mike Kravetz , Andrew Morton , linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, sparclinux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V2] mm: Merge pte_mkhuge() call into arch_make_huge_pte() Date: Thu, 3 Feb 2022 09:27:49 +0530 Message-Id: <1643860669-26307-1-git-send-email-anshuman.khandual@arm.com> X-Mailer: git-send-email 2.7.4 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Each call into pte_mkhuge() is invariably followed by arch_make_huge_pte(). Instead arch_make_huge_pte() can accommodate pte_mkhuge() at the beginning. This updates generic fallback stub for arch_make_huge_pte() and available platforms definitions. This makes huge pte creation much cleaner and easier to follow. Cc: Catalin Marinas Cc: Will Deacon Cc: Michael Ellerman Cc: Paul Mackerras Cc: "David S. Miller" Cc: Mike Kravetz Cc: Andrew Morton Cc: linux-arm-kernel@lists.infradead.org Cc: linuxppc-dev@lists.ozlabs.org Cc: sparclinux@vger.kernel.org Cc: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org Reviewed-by: Christophe Leroy Acked-by: Mike Kravetz Signed-off-by: Anshuman Khandual --- This applies on v5.17-rc2 Changes in V2: - Direct PTE encode in arch_make_huge_pte() on powerpc platform per Christophe Changes in V1: https://lore.kernel.org/all/1643780286-18798-1-git-send-email-anshuman.khandual@arm.com/ arch/arm64/mm/hugetlbpage.c | 1 + arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h | 4 ++-- arch/sparc/mm/hugetlbpage.c | 1 + include/linux/hugetlb.h | 2 +- mm/hugetlb.c | 3 +-- mm/vmalloc.c | 1 - 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/arch/arm64/mm/hugetlbpage.c b/arch/arm64/mm/hugetlbpage.c index ffb9c229610a..228226c5fa80 100644 --- a/arch/arm64/mm/hugetlbpage.c +++ b/arch/arm64/mm/hugetlbpage.c @@ -347,6 +347,7 @@ pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flags_t flags) { size_t pagesize = 1UL << shift; + entry = pte_mkhuge(entry); if (pagesize == CONT_PTE_SIZE) { entry = pte_mkcont(entry); } else if (pagesize == CONT_PMD_SIZE) { diff --git a/arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h b/arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h index 64b6c608eca4..de092b04ee1a 100644 --- a/arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h +++ b/arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h @@ -71,9 +71,9 @@ static inline pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flags size_t size = 1UL << shift; if (size == SZ_16K) - return __pte(pte_val(entry) & ~_PAGE_HUGE); + return __pte(pte_val(entry) | _PAGE_SPS); else - return entry; + return __pte(pte_val(entry) | _PAGE_SPS | _PAGE_HUGE); } #define arch_make_huge_pte arch_make_huge_pte #endif diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c index 0f49fada2093..d8e0e3c7038d 100644 --- a/arch/sparc/mm/hugetlbpage.c +++ b/arch/sparc/mm/hugetlbpage.c @@ -181,6 +181,7 @@ pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flags_t flags) { pte_t pte; + entry = pte_mkhuge(entry); pte = hugepage_shift_to_tte(entry, shift); #ifdef CONFIG_SPARC64 diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index d1897a69c540..52c462390aee 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -754,7 +754,7 @@ static inline void arch_clear_hugepage_flags(struct page *page) { } static inline pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flags_t flags) { - return entry; + return pte_mkhuge(entry); } #endif diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 61895cc01d09..5ca253c1b4e4 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -4637,7 +4637,6 @@ static pte_t make_huge_pte(struct vm_area_struct *vma, struct page *page, vma->vm_page_prot)); } entry = pte_mkyoung(entry); - entry = pte_mkhuge(entry); entry = arch_make_huge_pte(entry, shift, vma->vm_flags); return entry; @@ -6172,7 +6171,7 @@ unsigned long hugetlb_change_protection(struct vm_area_struct *vma, unsigned int shift = huge_page_shift(hstate_vma(vma)); old_pte = huge_ptep_modify_prot_start(vma, address, ptep); - pte = pte_mkhuge(huge_pte_modify(old_pte, newprot)); + pte = huge_pte_modify(old_pte, newprot); pte = arch_make_huge_pte(pte, shift, vma->vm_flags); huge_ptep_modify_prot_commit(vma, address, ptep, old_pte, pte); pages++; diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 4165304d3547..d0b14dd73adc 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -118,7 +118,6 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end, if (size != PAGE_SIZE) { pte_t entry = pfn_pte(pfn, prot); - entry = pte_mkhuge(entry); entry = arch_make_huge_pte(entry, ilog2(size), 0); set_huge_pte_at(&init_mm, addr, pte, entry); pfn += PFN_DOWN(size); -- 2.25.1