From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 03/10] target/arm: Introduce read_sys_reg32 for kvm32
Date: Mon, 19 Nov 2018 15:57:23 +0000 [thread overview]
Message-ID: <20181119155730.11758-4-peter.maydell@linaro.org> (raw)
In-Reply-To: <20181119155730.11758-1-peter.maydell@linaro.org>
From: Richard Henderson <richard.henderson@linaro.org>
Assert that the value to be written is the correct size.
No change in functionality here, just mirroring the same
function from kvm64.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-id: 20181113180154.17903-4-richard.henderson@linaro.org
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
target/arm/kvm32.c | 41 ++++++++++++++++-------------------------
1 file changed, 16 insertions(+), 25 deletions(-)
diff --git a/target/arm/kvm32.c b/target/arm/kvm32.c
index cb3fb73a961..bc0badf53db 100644
--- a/target/arm/kvm32.c
+++ b/target/arm/kvm32.c
@@ -28,6 +28,14 @@ static inline void set_feature(uint64_t *features, int feature)
*features |= 1ULL << feature;
}
+static int read_sys_reg32(int fd, uint32_t *pret, uint64_t id)
+{
+ struct kvm_one_reg idreg = { .id = id, .addr = (uintptr_t)pret };
+
+ assert((id & KVM_REG_SIZE_MASK) == KVM_REG_SIZE_U32);
+ return ioctl(fd, KVM_GET_ONE_REG, &idreg);
+}
+
bool kvm_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)
{
/* Identify the feature bits corresponding to the host CPU, and
@@ -35,9 +43,10 @@ bool kvm_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)
* we have to create a scratch VM, create a single CPU inside it,
* and then query that CPU for the relevant ID registers.
*/
- int i, ret, fdarray[3];
+ int err = 0, fdarray[3];
uint32_t midr, id_pfr0, mvfr1;
uint64_t features = 0;
+
/* Old kernels may not know about the PREFERRED_TARGET ioctl: however
* we know these will only support creating one kind of guest CPU,
* which is its preferred CPU type.
@@ -47,23 +56,6 @@ bool kvm_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)
QEMU_KVM_ARM_TARGET_NONE
};
struct kvm_vcpu_init init;
- struct kvm_one_reg idregs[] = {
- {
- .id = KVM_REG_ARM | KVM_REG_SIZE_U32
- | ENCODE_CP_REG(15, 0, 0, 0, 0, 0, 0),
- .addr = (uintptr_t)&midr,
- },
- {
- .id = KVM_REG_ARM | KVM_REG_SIZE_U32
- | ENCODE_CP_REG(15, 0, 0, 0, 1, 0, 0),
- .addr = (uintptr_t)&id_pfr0,
- },
- {
- .id = KVM_REG_ARM | KVM_REG_SIZE_U32
- | KVM_REG_ARM_VFP | KVM_REG_ARM_VFP_MVFR1,
- .addr = (uintptr_t)&mvfr1,
- },
- };
if (!kvm_arm_create_scratch_host_vcpu(cpus_to_try, fdarray, &init)) {
return false;
@@ -77,16 +69,15 @@ bool kvm_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)
*/
ahcf->dtb_compatible = "arm,arm-v7";
- for (i = 0; i < ARRAY_SIZE(idregs); i++) {
- ret = ioctl(fdarray[2], KVM_GET_ONE_REG, &idregs[i]);
- if (ret) {
- break;
- }
- }
+ err |= read_sys_reg32(fdarray[2], &midr, ARM_CP15_REG32(0, 0, 0, 0));
+ err |= read_sys_reg32(fdarray[2], &id_pfr0, ARM_CP15_REG32(0, 0, 1, 0));
+ err |= read_sys_reg32(fdarray[2], &mvfr1,
+ KVM_REG_ARM | KVM_REG_SIZE_U32 |
+ KVM_REG_ARM_VFP | KVM_REG_ARM_VFP_MVFR1);
kvm_arm_destroy_scratch_host_vcpu(fdarray);
- if (ret) {
+ if (err < 0) {
return false;
}
--
2.19.1
next prev parent reply other threads:[~2018-11-19 15:57 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-19 15:57 [Qemu-devel] [PULL 00/10] target-arm queue Peter Maydell
2018-11-19 15:57 ` [Qemu-devel] [PULL 01/10] target/arm: Install ARMISARegisters from kvm host Peter Maydell
2018-11-19 15:57 ` [Qemu-devel] [PULL 02/10] target/arm: Fill in ARMISARegisters for kvm64 Peter Maydell
2018-11-19 15:57 ` Peter Maydell [this message]
2018-11-19 15:57 ` [Qemu-devel] [PULL 04/10] target/arm: Fill in ARMISARegisters for kvm32 Peter Maydell
2018-11-19 15:57 ` [Qemu-devel] [PULL 05/10] MAINTAINERS: Add entries for missing ARM boards Peter Maydell
2018-11-19 15:57 ` [Qemu-devel] [PULL 06/10] hw/arm/stm32f205: Fix the UART and Timer region size Peter Maydell
2018-11-19 15:57 ` [Qemu-devel] [PULL 07/10] target/arm: fix smc incorrectly trapping to EL3 when secure is off Peter Maydell
2018-11-19 15:57 ` [Qemu-devel] [PULL 08/10] hw/block/onenand: Fix off-by-one error allowing out-of-bounds read Peter Maydell
2018-11-19 15:57 ` [Qemu-devel] [PULL 09/10] hw/block/onenand: use qemu_log_mask() for reporting Peter Maydell
2018-11-19 15:57 ` [Qemu-devel] [PULL 10/10] MAINTAINERS: list myself as maintainer for various Arm boards Peter Maydell
2018-11-19 18:10 ` [Qemu-devel] [PULL 00/10] target-arm queue Peter Maydell
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=20181119155730.11758-4-peter.maydell@linaro.org \
--to=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.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).