From: "Jan Beulich" Subject: [PATCH 4/5] x86: make mod_l1_entry() return a proper error code Date: Wed, 09 Mar 2011 10:57:39 +0000 Message-ID: <4D776B330200007800035768@vpn.id2.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part3C100B33.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. --=__Part3C100B33.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline ... again is so that the guest can actually know the reason for the (hypercall) failure. Signed-off-by: Jan Beulich --- 2011-03-09.orig/xen/arch/x86/mm.c +++ 2011-03-09/xen/arch/x86/mm.c @@ -1765,15 +1765,16 @@ static int mod_l1_entry(l1_pgentry_t *pl struct domain *pt_dom =3D pt_vcpu->domain; unsigned long mfn; p2m_type_t p2mt; - int rc =3D 1; + int rc =3D 0; =20 if ( unlikely(__copy_from_user(&ol1e, pl1e, sizeof(ol1e)) !=3D 0) ) - return 0; + return -EFAULT; =20 if ( unlikely(paging_mode_refcounts(pt_dom)) ) { - rc =3D UPDATE_ENTRY(l1, pl1e, ol1e, nl1e, gl1mfn, pt_vcpu, = preserve_ad); - return rc; + if ( UPDATE_ENTRY(l1, pl1e, ol1e, nl1e, gl1mfn, pt_vcpu, = preserve_ad) ) + return 0; + return -EBUSY; } =20 if ( l1e_get_flags(nl1e) & _PAGE_PRESENT ) @@ -1782,7 +1783,7 @@ static int mod_l1_entry(l1_pgentry_t *pl mfn =3D mfn_x(gfn_to_mfn(p2m_get_hostp2m(pg_dom), l1e_get_pfn(nl1e), &p2mt)); if ( !p2m_is_ram(p2mt) || unlikely(mfn =3D=3D INVALID_MFN) ) - return 0; + return -EINVAL; ASSERT((mfn & ~(PADDR_MASK >> PAGE_SHIFT)) =3D=3D 0); nl1e =3D l1e_from_pfn(mfn, l1e_get_flags(nl1e)); =20 @@ -1790,22 +1791,23 @@ static int mod_l1_entry(l1_pgentry_t *pl { MEM_LOG("Bad L1 flags %x", l1e_get_flags(nl1e) & l1_disallow_mask(pt_dom)); - return 0; + return -EINVAL; } =20 /* Fast path for identical mapping, r/w and presence. */ if ( !l1e_has_changed(ol1e, nl1e, _PAGE_RW | _PAGE_PRESENT) ) { adjust_guest_l1e(nl1e, pt_dom); - rc =3D UPDATE_ENTRY(l1, pl1e, ol1e, nl1e, gl1mfn, pt_vcpu, - preserve_ad); - return rc; + if ( UPDATE_ENTRY(l1, pl1e, ol1e, nl1e, gl1mfn, pt_vcpu, + preserve_ad) ) + return 0; + return -EBUSY; } =20 switch ( rc =3D get_page_from_l1e(nl1e, pt_dom, pg_dom) ) { default: - return 0; + return rc; case 0: break; case 1: @@ -1818,13 +1820,13 @@ static int mod_l1_entry(l1_pgentry_t *pl preserve_ad)) ) { ol1e =3D nl1e; - rc =3D 0; + rc =3D -EBUSY; } } else if ( unlikely(!UPDATE_ENTRY(l1, pl1e, ol1e, nl1e, gl1mfn, = pt_vcpu, preserve_ad)) ) { - return 0; + return -EBUSY; } =20 put_page_from_l1e(ol1e, pt_dom); @@ -3516,9 +3518,10 @@ int do_mmu_update( }=20 #endif =20 - okay =3D mod_l1_entry(va, l1e, mfn, - cmd =3D=3D MMU_PT_UPDATE_PRESERVE_= AD, v, - pg_owner); + 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: @@ -4300,7 +4303,7 @@ static int __do_update_va_mapping( goto out; } =20 - rc =3D mod_l1_entry(pl1e, val, gl1mfn, 0, v, pg_owner) ? 0 : -EINVAL; + rc =3D mod_l1_entry(pl1e, val, gl1mfn, 0, v, pg_owner); =20 page_unlock(gl1pg); put_page(gl1pg); --=__Part3C100B33.0__= Content-Type: text/plain; name="x86-mod_l1_entry-retcode.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-mod_l1_entry-retcode.patch" ... again is so that the guest can actually know the reason for the=0A(hype= rcall) failure.=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= @@ -1765,15 +1765,16 @@ static int mod_l1_entry(l1_pgentry_t *pl=0A = struct domain *pt_dom =3D pt_vcpu->domain;=0A unsigned long mfn;=0A = p2m_type_t p2mt;=0A- int rc =3D 1;=0A+ int rc =3D 0;=0A =0A if = ( unlikely(__copy_from_user(&ol1e, pl1e, sizeof(ol1e)) !=3D 0) )=0A- = return 0;=0A+ return -EFAULT;=0A =0A if ( unlikely(paging_mode_= refcounts(pt_dom)) )=0A {=0A- rc =3D UPDATE_ENTRY(l1, pl1e, = ol1e, nl1e, gl1mfn, pt_vcpu, preserve_ad);=0A- return rc;=0A+ = if ( UPDATE_ENTRY(l1, pl1e, ol1e, nl1e, gl1mfn, pt_vcpu, preserve_ad) = )=0A+ return 0;=0A+ return -EBUSY;=0A }=0A =0A = if ( l1e_get_flags(nl1e) & _PAGE_PRESENT )=0A@@ -1782,7 +1783,7 @@ static = int mod_l1_entry(l1_pgentry_t *pl=0A mfn =3D mfn_x(gfn_to_mfn(p2m_g= et_hostp2m(pg_dom),=0A l1e_get_pfn(nl1e), &p2mt));=0A = if ( !p2m_is_ram(p2mt) || unlikely(mfn =3D=3D INVALID_MFN) )=0A- = return 0;=0A+ return -EINVAL;=0A ASSERT((mfn & = ~(PADDR_MASK >> PAGE_SHIFT)) =3D=3D 0);=0A nl1e =3D l1e_from_pfn(mf= n, l1e_get_flags(nl1e));=0A =0A@@ -1790,22 +1791,23 @@ static int = mod_l1_entry(l1_pgentry_t *pl=0A {=0A MEM_LOG("Bad L1 = flags %x",=0A l1e_get_flags(nl1e) & l1_disallow_mask(pt= _dom));=0A- return 0;=0A+ return -EINVAL;=0A = }=0A =0A /* Fast path for identical mapping, r/w and presence. = */=0A if ( !l1e_has_changed(ol1e, nl1e, _PAGE_RW | _PAGE_PRESENT) = )=0A {=0A adjust_guest_l1e(nl1e, pt_dom);=0A- = rc =3D UPDATE_ENTRY(l1, pl1e, ol1e, nl1e, gl1mfn, pt_vcpu,=0A- = preserve_ad);=0A- return rc;=0A+ = if ( UPDATE_ENTRY(l1, pl1e, ol1e, nl1e, gl1mfn, pt_vcpu,=0A+ = preserve_ad) )=0A+ return 0;=0A+ = return -EBUSY;=0A }=0A =0A switch ( rc =3D get_page_from_l1= e(nl1e, pt_dom, pg_dom) )=0A {=0A default:=0A- = return 0;=0A+ return rc;=0A case 0:=0A = break;=0A case 1:=0A@@ -1818,13 +1820,13 @@ static int mod_l1_entry= (l1_pgentry_t *pl=0A preserve_ad)) = )=0A {=0A ol1e =3D nl1e;=0A- rc =3D 0;=0A+ = rc =3D -EBUSY;=0A }=0A }=0A else if ( unlikely(!U= PDATE_ENTRY(l1, pl1e, ol1e, nl1e, gl1mfn, pt_vcpu,=0A = preserve_ad)) )=0A {=0A- return 0;=0A+ = return -EBUSY;=0A }=0A =0A put_page_from_l1e(ol1e, pt_dom);=0A@@ = -3516,9 +3518,10 @@ int do_mmu_update(=0A } =0A = #endif=0A =0A- okay =3D mod_l1_entry(va, l1e, mfn,=0A- = cmd =3D=3D MMU_PT_UPDATE_PRESERVE_AD,= v,=0A- pg_owner);=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@@ -4300,7 +4303,7 @@ static int __do_update_va_mapping(=0A = goto out;=0A }=0A =0A- rc =3D mod_l1_entry(pl1e, val, gl1mfn, 0, v, = pg_owner) ? 0 : -EINVAL;=0A+ rc =3D mod_l1_entry(pl1e, val, gl1mfn, 0, = v, pg_owner);=0A =0A page_unlock(gl1pg);=0A put_page(gl1pg);=0A --=__Part3C100B33.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 --=__Part3C100B33.0__=--