From: Anshuman Khandual <anshuman.khandual@arm.com>
To: linux-arm-kernel@lists.infradead.org
Cc: mark.rutland@arm.com,
Anshuman Khandual <anshuman.khandual@arm.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Mark Brown <broonie@kernel.org>,
linux-kernel@vger.kernel.org
Subject: [PATCH] arm64/cpufeature: Move BUG_ON() inside get_arm64_ftr_reg()
Date: Wed, 20 May 2020 06:52:54 +0530 [thread overview]
Message-ID: <1589937774-20479-1-git-send-email-anshuman.khandual@arm.com> (raw)
There is no way to proceed when requested register could not be searched in
arm64_ftr_reg[]. Requesting for a non present register would be an error as
well. Hence lets just BUG_ON() when the search fails in get_arm64_ftr_reg()
rather than checking for return value and doing the same in some individual
callers.
But there are some callers that dont BUG_ON() upon search failure. It adds
an argument 'failsafe' that provides required switch between callers based
on whether they could proceed or not.
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Suzuki K Poulose <suzuki.poulose@arm.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
Applies on next-20200518 that has recent cpufeature changes from Will.
arch/arm64/kernel/cpufeature.c | 26 +++++++++++++-------------
1 file changed, 13 insertions(+), 13 deletions(-)
diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c
index bc5048f152c1..62767cc540c3 100644
--- a/arch/arm64/kernel/cpufeature.c
+++ b/arch/arm64/kernel/cpufeature.c
@@ -557,7 +557,7 @@ static int search_cmp_ftr_reg(const void *id, const void *regp)
* - NULL on failure. It is upto the caller to decide
* the impact of a failure.
*/
-static struct arm64_ftr_reg *get_arm64_ftr_reg(u32 sys_id)
+static struct arm64_ftr_reg *get_arm64_ftr_reg(u32 sys_id, bool failsafe)
{
const struct __ftr_reg_entry *ret;
@@ -568,6 +568,13 @@ static struct arm64_ftr_reg *get_arm64_ftr_reg(u32 sys_id)
search_cmp_ftr_reg);
if (ret)
return ret->reg;
+ /*
+ * This can not really proceed when the search fails.
+ * Requesting for a non existent register search will
+ * also be an error in itself. Error out when not
+ * called with fail safe request.
+ */
+ BUG_ON(!failsafe);
return NULL;
}
@@ -630,9 +637,7 @@ static void __init init_cpu_ftr_reg(u32 sys_reg, u64 new)
u64 valid_mask = 0;
const struct arm64_ftr_bits *ftrp;
- struct arm64_ftr_reg *reg = get_arm64_ftr_reg(sys_reg);
-
- BUG_ON(!reg);
+ struct arm64_ftr_reg *reg = get_arm64_ftr_reg(sys_reg, false);
for (ftrp = reg->ftr_bits; ftrp->width; ftrp++) {
u64 ftr_mask = arm64_ftr_mask(ftrp);
@@ -760,9 +765,8 @@ static void update_cpu_ftr_reg(struct arm64_ftr_reg *reg, u64 new)
static int check_update_ftr_reg(u32 sys_id, int cpu, u64 val, u64 boot)
{
- struct arm64_ftr_reg *regp = get_arm64_ftr_reg(sys_id);
+ struct arm64_ftr_reg *regp = get_arm64_ftr_reg(sys_id, false);
- BUG_ON(!regp);
update_cpu_ftr_reg(regp, val);
if ((boot & regp->strict_mask) == (val & regp->strict_mask))
return 0;
@@ -774,10 +778,7 @@ static int check_update_ftr_reg(u32 sys_id, int cpu, u64 val, u64 boot)
static void relax_cpu_ftr_reg(u32 sys_id, int field)
{
const struct arm64_ftr_bits *ftrp;
- struct arm64_ftr_reg *regp = get_arm64_ftr_reg(sys_id);
-
- if (WARN_ON(!regp))
- return;
+ struct arm64_ftr_reg *regp = get_arm64_ftr_reg(sys_id, false);
for (ftrp = regp->ftr_bits; ftrp->width; ftrp++) {
if (ftrp->shift == field) {
@@ -959,10 +960,9 @@ void update_cpu_features(int cpu,
u64 read_sanitised_ftr_reg(u32 id)
{
- struct arm64_ftr_reg *regp = get_arm64_ftr_reg(id);
+ struct arm64_ftr_reg *regp = get_arm64_ftr_reg(id, false);
/* We shouldn't get a request for an unsupported register */
- BUG_ON(!regp);
return regp->sys_val;
}
@@ -2565,7 +2565,7 @@ static int emulate_sys_reg(u32 id, u64 *valp)
if (sys_reg_CRm(id) == 0)
return emulate_id_reg(id, valp);
- regp = get_arm64_ftr_reg(id);
+ regp = get_arm64_ftr_reg(id, true);
if (regp)
*valp = arm64_ftr_reg_user_value(regp);
else
--
2.20.1
next reply other threads:[~2020-05-20 1:23 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-20 1:22 Anshuman Khandual [this message]
2020-05-20 11:49 ` Catalin Marinas
2020-05-20 12:20 ` Will Deacon
2020-05-20 15:47 ` Catalin Marinas
2020-05-20 17:39 ` Will Deacon
2020-05-21 3:15 ` Anshuman Khandual
2020-05-21 16:22 ` Will Deacon
2020-05-21 16:59 ` Catalin Marinas
2020-05-24 23:52 ` Anshuman Khandual
2020-05-26 12:19 ` Catalin Marinas
2020-05-21 3:12 ` Anshuman Khandual
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=1589937774-20479-1-git-send-email-anshuman.khandual@arm.com \
--to=anshuman.khandual@arm.com \
--cc=broonie@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=suzuki.poulose@arm.com \
--cc=will@kernel.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
all inboxes | Powered by JetHome®