Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e5098611 authored by Martin Schwidefsky's avatar Martin Schwidefsky
Browse files

s390/mm: cleanup page table definitions



Improve the encoding of the different pte types and the naming of the
page, segment table and region table bits. Due to the different pte
encoding the hugetlbfs primitives need to be adapted as well. To improve
compatability with common code make the huge ptes use the encoding of
normal ptes. The conversion between the pte and pmd encoding for a huge
pte is done with set_huge_pte_at and huge_ptep_get.
Overall the code is now easier to understand.

Reviewed-by: default avatarGerald Schaefer <gerald.schaefer@de.ibm.com>
Signed-off-by: default avatarMartin Schwidefsky <schwidefsky@de.ibm.com>
parent 416fd0ff
Loading
Loading
Loading
Loading
+33 −102
Original line number Diff line number Diff line
@@ -17,6 +17,9 @@

void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
		     pte_t *ptep, pte_t pte);
pte_t huge_ptep_get(pte_t *ptep);
pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
			      unsigned long addr, pte_t *ptep);

/*
 * If the arch doesn't supply something else, assume that hugepage
@@ -38,147 +41,75 @@ static inline int prepare_hugepage_range(struct file *file,
int arch_prepare_hugepage(struct page *page);
void arch_release_hugepage(struct page *page);

static inline pte_t huge_pte_wrprotect(pte_t pte)
{
	pte_val(pte) |= _PAGE_RO;
	return pte;
}

static inline int huge_pte_none(pte_t pte)
static inline void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
				  pte_t *ptep)
{
	return (pte_val(pte) & _SEGMENT_ENTRY_INV) &&
		!(pte_val(pte) & _SEGMENT_ENTRY_RO);
	pte_val(*ptep) = _SEGMENT_ENTRY_EMPTY;
}

static inline pte_t huge_ptep_get(pte_t *ptep)
static inline void huge_ptep_clear_flush(struct vm_area_struct *vma,
					 unsigned long address, pte_t *ptep)
{
	pte_t pte = *ptep;
	unsigned long mask;

	if (!MACHINE_HAS_HPAGE) {
		ptep = (pte_t *) (pte_val(pte) & _SEGMENT_ENTRY_ORIGIN);
		if (ptep) {
			mask = pte_val(pte) &
				(_SEGMENT_ENTRY_INV | _SEGMENT_ENTRY_RO);
			pte = pte_mkhuge(*ptep);
			pte_val(pte) |= mask;
		}
	}
	return pte;
	huge_ptep_get_and_clear(vma->vm_mm, address, ptep);
}

static inline void __pmd_csp(pmd_t *pmdp)
static inline int huge_ptep_set_access_flags(struct vm_area_struct *vma,
					     unsigned long addr, pte_t *ptep,
					     pte_t pte, int dirty)
{
	register unsigned long reg2 asm("2") = pmd_val(*pmdp);
	register unsigned long reg3 asm("3") = pmd_val(*pmdp) |
					       _SEGMENT_ENTRY_INV;
	register unsigned long reg4 asm("4") = ((unsigned long) pmdp) + 5;

	asm volatile(
		"	csp %1,%3"
		: "=m" (*pmdp)
		: "d" (reg2), "d" (reg3), "d" (reg4), "m" (*pmdp) : "cc");
	int changed = !pte_same(huge_ptep_get(ptep), pte);
	if (changed) {
		huge_ptep_get_and_clear(vma->vm_mm, addr, ptep);
		set_huge_pte_at(vma->vm_mm, addr, ptep, pte);
	}

static inline void huge_ptep_invalidate(struct mm_struct *mm,
					unsigned long address, pte_t *ptep)
{
	pmd_t *pmdp = (pmd_t *) ptep;

	if (MACHINE_HAS_IDTE)
		__pmd_idte(address, pmdp);
	else
		__pmd_csp(pmdp);
	pmd_val(*pmdp) = _SEGMENT_ENTRY_INV | _SEGMENT_ENTRY;
	return changed;
}

static inline pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
static inline void huge_ptep_set_wrprotect(struct mm_struct *mm,
					   unsigned long addr, pte_t *ptep)
{
	pte_t pte = huge_ptep_get(ptep);

	huge_ptep_invalidate(mm, addr, ptep);
	return pte;
	pte_t pte = huge_ptep_get_and_clear(mm, addr, ptep);
	set_huge_pte_at(mm, addr, ptep, pte_wrprotect(pte));
}

#define huge_ptep_set_access_flags(__vma, __addr, __ptep, __entry, __dirty) \
({									    \
	int __changed = !pte_same(huge_ptep_get(__ptep), __entry);	    \
	if (__changed) {						    \
		huge_ptep_invalidate((__vma)->vm_mm, __addr, __ptep);	    \
		set_huge_pte_at((__vma)->vm_mm, __addr, __ptep, __entry);   \
	}								    \
	__changed;							    \
})

#define huge_ptep_set_wrprotect(__mm, __addr, __ptep)			\
({									\
	pte_t __pte = huge_ptep_get(__ptep);				\
	if (huge_pte_write(__pte)) {					\
		huge_ptep_invalidate(__mm, __addr, __ptep);		\
		set_huge_pte_at(__mm, __addr, __ptep,			\
				huge_pte_wrprotect(__pte));		\
	}								\
})

static inline void huge_ptep_clear_flush(struct vm_area_struct *vma,
					 unsigned long address, pte_t *ptep)
static inline pte_t mk_huge_pte(struct page *page, pgprot_t pgprot)
{
	huge_ptep_invalidate(vma->vm_mm, address, ptep);
	return mk_pte(page, pgprot);
}

static inline pte_t mk_huge_pte(struct page *page, pgprot_t pgprot)
static inline int huge_pte_none(pte_t pte)
{
	pte_t pte;
	pmd_t pmd;

	pmd = mk_pmd_phys(page_to_phys(page), pgprot);
	pte_val(pte) = pmd_val(pmd);
	return pte;
	return pte_none(pte);
}

static inline int huge_pte_write(pte_t pte)
{
	pmd_t pmd;

	pmd_val(pmd) = pte_val(pte);
	return pmd_write(pmd);
	return pte_write(pte);
}

static inline int huge_pte_dirty(pte_t pte)
{
	/* No dirty bit in the segment table entry. */
	return 0;
	return pte_dirty(pte);
}

static inline pte_t huge_pte_mkwrite(pte_t pte)
{
	pmd_t pmd;

	pmd_val(pmd) = pte_val(pte);
	pte_val(pte) = pmd_val(pmd_mkwrite(pmd));
	return pte;
	return pte_mkwrite(pte);
}

static inline pte_t huge_pte_mkdirty(pte_t pte)
{
	/* No dirty bit in the segment table entry. */
	return pte;
	return pte_mkdirty(pte);
}

static inline pte_t huge_pte_modify(pte_t pte, pgprot_t newprot)
static inline pte_t huge_pte_wrprotect(pte_t pte)
{
	pmd_t pmd;

	pmd_val(pmd) = pte_val(pte);
	pte_val(pte) = pmd_val(pmd_modify(pmd, newprot));
	return pte;
	return pte_wrprotect(pte);
}

static inline void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
				  pte_t *ptep)
static inline pte_t huge_pte_modify(pte_t pte, pgprot_t newprot)
{
	pmd_clear((pmd_t *) ptep);
	return pte_modify(pte, newprot);
}

#endif /* _ASM_S390_HUGETLB_H */
+144 −156

File changed.

Preview size limit exceeded, changes collapsed.

+2 −2
Original line number Diff line number Diff line
@@ -113,11 +113,11 @@ int vdso_alloc_per_cpu(struct _lowcore *lowcore)

	clear_table((unsigned long *) segment_table, _SEGMENT_ENTRY_EMPTY,
		    PAGE_SIZE << SEGMENT_ORDER);
	clear_table((unsigned long *) page_table, _PAGE_TYPE_EMPTY,
	clear_table((unsigned long *) page_table, _PAGE_INVALID,
		    256*sizeof(unsigned long));

	*(unsigned long *) segment_table = _SEGMENT_ENTRY + page_table;
	*(unsigned long *) page_table = _PAGE_RO + page_frame;
	*(unsigned long *) page_table = _PAGE_PROTECT + page_frame;

	psal = (u32 *) (page_table + 256*sizeof(unsigned long));
	aste = psal + 32;
+8 −8
Original line number Diff line number Diff line
@@ -86,28 +86,28 @@ static unsigned long follow_table(struct mm_struct *mm,
	switch (mm->context.asce_bits & _ASCE_TYPE_MASK) {
	case _ASCE_TYPE_REGION1:
		table = table + ((address >> 53) & 0x7ff);
		if (unlikely(*table & _REGION_ENTRY_INV))
		if (unlikely(*table & _REGION_ENTRY_INVALID))
			return -0x39UL;
		table = (unsigned long *)(*table & _REGION_ENTRY_ORIGIN);
		/* fallthrough */
	case _ASCE_TYPE_REGION2:
		table = table + ((address >> 42) & 0x7ff);
		if (unlikely(*table & _REGION_ENTRY_INV))
		if (unlikely(*table & _REGION_ENTRY_INVALID))
			return -0x3aUL;
		table = (unsigned long *)(*table & _REGION_ENTRY_ORIGIN);
		/* fallthrough */
	case _ASCE_TYPE_REGION3:
		table = table + ((address >> 31) & 0x7ff);
		if (unlikely(*table & _REGION_ENTRY_INV))
		if (unlikely(*table & _REGION_ENTRY_INVALID))
			return -0x3bUL;
		table = (unsigned long *)(*table & _REGION_ENTRY_ORIGIN);
		/* fallthrough */
	case _ASCE_TYPE_SEGMENT:
		table = table + ((address >> 20) & 0x7ff);
		if (unlikely(*table & _SEGMENT_ENTRY_INV))
		if (unlikely(*table & _SEGMENT_ENTRY_INVALID))
			return -0x10UL;
		if (unlikely(*table & _SEGMENT_ENTRY_LARGE)) {
			if (write && (*table & _SEGMENT_ENTRY_RO))
			if (write && (*table & _SEGMENT_ENTRY_PROTECT))
				return -0x04UL;
			return (*table & _SEGMENT_ENTRY_ORIGIN_LARGE) +
				(address & ~_SEGMENT_ENTRY_ORIGIN_LARGE);
@@ -117,7 +117,7 @@ static unsigned long follow_table(struct mm_struct *mm,
	table = table + ((address >> 12) & 0xff);
	if (unlikely(*table & _PAGE_INVALID))
		return -0x11UL;
	if (write && (*table & _PAGE_RO))
	if (write && (*table & _PAGE_PROTECT))
		return -0x04UL;
	return (*table & PAGE_MASK) + (address & ~PAGE_MASK);
}
@@ -130,13 +130,13 @@ static unsigned long follow_table(struct mm_struct *mm,
	unsigned long *table = (unsigned long *)__pa(mm->pgd);

	table = table + ((address >> 20) & 0x7ff);
	if (unlikely(*table & _SEGMENT_ENTRY_INV))
	if (unlikely(*table & _SEGMENT_ENTRY_INVALID))
		return -0x10UL;
	table = (unsigned long *)(*table & _SEGMENT_ENTRY_ORIGIN);
	table = table + ((address >> 12) & 0xff);
	if (unlikely(*table & _PAGE_INVALID))
		return -0x11UL;
	if (write && (*table & _PAGE_RO))
	if (write && (*table & _PAGE_PROTECT))
		return -0x04UL;
	return (*table & PAGE_MASK) + (address & ~PAGE_MASK);
}
+9 −9
Original line number Diff line number Diff line
@@ -53,7 +53,7 @@ static void print_prot(struct seq_file *m, unsigned int pr, int level)
		seq_printf(m, "I\n");
		return;
	}
	seq_printf(m, "%s", pr & _PAGE_RO ? "RO " : "RW ");
	seq_printf(m, "%s", pr & _PAGE_PROTECT ? "RO " : "RW ");
	seq_printf(m, "%s", pr & _PAGE_CO ? "CO " : "   ");
	seq_putc(m, '\n');
}
@@ -105,12 +105,12 @@ static void note_page(struct seq_file *m, struct pg_state *st,
}

/*
 * The actual page table walker functions. In order to keep the implementation
 * of print_prot() short, we only check and pass _PAGE_INVALID and _PAGE_RO
 * flags to note_page() if a region, segment or page table entry is invalid or
 * read-only.
 * After all it's just a hint that the current level being walked contains an
 * invalid or read-only entry.
 * The actual page table walker functions. In order to keep the
 * implementation of print_prot() short, we only check and pass
 * _PAGE_INVALID and _PAGE_PROTECT flags to note_page() if a region,
 * segment or page table entry is invalid or read-only.
 * After all it's just a hint that the current level being walked
 * contains an invalid or read-only entry.
 */
static void walk_pte_level(struct seq_file *m, struct pg_state *st,
			   pmd_t *pmd, unsigned long addr)
@@ -122,14 +122,14 @@ static void walk_pte_level(struct seq_file *m, struct pg_state *st,
	for (i = 0; i < PTRS_PER_PTE && addr < max_addr; i++) {
		st->current_address = addr;
		pte = pte_offset_kernel(pmd, addr);
		prot = pte_val(*pte) & (_PAGE_RO | _PAGE_INVALID);
		prot = pte_val(*pte) & (_PAGE_PROTECT | _PAGE_INVALID);
		note_page(m, st, prot, 4);
		addr += PAGE_SIZE;
	}
}

#ifdef CONFIG_64BIT
#define _PMD_PROT_MASK (_SEGMENT_ENTRY_RO | _SEGMENT_ENTRY_CO)
#define _PMD_PROT_MASK (_SEGMENT_ENTRY_PROTECT | _SEGMENT_ENTRY_CO)
#else
#define _PMD_PROT_MASK 0
#endif
Loading