From: Peter Maydell <peter.maydell@linaro.org>
To: Eric Auger <eric.auger@redhat.com>
Cc: Eric Auger <eric.auger.pro@gmail.com>,
QEMU Developers <qemu-devel@nongnu.org>,
qemu-arm <qemu-arm@nongnu.org>,
jia.he@hxt-semitech.com, Jia He <hejianet@gmail.com>
Subject: Re: [Qemu-devel] [PATCH v2 3/4] hw/arm/smmuv3: IOTLB emulation
Date: Wed, 20 Jun 2018 17:07:41 +0100 [thread overview]
Message-ID: <CAFEAcA-EpZ6uzLmjr_1w9nno6C5-tyvqU9MfWR8XZwup4hKKDA@mail.gmail.com> (raw)
In-Reply-To: <1528790908-23441-4-git-send-email-eric.auger@redhat.com>
On 12 June 2018 at 09:08, Eric Auger <eric.auger@redhat.com> wrote:
> We emulate a TLB cache of size SMMU_IOTLB_MAX_SIZE=256.
> It is implemented as a hash table whose key is a combination
> of the 16b asid and 48b IOVA (Jenkins hash).
>
> Entries are invalidated on TLB invalidation commands, either
> globally, or per asid, or per asid/iova.
>
> Signed-off-by: Eric Auger <eric.auger@redhat.com>
>
> ---
>
> v1 -> v2:
> - add comment about Jenkins Hash
> - remove init of iotlb_hits, misses
>
> v1:
> - Add new trace point when smmu is bypassed
> - s/iotlb_miss/iotlb_misses, s/iotlb_hit/iotlb_hits
> - use SMMUIOTLBKey as a key
>
> Credit to Tomasz Nowicki who did the first implementation of
> this IOTLB implementation, inspired of intel_iommu implementation.
> ---
> hw/arm/smmu-common.c | 60 +++++++++++++++++++++++++++
> hw/arm/smmuv3.c | 98 ++++++++++++++++++++++++++++++++++++++++++--
> hw/arm/trace-events | 9 ++++
> include/hw/arm/smmu-common.h | 13 ++++++
> 4 files changed, 176 insertions(+), 4 deletions(-)
>
> diff --git a/hw/arm/smmu-common.c b/hw/arm/smmu-common.c
> index 264e096..16cd33a 100644
> --- a/hw/arm/smmu-common.c
> +++ b/hw/arm/smmu-common.c
> @@ -24,11 +24,43 @@
> #include "qom/cpu.h"
> #include "hw/qdev-properties.h"
> #include "qapi/error.h"
> +#include "qemu/jhash.h"
>
> #include "qemu/error-report.h"
> #include "hw/arm/smmu-common.h"
> #include "smmu-internal.h"
>
> +/* IOTLB Management */
> +
> +inline void smmu_iotlb_inv_all(SMMUState *s)
> +{
> + trace_smmu_iotlb_inv_all();
> + g_hash_table_remove_all(s->iotlb);
> +}
> +
> +static gboolean smmu_hash_remove_by_asid(gpointer key, gpointer value,
> + gpointer user_data)
> +{
> + uint16_t asid = *(uint16_t *)user_data;
> + SMMUIOTLBKey *iotlb_key = (SMMUIOTLBKey *)key;
> +
> + return iotlb_key->asid == asid;
> +}
> +
> +inline void smmu_iotlb_inv_iova(SMMUState *s, uint16_t asid, dma_addr_t iova)
> +{
> + SMMUIOTLBKey key = {.asid = asid, .iova = iova};
> +
> + trace_smmu_iotlb_inv_iova(asid, iova);
> + g_hash_table_remove(s->iotlb, &key);
> +}
> +
> +inline void smmu_iotlb_inv_asid(SMMUState *s, uint16_t asid)
> +{
> + trace_smmu_iotlb_inv_asid(asid);
> + g_hash_table_foreach_remove(s->iotlb, smmu_hash_remove_by_asid, &asid);
> +}
> +
> /* VMSAv8-64 Translation */
>
> /**
> @@ -328,6 +360,31 @@ IOMMUMemoryRegion *smmu_iommu_mr(SMMUState *s, uint32_t sid)
> return NULL;
> }
>
> +static guint smmu_iotlb_key_hash(gconstpointer v)
> +{
> + SMMUIOTLBKey *key = (SMMUIOTLBKey *)v;
> + uint32_t a, b, c;
> +
> + /* Henkins hash */
"Jenkins"
> + a = b = c = JHASH_INITVAL + sizeof(*key);
Why do we add the sizeof(SMMUIOTLBKey) here ?
> + a += key->asid;
> + b += extract64(key->iova, 0, 32);
> + c += extract64(key->iova, 32, 32);
> +
> + __jhash_mix(a, b, c);
> + __jhash_final(a, b, c);
> +
> + return c;
> +}
> +static gboolean smmu_iotlb_key_equal(gconstpointer v1, gconstpointer v2)
> +{
> + SMMUIOTLBKey *k1 = (SMMUIOTLBKey *)v1;
> + SMMUIOTLBKey *k2 = (SMMUIOTLBKey *)v2;
These should have a 'const', at which point I think you'll
find that you don't need the explicit casts.
Otherwise looks OK I think.
thanks
-- PMM
next prev parent reply other threads:[~2018-06-20 16:08 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-12 8:08 [Qemu-devel] [PATCH v2 0/4] ARM SMMUv3: IOTLB Emulation and VHOST Support Eric Auger
2018-06-12 8:08 ` [Qemu-devel] [PATCH v2 1/4] hw/arm/smmuv3: Fix translate error handling Eric Auger
2018-06-20 15:36 ` Peter Maydell
2018-06-12 8:08 ` [Qemu-devel] [PATCH v2 2/4] hw/arm/smmuv3: Cache/invalidate config data Eric Auger
2018-06-20 15:56 ` Peter Maydell
2018-06-20 16:10 ` Peter Maydell
2018-06-21 7:54 ` Auger Eric
2018-06-21 7:51 ` Auger Eric
2018-06-12 8:08 ` [Qemu-devel] [PATCH v2 3/4] hw/arm/smmuv3: IOTLB emulation Eric Auger
2018-06-20 16:07 ` Peter Maydell [this message]
2018-06-21 7:49 ` Auger Eric
2018-06-12 8:08 ` [Qemu-devel] [PATCH v2 4/4] hw/arm/smmuv3: Add notifications on invalidation Eric Auger
2018-06-20 16:15 ` 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=CAFEAcA-EpZ6uzLmjr_1w9nno6C5-tyvqU9MfWR8XZwup4hKKDA@mail.gmail.com \
--to=peter.maydell@linaro.org \
--cc=eric.auger.pro@gmail.com \
--cc=eric.auger@redhat.com \
--cc=hejianet@gmail.com \
--cc=jia.he@hxt-semitech.com \
--cc=qemu-arm@nongnu.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).