[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <168597409499.404.18296081560876564264.tip-bot2@tip-bot2>
Date: Mon, 05 Jun 2023 14:08:14 -0000
From: "tip-bot2 for Juergen Gross" <tip-bot2@...utronix.de>
To: linux-tip-commits@...r.kernel.org
Cc: Juergen Gross <jgross@...e.com>,
"Borislav Petkov (AMD)" <bp@...en8.de>,
Michael Kelley <mikelley@...rosoft.com>, x86@...nel.org,
linux-kernel@...r.kernel.org
Subject: [tip: x86/mtrr] x86/mtrr: Add get_effective_type() service function
The following commit has been merged into the x86/mtrr branch of tip:
Commit-ID: 1ca12099040fec8c6bbcd9fabf37f04ac0d08e48
Gitweb: https://git.kernel.org/tip/1ca12099040fec8c6bbcd9fabf37f04ac0d08e48
Author: Juergen Gross <jgross@...e.com>
AuthorDate: Tue, 02 May 2023 14:09:25 +02:00
Committer: Borislav Petkov (AMD) <bp@...en8.de>
CommitterDate: Thu, 01 Jun 2023 15:04:33 +02:00
x86/mtrr: Add get_effective_type() service function
Add a service function for obtaining the effective cache mode of
overlapping MTRR registers.
Make use of that function in check_type_overlap().
Signed-off-by: Juergen Gross <jgross@...e.com>
Signed-off-by: Borislav Petkov (AMD) <bp@...en8.de>
Tested-by: Michael Kelley <mikelley@...rosoft.com>
Link: https://lore.kernel.org/r/20230502120931.20719-11-jgross@suse.com
Signed-off-by: Borislav Petkov (AMD) <bp@...en8.de>
---
arch/x86/kernel/cpu/mtrr/generic.c | 39 ++++++++++++++---------------
1 file changed, 19 insertions(+), 20 deletions(-)
diff --git a/arch/x86/kernel/cpu/mtrr/generic.c b/arch/x86/kernel/cpu/mtrr/generic.c
index 4d8ca62..b944271 100644
--- a/arch/x86/kernel/cpu/mtrr/generic.c
+++ b/arch/x86/kernel/cpu/mtrr/generic.c
@@ -80,31 +80,30 @@ static u64 get_mtrr_size(u64 mask)
return size;
}
+static u8 get_effective_type(u8 type1, u8 type2)
+{
+ if (type1 == MTRR_TYPE_UNCACHABLE || type2 == MTRR_TYPE_UNCACHABLE)
+ return MTRR_TYPE_UNCACHABLE;
+
+ if ((type1 == MTRR_TYPE_WRBACK && type2 == MTRR_TYPE_WRTHROUGH) ||
+ (type1 == MTRR_TYPE_WRTHROUGH && type2 == MTRR_TYPE_WRBACK))
+ return MTRR_TYPE_WRTHROUGH;
+
+ if (type1 != type2)
+ return MTRR_TYPE_UNCACHABLE;
+
+ return type1;
+}
+
/*
* Check and return the effective type for MTRR-MTRR type overlap.
- * Returns 1 if the effective type is UNCACHEABLE, else returns 0
+ * Returns true if the effective type is UNCACHEABLE, else returns false
*/
-static int check_type_overlap(u8 *prev, u8 *curr)
+static bool check_type_overlap(u8 *prev, u8 *curr)
{
- if (*prev == MTRR_TYPE_UNCACHABLE || *curr == MTRR_TYPE_UNCACHABLE) {
- *prev = MTRR_TYPE_UNCACHABLE;
- *curr = MTRR_TYPE_UNCACHABLE;
- return 1;
- }
-
- if ((*prev == MTRR_TYPE_WRBACK && *curr == MTRR_TYPE_WRTHROUGH) ||
- (*prev == MTRR_TYPE_WRTHROUGH && *curr == MTRR_TYPE_WRBACK)) {
- *prev = MTRR_TYPE_WRTHROUGH;
- *curr = MTRR_TYPE_WRTHROUGH;
- }
+ *prev = *curr = get_effective_type(*curr, *prev);
- if (*prev != *curr) {
- *prev = MTRR_TYPE_UNCACHABLE;
- *curr = MTRR_TYPE_UNCACHABLE;
- return 1;
- }
-
- return 0;
+ return *prev == MTRR_TYPE_UNCACHABLE;
}
/**
Powered by blists - more mailing lists