diff mbox series

[RFC,3/5] Add APIs to get/set MTE tags

Message ID ae69254130370fff4c9a38673deb1e3a27609e9c.1612747873.git.haibo.xu@linaro.org
State Superseded
Headers show
Series target/arm: Add MTE support to KVM guest | expand

Commit Message

Haibo Xu Feb. 8, 2021, 3:20 a.m. UTC
MTE spec provide instructions to retrieve the memory tags:
(1) LDG, at 16 bytes granularity, and available in both user
    and kernel space;
(2) LDGM, at 256 bytes granularity in maximum, and only
    available in kernel space

To improve the performance, KVM has exposed the LDGM capability
to user space by providing a new APIs. This patch is just a
wrapper for the KVM APIs.

Signed-off-by: Haibo Xu <haibo.xu@linaro.org>

---
 target/arm/kvm64.c   | 24 ++++++++++++++++++++++++
 target/arm/kvm_arm.h |  2 ++
 2 files changed, 26 insertions(+)

-- 
2.17.1

Comments

Haibo Xu March 12, 2021, 1:50 a.m. UTC | #1
++ more migration experts!

On Mon, 8 Feb 2021 at 11:20, Haibo Xu <haibo.xu@linaro.org> wrote:
>

> MTE spec provide instructions to retrieve the memory tags:

> (1) LDG, at 16 bytes granularity, and available in both user

>     and kernel space;

> (2) LDGM, at 256 bytes granularity in maximum, and only

>     available in kernel space

>

> To improve the performance, KVM has exposed the LDGM capability

> to user space by providing a new APIs. This patch is just a

> wrapper for the KVM APIs.

>

> Signed-off-by: Haibo Xu <haibo.xu@linaro.org>

> ---

>  target/arm/kvm64.c   | 24 ++++++++++++++++++++++++

>  target/arm/kvm_arm.h |  2 ++

>  2 files changed, 26 insertions(+)

>

> diff --git a/target/arm/kvm64.c b/target/arm/kvm64.c

> index 23f34034db..4a6790d53b 100644

> --- a/target/arm/kvm64.c

> +++ b/target/arm/kvm64.c

> @@ -1608,3 +1608,27 @@ bool kvm_arm_verify_ext_dabt_pending(CPUState *cs)

>      }

>      return false;

>  }

> +

> +int kvm_arm_mte_get_tags(uint64_t ipa, uint64_t len, uint8_t *buf)

> +{

> +    struct kvm_arm_copy_mte_tags args = {

> +        .guest_ipa = ipa,

> +        .length = len,

> +        .addr = buf,

> +        .flags = KVM_ARM_TAGS_FROM_GUEST,

> +    };

> +

> +    return kvm_vm_ioctl(kvm_state, KVM_ARM_MTE_COPY_TAGS, &args);

> +}

> +

> +int kvm_arm_mte_set_tags(uint64_t ipa, uint64_t len, uint8_t *buf)

> +{

> +    struct kvm_arm_copy_mte_tags args = {

> +        .guest_ipa = ipa,

> +        .length = len,

> +        .addr = buf,

> +        .flags = KVM_ARM_TAGS_TO_GUEST,

> +    };

> +

> +    return kvm_vm_ioctl(kvm_state, KVM_ARM_MTE_COPY_TAGS, &args);

> +}

> diff --git a/target/arm/kvm_arm.h b/target/arm/kvm_arm.h

> index eb81b7059e..1b94dbe7c8 100644

> --- a/target/arm/kvm_arm.h

> +++ b/target/arm/kvm_arm.h

> @@ -358,6 +358,8 @@ int kvm_arm_vgic_probe(void);

>

>  void kvm_arm_pmu_set_irq(CPUState *cs, int irq);

>  void kvm_arm_pmu_init(CPUState *cs);

> +int kvm_arm_mte_get_tags(uint64_t ipa, uint64_t len, uint8_t *buf);

> +int kvm_arm_mte_set_tags(uint64_t ipa, uint64_t len, uint8_t *buf);

>

>  /**

>   * kvm_arm_pvtime_init:

> --

> 2.17.1

>
diff mbox series

Patch

diff --git a/target/arm/kvm64.c b/target/arm/kvm64.c
index 23f34034db..4a6790d53b 100644
--- a/target/arm/kvm64.c
+++ b/target/arm/kvm64.c
@@ -1608,3 +1608,27 @@  bool kvm_arm_verify_ext_dabt_pending(CPUState *cs)
     }
     return false;
 }
+
+int kvm_arm_mte_get_tags(uint64_t ipa, uint64_t len, uint8_t *buf)
+{
+    struct kvm_arm_copy_mte_tags args = {
+        .guest_ipa = ipa,
+        .length = len,
+        .addr = buf,
+        .flags = KVM_ARM_TAGS_FROM_GUEST,
+    };
+
+    return kvm_vm_ioctl(kvm_state, KVM_ARM_MTE_COPY_TAGS, &args);
+}
+
+int kvm_arm_mte_set_tags(uint64_t ipa, uint64_t len, uint8_t *buf)
+{
+    struct kvm_arm_copy_mte_tags args = {
+        .guest_ipa = ipa,
+        .length = len,
+        .addr = buf,
+        .flags = KVM_ARM_TAGS_TO_GUEST,
+    };
+
+    return kvm_vm_ioctl(kvm_state, KVM_ARM_MTE_COPY_TAGS, &args);
+}
diff --git a/target/arm/kvm_arm.h b/target/arm/kvm_arm.h
index eb81b7059e..1b94dbe7c8 100644
--- a/target/arm/kvm_arm.h
+++ b/target/arm/kvm_arm.h
@@ -358,6 +358,8 @@  int kvm_arm_vgic_probe(void);
 
 void kvm_arm_pmu_set_irq(CPUState *cs, int irq);
 void kvm_arm_pmu_init(CPUState *cs);
+int kvm_arm_mte_get_tags(uint64_t ipa, uint64_t len, uint8_t *buf);
+int kvm_arm_mte_set_tags(uint64_t ipa, uint64_t len, uint8_t *buf);
 
 /**
  * kvm_arm_pvtime_init: