From: "Jan Beulich" Subject: [PATCH 6/6] x86/HAP: prefer is_..._domain() over is_..._vcpu() Date: Thu, 11 Jun 2015 11:24:03 +0100 Message-ID: <55797DE302000078000838CD@mail.emea.novell.com> References: <55797BF702000078000838AF@mail.emea.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartF6C2D7D3.0__=" Return-path: Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Z2zeb-0003Sk-RL for xen-devel@lists.xenproject.org; Thu, 11 Jun 2015 10:24:10 +0000 In-Reply-To: <55797BF702000078000838AF@mail.emea.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 Cc: Tim Deegan 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. --=__PartF6C2D7D3.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline In hvm_hap_nested_page_fault() latch the current domain alongside the current vCPU into a local variable, making use of it where possible also beyond what the title says. Signed-off-by: Jan Beulich --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -2776,7 +2776,8 @@ int hvm_hap_nested_page_fault(paddr_t gp p2m_type_t p2mt; p2m_access_t p2ma; mfn_t mfn; - struct vcpu *v =3D current; + struct vcpu *curr =3D current; + struct domain *currd =3D curr->domain; struct p2m_domain *p2m; int rc, fall_through =3D 0, paged =3D 0; int sharing_enomem =3D 0; @@ -2786,9 +2787,9 @@ int hvm_hap_nested_page_fault(paddr_t gp * If this succeeds, all is fine. * If this fails, inject a nested page fault into the guest. */ - if ( nestedhvm_enabled(v->domain) - && nestedhvm_vcpu_in_guestmode(v) - && nestedhvm_paging_mode_hap(v) ) + if ( nestedhvm_enabled(currd) + && nestedhvm_vcpu_in_guestmode(curr) + && nestedhvm_paging_mode_hap(curr) ) { int rv; =20 @@ -2800,7 +2801,7 @@ int hvm_hap_nested_page_fault(paddr_t gp * the same as for shadow paging. */ =20 - rv =3D nestedhvm_hap_nested_page_fault(v, &gpa, + rv =3D nestedhvm_hap_nested_page_fault(curr, &gpa, npfec.read_access, npfec.write_access, npfec.insn_fetch); @@ -2830,8 +2831,8 @@ int hvm_hap_nested_page_fault(paddr_t gp * - 32-bit WinXP (& older Windows) on AMD CPUs for LAPIC accesses, * - newer Windows (like Server 2012) for HPET accesses. */ - if ( !nestedhvm_vcpu_in_guestmode(v) - && is_hvm_vcpu(v) + if ( !nestedhvm_vcpu_in_guestmode(curr) + && is_hvm_domain(currd) && hvm_mmio_internal(gpa) ) { if ( !handle_mmio_with_translation(gla, gpa >> PAGE_SHIFT, npfec) = ) @@ -2840,7 +2841,7 @@ int hvm_hap_nested_page_fault(paddr_t gp goto out; } =20 - p2m =3D p2m_get_hostp2m(v->domain); + p2m =3D p2m_get_hostp2m(currd); mfn =3D get_gfn_type_access(p2m, gfn, &p2mt, &p2ma,=20 P2M_ALLOC | (npfec.write_access ? P2M_UNSHAR= E : 0), NULL); @@ -2903,10 +2904,10 @@ int hvm_hap_nested_page_fault(paddr_t gp (npfec.write_access && (p2m_is_discard_write(p2mt) || (p2mt =3D=3D p2m_mmio_write_dm)))= ) { - put_gfn(p2m->domain, gfn); + put_gfn(currd, gfn); =20 rc =3D 0; - if ( unlikely(is_pvh_vcpu(v)) ) + if ( unlikely(is_pvh_domain(currd)) ) goto out; =20 if ( !handle_mmio_with_translation(gla, gpa >> PAGE_SHIFT, npfec) = ) @@ -2924,7 +2925,7 @@ int hvm_hap_nested_page_fault(paddr_t gp { ASSERT(p2m_is_hostp2m(p2m)); sharing_enomem =3D=20 - (mem_sharing_unshare_page(p2m->domain, gfn, 0) < 0); + (mem_sharing_unshare_page(currd, gfn, 0) < 0); rc =3D 1; goto out_put_gfn; } @@ -2939,8 +2940,8 @@ int hvm_hap_nested_page_fault(paddr_t gp */ if ( npfec.write_access ) { - paging_mark_dirty(v->domain, mfn_x(mfn)); - p2m_change_type_one(v->domain, gfn, p2m_ram_logdirty, = p2m_ram_rw); + paging_mark_dirty(currd, mfn_x(mfn)); + p2m_change_type_one(currd, gfn, p2m_ram_logdirty, p2m_ram_rw);= } rc =3D 1; goto out_put_gfn; @@ -2952,28 +2953,28 @@ int hvm_hap_nested_page_fault(paddr_t gp rc =3D fall_through; =20 out_put_gfn: - put_gfn(p2m->domain, gfn); + put_gfn(currd, gfn); out: /* All of these are delayed until we exit, since we might=20 * sleep on event ring wait queues, and we must not hold * locks in such circumstance */ if ( paged ) - p2m_mem_paging_populate(v->domain, gfn); + p2m_mem_paging_populate(currd, gfn); if ( sharing_enomem ) { int rv; - if ( (rv =3D mem_sharing_notify_enomem(v->domain, gfn, 1)) < 0 ) + if ( (rv =3D mem_sharing_notify_enomem(currd, gfn, 1)) < 0 ) { gdprintk(XENLOG_ERR, "Domain %hu attempt to unshare " "gfn %lx, ENOMEM and no helper (rc %d)\n", - v->domain->domain_id, gfn, rv); + currd->domain_id, gfn, rv); /* Crash the domain */ rc =3D 0; } } if ( req_ptr ) { - mem_access_send_req(v->domain, req_ptr); + mem_access_send_req(currd, req_ptr); xfree(req_ptr); } return rc; --=__PartF6C2D7D3.0__= Content-Type: text/plain; name="x86-HAP-nested-PF-latch-domain.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-HAP-nested-PF-latch-domain.patch" x86/HAP: prefer is_..._domain() over is_..._vcpu()=0A=0AIn hvm_hap_nested_p= age_fault() latch the current domain alongside the=0Acurrent vCPU into a = local variable, making use of it where possible=0Aalso beyond what the = title says.=0A=0ASigned-off-by: Jan Beulich =0A=0A--- = a/xen/arch/x86/hvm/hvm.c=0A+++ b/xen/arch/x86/hvm/hvm.c=0A@@ -2776,7 = +2776,8 @@ int hvm_hap_nested_page_fault(paddr_t gp=0A p2m_type_t = p2mt;=0A p2m_access_t p2ma;=0A mfn_t mfn;=0A- struct vcpu *v = =3D current;=0A+ struct vcpu *curr =3D current;=0A+ struct domain = *currd =3D curr->domain;=0A struct p2m_domain *p2m;=0A int rc, = fall_through =3D 0, paged =3D 0;=0A int sharing_enomem =3D 0;=0A@@ = -2786,9 +2787,9 @@ int hvm_hap_nested_page_fault(paddr_t gp=0A * If = this succeeds, all is fine.=0A * If this fails, inject a nested page = fault into the guest.=0A */=0A- if ( nestedhvm_enabled(v->domain)= =0A- && nestedhvm_vcpu_in_guestmode(v)=0A- && nestedhvm_pagin= g_mode_hap(v) )=0A+ if ( nestedhvm_enabled(currd)=0A+ && = nestedhvm_vcpu_in_guestmode(curr)=0A+ && nestedhvm_paging_mode_hap(c= urr) )=0A {=0A int rv;=0A =0A@@ -2800,7 +2801,7 @@ int = hvm_hap_nested_page_fault(paddr_t gp=0A * the same as for shadow = paging.=0A */=0A =0A- rv =3D nestedhvm_hap_nested_page_fau= lt(v, &gpa,=0A+ rv =3D nestedhvm_hap_nested_page_fault(curr, = &gpa,=0A npfec.read_access,= =0A npfec.write_access,=0A = npfec.insn_fetch);=0A@@ = -2830,8 +2831,8 @@ int hvm_hap_nested_page_fault(paddr_t gp=0A * - = 32-bit WinXP (& older Windows) on AMD CPUs for LAPIC accesses,=0A * - = newer Windows (like Server 2012) for HPET accesses.=0A */=0A- if ( = !nestedhvm_vcpu_in_guestmode(v)=0A- && is_hvm_vcpu(v)=0A+ if ( = !nestedhvm_vcpu_in_guestmode(curr)=0A+ && is_hvm_domain(currd)=0A = && hvm_mmio_internal(gpa) )=0A {=0A if ( !handle_mmio_w= ith_translation(gla, gpa >> PAGE_SHIFT, npfec) )=0A@@ -2840,7 +2841,7 @@ = int hvm_hap_nested_page_fault(paddr_t gp=0A goto out;=0A }=0A = =0A- p2m =3D p2m_get_hostp2m(v->domain);=0A+ p2m =3D p2m_get_hostp2m(= currd);=0A mfn =3D get_gfn_type_access(p2m, gfn, &p2mt, &p2ma, =0A = P2M_ALLOC | (npfec.write_access ? P2M_UNSHARE : = 0),=0A NULL);=0A@@ -2903,10 +2904,10 @@ int = hvm_hap_nested_page_fault(paddr_t gp=0A (npfec.write_access &&=0A = (p2m_is_discard_write(p2mt) || (p2mt =3D=3D p2m_mmio_write_dm))) = )=0A {=0A- put_gfn(p2m->domain, gfn);=0A+ put_gfn(currd, = gfn);=0A =0A rc =3D 0;=0A- if ( unlikely(is_pvh_vcpu(v)) = )=0A+ if ( unlikely(is_pvh_domain(currd)) )=0A goto = out;=0A =0A if ( !handle_mmio_with_translation(gla, gpa >> = PAGE_SHIFT, npfec) )=0A@@ -2924,7 +2925,7 @@ int hvm_hap_nested_page_fault(= paddr_t gp=0A {=0A ASSERT(p2m_is_hostp2m(p2m));=0A = sharing_enomem =3D =0A- (mem_sharing_unshare_page(p2m->domain, = gfn, 0) < 0);=0A+ (mem_sharing_unshare_page(currd, gfn, 0) < = 0);=0A rc =3D 1;=0A goto out_put_gfn;=0A }=0A@@ = -2939,8 +2940,8 @@ int hvm_hap_nested_page_fault(paddr_t gp=0A = */=0A if ( npfec.write_access )=0A {=0A- = paging_mark_dirty(v->domain, mfn_x(mfn));=0A- p2m_change_type_on= e(v->domain, gfn, p2m_ram_logdirty, p2m_ram_rw);=0A+ paging_mark= _dirty(currd, mfn_x(mfn));=0A+ p2m_change_type_one(currd, gfn, = p2m_ram_logdirty, p2m_ram_rw);=0A }=0A rc =3D 1;=0A = goto out_put_gfn;=0A@@ -2952,28 +2953,28 @@ int hvm_hap_nested_page_fault(= paddr_t gp=0A rc =3D fall_through;=0A =0A out_put_gfn:=0A- = put_gfn(p2m->domain, gfn);=0A+ put_gfn(currd, gfn);=0A out:=0A /* = All of these are delayed until we exit, since we might =0A * sleep on = event ring wait queues, and we must not hold=0A * locks in such = circumstance */=0A if ( paged )=0A- p2m_mem_paging_populate(v->d= omain, gfn);=0A+ p2m_mem_paging_populate(currd, gfn);=0A if ( = sharing_enomem )=0A {=0A int rv;=0A- if ( (rv =3D = mem_sharing_notify_enomem(v->domain, gfn, 1)) < 0 )=0A+ if ( (rv = =3D mem_sharing_notify_enomem(currd, gfn, 1)) < 0 )=0A {=0A = gdprintk(XENLOG_ERR, "Domain %hu attempt to unshare "=0A = "gfn %lx, ENOMEM and no helper (rc %d)\n",=0A- = v->domain->domain_id, gfn, rv);=0A+ currd->domain_id= , gfn, rv);=0A /* Crash the domain */=0A rc =3D = 0;=0A }=0A }=0A if ( req_ptr )=0A {=0A- = mem_access_send_req(v->domain, req_ptr);=0A+ mem_access_send_req(cur= rd, req_ptr);=0A xfree(req_ptr);=0A }=0A return rc;=0A --=__PartF6C2D7D3.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 --=__PartF6C2D7D3.0__=--