All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Xu, Quan" <quan.xu@intel.com>
To: "Tian, Kevin" <kevin.tian@intel.com>,
	"xen-devel@lists.xen.org" <xen-devel@lists.xen.org>
Cc: Keir Fraser <keir@xen.org>,
	"dario.faggioli@citrix.com" <dario.faggioli@citrix.com>,
	"Wu, Feng" <feng.wu@intel.com>, Jan Beulich <jbeulich@suse.com>,
	Andrew Cooper <andrew.cooper3@citrix.com>
Subject: Re: [PATCH v2 01/11] vt-d: fix the IOMMU flush issue
Date: Tue, 19 Apr 2016 08:33:09 +0000	[thread overview]
Message-ID: <945CA011AD5F084CBEA3E851C0AB28894B88D34B@SHSMSX101.ccr.corp.intel.com> (raw)
In-Reply-To: <AADFC41AFE54684AB9EE6CBC0274A5D15F821AC5@SHSMSX101.ccr.corp.intel.com>

On April 19, 2016 2:33pm, Tian, Kevin <kevin.tian@intel.com> wrote:
> > From: Xu, Quan
> > Sent: Monday, April 18, 2016 10:00 PM
> >
> > The propagation value from IOMMU flush interfaces may be positive,
> > which indicates callers need to flush cache, not one of faliures.
> >
> > when the propagation value is positive, this patch fixes this flush
> > issue as follows:
> >   - call iommu_flush_write_buffer() to flush cache.
> >   - return zero.
> >
> > Signed-off-by: Quan Xu <quan.xu@intel.com>
> >
> > CC: Kevin Tian <kevin.tian@intel.com>
> > CC: Feng Wu <feng.wu@intel.com>
> > CC: Keir Fraser <keir@xen.org>
> > CC: Jan Beulich <jbeulich@suse.com>
> > CC: Andrew Cooper <andrew.cooper3@citrix.com>
> > ---
> >  xen/drivers/passthrough/vtd/iommu.c | 94
> > ++++++++++++++++++++++++-------------
> >  xen/include/asm-x86/iommu.h         |  2 +-
> >  2 files changed, 63 insertions(+), 33 deletions(-)
> >
> > diff --git a/xen/drivers/passthrough/vtd/iommu.c
> > b/xen/drivers/passthrough/vtd/iommu.c
> > index 5ad25dc..50d98ac 100644
> > --- a/xen/drivers/passthrough/vtd/iommu.c
> > +++ b/xen/drivers/passthrough/vtd/iommu.c
> > @@ -558,14 +558,16 @@ static void iommu_flush_all(void)
> >      }
> >  }
> >
> > -static void __intel_iommu_iotlb_flush(struct domain *d, unsigned long gfn,
> > -        int dma_old_pte_present, unsigned int page_count)
> > +static int iommu_flush_iotlb(struct domain *d, unsigned long gfn,
> 
> any reason for the renaming here?
> 

As Jan mentioned, 
"this would be a good opportunity to also drop the stray double underscores: You need to touch all callers anyway."
http://lists.xenproject.org/archives/html/xen-devel/2016-03/msg02456.html 

think twice, I dropped the stray double underscores.
both intel_iommu_iotlb_flush and iommu_iotlb_flush were already in use,
So I tried to rename it to ' iommu_flush_iotlb'.


> > +                             int dma_old_pte_present,
> > +                             unsigned int page_count)
> >  {
> >      struct hvm_iommu *hd = domain_hvm_iommu(d);
> >      struct acpi_drhd_unit *drhd;
> >      struct iommu *iommu;
> >      int flush_dev_iotlb;
> >      int iommu_domid;
> > +    int rc = 0;
> >
> >      /*
> >       * No need pcideves_lock here because we have flush @@ -584,29
> > +586,34 @@ static void __intel_iommu_iotlb_flush(struct domain *d,
> > unsigned long gfn,
> >              continue;
> >
> >          if ( page_count != 1 || gfn == INVALID_GFN )
> > -        {
> > -            if ( iommu_flush_iotlb_dsi(iommu, iommu_domid,
> > -                        0, flush_dev_iotlb) )
> > -                iommu_flush_write_buffer(iommu);
> > -        }
> > +            rc = iommu_flush_iotlb_dsi(iommu, iommu_domid,
> > +                                       0, flush_dev_iotlb);
> >          else
> > +            rc = iommu_flush_iotlb_psi(iommu, iommu_domid,
> > +                                       (paddr_t)gfn <<
> PAGE_SHIFT_4K,
> > +                                       PAGE_ORDER_4K,
> > +                                       !dma_old_pte_present,
> > +                                       flush_dev_iotlb);
> > +
> > +        if ( rc > 0 )
> >          {
> > -            if ( iommu_flush_iotlb_psi(iommu, iommu_domid,
> > -                        (paddr_t)gfn << PAGE_SHIFT_4K,
> PAGE_ORDER_4K,
> > -                        !dma_old_pte_present, flush_dev_iotlb) )
> > -                iommu_flush_write_buffer(iommu);
> > -        }
> > +            iommu_flush_write_buffer(iommu);
> > +            rc = 0;
> > +        } else if ( rc < 0 )
> > +            break;
> >      }
> > +
> > +    return rc;
> >  }
> >
> >  static void intel_iommu_iotlb_flush(struct domain *d, unsigned long
> > gfn, unsigned int
> > page_count)
> >  {
> > -    __intel_iommu_iotlb_flush(d, gfn, 1, page_count);
> > +    iommu_flush_iotlb(d, gfn, 1, page_count);
> >  }
> >
> >  static void intel_iommu_iotlb_flush_all(struct domain *d)  {
> > -    __intel_iommu_iotlb_flush(d, INVALID_GFN, 0, 0);
> > +    iommu_flush_iotlb(d, INVALID_GFN, 0, 0);
> >  }
> 
> Do you plan to change return value of above 2 functions in another patch, or
> will keep it current form w/o propagation?
> 

Change return value of above 2 functions in another patches.


> >
> >  /* clear one page's page table */
> > @@ -640,7 +647,7 @@ static void dma_pte_clear_one(struct domain
> *domain, u64 addr)
> >      iommu_flush_cache_entry(pte, sizeof(struct dma_pte));
> >
> >      if ( !this_cpu(iommu_dont_flush_iotlb) )
> > -        __intel_iommu_iotlb_flush(domain, addr >> PAGE_SHIFT_4K, 1, 1);
> > +        iommu_flush_iotlb(domain, addr >> PAGE_SHIFT_4K, 1, 1);
> >
> >      unmap_vtd_domain_page(page);
> >  }
> > @@ -1281,6 +1288,7 @@ int domain_context_mapping_one(
> >      u64 maddr, pgd_maddr;
> >      u16 seg = iommu->intel->drhd->segment;
> >      int agaw;
> > +    int rc;
> >
> >      ASSERT(pcidevs_locked());
> >      spin_lock(&iommu->lock);
> > @@ -1394,13 +1402,19 @@ int domain_context_mapping_one(
> >      spin_unlock(&iommu->lock);
> >
> >      /* Context entry was previously non-present (with domid 0). */
> > -    if ( iommu_flush_context_device(iommu, 0, (((u16)bus) << 8) | devfn,
> > -                                    DMA_CCMD_MASK_NOBIT, 1) )
> > -        iommu_flush_write_buffer(iommu);
> > -    else
> > +    rc = iommu_flush_context_device(iommu, 0, (((u16)bus) << 8) | devfn,
> > +                                    DMA_CCMD_MASK_NOBIT, 1);
> > +
> > +    if ( !rc )
> >      {
> >          int flush_dev_iotlb = find_ats_dev_drhd(iommu) ? 1 : 0;
> > -        iommu_flush_iotlb_dsi(iommu, 0, 1, flush_dev_iotlb);
> > +        rc = iommu_flush_iotlb_dsi(iommu, 0, 1, flush_dev_iotlb);
> > +    }
> > +
> > +    if ( rc > 0 )
> > +    {
> > +        iommu_flush_write_buffer(iommu);
> > +        rc = 0;
> 
> what about 'rc>0' in iommu_flush_context_device while "rc<0"
> in iommu_flush_iotlb_dsi, which will leave write buffer not flushed?

That's true, but IMO it is impossible.
IOW, if 'rc>0' is in iommu_flush_context_device, the rc should be "rc>0" in iommu_flush_iotlb_dsi too.
As the flush_non_present_entry parameter is '1' to both, and read the same register 'iommu->cap' at the beginning of the functions.


To be honest, this modification is an aggressive approach and looks good to me, but I am open for any other suggestions.


Quan

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

  reply	other threads:[~2016-04-19  8:33 UTC|newest]

Thread overview: 78+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-18 14:00 [PATCH v2 00/11] Check VT-d Device-TLB flush error Quan Xu
2016-04-18 14:00 ` [PATCH v2 01/11] vt-d: fix the IOMMU flush issue Quan Xu
2016-04-19  6:33   ` Tian, Kevin
2016-04-19  8:33     ` Xu, Quan [this message]
2016-04-25  9:22   ` Jan Beulich
2016-04-26  1:17     ` Xu, Quan
2016-04-26  2:18     ` Xu, Quan
2016-04-26  9:10       ` Jan Beulich
2016-04-26 10:15         ` Xu, Quan
2016-04-26 10:52           ` Jan Beulich
2016-04-26 10:58             ` Xu, Quan
2016-04-18 14:00 ` [PATCH v2 02/11] IOMMU: handle IOMMU mapping and unmapping failures Quan Xu
2016-04-19  6:36   ` Tian, Kevin
2016-04-19  6:40     ` Xu, Quan
2016-04-25  9:26   ` Jan Beulich
2016-04-27 14:26     ` Xu, Quan
2016-04-27 15:02       ` Jan Beulich
2016-04-28  1:23         ` Xu, Quan
2016-04-18 14:00 ` [PATCH v2 03/11] IOMMU/MMU: enhance the call trees of IOMMU unmapping and mapping Quan Xu
2016-04-19  6:44   ` Tian, Kevin
2016-04-20  5:27     ` Xu, Quan
2016-04-20  5:44       ` Tian, Kevin
2016-04-20  6:11       ` Jan Beulich
2016-04-20  6:26         ` Xu, Quan
2016-04-25  9:50   ` Jan Beulich
2016-04-27  8:49     ` Xu, Quan
2016-04-27  9:36       ` Jan Beulich
2016-04-27 13:10         ` Xu, Quan
2016-04-27 14:06           ` Jan Beulich
2016-04-27 15:48   ` George Dunlap
2016-04-28  1:18     ` Xu, Quan
2016-04-18 14:00 ` [PATCH v2 04/11] grant_table: avoid unnecessary work during grant table unmapping Quan Xu
2016-04-19  6:46   ` Tian, Kevin
2016-04-19 13:27     ` Xu, Quan
2016-04-20  5:35       ` Tian, Kevin
2016-04-25  9:55   ` Jan Beulich
2016-04-26  6:48     ` Xu, Quan
2016-04-18 14:00 ` [PATCH v2 05/11] vt-d: propagate IOMMU Device-TLB flush error up to IOMMU unmapping Quan Xu
2016-04-19  6:51   ` Tian, Kevin
2016-04-19  7:01     ` Xu, Quan
2016-04-25 10:06   ` Jan Beulich
2016-04-26  6:49     ` Xu, Quan
2016-04-18 14:00 ` [PATCH v2 06/11] vt-d: propagate IOMMU Device-TLB flush error up to IOMMU mapping Quan Xu
2016-04-19  6:53   ` Tian, Kevin
2016-04-18 14:00 ` [PATCH v2 07/11] IOMMU/MMU: propagate IOMMU Device-TLB flush error up to iommu_iotlb_flush{, _all} (top level ones) Quan Xu
2016-04-25 10:19   ` Jan Beulich
2016-04-26 12:23     ` Xu, Quan
2016-04-26 12:48       ` Jan Beulich
2016-04-27  6:21         ` Xu, Quan
2016-04-27  6:31           ` Jan Beulich
2016-04-27  9:08             ` Xu, Quan
2016-04-27  9:38               ` Jan Beulich
2016-04-18 14:00 ` [PATCH v2 08/11] IOMMU: propagate IOMMU Device-TLB flush error up to iommu_iotlb_flush{, _all} (leaf ones) Quan Xu
2016-04-19  6:58   ` Tian, Kevin
2016-04-19  8:58     ` Xu, Quan
2016-04-25 11:39   ` Jan Beulich
2016-04-26 11:50     ` Xu, Quan
2016-04-26 12:51       ` Jan Beulich
2016-04-26 13:20         ` Xu, Quan
2016-04-18 14:00 ` [PATCH v2 09/11] IOMMU: propagate IOMMU Device-TLB flush error up to IOMMU suspending Quan Xu
2016-04-25 11:52   ` Jan Beulich
2016-04-25 13:58     ` Julien Grall
2016-04-25 14:50       ` Xu, Quan
2016-04-26  9:40         ` Julien Grall
2016-04-26 11:28     ` Xu, Quan
2016-04-28 14:14     ` Xu, Quan
2016-04-28 14:36       ` Jan Beulich
2016-04-28 15:03         ` Xu, Quan
2016-04-28 15:12           ` Jan Beulich
2016-04-28 16:08             ` Xu, Quan
2016-04-29  2:20               ` Tian, Kevin
2016-04-29  2:41                 ` Xu, Quan
2016-04-29  7:13                   ` Jan Beulich
2016-04-29  8:23                     ` Xu, Quan
2016-04-18 14:00 ` [PATCH v2 10/11] vt-d: propagate IOMMU Device-TLB flush error up to vt-d hardware initialization Quan Xu
2016-04-18 14:00 ` [PATCH v2 11/11] vt-d: propagate error up to ME phantom function mapping and unmapping Quan Xu
2016-04-25 12:00   ` Jan Beulich
2016-04-26 10:48     ` Xu, Quan

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=945CA011AD5F084CBEA3E851C0AB28894B88D34B@SHSMSX101.ccr.corp.intel.com \
    --to=quan.xu@intel.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=dario.faggioli@citrix.com \
    --cc=feng.wu@intel.com \
    --cc=jbeulich@suse.com \
    --cc=keir@xen.org \
    --cc=kevin.tian@intel.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.