Message ID | 1552357142-636-1-git-send-email-anshuman.khandual@arm.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | KVM: ARM: Remove pgtable page standard functions from stage-2 page tables | expand |
On Tue, Mar 12, 2019 at 07:49:02AM +0530, Anshuman Khandual wrote: > ARM64 standard pgtable functions are going to use pgtable_page_[ctor|dtor] > or pgtable_pmd_page_[ctor|dtor] constructs. At present KVM guest stage-2 > PUD|PMD|PTE level page tabe pages are allocated with __get_free_page() > via mmu_memory_cache_alloc() but released with standard pud|pmd_free() or > pte_free_kernel(). These will fail once they start calling into pgtable_ > [pmd]_page_dtor() for pages which never originally went through respective > constructor functions. Hence convert all stage-2 page table page release > functions to call buddy directly while freeing pages. This is apparently cleaner than what I have done. Acked-by: Yu Zhao <yuzhao@google.com> > Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com> > --- > arch/arm/include/asm/stage2_pgtable.h | 4 ++-- > arch/arm64/include/asm/stage2_pgtable.h | 4 ++-- > virt/kvm/arm/mmu.c | 2 +- > 3 files changed, 5 insertions(+), 5 deletions(-) > > diff --git a/arch/arm/include/asm/stage2_pgtable.h b/arch/arm/include/asm/stage2_pgtable.h > index de2089501b8b..417a3be00718 100644 > --- a/arch/arm/include/asm/stage2_pgtable.h > +++ b/arch/arm/include/asm/stage2_pgtable.h > @@ -32,14 +32,14 @@ > #define stage2_pgd_present(kvm, pgd) pgd_present(pgd) > #define stage2_pgd_populate(kvm, pgd, pud) pgd_populate(NULL, pgd, pud) > #define stage2_pud_offset(kvm, pgd, address) pud_offset(pgd, address) > -#define stage2_pud_free(kvm, pud) pud_free(NULL, pud) > +#define stage2_pud_free(kvm, pud) free_page((unsigned long)pud) > > #define stage2_pud_none(kvm, pud) pud_none(pud) > #define stage2_pud_clear(kvm, pud) pud_clear(pud) > #define stage2_pud_present(kvm, pud) pud_present(pud) > #define stage2_pud_populate(kvm, pud, pmd) pud_populate(NULL, pud, pmd) > #define stage2_pmd_offset(kvm, pud, address) pmd_offset(pud, address) > -#define stage2_pmd_free(kvm, pmd) pmd_free(NULL, pmd) > +#define stage2_pmd_free(kvm, pmd) free_page((unsigned long)pmd) > > #define stage2_pud_huge(kvm, pud) pud_huge(pud) > > diff --git a/arch/arm64/include/asm/stage2_pgtable.h b/arch/arm64/include/asm/stage2_pgtable.h > index 5412fa40825e..915809e4ac32 100644 > --- a/arch/arm64/include/asm/stage2_pgtable.h > +++ b/arch/arm64/include/asm/stage2_pgtable.h > @@ -119,7 +119,7 @@ static inline pud_t *stage2_pud_offset(struct kvm *kvm, > static inline void stage2_pud_free(struct kvm *kvm, pud_t *pud) > { > if (kvm_stage2_has_pud(kvm)) > - pud_free(NULL, pud); > + free_page((unsigned long)pud); > } > > static inline bool stage2_pud_table_empty(struct kvm *kvm, pud_t *pudp) > @@ -192,7 +192,7 @@ static inline pmd_t *stage2_pmd_offset(struct kvm *kvm, > static inline void stage2_pmd_free(struct kvm *kvm, pmd_t *pmd) > { > if (kvm_stage2_has_pmd(kvm)) > - pmd_free(NULL, pmd); > + free_page((unsigned long)pmd); > } > > static inline bool stage2_pud_huge(struct kvm *kvm, pud_t pud) > diff --git a/virt/kvm/arm/mmu.c b/virt/kvm/arm/mmu.c > index e9d28a7ca673..00bd79a2f0b1 100644 > --- a/virt/kvm/arm/mmu.c > +++ b/virt/kvm/arm/mmu.c > @@ -191,7 +191,7 @@ static void clear_stage2_pmd_entry(struct kvm *kvm, pmd_t *pmd, phys_addr_t addr > VM_BUG_ON(pmd_thp_or_huge(*pmd)); > pmd_clear(pmd); > kvm_tlb_flush_vmid_ipa(kvm, addr); > - pte_free_kernel(NULL, pte_table); > + __free_page(virt_to_page(pte_table)); > put_page(virt_to_page(pmd)); > } > > -- > 2.20.1 >
Hi Anshuman, On 12/03/2019 02:19, Anshuman Khandual wrote: > ARM64 standard pgtable functions are going to use pgtable_page_[ctor|dtor] > or pgtable_pmd_page_[ctor|dtor] constructs. At present KVM guest stage-2 > PUD|PMD|PTE level page tabe pages are allocated with __get_free_page() > via mmu_memory_cache_alloc() but released with standard pud|pmd_free() or > pte_free_kernel(). These will fail once they start calling into pgtable_ > [pmd]_page_dtor() for pages which never originally went through respective > constructor functions. Hence convert all stage-2 page table page release > functions to call buddy directly while freeing pages. > > Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com> > --- > arch/arm/include/asm/stage2_pgtable.h | 4 ++-- > arch/arm64/include/asm/stage2_pgtable.h | 4 ++-- > virt/kvm/arm/mmu.c | 2 +- > 3 files changed, 5 insertions(+), 5 deletions(-) > > diff --git a/arch/arm/include/asm/stage2_pgtable.h b/arch/arm/include/asm/stage2_pgtable.h > index de2089501b8b..417a3be00718 100644 > --- a/arch/arm/include/asm/stage2_pgtable.h > +++ b/arch/arm/include/asm/stage2_pgtable.h > @@ -32,14 +32,14 @@ > #define stage2_pgd_present(kvm, pgd) pgd_present(pgd) > #define stage2_pgd_populate(kvm, pgd, pud) pgd_populate(NULL, pgd, pud) > #define stage2_pud_offset(kvm, pgd, address) pud_offset(pgd, address) > -#define stage2_pud_free(kvm, pud) pud_free(NULL, pud) > +#define stage2_pud_free(kvm, pud) free_page((unsigned long)pud) That must be a NOP, as we don't have pud on arm32 (we have 3 level table). The pud_* helpers here all fallback to the generic no-pud helpers. > > #define stage2_pud_none(kvm, pud) pud_none(pud) > #define stage2_pud_clear(kvm, pud) pud_clear(pud) > #define stage2_pud_present(kvm, pud) pud_present(pud) > #define stage2_pud_populate(kvm, pud, pmd) pud_populate(NULL, pud, pmd) > #define stage2_pmd_offset(kvm, pud, address) pmd_offset(pud, address) > -#define stage2_pmd_free(kvm, pmd) pmd_free(NULL, pmd) > +#define stage2_pmd_free(kvm, pmd) free_page((unsigned long)pmd) > > #define stage2_pud_huge(kvm, pud) pud_huge(pud) > > diff --git a/arch/arm64/include/asm/stage2_pgtable.h b/arch/arm64/include/asm/stage2_pgtable.h > index 5412fa40825e..915809e4ac32 100644 > --- a/arch/arm64/include/asm/stage2_pgtable.h > +++ b/arch/arm64/include/asm/stage2_pgtable.h > @@ -119,7 +119,7 @@ static inline pud_t *stage2_pud_offset(struct kvm *kvm, > static inline void stage2_pud_free(struct kvm *kvm, pud_t *pud) > { > if (kvm_stage2_has_pud(kvm)) > - pud_free(NULL, pud); > + free_page((unsigned long)pud); > } > > static inline bool stage2_pud_table_empty(struct kvm *kvm, pud_t *pudp) > @@ -192,7 +192,7 @@ static inline pmd_t *stage2_pmd_offset(struct kvm *kvm, > static inline void stage2_pmd_free(struct kvm *kvm, pmd_t *pmd) > { > if (kvm_stage2_has_pmd(kvm)) > - pmd_free(NULL, pmd); > + free_page((unsigned long)pmd); > } > > static inline bool stage2_pud_huge(struct kvm *kvm, pud_t pud) > diff --git a/virt/kvm/arm/mmu.c b/virt/kvm/arm/mmu.c > index e9d28a7ca673..00bd79a2f0b1 100644 > --- a/virt/kvm/arm/mmu.c > +++ b/virt/kvm/arm/mmu.c > @@ -191,7 +191,7 @@ static void clear_stage2_pmd_entry(struct kvm *kvm, pmd_t *pmd, phys_addr_t addr > VM_BUG_ON(pmd_thp_or_huge(*pmd)); > pmd_clear(pmd); > kvm_tlb_flush_vmid_ipa(kvm, addr); > - pte_free_kernel(NULL, pte_table); > + __free_page(virt_to_page(pte_table)); > put_page(virt_to_page(pmd)); > } > With that fixed, Reviewed-by: Suzuki K Poulose <suzuki.poulose@arm.com>
On 03/12/2019 04:07 PM, Suzuki K Poulose wrote: > Hi Anshuman, > > On 12/03/2019 02:19, Anshuman Khandual wrote: >> ARM64 standard pgtable functions are going to use pgtable_page_[ctor|dtor] >> or pgtable_pmd_page_[ctor|dtor] constructs. At present KVM guest stage-2 >> PUD|PMD|PTE level page tabe pages are allocated with __get_free_page() >> via mmu_memory_cache_alloc() but released with standard pud|pmd_free() or >> pte_free_kernel(). These will fail once they start calling into pgtable_ >> [pmd]_page_dtor() for pages which never originally went through respective >> constructor functions. Hence convert all stage-2 page table page release >> functions to call buddy directly while freeing pages. >> >> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com> >> --- >> arch/arm/include/asm/stage2_pgtable.h | 4 ++-- >> arch/arm64/include/asm/stage2_pgtable.h | 4 ++-- >> virt/kvm/arm/mmu.c | 2 +- >> 3 files changed, 5 insertions(+), 5 deletions(-) >> >> diff --git a/arch/arm/include/asm/stage2_pgtable.h b/arch/arm/include/asm/stage2_pgtable.h >> index de2089501b8b..417a3be00718 100644 >> --- a/arch/arm/include/asm/stage2_pgtable.h >> +++ b/arch/arm/include/asm/stage2_pgtable.h >> @@ -32,14 +32,14 @@ >> #define stage2_pgd_present(kvm, pgd) pgd_present(pgd) >> #define stage2_pgd_populate(kvm, pgd, pud) pgd_populate(NULL, pgd, pud) >> #define stage2_pud_offset(kvm, pgd, address) pud_offset(pgd, address) >> -#define stage2_pud_free(kvm, pud) pud_free(NULL, pud) >> +#define stage2_pud_free(kvm, pud) free_page((unsigned long)pud) > > That must be a NOP, as we don't have pud on arm32 (we have 3 level table). > The pud_* helpers here all fallback to the generic no-pud helpers. Which is the following here for pud_free() #define pud_free(mm, x) do { } while (0) On arm64 its protected by kvm_stage2_has_pud() helper before calling into pud_free(). In this case even though applicable pud_free() is NOP, it is still misleading. If we are sure about page table level will always remain three it can directly have a NOP (do/while) in there.
On 12/03/2019 11:31, Anshuman Khandual wrote: > > > On 03/12/2019 04:07 PM, Suzuki K Poulose wrote: >> Hi Anshuman, >> >> On 12/03/2019 02:19, Anshuman Khandual wrote: >>> ARM64 standard pgtable functions are going to use pgtable_page_[ctor|dtor] >>> or pgtable_pmd_page_[ctor|dtor] constructs. At present KVM guest stage-2 >>> PUD|PMD|PTE level page tabe pages are allocated with __get_free_page() >>> via mmu_memory_cache_alloc() but released with standard pud|pmd_free() or >>> pte_free_kernel(). These will fail once they start calling into pgtable_ >>> [pmd]_page_dtor() for pages which never originally went through respective >>> constructor functions. Hence convert all stage-2 page table page release >>> functions to call buddy directly while freeing pages. >>> >>> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com> >>> --- >>> arch/arm/include/asm/stage2_pgtable.h | 4 ++-- >>> arch/arm64/include/asm/stage2_pgtable.h | 4 ++-- >>> virt/kvm/arm/mmu.c | 2 +- >>> 3 files changed, 5 insertions(+), 5 deletions(-) >>> >>> diff --git a/arch/arm/include/asm/stage2_pgtable.h b/arch/arm/include/asm/stage2_pgtable.h >>> index de2089501b8b..417a3be00718 100644 >>> --- a/arch/arm/include/asm/stage2_pgtable.h >>> +++ b/arch/arm/include/asm/stage2_pgtable.h >>> @@ -32,14 +32,14 @@ >>> #define stage2_pgd_present(kvm, pgd) pgd_present(pgd) >>> #define stage2_pgd_populate(kvm, pgd, pud) pgd_populate(NULL, pgd, pud) >>> #define stage2_pud_offset(kvm, pgd, address) pud_offset(pgd, address) >>> -#define stage2_pud_free(kvm, pud) pud_free(NULL, pud) >>> +#define stage2_pud_free(kvm, pud) free_page((unsigned long)pud) >> >> That must be a NOP, as we don't have pud on arm32 (we have 3 level table). >> The pud_* helpers here all fallback to the generic no-pud helpers. > Which is the following here for pud_free() > > #define pud_free(mm, x) do { } while (0) > > On arm64 its protected by kvm_stage2_has_pud() helper before calling into pud_free(). > In this case even though applicable pud_free() is NOP, it is still misleading. If we > are sure about page table level will always remain three it can directly have a NOP > (do/while) in there. > Yes, it is fixed for arm32 and you could have it as do {} while (0), which is what I meant by NOP. On arm64, we had varied number of levels depending on the PAGE_SIZE and now due to the dynamic IPA, hence the check. Cheers Suzuki
diff --git a/arch/arm/include/asm/stage2_pgtable.h b/arch/arm/include/asm/stage2_pgtable.h index de2089501b8b..417a3be00718 100644 --- a/arch/arm/include/asm/stage2_pgtable.h +++ b/arch/arm/include/asm/stage2_pgtable.h @@ -32,14 +32,14 @@ #define stage2_pgd_present(kvm, pgd) pgd_present(pgd) #define stage2_pgd_populate(kvm, pgd, pud) pgd_populate(NULL, pgd, pud) #define stage2_pud_offset(kvm, pgd, address) pud_offset(pgd, address) -#define stage2_pud_free(kvm, pud) pud_free(NULL, pud) +#define stage2_pud_free(kvm, pud) free_page((unsigned long)pud) #define stage2_pud_none(kvm, pud) pud_none(pud) #define stage2_pud_clear(kvm, pud) pud_clear(pud) #define stage2_pud_present(kvm, pud) pud_present(pud) #define stage2_pud_populate(kvm, pud, pmd) pud_populate(NULL, pud, pmd) #define stage2_pmd_offset(kvm, pud, address) pmd_offset(pud, address) -#define stage2_pmd_free(kvm, pmd) pmd_free(NULL, pmd) +#define stage2_pmd_free(kvm, pmd) free_page((unsigned long)pmd) #define stage2_pud_huge(kvm, pud) pud_huge(pud) diff --git a/arch/arm64/include/asm/stage2_pgtable.h b/arch/arm64/include/asm/stage2_pgtable.h index 5412fa40825e..915809e4ac32 100644 --- a/arch/arm64/include/asm/stage2_pgtable.h +++ b/arch/arm64/include/asm/stage2_pgtable.h @@ -119,7 +119,7 @@ static inline pud_t *stage2_pud_offset(struct kvm *kvm, static inline void stage2_pud_free(struct kvm *kvm, pud_t *pud) { if (kvm_stage2_has_pud(kvm)) - pud_free(NULL, pud); + free_page((unsigned long)pud); } static inline bool stage2_pud_table_empty(struct kvm *kvm, pud_t *pudp) @@ -192,7 +192,7 @@ static inline pmd_t *stage2_pmd_offset(struct kvm *kvm, static inline void stage2_pmd_free(struct kvm *kvm, pmd_t *pmd) { if (kvm_stage2_has_pmd(kvm)) - pmd_free(NULL, pmd); + free_page((unsigned long)pmd); } static inline bool stage2_pud_huge(struct kvm *kvm, pud_t pud) diff --git a/virt/kvm/arm/mmu.c b/virt/kvm/arm/mmu.c index e9d28a7ca673..00bd79a2f0b1 100644 --- a/virt/kvm/arm/mmu.c +++ b/virt/kvm/arm/mmu.c @@ -191,7 +191,7 @@ static void clear_stage2_pmd_entry(struct kvm *kvm, pmd_t *pmd, phys_addr_t addr VM_BUG_ON(pmd_thp_or_huge(*pmd)); pmd_clear(pmd); kvm_tlb_flush_vmid_ipa(kvm, addr); - pte_free_kernel(NULL, pte_table); + __free_page(virt_to_page(pte_table)); put_page(virt_to_page(pmd)); }
ARM64 standard pgtable functions are going to use pgtable_page_[ctor|dtor] or pgtable_pmd_page_[ctor|dtor] constructs. At present KVM guest stage-2 PUD|PMD|PTE level page tabe pages are allocated with __get_free_page() via mmu_memory_cache_alloc() but released with standard pud|pmd_free() or pte_free_kernel(). These will fail once they start calling into pgtable_ [pmd]_page_dtor() for pages which never originally went through respective constructor functions. Hence convert all stage-2 page table page release functions to call buddy directly while freeing pages. Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com> --- arch/arm/include/asm/stage2_pgtable.h | 4 ++-- arch/arm64/include/asm/stage2_pgtable.h | 4 ++-- virt/kvm/arm/mmu.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-)