Message ID | 1502310866-10450-11-git-send-email-tianyu.lan@intel.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On Wed, Aug 09, 2017 at 04:34:11PM -0400, Lan Tianyu wrote: > From: Chao Gao <chao.gao@intel.com> > > If guest is configured to have a vIOMMU, create it during domain construction. > > Signed-off-by: Chao Gao <chao.gao@intel.com> > Signed-off-by: Lan Tianyu <tianyu.lan@intel.com> > --- > tools/libxl/libxl_x86.c | 28 ++++++++++++++++++++++++++++ > 1 file changed, 28 insertions(+) > > diff --git a/tools/libxl/libxl_x86.c b/tools/libxl/libxl_x86.c > index 455f6f0..ace20e5 100644 > --- a/tools/libxl/libxl_x86.c > +++ b/tools/libxl/libxl_x86.c > @@ -341,8 +341,36 @@ int libxl__arch_domain_create(libxl__gc *gc, libxl_domain_config *d_config, > if (d_config->b_info.type == LIBXL_DOMAIN_TYPE_HVM) { I would rather change this check so it's: d_config->b_info.type != LIBXL_DOMAIN_TYPE_PV Is there any reason why PVH guests shouldn't get a vIOMMU? > unsigned long shadow = DIV_ROUNDUP(d_config->b_info.shadow_memkb, > 1024); > + libxl_viommu_info *viommu = &d_config->b_info.viommu; > + > xc_shadow_control(ctx->xch, domid, XEN_DOMCTL_SHADOW_OP_SET_ALLOCATION, > NULL, 0, &shadow, 0, NULL); > + > + /* Check supported capbilities and create viommu */ > + if (viommu->type) { > + uint32_t id; > + uint64_t cap; > + > + if (xc_viommu_query_cap(ctx->xch, domid, viommu->type, &cap)) { > + LOGED(ERROR, domid, "failed to query vIOMMU's capabilities"); > + ret = ERROR_FAIL; > + goto out; > + } > + > + if ((cap & viommu->cap) != viommu->cap) { > + LOGED(ERROR, domid, "vIOMMU: Unsupported cap %"PRIu64, cap); > + ret = ERROR_FAIL; > + goto out; > + } As said earlier, I don't think you should check the capabilities, just try to create the vIOMMU and if the selected capabilities are not supported xc_viommu_create should fail. Roger.
On 2017年08月23日 15:45, Roger Pau Monné wrote: > On Wed, Aug 09, 2017 at 04:34:11PM -0400, Lan Tianyu wrote: >> From: Chao Gao <chao.gao@intel.com> >> >> If guest is configured to have a vIOMMU, create it during domain construction. >> >> Signed-off-by: Chao Gao <chao.gao@intel.com> >> Signed-off-by: Lan Tianyu <tianyu.lan@intel.com> >> --- >> tools/libxl/libxl_x86.c | 28 ++++++++++++++++++++++++++++ >> 1 file changed, 28 insertions(+) >> >> diff --git a/tools/libxl/libxl_x86.c b/tools/libxl/libxl_x86.c >> index 455f6f0..ace20e5 100644 >> --- a/tools/libxl/libxl_x86.c >> +++ b/tools/libxl/libxl_x86.c >> @@ -341,8 +341,36 @@ int libxl__arch_domain_create(libxl__gc *gc, libxl_domain_config *d_config, >> if (d_config->b_info.type == LIBXL_DOMAIN_TYPE_HVM) { > > I would rather change this check so it's: > > d_config->b_info.type != LIBXL_DOMAIN_TYPE_PV > > Is there any reason why PVH guests shouldn't get a vIOMMU? No, but we current only support vIOMMU for HVM guest and don't know how PVH guest enumerates vIOMMU without ACPI DMAR table.
On Wed, Aug 23, 2017 at 04:02:40PM +0800, Lan Tianyu wrote: > On 2017年08月23日 15:45, Roger Pau Monné wrote: > > On Wed, Aug 09, 2017 at 04:34:11PM -0400, Lan Tianyu wrote: > >> From: Chao Gao <chao.gao@intel.com> > >> > >> If guest is configured to have a vIOMMU, create it during domain construction. > >> > >> Signed-off-by: Chao Gao <chao.gao@intel.com> > >> Signed-off-by: Lan Tianyu <tianyu.lan@intel.com> > >> --- > >> tools/libxl/libxl_x86.c | 28 ++++++++++++++++++++++++++++ > >> 1 file changed, 28 insertions(+) > >> > >> diff --git a/tools/libxl/libxl_x86.c b/tools/libxl/libxl_x86.c > >> index 455f6f0..ace20e5 100644 > >> --- a/tools/libxl/libxl_x86.c > >> +++ b/tools/libxl/libxl_x86.c > >> @@ -341,8 +341,36 @@ int libxl__arch_domain_create(libxl__gc *gc, libxl_domain_config *d_config, > >> if (d_config->b_info.type == LIBXL_DOMAIN_TYPE_HVM) { > > > > I would rather change this check so it's: > > > > d_config->b_info.type != LIBXL_DOMAIN_TYPE_PV > > > > Is there any reason why PVH guests shouldn't get a vIOMMU? > > No, but we current only support vIOMMU for HVM guest and don't know how > PVH guest enumerates vIOMMU without ACPI DMAR table. PVH guests have ACPI tables, you just need to add a DMAR table, like you are doing for HVM guests. Roger.
diff --git a/tools/libxl/libxl_x86.c b/tools/libxl/libxl_x86.c index 455f6f0..ace20e5 100644 --- a/tools/libxl/libxl_x86.c +++ b/tools/libxl/libxl_x86.c @@ -341,8 +341,36 @@ int libxl__arch_domain_create(libxl__gc *gc, libxl_domain_config *d_config, if (d_config->b_info.type == LIBXL_DOMAIN_TYPE_HVM) { unsigned long shadow = DIV_ROUNDUP(d_config->b_info.shadow_memkb, 1024); + libxl_viommu_info *viommu = &d_config->b_info.viommu; + xc_shadow_control(ctx->xch, domid, XEN_DOMCTL_SHADOW_OP_SET_ALLOCATION, NULL, 0, &shadow, 0, NULL); + + /* Check supported capbilities and create viommu */ + if (viommu->type) { + uint32_t id; + uint64_t cap; + + if (xc_viommu_query_cap(ctx->xch, domid, viommu->type, &cap)) { + LOGED(ERROR, domid, "failed to query vIOMMU's capabilities"); + ret = ERROR_FAIL; + goto out; + } + + if ((cap & viommu->cap) != viommu->cap) { + LOGED(ERROR, domid, "vIOMMU: Unsupported cap %"PRIu64, cap); + ret = ERROR_FAIL; + goto out; + } + + ret = xc_viommu_create(ctx->xch, domid, viommu->type, + viommu->base_addr, viommu->len, viommu->cap, &id); + if (ret) { + LOGED(ERROR, domid, "create vIOMMU fail"); + ret = ERROR_FAIL; + goto out; + } + } } if (d_config->c_info.type == LIBXL_DOMAIN_TYPE_PV &&