From: Marc Zyngier <marc.zyngier@arm.com>
To: Christoffer Dall <christoffer.dall@linaro.org>
Cc: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
kvmarm@lists.cs.columbia.edu
Subject: [PATCH v2 03/17] ARM: KVM: Enforce sorting of all CP tables
Date: Wed, 17 Feb 2016 16:40:35 +0000 [thread overview]
Message-ID: <1455727249-24752-4-git-send-email-marc.zyngier@arm.com> (raw)
In-Reply-To: <1455727249-24752-1-git-send-email-marc.zyngier@arm.com>
Since we're obviously terrible at sorting the CP tables, make sure
we're going to do it properly (or fail to boot). arm64 has had the
same mechanism for a while, and nobody ever broke it...
Reviewed-by: Christoffer Dall <christoffer.dall@linaro.org>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
---
arch/arm/kvm/coproc.c | 25 +++++++++++++++++--------
1 file changed, 17 insertions(+), 8 deletions(-)
diff --git a/arch/arm/kvm/coproc.c b/arch/arm/kvm/coproc.c
index 16c74f8..03f5d14 100644
--- a/arch/arm/kvm/coproc.c
+++ b/arch/arm/kvm/coproc.c
@@ -381,17 +381,26 @@ static const struct coproc_reg cp15_regs[] = {
{ CRn(15), CRm( 0), Op1( 4), Op2( 0), is32, access_cbar},
};
+static int check_reg_table(const struct coproc_reg *table, unsigned int n)
+{
+ unsigned int i;
+
+ for (i = 1; i < n; i++) {
+ if (cmp_reg(&table[i-1], &table[i]) >= 0) {
+ kvm_err("reg table %p out of order (%d)\n", table, i - 1);
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
/* Target specific emulation tables */
static struct kvm_coproc_target_table *target_tables[KVM_ARM_NUM_TARGETS];
void kvm_register_target_coproc_table(struct kvm_coproc_target_table *table)
{
- unsigned int i;
-
- for (i = 1; i < table->num; i++)
- BUG_ON(cmp_reg(&table->table[i-1],
- &table->table[i]) >= 0);
-
+ BUG_ON(check_reg_table(table->table, table->num));
target_tables[table->target] = table;
}
@@ -1210,8 +1219,8 @@ void kvm_coproc_table_init(void)
unsigned int i;
/* Make sure tables are unique and in order. */
- for (i = 1; i < ARRAY_SIZE(cp15_regs); i++)
- BUG_ON(cmp_reg(&cp15_regs[i-1], &cp15_regs[i]) >= 0);
+ BUG_ON(check_reg_table(cp15_regs, ARRAY_SIZE(cp15_regs)));
+ BUG_ON(check_reg_table(invariant_cp15, ARRAY_SIZE(invariant_cp15)));
/* We abuse the reset function to overwrite the table itself. */
for (i = 0; i < ARRAY_SIZE(invariant_cp15); i++)
--
2.1.4
next prev parent reply other threads:[~2016-02-17 16:40 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-17 16:40 [PATCH v2 00/17] KVM/ARM: Guest Entry/Exit optimizations Marc Zyngier
2016-02-17 16:40 ` [PATCH v2 01/17] arm64: KVM: Switch the sys_reg search to be a binary search Marc Zyngier
2016-02-17 16:40 ` [PATCH v2 02/17] ARM: KVM: Properly sort the invariant table Marc Zyngier
2016-02-17 16:40 ` Marc Zyngier [this message]
2016-02-17 16:40 ` [PATCH v2 04/17] ARM: KVM: Rename struct coproc_reg::is_64 to is_64bit Marc Zyngier
2016-02-17 16:40 ` [PATCH v2 05/17] ARM: KVM: Switch the CP reg search to be a binary search Marc Zyngier
2016-02-17 16:40 ` [PATCH v2 06/17] KVM: arm/arm64: timer: Add active state caching Marc Zyngier
2016-02-17 16:40 ` [PATCH v2 07/17] arm64: KVM: vgic-v2: Avoid accessing GICH registers Marc Zyngier
2016-03-02 23:08 ` Christoffer Dall
2016-02-17 16:40 ` [PATCH v2 08/17] arm64: KVM: vgic-v2: Save maintenance interrupt state only if required Marc Zyngier
2016-03-02 23:08 ` Christoffer Dall
2016-03-03 8:28 ` Marc Zyngier
2016-02-17 16:40 ` [PATCH v2 09/17] arm64: KVM: vgic-v2: Move GICH_ELRSR saving to its own function Marc Zyngier
2016-03-02 23:08 ` Christoffer Dall
2016-02-17 16:40 ` [PATCH v2 10/17] arm64: KVM: vgic-v2: Do not save an LR known to be empty Marc Zyngier
2016-03-02 23:08 ` Christoffer Dall
2016-02-17 16:40 ` [PATCH v2 11/17] arm64: KVM: vgic-v2: Only wipe LRs on vcpu exit Marc Zyngier
2016-03-02 23:08 ` Christoffer Dall
2016-03-03 8:14 ` Marc Zyngier
2016-03-03 15:58 ` Marc Zyngier
2016-03-04 11:36 ` Christoffer Dall
2016-03-04 11:45 ` Marc Zyngier
2016-02-17 16:40 ` [PATCH v2 12/17] arm64: KVM: vgic-v2: Make GICD_SGIR quicker to hit Marc Zyngier
2016-03-02 23:08 ` Christoffer Dall
2016-02-17 16:40 ` [PATCH v2 13/17] arm64: KVM: vgic-v3: Avoid accessing ICH registers Marc Zyngier
2016-02-17 16:40 ` [PATCH v2 14/17] arm64: KVM: vgic-v3: Save maintenance interrupt state only if required Marc Zyngier
2016-03-03 19:21 ` Christoffer Dall
2016-02-17 16:40 ` [PATCH v2 15/17] arm64: KVM: vgic-v3: Do not save an LR known to be empty Marc Zyngier
2016-03-03 19:21 ` Christoffer Dall
2016-02-17 16:40 ` [PATCH v2 16/17] arm64: KVM: vgic-v3: Only wipe LRs on vcpu exit Marc Zyngier
2016-03-03 19:21 ` Christoffer Dall
2016-02-17 16:40 ` [PATCH v2 17/17] arm64: KVM: vgic-v3: Do not save ICH_AP0Rn_EL2 for GICv2 emulation Marc Zyngier
2016-03-03 19:21 ` Christoffer Dall
2016-03-04 8:54 ` Marc Zyngier
2016-02-29 0:57 ` [PATCH v2 00/17] KVM/ARM: Guest Entry/Exit optimizations Mihai Claudiu Caraman
2016-02-29 8:26 ` Marc Zyngier
2016-02-29 10:43 ` Mihai Claudiu Caraman
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=1455727249-24752-4-git-send-email-marc.zyngier@arm.com \
--to=marc.zyngier@arm.com \
--cc=christoffer.dall@linaro.org \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=linux-arm-kernel@lists.infradead.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;
as well as URLs for NNTP newsgroup(s).