From: "Jan Beulich" Subject: Re: Bisected Xen-unstable: "Segment register inaccessible for d1v0" when starting HVM guest on intel Date: Tue, 01 Jul 2014 08:01:54 +0100 Message-ID: <53B27902020000780001ED8B@mail.emea.novell.com> References: <1057886355.20140628222158@eikelenboom.it> <53B1A244020000780001EA4D@mail.emea.novell.com> <1081819750.20140630183750@eikelenboom.it> <53B19EEB.4060603@citrix.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 1X1s4l-0003IG-12 for xen-devel@lists.xenproject.org; Tue, 01 Jul 2014 07:01:59 +0000 In-Reply-To: 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: Feng Wu Cc: Andrew Cooper , "xen-devel@lists.xenproject.org" , Sander Eikelenboom List-Id: xen-devel@lists.xenproject.org >>> On 01.07.14 at 07:05, wrote: >> From: Andrew Cooper [mailto:andrew.cooper3@citrix.com] >> During a context switch (where the vmcs is unavailable), we try to >> update the the runstate area. >> >> Following the identified changeset, we unconditionally try to read ss >> for an hvm vcpu supervisor access, but in this case we don't actually >> have a pagefault. >> >> I think there might need to be a distinction between "Xen is walking the >> guest pagetables because of a fault", and "Xen is walking the guest >> pagetables in an attempt to copy_to/from_guest". Neither SMEP or SMAP >> have any business being checked for a Xen accesses; the current vcpu >> operating mode has no bearing on whether Xen should be able to update >> the runstate info. > > Seems we cannot get the guest SS here by hvm_get_segment_register(), since > in this case this function will be called between setting 'current' and > vmx_do_resume(). Is the following solution okay to solve this issue: > > 1. Store GUEST_SS to regs->ss in vmx_vmexit_handler() just like what has been > done for GUEST_RIP/ GUEST_RSP/ GUEST_RFLAGS. > 2. Get the guest SS from struct cpu_user_regs in guest_walk_tables() I think you originally (and wrongly) did this via looking at the RPL; this won't all of the sudden become right now. DPL is the only thing you can use for the judgment, and that can't be read without calling hvm_get_segment_register() (unless we latched that while scheduling a vCPU out). But as Andrew validly said, for the purposes of out of context Xen writes the guest execution mode doesn't matter anyway, these ought to always assume supervisor mode. That points out another problem here: Accesses like the setting of a segment descriptor's accessed bit or the A/D bit in a page table entry also need to be done as if in supervisor mode, i.e. we need some kind of mode override also for other purposes. Yet I don't think that's going to be too intrusive a change: Everything here happens on "current", i.e. we can set and clear a mode override on the respective call paths. But then again - why do we need to determine CPL here anyway? PFEC_user_mode clear already tells us the access was a kernel mode one. And the SMEP check doesn't look at CPL, only the SMAP one does. Jan