Skip to content

Commit b0e98aa

Browse files
gerald-schaeferhcahca
authored andcommitted
s390/mm: make pmd/pud_deref() large page aware
pmd/pud_deref() assume that they will never operate on large pmd/pud entries, and therefore only use the non-large _xxx_ENTRY_ORIGIN mask. With commit 9ec8fa8 ("s390/vmemmap: extend modify_pagetable() to handle vmemmap"), that assumption is no longer true, at least for pmd_deref(). In theory, we could end up with wrong addresses because some of the non-address bits of a large entry would not be masked out. In practice, this does not (yet) show any impact, because vmemmap_free() is currently never used for s390. Fix pmd/pud_deref() to check for the entry type and use the _xxx_ENTRY_ORIGIN_LARGE mask for large entries. While at it, also move pmd/pud_pfn() around, in order to avoid code duplication, because they do the same thing. Fixes: 9ec8fa8 ("s390/vmemmap: extend modify_pagetable() to handle vmemmap") Cc: <stable@vger.kernel.org> # 5.9 Signed-off-by: Gerald Schaefer <gerald.schaefer@linux.ibm.com> Reviewed-by: Alexander Gordeev <agordeev@linux.ibm.com> Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
1 parent 29c2680 commit b0e98aa

1 file changed

Lines changed: 30 additions & 22 deletions

File tree

‎arch/s390/include/asm/pgtable.h‎

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -692,16 +692,6 @@ static inline int pud_large(pud_t pud)
692692
return !!(pud_val(pud) & _REGION3_ENTRY_LARGE);
693693
}
694694

695-
static inline unsigned long pud_pfn(pud_t pud)
696-
{
697-
unsigned long origin_mask;
698-
699-
origin_mask = _REGION_ENTRY_ORIGIN;
700-
if (pud_large(pud))
701-
origin_mask = _REGION3_ENTRY_ORIGIN_LARGE;
702-
return (pud_val(pud) & origin_mask) >> PAGE_SHIFT;
703-
}
704-
705695
#define pmd_leaf pmd_large
706696
static inline int pmd_large(pmd_t pmd)
707697
{
@@ -747,16 +737,6 @@ static inline int pmd_none(pmd_t pmd)
747737
return pmd_val(pmd) == _SEGMENT_ENTRY_EMPTY;
748738
}
749739

750-
static inline unsigned long pmd_pfn(pmd_t pmd)
751-
{
752-
unsigned long origin_mask;
753-
754-
origin_mask = _SEGMENT_ENTRY_ORIGIN;
755-
if (pmd_large(pmd))
756-
origin_mask = _SEGMENT_ENTRY_ORIGIN_LARGE;
757-
return (pmd_val(pmd) & origin_mask) >> PAGE_SHIFT;
758-
}
759-
760740
#define pmd_write pmd_write
761741
static inline int pmd_write(pmd_t pmd)
762742
{
@@ -1238,11 +1218,39 @@ static inline pte_t mk_pte(struct page *page, pgprot_t pgprot)
12381218
#define pud_index(address) (((address) >> PUD_SHIFT) & (PTRS_PER_PUD-1))
12391219
#define pmd_index(address) (((address) >> PMD_SHIFT) & (PTRS_PER_PMD-1))
12401220

1241-
#define pmd_deref(pmd) (pmd_val(pmd) & _SEGMENT_ENTRY_ORIGIN)
1242-
#define pud_deref(pud) (pud_val(pud) & _REGION_ENTRY_ORIGIN)
12431221
#define p4d_deref(pud) (p4d_val(pud) & _REGION_ENTRY_ORIGIN)
12441222
#define pgd_deref(pgd) (pgd_val(pgd) & _REGION_ENTRY_ORIGIN)
12451223

1224+
static inline unsigned long pmd_deref(pmd_t pmd)
1225+
{
1226+
unsigned long origin_mask;
1227+
1228+
origin_mask = _SEGMENT_ENTRY_ORIGIN;
1229+
if (pmd_large(pmd))
1230+
origin_mask = _SEGMENT_ENTRY_ORIGIN_LARGE;
1231+
return pmd_val(pmd) & origin_mask;
1232+
}
1233+
1234+
static inline unsigned long pmd_pfn(pmd_t pmd)
1235+
{
1236+
return pmd_deref(pmd) >> PAGE_SHIFT;
1237+
}
1238+
1239+
static inline unsigned long pud_deref(pud_t pud)
1240+
{
1241+
unsigned long origin_mask;
1242+
1243+
origin_mask = _REGION_ENTRY_ORIGIN;
1244+
if (pud_large(pud))
1245+
origin_mask = _REGION3_ENTRY_ORIGIN_LARGE;
1246+
return pud_val(pud) & origin_mask;
1247+
}
1248+
1249+
static inline unsigned long pud_pfn(pud_t pud)
1250+
{
1251+
return pud_deref(pud) >> PAGE_SHIFT;
1252+
}
1253+
12461254
/*
12471255
* The pgd_offset function *always* adds the index for the top-level
12481256
* region/segment table. This is done to get a sequence like the

0 commit comments

Comments
 (0)