All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Avoid needless flush cache when guest change MTRR
@ 2015-02-04  3:28 Liang Li
  2015-02-04  5:42 ` Tian, Kevin
  2015-02-04  8:50 ` Jan Beulich
  0 siblings, 2 replies; 5+ messages in thread
From: Liang Li @ 2015-02-04  3:28 UTC (permalink / raw)
  To: xen-devel
  Cc: kevin.tian, keir, andrew.cooper3, Liang Li, jbeulich, Yang Zhang

Flushing cache is needed only when guest has IOMMU device, using
need_iommu(d) can minimize the impact to guest with device assigned,
since a guest may be hot plugged with a device thus there may be dirty
cache lines before need_iommu(d) becoming true, force the flush_all
when the first device is assigned to guest to amend this issue.

Signed-off-by: Liang Li <liang.z.li@intel.com>
Signed-off-by: Yang Zhang <yang.z.zhang@intel.com>
---
 xen/arch/x86/hvm/mtrr.c       | 2 +-
 xen/drivers/passthrough/pci.c | 5 +++++
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/xen/arch/x86/hvm/mtrr.c b/xen/arch/x86/hvm/mtrr.c
index ee18553..858fb7e 100644
--- a/xen/arch/x86/hvm/mtrr.c
+++ b/xen/arch/x86/hvm/mtrr.c
@@ -791,7 +791,7 @@ HVM_REGISTER_SAVE_RESTORE(MTRR, hvm_save_mtrr_msr, hvm_load_mtrr_msr,
 
 void memory_type_changed(struct domain *d)
 {
-    if ( iommu_enabled && d->vcpu && d->vcpu[0] )
+    if ( need_iommu(d) && d->vcpu && d->vcpu[0] )
     {
         p2m_memory_type_changed(d);
         flush_all(FLUSH_CACHE);
diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c
index 78c6977..a023d1d 100644
--- a/xen/drivers/passthrough/pci.c
+++ b/xen/drivers/passthrough/pci.c
@@ -1365,6 +1365,11 @@ static int assign_device(struct domain *d, u16 seg, u8 bus, u8 devfn)
             }
         }
         d->need_iommu = 1;
+        /* There may be dirty cache lines when a device is assigned
+         * and before need_iommu(d) becoming true, this will cause
+         * memory_type_changed lose effect if memory type changes.
+         * Call memory_type_changed here to amend this. */
+        memory_type_changed(d);
     }
 
     pdev = pci_get_pdev_by_domain(hardware_domain, seg, bus, devfn);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] Avoid needless flush cache when guest change MTRR
  2015-02-04  3:28 [PATCH] Avoid needless flush cache when guest change MTRR Liang Li
@ 2015-02-04  5:42 ` Tian, Kevin
  2015-02-04  5:53   ` Zhang, Yang Z
  2015-02-04  8:50 ` Jan Beulich
  1 sibling, 1 reply; 5+ messages in thread
From: Tian, Kevin @ 2015-02-04  5:42 UTC (permalink / raw)
  To: Li, Liang Z, xen-devel; +Cc: Zhang, Yang Z, andrew.cooper3, keir, jbeulich

> From: Li, Liang Z
> Sent: Wednesday, February 04, 2015 11:28 AM
> 
> Flushing cache is needed only when guest has IOMMU device, using
> need_iommu(d) can minimize the impact to guest with device assigned,
> since a guest may be hot plugged with a device thus there may be dirty
> cache lines before need_iommu(d) becoming true, force the flush_all
> when the first device is assigned to guest to amend this issue.
> 
> Signed-off-by: Liang Li <liang.z.li@intel.com>
> Signed-off-by: Yang Zhang <yang.z.zhang@intel.com>
> ---
>  xen/arch/x86/hvm/mtrr.c       | 2 +-
>  xen/drivers/passthrough/pci.c | 5 +++++
>  2 files changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/xen/arch/x86/hvm/mtrr.c b/xen/arch/x86/hvm/mtrr.c
> index ee18553..858fb7e 100644
> --- a/xen/arch/x86/hvm/mtrr.c
> +++ b/xen/arch/x86/hvm/mtrr.c
> @@ -791,7 +791,7 @@ HVM_REGISTER_SAVE_RESTORE(MTRR,
> hvm_save_mtrr_msr, hvm_load_mtrr_msr,
> 
>  void memory_type_changed(struct domain *d)
>  {
> -    if ( iommu_enabled && d->vcpu && d->vcpu[0] )
> +    if ( need_iommu(d) && d->vcpu && d->vcpu[0] )
>      {
>          p2m_memory_type_changed(d);
>          flush_all(FLUSH_CACHE);
> diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c
> index 78c6977..a023d1d 100644
> --- a/xen/drivers/passthrough/pci.c
> +++ b/xen/drivers/passthrough/pci.c
> @@ -1365,6 +1365,11 @@ static int assign_device(struct domain *d, u16 seg,
> u8 bus, u8 devfn)
>              }
>          }
>          d->need_iommu = 1;
> +        /* There may be dirty cache lines when a device is assigned
> +         * and before need_iommu(d) becoming true, this will cause
> +         * memory_type_changed lose effect if memory type changes.
> +         * Call memory_type_changed here to amend this. */
> +        memory_type_changed(d);

could we relax this force flush only on the 1st assigned device which actually
changes need_iommu(d) from false to true?

>      }
> 
>      pdev = pci_get_pdev_by_domain(hardware_domain, seg, bus, devfn);
> --
> 1.9.1

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Avoid needless flush cache when guest change MTRR
  2015-02-04  5:42 ` Tian, Kevin
@ 2015-02-04  5:53   ` Zhang, Yang Z
  2015-02-04  6:13     ` Tian, Kevin
  0 siblings, 1 reply; 5+ messages in thread
From: Zhang, Yang Z @ 2015-02-04  5:53 UTC (permalink / raw)
  To: Tian, Kevin, Li, Liang Z, xen-devel; +Cc: andrew.cooper3, keir, jbeulich

Tian, Kevin wrote on 2015-02-04:
>> From: Li, Liang Z
>> Sent: Wednesday, February 04, 2015 11:28 AM
>> 
>> Flushing cache is needed only when guest has IOMMU device, using
>> need_iommu(d) can minimize the impact to guest with device assigned,
>> since a guest may be hot plugged with a device thus there may be
>> dirty cache lines before need_iommu(d) becoming true, force the
>> flush_all when the first device is assigned to guest to amend this issue.
>> 
>> Signed-off-by: Liang Li <liang.z.li@intel.com>
>> Signed-off-by: Yang Zhang <yang.z.zhang@intel.com>
>> ---
>>  xen/arch/x86/hvm/mtrr.c       | 2 +-
>>  xen/drivers/passthrough/pci.c | 5 +++++
>>  2 files changed, 6 insertions(+), 1 deletion(-)
>> diff --git a/xen/arch/x86/hvm/mtrr.c b/xen/arch/x86/hvm/mtrr.c index
>> ee18553..858fb7e 100644 --- a/xen/arch/x86/hvm/mtrr.c +++
>> b/xen/arch/x86/hvm/mtrr.c @@ -791,7 +791,7 @@
>> HVM_REGISTER_SAVE_RESTORE(MTRR, hvm_save_mtrr_msr, hvm_load_mtrr_msr,
>> 
>>  void memory_type_changed(struct domain *d)  {
>> -    if ( iommu_enabled && d->vcpu && d->vcpu[0] )
>> +    if ( need_iommu(d) && d->vcpu && d->vcpu[0] )
>>      {
>>          p2m_memory_type_changed(d);
>>          flush_all(FLUSH_CACHE);
>> diff --git a/xen/drivers/passthrough/pci.c
>> b/xen/drivers/passthrough/pci.c index 78c6977..a023d1d 100644
>> --- a/xen/drivers/passthrough/pci.c
>> +++ b/xen/drivers/passthrough/pci.c
>> @@ -1365,6 +1365,11 @@ static int assign_device(struct domain *d,
>> u16 seg,
>> u8 bus, u8 devfn)
>>              }
>>          }
>>          d->need_iommu = 1;
>> +        /* There may be dirty cache lines when a device is assigned
>> +         * and before need_iommu(d) becoming true, this will cause
>> +         * memory_type_changed lose effect if memory type changes.
>> +         * Call memory_type_changed here to amend this. */
>> +        memory_type_changed(d);
> 
> could we relax this force flush only on the 1st assigned device which
> actually changes need_iommu(d) from false to true?

It is already covered by current code when updating need_iommu, but the patch doesn't show it:

if ( need_iommu(d) <= 0 )
{    
    .....
    d->need_iommu = 1;
    memory_type_changed(d);
}

> 
>>      }
>>      
>>      pdev = pci_get_pdev_by_domain(hardware_domain, seg, bus,
>> devfn);
>> --
>> 1.9.1


Best regards,
Yang

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Avoid needless flush cache when guest change MTRR
  2015-02-04  5:53   ` Zhang, Yang Z
@ 2015-02-04  6:13     ` Tian, Kevin
  0 siblings, 0 replies; 5+ messages in thread
From: Tian, Kevin @ 2015-02-04  6:13 UTC (permalink / raw)
  To: Zhang, Yang Z, Li, Liang Z, xen-devel; +Cc: andrew.cooper3, keir, jbeulich

> From: Zhang, Yang Z
> Sent: Wednesday, February 04, 2015 1:54 PM
> 
> Tian, Kevin wrote on 2015-02-04:
> >> From: Li, Liang Z
> >> Sent: Wednesday, February 04, 2015 11:28 AM
> >>
> >> Flushing cache is needed only when guest has IOMMU device, using
> >> need_iommu(d) can minimize the impact to guest with device assigned,
> >> since a guest may be hot plugged with a device thus there may be
> >> dirty cache lines before need_iommu(d) becoming true, force the
> >> flush_all when the first device is assigned to guest to amend this issue.
> >>
> >> Signed-off-by: Liang Li <liang.z.li@intel.com>
> >> Signed-off-by: Yang Zhang <yang.z.zhang@intel.com>
> >> ---
> >>  xen/arch/x86/hvm/mtrr.c       | 2 +-
> >>  xen/drivers/passthrough/pci.c | 5 +++++
> >>  2 files changed, 6 insertions(+), 1 deletion(-)
> >> diff --git a/xen/arch/x86/hvm/mtrr.c b/xen/arch/x86/hvm/mtrr.c index
> >> ee18553..858fb7e 100644 --- a/xen/arch/x86/hvm/mtrr.c +++
> >> b/xen/arch/x86/hvm/mtrr.c @@ -791,7 +791,7 @@
> >> HVM_REGISTER_SAVE_RESTORE(MTRR, hvm_save_mtrr_msr,
> hvm_load_mtrr_msr,
> >>
> >>  void memory_type_changed(struct domain *d)  {
> >> -    if ( iommu_enabled && d->vcpu && d->vcpu[0] )
> >> +    if ( need_iommu(d) && d->vcpu && d->vcpu[0] )
> >>      {
> >>          p2m_memory_type_changed(d);
> >>          flush_all(FLUSH_CACHE);
> >> diff --git a/xen/drivers/passthrough/pci.c
> >> b/xen/drivers/passthrough/pci.c index 78c6977..a023d1d 100644
> >> --- a/xen/drivers/passthrough/pci.c
> >> +++ b/xen/drivers/passthrough/pci.c
> >> @@ -1365,6 +1365,11 @@ static int assign_device(struct domain *d,
> >> u16 seg,
> >> u8 bus, u8 devfn)
> >>              }
> >>          }
> >>          d->need_iommu = 1;
> >> +        /* There may be dirty cache lines when a device is assigned
> >> +         * and before need_iommu(d) becoming true, this will cause
> >> +         * memory_type_changed lose effect if memory type changes.
> >> +         * Call memory_type_changed here to amend this. */
> >> +        memory_type_changed(d);
> >
> > could we relax this force flush only on the 1st assigned device which
> > actually changes need_iommu(d) from false to true?
> 
> It is already covered by current code when updating need_iommu, but the
> patch doesn't show it:
> 
> if ( need_iommu(d) <= 0 )
> {
>     .....
>     d->need_iommu = 1;
>     memory_type_changed(d);
> }
> 

You're right. :-)

Acked-by: Kevin Tian <kevin.tian@intel.com>

Thanks
Kevin

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Avoid needless flush cache when guest change MTRR
  2015-02-04  3:28 [PATCH] Avoid needless flush cache when guest change MTRR Liang Li
  2015-02-04  5:42 ` Tian, Kevin
@ 2015-02-04  8:50 ` Jan Beulich
  1 sibling, 0 replies; 5+ messages in thread
From: Jan Beulich @ 2015-02-04  8:50 UTC (permalink / raw)
  To: Liang Li; +Cc: Yang Zhang, andrew.cooper3, kevin.tian, keir, xen-devel

>>> On 04.02.15 at 04:28, <liang.z.li@intel.com> wrote:
> --- a/xen/arch/x86/hvm/mtrr.c
> +++ b/xen/arch/x86/hvm/mtrr.c
> @@ -791,7 +791,7 @@ HVM_REGISTER_SAVE_RESTORE(MTRR, hvm_save_mtrr_msr, hvm_load_mtrr_msr,
>  
>  void memory_type_changed(struct domain *d)
>  {
> -    if ( iommu_enabled && d->vcpu && d->vcpu[0] )
> +    if ( need_iommu(d) && d->vcpu && d->vcpu[0] )
>      {
>          p2m_memory_type_changed(d);
>          flush_all(FLUSH_CACHE);

This doesn't do what title and description say: You not only suppress
the flush, but also the EPT table adjustments. Either adjust at least
the description accordingly, or make the code do what the description
says.

> --- a/xen/drivers/passthrough/pci.c
> +++ b/xen/drivers/passthrough/pci.c
> @@ -1365,6 +1365,11 @@ static int assign_device(struct domain *d, u16 seg, u8 bus, u8 devfn)
>              }
>          }
>          d->need_iommu = 1;
> +        /* There may be dirty cache lines when a device is assigned
> +         * and before need_iommu(d) becoming true, this will cause
> +         * memory_type_changed lose effect if memory type changes.
> +         * Call memory_type_changed here to amend this. */
> +        memory_type_changed(d);

The comment formatting does not adhere to ./CODING_STYLE.

Jan

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-02-04  8:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-04  3:28 [PATCH] Avoid needless flush cache when guest change MTRR Liang Li
2015-02-04  5:42 ` Tian, Kevin
2015-02-04  5:53   ` Zhang, Yang Z
2015-02-04  6:13     ` Tian, Kevin
2015-02-04  8:50 ` Jan Beulich

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.