public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Glauber de Oliveira Costa <gcosta-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
To: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: zach-pghWNbHTmq7QT0dZR+AlfA@public.gmane.org,
	lguest-mnsaURCQ41sdnm+yROfE0A@public.gmane.org,
	kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org,
	ak-l3A5Bk7waGM@public.gmane.org,
	avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org,
	virtualization-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org,
	akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org,
	Glauber de Oliveira Costa
	<gcosta-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
Subject: [PATCH 4/24] tlb functions consolidation
Date: Fri,  9 Nov 2007 16:42:45 -0200	[thread overview]
Message-ID: <11946338103068-git-send-email-gcosta@redhat.com> (raw)
In-Reply-To: <11946338053158-git-send-email-gcosta-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>

This patch consolidates part of the tlb handling functions for the x86
architecture. In this approach, we start by the parts actually used for
paravirt in i386.

Signed-off-by: Glauber de Oliveira Costa <gcosta-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
Signed-off-by: Steven Rostedt <rostedt-nx8X9YLhiw1AfugRpC6u6w@public.gmane.org>
Acked-by: Jeremy Fitzhardinge <jeremy-8XJ3FbD+ij9l57MIdRCFDg@public.gmane.org>
---
 arch/x86/kernel/smp_64.c      |    5 ++-
 include/asm-x86/tlbflush.h    |   77 +++++++++++++++++++++++++++++++++++++++++
 include/asm-x86/tlbflush_32.h |   77 -----------------------------------------
 include/asm-x86/tlbflush_64.h |   43 +++--------------------
 4 files changed, 85 insertions(+), 117 deletions(-)

diff --git a/arch/x86/kernel/smp_64.c b/arch/x86/kernel/smp_64.c
index 62b0f2a..ce3935b 100644
--- a/arch/x86/kernel/smp_64.c
+++ b/arch/x86/kernel/smp_64.c
@@ -166,11 +166,12 @@ out:
 	add_pda(irq_tlb_count, 1);
 }
 
-static void flush_tlb_others(cpumask_t cpumask, struct mm_struct *mm,
-						unsigned long va)
+void native_flush_tlb_others(const cpumask_t *cpumaskp,
+			     struct mm_struct *mm, unsigned long va)
 {
 	int sender;
 	union smp_flush_state *f;
+	cpumask_t cpumask = *cpumaskp;
 
 	/* Caller has disabled preemption */
 	sender = smp_processor_id() % NUM_INVALIDATE_TLB_VECTORS;
diff --git a/include/asm-x86/tlbflush.h b/include/asm-x86/tlbflush.h
index 9af4cc8..93283cf 100644
--- a/include/asm-x86/tlbflush.h
+++ b/include/asm-x86/tlbflush.h
@@ -1,5 +1,82 @@
+#ifndef _X86_TLBFLUSH_H_
+#define _X86_TLBFLUSH_H_
+
+#ifdef CONFIG_PARAVIRT
+#include <asm/paravirt.h>
+#else
+#define __flush_tlb() __native_flush_tlb()
+#define __flush_tlb_global() __native_flush_tlb_global()
+#define __flush_tlb_single(addr) __native_flush_tlb_single(addr)
+#endif
+
+static inline void __native_flush_tlb(void)
+{
+	write_cr3(read_cr3());
+}
+
+static inline void __native_flush_tlb_global(void)
+{
+	unsigned long cr4 = read_cr4();
+	write_cr4(cr4 & ~X86_CR4_PGE);  /* clear PGE */
+	write_cr4(cr4);                 /* write old PGE again and flush TLBs */
+}
+
+#define __native_flush_tlb_single(addr) 				\
+	__asm__ __volatile__("invlpg (%0)" ::"r" (addr) : "memory")
+
+#ifdef CONFIG_SMP
+
+#include <asm/smp.h>
+#include <linux/mm.h>
+
+#define local_flush_tlb() \
+	__flush_tlb()
+
+extern void flush_tlb_all(void);
+extern void flush_tlb_current_task(void);
+extern void flush_tlb_mm(struct mm_struct *);
+extern void flush_tlb_page(struct vm_area_struct *, unsigned long);
+
+#define flush_tlb()	flush_tlb_current_task()
+
+static inline void flush_tlb_range(struct vm_area_struct *vma,
+				   unsigned long start, unsigned long end)
+{
+	flush_tlb_mm(vma->vm_mm);
+}
+
+void native_flush_tlb_others(const cpumask_t *cpumask, struct mm_struct *mm,
+			     unsigned long va);
+
+#define TLBSTATE_OK	1
+#define TLBSTATE_LAZY	2
+
+#ifdef CONFIG_X86_64
+/* Roughly an IPI every 20MB with 4k pages for freeing page table
+   ranges. Cost is about 42k of memory for each CPU. */
+#define ARCH_FREE_PTE_NR 5350
+
+#else /* X86_64 */
+struct tlb_state
+{
+	struct mm_struct *active_mm;
+	int state;
+	char __cacheline_padding[L1_CACHE_BYTES-8];
+};
+DECLARE_PER_CPU(struct tlb_state, cpu_tlbstate);
+#endif /* X86_64 */
+
+#endif
+
+#ifndef CONFIG_PARAVIRT
+#define flush_tlb_others(mask, mm, va)		\
+	native_flush_tlb_others(&mask, mm, va)
+#endif
+
 #ifdef CONFIG_X86_32
 # include "tlbflush_32.h"
 #else
 # include "tlbflush_64.h"
 #endif
+
+#endif
diff --git a/include/asm-x86/tlbflush_32.h b/include/asm-x86/tlbflush_32.h
index 2bd5b95..07eaf37 100644
--- a/include/asm-x86/tlbflush_32.h
+++ b/include/asm-x86/tlbflush_32.h
@@ -1,49 +1,8 @@
 #ifndef _I386_TLBFLUSH_H
 #define _I386_TLBFLUSH_H
 
-#include <linux/mm.h>
 #include <asm/processor.h>
 
-#ifdef CONFIG_PARAVIRT
-#include <asm/paravirt.h>
-#else
-#define __flush_tlb() __native_flush_tlb()
-#define __flush_tlb_global() __native_flush_tlb_global()
-#define __flush_tlb_single(addr) __native_flush_tlb_single(addr)
-#endif
-
-#define __native_flush_tlb()						\
-	do {								\
-		unsigned int tmpreg;					\
-									\
-		__asm__ __volatile__(					\
-			"movl %%cr3, %0;              \n"		\
-			"movl %0, %%cr3;  # flush TLB \n"		\
-			: "=r" (tmpreg)					\
-			:: "memory");					\
-	} while (0)
-
-/*
- * Global pages have to be flushed a bit differently. Not a real
- * performance problem because this does not happen often.
- */
-#define __native_flush_tlb_global()					\
-	do {								\
-		unsigned int tmpreg, cr4, cr4_orig;			\
-									\
-		__asm__ __volatile__(					\
-			"movl %%cr4, %2;  # turn off PGE     \n"	\
-			"movl %2, %1;                        \n"	\
-			"andl %3, %1;                        \n"	\
-			"movl %1, %%cr4;                     \n"	\
-			"movl %%cr3, %0;                     \n"	\
-			"movl %0, %%cr3;  # flush TLB        \n"	\
-			"movl %2, %%cr4;  # turn PGE back on \n"	\
-			: "=&r" (tmpreg), "=&r" (cr4), "=&r" (cr4_orig)	\
-			: "i" (~X86_CR4_PGE)				\
-			: "memory");					\
-	} while (0)
-
 #define __native_flush_tlb_single(addr) 				\
 	__asm__ __volatile__("invlpg (%0)" ::"r" (addr) : "memory")
 
@@ -120,44 +79,8 @@ static inline void native_flush_tlb_others(const cpumask_t *cpumask,
 {
 }
 
-#else  /* SMP */
-
-#include <asm/smp.h>
-
-#define local_flush_tlb() \
-	__flush_tlb()
-
-extern void flush_tlb_all(void);
-extern void flush_tlb_current_task(void);
-extern void flush_tlb_mm(struct mm_struct *);
-extern void flush_tlb_page(struct vm_area_struct *, unsigned long);
-
-#define flush_tlb()	flush_tlb_current_task()
-
-static inline void flush_tlb_range(struct vm_area_struct * vma, unsigned long start, unsigned long end)
-{
-	flush_tlb_mm(vma->vm_mm);
-}
-
-void native_flush_tlb_others(const cpumask_t *cpumask, struct mm_struct *mm,
-			     unsigned long va);
-
-#define TLBSTATE_OK	1
-#define TLBSTATE_LAZY	2
-
-struct tlb_state
-{
-	struct mm_struct *active_mm;
-	int state;
-	char __cacheline_padding[L1_CACHE_BYTES-8];
-};
-DECLARE_PER_CPU(struct tlb_state, cpu_tlbstate);
 #endif	/* SMP */
 
-#ifndef CONFIG_PARAVIRT
-#define flush_tlb_others(mask, mm, va)		\
-	native_flush_tlb_others(&mask, mm, va)
-#endif
 
 static inline void flush_tlb_kernel_range(unsigned long start,
 					unsigned long end)
diff --git a/include/asm-x86/tlbflush_64.h b/include/asm-x86/tlbflush_64.h
index 7731fd2..d1d1097 100644
--- a/include/asm-x86/tlbflush_64.h
+++ b/include/asm-x86/tlbflush_64.h
@@ -6,21 +6,8 @@
 #include <asm/processor.h>
 #include <asm/system.h>
 
-static inline void __flush_tlb(void)
-{
-	write_cr3(read_cr3());
-}
-
-static inline void __flush_tlb_all(void)
-{
-	unsigned long cr4 = read_cr4();
-	write_cr4(cr4 & ~X86_CR4_PGE);	/* clear PGE */
-	write_cr4(cr4);			/* write old PGE again and flush TLBs */
-}
-
-#define __flush_tlb_one(addr) \
-	__asm__ __volatile__("invlpg (%0)" :: "r" (addr) : "memory")
-
+#define __flush_tlb_one(addr) __flush_tlb_single(addr)
+#define __flush_tlb_all() __flush_tlb_global()
 
 /*
  * TLB flushing:
@@ -63,32 +50,12 @@ static inline void flush_tlb_range(struct vm_area_struct *vma,
 		__flush_tlb();
 }
 
-#else
-
-#include <asm/smp.h>
-
-#define local_flush_tlb() \
-	__flush_tlb()
-
-extern void flush_tlb_all(void);
-extern void flush_tlb_current_task(void);
-extern void flush_tlb_mm(struct mm_struct *);
-extern void flush_tlb_page(struct vm_area_struct *, unsigned long);
-
-#define flush_tlb()	flush_tlb_current_task()
-
-static inline void flush_tlb_range(struct vm_area_struct * vma, unsigned long start, unsigned long end)
+static inline void native_flush_tlb_others(const cpumask_t *cpumask,
+					   struct mm_struct *mm,
+					   unsigned long va)
 {
-	flush_tlb_mm(vma->vm_mm);
 }
 
-#define TLBSTATE_OK	1
-#define TLBSTATE_LAZY	2
-
-/* Roughly an IPI every 20MB with 4k pages for freeing page table
-   ranges. Cost is about 42k of memory for each CPU. */
-#define ARCH_FREE_PTE_NR 5350	
-
 #endif
 
 static inline void flush_tlb_kernel_range(unsigned long start,
-- 
1.4.4.2


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/

  parent reply	other threads:[~2007-11-09 18:42 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-09 18:42 [PATCH 0/24] paravirt_ops for unified x86 - that's me again! Glauber de Oliveira Costa
     [not found] ` <11946337851964-git-send-email-gcosta-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2007-11-09 18:42   ` [PATCH 1/24] mm/sparse-vmemmap.c: make sure init_mm is included Glauber de Oliveira Costa
     [not found]     ` <11946337933104-git-send-email-gcosta-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2007-11-09 18:42       ` [PATCH 2/24] irqflags consolidation Glauber de Oliveira Costa
     [not found]         ` <11946337991750-git-send-email-gcosta-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2007-11-09 18:42           ` [PATCH 3/24] consolidate spinlock.h Glauber de Oliveira Costa
     [not found]             ` <11946338053158-git-send-email-gcosta-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2007-11-09 18:42               ` Glauber de Oliveira Costa [this message]
     [not found]                 ` <11946338103068-git-send-email-gcosta-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2007-11-09 18:42                   ` [PATCH 5/24] smp x86 consolidation Glauber de Oliveira Costa
2007-11-09 18:42                     ` [PATCH 6/24] Add debugreg/load_rsp native hooks Glauber de Oliveira Costa
     [not found]                       ` <11946338212915-git-send-email-gcosta-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2007-11-09 18:42                         ` [PATCH 7/24] consolidate msr.h Glauber de Oliveira Costa
     [not found]                           ` <11946338263902-git-send-email-gcosta-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2007-11-09 18:42                             ` [PATCH 8/24] consolidate system.h Glauber de Oliveira Costa
     [not found]                               ` <1194633831882-git-send-email-gcosta-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2007-11-09 18:42                                 ` [PATCH 9/24] Wipe out traditional opt from x86_64 Makefile Glauber de Oliveira Costa
     [not found]                                   ` <11946338361369-git-send-email-gcosta-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2007-11-09 18:42                                     ` [PATCH 10/24] paravirt hooks at entry functions Glauber de Oliveira Costa
     [not found]                                       ` <11946338413283-git-send-email-gcosta-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2007-11-09 18:42                                         ` [PATCH 11/24] read/write_crX, clts and wbinvd for 64-bit paravirt Glauber de Oliveira Costa
     [not found]                                           ` <11946338473652-git-send-email-gcosta-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2007-11-09 18:42                                             ` [PATCH 12/24] provide native irq initialization function Glauber de Oliveira Costa
     [not found]                                               ` <1194633852469-git-send-email-gcosta-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2007-11-09 18:42                                                 ` [PATCH 13/24] report ring kernel is running without paravirt Glauber de Oliveira Costa
     [not found]                                                   ` <1194633857930-git-send-email-gcosta-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2007-11-09 18:42                                                     ` [PATCH 14/24] export math_state_restore Glauber de Oliveira Costa
     [not found]                                                       ` <11946338621966-git-send-email-gcosta-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2007-11-09 18:42                                                         ` [PATCH 15/24] native versions for set pagetables Glauber de Oliveira Costa
     [not found]                                                           ` <11946338683305-git-send-email-gcosta-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2007-11-09 18:42                                                             ` [PATCH 16/24] add native functions for descriptors handling Glauber de Oliveira Costa
     [not found]                                                               ` <1194633873306-git-send-email-gcosta-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2007-11-09 18:42                                                                 ` [PATCH 17/24] This patch add provisions for time related functions so they Glauber de Oliveira Costa
     [not found]                                                                   ` <1194633878886-git-send-email-gcosta-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2007-11-09 18:42                                                                     ` [PATCH 18/24] export cpu_gdt_descr Glauber de Oliveira Costa
     [not found]                                                                       ` <11946338832681-git-send-email-gcosta-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2007-11-09 18:43                                                                         ` [PATCH 19/24] turn priviled operation into a macro in head_64.S Glauber de Oliveira Costa
     [not found]                                                                       ` <1194633888761-git-send-email-gco! sta@redhat.com>
     [not found]                                                                         ` <1194633888761-git-send-email-gcosta-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2007-11-09 18:43                                                                           ` [PATCH 20/24] tweak io_64.h for paravirt Glauber de Oliveira Costa
     [not found]                                                                             ` <11946338932611-git-send-email-gcosta-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2007-11-09 18:43                                                                               ` [PATCH 21/24] native versions for page table entries values Glauber de Oliveira Costa
     [not found]                                                                                 ` <1194633898545-git-send-email-gcosta-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2007-11-09 18:43                                                                                   ` [PATCH 22/24] prepare x86_64 architecture initialization for paravirt Glauber de Oliveira Costa
     [not found]                                                                                     ` <11946339033567-git-send-email-gcosta-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2007-11-09 18:43                                                                                       ` [PATCH 23/24] consolidation of paravirt for 32 and 64 bits Glauber de Oliveira Costa
     [not found]                                                                                         ` <11946339082711-git-send-email-gcosta-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2007-11-09 18:43                                                                                           ` [PATCH 24/24] make vsmp a paravirt client Glauber de Oliveira Costa
     [not found]                                                                                             ` <11946339142999-git-send-email-gcosta-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2007-11-11 18:07                                                                                               ` Andi Kleen
     [not found]                                                                                                 ` <20071111180709.GG22277-KvMlXPVkKihbpigZmTR7Iw@public.gmane.org>
2007-11-13 11:36                                                                                                   ` Glauber de Oliveira Costa
     [not found]                                                                                                     ` <47398C4A.40806-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2007-11-13 12:33                                                                                                       ` Andi Kleen
     [not found]                                                                                                         ` <200711131333.41946.ak-l3A5Bk7waGM@public.gmane.org>
2007-11-13 12:51                                                                                                           ` Glauber de Oliveira Costa
     [not found]                                                                                                             ` <47399DC8.7000504-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2007-11-13 13:09                                                                                                               ` Andi Kleen
     [not found]                                                                                                                 ` <200711131409.41959.ak-l3A5Bk7waGM@public.gmane.org>
2007-11-13 18:49                                                                                                                   ` Ravikiran Thirumalai
2007-11-13 17:21                                                                                                               ` Jeremy Fitzhardinge
2007-11-13 18:00                                                                                                       ` Ravikiran Thirumalai
2007-11-19 22:21                             ` [PATCH 7/24] consolidate msr.h Bastian Blank
2007-11-19 22:36                               ` Steven Rostedt
     [not found]                                 ` <Pine.LNX.4.58.0711191734270.32296-f9ZlEuEWxVcI6MkJdU+c8EEOCMrvLtNR@public.gmane.org>
2007-11-20  5:51                                   ` Ingo Molnar
     [not found]                                     ` <20071120055113.GC20436-X9Un+BFzKDI@public.gmane.org>
2007-11-20  6:14                                       ` Steven Rostedt
2007-11-20  6:16                                       ` Steven Rostedt
     [not found]                                         ` <Pine.LNX.4.58.0711200114580.4062-f9ZlEuEWxVcI6MkJdU+c8EEOCMrvLtNR@public.gmane.org>
2007-11-20 10:43                                           ` Rusty Russell
     [not found]                     ` <1194633815833-git-send-email-gcosta-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2007-11-10  0:29                       ` [PATCH 5/24] smp x86 consolidation Jeremy Fitzhardinge
     [not found]                         ` <4734FB67.8080500-TSDbQ3PG+2Y@public.gmane.org>
2007-11-10  1:29                           ` Glauber de Oliveira Costa
     [not found]                             ` <4735098B.7040305-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2007-11-10  2:08                               ` Jeremy Fitzhardinge
2007-11-17  9:32                               ` Ingo Molnar
2007-11-09 23:00       ` [PATCH 1/24] mm/sparse-vmemmap.c: make sure init_mm is included Jeremy Fitzhardinge
     [not found]         ` <4734E6A0.6070508-TSDbQ3PG+2Y@public.gmane.org>
2007-11-10  1:26           ` Glauber de Oliveira Costa
2007-11-12  8:17   ` [PATCH 0/24] paravirt_ops for unified x86 - that's me again! Amit Shah
     [not found]     ` <200711121347.20050.amit.shah-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-11-13 11:43       ` Glauber de Oliveira Costa
2007-11-13 20:26       ` Jeremy Fitzhardinge

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=11946338103068-git-send-email-gcosta@redhat.com \
    --to=gcosta-h+wxahxf7alqt0dzr+alfa@public.gmane.org \
    --cc=ak-l3A5Bk7waGM@public.gmane.org \
    --cc=akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org \
    --cc=avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org \
    --cc=kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
    --cc=lguest-mnsaURCQ41sdnm+yROfE0A@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=virtualization-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
    --cc=zach-pghWNbHTmq7QT0dZR+AlfA@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox