Skip to content

Commit 73636b1

Browse files
arch/tile: allow building Linux with transparent huge pages enabled
The change adds some infrastructure for managing tile pmd's more generally, using pte_pmd() and pmd_pte() methods to translate pmd values to and from ptes, since on TILEPro a pmd is really just a nested structure holding a pgd (aka pte). Several existing pmd methods are moved into this framework, and a whole raft of additional pmd accessors are defined that are used by the transparent hugepage framework. The tile PTE now has a "client2" bit. The bit is used to indicate a transparent huge page is in the process of being split into subpages. This change also fixes a generic bug where the return value of the generic pmdp_splitting_flush() was incorrect. Signed-off-by: Chris Metcalf <cmetcalf@tilera.com>
1 parent 5100700 commit 73636b1

File tree

6 files changed

+111
-53
lines changed

6 files changed

+111
-53
lines changed

arch/tile/include/asm/pgtable.h

+83-6
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ static inline void __pte_clear(pte_t *ptep)
187187
* Undefined behaviour if not..
188188
*/
189189
#define pte_present hv_pte_get_present
190+
#define pte_mknotpresent hv_pte_clear_present
190191
#define pte_user hv_pte_get_user
191192
#define pte_read hv_pte_get_readable
192193
#define pte_dirty hv_pte_get_dirty
@@ -312,7 +313,7 @@ extern void check_mm_caching(struct mm_struct *prev, struct mm_struct *next);
312313
*/
313314
static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
314315
{
315-
return pfn_pte(hv_pte_get_pfn(pte), newprot);
316+
return pfn_pte(pte_pfn(pte), newprot);
316317
}
317318

318319
/*
@@ -410,6 +411,46 @@ static inline unsigned long pmd_index(unsigned long address)
410411
return (address >> PMD_SHIFT) & (PTRS_PER_PMD - 1);
411412
}
412413

414+
#define __HAVE_ARCH_PMDP_TEST_AND_CLEAR_YOUNG
415+
static inline int pmdp_test_and_clear_young(struct vm_area_struct *vma,
416+
unsigned long address,
417+
pmd_t *pmdp)
418+
{
419+
return ptep_test_and_clear_young(vma, address, pmdp_ptep(pmdp));
420+
}
421+
422+
#define __HAVE_ARCH_PMDP_SET_WRPROTECT
423+
static inline void pmdp_set_wrprotect(struct mm_struct *mm,
424+
unsigned long address, pmd_t *pmdp)
425+
{
426+
ptep_set_wrprotect(mm, address, pmdp_ptep(pmdp));
427+
}
428+
429+
430+
#define __HAVE_ARCH_PMDP_GET_AND_CLEAR
431+
static inline pmd_t pmdp_get_and_clear(struct mm_struct *mm,
432+
unsigned long address,
433+
pmd_t *pmdp)
434+
{
435+
return pte_pmd(ptep_get_and_clear(mm, address, pmdp_ptep(pmdp)));
436+
}
437+
438+
static inline void __set_pmd(pmd_t *pmdp, pmd_t pmdval)
439+
{
440+
set_pte(pmdp_ptep(pmdp), pmd_pte(pmdval));
441+
}
442+
443+
#define set_pmd_at(mm, addr, pmdp, pmdval) __set_pmd(pmdp, pmdval)
444+
445+
/* Create a pmd from a PTFN. */
446+
static inline pmd_t ptfn_pmd(unsigned long ptfn, pgprot_t prot)
447+
{
448+
return pte_pmd(hv_pte_set_ptfn(prot, ptfn));
449+
}
450+
451+
/* Return the page-table frame number (ptfn) that a pmd_t points at. */
452+
#define pmd_ptfn(pmd) hv_pte_get_ptfn(pmd_pte(pmd))
453+
413454
/*
414455
* A given kernel pmd_t maps to a specific virtual address (either a
415456
* kernel huge page or a kernel pte_t table). Since kernel pte_t
@@ -432,6 +473,47 @@ static inline unsigned long pmd_page_vaddr(pmd_t pmd)
432473
*/
433474
#define pmd_page(pmd) pfn_to_page(HV_PTFN_TO_PFN(pmd_ptfn(pmd)))
434475

476+
static inline void pmd_clear(pmd_t *pmdp)
477+
{
478+
__pte_clear(pmdp_ptep(pmdp));
479+
}
480+
481+
#define pmd_mknotpresent(pmd) pte_pmd(pte_mknotpresent(pmd_pte(pmd)))
482+
#define pmd_young(pmd) pte_young(pmd_pte(pmd))
483+
#define pmd_mkyoung(pmd) pte_pmd(pte_mkyoung(pmd_pte(pmd)))
484+
#define pmd_mkold(pmd) pte_pmd(pte_mkold(pmd_pte(pmd)))
485+
#define pmd_mkwrite(pmd) pte_pmd(pte_mkwrite(pmd_pte(pmd)))
486+
#define pmd_write(pmd) pte_write(pmd_pte(pmd))
487+
#define pmd_wrprotect(pmd) pte_pmd(pte_wrprotect(pmd_pte(pmd)))
488+
#define pmd_mkdirty(pmd) pte_pmd(pte_mkdirty(pmd_pte(pmd)))
489+
#define pmd_huge_page(pmd) pte_huge(pmd_pte(pmd))
490+
#define pmd_mkhuge(pmd) pte_pmd(pte_mkhuge(pmd_pte(pmd)))
491+
#define __HAVE_ARCH_PMD_WRITE
492+
493+
#define pfn_pmd(pfn, pgprot) pte_pmd(pfn_pte((pfn), (pgprot)))
494+
#define pmd_pfn(pmd) pte_pfn(pmd_pte(pmd))
495+
#define mk_pmd(page, pgprot) pfn_pmd(page_to_pfn(page), (pgprot))
496+
497+
static inline pmd_t pmd_modify(pmd_t pmd, pgprot_t newprot)
498+
{
499+
return pfn_pmd(pmd_pfn(pmd), newprot);
500+
}
501+
502+
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
503+
#define has_transparent_hugepage() 1
504+
#define pmd_trans_huge pmd_huge_page
505+
506+
static inline pmd_t pmd_mksplitting(pmd_t pmd)
507+
{
508+
return pte_pmd(hv_pte_set_client2(pmd_pte(pmd)));
509+
}
510+
511+
static inline int pmd_trans_splitting(pmd_t pmd)
512+
{
513+
return hv_pte_get_client2(pmd_pte(pmd));
514+
}
515+
#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
516+
435517
/*
436518
* The pte page can be thought of an array like this: pte_t[PTRS_PER_PTE]
437519
*
@@ -448,11 +530,6 @@ static inline pte_t *pte_offset_kernel(pmd_t *pmd, unsigned long address)
448530
return (pte_t *)pmd_page_vaddr(*pmd) + pte_index(address);
449531
}
450532

451-
static inline int pmd_huge_page(pmd_t pmd)
452-
{
453-
return pmd_val(pmd) & _PAGE_HUGE_PAGE;
454-
}
455-
456533
#include <asm-generic/pgtable.h>
457534

458535
/* Support /proc/NN/pgtable API. */

arch/tile/include/asm/pgtable_32.h

+8-18
Original file line numberDiff line numberDiff line change
@@ -111,24 +111,14 @@ static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
111111
return pte;
112112
}
113113

114-
static inline void __set_pmd(pmd_t *pmdp, pmd_t pmdval)
115-
{
116-
set_pte(&pmdp->pud.pgd, pmdval.pud.pgd);
117-
}
118-
119-
/* Create a pmd from a PTFN. */
120-
static inline pmd_t ptfn_pmd(unsigned long ptfn, pgprot_t prot)
121-
{
122-
return (pmd_t){ { hv_pte_set_ptfn(prot, ptfn) } };
123-
}
124-
125-
/* Return the page-table frame number (ptfn) that a pmd_t points at. */
126-
#define pmd_ptfn(pmd) hv_pte_get_ptfn((pmd).pud.pgd)
127-
128-
static inline void pmd_clear(pmd_t *pmdp)
129-
{
130-
__pte_clear(&pmdp->pud.pgd);
131-
}
114+
/*
115+
* pmds are wrappers around pgds, which are the same as ptes.
116+
* It's often convenient to "cast" back and forth and use the pte methods,
117+
* which are the methods supplied by the hypervisor.
118+
*/
119+
#define pmd_pte(pmd) ((pmd).pud.pgd)
120+
#define pmdp_ptep(pmdp) (&(pmdp)->pud.pgd)
121+
#define pte_pmd(pte) ((pmd_t){ { (pte) } })
132122

133123
#endif /* __ASSEMBLY__ */
134124

arch/tile/include/asm/pgtable_64.h

+7-22
Original file line numberDiff line numberDiff line change
@@ -108,28 +108,6 @@ static inline unsigned long pud_index(unsigned long address)
108108
#define pmd_offset(pud, address) \
109109
((pmd_t *)pud_page_vaddr(*(pud)) + pmd_index(address))
110110

111-
static inline void __set_pmd(pmd_t *pmdp, pmd_t pmdval)
112-
{
113-
set_pte(pmdp, pmdval);
114-
}
115-
116-
/* Create a pmd from a PTFN and pgprot. */
117-
static inline pmd_t ptfn_pmd(unsigned long ptfn, pgprot_t prot)
118-
{
119-
return hv_pte_set_ptfn(prot, ptfn);
120-
}
121-
122-
/* Return the page-table frame number (ptfn) that a pmd_t points at. */
123-
static inline unsigned long pmd_ptfn(pmd_t pmd)
124-
{
125-
return hv_pte_get_ptfn(pmd);
126-
}
127-
128-
static inline void pmd_clear(pmd_t *pmdp)
129-
{
130-
__pte_clear(pmdp);
131-
}
132-
133111
/* Normalize an address to having the correct high bits set. */
134112
#define pgd_addr_normalize pgd_addr_normalize
135113
static inline unsigned long pgd_addr_normalize(unsigned long addr)
@@ -170,6 +148,13 @@ static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
170148
return hv_pte(__insn_exch(&ptep->val, 0UL));
171149
}
172150

151+
/*
152+
* pmds are the same as pgds and ptes, so converting is a no-op.
153+
*/
154+
#define pmd_pte(pmd) (pmd)
155+
#define pmdp_ptep(pmdp) (pmdp)
156+
#define pte_pmd(pte) (pte)
157+
173158
#endif /* __ASSEMBLY__ */
174159

175160
#endif /* _ASM_TILE_PGTABLE_64_H */

arch/tile/include/hv/hypervisor.h

+9-2
Original file line numberDiff line numberDiff line change
@@ -1855,8 +1855,7 @@ int hv_flush_remote(HV_PhysAddr cache_pa, unsigned long cache_control,
18551855
future use. */
18561856
#define HV_PTE_INDEX_MODE 16 /**< Page mode; see HV_PTE_MODE_xxx */
18571857
#define HV_PTE_MODE_BITS 3 /**< Number of bits in mode */
1858-
/* Bit 19 is reserved for
1859-
future use. */
1858+
#define HV_PTE_INDEX_CLIENT2 19 /**< Page client state 2 */
18601859
#define HV_PTE_INDEX_LOTAR 20 /**< Page's LOTAR; must be high bits
18611860
of word */
18621861
#define HV_PTE_LOTAR_BITS 12 /**< Number of bits in a LOTAR */
@@ -2046,6 +2045,13 @@ int hv_flush_remote(HV_PhysAddr cache_pa, unsigned long cache_control,
20462045
*/
20472046
#define HV_PTE_CLIENT1 (__HV_PTE_ONE << HV_PTE_INDEX_CLIENT1)
20482047

2048+
/** Client-private bit in PTE.
2049+
*
2050+
* This bit is guaranteed not to be inspected or modified by the
2051+
* hypervisor.
2052+
*/
2053+
#define HV_PTE_CLIENT2 (__HV_PTE_ONE << HV_PTE_INDEX_CLIENT2)
2054+
20492055
/** Non-coherent (NC) bit in PTE.
20502056
*
20512057
* If this bit is set, the mapping that is set up will be non-coherent
@@ -2180,6 +2186,7 @@ _HV_BIT(present, PRESENT)
21802186
_HV_BIT(page, PAGE)
21812187
_HV_BIT(client0, CLIENT0)
21822188
_HV_BIT(client1, CLIENT1)
2189+
_HV_BIT(client2, CLIENT2)
21832190
_HV_BIT(migrating, MIGRATING)
21842191
_HV_BIT(nc, NC)
21852192
_HV_BIT(readable, READABLE)

include/asm-generic/pgtable.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,8 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
158158
#endif
159159

160160
#ifndef __HAVE_ARCH_PMDP_SPLITTING_FLUSH
161-
extern pmd_t pmdp_splitting_flush(struct vm_area_struct *vma,
162-
unsigned long address,
163-
pmd_t *pmdp);
161+
extern void pmdp_splitting_flush(struct vm_area_struct *vma,
162+
unsigned long address, pmd_t *pmdp);
164163
#endif
165164

166165
#ifndef __HAVE_ARCH_PTE_SAME

mm/pgtable-generic.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ pmd_t pmdp_clear_flush(struct vm_area_struct *vma, unsigned long address,
109109

110110
#ifndef __HAVE_ARCH_PMDP_SPLITTING_FLUSH
111111
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
112-
pmd_t pmdp_splitting_flush(struct vm_area_struct *vma, unsigned long address,
113-
pmd_t *pmdp)
112+
void pmdp_splitting_flush(struct vm_area_struct *vma, unsigned long address,
113+
pmd_t *pmdp)
114114
{
115115
pmd_t pmd = pmd_mksplitting(*pmdp);
116116
VM_BUG_ON(address & ~HPAGE_PMD_MASK);

0 commit comments

Comments
 (0)