Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1034872AbdD0VWf (ORCPT ); Thu, 27 Apr 2017 17:22:35 -0400 Received: from mail-vk0-f52.google.com ([209.85.213.52]:36210 "EHLO mail-vk0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030812AbdD0VWb (ORCPT ); Thu, 27 Apr 2017 17:22:31 -0400 MIME-Version: 1.0 In-Reply-To: <89ea23ba-2fec-41e6-2628-c3a2fd789b1f@oracle.com> References: <47640bc3-02e6-ceb1-44bd-2c21e64b4d37@oracle.com> <89ea23ba-2fec-41e6-2628-c3a2fd789b1f@oracle.com> From: Andy Lutomirski Date: Thu, 27 Apr 2017 14:22:09 -0700 Message-ID: Subject: Re: xen_exit_mmap() questions To: Boris Ostrovsky Cc: Andy Lutomirski , "xen-devel@lists.xenproject.org" , Juergen Gross , X86 ML , Borislav Petkov , "linux-kernel@vger.kernel.org" Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2480 Lines: 58 On Thu, Apr 27, 2017 at 1:00 PM, Boris Ostrovsky wrote: > On 04/27/2017 12:46 PM, Andy Lutomirski wrote: >> On Thu, Apr 27, 2017 at 6:21 AM, Boris Ostrovsky >> wrote: >>>>>>>> Also, this code in drop_other_mm_ref() looks dubious to me: >>>>>>>> >>>>>>>> /* If this cpu still has a stale cr3 reference, then make sure >>>>>>>> it has been flushed. */ >>>>>>>> if (this_cpu_read(xen_current_cr3) == __pa(mm->pgd)) >>>>>>>> load_cr3(swapper_pg_dir); >>>>>>>> >>>>>>>> If cr3 hasn't been flushed to the hypervisor because we're in a lazy >>>>>>>> mode, why would load_cr3() help? Shouldn't this be xen_mc_flush() >>>>>>>> instead? >>>>>>> load_cr3() actually ends with xen_mc_flush() by way of xen_write_cr3() >>>>>>> -> xen_mc_issue(). >>>>>> xen_mc_issue() does: >>>>>> >>>>>> if ((paravirt_get_lazy_mode() & mode) == 0) >>>>>> xen_mc_flush(); >>>>>> >>>>>> I assume the load_cr3() is intended to deal with the case where we're >>>>>> in lazy mode, but we'll still be in lazy mode, right? Or does it >>>>>> serve some other purpose? >>>>> Of course. I can't read (I ignored the "== 0" part). >>>>> >>>>> Apparently the early version had an explicit flush but then it disappeared >>>>> (commit 9f79991d4186089e228274196413572cc000143b). >>>>> >>>>> The point of CR3 loading here, I believe, is to make sure the hypervisor >>>>> knows that the (v)CPU is no longer using the the mm's cr3 (we are loading >>>>> swapper_pgdir here). >>>> But that's what leave_mm() does. To be fair, the x86 lazy TLB >>>> management is a big mess, and this came up because I'm trying to clean >>>> it up without removing it. >>> True. I don't know though if you can guarantee that leave_mm() (or >>> load_cr3() inside it) is actually called if we are in lazy mode. >> The code just before that makes these calls. > > Yes, and I was unsure whether we always get to make these calls, based > on mm and cpu_tlbstate. I think we do and with your changes it is made > even more clear. :) > >> >> Anyway, I propose to rewrite the whole thing like this: >> >> https://git.kernel.org/pub/scm/linux/kernel/git/luto/linux.git/commit/?h=x86/tlbflush_cleanup&id=ff143a54bb3bafaaad6e32145a9cfbc112e8584f > > Can you explain xen_pgd_free() change? When do you expect > xen_exit_mmap() to fail unpinning (compared to what we have now)? I don't expect it to fail, but I made fairly extensive changes. --Andy