xen/vIOMMU: Add vIOMMU support with irq remapping fucntion of virtual vtd
v2 cover xen/vIOMMU: Add vIOMMU support with irq remapping fucntion of virtual vtd
Change since v1:
1) Fix coding style issues
2) Add definitions for vIOMMU type and capabilities
3) Change vIOMMU kconfig and select vIOMMU default on x86
4) Put vIOMMU creation in libxl__arch_domain_create()
5) Make vIOMMU structure of tool stack more general for both PV and HVM.
Change since RFC v2:
1) Move vvtd.c to drivers/passthrough/vtd directroy.
2) Make vIOMMU always built in on x86
3) Add new boot cmd "viommu" to enable viommu function
4) Fix some code stype issues.
Change since RFC v1:
1) Add Xen virtual IOMMU doc docs/misc/viommu.txt
2) Move vIOMMU hypercall of create/destroy vIOMMU and query
capabilities from dmop to domctl suggested by Paul Durrant. Because these hypercalls can be done in tool stack and more VM mode(E,G PVH or other modes don't use Qemu) can be benefit.
3) Add check of input MMIO address and length.
4) Add iommu_type in vIOMMU hypercall parameter to specify
vendor vIOMMU device model(E,G Intel VTD, AMD or ARM IOMMU. So far only support Intel VTD).
5) Add save and restore support for vvtd
This patchset is to introduce vIOMMU framework and add virtual VTD's interrupt remapping support according "Xen virtual IOMMU high level design doc V3"(https://lists.xenproject.org/archives/html/xen-devel/ 2016-11/msg01391.html).
- vIOMMU framework
New framework provides viommu_ops and help functions to abstract vIOMMU operations(E,G create, destroy, handle irq remapping request and so on). Vendors(Intel, ARM, AMD and son) can implement their vIOMMU callbacks.
- Virtual VTD
We enable irq remapping function and covers both
MSI and IOAPIC interrupts. Don't support post interrupt mode emulation and post interrupt mode enabled on host with virtual VTD. will add later.
Repo:
https://github.com/lantianyu/Xen/tree/xen_viommu_v2
Chao Gao (21):
tools/libxc: Add viommu operations in libxc tools/libacpi: Add DMA remapping reporting (DMAR) ACPI table
structures
tools/libacpi: Add new fields in acpi_config for DMAR table tools/libxl: Add a user configurable parameter to control vIOMMU
attributes
tools/libxl: build DMAR table for a guest with one virtual VTD tools/libxl: create vIOMMU during domain construction x86/hvm: Introduce a emulated VTD for HVM
x86/vvtd: Add MMIO handler for VVTD
x86/vvtd: Set Interrupt Remapping Table Pointer through GCMD x86/vvtd: Process interrupt remapping request
x86/vvtd: decode interrupt attribute from IRTE x86/vioapic: Hook interrupt delivery of vIOAPIC
x86/vvtd: Enable Queued Invalidation through GCMD x86/vvtd: Enable Interrupt Remapping through GCMD x86/vioapic: extend vioapic_get_vector() to support remapping format
RTE
passthrough: move some fields of hvm_gmsi_info to a sub-structure tools/libxc: Add a new interface to bind remapping format msi with
pirq
x86/vmsi: Hook delivering remapping format msi to guest x86/vvtd: Handle interrupt translation faults
x86/vvtd: Add queued invalidation (QI) support
x86/vvtd: save and restore emulated VT-d
Lan Tianyu (4):
DOMCTL: Introduce new DOMCTL commands for vIOMMU support
VIOMMU: Add irq request callback to deal with irq remapping
VIOMMU: Add get irq info callback to convert irq remapping request Xen/doc: Add Xen virtual IOMMU doc
docs/man/xl.cfg.pod.5.in | 34 +- docs/misc/viommu.txt | 139 ++++ tools/libacpi/acpi2_0.h | 61 ++ tools/libacpi/build.c | 57 ++ tools/libacpi/libacpi.h | 9 + tools/libxc/Makefile | 1 + tools/libxc/include/xenctrl.h | 25 + tools/libxc/xc_domain.c | 53 ++ tools/libxc/xc_viommu.c | 81 +++ tools/libxl/libxl_arch.h | 5 + tools/libxl/libxl_dom.c | 36 + tools/libxl/libxl_types.idl | 16 + tools/libxl/libxl_x86.c | 28 + tools/libxl/libxl_x86_acpi.c | 48 ++ tools/xl/xl_parse.c | 66 ++ xen/arch/x86/hvm/irq.c | 11 + xen/arch/x86/hvm/vioapic.c | 32 +- xen/arch/x86/hvm/vmsi.c | 18 +- xen/common/domctl.c | 3 + xen/common/viommu.c | 74 ++ xen/drivers/passthrough/io.c | 190 ++++- xen/drivers/passthrough/vtd/Makefile | 7 +- xen/drivers/passthrough/vtd/iommu.h | 222 +++++- xen/drivers/passthrough/vtd/vtd.h | 6 + xen/drivers/passthrough/vtd/vvtd.c | 1198 ++++++++++++++++++++++++++++++++ xen/include/asm-x86/msi.h | 3 + xen/include/asm-x86/viommu.h | 84 +++ xen/include/public/arch-x86/hvm/save.h | 24 +- xen/include/public/domctl.h | 59 ++ xen/include/xen/hvm/irq.h | 15 +- xen/include/xen/viommu.h | 24 + 31 files changed, 2546 insertions(+), 83 deletions(-) create mode 100644 docs/misc/viommu.txt create mode 100644 tools/libxc/xc_viommu.c create mode 100644 xen/drivers/passthrough/vtd/vvtd.c create mode 100644 xen/include/asm-x86/viommu.h
Signature · 7 lines
1.8.3.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH v2 1/25 DOMCTL: Introduce new DOMCTL commands for vIOMMU support
This patch is to introduce create, destroy and query capabilities command for vIOMMU. vIOMMU layer will deal with requests and call arch vIOMMU ops.
--- xen/common/domctl.c | 3 +++ xen/common/viommu.c | 43 +++++++++++++++++++++++++++++++++++++ xen/include/public/domctl.h | 52 +++++++++++++++++++++++++++++++++++++++++++++ xen/include/xen/viommu.h | 6 ++++++ 4 files changed, 104 insertions(+)
xen/common/domctl.c +3 -0
@@ -1144,6 +1144,9 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)if ( !ret ) copyback =1 ;break ; +case XEN_DOMCTL_viommu_op: + ret =viommu_domctl (d, &op->u.viommu_op, ©back); +break ;default : ret =arch_do_domctl (op, d, u_domctl);
xen/common/viommu.c +43 -0
49 lines not on this page · raw message
xen/include/public/domctl.h +52 -0
70 lines not on this page · raw message
xen/include/xen/viommu.h +6 -0
@@ -49,6 +49,8 @@ extern bool_t opt_viommu;static inline bool viommu_enabled (void ) {return opt_viommu; }int viommu_init_domain (struct domain *d);int viommu_register_type (u64 type,struct viommu_ops * ops); +int viommu_domctl (struct domain *d,struct xen_domctl_viommu_op *op, +bool_t *need_copy);int viommu_setup (void );#else static inline int viommu_init_domain (struct domain *d) {return 0 ; }
@@ -56,6 +58,10 @@ static inline int viommu_register_type(u64 type, struct viommu_ops * ops) {return 0 ; }static inline int __init viommu_setup (void ) {return 0 ; }static inline bool viommu_enabled (void ) {return false; } +static inline int viommu_domctl (struct domain *d, +struct xen_domctl_viommu_op *op, +bool *need_copy) +{ return -ENODEV };#endif #endif /* __XEN_VIOMMU_H__ */
Signature · 7 lines
1.8.3.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH V2 1/25] DOMCTL: Introduce new DOMCTL commands for vIOMMU support
On Wed, Aug 09, 2017 at 04:34:02PM -0400, Lan Tianyu wrote:
[...]
Quoted 6 lines
xen/common/viommu.c +5
-0+int viommu_domctl (struct domain *d,struct xen_domctl_viommu_op *op, +bool *need_copy) +{ +int rc = -EINVAL , ret; +
xen/common/viommu.c static u64 viommu_query_caps(struct domain *d, u64 type) · line 165
Quoted 10 lines
xen/common/viommu.c +10
-0+if ( !viommu_enabled () ) +return rc; + +switch ( op->cmd ) + { +case XEN_DOMCTL_create_viommu: + ret =viommu_create (d, op->u.create_viommu.viommu_type, + op->u.create_viommu.base_address, + op->u.create_viommu.length, + op->u.create_viommu.capabilities);
Please align these with "d" in previous line.
Quoted 1 line
+ if ( ret >= 0 ) {
Coding style is wrong.
xen/common/viommu.c static u64 viommu_query_caps(struct domain *d, u64 type) · line 169
Quoted 3 lines
xen/common/viommu.c +3
-0+ op->u.create_viommu.viommu_id = ret; + *need_copy = true; + rc =0 ;/* return 0 if success */
No need to have that comment.
Quoted 33 lines
xen/common/viommu.c +24
-0+ } +break ; + +case XEN_DOMCTL_destroy_viommu: + rc =viommu_destroy (d, op->u.destroy_viommu.viommu_id); +break ; + +case XEN_DOMCTL_query_viommu_caps: + ret =viommu_query_caps (d, op->u.query_caps.viommu_type); +if ( ret >=0 ) + { + op->u.query_caps.capabilities = ret; + rc =0 ; + } + *need_copy = true; +break ; + +default : +break ; + } + +return rc; +} +int __init viommu_setup (void ) {INIT_LIST_HEAD (&type_list);xen/include/public/domctl.h +0
-0@@ -1149,6 +1149,56 @@ struct xen_domctl_psr_cat_op {typedef struct xen_domctl_psr_cat_op xen_domctl_psr_cat_op_t ;
xen/include/public/domctl.h struct xen_domctl_psr_cat_op { · line 1159
Quoted 10 lines
xen/include/public/domctl.h +8
-0DEFINE_XEN_GUEST_HANDLE (xen_domctl_psr_cat_op_t); +/* vIOMMU helper +* +* vIOMMU interface can be used to create/destroy vIOMMU and +* query vIOMMU capabilities. +*/ + +/* vIOMMU type - specify vendor vIOMMU device model */ +#define VIOMMU_TYPE_INTEL_VTD (1u << 0)
Why use a bit when the types are mutually exclusive? Using a number should be fine?
Quoted 15 lines
xen/include/public/domctl.h +15
-0+ +/* vIOMMU capabilities */ +#define VIOMMU_CAP_IRQ_REMAPPING (1u << 0) + +struct xen_domctl_viommu_op { + uint32_t cmd; +#define XEN_DOMCTL_create_viommu 0 +#define XEN_DOMCTL_destroy_viommu 1 +#define XEN_DOMCTL_query_viommu_caps 2 + union { + struct { + /* IN - vIOMMU type */ + uint64_t viommu_type; + /* + * IN - MMIO base address of vIOMMU. vIOMMU device models
xen/include/public/domctl.h struct xen_domctl_psr_cat_op { · line 1184
Quoted 10 lines
xen/include/public/domctl.h +10
-0+* are in charge of to check base_address and length. +*/ +uint64_t base_address; +/* IN - Length of MMIO region */ +uint64_t length; +/* IN - Capabilities with which we want to create */ +uint64_t capabilities; +/* OUT - vIOMMU identity */ +uint32_t viommu_id; + } create_viommu;
create should be fine.
xen/include/public/domctl.h struct xen_domctl_psr_cat_op { · line 1189
Quoted 5 lines
xen/include/public/domctl.h +5
-0+ +struct { +/* IN - vIOMMU identity */ +uint32_t viommu_id; + } destroy_viommu;
destroy should be fine.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH V2 1/25] DOMCTL: Introduce new DOMCTL commands for vIOMMU support
Hi Wei:
Thanks for your review.
Quoted 9 lines · Wei Liu
Quoted 8 lines · Lan Tianyu
xen/include/public/domctl.h +0
-0@@ -1149,6 +1149,56 @@ struct xen_domctl_psr_cat_op {typedef struct xen_domctl_psr_cat_op xen_domctl_psr_cat_op_t ;DEFINE_XEN_GUEST_HANDLE (xen_domctl_psr_cat_op_t);
Quoted 11 lines
xen/include/public/domctl.h struct xen_domctl_psr_cat_op { · line 1159
Quoted 8 lines
xen/include/public/domctl.h +8
-0+/* vIOMMU helper +* +* vIOMMU interface can be used to create/destroy vIOMMU and +* query vIOMMU capabilities. +*/ + +/* vIOMMU type - specify vendor vIOMMU device model */ +#define VIOMMU_TYPE_INTEL_VTD (1u << 0)Why use a bit when the types are mutually exclusive? Using a number should be fine?
Yes, will update.
Quoted 20 lines
Quoted 20 lines
xen/include/public/domctl.h +19
-0+ +/* vIOMMU capabilities */ +#define VIOMMU_CAP_IRQ_REMAPPING (1u << 0) + +struct xen_domctl_viommu_op { + uint32_t cmd; +#define XEN_DOMCTL_create_viommu 0 +#define XEN_DOMCTL_destroy_viommu 1 +#define XEN_DOMCTL_query_viommu_caps 2 + union { + struct { + /* IN - vIOMMU type */ + uint64_t viommu_type; + /* + * IN - MMIO base address of vIOMMU. vIOMMU device models + * are in charge of to check base_address and length. + */ + uint64_t base_address; + /* IN - Length of MMIO region */
Quoted 9 lines
xen/include/public/domctl.h struct xen_domctl_psr_cat_op { · line 1184
Quoted 6 lines
xen/include/public/domctl.h +6
-0+uint64_t length; +/* IN - Capabilities with which we want to create */ +uint64_t capabilities; +/* OUT - vIOMMU identity */ +uint32_t viommu_id; + } create_viommu;create should be fine.
OK.
Quoted 8 lines
xen/include/public/domctl.h struct xen_domctl_psr_cat_op { · line 1189
Quoted 5 lines
xen/include/public/domctl.h +5
-0+ +struct { +/* IN - vIOMMU identity */ +uint32_t viommu_id; + } destroy_viommu;destroy should be fine.
OK.
Signature · 7 lines
Best regards Tianyu Lan _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH V2 1/25] DOMCTL: Introduce new DOMCTL commands for vIOMMU support
In reply to Lan TianyuQuoted 8 lines · Lan Tianyu
This patch is to introduce create, destroy and query capabilities command for vIOMMU. vIOMMU layer will deal with requests and call arch vIOMMU ops.
Signed-off-by Lan Tianyu <[email protected]>--- xen/common/domctl.c | 3 +++ xen/common/viommu.c | 43 +++++++++++++++++++++++++++++++++++++
I'm confused, I don't see this file in the repo, and the cover letter doesn't mention this being based on top of any other series, where does this viommu.c file come from?
Quoted 9 lines
xen/include/public/domctl.h | 52 +++++++++++++++++++++++++++++++++++++++++++++ xen/include/xen/viommu.h | 6 ++++++ 4 files changed, 104 insertions(+)xen/common/domctl.c +0
-0
xen/common/domctl.c long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) · line 1149
Quoted 6 lines
xen/common/domctl.c +3
-0@@ -1144,6 +1144,9 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)if ( !ret ) copyback =1 ;break ; +case XEN_DOMCTL_viommu_op: + ret =viommu_domctl (d, &op->u.viommu_op, ©back); +break ;
Hm, shouldn't this be protected with #ifdef CONFIG_VIOMMU?
Quoted 7 lines
xen/common/domctl.c +0
-0default : ret =arch_do_domctl (op, d, u_domctl);xen/common/viommu.c +0
-0
xen/common/viommu.c static u64 viommu_query_caps(struct domain *d, u64 type) · line 154
Quoted 7 lines
xen/common/viommu.c +4
-0@@ -148,6 +148,49 @@ static u64 viommu_query_caps(struct domain *d, u64 type)return viommu_type->ops->query_caps (d); } +int viommu_domctl (struct domain *d,struct xen_domctl_viommu_op *op, +bool *need_copy) +{ +int rc = -EINVAL , ret;
Do you really need both ret and rc?
xen/common/viommu.c static u64 viommu_query_caps(struct domain *d, u64 type) · line 156
Quoted 2 lines
xen/common/viommu.c +2
-0+if ( !viommu_enabled () ) +return rc;
EINVAL? Maybe ENODEV?
xen/common/viommu.c static u64 viommu_query_caps(struct domain *d, u64 type) · line 165
Quoted 8 lines
xen/common/viommu.c +8
-0+ +switch ( op->cmd ) + { +case XEN_DOMCTL_create_viommu: + ret =viommu_create (d, op->u.create_viommu.viommu_type, + op->u.create_viommu.base_address, + op->u.create_viommu.length, + op->u.create_viommu.capabilities);
I would rather prefer for viommu_create to simply return an error or 0, and store the viommu_id by passing a pointer parameter to viommu_create, ie:
rc = viommu_create(d, op->u.create_viommu.viommu_type,
op->u.create_viommu.base_address,
op->u.create_viommu.length,
op->u.create_viommu.capabilities,
&op->u.create_viommu.viommu_id);xen/common/viommu.c static u64 viommu_query_caps(struct domain *d, u64 type) · line 166
Quoted 1 line
xen/common/viommu.c +1
-0+if ( ret >=0 ) {
^ coding style
xen/common/viommu.c static u64 viommu_query_caps(struct domain *d, u64 type) · line 178
Quoted 12 lines
xen/common/viommu.c +12
-0+ op->u.create_viommu.viommu_id = ret; + *need_copy = true; + rc =0 ;/* return 0 if success */ + } +break ; + +case XEN_DOMCTL_destroy_viommu: + rc =viommu_destroy (d, op->u.destroy_viommu.viommu_id); +break ; + +case XEN_DOMCTL_query_viommu_caps: + ret =viommu_query_caps (d, op->u.query_caps.viommu_type);
Same here, I would rather pass another parameter and use the return for error only.
xen/common/viommu.c static u64 viommu_query_caps(struct domain *d, u64 type) · line 188
Quoted 10 lines
xen/common/viommu.c +10
-0+if ( ret >=0 ) + { + op->u.query_caps.capabilities = ret; + rc =0 ; + } + *need_copy = true; +break ; + +default : +break ;
Here you should return ENOSYS.
Quoted 14 lines
xen/common/viommu.c +5
-0+ } + +return rc; +} +int __init viommu_setup (void ) {INIT_LIST_HEAD (&type_list);xen/include/public/domctl.h +0
-0@@ -1149,6 +1149,56 @@ struct xen_domctl_psr_cat_op {typedef struct xen_domctl_psr_cat_op xen_domctl_psr_cat_op_t ;
xen/include/public/domctl.h struct xen_domctl_psr_cat_op { · line 1159
Quoted 10 lines
xen/include/public/domctl.h +8
-0DEFINE_XEN_GUEST_HANDLE (xen_domctl_psr_cat_op_t); +/* vIOMMU helper +* +* vIOMMU interface can be used to create/destroy vIOMMU and +* query vIOMMU capabilities. +*/ + +/* vIOMMU type - specify vendor vIOMMU device model */ +#define VIOMMU_TYPE_INTEL_VTD (1u << 0)
If this going to be used to specify the vendor only, it doesn't need to be a bitfield, because it doesn't make sense to specify for example VIOMMU_TYPE_INTEL_VTD | VIOMMU_TYPE_AMD, it's either Intel or AMD. Do you have plans to expand this with other uses? In which case the comment should be fixed.
Quoted 10 lines
xen/include/public/domctl.h +10
-0+ +/* vIOMMU capabilities */ +#define VIOMMU_CAP_IRQ_REMAPPING (1u << 0) + +struct xen_domctl_viommu_op { +uint32_t cmd; +#define XEN_DOMCTL_create_viommu 0 +#define XEN_DOMCTL_destroy_viommu 1 +#define XEN_DOMCTL_query_viommu_caps 2 +union {
xen/include/public/domctl.h struct xen_domctl_psr_cat_op { · line 1179
Quoted 10 lines
xen/include/public/domctl.h +10
-0+struct { +/* IN - vIOMMU type */ +uint64_t viommu_type; +/* +* IN - MMIO base address of vIOMMU. vIOMMU device models +* are in charge of to check base_address and length. +*/ +uint64_t base_address; +/* IN - Length of MMIO region */ +uint64_t length;
It seems weird that you can specify the length, is that something that a user would like to set? Isn't the length of the IOMMU MMIO region fixed by the hardware spec?
Quoted 7 lines
xen/include/public/domctl.h +7
-0+/* IN - Capabilities with which we want to create */ +uint64_t capabilities; +/* OUT - vIOMMU identity */ +uint32_t viommu_id; + } create_viommu; + +struct {
xen/include/public/domctl.h struct xen_domctl_psr_cat_op { · line 1196
Quoted 10 lines
xen/include/public/domctl.h +10
-0+/* IN - vIOMMU identity */ +uint32_t viommu_id; + } destroy_viommu; + +struct { +/* IN - vIOMMU type */ +uint64_t viommu_type; +/* OUT - vIOMMU Capabilities */ +uint64_t capabilities; + } query_caps;
This also seems weird, shouldn't you query the capabilities of an already created vIOMMU, rather than a vIOMMU type? Shouldn't the first field be viommu_id?
Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH V2 1/25] DOMCTL: Introduce new DOMCTL commands for vIOMMU support
Hi Roger:
Thanks for your review.
Quoted 18 lines · Roger Pau Monné
Quoted 8 lines · Lan Tianyu
This patch is to introduce create, destroy and query capabilities command for vIOMMU. vIOMMU layer will deal with requests and call arch vIOMMU ops.
Signed-off-by Lan Tianyu <[email protected]>--- xen/common/domctl.c | 3 +++ xen/common/viommu.c | 43 +++++++++++++++++++++++++++++++++++++I'm confused, I don't see this file in the repo, and the cover letter doesn't mention this being based on top of any other series, where does this
viommu.cfile come from?Quoted 4 lines
xen/include/public/domctl.h | 52 +++++++++++++++++++++++++++++++++++++++++++++ xen/include/xen/viommu.h | 6 ++++++ 4 files changed, 104 insertions(+)
Quoted 14 lines
xen/common/domctl.c long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) · line 1149
Quoted 11 lines
xen/common/domctl.c +3
-0@@ -1144,6 +1144,9 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)if ( !ret ) copyback =1 ;break ; +case XEN_DOMCTL_viommu_op: + ret =viommu_domctl (d, &op->u.viommu_op, ©back); +break ;Hm, shouldn't this be protected with #ifdef
CONFIG_VIOMMU?
Added viommu_domctl() always returns -ENODEV when CONFIG_VIOMMU is unset.
Quoted 17 lines
Quoted 7 lines
xen/common/domctl.c +0
-0default : ret =arch_do_domctl (op, d, u_domctl);xen/common/viommu.c +0
-0xen/common/viommu.c static u64 viommu_query_caps(struct domain *d, u64 type) · line 154
Quoted 7 lines
xen/common/viommu.c +4
-0@@ -148,6 +148,49 @@ static u64 viommu_query_caps(struct domain *d, u64 type)return viommu_type->ops->query_caps (d); } +int viommu_domctl (struct domain *d,struct xen_domctl_viommu_op *op, +bool *need_copy) +{ +int rc = -EINVAL , ret;Do you really need both ret and rc?
Quoted 4 lines
xen/common/viommu.c static u64 viommu_query_caps(struct domain *d, u64 type) · line 156
Quoted 2 lines
xen/common/viommu.c +2
-0+if ( !viommu_enabled () ) +return rc;EINVAL? Maybe ENODEV?
OK.
Quoted 10 lines
xen/common/viommu.c static u64 viommu_query_caps(struct domain *d, u64 type) · line 165
Quoted 9 lines
xen/common/viommu.c +8
-0+ +switch ( op->cmd ) + { +case XEN_DOMCTL_create_viommu: + ret =viommu_create (d, op->u.create_viommu.viommu_type, + op->u.create_viommu.base_address, + op->u.create_viommu.length, + op->u.create_viommu.capabilities);
Quoted 9 lines
I would rather prefer for
viommu_createto simply return an error or 0, and store theviommu_idby passing a pointer parameter toviommu_create, ie:rc = viommu_create(d,
op->u.create_viommu.viommu_type,op->u.create_viommu.base_address, op->u.create_viommu.length, op->u.create_viommu.capabilities, &op->u.create_viommu.viommu_id);
Got it. Will update in the next version.
Quoted 29 lines
xen/common/viommu.c static u64 viommu_query_caps(struct domain *d, u64 type) · line 166
Quoted 1 line
xen/common/viommu.c +1
-0+if ( ret >=0 ) {^ coding style
xen/common/viommu.c static u64 viommu_query_caps(struct domain *d, u64 type) · line 178
Quoted 12 lines
xen/common/viommu.c +12
-0+ op->u.create_viommu.viommu_id = ret; + *need_copy = true; + rc =0 ;/* return 0 if success */ + } +break ; + +case XEN_DOMCTL_destroy_viommu: + rc =viommu_destroy (d, op->u.destroy_viommu.viommu_id); +break ; + +case XEN_DOMCTL_query_viommu_caps: + ret =viommu_query_caps (d, op->u.query_caps.viommu_type);Same here, I would rather pass another parameter and use the return for error only.
xen/common/viommu.c static u64 viommu_query_caps(struct domain *d, u64 type) · line 188
Quoted 10 lines
xen/common/viommu.c +10
-0+if ( ret >=0 ) + { + op->u.query_caps.capabilities = ret; + rc =0 ; + } + *need_copy = true; +break ; + +default : +break ;
Quoted 1 line
Here you should return ENOSYS.
OK.
Quoted 17 lines
Quoted 17 lines
xen/common/viommu.c +5
-0+ } + +return rc; +} +int __init viommu_setup (void ) {INIT_LIST_HEAD (&type_list);xen/include/public/domctl.h +0
-0@@ -1149,6 +1149,56 @@ struct xen_domctl_psr_cat_op {typedef struct xen_domctl_psr_cat_op xen_domctl_psr_cat_op_t ;DEFINE_XEN_GUEST_HANDLE (xen_domctl_psr_cat_op_t);
Quoted 14 lines
xen/include/public/domctl.h struct xen_domctl_psr_cat_op { · line 1159
Quoted 8 lines
xen/include/public/domctl.h +8
-0+/* vIOMMU helper +* +* vIOMMU interface can be used to create/destroy vIOMMU and +* query vIOMMU capabilities. +*/ + +/* vIOMMU type - specify vendor vIOMMU device model */ +#define VIOMMU_TYPE_INTEL_VTD (1u << 0)If this going to be used to specify the vendor only, it doesn't need to be a bitfield, because it doesn't make sense to specify for example
VIOMMU_TYPE_INTEL_VTD|VIOMMU_TYPE_AMD, it's either Intel or AMD. Do you have plans to expand this with other uses? In which case the comment should be fixed.
Wei suggested to replace this bitfield with a number directly. Will update.
Quoted 17 lines
Quoted 17 lines
xen/include/public/domctl.h +16
-0+ +/* vIOMMU capabilities */ +#define VIOMMU_CAP_IRQ_REMAPPING (1u << 0) + +struct xen_domctl_viommu_op { + uint32_t cmd; +#define XEN_DOMCTL_create_viommu 0 +#define XEN_DOMCTL_destroy_viommu 1 +#define XEN_DOMCTL_query_viommu_caps 2 + union { + struct { + /* IN - vIOMMU type */ + uint64_t viommu_type; + /* + * IN - MMIO base address of vIOMMU. vIOMMU device models + * are in charge of to check base_address and length.
Quoted 8 lines
xen/include/public/domctl.h struct xen_domctl_psr_cat_op { · line 1179
Quoted 4 lines
xen/include/public/domctl.h +4
-0+*/ +uint64_t base_address; +/* IN - Length of MMIO region */ +uint64_t length;It seems weird that you can specify the length, is that something that a user would like to set? Isn't the length of the IOMMU MMIO region fixed by the hardware spec?
Different vendor may have different IOMMU register region sizes. (e.g, VTD has one page size for register region). The length field is to make vIOMMU device model not to abuse address space. Some registers' offsets are reported by other register and these offsets are emulated by vIOMMU device model. If it's not necessary, we can remove it and add it when there is real such requirement.
Quoted 14 lines
Quoted 14 lines
xen/include/public/domctl.h +13
-0+/* IN - Capabilities with which we want to create */ +uint64_t capabilities; +/* OUT - vIOMMU identity */ +uint32_t viommu_id; + } create_viommu; + +struct { +/* IN - vIOMMU identity */ +uint32_t viommu_id; + } destroy_viommu; + +struct { +/* IN - vIOMMU type */
Quoted 9 lines
xen/include/public/domctl.h struct xen_domctl_psr_cat_op { · line 1196
Quoted 4 lines
xen/include/public/domctl.h +4
-0+uint64_t viommu_type; +/* OUT - vIOMMU Capabilities */ +uint64_t capabilities; + } query_caps;This also seems weird, shouldn't you query the capabilities of an already created vIOMMU, rather than a vIOMMU type? Shouldn't the first field be
viommu_id?
Query interface here is to check what capabilities the vIOMMU device model specified by viommu_type can support before create vIOMMU (suppose user may select different capabilities). If capabilities returned by query interface doesn't meet user configuration, tool stack should return error. So it just accepts viommu_type.
Signature · 7 lines
Best regards Tianyu Lan _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH V2 1/25] DOMCTL: Introduce new DOMCTL commands for vIOMMU support
Quoted 30 lines · Lan Tianyu
Hi Roger:
Thanks for your review.Quoted 17 lines · Roger Pau Monné
Quoted 16 lines · Lan Tianyu
xen/include/public/domctl.h +16
-0+ +/* vIOMMU capabilities */ +#define VIOMMU_CAP_IRQ_REMAPPING (1u << 0) + +struct xen_domctl_viommu_op { + uint32_t cmd; +#define XEN_DOMCTL_create_viommu 0 +#define XEN_DOMCTL_destroy_viommu 1 +#define XEN_DOMCTL_query_viommu_caps 2 + union { + struct { + /* IN - vIOMMU type */ + uint64_t viommu_type; + /* + * IN - MMIO base address of vIOMMU. vIOMMU device models + * are in charge of to check base_address and length.Quoted 8 lines
xen/include/public/domctl.h struct xen_domctl_psr_cat_op { · line 1179
Quoted 4 lines
xen/include/public/domctl.h +4
-0+*/ +uint64_t base_address; +/* IN - Length of MMIO region */ +uint64_t length;It seems weird that you can specify the length, is that something that a user would like to set? Isn't the length of the IOMMU MMIO region fixed by the hardware spec?
Quoted 6 lines
Different vendor may have different IOMMU register region sizes. (e.g, VTD has one page size for register region). The length field is to make vIOMMU device model not to abuse address space. Some registers' offsets are reported by other register and these offsets are emulated by vIOMMU device model. If it's not necessary, we can remove it and add it when there is real such requirement.
So from my understanding the size of the IOMMU MMIO region is implicit in the IOMMU type that the user chooses. I don't think this field is needed.
Quoted 24 lines
Quoted 14 lines
Quoted 14 lines
xen/include/public/domctl.h +13
-0+/* IN - Capabilities with which we want to create */ +uint64_t capabilities; +/* OUT - vIOMMU identity */ +uint32_t viommu_id; + } create_viommu; + +struct { +/* IN - vIOMMU identity */ +uint32_t viommu_id; + } destroy_viommu; + +struct { +/* IN - vIOMMU type */ Quoted 9 lines
xen/include/public/domctl.h struct xen_domctl_psr_cat_op { · line 1196
Quoted 4 lines
xen/include/public/domctl.h +4
-0+uint64_t viommu_type; +/* OUT - vIOMMU Capabilities */ +uint64_t capabilities; + } query_caps;This also seems weird, shouldn't you query the capabilities of an already created vIOMMU, rather than a vIOMMU type? Shouldn't the first field be
viommu_id?
Quoted 5 lines
Query interface here is to check what capabilities the vIOMMU device model specified by
viommu_typecan support before create vIOMMU (suppose user may select different capabilities). If capabilities returned by query interface doesn't meet user configuration, tool stack should return error. So it just acceptsviommu_type.
I don't think that's needed, if the chosen capabilities are not supported by the selected IOMMU type simply return error in XEN_DOMCTL_create_viommu.
The capabilities of each IOMMU type should be listed in the man page, and the user should select a supported set or else XEN_DOMCTL_create_viommu will fail. Doing the checks both in the toolstack and in XEN_DOMCTL_create_viommu seems pointless and prone to errors.
Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH V2 1/25] DOMCTL: Introduce new DOMCTL commands for vIOMMU support
Quoted 38 lines · Roger Pau Monné
Quoted 30 lines · Lan Tianyu
Hi Roger:
Thanks for your review.Quoted 17 lines · Roger Pau Monné
Quoted 16 lines · Lan Tianyu
xen/include/public/domctl.h +16
-0+ +/* vIOMMU capabilities */ +#define VIOMMU_CAP_IRQ_REMAPPING (1u << 0) + +struct xen_domctl_viommu_op { + uint32_t cmd; +#define XEN_DOMCTL_create_viommu 0 +#define XEN_DOMCTL_destroy_viommu 1 +#define XEN_DOMCTL_query_viommu_caps 2 + union { + struct { + /* IN - vIOMMU type */ + uint64_t viommu_type; + /* + * IN - MMIO base address of vIOMMU. vIOMMU device models + * are in charge of to check base_address and length.Quoted 8 lines
xen/include/public/domctl.h struct xen_domctl_psr_cat_op { · line 1179
Quoted 4 lines
xen/include/public/domctl.h +4
-0+*/ +uint64_t base_address; +/* IN - Length of MMIO region */ +uint64_t length;It seems weird that you can specify the length, is that something that a user would like to set? Isn't the length of the IOMMU MMIO region fixed by the hardware spec?
Quoted 6 lines
Different vendor may have different IOMMU register region sizes. (e.g, VTD has one page size for register region). The length field is to make vIOMMU device model not to abuse address space. Some registers' offsets are reported by other register and these offsets are emulated by vIOMMU device model. If it's not necessary, we can remove it and add it when there is real such requirement.
Quoted 3 lines
So from my understanding the size of the IOMMU MMIO region is implicit in the IOMMU type that the user chooses. I don't think this field is needed.
OK. Will remove it.
Signature · 7 lines
Best regards Tianyu Lan _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH V2 1/25] DOMCTL: Introduce new DOMCTL commands for vIOMMU support
In reply to Roger Pau MonnéHi Roger,
Quoted 38 lines · Roger Pau Monné
Quoted 30 lines · Lan Tianyu
Hi Roger:
Thanks for your review.Quoted 17 lines · Roger Pau Monné
Quoted 16 lines · Lan Tianyu
xen/include/public/domctl.h +16
-0+ +/* vIOMMU capabilities */ +#define VIOMMU_CAP_IRQ_REMAPPING (1u << 0) + +struct xen_domctl_viommu_op { + uint32_t cmd; +#define XEN_DOMCTL_create_viommu 0 +#define XEN_DOMCTL_destroy_viommu 1 +#define XEN_DOMCTL_query_viommu_caps 2 + union { + struct { + /* IN - vIOMMU type */ + uint64_t viommu_type; + /* + * IN - MMIO base address of vIOMMU. vIOMMU device models + * are in charge of to check base_address and length.Quoted 8 lines
xen/include/public/domctl.h struct xen_domctl_psr_cat_op { · line 1179
Quoted 4 lines
xen/include/public/domctl.h +4
-0+*/ +uint64_t base_address; +/* IN - Length of MMIO region */ +uint64_t length;It seems weird that you can specify the length, is that something that a user would like to set? Isn't the length of the IOMMU MMIO region fixed by the hardware spec?
Quoted 6 lines
Different vendor may have different IOMMU register region sizes. (e.g, VTD has one page size for register region). The length field is to make vIOMMU device model not to abuse address space. Some registers' offsets are reported by other register and these offsets are emulated by vIOMMU device model. If it's not necessary, we can remove it and add it when there is real such requirement.
Quoted 3 lines
So from my understanding the size of the IOMMU MMIO region is implicit in the IOMMU type that the user chooses. I don't think this field is needed.
To me, it makes more sense to care both the base and the size rather than only the former.
The toolstack is in charge of the address space and should be aware of the size of everything. This address space may not be static and it makes sense to give this information to Xen and verify we had the same assumption.
Quoted 35 lines
Quoted 25 lines
Quoted 15 lines
Quoted 15 lines
xen/include/public/domctl.h +13
-0+/* IN - Capabilities with which we want to create */ +uint64_t capabilities; +/* OUT - vIOMMU identity */ +uint32_t viommu_id; + } create_viommu; + +struct { +/* IN - vIOMMU identity */ +uint32_t viommu_id; + } destroy_viommu; + +struct { +/* IN - vIOMMU type */ Quoted 9 lines
xen/include/public/domctl.h struct xen_domctl_psr_cat_op { · line 1196
Quoted 4 lines
xen/include/public/domctl.h +4
-0+uint64_t viommu_type; +/* OUT - vIOMMU Capabilities */ +uint64_t capabilities; + } query_caps;This also seems weird, shouldn't you query the capabilities of an already created vIOMMU, rather than a vIOMMU type? Shouldn't the first field be
viommu_id?Quoted 5 lines
Query interface here is to check what capabilities the vIOMMU device model specified by
viommu_typecan support before create vIOMMU (suppose user may select different capabilities). If capabilities returned by query interface doesn't meet user configuration, tool stack should return error. So it just acceptsviommu_type.I don't think that's needed, if the chosen capabilities are not supported by the selected IOMMU type simply return error in
XEN_DOMCTL_create_viommu.
Quoted 5 lines
The capabilities of each IOMMU type should be listed in the man page, and the user should select a supported set or else
XEN_DOMCTL_create_viommuwill fail. Doing the checks both in the toolstack and inXEN_DOMCTL_create_viommuseems pointless and prone to errors.
What if the some capabilities depends on host IOMMU? How are you going to report that to the user?
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH V2 1/25] DOMCTL: Introduce new DOMCTL commands for vIOMMU support
Quoted 45 lines · Julien Grall
Hi Roger,
Quoted 38 lines · Roger Pau Monné
Quoted 30 lines · Lan Tianyu
Hi Roger:
Thanks for your review.Quoted 17 lines · Roger Pau Monné
Quoted 16 lines · Lan Tianyu
xen/include/public/domctl.h +16
-0+ +/* vIOMMU capabilities */ +#define VIOMMU_CAP_IRQ_REMAPPING (1u << 0) + +struct xen_domctl_viommu_op { + uint32_t cmd; +#define XEN_DOMCTL_create_viommu 0 +#define XEN_DOMCTL_destroy_viommu 1 +#define XEN_DOMCTL_query_viommu_caps 2 + union { + struct { + /* IN - vIOMMU type */ + uint64_t viommu_type; + /* + * IN - MMIO base address of vIOMMU. vIOMMU device models + * are in charge of to check base_address and length.Quoted 8 lines
xen/include/public/domctl.h struct xen_domctl_psr_cat_op { · line 1179
Quoted 4 lines
xen/include/public/domctl.h +4
-0+*/ +uint64_t base_address; +/* IN - Length of MMIO region */ +uint64_t length;It seems weird that you can specify the length, is that something that a user would like to set? Isn't the length of the IOMMU MMIO region fixed by the hardware spec?
Quoted 6 lines
Different vendor may have different IOMMU register region sizes. (e.g, VTD has one page size for register region). The length field is to make vIOMMU device model not to abuse address space. Some registers' offsets are reported by other register and these offsets are emulated by vIOMMU device model. If it's not necessary, we can remove it and add it when there is real such requirement.
Quoted 3 lines
So from my understanding the size of the IOMMU MMIO region is implicit in the IOMMU type that the user chooses. I don't think this field is needed.
Quoted 6 lines
To me, it makes more sense to care both the base and the size rather than only the former.
The toolstack is in charge of the address space and should be aware of the size of everything. This address space may not be static and it makes sense to give this information to Xen and verify we had the same assumption.
Does this imply that we will have variable size vIOMMU MMIO regions?
If not the toolstack should know the size of the MMIO region at all times, unless you are running a toolstack version != Xen version, which is not supported.
Quoted 35 lines
Quoted 35 lines
Quoted 25 lines
Quoted 15 lines
Quoted 15 lines
xen/include/public/domctl.h +13
-0+/* IN - Capabilities with which we want to create */ +uint64_t capabilities; +/* OUT - vIOMMU identity */ +uint32_t viommu_id; + } create_viommu; + +struct { +/* IN - vIOMMU identity */ +uint32_t viommu_id; + } destroy_viommu; + +struct { +/* IN - vIOMMU type */ Quoted 9 lines
xen/include/public/domctl.h struct xen_domctl_psr_cat_op { · line 1196
Quoted 4 lines
xen/include/public/domctl.h +4
-0+uint64_t viommu_type; +/* OUT - vIOMMU Capabilities */ +uint64_t capabilities; + } query_caps;This also seems weird, shouldn't you query the capabilities of an already created vIOMMU, rather than a vIOMMU type? Shouldn't the first field be
viommu_id?Quoted 5 lines
Query interface here is to check what capabilities the vIOMMU device model specified by
viommu_typecan support before create vIOMMU (suppose user may select different capabilities). If capabilities returned by query interface doesn't meet user configuration, tool stack should return error. So it just acceptsviommu_type.I don't think that's needed, if the chosen capabilities are not supported by the selected IOMMU type simply return error in
XEN_DOMCTL_create_viommu.
Quoted 8 lines
Quoted 5 lines
The capabilities of each IOMMU type should be listed in the man page, and the user should select a supported set or else
XEN_DOMCTL_create_viommuwill fail. Doing the checks both in the toolstack and inXEN_DOMCTL_create_viommuseems pointless and prone to errors.What if the some capabilities depends on host IOMMU? How are you going to report that to the user?
I would print a message on the hypervisor console, I don't see the value of doing the same check in the toolstack that Xen will also need to do in XEN_DOMCTL_create_viommu.
I would see value on having such a query hypercall once we have an implementation that indeed has different capabilities depending on the hardware, and once a xl command to fetch and print such capabilities is introduced.
As said, the above query is only used to perform the checks done in XEN_DOMCTL_create_viommu on the toolstack.
Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH V2 1/25] DOMCTL: Introduce new DOMCTL commands for vIOMMU support
Hi,
Quoted 46 lines · Roger Pau Monné
Quoted 45 lines · Julien Grall
Hi Roger,
Quoted 41 lines · Roger Pau Monné
Quoted 30 lines · Lan Tianyu
Hi Roger:
Thanks for your review.Quoted 17 lines · Roger Pau Monné
Quoted 16 lines · Lan Tianyu
xen/include/public/domctl.h +16
-0+ +/* vIOMMU capabilities */ +#define VIOMMU_CAP_IRQ_REMAPPING (1u << 0) + +struct xen_domctl_viommu_op { + uint32_t cmd; +#define XEN_DOMCTL_create_viommu 0 +#define XEN_DOMCTL_destroy_viommu 1 +#define XEN_DOMCTL_query_viommu_caps 2 + union { + struct { + /* IN - vIOMMU type */ + uint64_t viommu_type; + /* + * IN - MMIO base address of vIOMMU. vIOMMU device models + * are in charge of to check base_address and length.Quoted 8 lines
xen/include/public/domctl.h struct xen_domctl_psr_cat_op { · line 1179
Quoted 4 lines
xen/include/public/domctl.h +4
-0+*/ +uint64_t base_address; +/* IN - Length of MMIO region */ +uint64_t length;It seems weird that you can specify the length, is that something that a user would like to set? Isn't the length of the IOMMU MMIO region fixed by the hardware spec?
Quoted 6 lines
Different vendor may have different IOMMU register region sizes. (e.g, VTD has one page size for register region). The length field is to make vIOMMU device model not to abuse address space. Some registers' offsets are reported by other register and these offsets are emulated by vIOMMU device model. If it's not necessary, we can remove it and add it when there is real such requirement.
So from my understanding the size of the IOMMU MMIO region is implicit in the IOMMU type that the user chooses. I don't think this field is needed.
Quoted 8 lines
Quoted 6 lines
To me, it makes more sense to care both the base and the size rather than only the former.
The toolstack is in charge of the address space and should be aware of the size of everything. This address space may not be static and it makes sense to give this information to Xen and verify we had the same assumption.
Does this imply that we will have variable size vIOMMU MMIO regions?
There are existing IOMMU with multiple MMIO regions. This is the case of the Nvidia SMMU. Whether we will emulate then is another question. But for completeness, I would use address/size.
Note that we haven't decided on ARM whether we will emulate the IOMMU or use a PV based solution.
Quoted 49 lines
If not the toolstack should know the size of the MMIO region at all times, unless you are running a toolstack version != Xen version, which is not supported.
Quoted 35 lines
Quoted 35 lines
Quoted 25 lines
Quoted 15 lines
Quoted 15 lines
xen/include/public/domctl.h +13
-0+/* IN - Capabilities with which we want to create */ +uint64_t capabilities; +/* OUT - vIOMMU identity */ +uint32_t viommu_id; + } create_viommu; + +struct { +/* IN - vIOMMU identity */ +uint32_t viommu_id; + } destroy_viommu; + +struct { +/* IN - vIOMMU type */ Quoted 9 lines
xen/include/public/domctl.h struct xen_domctl_psr_cat_op { · line 1196
Quoted 4 lines
xen/include/public/domctl.h +4
-0+uint64_t viommu_type; +/* OUT - vIOMMU Capabilities */ +uint64_t capabilities; + } query_caps;This also seems weird, shouldn't you query the capabilities of an already created vIOMMU, rather than a vIOMMU type? Shouldn't the first field be
viommu_id?Quoted 5 lines
Query interface here is to check what capabilities the vIOMMU device model specified by
viommu_typecan support before create vIOMMU (suppose user may select different capabilities). If capabilities returned by query interface doesn't meet user configuration, tool stack should return error. So it just acceptsviommu_type.I don't think that's needed, if the chosen capabilities are not supported by the selected IOMMU type simply return error in
XEN_DOMCTL_create_viommu.Quoted 8 lines
Quoted 5 lines
The capabilities of each IOMMU type should be listed in the man page, and the user should select a supported set or else
XEN_DOMCTL_create_viommuwill fail. Doing the checks both in the toolstack and inXEN_DOMCTL_create_viommuseems pointless and prone to errors.What if the some capabilities depends on host IOMMU? How are you going to report that to the user?
Quoted 8 lines
I would print a message on the hypervisor console, I don't see the value of doing the same check in the toolstack that Xen will also need to do in
XEN_DOMCTL_create_viommu.I would see value on having such a query hypercall once we have an implementation that indeed has different capabilities depending on the hardware, and once a xl command to fetch and print such capabilities is introduced.
Fair enough.
Quoted 2 lines
As said, the above query is only used to perform the checks done in
XEN_DOMCTL_create_viommuon the toolstack.
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH V2 1/25] DOMCTL: Introduce new DOMCTL commands for vIOMMU support
Quoted 56 lines · Julien Grall
Hi,
Quoted 53 lines · Roger Pau Monné
Quoted 51 lines · Julien Grall
Hi Roger,
Quoted 38 lines · Roger Pau Monné
Quoted 30 lines · Lan Tianyu
Hi Roger:
Thanks for your review.Quoted 17 lines · Roger Pau Monné
Quoted 16 lines · Lan Tianyu
(quoted diff) +16
-0+ +/* vIOMMU capabilities */ +#define VIOMMU_CAP_IRQ_REMAPPING (1u << 0) + +struct xen_domctl_viommu_op { + uint32_t cmd; +#define XEN_DOMCTL_create_viommu 0 +#define XEN_DOMCTL_destroy_viommu 1 +#define XEN_DOMCTL_query_viommu_caps 2 + union { + struct { + /* IN - vIOMMU type */ + uint64_t viommu_type; + /* + * IN - MMIO base address of vIOMMU. vIOMMU device models + * are in charge of to check base_address and length.Quoted 8 lines
Review
Quoted 4 lines
(quoted diff) +4
-0+ */ + uint64_t base_address; + /* IN - Length of MMIO region */ + uint64_t length;It seems weird that you can specify the length, is that something that a user would like to set? Isn't the length of the IOMMU MMIO region fixed by the hardware spec?
Quoted 6 lines
Different vendor may have different IOMMU register region sizes. (e.g, VTD has one page size for register region). The length field is to make vIOMMU device model not to abuse address space. Some registers' offsets are reported by other register and these offsets are emulated by vIOMMU device model. If it's not necessary, we can remove it and add it when there is real such requirement.
Quoted 3 lines
So from my understanding the size of the IOMMU MMIO region is implicit in the IOMMU type that the user chooses. I don't think this field is needed.
To me, it makes more sense to care both the base and the size rather than only the former.
The toolstack is in charge of the address space and should be aware of the size of everything. This address space may not be static and it makes sense to give this information to Xen and verify we had the same assumption.
Quoted 5 lines
Quoted 1 line
Does this imply that we will have variable size vIOMMU MMIO regions?
There are existing IOMMU with multiple MMIO regions. This is the case of the Nvidia SMMU. Whether we will emulate then is another question. But for completeness, I would use address/size.
The proposed implementation does not support multiple MMIO regions anyway. I'm not going to oppose to this anymore, but I don't see much value on implementing things just for completeness without having a real use case, specially when this is a domctl interface that is not stable, ie: we can always modify it later on without any issues.
Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v2 2/25 VIOMMU: Add irq request callback to deal with irq remapping
In reply to Lan TianyuThis patch is to add irq request callback for platform implementation to deal with irq remapping request.
--- xen/common/viommu.c | 15 +++++++++ xen/include/asm-x86/viommu.h | 73 ++++++++++++++++++++++++++++++++++++++++++++ xen/include/xen/viommu.h | 9 ++++++ 3 files changed, 97 insertions(+) create mode 100644 xen/include/asm-x86/viommu.h
xen/common/viommu.c +15 -0
@@ -198,6 +198,21 @@ int __init viommu_setup(void)return 0 ; } +int viommu_handle_irq_request (struct domain *d,u32 viommu_id, +struct irq_remapping_request *request) +{ +struct viommu_info *info = &d->viommu; + +if ( viommu_id >= info->nr_viommu + || !info->viommu[viommu_id] ) +return -EINVAL ; + +if ( !info->viommu[viommu_id]->ops->handle_irq_request ) +return -EINVAL ; + +return info->viommu[viommu_id]->ops->handle_irq_request (d, request); +} +/* * Local variables: * mode: C
xen/include/asm-x86/viommu.h new file +73 -0
73 lines not on this page · raw message
xen/include/xen/viommu.h +9 -0
@@ -20,6 +20,8 @@#ifndef __XEN_VIOMMU_H__#define __XEN_VIOMMU_H__ +#include <asm/viommu.h> +#define NR_VIOMMU_PER_DOMAIN 1struct viommu ;
@@ -28,6 +30,8 @@ struct viommu_ops {u64 (*query_caps)(struct domain *d);int (*create)(struct domain *d,struct viommu *viommu);int (*destroy)(struct viommu *viommu); +int (*handle_irq_request)(struct domain *d, +struct irq_remapping_request *request); };struct viommu {
@@ -52,6 +56,8 @@ int viommu_register_type(u64 type, struct viommu_ops * ops);int viommu_domctl (struct domain *d,struct xen_domctl_viommu_op *op,bool_t *need_copy);int viommu_setup (void ); +int viommu_handle_irq_request (struct domain *d,u32 viommu_id, +struct irq_remapping_request *request);#else static inline int viommu_init_domain (struct domain *d) {return 0 ; }static inline int viommu_register_type (u64 type,struct viommu_ops * ops)
@@ -62,6 +68,9 @@ static inline int viommu_domctl(struct domain *d,struct xen_domctl_viommu_op *op, bool *need_copy) { return -ENODEV }; +static inline int viommu_handle_irq_request (struct domain *d,u32 viommu_id, +struct irq_remapping_request *request) +{ return 0 };#endif #endif /* __XEN_VIOMMU_H__ */
Signature · 7 lines
1.8.3.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH V2 2/25] VIOMMU: Add irq request callback to deal with irq remapping
Quoted 16 lines · Lan Tianyu
This patch is to add irq request callback for platform implementation to deal with irq remapping request.
Signed-off-by Lan Tianyu <[email protected]>--- xen/common/viommu.c | 15 +++++++++ xen/include/asm-x86/viommu.h | 73 ++++++++++++++++++++++++++++++++++++++++++++ xen/include/xen/viommu.h | 9 ++++++ 3 files changed, 97 insertions(+) create mode 100644 xen/include/asm-x86/viommu.hxen/common/viommu.c +0
-0
xen/common/viommu.c int __init viommu_setup(void) · line 204
Quoted 7 lines
xen/common/viommu.c +4
-0@@ -198,6 +198,21 @@ int __init viommu_setup(void)return 0 ; } +int viommu_handle_irq_request (struct domain *d,u32 viommu_id, +struct irq_remapping_request *request) +{ +struct viommu_info *info = &d->viommu;
Does this compile? This patch and the previous one don't have viommu added to struct domain.
xen/common/viommu.c int __init viommu_setup(void) · line 207
Quoted 3 lines
xen/common/viommu.c +3
-0+ +if ( viommu_id >= info->nr_viommu + || !info->viommu[viommu_id] )
Join this to previous line?
xen/common/viommu.c int __init viommu_setup(void) · line 208
Quoted 1 line
xen/common/viommu.c +1
-0+return -EINVAL ;
ASSERT(info->viommu[viommu_id]->ops);
For extra safety.
Quoted 28 lines
xen/common/viommu.c +7
-0+ +if ( !info->viommu[viommu_id]->ops->handle_irq_request ) +return -EINVAL ; + +return info->viommu[viommu_id]->ops->handle_irq_request (d, request); +} +/* * Local variables: * mode: C xen/include/asm-x86/viommu.h new file +12
-0@@ -0,0 +1,73 @@ +/* +* include/asm-x86/viommu.h +* +* Copyright (c) 2017 Intel Corporation. +* Author: Lan Tianyu <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
xen/include/asm-x86/viommu.h line 22
Quoted 10 lines
xen/include/asm-x86/viommu.h new file +10
-0+* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* You should have received a copy of the GNU General Public License along with +* this program; If not, see <http://www.gnu.org/licenses/>. +* +*/ +#ifndef __ARCH_X86_VIOMMU_H__ +#define __ARCH_X86_VIOMMU_H__ +
Is a corresponding ARM header needed? Given viommu is common code.
xen/include/asm-x86/viommu.h line 23
Quoted 1 line
xen/include/asm-x86/viommu.h new file +1
-0+#include <xen/viommu.h>
I think you're probably doing it wrong.
It should be that the common header header includes arch header, then the code only uses the common header (I haven't read the rest of your series at this point).
Quoted 9 lines
xen/include/asm-x86/viommu.h new file +9
-0+#include <asm/types.h> + +/* IRQ request type */ +#define VIOMMU_REQUEST_IRQ_MSI 0 +#define VIOMMU_REQUEST_IRQ_APIC 1 + +struct irq_remapping_request +{ + union {
xen/include/asm-x86/viommu.h line 42
Quoted 10 lines
xen/include/asm-x86/viommu.h new file +10
-0+/* MSI */ +struct { +u64 addr; +u32 data; + } msi; +/* Redirection Entry in IOAPIC */ +u64 rte; + } msg; +u16 source_id; +u8 type;
uintXX_t please.
xen/include/asm-x86/viommu.h line 46
Quoted 4 lines
xen/include/asm-x86/viommu.h new file +4
-0+}; + +static inline void irq_request_ioapic_fill (struct irq_remapping_request *req, +uint32_t ioapic_id,uint64_t rte)
Indentation.
xen/include/asm-x86/viommu.h line 55
Quoted 9 lines
xen/include/asm-x86/viommu.h new file +9
-0+{ +ASSERT (req); + req->type =VIOMMU_REQUEST_IRQ_APIC ; + req->source_id = ioapic_id; + req->msg.rte = rte; +} + +static inline void irq_request_msi_fill (struct irq_remapping_request *req, +uint32_t source_id,uint64_t addr,uint32_t data)
Indentation.
Quoted 23 lines
xen/include/asm-x86/viommu.h new file +18
-0+{ +ASSERT (req); + req->type =VIOMMU_REQUEST_IRQ_MSI ; + req->source_id = source_id; + req->msg.msi.addr = addr; + req->msg.msi.data = data; +} + +#endif /* __ARCH_X86_VIOMMU_H__ */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* End: +*/ xen/include/xen/viommu.h +0
-0
xen/include/xen/viommu.h line 24
Quoted 5 lines
xen/include/xen/viommu.h +2
-0@@ -20,6 +20,8 @@#ifndef __XEN_VIOMMU_H__#define __XEN_VIOMMU_H__ +#include <asm/viommu.h> +
Circular inclusion? Note the #include <xen/viommu.h> some lines above.
Quoted 22 lines
xen/include/xen/viommu.h +4
-0#define NR_VIOMMU_PER_DOMAIN 1struct viommu ;@@ -28,6 +30,8 @@ struct viommu_ops {u64 (*query_caps)(struct domain *d);int (*create)(struct domain *d,struct viommu *viommu);int (*destroy)(struct viommu *viommu); +int (*handle_irq_request)(struct domain *d, +struct irq_remapping_request *request); };struct viommu {@@ -52,6 +56,8 @@ int viommu_register_type(u64 type, struct viommu_ops * ops);int viommu_domctl (struct domain *d,struct xen_domctl_viommu_op *op,bool_t *need_copy);int viommu_setup (void ); +int viommu_handle_irq_request (struct domain *d,u32 viommu_id, +struct irq_remapping_request *request);#else static inline int viommu_init_domain (struct domain *d) {return 0 ; }static inline int viommu_register_type (u64 type,struct viommu_ops * ops)
xen/include/xen/viommu.h static inline int viommu_domctl(struct domain *d, · line 73
Quoted 6 lines
xen/include/xen/viommu.h +3
-0@@ -62,6 +68,9 @@ static inline int viommu_domctl(struct domain *d,struct xen_domctl_viommu_op *op, bool *need_copy) { return -ENODEV }; +static inline int viommu_handle_irq_request (struct domain *d,u32 viommu_id, +struct irq_remapping_request *request) +{ return 0 };
This should fail.
Quoted 6 lines
xen/include/xen/viommu.h +0
-0#endif #endif /* __XEN_VIOMMU_H__ */ Signature · 1 line
1.8.3.1
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v2 1/25 VIOMMU: Add vIOMMU helper functions to create, destroy and query capabilities
This patch is to introduct an abstract layer for arch vIOMMU implementation to deal with requests from dom0. Arch vIOMMU code needs to provide callback to perform create, destroy and query capabilities operation.
--- xen/arch/x86/Kconfig | 1 + xen/arch/x86/setup.c | 1 + xen/common/Kconfig | 3 + xen/common/Makefile | 1 + xen/common/domain.c | 3 + xen/common/viommu.c | 165 +++++++++++++++++++++++++++++++++++++++++++++++ xen/include/xen/sched.h | 2 + xen/include/xen/viommu.h | 71 ++++++++++++++++++++ 8 files changed, 247 insertions(+) create mode 100644 xen/common/viommu.c create mode 100644 xen/include/xen/viommu.h
xen/arch/x86/Kconfig +1 -0
@@ -23,6 +23,7 @@ config X86 select HAS_PDX select NUMA select VGA + select VIOMMU config ARCH_DEFCONFIG string
xen/arch/x86/setup.c +1 -0
@@ -1513,6 +1513,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)early_msi_init ();iommu_setup ();/* setup iommu if available */ +viommu_setup ();smp_prepare_cpus (max_cpus);
xen/common/Kconfig +3 -0
@@ -49,6 +49,9 @@ config HAS_CHECKPOLICY string option env="XEN_HAS_CHECKPOLICY" +config VIOMMU + bool + config KEXEC bool "kexec support" default y
xen/common/Makefile +1 -0
@@ -56,6 +56,7 @@ obj-y += time.o obj-y += timer.o obj-y += trace.o obj-y += version.o +obj-$(CONFIG_VIOMMU) += viommu.o obj-y += virtual_region.o obj-y += vm_event.o obj-y += vmap.o
xen/common/domain.c +3 -0
@@ -396,6 +396,9 @@ struct domain *domain_create(domid_t domid, unsigned int domcr_flags,spin_unlock (&domlist_update_lock); } +if ( (err =viommu_init_domain (d)) !=0 ) + goto fail; +return d; fail:
xen/common/viommu.c new file +165 -0
165 lines not on this page · raw message
xen/include/xen/sched.h +2 -0
@@ -21,6 +21,7 @@#include <xen/perfc.h> #include <asm/atomic.h> #include <xen/wait.h> +#include <xen/viommu.h> #include <public/xen.h> #include <public/domctl.h> #include <public/sysctl.h>
@@ -477,6 +478,7 @@ struct domain/* vNUMA topology accesses are protected by rwlock. */ rwlock_t vnuma_rwlock;struct vnuma_info *vnuma; +struct viommu_info viommu;/* Common monitor options */ struct {
xen/include/xen/viommu.h new file +71 -0
71 lines not on this page · raw message
Signature · 7 lines
1.8.3.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH V2 1/25] VIOMMU: Add vIOMMU helper functions to create, destroy and query capabilities
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 18.08.17 at 02:22, <[email protected]> wrote:
This patch is to introduct an abstract layer for arch vIOMMU implementation to deal with requests from dom0. Arch vIOMMU code needs to provide callback to perform create, destroy and query capabilities operation.
Signed-off-by Lan Tianyu <[email protected]>
What is this? It looks to be a standalone patch when there was a V2 series a couple of days ago with 1/25 titled "DOMCTL:
Introduce new DOMCTL commands for vIOMMU support". I'm confused.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH V2 1/25] VIOMMU: Add vIOMMU helper functions to create, destroy and query capabilities
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 18.08.17 at 02:22, <[email protected]> wrote:
This patch is to introduct an abstract layer for arch vIOMMU implementation to deal with requests from dom0. Arch vIOMMU code needs to provide callback to perform create, destroy and query capabilities operation.
Quoted 9 lines
Quoted 1 line
Signed-off-by Lan Tianyu <[email protected]>What is this? It looks to be a standalone patch when there was a V2 series a couple of days ago with 1/25 titled "DOMCTL:
Introduce new DOMCTL commands for vIOMMU support". I'm confused.Jan
Hi Jan:
Sorry. Missed this patch in this patchset and this should be the first
one. I will send v3 with some fixs.
Signature · 7 lines
Best regards Tianyu Lan _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH V2 1/25] VIOMMU: Add vIOMMU helper functions to create, destroy and query capabilities
In reply to Lan Tianyuxen/common/domain.c struct domain *domain_create(domid_t domid, unsigned int domcr_flags, · line 401
Quoted 11 lines · Lan Tianyu
xen/common/domain.c +3
-0@@ -396,6 +396,9 @@ struct domain *domain_create(domid_t domid, unsigned int domcr_flags,spin_unlock (&domlist_update_lock); } +if ( (err =viommu_init_domain (d)) !=0 ) + goto fail; +
Where is the code to destroy viommu during domain destruction?
I suppose you will need a viommu_destroy_domain and call it somewhere in complete_domain_destroy.
xen/common/domain.c struct domain *domain_create(domid_t domid, unsigned int domcr_flags,
Quoted 8 lines
xen/common/domain.c +8
-0+ +#include <xen/sched.h> +#include <xen/spinlock.h> +#include <xen/types.h> +#include <xen/viommu.h> + +bool __read_mostly opt_viommu; +boolean_param ("viommu" , opt_viommu);
Missing patch to xen command line option doc.
xen/common/domain.c
Quoted 6 lines
xen/common/domain.c +6
-0+ +static spinlock_t type_list_lock; +static struct list_head type_list; + +struct viommu_type { +u64 type;
uintXX_t here and in all other places please.
[...]
Quoted 4 lines
xen/common/domain.c +4
-0+ +static int viommu_create (struct domain *d,u64 type,u64 base_address, +u64 length,u64 caps) +{
xen/common/domain.c
Quoted 10 lines
xen/common/domain.c +10
-0+struct viommu_info *info = &d->viommu; +struct viommu *viommu; +struct viommu_type *viommu_type =NULL ; +int rc; + + viommu_type =viommu_get_type (type); +if ( !viommu_type ) +return -EINVAL ; + + if ( info->nr_viommu >= NR_VIOMMU_PER_DOMAIN
E2BIG for this?
Quoted 7 lines
xen/common/domain.c +7
-0+ || !viommu_type->ops || !viommu_type->ops->create ) +return -EINVAL ; + + viommu = xzalloc(struct viommu); +if ( !viommu ) +return -ENOMEM ; +
[...]
Quoted 13 lines
xen/include/xen/sched.h +1
-0@@ -21,6 +21,7 @@#include <xen/perfc.h> #include <asm/atomic.h> #include <xen/wait.h> +#include <xen/viommu.h> #include <public/xen.h> #include <public/domctl.h> #include <public/sysctl.h>
xen/include/xen/sched.h struct domain · line 480
Quoted 3 lines
xen/include/xen/sched.h +0
-0@@ -477,6 +478,7 @@ struct domain/* vNUMA topology accesses are protected by rwlock. */ rwlock_t vnuma_rwlock;struct vnuma_info *vnuma;
Please add a new line here.
Quoted 43 lines
xen/include/xen/sched.h +1
-0+struct viommu_info viommu;/* Common monitor options */ struct {xen/include/xen/viommu.h new file +33
-0@@ -0,0 +1,71 @@ +/* +* include/xen/viommu.h +* +* Copyright (c) 2017, Intel Corporation +* Author: Lan Tianyu <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* You should have received a copy of the GNU General Public License along with +* this program; If not, see <http://www.gnu.org/licenses/>. +* +*/ +#ifndef __XEN_VIOMMU_H__ +#define __XEN_VIOMMU_H__ + +#define NR_VIOMMU_PER_DOMAIN 1 + +struct viommu ; + +struct viommu_ops { +u64 (*query_caps)(struct domain *d); +int (*create)(struct domain *d,struct viommu *viommu); +int (*destroy)(struct viommu *viommu); +}; + +struct viommu {
xen/include/xen/viommu.h line 43
Quoted 10 lines
xen/include/xen/viommu.h new file +10
-0+u64 base_address; +u64 length; +u64 caps; +u32 viommu_id; +const struct viommu_ops *ops; +void *priv; +}; + +struct viommu_info { +u32 nr_viommu;
unsigned int
xen/include/xen/viommu.h line 48
Quoted 5 lines
xen/include/xen/viommu.h new file +5
-0+struct viommu *viommu[NR_VIOMMU_PER_DOMAIN ];/* viommu array*/ +}; + +#ifdef CONFIG_VIOMMU +extern bool_t opt_viommu;
bool
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH V2 1/25] VIOMMU: Add vIOMMU helper functions to create, destroy and query capabilities
In reply to Lan TianyuQuoted 106 lines · Lan Tianyu
This patch is to introduct an abstract layer for arch vIOMMU implementation to deal with requests from dom0. Arch vIOMMU code needs to provide callback to perform create, destroy and query capabilities operation.
Signed-off-by Lan Tianyu <[email protected]>--- xen/arch/x86/Kconfig | 1 + xen/arch/x86/setup.c | 1 + xen/common/Kconfig | 3 + xen/common/Makefile | 1 + xen/common/domain.c | 3 + xen/common/viommu.c | 165 +++++++++++++++++++++++++++++++++++++++++++++++ xen/include/xen/sched.h | 2 + xen/include/xen/viommu.h | 71 ++++++++++++++++++++ 8 files changed, 247 insertions(+) create mode 100644 xen/common/viommu.c create mode 100644 xen/include/xen/viommu.hxen/arch/x86/Kconfig +1
-0@@ -23,6 +23,7 @@ config X86 select HAS_PDX select NUMA select VGA + select VIOMMU config ARCH_DEFCONFIG stringxen/arch/x86/setup.c +1
-0@@ -1513,6 +1513,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)early_msi_init ();iommu_setup ();/* setup iommu if available */ +viommu_setup ();smp_prepare_cpus (max_cpus);xen/common/Kconfig +3
-0@@ -49,6 +49,9 @@ config HAS_CHECKPOLICY string option env="XEN_HAS_CHECKPOLICY" +config VIOMMU + bool + config KEXEC bool "kexec support" default yxen/common/Makefile +1
-0@@ -56,6 +56,7 @@ obj-y += time.o obj-y += timer.o obj-y += trace.o obj-y += version.o +obj-$(CONFIG_VIOMMU) += viommu.o obj-y += virtual_region.o obj-y += vm_event.o obj-y += vmap.oxen/common/domain.c +3
-0@@ -396,6 +396,9 @@ struct domain *domain_create(domid_t domid, unsigned int domcr_flags,spin_unlock (&domlist_update_lock); } +if ( (err =viommu_init_domain (d)) !=0 ) + goto fail; +return d; fail:xen/common/viommu.c new file +18
-0@@ -0,0 +1,165 @@ +/* +* common/viommu.c +* +* Copyright (c) 2017 Intel Corporation +* Author: Lan Tianyu <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* You should have received a copy of the GNU General Public License along with +* this program; If not, see <http://www.gnu.org/licenses/>. +*/
xen/common/viommu.c line 28
Quoted 10 lines
xen/common/viommu.c new file +10
-0+ +#include <xen/sched.h> +#include <xen/spinlock.h> +#include <xen/types.h> +#include <xen/viommu.h> + +bool __read_mostly opt_viommu; +boolean_param ("viommu" , opt_viommu); + +static spinlock_t type_list_lock;
static DEFINE_SPINLOCK(type_list_lock);
xen/common/viommu.c line 29
Quoted 1 line
xen/common/viommu.c new file +1
-0+static struct list_head type_list;
static LIST_HEAD(type_list);
xen/common/viommu.c line 41
Quoted 12 lines
xen/common/viommu.c new file +12
-0+ +struct viommu_type { +u64 type; +struct viommu_ops *ops; +struct list_head node; +}; + +int viommu_init_domain (struct domain *d) +{ + d->viommu.nr_viommu =0 ; +return 0 ; +}
If you don't use the viommu_info struct you can also get rid of this. The array entries will point to NULL which can be used to signal not initialized.
Quoted 15 lines
xen/common/viommu.c new file +15
-0+ +static struct viommu_type *viommu_get_type (u64 type) +{ +struct viommu_type *viommu_type =NULL ; + +spin_lock (&type_list_lock); +list_for_each_entry ( viommu_type, &type_list, node ) + { +if ( viommu_type->type == type ) + { +spin_unlock (&type_list_lock); +return viommu_type; + } + } +spin_unlock (&type_list_lock);
xen/common/viommu.c line 66
Quoted 10 lines
xen/common/viommu.c new file +10
-0+ +return NULL ; +} + +int viommu_register_type (u64 type,struct viommu_ops * ops) +{ +struct viommu_type *viommu_type =NULL ; + +if ( !viommu_enabled () ) +return -EINVAL ;
ENODEV is maybe better here.
Quoted 7 lines
xen/common/viommu.c new file +7
-0+ +if (viommu_get_type (type) ) +return -EEXIST ; + + viommu_type = xzalloc(struct viommu_type); +if ( !viommu_type ) +return -ENOMEM ;
xen/common/viommu.c line 83
Quoted 10 lines
xen/common/viommu.c new file +10
-0+ + viommu_type->type = type; + viommu_type->ops = ops; + +spin_lock (&type_list_lock); +list_add_tail (&viommu_type->node, &type_list); +spin_unlock (&type_list_lock); + +return 0 ; +}
Hm, I haven't seen the usage of this function, but from the looks of it it seems like you want to use something similar to what's used by the scheduler in order to register vIOMMU types.
See the logic around REGISTER_SCHEDULER in xen/sched-if.h.
Quoted 5 lines
xen/common/viommu.c new file +5
-0+ +static int viommu_create (struct domain *d,u64 type,u64 base_address, +u64 length,u64 caps) +{ +struct viommu_info *info = &d->viommu;
xen/common/viommu.c line 98
Quoted 10 lines
xen/common/viommu.c new file +10
-0+struct viommu *viommu; +struct viommu_type *viommu_type =NULL ; +int rc; + + viommu_type =viommu_get_type (type); +if ( !viommu_type ) +return -EINVAL ; + +if ( info->nr_viommu >=NR_VIOMMU_PER_DOMAIN + || !viommu_type->ops || !viommu_type->ops->create )
^ aligned with "info" above.
Quoted 26 lines
xen/common/viommu.c new file +26
-0+return -EINVAL ; + + viommu = xzalloc(struct viommu); +if ( !viommu ) +return -ENOMEM ; + + viommu->base_address = base_address; + viommu->length = length; + viommu->caps = caps; + viommu->ops = viommu_type->ops; + viommu->viommu_id = info->nr_viommu; + + info->viommu[info->nr_viommu] = viommu; + info->nr_viommu++; + + rc = viommu->ops->create (d, viommu); +if ( rc <0 ) + { +xfree (viommu); + info->nr_viommu--; + info->viommu[info->nr_viommu] =NULL ; +return rc; + } + +return viommu->viommu_id; +}
xen/common/viommu.c line 134
Quoted 10 lines
xen/common/viommu.c new file +10
-0+ +static int viommu_destroy (struct domain *d,u32 viommu_id) +{ +struct viommu_info *info = &d->viommu; + +if ( viommu_id >= info->nr_viommu || !info->viommu[viommu_id] ) +return -EINVAL ; + +if ( info->viommu[viommu_id]->ops->destroy (info->viommu[viommu_id]) ) +return -EFAULT ;
You should return the return the original return value from the "destroy" function pointer, instead of hardcoding it to EFAULT.
Quoted 12 lines
xen/common/viommu.c new file +12
-0+ +xfree (info->viommu[viommu_id]); + info->viommu[viommu_id] =NULL ; +return 0 ; +} + +static u64 viommu_query_caps (struct domain *d,u64 type) +{ +struct viommu_type *viommu_type =viommu_get_type (type); + +if ( !viommu_type ) +return -EINVAL ;
xen/common/viommu.c line 156
Quoted 10 lines
xen/common/viommu.c new file +10
-0+ +return viommu_type->ops->query_caps (d); +} + +int __init viommu_setup (void ) +{ +INIT_LIST_HEAD (&type_list); +spin_lock_init (&type_list_lock); +return 0 ; +}
With the suggested changes to init type_list and type_list_lock at definition time you can get rid of viommu_setup.
Quoted 59 lines
xen/common/viommu.c new file +9
-0+ +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* End: +*/ xen/include/xen/sched.h +2
-0@@ -21,6 +21,7 @@#include <xen/perfc.h> #include <asm/atomic.h> #include <xen/wait.h> +#include <xen/viommu.h> #include <public/xen.h> #include <public/domctl.h> #include <public/sysctl.h> @@ -477,6 +478,7 @@ struct domain/* vNUMA topology accesses are protected by rwlock. */ rwlock_t vnuma_rwlock;struct vnuma_info *vnuma; +struct viommu_info viommu;/* Common monitor options */ struct {xen/include/xen/viommu.h new file +24
-0@@ -0,0 +1,71 @@ +/* +* include/xen/viommu.h +* +* Copyright (c) 2017, Intel Corporation +* Author: Lan Tianyu <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* You should have received a copy of the GNU General Public License along with +* this program; If not, see <http://www.gnu.org/licenses/>. +* +*/ +#ifndef __XEN_VIOMMU_H__ +#define __XEN_VIOMMU_H__ + +#define NR_VIOMMU_PER_DOMAIN 1 +
xen/include/xen/viommu.h line 34
Quoted 10 lines
xen/include/xen/viommu.h new file +10
-0+struct viommu ; + +struct viommu_ops { +u64 (*query_caps)(struct domain *d); +int (*create)(struct domain *d,struct viommu *viommu); +int (*destroy)(struct viommu *viommu); +}; + +struct viommu { +u64 base_address;
All those should use uint*_t instead of the u* types.
xen/include/xen/viommu.h line 44
Quoted 10 lines
xen/include/xen/viommu.h new file +10
-0+u64 length; +u64 caps; +u32 viommu_id; +const struct viommu_ops *ops; +void *priv; +}; + +struct viommu_info { +u32 nr_viommu; +struct viommu *viommu[NR_VIOMMU_PER_DOMAIN ];/* viommu array*/
Seems kind of pointless to have a nr_viommu field when the array is not dynamic, you could just use ARRAY_SIZE. And then in the domain struct you could directly add an array of viommu structs, getting rid of viommu_info altogether.
xen/include/xen/viommu.h line 48
Quoted 4 lines
xen/include/xen/viommu.h new file +4
-0+}; + +#ifdef CONFIG_VIOMMU +extern bool_t opt_viommu;
bool
xen/include/xen/viommu.h line 49
Quoted 1 line
xen/include/xen/viommu.h new file +1
-0+static inline bool viommu_enabled (void ) {return opt_viommu; }
I think those static inline functions should also follow the coding standard.
Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH V2 1/25] VIOMMU: Add vIOMMU helper functions to create, destroy and query capabilities
Quoted 124 lines · Roger Pau Monné
Quoted 106 lines · Lan Tianyu
This patch is to introduct an abstract layer for arch vIOMMU implementation to deal with requests from dom0. Arch vIOMMU code needs to provide callback to perform create, destroy and query capabilities operation.
Signed-off-by Lan Tianyu <[email protected]>--- xen/arch/x86/Kconfig | 1 + xen/arch/x86/setup.c | 1 + xen/common/Kconfig | 3 + xen/common/Makefile | 1 + xen/common/domain.c | 3 + xen/common/viommu.c | 165 +++++++++++++++++++++++++++++++++++++++++++++++ xen/include/xen/sched.h | 2 + xen/include/xen/viommu.h | 71 ++++++++++++++++++++ 8 files changed, 247 insertions(+) create mode 100644 xen/common/viommu.c create mode 100644 xen/include/xen/viommu.hxen/arch/x86/Kconfig +1
-0@@ -23,6 +23,7 @@ config X86 select HAS_PDX select NUMA select VGA + select VIOMMU config ARCH_DEFCONFIG stringxen/arch/x86/setup.c +1
-0@@ -1513,6 +1513,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)early_msi_init ();iommu_setup ();/* setup iommu if available */ +viommu_setup ();smp_prepare_cpus (max_cpus);xen/common/Kconfig +3
-0@@ -49,6 +49,9 @@ config HAS_CHECKPOLICY string option env="XEN_HAS_CHECKPOLICY" +config VIOMMU + bool + config KEXEC bool "kexec support" default yxen/common/Makefile +1
-0@@ -56,6 +56,7 @@ obj-y += time.o obj-y += timer.o obj-y += trace.o obj-y += version.o +obj-$(CONFIG_VIOMMU) += viommu.o obj-y += virtual_region.o obj-y += vm_event.o obj-y += vmap.oxen/common/domain.c +3
-0@@ -396,6 +396,9 @@ struct domain *domain_create(domid_t domid, unsigned int domcr_flags,spin_unlock (&domlist_update_lock); } +if ( (err =viommu_init_domain (d)) !=0 ) + goto fail; +return d; fail:xen/common/viommu.c new file +18
-0@@ -0,0 +1,165 @@ +/* +* common/viommu.c +* +* Copyright (c) 2017 Intel Corporation +* Author: Lan Tianyu <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* You should have received a copy of the GNU General Public License along with +* this program; If not, see <http://www.gnu.org/licenses/>. +*/ xen/common/viommu.c line 28
Quoted 10 lines
xen/common/viommu.c new file +10
-0+ +#include <xen/sched.h> +#include <xen/spinlock.h> +#include <xen/types.h> +#include <xen/viommu.h> + +bool __read_mostly opt_viommu; +boolean_param ("viommu" , opt_viommu); + +static spinlock_t type_list_lock;static
DEFINE_SPINLOCK(type_list_lock);xen/common/viommu.c line 29
Quoted 1 line
xen/common/viommu.c new file +1
-0+static struct list_head type_list;static
LIST_HEAD(type_list);
Quoted 16 lines
xen/common/viommu.c line 41
Quoted 12 lines
xen/common/viommu.c new file +12
-0+ +struct viommu_type { +u64 type; +struct viommu_ops *ops; +struct list_head node; +}; + +int viommu_init_domain (struct domain *d) +{ + d->viommu.nr_viommu =0 ; +return 0 ; +}If you don't use the
viommu_infostruct you can also get rid of this. The array entries will point to NULL which can be used to signal not initialized.
Yes, just check the memory for struct domain will be set to all zero after allocation.
Quoted 20 lines
Quoted 20 lines
xen/common/viommu.c new file +19
-0+ +static struct viommu_type *viommu_get_type (u64 type) +{ +struct viommu_type *viommu_type =NULL ; + +spin_lock (&type_list_lock); +list_for_each_entry ( viommu_type, &type_list, node ) + { +if ( viommu_type->type == type ) + { +spin_unlock (&type_list_lock); +return viommu_type; + } + } +spin_unlock (&type_list_lock); + +return NULL ; +} +
Quoted 8 lines
xen/common/viommu.c line 66
Quoted 6 lines
xen/common/viommu.c new file +6
-0+int viommu_register_type (u64 type,struct viommu_ops * ops) +{ +struct viommu_type *viommu_type =NULL ; + +if ( !viommu_enabled () ) +return -EINVAL ;ENODEV is maybe better here.
Will update.
Quoted 23 lines
Quoted 8 lines
xen/common/viommu.c new file +7
-0+ +if (viommu_get_type (type) ) +return -EEXIST ; + + viommu_type = xzalloc(struct viommu_type); +if ( !viommu_type ) +return -ENOMEM ;xen/common/viommu.c line 83
Quoted 10 lines
xen/common/viommu.c new file +10
-0+ + viommu_type->type = type; + viommu_type->ops = ops; + +spin_lock (&type_list_lock); +list_add_tail (&viommu_type->node, &type_list); +spin_unlock (&type_list_lock); + +return 0 ; +}Hm, I haven't seen the usage of this function, but from the looks of it it seems like you want to use something similar to what's used by the scheduler in order to register vIOMMU types.
Quoted 1 line
See the logic around
REGISTER_SCHEDULERinxen/sched-if.h.
Each vIOMMU devel model needs to call viommu_register_type() to register its vIOMMU type. Tool stack will pass viommu_type and vIOMMU abstract layer call vendor's vIOMMU callback to query vIOMMU capabilities, create and destroy() vIOMMU. We just need to maintain type list. REGISTER_SCHEDULER seems to heavy which reserve a scheduler array in the Xen data section.
Quoted 48 lines
Quoted 6 lines
xen/common/viommu.c new file +5
-0+ +static int viommu_create (struct domain *d,u64 type,u64 base_address, +u64 length,u64 caps) +{ +struct viommu_info *info = &d->viommu;xen/common/viommu.c line 98
Quoted 10 lines
xen/common/viommu.c new file +10
-0+struct viommu *viommu; +struct viommu_type *viommu_type =NULL ; +int rc; + + viommu_type =viommu_get_type (type); +if ( !viommu_type ) +return -EINVAL ; + +if ( info->nr_viommu >=NR_VIOMMU_PER_DOMAIN + || !viommu_type->ops || !viommu_type->ops->create )^ aligned with "info" above.
Quoted 31 lines
xen/common/viommu.c new file +31
-0+return -EINVAL ; + + viommu = xzalloc(struct viommu); +if ( !viommu ) +return -ENOMEM ; + + viommu->base_address = base_address; + viommu->length = length; + viommu->caps = caps; + viommu->ops = viommu_type->ops; + viommu->viommu_id = info->nr_viommu; + + info->viommu[info->nr_viommu] = viommu; + info->nr_viommu++; + + rc = viommu->ops->create (d, viommu); +if ( rc <0 ) + { +xfree (viommu); + info->nr_viommu--; + info->viommu[info->nr_viommu] =NULL ; +return rc; + } + +return viommu->viommu_id; +} + +static int viommu_destroy (struct domain *d,u32 viommu_id) +{ +struct viommu_info *info = &d->viommu; +
Quoted 8 lines
xen/common/viommu.c line 134
Quoted 5 lines
xen/common/viommu.c new file +5
-0+if ( viommu_id >= info->nr_viommu || !info->viommu[viommu_id] ) +return -EINVAL ; + +if ( info->viommu[viommu_id]->ops->destroy (info->viommu[viommu_id]) ) +return -EFAULT ;You should return the return the original return value from the "destroy" function pointer, instead of hardcoding it to EFAULT.
OK. Will update.
Quoted 18 lines
Quoted 18 lines
xen/common/viommu.c new file +17
-0+ +xfree (info->viommu[viommu_id]); + info->viommu[viommu_id] =NULL ; +return 0 ; +} + +static u64 viommu_query_caps (struct domain *d,u64 type) +{ +struct viommu_type *viommu_type =viommu_get_type (type); + +if ( !viommu_type ) +return -EINVAL ; + +return viommu_type->ops->query_caps (d); +} + +int __init viommu_setup (void )
Quoted 8 lines
xen/common/viommu.c line 156
Quoted 5 lines
xen/common/viommu.c new file +5
-0+{ +INIT_LIST_HEAD (&type_list); +spin_lock_init (&type_list_lock); +return 0 ; +}With the suggested changes to init
type_listandtype_list_lockat definition time you can get rid ofviommu_setup.
OK. Will update.
Quoted 73 lines
Quoted 60 lines
xen/common/viommu.c new file +9
-0+ +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* End: +*/ xen/include/xen/sched.h +2
-0@@ -21,6 +21,7 @@#include <xen/perfc.h> #include <asm/atomic.h> #include <xen/wait.h> +#include <xen/viommu.h> #include <public/xen.h> #include <public/domctl.h> #include <public/sysctl.h> @@ -477,6 +478,7 @@ struct domain/* vNUMA topology accesses are protected by rwlock. */ rwlock_t vnuma_rwlock;struct vnuma_info *vnuma; +struct viommu_info viommu;/* Common monitor options */ struct {xen/include/xen/viommu.h new file +24
-0@@ -0,0 +1,71 @@ +/* +* include/xen/viommu.h +* +* Copyright (c) 2017, Intel Corporation +* Author: Lan Tianyu <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* You should have received a copy of the GNU General Public License along with +* this program; If not, see <http://www.gnu.org/licenses/>. +* +*/ +#ifndef __XEN_VIOMMU_H__ +#define __XEN_VIOMMU_H__ + +#define NR_VIOMMU_PER_DOMAIN 1 +xen/include/xen/viommu.h line 34
Quoted 10 lines
xen/include/xen/viommu.h new file +10
-0+struct viommu ; + +struct viommu_ops { +u64 (*query_caps)(struct domain *d); +int (*create)(struct domain *d,struct viommu *viommu); +int (*destroy)(struct viommu *viommu); +}; + +struct viommu { +u64 base_address;All those should use uint*_t instead of the u* types.
Quoted 15 lines
xen/include/xen/viommu.h line 44
Quoted 10 lines
xen/include/xen/viommu.h new file +10
-0+u64 length; +u64 caps; +u32 viommu_id; +const struct viommu_ops *ops; +void *priv; +}; + +struct viommu_info { +u32 nr_viommu; +struct viommu *viommu[NR_VIOMMU_PER_DOMAIN ];/* viommu array*/ Seems kind of pointless to have a
nr_viommufield when the array is not dynamic, you could just useARRAY_SIZE. And then in the domain struct you could directly add an array of viommu structs, getting rid ofviommu_infoaltogether.
nr_viommu helps to allocate new viommu id and check whether vIOMMU id passed by tool stack is valid. Otherwise, we have to check vIOMMU array every time to get viommu number.
Quoted 8 lines
xen/include/xen/viommu.h line 48
Quoted 5 lines
xen/include/xen/viommu.h new file +4
-0+}; + +#ifdef CONFIG_VIOMMU +extern bool_t opt_viommu;bool
Quoted 4 lines
xen/include/xen/viommu.h line 49
Quoted 1 line
xen/include/xen/viommu.h new file +1
-0+static inline bool viommu_enabled (void ) {return opt_viommu; }I think those static inline functions should also follow the coding standard.
Yes, I am not sure what wrong here. Could you elaborate? Thanks.
Signature · 7 lines
Best regards Tianyu Lan _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH V2 1/25] VIOMMU: Add vIOMMU helper functions to create, destroy and query capabilities
Quoted 36 lines · Lan Tianyu
Quoted 9 lines · Roger Pau Monné
xen/common/viommu.c line 66
Quoted 6 lines · Lan Tianyu
xen/common/viommu.c new file +6
-0+int viommu_register_type (u64 type,struct viommu_ops * ops) +{ +struct viommu_type *viommu_type =NULL ; + +if ( !viommu_enabled () ) +return -EINVAL ;ENODEV is maybe better here.
Will update.
Quoted 23 lines
Quoted 8 lines
xen/common/viommu.c new file +7
-0+ +if (viommu_get_type (type) ) +return -EEXIST ; + + viommu_type = xzalloc(struct viommu_type); +if ( !viommu_type ) +return -ENOMEM ;xen/common/viommu.c line 83
Quoted 10 lines
xen/common/viommu.c new file +10
-0+ + viommu_type->type = type; + viommu_type->ops = ops; + +spin_lock (&type_list_lock); +list_add_tail (&viommu_type->node, &type_list); +spin_unlock (&type_list_lock); + +return 0 ; +}Hm, I haven't seen the usage of this function, but from the looks of it it seems like you want to use something similar to what's used by the scheduler in order to register vIOMMU types.
Quoted 8 lines
Quoted 1 line
See the logic around
REGISTER_SCHEDULERinxen/sched-if.h.Each vIOMMU devel model needs to call
viommu_register_type()to register its vIOMMU type. Tool stack will passviommu_typeand vIOMMU abstract layer call vendor's vIOMMU callback to query vIOMMU capabilities, create anddestroy()vIOMMU. We just need to maintain type list.REGISTER_SCHEDULERseems to heavy which reserve a scheduler array in the Xen data section.
I will let the maintainers comment, but I find it easier to use something similar to REGISTER_SCHEDULER rather than have each IOMMU type have it's initialization function hooked up in the init procedure and calling viommu_register_type.
From an abstract point of view I don't really see how this is different from a scheduler for example, the IOMMU types are fixed and compiled into Xen, and they need to be initialized/registered at boot time.
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
+static inline bool
viommu_enabled(void){ returnopt_viommu; }I think those static inline functions should also follow the coding standard.
Yes, I am not sure what wrong here. Could you elaborate? Thanks.
IMHO they should be:
static inline bool viommu_enabled(void)
{
return opt_viommu;
}Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH V2 1/25] VIOMMU: Add vIOMMU helper functions to create, destroy and query capabilities
In reply to Lan TianyuQuoted 41 lines
From: Lan, Tianyu
Sent: Friday, August 18, 2017 8:22 AMThis patch is to introduct an abstract layer for arch vIOMMU implementation
to deal with requests from dom0. Arch vIOMMU code needs to provide callback
to perform create, destroy and query capabilities operation.Signed-off-by Lan Tianyu <[email protected]>--- xen/arch/x86/Kconfig | 1 + xen/arch/x86/setup.c | 1 + xen/common/Kconfig | 3 + xen/common/Makefile | 1 + xen/common/domain.c | 3 + xen/common/viommu.c | 165 +++++++++++++++++++++++++++++++++++++++++++++++ xen/include/xen/sched.h | 2 + xen/include/xen/viommu.h | 71 ++++++++++++++++++++ 8 files changed, 247 insertions(+) create mode 100644 xen/common/viommu.c create mode 100644 xen/include/xen/viommu.hxen/arch/x86/Kconfig +1
-0@@ -23,6 +23,7 @@ config X86 select HAS_PDX select NUMA select VGA + select VIOMMU config ARCH_DEFCONFIG stringxen/arch/x86/setup.c +0
-0
xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long · line 1517
Quoted 5 lines
xen/arch/x86/setup.c +1
-0@@ -1513,6 +1513,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)early_msi_init ();iommu_setup ();/* setup iommu if available */ +viommu_setup ();
start_xen is about physical bits, why placing viommu stuff here?
Quoted 34 lines
xen/arch/x86/setup.c +0
-0smp_prepare_cpus (max_cpus);xen/common/Kconfig +3
-0@@ -49,6 +49,9 @@ config HAS_CHECKPOLICY string option env="XEN_HAS_CHECKPOLICY" +config VIOMMU + bool + config KEXEC bool "kexec support" default yxen/common/Makefile +1
-0@@ -56,6 +56,7 @@ obj-y += time.o obj-y += timer.o obj-y += trace.o obj-y += version.o +obj-$(CONFIG_VIOMMU) += viommu.o obj-y += virtual_region.o obj-y += vm_event.o obj-y += vmap.oxen/common/domain.c +0
-0
xen/common/domain.c struct domain *domain_create(domid_t domid, · line 402
Quoted 7 lines
xen/common/domain.c +3
-0@@ -396,6 +396,9 @@ struct domain *domain_create(domid_t domid,unsigned int domcr_flags, spin_unlock(&domlist_update_lock); } +if ( (err =viommu_init_domain (d)) !=0 ) + goto fail; +
though viommu framework is common, it's better to have arch specific code invoke above function based on their own requirement (e.g. if any dependency required to enforce)
Quoted 34 lines
xen/common/domain.c +0
-0return d;fail:
xen/common/viommu.c new file +12
-0@@ -0,0 +1,165 @@ +/* +* common/viommu.c +* +* Copyright (c) 2017 Intel Corporation +* Author: Lan Tianyu <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; If not, see <http://www.gnu.org/licenses/>.
+ */xen/common/viommu.c new file +4
-0+ +#include <xen/sched.h> +#include <xen/spinlock.h> +#include <xen/types.h>
xen/common/viommu.c line 32
Quoted 10 lines
xen/common/viommu.c new file +10
-0+#include <xen/viommu.h> + +bool __read_mostly opt_viommu; +boolean_param ("viommu" , opt_viommu); + +static spinlock_t type_list_lock; +static struct list_head type_list; + +struct viommu_type { +u64 type;
please add some comment what 'type' stands for.
Quoted 24 lines
xen/common/viommu.c new file +24
-0+struct viommu_ops *ops; +struct list_head node; +}; + +int viommu_init_domain (struct domain *d) +{ + d->viommu.nr_viommu =0 ; +return 0 ; +} + +static struct viommu_type *viommu_get_type (u64 type) +{ +struct viommu_type *viommu_type =NULL ; + +spin_lock (&type_list_lock); +list_for_each_entry ( viommu_type, &type_list, node ) + { +if ( viommu_type->type == type ) + { +spin_unlock (&type_list_lock); +return viommu_type; + } + } +spin_unlock (&type_list_lock);
xen/common/viommu.c line 66
Quoted 10 lines
xen/common/viommu.c new file +10
-0+ +return NULL ; +} + +int viommu_register_type (u64 type,struct viommu_ops * ops) +{ +struct viommu_type *viommu_type =NULL ; + +if ( !viommu_enabled () ) +return -EINVAL ;
shouldn't above be domain specific check?
Thanks
Kevin
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH V2 2/25] VIOMMU: Add irq request callback to deal with irq remapping
In reply to Wei LiuQuoted 20 lines · Wei Liu
Quoted 19 lines · Lan Tianyu
This patch is to add irq request callback for platform implementation to deal with irq remapping request.
Signed-off-by Lan Tianyu <[email protected]>--- xen/common/viommu.c | 15 +++++++++ xen/include/asm-x86/viommu.h | 73 ++++++++++++++++++++++++++++++++++++++++++++ xen/include/xen/viommu.h | 9 ++++++ 3 files changed, 97 insertions(+) create mode 100644 xen/include/asm-x86/viommu.hxen/common/viommu.c +0
-0@@ -198,6 +198,21 @@ int __init viommu_setup(void)return 0 ; }
Quoted 7 lines
xen/common/viommu.c int __init viommu_setup(void) · line 204
Quoted 4 lines
xen/common/viommu.c +4
-0+int viommu_handle_irq_request (struct domain *d,u32 viommu_id, +struct irq_remapping_request *request) +{ +struct viommu_info *info = &d->viommu;Does this compile? This patch and the previous one don't have viommu added to struct domain.
Oh. Sorry. Missed patch "VIOMMU: Add vIOMMU helper functions to create,
destroy and query capabilities" in this series. I just sent out and
followed this mail. Please have a look.
Quoted 7 lines
xen/common/viommu.c int __init viommu_setup(void) · line 207
Quoted 4 lines
xen/common/viommu.c +3
-0+ +if ( viommu_id >= info->nr_viommu + || !info->viommu[viommu_id] )Join this to previous line?
OK.
Quoted 5 lines
xen/common/viommu.c int __init viommu_setup(void) · line 208
Quoted 1 line
xen/common/viommu.c +1
-0+return -EINVAL ;
ASSERT(info->viommu[viommu_id]->ops);For extra safety.
Or check ops in the previous if?
Quoted 33 lines
Quoted 33 lines
xen/common/viommu.c +7
-0+ +if ( !info->viommu[viommu_id]->ops->handle_irq_request ) +return -EINVAL ; + +return info->viommu[viommu_id]->ops->handle_irq_request (d, request); +} +/* * Local variables: * mode: C xen/include/asm-x86/viommu.h new file +16
-0@@ -0,0 +1,73 @@ +/* +* include/asm-x86/viommu.h +* +* Copyright (c) 2017 Intel Corporation. +* Author: Lan Tianyu <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* You should have received a copy of the GNU General Public License along with
Quoted 8 lines
xen/include/asm-x86/viommu.h line 22
Quoted 6 lines
xen/include/asm-x86/viommu.h new file +6
-0+* this program; If not, see <http://www.gnu.org/licenses/>. +* +*/ +#ifndef __ARCH_X86_VIOMMU_H__ +#define __ARCH_X86_VIOMMU_H__ +Is a corresponding ARM header needed? Given viommu is common code.
I added such ARM header file in previous version but Julien hope vIOMMU should be disabled for ARM because ARM doesn't support vIOMMU so far.
Quoted 8 lines
xen/include/asm-x86/viommu.h line 23
Quoted 2 lines
xen/include/asm-x86/viommu.h new file +1
-0+#include <xen/viommu.h> I think you're probably doing it wrong.
It should be that the common header header includes arch header, then the code only uses the common header (I haven't read the rest of your series at this point).
OK. Will fix it.
Quoted 14 lines
Quoted 14 lines
xen/include/asm-x86/viommu.h new file +13
-0+#include <asm/types.h> + +/* IRQ request type */ +#define VIOMMU_REQUEST_IRQ_MSI 0 +#define VIOMMU_REQUEST_IRQ_APIC 1 + +struct irq_remapping_request +{ + union { + /* MSI */ + struct { + u64 addr; + u32 data;
Quoted 8 lines
xen/include/asm-x86/viommu.h line 42
Quoted 6 lines
xen/include/asm-x86/viommu.h new file +6
-0+ } msi; +/* Redirection Entry in IOAPIC */ +u64 rte; + } msg; +u16 source_id; +u8 type;
uintXX_tplease.
Sure.
Quoted 88 lines
xen/include/asm-x86/viommu.h line 46
Quoted 5 lines
xen/include/asm-x86/viommu.h new file +4
-0+}; + +static inline void irq_request_ioapic_fill (struct irq_remapping_request *req, +uint32_t ioapic_id,uint64_t rte)Indentation.
xen/include/asm-x86/viommu.h line 55
Quoted 9 lines
xen/include/asm-x86/viommu.h new file +9
-0+{ +ASSERT (req); + req->type =VIOMMU_REQUEST_IRQ_APIC ; + req->source_id = ioapic_id; + req->msg.rte = rte; +} + +static inline void irq_request_msi_fill (struct irq_remapping_request *req, +uint32_t source_id,uint64_t addr,uint32_t data)Indentation.
Quoted 23 lines
xen/include/asm-x86/viommu.h new file +18
-0+{ +ASSERT (req); + req->type =VIOMMU_REQUEST_IRQ_MSI ; + req->source_id = source_id; + req->msg.msi.addr = addr; + req->msg.msi.data = data; +} + +#endif /* __ARCH_X86_VIOMMU_H__ */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* End: +*/ xen/include/xen/viommu.h +0
-0xen/include/xen/viommu.h line 24
Quoted 5 lines
xen/include/xen/viommu.h +2
-0@@ -20,6 +20,8 @@#ifndef __XEN_VIOMMU_H__#define __XEN_VIOMMU_H__ +#include <asm/viommu.h> +Circular inclusion? Note the #include <
xen/viommu.h> some lines above.Quoted 22 lines
xen/include/xen/viommu.h +4
-0#define NR_VIOMMU_PER_DOMAIN 1struct viommu ;@@ -28,6 +30,8 @@ struct viommu_ops {u64 (*query_caps)(struct domain *d);int (*create)(struct domain *d,struct viommu *viommu);int (*destroy)(struct viommu *viommu); +int (*handle_irq_request)(struct domain *d, +struct irq_remapping_request *request); };struct viommu {@@ -52,6 +56,8 @@ int viommu_register_type(u64 type, struct viommu_ops * ops);int viommu_domctl (struct domain *d,struct xen_domctl_viommu_op *op,bool_t *need_copy);int viommu_setup (void ); +int viommu_handle_irq_request (struct domain *d,u32 viommu_id, +struct irq_remapping_request *request);#else static inline int viommu_init_domain (struct domain *d) {return 0 ; }static inline int viommu_register_type (u64 type,struct viommu_ops * ops)xen/include/xen/viommu.h static inline int viommu_domctl(struct domain *d, · line 73
Quoted 6 lines
xen/include/xen/viommu.h +3
-0@@ -62,6 +68,9 @@ static inline int viommu_domctl(struct domain *d,struct xen_domctl_viommu_op *op, bool *need_copy) { return -ENODEV }; +static inline int viommu_handle_irq_request (struct domain *d,u32 viommu_id, +struct irq_remapping_request *request) +{ return 0 };This should fail.
Quoted 6 lines
xen/include/xen/viommu.h +0
-0#endif #endif /* __XEN_VIOMMU_H__ */ Signature · 1 line
1.8.3.1
Signature · 7 lines
Best regards Tianyu Lan _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH V2 2/25] VIOMMU: Add irq request callback to deal with irq remapping
Quoted 43 lines · Lan Tianyu
Quoted 20 lines · Wei Liu
Quoted 19 lines · Lan Tianyu
This patch is to add irq request callback for platform implementation to deal with irq remapping request.
Signed-off-by Lan Tianyu <[email protected]>--- xen/common/viommu.c | 15 +++++++++ xen/include/asm-x86/viommu.h | 73 ++++++++++++++++++++++++++++++++++++++++++++ xen/include/xen/viommu.h | 9 ++++++ 3 files changed, 97 insertions(+) create mode 100644 xen/include/asm-x86/viommu.hxen/common/viommu.c +0
-0@@ -198,6 +198,21 @@ int __init viommu_setup(void)return 0 ; }Quoted 7 lines
xen/common/viommu.c int __init viommu_setup(void) · line 204
Quoted 4 lines
xen/common/viommu.c +4
-0+int viommu_handle_irq_request (struct domain *d,u32 viommu_id, +struct irq_remapping_request *request) +{ +struct viommu_info *info = &d->viommu;Does this compile? This patch and the previous one don't have viommu added to struct domain.
Oh. Sorry. Missed patch "VIOMMU: Add vIOMMU helper functions to create,
destroy and query capabilities" in this series. I just sent out and
followed this mail. Please have a look.Quoted 7 lines
xen/common/viommu.c int __init viommu_setup(void) · line 207
Quoted 4 lines
xen/common/viommu.c +3
-0+ +if ( viommu_id >= info->nr_viommu + || !info->viommu[viommu_id] )Join this to previous line?
OK.
Quoted 8 lines
Quoted 5 lines
xen/common/viommu.c int __init viommu_setup(void) · line 208
Quoted 1 line
xen/common/viommu.c +1
-0+return -EINVAL ;
ASSERT(info->viommu[viommu_id]->ops);For extra safety.
Or check ops in the previous if?
That depends on if ops can be null or not.
Quoted 42 lines
Quoted 33 lines
Quoted 33 lines
xen/common/viommu.c +7
-0+ +if ( !info->viommu[viommu_id]->ops->handle_irq_request ) +return -EINVAL ; + +return info->viommu[viommu_id]->ops->handle_irq_request (d, request); +} +/* * Local variables: * mode: C xen/include/asm-x86/viommu.h new file +16
-0@@ -0,0 +1,73 @@ +/* +* include/asm-x86/viommu.h +* +* Copyright (c) 2017 Intel Corporation. +* Author: Lan Tianyu <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* You should have received a copy of the GNU General Public License along with Quoted 8 lines
xen/include/asm-x86/viommu.h line 22
Quoted 6 lines
xen/include/asm-x86/viommu.h new file +6
-0+* this program; If not, see <http://www.gnu.org/licenses/>. +* +*/ +#ifndef __ARCH_X86_VIOMMU_H__ +#define __ARCH_X86_VIOMMU_H__ +Is a corresponding ARM header needed? Given viommu is common code.
Quoted 3 lines
I added such ARM header file in previous version but Julien hope vIOMMU should be disabled for ARM because ARM doesn't support vIOMMU so far.
If that's what he wanted, sure.
Please build test ARM as well. You can do so using travis-ci.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH V2 2/25] VIOMMU: Add irq request callback to deal with irq remapping
Quoted 7 lines · Wei Liu
Quoted 6 lines
Quoted 6 lines
ASSERT(info->viommu[viommu_id]->ops);Quoted 2 lines
Quoted 2 lines
For extra safety.
Or check ops in the previous if?
That depends on if ops can be null or not.
If ops isn't be set, it will be null. Because struct viommu is allocated via xzalloc().
Quoted 32 lines
Quoted 32 lines
Quoted 31 lines
xen/include/asm-x86/viommu.h +0
-0Quoted 29 lines
Quoted 19 lines
Quoted 19 lines
new file mode 100644
index 0000000..51bda72xen/include/asm-x86/viommu.h new file +14
-0@@ -0,0 +1,73 @@ +/* +* include/asm-x86/viommu.h +* +* Copyright (c) 2017 Intel Corporation. +* Author: Lan Tianyu <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. Quoted 8 lines
xen/include/asm-x86/viommu.h line 22
Quoted 8 lines
xen/include/asm-x86/viommu.h new file +8
-0+* +* You should have received a copy of the GNU General Public License along with +* this program; If not, see <http://www.gnu.org/licenses/>. +* +*/ +#ifndef __ARCH_X86_VIOMMU_H__ +#define __ARCH_X86_VIOMMU_H__ +Is a corresponding ARM header needed? Given viommu is common code.
Quoted 6 lines
Quoted 3 lines
I added such ARM header file in previous version but Julien hope vIOMMU
Quoted 2 lines
should be disabled for ARM because ARM doesn't support vIOMMU so far.
If that's what he wanted, sure.
Please build test ARM as well. You can do so using travis-ci.
OK. Will test.
Signature · 7 lines
Best regards Tianyu Lan _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH V2 2/25] VIOMMU: Add irq request callback to deal with irq remapping
Quoted 11 lines · Lan Tianyu
Quoted 7 lines · Wei Liu
Quoted 6 lines
Quoted 6 lines
ASSERT(info->viommu[viommu_id]->ops);Quoted 2 lines
Quoted 2 lines
For extra safety.
Or check ops in the previous if?
That depends on if ops can be null or not.
If ops isn't be set, it will be null. Because struct viommu is allocated via
xzalloc().
But is it functionally correct / possible to have it to be NULL when you come to this path?
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH V2 2/25] VIOMMU: Add irq request callback to deal with irq remapping
Quoted 8 lines · Wei Liu
Quoted 7 lines · Lan Tianyu
Quoted 6 lines · Wei Liu
Quoted 6 lines
Quoted 6 lines
ASSERT(info->viommu[viommu_id]->ops);Quoted 2 lines
Quoted 2 lines
For extra safety.
Or check ops in the previous if?
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
That depends on if ops can be null or not.
If ops isn't be set, it will be null. Because struct viommu is allocated via
xzalloc().But is it functionally correct / possible to have it to be NULL when you come to this path?
No, it shouldn't be NULL if struct viommu is set up correctly.
Signature · 7 lines
Best regards Tianyu Lan _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH V2 2/25] VIOMMU: Add irq request callback to deal with irq remapping
Quoted 11 lines · Lan Tianyu
Quoted 10 lines · Wei Liu
Quoted 9 lines · Lan Tianyu
Quoted 7 lines · Wei Liu
Quoted 6 lines
Quoted 6 lines
ASSERT(info->viommu[viommu_id]->ops);Quoted 2 lines
Quoted 2 lines
For extra safety.
Or check ops in the previous if?
That depends on if ops can be null or not.
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines
If ops isn't be set, it will be null. Because struct viommu is allocated via
xzalloc().But is it functionally correct / possible to have it to be NULL when you come to this path?
No, it shouldn't be NULL if struct viommu is set up correctly.
Then an ASSERT is warranted -- hope you see the line of thinking.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH V2 2/25] VIOMMU: Add irq request callback to deal with irq remapping
Quoted 15 lines · Wei Liu
Quoted 14 lines · Lan Tianyu
Quoted 13 lines · Wei Liu
Quoted 11 lines · Lan Tianyu
Quoted 7 lines · Wei Liu
Quoted 6 lines
Quoted 6 lines
ASSERT(info->viommu[viommu_id]->ops);Quoted 2 lines
Quoted 2 lines
For extra safety.
Or check ops in the previous if?
That depends on if ops can be null or not.
If ops isn't be set, it will be null. Because struct viommu is allocated via
xzalloc().
Quoted 9 lines
Quoted 6 lines
Quoted 3 lines
But is it functionally correct / possible to have it to be NULL when you come to this path?
No, it shouldn't be NULL if struct viommu is set up correctly.
Then an ASSERT is warranted -- hope you see the line of thinking.
OK. I got it. Will add in the next version.
Signature · 7 lines
Best regards Tianyu Lan _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH V2 2/25] VIOMMU: Add irq request callback to deal with irq remapping
In reply to Lan TianyuQuoted 16 lines · Lan Tianyu
This patch is to add irq request callback for platform implementation to deal with irq remapping request.
Signed-off-by Lan Tianyu <[email protected]>--- xen/common/viommu.c | 15 +++++++++ xen/include/asm-x86/viommu.h | 73 ++++++++++++++++++++++++++++++++++++++++++++ xen/include/xen/viommu.h | 9 ++++++ 3 files changed, 97 insertions(+) create mode 100644 xen/include/asm-x86/viommu.hxen/common/viommu.c +0
-0
xen/common/viommu.c int __init viommu_setup(void) · line 207
Quoted 10 lines
xen/common/viommu.c +7
-0@@ -198,6 +198,21 @@ int __init viommu_setup(void)return 0 ; } +int viommu_handle_irq_request (struct domain *d,u32 viommu_id, +struct irq_remapping_request *request) +{ +struct viommu_info *info = &d->viommu; + +if ( viommu_id >= info->nr_viommu + || !info->viommu[viommu_id] )
This fits on the same line, no need to split it.
Quoted 69 lines
xen/common/viommu.c +8
-0+return -EINVAL ; + +if ( !info->viommu[viommu_id]->ops->handle_irq_request ) +return -EINVAL ; + +return info->viommu[viommu_id]->ops->handle_irq_request (d, request); +} +/* * Local variables: * mode: C xen/include/asm-x86/viommu.h new file +52
-0@@ -0,0 +1,73 @@ +/* +* include/asm-x86/viommu.h +* +* Copyright (c) 2017 Intel Corporation. +* Author: Lan Tianyu <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* You should have received a copy of the GNU General Public License along with +* this program; If not, see <http://www.gnu.org/licenses/>. +* +*/ +#ifndef __ARCH_X86_VIOMMU_H__ +#define __ARCH_X86_VIOMMU_H__ + +#include <xen/viommu.h> +#include <asm/types.h> + +/* IRQ request type */ +#define VIOMMU_REQUEST_IRQ_MSI 0 +#define VIOMMU_REQUEST_IRQ_APIC 1 + +struct irq_remapping_request +{ +union { +/* MSI */ +struct { +u64 addr; +u32 data; + } msi; +/* Redirection Entry in IOAPIC */ +u64 rte; + } msg; +u16 source_id; +u8 type; +}; + +static inline void irq_request_ioapic_fill (struct irq_remapping_request *req, +uint32_t ioapic_id,uint64_t rte) +{ +ASSERT (req); + req->type =VIOMMU_REQUEST_IRQ_APIC ; + req->source_id = ioapic_id; + req->msg.rte = rte; +}
xen/include/asm-x86/viommu.h line 62
Quoted 10 lines
xen/include/asm-x86/viommu.h new file +10
-0+ +static inline void irq_request_msi_fill (struct irq_remapping_request *req, +uint32_t source_id,uint64_t addr,uint32_t data) +{ +ASSERT (req); + req->type =VIOMMU_REQUEST_IRQ_MSI ; + req->source_id = source_id; + req->msg.msi.addr = addr; + req->msg.msi.data = data; +}
What's the usage of those two functions? AFAICT they don't have any callers in this patch.
Quoted 25 lines
xen/include/asm-x86/viommu.h new file +11
-0+ +#endif /* __ARCH_X86_VIOMMU_H__ */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* End: +*/ xen/include/xen/viommu.h +2
-0@@ -20,6 +20,8 @@#ifndef __XEN_VIOMMU_H__#define __XEN_VIOMMU_H__ +#include <asm/viommu.h> +#define NR_VIOMMU_PER_DOMAIN 1struct viommu ;
xen/include/xen/viommu.h struct viommu_ops { · line 34
Quoted 5 lines
xen/include/xen/viommu.h +2
-0@@ -28,6 +30,8 @@ struct viommu_ops {u64 (*query_caps)(struct domain *d);int (*create)(struct domain *d,struct viommu *viommu);int (*destroy)(struct viommu *viommu); +int (*handle_irq_request)(struct domain *d, +struct irq_remapping_request *request);
I'm slightly lost, you add the function pointer here and some inline functions in asm-x86/viommu.h, yet I don't see them being hooked into the struct viommu_ops in any way.
Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH V2 2/25] VIOMMU: Add irq request callback to deal with irq remapping
Quoted 104 lines · Roger Pau Monné
Quoted 16 lines · Lan Tianyu
This patch is to add irq request callback for platform implementation to deal with irq remapping request.
Signed-off-by Lan Tianyu <[email protected]>--- xen/common/viommu.c | 15 +++++++++ xen/include/asm-x86/viommu.h | 73 ++++++++++++++++++++++++++++++++++++++++++++ xen/include/xen/viommu.h | 9 ++++++ 3 files changed, 97 insertions(+) create mode 100644 xen/include/asm-x86/viommu.hxen/common/viommu.c +0
-0xen/common/viommu.c int __init viommu_setup(void) · line 207
Quoted 10 lines
xen/common/viommu.c +7
-0@@ -198,6 +198,21 @@ int __init viommu_setup(void)return 0 ; } +int viommu_handle_irq_request (struct domain *d,u32 viommu_id, +struct irq_remapping_request *request) +{ +struct viommu_info *info = &d->viommu; + +if ( viommu_id >= info->nr_viommu + || !info->viommu[viommu_id] )This fits on the same line, no need to split it.
Quoted 74 lines
xen/common/viommu.c +8
-0+return -EINVAL ; + +if ( !info->viommu[viommu_id]->ops->handle_irq_request ) +return -EINVAL ; + +return info->viommu[viommu_id]->ops->handle_irq_request (d, request); +} +/* * Local variables: * mode: C xen/include/asm-x86/viommu.h new file +57
-0@@ -0,0 +1,73 @@ +/* +* include/asm-x86/viommu.h +* +* Copyright (c) 2017 Intel Corporation. +* Author: Lan Tianyu <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* You should have received a copy of the GNU General Public License along with +* this program; If not, see <http://www.gnu.org/licenses/>. +* +*/ +#ifndef __ARCH_X86_VIOMMU_H__ +#define __ARCH_X86_VIOMMU_H__ + +#include <xen/viommu.h> +#include <asm/types.h> + +/* IRQ request type */ +#define VIOMMU_REQUEST_IRQ_MSI 0 +#define VIOMMU_REQUEST_IRQ_APIC 1 + +struct irq_remapping_request +{ +union { +/* MSI */ +struct { +u64 addr; +u32 data; + } msi; +/* Redirection Entry in IOAPIC */ +u64 rte; + } msg; +u16 source_id; +u8 type; +}; + +static inline void irq_request_ioapic_fill (struct irq_remapping_request *req, +uint32_t ioapic_id,uint64_t rte) +{ +ASSERT (req); + req->type =VIOMMU_REQUEST_IRQ_APIC ; + req->source_id = ioapic_id; + req->msg.rte = rte; +} + +static inline void irq_request_msi_fill (struct irq_remapping_request *req, +uint32_t source_id,uint64_t addr,uint32_t data) +{ +ASSERT (req);
Quoted 8 lines
xen/include/asm-x86/viommu.h line 62
Quoted 5 lines
xen/include/asm-x86/viommu.h new file +5
-0+ req->type =VIOMMU_REQUEST_IRQ_MSI ; + req->source_id = source_id; + req->msg.msi.addr = addr; + req->msg.msi.data = data; +}What's the usage of those two functions? AFAICT they don't have any callers in this patch.
These functions will be called in the following interrupt patch 22 "x86/vmsi: Hook delivering remapping format msi to guest" and patch 16 "x86/vioapic: Hook interrupt delivery of vIOAPIC"
Quoted 38 lines
Quoted 26 lines
xen/include/asm-x86/viommu.h new file +11
-0+ +#endif /* __ARCH_X86_VIOMMU_H__ */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* End: +*/ xen/include/xen/viommu.h +2
-0@@ -20,6 +20,8 @@#ifndef __XEN_VIOMMU_H__#define __XEN_VIOMMU_H__ +#include <asm/viommu.h> +#define NR_VIOMMU_PER_DOMAIN 1struct viommu ;xen/include/xen/viommu.h struct viommu_ops { · line 34
Quoted 5 lines
xen/include/xen/viommu.h +2
-0@@ -28,6 +30,8 @@ struct viommu_ops {u64 (*query_caps)(struct domain *d);int (*create)(struct domain *d,struct viommu *viommu);int (*destroy)(struct viommu *viommu); +int (*handle_irq_request)(struct domain *d, +struct irq_remapping_request *request);I'm slightly lost, you add the function pointer here and some inline functions in
asm-x86/viommu.h, yet I don't see them being hooked into the structviommu_opsin any way.Roger.
Signature · 7 lines
Best regards Tianyu Lan _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH V2 2/25] VIOMMU: Add irq request callback to deal with irq remapping
Quoted 25 lines
Quoted 1 line
Quoted 1 line · On 23.08.17 at 09:42, <[email protected]> wrote:
Quoted 14 lines · Roger Pau Monné
Quoted 13 lines · Lan Tianyu
xen/include/asm-x86/viommu.h new file +13
-0+static inline void irq_request_ioapic_fill (struct irq_remapping_request *req, +uint32_t ioapic_id,uint64_t rte) +{ +ASSERT (req); + req->type =VIOMMU_REQUEST_IRQ_APIC ; + req->source_id = ioapic_id; + req->msg.rte = rte; +} + +static inline void irq_request_msi_fill (struct irq_remapping_request *req, +uint32_t source_id,uint64_t addr,uint32_t data) +{ +ASSERT (req);Quoted 8 lines
xen/include/asm-x86/viommu.h line 62
Quoted 5 lines
xen/include/asm-x86/viommu.h new file +5
-0+ req->type =VIOMMU_REQUEST_IRQ_MSI ; + req->source_id = source_id; + req->msg.msi.addr = addr; + req->msg.msi.data = data; +}What's the usage of those two functions? AFAICT they don't have any callers in this patch.
Quoted 3 lines
These functions will be called in the following interrupt patch 22 "x86/vmsi: Hook delivering remapping format msi to guest" and patch 16 "x86/vioapic: Hook interrupt delivery of vIOAPIC"
That's _far_ away. As implied by Roger's comment, please try to avoid introducing dead code, especially when it's dead for an extended period of time. Always remember that a series may not be committed in one go.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH V2 2/25] VIOMMU: Add irq request callback to deal with irq remapping
Quoted 25 lines · Jan Beulich
Quoted 25 lines
Quoted 1 line
Quoted 1 line · On 23.08.17 at 09:42, <[email protected]> wrote:
Quoted 22 lines · Roger Pau Monné
Quoted 8 lines · Lan Tianyu
xen/include/asm-x86/viommu.h new file +8
-0+static inline void irq_request_ioapic_fill (struct irq_remapping_request *req, +uint32_t ioapic_id,uint64_t rte) +{ +ASSERT (req); + req->type =VIOMMU_REQUEST_IRQ_APIC ; + req->source_id = ioapic_id; + req->msg.rte = rte; +}xen/include/asm-x86/viommu.h line 62
Quoted 10 lines
xen/include/asm-x86/viommu.h new file +10
-0+ +static inline void irq_request_msi_fill (struct irq_remapping_request *req, +uint32_t source_id,uint64_t addr,uint32_t data) +{ +ASSERT (req); + req->type =VIOMMU_REQUEST_IRQ_MSI ; + req->source_id = source_id; + req->msg.msi.addr = addr; + req->msg.msi.data = data; +}What's the usage of those two functions? AFAICT they don't have any callers in this patch.
Quoted 8 lines
Quoted 3 lines
These functions will be called in the following interrupt patch 22 "x86/vmsi: Hook delivering remapping format msi to guest" and patch 16 "x86/vioapic: Hook interrupt delivery of vIOAPIC"
That's _far_ away. As implied by Roger's comment, please try to avoid introducing dead code, especially when it's dead for an extended period of time. Always remember that a series may not be committed in one go.
OK. Will change order.
Signature · 7 lines
Best regards Tianyu Lan _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH v2 3/25 VIOMMU: Add get irq info callback to convert irq remapping request
In reply to Lan TianyuThis patch is to add get_irq_info callback for platform implementation to convert irq remapping request to irq info (E,G vector, dest, dest_mode and so on).
--- xen/common/viommu.c | 16 ++++++++++++++++ xen/include/asm-x86/viommu.h | 8 ++++++++ xen/include/xen/viommu.h | 9 +++++++++ 3 files changed, 33 insertions(+)
xen/common/viommu.c +16 -0
@@ -213,6 +213,22 @@ int viommu_handle_irq_request(struct domain *d, u32 viommu_id,return info->viommu[viommu_id]->ops->handle_irq_request (d, request); } +int viommu_get_irq_info (struct domain *d,u32 viommu_id, +struct irq_remapping_request *request, +struct irq_remapping_info *irq_info) +{ +struct viommu_info *info = &d->viommu; + +if ( viommu_id >= info->nr_viommu + || !info->viommu[viommu_id] ) +return -EINVAL ; + +if ( !info->viommu[viommu_id]->ops->get_irq_info ) +return -EINVAL ; + +return info->viommu[viommu_id]->ops->get_irq_info (d, request, irq_info); +} +/* * Local variables: * mode: C
xen/include/asm-x86/viommu.h +8 -0
@@ -27,6 +27,14 @@#define VIOMMU_REQUEST_IRQ_MSI 0#define VIOMMU_REQUEST_IRQ_APIC 1 +struct irq_remapping_info +{ +u8 vector; +u32 dest; +u32 dest_mode:1 ; +u32 delivery_mode:3 ; +}; + struct irq_remapping_request { union {
xen/include/xen/viommu.h +9 -0
@@ -32,6 +32,8 @@ struct viommu_ops {int (*destroy)(struct viommu *viommu);int (*handle_irq_request)(struct domain *d,struct irq_remapping_request *request); +int (*get_irq_info)(struct domain *d,struct irq_remapping_request *request, +struct irq_remapping_info *info); };struct viommu {
@@ -58,6 +60,9 @@ int viommu_domctl(struct domain *d, struct xen_domctl_viommu_op *op,int viommu_setup (void );int viommu_handle_irq_request (struct domain *d,u32 viommu_id,struct irq_remapping_request *request); +int viommu_get_irq_info (struct domain *d,u32 viommu_id, +struct irq_remapping_request *request, +struct irq_remapping_info *irq_info);#else static inline int viommu_init_domain (struct domain *d) {return 0 ; }static inline int viommu_register_type (u64 type,struct viommu_ops * ops)
@@ -71,6 +76,10 @@ static inline int viommu_domctl(struct domain *d, static inline int viommu_handle_irq_request(struct domain *d, u32 viommu_id, struct irq_remapping_request *request) { return 0 }; +static inline int viommu_get_irq_info(struct domain *d, u32 viommu_id, + struct irq_remapping_request *request, + struct irq_remapping_info *irq_info) +{ return 0 }; #endif #endif /* __XEN_VIOMMU_H__ */
Signature · 7 lines
1.8.3.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH V2 3/25] VIOMMU: Add get irq info callback to convert irq remapping request
Quoted 16 lines · Lan Tianyu
This patch is to add
get_irq_infocallback for platform implementation to convert irq remapping request to irq info (E,G vector, dest,dest_modeand so on).Signed-off-by Lan Tianyu <[email protected]>--- xen/common/viommu.c | 16 ++++++++++++++++ xen/include/asm-x86/viommu.h | 8 ++++++++ xen/include/xen/viommu.h | 9 +++++++++ 3 files changed, 33 insertions(+)xen/common/viommu.c +0
-0
xen/common/viommu.c int viommu_handle_irq_request(struct domain *d, u32 viommu_id, · line 216
Quoted 4 lines
xen/common/viommu.c +1
-0@@ -213,6 +213,22 @@ int viommu_handle_irq_request(struct domain *d, u32 viommu_id,return info->viommu[viommu_id]->ops->handle_irq_request (d, request); } +int viommu_get_irq_info(struct domain *d, u32 viommu_id,
Again, uint32_t please.
Please fix all these in this series.
xen/common/viommu.c int viommu_handle_irq_request(struct domain *d, u32 viommu_id, · line 220
Quoted 4 lines
xen/common/viommu.c +4
-0+struct irq_remapping_request *request, + struct irq_remapping_info *irq_info) +{ + struct viommu_info *info = &d->viommu;
Having skimmed the rest of this series, there is no addition of viommu to struct domain (no change to sched.h). Did I miss something obvious?
xen/common/viommu.c int viommu_handle_irq_request(struct domain *d, u32 viommu_id, · line 229
Quoted 9 lines
xen/common/viommu.c +9
-0+ +if ( viommu_id >= info->nr_viommu + || !info->viommu[viommu_id] ) +return -EINVAL ; + +if ( !info->viommu[viommu_id]->ops->get_irq_info ) +return -EINVAL ; + +return info->viommu[viommu_id]->ops->get_irq_info (d, request, irq_info);
Same comments in previous patch apply here, too.
Quoted 6 lines
xen/common/viommu.c +2
-0+} +/* * Local variables: * mode: C xen/include/asm-x86/viommu.h +0
-0
[...]
xen/include/asm-x86/viommu.h
Quoted 4 lines
xen/include/asm-x86/viommu.h +4
-0+static inline int viommu_get_irq_info (struct domain *d,u32 viommu_id, +struct irq_remapping_request *request, +struct irq_remapping_info *irq_info) +{ return 0 };
This should fail, too.
Quoted 6 lines
#endif
#endif /*
__XEN_VIOMMU_H__*/Signature · 1 line
1.8.3.1
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH V2 3/25] VIOMMU: Add get irq info callback to convert irq remapping request
In reply to Lan TianyuQuoted 16 lines · Lan Tianyu
This patch is to add
get_irq_infocallback for platform implementation to convert irq remapping request to irq info (E,G vector, dest,dest_modeand so on).Signed-off-by Lan Tianyu <[email protected]>--- xen/common/viommu.c | 16 ++++++++++++++++ xen/include/asm-x86/viommu.h | 8 ++++++++ xen/include/xen/viommu.h | 9 +++++++++ 3 files changed, 33 insertions(+)xen/common/viommu.c +0
-0
xen/common/viommu.c int viommu_handle_irq_request(struct domain *d, u32 viommu_id, · line 218
Quoted 6 lines
xen/common/viommu.c +3
-0@@ -213,6 +213,22 @@ int viommu_handle_irq_request(struct domain *d, u32 viommu_id,return info->viommu[viommu_id]->ops->handle_irq_request (d, request); } +int viommu_get_irq_info (struct domain *d,u32 viommu_id, +struct irq_remapping_request *request, +struct irq_remapping_info *irq_info)
The definition of this struct seems to be arch-specific, in which case IMHO it should be called arch_irq_remapping_info, in order to denote it's arch-specific.
xen/common/viommu.c int viommu_handle_irq_request(struct domain *d, u32 viommu_id, · line 223
Quoted 5 lines
xen/common/viommu.c +5
-0+{ +struct viommu_info *info = &d->viommu; + +if ( viommu_id >= info->nr_viommu + || !info->viommu[viommu_id] )
Unneeded line break.
Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH V2 3/25] VIOMMU: Add get irq info callback to convert irq remapping request
Quoted 20 lines · Roger Pau Monné
Quoted 19 lines · Lan Tianyu
This patch is to add
get_irq_infocallback for platform implementation to convert irq remapping request to irq info (E,G vector, dest,dest_modeand so on).Signed-off-by Lan Tianyu <[email protected]>--- xen/common/viommu.c | 16 ++++++++++++++++ xen/include/asm-x86/viommu.h | 8 ++++++++ xen/include/xen/viommu.h | 9 +++++++++ 3 files changed, 33 insertions(+)xen/common/viommu.c +0
-0@@ -213,6 +213,22 @@ int viommu_handle_irq_request(struct domain *d, u32 viommu_id,return info->viommu[viommu_id]->ops->handle_irq_request (d, request); }
Quoted 7 lines
xen/common/viommu.c int viommu_handle_irq_request(struct domain *d, u32 viommu_id, · line 218
Quoted 3 lines
xen/common/viommu.c +3
-0+int viommu_get_irq_info (struct domain *d,u32 viommu_id, +struct irq_remapping_request *request, +struct irq_remapping_info *irq_info)The definition of this struct seems to be arch-specific, in which case IMHO it should be called
arch_irq_remapping_info, in order to denote it's arch-specific.
OK. Will update.
Quoted 11 lines
xen/common/viommu.c int viommu_handle_irq_request(struct domain *d, u32 viommu_id, · line 223
Quoted 6 lines
xen/common/viommu.c +5
-0+{ +struct viommu_info *info = &d->viommu; + +if ( viommu_id >= info->nr_viommu + || !info->viommu[viommu_id] )Unneeded line break.
Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH V2 3/25] VIOMMU: Add get irq info callback to convert irq remapping request
In reply to Roger Pau MonnéQuoted 8 lines
Quoted 1 line
Quoted 1 line · On 22.08.17 at 17:38, <[email protected]> wrote:
Quoted 6 lines · Lan Tianyu
xen/common/viommu.c +0
-0@@ -213,6 +213,22 @@ int viommu_handle_irq_request(struct domain *d, u32 viommu_id,return info->viommu[viommu_id]->ops->handle_irq_request (d, request); }
Quoted 7 lines
xen/common/viommu.c int viommu_handle_irq_request(struct domain *d, u32 viommu_id, · line 218
Quoted 3 lines
xen/common/viommu.c +3
-0+int viommu_get_irq_info (struct domain *d,u32 viommu_id, +struct irq_remapping_request *request, +struct irq_remapping_info *irq_info)The definition of this struct seems to be arch-specific, in which case IMHO it should be called
arch_irq_remapping_info, in order to denote it's arch-specific.
In which case it also wouldn't belong in this file.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v2 4/25 Xen/doc: Add Xen virtual IOMMU doc
In reply to Lan TianyuThis patch is to add Xen virtual IOMMU doc to introduce motivation, framework, vIOMMU hypercall and xl configuration.
--- docs/misc/viommu.txt | 139 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 docs/misc/viommu.txt
docs/misc/viommu.txt new file +139 -0
@@ -0,0 +1,139 @@ +Xen virtual IOMMU + +Motivation +========== +*) Enable more than 255 vcpu support +HPC cloud service requires VM provides high performance parallel +computing and we hope to create a huge VM with >255 vcpu on one machine +to meet such requirement. Pin each vcpu to separate pcpus. + +To support >255 vcpus, X2APIC mode in guest is necessary because legacy +APIC(XAPIC) just supports 8-bit APIC ID and it only can support 255 +vcpus at most. X2APIC mode supports 32-bit APIC ID and it requires +interrupt mapping function of vIOMMU. + +The reason for this is that there is no modification to existing PCI MSI +and IOAPIC with the introduction of X2APIC. PCI MSI/IOAPIC can only send +interrupt message containing 8-bit APIC ID, which cannot address >255 +cpus. Interrupt remapping supports 32-bit APIC ID and so it's necessary +to enable >255 cpus with x2apic mode. + + +vIOMMU Architecture +=================== +vIOMMU device model is inside Xen hypervisor for following factors + 1) Avoid round trips between Qemu and Xen hypervisor + 2) Ease of integration with the rest of hypervisor + 3) HVMlite/PVH doesn't use Qemu + +* Interrupt remapping overview. +Interrupts from virtual devices and physical devices are delivered +to vLAPIC from vIOAPIC and vMSI. vIOMMU needs to remap interrupt during +this procedure. + ++---------------------------------------------------+ +|Qemu |VM | +| | +----------------+ | +| | | Device driver | | +| | +--------+-------+ | +| | ^ | +| +----------------+ | +--------+-------+ | +| | Virtual device | | | IRQ subsystem | | +| +-------+--------+ | +--------+-------+ | +| | | ^ | +| | | | | ++---------------------------+-----------------------+ +|hypervisor | | VIRQ | +| | +---------+--------+ | +| | | vLAPIC | | +| |VIRQ +---------+--------+ | +| | ^ | +| | | | +| | +---------+--------+ | +| | | vIOMMU | | +| | +---------+--------+ | +| | ^ | +| | | | +| | +---------+--------+ | +| | | vIOAPIC/vMSI | | +| | +----+----+--------+ | +| | ^ ^ | +| +-----------------+ | | +| | | ++---------------------------------------------------+ +HW |IRQ + +-------------------+ + | PCI Device | + +-------------------+ + + +vIOMMU hypercall +================ +Introduce new domctl hypercall "xen_domctl_viommu_op" to create/destroy +vIOMMU and query vIOMMU capabilities that device model can support. + +* vIOMMU hypercall parameter structure + +/* vIOMMU type - specify vendor vIOMMU device model */ +#define VIOMMU_TYPE_INTEL_VTD (1u << 0) + +/* vIOMMU capabilities */ +#define VIOMMU_CAP_IRQ_REMAPPING (1u << 0) + +struct xen_domctl_viommu_op { + uint32_t cmd; +#define XEN_DOMCTL_create_viommu 0 +#define XEN_DOMCTL_destroy_viommu 1 +#define XEN_DOMCTL_query_viommu_caps 2 + union { + struct { + /* IN - vIOMMU type */ + uint64_t viommu_type; + /* IN - MMIO base address of vIOMMU. */ + uint64_t base_address; + /* IN - Length of MMIO region */ + uint64_t length; + /* IN - Capabilities with which we want to create */ + uint64_t capabilities; + /* OUT - vIOMMU identity */ + uint32_t viommu_id; + } create_viommu; + + struct { + /* IN - vIOMMU identity */ + uint32_t viommu_id; + } destroy_viommu; + + struct { + /* IN - vIOMMU type */ + uint64_t viommu_type; + /* OUT - vIOMMU Capabilities */ + uint64_t capabilities; + } query_caps; + } u; +}; + +- XEN_DOMCTL_query_viommu_caps + Query capabilities of vIOMMU device model. vIOMMU_type specifies +which vendor vIOMMU device model(E,G Intel VTD) is targeted and hypervisor +returns capability bits(E,G interrupt remapping bit). + +- XEN_DOMCTL_create_viommu + Create vIOMMU device with vIOMMU_type, capabilities, MMIO +base address and length. Hypervisor returns viommu_id. Capabilities should +be in range of value returned by query_viommu_caps hypercall. + +- XEN_DOMCTL_destroy_viommu + Destroy vIOMMU in Xen hypervisor with viommu_id as parameters. + +Now just suppport single vIOMMU for one VM and introduced domtcls are compatible +with multi-vIOMMU support. + +xl vIOMMU configuration +======================= +viommu="type=intel_vtd,intremap=1,x2apic=1" + +"type" - Specify vIOMMU device model type. Currently only supports Intel vtd +device model. +"intremap" - Enable vIOMMU interrupt remapping function. +"x2apic" - Support x2apic mode with interrupt remapping function.
Signature · 7 lines
1.8.3.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH V2 4/25] Xen/doc: Add Xen virtual IOMMU doc
docs/misc/viommu.txt line 130
Quoted 2 lines · Lan Tianyu
docs/misc/viommu.txt new file +2
-0+Now just suppport single vIOMMU for one VM and introduced domtcls are compatible +with multi-vIOMMU support.
Is this still true? There is an ID field in the struct which can distinguish multiple viommus, right?
docs/misc/viommu.txt line 134
Quoted 4 lines
docs/misc/viommu.txt new file +4
-0+ +xl vIOMMU configuration +======================= +viommu="type=intel_vtd,intremap=1,x2apic=1"
If there is provision to support multiple viommu please make this an array.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH V2 4/25] Xen/doc: Add Xen virtual IOMMU doc
Quoted 5 lines · Wei Liu
Review
Quoted 2 lines · Lan Tianyu
(quoted diff) +2
-0+Now just suppport single vIOMMU for one VM and introduced domctls are compatible +with multi-vIOMMU support.Is this still true?
Yes, the patchset just supports single vIOMMU for one VM.
Quoted 2 lines
There is an ID field in the struct which can
distinguish multiple viommus, right?
Yes, this is reserved for mult vIOMMU support.
Quoted 8 lines
docs/misc/viommu.txt line 134
Quoted 5 lines
docs/misc/viommu.txt new file +4
-0+ +xl vIOMMU configuration +======================= +viommu="type=intel_vtd,intremap=1,x2apic=1"If there is provision to support multiple viommu please make this an array.
Ok. Will update.
Signature · 7 lines
Best regards Tianyu Lan _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH V2 4/25] Xen/doc: Add Xen virtual IOMMU doc
Quoted 9 lines · Lan Tianyu
Quoted 5 lines · Wei Liu
Review
Quoted 2 lines · Lan Tianyu
(quoted diff) +2
-0+Now just suppport single vIOMMU for one VM and introduced domctls are compatible +with multi-vIOMMU support.Is this still true?
Yes, the patchset just supports single vIOMMU for one VM.
The first part of the sentence is true, but the latter is probably not. It seems to me domctl is able to cope with multiple viommu. Please correct me if I'm wrong.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH V2 4/25] Xen/doc: Add Xen virtual IOMMU doc
Quoted 8 lines · Wei Liu
Quoted 7 lines · Lan Tianyu
Quoted 5 lines · Wei Liu
Review
Quoted 2 lines · Lan Tianyu
(quoted diff) +2
-0+Now just suppport single vIOMMU for one VM and introduced domctls are compatible +with multi-vIOMMU support.Is this still true?
Quoted 6 lines
Quoted 2 lines
Yes, the patchset just supports single vIOMMU for one VM.
The first part of the sentence is true, but the latter is probably not. It seems to me domctl is able to cope with multiple viommu. Please correct me if I'm wrong.
These domctl is able to support multiple vIOMMU but vIOMMU device model in Xen hypervisor only support single vIOMMU for one VM.
Signature · 7 lines
Best regards Tianyu Lan _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH V2 4/25] Xen/doc: Add Xen virtual IOMMU doc
Quoted 12 lines · Lan Tianyu
Quoted 11 lines · Wei Liu
Quoted 9 lines · Lan Tianyu
Quoted 5 lines · Wei Liu
Review
Quoted 2 lines · Lan Tianyu
(quoted diff) +2
-0+Now just suppport single vIOMMU for one VM and introduced domctls are compatible +with multi-vIOMMU support.Is this still true?
Yes, the patchset just supports single vIOMMU for one VM.
Quoted 7 lines
Quoted 3 lines
The first part of the sentence is true, but the latter is probably not. It seems to me domctl is able to cope with multiple viommu. Please correct me if I'm wrong.
These domctl is able to support multiple vIOMMU but vIOMMU device model in Xen hypervisor only support single vIOMMU for one VM.
In that case please update the document.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH V2 4/25] Xen/doc: Add Xen virtual IOMMU doc
Quoted 17 lines · Wei Liu
Quoted 16 lines · Lan Tianyu
Quoted 14 lines · Wei Liu
Quoted 9 lines · Lan Tianyu
Quoted 5 lines · Wei Liu
Review
Quoted 2 lines · Lan Tianyu
(quoted diff) +2
-0+Now just suppport single vIOMMU for one VM and introduced domctls are compatible +with multi-vIOMMU support.Is this still true?
Yes, the patchset just supports single vIOMMU for one VM.
The first part of the sentence is true, but the latter is probably not. It seems to me domctl is able to cope with multiple viommu. Please correct me if I'm wrong.
Quoted 6 lines
Quoted 3 lines
These domctl is able to support multiple vIOMMU but vIOMMU device model in Xen hypervisor only support single vIOMMU for one VM.
In that case please update the document.
OK. Will update.
Signature · 7 lines
Best regards Tianyu Lan _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH V2 4/25] Xen/doc: Add Xen virtual IOMMU doc
In reply to Lan Tianyudocs/misc/viommu.txt
Quoted 14 lines · Lan Tianyu
This patch is to add Xen virtual IOMMU doc to introduce motivation, framework, vIOMMU hypercall and xl configuration.
Signed-off-by Lan Tianyu <[email protected]>--- docs/misc/viommu.txt | 139 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 docs/misc/viommu.txtdocs/misc/viommu.txt new file +0
-0
IMHO, this should be the first patch in the series.
docs/misc/viommu.txt line 5
Quoted 6 lines
docs/misc/viommu.txt new file +5
-0@@ -0,0 +1,139 @@ +Xen virtual IOMMU + +Motivation +========== +*) Enable more than 255 vcpu support
Seems like the "*)" is some kind of leftover?
docs/misc/viommu.txt line 8
Quoted 3 lines
docs/misc/viommu.txt new file +3
-0+HPC cloud service requires VM provides high performance parallel +computing and we hope to create a huge VM with >255 vcpu on one machine +to meet such requirement. Pin each vcpu to separate pcpus.
I would re-write this as:
The current requirements of HPC cloud service requires VM with a high number of CPUs in order to achieve high performance in parallel computing.
Also, this is needed in order to create VMs with > 128 vCPUs, not 255 vCPUs. That's because the APIC ID used by Xen is CPU ID * 2 (ie: CPU 127 has APIC ID 254, which is the last one available in xAPIC mode). You should reword the paragraphs below in order to fix the mention of 255 vCPUs.
docs/misc/viommu.txt line 13
Quoted 5 lines
docs/misc/viommu.txt new file +5
-0+ +To support >255 vcpus, X2APIC mode in guest is necessary because legacy +APIC(XAPIC) just supports 8-bit APIC ID and it only can support 255 +vcpus at most. X2APIC mode supports 32-bit APIC ID and it requires +interrupt mapping function of vIOMMU.
Correct me if I'm wrong, but I don't think x2APIC requires vIOMMU. The IOMMU is required so that you can route interrupts to all the possible CPUs. One could image a setup where only CPUs with APIC IDs < 255 are used as targets of external interrupts, and that doesn't require a IOMMU.
Quoted 48 lines
docs/misc/viommu.txt new file +48
-0+The reason for this is that there is no modification to existing PCI MSI +and IOAPIC with the introduction of X2APIC. PCI MSI/IOAPIC can only send +interrupt message containing 8-bit APIC ID, which cannot address >255 +cpus. Interrupt remapping supports 32-bit APIC ID and so it's necessary +to enable >255 cpus with x2apic mode. + + +vIOMMU Architecture +=================== +vIOMMU device model is inside Xen hypervisor for following factors + 1) Avoid round trips between Qemu and Xen hypervisor + 2) Ease of integration with the rest of hypervisor + 3) HVMlite/PVH doesn't use Qemu + +* Interrupt remapping overview. +Interrupts from virtual devices and physical devices are delivered +to vLAPIC from vIOAPIC and vMSI. vIOMMU needs to remap interrupt during +this procedure. + ++---------------------------------------------------+ +|Qemu |VM | +| | +----------------+ | +| | | Device driver | | +| | +--------+-------+ | +| | ^ | +| +----------------+ | +--------+-------+ | +| | Virtual device | | | IRQ subsystem | | +| +-------+--------+ | +--------+-------+ | +| | | ^ | +| | | | | ++---------------------------+-----------------------+ +|hypervisor | | VIRQ | +| | +---------+--------+ | +| | | vLAPIC | | +| |VIRQ +---------+--------+ | +| | ^ | +| | | | +| | +---------+--------+ | +| | | vIOMMU | | +| | +---------+--------+ | +| | ^ | +| | | | +| | +---------+--------+ | +| | | vIOAPIC/vMSI | | +| | +----+----+--------+ | +| | ^ ^ | +| +-----------------+ | | +| | |
docs/misc/viommu.txt line 72
Quoted 10 lines
docs/misc/viommu.txt new file +10
-0++---------------------------------------------------+ +HW |IRQ + +-------------------+ + | PCI Device | + +-------------------+ + + +vIOMMU hypercall +================ +Introduce new domctl hypercall "xen_domctl_viommu_op" to create/destroy
^ a
docs/misc/viommu.txt line 73
Quoted 1 line
docs/misc/viommu.txt new file +1
-0+vIOMMU and query vIOMMU capabilities that device model can support.
^ s ^ the
Quoted 49 lines
docs/misc/viommu.txt new file +49
-0+ +* vIOMMU hypercall parameter structure + +/* vIOMMU type - specify vendor vIOMMU device model */ +#define VIOMMU_TYPE_INTEL_VTD (1u << 0) + +/* vIOMMU capabilities */ +#define VIOMMU_CAP_IRQ_REMAPPING (1u << 0) + +struct xen_domctl_viommu_op { + uint32_t cmd; +#define XEN_DOMCTL_create_viommu 0 +#define XEN_DOMCTL_destroy_viommu 1 +#define XEN_DOMCTL_query_viommu_caps 2 + union { + struct { + /* IN - vIOMMU type */ + uint64_t viommu_type; + /* IN - MMIO base address of vIOMMU. */ + uint64_t base_address; + /* IN - Length of MMIO region */ + uint64_t length; + /* IN - Capabilities with which we want to create */ + uint64_t capabilities; + /* OUT - vIOMMU identity */ + uint32_t viommu_id; + } create_viommu; + + struct { + /* IN - vIOMMU identity */ + uint32_t viommu_id; + } destroy_viommu; + + struct { + /* IN - vIOMMU type */ + uint64_t viommu_type; + /* OUT - vIOMMU Capabilities */ + uint64_t capabilities; + } query_caps; + } u; +}; + +- XEN_DOMCTL_query_viommu_caps + Query capabilities of vIOMMU device model. vIOMMU_type specifies +which vendor vIOMMU device model(E,G Intel VTD) is targeted and hypervisor +returns capability bits(E,G interrupt remapping bit). + +- XEN_DOMCTL_create_viommu + Create vIOMMU device with vIOMMU_type, capabilities, MMIO
docs/misc/viommu.txt line 132
Quoted 10 lines
docs/misc/viommu.txt new file +10
-0+base address and length. Hypervisor returns viommu_id. Capabilities should +be in range of value returned by query_viommu_caps hypercall. + +- XEN_DOMCTL_destroy_viommu + Destroy vIOMMU in Xen hypervisor with viommu_id as parameters. + +Now just suppport single vIOMMU for one VM and introduced domtcls are compatible +with multi-vIOMMU support. + +xl vIOMMU configuration
This should be "xl x86 vIOMMU configuration", since it's clearly x86 specific.
docs/misc/viommu.txt line 134
Quoted 2 lines
docs/misc/viommu.txt new file +2
-0+======================= +viommu="type=intel_vtd,intremap=1,x2apic=1"
Shouldn't this have some kind of array form? From the code I saw it seems like you are adding support for domains having multiple IOMMUs, in which case this should at least look like:
viommu = [
'type=intel_vtd,intremap=1,x2apic=1',
'type=intel_vtd,intremap=1,x2apic=1']
But then it's missing to which PCI bus each IOMMU is attached.
Also, why do you need the x2apic parameter? Is there any value in providing a vIOMMU if it doesn't support x2APIC mode?
Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH V2 4/25] Xen/doc: Add Xen virtual IOMMU doc
Quoted 10 lines · Roger Pau Monné
Quoted 9 lines · Lan Tianyu
This patch is to add Xen virtual IOMMU doc to introduce motivation, framework, vIOMMU hypercall and xl configuration.
Signed-off-by Lan Tianyu <[email protected]>--- docs/misc/viommu.txt | 139 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 docs/misc/viommu.txt
Quoted 7 lines
docs/misc/viommu.txt
Quoted 5 lines
docs/misc/viommu.txt new file +0
-0IMHO, this should be the first patch in the series.
OK. Will update.
Quoted 20 lines
docs/misc/viommu.txt line 5
Quoted 7 lines
docs/misc/viommu.txt new file +5
-0@@ -0,0 +1,139 @@ +Xen virtual IOMMU + +Motivation +========== +*) Enable more than 255 vcpu supportSeems like the "*)" is some kind of leftover?
docs/misc/viommu.txt line 8
Quoted 3 lines
docs/misc/viommu.txt new file +3
-0+HPC cloud service requires VM provides high performance parallel +computing and we hope to create a huge VM with >255 vcpu on one machine +to meet such requirement. Pin each vcpu to separate pcpus.I would re-write this as:
The current requirements of HPC cloud service requires VM with a high number of CPUs in order to achieve high performance in parallel computing.
Quoted 5 lines
Also, this is needed in order to create VMs with > 128 vCPUs, not 255 vCPUs. That's because the APIC ID used by Xen is CPU ID * 2 (ie: CPU 127 has APIC ID 254, which is the last one available in xAPIC mode). You should reword the paragraphs below in order to fix the mention of 255 vCPUs.
Thanks for your rewrite.
Quoted 12 lines
docs/misc/viommu.txt line 13
Quoted 6 lines
docs/misc/viommu.txt new file +5
-0+ +To support >255 vcpus, X2APIC mode in guest is necessary because legacy +APIC(XAPIC) just supports 8-bit APIC ID and it only can support 255 +vcpus at most. X2APIC mode supports 32-bit APIC ID and it requires +interrupt mapping function of vIOMMU.Correct me if I'm wrong, but I don't think x2APIC requires vIOMMU. The IOMMU is required so that you can route interrupts to all the possible CPUs. One could image a setup where only CPUs with APIC IDs < 255 are used as targets of external interrupts, and that doesn't require a IOMMU.
This is OS behavior. IIRC, Windows strictly requires IOMMU when enable x2apic mode and Linux kernel only has such requirement when cpu number is > 255.
Quoted 116 lines
Quoted 49 lines
docs/misc/viommu.txt new file +48
-0+The reason for this is that there is no modification to existing PCI MSI +and IOAPIC with the introduction of X2APIC. PCI MSI/IOAPIC can only send +interrupt message containing 8-bit APIC ID, which cannot address >255 +cpus. Interrupt remapping supports 32-bit APIC ID and so it's necessary +to enable >255 cpus with x2apic mode. + + +vIOMMU Architecture +=================== +vIOMMU device model is inside Xen hypervisor for following factors + 1) Avoid round trips between Qemu and Xen hypervisor + 2) Ease of integration with the rest of hypervisor + 3) HVMlite/PVH doesn't use Qemu + +* Interrupt remapping overview. +Interrupts from virtual devices and physical devices are delivered +to vLAPIC from vIOAPIC and vMSI. vIOMMU needs to remap interrupt during +this procedure. + ++---------------------------------------------------+ +|Qemu |VM | +| | +----------------+ | +| | | Device driver | | +| | +--------+-------+ | +| | ^ | +| +----------------+ | +--------+-------+ | +| | Virtual device | | | IRQ subsystem | | +| +-------+--------+ | +--------+-------+ | +| | | ^ | +| | | | | ++---------------------------+-----------------------+ +|hypervisor | | VIRQ | +| | +---------+--------+ | +| | | vLAPIC | | +| |VIRQ +---------+--------+ | +| | ^ | +| | | | +| | +---------+--------+ | +| | | vIOMMU | | +| | +---------+--------+ | +| | ^ | +| | | | +| | +---------+--------+ | +| | | vIOAPIC/vMSI | | +| | +----+----+--------+ | +| | ^ ^ | +| +-----------------+ | | +| | |docs/misc/viommu.txt line 72
Quoted 10 lines
docs/misc/viommu.txt new file +10
-0++---------------------------------------------------+ +HW |IRQ + +-------------------+ + | PCI Device | + +-------------------+ + + +vIOMMU hypercall +================ +Introduce new domctl hypercall "xen_domctl_viommu_op" to create/destroy^ adocs/misc/viommu.txt line 73
Quoted 1 line
docs/misc/viommu.txt new file +1
-0+vIOMMU and query vIOMMU capabilities that device model can support.^ s ^ the
Quoted 54 lines
docs/misc/viommu.txt new file +54
-0+ +* vIOMMU hypercall parameter structure + +/* vIOMMU type - specify vendor vIOMMU device model */ +#define VIOMMU_TYPE_INTEL_VTD (1u << 0) + +/* vIOMMU capabilities */ +#define VIOMMU_CAP_IRQ_REMAPPING (1u << 0) + +struct xen_domctl_viommu_op { + uint32_t cmd; +#define XEN_DOMCTL_create_viommu 0 +#define XEN_DOMCTL_destroy_viommu 1 +#define XEN_DOMCTL_query_viommu_caps 2 + union { + struct { + /* IN - vIOMMU type */ + uint64_t viommu_type; + /* IN - MMIO base address of vIOMMU. */ + uint64_t base_address; + /* IN - Length of MMIO region */ + uint64_t length; + /* IN - Capabilities with which we want to create */ + uint64_t capabilities; + /* OUT - vIOMMU identity */ + uint32_t viommu_id; + } create_viommu; + + struct { + /* IN - vIOMMU identity */ + uint32_t viommu_id; + } destroy_viommu; + + struct { + /* IN - vIOMMU type */ + uint64_t viommu_type; + /* OUT - vIOMMU Capabilities */ + uint64_t capabilities; + } query_caps; + } u; +}; + +- XEN_DOMCTL_query_viommu_caps + Query capabilities of vIOMMU device model. vIOMMU_type specifies +which vendor vIOMMU device model(E,G Intel VTD) is targeted and hypervisor +returns capability bits(E,G interrupt remapping bit). + +- XEN_DOMCTL_create_viommu + Create vIOMMU device with vIOMMU_type, capabilities, MMIO +base address and length. Hypervisor returns viommu_id. Capabilities should +be in range of value returned by query_viommu_caps hypercall. + +- XEN_DOMCTL_destroy_viommu + Destroy vIOMMU in Xen hypervisor with viommu_id as parameters.
Quoted 8 lines
docs/misc/viommu.txt line 132
Quoted 5 lines
docs/misc/viommu.txt new file +5
-0+ +Now just suppport single vIOMMU for one VM and introduced domtcls are compatible +with multi-vIOMMU support. + +xl vIOMMU configurationThis should be "xl x86 vIOMMU configuration", since it's clearly x86 specific.
OK. Will update.
Quoted 7 lines
docs/misc/viommu.txt line 134
Quoted 3 lines
docs/misc/viommu.txt new file +2
-0+======================= +viommu="type=intel_vtd,intremap=1,x2apic=1"Shouldn't this have some kind of array form? From the code I saw it seems like you are adding support for domains having multiple IOMMUs, in which case this should at least look like:
No, we don't support mult-vIOMMU but some vIOMMU data structure is defined with multi-vIOMMU consideration.
Quoted 6 lines
viommu = [
'type=intel_vtd,intremap=1,x2apic=1', 'type=intel_vtd,intremap=1,x2apic=1']
Wei also suggested this. Will update.
Quoted 1 line
But then it's missing to which PCI bus each IOMMU is attached.
This will be added if we really need to support multi vIOMMU.
Quoted 3 lines
Also, why do you need the x2apic parameter? Is there any value in providing a vIOMMU if it doesn't support x2APIC mode?
User can configure whether vIOMMU can support x2APIC mode and tool stack will use this configuration to prepare ACPI DMAR table. There is an X2APIC_OPT_OUT bit in DMAR table to tell OS not enable X2APIC mode for IOMMU.
Quoted 3 lines
Roger.
Signature · 7 lines
Best regards Tianyu Lan _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH V2 4/25] Xen/doc: Add Xen virtual IOMMU doc
Quoted 28 lines · Lan Tianyu
Quoted 10 lines · Roger Pau Monné
Quoted 9 lines · Lan Tianyu
This patch is to add Xen virtual IOMMU doc to introduce motivation, framework, vIOMMU hypercall and xl configuration.
Signed-off-by Lan Tianyu <[email protected]>--- docs/misc/viommu.txt | 139 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 docs/misc/viommu.txtQuoted 16 lines
docs/misc/viommu.txt line 13
Quoted 10 lines
docs/misc/viommu.txt new file +5
-0+ +To support >255 vcpus, X2APIC mode in guest is necessary because legacy +APIC(XAPIC) just supports 8-bit APIC ID and it only can support 255 +vcpus at most. X2APIC mode supports 32-bit APIC ID and it requires +interrupt mapping function of vIOMMU.Correct me if I'm wrong, but I don't think x2APIC requires vIOMMU. The IOMMU is required so that you can route interrupts to all the possible CPUs. One could image a setup where only CPUs with APIC IDs < 255 are used as targets of external interrupts, and that doesn't require a IOMMU.
Quoted 3 lines
This is OS behavior. IIRC, Windows strictly requires IOMMU when enable x2apic mode and Linux kernel only has such requirement when cpu number is > 255.
But this document doesn't speak about OSes, it speaks about the IOMMU implementation. What I think is wrong is the following sentence:
"x2APIC mode supports 32-bit APIC ID and it requires interrupt mapping function of vIOMMU."
IMHO it should be:
"x2APIC mode supports 32-bit APIC ID and it requires the interrupt remapping functionality of a vIOMMU if the guest wishes to route interrupts to all available vCPUs."
Quoted 8 lines
Quoted 3 lines
Also, why do you need the x2apic parameter? Is there any value in providing a vIOMMU if it doesn't support x2APIC mode?
User can configure whether vIOMMU can support x2APIC mode and tool stack will use this configuration to prepare ACPI DMAR table. There is an
X2APIC_OPT_OUTbit in DMAR table to tell OS not enable X2APIC mode for IOMMU.
Let me rephrase my question, what's the value in implementing the xAPIC support for vIOMMU?
The vIOMMU work is done so that Xen can create guests with > 128 vCPUs (> 255 APIC IDs), at which point you _must_ use x2APIC mode. Is there any value is providing a vIOMMU implementation that doesn't support x2APIC?
Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v2 5/25 tools/libxc: Add viommu operations in libxc
In reply to Lan TianyuFrom: Chao Gao <[email protected]>
This patch adds XEN_DOMCTL_viommu_op hypercall. This hypercall comprises three sub-command:
- query capabilities of one specific type vIOMMU emulated by Xen
- create vIOMMU in Xen hypervisor, given viommu type, register-set location and capabilities
- destroy vIOMMU specified by viommu_id
--- tools/libxc/Makefile | 1 + tools/libxc/include/xenctrl.h | 8 +++++ tools/libxc/xc_viommu.c | 81 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 tools/libxc/xc_viommu.c
tools/libxc/Makefile +1 -0
@@ -51,6 +51,7 @@ CTRL_SRCS-$(CONFIG_MiniOS) += xc_minios.c CTRL_SRCS-y += xc_evtchn_compat.c CTRL_SRCS-y += xc_gnttab_compat.c CTRL_SRCS-y += xc_devicemodel_compat.c +CTRL_SRCS-y += xc_viommu.c GUEST_SRCS-y := GUEST_SRCS-y += xg_private.c xc_suspend.c
tools/libxc/include/xenctrl.h +8 -0
@@ -27,6 +27,7 @@#define __XEN_TOOLS__ 1#endif +#include <errno.h> #include <unistd.h> #include <stddef.h> #include <stdint.h>
@@ -2499,6 +2500,13 @@ enum xc_static_cpu_featuremask {const uint32_t *xc_get_static_cpu_featuremask (enum xc_static_cpu_featuremask );const uint32_t *xc_get_feature_deep_deps (uint32_t feature); +int xc_viommu_query_cap (xc_interface *xch,domid_t dom, +uint64_t type,uint64_t *cap); +int xc_viommu_create (xc_interface *xch,domid_t dom,uint64_t type, +uint64_t base_addr,uint64_t length,uint64_t cap, +uint32_t *viommu_id); +int xc_viommu_destroy (xc_interface *xch,domid_t dom,uint32_t viommu_id); +#endif int xc_livepatch_upload(xc_interface *xch,
tools/libxc/xc_viommu.c new file +81 -0
81 lines not on this page · raw message
Signature · 7 lines
1.8.3.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH V2 5/25] tools/libxc: Add viommu operations in libxc
Quoted 11 lines · Lan Tianyu
From: Chao Gao <[email protected]>
This patch adds
XEN_DOMCTL_viommu_ophypercall. This hypercall comprises three sub-command:
- query capabilities of one specific type vIOMMU emulated by Xen
- create vIOMMU in Xen hypervisor, given viommu type, register-set location and capabilities
- destroy vIOMMU specified byviommu_idSigned-off-by Chao Gao <[email protected]>Signed-off-by Lan Tianyu <[email protected]>
This needs to get rebased in accordance with the proposed name changes in the struct.
tools/libxc/xc_viommu.c line 30
Quoted 11 lines
tools/libxc/xc_viommu.c new file +11
-0+ +#include "xc_private.h" + +int xc_viommu_query_cap (xc_interface *xch,domid_t dom, +uint64_t type,uint64_t *cap) +{ +int rc; +DECLARE_DOMCTL ; + + domctl.cmd = XEN_DOMCTL_viommu_op; + domctl.domain = (domid_t )dom;
Pointless cast here and below.
tools/libxc/xc_viommu.c line 36
Quoted 6 lines
tools/libxc/xc_viommu.c new file +6
-0+ domctl.u.viommu_op.cmd = XEN_DOMCTL_query_viommu_caps; + domctl.u.viommu_op.u.query_caps.viommu_type = type; + + rc =do_domctl (xch, &domctl); +if ( !rc ) + *cap = domctl.u.viommu_op.u.query_caps.capabilities;
Blank line here please.
Quoted 11 lines
tools/libxc/xc_viommu.c new file +11
-0+return rc; +} + +int xc_viommu_create (xc_interface *xch,domid_t dom,uint64_t type, +uint64_t base_addr,uint64_t length,uint64_t cap, +uint32_t *viommu_id) +{ +int rc; +DECLARE_DOMCTL ; + + domctl.cmd = XEN_DOMCTL_viommu_op;
tools/libxc/xc_viommu.c line 57
Quoted 10 lines
tools/libxc/xc_viommu.c new file +10
-0+ domctl.domain = (domid_t )dom; + domctl.u.viommu_op.cmd = XEN_DOMCTL_create_viommu; + domctl.u.viommu_op.u.create_viommu.viommu_type = type; + domctl.u.viommu_op.u.create_viommu.base_address = base_addr; + domctl.u.viommu_op.u.create_viommu.length = length; + domctl.u.viommu_op.u.create_viommu.capabilities = cap; + + rc =do_domctl (xch, &domctl); +if ( !rc ) + *viommu_id = domctl.u.viommu_op.u.create_viommu.viommu_id;
Ditto.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH V2 5/25] tools/libxc: Add viommu operations in libxc
In reply to Lan TianyuQuoted 4 lines · Lan Tianyu
From: Chao Gao <[email protected]>
This patch adds
XEN_DOMCTL_viommu_ophypercall. This hypercall comprises three sub-command:
^ s
Quoted 1 line
- query capabilities of one specific type vIOMMU emulated by Xen
^ of
Quoted 1 line
- create vIOMMU in Xen hypervisor, given viommu type, register-set location
^ a ^s/hypervisor//
Quoted 2 lines
and capabilities
- destroy vIOMMU specified byviommu_id
^ a
Quoted 27 lines
Signed-off-by Chao Gao <[email protected]>Signed-off-by Lan Tianyu <[email protected]>--- tools/libxc/Makefile | 1 + tools/libxc/include/xenctrl.h | 8 +++++ tools/libxc/xc_viommu.c | 81 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 tools/libxc/xc_viommu.ctools/libxc/Makefile +1
-0@@ -51,6 +51,7 @@ CTRL_SRCS-$(CONFIG_MiniOS) += xc_minios.c CTRL_SRCS-y += xc_evtchn_compat.c CTRL_SRCS-y += xc_gnttab_compat.c CTRL_SRCS-y += xc_devicemodel_compat.c +CTRL_SRCS-y += xc_viommu.c GUEST_SRCS-y := GUEST_SRCS-y += xg_private.c xc_suspend.ctools/libxc/include/xenctrl.h +0
-0
tools/libxc/include/xenctrl.h line 30
Quoted 4 lines
tools/libxc/include/xenctrl.h +1
-0@@ -27,6 +27,7 @@#define __XEN_TOOLS__ 1#endif +#include <errno.h>
I don't see the need for this include.
Quoted 43 lines
tools/libxc/include/xenctrl.h +7
-0#include <unistd.h> #include <stddef.h> #include <stdint.h> @@ -2499,6 +2500,13 @@ enum xc_static_cpu_featuremask {const uint32_t *xc_get_static_cpu_featuremask (enum xc_static_cpu_featuremask );const uint32_t *xc_get_feature_deep_deps (uint32_t feature); +int xc_viommu_query_cap (xc_interface *xch,domid_t dom, +uint64_t type,uint64_t *cap); +int xc_viommu_create (xc_interface *xch,domid_t dom,uint64_t type, +uint64_t base_addr,uint64_t length,uint64_t cap, +uint32_t *viommu_id); +int xc_viommu_destroy (xc_interface *xch,domid_t dom,uint32_t viommu_id); +#endif int xc_livepatch_upload(xc_interface *xch,tools/libxc/xc_viommu.c new file +20
-0@@ -0,0 +1,81 @@ +/* +* xc_viommu.c +* +* viommu related API functions. +* +* Copyright (C) 2017 Intel Corporation +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License, version 2.1, as published by the Free Software Foundation. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; If not, see <http://www.gnu.org/licenses/>. +*/ +
tools/libxc/xc_viommu.c line 30
Quoted 10 lines
tools/libxc/xc_viommu.c new file +10
-0+#include "xc_private.h" + +int xc_viommu_query_cap (xc_interface *xch,domid_t dom, +uint64_t type,uint64_t *cap) +{ +int rc; +DECLARE_DOMCTL ; + + domctl.cmd = XEN_DOMCTL_viommu_op; + domctl.domain = (domid_t )dom;
Pointless cast.
Quoted 8 lines
tools/libxc/xc_viommu.c new file +8
-0+ domctl.u.viommu_op.cmd = XEN_DOMCTL_query_viommu_caps; + domctl.u.viommu_op.u.query_caps.viommu_type = type; + + rc =do_domctl (xch, &domctl); +if ( !rc ) + *cap = domctl.u.viommu_op.u.query_caps.capabilities; +return rc; +}
tools/libxc/xc_viommu.c line 48
Quoted 10 lines
tools/libxc/xc_viommu.c new file +10
-0+ +int xc_viommu_create (xc_interface *xch,domid_t dom,uint64_t type, +uint64_t base_addr,uint64_t length,uint64_t cap, +uint32_t *viommu_id) +{ +int rc; +DECLARE_DOMCTL ; + + domctl.cmd = XEN_DOMCTL_viommu_op; + domctl.domain = (domid_t )dom;
Pointless cast.
Quoted 41 lines
tools/libxc/xc_viommu.c new file +33
-0+ domctl.u.viommu_op.cmd = XEN_DOMCTL_create_viommu; + domctl.u.viommu_op.u.create_viommu.viommu_type = type; + domctl.u.viommu_op.u.create_viommu.base_address = base_addr; + domctl.u.viommu_op.u.create_viommu.length = length; + domctl.u.viommu_op.u.create_viommu.capabilities = cap; + + rc =do_domctl (xch, &domctl); +if ( !rc ) + *viommu_id = domctl.u.viommu_op.u.create_viommu.viommu_id; +return rc; +} + +int xc_viommu_destroy (xc_interface *xch,domid_t dom,uint32_t viommu_id) +{ +DECLARE_DOMCTL ; + + domctl.cmd = XEN_DOMCTL_viommu_op; + domctl.domain = (domid_t )dom; + domctl.u.viommu_op.cmd = XEN_DOMCTL_destroy_viommu; + domctl.u.viommu_op.u.destroy_viommu.viommu_id = viommu_id; + +return do_domctl (xch, &domctl); +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/ Signature · 7 lines
1.8.3.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v2 6/25 tools/libacpi: Add DMA remapping reporting (DMAR) ACPI table structures
In reply to Lan TianyuFrom: Chao Gao <[email protected]>
Add dmar table structure according Chapter 8 "BIOS Considerations" of VTd spec Rev. 2.4.
--- tools/libacpi/acpi2_0.h | 61 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+)
tools/libacpi/acpi2_0.h +61 -0
@@ -422,6 +422,65 @@ struct acpi_20_slit { };/* +* DMA Remapping Table header definition (DMAR) +*/ + +/* +* DMAR Flags. +*/ +#define ACPI_DMAR_INTR_REMAP (1 << 0) +#define ACPI_DMAR_X2APIC_OPT_OUT (1 << 1) + +struct acpi_dmar { +struct acpi_header header; +uint8_t host_address_width; +uint8_t flags; +uint8_t reserved[10 ]; +}; + +/* +* Device Scope Types +*/ +#define ACPI_DMAR_DEVICE_SCOPE_PCI_ENDPOINT 0x01 +#define ACPI_DMAR_DEVICE_SCOPE_PCI_SUB_HIERARACHY 0x01 +#define ACPI_DMAR_DEVICE_SCOPE_IOAPIC 0x03 +#define ACPI_DMAR_DEVICE_SCOPE_HPET 0x04 +#define ACPI_DMAR_DEVICE_SCOPE_ACPI_NAMESPACE_DEVICE 0x05 + +struct dmar_device_scope { +uint8_t type; +uint8_t length; +uint8_t reserved[2 ]; +uint8_t enumeration_id; +uint8_t bus; +uint16_t path[0 ]; +}; + +/* +* DMA Remapping Hardware Unit Types +*/ +#define ACPI_DMAR_TYPE_HARDWARE_UNIT 0x00 +#define ACPI_DMAR_TYPE_RESERVED_MEMORY 0x01 +#define ACPI_DMAR_TYPE_ATSR 0x02 +#define ACPI_DMAR_TYPE_HARDWARE_AFFINITY 0x03 +#define ACPI_DMAR_TYPE_ANDD 0x04 + +/* +* DMA Remapping Hardware Unit Flags. All other bits are reserved and must be 0. +*/ +#define ACPI_DMAR_INCLUDE_PCI_ALL (1 << 0) + +struct acpi_dmar_hardware_unit { +uint16_t type; +uint16_t length; +uint8_t flags; +uint8_t reserved; +uint16_t pci_segment; +uint64_t base_address; +struct dmar_device_scope scope[0 ]; +}; + +/* * Table Signatures. */ #define ACPI_2_0_RSDP_SIGNATURE ASCII64('R','S','D',' ','P','T','R',' ')
@@ -435,6 +494,7 @@ struct acpi_20_slit {#define ACPI_2_0_WAET_SIGNATURE ASCII32('W','A','E','T')#define ACPI_2_0_SRAT_SIGNATURE ASCII32('S','R','A','T')#define ACPI_2_0_SLIT_SIGNATURE ASCII32('S','L','I','T') +#define ACPI_2_0_DMAR_SIGNATURE ASCII32('D','M','A','R')/* * Table revision numbers.
@@ -449,6 +509,7 @@ struct acpi_20_slit {#define ACPI_1_0_FADT_REVISION 0x01#define ACPI_2_0_SRAT_REVISION 0x01#define ACPI_2_0_SLIT_REVISION 0x01 +#define ACPI_2_0_DMAR_REVISION 0x01#pragma pack ()
Signature · 7 lines
1.8.3.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH V2 6/25] tools/libacpi: Add DMA remapping reporting (DMAR) ACPI table structures
Quoted 9 lines · Lan Tianyu
From: Chao Gao <[email protected]>
Add dmar table structure according Chapter 8 "BIOS Considerations" of VTd spec Rev. 2.4.
Signed-off-by Chao Gao <[email protected]>Signed-off-by Lan Tianyu <[email protected]>
I check the spec and the content, they match.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH V2 6/25] tools/libacpi: Add DMA remapping reporting (DMAR) ACPI table structures
Quoted 6 lines · Wei Liu
Quoted 5 lines · Lan Tianyu
From: Chao Gao <[email protected]>
Add dmar table structure according Chapter 8 "BIOS Considerations" of VTd spec Rev. 2.4.
Quoted 7 lines
Quoted 4 lines
Signed-off-by Chao Gao <[email protected]>Signed-off-by Lan Tianyu <[email protected]>I check the spec and the content, they match.
Thanks.
Signature · 7 lines
Best regards Tianyu Lan _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH v2 7/25 tools/libacpi: Add new fields in acpi_config for DMAR table
In reply to Lan TianyuFrom: Chao Gao <[email protected]>
The BIOS reports the remapping hardware units in a platform to system software through the DMA Remapping Reporting (DMAR) ACPI table.
New fields are introduces for DMAR table. These new fields are set by toolstack through parsing guest's config file. construct_dmar() is added to build DMAR table according to the new fields.
--- tools/libacpi/build.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ tools/libacpi/libacpi.h | 9 ++++++++ 2 files changed, 66 insertions(+)
tools/libacpi/build.c +57 -0
@@ -28,6 +28,10 @@#define ACPI_MAX_SECONDARY_TABLES 16 +#define VTD_HOST_ADDRESS_WIDTH 39 +#define I440_PSEUDO_BUS_PLATFORM 0xff +#define I440_PSEUDO_DEVFN_IOAPIC 0x0 +#define align16 (sz) (((sz) + 15) & ~15)#define fixed_strcpy (d, s) strncpy((d), (s), sizeof(d))
@@ -303,6 +307,59 @@ static struct acpi_20_slit *construct_slit(struct acpi_ctxt *ctxt,return slit; } +/* +* Only one DMA remapping hardware unit is exposed and all devices +* are under the remapping hardware unit. I/O APIC should be explicitly +* enumerated. +*/ +struct acpi_dmar *construct_dmar (struct acpi_ctxt *ctxt, +const struct acpi_config *config) +{ +struct acpi_dmar *dmar; +struct acpi_dmar_hardware_unit *drhd; +struct dmar_device_scope *scope; +unsigned int size; +unsigned int ioapic_scope_size =sizeof (*scope) +sizeof (scope->path[0 ]); + + size =sizeof (*dmar) +sizeof (*drhd) + ioapic_scope_size; + + dmar = ctxt->mem_ops.alloc (ctxt, size,16 ); +if ( !dmar ) +return NULL ; + +memset (dmar,0 , size); + dmar->header.signature =ACPI_2_0_DMAR_SIGNATURE ; + dmar->header.revision =ACPI_2_0_DMAR_REVISION ; + dmar->header.length = size; +fixed_strcpy (dmar->header.oem_id,ACPI_OEM_ID ); +fixed_strcpy (dmar->header.oem_table_id,ACPI_OEM_TABLE_ID ); + dmar->header.oem_revision =ACPI_OEM_REVISION ; + dmar->header.creator_id =ACPI_CREATOR_ID ; + dmar->header.creator_revision =ACPI_CREATOR_REVISION ; + dmar->host_address_width =VTD_HOST_ADDRESS_WIDTH -1 ; +if ( config->iommu_intremap_supported ) + dmar->flags =ACPI_DMAR_INTR_REMAP ; +if ( !config->iommu_x2apic_supported ) + dmar->flags |=ACPI_DMAR_X2APIC_OPT_OUT ; + + drhd = (struct acpi_dmar_hardware_unit *)((void *)dmar +sizeof (*dmar)); + drhd->type =ACPI_DMAR_TYPE_HARDWARE_UNIT ; + drhd->length =sizeof (*drhd) + ioapic_scope_size; + drhd->flags =ACPI_DMAR_INCLUDE_PCI_ALL ; + drhd->pci_segment =0 ; + drhd->base_address = config->iommu_base_addr; + + scope = &drhd->scope[0 ]; + scope->type =ACPI_DMAR_DEVICE_SCOPE_IOAPIC ; + scope->length = ioapic_scope_size; + scope->enumeration_id = config->ioapic_id; + scope->bus =I440_PSEUDO_BUS_PLATFORM ; + scope->path[0 ] =I440_PSEUDO_DEVFN_IOAPIC ; + +set_checksum (dmar, offsetof(struct acpi_header , checksum), size); +return dmar; +} + static int construct_passthrough_tables(struct acpi_ctxt *ctxt, unsigned long *table_ptrs, int nr_tables,
tools/libacpi/libacpi.h +9 -0
@@ -20,6 +20,8 @@#ifndef __LIBACPI_H__#define __LIBACPI_H__ +#include <stdbool.h> +#define ACPI_HAS_COM1 (1<<0)#define ACPI_HAS_COM2 (1<<1)#define ACPI_HAS_LPT1 (1<<2)
@@ -96,8 +98,15 @@ struct acpi_config {uint32_t ioapic_base_address;uint16_t pci_isa_irq_mask;uint8_t ioapic_id; + +/* Emulated IOMMU features and location */ +bool iommu_intremap_supported; +bool iommu_x2apic_supported; + uint64_t iommu_base_addr; }; +struct acpi_dmar *construct_dmar (struct acpi_ctxt *ctxt, +const struct acpi_config *config);int acpi_build_tables (struct acpi_ctxt *ctxt,struct acpi_config *config);#endif /* __LIBACPI_H__ */
Signature · 7 lines
1.8.3.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH V2 7/25] tools/libacpi: Add new fields in acpi_config for DMAR table
Quoted 20 lines · Lan Tianyu
From: Chao Gao <[email protected]>
The BIOS reports the remapping hardware units in a platform to system software through the DMA Remapping Reporting (DMAR) ACPI table.
New fields are introduces for DMAR table. These new fields are set by toolstack through parsing guest's config file.construct_dmar()is added to build DMAR table according to the new fields.Signed-off-by Chao Gao <[email protected]>Signed-off-by Lan Tianyu <[email protected]>--- tools/libacpi/build.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ tools/libacpi/libacpi.h | 9 ++++++++ 2 files changed, 66 insertions(+)tools/libacpi/build.c +0
-0
tools/libacpi/build.c line 33
Quoted 6 lines
tools/libacpi/build.c +3
-0@@ -28,6 +28,10 @@#define ACPI_MAX_SECONDARY_TABLES 16 +#define VTD_HOST_ADDRESS_WIDTH 39 +#define I440_PSEUDO_BUS_PLATFORM 0xff +#define I440_PSEUDO_DEVFN_IOAPIC 0x0
I have some stupid questions. What are these I440 values? Where do they come from?
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH V2 7/25] tools/libacpi: Add new fields in acpi_config for DMAR table
Quoted 22 lines · Wei Liu
Quoted 21 lines · Lan Tianyu
From: Chao Gao <[email protected]>
The BIOS reports the remapping hardware units in a platform to system software through the DMA Remapping Reporting (DMAR) ACPI table.
New fields are introduces for DMAR table. These new fields are set by toolstack through parsing guest's config file.construct_dmar()is added to build DMAR table according to the new fields.Signed-off-by Chao Gao <[email protected]>Signed-off-by Lan Tianyu <[email protected]>--- tools/libacpi/build.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ tools/libacpi/libacpi.h | 9 ++++++++ 2 files changed, 66 insertions(+)tools/libacpi/build.c +0
-0@@ -28,6 +28,10 @@
Quoted 9 lines
tools/libacpi/build.c line 33
Quoted 5 lines
tools/libacpi/build.c +3
-0#define ACPI_MAX_SECONDARY_TABLES 16 +#define VTD_HOST_ADDRESS_WIDTH 39 +#define I440_PSEUDO_BUS_PLATFORM 0xff +#define I440_PSEUDO_DEVFN_IOAPIC 0x0I have some stupid questions. What are these I440 values? Where do they come from?
Each IOAPIC device in the system reported via ACPI MADT must be explicitly enumerated under one specific remapping hardware unit. We assigned IOAPCI unit to bdf ff:00 and referenced Qemu vIOMMU implementation.
Signature · 7 lines
Best regards Tianyu Lan _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH V2 7/25] tools/libacpi: Add new fields in acpi_config for DMAR table
Quoted 33 lines · Lan Tianyu
Quoted 22 lines · Wei Liu
Quoted 21 lines · Lan Tianyu
From: Chao Gao <[email protected]>
The BIOS reports the remapping hardware units in a platform to system software through the DMA Remapping Reporting (DMAR) ACPI table.
New fields are introduces for DMAR table. These new fields are set by toolstack through parsing guest's config file.construct_dmar()is added to build DMAR table according to the new fields.Signed-off-by Chao Gao <[email protected]>Signed-off-by Lan Tianyu <[email protected]>--- tools/libacpi/build.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ tools/libacpi/libacpi.h | 9 ++++++++ 2 files changed, 66 insertions(+)tools/libacpi/build.c +0
-0@@ -28,6 +28,10 @@Quoted 9 lines
tools/libacpi/build.c line 33
Quoted 5 lines
tools/libacpi/build.c +3
-0#define ACPI_MAX_SECONDARY_TABLES 16 +#define VTD_HOST_ADDRESS_WIDTH 39 +#define I440_PSEUDO_BUS_PLATFORM 0xff +#define I440_PSEUDO_DEVFN_IOAPIC 0x0I have some stupid questions. What are these I440 values? Where do they come from?
Quoted 3 lines
Each IOAPIC device in the system reported via ACPI MADT must be explicitly enumerated under one specific remapping hardware unit. We assigned IOAPCI unit to bdf ff:00 and referenced Qemu vIOMMU implementation.
OK, do they need to be somewhere in a public header?
(See Roger's comment in the other sub-thread)
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH V2 7/25] tools/libacpi: Add new fields in acpi_config for DMAR table
In reply to Lan TianyuQuoted 5 lines · Lan Tianyu
From: Chao Gao <[email protected]>
The BIOS reports the remapping hardware units in a platform to system software through the DMA Remapping Reporting (DMAR) ACPI table.
New fields are introduces for DMAR table. These new fields are set by
^ s/s/d/ to libacpi
Quoted 15 lines
toolstack through parsing guest's config file.
construct_dmar()is added to build DMAR table according to the new fields.Signed-off-by Chao Gao <[email protected]>Signed-off-by Lan Tianyu <[email protected]>--- tools/libacpi/build.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ tools/libacpi/libacpi.h | 9 ++++++++ 2 files changed, 66 insertions(+)tools/libacpi/build.c +0
-0
tools/libacpi/build.c line 29
Quoted 2 lines
tools/libacpi/build.c +0
-0@@ -28,6 +28,10 @@#define ACPI_MAX_SECONDARY_TABLES 16
A comment about the meaning of the defines below might be helpful.
Quoted 33 lines
tools/libacpi/build.c +26
-0+#define VTD_HOST_ADDRESS_WIDTH 39 +#define I440_PSEUDO_BUS_PLATFORM 0xff +#define I440_PSEUDO_DEVFN_IOAPIC 0x0 +#define align16 (sz) (((sz) + 15) & ~15)#define fixed_strcpy (d, s) strncpy((d), (s), sizeof(d))@@ -303,6 +307,59 @@ static struct acpi_20_slit *construct_slit(struct acpi_ctxt *ctxt,return slit; } +/* +* Only one DMA remapping hardware unit is exposed and all devices +* are under the remapping hardware unit. I/O APIC should be explicitly +* enumerated. +*/ +struct acpi_dmar *construct_dmar (struct acpi_ctxt *ctxt, +const struct acpi_config *config) +{ +struct acpi_dmar *dmar; +struct acpi_dmar_hardware_unit *drhd; +struct dmar_device_scope *scope; +unsigned int size; +unsigned int ioapic_scope_size =sizeof (*scope) +sizeof (scope->path[0 ]); + + size =sizeof (*dmar) +sizeof (*drhd) + ioapic_scope_size; + + dmar = ctxt->mem_ops.alloc (ctxt, size,16 ); +if ( !dmar ) +return NULL ; + +memset (dmar,0 , size); + dmar->header.signature =ACPI_2_0_DMAR_SIGNATURE ;
tools/libacpi/build.c static struct acpi_20_slit *construct_slit(struct acpi_ctxt *ctxt, · line 341
Quoted 10 lines
tools/libacpi/build.c +10
-0+ dmar->header.revision =ACPI_2_0_DMAR_REVISION ; + dmar->header.length = size; +fixed_strcpy (dmar->header.oem_id,ACPI_OEM_ID ); +fixed_strcpy (dmar->header.oem_table_id,ACPI_OEM_TABLE_ID ); + dmar->header.oem_revision =ACPI_OEM_REVISION ; + dmar->header.creator_id =ACPI_CREATOR_ID ; + dmar->header.creator_revision =ACPI_CREATOR_REVISION ; + dmar->host_address_width =VTD_HOST_ADDRESS_WIDTH -1 ; +if ( config->iommu_intremap_supported ) + dmar->flags =ACPI_DMAR_INTR_REMAP ;
Since you initialize flags to 0 I would use |= here, in case this gets moved later and this is not the first flag to be set.
tools/libacpi/build.c static struct acpi_20_slit *construct_slit(struct acpi_ctxt *ctxt, · line 343
Quoted 2 lines
tools/libacpi/build.c +2
-0+if ( !config->iommu_x2apic_supported ) + dmar->flags |=ACPI_DMAR_X2APIC_OPT_OUT ;
I'm not sure of the reason behind not supporting x2APIC mode (I've already commented in another patch).
tools/libacpi/build.c static struct acpi_20_slit *construct_slit(struct acpi_ctxt *ctxt, · line 357
Quoted 13 lines
tools/libacpi/build.c +13
-0+ drhd = (struct acpi_dmar_hardware_unit *)((void *)dmar +sizeof (*dmar)); + drhd->type =ACPI_DMAR_TYPE_HARDWARE_UNIT ; + drhd->length =sizeof (*drhd) + ioapic_scope_size; + drhd->flags =ACPI_DMAR_INCLUDE_PCI_ALL ; + drhd->pci_segment =0 ; + drhd->base_address = config->iommu_base_addr; + + scope = &drhd->scope[0 ]; + scope->type =ACPI_DMAR_DEVICE_SCOPE_IOAPIC ; + scope->length = ioapic_scope_size; + scope->enumeration_id = config->ioapic_id; + scope->bus =I440_PSEUDO_BUS_PLATFORM ; + scope->path[0 ] =I440_PSEUDO_DEVFN_IOAPIC ;
I'm not sure whether this constants should instead be fields in the acpi_config struct passed down from libxl. libxc shouldn't really need to know anything about which chipset a VM is using.
Quoted 44 lines
tools/libacpi/build.c +4
-0+set_checksum (dmar, offsetof(struct acpi_header , checksum), size); +return dmar; +} + static int construct_passthrough_tables(struct acpi_ctxt *ctxt, unsigned long *table_ptrs, int nr_tables,tools/libacpi/libacpi.h +9
-0@@ -20,6 +20,8 @@#ifndef __LIBACPI_H__#define __LIBACPI_H__ +#include <stdbool.h> +#define ACPI_HAS_COM1 (1<<0)#define ACPI_HAS_COM2 (1<<1)#define ACPI_HAS_LPT1 (1<<2)@@ -96,8 +98,15 @@ struct acpi_config {uint32_t ioapic_base_address;uint16_t pci_isa_irq_mask;uint8_t ioapic_id; + +/* Emulated IOMMU features and location */ +bool iommu_intremap_supported; +bool iommu_x2apic_supported; + uint64_t iommu_base_addr; }; +struct acpi_dmar *construct_dmar (struct acpi_ctxt *ctxt, +const struct acpi_config *config);int acpi_build_tables (struct acpi_ctxt *ctxt,struct acpi_config *config);#endif /* __LIBACPI_H__ */ Signature · 7 lines
1.8.3.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH V2 7/25] tools/libacpi: Add new fields in acpi_config for DMAR table
Quoted 13 lines · Roger Pau Monné
Quoted 5 lines
Quoted 5 lines
tools/libacpi/build.c +5
-0+ drhd = (struct acpi_dmar_hardware_unit *)((void *)dmar +sizeof (*dmar)); + drhd->type =ACPI_DMAR_TYPE_HARDWARE_UNIT ; + drhd->length =sizeof (*drhd) + ioapic_scope_size; + drhd->flags =ACPI_DMAR_INCLUDE_PCI_ALL ; + drhd->pci_segment =0 ;Quoted 8 lines
tools/libacpi/build.c static struct acpi_20_slit *construct_slit(struct acpi_ctxt *ctxt, · line 357
Quoted 8 lines
tools/libacpi/build.c +8
-0+ drhd->base_address = config->iommu_base_addr; + + scope = &drhd->scope[0 ]; + scope->type =ACPI_DMAR_DEVICE_SCOPE_IOAPIC ; + scope->length = ioapic_scope_size; + scope->enumeration_id = config->ioapic_id; + scope->bus =I440_PSEUDO_BUS_PLATFORM ; + scope->path[0 ] =I440_PSEUDO_DEVFN_IOAPIC ;
Quoted 3 lines
I'm not sure whether this constants should instead be fields in the
acpi_configstruct passed down from libxl. libxc shouldn't really need to know anything about which chipset a VM is using.
How about rename I440_PSEUDO_XXX to VIOMMU_PSEUDO_XXX?
Signature · 7 lines
Best regards Tianyu Lan _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH V2 7/25] tools/libacpi: Add new fields in acpi_config for DMAR table
Quoted 14 lines · Lan Tianyu
Quoted 13 lines · Roger Pau Monné
Quoted 13 lines
Quoted 13 lines
tools/libacpi/build.c +13
-0+ drhd = (struct acpi_dmar_hardware_unit *)((void *)dmar +sizeof (*dmar)); + drhd->type =ACPI_DMAR_TYPE_HARDWARE_UNIT ; + drhd->length =sizeof (*drhd) + ioapic_scope_size; + drhd->flags =ACPI_DMAR_INCLUDE_PCI_ALL ; + drhd->pci_segment =0 ; + drhd->base_address = config->iommu_base_addr; + + scope = &drhd->scope[0 ]; + scope->type =ACPI_DMAR_DEVICE_SCOPE_IOAPIC ; + scope->length = ioapic_scope_size; + scope->enumeration_id = config->ioapic_id; + scope->bus =I440_PSEUDO_BUS_PLATFORM ; + scope->path[0 ] =I440_PSEUDO_DEVFN_IOAPIC ;
Quoted 5 lines
Quoted 3 lines
I'm not sure whether this constants should instead be fields in the
acpi_configstruct passed down from libxl. libxc shouldn't really need to know anything about which chipset a VM is using.How about rename
I440_PSEUDO_XXXtoVIOMMU_PSEUDO_XXX?
I'm not really complaining about the naming, I'm just saying that I'm not sure whether this constants should live in libxl. It would be better IMHO if they where defined in some libxl x86 specific header, and passed to libxc inside of the acpi_config struct.
At the end it is libxl which decides which chipset the VM is going to use, not libxc.
Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH V2 7/25] tools/libacpi: Add new fields in acpi_config for DMAR table
Small mistake in my message.
Quoted 15 lines · Roger Pau Monné
Quoted 14 lines · Lan Tianyu
Quoted 13 lines · Roger Pau Monné
Quoted 13 lines
Quoted 13 lines
tools/libacpi/build.c +13
-0+ drhd = (struct acpi_dmar_hardware_unit *)((void *)dmar +sizeof (*dmar)); + drhd->type =ACPI_DMAR_TYPE_HARDWARE_UNIT ; + drhd->length =sizeof (*drhd) + ioapic_scope_size; + drhd->flags =ACPI_DMAR_INCLUDE_PCI_ALL ; + drhd->pci_segment =0 ; + drhd->base_address = config->iommu_base_addr; + + scope = &drhd->scope[0 ]; + scope->type =ACPI_DMAR_DEVICE_SCOPE_IOAPIC ; + scope->length = ioapic_scope_size; + scope->enumeration_id = config->ioapic_id; + scope->bus =I440_PSEUDO_BUS_PLATFORM ; + scope->path[0 ] =I440_PSEUDO_DEVFN_IOAPIC ;
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
I'm not sure whether this constants should instead be fields in the
acpi_configstruct passed down from libxl. libxc shouldn't really need to know anything about which chipset a VM is using.How about rename
I440_PSEUDO_XXXtoVIOMMU_PSEUDO_XXX?I'm not really complaining about the naming, I'm just saying that I'm not sure whether this constants should live in libxl. It would be
^ libxc
Quoted 6 lines
better IMHO if they where defined in some libxl x86 specific header, and passed to libxc inside of the
acpi_configstruct.At the end it is libxl which decides which chipset the VM is going to use, not libxc.
Quoted 6 lines
Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH V2 7/25] tools/libacpi: Add new fields in acpi_config for DMAR table
In reply to Roger Pau MonnéQuoted 21 lines · Roger Pau Monné
Quoted 14 lines · Lan Tianyu
Quoted 13 lines · Roger Pau Monné
Quoted 13 lines
Quoted 13 lines
tools/libacpi/build.c +13
-0+ drhd = (struct acpi_dmar_hardware_unit *)((void *)dmar +sizeof (*dmar)); + drhd->type =ACPI_DMAR_TYPE_HARDWARE_UNIT ; + drhd->length =sizeof (*drhd) + ioapic_scope_size; + drhd->flags =ACPI_DMAR_INCLUDE_PCI_ALL ; + drhd->pci_segment =0 ; + drhd->base_address = config->iommu_base_addr; + + scope = &drhd->scope[0 ]; + scope->type =ACPI_DMAR_DEVICE_SCOPE_IOAPIC ; + scope->length = ioapic_scope_size; + scope->enumeration_id = config->ioapic_id; + scope->bus =I440_PSEUDO_BUS_PLATFORM ; + scope->path[0 ] =I440_PSEUDO_DEVFN_IOAPIC ;Quoted 5 lines
Quoted 3 lines
I'm not sure whether this constants should instead be fields in the
acpi_configstruct passed down from libxl. libxc shouldn't really need to know anything about which chipset a VM is using.How about rename
I440_PSEUDO_XXXtoVIOMMU_PSEUDO_XXX?
Quoted 7 lines
I'm not really complaining about the naming, I'm just saying that I'm not sure whether this constants should live in libxl. It would be better IMHO if they where defined in some libxl x86 specific header, and passed to libxc inside of the
acpi_configstruct.At the end it is libxl which decides which chipset the VM is going to use, not libxc.
We can do that but the bdf is reserved for IOAPIC and should be same for different chipset. Do we still need to pass it via acpi_config?
Quoted 3 lines
Roger.
Signature · 7 lines
Best regards Tianyu Lan _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH V2 7/25] tools/libacpi: Add new fields in acpi_config for DMAR table
Quoted 28 lines
Quoted 1 line
Quoted 1 line · On 24.08.17 at 04:33, <[email protected]> wrote:
Quoted 26 lines · Roger Pau Monné
Quoted 14 lines · Lan Tianyu
Quoted 13 lines · Roger Pau Monné
Quoted 13 lines
Quoted 13 lines
tools/libacpi/build.c +13
-0+ drhd = (struct acpi_dmar_hardware_unit *)((void *)dmar +sizeof (*dmar)); + drhd->type =ACPI_DMAR_TYPE_HARDWARE_UNIT ; + drhd->length =sizeof (*drhd) + ioapic_scope_size; + drhd->flags =ACPI_DMAR_INCLUDE_PCI_ALL ; + drhd->pci_segment =0 ; + drhd->base_address = config->iommu_base_addr; + + scope = &drhd->scope[0 ]; + scope->type =ACPI_DMAR_DEVICE_SCOPE_IOAPIC ; + scope->length = ioapic_scope_size; + scope->enumeration_id = config->ioapic_id; + scope->bus =I440_PSEUDO_BUS_PLATFORM ; + scope->path[0 ] =I440_PSEUDO_DEVFN_IOAPIC ;Quoted 5 lines
Quoted 3 lines
I'm not sure whether this constants should instead be fields in the
acpi_configstruct passed down from libxl. libxc shouldn't really need to know anything about which chipset a VM is using.How about rename
I440_PSEUDO_XXXtoVIOMMU_PSEUDO_XXX?I'm not really complaining about the naming, I'm just saying that I'm not sure whether this constants should live in libxl. It would be better IMHO if they where defined in some libxl x86 specific header, and passed to libxc inside of the
acpi_configstruct.
Quoted 5 lines
Quoted 2 lines
At the end it is libxl which decides which chipset the VM is going to use, not libxc.
We can do that but the bdf is reserved for IOAPIC and should be same for different chipset. Do we still need to pass it via
acpi_config?
Well, which value is the right (reserved) one surely can - at least in theory - depend on the chipset. Which means that it should come from the same place which determines the chipset to be emulated for the guest.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH V2 7/25] tools/libacpi: Add new fields in acpi_config for DMAR table
Quoted 31 lines · Jan Beulich
Quoted 31 lines
Quoted 1 line
Quoted 1 line · On 24.08.17 at 04:33, <[email protected]> wrote:
Quoted 28 lines · Roger Pau Monné
Quoted 14 lines · Lan Tianyu
Quoted 13 lines · Roger Pau Monné
Quoted 13 lines
Quoted 13 lines
tools/libacpi/build.c +13
-0+ drhd = (struct acpi_dmar_hardware_unit *)((void *)dmar +sizeof (*dmar)); + drhd->type =ACPI_DMAR_TYPE_HARDWARE_UNIT ; + drhd->length =sizeof (*drhd) + ioapic_scope_size; + drhd->flags =ACPI_DMAR_INCLUDE_PCI_ALL ; + drhd->pci_segment =0 ; + drhd->base_address = config->iommu_base_addr; + + scope = &drhd->scope[0 ]; + scope->type =ACPI_DMAR_DEVICE_SCOPE_IOAPIC ; + scope->length = ioapic_scope_size; + scope->enumeration_id = config->ioapic_id; + scope->bus =I440_PSEUDO_BUS_PLATFORM ; + scope->path[0 ] =I440_PSEUDO_DEVFN_IOAPIC ;Quoted 5 lines
Quoted 3 lines
I'm not sure whether this constants should instead be fields in the
acpi_configstruct passed down from libxl. libxc shouldn't really need to know anything about which chipset a VM is using.How about rename
I440_PSEUDO_XXXtoVIOMMU_PSEUDO_XXX?I'm not really complaining about the naming, I'm just saying that I'm not sure whether this constants should live in libxl. It would be better IMHO if they where defined in some libxl x86 specific header, and passed to libxc inside of the
acpi_configstruct.At the end it is libxl which decides which chipset the VM is going to use, not libxc.
Quoted 8 lines
Quoted 2 lines
We can do that but the bdf is reserved for IOAPIC and should be same for different chipset. Do we still need to pass it via
acpi_config?Well, which value is the right (reserved) one surely can - at least in theory - depend on the chipset. Which means that it should come from the same place which determines the chipset to be emulated for the guest.
OK. Will update.
Signature · 7 lines
Best regards Tianyu Lan _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH v2 8/25 tools/libxl: Add a user configurable parameter to control vIOMMU attributes
In reply to Lan TianyuFrom: Chao Gao <[email protected]>
A field, viommu_info, is added to struct libxl_domain_build_info. Several attributes can be specified by guest config file for virtual IOMMU. These attributes are used for DMAR construction and vIOMMU creation.
--- docs/man/xl.cfg.pod.5.in | 34 ++++++++++++++++++++++- tools/libxl/libxl_types.idl | 16 +++++++++++ tools/xl/xl_parse.c | 66 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 115 insertions(+), 1 deletion(-)
docs/man/xl.cfg.pod.5.in +33 -1
@@ -1545,7 +1545,39 @@ Do not provide a VM generation ID. See also "Virtual Machine Generation ID" by Microsoft: L<http://www.microsoft.com/en-us/download/details.aspx?id=30707> -=back +=back + +=item B<viommu="VIOMMU_STRING"> + +Specifies the vIOMMU which are to be provided to the guest. + +B<VIOMMU_STRING> has the form C<KEY=VALUE,KEY=VALUE,...> where: + +=over 4 + +=item B<KEY=VALUE> + +Possible B<KEY>s are: + +=over 4 + +=item B<type="STRING"> + +Currently there is only one valid type: + +(x86 only) "intel_vtd" means providing a emulated Intel VT-d to the guest. + +=item B<intremap=BOOLEAN> + +Specifies whether the vIOMMU should support interrupt remapping +and default 'true'. + +=item B<x2apic=BOOLEAN> + +Specifies whether the vIOMMU should support x2apic mode and default 'true'. +Only valid for "intel_vtd". + +=back =head3 Guest Virtual Time Controls
tools/libxl/libxl_types.idl +16 -0
@@ -450,6 +450,21 @@ libxl_altp2m_mode = Enumeration("altp2m_mode", [ (3, "limited"), ], init_val = "LIBXL_ALTP2M_MODE_DISABLED") +libxl_viommu_type = Enumeration("viommu_type", [ + (1, "intel_vtd"), + ]) + +libxl_viommu_info = Struct("viommu_info", [ + ("u", KeyedUnion(None, libxl_viommu_type, "type", + [("intel_vtd", Struct(None, [ + ("x2apic", libxl_defbool)])) + ])), + ("intremap", libxl_defbool), + ("cap", uint64), + ("base_addr", uint64), + ("len", uint64), + ]) + libxl_domain_build_info = Struct("domain_build_info",[ ("max_vcpus", integer), ("avail_vcpus", libxl_bitmap),
@@ -506,6 +521,7 @@ libxl_domain_build_info = Struct("domain_build_info",[ # 65000 which is reserved by the toolstack. ("device_tree", string), ("acpi", libxl_defbool), + ("viommu", libxl_viommu_info), ("u", KeyedUnion(None, libxl_domain_type, "type", [("hvm", Struct(None, [("firmware", string), ("bios", libxl_bios_type),
tools/xl/xl_parse.c +66 -0
90 lines not on this page · raw message
Signature · 7 lines
1.8.3.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH V2 8/25] tools/libxl: Add a user configurable parameter to control vIOMMU attributes
Quoted 1 line · Lan Tianyu
From: Chao Gao <[email protected]>
[...]
Quoted 22 lines
-=back
+=backdocs/man/xl.cfg.pod.5.in +20
-0+ +=item B<viommu="VIOMMU_STRING"> + +Specifies the vIOMMU which are to be provided to the guest. + +B<VIOMMU_STRING> has the form C<KEY=VALUE,KEY=VALUE,...> where: + +=over 4 + +=item B<KEY=VALUE> + +Possible B<KEY>s are: + +=over 4 + +=item B<type="STRING"> + +Currently there is only one valid type: + +(x86 only) "intel_vtd" means providing a emulated Intel VT-d to the guest.
docs/man/xl.cfg.pod.5.in Do not provide a VM generation ID. · line 1578
Quoted 10 lines
docs/man/xl.cfg.pod.5.in +10
-0+ +=item B<intremap=BOOLEAN> + +Specifies whether the vIOMMU should support interrupt remapping +and default 'true'. + +=item B<x2apic=BOOLEAN> + +Specifies whether the vIOMMU should support x2apic mode and default 'true'. +Only valid for "intel_vtd".
Why not expose base address and length as well?
Quoted 32 lines
docs/man/xl.cfg.pod.5.in +2
-0+ +=back =head3 Guest Virtual Time Controlstools/libxl/libxl_types.idl +15
-0@@ -450,6 +450,21 @@ libxl_altp2m_mode = Enumeration("altp2m_mode", [ (3, "limited"), ], init_val = "LIBXL_ALTP2M_MODE_DISABLED") +libxl_viommu_type = Enumeration("viommu_type", [ + (1, "intel_vtd"), + ]) + +libxl_viommu_info = Struct("viommu_info", [ + ("u", KeyedUnion(None, libxl_viommu_type, "type", + [("intel_vtd", Struct(None, [ + ("x2apic", libxl_defbool)])) + ])), + ("intremap", libxl_defbool), + ("cap", uint64), + ("base_addr", uint64), + ("len", uint64), + ]) + libxl_domain_build_info = Struct("domain_build_info",[ ("max_vcpus", integer), ("avail_vcpus", libxl_bitmap),
tools/libxl/libxl_types.idl libxl_domain_build_info = Struct("domain_build_info",[ · line 524
Quoted 4 lines
tools/libxl/libxl_types.idl +1
-0@@ -506,6 +521,7 @@ libxl_domain_build_info = Struct("domain_build_info",[ # 65000 which is reserved by the toolstack. ("device_tree", string), ("acpi", libxl_defbool), + ("viommu", libxl_viommu_info),
An array please, we shouldn't limit the number of viommus.
tools/xl/xl_parse.c line 20
Quoted 12 lines
tools/libxl/libxl_types.idl +0
-0("u", KeyedUnion(None, libxl_domain_type, "type", [("hvm", Struct(None, [("firmware", string), ("bios", libxl_bios_type),tools/xl/xl_parse.c +1
-0@@ -17,6 +17,7 @@#include <limits.h> #include <stdio.h> #include <stdlib.h> +#include <xen/domctl.h>
Why is this needed?
Quoted 56 lines
tools/xl/xl_parse.c +42
-0#include <xen/hvm/e820.h> #include <xen/hvm/params.h> @@ -30,6 +31,9 @@extern void set_default_nic_values (libxl_device_nic *nic); +#define VIOMMU_VTD_BASE_ADDR 0xfed90000ULL +#define VIOMMU_VTD_REGISTER_LEN 0x1000ULL +#define ARRAY_EXTEND_INIT__CORE (array,count,initfn,more) \ ({ \ typeof((count)) array_extend_old_count = (count); \@@ -804,6 +808,61 @@ int parse_usbdev_config(libxl_device_usbdev *usbdev, char *token)return 0 ; } +/* Parses viommu data and adds info into viommu +* Returns 1 if the input doesn't form a valid viommu +* or parsed values are not correct. Successful parse returns 0 */ +static int parse_viommu_config (libxl_viommu_info *viommu,const char *info) +{ +char *ptr, *oparg, *saveptr =NULL , *buf =xstrdup (info); + + ptr =strtok_r (buf,"," , &saveptr); +if (MATCH_OPTION ("type" , ptr, oparg)) { +if (!strcmp (oparg,"intel_vtd" )) { + viommu->type =LIBXL_VIOMMU_TYPE_INTEL_VTD ; + }else { +fprintf (stderr,"Invalid viommu type: %s\n" , oparg); +return 1 ; + } + }else { +fprintf (stderr,"viommu type should be set first: %s\n" , oparg); +return 1 ; + } + + ptr =strtok_r (NULL ,"," , &saveptr); +if (MATCH_OPTION ("intremap" , ptr, oparg)) { +libxl_defbool_set (&viommu->intremap, !!strtoul (oparg,NULL ,0 )); + } + +if (viommu->type ==LIBXL_VIOMMU_TYPE_INTEL_VTD ) { +for (ptr =strtok_r (NULL ,"," , &saveptr); ptr; + ptr =strtok_r (NULL ,"," , &saveptr)) { +if (MATCH_OPTION ("x2apic" , ptr, oparg)) { +libxl_defbool_set (&viommu->u.intel_vtd.x2apic, + !!strtoul (oparg,NULL ,0 )); + }else { +fprintf (stderr,"Unknown string `%s' in viommu spec\n" , ptr); +return 1 ; + } + } + +if (libxl_defbool_is_default (viommu->intremap)) +libxl_defbool_set (&viommu->intremap, true);
tools/xl/xl_parse.c int parse_usbdev_config(libxl_device_usbdev *usbdev, char *token) · line 859
Quoted 10 lines
tools/xl/xl_parse.c +10
-0+ +if (!libxl_defbool_val (viommu->intremap)) { +fprintf (stderr,"Cannot create one virtual VTD without intremap\n" ); +return 1 ; + } + +/* Set default values to unexposed fields */ + viommu->base_addr =VIOMMU_VTD_BASE_ADDR ; + viommu->len =VIOMMU_VTD_REGISTER_LEN ; +
You're doing this is xl. This is not right. The default value should be set from within libxl.
You should have a libxl_XXX_setdefault function for this type.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH V2 8/25] tools/libxl: Add a user configurable parameter to control vIOMMU attributes
Quoted 16 lines · Wei Liu
Quoted 16 lines
+=over 4
Quoted 15 lines
docs/man/xl.cfg.pod.5.in +15
-0+ +=item B<KEY=VALUE> + +Possible B<KEY>s are: + +=over 4 + +=item B<type="STRING"> + +Currently there is only one valid type: + +(x86 only) "intel_vtd" means providing a emulated Intel VT-d to the guest. + +=item B<intremap=BOOLEAN> +
Quoted 8 lines
Quoted 7 lines
docs/man/xl.cfg.pod.5.in Do not provide a VM generation ID. · line 1578
Quoted 7 lines
docs/man/xl.cfg.pod.5.in +7
-0+Specifies whether the vIOMMU should support interrupt remapping +and default 'true'. + +=item B<x2apic=BOOLEAN> + +Specifies whether the vIOMMU should support x2apic mode and default 'true'. +Only valid for "intel_vtd".Why not expose base address and length as well?
"base address" and "length" of vIOMMU register region is low level vIOMMU configuration. I am afraid users is vary hard to determine which region is suitable for vIOMMU and doesn't conflict with other device model.
Quoted 52 lines
Quoted 13 lines
+
Quoted 11 lines
tools/libxl/libxl_types.idl +11
-0+libxl_viommu_info = Struct("viommu_info", [ + ("u", KeyedUnion(None, libxl_viommu_type, "type", + [("intel_vtd", Struct(None, [ + ("x2apic", libxl_defbool)])) + ])), + ("intremap", libxl_defbool), + ("cap", uint64), + ("base_addr", uint64), + ("len", uint64), + ]) +Quoted 8 lines
tools/libxl/libxl_types.idl libxl_domain_build_info = Struct("domain_build_info",[ · line 524
Quoted 8 lines
libxl_domain_build_info= Struct("domain_build_info",[
("max_vcpus", integer),
("avail_vcpus",libxl_bitmap),tools/libxl/libxl_types.idl +1
-0@@ -506,6 +521,7 @@ libxl_domain_build_info = Struct("domain_build_info",[ # 65000 which is reserved by the toolstack. ("device_tree", string), ("acpi", libxl_defbool), + ("viommu", libxl_viommu_info),An array please, we shouldn't limit the number of viommus.
Quoted 4 lines
Quoted 4 lines
tools/libxl/libxl_types.idl +0
-0("u", KeyedUnion(None, libxl_domain_type, "type", [("hvm", Struct(None, [("firmware", string), ("bios", libxl_bios_type),tools/xl/xl_parse.c +0
-0Quoted 8 lines
tools/xl/xl_parse.c line 20
Quoted 8 lines
index 5c2bf17..11c4eb2 100644
tools/xl/xl_parse.c +1
-0@@ -17,6 +17,7 @@#include <limits.h> #include <stdio.h> #include <stdlib.h> +#include <xen/domctl.h> Why is this needed?
Quoted 4 lines
Quoted 4 lines
tools/xl/xl_parse.c +4
-0+if (libxl_defbool_is_default (viommu->intremap)) +libxl_defbool_set (&viommu->intremap, true); + +if (!libxl_defbool_val (viommu->intremap)) {Quoted 8 lines
tools/xl/xl_parse.c int parse_usbdev_config(libxl_device_usbdev *usbdev, char *token) · line 859
Quoted 8 lines
tools/xl/xl_parse.c +8
-0+fprintf (stderr,"Cannot create one virtual VTD without intremap\n" ); +return 1 ; + } + +/* Set default values to unexposed fields */ + viommu->base_addr =VIOMMU_VTD_BASE_ADDR ; + viommu->len =VIOMMU_VTD_REGISTER_LEN ; +You're doing this is xl. This is not right. The default value should be set from within libxl.
Quoted 1 line
You should have a
libxl_XXX_setdefaultfunction for this type.
OK. will update.
Signature · 7 lines
Best regards Tianyu Lan _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH V2 8/25] tools/libxl: Add a user configurable parameter to control vIOMMU attributes
Quoted 26 lines · Lan Tianyu
Quoted 16 lines · Wei Liu
Quoted 16 lines
+=over 4
Quoted 15 lines
docs/man/xl.cfg.pod.5.in +15
-0+ +=item B<KEY=VALUE> + +Possible B<KEY>s are: + +=over 4 + +=item B<type="STRING"> + +Currently there is only one valid type: + +(x86 only) "intel_vtd" means providing a emulated Intel VT-d to the guest. + +=item B<intremap=BOOLEAN> +Quoted 8 lines
Quoted 7 lines
docs/man/xl.cfg.pod.5.in Do not provide a VM generation ID. · line 1578
Quoted 7 lines
docs/man/xl.cfg.pod.5.in +7
-0+Specifies whether the vIOMMU should support interrupt remapping +and default 'true'. + +=item B<x2apic=BOOLEAN> + +Specifies whether the vIOMMU should support x2apic mode and default 'true'. +Only valid for "intel_vtd".Why not expose base address and length as well?
Quoted 3 lines
"base address" and "length" of vIOMMU register region is low level vIOMMU configuration. I am afraid users is vary hard to determine which region is suitable for vIOMMU and doesn't conflict with other device model.
That's fair. Assuming those two values are hardware specific (as I read in another sub-thread) I'm fine with not exposing them (should they be needed at all).
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH V2 8/25] tools/libxl: Add a user configurable parameter to control vIOMMU attributes
In reply to Lan TianyuQuoted 19 lines · Lan Tianyu
From: Chao Gao <[email protected]>
A field,
viommu_info, is added to structlibxl_domain_build_info. Several attributes can be specified by guest config file for virtual IOMMU. These attributes are used for DMAR construction and vIOMMU creation.Signed-off-by Chao Gao <[email protected]>Signed-off-by Lan Tianyu <[email protected]>--- docs/man/xl.cfg.pod.5.in | 34 ++++++++++++++++++++++- tools/libxl/libxl_types.idl | 16 +++++++++++ tools/xl/xl_parse.c | 66 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 115 insertions(+), 1 deletion(-)docs/man/xl.cfg.pod.5.in +0
-0
docs/man/xl.cfg.pod.5.in Do not provide a VM generation ID. · line 1548
Quoted 5 lines
docs/man/xl.cfg.pod.5.in +1
-1@@ -1545,7 +1545,39 @@ Do not provide a VM generation ID. See also "Virtual Machine Generation ID" by Microsoft: L<http://www.microsoft.com/en-us/download/details.aspx?id=30707> -=back +=back
No spurious changes. Leave the extra " " as is.
docs/man/xl.cfg.pod.5.in Do not provide a VM generation ID. · line 1554
Quoted 6 lines
docs/man/xl.cfg.pod.5.in +6
-0+ +=item B<viommu="VIOMMU_STRING"> + +Specifies the vIOMMU which are to be provided to the guest. + +B<VIOMMU_STRING> has the form C<KEY=VALUE,KEY=VALUE,...> where:
Should be an array of VIOMMU_STRINGs instead.
docs/man/xl.cfg.pod.5.in Do not provide a VM generation ID. · line 1568
Quoted 13 lines
docs/man/xl.cfg.pod.5.in +13
-0+=over 4 + +=item B<KEY=VALUE> + +Possible B<KEY>s are: + +=over 4 + +=item B<type="STRING"> + +Currently there is only one valid type: + +(x86 only) "intel_vtd" means providing a emulated Intel VT-d to the guest.
^ an
Quoted 62 lines
docs/man/xl.cfg.pod.5.in +12
-0+ +=item B<intremap=BOOLEAN> + +Specifies whether the vIOMMU should support interrupt remapping +and default 'true'. + +=item B<x2apic=BOOLEAN> + +Specifies whether the vIOMMU should support x2apic mode and default 'true'. +Only valid for "intel_vtd". + +=back =head3 Guest Virtual Time Controlstools/libxl/libxl_types.idl +16
-0@@ -450,6 +450,21 @@ libxl_altp2m_mode = Enumeration("altp2m_mode", [ (3, "limited"), ], init_val = "LIBXL_ALTP2M_MODE_DISABLED") +libxl_viommu_type = Enumeration("viommu_type", [ + (1, "intel_vtd"), + ]) + +libxl_viommu_info = Struct("viommu_info", [ + ("u", KeyedUnion(None, libxl_viommu_type, "type", + [("intel_vtd", Struct(None, [ + ("x2apic", libxl_defbool)])) + ])), + ("intremap", libxl_defbool), + ("cap", uint64), + ("base_addr", uint64), + ("len", uint64), + ]) + libxl_domain_build_info = Struct("domain_build_info",[ ("max_vcpus", integer), ("avail_vcpus", libxl_bitmap),@@ -506,6 +521,7 @@ libxl_domain_build_info = Struct("domain_build_info",[ # 65000 which is reserved by the toolstack. ("device_tree", string), ("acpi", libxl_defbool), + ("viommu", libxl_viommu_info), ("u", KeyedUnion(None, libxl_domain_type, "type", [("hvm", Struct(None, [("firmware", string), ("bios", libxl_bios_type),tools/xl/xl_parse.c +1
-0@@ -17,6 +17,7 @@#include <limits.h> #include <stdio.h> #include <stdlib.h> +#include <xen/domctl.h> #include <xen/hvm/e820.h> #include <xen/hvm/params.h>
tools/xl/xl_parse.c line 35
Quoted 5 lines
tools/xl/xl_parse.c +2
-0@@ -30,6 +31,9 @@extern void set_default_nic_values (libxl_device_nic *nic); +#define VIOMMU_VTD_BASE_ADDR 0xfed90000ULL +#define VIOMMU_VTD_REGISTER_LEN 0x1000ULL
I don't think those defines should be here at all.
Quoted 30 lines
tools/xl/xl_parse.c +23
-0#define ARRAY_EXTEND_INIT__CORE (array,count,initfn,more) \ ({ \ typeof((count)) array_extend_old_count = (count); \@@ -804,6 +808,61 @@ int parse_usbdev_config(libxl_device_usbdev *usbdev, char *token)return 0 ; } +/* Parses viommu data and adds info into viommu +* Returns 1 if the input doesn't form a valid viommu +* or parsed values are not correct. Successful parse returns 0 */ +static int parse_viommu_config (libxl_viommu_info *viommu,const char *info) +{ +char *ptr, *oparg, *saveptr =NULL , *buf =xstrdup (info); + + ptr =strtok_r (buf,"," , &saveptr); +if (MATCH_OPTION ("type" , ptr, oparg)) { +if (!strcmp (oparg,"intel_vtd" )) { + viommu->type =LIBXL_VIOMMU_TYPE_INTEL_VTD ; + }else { +fprintf (stderr,"Invalid viommu type: %s\n" , oparg); +return 1 ; + } + }else { +fprintf (stderr,"viommu type should be set first: %s\n" , oparg); +return 1 ; + } + + ptr =strtok_r (NULL ,"," , &saveptr); +if (MATCH_OPTION ("intremap" , ptr, oparg)) { +libxl_defbool_set (&viommu->intremap, !!strtoul (oparg,NULL ,0 ));
tools/xl/xl_parse.c int parse_usbdev_config(libxl_device_usbdev *usbdev, char *token) · line 843
Quoted 10 lines
tools/xl/xl_parse.c +10
-0+ } + +if (viommu->type ==LIBXL_VIOMMU_TYPE_INTEL_VTD ) { +for (ptr =strtok_r (NULL ,"," , &saveptr); ptr; + ptr =strtok_r (NULL ,"," , &saveptr)) { +if (MATCH_OPTION ("x2apic" , ptr, oparg)) { +libxl_defbool_set (&viommu->u.intel_vtd.x2apic, + !!strtoul (oparg,NULL ,0 )); + }else { +fprintf (stderr,"Unknown string `%s' in viommu spec\n" , ptr);
^ '
tools/xl/xl_parse.c int parse_usbdev_config(libxl_device_usbdev *usbdev, char *token) · line 854
Quoted 11 lines
tools/xl/xl_parse.c +11
-0+return 1 ; + } + } + +if (libxl_defbool_is_default (viommu->intremap)) +libxl_defbool_set (&viommu->intremap, true); + +if (!libxl_defbool_val (viommu->intremap)) { +fprintf (stderr,"Cannot create one virtual VTD without intremap\n" ); +return 1 ; + }
Why is that an option anyway if it's not possible to create an IOMMU without intremap anyway?
tools/xl/xl_parse.c int parse_usbdev_config(libxl_device_usbdev *usbdev, char *token) · line 861
Quoted 7 lines
tools/xl/xl_parse.c +7
-0+ +/* Set default values to unexposed fields */ + viommu->base_addr =VIOMMU_VTD_BASE_ADDR ; + viommu->len =VIOMMU_VTD_REGISTER_LEN ; + +/* Set desired capbilities */ + viommu->cap =VIOMMU_CAP_IRQ_REMAPPING ;
This should be set in libxl__domain_build_info_setdefault IMHO.
Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v2 9/25 tools/libxl: build DMAR table for a guest with one virtual VTD
In reply to Lan TianyuFrom: Chao Gao <[email protected]>
A new logic is added to build ACPI DMAR table in tool stack for a guest with one virtual VTD and pass through it to guest via existing mechanism. If there already are ACPI tables needed to pass through, we joint the tables.
--- tools/libxl/libxl_arch.h | 5 +++++ tools/libxl/libxl_dom.c | 36 +++++++++++++++++++++++++++++++++ tools/libxl/libxl_x86_acpi.c | 48 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+)
tools/libxl/libxl_arch.h +5 -0
@@ -78,6 +78,11 @@ int libxl__arch_extra_memory(libxl__gc *gc,int libxl__dom_load_acpi (libxl__gc *gc,const libxl_domain_build_info *b_info,struct xc_dom_image *dom); + +int libxl__dom_build_dmar (libxl__gc *gc, +const libxl_domain_build_info *b_info, +struct xc_dom_image *dom, +void **data,int *len);#endif #endif
tools/libxl/libxl_dom.c +36 -0
@@ -1060,6 +1060,42 @@ static int libxl__domain_firmware(libxl__gc *gc, } } +/* +* If a guest has one virtual VTD, build DMAR table for it and joint this +* table with existing content in acpi_modules in order to employ HVM +* firmware pass-through mechanism to pass-through DMAR table. +*/ +if (info->viommu.type ==LIBXL_VIOMMU_TYPE_INTEL_VTD ) { + datalen =0 ; + e =libxl__dom_build_dmar (gc, info, dom, &data, &datalen); +if (e) { +LOGEV (ERROR , e,"failed to build DMAR table" ); + rc =ERROR_FAIL ; + goto out; + } +if (datalen) { +libxl__ptr_add (gc, data); +if (!dom->acpi_modules[0 ].data) { + dom->acpi_modules[0 ].data = data; + dom->acpi_modules[0 ].length = (uint32_t )datalen; + }else { +/* joint tables */ +void *newdata; + newdata =malloc (datalen + dom->acpi_modules[0 ].length); +if (!newdata) { +LOGE (ERROR ,"failed to joint DMAR table to acpi modules" ); + rc =ERROR_FAIL ; + goto out; + } +memcpy (newdata, dom->acpi_modules[0 ].data, + dom->acpi_modules[0 ].length); +memcpy (newdata + dom->acpi_modules[0 ].length, data, datalen); + dom->acpi_modules[0 ].data = newdata; + dom->acpi_modules[0 ].length += (uint32_t )datalen; + } + } + } +return 0 ; out:assert (rc !=0 );
tools/libxl/libxl_x86_acpi.c +48 -0
60 lines not on this page · raw message
Signature · 7 lines
1.8.3.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH V2 9/25] tools/libxl: build DMAR table for a guest with one virtual VTD
Quoted 20 lines · Lan Tianyu
tools/libxl/libxl_dom.c +12
-0@@ -1060,6 +1060,42 @@ static int libxl__domain_firmware(libxl__gc *gc, } } +/* +* If a guest has one virtual VTD, build DMAR table for it and joint this +* table with existing content in acpi_modules in order to employ HVM +* firmware pass-through mechanism to pass-through DMAR table. +*/ +if (info->viommu.type ==LIBXL_VIOMMU_TYPE_INTEL_VTD ) { + datalen =0 ; + e =libxl__dom_build_dmar (gc, info, dom, &data, &datalen); +if (e) { +LOGEV (ERROR , e,"failed to build DMAR table" ); + rc =ERROR_FAIL ; + goto out;
tools/libxl/libxl_dom.c static int libxl__domain_firmware(libxl__gc *gc, · line 1084
Quoted 10 lines
tools/libxl/libxl_dom.c +10
-0+ } +if (datalen) { +libxl__ptr_add (gc, data); +if (!dom->acpi_modules[0 ].data) { + dom->acpi_modules[0 ].data = data; + dom->acpi_modules[0 ].length = (uint32_t )datalen; + }else { +/* joint tables */ +void *newdata; + newdata =malloc (datalen + dom->acpi_modules[0 ].length);
All memory allocations in libxl should use libxl__*lloc wrappers.
tools/libxl/libxl_dom.c static int libxl__domain_firmware(libxl__gc *gc, · line 1097
Quoted 13 lines
tools/libxl/libxl_dom.c +13
-0+if (!newdata) { +LOGE (ERROR ,"failed to joint DMAR table to acpi modules" ); + rc =ERROR_FAIL ; + goto out; + } +memcpy (newdata, dom->acpi_modules[0 ].data, + dom->acpi_modules[0 ].length); +memcpy (newdata + dom->acpi_modules[0 ].length, data, datalen); + dom->acpi_modules[0 ].data = newdata; + dom->acpi_modules[0 ].length += (uint32_t )datalen; + } + } + }
This still looks wrong to me. How do you know acpi_modules[0] is DMAR table?
You should have a look at libxl_x86_acpi.c and work out a proper solution.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH V2 9/25] tools/libxl: build DMAR table for a guest with one virtual VTD
Quoted 25 lines · Wei Liu
Quoted 24 lines · Lan Tianyu
tools/libxl/libxl_dom.c +16
-0@@ -1060,6 +1060,42 @@ static int libxl__domain_firmware(libxl__gc *gc, } } +/* +* If a guest has one virtual VTD, build DMAR table for it and joint this +* table with existing content in acpi_modules in order to employ HVM +* firmware pass-through mechanism to pass-through DMAR table. +*/ +if (info->viommu.type ==LIBXL_VIOMMU_TYPE_INTEL_VTD ) { + datalen =0 ; + e =libxl__dom_build_dmar (gc, info, dom, &data, &datalen); +if (e) { +LOGEV (ERROR , e,"failed to build DMAR table" ); + rc =ERROR_FAIL ; + goto out; + } +if (datalen) { +libxl__ptr_add (gc, data); +if (!dom->acpi_modules[0 ].data) {
Quoted 19 lines
tools/libxl/libxl_dom.c static int libxl__domain_firmware(libxl__gc *gc, · line 1084
Quoted 6 lines
tools/libxl/libxl_dom.c +6
-0+ dom->acpi_modules[0 ].data = data; + dom->acpi_modules[0 ].length = (uint32_t )datalen; + }else { +/* joint tables */ +void *newdata; + newdata =malloc (datalen + dom->acpi_modules[0 ].length);All memory allocations in libxl should use libxl__*lloc wrappers.
Quoted 10 lines
tools/libxl/libxl_dom.c +10
-0+if (!newdata) { +LOGE (ERROR ,"failed to joint DMAR table to acpi modules" ); + rc =ERROR_FAIL ; + goto out; + } +memcpy (newdata, dom->acpi_modules[0 ].data, + dom->acpi_modules[0 ].length); +memcpy (newdata + dom->acpi_modules[0 ].length, data, datalen); + dom->acpi_modules[0 ].data = newdata; + dom->acpi_modules[0 ].length += (uint32_t )datalen;
Also, this leaks the old pointer, right?
Quoted 7 lines
tools/libxl/libxl_dom.c static int libxl__domain_firmware(libxl__gc *gc, · line 1095
Quoted 3 lines
tools/libxl/libxl_dom.c +3
-0+ } + } + }This still looks wrong to me. How do you know acpi_modules[0] is DMAR table?
Oh, I sorta see why you do this, but I still think this is wrong. The DMAR should either be a new module or be joined to the existing one (and with all conflicts resolved).
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH V2 9/25] tools/libxl: build DMAR table for a guest with one virtual VTD
Quoted 46 lines · Wei Liu
Quoted 25 lines · Wei Liu
Quoted 24 lines · Lan Tianyu
tools/libxl/libxl_dom.c +16
-0@@ -1060,6 +1060,42 @@ static int libxl__domain_firmware(libxl__gc *gc, } } +/* +* If a guest has one virtual VTD, build DMAR table for it and joint this +* table with existing content in acpi_modules in order to employ HVM +* firmware pass-through mechanism to pass-through DMAR table. +*/ +if (info->viommu.type ==LIBXL_VIOMMU_TYPE_INTEL_VTD ) { + datalen =0 ; + e =libxl__dom_build_dmar (gc, info, dom, &data, &datalen); +if (e) { +LOGEV (ERROR , e,"failed to build DMAR table" ); + rc =ERROR_FAIL ; + goto out; + } +if (datalen) { +libxl__ptr_add (gc, data); +if (!dom->acpi_modules[0 ].data) {Quoted 19 lines
tools/libxl/libxl_dom.c static int libxl__domain_firmware(libxl__gc *gc, · line 1084
Quoted 6 lines
tools/libxl/libxl_dom.c +6
-0+ dom->acpi_modules[0 ].data = data; + dom->acpi_modules[0 ].length = (uint32_t )datalen; + }else { +/* joint tables */ +void *newdata; + newdata =malloc (datalen + dom->acpi_modules[0 ].length);All memory allocations in libxl should use libxl__*lloc wrappers.
Quoted 10 lines
tools/libxl/libxl_dom.c +10
-0+if (!newdata) { +LOGE (ERROR ,"failed to joint DMAR table to acpi modules" ); + rc =ERROR_FAIL ; + goto out; + } +memcpy (newdata, dom->acpi_modules[0 ].data, + dom->acpi_modules[0 ].length); +memcpy (newdata + dom->acpi_modules[0 ].length, data, datalen); + dom->acpi_modules[0 ].data = newdata; + dom->acpi_modules[0 ].length += (uint32_t )datalen;
Quoted 1 line
Also, this leaks the old pointer, right?
Yes. Will fix this.
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
tools/libxl/libxl_dom.c +3
-0+ } + } + }
Quoted 7 lines
Quoted 3 lines
This still looks wrong to me. How do you know acpi_modules[0] is DMAR table?
Oh, I sorta see why you do this, but I still think this is wrong. The DMAR should either be a new module or be joined to the existing one (and with all conflicts resolved).
Hi, Wei
Thanks for your comments.
iirc, HVM only supports one module; DMAR cannot be a new module. Joining to the existing one is the approach we are taking.
Which kind of conflicts you think should be resolved? If you mean I forget to free the old buf, I will fix this. If you mean the potential overlap between the binary passed by admin and DMAR table built here, I don't have much idea on this. Even without the DMAR table, the binary may contains MADT or other tables and tool stacks don't intrepret the binary and check whether there are conflicts, right?
Thanks
Chao
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH V2 9/25] tools/libxl: build DMAR table for a guest with one virtual VTD
Quoted 9 lines · Chao Gao
Quoted 9 lines
Quoted 8 lines
tools/libxl/libxl_dom.c static int libxl__domain_firmware(libxl__gc *gc, · line 1095
Quoted 4 lines
tools/libxl/libxl_dom.c +3
-0+ } + } + }This still looks wrong to me. How do you know acpi_modules[0] is DMAR table?
Quoted 8 lines
Quoted 3 lines
Oh, I sorta see why you do this, but I still think this is wrong. The DMAR should either be a new module or be joined to the existing one (and with all conflicts resolved).
Hi, Wei
Thanks for your comments.iirc, HVM only supports one module;
This is indeed how it is stated in various comments. I'm not sure why there is such restriction. Maybe x86 maintainers can shed more light on this?
Quoted 9 lines
DMAR cannot be a new module. Joining to
the existing one is the approach we are taking.Which kind of conflicts you think should be resolved? If you mean I forget to free the old buf, I will fix this. If you mean the potential overlap between the binary passed by admin and DMAR table built here, I don't have much idea on this. Even without the DMAR table, the binary may contains MADT or other tables and tool stacks don't intrepret the binary and check whether there are conflicts, right?
That's true. Ignore the comment about fixing up conflicts then.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH V2 9/25] tools/libxl: build DMAR table for a guest with one virtual VTD
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 18.08.17 at 15:45, <[email protected]> wrote:
Quoted 13 lines · Chao Gao
Quoted 12 lines
Quoted 8 lines
tools/libxl/libxl_dom.c static int libxl__domain_firmware(libxl__gc *gc, · line 1095
Quoted 4 lines
tools/libxl/libxl_dom.c +3
-0+ } + } + }This still looks wrong to me. How do you know acpi_modules[0] is DMAR table?
Oh, I sorta see why you do this, but I still think this is wrong. The DMAR should either be a new module or be joined to the existing one (and with all conflicts resolved).
Quoted 8 lines
Quoted 4 lines
Hi, Wei
Thanks for your comments.iirc, HVM only supports one module;
This is indeed how it is stated in various comments. I'm not sure why there is such restriction. Maybe x86 maintainers can shed more light on this?
Not me, sorry. Maybe ask whoever has written that code?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH V2 9/25] tools/libxl: build DMAR table for a guest with one virtual VTD
Quoted 18 lines · Jan Beulich
Quoted 18 lines
Quoted 1 line
Quoted 1 line · On 18.08.17 at 15:45, <[email protected]> wrote:
Quoted 16 lines · Chao Gao
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
tools/libxl/libxl_dom.c +3
-0+ } + } + }Quoted 7 lines
Quoted 3 lines
This still looks wrong to me. How do you know acpi_modules[0] is DMAR table?
Oh, I sorta see why you do this, but I still think this is wrong. The DMAR should either be a new module or be joined to the existing one (and with all conflicts resolved).
Hi, Wei
Thanks for your comments.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
iirc, HVM only supports one module;
This is indeed how it is stated in various comments. I'm not sure why there is such restriction. Maybe x86 maintainers can shed more light on this?
Not me, sorry. Maybe ask whoever has written that code?
OK. I have misunderstood the restriction was from hvmloader.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH V2 9/25] tools/libxl: build DMAR table for a guest with one virtual VTD
In reply to Chao GaoQuoted 70 lines · Chao Gao
Quoted 46 lines · Wei Liu
Quoted 25 lines · Wei Liu
Quoted 24 lines · Lan Tianyu
tools/libxl/libxl_dom.c +16
-0@@ -1060,6 +1060,42 @@ static int libxl__domain_firmware(libxl__gc *gc, } } +/* +* If a guest has one virtual VTD, build DMAR table for it and joint this +* table with existing content in acpi_modules in order to employ HVM +* firmware pass-through mechanism to pass-through DMAR table. +*/ +if (info->viommu.type ==LIBXL_VIOMMU_TYPE_INTEL_VTD ) { + datalen =0 ; + e =libxl__dom_build_dmar (gc, info, dom, &data, &datalen); +if (e) { +LOGEV (ERROR , e,"failed to build DMAR table" ); + rc =ERROR_FAIL ; + goto out; + } +if (datalen) { +libxl__ptr_add (gc, data); +if (!dom->acpi_modules[0 ].data) {Quoted 19 lines
tools/libxl/libxl_dom.c static int libxl__domain_firmware(libxl__gc *gc, · line 1084
Quoted 6 lines
tools/libxl/libxl_dom.c +6
-0+ dom->acpi_modules[0 ].data = data; + dom->acpi_modules[0 ].length = (uint32_t )datalen; + }else { +/* joint tables */ +void *newdata; + newdata =malloc (datalen + dom->acpi_modules[0 ].length);All memory allocations in libxl should use libxl__*lloc wrappers.
Quoted 10 lines
tools/libxl/libxl_dom.c +10
-0+if (!newdata) { +LOGE (ERROR ,"failed to joint DMAR table to acpi modules" ); + rc =ERROR_FAIL ; + goto out; + } +memcpy (newdata, dom->acpi_modules[0 ].data, + dom->acpi_modules[0 ].length); +memcpy (newdata + dom->acpi_modules[0 ].length, data, datalen); + dom->acpi_modules[0 ].data = newdata; + dom->acpi_modules[0 ].length += (uint32_t )datalen;Quoted 1 line
Also, this leaks the old pointer, right?
Yes. Will fix this.
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
tools/libxl/libxl_dom.c +3
-0+ } + } + }Quoted 7 lines
Quoted 3 lines
This still looks wrong to me. How do you know acpi_modules[0] is DMAR table?
Oh, I sorta see why you do this, but I still think this is wrong. The DMAR should either be a new module or be joined to the existing one (and with all conflicts resolved).
Hi, Wei
Thanks for your comments.iirc, HVM only supports one module; DMAR cannot be a new module. Joining to the existing one is the approach we are taking.
Quoted 7 lines
Which kind of conflicts you think should be resolved? If you mean I forget to free the old buf, I will fix this. If you mean the potential overlap between the binary passed by admin and DMAR table built here, I don't have much idea on this. Even without the DMAR table, the binary may contains MADT or other tables and tool stacks don't intrepret the binary and check whether there are conflicts, right?
Thinking a bit more about this, when I first said "conflicts" I didn't mean to parse the content. I was referring to the code in libxl_x86_apci.c which also seems to manipulate acpi_modules.
I would like the code to generate dmar take into consideration libxl__dom_load_acpi.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH V2 9/25] tools/libxl: build DMAR table for a guest with one virtual VTD
Quoted 13 lines · Wei Liu
Quoted 6 lines
Quoted 6 lines
Hi, Wei
Thanks for your comments.iirc, HVM only supports one module; DMAR cannot be a new module. Joining to the existing one is the approach we are taking.
Quoted 7 lines
Quoted 7 lines
Which kind of conflicts you think should be resolved? If you mean I forget to free the old buf, I will fix this. If you mean the potential overlap between the binary passed by admin and DMAR table built here, I don't have much idea on this. Even without the DMAR table, the binary may contains MADT or other tables and tool stacks don't intrepret the binary and check whether there are conflicts, right?
Quoted 3 lines
Thinking a bit more about this, when I first said "conflicts" I didn't mean to parse the content. I was referring to the code in
libxl_x86_apci.cwhich also seems to manipulateacpi_modules.
Code in libxl_x86_acpi.c works for Hvmlite/PVHv2. The code we added is for hvm guest.
Quoted 4 lines
I would like the code to generate dmar take into consideration
libxl__dom_load_acpi.
If add dmar table for hvmlite, we should combine dmar table with other ACPI table and populate into acpi_modules[2]. This is how hvmlite add other ACPI tables in libxl__dom_load_acpi().
Signature · 7 lines
Best regards Tianyu Lan _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH V2 9/25] tools/libxl: build DMAR table for a guest with one virtual VTD
Quoted 14 lines · Lan Tianyu
Quoted 13 lines · Wei Liu
Quoted 13 lines
Quoted 13 lines
Hi, Wei
Thanks for your comments.iirc, HVM only supports one module; DMAR cannot be a new module. Joining to the existing one is the approach we are taking.
Which kind of conflicts you think should be resolved? If you mean I forget to free the old buf, I will fix this. If you mean the potential overlap between the binary passed by admin and DMAR table built here, I don't have much idea on this. Even without the DMAR table, the binary may contains MADT or other tables and tool stacks don't intrepret the binary and check whether there are conflicts, right?
Quoted 7 lines
Quoted 3 lines
Thinking a bit more about this, when I first said "conflicts" I didn't mean to parse the content. I was referring to the code in
libxl_x86_apci.cwhich also seems to manipulateacpi_modules.Code in
libxl_x86_acpi.cworks for Hvmlite/PVHv2. The code we added is for hvm guest.
That's correct for the code as-is but what is preventing the code there from working with HVM? Assuming correct checks and branches are added to appropriate places?
I'm against having multiple locations doing things that could potentially clash with each other. In the foreseeable future PVH is going to get need similar functionality.
My expectation is that if the existing code needs to be taken into consideration and the contributors need to figure out if and how it can be modified to suite their needs. If everyone is doing their own thing in their own little function Xen will eventually become unmaintainable.
Quoted 9 lines
Quoted 4 lines
I would like the code to generate dmar take into consideration
libxl__dom_load_acpi.If add dmar table for hvmlite, we should combine dmar table with other ACPI table and populate into acpi_modules[2]. This is how hvmlite add other ACPI tables in
libxl__dom_load_acpi().
Sure, that sounds plausible.
What I would like to see is to have one entry point to manipulate APCI tables.
Given the patch volume we're seeing now, we expect contributors to drive the discussion forward. If you're not sure, feel free to ask more questions.
Quoted 4 lines
Signature · 3 lines
-- Best regards Tianyu Lan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH V2 9/25] tools/libxl: build DMAR table for a guest with one virtual VTD
Quoted 46 lines · Wei Liu
Quoted 14 lines · Lan Tianyu
Quoted 13 lines · Wei Liu
Quoted 13 lines
Quoted 13 lines
Hi, Wei
Thanks for your comments.iirc, HVM only supports one module; DMAR cannot be a new module. Joining to the existing one is the approach we are taking.
Which kind of conflicts you think should be resolved? If you mean I forget to free the old buf, I will fix this. If you mean the potential overlap between the binary passed by admin and DMAR table built here, I don't have much idea on this. Even without the DMAR table, the binary may contains MADT or other tables and tool stacks don't intrepret the binary and check whether there are conflicts, right?
Quoted 7 lines
Quoted 3 lines
Thinking a bit more about this, when I first said "conflicts" I didn't mean to parse the content. I was referring to the code in
libxl_x86_apci.cwhich also seems to manipulateacpi_modules.Code in
libxl_x86_acpi.cworks for Hvmlite/PVHv2. The code we added is for hvm guest.That's correct for the code as-is but what is preventing the code there from working with HVM? Assuming correct checks and branches are added to appropriate places?
I'm against having multiple locations doing things that could potentially clash with each other. In the foreseeable future PVH is going to get need similar functionality.
My expectation is that if the existing code needs to be taken into consideration and the contributors need to figure out if and how it can be modified to suite their needs. If everyone is doing their own thing in their own little function Xen will eventually become unmaintainable.
Quoted 9 lines
Quoted 4 lines
I would like the code to generate dmar take into consideration
libxl__dom_load_acpi.If add dmar table for hvmlite, we should combine dmar table with other ACPI table and populate into acpi_modules[2]. This is how hvmlite add other ACPI tables in
libxl__dom_load_acpi().
Quoted 7 lines
Sure, that sounds plausible.
What I would like to see is to have one entry point to manipulate APCI tables.
Given the patch volume we're seeing now, we expect contributors to drive the discussion forward. If you're not sure, feel free to ask more questions.
I am not sure whether I understood correctly.
PVHv2 builds all ACPI table in tool stack and uses acpi_module[0, 1, 2] to pass related table content.
HVM builds ACPI tables in hvmloader and just use acpi_module[0] to pass additional ACPI firmware or table.
These two modes have different way to use acpi_modules[]. So I think we can't combine them, right?
For build dmar table, we have introduced construct_dmar() in under libacpi to build dmar table and PVHv2 also can use it in libxl__dom_load_acpi().
Signature · 7 lines
Best regards Tianyu Lan _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH V2 9/25] tools/libxl: build DMAR table for a guest with one virtual VTD
Quoted 21 lines · Lan Tianyu
Quoted 10 lines · Wei Liu
Quoted 9 lines
Quoted 4 lines
I would like the code to generate dmar take into consideration
libxl__dom_load_acpi.If add dmar table for hvmlite, we should combine dmar table with other ACPI table and populate into acpi_modules[2]. This is how hvmlite add other ACPI tables in
libxl__dom_load_acpi().Quoted 7 lines
Sure, that sounds plausible.
What I would like to see is to have one entry point to manipulate APCI tables.
Given the patch volume we're seeing now, we expect contributors to drive the discussion forward. If you're not sure, feel free to ask more questions.
I am not sure whether I understood correctly.
Quoted 9 lines
PVHv2 builds all ACPI table in tool stack and uses acpi_module[0, 1, 2] to pass related table content.
HVM builds ACPI tables in hvmloader and just use acpi_module[0] to pass additional ACPI firmware or table.
These two modes have different way to use acpi_modules[]. So I think we can't combine them, right?
There might be some misunderstanding. We probably don't want to manipulate the content of the tables in libxl.
Quoted 4 lines
For build dmar table, we have introduced
construct_dmar()in under libacpi to build dmar table and PVHv2 also can use it inlibxl__dom_load_acpi().
My major complain is now there are two functions and in two different locations, in two different phases of domain construction that would manipulate ACPI tables. I would like to have only one.
The function you're currently modifying libxl__domain_firmware is not the right place. It's primary function is to load files from disks.
You should be able to call the function you introduced in libxl__dom_load_acpi, provided appropriate checks are added.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH V2 9/25] tools/libxl: build DMAR table for a guest with one virtual VTD
Quoted 35 lines · Wei Liu
Quoted 18 lines
Quoted 18 lines
Quoted 12 lines
If add dmar table for hvmlite, we should combine dmar table with other
Quoted 11 lines
Quoted 3 lines
Quoted 3 lines
ACPI table and populate into acpi_modules[2]. This is how hvmlite add other ACPI tables in
libxl__dom_load_acpi().Sure, that sounds plausible.
What I would like to see is to have one entry point to manipulate APCI tables.
Given the patch volume we're seeing now, we expect contributors to drive the discussion forward. If you're not sure, feel free to ask more questions.
I am not sure whether I understood correctly.
PVHv2 builds all ACPI table in tool stack and uses acpi_module[0, 1, 2] to pass related table content.
Quoted 6 lines
Quoted 6 lines
HVM builds ACPI tables in hvmloader and just use acpi_module[0] to pass additional ACPI firmware or table.
These two modes have different way to use acpi_modules[]. So I think we can't combine them, right?
There might be some misunderstanding. We probably don't want to manipulate the content of the tables in libxl.
Quoted 4 lines
Quoted 4 lines
For build dmar table, we have introduced
construct_dmar()in under libacpi to build dmar table and PVHv2 also can use it inlibxl__dom_load_acpi().My major complain is now there are two functions and in two different locations, in two different phases of domain construction that would manipulate ACPI tables. I would like to have only one.
Quoted 5 lines
The function you're currently modifying
libxl__domain_firmwareis not the right place. It's primary function is to load files from disks.You should be able to call the function you introduced in
libxl__dom_load_acpi, provided appropriate checks are added.
But libxl__dom_load_acpi() isn't called on hvm guest code path. It just works for PVHv2/HVMlite and have some conflict with hvm guest configuration(i.e, acpi_module).
int libxl__arch_domain_finalise_hw_description(libxl__gc *gc,
libxl_domain_build_info
*info,
struct xc_dom_image *dom)
{
int rc = 0;
if ((info->type == LIBXL_DOMAIN_TYPE_HVM) &&
(info->device_model_version == LIBXL_DEVICE_MODEL_VERSION_NONE)) {
rc = libxl__dom_load_acpi(gc, info, dom);
if (rc != 0)
LOGE(ERROR, "libxl_dom_load_acpi failed");
}
return rc;
}Signature · 7 lines
Best regards Tianyu Lan _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH V2 9/25] tools/libxl: build DMAR table for a guest with one virtual VTD
Quoted 51 lines · Lan Tianyu
Quoted 35 lines · Wei Liu
Quoted 18 lines
Quoted 18 lines
Quoted 12 lines
If add dmar table for hvmlite, we should combine dmar table with other
Quoted 11 lines
Quoted 3 lines
Quoted 3 lines
ACPI table and populate into acpi_modules[2]. This is how hvmlite add other ACPI tables in
libxl__dom_load_acpi().Sure, that sounds plausible.
What I would like to see is to have one entry point to manipulate APCI tables.
Given the patch volume we're seeing now, we expect contributors to drive the discussion forward. If you're not sure, feel free to ask more questions.
I am not sure whether I understood correctly.
PVHv2 builds all ACPI table in tool stack and uses acpi_module[0, 1, 2] to pass related table content.
Quoted 6 lines
Quoted 6 lines
HVM builds ACPI tables in hvmloader and just use acpi_module[0] to pass additional ACPI firmware or table.
These two modes have different way to use acpi_modules[]. So I think we can't combine them, right?
There might be some misunderstanding. We probably don't want to manipulate the content of the tables in libxl.
Quoted 4 lines
Quoted 4 lines
For build dmar table, we have introduced
construct_dmar()in under libacpi to build dmar table and PVHv2 also can use it inlibxl__dom_load_acpi().My major complain is now there are two functions and in two different locations, in two different phases of domain construction that would manipulate ACPI tables. I would like to have only one.
Quoted 5 lines
The function you're currently modifying
libxl__domain_firmwareis not the right place. It's primary function is to load files from disks.You should be able to call the function you introduced in
libxl__dom_load_acpi, provided appropriate checks are added.But
libxl__dom_load_acpi()isn't called on hvm guest code path. It just works for PVHv2/HVMlite and have some conflict with hvm guestconfiguration(i.e, acpi_module).int libxl__arch_domain_finalise_hw_description(libxl__gc *gc,
libxl_domain_build_info
*info,
structxc_dom_image*dom)
Quoted 12 lines
{
int rc = 0;
if ((info->type == LIBXL_DOMAIN_TYPE_HVM) &&
(info->device_model_version == LIBXL_DEVICE_MODEL_VERSION_NONE)) {
rc = libxl__dom_load_acpi(gc, info, dom);
if (rc != 0)
LOGE(ERROR, "libxl_dom_load_acpi failed");
}
return rc;
}We may remove the check and move introduced code in libxl__dom_load_acpi(). Run new code just for hvm guest. Does this make sense?
Signature · 7 lines
Best regards Tianyu Lan _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH V2 9/25] tools/libxl: build DMAR table for a guest with one virtual VTD
Quoted 15 lines · Lan Tianyu
Quoted 15 lines
int libxl__arch_domain_finalise_hw_description(libxl__gc *gc,
libxl_domain_build_info
*info,
structxc_dom_image*dom){ int rc = 0; if ((info->type == LIBXL_DOMAIN_TYPE_HVM) && (info->device_model_version == LIBXL_DEVICE_MODEL_VERSION_NONE)) { rc = libxl__dom_load_acpi(gc, info, dom); if (rc != 0) LOGE(ERROR, "libxl_dom_load_acpi failed"); }
Quoted 7 lines
Quoted 2 lines
return rc; }We may remove the check and move introduced code in
libxl__dom_load_acpi(). Run new code just for hvm guest. Does this make sense?
More or less. Push the check down to libxl__dom_load_acpi
Quoted 3 lines
Signature · 2 lines
Best regards Tianyu Lan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v2 10/25 tools/libxl: create vIOMMU during domain construction
In reply to Lan TianyuFrom: Chao Gao <[email protected]>
If guest is configured to have a vIOMMU, create it during domain construction.
--- tools/libxl/libxl_x86.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
tools/libxl/libxl_x86.c +28 -0
@@ -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 &&
Signature · 7 lines
1.8.3.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH V2 10/25] tools/libxl: create vIOMMU during domain construction
Quoted 15 lines · Lan Tianyu
From: Chao Gao <[email protected]>
If guest is configured to have a vIOMMU, create it during domain construction.
Signed-off-by Chao Gao <[email protected]>Signed-off-by Lan Tianyu <[email protected]>--- tools/libxl/libxl_x86.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)tools/libxl/libxl_x86.c +0
-0
tools/libxl/libxl_x86.c int libxl__arch_domain_create(libxl__gc *gc, libxl_domain_config *d_config, · line 341
Quoted 1 line
tools/libxl/libxl_x86.c +0
-0@@ -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?
Quoted 13 lines
tools/libxl/libxl_x86.c +9
-0unsigned 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)) {
tools/libxl/libxl_x86.c int libxl__arch_domain_create(libxl__gc *gc, libxl_domain_config *d_config, · line 364
Quoted 10 lines
tools/libxl/libxl_x86.c +10
-0+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.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH V2 10/25] tools/libxl: create vIOMMU during domain construction
Quoted 20 lines · Roger Pau Monné
Quoted 15 lines · Lan Tianyu
From: Chao Gao <[email protected]>
If guest is configured to have a vIOMMU, create it during domain construction.
Signed-off-by Chao Gao <[email protected]>Signed-off-by Lan Tianyu <[email protected]>--- tools/libxl/libxl_x86.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)tools/libxl/libxl_x86.c +0
-0tools/libxl/libxl_x86.c int libxl__arch_domain_create(libxl__gc *gc, libxl_domain_config *d_config, · line 341
Quoted 1 line
tools/libxl/libxl_x86.c +0
-0@@ -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:
Quoted 3 lines
d_config->b_info.type!=LIBXL_DOMAIN_TYPE_PVIs 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.
Signature · 7 lines
Best regards Tianyu Lan _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH V2 10/25] tools/libxl: create vIOMMU during domain construction
Quoted 21 lines · Lan Tianyu
Quoted 20 lines · Roger Pau Monné
Quoted 15 lines · Lan Tianyu
From: Chao Gao <[email protected]>
If guest is configured to have a vIOMMU, create it during domain construction.
Signed-off-by Chao Gao <[email protected]>Signed-off-by Lan Tianyu <[email protected]>--- tools/libxl/libxl_x86.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)tools/libxl/libxl_x86.c +0
-0tools/libxl/libxl_x86.c int libxl__arch_domain_create(libxl__gc *gc, libxl_domain_config *d_config, · line 341
Quoted 1 line
tools/libxl/libxl_x86.c +0
-0@@ -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:
Quoted 6 lines
Quoted 3 lines
d_config->b_info.type!=LIBXL_DOMAIN_TYPE_PVIs 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.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v2 11/25 x86/hvm: Introduce a emulated VTD for HVM
In reply to Lan TianyuFrom: Chao Gao <[email protected]>
This patch adds create/destroy/query function for the emulated VTD and adapts it to the common VIOMMU abstraction.
--- xen/drivers/passthrough/vtd/Makefile | 7 +- xen/drivers/passthrough/vtd/iommu.h | 99 +++++++++++++++++----- xen/drivers/passthrough/vtd/vvtd.c | 158 +++++++++++++++++++++++++++++++++++ xen/include/asm-x86/viommu.h | 3 + 4 files changed, 241 insertions(+), 26 deletions(-) create mode 100644 xen/drivers/passthrough/vtd/vvtd.c
xen/drivers/passthrough/vtd/Makefile +4 -3
@@ -1,8 +1,9 @@ subdir-$(CONFIG_X86) += x86 -obj-y += iommu.o obj-y += dmar.o -obj-y += utils.o -obj-y += qinval.o obj-y += intremap.o +obj-y += iommu.o +obj-y += qinval.o obj-y += quirks.o +obj-y += utils.o +obj-$(CONFIG_VIOMMU) += vvtd.o
xen/drivers/passthrough/vtd/iommu.h +76 -23
119 lines not on this page · raw message
xen/drivers/passthrough/vtd/vvtd.c new file +158 -0
158 lines not on this page · raw message
xen/include/asm-x86/viommu.h +3 -0
@@ -22,6 +22,9 @@#include <xen/viommu.h> #include <asm/types.h> +#include <asm/processor.h> + +extern struct viommu_ops vvtd_hvm_vmx_ops;/* IRQ request type */ #define VIOMMU_REQUEST_IRQ_MSI 0
Signature · 7 lines
1.8.3.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH V2 11/25] x86/hvm: Introduce a emulated VTD for HVM
Quoted 146 lines · Lan Tianyu
From: Chao Gao <[email protected]>
This patch adds create/destroy/query function for the emulated VTD and adapts it to the common VIOMMU abstraction.
Signed-off-by Chao Gao <[email protected]>Signed-off-by Lan Tianyu <[email protected]>--- xen/drivers/passthrough/vtd/Makefile | 7 +- xen/drivers/passthrough/vtd/iommu.h | 99 +++++++++++++++++----- xen/drivers/passthrough/vtd/vvtd.c | 158 +++++++++++++++++++++++++++++++++++ xen/include/asm-x86/viommu.h | 3 + 4 files changed, 241 insertions(+), 26 deletions(-) create mode 100644 xen/drivers/passthrough/vtd/vvtd.cxen/drivers/passthrough/vtd/Makefile +4
-3@@ -1,8 +1,9 @@ subdir-$(CONFIG_X86) += x86 -obj-y += iommu.o obj-y += dmar.o -obj-y += utils.o -obj-y += qinval.o obj-y += intremap.o +obj-y += iommu.o +obj-y += qinval.o obj-y += quirks.o +obj-y += utils.o +obj-$(CONFIG_VIOMMU) += vvtd.oxen/drivers/passthrough/vtd/iommu.h +70
-23@@ -23,31 +23,54 @@#include <asm/msi.h> /* -* Intel IOMMU register specification per version 1.0 public spec. +* Intel IOMMU register specification per version 2.4 public spec. */ -#define DMAR_VER_REG 0x0/* Arch version supported by this IOMMU */ -#define DMAR_CAP_REG 0x8/* Hardware supported capabilities */ -#define DMAR_ECAP_REG 0x10/* Extended capabilities supported */ -#define DMAR_GCMD_REG 0x18/* Global command register */ -#define DMAR_GSTS_REG 0x1c/* Global status register */ -#define DMAR_RTADDR_REG 0x20/* Root entry table */ -#define DMAR_CCMD_REG 0x28/* Context command reg */ -#define DMAR_FSTS_REG 0x34/* Fault Status register */ -#define DMAR_FECTL_REG 0x38/* Fault control register */ -#define DMAR_FEDATA_REG 0x3c/* Fault event interrupt data register */ -#define DMAR_FEADDR_REG 0x40/* Fault event interrupt addr register */ -#define DMAR_FEUADDR_REG 0x44/* Upper address register */ -#define DMAR_AFLOG_REG 0x58/* Advanced Fault control */ -#define DMAR_PMEN_REG 0x64/* Enable Protected Memory Region */ -#define DMAR_PLMBASE_REG 0x68/* PMRR Low addr */ -#define DMAR_PLMLIMIT_REG 0x6c/* PMRR low limit */ -#define DMAR_PHMBASE_REG 0x70/* pmrr high base addr */ -#define DMAR_PHMLIMIT_REG 0x78/* pmrr high limit */ -#define DMAR_IQH_REG 0x80/* invalidation queue head */ -#define DMAR_IQT_REG 0x88/* invalidation queue tail */ -#define DMAR_IQA_REG 0x90/* invalidation queue addr */ -#define DMAR_IRTA_REG 0xB8/* intr remap */ +#define DMAR_VER_REG 0x0/* Arch version supported by this IOMMU */ +#define DMAR_CAP_REG 0x8/* Hardware supported capabilities */ +#define DMAR_ECAP_REG 0x10/* Extended capabilities supported */ +#define DMAR_GCMD_REG 0x18/* Global command register */ +#define DMAR_GSTS_REG 0x1c/* Global status register */ +#define DMAR_RTADDR_REG 0x20/* Root entry table */ +#define DMAR_CCMD_REG 0x28/* Context command reg */ +#define DMAR_FSTS_REG 0x34/* Fault Status register */ +#define DMAR_FECTL_REG 0x38/* Fault control register */ +#define DMAR_FEDATA_REG 0x3c/* Fault event interrupt data register */ +#define DMAR_FEADDR_REG 0x40/* Fault event interrupt addr register */ +#define DMAR_FEUADDR_REG 0x44/* Upper address register */ +#define DMAR_AFLOG_REG 0x58/* Advanced Fault control */ +#define DMAR_PMEN_REG 0x64/* Enable Protected Memory Region */ +#define DMAR_PLMBASE_REG 0x68/* PMRR Low addr */ +#define DMAR_PLMLIMIT_REG 0x6c/* PMRR low limit */ +#define DMAR_PHMBASE_REG 0x70/* pmrr high base addr */ +#define DMAR_PHMLIMIT_REG 0x78/* pmrr high limit */ +#define DMAR_IQH_REG 0x80/* invalidation queue head */ +#define DMAR_IQT_REG 0x88/* invalidation queue tail */ +#define DMAR_IQT_REG_HI 0x8c +#define DMAR_IQA_REG 0x90/* invalidation queue addr */ +#define DMAR_IQA_REG_HI 0x94 +#define DMAR_ICS_REG 0x9c/* Invalidation complete status */ +#define DMAR_IECTL_REG 0xa0/* Invalidation event control */ +#define DMAR_IEDATA_REG 0xa4/* Invalidation event data */ +#define DMAR_IEADDR_REG 0xa8/* Invalidation event address */ +#define DMAR_IEUADDR_REG 0xac/* Invalidation event address */ +#define DMAR_IRTA_REG 0xb8/* Interrupt remapping table addr */ +#define DMAR_IRTA_REG_HI 0xbc +#define DMAR_PQH_REG 0xc0/* Page request queue head */ +#define DMAR_PQH_REG_HI 0xc4 +#define DMAR_PQT_REG 0xc8/* Page request queue tail*/ +#define DMAR_PQT_REG_HI 0xcc +#define DMAR_PQA_REG 0xd0/* Page request queue address */ +#define DMAR_PQA_REG_HI 0xd4 +#define DMAR_PRS_REG 0xdc/* Page request status */ +#define DMAR_PECTL_REG 0xe0/* Page request event control */ +#define DMAR_PEDATA_REG 0xe4/* Page request event data */ +#define DMAR_PEADDR_REG 0xe8/* Page request event address */ +#define DMAR_PEUADDR_REG 0xec/* Page event upper address */ +#define DMAR_MTRRCAP_REG 0x100/* MTRR capability */ +#define DMAR_MTRRCAP_REG_HI 0x104 +#define DMAR_MTRRDEF_REG 0x108/* MTRR default type */ +#define DMAR_MTRRDEF_REG_HI 0x10c#define OFFSET_STRIDE (9)#define dmar_readl (dmar, reg) readl((dmar) + (reg))@@ -58,6 +81,30 @@#define VER_MAJOR (v) (((v) & 0xf0) >> 4)#define VER_MINOR (v) ((v) & 0x0f) +/* CAP_REG */ +#define DMA_DOMAIN_ID_SHIFT 16/* 16-bit domain id for 64K domains */ +#define DMA_DOMAIN_ID_MASK ((1UL << DMA_DOMAIN_ID_SHIFT) - 1) +#define DMA_CAP_ND (((DMA_DOMAIN_ID_SHIFT - 4) / 2) & 7ULL) +#define DMA_MGAW 39/* Maximum Guest Address Width */ +#define DMA_CAP_MGAW (((DMA_MGAW - 1) & 0x3fULL) << 16) +#define DMA_MAMV 18ULL +#define DMA_CAP_MAMV (DMA_MAMV << 48) +#define DMA_CAP_PSI (1ULL << 39) +#define DMA_CAP_SLLPS ((1ULL << 34) | (1ULL << 35)) +#define DMA_FRCD_REG_NR 1ULL +#define DMA_CAP_NFR ((DMA_FRCD_REG_NR - 1) << 40) +#define DMA_CAP_FRO_OFFSET 0x220ULL +#define DMA_CAP_FRO (DMA_CAP_FRO_OFFSET << 20) + +/* Supported Adjusted Guest Address Widths */ +#define DMA_CAP_SAGAW_SHIFT 8 +#define DMA_CAP_SAGAW_MASK (0x1fULL << DMA_CAP_SAGAW_SHIFT) +/* 39-bit AGAW, 3-level page-table */ +#define DMA_CAP_SAGAW_39bit (0x2ULL << DMA_CAP_SAGAW_SHIFT) +/* 48-bit AGAW, 4-level page-table */ +#define DMA_CAP_SAGAW_48bit (0x4ULL << DMA_CAP_SAGAW_SHIFT) +#define DMA_CAP_SAGAW DMA_CAP_SAGAW_39bit +/* * Decoding Capability Register */
xen/drivers/passthrough/vtd/iommu.h line 143
Quoted 8 lines
xen/drivers/passthrough/vtd/iommu.h +5
-0@@ -89,6 +136,12 @@#define cap_afl (c) (((c) >> 3) & 1)#define cap_ndoms (c) (1 << (4 + 2 * ((c) & 0x7))) +/* ECAP_REG */ +#define DMA_ECAP_QI (1ULL << 1) +#define DMA_ECAP_IR (1ULL << 3) +#define DMA_ECAP_EIM (1ULL << 4) +#define DMA_ECAP_MHMV (15ULL << 20)
Wow, what's this chunk above? The description only mentions adding functions for the VDT IOMMU implementation, yet there seems to be some code movement here. Please split it into a separate patch.
Quoted 42 lines
xen/drivers/passthrough/vtd/iommu.h +0
-0/* * Extended Capability Register */ xen/drivers/passthrough/vtd/vvtd.c new file +33
-0@@ -0,0 +1,158 @@ +/* +* vvtd.c +* +* virtualize VTD for HVM. +* +* Copyright (C) 2017 Chao Gao, Intel Corporation. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms and conditions of the GNU General Public +* License, version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public +* License along with this program; If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <xen/domain_page.h> +#include <xen/sched.h> +#include <xen/types.h> +#include <xen/viommu.h> +#include <xen/xmalloc.h> +#include <asm/current.h> +#include <asm/hvm/domain.h> +#include <asm/page.h> + +#include "iommu.h" + +struct hvm_hw_vvtd_regs { +uint8_t data[1024 ];
xen/drivers/passthrough/vtd/vvtd.c line 43
Quoted 10 lines
xen/drivers/passthrough/vtd/vvtd.c new file +10
-0+}; + +/* Status field of struct vvtd */ +#define VIOMMU_STATUS_DEFAULT (0) +#define VIOMMU_STATUS_IRQ_REMAPPING_ENABLED (1 << 0) +#define VIOMMU_STATUS_DMA_REMAPPING_ENABLED (1 << 1) + +struct vvtd { +/* VIOMMU_STATUS_XXX */ +int status;
unsigned int if it's a bitfield.
Quoted 13 lines
xen/drivers/passthrough/vtd/vvtd.c new file +13
-0+/* Address range of remapping hardware register-set */ +uint64_t base_addr; +uint64_t length; +/* Point back to the owner domain */ +struct domain *domain; +struct hvm_hw_vvtd_regs *regs; +struct page_info *regs_page; +}; + +static inline void vvtd_set_reg (struct vvtd *vtd,uint32_t reg, +uint32_t value) +{ + *((uint32_t *)(&vtd->regs->data[reg])) = value;
xen/drivers/passthrough/vtd/vvtd.c line 66
Quoted 10 lines
xen/drivers/passthrough/vtd/vvtd.c new file +10
-0+} + +static inline uint32_t vvtd_get_reg (struct vvtd *vtd,uint32_t reg) +{ +return *((uint32_t *)(&vtd->regs->data[reg])); +} + +static inline uint8_t vvtd_get_reg_byte (struct vvtd *vtd,uint32_t reg) +{ +return *((uint8_t *)(&vtd->regs->data[reg]));
You don't need castings here, data is already an array of uint8_t.
xen/drivers/passthrough/vtd/vvtd.c line 77
Quoted 11 lines
xen/drivers/passthrough/vtd/vvtd.c new file +11
-0+} + +#define vvtd_get_reg_quad (vvtd, reg, val) do { \ + (val) = vvtd_get_reg(vvtd, (reg) + 4 ); \ + (val) = (val) << 32; \ + (val) += vvtd_get_reg(vvtd, reg); \ +} while(0) +#define vvtd_set_reg_quad (vvtd, reg, val) do { \ + vvtd_set_reg(vvtd, reg, (val)); \ + vvtd_set_reg(vvtd, (reg) + 4, (val) >> 32); \ +} while(0)
You seem to need to access hvm_hw_vvtd_regs using different sizes, why not do:
union hvm_hw_vvtd_regs {
uint8_t data8[1024];
uint16_t data16[512];
uint32_t data32[256];
uint64_t data64[128];
};Then the access is much more straightforward and you don't need the complicated helpers that you have above.
Quoted 33 lines
xen/drivers/passthrough/vtd/vvtd.c new file +33
-0+static void vvtd_reset (struct vvtd *vvtd,uint64_t capability) +{ +uint64_t cap =DMA_CAP_NFR |DMA_CAP_SLLPS |DMA_CAP_FRO | +DMA_CAP_MGAW |DMA_CAP_SAGAW |DMA_CAP_ND ; +uint64_t ecap =DMA_ECAP_IR |DMA_ECAP_EIM |DMA_ECAP_QI ; + +vvtd_set_reg (vvtd,DMAR_VER_REG ,0x10UL ); +vvtd_set_reg_quad (vvtd,DMAR_CAP_REG , cap); +vvtd_set_reg_quad (vvtd,DMAR_ECAP_REG , ecap); +vvtd_set_reg (vvtd,DMAR_FECTL_REG ,0x80000000UL ); +vvtd_set_reg (vvtd,DMAR_IECTL_REG ,0x80000000UL ); +} + +static u64 vvtd_query_caps (struct domain *d) +{ +return VIOMMU_CAP_IRQ_REMAPPING ; +} + +static int vvtd_create (struct domain *d,struct viommu *viommu) +{ +struct vvtd *vvtd; +int ret; + +if ( !is_hvm_domain (d) || (viommu->length !=PAGE_SIZE ) || + (~vvtd_query_caps (d) & viommu->caps) ) +return -EINVAL ; + + ret = -ENOMEM ; + vvtd =xmalloc_bytes (sizeof (struct vvtd )); +if ( !vvtd ) +return ret; + + vvtd->regs_page =alloc_domheap_page (d, MEMF_no_owner);
xen/drivers/passthrough/vtd/vvtd.c line 121
Quoted 10 lines
xen/drivers/passthrough/vtd/vvtd.c new file +10
-0+if ( !vvtd->regs_page ) + goto out1; + + vvtd->regs =__map_domain_page_global (vvtd->regs_page); +if ( !vvtd->regs ) + goto out2; +clear_page (vvtd->regs); + +vvtd_reset (vvtd, viommu->caps); + vvtd->base_addr = viommu->base_address;
Don't you need to perform any checks on the base_address? It needs to be page aligned at least.
Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH V2 11/25] x86/hvm: Introduce a emulated VTD for HVM
Quoted 150 lines · Roger Pau Monné
Quoted 149 lines · Lan Tianyu
From: Chao Gao <[email protected]>
This patch adds create/destroy/query function for the emulated VTD and adapts it to the common VIOMMU abstraction.
Signed-off-by Chao Gao <[email protected]>Signed-off-by Lan Tianyu <[email protected]>--- xen/drivers/passthrough/vtd/Makefile | 7 +- xen/drivers/passthrough/vtd/iommu.h | 99 +++++++++++++++++----- xen/drivers/passthrough/vtd/vvtd.c | 158 +++++++++++++++++++++++++++++++++++ xen/include/asm-x86/viommu.h | 3 + 4 files changed, 241 insertions(+), 26 deletions(-) create mode 100644 xen/drivers/passthrough/vtd/vvtd.cxen/drivers/passthrough/vtd/Makefile +4
-3@@ -1,8 +1,9 @@ subdir-$(CONFIG_X86) += x86 -obj-y += iommu.o obj-y += dmar.o -obj-y += utils.o -obj-y += qinval.o obj-y += intremap.o +obj-y += iommu.o +obj-y += qinval.o obj-y += quirks.o +obj-y += utils.o +obj-$(CONFIG_VIOMMU) += vvtd.oxen/drivers/passthrough/vtd/iommu.h +70
-23@@ -23,31 +23,54 @@#include <asm/msi.h> /* -* Intel IOMMU register specification per version 1.0 public spec. +* Intel IOMMU register specification per version 2.4 public spec. */ -#define DMAR_VER_REG 0x0/* Arch version supported by this IOMMU */ -#define DMAR_CAP_REG 0x8/* Hardware supported capabilities */ -#define DMAR_ECAP_REG 0x10/* Extended capabilities supported */ -#define DMAR_GCMD_REG 0x18/* Global command register */ -#define DMAR_GSTS_REG 0x1c/* Global status register */ -#define DMAR_RTADDR_REG 0x20/* Root entry table */ -#define DMAR_CCMD_REG 0x28/* Context command reg */ -#define DMAR_FSTS_REG 0x34/* Fault Status register */ -#define DMAR_FECTL_REG 0x38/* Fault control register */ -#define DMAR_FEDATA_REG 0x3c/* Fault event interrupt data register */ -#define DMAR_FEADDR_REG 0x40/* Fault event interrupt addr register */ -#define DMAR_FEUADDR_REG 0x44/* Upper address register */ -#define DMAR_AFLOG_REG 0x58/* Advanced Fault control */ -#define DMAR_PMEN_REG 0x64/* Enable Protected Memory Region */ -#define DMAR_PLMBASE_REG 0x68/* PMRR Low addr */ -#define DMAR_PLMLIMIT_REG 0x6c/* PMRR low limit */ -#define DMAR_PHMBASE_REG 0x70/* pmrr high base addr */ -#define DMAR_PHMLIMIT_REG 0x78/* pmrr high limit */ -#define DMAR_IQH_REG 0x80/* invalidation queue head */ -#define DMAR_IQT_REG 0x88/* invalidation queue tail */ -#define DMAR_IQA_REG 0x90/* invalidation queue addr */ -#define DMAR_IRTA_REG 0xB8/* intr remap */ +#define DMAR_VER_REG 0x0/* Arch version supported by this IOMMU */ +#define DMAR_CAP_REG 0x8/* Hardware supported capabilities */ +#define DMAR_ECAP_REG 0x10/* Extended capabilities supported */ +#define DMAR_GCMD_REG 0x18/* Global command register */ +#define DMAR_GSTS_REG 0x1c/* Global status register */ +#define DMAR_RTADDR_REG 0x20/* Root entry table */ +#define DMAR_CCMD_REG 0x28/* Context command reg */ +#define DMAR_FSTS_REG 0x34/* Fault Status register */ +#define DMAR_FECTL_REG 0x38/* Fault control register */ +#define DMAR_FEDATA_REG 0x3c/* Fault event interrupt data register */ +#define DMAR_FEADDR_REG 0x40/* Fault event interrupt addr register */ +#define DMAR_FEUADDR_REG 0x44/* Upper address register */ +#define DMAR_AFLOG_REG 0x58/* Advanced Fault control */ +#define DMAR_PMEN_REG 0x64/* Enable Protected Memory Region */ +#define DMAR_PLMBASE_REG 0x68/* PMRR Low addr */ +#define DMAR_PLMLIMIT_REG 0x6c/* PMRR low limit */ +#define DMAR_PHMBASE_REG 0x70/* pmrr high base addr */ +#define DMAR_PHMLIMIT_REG 0x78/* pmrr high limit */ +#define DMAR_IQH_REG 0x80/* invalidation queue head */ +#define DMAR_IQT_REG 0x88/* invalidation queue tail */ +#define DMAR_IQT_REG_HI 0x8c +#define DMAR_IQA_REG 0x90/* invalidation queue addr */ +#define DMAR_IQA_REG_HI 0x94 +#define DMAR_ICS_REG 0x9c/* Invalidation complete status */ +#define DMAR_IECTL_REG 0xa0/* Invalidation event control */ +#define DMAR_IEDATA_REG 0xa4/* Invalidation event data */ +#define DMAR_IEADDR_REG 0xa8/* Invalidation event address */ +#define DMAR_IEUADDR_REG 0xac/* Invalidation event address */ +#define DMAR_IRTA_REG 0xb8/* Interrupt remapping table addr */ +#define DMAR_IRTA_REG_HI 0xbc +#define DMAR_PQH_REG 0xc0/* Page request queue head */ +#define DMAR_PQH_REG_HI 0xc4 +#define DMAR_PQT_REG 0xc8/* Page request queue tail*/ +#define DMAR_PQT_REG_HI 0xcc +#define DMAR_PQA_REG 0xd0/* Page request queue address */ +#define DMAR_PQA_REG_HI 0xd4 +#define DMAR_PRS_REG 0xdc/* Page request status */ +#define DMAR_PECTL_REG 0xe0/* Page request event control */ +#define DMAR_PEDATA_REG 0xe4/* Page request event data */ +#define DMAR_PEADDR_REG 0xe8/* Page request event address */ +#define DMAR_PEUADDR_REG 0xec/* Page event upper address */ +#define DMAR_MTRRCAP_REG 0x100/* MTRR capability */ +#define DMAR_MTRRCAP_REG_HI 0x104 +#define DMAR_MTRRDEF_REG 0x108/* MTRR default type */ +#define DMAR_MTRRDEF_REG_HI 0x10c#define OFFSET_STRIDE (9)#define dmar_readl (dmar, reg) readl((dmar) + (reg))@@ -58,6 +81,30 @@#define VER_MAJOR (v) (((v) & 0xf0) >> 4)#define VER_MINOR (v) ((v) & 0x0f) +/* CAP_REG */ +#define DMA_DOMAIN_ID_SHIFT 16/* 16-bit domain id for 64K domains */ +#define DMA_DOMAIN_ID_MASK ((1UL << DMA_DOMAIN_ID_SHIFT) - 1) +#define DMA_CAP_ND (((DMA_DOMAIN_ID_SHIFT - 4) / 2) & 7ULL) +#define DMA_MGAW 39/* Maximum Guest Address Width */ +#define DMA_CAP_MGAW (((DMA_MGAW - 1) & 0x3fULL) << 16) +#define DMA_MAMV 18ULL +#define DMA_CAP_MAMV (DMA_MAMV << 48) +#define DMA_CAP_PSI (1ULL << 39) +#define DMA_CAP_SLLPS ((1ULL << 34) | (1ULL << 35)) +#define DMA_FRCD_REG_NR 1ULL +#define DMA_CAP_NFR ((DMA_FRCD_REG_NR - 1) << 40) +#define DMA_CAP_FRO_OFFSET 0x220ULL +#define DMA_CAP_FRO (DMA_CAP_FRO_OFFSET << 20) + +/* Supported Adjusted Guest Address Widths */ +#define DMA_CAP_SAGAW_SHIFT 8 +#define DMA_CAP_SAGAW_MASK (0x1fULL << DMA_CAP_SAGAW_SHIFT) +/* 39-bit AGAW, 3-level page-table */ +#define DMA_CAP_SAGAW_39bit (0x2ULL << DMA_CAP_SAGAW_SHIFT) +/* 48-bit AGAW, 4-level page-table */ +#define DMA_CAP_SAGAW_48bit (0x4ULL << DMA_CAP_SAGAW_SHIFT) +#define DMA_CAP_SAGAW DMA_CAP_SAGAW_39bit +/* * Decoding Capability Register */ @@ -89,6 +136,12 @@#define cap_afl (c) (((c) >> 3) & 1)#define cap_ndoms (c) (1 << (4 + 2 * ((c) & 0x7)))
Quoted 10 lines
xen/drivers/passthrough/vtd/iommu.h line 143
Quoted 5 lines
xen/drivers/passthrough/vtd/iommu.h +5
-0+/* ECAP_REG */ +#define DMA_ECAP_QI (1ULL << 1) +#define DMA_ECAP_IR (1ULL << 3) +#define DMA_ECAP_EIM (1ULL << 4) +#define DMA_ECAP_MHMV (15ULL << 20)Wow, what's this chunk above? The description only mentions adding functions for the VDT IOMMU implementation, yet there seems to be some code movement here. Please split it into a separate patch.
Sure. Will split.
Quoted 104 lines
Quoted 42 lines
xen/drivers/passthrough/vtd/iommu.h +0
-0/* * Extended Capability Register */ xen/drivers/passthrough/vtd/vvtd.c new file +33
-0@@ -0,0 +1,158 @@ +/* +* vvtd.c +* +* virtualize VTD for HVM. +* +* Copyright (C) 2017 Chao Gao, Intel Corporation. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms and conditions of the GNU General Public +* License, version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public +* License along with this program; If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <xen/domain_page.h> +#include <xen/sched.h> +#include <xen/types.h> +#include <xen/viommu.h> +#include <xen/xmalloc.h> +#include <asm/current.h> +#include <asm/hvm/domain.h> +#include <asm/page.h> + +#include "iommu.h" + +struct hvm_hw_vvtd_regs { +uint8_t data[1024 ];xen/drivers/passthrough/vtd/vvtd.c line 43
Quoted 10 lines
xen/drivers/passthrough/vtd/vvtd.c new file +10
-0+}; + +/* Status field of struct vvtd */ +#define VIOMMU_STATUS_DEFAULT (0) +#define VIOMMU_STATUS_IRQ_REMAPPING_ENABLED (1 << 0) +#define VIOMMU_STATUS_DMA_REMAPPING_ENABLED (1 << 1) + +struct vvtd { +/* VIOMMU_STATUS_XXX */ +int status;unsigned int if it's a bitfield.
Quoted 13 lines
xen/drivers/passthrough/vtd/vvtd.c new file +13
-0+/* Address range of remapping hardware register-set */ +uint64_t base_addr; +uint64_t length; +/* Point back to the owner domain */ +struct domain *domain; +struct hvm_hw_vvtd_regs *regs; +struct page_info *regs_page; +}; + +static inline void vvtd_set_reg (struct vvtd *vtd,uint32_t reg, +uint32_t value) +{ + *((uint32_t *)(&vtd->regs->data[reg])) = value;xen/drivers/passthrough/vtd/vvtd.c line 66
Quoted 10 lines
xen/drivers/passthrough/vtd/vvtd.c new file +10
-0+} + +static inline uint32_t vvtd_get_reg (struct vvtd *vtd,uint32_t reg) +{ +return *((uint32_t *)(&vtd->regs->data[reg])); +} + +static inline uint8_t vvtd_get_reg_byte (struct vvtd *vtd,uint32_t reg) +{ +return *((uint8_t *)(&vtd->regs->data[reg]));You don't need castings here, data is already an array of
uint8_t.xen/drivers/passthrough/vtd/vvtd.c line 77
Quoted 11 lines
xen/drivers/passthrough/vtd/vvtd.c new file +11
-0+} + +#define vvtd_get_reg_quad (vvtd, reg, val) do { \ + (val) = vvtd_get_reg(vvtd, (reg) + 4 ); \ + (val) = (val) << 32; \ + (val) += vvtd_get_reg(vvtd, reg); \ +} while(0) +#define vvtd_set_reg_quad (vvtd, reg, val) do { \ + vvtd_set_reg(vvtd, reg, (val)); \ + vvtd_set_reg(vvtd, (reg) + 4, (val) >> 32); \ +} while(0)You seem to need to access
hvm_hw_vvtd_regsusing different sizes, why not do:union hvm_hw_vvtd_regs { uint8_t data8[1024]; uint16_t data16[512]; uint32_t data32[256]; uint64_t data64[128]; };
Quoted 2 lines
Then the access is much more straightforward and you don't need the complicated helpers that you have above.
Yes, that will be simpler.
Quoted 39 lines
Quoted 39 lines
xen/drivers/passthrough/vtd/vvtd.c new file +38
-0+static void vvtd_reset (struct vvtd *vvtd,uint64_t capability) +{ +uint64_t cap =DMA_CAP_NFR |DMA_CAP_SLLPS |DMA_CAP_FRO | +DMA_CAP_MGAW |DMA_CAP_SAGAW |DMA_CAP_ND ; +uint64_t ecap =DMA_ECAP_IR |DMA_ECAP_EIM |DMA_ECAP_QI ; + +vvtd_set_reg (vvtd,DMAR_VER_REG ,0x10UL ); +vvtd_set_reg_quad (vvtd,DMAR_CAP_REG , cap); +vvtd_set_reg_quad (vvtd,DMAR_ECAP_REG , ecap); +vvtd_set_reg (vvtd,DMAR_FECTL_REG ,0x80000000UL ); +vvtd_set_reg (vvtd,DMAR_IECTL_REG ,0x80000000UL ); +} + +static u64 vvtd_query_caps (struct domain *d) +{ +return VIOMMU_CAP_IRQ_REMAPPING ; +} + +static int vvtd_create (struct domain *d,struct viommu *viommu) +{ +struct vvtd *vvtd; +int ret; + +if ( !is_hvm_domain (d) || (viommu->length !=PAGE_SIZE ) || + (~vvtd_query_caps (d) & viommu->caps) ) +return -EINVAL ; + + ret = -ENOMEM ; + vvtd =xmalloc_bytes (sizeof (struct vvtd )); +if ( !vvtd ) +return ret; + + vvtd->regs_page =alloc_domheap_page (d, MEMF_no_owner); +if ( !vvtd->regs_page ) + goto out1; + + vvtd->regs =__map_domain_page_global (vvtd->regs_page); +if ( !vvtd->regs )
Quoted 8 lines
xen/drivers/passthrough/vtd/vvtd.c line 121
Quoted 5 lines
xen/drivers/passthrough/vtd/vvtd.c new file +5
-0+ goto out2; +clear_page (vvtd->regs); + +vvtd_reset (vvtd, viommu->caps); + vvtd->base_addr = viommu->base_address;Don't you need to perform any checks on the
base_address? It needs to be page aligned at least.
Yes, it should be check.
Signature · 7 lines
Best regards Tianyu Lan _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH V2 11/25] x86/hvm: Introduce a emulated VTD for HVM
Quoted 25 lines · Lan Tianyu
Quoted 24 lines · Roger Pau Monné
xen/drivers/passthrough/vtd/vvtd.c line 77
Quoted 12 lines · Lan Tianyu
From: Chao Gao <[email protected]>
xen/drivers/passthrough/vtd/vvtd.c new file +11
-0+} + +#define vvtd_get_reg_quad (vvtd, reg, val) do { \ + (val) = vvtd_get_reg(vvtd, (reg) + 4 ); \ + (val) = (val) << 32; \ + (val) += vvtd_get_reg(vvtd, reg); \ +} while(0) +#define vvtd_set_reg_quad (vvtd, reg, val) do { \ + vvtd_set_reg(vvtd, reg, (val)); \ + vvtd_set_reg(vvtd, (reg) + 4, (val) >> 32); \ +} while(0)You seem to need to access
hvm_hw_vvtd_regsusing different sizes, why not do:union hvm_hw_vvtd_regs { uint8_t data8[1024]; uint16_t data16[512]; uint32_t data32[256]; uint64_t data64[128]; };
Quoted 4 lines
Quoted 2 lines
Then the access is much more straightforward and you don't need the complicated helpers that you have above.
Yes, that will be simpler.
Keep in mind (as said in another patch) that this approach will only work correctly as long as you force accesses to be size aligned, which you where not doing now.
I've looked at the VT-d spec, but I cannot find any section that explains the restrictions on access sizes and alignments.
Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH V2 11/25] x86/hvm: Introduce a emulated VTD for HVM
Quoted 29 lines · Roger Pau Monné
Quoted 28 lines · Lan Tianyu
Quoted 26 lines · Roger Pau Monné
xen/drivers/passthrough/vtd/vvtd.c line 77
Quoted 12 lines · Lan Tianyu
From: Chao Gao <[email protected]>
xen/drivers/passthrough/vtd/vvtd.c new file +11
-0+} + +#define vvtd_get_reg_quad (vvtd, reg, val) do { \ + (val) = vvtd_get_reg(vvtd, (reg) + 4 ); \ + (val) = (val) << 32; \ + (val) += vvtd_get_reg(vvtd, reg); \ +} while(0) +#define vvtd_set_reg_quad (vvtd, reg, val) do { \ + vvtd_set_reg(vvtd, reg, (val)); \ + vvtd_set_reg(vvtd, (reg) + 4, (val) >> 32); \ +} while(0)You seem to need to access
hvm_hw_vvtd_regsusing different sizes, why not do:union hvm_hw_vvtd_regs { uint8_t data8[1024]; uint16_t data16[512]; uint32_t data32[256]; uint64_t data64[128]; };Then the access is much more straightforward and you don't need the complicated helpers that you have above.
Quoted 9 lines
Quoted 1 line
Yes, that will be simpler.
Keep in mind (as said in another patch) that this approach will only work correctly as long as you force accesses to be size aligned, which you where not doing now.
I've looked at the VT-d spec, but I cannot find any section that explains the restrictions on access sizes and alignments.
10.2 Software Access to Registers?
Signature · 7 lines
Best regards Tianyu Lan _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH V2 11/25] x86/hvm: Introduce a emulated VTD for HVM
Quoted 36 lines · Lan Tianyu
Quoted 35 lines · Roger Pau Monné
Quoted 25 lines · Lan Tianyu
Quoted 24 lines · Roger Pau Monné
xen/drivers/passthrough/vtd/vvtd.c line 77
Quoted 12 lines · Lan Tianyu
From: Chao Gao <[email protected]>
xen/drivers/passthrough/vtd/vvtd.c new file +11
-0+} + +#define vvtd_get_reg_quad (vvtd, reg, val) do { \ + (val) = vvtd_get_reg(vvtd, (reg) + 4 ); \ + (val) = (val) << 32; \ + (val) += vvtd_get_reg(vvtd, reg); \ +} while(0) +#define vvtd_set_reg_quad (vvtd, reg, val) do { \ + vvtd_set_reg(vvtd, reg, (val)); \ + vvtd_set_reg(vvtd, (reg) + 4, (val) >> 32); \ +} while(0)You seem to need to access
hvm_hw_vvtd_regsusing different sizes, why not do:union hvm_hw_vvtd_regs { uint8_t data8[1024]; uint16_t data16[512]; uint32_t data32[256]; uint64_t data64[128]; };Quoted 4 lines
Quoted 2 lines
Then the access is much more straightforward and you don't need the complicated helpers that you have above.
Yes, that will be simpler.
Keep in mind (as said in another patch) that this approach will only work correctly as long as you force accesses to be size aligned, which you where not doing now.
Quoted 5 lines
Quoted 3 lines
I've looked at the VT-d spec, but I cannot find any section that explains the restrictions on access sizes and alignments.
10.2 Software Access to Registers?
Oh, thanks. I was grepping for "access sizes".
So yes only size aligned accesses are allowed. You should fix the patch where you check the access size/alignment so it checks for (addr & (len - 1)) (IIRC you where checking addr & 3).
Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v2 12/25 x86/vvtd: Add MMIO handler for VVTD
In reply to Lan TianyuFrom: Chao Gao <[email protected]>
This patch adds VVTD MMIO handler to deal with MMIO access.
--- xen/drivers/passthrough/vtd/vvtd.c | 114 +++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+)
xen/drivers/passthrough/vtd/vvtd.c +114 -0
@@ -50,6 +50,38 @@ struct vvtd {struct page_info *regs_page; }; +#define __DEBUG_VVTD__ +#ifdef __DEBUG_VVTD__ +extern unsigned int vvtd_debug_level; +#define VVTD_DBG_INFO 1 +#define VVTD_DBG_TRANS (1<<1) +#define VVTD_DBG_RW (1<<2) +#define VVTD_DBG_FAULT (1<<3) +#define VVTD_DBG_EOI (1<<4) +#define VVTD_DEBUG(lvl, _f, _a...) do { \ + if ( vvtd_debug_level & lvl ) \ + printk("VVTD %s:" _f "\n", __func__, ## _a); \ +} while(0) +#else +#define VVTD_DEBUG(fmt...) do {} while(0) +#endif + +unsigned int vvtd_debug_level__read_mostly ; +integer_param ("vvtd_debug" , vvtd_debug_level); + +struct vvtd *domain_vvtd (struct domain *d) +{ +struct viommu_info *info = &d->viommu; + +BUILD_BUG_ON (NR_VIOMMU_PER_DOMAIN !=1 ); +return (info && info->viommu[0 ]) ? info->viommu[0 ]->priv :NULL ; +} + +static inline struct vvtd *vcpu_vvtd (struct vcpu *v) +{ +return domain_vvtd (v->domain); +} +static inline void vvtd_set_reg (struct vvtd *vtd,uint32_t reg,uint32_t value) {
@@ -76,6 +108,87 @@ static inline uint8_t vvtd_get_reg_byte(struct vvtd *vtd, uint32_t reg)vvtd_set_reg (vvtd, (reg) +4 , (val) >>32 ); \ }while (0 ) +static int vvtd_range(struct vcpu *v, unsigned long addr) +{ +struct vvtd *vvtd =vcpu_vvtd (v); + +if ( vvtd ) +return (addr >= vvtd->base_addr) && + (addr < vvtd->base_addr +PAGE_SIZE ); +return 0 ; +} + +static int vvtd_read (struct vcpu *v,unsigned long addr, +unsigned int len,unsigned long *pval) +{ +struct vvtd *vvtd =vcpu_vvtd (v); +unsigned int offset = addr - vvtd->base_addr; +unsigned int offset_aligned = offset & ~3 ; + +VVTD_DEBUG (VVTD_DBG_RW ,"READ INFO: offset %x len %d." , offset, len); + +if ( !pval ) +return X86EMUL_UNHANDLEABLE ; + +if ( (offset &3 ) || ((len !=4 ) && (len !=8 )) ) + { +VVTD_DEBUG (VVTD_DBG_RW ,"Alignment or length is not canonical" ); +return X86EMUL_UNHANDLEABLE ; + } + +if ( len ==4 ) + *pval =vvtd_get_reg (vvtd, offset_aligned); +else +vvtd_get_reg_quad (vvtd, offset_aligned, *pval); +return X86EMUL_OKAY ; +} + +static int vvtd_write (struct vcpu *v,unsigned long addr, +unsigned int len,unsigned long val) +{ +struct vvtd *vvtd =vcpu_vvtd (v); +unsigned int offset = addr - vvtd->base_addr; +unsigned int offset_aligned = offset & ~0x3 ; +int ret; + +VVTD_DEBUG (VVTD_DBG_RW ,"WRITE INFO: offset %x len %d val %lx." , + offset, len, val); + +if ( (offset &3 ) || ((len !=4 ) && (len !=8 )) ) + { +VVTD_DEBUG (VVTD_DBG_RW ,"Alignment or length is not canonical" ); +return X86EMUL_UNHANDLEABLE ; + } + + ret =X86EMUL_UNHANDLEABLE ; +if ( len ==4 ) + { +switch ( offset_aligned ) + { +case DMAR_IEDATA_REG : +case DMAR_IEADDR_REG : +case DMAR_IEUADDR_REG : +case DMAR_FEDATA_REG : +case DMAR_FEADDR_REG : +case DMAR_FEUADDR_REG : +vvtd_set_reg (vvtd, offset_aligned, val); + ret =X86EMUL_OKAY ; +break ; + +default : +break ; + } + } + +return ret; +} + +static const struct hvm_mmio_ops vvtd_mmio_ops = { + .check = vvtd_range, + .read = vvtd_read, + .write = vvtd_write +}; +static void vvtd_reset (struct vvtd *vvtd,uint64_t capability) { uint64_t cap = DMA_CAP_NFR | DMA_CAP_SLLPS | DMA_CAP_FRO |
@@ -122,6 +235,7 @@ static int vvtd_create(struct domain *d, struct viommu *viommu) vvtd->length = viommu->length; vvtd->domain = d; vvtd->status =VIOMMU_STATUS_DEFAULT ; +register_mmio_handler (d, &vvtd_mmio_ops);return 0 ; out2:
Signature · 7 lines
1.8.3.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH V2 12/25] x86/vvtd: Add MMIO handler for VVTD
Quoted 15 lines · Lan Tianyu
From: Chao Gao <[email protected]>
This patch adds VVTD MMIO handler to deal with MMIO access.
Signed-off-by Chao Gao <[email protected]>Signed-off-by Lan Tianyu <[email protected]>--- xen/drivers/passthrough/vtd/vvtd.c | 114 +++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+)xen/drivers/passthrough/vtd/vvtd.c +0
-0
xen/drivers/passthrough/vtd/vvtd.c struct vvtd { · line 54
Quoted 5 lines
xen/drivers/passthrough/vtd/vvtd.c +2
-0@@ -50,6 +50,38 @@ struct vvtd {struct page_info *regs_page; }; +#define __DEBUG_VVTD__ +#ifdef __DEBUG_VVTD__
Why do you need this define? You can use NDEBUG which is the global Xen debug define.
Quoted 6 lines
xen/drivers/passthrough/vtd/vvtd.c +6
-0+extern unsigned int vvtd_debug_level; +#define VVTD_DBG_INFO 1 +#define VVTD_DBG_TRANS (1<<1) +#define VVTD_DBG_RW (1<<2) +#define VVTD_DBG_FAULT (1<<3) +#define VVTD_DBG_EOI (1<<4)
xen/drivers/passthrough/vtd/vvtd.c struct vvtd { · line 70
Quoted 10 lines
xen/drivers/passthrough/vtd/vvtd.c +10
-0+#define VVTD_DEBUG(lvl, _f, _a...) do { \ + if ( vvtd_debug_level & lvl ) \ + printk("VVTD %s:" _f "\n", __func__, ## _a); \ +} while(0) +#else +#define VVTD_DEBUG(fmt...) do {} while(0) +#endif + +unsigned int vvtd_debug_level__read_mostly ; +integer_param ("vvtd_debug" , vvtd_debug_level);
I think this should be a top level option for viommu, not a vtd specific one, like it's done for iommu. I would prefer to have something like:
viommu=verbose,[...]
So that we can add further options to it in the future, and that should be shared between all the vIOMMU implementations.
xen/drivers/passthrough/vtd/vvtd.c struct vvtd { · line 83
Quoted 13 lines
xen/drivers/passthrough/vtd/vvtd.c +13
-0+ +struct vvtd *domain_vvtd (struct domain *d) +{ +struct viommu_info *info = &d->viommu; + +BUILD_BUG_ON (NR_VIOMMU_PER_DOMAIN !=1 ); +return (info && info->viommu[0 ]) ? info->viommu[0 ]->priv :NULL ; +} + +static inline struct vvtd *vcpu_vvtd (struct vcpu *v) +{ +return domain_vvtd (v->domain); +}
Do you really need the above helper? Seems quite trivial to directly open code the call to domain_vvtd.
xen/drivers/passthrough/vtd/vvtd.c static inline uint8_t vvtd_get_reg_byte(struct vvtd *vtd, uint32_t reg) · line 111
Quoted 9 lines
xen/drivers/passthrough/vtd/vvtd.c +2
-0+static inline void vvtd_set_reg (struct vvtd *vtd,uint32_t reg,uint32_t value) {@@ -76,6 +108,87 @@ static inline uint8_t vvtd_get_reg_byte(struct vvtd *vtd, uint32_t reg)vvtd_set_reg (vvtd, (reg) +4 , (val) >>32 ); \ }while (0 ) +static int vvtd_range(struct vcpu *v, unsigned long addr)
bool and maybe vvtd_in_range is more descriptive.
xen/drivers/passthrough/vtd/vvtd.c static inline uint8_t vvtd_get_reg_byte(struct vvtd *vtd, uint32_t reg) · line 117
Quoted 6 lines
xen/drivers/passthrough/vtd/vvtd.c +6
-0+{ +struct vvtd *vvtd =vcpu_vvtd (v); + +if ( vvtd ) +return (addr >= vvtd->base_addr) && + (addr < vvtd->base_addr +PAGE_SIZE );
So here you simply hardcode PAGE_SIZE, which makes me think that the size parameter is indeed not needed.
xen/drivers/passthrough/vtd/vvtd.c static inline uint8_t vvtd_get_reg_byte(struct vvtd *vtd, uint32_t reg) · line 126
Quoted 9 lines
xen/drivers/passthrough/vtd/vvtd.c +9
-0+return 0 ; +} + +static int vvtd_read (struct vcpu *v,unsigned long addr, +unsigned int len,unsigned long *pval) +{ +struct vvtd *vvtd =vcpu_vvtd (v); +unsigned int offset = addr - vvtd->base_addr; +unsigned int offset_aligned = offset & ~3 ;
This is not needed IMHO.
xen/drivers/passthrough/vtd/vvtd.c static inline uint8_t vvtd_get_reg_byte(struct vvtd *vtd, uint32_t reg) · line 131
Quoted 5 lines
xen/drivers/passthrough/vtd/vvtd.c +5
-0+ +VVTD_DEBUG (VVTD_DBG_RW ,"READ INFO: offset %x len %d." , offset, len); + +if ( !pval ) +return X86EMUL_UNHANDLEABLE ;
I don't think you can get a NULL pval here.
xen/drivers/passthrough/vtd/vvtd.c static inline uint8_t vvtd_get_reg_byte(struct vvtd *vtd, uint32_t reg) · line 133
Quoted 2 lines
xen/drivers/passthrough/vtd/vvtd.c +2
-0+ +if ( (offset &3 ) || ((len !=4 ) && (len !=8 )) )
Do you really intend to allow non-aligned 8 byte accesses? If so my previous recommendation to use a union for the vvtd struct data field is moot.
xen/drivers/passthrough/vtd/vvtd.c static inline uint8_t vvtd_get_reg_byte(struct vvtd *vtd, uint32_t reg) · line 136
Quoted 3 lines
xen/drivers/passthrough/vtd/vvtd.c +3
-0+ { +VVTD_DEBUG (VVTD_DBG_RW ,"Alignment or length is not canonical" ); +return X86EMUL_UNHANDLEABLE ;
IMHO you should not return X86EMUL_UNHANDLEABLE here. The read does indeed belong to the vIOMMU region, so what does bare-metal hardware do when a non-aligned or non size compliant read is performed?
xen/drivers/passthrough/vtd/vvtd.c static inline uint8_t vvtd_get_reg_byte(struct vvtd *vtd, uint32_t reg) · line 140
Quoted 4 lines
xen/drivers/passthrough/vtd/vvtd.c +4
-0+ } + +if ( len ==4 ) + *pval =vvtd_get_reg (vvtd, offset_aligned);
You can just use offset here and below, the check that you do above guarantees that offset & 3 == 0 (ie: at this point offset == offset_aligned).
xen/drivers/passthrough/vtd/vvtd.c static inline uint8_t vvtd_get_reg_byte(struct vvtd *vtd, uint32_t reg) · line 142
Quoted 2 lines
xen/drivers/passthrough/vtd/vvtd.c +2
-0+else +vvtd_get_reg_quad (vvtd, offset_aligned, *pval);
Newline
Quoted 5 lines
xen/drivers/passthrough/vtd/vvtd.c +5
-0+return X86EMUL_OKAY ; +} + +static int vvtd_write (struct vcpu *v,unsigned long addr, +unsigned int len,unsigned long val)
xen/drivers/passthrough/vtd/vvtd.c static inline uint8_t vvtd_get_reg_byte(struct vvtd *vtd, uint32_t reg) · line 157
Quoted 10 lines
xen/drivers/passthrough/vtd/vvtd.c +10
-0+{ +struct vvtd *vvtd =vcpu_vvtd (v); +unsigned int offset = addr - vvtd->base_addr; +unsigned int offset_aligned = offset & ~0x3 ; +int ret; + +VVTD_DEBUG (VVTD_DBG_RW ,"WRITE INFO: offset %x len %d val %lx." , + offset, len, val); + +if ( (offset &3 ) || ((len !=4 ) && (len !=8 )) )
Same comment about alignment.
xen/drivers/passthrough/vtd/vvtd.c static inline uint8_t vvtd_get_reg_byte(struct vvtd *vtd, uint32_t reg) · line 163
Quoted 6 lines
xen/drivers/passthrough/vtd/vvtd.c +6
-0+ { +VVTD_DEBUG (VVTD_DBG_RW ,"Alignment or length is not canonical" ); +return X86EMUL_UNHANDLEABLE ; + } + + ret =X86EMUL_UNHANDLEABLE ;
Same here, you should not return X86EMUL_UNHANDLEABLE but instead do what the native hardware would do, which I guess is to just ignore the write?
Quoted 32 lines
xen/drivers/passthrough/vtd/vvtd.c +28
-0+if ( len ==4 ) + { +switch ( offset_aligned ) + { +case DMAR_IEDATA_REG : +case DMAR_IEADDR_REG : +case DMAR_IEUADDR_REG : +case DMAR_FEDATA_REG : +case DMAR_FEADDR_REG : +case DMAR_FEUADDR_REG : +vvtd_set_reg (vvtd, offset_aligned, val); + ret =X86EMUL_OKAY ; +break ; + +default : +break ; + } + } + +return ret; +} + +static const struct hvm_mmio_ops vvtd_mmio_ops = { + .check = vvtd_range, + .read = vvtd_read, + .write = vvtd_write +}; +static void vvtd_reset (struct vvtd *vvtd,uint64_t capability) { uint64_t cap = DMA_CAP_NFR | DMA_CAP_SLLPS | DMA_CAP_FRO |
xen/drivers/passthrough/vtd/vvtd.c static int vvtd_create(struct domain *d, struct viommu *viommu) · line 238
Quoted 4 lines
xen/drivers/passthrough/vtd/vvtd.c +1
-0@@ -122,6 +235,7 @@ static int vvtd_create(struct domain *d, struct viommu *viommu) vvtd->length = viommu->length; vvtd->domain = d; vvtd->status =VIOMMU_STATUS_DEFAULT ; +register_mmio_handler (d, &vvtd_mmio_ops);
Newline.
Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v2 13/25 x86/vvtd: Set Interrupt Remapping Table Pointer through GCMD
In reply to Lan TianyuFrom: Chao Gao <[email protected]>
Software sets this field to set/update the interrupt remapping table pointer used by hardware. The interrupt remapping table pointer is specified through the Interrupt Remapping Table Address (IRTA_REG) register.
This patch emulates this operation and adds some new fields in VVTD to track info (e.g. the table's gfn and max supported entries) of interrupt remapping table.
--- xen/drivers/passthrough/vtd/iommu.h | 9 ++++- xen/drivers/passthrough/vtd/vvtd.c | 73 +++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 1 deletion(-)
xen/drivers/passthrough/vtd/iommu.h +8 -1
@@ -192,9 +192,16 @@#define DMA_GSTS_WBFS (((u64)1) << 27)#define DMA_GSTS_QIES (((u64)1) <<26)#define DMA_GSTS_IRES (((u64)1) <<25) -#define DMA_GSTS_SIRTPS (((u64)1) << 24) +#define DMA_GSTS_SIRTPS_BIT 24 +#define DMA_GSTS_SIRTPS (((u64)1) << DMA_GSTS_SIRTPS_BIT)#define DMA_GSTS_CFIS (((u64)1) <<23) +/* IRTA_REG */ +#define DMA_IRTA_ADDR (val) (val & ~0xfffULL) +#define DMA_IRTA_EIME (val) (!!(val & (1 << 11))) +#define DMA_IRTA_S (val) (val & 0xf) +#define DMA_IRTA_SIZE (val) (1UL << (DMA_IRTA_S(val) + 1)) +/* PMEN_REG */ #define DMA_PMEN_EPM (((u32)1) << 31)#define DMA_PMEN_PRS (((u32)1) << 0)
xen/drivers/passthrough/vtd/vvtd.c +73 -0
115 lines not on this page · raw message
Signature · 7 lines
1.8.3.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH V2 13/25] x86/vvtd: Set Interrupt Remapping Table Pointer through GCMD
Quoted 22 lines · Lan Tianyu
From: Chao Gao <[email protected]>
Software sets this field to set/update the interrupt remapping table pointer used by hardware. The interrupt remapping table pointer is specified through the Interrupt Remapping Table Address (
IRTA_REG) register.This patch emulates this operation and adds some new fields in VVTD to track info (e.g. the table's gfn and max supported entries) of interrupt remapping table.
Signed-off-by Chao Gao <[email protected]>Signed-off-by Lan Tianyu <[email protected]>--- xen/drivers/passthrough/vtd/iommu.h | 9 ++++- xen/drivers/passthrough/vtd/vvtd.c | 73 +++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 1 deletion(-)xen/drivers/passthrough/vtd/iommu.h +0
-0
xen/drivers/passthrough/vtd/iommu.h line 195
Quoted 5 lines
xen/drivers/passthrough/vtd/iommu.h +1
-1@@ -192,9 +192,16 @@#define DMA_GSTS_WBFS (((u64)1) << 27)#define DMA_GSTS_QIES (((u64)1) <<26)#define DMA_GSTS_IRES (((u64)1) <<25) -#define DMA_GSTS_SIRTPS (((u64)1) << 24) +#define DMA_GSTS_SIRTPS_BIT 24
Those kind of defines are usually suffixed with _SHIFT, not _BIT.
xen/drivers/passthrough/vtd/iommu.h line 201
Quoted 6 lines
xen/drivers/passthrough/vtd/iommu.h +4
-0+#define DMA_GSTS_SIRTPS (((u64)1) << DMA_GSTS_SIRTPS_BIT)#define DMA_GSTS_CFIS (((u64)1) <<23) +/* IRTA_REG */ +#define DMA_IRTA_ADDR (val) (val & ~0xfffULL) +#define DMA_IRTA_EIME (val) (!!(val & (1 << 11)))
No need for the outer parentheses.
xen/drivers/passthrough/vtd/iommu.h line 203
Quoted 2 lines
xen/drivers/passthrough/vtd/iommu.h +2
-0+#define DMA_IRTA_S (val) (val & 0xf) +#define DMA_IRTA_SIZE (val) (1UL << (DMA_IRTA_S(val) + 1))
All those defines above seem kind of magic. Can we maybe get a small comment describing it's meaning?
Quoted 8 lines
xen/drivers/passthrough/vtd/iommu.h +0
-0/* PMEN_REG */ #define DMA_PMEN_EPM (((u32)1) << 31)#define DMA_PMEN_PRS (((u32)1) << 0)xen/drivers/passthrough/vtd/vvtd.c +0
-0
xen/drivers/passthrough/vtd/vvtd.c struct vvtd { · line 52
Quoted 7 lines
xen/drivers/passthrough/vtd/vvtd.c +4
-0@@ -46,6 +46,13 @@ struct vvtd {uint64_t length;/* Point back to the owner domain */ struct domain *domain; +/* Is in Extended Interrupt Mode? */ +bool eim; +/* Max remapping entries in IRT */ +int irt_max_entry;
unsigned int.
xen/drivers/passthrough/vtd/vvtd.c struct vvtd { · line 54
Quoted 2 lines
xen/drivers/passthrough/vtd/vvtd.c +2
-0+/* Interrupt remapping table base gfn */ +uint64_t irt;
If it's a gfn you should use gfn_t.
xen/drivers/passthrough/vtd/vvtd.c static inline struct vvtd *vcpu_vvtd(struct vcpu *v) · line 92
Quoted 9 lines
xen/drivers/passthrough/vtd/vvtd.c +2
-0+struct hvm_hw_vvtd_regs *regs;struct page_info *regs_page; };@@ -82,6 +89,11 @@ static inline struct vvtd *vcpu_vvtd(struct vcpu *v)return domain_vvtd (v->domain); } +static inline void __vvtd_set_bit (struct vvtd *vvtd,uint32_t reg,int nr)
No leading underscores, and unsigned int for nr.
xen/drivers/passthrough/vtd/vvtd.c static inline struct vvtd *vcpu_vvtd(struct vcpu *v) · line 94
Quoted 2 lines
xen/drivers/passthrough/vtd/vvtd.c +2
-0+{ +return __set_bit (nr, (uint32_t *)&vvtd->regs->data[reg]);
Why the return?
Quoted 23 lines
xen/drivers/passthrough/vtd/vvtd.c +16
-0+} +static inline void vvtd_set_reg (struct vvtd *vtd,uint32_t reg,uint32_t value) {@@ -108,6 +120,44 @@ static inline uint8_t vvtd_get_reg_byte(struct vvtd *vtd, uint32_t reg)vvtd_set_reg (vvtd, (reg) +4 , (val) >>32 ); \ }while (0 ) +static int vvtd_handle_gcmd_sirtp(struct vvtd *vvtd, uint32_t val) +{ +uint64_t irta; + +if ( !(val &DMA_GCMD_SIRTP ) ) +return X86EMUL_OKAY ; + +vvtd_get_reg_quad (vvtd,DMAR_IRTA_REG , irta); + vvtd->irt =DMA_IRTA_ADDR (irta) >>PAGE_SHIFT ; + vvtd->irt_max_entry =DMA_IRTA_SIZE (irta); + vvtd->eim =DMA_IRTA_EIME (irta); +VVTD_DEBUG (VVTD_DBG_RW ,"Update IR info (addr=%lx eim=%d size=%d)." , + vvtd->irt, vvtd->eim, vvtd->irt_max_entry); +__vvtd_set_bit (vvtd,DMAR_GSTS_REG ,DMA_GSTS_SIRTPS_BIT );
xen/drivers/passthrough/vtd/vvtd.c static inline uint8_t vvtd_get_reg_byte(struct vvtd *vtd, uint32_t reg) · line 146
Quoted 10 lines
xen/drivers/passthrough/vtd/vvtd.c +10
-0+ +return X86EMUL_OKAY ; +} + +static int vvtd_write_gcmd (struct vvtd *vvtd,uint32_t val) +{ +uint32_t orig =vvtd_get_reg (vvtd,DMAR_GSTS_REG ); +uint32_t changed; + + orig = orig &0x96ffffff ;/* reset the one-shot bits */
Some kind of define for this magic value is needed.
xen/drivers/passthrough/vtd/vvtd.c static inline uint8_t vvtd_get_reg_byte(struct vvtd *vtd, uint32_t reg) · line 153
Quoted 7 lines
xen/drivers/passthrough/vtd/vvtd.c +7
-0+ changed = orig ^ val; + +if ( !changed ) +return X86EMUL_OKAY ; +if ( (changed & (changed -1 )) ) +VVTD_DEBUG (VVTD_DBG_RW ,"Guest attempts to update multiple fields " +"of GCMD_REG in one write transation." );
Since this is a debug message it would be good to print at least the value of changed, or possibly even better the values of both orig and val.
Quoted 34 lines
xen/drivers/passthrough/vtd/vvtd.c +14
-0+ +if ( changed &DMA_GCMD_SIRTP ) +vvtd_handle_gcmd_sirtp (vvtd, val); + +return X86EMUL_OKAY ; +} +static int vvtd_range (struct vcpu *v,unsigned long addr) {struct vvtd *vvtd =vcpu_vvtd (v);@@ -165,12 +215,18 @@ static int vvtd_write(struct vcpu *v, unsigned long addr, {switch ( offset_aligned ) { +case DMAR_GCMD_REG : + ret =vvtd_write_gcmd (vvtd, val); +break ; +case DMAR_IEDATA_REG :case DMAR_IEADDR_REG :case DMAR_IEUADDR_REG :case DMAR_FEDATA_REG :case DMAR_FEADDR_REG :case DMAR_FEUADDR_REG : +case DMAR_IRTA_REG : +case DMAR_IRTA_REG_HI :vvtd_set_reg (vvtd, offset_aligned, val); ret =X86EMUL_OKAY ;break ;@@ -179,6 +235,20 @@ static int vvtd_write(struct vcpu *v, unsigned long addr,break ; } } +else /* len == 8 */
xen/drivers/passthrough/vtd/vvtd.c static int vvtd_write(struct vcpu *v, unsigned long addr, · line 248
Quoted 10 lines
xen/drivers/passthrough/vtd/vvtd.c +10
-0+ { +switch ( offset_aligned ) + { +case DMAR_IRTA_REG : +vvtd_set_reg_quad (vvtd,DMAR_IRTA_REG , val); + ret =X86EMUL_OKAY ; +break ; + +default : + ret =X86EMUL_UNHANDLEABLE ;
Same here, you should not return X86EMUL_UNHANDLEABLE but instead mimic what native hardware would do in such case.
xen/drivers/passthrough/vtd/vvtd.c static int vvtd_create(struct domain *d, struct viommu *viommu) · line 310
Quoted 13 lines
xen/drivers/passthrough/vtd/vvtd.c +6
-0+break ; + } + }return ret; }@@ -235,6 +305,9 @@ static int vvtd_create(struct domain *d, struct viommu *viommu) vvtd->length = viommu->length; vvtd->domain = d; vvtd->status =VIOMMU_STATUS_DEFAULT ; + vvtd->eim =0 ; + vvtd->irt =0 ; + vvtd->irt_max_entry =0 ;
Maybe you should consider using xzalloc which will already initialize this to 0.
Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v2 14/25 x86/vvtd: Process interrupt remapping request
In reply to Lan TianyuFrom: Chao Gao <[email protected]>
When a remapping interrupt request arrives, remapping hardware computes the interrupt_index per the algorithm described in VTD spec "Interrupt Remapping Table", interprets the IRTE and generates a remapped interrupt request.
This patch introduces viommu_handle_irq_request() to emulate the process how remapping hardware handles a remapping interrupt request.
--- xen/drivers/passthrough/vtd/iommu.h | 21 +++ xen/drivers/passthrough/vtd/vtd.h | 6 + xen/drivers/passthrough/vtd/vvtd.c | 276 +++++++++++++++++++++++++++++++++++- 3 files changed, 302 insertions(+), 1 deletion(-)
xen/drivers/passthrough/vtd/iommu.h +21 -0
@@ -244,6 +244,21 @@#define dma_frcd_source_id (c) (c & 0xffff)#define dma_frcd_page_addr (d) (d & (((u64)-1) << 12))/* low 64 bit */ +enum VTD_FAULT_TYPE +{ +/* Interrupt remapping transition faults */ +VTD_FR_IR_REQ_RSVD =0x20 ,/* One or more IR request reserved +* fields set */ +VTD_FR_IR_INDEX_OVER =0x21 ,/* Index value greater than max */ +VTD_FR_IR_ENTRY_P =0x22 ,/* Present (P) not set in IRTE */ +VTD_FR_IR_ROOT_INVAL =0x23 ,/* IR Root table invalid */ +VTD_FR_IR_IRTE_RSVD =0x24 ,/* IRTE Rsvd field non-zero with +* Present flag set */ +VTD_FR_IR_REQ_COMPAT =0x25 ,/* Encountered compatible IR +* request while disabled */ +VTD_FR_IR_SID_ERR =0x26 ,/* Invalid Source-ID */ +}; +/* * 0: Present * 1-11: Reserved
@@ -384,6 +399,12 @@ struct iremap_entry { };/* +* When VT-d doesn't enable Extended Interrupt Mode. Hardware only interprets +* only 8-bits ([15:8]) of Destination-ID field in the IRTEs. +*/ +#define IRTE_xAPIC_DEST_MASK 0xff00 + +/* * Posted-interrupt descriptor address is 64 bits with 64-byte aligned, only * the upper 26 bits of lest significiant 32 bits is available. */
xen/drivers/passthrough/vtd/vtd.h +6 -0
@@ -47,6 +47,8 @@ struct IO_APIC_route_remap_entry { }; }; +#define IOAPIC_REMAP_ENTRY_INDEX (x) ((x.index_15 << 15) + x.index_0_14) + struct msi_msg_remap_entry { union { u32 val;
@@ -65,4 +67,8 @@ struct msi_msg_remap_entry { u32 data; /* msi message data */ }; +#define MSI_REMAP_ENTRY_INDEX (x) ((x.address_lo.index_15 << 15) + \ + x.address_lo.index_0_14 + \ + (x.address_lo.SHV ? (uint16_t)x.data : 0)) +#endif // _VTD_H_
xen/drivers/passthrough/vtd/vvtd.c +275 -1
311 lines not on this page · raw message
Signature · 7 lines
1.8.3.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH V2 14/25] x86/vvtd: Process interrupt remapping request
Quoted 30 lines · Lan Tianyu
From: Chao Gao <[email protected]>
When a remapping interrupt request arrives, remapping hardware computes the
interrupt_indexper the algorithm described in VTD spec "Interrupt Remapping Table", interprets the IRTE and generates a remapped interrupt request.This patch introduces
viommu_handle_irq_request()to emulate the process how remapping hardware handles a remapping interrupt request.Signed-off-by Chao Gao <[email protected]>Signed-off-by Lan Tianyu <[email protected]>--- xen/drivers/passthrough/vtd/iommu.h | 21 +++ xen/drivers/passthrough/vtd/vtd.h | 6 + xen/drivers/passthrough/vtd/vvtd.c | 276 +++++++++++++++++++++++++++++++++++- 3 files changed, 302 insertions(+), 1 deletion(-)xen/drivers/passthrough/vtd/iommu.h +4
-0@@ -244,6 +244,21 @@#define dma_frcd_source_id (c) (c & 0xffff)#define dma_frcd_page_addr (d) (d & (((u64)-1) << 12))/* low 64 bit */ +enum VTD_FAULT_TYPE +{ +/* Interrupt remapping transition faults */ +VTD_FR_IR_REQ_RSVD =0x20 ,/* One or more IR request reserved
xen/drivers/passthrough/vtd/iommu.h line 260
Quoted 10 lines
xen/drivers/passthrough/vtd/iommu.h +10
-0+* fields set */ +VTD_FR_IR_INDEX_OVER =0x21 ,/* Index value greater than max */ +VTD_FR_IR_ENTRY_P =0x22 ,/* Present (P) not set in IRTE */ +VTD_FR_IR_ROOT_INVAL =0x23 ,/* IR Root table invalid */ +VTD_FR_IR_IRTE_RSVD =0x24 ,/* IRTE Rsvd field non-zero with +* Present flag set */ +VTD_FR_IR_REQ_COMPAT =0x25 ,/* Encountered compatible IR +* request while disabled */ + VTD_FR_IR_SID_ERR = 0x26, /* Invalid Source-ID */ +};
Could you please align the values, like:
enum VTD_FAULT_TYPE
{
/* Interrupt remapping transition faults */
VTD_FR_IR_REQ_RSVD = 0x20, /* One or more IR request reserved
* fields set */
VTD_FR_IR_INDEX_OVER = 0x21, /* Index value greater than max */xen/drivers/passthrough/vtd/iommu.h struct iremap_entry { · line 403
Quoted 10 lines
xen/drivers/passthrough/vtd/iommu.h +3
-0+/* * 0: Present * 1-11: Reserved @@ -384,6 +399,12 @@ struct iremap_entry { };/* +* When VT-d doesn't enable Extended Interrupt Mode. Hardware only interprets +* only 8-bits ([15:8]) of Destination-ID field in the IRTEs.
The above comment needs to be rewritten. My knowledge of VT-d is limited, what is IRTE referring to? I thought I was referring to the IO APIC redirection table registers, but the mask then doesn't make sense.
Quoted 12 lines
xen/drivers/passthrough/vtd/iommu.h +4
-0+*/ +#define IRTE_xAPIC_DEST_MASK 0xff00 + +/* * Posted-interrupt descriptor address is 64 bits with 64-byte aligned, only * the upper 26 bits of lest significiant 32 bits is available. */ xen/drivers/passthrough/vtd/vtd.h +0
-0
xen/drivers/passthrough/vtd/vtd.h struct IO_APIC_route_remap_entry { · line 50
Quoted 4 lines
xen/drivers/passthrough/vtd/vtd.h +1
-0@@ -47,6 +47,8 @@ struct IO_APIC_route_remap_entry { }; }; +#define IOAPIC_REMAP_ENTRY_INDEX (x) ((x.index_15 << 15) + x.index_0_14)
Could you use entry instead of x? And you should add parentheses around it's usage in the macro.
xen/drivers/passthrough/vtd/vtd.h struct msi_msg_remap_entry { · line 72
Quoted 11 lines
xen/drivers/passthrough/vtd/vtd.h +4
-0+ struct msi_msg_remap_entry { union { u32 val;@@ -65,4 +67,8 @@ struct msi_msg_remap_entry {u32 data;/* msi message data */ }; +#define MSI_REMAP_ENTRY_INDEX (x) ((x.address_lo.index_15 << 15) + \ + x.address_lo.index_0_14 + \ + (x.address_lo.SHV ? (uint16_t)x.data : 0))
Same here. And it would be clearer to place both macros together IMHO.
Quoted 33 lines
xen/drivers/passthrough/vtd/vtd.h +0
-0#endif // _VTD_H_ xen/drivers/passthrough/vtd/vvtd.c +8
-0@@ -23,11 +23,16 @@#include <xen/types.h> #include <xen/viommu.h> #include <xen/xmalloc.h> +#include <asm/apic.h> #include <asm/current.h> +#include <asm/event.h> #include <asm/hvm/domain.h> +#include <asm/io_apic.h> #include <asm/page.h> +#include <asm/p2m.h> #include "iommu.h" +#include "vtd.h" struct hvm_hw_vvtd_regs {uint8_t data[1024 ];@@ -38,6 +43,9 @@ struct hvm_hw_vvtd_regs {#define VIOMMU_STATUS_IRQ_REMAPPING_ENABLED (1 << 0)#define VIOMMU_STATUS_DMA_REMAPPING_ENABLED (1 << 1) +#define vvtd_irq_remapping_enabled (vvtd) \ + (vvtd->status & VIOMMU_STATUS_IRQ_REMAPPING_ENABLED) +struct vvtd {/* VIOMMU_STATUS_XXX */ int status;
xen/drivers/passthrough/vtd/vvtd.c static inline uint8_t vvtd_get_reg_byte(struct vvtd *vtd, uint32_t reg) · line 131
Quoted 4 lines
xen/drivers/passthrough/vtd/vvtd.c +1
-0@@ -120,6 +128,140 @@ static inline uint8_t vvtd_get_reg_byte(struct vvtd *vtd, uint32_t reg)vvtd_set_reg (vvtd, (reg) +4 , (val) >>32 ); \ }while (0 ) +static int map_guest_page(struct domain *d, uint64_t gfn, void **virt)
You can make this function return a void * and encode the error in there. See IS_ERR_VALUE and ERR_PTR.
Quoted 9 lines
xen/drivers/passthrough/vtd/vvtd.c +9
-0+{ +struct page_info *p; + + p =get_page_from_gfn (d, gfn,NULL ,P2M_ALLOC ); +if ( !p ) +return -EINVAL ; + +if ( !get_page_type (p, PGT_writable_page) ) + {
xen/drivers/passthrough/vtd/vvtd.c static inline uint8_t vvtd_get_reg_byte(struct vvtd *vtd, uint32_t reg) · line 150
Quoted 10 lines
xen/drivers/passthrough/vtd/vvtd.c +10
-0+put_page (p); +return -EINVAL ; + } + + *virt =__map_domain_page_global (p); +if ( !*virt ) + { +put_page_and_type (p); +return -ENOMEM ; + }
Newline
xen/drivers/passthrough/vtd/vvtd.c static inline uint8_t vvtd_get_reg_byte(struct vvtd *vtd, uint32_t reg) · line 161
Quoted 11 lines
xen/drivers/passthrough/vtd/vvtd.c +11
-0+return 0 ; +} + +static void unmap_guest_page (void *virt) +{ +struct page_info *page; + +if ( !virt ) +return ; + + virt = (void *)((unsigned long )virt &PAGE_MASK );
This should maybe be an ASSERT? Are you going to call unmap_guest_page with something different than the return of map_guest_page?
xen/drivers/passthrough/vtd/vvtd.c static inline uint8_t vvtd_get_reg_byte(struct vvtd *vtd, uint32_t reg) · line 172
Quoted 11 lines
xen/drivers/passthrough/vtd/vvtd.c +11
-0+ page =mfn_to_page (domain_page_map_to_mfn (virt)); + +unmap_domain_page_global (virt); +put_page_and_type (page); +} + +static void vvtd_inj_irq ( +struct vlapic *target, +uint8_t vector, +uint8_t trig_mode, +uint8_t delivery_mode)
Indentation.
Quoted 4 lines
xen/drivers/passthrough/vtd/vvtd.c +4
-0+{ + VVTD_DEBUG(VVTD_DBG_INFO, "dest=v%d, delivery_mode=%x vector=%d " + "trig_mode=%d.", + vlapic_vcpu(target)->vcpu_id, delivery_mode,
xen/drivers/passthrough/vtd/vvtd.c static inline uint8_t vvtd_get_reg_byte(struct vvtd *vtd, uint32_t reg) · line 186
Quoted 10 lines
xen/drivers/passthrough/vtd/vvtd.c +10
-0+ vector, trig_mode); + +ASSERT ((delivery_mode == dest_Fixed) || + (delivery_mode == dest_LowestPrio)); + +vlapic_set_irq (target, vector, trig_mode); +} + +static int vvtd_delivery( + struct domain *d, int vector,
uint8_t vector?
xen/drivers/passthrough/vtd/vvtd.c static inline uint8_t vvtd_get_reg_byte(struct vvtd *vtd, uint32_t reg) · line 188
Quoted 2 lines
xen/drivers/passthrough/vtd/vvtd.c +2
-0+ uint32_t dest, uint8_t dest_mode, + uint8_t delivery_mode, uint8_t trig_mode)
Indentation.
Quoted 25 lines
xen/drivers/passthrough/vtd/vvtd.c +25
-0+{ +struct vlapic *target; +struct vcpu *v; + +switch ( delivery_mode ) + { +case dest_LowestPrio: + target =vlapic_lowest_prio (d,NULL ,0 , dest, dest_mode); +if ( target !=NULL ) + { +vvtd_inj_irq (target, vector, trig_mode, delivery_mode); +break ; + } +VVTD_DEBUG (VVTD_DBG_INFO ,"null round robin: vector=%02x\n" , vector); +break ; + +case dest_Fixed: + for_each_vcpu ( d, v ) +if (vlapic_match_dest (vcpu_vlapic (v),NULL ,0 , dest, + dest_mode) ) +vvtd_inj_irq (vcpu_vlapic (v), vector, + trig_mode, delivery_mode); +break ; + +case dest_NMI:
xen/drivers/passthrough/vtd/vvtd.c static inline uint8_t vvtd_get_reg_byte(struct vvtd *vtd, uint32_t reg) · line 223
Quoted 10 lines
xen/drivers/passthrough/vtd/vvtd.c +10
-0+ for_each_vcpu ( d, v ) +if (vlapic_match_dest (vcpu_vlapic (v),NULL ,0 , dest, dest_mode) + && !test_and_set_bool (v->nmi_pending) ) +vcpu_kick (v); +break ; + +default : +printk (XENLOG_G_WARNING +"%pv: Unsupported VTD delivery mode %d for Dom%d\n" , + current, delivery_mode, d->domain_id);
gprintk? Or at least this should be rate-limited somehow, it seems like the guest can trigger such behavior?
xen/drivers/passthrough/vtd/vvtd.c static inline uint8_t vvtd_get_reg_byte(struct vvtd *vtd, uint32_t reg) · line 230
Quoted 7 lines
xen/drivers/passthrough/vtd/vvtd.c +7
-0+return -EINVAL ; + } + +return 0 ; +} + +static uint32_t irq_remapping_request_index (struct irq_remapping_request *irq)
irq should be const.
xen/drivers/passthrough/vtd/vvtd.c static inline uint8_t vvtd_get_reg_byte(struct vvtd *vtd, uint32_t reg) · line 235
Quoted 5 lines
xen/drivers/passthrough/vtd/vvtd.c +5
-0+{ +if ( irq->type ==VIOMMU_REQUEST_IRQ_MSI ) + { +struct msi_msg_remap_entry msi_msg = { { irq->msg.msi.addr },0 , + irq->msg.msi.data };
I would rather prefer that you use designated initializers, ie:
struct msi_msg_remap_entry msi_msg =
{
.address_lo = { .val = irq->msg.msi.addr },
.data = irq->msg.msi.data,
};xen/drivers/passthrough/vtd/vvtd.c static inline uint8_t vvtd_get_reg_byte(struct vvtd *vtd, uint32_t reg) · line 245
Quoted 10 lines
xen/drivers/passthrough/vtd/vvtd.c +10
-0+ +return MSI_REMAP_ENTRY_INDEX (msi_msg); + } +else if ( irq->type ==VIOMMU_REQUEST_IRQ_APIC ) + { +struct IO_APIC_route_remap_entry remap_rte = { { irq->msg.rte } }; + +return IOAPIC_REMAP_ENTRY_INDEX (remap_rte); + } +BUG ();
ASSERT_UNREACHABLE();
And newline.
xen/drivers/passthrough/vtd/vvtd.c static inline uint8_t vvtd_get_reg_byte(struct vvtd *vtd, uint32_t reg) · line 249
Quoted 4 lines
xen/drivers/passthrough/vtd/vvtd.c +4
-0+return 0 ; +} + +static inline uint32_t irte_dest (struct vvtd *vvtd,uint32_t dest)
vvtd should be const.
Quoted 4 lines
xen/drivers/passthrough/vtd/vvtd.c +4
-0+{ +uint64_t irta; + +vvtd_get_reg_quad (vvtd,DMAR_IRTA_REG , irta);
xen/drivers/passthrough/vtd/vvtd.c static inline uint8_t vvtd_get_reg_byte(struct vvtd *vtd, uint32_t reg) · line 263
Quoted 10 lines
xen/drivers/passthrough/vtd/vvtd.c +10
-0+/* In xAPIC mode, only 8-bits([15:8]) are valid */ +return DMA_IRTA_EIME (irta) ? dest :MASK_EXTR (dest, IRTE_xAPIC_DEST_MASK); +} + +static int vvtd_record_fault (struct vvtd *vvtd, +struct irq_remapping_request *irq, +int reason) +{ +return 0 ; +}
I guess this is going to be expanded later in the series? Seems pointless to introduce it now.
xen/drivers/passthrough/vtd/vvtd.c static const struct hvm_mmio_ops vvtd_mmio_ops = { · line 407
Quoted 12 lines
xen/drivers/passthrough/vtd/vvtd.c +5
-0+static int vvtd_handle_gcmd_sirtp (struct vvtd *vvtd,uint32_t val) {uint64_t irta;@@ -259,6 +401,137 @@ static const struct hvm_mmio_ops vvtd_mmio_ops = { .write = vvtd_write }; +static bool ir_sid_valid (struct iremap_entry *irte,uint32_t source_id) +{ +return true; +}
144 lines not shown · raw message
Part of this message is not shown here. View the raw message.
Re: [PATCH V2 14/25] x86/vvtd: Process interrupt remapping request
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 23.08.17 at 11:49, <[email protected]> wrote:
Quoted 3 lines · Lan Tianyu
(quoted diff) +0
-0@@ -384,6 +399,12 @@ struct iremap_entry { };
Quoted 8 lines
xen/drivers/passthrough/vtd/iommu.h struct iremap_entry { · line 403
Quoted 3 lines
xen/drivers/passthrough/vtd/iommu.h +2
-0/* +* When VT-d doesn't enable Extended Interrupt Mode. Hardware only interprets +* only 8-bits ([15:8]) of Destination-ID field in the IRTEs. The above comment needs to be rewritten. My knowledge of VT-d is limited, what is IRTE referring to? I thought I was referring to the IO APIC redirection table registers, but the mask then doesn't make sense.
IRTE = Interrupt Remapping Table Entry (a term used quite frequently); an IO-APIC one would normally be called just RTE.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v2 15/25 x86/vvtd: decode interrupt attribute from IRTE
In reply to Lan TianyuFrom: Chao Gao <[email protected]>
Previously, interrupt attributes can be extracted from msi message or IOAPIC RTE. However, with interrupt remapping enabled, the attributes are enclosed in the associated IRTE. This callback is for cases in which the caller wants to acquire interrupt attributes.
--- xen/drivers/passthrough/vtd/vvtd.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-)
xen/drivers/passthrough/vtd/vvtd.c +21 -1
@@ -532,6 +532,25 @@ static int vvtd_handle_irq_request(struct domain *d,return -EFAULT ; } +static int vvtd_get_irq_info (struct domain *d, +struct irq_remapping_request *irq, +struct irq_remapping_info *info) +{ +int ret; +struct iremap_entry irte; +struct vvtd *vvtd =domain_vvtd (d); + + ret =vvtd_get_entry (vvtd, irq, &irte, false); +if ( ret ) +return ret; + + info->vector = irte.remap.vector; + info->dest =irte_dest (vvtd, irte.remap.dst); + info->dest_mode = irte.remap.dm; + info->delivery_mode = irte.remap.dlm; +return 0 ; +} +static void vvtd_reset (struct vvtd *vvtd,uint64_t capability) { uint64_t cap = DMA_CAP_NFR | DMA_CAP_SLLPS | DMA_CAP_FRO |
@@ -608,7 +627,8 @@ struct viommu_ops vvtd_hvm_vmx_ops = { .query_caps = vvtd_query_caps, .create = vvtd_create, .destroy = vvtd_destroy, - .handle_irq_request = vvtd_handle_irq_request + .handle_irq_request = vvtd_handle_irq_request, + .get_irq_info = vvtd_get_irq_info };static int vvtd_register (void )
Signature · 7 lines
1.8.3.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH V2 15/25] x86/vvtd: decode interrupt attribute from IRTE
Quoted 6 lines · Lan Tianyu
From: Chao Gao <[email protected]>
Previously, interrupt attributes can be extracted from msi message or IOAPIC RTE. However, with interrupt remapping enabled, the attributes are enclosed in the associated IRTE. This callback is for cases in which the caller wants to acquire interrupt attributes.
Can you elaborate a little bit more on the usage? Is this for internal Xen usage or the guest itself?
Quoted 12 lines
Signed-off-by Chao Gao <[email protected]>Signed-off-by Lan Tianyu <[email protected]>--- xen/drivers/passthrough/vtd/vvtd.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-)xen/drivers/passthrough/vtd/vvtd.c +0
-0
xen/drivers/passthrough/vtd/vvtd.c static int vvtd_handle_irq_request(struct domain *d, · line 536
Quoted 5 lines
xen/drivers/passthrough/vtd/vvtd.c +2
-0@@ -532,6 +532,25 @@ static int vvtd_handle_irq_request(struct domain *d,return -EFAULT ; } +static int vvtd_get_irq_info(struct domain *d, + struct irq_remapping_request *irq,
const.
xen/drivers/passthrough/vtd/vvtd.c struct viommu_ops vvtd_hvm_vmx_ops = {
Quoted 21 lines
xen/drivers/passthrough/vtd/vvtd.c +17
-0+ struct irq_remapping_info *info) +{ +int ret; +struct iremap_entry irte; +struct vvtd *vvtd =domain_vvtd (d); + + ret =vvtd_get_entry (vvtd, irq, &irte, false); +if ( ret ) +return ret; + + info->vector = irte.remap.vector; + info->dest =irte_dest (vvtd, irte.remap.dst); + info->dest_mode = irte.remap.dm; + info->delivery_mode = irte.remap.dlm; +return 0 ; +} +static void vvtd_reset (struct vvtd *vvtd,uint64_t capability) { uint64_t cap = DMA_CAP_NFR | DMA_CAP_SLLPS | DMA_CAP_FRO |@@ -608,7 +627,8 @@ struct viommu_ops vvtd_hvm_vmx_ops = {
Forgot to mention in previous patches, vvtd_hvm_vmx_ops should be const.
Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v2 16/25 x86/vioapic: Hook interrupt delivery of vIOAPIC
In reply to Lan TianyuFrom: Chao Gao <[email protected]>
When irq remapping is enabled, IOAPIC Redirection Entry may be in remapping format. If that, generate an irq_remapping_request and call the common VIOMMU abstraction's callback to handle this interrupt request. Device model is responsible for checking the request's validity.
--- xen/arch/x86/hvm/vioapic.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
xen/arch/x86/hvm/vioapic.c +14 -0
@@ -30,6 +30,7 @@#include <xen/lib.h> #include <xen/errno.h> #include <xen/sched.h> +#include <xen/viommu.h> #include <public/hvm/ioreq.h> #include <asm/hvm/io.h> #include <asm/hvm/vpic.h>
@@ -39,6 +40,8 @@#include <asm/event.h> #include <asm/io_apic.h> +#include "../../../drivers/passthrough/vtd/vtd.h" +/* HACK: Route IRQ0 only to VCPU0 to prevent time jumps. */ #define IRQ0_SPECIAL_ROUTING 1
@@ -387,9 +390,20 @@ static void vioapic_deliver(struct hvm_vioapic *vioapic, unsigned int pin)struct vlapic *target;struct vcpu *v;unsigned int irq = vioapic->base_gsi + pin; +struct IO_APIC_route_remap_entry rte = { { vioapic->redirtbl[pin].bits } };ASSERT (spin_is_locked (&d->arch.hvm_domain.irq_lock)); +if ( rte.format ) + { +struct irq_remapping_request request; + +irq_request_ioapic_fill (&request, vioapic->id, rte.val); +/* Currently, only viommu 0 is supported */ +viommu_handle_irq_request (d,0 , &request); +return ; + } + HVM_DBG_LOG(DBG_LEVEL_IOAPIC, "dest=%x dest_mode=%x delivery_mode=%x " "vector=%x trig_mode=%x",
Signature · 7 lines
1.8.3.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH V2 16/25] x86/vioapic: Hook interrupt delivery of vIOAPIC
Quoted 26 lines · Lan Tianyu
From: Chao Gao <[email protected]>
When irq remapping is enabled, IOAPIC Redirection Entry may be in remapping format. If that, generate an
irq_remapping_requestand call the common VIOMMU abstraction's callback to handle this interrupt request. Device model is responsible for checking the request's validity.Signed-off-by Chao Gao <[email protected]>Signed-off-by Lan Tianyu <[email protected]>--- xen/arch/x86/hvm/vioapic.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)xen/arch/x86/hvm/vioapic.c +1
-0@@ -30,6 +30,7 @@#include <xen/lib.h> #include <xen/errno.h> #include <xen/sched.h> +#include <xen/viommu.h> #include <public/hvm/ioreq.h> #include <asm/hvm/io.h> #include <asm/hvm/vpic.h>
xen/arch/x86/hvm/vioapic.c line 43
Quoted 4 lines
xen/arch/x86/hvm/vioapic.c +1
-0@@ -39,6 +40,8 @@#include <asm/event.h> #include <asm/io_apic.h> +#include "../../../drivers/passthrough/vtd/vtd.h"
Ouch, that's not very nice. Why do you need this? I though that you introduced an arch-agnostic layer that should be suitable?
xen/arch/x86/hvm/vioapic.c static void vioapic_deliver(struct hvm_vioapic *vioapic, unsigned int pin) · line 393
Quoted 8 lines
xen/arch/x86/hvm/vioapic.c +1
-0/* HACK: Route IRQ0 only to VCPU0 to prevent time jumps. */ #define IRQ0_SPECIAL_ROUTING 1@@ -387,9 +390,20 @@ static void vioapic_deliver(struct hvm_vioapic *vioapic, unsigned int pin)struct vlapic *target;struct vcpu *v;unsigned int irq = vioapic->base_gsi + pin; +struct IO_APIC_route_remap_entry rte = { { vioapic->redirtbl[pin].bits } };
Designated initializers please.
Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH V2 16/25] x86/vioapic: Hook interrupt delivery of vIOAPIC
Quoted 30 lines · Roger Pau Monné
Quoted 29 lines · Lan Tianyu
From: Chao Gao <[email protected]>
When irq remapping is enabled, IOAPIC Redirection Entry may be in remapping format. If that, generate an
irq_remapping_requestand call the common VIOMMU abstraction's callback to handle this interrupt request. Device model is responsible for checking the request's validity.Signed-off-by Chao Gao <[email protected]>Signed-off-by Lan Tianyu <[email protected]>--- xen/arch/x86/hvm/vioapic.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)xen/arch/x86/hvm/vioapic.c +1
-0@@ -30,6 +30,7 @@#include <xen/lib.h> #include <xen/errno.h> #include <xen/sched.h> +#include <xen/viommu.h> #include <public/hvm/ioreq.h> #include <asm/hvm/io.h> #include <asm/hvm/vpic.h> @@ -39,6 +40,8 @@#include <asm/event.h> #include <asm/io_apic.h>
Quoted 4 lines
xen/arch/x86/hvm/vioapic.c line 43
Quoted 1 line
xen/arch/x86/hvm/vioapic.c +1
-0+#include "../../../drivers/passthrough/vtd/vtd.h" Ouch, that's not very nice. Why do you need this? I though that you introduced an arch-agnostic layer that should be suitable?
Yes, agree. So far, I think of introducing a callback of checking remapping mode in viommu ops and let vIOMMU device model to check whether vioapic is in interrupt remapping mode. Device model can use Intel or AMD IOAPIC remapping format to parse IOAPIC entry.
Quoted 14 lines
xen/arch/x86/hvm/vioapic.c static void vioapic_deliver(struct hvm_vioapic *vioapic, unsigned int pin) · line 393
Quoted 9 lines
xen/arch/x86/hvm/vioapic.c +1
-0/* HACK: Route IRQ0 only to VCPU0 to prevent time jumps. */ #define IRQ0_SPECIAL_ROUTING 1@@ -387,9 +390,20 @@ static void vioapic_deliver(struct hvm_vioapic *vioapic, unsigned int pin)struct vlapic *target;struct vcpu *v;unsigned int irq = vioapic->base_gsi + pin; +struct IO_APIC_route_remap_entry rte = { { vioapic->redirtbl[pin].bits } };Designated initializers please.
Roger.
Signature · 7 lines
Best regards Tianyu Lan _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH v2 17/25 x86/vvtd: Enable Queued Invalidation through GCMD
In reply to Lan TianyuFrom: Chao Gao <[email protected]>
Software writes to QIE fields of GCMD to enable or disable queued invalidations. This patch emulates QIE fields of GCMD.
--- xen/drivers/passthrough/vtd/iommu.h | 3 ++- xen/drivers/passthrough/vtd/vvtd.c | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-)
xen/drivers/passthrough/vtd/iommu.h +2 -1
@@ -190,7 +190,8 @@#define DMA_GSTS_FLS (((u64)1) << 29)#define DMA_GSTS_AFLS (((u64)1) << 28)#define DMA_GSTS_WBFS (((u64)1) << 27) -#define DMA_GSTS_QIES (((u64)1) <<26) +#define DMA_GSTS_QIES_BIT 26 +#define DMA_GSTS_QIES (((u64)1) << DMA_GSTS_QIES_BIT)#define DMA_GSTS_IRES (((u64)1) <<25)#define DMA_GSTS_SIRTPS_BIT 24#define DMA_GSTS_SIRTPS (((u64)1) << DMA_GSTS_SIRTPS_BIT)
xen/drivers/passthrough/vtd/vvtd.c +22 -0
@@ -102,6 +102,11 @@ static inline void __vvtd_set_bit(struct vvtd *vvtd, uint32_t reg, int nr)return __set_bit (nr, (uint32_t *)&vvtd->regs->data[reg]); } +static inline void __vvtd_clear_bit (struct vvtd *vvtd,uint32_t reg,int nr) +{ +return __clear_bit (nr, (uint32_t *)&vvtd->regs->data[reg]); +} +static inline void vvtd_set_reg (struct vvtd *vtd,uint32_t reg,uint32_t value) {
@@ -262,6 +267,21 @@ static int vvtd_record_fault(struct vvtd *vvtd,return 0 ; } +static int vvtd_handle_gcmd_qie (struct vvtd *vvtd,uint32_t val) +{ +VVTD_DEBUG (VVTD_DBG_RW ,"%sable Queue Invalidation." , + (val &DMA_GCMD_QIE ) ?"En" :"Dis" ); + +if ( val &DMA_GCMD_QIE ) +__vvtd_set_bit (vvtd,DMAR_GSTS_REG ,DMA_GSTS_QIES_BIT ); +else + { +vvtd_set_reg_quad (vvtd,DMAR_IQH_REG ,0ULL ); +__vvtd_clear_bit (vvtd,DMAR_GSTS_REG ,DMA_GSTS_QIES_BIT ); + } +return X86EMUL_OKAY ; +} +static int vvtd_handle_gcmd_sirtp (struct vvtd *vvtd,uint32_t val) {uint64_t irta;
@@ -296,6 +316,8 @@ static int vvtd_write_gcmd(struct vvtd *vvtd, uint32_t val)if ( changed &DMA_GCMD_SIRTP )vvtd_handle_gcmd_sirtp (vvtd, val); +if ( changed &DMA_GCMD_QIE ) +vvtd_handle_gcmd_qie (vvtd, val);return X86EMUL_OKAY ; }
Signature · 7 lines
1.8.3.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH V2 17/25] x86/vvtd: Enable Queued Invalidation through GCMD
Quoted 3 lines · Lan Tianyu
From: Chao Gao <[email protected]>
Software writes to QIE fields of GCMD to enable or disable queued
fields or field?
Quoted 14 lines
invalidations. This patch emulates QIE fields of GCMD.
Signed-off-by Chao Gao <[email protected]>Signed-off-by Lan Tianyu <[email protected]>--- xen/drivers/passthrough/vtd/iommu.h | 3 ++- xen/drivers/passthrough/vtd/vvtd.c | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-)xen/drivers/passthrough/vtd/iommu.h +0
-0
xen/drivers/passthrough/vtd/iommu.h line 193
Quoted 5 lines
xen/drivers/passthrough/vtd/iommu.h +1
-1@@ -190,7 +190,8 @@#define DMA_GSTS_FLS (((u64)1) << 29)#define DMA_GSTS_AFLS (((u64)1) << 28)#define DMA_GSTS_WBFS (((u64)1) << 27) -#define DMA_GSTS_QIES (((u64)1) <<26) +#define DMA_GSTS_QIES_BIT 26
_SHIFT.
xen/drivers/passthrough/vtd/vvtd.c static inline void __vvtd_set_bit(struct vvtd *vvtd, uint32_t reg, int nr) · line 105
Quoted 13 lines
xen/drivers/passthrough/vtd/iommu.h +1
-0+#define DMA_GSTS_QIES (((u64)1) << DMA_GSTS_QIES_BIT)#define DMA_GSTS_IRES (((u64)1) <<25)#define DMA_GSTS_SIRTPS_BIT 24#define DMA_GSTS_SIRTPS (((u64)1) << DMA_GSTS_SIRTPS_BIT)xen/drivers/passthrough/vtd/vvtd.c +1
-0@@ -102,6 +102,11 @@ static inline void __vvtd_set_bit(struct vvtd *vvtd, uint32_t reg, int nr)return __set_bit (nr, (uint32_t *)&vvtd->regs->data[reg]); } +static inline void __vvtd_clear_bit (struct vvtd *vvtd,uint32_t reg,int nr)
No underscore prefixes please.
xen/drivers/passthrough/vtd/vvtd.c static inline void __vvtd_set_bit(struct vvtd *vvtd, uint32_t reg, int nr) · line 107
Quoted 2 lines
xen/drivers/passthrough/vtd/vvtd.c +2
-0+{ +return __clear_bit (nr, (uint32_t *)&vvtd->regs->data[reg]);
Unneeded return.
Quoted 9 lines
xen/drivers/passthrough/vtd/vvtd.c +2
-0+} +static inline void vvtd_set_reg (struct vvtd *vtd,uint32_t reg,uint32_t value) {@@ -262,6 +267,21 @@ static int vvtd_record_fault(struct vvtd *vvtd,return 0 ; }
xen/drivers/passthrough/vtd/vvtd.c static int vvtd_record_fault(struct vvtd *vvtd, · line 279
Quoted 10 lines
xen/drivers/passthrough/vtd/vvtd.c +10
-0+static int vvtd_handle_gcmd_qie (struct vvtd *vvtd,uint32_t val) +{ +VVTD_DEBUG (VVTD_DBG_RW ,"%sable Queue Invalidation." , + (val &DMA_GCMD_QIE ) ?"En" :"Dis" ); + +if ( val &DMA_GCMD_QIE ) +__vvtd_set_bit (vvtd,DMAR_GSTS_REG ,DMA_GSTS_QIES_BIT ); +else + { +vvtd_set_reg_quad (vvtd,DMAR_IQH_REG ,0ULL );
0 should be fine, no need for the ull suffix.
xen/drivers/passthrough/vtd/vvtd.c static int vvtd_record_fault(struct vvtd *vvtd, · line 281
Quoted 2 lines
xen/drivers/passthrough/vtd/vvtd.c +2
-0+__vvtd_clear_bit (vvtd,DMAR_GSTS_REG ,DMA_GSTS_QIES_BIT ); + }
Newline.
xen/drivers/passthrough/vtd/vvtd.c static int vvtd_write_gcmd(struct vvtd *vvtd, uint32_t val) · line 320
Quoted 12 lines
xen/drivers/passthrough/vtd/vvtd.c +5
-0+return X86EMUL_OKAY ; +} +static int vvtd_handle_gcmd_sirtp (struct vvtd *vvtd,uint32_t val) {uint64_t irta;@@ -296,6 +316,8 @@ static int vvtd_write_gcmd(struct vvtd *vvtd, uint32_t val)if ( changed &DMA_GCMD_SIRTP )vvtd_handle_gcmd_sirtp (vvtd, val); +if ( changed &DMA_GCMD_QIE ) +vvtd_handle_gcmd_qie (vvtd, val);
You are losing the return value of vvtd_handle_gcmd_qie. So you either make the function void or do something with the return value.
Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v2 18/25 x86/vvtd: Enable Interrupt Remapping through GCMD
In reply to Lan TianyuFrom: Chao Gao <[email protected]>
Software writes this field to enable/disable interrupt reampping. This patch emulate IRES field of GCMD.
--- xen/drivers/passthrough/vtd/iommu.h | 3 ++- xen/drivers/passthrough/vtd/vvtd.c | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-)
xen/drivers/passthrough/vtd/iommu.h +2 -1
@@ -192,7 +192,8 @@#define DMA_GSTS_WBFS (((u64)1) << 27)#define DMA_GSTS_QIES_BIT 26#define DMA_GSTS_QIES (((u64)1) << DMA_GSTS_QIES_BIT) -#define DMA_GSTS_IRES (((u64)1) <<25) +#define DMA_GSTS_IRES_BIT 25 +#define DMA_GSTS_IRES (((u64)1) << DMA_GSTS_IRES_BIT)#define DMA_GSTS_SIRTPS_BIT 24#define DMA_GSTS_SIRTPS (((u64)1) << DMA_GSTS_SIRTPS_BIT)#define DMA_GSTS_CFIS (((u64)1) <<23)
xen/drivers/passthrough/vtd/vvtd.c +27 -0
@@ -282,6 +282,25 @@ static int vvtd_handle_gcmd_qie(struct vvtd *vvtd, uint32_t val)return X86EMUL_OKAY ; } +static int vvtd_handle_gcmd_ire (struct vvtd *vvtd,uint32_t val) +{ +VVTD_DEBUG (VVTD_DBG_RW ,"%sable Interrupt Remapping." , + (val &DMA_GCMD_IRE ) ?"En" :"Dis" ); + +if ( val &DMA_GCMD_IRE ) + { + vvtd->status |=VIOMMU_STATUS_IRQ_REMAPPING_ENABLED ; +__vvtd_set_bit (vvtd,DMAR_GSTS_REG ,DMA_GSTS_IRES_BIT ); + } +else + { + vvtd->status |= ~VIOMMU_STATUS_IRQ_REMAPPING_ENABLED ; +__vvtd_clear_bit (vvtd,DMAR_GSTS_REG ,DMA_GSTS_IRES_BIT ); + } + +return X86EMUL_OKAY ; +} +static int vvtd_handle_gcmd_sirtp (struct vvtd *vvtd,uint32_t val) {uint64_t irta;
@@ -289,6 +308,10 @@ static int vvtd_handle_gcmd_sirtp(struct vvtd *vvtd, uint32_t val)if ( !(val &DMA_GCMD_SIRTP ) )return X86EMUL_OKAY ; +if (vvtd_irq_remapping_enabled (vvtd) ) +VVTD_DEBUG (VVTD_DBG_RW ,"Update Interrupt Remapping Table when " +"active." ); +vvtd_get_reg_quad (vvtd,DMAR_IRTA_REG , irta); vvtd->irt =DMA_IRTA_ADDR (irta) >>PAGE_SHIFT ; vvtd->irt_max_entry =DMA_IRTA_SIZE (irta);
@@ -318,6 +341,10 @@ static int vvtd_write_gcmd(struct vvtd *vvtd, uint32_t val)vvtd_handle_gcmd_sirtp (vvtd, val);if ( changed &DMA_GCMD_QIE )vvtd_handle_gcmd_qie (vvtd, val); +if ( changed &DMA_GCMD_IRE ) +vvtd_handle_gcmd_ire (vvtd, val); +if ( changed & ~(DMA_GCMD_QIE |DMA_GCMD_SIRTP |DMA_GCMD_IRE ) ) +gdprintk (XENLOG_INFO ,"Only QIE,SIRTP,IRE in GCMD_REG are handled.\n" );return X86EMUL_OKAY ; }
Signature · 7 lines
1.8.3.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH V2 18/25] x86/vvtd: Enable Interrupt Remapping through GCMD
Quoted 17 lines · Lan Tianyu
From: Chao Gao <[email protected]>
Software writes this field to enable/disable interrupt reampping. This patch emulate IRES field of GCMD.
Signed-off-by Chao Gao <[email protected]>Signed-off-by Lan Tianyu <[email protected]>--- xen/drivers/passthrough/vtd/iommu.h | 3 ++- xen/drivers/passthrough/vtd/vvtd.c | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-)xen/drivers/passthrough/vtd/iommu.h +0
-0
xen/drivers/passthrough/vtd/iommu.h line 195
Quoted 5 lines
xen/drivers/passthrough/vtd/iommu.h +1
-1@@ -192,7 +192,8 @@#define DMA_GSTS_WBFS (((u64)1) << 27)#define DMA_GSTS_QIES_BIT 26#define DMA_GSTS_QIES (((u64)1) << DMA_GSTS_QIES_BIT) -#define DMA_GSTS_IRES (((u64)1) <<25) +#define DMA_GSTS_IRES_BIT 25
_SHIFT.
Quoted 15 lines
xen/drivers/passthrough/vtd/iommu.h +1
-0+#define DMA_GSTS_IRES (((u64)1) << DMA_GSTS_IRES_BIT)#define DMA_GSTS_SIRTPS_BIT 24#define DMA_GSTS_SIRTPS (((u64)1) << DMA_GSTS_SIRTPS_BIT)#define DMA_GSTS_CFIS (((u64)1) <<23)xen/drivers/passthrough/vtd/vvtd.c +3
-0@@ -282,6 +282,25 @@ static int vvtd_handle_gcmd_qie(struct vvtd *vvtd, uint32_t val)return X86EMUL_OKAY ; } +static int vvtd_handle_gcmd_ire (struct vvtd *vvtd,uint32_t val) +{ + VVTD_DEBUG(VVTD_DBG_RW, "%sable Interrupt Remapping.",
xen/drivers/passthrough/vtd/vvtd.c static int vvtd_handle_gcmd_qie(struct vvtd *vvtd, uint32_t val) · line 297
Quoted 10 lines
xen/drivers/passthrough/vtd/vvtd.c +10
-0+ (val & DMA_GCMD_IRE) ? "En" : "Dis"); + +if ( val &DMA_GCMD_IRE ) + { + vvtd->status |=VIOMMU_STATUS_IRQ_REMAPPING_ENABLED ; +__vvtd_set_bit (vvtd,DMAR_GSTS_REG ,DMA_GSTS_IRES_BIT ); + } +else + { + vvtd->status |= ~VIOMMU_STATUS_IRQ_REMAPPING_ENABLED ;
Hm, that's not correct, you are not clearing the bit here. It should be '&=', not '|='.
Quoted 10 lines
xen/drivers/passthrough/vtd/vvtd.c +6
-0+__vvtd_clear_bit (vvtd,DMAR_GSTS_REG ,DMA_GSTS_IRES_BIT ); + } + +return X86EMUL_OKAY ; +} +static int vvtd_handle_gcmd_sirtp (struct vvtd *vvtd,uint32_t val) {uint64_t irta;
xen/drivers/passthrough/vtd/vvtd.c static int vvtd_handle_gcmd_sirtp(struct vvtd *vvtd, uint32_t val) · line 313
Quoted 6 lines
xen/drivers/passthrough/vtd/vvtd.c +3
-0@@ -289,6 +308,10 @@ static int vvtd_handle_gcmd_sirtp(struct vvtd *vvtd, uint32_t val)if ( !(val &DMA_GCMD_SIRTP ) )return X86EMUL_OKAY ; +if (vvtd_irq_remapping_enabled (vvtd) ) +VVTD_DEBUG (VVTD_DBG_RW ,"Update Interrupt Remapping Table when " +"active." );
Don't split console messages, instead add a newline and align to the '('.
xen/drivers/passthrough/vtd/vvtd.c static int vvtd_write_gcmd(struct vvtd *vvtd, uint32_t val) · line 345
Quoted 10 lines
xen/drivers/passthrough/vtd/vvtd.c +3
-0+vvtd_get_reg_quad (vvtd,DMAR_IRTA_REG , irta); vvtd->irt =DMA_IRTA_ADDR (irta) >>PAGE_SHIFT ; vvtd->irt_max_entry =DMA_IRTA_SIZE (irta);@@ -318,6 +341,10 @@ static int vvtd_write_gcmd(struct vvtd *vvtd, uint32_t val)vvtd_handle_gcmd_sirtp (vvtd, val);if ( changed &DMA_GCMD_QIE )vvtd_handle_gcmd_qie (vvtd, val); +if ( changed &DMA_GCMD_IRE ) +vvtd_handle_gcmd_ire (vvtd, val);
Lost return value of vvtd_handle_gcmd_ire.
xen/drivers/passthrough/vtd/vvtd.c static int vvtd_write_gcmd(struct vvtd *vvtd, uint32_t val) · line 347
Quoted 2 lines
xen/drivers/passthrough/vtd/vvtd.c +2
-0+if ( changed & ~(DMA_GCMD_QIE |DMA_GCMD_SIRTP |DMA_GCMD_IRE ) ) +gdprintk (XENLOG_INFO ,"Only QIE,SIRTP,IRE in GCMD_REG are handled.\n" );
Missing spaces between commas, and I think this should be a VVTD_DEBUG in any case, although I'm not sure of it's usefulness.
Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v2 19/25 x86/vioapic: extend vioapic_get_vector() to support remapping format RTE
In reply to Lan TianyuFrom: Chao Gao <[email protected]>
When IOAPIC RTE is in remapping format, it doesn't contain the vector of interrupt. For this case, the RTE contains an index of interrupt remapping table where the vector of interrupt is stored. This patchs gets the vector through a vIOMMU interface.
--- xen/arch/x86/hvm/vioapic.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
xen/arch/x86/hvm/vioapic.c +17 -1
@@ -565,11 +565,27 @@ int vioapic_get_vector(const struct domain *d, unsigned int gsi) {unsigned int pin;const struct hvm_vioapic *vioapic =gsi_vioapic (d, gsi, &pin); +struct IO_APIC_route_remap_entry rte = { { vioapic->redirtbl[pin].bits } };if ( !vioapic )return -EINVAL ; -return vioapic->redirtbl[pin].fields.vector; +if ( rte.format ) + { +int err; +struct irq_remapping_request request; +struct irq_remapping_info info; + +irq_request_ioapic_fill (&request, vioapic->id, rte.val); +/* Currently, only viommu 0 is supported */ + err =viommu_get_irq_info (vioapic->domain,0 , &request, &info); +return !err ? info.vector :-1 ; + } +else + { +return vioapic->redirtbl[pin].fields.vector; + } + }int vioapic_get_trigger_mode (const struct domain *d,unsigned int gsi)
Signature · 7 lines
1.8.3.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH V2 19/25] x86/vioapic: extend vioapic_get_vector() to support remapping format RTE
Quoted 18 lines · Lan Tianyu
From: Chao Gao <[email protected]>
When IOAPIC RTE is in remapping format, it doesn't contain the vector of interrupt. For this case, the RTE contains an index of interrupt remapping table where the vector of interrupt is stored. This patchs gets the vector through a vIOMMU interface.
Signed-off-by Chao Gao <[email protected]>Signed-off-by Lan Tianyu <[email protected]>--- xen/arch/x86/hvm/vioapic.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)xen/arch/x86/hvm/vioapic.c +0
-0
xen/arch/x86/hvm/vioapic.c int vioapic_get_vector(const struct domain *d, unsigned int gsi) · line 568
Quoted 4 lines
xen/arch/x86/hvm/vioapic.c +1
-0@@ -565,11 +565,27 @@ int vioapic_get_vector(const struct domain *d, unsigned int gsi) {unsigned int pin;const struct hvm_vioapic *vioapic =gsi_vioapic (d, gsi, &pin); +struct IO_APIC_route_remap_entry rte = { { vioapic->redirtbl[pin].bits } };
Designated initialization and const.
xen/arch/x86/hvm/vioapic.c int vioapic_get_vector(const struct domain *d, unsigned int gsi) · line 580
Quoted 13 lines
xen/arch/x86/hvm/vioapic.c +8
-1if ( !vioapic )return -EINVAL ; -return vioapic->redirtbl[pin].fields.vector; +if ( rte.format ) + { +int err; +struct irq_remapping_request request; +struct irq_remapping_info info; + +irq_request_ioapic_fill (&request, vioapic->id, rte.val); +/* Currently, only viommu 0 is supported */
This seems to be hardcoded in a bunch of places, which makes me wonder whether having an array of vIOMMUs is the correct choice. I think that you should remove the array and have a single vIOMMU per domain.
xen/arch/x86/hvm/vioapic.c int vioapic_get_vector(const struct domain *d, unsigned int gsi) · line 582
Quoted 2 lines
xen/arch/x86/hvm/vioapic.c +2
-0+ err =viommu_get_irq_info (vioapic->domain,0 , &request, &info); +return !err ? info.vector :-1 ;
maybe:
return err ?: info.vector;
?
Quoted 17 lines
xen/arch/x86/hvm/vioapic.c +6
-0+ } +else + { +return vioapic->redirtbl[pin].fields.vector; + } + }int vioapic_get_trigger_mode (const struct domain *d,unsigned int gsi)Signature · 7 lines
1.8.3.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH V2 19/25] x86/vioapic: extend vioapic_get_vector() to support remapping format RTE
Quoted 40 lines · Roger Pau Monné
Quoted 18 lines · Lan Tianyu
From: Chao Gao <[email protected]>
When IOAPIC RTE is in remapping format, it doesn't contain the vector of interrupt. For this case, the RTE contains an index of interrupt remapping table where the vector of interrupt is stored. This patchs gets the vector through a vIOMMU interface.
Signed-off-by Chao Gao <[email protected]>Signed-off-by Lan Tianyu <[email protected]>--- xen/arch/x86/hvm/vioapic.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)xen/arch/x86/hvm/vioapic.c +0
-0xen/arch/x86/hvm/vioapic.c int vioapic_get_vector(const struct domain *d, unsigned int gsi) · line 568
Quoted 4 lines
xen/arch/x86/hvm/vioapic.c +1
-0@@ -565,11 +565,27 @@ int vioapic_get_vector(const struct domain *d, unsigned int gsi) {unsigned int pin;const struct hvm_vioapic *vioapic =gsi_vioapic (d, gsi, &pin); +struct IO_APIC_route_remap_entry rte = { { vioapic->redirtbl[pin].bits } };Designated initialization and const.
xen/arch/x86/hvm/vioapic.c int vioapic_get_vector(const struct domain *d, unsigned int gsi) · line 580
Quoted 13 lines
xen/arch/x86/hvm/vioapic.c +8
-1if ( !vioapic )return -EINVAL ; -return vioapic->redirtbl[pin].fields.vector; +if ( rte.format ) + { +int err; +struct irq_remapping_request request; +struct irq_remapping_info info; + +irq_request_ioapic_fill (&request, vioapic->id, rte.val); +/* Currently, only viommu 0 is supported */
Quoted 3 lines
This seems to be hardcoded in a bunch of places, which makes me wonder whether having an array of vIOMMUs is the correct choice. I think that you should remove the array and have a single vIOMMU per domain.
The array is reserved for mult-vIOMMU support but so far no such requirement as I know. In design stage, someone commented we should take mult-vIOMMU support into account.
We may add callback of getting vIOMMU in vIOMMU ops and let vIOMMU device model return associated vIOMMU instance according irq remapping information(e.g source id). One VM suppose to have only one vIOMMU type. When add multi-vIOMMU support, this logic also can be applied.
For current scenario. device model should return the first vIOMMU directly.
Quoted 27 lines
xen/arch/x86/hvm/vioapic.c int vioapic_get_vector(const struct domain *d, unsigned int gsi) · line 582
Quoted 3 lines
xen/arch/x86/hvm/vioapic.c +2
-0+ err =viommu_get_irq_info (vioapic->domain,0 , &request, &info); +return !err ? info.vector :-1 ;maybe:
return err ?: info.vector;
?
Quoted 17 lines
xen/arch/x86/hvm/vioapic.c +6
-0+ } +else + { +return vioapic->redirtbl[pin].fields.vector; + } + }int vioapic_get_trigger_mode (const struct domain *d,unsigned int gsi)Signature · 7 lines
1.8.3.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Signature · 7 lines
Best regards Tianyu Lan _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH V2 19/25] x86/vioapic: extend vioapic_get_vector() to support remapping format RTE
Quoted 27 lines
Quoted 1 line
Quoted 1 line · On 24.08.17 at 08:11, <[email protected]> wrote:
Quoted 25 lines · Roger Pau Monné
xen/arch/x86/hvm/vioapic.c int vioapic_get_vector(const struct domain *d, unsigned int gsi) · line 568
Quoted 7 lines · Lan Tianyu
xen/arch/x86/hvm/vioapic.c +1
-0@@ -565,11 +565,27 @@ int vioapic_get_vector(const struct domain *d, unsigned int gsi) {unsigned int pin;const struct hvm_vioapic *vioapic =gsi_vioapic (d, gsi, &pin); +struct IO_APIC_route_remap_entry rte = { { vioapic->redirtbl[pin].bits } };Designated initialization and const.
Quoted 13 lines
xen/arch/x86/hvm/vioapic.c +8
-1if ( !vioapic )return -EINVAL ; -return vioapic->redirtbl[pin].fields.vector; +if ( rte.format ) + { +int err; +struct irq_remapping_request request; +struct irq_remapping_info info; + +irq_request_ioapic_fill (&request, vioapic->id, rte.val); +/* Currently, only viommu 0 is supported */
Quoted 7 lines
Quoted 3 lines
This seems to be hardcoded in a bunch of places, which makes me wonder whether having an array of vIOMMUs is the correct choice. I think that you should remove the array and have a single vIOMMU per domain.
The array is reserved for mult-vIOMMU support but so far no such requirement as I know. In design stage, someone commented we should take mult-vIOMMU support into account.
It _may_ suffice to do so at the public interface level. I'm not against using a single entry array right away, but then the rest of the code needs to be written as if the array bound was not fixed at 1, i.e. no hard coded uses of zero as the only valid array index should occur.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH V2 19/25] x86/vioapic: extend vioapic_get_vector() to support remapping format RTE
Quoted 35 lines · Jan Beulich
Quoted 27 lines
Quoted 1 line
Quoted 1 line · On 24.08.17 at 08:11, <[email protected]> wrote:
Quoted 25 lines · Roger Pau Monné
xen/arch/x86/hvm/vioapic.c int vioapic_get_vector(const struct domain *d, unsigned int gsi) · line 568
Quoted 7 lines · Lan Tianyu
xen/arch/x86/hvm/vioapic.c +1
-0@@ -565,11 +565,27 @@ int vioapic_get_vector(const struct domain *d, unsigned int gsi) {unsigned int pin;const struct hvm_vioapic *vioapic =gsi_vioapic (d, gsi, &pin); +struct IO_APIC_route_remap_entry rte = { { vioapic->redirtbl[pin].bits } };Designated initialization and const.
Quoted 13 lines
xen/arch/x86/hvm/vioapic.c +8
-1if ( !vioapic )return -EINVAL ; -return vioapic->redirtbl[pin].fields.vector; +if ( rte.format ) + { +int err; +struct irq_remapping_request request; +struct irq_remapping_info info; + +irq_request_ioapic_fill (&request, vioapic->id, rte.val); +/* Currently, only viommu 0 is supported */ Quoted 7 lines
Quoted 3 lines
This seems to be hardcoded in a bunch of places, which makes me wonder whether having an array of vIOMMUs is the correct choice. I think that you should remove the array and have a single vIOMMU per domain.
The array is reserved for mult-vIOMMU support but so far no such requirement as I know. In design stage, someone commented we should take mult-vIOMMU support into account.
Quoted 5 lines
It _may_ suffice to do so at the public interface level. I'm not against using a single entry array right away, but then the rest of the code needs to be written as if the array bound was not fixed at 1, i.e. no hard coded uses of zero as the only valid array index should occur.
Hi Jan:
I am not sure whether we can hide single vIOMMU logic in the device model. When vIOMMU instance is created in device model, store vIOMMU instance in the global variable of virtual VTD code. Provide getting viommu instance callback in vIOMMU ops and helper function in vIOMMU abstract layer with interrupt information as parameter. New callback always returns stored vIOMMU instance. This seems to avoid hard coded uses of zero.
If this can't be accept, removing the array seems to be only feasible way.
Signature · 7 lines
Best regards Tianyu Lan _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH v2 20/25 passthrough: move some fields of hvm_gmsi_info to a sub-structure
In reply to Lan TianyuFrom: Chao Gao <[email protected]>
No functional change. It is a preparation for introducing new fields in hvm_gmsi_info to manage remapping format msi bound to a physical msi.
--- xen/arch/x86/hvm/vmsi.c | 4 ++-- xen/drivers/passthrough/io.c | 32 ++++++++++++++++---------------- xen/include/xen/hvm/irq.h | 8 ++++++-- 3 files changed, 24 insertions(+), 20 deletions(-)
xen/arch/x86/hvm/vmsi.c +2 -2
@@ -101,8 +101,8 @@ int vmsi_deliver(void vmsi_deliver_pirq (struct domain *d,const struct hvm_pirq_dpci *pirq_dpci) { -uint32_t flags = pirq_dpci->gmsi.gflags; -int vector = pirq_dpci->gmsi.gvec; +uint32_t flags = pirq_dpci->gmsi.legacy.gflags; +int vector = pirq_dpci->gmsi.legacy.gvec;uint8_t dest = (uint8_t )flags;uint8_t dest_mode = !!(flags &VMSI_DM_MASK );uint8_t delivery_mode = (flags &VMSI_DELIV_MASK )
xen/drivers/passthrough/io.c +16 -16
@@ -348,8 +348,8 @@ int pt_irq_create_bind( { pirq_dpci->flags =HVM_IRQ_DPCI_MAPPED |HVM_IRQ_DPCI_MACH_MSI |HVM_IRQ_DPCI_GUEST_MSI ; - pirq_dpci->gmsi.gvec = pt_irq_bind->u.msi.gvec; - pirq_dpci->gmsi.gflags = pt_irq_bind->u.msi.gflags; + pirq_dpci->gmsi.legacy.gvec = pt_irq_bind->u.msi.gvec; + pirq_dpci->gmsi.legacy.gflags = pt_irq_bind->u.msi.gflags;/* * 'pt_irq_create_bind' can be called after 'pt_irq_destroy_bind'. * The 'pirq_cleanup_check' which would free the structure is only
@@ -381,8 +381,8 @@ int pt_irq_create_bind( }if (unlikely (rc) ) { - pirq_dpci->gmsi.gflags =0 ; - pirq_dpci->gmsi.gvec =0 ; + pirq_dpci->gmsi.legacy.gflags =0 ; + pirq_dpci->gmsi.legacy.gvec =0 ; pirq_dpci->dom =NULL ; pirq_dpci->flags =0 ;pirq_cleanup_check (info, d);
@@ -401,20 +401,20 @@ int pt_irq_create_bind( }/* If pirq is already mapped as vmsi, update guest data/addr. */ -if ( pirq_dpci->gmsi.gvec != pt_irq_bind->u.msi.gvec || - pirq_dpci->gmsi.gflags != pt_irq_bind->u.msi.gflags ) +if ( pirq_dpci->gmsi.legacy.gvec != pt_irq_bind->u.msi.gvec || + pirq_dpci->gmsi.legacy.gflags != pt_irq_bind->u.msi.gflags ) {/* Directly clear pending EOIs before enabling new MSI info. */ pirq_guest_eoi (info); - pirq_dpci->gmsi.gvec = pt_irq_bind->u.msi.gvec; - pirq_dpci->gmsi.gflags = pt_irq_bind->u.msi.gflags; + pirq_dpci->gmsi.legacy.gvec = pt_irq_bind->u.msi.gvec; + pirq_dpci->gmsi.legacy.gflags = pt_irq_bind->u.msi.gflags; } }/* Calculate dest_vcpu_id for MSI-type pirq migration. */ - dest = pirq_dpci->gmsi.gflags &VMSI_DEST_ID_MASK ; - dest_mode = !!(pirq_dpci->gmsi.gflags &VMSI_DM_MASK ); - delivery_mode = (pirq_dpci->gmsi.gflags &VMSI_DELIV_MASK ) >> + dest = pirq_dpci->gmsi.legacy.gflags &VMSI_DEST_ID_MASK ; + dest_mode = !!(pirq_dpci->gmsi.legacy.gflags &VMSI_DM_MASK ); + delivery_mode = (pirq_dpci->gmsi.legacy.gflags &VMSI_DELIV_MASK ) >>GFLAGS_SHIFT_DELIV_MODE ; dest_vcpu_id =hvm_girq_dest_2_vcpu_id (d, dest, dest_mode);
@@ -427,7 +427,7 @@ int pt_irq_create_bind( {if ( delivery_mode == dest_LowestPrio ) vcpu =vector_hashing_dest (d, dest, dest_mode, - pirq_dpci->gmsi.gvec); + pirq_dpci->gmsi.legacy.gvec);if ( vcpu ) pirq_dpci->gmsi.posted = true; }
@@ -437,7 +437,7 @@ int pt_irq_create_bind(/* Use interrupt posting if it is supported. */ if ( iommu_intpost )pi_update_irte (vcpu ? &vcpu->arch.hvm_vmx.pi_desc :NULL , - info, pirq_dpci->gmsi.gvec); + info, pirq_dpci->gmsi.legacy.gvec);break ; }
@@ -817,10 +817,10 @@ static int _hvm_dpci_msi_eoi(struct domain *d,int vector = (long )arg;if ( (pirq_dpci->flags &HVM_IRQ_DPCI_MACH_MSI ) && - (pirq_dpci->gmsi.gvec == vector) ) + (pirq_dpci->gmsi.legacy.gvec == vector) ) { -int dest = pirq_dpci->gmsi.gflags &VMSI_DEST_ID_MASK ; -int dest_mode = !!(pirq_dpci->gmsi.gflags &VMSI_DM_MASK ); +int dest = pirq_dpci->gmsi.legacy.gflags &VMSI_DEST_ID_MASK ; +int dest_mode = !!(pirq_dpci->gmsi.legacy.gflags &VMSI_DM_MASK );if (vlapic_match_dest (vcpu_vlapic (current),NULL ,0 , dest, dest_mode) )
xen/include/xen/hvm/irq.h +6 -2
@@ -62,8 +62,12 @@ struct dev_intx_gsi_link {#define GFLAGS_SHIFT_TRG_MODE 15struct hvm_gmsi_info { -uint32_t gvec; -uint32_t gflags; +union { +struct { +uint32_t gvec; +uint32_t gflags; + } legacy; + };int dest_vcpu_id;/* -1 :multi-dest, non-negative: dest_vcpu_id */ bool posted;/* directly deliver to guest via VT-d PI? */ };
Signature · 7 lines
1.8.3.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH v2 21/25 tools/libxc: Add a new interface to bind remapping format msi with pirq
In reply to Lan TianyuFrom: Chao Gao <[email protected]>
Introduce a new binding relationship and provide a new interface to manage the new relationship.
--- tools/libxc/include/xenctrl.h | 17 ++++++ tools/libxc/xc_domain.c | 53 +++++++++++++++++ xen/drivers/passthrough/io.c | 135 +++++++++++++++++++++++++++++++++++------- xen/include/public/domctl.h | 7 +++ xen/include/xen/hvm/irq.h | 7 +++ 5 files changed, 198 insertions(+), 21 deletions(-)
tools/libxc/include/xenctrl.h +17 -0
@@ -1720,6 +1720,15 @@ int xc_domain_ioport_mapping(xc_interface *xch,uint32_t nr_ports, uint32_t add_mapping); +int xc_domain_update_msi_irq_remapping ( +xc_interface *xch, +uint32_t domid, +uint32_t pirq, +uint32_t source_id, +uint32_t data, +uint64_t addr, +uint64_t gtable); + int xc_domain_update_msi_irq( xc_interface *xch, uint32_t domid,
@@ -1734,6 +1743,14 @@ int xc_domain_unbind_msi_irq(xc_interface *xch,uint32_t pirq, uint32_t gflags); +int xc_domain_unbind_msi_irq_remapping ( +xc_interface *xch, +uint32_t domid, +uint32_t pirq, +uint32_t source_id, +uint32_t data, +uint64_t addr); + int xc_domain_bind_pt_irq(xc_interface *xch, uint32_t domid, uint8_t machine_irq,
tools/libxc/xc_domain.c +53 -0
67 lines not on this page · raw message
xen/drivers/passthrough/io.c +114 -21
203 lines not on this page · raw message
xen/include/public/domctl.h +7 -0
@@ -555,6 +555,7 @@ typedef enum pt_irq_type_e { PT_IRQ_TYPE_MSI,PT_IRQ_TYPE_MSI_TRANSLATE ,PT_IRQ_TYPE_SPI ,/* ARM: valid range 32-1019 */ +PT_IRQ_TYPE_MSI_IR , } pt_irq_type_t;struct xen_domctl_bind_pt_irq {uint32_t machine_irq;
@@ -575,6 +576,12 @@ struct xen_domctl_bind_pt_irq {uint64_aligned_t gtable; } msi;struct { +uint32_t source_id; +uint32_t data; +uint64_t addr; +uint64_aligned_t gtable; + } msi_ir; +struct {uint16_t spi; } spi; } u;
xen/include/xen/hvm/irq.h +7 -0
@@ -41,6 +41,7 @@ struct dev_intx_gsi_link {#define _HVM_IRQ_DPCI_GUEST_PCI_SHIFT 4#define _HVM_IRQ_DPCI_GUEST_MSI_SHIFT 5#define _HVM_IRQ_DPCI_IDENTITY_GSI_SHIFT 6 +#define _HVM_IRQ_DPCI_GUEST_MSI_IR_SHIFT 7#define _HVM_IRQ_DPCI_TRANSLATE_SHIFT 15#define HVM_IRQ_DPCI_MACH_PCI (1 << _HVM_IRQ_DPCI_MACH_PCI_SHIFT)#define HVM_IRQ_DPCI_MACH_MSI (1 << _HVM_IRQ_DPCI_MACH_MSI_SHIFT)
@@ -49,6 +50,7 @@ struct dev_intx_gsi_link {#define HVM_IRQ_DPCI_GUEST_PCI (1 << _HVM_IRQ_DPCI_GUEST_PCI_SHIFT)#define HVM_IRQ_DPCI_GUEST_MSI (1 << _HVM_IRQ_DPCI_GUEST_MSI_SHIFT)#define HVM_IRQ_DPCI_IDENTITY_GSI (1 << _HVM_IRQ_DPCI_IDENTITY_GSI_SHIFT) +#define HVM_IRQ_DPCI_GUEST_MSI_IR (1 << _HVM_IRQ_DPCI_GUEST_MSI_IR_SHIFT)#define HVM_IRQ_DPCI_TRANSLATE (1 << _HVM_IRQ_DPCI_TRANSLATE_SHIFT)#define VMSI_DEST_ID_MASK 0xff
@@ -67,6 +69,11 @@ struct hvm_gmsi_info {uint32_t gvec;uint32_t gflags; } legacy; +struct { +uint32_t source_id; +uint32_t data; +uint64_t addr; + } intremap; };int dest_vcpu_id;/* -1 :multi-dest, non-negative: dest_vcpu_id */ bool posted;/* directly deliver to guest via VT-d PI? */
Signature · 7 lines
1.8.3.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH V2 21/25] tools/libxc: Add a new interface to bind remapping format msi with pirq
Quoted 36 lines · Lan Tianyu
From: Chao Gao <[email protected]>
Introduce a new binding relationship and provide a new interface to manage the new relationship.
Signed-off-by Chao Gao <[email protected]>Signed-off-by Lan Tianyu <[email protected]>--- tools/libxc/include/xenctrl.h | 17 ++++++ tools/libxc/xc_domain.c | 53 +++++++++++++++++ xen/drivers/passthrough/io.c | 135 +++++++++++++++++++++++++++++++++++------- xen/include/public/domctl.h | 7 +++ xen/include/xen/hvm/irq.h | 7 +++ 5 files changed, 198 insertions(+), 21 deletions(-)tools/libxc/include/xenctrl.h +9
-0@@ -1720,6 +1720,15 @@ int xc_domain_ioport_mapping(xc_interface *xch,uint32_t nr_ports, uint32_t add_mapping); +int xc_domain_update_msi_irq_remapping ( +xc_interface *xch, +uint32_t domid, +uint32_t pirq, +uint32_t source_id, +uint32_t data, +uint64_t addr, +uint64_t gtable); + int xc_domain_update_msi_irq( xc_interface *xch, uint32_t domid,
tools/libxc/include/xenctrl.h int xc_domain_unbind_msi_irq(xc_interface *xch, · line 1752
Quoted 10 lines
tools/libxc/include/xenctrl.h +7
-0@@ -1734,6 +1743,14 @@ int xc_domain_unbind_msi_irq(xc_interface *xch,uint32_t pirq, uint32_t gflags); +int xc_domain_unbind_msi_irq_remapping ( +xc_interface *xch, +uint32_t domid, +uint32_t pirq, +uint32_t source_id, +uint32_t data, +uint64_t addr);
I think this doesn't match the coding style, but it seems like the surrounding functions also use it, so I will let the maintainers decide whether this is fine or not.
Quoted 12 lines
tools/libxc/include/xenctrl.h +0
-0int xc_domain_bind_pt_irq(xc_interface *xch, uint32_t domid, uint8_t machine_irq,tools/libxc/xc_domain.c +1
-0@@ -1702,8 +1702,34 @@ int xc_deassign_dt_device(return rc; } +int xc_domain_update_msi_irq_remapping(
tools/libxc/xc_domain.c int xc_deassign_dt_device( · line 1715
Quoted 10 lines
tools/libxc/xc_domain.c +10
-0+xc_interface *xch, + uint32_t domid, + uint32_t pirq, + uint32_t source_id, + uint32_t data, + uint64_t addr, + uint64_t gtable) +{ + int rc; +xen_domctl_bind_pt_irq_t *bind;
No newline.
Quoted 58 lines
tools/libxc/xc_domain.c +41
-0+DECLARE_DOMCTL ; + domctl.cmd = XEN_DOMCTL_bind_pt_irq; + domctl.domain = (domid_t )domid; + bind = &(domctl.u.bind_pt_irq); + bind->irq_type =PT_IRQ_TYPE_MSI_IR ; + bind->machine_irq = pirq; + bind->u.msi_ir.source_id = source_id; + bind->u.msi_ir.data = data; + bind->u.msi_ir.addr = addr; + bind->u.msi_ir.gtable = gtable; + + rc =do_domctl (xch, &domctl); +return rc; +} int xc_domain_update_msi_irq( xc_interface *xch,@@ -1732,6 +1758,33 @@ int xc_domain_update_msi_irq(return rc; } +int xc_domain_unbind_msi_irq_remapping ( +xc_interface *xch, +uint32_t domid, +uint32_t pirq, +uint32_t source_id, +uint32_t data, +uint64_t addr) +{ +int rc; +xen_domctl_bind_pt_irq_t *bind; + +DECLARE_DOMCTL ; + + domctl.cmd = XEN_DOMCTL_unbind_pt_irq; + domctl.domain = (domid_t )domid; + + bind = &(domctl.u.bind_pt_irq); + bind->irq_type =PT_IRQ_TYPE_MSI_IR ; + bind->machine_irq = pirq; + bind->u.msi_ir.source_id = source_id; + bind->u.msi_ir.data = data; + bind->u.msi_ir.addr = addr; + + rc =do_domctl (xch, &domctl); +return rc; +} + int xc_domain_unbind_msi_irq( xc_interface *xch, uint32_t domid,xen/drivers/passthrough/io.c +0
-0
xen/drivers/passthrough/io.c static struct vcpu *vector_hashing_dest(const struct domain *d, · line 280
Quoted 5 lines
xen/drivers/passthrough/io.c +2
-0@@ -276,6 +276,92 @@ static struct vcpu *vector_hashing_dest(const struct domain *d,return dest; } +static inline void set_hvm_gmsi_info (struct hvm_gmsi_info *msi, +xen_domctl_bind_pt_irq_t *pt_irq_bind)
Inline? I would rather let the compiler decide IMHO.
xen/drivers/passthrough/io.c static struct vcpu *vector_hashing_dest(const struct domain *d, · line 282
Quoted 2 lines
xen/drivers/passthrough/io.c +2
-0+{ +if ( pt_irq_bind->irq_type ==PT_IRQ_TYPE_MSI )
A switch seems like a better choice here.
xen/drivers/passthrough/io.c static struct vcpu *vector_hashing_dest(const struct domain *d, · line 294
Quoted 12 lines
xen/drivers/passthrough/io.c +12
-0+ { + msi->legacy.gvec = pt_irq_bind->u.msi.gvec; + msi->legacy.gflags = pt_irq_bind->u.msi.gflags; + } + else if ( pt_irq_bind->irq_type == PT_IRQ_TYPE_MSI_IR ) + { + msi->intremap.source_id = pt_irq_bind->u.msi_ir.source_id; + msi->intremap.data = pt_irq_bind->u.msi_ir.data; + msi->intremap.addr = pt_irq_bind->u.msi_ir.addr; + } + else +BUG ();
ASSERT_UNREACHABLE();
xen/drivers/passthrough/io.c static struct vcpu *vector_hashing_dest(const struct domain *d, · line 297
Quoted 3 lines
xen/drivers/passthrough/io.c +3
-0+} + +static inline void clear_hvm_gmsi_info (struct hvm_gmsi_info *msi,int irq_type)
No inline.
xen/drivers/passthrough/io.c static struct vcpu *vector_hashing_dest(const struct domain *d, · line 299
Quoted 2 lines
xen/drivers/passthrough/io.c +2
-0+{ +if ( irq_type ==PT_IRQ_TYPE_MSI )
Same here (switch + ASSERT). Maybe a memset would be faster here?
Quoted 5 lines
xen/drivers/passthrough/io.c +5
-0+ { + msi->legacy.gvec =0 ; + msi->legacy.gflags =0 ; + } + else if ( irq_type == PT_IRQ_TYPE_MSI_IR )
xen/drivers/passthrough/io.c static struct vcpu *vector_hashing_dest(const struct domain *d, · line 314
Quoted 10 lines
xen/drivers/passthrough/io.c +10
-0+ { + msi->intremap.source_id =0 ; + msi->intremap.data =0 ; + msi->intremap.addr =0 ; + } + else +BUG (); +} + +static inline bool hvm_gmsi_info_need_update(struct hvm_gmsi_info *msi,
No inline.
xen/drivers/passthrough/io.c static struct vcpu *vector_hashing_dest(const struct domain *d, · line 282
Quoted 3 lines
xen/drivers/passthrough/io.c +3
-0+ xen_domctl_bind_pt_irq_t *pt_irq_bind) +{ +if ( pt_irq_bind->irq_type ==PT_IRQ_TYPE_MSI )
switch please.
xen/drivers/passthrough/io.c static struct vcpu *vector_hashing_dest(const struct domain *d, · line 320
Quoted 3 lines
xen/drivers/passthrough/io.c +3
-0+return ((msi->legacy.gvec != pt_irq_bind->u.msi.gvec) || + (msi->legacy.gflags != pt_irq_bind->u.msi.gflags)); + else if ( pt_irq_bind->irq_type == PT_IRQ_TYPE_MSI_IR )
Unneeded else.
xen/drivers/passthrough/io.c static struct vcpu *vector_hashing_dest(const struct domain *d, · line 324
Quoted 4 lines
xen/drivers/passthrough/io.c +4
-0+return ((msi->intremap.source_id != pt_irq_bind->u.msi_ir.source_id) || + (msi->intremap.data != pt_irq_bind->u.msi_ir.data) || + (msi->intremap.addr != pt_irq_bind->u.msi_ir.addr)); +BUG ();
ASSERT_UNREACHABLE and newline.
Quoted 6 lines
xen/drivers/passthrough/io.c +6
-0+return 0 ; +} + +static int pirq_dpci_2_msi_attr (struct domain *d, +struct hvm_pirq_dpci *pirq_dpci,uint8_t *gvec, +uint8_t *dest,uint8_t *dm,uint8_t *dlm)
xen/drivers/passthrough/io.c static struct vcpu *vector_hashing_dest(const struct domain *d, · line 340
Quoted 10 lines
xen/drivers/passthrough/io.c +10
-0+{ +int rc =0 ; + +if ( pirq_dpci->flags &HVM_IRQ_DPCI_GUEST_MSI ) + { + *gvec = pirq_dpci->gmsi.legacy.gvec; + *dest = pirq_dpci->gmsi.legacy.gflags &VMSI_DEST_ID_MASK ; + *dm = !!(pirq_dpci->gmsi.legacy.gflags &VMSI_DM_MASK ); + *dlm = (pirq_dpci->gmsi.legacy.gflags &VMSI_DELIV_MASK ) >> +GFLAGS_SHIFT_DELIV_MODE ;
MASK_EXTR.
xen/drivers/passthrough/io.c static struct vcpu *vector_hashing_dest(const struct domain *d, · line 352
Quoted 12 lines
xen/drivers/passthrough/io.c +12
-0+ } +else if ( pirq_dpci->flags &HVM_IRQ_DPCI_GUEST_MSI_IR ) + { +struct irq_remapping_request request; +struct irq_remapping_info irq_info; + +irq_request_msi_fill (&request, pirq_dpci->gmsi.intremap.source_id, + pirq_dpci->gmsi.intremap.addr, + pirq_dpci->gmsi.intremap.data); +/* Currently, only viommu 0 is supported */ + rc =viommu_get_irq_info (d,0 , &request, &irq_info); +if ( !rc )
I don't like the !rc construct, I would rather have:
if ( rc )
return rc;
*gvec = ...;
But that's my personal taste, you should wait for maintainers to express their opinions.
xen/drivers/passthrough/io.c static struct vcpu *vector_hashing_dest(const struct domain *d, · line 361
Quoted 9 lines
xen/drivers/passthrough/io.c +9
-0+ { + *gvec = irq_info.vector; + *dest = irq_info.dest; + *dm = irq_info.dest_mode; + *dlm = irq_info.delivery_mode; + } + } +else +BUG ();
ASSERT_UNREACHABLE();
Quoted 7 lines
xen/drivers/passthrough/io.c +3
-0+return rc; +} +int pt_irq_create_bind (struct domain *d,xen_domctl_bind_pt_irq_t *pt_irq_bind) {
xen/drivers/passthrough/io.c int pt_irq_create_bind( · line 430
Quoted 7 lines
xen/drivers/passthrough/io.c +2
-1@@ -339,17 +425,21 @@ int pt_irq_create_bind(switch ( pt_irq_bind->irq_type ) {case PT_IRQ_TYPE_MSI : +case PT_IRQ_TYPE_MSI_IR : { -uint8_t dest, dest_mode, delivery_mode; +uint8_t dest =0 , dest_mode =0 , delivery_mode =0 , gvec;
Why do you need those initializations now? They where unneeded before and I don't see you using those variables.
Quoted 41 lines
xen/drivers/passthrough/io.c +9
-7int dest_vcpu_id;const struct vcpu *vcpu; +bool ir = (pt_irq_bind->irq_type ==PT_IRQ_TYPE_MSI_IR ); +uint64_t gtable = ir ? pt_irq_bind->u.msi_ir.gtable : + pt_irq_bind->u.msi.gtable;if ( !(pirq_dpci->flags &HVM_IRQ_DPCI_MAPPED ) ) { pirq_dpci->flags =HVM_IRQ_DPCI_MAPPED |HVM_IRQ_DPCI_MACH_MSI | -HVM_IRQ_DPCI_GUEST_MSI ; - pirq_dpci->gmsi.legacy.gvec = pt_irq_bind->u.msi.gvec; - pirq_dpci->gmsi.legacy.gflags = pt_irq_bind->u.msi.gflags; + (ir ?HVM_IRQ_DPCI_GUEST_MSI_IR : +HVM_IRQ_DPCI_GUEST_MSI ); +set_hvm_gmsi_info (&pirq_dpci->gmsi, pt_irq_bind);/* * 'pt_irq_create_bind' can be called after 'pt_irq_destroy_bind'. * The 'pirq_cleanup_check' which would free the structure is only @@ -364,9 +454,9 @@ int pt_irq_create_bind( pirq_dpci->dom = d;/* bind after hvm_irq_dpci is setup to avoid race with irq handler*/ rc =pirq_guest_bind (d->vcpu[0 ], info,0 ); -if ( rc ==0 && pt_irq_bind->u.msi.gtable ) +if ( rc ==0 && gtable ) { - rc =msixtbl_pt_register (d, info, pt_irq_bind->u.msi.gtable); + rc =msixtbl_pt_register (d, info, gtable);if (unlikely (rc) ) {pirq_guest_unbind (d, info);@@ -381,8 +471,7 @@ int pt_irq_create_bind( }if (unlikely (rc) ) { - pirq_dpci->gmsi.legacy.gflags =0 ; - pirq_dpci->gmsi.legacy.gvec =0 ; +clear_hvm_gmsi_info (&pirq_dpci->gmsi, pt_irq_bind->irq_type); pirq_dpci->dom =NULL ; pirq_dpci->flags =0 ;pirq_cleanup_check (info, d);
xen/drivers/passthrough/io.c int pt_irq_create_bind( · line 485
Quoted 6 lines
xen/drivers/passthrough/io.c +2
-1@@ -392,7 +481,8 @@ int pt_irq_create_bind( }else { -uint32_t mask =HVM_IRQ_DPCI_MACH_MSI |HVM_IRQ_DPCI_GUEST_MSI ; +uint32_t mask =HVM_IRQ_DPCI_MACH_MSI | + (ir ?HVM_IRQ_DPCI_GUEST_MSI_IR :HVM_IRQ_DPCI_GUEST_MSI );
Maybe:
uint32_t mask = (ir ? HVM_IRQ_DPCI_GUEST_MSI_IR
: HVM_IRQ_DPCI_GUEST_MSI) |
HVM_IRQ_DPCI_MACH_MSI;Quoted 22 lines
xen/drivers/passthrough/io.c +2
-6if ( (pirq_dpci->flags & mask) != mask ) {@@ -401,29 +491,31 @@ int pt_irq_create_bind( }/* If pirq is already mapped as vmsi, update guest data/addr. */ -if ( pirq_dpci->gmsi.legacy.gvec != pt_irq_bind->u.msi.gvec || - pirq_dpci->gmsi.legacy.gflags != pt_irq_bind->u.msi.gflags ) +if (hvm_gmsi_info_need_update (&pirq_dpci->gmsi, pt_irq_bind) ) {/* Directly clear pending EOIs before enabling new MSI info. */ pirq_guest_eoi (info); - pirq_dpci->gmsi.legacy.gvec = pt_irq_bind->u.msi.gvec; - pirq_dpci->gmsi.legacy.gflags = pt_irq_bind->u.msi.gflags; +set_hvm_gmsi_info (&pirq_dpci->gmsi, pt_irq_bind); } }/* Calculate dest_vcpu_id for MSI-type pirq migration. */ - dest = pirq_dpci->gmsi.legacy.gflags &VMSI_DEST_ID_MASK ; - dest_mode = !!(pirq_dpci->gmsi.legacy.gflags &VMSI_DM_MASK );
xen/drivers/passthrough/io.c int pt_irq_create_bind( · line 508
Quoted 10 lines
xen/drivers/passthrough/io.c +6
-4- delivery_mode = (pirq_dpci->gmsi.legacy.gflags &VMSI_DELIV_MASK ) >> -GFLAGS_SHIFT_DELIV_MODE ; - - dest_vcpu_id =hvm_girq_dest_2_vcpu_id (d, dest, dest_mode); + rc =pirq_dpci_2_msi_attr (d, pirq_dpci, &gvec, &dest, &dest_mode, + &delivery_mode); +if (unlikely (rc) ) + { +spin_unlock (&d->event_lock); +return -EFAULT ;
Return rc? Or else you are losing the return value for no apparent reason.
xen/drivers/passthrough/io.c int pt_irq_create_bind( · line 510
Quoted 2 lines
xen/drivers/passthrough/io.c +2
-0+ } +else
Unneeded else branch.
Quoted 13 lines
xen/drivers/passthrough/io.c +3
-1+ dest_vcpu_id =hvm_girq_dest_2_vcpu_id (d, dest, dest_mode); pirq_dpci->gmsi.dest_vcpu_id = dest_vcpu_id;spin_unlock (&d->event_lock); pirq_dpci->gmsi.posted = false; vcpu = (dest_vcpu_id >=0 ) ? d->vcpu[dest_vcpu_id] :NULL ; -if ( iommu_intpost ) +/* Currently, don't use interrupt posting for guest's remapping MSIs */ +if ( iommu_intpost && !ir ) {if ( delivery_mode == dest_LowestPrio ) vcpu = vector_hashing_dest(d, dest, dest_mode,
xen/drivers/passthrough/io.c int pt_irq_create_bind( · line 530
Quoted 5 lines
xen/drivers/passthrough/io.c +1
-1@@ -435,7 +527,7 @@ int pt_irq_create_bind(hvm_migrate_pirqs (d->vcpu[dest_vcpu_id]);/* Use interrupt posting if it is supported. */ -if ( iommu_intpost ) +if ( iommu_intpost && !ir )
So with interrupt remapping posted interrupts are not available...
Quoted 24 lines
xen/drivers/passthrough/io.c +1
-0pi_update_irte (vcpu ? &vcpu->arch.hvm_vmx.pi_desc :NULL , info, pirq_dpci->gmsi.legacy.gvec);@@ -627,6 +719,7 @@ int pt_irq_destroy_bind( }break ;case PT_IRQ_TYPE_MSI : +case PT_IRQ_TYPE_MSI_IR :break ;default :return -EOPNOTSUPP ;xen/include/public/domctl.h +1
-0@@ -555,6 +555,7 @@ typedef enum pt_irq_type_e { PT_IRQ_TYPE_MSI,PT_IRQ_TYPE_MSI_TRANSLATE ,PT_IRQ_TYPE_SPI ,/* ARM: valid range 32-1019 */ +PT_IRQ_TYPE_MSI_IR , } pt_irq_type_t;struct xen_domctl_bind_pt_irq {uint32_t machine_irq;
xen/include/public/domctl.h struct xen_domctl_bind_pt_irq { · line 582
Quoted 7 lines
xen/include/public/domctl.h +4
-0@@ -575,6 +576,12 @@ struct xen_domctl_bind_pt_irq {uint64_aligned_t gtable; } msi;struct { +uint32_t source_id; +uint32_t data; +uint64_t addr; +uint64_aligned_t gtable;
uint64_aligned_t? Please use uint64_t.
Quoted 10 lines
xen/include/public/domctl.h +2
-0+ } msi_ir; +struct {uint16_t spi; } spi; } u;xen/include/xen/hvm/irq.h +0
-0
xen/include/xen/hvm/irq.h struct dev_intx_gsi_link { · line 44
Quoted 4 lines
xen/include/xen/hvm/irq.h +1
-0@@ -41,6 +41,7 @@ struct dev_intx_gsi_link {#define _HVM_IRQ_DPCI_GUEST_PCI_SHIFT 4#define _HVM_IRQ_DPCI_GUEST_MSI_SHIFT 5#define _HVM_IRQ_DPCI_IDENTITY_GSI_SHIFT 6 +#define _HVM_IRQ_DPCI_GUEST_MSI_IR_SHIFT 7
Trailing space.
Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH V2 21/25] tools/libxc: Add a new interface to bind remapping format msi with pirq
Quoted 20 lines · Roger Pau Monné
Quoted 19 lines · Lan Tianyu
From: Chao Gao <[email protected]>
Introduce a new binding relationship and provide a new interface to manage the new relationship.
Signed-off-by Chao Gao <[email protected]>Signed-off-by Lan Tianyu <[email protected]>---
pirq_dpci->gmsi.posted = false; vcpu = (dest_vcpu_id >= 0) ? d->vcpu[dest_vcpu_id] : NULL;xen/drivers/passthrough/io.c +2
-1-if ( iommu_intpost ) +/* Currently, don't use interrupt posting for guest's remapping MSIs */ +if ( iommu_intpost && !ir ) {if ( delivery_mode == dest_LowestPrio ) vcpu = vector_hashing_dest(d, dest, dest_mode,@@ -435,7 +527,7 @@ int pt_irq_create_bind(hvm_migrate_pirqs (d->vcpu[dest_vcpu_id]);
Quoted 5 lines
xen/drivers/passthrough/io.c int pt_irq_create_bind( · line 530
Quoted 3 lines
xen/drivers/passthrough/io.c +1
-1/* Use interrupt posting if it is supported. */ -if ( iommu_intpost ) +if ( iommu_intpost && !ir )So with interrupt remapping posted interrupts are not available...
Yes. We want to make thing simple. Currently, all vIRTE isn't cached by vvtd and thus we needn't do anything when guest try to flush vIRTE. If we use posted interrupt here, it means some information will be cached by physical VTd. In that case, we should push effort to flush correspond phyiscal IRTE. We don't include these patches in this series.
Thanks
Chao
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH V2 21/25] tools/libxc: Add a new interface to bind remapping format msi with pirq
Quoted 27 lines · Chao Gao
Quoted 20 lines · Roger Pau Monné
Quoted 19 lines · Lan Tianyu
From: Chao Gao <[email protected]>
Introduce a new binding relationship and provide a new interface to manage the new relationship.
Signed-off-by Chao Gao <[email protected]>Signed-off-by Lan Tianyu <[email protected]>---
pirq_dpci->gmsi.posted = false; vcpu = (dest_vcpu_id >= 0) ? d->vcpu[dest_vcpu_id] : NULL;xen/drivers/passthrough/io.c +2
-1-if ( iommu_intpost ) +/* Currently, don't use interrupt posting for guest's remapping MSIs */ +if ( iommu_intpost && !ir ) {if ( delivery_mode == dest_LowestPrio ) vcpu = vector_hashing_dest(d, dest, dest_mode,@@ -435,7 +527,7 @@ int pt_irq_create_bind(hvm_migrate_pirqs (d->vcpu[dest_vcpu_id]);Quoted 5 lines
xen/drivers/passthrough/io.c int pt_irq_create_bind( · line 530
Quoted 3 lines
xen/drivers/passthrough/io.c +1
-1/* Use interrupt posting if it is supported. */ -if ( iommu_intpost ) +if ( iommu_intpost && !ir )So with interrupt remapping posted interrupts are not available...
Quoted 6 lines
Yes. We want to make thing simple. Currently, all vIRTE isn't cached by vvtd and thus we needn't do anything when guest try to flush vIRTE. If we use posted interrupt here, it means some information will be cached by physical VTd. In that case, we should push effort to flush correspond phyiscal IRTE. We don't include these patches in this series.
Might be worth adding a "FIXME".
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v2 22/25 x86/vmsi: Hook delivering remapping format msi to guest
In reply to Lan TianyuFrom: Chao Gao <[email protected]>
In two situations, hypervisor delivers a msi to a hvm guest. One is when qemu sends a request to hypervisor through XEN_DMOP_inject_msi. The other is when a physical interrupt arrives and it has been bound to a guest msi.
For the former, the msi is routed to common vIOMMU layer if it is in remapping format. For the latter, if the pt irq is bound to a guest remapping msi, a new remapping msi is constructed based on the binding information and routed to common vIOMMU layer.
--- xen/arch/x86/hvm/irq.c | 11 ++++++++++ xen/arch/x86/hvm/vmsi.c | 14 ++++++++++-- xen/drivers/passthrough/io.c | 51 +++++++++++++++++++++++++++++++++----------- xen/include/asm-x86/msi.h | 3 +++ 4 files changed, 65 insertions(+), 14 deletions(-)
xen/arch/x86/hvm/irq.c +11 -0
@@ -26,6 +26,7 @@#include <asm/hvm/domain.h> #include <asm/hvm/support.h> #include <asm/msi.h> +#include <asm/viommu.h> /* Must be called with hvm_domain->irq_lock hold */ static void assert_gsi (struct domain *d,unsigned ioapic_gsi)
@@ -340,6 +341,16 @@ int hvm_inject_msi(struct domain *d, uint64_t addr, uint32_t data) >> MSI_DATA_TRIGGER_SHIFT;uint8_t vector = data &MSI_DATA_VECTOR_MASK ; +if ( addr &MSI_ADDR_INTEFORMAT_MASK ) + { +struct irq_remapping_request request; + +irq_request_msi_fill (&request,0 , addr, data); +/* Currently, only viommu 0 is supported */ +viommu_handle_irq_request (d,0 , &request); +return 0 ; + } +if ( !vector ) {int pirq = ((addr >>32 ) &0xffffff00 ) | dest;
xen/arch/x86/hvm/vmsi.c +12 -2
@@ -114,9 +114,19 @@ void vmsi_deliver_pirq(struct domain *d, const struct hvm_pirq_dpci *pirq_dpci)"vector=%x trig_mode=%x\n" , dest, dest_mode, delivery_mode, vector, trig_mode); -ASSERT (pirq_dpci->flags &HVM_IRQ_DPCI_GUEST_MSI ); +ASSERT (pirq_dpci->flags & (HVM_IRQ_DPCI_GUEST_MSI |HVM_IRQ_DPCI_GUEST_MSI_IR )); +if ( pirq_dpci->flags &HVM_IRQ_DPCI_GUEST_MSI_IR ) + { +struct irq_remapping_request request; -vmsi_deliver (d, vector, dest, dest_mode, delivery_mode, trig_mode); +irq_request_msi_fill (&request, pirq_dpci->gmsi.intremap.source_id, + pirq_dpci->gmsi.intremap.addr, + pirq_dpci->gmsi.intremap.data); +/* Currently, only viommu 0 is supported */ +viommu_handle_irq_request (d,0 , &request); + } +else +vmsi_deliver (d, vector, dest, dest_mode, delivery_mode, trig_mode); }/* Return value, -1 : multi-dests, non-negative value: dest_vcpu_id */
xen/drivers/passthrough/io.c +39 -12
84 lines not on this page · raw message
xen/include/asm-x86/msi.h +3 -0
@@ -49,6 +49,9 @@#define MSI_ADDR_REDIRECTION_CPU (0 << MSI_ADDR_REDIRECTION_SHIFT)#define MSI_ADDR_REDIRECTION_LOWPRI (1 << MSI_ADDR_REDIRECTION_SHIFT) +#define MSI_ADDR_INTEFORMAT_SHIFT 4 +#define MSI_ADDR_INTEFORMAT_MASK (1 << MSI_ADDR_INTEFORMAT_SHIFT) +#define MSI_ADDR_DEST_ID_SHIFT 12#define MSI_ADDR_DEST_ID_MASK 0x00ff000#define MSI_ADDR_DEST_ID (dest) (((dest) << MSI_ADDR_DEST_ID_SHIFT) & MSI_ADDR_DEST_ID_MASK)
Signature · 7 lines
1.8.3.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH V2 22/25] x86/vmsi: Hook delivering remapping format msi to guest
Quoted 11 lines · Lan Tianyu
From: Chao Gao <[email protected]>
In two situations, hypervisor delivers a msi to a hvm guest. One is when qemu sends a request to hypervisor through
XEN_DMOP_inject_msi. The other is when a physical interrupt arrives and it has been bound to a guest msi.For the former, the msi is routed to common vIOMMU layer if it is in remapping format. For the latter, if the pt irq is bound to a guest remapping msi, a new remapping msi is constructed based on the binding information and routed to common vIOMMU layer.
After looking at the code below, I'm wondering whether it would make sense to add a new flag that's HVM_IRQ_DPCI_GUEST_REMAPPED or similar, so that you would use:
HVM_IRQ_DPCI_GUEST_MSI | HVM_IRQ_DPCI_GUEST_REMAPPED
In order to designate a remapped MSI. It seems like it would avoid some of the changes below (where you are just adding HVM_IRQ_DPCI_GUEST_MSI_IR to code paths already used by HVM_IRQ_DPCI_GUEST_MSI). More of a suggestion rather than a request for you to change the code.
Quoted 43 lines
Signed-off-by Chao Gao <[email protected]>Signed-off-by Lan Tianyu <[email protected]>--- xen/arch/x86/hvm/irq.c | 11 ++++++++++ xen/arch/x86/hvm/vmsi.c | 14 ++++++++++-- xen/drivers/passthrough/io.c | 51 +++++++++++++++++++++++++++++++++----------- xen/include/asm-x86/msi.h | 3 +++ 4 files changed, 65 insertions(+), 14 deletions(-)xen/arch/x86/hvm/irq.c +11
-0@@ -26,6 +26,7 @@#include <asm/hvm/domain.h> #include <asm/hvm/support.h> #include <asm/msi.h> +#include <asm/viommu.h> /* Must be called with hvm_domain->irq_lock hold */ static void assert_gsi (struct domain *d,unsigned ioapic_gsi)@@ -340,6 +341,16 @@ int hvm_inject_msi(struct domain *d, uint64_t addr, uint32_t data) >> MSI_DATA_TRIGGER_SHIFT;uint8_t vector = data &MSI_DATA_VECTOR_MASK ; +if ( addr &MSI_ADDR_INTEFORMAT_MASK ) + { +struct irq_remapping_request request; + +irq_request_msi_fill (&request,0 , addr, data); +/* Currently, only viommu 0 is supported */ +viommu_handle_irq_request (d,0 , &request); +return 0 ; + } +if ( !vector ) {int pirq = ((addr >>32 ) &0xffffff00 ) | dest;xen/arch/x86/hvm/vmsi.c +0
-0
xen/arch/x86/hvm/vmsi.c void vmsi_deliver_pirq(struct domain *d, const struct hvm_pirq_dpci *pirq_dpci) · line 117
Quoted 5 lines
xen/arch/x86/hvm/vmsi.c +1
-1@@ -114,9 +114,19 @@ void vmsi_deliver_pirq(struct domain *d, const struct hvm_pirq_dpci *pirq_dpci)"vector=%x trig_mode=%x\n" , dest, dest_mode, delivery_mode, vector, trig_mode); -ASSERT (pirq_dpci->flags &HVM_IRQ_DPCI_GUEST_MSI ); +ASSERT (pirq_dpci->flags & (HVM_IRQ_DPCI_GUEST_MSI |HVM_IRQ_DPCI_GUEST_MSI_IR ));
Line break.
Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH V2 22/25] x86/vmsi: Hook delivering remapping format msi to guest
Quoted 18 lines
Quoted 1 line
Quoted 1 line · On 23.08.17 at 12:55, <[email protected]> wrote:
Quoted 11 lines · Lan Tianyu
From: Chao Gao <[email protected]>
In two situations, hypervisor delivers a msi to a hvm guest. One is when qemu sends a request to hypervisor through
XEN_DMOP_inject_msi. The other is when a physical interrupt arrives and it has been bound to a guest msi.For the former, the msi is routed to common vIOMMU layer if it is in remapping format. For the latter, if the pt irq is bound to a guest remapping msi, a new remapping msi is constructed based on the binding information and routed to common vIOMMU layer.
After looking at the code below, I'm wondering whether it would make sense to add a new flag that's
HVM_IRQ_DPCI_GUEST_REMAPPEDor similar, so that you would use:
Quoted 7 lines
HVM_IRQ_DPCI_GUEST_MSI|HVM_IRQ_DPCI_GUEST_REMAPPEDIn order to designate a remapped MSI. It seems like it would avoid some of the changes below (where you are just adding
HVM_IRQ_DPCI_GUEST_MSI_IRto code paths already used byHVM_IRQ_DPCI_GUEST_MSI). More of a suggestion rather than a request for you to change the code.
I think this is a pretty good suggestion.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v2 23/25 x86/vvtd: Handle interrupt translation faults
In reply to Lan TianyuFrom: Chao Gao <[email protected]>
Interrupt translation faults are non-recoverable fault. When faults are triggered, it needs to populate fault info to Fault Recording Registers and inject vIOMMU msi interrupt to notify guest IOMMU driver to deal with faults.
This patch emulates hardware's handling interrupt translation faults (more information about the process can be found in VT-d spec, chipter "Translation Faults", section "Non-Recoverable Fault Reporting" and section "Non-Recoverable Logging"). Specifically, viommu_record_fault() records the fault information and viommu_report_non_recoverable_fault() reports faults to software. Currently, only Primary Fault Logging is supported and the Number of Fault-recording Registers is 1.
--- xen/drivers/passthrough/vtd/iommu.h | 60 +++++++-- xen/drivers/passthrough/vtd/vvtd.c | 238 +++++++++++++++++++++++++++++++++++- 2 files changed, 286 insertions(+), 12 deletions(-)
xen/drivers/passthrough/vtd/iommu.h +50 -10
@@ -226,26 +226,66 @@#define DMA_CCMD_CAIG_MASK (x) (((u64)x) & ((u64) 0x3 << 59))/* FECTL_REG */ -#define DMA_FECTL_IM (((u64)1) << 31) +#define DMA_FECTL_IM_BIT 31 +#define DMA_FECTL_IM (1U << DMA_FECTL_IM_BIT) +#define DMA_FECTL_IP_BIT 30 +#define DMA_FECTL_IP (1U << DMA_FECTL_IP_BIT)/* FSTS_REG */ -#define DMA_FSTS_PFO ((u64)1 << 0) -#define DMA_FSTS_PPF ((u64)1 << 1) -#define DMA_FSTS_AFO ((u64)1 << 2) -#define DMA_FSTS_APF ((u64)1 << 3) -#define DMA_FSTS_IQE ((u64)1 << 4) -#define DMA_FSTS_ICE ((u64)1 << 5) -#define DMA_FSTS_ITE ((u64)1 << 6) -#define DMA_FSTS_FAULTS DMA_FSTS_PFO | DMA_FSTS_PPF | DMA_FSTS_AFO | DMA_FSTS_APF | DMA_FSTS_IQE | DMA_FSTS_ICE | DMA_FSTS_ITE +#define DMA_FSTS_PFO_BIT 0 +#define DMA_FSTS_PFO (1U << DMA_FSTS_PFO_BIT) +#define DMA_FSTS_PPF_BIT 1 +#define DMA_FSTS_PPF (1U << DMA_FSTS_PPF_BIT) +#define DMA_FSTS_AFO (1U << 2) +#define DMA_FSTS_APF (1U << 3) +#define DMA_FSTS_IQE (1U << 4) +#define DMA_FSTS_ICE (1U << 5) +#define DMA_FSTS_ITE (1U << 6) +#define DMA_FSTS_PRO_BIT 7 +#define DMA_FSTS_PRO (1U << DMA_FSTS_PRO_BIT) +#define DMA_FSTS_FAULTS (DMA_FSTS_PFO | DMA_FSTS_PPF | DMA_FSTS_AFO | DMA_FSTS_APF | DMA_FSTS_IQE | DMA_FSTS_ICE | DMA_FSTS_ITE | DMA_FSTS_PRO) +#define DMA_FSTS_RW1CS (DMA_FSTS_PFO | DMA_FSTS_AFO | DMA_FSTS_APF | DMA_FSTS_IQE | DMA_FSTS_ICE | DMA_FSTS_ITE | DMA_FSTS_PRO)#define dma_fsts_fault_record_index (s) (((s) >> 8) & 0xff)/* FRCD_REG, 32 bits access */ -#define DMA_FRCD_F (((u64)1) << 31) +#define DMA_FRCD_LEN 0x10 +#define DMA_FRCD0_OFFSET 0x0 +#define DMA_FRCD1_OFFSET 0x4 +#define DMA_FRCD2_OFFSET 0x8 +#define DMA_FRCD3_OFFSET 0xc +#define DMA_FRCD3_FR_MASK 0xffUL +#define DMA_FRCD_F_BIT 31 +#define DMA_FRCD_F ((u64)1 << DMA_FRCD_F_BIT) +#define DMA_FRCD (idx, offset) (DMA_CAP_FRO_OFFSET + DMA_FRCD_LEN * idx + offset)#define dma_frcd_type (d) ((d >> 30) & 1)#define dma_frcd_fault_reason (c) (c & 0xff)#define dma_frcd_source_id (c) (c & 0xffff)#define dma_frcd_page_addr (d) (d & (((u64)-1) << 12))/* low 64 bit */ +struct vtd_fault_record_register +{ +union { +struct { +u64 lo; +u64 hi; + } bits; +struct { +u64 rsvd0 :12 , + FI :52 ;/* Fault Info */ +u64 SID :16 ,/* Source Identifier */ + rsvd1 :9 , + PRIV :1 ,/* Privilege Mode Requested */ + EXE :1 ,/* Execute Permission Requested */ + PP :1 ,/* PASID Present */ + FR :8 ,/* Fault Reason */ + PV :20 ,/* PASID Value */ + AT :2 ,/* Address Type */ + T :1 ,/* Type. (0) Write (1) Read/AtomicOp */ + F :1 ;/* Fault */ + } fields; + }; +}; +enum VTD_FAULT_TYPE {/* Interrupt remapping transition faults */
xen/drivers/passthrough/vtd/vvtd.c +236 -2
295 lines not on this page · raw message
Signature · 7 lines
1.8.3.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH V2 23/25] x86/vvtd: Handle interrupt translation faults
Quoted 3 lines · Lan Tianyu
From: Chao Gao <[email protected]>
Interrupt translation faults are non-recoverable fault. When faults
^ faults
Quoted 7 lines
are triggered, it needs to populate fault info to Fault Recording Registers and inject vIOMMU msi interrupt to notify guest IOMMU driver to deal with faults.
This patch emulates hardware's handling interrupt translation faults (more information about the process can be found in VT-d spec, chipter "Translation Faults", section "Non-Recoverable Fault
^ chapter
Quoted 18 lines
Reporting" and section "Non-Recoverable Logging"). Specifically,
viommu_record_fault()records the fault information andviommu_report_non_recoverable_fault()reports faults to software. Currently, only Primary Fault Logging is supported and the Number of Fault-recording Registers is 1.Signed-off-by Chao Gao <[email protected]>Signed-off-by Lan Tianyu <[email protected]>--- xen/drivers/passthrough/vtd/iommu.h | 60 +++++++-- xen/drivers/passthrough/vtd/vvtd.c | 238 +++++++++++++++++++++++++++++++++++- 2 files changed, 286 insertions(+), 12 deletions(-)xen/drivers/passthrough/vtd/iommu.h +0
-0
xen/drivers/passthrough/vtd/iommu.h line 229
Quoted 5 lines
xen/drivers/passthrough/vtd/iommu.h +1
-1@@ -226,26 +226,66 @@#define DMA_CCMD_CAIG_MASK (x) (((u64)x) & ((u64) 0x3 << 59))/* FECTL_REG */ -#define DMA_FECTL_IM (((u64)1) << 31) +#define DMA_FECTL_IM_BIT 31
_SHIFT (here and below).
Quoted 16 lines
xen/drivers/passthrough/vtd/iommu.h +6
-8+#define DMA_FECTL_IM (1U << DMA_FECTL_IM_BIT) +#define DMA_FECTL_IP_BIT 30 +#define DMA_FECTL_IP (1U << DMA_FECTL_IP_BIT)/* FSTS_REG */ -#define DMA_FSTS_PFO ((u64)1 << 0) -#define DMA_FSTS_PPF ((u64)1 << 1) -#define DMA_FSTS_AFO ((u64)1 << 2) -#define DMA_FSTS_APF ((u64)1 << 3) -#define DMA_FSTS_IQE ((u64)1 << 4) -#define DMA_FSTS_ICE ((u64)1 << 5) -#define DMA_FSTS_ITE ((u64)1 << 6) -#define DMA_FSTS_FAULTS DMA_FSTS_PFO | DMA_FSTS_PPF | DMA_FSTS_AFO | DMA_FSTS_APF | DMA_FSTS_IQE | DMA_FSTS_ICE | DMA_FSTS_ITE +#define DMA_FSTS_PFO_BIT 0 +#define DMA_FSTS_PFO (1U << DMA_FSTS_PFO_BIT) +#define DMA_FSTS_PPF_BIT 1
xen/drivers/passthrough/vtd/iommu.h line 247
Quoted 10 lines
xen/drivers/passthrough/vtd/iommu.h +10
-0+#define DMA_FSTS_PPF (1U << DMA_FSTS_PPF_BIT) +#define DMA_FSTS_AFO (1U << 2) +#define DMA_FSTS_APF (1U << 3) +#define DMA_FSTS_IQE (1U << 4) +#define DMA_FSTS_ICE (1U << 5) +#define DMA_FSTS_ITE (1U << 6) +#define DMA_FSTS_PRO_BIT 7 +#define DMA_FSTS_PRO (1U << DMA_FSTS_PRO_BIT) +#define DMA_FSTS_FAULTS (DMA_FSTS_PFO | DMA_FSTS_PPF | DMA_FSTS_AFO | DMA_FSTS_APF | DMA_FSTS_IQE | DMA_FSTS_ICE | DMA_FSTS_ITE | DMA_FSTS_PRO) +#define DMA_FSTS_RW1CS (DMA_FSTS_PFO | DMA_FSTS_AFO | DMA_FSTS_APF | DMA_FSTS_IQE | DMA_FSTS_ICE | DMA_FSTS_ITE | DMA_FSTS_PRO)
Please split into separate lines.
xen/drivers/passthrough/vtd/iommu.h line 252
Quoted 6 lines
xen/drivers/passthrough/vtd/iommu.h +2
-1#define dma_fsts_fault_record_index (s) (((s) >> 8) & 0xff)/* FRCD_REG, 32 bits access */ -#define DMA_FRCD_F (((u64)1) << 31) +#define DMA_FRCD_LEN 0x10 +#define DMA_FRCD0_OFFSET 0x0
0
xen/drivers/passthrough/vtd/iommu.h line 259
Quoted 7 lines
xen/drivers/passthrough/vtd/iommu.h +7
-0+#define DMA_FRCD1_OFFSET 0x4 +#define DMA_FRCD2_OFFSET 0x8 +#define DMA_FRCD3_OFFSET 0xc +#define DMA_FRCD3_FR_MASK 0xffUL +#define DMA_FRCD_F_BIT 31 +#define DMA_FRCD_F ((u64)1 << DMA_FRCD_F_BIT) +#define DMA_FRCD (idx, offset) (DMA_CAP_FRO_OFFSET + DMA_FRCD_LEN * idx + offset)
idx and offset need parentheses.
xen/drivers/passthrough/vtd/iommu.h line 269
Quoted 10 lines
xen/drivers/passthrough/vtd/iommu.h +5
-0#define dma_frcd_type (d) ((d >> 30) & 1)#define dma_frcd_fault_reason (c) (c & 0xff)#define dma_frcd_source_id (c) (c & 0xffff)#define dma_frcd_page_addr (d) (d & (((u64)-1) << 12))/* low 64 bit */ +struct vtd_fault_record_register +{ + union { + struct { + u64 lo;
uint64_t here and below.
xen/drivers/passthrough/vtd/iommu.h line 271
Quoted 2 lines
xen/drivers/passthrough/vtd/iommu.h +2
-0+u64 hi; + } bits;
s/bits/raw/? I don't have a strong opinion though.
xen/drivers/passthrough/vtd/iommu.h line 284
Quoted 13 lines
xen/drivers/passthrough/vtd/iommu.h +13
-0+struct { +u64 rsvd0 :12 , + FI :52 ;/* Fault Info */ +u64 SID :16 ,/* Source Identifier */ + rsvd1 :9 , + PRIV :1 ,/* Privilege Mode Requested */ + EXE :1 ,/* Execute Permission Requested */ + PP :1 ,/* PASID Present */ + FR :8 ,/* Fault Reason */ + PV :20 ,/* PASID Value */ + AT :2 ,/* Address Type */ + T :1 ,/* Type. (0) Write (1) Read/AtomicOp */ + F :1 ;/* Fault */
I don't think we use capital letters for struct fields. Also some of them could be more descriptive IMHO, like T -> type, F -> fault, FI -> fault_info...
Quoted 20 lines
xen/drivers/passthrough/vtd/iommu.h +4
-0+ } fields; + }; +}; +enum VTD_FAULT_TYPE {/* Interrupt remapping transition faults */ xen/drivers/passthrough/vtd/vvtd.c +1
-0@@ -19,6 +19,7 @@*/ #include <xen/domain_page.h> +#include <xen/lib.h> #include <xen/sched.h> #include <xen/types.h> #include <xen/viommu.h>
xen/drivers/passthrough/vtd/vvtd.c line 34
Quoted 4 lines
xen/drivers/passthrough/vtd/vvtd.c +1
-0@@ -30,6 +31,7 @@#include <asm/io_apic.h> #include <asm/page.h> #include <asm/p2m.h> +#include <asm/system.h>
system.h already includes xen/lib.h IIRC.
xen/drivers/passthrough/vtd/vvtd.c struct hvm_hw_vvtd_regs { · line 55
Quoted 9 lines
xen/drivers/passthrough/vtd/vvtd.c +2
-0#include "iommu.h" #include "vtd.h" @@ -49,6 +51,8 @@ struct hvm_hw_vvtd_regs {struct vvtd {/* VIOMMU_STATUS_XXX */ int status; +/* Fault Recording index */ +int frcd_idx;
fault_index?
xen/drivers/passthrough/vtd/vvtd.c static inline struct vvtd *vcpu_vvtd(struct vcpu *v) · line 105
Quoted 9 lines
xen/drivers/passthrough/vtd/vvtd.c +2
-0/* Address range of remapping hardware register-set */ uint64_t base_addr;uint64_t length;@@ -97,6 +101,23 @@ static inline struct vvtd *vcpu_vvtd(struct vcpu *v)return domain_vvtd (v->domain); } +static inline int vvtd_test_and_set_bit (struct vvtd *vvtd,uint32_t reg, +int nr)
unsigned int for nr, and I'm not really sure the usefulness of this helpers. In any case inline should not be used and instead let the compiler optimize this.
Quoted 19 lines
xen/drivers/passthrough/vtd/vvtd.c +15
-0+{ +return test_and_set_bit (nr, (uint32_t *)&vvtd->regs->data[reg]); +} + +static inline int vvtd_test_and_clear_bit (struct vvtd *vvtd,uint32_t reg, +int nr) +{ +return test_and_clear_bit (nr, (uint32_t *)&vvtd->regs->data[reg]); +} + +static inline int vvtd_test_bit (struct vvtd *vvtd,uint32_t reg,int nr) +{ +return test_bit (nr, (uint32_t *)&vvtd->regs->data[reg]); +} +static inline void __vvtd_set_bit (struct vvtd *vvtd,uint32_t reg,int nr) {return __set_bit (nr, (uint32_t *)&vvtd->regs->data[reg]);
xen/drivers/passthrough/vtd/vvtd.c static int vvtd_delivery( · line 256
Quoted 4 lines
xen/drivers/passthrough/vtd/vvtd.c +1
-0@@ -232,6 +253,24 @@ static int vvtd_delivery(return 0 ; } +void vvtd_generate_interrupt(struct vvtd *vvtd,
const.
xen/drivers/passthrough/vtd/vvtd.c static int vvtd_delivery( · line 265
Quoted 9 lines
xen/drivers/passthrough/vtd/vvtd.c +9
-0+uint32_t addr, + uint32_t data) +{ + uint8_t dest, dm, dlm, tm, vector; + +VVTD_DEBUG (VVTD_DBG_FAULT ,"Sending interrupt %x %x to d%d" , + addr, data, vvtd->domain->domain_id); + + dest = (addr &MSI_ADDR_DEST_ID_MASK ) >>MSI_ADDR_DEST_ID_SHIFT ;
MASK_EXTR (here and below).
Quoted 12 lines
xen/drivers/passthrough/vtd/vvtd.c +8
-0+ dm = !!(addr &MSI_ADDR_DESTMODE_MASK ); + dlm = (data &MSI_DATA_DELIVERY_MODE_MASK ) >>MSI_DATA_DELIVERY_MODE_SHIFT ; + tm = (data &MSI_DATA_TRIGGER_MASK ) >>MSI_DATA_TRIGGER_SHIFT ; + vector = data &MSI_DATA_VECTOR_MASK ; + +vvtd_delivery (vvtd->domain, vector, dest, dm, dlm, tm); +} +static uint32_t irq_remapping_request_index (struct irq_remapping_request *irq) {if ( irq->type ==VIOMMU_REQUEST_IRQ_MSI )
xen/drivers/passthrough/vtd/vvtd.c static inline uint32_t irte_dest(struct vvtd *vvtd, uint32_t dest) · line 308
Quoted 10 lines
xen/drivers/passthrough/vtd/vvtd.c +7
-0@@ -260,11 +299,189 @@ static inline uint32_t irte_dest(struct vvtd *vvtd, uint32_t dest)return DMA_IRTA_EIME (irta) ? dest :MASK_EXTR (dest, IRTE_xAPIC_DEST_MASK); } +static void vvtd_report_non_recoverable_fault (struct vvtd *vvtd,int reason) +{ +uint32_t fsts; + +ASSERT (reason &DMA_FSTS_FAULTS ); + fsts =vvtd_get_reg (vvtd,DMAR_FSTS_REG ); +__vvtd_set_bit (vvtd,DMAR_FSTS_REG , reason);
I don't understand this, is reason a bit position or a mask?
DMA_FSTS_FAULTS seems to be a mask, that should be set into DMAR_FSTS_REG?
xen/drivers/passthrough/vtd/vvtd.c static inline uint32_t irte_dest(struct vvtd *vvtd, uint32_t dest) · line 321
Quoted 13 lines
xen/drivers/passthrough/vtd/vvtd.c +13
-0+ +/* +* Accoroding to VT-d spec "Non-Recoverable Fault Event" chapter, if +* there are any previously reported interrupt conditions that are yet to +* be sevices by software, the Fault Event interrrupt is not generated. +*/ +if ( fsts &DMA_FSTS_FAULTS ) +return ; + +__vvtd_set_bit (vvtd,DMAR_FECTL_REG ,DMA_FECTL_IP_BIT ); +if ( !vvtd_test_bit (vvtd,DMAR_FECTL_REG ,DMA_FECTL_IM_BIT ) ) + { +uint32_t fe_data, fe_addr;
Newline.
xen/drivers/passthrough/vtd/vvtd.c static inline uint32_t irte_dest(struct vvtd *vvtd, uint32_t dest) · line 329
Quoted 8 lines
xen/drivers/passthrough/vtd/vvtd.c +8
-0+ fe_data =vvtd_get_reg (vvtd,DMAR_FEDATA_REG ); + fe_addr =vvtd_get_reg (vvtd,DMAR_FEADDR_REG ); +vvtd_generate_interrupt (vvtd, fe_addr, fe_data); +__vvtd_clear_bit (vvtd,DMAR_FECTL_REG ,DMA_FECTL_IP_BIT ); + } +} + +static void vvtd_recomputing_ppf (struct vvtd *vvtd)
recompute, or maybe better update?
xen/drivers/passthrough/vtd/vvtd.c static inline uint32_t irte_dest(struct vvtd *vvtd, uint32_t dest) · line 331
Quoted 2 lines
xen/drivers/passthrough/vtd/vvtd.c +2
-0+{ +int i;
unsigned int.
Quoted 13 lines
xen/drivers/passthrough/vtd/vvtd.c +13
-0+ +for ( i =0 ; i <DMA_FRCD_REG_NR ; i++ ) + { +if (vvtd_test_bit (vvtd,DMA_FRCD (i,DMA_FRCD3_OFFSET ), +DMA_FRCD_F_BIT ) ) + { +vvtd_report_non_recoverable_fault (vvtd,DMA_FSTS_PPF_BIT ); +return ; + } + } +/* +* No Primary Fault is in Fault Record Registers, thus clear PPF bit in +* FSTS.
xen/drivers/passthrough/vtd/vvtd.c static inline uint32_t irte_dest(struct vvtd *vvtd, uint32_t dest) · line 354
Quoted 10 lines
xen/drivers/passthrough/vtd/vvtd.c +10
-0+*/ +__vvtd_clear_bit (vvtd,DMAR_FSTS_REG ,DMA_FSTS_PPF_BIT ); + +/* If no fault is in FSTS, clear pending bit in FECTL. */ +if ( !(vvtd_get_reg (vvtd,DMAR_FSTS_REG ) &DMA_FSTS_FAULTS ) ) +__vvtd_clear_bit (vvtd,DMAR_FECTL_REG ,DMA_FECTL_IP_BIT ); +} + +/* +* Commit a frcd to emulated Fault Record Registers.
frcd is not really helpful here, you should expand this into something that's readable.
Quoted 10 lines
xen/drivers/passthrough/vtd/vvtd.c +10
-0+*/ +static void vvtd_commit_frcd (struct vvtd *vvtd,int idx, +struct vtd_fault_record_register *frcd) +{ +vvtd_set_reg_quad (vvtd,DMA_FRCD (idx,DMA_FRCD0_OFFSET ), frcd->bits.lo); +vvtd_set_reg_quad (vvtd,DMA_FRCD (idx,DMA_FRCD2_OFFSET ), frcd->bits.hi); +vvtd_recomputing_ppf (vvtd); +} + +/*
xen/drivers/passthrough/vtd/vvtd.c static inline uint32_t irte_dest(struct vvtd *vvtd, uint32_t dest) · line 374
Quoted 10 lines
xen/drivers/passthrough/vtd/vvtd.c +10
-0+* Allocate a FRCD for the caller. If success, return the FRI. Or, return -1 +* when failure. +*/ +static int vvtd_alloc_frcd (struct vvtd *vvtd) +{ +int prev; + +/* Set the F bit to indicate the FRCD is in use. */ +if (vvtd_test_and_set_bit (vvtd,DMA_FRCD (vvtd->frcd_idx,DMA_FRCD3_OFFSET ), +DMA_FRCD_F_BIT ) )
Shouldn't this be !vvtd_test_and_set_bit?
xen/drivers/passthrough/vtd/vvtd.c static inline uint32_t irte_dest(struct vvtd *vvtd, uint32_t dest) · line 380
Quoted 6 lines
xen/drivers/passthrough/vtd/vvtd.c +6
-0+ { + prev = vvtd->frcd_idx; + vvtd->frcd_idx = (prev +1 ) %DMA_FRCD_REG_NR ; +return vvtd->frcd_idx; + } +return -1 ;
-ENOMEM?
AFAICT this happens when you cannot find a free register?
Quoted 34 lines
xen/drivers/passthrough/vtd/vvtd.c +30
-1+} + +static void vvtd_free_frcd (struct vvtd *vvtd,int i) +{ +__vvtd_clear_bit (vvtd,DMA_FRCD (i,DMA_FRCD3_OFFSET ),DMA_FRCD_F_BIT ); +} +static int vvtd_record_fault (struct vvtd *vvtd, -struct irq_remapping_request *irq, +struct irq_remapping_request *request,int reason) {Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
xen/drivers/passthrough/vtd/vvtd.c static inline uint32_t irte_dest(struct vvtd *vvtd, uint32_t dest) · line 400
Quoted 10 lines
xen/drivers/passthrough/vtd/vvtd.c +9
-1-return 0 ; +struct vtd_fault_record_register frcd; +int frcd_idx; + +switch (reason) + { +case VTD_FR_IR_REQ_RSVD : +case VTD_FR_IR_INDEX_OVER : +case VTD_FR_IR_ENTRY_P : +case VTD_FR_IR_ROOT_INVAL :
63 lines not shown · raw message
Parts of this message are not shown here. View the raw message.
Re: [PATCH V2 23/25] x86/vvtd: Handle interrupt translation faults
Quoted 30 lines · Roger Pau Monné
Quoted 3 lines · Lan Tianyu
From: Chao Gao <[email protected]>
Interrupt translation faults are non-recoverable fault. When faults
^ faults
Quoted 7 lines
are triggered, it needs to populate fault info to Fault Recording Registers and inject vIOMMU msi interrupt to notify guest IOMMU driver to deal with faults.
This patch emulates hardware's handling interrupt translation faults (more information about the process can be found in VT-d spec, chipter "Translation Faults", section "Non-Recoverable Fault
^ chapter
Quoted 17 lines
Reporting" and section "Non-Recoverable Logging"). Specifically,
viommu_record_fault()records the fault information andviommu_report_non_recoverable_fault()reports faults to software. Currently, only Primary Fault Logging is supported and the Number of Fault-recording Registers is 1.Signed-off-by Chao Gao <[email protected]>Signed-off-by Lan Tianyu <[email protected]>---
/* Address range of remapping hardware register-set */ uint64_t base_addr; uint64_t length;xen/drivers/passthrough/vtd/vvtd.c +0
-0@@ -97,6 +101,23 @@ static inline struct vvtd *vcpu_vvtd(struct vcpu *v)return domain_vvtd (v->domain); }
Quoted 7 lines
Review static inline struct vvtd *vcpu_vvtd(struct vcpu *v) · line 105
Quoted 2 lines
(quoted diff) +2
-0+static inline int vvtd_test_and_set_bit(struct vvtd *vvtd, uint32_t reg, + int nr)unsigned int for nr, and I'm not really sure the usefulness of this helpers. In any case inline should not be used and instead let the compiler optimize this.
I think compiler doesn't know the frequency of calling these function. Explicitly make this function inline sometimes can avoid compiler doesn't do this for some short and frequently used functions.
Quoted 11 lines
xen/drivers/passthrough/vtd/vvtd.c static inline uint32_t irte_dest(struct vvtd *vvtd, uint32_t dest) · line 308
Quoted 7 lines
xen/drivers/passthrough/vtd/vvtd.c +7
-0+static void vvtd_report_non_recoverable_fault (struct vvtd *vvtd,int reason) +{ +uint32_t fsts; + +ASSERT (reason &DMA_FSTS_FAULTS ); + fsts =vvtd_get_reg (vvtd,DMAR_FSTS_REG ); +__vvtd_set_bit (vvtd,DMAR_FSTS_REG , reason);I don't understand this, is reason a bit position or a mask?
DMA_FSTS_FAULTSseems to be a mask, that should be set intoDMAR_FSTS_REG?
According VT-d spec 10.4.9, Each kind of fault is denoted by one bit in DMAR_FSTS_REG.
Quoted 32 lines
Quoted 32 lines
xen/drivers/passthrough/vtd/vvtd.c +27
-2static int vvtd_record_fault (struct vvtd *vvtd, -struct irq_remapping_request *irq, +struct irq_remapping_request *request,int reason) { -return 0 ; +struct vtd_fault_record_register frcd; +int frcd_idx; + +switch (reason) + { +case VTD_FR_IR_REQ_RSVD : +case VTD_FR_IR_INDEX_OVER : +case VTD_FR_IR_ENTRY_P : +case VTD_FR_IR_ROOT_INVAL : +case VTD_FR_IR_IRTE_RSVD : +case VTD_FR_IR_REQ_COMPAT : +case VTD_FR_IR_SID_ERR : +if (vvtd_test_bit (vvtd,DMAR_FSTS_REG ,DMA_FSTS_PFO_BIT ) ) +return X86EMUL_OKAY ; + +/* No available Fault Record means Fault overflowed */ + frcd_idx =vvtd_alloc_frcd (vvtd); +if ( frcd_idx ==-1 ) + { +vvtd_report_non_recoverable_fault (vvtd,DMA_FSTS_PFO_BIT ); +return X86EMUL_OKAY ; + } +memset (&frcd,0 ,sizeof (frcd)); + frcd.fields.FR = (u8 )reason; + frcd.fields.FI = ((u64 )irq_remapping_request_index (request)) <<36 ; + frcd.fields.SID = (u16 )request->source_id;
Quoted 8 lines
xen/drivers/passthrough/vtd/vvtd.c static inline uint32_t irte_dest(struct vvtd *vvtd, uint32_t dest) · line 422
Quoted 5 lines
xen/drivers/passthrough/vtd/vvtd.c +5
-0+ frcd.fields.F =1 ; +vvtd_commit_frcd (vvtd, frcd_idx, &frcd); +return X86EMUL_OKAY ; + +default :Other reasons are just ignored? Should this have an
ASSERT_UNREACHABLEmaybe?
It can have for all the faults are raised by vvtd. When vvtd generates a new kinds of fault, the corresponding handler also should be added.
Quoted 10 lines
xen/drivers/passthrough/vtd/vvtd.c static inline uint32_t irte_dest(struct vvtd *vvtd, uint32_t dest) · line 427
Quoted 6 lines
xen/drivers/passthrough/vtd/vvtd.c +5
-0+break ; + } + +gdprintk (XENLOG_ERR ,"Can't handle vVTD Fault (reason 0x%x)." , reason); +domain_crash (vvtd->domain);Oh, I see. Is it expected that such faults with unhandled reasons can be somehow generated by the domain itself?
No. Faults are generated by vvtd. We only add interrupt translation faults. Other faults can be added when adding other features (e.g. DMA remapping).
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH V2 23/25] x86/vvtd: Handle interrupt translation faults
Quoted 39 lines · Chao Gao
Quoted 30 lines · Roger Pau Monné
Quoted 3 lines · Lan Tianyu
From: Chao Gao <[email protected]>
Interrupt translation faults are non-recoverable fault. When faults
^ faults
Quoted 7 lines
are triggered, it needs to populate fault info to Fault Recording Registers and inject vIOMMU msi interrupt to notify guest IOMMU driver to deal with faults.
This patch emulates hardware's handling interrupt translation faults (more information about the process can be found in VT-d spec, chipter "Translation Faults", section "Non-Recoverable Fault
^ chapter
Quoted 17 lines
Reporting" and section "Non-Recoverable Logging"). Specifically,
viommu_record_fault()records the fault information andviommu_report_non_recoverable_fault()reports faults to software. Currently, only Primary Fault Logging is supported and the Number of Fault-recording Registers is 1.Signed-off-by Chao Gao <[email protected]>Signed-off-by Lan Tianyu <[email protected]>---
/* Address range of remapping hardware register-set */ uint64_t base_addr; uint64_t length;xen/drivers/passthrough/vtd/vvtd.c +0
-0@@ -97,6 +101,23 @@ static inline struct vvtd *vcpu_vvtd(struct vcpu *v)return domain_vvtd (v->domain); }Quoted 7 lines
Review static inline struct vvtd *vcpu_vvtd(struct vcpu *v) · line 105
Quoted 2 lines
(quoted diff) +2
-0+static inline int vvtd_test_and_set_bit(struct vvtd *vvtd, uint32_t reg, + int nr)unsigned int for nr, and I'm not really sure the usefulness of this helpers. In any case inline should not be used and instead let the compiler optimize this.
Quoted 3 lines
I think compiler doesn't know the frequency of calling these function. Explicitly make this function inline sometimes can avoid compiler doesn't do this for some short and frequently used functions.
I will leave that to the maintainers. IMHO I wouldn't add inline unless I see some figures that back up the supposed speed increase.
Quoted 10 lines
Quoted 10 lines
xen/drivers/passthrough/vtd/vvtd.c static inline uint32_t irte_dest(struct vvtd *vvtd, uint32_t dest) · line 308
Quoted 7 lines
xen/drivers/passthrough/vtd/vvtd.c +7
-0+static void vvtd_report_non_recoverable_fault (struct vvtd *vvtd,int reason) +{ +uint32_t fsts; + +ASSERT (reason &DMA_FSTS_FAULTS ); + fsts =vvtd_get_reg (vvtd,DMAR_FSTS_REG ); +__vvtd_set_bit (vvtd,DMAR_FSTS_REG , reason);I don't understand this, is reason a bit position or a mask?
Quoted 4 lines
Quoted 1 line
DMA_FSTS_FAULTSseems to be a mask, that should be set intoDMAR_FSTS_REG?According VT-d spec 10.4.9, Each kind of fault is denoted by one bit in
DMAR_FSTS_REG.
So 'reason' is a bit position in this context? It needs to be unsigned int then.
Quoted 41 lines
Quoted 32 lines
Quoted 32 lines
xen/drivers/passthrough/vtd/vvtd.c +27
-2static int vvtd_record_fault (struct vvtd *vvtd, -struct irq_remapping_request *irq, +struct irq_remapping_request *request,int reason) { -return 0 ; +struct vtd_fault_record_register frcd; +int frcd_idx; + +switch (reason) + { +case VTD_FR_IR_REQ_RSVD : +case VTD_FR_IR_INDEX_OVER : +case VTD_FR_IR_ENTRY_P : +case VTD_FR_IR_ROOT_INVAL : +case VTD_FR_IR_IRTE_RSVD : +case VTD_FR_IR_REQ_COMPAT : +case VTD_FR_IR_SID_ERR : +if (vvtd_test_bit (vvtd,DMAR_FSTS_REG ,DMA_FSTS_PFO_BIT ) ) +return X86EMUL_OKAY ; + +/* No available Fault Record means Fault overflowed */ + frcd_idx =vvtd_alloc_frcd (vvtd); +if ( frcd_idx ==-1 ) + { +vvtd_report_non_recoverable_fault (vvtd,DMA_FSTS_PFO_BIT ); +return X86EMUL_OKAY ; + } +memset (&frcd,0 ,sizeof (frcd)); + frcd.fields.FR = (u8 )reason; + frcd.fields.FI = ((u64 )irq_remapping_request_index (request)) <<36 ; + frcd.fields.SID = (u16 )request->source_id;Quoted 8 lines
xen/drivers/passthrough/vtd/vvtd.c static inline uint32_t irte_dest(struct vvtd *vvtd, uint32_t dest) · line 422
Quoted 5 lines
xen/drivers/passthrough/vtd/vvtd.c +5
-0+ frcd.fields.F =1 ; +vvtd_commit_frcd (vvtd, frcd_idx, &frcd); +return X86EMUL_OKAY ; + +default :Other reasons are just ignored? Should this have an
ASSERT_UNREACHABLEmaybe?
Quoted 2 lines
It can have for all the faults are raised by vvtd. When vvtd generates a new kinds of fault, the corresponding handler also should be added.
Do you mean that with the code above all the possible fault types are covered?
In which case it seems you want to add a ASSERT_UNREACHABLE to the default case.
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
xen/drivers/passthrough/vtd/vvtd.c +5
-0+break ; + } + +gdprintk (XENLOG_ERR ,"Can't handle vVTD Fault (reason 0x%x)." , reason); +domain_crash (vvtd->domain);
Quoted 7 lines
Quoted 3 lines
Oh, I see. Is it expected that such faults with unhandled reasons can be somehow generated by the domain itself?
No. Faults are generated by vvtd. We only add interrupt translation faults. Other faults can be added when adding other features (e.g. DMA remapping).
OK, so then it looks like you want an ASSERT above, and I'm not sure whether you want to kill the domain. At the end if Xen ever gets here it means there's a bug in the vvtd implementation. I think the proper solution is to add the ASSERT above and simply return X86EMUL_OKAY here.
Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v2 24/25 x86/vvtd: Add queued invalidation (QI) support
In reply to Lan TianyuFrom: Chao Gao <[email protected]>
Queued Invalidation Interface is an expanded invalidation interface with extended capabilities. Hardware implementations report support for queued invalidation interface through the Extended Capability Register. The queued invalidation interface uses an Invalidation Queue (IQ), which is a circular buffer in system memory. Software submits commands by writing Invalidation Descriptors to the IQ.
In this patch, a new function viommu_process_iq() is used for emulating how hardware handles invalidation requests through QI.
--- xen/drivers/passthrough/vtd/iommu.h | 29 ++++- xen/drivers/passthrough/vtd/vvtd.c | 244 ++++++++++++++++++++++++++++++++++++ 2 files changed, 272 insertions(+), 1 deletion(-)
xen/drivers/passthrough/vtd/iommu.h +28 -1
@@ -204,6 +204,32 @@#define DMA_IRTA_S (val) (val & 0xf)#define DMA_IRTA_SIZE (val) (1UL << (DMA_IRTA_S(val) + 1)) +/* IQH_REG */ +#define DMA_IQH_QH_SHIFT 4 +#define DMA_IQH_QH (val) ((val >> 4) & 0x7fffULL) + +/* IQT_REG */ +#define DMA_IQT_QT_SHIFT 4 +#define DMA_IQT_QT (val) ((val >> 4) & 0x7fffULL) +#define DMA_IQT_RSVD 0xfffffffffff80007ULL + +/* IQA_REG */ +#define DMA_MGAW 39/* Maximum Guest Address Width */ +#define DMA_IQA_ADDR (val) (val & ~0xfffULL) +#define DMA_IQA_QS (val) (val & 0x7) +#define DMA_IQA_ENTRY_PER_PAGE (1 << 8) +#define DMA_IQA_RSVD (~((1ULL << DMA_MGAW) -1 ) | 0xff8ULL) + +/* IECTL_REG */ +#define DMA_IECTL_IM_BIT 31 +#define DMA_IECTL_IM (1 << DMA_IECTL_IM_BIT) +#define DMA_IECTL_IP_BIT 30 +#define DMA_IECTL_IP (((u64)1) << DMA_IECTL_IP_BIT) + +/* ICS_REG */ +#define DMA_ICS_IWC_BIT 0 +#define DMA_ICS_IWC (1 << DMA_ICS_IWC_BIT) +/* PMEN_REG */ #define DMA_PMEN_EPM (((u32)1) << 31)#define DMA_PMEN_PRS (((u32)1) << 0)
@@ -238,7 +264,8 @@#define DMA_FSTS_PPF (1U << DMA_FSTS_PPF_BIT)#define DMA_FSTS_AFO (1U << 2)#define DMA_FSTS_APF (1U << 3) -#define DMA_FSTS_IQE (1U << 4) +#define DMA_FSTS_IQE_BIT 4 +#define DMA_FSTS_IQE (1U << DMA_FSTS_IQE_BIT)#define DMA_FSTS_ICE (1U << 5)#define DMA_FSTS_ITE (1U << 6)#define DMA_FSTS_PRO_BIT 7
xen/drivers/passthrough/vtd/vvtd.c +244 -0
274 lines not on this page · raw message
Signature · 7 lines
1.8.3.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH V2 24/25] x86/vvtd: Add queued invalidation (QI) support
Quoted 11 lines · Lan Tianyu
From: Chao Gao <[email protected]>
Queued Invalidation Interface is an expanded invalidation interface with extended capabilities. Hardware implementations report support for queued invalidation interface through the Extended Capability Register. The queued invalidation interface uses an Invalidation Queue (IQ), which is a circular buffer in system memory. Software submits commands by writing Invalidation Descriptors to the IQ.
In this patch, a new function
viommu_process_iq()is used for emulating how hardware handles invalidation requests through QI.
It seems like this is an extended feature, which is not needed for basic functionality. Would it be possible to have this series focus on the bare-minimum functionality, leaving everything else to a separate series?
Quoted 12 lines
Signed-off-by Chao Gao <[email protected]>Signed-off-by Lan Tianyu <[email protected]>--- xen/drivers/passthrough/vtd/iommu.h | 29 ++++- xen/drivers/passthrough/vtd/vvtd.c | 244 ++++++++++++++++++++++++++++++++++++ 2 files changed, 272 insertions(+), 1 deletion(-)xen/drivers/passthrough/vtd/iommu.h +0
-0
xen/drivers/passthrough/vtd/iommu.h line 209
Quoted 6 lines
xen/drivers/passthrough/vtd/iommu.h +3
-0@@ -204,6 +204,32 @@#define DMA_IRTA_S (val) (val & 0xf)#define DMA_IRTA_SIZE (val) (1UL << (DMA_IRTA_S(val) + 1)) +/* IQH_REG */ +#define DMA_IQH_QH_SHIFT 4 +#define DMA_IQH_QH (val) ((val >> 4) & 0x7fffULL)
Missing parentheses around val (here and below).
xen/drivers/passthrough/vtd/iommu.h line 214
Quoted 5 lines
xen/drivers/passthrough/vtd/iommu.h +5
-0+ +/* IQT_REG */ +#define DMA_IQT_QT_SHIFT 4 +#define DMA_IQT_QT (val) ((val >> 4) & 0x7fffULL) +#define DMA_IQT_RSVD 0xfffffffffff80007ULL
~0x7fffULL?
xen/drivers/passthrough/vtd/iommu.h line 217
Quoted 2 lines
xen/drivers/passthrough/vtd/iommu.h +2
-0+/* IQA_REG */ +#define DMA_MGAW 39/* Maximum Guest Address Width */
I've got the feeling this is also in the CPUID info, in which case shouldn't this match what's reported there?
Or is it expected to have the IOMMU report support for address width different than the processor?
xen/drivers/passthrough/vtd/iommu.h line 221
Quoted 4 lines
xen/drivers/passthrough/vtd/iommu.h +4
-0+#define DMA_IQA_ADDR (val) (val & ~0xfffULL) +#define DMA_IQA_QS (val) (val & 0x7) +#define DMA_IQA_ENTRY_PER_PAGE (1 << 8) +#define DMA_IQA_RSVD (~((1ULL << DMA_MGAW) -1 ) | 0xff8ULL)
There seems to be a fair amount of magic constants here, shouldn't those be added as defines?
xen/drivers/passthrough/vtd/iommu.h line 224
Quoted 3 lines
xen/drivers/passthrough/vtd/iommu.h +3
-0+ +/* IECTL_REG */ +#define DMA_IECTL_IM_BIT 31
_SHIFT.
Quoted 41 lines
xen/drivers/passthrough/vtd/iommu.h +10
-1+#define DMA_IECTL_IM (1 << DMA_IECTL_IM_BIT) +#define DMA_IECTL_IP_BIT 30 +#define DMA_IECTL_IP (((u64)1) << DMA_IECTL_IP_BIT) + +/* ICS_REG */ +#define DMA_ICS_IWC_BIT 0 +#define DMA_ICS_IWC (1 << DMA_ICS_IWC_BIT) +/* PMEN_REG */ #define DMA_PMEN_EPM (((u32)1) << 31)#define DMA_PMEN_PRS (((u32)1) << 0)@@ -238,7 +264,8 @@#define DMA_FSTS_PPF (1U << DMA_FSTS_PPF_BIT)#define DMA_FSTS_AFO (1U << 2)#define DMA_FSTS_APF (1U << 3) -#define DMA_FSTS_IQE (1U << 4) +#define DMA_FSTS_IQE_BIT 4 +#define DMA_FSTS_IQE (1U << DMA_FSTS_IQE_BIT)#define DMA_FSTS_ICE (1U << 5)#define DMA_FSTS_ITE (1U << 6)#define DMA_FSTS_PRO_BIT 7xen/drivers/passthrough/vtd/vvtd.c +12
-0@@ -428,6 +428,185 @@ static int vvtd_record_fault(struct vvtd *vvtd,return X86EMUL_OKAY ; } +/* +* Process a invalidation descriptor. Currently, only two types descriptors, +* Interrupt Entry Cache Invalidation Descritor and Invalidation Wait +* Descriptor are handled. +* @vvtd: the virtual vtd instance +* @i: the index of the invalidation descriptor to be processed +* +* If success return 0, or return -1 when failure. +*/ +static int process_iqe (struct vvtd *vvtd,int i) +{ +uint64_t iqa, addr;
xen/drivers/passthrough/vtd/vvtd.c static int vvtd_record_fault(struct vvtd *vvtd, · line 452
Quoted 10 lines
xen/drivers/passthrough/vtd/vvtd.c +10
-0+struct qinval_entry *qinval_page; +void *pg; +int ret; + +vvtd_get_reg_quad (vvtd,DMAR_IQA_REG , iqa); + ret =map_guest_page (vvtd->domain,DMA_IQA_ADDR (iqa)>>PAGE_SHIFT , + (void **)&qinval_page); +if ( ret ) + { +gdprintk (XENLOG_ERR ,"Can't map guest IRT (rc %d)" , ret);
VVTD_DEBUG?
xen/drivers/passthrough/vtd/vvtd.c static int vvtd_record_fault(struct vvtd *vvtd, · line 453
Quoted 1 line
xen/drivers/passthrough/vtd/vvtd.c +1
-0+return -1 ;
return ret;
Quoted 6 lines
xen/drivers/passthrough/vtd/vvtd.c +6
-0+ } + +switch ( qinval_page[i].q.inv_wait_dsc.lo.type ) + { +case TYPE_INVAL_WAIT : +if ( qinval_page[i].q.inv_wait_dsc.lo.sw )
xen/drivers/passthrough/vtd/vvtd.c static int vvtd_record_fault(struct vvtd *vvtd, · line 469
Quoted 10 lines
xen/drivers/passthrough/vtd/vvtd.c +10
-0+ { + addr = (qinval_page[i].q.inv_wait_dsc.hi.saddr <<2 ); + ret =map_guest_page (vvtd->domain, addr >>PAGE_SHIFT , &pg); +if ( ret ) + { +gdprintk (XENLOG_ERR ,"Can't map guest memory to inform guest " +"IWC completion (rc %d)" , ret); + goto error; + } + *(uint32_t *)((uint64_t)pg + (addr & ~PAGE_MASK)) =
^ no need to cast AFAICT
xen/drivers/passthrough/vtd/vvtd.c static int vvtd_record_fault(struct vvtd *vvtd, · line 471
Quoted 2 lines
xen/drivers/passthrough/vtd/vvtd.c +2
-0+ qinval_page[i].q.inv_wait_dsc.lo.sdata; +unmap_guest_page (pg);
Since this is kind of a sporadic usage, maybe you could use hvm_copy_to_guest_phys?
Quoted 32 lines
xen/drivers/passthrough/vtd/vvtd.c +32
-0+ } + +/* +* The following code generates an invalidation completion event +* indicating the invalidation wait descriptor completion. Note that +* the following code fragment is not tested properly. +*/ +if ( qinval_page[i].q.inv_wait_dsc.lo.iflag ) + { +uint32_t ie_data, ie_addr; +if ( !vvtd_test_and_set_bit (vvtd,DMAR_ICS_REG ,DMA_ICS_IWC_BIT ) ) + { +__vvtd_set_bit (vvtd,DMAR_IECTL_REG ,DMA_IECTL_IP_BIT ); +if ( !vvtd_test_bit (vvtd,DMAR_IECTL_REG ,DMA_IECTL_IM_BIT ) ) + { + ie_data =vvtd_get_reg (vvtd,DMAR_IEDATA_REG ); + ie_addr =vvtd_get_reg (vvtd,DMAR_IEADDR_REG ); +vvtd_generate_interrupt (vvtd, ie_addr, ie_data); +__vvtd_clear_bit (vvtd,DMAR_IECTL_REG ,DMA_IECTL_IP_BIT ); + } + } + } +break ; + +case TYPE_INVAL_IEC : +/* +* Currently, no cache is preserved in hypervisor. Only need to update +* pIRTEs which are modified in binding process. +*/ +break ; + +default :
xen/drivers/passthrough/vtd/vvtd.c static int vvtd_record_fault(struct vvtd *vvtd, · line 513
Quoted 10 lines
xen/drivers/passthrough/vtd/vvtd.c +10
-0+ goto error; + } + +unmap_guest_page ((void *)qinval_page); +return 0 ; + + error: +unmap_guest_page ((void *)qinval_page); +gdprintk (XENLOG_ERR ,"Internal error in Queue Invalidation.\n" ); +domain_crash (vvtd->domain);
Is it really needed to crash the guest?
xen/drivers/passthrough/vtd/vvtd.c static int vvtd_record_fault(struct vvtd *vvtd, · line 514
Quoted 1 line
xen/drivers/passthrough/vtd/vvtd.c +1
-0+return -1 ;
return ret;
Quoted 16 lines
xen/drivers/passthrough/vtd/vvtd.c +16
-0+} + +/* +* Invalidate all the descriptors in Invalidation Queue. +*/ +static void vvtd_process_iq (struct vvtd *vvtd) +{ +uint64_t iqh, iqt, iqa, max_entry, i; +int ret =0 ; + +/* +* No new descriptor is fetched from the Invalidation Queue until +* software clears the IQE field in the Fault Status Register +*/ +if (vvtd_test_bit (vvtd,DMAR_FSTS_REG ,DMA_FSTS_IQE_BIT ) ) +return ;
xen/drivers/passthrough/vtd/vvtd.c static int vvtd_record_fault(struct vvtd *vvtd, · line 540
Quoted 10 lines
xen/drivers/passthrough/vtd/vvtd.c +10
-0+ +vvtd_get_reg_quad (vvtd,DMAR_IQH_REG , iqh); +vvtd_get_reg_quad (vvtd,DMAR_IQT_REG , iqt); +vvtd_get_reg_quad (vvtd,DMAR_IQA_REG , iqa); + + max_entry =DMA_IQA_ENTRY_PER_PAGE <<DMA_IQA_QS (iqa); + iqh =DMA_IQH_QH (iqh); + iqt =DMA_IQT_QT (iqt); + +ASSERT (iqt < max_entry);
Is the guest allowed to write to DMAR_IQT_REG? Is there a chance it can write a value that could make the ASSERT trigger?
xen/drivers/passthrough/vtd/vvtd.c static int vvtd_record_fault(struct vvtd *vvtd, · line 545
Quoted 5 lines
xen/drivers/passthrough/vtd/vvtd.c +5
-0+if ( iqh == iqt ) +return ; + + i = iqh; +while ( i != iqt )
This looks like it wants to be a for loop.
xen/drivers/passthrough/vtd/vvtd.c static int vvtd_record_fault(struct vvtd *vvtd, · line 550
Quoted 5 lines
xen/drivers/passthrough/vtd/vvtd.c +5
-0+ { + ret =process_iqe (vvtd, i); +if ( ret ) +break ; +else
Unneeded else.
xen/drivers/passthrough/vtd/vvtd.c static int vvtd_record_fault(struct vvtd *vvtd, · line 552
Quoted 2 lines
xen/drivers/passthrough/vtd/vvtd.c +2
-0+ i = (i +1 ) % max_entry; +vvtd_set_reg_quad (vvtd,DMAR_IQH_REG , i <<DMA_IQH_QH_SHIFT );
Can't you do this at the end of the loop instead of doing it on every iterations?
Quoted 7 lines
xen/drivers/passthrough/vtd/vvtd.c +7
-0+ } + +/* +* When IQE set, IQH references the desriptor associated with the error. +*/ +if ( ret ) +vvtd_report_non_recoverable_fault (vvtd,DMA_FSTS_IQE_BIT );
xen/drivers/passthrough/vtd/vvtd.c static int vvtd_record_fault(struct vvtd *vvtd, · line 569
Quoted 10 lines
xen/drivers/passthrough/vtd/vvtd.c +10
-0+} + +static int vvtd_write_iqt (struct vvtd *vvtd,unsigned long val) +{ +uint64_t iqa; + +if ( val &DMA_IQT_RSVD ) + { +VVTD_DEBUG (VVTD_DBG_RW ,"Attempt to set reserved bits in " +"Invalidation Queue Tail." );
Please try to not split the debug messages into separate lines, it makes grepping for them harder.
xen/drivers/passthrough/vtd/vvtd.c static int vvtd_record_fault(struct vvtd *vvtd, · line 577
Quoted 8 lines
xen/drivers/passthrough/vtd/vvtd.c +8
-0+return X86EMUL_OKAY ; + } + +vvtd_get_reg_quad (vvtd,DMAR_IQA_REG , iqa); +if (DMA_IQT_QT (val) >=DMA_IQA_ENTRY_PER_PAGE <<DMA_IQA_QS (iqa) ) + { +VVTD_DEBUG (VVTD_DBG_RW ,"IQT: Value %lx exceeded supported max " +"index." , val);
Same here.
xen/drivers/passthrough/vtd/vvtd.c static int vvtd_record_fault(struct vvtd *vvtd, · line 582
Quoted 5 lines
xen/drivers/passthrough/vtd/vvtd.c +5
-0+return X86EMUL_OKAY ; + } + +vvtd_set_reg_quad (vvtd,DMAR_IQT_REG , val); +vvtd_process_iq (vvtd);
Newline.
Quoted 36 lines
xen/drivers/passthrough/vtd/vvtd.c +29
-0+return X86EMUL_OKAY ; +} + +static int vvtd_write_iqa (struct vvtd *vvtd,unsigned long val) +{ +if ( val &DMA_IQA_RSVD ) + { +VVTD_DEBUG (VVTD_DBG_RW ,"Attempt to set reserved bits in " +"Invalidation Queue Address." ); +return X86EMUL_OKAY ; + } + +vvtd_set_reg_quad (vvtd,DMAR_IQA_REG , val); +return X86EMUL_OKAY ; +} + +static int vvtd_write_ics (struct vvtd *vvtd,uint32_t val) +{ +if ( val &DMA_ICS_IWC ) + { +__vvtd_clear_bit (vvtd,DMAR_ICS_REG ,DMA_ICS_IWC_BIT ); +/*When IWC field is cleared, the IP field needs to be cleared */ +__vvtd_clear_bit (vvtd,DMAR_IECTL_REG ,DMA_IECTL_IP_BIT ); + } +return X86EMUL_OKAY ; +} +static int vvtd_write_frcd3 (struct vvtd *vvtd,uint32_t val) {/* Writing a 1 means clear fault */ @@ -439,6 +618,29 @@ static int vvtd_write_frcd3(struct vvtd *vvtd, uint32_t val)return X86EMUL_OKAY ; } +static int vvtd_write_iectl (struct vvtd *vvtd,uint32_t val) +{
xen/drivers/passthrough/vtd/vvtd.c static int vvtd_write_frcd3(struct vvtd *vvtd, uint32_t val) · line 632
Quoted 10 lines
xen/drivers/passthrough/vtd/vvtd.c +10
-0+/* +* Only DMA_IECTL_IM bit is writable. Generate pending event when unmask. +*/ +if ( !(val &DMA_IECTL_IM ) ) + { +/* Clear IM and clear IP */ +__vvtd_clear_bit (vvtd,DMAR_IECTL_REG ,DMA_IECTL_IM_BIT ); +if (vvtd_test_and_clear_bit (vvtd,DMAR_IECTL_REG ,DMA_IECTL_IP_BIT ) ) + { +uint32_t ie_data, ie_addr;
Newline.
Quoted 37 lines
xen/drivers/passthrough/vtd/vvtd.c +23
-0+ ie_data =vvtd_get_reg (vvtd,DMAR_IEDATA_REG ); + ie_addr =vvtd_get_reg (vvtd,DMAR_IEADDR_REG ); +vvtd_generate_interrupt (vvtd, ie_addr, ie_data); + } + } +else +__vvtd_set_bit (vvtd,DMAR_IECTL_REG ,DMA_IECTL_IM_BIT ); + +return X86EMUL_OKAY ; +} +static int vvtd_write_fectl (struct vvtd *vvtd,uint32_t val) {/* @@ -481,6 +683,10 @@ static int vvtd_write_fsts(struct vvtd *vvtd, uint32_t val)if ( !((vvtd_get_reg (vvtd,DMAR_FSTS_REG ) &DMA_FSTS_FAULTS )) )__vvtd_clear_bit (vvtd,DMAR_FECTL_REG ,DMA_FECTL_IP_BIT ); +/* Continue to deal invalidation when IQE is clear */ +if ( !vvtd_test_bit (vvtd,DMAR_FSTS_REG ,DMA_FSTS_IQE_BIT ) ) +vvtd_process_iq (vvtd); +return X86EMUL_OKAY ; }@@ -639,6 +845,36 @@ static int vvtd_write(struct vcpu *v, unsigned long addr, ret =vvtd_write_frcd3 (vvtd, val);break ; +case DMAR_IECTL_REG : + ret =vvtd_write_iectl (vvtd, val); +break ; + +case DMAR_ICS_REG : + ret =vvtd_write_ics (vvtd, val); +break ; +
xen/drivers/passthrough/vtd/vvtd.c static int vvtd_write(struct vcpu *v, unsigned long addr, · line 865
Quoted 10 lines
xen/drivers/passthrough/vtd/vvtd.c +10
-0+case DMAR_IQT_REG : + ret =vvtd_write_iqt (vvtd, (uint32_t )val); +break ; + +case DMAR_IQA_REG : + { +uint32_t iqa_hi; + + iqa_hi =vvtd_get_reg (vvtd,DMAR_IQA_REG_HI ); + ret =vvtd_write_iqa (vvtd, (uint32_t )val | ((uint64_t )iqa_hi <<32 ));
Line length.
Quoted 38 lines
xen/drivers/passthrough/vtd/vvtd.c +20
-0+break ; + } + +case DMAR_IQA_REG_HI : + { +uint32_t iqa_lo; + + iqa_lo =vvtd_get_reg (vvtd,DMAR_IQA_REG ); + ret =vvtd_write_iqa (vvtd, (val <<32 ) | iqa_lo); +break ; + } +case DMAR_IEDATA_REG :case DMAR_IEADDR_REG :case DMAR_IEUADDR_REG :@@ -668,6 +904,14 @@ static int vvtd_write(struct vcpu *v, unsigned long addr, ret =vvtd_write_frcd3 (vvtd, val >>32 );break ; +case DMAR_IQT_REG : + ret =vvtd_write_iqt (vvtd, val); +break ; + +case DMAR_IQA_REG : + ret =vvtd_write_iqa (vvtd, val); +break ; +default : ret =X86EMUL_UNHANDLEABLE ;break ;Signature · 7 lines
1.8.3.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH V2 24/25] x86/vvtd: Add queued invalidation (QI) support
Quoted 10 lines · Roger Pau Monné
Quoted 9 lines · Lan Tianyu
Quoted 9 lines
From: Chao Gao <[email protected]>
Queued Invalidation Interface is an expanded invalidation interface with extended capabilities. Hardware implementations report support for queued invalidation interface through the Extended Capability Register. The queued invalidation interface uses an Invalidation Queue (IQ), which is a circular buffer in system memory. Software submits commands by writing Invalidation Descriptors to the IQ.
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
In this patch, a new function
viommu_process_iq()is used for emulating how hardware handles invalidation requests through QI.It seems like this is an extended feature, which is not needed for basic functionality. Would it be possible to have this series focus on the bare-minimum functionality, leaving everything else to a separate series?
No, IOMMU supporting interrupt remapping must also support Queued Invalidation (QI) according VTD spec.
Signature · 7 lines
Best regards Tianyu Lan _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel