From: "Tian, Kevin" <kevin.tian@intel.com>
To: Paul Durrant <paul@xen.org>,
"xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>
Cc: "Paul Durrant" <pdurrant@amazon.com>,
"Jan Beulich" <jbeulich@suse.com>,
"Andrew Cooper" <andrew.cooper3@citrix.com>,
"George Dunlap" <george.dunlap@citrix.com>,
"Wei Liu" <wl@xen.org>, "Roger Pau Monné" <roger.pau@citrix.com>
Subject: RE: [PATCH v4 10/14] iommu: remove the share_p2m operation
Date: Fri, 14 Aug 2020 07:04:44 +0000 [thread overview]
Message-ID: <MWHPR11MB1645DA201DEF84340FE173E98C400@MWHPR11MB1645.namprd11.prod.outlook.com> (raw)
In-Reply-To: <20200804134209.8717-11-paul@xen.org>
> From: Paul Durrant <paul@xen.org>
> Sent: Tuesday, August 4, 2020 9:42 PM
>
> From: Paul Durrant <pdurrant@amazon.com>
>
> Sharing of HAP tables is now VT-d specific so the operation is never defined
> for AMD IOMMU any more. There's also no need to pro-actively set
> vtd.pgd_maddr
> when using shared EPT as it is straightforward to simply define a helper
> function to return the appropriate value in the shared and non-shared cases.
>
> Signed-off-by: Paul Durrant <pdurrant@amazon.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
> ---
> Cc: Jan Beulich <jbeulich@suse.com>
> Cc: Andrew Cooper <andrew.cooper3@citrix.com>
> Cc: George Dunlap <george.dunlap@citrix.com>
> Cc: Wei Liu <wl@xen.org>
> Cc: "Roger Pau Monné" <roger.pau@citrix.com>
> Cc: Kevin Tian <kevin.tian@intel.com>
>
> v2:
> - Put the PGD level adjust into the helper function too, since it is
> irrelevant in the shared EPT case
> ---
> xen/arch/x86/mm/p2m.c | 3 -
> xen/drivers/passthrough/iommu.c | 8 ---
> xen/drivers/passthrough/vtd/iommu.c | 90 ++++++++++++++++-------------
> xen/include/xen/iommu.h | 3 -
> 4 files changed, 50 insertions(+), 54 deletions(-)
>
> diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c
> index 9f8b9bc5fd..3bd8d83d23 100644
> --- a/xen/arch/x86/mm/p2m.c
> +++ b/xen/arch/x86/mm/p2m.c
> @@ -726,9 +726,6 @@ int p2m_alloc_table(struct p2m_domain *p2m)
>
> p2m->phys_table = pagetable_from_mfn(top_mfn);
>
> - if ( hap_enabled(d) )
> - iommu_share_p2m_table(d);
> -
> p2m_unlock(p2m);
> return 0;
> }
> diff --git a/xen/drivers/passthrough/iommu.c
> b/xen/drivers/passthrough/iommu.c
> index ab44c332bb..7464f10d1c 100644
> --- a/xen/drivers/passthrough/iommu.c
> +++ b/xen/drivers/passthrough/iommu.c
> @@ -498,14 +498,6 @@ int iommu_do_domctl(
> return ret;
> }
>
> -void iommu_share_p2m_table(struct domain* d)
> -{
> - ASSERT(hap_enabled(d));
> -
> - if ( iommu_use_hap_pt(d) )
> - iommu_get_ops()->share_p2m(d);
> -}
> -
> void iommu_crash_shutdown(void)
> {
> if ( !iommu_crash_disable )
> diff --git a/xen/drivers/passthrough/vtd/iommu.c
> b/xen/drivers/passthrough/vtd/iommu.c
> index 68cf0e535a..a532d9e88c 100644
> --- a/xen/drivers/passthrough/vtd/iommu.c
> +++ b/xen/drivers/passthrough/vtd/iommu.c
> @@ -318,6 +318,48 @@ static u64 addr_to_dma_page_maddr(struct
> domain *domain, u64 addr, int alloc)
> return pte_maddr;
> }
>
> +static uint64_t domain_pgd_maddr(struct domain *d, struct vtd_iommu
> *iommu)
> +{
> + struct domain_iommu *hd = dom_iommu(d);
> + uint64_t pgd_maddr;
> + unsigned int agaw;
> +
> + ASSERT(spin_is_locked(&hd->arch.mapping_lock));
> +
> + if ( iommu_use_hap_pt(d) )
> + {
> + mfn_t pgd_mfn =
> + pagetable_get_mfn(p2m_get_pagetable(p2m_get_hostp2m(d)));
> +
> + return pagetable_get_paddr(pagetable_from_mfn(pgd_mfn));
> + }
> +
> + if ( !hd->arch.vtd.pgd_maddr )
> + {
> + addr_to_dma_page_maddr(d, 0, 1);
> +
> + if ( !hd->arch.vtd.pgd_maddr )
> + return 0;
> + }
> +
> + pgd_maddr = hd->arch.vtd.pgd_maddr;
> +
> + /* Skip top levels of page tables for 2- and 3-level DRHDs. */
> + for ( agaw = level_to_agaw(4);
> + agaw != level_to_agaw(iommu->nr_pt_levels);
> + agaw-- )
> + {
> + struct dma_pte *p = map_vtd_domain_page(pgd_maddr);
> +
> + pgd_maddr = dma_pte_addr(*p);
> + unmap_vtd_domain_page(p);
> + if ( !pgd_maddr )
> + return 0;
> + }
> +
> + return pgd_maddr;
> +}
> +
> static void iommu_flush_write_buffer(struct vtd_iommu *iommu)
> {
> u32 val;
> @@ -1286,7 +1328,7 @@ int domain_context_mapping_one(
> struct context_entry *context, *context_entries;
> u64 maddr, pgd_maddr;
> u16 seg = iommu->drhd->segment;
> - int agaw, rc, ret;
> + int rc, ret;
> bool_t flush_dev_iotlb;
>
> ASSERT(pcidevs_locked());
> @@ -1340,37 +1382,18 @@ int domain_context_mapping_one(
> if ( iommu_hwdom_passthrough && is_hardware_domain(domain) )
> {
> context_set_translation_type(*context, CONTEXT_TT_PASS_THRU);
> - agaw = level_to_agaw(iommu->nr_pt_levels);
> }
> else
> {
> spin_lock(&hd->arch.mapping_lock);
>
> - /* Ensure we have pagetables allocated down to leaf PTE. */
> - if ( hd->arch.vtd.pgd_maddr == 0 )
> + pgd_maddr = domain_pgd_maddr(domain, iommu);
> + if ( !pgd_maddr )
> {
> - addr_to_dma_page_maddr(domain, 0, 1);
> - if ( hd->arch.vtd.pgd_maddr == 0 )
> - {
> - nomem:
> - spin_unlock(&hd->arch.mapping_lock);
> - spin_unlock(&iommu->lock);
> - unmap_vtd_domain_page(context_entries);
> - return -ENOMEM;
> - }
> - }
> -
> - /* Skip top levels of page tables for 2- and 3-level DRHDs. */
> - pgd_maddr = hd->arch.vtd.pgd_maddr;
> - for ( agaw = level_to_agaw(4);
> - agaw != level_to_agaw(iommu->nr_pt_levels);
> - agaw-- )
> - {
> - struct dma_pte *p = map_vtd_domain_page(pgd_maddr);
> - pgd_maddr = dma_pte_addr(*p);
> - unmap_vtd_domain_page(p);
> - if ( pgd_maddr == 0 )
> - goto nomem;
> + spin_unlock(&hd->arch.mapping_lock);
> + spin_unlock(&iommu->lock);
> + unmap_vtd_domain_page(context_entries);
> + return -ENOMEM;
> }
>
> context_set_address_root(*context, pgd_maddr);
> @@ -1389,7 +1412,7 @@ int domain_context_mapping_one(
> return -EFAULT;
> }
>
> - context_set_address_width(*context, agaw);
> + context_set_address_width(*context, level_to_agaw(iommu-
> >nr_pt_levels));
> context_set_fault_enable(*context);
> context_set_present(*context);
> iommu_sync_cache(context, sizeof(struct context_entry));
> @@ -1848,18 +1871,6 @@ static int __init vtd_ept_page_compatible(struct
> vtd_iommu *iommu)
> (ept_has_1gb(ept_cap) && opt_hap_1gb) <= cap_sps_1gb(vtd_cap);
> }
>
> -/*
> - * set VT-d page table directory to EPT table if allowed
> - */
> -static void iommu_set_pgd(struct domain *d)
> -{
> - mfn_t pgd_mfn;
> -
> - pgd_mfn =
> pagetable_get_mfn(p2m_get_pagetable(p2m_get_hostp2m(d)));
> - dom_iommu(d)->arch.vtd.pgd_maddr =
> - pagetable_get_paddr(pagetable_from_mfn(pgd_mfn));
> -}
> -
> static int rmrr_identity_mapping(struct domain *d, bool_t map,
> const struct acpi_rmrr_unit *rmrr,
> u32 flag)
> @@ -2719,7 +2730,6 @@ static struct iommu_ops __initdata vtd_ops = {
> .adjust_irq_affinities = adjust_vtd_irq_affinities,
> .suspend = vtd_suspend,
> .resume = vtd_resume,
> - .share_p2m = iommu_set_pgd,
> .crash_shutdown = vtd_crash_shutdown,
> .iotlb_flush = iommu_flush_iotlb_pages,
> .iotlb_flush_all = iommu_flush_iotlb_all,
> diff --git a/xen/include/xen/iommu.h b/xen/include/xen/iommu.h
> index b7e5d3da09..1f25d2082f 100644
> --- a/xen/include/xen/iommu.h
> +++ b/xen/include/xen/iommu.h
> @@ -271,7 +271,6 @@ struct iommu_ops {
>
> int __must_check (*suspend)(void);
> void (*resume)(void);
> - void (*share_p2m)(struct domain *d);
> void (*crash_shutdown)(void);
> int __must_check (*iotlb_flush)(struct domain *d, dfn_t dfn,
> unsigned long page_count,
> @@ -348,8 +347,6 @@ void iommu_resume(void);
> void iommu_crash_shutdown(void);
> int iommu_get_reserved_device_memory(iommu_grdm_t *, void *);
>
> -void iommu_share_p2m_table(struct domain *d);
> -
> #ifdef CONFIG_HAS_PCI
> int iommu_do_pci_domctl(struct xen_domctl *, struct domain *d,
> XEN_GUEST_HANDLE_PARAM(xen_domctl_t));
> --
> 2.20.1
next prev parent reply other threads:[~2020-08-14 7:05 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-04 13:41 [PATCH v4 00/14] IOMMU cleanup Paul Durrant
2020-08-04 13:41 ` [PATCH v4 01/14] x86/iommu: re-arrange arch_iommu to separate common fields Paul Durrant
2020-08-14 6:14 ` Tian, Kevin
2020-08-04 13:41 ` [PATCH v4 02/14] x86/iommu: add common page-table allocator Paul Durrant
2020-08-05 15:39 ` Jan Beulich
2020-08-04 13:41 ` [PATCH v4 03/14] x86/iommu: convert VT-d code to use new page table allocator Paul Durrant
2020-08-14 6:41 ` Tian, Kevin
2020-08-14 7:16 ` Durrant, Paul
2020-08-04 13:41 ` [PATCH v4 04/14] x86/iommu: convert AMD IOMMU " Paul Durrant
2020-08-04 13:42 ` [PATCH v4 05/14] iommu: remove unused iommu_ops method and tasklet Paul Durrant
2020-08-04 13:42 ` [PATCH v4 06/14] iommu: flush I/O TLB if iommu_map() or iommu_unmap() fail Paul Durrant
2020-08-05 16:06 ` Jan Beulich
2020-08-05 16:18 ` Paul Durrant
2020-08-06 11:41 ` Jan Beulich
2020-08-14 6:53 ` Tian, Kevin
2020-08-14 7:19 ` Durrant, Paul
2020-08-04 13:42 ` [PATCH v4 07/14] iommu: make map, unmap and flush all take both an order and a count Paul Durrant
2020-08-06 9:57 ` Jan Beulich
2020-08-11 11:00 ` Durrant, Paul
2020-08-14 6:57 ` Tian, Kevin
2020-08-04 13:42 ` [PATCH v4 08/14] remove remaining uses of iommu_legacy_map/unmap Paul Durrant
2020-08-06 10:28 ` Jan Beulich
2020-08-12 9:36 ` [EXTERNAL] " Paul Durrant
2020-08-04 13:42 ` [PATCH v4 09/14] common/grant_table: batch flush I/O TLB Paul Durrant
2020-08-06 11:49 ` Jan Beulich
2020-08-04 13:42 ` [PATCH v4 10/14] iommu: remove the share_p2m operation Paul Durrant
2020-08-06 12:18 ` Jan Beulich
2020-08-14 7:04 ` Tian, Kevin [this message]
2020-08-04 13:42 ` [PATCH v4 11/14] iommu: stop calling IOMMU page tables 'p2m tables' Paul Durrant
2020-08-06 12:23 ` Jan Beulich
2020-08-14 7:12 ` Tian, Kevin
2020-08-04 13:42 ` [PATCH v4 12/14] vtd: use a bit field for root_entry Paul Durrant
2020-08-06 12:34 ` Jan Beulich
2020-08-12 13:13 ` Durrant, Paul
2020-08-18 8:27 ` Jan Beulich
2020-08-14 7:17 ` Tian, Kevin
2020-08-04 13:42 ` [PATCH v4 13/14] vtd: use a bit field for context_entry Paul Durrant
2020-08-06 12:46 ` Jan Beulich
2020-08-12 13:47 ` Paul Durrant
2020-08-14 7:19 ` Tian, Kevin
2020-08-04 13:42 ` [PATCH v4 14/14] vtd: use a bit field for dma_pte Paul Durrant
2020-08-06 12:53 ` Jan Beulich
2020-08-12 13:49 ` Paul Durrant
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=MWHPR11MB1645DA201DEF84340FE173E98C400@MWHPR11MB1645.namprd11.prod.outlook.com \
--to=kevin.tian@intel.com \
--cc=andrew.cooper3@citrix.com \
--cc=george.dunlap@citrix.com \
--cc=jbeulich@suse.com \
--cc=paul@xen.org \
--cc=pdurrant@amazon.com \
--cc=roger.pau@citrix.com \
--cc=wl@xen.org \
--cc=xen-devel@lists.xenproject.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).