From: David Gibson <david@gibson.dropbear.id.au>
To: Alexey Kardashevskiy <aik@ozlabs.ru>
Cc: linuxppc-dev@lists.ozlabs.org,
Alex Williamson <alex.williamson@redhat.com>,
Nicholas Piggin <npiggin@gmail.com>,
Paul Mackerras <paulus@samba.org>,
kvm@vger.kernel.org
Subject: Re: [PATCH kernel v6 4/7] vfio/spapr: Add a helper to create default DMA window
Date: Tue, 29 Nov 2016 15:33:08 +1100 [thread overview]
Message-ID: <20161129043308.GK13307@umbus.fritz.box> (raw)
In-Reply-To: <1479966490-8739-5-git-send-email-aik@ozlabs.ru>
[-- Attachment #1: Type: text/plain, Size: 5545 bytes --]
On Thu, Nov 24, 2016 at 04:48:07PM +1100, Alexey Kardashevskiy wrote:
> There is already a helper to create a DMA window which does allocate
> a table and programs it to the IOMMU group. However
> tce_iommu_take_ownership_ddw() did not use it and did these 2 calls
> itself to simplify error path.
>
> Since we are going to delay the default window creation till
> the default window is accessed/removed or new window is added,
> we need a helper to create a default window from all these cases.
>
> This adds tce_iommu_create_default_window(). Since it relies on
> a VFIO container to have at least one IOMMU group (for future use),
> this changes tce_iommu_attach_group() to add a group to the container
> first and then call the new helper.
>
> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
> ---
> Changes:
> v6:
> * new to the patchset
> ---
> drivers/vfio/vfio_iommu_spapr_tce.c | 87 ++++++++++++++++++-------------------
> 1 file changed, 42 insertions(+), 45 deletions(-)
>
> diff --git a/drivers/vfio/vfio_iommu_spapr_tce.c b/drivers/vfio/vfio_iommu_spapr_tce.c
> index 4efd2b2..a67bbfd 100644
> --- a/drivers/vfio/vfio_iommu_spapr_tce.c
> +++ b/drivers/vfio/vfio_iommu_spapr_tce.c
> @@ -710,6 +710,29 @@ static long tce_iommu_remove_window(struct tce_container *container,
> return 0;
> }
>
> +static long tce_iommu_create_default_window(struct tce_container *container)
> +{
> + long ret;
> + __u64 start_addr = 0;
> + struct tce_iommu_group *tcegrp;
> + struct iommu_table_group *table_group;
> +
> + if (!tce_groups_attached(container))
> + return -ENODEV;
> +
> + tcegrp = list_first_entry(&container->group_list,
> + struct tce_iommu_group, next);
> + table_group = iommu_group_get_iommudata(tcegrp->grp);
> + if (!table_group)
> + return -ENODEV;
> +
> + ret = tce_iommu_create_window(container, IOMMU_PAGE_SHIFT_4K,
> + table_group->tce32_size, 1, &start_addr);
> + WARN_ON_ONCE(!ret && start_addr);
> +
> + return ret;
> +}
> +
> static long tce_iommu_ioctl(void *iommu_data,
> unsigned int cmd, unsigned long arg)
> {
> @@ -1100,9 +1123,6 @@ static void tce_iommu_release_ownership_ddw(struct tce_container *container,
> static long tce_iommu_take_ownership_ddw(struct tce_container *container,
> struct iommu_table_group *table_group)
> {
> - long i, ret = 0;
> - struct iommu_table *tbl = NULL;
> -
> if (!table_group->ops->create_table || !table_group->ops->set_window ||
> !table_group->ops->release_ownership) {
> WARN_ON_ONCE(1);
> @@ -1111,47 +1131,7 @@ static long tce_iommu_take_ownership_ddw(struct tce_container *container,
>
> table_group->ops->take_ownership(table_group);
>
> - /*
> - * If it the first group attached, check if there is
> - * a default DMA window and create one if none as
> - * the userspace expects it to exist.
> - */
> - if (!tce_groups_attached(container) && !container->tables[0]) {
> - ret = tce_iommu_create_table(container,
> - table_group,
> - 0, /* window number */
> - IOMMU_PAGE_SHIFT_4K,
> - table_group->tce32_size,
> - 1, /* default levels */
> - &tbl);
> - if (ret)
> - goto release_exit;
> - else
> - container->tables[0] = tbl;
> - }
> -
> - /* Set all windows to the new group */
> - for (i = 0; i < IOMMU_TABLE_GROUP_MAX_TABLES; ++i) {
> - tbl = container->tables[i];
> -
> - if (!tbl)
> - continue;
> -
> - /* Set the default window to a new group */
> - ret = table_group->ops->set_window(table_group, i, tbl);
> - if (ret)
> - goto release_exit;
> - }
> -
> return 0;
> -
> -release_exit:
> - for (i = 0; i < IOMMU_TABLE_GROUP_MAX_TABLES; ++i)
> - table_group->ops->unset_window(table_group, i);
> -
> - table_group->ops->release_ownership(table_group);
> -
> - return ret;
> }
>
> static int tce_iommu_attach_group(void *iommu_data,
> @@ -1161,6 +1141,7 @@ static int tce_iommu_attach_group(void *iommu_data,
> struct tce_container *container = iommu_data;
> struct iommu_table_group *table_group;
> struct tce_iommu_group *tcegrp = NULL;
> + bool create_default_window = false;
>
> mutex_lock(&container->lock);
>
> @@ -1203,14 +1184,30 @@ static int tce_iommu_attach_group(void *iommu_data,
> }
>
> if (!table_group->ops || !table_group->ops->take_ownership ||
> - !table_group->ops->release_ownership)
> + !table_group->ops->release_ownership) {
> ret = tce_iommu_take_ownership(container, table_group);
> - else
> + } else {
> ret = tce_iommu_take_ownership_ddw(container, table_group);
> + if (!tce_groups_attached(container) && !container->tables[0])
> + create_default_window = true;
> + }
>
> if (!ret) {
> tcegrp->grp = iommu_group;
> list_add(&tcegrp->next, &container->group_list);
> + /*
> + * If it the first group attached, check if there is
> + * a default DMA window and create one if none as
> + * the userspace expects it to exist.
> + */
> + if (create_default_window) {
> + ret = tce_iommu_create_default_window(container);
> + if (ret) {
> + list_del(&tcegrp->next);
> + tce_iommu_release_ownership_ddw(container,
> + table_group);
> + }
> + }
> }
>
> unlock_exit:
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
next prev parent reply other threads:[~2016-11-29 4:44 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-24 5:48 [PATCH kernel v6 0/7] powerpc/spapr/vfio: Put pages on VFIO container shutdown Alexey Kardashevskiy
2016-11-24 5:48 ` [PATCH kernel v6 1/7] powerpc/iommu: Pass mm_struct to init/cleanup helpers Alexey Kardashevskiy
2016-11-24 5:48 ` [PATCH kernel v6 2/7] powerpc/iommu: Stop using @current in mm_iommu_xxx Alexey Kardashevskiy
2016-11-24 5:48 ` [PATCH kernel v6 3/7] vfio/spapr: Postpone allocation of userspace version of TCE table Alexey Kardashevskiy
2016-11-25 1:36 ` David Gibson
2016-11-29 4:31 ` David Gibson
2016-11-24 5:48 ` [PATCH kernel v6 4/7] vfio/spapr: Add a helper to create default DMA window Alexey Kardashevskiy
2016-11-25 4:33 ` David Gibson
2016-11-29 4:33 ` David Gibson [this message]
2016-11-24 5:48 ` [PATCH kernel v6 5/7] vfio/spapr: Postpone default window creation Alexey Kardashevskiy
2016-11-25 4:39 ` David Gibson
2016-11-25 6:38 ` Alexey Kardashevskiy
2016-11-25 11:37 ` David Gibson
2016-11-28 10:40 ` Alexey Kardashevskiy
2016-11-29 4:33 ` David Gibson
2016-11-24 5:48 ` [PATCH kernel v6 6/7] vfio/spapr: Reference mm in tce_container Alexey Kardashevskiy
2016-11-29 4:55 ` David Gibson
2016-11-24 5:48 ` [PATCH kernel v6 7/7] powerpc/mm/iommu, vfio/spapr: Put pages on VFIO container shutdown Alexey Kardashevskiy
2016-11-29 5:07 ` David Gibson
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=20161129043308.GK13307@umbus.fritz.box \
--to=david@gibson.dropbear.id.au \
--cc=aik@ozlabs.ru \
--cc=alex.williamson@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=npiggin@gmail.com \
--cc=paulus@samba.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).