From: Tim Deegan Subject: Re: [PATCH RFC v2 2/3] xen/shadow: fix shadow_track_dirty_vram to work on hvm guests Date: Thu, 9 Apr 2015 13:41:52 +0100 Message-ID: <20150409124152.GL17031@deinos.phlegethon.org> References: <1427970395-16203-1-git-send-email-roger.pau@citrix.com> <1427970395-16203-3-git-send-email-roger.pau@citrix.com> <551D933D.2030300@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Return-path: Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YgBmO-0000D9-0T for xen-devel@lists.xenproject.org; Thu, 09 Apr 2015 12:41:56 +0000 Content-Disposition: inline In-Reply-To: <551D933D.2030300@citrix.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: Andrew Cooper Cc: xen-devel@lists.xenproject.org, Jan Beulich , Roger Pau Monne List-Id: xen-devel@lists.xenproject.org At 20:06 +0100 on 02 Apr (1428005197), Andrew Cooper wrote: > On 02/04/15 11:26, Roger Pau Monne wrote: > > Modify shadow_track_dirty_vram to use a local buffer and then flush to = the > > guest without the paging_lock held. This is modeled after > > hap_track_dirty_vram. > > > > Signed-off-by: Roger Pau Monn=E9 > > Cc: Tim Deegan > > Cc: Jan Beulich > > Cc: Andrew Cooper > = > Reviewed-by: Andrew Cooper , subject to two > corrections and a suggestion. > = > > --- > > xen/arch/x86/mm/shadow/common.c | 18 +++++++++++++++--- > > 1 file changed, 15 insertions(+), 3 deletions(-) > > > > diff --git a/xen/arch/x86/mm/shadow/common.c b/xen/arch/x86/mm/shadow/c= ommon.c > > index 2e43d6d..8fff43a 100644 > > --- a/xen/arch/x86/mm/shadow/common.c > > +++ b/xen/arch/x86/mm/shadow/common.c > > @@ -3516,7 +3516,7 @@ static void sh_clean_dirty_bitmap(struct domain *= d) > > int shadow_track_dirty_vram(struct domain *d, > > unsigned long begin_pfn, > > unsigned long nr, > > - XEN_GUEST_HANDLE_64(uint8) dirty_bitmap) > > + XEN_GUEST_HANDLE_64(uint8) guest_dirty_bit= map) > > { > > int rc; > > unsigned long end_pfn =3D begin_pfn + nr; > > @@ -3526,6 +3526,7 @@ int shadow_track_dirty_vram(struct domain *d, > > p2m_type_t t; > > struct sh_dirty_vram *dirty_vram; > > struct p2m_domain *p2m =3D p2m_get_hostp2m(d); > > + uint8_t *dirty_bitmap =3D NULL; > > = > > if ( end_pfn < begin_pfn || end_pfn > p2m->max_mapped_pfn + 1 ) > > return -EINVAL; > > @@ -3554,6 +3555,12 @@ int shadow_track_dirty_vram(struct domain *d, > > goto out; > > } > > = > > + dirty_bitmap =3D xzalloc_bytes(dirty_size); > > + if ( dirty_bitmap =3D=3D NULL ) > > + { > > + rc =3D -ENOMEM; > > + goto out; > > + } > > /* This should happen seldomly (Video mode change), > > * no need to be careful. */ > > if ( !dirty_vram ) > > @@ -3587,7 +3594,7 @@ int shadow_track_dirty_vram(struct domain *d, > > { > > /* still completely clean, just copy our empty bitmap */ > > rc =3D -EFAULT; > > - if ( copy_to_guest(dirty_bitmap, dirty_vram->dirty_bitmap, dir= ty_size) =3D=3D 0 ) > > + if ( memcpy(dirty_bitmap, dirty_vram->dirty_bitmap, dirty_size= ) !=3D NULL ) > = > memcpy() returns an int, not a pointer. No, memcpy() returns a pointer, but it's always =3D=3D its first argument so there's no need to check it at all. :) > > + if ( rc =3D=3D 0 && dirty_bitmap !=3D NULL ) > > + if ( copy_to_guest(guest_dirty_bitmap, dirty_bitmap, dirty_siz= e) !=3D 0 ) > > + rc =3D -EFAULT; > = > These two if()s can be joined, and shorted for brevity. > = > if ( !rc && dirty_bitmap && copy_to_guest(guest_dirty_bitmap, > dirty_bitmap, dirty_size) ) > rc =3D -EFAULT; +1. Cheers, Tim.