s390/mm: split huge pages in GMAP when protecting
RFC 4/14 s390/mm: split huge pages in GMAP when protecting
Dirty tracking, vsie protection and lowcore invalidation notification are best done on the smallest page size available to avoid unnecessary flushing and table management operations.
Hence we now split huge pages and introduce a page table if a notification bit is set or memory is protected via gmap_protect_range or gmap_protect_rmap.
Signed-off-by Janosch Frank <[email protected]>
--- arch/s390/include/asm/gmap.h | 18 +++ arch/s390/include/asm/pgtable.h | 3 + arch/s390/mm/gmap.c | 243 +++++++++++++++++++++++++++++++--------- arch/s390/mm/pgtable.c | 33 ++++++ 4 files changed, 247 insertions(+), 50 deletions(-)
arch/s390/include/asm/gmap.h +18 -0
@@ -16,6 +16,11 @@/* Status bits only for huge segment entries */ #define _SEGMENT_ENTRY_GMAP_IN 0x8000/* invalidation notify bit */ #define _SEGMENT_ENTRY_GMAP_UC 0x4000/* dirty (migration) */ +/* Status bits in the gmap segment entry. */ +#define _SEGMENT_ENTRY_GMAP_SPLIT 0x0001/* split huge pmd */ + +#define GMAP_SEGMENT_STATUS_BITS (_SEGMENT_ENTRY_GMAP_UC | _SEGMENT_ENTRY_GMAP_SPLIT) +#define GMAP_SEGMENT_NOTIFY_BITS _SEGMENT_ENTRY_GMAP_IN/** * struct gmap_struct - guest address space
@@ -56,6 +61,8 @@ struct gmap {struct radix_tree_root host_to_rmap;struct list_head children;struct list_head pt_list; +struct list_head split_list; +spinlock_t split_list_lock;spinlock_t shadow_lock;struct gmap *parent;unsigned long orig_asce;
@@ -96,6 +103,17 @@ static inline int gmap_is_shadow(struct gmap *gmap)return !!gmap->parent; } +/** +* gmap_pmd_is_split - Returns if a huge gmap pmd has been split. +* @pmdp: pointer to the pmd +* +* Returns true if the passed huge gmap pmd has been split. +*/ +static inline bool gmap_pmd_is_split (pmd_t *pmdp) +{ +return !!(pmd_val (*pmdp) & _SEGMENT_ENTRY_GMAP_SPLIT); +} +struct gmap *gmap_create (struct mm_struct *mm,unsigned long limit);void gmap_remove (struct gmap *gmap);struct gmap *gmap_get (struct gmap *gmap);
arch/s390/include/asm/pgtable.h +3 -0
@@ -1103,6 +1103,9 @@ int ptep_shadow_pte(struct mm_struct *mm, unsigned long saddr, pte_t *sptep, pte_t *tptep, pte_t pte);void ptep_unshadow_pte (struct mm_struct *mm,unsigned long saddr,pte_t *ptep); +unsigned long ptep_get_and_clear_notification_bits (pte_t *ptep); +void ptep_remove_protection_split (struct mm_struct *mm,pte_t *ptep, +unsigned long gaddr);bool ptep_test_and_clear_uc (struct mm_struct *mm,unsigned long address,pte_t *ptep); int set_guest_storage_key(struct mm_struct *mm, unsigned long addr,
arch/s390/mm/gmap.c +193 -50
435 lines not on this page · raw message
arch/s390/mm/pgtable.c +33 -0
@@ -719,6 +719,39 @@ void ptep_zap_key(struct mm_struct *mm, unsigned long addr, pte_t *ptep)preempt_enable (); } +unsigned long ptep_get_and_clear_notification_bits (pte_t *ptep) +{ +pgste_t pgste; +unsigned long bits; + + pgste =pgste_get_lock (ptep); + bits =pgste_val (pgste) & (PGSTE_IN_BIT |PGSTE_VSIE_BIT ); +pgste_val (pgste) ^= bits; +pgste_set_unlock (ptep, pgste); + +return bits; +} +EXPORT_SYMBOL_GPL (ptep_get_and_clear_notification_bits); + +void ptep_remove_protection_split (struct mm_struct *mm,pte_t *ptep, +unsigned long gaddr) +{ +pte_t pte; +pgste_t pgste; + + pgste =pgste_get_lock (ptep); +pgste_val (pgste) |=PGSTE_UC_BIT ; + pte = *ptep; +pte_val (pte) &= ~_PAGE_PROTECT; + + pgste =pgste_pte_notify (mm, gaddr, ptep, pgste); +ptep_ipte_global (mm, gaddr, ptep,0 ); + + *ptep = pte; +pgste_set_unlock (ptep, pgste); +} +EXPORT_SYMBOL_GPL (ptep_remove_protection_split); +/* * Test and reset if a guest page is dirty */
Signature · 1 line
2.14.3