xenpaging: handle evict failures
PATCH 1/1 xenpaging: handle evict failures
# HG changeset patch
# User Olaf Hering <[email protected]>
# Date 1318336551 -7200
# Node ID bdd49540f1e1c803d01c88adb67c6ce01e2d00d8 # Parent 4b0907c6a08c348962bd976c2976257b412408be
xenpaging: handle evict failures
Evict of a nominated gfn must fail if some other process mapped the page without checking the p2mt of that gfn first.
Add a check to cancel eviction if the page usage count is not 1.
Handle the possible eviction failure in the page-in paths. After nominate and before evict, something may check the p2mt and call populate. Handle this case and let the gfn enter the page-in path. The gfn may still be connected to a mfn, so there is no need to allocate a new page in prep.
Adjust do_mmu_update to return -ENOENT only if the gfn has entered the page-in path and if it is not yet connected to a mfn. Otherwise linux_privcmd_map_foreign_bulk() may loop forever.
Add MEM_EVENT_FLAG_EVICT_FAIL to inform pager that a page-in request for a possible not-evicted page was sent. xenpaging does currently not need that flag because failure to evict a gfn will be caught.
tools/xenpaging/xenpaging.c +6 -4
@@ -734,10 +734,12 @@ int main(int argc, char *argv[]) }else { -DPRINTF ("page already populated (domain = %d; vcpu = %d;" -" gfn = %" PRIx64"; paused = %d)\n" , - paging->mem_event.domain_id, req.vcpu_id, - req.gfn, req.flags &MEM_EVENT_FLAG_VCPU_PAUSED ); +DPRINTF ("page %s populated (domain = %d; vcpu = %d;" +" gfn = %" PRIx64"; paused = %d; evict_fail = %d)\n" , + req.flags &MEM_EVENT_FLAG_EVICT_FAIL ?"not" :"already" , + paging->mem_event.domain_id, req.vcpu_id, req.gfn, + !!(req.flags &MEM_EVENT_FLAG_VCPU_PAUSED ) , + !!(req.flags &MEM_EVENT_FLAG_EVICT_FAIL ) );/* Tell Xen to resume the vcpu */ /* XXX: Maybe just check if the vcpu was paused? */
xen/arch/x86/mm.c +4 -4
@@ -3532,7 +3532,7 @@ int do_mmu_update( rc = -ENOENT ;break ; } -else if ( p2m_ram_paging_in_start == l1e_p2mt ) +else if ( p2m_ram_paging_in_start == l1e_p2mt && !mfn_valid (mfn) ) { rc = -ENOENT ;break ;
@@ -3572,7 +3572,7 @@ int do_mmu_update( rc = -ENOENT ;break ; } -else if ( p2m_ram_paging_in_start == l2e_p2mt ) +else if ( p2m_ram_paging_in_start == l2e_p2mt && !mfn_valid (mfn) ) { rc = -ENOENT ;break ;
@@ -3600,7 +3600,7 @@ int do_mmu_update( rc = -ENOENT ;break ; } -else if ( p2m_ram_paging_in_start == l3e_p2mt ) +else if ( p2m_ram_paging_in_start == l3e_p2mt && !mfn_valid (mfn) ) { rc = -ENOENT ;break ;
@@ -3628,7 +3628,7 @@ int do_mmu_update( rc = -ENOENT ;break ; } -else if ( p2m_ram_paging_in_start == l4e_p2mt ) +else if ( p2m_ram_paging_in_start == l4e_p2mt && !mfn_valid (mfn) ) { rc = -ENOENT ;break ;
xen/arch/x86/mm/p2m.c +39 -17
115 lines not on this page · raw message
xen/include/public/mem_event.h +1 -0
@@ -38,6 +38,7 @@/* Memory event flags */ #define MEM_EVENT_FLAG_VCPU_PAUSED (1 << 0)#define MEM_EVENT_FLAG_DROP_PAGE (1 << 1) +#define MEM_EVENT_FLAG_EVICT_FAIL (1 << 2)/* Reasons for the memory event request */ #define MEM_EVENT_REASON_UNKNOWN 0/* typical reason */
Quoted 16 lines · Olaf Hering
xenpaging: handle evict failures
Evict of a nominated gfn must fail if some other process mapped the page without checking the p2mt of that gfn first.
Add a check to cancel eviction if the page usage count is not 1.Handle the possible eviction failure in the page-in paths. After nominate and before evict, something may check the p2mt and call populate. Handle this case and let the gfn enter the page-in path. The gfn may still be connected to a mfn, so there is no need to allocate a new page in prep.
Adjust
do_mmu_updateto return-ENOENTonly if the gfn has entered the page-in path and if it is not yet connected to a mfn. Otherwiselinux_privcmd_map_foreign_bulk()may loop forever.
Quoted 5 lines
Add
MEM_EVENT_FLAG_EVICT_FAILto inform pager that a page-in request for a possible not-evicted page was sent. xenpaging does currently not need that flag because failure to evict a gfn will be caught.Signed-off-by Olaf Hering <[email protected]>
This doesn't completely close off that race condition (that will require the p2m refcounting that's being discussed in another thread) but it's a big improvement so I've applied it.
Cheers,
Tim.