All of lore.kernel.org
 help / color / mirror / Atom feed
From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
To: Malcolm Crossley <malcolm.crossley@citrix.com>
Cc: kevin.tian@intel.com, feng.wu@intel.com, xen-devel@lists.xen.org
Subject: Re: [RFC PATCH 3/7] VT-d: Add iommu_lookup_page support
Date: Wed, 17 Feb 2016 15:32:25 -0500	[thread overview]
Message-ID: <20160217203225.GD25726@char.us.oracle.com> (raw)
In-Reply-To: <1455099035-17649-4-git-send-email-malcolm.crossley@citrix.com>

On Wed, Feb 10, 2016 at 10:10:31AM +0000, Malcolm Crossley wrote:
> Function does not need to handle shared EPT use of IOMMU as core code
> already handles this.

Could you mention which part of 'core code' handles this?

Also you may want to say this code can only deal with 4K pages but
not with larger ones.

> 
> Signed-off-by: Malcolm Crossley <malcolm.crossley@citrix.com>
> --
> Cc: kevin.tian@intel.com
> Cc: feng.wu@intel.com
> Cc: xen-devel@lists.xen.org
> ---
>  xen/drivers/passthrough/vtd/iommu.c | 31 +++++++++++++++++++++++++++++++
>  xen/drivers/passthrough/vtd/iommu.h |  1 +
>  2 files changed, 32 insertions(+)
> 
> diff --git a/xen/drivers/passthrough/vtd/iommu.c b/xen/drivers/passthrough/vtd/iommu.c
> index ec31c6b..0c79b48 100644
> --- a/xen/drivers/passthrough/vtd/iommu.c
> +++ b/xen/drivers/passthrough/vtd/iommu.c
> @@ -1754,6 +1754,36 @@ static int intel_iommu_unmap_page(struct domain *d, unsigned long gfn)
>      return 0;
>  }
>  
> +static int intel_iommu_lookup_page(
> +    struct domain *d, unsigned long gfn, unsigned long *mfn)
> +{
> +    struct hvm_iommu *hd = domain_hvm_iommu(d);
> +    struct dma_pte *page = NULL, *pte = NULL, old;
> +    u64 pg_maddr;
> +
> +    spin_lock(&hd->arch.mapping_lock);
> +
> +    pg_maddr = addr_to_dma_page_maddr(d, (paddr_t)gfn << PAGE_SHIFT_4K, 1);
> +    if ( pg_maddr == 0 )
> +    {
> +        spin_unlock(&hd->arch.mapping_lock);
> +        return -ENOMEM;
> +    }
> +    page = (struct dma_pte *)map_vtd_domain_page(pg_maddr);
> +    pte = page + (gfn & LEVEL_MASK);
> +    old = *pte;
> +    if (!dma_pte_present(old)) {
> +        unmap_vtd_domain_page(page);
> +        spin_unlock(&hd->arch.mapping_lock);
> +        return -ENOMEM;
> +    }
> +    unmap_vtd_domain_page(page);
> +    spin_unlock(&hd->arch.mapping_lock);

All this code looks close to lookup routine in dma_pte_clear_one and
intel_iommu_map_page.

Could you move most of this lookup code in a static function that your
code and the other ones could call?

> +
> +    *mfn = dma_get_pte_addr(old) >> PAGE_SHIFT_4K;
> +    return 0;
> +}
> +
>  void iommu_pte_flush(struct domain *d, u64 gfn, u64 *pte,
>                       int order, int present)
>  {
> @@ -2534,6 +2564,7 @@ const struct iommu_ops intel_iommu_ops = {
>      .teardown = iommu_domain_teardown,
>      .map_page = intel_iommu_map_page,
>      .unmap_page = intel_iommu_unmap_page,
> +    .lookup_page = intel_iommu_lookup_page,
>      .free_page_table = iommu_free_page_table,
>      .reassign_device = reassign_device_ownership,
>      .get_device_group_id = intel_iommu_group_id,
> diff --git a/xen/drivers/passthrough/vtd/iommu.h b/xen/drivers/passthrough/vtd/iommu.h
> index c55ee08..03583ef 100644
> --- a/xen/drivers/passthrough/vtd/iommu.h
> +++ b/xen/drivers/passthrough/vtd/iommu.h
> @@ -275,6 +275,7 @@ struct dma_pte {
>  #define dma_pte_addr(p) ((p).val & PADDR_MASK & PAGE_MASK_4K)
>  #define dma_set_pte_addr(p, addr) do {\
>              (p).val |= ((addr) & PAGE_MASK_4K); } while (0)
> +#define dma_get_pte_addr(p) (((p).val & PAGE_MASK_4K))
>  #define dma_pte_present(p) (((p).val & DMA_PTE_PROT) != 0)
>  #define dma_pte_superpage(p) (((p).val & DMA_PTE_SP) != 0)
>  
> -- 
> 1.7.12.4
> 
> 
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xen.org
> http://lists.xen.org/xen-devel

  reply	other threads:[~2016-02-17 20:32 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1455099035-17649-1-git-send-email-malcolm.crossley@citrix.com>
2016-02-10 10:10 ` [RFC PATCH 1/7] common/pv-iommu: Add stub hypercall for PV-IOMMU Malcolm Crossley
2016-02-10 10:36   ` Malcolm Crossley
2016-02-17 20:09   ` Konrad Rzeszutek Wilk
2016-02-10 10:10 ` [RFC PATCH 2/7] iommu: add iommu_lookup_page to lookup guest gfn for a particular IOMMU mapping Malcolm Crossley
2016-02-17 20:22   ` Konrad Rzeszutek Wilk
2016-02-24 15:08     ` George Dunlap
2016-02-24 15:10       ` Andrew Cooper
2016-02-10 10:10 ` [RFC PATCH 3/7] VT-d: Add iommu_lookup_page support Malcolm Crossley
2016-02-17 20:32   ` Konrad Rzeszutek Wilk [this message]
2016-02-10 10:10 ` [RFC PATCH 4/7] common/pv-iommu: Add query, map and unmap ops Malcolm Crossley
2016-02-17 21:05   ` Konrad Rzeszutek Wilk
2016-02-17 21:07     ` Konrad Rzeszutek Wilk
2016-02-10 10:10 ` [RFC PATCH 5/7] x86/m2b: Add a tracking structure for mfn to bfn mappings per page Malcolm Crossley
2016-02-24 17:07   ` George Dunlap
2016-02-10 10:10 ` [RFC PATCH 6/7] common/pv-iommu: Add foreign ops to PV-IOMMU interface Malcolm Crossley
2016-02-17 21:11   ` Konrad Rzeszutek Wilk
2016-02-10 10:10 ` [RFC PATCH 7/7] common/pv-iommu: Allow hardware_domain to pre IOMMU map foreign memory Malcolm Crossley
2016-02-10 10:33 ` [RFC PATCH 0/7] Implement Xen PV-IOMMU interface Malcolm Crossley
2016-02-17 20:12   ` Konrad Rzeszutek Wilk
2016-02-24 18:08   ` George Dunlap
2016-11-22 16:21   ` Martin Cerveny

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=20160217203225.GD25726@char.us.oracle.com \
    --to=konrad.wilk@oracle.com \
    --cc=feng.wu@intel.com \
    --cc=kevin.tian@intel.com \
    --cc=malcolm.crossley@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.