Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp403178img; Wed, 20 Mar 2019 03:09:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqyEzdQUvJZHv6VaZstA+DeSlYOyqTo8Xr6x8rj9J2PMY2ZdkH9dGU/Mmw+G9bMa+4HA0uSG X-Received: by 2002:a17:902:bd96:: with SMTP id q22mr7119584pls.7.1553076562491; Wed, 20 Mar 2019 03:09:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553076562; cv=none; d=google.com; s=arc-20160816; b=rK6fOHzSyibf8gtYK5ZpHcZHqRvgUwogB32UMbTdp3oMYkRFLkRgnQLofoUFTGHd2R WfSZgeNUO4ZczsGy8V3zBUFNm+i1u4d0G8JdBXQa6ypQ/Do9U408DeEhTqBqWSzt/hRQ KzuCNuYUBwCTt4BOHhKopTPuKObO6iZHhW5wB2TruJUsA2ttoJg9Iunnrd/KJYWEQagj tJ8nSz6yNkxt6Vq0/axkaIctuQx7A2YkF0UY9Tne9fyR2J34iuPTohXjyw45+oysKuXR DgdbG3afQOrgn6ShYRblmZqvYPGtdVs/R+mMjtQP9CrJI21rQIq9Lq9Gnx/4W8bQVTtA AQuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:cc:to:subject:from:references :in-reply-to:message-id:dkim-signature; bh=3Qt6UQ3ffffO/L8sunyHgvgpbRibyr/ois3WcgDAd5g=; b=AKhK9RGn/ygLrmpITcikPNUF7EexuK0IUu2N636iSaLA44dJuZr2qr7qsvKUNBtZDu bwWi6LrQ6XIhxN5IG5sRLJrgwAVtX9bX7bg1/7RIC5QlkPX5v57OsuxwaOz/EXR1qoas a9CGqyOzg+2AKooWSj8KMAhHVaKJ5mmX7gYnS/JKoz323DQqcDwreg1kx/DvpYqeVDjj M2qMMLATTyfB1ICxscpvZ+tw2aRkNlJQAzaKNrnNdroTLibhu4d7bCmZWlHSPO5FYv8c //f4RJj18WCZnxf4UONOewnOVfGGAuW1MFqx91ImtALS8kcaMeOiyUt/UiFHQMPVVkCD a6qA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=GJlgJvUn; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x14si1467650pgq.185.2019.03.20.03.09.06; Wed, 20 Mar 2019 03:09:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=GJlgJvUn; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727793AbfCTKGz (ORCPT + 99 others); Wed, 20 Mar 2019 06:06:55 -0400 Received: from pegase1.c-s.fr ([93.17.236.30]:8626 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727743AbfCTKGx (ORCPT ); Wed, 20 Mar 2019 06:06:53 -0400 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 44PQZ24l3jz9vC04; Wed, 20 Mar 2019 11:06:50 +0100 (CET) Authentication-Results: localhost; dkim=pass reason="1024-bit key; insecure key" header.d=c-s.fr header.i=@c-s.fr header.b=GJlgJvUn; dkim-adsp=pass; dkim-atps=neutral X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id AJQbp7OS1rAz; Wed, 20 Mar 2019 11:06:50 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 44PQZ23bWVz9vByx; Wed, 20 Mar 2019 11:06:50 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1553076410; bh=3Qt6UQ3ffffO/L8sunyHgvgpbRibyr/ois3WcgDAd5g=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=GJlgJvUnLRdqDLK0qxzNY2px6Q87Wq+D3ptunkddYDVp+dc1a0LpVVBKyRgjaJZ2G Uhtws7C3jwrF4w+GLQRrwj/fAfgZ28R+JCEpTcWF0REs5+0ebg1eG0CzS0w9HxDlvc HxSLdNkfw2tNy/fbKycSQtuYAi6x3+uLYMhh1fZ4= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 9B7BE8B918; Wed, 20 Mar 2019 11:06:51 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id LpscSlKqI4Ug; Wed, 20 Mar 2019 11:06:51 +0100 (CET) Received: from po16846vm.idsi0.si.c-s.fr (unknown [172.25.231.2]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 7330F8B911; Wed, 20 Mar 2019 11:06:51 +0100 (CET) Received: by po16846vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 51CC363AEF; Wed, 20 Mar 2019 10:06:51 +0000 (UTC) Message-Id: <54f43a41968cf6db1369f98247618c58ed2ff94d.1553076180.git.christophe.leroy@c-s.fr> In-Reply-To: References: From: Christophe Leroy Subject: [PATCH v1 15/27] powerpc/mm: cleanup ifdef mess in add_huge_page_size() To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , aneesh.kumar@linux.ibm.com Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Date: Wed, 20 Mar 2019 10:06:51 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Introduce a subarch specific helper check_and_get_huge_psize() to check the huge page sizes and cleanup the ifdef mess in add_huge_page_size() Signed-off-by: Christophe Leroy --- arch/powerpc/include/asm/book3s/64/hugetlb.h | 27 +++++++++++++++++ arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h | 5 ++++ arch/powerpc/include/asm/nohash/hugetlb-book3e.h | 8 +++++ arch/powerpc/mm/hugetlbpage.c | 37 ++---------------------- 4 files changed, 43 insertions(+), 34 deletions(-) diff --git a/arch/powerpc/include/asm/book3s/64/hugetlb.h b/arch/powerpc/include/asm/book3s/64/hugetlb.h index 177c81079209..4522a56a6269 100644 --- a/arch/powerpc/include/asm/book3s/64/hugetlb.h +++ b/arch/powerpc/include/asm/book3s/64/hugetlb.h @@ -108,4 +108,31 @@ static inline void hugepd_populate(hugepd_t *hpdp, pte_t *new, unsigned int pshi void flush_hugetlb_page(struct vm_area_struct *vma, unsigned long vmaddr); +static inline int check_and_get_huge_psize(int shift) +{ + int mmu_psize; + + if (shift > SLICE_HIGH_SHIFT) + return -EINVAL; + + mmu_psize = shift_to_mmu_psize(shift); + + /* + * We need to make sure that for different page sizes reported by + * firmware we only add hugetlb support for page sizes that can be + * supported by linux page table layout. + * For now we have + * Radix: 2M and 1G + * Hash: 16M and 16G + */ + if (radix_enabled()) { + if (mmu_psize != MMU_PAGE_2M && mmu_psize != MMU_PAGE_1G) + return -EINVAL; + } else { + if (mmu_psize != MMU_PAGE_16M && mmu_psize != MMU_PAGE_16G) + return -EINVAL; + } + return mmu_psize; +} + #endif diff --git a/arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h b/arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h index eb90c2db7601..a442b499d5c8 100644 --- a/arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h +++ b/arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h @@ -37,4 +37,9 @@ static inline void hugepd_populate(hugepd_t *hpdp, pte_t *new, unsigned int pshi (pshift == PAGE_SHIFT_8M ? _PMD_PAGE_8M : _PMD_PAGE_512K)); } +static inline int check_and_get_huge_psize(int shift) +{ + return shift_to_mmu_psize(shift); +} + #endif /* _ASM_POWERPC_NOHASH_32_HUGETLB_8XX_H */ diff --git a/arch/powerpc/include/asm/nohash/hugetlb-book3e.h b/arch/powerpc/include/asm/nohash/hugetlb-book3e.h index 51439bcfe313..ecd8694cb229 100644 --- a/arch/powerpc/include/asm/nohash/hugetlb-book3e.h +++ b/arch/powerpc/include/asm/nohash/hugetlb-book3e.h @@ -34,4 +34,12 @@ static inline void hugepd_populate(hugepd_t *hpdp, pte_t *new, unsigned int pshi *hpdp = __hugepd(((unsigned long)new & ~PD_HUGE) | pshift); } +static inline int check_and_get_huge_psize(int shift) +{ + if (shift & 1) /* Not a power of 4 */ + return -EINVAL; + + return shift_to_mmu_psize(shift); +} + #endif /* _ASM_POWERPC_NOHASH_HUGETLB_BOOK3E_H */ diff --git a/arch/powerpc/mm/hugetlbpage.c b/arch/powerpc/mm/hugetlbpage.c index 87358b89513e..3b449c9d4e47 100644 --- a/arch/powerpc/mm/hugetlbpage.c +++ b/arch/powerpc/mm/hugetlbpage.c @@ -549,13 +549,6 @@ unsigned long vma_mmu_pagesize(struct vm_area_struct *vma) return vma_kernel_pagesize(vma); } -static inline bool is_power_of_4(unsigned long x) -{ - if (is_power_of_2(x)) - return (__ilog2(x) % 2) ? false : true; - return false; -} - static int __init add_huge_page_size(unsigned long long size) { int shift = __ffs(size); @@ -563,37 +556,13 @@ static int __init add_huge_page_size(unsigned long long size) /* Check that it is a page size supported by the hardware and * that it fits within pagetable and slice limits. */ - if (size <= PAGE_SIZE) - return -EINVAL; -#if defined(CONFIG_PPC_FSL_BOOK3E) - if (!is_power_of_4(size)) + if (size <= PAGE_SIZE || !is_power_of_2(size)) return -EINVAL; -#elif !defined(CONFIG_PPC_8xx) - if (!is_power_of_2(size) || (shift > SLICE_HIGH_SHIFT)) - return -EINVAL; -#endif - if ((mmu_psize = shift_to_mmu_psize(shift)) < 0) + mmu_psize = check_and_get_huge_psize(size); + if (mmu_psize < 0) return -EINVAL; -#ifdef CONFIG_PPC_BOOK3S_64 - /* - * We need to make sure that for different page sizes reported by - * firmware we only add hugetlb support for page sizes that can be - * supported by linux page table layout. - * For now we have - * Radix: 2M and 1G - * Hash: 16M and 16G - */ - if (radix_enabled()) { - if (mmu_psize != MMU_PAGE_2M && mmu_psize != MMU_PAGE_1G) - return -EINVAL; - } else { - if (mmu_psize != MMU_PAGE_16M && mmu_psize != MMU_PAGE_16G) - return -EINVAL; - } -#endif - if (WARN_ON(mmu_psize_defs[mmu_psize].shift != shift)) return -EINVAL; -- 2.13.3