From: Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>
To: Oleksandr Tyshchenko <olekstysh@gmail.com>
Cc: Stefano Stabellini <sstabellini@kernel.org>,
Julien Grall <julien@xen.org>,
Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>,
Oleksandr Tyshchenko <Oleksandr_Tyshchenko@epam.com>,
"xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>,
Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>
Subject: Re: [Xen-devel] [PATCH] iommu/arm: Don't allow the same micro-TLB to be shared between domains
Date: Wed, 29 Jan 2020 16:07:42 +0000 [thread overview]
Message-ID: <874kwep7pe.fsf@epam.com> (raw)
In-Reply-To: <1580309714-21912-1-git-send-email-olekstysh@gmail.com>
Hi Oleksandr,
Oleksandr Tyshchenko writes:
[...]
> @@ -434,19 +435,45 @@ static void ipmmu_tlb_invalidate(struct ipmmu_vmsa_domain *domain)
> }
>
> /* Enable MMU translation for the micro-TLB. */
> -static void ipmmu_utlb_enable(struct ipmmu_vmsa_domain *domain,
> - unsigned int utlb)
> +static int ipmmu_utlb_enable(struct ipmmu_vmsa_domain *domain,
> + unsigned int utlb)
> {
> struct ipmmu_vmsa_device *mmu = domain->mmu;
> + uint32_t data;
Just nitpicking: I believe, that "imuctr" is better name than "data".
> +
> + /*
> + * We need to prevent the use cases where devices which use the same
> + * micro-TLB are assigned to different Xen domains (micro-TLB cannot be
> + * shared between multiple Xen domains, since it points to the context bank
> + * to use for the page walk).
> + * As each Xen domain uses individual context bank pointed by context_id,
> + * we can potentially recognize that use case by comparing current and new
> + * context_id for already enabled micro-TLB and prevent different context
> + * bank from being set.
> + */
> + data = ipmmu_read(mmu, IMUCTR(utlb));
I can see that this code is not covered by spinlock. So, I believe,
there can be a race comdition, when this register is being read on two
CPUs simultaneously.
> + if ( data & IMUCTR_MMUEN )
> + {
> + unsigned int context_id;
> +
> + context_id = (data & IMUCTR_TTSEL_MASK) >> IMUCTR_TTSEL_SHIFT;
> + if ( domain->context_id != context_id )
> + {
> + dev_err(mmu->dev, "Micro-TLB %u already assigned to IPMMU context %u\n",
> + utlb, context_id);
> + return -EINVAL;
> + }
> + }
>
> /*
> * TODO: Reference-count the micro-TLB as several bus masters can be
> - * connected to the same micro-TLB. Prevent the use cases where
> - * the same micro-TLB could be shared between multiple Xen domains.
> + * connected to the same micro-TLB.
> */
> ipmmu_write(mmu, IMUASID(utlb), 0);
> - ipmmu_write(mmu, IMUCTR(utlb), ipmmu_read(mmu, IMUCTR(utlb)) |
> + ipmmu_write(mmu, IMUCTR(utlb), data |
> IMUCTR_TTSEL_MMU(domain->context_id) | IMUCTR_MMUEN);
> +
> + return 0;
> }
>
> /* Disable MMU translation for the micro-TLB. */
> @@ -671,7 +698,12 @@ static int ipmmu_attach_device(struct ipmmu_vmsa_domain *domain,
> dev_info(dev, "Reusing IPMMU context %u\n", domain->context_id);
>
> for ( i = 0; i < fwspec->num_ids; ++i )
> - ipmmu_utlb_enable(domain, fwspec->ids[i]);
> + {
> + int ret = ipmmu_utlb_enable(domain, fwspec->ids[i]);
> +
> + if ( ret )
> + return ret;
I can't see error path where ipmmu_utlb_disable() would be called for
already enable uTLBs. Is this normal?
> + }
>
> return 0;
> }
--
Volodymyr Babchuk at EPAM
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
next prev parent reply other threads:[~2020-01-29 16:08 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-29 14:55 [Xen-devel] [PATCH] iommu/arm: Don't allow the same micro-TLB to be shared between domains Oleksandr Tyshchenko
2020-01-29 16:07 ` Volodymyr Babchuk [this message]
2020-01-30 14:34 ` Oleksandr
2020-01-30 15:05 ` Volodymyr Babchuk
2020-01-30 15:20 ` Volodymyr Babchuk
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=874kwep7pe.fsf@epam.com \
--to=volodymyr_babchuk@epam.com \
--cc=Oleksandr_Tyshchenko@epam.com \
--cc=julien@xen.org \
--cc=olekstysh@gmail.com \
--cc=sstabellini@kernel.org \
--cc=xen-devel@lists.xenproject.org \
--cc=yoshihiro.shimoda.uh@renesas.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.