diff mbox series

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

Message ID 5f269099f5f06c23f11d41b45d64f77eca23a8ff.1615972140.git.haibo.xu@linaro.org
State New
Headers show
Series target/arm: Add MTE support to KVM guest | expand

Commit Message

Haibo Xu March 17, 2021, 9:28 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

Juan Quintela March 25, 2021, 12:18 p.m. UTC | #1
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 73a191f8e1..3157025316 100644

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

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

> @@ -1606,3 +1606,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);


Just a question, how fast/slow are this calls?

My understanding is that we are making a kvm call for each page that we
want to migrate, right?

Each time that we want to send it.

Later, Juan.


> +}

> +

> +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 34f8daa377..bbb833d6c6 100644

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

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

> @@ -360,6 +360,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:
Haibo Xu April 1, 2021, 1:12 p.m. UTC | #2
On Thu, 25 Mar 2021 at 20:18, Juan Quintela <quintela@redhat.com> wrote:
>

> 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 73a191f8e1..3157025316 100644

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

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

> > @@ -1606,3 +1606,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);

>

> Just a question, how fast/slow are this calls?

>


There is no performance data for this API yet, but at least it's more
efficient than that
to only be able to access a single tag by the EL0 "LDG" instruction.
We will try to
collect some performance data for this KVM API later.

> My understanding is that we are making a kvm call for each page that we

> want to migrate, right?

>


Yes, currently I chose to append the tag values to the page data
during the migration.

> Each time that we want to send it.

>

> Later, Juan.

>

>

> > +}

> > +

> > +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 34f8daa377..bbb833d6c6 100644

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

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

> > @@ -360,6 +360,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:

>
diff mbox series

Patch

diff --git a/target/arm/kvm64.c b/target/arm/kvm64.c
index 73a191f8e1..3157025316 100644
--- a/target/arm/kvm64.c
+++ b/target/arm/kvm64.c
@@ -1606,3 +1606,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 34f8daa377..bbb833d6c6 100644
--- a/target/arm/kvm_arm.h
+++ b/target/arm/kvm_arm.h
@@ -360,6 +360,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: