From: "Jan Beulich" Subject: Re: [PATCH RFC v2 1/4] x86/mm: Shadow and p2m changes for PV mem_access Date: Wed, 30 Jul 2014 08:11:08 +0100 Message-ID: <53D8B6AC0200007800027844@mail.emea.novell.com> References: <1404787805-4540-1-git-send-email-aravindp@cisco.com> <1404787805-4540-2-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> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XCO2c-0001gC-FA for xen-devel@lists.xenproject.org; Wed, 30 Jul 2014 07:11:14 +0000 In-Reply-To: <97A500D504438F4ABC02EBA81613CC633188EC46@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: "xen-devel@lists.xenproject.org" , Keir Fraser , Ian Jackson , Ian Campbell , Tim Deegan List-Id: xen-devel@lists.xenproject.org >>> On 30.07.14 at 06:05, wrote: > I took another stab at solving this issue. This is what the solution looks > like: > > 1. mem_access listener attaches to a PV domain and listens for write > violation. > 2. Xen tries to write to a guest page that is marked not writable. > 3. PF occurs. > - Do not pass on the violation to the mem_access listener. > - Temporarily change the access permission for the page in question to R/W. > - Allow the fault to be handled which will end up with a PTE with the RW bit set. > - Stash the mfn in question in the pv_vcpu structure. > - Check if this field is set on exiting from guest access functions. If it > is, reset the page permission to the default value and drop its shadows. > 4. I had to take care that the checks in the guest access functions for > resetting the page permissions do not kick in when the shadow code is trying > to construct the PTE for the page in question or when removing all the > mappings. > > Here is a POC patch that does the above. I have it on top of the patch that > was using CR0.WP to highlight the difference. I realize some of the other > comments like using shadow_flags have not been addressed here. I just want to > get feedback if this is a viable solution before addressing those issues. Still rather ugly, and still leaving the window in time as big as the CR0.CD variant (the window in space got shrunk to just a page). Furthermore, how would you guarantee no other vCPU of the same guest modifies the now writable page in the meantime? Jan