From: "Jan Beulich" Subject: Re: [PATCH RFC v2 1/4] x86/mm: Shadow and p2m changes for PV mem_access Date: Mon, 28 Jul 2014 07:49:36 +0100 Message-ID: <53D60EA002000078000265FC@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> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XBekf-0004u5-Ij for xen-devel@lists.xenproject.org; Mon, 28 Jul 2014 06:49:41 +0000 In-Reply-To: <97A500D504438F4ABC02EBA81613CC633188BE3A@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 25.07.14 at 23:39, wrote: >>>>I wonder how well the window where you're running with CR0.WP clear >>>>is bounded: The flag serves as a kind of security measure, and hence >>>>shouldn't be left off for extended periods of time. >>> >>> I agree. Is there a way I can bound this? >> >>That's what you need to figure out. The simplistic solution (single >>stepping just the critical instruction(s)) is probably not going to be >>acceptable due to its fragility. I have no good other suggestions, >>but I'm not eager to allow code in that weakens protection. > > From the debugging I have done to get this working, this is what the flow > should be. Xen tries to write to guest page marked read only and page fault > occurs. So __copy_to_user_ll() -> handle_exception_saved->do_page_fault() and > CR0.WP is cleared. Once the fault is handled __copy_to_user_ll() is retried > and it goes through. At the end of which CR0.WP is turned on. So this is the > only window that pv_vcpu.need_cr0_wp_set should be true. Is there a spot > outside of this window that I check to see if it is set and if it is, turn it > back on again? Would that be a sufficient bound? That's the obvious (direct) path. What you leave aside are any interrupts occurring in between. >>>>> pg[i].count_info = PGC_allocated | 1; >>>>> + if ( is_pv_domain(d) ) >>>>> + shadow_set_access(&pg[i], p2m_get_hostp2m(d)- >>>default_access); >>>> >>>>I don't think you should call shadow code from here. >>> >>> Should I add a p2m wrapper for this, so that it is valid only for x86 and a >>> no-op for ARM? >> >>That's not necessarily enough, but at least presumably the right >>route: You also need to avoid fiddling with struct page_info fields >>that may be used (now or in the future) for other purposes, i.e. >>you need to gate the setting of the flags by more than just >>is_pv_domain(). > > Coupled with your response to the other thread, I am thinking I should move > away from using the shadow_flags for access permissions. Tim's other > suggestion was to try and re-use the p2m-pt implementation. I'll leave that to Tim and you. Jan