From: Haibo Xu <haibo.xu@linaro.org>
To: Andrew Jones <drjones@redhat.com>,
Richard Henderson <richard.henderson@linaro.org>,
"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
Juan Quintela <quintela@redhat.com>
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
qemu-arm <qemu-arm@nongnu.org>,
"Philippe Mathieu-Daudé" <philmd@redhat.com>,
"QEMU Developers" <qemu-devel@nongnu.org>
Subject: Re: [RFC PATCH 2/5] Add basic MTE support to KVM guest
Date: Fri, 12 Mar 2021 09:49:45 +0800 [thread overview]
Message-ID: <CAJc+Z1EJiv-t4Wf4Kjho=P+VfW0+9SZuWcHtBS9-oevhT-odVg@mail.gmail.com> (raw)
In-Reply-To: <9c4507258ffe9cea4aeb5e19ef8475cb65230c3d.1612747873.git.haibo.xu@linaro.org>
++ more migration experts!
On Mon, 8 Feb 2021 at 11:20, Haibo Xu <haibo.xu@linaro.org> wrote:
>
> Enable the virt machine feature "mte" to work with
> KVM guest. This feature is still hiden from the user
> in this patch, and will be available in a later patch.
>
> Signed-off-by: Haibo Xu <haibo.xu@linaro.org>
> ---
> hw/arm/virt.c | 22 +++++++++++-----------
> target/arm/cpu.c | 2 +-
> target/arm/kvm.c | 9 +++++++++
> target/arm/kvm64.c | 7 +++++++
> 4 files changed, 28 insertions(+), 12 deletions(-)
>
> diff --git a/hw/arm/virt.c b/hw/arm/virt.c
> index 399da73454..623d5e9397 100644
> --- a/hw/arm/virt.c
> +++ b/hw/arm/virt.c
> @@ -1974,18 +1974,18 @@ static void machvirt_init(MachineState *machine)
> }
>
> if (vms->mte) {
> + /*
> + * The property exists only if MemTag is supported.
> + * If it is, we must allocate the ram to back that up.
> + */
> + if (!object_property_find(cpuobj, "tag-memory")) {
> + error_report("MTE requested, but not supported "
> + "by the guest CPU");
> + exit(1);
> + }
> +
> /* Create the memory region only once, but link to all cpus. */
> - if (!tag_sysmem) {
> - /*
> - * The property exists only if MemTag is supported.
> - * If it is, we must allocate the ram to back that up.
> - */
> - if (!object_property_find(cpuobj, "tag-memory")) {
> - error_report("MTE requested, but not supported "
> - "by the guest CPU");
> - exit(1);
> - }
> -
> + if (!tag_sysmem && !kvm_enabled()) {
> tag_sysmem = g_new(MemoryRegion, 1);
> memory_region_init(tag_sysmem, OBJECT(machine),
> "tag-memory", UINT64_MAX / 32);
> diff --git a/target/arm/cpu.c b/target/arm/cpu.c
> index 40142ac141..50f3223944 100644
> --- a/target/arm/cpu.c
> +++ b/target/arm/cpu.c
> @@ -1831,7 +1831,7 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)
> cpu->secure_memory);
> }
>
> - if (cpu->tag_memory != NULL) {
> + if (cpu->tag_memory != NULL && !kvm_enabled()) {
> cpu_address_space_init(cs, ARMASIdx_TagNS, "cpu-tag-memory",
> cpu->tag_memory);
> if (has_secure) {
> diff --git a/target/arm/kvm.c b/target/arm/kvm.c
> index ffe186de8d..33630b2b70 100644
> --- a/target/arm/kvm.c
> +++ b/target/arm/kvm.c
> @@ -32,6 +32,7 @@
> #include "hw/boards.h"
> #include "hw/irq.h"
> #include "qemu/log.h"
> +#include "hw/arm/virt.h"
>
> const KVMCapabilityInfo kvm_arch_required_capabilities[] = {
> KVM_CAP_LAST_INFO
> @@ -272,6 +273,14 @@ int kvm_arch_init(MachineState *ms, KVMState *s)
> }
> }
>
> + if (kvm_check_extension(s, KVM_CAP_ARM_MTE) &&
> + object_dynamic_cast(OBJECT(ms), TYPE_VIRT_MACHINE) &&
> + VIRT_MACHINE(ms)->mte) {
> + if (kvm_vm_enable_cap(s, KVM_CAP_ARM_MTE, 0)) {
> + error_report("Failed to enable KVM_CAP_ARM_MTE cap");
> + }
> + }
> +
> return ret;
> }
>
> diff --git a/target/arm/kvm64.c b/target/arm/kvm64.c
> index 3c37fc4fb6..23f34034db 100644
> --- a/target/arm/kvm64.c
> +++ b/target/arm/kvm64.c
> @@ -500,6 +500,7 @@ bool kvm_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)
> */
> int fdarray[3];
> bool sve_supported;
> + bool mte_supported;
> uint64_t features = 0;
> uint64_t t;
> int err;
> @@ -646,6 +647,7 @@ bool kvm_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)
> }
>
> sve_supported = ioctl(fdarray[0], KVM_CHECK_EXTENSION, KVM_CAP_ARM_SVE) > 0;
> + mte_supported = ioctl(fdarray[0], KVM_CHECK_EXTENSION, KVM_CAP_ARM_MTE) > 0;
>
> kvm_arm_destroy_scratch_host_vcpu(fdarray);
>
> @@ -659,6 +661,11 @@ bool kvm_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)
> t = FIELD_DP64(t, ID_AA64PFR0, SVE, 1);
> ahcf->isar.id_aa64pfr0 = t;
> }
> + if (mte_supported) {
> + t = ahcf->isar.id_aa64pfr1;
> + t = FIELD_DP64(t, ID_AA64PFR1, MTE, 2);
> + ahcf->isar.id_aa64pfr1 = t;
> + }
>
> /*
> * We can assume any KVM supporting CPU is at least a v8
> --
> 2.17.1
>
next prev parent reply other threads:[~2021-03-12 1:51 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-08 3:20 [RFC PATCH 0/5] target/arm: Add MTE support to KVM guest Haibo Xu
2021-02-08 3:20 ` [RFC PATCH 1/5] Update Linux headers with new MTE support Haibo Xu
2021-03-12 1:48 ` Haibo Xu
2021-02-08 3:20 ` [RFC PATCH 2/5] Add basic MTE support to KVM guest Haibo Xu
2021-03-12 1:49 ` Haibo Xu [this message]
2021-02-08 3:20 ` [RFC PATCH 3/5] Add APIs to get/set MTE tags Haibo Xu
2021-03-12 1:50 ` Haibo Xu
2021-02-08 3:20 ` [RFC PATCH 4/5] Add migration support for KVM guest with MTE Haibo Xu
2021-02-16 15:31 ` Richard Henderson
2021-02-22 9:46 ` Haibo Xu
2021-02-22 22:47 ` Richard Henderson
2021-03-12 1:50 ` Haibo Xu
2021-02-08 3:20 ` [RFC PATCH 5/5] Enable the MTE support for KVM guest Haibo Xu
2021-03-12 1:51 ` Haibo Xu
2021-02-16 11:20 ` [RFC PATCH 0/5] target/arm: Add MTE support to " Peter Maydell
2021-02-22 4:18 ` Haibo Xu
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='CAJc+Z1EJiv-t4Wf4Kjho=P+VfW0+9SZuWcHtBS9-oevhT-odVg@mail.gmail.com' \
--to=haibo.xu@linaro.org \
--cc=dgilbert@redhat.com \
--cc=drjones@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=philmd@redhat.com \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
--cc=richard.henderson@linaro.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).