Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp346266ybz; Tue, 21 Apr 2020 10:06:42 -0700 (PDT) X-Google-Smtp-Source: APiQypI84jgUrJBod4Jv5jKZQS02TnbPO39cJOLjwUegDA5k65lG5s7S3l1p2FlHRgrmyzCwwpor X-Received: by 2002:a17:906:ecb8:: with SMTP id qh24mr21858485ejb.299.1587488802503; Tue, 21 Apr 2020 10:06:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587488802; cv=none; d=google.com; s=arc-20160816; b=ImCnMVr4o17axla5uARoQM1iQcg9Yo2hWYI+EsGD0lf2HhFIGYf27Esd2w7Q/bDzHK iBqx8wzpUA3rdZ2JoBJvsz5yX4AhttuZjdR+dFbSgEguEgo3e4ZWjk6CDtUc8hMqcCp7 haT2BCWV6ecjX5pyqoByqiALQsoDRkZE6sK9dT7eB0foJbCanYsq/y0NaaRmlIaeo5b+ eY/EogLTT0jJTDKWGTvulVWoW/aRmbpRa0mUbYNLOgsTCIFsaWTGMoGwI2Obr5KyaH19 g9Ne1J5HCyYR1N9C8o2tyiwYQ93yG+DPam8npI7q76vWn7MjBU1Wr+g2csobBxD6mnqG 6zQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=SMH7LFHGjke0ecop6Ck37MhaqJozu4/xdSqYH1Nj1NM=; b=pNFpONPiTwgk4whh0e8C9+Z2Vj9b35RnVCOAnVyZuUZ7L4aeqR+idYxw4O5yAvgCoS 5AmZCrEwTG3ZFzuRk9Edc+G3jBI5kVWSlt0NI5ClaR2JpoFqLLDxb3ihlAvpramqgtQ+ x8SFtjQ+Jfvrkia/bLwEOZIs6sOJcsY7FWfnUbie4hryrGIjphBia3Mdu4ZbM9V9FnE9 4kSfaCha+Kyb9liJ3Apy7T1G0Q+FlZGP/WykjOjIZGgsL0aT5MqGWxWxpaj2KDdtwPuG emUS1Q8+BgBupmpBSOb3XCK3OAdOFEQNhS1AHwaauIvvCcPVBK990E4C26aD59tNorY5 xm/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amacapital-net.20150623.gappssmtp.com header.s=20150623 header.b=eCuJRkEO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 13si1730569ejz.499.2020.04.21.10.06.17; Tue, 21 Apr 2020 10:06:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@amacapital-net.20150623.gappssmtp.com header.s=20150623 header.b=eCuJRkEO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729375AbgDUREw (ORCPT + 99 others); Tue, 21 Apr 2020 13:04:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726628AbgDUREu (ORCPT ); Tue, 21 Apr 2020 13:04:50 -0400 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF9BFC061A41 for ; Tue, 21 Apr 2020 10:04:49 -0700 (PDT) Received: by mail-wr1-x442.google.com with SMTP id f13so17263912wrm.13 for ; Tue, 21 Apr 2020 10:04:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amacapital-net.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=SMH7LFHGjke0ecop6Ck37MhaqJozu4/xdSqYH1Nj1NM=; b=eCuJRkEOayneNiTHhGB1PYMY2orZhaGSb/KOKIohfqoyYSCZNGbtlztY3blkbaVk+2 RnA953vmTpFpq6DSwvsCXy2eeQKIZsaz8iku/u6362mwKNW3Ag4lc+zO7ilxtQESJteQ PXumE+UnihMQTBslwGmz0qmCy8xDgWOzXgxgesQiv+TwB1IXopoCyDfie5Kxb7/7Uzjz 4FeWmZ71AC9buVWlkb+lJm7B5aff9eB9rck9tjkpj8H99ZtXEkpXPkWSi1fGBswOe4Mf 8NAzZrM9O0fk6eiHzk+dqrxlqiAYu9s9LVSAhDmzknCTcppBQWWd8380mxddsuzyUnZc //OA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=SMH7LFHGjke0ecop6Ck37MhaqJozu4/xdSqYH1Nj1NM=; b=TDoArVYpP/JnueOpRmOl+2yAP3/l8Ir3OCNUhIFqgExQEre0u+cYiCv+6zW+fAWUah gRVqmscwIRsP7swVNLsghCf8pJ4q2p3nG5ZPiG5XXt5U/rPRm8iGDdNurIUEYvmmNg8h Bq2Xqt3WLFkvz7BjegC0GGgsLS7lbKek58u81O6+/zB8DPa1qmx24BoMgLsDftYrSwmw f8zRFm4DhzfSeEtPkQyzz2PSRsx8aqY05Q2pvFy+mFq9N8Hswh8IVRkujnfwDEJEJnOy GSUfIqFwOJS3DpdUKd7mw7Ynls9cUTVroRSfPeBDJCEg0XQntap8ORdItkBPWuTmjMUO 7Y+w== X-Gm-Message-State: AGi0PuYqTpkQrRoMiEKkTgOhdI97sHMCCJ3z+rTX11dTqWCgLOGLlRJp FORwJFFtEGVW1Q2W+AJSGB3B2O5A23+UO1HWel2Krw== X-Received: by 2002:a5d:62cc:: with SMTP id o12mr24429721wrv.75.1587488688393; Tue, 21 Apr 2020 10:04:48 -0700 (PDT) MIME-Version: 1.0 References: <20200421092027.591582014@linutronix.de> <20200421092558.848064318@linutronix.de> In-Reply-To: <20200421092558.848064318@linutronix.de> From: Andy Lutomirski Date: Tue, 21 Apr 2020 10:04:37 -0700 Message-ID: Subject: Re: [patch V2 01/16] x86/tlb: Uninline __get_current_cr3_fast() To: Thomas Gleixner Cc: LKML , X86 ML , Christoph Hellwig , Kees Cook , Alexandre Chartre , "Peter Zijlstra (Intel)" , Thomas Lendacky , Juergen Gross , Boris Ostrovsky Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 21, 2020 at 2:26 AM Thomas Gleixner wrote: > > cpu_tlbstate is exported because various TLB related functions need access > to it, but cpu_tlbstate is sensitive information which should only be > accessed by well contained kernel functions and not be directly exposed to > modules. > > In preparation of unexporting cpu_tlbstate move __get_current_cr3_fast() > into the x86 TLB management code. > > No functional change. > > Signed-off-by: Thomas Gleixner > Reviewed-by: Alexandre Chartre > Acked-by: Peter Zijlstra (Intel) Acked-by: Andy Lutomirski > --- > arch/x86/include/asm/mmu_context.h | 19 +------------------ > arch/x86/mm/tlb.c | 20 ++++++++++++++++++++ > 2 files changed, 21 insertions(+), 18 deletions(-) > > --- a/arch/x86/include/asm/mmu_context.h > +++ b/arch/x86/include/asm/mmu_context.h > @@ -225,24 +225,7 @@ static inline bool arch_vma_access_permi > return __pkru_allows_pkey(vma_pkey(vma), write); > } > > -/* > - * This can be used from process context to figure out what the value of > - * CR3 is without needing to do a (slow) __read_cr3(). > - * > - * It's intended to be used for code like KVM that sneakily changes CR3 > - * and needs to restore it. It needs to be used very carefully. > - */ > -static inline unsigned long __get_current_cr3_fast(void) > -{ > - unsigned long cr3 = build_cr3(this_cpu_read(cpu_tlbstate.loaded_mm)->pgd, > - this_cpu_read(cpu_tlbstate.loaded_mm_asid)); > - > - /* For now, be very restrictive about when this can be called. */ > - VM_WARN_ON(in_nmi() || preemptible()); > - > - VM_BUG_ON(cr3 != __read_cr3()); > - return cr3; > -} > +unsigned long __get_current_cr3_fast(void); > > typedef struct { > struct mm_struct *mm; > --- a/arch/x86/mm/tlb.c > +++ b/arch/x86/mm/tlb.c > @@ -844,6 +844,26 @@ void flush_tlb_kernel_range(unsigned lon > } > > /* > + * This can be used from process context to figure out what the value of > + * CR3 is without needing to do a (slow) __read_cr3(). > + * > + * It's intended to be used for code like KVM that sneakily changes CR3 > + * and needs to restore it. It needs to be used very carefully. > + */ > +unsigned long __get_current_cr3_fast(void) > +{ > + unsigned long cr3 = build_cr3(this_cpu_read(cpu_tlbstate.loaded_mm)->pgd, > + this_cpu_read(cpu_tlbstate.loaded_mm_asid)); > + > + /* For now, be very restrictive about when this can be called. */ > + VM_WARN_ON(in_nmi() || preemptible()); > + > + VM_BUG_ON(cr3 != __read_cr3()); > + return cr3; > +} > +EXPORT_SYMBOL_GPL(__get_current_cr3_fast); > + > +/* > * arch_tlbbatch_flush() performs a full TLB flush regardless of the active mm. > * This means that the 'struct flush_tlb_info' that describes which mappings to > * flush is actually fixed. We therefore set a single fixed struct and use it in > -- Andy Lutomirski AMA Capital Management, LLC