Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp2127396ybz; Sun, 26 Apr 2020 11:45:03 -0700 (PDT) X-Google-Smtp-Source: APiQypLdp3aURd4BKFhJ7Hl6SJ8IbY5ltw7e9Kk8P0ZktPMJP+/Zldr38T7Q9RhyAbVZwQfO/HQ9 X-Received: by 2002:a17:906:68cf:: with SMTP id y15mr15749434ejr.260.1587926703277; Sun, 26 Apr 2020 11:45:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587926703; cv=none; d=google.com; s=arc-20160816; b=dCfFn9qJ67U2RKUacPoGReO9jA3008XTENyMlMJSrpsJ47VN/JzkUS3neNMbVSL6k+ nV0MYgBpbjI5g09wS1v3nzbIN+w6Zr4wC8osasBk2KhGPbiRZbY9OZfC1Bzhx1slvpVd SqlOF+Vg3Y4KskgQt6wHDfXmYMe1oEPq7uRmHqsZNCflm7duxOZIbjwyUincw+cDQWbp 4y03Gpc3+fQd8FH/28CW84H4ZKjoKH6g1jDB6mV4pliUFRhbiMs92flwVdIolZMPC5Bw c/RT9oGiEfOeODVy5h6Z3s9+cjEtzPrSWaKv4iLnlsyc4WwgT8TmqptC/6veqwqB7IbY 3RGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :robot-unsubscribe:robot-id:message-id:mime-version:references :in-reply-to:cc:subject:to:reply-to:from:date; bh=hFMjqPhayShfqEXlhcBu0A99oMWtYNJgl4S8qadPxBc=; b=zo3+VEusQ2Nh5ct+DIWSmDF8lhxwmLngu7MQW9H6mqLx7+1kZkWe78OphYcsE3bti2 rCDCzKRbbwC7zNJC5bjq/igRw/K9BijLIP6k3ZlqNDRMAsYObdrwKWKwPJtGawOtuMPT Wbv3U4TPiKdc/PXtv0ygbfoqOXoYvZ97tCm/nlqs/roW3U+qk/Gbaxj4C6ycf2EHaBg7 5hfHfzyOJY13qL/Zp7fj6Z0A2xIykxuTXTz/hANcyLI3aNc0oKMG2dDjlYAX6hV1am6l XhWmb2a/voZ31crWV+k9wrtlvNqabLw0kq219PSLCy5GR7XfVybQICmOHUBjjNq9Gkst arCg== ARC-Authentication-Results: i=1; mx.google.com; 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 qq22si6764351ejb.523.2020.04.26.11.44.40; Sun, 26 Apr 2020 11:45:03 -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; 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 S1726490AbgDZSnK (ORCPT + 99 others); Sun, 26 Apr 2020 14:43:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726410AbgDZSnB (ORCPT ); Sun, 26 Apr 2020 14:43:01 -0400 Received: from Galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 687D6C061A41; Sun, 26 Apr 2020 11:43:01 -0700 (PDT) Received: from [5.158.153.53] (helo=tip-bot2.lab.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1jSmEx-0007Eb-I7; Sun, 26 Apr 2020 20:42:55 +0200 Received: from [127.0.1.1] (localhost [IPv6:::1]) by tip-bot2.lab.linutronix.de (Postfix) with ESMTP id 33C051C0178; Sun, 26 Apr 2020 20:42:55 +0200 (CEST) Date: Sun, 26 Apr 2020 18:42:54 -0000 From: "tip-bot2 for Thomas Gleixner" Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/mm] x86/tlb: Uninline __get_current_cr3_fast() Cc: Thomas Gleixner , Borislav Petkov , Alexandre Chartre , "Peter Zijlstra (Intel)" , Andy Lutomirski , x86 , LKML In-Reply-To: <20200421092558.848064318@linutronix.de> References: <20200421092558.848064318@linutronix.de> MIME-Version: 1.0 Message-ID: <158792657479.28353.17566281114631962456.tip-bot2@tip-bot2> X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the x86/mm branch of tip: Commit-ID: 8c5cc19e94703182647dfccc164e4437a04539c8 Gitweb: https://git.kernel.org/tip/8c5cc19e94703182647dfccc164e4437a04539c8 Author: Thomas Gleixner AuthorDate: Tue, 21 Apr 2020 11:20:28 +02:00 Committer: Borislav Petkov CommitterDate: Fri, 24 Apr 2020 15:55:50 +02:00 x86/tlb: Uninline __get_current_cr3_fast() 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 for unexporting cpu_tlbstate move __get_current_cr3_fast() into the x86 TLB management code. No functional change. Signed-off-by: Thomas Gleixner Signed-off-by: Borislav Petkov Reviewed-by: Alexandre Chartre Acked-by: Peter Zijlstra (Intel) Acked-by: Andy Lutomirski Link: https://lkml.kernel.org/r/20200421092558.848064318@linutronix.de --- arch/x86/include/asm/mmu_context.h | 19 +------------------ arch/x86/mm/tlb.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h index 4e55370..9608536 100644 --- 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_permitted(struct vm_area_struct *vma, 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; diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c index 66f96f2..ea6f98a 100644 --- a/arch/x86/mm/tlb.c +++ b/arch/x86/mm/tlb.c @@ -844,6 +844,26 @@ void flush_tlb_kernel_range(unsigned long start, unsigned long end) } /* + * 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