vfio/spapr: Allow backing bigger guest IOMMU pages with smaller physical pages
PATCH v2 1/1 vfio/spapr: Allow backing bigger guest IOMMU pages with smaller physical pages
At the moment the PPC64/pseries guest only supports 4K/64K/16M IOMMU pages and POWER8 CPU supports the exact same set of page size so so far things worked fine.
However POWER9 supports different set of sizes - 4K/64K/2M/1G and the last two - 2M and 1G - are not even allowed in the paravirt interface (RTAS DDW) so we always end up using 64K IOMMU pages, although we could back guest's 16MB IOMMU pages with 2MB pages on the host.
This stores the supported host IOMMU page sizes in VFIOContainer and uses this later when creating a new DMA window. This uses the system page size (64k normally, 2M/16M/1G if hugepages used) as the upper limit of the IOMMU pagesize.
This changes the type of @pagesize to uint64_t as this is what memory_region_iommu_get_min_page_size() returns and clz64() takes.
There should be no behavioral changes on platforms other than pseries. The guest will keep using the IOMMU page size selected by the PHB pagesize property as this only changes the underlying hardware TCE table granularity.
---
Changes:
v2:
* fixed biggest but smaller page size calculation
* limit IOMMU pagesize to the system pagesize
--- include/hw/vfio/vfio-common.h | 1 + hw/vfio/common.c | 3 +++ hw/vfio/spapr.c | 21 ++++++++++++++++++++- 3 files changed, 24 insertions(+), 1 deletion(-)
include/hw/vfio/vfio-common.h +1 -0
@@ -73,6 +73,7 @@ typedef struct VFIOContainer {unsigned iommu_type;int error;bool initialized; +unsigned long pgsizes;/* * This assumes the host IOMMU can support only a single * contiguous IOVA window. We may need to generalize that in
hw/vfio/common.c +3 -0
@@ -1108,6 +1108,7 @@ static int vfio_connect_container(VFIOGroup *group, AddressSpace *as, info.iova_pgsizes =4096 ; }vfio_host_win_add (container,0 , (hwaddr)-1 , info.iova_pgsizes); + container->pgsizes = info.iova_pgsizes; }else if (ioctl (fd,VFIO_CHECK_EXTENSION ,VFIO_SPAPR_TCE_IOMMU ) ||ioctl (fd,VFIO_CHECK_EXTENSION , VFIO_SPAPR_TCE_v2_IOMMU)) {struct vfio_iommu_spapr_tce_info info;
@@ -1172,6 +1173,7 @@ static int vfio_connect_container(VFIOGroup *group, AddressSpace *as, }if (v2) { + container->pgsizes = info.ddw.pgsizes;/* * There is a default window in just created container. * To make region_add/del simpler, we better remove this
@@ -1186,6 +1188,7 @@ static int vfio_connect_container(VFIOGroup *group, AddressSpace *as, } }else {/* The default table uses 4K pages */ + container->pgsizes =0x1000 ; vfio_host_win_add(container, info.dma32_window_start, info.dma32_window_start + info.dma32_window_size - 1,
hw/vfio/spapr.c +20 -1
@@ -15,6 +15,7 @@#include "hw/vfio/vfio-common.h" #include "hw/hw.h" +#include "exec/ram_addr.h" #include "qemu/error-report.h" #include "trace.h"
@@ -144,9 +145,27 @@ int vfio_spapr_create_window(VFIOContainer *container, {int ret;IOMMUMemoryRegion *iommu_mr =IOMMU_MEMORY_REGION (section->mr); -unsigned pagesize =memory_region_iommu_get_min_page_size (iommu_mr); +uint64_t pagesize =memory_region_iommu_get_min_page_size (iommu_mr);unsigned entries, pages;struct vfio_iommu_spapr_tce_create create = { .argsz =sizeof (create) }; +long systempagesize =qemu_getrampagesize (); + +/* +* The host might not support the guest supported IOMMU page size, +* so we will use smaller physical IOMMU pages to back them. +*/ +if (pagesize > systempagesize) { + pagesize = systempagesize; + } + pagesize =1ULL << (63 -clz64 (container->pgsizes & + (pagesize | (pagesize -1 )))); +if (!pagesize) { +error_report ("Host doesn't support page size 0x%" PRIx64 +", the supported mask is 0x%lx" , +memory_region_iommu_get_min_page_size (iommu_mr), + container->pgsizes); +return -EINVAL ; + }/* * FIXME: For VFIO iommu types which have KVM acceleration to
Signature · 1 line
2.11.0
Quoted 17 lines · Alexey Kardashevskiy
At the moment the PPC64/pseries guest only supports 4K/64K/16M IOMMU pages and POWER8 CPU supports the exact same set of page size so so far things worked fine.
However POWER9 supports different set of sizes - 4K/64K/2M/1G and the last two - 2M and 1G - are not even allowed in the paravirt interface (RTAS DDW) so we always end up using 64K IOMMU pages, although we could back guest's 16MB IOMMU pages with 2MB pages on the host.
This stores the supported host IOMMU page sizes in VFIOContainer and uses this later when creating a new DMA window. This uses the system page size (64k normally, 2M/16M/1G if hugepages used) as the upper limit of the IOMMU pagesize.
This changes the type of @pagesize to
uint64_tas this is whatmemory_region_iommu_get_min_page_size()returns andclz64()takes.
Quoted 6 lines
There should be no behavioral changes on platforms other than pseries. The guest will keep using the IOMMU page size selected by the PHB pagesize property as this only changes the underlying hardware TCE table granularity.
Signed-off-by Alexey Kardashevskiy <[email protected]>
Ping?
Quoted 93 lines
---
Changes:
v2:
* fixed biggest but smaller page size calculation
* limit IOMMU pagesize to the system pagesize--- include/hw/vfio/vfio-common.h | 1 + hw/vfio/common.c | 3 +++ hw/vfio/spapr.c | 21 ++++++++++++++++++++- 3 files changed, 24 insertions(+), 1 deletion(-)include/hw/vfio/vfio-common.h +1
-0@@ -73,6 +73,7 @@ typedef struct VFIOContainer {unsigned iommu_type;int error;bool initialized; +unsigned long pgsizes;/* * This assumes the host IOMMU can support only a single * contiguous IOVA window. We may need to generalize that in hw/vfio/common.c +3
-0@@ -1108,6 +1108,7 @@ static int vfio_connect_container(VFIOGroup *group, AddressSpace *as, info.iova_pgsizes =4096 ; }vfio_host_win_add (container,0 , (hwaddr)-1 , info.iova_pgsizes); + container->pgsizes = info.iova_pgsizes; }else if (ioctl (fd,VFIO_CHECK_EXTENSION ,VFIO_SPAPR_TCE_IOMMU ) ||ioctl (fd,VFIO_CHECK_EXTENSION , VFIO_SPAPR_TCE_v2_IOMMU)) {struct vfio_iommu_spapr_tce_info info;@@ -1172,6 +1173,7 @@ static int vfio_connect_container(VFIOGroup *group, AddressSpace *as, }if (v2) { + container->pgsizes = info.ddw.pgsizes;/* * There is a default window in just created container. * To make region_add/del simpler, we better remove this @@ -1186,6 +1188,7 @@ static int vfio_connect_container(VFIOGroup *group, AddressSpace *as, } }else {/* The default table uses 4K pages */ + container->pgsizes =0x1000 ; vfio_host_win_add(container, info.dma32_window_start, info.dma32_window_start + info.dma32_window_size - 1,hw/vfio/spapr.c +20
-1@@ -15,6 +15,7 @@#include "hw/vfio/vfio-common.h" #include "hw/hw.h" +#include "exec/ram_addr.h" #include "qemu/error-report.h" #include "trace.h" @@ -144,9 +145,27 @@ int vfio_spapr_create_window(VFIOContainer *container, {int ret;IOMMUMemoryRegion *iommu_mr =IOMMU_MEMORY_REGION (section->mr); -unsigned pagesize =memory_region_iommu_get_min_page_size (iommu_mr); +uint64_t pagesize =memory_region_iommu_get_min_page_size (iommu_mr);unsigned entries, pages;struct vfio_iommu_spapr_tce_create create = { .argsz =sizeof (create) }; +long systempagesize =qemu_getrampagesize (); + +/* +* The host might not support the guest supported IOMMU page size, +* so we will use smaller physical IOMMU pages to back them. +*/ +if (pagesize > systempagesize) { + pagesize = systempagesize; + } + pagesize =1ULL << (63 -clz64 (container->pgsizes & + (pagesize | (pagesize -1 )))); +if (!pagesize) { +error_report ("Host doesn't support page size 0x%" PRIx64 +", the supported mask is 0x%lx" , +memory_region_iommu_get_min_page_size (iommu_mr), + container->pgsizes); +return -EINVAL ; + }/* * FIXME: For VFIO iommu types which have KVM acceleration to
Signature · 1 line
Alexey
Quoted 22 lines · Alexey Kardashevskiy
At the moment the PPC64/pseries guest only supports 4K/64K/16M IOMMU pages and POWER8 CPU supports the exact same set of page size so so far things worked fine.
However POWER9 supports different set of sizes - 4K/64K/2M/1G and the last two - 2M and 1G - are not even allowed in the paravirt interface (RTAS DDW) so we always end up using 64K IOMMU pages, although we could back guest's 16MB IOMMU pages with 2MB pages on the host.
This stores the supported host IOMMU page sizes in VFIOContainer and uses this later when creating a new DMA window. This uses the system page size (64k normally, 2M/16M/1G if hugepages used) as the upper limit of the IOMMU pagesize.
This changes the type of @pagesize to
uint64_tas this is whatmemory_region_iommu_get_min_page_size()returns andclz64()takes.There should be no behavioral changes on platforms other than pseries. The guest will keep using the IOMMU page size selected by the PHB pagesize property as this only changes the underlying hardware TCE table granularity.
Quoted 6 lines
Signed-off-by Alexey Kardashevskiy <[email protected]>---
Changes:
v2:
* fixed biggest but smaller page size calculation
* limit IOMMU pagesize to the system pagesize
Sorry, this fell of my radar for a bit.
I've now applied it to ppc-for-3.1.
Quoted 87 lines
--- include/hw/vfio/vfio-common.h | 1 + hw/vfio/common.c | 3 +++ hw/vfio/spapr.c | 21 ++++++++++++++++++++- 3 files changed, 24 insertions(+), 1 deletion(-)include/hw/vfio/vfio-common.h +1
-0@@ -73,6 +73,7 @@ typedef struct VFIOContainer {unsigned iommu_type;int error;bool initialized; +unsigned long pgsizes;/* * This assumes the host IOMMU can support only a single * contiguous IOVA window. We may need to generalize that in hw/vfio/common.c +3
-0@@ -1108,6 +1108,7 @@ static int vfio_connect_container(VFIOGroup *group, AddressSpace *as, info.iova_pgsizes =4096 ; }vfio_host_win_add (container,0 , (hwaddr)-1 , info.iova_pgsizes); + container->pgsizes = info.iova_pgsizes; }else if (ioctl (fd,VFIO_CHECK_EXTENSION ,VFIO_SPAPR_TCE_IOMMU ) ||ioctl (fd,VFIO_CHECK_EXTENSION , VFIO_SPAPR_TCE_v2_IOMMU)) {struct vfio_iommu_spapr_tce_info info;@@ -1172,6 +1173,7 @@ static int vfio_connect_container(VFIOGroup *group, AddressSpace *as, }if (v2) { + container->pgsizes = info.ddw.pgsizes;/* * There is a default window in just created container. * To make region_add/del simpler, we better remove this @@ -1186,6 +1188,7 @@ static int vfio_connect_container(VFIOGroup *group, AddressSpace *as, } }else {/* The default table uses 4K pages */ + container->pgsizes =0x1000 ; vfio_host_win_add(container, info.dma32_window_start, info.dma32_window_start + info.dma32_window_size - 1,hw/vfio/spapr.c +20
-1@@ -15,6 +15,7 @@#include "hw/vfio/vfio-common.h" #include "hw/hw.h" +#include "exec/ram_addr.h" #include "qemu/error-report.h" #include "trace.h" @@ -144,9 +145,27 @@ int vfio_spapr_create_window(VFIOContainer *container, {int ret;IOMMUMemoryRegion *iommu_mr =IOMMU_MEMORY_REGION (section->mr); -unsigned pagesize =memory_region_iommu_get_min_page_size (iommu_mr); +uint64_t pagesize =memory_region_iommu_get_min_page_size (iommu_mr);unsigned entries, pages;struct vfio_iommu_spapr_tce_create create = { .argsz =sizeof (create) }; +long systempagesize =qemu_getrampagesize (); + +/* +* The host might not support the guest supported IOMMU page size, +* so we will use smaller physical IOMMU pages to back them. +*/ +if (pagesize > systempagesize) { + pagesize = systempagesize; + } + pagesize =1ULL << (63 -clz64 (container->pgsizes & + (pagesize | (pagesize -1 )))); +if (!pagesize) { +error_report ("Host doesn't support page size 0x%" PRIx64 +", the supported mask is 0x%lx" , +memory_region_iommu_get_min_page_size (iommu_mr), + container->pgsizes); +return -EINVAL ; + }/* * FIXME: For VFIO iommu types which have KVM acceleration to
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Quoted 30 lines · David Gibson
Quoted 22 lines · Alexey Kardashevskiy
At the moment the PPC64/pseries guest only supports 4K/64K/16M IOMMU pages and POWER8 CPU supports the exact same set of page size so so far things worked fine.
However POWER9 supports different set of sizes - 4K/64K/2M/1G and the last two - 2M and 1G - are not even allowed in the paravirt interface (RTAS DDW) so we always end up using 64K IOMMU pages, although we could back guest's 16MB IOMMU pages with 2MB pages on the host.
This stores the supported host IOMMU page sizes in VFIOContainer and uses this later when creating a new DMA window. This uses the system page size (64k normally, 2M/16M/1G if hugepages used) as the upper limit of the IOMMU pagesize.
This changes the type of @pagesize to
uint64_tas this is whatmemory_region_iommu_get_min_page_size()returns andclz64()takes.There should be no behavioral changes on platforms other than pseries. The guest will keep using the IOMMU page size selected by the PHB pagesize property as this only changes the underlying hardware TCE table granularity.
Quoted 6 lines
Signed-off-by Alexey Kardashevskiy <[email protected]>---
Changes:
v2:
* fixed biggest but smaller page size calculation
* limit IOMMU pagesize to the system pagesize
Quoted 3 lines
Sorry, this fell of my radar for a bit.
I've now applied it to ppc-for-3.1.
Alex might object that as it does not have his "rb" ;)
Quoted 89 lines
Quoted 88 lines
--- include/hw/vfio/vfio-common.h | 1 + hw/vfio/common.c | 3 +++ hw/vfio/spapr.c | 21 ++++++++++++++++++++- 3 files changed, 24 insertions(+), 1 deletion(-)include/hw/vfio/vfio-common.h +1
-0@@ -73,6 +73,7 @@ typedef struct VFIOContainer {unsigned iommu_type;int error;bool initialized; +unsigned long pgsizes;/* * This assumes the host IOMMU can support only a single * contiguous IOVA window. We may need to generalize that in hw/vfio/common.c +3
-0@@ -1108,6 +1108,7 @@ static int vfio_connect_container(VFIOGroup *group, AddressSpace *as, info.iova_pgsizes =4096 ; }vfio_host_win_add (container,0 , (hwaddr)-1 , info.iova_pgsizes); + container->pgsizes = info.iova_pgsizes; }else if (ioctl (fd,VFIO_CHECK_EXTENSION ,VFIO_SPAPR_TCE_IOMMU ) ||ioctl (fd,VFIO_CHECK_EXTENSION , VFIO_SPAPR_TCE_v2_IOMMU)) {struct vfio_iommu_spapr_tce_info info;@@ -1172,6 +1173,7 @@ static int vfio_connect_container(VFIOGroup *group, AddressSpace *as, }if (v2) { + container->pgsizes = info.ddw.pgsizes;/* * There is a default window in just created container. * To make region_add/del simpler, we better remove this @@ -1186,6 +1188,7 @@ static int vfio_connect_container(VFIOGroup *group, AddressSpace *as, } }else {/* The default table uses 4K pages */ + container->pgsizes =0x1000 ; vfio_host_win_add(container, info.dma32_window_start, info.dma32_window_start + info.dma32_window_size - 1,hw/vfio/spapr.c +20
-1@@ -15,6 +15,7 @@#include "hw/vfio/vfio-common.h" #include "hw/hw.h" +#include "exec/ram_addr.h" #include "qemu/error-report.h" #include "trace.h" @@ -144,9 +145,27 @@ int vfio_spapr_create_window(VFIOContainer *container, {int ret;IOMMUMemoryRegion *iommu_mr =IOMMU_MEMORY_REGION (section->mr); -unsigned pagesize =memory_region_iommu_get_min_page_size (iommu_mr); +uint64_t pagesize =memory_region_iommu_get_min_page_size (iommu_mr);unsigned entries, pages;struct vfio_iommu_spapr_tce_create create = { .argsz =sizeof (create) }; +long systempagesize =qemu_getrampagesize (); + +/* +* The host might not support the guest supported IOMMU page size, +* so we will use smaller physical IOMMU pages to back them. +*/ +if (pagesize > systempagesize) { + pagesize = systempagesize; + } + pagesize =1ULL << (63 -clz64 (container->pgsizes & + (pagesize | (pagesize -1 )))); +if (!pagesize) { +error_report ("Host doesn't support page size 0x%" PRIx64 +", the supported mask is 0x%lx" , +memory_region_iommu_get_min_page_size (iommu_mr), + container->pgsizes); +return -EINVAL ; + }/* * FIXME: For VFIO iommu types which have KVM acceleration to
Signature · 1 line
Alexey
Quoted 33 lines · Alexey Kardashevskiy
Quoted 30 lines · David Gibson
Quoted 28 lines · Alexey Kardashevskiy
At the moment the PPC64/pseries guest only supports 4K/64K/16M IOMMU pages and POWER8 CPU supports the exact same set of page size so so far things worked fine.
However POWER9 supports different set of sizes - 4K/64K/2M/1G and the last two - 2M and 1G - are not even allowed in the paravirt interface (RTAS DDW) so we always end up using 64K IOMMU pages, although we could back guest's 16MB IOMMU pages with 2MB pages on the host.
This stores the supported host IOMMU page sizes in VFIOContainer and uses this later when creating a new DMA window. This uses the system page size (64k normally, 2M/16M/1G if hugepages used) as the upper limit of the IOMMU pagesize.
This changes the type of @pagesize to
uint64_tas this is whatmemory_region_iommu_get_min_page_size()returns andclz64()takes.There should be no behavioral changes on platforms other than pseries. The guest will keep using the IOMMU page size selected by the PHB pagesize property as this only changes the underlying hardware TCE table granularity.
Signed-off-by Alexey Kardashevskiy <[email protected]>---
Changes:
v2:
* fixed biggest but smaller page size calculation
* limit IOMMU pagesize to the system pagesize
Quoted 6 lines
Quoted 3 lines
Sorry, this fell of my radar for a bit.
I've now applied it to ppc-for-3.1.
Alex might object that as it does not have his "rb" ;)
Well, if he does I'll yank it from my tree. It won't be going upstream for a while yet.
Quoted 92 lines
Quoted 91 lines
Quoted 90 lines
--- include/hw/vfio/vfio-common.h | 1 + hw/vfio/common.c | 3 +++ hw/vfio/spapr.c | 21 ++++++++++++++++++++- 3 files changed, 24 insertions(+), 1 deletion(-)include/hw/vfio/vfio-common.h +1
-0@@ -73,6 +73,7 @@ typedef struct VFIOContainer {unsigned iommu_type;int error;bool initialized; +unsigned long pgsizes;/* * This assumes the host IOMMU can support only a single * contiguous IOVA window. We may need to generalize that in hw/vfio/common.c +3
-0@@ -1108,6 +1108,7 @@ static int vfio_connect_container(VFIOGroup *group, AddressSpace *as, info.iova_pgsizes =4096 ; }vfio_host_win_add (container,0 , (hwaddr)-1 , info.iova_pgsizes); + container->pgsizes = info.iova_pgsizes; }else if (ioctl (fd,VFIO_CHECK_EXTENSION ,VFIO_SPAPR_TCE_IOMMU ) ||ioctl (fd,VFIO_CHECK_EXTENSION , VFIO_SPAPR_TCE_v2_IOMMU)) {struct vfio_iommu_spapr_tce_info info;@@ -1172,6 +1173,7 @@ static int vfio_connect_container(VFIOGroup *group, AddressSpace *as, }if (v2) { + container->pgsizes = info.ddw.pgsizes;/* * There is a default window in just created container. * To make region_add/del simpler, we better remove this @@ -1186,6 +1188,7 @@ static int vfio_connect_container(VFIOGroup *group, AddressSpace *as, } }else {/* The default table uses 4K pages */ + container->pgsizes =0x1000 ; vfio_host_win_add(container, info.dma32_window_start, info.dma32_window_start + info.dma32_window_size - 1,hw/vfio/spapr.c +20
-1@@ -15,6 +15,7 @@#include "hw/vfio/vfio-common.h" #include "hw/hw.h" +#include "exec/ram_addr.h" #include "qemu/error-report.h" #include "trace.h" @@ -144,9 +145,27 @@ int vfio_spapr_create_window(VFIOContainer *container, {int ret;IOMMUMemoryRegion *iommu_mr =IOMMU_MEMORY_REGION (section->mr); -unsigned pagesize =memory_region_iommu_get_min_page_size (iommu_mr); +uint64_t pagesize =memory_region_iommu_get_min_page_size (iommu_mr);unsigned entries, pages;struct vfio_iommu_spapr_tce_create create = { .argsz =sizeof (create) }; +long systempagesize =qemu_getrampagesize (); + +/* +* The host might not support the guest supported IOMMU page size, +* so we will use smaller physical IOMMU pages to back them. +*/ +if (pagesize > systempagesize) { + pagesize = systempagesize; + } + pagesize =1ULL << (63 -clz64 (container->pgsizes & + (pagesize | (pagesize -1 )))); +if (!pagesize) { +error_report ("Host doesn't support page size 0x%" PRIx64 +", the supported mask is 0x%lx" , +memory_region_iommu_get_min_page_size (iommu_mr), + container->pgsizes); +return -EINVAL ; + }/* * FIXME: For VFIO iommu types which have KVM acceleration to
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson