From: "Jan Beulich" Subject: [PATCH 5/5] x86: make mod_l2_entry() return a proper error code Date: Wed, 09 Mar 2011 10:58:48 +0000 Message-ID: <4D776B78020000780003576C@vpn.id2.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part775B4078.0__=" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: "xen-devel@lists.xensource.com" List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part775B4078.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline ... so that finally all mod_lN_entry() functions behave identically, allowing some cleanup in do_mmu_update() (which no longer needs to track both an okay status and an error code). Signed-off-by: Jan Beulich --- 2011-03-09.orig/xen/arch/x86/mm.c +++ 2011-03-09/xen/arch/x86/mm.c @@ -1845,16 +1845,16 @@ static int mod_l2_entry(l2_pgentry_t *pl struct domain *d =3D vcpu->domain; struct page_info *l2pg =3D mfn_to_page(pfn); unsigned long type =3D l2pg->u.inuse.type_info; - int rc =3D 1; + int rc =3D 0; =20 if ( unlikely(!is_guest_l2_slot(d, type, pgentry_ptr_to_slot(pl2e))) = ) { MEM_LOG("Illegal L2 update attempt in Xen-private area %p", = pl2e); - return 0; + return -EPERM; } =20 if ( unlikely(__copy_from_user(&ol2e, pl2e, sizeof(ol2e)) !=3D 0) ) - return 0; + return -EFAULT; =20 if ( l2e_get_flags(nl2e) & _PAGE_PRESENT ) { @@ -1862,32 +1862,33 @@ static int mod_l2_entry(l2_pgentry_t *pl { MEM_LOG("Bad L2 flags %x", l2e_get_flags(nl2e) & L2_DISALLOW_MASK); - return 0; + return -EINVAL; } =20 /* Fast path for identical mapping and presence. */ if ( !l2e_has_changed(ol2e, nl2e, _PAGE_PRESENT) ) { adjust_guest_l2e(nl2e, d); - rc =3D UPDATE_ENTRY(l2, pl2e, ol2e, nl2e, pfn, vcpu, = preserve_ad); - return rc; + if ( UPDATE_ENTRY(l2, pl2e, ol2e, nl2e, pfn, vcpu, preserve_ad= ) ) + return 0; + return -EBUSY; } =20 - if ( unlikely(get_page_from_l2e(nl2e, pfn, d) < 0) ) - return 0; + if ( unlikely((rc =3D get_page_from_l2e(nl2e, pfn, d)) < 0) ) + return rc; =20 adjust_guest_l2e(nl2e, d); if ( unlikely(!UPDATE_ENTRY(l2, pl2e, ol2e, nl2e, pfn, vcpu, preserve_ad)) ) { ol2e =3D nl2e; - rc =3D 0; + rc =3D -EBUSY; } } else if ( unlikely(!UPDATE_ENTRY(l2, pl2e, ol2e, nl2e, pfn, vcpu, preserve_ad)) ) { - return 0; + return -EBUSY; } =20 put_page_from_l2e(ol2e, pfn); @@ -3367,7 +3368,7 @@ int do_mmu_update( void *va; unsigned long gpfn, gmfn, mfn; struct page_info *page; - int rc =3D 0, okay =3D 1, i =3D 0; + int rc =3D 0, i =3D 0; unsigned int cmd, done =3D 0, pt_dom; struct vcpu *v =3D current; struct domain *d =3D v->domain, *pt_owner =3D d, *pg_owner; @@ -3434,7 +3435,6 @@ int do_mmu_update( } =20 cmd =3D req.ptr & (sizeof(l1_pgentry_t)-1); - okay =3D 0; =20 switch ( cmd ) { @@ -3451,6 +3451,7 @@ int do_mmu_update( rc =3D xsm_mmu_normal_update(d, pg_owner, req.val); if ( rc ) break; + rc =3D -EINVAL; =20 req.ptr -=3D cmd; gmfn =3D req.ptr >> PAGE_SHIFT; @@ -3521,7 +3522,6 @@ int do_mmu_update( rc =3D mod_l1_entry(va, l1e, mfn, cmd =3D=3D MMU_PT_UPDATE_PRESERVE_AD= , v, pg_owner); - okay =3D !rc; } break; case PGT_l2_page_table: @@ -3545,13 +3545,12 @@ int do_mmu_update( else if ( p2m_ram_shared =3D=3D l2e_p2mt ) { MEM_LOG("Unexpected attempt to map shared = page.\n"); - rc =3D -EINVAL; break; } =20 =20 - okay =3D mod_l2_entry(va, l2e, mfn, - cmd =3D=3D MMU_PT_UPDATE_PRESERVE_= AD, v); + rc =3D mod_l2_entry(va, l2e, mfn, + cmd =3D=3D MMU_PT_UPDATE_PRESERVE_AD= , v); } break; case PGT_l3_page_table: @@ -3575,13 +3574,11 @@ int do_mmu_update( else if ( p2m_ram_shared =3D=3D l3e_p2mt ) { MEM_LOG("Unexpected attempt to map shared = page.\n"); - rc =3D -EINVAL; break; } =20 rc =3D mod_l3_entry(va, l3e, mfn, cmd =3D=3D MMU_PT_UPDATE_PRESERVE_AD= , 1, v); - okay =3D !rc; } break; #if CONFIG_PAGING_LEVELS >=3D 4 @@ -3607,20 +3604,18 @@ int do_mmu_update( else if ( p2m_ram_shared =3D=3D l4e_p2mt ) { MEM_LOG("Unexpected attempt to map shared = page.\n"); - rc =3D -EINVAL; break; } =20 rc =3D mod_l4_entry(va, l4e, mfn, cmd =3D=3D MMU_PT_UPDATE_PRESERVE_AD= , 1, v); - okay =3D !rc; } break; #endif case PGT_writable_page: perfc_incr(writable_mmu_updates); - okay =3D paging_write_guest_entry( - v, va, req.val, _mfn(mfn)); + if ( paging_write_guest_entry(v, va, req.val, = _mfn(mfn)) ) + rc =3D 0; break; } page_unlock(page); @@ -3630,8 +3625,8 @@ int do_mmu_update( else if ( get_page_type(page, PGT_writable_page) ) { perfc_incr(writable_mmu_updates); - okay =3D paging_write_guest_entry( - v, va, req.val, _mfn(mfn)); + if ( paging_write_guest_entry(v, va, req.val, _mfn(mfn)) = ) + rc =3D 0; put_page_type(page); } =20 @@ -3652,17 +3647,18 @@ int do_mmu_update( if ( unlikely(!get_page_from_pagenr(mfn, pg_owner)) ) { MEM_LOG("Could not get page for mach->phys update"); + rc =3D -EINVAL; break; } =20 if ( unlikely(paging_mode_translate(pg_owner)) ) { MEM_LOG("Mach-phys update on auto-translate guest"); + rc =3D -EINVAL; break; } =20 set_gpfn_from_mfn(mfn, gpfn); - okay =3D 1; =20 paging_mark_dirty(pg_owner, mfn); =20 @@ -3672,15 +3668,11 @@ int do_mmu_update( default: MEM_LOG("Invalid page update command %x", cmd); rc =3D -ENOSYS; - okay =3D 0; break; } =20 - if ( unlikely(!okay) ) - { - rc =3D rc ? rc : -EINVAL; + if ( unlikely(rc) ) break; - } =20 guest_handle_add_offset(ureqs, 1); } --=__Part775B4078.0__= Content-Type: text/plain; name="x86-mod_l2_entry-retcode.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-mod_l2_entry-retcode.patch" ... so that finally all mod_lN_entry() functions behave identically,=0Aallo= wing some cleanup in do_mmu_update() (which no longer needs to=0Atrack = both an okay status and an error code).=0A=0ASigned-off-by: Jan Beulich = =0A=0A--- 2011-03-09.orig/xen/arch/x86/mm.c=0A+++ = 2011-03-09/xen/arch/x86/mm.c=0A@@ -1845,16 +1845,16 @@ static int = mod_l2_entry(l2_pgentry_t *pl=0A struct domain *d =3D vcpu->domain;=0A = struct page_info *l2pg =3D mfn_to_page(pfn);=0A unsigned long type = =3D l2pg->u.inuse.type_info;=0A- int rc =3D 1;=0A+ int rc =3D 0;=0A = =0A if ( unlikely(!is_guest_l2_slot(d, type, pgentry_ptr_to_slot(pl2e))= ) )=0A {=0A MEM_LOG("Illegal L2 update attempt in Xen-private = area %p", pl2e);=0A- return 0;=0A+ return -EPERM;=0A = }=0A =0A if ( unlikely(__copy_from_user(&ol2e, pl2e, sizeof(ol2e)) = !=3D 0) )=0A- return 0;=0A+ return -EFAULT;=0A =0A if ( = l2e_get_flags(nl2e) & _PAGE_PRESENT )=0A {=0A@@ -1862,32 +1862,33 @@ = static int mod_l2_entry(l2_pgentry_t *pl=0A {=0A = MEM_LOG("Bad L2 flags %x",=0A l2e_get_flags(nl2e) & = L2_DISALLOW_MASK);=0A- return 0;=0A+ return = -EINVAL;=0A }=0A =0A /* Fast path for identical mapping = and presence. */=0A if ( !l2e_has_changed(ol2e, nl2e, _PAGE_PRESENT= ) )=0A {=0A adjust_guest_l2e(nl2e, d);=0A- = rc =3D UPDATE_ENTRY(l2, pl2e, ol2e, nl2e, pfn, vcpu, preserve_ad);=0A- = return rc;=0A+ if ( UPDATE_ENTRY(l2, pl2e, ol2e, nl2e, = pfn, vcpu, preserve_ad) )=0A+ return 0;=0A+ = return -EBUSY;=0A }=0A =0A- if ( unlikely(get_page_from_l2e(= nl2e, pfn, d) < 0) )=0A- return 0;=0A+ if ( unlikely((rc = =3D get_page_from_l2e(nl2e, pfn, d)) < 0) )=0A+ return rc;=0A = =0A adjust_guest_l2e(nl2e, d);=0A if ( unlikely(!UPDATE_ENT= RY(l2, pl2e, ol2e, nl2e, pfn, vcpu,=0A = preserve_ad)) )=0A {=0A ol2e =3D nl2e;=0A- = rc =3D 0;=0A+ rc =3D -EBUSY;=0A }=0A }=0A else = if ( unlikely(!UPDATE_ENTRY(l2, pl2e, ol2e, nl2e, pfn, vcpu,=0A = preserve_ad)) )=0A {=0A- return = 0;=0A+ return -EBUSY;=0A }=0A =0A put_page_from_l2e(ol2e, = pfn);=0A@@ -3367,7 +3368,7 @@ int do_mmu_update(=0A void *va;=0A = unsigned long gpfn, gmfn, mfn;=0A struct page_info *page;=0A- int = rc =3D 0, okay =3D 1, i =3D 0;=0A+ int rc =3D 0, i =3D 0;=0A = unsigned int cmd, done =3D 0, pt_dom;=0A struct vcpu *v =3D current;=0A= struct domain *d =3D v->domain, *pt_owner =3D d, *pg_owner;=0A@@ = -3434,7 +3435,6 @@ int do_mmu_update(=0A }=0A =0A cmd =3D = req.ptr & (sizeof(l1_pgentry_t)-1);=0A- okay =3D 0;=0A =0A = switch ( cmd )=0A {=0A@@ -3451,6 +3451,7 @@ int do_mmu_update(=0A = rc =3D xsm_mmu_normal_update(d, pg_owner, req.val);=0A = if ( rc )=0A break;=0A+ rc =3D -EINVAL;=0A = =0A req.ptr -=3D cmd;=0A gmfn =3D req.ptr >> = PAGE_SHIFT;=0A@@ -3521,7 +3522,6 @@ int do_mmu_update(=0A = rc =3D mod_l1_entry(va, l1e, mfn,=0A = cmd =3D=3D MMU_PT_UPDATE_PRESERVE_AD, v,=0A = pg_owner);=0A- okay =3D !rc;=0A = }=0A break;=0A case PGT_l2_page_table:=0A= @@ -3545,13 +3545,12 @@ int do_mmu_update(=0A else if = ( p2m_ram_shared =3D=3D l2e_p2mt )=0A {=0A = MEM_LOG("Unexpected attempt to map shared page.\n");=0A- = rc =3D -EINVAL;=0A break;=0A = }=0A =0A =0A- okay =3D mod_l2_entry(va, = l2e, mfn,=0A- cmd =3D=3D MMU_PT_UPDA= TE_PRESERVE_AD, v);=0A+ rc =3D mod_l2_entry(va, l2e, = mfn,=0A+ cmd =3D=3D MMU_PT_UPDATE_PRES= ERVE_AD, v);=0A }=0A break;=0A = case PGT_l3_page_table:=0A@@ -3575,13 +3574,11 @@ int do_mmu_update(=0A= else if ( p2m_ram_shared =3D=3D l3e_p2mt )=0A = {=0A MEM_LOG("Unexpected attempt to = map shared page.\n");=0A- rc =3D -EINVAL;=0A = break;=0A }=0A =0A = rc =3D mod_l3_entry(va, l3e, mfn,=0A = cmd =3D=3D MMU_PT_UPDATE_PRESERVE_AD, 1, v);=0A- okay = =3D !rc;=0A }=0A break;=0A #if CONFIG_PAGIN= G_LEVELS >=3D 4=0A@@ -3607,20 +3604,18 @@ int do_mmu_update(=0A = else if ( p2m_ram_shared =3D=3D l4e_p2mt )=0A = {=0A MEM_LOG("Unexpected attempt to map shared = page.\n");=0A- rc =3D -EINVAL;=0A = break;=0A }=0A =0A rc =3D = mod_l4_entry(va, l4e, mfn,=0A cmd = =3D=3D MMU_PT_UPDATE_PRESERVE_AD, 1, v);=0A- okay =3D = !rc;=0A }=0A break;=0A #endif=0A = case PGT_writable_page:=0A perfc_incr(writable_mm= u_updates);=0A- okay =3D paging_write_guest_entry(=0A- = v, va, req.val, _mfn(mfn));=0A+ = if ( paging_write_guest_entry(v, va, req.val, _mfn(mfn)) )=0A+ = rc =3D 0;=0A break;=0A }=0A = page_unlock(page);=0A@@ -3630,8 +3625,8 @@ int do_mmu_updat= e(=0A else if ( get_page_type(page, PGT_writable_page) )=0A = {=0A perfc_incr(writable_mmu_updates);=0A- = okay =3D paging_write_guest_entry(=0A- v, va, = req.val, _mfn(mfn));=0A+ if ( paging_write_guest_entry(v, = va, req.val, _mfn(mfn)) )=0A+ rc =3D 0;=0A = put_page_type(page);=0A }=0A =0A@@ -3652,17 +3647,18 @@ int = do_mmu_update(=0A if ( unlikely(!get_page_from_pagenr(mfn, = pg_owner)) )=0A {=0A MEM_LOG("Could not get = page for mach->phys update");=0A+ rc =3D -EINVAL;=0A = break;=0A }=0A =0A if ( unlikely(paging_mo= de_translate(pg_owner)) )=0A {=0A MEM_LOG("Mach= -phys update on auto-translate guest");=0A+ rc =3D = -EINVAL;=0A break;=0A }=0A =0A = set_gpfn_from_mfn(mfn, gpfn);=0A- okay =3D 1;=0A =0A = paging_mark_dirty(pg_owner, mfn);=0A =0A@@ -3672,15 +3668,11 @@ int = do_mmu_update(=0A default:=0A MEM_LOG("Invalid page = update command %x", cmd);=0A rc =3D -ENOSYS;=0A- = okay =3D 0;=0A break;=0A }=0A =0A- if ( = unlikely(!okay) )=0A- {=0A- rc =3D rc ? rc : -EINVAL;=0A+= if ( unlikely(rc) )=0A break;=0A- }=0A =0A = guest_handle_add_offset(ureqs, 1);=0A }=0A --=__Part775B4078.0__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --=__Part775B4078.0__=--