From: "Jan Beulich" Subject: Re: [PATCH RFC v2 1/4] x86/mm: Shadow and p2m changes for PV mem_access Date: Mon, 25 Aug 2014 08:29:07 +0100 Message-ID: <53FB01E3020000780002D082@mail.emea.novell.com> References: <1404787805-4540-1-git-send-email-aravindp@cisco.com> <53D13457020000780002599B@mail.emea.novell.com> <97A500D504438F4ABC02EBA81613CC633188B795@xmb-aln-x02.cisco.com> <53D221270200007800025CEA@mail.emea.novell.com> <97A500D504438F4ABC02EBA81613CC633188BE3A@xmb-aln-x02.cisco.com> <53D60EA002000078000265FC@mail.emea.novell.com> <97A500D504438F4ABC02EBA81613CC633188EC46@xmb-aln-x02.cisco.com> <53D8B6AC0200007800027844@mail.emea.novell.com> <97A500D504438F4ABC02EBA81613CC633188EF44@xmb-aln-x02.cisco.com> <53DB52380200007800028448@mail.emea.novell.com> <97A500D504438F4ABC02EBA81613CC633188FBD7@xmb-aln-x02.cisco.com> <53DF4C6B0200007800028CA5@mail.emea.novell.com> <97A500D504438F4ABC02EBA81613CC63318A2DBD@xmb-rcd-x02.cisco.com> <53E096C902000078000294A2@mail.emea.novell.com> <97A500D504438F4ABC02EBA81613CC63318E00F6@xmb-aln-x02.cisco.com> <53F77EEC020000780002CC3E@mail.emea.novell.com> <97A500D504438F4ABC02EBA81613CC63318E04E7@xmb-aln-x02.cisco.com> <53F798D9.9090800@citrix.com> <97A500D504438F4ABC02EBA81613CC63318E057E@xmb-aln-x02.cisco.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XLoiH-000652-7b for xen-devel@lists.xenproject.org; Mon, 25 Aug 2014 07:29:13 +0000 In-Reply-To: <97A500D504438F4ABC02EBA81613CC63318E057E@xmb-aln-x02.cisco.com> Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: "Aravindh Puthiyaparambil (aravindp)" Cc: Keir Fraser , Ian Campbell , Andrew Cooper , Tim Deegan , "xen-devel@lists.xenproject.org" , Ian Jackson List-Id: xen-devel@lists.xenproject.org >>> On 22.08.14 at 21:48, wrote: >>>> As Andrew already pointed out, you absolutely need to deal with page >>>> crossing accesses, >>> Is this for say an unsigned long that lives across two pages? Off the top of >>my head, I think always allowing writes to the page in question and the next >>followed by reverting to default for both pages at the end of the write > should >>take care of this. I would have to walk the page tables to figure out the > next >>mfn. Or am I on the wrong track here? >> >>create_bounce_frame puts several adjacent words on a guest stack, and this >>is very capable of crossing a page boundary. >> >>Even an unaligned uint16_t can cross a page boundary. > > OK, so marking two adjacent pages as writable and reverting after the write > went through should solve this problem. For create_bounce_frame() yes, but not for the generic copy_to_user(). But there you'd have the option of reverting the first page's permissions when you hit a fault on the third one (i.e. two slots for tracking pages should still suffice). >>>>> + if ( guest_l1e_get_flags(gw.l1e) & _PAGE_RW ) >>>>> { >>>>> - cr0 &= ~X86_CR0_WP; >>>>> - write_cr0(cr0); >>>>> - v->arch.pv_vcpu.need_cr0_wp_set = 1; >>>>> + domain_pause_nosync(d); >>>> I don't think a "nosync" pause is enough here, as that leaves a >>>> window for the guest to write to the page. Since the sync version may >>>> take some time to complete it may become difficult for you to >>>> actually handle this in an acceptable way. >>> Are you worried about performance or is there some other issue? >> >>Both performance and correctness. With nosync(), guest vcpus can still be >>running on other pcpus, and playing with this pagetable entry. >> >>The synchronous variants can block for a moderate period of time. > > OK, I don't follow why pausing the other vcpus synchronously is an issue > here. So what is you don't understand? The remote vCPU-s won't necessarily be paused by the time domain_pause_nosync() returns (that's the nature of the "nosync"). Since the page table entry then gets modified, those remote vCPU-s might access memory using that entry, and the listener wouldn't see the write access. And when you use the synchronous form, the waiting for the remote vCPU-s to become de-scheduled will take some time, which is particularly bad for many-vCPU guests with the way domain_pause() currently works (of course this could be improved by parallelizing the pausing of the individual vCPU-s, first issuing vcpu_sleep_nosync() on all of them and then waiting for all of them to become non-running). Jan