Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp287569yba; Thu, 25 Apr 2019 23:24:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqxcqIRkBebYyLMVV3UtD54IC5mRaGyH4QsHCRzS9f7STfVS8i6KVg+p6lx2HwH3fgsolZDI X-Received: by 2002:a63:6fc1:: with SMTP id k184mr42280474pgc.239.1556259864024; Thu, 25 Apr 2019 23:24:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556259864; cv=none; d=google.com; s=arc-20160816; b=BecEhBIPgUMmfPfi+JYB3fYrYo1/yk51F/EMdrXMzoNMHTJp7ab4zSIxpz/WtRPfbO doYOZek3aYvZCMSp4sHw9qlyjMVx9Tb//9ZVf+u0g6dEDcP+O6SZ7SxrCg/VNAVoRpYH ZF4ti6/FWnqqKMKXimCSSang8Ign0HCuMun07qRe+dLUDVkJuArHzjxi/8xWQ64hvRSd ldc4wAAhJXZ0k4rP73KHfZskKfBculVrQqWhzp9L6RHw8B7nHDOKljxiyT1AnhqNjoLZ J0WvfyBvKk5GpPClc/6Y6rWS2MxxsVX/L0MqMZ+2amppcMAEN0zkTUF8fi9asBM4eHKF eVMw== 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=QToxofJ1PaFaM/QQt1TF/vg3DxZfKiY0Bf3t2AIYKS0=; b=pILfEeygNA39p7I+7oEoUBVGYLH85nbUTxHsfEEx1nB8O2wUcwE3BPHx5sOsmZiGM0 sSrmoHyx/JlM8ykDfgfMFotduCl/aVsIet+PZ7Bz0P15SoDYuRnDx6N5nGR1SVP4SS/Q Llm3VTQC/ZhVB87RH1QOIFoq6f660BggPAcJvKcwIwhdDjvaX/wEOyAG4zkuyPdtaBhJ vqOyXnxGG0cT72wfpVgNwUX75Pq3eoBfnxmaImvp6Np9/ePtTTWkozinXwZMCP+ays2e 4ZINes4inLWqn/8dSpEJ4FxeOjyqvJdBIc6v/idczNUEyC/gmZXbTPQ4uvdlN8wRB5iq yh1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b="I7O/Xg1i"; 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 f1si23676960pgm.373.2019.04.25.23.24.08; Thu, 25 Apr 2019 23:24:24 -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="I7O/Xg1i"; 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 S1727088AbfDZF7x (ORCPT + 99 others); Fri, 26 Apr 2019 01:59:53 -0400 Received: from pegase1.c-s.fr ([93.17.236.30]:7443 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726991AbfDZF7u (ORCPT ); Fri, 26 Apr 2019 01:59:50 -0400 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 44r3Kt2wLtz9v1vN; Fri, 26 Apr 2019 07:59:46 +0200 (CEST) Authentication-Results: localhost; dkim=pass reason="1024-bit key; insecure key" header.d=c-s.fr header.i=@c-s.fr header.b=I7O/Xg1i; 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 PPl-j5Hxcffv; Fri, 26 Apr 2019 07:59:46 +0200 (CEST) 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 44r3Kt1lHxz9v1tj; Fri, 26 Apr 2019 07:59:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1556258386; bh=QToxofJ1PaFaM/QQt1TF/vg3DxZfKiY0Bf3t2AIYKS0=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=I7O/Xg1i0RWM96o5P+e28nG2OdP4Ozrn+twWxyqXB3td8HLpPg6ThT77DQVtzuY72 f3bXRqI/oqQvPYthOqvN+RattHr8iibNAiyhSSvtU4bntKK8xNC8RRg03h48RLIvPd zEh0U0Y3e3riyipFLF1XnHgdr4A3b2/hM4fFG1ds= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 21DBD8B807; Fri, 26 Apr 2019 07:59:47 +0200 (CEST) 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 relVsom-ikF0; Fri, 26 Apr 2019 07:59:47 +0200 (CEST) Received: from po16846vm.idsi0.si.c-s.fr (po15451.idsi0.si.c-s.fr [172.25.231.6]) by messagerie.si.c-s.fr (Postfix) with ESMTP id EE4C08B74C; Fri, 26 Apr 2019 07:59:46 +0200 (CEST) Received: by po16846vm.idsi0.si.c-s.fr (Postfix, from userid 0) id D351966276; Fri, 26 Apr 2019 05:59:46 +0000 (UTC) Message-Id: In-Reply-To: References: From: Christophe Leroy Subject: [PATCH v2 11/17] 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: Fri, 26 Apr 2019 05:59:46 +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 5537046b4c78..0756036e2b2d 100644 --- a/arch/powerpc/include/asm/book3s/64/hugetlb.h +++ b/arch/powerpc/include/asm/book3s/64/hugetlb.h @@ -107,4 +107,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 d9aa72fd76b3..baa386c51d87 100644 --- a/arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h +++ b/arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h @@ -36,4 +36,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 0322a0617371..828860a7492e 100644 --- a/arch/powerpc/mm/hugetlbpage.c +++ b/arch/powerpc/mm/hugetlbpage.c @@ -551,13 +551,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); @@ -565,37 +558,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 - VM_BUG_ON(mmu_psize_defs[mmu_psize].shift != shift); /* Return if huge page size has already been setup */ -- 2.13.3