Skip to content

Commit 84b7387

Browse files
author
Claudio Imbrenda
committed
KVM: s390: remove the last user of page->index
Shadow page tables use page->index to keep the g2 address of the guest page table being shadowed. Instead of keeping the information in page->index, split the address and smear it over the 16-bit softbits areas of 4 PGSTEs. This removes the last s390 user of page->index. Reviewed-by: Steffen Eiden <seiden@linux.ibm.com> Reviewed-by: Christoph Schlameuss <schlameuss@linux.ibm.com> Link: https://lore.kernel.org/r/20250123144627.312456-16-imbrenda@linux.ibm.com Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com> Message-ID: <20250123144627.312456-16-imbrenda@linux.ibm.com>
1 parent 1f43899 commit 84b7387

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

arch/s390/include/asm/pgtable.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ void setup_protection_map(void);
420420
#define PGSTE_HC_BIT 0x0020000000000000UL
421421
#define PGSTE_GR_BIT 0x0004000000000000UL
422422
#define PGSTE_GC_BIT 0x0002000000000000UL
423+
#define PGSTE_ST2_MASK 0x0000ffff00000000UL
423424
#define PGSTE_UC_BIT 0x0000000000008000UL /* user dirty (migration) */
424425
#define PGSTE_IN_BIT 0x0000000000004000UL /* IPTE notify bit */
425426
#define PGSTE_VSIE_BIT 0x0000000000002000UL /* ref'd in a shadow table */
@@ -2007,4 +2008,18 @@ extern void s390_reset_cmma(struct mm_struct *mm);
20072008
#define pmd_pgtable(pmd) \
20082009
((pgtable_t)__va(pmd_val(pmd) & -sizeof(pte_t)*PTRS_PER_PTE))
20092010

2011+
static inline unsigned long gmap_pgste_get_pgt_addr(unsigned long *pgt)
2012+
{
2013+
unsigned long *pgstes, res;
2014+
2015+
pgstes = pgt + _PAGE_ENTRIES;
2016+
2017+
res = (pgstes[0] & PGSTE_ST2_MASK) << 16;
2018+
res |= pgstes[1] & PGSTE_ST2_MASK;
2019+
res |= (pgstes[2] & PGSTE_ST2_MASK) >> 16;
2020+
res |= (pgstes[3] & PGSTE_ST2_MASK) >> 32;
2021+
2022+
return res;
2023+
}
2024+
20102025
#endif /* _S390_PAGE_H */

arch/s390/kvm/gaccess.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,6 +1409,7 @@ static int kvm_s390_shadow_tables(struct gmap *sg, unsigned long saddr,
14091409
static int shadow_pgt_lookup(struct gmap *sg, unsigned long saddr, unsigned long *pgt,
14101410
int *dat_protection, int *fake)
14111411
{
1412+
unsigned long pt_index;
14121413
unsigned long *table;
14131414
struct page *page;
14141415
int rc;
@@ -1418,9 +1419,10 @@ static int shadow_pgt_lookup(struct gmap *sg, unsigned long saddr, unsigned long
14181419
if (table && !(*table & _SEGMENT_ENTRY_INVALID)) {
14191420
/* Shadow page tables are full pages (pte+pgste) */
14201421
page = pfn_to_page(*table >> PAGE_SHIFT);
1421-
*pgt = page->index & ~GMAP_SHADOW_FAKE_TABLE;
1422+
pt_index = gmap_pgste_get_pgt_addr(page_to_virt(page));
1423+
*pgt = pt_index & ~GMAP_SHADOW_FAKE_TABLE;
14221424
*dat_protection = !!(*table & _SEGMENT_ENTRY_PROTECT);
1423-
*fake = !!(page->index & GMAP_SHADOW_FAKE_TABLE);
1425+
*fake = !!(pt_index & GMAP_SHADOW_FAKE_TABLE);
14241426
rc = 0;
14251427
} else {
14261428
rc = -EAGAIN;

arch/s390/mm/gmap.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1733,6 +1733,23 @@ int gmap_shadow_sgt(struct gmap *sg, unsigned long saddr, unsigned long sgt,
17331733
}
17341734
EXPORT_SYMBOL_GPL(gmap_shadow_sgt);
17351735

1736+
static void gmap_pgste_set_pgt_addr(struct ptdesc *ptdesc, unsigned long pgt_addr)
1737+
{
1738+
unsigned long *pgstes = page_to_virt(ptdesc_page(ptdesc));
1739+
1740+
pgstes += _PAGE_ENTRIES;
1741+
1742+
pgstes[0] &= ~PGSTE_ST2_MASK;
1743+
pgstes[1] &= ~PGSTE_ST2_MASK;
1744+
pgstes[2] &= ~PGSTE_ST2_MASK;
1745+
pgstes[3] &= ~PGSTE_ST2_MASK;
1746+
1747+
pgstes[0] |= (pgt_addr >> 16) & PGSTE_ST2_MASK;
1748+
pgstes[1] |= pgt_addr & PGSTE_ST2_MASK;
1749+
pgstes[2] |= (pgt_addr << 16) & PGSTE_ST2_MASK;
1750+
pgstes[3] |= (pgt_addr << 32) & PGSTE_ST2_MASK;
1751+
}
1752+
17361753
/**
17371754
* gmap_shadow_pgt - instantiate a shadow page table
17381755
* @sg: pointer to the shadow guest address space structure
@@ -1760,9 +1777,10 @@ int gmap_shadow_pgt(struct gmap *sg, unsigned long saddr, unsigned long pgt,
17601777
ptdesc = page_table_alloc_pgste(sg->mm);
17611778
if (!ptdesc)
17621779
return -ENOMEM;
1763-
ptdesc->pt_index = pgt & _SEGMENT_ENTRY_ORIGIN;
1780+
origin = pgt & _SEGMENT_ENTRY_ORIGIN;
17641781
if (fake)
1765-
ptdesc->pt_index |= GMAP_SHADOW_FAKE_TABLE;
1782+
origin |= GMAP_SHADOW_FAKE_TABLE;
1783+
gmap_pgste_set_pgt_addr(ptdesc, origin);
17661784
s_pgt = page_to_phys(ptdesc_page(ptdesc));
17671785
/* Install shadow page table */
17681786
spin_lock(&sg->guest_table_lock);

0 commit comments

Comments
 (0)