x86/P2M: pass on errors from p2m_set_entry()
PATCH 1/1 x86/P2M: pass on errors from p2m_set_entry()
... at least in a couple of straightforward cases.
xen/arch/x86/mm/p2m.c +13 -16
@@ -501,7 +501,7 @@ void p2m_final_teardown(struct domain *d } -static void +static int p2m_remove_page (struct p2m_domain *p2m,unsigned long gfn,unsigned long mfn,unsigned int page_order) {
@@ -515,7 +515,7 @@ p2m_remove_page(struct p2m_domain *p2m,if (need_iommu (p2m->domain) )for ( i =0 ; i < (1 << page_order); i++ )iommu_unmap_page (p2m->domain, mfn + i); -return ; +return 0 ; }ASSERT (gfn_locked_by_me (p2m, gfn));
@@ -531,8 +531,8 @@ p2m_remove_page(struct p2m_domain *p2m,ASSERT ( !p2m_is_valid (t) || mfn + i ==mfn_x (mfn_return) ); } } -p2m_set_entry (p2m, gfn,_mfn (INVALID_MFN ), page_order, p2m_invalid, - p2m->default_access); +return p2m_set_entry (p2m, gfn,_mfn (INVALID_MFN ), page_order, p2m_invalid, + p2m->default_access); }void
@@ -719,8 +719,9 @@ p2m_type_t p2m_change_type(struct domaingfn_lock (p2m, gfn,0 ); mfn = p2m->get_entry (p2m, gfn, &pt, &a,0 ,NULL ); -if ( pt == ot ) -p2m_set_entry (p2m, gfn, mfn,PAGE_ORDER_4K , nt, p2m->default_access); +if ( pt == ot && +p2m_set_entry (p2m, gfn, mfn,PAGE_ORDER_4K , nt, p2m->default_access) ) + pt = p2m_invalid;gfn_unlock (p2m, gfn,0 );
@@ -945,8 +946,7 @@ int p2m_mem_paging_nominate(struct domai goto out;/* Fix p2m entry */ -p2m_set_entry (p2m, gfn, mfn,PAGE_ORDER_4K , p2m_ram_paging_out, a); - ret =0 ; + ret =p2m_set_entry (p2m, gfn, mfn,PAGE_ORDER_4K , p2m_ram_paging_out, a); out:gfn_unlock (p2m, gfn,0 );
@@ -1010,7 +1010,8 @@ int p2m_mem_paging_evict(struct domain *put_page (page);/* Remove mapping from p2m table */ -p2m_set_entry (p2m, gfn,_mfn (INVALID_MFN ),PAGE_ORDER_4K , p2m_ram_paged, a); + ret =p2m_set_entry (p2m, gfn,_mfn (INVALID_MFN ),PAGE_ORDER_4K , + p2m_ram_paged, a);/* Clear content before returning the page to Xen */ scrub_one_page (page);
@@ -1018,8 +1019,6 @@ int p2m_mem_paging_evict(struct domain */* Track number of paged gfns */ atomic_inc (&d->paged_pages); - ret =0 ; - out_put:/* Put the page back so it gets freed */ put_page (page);
@@ -1219,16 +1218,14 @@ int p2m_mem_paging_prep(struct domain *d/* Make the page already guest-accessible. If the pager still has a * pending resume operation, it will be idempotent p2m entry-wise, * but will unpause the vcpu */ -p2m_set_entry (p2m, gfn, mfn,PAGE_ORDER_4K , -paging_mode_log_dirty (d) ? p2m_ram_logdirty : - p2m_ram_rw, a); + ret =p2m_set_entry (p2m, gfn, mfn,PAGE_ORDER_4K , +paging_mode_log_dirty (d) ? p2m_ram_logdirty + : p2m_ram_rw, a);set_gpfn_from_mfn (mfn_x (mfn), gfn);if ( !page_extant )atomic_dec (&d->paged_pages); - ret =0 ; - out:gfn_unlock (p2m, gfn,0 );return ret;
x86/P2M: pass on errors from p2m_set_entry()
... at least in a couple of straightforward cases.
xen/arch/x86/mm/p2m.c +13 -16
@@ -501,7 +501,7 @@ void p2m_final_teardown(struct domain *d } -static void +static int p2m_remove_page (struct p2m_domain *p2m,unsigned long gfn,unsigned long mfn,unsigned int page_order) {
@@ -515,7 +515,7 @@ p2m_remove_page(struct p2m_domain *p2m,if (need_iommu (p2m->domain) )for ( i =0 ; i < (1 << page_order); i++ )iommu_unmap_page (p2m->domain, mfn + i); -return ; +return 0 ; }ASSERT (gfn_locked_by_me (p2m, gfn));
@@ -531,8 +531,8 @@ p2m_remove_page(struct p2m_domain *p2m,ASSERT ( !p2m_is_valid (t) || mfn + i ==mfn_x (mfn_return) ); } } -p2m_set_entry (p2m, gfn,_mfn (INVALID_MFN ), page_order, p2m_invalid, - p2m->default_access); +return p2m_set_entry (p2m, gfn,_mfn (INVALID_MFN ), page_order, p2m_invalid, + p2m->default_access); }void
@@ -719,8 +719,9 @@ p2m_type_t p2m_change_type(struct domaingfn_lock (p2m, gfn,0 ); mfn = p2m->get_entry (p2m, gfn, &pt, &a,0 ,NULL ); -if ( pt == ot ) -p2m_set_entry (p2m, gfn, mfn,PAGE_ORDER_4K , nt, p2m->default_access); +if ( pt == ot && +p2m_set_entry (p2m, gfn, mfn,PAGE_ORDER_4K , nt, p2m->default_access) ) + pt = p2m_invalid;gfn_unlock (p2m, gfn,0 );
@@ -945,8 +946,7 @@ int p2m_mem_paging_nominate(struct domai goto out;/* Fix p2m entry */ -p2m_set_entry (p2m, gfn, mfn,PAGE_ORDER_4K , p2m_ram_paging_out, a); - ret =0 ; + ret =p2m_set_entry (p2m, gfn, mfn,PAGE_ORDER_4K , p2m_ram_paging_out, a); out:gfn_unlock (p2m, gfn,0 );
@@ -1010,7 +1010,8 @@ int p2m_mem_paging_evict(struct domain *put_page (page);/* Remove mapping from p2m table */ -p2m_set_entry (p2m, gfn,_mfn (INVALID_MFN ),PAGE_ORDER_4K , p2m_ram_paged, a); + ret =p2m_set_entry (p2m, gfn,_mfn (INVALID_MFN ),PAGE_ORDER_4K , + p2m_ram_paged, a);/* Clear content before returning the page to Xen */ scrub_one_page (page);
@@ -1018,8 +1019,6 @@ int p2m_mem_paging_evict(struct domain */* Track number of paged gfns */ atomic_inc (&d->paged_pages); - ret =0 ; - out_put:/* Put the page back so it gets freed */ put_page (page);
@@ -1219,16 +1218,14 @@ int p2m_mem_paging_prep(struct domain *d/* Make the page already guest-accessible. If the pager still has a * pending resume operation, it will be idempotent p2m entry-wise, * but will unpause the vcpu */ -p2m_set_entry (p2m, gfn, mfn,PAGE_ORDER_4K , -paging_mode_log_dirty (d) ? p2m_ram_logdirty : - p2m_ram_rw, a); + ret =p2m_set_entry (p2m, gfn, mfn,PAGE_ORDER_4K , +paging_mode_log_dirty (d) ? p2m_ram_logdirty + : p2m_ram_rw, a);set_gpfn_from_mfn (mfn_x (mfn), gfn);if ( !page_extant )atomic_dec (&d->paged_pages); - ret =0 ; - out:gfn_unlock (p2m, gfn,0 );return ret;
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
xen/arch/x86/mm/p2m.c p2m_type_t p2m_change_type(struct domain · line 724
Quoted 9 lines · Jan Beulich
xen/arch/x86/mm/p2m.c +3
-2@@ -719,8 +719,9 @@ p2m_type_t p2m_change_type(struct domaingfn_lock (p2m, gfn,0 ); mfn = p2m->get_entry (p2m, gfn, &pt, &a,0 ,NULL ); -if ( pt == ot ) -p2m_set_entry (p2m, gfn, mfn,PAGE_ORDER_4K , nt, p2m->default_access); +if ( pt == ot && +p2m_set_entry (p2m, gfn, mfn,PAGE_ORDER_4K , nt, p2m->default_access) ) + pt = p2m_invalid;
While I can see we want to do something on error here, think this is a bit weird. It would be better just to make this function return bool, since every caller just tests the result for ==ot anyway. (Well, the HVMOP_set_mem_type hanlder printks it but I don't think it's that helpful.)
Cheers,
Tim.
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 01.05.14 at 15:02, <[email protected]> wrote:
xen/arch/x86/mm/p2m.c p2m_type_t p2m_change_type(struct domain · line 723
Quoted 8 lines · Jan Beulich
xen/arch/x86/mm/p2m.c +2
-2@@ -719,8 +719,9 @@ p2m_type_t p2m_change_type(struct domaingfn_lock (p2m, gfn,0 ); mfn = p2m->get_entry (p2m, gfn, &pt, &a,0 ,NULL ); -if ( pt == ot ) -p2m_set_entry (p2m, gfn, mfn,PAGE_ORDER_4K , nt, p2m->default_access); +if ( pt == ot && + p2m_set_entry(p2m, gfn, mfn, PAGE_ORDER_4K, nt, p2m->default_access))
Quoted 7 lines
Review p2m_type_t p2m_change_type(struct domain · line 724
Quoted 1 line
(quoted diff) +1
-0+ pt = p2m_invalid;While I can see we want to do something on error here, think this is a bit weird. It would be better just to make this function return bool, since every caller just tests the result for ==ot anyway. (Well, the
HVMOP_set_mem_typehanlder printks it but I don't think it's that helpful.)
I can certainly do that, but wouldn't your return-type-changes concern you (imo validly) had on Mukesh's recent changes then here apply too, i.e. shouldn't we rename the function? (I might have done the rename right away, if only I could see a good replacement name.)
Also, regarding that printk: Now that it would need altering anyway, do you think it's of much as a whole (your comment left open whether you think printing the new type isn't very helpful, or the entire thing)? I.e. shouldn't we rather drop it instead of adjusting it?
Jan
Quoted 19 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 01.05.14 at 15:02, <[email protected]> wrote:
xen/arch/x86/mm/p2m.c p2m_type_t p2m_change_type(struct domain · line 723
Quoted 8 lines · Jan Beulich
xen/arch/x86/mm/p2m.c +2
-2@@ -719,8 +719,9 @@ p2m_type_t p2m_change_type(struct domaingfn_lock (p2m, gfn,0 ); mfn = p2m->get_entry (p2m, gfn, &pt, &a,0 ,NULL ); -if ( pt == ot ) -p2m_set_entry (p2m, gfn, mfn,PAGE_ORDER_4K , nt, p2m->default_access); +if ( pt == ot && + p2m_set_entry(p2m, gfn, mfn, PAGE_ORDER_4K, nt, p2m->default_access))
Quoted 7 lines
Review p2m_type_t p2m_change_type(struct domain · line 724
Quoted 1 line
(quoted diff) +1
-0+ pt = p2m_invalid;While I can see we want to do something on error here, think this is a bit weird. It would be better just to make this function return bool, since every caller just tests the result for ==ot anyway. (Well, the
HVMOP_set_mem_typehanlder printks it but I don't think it's that helpful.)
Quoted 5 lines
I can certainly do that, but wouldn't your return-type-changes concern you (imo validly) had on Mukesh's recent changes then here apply too, i.e. shouldn't we rename the function? (I might have done the rename right away, if only I could see a good replacement name.)
Oh - I had thought that the different return type would make the compile fail but of course the implicit cast bool_t (-> int) -> p2m_type_t works fine. :(
So yes, we should rename it. How about p2m_change_type_one() to contrast with p2m_change_type_range()?
Quoted 5 lines
Also, regarding that printk: Now that it would need altering anyway, do you think it's of much as a whole (your comment left open whether you think printing the new type isn't very helpful, or the entire thing)? I.e. shouldn't we rather drop it instead of adjusting it?
Yes, I think we can drop it, or at least downgrade it from XENLOG_WARNING. The same goes for the p2m_is_grant() printk just above.
Cheers,
Tim.
Quoted 28 lines
Quoted 1 line
Quoted 1 line · On 02.05.14 at 12:32, <[email protected]> wrote:
Quoted 10 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 01.05.14 at 15:02, <[email protected]> wrote:
xen/arch/x86/mm/p2m.c p2m_type_t p2m_change_type(struct domain · line 723
Quoted 8 lines · Jan Beulich
xen/arch/x86/mm/p2m.c +2
-2@@ -719,8 +719,9 @@ p2m_type_t p2m_change_type(struct domaingfn_lock (p2m, gfn,0 ); mfn = p2m->get_entry (p2m, gfn, &pt, &a,0 ,NULL ); -if ( pt == ot ) -p2m_set_entry (p2m, gfn, mfn,PAGE_ORDER_4K , nt, p2m->default_access); +if ( pt == ot && + p2m_set_entry(p2m, gfn, mfn, PAGE_ORDER_4K, nt,
p2m->default_access)Quoted 9 lines
Quoted 8 lines
)
Review p2m_type_t p2m_change_type(struct domain · line 724
Quoted 1 line
(quoted diff) +1
-0+ pt = p2m_invalid;While I can see we want to do something on error here, think this is a bit weird. It would be better just to make this function return bool, since every caller just tests the result for ==ot anyway. (Well, the
HVMOP_set_mem_typehanlder printks it but I don't think it's that helpful.)Quoted 5 lines
I can certainly do that, but wouldn't your return-type-changes concern you (imo validly) had on Mukesh's recent changes then here apply too, i.e. shouldn't we rename the function? (I might have done the rename right away, if only I could see a good replacement name.)
Quoted 6 lines
Oh - I had thought that the different return type would make the compile fail but of course the implicit cast
bool_t(-> int) ->p2m_type_tworks fine. :(So yes, we should rename it. How about
p2m_change_type_one()to contrast withp2m_change_type_range()?
Fine with me. As to the type change, I think it is better to have the function have an actual rc, forwarded from p2m_set_entry() or set to -EBUSY when the type didn't match. That way the different failure modes will be distinguishable at the call sites (eventually useful for debugging as well as a decision towards a retry at the original caller level).
Jan
Quoted 7 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 02.05.14 at 12:32, <[email protected]> wrote:
So yes, we should rename it. How about
p2m_change_type_one()to contrast withp2m_change_type_range()?Fine with me. As to the type change, I think it is better to have the function have an actual rc, forwarded from
p2m_set_entry()or set to-EBUSYwhen the type didn't match.
Yes, good idea.
Tim.