KVM: ARM: Support transparent huge pages and hugetlbfs
Subsystems (2)
cover KVM: ARM: Support transparent huge pages and hugetlbfs
The following series implements support for transparent huge pages and hugetlbfs for KVM/ARM. The patch series is based on kvm-arm-v13-vgic-timers with Will Deacon's hugetlb branch series merged.
These patches can also be fetched from here:git://github.com/virtualopensystems/linux-kvm-arm.git kvm-arm-hugetlb
Christoffer Dall (4):
KVM: ARM: Report support of mmu notifiers to user space
KVM: ARM: Fixup trace ipa printing
KVM: ARM: Improve stage2_clear_pte
KVM: ARM: Transparent huge pages and hugetlbfs support
arch/arm/include/asm/kvm_host.h | 6 +- arch/arm/kvm/arm.c | 1 + arch/arm/kvm/mmu.c | 248 +++++++++++++++++++++++++++++---------- arch/arm/kvm/trace.h | 8 +- 4 files changed, 191 insertions(+), 72 deletions(-)
Signature · 1 line
1.7.9.5
RFC PATCH 1/4 KVM: ARM: Report support of mmu notifiers to user space
This should have been added a long time ago, and is at least required for user space to take advantage of hugetlbfs.
--- arch/arm/kvm/arm.c | 1 + 1 file changed, 1 insertion(+)
arch/arm/kvm/arm.c +1 -0
@@ -199,6 +199,7 @@ int kvm_dev_ioctl_check_extension(long ext)break ;#endif case KVM_CAP_USER_MEMORY : +case KVM_CAP_SYNC_MMU :case KVM_CAP_DESTROY_MEMORY_REGION_WORKS :case KVM_CAP_ONE_REG : r =1 ;
Signature · 1 line
1.7.9.5
RFC PATCH 2/4 KVM: ARM: Fixup trace ipa printing
In reply to Christoffer DallThe arguments where shifted and printed a 64 bit integer as a 32 bit integer.
--- arch/arm/kvm/trace.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
arch/arm/kvm/trace.h +4 -4
@@ -42,14 +42,14 @@ TRACE_EVENT(kvm_exit, TRACE_EVENT(kvm_guest_fault, TP_PROTO(unsigned long vcpu_pc, unsigned long hsr, unsigned long hxfar, - unsigned long ipa), + unsigned long long ipa), TP_ARGS(vcpu_pc, hsr, hxfar, ipa), TP_STRUCT__entry( __field( unsigned long, vcpu_pc ) __field( unsigned long, hsr ) __field( unsigned long, hxfar ) - __field( unsigned long, ipa ) + __field( unsigned long long, ipa ) ), TP_fast_assign(
@@ -60,9 +60,9 @@ TRACE_EVENT(kvm_guest_fault, ),TP_printk ("guest fault at PC %#08lx (hxfar %#08lx, " -"ipa %#08lx, hsr %#08lx" , +"ipa %#16llx, hsr %#08lx" , __entry->vcpu_pc, __entry->hxfar, - __entry->hsr, __entry->ipa) + __entry->ipa, __entry->hsr) ); TRACE_EVENT(kvm_irq_line,
Signature · 1 line
1.7.9.5
RFC PATCH 3/4 KVM: ARM: Improve stage2_clear_pte
In reply to Christoffer DallFactor out parts of the functionality to make the code more readable and rename to unmap_stage2_range while supporting unmapping ranges in one go.
--- arch/arm/kvm/mmu.c | 122 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 83 insertions(+), 39 deletions(-)
arch/arm/kvm/mmu.c +83 -39
@@ -365,59 +365,103 @@ void kvm_free_stage2_pgd(struct kvm *kvm) kvm->arch.pgd =NULL ; } +static void clear_pud_entry (pud_t *pud) +{ +pmd_t *pmd_table =pmd_offset (pud,0 ); +pud_clear (pud); +pmd_free (NULL , pmd_table); +put_page (virt_to_page (pud)); +} + +static void clear_pmd_entry (pmd_t *pmd) +{ +if (pmd_huge (*pmd)) { +pmd_clear (pmd); + }else { +pte_t *pte_table =pte_offset_kernel (pmd,0 ); +pmd_clear (pmd); +pte_free_kernel (NULL , pte_table); + } +put_page (virt_to_page (pmd)); +} + +static bool pmd_empty (pmd_t *pmd) +{ +struct page *pmd_page =virt_to_page (pmd); +return page_count (pmd_page) ==1 ; +} + +static void clear_pte_entry (pte_t *pte) +{ +set_pte_ext (pte,__pte (0 ),0 ); +put_page (virt_to_page (pte)); +} + +static bool pte_empty (pte_t *pte) +{ +struct page *pte_page =virt_to_page (pte); +return page_count (pte_page) ==1 ; +} +/** -* stage2_clear_pte -- Clear a stage-2 PTE. -* @kvm: The VM pointer -* @addr: The physical address of the PTE +* unmap_stage2_range -- Clear stage2 page table entries to unmap a range +* @kvm: The VM pointer +* @start: The intermediate physical base address of the range to unmap +* @size: The size of the area to unmap * -* Clear a stage-2 PTE, lowering the various ref-counts. Also takes -* care of invalidating the TLBs. Must be called while holding -* mmu_lock, otherwise another faulting VCPU may come in and mess -* things behind our back. +* Clear a range of stage-2 mappings, lowering the various ref-counts. Also +* takes care of invalidating the TLBs. Must be called while holding +* mmu_lock, otherwise another faulting VCPU may come in and mess with things +* behind our backs. */ -static void stage2_clear_pte (struct kvm *kvm,phys_addr_t addr) +static void unmap_stage2_range (struct kvm *kvm,phys_addr_t start,size_t size) {pgd_t *pgd;pud_t *pud;pmd_t *pmd;pte_t *pte; -struct page *page; - - pgd = kvm->arch.pgd +pgd_index (addr); - pud =pud_offset (pgd, addr); -if (pud_none (*pud)) -return ; +phys_addr_t addr = start, end = start + size; +size_t range; - pmd =pmd_offset (pud, addr); -if (pmd_none (*pmd)) -return ; +while (addr < end) { + pgd = kvm->arch.pgd +pgd_index (addr); + pud =pud_offset (pgd, addr); +if (pud_none (*pud)) { + addr +=PUD_SIZE ; +continue ; + } - pte =pte_offset_kernel (pmd, addr); -set_pte_ext (pte,__pte (0 ),0 ); + pmd =pmd_offset (pud, addr); +if (pmd_none (*pmd)) { + addr +=PMD_SIZE ; +continue ; + } - page =virt_to_page (pte); -put_page (page); -if (page_count (page) !=1 ) { -kvm_tlb_flush_vmid (kvm); -return ; - } +if (pmd_huge (*pmd)) { +clear_pmd_entry (pmd); +if (pmd_empty (pmd)) +clear_pud_entry (pud); + addr +=PMD_SIZE ; +continue ; + } -/* Need to remove pte page */ -pmd_clear (pmd); -pte_free_kernel (NULL , (pte_t *)((unsigned long )pte &PAGE_MASK )); + pte =pte_offset_kernel (pmd, addr); +clear_pte_entry (pte); + range =PAGE_SIZE ; + +/* If we emptied the pte, walk back up the ladder */ +if (pte_empty (pte)) { +clear_pmd_entry (pmd); + range =PMD_SIZE ; +if (pmd_empty (pmd)) { +clear_pud_entry (pud); + range =PUD_SIZE ; + } + } - page =virt_to_page (pmd); -put_page (page); -if (page_count (page) !=1 ) { -kvm_tlb_flush_vmid (kvm); -return ; + addr += range; } -pud_clear (pud); -pmd_free (NULL , (pmd_t *)((unsigned long )pmd &PAGE_MASK )); - - page =virt_to_page (pud); -put_page (page);kvm_tlb_flush_vmid (kvm); }
@@ -693,7 +737,7 @@ static void handle_hva_to_gpa(struct kvm *kvm,static void kvm_unmap_hva_handler (struct kvm *kvm,gpa_t gpa,void *data) { -stage2_clear_pte (kvm, gpa); +unmap_stage2_range (kvm, gpa,PAGE_SIZE ); }int kvm_unmap_hva (struct kvm *kvm,unsigned long hva)
Signature · 1 line
1.7.9.5
RFC PATCH 4/4 KVM: ARM: Transparent huge pages and hugetlbfs support
In reply to Christoffer DallSupport transparent huge pages in KVM/ARM. This requires quite a bit of checkint and for qemu support to take advantage of this, you need to make sure qemu allocates pages on aligned to the PMD size.
--- arch/arm/include/asm/kvm_host.h | 6 +- arch/arm/kvm/mmu.c | 126 +++++++++++++++++++++++++++++++-------- 2 files changed, 103 insertions(+), 29 deletions(-)
arch/arm/include/asm/kvm_host.h +3 -3
@@ -34,9 +34,9 @@#define KVM_VCPU_MAX_FEATURES 0/* We don't currently support large pages. */ -#define KVM_HPAGE_GFN_SHIFT (x) 0 -#define KVM_NR_PAGE_SIZES 1 -#define KVM_PAGES_PER_HPAGE (x) (1UL<<31) +#define KVM_HPAGE_GFN_SHIFT (_level) (((_level) - 1) * 21) +#define KVM_HPAGE_SIZE (1UL << KVM_HPAGE_GFN_SHIFT(1)) +#define KVM_PAGES_PER_HPAGE (KVM_HPAGE_SIZE / PAGE_SIZE)struct kvm_vcpu ;u32 *kvm_vcpu_reg (struct kvm_vcpu *vcpu,u8 reg_num,u32 mode);
arch/arm/kvm/mmu.c +100 -26
206 lines not on this page · raw message
Signature · 1 line
1.7.9.5