All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 1/2] xen: replace complicated tlbflush check with an inline function
@ 2016-09-12  8:16 Dongli Zhang
  2016-09-12  8:16 ` [PATCH v4 2/2] xen: move TLB-flush filtering out into populate_physmap during vm creation Dongli Zhang
  2016-09-14 16:16 ` [PATCH v4 1/2] xen: replace complicated tlbflush check with an inline function Jan Beulich
  0 siblings, 2 replies; 8+ messages in thread
From: Dongli Zhang @ 2016-09-12  8:16 UTC (permalink / raw)
  To: xen-devel
  Cc: sstabellini, wei.liu2, George.Dunlap, andrew.cooper3,
	dario.faggioli, ian.jackson, tim, david.vrabel, jbeulich

This patch cleaned up the code by replacing complicated tlbflush check with
an inline function. We should use this inline function to avoid the long
and complicated to read tlbflush check when implementing TODOs left in
commit a902c12ee45fc9389eb8fe54eeddaf267a555c58.

Signed-off-by: Dongli Zhang <dongli.zhang@oracle.com>
---
Changed since v3:
  * Wrap the complicated tlbflush condition check as inline function
    (suggested by Dario).

---
 xen/common/page_alloc.c |  7 +++----
 xen/include/xen/mm.h    | 11 +++++++++++
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c
index 18ff6cf..5b93a01 100644
--- a/xen/common/page_alloc.c
+++ b/xen/common/page_alloc.c
@@ -827,10 +827,9 @@ static struct page_info *alloc_heap_pages(
         BUG_ON(pg[i].count_info != PGC_state_free);
         pg[i].count_info = PGC_state_inuse;
 
-        if ( pg[i].u.free.need_tlbflush &&
-             (pg[i].tlbflush_timestamp <= tlbflush_current_time()) &&
-             (!need_tlbflush ||
-              (pg[i].tlbflush_timestamp > tlbflush_timestamp)) )
+        if ( page_needs_tlbflush(&pg[i], need_tlbflush,
+                                 tlbflush_timestamp,
+                                 tlbflush_current_time()) )
         {
             need_tlbflush = 1;
             tlbflush_timestamp = pg[i].tlbflush_timestamp;
diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h
index 58bc0b8..766559d 100644
--- a/xen/include/xen/mm.h
+++ b/xen/include/xen/mm.h
@@ -567,4 +567,15 @@ int prepare_ring_for_helper(struct domain *d, unsigned long gmfn,
                             struct page_info **_page, void **_va);
 void destroy_ring_for_helper(void **_va, struct page_info *page);
 
+static inline int page_needs_tlbflush(struct page_info *page,
+                                      bool_t need_tlbflush,
+                                      uint32_t tlbflush_timestamp,
+                                      uint32_t tlbflush_current_time)
+{
+    return page->u.free.need_tlbflush &&
+           page->tlbflush_timestamp <= tlbflush_current_time &&
+           (!need_tlbflush ||
+            page->tlbflush_timestamp > tlbflush_timestamp);
+}
+
 #endif /* __XEN_MM_H__ */
-- 
1.9.1


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

^ permalink raw reply related	[flat|nested] 8+ messages in thread
* Re: [PATCH v4 2/2] xen: move TLB-flush filtering out into populate_physmap during vm creation
@ 2016-09-16 10:47 Dongli Zhang
  2016-09-16 10:55 ` Wei Liu
  0 siblings, 1 reply; 8+ messages in thread
From: Dongli Zhang @ 2016-09-16 10:47 UTC (permalink / raw)
  To: JBeulich, wei.liu2
  Cc: sstabellini, George.Dunlap, tim, dario.faggioli, ian.jackson,
	xen-devel, david.vrabel, andrew.cooper3

> > +    /*
> > +     * MEMF_no_tlbflush can be set only during vm creation phase when
> > +     * is_ever_unpaused is still false before this domain gets unpaused for
> > +     * the first time.
> > +     */
> > +    if ( unlikely(!d->is_ever_unpaused) )
> > +        a->memflags |= MEMF_no_tlbflush;
> 
> So you no longer mean to expose this to the caller?

hmmm.... I would prefer to expose this to the toolstack if it is OK for
maintainers.

I copy and paste Wei's comments below:

==============================================

> Rule 1. It is toolstack's responsibility to set the "MEMF_no_tlbflush" bit
> in memflags. The toolstack developers should be careful that
> "MEMF_no_tlbflush" should never be used after vm creation is finished.
> 

Is it possible to have a safety catch for this in the hypervisor? In
general IMHO we should avoid providing an interface that is possible to
create a security problem.

==============================================

Hi Wei, since it is possible to have a safety catch now in the hypervisor (the
bit is allowed only before VM creation is finished), is it OK for you to expose
MEMF_no_tlbflush bit to toolstack?

Thank you very much!

Dongli Zhang

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

^ permalink raw reply	[flat|nested] 8+ messages in thread
* Re: [PATCH v4 2/2] xen: move TLB-flush filtering out into populate_physmap during vm creation
@ 2016-09-16 11:34 Dongli Zhang
  0 siblings, 0 replies; 8+ messages in thread
From: Dongli Zhang @ 2016-09-16 11:34 UTC (permalink / raw)
  To: wei.liu2
  Cc: sstabellini, George.Dunlap, tim, dario.faggioli, ian.jackson,
	xen-devel, david.vrabel, JBeulich, andrew.cooper3

> What is the scenario that you would want toolstack to set such flag?
> 
> Shouldn't hypervisor always set the flag when the guest is never
> unpaused and always clear / ignore that flag if the guest is ever
> unpaused? If that's all is needed, why does toolstack need to get
> involved?

You are right. I will not expose the flag to toolstack.

----- Original Message -----
From: wei.liu2@citrix.com
To: dongli.zhang@oracle.com
Cc: JBeulich@suse.com, wei.liu2@citrix.com, konrad.wilk@oracle.com, sstabellini@kernel.org, tim@xen.org, dario.faggioli@citrix.com, ian.jackson@eu.citrix.com, George.Dunlap@eu.citrix.com, david.vrabel@citrix.com, xen-devel@lists.xen.org, andrew.cooper3@citrix.com
Sent: Friday, September 16, 2016 6:55:33 PM GMT +08:00 Beijing / Chongqing / Hong Kong / Urumqi
Subject: Re: [PATCH v4 2/2] xen: move TLB-flush filtering out into populate_physmap during vm creation

On Fri, Sep 16, 2016 at 03:47:23AM -0700, Dongli Zhang wrote:
> > > +    /*
> > > +     * MEMF_no_tlbflush can be set only during vm creation phase when
> > > +     * is_ever_unpaused is still false before this domain gets unpaused for
> > > +     * the first time.
> > > +     */
> > > +    if ( unlikely(!d->is_ever_unpaused) )
> > > +        a->memflags |= MEMF_no_tlbflush;
> > 
> > So you no longer mean to expose this to the caller?
> 
> hmmm.... I would prefer to expose this to the toolstack if it is OK for
> maintainers.
> 
> I copy and paste Wei's comments below:
> 
> ==============================================
> 
> > Rule 1. It is toolstack's responsibility to set the "MEMF_no_tlbflush" bit
> > in memflags. The toolstack developers should be careful that
> > "MEMF_no_tlbflush" should never be used after vm creation is finished.
> > 
> 
> Is it possible to have a safety catch for this in the hypervisor? In
> general IMHO we should avoid providing an interface that is possible to
> create a security problem.
> 
> ==============================================
> 
> Hi Wei, since it is possible to have a safety catch now in the hypervisor (the
> bit is allowed only before VM creation is finished), is it OK for you to expose
> MEMF_no_tlbflush bit to toolstack?
> 

What is the scenario that you would want toolstack to set such flag?

Shouldn't hypervisor always set the flag when the guest is never
unpaused and always clear / ignore that flag if the guest is ever
unpaused? If that's all is needed, why does toolstack need to get
involved?

Do I miss something here?

Wei.


> Thank you very much!
> 
> Dongli Zhang

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

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

end of thread, other threads:[~2016-09-16 11:34 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-12  8:16 [PATCH v4 1/2] xen: replace complicated tlbflush check with an inline function Dongli Zhang
2016-09-12  8:16 ` [PATCH v4 2/2] xen: move TLB-flush filtering out into populate_physmap during vm creation Dongli Zhang
2016-09-14 16:52   ` Dario Faggioli
2016-09-15  8:39   ` Jan Beulich
2016-09-14 16:16 ` [PATCH v4 1/2] xen: replace complicated tlbflush check with an inline function Jan Beulich
2016-09-16 10:47 [PATCH v4 2/2] xen: move TLB-flush filtering out into populate_physmap during vm creation Dongli Zhang
2016-09-16 10:55 ` Wei Liu
2016-09-16 11:34 Dongli Zhang

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.