powerpc: lookup_linux_pte has been made public
Subsystems (3)
A message that is not in the archive (sent off-list or not yet received): 1360584763-21988-1-git-send-email-a
PATCH 1/4 powerpc: lookup_linux_pte has been made public
From: Alexey Kardashevskiy <[email protected]>
The lookup_linux_pte() function returns a linux PTE which is required to convert KVM guest physical address into host real address in real mode.
This convertion will be used by upcoming support of H_PUT_TCE_INDIRECT as TCE list address comes from the guest directly so it is a guest physical.
--- arch/powerpc/include/asm/pgtable-ppc64.h | 3 +++ arch/powerpc/kvm/book3s_hv_rm_mmu.c | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-)
arch/powerpc/include/asm/pgtable-ppc64.h +3 -0
@@ -377,6 +377,9 @@ static inline pte_t *find_linux_pte_or_hugepte(pgd_t *pgdir, unsigned long ea, }#endif /* !CONFIG_HUGETLB_PAGE */ +pte_t lookup_linux_pte (pgd_t *pgdir,unsigned long hva, +int writing,unsigned long *pte_sizep); +#endif /* __ASSEMBLY__ */ #endif /* _ASM_POWERPC_PGTABLE_PPC64_H_ */
arch/powerpc/kvm/book3s_hv_rm_mmu.c +2 -2
@@ -145,8 +145,8 @@ static void remove_revmap_chain(struct kvm *kvm, long pte_index,unlock_rmap (rmap); } -static pte_t lookup_linux_pte (pgd_t *pgdir,unsigned long hva, -int writing,unsigned long *pte_sizep) +pte_t lookup_linux_pte (pgd_t *pgdir,unsigned long hva, +int writing,unsigned long *pte_sizep) {pte_t *ptep;unsigned long ps = *pte_sizep;
Signature · 1 line
1.7.10.4
Quoted 22 lines · On Mon, Feb 11, 2013 at 11:12:40PM +1100, [email protected] wrote:
From: Alexey Kardashevskiy <[email protected]>
The
lookup_linux_pte()function returns a linux PTE which is required to convert KVM guest physical address into host real address in real mode.This convertion will be used by upcoming support of
H_PUT_TCE_INDIRECTas TCE list address comes from the guest directly so it is a guest physical.Signed-off-by Alexey Kardashevskiy <[email protected]>Cc David Gibson <[email protected]>--- arch/powerpc/include/asm/pgtable-ppc64.h | 3 +++ arch/powerpc/kvm/book3s_hv_rm_mmu.c | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-)arch/powerpc/include/asm/pgtable-ppc64.h +0
-0
arch/powerpc/include/asm/pgtable-ppc64.h static inline pte_t *find_linux_pte_or_hugepte(pgd_t *pgdir, unsigned long ea, · line 382
Quoted 6 lines
arch/powerpc/include/asm/pgtable-ppc64.h +3
-0@@ -377,6 +377,9 @@ static inline pte_t *find_linux_pte_or_hugepte(pgd_t *pgdir, unsigned long ea, }#endif /* !CONFIG_HUGETLB_PAGE */ +pte_t lookup_linux_pte (pgd_t *pgdir,unsigned long hva, +int writing,unsigned long *pte_sizep); +
This seems a slightly odd place to put the declaration of a function which is defined in the KVM code. kvm-ppc.h might be a better place.
Paul.
PATCH 2/4 powerpc kvm: added multiple TCEs requests support
In reply to a message not in the archiveFrom: Alexey Kardashevskiy <[email protected]>
The patch adds real mode handlers for H_PUT_TCE_INDIRECT and H_STUFF_TCE hypercalls for QEMU emulated devices such as virtio devices or emulated PCI. These calls allow adding multiple entries (up to 512) into the TCE table in one call which saves time on transition to/from real mode.
The patch adds a guest physical to host real address converter and calls the existing H_PUT_TCE handler. The converting function is going to be fully utilized by upcoming VFIO supporting patches.
The patch also implements the KVM_CAP_PPC_MULTITCE capability, so in order to support the functionality of this patch QEMU needs to query for this capability and set the "hcall-multi-tce" hypertas property if the capability is present.
--- arch/powerpc/include/asm/kvm_ppc.h | 15 ++ arch/powerpc/kvm/book3s_64_vio_hv.c | 241 ++++++++++++++++++++++++++++--- arch/powerpc/kvm/book3s_hv.c | 23 +++ arch/powerpc/kvm/book3s_hv_rmhandlers.S | 6 + arch/powerpc/kvm/book3s_pr_papr.c | 37 ++++- arch/powerpc/kvm/powerpc.c | 3 + include/uapi/linux/kvm.h | 1 + 7 files changed, 301 insertions(+), 25 deletions(-)
arch/powerpc/include/asm/kvm_ppc.h +15 -0
@@ -136,6 +136,21 @@ extern long kvm_vm_ioctl_create_spapr_tce(struct kvm *kvm, struct kvm_create_spapr_tce *args);extern long kvmppc_h_put_tce (struct kvm_vcpu *vcpu,unsigned long liobn,unsigned long ioba,unsigned long tce); +extern long kvmppc_h_put_tce_indirect (struct kvm_vcpu *vcpu, +unsigned long liobn,unsigned long ioba, +unsigned long tce_list,unsigned long npages); +extern long kvmppc_h_stuff_tce (struct kvm_vcpu *vcpu, +unsigned long liobn,unsigned long ioba, +unsigned long tce_value,unsigned long npages); +extern long kvmppc_virtmode_h_put_tce (struct kvm_vcpu *vcpu, +unsigned long liobn,unsigned long ioba, +unsigned long tce); +extern long kvmppc_virtmode_h_put_tce_indirect (struct kvm_vcpu *vcpu, +unsigned long liobn,unsigned long ioba, +unsigned long tce_list,unsigned long npages); +extern long kvmppc_virtmode_h_stuff_tce (struct kvm_vcpu *vcpu, +unsigned long liobn,unsigned long ioba, +unsigned long tce_value,unsigned long npages);extern long kvm_vm_ioctl_allocate_rma (struct kvm *kvm,struct kvm_allocate_rma *rma);extern struct kvmppc_linear_info *kvm_alloc_rma (void );
arch/powerpc/kvm/book3s_64_vio_hv.c +217 -24
271 lines not on this page · raw message
arch/powerpc/kvm/book3s_hv.c +23 -0
@@ -515,6 +515,29 @@ int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu)kvmppc_get_gpr (vcpu,5 ), kvmppc_get_gpr(vcpu, 6));break ; +case H_PUT_TCE : + ret =kvmppc_virtmode_h_put_tce (vcpu,kvmppc_get_gpr (vcpu,4 ), +kvmppc_get_gpr (vcpu,5 ), +kvmppc_get_gpr (vcpu,6 )); +if (ret =H_TOO_HARD ) +return RESUME_HOST ; +break ; +case H_PUT_TCE_INDIRECT : + ret =kvmppc_virtmode_h_put_tce_indirect (vcpu,kvmppc_get_gpr (vcpu,4 ), +kvmppc_get_gpr (vcpu,5 ), +kvmppc_get_gpr (vcpu,6 ), +kvmppc_get_gpr (vcpu,7 )); +if (ret =H_TOO_HARD ) +return RESUME_HOST ; +break ; +case H_STUFF_TCE : + ret =kvmppc_virtmode_h_stuff_tce (vcpu,kvmppc_get_gpr (vcpu,4 ), +kvmppc_get_gpr (vcpu,5 ), +kvmppc_get_gpr (vcpu,6 ), +kvmppc_get_gpr (vcpu,7 )); +if (ret =H_TOO_HARD ) +return RESUME_HOST ; +break ;default :return RESUME_HOST ; }
arch/powerpc/kvm/book3s_hv_rmhandlers.S +6 -0
@@ -1390,6 +1390,12 @@ hcall_real_table: .long 0 /* 0x11c */ .long 0 /* 0x120 */ .long .kvmppc_h_bulk_remove - hcall_real_table + .long 0 /* 0x128 */ + .long 0 /* 0x12c */ + .long 0 /* 0x130 */ + .long 0 /* 0x134 */ + .long .kvmppc_h_stuff_tce - hcall_real_table + .long .kvmppc_h_put_tce_indirect - hcall_real_table hcall_real_table_end: ignore_hdec:
arch/powerpc/kvm/book3s_pr_papr.c +36 -1
@@ -220,7 +220,38 @@ static int kvmppc_h_pr_put_tce(struct kvm_vcpu *vcpu)unsigned long tce =kvmppc_get_gpr (vcpu,6 );long rc; - rc =kvmppc_h_put_tce (vcpu, liobn, ioba, tce); + rc =kvmppc_virtmode_h_put_tce (vcpu, liobn, ioba, tce,1 ); +if (rc =H_TOO_HARD ) +return EMULATE_FAIL ; +kvmppc_set_gpr (vcpu,3 , rc); +return EMULATE_DONE ; +} + +static int kvmppc_h_pr_put_tce_indirect (struct kvm_vcpu *vcpu) +{ +unsigned long liobn =kvmppc_get_gpr (vcpu,4 ); +unsigned long ioba =kvmppc_get_gpr (vcpu,5 ); +unsigned long tce =kvmppc_get_gpr (vcpu,6 ); +unsigned long npages =kvmppc_get_gpr (vcpu,7 ); +long rc; + + rc =kvmppc_virtmode_h_put_tce_indirect (vcpu, liobn, ioba, + tce, npages); +if (rc =H_TOO_HARD ) +return EMULATE_FAIL ; +kvmppc_set_gpr (vcpu,3 , rc); +return EMULATE_DONE ; +} + +static int kvmppc_h_pr_stuff_tce (struct kvm_vcpu *vcpu) +{ +unsigned long liobn =kvmppc_get_gpr (vcpu,4 ); +unsigned long ioba =kvmppc_get_gpr (vcpu,5 ); +unsigned long tce_value =kvmppc_get_gpr (vcpu,6 ); +unsigned long npages =kvmppc_get_gpr (vcpu,7 ); +long rc; + + rc =kvmppc_virtmode_h_stuff_tce (vcpu, liobn, ioba, tce_value, npages);if (rc =H_TOO_HARD )return EMULATE_FAIL ;kvmppc_set_gpr (vcpu,3 , rc);
@@ -240,6 +271,10 @@ int kvmppc_h_pr(struct kvm_vcpu *vcpu, unsigned long cmd)return kvmppc_h_pr_bulk_remove (vcpu);case H_PUT_TCE :return kvmppc_h_pr_put_tce (vcpu); +case H_PUT_TCE_INDIRECT : +return kvmppc_h_pr_put_tce_indirect (vcpu); +case H_STUFF_TCE : +return kvmppc_h_pr_stuff_tce (vcpu);case H_CEDE : vcpu->arch.shared->msr |=MSR_EE ;kvm_vcpu_block (vcpu);
arch/powerpc/kvm/powerpc.c +3 -0
@@ -383,6 +383,9 @@ int kvm_dev_ioctl_check_extension(long ext) r =1 ;break ;#endif +case KVM_CAP_PPC_MULTITCE : + r =1 ; +break ;default : r =0 ;break ;
include/uapi/linux/kvm.h +1 -0
@@ -635,6 +635,7 @@ struct kvm_ppc_smmu_info {#define KVM_CAP_IRQFD_RESAMPLE 82#define KVM_CAP_PPC_BOOKE_WATCHDOG 83#define KVM_CAP_PPC_HTAB_FD 84 +#define KVM_CAP_PPC_MULTITCE 87#ifdef KVM_CAP_IRQ_ROUTING
Signature · 1 line
1.7.10.4
Re: [PATCH 2/4] powerpc kvm: added multiple TCEs requests support
arch/powerpc/kvm/book3s_64_vio_hv.c line 154
Quoted 11 lines · On Mon, Feb 11, 2013 at 11:12:41PM +1100, [email protected] wrote:
arch/powerpc/kvm/book3s_64_vio_hv.c +11
-0+static long emulated_h_put_tce (struct kvmppc_spapr_tce_table *stt, +unsigned long ioba,unsigned long tce) +{ +unsigned long idx = ioba >>SPAPR_TCE_SHIFT ; +struct page *page; +u64 *tbl; + +/* udbg_printf("H_PUT_TCE: liobn 0x%lx => stt=%p window_size=0x%x\n", */ +/* liobn, stt, stt->window_size); */ +if (ioba >= stt->window_size) { +pr_err ("%s failed on ioba=%lx\n" , __func__, ioba);
Doesn't this give the guest a way to spam the host logs? And in fact printk in real mode is potentially problematic. I would just leave out this statement.
arch/powerpc/kvm/book3s_64_vio_hv.c line 159
Quoted 5 lines
arch/powerpc/kvm/book3s_64_vio_hv.c +5
-0+return H_PARAMETER ; + } + + page = stt->pages[idx /TCES_PER_PAGE ]; + tbl = (u64 *)page_address (page);
I would like to see an explanation of why we are confident that page_address() will work correctly in real mode, across all the combinations of config options that we can have for a ppc64 book3s kernel.
Quoted 47 lines
arch/powerpc/kvm/book3s_64_vio_hv.c +32
-8+ +/* FIXME: Need to validate the TCE itself */ +/* udbg_printf("tce @ %p\n", &tbl[idx % TCES_PER_PAGE]); */ + tbl[idx %TCES_PER_PAGE ] = tce; + +return H_SUCCESS ; +} + +/* +* Real mode handlers */ long kvmppc_h_put_tce (struct kvm_vcpu *vcpu,unsigned long liobn,unsigned long ioba,unsigned long tce) { -struct kvm *kvm = vcpu->kvm;struct kvmppc_spapr_tce_table *stt; -/* udbg_printf("H_PUT_TCE(): liobn=0x%lx ioba=0x%lx, tce=0x%lx\n", */ -/* liobn, ioba, tce); */ + stt =find_tce_table (vcpu, liobn); +/* Didn't find the liobn, put it to userspace */ +if (!stt) +return H_TOO_HARD ; + +/* Emulated IO */ +return emulated_h_put_tce (stt, ioba, tce); +} + +long kvmppc_h_put_tce_indirect (struct kvm_vcpu *vcpu, +unsigned long liobn,unsigned long ioba, +unsigned long tce_list,unsigned long npages) +{ +struct kvmppc_spapr_tce_table *stt; +long i, ret =0 ; +unsigned long *tces; + + stt =find_tce_table (vcpu, liobn); +/* Didn't find the liobn, put it to userspace */ +if (!stt) +return H_TOO_HARD ; -list_for_each_entry (stt, &kvm->arch.spapr_tce_tables, list) { -if (stt->liobn == liobn) { -unsigned long idx = ioba >>SPAPR_TCE_SHIFT ; -struct page *page; -u64 *tbl; + tces = (void *)get_real_address (vcpu, tce_list, false,NULL ,NULL );
arch/powerpc/kvm/book3s_64_vio_hv.c line 204
Quoted 10 lines
arch/powerpc/kvm/book3s_64_vio_hv.c +5
-4+if (!tces) +return H_TOO_HARD ; -/* udbg_printf("H_PUT_TCE: liobn 0x%lx => stt=%p window_size=0x%x\n", */ -/* liobn, stt, stt->window_size); */ -if (ioba >= stt->window_size) -return H_PARAMETER ; +/* Emulated IO */ +for (i =0 ; (i < npages) && !ret; ++i, ioba +=IOMMU_PAGE_SIZE ) + ret =emulated_h_put_tce (stt, ioba, tces[i]);
So, tces is a pointer to somewhere inside a real page. Did we check somewhere that tces[npages-1] is in the same page as tces[0]? If so, I missed it. If we didn't, then we probably should check and do something about it.
Quoted 54 lines
arch/powerpc/kvm/book3s_64_vio_hv.c +41
-10- page = stt->pages[idx /TCES_PER_PAGE ]; - tbl = (u64 *)page_address (page); +return ret; +} -/* FIXME: Need to validate the TCE itself */ -/* udbg_printf("tce @ %p\n", &tbl[idx % TCES_PER_PAGE]); */ - tbl[idx %TCES_PER_PAGE ] = tce; -return H_SUCCESS ; - } - } +long kvmppc_h_stuff_tce (struct kvm_vcpu *vcpu, +unsigned long liobn,unsigned long ioba, +unsigned long tce_value,unsigned long npages) +{ +struct kvmppc_spapr_tce_table *stt; +long i, ret =0 ; + + stt =find_tce_table (vcpu, liobn); +/* Didn't find the liobn, put it to userspace */ +if (!stt) +return H_TOO_HARD ; -/* Didn't find the liobn, punt it to userspace */ -return H_TOO_HARD ; +/* Emulated IO */ +for (i =0 ; (i < npages) && !ret; ++i, ioba +=IOMMU_PAGE_SIZE ) + ret =emulated_h_put_tce (stt, ioba, tce_value); + +return ret; +} + +/* +* Virtual mode handlers +*/ +extern long kvmppc_virtmode_h_put_tce (struct kvm_vcpu *vcpu, +unsigned long liobn,unsigned long ioba, +unsigned long tce) +{ +/* At the moment emulated IO is handled the same way */ +return kvmppc_h_put_tce (vcpu, liobn, ioba, tce); +} + +extern long kvmppc_virtmode_h_put_tce_indirect (struct kvm_vcpu *vcpu, +unsigned long liobn,unsigned long ioba, +unsigned long tce_list,unsigned long npages) +{ +struct kvmppc_spapr_tce_table *stt; +unsigned long *tces; +long ret =0 , i; + + stt =find_tce_table (vcpu, liobn); +/* Didn't find the liobn, put it to userspace */
arch/powerpc/kvm/book3s_64_vio_hv.c line 258
Quoted 10 lines
arch/powerpc/kvm/book3s_64_vio_hv.c +10
-0+if (!stt) +return H_TOO_HARD ; + + tces = (void *)get_virt_address (vcpu, tce_list, false,NULL ,NULL ); +if (!tces) +return H_TOO_HARD ; + +/* Emulated IO */ +for (i =0 ; (i < npages) && !ret; ++i, ioba +=IOMMU_PAGE_SIZE ) + ret =emulated_h_put_tce (stt, ioba, tces[i]);
Same comment here about tces[i] overflowing a page boundary.
Quoted 45 lines
arch/powerpc/kvm/book3s_64_vio_hv.c +10
-0+ +return ret; +} + +extern long kvmppc_virtmode_h_stuff_tce (struct kvm_vcpu *vcpu, +unsigned long liobn,unsigned long ioba, +unsigned long tce_value,unsigned long npages) +{ +/* At the moment emulated IO is handled the same way */ +return kvmppc_h_stuff_tce (vcpu, liobn, ioba, tce_value, npages); }arch/powerpc/kvm/book3s_hv.c +23
-0@@ -515,6 +515,29 @@ int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu)kvmppc_get_gpr (vcpu,5 ), kvmppc_get_gpr(vcpu, 6));break ; +case H_PUT_TCE : + ret =kvmppc_virtmode_h_put_tce (vcpu,kvmppc_get_gpr (vcpu,4 ), +kvmppc_get_gpr (vcpu,5 ), +kvmppc_get_gpr (vcpu,6 )); +if (ret ==H_TOO_HARD ) +return RESUME_HOST ; +break ; +case H_PUT_TCE_INDIRECT : + ret =kvmppc_virtmode_h_put_tce_indirect (vcpu,kvmppc_get_gpr (vcpu,4 ), +kvmppc_get_gpr (vcpu,5 ), +kvmppc_get_gpr (vcpu,6 ), +kvmppc_get_gpr (vcpu,7 )); +if (ret ==H_TOO_HARD ) +return RESUME_HOST ; +break ; +case H_STUFF_TCE : + ret =kvmppc_virtmode_h_stuff_tce (vcpu,kvmppc_get_gpr (vcpu,4 ), +kvmppc_get_gpr (vcpu,5 ), +kvmppc_get_gpr (vcpu,6 ), +kvmppc_get_gpr (vcpu,7 )); +if (ret ==H_TOO_HARD ) +return RESUME_HOST ; +break ;default :return RESUME_HOST ; }
[snip]
Quoted 19 lines
arch/powerpc/kvm/powerpc.c +3
-0@@ -383,6 +383,9 @@ int kvm_dev_ioctl_check_extension(long ext) r =1 ;break ;#endif +case KVM_CAP_PPC_MULTITCE : + r =1 ; +break ;default : r =0 ;break ;include/uapi/linux/kvm.h +0
-0
include/uapi/linux/kvm.h struct kvm_ppc_smmu_info { · line 638
Quoted 4 lines
include/uapi/linux/kvm.h +1
-0@@ -635,6 +635,7 @@ struct kvm_ppc_smmu_info {#define KVM_CAP_IRQFD_RESAMPLE 82#define KVM_CAP_PPC_BOOKE_WATCHDOG 83#define KVM_CAP_PPC_HTAB_FD 84 +#define KVM_CAP_PPC_MULTITCE 87
The capability should be described inDocumentation/virtual/kvm/api.txt.
Paul.
Re: [PATCH 2/4] powerpc kvm: added multiple TCEs requests support
Quoted 18 lines · Paul Mackerras
arch/powerpc/kvm/book3s_64_vio_hv.c line 154
Quoted 11 lines · On Mon, Feb 11, 2013 at 11:12:41PM +1100, [email protected] wrote:
arch/powerpc/kvm/book3s_64_vio_hv.c +11
-0+static long emulated_h_put_tce (struct kvmppc_spapr_tce_table *stt, +unsigned long ioba,unsigned long tce) +{ +unsigned long idx = ioba >>SPAPR_TCE_SHIFT ; +struct page *page; +u64 *tbl; + +/* udbg_printf("H_PUT_TCE: liobn 0x%lx => stt=%p window_size=0x%x\n", */ +/* liobn, stt, stt->window_size); */ +if (ioba >= stt->window_size) { +pr_err ("%s failed on ioba=%lx\n" , __func__, ioba);Doesn't this give the guest a way to spam the host logs? And in fact printk in real mode is potentially problematic. I would just leave out this statement.
Quoted 10 lines
arch/powerpc/kvm/book3s_64_vio_hv.c line 159
Quoted 5 lines
arch/powerpc/kvm/book3s_64_vio_hv.c +5
-0+return H_PARAMETER ; + } + + page = stt->pages[idx /TCES_PER_PAGE ]; + tbl = (u64 *)page_address (page);I would like to see an explanation of why we are confident that
page_address()will work correctly in real mode, across all the combinations of config options that we can have for a ppc64 book3s kernel.
It was there before this patch, I just moved it so I would think it has been explained before :)
There is no combination on PPC to get WANT_PAGE_VIRTUAL enabled. CONFIG_HIGHMEM is supported for PPC32 only so HASHED_PAGE_VIRTUAL is not enabled on PPC64 either.
So this definition is supposed to work on PPC64:
#define page_address(page) lowmem_page_address(page)
where lowmem_page_address() is arithmetic operation on a page struct address:
static __always_inline void *lowmem_page_address(const struct page *page)
{
return __va(PFN_PHYS(page_to_pfn(page)));
}PPC32 will use page_address() from mm/highmem.c, I need some lesson about memory layout in 32bit but for now I cannot see how it can possibly fail here.
Quoted 194 lines
Quoted 47 lines
arch/powerpc/kvm/book3s_64_vio_hv.c +32
-8+ +/* FIXME: Need to validate the TCE itself */ +/* udbg_printf("tce @ %p\n", &tbl[idx % TCES_PER_PAGE]); */ + tbl[idx %TCES_PER_PAGE ] = tce; + +return H_SUCCESS ; +} + +/* +* Real mode handlers */ long kvmppc_h_put_tce (struct kvm_vcpu *vcpu,unsigned long liobn,unsigned long ioba,unsigned long tce) { -struct kvm *kvm = vcpu->kvm;struct kvmppc_spapr_tce_table *stt; -/* udbg_printf("H_PUT_TCE(): liobn=0x%lx ioba=0x%lx, tce=0x%lx\n", */ -/* liobn, ioba, tce); */ + stt =find_tce_table (vcpu, liobn); +/* Didn't find the liobn, put it to userspace */ +if (!stt) +return H_TOO_HARD ; + +/* Emulated IO */ +return emulated_h_put_tce (stt, ioba, tce); +} + +long kvmppc_h_put_tce_indirect (struct kvm_vcpu *vcpu, +unsigned long liobn,unsigned long ioba, +unsigned long tce_list,unsigned long npages) +{ +struct kvmppc_spapr_tce_table *stt; +long i, ret =0 ; +unsigned long *tces; + + stt =find_tce_table (vcpu, liobn); +/* Didn't find the liobn, put it to userspace */ +if (!stt) +return H_TOO_HARD ; -list_for_each_entry (stt, &kvm->arch.spapr_tce_tables, list) { -if (stt->liobn = liobn) { -unsigned long idx = ioba >>SPAPR_TCE_SHIFT ; -struct page *page; -u64 *tbl; + tces = (void *)get_real_address (vcpu, tce_list, false,NULL ,NULL );arch/powerpc/kvm/book3s_64_vio_hv.c line 204
Quoted 10 lines
arch/powerpc/kvm/book3s_64_vio_hv.c +5
-4+if (!tces) +return H_TOO_HARD ; -/* udbg_printf("H_PUT_TCE: liobn 0x%lx => stt=%p window_size=0x%x\n", */ -/* liobn, stt, stt->window_size); */ -if (ioba >= stt->window_size) -return H_PARAMETER ; +/* Emulated IO */ +for (i =0 ; (i < npages) && !ret; ++i, ioba +=IOMMU_PAGE_SIZE ) + ret =emulated_h_put_tce (stt, ioba, tces[i]);So, tces is a pointer to somewhere inside a real page. Did we check somewhere that tces[npages-1] is in the same page as tces[0]? If so, I missed it. If we didn't, then we probably should check and do something about it.
Quoted 54 lines
arch/powerpc/kvm/book3s_64_vio_hv.c +41
-10- page = stt->pages[idx /TCES_PER_PAGE ]; - tbl = (u64 *)page_address (page); +return ret; +} -/* FIXME: Need to validate the TCE itself */ -/* udbg_printf("tce @ %p\n", &tbl[idx % TCES_PER_PAGE]); */ - tbl[idx %TCES_PER_PAGE ] = tce; -return H_SUCCESS ; - } - } +long kvmppc_h_stuff_tce (struct kvm_vcpu *vcpu, +unsigned long liobn,unsigned long ioba, +unsigned long tce_value,unsigned long npages) +{ +struct kvmppc_spapr_tce_table *stt; +long i, ret =0 ; + + stt =find_tce_table (vcpu, liobn); +/* Didn't find the liobn, put it to userspace */ +if (!stt) +return H_TOO_HARD ; -/* Didn't find the liobn, punt it to userspace */ -return H_TOO_HARD ; +/* Emulated IO */ +for (i =0 ; (i < npages) && !ret; ++i, ioba +=IOMMU_PAGE_SIZE ) + ret =emulated_h_put_tce (stt, ioba, tce_value); + +return ret; +} + +/* +* Virtual mode handlers +*/ +extern long kvmppc_virtmode_h_put_tce (struct kvm_vcpu *vcpu, +unsigned long liobn,unsigned long ioba, +unsigned long tce) +{ +/* At the moment emulated IO is handled the same way */ +return kvmppc_h_put_tce (vcpu, liobn, ioba, tce); +} + +extern long kvmppc_virtmode_h_put_tce_indirect (struct kvm_vcpu *vcpu, +unsigned long liobn,unsigned long ioba, +unsigned long tce_list,unsigned long npages) +{ +struct kvmppc_spapr_tce_table *stt; +unsigned long *tces; +long ret =0 , i; + + stt =find_tce_table (vcpu, liobn); +/* Didn't find the liobn, put it to userspace */ arch/powerpc/kvm/book3s_64_vio_hv.c line 258
Quoted 10 lines
arch/powerpc/kvm/book3s_64_vio_hv.c +10
-0+if (!stt) +return H_TOO_HARD ; + + tces = (void *)get_virt_address (vcpu, tce_list, false,NULL ,NULL ); +if (!tces) +return H_TOO_HARD ; + +/* Emulated IO */ +for (i =0 ; (i < npages) && !ret; ++i, ioba +=IOMMU_PAGE_SIZE ) + ret =emulated_h_put_tce (stt, ioba, tces[i]);Same comment here about tces[i] overflowing a page boundary.
Quoted 45 lines
arch/powerpc/kvm/book3s_64_vio_hv.c +10
-0+ +return ret; +} + +extern long kvmppc_virtmode_h_stuff_tce (struct kvm_vcpu *vcpu, +unsigned long liobn,unsigned long ioba, +unsigned long tce_value,unsigned long npages) +{ +/* At the moment emulated IO is handled the same way */ +return kvmppc_h_stuff_tce (vcpu, liobn, ioba, tce_value, npages); }arch/powerpc/kvm/book3s_hv.c +23
-0@@ -515,6 +515,29 @@ int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu)kvmppc_get_gpr (vcpu,5 ), kvmppc_get_gpr(vcpu, 6));break ; +case H_PUT_TCE : + ret =kvmppc_virtmode_h_put_tce (vcpu,kvmppc_get_gpr (vcpu,4 ), +kvmppc_get_gpr (vcpu,5 ), +kvmppc_get_gpr (vcpu,6 )); +if (ret =H_TOO_HARD ) +return RESUME_HOST ; +break ; +case H_PUT_TCE_INDIRECT : + ret =kvmppc_virtmode_h_put_tce_indirect (vcpu,kvmppc_get_gpr (vcpu,4 ), +kvmppc_get_gpr (vcpu,5 ), +kvmppc_get_gpr (vcpu,6 ), +kvmppc_get_gpr (vcpu,7 )); +if (ret =H_TOO_HARD ) +return RESUME_HOST ; +break ; +case H_STUFF_TCE : + ret =kvmppc_virtmode_h_stuff_tce (vcpu,kvmppc_get_gpr (vcpu,4 ), +kvmppc_get_gpr (vcpu,5 ), +kvmppc_get_gpr (vcpu,6 ), +kvmppc_get_gpr (vcpu,7 )); +if (ret =H_TOO_HARD ) +return RESUME_HOST ; +break ;default :return RESUME_HOST ; }[snip]
Quoted 18 lines
arch/powerpc/kvm/powerpc.c +3
-0@@ -383,6 +383,9 @@ int kvm_dev_ioctl_check_extension(long ext) r =1 ;break ;#endif +case KVM_CAP_PPC_MULTITCE : + r =1 ; +break ;default : r =0 ;break ;include/uapi/linux/kvm.h +0
-0
Quoted 8 lines
include/uapi/linux/kvm.h struct kvm_ppc_smmu_info { · line 638
Quoted 5 lines
include/uapi/linux/kvm.h +1
-0@@ -635,6 +635,7 @@ struct kvm_ppc_smmu_info {#define KVM_CAP_IRQFD_RESAMPLE 82#define KVM_CAP_PPC_BOOKE_WATCHDOG 83#define KVM_CAP_PPC_HTAB_FD 84 +#define KVM_CAP_PPC_MULTITCE 87The capability should be described in
Documentation/virtual/kvm/api.txt.
Is it enough description?
=4.79 KVM_CAP_PPC_MULTITCE
Architectures: ppc
Parameters: none
Returns: 0 on success; -1 on error
This capability enables the guest to put/remove multiple TCE entries per hypercall which significanly accelerates DMA operations for PPC KVM guests.
When this capability is enabled, H_PUT_TCE_INDIRECT and H_STUFF_TCE are expected to occur rather than H_PUT_TCE which supports only one TCE entry per call.
=
Signature · 1 line
Alexey
PATCH 3/4 powerpc: preparing to support real mode optimization
In reply to a message not in the archiveFrom: Alexey Kardashevskiy <[email protected]>
he current VFIO-on-POWER implementation supports only user mode driven mapping, i.e. QEMU is sending requests to map/unmap pages. However this approach is really slow in really fast hardware so it is better to be moved to the real mode.
The patch adds an API to increment/decrement page counter as get_user_pages API used for user mode mapping does not work in the real mode.
CONFIG_SPARSEMEM_VMEMMAP and CONFIG_FLATMEN are supported.
--- arch/powerpc/include/asm/pgtable-ppc64.h | 3 ++ arch/powerpc/mm/init_64.c | 56 +++++++++++++++++++++++++++++- 2 files changed, 58 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/pgtable-ppc64.h +3 -0
@@ -377,6 +377,9 @@ static inline pte_t *find_linux_pte_or_hugepte(pgd_t *pgdir, unsigned long ea, }#endif /* !CONFIG_HUGETLB_PAGE */ +struct page *vmemmap_pfn_to_page (unsigned long pfn); +long vmemmap_get_page (struct page *page); +long vmemmap_put_page (struct page *page);pte_t lookup_linux_pte (pgd_t *pgdir,unsigned long hva,int writing,unsigned long *pte_sizep);
arch/powerpc/mm/init_64.c +55 -1
60 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Re: [PATCH 3/4] powerpc: preparing to support real mode optimization
Quoted 11 lines · On Mon, Feb 11, 2013 at 11:12:42PM +1100, [email protected] wrote:
From: Alexey Kardashevskiy <[email protected]>
he current VFIO-on-POWER implementation supports only user mode driven mapping, i.e. QEMU is sending requests to map/unmap pages. However this approach is really slow in really fast hardware so it is better to be moved to the real mode.
The patch adds an API to increment/decrement page counter as
get_user_pagesAPI used for user mode mapping does not work in the real mode.
Quoted 5 lines
CONFIG_SPARSEMEM_VMEMMAPandCONFIG_FLATMENare supported.Signed-off-by Alexey Kardashevskiy <[email protected]>Cc David Gibson <[email protected]>---
The names are slightly odd, in that they include "vmemmap_" but exist and work in the flatmem case as well. Apart from that...
Paul.
PATCH 4/4 vfio powerpc: added real mode support
In reply to a message not in the archiveFrom: Alexey Kardashevskiy <[email protected]>
The patch allows the host kernel to handle H_PUT_TCE request without involving QEMU in it what should save time on switching from the kernel to QEMU and back.
The patch adds an IOMMU ID parameter into the KVM_CAP_SPAPR_TCE ioctl, QEMU needs to be fixed to support that.
At the moment H_PUT_TCE is processed in the virtual mode as the page to be mapped may not be present in the RAM so paging may be involved as it can be done from the virtual mode only.
Tests show that this patch increases tranmission speed from 220MB/s to 750..1020MB/s on 10Gb network (Chelsea CXGB3 10Gb ethernet card).
--- arch/powerpc/include/asm/iommu.h | 10 ++ arch/powerpc/include/asm/kvm_host.h | 2 + arch/powerpc/include/asm/kvm_ppc.h | 2 + arch/powerpc/include/uapi/asm/kvm.h | 8 ++ arch/powerpc/kernel/iommu.c | 253 +++++++++++++++++++++++++++++++++-- arch/powerpc/kvm/book3s_64_vio.c | 55 +++++++- arch/powerpc/kvm/book3s_64_vio_hv.c | 186 +++++++++++++++++++++++-- arch/powerpc/kvm/powerpc.c | 11 ++ include/uapi/linux/kvm.h | 1 + 9 files changed, 503 insertions(+), 25 deletions(-)
arch/powerpc/include/asm/iommu.h +10 -0
@@ -78,6 +78,7 @@ struct iommu_table {unsigned long *it_map;/* A simple allocation bitmap for now */ #ifdef CONFIG_IOMMU_API struct iommu_group *it_group; +struct list_head it_hugepages;#endif };
@@ -158,6 +159,15 @@ extern long iommu_clear_tce_user_mode(struct iommu_table *tbl, unsigned long npages);extern long iommu_put_tce_user_mode (struct iommu_table *tbl,unsigned long ioba,unsigned long tce); +extern long iommu_put_tce_real_mode (struct iommu_table *tbl, +unsigned long ioba,unsigned long tce, +pte_t pte,unsigned long pg_size); +extern long iommu_clear_tce_real_mode (struct iommu_table *tbl, +unsigned long ioba,unsigned long tce_value, +unsigned long npages); +extern long iommu_put_tce_virt_mode (struct iommu_table *tbl, +unsigned long ioba,unsigned long tce, +pte_t pte,unsigned long pg_size);extern void iommu_flush_tce (struct iommu_table *tbl);extern long iommu_lock_table (struct iommu_table *tbl,bool lock);
arch/powerpc/include/asm/kvm_host.h +2 -0
@@ -178,6 +178,8 @@ struct kvmppc_spapr_tce_table {struct kvm *kvm;u64 liobn;u32 window_size; +bool virtmode_only; +struct iommu_table *tbl;struct page *pages[0 ]; };
arch/powerpc/include/asm/kvm_ppc.h +2 -0
@@ -134,6 +134,8 @@ extern void kvmppc_map_vrma(struct kvm_vcpu *vcpu,extern int kvmppc_pseries_do_hcall (struct kvm_vcpu *vcpu);extern long kvm_vm_ioctl_create_spapr_tce (struct kvm *kvm,struct kvm_create_spapr_tce *args); +extern long kvm_vm_ioctl_create_spapr_tce_iommu (struct kvm *kvm, +struct kvm_create_spapr_tce_iommu *args);extern long kvmppc_h_put_tce (struct kvm_vcpu *vcpu,unsigned long liobn,unsigned long ioba,unsigned long tce); extern long kvmppc_h_put_tce_indirect(struct kvm_vcpu *vcpu,
arch/powerpc/include/uapi/asm/kvm.h +8 -0
@@ -291,6 +291,14 @@ struct kvm_create_spapr_tce {__u32 window_size; }; +/* for KVM_CAP_SPAPR_TCE_IOMMU */ +struct kvm_create_spapr_tce_iommu { +__u64 liobn; +__u32 iommu_id; +#define SPAPR_TCE_PUT_TCE_VIRTMODE_ONLY 1/* for debug purposes */ +__u32 flags; +}; +/* for KVM_ALLOCATE_RMA */ struct kvm_allocate_rma {__u64 rma_size;
arch/powerpc/kernel/iommu.c +244 -9
322 lines not on this page · raw message
arch/powerpc/kvm/book3s_64_vio.c +53 -2
76 lines not on this page · raw message
arch/powerpc/kvm/book3s_64_vio_hv.c +172 -14
236 lines not on this page · raw message
arch/powerpc/kvm/powerpc.c +11 -0
@@ -934,6 +934,17 @@ long kvm_arch_vm_ioctl(struct file *filp, r =kvm_vm_ioctl_create_spapr_tce (kvm, &create_tce); goto out; } +case KVM_CREATE_SPAPR_TCE_IOMMU : { +struct kvm_create_spapr_tce_iommu create_tce_iommu; +struct kvm *kvm = filp->private_data; + + r = -EFAULT ; +if (copy_from_user (&create_tce_iommu, argp, +sizeof (create_tce_iommu))) + goto out; + r =kvm_vm_ioctl_create_spapr_tce_iommu (kvm, &create_tce_iommu); + goto out; + }#endif /* CONFIG_PPC_BOOK3S_64 */ #ifdef CONFIG_KVM_BOOK3S_64_HV
include/uapi/linux/kvm.h +1 -0
@@ -863,6 +863,7 @@ struct kvm_s390_ucas_mapping {#define KVM_ALLOCATE_RMA _IOR(KVMIO, 0xa9, struct kvm_allocate_rma)/* Available with KVM_CAP_PPC_HTAB_FD */ #define KVM_PPC_GET_HTAB_FD _IOW(KVMIO, 0xaa, struct kvm_get_htab_fd) +#define KVM_CREATE_SPAPR_TCE_IOMMU _IOW(KVMIO, 0xaf, struct kvm_create_spapr_tce_iommu)/* * ioctls for vcpu fds
Signature · 1 line
1.7.10.4
Re: [PATCH 4/4] vfio powerpc: added real mode support
Quoted 15 lines · On Mon, Feb 11, 2013 at 11:12:43PM +1100, [email protected] wrote:
From: Alexey Kardashevskiy <[email protected]>
The patch allows the host kernel to handle
H_PUT_TCErequest without involving QEMU in it what should save time on switching from the kernel to QEMU and back.The patch adds an IOMMU ID parameter into the
KVM_CAP_SPAPR_TCEioctl, QEMU needs to be fixed to support that.At the moment
H_PUT_TCEis processed in the virtual mode as the page to be mapped may not be present in the RAM so paging may be involved as it can be done from the virtual mode only.Tests show that this patch increases tranmission speed from 220MB/s to 750..1020MB/s on 10Gb network (Chelsea CXGB3 10Gb ethernet card).
[snip]
Quoted 91 lines
arch/powerpc/kernel/iommu.c +69
-0@@ -47,6 +47,8 @@#include <asm/fadump.h> #include <asm/vio.h> #include <asm/tce.h> +#include <asm/kvm_book3s_64.h> +#include <asm/page.h> #define DBG (...)@@ -727,6 +729,7 @@ void iommu_register_group(struct iommu_table * tbl,return ; } tbl->it_group = grp; +INIT_LIST_HEAD (&tbl->it_hugepages);iommu_group_set_iommudata (grp, tbl, group_release);iommu_group_set_name (grp,kasprintf (GFP_KERNEL ,"domain%d-pe%lx" , domain_number, pe_num));@@ -906,6 +909,83 @@ void kvm_iommu_unmap_pages(struct kvm *kvm, struct kvm_memory_slot *slot) { } +/* +* The KVM guest can be backed with 16MB pages (qemu switch +* -mem-path /var/lib/hugetlbfs/global/pagesize-16MB/). +* In this case, we cannot do page counting from the real mode +* as the compound pages are used - they are linked in a list +* with pointers as virtual addresses which are inaccessible +* in real mode. +* +* The code below keeps a 16MB pages list and uses page struct +* in real mode if it is already locked in RAM and inserted into +* the list or switches to the virtual mode where it can be +* handled in a usual manner. +*/ +struct iommu_kvmppc_hugepages { +struct list_head list; +pte_t pte;/* Huge page PTE */ +unsigned long pa;/* Base phys address used as a real TCE */ +struct page *page;/* page struct of the very first subpage */ +unsigned long size;/* Huge page size (always 16MB at the moment) */ +bool dirty;/* Dirty bit */ +}; + +static struct iommu_kvmppc_hugepages *find_hp_by_pte (struct iommu_table *tbl, +pte_t pte) +{ +struct iommu_kvmppc_hugepages *hp; + +list_for_each_entry (hp, &tbl->it_hugepages, list) { +if (hp->pte == pte) +return hp; + } + +return NULL ; +} + +static struct iommu_kvmppc_hugepages *find_hp_by_pa (struct iommu_table *tbl, +unsigned long pa) +{ +struct iommu_kvmppc_hugepages *hp; + +list_for_each_entry (hp, &tbl->it_hugepages, list) { +if ((hp->pa <= pa) && (pa < hp->pa + hp->size)) +return hp; + } + +return NULL ; +} + +static struct iommu_kvmppc_hugepages *add_hp (struct iommu_table *tbl, +pte_t pte,unsigned long va,unsigned long pg_size) +{ +int ret; +struct iommu_kvmppc_hugepages *hp; + + hp =kzalloc (sizeof (*hp),GFP_KERNEL ); +if (!hp) +return NULL ; + + hp->pte = pte; + va = va & ~(pg_size -1 ); + ret =get_user_pages_fast (va,1 , true/*write*/ , &hp->page); +if ((ret !=1 ) || !hp->page) { +kfree (hp); +return NULL ; + } +#if defined(HASHED_PAGE_VIRTUAL ) || defined(WANT_PAGE_VIRTUAL )
arch/powerpc/kernel/iommu.c void kvm_iommu_unmap_pages(struct kvm *kvm, struct kvm_memory_slot *slot) · line 987
Quoted 10 lines
arch/powerpc/kernel/iommu.c +10
-0+#error TODO: fix to avoid page_address() here +#endif + hp->pa =__pa ((unsigned long )page_address (hp->page)); + + hp->size = pg_size; + +list_add (&hp->list, &tbl->it_hugepages); + +return hp; +}
I don't see any locking here. What stops one cpu doing add_hp() from racing with another doing find_hp_by_pte() or find_hp_by_pa()?
[snip]
Quoted 7 lines
arch/powerpc/kernel/iommu.c +3
-0@@ -1021,6 +1123,24 @@ long iommu_clear_tce_user_mode(struct iommu_table *tbl, unsigned long ioba, }EXPORT_SYMBOL_GPL (iommu_clear_tce_user_mode); +long iommu_clear_tce_real_mode (struct iommu_table *tbl,unsigned long ioba, +unsigned long tce_value,unsigned long npages) +{
arch/powerpc/kernel/iommu.c long iommu_clear_tce_user_mode(struct iommu_table *tbl, unsigned long ioba, · line 1138
Quoted 10 lines
arch/powerpc/kernel/iommu.c +10
-0+long ret; +unsigned long entry = ioba >>IOMMU_PAGE_SHIFT ; + + ret =tce_clear_param_check (tbl, ioba, tce_value, npages); +if (!ret) + ret =clear_tce (tbl, true, entry, npages); + +if (ret <0 ) +pr_err ("iommu_tce: %s failed ioba=%lx, tce_value=%lx ret=%ld\n" , + __func__, ioba, tce_value, ret);
Better to avoid printk in real mode if at all possible, particularly if they're guest-triggerable.
[snip]
Quoted 23 lines
arch/powerpc/kernel/iommu.c +12
-2@@ -195,15 +225,43 @@ long kvmppc_h_put_tce_indirect(struct kvm_vcpu *vcpu,if (!stt)return H_TOO_HARD ; +if (stt->virtmode_only) +return H_TOO_HARD ; + tces = (void *)get_real_address (vcpu, tce_list, false,NULL ,NULL );if (!tces)return H_TOO_HARD ;/* Emulated IO */ -for (i =0 ; (i < npages) && !ret; ++i, ioba +=IOMMU_PAGE_SIZE ) - ret =emulated_h_put_tce (stt, ioba, tces[i]); +if (!stt->tbl) { +for (i =0 ; (i < npages) && !ret; ++i, ioba +=IOMMU_PAGE_SIZE ) + ret =emulated_h_put_tce (stt, ioba, tces[i]); + +return ret; + } + +/* VFIO IOMMU */ +for (i =0 ; (i < npages) && !ret; ++i, ioba +=IOMMU_PAGE_SIZE ) {
arch/powerpc/kernel/iommu.c long kvmppc_h_put_tce_indirect(struct kvm_vcpu *vcpu, · line 254
Quoted 10 lines
arch/powerpc/kernel/iommu.c +10
-0+unsigned long hpa, pg_size =0 ; +pte_t pte =0 ; + + hpa =get_real_address (vcpu, tces[i], tces[i] &TCE_PCI_WRITE , + &pte, &pg_size); +if (!hpa) +return H_TOO_HARD ; + + ret =iommu_put_tce_real_mode (stt->tbl, + ioba, hpa, pte, pg_size);
If we get a failure part-way through, should we go back and remove the entries we put in?
[snip]
include/uapi/linux/kvm.h struct kvm_s390_ucas_mapping { · line 866
Quoted 9 lines
include/uapi/linux/kvm.h +1
-0@@ -863,6 +863,7 @@ struct kvm_s390_ucas_mapping {#define KVM_ALLOCATE_RMA _IOR(KVMIO, 0xa9, struct kvm_allocate_rma)/* Available with KVM_CAP_PPC_HTAB_FD */ #define KVM_PPC_GET_HTAB_FD _IOW(KVMIO, 0xaa, struct kvm_get_htab_fd) +#define KVM_CREATE_SPAPR_TCE_IOMMU _IOW(KVMIO, 0xaf, struct kvm_create_spapr_tce_iommu)
This needs an entry in Documentation/virtual/kvm/api.txt.
Paul.