From: Chao Gao <chao.gao@intel.com>
To: "Roger Pau Monné" <roger.pau@citrix.com>
Cc: Lan Tianyu <tianyu.lan@intel.com>,
tim@xen.org, kevin.tian@intel.com, sstabellini@kernel.org,
wei.liu2@citrix.com, konrad.wilk@oracle.com,
George.Dunlap@eu.citrix.com, andrew.cooper3@citrix.com,
ian.jackson@eu.citrix.com, xen-devel@lists.xen.org,
jbeulich@suse.com
Subject: Re: [PATCH V3 11/29] x86/hvm: Introduce a emulated VTD for HVM
Date: Fri, 20 Oct 2017 10:46:40 +0800 [thread overview]
Message-ID: <20171020024640.GE74825@op-computing> (raw)
In-Reply-To: <20171019112035.juze2w6zmlswco4d@dhcp-3-128.uk.xensource.com>
On Thu, Oct 19, 2017 at 12:20:35PM +0100, Roger Pau Monné wrote:
>On Thu, Sep 21, 2017 at 11:01:52PM -0400, Lan Tianyu wrote:
>> From: Chao Gao <chao.gao@intel.com>
>>
>> This patch adds create/destroy function for the emulated VTD
>> and adapts it to the common VIOMMU abstraction.
>>
>> Signed-off-by: Chao Gao <chao.gao@intel.com>
>> Signed-off-by: Lan Tianyu <tianyu.lan@intel.com>
>> ---
>>
>> -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
>
>Why do you need to shuffle the list above?
I placed them in alphabetic order.
>
>Also I'm not sure the Intel vIOMMU implementation should live here. As
>you can see the path is:
>
>xen/drivers/passthrough/vtd/
>
>The vIOMMU is not tied to passthrough at all, so I would rather place
>it in:
>
>xen/drivers/vvtd/
>
>Or maybe you can create something like:
>
>xen/drivers/viommu/
>
>So that all vIOMMU implementations can share some code.
>
vvtd and vtd use the same header files (i.g. vtd.h). That is why we put
it there. If that, we shoule move the related header files to a public
directory.
>> #define cap_isoch(c) (((c) >> 23) & 1)
>> #define cap_qos(c) (((c) >> 22) & 1)
>> #define cap_mgaw(c) ((((c) >> 16) & 0x3f) + 1)
>> -#define cap_sagaw(c) (((c) >> 8) & 0x1f)
>> +#define cap_set_mgaw(c) ((((c) - 1) & 0x3f) << 16)
>> +#define cap_sagaw(c) (((c) >> DMA_CAP_SAGAW_SHIFT) & 0x1f)
>> #define cap_caching_mode(c) (((c) >> 7) & 1)
>> #define cap_phmr(c) (((c) >> 6) & 1)
>> #define cap_plmr(c) (((c) >> 5) & 1)
>> @@ -104,10 +113,16 @@
>> #define ecap_niotlb_iunits(e) ((((e) >> 24) & 0xff) + 1)
>> #define ecap_iotlb_offset(e) ((((e) >> 8) & 0x3ff) * 16)
>> #define ecap_coherent(e) ((e >> 0) & 0x1)
>> -#define ecap_queued_inval(e) ((e >> 1) & 0x1)
>> +#define DMA_ECAP_QI_SHIFT 1
>> +#define DMA_ECAP_QI (1ULL << DMA_ECAP_QI_SHIFT)
>> +#define ecap_queued_inval(e) ((e >> DMA_ECAP_QI_SHIFT) & 0x1)
>
>Looks like this could be based on MASK_EXTR instead, but seeing how
>the file is full of open-coded mask extracts I'm not sure it's worth
>it anymore.
>
>> #define ecap_dev_iotlb(e) ((e >> 2) & 0x1)
>> -#define ecap_intr_remap(e) ((e >> 3) & 0x1)
>> -#define ecap_eim(e) ((e >> 4) & 0x1)
>> +#define DMA_ECAP_IR_SHIFT 3
>> +#define DMA_ECAP_IR (1ULL << DMA_ECAP_IR_SHIFT)
>> +#define ecap_intr_remap(e) ((e >> DMA_ECAP_IR_SHIFT) & 0x1)
>> +#define DMA_ECAP_EIM_SHIFT 4
>> +#define DMA_ECAP_EIM (1ULL << DMA_ECAP_EIM_SHIFT)
>> +#define ecap_eim(e) ((e >> DMA_ECAP_EIM_SHIFT) & 0x1)
>
>Maybe worth placing all the DMA_ECAP_* defines in a separate section?
>Seems like how it's done for other features like DMA_FSTS or
>DMA_CCMD.
Got it.
>> +
>> +/* Supported capabilities by vvtd */
>> +unsigned int vvtd_caps = VIOMMU_CAP_IRQ_REMAPPING;
>
>static?
>
>Or even better, why is this not a define like VIOMMU_MAX_CAPS or
>similar.
Yeah. It should be renamed to VVTD_MAX_CAPS.
>
>> +
>> +union hvm_hw_vvtd_regs {
>> + uint32_t data32[256];
>> + uint64_t data64[128];
>> +};
>
>Do you really need to store all the register space instead of only
>storing specific registers?
I prefer to store all the registers for we don't need a trick to map
the real offset in hardware to the index in the array.
>
>> +
>> +struct vvtd {
>> + /* Address range of remapping hardware register-set */
>> + uint64_t base_addr;
>> + uint64_t length;
>
>The length field doesn't seem to be used below.
will remove it.
>
>> + /* Point back to the owner domain */
>> + struct domain *domain;
>> + union hvm_hw_vvtd_regs *regs;
>
>Does this need to be a pointer?
Seems not.
>
>> + struct page_info *regs_page;
>> +};
>> +
>> +static int vvtd_create(struct domain *d, struct viommu *viommu)
>> +{
>> + struct vvtd *vvtd;
>> + int ret;
>> +
>> + if ( !is_hvm_domain(d) || (viommu->base_address & (PAGE_SIZE - 1)) ||
>> + (~vvtd_caps & viommu->caps) )
>> + return -EINVAL;
>> +
>> + ret = -ENOMEM;
>> + vvtd = xzalloc_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 )
>> + goto out2;
>> + clear_page(vvtd->regs);
>
>Not sure why vvtd->regs needs to be a pointer, and why it needs to use
>a full page. AFAICT the size of hvm_hw_vvtd_regs is 1024B, so you are
>wasting 3/4 of a page.
I will define registers as an array directly and
shrink the size to the number we are really used now.
>> +struct viommu_ops vvtd_hvm_vmx_ops = {
>> + .create = vvtd_create,
>> + .destroy = vvtd_destroy
>> +};
>> +
>> +static int vvtd_register(void)
>> +{
>> + viommu_register_type(VIOMMU_TYPE_INTEL_VTD, &vvtd_hvm_vmx_ops);
>> + return 0;
>> +}
>> +__initcall(vvtd_register);
>
>As commented in another patch I think the vIOMMU types should be
>registered using a method similar to REGISTER_SCHEDULER.
Both are ok to me. Will follow your suggestion.
Thanks
Chao
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2017-10-20 2:46 UTC|newest]
Thread overview: 108+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-22 3:01 [PATCH V3 00/29] Lan Tianyu
2017-09-22 3:01 ` [PATCH V3 1/29] Xen/doc: Add Xen virtual IOMMU doc Lan Tianyu
2017-10-18 13:26 ` Roger Pau Monné
2017-10-19 2:26 ` Lan Tianyu
2017-10-19 8:49 ` Roger Pau Monné
2017-10-19 11:28 ` Jan Beulich
2017-10-24 7:16 ` Lan Tianyu
2017-09-22 3:01 ` [PATCH V3 2/29] VIOMMU: Add vIOMMU helper functions to create, destroy vIOMMU instance Lan Tianyu
2017-10-18 14:05 ` Roger Pau Monné
2017-10-19 6:31 ` Lan Tianyu
2017-10-19 8:47 ` Roger Pau Monné
2017-10-25 1:43 ` Lan Tianyu
2017-10-30 1:41 ` Lan Tianyu
2017-10-30 9:54 ` Roger Pau Monné
2017-10-30 1:51 ` Lan Tianyu
2017-11-06 8:19 ` Jan Beulich
2017-09-22 3:01 ` [PATCH V3 3/29] DOMCTL: Introduce new DOMCTL commands for vIOMMU support Lan Tianyu
2017-10-18 14:18 ` Roger Pau Monné
2017-10-19 6:41 ` Lan Tianyu
2017-09-22 3:01 ` [PATCH V3 4/29] tools/libacpi: Add DMA remapping reporting (DMAR) ACPI table structures Lan Tianyu
2017-10-18 14:36 ` Roger Pau Monné
2017-10-19 6:46 ` Lan Tianyu
2017-09-22 3:01 ` [PATCH V3 5/29] tools/libacpi: Add new fields in acpi_config for DMAR table Lan Tianyu
2017-10-18 15:12 ` Roger Pau Monné
2017-10-19 8:09 ` Lan Tianyu
2017-10-19 8:40 ` Roger Pau Monné
2017-10-25 6:06 ` Lan Tianyu
2017-10-19 11:31 ` Jan Beulich
2017-09-22 3:01 ` [PATCH V3 6/29] tools/libxl: Add a user configurable parameter to control vIOMMU attributes Lan Tianyu
2017-10-19 9:49 ` Roger Pau Monné
2017-10-20 1:36 ` Chao Gao
2017-09-22 3:01 ` [PATCH V3 7/29] tools/libxl: build DMAR table for a guest with one virtual VTD Lan Tianyu
2017-10-19 10:00 ` Roger Pau Monné
2017-10-20 1:44 ` Chao Gao
2017-09-22 3:01 ` [PATCH V3 8/29] tools/libxl: create vIOMMU during domain construction Lan Tianyu
2017-10-19 10:13 ` Roger Pau Monné
2017-10-26 12:05 ` Wei Liu
2017-10-27 1:58 ` Lan Tianyu
2017-09-22 3:01 ` [PATCH V3 9/29] tools/libxc: Add viommu operations in libxc Lan Tianyu
2017-10-19 10:17 ` Roger Pau Monné
2017-09-22 3:01 ` [PATCH V3 10/29] vtd: add and align register definitions Lan Tianyu
2017-10-19 10:21 ` Roger Pau Monné
2017-10-20 1:47 ` Chao Gao
2017-09-22 3:01 ` [PATCH V3 11/29] x86/hvm: Introduce a emulated VTD for HVM Lan Tianyu
2017-10-19 11:20 ` Roger Pau Monné
2017-10-20 2:46 ` Chao Gao [this message]
2017-10-20 6:56 ` Jan Beulich
2017-10-20 6:12 ` Chao Gao
2017-10-20 8:37 ` Lan Tianyu
2017-09-22 3:01 ` [PATCH V3 12/29] x86/vvtd: Add MMIO handler for VVTD Lan Tianyu
2017-10-19 11:34 ` Roger Pau Monné
2017-10-20 2:58 ` Chao Gao
2017-10-20 9:51 ` Roger Pau Monné
2017-09-22 3:01 ` [PATCH V3 13/29] x86/vvtd: Set Interrupt Remapping Table Pointer through GCMD Lan Tianyu
2017-10-19 11:56 ` Roger Pau Monné
2017-10-20 4:08 ` Chao Gao
2017-10-20 6:57 ` Jan Beulich
2017-09-22 3:01 ` [PATCH V3 14/29] x86/vvtd: Enable Interrupt Remapping " Lan Tianyu
2017-10-19 13:42 ` Roger Pau Monné
2017-09-22 3:01 ` [PATCH V3 15/29] x86/vvtd: Process interrupt remapping request Lan Tianyu
2017-10-19 14:26 ` Roger Pau Monné
2017-10-20 5:16 ` Chao Gao
2017-10-20 10:01 ` Roger Pau Monné
2017-10-23 6:44 ` Chao Gao
2017-09-22 3:01 ` [PATCH V3 16/29] x86/vvtd: decode interrupt attribute from IRTE Lan Tianyu
2017-10-19 14:39 ` Roger Pau Monné
2017-10-20 5:22 ` Chao Gao
2017-09-22 3:01 ` [PATCH V3 17/29] x86/vvtd: add a helper function to decide the interrupt format Lan Tianyu
2017-10-19 14:43 ` Roger Pau Monné
2017-09-22 3:01 ` [PATCH V3 18/29] VIOMMU: Add irq request callback to deal with irq remapping Lan Tianyu
2017-10-19 15:00 ` Roger Pau Monné
2017-09-22 3:02 ` [PATCH V3 19/29] x86/vioapic: Hook interrupt delivery of vIOAPIC Lan Tianyu
2017-10-19 15:37 ` Roger Pau Monné
2017-09-22 3:02 ` [PATCH V3 20/29] VIOMMU: Add get irq info callback to convert irq remapping request Lan Tianyu
2017-10-19 15:42 ` Roger Pau Monné
2017-10-25 7:30 ` Lan Tianyu
2017-10-25 7:43 ` Roger Pau Monné
2017-10-25 7:38 ` Lan Tianyu
2017-09-22 3:02 ` [PATCH V3 21/29] VIOMMU: Introduce callback of checking irq remapping mode Lan Tianyu
2017-10-19 15:43 ` Roger Pau Monné
2017-09-22 3:02 ` [PATCH V3 22/29] x86/vioapic: extend vioapic_get_vector() to support remapping format RTE Lan Tianyu
2017-10-19 15:49 ` Roger Pau Monné
2017-10-19 15:56 ` Jan Beulich
2017-10-20 1:04 ` Chao Gao
2017-09-22 3:02 ` [PATCH V3 23/29] passthrough: move some fields of hvm_gmsi_info to a sub-structure Lan Tianyu
2017-09-22 3:02 ` [PATCH V3 24/29] tools/libxc: Add a new interface to bind remapping format msi with pirq Lan Tianyu
2017-10-19 16:03 ` Roger Pau Monné
2017-10-20 5:39 ` Chao Gao
2017-09-22 3:02 ` [PATCH V3 25/29] x86/vmsi: Hook delivering remapping format msi to guest Lan Tianyu
2017-10-19 16:07 ` Roger Pau Monné
2017-10-20 6:48 ` Jan Beulich
2017-09-22 3:02 ` [PATCH V3 26/29] x86/vvtd: Handle interrupt translation faults Lan Tianyu
2017-10-19 16:31 ` Roger Pau Monné
2017-10-20 5:54 ` Chao Gao
2017-10-20 10:08 ` Roger Pau Monné
2017-10-20 14:20 ` Jan Beulich
2017-09-22 3:02 ` [PATCH V3 27/29] x86/vvtd: Enable Queued Invalidation through GCMD Lan Tianyu
2017-10-20 10:30 ` Roger Pau Monné
2017-09-22 3:02 ` [PATCH V3 28/29] x86/vvtd: Add queued invalidation (QI) support Lan Tianyu
2017-10-20 11:20 ` Roger Pau Monné
2017-10-23 7:50 ` Chao Gao
2017-10-23 8:57 ` Roger Pau Monné
2017-10-23 8:52 ` Chao Gao
2017-10-23 23:26 ` Tian, Kevin
2017-09-22 3:02 ` [PATCH V3 29/29] x86/vvtd: save and restore emulated VT-d Lan Tianyu
2017-10-20 11:25 ` Roger Pau Monné
2017-10-20 11:36 ` [PATCH V3 00/29] Roger Pau Monné
2017-10-23 1:23 ` Lan Tianyu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171020024640.GE74825@op-computing \
--to=chao.gao@intel.com \
--cc=George.Dunlap@eu.citrix.com \
--cc=andrew.cooper3@citrix.com \
--cc=ian.jackson@eu.citrix.com \
--cc=jbeulich@suse.com \
--cc=kevin.tian@intel.com \
--cc=konrad.wilk@oracle.com \
--cc=roger.pau@citrix.com \
--cc=sstabellini@kernel.org \
--cc=tianyu.lan@intel.com \
--cc=tim@xen.org \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).