From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Jan Beulich" Subject: [PATCH 09/11] x86: properly use map_domain_page() in miscellaneous places Date: Tue, 22 Jan 2013 10:56:37 +0000 Message-ID: <50FE7E7502000078000B834D@nat28.tlf.novell.com> References: <50FE7BF502000078000B82F8@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartC3F26075.0__=" Return-path: In-Reply-To: <50FE7BF502000078000B82F8@nat28.tlf.novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel 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. --=__PartC3F26075.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Signed-off-by: Jan Beulich --- a/xen/arch/x86/domctl.c +++ b/xen/arch/x86/domctl.c @@ -150,7 +150,7 @@ long arch_do_domctl( ret =3D -ENOMEM; break; } - arr =3D page_to_virt(page); + arr =3D __map_domain_page(page); =20 for ( n =3D ret =3D 0; n < num; ) { @@ -220,7 +220,9 @@ long arch_do_domctl( n +=3D k; } =20 - free_domheap_page(virt_to_page(arr)); + page =3D mfn_to_page(domain_page_map_to_mfn(arr)); + unmap_domain_page(arr); + free_domheap_page(page); =20 break; } @@ -1347,8 +1349,11 @@ void arch_get_info_guest(struct vcpu *v, } else { - l4_pgentry_t *l4e =3D __va(pagetable_get_paddr(v->arch.guest_t= able)); + const l4_pgentry_t *l4e =3D + map_domain_page(pagetable_get_pfn(v->arch.guest_table)); + c.cmp->ctrlreg[3] =3D compat_pfn_to_cr3(l4e_get_pfn(*l4e)); + unmap_domain_page(l4e); =20 /* Merge shadow DR7 bits into real DR7. */ c.cmp->debugreg[7] |=3D c.cmp->debugreg[5]; --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -2538,14 +2538,18 @@ int new_guest_cr3(unsigned long mfn) =20 if ( is_pv_32on64_domain(d) ) { + unsigned long gt_mfn =3D pagetable_get_pfn(curr->arch.guest_table)= ; + l4_pgentry_t *pl4e =3D map_domain_page(gt_mfn); + okay =3D paging_mode_refcounts(d) ? 0 /* Old code was broken, but what should it be? */ : mod_l4_entry( - __va(pagetable_get_paddr(curr->arch.guest_table)), + pl4e, l4e_from_pfn( mfn, (_PAGE_PRESENT|_PAGE_RW|_PAGE_USER|_PAGE_ACCESSED)= ), - pagetable_get_pfn(curr->arch.guest_table), 0, 0, = curr) =3D=3D 0; + gt_mfn, 0, 0, curr) =3D=3D 0; + unmap_domain_page(pl4e); if ( unlikely(!okay) ) { MEM_LOG("Error while installing new compat baseptr %lx", = mfn); --- a/xen/arch/x86/mm/shadow/common.c +++ b/xen/arch/x86/mm/shadow/common.c @@ -3543,6 +3543,9 @@ int shadow_track_dirty_vram(struct domai } else { + unsigned long map_mfn =3D INVALID_MFN; + void *map_sl1p =3D NULL; + /* Iterate over VRAM to track dirty bits. */ for ( i =3D 0; i < nr; i++ ) { mfn_t mfn =3D get_gfn_query_unlocked(d, begin_pfn + i, &t); @@ -3576,7 +3579,17 @@ int shadow_track_dirty_vram(struct domai { /* Hopefully the most common case: only one = mapping, * whose dirty bit we can use. */ - l1_pgentry_t *sl1e =3D maddr_to_virt(sl1ma); + l1_pgentry_t *sl1e; + unsigned long sl1mfn =3D paddr_to_pfn(sl1ma); + + if ( sl1mfn !=3D map_mfn ) + { + if ( map_sl1p ) + sh_unmap_domain_page(map_sl1p); + map_sl1p =3D sh_map_domain_page(_mfn(sl1mfn));= + map_mfn =3D sl1mfn; + } + sl1e =3D map_sl1p + (sl1ma & ~PAGE_MASK); =20 if ( l1e_get_flags(*sl1e) & _PAGE_DIRTY ) { @@ -3603,6 +3616,9 @@ int shadow_track_dirty_vram(struct domai } } =20 + if ( map_sl1p ) + sh_unmap_domain_page(map_sl1p); + rc =3D -EFAULT; if ( copy_to_guest(dirty_bitmap, dirty_vram->dirty_bitmap, = dirty_size) =3D=3D 0 ) { memset(dirty_vram->dirty_bitmap, 0, dirty_size); --- a/xen/arch/x86/traps.c +++ b/xen/arch/x86/traps.c @@ -2255,7 +2255,11 @@ static int emulate_privileged_op(struct=20 } else { - mfn =3D l4e_get_pfn(*(l4_pgentry_t *)__va(pagetable_get_pa= ddr(v->arch.guest_table))); + l4_pgentry_t *pl4e =3D + map_domain_page(pagetable_get_pfn(v->arch.guest_table)= ); + + mfn =3D l4e_get_pfn(*pl4e); + unmap_domain_page(pl4e); *reg =3D compat_pfn_to_cr3(mfn_to_gmfn( v->domain, mfn)); } --=__PartC3F26075.0__= Content-Type: text/plain; name="x86-map-domain-misc.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-map-domain-misc.patch" x86: properly use map_domain_page() in miscellaneous places=0A=0ASigned-off= -by: Jan Beulich =0A=0A--- a/xen/arch/x86/domctl.c=0A+++= b/xen/arch/x86/domctl.c=0A@@ -150,7 +150,7 @@ long arch_do_domctl(=0A = ret =3D -ENOMEM;=0A break;=0A = }=0A- arr =3D page_to_virt(page);=0A+ arr =3D = __map_domain_page(page);=0A =0A for ( n =3D ret =3D 0; n < = num; )=0A {=0A@@ -220,7 +220,9 @@ long arch_do_domctl(=0A = n +=3D k;=0A }=0A =0A- free_domheap_page(= virt_to_page(arr));=0A+ page =3D mfn_to_page(domain_page_map_to_= mfn(arr));=0A+ unmap_domain_page(arr);=0A+ free_domhe= ap_page(page);=0A =0A break;=0A }=0A@@ -1347,8 = +1349,11 @@ void arch_get_info_guest(struct vcpu *v,=0A }=0A = else=0A {=0A- l4_pgentry_t *l4e =3D __va(pagetable_get= _paddr(v->arch.guest_table));=0A+ const l4_pgentry_t *l4e = =3D=0A+ map_domain_page(pagetable_get_pfn(v->arch.guest_tabl= e));=0A+=0A c.cmp->ctrlreg[3] =3D compat_pfn_to_cr3(l4e_get_pfn= (*l4e));=0A+ unmap_domain_page(l4e);=0A =0A /* = Merge shadow DR7 bits into real DR7. */=0A c.cmp->debugreg[7] = |=3D c.cmp->debugreg[5];=0A--- a/xen/arch/x86/mm.c=0A+++ b/xen/arch/x86/mm.= c=0A@@ -2538,14 +2538,18 @@ int new_guest_cr3(unsigned long mfn)=0A =0A = if ( is_pv_32on64_domain(d) )=0A {=0A+ unsigned long gt_mfn = =3D pagetable_get_pfn(curr->arch.guest_table);=0A+ l4_pgentry_t = *pl4e =3D map_domain_page(gt_mfn);=0A+=0A okay =3D paging_mode_refc= ounts(d)=0A ? 0 /* Old code was broken, but what should it be? = */=0A : mod_l4_entry(=0A- __va(pagetable_get= _paddr(curr->arch.guest_table)),=0A+ pl4e,=0A = l4e_from_pfn(=0A mfn,=0A = (_PAGE_PRESENT|_PAGE_RW|_PAGE_USER|_PAGE_ACCESSED)),=0A- = pagetable_get_pfn(curr->arch.guest_table), 0, 0, curr) =3D=3D = 0;=0A+ gt_mfn, 0, 0, curr) =3D=3D 0;=0A+ = unmap_domain_page(pl4e);=0A if ( unlikely(!okay) )=0A {=0A = MEM_LOG("Error while installing new compat baseptr %lx", = mfn);=0A--- a/xen/arch/x86/mm/shadow/common.c=0A+++ b/xen/arch/x86/mm/shado= w/common.c=0A@@ -3543,6 +3543,9 @@ int shadow_track_dirty_vram(struct = domai=0A }=0A else=0A {=0A+ unsigned long map_mfn =3D = INVALID_MFN;=0A+ void *map_sl1p =3D NULL;=0A+=0A /* Iterate = over VRAM to track dirty bits. */=0A for ( i =3D 0; i < nr; i++ ) = {=0A mfn_t mfn =3D get_gfn_query_unlocked(d, begin_pfn + i, = &t);=0A@@ -3576,7 +3579,17 @@ int shadow_track_dirty_vram(struct domai=0A = {=0A /* Hopefully the most = common case: only one mapping,=0A * whose dirty = bit we can use. */=0A- l1_pgentry_t *sl1e =3D = maddr_to_virt(sl1ma);=0A+ l1_pgentry_t *sl1e;=0A+ = unsigned long sl1mfn =3D paddr_to_pfn(sl1ma);=0A+=0A+ = if ( sl1mfn !=3D map_mfn )=0A+ = {=0A+ if ( map_sl1p )=0A+ = sh_unmap_domain_page(map_sl1p);=0A+ = map_sl1p =3D sh_map_domain_page(_mfn(sl1mfn));=0A+ = map_mfn =3D sl1mfn;=0A+ }=0A+ = sl1e =3D map_sl1p + (sl1ma & ~PAGE_MASK);=0A =0A = if ( l1e_get_flags(*sl1e) & _PAGE_DIRTY )=0A = {=0A@@ -3603,6 +3616,9 @@ int shadow_track_dirty_vram(struct domai=0A = }=0A }=0A =0A+ if ( map_sl1p )=0A+ = sh_unmap_domain_page(map_sl1p);=0A+=0A rc =3D -EFAULT;=0A = if ( copy_to_guest(dirty_bitmap, dirty_vram->dirty_bitmap, dirty_size) = =3D=3D 0 ) {=0A memset(dirty_vram->dirty_bitmap, 0, dirty_size)= ;=0A--- a/xen/arch/x86/traps.c=0A+++ b/xen/arch/x86/traps.c=0A@@ -2255,7 = +2255,11 @@ static int emulate_privileged_op(struct =0A }=0A = else=0A {=0A- mfn =3D l4e_get_pfn(*(l4= _pgentry_t *)__va(pagetable_get_paddr(v->arch.guest_table)));=0A+ = l4_pgentry_t *pl4e =3D=0A+ map_domain_page(pagetab= le_get_pfn(v->arch.guest_table));=0A+=0A+ mfn =3D l4e_get_pf= n(*pl4e);=0A+ unmap_domain_page(pl4e);=0A = *reg =3D compat_pfn_to_cr3(mfn_to_gmfn(=0A v->domain, = mfn));=0A }=0A --=__PartC3F26075.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.xen.org http://lists.xen.org/xen-devel --=__PartC3F26075.0__=--