x86/ioreq server: Asynchronously reset outstanding p2m_ioreq_server entries.
PATCH 1/1 x86/ioreq server: Asynchronously reset outstanding p2m_ioreq_server entries.
After an ioreq server has unmapped, the remaining p2m_ioreq_server entries need to be reset back to p2m_ram_rw. This patch does this asynchronously with the current p2m_change_entry_type_global() interface.
New field entry_count is introduced in struct p2m_domain, to record the number of p2m_ioreq_server p2m page table entries. One nature of these entries is that they only point to 4K sized page frames, because all p2m_ioreq_server entries are originated from p2m_ram_rw ones in p2m_change_type_one(). We do not need to worry about the counting for 2M/1G sized pages.
This patch disallows mapping of an ioreq server, when there's still p2m_ioreq_server entry left, in case another mapping occurs right after the current one being unmapped, releases its lock, with p2m table not synced yet.
This patch also disallows live migration, when there's remaining p2m_ioreq_server entry in p2m table. The core reason is our current implementation of p2m_change_entry_type_global() lacks information to resync p2m_ioreq_server entries correctly if global_logdirty is on.
We still need to handle other recalculations, however; which means that when doing a recalculation, if the current type is p2m_ioreq_server, we check to see if p2m->ioreq.server is valid or not. If it is, we leave it as type p2m_ioreq_server; if not, we reset it to p2m_ram as appropriate.
To avoid code duplication, lift recalc_type() out of p2m-pt.c and use it for all type recalculations (both in p2m-pt.c and p2m-ept.c).
---
Cc: Paul Durrant <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Jun Nakajima <[email protected]>
Cc: Kevin Tian <[email protected]>
Note: this is the 5/6 patch for the ioreq server patch series v12. with other patches got reviewed-by/acked-by, I just resend this one.
changes in v8:
- According to comments from Jan: do not reset p2m_ioreq_server back when an ioreq server is mapped.
- According to comments from Jan: added a helper function to do the p2m type calculation.
- According to comments from Jan: add ASSERT for 1G and 2M page size.
- According to comments from George: comment changes.
- Added "Signed-off-by: George Dunlap <[email protected]>".
changes in v7:
- According to comments from George: add code to increase the entry_count.
- Comment changes in {ept,p2m_pt}_set_entry.
changes in v6:
- According to comments from Jan & George: move the count from
p2m_change_type_one() to {ept,p2m_pt}_set_entry.- According to comments from George: comments change.
changes in v5:
- According to comments from Jan: use unsigned long for entry_count;
- According to comments from Jan: refuse mapping requirement when there's p2m_ioreq_server remained in p2m table.
- Added "Reviewed-by: Paul Durrant <[email protected]>"
changes in v4:
- According to comments from Jan: use ASSERT() instead of 'if' condition in p2m_change_type_one().
- According to comments from Jan: commit message changes to mention the p2m_ioreq_server are all based on 4K sized pages.
changes in v3:
- Move the synchronously resetting logic into patch 5.
- According to comments from Jan: introduce p2m_check_changeable() to clarify the p2m type change code.
- According to comments from George: use locks in the same order to avoid deadlock, call p2m_change_entry_type_global() after unmap of the ioreq server is finished.
changes in v2:
- Move the calculation of ioreq server page entry_cout into p2m_change_type_one() so that we do not need a seperate lock.
Note: entry_count is also calculated in resolve_misconfig()/ do_recalc(), fortunately callers of both routines have p2m lock protected already.
- Simplify logic in hvmop_set_mem_type().
- Introduce routine p2m_finish_type_change() to walk the p2m table and do the p2m reset.
--- xen/arch/x86/hvm/ioreq.c | 8 +++++ xen/arch/x86/mm/hap/hap.c | 9 ++++++ xen/arch/x86/mm/p2m-ept.c | 75 +++++++++++++++++++++++++++++++---------------- xen/arch/x86/mm/p2m-pt.c | 62 ++++++++++++++++++++++++++------------- xen/arch/x86/mm/p2m.c | 9 ++++++ xen/include/asm-x86/p2m.h | 25 +++++++++++++++- 6 files changed, 140 insertions(+), 48 deletions(-)
xen/arch/x86/hvm/ioreq.c +8 -0
@@ -955,6 +955,14 @@ int hvm_map_mem_type_to_ioreq_server(struct domain *d, ioservid_t id,spin_unlock_recursive (&d->arch.hvm_domain.ioreq_server.lock); +if ( rc ==0 && flags ==0 ) + { +struct p2m_domain *p2m =p2m_get_hostp2m (d); + +if (read_atomic (&p2m->ioreq.entry_count) ) +p2m_change_entry_type_global (d, p2m_ioreq_server, p2m_ram_rw); + } +return rc; }
xen/arch/x86/mm/hap/hap.c +9 -0
@@ -187,6 +187,15 @@ out:*/ static int hap_enable_log_dirty (struct domain *d,bool_t log_global) { +struct p2m_domain *p2m =p2m_get_hostp2m (d); + +/* +* Refuse to turn on global log-dirty mode if +* there are outstanding p2m_ioreq_server pages. +*/ +if ( log_global &&read_atomic (&p2m->ioreq.entry_count) ) +return -EBUSY ; +/* turn on PG_log_dirty bit in paging mode */ paging_lock (d); d->arch.paging.mode |= PG_log_dirty;
xen/arch/x86/mm/p2m-ept.c +49 -26
106 lines not on this page · raw message
xen/arch/x86/mm/p2m-pt.c +41 -21
136 lines not on this page · raw message
xen/arch/x86/mm/p2m.c +9 -0
@@ -317,6 +317,15 @@ int p2m_set_ioreq_server(struct domain *d,if ( p2m->ioreq.server !=NULL ) goto out; +/* +* It is possible that an ioreq server has just been unmapped, +* released the spin lock, with some p2m_ioreq_server entries +* in p2m table remained. We shall refuse another ioreq server +* mapping request in such case. +*/ +if (read_atomic (&p2m->ioreq.entry_count) ) + goto out; + p2m->ioreq.server = s; p2m->ioreq.flags = flags; }
xen/include/asm-x86/p2m.h +24 -1
@@ -120,7 +120,8 @@ typedef unsigned int p2m_query_t;/* Types that can be subject to bulk transitions. */ #define P2M_CHANGEABLE_TYPES (p2m_to_mask(p2m_ram_rw) \ - | p2m_to_mask(p2m_ram_logdirty) ) + | p2m_to_mask(p2m_ram_logdirty) \ + | p2m_to_mask(p2m_ioreq_server) )#define P2M_POD_TYPES (p2m_to_mask(p2m_populate_on_demand))
@@ -349,6 +350,7 @@ struct p2m_domain {* are to be emulated by an ioreq server. */ unsigned int flags; +unsigned long entry_count; } ioreq; };
@@ -744,6 +746,27 @@ static inline p2m_type_t p2m_flags_to_type(unsigned long flags)return (flags >>12 ) &0x7f ; } +static inline p2m_type_t p2m_recalc_type_range (bool recalc,p2m_type_t t, +struct p2m_domain *p2m, +unsigned long gfn_start, +unsigned long gfn_end) +{ +if ( !recalc || !p2m_is_changeable (t) ) +return t; + +if ( t == p2m_ioreq_server && p2m->ioreq.server !=NULL ) +return t; + +return p2m_is_logdirty_range (p2m, gfn_start, gfn_end) ? p2m_ram_logdirty + : p2m_ram_rw; +} + +static inline p2m_type_t p2m_recalc_type (bool_t recalc,p2m_type_t t, +struct p2m_domain *p2m,unsigned long gfn) +{ +return p2m_recalc_type_range (recalc, t, p2m, gfn, gfn); +} +int p2m_pt_handle_deferred_changes (uint64_t gpa);/*
Signature · 7 lines
1.9.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Quoted 30 lines
Quoted 1 line
Quoted 1 line · On 07.04.17 at 16:44, <[email protected]> wrote:
After an ioreq server has unmapped, the remaining
p2m_ioreq_serverentries need to be reset back top2m_ram_rw. This patch does this asynchronously with the currentp2m_change_entry_type_global()interface.New field
entry_countis introduced in structp2m_domain, to record the number ofp2m_ioreq_serverp2m page table entries. One nature of these entries is that they only point to 4K sized page frames, because allp2m_ioreq_serverentries are originated fromp2m_ram_rwones inp2m_change_type_one(). We do not need to worry about the counting for 2M/1G sized pages.This patch disallows mapping of an ioreq server, when there's still
p2m_ioreq_serverentry left, in case another mapping occurs right after the current one being unmapped, releases its lock, with p2m table not synced yet.This patch also disallows live migration, when there's remaining
p2m_ioreq_serverentry in p2m table. The core reason is our current implementation ofp2m_change_entry_type_global()lacks information to resyncp2m_ioreq_serverentries correctly ifglobal_logdirtyis on.We still need to handle other recalculations, however; which means that when doing a recalculation, if the current type is
p2m_ioreq_server, we check to see ifp2m->ioreq.serveris valid or not. If it is, we leave it as typep2m_ioreq_server; if not, we reset it top2m_ramas appropriate.
Quoted 6 lines
To avoid code duplication, lift
recalc_type()out ofp2m-pt.cand use it for all type recalculations (both inp2m-pt.candp2m-ept.c).Signed-off-by Yu Zhang <[email protected]>Signed-off-by George Dunlap <[email protected]>Reviewed-by Paul Durrant <[email protected]>
with two (cosmetic) remarks (may be addressed while committing):
Quoted 10 lines
xen/arch/x86/mm/p2m-ept.c +3
-2@@ -542,10 +544,17 @@ static int resolve_misconfig(struct p2m_domain *p2m, unsigned long gfn)_mfn (e.mfn),0 , &ipat, e.sa_p2mt == p2m_mmio_direct); e.ipat = ipat; -if ( e.recalc &&p2m_is_changeable (e.sa_p2mt) ) + + nt =p2m_recalc_type (e.recalc, e.sa_p2mt, p2m, gfn + i); +if ( nt != e.sa_p2mt ) { - e.sa_p2mt =p2m_is_logdirty_range (p2m, gfn + i, gfn + i)
xen/arch/x86/mm/p2m-ept.c static int resolve_misconfig(struct p2m_domain *p2m, unsigned long gfn) · line 559
Quoted 10 lines
xen/arch/x86/mm/p2m-ept.c +7
-1- ? p2m_ram_logdirty : p2m_ram_rw; +if ( e.sa_p2mt == p2m_ioreq_server ) + { +ASSERT (p2m->ioreq.entry_count >0 ); + p2m->ioreq.entry_count--; + } + + e.sa_p2mt = nt;ept_p2m_type_to_flags (p2m, &e, e.sa_p2mt, e.access); }
Indentation in that scope is till wrong (and hence the badness is being extended).
xen/include/asm-x86/p2m.h static inline p2m_type_t p2m_flags_to_type(unsigned long flags) · line 749
Quoted 5 lines
xen/include/asm-x86/p2m.h +1
-0@@ -744,6 +746,27 @@ static inline p2m_type_t p2m_flags_to_type(unsigned long flags)return (flags >>12 ) &0x7f ; } +static inline p2m_type_t p2m_recalc_type_range(bool recalc, p2m_type_t t,
While this is bool now, ...
Quoted 5 lines
xen/include/asm-x86/p2m.h +5
-0+struct p2m_domain *p2m, + unsigned long gfn_start, + unsigned long gfn_end) +{ + if ( !recalc || !p2m_is_changeable(t) )
xen/include/asm-x86/p2m.h static inline p2m_type_t p2m_flags_to_type(unsigned long flags) · line 764
Quoted 10 lines
xen/include/asm-x86/p2m.h +10
-0+return t; + +if ( t == p2m_ioreq_server && p2m->ioreq.server !=NULL ) +return t; + +return p2m_is_logdirty_range (p2m, gfn_start, gfn_end) ? p2m_ram_logdirty + : p2m_ram_rw; +} + +static inline p2m_type_t p2m_recalc_type(bool_t recalc, p2m_type_t t,
... this one still isn't.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel