From: ard.biesheuvel@linaro.org (Ard Biesheuvel)
To: linux-arm-kernel@lists.infradead.org
Subject: [RFC/RFT PATCH 2/3] arm64: KVM: mangle MAIR register to prevent uncached guest mappings
Date: Thu, 19 Feb 2015 10:54:45 +0000 [thread overview]
Message-ID: <1424343286-6792-3-git-send-email-ard.biesheuvel@linaro.org> (raw)
In-Reply-To: <1424343286-6792-1-git-send-email-ard.biesheuvel@linaro.org>
Mangle the memory attribute register values at each write to MAIR_EL1
so that regions that the guest intends to map as device or uncached are
in fact mapped as cached instead. This avoids incoherency issues when
the guest bypassed the caches to access memory that the host has mapped
as cached.
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
arch/arm64/kvm/sys_regs.c | 35 ++++++++++++++++++++++++++++++++++-
1 file changed, 34 insertions(+), 1 deletion(-)
diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
index 1e170eab6603..bde2b49a7cd8 100644
--- a/arch/arm64/kvm/sys_regs.c
+++ b/arch/arm64/kvm/sys_regs.c
@@ -110,6 +110,39 @@ static bool access_vm_reg(struct kvm_vcpu *vcpu,
return true;
}
+static bool access_mair(struct kvm_vcpu *vcpu,
+ const struct sys_reg_params *p,
+ const struct sys_reg_desc *r)
+{
+ unsigned long val, mask;
+
+ BUG_ON(!p->is_write);
+
+ val = *vcpu_reg(vcpu, p->Rt);
+
+ if (!p->is_aarch32) {
+ /*
+ * Mangle val so that all device and uncached attributes are
+ * replaced with cached attributes.
+ * For each attribute, check whether any of bit 7, bit 5 or bit
+ * 4 are set. If not, it is a device or outer non-cacheable
+ * mapping and we override it with inner, outer write-through,
+ * read+write-allocate (0xbb).
+ * TODO: handle outer cacheable inner non-cacheable
+ */
+ mask = ~(val >> 7 | val >> 5 | val >> 4) & 0x0101010101010101UL;
+ val = (val & ~(mask * 0xff)) | (mask * 0xbb);
+
+ vcpu_sys_reg(vcpu, r->reg) = val;
+ } else {
+ if (!p->is_32bit)
+ vcpu_cp15_64_high(vcpu, r->reg) = val >> 32;
+ vcpu_cp15_64_low(vcpu, r->reg) = val & 0xffffffffUL;
+ }
+
+ return true;
+}
+
static bool trap_raz_wi(struct kvm_vcpu *vcpu,
const struct sys_reg_params *p,
const struct sys_reg_desc *r)
@@ -371,7 +404,7 @@ static const struct sys_reg_desc sys_reg_descs[] = {
/* MAIR_EL1 */
{ Op0(0b11), Op1(0b000), CRn(0b1010), CRm(0b0010), Op2(0b000),
- access_vm_reg, reset_unknown, MAIR_EL1 },
+ access_mair, reset_unknown, MAIR_EL1 },
/* AMAIR_EL1 */
{ Op0(0b11), Op1(0b000), CRn(0b1010), CRm(0b0011), Op2(0b000),
access_handled_at_el2, reset_amair_el1, AMAIR_EL1 },
--
1.8.3.2
next prev parent reply other threads:[~2015-02-19 10:54 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-19 10:54 [RFC/RFT PATCH 0/3] arm64: KVM: work around incoherency with uncached guest mappings Ard Biesheuvel
2015-02-19 10:54 ` [RFC/RFT PATCH 1/3] arm64: KVM: handle some sysreg writes in EL2 Ard Biesheuvel
2015-03-03 17:59 ` Mario Smarduch
2015-02-19 10:54 ` Ard Biesheuvel [this message]
2015-02-19 10:54 ` [RFC/RFT PATCH 3/3] arm64: KVM: keep trapping of VM sysreg writes enabled Ard Biesheuvel
2015-02-19 13:40 ` Marc Zyngier
2015-02-19 13:44 ` Ard Biesheuvel
2015-02-19 15:19 ` Marc Zyngier
2015-02-19 15:22 ` Ard Biesheuvel
2015-02-19 14:50 ` [RFC/RFT PATCH 0/3] arm64: KVM: work around incoherency with uncached guest mappings Alexander Graf
2015-02-19 14:56 ` Ard Biesheuvel
2015-02-19 15:27 ` Alexander Graf
2015-02-19 15:31 ` Ard Biesheuvel
2015-02-19 16:57 ` Andrew Jones
2015-02-19 17:19 ` Ard Biesheuvel
2015-02-19 17:55 ` Andrew Jones
2015-02-19 17:57 ` Paolo Bonzini
2015-02-20 14:29 ` Andrew Jones
2015-02-20 14:37 ` Ard Biesheuvel
2015-02-20 15:36 ` Andrew Jones
2015-02-24 14:55 ` Andrew Jones
2015-02-24 17:47 ` Ard Biesheuvel
2015-02-24 19:12 ` Andrew Jones
2015-03-02 16:31 ` Christoffer Dall
2015-03-02 16:47 ` Paolo Bonzini
2015-03-02 16:55 ` Laszlo Ersek
2015-03-02 17:05 ` Andrew Jones
2015-03-02 16:48 ` Andrew Jones
2015-03-03 2:20 ` Mario Smarduch
2015-03-04 11:35 ` Catalin Marinas
2015-03-04 11:50 ` Ard Biesheuvel
2015-03-04 12:29 ` Catalin Marinas
2015-03-04 12:43 ` Ard Biesheuvel
2015-03-04 14:12 ` Andrew Jones
2015-03-04 14:29 ` Catalin Marinas
2015-03-04 14:34 ` Peter Maydell
2015-03-04 17:03 ` Paolo Bonzini
2015-03-04 17:28 ` Catalin Marinas
2015-03-05 10:12 ` Paolo Bonzini
2015-03-05 11:04 ` Catalin Marinas
2015-03-05 11:52 ` Peter Maydell
2015-03-05 12:03 ` Catalin Marinas
2015-03-05 12:26 ` Paolo Bonzini
2015-03-05 14:58 ` Catalin Marinas
2015-03-05 17:43 ` Paolo Bonzini
2015-03-06 21:08 ` Mario Smarduch
2015-03-09 14:26 ` Andrew Jones
2015-03-09 15:33 ` Mario Smarduch
2015-03-05 19:13 ` Ard Biesheuvel
2015-03-06 20:33 ` Mario Smarduch
2015-02-19 18:44 ` Ard Biesheuvel
2015-03-03 17:34 ` Alexander Graf
2015-03-03 18:13 ` Laszlo Ersek
2015-03-03 20:58 ` Andrew Jones
2015-03-03 18:32 ` Catalin Marinas
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=1424343286-6792-3-git-send-email-ard.biesheuvel@linaro.org \
--to=ard.biesheuvel@linaro.org \
--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).