Skip to contentSkip to conversation

x86/mtrr: basic cleanups

PATCH Superseded Doug Goldstein 3 participants 24 messages Aug 16, 2016 – Aug 18, 2016

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover x86/mtrr: basic cleanups

I was stuck on an airplane and as idly reading this code and noticed that Xen does not need multiple MTRR implementations anymore since only x86_64 is supported. This guts some of the indirection and drops what should be dead code paths. I will admit I have only compiled this and not booted it.

Doug Goldstein (9):
x86/mtrr: prefix fns with mtrr and drop static x86/mtrr: drop mtrr_if indirection x86/mtrr: drop have_wrcomb() wrapper x86/mtrr: drop unnecessary use_intel() macro x86/mtrr: drop unused is_cpu() macro x86/mtrr: drop unused mtrr_ops struct x86/mtrr: drop unused positive_have_wrcomb() x86/mtrr: drop unused func prototypes and struct x86/mtrr: use stdbool instead of int + define

 xen/arch/x86/cpu/mtrr/generic.c   | 54 +++++++++++--------------------
 xen/arch/x86/cpu/mtrr/main.c      | 68 +++++++++++----------------------------
 xen/arch/x86/cpu/mtrr/mtrr.h      | 62 ++++++-----------------------------
 xen/arch/x86/platform_hypercall.c |  2 +-
 4 files changed, 48 insertions(+), 138 deletions(-)
Signature · 7 lines
2.7.3


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#1 lore raw

PATCH 1/9 x86/mtrr: prefix fns with mtrr and drop static

For the functions that make up the interface to the MTRR code, drop the static keyword and prefix them all with mtrr for improved clarity when they're called outside this file. This also required adjusting or providing function prototypes to make them callable.

---
 xen/arch/x86/cpu/mtrr/generic.c | 24 ++++++++++++------------
 xen/arch/x86/cpu/mtrr/mtrr.h    | 14 ++++++++++----
 2 files changed, 22 insertions(+), 16 deletions(-)
xen/arch/x86/cpu/mtrr/generic.c +12 -12
index 234d2ba..224d231 100644
@@ -250,7 +250,7 @@ static void set_fixed_range(int msr, int * changed, unsigned int * msrwords)
 	}
 }
 
-int generic_get_free_region(unsigned long base, unsigned long size, int replace_reg)
+int mtrr_generic_get_free_region(unsigned long base, unsigned long size, int replace_reg)
 /*  [SUMMARY] Get a free MTRR.
     <base> The starting (base) address of the region.
     <size> The size (in bytes) of the region.
@@ -272,7 +272,7 @@ int generic_get_free_region(unsigned long base, unsigned long size, int replace_
 	return -ENOSPC;
 }
 
-static void generic_get_mtrr(unsigned int reg, unsigned long *base,
+void mtrr_generic_get(unsigned int reg, unsigned long *base,
 			     unsigned long *size, mtrr_type *type)
 {
 	uint64_t _mask, _base;
@@ -448,7 +448,7 @@ static void post_set(void)
 	spin_unlock(&set_atomicity_lock);
 }
 
-static void generic_set_all(void)
+void mtrr_generic_set_all(void)
 {
 	unsigned long mask, count;
 	unsigned long flags;
@@ -471,7 +471,7 @@ static void generic_set_all(void)
 	
 }
 
-static void generic_set_mtrr(unsigned int reg, unsigned long base,
+void mtrr_generic_set(unsigned int reg, unsigned long base,
 			     unsigned long size, mtrr_type type)
 /*  [SUMMARY] Set variable MTRR register on the local CPU.
     <reg> The register to set.
@@ -514,7 +514,7 @@ static void generic_set_mtrr(unsigned int reg, unsigned long base,
 	local_irq_restore(flags);
 }
 
-int generic_validate_add_page(unsigned long base, unsigned long size, unsigned int type)
+int mtrr_generic_validate_add_page(unsigned long base, unsigned long size, unsigned int type)
 {
 	unsigned long lbase, last;
 
@@ -549,7 +549,7 @@ int generic_validate_add_page(unsigned long base, unsigned long size, unsigned i
 }
 
 
-static int generic_have_wrcomb(void)
+int mtrr_generic_have_wrcomb(void)
 {
 	unsigned long config;
 	rdmsrl(MSR_MTRRcap, config);
@@ -565,10 +565,10 @@ int positive_have_wrcomb(void)
  */
 const struct mtrr_ops generic_mtrr_ops = {
 	.use_intel_if      = 1,
-	.set_all	   = generic_set_all,
-	.get               = generic_get_mtrr,
-	.get_free_region   = generic_get_free_region,
-	.set               = generic_set_mtrr,
-	.validate_add_page = generic_validate_add_page,
-	.have_wrcomb       = generic_have_wrcomb,
+	.set_all	   = mtrr_generic_set_all,
+	.get               = mtrr_generic_get,
+	.get_free_region   = mtrr_generic_get_free_region,
+	.set               = mtrr_generic_set,
+	.validate_add_page = mtrr_generic_validate_add_page,
+	.have_wrcomb       = mtrr_generic_have_wrcomb,
 };
xen/arch/x86/cpu/mtrr/mtrr.h +10 -4
index b41eb58..619575f 100644
@@ -29,10 +29,16 @@ struct mtrr_ops {
 	int	(*have_wrcomb)(void);
 };
 
-extern int generic_get_free_region(unsigned long base, unsigned long size,
-				   int replace_reg);
-extern int generic_validate_add_page(unsigned long base, unsigned long size,
-				     unsigned int type);
+void mtrr_generic_get(unsigned int reg, unsigned long *base,
+        unsigned long *size, mtrr_type *type);
+int mtrr_generic_get_free_region(unsigned long base, unsigned long size,
+        int replace_reg);
+int mtrr_generic_validate_add_page(unsigned long base, unsigned long size,
+        unsigned int type);
+void mtrr_generic_set_all(void);
+void mtrr_generic_set(unsigned int reg, unsigned long base,
+        unsigned long size, mtrr_type type);
+int mtrr_generic_have_wrcomb(void);
 
 extern const struct mtrr_ops generic_mtrr_ops;
 
Signature · 7 lines
2.7.3


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#2 lore raw

Re: [PATCH 1/9] x86/mtrr: prefix fns with mtrr and drop static

Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 17.08.16 at 01:28, <[email protected]> wrote:

For the functions that make up the interface to the MTRR code, drop the static keyword and prefix them all with mtrr for improved clarity when they're called outside this file. This also required adjusting or providing function prototypes to make them callable.

I can see why you want to do this for non-static functions, but I can't see why static ones would need to get altered (unless you mean to call them directly in subsequent patches, in which case the rationale above should be adjusted). Nor can I see why the two functions previously having been non-static can't simply be made static, without changing their names, as the patch demonstrates that they don't have callers in other CUs.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#3 lore raw

Re: [PATCH 1/9] x86/mtrr: prefix fns with mtrr and drop static

Quoted 14 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 17.08.16 at 01:28, <[email protected]> wrote:

For the functions that make up the interface to the MTRR code, drop the static keyword and prefix them all with mtrr for improved clarity when they're called outside this file. This also required adjusting or providing function prototypes to make them callable.

I can see why you want to do this for non-static functions, but I can't see why static ones would need to get altered (unless you mean to call them directly in subsequent patches, in which case the rationale above should be adjusted). Nor can I see why the two functions previously having been non-static can't simply be made static, without changing their names, as the patch demonstrates that they don't have callers in other CUs.

Quoted 2 lines

Jan

I've added:

Future changes will directly call these functions instead of using the indirect call through the ops structure.

Does that work?

Signature · 1 line
Doug Goldstein

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#4 lore raw

Re: [PATCH 1/9] x86/mtrr: prefix fns with mtrr and drop static

Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 18.08.16 at 03:38, <[email protected]> wrote:
Quoted 6 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 17.08.16 at 01:28, <[email protected]> wrote:

For the functions that make up the interface to the MTRR code, drop the static keyword and prefix them all with mtrr for improved clarity when they're called outside this file. This also required adjusting or providing function prototypes to make them callable.

Quoted 7 lines

I can see why you want to do this for non-static functions, but I can't see why static ones would need to get altered (unless you mean to call them directly in subsequent patches, in which case the rationale above should be adjusted). Nor can I see why the two functions previously having been non-static can't simply be made static, without changing their names, as the patch demonstrates that they don't have callers in other CUs.

Quoted 6 lines

I've added:

Future changes will directly call these functions instead of using the indirect call through the ops structure.

Does that work?

Sure, having seen the further parts of the series.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#5 lore raw

PATCH 2/9 x86/mtrr: drop mtrr_if indirection

In reply to Doug Goldstein

There can only ever be one mtrr_if now and that is the generic implementation so instead of going through an indirect call change everything to call the generic implementation directly. The is_cpu() macro would result in the left side always being equal to X86_VENDOR_INTEL for the generic implementation due to Intel having a value of 0. The use_intel() macro was always true in the generic implementation case as well. Removed some extraneous whitespace at the same time.

---
 xen/arch/x86/cpu/mtrr/generic.c   |  2 +-
 xen/arch/x86/cpu/mtrr/main.c      | 47 ++++++++++++++-------------------------
 xen/arch/x86/cpu/mtrr/mtrr.h      |  4 ++--
 xen/arch/x86/platform_hypercall.c |  2 +-
 4 files changed, 21 insertions(+), 34 deletions(-)
xen/arch/x86/cpu/mtrr/generic.c +1 -1
index 224d231..5c4b273 100644
@@ -265,7 +265,7 @@ int mtrr_generic_get_free_region(unsigned long base, unsigned long size, int rep
 	if (replace_reg >= 0 && replace_reg < max)
 		return replace_reg;
 	for (i = 0; i < max; ++i) {
-		mtrr_if->get(i, &lbase, &lsize, &ltype);
+		mtrr_generic_get(i, &lbase, &lsize, &ltype);
 		if (lsize == 0)
 			return i;
 	}
xen/arch/x86/cpu/mtrr/main.c +17 -30

138 lines not on this page · raw message

xen/arch/x86/cpu/mtrr/mtrr.h +2 -2
index 619575f..92b0b11 100644
@@ -63,8 +63,8 @@ extern void set_mtrr_ops(const struct mtrr_ops *);
 extern u64 size_or_mask, size_and_mask;
 extern const struct mtrr_ops *mtrr_if;
 
-#define is_cpu(vnd)	(mtrr_if && mtrr_if->vendor == X86_VENDOR_##vnd)
-#define use_intel()	(mtrr_if && mtrr_if->use_intel_if == 1)
+#define is_cpu(vnd)	(X86_VENDOR_INTEL == X86_VENDOR_##vnd)
+#define use_intel()	(1)
 
 extern unsigned int num_var_ranges;
 
xen/arch/x86/platform_hypercall.c +1 -1
index 780f22d..4a294b4 100644
@@ -265,7 +265,7 @@ ret_t do_platform_op(XEN_GUEST_HANDLE_PARAM(xen_platform_op_t) u_xenpf_op)
         ret = -EINVAL;
         if ( op->u.read_memtype.reg < num_var_ranges )
         {
-            mtrr_if->get(op->u.read_memtype.reg, &mfn, &nr_mfns, &type);
+            mtrr_generic_get(op->u.read_memtype.reg, &mfn, &nr_mfns, &type);
             op->u.read_memtype.mfn     = mfn;
             op->u.read_memtype.nr_mfns = nr_mfns;
             op->u.read_memtype.type    = type;
Signature · 7 lines
2.7.3


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#6 lore raw

Re: [PATCH 2/9] x86/mtrr: drop mtrr_if indirection

Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 17.08.16 at 01:28, <[email protected]> wrote:

There can only ever be one mtrr_if now and that is the generic implementation

This is only true when taking into consideration that cpu_has_mtrr is #define-d to 1 right now. I'm not sure that's actually a good assumption (especially when think about running Xen itself virtualized, or possibly adding a mode of operation where no MTRRs are to be used). But if we want to keep it that way, then I'd suggest this patch should include removing cpu_has_mtrr (which will then show to the reviewers that the checks of mtrr_if against NULL indeed are dead code.

Quoted 10 lines
xen/arch/x86/cpu/mtrr/main.c +0 -2
@@ -569,22 +561,19 @@ struct mtrr_value {
 void __init mtrr_bp_init(void)
 {
 	if (cpu_has_mtrr) {
-		mtrr_if = &generic_mtrr_ops;
 		size_or_mask = ~((1ULL << (paddr_bits - PAGE_SHIFT)) - 1);
 		size_and_mask = ~size_or_mask & 0xfffff00000ULL;
 	}
 
-	if (mtrr_if) {

xen/arch/x86/cpu/mtrr/main.c struct mtrr_value { · line 572

Quoted 10 lines
xen/arch/x86/cpu/mtrr/main.c +4 -5
-		set_num_var_ranges();
-		init_table();
-		if (use_intel())
-			get_mtrr_state();
-	}
+    set_num_var_ranges();
+    init_table();
+    if (use_intel())
+        get_mtrr_state();
 }

Please don't break indentation style.

xen/arch/x86/cpu/mtrr/mtrr.h extern void set_mtrr_ops(const struct mtrr_ops *); · line 67

Quoted 10 lines
xen/arch/x86/cpu/mtrr/mtrr.h +2 -2
@@ -63,8 +63,8 @@ extern void set_mtrr_ops(const struct mtrr_ops *);
 extern u64 size_or_mask, size_and_mask;
 extern const struct mtrr_ops *mtrr_if;
 
-#define is_cpu(vnd)	(mtrr_if && mtrr_if->vendor == X86_VENDOR_##vnd)
-#define use_intel()	(mtrr_if && mtrr_if->use_intel_if == 1)
+#define is_cpu(vnd)	(X86_VENDOR_INTEL == X86_VENDOR_##vnd)
+#define use_intel()	(1)

Is the latter really useful to keep then?

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#7 lore raw

Re: [PATCH 2/9] x86/mtrr: drop mtrr_if indirection

Quoted 4 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 17.08.16 at 01:28, <[email protected]> wrote:

There can only ever be one mtrr_if now and that is the generic implementation

Quoted 8 lines

This is only true when taking into consideration that cpu_has_mtrr is #define-d to 1 right now. I'm not sure that's actually a good assumption (especially when think about running Xen itself virtualized, or possibly adding a mode of operation where no MTRRs are to be used). But if we want to keep it that way, then I'd suggest this patch should include removing cpu_has_mtrr (which will then show to the reviewers that the checks of mtrr_if against NULL indeed are dead code.

Sure I can remove cpu_has_mtrr that would certainly make it cleaner. Is it ok with you and Andrew to make the assumption that we'll always have MTRRs (until the day we don't like you described)?

Quoted 10 lines
Quoted 10 lines
xen/arch/x86/cpu/mtrr/main.c +0 -1
@@ -569,22 +561,19 @@ struct mtrr_value {
 void __init mtrr_bp_init(void)
 {
 	if (cpu_has_mtrr) {
-		mtrr_if = &generic_mtrr_ops;
 		size_or_mask = ~((1ULL << (paddr_bits - PAGE_SHIFT)) - 1);
 		size_and_mask = ~size_or_mask & 0xfffff00000ULL;
 	}
 
Quoted 13 lines

xen/arch/x86/cpu/mtrr/main.c struct mtrr_value { · line 572

Quoted 11 lines
xen/arch/x86/cpu/mtrr/main.c +4 -6
-	if (mtrr_if) {
-		set_num_var_ranges();
-		init_table();
-		if (use_intel())
-			get_mtrr_state();
-	}
+    set_num_var_ranges();
+    init_table();
+    if (use_intel())
+        get_mtrr_state();
 }

Please don't break indentation style.

Sad panda. This file has tabs. Sorry I missed that.

Quoted 7 lines
Quoted 7 lines
xen/arch/x86/cpu/mtrr/mtrr.h +0 -0
@@ -63,8 +63,8 @@ extern void set_mtrr_ops(const struct mtrr_ops *);
 extern u64 size_or_mask, size_and_mask;
 extern const struct mtrr_ops *mtrr_if;
 
Quoted 6 lines

xen/arch/x86/cpu/mtrr/mtrr.h extern void set_mtrr_ops(const struct mtrr_ops *); · line 67

Quoted 4 lines
xen/arch/x86/cpu/mtrr/mtrr.h +2 -2
-#define is_cpu(vnd)	(mtrr_if && mtrr_if->vendor == X86_VENDOR_##vnd)
-#define use_intel()	(mtrr_if && mtrr_if->use_intel_if == 1)
+#define is_cpu(vnd)	(X86_VENDOR_INTEL == X86_VENDOR_##vnd)
+#define use_intel()	(1)

Is the latter really useful to keep then?

Would you like me to squash patch 4 into this or make a note in the commit message that further clean ups are coming?

--
Doug Goldstein

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#8 lore raw

Re: [PATCH 2/9] x86/mtrr: drop mtrr_if indirection

Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 18.08.16 at 03:59, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 17.08.16 at 01:28, <[email protected]> wrote:

There can only ever be one mtrr_if now and that is the generic implementation

Quoted 8 lines

This is only true when taking into consideration that cpu_has_mtrr is #define-d to 1 right now. I'm not sure that's actually a good assumption (especially when think about running Xen itself virtualized, or possibly adding a mode of operation where no MTRRs are to be used). But if we want to keep it that way, then I'd suggest this patch should include removing cpu_has_mtrr (which will then show to the reviewers that the checks of mtrr_if against NULL indeed are dead code.

Quoted 3 lines

Sure I can remove cpu_has_mtrr that would certainly make it cleaner. Is it ok with you and Andrew to make the assumption that we'll always have MTRRs (until the day we don't like you described)?

Well, that's what I've basically put up for discussion. My personal preference would be to drop the hard coding of cpu_has_mtrr (and hence keep it as well as mtrr_if).

Quoted 13 lines
Quoted 6 lines
Quoted 6 lines
xen/arch/x86/cpu/mtrr/mtrr.h +0 -0
@@ -63,8 +63,8 @@ extern void set_mtrr_ops(const struct mtrr_ops *);
 extern u64 size_or_mask, size_and_mask;
 extern const struct mtrr_ops *mtrr_if;
 
Quoted 6 lines

xen/arch/x86/cpu/mtrr/mtrr.h extern void set_mtrr_ops(const struct mtrr_ops *); · line 67

Quoted 4 lines
xen/arch/x86/cpu/mtrr/mtrr.h +2 -2
-#define is_cpu(vnd)	(mtrr_if && mtrr_if->vendor == X86_VENDOR_##vnd)
-#define use_intel()	(mtrr_if && mtrr_if->use_intel_if == 1)
+#define is_cpu(vnd)	(X86_VENDOR_INTEL == X86_VENDOR_##vnd)
+#define use_intel()	(1)

Is the latter really useful to keep then?

Quoted 2 lines

Would you like me to squash patch 4 into this or make a note in the commit message that further clean ups are coming?

Either way is fine with me, all I wish is for it to be clear that you don't stop half ways with the cleanup (which I'm glad you took a stab on, btw).

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#9 lore raw

Re: [PATCH 2/9] x86/mtrr: drop mtrr_if indirection

In reply to Doug Goldstein
Quoted 12 lines · Doug Goldstein
Quoted 11 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 17.08.16 at 01:28, <[email protected]> wrote:

There can only ever be one mtrr_if now and that is the generic implementation

This is only true when taking into consideration that cpu_has_mtrr is #define-d to 1 right now. I'm not sure that's actually a good assumption (especially when think about running Xen itself virtualized, or possibly adding a mode of operation where no MTRRs are to be used). But if we want to keep it that way, then I'd suggest this patch should include removing cpu_has_mtrr (which will then show to the reviewers that the checks of mtrr_if against NULL indeed are dead code.

Quoted 3 lines

Sure I can remove cpu_has_mtrr that would certainly make it cleaner. Is it ok with you and Andrew to make the assumption that we'll always have MTRRs (until the day we don't like you described)?

Please don't remove cpu_has_mtrr. I plan to make better use of it with the future plan to move PV guests into a PVH container.

In such a case, the PVH container won't want/need MTRRs, and we will get better performance by not having them available.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#10 lore raw

PATCH 3/9 x86/mtrr: drop have_wrcomb() wrapper

In reply to Doug Goldstein

The only call was always to the generic implementation.

---
 xen/arch/x86/cpu/mtrr/main.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
xen/arch/x86/cpu/mtrr/main.c +1 -7
index ff908ad..5dd1f5d 100644
@@ -77,12 +77,6 @@ static const char *mtrr_attrib_to_str(int x)
 	return (x <= 6) ? mtrr_strings[x] : "?";
 }
 
-/*  Returns non-zero if we have the write-combining memory type  */
-static int have_wrcomb(void)
-{
-	return mtrr_generic_have_wrcomb();
-}
-
 /*  This function returns the number of variable MTRRs  */
 static void __init set_num_var_ranges(void)
 {
@@ -324,7 +318,7 @@ int mtrr_add_page(unsigned long base, unsigned long size,
 	}
 
 	/*  If the type is WC, check that this processor supports it  */
-	if ((type == MTRR_TYPE_WRCOMB) && !have_wrcomb()) {
+	if ((type == MTRR_TYPE_WRCOMB) && !mtrr_generic_have_wrcomb()) {
 		printk(KERN_WARNING
 		       "mtrr: your processor doesn't support write-combining\n");
 		return -ENOSYS;
Signature · 7 lines
2.7.3


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#12 lore raw

PATCH 4/9 x86/mtrr: drop unnecessary use_intel() macro

In reply to Doug Goldstein

The use_intel() macro always evaluates to true so don't bother using it.

---
 xen/arch/x86/cpu/mtrr/main.c | 21 ++++-----------------
 xen/arch/x86/cpu/mtrr/mtrr.h |  1 -
 2 files changed, 4 insertions(+), 18 deletions(-)
xen/arch/x86/cpu/mtrr/main.c +4 -17
index 5dd1f5d..6f0113a 100644
@@ -82,12 +82,7 @@ static void __init set_num_var_ranges(void)
 {
 	unsigned long config = 0;
 
-	if (use_intel()) {
-		rdmsrl(MSR_MTRRcap, config);
-	} else if (is_cpu(AMD))
-		config = 2;
-	else if (is_cpu(CYRIX) || is_cpu(CENTAUR))
-		config = 8;
+    rdmsrl(MSR_MTRRcap, config);
 	num_var_ranges = config & 0xff;
 }
 
@@ -561,13 +556,12 @@ void __init mtrr_bp_init(void)
 
     set_num_var_ranges();
     init_table();
-    if (use_intel())
-        get_mtrr_state();
+    get_mtrr_state();
 }
 
 void mtrr_ap_init(void)
 {
-	if (!use_intel() || hold_mtrr_updates_on_aps)
+	if (hold_mtrr_updates_on_aps)
 		return;
 	/*
 	 * Ideally we should hold mtrr_mutex here to avoid mtrr entries changed,
@@ -596,30 +590,23 @@ void mtrr_save_state(void)
 
 void mtrr_aps_sync_begin(void)
 {
-	if (!use_intel())
-		return;
 	hold_mtrr_updates_on_aps = 1;
 }
 
 void mtrr_aps_sync_end(void)
 {
-	if (!use_intel())
-		return;
 	set_mtrr(~0U, 0, 0, 0);
 	hold_mtrr_updates_on_aps = 0;
 }
 
 void mtrr_bp_restore(void)
 {
-	if (!use_intel())
-		return;
 	mtrr_generic_set_all();
 }
 
 static int __init mtrr_init_finialize(void)
 {
-	if (use_intel())
-		mtrr_state_warn();
+    mtrr_state_warn();
 	return 0;
 }
 __initcall(mtrr_init_finialize);
xen/arch/x86/cpu/mtrr/mtrr.h +0 -1
index 92b0b11..5e0d832 100644
@@ -64,7 +64,6 @@ extern u64 size_or_mask, size_and_mask;
 extern const struct mtrr_ops *mtrr_if;
 
 #define is_cpu(vnd)	(X86_VENDOR_INTEL == X86_VENDOR_##vnd)
-#define use_intel()	(1)
 
 extern unsigned int num_var_ranges;
 
Signature · 7 lines
2.7.3


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#13 lore raw

Re: [PATCH 4/9] x86/mtrr: drop unnecessary use_intel() macro

Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 17.08.16 at 01:28, <[email protected]> wrote:

The use_intel() macro always evaluates to true so don't bother using it.

Ah, here we go. But there are indentation issues again here.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#14 lore raw

PATCH 5/9 x86/mtrr: drop unused is_cpu() macro

In reply to Doug Goldstein

is_cpu() evaluated to Intel always so just drop it entirely.

---
 xen/arch/x86/cpu/mtrr/generic.c | 2 +-
 xen/arch/x86/cpu/mtrr/mtrr.h    | 2 --
 2 files changed, 1 insertion(+), 3 deletions(-)
xen/arch/x86/cpu/mtrr/generic.c +1 -1
index 5c4b273..45d4def 100644
@@ -520,7 +520,7 @@ int mtrr_generic_validate_add_page(unsigned long base, unsigned long size, unsig
 
 	/*  For Intel PPro stepping <= 7, must be 4 MiB aligned 
 	    and not touch 0x70000000->0x7003FFFF */
-	if (is_cpu(INTEL) && boot_cpu_data.x86 == 6 &&
+	if (boot_cpu_data.x86 == 6 &&
 	    boot_cpu_data.x86_model == 1 &&
 	    boot_cpu_data.x86_mask <= 7) {
 		if (base & ((1 << (22 - PAGE_SHIFT)) - 1)) {
xen/arch/x86/cpu/mtrr/mtrr.h +0 -2
index 5e0d832..25f4867 100644
@@ -63,8 +63,6 @@ extern void set_mtrr_ops(const struct mtrr_ops *);
 extern u64 size_or_mask, size_and_mask;
 extern const struct mtrr_ops *mtrr_if;
 
-#define is_cpu(vnd)	(X86_VENDOR_INTEL == X86_VENDOR_##vnd)
-
 extern unsigned int num_var_ranges;
 
 void mtrr_state_warn(void);
Signature · 7 lines
2.7.3


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#15 lore raw

Re: [PATCH 5/9] x86/mtrr: drop unused is_cpu() macro

xen/arch/x86/cpu/mtrr/generic.c int mtrr_generic_validate_add_page(unsigned long base, unsigned long size, unsig · line 526

Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 17.08.16 at 01:28, <[email protected]> wrote:
xen/arch/x86/cpu/mtrr/generic.c +1 -1
@@ -520,7 +520,7 @@ int mtrr_generic_validate_add_page(unsigned long base, unsigned long size, unsig
 
 	/*  For Intel PPro stepping <= 7, must be 4 MiB aligned 
 	    and not touch 0x70000000->0x7003FFFF */
-	if (is_cpu(INTEL) && boot_cpu_data.x86 == 6 &&
+	if (boot_cpu_data.x86 == 6 &&
 	    boot_cpu_data.x86_model == 1 &&
 	    boot_cpu_data.x86_mask <= 7) {
 		if (base & ((1 << (22 - PAGE_SHIFT)) - 1)) {

Well, this check then was and is (a) wrong (regardless of the MTRR flavor used the family/model/stepping check has to be CPU vendor specific) and (b) dead code (we don't run on PPro-s anymore). Please instead delete it altogether.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#16 lore raw

PATCH 6/9 x86/mtrr: drop unused mtrr_ops struct

In reply to Doug Goldstein

There are no users of the mtrr_ops struct or any of the callers on it so drop those.

---
 xen/arch/x86/cpu/mtrr/generic.c | 12 ------------
 xen/arch/x86/cpu/mtrr/mtrr.h    | 23 -----------------------
 2 files changed, 35 deletions(-)
xen/arch/x86/cpu/mtrr/generic.c +0 -12
index 45d4def..1d67035 100644
@@ -560,15 +560,3 @@ int positive_have_wrcomb(void)
 {
 	return 1;
 }
-
-/* generic structure...
- */
-const struct mtrr_ops generic_mtrr_ops = {
-	.use_intel_if      = 1,
-	.set_all	   = mtrr_generic_set_all,
-	.get               = mtrr_generic_get,
-	.get_free_region   = mtrr_generic_get_free_region,
-	.set               = mtrr_generic_set,
-	.validate_add_page = mtrr_generic_validate_add_page,
-	.have_wrcomb       = mtrr_generic_have_wrcomb,
-};
xen/arch/x86/cpu/mtrr/mtrr.h +0 -23
index 25f4867..9391fc5 100644
@@ -11,24 +11,6 @@
 #define MTRR_CHANGE_MASK_VARIABLE  0x02
 #define MTRR_CHANGE_MASK_DEFTYPE   0x04
 
-
-struct mtrr_ops {
-	u32	vendor;
-	u32	use_intel_if;
-//	void	(*init)(void);
-	void	(*set)(unsigned int reg, unsigned long base,
-		       unsigned long size, mtrr_type type);
-	void	(*set_all)(void);
-
-	void	(*get)(unsigned int reg, unsigned long *base,
-		       unsigned long *size, mtrr_type * type);
-	int	(*get_free_region)(unsigned long base, unsigned long size,
-				   int replace_reg);
-	int	(*validate_add_page)(unsigned long base, unsigned long size,
-				     unsigned int type);
-	int	(*have_wrcomb)(void);
-};
-
 void mtrr_generic_get(unsigned int reg, unsigned long *base,
         unsigned long *size, mtrr_type *type);
 int mtrr_generic_get_free_region(unsigned long base, unsigned long size,
@@ -40,8 +22,6 @@ void mtrr_generic_set(unsigned int reg, unsigned long base,
         unsigned long size, mtrr_type type);
 int mtrr_generic_have_wrcomb(void);
 
-extern const struct mtrr_ops generic_mtrr_ops;
-
 extern int positive_have_wrcomb(void);
 
 /* library functions for processor-specific routines */
@@ -58,10 +38,7 @@ void set_mtrr_prepare_save(struct set_mtrr_context *ctxt);
 
 void get_mtrr_state(void);
 
-extern void set_mtrr_ops(const struct mtrr_ops *);
-
 extern u64 size_or_mask, size_and_mask;
-extern const struct mtrr_ops *mtrr_if;
 
 extern unsigned int num_var_ranges;
 
Signature · 7 lines
2.7.3


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Acked-by on v1 6/9
#17 lore raw

Re: [PATCH 6/9] x86/mtrr: drop unused mtrr_ops struct

Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 17.08.16 at 01:28, <[email protected]> wrote:

There are no users of the mtrr_ops struct or any of the callers on it so drop those.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#18 lore raw

PATCH 7/9 x86/mtrr: drop unused positive_have_wrcomb()

In reply to Doug Goldstein

Unused function, gone.

---
 xen/arch/x86/cpu/mtrr/generic.c | 5 -----
 xen/arch/x86/cpu/mtrr/mtrr.h    | 2 --
 2 files changed, 7 deletions(-)
xen/arch/x86/cpu/mtrr/generic.c +0 -5
index 1d67035..012aca4 100644
@@ -555,8 +555,3 @@ int mtrr_generic_have_wrcomb(void)
 	rdmsrl(MSR_MTRRcap, config);
 	return (config & (1ULL << 10));
 }
-
-int positive_have_wrcomb(void)
-{
-	return 1;
-}
xen/arch/x86/cpu/mtrr/mtrr.h +0 -2
index 9391fc5..9405cbc 100644
@@ -22,8 +22,6 @@ void mtrr_generic_set(unsigned int reg, unsigned long base,
         unsigned long size, mtrr_type type);
 int mtrr_generic_have_wrcomb(void);
 
-extern int positive_have_wrcomb(void);
-
 /* library functions for processor-specific routines */
 struct set_mtrr_context {
 	unsigned long flags;
Signature · 7 lines
2.7.3


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Acked-by on v1 7/9
#19 lore raw

Re: [PATCH 7/9] x86/mtrr: drop unused positive_have_wrcomb()

Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 17.08.16 at 01:28, <[email protected]> wrote:

Unused function, gone.

But perhaps worth getting folded into the one dropping have_wrcomb() (the acks for both patches can be retained for the merged result).

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#20 lore raw

PATCH 8/9 x86/mtrr: drop unused func prototypes and struct

In reply to Doug Goldstein

These weren't used so drop them.

---
 xen/arch/x86/cpu/mtrr/mtrr.h | 15 ---------------
 1 file changed, 15 deletions(-)
xen/arch/x86/cpu/mtrr/mtrr.h +0 -15
index 9405cbc..1a3b1e5 100644
@@ -22,18 +22,6 @@ void mtrr_generic_set(unsigned int reg, unsigned long base,
         unsigned long size, mtrr_type type);
 int mtrr_generic_have_wrcomb(void);
 
-/* library functions for processor-specific routines */
-struct set_mtrr_context {
-	unsigned long flags;
-	unsigned long cr4val;
-	uint64_t deftype;
-	u32 ccr3;
-};
-
-void set_mtrr_done(struct set_mtrr_context *ctxt);
-void set_mtrr_cache_disable(struct set_mtrr_context *ctxt);
-void set_mtrr_prepare_save(struct set_mtrr_context *ctxt);
-
 void get_mtrr_state(void);
 
 extern u64 size_or_mask, size_and_mask;
@@ -41,6 +29,3 @@ extern u64 size_or_mask, size_and_mask;
 extern unsigned int num_var_ranges;
 
 void mtrr_state_warn(void);
-
-extern int amd_init_mtrr(void);
-extern int cyrix_init_mtrr(void);
Signature · 7 lines
2.7.3


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#22 lore raw

PATCH 9/9 x86/mtrr: use stdbool instead of int + define

In reply to Doug Goldstein

Instead of using an int and providing a define for TRUE and FALSE, change the code to use stdbool that Xen provides.

---
 xen/arch/x86/cpu/mtrr/generic.c | 21 +++++++++++----------
 xen/arch/x86/cpu/mtrr/mtrr.h    |  5 -----
 2 files changed, 11 insertions(+), 15 deletions(-)
xen/arch/x86/cpu/mtrr/generic.c +11 -10
index 012aca4..2d2eadc 100644
@@ -3,6 +3,7 @@
 #include <xen/lib.h>
 #include <xen/init.h>
 #include <xen/mm.h>
+#include <xen/stdbool.h>
 #include <asm/flushtlb.h>
 #include <asm/io.h>
 #include <asm/mtrr.h>
@@ -237,7 +238,7 @@ static void mtrr_wrmsr(unsigned int msr, uint64_t msr_content)
  * \param changed pointer which indicates whether the MTRR needed to be changed
  * \param msrwords pointer to the MSR values which the MSR should have
  */
-static void set_fixed_range(int msr, int * changed, unsigned int * msrwords)
+static void set_fixed_range(int msr, bool * changed, unsigned int * msrwords)
 {
 	uint64_t msr_content, val;
 
@@ -246,7 +247,7 @@ static void set_fixed_range(int msr, int * changed, unsigned int * msrwords)
 
 	if (msr_content != val) {
 		mtrr_wrmsr(msr, val);
-		*changed = TRUE;
+		*changed = true;
 	}
 }
 
@@ -302,10 +303,10 @@ void mtrr_generic_get(unsigned int reg, unsigned long *base,
  * Checks and updates the fixed-range MTRRs if they differ from the saved set
  * \param frs pointer to fixed-range MTRR values, saved by get_fixed_ranges()
  */
-static int set_fixed_ranges(mtrr_type * frs)
+static bool set_fixed_ranges(mtrr_type * frs)
 {
 	unsigned long long *saved = (unsigned long long *) frs;
-	int changed = FALSE;
+	bool changed = false;
 	int block=-1, range;
 
 	while (fixed_range_blocks[++block].ranges)
@@ -316,13 +317,13 @@ static int set_fixed_ranges(mtrr_type * frs)
 	return changed;
 }
 
-/*  Set the MSR pair relating to a var range. Returns TRUE if
+/*  Set the MSR pair relating to a var range. Returns true if
     changes are made  */
-static int set_mtrr_var_ranges(unsigned int index, struct mtrr_var_range *vr)
+static bool set_mtrr_var_ranges(unsigned int index, struct mtrr_var_range *vr)
 {
 	uint32_t lo, hi, base_lo, base_hi, mask_lo, mask_hi;
 	uint64_t msr_content;
-	int changed = FALSE;
+	bool changed = false;
 
 	rdmsrl(MSR_IA32_MTRR_PHYSBASE(index), msr_content);
 	lo = (uint32_t)msr_content;
@@ -337,7 +338,7 @@ static int set_mtrr_var_ranges(unsigned int index, struct mtrr_var_range *vr)
 
 	if ((base_lo != lo) || (base_hi != hi)) {
 		mtrr_wrmsr(MSR_IA32_MTRR_PHYSBASE(index), vr->base);
-		changed = TRUE;
+		changed = true;
 	}
 
 	rdmsrl(MSR_IA32_MTRR_PHYSMASK(index), msr_content);
@@ -353,7 +354,7 @@ static int set_mtrr_var_ranges(unsigned int index, struct mtrr_var_range *vr)
 
 	if ((mask_lo != lo) || (mask_hi != hi)) {
 		mtrr_wrmsr(MSR_IA32_MTRR_PHYSMASK(index), vr->mask);
-		changed = TRUE;
+		changed = true;
 	}
 	return changed;
 }
@@ -478,7 +479,7 @@ void mtrr_generic_set(unsigned int reg, unsigned long base,
     <base> The base address of the region.
     <size> The size of the region. If this is 0 the region is disabled.
     <type> The type of the region.
-    <do_safe> If TRUE, do the change safely. If FALSE, safety measures should
+    <do_safe> If true, do the change safely. If false, safety measures should
     be done externally.
     [RETURNS] Nothing.
 */
xen/arch/x86/cpu/mtrr/mtrr.h +0 -5
index 1a3b1e5..9d55c68 100644
@@ -2,11 +2,6 @@
  * local mtrr defines.
  */
 
-#ifndef TRUE
-#define TRUE  1
-#define FALSE 0
-#endif
-
 #define MTRR_CHANGE_MASK_FIXED     0x01
 #define MTRR_CHANGE_MASK_VARIABLE  0x02
 #define MTRR_CHANGE_MASK_DEFTYPE   0x04
Signature · 7 lines
2.7.3


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#23 lore raw

Re: [PATCH 9/9] x86/mtrr: use stdbool instead of int + define

xen/arch/x86/cpu/mtrr/generic.c line 6

Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 17.08.16 at 01:28, <[email protected]> wrote:
xen/arch/x86/cpu/mtrr/generic.c +1 -0
@@ -3,6 +3,7 @@
 #include <xen/lib.h>
 #include <xen/init.h>
 #include <xen/mm.h>
+#include <xen/stdbool.h>

Is this really needed, with xen/types.h already including it?

xen/arch/x86/cpu/mtrr/generic.c static void mtrr_wrmsr(unsigned int msr, uint64_t msr_content) · line 241

Quoted 6 lines
xen/arch/x86/cpu/mtrr/generic.c +1 -1
@@ -237,7 +238,7 @@ static void mtrr_wrmsr(unsigned int msr, uint64_t msr_content)
  * \param changed pointer which indicates whether the MTRR needed to be changed
  * \param msrwords pointer to the MSR values which the MSR should have
  */
-static void set_fixed_range(int msr, int * changed, unsigned int * msrwords)
+static void set_fixed_range(int msr, bool * changed, unsigned int * msrwords)

Please drop the stray blanks while touching this.

xen/arch/x86/cpu/mtrr/generic.c void mtrr_generic_set(unsigned int reg, unsigned long base, · line 483

Quoted 7 lines
xen/arch/x86/cpu/mtrr/generic.c +1 -1
@@ -478,7 +479,7 @@ void mtrr_generic_set(unsigned int reg, unsigned long base,
     <base> The base address of the region.
     <size> The size of the region. If this is 0 the region is disabled.
     <type> The type of the region.
-    <do_safe> If TRUE, do the change safely. If FALSE, safety measures should
+    <do_safe> If true, do the change safely. If false, safety measures should
     be done externally.

Please drop this stale comment portion instead of adjusting it.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel