Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1536270ybv; Thu, 6 Feb 2020 05:52:51 -0800 (PST) X-Google-Smtp-Source: APXvYqxZ5ZoC2eub55h8whRZ73Luc4i2zEqXKAmewE4YjC0mheERmKwj4msmD2p4ih6ScpeShw/B X-Received: by 2002:aca:3354:: with SMTP id z81mr7107508oiz.129.1580997170920; Thu, 06 Feb 2020 05:52:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580997170; cv=none; d=google.com; s=arc-20160816; b=C8ZyUQtTXX0PLx7Wa2PkrwobofVkYPS4V6tTj36Bsj7majMXEb9WYtliHpDx0jYv6J 7bC1/XvOvMo1L0hD92ypca3YPt4m7nAOSzU/t18/Y+wGRYBKZnI3azvayQnck2m3/DyR nJ956GmXMyqQDLL9frfTQGNrB+tEqBAY6TX5ObPMAZ/BV7qdCVvc1Or9+XKKdCNebGFY Rx/3D1t+3JFzhAydNf4S9GMcaZLx7m5kvss5QqASzLCppdk4qOuhX4fC7CcP7lR7fu+Y jQUym7B/MgGNUyYe4zjLKO7BYXpf+0ozBFOD8/sEkO2TyfLx5YOOHOgDEXCCeH/rtyOt Gqfg== 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:message-id :dkim-signature; bh=uc8VNbrzn2Tun7H3rxrb1NAqwgMomOLG/cwa2WL0XrI=; b=sysdqPHg/7hufuxjsDwJUTsta2sD3xkYyhy9PdDSRPDjj2UlXXoLcrBCzB1JW2Nakb GG0wESD0vJ+jcHPUoajk7OQX2162llB51dOtAQI3KMsmn+YUHtRR0oav3K+n/wWFEMyC OL1QE77xUtKtKRZ2MWXVdtpg7z92BKK3oCK+ObLuUD+b9TApBVSSMBHBcpiK3DiM9hiL FCMpnQcixQ0AMu9U0FtrerKi/tydoUzvkwj0wU2Qqgw+G6V+Nc2/9wwSb8IYFznsypvX QH+qPguSID5r+m+Lt+paobdnO6DfzcKF/+1nkxeQ24gEKCPrUdh7lSpq0I8jmBweCEc6 MAJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=tupqd5xr; 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 f17si2010228otq.96.2020.02.06.05.52.37; Thu, 06 Feb 2020 05:52:50 -0800 (PST) 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=tupqd5xr; 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 S1728146AbgBFNue (ORCPT + 99 others); Thu, 6 Feb 2020 08:50:34 -0500 Received: from pegase1.c-s.fr ([93.17.236.30]:17745 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728069AbgBFNud (ORCPT ); Thu, 6 Feb 2020 08:50:33 -0500 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 48D0F16K7Tz9v996; Thu, 6 Feb 2020 14:50:29 +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=tupqd5xr; 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 BLdc-dv9CEj2; Thu, 6 Feb 2020 14:50:29 +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 48D0F14F70z9v994; Thu, 6 Feb 2020 14:50:29 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1580997029; bh=uc8VNbrzn2Tun7H3rxrb1NAqwgMomOLG/cwa2WL0XrI=; h=From:Subject:To:Cc:Date:From; b=tupqd5xrNQLdgEsO2AcJVhmkNDxeVYcsAPNRMq2Uqh4Qkesm61e/a+YtblrJKKXp1 jO/JQsA4HtEiK3X3aAeqySyH+OBdckfevM+EOprgf5TW2qd6imBoeWl/kcZrofSIiq iGvJz6SCxIDeHpg/TOTvmADdmgZr2+YxOEoEV35U= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id D46EE8B889; Thu, 6 Feb 2020 14:50:30 +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 zqimB3y9gjxp; Thu, 6 Feb 2020 14:50:30 +0100 (CET) Received: from pc16570vm.idsi0.si.c-s.fr (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 425478B887; Thu, 6 Feb 2020 14:50:30 +0100 (CET) Received: by pc16570vm.idsi0.si.c-s.fr (Postfix, from userid 0) id E46DD652B7; Thu, 6 Feb 2020 13:50:29 +0000 (UTC) Message-Id: From: Christophe Leroy Subject: [PATCH] powerpc/hugetlb: Fix 8M hugepages on 8xx To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , aneesh.kumar@linux.ibm.com Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Date: Thu, 6 Feb 2020 13:50:29 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit 55c8fc3f4930 ("powerpc/8xx: reintroduce 16K pages with HW assistance") redefined pte_t as a struct of 4 pte_basic_t, because in 16K pages mode there are four identical entries in the page table. But hugepd entries for 8k pages require only one entrie of size pte_basic_t. So there is no point in creating a cache for 4 entries page tables. Also, with HW assistance the entries must be 4k aligned, the 8xx drops the last 12 bits. Redefine HUGEPD_SHIFT_MASK to mask them out. Calculate PTE_T_ORDER using the size of pte_basic_t instead of pte_t. In 16k mode, define a specific set_huge_pte_at() function which writes the pte in a single entry instead of using set_pte_at() which writes 4 identical entries. Define set_pte_filter() inline otherwise GCC doesn't inline it anymore because it is now used twice, and that gives a pretty suboptimal code because of pte_t being a struct of 4 entries. This function is also used for 512k pages which only require one entry as well allthough replicating it four times is harmless as 512k pages entries are spread every 128 bytes in the table. Fixes: 22569b881d37 ("powerpc/8xx: Enable 8M hugepage support with HW assistance") Cc: stable@vger.kernel.org Signed-off-by: Christophe Leroy --- arch/powerpc/include/asm/hugetlb.h | 5 +++++ arch/powerpc/include/asm/page.h | 5 +++++ arch/powerpc/mm/hugetlbpage.c | 3 ++- arch/powerpc/mm/pgtable.c | 19 ++++++++++++++++++- 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/include/asm/hugetlb.h b/arch/powerpc/include/asm/hugetlb.h index bd6504c28c2f..f43cfbcf014f 100644 --- a/arch/powerpc/include/asm/hugetlb.h +++ b/arch/powerpc/include/asm/hugetlb.h @@ -64,6 +64,11 @@ static inline void arch_clear_hugepage_flags(struct page *page) { } +#if defined(CONFIG_PPC_8xx) && defined(CONFIG_PPC_16K_PAGES) +#define __HAVE_ARCH_HUGE_SET_HUGE_PTE_AT +void set_huge_pte_at(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte); +#endif + #include #else /* ! CONFIG_HUGETLB_PAGE */ diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h index 86332080399a..080a0bf8e54b 100644 --- a/arch/powerpc/include/asm/page.h +++ b/arch/powerpc/include/asm/page.h @@ -295,8 +295,13 @@ static inline bool pfn_valid(unsigned long pfn) /* * Some number of bits at the level of the page table that points to * a hugepte are used to encode the size. This masks those bits. + * On 8xx, HW assistance requires 4k alignment for the hugepte. */ +#ifdef CONFIG_PPC_8xx +#define HUGEPD_SHIFT_MASK 0xfff +#else #define HUGEPD_SHIFT_MASK 0x3f +#endif #ifndef __ASSEMBLY__ diff --git a/arch/powerpc/mm/hugetlbpage.c b/arch/powerpc/mm/hugetlbpage.c index 73d4873fc7f8..c61032580185 100644 --- a/arch/powerpc/mm/hugetlbpage.c +++ b/arch/powerpc/mm/hugetlbpage.c @@ -30,7 +30,8 @@ bool hugetlb_disabled = false; #define hugepd_none(hpd) (hpd_val(hpd) == 0) -#define PTE_T_ORDER (__builtin_ffs(sizeof(pte_t)) - __builtin_ffs(sizeof(void *))) +#define PTE_T_ORDER (__builtin_ffs(sizeof(pte_basic_t)) - \ + __builtin_ffs(sizeof(void *))) pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long addr, unsigned long sz) { diff --git a/arch/powerpc/mm/pgtable.c b/arch/powerpc/mm/pgtable.c index e3759b69f81b..7a38eaa6ca72 100644 --- a/arch/powerpc/mm/pgtable.c +++ b/arch/powerpc/mm/pgtable.c @@ -100,7 +100,7 @@ static pte_t set_pte_filter_hash(pte_t pte) { return pte; } * as we don't have two bits to spare for _PAGE_EXEC and _PAGE_HWEXEC so * instead we "filter out" the exec permission for non clean pages. */ -static pte_t set_pte_filter(pte_t pte) +static inline pte_t set_pte_filter(pte_t pte) { struct page *pg; @@ -259,6 +259,23 @@ int huge_ptep_set_access_flags(struct vm_area_struct *vma, return changed; #endif } + +#if defined(CONFIG_PPC_8xx) && defined(CONFIG_PPC_16K_PAGES) +void set_huge_pte_at(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte) +{ + /* + * Make sure hardware valid bit is not set. We don't do + * tlb flush for this update. + */ + VM_WARN_ON(pte_hw_valid(*ptep) && !pte_protnone(*ptep)); + + pte = pte_mkpte(pte); + + pte = set_pte_filter(pte); + + ptep->pte = pte_val(pte); +} +#endif #endif /* CONFIG_HUGETLB_PAGE */ #ifdef CONFIG_DEBUG_VM -- 2.25.0